Previous 15994 Revisions Next

r3768 Monday 8th December, 2008 at 00:52:07 UTC by Firewave
Removed obsolete files
[src/emu]cpuint.c cpuint.h
[src/emu/cpu/h83002]h83002.c h83002.h
[src/emu/cpu/m68000]m68k.h m68kconf.h m68kmame.c m68kmame.h
[src/emu/cpu/mips]mipsdasm.c
[src/mame/drivers]couple.c pmpoker.c
[src/mame/layout]pottnpkr.lay
[src/mame/machine]mspacman.c

src/mame/machine/mspacman.c
r3767r3768
1#include "driver.h"
2#include "includes/pacman.h"
3
4
5/*
6  It turns out the bootleg is the decrypted version with the checksum check
7  removed and interrupt mode changed to 1.
8
9  u7= boot 4($3000-$3fff) other than 4 bytes(checksum check and interupt mode)
10  u6= boot 6($9000-$9fff). The second half of u6 gets mirrored to the second
11      half of boot5($8800-$8fff) where it is used.
12  u5= first half of boot5($8000-$87ff)
13
14  $8000-$81ef contain 8 byte patches that are overlayed on locations in $0000-$2fff
15
16  The Ms Pacman daughter board is not activated with the mainboard.  As near as I
17  can tell it requires a sequence of bytes starting at around 3176 and ending with
18  3196. The location of the bytes doesn't seem to matter, just that those bytes
19  are executed. That sequence of bytes includes a write to 5006 so I'm using that
20  to bankswitch, but that is not accurate. The actual change is I believe at $317D.
21  The daughterboard can also be deactivated. A read to any of the several 8 byte
22  chunks listed will cause the Ms Pac roms to disappear and Pacman to show up.
23  As a result I couldn't verify what they contained. They should be the same as the
24  pacman roms, but I don't see how it could matter. These areas can be accessed by
25  the random number generator at $2a23 and the board is deactivated but is
26  immediately reactivated. So the net result is no change. The exact trigger for
27  this is not yet known.
28
29  deactivation, 8 bytes starting at:
30  $38,$3b0,$1600,$2120,$3ff0,$8000
31
32  David Widel
33  d_widel@hotmail.com
34*/
35
36
37
38
39static UINT8 decryptd(UINT8 e)
40{
41   UINT8 d;
42
43   d  = (e & 0x80) >> 3;
44   d |= (e & 0x40) >> 3;
45   d |= (e & 0x20)     ;
46   d |= (e & 0x10) << 2;
47   d |= (e & 0x08) >> 1;
48   d |= (e & 0x04) >> 1;
49   d |= (e & 0x02) >> 1;
50   d |= (e & 0x01) << 7;
51
52   return d;
53}
54
55static UINT32 decrypta1(UINT32 e)
56{
57   UINT32 d;
58
59   d  = (e & 0x800)     ;
60   d |= (e & 0x400) >> 7;
61   d |= (e & 0x200) >> 2;
62   d |= (e & 0x100) << 1;
63   d |= (e & 0x80) << 3;
64   d |= (e & 0x40) << 2;
65   d |= (e & 0x20) << 1;
66   d |= (e & 0x10) << 1;
67   d |= (e & 0x08) << 1;
68   d |= (e & 0x04)     ;
69   d |= (e & 0x02)     ;
70   d |= (e & 0x01)     ;
71
72   return d;
73}
74
75static UINT32 decrypta2(UINT32 e)
76{
77   UINT32 d;
78   d  = (e & 0x800)     ;
79   d |= (e & 0x400) >> 2;
80   d |= (e & 0x200) >> 2;
81   d |= (e & 0x100) >> 3;
82   d |= (e & 0x80) << 2;
83   d |= (e & 0x40) << 4;
84   d |= (e & 0x20) << 1;
85   d |= (e & 0x10) >> 1;
86   d |= (e & 0x08) << 1;
87   d |= (e & 0x04)     ;
88   d |= (e & 0x02)     ;
89   d |= (e & 0x01)     ;
90
91   return d;
92}
93
94
95
96
97static void mspacman_decode(running_machine *machine)
98{
99   int i;
100   UINT8 *RAM;
101
102
103
104   /* CPU ROMs */
105
106   RAM = memory_region(machine, "main");
107   for (i = 0; i < 0x1000; i++)
108   {
109   RAM[0x10000+i] = RAM[0x0000+i];
110   RAM[0x11000+i] = RAM[0x1000+i];
111   RAM[0x12000+i] = RAM[0x2000+i];
112   RAM[0x1a000+i] = RAM[0x2000+i];  /*not needed but it's there*/
113   RAM[0x1b000+i] = RAM[0x3000+i];  /*not needed but it's there*/
114
115   }
116
117
118   for (i = 0; i < 0x1000; i++)
119   {
120      RAM[decrypta1(i)+0x13000] = decryptd(RAM[0xb000+i]);   /*u7*/
121      RAM[decrypta1(i)+0x19000] = decryptd(RAM[0x9000+i]);   /*u6*/
122   }
123
124   for (i = 0; i < 0x800; i++)
125   {
126      RAM[decrypta2(i)+0x18000] = decryptd(RAM[0x8000+i]);     /*u5*/
127      RAM[0x18800+i] = RAM[0x19800+i];
128   }
129
130
131
132   for (i = 0; i < 8; i++)
133   {
134      RAM[0x10410+i] = RAM[0x18008+i];
135      RAM[0x108E0+i] = RAM[0x181D8+i];
136      RAM[0x10A30+i] = RAM[0x18118+i];
137      RAM[0x10BD0+i] = RAM[0x180D8+i];
138      RAM[0x10C20+i] = RAM[0x18120+i];
139      RAM[0x10E58+i] = RAM[0x18168+i];
140      RAM[0x10EA8+i] = RAM[0x18198+i];
141
142      RAM[0x11000+i] = RAM[0x18020+i];
143      RAM[0x11008+i] = RAM[0x18010+i];
144      RAM[0x11288+i] = RAM[0x18098+i];
145      RAM[0x11348+i] = RAM[0x18048+i];
146      RAM[0x11688+i] = RAM[0x18088+i];
147      RAM[0x116B0+i] = RAM[0x18188+i];
148      RAM[0x116D8+i] = RAM[0x180C8+i];
149      RAM[0x116F8+i] = RAM[0x181C8+i];
150      RAM[0x119A8+i] = RAM[0x180A8+i];
151      RAM[0x119B8+i] = RAM[0x181A8+i];
152
153      RAM[0x12060+i] = RAM[0x18148+i];
154      RAM[0x12108+i] = RAM[0x18018+i];
155      RAM[0x121A0+i] = RAM[0x181A0+i];
156      RAM[0x12298+i] = RAM[0x180A0+i];
157      RAM[0x123E0+i] = RAM[0x180E8+i];
158      RAM[0x12418+i] = RAM[0x18000+i];
159      RAM[0x12448+i] = RAM[0x18058+i];
160      RAM[0x12470+i] = RAM[0x18140+i];
161      RAM[0x12488+i] = RAM[0x18080+i];
162      RAM[0x124B0+i] = RAM[0x18180+i];
163      RAM[0x124D8+i] = RAM[0x180C0+i];
164      RAM[0x124F8+i] = RAM[0x181C0+i];
165      RAM[0x12748+i] = RAM[0x18050+i];
166      RAM[0x12780+i] = RAM[0x18090+i];
167      RAM[0x127B8+i] = RAM[0x18190+i];
168      RAM[0x12800+i] = RAM[0x18028+i];
169      RAM[0x12B20+i] = RAM[0x18100+i];
170      RAM[0x12B30+i] = RAM[0x18110+i];
171      RAM[0x12BF0+i] = RAM[0x181D0+i];
172      RAM[0x12CC0+i] = RAM[0x180D0+i];
173      RAM[0x12CD8+i] = RAM[0x180E0+i];
174      RAM[0x12CF0+i] = RAM[0x181E0+i];
175      RAM[0x12D60+i] = RAM[0x18160+i];
176   }
177}
178
179
180MACHINE_RESET( mspacman )
181{
182   UINT8 *RAM = memory_region(machine, "main");
183   mspacman_decode(machine);
184
185   memory_configure_bank(1, 0, 2, &RAM[0x00000], 0x10000);
186   memory_set_bank(1, 0);
187}
188
189
190WRITE8_HANDLER( mspacman_activate_rom )
191{
192   if (data==1) memory_set_bank(1, 1);
193}
194
195
src/mame/layout/pottnpkr.lay
r3767r3768
1<?xml version="1.0"?>
2<mamelayout version="2">
3   <element name="BET" defstate="1">
4      <rect state="1">
5         <color red="1.0" green="1.0" blue="1.0" />
6      </rect>
7      <rect state="0">
8         <color red="0.2" green="0.2" blue="0.2" />
9      </rect>
10      <text string="BET">
11         <color red="0.0" green="0.0" blue="0.0" />
12         <bounds x="0" y="0.1" width="1" height="0.8" />
13      </text>
14   </element>
15
16   <element name="DEAL" defstate="1">
17      <rect state="1">
18         <color red="1.0" green="1.0" blue="1.0" />
19      </rect>
20      <rect state="0">
21         <color red="0.2" green="0.2" blue="0.2" />
22      </rect>
23      <text string="DEAL">
24         <color red="0.0" green="0.0" blue="0.0" />
25         <bounds x="0" y="0.1" width="1" height="0.8" />
26      </text>
27   </element>
28
29   <element name="HOLD" defstate="1">
30      <rect state="1">
31         <color red="1.0" green="0.5" blue="0.0" />
32      </rect>
33      <rect state="0">
34         <color red="0.3" green="0.1" blue="0.0" />
35      </rect>
36      <text string="HOLD">
37         <color red="0.0" green="0.0" blue="0.0" />
38         <bounds x="0" y="0.1" width="1" height="0.8" />
39      </text>
40   </element>
41
42   <element name="CANCEL" defstate="1">
43      <rect state="1">
44         <color red="1.0" green="0.0" blue="0.0" />
45      </rect>
46      <rect state="0">
47         <color red="0.3" green="0.0" blue="0.0" />
48      </rect>
49      <text string="CANCEL">
50         <color red="0.0" green="0.0" blue="0.0" />
51         <bounds x="0" y="0.1" width="1" height="0.8" />
52      </text>
53   </element>
54
55   <view name="Button Lamps">
56      <screen index="0">
57         <bounds left="0" top="0" right="4" bottom="3" />
58      </screen>
59      <bezel name="lamp0" element="BET">
60         <bounds x="0" y="3.13" width="0.40" height="0.24" />
61      </bezel>
62      <bezel name="lamp1" element="DEAL">
63         <bounds x="0.5" y="3.13" width="0.40" height="0.24" />
64      </bezel>
65      <bezel name="lamp2" element="HOLD">
66         <bounds x="1.0" y="3.13" width="0.40" height="0.24" />
67      </bezel>
68      <bezel name="lamp2" element="HOLD">
69         <bounds x="1.5" y="3.13" width="0.40" height="0.24" />
70      </bezel>
71      <bezel name="lamp2" element="HOLD">
72         <bounds x="2.0" y="3.13" width="0.40" height="0.24" />
73      </bezel>
74      <bezel name="lamp2" element="HOLD">
75         <bounds x="2.5" y="3.13" width="0.40" height="0.24" />
76      </bezel>
77      <bezel name="lamp2" element="HOLD">
78         <bounds x="3.0" y="3.13" width="0.40" height="0.24" />
79      </bezel>
80      <bezel name="lamp2" element="CANCEL">
81         <bounds x="3.5" y="3.13" width="0.50" height="0.24" />
82      </bezel>
83   </view>
84</mamelayout>
src/mame/drivers/couple.c
r3767r3768
1/*******************************************************************************************
2
3The Couples (c) 1986/1988 The Couples (?)
4
5Preliminary driver by Angelo Salese
6
7This seems the second revision of the Merit.c HW,with the rom banking,the backup ram &
8some sort of protection/funky ram banking which involves a program uploaded into
9the backup ram itself.
10
11TODO:
12-Fix graphics bugs;
13-Support the C.R.T.C 6845 features;
14-Inputs are sometimes buggy;
15-Colors;
16-Merge with the Merit.c driver;
17-Uncertain Manufacturer & Year of production,is it Merit,it is an hack/bootleg running
18on that board or Merit got bankrupt and can't use his trademark?
19- update 2006018 by f205v: in-game grafics clearly displays Merit simbol, for this reason
20I changed manufacturer to "Merit"
21
22********************************************************************************************
23
24Main CPU : Z80B CPU
25
26Sound : AY3-8910 + 2 x Nec D8255AC-2
27
28Other : MC6845P
29
30Battery backup ram (6264)
31
32Provided to you by Thierry (ShinobiZ) & Gerald (COY)
33
34*******************************************************************************************/
35
36#include "driver.h"
37#include "machine/8255ppi.h"
38#include "sound/ay8910.h"
39#include "video/mc6845.h"
40
41static tilemap *bg_tilemap;
42static UINT8 *vram_lo,*vram_hi;
43static UINT8 *backup_ram;
44
45//before 53 after 71 then 6b
46/*
47Hi VRAM   Lo VRAM
481111 11
495432 1098 7654 3210
50x-x- ---- ---- ---- extra tile number.
51-x-- ---- ---- ---- rom selector?
52---x xxxx ---- ---- color?
53---- ---- xxxx xxxx tile number
54*/
55
56static TILE_GET_INFO( get_tile_info )
57{
58   UINT16 vram_data = (((vram_hi[tile_index] & 0xff) << 8) | (vram_lo[tile_index] & 0xff));
59   UINT16 region = (vram_data & 0x4000) >> 14;
60   UINT16 code = ((vram_data & 0xff) | ((vram_data & 0x8000) >> 7) | ((vram_data & 0x2000) >> 4));
61   UINT16 color = (vram_data & 0x0f00) >> 8;
62
63   SET_TILE_INFO(region, code, color, 0);
64}
65
66static VIDEO_START( couple )
67{
68   bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,8,8,64,32);
69}
70
71static VIDEO_UPDATE( couple )
72{
73   tilemap_draw(bitmap,cliprect,bg_tilemap,0,0);
74   return 0;
75}
76
77static WRITE8_HANDLER( couple_vram_lo_w )
78{
79   vram_lo[offset] = data;
80   tilemap_mark_tile_dirty(bg_tilemap,offset);
81}
82
83static WRITE8_HANDLER( couple_vram_hi_w )
84{
85   vram_hi[offset] = data;
86   tilemap_mark_tile_dirty(bg_tilemap,offset);
87}
88
89#ifdef UNUSED_FUNCTION
90static READ8_HANDLER( dummy_inputs_r )
91{
92   logerror("Read %02x @ %06x\n",offset,cpu_get_pc(space->cpu));
93   return 0xff;
94}
95#endif
96
97/*static UINT8 unk_data;
98
99static READ8_HANDLER( unk_r )
100{
101    return unk_data;
102}
103
104static WRITE8_HANDLER( unk_w )
105{
106    unk_data = data;
107    popmessage("%04x",data);
108}*/
109
110/*Actually clear RAM stuff,writes 0x90 at start-up.*/
111static WRITE8_HANDLER( merit_prot_w )
112{
113   /*This is likely to be wrong here but I don't know where to put it,It ensures
114      that the parent set don't crash when jumps to $b011*/
115   backup_ram[0x1011] = 0xc9; //ret
116   //unk_data = data;
117   //if(data == 0xc9)
118   //popmessage("%02x",data);
119}
120
121#if 0
122static const ay8910_interface ay8910_config =
123{
124   input_port_4_r,
125};
126#endif
127
128static const ppi8255_interface ppi8255_intf[2] =
129{
130   {
131      DEVICE8_PORT("P1"),         /* Port A read */
132      DEVICE8_PORT("SYSTEM"),      /* Port B read */
133      NULL,                  /* Port C read */
134      NULL,                  /* Port A write */
135      NULL,                  /* Port B write */
136      NULL                  /* Port C write */
137   },
138   {
139      DEVICE8_PORT("DSW"),      /* Port A read */
140      DEVICE8_PORT("IN3"),      /* Port B read */
141      DEVICE8_PORT("IN4"),      /* Port C read */
142      NULL,                  /* Port A write */
143      NULL,                  /* Port B write */
144      NULL                  /* Port C write */
145   }
146};
147
148static ADDRESS_MAP_START( merit_mem, ADDRESS_SPACE_PROGRAM, 8 )
149   AM_RANGE( 0x0000, 0x7fff ) AM_ROM
150   AM_RANGE( 0x8000, 0x9fff ) AM_ROMBANK(1)
151   AM_RANGE( 0xa000, 0xbfff ) AM_RAM AM_BASE(&backup_ram)
152   AM_RANGE( 0xc004, 0xc007 ) AM_DEVREADWRITE(PPI8255, "ppi8255_0", ppi8255_r, ppi8255_w)
153   AM_RANGE( 0xc008, 0xc00a ) AM_DEVREADWRITE(PPI8255, "ppi8255_1", ppi8255_r, ppi8255_w)
154   AM_RANGE( 0xc00b, 0xc00b ) AM_WRITE(merit_prot_w)
155//  AM_RANGE( 0xc000, 0xc00f ) AM_READ(dummy_inputs_r)
156//  AM_RANGE( 0xc008, 0xc008 ) AM_READ_PORT("P1")
157//  AM_RANGE( 0xc00a, 0xc00a ) AM_READ_PORT("DSW")
158     AM_RANGE( 0xe000, 0xe000 ) AM_DEVWRITE(MC6845, "crtc", mc6845_address_w)
159     AM_RANGE( 0xe001, 0xe001 ) AM_DEVWRITE(MC6845, "crtc", mc6845_register_w)
160   AM_RANGE( 0xe800, 0xefff ) AM_RAM_WRITE(couple_vram_hi_w) AM_BASE(&vram_hi)
161   AM_RANGE( 0xf000, 0xf7ff ) AM_RAM_WRITE(couple_vram_lo_w) AM_BASE(&vram_lo)
162   AM_RANGE( 0xf800, 0xfbff ) AM_RAM /*extra VRAM?*/
163ADDRESS_MAP_END
164
165static ADDRESS_MAP_START( merit_io, ADDRESS_SPACE_IO, 8 )
166//  ADDRESS_MAP_GLOBAL_MASK(0xff)
167   AM_RANGE(0xc00c, 0xc00c) AM_WRITE(ay8910_control_port_0_w)
168   AM_RANGE(0xc10c, 0xc10c) AM_WRITE(ay8910_write_port_0_w)
169ADDRESS_MAP_END
170
171static PALETTE_INIT( couple )
172{
173   int i;
174
175   /*TODO:color table not yet understood.Need a snapshot of the real thing.*/
176   /*RRGGGBBB*/
177   for (i = 0;i < 0xff;i++)
178   {
179      int bit0,bit1,bit2,bit3,r,g,b;
180
181      bit0 = 1;
182      bit1 = 1;
183      bit2 = (color_prom[i] >> 6) & 0x01;
184      bit3 = (color_prom[i] >> 7) & 0x01;
185      r = 0x0e * bit0 + 0x1f * bit1 + 0x42 * bit2 + 0x90 * bit3;
186      bit0 = 1;
187      bit1 = (color_prom[i] >> 3) & 0x01;
188      bit2 = (color_prom[i] >> 4) & 0x01;
189      bit3 = (color_prom[i] >> 5) & 0x01;
190      g = 0x0e * bit0 + 0x1f * bit1 + 0x42 * bit2 + 0x90 * bit3;
191      bit0 = 1;
192      bit1 = (color_prom[i] >> 0) & 0x01;
193      bit2 = (color_prom[i] >> 1) & 0x01;
194      bit3 = (color_prom[i] >> 2) & 0x01;
195      b = 0x0e * bit0 + 0x1f * bit1 + 0x42 * bit2 + 0x90 * bit3;
196
197      palette_set_color(machine,i,MAKE_RGB(r,g,b));
198      //color_prom++;
199   }
200}
201
202static INPUT_PORTS_START( couple )
203   PORT_START("P1")
204   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1)
205   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
206   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
207   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1)
208   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_IMPULSE(1)
209   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_IMPULSE(1)
210   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_IMPULSE(1)
211   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_IMPULSE(1)
212
213   PORT_START("DSW")
214   PORT_DIPNAME( 0x01, 0x00, "Number of Attempts" )
215   PORT_DIPSETTING(    0x01, "99" )
216   PORT_DIPSETTING(    0x00, "9" )
217   PORT_DIPNAME( 0x02, 0x02, "Tries Per Coin" )
218   PORT_DIPSETTING(    0x02, "3" )
219   PORT_DIPSETTING(    0x00, "2" )
220   PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Coinage ) )
221   PORT_DIPSETTING(    0x08, DEF_STR( 2C_1C ) )
222   PORT_DIPSETTING(    0x0c, DEF_STR( 1C_1C ) )
223   PORT_DIPSETTING(    0x04, DEF_STR( 1C_2C ) )
224/*2 Coins for 2 Credits?I think this is an invalid setting,it doesn't even work correctly*/
225/*  PORT_DIPSETTING(    0x00, DEF_STR( 2C_2C ) ) */
226   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Difficulty ) )
227   PORT_DIPSETTING(    0x10, DEF_STR( Easy ) )
228   PORT_DIPSETTING(    0x00, DEF_STR( Hard ) )
229   PORT_DIPNAME( 0x20, 0x00, "Sound" )
230   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
231   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
232   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unused ) )
233   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
234   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
235   PORT_DIPNAME( 0x80, 0x80, "Clear RAM" )
236   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
237   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
238
239   PORT_START("SYSTEM")
240   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_IMPULSE(1)
241   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
242   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
243   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
244   PORT_SERVICE( 0x04, IP_ACTIVE_LOW )
245   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
246   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
247   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
248   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
249   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
250   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
251   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
252   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
253   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
254   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
255   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
256   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
257   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
258   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
259   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
260
261   PORT_START("IN3")
262   PORT_DIPNAME( 0x01, 0x01, "3" )
263   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
264   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
265   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
266   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
267   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
268   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
269   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
270   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
271   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
272   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
273   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
274   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
275   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
276   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
277   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
278   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
279   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
280   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
281   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
282   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
283   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
284   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
285   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
286
287   PORT_START("IN4")
288   PORT_DIPNAME( 0x01, 0x01, "4" )
289   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
290   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
291   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
292   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
293   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
294   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
295   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
296   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
297   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
298   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
299   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
300   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
301   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
302   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
303   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
304   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
305   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
306   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
307   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
308   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
309   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
310   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
311   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
312INPUT_PORTS_END
313
314/*Different DSWs*/
315static INPUT_PORTS_START( couplep )
316   PORT_INCLUDE( couple )
317
318   PORT_MODIFY("DSW")
319   PORT_DIPNAME( 0x40, 0x40, "Bonus Play" )
320   PORT_DIPSETTING(    0x40, "at 150.000" )
321   PORT_DIPSETTING(    0x00, "at 200.000" )
322   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unused ) )
323   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
324   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
325INPUT_PORTS_END
326
327
328static const gfx_layout tiles8x8x4_layout =
329{
330   8,8,
331   RGN_FRAC(1,4),
332   4,
333   { RGN_FRAC(0,4), RGN_FRAC(1,4), RGN_FRAC(2,4), RGN_FRAC(3,4) },
334   { 0, 1, 2, 3, 4, 5, 6, 7 },
335   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
336   16*8
337};
338
339static const gfx_layout tiles8x8x3_layout =
340{
341   8,8,
342   RGN_FRAC(1,3),
343   3,
344   { RGN_FRAC(0,3), RGN_FRAC(1,3), RGN_FRAC(2,3) },
345   { 0, 1, 2, 3, 4, 5, 6, 7 },
346   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
347   16*8
348};
349
350static GFXDECODE_START( couple )
351   GFXDECODE_ENTRY( "gfx1", 0, tiles8x8x3_layout, 0, 32 )
352   GFXDECODE_ENTRY( "gfx2", 0, tiles8x8x4_layout, 0, 16 )
353   GFXDECODE_ENTRY( "gfx1", 8, tiles8x8x3_layout, 0, 32 ) //flipped tiles
354   GFXDECODE_ENTRY( "gfx2", 8, tiles8x8x4_layout, 0, 16 ) //flipped tiles
355GFXDECODE_END
356
357static MACHINE_DRIVER_START( couple )
358   MDRV_CPU_ADD("main", Z80,18432000/6)       /* ?? */
359   MDRV_CPU_PROGRAM_MAP(merit_mem,0)
360   MDRV_CPU_IO_MAP(merit_io,0)
361   MDRV_CPU_VBLANK_INT("main", irq0_line_hold)
362
363   MDRV_PPI8255_ADD( "ppi8255_0", ppi8255_intf[0] )
364   MDRV_PPI8255_ADD( "ppi8255_1", ppi8255_intf[1] )
365
366   /* video hardware */
367   MDRV_SCREEN_ADD("main", RASTER)
368   MDRV_SCREEN_REFRESH_RATE(60)
369   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
370   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
371   MDRV_SCREEN_SIZE(64*8, 32*8)
372   MDRV_SCREEN_VISIBLE_AREA(0*8, 64*8-1, 0*8, 32*8-1)
373
374   MDRV_GFXDECODE(couple)
375   MDRV_PALETTE_LENGTH(0x100)
376   MDRV_PALETTE_INIT(couple)
377
378   MDRV_VIDEO_START(couple)
379   MDRV_VIDEO_UPDATE(couple)
380
381   MDRV_DEVICE_ADD("crtc", MC6845)
382
383   MDRV_SPEAKER_STANDARD_MONO("mono")
384
385   MDRV_SOUND_ADD("ay", AY8910, 4000000)
386//  MDRV_SOUND_CONFIG(ay8910_config)
387   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
388MACHINE_DRIVER_END
389
390ROM_START( couple )
391   ROM_REGION( 0x20000, "main", 0 )
392   ROM_LOAD( "1.1d",  0x00000, 0x8000, CRC(bc70337a) SHA1(ffc484bc3965f0780d3fa5d8801af27a7164a417) )
393   ROM_LOAD( "2.1e",  0x10000, 0x8000, CRC(17372a93) SHA1(e0f0980003473555c2543d98d1494f82afa49f1a) )
394
395   ROM_REGION( 0x18000, "gfx1", 0 )
396   ROM_LOAD( "3.9c",  0x00000, 0x8000, CRC(f017399a) SHA1(baf4c1bea6a12b1d4c8838552503fbdb81378411) )
397   ROM_LOAD( "4.9d",  0x08000, 0x8000, CRC(66da76c1) SHA1(8cdcec008d0d51704544069246e9eabb5d5958ea) )
398   ROM_LOAD( "5.10c", 0x10000, 0x8000, CRC(fc22bcf4) SHA1(cf3f6872965cb264d56d3a0b5ab998541b9af4ef) )
399
400   ROM_REGION( 0x08000, "gfx2", 0 )
401   ROM_LOAD( "6.10d", 0x00000, 0x8000, CRC(a6a9a73d) SHA1(f3cb1d434d730f6e00f48079eaf8b88f57779fa0) )
402
403   ROM_REGION( 0x0800, "proms", 0 )
404   /*Only 0x00-0xff data seems color prom*/
405   ROM_LOAD( "7.7a",  0x00000, 0x0800, CRC(6c36361e) SHA1(7a018eecf3d8b7cf8845dcfcf8067feb292933b2) )
406ROM_END
407
408/*f205v's dump,same except for the first z80 rom,first noticeable differences are that
409it doesn't jump to the backup ram area and it gives an extra play if you reach a certain
410amount of points (there is a dip switch to select the trigger: 150.000 or 200.000*/
411ROM_START( couplep )
412   ROM_REGION( 0x20000, "main", 0 )
413   ROM_LOAD( "1.1d",  0x00000, 0x8000, CRC(4601ace6) SHA1(a824ceebf8b9ce77ef2c8e92636e4261f2ae0420) )
414   ROM_LOAD( "2.1e",  0x10000, 0x8000, CRC(17372a93) SHA1(e0f0980003473555c2543d98d1494f82afa49f1a) )
415
416   ROM_REGION( 0x18000, "gfx1", 0 )
417   ROM_LOAD( "3.9c",  0x00000, 0x8000, CRC(f017399a) SHA1(baf4c1bea6a12b1d4c8838552503fbdb81378411) )
418   ROM_LOAD( "4.9d",  0x08000, 0x8000, CRC(66da76c1) SHA1(8cdcec008d0d51704544069246e9eabb5d5958ea) )
419   ROM_LOAD( "5.10c", 0x10000, 0x8000, CRC(fc22bcf4) SHA1(cf3f6872965cb264d56d3a0b5ab998541b9af4ef) )
420
421   ROM_REGION( 0x08000, "gfx2", 0 )
422   ROM_LOAD( "6.10d", 0x00000, 0x8000, CRC(a6a9a73d) SHA1(f3cb1d434d730f6e00f48079eaf8b88f57779fa0) )
423
424   ROM_REGION( 0x0800, "proms", 0 )
425   /*Only 0x00-0xff data seems color prom*/
426   ROM_LOAD( "7.7a",  0x00000, 0x0800, CRC(6c36361e) SHA1(7a018eecf3d8b7cf8845dcfcf8067feb292933b2) )
427ROM_END
428
429/*f205v's dump,this one looks like an intermediate release between set1 and set2;
430it has same dips as set1, but remaining machine code is the same as set2*/
431ROM_START( couplei )
432   ROM_REGION( 0x20000, "main", 0 )
433   ROM_LOAD( "1.1d",  0x00000, 0x8000, CRC(760fa29e) SHA1(a37a1562028d9615adff3d2ef88e0156354c720a) )
434   ROM_LOAD( "2.1e",  0x10000, 0x8000, CRC(17372a93) SHA1(e0f0980003473555c2543d98d1494f82afa49f1a) )
435
436   ROM_REGION( 0x18000, "gfx1", 0 )
437   ROM_LOAD( "3.9c",  0x00000, 0x8000, CRC(f017399a) SHA1(baf4c1bea6a12b1d4c8838552503fbdb81378411) )
438   ROM_LOAD( "4.9d",  0x08000, 0x8000, CRC(66da76c1) SHA1(8cdcec008d0d51704544069246e9eabb5d5958ea) )
439   ROM_LOAD( "5.10c", 0x10000, 0x8000, CRC(fc22bcf4) SHA1(cf3f6872965cb264d56d3a0b5ab998541b9af4ef) )
440
441   ROM_REGION( 0x08000, "gfx2", 0 )
442   ROM_LOAD( "6.10d", 0x00000, 0x8000, CRC(a6a9a73d) SHA1(f3cb1d434d730f6e00f48079eaf8b88f57779fa0) )
443
444   ROM_REGION( 0x0800, "proms", 0 )
445   /*Only 0x00-0xff data seems color prom*/
446   ROM_LOAD( "7.7a",  0x00000, 0x0800, CRC(6c36361e) SHA1(7a018eecf3d8b7cf8845dcfcf8067feb292933b2) )
447ROM_END
448
449static DRIVER_INIT( couple )
450{
451   UINT8 *ROM = memory_region(machine, "main");
452
453   #if 0 //quick rom compare test
454   {
455      static int i,r;
456      r = 0;
457      for(i=0;i<0x2000;i++)
458      {
459         if(ROM[0x14000+i] == ROM[0x16000+i])
460            r++;
461      }
462      mame_printf_debug("%02x (in HEX) identical bytes (no offset done)\n",r);
463   }
464   #endif
465
466   /*The banked rom isn't a *real* banking,it's just a strange rom hook-up,the 2nd
467      and the 3rd halves are 100% identical(!),unless it's an error of TWO different
468      dumpers it's just the way it is,a.k.a. it's an "hardware" banking.
469    update 20060118 by f205v: now we have 3 dumps from 3 different boards and they
470    all behave the same...*/
471   memory_set_bankptr(machine, 1,ROM + 0x10000 + (0x2000 * 2));
472}
473
474/*Year is uncertain:
475title screen says "1988"
476PCB marking (set 2) and (set 3) says "230188"
477service mode says "6221-51 U5-0 12/02/86" */
478
479GAME( 1988, couple,  0,      couple, couple,  couple, ROT0, "Merit", "The Couples (Set 1)", GAME_IMPERFECT_GRAPHICS | GAME_WRONG_COLORS | GAME_NOT_WORKING)
480GAME( 1988, couplep, couple, couple, couplep, couple, ROT0, "Merit", "The Couples (Set 2)", GAME_IMPERFECT_GRAPHICS | GAME_WRONG_COLORS | GAME_NOT_WORKING)
481GAME( 1988, couplei, couple, couple, couple,  couple, ROT0, "Merit", "The Couples (Set 3)", GAME_IMPERFECT_GRAPHICS | GAME_WRONG_COLORS | GAME_NOT_WORKING)
src/mame/drivers/pmpoker.c
r3767r3768
1/******************************************************************************
2
3    PLAYMAN POKER
4    -------------
5
6    Driver by Roberto Fresca.
7
8
9    Games running on this hardware:
10
11    * PlayMan Poker (german).             1981, PlayMan.
12    * Golden Poker Double Up (Big Boy).   1981, Bonanza Enterprises, Ltd.
13    * Golden Poker Double Up (Mini Boy).  1981, Bonanza Enterprises, Ltd.
14    * Jack Potten's Poker (set 1).        198?, Bootleg.
15    * Jack Potten's Poker (set 2).        198?, Bootleg in Coinmaster H/W.
16    * Jack Potten's Poker (set 3).        198?, Bootleg.
17    * Jack Potten's Poker (set 4).        198?, Bootleg.
18    * Jack Potten's Poker (set 5).        198?, Bootleg.
19    * Jack Potten's Poker (set 6).        198?, Bootleg.
20    * Good Luck.                          198?, Unknown.
21    * Buena Suerte (spanish, set 1).      198?, Unknown.
22    * Buena Suerte (spanish, set 2).      198?, Unknown.
23    * Royale.                             198?, Unknown.
24    * Witch Card.                         1991, Unknown.
25    * Witch Card (spanish, set 1).        1991, Unknown.
26    * Witch Card (spanish, set 2).        1991, Unknown.
27    * Super Loco 93 (spanish, set 1).     1993, Unknown.
28    * Super Loco 93 (spanish, set 2).     1993, Unknown.
29
30
31*******************************************************************************
32
33
34    I think "Diamond Poker Double Up" from Bonanza Enterprises should run on this hardware too.
35    http://www.arcadeflyers.com/?page=thumbs&id=4539
36
37    Big-Boy and Mini-Boy are different sized cabinets for Bonanza Enterprises games.
38    http://www.arcadeflyers.com/?page=thumbs&id=4616
39    http://www.arcadeflyers.com/?page=thumbs&id=4274
40
41
42    Preliminary Notes (pmpoker):
43
44    - This set was found as "unknown playman-poker".
45    - The ROMs didn't match any currently supported set (0.108u2 romident switch).
46    - All this driver was made using reverse engineering in the program roms.
47
48
49    Game Notes:
50    ==========
51
52    * goldnpkr & goldnpkb:
53
54    "How to play"... (from "Golden Poker Double Up" instruction card)
55
56    1st GAME
57    - Insert coin / bank note.
58    - Push BET button, 1-10 credits multiple play.
59    - Push DEAL/DRAW button.
60    - Push HOLD buttons to hold cards you need.
61    - Cards held can be cancelled by pushing CANCEL button.
62    - Push DEAL/DRAW button to draw cards.
63
64    2nd GAME - Double Up game
65    - When you win, choose TAKE SCORE or DOUBLE UP game.
66    - Bet winnings on
67        "BIG (8 or more number)" or
68        "SMALL (6 and less number)" of next one card dealt.
69    - Over 5,000 winnings will be storaged automatically.
70
71
72    ----- Learn Mode (settings) -----
73    Press LEARN (F2) to enter the learn mode for settings.
74    This is a timed function and after 30-40 seconds switch back to the game.
75
76    Press DOUBLE UP to change Double Up 7 settings between 'Even' and 'Lose'.
77    Press BET to adjust the maximum bet (20-200).
78    Press HOLD4 for Meter Over (5000-50000).
79    Press BIG to change Double Up settings (Normal-Hard).
80    Press TAKE SCORE to set Half Gamble (Yes/No).
81    Press SMALL to set win sound (Yes/No).
82    Press HOLD1 to set coinage 1.
83    Press HOLD2 to set coinage 2.
84    Press HOLD3 to set coinage 3.
85    Press HOLD5 to exit.
86
87    ----- Meters Mode -----
88    Press METER SW (9) to enter the Meters mode. You also can switch between interim
89    and permanent meters using METER SW (only for goldnpkr).
90    This is a timed function and after 30-40 seconds switch back to the game.
91
92    To reset meters push CANCEL + SMALL buttons. HOLD5 to exit.
93    In goldnpkr you can switch between Permanent/Interim Meters.
94    In goldnpkb & pmpoker you can see only Permanent Meters.
95
96    ----- Percentage Mode -----
97    Press Meter SW (9), then DEAL/DRAW, to enter the percentage mode.
98    Press HOLD4 to change the value following the table below (from manual). HOLD1 to exit.
99
100    Number    Overall scoring percentage in the LONG RUN
101    - - - - - - - - - - - - - - - - - - - - - - - - - - -
102      0         about 85%
103      1         about 30%
104      2         about 40%
105      3         about 50%
106
107    ----- Test Mode -----
108    Press Meter SW (9), then DEAL/DRAW, then HOLD5 to enter the test mode.
109    After a RAM test, you can see an input test matrix. Press HOLD1+HOLD2+HOLD3 to exit
110    entering into a video grid test. Press HOLD5 to exit.
111
112
113    * Good Luck
114
115    This hybrid runs on Witch Card hardware.
116    Even when is shown on screen "Bet 1 to 10", you can bet up to 50.
117    There are extra graphics for a couple of jokers, but they never are shown.
118    Maybe some settings can enable the use of them...
119
120
121    * Witch Card
122
123    This game is derivated from Golden Poker.
124
125    The hardware has a feature called BLUE KILLER.
126    Using the original intensity line, the PCB has a bridge
127    that allow (as default) turn the background black.
128
129    Except goodluck, all other games running in this hardware
130    were designed to wear black background.
131
132    Settings:
133
134    There are 12 parameters to program. All of them are unknown.
135    To program them, use the HOLD keys, CANCEL key, DEAL + HOLD keys,
136    and DEAL + CANCEL.
137
138
139    * Super Loco 93
140
141    I like this game!... This one has nothing to do with poker games.
142    The objective is to get the higher sum with 2 or 3 cards. Is clearly
143    based on a passage (Envido) of the famous argentine's game called "Truco".
144
145    How to play?...
146
147    Like in Truco's envido, You must add 20 to the sum of your cards.
148    If you have 7 and 5 of the same kind, you have 7 + 5 + 20 = 32 points.
149
150    "Flor", is 3 cards of the same kind.
151    "Simple", is 2 cards of the same kind.
152
153    HAND             WIN    DESCRIPTION
154    ----------------------------------------------
155    38  Corazones   1000    7, 6 and 5 of hearts.
156    777 Loco Loco    200    3x sevens.
157    38  Flor          80    7, 6 and 5 of the same kind (except hearts).
158    37  Flor          20    7, 6 and 4 of the same kind.
159    36  Flor          14    7, 5 and 4 of the same kind.
160    35  Flor          10    6, 5 and 4 of the same kind.
161    32-33-34 Flor      6    3 of the same kind that sum 32, 33 or 34.
162    33  Simple         4    7 and 6 of the same kind.
163    32  Simple         2    7 and 5 of the same kind.
164
165    After bet (apuesta) some credits, Press deal (reparte) button.
166    The game will deals 3 cards. You can discard up to all your 3 cards.
167    Pressing the deal button again, new cards will appear in the place
168    of the previously selected cards.
169
170    Settings:
171
172    There are 12 parameters to program.
173    To program them, use the HOLD keys, CANCEL key, DEAL + HOLD keys,
174    and DEAL + CANCEL.
175
176
177
178*******************************************************************************
179
180
181    Hardware Notes (pmpoker):
182
183    - CPU:            1x M6502.
184    - Video:          1x MC6845.
185    - RAM:            4x uPD2114LC
186    - I/O             2x 6821 PIAs.
187    - prg ROMs:       3x 2732 (32Kb) or similar.
188    - gfx ROMs:       4x 2716 (16Kb) or similar.
189    - sound:          (discrete).
190    - battery backup: 2x S8423
191
192
193    PCB Layout (pmpoker): (XX) = unreadable.
194     _______________________________________________________________________________
195    |   _________                                                                   |
196    |  |         |               -- DIP SW x8 --                                    |
197    |  | Battery |   _________   _______________   _________  _________   ________  |
198    |  |   055   |  | 74LS32  | |1|2|3|4|5|6|7|8| | HCF4011 || HCF4096 | | LM339N | |
199    |  |_________|  |_________| |_|_|_|_|_|_|_|_| |_________||_________| |________| |
200    |       _________     _________   _________   _________                         |
201    |      | 74LS138 |   | S-8423  | | 74LS08N | | 74LS(XX)|                        |
202    |      |_________|   |_________| |_________| |_________|                        |
203    |  _______________    _________   ____________________                      ____|
204    | |               |  | S-8423  | |                    |                    |
205    | |     2732      |  |_________| |       6502P        |                    |
206    | |_______________|   _________  |____________________|                    |
207    |  _______________   |  7432   |  ____________________                     |____
208    | |               |  |_________| |                    |                     ____|
209    | |     2732      |   _________  |       6821P        |                     ____|
210    | |_______________|  | 74LS157 | |____________________|                     ____|
211    |  _______________   |_________|  ____________________                      ____|
212    | |               |   _________  |                    |                     ____|
213    | |     2732      |  | 74LS157 | |       6821P        |                     ____|
214    | |_______________|  |_________| |____________________|                     ____|
215    |  _______________    _________   ____________________                      ____|
216    | |               |  | 74LS157 | |                    |                     ____|
217    | |     2732      |  |_________| |       6845SP       |                     ____|
218    | |_______________|   _________  |____________________|                     ____|
219    |                    | 2114-LC |                                            ____| 28x2
220    |                    |_________|                                            ____| connector
221    |       _________     _________                                             ____|
222    |      | 74LS245 |   | 2114-LC |                                            ____|
223    |      |_________|   |_________|                                            ____|
224    |       _________     _________               _________                     ____|
225    |      | 74LS245 |   | 2114-LC |             | 74LS174 |                    ____|
226    |      |_________|   |_________|             |_________|                    ____|
227    |  ________________   _________   _________   _________                     ____|
228    | |                | | 2114-LC | | 74LS08H | | TI (XX) | <-- socketed.      ____|
229    | |      2716      | |_________| |_________| |_________|       PROM         ____|
230    | |________________|              _________   _________                     ____|
231    |  ________________              | 74LS04P | | 74LS174 |                    ____|
232    | |                |             |_________| |_________|                    ____|
233    | |      2716      |              _________   _________                     ____|
234    | |________________|             | 74166P  | | 74LS86C |                    ____|
235    |  ________________              |_________| |_________|                    ____|
236    | |                |              _________    _______                     |
237    | |      2716      |             | 74166P  |  | 555TC |                    |
238    | |________________|             |_________|  |_______|                    |
239    |  ________________                                                        |____
240    | |                |                                                        ____|
241    | |      2716      |              _________   _________      ________       ____| 5x2
242    | |________________|             | 74166P  | |  7407N  |    | LM380N |      ____| connector
243    |                                |_________| |_________|    |________|      ____|
244    |  ________  ______               _________   _________      ___            ____|
245    | | 74LS04 || osc. |             | 74LS193 | |  7407N  |    /   \          |
246    | |________||10 MHz|             |_________| |_________|   | POT |         |
247    |           |______|                                        \___/          |
248    |__________________________________________________________________________|
249
250
251
252    Some odds:
253
254    - There are unused pieces of code like the following sub:
255
256    78DE: 18         clc
257    78DF: 69 07      adc  #$07
258    78E1: 9D 20 10   sta  $1020,x
259    78E4: A9 00      lda  #$00
260    78E6: 9D 20 18   sta  $1820,x
261    78E9: E8         inx
262
263    78EA: 82         DOP        ; use of DOP (double NOP)
264    78EB: A2 0A      dummy (ldx #$0A)
265
266    78ED: AD 82 08   lda  $0882
267
268    78F0: 82         DOP        ; use of DOP (double NOP)
269    78F1: 48 08      dummy
270    78F3: D0 F6      bne  $78EB ; branch to the 1st DOP dummy arguments (now ldx #$0A).
271    78F5: CA         dex
272    78F6: D0 F8      bne  $78F0
273    78F8: 29 10      and  #$10
274    78FA: 60         rts
275
276    Offset $78EA and $78F0 contains an undocumented 6502 opcode (0x82).
277
278    At beginning, I thought that the main processor was a 65sc816, since 0x82 is a documented opcode (BRL) for this CPU.
279    Even the vector $FFF8 contain 0x09 (used to indicate "Emulation Mode" for the 65sc816).
280    I dropped the idea following the code. Impossible to use BRL (branch relative long) in this structure.
281
282    Some 6502 sources list the 0x82 mnemonic as DOP (double NOP), with 2 dummy bytes as argument.
283    The above routine dynamically change the X register value using the DOP undocumented opcode.
284    Since the opcode DOP in fact has only 1 dummy byte as argument, they apparently dropped this
285    piece of code due to it didn't work as expected. Now all have sense.
286
287
288*******************************************************************************
289
290
291    -----------------------------------------------
292    ***  Memory Map (pmpoker/goldnpkr hardware) ***
293    -----------------------------------------------
294
295    $0000 - $00FF   RAM     ; Zero Page (pointers and registers)
296
297                            ; $45 to $47 - Coin settings.
298                            ; $50 - Input port register.
299                            ; $5C - Input port register.
300                            ; $5D - Input port register.
301                            ; $5E - Input port register.
302                            ; $5F - Input port register.
303
304    $0100 - $01FF   RAM     ; 6502 Stack Pointer.
305
306    $0200 - $02FF   RAM     ; R/W. (settings)
307    $0300 - $03FF   RAM     ; R/W (mainly to $0383). $0340 - $035f (settings).
308
309    $0800 - $0801   MC6845  ; MC6845 use $0800 for register addressing and $0801 for register values.
310
311                            *** pmpoker mc6845 init at $65B9 ***
312                            *** goldnpkr mc6845 init at $5E75 ***
313                            *** sloco93 mc6845 init at $D765 ***
314                            register:   00    01    02    03    04    05    06    07    08    09    10    11    12    13    14    15    16    17
315                            value:     0x27  0x20  0x22  0x02  0x1F  0x04  0x1D  0x1E  0x00  0x07  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00.
316
317                            *** goodluck mc6845 init at $527B ***
318                            register:   00    01    02    03    04    05    06    07    08    09    10    11    12    13    14    15    16    17
319                            value:     0x27  0x20  0x23  0x03  0x1F  0x04  0x1D  0x1F  0x00  0x00  0x26  0x00  0x20  0x22  0x58  0xA5  0x4F  0xC9.
320
321                            *** royale mc6845 init at $6581 ***
322                            register:   00    01    02    03    04    05    06    07    08    09    10    11    12    13    14    15    16    17
323                            value:     0x27  0x20  0x23  0x03  0x1F  0x04  0x1D  0x1E  0x00  0x07  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00.
324
325    $0844 - $0847   PIA0    ; Muxed inputs and lamps. Initialized at $5000.
326    $0848 - $084B   PIA1    ; Sound writes and muxed inputs selector. Initialized at $5000.
327
328    $1000 - $13FF   Video RAM   ; Initialized in subroutine starting at $5042.
329    $1800 - $1BFF   Color RAM   ; Initialized in subroutine starting at $5042.
330
331    $4000 - $7FFF   ROM
332
333    $8000 - $FFFF           ; Mirrored from $0000 - $7FFF due to lack of A15 line connection.
334
335
336
337    ---------------------------------------
338    ***  Memory Map (pottnpkr hardware) ***
339    ---------------------------------------
340
341    $0000 - $00FF   RAM     ; Zero Page (pointers and registers)
342    $0100 - $01FF   RAM     ; 6502 Stack Pointer.
343    $0200 - $02FF   RAM     ; R/W. (settings)
344    $0300 - $03FF   RAM     ; R/W (mainly to $0383). $0340 - $035f (settings).
345
346    $0800 - $0801   MC6845  ; MC6845 use $0800 for register addressing and $0801 for register values.
347
348    $0844 - $0847   PIA0    ; Muxed inputs and lamps.
349    $0848 - $084B   PIA1    ; Sound writes and muxed inputs selector.
350
351    $1000 - $13FF   Video RAM
352    $1800 - $1BFF   Color RAM
353
354    $2000 - $3FFF   ROM space
355
356    $4000 - $7FFF           ; Mirrored from $0000 - $3FFF due to lack of A14 & A15 lines connection.
357    $8000 - $BFFF           ; Mirrored from $0000 - $3FFF due to lack of A14 & A15 lines connection.
358    $C000 - $FFFF           ; Mirrored from $0000 - $3FFF due to lack of A14 & A15 lines connection.
359
360
361
362*******************************************************************************
363
364
365    Buttons/Inputs   goldnpkr goldnpkb  pmpoker  bsuerte goodluck pottnpkr potnpkra potnpkrc potnpkrb
366    -------------------------------------------------------------------------------------------------
367
368    HOLD (5 buttons)  mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped
369    CANCEL            mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped
370    BIG               mapped   mapped   mapped   mapped    ----     ----     ----     ----     ----
371    SMALL             mapped   mapped   mapped   mapped    ----     ----     ----     ----     ----
372    DOUBLE UP         mapped   mapped   mapped   mapped    ----     ----     ----     ----     ----
373    TAKE SCORE        mapped   mapped   mapped   mapped    ----     ----     ----     ----     ----
374    DEAL/DRAW         mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped
375    BET               mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped
376
377    Coin 1 (coins)    mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped
378    Coin 2 (notes)    mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped   fixed 1c-1c
379    Coin 3 (coupons)  mapped   mapped   mapped   mapped    ----     ----     ----     ----     ----
380    Payout            mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped
381    Manual Collect    mapped   mapped   mapped    ----    mapped   mapped   mapped   mapped   mapped
382
383    LEARN/SETTINGS    mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped
384    METERS            mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped   mapped
385
386
387    Inputs are different for some games. Normally each button has only one function.
388    In pmpoker some buttons have different functions.
389
390
391*******************************************************************************
392
393
394    DRIVER UPDATES:
395
396
397    [2006-09-02]
398
399    - Initial release.
400
401
402    [2006-09-06]
403
404    - Understood the GFX banks:
405        - 1 bank (1bpp) for text layer and minor graphics.
406        - 1 bank (3bpp) for the undumped cards deck graphics.
407
408    - Partially added inputs through 6821 PIAs.
409        ("Bitte techniker rufen" error messages. Press 'W' to reset the machine)
410
411    - Confirmed the CPU as 6502. (was in doubt due to use of illegal opcodes)
412
413
414    [2006-09-15]
415
416    - Confirmed the GFX banks (a complete dump appeared!).
417    - Improved technical notes and added a PCB layout based on PCB picture.
418    - Found and fixed the 3rd bitplane of BigBoy gfx.
419    - Renamed Big-Boy to Golden Poker Double Up. (Big-Boy and Mini-Boy are names of cabinet models).
420    - Added 'Joker Poker' (Golden Poker version without the 'double-up' feature).
421    - Added 'Jack Potten's Poker' (same as Joker Poker, but with 'Aces or better' instead of jacks).
422    - Simulated colors for all sets till color PROMs appear.
423    - Fixed bit corruption in goldnpkr rom u40_4a.bin.
424    - Completed inputs in all sets (except DIP switches).
425    - Removed flags GAME_WRONG_COLORS and GAME_IMPERFECT_GRAPHICS in all sets.
426    - Removed flag GAME_NOT_WORKING. All sets are now playable. :)
427
428
429    [2006-10-09]
430
431    - Added service/settings mode to pmpoker.
432    - Added PORT_IMPULSE to manage correct timings for most inputs in all games.
433      (jokerpkr still trigger more than 1 credit for coin pulse).
434
435
436    [2007-02-01]
437
438    - Crystal documented via #define.
439    - CPU clock derived from #defined crystal value.
440    - Replaced simulated colors with proper color prom decode.
441    - Renamed "Golden Poker Double Up" to "Golden Poker Double Up (Big Boy)".
442    - Added set Golden Poker Double Up (Mini Boy).
443    - Cleaned up the driver a bit.
444    - Updated technical notes.
445
446
447    [2007-05-05]
448
449    - Removed all inputs hacks.
450    - Connected both PIAs properly.
451    - Demuxed all inputs for each game.
452    - Documented all outputs.
453    - Added lamps support.
454    - Created different layout files to cover each game.
455    - Add NVRAM support to all games.
456    - Corrected the color PROM status for each set.
457    - Figured out most of the DIP switches.
458    - Added diplocations to goldnpkb.
459    - Replaced the remaining IPT_SERVICE with IPT_BUTTON for regular buttons.
460    - Updated technical notes.
461    - Cleaned up the driver. Now is better organized and documented.
462
463
464    [2007-07-07]
465
466    - Added set goldnpkc (Golden Poker without the double up feature).
467    - Updated technical notes.
468
469
470    [2008-10-12] *** REWRITE ***
471
472    - Added discrete sound support to Golden Poker hardware games based on schematics.
473    - Added discrete sound support to Potten's Poker hardware games based on PCB analysis.
474    - Added discrete circuitry diagrams for both hardware types.
475    - Adjusted the CPU adressing to 15 bits for pmpoker/goldenpkr hardware.
476    - Adjusted the CPU adressing to 14 bits for pottnpkr hardware.
477    - Rewrote all the ROM loads based on these changes.
478    - Defined MASTER Xtal & CPU clock.
479    - Fixed the visible area based on M6845 registers.
480    - Improved the lamps layouts to be more realistic.
481    - Added Good Luck (potten's poker hybrid running in goldnpkr hardware).
482    - Added Buena Suerte (spanish) x 2 sets.
483    - Added set Royale.
484    - Added Witch Card and spanish variants.
485    - Added Super Loco 93 (spanish) x 2 sets.
486    - Renamed set goldnpkc to pottnpkr (parent Jack Potten's Poker set).
487    - Renamed set jokerpkr to potnpkra, since is another Jack Potten's Poker set.
488    - Added other 2 clones of Jack Potten's Poker.
489    - Renamed/cleaned all sets based on code/hardware analysis.
490    - Added intensity bit to the color system.
491    - Implemented the blue killer bit for Witch Card hardware.
492    - Implemented the extended graphics addressing bit for Witch Card hardware.
493    - Added proper visible area to sloco93.
494    - Rewrote the graphics & color decode system based on schematics. No more patched codes.
495    - Changed the char gfx bank structure and rom load according to the new routines.
496    - Adjusted the amount of color codes and PROM region size accordingly.
497    - Updated all notes.
498
499
500    TODO:
501
502    - Analyze the code of other upcoming clones to see if worth the inclusion.
503    - Inputs & lamps for Royale.
504    - Final cleanup and split the driver.
505
506
507*******************************************************************************/
508
509
510#define MASTER_CLOCK   XTAL_10MHz
511#define CPU_CLOCK      (MASTER_CLOCK/16)
512
513#include "driver.h"
514#include "video/mc6845.h"
515#include "machine/6821pia.h"
516#include "sound/discrete.h"
517
518#include "pmpoker.lh"
519#include "goldnpkr.lh"
520#include "pottnpkr.lh"
521
522
523/*************************
524*     Video Hardware     *
525*************************/
526
527static tilemap *bg_tilemap;
528
529static WRITE8_HANDLER( pmpoker_videoram_w )
530{
531   videoram[offset] = data;
532   tilemap_mark_tile_dirty(bg_tilemap, offset);
533}
534
535static WRITE8_HANDLER( pmpoker_colorram_w )
536{
537   colorram[offset] = data;
538   tilemap_mark_tile_dirty(bg_tilemap, offset);
539}
540
541static TILE_GET_INFO( get_bg_tile_info )
542{
543/*  - bits -
544    7654 3210
545    --xx xx--   tiles color.
546    ---- --x-   tiles bank.
547    ---- ---x   tiles extended address (MSB).
548    xx-- ----   unused.
549*/
550
551   int attr = colorram[tile_index];
552   int code = ((attr & 1) << 8) | videoram[tile_index];
553   int bank = (attr & 0x02) >> 1;   /* bit 1 switch the gfx banks */
554    int color = (attr & 0x3c) >> 2;   /* bits 2-3-4-5 for color */
555
556   SET_TILE_INFO(bank, code, color, 0);
557}
558
559static VIDEO_START( pmpoker )
560{
561   bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan_rows, 8, 8, 32, 29);
562}
563
564static VIDEO_UPDATE( pmpoker )
565{
566   tilemap_draw(bitmap, cliprect, bg_tilemap, 0, 0);
567   return 0;
568}
569
570static PALETTE_INIT( goldnpkr )
571{
572/*  prom bits
573    7654 3210
574    ---- ---x   red component.
575    ---- --x-   green component.
576    ---- -x--   blue component.
577    ---- x---   intensity.
578    xxxx ----   unused.
579*/
580   int i;
581
582   /* 0000IBGR */
583   if (color_prom == 0) return;
584
585   for (i = 0;i < machine->config->total_colors;i++)
586   {
587      int bit0, bit1, bit2, r, g, b, inten, intenmin, intenmax;
588
589      intenmin = 0xe0;
590//      intenmin = 0xc2;    /* 2.5 Volts (75.757575% of the whole range) */
591      intenmax = 0xff;   /* 3.3 Volts (the whole range) */
592
593      /* intensity component */
594      inten = (color_prom[i] >> 3) & 0x01;
595
596      /* red component */
597      bit0 = (color_prom[i] >> 0) & 0x01;
598      r = (bit0 * intenmin) + (inten * (bit0 * (intenmax - intenmin)));
599
600      /* green component */
601      bit1 = (color_prom[i] >> 1) & 0x01;
602      g = (bit1 * intenmin) + (inten * (bit1 * (intenmax - intenmin)));
603
604      /* blue component */
605      bit2 = (color_prom[i] >> 2) & 0x01;
606      b = (bit2 * intenmin) + (inten * (bit2 * (intenmax - intenmin)));
607
608
609      palette_set_color(machine, i, MAKE_RGB(r, g, b));
610   }
611}
612
613static PALETTE_INIT( witchcrd )
614{
615/*
616    This hardware has a feature called BLUE KILLER.
617    Using the original intensity line, the PCB has a bridge
618    that allow (as default) turn the background black.
619
620    Except goodluck, all other games running in this hardware
621    were designed to wear black background.
622
623    7654 3210
624    ---- ---x   red component.
625    ---- --x-   green component.
626    ---- -x--   blue component.
627    ---- x---   blue killer.
628    xxxx ----   unused.
629*/
630   int i;
631
632   /* 0000KBGR */
633
634   if (color_prom == 0) return;
635
636   for (i = 0;i < machine->config->total_colors;i++)
637   {
638      int bit0, bit1, bit2, bit3, r, g, b, bk;
639
640      /* blue killer (from schematics) */
641        bit3 = (color_prom[i] >> 3) & 0x01;
642        bk = bit3;
643
644      /* red component */
645      bit0 = (color_prom[i] >> 0) & 0x01;
646      r = (bit0 * 0xff);
647
648      /* green component */
649      bit1 = (color_prom[i] >> 1) & 0x01;
650      g = (bit1 * 0xff);
651
652      /* blue component */
653      bit2 = (color_prom[i] >> 2) & 0x01;
654      b = bk * (bit2 * 0xff);
655
656      palette_set_color(machine, i, MAKE_RGB(r, g, b));
657   }
658}
659
660
661/***********************
662*     R/W Handlers     *
663***********************/
664
665static int input_selector = 0;
666
667/* Inputs (buttons) are multiplexed.
668   There are 4 sets of 5 bits each and are connected to PIA0, portA.
669   The selector bits are located in PIA1, portB (bits 4-7).
670*/
671static READ8_HANDLER( mux_port_r )
672{
673   switch( input_selector )
674   {
675      case 0x10: return input_port_read(space->machine, "IN0-0");
676      case 0x20: return input_port_read(space->machine, "IN0-1");
677      case 0x40: return input_port_read(space->machine, "IN0-2");
678      case 0x80: return input_port_read(space->machine, "IN0-3");
679   }
680   return 0xff;
681}
682
683static WRITE8_HANDLER( mux_port_w )
684{
685//  popmessage("written : %02X", data);
686   input_selector = (data ^ 0xff) & 0xf0;   /* bits 4-7, inverted */
687}
688
689/***** Lamps wiring *****
690
691    -------------------
692    pmpoker
693    -------------------
694    L0 = Deal
695    L1 = Hold3
696    L2 = Hold1
697    L3 = Hold5
698    L4 = Hold2 & Hold4
699
700    -----------------------
701    goldnpkr sets & bsuerte
702    -----------------------
703    L0 = Bet
704    L1 = Deal
705    L2 = Holds (all)
706    L3 = Double Up & Take
707    L4 = Big & Small
708
709    ----------------------------------
710    pottnpkr sets, jokerpkr & goodluck
711    ----------------------------------
712    L0 = Bet
713    L1 = Deal
714    L2 = Holds (all)
715
716    ------------------
717    witchcrd & sloco93
718    ------------------
719    NONE. Just lack of lamps...
720
721*/
722
723static WRITE8_HANDLER( lamps_a_w )
724{
725   output_set_lamp_value(0, 1 - ((data) & 1));         /* Lamp 0 */
726   output_set_lamp_value(1, 1 - ((data >> 1) & 1));   /* Lamp 1 */
727   output_set_lamp_value(2, 1 - ((data >> 2) & 1));   /* Lamp 2 */
728   output_set_lamp_value(3, 1 - ((data >> 3) & 1));   /* Lamp 3 */
729   output_set_lamp_value(4, 1 - ((data >> 4) & 1));   /* Lamp 4 */
730
731   coin_counter_w(0, data & 0x40);   /* Coin1 */
732   coin_counter_w(1, data & 0x80);   /* Note */
733
734/*  Counters:
735
736    bit 5 = Coin out
737    bit 6 = Coin counter
738    bit 7 = Note counter (only goldnpkr use it)
739
740    ONLY for witchcrd and sloco93 sets:
741
742    bit3 = Coin counter (inverted).
743    bit5 = Coin out (inverted).
744*/
745}
746
747static WRITE8_HANDLER( sound_w )
748{
749   /* 555 voltage controlled */
750   logerror("Sound Data: %2x\n",data & 0x0f);
751
752   /* discrete sound is connected to PIA1, portA: bits 0-3 */
753   discrete_sound_w(space,NODE_01, data >> 3 & 0x01);
754   discrete_sound_w(space,NODE_10, data & 0x07);
755}
756
757
758/*************************
759* Memory Map Information *
760*************************/
761
762static ADDRESS_MAP_START( pmpoker_map, ADDRESS_SPACE_PROGRAM, 8 )
763   ADDRESS_MAP_GLOBAL_MASK(0x7fff)
764   AM_RANGE(0x0000, 0x07ff) AM_RAM AM_BASE(&generic_nvram) AM_SIZE(&generic_nvram_size)   /* battery backed RAM */
765   AM_RANGE(0x0800, 0x0800) AM_DEVWRITE(MC6845, "crtc", mc6845_address_w)
766   AM_RANGE(0x0801, 0x0801) AM_DEVREADWRITE(MC6845, "crtc", mc6845_register_r, mc6845_register_w)
767   AM_RANGE(0x0844, 0x0847) AM_READWRITE(pia_0_r, pia_0_w)
768   AM_RANGE(0x0848, 0x084b) AM_READWRITE(pia_1_r, pia_1_w)
769   AM_RANGE(0x1000, 0x13ff) AM_RAM_WRITE(pmpoker_videoram_w) AM_BASE(&videoram)
770   AM_RANGE(0x1800, 0x1bff) AM_RAM_WRITE(pmpoker_colorram_w) AM_BASE(&colorram)
771   AM_RANGE(0x4000, 0x7fff) AM_ROM
772ADDRESS_MAP_END
773
774static ADDRESS_MAP_START( pottnpkr_map, ADDRESS_SPACE_PROGRAM, 8 )
775   ADDRESS_MAP_GLOBAL_MASK(0x3fff)
776   AM_RANGE(0x0000, 0x07ff) AM_RAM AM_BASE(&generic_nvram) AM_SIZE(&generic_nvram_size)   /* battery backed RAM */
777   AM_RANGE(0x0800, 0x0800) AM_DEVWRITE(MC6845, "crtc", mc6845_address_w)
778   AM_RANGE(0x0801, 0x0801) AM_DEVREADWRITE(MC6845, "crtc", mc6845_register_r, mc6845_register_w)
779   AM_RANGE(0x0844, 0x0847) AM_READWRITE(pia_0_r, pia_0_w)
780   AM_RANGE(0x0848, 0x084b) AM_READWRITE(pia_1_r, pia_1_w)
781   AM_RANGE(0x1000, 0x13ff) AM_RAM_WRITE(pmpoker_videoram_w) AM_BASE(&videoram)
782   AM_RANGE(0x1800, 0x1bff) AM_RAM_WRITE(pmpoker_colorram_w) AM_BASE(&colorram)
783   AM_RANGE(0x2000, 0x3fff) AM_ROM
784ADDRESS_MAP_END
785
786
787/*************************
788*      Input Ports       *
789*************************/
790
791static INPUT_PORTS_START( pmpoker )
792   /* Multiplexed - 4x5bits */
793   PORT_START("IN0-0")
794   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNKNOWN )
795   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Meters") PORT_CODE(KEYCODE_9)
796   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
797   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("Deal/Draw") PORT_CODE(KEYCODE_2)
798   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
799   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
800   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
801   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
802
803   PORT_START("IN0-1")
804   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_IMPULSE(3) PORT_NAME("Out (Manual Collect)") PORT_CODE(KEYCODE_Q)
805   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("Payout") PORT_CODE(KEYCODE_W)
806   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
807   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )
808   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
809   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
810   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
811   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
812
813   PORT_START("IN0-2")
814   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("Hold1 / Take Score (Kasse)") PORT_CODE(KEYCODE_Z)
815   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("Hold2 / Small (Tief)") PORT_CODE(KEYCODE_X)
816   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("Hold3 / Bet (Setze)") PORT_CODE(KEYCODE_C)
817   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("Hold4 / Big (Hoch)") PORT_CODE(KEYCODE_V)
818   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("Hold5 / Double Up (Dopp.)") PORT_CODE(KEYCODE_B)
819   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
820   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
821   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
822
823   PORT_START("IN0-3")
824   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Settings") PORT_CODE(KEYCODE_F2)
825   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNKNOWN )
826   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN2 )   PORT_IMPULSE(3) PORT_NAME("Note 1 In")
827   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_COIN1 )   PORT_IMPULSE(3) PORT_NAME("Coin In")
828   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_COIN3 )   PORT_NAME("Note 2 In")
829   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
830   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
831   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
832
833   PORT_START("SW1")
834   PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unknown ) )
835   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
836   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
837   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
838   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
839   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
840   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
841   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
842   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
843   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
844   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
845   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
846   PORT_DIPNAME( 0x10, 0x10, "Hohes Paar (Jacks or Better)" )
847   PORT_DIPSETTING(    0x10, DEF_STR( No ) )
848   PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
849   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
850   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
851   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
852   PORT_DIPNAME( 0x40, 0x00, "Payout Mode" )
853   PORT_DIPSETTING(    0x40, "Manual" )
854   PORT_DIPSETTING(    0x00, "Auto" )
855   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
856   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
857   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
858INPUT_PORTS_END
859
860static INPUT_PORTS_START( goldnpkr )
861   /* Multiplexed - 4x5bits */
862   PORT_START("IN0-0")
863   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("Bet") PORT_CODE(KEYCODE_1)
864   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Meters") PORT_CODE(KEYCODE_9)
865   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON9 ) PORT_NAME("Double Up") PORT_CODE(KEYCODE_3)
866   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("Deal/Draw") PORT_CODE(KEYCODE_2)
867   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("Cancel") PORT_CODE(KEYCODE_N)
868   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
869   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
870   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
871
872   PORT_START("IN0-1")
873   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON13 ) PORT_IMPULSE(3) PORT_NAME("Out (Manual Collect)") PORT_CODE(KEYCODE_Q)
874   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON14 ) PORT_NAME("Off (Payout)") PORT_CODE(KEYCODE_W)
875   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON10 ) PORT_NAME("Take") PORT_CODE(KEYCODE_4)
876   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON11 ) PORT_NAME("Big") PORT_CODE(KEYCODE_A)
877   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON12 ) PORT_NAME("Small") PORT_CODE(KEYCODE_S)
878   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
879   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
880   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
881
882   PORT_START("IN0-2")
883   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("Hold1") PORT_CODE(KEYCODE_Z)
884   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("Hold2") PORT_CODE(KEYCODE_X)
885   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("Hold3") PORT_CODE(KEYCODE_C)
886   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("Hold4") PORT_CODE(KEYCODE_V)
887   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("Hold5") PORT_CODE(KEYCODE_B)
888   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
889   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
890   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
891
892   PORT_START("IN0-3")
893   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Learn Mode") PORT_CODE(KEYCODE_F2)
894   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("D-31") PORT_CODE(KEYCODE_E)   /* O.A.R? (D-31 in schematics) */
895   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN2 )   PORT_NAME("Coupon (Note In)")
896   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_COIN1 )   PORT_IMPULSE(3) PORT_NAME("Coin In")
897   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_COIN3 )   PORT_NAME("Weight (Coupon In)")
898   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
899   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
900   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
901
902   PORT_START("SW1")
903   /* only bits 4-7 are connected here and were routed to SW1 1-4 */
904   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
905   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
906   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
907   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
908   PORT_DIPNAME( 0x10, 0x00, "Jacks or Better" )   PORT_DIPLOCATION("SW1:1")
909   PORT_DIPSETTING(    0x10, DEF_STR( No ) )
910   PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
911   PORT_DIPNAME( 0x20, 0x20, "50hz/60hz" )         PORT_DIPLOCATION("SW1:2")
912   PORT_DIPSETTING(    0x20, "50hz" )
913   PORT_DIPSETTING(    0x00, "60hz" )
914   PORT_DIPNAME( 0x40, 0x00, "Payout Mode" )      PORT_DIPLOCATION("SW1:3")   /* listed in the manual as "Play Mode" */
915   PORT_DIPSETTING(    0x40, "Manual" )         /*  listed in the manual as "Out Play" */
916   PORT_DIPSETTING(    0x00, "Auto" )            /*  listed in the manual as "Credit Play" */
917   PORT_DIPNAME( 0x80, 0x00, "Royal Flush" )      PORT_DIPLOCATION("SW1:4")
918   PORT_DIPSETTING(    0x80, DEF_STR( No ) )
919   PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
920INPUT_PORTS_END
921
922static INPUT_PORTS_START( bsuerte )
923   /* Multiplexed - 4x5bits */
924   PORT_START("IN0-0")
925   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("Apostar (Bet)") PORT_CODE(KEYCODE_1)
926   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Contabilidad (Meters)") PORT_CODE(KEYCODE_9)
927   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON9 ) PORT_NAME("Doblar (Double Up)") PORT_CODE(KEYCODE_3)
928   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("Dar/Virar (Deal/Draw)") PORT_CODE(KEYCODE_2)
929   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("Cancelar (Cancel)") PORT_CODE(KEYCODE_N)
930   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
931   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
932   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
933
934   PORT_START("IN0-1")
935   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON13 ) PORT_IMPULSE(3) PORT_NAME("Out (Manual Collect)") PORT_CODE(KEYCODE_Q)
936   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON14 ) PORT_NAME("Pagar (Payout)") PORT_CODE(KEYCODE_W)
937   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON10 ) PORT_NAME("Cobrar (Take)") PORT_CODE(KEYCODE_4)
938   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON11 ) PORT_NAME("Mayor (Big)") PORT_CODE(KEYCODE_A)
939   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON12 ) PORT_NAME("Menor (Small)") PORT_CODE(KEYCODE_S)
940   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
941   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
942   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
943
944   PORT_START("IN0-2")
945   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("Hold1") PORT_CODE(KEYCODE_Z)
946   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("Hold2") PORT_CODE(KEYCODE_X)
947   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("Hold3") PORT_CODE(KEYCODE_C)
948   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("Hold4") PORT_CODE(KEYCODE_V)
949   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("Hold5") PORT_CODE(KEYCODE_B)
950   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
951   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
952   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
953
954   PORT_START("IN0-3")
955   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Configuracion (settings)") PORT_CODE(KEYCODE_F2)
956   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNKNOWN )
957   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN2 )   PORT_NAME("Billetes (Note In)")
958   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_COIN1 )   PORT_IMPULSE(3) PORT_NAME("Fichas (Coin In)")
959   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_COIN3 )   PORT_NAME("Cupones (Coupon In)")
960   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
961   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
962   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
963
964   PORT_START("SW1")
965   /* only bits 4-7 are connected here and were routed to SW1 1-4 */
966   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
967   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
968   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
969   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
970   PORT_DIPNAME( 0x10, 0x00, "Jotas o Mejores" )   PORT_DIPLOCATION("SW1:1")
971   PORT_DIPSETTING(    0x10, DEF_STR( No ) )
972   PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
973   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )   PORT_DIPLOCATION("SW1:2")
974   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
975   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
976   PORT_DIPNAME( 0x40, 0x00, "Modo de Pago" )      PORT_DIPLOCATION("SW1:3")   /* left as 'auto' */
977   PORT_DIPSETTING(    0x40, "Manual" )
978   PORT_DIPSETTING(    0x00, "Auto" )
979   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )   PORT_DIPLOCATION("SW1:4")
980   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
981   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
982INPUT_PORTS_END
983
984static INPUT_PORTS_START( goodluck )
985   /* Multiplexed - 4x5bits */
986   PORT_START("IN0-0")
987   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("Bet") PORT_CODE(KEYCODE_1)
988   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Meters") PORT_CODE(KEYCODE_9)
989   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
990   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("Deal/Draw") PORT_CODE(KEYCODE_2)
991   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("Cancel") PORT_CODE(KEYCODE_N)
992   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
993   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
994   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
995
996   PORT_START("IN0-1")
997   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON9 )  PORT_IMPULSE(3) PORT_NAME("Manual Collect") PORT_CODE(KEYCODE_Q)
998   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON10 ) PORT_NAME("Payout") PORT_CODE(KEYCODE_W)
999   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
1000   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )
1001   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
1002   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1003   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1004   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1005
1006   PORT_START("IN0-2")
1007   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("Hold1") PORT_CODE(KEYCODE_Z)
1008   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("Hold2") PORT_CODE(KEYCODE_X)
1009   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("Hold3") PORT_CODE(KEYCODE_C)
1010   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("Hold4") PORT_CODE(KEYCODE_V)
1011   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("Hold5") PORT_CODE(KEYCODE_B)
1012   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1013   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1014   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1015
1016   PORT_START("IN0-3")
1017   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Settings") PORT_CODE(KEYCODE_F2)
1018   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNKNOWN )
1019   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN2 )   PORT_NAME("Note In")
1020   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_COIN1 )   PORT_IMPULSE(3) PORT_NAME("Coin In")
1021   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
1022   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1023   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1024   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1025
1026   PORT_START("SW1")
1027   /* only bits 4-7 are connected here and were routed to SW1 1-4 */
1028   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
1029   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
1030   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
1031   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
1032   PORT_DIPNAME( 0x10, 0x00, "Jacks or Better" )   PORT_DIPLOCATION("SW1:1")
1033   PORT_DIPSETTING(    0x10, DEF_STR( No ) )
1034   PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
1035   PORT_DIPNAME( 0x20, 0x00, DEF_STR( Unknown ) )   PORT_DIPLOCATION("SW1:2")
1036   PORT_DIPSETTING(    0x20, DEF_STR( No ) )
1037   PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
1038   PORT_DIPNAME( 0x40, 0x00, "Payout Mode" )      PORT_DIPLOCATION("SW1:3")
1039   PORT_DIPSETTING(    0x40, "Manual" )
1040   PORT_DIPSETTING(    0x00, "Auto" )
1041   PORT_DIPNAME( 0x80, 0x00, DEF_STR( Unknown ) )   PORT_DIPLOCATION("SW1:4")
1042   PORT_DIPSETTING(    0x80, DEF_STR( No ) )
1043   PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
1044INPUT_PORTS_END
1045
1046static INPUT_PORTS_START( pottnpkr )
1047   /* Multiplexed - 4x5bits */
1048   PORT_START("IN0-0")
1049   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("Bet") PORT_CODE(KEYCODE_1)
1050   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Meters") PORT_CODE(KEYCODE_9)
1051   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
1052   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("Deal/Draw") PORT_CODE(KEYCODE_2)
1053   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("Cancel") PORT_CODE(KEYCODE_N)
1054   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1055   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1056   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1057
1058   PORT_START("IN0-1")
1059   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON9 ) PORT_IMPULSE(3) PORT_NAME("Out (Manual Collect)") PORT_CODE(KEYCODE_Q)
1060   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON10 ) PORT_NAME("Off (Payout)") PORT_CODE(KEYCODE_W)
1061   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
1062   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )
1063   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
1064   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1065   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1066   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1067
1068   PORT_START("IN0-2")
1069   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("Hold1") PORT_CODE(KEYCODE_Z)
1070   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("Hold2") PORT_CODE(KEYCODE_X)
1071   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("Hold3") PORT_CODE(KEYCODE_C)
1072   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("Hold4") PORT_CODE(KEYCODE_V)
1073   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("Hold5") PORT_CODE(KEYCODE_B)
1074   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1075   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1076   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1077
1078   PORT_START("IN0-3")
1079   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Learn Mode") PORT_CODE(KEYCODE_F2)
1080   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNKNOWN )
1081   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN2 )   PORT_NAME("Coupon (Note In)")
1082   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_COIN1 )   PORT_IMPULSE(3) PORT_NAME("Coin In")
1083   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
1084   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1085   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1086   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1087
1088   PORT_START("SW1")
1089   /* only bits 4-7 are connected here and were routed to SW1 1-4 */
1090   PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unknown ) )
1091   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
1092   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1093   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
1094   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
1095   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1096   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
1097   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
1098   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1099   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
1100   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
1101   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1102   PORT_DIPNAME( 0x10, 0x00, "Jacks or Better" )   PORT_DIPLOCATION("SW1:1")
1103   PORT_DIPSETTING(    0x10, DEF_STR( No ) )
1104   PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
1105   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )   PORT_DIPLOCATION("SW1:2")
1106   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
1107   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1108   /* listed in the manual as "Play Mode" */
1109   PORT_DIPNAME( 0x40, 0x00, "Payout Mode" )      PORT_DIPLOCATION("SW1:3")
1110   PORT_DIPSETTING(    0x40, "Manual" )         /*  listed in the manual as "Out Play" */
1111   PORT_DIPSETTING(    0x00, "Auto" )            /*  listed in the manual as "Credit Play" */
1112   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )   PORT_DIPLOCATION("SW1:4")
1113   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
1114   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1115INPUT_PORTS_END
1116
1117static INPUT_PORTS_START( potnpkra )
1118   /* Multiplexed - 4x5bits */
1119   PORT_START("IN0-0")
1120   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )   PORT_IMPULSE(3) PORT_NAME("Coin 1")
1121   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Meters") PORT_CODE(KEYCODE_9)
1122   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
1123   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("Deal/Draw") PORT_CODE(KEYCODE_2)
1124   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("Cancel") PORT_CODE(KEYCODE_N)
1125   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1126   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1127   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1128
1129   PORT_START("IN0-1")
1130   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON9 )  PORT_IMPULSE(3) PORT_NAME("Out (Manual Collect)") PORT_CODE(KEYCODE_Q)
1131   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON10 ) PORT_NAME("Off (Payout)") PORT_CODE(KEYCODE_W)
1132   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
1133   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )
1134   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
1135   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1136   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1137   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1138
1139   PORT_START("IN0-2")
1140   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("Hold1") PORT_CODE(KEYCODE_Z)
1141   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("Hold2") PORT_CODE(KEYCODE_X)
1142   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("Hold3") PORT_CODE(KEYCODE_C)
1143   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("Hold4") PORT_CODE(KEYCODE_V)
1144   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("Hold5") PORT_CODE(KEYCODE_B)
1145   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1146   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1147   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1148
1149   PORT_START("IN0-3")
1150   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Settings") PORT_CODE(KEYCODE_F2)
1151   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNKNOWN )
1152   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN2 )   PORT_NAME("Note in")
1153   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("Bet") PORT_CODE(KEYCODE_1)
1154   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
1155   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1156   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1157   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1158
1159   PORT_START("SW1")
1160   PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unknown ) )
1161   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
1162   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1163   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
1164   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
1165   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1166   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
1167   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
1168   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1169   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
1170   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
1171   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1172   PORT_DIPNAME( 0x10, 0x00, "Jacks or Better" )   PORT_DIPLOCATION("SW1:1")
1173   PORT_DIPSETTING(    0x10, DEF_STR( No ) )
1174   PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
1175   PORT_DIPNAME( 0x20, 0x20, "Royal Flush Value" )   PORT_DIPLOCATION("SW1:2")
1176   PORT_DIPSETTING(    0x20, "250 by bet" )
1177   PORT_DIPSETTING(    0x00, "500 by bet" )
1178   PORT_DIPNAME( 0x40, 0x00, "Payout Mode" )      PORT_DIPLOCATION("SW1:3")
1179   PORT_DIPSETTING(    0x40, "Manual" )
1180   PORT_DIPSETTING(    0x00, "Auto" )
1181   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )   PORT_DIPLOCATION("SW1:4")
1182   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
1183   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1184INPUT_PORTS_END
1185
1186static INPUT_PORTS_START( potnpkrc )
1187   /* Multiplexed - 4x5bits */
1188   PORT_START("IN0-0")
1189   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )   PORT_IMPULSE(3) PORT_NAME("Coin 1")
1190   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Meters") PORT_CODE(KEYCODE_9)
1191   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
1192   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("Deal/Draw") PORT_CODE(KEYCODE_2)
1193   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("Cancel") PORT_CODE(KEYCODE_N)
1194   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1195   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1196   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1197
1198   PORT_START("IN0-1")
1199   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON9 )  PORT_IMPULSE(3) PORT_NAME("Out (Manual Collect)") PORT_CODE(KEYCODE_Q)
1200   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON10 ) PORT_NAME("Off (Payout)") PORT_CODE(KEYCODE_W)
1201   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
1202   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )
1203   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
1204   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1205   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1206   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1207
1208   PORT_START("IN0-2")
1209   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("Hold1") PORT_CODE(KEYCODE_Z)
1210   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("Hold2") PORT_CODE(KEYCODE_X)
1211   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("Hold3") PORT_CODE(KEYCODE_C)
1212   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("Hold4") PORT_CODE(KEYCODE_V)
1213   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("Hold5") PORT_CODE(KEYCODE_B)
1214   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1215   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1216   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1217
1218   PORT_START("IN0-3")
1219   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Settings") PORT_CODE(KEYCODE_F2)
1220   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNKNOWN )
1221   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN2 )   PORT_NAME("Note in")
1222   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("Bet") PORT_CODE(KEYCODE_1)
1223   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
1224   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1225   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1226   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1227
1228   PORT_START("SW1")
1229   PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unknown ) )
1230   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
1231   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1232   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
1233   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
1234   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1235   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
1236   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
1237   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1238   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
1239   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
1240   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1241   PORT_DIPNAME( 0x10, 0x00, "Ace or Better" )      PORT_DIPLOCATION("SW1:1")
1242   PORT_DIPSETTING(    0x10, DEF_STR( No ) )
1243   PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
1244   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )   PORT_DIPLOCATION("SW1:2")
1245   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
1246   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1247   PORT_DIPNAME( 0x40, 0x00, "Payout Mode" )      PORT_DIPLOCATION("SW1:3")
1248   PORT_DIPSETTING(    0x40, "Manual" )
1249   PORT_DIPSETTING(    0x00, "Auto" )
1250   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )   PORT_DIPLOCATION("SW1:4")
1251   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
1252   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1253INPUT_PORTS_END
1254
1255static INPUT_PORTS_START( witchcrd )
1256   /* Multiplexed - 4x5bits */
1257   PORT_START("IN0-0")
1258   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("Bet") PORT_CODE(KEYCODE_1)
1259   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Meters") PORT_CODE(KEYCODE_9)
1260   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON9 ) PORT_NAME("Double Up") PORT_CODE(KEYCODE_3)
1261   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("Deal/Draw") PORT_CODE(KEYCODE_2)
1262   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("Cancel") PORT_CODE(KEYCODE_N)
1263   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1264   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1265   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1266
1267   PORT_START("IN0-1")
1268   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON13 ) PORT_IMPULSE(3) PORT_NAME("Out (Manual Collect)") PORT_CODE(KEYCODE_Q)
1269   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON14 ) PORT_NAME("Off (Payout)") PORT_CODE(KEYCODE_W)
1270   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON10 ) PORT_NAME("Take") PORT_CODE(KEYCODE_4)
1271   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON11 ) PORT_NAME("Big") PORT_CODE(KEYCODE_A)
1272   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON12 ) PORT_NAME("Small") PORT_CODE(KEYCODE_S)
1273   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1274   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1275   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1276
1277   PORT_START("IN0-2")
1278   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("Hold1") PORT_CODE(KEYCODE_Z)
1279   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("Hold2") PORT_CODE(KEYCODE_X)
1280   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("Hold3") PORT_CODE(KEYCODE_C)
1281   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("Hold4") PORT_CODE(KEYCODE_V)
1282   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("Hold5") PORT_CODE(KEYCODE_B)
1283   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1284   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1285   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1286
1287   PORT_START("IN0-3")
1288   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Learn Mode") PORT_CODE(KEYCODE_F2)
1289   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("D-31") PORT_CODE(KEYCODE_E)
1290   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN2 )   PORT_NAME("Note In")
1291   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_COIN1 )   PORT_IMPULSE(3) PORT_NAME("Coin In")
1292   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
1293   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1294   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1295   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1296
1297   PORT_START("SW1")
1298   /* only bits 4-7 are connected here and were routed to SW1 1-4 */
1299   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
1300   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
1301   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
1302   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
1303   PORT_DIPNAME( 0x10, 0x00, "Jacks or Better" )      PORT_DIPLOCATION("SW1:1")
1304   PORT_DIPSETTING(    0x10, DEF_STR( No ) )
1305   PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
1306   PORT_DIPNAME( 0x20, 0x00, "Won Credits Counter" )   PORT_DIPLOCATION("SW1:2")
1307   PORT_DIPSETTING(    0x20, "Show" )
1308   PORT_DIPSETTING(    0x00, "Hide" )
1309   PORT_DIPNAME( 0x40, 0x00, "Payout Mode" )         PORT_DIPLOCATION("SW1:3")
1310   PORT_DIPSETTING(    0x40, "Manual" )
1311   PORT_DIPSETTING(    0x00, "Auto" )
1312   PORT_DIPNAME( 0x80, 0x00, DEF_STR( Coinage ) )      PORT_DIPLOCATION("SW1:4")
1313   /* Note In is always 1 Note - 10 Credits */
1314   PORT_DIPSETTING(    0x00, "1 Coin - 1 Credit / 1 Note - 10 Credits" )
1315   PORT_DIPSETTING(    0x80, "1 Coin - 5 Credits / 1 Note - 10 Credits" )
1316INPUT_PORTS_END
1317
1318static INPUT_PORTS_START( sloco93 )
1319   /* Multiplexed - 4x5bits */
1320   PORT_START("IN0-0")
1321   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("Apuesta/Bet") PORT_CODE(KEYCODE_1)
1322   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Bookkeeping") PORT_CODE(KEYCODE_9)
1323   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON9 ) PORT_NAME("Double Up") PORT_CODE(KEYCODE_3)
1324   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("Reparte/Deal") PORT_CODE(KEYCODE_2)
1325   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("Cancela/Cancel") PORT_CODE(KEYCODE_N)
1326   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1327   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1328   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1329
1330   PORT_START("IN0-1")
1331   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON13 ) PORT_IMPULSE(3) PORT_NAME("Out (Manual Collect)") PORT_CODE(KEYCODE_Q)
1332   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON14 ) PORT_NAME("Off (Payout)") PORT_CODE(KEYCODE_W)
1333   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON10 ) PORT_NAME("Take") PORT_CODE(KEYCODE_4)
1334   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON11 ) PORT_NAME("Big") PORT_CODE(KEYCODE_A)
1335   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON12 ) PORT_NAME("Small") PORT_CODE(KEYCODE_S)
1336   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1337   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1338   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1339
1340   PORT_START("IN0-2")
1341   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("Hold1") PORT_CODE(KEYCODE_Z)
1342   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("Hold2") PORT_CODE(KEYCODE_X)
1343   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("Hold3") PORT_CODE(KEYCODE_C)
1344   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("Hold4") PORT_CODE(KEYCODE_V)
1345   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("Hold5") PORT_CODE(KEYCODE_B)
1346   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1347   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1348   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1349
1350   PORT_START("IN0-3")
1351   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Learn Mode") PORT_CODE(KEYCODE_F2)
1352   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("D-31") PORT_CODE(KEYCODE_E)
1353   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN2 )   PORT_NAME("Note In")
1354   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_COIN1 )   PORT_IMPULSE(3) PORT_NAME("Coin In")
1355   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
1356   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1357   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1358   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
1359
1360   PORT_START("SW1")
1361   /* only bits 4-7 are connected here and were routed to SW1 1-4 */
1362   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
1363   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
1364   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
1365   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
1366   PORT_DIPNAME( 0x10, 0x00, "32 Simple" )            PORT_DIPLOCATION("SW1:1")
1367   PORT_DIPSETTING(    0x10, DEF_STR( No ) )
1368   PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
1369   PORT_DIPNAME( 0x20, 0x00, "Won Credits Counter" )   PORT_DIPLOCATION("SW1:2")
1370   PORT_DIPSETTING(    0x20, "Show" )
1371   PORT_DIPSETTING(    0x00, "Hide" )
1372   PORT_DIPNAME( 0x40, 0x00, "Payout Mode" )         PORT_DIPLOCATION("SW1:3")
1373   PORT_DIPSETTING(    0x40, "Manual" )
1374   PORT_DIPSETTING(    0x00, "Auto" )
1375   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Coinage ) )      PORT_DIPLOCATION("SW1:4")
1376   PORT_DIPSETTING(    0x80, "1 Coin - 10 Credit / 1 Note - 120 Credits" )
1377   PORT_DIPSETTING(    0x00, "1 Coin - 100 Credits / 1 Note - 100 Credits" )
1378INPUT_PORTS_END
1379
1380static INPUT_PORTS_START( royale )
1381   PORT_START("IN0-0")
1382   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("0-1") PORT_CODE(KEYCODE_1)
1383   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("0-2") PORT_CODE(KEYCODE_2)
1384   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("0-3") PORT_CODE(KEYCODE_3)
1385   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("0-4") PORT_CODE(KEYCODE_4)
1386   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("0-5") PORT_CODE(KEYCODE_5)
1387   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("0-6") PORT_CODE(KEYCODE_6)
1388   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("0-7") PORT_CODE(KEYCODE_7)
1389   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("0-8") PORT_CODE(KEYCODE_8)
1390
1391   PORT_START("IN0-1")
1392   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("1-1") PORT_CODE(KEYCODE_Q)
1393   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("1-2") PORT_CODE(KEYCODE_W)
1394   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("1-3") PORT_CODE(KEYCODE_E)
1395   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("1-4") PORT_CODE(KEYCODE_R)
1396   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("1-5") PORT_CODE(KEYCODE_T)
1397   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("1-6") PORT_CODE(KEYCODE_Y)
1398   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("1-7") PORT_CODE(KEYCODE_U)
1399   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("1-8") PORT_CODE(KEYCODE_I)
1400
1401   PORT_START("IN0-2")
1402   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("2-1") PORT_CODE(KEYCODE_A)
1403   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("2-2") PORT_CODE(KEYCODE_S)
1404   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("2-3") PORT_CODE(KEYCODE_D)
1405   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("2-4") PORT_CODE(KEYCODE_F)
1406   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("2-5") PORT_CODE(KEYCODE_G)
1407   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("2-6") PORT_CODE(KEYCODE_H)
1408   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("2-7") PORT_CODE(KEYCODE_J)
1409   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("2-8") PORT_CODE(KEYCODE_K)
1410
1411   PORT_START("IN0-3")
1412   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("3-1") PORT_CODE(KEYCODE_Z)
1413   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("3-2") PORT_CODE(KEYCODE_X)
1414   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("3-3") PORT_CODE(KEYCODE_C)
1415   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("3-4") PORT_CODE(KEYCODE_V)
1416   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("3-5") PORT_CODE(KEYCODE_B)
1417   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("3-6") PORT_CODE(KEYCODE_N)
1418   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("3-7") PORT_CODE(KEYCODE_M)
1419   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("3-8") PORT_CODE(KEYCODE_L)
1420
1421   PORT_START("SW1")
1422   PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unknown ) )
1423   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
1424   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1425   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
1426   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
1427   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1428   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
1429   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
1430   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1431   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
1432   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
1433   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1434   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
1435   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
1436   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1437   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
1438   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
1439   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1440   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
1441   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
1442   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1443   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
1444   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
1445   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1446INPUT_PORTS_END
1447
1448
1449/*************************
1450*    Graphics Layouts    *
1451*************************/
1452
1453static const gfx_layout tilelayout =
1454{
1455   8, 8,
1456   RGN_FRAC(1,3),
1457   3,
1458   { 0, RGN_FRAC(1,3), RGN_FRAC(2,3) },
1459   { 0, 1, 2, 3, 4, 5, 6, 7 },
1460   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
1461   8*8
1462};
1463
1464
1465/******************************
1466* Graphics Decode Information *
1467******************************/
1468
1469static GFXDECODE_START( pmpoker )
1470   GFXDECODE_ENTRY( "gfx1", 0, tilelayout, 0, 16 )
1471   GFXDECODE_ENTRY( "gfx2", 0, tilelayout, 0, 16 )
1472GFXDECODE_END
1473
1474
1475/***********************
1476*    PIA Interfaces    *
1477***********************/
1478
1479static const pia6821_interface pia0_intf =
1480{
1481   /* PIA inputs: A, B, CA1, CB1, CA2, CB2 */
1482   mux_port_r, 0, 0, 0, 0, 0,
1483
1484   /* PIA outputs: A, B, CA2, CB2 */
1485   0, lamps_a_w, 0, 0,
1486
1487   /* PIA IRQs: A, B */
1488   0, 0
1489};
1490
1491static const pia6821_interface pia1_intf =
1492{
1493   /* PIA inputs: A, B, CA1, CB1, CA2, CB2 */
1494   input_port_4_r, 0, 0, 0, 0, 0,
1495
1496   /* PIA outputs: A, B, CA2, CB2 */
1497
1498   sound_w, mux_port_w, 0, 0,
1499
1500   /* PIA IRQs: A, B */
1501   0, 0
1502};
1503
1504
1505/**************************************
1506*       Discrete Sound Routines       *
1507***************************************
1508
1509    Golden Poker Double-Up discrete sound circuitry.
1510    ------------------------------------------------
1511
1512           +12V                            .--------+---------------.  +5V
1513            |                              |        |               |   |
1514         .--+                              |        Z             +-------+
1515         |  |                             8|        Z 1K          | PC617 |
1516         Z  Z                         +----+----+   Z             +-------+
1517    330K Z  Z 47K                     |   VCC   |3  |   20K   1uF  |     |
1518         Z  Z             1.7uF       |        Q|---|--ZZZZZ--||---+     Z   1uF         6|\
1519         |  |            .-||-- GND   |         |7  |              |  1K Z<--||--+--------| \
1520         |  |   30K      |           4|      DIS|---+              Z     Z       |   LM380|  \  220uF
1521  PA0 ---|--|--ZZZZZ--.  |      .-----|R        |   |         2.2K Z     |       Z        |  8>--||----> Audio Out.
1522         |  |         |  |      |     |   555   |   Z              Z    -+-  10K Z     7+-|  /
1523         |  |   15K   |  |      |    5|         |   Z 10K          |    GND      Z     3+-| /-.1   .---> Audio Out.
1524  PA1 ---+--|--ZZZZZ--+--+------|-----|CV       |   Z              |             |     2+-|/  |    |
1525            |         |         |    2|         |6  |              |             |      |     |    |
1526            |  7.5K   |         |  .--|TR    THR|---+---||---------+-------------+      +-||--'    |
1527  PA2 ------+--ZZZZZ--'  |\     |  |  |   GND   |   |                            |      |          |
1528                         | \    |  |  +----+----+   |  .1uF                      |      | 10uF     |
1529                        9|  \   |  |      1|        |                           -+-     |          |
1530  PA3 -------------------|  8>--'  |      -+-       |                           GND     +----------'
1531                    4069 |  /      |      GND       |                                   |
1532                         | /       |                |                                  -+-
1533                         |/        '----------------'                                  GND
1534*/
1535
1536static const discrete_555_desc goldnpkr_555_vco_desc =
1537   {DISC_555_OUT_DC | DISC_555_OUT_ENERGY, 5, DEFAULT_555_VALUES};
1538
1539static const discrete_dac_r1_ladder dac_goldnpkr_ladder =
1540{
1541   3,                           /* size of ladder */
1542   {RES_K(30), RES_K(15), RES_K(7.5)},   /* elements */
1543
1544/*  external vBias doesn't seems to be accurate.
1545    using the 555 internal values sound better.
1546*/
1547   5,                           /* voltage Bias resistor is tied to */
1548   RES_K(5),                     /* additional resistor tied to vBias */
1549   RES_K(10),                     /* resistor tied to ground */
1550
1551   CAP_U(1.7)                     /* filtering cap tied to ground */
1552
1553//  12,                                 /* voltage Bias resistor is tied to */
1554//  RES_K(330),                         /* additional resistor tied to vBias */
1555//  0,                                  /* resistor tied to ground */
1556};
1557
1558static DISCRETE_SOUND_START( goldnpkr )
1559/*
1560    - bits -
1561    76543210
1562    --------
1563    .....xxx --> sound data.
1564    ....x... --> enable/disable.
1565
1566*/
1567   DISCRETE_INPUT_NOT   (NODE_01)      /* bit 3 - enable/disable */
1568   DISCRETE_INPUT_DATA  (NODE_10)      /* bits 0-2  - sound data */
1569
1570   DISCRETE_DAC_R1(NODE_20, NODE_01, NODE_10, 5, &dac_goldnpkr_ladder)
1571
1572   DISCRETE_555_ASTABLE_CV(NODE_30, NODE_01, RES_K(1), RES_K(10), CAP_U(.1), NODE_20, &goldnpkr_555_vco_desc)
1573   DISCRETE_OUTPUT(NODE_30, 3000)
1574
1575DISCRETE_SOUND_END
1576
1577/*
1578    Jack Potten's Poker discrete sound circuitry.
1579    ---------------------------------------------
1580
1581                                           +5V
1582           +12V                             |
1583            |                               +--------.
1584         .--+                               |        Z
1585         |  |                              8|        Z 1K                                 +12V
1586         Z  Z                          .----+----.   Z                                     |
1587     47K Z  Z 220K                     |   VCC   |3  |    10K    1uF                     |\|
1588         Z  Z                          |        Q|---|---ZZZZZ---||--.             1K   7| \
1589         |  |                          |         |7  |               |         .--ZZZZZ--|+ \  470uF
1590         |  |   33K                   4|      DIS|---+               Z   10uF  |        6|  8>--||----> Audio Out.
1591  PA0 ---|--|--ZZZZZ--.         .------|R        |   |               Z<---||---+---------|- /
1592         |  |         |         |      |   555   |   Z               Z              LM380| /   .------> Audio Out.
1593         |  |   18K   |         |     5|         |   Z 1K            |                   |/|   |
1594  PA1 ---+--|--ZZZZZ--+---------|------|CV       |   Z               |                2,3,4|   |
1595            |         |         |     2|         |6  |  +            |                5,10 +---'
1596            |   10K   |         |  .---|TR    THR|---+---|(----------+                11,12|
1597  PA2 ------+--ZZZZZ--'  |\     |  |   |   GND   |   |               |                     |
1598                         | \    |  |   '----+----'   |   1uF        -+-                   -+-
1599                        9|  \ 8 |  |       1|        |              GND                   GND
1600  PA3 -------------------|   >--'  |       -+-       |
1601                  74LS04 |  /      |       GND       |
1602                         | /       |                 |
1603                         |/        '-----------------'
1604*/
1605
1606static const discrete_dac_r1_ladder dac_pottnpkr_ladder =
1607{
1608   3,                           /* size of ladder */
1609   {RES_K(33), RES_K(18), RES_K(10)},   /* elements */
1610
1611/*  external vBias doesn't seems to be accurate.
1612    using the 555 internal values sound better.
1613*/
1614   5,                           /* voltage Bias resistor is tied to */
1615   RES_K(5),                     /* additional resistor tied to vBias */
1616   RES_K(10),                     /* resistor tied to ground */
1617
1618   0                           /* no filtering cap tied to ground */
1619};
1620
1621static DISCRETE_SOUND_START( pottnpkr )
1622/*
1623    - bits -
1624    76543210
1625    --------
1626    .....xxx --> sound data.
1627    ....x... --> enable/disable.
1628
1629*/
1630   DISCRETE_INPUT_NOT   (NODE_01)      /* bit 3 - enable/disable */
1631   DISCRETE_INPUT_DATA  (NODE_10)      /* bits 0-2  - sound data */
1632
1633   DISCRETE_DAC_R1(NODE_20, NODE_01, NODE_10, 5, &dac_pottnpkr_ladder)
1634
1635   DISCRETE_555_ASTABLE_CV(NODE_30, NODE_01, RES_K(1), RES_K(1), CAP_U(1), NODE_20, &goldnpkr_555_vco_desc)
1636   DISCRETE_OUTPUT(NODE_30, 3000)
1637
1638DISCRETE_SOUND_END
1639
1640
1641/*************************
1642*    Machine Drivers     *
1643*************************/
1644
1645static MACHINE_DRIVER_START( pmpoker_base )
1646
1647   /* basic machine hardware */
1648   MDRV_CPU_ADD("main", M6502, CPU_CLOCK)
1649   MDRV_CPU_PROGRAM_MAP(pmpoker_map, 0)
1650   MDRV_CPU_VBLANK_INT("main", nmi_line_pulse)
1651
1652   MDRV_NVRAM_HANDLER(generic_0fill)
1653
1654   /* video hardware */
1655   MDRV_SCREEN_ADD("main", RASTER)
1656   MDRV_SCREEN_REFRESH_RATE(60)
1657   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
1658   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
1659   MDRV_SCREEN_SIZE((39+1)*8, (31+1)*8)                  /* From MC6845 init, registers 00 & 04 (programmed with value-1). */
1660   MDRV_SCREEN_VISIBLE_AREA(1*8, 32*8-1, 0*8, 29*8-1)    /* From MC6845 init, registers 01 & 06. */
1661
1662   MDRV_DEVICE_ADD("crtc", MC6845)
1663
1664   MDRV_GFXDECODE(pmpoker)
1665   MDRV_PALETTE_INIT(goldnpkr)
1666   MDRV_PALETTE_LENGTH(256)
1667   MDRV_VIDEO_START(pmpoker)
1668   MDRV_VIDEO_UPDATE(pmpoker)
1669MACHINE_DRIVER_END
1670
1671
1672static MACHINE_DRIVER_START( pmpoker )
1673
1674   MDRV_IMPORT_FROM(pmpoker_base)
1675
1676   /* sound hardware */
1677   MDRV_SPEAKER_STANDARD_MONO("mono")
1678   MDRV_SOUND_ADD("discrete", DISCRETE, 0)
1679   MDRV_SOUND_CONFIG_DISCRETE(goldnpkr)
1680   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
1681MACHINE_DRIVER_END
1682
1683
1684static MACHINE_DRIVER_START( pottnpkr )
1685
1686   MDRV_IMPORT_FROM(pmpoker_base)
1687
1688   /* basic machine hardware */
1689   MDRV_CPU_MODIFY("main")
1690   MDRV_CPU_PROGRAM_MAP(pottnpkr_map, 0)
1691
1692   /* sound hardware */
1693   MDRV_SPEAKER_STANDARD_MONO("mono")
1694   MDRV_SOUND_ADD("discrete", DISCRETE, 0)
1695   MDRV_SOUND_CONFIG_DISCRETE(pottnpkr)
1696   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
1697MACHINE_DRIVER_END
1698
1699static MACHINE_DRIVER_START( witchcrd )
1700
1701   MDRV_IMPORT_FROM(pmpoker_base)
1702
1703   /* video hardware */
1704   MDRV_PALETTE_INIT(witchcrd)
1705
1706   /* sound hardware */
1707   MDRV_SPEAKER_STANDARD_MONO("mono")
1708   MDRV_SOUND_ADD("discrete", DISCRETE, 0)
1709   MDRV_SOUND_CONFIG_DISCRETE(goldnpkr)
1710   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
1711MACHINE_DRIVER_END
1712
1713static MACHINE_DRIVER_START( sloco93 )
1714
1715   MDRV_IMPORT_FROM(pmpoker_base)
1716
1717   /* video hardware */
1718   MDRV_SCREEN_MODIFY("main")
1719   MDRV_SCREEN_SIZE((39+1)*8, (31+1)*8)
1720   MDRV_SCREEN_VISIBLE_AREA(2*8, 32*8-1, 1*8, 29*8-1)
1721
1722   MDRV_PALETTE_INIT(witchcrd)
1723
1724   /* sound hardware */
1725   MDRV_SPEAKER_STANDARD_MONO("mono")
1726   MDRV_SOUND_ADD("discrete", DISCRETE, 0)
1727   MDRV_SOUND_CONFIG_DISCRETE(goldnpkr)
1728   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
1729MACHINE_DRIVER_END
1730
1731
1732/*************************
1733*        Rom Load        *
1734*************************/
1735
1736ROM_START( pmpoker )
1737   ROM_REGION( 0x10000, "main", 0 )
1738   ROM_LOAD( "2-5.bin",   0x5000, 0x1000, CRC(3446a643) SHA1(e67854e3322e238c17fed4e05282922028b5b5ea) )
1739   ROM_LOAD( "2-6.bin",   0x6000, 0x1000, CRC(50d2d026) SHA1(7f58ab176de0f0f7666d87271af69a845faec090) )
1740   ROM_LOAD( "2-7.bin",   0x7000, 0x1000, CRC(a9ab972e) SHA1(477441b7ff3acae3a5d5a3e4c2a428e0b3121534) )
1741
1742   ROM_REGION( 0x1800, "gfx1", ROMREGION_DISPOSE )
1743   ROM_FILL(            0x0000, 0x1000, 0 ) /* filling the R-G bitplanes */
1744   ROM_LOAD( "1-4.bin",   0x1000, 0x0800, CRC(62b9f90d) SHA1(39c61a01225027572fdb75543bb6a78ed74bb2fb) )    /* text layer */
1745
1746   ROM_REGION( 0x1800, "gfx2", ROMREGION_DISPOSE )
1747   ROM_LOAD( "1-1.bin",   0x0000, 0x0800, CRC(f2f94661) SHA1(f37f7c0dff680fd02897dae64e13e297d0fdb3e7) )    /* cards deck gfx, bitplane1 */
1748   ROM_LOAD( "1-2.bin",   0x0800, 0x0800, CRC(6bbb1e2d) SHA1(51ee282219bf84218886ad11a24bc6a8e7337527) )    /* cards deck gfx, bitplane2 */
1749   ROM_LOAD( "1-3.bin",   0x1000, 0x0800, CRC(6e3e9b1d) SHA1(14eb8d14ce16719a6ad7d13db01e47c8f05955f0) )    /* cards deck gfx, bitplane3 */
1750
1751   ROM_REGION( 0x0100, "proms", 0 )
1752   ROM_LOAD( "tbp24sa10n.7d",      0x0000, 0x0100, BAD_DUMP CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) ) /* PROM dump needed */
1753ROM_END
1754
1755/*  the original goldnpkr u40_4a.bin rom is bit corrupted.
1756    U43_2A.bin        BADADDR      --xxxxxxxxxxx
1757    U38_5A.bin        1ST AND 2ND HALF IDENTICAL
1758    UPS39_12A.bin     0xxxxxxxxxxxxxx = 0xFF
1759*/
1760ROM_START( goldnpkr )
1761   ROM_REGION( 0x10000, "main", 0 )
1762   ROM_LOAD( "ups39_12a.bin",   0x0000, 0x8000, CRC(216b45fb) SHA1(fbfcd98cc39b2e791cceb845b166ff697f584add) )
1763
1764   ROM_REGION( 0x6000, "gfx1", ROMREGION_DISPOSE )
1765   ROM_FILL(            0x0000, 0x4000, 0 ) /* filling the R-G bitplanes */
1766   ROM_LOAD( "u38_5a.bin",   0x4000, 0x2000, CRC(32705e1d) SHA1(84f9305af38179985e0224ae2ea54c01dfef6e12) )    /* text layer */
1767
1768   ROM_REGION( 0x6000, "gfx2", ROMREGION_DISPOSE )
1769   ROM_LOAD( "u43_2a.bin",   0x0000, 0x2000, CRC(10b34856) SHA1(52e4cc81b36b4c807b1d4471c0f7bea66108d3fd) )    /* cards deck gfx, bitplane1 */
1770   ROM_LOAD( "u40_4a.bin",   0x2000, 0x2000, CRC(5fc965ef) SHA1(d9ecd7e9b4915750400e76ca604bec8152df1fe4) )    /* cards deck gfx, bitplane2 */
1771   ROM_COPY( "gfx1",   0x4800, 0x4000, 0x0800 )    /* cards deck gfx, bitplane3. found in the 2nd quarter of the text layer rom */
1772
1773   ROM_REGION( 0x0100, "proms", 0 )
1774   ROM_LOAD( "tbp24s10n.7d",      0x0000, 0x0100, CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) )
1775
1776/*  pmpoker                 goldnpkr
1777    1-4.bin                 u38_5a (1st quarter)    96.582031%  \ 1st and 2nd halves are identical.
1778    1-3.bin                 u38_5a (2nd quarter)    IDENTICAL   /
1779    1-1.bin                 u43_2a (1st quarter)    IDENTICAL   ; 4 quarters are identical.
1780*/
1781ROM_END
1782
1783ROM_START( goldnpkb )
1784   ROM_REGION( 0x10000, "main", 0 )
1785   ROM_LOAD( "ups31h.12a",   0x0000, 0x8000, CRC(bee5b07a) SHA1(5da60292ecbbedd963c273eac2a1fb88ad66ada8) )
1786
1787   ROM_REGION( 0x6000, "gfx1", ROMREGION_DISPOSE )
1788   ROM_FILL(            0x0000, 0x4000, 0 ) /* filling the R-G bitplanes */
1789   ROM_LOAD( "u38_5a.bin",   0x4000, 0x2000, CRC(32705e1d) SHA1(84f9305af38179985e0224ae2ea54c01dfef6e12) )    /* text layer */
1790
1791   ROM_REGION( 0x6000, "gfx2", ROMREGION_DISPOSE )
1792   ROM_LOAD( "u43_2a.bin",   0x0000, 0x2000, CRC(10b34856) SHA1(52e4cc81b36b4c807b1d4471c0f7bea66108d3fd) )    /* cards deck gfx, bitplane1 */
1793   ROM_LOAD( "u40_4a.bin",   0x2000, 0x2000, CRC(5fc965ef) SHA1(d9ecd7e9b4915750400e76ca604bec8152df1fe4) )    /* cards deck gfx, bitplane2 */
1794   ROM_COPY( "gfx1",   0x4800, 0x4000, 0x0800 )    /* cards deck gfx, bitplane3. found in the 2nd quarter of the text layer rom */
1795
1796   ROM_REGION( 0x0100, "proms", 0 )
1797   ROM_LOAD( "tbp24s10n.7d",      0x0000, 0x0100, CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) )
1798
1799/*  pmpoker                 goldnpkb
1800    1-4.bin                 u38.5a (1st quarter)    96.582031%  \ 1st and 2nd halves are identical.
1801    1-3.bin                 u38.5a (2nd quarter)    IDENTICAL   /
1802    1-1.bin                 u43.2a (1st quarter)    IDENTICAL   ; 4 quarters are identical.
1803*/
1804ROM_END
1805
1806ROM_START( pottnpkr )   /* Golden Poker game without the double up feature. Code is intended to start at $6000 */
1807   ROM_REGION( 0x10000, "main", 0 )
1808   ROM_LOAD( "ic13_3.bin",   0x2000, 0x1000, CRC(23c975cd) SHA1(1d32a9ba3aa996287a823558b9d610ab879a29e8) )
1809   ROM_LOAD( "ic14_4.bin",   0x3000, 0x1000, CRC(86a03aab) SHA1(0c4e8699b9fc9943de1fa0a364e043b3878636dc) )
1810
1811   ROM_REGION( 0x3000, "gfx1", ROMREGION_DISPOSE )
1812   ROM_FILL(            0x0000, 0x2000, 0 ) /* filling the R-G bitplanes */
1813   ROM_LOAD( "ic7_0.bin",   0x2000, 0x1000, CRC(1090e7f0) SHA1(26a7fc8853debb9a759811d7fee39410614c3895) )    /* text layer */
1814
1815   ROM_REGION( 0x3000, "gfx2", ROMREGION_DISPOSE )
1816   ROM_LOAD( "ic2_7.bin",   0x0000, 0x1000, CRC(b5a1f5a3) SHA1(a34aaaab5443c6962177a5dd35002bd09d0d2772) )    /* cards deck gfx, bitplane1 */
1817   ROM_LOAD( "ic3_8.bin",   0x1000, 0x1000, CRC(40e426af) SHA1(7e7cb30dafc96bcb87a05d3e0ef5c2d426ed6a74) )    /* cards deck gfx, bitplane2 */
1818   ROM_LOAD( "ic5_9.bin",   0x2000, 0x1000, CRC(232374f3) SHA1(b75907edbf769b8c46fb1ebdb301c325c556e6c2) )    /* cards deck gfx, bitplane3 */
1819
1820   ROM_REGION( 0x0100, "proms", 0 )
1821   ROM_LOAD( "tbp24s10n.7d",      0x0000, 0x0100, CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) )
1822
1823/*  ic2_7.bin    1ST AND 2ND HALF IDENTICAL
1824    ic3_8.bin    1ST AND 2ND HALF IDENTICAL
1825    ic5_9.bin    1ST AND 2ND HALF IDENTICAL
1826    ic7_0.bin    1ST AND 2ND HALF IDENTICAL
1827
1828    RB confirmed the dump. There are other games with double sized roms and identical halves.
1829*/
1830ROM_END
1831
1832ROM_START( potnpkra )    /* a Coinmaster game?... seems to be a hack */
1833   ROM_REGION( 0x10000, "main", 0 )
1834   ROM_LOAD( "vp-5.bin",   0x2000, 0x1000, CRC(1443d0ff) SHA1(36625d24d9a871cc8c03bdeda983982ba301b385) )
1835   ROM_LOAD( "vp-6.bin",   0x3000, 0x1000, CRC(94f82fc1) SHA1(ce95fc429f5389eea45fec877bac992fa7ba2b3c) )
1836
1837   ROM_REGION( 0x1800, "gfx1", ROMREGION_DISPOSE )
1838   ROM_FILL(            0x0000, 0x1000, 0 ) /* filling the R-G bitplanes */
1839   ROM_LOAD( "vp-4.bin",   0x1000, 0x0800, CRC(2c53493f) SHA1(9e71db51499294bb4b16e7d8013e5daf6f1f9d18) )    /* text layer */
1840
1841   ROM_REGION( 0x1800, "gfx2", ROMREGION_DISPOSE )
1842   ROM_LOAD( "vp-1.bin",   0x0000, 0x0800, CRC(f2f94661) SHA1(f37f7c0dff680fd02897dae64e13e297d0fdb3e7) )    /* cards deck gfx, bitplane1 */
1843   ROM_LOAD( "vp-2.bin",   0x0800, 0x0800, CRC(6bbb1e2d) SHA1(51ee282219bf84218886ad11a24bc6a8e7337527) )    /* cards deck gfx, bitplane2 */
1844   ROM_LOAD( "vp-3.bin",   0x1000, 0x0800, CRC(6e3e9b1d) SHA1(14eb8d14ce16719a6ad7d13db01e47c8f05955f0) )    /* cards deck gfx, bitplane3 */
1845
1846   ROM_REGION( 0x0100, "proms", 0 )
1847   ROM_LOAD( "82s129.9c",      0x0000, 0x0100, BAD_DUMP CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) )
1848ROM_END
1849
1850/*
1851pottpok4.bin                                                 0xxxxxxxxxx = 0x00
1852                        517.4a                               0xxxxxxxxxx = 0x00
1853pottpok1.bin            517.8a                  IDENTICAL
1854pottpok2.bin            517.7a                  IDENTICAL
1855pottpok3.bin            517.6a                  IDENTICAL
1856pottpok4.bin            517.4a                  IDENTICAL
1857pottpok5.bin            517.16a                 69.335938%
1858pottpok6.bin            517.17a                 2.685547%
1859*/
1860
1861ROM_START( potnpkrb )
1862   ROM_REGION( 0x10000, "main", 0 )
1863   ROM_LOAD( "517.16a",   0x2000, 0x1000, CRC(8892fbd4) SHA1(22a27c0c3709ca4808a9afb8848233bc4124559f) )
1864   ROM_LOAD( "517.17a",   0x3000, 0x1000, CRC(75a72877) SHA1(9df8fd2c98526d20aa0fa056a7b71b5c5fb5206b) )
1865
1866   ROM_REGION( 0x1800, "gfx1", ROMREGION_DISPOSE )
1867   ROM_FILL(            0x0000, 0x1000, 0 ) /* filling the R-G bitplanes */
1868   ROM_LOAD( "517.8a",      0x1000, 0x0800, CRC(2c53493f) SHA1(9e71db51499294bb4b16e7d8013e5daf6f1f9d18) )    /* text layer */
1869
1870   ROM_REGION( 0x1800, "gfx2", ROMREGION_DISPOSE )
1871   ROM_LOAD( "517.4a",      0x0000, 0x0800, CRC(f2f94661) SHA1(f37f7c0dff680fd02897dae64e13e297d0fdb3e7) )    /* cards deck gfx, bitplane1 */
1872   ROM_LOAD( "517.6a",      0x0800, 0x0800, CRC(6bbb1e2d) SHA1(51ee282219bf84218886ad11a24bc6a8e7337527) )    /* cards deck gfx, bitplane2 */
1873   ROM_LOAD( "517.7a",      0x1000, 0x0800, CRC(6e3e9b1d) SHA1(14eb8d14ce16719a6ad7d13db01e47c8f05955f0) )    /* cards deck gfx, bitplane3 */
1874
1875   ROM_REGION( 0x0100, "proms", 0 )
1876   ROM_LOAD( "517_mb7052.9c",   0x0000, 0x0100, CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) )
1877ROM_END
1878
1879/* the alternative Jack Potten set is identical, but with different sized roms.
1880
1881                pot1.bin                1ST AND 2ND HALF IDENTICAL
1882                pot2.bin                1ST AND 2ND HALF IDENTICAL
1883pottpok1.bin    pot34.bin (1st half)    IDENTICAL
1884pottpok2.bin    pot34.bin (2nd half)    IDENTICAL
1885pottpok3.bin    pot2.bin (1st half)     IDENTICAL
1886pottpok4.bin    pot1.bin (1st half)     IDENTICAL
1887pottpok5.bin    pot5.bin                IDENTICAL
1888pottpok6.bin    pot6.bin                IDENTICAL
1889*/
1890
1891ROM_START( potnpkrc )
1892   ROM_REGION( 0x10000, "main", 0 )
1893   ROM_LOAD( "pottpok5.bin",   0x2000, 0x1000, CRC(d74e50f4) SHA1(c3a8a6322a3f1622898c6759e695b4e702b79b28) )
1894   ROM_LOAD( "pottpok6.bin",   0x3000, 0x1000, CRC(53237873) SHA1(b640cb3db2513784c8d2d8983a17352276c11e07) )
1895
1896   ROM_REGION( 0x1800, "gfx1", ROMREGION_DISPOSE )
1897   ROM_FILL(               0x0000, 0x1000, 0 ) /* filling the R-G bitplanes */
1898   ROM_LOAD( "pottpok1.bin",   0x1000, 0x0800, CRC(2c53493f) SHA1(9e71db51499294bb4b16e7d8013e5daf6f1f9d18) )    /* text layer */
1899
1900   ROM_REGION( 0x1800, "gfx2", ROMREGION_DISPOSE )
1901   ROM_LOAD( "pottpok4.bin",   0x0000, 0x0800, CRC(f2f94661) SHA1(f37f7c0dff680fd02897dae64e13e297d0fdb3e7) )    /* cards deck gfx, bitplane1 */
1902   ROM_LOAD( "pottpok3.bin",   0x0800, 0x0800, CRC(6bbb1e2d) SHA1(51ee282219bf84218886ad11a24bc6a8e7337527) )    /* cards deck gfx, bitplane2 */
1903   ROM_LOAD( "pottpok2.bin",   0x1000, 0x0800, CRC(6e3e9b1d) SHA1(14eb8d14ce16719a6ad7d13db01e47c8f05955f0) )    /* cards deck gfx, bitplane3 */
1904
1905   ROM_REGION( 0x0100, "proms", 0 )
1906   ROM_LOAD( "82s129.9c",      0x0000, 0x0100, CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) )
1907ROM_END
1908
1909
1910/***************** NEW SETS **************************/
1911
1912
1913ROM_START( potnpkrd )
1914   ROM_REGION( 0x10000, "main", 0 )
1915   ROM_LOAD( "pot5.bin",   0x2000, 0x1000, CRC(d74e50f4) SHA1(c3a8a6322a3f1622898c6759e695b4e702b79b28) )
1916   ROM_LOAD( "pot6.bin",   0x3000, 0x1000, CRC(53237873) SHA1(b640cb3db2513784c8d2d8983a17352276c11e07) )
1917
1918   ROM_REGION( 0x3000, "gfx1", ROMREGION_DISPOSE )
1919   ROM_FILL(            0x0000, 0x2000, 0 ) /* filling the R-G bitplanes */
1920   ROM_LOAD( "pot34.bin",   0x2000, 0x1000, CRC(52fd35d2) SHA1(ad8bf8c222ceb2e9b3b6d9033866867f1977c65f) )    /* text layer */
1921
1922   ROM_REGION( 0x3000, "gfx2", ROMREGION_DISPOSE )
1923   ROM_LOAD( "pot1.bin",   0x0000, 0x1000, CRC(b5a1f5a3) SHA1(a34aaaab5443c6962177a5dd35002bd09d0d2772) )    /* cards deck gfx, bitplane1 */
1924   ROM_LOAD( "pot2.bin",   0x1000, 0x1000, CRC(40e426af) SHA1(7e7cb30dafc96bcb87a05d3e0ef5c2d426ed6a74) )    /* cards deck gfx, bitplane2 */
1925   ROM_COPY( "gfx1",      0x2800, 0x2000, 0x0800 )    /* cards deck gfx, bitplane3. found in the 2nd quarter of the text layer rom */
1926
1927   ROM_REGION( 0x0100, "proms", 0 )
1928   ROM_LOAD( "82s129.9c",      0x0000, 0x0100, CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) )
1929ROM_END
1930
1931ROM_START( potnpkre )
1932   ROM_REGION( 0x10000, "main", 0 )
1933   ROM_LOAD( "g_luck_a.bin",   0x2000, 0x1000, CRC(21d3b5e9) SHA1(32f06eb26c5232738ad7e86f1a81eb9717f9c7e0) )
1934   ROM_LOAD( "g_luck_b.bin",   0x3000, 0x1000, CRC(7e848e5e) SHA1(45461cfcce06f6240562761d26ba7fdb7ef4986b) )
1935
1936   ROM_REGION( 0x3000, "gfx1", ROMREGION_DISPOSE )
1937   ROM_FILL(            0x0000, 0x2000, 0 ) /* filling the R-G bitplanes */
1938   ROM_LOAD( "ic7_0.bin",   0x2000, 0x1000, CRC(1090e7f0) SHA1(26a7fc8853debb9a759811d7fee39410614c3895) )    /* text layer */
1939
1940   ROM_REGION( 0x3000, "gfx2", ROMREGION_DISPOSE )
1941   ROM_LOAD( "ic2_7.bin",   0x0000, 0x1000, CRC(b5a1f5a3) SHA1(a34aaaab5443c6962177a5dd35002bd09d0d2772) )    /* cards deck gfx, bitplane1 */
1942   ROM_LOAD( "ic3_8.bin",   0x1000, 0x1000, CRC(40e426af) SHA1(7e7cb30dafc96bcb87a05d3e0ef5c2d426ed6a74) )    /* cards deck gfx, bitplane2 */
1943   ROM_LOAD( "ic5_9.bin",   0x2000, 0x1000, CRC(232374f3) SHA1(b75907edbf769b8c46fb1ebdb301c325c556e6c2) )    /* cards deck gfx, bitplane3 */
1944
1945   ROM_REGION( 0x0100, "proms", 0 )
1946   ROM_LOAD( "tbp24s10n.7d",      0x0000, 0x0100, BAD_DUMP CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) ) /* PROM dump needed */
1947ROM_END
1948
1949ROM_START( goodluck )
1950   ROM_REGION( 0x10000, "main", 0 )
1951   ROM_LOAD( "goodluck_glh6b.bin",   0x0000, 0x8000, CRC(2cfa4a2c) SHA1(720e2900f3a0ef2632aa201a63b5eba0570e6aa3) )
1952
1953   ROM_REGION( 0x3000, "gfx1", ROMREGION_DISPOSE )
1954   ROM_FILL(         0x0000, 0x2000, 0 ) /* filling the R-G bitplanes */
1955   ROM_LOAD( "4.bin",   0x2000, 0x1000, CRC(41924d13) SHA1(8ab69b6efdc20858960fa5df669470ba90b5f8d7) )    /* text layer */
1956
1957   ROM_REGION( 0x3000, "gfx2", ROMREGION_DISPOSE )
1958   ROM_LOAD( "7.bin",   0x0000, 0x1000, CRC(28ecfaea) SHA1(19d73ed0fdb5a873447b46e250ad6e71abe257cd) )    /* cards deck gfx, bitplane1 */
1959   ROM_LOAD( "6.bin",   0x1000, 0x1000, CRC(eeec8862) SHA1(ae03aba1bd43c3ffd140f76770fc1c8cf89ea115) )    /* cards deck gfx, bitplane2 */
1960   ROM_LOAD( "5.bin",   0x2000, 0x1000, CRC(2712f297) SHA1(d3cc1469d07c3febbbe4a645cd6bdb57e09cf504) )    /* cards deck gfx, bitplane3 */
1961
1962   ROM_REGION( 0x0100, "proms", 0 )
1963   ROM_LOAD( "82s129.9c",      0x0000, 0x0100, CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) ) /* PROM dump needed */
1964ROM_END
1965
1966ROM_START( bsuerte )
1967   ROM_REGION( 0x10000, "main", 0 )
1968   ROM_LOAD( "ups39_12a.bin",   0x0000, 0x8000, CRC(e6b661b7) SHA1(b265f6814a168034d24bc1c25f67ece131281bc2) )
1969
1970   ROM_REGION( 0x3000, "gfx1", ROMREGION_DISPOSE )
1971   ROM_FILL(            0x0000, 0x2000, 0 ) /* filling the R-G bitplanes */
1972   ROM_LOAD( "u38.bin",   0x2000, 0x1000, CRC(0a159dfa) SHA1(0a9c8e6177b36831b365917a10042aac3383983d) )    /* text layer */
1973
1974   ROM_REGION( 0x3000, "gfx2", ROMREGION_DISPOSE )
1975   ROM_LOAD( "7.bin",   0x0000, 0x1000, CRC(28ecfaea) SHA1(19d73ed0fdb5a873447b46e250ad6e71abe257cd) )    /* cards deck gfx, bitplane1 */
1976   ROM_LOAD( "6.bin",   0x1000, 0x1000, CRC(eeec8862) SHA1(ae03aba1bd43c3ffd140f76770fc1c8cf89ea115) )    /* cards deck gfx, bitplane2 */
1977   ROM_LOAD( "5.bin",   0x2000, 0x1000, CRC(2712f297) SHA1(d3cc1469d07c3febbbe4a645cd6bdb57e09cf504) )    /* cards deck gfx, bitplane3 */
1978
1979   ROM_REGION( 0x0100, "proms", 0 )
1980   ROM_LOAD( "82s129.9c",      0x0000, 0x0100, CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) ) /* PROM dump needed */
1981ROM_END
1982
1983ROM_START( bsuertea )
1984   ROM_REGION( 0x10000, "main", 0 )
1985   ROM_LOAD( "x10d4esp.16c",   0x0000, 0x8000, CRC(0606bab4) SHA1(624b0cef1a23a4e7ba2d2d256f30f73b1e455fa7) )
1986
1987   ROM_REGION( 0x3000, "gfx1", ROMREGION_DISPOSE )
1988   ROM_FILL(            0x0000, 0x2000, 0 ) /* filling the R-G bitplanes */
1989   ROM_LOAD( "u38.bin",   0x2000, 0x1000, CRC(0a159dfa) SHA1(0a9c8e6177b36831b365917a10042aac3383983d) )    /* text layer */
1990
1991   ROM_REGION( 0x3000, "gfx2", ROMREGION_DISPOSE )
1992   ROM_LOAD( "7.bin",   0x0000, 0x1000, CRC(28ecfaea) SHA1(19d73ed0fdb5a873447b46e250ad6e71abe257cd) )    /* cards deck gfx, bitplane1 */
1993   ROM_LOAD( "6.bin",   0x1000, 0x1000, CRC(eeec8862) SHA1(ae03aba1bd43c3ffd140f76770fc1c8cf89ea115) )    /* cards deck gfx, bitplane2 */
1994   ROM_LOAD( "5.bin",   0x2000, 0x1000, CRC(2712f297) SHA1(d3cc1469d07c3febbbe4a645cd6bdb57e09cf504) )    /* cards deck gfx, bitplane3 */
1995
1996   ROM_REGION( 0x0100, "proms", 0 )
1997   ROM_LOAD( "82s129.9c",      0x0000, 0x0100, CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) ) /* PROM dump needed */
1998ROM_END
1999
2000ROM_START( royale )
2001   ROM_REGION( 0x10000, "main", 0 )
2002   ROM_LOAD( "royalex.bin",   0x4000, 0x4000, CRC(ef370617) SHA1(0fc5679e9787aeea3bc592b36efcaa20e859f912) )
2003
2004   ROM_REGION( 0x3000, "gfx1", ROMREGION_DISPOSE )
2005   ROM_FILL(               0x0000, 0x2000, 0 ) /* filling the R-G bitplanes */
2006   ROM_LOAD( "royalechr.bin",   0x2000, 0x1000, CRC(b1f2cbb8) SHA1(8f4930038f2e21ca90b213c35b45ed14d8fad6fb) )    /* text layer */
2007
2008   ROM_REGION( 0x1800, "gfx2", ROMREGION_DISPOSE )
2009   ROM_LOAD( "royale3.bin",   0x0000, 0x0800, CRC(1f41c541) SHA1(00df5079193f78db0617a6b8a613d8a0616fc8e9) )    /* cards deck gfx, bitplane1 */
2010   ROM_LOAD( "royale2.bin",   0x0800, 0x0800, CRC(6bbb1e2d) SHA1(51ee282219bf84218886ad11a24bc6a8e7337527) )    /* cards deck gfx, bitplane2 */
2011   ROM_LOAD( "royale1.bin",   0x1000, 0x0800, CRC(6e3e9b1d) SHA1(14eb8d14ce16719a6ad7d13db01e47c8f05955f0) )    /* cards deck gfx, bitplane3 */
2012
2013   ROM_REGION( 0x0100, "proms", 0 )
2014   ROM_LOAD( "82s129.9c",      0x0000, 0x0100, CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) ) /* PROM dump needed */
2015ROM_END
2016
2017ROM_START( witchcrd )
2018   ROM_REGION( 0x10000, "main", 0 )
2019   ROM_LOAD( "wc_sbruj.256",   0x0000, 0x8000, CRC(5689ae41) SHA1(c7a624ec881204137489b147ce66cc9a9900650a) )
2020
2021   ROM_REGION( 0x3000, "gfx1", ROMREGION_DISPOSE )
2022   ROM_FILL(               0x0000, 0x2000, 0 ) /* filling the R-G bitplanes */
2023   ROM_LOAD( "bs_4_wc.032",   0x2000, 0x1000, CRC(41924d13) SHA1(8ab69b6efdc20858960fa5df669470ba90b5f8d7) )    /* text layer */
2024
2025   ROM_REGION( 0x3000, "gfx2", ROMREGION_DISPOSE )
2026   ROM_LOAD( "7.bin",   0x0000, 0x1000, CRC(28ecfaea) SHA1(19d73ed0fdb5a873447b46e250ad6e71abe257cd) )    /* cards deck gfx, bitplane1 */
2027   ROM_LOAD( "6.bin",   0x1000, 0x1000, CRC(eeec8862) SHA1(ae03aba1bd43c3ffd140f76770fc1c8cf89ea115) )    /* cards deck gfx, bitplane2 */
2028   ROM_LOAD( "5.bin",   0x2000, 0x1000, CRC(2712f297) SHA1(d3cc1469d07c3febbbe4a645cd6bdb57e09cf504) )    /* cards deck gfx, bitplane3 */
2029
2030   ROM_REGION( 0x0100, "proms", 0 )
2031   ROM_LOAD( "82s129.9c",      0x0000, 0x0100, CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) ) /* PROM dump needed */
2032ROM_END
2033
2034ROM_START( witchcda )
2035   ROM_REGION( 0x10000, "main", 0 )
2036   ROM_LOAD( "w_card.256",   0x0000, 0x8000, CRC(104218a4) SHA1(191e198f5443afc80a0e1bba3ccaad4e744b15e0) )
2037
2038   ROM_REGION( 0x3000, "gfx1", ROMREGION_DISPOSE )
2039   ROM_FILL(               0x0000, 0x2000, 0 ) /* filling the R-G bitplanes */
2040   ROM_LOAD( "bs_4_wc.032",   0x2000, 0x1000, CRC(41924d13) SHA1(8ab69b6efdc20858960fa5df669470ba90b5f8d7) )    /* text layer */
2041
2042   ROM_REGION( 0x3000, "gfx2", ROMREGION_DISPOSE )
2043   ROM_LOAD( "7.bin",   0x0000, 0x1000, CRC(28ecfaea) SHA1(19d73ed0fdb5a873447b46e250ad6e71abe257cd) )    /* cards deck gfx, bitplane1 */
2044   ROM_LOAD( "6.bin",   0x1000, 0x1000, CRC(eeec8862) SHA1(ae03aba1bd43c3ffd140f76770fc1c8cf89ea115) )    /* cards deck gfx, bitplane2 */
2045   ROM_LOAD( "5.bin",   0x2000, 0x1000, CRC(2712f297) SHA1(d3cc1469d07c3febbbe4a645cd6bdb57e09cf504) )    /* cards deck gfx, bitplane3 */
2046
2047   ROM_REGION( 0x0100, "proms", 0 )
2048   ROM_LOAD( "82s129.9c",      0x0000, 0x0100, CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) ) /* PROM dump needed */
2049ROM_END
2050
2051ROM_START( witchcdb )
2052   ROM_REGION( 0x10000, "main", 0 )
2053   ROM_LOAD( "w_card.128",   0x4000, 0x4000, CRC(620ac5ca) SHA1(69275683780c65a83ee6dcef3bd14ac02f4929a0) )
2054
2055   ROM_REGION( 0x3000, "gfx1", ROMREGION_DISPOSE )
2056   ROM_FILL(               0x0000, 0x2000, 0 ) /* filling the R-G bitplanes */
2057   ROM_LOAD( "bs_4_wc.032",   0x2000, 0x1000, CRC(41924d13) SHA1(8ab69b6efdc20858960fa5df669470ba90b5f8d7) )    /* text layer */
2058
2059   ROM_REGION( 0x3000, "gfx2", ROMREGION_DISPOSE )
2060   ROM_LOAD( "7.bin",   0x0000, 0x1000, CRC(28ecfaea) SHA1(19d73ed0fdb5a873447b46e250ad6e71abe257cd) )    /* cards deck gfx, bitplane1 */
2061   ROM_LOAD( "6.bin",   0x1000, 0x1000, CRC(eeec8862) SHA1(ae03aba1bd43c3ffd140f76770fc1c8cf89ea115) )    /* cards deck gfx, bitplane2 */
2062   ROM_LOAD( "5.bin",   0x2000, 0x1000, CRC(2712f297) SHA1(d3cc1469d07c3febbbe4a645cd6bdb57e09cf504) )    /* cards deck gfx, bitplane3 */
2063
2064   ROM_REGION( 0x0100, "proms", 0 )
2065   ROM_LOAD( "82s129.9c",      0x0000, 0x0100, CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) ) /* PROM dump needed */
2066ROM_END
2067
2068ROM_START( sloco93 )
2069   ROM_REGION( 0x10000, "main", 0 )
2070   ROM_LOAD( "locoloco.128",   0x4000, 0x4000, CRC(f626a770) SHA1(afbd33b3f65b8a781c716a3d6e5447aa817d856c) )
2071
2072   ROM_REGION( 0x3000, "gfx1", ROMREGION_DISPOSE )
2073   ROM_FILL(               0x0000, 0x2000, 0 ) /* filling the R-G bitplanes */
2074   ROM_LOAD( "confloco.032",   0x2000, 0x1000, CRC(b86f219c) SHA1(3f655a96bcf597a271a4eaaa0acbf8dd70fcdae9) )    /* text layer */
2075
2076   ROM_REGION( 0x3000, "gfx2", ROMREGION_DISPOSE )
2077   ROM_LOAD( "7.bin",   0x0000, 0x1000, CRC(28ecfaea) SHA1(19d73ed0fdb5a873447b46e250ad6e71abe257cd) )    /* cards deck gfx, bitplane1 */
2078   ROM_LOAD( "6.bin",   0x1000, 0x1000, CRC(eeec8862) SHA1(ae03aba1bd43c3ffd140f76770fc1c8cf89ea115) )    /* cards deck gfx, bitplane2 */
2079   ROM_LOAD( "5.bin",   0x2000, 0x1000, CRC(2712f297) SHA1(d3cc1469d07c3febbbe4a645cd6bdb57e09cf504) )    /* cards deck gfx, bitplane3 */
2080
2081   ROM_REGION( 0x0100, "proms", 0 )
2082   ROM_LOAD( "82s129.9c",      0x0000, 0x0100, CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) ) /* PROM dump needed */
2083ROM_END
2084
2085ROM_START( sloco93a )
2086   ROM_REGION( 0x10000, "main", 0 )
2087   ROM_LOAD( "locoloco.256",   0x0000, 0x8000, CRC(ab037b0b) SHA1(16f811daaed5bf7b72549db85755c5274dfee310) )
2088
2089   ROM_REGION( 0x3000, "gfx1", ROMREGION_DISPOSE )
2090   ROM_FILL(               0x0000, 0x2000, 0 ) /* filling the R-G bitplanes */
2091   ROM_LOAD( "confloco.032",   0x2000, 0x1000, CRC(b86f219c) SHA1(3f655a96bcf597a271a4eaaa0acbf8dd70fcdae9) )    /* text layer */
2092
2093   ROM_REGION( 0x3000, "gfx2", ROMREGION_DISPOSE )
2094   ROM_LOAD( "7.bin",   0x0000, 0x1000, CRC(28ecfaea) SHA1(19d73ed0fdb5a873447b46e250ad6e71abe257cd) )    /* cards deck gfx, bitplane1 */
2095   ROM_LOAD( "6.bin",   0x1000, 0x1000, CRC(eeec8862) SHA1(ae03aba1bd43c3ffd140f76770fc1c8cf89ea115) )    /* cards deck gfx, bitplane2 */
2096   ROM_LOAD( "5.bin",   0x2000, 0x1000, CRC(2712f297) SHA1(d3cc1469d07c3febbbe4a645cd6bdb57e09cf504) )    /* cards deck gfx, bitplane3 */
2097
2098   ROM_REGION( 0x0100, "proms", 0 )
2099   ROM_LOAD( "82s129.9c",      0x0000, 0x0100, CRC(7f31066b) SHA1(15420780ec6b2870fc4539ec3afe4f0c58eedf12) ) /* PROM dump needed */
2100ROM_END
2101
2102
2103/*************************
2104*      Driver Init       *
2105*************************/
2106
2107static DRIVER_INIT( pmpoker )
2108{
2109   pia_config(0, &pia0_intf);
2110   pia_config(1, &pia1_intf);
2111}
2112/*
2113    Golden Poker H/W sets:
2114
2115    newname    oldname    gameplay  music      settings    testmode
2116    ===================================================================
2117    pmpoker    pmpoker    fast      minimal    hack        matrix/grill
2118    goldnpkr   goldnpkr   fast      y.doodle   excellent   matrix/grill
2119    goldnpkb   goldnpkb   normal    minimal    normal      matrix/grill
2120
2121
2122    Potten's Poker H/W sets:
2123
2124    newname    oldname    gameplay  music      settings    testmode
2125    ===================================================================
2126    pottnpkr   goldnpkc   fast      y.doodle   normal      only grid
2127    potnpkra   jokerpkr   normal    normal     normal      only skill
2128    potnpkrb   pottnpkb   slow      y.doodle   normal      only grid
2129    potnpkrc   pottnpkr   normal    minimal    hack        only skill
2130    potnpkrd   --------   normal    minimal    hack        only skill
2131    potnpkre   --------   slow      y.doodle   normal      matrix/grill
2132
2133
2134    Witch Card H/W sets:
2135
2136    newname    oldname    gameplay  music      settings    testmode
2137    ===================================================================
2138    bsuerte    --------   normal    minimal    only 1-10   matrix/grill
2139    bsuertea   --------   normal    minimal    only 1-10   matrix/grill
2140    goodluck   --------   fast      y.doodle   normal      matrix/grill
2141    royale     --------
2142    witchcrd   --------   normal    y.doodle   12-param    only grid
2143    witchcda   --------   fast      y.doodle   12-param    only grid
2144    witchcdb   --------   normal    y.doodle   12-param    only grid
2145    sloco93    --------   fast      custom     complete    only grid
2146    sloco93a   --------   fast      custom     complete    only grid
2147
2148*/
2149static DRIVER_INIT( royale )
2150{
2151    /* $60bb, NOPing the ORA #$F0 (after read the PIA1 port B */
2152
2153//  UINT8 *ROM = memory_region(machine, "main");
2154
2155//  ROM[0x60bb] = 0xea;
2156//  ROM[0x60bc] = 0xea;
2157
2158   pia_config(0, &pia0_intf);
2159   pia_config(1, &pia1_intf);
2160}
2161
2162/*************************
2163*      Game Drivers      *
2164*************************/
2165
2166/*     YEAR  NAME      PARENT    MACHINE   INPUT     INIT      ROT      COMPANY                      FULLNAME                            FLAGS                    LAYOUT  */
2167GAMEL( 1981, pmpoker,  0,        pmpoker,  pmpoker,  pmpoker,  ROT0,   "PlayMan",                   "PlayMan Poker (german)",            0,                       layout_pmpoker  )
2168GAMEL( 1981, goldnpkr, 0,        pmpoker,  goldnpkr, pmpoker,  ROT0,   "Bonanza Enterprises, Ltd",  "Golden Poker Double Up (Big Boy)",  0,                       layout_goldnpkr )
2169GAMEL( 1981, goldnpkb, goldnpkr, pmpoker,  goldnpkr, pmpoker,  ROT0,   "Bonanza Enterprises, Ltd",  "Golden Poker Double Up (Mini Boy)", 0,                       layout_goldnpkr )
2170GAMEL( 198?, pottnpkr, 0,        pottnpkr, pottnpkr, pmpoker,  ROT0,   "Bootleg",                   "Jack Potten's Poker (set 1)",       0,                       layout_pottnpkr )
2171GAMEL( 198?, potnpkra, pottnpkr, pottnpkr, potnpkra, pmpoker,  ROT0,   "Bootleg on Coinmaster H/W", "Jack Potten's Poker (set 2)",       0,                       layout_pottnpkr )
2172GAMEL( 198?, potnpkrb, pottnpkr, pottnpkr, pottnpkr, pmpoker,  ROT0,   "Bootleg",                   "Jack Potten's Poker (set 3)",       0,                       layout_pottnpkr )
2173GAMEL( 198?, potnpkrc, pottnpkr, pottnpkr, potnpkrc, pmpoker,  ROT0,   "Bootleg",                   "Jack Potten's Poker (set 4)",       0,                       layout_pottnpkr )
2174
2175GAMEL( 198?, potnpkrd, pottnpkr, pottnpkr, potnpkrc, pmpoker,  ROT0,   "Bootleg",                   "Jack Potten's Poker (set 5)",       0,                       layout_pottnpkr )
2176GAMEL( 198?, potnpkre, pottnpkr, pottnpkr, pottnpkr, pmpoker,  ROT0,   "Bootleg",                   "Jack Potten's Poker (set 6)",       0,                       layout_pottnpkr )
2177GAMEL( 198?, goodluck, 0,        witchcrd, goodluck, pmpoker,  ROT0,   "Unknown",                   "Good Luck",                         0,                       layout_pottnpkr )
2178GAMEL( 198?, bsuerte,  0,        witchcrd, bsuerte,  pmpoker,  ROT0,   "Unknown",                   "Buena Suerte (spanish, set 1)",     0,                       layout_goldnpkr )
2179GAMEL( 198?, bsuertea, bsuerte,  witchcrd, bsuerte,  pmpoker,  ROT0,   "Unknown",                   "Buena Suerte (spanish, set 2)",     0,                       layout_goldnpkr )
2180GAMEL( 198?, royale,   0,        pmpoker,  royale,   royale,   ROT0,   "Unknown",                   "Royale (ver.X)",                    GAME_NOT_WORKING,        layout_goldnpkr )
2181GAME(  1991, witchcrd, 0,        witchcrd, witchcrd, pmpoker,  ROT0,   "Unknown",                   "Witch Card (english)",              0 )
2182GAME(  1991, witchcda, witchcrd, witchcrd, witchcrd, pmpoker,  ROT0,   "Unknown",                   "Witch Card (spanish, set 1)",       0 )
2183GAME(  1991, witchcdb, witchcrd, witchcrd, witchcrd, pmpoker,  ROT0,   "Unknown",                   "Witch Card (spanish, set 2)",       0 )
2184GAME(  1993, sloco93,  0,        sloco93,  sloco93,  pmpoker,  ROT0,   "Unknown",                   "Super Loco 93 (spanish, set 1)",    0 )
2185GAME(  1993, sloco93a, sloco93,  sloco93,  sloco93,  pmpoker,  ROT0,   "Unknown",                   "Super Loco 93 (spanish, set 2)",    0 )
src/emu/cpuint.c
r3767r3768
1/***************************************************************************
2
3    cpuint.c
4
5    Core multi-CPU interrupt engine.
6
7    Copyright Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10***************************************************************************/
11
12#include "driver.h"
13#include "deprecat.h"
14#include "debug/debugcpu.h"
15
16
17
18/*************************************
19 *
20 *  Debug logging
21 *
22 *************************************/
23
24#define VERBOSE 0
25
26#define LOG(x)   do { if (VERBOSE) logerror x; } while (0)
27
28
29
30
31/*************************************
32 *
33 *  CPU interrupt variables
34 *
35 *************************************/
36
37/* current states for each CPU */
38static INT32 interrupt_vector[MAX_CPU][MAX_INPUT_LINES];
39
40/* deferred states written in callbacks */
41static UINT8 input_line_state[MAX_CPU][MAX_INPUT_LINES];
42static INT32 input_line_vector[MAX_CPU][MAX_INPUT_LINES];
43
44/* ick, interrupt event queues */
45#define MAX_INPUT_EVENTS      32
46static INT32 input_event_queue[MAX_CPU][MAX_INPUT_LINES][MAX_INPUT_EVENTS];
47static int input_event_index[MAX_CPU][MAX_INPUT_LINES];
48
49
50
51/*************************************
52 *
53 *  IRQ acknowledge callbacks
54 *
55 *************************************/
56
57static int cpu_0_irq_callback(const device_config *device, int line);
58static int cpu_1_irq_callback(const device_config *device, int line);
59static int cpu_2_irq_callback(const device_config *device, int line);
60static int cpu_3_irq_callback(const device_config *device, int line);
61static int cpu_4_irq_callback(const device_config *device, int line);
62static int cpu_5_irq_callback(const device_config *device, int line);
63static int cpu_6_irq_callback(const device_config *device, int line);
64static int cpu_7_irq_callback(const device_config *device, int line);
65
66cpu_irq_callback cpu_irq_callbacks[MAX_CPU] =
67{
68   cpu_0_irq_callback,
69   cpu_1_irq_callback,
70   cpu_2_irq_callback,
71   cpu_3_irq_callback,
72   cpu_4_irq_callback,
73   cpu_5_irq_callback,
74   cpu_6_irq_callback,
75   cpu_7_irq_callback
76};
77
78static int (*drv_irq_callbacks[MAX_CPU])(running_machine *, int);
79
80
81
82#if 0
83#pragma mark CORE CPU
84#endif
85
86/*************************************
87 *
88 *  Initialize a CPU's interrupt states
89 *
90 *************************************/
91
92void cpuint_init(running_machine *machine)
93{
94   int cpunum;
95   int line;
96
97   /* loop over all CPUs and input lines */
98   for (cpunum = 0; cpunum < cpu_gettotalcpu(); cpunum++)
99   {
100      /* reset any driver hooks into the IRQ acknowledge callbacks */
101      drv_irq_callbacks[cpunum] = NULL;
102
103      /* clear out all the CPU states */
104      for (line = 0; line < MAX_INPUT_LINES; line++)
105      {
106         input_line_state[cpunum][line] = CLEAR_LINE;
107         interrupt_vector[cpunum][line] =
108         input_line_vector[cpunum][line] = cputype_default_irq_vector(machine->config->cpu[cpunum].type);
109         input_event_index[cpunum][line] = 0;
110      }
111   }
112
113   /* set up some stuff to save */
114   state_save_push_tag(0);
115   state_save_register_item_2d_array("cpu", 0, interrupt_vector);
116   state_save_register_item_2d_array("cpu", 0, input_line_state);
117   state_save_register_item_2d_array("cpu", 0, input_line_vector);
118   state_save_pop_tag();
119}
120
121
122
123/*************************************
124 *
125 *  Reset a CPU's interrupt states
126 *
127 *************************************/
128
129void cpuint_reset(void)
130{
131   int cpunum, line;
132
133   /* loop over CPUs */
134   for (cpunum = 0; cpunum < cpu_gettotalcpu(); cpunum++)
135      for (line = 0; line < MAX_INPUT_LINES; line++)
136      {
137         interrupt_vector[cpunum][line] = cpunum_default_irq_vector(cpunum);
138         input_event_index[cpunum][line] = 0;
139      }
140}
141
142
143
144#if 0
145#pragma mark -
146#pragma mark LINE STATES
147#endif
148
149
150/*************************************
151 *
152 *  Empty a CPU's event queue for
153 *  a specific input line
154 *
155 *************************************/
156
157static TIMER_CALLBACK( cpunum_empty_event_queue )
158{
159   int cpunum = param & 0xff;
160   int line = param >> 8;
161   int i;
162
163   /* swap to the CPU's context */
164   cpuintrf_push_context(cpunum);
165
166   /* loop over all events */
167   for (i = 0; i < input_event_index[cpunum][line]; i++)
168   {
169      INT32 input_event = input_event_queue[cpunum][line][i];
170      int state = input_event & 0xff;
171      int vector = input_event >> 8;
172
173      LOG(("cpunum_empty_event_queue %d,%d,%d\n",cpunum,line,state));
174
175      /* set the input line state and vector */
176      input_line_state[cpunum][line] = state;
177      input_line_vector[cpunum][line] = vector;
178
179      /* special case: RESET */
180      if (line == INPUT_LINE_RESET)
181      {
182         /* if we're asserting the line, just halt the CPU */
183         if (state == ASSERT_LINE)
184            cpunum_suspend(cpunum, SUSPEND_REASON_RESET, 1);
185         else
186         {
187            /* if we're clearing the line that was previously asserted, or if we're just */
188            /* pulsing the line, reset the CPU */
189            if ((state == CLEAR_LINE && cpunum_is_suspended(cpunum, SUSPEND_REASON_RESET)) || state == PULSE_LINE)
190               cpunum_reset(cpunum);
191
192            /* if we're clearing the line, make sure the CPU is not halted */
193            cpunum_resume(cpunum, SUSPEND_REASON_RESET);
194         }
195      }
196
197      /* special case: HALT */
198      else if (line == INPUT_LINE_HALT)
199      {
200         /* if asserting, halt the CPU */
201         if (state == ASSERT_LINE)
202            cpunum_suspend(cpunum, SUSPEND_REASON_HALT, 1);
203
204         /* if clearing, unhalt the CPU */
205         else if (state == CLEAR_LINE)
206            cpunum_resume(cpunum, SUSPEND_REASON_HALT);
207      }
208
209      /* all other cases */
210      else
211      {
212         /* switch off the requested state */
213         switch (state)
214         {
215            case PULSE_LINE:
216               /* temporary: PULSE_LINE only makes sense for NMI lines on Z80 */
217               assert(machine->config->cpu[cpunum].type != CPU_Z80 || line == INPUT_LINE_NMI);
218               activecpu_set_input_line(line, INTERNAL_ASSERT_LINE);
219               activecpu_set_input_line(line, INTERNAL_CLEAR_LINE);
220               break;
221
222            case HOLD_LINE:
223            case ASSERT_LINE:
224               activecpu_set_input_line(line, INTERNAL_ASSERT_LINE);
225               break;
226
227            case CLEAR_LINE:
228               activecpu_set_input_line(line, INTERNAL_CLEAR_LINE);
229               break;
230
231            default:
232               logerror("cpunum_empty_event_queue cpu #%d, line %d, unknown state %d\n", cpunum, line, state);
233         }
234
235         /* generate a trigger to unsuspend any CPUs waiting on the interrupt */
236         if (state != CLEAR_LINE)
237            cpu_triggerint(machine, cpunum);
238      }
239   }
240
241   /* swap back */
242   cpuintrf_pop_context();
243
244   /* reset counter */
245   input_event_index[cpunum][line] = 0;
246}
247
248
249
250/*************************************
251 *
252 *  Set the state of a CPU's input
253 *  line
254 *
255 *************************************/
256
257void cpunum_set_input_line(running_machine *machine, int cpunum, int line, int state)
258{
259   int vector = (line >= 0 && line < MAX_INPUT_LINES) ? interrupt_vector[cpunum][line] : 0xff;
260   cpunum_set_input_line_and_vector(machine, cpunum, line, state, vector);
261}
262
263
264void cputag_set_input_line(running_machine *machine, const char *tag, int line, int state)
265{
266   int cpunum = mame_find_cpu_index(machine, tag);
267   assert(cpunum != -1);
268   cpunum_set_input_line(machine, cpunum, line, state);
269}
270
271
272void cpunum_set_input_line_vector(int cpunum, int line, int vector)
273{
274   if (cpunum < cpu_gettotalcpu() && line >= 0 && line < MAX_INPUT_LINES)
275   {
276      LOG(("cpunum_set_input_line_vector(%d,%d,$%04x)\n",cpunum,line,vector));
277      interrupt_vector[cpunum][line] = vector;
278      return;
279   }
280   LOG(("cpunum_set_input_line_vector CPU#%d line %d > max input lines\n", cpunum, line));
281}
282
283
284void cpunum_set_input_line_and_vector(running_machine *machine, int cpunum, int line, int state, int vector)
285{
286#ifdef MAME_DEBUG
287   /* catch errors where people use PULSE_LINE for CPUs that don't support it */
288   if (state == PULSE_LINE && line != INPUT_LINE_NMI && line != INPUT_LINE_RESET)
289   {
290      switch (machine->config->cpu[cpunum].type)
291      {
292         case CPU_Z80:
293         case CPU_Z180:
294         case CPU_M68000:
295         case CPU_M68008:
296         case CPU_M68010:
297         case CPU_M68EC020:
298         case CPU_M68020:
299         case CPU_M68040:
300         case CPU_R4600BE:
301         case CPU_R4600LE:
302         case CPU_R4650BE:
303         case CPU_R4650LE:
304         case CPU_R4700BE:
305         case CPU_R4700LE:
306         case CPU_R5000BE:
307         case CPU_R5000LE:
308         case CPU_QED5271BE:
309         case CPU_QED5271LE:
310         case CPU_RM7000BE:
311         case CPU_RM7000LE:
312         case CPU_PPC403GA:
313         case CPU_PPC403GCX:
314         case CPU_PPC601:
315         case CPU_PPC602:
316         case CPU_PPC603:
317         case CPU_PPC603E:
318         case CPU_PPC603R:
319         case CPU_PPC604:
320         case CPU_I8035:
321         case CPU_I8041:
322         case CPU_I8048:
323         case CPU_I8648:
324         case CPU_I8748:
325         case CPU_MB8884:
326         case CPU_N7751:
327         case CPU_TMS34010:
328         case CPU_TMS34020:
329         case CPU_TMS32010:
330         case CPU_TMS32025:
331         case CPU_TMS32026:
332            fatalerror("CPU %s: PULSE_LINE used with level-detected IRQ %d\n", machine->config->cpu[cpunum].tag, line);
333            break;
334
335         default:
336            break;
337      }
338   }
339#endif
340
341   if (line >= 0 && line < MAX_INPUT_LINES)
342   {
343      INT32 input_event = (state & 0xff) | (vector << 8);
344      int event_index = input_event_index[cpunum][line]++;
345
346      LOG(("cpunum_set_input_line_and_vector(%d,%d,%d,%02x)\n", cpunum, line, state, vector));
347
348      /* if we're full of events, flush the queue and log a message */
349      if (event_index >= MAX_INPUT_EVENTS)
350      {
351         input_event_index[cpunum][line]--;
352         cpunum_empty_event_queue(machine, NULL, cpunum | (line << 8));
353         event_index = input_event_index[cpunum][line]++;
354         logerror("Exceeded pending input line event queue on CPU %d!\n", cpunum);
355      }
356
357      /* enqueue the event */
358      if (event_index < MAX_INPUT_EVENTS)
359      {
360         input_event_queue[cpunum][line][event_index] = input_event;
361
362         /* if this is the first one, set the timer */
363         if (event_index == 0)
364            timer_call_after_resynch(NULL, cpunum | (line << 8), cpunum_empty_event_queue);
365      }
366   }
367}
368
369
370void cputag_set_input_line_and_vector(running_machine *machine, const char *tag, int line, int state, int vector)
371{
372   int cpunum = mame_find_cpu_index(machine, tag);
373   assert(cpunum != -1);
374   cpunum_set_input_line_and_vector(machine, cpunum, line, state, vector);
375}
376
377
378#if 0
379#pragma mark -
380#pragma mark INTERRUPT HANDLING
381#endif
382
383/*************************************
384 *
385 *  Set IRQ callback for drivers
386 *
387 *************************************/
388
389void cpunum_set_irq_callback(int cpunum, int (*callback)(running_machine *, int))
390{
391   drv_irq_callbacks[cpunum] = callback;
392}
393
394
395
396/*************************************
397 *
398 *  Internal IRQ callbacks
399 *
400 *************************************/
401
402INLINE int generic_irq_callback(running_machine *machine, int cpunum, int line)
403{
404   int vector = input_line_vector[cpunum][line];
405
406   LOG(("cpu_%d_irq_callback(%d) $%04x\n", cpunum, line, vector));
407
408   /* if the IRQ state is HOLD_LINE, clear it */
409   if (input_line_state[cpunum][line] == HOLD_LINE)
410   {
411      LOG(("->set_irq_line(%d,%d,%d)\n", cpunum, line, CLEAR_LINE));
412      activecpu_set_input_line(line, INTERNAL_CLEAR_LINE);
413      input_line_state[cpunum][line] = CLEAR_LINE;
414   }
415
416   /* if there's a driver callback, run it */
417   if (drv_irq_callbacks[cpunum])
418      vector = (*drv_irq_callbacks[cpunum])(machine, line);
419
420   /* notify the debugger */
421   debug_cpu_interrupt_hook(machine, cpunum, line);
422
423   /* otherwise, just return the current vector */
424   return vector;
425}
426
427static int cpu_0_irq_callback(const device_config *device, int line) { return generic_irq_callback(device->machine, 0, line); }
428static int cpu_1_irq_callback(const device_config *device, int line) { return generic_irq_callback(device->machine, 1, line); }
429static int cpu_2_irq_callback(const device_config *device, int line) { return generic_irq_callback(device->machine, 2, line); }
430static int cpu_3_irq_callback(const device_config *device, int line) { return generic_irq_callback(device->machine, 3, line); }
431static int cpu_4_irq_callback(const device_config *device, int line) { return generic_irq_callback(device->machine, 4, line); }
432static int cpu_5_irq_callback(const device_config *device, int line) { return generic_irq_callback(device->machine, 5, line); }
433static int cpu_6_irq_callback(const device_config *device, int line) { return generic_irq_callback(device->machine, 6, line); }
434static int cpu_7_irq_callback(const device_config *device, int line) { return generic_irq_callback(device->machine, 7, line); }
src/emu/cpuint.h
r3767r3768
1/***************************************************************************
2
3    cpuint.h
4
5    Core multi-CPU interrupt engine.
6
7    Copyright Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10***************************************************************************/
11
12#pragma once
13
14#ifndef __CPUINT_H__
15#define __CPUINT_H__
16
17#include "memory.h"
18
19#define INTERRUPT_GEN(func)      void func(running_machine *machine, int cpunum)
20#define IRQ_CALLBACK(func)      int func(running_machine *machine, int irqline)
21
22
23
24/*************************************
25 *
26 *  Startup/shutdown
27 *
28 *************************************/
29
30void cpuint_init(running_machine *machine);
31
32void cpuint_reset(void);
33
34
35
36/*************************************
37 *
38 *  CPU lines
39 *
40 *************************************/
41
42/* Set the logical state (ASSERT_LINE/CLEAR_LINE) of the an input line on a CPU */
43void cpunum_set_input_line(running_machine *machine, int cpunum, int line, int state);
44void cputag_set_input_line(running_machine *machine, const char *tag, int line, int state);
45
46/* Set the vector to be returned during a CPU's interrupt acknowledge cycle */
47void cpunum_set_input_line_vector(int cpunum, int irqline, int vector);
48
49/* Set the logical state (ASSERT_LINE/CLEAR_LINE) of the an input line on a CPU and its associated vector */
50void cpunum_set_input_line_and_vector(running_machine *machine, int cpunum, int line, int state, int vector);
51void cputag_set_input_line_and_vector(running_machine *machine, const char *tag, int line, int state, int vector);
52
53/* Install a driver callback for IRQ acknowledge */
54void cpunum_set_irq_callback(int cpunum, int (*callback)(running_machine *machine, int irqline));
55
56
57#endif   /* __CPUINT_H__ */
src/emu/cpu/h83002/h83002.c
r3767r3768
1/***************************************************************************
2
3 h83002.c: Hitachi H8/3002 microcontroller emulator
4
5 Original by The_Author & DynaChicken for the ZiNc emulator.
6
7 Rewrite for MAME by R. Belmont, including...
8   - Changed types to MAME standards
9   - Added MAME cpuintrf glue
10   - Put all per-CPU state in a struct
11   - Fixed ADD flag calcs
12   - Added support for all 8 flag bits
13   - Added cycle timing (probably not right yet)
14   - Fixed and optimized interrupt handling
15   - Optimized main execution loop
16   - Added new opcodes for ND-1 and System 23 BIOS programs
17   - Improved I/O and timer support
18   - Fixed major error in 7Cxx/7Dxx series bit opcodes where the wrong
19     instructions were being picked.
20
21 TS 20060412 Added exts.l, sub.l, divxs.w (buggy), jsr @reg, rotxl.l reg, mov.l @(adr, reg), reg
22 LE 20070903 Added divxu.b  shal.l  extu.w  dec.l #Imm,Rd  subx.b
23 LE 20080202 Separated 3002/3044/3007, Added or.l  shal.l  rotl.l  not.l  neg.l  exts.w
24             sub/or/xor.l #Imm:32,ERd  bset/bnot/bclr.b Rn,@ERd  bst/bist.b #Imm:3,@ERd  bnot.b #Imm:3,@ERd
25
26 Note: The H8/3000 series is normally back-compatible to the 8-bit H8/300,
27 but the 3002 does not include "emulation mode" - it always runs in full
28 16/32-bit ("advanced") mode.  So this core is not suitable for general
29 H8/300 emulation.
30
31****************************************************************************/
32
33#include "debugger.h"
34#include "deprecat.h"
35#include "h83002.h"
36#include "h8priv.h"
37
38#define H8_SP   (7)
39
40#define h8_mem_read8(x) program_read_byte_16be(x)
41#define h8_mem_read16(x) program_read_word_16be(x)
42#define h8_mem_write8(x, y)  program_write_byte_16be(x, y)
43#define h8_mem_write16(x, y) program_write_word_16be(x, y)
44
45// timing macros
46// note: we assume a system 12 - type setup where external access is 3+1 states
47// timing will be off somewhat for other configurations.
48#define H8_IFETCH_TIMING(x)   h8_cyccnt -= (x) * 4;
49#define H8_BRANCH_TIMING(x)   h8_cyccnt -= (x) * 4;
50#define H8_STACK_TIMING(x)   h8_cyccnt -= (x) * 4;
51#define H8_BYTE_TIMING(x, adr)   if (address24 >= 0xffff10) h8_cyccnt -= (x) * 3; else h8_cyccnt -= (x) * 4;
52#define H8_WORD_TIMING(x, adr)   if (address24 >= 0xffff10) h8_cyccnt -= (x) * 3; else h8_cyccnt -= (x) * 4;
53#define H8_IOP_TIMING(x)   h8_cyccnt -= (x);
54
55INLINE UINT32 h8_mem_read32(offs_t address)
56{
57   UINT32 result = program_read_word_16be(address) << 16;
58   return result | program_read_word_16be(address + 2);
59}
60
61INLINE void h8_mem_write32(offs_t address, UINT32 data)
62{
63   program_write_word_16be(address, data >> 16);
64   program_write_word_16be(address + 2, data);
65}
66
67
68h83002_state h8;
69
70static INT32 h8_cyccnt;
71
72static UINT32 udata32, address24;
73static INT32 sdata32;
74static UINT16 udata16, ext16;
75static INT16 sdata16;
76static UINT8 udata8;
77static INT8 sdata8;
78static UINT8 srcreg, dstreg;
79
80/* internal functions */
81
82static void h8_check_irqs(void);
83
84static void h8_group0(UINT16 opcode);
85static void h8_group1(UINT16 opcode);
86static void h8_group5(UINT16 opcode);
87static void h8_group6(UINT16 opcode);
88static void h8_group7(UINT16 opcode);
89
90static int h8_branch(UINT8 condition);
91
92static UINT8 h8_mov8(UINT8 src);
93static UINT16 h8_mov16(UINT16 src);
94static UINT32 h8_mov32(UINT32 src);
95
96static UINT8 h8_add8(UINT8 src, UINT8 dst);
97static UINT16 h8_add16(UINT16 src, UINT16 dst);
98static UINT32 h8_add32(UINT32 src, UINT32 dst);
99
100static UINT8 h8_sub8(UINT8 src, UINT8 dst);
101static UINT16 h8_sub16(UINT16 src, UINT16 dst);
102static UINT32 h8_sub32(UINT32 src, UINT32 dst);
103
104static UINT8 h8_addx8(UINT8 src, UINT8 dst);
105
106static void h8_cmp8(UINT8 src, UINT8 dst);
107static void h8_cmp16(UINT16 src, UINT16 dst);
108static void h8_cmp32(UINT32 src, UINT32 dst);
109static UINT8 h8_subx8(UINT8 src, UINT8 dst);
110
111static UINT8 h8_or8(UINT8 src, UINT8 dst);
112static UINT16 h8_or16(UINT16 src, UINT16 dst);
113static UINT32 h8_or32(UINT32 src, UINT32 dst);
114
115static UINT8 h8_xor8(UINT8 src, UINT8 dst);
116static UINT16 h8_xor16(UINT16 src, UINT16 dst);
117static UINT32 h8_xor32(UINT32 src, UINT32 dst);
118
119static UINT8 h8_and8(UINT8 src, UINT8 dst);
120static UINT16 h8_and16(UINT16 src, UINT16 dst);
121static UINT32 h8_and32(UINT32 src, UINT32 dst);
122
123static INT8 h8_neg8(INT8 src);
124static INT16 h8_neg16(INT16 src);
125static INT32 h8_neg32(INT32 src);
126
127static UINT16 h8_divxu8 (UINT16 dst, UINT8  src);
128static UINT32 h8_divxu16(UINT32 dst, UINT16 src);
129
130static UINT8 h8_not8(UINT8 src);
131static UINT16 h8_not16(UINT16 src);
132static UINT32 h8_not32(UINT32 src);
133
134static UINT8 h8_rotl8(UINT8 src);
135static UINT16 h8_rotl16(UINT16 src);
136static UINT32 h8_rotl32(UINT32 src);
137
138static UINT8 h8_rotxl8(UINT8 src);
139static UINT16 h8_rotxl16(UINT16 src);
140static UINT32 h8_rotxl32(UINT32 src);
141
142static UINT8 h8_rotxr8(UINT8 src);
143static UINT16 h8_rotxr16(UINT16 src);
144
145static UINT8 h8_shll8(UINT8 src);
146static UINT16 h8_shll16(UINT16 src);
147static UINT32 h8_shll32(UINT32 src);
148
149static UINT8 h8_shlr8(UINT8 src);
150static UINT16 h8_shlr16(UINT16 src);
151static UINT32 h8_shlr32(UINT32 src);
152
153static INT8 h8_shal8(INT8 src);
154static INT16 h8_shal16(INT16 src);
155static INT32 h8_shal32(INT32 src);
156
157static INT8 h8_shar8(INT8 src);
158static INT16 h8_shar16(INT16 src);
159static INT32 h8_shar32(INT32 src);
160
161static UINT8 h8_dec8(UINT8 src);
162static UINT16 h8_dec16(UINT16 src);
163static UINT32 h8_dec32(UINT32 src);
164
165static UINT8 h8_inc8(UINT8 src);
166static UINT16 h8_inc16(UINT16 src);
167static UINT32 h8_inc32(UINT32 src);
168
169static UINT8 h8_bnot8(UINT8 src, UINT8 dst);
170static UINT8 h8_bst8(UINT8 src, UINT8 dst);
171static UINT8 h8_bist8(UINT8 src, UINT8 dst);
172static UINT8 h8_bset8(UINT8 src, UINT8 dst);
173static UINT8 h8_bclr8(UINT8 src, UINT8 dst);
174static void h8_btst8(UINT8 src, UINT8 dst);
175static void h8_bld8(UINT8 src, UINT8 dst); // loads to carry
176static void h8_bor8(UINT8 src, UINT8 dst); // result in carry
177//static void h8_bxor8(UINT8 src, UINT8 dst);
178
179static INT32 h8_mulxs16(INT16 src, INT16 dst);
180static UINT32 h8_divxs16(INT16 src, INT32 dst);
181
182/* implementation */
183
184extern CPU_DISASSEMBLE( h8 );
185
186void h8_3002_InterruptRequest(UINT8 source)
187{
188   if(source>31)
189   {
190      h8.h8_IRQrequestH |= (1<<(source-32));
191   }
192   else
193   {
194      h8.h8_IRQrequestL |= (1<<source);
195   }
196}
197
198
199static UINT8 h8_get_ccr(void)
200{
201   h8.ccr = 0;
202   if(h8.h8nflag)h8.ccr |= NFLAG;
203   if(h8.h8zflag)h8.ccr |= ZFLAG;
204   if(h8.h8vflag)h8.ccr |= VFLAG;
205   if(h8.h8cflag)h8.ccr |= CFLAG;
206   if(h8.h8uflag)h8.ccr |= UFLAG;
207   if(h8.h8hflag)h8.ccr |= HFLAG;
208   if(h8.h8uiflag)h8.ccr |= UIFLAG;
209   if(h8.h8iflag)h8.ccr |= IFLAG;
210   return h8.ccr;
211}
212
213static char *h8_get_ccr_str(void)
214{
215   static char res[8];
216
217   memset(res, 0, 8);
218   if(h8.h8iflag) strcat(res, "I"); else strcat(res, "i");
219   if(h8.h8uiflag)strcat(res, "U"); else strcat(res, "u");
220   if(h8.h8hflag) strcat(res, "H"); else strcat(res, "h");
221   if(h8.h8uflag) strcat(res, "U"); else strcat(res, "u");
222   if(h8.h8nflag) strcat(res, "N"); else strcat(res, "n");
223   if(h8.h8zflag) strcat(res, "Z"); else strcat(res, "z");
224   if(h8.h8vflag) strcat(res, "V"); else strcat(res, "v");
225   if(h8.h8cflag) strcat(res, "C"); else strcat(res, "c");
226
227   return res;
228}
229
230static void h8_set_ccr(UINT8 data)
231{
232   h8.ccr = data;
233
234   h8.h8nflag = 0;
235   h8.h8zflag = 0;
236   h8.h8vflag = 0;
237   h8.h8cflag = 0;
238   h8.h8hflag = 0;
239   h8.h8iflag = 0;
240   h8.h8uflag = 0;
241   h8.h8uiflag = 0;
242
243   if(h8.ccr & NFLAG) h8.h8nflag = 1;
244   if(h8.ccr & ZFLAG) h8.h8zflag = 1;
245   if(h8.ccr & VFLAG) h8.h8vflag = 1;
246   if(h8.ccr & CFLAG) h8.h8cflag = 1;
247   if(h8.ccr & HFLAG) h8.h8hflag = 1;
248   if(h8.ccr & UFLAG) h8.h8uflag = 1;
249   if(h8.ccr & UIFLAG) h8.h8uiflag = 1;
250   if(h8.ccr & IFLAG) h8.h8iflag = 1;
251
252   h8_check_irqs();
253}
254
255static INT16 h8_getreg16(UINT8 reg)
256{
257   if(reg > 7)
258   {
259      return h8.regs[reg-8]>>16;
260   }
261   else
262   {
263      return h8.regs[reg];
264   }
265}
266
267static void h8_setreg16(UINT8 reg, UINT16 data)
268{
269   if(reg > 7)
270   {
271      h8.regs[reg-8] &= 0xffff;
272      h8.regs[reg-8] |= data<<16;
273   }
274   else
275   {
276      h8.regs[reg] &= 0xffff0000;
277      h8.regs[reg] |= data;
278   }
279}
280
281static UINT8 h8_getreg8(UINT8 reg)
282{
283   if(reg > 7)
284   {
285      return h8.regs[reg-8];
286   }
287   else
288   {
289      return h8.regs[reg]>>8;
290   }
291}
292
293static void h8_setreg8(UINT8 reg, UINT8 data)
294{
295   if(reg > 7)
296   {
297      h8.regs[reg-8] &= 0xffffff00;
298      h8.regs[reg-8] |= data;
299   }
300   else
301   {
302      h8.regs[reg] &= 0xffff00ff;
303      h8.regs[reg] |= data<<8;
304   }
305}
306
307static UINT32 h8_getreg32(UINT8 reg)
308{
309   return h8.regs[reg];
310}
311
312static void h8_setreg32(UINT8 reg, UINT32 data)
313{
314   h8.regs[reg] = data;
315}
316
317static STATE_POSTLOAD( h8_onstateload )
318{
319   h8_set_ccr(h8.ccr);
320}
321
322static CPU_INIT( h8 )
323{
324   memset(&h8, 0, sizeof(h8));
325   h8.h8iflag = 1;
326
327   h8.irq_cb = irqcallback;
328   h8.device = device;
329
330   state_save_register_item("H8/3002", index, h8.h8err);
331   state_save_register_item_array("H8/3002", index, h8.regs);
332   state_save_register_item("H8/3002", index, h8.pc);
333   state_save_register_item("H8/3002", index, h8.ppc);
334   state_save_register_item("H8/3002", index, h8.h8_IRQrequestH);
335   state_save_register_item("H8/3002", index, h8.h8_IRQrequestL);
336   state_save_register_item("H8/3002", index, h8.ccr);
337
338   state_save_register_item_array("H8/3002", index, h8.per_regs);
339   state_save_register_item("H8/3002", index, h8.h8TSTR);
340   state_save_register_item_array("H8/3002", index, h8.h8TCNT);
341
342   state_save_register_postload(Machine, h8_onstateload, NULL);
343
344   h8_itu_init();
345}
346
347static CPU_INIT( h8_3007 )
348{
349   CPU_INIT_CALL(h8);
350   h8_3007_itu_init();
351}
352
353static CPU_RESET( h8 )
354{
355   h8.h8err = 0;
356   h8.pc = h8_mem_read32(0) & 0xffffff;
357   change_pc(h8.pc);
358
359   // disable timers
360   h8.h8TSTR = 0;
361
362   h8_itu_reset();
363}
364
365static void h8_GenException(UINT8 vectornr)
366{
367   // push PC on stack
368   // extended mode stack push!
369   h8_setreg32(H8_SP, h8_getreg32(H8_SP)-4);
370   h8_mem_write32(h8_getreg32(H8_SP), h8.pc);
371   // push ccr
372   h8_setreg32(H8_SP, h8_getreg32(H8_SP)-2);
373   h8_mem_write16(h8_getreg32(H8_SP), h8_get_ccr());
374
375   // generate address from vector
376   h8_set_ccr(h8_get_ccr() | 0x80);
377   if (h8.h8uiflag == 0)
378      h8_set_ccr(h8_get_ccr() | 0x40);
379   h8.pc = h8_mem_read32(vectornr * 4) & 0xffffff;
380   change_pc(h8.pc);
381
382   // I couldn't find timing info for exceptions, so this is a guess (based on JSR/BSR)
383   H8_IFETCH_TIMING(2);
384   H8_STACK_TIMING(2);
385}
386
387static int h8_get_priority(UINT8 bit)
388{
389   int res = 0;
390   switch(bit)
391   {
392   case 12: // IRQ0
393      if (h8.per_regs[0xF8]&0x80) res = 1; break;
394   case 13: // IRQ1
395      if (h8.per_regs[0xF8]&0x40) res = 1; break;
396   case 14: // IRQ2
397   case 15: // IRQ3
398      if (h8.per_regs[0xF8]&0x20) res = 1; break;
399   case 16: // IRQ4
400   case 17: // IRQ5
401      if (h8.per_regs[0xF8]&0x10) res = 1; break;
402   }
403   return res;
404}
405
406static void h8_check_irqs(void)
407{
408   int lv = -1;
409   if (h8.h8iflag == 0)
410   {
411      lv = 0;
412   }
413   else
414   {
415      if ((h8.per_regs[0xF2]&0x08)/*SYSCR*/ == 0)
416      {
417         if (h8.h8uiflag == 0)
418            lv = 1;
419      }
420   }
421
422   // any interrupts wanted and can accept ?
423   if(((h8.h8_IRQrequestH != 0) || (h8.h8_IRQrequestL != 0)) && (lv >= 0))
424   {
425      UINT8 bit, source;
426      // which one ?
427      for(bit = 0, source = 0xff; source == 0xff && bit < 32; bit++)
428      {
429         if( h8.h8_IRQrequestL & (1<<bit) )
430         {
431            if (h8_get_priority(bit) >= lv)
432            {
433               // mask off
434               h8.h8_IRQrequestL &= ~(1<<bit);
435               source = bit;
436            }
437         }
438      }
439      // which one ?
440      for(bit = 0; source == 0xff && bit < 32; bit++)
441      {
442         if( h8.h8_IRQrequestH & (1<<bit) )
443         {
444            if (h8_get_priority(bit + 32) >= lv)
445            {
446               // mask off
447               h8.h8_IRQrequestH &= ~(1<<bit);
448               source = bit + 32;
449            }
450         }
451      }
452
453      // call the MAME callback if it's one of the 6
454      // external IRQs
455      if (source >= 12 && source <= 17)
456      {
457         (*h8.irq_cb)(h8.device, source - 12 + H8_IRQ0);
458      }
459
460      if (source != 0xff)
461         h8_GenException(source);
462   }
463}
464
465static CPU_EXECUTE( h8 )
466{
467   UINT16 opcode=0;
468
469   h8_cyccnt = cycles;
470
471    h8_check_irqs();
472
473   while ((h8_cyccnt > 0) && (!h8.h8err))
474   {
475      h8.ppc = h8.pc;
476
477      debugger_instruction_hook(Machine, h8.pc);
478
479      opcode = cpu_readop16(h8.pc);
480//      mame_printf_debug("[%06x]: %04x => %x\n", h8.pc, opcode, (opcode>>12)&0xf);
481      h8.pc += 2;
482
483      switch((opcode>>12) & 0xf)
484      {
485      case 0x0:
486         h8_group0(opcode);
487         break;
488      case 0x1:
489         h8_group1(opcode);
490         break;
491      case 0x2:
492         // mov.b @xx:8, Rd (abs)
493         dstreg = (opcode>>8) & 0xf;
494         udata8 = h8_mem_read8(0xffff00+(opcode & 0xff));
495         h8_mov8(udata8); // flags calculation, dont care about others
496         h8_setreg8(dstreg, udata8);
497         H8_IFETCH_TIMING(1);
498         break;
499      case 0x3: // pass
500         // mov.b Rs, @xx:8 (abs)
501         srcreg = (opcode>>8) & 0xf;
502         udata8 = h8_getreg8(srcreg);
503         h8_mov8(udata8); // flags calculation, dont care about others
504         h8_mem_write8(0xffff00+(opcode & 0xff), udata8);
505         H8_IFETCH_TIMING(1);
506         H8_BYTE_TIMING(1, 0xffff00+(opcode & 0xff));
507         break;
508      case 0x4:
509         // bcc @xx:8
510         sdata8 = (opcode & 0xff);
511         if( h8_branch((opcode >> 8) & 0xf) == 1)h8.pc += sdata8;
512         change_pc(h8.pc);
513         break;
514      case 0x5:
515         h8_group5(opcode);
516         break;
517      case 0x6:
518         h8_group6(opcode);
519         break;
520      case 0x7:
521         h8_group7(opcode);
522         break;
523      case 0x8:
524         // add.b #xx:8, Rd
525         dstreg = (opcode>>8) & 0xf;
526         udata8 = h8_add8(opcode & 0xff, h8_getreg8(dstreg));
527         h8_setreg8(dstreg, udata8);
528         H8_IFETCH_TIMING(1)
529         break;
530      case 0x9:
531         // addx.b #xx:8, Rd
532         dstreg = (opcode>>8) & 0xf;
533         udata8 = h8_addx8(opcode & 0xff, h8_getreg8(dstreg));
534         h8_setreg8(dstreg, udata8);
535         H8_IFETCH_TIMING(1)
536         break;
537      case 0xa:
538         // cmp.b #xx:8, Rd
539         dstreg = (opcode>>8) & 0xf;
540         h8_cmp8(opcode & 0xff, h8_getreg8(dstreg));
541         H8_IFETCH_TIMING(1);
542         break;
543      case 0xb:
544         // subx.b #xx:8, Rd
545         dstreg = (opcode>>8) & 0xf;
546         udata8 = h8_subx8(opcode & 0xff, h8_getreg8(dstreg));
547         h8_setreg8(dstreg, udata8);
548         H8_IFETCH_TIMING(1);
549         break;
550      case 0xc:
551         // or.b #xx:8, Rd
552         dstreg = (opcode>>8) & 0xf;
553         udata8 = h8_or8(opcode & 0xff, h8_getreg8(dstreg));
554         h8_setreg8(dstreg, udata8);
555         H8_IFETCH_TIMING(1);
556         break;
557      case 0xd:
558         // xor.b #xx:8, Rd
559         dstreg = (opcode>>8) & 0xf;
560         udata8 = h8_xor8(opcode & 0xff, h8_getreg8(dstreg));
561         h8_setreg8(dstreg, udata8);
562         H8_IFETCH_TIMING(1);
563         break;
564      case 0xe: // pass
565         // and.b #xx:8, Rd
566         dstreg = (opcode>>8) & 0xf;
567         udata8 = h8_and8(opcode & 0xff, h8_getreg8(dstreg));
568         h8_setreg8(dstreg, udata8);
569         H8_IFETCH_TIMING(1)
570         break;
571      case 0xf: // pass
572         // mov.b #xx:8, Rd
573         dstreg = (opcode>>8) & 0xf;
574         udata8 = h8_mov8(opcode & 0xff);
575         h8_setreg8(dstreg, udata8);
576         H8_IFETCH_TIMING(1);
577         break;
578      }
579   }
580
581   if (h8.h8err)
582   {
583      fatalerror("H8/3002: Unknown opcode (PC=%x)  %x", h8.ppc, opcode);
584
585   }
586
587   return cycles - h8_cyccnt;
588}
589
590static void h8_group0(UINT16 opcode)
591{
592   switch((opcode>>8)&0xf)
593   {
594   case 0:
595      // nop
596      H8_IFETCH_TIMING(1);
597      break;
598   case 0x1:
599      // 010x  where x should always be 0!
600      if((opcode & 0xf) != 0)
601      {
602         h8.h8err = 1;
603         break;
604      }
605      switch((opcode>>4) & 0xf)
606      {
607         // 0100 mov.l prefix
608      case 0xf:     // and.l Rn, Rn
609         ext16 = h8_mem_read16(h8.pc);
610         h8.pc += 2;
611         if (ext16 & 0x88)
612         {
613            h8.h8err = 1;
614         }
615         else
616         {
617            dstreg = ext16 & 0x7;
618            switch((ext16>>8)&0xff)
619            {
620            case 0x64:   // or.l ERs, ERd
621               udata32 = h8_or32(h8_getreg32((ext16>>4) & 0x7), h8_getreg32(dstreg));
622               break;
623            case 0x65:   // xor.l ERs, ERd
624               udata32 = h8_xor32(h8_getreg32((ext16>>4) & 0x7), h8_getreg32(dstreg));
625               break;
626            case 0x66:   // and.l ERs, ERd
627               udata32 = h8_and32(h8_getreg32((ext16>>4) & 0x7), h8_getreg32(dstreg));
628               break;
629            default:
630               h8.h8err = 1;
631               return;
632            }
633            h8_setreg32(dstreg, udata32);
634            H8_IFETCH_TIMING(2);
635         }
636         break;
637
638      case 0:
639         ext16 = h8_mem_read16(h8.pc);
640         h8.pc+=2;
641         switch((ext16 >> 8) & 0xff)
642         {
643         case 0x69:
644            if((ext16 & 0x80) == 0x80)
645            {
646               // mov.l rx, @rx
647               udata32 = h8_mov32(h8_getreg32(ext16 & 7));
648               h8_mem_write32(h8_getreg32((ext16 >> 4) & 7), udata32);
649               H8_IFETCH_TIMING(2);
650               H8_WORD_TIMING(2, h8_getreg32((ext16 >> 4) & 7));
651            }
652            else
653            {
654               // mov.l @rx, rx
655               udata32 = h8_mem_read32(h8_getreg32( (ext16 >> 4) &7));
656               h8_mov32(udata32);
657               h8_setreg32(ext16 & 7, udata32);
658               H8_IFETCH_TIMING(2);
659               H8_WORD_TIMING(2, h8_getreg32( (ext16 >> 4) &7));
660            }
661            break;
662         case 0x6b:
663            // mov.l rx, @xx / mov.l @xx, rx
664            switch((ext16 >> 4)&0xf)
665            {
666            case 0x2:
667               // mov.l @aa:24, erx
668               address24=h8_mem_read32(h8.pc);
669               h8.pc += 4;
670               udata32=h8_mem_read32(address24);
671               h8_mov32(udata32); // flags only
672               h8_setreg32(ext16 & 0x7, udata32);
673               H8_IFETCH_TIMING(4);
674               H8_WORD_TIMING(2, address24);
675               break;
676            case 0xa:
677               // mov.l erx, @aa:24
678               address24=h8_mem_read32(h8.pc);
679               h8.pc += 4;
680               udata32=h8_getreg32(ext16 & 0x7);
681               h8_mov32(udata32); // flags only
682               h8_mem_write32(address24, udata32);
683               H8_IFETCH_TIMING(4);
684               H8_WORD_TIMING(2, address24);
685               break;
686            default:
687               h8.h8err = 1;
688               break;
689            }
690            break;
691         case 0x6d:
692            if(ext16 & 0x80)
693            {
694               // mov.l rs, @-erd
695               srcreg = (ext16>>4)&7;
696               h8_setreg32(srcreg, h8_getreg32(srcreg)-4);
697               address24 = h8_getreg32(srcreg) & 0xffffff;
698               udata32 = h8_getreg32(ext16 & 0x7);
699               h8_mem_write32(address24, udata32);
700               H8_IFETCH_TIMING(2);
701               H8_WORD_TIMING(2, address24);
702               H8_IOP_TIMING(2);
703            }
704            else
705            {
706               // mov.l @ers+, rd
707               srcreg = (ext16 >>4)&7;
708               address24 = h8_getreg32(srcreg) & 0xffffff;
709               h8_setreg32(srcreg, h8_getreg32(srcreg)+4);
710               udata32 = h8_mem_read32(address24);
711               h8_setreg32(ext16 & 0x7, udata32);
712               H8_IFETCH_TIMING(2);
713               H8_WORD_TIMING(2, address24);
714               H8_IOP_TIMING(2);
715            }
716            h8_mov32(udata32);
717            break;
718         case 0x6f:
719            // mov.l @(displ16 + Rs), rd
720            sdata16=h8_mem_read16(h8.pc); // sign extend displacements !
721            h8.pc += 2;
722            address24 = (h8_getreg32((ext16 >> 4)&7)) & 0xffffff;
723            address24 += sdata16;
724            H8_IFETCH_TIMING(3);
725            H8_WORD_TIMING(2, address24);
726            if(ext16 & 0x80)
727            {
728               udata32 = h8_getreg32(ext16 & 0x7);
729               h8_mem_write32(address24, udata32);
730            }
731            else
732            {
733               udata32 = h8_mem_read32(address24);
734               h8_setreg32(ext16 & 0x7, udata32);
735            }
736            h8_mov32(udata32);
737            break;
738         case 0x78:
739            // prefix for
740            // mov.l (@aa:x, rx), Rx
741            //00000A10 010078606B2600201AC2 MOV.L   @($00201AC2,ER6),ER6
742            // mov.l @(displ24 + Rs), rd
743            srcreg = (ext16 >> 4) & 7;
744
745            // 6b20
746            udata16 = h8_mem_read16(h8.pc);
747            h8.pc += 2;
748            dstreg = udata16 & 7;
749
750            address24 = h8_mem_read32(h8.pc);
751            h8.pc += 4;
752            address24 += h8_getreg32(srcreg);
753            address24 &= 0xffffff;
754
755            if ( (ext16 & 0x80) && ((udata16 & ~7) == 0x6ba0) )
756            {
757               udata32 = h8_getreg32(dstreg);
758               h8_mem_write32(address24, udata32);
759            }
760            else if ( (!(ext16 & 0x80)) && ((udata16 & ~7) == 0x6b20) )
761            {
762               udata32 = h8_mem_read32(address24);
763               h8_setreg32(dstreg, udata32);
764            }
765            else
766            {
767               h8.h8err = 1;
768            }
769
770            h8_mov32(udata32);
771
772            H8_IFETCH_TIMING(5);
773            H8_WORD_TIMING(2, address24);
774
775            break;
776         default:
777            h8.h8err = 1;
778            break;
779         }
780         break;
781      case 0xc:
782         // mulxs
783         ext16 = h8_mem_read16(h8.pc);
784         h8.pc+=2;
785         if(((ext16>>8) & 0xf) == 0)
786         {
787            h8.h8err = 1;
788         }
789         else if(((ext16>>8) & 0xf) == 2)
790         {
791            sdata32 = h8_getreg32(ext16 & 0x7);
792            sdata16 = h8_getreg16((ext16>>4) & 0xf);
793            sdata32 = h8_mulxs16(sdata16, sdata32);
794            h8_setreg32(ext16 & 0x7, sdata32);
795            H8_IFETCH_TIMING(2);
796            H8_IOP_TIMING(20);
797         }
798         else
799         {
800            logerror("H8/3002: Unk. group 0 mulxs %x\n", opcode);
801            h8.h8err = 1;
802         }
803         break;
804
805      case 0xd:
806         //divxs - probbaly buggy (flags?)
807         ext16 = h8_mem_read16(h8.pc);
808         h8.pc+=2;
809         if(((ext16>>8) & 0xf) == 0)
810         {
811            h8.h8err = 1;
812         }
813         else if(((ext16>>8) & 0xf) == 3)
814         {
815            sdata32 = h8_getreg32(ext16 & 0x7);
816            sdata16 = h8_getreg16((ext16>>4) & 0xf);
817            sdata32 = h8_divxs16(sdata16, sdata32);
818            h8_setreg32(ext16 & 0x7, sdata32);
819            H8_IFETCH_TIMING(2);
820            H8_IOP_TIMING(20);
821         }
822         else
823         {
824            h8.h8err = 1;
825         }
826
827
828      break;
829
830      default:
831         h8.h8err = 1;
832         break;
833      }
834      break;
835   case 0x2:
836      // stc ccr, rd
837      if(((opcode>>4) & 0xf) == 0)
838      {
839         h8_setreg8(opcode & 0xf, h8_get_ccr());
840         H8_IFETCH_TIMING(1);
841      }
842      else
843      {
844         logerror("H8/3002: Unk. group 0 2 %x\n", opcode);
845         h8.h8err = 1;
846      }
847      break;
848   case 0x3:
849      // ldc rd, ccr
850      if(((opcode>>4) & 0xf) == 0)
851      {
852         udata8 = h8_getreg8(opcode & 0xf);
853         h8_set_ccr(udata8);
854         H8_IFETCH_TIMING(1);
855      }
856      else
857      {
858         logerror("H8/3002: Unk. group 0 3 %x\n", opcode);
859         h8.h8err = 1;
860      }
861      break;
862   case 0x4: // pass
863      // orc
864      udata8 = h8_or8(opcode & 0xff, h8_get_ccr());
865      h8_set_ccr(udata8);
866      H8_IFETCH_TIMING(1);
867      break;
868   case 0x6:
869      // andc
870      udata8 = h8_and8(opcode & 0xff, h8_get_ccr());
871      h8_set_ccr(udata8);
872      H8_IFETCH_TIMING(1)
873      break;
874      // ldc
875   case 0x8:
876      // add.b rx, ry
877      dstreg = opcode & 0xf;
878      udata8 = h8_add8(h8_getreg8((opcode>>4) &0xf), h8_getreg8(dstreg));
879      h8_setreg8(dstreg, udata8);
880      H8_IFETCH_TIMING(1)
881      break;
882      // add.w rx, ry
883   case 0x9:
884      dstreg = opcode & 0xf;
885      udata16 = h8_add16(h8_getreg16((opcode>>4) &0xf), h8_getreg16(dstreg));
886      h8_setreg16(dstreg, udata16);
887      H8_IFETCH_TIMING(1)
888      break;
889      // inc.b rx
890   case 0xA:
891      if(opcode&0x80)
892      {
893         if(opcode & 0x8)
894         {
895            logerror("H8/3002: Unk. group 0 a %x\n", opcode);
896            h8.h8err = 1;
897         }
898         else
899         {
900            dstreg = opcode & 0x7;
901            udata32 = h8_add32(h8_getreg32((opcode>>4) &0x7), h8_getreg32(dstreg));
902            h8_setreg32(dstreg, udata32);
903            H8_IFETCH_TIMING(1)
904         }
905      }
906      else
907      {
908         if(opcode & 0xf0)
909         {
910         logerror("H8/3002: Unk. group 0 a2 %x\n", opcode);
911            h8.h8err =1;
912         }
913         else
914         {
915            dstreg = opcode & 0xf;
916            udata8 = h8_inc8(h8_getreg8(dstreg));
917            h8_setreg8(dstreg, udata8);
918            H8_IFETCH_TIMING(1);
919         }
920      }
921      break;
922   case 0xb:
923      switch((opcode>>4)& 0xf)
924      {
925      case 0:
926         if(opcode & 8)
927         {
928            h8.h8err = 1;
929         }
930         else
931         {
932            dstreg = opcode & 7;
933            udata32 = h8_getreg32(dstreg) + 1;
934            h8_setreg32(dstreg, udata32);
935            H8_IFETCH_TIMING(1)
936         }
937         break;
938      case 5:
939         dstreg = opcode & 0xf;
940         udata16 = h8_inc16(h8_getreg16(dstreg));
941         h8_setreg16(dstreg, udata16);
942         H8_IFETCH_TIMING(1);
943         break;
944      case 7:
945         dstreg = opcode & 0x7;
946         udata32 = h8_inc32(h8_getreg32(dstreg));
947         h8_setreg32(dstreg, udata32);
948         H8_IFETCH_TIMING(1);
949         break;
950      case 8:
951         if(opcode & 8)
952         {
953            h8.h8err = 1;
954         }
955         else
956         {
957            dstreg = opcode & 7;
958            udata32 = h8_getreg32(dstreg) + 2;
959            h8_setreg32(dstreg, udata32);
960            H8_IFETCH_TIMING(1)
961         }
962         break;
963      case 9:
964         if(opcode & 8)
965         {
966            h8.h8err = 1;
967         }
968         else
969         {
970            dstreg = opcode & 7;
971            udata32 = h8_getreg32(dstreg) + 4;
972            h8_setreg32(dstreg, udata32);
973            H8_IFETCH_TIMING(1)
974         }
975         break;
976      case 0xd:
977         dstreg = opcode & 0xf;
978         udata16 = h8_inc16(h8_getreg16(dstreg));
979         if(h8.h8vflag)
980         {
981            udata16 = h8_inc16(udata16); // slow and easy
982            h8.h8vflag = 1;
983         }
984         else
985            udata16 = h8_inc16(udata16); // slow and easy
986         h8_setreg16(dstreg, udata16);
987         H8_IFETCH_TIMING(1);
988         break;
989      case 0xf:
990         dstreg = opcode & 0x7;
991         udata32 = h8_inc32(h8_getreg32(dstreg));
992         if(h8.h8vflag)
993         {
994            udata32 = h8_inc32(udata32); // slow and easy
995            h8.h8vflag = 1;
996         }
997         else
998            udata32 = h8_inc32(udata32); // slow and easy
999         h8_setreg32(dstreg, udata32);
1000         H8_IFETCH_TIMING(1);
1001         break;
1002      default:
1003         logerror("H8/3002: Unk. group 0 b %x\n", opcode);
1004         h8.h8err = 1;
1005         break;
1006      }
1007      break;
1008      // mov.b rx, ry
1009   case 0xc: // pass
1010      dstreg = opcode & 0xf;
1011      udata8 = h8_mov8(h8_getreg8((opcode>>4) &0xf));
1012      h8_setreg8(dstreg, udata8);
1013      H8_IFETCH_TIMING(1);
1014      break;
1015   case 0xd:
1016      // mov.w rx, ry
1017      dstreg = opcode & 0xf;
1018      udata16 = h8_mov16(h8_getreg16((opcode>>4) &0xf));
1019      h8_setreg16(dstreg, udata16);
1020      H8_IFETCH_TIMING(1);
1021      break;
1022   case 0xf:
1023      if(opcode & 0x80)
1024      {
1025         if(opcode & 8)
1026         {
1027         logerror("H8/3002: Unk. group 0 f %x\n", opcode);
1028            h8.h8err = 1;
1029         }
1030         else
1031         {
1032            dstreg = opcode & 0x7;
1033            udata32 = h8_mov32(h8_getreg32((opcode>>4) &0x7));
1034            h8_setreg32(dstreg, udata32);
1035            H8_IFETCH_TIMING(1);
1036         }
1037      }
1038      else
1039      {
1040         h8.h8err = 1;
1041         logerror("H8/3002: Unk. group 0 f2 %x\n", opcode);
1042         if((opcode & 0xf0) !=0)
1043         {
1044            h8.h8err = 1;
1045         }
1046         else
1047         {
1048            h8.h8err = 1;
1049         }
1050      }
1051      break;
1052   default:
1053      logerror("H8/3002: Unk. group 0 tdef %x\n", opcode);
1054      h8.h8err = 1;
1055      break;
1056   }
1057}
1058
1059static void h8_group1(UINT16 opcode)
1060{
1061   switch((opcode>>8)&0xf)
1062   {
1063   case 0x0:
1064      switch((opcode>>4)&0xf)
1065      {
1066      case 0x0:
1067         // shll.b Rx
1068         udata8 = h8_getreg8(opcode & 0xf);
1069         udata8 = h8_shll8(udata8);
1070         h8_setreg8(opcode & 0xf, udata8);
1071         H8_IFETCH_TIMING(1);
1072         break;
1073      case 0x1:
1074         // shll.w Rx
1075         udata16 = h8_getreg16(opcode & 0xf);
1076         udata16 = h8_shll16(udata16);
1077         h8_setreg16(opcode & 0xf, udata16);
1078         H8_IFETCH_TIMING(1);
1079         break;
1080      case 0x3:
1081         // shal.l Rx
1082         udata32 = h8_getreg32(opcode & 0x7);
1083         udata32 = h8_shll32(udata32);
1084         h8_setreg32(opcode & 0x7, udata32);
1085         H8_IFETCH_TIMING(1);
1086         break;
1087
1088      case 0x8:
1089         // shal.b Rx
1090         udata8 = h8_getreg8(opcode & 0xf);
1091         udata8 = h8_shal8(udata8);
1092         h8_setreg8(opcode & 0xf, udata8);
1093         H8_IFETCH_TIMING(1);
1094         break;
1095      case 0x9:
1096         // shal.w Rx
1097         udata16 = h8_getreg16(opcode & 0xf);
1098         udata16 = h8_shal16(udata16);
1099         h8_setreg16(opcode & 0xf, udata16);
1100         H8_IFETCH_TIMING(1);
1101         break;
1102      case 0xb:
1103         // shal.l ERx
1104         udata32 = h8_getreg32(opcode & 0x7);
1105         udata32 = h8_shal32(udata32);
1106         h8_setreg32(opcode & 0x7, udata32);
1107         H8_IFETCH_TIMING(1);
1108         break;
1109
1110      default:
1111         logerror("H8/3002: Unk. group 1 0 %x\n", opcode);
1112         h8.h8err = 1;
1113         break;
1114      }
1115      break;
1116   case 0x1:
1117      switch((opcode>>4)&0xf)
1118      {
1119      case 0x0:
1120         // shlr.b rx
1121         udata8 = h8_getreg8(opcode & 0xf);
1122         udata8 = h8_shlr8(udata8);
1123         h8_setreg8(opcode & 0xf, udata8);
1124         H8_IFETCH_TIMING(1);
1125         break;
1126      case 0x1:
1127         // shlr.w rx
1128         udata16 = h8_getreg16(opcode & 0xf);
1129         udata16 = h8_shlr16(udata16);
1130         h8_setreg16(opcode & 0xf, udata16);
1131         H8_IFETCH_TIMING(1);
1132         break;
1133         // shlr.l rx
1134      case 0x3:
1135         udata32 = h8_getreg32(opcode & 0x7);
1136         udata32 = h8_shlr32(udata32);
1137         h8_setreg32(opcode & 0x7, udata32);
1138         H8_IFETCH_TIMING(1);
1139         break;
1140      case 0x8:
1141         // shar.b rx
1142         udata8 = h8_getreg8(opcode & 0xf);
1143         udata8 = h8_shar8(udata8);
1144         h8_setreg8(opcode & 0xf, udata8);
1145         H8_IFETCH_TIMING(1);
1146         break;
1147      case 0x9:
1148         // shar.w rx
1149         udata16 = h8_getreg16(opcode & 0xf);
1150         udata16 = h8_shar16(udata16);
1151         h8_setreg16(opcode & 0xf, udata16);
1152         H8_IFETCH_TIMING(1);
1153         break;
1154      case 0xb:
1155         // shar.l rx
1156         udata32 = h8_getreg32(opcode & 0x7);
1157         udata32 = h8_shar32(udata32);
1158         h8_setreg32(opcode & 0x7, udata32);
1159         H8_IFETCH_TIMING(1);
1160         break;
1161      default:
1162         logerror("H8/3002: Unk. group 1 1 %x\n", opcode);
1163         h8.h8err = 1;
1164         break;
1165      }
1166      break;
1167   case 0x2:
1168      switch((opcode>>4)&0xf)
1169      {
1170      case 0x0:
1171         // rotxl.b Rx
1172         udata8 = h8_getreg8(opcode & 0xf);
1173         udata8 = h8_rotxl8(udata8);
1174         h8_setreg8(opcode & 0xf, udata8);
1175         H8_IFETCH_TIMING(1);
1176         break;
1177      case 0x1:
1178         // rotxl.w Rx
1179         udata16 = h8_getreg16(opcode & 0xf);
1180         udata16 = h8_rotxl16(udata16);
1181         h8_setreg16(opcode & 0xf, udata16);
1182         H8_IFETCH_TIMING(1);
1183         break;
1184
1185      case 0x3:
1186         // rotxl.l Rx
1187         udata32 = h8_getreg32(opcode & 0x7);
1188         udata32 = h8_rotxl32(udata32);
1189         h8_setreg32(opcode & 0xf, udata32);
1190         H8_IFETCH_TIMING(1);
1191         break;
1192
1193      case 0x8:
1194         // rotl.b Rx
1195         udata8 = h8_getreg8(opcode & 0xf);
1196         udata8 = h8_rotl8(udata8);
1197         h8_setreg8(opcode & 0xf, udata8);
1198         H8_IFETCH_TIMING(1);
1199         break;
1200      case 0x9:
1201         // rotl.w Rx
1202         udata16 = h8_getreg16(opcode & 0xf);
1203         udata16 = h8_rotl16(udata16);
1204         h8_setreg16(opcode & 0xf, udata16);
1205         H8_IFETCH_TIMING(1);
1206         break;
1207      case 0xb:
1208         // rotl.l ERx
1209         udata32 = h8_getreg32(opcode & 0x7);
1210         udata32 = h8_rotl32(udata32);
1211         h8_setreg32(opcode & 0x7, udata32);
1212         H8_IFETCH_TIMING(1);
1213         break;
1214
1215      default:
1216         logerror("H8/3002: Unk. group 1 2 %x\n", opcode);
1217         h8.h8err = 1;
1218         break;
1219      }
1220      break;
1221   case 0x3:
1222      switch((opcode>>4)&0xf)
1223      {
1224      case 0x0:
1225         // rotxr.b Rx
1226         udata8 = h8_getreg8(opcode & 0xf);
1227         udata8 = h8_rotxr8(udata8);
1228         h8_setreg8(opcode & 0xf, udata8);
1229         H8_IFETCH_TIMING(1);
1230         break;
1231      case 0x1:
1232         // rotxr.w Rx
1233         udata16 = h8_getreg16(opcode & 0xf);
1234         udata16 = h8_rotxr16(udata16);
1235         h8_setreg16(opcode & 0xf, udata16);
1236         H8_IFETCH_TIMING(1);
1237         break;
1238      default:
1239         logerror("H8/3002: Unk. group 1 3 %x\n", opcode);
1240         h8.h8err = 1;
1241         break;
1242      }
1243      break;
1244   case 0x4:
1245      // or.b rs, rd
1246      dstreg = opcode & 0xf;
1247      udata8 = h8_or8(h8_getreg8((opcode>>4) &0xf), h8_getreg8(dstreg));
1248      h8_setreg8(dstreg, udata8);
1249      H8_IFETCH_TIMING(1);
1250      break;
1251   case 0x5:
1252      // xor.b rs, rd
1253      dstreg = opcode & 0xf;
1254      udata8 = h8_xor8(h8_getreg8((opcode>>4) &0xf), h8_getreg8(dstreg));
1255      h8_setreg8(dstreg, udata8);
1256      H8_IFETCH_TIMING(1);
1257      break;
1258   case 0x6:
1259      // and.b rs, rd
1260      dstreg = opcode & 0xf;
1261      udata8 = h8_and8(h8_getreg8((opcode>>4) &0xf), h8_getreg8(dstreg));
1262      h8_setreg8(dstreg, udata8);
1263      H8_IFETCH_TIMING(1)
1264      break;
1265      // not
1266   case 0x7:
1267      switch((opcode>>4)&0xf)
1268      {
1269      case 0x0:
1270         // not.b Rx
1271         dstreg = opcode & 0xf;
1272         udata8 = h8_not8(h8_getreg8(dstreg));
1273         h8_setreg8(dstreg, udata8);
1274         H8_IFETCH_TIMING(1);
1275         break;
1276      case 0x1:
1277         // not.w Rx
1278         dstreg = opcode & 0xf;
1279         udata16 = h8_not16(h8_getreg16(dstreg));
1280         h8_setreg16(dstreg, udata16);
1281         H8_IFETCH_TIMING(1);
1282         break;
1283      case 0x3:
1284         // not.l ERx
1285         dstreg = opcode & 0x7;
1286         udata32 = h8_not32(h8_getreg32(dstreg));
1287         h8_setreg32(dstreg, udata32);
1288         H8_IFETCH_TIMING(1);
1289         break;
1290
1291      case 0x5:
1292         // extu.w Rx
1293         dstreg = opcode & 0xf;
1294         udata16 = h8_getreg16(dstreg) & 0x00ff;
1295         h8_setreg16(dstreg, udata16);
1296         h8.h8nflag = 0;
1297         h8.h8vflag = 0;
1298         h8.h8zflag = ((udata16 == 0) ? 1 : 0);
1299         H8_IFETCH_TIMING(1);
1300         break;
1301      case 0x7:
1302         // extu.l Rx
1303         dstreg = opcode & 0x7;
1304         udata32 = h8_getreg32(dstreg) & 0x0000ffff;
1305         h8_setreg32(dstreg, udata32);
1306         h8.h8nflag = 0;
1307         h8.h8vflag = 0;
1308         h8.h8zflag = ((udata32 == 0) ? 1 : 0);
1309         H8_IFETCH_TIMING(1);
1310         break;
1311      case 0x8:
1312         // neg.b Rx
1313         dstreg = opcode & 0xf;
1314         sdata8 = h8_neg8(h8_getreg8(dstreg));
1315         h8_setreg8(dstreg, sdata8);
1316         H8_IFETCH_TIMING(1);
1317         break;
1318      case 0x9:
1319         // neg.w Rx
1320         dstreg = opcode & 0xf;
1321         sdata16 = h8_neg16(h8_getreg16(dstreg));
1322         h8_setreg16(dstreg, sdata16);
1323         H8_IFETCH_TIMING(1);
1324         break;
1325      case 0xb:
1326         // neg.l ERx
1327         dstreg = opcode & 0x7;
1328         sdata32 = h8_neg32(h8_getreg32(dstreg));
1329         h8_setreg32(dstreg, sdata32);
1330         H8_IFETCH_TIMING(1);
1331         break;
1332      case 0xd:
1333         // exts.w Rx
1334         dstreg = opcode & 0xf;
1335         udata16=h8_getreg16(dstreg)&0xff;
1336         if(udata16&0x80)
1337         {
1338            udata16|=0xff00;
1339         }
1340         h8_setreg16(dstreg, udata16);
1341
1342         h8.h8vflag = 0;
1343         h8.h8nflag = (udata16 & 0xff00) ? 1 : 0;
1344         h8.h8zflag = (udata16) ? 0 : 1;
1345
1346         H8_IFETCH_TIMING(1);
1347         break;
1348
1349      case 0xf:
1350         // exts.l Rx
1351         dstreg = opcode & 0x7;
1352         udata32=h8_getreg32(dstreg)&0xffff;
1353         if(udata32&0x8000)
1354         {
1355            udata32|=0xffff0000;
1356         }
1357         h8_setreg32(dstreg, udata32);
1358
1359         h8.h8vflag = 0;
1360         h8.h8nflag = (udata32 & 0xffff0000) ? 1 : 0;
1361         h8.h8zflag = (udata32) ? 0 : 1;
1362
1363         H8_IFETCH_TIMING(1);
1364         break;
1365
1366      default:
1367         logerror("H8/3002: Unk. group 1 7-9 %x\n", opcode);
1368         h8.h8err = 1;
1369         break;
1370      }
1371      break;
1372   case 0x8:
1373      // sub.b rs, rd
1374      dstreg = opcode & 0xf;
1375      udata8 = h8_sub8(h8_getreg8((opcode>>4) &0xf), h8_getreg8(dstreg));
1376      h8_setreg8(dstreg, udata8);
1377      H8_IFETCH_TIMING(1);
1378      break;
1379   case 0x9:
1380      // sub.w rs, rd
1381      dstreg = opcode & 0xf;
1382      udata16 = h8_sub16(h8_getreg16((opcode>>4) &0xf), h8_getreg16(dstreg));
1383      h8_setreg16(dstreg, udata16);
1384      H8_IFETCH_TIMING(1);
1385      break;
1386      // sub.b rx
1387   case 0xA:
1388      if(opcode&0x80)
1389      {
1390         //logerror("H8/3002: Unk. group 1 A %x\n", opcode);
1391
1392         // sub.l rs,rd
1393         dstreg = opcode & 0x7;
1394         udata32=h8_sub32(h8_getreg32((opcode>>4) &0x7), h8_getreg32(dstreg));
1395         h8_setreg32(dstreg, udata32);
1396         H8_IFETCH_TIMING(2);
1397         break;
1398
1399      }
1400      else
1401      {
1402         if(opcode & 0xf0)
1403         {
1404            logerror("H8/3002: Unk. group A2 0 %x\n", opcode);
1405            h8.h8err = 1;
1406         }
1407         else
1408         {
1409            udata8 = h8_getreg8(opcode & 0xf);
1410            udata8 = h8_dec8(udata8);
1411            h8_setreg8(opcode & 0xf, udata8);
1412            H8_IFETCH_TIMING(1);
1413         }
1414      }
1415      break;
1416      //
1417   case 0xb:
1418      switch((opcode>>4)& 0xf)
1419      {
1420      case 0:   // subs.l #1, rN (decrement without touching flags)
1421         dstreg = opcode & 0x7;
1422         udata32 = h8_getreg32(dstreg);
1423         udata32--;
1424         h8_setreg32(dstreg, udata32);
1425         H8_IFETCH_TIMING(1);
1426         break;
1427      case 5:   // dec.w #1, rN
1428         dstreg = opcode & 0xf;
1429         udata16 = h8_dec16(h8_getreg16(dstreg));
1430         h8_setreg16(dstreg, udata16);
1431         H8_IFETCH_TIMING(1);
1432         break;
1433      case 7:   // dec.l #1, rN
1434         dstreg = opcode & 0x7;
1435         udata32 = h8_dec32(h8_getreg32(dstreg));
1436         h8_setreg32(dstreg, udata32);
1437         H8_IFETCH_TIMING(1);
1438         break;
1439      case 8:   // subs.l #2, rN (decrement without touching flags)
1440         dstreg = opcode & 0x7;
1441         udata32 = h8_getreg32(dstreg);
1442         udata32-=2;
1443         h8_setreg32(dstreg, udata32);
1444         H8_IFETCH_TIMING(1);
1445         break;
1446      case 9:   // subs.l #4, rN (decrement without touching flags)
1447         dstreg = opcode & 0x7;
1448         udata32 = h8_getreg32(dstreg);
1449         udata32-=4;
1450         h8_setreg32(dstreg, udata32);
1451         H8_IFETCH_TIMING(1);
1452         break;
1453      case 0xd:   // dec.w #2, rN
1454         dstreg = opcode & 0xf;
1455         udata16 = h8_dec16(h8_getreg16(dstreg));
1456         if (h8.h8vflag)
1457         {
1458            udata16 = h8_dec16(udata16);
1459            h8.h8vflag = 1;
1460         }
1461         else
1462            udata16 = h8_dec16(udata16);
1463         h8_setreg16(dstreg, udata16);
1464         H8_IFETCH_TIMING(1);
1465         break;
1466      case 0xf:   // dec.l #2, rN
1467         dstreg = opcode & 0x7;
1468         udata32 = h8_dec32(h8_getreg32(dstreg));
1469         if (h8.h8vflag)
1470         {
1471            udata32 = h8_dec32(udata32);
1472            h8.h8vflag = 1;
1473         }
1474         else
1475            udata32 = h8_dec32(udata32);
1476         h8_setreg32(dstreg, udata32);
1477         H8_IFETCH_TIMING(1);
1478         break;
1479
1480      default:
1481         logerror("H8/3002: Unk. group 1 B %x\n", opcode);
1482         h8.h8err = 1;
1483         break;
1484      }
1485      break;
1486   case 0xc:
1487      // cmp.b rs, rd
1488      h8_cmp8(h8_getreg8((opcode>>4) &0xf), h8_getreg8(opcode & 0xf));
1489      H8_IFETCH_TIMING(1);
1490      break;
1491   case 0xd:
1492      // cmp.w rx, ry
1493      h8_cmp16(h8_getreg16((opcode>>4) &0xf), h8_getreg16(opcode & 0xf));
1494      H8_IFETCH_TIMING(1);
1495      break;
1496   case 0xe:
1497      // subx.b rx, ry
1498      dstreg = opcode & 0xf;
1499      udata8 = h8_subx8(h8_getreg8((opcode>>4) &0xf), h8_getreg8(dstreg));
1500      h8_setreg8(dstreg, udata8);
1501      H8_IFETCH_TIMING(1);
1502      break;
1503   case 0xf:
1504      if(opcode & 0x80)
1505      {
1506         if(opcode & 8)
1507         {
1508            logerror("H8/3002: Unk. group 1 f %x\n", opcode);
1509            h8.h8err = 1;
1510         }
1511         else
1512         {
1513            h8_cmp32(h8_getreg32((opcode>>4) & 0x7), h8_getreg32(opcode & 0x7));
1514            H8_IFETCH_TIMING(1);
1515         }
1516      }
1517      else
1518      {
1519         logerror("H8/3002: Unk. group 1 f2 %x\n", opcode);
1520         h8.h8err = 1;
1521      }
1522      break;
1523   default:
1524      logerror("H8/3002: Unk. group 1 def %x\n", opcode);
1525      h8.h8err = 1;
1526      break;
1527   }
1528}
1529
1530
1531static void h8_group5(UINT16 opcode)
1532{
1533   switch((opcode>>8)&0xf)
1534   {
1535   case 0x0:
1536      // mulxu.b
1537      udata8 = h8_getreg8((opcode>>4)&0xf);
1538      udata16 = h8_getreg16(opcode & 0xf);
1539      udata16 &= 0xff;
1540      udata16 = udata16*udata8;
1541      // no flags modified!
1542      h8_setreg16(opcode & 0xf, udata16);
1543      H8_IFETCH_TIMING(1);
1544      H8_IOP_TIMING(12);
1545      break;
1546   case 0x1:
1547      // divxu.b
1548      udata8 = h8_getreg8((opcode>>4)&0xf);
1549      udata16 = h8_getreg16(opcode & 0x0f);
1550      udata16 = h8_divxu8(udata16,udata8);
1551      h8_setreg16(opcode & 0xf, udata16);
1552      H8_IFETCH_TIMING(1);
1553      H8_IOP_TIMING(12);
1554      break;
1555   case 0x2:
1556      // mulxu.w
1557      udata16 = h8_getreg16((opcode>>4)&0xf);
1558      udata32 = h8_getreg32(opcode & 7);
1559      udata32 &= 0xffff;
1560      udata32 = udata32*udata16;
1561      // no flags modified!
1562      h8_setreg32(opcode & 7, udata32);
1563      H8_IFETCH_TIMING(1);
1564      H8_IOP_TIMING(20);
1565      break;
1566   case 0x3:
1567      // divxu.w
1568      udata16 = h8_getreg16((opcode>>4)&0xf);
1569      udata32 = h8_getreg32(opcode & 7);
1570      udata32 = h8_divxu16(udata32,udata16);
1571      h8_setreg32(opcode & 7, udata32);
1572      H8_IFETCH_TIMING(1);
1573      H8_IOP_TIMING(20);
1574      break;
1575   case 0x4:
1576      if(opcode == 0x5470)
1577      {
1578         // rts
1579         udata32 = h8_mem_read32(h8_getreg32(H8_SP));
1580         h8_setreg32(H8_SP, h8_getreg32(H8_SP)+4);
1581         // extended mode
1582         h8.pc = udata32;
1583         change_pc(h8.pc);
1584         H8_IFETCH_TIMING(2);
1585         H8_STACK_TIMING(2);
1586         H8_IOP_TIMING(2);
1587      }
1588      else
1589      {
1590         logerror("H8/3002: Unk. group 5 1 %x\n", opcode);
1591         h8.h8err = 1;
1592      }
1593      break;
1594   case 0x5:
1595      // bsr 8
1596      sdata8 = opcode & 0xff;
1597      // extended mode stack push!
1598      h8_setreg32(H8_SP, h8_getreg32(H8_SP)-4);
1599      h8_mem_write32(h8_getreg32(H8_SP), h8.pc);
1600      h8.pc = h8.pc + sdata8;
1601      change_pc(h8.pc);
1602      H8_IFETCH_TIMING(2); H8_STACK_TIMING(2);
1603      break;
1604   case 0x6:
1605      // rte
1606      if(opcode == 0x5670)
1607      {
1608         // restore CCR
1609         udata16 = h8_mem_read16(h8_getreg32(H8_SP));
1610         h8_setreg32(H8_SP, h8_getreg32(H8_SP)+2);
1611         // extended mode restore PC
1612         udata32 = h8_mem_read32(h8_getreg32(H8_SP));
1613         h8_setreg32(H8_SP, h8_getreg32(H8_SP)+4);
1614         // extended mode
1615         h8.pc = udata32;
1616         change_pc(h8.pc);
1617         // must do this last, because set_ccr() does a check_irq()
1618         h8_set_ccr((UINT8)udata16);
1619         H8_IFETCH_TIMING(2);
1620         H8_STACK_TIMING(2);
1621         H8_IOP_TIMING(2);
1622      }
1623      else
1624      {
1625         logerror("H8/3002: Unk. group 5 6 %x\n", opcode);
1626         h8.h8err = 1;
1627      }
1628      break;
1629      // trapa
1630   case 0x7:
1631      logerror("H8/3002: Unk. group 5 7 %x\n", opcode);
1632      h8.h8err = 1;
1633      break;
1634   case 0x8:
1635      // bcc @xx:16
1636      if(opcode & 0xf)
1637      {
1638         logerror("H8/3002: Unk. group 5 8 %x\n", opcode);
1639         h8.h8err = 1;
1640      }
1641      else
1642      {
1643         sdata16 = h8_mem_read16(h8.pc);
1644         h8.pc += 2;
1645         if( h8_branch((opcode >> 4) & 0xf) == 1)h8.pc += sdata16;
1646         change_pc(h8.pc);
1647         H8_IOP_TIMING(2)
1648      }
1649      break;
1650   case 0x9:
1651      // jmp @erd
1652      address24 = h8_getreg32((opcode>>4)&7);
1653      address24 &= 0xffffff;
1654      h8.pc = address24;
1655      change_pc(h8.pc);
1656      H8_IFETCH_TIMING(2);
1657      break;
1658      // jmp @aa:24
1659   case 0xa:
1660      address24=h8_mem_read32(h8.pc-2);
1661      address24 &= 0xffffff;
1662      h8.pc = address24;
1663      change_pc(h8.pc);
1664      H8_IFETCH_TIMING(2);
1665      H8_IOP_TIMING(2);
1666      break;
1667      // jmp @aa:8
1668   case 0xc:
1669      if(opcode & 0xff)
1670      {
1671         logerror("H8/3002: Unk. group 5 c %x\n", opcode);
1672         h8.h8err = 1;
1673      }
1674      else
1675      {
1676         // bsr d:16
1677         sdata16=h8_mem_read16(h8.pc);
1678         h8_setreg32(H8_SP, h8_getreg32(H8_SP)-4);
1679         h8_mem_write32(h8_getreg32(H8_SP), h8.pc+2);
1680         h8.pc += sdata16 + 2;
1681         change_pc(h8.pc);
1682         H8_IFETCH_TIMING(2); H8_STACK_TIMING(2); H8_IOP_TIMING(2);
1683      }
1684      break;
1685   case 0xd:
1686      // jsr @reg
1687      address24=h8_getreg32((opcode>>4)&7);
1688      address24 &= 0xffffff;
1689      // extended mode stack push!
1690      h8_setreg32(H8_SP, h8_getreg32(H8_SP)-4);
1691      h8_mem_write32(h8_getreg32(H8_SP), h8.pc);
1692      h8.pc = address24;
1693      change_pc(h8.pc);
1694      H8_STACK_TIMING(2);
1695      H8_IOP_TIMING(2);
1696      break;
1697   case 0xe:
1698      // jsr @aa:24
1699      address24=h8_mem_read32(h8.pc-2);
1700      address24 &= 0xffffff;
1701      // extended mode stack push!
1702      h8_setreg32(H8_SP, h8_getreg32(H8_SP)-4);
1703      h8_mem_write32(h8_getreg32(H8_SP), h8.pc+2);
1704      h8.pc = address24;
1705      change_pc(h8.pc);
1706      H8_IFETCH_TIMING(2);
1707      H8_STACK_TIMING(2);
1708      H8_IOP_TIMING(2);
1709      break;
1710      // jsr @aa:8
1711   default:
1712      logerror("H8/3002: Unk. group 5 def %x\n", opcode);
1713      h8.h8err = 1;
1714      break;
1715   }
1716}
1717
1718static void h8_group6(UINT16 opcode)
1719{
1720   switch((opcode>>8)&0xf)
1721   {
1722   case 0:case 1:case 2:case 3:
1723      {
1724         UINT8 bitnr;
1725
1726         dstreg = opcode & 0xf;
1727         udata8 = h8_getreg8(dstreg);
1728         bitnr = h8_getreg8((opcode>>4)& 0xf)&7;
1729
1730         switch((opcode>>8)&0xf)
1731         {
1732         case 0:   udata8 = h8_bset8(bitnr, udata8); h8_setreg8(dstreg, udata8); H8_IFETCH_TIMING(1); break;
1733         case 2:   udata8 = h8_bclr8(bitnr, udata8); h8_setreg8(dstreg, udata8); H8_IFETCH_TIMING(1); break;
1734         case 3:   h8_btst8(bitnr, udata8); H8_IFETCH_TIMING(1); break;
1735         default:
1736            logerror("H8/3002: Unk. group 6 def 0-3-0 %x\n", opcode);
1737            h8.h8err = 1;
1738            break;
1739         }
1740      }
1741      break;
1742   case 0x4:
1743      // or.w rs, rd
1744      dstreg = opcode & 0xf;
1745      udata16 = h8_getreg16(dstreg);
1746      udata16 = h8_or16(h8_getreg16((opcode>>4) & 0xf), udata16);
1747      h8_setreg16(dstreg, udata16);
1748      H8_IFETCH_TIMING(1);
1749      break;
1750   case 0x5:
1751      // xor.w rs, rd
1752      dstreg = opcode & 0xf;
1753      udata16 = h8_getreg16(dstreg);
1754      udata16 = h8_xor16(h8_getreg16((opcode>>4) & 0xf), udata16);
1755      h8_setreg16(dstreg, udata16);
1756      H8_IFETCH_TIMING(1);
1757      break;
1758   case 0x6:
1759      // and.w rs, rd
1760      dstreg = opcode & 0xf;
1761      udata16 = h8_getreg16(dstreg);
1762      udata16 = h8_and16(h8_getreg16((opcode>>4) & 0xf), udata16);
1763      h8_setreg16(dstreg, udata16);
1764      H8_IFETCH_TIMING(1)
1765      break;
1766   case 0x7:
1767      // bst/bist #imm, rd
1768      if(opcode & 0x80)
1769      {
1770         udata8 = h8_getreg8(opcode & 0xf);
1771         udata8 = h8_bist8((opcode>>4) & 7, udata8);
1772         h8_setreg8(opcode & 0xf, udata8);
1773         H8_IFETCH_TIMING(1);
1774      }
1775      else
1776      {
1777         udata8 = h8_getreg8(opcode & 0xf);
1778         udata8 = h8_bst8((opcode>>4) & 7, udata8);
1779         h8_setreg8(opcode & 0xf, udata8);
1780         H8_IFETCH_TIMING(1);
1781      }
1782      break;
1783   case 0x8:
1784      if(opcode & 0x80)
1785      {
1786         // mov.b rx, @rx
1787         udata8 = h8_getreg8(opcode & 0xf);
1788         address24 = h8_getreg32((opcode>>4)&7) & 0xffffff;
1789         h8_mov8(udata8);
1790         h8_mem_write8(address24, udata8);
1791         H8_IFETCH_TIMING(1);
1792         H8_BYTE_TIMING(1, address24);
1793      }
1794      else
1795      {
1796         // mov.b @rx, rx
1797         address24 = h8_getreg32((opcode>>4)&7) & 0xffffff;
1798         udata8 = h8_mem_read8(address24);
1799         h8_mov8(udata8);
1800         h8_setreg8(opcode & 0xf, udata8);
1801         H8_IFETCH_TIMING(1);
1802         H8_BYTE_TIMING(1, address24);
1803      }
1804      break;
1805   case 0x9:
1806      if(opcode & 0x80)
1807      {
1808         // mov.w rx, @rx
1809         address24 = h8_getreg32((opcode>>4)&7) & 0xffffff;
1810         udata16 = h8_getreg16(opcode & 0xf);
1811         h8_mov16(udata16);
1812         h8_mem_write16(address24, udata16);
1813         H8_IFETCH_TIMING(1);
1814         H8_WORD_TIMING(1, address24);
1815      }
1816      else
1817      {
1818         // mov.w @rx, rx
1819         address24 = h8_getreg32((opcode>>4)&7) & 0xffffff;
1820         udata16 = h8_mem_read16(address24);
1821         h8_mov16(udata16);
1822         h8_setreg16(opcode & 0xf, udata16);
1823         H8_IFETCH_TIMING(1);
1824         H8_WORD_TIMING(1, address24);
1825      }
1826      break;
1827   case 0xa:
1828      // mov.b rx, @xx
1829      switch((opcode>>4)&0xf)
1830      {
1831      case 0x0:
1832         sdata16=h8_mem_read16(h8.pc);
1833         h8.pc += 2;
1834         address24 = sdata16 & 0xffffff;
1835         udata8=h8_mem_read8(address24);
1836         h8_mov8(udata8); // flags only
1837         h8_setreg8(opcode & 0xf, udata8);
1838         H8_IFETCH_TIMING(1);
1839         H8_BYTE_TIMING(1, address24);
1840         break;
1841      case 0x2:
1842         address24=h8_mem_read32(h8.pc);
1843         h8.pc += 4;
1844         udata8=h8_mem_read8(address24);
1845         h8_mov8(udata8); // flags only
1846         h8_setreg8(opcode & 0xf, udata8);
1847         H8_IFETCH_TIMING(2);
1848         H8_BYTE_TIMING(1, address24);
1849         break;
1850      case 0x8:
1851         sdata16=h8_mem_read16(h8.pc);
1852         h8.pc += 2;
1853         address24 = sdata16 & 0xffffff;
1854         udata8=h8_getreg8(opcode & 0xf);
1855         h8_mov8(udata8); // flags only
1856         h8_mem_write8(address24, udata8);
1857         H8_IFETCH_TIMING(3);
1858         H8_BYTE_TIMING(1, address24);
1859         break;
1860      case 0xa: // pass
1861         address24=h8_mem_read32(h8.pc);
1862         h8.pc += 4;
1863         udata8=h8_getreg8(opcode & 0xf);
1864         h8_mov8(udata8); // flags only
1865         h8_mem_write8(address24, udata8);
1866         H8_IFETCH_TIMING(3);
1867         H8_BYTE_TIMING(1, address24);
1868         break;
1869      default:
1870         logerror("H8/3002: Unk. group 6 a %x\n", opcode);
1871         h8.h8err = 1;
1872         break;
1873      }
1874      break;
1875   case 0xb:
1876      // mov.w rx, @xx / mov.w @xx, rx
1877      switch((opcode>>4)&0xf)
1878      {
1879      case 0x0:
1880         sdata16=h8_mem_read16(h8.pc);
1881         address24 = sdata16;
1882         address24 &= 0xffffff;
1883         h8.pc += 2;
1884         udata16=h8_mem_read16(address24);
1885         h8_mov16(udata16); // flags only
1886         h8_setreg16(opcode & 0xf, udata16);
1887         H8_IFETCH_TIMING(2);
1888         H8_WORD_TIMING(1, address24);
1889         break;
1890      case 0x2:
1891         address24=h8_mem_read32(h8.pc);
1892         h8.pc += 4;
1893         udata16=h8_mem_read16(address24);
1894         h8_mov16(udata16); // flags only
1895         h8_setreg16(opcode & 0xf, udata16);
1896         H8_IFETCH_TIMING(4);
1897         H8_WORD_TIMING(1, address24);
1898         break;
1899      case 0x8:
1900         sdata16=h8_mem_read16(h8.pc);
1901         address24 = sdata16;
1902         address24 &= 0xffffff;
1903         h8.pc += 2;
1904         udata16=h8_getreg16(opcode & 0xf);
1905         h8_mov16(udata16); // flags only
1906         h8_mem_write16(address24, udata16);
1907         H8_IFETCH_TIMING(2);
1908         H8_WORD_TIMING(1, address24);
1909         break;
1910      case 0xa: // pass
1911         address24=h8_mem_read32(h8.pc);
1912         h8.pc += 4;
1913         udata16=h8_getreg16(opcode & 0xf);
1914         h8_mov16(udata16); // flags only
1915         h8_mem_write16(address24, udata16);
1916         H8_IFETCH_TIMING(4);
1917         H8_WORD_TIMING(1, address24);
1918         break;
1919      default:
1920         logerror("H8/3002: Unk. group 6b %x\n", opcode);
1921         h8.h8err = 1;
1922         break;
1923      }
1924      break;
1925   case 0xc:
1926      if(opcode & 0x80)
1927      {
1928         // mov.b rx, @-erx
1929         srcreg = (opcode>>4)&7;
1930         h8_setreg32(srcreg, h8_getreg32(srcreg)-1);
1931         address24 = h8_getreg32(srcreg) & 0xffffff;
1932         udata8 = h8_getreg8(opcode & 0xf);
1933         h8_mem_write8(address24, udata8);
1934         H8_IFETCH_TIMING(1);
1935         H8_BYTE_TIMING(1, address24);
1936         H8_IOP_TIMING(2);
1937      }
1938      else
1939      {
1940         // mov.b @erx+,rx
1941         srcreg = (opcode>>4)&7;
1942         address24 = h8_getreg32(srcreg) & 0xffffff;
1943         h8_setreg32(srcreg, h8_getreg32(srcreg)+1);
1944         udata8 = h8_mem_read8(address24);
1945         h8_setreg8(opcode & 0xf, udata8);
1946         H8_IFETCH_TIMING(1);
1947         H8_BYTE_TIMING(1, address24);
1948         H8_IOP_TIMING(2);
1949      }
1950      h8_mov8(udata8);
1951      break;
1952   case 0xd:
1953      if(opcode & 0x80)
1954      {
1955         // mov.w rs, @-erd
1956         srcreg = (opcode>>4)&7;
1957         h8_setreg32(srcreg, h8_getreg32(srcreg)-2);
1958         address24 = h8_getreg32(srcreg) & 0xffffff;
1959         udata16 = h8_getreg16(opcode & 0xf);
1960         h8_mem_write16(address24, udata16);
1961         H8_IFETCH_TIMING(1);
1962         H8_WORD_TIMING(1, address24);
1963         H8_IOP_TIMING(2);
1964      }
1965      else
1966      {
1967         // mov.w @ers+, rd
1968         srcreg = (opcode>>4)&7;
1969         address24 = h8_getreg32(srcreg) & 0xffffff;
1970         h8_setreg32(srcreg, h8_getreg32(srcreg)+2);
1971         udata16 = h8_mem_read16(address24);
1972         h8_setreg16(opcode & 0xf, udata16);
1973         H8_IFETCH_TIMING(1);
1974         H8_BYTE_TIMING(1, address24);
1975         H8_IOP_TIMING(2);
1976      }
1977      h8_mov16(udata16);
1978      break;
1979   case 0xe: // pass
1980      // mov.b @(displ16 + Rs), rd
1981      sdata16=h8_mem_read16(h8.pc); // sign extend displacements !
1982      h8.pc += 2;
1983      address24 = (h8_getreg32((opcode>>4)&7)) & 0xffffff;
1984      address24 += sdata16;
1985      if(opcode & 0x80)
1986      {
1987         udata8 = h8_getreg8(opcode & 0xf);
1988         h8_mem_write8(address24, udata8);
1989      }
1990      else
1991      {
1992         udata8 = h8_mem_read8(address24);
1993         h8_setreg8(opcode & 0xf, udata8);
1994      }
1995      h8_mov8(udata8);
1996      H8_IFETCH_TIMING(2);
1997      H8_BYTE_TIMING(1, address24);
1998      break;
1999   case 0xf:
2000      // mov.w @(displ16 + Rs), rd
2001      sdata16=h8_mem_read16(h8.pc); // sign extend displacements !
2002      h8.pc += 2;
2003      address24 = (h8_getreg32((opcode>>4)&7)) & 0xffffff;
2004      address24 += sdata16;
2005      if(opcode & 0x80)
2006      {
2007         udata16 = h8_getreg16(opcode & 0xf);
2008         h8_mem_write16(address24, udata16);
2009      }
2010      else
2011      {
2012         udata16 = h8_mem_read16(address24);
2013         h8_setreg16(opcode & 0xf, udata16);
2014      }
2015      h8_mov16(udata16);
2016      H8_IFETCH_TIMING(2);
2017      H8_WORD_TIMING(1, address24);
2018      break;
2019   default:
2020      logerror("H8/3002: Unk. group 6 def %x\n", opcode);
2021      h8.h8err = 1;
2022      break;
2023   }
2024}
2025
2026static void h8_group7(UINT16 opcode)
2027{
2028   switch((opcode>>8)&0xf)
2029   {
2030   case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:
2031      {
2032         UINT8 bitnr;
2033
2034         dstreg = opcode & 0xf;
2035         udata8 = h8_getreg8(dstreg);
2036         bitnr = (opcode>>4)&7;
2037
2038         if(((opcode>>4)&0x8) == 0)
2039         {
2040            switch((opcode>>8)&7)
2041            {
2042            case 0:   udata8 = h8_bset8(bitnr, udata8); h8_setreg8(dstreg, udata8); H8_IFETCH_TIMING(1); break;
2043            case 2:   udata8 = h8_bclr8(bitnr, udata8); h8_setreg8(dstreg, udata8);H8_IFETCH_TIMING(1);break;
2044            case 3:   h8_btst8(bitnr, udata8); H8_IFETCH_TIMING(1); break;
2045            case 7:   h8_bld8(bitnr, udata8); H8_IFETCH_TIMING(1); break;
2046            default:
2047               logerror("H8/3002: Unk. group 7 0-7 def %x\n", opcode);
2048               h8.h8err = 1;
2049               break;
2050            }
2051         }
2052         else
2053         {
2054            switch((opcode>>8)&7)
2055            {
2056            default:
2057               logerror("H8/3002: Unk. group 7 0-7-1 def %x\n", opcode);
2058               h8.h8err = 1;
2059               break;
2060            }
2061         }
2062      }
2063      break;
2064   case 0x8:
2065      ext16 = h8_mem_read16(h8.pc);
2066      h8.pc += 2;
2067      udata32 = h8_mem_read32(h8.pc);
2068      h8.pc += 4;
2069
2070      if(((ext16>>8) & 0xf) == 0xa)
2071      {
2072         if(((ext16>>4) & 0xf) == 0xa)
2073         {
2074            udata8 = h8_getreg8(ext16 & 0xf);
2075            h8_mov8(udata8); // update flags !
2076            udata32 += h8_getreg32((opcode >> 4) & 7);
2077            h8_mem_write8(udata32, udata8);
2078         }
2079         else
2080         {
2081            udata32 += h8_getreg32((opcode >> 4) & 7);
2082            udata8 = h8_mem_read8(udata32);
2083            h8_mov8(udata8); // update flags !
2084            h8_setreg8(ext16 & 0xf, udata8);
2085         }
2086         H8_BYTE_TIMING(1, udata32);
2087         H8_IFETCH_TIMING(4);
2088      }
2089      else if ((ext16 & 0xfff0) == 0x6b20) // mov.w @(24-bit direct, rN), rM
2090      {
2091         udata32 += h8_getreg32((opcode >> 4) & 7);
2092         udata16 = h8_mem_read16(udata32);
2093         h8_setreg16(ext16 & 0xf, udata16);
2094         h8_mov16(udata16); // update flags !
2095         H8_WORD_TIMING(1, udata32);
2096         H8_IFETCH_TIMING(4);
2097      }
2098      else if ((ext16 & 0xfff0) == 0x6ba0) // mov.w rM, @(24-bit direct, rN)
2099      {
2100         udata32 += h8_getreg32((opcode >> 4) & 7);
2101         udata16 = h8_getreg16(ext16 & 0xf);
2102         h8_mem_write16(udata32, udata16);
2103         h8_mov16(udata16); // update flags !
2104         H8_WORD_TIMING(1, udata32);
2105         H8_IFETCH_TIMING(4);
2106      }
2107      else
2108      {
2109         logerror("H8/3002: Unk. group 7 8 %x\n", opcode);
2110         h8.h8err = 1;
2111      }
2112      break;
2113
2114
2115      // xxx.w #aa:16, rd
2116   case 0x9:
2117      if( ((opcode>>4) & 0xf) > 0x6)
2118      {
2119         logerror("H8/3002: Unk. group 7 9 %x\n", opcode);
2120         h8.h8err = 1;
2121      }
2122      else
2123      {
2124         UINT16 dst16;
2125         udata16 = h8_mem_read16(h8.pc);
2126         h8.pc += 2;
2127         dstreg = opcode&0xf;
2128         dst16 = h8_getreg16(dstreg);
2129
2130         switch((opcode>>4)&7)
2131         {
2132         case 0:   dst16 = h8_mov16(udata16); h8_setreg16(dstreg, dst16); H8_IFETCH_TIMING(2);break;
2133         case 1: dst16 = h8_add16(udata16, dst16); h8_setreg16(dstreg, dst16); H8_IFETCH_TIMING(2); break;
2134         case 2: h8_cmp16(udata16, dst16); H8_IFETCH_TIMING(2); break;
2135         case 3: dst16 = h8_sub16(udata16, dst16); h8_setreg16(dstreg, dst16); H8_IFETCH_TIMING(2); break;
2136         case 4: dst16 = h8_or16(udata16, dst16); h8_setreg16(dstreg, dst16); H8_IFETCH_TIMING(2); break;
2137         case 5: dst16 = h8_xor16(udata16, dst16); h8_setreg16(dstreg, dst16); H8_IFETCH_TIMING(2); break;
2138         case 6: dst16 = h8_and16(udata16, dst16); h8_setreg16(dstreg, dst16); H8_IFETCH_TIMING(2); break;
2139         default:
2140            logerror("H8/3002: Unk. group 7 9 %x\n", opcode);
2141            h8.h8err = 1;
2142            break;
2143         }
2144      }
2145      break;
2146      // xxx.l #aa:32, erd
2147   case 0xa:
2148      if( (((opcode>>4) & 0xf) > 0x6) || (opcode & 0x8))
2149      {
2150         logerror("H8/3002: Unk. group 7 a %x\n", opcode);
2151         h8.h8err = 1;
2152      }
2153      else
2154      {
2155         UINT32 dst32;
2156         udata32 = h8_mem_read32(h8.pc);
2157         dstreg = opcode&0x7;
2158         h8.pc +=4;
2159         dst32 = h8_getreg32(dstreg);
2160
2161         switch((opcode>>4)&7)
2162         {
2163         case 0:   dst32 = h8_mov32(udata32); h8_setreg32(dstreg, dst32); H8_IFETCH_TIMING(3); break;
2164         case 1: dst32 = h8_add32(udata32, dst32); h8_setreg32(dstreg, dst32); H8_IFETCH_TIMING(3); break;
2165         case 2: h8_cmp32(udata32, dst32); H8_IFETCH_TIMING(3); break;
2166         case 3: dst32 = h8_sub32(udata32, dst32); h8_setreg32(dstreg, dst32); H8_IFETCH_TIMING(3); break;
2167         case 4: dst32 = h8_or32(udata32, dst32);  h8_setreg32(dstreg, dst32); H8_IFETCH_TIMING(3); break;
2168         case 5: dst32 = h8_xor32(udata32, dst32); h8_setreg32(dstreg, dst32); H8_IFETCH_TIMING(3); break;
2169         case 6: dst32 = h8_and32(udata32, dst32); h8_setreg32(dstreg, dst32); H8_IFETCH_TIMING(3); break;
2170         default:
2171            logerror("H8/3002: Unk. group 7 a2 %x\n", opcode);
2172            h8.h8err = 1;
2173            break;
2174         }
2175      }
2176      break;
2177      // eepmov
2178   case 0xb:
2179      if ((opcode & 0xff) == 0xd4)
2180      {
2181         UINT16 cnt = h8_getreg16(4);
2182
2183         H8_IFETCH_TIMING(1);
2184         H8_BYTE_TIMING((2*cnt)+2, h8.regs[5]);
2185
2186         // eepmov.w
2187         while (cnt > 0)
2188         {
2189            h8_mem_write8(h8.regs[6], h8_mem_read8(h8.regs[5]));
2190            h8.regs[5]++;
2191            h8.regs[6]++;
2192            cnt--;
2193         }
2194         h8_setreg16(4, 0);
2195         h8.pc += 2;
2196      }
2197      else
2198      {
2199         logerror("H8/3002: Unk. eepmov form\n");
2200         h8.h8err = 1;
2201      }
2202      break;
2203      // bxx.b #xx:3, @rd
2204   case 0xc:
2205      {
2206         UINT8 bitnr;
2207
2208         address24 = h8_getreg32((opcode>>4) & 0x7);
2209         udata8 = h8_mem_read8(address24);
2210         H8_BYTE_TIMING(1, address24);
2211
2212         ext16 = h8_mem_read16(h8.pc);
2213         h8.pc += 2;
2214         H8_IFETCH_TIMING(2);
2215
2216         switch(ext16>>8)
2217         {
2218            // BTST Rn,@ERd
2219            case 0x63:
2220               srcreg = (ext16>>4)&0xf;
2221               bitnr = h8_getreg8(srcreg)&7;
2222               h8_btst8(bitnr, udata8);
2223               break;
2224            // btst.b #imm, @Rn
2225            case 0x73:
2226               bitnr = (ext16>>4)&7;
2227               h8_btst8(bitnr, udata8);
2228               break;
2229            default:
2230               h8.h8err=1;
2231         }
2232      }
2233      break;
2234   case 0xd:
2235      ext16 = h8_mem_read16(h8.pc);
2236      h8.pc += 2;
2237      address24 = h8_getreg32((opcode>>4) & 0x7);
2238      H8_IFETCH_TIMING(2);
2239      H8_BYTE_TIMING(1, address24);
2240      switch(ext16>>8)
2241      {
2242         // bset/bnot/bclr.b Rn, @ERd
2243         case 0x60:
2244            if (((opcode & 0x8f)!=0)||((ext16 & 0x0f)!=0))   {   h8.h8err=1;   break;   }
2245            h8_mem_write8(address24, h8_bset8(h8_getreg16((ext16>>4)&0xf)&7, h8_mem_read8(address24)));
2246            break;
2247         case 0x61:
2248            if (((opcode & 0x8f)!=0)||((ext16 & 0x0f)!=0))   {   h8.h8err=1;   break;   }
2249            h8_mem_write8(address24, h8_bnot8(h8_getreg16((ext16>>4)&0xf)&7, h8_mem_read8(address24)));
2250            break;
2251         case 0x62:
2252            if (((opcode & 0x8f)!=0)||((ext16 & 0x0f)!=0))   {   h8.h8err=1;   break;   }
2253            h8_mem_write8(address24, h8_bclr8(h8_getreg16((ext16>>4)&0xf)&7, h8_mem_read8(address24)));
2254            break;
2255
2256         case 0x67:   // bst/bist.b #Imm:3, @ERd
2257            if (((opcode & 0x8f)!=0)||((ext16 & 0x0f)!=0))   {   h8.h8err=1;   break;   }
2258            if ((ext16 & 0x80)!=0)
2259            {
2260               h8_mem_write8(address24, h8_bist8((ext16>>4)&7, h8_mem_read8(address24)));
2261            }
2262            else
2263            {
2264               h8_mem_write8(address24, h8_bst8((ext16>>4)&7, h8_mem_read8(address24)));
2265            }
2266            break;
2267
2268         // bset/bnot/bclr.b #Imm:3, @ERd
2269         case 0x70:
2270            if (((opcode & 0x8f)!=0)||((ext16 & 0x8f)!=0))   {   h8.h8err=1;   break;   }
2271            h8_mem_write8(address24, h8_bset8((ext16>>4)&7, h8_mem_read8(address24)));
2272            break;
2273         case 0x71:
2274            if (((opcode & 0x8f)!=0)||((ext16 & 0x8f)!=0))   {   h8.h8err=1;   break;   }
2275            h8_mem_write8(address24, h8_bnot8((ext16>>4)&7, h8_mem_read8(address24)));
2276            break;
2277         case 0x72:
2278            if (((opcode & 0x8f)!=0)||((ext16 & 0x8f)!=0))   {   h8.h8err=1;   break;   }
2279            h8_mem_write8(address24, h8_bclr8((ext16>>4)&7, h8_mem_read8(address24)));
2280            break;
2281      }
2282      break;
2283
2284      // bxxx.b #imm, @aa:8
2285   case 0xe:
2286   case 0xf:
2287      {
2288         UINT8 bitnr=0;
2289         ext16 = h8_mem_read16(h8.pc);
2290         h8.pc += 2;
2291         address24 = 0xffff00 + (opcode & 0xff);
2292         udata8 = h8_mem_read8(address24);
2293
2294         switch((ext16>>8)&0xff)
2295         {
2296         case 0x30:
2297         case 0x60:
2298            bitnr = (ext16>>4)&7;
2299            udata8 = h8_bset8(bitnr, udata8); h8_mem_write8(address24, udata8); H8_IFETCH_TIMING(2); H8_BYTE_TIMING(2, address24);
2300            break;
2301         case 0x70:
2302            bitnr = (ext16>>4)&7;
2303            if(ext16&0x80) h8.h8err = 1;
2304            udata8 = h8_bset8(bitnr, udata8); h8_mem_write8(address24, udata8); H8_IFETCH_TIMING(2); H8_BYTE_TIMING(2, address24);
2305            break;
2306         case 0x32:
2307         case 0x62:
2308            bitnr = h8_getreg8((ext16>>4)&0xf)&7;
2309            udata8 = h8_bclr8(bitnr, udata8); h8_mem_write8(address24, udata8); H8_IFETCH_TIMING(2); H8_BYTE_TIMING(2, address24);
2310            break;
2311         case 0x72:
2312            bitnr = (ext16>>4)&7;
2313            if(ext16&0x80) h8.h8err = 1;
2314            udata8 = h8_bclr8(bitnr, udata8); h8_mem_write8(address24, udata8); H8_IFETCH_TIMING(2); H8_BYTE_TIMING(2, address24);
2315            break;
2316         case 0x63:
2317            bitnr = h8_getreg8((ext16>>4)&0xf)&7;
2318            h8_btst8(bitnr, udata8); H8_IFETCH_TIMING(2); H8_BYTE_TIMING(1, address24);
2319            break;
2320         case 0x73:
2321            bitnr = (ext16>>4)&7;
2322            if(ext16&0x80) h8.h8err = 1;
2323            h8_btst8(bitnr, udata8); H8_IFETCH_TIMING(2); H8_BYTE_TIMING(1, address24);
2324            break;
2325         case 0x74:
2326            bitnr = (ext16>>4)&7;
2327            if(ext16&0x80)
2328            {
2329               // bior
2330               h8.h8err = 1;
2331            }
2332            else
2333            {
2334               h8_bor8(bitnr, udata8);  H8_IFETCH_TIMING(2); H8_BYTE_TIMING(1, address24);
2335            }
2336            break;
2337         case 0x67:
2338            bitnr = (ext16>>4)&7;
2339            if(ext16&0x80)
2340            {
2341               // bist
2342               h8.h8err = 1;
2343            }
2344            else
2345            {
2346               h8_bst8(bitnr, udata8);  H8_IFETCH_TIMING(2); H8_BYTE_TIMING(2, address24);
2347            }
2348            break;
2349         case 0x77:
2350            bitnr = (ext16>>4)&7;
2351            if(ext16&0x80)
2352            {
2353               // bild
2354               h8.h8err = 1;
2355            }
2356            else
2357            {
2358               h8_bld8(bitnr, udata8);  H8_IFETCH_TIMING(2); H8_BYTE_TIMING(2, address24);
2359            }
2360            break;
2361         default:
2362            h8.h8err = 1;
2363            break;
2364         }
2365         if(h8.h8err)
2366            logerror("H8/3002: Unk. group 7 e %x\n", opcode);
2367      }
2368      break;
2369   default:
2370      logerror("H8/3002: Unk. group 7 def %x\n", opcode);
2371      h8.h8err = 1;
2372      break;
2373   }
2374}
2375
2376
2377static UINT8 h8_mov8(UINT8 src)
2378{
2379   // N and Z modified
2380   h8.h8nflag = (src>>7) & 1;
2381   h8.h8vflag = 0;
2382
2383   // zflag
2384   if(src==0)
2385   {
2386      h8.h8zflag = 1;
2387   }
2388   else
2389   {
2390      h8.h8zflag = 0;
2391   }
2392
2393   return src;
2394}
2395
2396static UINT16 h8_mov16(UINT16 src)
2397{
2398   // N and Z modified
2399   h8.h8nflag = (src>>15) & 1;
2400   h8.h8vflag = 0;
2401
2402   // zflag
2403   if(src==0)
2404   {
2405      h8.h8zflag = 1;
2406   }
2407   else
2408   {
2409      h8.h8zflag = 0;
2410   }
2411   return src;
2412}
2413
2414static UINT32 h8_mov32(UINT32 src)
2415{
2416   // N and Z modified
2417   h8.h8nflag = (src>>31) & 1;
2418   h8.h8vflag = 0;
2419
2420   // zflag
2421   if(src==0)
2422   {
2423      h8.h8zflag = 1;
2424   }
2425   else
2426   {
2427      h8.h8zflag = 0;
2428   }
2429
2430   return src;
2431}
2432
2433static UINT8 h8_sub8(UINT8 src, UINT8 dst)
2434{
2435   UINT16 res;
2436
2437   res = (UINT16)dst - src;
2438   // H,N,Z,V,C modified
2439   h8.h8nflag = (res>>7) & 1;
2440   h8.h8vflag = (((src^dst) & (res^dst))>>7) & 1;
2441   h8.h8cflag = (res >> 8) & 1;
2442
2443   // zflag
2444   if((res&0xff)==0)
2445   {
2446      h8.h8zflag = 1;
2447   }
2448   else
2449   {
2450      h8.h8zflag = 0;
2451   }
2452
2453   h8.h8hflag = ((src^dst^res) & 0x10) ? 1 : 0;
2454
2455   return res;
2456}
2457
2458static UINT16 h8_sub16(UINT16 src, UINT16 dst)
2459{
2460   UINT32 res;
2461
2462   res = (UINT32)dst - src;
2463   // H,N,Z,V,C modified
2464   h8.h8nflag = (res>>15) & 1;
2465   h8.h8vflag = (((src^dst) & (res^dst))>>15) & 1;
2466   h8.h8cflag = (res >> 16) & 1;
2467   //  h8.h8hflag = (res>>28) & 1;
2468
2469   // zflag
2470   if((res&0xffff)==0)
2471   {
2472      h8.h8zflag = 1;
2473   }
2474   else
2475   {
2476      h8.h8zflag = 0;
2477   }
2478
2479   h8.h8hflag = ((src^dst^res) & 0x1000) ? 1 : 0;
2480
2481   return res;
2482}
2483
2484static UINT32 h8_sub32(UINT32 src, UINT32 dst)
2485{
2486   UINT64 res;
2487
2488   res = (UINT64)dst - src;
2489   // H,N,Z,V,C modified
2490   h8.h8nflag = (res>>31) & 1;
2491   h8.h8vflag = (((src^dst) & (res^dst))>>31) & 1;
2492   h8.h8cflag = (res >> 32) & 1;
2493   //  h8.h8hflag = (res>>28) & 1;
2494
2495   // zflag
2496   if((res&0xffffffff)==0)
2497   {
2498      h8.h8zflag = 1;
2499   }
2500   else
2501   {
2502      h8.h8zflag = 0;
2503   }
2504
2505   h8.h8hflag = ((src^dst^res) & 0x10000000) ? 1 : 0;
2506
2507   return res;
2508}
2509
2510
2511
2512
2513static UINT8 h8_add8(UINT8 src, UINT8 dst)
2514{
2515   UINT16 res;
2516
2517   res = (UINT16)src + dst;
2518   // H,N,Z,V,C modified
2519   h8.h8nflag = (res & 0x80) ? 1 : 0;
2520   h8.h8vflag = ((src^res) & (dst^res) & 0x80) ? 1 : 0;
2521   h8.h8cflag = (res & 0x100) ? 1 : 0;
2522   h8.h8zflag = (res & 0xff) ? 0 : 1;
2523   h8.h8hflag = ((src^dst^res) & 0x10) ? 1 : 0;
2524
2525   return (UINT8)res;
2526}
2527
2528static UINT16 h8_add16(UINT16 src, UINT16 dst)
2529{
2530   UINT32 res;
2531
2532   res = (UINT32)src + dst;
2533   // H,N,Z,V,C modified
2534   h8.h8nflag = (res & 0x8000) ? 1 : 0;
2535   h8.h8vflag = ((src^res) & (dst^res) & 0x8000) ? 1 : 0;
2536   h8.h8cflag = (res & 0x10000) ? 1 : 0;
2537   h8.h8zflag = (res & 0xffff) ? 0 : 1;
2538   h8.h8hflag = ((src^dst^res) & 0x1000) ? 1 : 0;
2539
2540   return res;
2541}
2542
2543static UINT32 h8_add32(UINT32 src, UINT32 dst)
2544{
2545   UINT64 res;
2546
2547   res = (UINT64)src + dst;
2548   // H,N,Z,V,C modified
2549   h8.h8nflag = (res & 0x80000000) ? 1 : 0;
2550   h8.h8vflag = (((src^res) & (dst^res)) & 0x80000000) ? 1 : 0;
2551   h8.h8cflag = ((res) & (((UINT64)1) << 32)) ? 1 : 0;
2552   h8.h8zflag = (res & 0xffffffff) ? 0 : 1;
2553   h8.h8hflag = ((src^dst^res) & 0x10000000) ? 1 : 0;
2554
2555   return res;
2556}
2557
2558
2559static UINT8 h8_addx8(UINT8 src, UINT8 dst)
2560{
2561   UINT16 res;
2562
2563   res = (UINT16)src + dst + h8.h8cflag;
2564   // H,N,Z,V,C modified
2565   h8.h8nflag = (res & 0x80) ? 1 : 0;
2566   h8.h8vflag = ((src^res) & (dst^res) & 0x80) ? 1 : 0;
2567   h8.h8cflag = (res >> 8) & 1;
2568   h8.h8hflag = ((src^dst^res) & 0x10) ? 1 : 0;
2569   h8.h8zflag = (res & 0xff) ? 0 : h8.h8zflag;
2570
2571   return (UINT8)res;
2572}
2573
2574static void h8_cmp8(UINT8 src, UINT8 dst)
2575{
2576   UINT16 res = (UINT16)dst - src;
2577
2578   h8.h8cflag = (res & 0x100) ? 1 : 0;
2579   h8.h8vflag = (((dst) ^ (src)) & ((dst) ^ (res)) & 0x80) ? 1 : 0;
2580   h8.h8zflag = ((res & 0xff) == 0) ? 1 : 0;
2581   h8.h8nflag = (res & 0x80) ? 1 : 0;
2582   h8.h8hflag = ((src^dst^res) & 0x10) ? 1 : 0;
2583}
2584
2585static void h8_cmp16(UINT16 src, UINT16 dst)
2586{
2587   UINT32 res = (UINT32)dst - src;
2588
2589   h8.h8cflag = (res & 0x10000) ? 1 : 0;
2590   h8.h8vflag = (((dst) ^ (src)) & ((dst) ^ (res)) & 0x8000) ? 1 : 0;
2591   h8.h8zflag = ((res & 0xffff) == 0) ? 1 : 0;
2592   h8.h8nflag = (res & 0x8000) ? 1 : 0;
2593   h8.h8hflag = ((src^dst^res) & 0x1000) ? 1 : 0;
2594}
2595
2596static void h8_cmp32(UINT32 src, UINT32 dst)
2597{
2598   UINT64 res = (UINT64)dst - src;
2599
2600   h8.h8cflag = (res & (UINT64)U64(0x100000000)) ? 1 : 0;
2601   h8.h8vflag = (((dst) ^ (src)) & ((dst) ^ (res)) & 0x80000000) ? 1 : 0;
2602   h8.h8zflag = ((res & 0xffffffff) == 0) ? 1 : 0;
2603   h8.h8nflag = (res & 0x80000000) ? 1 : 0;
2604   h8.h8hflag = ((src^dst^res) & 0x10000000) ? 1 : 0;
2605}
2606
2607
2608static UINT8 h8_subx8(UINT8 src, UINT8 dst)
2609{
2610   UINT16 res;
2611
2612   res = (UINT16)dst - src - (h8.h8cflag) ? 1 : 0;
2613   // H,N,Z,V,C modified
2614   h8.h8nflag = (res>>7) & 1;
2615   h8.h8vflag = (((src^dst) & (res^dst))>>7) & 1;
2616   h8.h8cflag = (res >> 8) & 1;
2617
2618   // zflag
2619   if((res&0xff)==0)
2620   {
2621      h8.h8zflag = 1;
2622   }
2623   else
2624   {
2625      h8.h8zflag = 0;
2626   }
2627
2628   h8.h8hflag = ((src^dst^res) & 0x10) ? 1 : 0;
2629
2630   return res;
2631}
2632
2633static UINT8 h8_or8(UINT8 src, UINT8 dst)
2634{
2635   UINT8 res;
2636   res = src | dst;
2637
2638   h8.h8nflag = (res>>7) & 1;
2639   h8.h8vflag = 0;
2640
2641   // zflag
2642   if(res==0)
2643   {
2644      h8.h8zflag = 1;
2645   }
2646   else
2647   {
2648      h8.h8zflag = 0;
2649   }
2650
2651   return res;
2652}
2653
2654static UINT16 h8_or16(UINT16 src, UINT16 dst)
2655{
2656   UINT16 res;
2657   res = src | dst;
2658
2659   h8.h8nflag = (res>>15) & 1;
2660   h8.h8vflag = 0;
2661
2662   // zflag
2663   if(res==0)
2664   {
2665      h8.h8zflag = 1;
2666   }
2667   else
2668   {
2669      h8.h8zflag = 0;
2670   }
2671
2672   return res;
2673}
2674
2675static UINT32 h8_or32(UINT32 src, UINT32 dst)
2676{
2677   UINT32 res;
2678   res = src | dst;
2679
2680   h8.h8nflag = (res>>31) & 1;
2681   h8.h8vflag = 0;
2682
2683   // zflag
2684   if(res==0)
2685   {
2686      h8.h8zflag = 1;
2687   }
2688   else
2689   {
2690      h8.h8zflag = 0;
2691   }
2692
2693   return res;
2694}
2695
2696static UINT8 h8_xor8(UINT8 src, UINT8 dst)
2697{
2698   UINT8 res;
2699   res = src ^ dst;
2700
2701   h8.h8nflag = (res>>7) & 1;
2702   h8.h8vflag = 0;
2703
2704   // zflag
2705   if(res==0)
2706   {
2707      h8.h8zflag = 1;
2708   }
2709   else
2710   {
2711      h8.h8zflag = 0;
2712   }
2713
2714   return res;
2715}
2716
2717static UINT16 h8_xor16(UINT16 src, UINT16 dst)
2718{
2719   UINT16 res;
2720   res = src ^ dst;
2721
2722   h8.h8nflag = (res>>15) & 1;
2723   h8.h8vflag = 0;
2724
2725   // zflag
2726   if(res==0)
2727   {
2728      h8.h8zflag = 1;
2729   }
2730   else
2731   {
2732      h8.h8zflag = 0;
2733   }
2734
2735   return res;
2736}
2737
2738static UINT32 h8_xor32(UINT32 src, UINT32 dst)
2739{
2740   UINT32 res;
2741   res = src ^ dst;
2742
2743   h8.h8nflag = (res>>31) & 1;
2744   h8.h8vflag = 0;
2745
2746   // zflag
2747   if(res==0)
2748   {
2749      h8.h8zflag = 1;
2750   }
2751   else
2752   {
2753      h8.h8zflag = 0;
2754   }
2755
2756   return res;
2757}
2758
2759static UINT8 h8_and8(UINT8 src, UINT8 dst)
2760{
2761   UINT8 res;
2762
2763   res = src & dst;
2764   // N and Z modified
2765   h8.h8nflag = (res>>7) & 1;
2766   h8.h8vflag = 0;
2767
2768   // zflag
2769   if(res==0)
2770   {
2771      h8.h8zflag = 1;
2772   }
2773   else
2774   {
2775      h8.h8zflag = 0;
2776   }
2777
2778   return res;
2779}
2780
2781static UINT16 h8_and16(UINT16 src, UINT16 dst)
2782{
2783   UINT16 res;
2784
2785   res = src & dst;
2786   // N and Z modified
2787   h8.h8nflag = (res>>15) & 1;
2788   h8.h8vflag = 0;
2789
2790   // zflag
2791   if(res==0)
2792   {
2793      h8.h8zflag = 1;
2794   }
2795   else
2796   {
2797      h8.h8zflag = 0;
2798   }
2799
2800   return res;
2801}
2802
2803static UINT32 h8_and32(UINT32 src, UINT32 dst)
2804{
2805   UINT32 res;
2806
2807   res = src & dst;
2808   // N and Z modified
2809   h8.h8nflag = (res>>31) & 1;
2810   h8.h8vflag = 0;
2811
2812   // zflag
2813   if(res==0)
2814   {
2815      h8.h8zflag = 1;
2816   }
2817   else
2818   {
2819      h8.h8zflag = 0;
2820   }
2821
2822   return res;
2823}
2824
2825static void h8_btst8(UINT8 bit, UINT8 dst)
2826{
2827   // test single bit and update Z flag
2828   if( (dst & (1<<bit)) == 0)
2829   {
2830      h8.h8zflag = 1;
2831   }
2832   else
2833   {
2834      h8.h8zflag = 0;
2835   }
2836}
2837
2838static void h8_bld8(UINT8 bit, UINT8 dst)
2839{
2840   // load bit to carry
2841   h8.h8cflag = (dst >> bit) & 1;
2842}
2843
2844static UINT8 h8_bnot8(UINT8 src, UINT8 dst)
2845{
2846   // invert single bit, no effect on C flag
2847   return dst ^ (1<<src);
2848}
2849
2850static UINT8 h8_bst8(UINT8 src, UINT8 dst)
2851{
2852   UINT8 res;
2853
2854   // store carry flag in bit position
2855   if(h8.h8cflag == 1)
2856   {
2857      res = dst | (1<<src);
2858   }
2859   else
2860   {
2861      res = dst & ~(1<<src); // mask off
2862   }
2863   return res;
2864}
2865
2866static UINT8 h8_bist8(UINT8 src, UINT8 dst)
2867{
2868   UINT8 res;
2869
2870   // store inverse of carry flag in bit position
2871   if(h8.h8cflag == 0)
2872   {
2873      res = dst | (1<<src);
2874   }
2875   else
2876   {
2877      res = dst & ~(1<<src); // mask off
2878   }
2879   return res;
2880}
2881
2882static UINT8 h8_bset8(UINT8 src, UINT8 dst)
2883{
2884   // pass
2885   UINT8 res;
2886   res = dst | (1<<src);
2887   return res;
2888}
2889
2890// does not affect result, res in C flag only
2891static void h8_bor8(UINT8 src, UINT8 dst)
2892{
2893   // pass
2894   UINT8 res;
2895
2896   res = dst & (1<<src);
2897   h8.h8cflag |= res ? 1 : 0;
2898}
2899
2900#ifdef UNUSED_FUNCTION
2901static void h8_bxor8(UINT8 src, UINT8 dst)
2902{
2903   dst >>= src;
2904   dst &= 0x1;
2905   h8.h8cflag ^= dst;
2906}
2907#endif
2908
2909static UINT8 h8_bclr8(UINT8 src, UINT8 dst)
2910{
2911   // pass
2912   UINT8 res;
2913   res = dst & ~(1<<src);
2914   return res;
2915}
2916
2917static INT8 h8_neg8(INT8 src)
2918{
2919   INT8 res;
2920
2921   if((UINT8)src == 0x80)
2922   {
2923      // overflow !
2924      h8.h8vflag = 1;
2925      res = 0x80;
2926   }
2927   else
2928   {
2929      h8.h8vflag = 0;
2930      res = 0-src;
2931   }
2932
2933   // N and Z modified
2934   h8.h8nflag = (res>>7) & 1;
2935   // zflag
2936   if(res==0)
2937   {
2938      h8.h8zflag = 1;
2939   }
2940   else
2941   {
2942      h8.h8zflag = 0;
2943   }
2944
2945   h8.h8hflag = ((src|res)&0x08) ? 1 : 0;
2946   h8.h8cflag = ((src|res)&0x80) ? 1 : 0;
2947
2948   return res;
2949}
2950
2951static INT16 h8_neg16(INT16 src)
2952{
2953   INT16 res;
2954
2955   if((UINT16)src == 0x8000)
2956   {
2957      // overflow !
2958      h8.h8vflag = 1;
2959      res = 0x8000;
2960   }
2961   else
2962   {
2963      h8.h8vflag = 0;
2964      res = 0-src;
2965   }
2966
2967   // N and Z modified
2968   h8.h8nflag = (res>>15) & 1;
2969   // zflag
2970   if(res==0)
2971   {
2972      h8.h8zflag = 1;
2973   }
2974   else
2975   {
2976      h8.h8zflag = 0;
2977   }
2978
2979   h8.h8hflag = ((src|res)&0x0800) ? 1 : 0;
2980   h8.h8cflag = ((src|res)&0x8000) ? 1 : 0;
2981
2982   return res;
2983}
2984
2985static INT32 h8_neg32(INT32 src)
2986{
2987   INT32 res;
2988
2989   if((UINT32)src == 0x80000000)
2990   {
2991      // overflow !
2992      h8.h8vflag = 1;
2993      res = 0x80000000;
2994   }
2995   else
2996   {
2997      h8.h8vflag = 0;
2998      res = 0-src;
2999   }
3000
3001   // N and Z modified
3002   h8.h8nflag = (res>>31) & 1;
3003   // zflag
3004   if(res==0)
3005   {
3006      h8.h8zflag = 1;
3007   }
3008   else
3009   {
3010      h8.h8zflag = 0;
3011   }
3012
3013   h8.h8hflag = ((src|res)&0x08000000) ? 1 : 0;
3014   h8.h8cflag = ((src|res)&0x80000000) ? 1 : 0;
3015
3016   return res;
3017}
3018
3019static UINT8 h8_not8(UINT8 src)
3020{
3021   UINT8 res;
3022
3023   res = ~src;
3024
3025   // N and Z modified
3026   h8.h8nflag = (res>>7) & 1;
3027   h8.h8vflag = 0;
3028
3029   // zflag
3030   if(res==0)
3031   {
3032      h8.h8zflag = 1;
3033   }
3034   else
3035   {
3036      h8.h8zflag = 0;
3037   }
3038
3039   return res;
3040}
3041
3042static UINT16 h8_not16(UINT16 src)
3043{
3044   UINT16 res;
3045
3046   res = ~src;
3047
3048   // N and Z modified
3049   h8.h8nflag = (res>>15) & 1;
3050   h8.h8vflag = 0;
3051
3052   // zflag
3053   if(res==0)
3054   {
3055      h8.h8zflag = 1;
3056   }
3057   else
3058   {
3059      h8.h8zflag = 0;
3060   }
3061
3062   return res;
3063}
3064
3065static UINT32 h8_not32(UINT32 src)
3066{
3067   UINT32 res;
3068
3069   res = ~src;
3070
3071   // N and Z modified
3072   h8.h8nflag = (res>>31) & 1;
3073   h8.h8vflag = 0;
3074
3075   // zflag
3076   if(res==0)
3077   {
3078      h8.h8zflag = 1;
3079   }
3080   else
3081   {
3082      h8.h8zflag = 0;
3083   }
3084
3085   return res;
3086}
3087
3088static UINT8 h8_rotxr8(UINT8 src)
3089{
3090   UINT8 res;
3091
3092   // rotate through carry right
3093   res = src>>1;
3094   if(h8.h8cflag)res |= 0x80; // put cflag in upper bit
3095   h8.h8cflag = src & 1;
3096
3097   // N and Z modified
3098   h8.h8nflag = (res>>7) & 1;
3099   h8.h8vflag = 0;
3100
3101   // zflag
3102   if(res==0)
3103   {
3104      h8.h8zflag = 1;
3105   }
3106   else
3107   {
3108      h8.h8zflag = 0;
3109   }
3110
3111   return res;
3112}
3113
3114static UINT16 h8_rotxr16(UINT16 src)
3115{
3116   UINT16 res;
3117
3118   // rotate through carry right
3119   res = src>>1;
3120   if(h8.h8cflag)res |= 0x8000; // put cflag in upper bit
3121   h8.h8cflag = src & 1;
3122
3123   // N and Z modified
3124   h8.h8nflag = (res>>15) & 1;
3125   h8.h8vflag = 0;
3126
3127   // zflag
3128   if(res==0)
3129   {
3130      h8.h8zflag = 1;
3131   }
3132   else
3133   {
3134      h8.h8zflag = 0;
3135   }
3136
3137   return res;
3138}
3139
3140static UINT8 h8_rotxl8(UINT8 src)
3141{
3142   UINT8 res;
3143
3144   // rotate through carry
3145   res = src<<1;
3146   res |= (h8.h8cflag & 1);
3147   h8.h8cflag = (src>>7) & 1;
3148
3149   // N and Z modified
3150   h8.h8nflag = (res>>7) & 1;
3151   h8.h8vflag = 0;
3152
3153   // zflag
3154   if(res==0)
3155   {
3156      h8.h8zflag = 1;
3157   }
3158   else
3159   {
3160      h8.h8zflag = 0;
3161   }
3162
3163   return res;
3164}
3165
3166static UINT16 h8_rotxl16(UINT16 src)
3167{
3168   UINT16 res;
3169
3170   // rotate through carry
3171   res = src<<1;
3172   res |= (h8.h8cflag & 1);
3173   h8.h8cflag = (src>>15) & 1;
3174
3175   // N and Z modified
3176   h8.h8nflag = (res>>15) & 1;
3177   h8.h8vflag = 0;
3178
3179   // zflag
3180   if(res==0)
3181   {
3182      h8.h8zflag = 1;
3183   }
3184   else
3185   {
3186      h8.h8zflag = 0;
3187   }
3188
3189   return res;
3190}
3191
3192static UINT32 h8_rotxl32(UINT32 src)
3193{
3194   UINT32 res;
3195
3196   // rotate through carry
3197   res = src<<1;
3198   res |= (h8.h8cflag & 1);
3199   h8.h8cflag = (src>>31) & 1;
3200
3201   // N and Z modified
3202   h8.h8nflag = (res>>31) & 1;
3203   h8.h8vflag = 0;
3204
3205   // zflag
3206   if(res==0)
3207   {
3208      h8.h8zflag = 1;
3209   }
3210   else
3211   {
3212      h8.h8zflag = 0;
3213   }
3214
3215   return res;
3216}
3217
3218
3219static UINT8 h8_rotl8(UINT8 src)
3220{
3221   UINT8 res;
3222
3223   // rotate
3224   res = src<<1;
3225   h8.h8cflag = (src>>7) & 1;
3226   res |= (h8.h8cflag & 1);
3227
3228   // N and Z modified
3229   h8.h8nflag = (res>>7) & 1;
3230   h8.h8vflag = 0;
3231
3232   // zflag
3233   if(res==0)
3234   {
3235      h8.h8zflag = 1;
3236   }
3237   else
3238   {
3239      h8.h8zflag = 0;
3240   }
3241
3242   return res;
3243}
3244
3245static UINT16 h8_rotl16(UINT16 src)
3246{
3247   UINT16 res;
3248
3249   // rotate
3250   res = src<<1;
3251   h8.h8cflag = (src>>15) & 1;
3252   res |= (h8.h8cflag & 1);
3253
3254   // N and Z modified
3255   h8.h8nflag = (res>>15) & 1;
3256   h8.h8vflag = 0;
3257
3258   // zflag
3259   if(res==0)
3260   {
3261      h8.h8zflag = 1;
3262   }
3263   else
3264   {
3265      h8.h8zflag = 0;
3266   }
3267
3268   return res;
3269}
3270
3271static UINT32 h8_rotl32(UINT32 src)
3272{
3273   UINT32 res;
3274
3275   // rotate
3276   res = src<<1;
3277   h8.h8cflag = (src>>31) & 1;
3278   res |= (h8.h8cflag & 1);
3279
3280   // N and Z modified
3281   h8.h8nflag = (res>>31) & 1;
3282   h8.h8vflag = 0;
3283
3284   // zflag
3285   if(res==0)
3286   {
3287      h8.h8zflag = 1;
3288   }
3289   else
3290   {
3291      h8.h8zflag = 0;
3292   }
3293
3294   return res;
3295}
3296
3297static UINT8 h8_shll8(UINT8 src)
3298{
3299   UINT8 res;
3300   h8.h8cflag = (src>>7) & 1;
3301   res = src<<1;
3302   // N and Z modified
3303   h8.h8nflag = (res>>7) & 1;
3304   h8.h8vflag = 0;
3305
3306   // zflag
3307   if(res==0)
3308   {
3309      h8.h8zflag = 1;
3310   }
3311   else
3312   {
3313      h8.h8zflag = 0;
3314   }
3315
3316   return res;
3317}
3318
3319static UINT16 h8_shll16(UINT16 src)
3320{
3321   UINT16 res;
3322   h8.h8cflag = (src>>15) & 1;
3323   res = src<<1;
3324   // N and Z modified
3325   h8.h8nflag = (res>>15) & 1;
3326   h8.h8vflag = 0;
3327
3328   // zflag
3329   if(res==0)
3330   {
3331      h8.h8zflag = 1;
3332   }
3333   else
3334   {
3335      h8.h8zflag = 0;
3336   }
3337
3338   return res;
3339}
3340
3341static UINT32 h8_shll32(UINT32 src)
3342{
3343   UINT32 res;
3344   h8.h8cflag = (src>>31) & 1;
3345   res = src<<1;
3346   // N and Z modified
3347   h8.h8nflag = (res>>31) & 1;
3348   h8.h8vflag = 0;
3349
3350   // zflag
3351   if(res==0)
3352   {
3353      h8.h8zflag = 1;
3354   }
3355   else
3356   {
3357      h8.h8zflag = 0;
3358   }
3359
3360   return res;
3361}
3362
3363static UINT8 h8_shlr8(UINT8 src)
3364{
3365   UINT8 res;
3366   h8.h8cflag = src&1;
3367   res = src>>1;
3368   // N and Z modified
3369   h8.h8nflag = 0;
3370   h8.h8vflag = 0;
3371
3372   // zflag
3373   if(res==0)
3374   {
3375      h8.h8zflag = 1;
3376   }
3377   else
3378   {
3379      h8.h8zflag = 0;
3380   }
3381
3382   return res;
3383}
3384
3385static UINT16 h8_shlr16(UINT16 src)
3386{
3387   UINT16 res;
3388   h8.h8cflag = src&1;
3389   res = src>>1;
3390   // N and Z modified
3391   h8.h8nflag = 0;
3392   h8.h8vflag = 0;
3393
3394   // zflag
3395   if(res==0)
3396   {
3397      h8.h8zflag = 1;
3398   }
3399   else
3400   {
3401      h8.h8zflag = 0;
3402   }
3403
3404   return res;
3405}
3406
3407static UINT32 h8_shlr32(UINT32 src)
3408{
3409   UINT32 res;
3410   h8.h8cflag = src&1;
3411   res = src>>1;
3412
3413   // N and Z modified, V always cleared
3414   h8.h8nflag = 0;
3415   h8.h8vflag = 0;
3416
3417   // zflag
3418   if(res==0)
3419   {
3420      h8.h8zflag = 1;
3421   }
3422   else
3423   {
3424      h8.h8zflag = 0;
3425   }
3426
3427   return res;
3428}
3429
3430static INT8 h8_shar8(INT8 src)
3431{
3432   INT8 res;
3433   h8.h8cflag = src&1;
3434   res = (src>>1)|(src&0x80);
3435   // N and Z modified
3436   h8.h8nflag = (res>>7)&1;
3437   h8.h8vflag = 0;
3438
3439   // zflag
3440   if(res==0)
3441   {
3442      h8.h8zflag = 1;
3443   }
3444   else
3445   {
3446      h8.h8zflag = 0;
3447   }
3448
3449   return res;
3450}
3451
3452static INT16 h8_shar16(INT16 src)
3453{
3454   INT16 res;
3455   h8.h8cflag = src&1;
3456   res = (src>>1)|(src&0x8000);
3457   // N and Z modified
3458   h8.h8nflag = (res>>15)&1;
3459   h8.h8vflag = 0;
3460
3461   // zflag
3462   if(res==0)
3463   {
3464      h8.h8zflag = 1;
3465   }
3466   else
3467   {
3468      h8.h8zflag = 0;
3469   }
3470
3471   return res;
3472}
3473
3474static INT32 h8_shar32(INT32 src)
3475{
3476   INT32 res;
3477
3478   h8.h8cflag = src&1;
3479   res = (src>>1)|(src&0x80000000);
3480   // N and Z modified
3481   h8.h8nflag = (res>>31) & 1;
3482   h8.h8vflag = 0;
3483
3484   // zflag
3485   if(res==0)
3486   {
3487      h8.h8zflag = 1;
3488   }
3489   else
3490   {
3491      h8.h8zflag = 0;
3492   }
3493
3494   return res;
3495}
3496
3497static INT8 h8_shal8(INT8 src)
3498{
3499   INT8 res;
3500
3501   h8.h8cflag = (src>>7)&1;
3502   res = src<<1;
3503   // N and Z modified
3504   h8.h8nflag = (res>>7)&1;
3505   h8.h8vflag = (src ^ res) >> 7;
3506
3507   // zflag
3508   if(res==0)
3509   {
3510      h8.h8zflag = 1;
3511   }
3512   else
3513   {
3514      h8.h8zflag = 0;
3515   }
3516
3517   return res;
3518}
3519
3520static INT16 h8_shal16(INT16 src)
3521{
3522   INT16 res;
3523
3524   h8.h8cflag = (src>>15)&1;
3525   res = src<<1;
3526   // N and Z modified
3527   h8.h8nflag = (res>>15)&1;
3528   h8.h8vflag = (src ^ res) >> 15;
3529
3530   // zflag
3531   if(res==0)
3532   {
3533      h8.h8zflag = 1;
3534   }
3535   else
3536   {
3537      h8.h8zflag = 0;
3538   }
3539
3540   return res;
3541}
3542
3543static INT32 h8_shal32(INT32 src)
3544{
3545   INT32 res;
3546
3547   h8.h8cflag = (src>>31)&1;
3548   res = src<<1;
3549   // N and Z modified
3550   h8.h8nflag = (res>>31)&1;
3551   h8.h8vflag = (src ^ res) >> 31;
3552
3553   // zflag
3554   if(res==0)
3555   {
3556      h8.h8zflag = 1;
3557   }
3558   else
3559   {
3560      h8.h8zflag = 0;
3561   }
3562
3563   return res;
3564}
3565
3566static UINT8 h8_dec8(UINT8 src)
3567{
3568   UINT8 res;
3569
3570   res = src - 1;
3571   // N and Z modified
3572   h8.h8nflag = (res>>7)&1;
3573   if(src == 0x80)
3574   {
3575      h8.h8vflag = 1;
3576   }
3577   else
3578   {
3579      h8.h8vflag = 0;
3580   }
3581
3582   // zflag
3583   if(res==0)
3584   {
3585      h8.h8zflag = 1;
3586   }
3587   else
3588   {
3589      h8.h8zflag = 0;
3590   }
3591
3592   return res;
3593}
3594
3595static UINT16 h8_dec16(UINT16 src)
3596{
3597   UINT16 res;
3598
3599   res = src - 1;
3600   // N and Z modified
3601   h8.h8nflag = (res>>15)&1;
3602   if(src == 0x8000)
3603   {
3604      h8.h8vflag = 1;
3605   }
3606   else
3607   {
3608      h8.h8vflag = 0;
3609   }
3610
3611   // zflag
3612   if(res==0)
3613   {
3614      h8.h8zflag = 1;
3615   }
3616   else
3617   {
3618      h8.h8zflag = 0;
3619   }
3620
3621   return res;
3622}
3623
3624static UINT32 h8_dec32(UINT32 src)
3625{
3626   UINT32 res;
3627
3628   res = src - 1;
3629   // N and Z modified
3630   h8.h8nflag = (res>>31)&1;
3631   if(src == 0x80000000)
3632   {
3633      h8.h8vflag = 1;
3634   }
3635   else
3636   {
3637      h8.h8vflag = 0;
3638   }
3639
3640   // zflag
3641   if(res==0)
3642   {
3643      h8.h8zflag = 1;
3644   }
3645   else
3646   {
3647      h8.h8zflag = 0;
3648   }
3649
3650   return res;
3651}
3652
3653static UINT8 h8_inc8(UINT8 src)
3654{
3655   UINT8 res;
3656
3657   res = src + 1;
3658   // N and Z modified
3659   h8.h8nflag = (res>>7)&1;
3660   if(src == 0x7f)
3661   {
3662      h8.h8vflag = 1;
3663   }
3664   else
3665   {
3666      h8.h8vflag = 0;
3667   }
3668
3669   // zflag
3670   if(res==0)
3671   {
3672      h8.h8zflag = 1;
3673   }
3674   else
3675   {
3676      h8.h8zflag = 0;
3677   }
3678
3679   return res;
3680}
3681
3682static UINT16 h8_inc16(UINT16 src)
3683{
3684   UINT16 res;
3685
3686   res = src + 1;
3687   // N and Z modified
3688   h8.h8nflag = (res>>15)&1;
3689   if(src == 0x7fff)
3690   {
3691      h8.h8vflag = 1;
3692   }
3693   else
3694   {
3695      h8.h8vflag = 0;
3696   }
3697
3698   // zflag
3699   if(res==0)
3700   {
3701      h8.h8zflag = 1;
3702   }
3703   else
3704   {
3705      h8.h8zflag = 0;
3706   }
3707
3708   return res;
3709}
3710
3711static UINT32 h8_inc32(UINT32 src)
3712{
3713   UINT32 res;
3714
3715   res = src + 1;
3716   // N and Z modified
3717   h8.h8nflag = (res>>31)&1;
3718   if(src == 0x7fffffff)
3719   {
3720      h8.h8vflag = 1;
3721   }
3722   else
3723   {
3724      h8.h8vflag = 0;
3725   }
3726
3727   // zflag
3728   if(res==0)
3729   {
3730      h8.h8zflag = 1;
3731   }
3732   else
3733   {
3734      h8.h8zflag = 0;
3735   }
3736
3737   return res;
3738}
3739
3740static INT32 h8_mulxs16(INT16 src, INT16 dst)
3741{
3742   INT32 res;
3743
3744   res = (INT32)src * dst;
3745
3746   // N and Z modified
3747   h8.h8nflag = (res>>31)&1;
3748   // zflag
3749   if(res==0)
3750   {
3751      h8.h8zflag = 1;
3752   }
3753   else
3754   {
3755      h8.h8zflag = 0;
3756   }
3757   return res;
3758}
3759
3760static UINT32 h8_divxs16(INT16 src, INT32 dst)
3761{
3762   // NOT tested !
3763   UINT32 res,r1,r2;
3764   INT16 remainder, quotient;
3765
3766   if(src!=0)
3767   {
3768      quotient = dst/src;
3769      h8.h8zflag = 0;
3770   }
3771   else
3772   {
3773      quotient = 0;
3774      h8.h8zflag = 1;
3775   }
3776   remainder = dst%src;
3777
3778   r1=*(&quotient);
3779   r2=*(&remainder);
3780   res=(r2<<16)|r1;
3781
3782   h8.h8nflag = (quotient<0)?1:0;
3783
3784   return res;
3785
3786}
3787
3788static UINT16 h8_divxu8(UINT16 dst, UINT8 src)
3789{
3790   UINT8 remainder, quotient;
3791   UINT16 res = 0;
3792   // N and Z modified
3793   h8.h8nflag = (src>>7)&1;
3794   // zflag
3795   if(src==0)
3796   {
3797      h8.h8zflag = 1;
3798      // dont do anything on division by zero !
3799   }
3800   else
3801   {
3802      h8.h8zflag = 0;
3803      quotient = dst / src;
3804      remainder = dst % src;
3805      res = (remainder << 8) | quotient;
3806   }
3807   return res;
3808}
3809
3810static UINT32 h8_divxu16(UINT32 dst, UINT16 src)
3811{
3812   UINT16 remainder, quotient;
3813   UINT32 res = 0;
3814   // N and Z modified
3815   h8.h8nflag = (src>>15)&1;
3816   // zflag
3817   if(src==0)
3818   {
3819      h8.h8zflag = 1;
3820      // dont do anything on division by zero !
3821   }
3822   else
3823   {
3824      h8.h8zflag = 0;
3825      quotient = dst / src;
3826      remainder = dst % src;
3827      res = (remainder << 16) | quotient;
3828   }
3829   return res;
3830}
3831
3832// input: branch condition
3833// output: 1 if condition met, 0 if not condition met
3834static int h8_branch(UINT8 condition)
3835{
3836   int taken = 0;
3837
3838   // a branch always eats 2 ifetch states, regardless of if it's taken
3839   H8_IFETCH_TIMING(2)
3840
3841   switch(condition)
3842   {
3843   case 0: // bt
3844      taken = 1;
3845      break;
3846   case 1: // bf
3847      break;
3848   case 2: // bhi (C | Z) == 0)
3849      if((h8.h8cflag | h8.h8zflag) == 0)taken = 1;
3850      break;
3851   case 3: // bls
3852      if((h8.h8cflag | h8.h8zflag) == 1)taken = 1;
3853      break;
3854   case 4: // bcc C = 0
3855      if(h8.h8cflag == 0)taken = 1;
3856      break;
3857   case 5: // bcs C = 1
3858      if(h8.h8cflag == 1)taken = 1;
3859      break;
3860   case 6: // bne Z = 0
3861      if(h8.h8zflag == 0)taken = 1;
3862      break;
3863   case 7: // beq Z = 1
3864      if(h8.h8zflag == 1)taken = 1;
3865      break;
3866   case 8: // bvc V = 0
3867      h8.h8err = 1;
3868      if(h8.h8vflag == 0)taken = 1;
3869      break;
3870   case 9: // bvs V = 1
3871      h8.h8err = 1;
3872      if(h8.h8vflag == 1)taken = 1;
3873      break;
3874   case 0xa: // bpl N = 0
3875      if(h8.h8nflag == 0)taken = 1;
3876      break;
3877   case 0xb: // bmi N = 1
3878      if(h8.h8nflag == 1)taken = 1;
3879      break;
3880   case 0xc: // bge (N ^ V) = 0
3881      if((h8.h8nflag ^ h8.h8vflag) == 0)taken = 1;
3882      break;
3883   case 0xd: // blt (N ^ V) = 1
3884      if((h8.h8nflag ^ h8.h8vflag) == 1)taken = 1;
3885      break;
3886   case 0xe: // bgt (Z | (N ^ V)) = 0
3887      if((h8.h8zflag | (h8.h8nflag ^ h8.h8vflag)) == 0)taken = 1;
3888      break;
3889   case 0xf: // ble (Z | (N ^ V)) = 1
3890      if((h8.h8zflag | (h8.h8nflag ^ h8.h8vflag)) == 1)taken = 1;
3891      break;
3892   }
3893   return taken;
3894}
3895
3896// MAME interface stuff
3897
3898static CPU_GET_CONTEXT( h8 )
3899{
3900   *(h83002_state *)dst = h8;
3901}
3902
3903static CPU_SET_CONTEXT( h8 )
3904{
3905   h8 = *(h83002_state *)src;
3906}
3907
3908static CPU_SET_INFO( h8 )
3909{
3910   switch(state) {
3911   case CPUINFO_INT_PC:                  h8.pc = info->i; change_pc(h8.pc);            break;
3912   case CPUINFO_INT_REGISTER + H8_PC:         h8.pc = info->i; change_pc(h8.pc);            break;
3913   case CPUINFO_INT_REGISTER + H8_CCR:         h8_set_ccr(info->i);                     break;
3914
3915   case CPUINFO_INT_REGISTER + H8_E0:         h8.regs[0] = info->i;                     break;
3916   case CPUINFO_INT_REGISTER + H8_E1:         h8.regs[1] = info->i;                     break;
3917   case CPUINFO_INT_REGISTER + H8_E2:         h8.regs[2] = info->i;                     break;
3918   case CPUINFO_INT_REGISTER + H8_E3:         h8.regs[3] = info->i;                     break;
3919   case CPUINFO_INT_REGISTER + H8_E4:         h8.regs[4] = info->i;                     break;
3920   case CPUINFO_INT_REGISTER + H8_E5:         h8.regs[5] = info->i;                     break;
3921   case CPUINFO_INT_REGISTER + H8_E6:         h8.regs[6] = info->i;                     break;
3922   case CPUINFO_INT_REGISTER + H8_E7:         h8.regs[7] = info->i;                     break;
3923
3924   case CPUINFO_INT_INPUT_STATE + H8_IRQ0:      if (info->i) h8_3002_InterruptRequest(12);      break;
3925   case CPUINFO_INT_INPUT_STATE + H8_IRQ1:      if (info->i) h8_3002_InterruptRequest(13);      break;
3926   case CPUINFO_INT_INPUT_STATE + H8_IRQ2:      if (info->i) h8_3002_InterruptRequest(14);      break;
3927   case CPUINFO_INT_INPUT_STATE + H8_IRQ3:      if (info->i) h8_3002_InterruptRequest(15);      break;
3928   case CPUINFO_INT_INPUT_STATE + H8_IRQ4:      if (info->i) h8_3002_InterruptRequest(16);      break;
3929   case CPUINFO_INT_INPUT_STATE + H8_IRQ5:      if (info->i) h8_3002_InterruptRequest(17);      break;
3930
3931   default:
3932      fatalerror("h8_set_info unknown request %x", state);
3933      break;
3934   }
3935}
3936
3937static READ16_HANDLER( h8_itu_r )
3938{
3939   if (mem_mask == 0xffff)
3940   {
3941      // 16-bit read
3942      return h8_register_read8(offset*2 + 0xffff10)<<8 | h8_register_read8((offset*2) + 1 + 0xffff10);
3943   }
3944   else if (mem_mask == 0xff00)
3945   {
3946      return h8_register_read8(offset*2 + 0xffff10)<<8;
3947   }
3948   else if (mem_mask == 0x00ff)
3949   {
3950      return h8_register_read8((offset*2) + 1 + 0xffff10);
3951   }
3952
3953   return 0;
3954}
3955
3956static WRITE16_HANDLER( h8_itu_w )
3957{
3958   if (mem_mask == 0xffff)
3959   {
3960      // 16-bit write
3961      h8_register_write8(offset*2 + 0xffff10, data>>8);
3962      h8_register_write8((offset*2) + 1 + 0xffff10, data&0xff);
3963   }
3964   else if (mem_mask == 0xff00)
3965   {
3966      h8_register_write8(offset*2 + 0xffff10, data>>8);
3967   }
3968   else if (mem_mask == 0x00ff)
3969   {
3970      h8_register_write8((offset*2) + 1 + 0xffff10, data&0xff);
3971   }
3972}
3973
3974static READ16_HANDLER( h8_3007_itu_r )
3975{
3976   if (mem_mask == 0xffff)
3977   {
3978      // 16-bit read
3979      return h8_3007_register_read8(offset*2 + 0xffff20)<<8 | h8_3007_register_read8((offset*2) + 1 + 0xffff20);
3980   }
3981   else if (mem_mask == 0xff00)
3982   {
3983      return h8_3007_register_read8(offset*2 + 0xffff20)<<8;
3984   }
3985   else if (mem_mask == 0x00ff)
3986   {
3987      return h8_3007_register_read8((offset*2) + 1 + 0xffff20);
3988   }
3989
3990   return 0;
3991}
3992static WRITE16_HANDLER( h8_3007_itu_w )
3993{
3994   if (mem_mask == 0xffff)
3995   {
3996      // 16-bit write
3997      h8_3007_register_write8(offset*2 + 0xffff20, data>>8);
3998      h8_3007_register_write8((offset*2) + 1 + 0xffff20, data&0xff);
3999   }
4000   else if (mem_mask == 0xff00)
4001   {
4002      h8_3007_register_write8(offset*2 + 0xffff20, data>>8);
4003   }
4004   else if (mem_mask == 0x00ff)
4005   {
4006      h8_3007_register_write8((offset*2) + 1 + 0xffff20, data&0xff);
4007   }
4008}
4009
4010static READ16_HANDLER( h8_3007_itu1_r )
4011{
4012   if (mem_mask == 0xffff)
4013   {
4014      // 16-bit read
4015      return h8_3007_register1_read8(offset*2 + 0xfee000)<<8 | h8_3007_register1_read8((offset*2) + 1 + 0xfee000);
4016   }
4017   else if (mem_mask == 0xff00)
4018   {
4019      return h8_3007_register1_read8(offset*2 + 0xfee000)<<8;
4020   }
4021   else if (mem_mask == 0x00ff)
4022   {
4023      return h8_3007_register1_read8((offset*2) + 1 + 0xfee000);
4024   }
4025
4026   return 0;
4027}
4028static WRITE16_HANDLER( h8_3007_itu1_w )
4029{
4030   if (mem_mask == 0xffff)
4031   {
4032      // 16-bit write
4033      h8_3007_register1_write8(offset*2 + 0xfee000, data>>8);
4034      h8_3007_register1_write8((offset*2) + 1 + 0xfee000, data&0xff);
4035   }
4036   else if (mem_mask == 0xff00)
4037   {
4038      h8_3007_register1_write8(offset*2 + 0xfee000, data>>8);
4039   }
4040   else if (mem_mask == 0x00ff)
4041   {
4042      h8_3007_register1_write8((offset*2) + 1 + 0xfee000, data&0xff);
4043   }
4044}
4045
4046// On-board RAM and peripherals
4047static ADDRESS_MAP_START( h8_3002_internal_map, ADDRESS_SPACE_PROGRAM, 16 )
4048   // 512B RAM
4049   AM_RANGE(0xfffd10, 0xffff0f) AM_RAM
4050   AM_RANGE(0xffff10, 0xffffff) AM_READWRITE( h8_itu_r, h8_itu_w )
4051ADDRESS_MAP_END
4052
4053static ADDRESS_MAP_START( h8_3044_internal_map, ADDRESS_SPACE_PROGRAM, 16 )
4054   // 32k ROM, 2k RAM
4055   AM_RANGE(0xfff710, 0xffff0f) AM_RAM
4056   AM_RANGE(0xffff1c, 0xffffff) AM_READWRITE( h8_itu_r, h8_itu_w )
4057ADDRESS_MAP_END
4058
4059static ADDRESS_MAP_START( h8_3007_internal_map, ADDRESS_SPACE_PROGRAM, 16 )
4060   // ROM-less, 4k RAM
4061   AM_RANGE(0xfee000, 0xfee0ff) AM_READWRITE( h8_3007_itu1_r, h8_3007_itu1_w )
4062   AM_RANGE(0xffef20, 0xffff1f) AM_RAM
4063   AM_RANGE(0xffff20, 0xffffe9) AM_READWRITE( h8_3007_itu_r, h8_3007_itu_w )
4064ADDRESS_MAP_END
4065
4066
4067CPU_GET_INFO( h8_3002 )
4068{
4069   switch(state) {
4070   // Interface functions and variables
4071   case CPUINFO_PTR_SET_INFO:               info->setinfo     = CPU_SET_INFO_NAME(h8);      break;
4072   case CPUINFO_PTR_GET_CONTEXT:            info->getcontext  = CPU_GET_CONTEXT_NAME(h8);   break;
4073   case CPUINFO_PTR_SET_CONTEXT:            info->setcontext  = CPU_SET_CONTEXT_NAME(h8);   break;
4074   case CPUINFO_PTR_INIT:                  info->init        = CPU_INIT_NAME(h8);         break;
4075   case CPUINFO_PTR_RESET:                  info->reset       = CPU_RESET_NAME(h8);         break;
4076   case CPUINFO_PTR_EXIT:                  info->exit        = 0;                     break;
4077   case CPUINFO_PTR_EXECUTE:               info->execute     = CPU_EXECUTE_NAME(h8);      break;
4078   case CPUINFO_PTR_BURN:                  info->burn        = 0;                     break;
4079   case CPUINFO_PTR_DISASSEMBLE:            info->disassemble = CPU_DISASSEMBLE_NAME(h8);   break;
4080   case CPUINFO_PTR_INSTRUCTION_COUNTER:      info->icount      = &h8_cyccnt;               break;
4081   case CPUINFO_INT_CONTEXT_SIZE:            info->i           = sizeof(h83002_state);      break;
4082   case CPUINFO_INT_MIN_INSTRUCTION_BYTES:      info->i           = 2;                     break;
4083   case CPUINFO_INT_MAX_INSTRUCTION_BYTES:      info->i           = 10;                     break;
4084
4085      // Bus sizes
4086   case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_PROGRAM:   info->i = 16;                  break;
4087   case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_PROGRAM:   info->i = 24;                  break;
4088   case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_PROGRAM:   info->i = 0;                  break;
4089   case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_DATA:   info->i = 0;                  break;
4090   case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_DATA:   info->i = 0;                  break;
4091   case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_DATA:   info->i = 0;                  break;
4092   case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_IO:      info->i = 8;                  break;
4093   case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_IO:      info->i = 16;                  break;
4094   case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_IO:      info->i = 0;                  break;
4095
4096      // Internal maps
4097   case CPUINFO_PTR_INTERNAL_MEMORY_MAP + ADDRESS_SPACE_PROGRAM: info->internal_map16 = ADDRESS_MAP_NAME(h8_3002_internal_map); break;
4098   case CPUINFO_PTR_INTERNAL_MEMORY_MAP + ADDRESS_SPACE_DATA:    info->internal_map16 = NULL;   break;
4099   case CPUINFO_PTR_INTERNAL_MEMORY_MAP + ADDRESS_SPACE_IO:      info->internal_map16 = NULL;   break;
4100
4101      // CPU misc parameters
4102   case CPUINFO_STR_NAME:                  strcpy(info->s, "H8/3002");                  break;
4103   case CPUINFO_STR_CORE_FILE:               strcpy(info->s, __FILE__);                  break;
4104   case CPUINFO_STR_FLAGS:                  strcpy(info->s, h8_get_ccr_str());            break;
4105   case CPUINFO_INT_ENDIANNESS:            info->i = CPU_IS_BE;                     break;
4106   case CPUINFO_INT_CLOCK_MULTIPLIER:         info->i = 1;                           break;
4107   case CPUINFO_INT_CLOCK_DIVIDER:            info->i = 1;                           break;
4108   case CPUINFO_INT_INPUT_LINES:            info->i = 16;                           break;
4109   case CPUINFO_INT_DEFAULT_IRQ_VECTOR:      info->i = -1;                           break;
4110
4111      // CPU main state
4112   case CPUINFO_INT_PC:                  info->i = h8.pc;                        break;
4113   case CPUINFO_INT_PREVIOUSPC:            info->i = h8.ppc;                        break;
4114
4115   case CPUINFO_INT_REGISTER + H8_PC:         info->i = h8.pc;                        break;
4116   case CPUINFO_INT_REGISTER + H8_CCR:         info->i = h8_get_ccr();                     break;
4117
4118   case CPUINFO_INT_REGISTER + H8_E0:         info->i = h8.regs[0];                     break;
4119   case CPUINFO_INT_REGISTER + H8_E1:         info->i = h8.regs[1];                     break;
4120   case CPUINFO_INT_REGISTER + H8_E2:         info->i = h8.regs[2];                     break;
4121   case CPUINFO_INT_REGISTER + H8_E3:         info->i = h8.regs[3];                     break;
4122   case CPUINFO_INT_REGISTER + H8_E4:         info->i = h8.regs[4];                     break;
4123   case CPUINFO_INT_REGISTER + H8_E5:         info->i = h8.regs[5];                     break;
4124   case CPUINFO_INT_REGISTER + H8_E6:         info->i = h8.regs[6];                     break;
4125   case CPUINFO_INT_REGISTER + H8_E7:         info->i = h8.regs[7];                     break;
4126
4127   // CPU debug stuff
4128   case CPUINFO_STR_REGISTER + H8_PC:         sprintf(info->s, "PC   :%08x", h8.pc);         break;
4129   case CPUINFO_STR_REGISTER + H8_CCR:         sprintf(info->s, "CCR  :%08x", h8_get_ccr());   break;
4130
4131   case CPUINFO_STR_REGISTER + H8_E0:         sprintf(info->s, "ER0  :%08x", h8.regs[0]);      break;
4132   case CPUINFO_STR_REGISTER + H8_E1:         sprintf(info->s, "ER1  :%08x", h8.regs[1]);      break;
4133   case CPUINFO_STR_REGISTER + H8_E2:         sprintf(info->s, "ER2  :%08x", h8.regs[2]);      break;
4134   case CPUINFO_STR_REGISTER + H8_E3:         sprintf(info->s, "ER3  :%08x", h8.regs[3]);      break;
4135   case CPUINFO_STR_REGISTER + H8_E4:         sprintf(info->s, "ER4  :%08x", h8.regs[4]);      break;
4136   case CPUINFO_STR_REGISTER + H8_E5:         sprintf(info->s, "ER5  :%08x", h8.regs[5]);      break;
4137   case CPUINFO_STR_REGISTER + H8_E6:         sprintf(info->s, "ER6  :%08x", h8.regs[6]);      break;
4138   case CPUINFO_STR_REGISTER + H8_E7:         sprintf(info->s, " SP  :%08x", h8.regs[7]);      break;
4139   }
4140}
4141
4142CPU_GET_INFO( h8_3044 )
4143{
4144   switch (state)
4145   {
4146      case CPUINFO_PTR_INTERNAL_MEMORY_MAP + ADDRESS_SPACE_PROGRAM: info->internal_map16 = ADDRESS_MAP_NAME(h8_3044_internal_map);  break;
4147      case CPUINFO_STR_NAME:            strcpy(info->s, "H8/3044");    break;
4148      default:
4149         CPU_GET_INFO_CALL(h8_3002);
4150   }
4151}
4152
4153CPU_GET_INFO( h8_3007 )
4154{
4155   switch (state)
4156   {
4157      case CPUINFO_PTR_INTERNAL_MEMORY_MAP + ADDRESS_SPACE_PROGRAM: info->internal_map16 = address_map_h8_3007_internal_map;  break;
4158      case CPUINFO_PTR_INIT:            info->init = CPU_INIT_NAME(h8_3007);      break;
4159      case CPUINFO_STR_NAME:            strcpy(info->s, "H8/3007");      break;
4160      default:
4161         CPU_GET_INFO_CALL(h8_3002);
4162   }
4163}
src/emu/cpu/h83002/h83002.h
r3767r3768
1/***************************************************************************
2
3 h83002.h : Public constants and function defs for the H8/3002 emulator.
4
5****************************************************************************/
6
7#pragma once
8
9#ifndef __H83002_H__
10#define __H83002_H__
11
12#include "cpuintrf.h"
13
14#define IFLAG  0x80
15#define UIFLAG 0x40
16#define HFLAG  0x20
17#define UFLAG  0x10
18#define NFLAG  0x08
19#define ZFLAG  0x04
20#define VFLAG  0x02
21#define CFLAG  0x01
22
23enum
24{
25   H8_E0 = 1,
26   H8_E1,
27   H8_E2,
28   H8_E3,
29   H8_E4,
30   H8_E5,
31   H8_E6,
32   H8_E7,
33
34   H8_PC,
35   H8_CCR
36};
37
38// external interrupt lines
39enum
40{
41   H8_IRQ0 = 0,
42   H8_IRQ1,
43   H8_IRQ2,
44   H8_IRQ3,
45   H8_IRQ4,
46   H8_IRQ5
47};
48
49// I/O ports
50enum
51{
52   // digital I/O ports
53   H8_PORT4 = 0,   // 0
54   H8_PORT6,   // 1
55   H8_PORT7,   // 2
56   H8_PORT8,   // 3
57   H8_PORT9,   // 4
58   H8_PORTA,   // 5
59   H8_PORTB,   // 6
60
61   // analog inputs
62   H8_ADC_0_H = 0x10,
63   H8_ADC_0_L,
64   H8_ADC_1_H,
65   H8_ADC_1_L,
66   H8_ADC_2_H,
67   H8_ADC_2_L,
68   H8_ADC_3_H,
69   H8_ADC_3_L,
70
71   // serial ports
72   H8_SERIAL_A = 0x20,
73   H8_SERIAL_B
74};
75
76CPU_GET_INFO( h8_3002 );
77
78void h8_3002_InterruptRequest(UINT8 source);
79
80#endif /* __H83002_H__ */
src/emu/cpu/m68000/m68kmame.c
r3767r3768
1#include <stdio.h>
2#include <stdlib.h>
3#include "m68kcpu.h"
4#include "m68000.h"
5
6/* global access */
7
8static void *token;
9
10m68k_memory_interface m68k_memory_intf;
11offs_t m68k_encrypted_opcode_start[MAX_CPU];
12offs_t m68k_encrypted_opcode_end[MAX_CPU];
13
14
15void m68k_set_encrypted_opcode_range(int cpunum, offs_t start, offs_t end)
16{
17   m68k_encrypted_opcode_start[cpunum] = start;
18   m68k_encrypted_opcode_end[cpunum] = end;
19}
20
21/****************************************************************************
22 * 8-bit data memory interface
23 ****************************************************************************/
24
25static UINT16 m68008_read_immediate_16(offs_t address)
26{
27   offs_t addr = address;
28   return (cpu_readop(addr) << 8) | (cpu_readop(addr + 1));
29}
30
31/* interface for 20/22-bit address bus, 8-bit data bus (68008) */
32static const m68k_memory_interface interface_d8 =
33{
34   0,
35   m68008_read_immediate_16,
36   program_read_byte_8be,
37   program_read_word_8be,
38   program_read_dword_8be,
39   program_write_byte_8be,
40   program_write_word_8be,
41   program_write_dword_8be
42};
43
44/****************************************************************************
45 * 16-bit data memory interface
46 ****************************************************************************/
47
48static UINT16 read_immediate_16(offs_t address)
49{
50   return cpu_readop16((address) ^ m68k_memory_intf.opcode_xor);
51}
52
53/* interface for 24-bit address bus, 16-bit data bus (68000, 68010) */
54static const m68k_memory_interface interface_d16 =
55{
56   0,
57   cpu_readop16,
58   program_read_byte_16be,
59   program_read_word_16be,
60   program_read_dword_16be,
61   program_write_byte_16be,
62   program_write_word_16be,
63   program_write_dword_16be
64};
65
66/****************************************************************************
67 * 32-bit data memory interface
68 ****************************************************************************/
69
70/* potentially misaligned 16-bit reads with a 32-bit data bus (and 24-bit address bus) */
71static UINT16 readword_d32(offs_t address)
72{
73   UINT16 result;
74
75   if (!(address & 1))
76      return program_read_word_32be(address);
77   result = program_read_byte_32be(address) << 8;
78   return result | program_read_byte_32be(address + 1);
79}
80
81/* potentially misaligned 16-bit writes with a 32-bit data bus (and 24-bit address bus) */
82static void writeword_d32(offs_t address, UINT16 data)
83{
84   if (!(address & 1))
85   {
86      program_write_word_32be(address, data);
87      return;
88   }
89   program_write_byte_32be(address, data >> 8);
90   program_write_byte_32be(address + 1, data);
91}
92
93/* potentially misaligned 32-bit reads with a 32-bit data bus (and 24-bit address bus) */
94static UINT32 readlong_d32(offs_t address)
95{
96   UINT32 result;
97
98   if (!(address & 3))
99      return program_read_dword_32be(address);
100   else if (!(address & 1))
101   {
102      result = program_read_word_32be(address) << 16;
103      return result | program_read_word_32be(address + 2);
104   }
105   result = program_read_byte_32be(address) << 24;
106   result |= program_read_word_32be(address + 1) << 8;
107   return result | program_read_byte_32be(address + 3);
108}
109
110/* potentially misaligned 32-bit writes with a 32-bit data bus (and 24-bit address bus) */
111static void writelong_d32(offs_t address, UINT32 data)
112{
113   if (!(address & 3))
114   {
115      program_write_dword_32be(address, data);
116      return;
117   }
118   else if (!(address & 1))
119   {
120      program_write_word_32be(address, data >> 16);
121      program_write_word_32be(address + 2, data);
122      return;
123   }
124   program_write_byte_32be(address, data >> 24);
125   program_write_word_32be(address + 1, data >> 8);
126   program_write_byte_32be(address + 3, data);
127}
128
129/* interface for 32-bit data bus (68EC020, 68020) */
130static const m68k_memory_interface interface_d32 =
131{
132   WORD_XOR_BE(0),
133   read_immediate_16,
134   program_read_byte_32be,
135   readword_d32,
136   readlong_d32,
137   program_write_byte_32be,
138   writeword_d32,
139   writelong_d32
140};
141
142
143static void set_irq_line(m68ki_cpu_core *m68k, int irqline, int state)
144{
145   if (irqline == INPUT_LINE_NMI)
146      irqline = 7;
147
148   m68k_set_virq(m68k, irqline, state == ASSERT_LINE ? 1 : 0);
149}
150
151
152/****************************************************************************
153 * 68000 section
154 ****************************************************************************/
155
156static CPU_INIT( m68000 )
157{
158   m68ki_cpu_core *m68k = device->token;
159   token = device->token;   // temporary
160   m68k_init(m68k);
161   m68k_set_cpu_type(m68k, M68K_CPU_TYPE_68000);
162   m68k_memory_intf = interface_d16;
163   m68k_state_register(m68k, "m68000", index);
164   m68k_set_int_ack_callback(m68k, (void *)device, (int (*)(void *param, int int_level)) irqcallback);
165}
166
167static CPU_RESET( m68000 )
168{
169   m68k_pulse_reset(device->token);
170}
171
172static CPU_EXIT( m68000 )
173{
174   /* nothing to do */
175}
176
177static CPU_EXECUTE( m68000 )
178{
179   return m68k_execute(device->token, cycles);
180}
181
182static CPU_GET_CONTEXT( m68000 )
183{
184}
185
186static CPU_SET_CONTEXT( m68000 )
187{
188   if (m68k_memory_intf.read8 != program_read_byte_16be)
189      m68k_memory_intf = interface_d16;
190   token = src;
191}
192
193static CPU_DISASSEMBLE( m68000 )
194{
195   return m68k_disassemble_raw(buffer, pc, oprom, opram, M68K_CPU_TYPE_68000);
196}
197
198/****************************************************************************
199 * M68008 section
200 ****************************************************************************/
201#if HAS_M68008
202
203static CPU_INIT( m68008 )
204{
205   m68ki_cpu_core *m68k = device->token;
206   token = device->token;   // temporary
207   m68k_init(m68k);
208   m68k_set_cpu_type(m68k, M68K_CPU_TYPE_68008);
209   m68k_memory_intf = interface_d8;
210   m68k_state_register(m68k, "m68008", index);
211   m68k_set_int_ack_callback(m68k, (void *)device, (int (*)(void *param, int int_level)) irqcallback);
212}
213
214static CPU_RESET( m68008 )
215{
216   m68k_pulse_reset(device->token);
217}
218
219static CPU_EXIT( m68008 )
220{
221   /* nothing to do */
222}
223
224static CPU_EXECUTE( m68008 )
225{
226   return m68k_execute(device->token, cycles);
227}
228
229static CPU_GET_CONTEXT( m68008 )
230{
231}
232
233static CPU_SET_CONTEXT( m68008 )
234{
235   if (m68k_memory_intf.read8 != program_read_byte_8be)
236      m68k_memory_intf = interface_d8;
237   token = src;
238}
239
240static CPU_DISASSEMBLE( m68008 )
241{
242   return m68k_disassemble_raw(buffer, pc, oprom, opram, M68K_CPU_TYPE_68008);
243}
244
245#endif /* HAS_M68008 */
246
247/****************************************************************************
248 * M68010 section
249 ****************************************************************************/
250#if HAS_M68010
251
252static CPU_INIT( m68010 )
253{
254   m68ki_cpu_core *m68k = device->token;
255   token = device->token;   // temporary
256   m68k_init(m68k);
257   m68k_set_cpu_type(m68k, M68K_CPU_TYPE_68010);
258   m68k_memory_intf = interface_d16;
259   m68k_state_register(m68k, "m68010", index);
260   m68k_set_int_ack_callback(m68k, (void *)device, (int (*)(void *param, int int_level)) irqcallback);
261}
262
263static CPU_DISASSEMBLE( m68010 )
264{
265   return m68k_disassemble_raw(buffer, pc, oprom, opram, M68K_CPU_TYPE_68010);
266}
267
268#endif /* HAS_M68010 */
269
270/****************************************************************************
271 * M68020 section
272 ****************************************************************************/
273
274static CPU_INIT( m68020 )
275{
276   m68ki_cpu_core *m68k = device->token;
277   token = device->token;   // temporary
278   m68k_init(m68k);
279   m68k_set_cpu_type(m68k, M68K_CPU_TYPE_68020);
280   m68k_memory_intf = interface_d32;
281   m68k_state_register(m68k, "m68020", index);
282   m68k_set_int_ack_callback(m68k, (void *)device, (int (*)(void *param, int int_level)) irqcallback);
283}
284
285static CPU_RESET( m68020 )
286{
287   m68k_pulse_reset(device->token);
288}
289
290static CPU_EXIT( m68020 )
291{
292   /* nothing to do */
293}
294
295static CPU_EXECUTE( m68020 )
296{
297   return m68k_execute(device->token, cycles);
298}
299
300static CPU_GET_CONTEXT( m68020 )
301{
302}
303
304static CPU_SET_CONTEXT( m68020 )
305{
306   if (m68k_memory_intf.read8 != program_read_byte_32be)
307      m68k_memory_intf = interface_d32;
308   token = src;
309}
310
311static CPU_DISASSEMBLE( m68020 )
312{
313   return m68k_disassemble_raw(buffer, pc, oprom, opram, M68K_CPU_TYPE_68020);
314}
315
316
317/****************************************************************************
318 * M680EC20 section
319 ****************************************************************************/
320#if HAS_M68EC020
321
322static CPU_INIT( m68ec020 )
323{
324   m68ki_cpu_core *m68k = device->token;
325   token = device->token;   // temporary
326   m68k_init(m68k);
327   m68k_set_cpu_type(m68k, M68K_CPU_TYPE_68EC020);
328   m68k_memory_intf = interface_d32;
329   m68k_state_register(m68k, "m68ec020", index);
330   m68k_set_int_ack_callback(m68k, (void *)device, (int (*)(void *param, int int_level)) irqcallback);
331}
332
333static CPU_DISASSEMBLE( m68ec020 )
334{
335   return m68k_disassemble_raw(buffer, pc, oprom, opram, M68K_CPU_TYPE_68EC020);
336}
337
338#endif /* HAS_M68EC020 */
339
340/****************************************************************************
341 * M68040 section
342 ****************************************************************************/
343#if HAS_M68040
344
345static CPU_INIT( m68040 )
346{
347   m68ki_cpu_core *m68k = device->token;
348   token = device->token;   // temporary
349   m68k_init(m68k);
350   m68k_set_cpu_type(m68k, M68K_CPU_TYPE_68040);
351   m68k_memory_intf = interface_d32;
352   m68k_state_register(m68k, "m68040", index);
353   m68k_set_int_ack_callback(m68k, (void *)device, (int (*)(void *param, int int_level)) irqcallback);
354}
355
356static CPU_RESET( m68040 )
357{
358   m68k_pulse_reset(device->token);
359}
360
361static CPU_EXIT( m68040 )
362{
363   /* nothing to do */
364}
365
366static CPU_EXECUTE( m68040 )
367{
368   return m68k_execute(device->token, cycles);
369}
370
371static CPU_GET_CONTEXT( m68040 )
372{
373}
374
375static CPU_SET_CONTEXT( m68040 )
376{
377   if (m68k_memory_intf.read8 != program_read_byte_32be)
378      m68k_memory_intf = interface_d32;
379   token = src;
380}
381
382static CPU_DISASSEMBLE( m68040 )
383{
384   return m68k_disassemble_raw(buffer, pc, oprom, opram, M68K_CPU_TYPE_68040);
385}
386
387#endif /* HAS_M68040 */
388
389/**************************************************************************
390 * Generic set_info
391 **************************************************************************/
392
393static CPU_SET_INFO( m68000 )
394{
395   m68ki_cpu_core *m68k = token;
396   switch (state)
397   {
398      /* --- the following bits of info are set as 64-bit signed integers --- */
399      case CPUINFO_INT_INPUT_STATE + 0:         set_irq_line(m68k, 0, info->i);               break;
400      case CPUINFO_INT_INPUT_STATE + 1:         set_irq_line(m68k, 1, info->i);               break;
401      case CPUINFO_INT_INPUT_STATE + 2:         set_irq_line(m68k, 2, info->i);               break;
402      case CPUINFO_INT_INPUT_STATE + 3:         set_irq_line(m68k, 3, info->i);               break;
403      case CPUINFO_INT_INPUT_STATE + 4:         set_irq_line(m68k, 4, info->i);               break;
404      case CPUINFO_INT_INPUT_STATE + 5:         set_irq_line(m68k, 5, info->i);               break;
405      case CPUINFO_INT_INPUT_STATE + 6:         set_irq_line(m68k, 6, info->i);               break;
406      case CPUINFO_INT_INPUT_STATE + 7:         set_irq_line(m68k, 7, info->i);               break;
407
408      case CPUINFO_INT_PC:                    m68k_set_reg(m68k, M68K_REG_PC, info->i&0x00ffffff); break;
409      case CPUINFO_INT_REGISTER + M68K_PC:        m68k_set_reg(m68k, M68K_REG_PC, info->i);         break;
410      case CPUINFO_INT_SP:
411      case CPUINFO_INT_REGISTER + M68K_SP:        m68k_set_reg(m68k, M68K_REG_SP, info->i);         break;
412      case CPUINFO_INT_REGISTER + M68K_ISP:       m68k_set_reg(m68k, M68K_REG_ISP, info->i);      break;
413      case CPUINFO_INT_REGISTER + M68K_USP:       m68k_set_reg(m68k, M68K_REG_USP, info->i);      break;
414      case CPUINFO_INT_REGISTER + M68K_SR:        m68k_set_reg(m68k, M68K_REG_SR, info->i);         break;
415      case CPUINFO_INT_REGISTER + M68K_D0:        m68k_set_reg(m68k, M68K_REG_D0, info->i);         break;
416      case CPUINFO_INT_REGISTER + M68K_D1:        m68k_set_reg(m68k, M68K_REG_D1, info->i);         break;
417      case CPUINFO_INT_REGISTER + M68K_D2:        m68k_set_reg(m68k, M68K_REG_D2, info->i);         break;
418      case CPUINFO_INT_REGISTER + M68K_D3:        m68k_set_reg(m68k, M68K_REG_D3, info->i);         break;
419      case CPUINFO_INT_REGISTER + M68K_D4:        m68k_set_reg(m68k, M68K_REG_D4, info->i);         break;
420      case CPUINFO_INT_REGISTER + M68K_D5:        m68k_set_reg(m68k, M68K_REG_D5, info->i);         break;
421      case CPUINFO_INT_REGISTER + M68K_D6:        m68k_set_reg(m68k, M68K_REG_D6, info->i);         break;
422      case CPUINFO_INT_REGISTER + M68K_D7:        m68k_set_reg(m68k, M68K_REG_D7, info->i);         break;
423      case CPUINFO_INT_REGISTER + M68K_A0:        m68k_set_reg(m68k, M68K_REG_A0, info->i);         break;
424      case CPUINFO_INT_REGISTER + M68K_A1:        m68k_set_reg(m68k, M68K_REG_A1, info->i);         break;
425      case CPUINFO_INT_REGISTER + M68K_A2:        m68k_set_reg(m68k, M68K_REG_A2, info->i);         break;
426      case CPUINFO_INT_REGISTER + M68K_A3:        m68k_set_reg(m68k, M68K_REG_A3, info->i);         break;
427      case CPUINFO_INT_REGISTER + M68K_A4:        m68k_set_reg(m68k, M68K_REG_A4, info->i);         break;
428      case CPUINFO_INT_REGISTER + M68K_A5:        m68k_set_reg(m68k, M68K_REG_A5, info->i);         break;
429      case CPUINFO_INT_REGISTER + M68K_A6:        m68k_set_reg(m68k, M68K_REG_A6, info->i);         break;
430      case CPUINFO_INT_REGISTER + M68K_A7:        m68k_set_reg(m68k, M68K_REG_A7, info->i);         break;
431      case CPUINFO_INT_REGISTER + M68K_PREF_ADDR:   m68k_set_reg(m68k, M68K_REG_PREF_ADDR, info->i);   break;
432
433      /* --- the following bits of info are set as pointers to data or functions --- */
434      case CPUINFO_PTR_M68K_RESET_CALLBACK:      m68k_set_reset_instr_callback(m68k, info->f);      break;
435      case CPUINFO_PTR_M68K_CMPILD_CALLBACK:      m68k_set_cmpild_instr_callback(m68k, (void (*)(unsigned int,int))(info->f)); break;
436      case CPUINFO_PTR_M68K_RTE_CALLBACK:         m68k_set_rte_instr_callback(m68k, info->f);      break;
437      case CPUINFO_PTR_M68K_TAS_CALLBACK:         m68k_set_tas_instr_callback(m68k, (int (*)(void))(info->f)); break;
438   }
439}
440
441/**************************************************************************
442 * Generic get_info
443 **************************************************************************/
444
445CPU_GET_INFO( m68000 )
446{
447   m68ki_cpu_core *m68k = token;
448   int sr;
449
450   switch (state)
451   {
452      /* --- the following bits of info are returned as 64-bit signed integers --- */
453      case CPUINFO_INT_CONTEXT_SIZE:               info->i = sizeof(m68ki_cpu_core);      break;
454      case CPUINFO_INT_INPUT_LINES:               info->i = 8;                     break;
455      case CPUINFO_INT_DEFAULT_IRQ_VECTOR:         info->i = -1;                     break;
456      case CPUINFO_INT_ENDIANNESS:               info->i = CPU_IS_BE;               break;
457      case CPUINFO_INT_CLOCK_MULTIPLIER:            info->i = 1;                     break;
458      case CPUINFO_INT_CLOCK_DIVIDER:               info->i = 1;                     break;
459      case CPUINFO_INT_MIN_INSTRUCTION_BYTES:         info->i = 2;                     break;
460      case CPUINFO_INT_MAX_INSTRUCTION_BYTES:         info->i = 10;                     break;
461      case CPUINFO_INT_MIN_CYCLES:               info->i = 4;                     break;
462      case CPUINFO_INT_MAX_CYCLES:               info->i = 158;                     break;
463
464      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_PROGRAM:   info->i = 16;               break;
465      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_PROGRAM: info->i = 24;               break;
466      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_PROGRAM: info->i = 0;               break;
467      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_DATA:   info->i = 0;               break;
468      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_DATA:    info->i = 0;               break;
469      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_DATA:    info->i = 0;               break;
470      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_IO:      info->i = 0;               break;
471      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_IO:       info->i = 0;               break;
472      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_IO:       info->i = 0;               break;
473
474      case CPUINFO_INT_INPUT_STATE + 0:            info->i = 0;  /* there is no level 0 */   break;
475      case CPUINFO_INT_INPUT_STATE + 1:            info->i = m68k_get_virq(m68k, 1);            break;
476      case CPUINFO_INT_INPUT_STATE + 2:            info->i = m68k_get_virq(m68k, 2);            break;
477      case CPUINFO_INT_INPUT_STATE + 3:            info->i = m68k_get_virq(m68k, 3);            break;
478      case CPUINFO_INT_INPUT_STATE + 4:            info->i = m68k_get_virq(m68k, 4);            break;
479      case CPUINFO_INT_INPUT_STATE + 5:            info->i = m68k_get_virq(m68k, 5);            break;
480      case CPUINFO_INT_INPUT_STATE + 6:            info->i = m68k_get_virq(m68k, 6);            break;
481      case CPUINFO_INT_INPUT_STATE + 7:            info->i = m68k_get_virq(m68k, 7);            break;
482
483      case CPUINFO_INT_PREVIOUSPC:               info->i = m68k_get_reg(m68k, M68K_REG_PPC); break;
484
485      case CPUINFO_INT_PC:                     info->i = m68k_get_reg(m68k, M68K_REG_PC)&0x00ffffff; break;
486      case CPUINFO_INT_REGISTER + M68K_PC:         info->i = m68k_get_reg(m68k, M68K_REG_PC); break;
487      case CPUINFO_INT_SP:
488      case CPUINFO_INT_REGISTER + M68K_SP:         info->i = m68k_get_reg(m68k, M68K_REG_SP); break;
489      case CPUINFO_INT_REGISTER + M68K_ISP:         info->i = m68k_get_reg(m68k, M68K_REG_ISP); break;
490      case CPUINFO_INT_REGISTER + M68K_USP:         info->i = m68k_get_reg(m68k, M68K_REG_USP); break;
491      case CPUINFO_INT_REGISTER + M68K_SR:         info->i = m68k_get_reg(m68k, M68K_REG_SR); break;
492      case CPUINFO_INT_REGISTER + M68K_D0:         info->i = m68k_get_reg(m68k, M68K_REG_D0); break;
493      case CPUINFO_INT_REGISTER + M68K_D1:         info->i = m68k_get_reg(m68k, M68K_REG_D1); break;
494      case CPUINFO_INT_REGISTER + M68K_D2:         info->i = m68k_get_reg(m68k, M68K_REG_D2); break;
495      case CPUINFO_INT_REGISTER + M68K_D3:         info->i = m68k_get_reg(m68k, M68K_REG_D3); break;
496      case CPUINFO_INT_REGISTER + M68K_D4:         info->i = m68k_get_reg(m68k, M68K_REG_D4); break;
497      case CPUINFO_INT_REGISTER + M68K_D5:         info->i = m68k_get_reg(m68k, M68K_REG_D5); break;
498      case CPUINFO_INT_REGISTER + M68K_D6:         info->i = m68k_get_reg(m68k, M68K_REG_D6); break;
499      case CPUINFO_INT_REGISTER + M68K_D7:         info->i = m68k_get_reg(m68k, M68K_REG_D7); break;
500      case CPUINFO_INT_REGISTER + M68K_A0:         info->i = m68k_get_reg(m68k, M68K_REG_A0); break;
501      case CPUINFO_INT_REGISTER + M68K_A1:         info->i = m68k_get_reg(m68k, M68K_REG_A1); break;
502      case CPUINFO_INT_REGISTER + M68K_A2:         info->i = m68k_get_reg(m68k, M68K_REG_A2); break;
503      case CPUINFO_INT_REGISTER + M68K_A3:         info->i = m68k_get_reg(m68k, M68K_REG_A3); break;
504      case CPUINFO_INT_REGISTER + M68K_A4:         info->i = m68k_get_reg(m68k, M68K_REG_A4); break;
505      case CPUINFO_INT_REGISTER + M68K_A5:         info->i = m68k_get_reg(m68k, M68K_REG_A5); break;
506      case CPUINFO_INT_REGISTER + M68K_A6:         info->i = m68k_get_reg(m68k, M68K_REG_A6); break;
507      case CPUINFO_INT_REGISTER + M68K_A7:         info->i = m68k_get_reg(m68k, M68K_REG_A7); break;
508      case CPUINFO_INT_REGISTER + M68K_PREF_ADDR:      info->i = m68k_get_reg(m68k, M68K_REG_PREF_ADDR); break;
509      case CPUINFO_INT_REGISTER + M68K_PREF_DATA:      info->i = m68k_get_reg(m68k, M68K_REG_PREF_DATA); break;
510
511      /* --- the following bits of info are returned as pointers to data or functions --- */
512      case CPUINFO_PTR_SET_INFO:                  info->setinfo = CPU_SET_INFO_NAME(m68000);      break;
513      case CPUINFO_PTR_GET_CONTEXT:               info->getcontext = CPU_GET_CONTEXT_NAME(m68000);   break;
514      case CPUINFO_PTR_SET_CONTEXT:               info->setcontext = CPU_SET_CONTEXT_NAME(m68000);   break;
515      case CPUINFO_PTR_INIT:                     info->init = CPU_INIT_NAME(m68000);            break;
516      case CPUINFO_PTR_RESET:                     info->reset = CPU_RESET_NAME(m68000);            break;
517      case CPUINFO_PTR_EXIT:                     info->exit = CPU_EXIT_NAME(m68000);            break;
518      case CPUINFO_PTR_EXECUTE:                  info->execute = CPU_EXECUTE_NAME(m68000);         break;
519      case CPUINFO_PTR_BURN:                     info->burn = NULL;                  break;
520      case CPUINFO_PTR_DISASSEMBLE:               info->disassemble = CPU_DISASSEMBLE_NAME(m68000);      break;
521      case CPUINFO_PTR_INSTRUCTION_COUNTER:         info->icount = &m68k->remaining_cycles;   break;
522
523      /* --- the following bits of info are returned as NULL-terminated strings --- */
524      case CPUINFO_STR_NAME:                     strcpy(info->s, "68000");            break;
525      case CPUINFO_STR_CORE_FAMILY:               strcpy(info->s, "Motorola 68K");      break;
526      case CPUINFO_STR_CORE_VERSION:               strcpy(info->s, "3.32");               break;
527      case CPUINFO_STR_CORE_FILE:                  strcpy(info->s, __FILE__);            break;
528      case CPUINFO_STR_CORE_CREDITS:               strcpy(info->s, "Copyright Karl Stenerud. All rights reserved. (2.1 fixes HJB)"); break;
529
530      case CPUINFO_STR_FLAGS:
531         sr = m68k_get_reg(m68k, M68K_REG_SR);
532         sprintf(info->s, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
533            sr & 0x8000 ? 'T':'.',
534            sr & 0x4000 ? '?':'.',
535            sr & 0x2000 ? 'S':'.',
536            sr & 0x1000 ? '?':'.',
537            sr & 0x0800 ? '?':'.',
538            sr & 0x0400 ? 'I':'.',
539            sr & 0x0200 ? 'I':'.',
540            sr & 0x0100 ? 'I':'.',
541            sr & 0x0080 ? '?':'.',
542            sr & 0x0040 ? '?':'.',
543            sr & 0x0020 ? '?':'.',
544            sr & 0x0010 ? 'X':'.',
545            sr & 0x0008 ? 'N':'.',
546            sr & 0x0004 ? 'Z':'.',
547            sr & 0x0002 ? 'V':'.',
548            sr & 0x0001 ? 'C':'.');
549         break;
550
551      case CPUINFO_STR_REGISTER + M68K_PC:         sprintf(info->s, "PC :%08X", m68k_get_reg(m68k, M68K_REG_PC)); break;
552      case CPUINFO_STR_REGISTER + M68K_SR:           sprintf(info->s, "SR :%04X", m68k_get_reg(m68k, M68K_REG_SR)); break;
553      case CPUINFO_STR_REGISTER + M68K_SP:           sprintf(info->s, "SP :%08X", m68k_get_reg(m68k, M68K_REG_SP)); break;
554      case CPUINFO_STR_REGISTER + M68K_ISP:          sprintf(info->s, "ISP:%08X", m68k_get_reg(m68k, M68K_REG_ISP)); break;
555      case CPUINFO_STR_REGISTER + M68K_USP:          sprintf(info->s, "USP:%08X", m68k_get_reg(m68k, M68K_REG_USP)); break;
556      case CPUINFO_STR_REGISTER + M68K_D0:         sprintf(info->s, "D0 :%08X", m68k_get_reg(m68k, M68K_REG_D0)); break;
557      case CPUINFO_STR_REGISTER + M68K_D1:         sprintf(info->s, "D1 :%08X", m68k_get_reg(m68k, M68K_REG_D1)); break;
558      case CPUINFO_STR_REGISTER + M68K_D2:         sprintf(info->s, "D2 :%08X", m68k_get_reg(m68k, M68K_REG_D2)); break;
559      case CPUINFO_STR_REGISTER + M68K_D3:         sprintf(info->s, "D3 :%08X", m68k_get_reg(m68k, M68K_REG_D3)); break;
560      case CPUINFO_STR_REGISTER + M68K_D4:         sprintf(info->s, "D4 :%08X", m68k_get_reg(m68k, M68K_REG_D4)); break;
561      case CPUINFO_STR_REGISTER + M68K_D5:         sprintf(info->s, "D5 :%08X", m68k_get_reg(m68k, M68K_REG_D5)); break;
562      case CPUINFO_STR_REGISTER + M68K_D6:         sprintf(info->s, "D6 :%08X", m68k_get_reg(m68k, M68K_REG_D6)); break;
563      case CPUINFO_STR_REGISTER + M68K_D7:         sprintf(info->s, "D7 :%08X", m68k_get_reg(m68k, M68K_REG_D7)); break;
564      case CPUINFO_STR_REGISTER + M68K_A0:         sprintf(info->s, "A0 :%08X", m68k_get_reg(m68k, M68K_REG_A0)); break;
565      case CPUINFO_STR_REGISTER + M68K_A1:         sprintf(info->s, "A1 :%08X", m68k_get_reg(m68k, M68K_REG_A1)); break;
566      case CPUINFO_STR_REGISTER + M68K_A2:         sprintf(info->s, "A2 :%08X", m68k_get_reg(m68k, M68K_REG_A2)); break;
567      case CPUINFO_STR_REGISTER + M68K_A3:         sprintf(info->s, "A3 :%08X", m68k_get_reg(m68k, M68K_REG_A3)); break;
568      case CPUINFO_STR_REGISTER + M68K_A4:         sprintf(info->s, "A4 :%08X", m68k_get_reg(m68k, M68K_REG_A4)); break;
569      case CPUINFO_STR_REGISTER + M68K_A5:         sprintf(info->s, "A5 :%08X", m68k_get_reg(m68k, M68K_REG_A5)); break;
570      case CPUINFO_STR_REGISTER + M68K_A6:         sprintf(info->s, "A6 :%08X", m68k_get_reg(m68k, M68K_REG_A6)); break;
571      case CPUINFO_STR_REGISTER + M68K_A7:         sprintf(info->s, "A7 :%08X", m68k_get_reg(m68k, M68K_REG_A7)); break;
572      case CPUINFO_STR_REGISTER + M68K_PREF_ADDR:      sprintf(info->s, "PAR:%08X", m68k_get_reg(m68k, M68K_REG_PREF_ADDR)); break;
573      case CPUINFO_STR_REGISTER + M68K_PREF_DATA:      sprintf(info->s, "PDA:%08X", m68k_get_reg(m68k, M68K_REG_PREF_DATA)); break;
574   }
575}
576
577#if HAS_M68008
578
579static CPU_SET_INFO( m68008 )
580{
581   m68ki_cpu_core *m68k = token;
582   switch (state)
583   {
584      /* --- the following bits of info are set as 64-bit signed integers --- */
585      case CPUINFO_INT_INPUT_STATE + 0:         set_irq_line(m68k, 0, info->i);               break;
586      case CPUINFO_INT_INPUT_STATE + 1:         set_irq_line(m68k, 1, info->i);               break;
587      case CPUINFO_INT_INPUT_STATE + 2:         set_irq_line(m68k, 2, info->i);               break;
588      case CPUINFO_INT_INPUT_STATE + 3:         set_irq_line(m68k, 3, info->i);               break;
589      case CPUINFO_INT_INPUT_STATE + 4:         set_irq_line(m68k, 4, info->i);               break;
590      case CPUINFO_INT_INPUT_STATE + 5:         set_irq_line(m68k, 5, info->i);               break;
591      case CPUINFO_INT_INPUT_STATE + 6:         set_irq_line(m68k, 6, info->i);               break;
592      case CPUINFO_INT_INPUT_STATE + 7:         set_irq_line(m68k, 7, info->i);               break;
593
594      case CPUINFO_INT_PC:                    m68k_set_reg(m68k, M68K_REG_PC, info->i&0x00ffffff); break;
595      case CPUINFO_INT_REGISTER + M68K_PC:        m68k_set_reg(m68k, M68K_REG_PC, info->i);         break;
596      case CPUINFO_INT_SP:
597      case CPUINFO_INT_REGISTER + M68K_SP:        m68k_set_reg(m68k, M68K_REG_SP, info->i);         break;
598      case CPUINFO_INT_REGISTER + M68K_ISP:       m68k_set_reg(m68k, M68K_REG_ISP, info->i);      break;
599      case CPUINFO_INT_REGISTER + M68K_USP:       m68k_set_reg(m68k, M68K_REG_USP, info->i);      break;
600      case CPUINFO_INT_REGISTER + M68K_SR:        m68k_set_reg(m68k, M68K_REG_SR, info->i);         break;
601      case CPUINFO_INT_REGISTER + M68K_D0:        m68k_set_reg(m68k, M68K_REG_D0, info->i);         break;
602      case CPUINFO_INT_REGISTER + M68K_D1:        m68k_set_reg(m68k, M68K_REG_D1, info->i);         break;
603      case CPUINFO_INT_REGISTER + M68K_D2:        m68k_set_reg(m68k, M68K_REG_D2, info->i);         break;
604      case CPUINFO_INT_REGISTER + M68K_D3:        m68k_set_reg(m68k, M68K_REG_D3, info->i);         break;
605      case CPUINFO_INT_REGISTER + M68K_D4:        m68k_set_reg(m68k, M68K_REG_D4, info->i);         break;
606      case CPUINFO_INT_REGISTER + M68K_D5:        m68k_set_reg(m68k, M68K_REG_D5, info->i);         break;
607      case CPUINFO_INT_REGISTER + M68K_D6:        m68k_set_reg(m68k, M68K_REG_D6, info->i);         break;
608      case CPUINFO_INT_REGISTER + M68K_D7:        m68k_set_reg(m68k, M68K_REG_D7, info->i);         break;
609      case CPUINFO_INT_REGISTER + M68K_A0:        m68k_set_reg(m68k, M68K_REG_A0, info->i);         break;
610      case CPUINFO_INT_REGISTER + M68K_A1:        m68k_set_reg(m68k, M68K_REG_A1, info->i);         break;
611      case CPUINFO_INT_REGISTER + M68K_A2:        m68k_set_reg(m68k, M68K_REG_A2, info->i);         break;
612      case CPUINFO_INT_REGISTER + M68K_A3:        m68k_set_reg(m68k, M68K_REG_A3, info->i);         break;
613      case CPUINFO_INT_REGISTER + M68K_A4:        m68k_set_reg(m68k, M68K_REG_A4, info->i);         break;
614      case CPUINFO_INT_REGISTER + M68K_A5:        m68k_set_reg(m68k, M68K_REG_A5, info->i);         break;
615      case CPUINFO_INT_REGISTER + M68K_A6:        m68k_set_reg(m68k, M68K_REG_A6, info->i);         break;
616      case CPUINFO_INT_REGISTER + M68K_A7:        m68k_set_reg(m68k, M68K_REG_A7, info->i);         break;
617
618      /* --- the following bits of info are set as pointers to data or functions --- */
619      case CPUINFO_PTR_M68K_RESET_CALLBACK:      m68k_set_reset_instr_callback(m68k, info->f);      break;
620      case CPUINFO_PTR_M68K_CMPILD_CALLBACK:      m68k_set_cmpild_instr_callback(m68k, (void (*)(unsigned int,int))(info->f)); break;
621      case CPUINFO_PTR_M68K_RTE_CALLBACK:         m68k_set_rte_instr_callback(m68k, info->f);      break;
622   }
623}
624
625CPU_GET_INFO( m68008 )
626{
627   m68ki_cpu_core *m68k = token;
628   int sr;
629
630   switch (state)
631   {
632      /* --- the following bits of info are returned as 64-bit signed integers --- */
633      case CPUINFO_INT_CONTEXT_SIZE:               info->i = sizeof(m68ki_cpu_core);      break;
634      case CPUINFO_INT_INPUT_LINES:               info->i = 8;                     break;
635      case CPUINFO_INT_DEFAULT_IRQ_VECTOR:         info->i = -1;                     break;
636      case CPUINFO_INT_ENDIANNESS:               info->i = CPU_IS_BE;               break;
637      case CPUINFO_INT_CLOCK_MULTIPLIER:            info->i = 1;                     break;
638      case CPUINFO_INT_CLOCK_DIVIDER:               info->i = 1;                     break;
639      case CPUINFO_INT_MIN_INSTRUCTION_BYTES:         info->i = 2;                     break;
640      case CPUINFO_INT_MAX_INSTRUCTION_BYTES:         info->i = 10;                     break;
641      case CPUINFO_INT_MIN_CYCLES:               info->i = 4;                     break;
642      case CPUINFO_INT_MAX_CYCLES:               info->i = 158;                     break;
643
644      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_PROGRAM:   info->i = 8;               break;
645      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_PROGRAM: info->i = 22;               break;
646      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_PROGRAM: info->i = 0;               break;
647      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_DATA:   info->i = 0;               break;
648      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_DATA:    info->i = 0;               break;
649      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_DATA:    info->i = 0;               break;
650      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_IO:      info->i = 0;               break;
651      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_IO:       info->i = 0;               break;
652      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_IO:       info->i = 0;               break;
653
654      case CPUINFO_INT_INPUT_STATE + 0:            info->i = 0;  /* there is no level 0 */   break;
655      case CPUINFO_INT_INPUT_STATE + 1:            info->i = m68k_get_virq(m68k, 1);            break;
656      case CPUINFO_INT_INPUT_STATE + 2:            info->i = m68k_get_virq(m68k, 2);            break;
657      case CPUINFO_INT_INPUT_STATE + 3:            info->i = m68k_get_virq(m68k, 3);            break;
658      case CPUINFO_INT_INPUT_STATE + 4:            info->i = m68k_get_virq(m68k, 4);            break;
659      case CPUINFO_INT_INPUT_STATE + 5:            info->i = m68k_get_virq(m68k, 5);            break;
660      case CPUINFO_INT_INPUT_STATE + 6:            info->i = m68k_get_virq(m68k, 6);            break;
661      case CPUINFO_INT_INPUT_STATE + 7:            info->i = m68k_get_virq(m68k, 7);            break;
662
663      case CPUINFO_INT_PREVIOUSPC:               info->i = m68k_get_reg(m68k, M68K_REG_PPC); break;
664
665      case CPUINFO_INT_PC:                     info->i = m68k_get_reg(m68k, M68K_REG_PC)&0x00ffffff; break;
666      case CPUINFO_INT_REGISTER + M68K_PC:         info->i = m68k_get_reg(m68k, M68K_REG_PC); break;
667      case CPUINFO_INT_SP:
668      case CPUINFO_INT_REGISTER + M68K_SP:         info->i = m68k_get_reg(m68k, M68K_REG_SP); break;
669      case CPUINFO_INT_REGISTER + M68K_ISP:         info->i = m68k_get_reg(m68k, M68K_REG_ISP); break;
670      case CPUINFO_INT_REGISTER + M68K_USP:         info->i = m68k_get_reg(m68k, M68K_REG_USP); break;
671      case CPUINFO_INT_REGISTER + M68K_SR:         info->i = m68k_get_reg(m68k, M68K_REG_SR); break;
672      case CPUINFO_INT_REGISTER + M68K_D0:         info->i = m68k_get_reg(m68k, M68K_REG_D0); break;
673      case CPUINFO_INT_REGISTER + M68K_D1:         info->i = m68k_get_reg(m68k, M68K_REG_D1); break;
674      case CPUINFO_INT_REGISTER + M68K_D2:         info->i = m68k_get_reg(m68k, M68K_REG_D2); break;
675      case CPUINFO_INT_REGISTER + M68K_D3:         info->i = m68k_get_reg(m68k, M68K_REG_D3); break;
676      case CPUINFO_INT_REGISTER + M68K_D4:         info->i = m68k_get_reg(m68k, M68K_REG_D4); break;
677      case CPUINFO_INT_REGISTER + M68K_D5:         info->i = m68k_get_reg(m68k, M68K_REG_D5); break;
678      case CPUINFO_INT_REGISTER + M68K_D6:         info->i = m68k_get_reg(m68k, M68K_REG_D6); break;
679      case CPUINFO_INT_REGISTER + M68K_D7:         info->i = m68k_get_reg(m68k, M68K_REG_D7); break;
680      case CPUINFO_INT_REGISTER + M68K_A0:         info->i = m68k_get_reg(m68k, M68K_REG_A0); break;
681      case CPUINFO_INT_REGISTER + M68K_A1:         info->i = m68k_get_reg(m68k, M68K_REG_A1); break;
682      case CPUINFO_INT_REGISTER + M68K_A2:         info->i = m68k_get_reg(m68k, M68K_REG_A2); break;
683      case CPUINFO_INT_REGISTER + M68K_A3:         info->i = m68k_get_reg(m68k, M68K_REG_A3); break;
684      case CPUINFO_INT_REGISTER + M68K_A4:         info->i = m68k_get_reg(m68k, M68K_REG_A4); break;
685      case CPUINFO_INT_REGISTER + M68K_A5:         info->i = m68k_get_reg(m68k, M68K_REG_A5); break;
686      case CPUINFO_INT_REGISTER + M68K_A6:         info->i = m68k_get_reg(m68k, M68K_REG_A6); break;
687      case CPUINFO_INT_REGISTER + M68K_A7:         info->i = m68k_get_reg(m68k, M68K_REG_A7); break;
688      case CPUINFO_INT_REGISTER + M68K_PREF_ADDR:      info->i = m68k_get_reg(m68k, M68K_REG_PREF_ADDR); break;
689      case CPUINFO_INT_REGISTER + M68K_PREF_DATA:      info->i = m68k_get_reg(m68k, M68K_REG_PREF_DATA); break;
690
691      /* --- the following bits of info are returned as pointers to data or functions --- */
692      case CPUINFO_PTR_SET_INFO:                  info->setinfo = CPU_SET_INFO_NAME(m68008);      break;
693      case CPUINFO_PTR_GET_CONTEXT:               info->getcontext = CPU_GET_CONTEXT_NAME(m68008);   break;
694      case CPUINFO_PTR_SET_CONTEXT:               info->setcontext = CPU_SET_CONTEXT_NAME(m68008);   break;
695      case CPUINFO_PTR_INIT:                     info->init = CPU_INIT_NAME(m68008);            break;
696      case CPUINFO_PTR_RESET:                     info->reset = CPU_RESET_NAME(m68008);            break;
697      case CPUINFO_PTR_EXIT:                     info->exit = CPU_EXIT_NAME(m68008);            break;
698      case CPUINFO_PTR_EXECUTE:                  info->execute = CPU_EXECUTE_NAME(m68008);         break;
699      case CPUINFO_PTR_BURN:                     info->burn = NULL;                  break;
700      case CPUINFO_PTR_DISASSEMBLE:               info->disassemble = CPU_DISASSEMBLE_NAME(m68008);      break;
701      case CPUINFO_PTR_INSTRUCTION_COUNTER:         info->icount = &m68k->remaining_cycles;   break;
702
703      /* --- the following bits of info are returned as NULL-terminated strings --- */
704      case CPUINFO_STR_NAME:                     strcpy(info->s, "68008");            break;
705      case CPUINFO_STR_CORE_FAMILY:               strcpy(info->s, "Motorola 68K");      break;
706      case CPUINFO_STR_CORE_VERSION:               strcpy(info->s, "3.32");               break;
707      case CPUINFO_STR_CORE_FILE:                  strcpy(info->s, __FILE__);            break;
708      case CPUINFO_STR_CORE_CREDITS:               strcpy(info->s, "Copyright Karl Stenerud. All rights reserved. (2.1 fixes HJB)"); break;
709
710      case CPUINFO_STR_FLAGS:
711         sr = m68k_get_reg(m68k, M68K_REG_SR);
712         sprintf(info->s, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
713            sr & 0x8000 ? 'T':'.',
714            sr & 0x4000 ? '?':'.',
715            sr & 0x2000 ? 'S':'.',
716            sr & 0x1000 ? '?':'.',
717            sr & 0x0800 ? '?':'.',
718            sr & 0x0400 ? 'I':'.',
719            sr & 0x0200 ? 'I':'.',
720            sr & 0x0100 ? 'I':'.',
721            sr & 0x0080 ? '?':'.',
722            sr & 0x0040 ? '?':'.',
723            sr & 0x0020 ? '?':'.',
724            sr & 0x0010 ? 'X':'.',
725            sr & 0x0008 ? 'N':'.',
726            sr & 0x0004 ? 'Z':'.',
727            sr & 0x0002 ? 'V':'.',
728            sr & 0x0001 ? 'C':'.');
729         break;
730
731      case CPUINFO_STR_REGISTER + M68K_PC:         sprintf(info->s, "PC :%08X", m68k_get_reg(m68k, M68K_REG_PC)); break;
732      case CPUINFO_STR_REGISTER + M68K_SR:           sprintf(info->s, "SR :%04X", m68k_get_reg(m68k, M68K_REG_SR)); break;
733      case CPUINFO_STR_REGISTER + M68K_SP:           sprintf(info->s, "SP :%08X", m68k_get_reg(m68k, M68K_REG_SP)); break;
734      case CPUINFO_STR_REGISTER + M68K_ISP:          sprintf(info->s, "ISP:%08X", m68k_get_reg(m68k, M68K_REG_ISP)); break;
735      case CPUINFO_STR_REGISTER + M68K_USP:          sprintf(info->s, "USP:%08X", m68k_get_reg(m68k, M68K_REG_USP)); break;
736      case CPUINFO_STR_REGISTER + M68K_D0:         sprintf(info->s, "D0 :%08X", m68k_get_reg(m68k, M68K_REG_D0)); break;
737      case CPUINFO_STR_REGISTER + M68K_D1:         sprintf(info->s, "D1 :%08X", m68k_get_reg(m68k, M68K_REG_D1)); break;
738      case CPUINFO_STR_REGISTER + M68K_D2:         sprintf(info->s, "D2 :%08X", m68k_get_reg(m68k, M68K_REG_D2)); break;
739      case CPUINFO_STR_REGISTER + M68K_D3:         sprintf(info->s, "D3 :%08X", m68k_get_reg(m68k, M68K_REG_D3)); break;
740      case CPUINFO_STR_REGISTER + M68K_D4:         sprintf(info->s, "D4 :%08X", m68k_get_reg(m68k, M68K_REG_D4)); break;
741      case CPUINFO_STR_REGISTER + M68K_D5:         sprintf(info->s, "D5 :%08X", m68k_get_reg(m68k, M68K_REG_D5)); break;
742      case CPUINFO_STR_REGISTER + M68K_D6:         sprintf(info->s, "D6 :%08X", m68k_get_reg(m68k, M68K_REG_D6)); break;
743      case CPUINFO_STR_REGISTER + M68K_D7:         sprintf(info->s, "D7 :%08X", m68k_get_reg(m68k, M68K_REG_D7)); break;
744      case CPUINFO_STR_REGISTER + M68K_A0:         sprintf(info->s, "A0 :%08X", m68k_get_reg(m68k, M68K_REG_A0)); break;
745      case CPUINFO_STR_REGISTER + M68K_A1:         sprintf(info->s, "A1 :%08X", m68k_get_reg(m68k, M68K_REG_A1)); break;
746      case CPUINFO_STR_REGISTER + M68K_A2:         sprintf(info->s, "A2 :%08X", m68k_get_reg(m68k, M68K_REG_A2)); break;
747      case CPUINFO_STR_REGISTER + M68K_A3:         sprintf(info->s, "A3 :%08X", m68k_get_reg(m68k, M68K_REG_A3)); break;
748      case CPUINFO_STR_REGISTER + M68K_A4:         sprintf(info->s, "A4 :%08X", m68k_get_reg(m68k, M68K_REG_A4)); break;
749      case CPUINFO_STR_REGISTER + M68K_A5:         sprintf(info->s, "A5 :%08X", m68k_get_reg(m68k, M68K_REG_A5)); break;
750      case CPUINFO_STR_REGISTER + M68K_A6:         sprintf(info->s, "A6 :%08X", m68k_get_reg(m68k, M68K_REG_A6)); break;
751      case CPUINFO_STR_REGISTER + M68K_A7:         sprintf(info->s, "A7 :%08X", m68k_get_reg(m68k, M68K_REG_A7)); break;
752      case CPUINFO_STR_REGISTER + M68K_PREF_ADDR:      sprintf(info->s, "PAR:%08X", m68k_get_reg(m68k, M68K_REG_PREF_ADDR)); break;
753      case CPUINFO_STR_REGISTER + M68K_PREF_DATA:      sprintf(info->s, "PDA:%08X", m68k_get_reg(m68k, M68K_REG_PREF_DATA)); break;
754   }
755}
756
757#endif /* HAS_M68008 */
758
759/**************************************************************************
760 * CPU-specific set_info
761 **************************************************************************/
762#if HAS_M68010
763
764static CPU_SET_INFO( m68010 )
765{
766   m68ki_cpu_core *m68k = token;
767   switch (state)
768   {
769      /* --- the following bits of info are set as 64-bit signed integers --- */
770      case CPUINFO_INT_REGISTER + M68K_VBR:           m68k_set_reg(m68k, M68K_REG_VBR, info->i);   break;
771      case CPUINFO_INT_REGISTER + M68K_SFC:           m68k_set_reg(m68k, M68K_REG_SFC, info->i);   break;
772      case CPUINFO_INT_REGISTER + M68K_DFC:           m68k_set_reg(m68k, M68K_REG_DFC, info->i);   break;
773
774      default:                              CPU_SET_INFO_CALL(m68000);               break;
775   }
776}
777
778CPU_GET_INFO( m68010 )
779{
780   m68ki_cpu_core *m68k = token;
781   switch (state)
782   {
783      /* --- the following bits of info are returned as 64-bit signed integers --- */
784      case CPUINFO_INT_REGISTER + M68K_VBR:           info->i = m68k_get_reg(m68k, M68K_REG_VBR); break;
785      case CPUINFO_INT_REGISTER + M68K_SFC:           info->i = m68k_get_reg(m68k, M68K_REG_SFC); break;
786      case CPUINFO_INT_REGISTER + M68K_DFC:           info->i = m68k_get_reg(m68k, M68K_REG_DFC); break;
787
788      /* --- the following bits of info are returned as pointers to data or functions --- */
789      case CPUINFO_PTR_SET_INFO:                  info->setinfo = CPU_SET_INFO_NAME(m68010);      break;
790      case CPUINFO_PTR_INIT:                     info->init = CPU_INIT_NAME(m68010);            break;
791      case CPUINFO_PTR_DISASSEMBLE:               info->disassemble = CPU_DISASSEMBLE_NAME(m68010);      break;
792
793      /* --- the following bits of info are returned as NULL-terminated strings --- */
794      case CPUINFO_STR_NAME:                     strcpy(info->s, "68010");            break;
795      case CPUINFO_STR_REGISTER + M68K_SFC:         sprintf(info->s, "SFC:%X",   m68k_get_reg(m68k, M68K_REG_SFC)); break;
796      case CPUINFO_STR_REGISTER + M68K_DFC:         sprintf(info->s, "DFC:%X",   m68k_get_reg(m68k, M68K_REG_DFC)); break;
797      case CPUINFO_STR_REGISTER + M68K_VBR:         sprintf(info->s, "VBR:%08X", m68k_get_reg(m68k, M68K_REG_VBR)); break;
798
799      default:                              CPU_GET_INFO_CALL(m68000);               break;
800   }
801}
802
803#endif /* HAS_M68010 */
804
805/**************************************************************************
806 * CPU-specific set_info
807 **************************************************************************/
808
809static CPU_SET_INFO( m68020 )
810{
811   m68ki_cpu_core *m68k = token;
812   switch (state)
813   {
814      /* --- the following bits of info are set as 64-bit signed integers --- */
815      case CPUINFO_INT_INPUT_STATE + 0:         set_irq_line(m68k, 0, info->i);               break;
816      case CPUINFO_INT_INPUT_STATE + 1:         set_irq_line(m68k, 1, info->i);               break;
817      case CPUINFO_INT_INPUT_STATE + 2:         set_irq_line(m68k, 2, info->i);               break;
818      case CPUINFO_INT_INPUT_STATE + 3:         set_irq_line(m68k, 3, info->i);               break;
819      case CPUINFO_INT_INPUT_STATE + 4:         set_irq_line(m68k, 4, info->i);               break;
820      case CPUINFO_INT_INPUT_STATE + 5:         set_irq_line(m68k, 5, info->i);               break;
821      case CPUINFO_INT_INPUT_STATE + 6:         set_irq_line(m68k, 6, info->i);               break;
822      case CPUINFO_INT_INPUT_STATE + 7:         set_irq_line(m68k, 7, info->i);               break;
823
824      case CPUINFO_INT_PC:                    m68k_set_reg(m68k, M68K_REG_PC, info->i);         break;
825      case CPUINFO_INT_REGISTER + M68K_PC:        m68k_set_reg(m68k, M68K_REG_PC, info->i);         break;
826      case CPUINFO_INT_SP:
827      case CPUINFO_INT_REGISTER + M68K_SP:        m68k_set_reg(m68k, M68K_REG_SP, info->i);         break;
828      case CPUINFO_INT_REGISTER + M68K_ISP:       m68k_set_reg(m68k, M68K_REG_ISP, info->i);      break;
829      case CPUINFO_INT_REGISTER + M68K_USP:       m68k_set_reg(m68k, M68K_REG_USP, info->i);      break;
830      case CPUINFO_INT_REGISTER + M68K_SR:        m68k_set_reg(m68k, M68K_REG_SR, info->i);         break;
831      case CPUINFO_INT_REGISTER + M68K_D0:        m68k_set_reg(m68k, M68K_REG_D0, info->i);         break;
832      case CPUINFO_INT_REGISTER + M68K_D1:        m68k_set_reg(m68k, M68K_REG_D1, info->i);         break;
833      case CPUINFO_INT_REGISTER + M68K_D2:        m68k_set_reg(m68k, M68K_REG_D2, info->i);         break;
834      case CPUINFO_INT_REGISTER + M68K_D3:        m68k_set_reg(m68k, M68K_REG_D3, info->i);         break;
835      case CPUINFO_INT_REGISTER + M68K_D4:        m68k_set_reg(m68k, M68K_REG_D4, info->i);         break;
836      case CPUINFO_INT_REGISTER + M68K_D5:        m68k_set_reg(m68k, M68K_REG_D5, info->i);         break;
837      case CPUINFO_INT_REGISTER + M68K_D6:        m68k_set_reg(m68k, M68K_REG_D6, info->i);         break;
838      case CPUINFO_INT_REGISTER + M68K_D7:        m68k_set_reg(m68k, M68K_REG_D7, info->i);         break;
839      case CPUINFO_INT_REGISTER + M68K_A0:        m68k_set_reg(m68k, M68K_REG_A0, info->i);         break;
840      case CPUINFO_INT_REGISTER + M68K_A1:        m68k_set_reg(m68k, M68K_REG_A1, info->i);         break;
841      case CPUINFO_INT_REGISTER + M68K_A2:        m68k_set_reg(m68k, M68K_REG_A2, info->i);         break;
842      case CPUINFO_INT_REGISTER + M68K_A3:        m68k_set_reg(m68k, M68K_REG_A3, info->i);         break;
843      case CPUINFO_INT_REGISTER + M68K_A4:        m68k_set_reg(m68k, M68K_REG_A4, info->i);         break;
844      case CPUINFO_INT_REGISTER + M68K_A5:        m68k_set_reg(m68k, M68K_REG_A5, info->i);         break;
845      case CPUINFO_INT_REGISTER + M68K_A6:        m68k_set_reg(m68k, M68K_REG_A6, info->i);         break;
846      case CPUINFO_INT_REGISTER + M68K_A7:        m68k_set_reg(m68k, M68K_REG_A7, info->i);         break;
847      case CPUINFO_INT_REGISTER + M68K_MSP:      m68k_set_reg(m68k, M68K_REG_MSP, info->i);      break; /* 68020+ */
848      case CPUINFO_INT_REGISTER + M68K_CACR:      m68k_set_reg(m68k, M68K_REG_CACR, info->i);      break; /* 68020+ */
849      case CPUINFO_INT_REGISTER + M68K_CAAR:      m68k_set_reg(m68k, M68K_REG_CAAR, info->i);      break; /* 68020+ */
850      case CPUINFO_INT_REGISTER + M68K_VBR:      m68k_set_reg(m68k, M68K_REG_VBR, info->i);      break; /* 68010+ */
851      case CPUINFO_INT_REGISTER + M68K_SFC:      m68k_set_reg(m68k, M68K_REG_SFC, info->i);      break; /* 68010+ */
852      case CPUINFO_INT_REGISTER + M68K_DFC:      m68k_set_reg(m68k, M68K_REG_DFC, info->i);      break; /* 68010+ */
853
854      /* --- the following bits of info are set as pointers to data or functions --- */
855      case CPUINFO_PTR_M68K_RESET_CALLBACK:      m68k_set_reset_instr_callback(m68k, info->f);      break;
856      case CPUINFO_PTR_M68K_CMPILD_CALLBACK:      m68k_set_cmpild_instr_callback(m68k, (void (*)(unsigned int,int))(info->f)); break;
857      case CPUINFO_PTR_M68K_RTE_CALLBACK:         m68k_set_rte_instr_callback(m68k, info->f);      break;
858   }
859}
860
861CPU_GET_INFO( m68020 )
862{
863   m68ki_cpu_core *m68k = token;
864   int sr;
865
866   switch (state)
867   {
868      /* --- the following bits of info are returned as 64-bit signed integers --- */
869      case CPUINFO_INT_CONTEXT_SIZE:               info->i = sizeof(m68ki_cpu_core);      break;
870      case CPUINFO_INT_INPUT_LINES:               info->i = 8;                     break;
871      case CPUINFO_INT_DEFAULT_IRQ_VECTOR:         info->i = -1;                     break;
872      case CPUINFO_INT_ENDIANNESS:               info->i = CPU_IS_BE;               break;
873      case CPUINFO_INT_CLOCK_MULTIPLIER:            info->i = 1;                     break;
874      case CPUINFO_INT_CLOCK_DIVIDER:               info->i = 1;                     break;
875      case CPUINFO_INT_MIN_INSTRUCTION_BYTES:         info->i = 2;                     break;
876      case CPUINFO_INT_MAX_INSTRUCTION_BYTES:         info->i = 20;                     break;
877      case CPUINFO_INT_MIN_CYCLES:               info->i = 2;                     break;
878      case CPUINFO_INT_MAX_CYCLES:               info->i = 158;                     break;
879
880      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_PROGRAM:   info->i = 32;               break;
881      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_PROGRAM: info->i = 32;               break;
882      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_PROGRAM: info->i = 0;               break;
883      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_DATA:   info->i = 0;               break;
884      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_DATA:    info->i = 0;               break;
885      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_DATA:    info->i = 0;               break;
886      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_IO:      info->i = 0;               break;
887      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_IO:       info->i = 0;               break;
888      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_IO:       info->i = 0;               break;
889
890      case CPUINFO_INT_INPUT_STATE + 0:            info->i = 0;  /* there is no level 0 */   break;
891      case CPUINFO_INT_INPUT_STATE + 1:            info->i = m68k_get_virq(m68k, 1);            break;
892      case CPUINFO_INT_INPUT_STATE + 2:            info->i = m68k_get_virq(m68k, 2);            break;
893      case CPUINFO_INT_INPUT_STATE + 3:            info->i = m68k_get_virq(m68k, 3);            break;
894      case CPUINFO_INT_INPUT_STATE + 4:            info->i = m68k_get_virq(m68k, 4);            break;
895      case CPUINFO_INT_INPUT_STATE + 5:            info->i = m68k_get_virq(m68k, 5);            break;
896      case CPUINFO_INT_INPUT_STATE + 6:            info->i = m68k_get_virq(m68k, 6);            break;
897      case CPUINFO_INT_INPUT_STATE + 7:            info->i = m68k_get_virq(m68k, 7);            break;
898
899      case CPUINFO_INT_PREVIOUSPC:               info->i = m68k_get_reg(m68k, M68K_REG_PPC); break;
900
901      case CPUINFO_INT_PC:                     info->i = m68k_get_reg(m68k, M68K_REG_PC); break;
902      case CPUINFO_INT_REGISTER + M68K_PC:         info->i = m68k_get_reg(m68k, M68K_REG_PC); break;
903      case CPUINFO_INT_SP:
904      case CPUINFO_INT_REGISTER + M68K_SP:         info->i = m68k_get_reg(m68k, M68K_REG_SP); break;
905      case CPUINFO_INT_REGISTER + M68K_ISP:         info->i = m68k_get_reg(m68k, M68K_REG_ISP); break;
906      case CPUINFO_INT_REGISTER + M68K_USP:         info->i = m68k_get_reg(m68k, M68K_REG_USP); break;
907      case CPUINFO_INT_REGISTER + M68K_SR:         info->i = m68k_get_reg(m68k, M68K_REG_SR); break;
908      case CPUINFO_INT_REGISTER + M68K_D0:         info->i = m68k_get_reg(m68k, M68K_REG_D0); break;
909      case CPUINFO_INT_REGISTER + M68K_D1:         info->i = m68k_get_reg(m68k, M68K_REG_D1); break;
910      case CPUINFO_INT_REGISTER + M68K_D2:         info->i = m68k_get_reg(m68k, M68K_REG_D2); break;
911      case CPUINFO_INT_REGISTER + M68K_D3:         info->i = m68k_get_reg(m68k, M68K_REG_D3); break;
912      case CPUINFO_INT_REGISTER + M68K_D4:         info->i = m68k_get_reg(m68k, M68K_REG_D4); break;
913      case CPUINFO_INT_REGISTER + M68K_D5:         info->i = m68k_get_reg(m68k, M68K_REG_D5); break;
914      case CPUINFO_INT_REGISTER + M68K_D6:         info->i = m68k_get_reg(m68k, M68K_REG_D6); break;
915      case CPUINFO_INT_REGISTER + M68K_D7:         info->i = m68k_get_reg(m68k, M68K_REG_D7); break;
916      case CPUINFO_INT_REGISTER + M68K_A0:         info->i = m68k_get_reg(m68k, M68K_REG_A0); break;
917      case CPUINFO_INT_REGISTER + M68K_A1:         info->i = m68k_get_reg(m68k, M68K_REG_A1); break;
918      case CPUINFO_INT_REGISTER + M68K_A2:         info->i = m68k_get_reg(m68k, M68K_REG_A2); break;
919      case CPUINFO_INT_REGISTER + M68K_A3:         info->i = m68k_get_reg(m68k, M68K_REG_A3); break;
920      case CPUINFO_INT_REGISTER + M68K_A4:         info->i = m68k_get_reg(m68k, M68K_REG_A4); break;
921      case CPUINFO_INT_REGISTER + M68K_A5:         info->i = m68k_get_reg(m68k, M68K_REG_A5); break;
922      case CPUINFO_INT_REGISTER + M68K_A6:         info->i = m68k_get_reg(m68k, M68K_REG_A6); break;
923      case CPUINFO_INT_REGISTER + M68K_A7:         info->i = m68k_get_reg(m68k, M68K_REG_A7); break;
924      case CPUINFO_INT_REGISTER + M68K_PREF_ADDR:      info->i = m68k_get_reg(m68k, M68K_REG_PREF_ADDR); break;
925      case CPUINFO_INT_REGISTER + M68K_PREF_DATA:      info->i = m68k_get_reg(m68k, M68K_REG_PREF_DATA); break;
926      case CPUINFO_INT_REGISTER + M68K_MSP:         info->i = m68k_get_reg(m68k, M68K_REG_MSP); /* 68020+ */ break;
927      case CPUINFO_INT_REGISTER + M68K_CACR:          info->i = m68k_get_reg(m68k, M68K_REG_CACR); /* 68020+ */ break;
928      case CPUINFO_INT_REGISTER + M68K_CAAR:          info->i = m68k_get_reg(m68k, M68K_REG_CAAR); /* 68020+ */ break;
929      case CPUINFO_INT_REGISTER + M68K_VBR:         info->i = m68k_get_reg(m68k, M68K_REG_VBR); /* 68010+ */ break;
930      case CPUINFO_INT_REGISTER + M68K_SFC:         info->i = m68k_get_reg(m68k, M68K_REG_SFC); /* 68010" */ break;
931      case CPUINFO_INT_REGISTER + M68K_DFC:         info->i = m68k_get_reg(m68k, M68K_REG_DFC); /* 68010+ */ break;
932
933      /* --- the following bits of info are returned as pointers to data or functions --- */
934      case CPUINFO_PTR_SET_INFO:                  info->setinfo = CPU_SET_INFO_NAME(m68020);      break;
935      case CPUINFO_PTR_GET_CONTEXT:               info->getcontext = CPU_GET_CONTEXT_NAME(m68020);   break;
936      case CPUINFO_PTR_SET_CONTEXT:               info->setcontext = CPU_SET_CONTEXT_NAME(m68020);   break;
937      case CPUINFO_PTR_INIT:                     info->init = CPU_INIT_NAME(m68020);            break;
938      case CPUINFO_PTR_RESET:                     info->reset = CPU_RESET_NAME(m68020);            break;
939      case CPUINFO_PTR_EXIT:                     info->exit = CPU_EXIT_NAME(m68020);            break;
940      case CPUINFO_PTR_EXECUTE:                  info->execute = CPU_EXECUTE_NAME(m68020);         break;
941      case CPUINFO_PTR_BURN:                     info->burn = NULL;                  break;
942      case CPUINFO_PTR_DISASSEMBLE:               info->disassemble = CPU_DISASSEMBLE_NAME(m68020);      break;
943      case CPUINFO_PTR_INSTRUCTION_COUNTER:         info->icount = &m68k->remaining_cycles;   break;
944
945      /* --- the following bits of info are returned as NULL-terminated strings --- */
946      case CPUINFO_STR_NAME:                     strcpy(info->s, "68020");            break;
947      case CPUINFO_STR_CORE_FAMILY:               strcpy(info->s, "Motorola 68K");      break;
948      case CPUINFO_STR_CORE_VERSION:               strcpy(info->s, "3.32");               break;
949      case CPUINFO_STR_CORE_FILE:                  strcpy(info->s, __FILE__);            break;
950      case CPUINFO_STR_CORE_CREDITS:               strcpy(info->s, "Copyright Karl Stenerud. All rights reserved. (2.1 fixes HJB)"); break;
951
952      case CPUINFO_STR_FLAGS:
953         sr = m68k_get_reg(m68k, M68K_REG_SR);
954         sprintf(info->s, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
955            sr & 0x8000 ? 'T':'.',
956            sr & 0x4000 ? 't':'.',
957            sr & 0x2000 ? 'S':'.',
958            sr & 0x1000 ? 'M':'.',
959            sr & 0x0800 ? '?':'.',
960            sr & 0x0400 ? 'I':'.',
961            sr & 0x0200 ? 'I':'.',
962            sr & 0x0100 ? 'I':'.',
963            sr & 0x0080 ? '?':'.',
964            sr & 0x0040 ? '?':'.',
965            sr & 0x0020 ? '?':'.',
966            sr & 0x0010 ? 'X':'.',
967            sr & 0x0008 ? 'N':'.',
968            sr & 0x0004 ? 'Z':'.',
969            sr & 0x0002 ? 'V':'.',
970            sr & 0x0001 ? 'C':'.');
971         break;
972
973      case CPUINFO_STR_REGISTER + M68K_PC:         sprintf(info->s, "PC :%08X", m68k_get_reg(m68k, M68K_REG_PC)); break;
974      case CPUINFO_STR_REGISTER + M68K_SR:           sprintf(info->s, "SR :%04X", m68k_get_reg(m68k, M68K_REG_SR)); break;
975      case CPUINFO_STR_REGISTER + M68K_SP:           sprintf(info->s, "SP :%08X", m68k_get_reg(m68k, M68K_REG_SP)); break;
976      case CPUINFO_STR_REGISTER + M68K_ISP:          sprintf(info->s, "ISP:%08X", m68k_get_reg(m68k, M68K_REG_ISP)); break;
977      case CPUINFO_STR_REGISTER + M68K_USP:          sprintf(info->s, "USP:%08X", m68k_get_reg(m68k, M68K_REG_USP)); break;
978      case CPUINFO_STR_REGISTER + M68K_D0:         sprintf(info->s, "D0 :%08X", m68k_get_reg(m68k, M68K_REG_D0)); break;
979      case CPUINFO_STR_REGISTER + M68K_D1:         sprintf(info->s, "D1 :%08X", m68k_get_reg(m68k, M68K_REG_D1)); break;
980      case CPUINFO_STR_REGISTER + M68K_D2:         sprintf(info->s, "D2 :%08X", m68k_get_reg(m68k, M68K_REG_D2)); break;
981      case CPUINFO_STR_REGISTER + M68K_D3:         sprintf(info->s, "D3 :%08X", m68k_get_reg(m68k, M68K_REG_D3)); break;
982      case CPUINFO_STR_REGISTER + M68K_D4:         sprintf(info->s, "D4 :%08X", m68k_get_reg(m68k, M68K_REG_D4)); break;
983      case CPUINFO_STR_REGISTER + M68K_D5:         sprintf(info->s, "D5 :%08X", m68k_get_reg(m68k, M68K_REG_D5)); break;
984      case CPUINFO_STR_REGISTER + M68K_D6:         sprintf(info->s, "D6 :%08X", m68k_get_reg(m68k, M68K_REG_D6)); break;
985      case CPUINFO_STR_REGISTER + M68K_D7:         sprintf(info->s, "D7 :%08X", m68k_get_reg(m68k, M68K_REG_D7)); break;
986      case CPUINFO_STR_REGISTER + M68K_A0:         sprintf(info->s, "A0 :%08X", m68k_get_reg(m68k, M68K_REG_A0)); break;
987      case CPUINFO_STR_REGISTER + M68K_A1:         sprintf(info->s, "A1 :%08X", m68k_get_reg(m68k, M68K_REG_A1)); break;
988      case CPUINFO_STR_REGISTER + M68K_A2:         sprintf(info->s, "A2 :%08X", m68k_get_reg(m68k, M68K_REG_A2)); break;
989      case CPUINFO_STR_REGISTER + M68K_A3:         sprintf(info->s, "A3 :%08X", m68k_get_reg(m68k, M68K_REG_A3)); break;
990      case CPUINFO_STR_REGISTER + M68K_A4:         sprintf(info->s, "A4 :%08X", m68k_get_reg(m68k, M68K_REG_A4)); break;
991      case CPUINFO_STR_REGISTER + M68K_A5:         sprintf(info->s, "A5 :%08X", m68k_get_reg(m68k, M68K_REG_A5)); break;
992      case CPUINFO_STR_REGISTER + M68K_A6:         sprintf(info->s, "A6 :%08X", m68k_get_reg(m68k, M68K_REG_A6)); break;
993      case CPUINFO_STR_REGISTER + M68K_A7:         sprintf(info->s, "A7 :%08X", m68k_get_reg(m68k, M68K_REG_A7)); break;
994      case CPUINFO_STR_REGISTER + M68K_PREF_ADDR:      sprintf(info->s, "PAR:%08X", m68k_get_reg(m68k, M68K_REG_PREF_ADDR)); break;
995      case CPUINFO_STR_REGISTER + M68K_PREF_DATA:      sprintf(info->s, "PDA:%08X", m68k_get_reg(m68k, M68K_REG_PREF_DATA)); break;
996      case CPUINFO_STR_REGISTER + M68K_MSP:         sprintf(info->s, "MSP:%08X", m68k_get_reg(m68k, M68K_REG_MSP)); break;
997      case CPUINFO_STR_REGISTER + M68K_CACR:         sprintf(info->s, "CCR:%08X", m68k_get_reg(m68k, M68K_REG_CACR)); break;
998      case CPUINFO_STR_REGISTER + M68K_CAAR:         sprintf(info->s, "CAR:%08X", m68k_get_reg(m68k, M68K_REG_CAAR)); break;
999      case CPUINFO_STR_REGISTER + M68K_SFC:         sprintf(info->s, "SFC:%X",   m68k_get_reg(m68k, M68K_REG_SFC)); break;
1000      case CPUINFO_STR_REGISTER + M68K_DFC:         sprintf(info->s, "DFC:%X",   m68k_get_reg(m68k, M68K_REG_DFC)); break;
1001      case CPUINFO_STR_REGISTER + M68K_VBR:         sprintf(info->s, "VBR:%08X", m68k_get_reg(m68k, M68K_REG_VBR)); break;
1002   }
1003}
1004
1005
1006/**************************************************************************
1007 * CPU-specific set_info
1008 **************************************************************************/
1009#if HAS_M68EC020
1010
1011static CPU_SET_INFO( m68ec020 )
1012{
1013   m68ki_cpu_core *m68k = token;
1014   switch (state)
1015   {
1016      /* --- the following bits of info are set as 64-bit signed integers --- */
1017      case CPUINFO_INT_PC:                       m68k_set_reg(m68k, M68K_REG_PC, info->i&0x00ffffff); break;
1018
1019      default:                              CPU_SET_INFO_CALL(m68020);               break;
1020   }
1021}
1022
1023CPU_GET_INFO( m68ec020 )
1024{
1025   m68ki_cpu_core *m68k = token;
1026   switch (state)
1027   {
1028      /* --- the following bits of info are returned as 64-bit signed integers --- */
1029      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_PROGRAM: info->i = 24;               break;
1030      case CPUINFO_INT_PC:                     info->i = m68k_get_reg(m68k, M68K_REG_PC)&0x00ffffff; break;
1031
1032      /* --- the following bits of info are returned as pointers to data or functions --- */
1033      case CPUINFO_PTR_SET_INFO:                  info->setinfo = CPU_SET_INFO_NAME(m68ec020);      break;
1034      case CPUINFO_PTR_INIT:                     info->init = CPU_INIT_NAME(m68ec020);            break;
1035      case CPUINFO_PTR_DISASSEMBLE:               info->disassemble = CPU_DISASSEMBLE_NAME(m68ec020);      break;
1036
1037      /* --- the following bits of info are returned as NULL-terminated strings --- */
1038      case CPUINFO_STR_NAME:                     strcpy(info->s, "68EC020");            break;
1039
1040      default:                              CPU_GET_INFO_CALL(m68020);               break;
1041   }
1042}
1043
1044#endif /* HAS_M68EC020 */
1045
1046/**************************************************************************
1047 * CPU-specific set_info
1048 **************************************************************************/
1049
1050#if HAS_M68040
1051static CPU_SET_INFO( m68040 )
1052{
1053   m68ki_cpu_core *m68k = token;
1054   switch (state)
1055   {
1056      /* --- the following bits of info are set as 64-bit signed integers --- */
1057      case CPUINFO_INT_INPUT_STATE + 0:         set_irq_line(m68k, 0, info->i);               break;
1058      case CPUINFO_INT_INPUT_STATE + 1:         set_irq_line(m68k, 1, info->i);               break;
1059      case CPUINFO_INT_INPUT_STATE + 2:         set_irq_line(m68k, 2, info->i);               break;
1060      case CPUINFO_INT_INPUT_STATE + 3:         set_irq_line(m68k, 3, info->i);               break;
1061      case CPUINFO_INT_INPUT_STATE + 4:         set_irq_line(m68k, 4, info->i);               break;
1062      case CPUINFO_INT_INPUT_STATE + 5:         set_irq_line(m68k, 5, info->i);               break;
1063      case CPUINFO_INT_INPUT_STATE + 6:         set_irq_line(m68k, 6, info->i);               break;
1064      case CPUINFO_INT_INPUT_STATE + 7:         set_irq_line(m68k, 7, info->i);               break;
1065
1066      case CPUINFO_INT_PC:                    m68k_set_reg(m68k, M68K_REG_PC, info->i);         break;
1067      case CPUINFO_INT_REGISTER + M68K_PC:        m68k_set_reg(m68k, M68K_REG_PC, info->i);         break;
1068      case CPUINFO_INT_SP:
1069      case CPUINFO_INT_REGISTER + M68K_SP:        m68k_set_reg(m68k, M68K_REG_SP, info->i);         break;
1070      case CPUINFO_INT_REGISTER + M68K_ISP:       m68k_set_reg(m68k, M68K_REG_ISP, info->i);      break;
1071      case CPUINFO_INT_REGISTER + M68K_USP:       m68k_set_reg(m68k, M68K_REG_USP, info->i);      break;
1072      case CPUINFO_INT_REGISTER + M68K_SR:        m68k_set_reg(m68k, M68K_REG_SR, info->i);         break;
1073      case CPUINFO_INT_REGISTER + M68K_D0:        m68k_set_reg(m68k, M68K_REG_D0, info->i);         break;
1074      case CPUINFO_INT_REGISTER + M68K_D1:        m68k_set_reg(m68k, M68K_REG_D1, info->i);         break;
1075      case CPUINFO_INT_REGISTER + M68K_D2:        m68k_set_reg(m68k, M68K_REG_D2, info->i);         break;
1076      case CPUINFO_INT_REGISTER + M68K_D3:        m68k_set_reg(m68k, M68K_REG_D3, info->i);         break;
1077      case CPUINFO_INT_REGISTER + M68K_D4:        m68k_set_reg(m68k, M68K_REG_D4, info->i);         break;
1078      case CPUINFO_INT_REGISTER + M68K_D5:        m68k_set_reg(m68k, M68K_REG_D5, info->i);         break;
1079      case CPUINFO_INT_REGISTER + M68K_D6:        m68k_set_reg(m68k, M68K_REG_D6, info->i);         break;
1080      case CPUINFO_INT_REGISTER + M68K_D7:        m68k_set_reg(m68k, M68K_REG_D7, info->i);         break;
1081      case CPUINFO_INT_REGISTER + M68K_A0:        m68k_set_reg(m68k, M68K_REG_A0, info->i);         break;
1082      case CPUINFO_INT_REGISTER + M68K_A1:        m68k_set_reg(m68k, M68K_REG_A1, info->i);         break;
1083      case CPUINFO_INT_REGISTER + M68K_A2:        m68k_set_reg(m68k, M68K_REG_A2, info->i);         break;
1084      case CPUINFO_INT_REGISTER + M68K_A3:        m68k_set_reg(m68k, M68K_REG_A3, info->i);         break;
1085      case CPUINFO_INT_REGISTER + M68K_A4:        m68k_set_reg(m68k, M68K_REG_A4, info->i);         break;
1086      case CPUINFO_INT_REGISTER + M68K_A5:        m68k_set_reg(m68k, M68K_REG_A5, info->i);         break;
1087      case CPUINFO_INT_REGISTER + M68K_A6:        m68k_set_reg(m68k, M68K_REG_A6, info->i);         break;
1088      case CPUINFO_INT_REGISTER + M68K_A7:        m68k_set_reg(m68k, M68K_REG_A7, info->i);         break;
1089      case CPUINFO_INT_REGISTER + M68K_MSP:      m68k_set_reg(m68k, M68K_REG_MSP, info->i);      break; /* 68020+ */
1090      case CPUINFO_INT_REGISTER + M68K_CACR:      m68k_set_reg(m68k, M68K_REG_CACR, info->i);      break; /* 68020+ */
1091      case CPUINFO_INT_REGISTER + M68K_CAAR:      m68k_set_reg(m68k, M68K_REG_CAAR, info->i);      break; /* 68020+ */
1092      case CPUINFO_INT_REGISTER + M68K_VBR:      m68k_set_reg(m68k, M68K_REG_VBR, info->i);      break; /* 68010+ */
1093      case CPUINFO_INT_REGISTER + M68K_SFC:      m68k_set_reg(m68k, M68K_REG_SFC, info->i);      break; /* 68010+ */
1094      case CPUINFO_INT_REGISTER + M68K_DFC:      m68k_set_reg(m68k, M68K_REG_DFC, info->i);      break; /* 68010+ */
1095
1096      /* --- the following bits of info are set as pointers to data or functions --- */
1097      case CPUINFO_PTR_M68K_RESET_CALLBACK:      m68k_set_reset_instr_callback(m68k, info->f);      break;
1098      case CPUINFO_PTR_M68K_CMPILD_CALLBACK:      m68k_set_cmpild_instr_callback(m68k, (void (*)(unsigned int,int))(info->f)); break;
1099      case CPUINFO_PTR_M68K_RTE_CALLBACK:         m68k_set_rte_instr_callback(m68k, info->f);      break;
1100   }
1101}
1102
1103CPU_GET_INFO( m68040 )
1104{
1105   m68ki_cpu_core *m68k = token;
1106   int sr;
1107
1108   switch (state)
1109   {
1110      /* --- the following bits of info are returned as 64-bit signed integers --- */
1111      case CPUINFO_INT_CONTEXT_SIZE:               info->i = sizeof(m68ki_cpu_core);      break;
1112      case CPUINFO_INT_INPUT_LINES:               info->i = 8;                     break;
1113      case CPUINFO_INT_DEFAULT_IRQ_VECTOR:         info->i = -1;                     break;
1114      case CPUINFO_INT_ENDIANNESS:               info->i = CPU_IS_BE;               break;
1115      case CPUINFO_INT_CLOCK_MULTIPLIER:            info->i = 1;                     break;
1116      case CPUINFO_INT_CLOCK_DIVIDER:               info->i = 1;                     break;
1117      case CPUINFO_INT_MIN_INSTRUCTION_BYTES:         info->i = 2;                     break;
1118      case CPUINFO_INT_MAX_INSTRUCTION_BYTES:         info->i = 20;                     break;
1119      case CPUINFO_INT_MIN_CYCLES:               info->i = 2;                     break;
1120      case CPUINFO_INT_MAX_CYCLES:               info->i = 158;                     break;
1121
1122      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_PROGRAM:   info->i = 32;               break;
1123      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_PROGRAM: info->i = 32;               break;
1124      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_PROGRAM: info->i = 0;               break;
1125      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_DATA:   info->i = 0;               break;
1126      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_DATA:    info->i = 0;               break;
1127      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_DATA:    info->i = 0;               break;
1128      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_IO:      info->i = 0;               break;
1129      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_IO:       info->i = 0;               break;
1130      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_IO:       info->i = 0;               break;
1131
1132      case CPUINFO_INT_INPUT_STATE + 0:            info->i = 0;  /* there is no level 0 */   break;
1133      case CPUINFO_INT_INPUT_STATE + 1:            info->i = m68k_get_virq(m68k, 1);            break;
1134      case CPUINFO_INT_INPUT_STATE + 2:            info->i = m68k_get_virq(m68k, 2);            break;
1135      case CPUINFO_INT_INPUT_STATE + 3:            info->i = m68k_get_virq(m68k, 3);            break;
1136      case CPUINFO_INT_INPUT_STATE + 4:            info->i = m68k_get_virq(m68k, 4);            break;
1137      case CPUINFO_INT_INPUT_STATE + 5:            info->i = m68k_get_virq(m68k, 5);            break;
1138      case CPUINFO_INT_INPUT_STATE + 6:            info->i = m68k_get_virq(m68k, 6);            break;
1139      case CPUINFO_INT_INPUT_STATE + 7:            info->i = m68k_get_virq(m68k, 7);            break;
1140
1141      case CPUINFO_INT_PREVIOUSPC:               info->i = m68k_get_reg(m68k, M68K_REG_PPC); break;
1142
1143      case CPUINFO_INT_PC:                     info->i = m68k_get_reg(m68k, M68K_REG_PC); break;
1144      case CPUINFO_INT_REGISTER + M68K_PC:         info->i = m68k_get_reg(m68k, M68K_REG_PC); break;
1145      case CPUINFO_INT_SP:
1146      case CPUINFO_INT_REGISTER + M68K_SP:         info->i = m68k_get_reg(m68k, M68K_REG_SP); break;
1147      case CPUINFO_INT_REGISTER + M68K_ISP:         info->i = m68k_get_reg(m68k, M68K_REG_ISP); break;
1148      case CPUINFO_INT_REGISTER + M68K_USP:         info->i = m68k_get_reg(m68k, M68K_REG_USP); break;
1149      case CPUINFO_INT_REGISTER + M68K_SR:         info->i = m68k_get_reg(m68k, M68K_REG_SR); break;
1150      case CPUINFO_INT_REGISTER + M68K_D0:         info->i = m68k_get_reg(m68k, M68K_REG_D0); break;
1151      case CPUINFO_INT_REGISTER + M68K_D1:         info->i = m68k_get_reg(m68k, M68K_REG_D1); break;
1152      case CPUINFO_INT_REGISTER + M68K_D2:         info->i = m68k_get_reg(m68k, M68K_REG_D2); break;
1153      case CPUINFO_INT_REGISTER + M68K_D3:         info->i = m68k_get_reg(m68k, M68K_REG_D3); break;
1154      case CPUINFO_INT_REGISTER + M68K_D4:         info->i = m68k_get_reg(m68k, M68K_REG_D4); break;
1155      case CPUINFO_INT_REGISTER + M68K_D5:         info->i = m68k_get_reg(m68k, M68K_REG_D5); break;
1156      case CPUINFO_INT_REGISTER + M68K_D6:         info->i = m68k_get_reg(m68k, M68K_REG_D6); break;
1157      case CPUINFO_INT_REGISTER + M68K_D7:         info->i = m68k_get_reg(m68k, M68K_REG_D7); break;
1158      case CPUINFO_INT_REGISTER + M68K_A0:         info->i = m68k_get_reg(m68k, M68K_REG_A0); break;
1159      case CPUINFO_INT_REGISTER + M68K_A1:         info->i = m68k_get_reg(m68k, M68K_REG_A1); break;
1160      case CPUINFO_INT_REGISTER + M68K_A2:         info->i = m68k_get_reg(m68k, M68K_REG_A2); break;
1161      case CPUINFO_INT_REGISTER + M68K_A3:         info->i = m68k_get_reg(m68k, M68K_REG_A3); break;
1162      case CPUINFO_INT_REGISTER + M68K_A4:         info->i = m68k_get_reg(m68k, M68K_REG_A4); break;
1163      case CPUINFO_INT_REGISTER + M68K_A5:         info->i = m68k_get_reg(m68k, M68K_REG_A5); break;
1164      case CPUINFO_INT_REGISTER + M68K_A6:         info->i = m68k_get_reg(m68k, M68K_REG_A6); break;
1165      case CPUINFO_INT_REGISTER + M68K_A7:         info->i = m68k_get_reg(m68k, M68K_REG_A7); break;
1166      case CPUINFO_INT_REGISTER + M68K_PREF_ADDR:      info->i = m68k_get_reg(m68k, M68K_REG_PREF_ADDR); break;
1167      case CPUINFO_INT_REGISTER + M68K_PREF_DATA:      info->i = m68k_get_reg(m68k, M68K_REG_PREF_DATA); break;
1168      case CPUINFO_INT_REGISTER + M68K_MSP:         info->i = m68k_get_reg(m68k, M68K_REG_MSP); /* 68020+ */ break;
1169      case CPUINFO_INT_REGISTER + M68K_CACR:          info->i = m68k_get_reg(m68k, M68K_REG_CACR); /* 68020+ */ break;
1170      case CPUINFO_INT_REGISTER + M68K_CAAR:          info->i = m68k_get_reg(m68k, M68K_REG_CAAR); /* 68020+ */ break;
1171      case CPUINFO_INT_REGISTER + M68K_VBR:         info->i = m68k_get_reg(m68k, M68K_REG_VBR); /* 68010+ */ break;
1172      case CPUINFO_INT_REGISTER + M68K_SFC:         info->i = m68k_get_reg(m68k, M68K_REG_SFC); /* 68010" */ break;
1173      case CPUINFO_INT_REGISTER + M68K_DFC:         info->i = m68k_get_reg(m68k, M68K_REG_DFC); /* 68010+ */ break;
1174
1175      /* --- the following bits of info are returned as pointers to data or functions --- */
1176      case CPUINFO_PTR_SET_INFO:                  info->setinfo = CPU_SET_INFO_NAME(m68040);      break;
1177      case CPUINFO_PTR_GET_CONTEXT:               info->getcontext = CPU_GET_CONTEXT_NAME(m68040);   break;
1178      case CPUINFO_PTR_SET_CONTEXT:               info->setcontext = CPU_SET_CONTEXT_NAME(m68040);   break;
1179      case CPUINFO_PTR_INIT:                     info->init = CPU_INIT_NAME(m68040);            break;
1180      case CPUINFO_PTR_RESET:                     info->reset = CPU_RESET_NAME(m68040);            break;
1181      case CPUINFO_PTR_EXIT:                     info->exit = CPU_EXIT_NAME(m68040);            break;
1182      case CPUINFO_PTR_EXECUTE:                  info->execute = CPU_EXECUTE_NAME(m68040);         break;
1183      case CPUINFO_PTR_BURN:                     info->burn = NULL;                  break;
1184      case CPUINFO_PTR_DISASSEMBLE:               info->disassemble = CPU_DISASSEMBLE_NAME(m68040);      break;
1185      case CPUINFO_PTR_INSTRUCTION_COUNTER:         info->icount = &m68k->remaining_cycles;   break;
1186
1187      /* --- the following bits of info are returned as NULL-terminated strings --- */
1188      case CPUINFO_STR_NAME:                     strcpy(info->s, "68040");            break;
1189      case CPUINFO_STR_CORE_FAMILY:               strcpy(info->s, "Motorola 68K");      break;
1190      case CPUINFO_STR_CORE_VERSION:               strcpy(info->s, "3.32");               break;
1191      case CPUINFO_STR_CORE_FILE:                  strcpy(info->s, __FILE__);            break;
1192      case CPUINFO_STR_CORE_CREDITS:               strcpy(info->s, "Copyright Karl Stenerud. All rights reserved. (2.1 fixes HJB)"); break;
1193
1194      case CPUINFO_STR_FLAGS:
1195         sr = m68k_get_reg(m68k, M68K_REG_SR);
1196         sprintf(info->s, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
1197            sr & 0x8000 ? 'T':'.',
1198            sr & 0x4000 ? 't':'.',
1199            sr & 0x2000 ? 'S':'.',
1200            sr & 0x1000 ? 'M':'.',
1201            sr & 0x0800 ? '?':'.',
1202            sr & 0x0400 ? 'I':'.',
1203            sr & 0x0200 ? 'I':'.',
1204            sr & 0x0100 ? 'I':'.',
1205            sr & 0x0080 ? '?':'.',
1206            sr & 0x0040 ? '?':'.',
1207            sr & 0x0020 ? '?':'.',
1208            sr & 0x0010 ? 'X':'.',
1209            sr & 0x0008 ? 'N':'.',
1210            sr & 0x0004 ? 'Z':'.',
1211            sr & 0x0002 ? 'V':'.',
1212            sr & 0x0001 ? 'C':'.');
1213         break;
1214
1215      case CPUINFO_STR_REGISTER + M68K_PC:         sprintf(info->s, "PC :%08X", m68k_get_reg(m68k, M68K_REG_PC)); break;
1216      case CPUINFO_STR_REGISTER + M68K_SR:           sprintf(info->s, "SR :%04X", m68k_get_reg(m68k, M68K_REG_SR)); break;
1217      case CPUINFO_STR_REGISTER + M68K_SP:           sprintf(info->s, "SP :%08X", m68k_get_reg(m68k, M68K_REG_SP)); break;
1218      case CPUINFO_STR_REGISTER + M68K_ISP:          sprintf(info->s, "ISP:%08X", m68k_get_reg(m68k, M68K_REG_ISP)); break;
1219      case CPUINFO_STR_REGISTER + M68K_USP:          sprintf(info->s, "USP:%08X", m68k_get_reg(m68k, M68K_REG_USP)); break;
1220      case CPUINFO_STR_REGISTER + M68K_D0:         sprintf(info->s, "D0 :%08X", m68k_get_reg(m68k, M68K_REG_D0)); break;
1221      case CPUINFO_STR_REGISTER + M68K_D1:         sprintf(info->s, "D1 :%08X", m68k_get_reg(m68k, M68K_REG_D1)); break;
1222      case CPUINFO_STR_REGISTER + M68K_D2:         sprintf(info->s, "D2 :%08X", m68k_get_reg(m68k, M68K_REG_D2)); break;
1223      case CPUINFO_STR_REGISTER + M68K_D3:         sprintf(info->s, "D3 :%08X", m68k_get_reg(m68k, M68K_REG_D3)); break;
1224      case CPUINFO_STR_REGISTER + M68K_D4:         sprintf(info->s, "D4 :%08X", m68k_get_reg(m68k, M68K_REG_D4)); break;
1225      case CPUINFO_STR_REGISTER + M68K_D5:         sprintf(info->s, "D5 :%08X", m68k_get_reg(m68k, M68K_REG_D5)); break;
1226      case CPUINFO_STR_REGISTER + M68K_D6:         sprintf(info->s, "D6 :%08X", m68k_get_reg(m68k, M68K_REG_D6)); break;
1227      case CPUINFO_STR_REGISTER + M68K_D7:         sprintf(info->s, "D7 :%08X", m68k_get_reg(m68k, M68K_REG_D7)); break;
1228      case CPUINFO_STR_REGISTER + M68K_A0:         sprintf(info->s, "A0 :%08X", m68k_get_reg(m68k, M68K_REG_A0)); break;
1229      case CPUINFO_STR_REGISTER + M68K_A1:         sprintf(info->s, "A1 :%08X", m68k_get_reg(m68k, M68K_REG_A1)); break;
1230      case CPUINFO_STR_REGISTER + M68K_A2:         sprintf(info->s, "A2 :%08X", m68k_get_reg(m68k, M68K_REG_A2)); break;
1231      case CPUINFO_STR_REGISTER + M68K_A3:         sprintf(info->s, "A3 :%08X", m68k_get_reg(m68k, M68K_REG_A3)); break;
1232      case CPUINFO_STR_REGISTER + M68K_A4:         sprintf(info->s, "A4 :%08X", m68k_get_reg(m68k, M68K_REG_A4)); break;
1233      case CPUINFO_STR_REGISTER + M68K_A5:         sprintf(info->s, "A5 :%08X", m68k_get_reg(m68k, M68K_REG_A5)); break;
1234      case CPUINFO_STR_REGISTER + M68K_A6:         sprintf(info->s, "A6 :%08X", m68k_get_reg(m68k, M68K_REG_A6)); break;
1235      case CPUINFO_STR_REGISTER + M68K_A7:         sprintf(info->s, "A7 :%08X", m68k_get_reg(m68k, M68K_REG_A7)); break;
1236      case CPUINFO_STR_REGISTER + M68K_PREF_ADDR:      sprintf(info->s, "PAR:%08X", m68k_get_reg(m68k, M68K_REG_PREF_ADDR)); break;
1237      case CPUINFO_STR_REGISTER + M68K_PREF_DATA:      sprintf(info->s, "PDA:%08X", m68k_get_reg(m68k, M68K_REG_PREF_DATA)); break;
1238      case CPUINFO_STR_REGISTER + M68K_MSP:         sprintf(info->s, "MSP:%08X", m68k_get_reg(m68k, M68K_REG_MSP)); break;
1239      case CPUINFO_STR_REGISTER + M68K_CACR:         sprintf(info->s, "CCR:%08X", m68k_get_reg(m68k, M68K_REG_CACR)); break;
1240      case CPUINFO_STR_REGISTER + M68K_CAAR:         sprintf(info->s, "CAR:%08X", m68k_get_reg(m68k, M68K_REG_CAAR)); break;
1241      case CPUINFO_STR_REGISTER + M68K_SFC:         sprintf(info->s, "SFC:%X",   m68k_get_reg(m68k, M68K_REG_SFC)); break;
1242      case CPUINFO_STR_REGISTER + M68K_DFC:         sprintf(info->s, "DFC:%X",   m68k_get_reg(m68k, M68K_REG_DFC)); break;
1243      case CPUINFO_STR_REGISTER + M68K_VBR:         sprintf(info->s, "VBR:%08X", m68k_get_reg(m68k, M68K_REG_VBR)); break;
1244   }
1245}
1246
1247#endif /* HAS_M68040 */
1248
src/emu/cpu/m68000/m68k.h
r3767r3768
1#pragma once
2
3#ifndef __M68K_H__
4#define __M68K_H__
5
6/* ======================================================================== */
7/* ========================= LICENSING & COPYRIGHT ======================== */
8/* ======================================================================== */
9/*
10 *                                  MUSASHI
11 *                                Version 3.32
12 *
13 * A portable Motorola M680x0 processor emulation engine.
14 * Copyright Karl Stenerud.  All rights reserved.
15 *
16 * This code may be freely used for non-commercial purposes as long as this
17 * copyright notice remains unaltered in the source code and any binary files
18 * containing this code in compiled form.
19 *
20 * All other licensing terms must be negotiated with the author
21 * (Karl Stenerud).
22 *
23 * The latest version of this code can be obtained at:
24 * http://kstenerud.cjb.net
25 */
26
27/* ======================================================================== */
28/* ============================ GENERAL DEFINES =========================== */
29
30/* ======================================================================== */
31
32/* CPU types for use in m68k_set_cpu_type() */
33enum
34{
35   M68K_CPU_TYPE_INVALID,
36   M68K_CPU_TYPE_68000,
37   M68K_CPU_TYPE_68008,
38   M68K_CPU_TYPE_68010,
39   M68K_CPU_TYPE_68EC020,
40   M68K_CPU_TYPE_68020,
41   M68K_CPU_TYPE_68030,   /* Supported by disassembler ONLY */
42   M68K_CPU_TYPE_68040      /* Supported by disassembler ONLY */
43};
44
45/* Registers used by m68k_get_reg() and m68k_set_reg() */
46enum _m68k_register_t
47{
48   /* Real registers */
49   M68K_REG_D0,      /* Data registers */
50   M68K_REG_D1,
51   M68K_REG_D2,
52   M68K_REG_D3,
53   M68K_REG_D4,
54   M68K_REG_D5,
55   M68K_REG_D6,
56   M68K_REG_D7,
57   M68K_REG_A0,      /* Address registers */
58   M68K_REG_A1,
59   M68K_REG_A2,
60   M68K_REG_A3,
61   M68K_REG_A4,
62   M68K_REG_A5,
63   M68K_REG_A6,
64   M68K_REG_A7,
65   M68K_REG_PC,      /* Program Counter */
66   M68K_REG_SR,      /* Status Register */
67   M68K_REG_SP,      /* The current Stack Pointer (located in A7) */
68   M68K_REG_USP,      /* User Stack Pointer */
69   M68K_REG_ISP,      /* Interrupt Stack Pointer */
70   M68K_REG_MSP,      /* Master Stack Pointer */
71   M68K_REG_SFC,      /* Source Function Code */
72   M68K_REG_DFC,      /* Destination Function Code */
73   M68K_REG_VBR,      /* Vector Base Register */
74   M68K_REG_CACR,      /* Cache Control Register */
75   M68K_REG_CAAR,      /* Cache Address Register */
76
77   /* Assumed registers */
78   /* These are cheat registers which emulate the 1-longword prefetch
79     * present in the 68000 and 68010.
80     */
81   M68K_REG_PREF_ADDR,   /* Last prefetch address */
82   M68K_REG_PREF_DATA,   /* Last prefetch data */
83
84   /* Convenience registers */
85   M68K_REG_PPC,      /* Previous value in the program counter */
86   M68K_REG_IR,      /* Instruction register */
87   M68K_REG_CPU_TYPE   /* Type of CPU being run */
88};
89typedef enum _m68k_register_t m68k_register_t;
90
91
92
93/* ======================================================================== */
94/* ====================== FUNCTIONS CALLED BY THE CPU ===================== */
95/* ======================================================================== */
96
97/* You will have to implement these functions */
98
99/* read/write functions called by the CPU to access memory.
100 * while values used are 32 bits, only the appropriate number
101 * of bits are relevant (i.e. in write_memory_8, only the lower 8 bits
102 * of value should be written to memory).
103 *
104 * NOTE: I have separated the immediate and PC-relative memory fetches
105 *       from the other memory fetches because some systems require
106 *       differentiation between PROGRAM and DATA fetches (usually
107 *       for security setups such as encryption).
108 *       This separation can either be achieved by setting
109 *       M68K_SEPARATE_READS in m68kconf.h and defining
110 *       the read functions, or by setting M68K_EMULATE_FC and
111 *       making a function code callback function.
112 *       Using the callback offers better emulation coverage
113 *       because you can also monitor whether the CPU is in SYSTEM or
114 *       USER mode, but it is also slower.
115 */
116
117/* Read from anywhere */
118unsigned int  m68k_read_memory_8(m68ki_cpu_core *m68k, unsigned int address);
119unsigned int  m68k_read_memory_16(m68ki_cpu_core *m68k, unsigned int address);
120unsigned int  m68k_read_memory_32(m68ki_cpu_core *m68k, unsigned int address);
121
122/* Read data immediately following the PC */
123unsigned int  m68k_read_immediate_16(m68ki_cpu_core *m68k, unsigned int address);
124unsigned int  m68k_read_immediate_32(m68ki_cpu_core *m68k, unsigned int address);
125
126/* Read data relative to the PC */
127unsigned int  m68k_read_pcrelative_8(m68ki_cpu_core *m68k, unsigned int address);
128unsigned int  m68k_read_pcrelative_16(m68ki_cpu_core *m68k, unsigned int address);
129unsigned int  m68k_read_pcrelative_32(m68ki_cpu_core *m68k, unsigned int address);
130
131/* Memory access for the disassembler */
132unsigned int m68k_read_disassembler_8  (unsigned int address);
133unsigned int m68k_read_disassembler_16 (unsigned int address);
134unsigned int m68k_read_disassembler_32 (unsigned int address);
135
136/* Write to anywhere */
137void m68k_write_memory_8(m68ki_cpu_core *m68k, unsigned int address, unsigned int value);
138void m68k_write_memory_16(m68ki_cpu_core *m68k, unsigned int address, unsigned int value);
139void m68k_write_memory_32(m68ki_cpu_core *m68k, unsigned int address, unsigned int value);
140
141/* Special call to simulate undocumented 68k behavior when move.l with a
142 * predecrement destination mode is executed.
143 * To simulate real 68k behavior, first write the high word to
144 * [address+2], and then write the low word to [address].
145 */
146void m68k_write_memory_32_pd(m68ki_cpu_core *m68k, unsigned int address, unsigned int value);
147
148
149
150/* ======================================================================== */
151/* ============================== CALLBACKS =============================== */
152/* ======================================================================== */
153
154/* These functions allow you to set callbacks to the host when specific events
155 * occur.  Note that you must enable the corresponding value in m68kconf.h
156 * in order for these to do anything useful.
157 * Note: I have defined default callbacks which are used if you have enabled
158 * the corresponding #define in m68kconf.h but either haven't assigned a
159 * callback or have assigned a callback of NULL.
160 */
161
162/* Set the callback for an interrupt acknowledge.
163 * The CPU will call the callback with the interrupt level being acknowledged.
164 * The host program must return either a vector from 0x02-0xff, or one of the
165 * special interrupt acknowledge values specified earlier in this header.
166 * If this is not implemented, the CPU will always assume an autovectored
167 * interrupt, and will automatically clear the interrupt request when it
168 * services the interrupt.
169 * Default behavior: return M68K_INT_ACK_AUTOVECTOR.
170 */
171void m68k_set_int_ack_callback(m68ki_cpu_core *m68k, void *param, int  (*callback)(void *param, int int_level));
172
173
174/* Set the callback for a breakpoint acknowledge (68010+).
175 * The CPU will call the callback with whatever was in the data field of the
176 * BKPT instruction for 68020+, or 0 for 68010.
177 * Default behavior: do nothing.
178 */
179void m68k_set_bkpt_ack_callback(m68ki_cpu_core *m68k, void (*callback)(unsigned int data));
180
181
182/* Set the callback for the RESET instruction.
183 * The CPU calls this callback every time it encounters a RESET instruction.
184 * Default behavior: do nothing.
185 */
186void m68k_set_reset_instr_callback(m68ki_cpu_core *m68k, void  (*callback)(void));
187
188
189/* Set the callback for the CMPI.L #v, Dn instruction.
190 * The CPU calls this callback every time it encounters a CMPI.L #v, Dn instruction.
191 * Default behavior: do nothing.
192 */
193void m68k_set_cmpild_instr_callback(m68ki_cpu_core *m68k, void  (*callback)(unsigned int val, int reg));
194
195
196/* Set the callback for the RTE instruction.
197 * The CPU calls this callback every time it encounters a RTE instruction.
198 * Default behavior: do nothing.
199 */
200void m68k_set_rte_instr_callback(m68ki_cpu_core *m68k, void  (*callback)(void));
201
202/* Set the callback for the TAS instruction.
203 * The CPU calls this callback every time it encounters a TAS instruction.
204 * Default behavior: return 1, allow writeback.
205 */
206void m68k_set_tas_instr_callback(m68ki_cpu_core *m68k, int  (*callback)(void));
207
208
209
210/* Set the callback for CPU function code changes.
211 * You must enable M68K_EMULATE_FC in m68kconf.h.
212 * The CPU calls this callback with the function code before every memory
213 * access to set the CPU's function code according to what kind of memory
214 * access it is (supervisor/user, program/data and such).
215 * Default behavior: do nothing.
216 */
217void m68k_set_fc_callback(m68ki_cpu_core *m68k, void  (*callback)(unsigned int new_fc));
218
219
220
221/* ======================================================================== */
222/* ====================== FUNCTIONS TO ACCESS THE CPU ===================== */
223/* ======================================================================== */
224
225/* Use this function to set the CPU type you want to emulate.
226 * Currently supported types are: M68K_CPU_TYPE_68000, M68K_CPU_TYPE_68008,
227 * M68K_CPU_TYPE_68010, M68K_CPU_TYPE_EC020, and M68K_CPU_TYPE_68020.
228 */
229void m68k_set_cpu_type(m68ki_cpu_core *m68k, unsigned int cpu_type);
230
231/* Do whatever initialisations the core requires.  Should be called
232 * at least once at init time.
233 */
234void m68k_init(m68ki_cpu_core *m68k);
235
236/* Pulse the RESET pin on the CPU.
237 * You *MUST* reset the CPU at least once to initialize the emulation
238 * Note: If you didn't call m68k_set_cpu_type() before resetting
239 *       the CPU for the first time, the CPU will be set to
240 *       M68K_CPU_TYPE_68000.
241 */
242void m68k_pulse_reset(m68ki_cpu_core *m68k);
243
244/* execute num_cycles worth of instructions.  returns number of cycles used */
245int m68k_execute(m68ki_cpu_core *m68k, int num_cycles);
246
247/* These functions let you read/write/modify the number of cycles left to run
248 * while m68k_execute() is running.
249 * These are useful if the 68k accesses a memory-mapped port on another device
250 * that requires immediate processing by another CPU.
251 */
252int m68k_cycles_run(m68ki_cpu_core *m68k);              /* Number of cycles run so far */
253int m68k_cycles_remaining(m68ki_cpu_core *m68k);        /* Number of cycles left */
254void m68k_modify_timeslice(m68ki_cpu_core *m68k, int cycles); /* Modify cycles left */
255void m68k_end_timeslice(m68ki_cpu_core *m68k);          /* End timeslice now */
256
257/* Set the IPL0-IPL2 pins on the CPU (IRQ).
258 * A transition from < 7 to 7 will cause a non-maskable interrupt (NMI).
259 * Setting IRQ to 0 will clear an interrupt request.
260 */
261void m68k_set_irq(m68ki_cpu_core *m68k, unsigned int int_level);
262
263/* Set the virtual irq lines, where the highest level
264 * active line is automatically selected.  If you use this function,
265 * do not use m68k_set_irq.
266 */
267void m68k_set_virq(m68ki_cpu_core *m68k, unsigned int level, unsigned int active);
268unsigned int m68k_get_virq(m68ki_cpu_core *m68k, unsigned int level);
269
270/* Halt the CPU as if you pulsed the HALT pin. */
271void m68k_pulse_halt(m68ki_cpu_core *m68k);
272
273
274/* Context switching to allow multiple CPUs */
275
276/* Get the size of the cpu context in bytes */
277unsigned int m68k_context_size(void);
278
279/* Get a cpu context */
280unsigned int m68k_get_context(void* dst);
281
282/* set the current cpu context */
283void m68k_set_context(void* dst);
284
285/* Register the CPU state information */
286void m68k_state_register(m68ki_cpu_core *m68k, const char *type, int index);
287
288
289/* Peek at the internals of a CPU context.  This can either be a context
290 * retrieved using m68k_get_context() or the currently running context.
291 * If context is NULL, the currently running CPU context will be used.
292 */
293unsigned int m68k_get_reg(m68ki_cpu_core *m68k, m68k_register_t regnum);
294
295/* Poke values into the internals of the currently running CPU context */
296void m68k_set_reg(m68ki_cpu_core *m68k, m68k_register_t reg, unsigned int value);
297
298/* Check if an instruction is valid for the specified CPU type */
299unsigned int m68k_is_valid_instruction(unsigned int instruction, unsigned int cpu_type);
300
301/* Disassemble 1 instruction using the epecified CPU type at pc.  Stores
302 * disassembly in str_buff and returns the size of the instruction in bytes.
303 */
304unsigned int m68k_disassemble(char* str_buff, unsigned int pc, unsigned int cpu_type);
305
306/* Same as above but accepts raw opcode data directly rather than fetching
307 * via the read/write interfaces.
308 */
309unsigned int m68k_disassemble_raw(char* str_buff, unsigned int pc, const unsigned char* opdata, const unsigned char* argdata, unsigned int cpu_type);
310
311
312/* ======================================================================== */
313/* ============================== MAME STUFF ============================== */
314/* ======================================================================== */
315
316#include "m68kmame.h"
317
318
319/* ======================================================================== */
320/* ============================== END OF FILE ============================= */
321/* ======================================================================== */
322
323#endif /* __M68K_H__ */
src/emu/cpu/m68000/m68kmame.h
r3767r3768
1#pragma once
2
3#ifndef __M68KMAME_H__
4#define __M68KMAME_H__
5
6/* ======================================================================== */
7/* ============================== MAME STUFF ============================== */
8/* ======================================================================== */
9
10#include "debugger.h"
11#include "deprecat.h"
12#include "m68000.h"
13
14#ifndef __M68KCPU_H__
15#define m68ki_cpu_core void
16#endif
17
18#define OPT_ON 1
19#define OPT_OFF 0
20
21/* Configuration switches (see m68kconf.h for explanation) */
22#define M68K_SEPARATE_READS         OPT_ON
23
24#define M68K_EMULATE_TRACE          OPT_OFF
25
26#define M68K_EMULATE_FC             OPT_OFF
27#define M68K_SET_FC_CALLBACK(A)
28
29#define M68K_LOG_ENABLE             OPT_OFF
30#define M68K_LOG_1010_1111          OPT_OFF
31#define M68K_LOG_FILEHANDLE         errorlog
32
33#define M68K_USE_64_BIT             OPT_OFF
34
35
36extern m68k_memory_interface m68k_memory_intf;
37extern offs_t m68k_encrypted_opcode_start[MAX_CPU];
38extern offs_t m68k_encrypted_opcode_end[MAX_CPU];
39
40#define m68k_read_memory_8(M, A)            (*m68k_memory_intf.read8)(A)
41#define m68k_read_memory_16(M, A)            (*m68k_memory_intf.read16)(A)
42#define m68k_read_memory_32(M, A)            (*m68k_memory_intf.read32)(A)
43
44#define m68k_read_immediate_16(M, A)         (*m68k_memory_intf.readimm16)(A)
45#define m68k_read_immediate_32(M, A)         m68kx_read_immediate_32(M, A)
46#define m68k_read_pcrelative_8(M, A)         m68kx_read_pcrelative_8(M, A)
47#define m68k_read_pcrelative_16(M, A)         m68kx_read_pcrelative_16(M, A)
48#define m68k_read_pcrelative_32(M, A)         m68kx_read_pcrelative_32(M, A)
49
50#define m68k_read_disassembler_16(M, A)         m68k_read_immediate_16(M, A)
51#define m68k_read_disassembler_32(M, A)         m68kx_read_immediate_32(M, A)
52
53#define m68k_write_memory_8(M, A, V)         (*m68k_memory_intf.write8)(A, V)
54#define m68k_write_memory_16(M, A, V)         (*m68k_memory_intf.write16)(A, V)
55#define m68k_write_memory_32(M, A, V)         (*m68k_memory_intf.write32)(A, V)
56#define m68k_write_memory_32_pd(M, A, V)      m68kx_write_memory_32_pd(M, A, V)
57
58
59INLINE unsigned int m68k_read_immediate_32(m68ki_cpu_core *m68k, unsigned int address);
60INLINE unsigned int m68k_read_pcrelative_8(m68ki_cpu_core *m68k, unsigned int address);
61INLINE unsigned int m68k_read_pcrelative_16(m68ki_cpu_core *m68k, unsigned int address);
62INLINE unsigned int m68k_read_pcrelative_32(m68ki_cpu_core *m68k, unsigned int address);
63INLINE void m68k_write_memory_32_pd(m68ki_cpu_core *m68k, unsigned int address, unsigned int value);
64
65
66INLINE unsigned int m68kx_read_immediate_32(m68ki_cpu_core *m68k, unsigned int address)
67{
68   return ((m68k_read_immediate_16(m68k, address) << 16) | m68k_read_immediate_16(m68k, (address)+2));
69}
70
71INLINE unsigned int m68kx_read_pcrelative_8(m68ki_cpu_core *m68k, unsigned int address)
72{
73   if (address >= m68k_encrypted_opcode_start[cpu_getactivecpu()] &&
74         address < m68k_encrypted_opcode_end[cpu_getactivecpu()])
75      return ((m68k_read_immediate_16(m68k, address&~1)>>(8*(1-(address & 1))))&0xff);
76   else
77      return m68k_read_memory_8(m68k, address);
78}
79
80INLINE unsigned int m68kx_read_pcrelative_16(m68ki_cpu_core *m68k, unsigned int address)
81{
82   if (address >= m68k_encrypted_opcode_start[cpu_getactivecpu()] &&
83         address < m68k_encrypted_opcode_end[cpu_getactivecpu()])
84      return m68k_read_immediate_16(m68k, address);
85   else
86      return m68k_read_memory_16(m68k, address);
87}
88
89INLINE unsigned int m68kx_read_pcrelative_32(m68ki_cpu_core *m68k, unsigned int address)
90{
91   if (address >= m68k_encrypted_opcode_start[cpu_getactivecpu()] &&
92         address < m68k_encrypted_opcode_end[cpu_getactivecpu()])
93      return m68k_read_immediate_32(m68k, address);
94   else
95      return m68k_read_memory_32(m68k, address);
96}
97
98
99/* Special call to simulate undocumented 68k behavior when move.l with a
100 * predecrement destination mode is executed.
101 * A real 68k first writes the high word to [address+2], and then writes the
102 * low word to [address].
103 */
104INLINE void m68kx_write_memory_32_pd(m68ki_cpu_core *m68k, unsigned int address, unsigned int value)
105{
106   (*m68k_memory_intf.write16)(address+2, value>>16);
107   (*m68k_memory_intf.write16)(address, value&0xffff);
108}
109
110
111void m68k_set_encrypted_opcode_range(int cpunum, offs_t start, offs_t end);
112
113
114/* ======================================================================== */
115/* ============================== END OF FILE ============================= */
116/* ======================================================================== */
117
118#endif /* __M68KMAME_H__ */
src/emu/cpu/mips/mipsdasm.c
r3767r3768
1/*
2 * MIPS disassembler for the MAME project written by smf
3 *
4 */
5
6#include "psx.h"
7
8static char *make_signed_hex_str_16( UINT32 value )
9{
10   static char s_hex[ 20 ];
11
12   value &= 0xffff;
13   if( value & 0x8000 )
14   {
15      sprintf( s_hex, "-$%x", ( 0 - value ) & 0x7fff );
16   }
17   else
18   {
19      sprintf( s_hex, "$%x", value & 0x7fff );
20   }
21   return s_hex;
22}
23
24static const char *const s_cpugenreg[] =
25{
26   "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
27   "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
28   "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
29   "t8", "t9", "k0", "k1", "gp", "sp", "fp", "ra"
30};
31
32static const char *const s_cp0genreg[] =
33{
34   "!Index", "!Random", "!EntryLo", "BPC", "!Context", "BDA", "TAR", "DCIC",
35   "BadA", "BDAM", "!EntryHi", "BPCM", "SR", "Cause", "EPC", "PRId",
36   "cp0r16", "cp0r17", "cp0r18", "cp0r19", "cp0r20", "cp0r21", "cp0r22", "cp0r23",
37   "cp0r24", "cp0r25", "cp0r26", "cp0r27", "cp0r28", "cp0r29", "cp0r30", "cp0r31"
38};
39
40static const char *const s_cp0ctlreg[] =
41{
42   "cp0cr0", "cp0cr1", "cp0cr2", "cp0cr3", "cp0cr4", "cp0cr5", "cp0cr6", "cp0cr7",
43   "cp0cr8", "cp0cr9", "cp0cr10", "cp0cr11", "cp0cr12", "cp0cr13", "cp0cr14", "cp0cr15",
44   "cp0cr16", "cp0cr17", "cp0cr18", "cp0cr19", "cp0cr20", "cp0cr21", "cp0cr22", "cp0cr23",
45   "cp0cr24", "cp0cr25", "cp0cr26", "cp0cr27", "cp0cr28", "cp0cr29", "cp0cr30", "cp0cr31"
46};
47
48static const char *const s_cp1genreg[] =
49{
50   "cp1r0", "cp1r1", "cp1r2", "cp1r3", "cp1r4", "cp1r5", "cp1r6", "cp1r7",
51   "cp1r8", "cp1r9", "cp1r10", "cp1r11", "cp1r12", "cp1r13", "cp1r14", "cp1r15",
52   "cp1r16", "cp1r17", "cp1r18", "cp1r19", "cp1r20", "cp1r21", "cp1r22", "cp1r22",
53   "cp1r23", "cp1r24", "cp1r25", "cp1r26", "cp1r27", "cp1r28", "cp1r29", "cp1r30"
54};
55
56static const char *const s_cp1ctlreg[] =
57{
58   "cp1cr0", "cp1cr1", "cp1cr2", "cp1cr3", "cp1cr4", "cp1cr5", "cp1cr6", "cp1cr7",
59   "cp1cr8", "cp1cr9", "cp1cr10", "cp1cr11", "cp1cr12", "cp1cr13", "cp1cr14", "cp1cr15",
60   "cp1cr16", "cp1cr17", "cp1cr18", "cp1cr19", "cp1cr20", "cp1cr21", "cp1cr22", "cp1cr23",
61   "cp1cr24", "cp1cr25", "cp1cr26", "cp1cr27", "cp1cr28", "cp1cr29", "cp1cr30", "cp1cr31"
62};
63
64static const char *const s_cp2genreg[] =
65{
66   "vxy0", "vz0", "vxy1", "vz1", "vxy2", "vz2", "rgb", "otz",
67   "ir0", "ir1", "ir2", "ir3", "sxy0", "sxy1", "sxy2", "sxyp",
68   "sz0", "sz1", "sz2", "sz3", "rgb0", "rgb1", "rgb2", "cp2cr23",
69   "mac0", "mac1", "mac2", "mac3", "irgb", "orgb", "lzcs", "lzcr"
70};
71
72static const char *const s_cp2ctlreg[] =
73{
74   "r11r12", "r13r21", "r22r23", "r31r32", "r33", "trx", "try", "trz",
75   "l11l12", "l13l21", "l22l23", "l31l32", "l33", "rbk", "gbk", "bbk",
76   "lr1lr2", "lr3lg1", "lg2lg3", "lb1lb2", "lb3", "rfc", "gfc", "bfc",
77   "ofx", "ofy", "h", "dqa", "dqb", "zsf3", "zsf4", "flag"
78};
79
80static const char *const s_cp3genreg[] =
81{
82   "cp3r0", "cp3r1", "cp3r2", "cp3r3", "cp3r4", "cp3r5", "cp3r6", "cp3r7",
83   "cp3r8", "cp3r9", "cp3r10", "cp3r11", "cp3r12", "cp3r13", "cp3r14", "cp3r15",
84   "cp3r16", "cp3r17", "cp3r18", "cp3r19", "cp3r20", "cp3r21", "cp3r22", "cp3r22",
85   "cp3r23", "cp3r24", "cp3r25", "cp3r26", "cp3r27", "cp3r28", "cp3r29", "cp3r30"
86};
87
88static const char *const s_cp3ctlreg[] =
89{
90   "cp3cr0", "cp3cr1", "cp3cr2", "cp3cr3", "cp3cr4", "cp3cr5", "cp3cr6", "cp3cr7",
91   "cp3cr8", "cp3cr9", "cp3cr10", "cp3cr11", "cp3cr12", "cp3cr13", "cp3cr14", "cp3cr15",
92   "cp3cr16", "cp3cr17", "cp3cr18", "cp3cr19", "cp3cr20", "cp3cr21", "cp3cr22", "cp3cr23",
93   "cp3cr24", "cp3cr25", "cp3cr26", "cp3cr27", "cp3cr28", "cp3cr29", "cp3cr30", "cp3cr31"
94};
95
96static const char *const s_gtesf[] =
97{
98   "0", "12"
99};
100
101static const char *const s_gtemx[] =
102{
103   "rm", "lm", "cm", "0"
104};
105
106static const char *const s_gtev[] =
107{
108   "v0", "v1", "v2", "ir"
109};
110
111static const char *const s_gtecv[] =
112{
113   "tr", "bk", "fc", "0"
114};
115
116static const char *const s_gtelm[] =
117{
118   "0", "1"
119};
120
121static char *effective_address( UINT32 pc, UINT32 op )
122{
123   static char s_address[ 20 ];
124#ifndef STANDALONE
125   if( pc == activecpu_get_pc() )
126   {
127      sprintf( s_address, "%s(%s) ; 0x%08x", make_signed_hex_str_16( INS_IMMEDIATE( op ) ), s_cpugenreg[ INS_RS( op ) ],
128         (UINT32)( activecpu_get_reg( MIPS_R0 + INS_RS( op ) ) + (INT16)INS_IMMEDIATE( op ) ) );
129      return s_address;
130   }
131#endif
132   sprintf( s_address, "%s(%s)", make_signed_hex_str_16( INS_IMMEDIATE( op ) ), s_cpugenreg[ INS_RS( op ) ] );
133   return s_address;
134}
135
136static UINT32 relative_address( UINT32 pc, UINT32 op )
137{
138   UINT32 nextpc = pc + 4;
139#ifndef STANDALONE
140   if( pc == activecpu_get_pc() && activecpu_get_reg( MIPS_DELAYR ) == 32 )
141   {
142      nextpc = activecpu_get_reg( MIPS_DELAYV );
143   }
144#endif
145   return nextpc + ( MIPS_WORD_EXTEND( INS_IMMEDIATE( op ) ) << 2 );
146}
147
148static UINT32 jump_address( UINT32 pc, UINT32 op )
149{
150   UINT32 nextpc = pc + 4;
151#ifndef STANDALONE
152   if( pc == activecpu_get_pc() && activecpu_get_reg( MIPS_DELAYR ) == 32 )
153   {
154      nextpc = activecpu_get_reg( MIPS_DELAYV );
155   }
156#endif
157   return ( nextpc & 0xf0000000 ) + ( INS_TARGET( op ) << 2 );
158}
159
160static UINT32 fetch_op( const UINT8 *opram )
161{
162   return ( opram[ 3 ] << 24 ) | ( opram[ 2 ] << 16 ) | ( opram[ 1 ] << 8 ) | ( opram[ 0 ] << 0 );
163}
164
165static char *upper_address( UINT32 op, const UINT8 *opram )
166{
167   static char s_address[ 20 ];
168   UINT32 nextop = fetch_op( opram );
169
170   if( INS_OP( nextop ) == OP_ORI && INS_RT( op ) == INS_RS( nextop ) )
171   {
172      sprintf( s_address, "$%04x ; 0x%08x", INS_IMMEDIATE( op ), ( INS_IMMEDIATE( op ) << 16 ) | INS_IMMEDIATE( nextop ) );
173   }
174   else if( INS_OP( nextop ) == OP_ADDIU && INS_RT( op ) == INS_RS( nextop ) )
175   {
176      sprintf( s_address, "$%04x ; 0x%08x", INS_IMMEDIATE( op ), ( INS_IMMEDIATE( op ) << 16 ) + (INT16) INS_IMMEDIATE( nextop ) );
177   }
178   else
179   {
180      sprintf( s_address, "$%04x", INS_IMMEDIATE( op ) );
181   }
182
183   return s_address;
184}
185
186unsigned DasmMIPS( char *buffer, UINT32 pc, const UINT8 *opram )
187{
188   UINT32 op;
189   const UINT8 *oldopram;
190   UINT32 flags = 0;
191
192   oldopram = opram;
193   op = fetch_op( opram );
194   opram += 4;
195
196   sprintf( buffer, "dw      $%08x", op );
197
198   switch( INS_OP( op ) )
199   {
200   case OP_SPECIAL:
201      switch( INS_FUNCT( op ) )
202      {
203      case FUNCT_SLL:
204         if( op == 0 )
205         {
206            /* the standard nop is "sll     zero,zero,$0000" */
207            sprintf( buffer, "nop" );
208         }
209         else
210         {
211            sprintf( buffer, "sll     %s,%s,$%02x", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RT( op ) ], INS_SHAMT( op ) );
212         }
213         break;
214      case FUNCT_SRL:
215         sprintf( buffer, "srl     %s,%s,$%02x", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RT( op ) ], INS_SHAMT( op ) );
216         break;
217      case FUNCT_SRA:
218         sprintf( buffer, "sra     %s,%s,$%02x", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RT( op ) ], INS_SHAMT( op ) );
219         break;
220      case FUNCT_SLLV:
221         sprintf( buffer, "sllv    %s,%s,%s", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RT( op ) ], s_cpugenreg[ INS_RS( op ) ] );
222         break;
223      case FUNCT_SRLV:
224         sprintf( buffer, "srlv    %s,%s,%s", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RT( op ) ], s_cpugenreg[ INS_RS( op ) ] );
225         break;
226      case FUNCT_SRAV:
227         sprintf( buffer, "srav    %s,%s,%s", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RT( op ) ], s_cpugenreg[ INS_RS( op ) ] );
228         break;
229      case FUNCT_JR:
230         sprintf( buffer, "jr      %s", s_cpugenreg[ INS_RS( op ) ] );
231         if( INS_RS( op ) == 31 )
232         {
233            flags = DASMFLAG_STEP_OUT;
234         }
235         break;
236      case FUNCT_JALR:
237         sprintf( buffer, "jalr    %s,%s", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RS( op ) ] );
238         flags = DASMFLAG_STEP_OVER | DASMFLAG_STEP_OVER_EXTRA( 1 );
239         break;
240      case FUNCT_SYSCALL:
241         sprintf( buffer, "syscall $%05x", INS_CODE( op ) );
242         flags = DASMFLAG_STEP_OVER;
243         break;
244      case FUNCT_BREAK:
245         sprintf( buffer, "break   $%05x", INS_CODE( op ) );
246         flags = DASMFLAG_STEP_OVER;
247         break;
248      case FUNCT_MFHI:
249         sprintf( buffer, "mfhi    %s", s_cpugenreg[ INS_RD( op ) ] );
250         break;
251      case FUNCT_MTHI:
252         sprintf( buffer, "mthi    %s", s_cpugenreg[ INS_RS( op ) ] );
253         break;
254      case FUNCT_MFLO:
255         sprintf( buffer, "mflo    %s", s_cpugenreg[ INS_RD( op ) ] );
256         break;
257      case FUNCT_MTLO:
258         sprintf( buffer, "mtlo    %s", s_cpugenreg[ INS_RS( op ) ] );
259         break;
260      case FUNCT_MULT:
261         sprintf( buffer, "mult    %s,%s", s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ] );
262         break;
263      case FUNCT_MULTU:
264         sprintf( buffer, "multu   %s,%s", s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ] );
265         break;
266      case FUNCT_DIV:
267         sprintf( buffer, "div     %s,%s", s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ] );
268         break;
269      case FUNCT_DIVU:
270         sprintf( buffer, "divu    %s,%s", s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ] );
271         break;
272      case FUNCT_ADD:
273         sprintf( buffer, "add     %s,%s,%s", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ] );
274         break;
275      case FUNCT_ADDU:
276         sprintf( buffer, "addu    %s,%s,%s", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ] );
277         break;
278      case FUNCT_SUB:
279         sprintf( buffer, "sub     %s,%s,%s", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ] );
280         break;
281      case FUNCT_SUBU:
282         sprintf( buffer, "subu    %s,%s,%s", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ] );
283         break;
284      case FUNCT_AND:
285         sprintf( buffer, "and     %s,%s,%s", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ] );
286         break;
287      case FUNCT_OR:
288         sprintf( buffer, "or      %s,%s,%s", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ] );
289         break;
290      case FUNCT_XOR:
291         sprintf( buffer, "xor     %s,%s,%s", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ] );
292         break;
293      case FUNCT_NOR:
294         sprintf( buffer, "nor     %s,%s,%s", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ] );
295         break;
296      case FUNCT_SLT:
297         sprintf( buffer, "slt     %s,%s,%s", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ] );
298         break;
299      case FUNCT_SLTU:
300         sprintf( buffer, "sltu    %s,%s,%s", s_cpugenreg[ INS_RD( op ) ], s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ] );
301         break;
302      }
303      break;
304   case OP_REGIMM:
305      switch( INS_RT_REGIMM( op ) )
306      {
307      case RT_BLTZ:
308         if( INS_RT( op ) == RT_BLTZAL )
309         {
310            sprintf( buffer, "bltzal  %s,$%08x", s_cpugenreg[ INS_RS( op ) ], relative_address( pc, op ) );
311            flags = DASMFLAG_STEP_OVER | DASMFLAG_STEP_OVER_EXTRA( 1 );
312         }
313         else
314         {
315            sprintf( buffer, "bltz    %s,$%08x", s_cpugenreg[ INS_RS( op ) ], relative_address( pc, op ) );
316         }
317         break;
318      case RT_BGEZ:
319         if( INS_RT( op ) == RT_BGEZAL )
320         {
321            sprintf( buffer, "bgezal  %s,$%08x", s_cpugenreg[ INS_RS( op ) ], relative_address( pc, op ) );
322            flags = DASMFLAG_STEP_OVER | DASMFLAG_STEP_OVER_EXTRA( 1 );
323         }
324         else
325         {
326            sprintf( buffer, "bgez    %s,$%08x", s_cpugenreg[ INS_RS( op ) ], relative_address( pc, op ) );
327         }
328         break;
329      }
330      break;
331   case OP_J:
332      sprintf( buffer, "j       $%08x", jump_address( pc, op ) );
333      break;
334   case OP_JAL:
335      sprintf( buffer, "jal     $%08x", jump_address( pc, op ) );
336      flags = DASMFLAG_STEP_OVER | DASMFLAG_STEP_OVER_EXTRA( 1 );
337      break;
338   case OP_BEQ:
339      sprintf( buffer, "beq     %s,%s,$%08x", s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ], relative_address( pc, op ) );
340      break;
341   case OP_BNE:
342      sprintf( buffer, "bne     %s,%s,$%08x", s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ], relative_address( pc, op ) );
343      break;
344   case OP_BLEZ:
345      sprintf( buffer, "blez    %s,%s,$%08x", s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ], relative_address( pc, op ) );
346      break;
347   case OP_BGTZ:
348      sprintf( buffer, "bgtz    %s,%s,$%08x", s_cpugenreg[ INS_RS( op ) ], s_cpugenreg[ INS_RT( op ) ], relative_address( pc, op ) );
349      break;
350   case OP_ADDI:
351      sprintf( buffer, "addi    %s,%s,%s", s_cpugenreg[ INS_RT( op ) ], s_cpugenreg[ INS_RS( op ) ], make_signed_hex_str_16( INS_IMMEDIATE( op ) ) );
352      break;
353   case OP_ADDIU:
354      sprintf( buffer, "addiu   %s,%s,%s", s_cpugenreg[ INS_RT( op ) ], s_cpugenreg[ INS_RS( op ) ], make_signed_hex_str_16( INS_IMMEDIATE( op ) ) );
355      break;
356   case OP_SLTI:
357      sprintf( buffer, "slti    %s,%s,%s", s_cpugenreg[ INS_RT( op ) ], s_cpugenreg[ INS_RS( op ) ], make_signed_hex_str_16( INS_IMMEDIATE( op ) ) );
358      break;
359   case OP_SLTIU:
360      sprintf( buffer, "sltiu   %s,%s,%s", s_cpugenreg[ INS_RT( op ) ], s_cpugenreg[ INS_RS( op ) ], make_signed_hex_str_16( INS_IMMEDIATE( op ) ) );
361      break;
362   case OP_ANDI:
363      sprintf( buffer, "andi    %s,%s,$%04x", s_cpugenreg[ INS_RT( op ) ], s_cpugenreg[ INS_RS( op ) ], INS_IMMEDIATE( op ) );
364      break;
365   case OP_ORI:
366      sprintf( buffer, "ori     %s,%s,$%04x", s_cpugenreg[ INS_RT( op ) ], s_cpugenreg[ INS_RS( op ) ], INS_IMMEDIATE( op ) );
367      break;
368   case OP_XORI:
369      sprintf( buffer, "xori    %s,%s,$%04x", s_cpugenreg[ INS_RT( op ) ], s_cpugenreg[ INS_RS( op ) ], INS_IMMEDIATE( op ) );
370      break;
371   case OP_LUI:
372      sprintf( buffer, "lui     %s,%s", s_cpugenreg[ INS_RT( op ) ], upper_address( op, opram ) );
373      break;
374   case OP_COP0:
375      switch( INS_RS( op ) )
376      {
377      case RS_MFC:
378         sprintf( buffer, "mfc0    %s,%s",  s_cpugenreg[ INS_RT( op ) ], s_cp0genreg[ INS_RD( op ) ] );
379         break;
380      case RS_CFC:
381         sprintf( buffer, "!cfc0    %s,%s",  s_cpugenreg[ INS_RT( op ) ], s_cp0ctlreg[ INS_RD( op ) ] );
382         break;
383      case RS_MTC:
384         sprintf( buffer, "mtc0    %s,%s",  s_cpugenreg[ INS_RT( op ) ], s_cp0genreg[ INS_RD( op ) ] );
385         break;
386      case RS_CTC:
387         sprintf( buffer, "!ctc0    %s,%s",  s_cpugenreg[ INS_RT( op ) ], s_cp0ctlreg[ INS_RD( op ) ] );
388         break;
389      case RS_BC:
390      case RS_BC_ALT:
391         switch( INS_BC( op ) )
392         {
393         case BC_BCF:
394            sprintf( buffer, "bc0f    $%08x", relative_address( pc, op ) );
395            break;
396         case BC_BCT:
397            sprintf( buffer, "bc0t    $%08x", relative_address( pc, op ) );
398            break;
399         }
400         break;
401      default:
402         switch( INS_CO( op ) )
403         {
404         case 1:
405            sprintf( buffer, "cop0    $%07x", INS_COFUN( op ) );
406
407            switch( INS_CF( op ) )
408            {
409            case CF_TLBR:
410               sprintf( buffer, "!tlbr" );
411               break;
412            case CF_TLBWI:
413               sprintf( buffer, "!tlbwi" );
414               break;
415            case CF_TLBWR:
416               sprintf( buffer, "!tlbwr" );
417               break;
418            case CF_TLBP:
419               sprintf( buffer, "!tlbp" );
420               break;
421            case CF_RFE:
422               sprintf( buffer, "rfe" );
423               break;
424            }
425            break;
426         }
427         break;
428      }
429      break;
430   case OP_COP1:
431      switch( INS_RS( op ) )
432      {
433      case RS_MFC:
434         sprintf( buffer, "mfc1    %s,%s",  s_cpugenreg[ INS_RT( op ) ], s_cp1genreg[ INS_RD( op ) ] );
435         break;
436      case RS_CFC:
437         sprintf( buffer, "cfc1    %s,%s",  s_cpugenreg[ INS_RT( op ) ], s_cp1ctlreg[ INS_RD( op ) ] );
438         break;
439      case RS_MTC:
440         sprintf( buffer, "mtc1    %s,%s",  s_cpugenreg[ INS_RT( op ) ], s_cp1genreg[ INS_RD( op ) ] );
441         break;
442      case RS_CTC:
443         sprintf( buffer, "ctc1    %s,%s",  s_cpugenreg[ INS_RT( op ) ], s_cp1ctlreg[ INS_RD( op ) ] );
444         break;
445      case RS_BC:
446      case RS_BC_ALT:
447         switch( INS_BC( op ) )
448         {
449         case BC_BCF:
450            sprintf( buffer, "bc1f    $%08x", relative_address( pc, op ) );
451            break;
452         case BC_BCT:
453            sprintf( buffer, "bc1t    $%08x", relative_address( pc, op ) );
454            break;
455         }
456         break;
457      default:
458         switch( INS_CO( op ) )
459         {
460         case 1:
461            sprintf( buffer, "cop1    $%07x", INS_COFUN( op ) );
462            break;
463         }
464         break;
465      }
466      break;
467   case OP_COP2:
468      switch( INS_RS( op ) )
469      {
470      case RS_MFC:
471         sprintf( buffer, "mfc2    %s,%s",  s_cpugenreg[ INS_RT( op ) ], s_cp2genreg[ INS_RD( op ) ] );
472         break;
473      case RS_CFC:
474         sprintf( buffer, "cfc2    %s,%s",  s_cpugenreg[ INS_RT( op ) ], s_cp2ctlreg[ INS_RD( op ) ] );
475         break;
476      case RS_MTC:
477         sprintf( buffer, "mtc2    %s,%s",  s_cpugenreg[ INS_RT( op ) ], s_cp2genreg[ INS_RD( op ) ] );
478         break;
479      case RS_CTC:
480         sprintf( buffer, "ctc2    %s,%s",  s_cpugenreg[ INS_RT( op ) ], s_cp2ctlreg[ INS_RD( op ) ] );
481         break;
482      case RS_BC:
483      case RS_BC_ALT:
484         switch( INS_BC( op ) )
485         {
486         case BC_BCF:
487            sprintf( buffer, "bc2f    $%08x", relative_address( pc, op ) );
488            break;
489         case BC_BCT:
490            sprintf( buffer, "bc2t    $%08x", relative_address( pc, op ) );
491            break;
492         }
493         break;
494      default:
495         switch( INS_CO( op ) )
496         {
497         case 1:
498            sprintf( buffer, "cop2    $%07x", INS_COFUN( op ) );
499
500            switch( GTE_FUNCT( op ) )
501            {
502            case 0x01:
503               if( INS_COFUN( op ) == 0x0180001 )
504               {
505                  sprintf( buffer, "rtps" );
506               }
507               break;
508            case 0x06:
509               if( INS_COFUN( op ) == 0x0400006 ||
510                  INS_COFUN( op ) == 0x1400006 ||
511                  INS_COFUN( op ) == 0x0155cc6 )
512               {
513                  sprintf( buffer, "nclip" );
514               }
515               break;
516            case 0x0c:
517               if( GTE_OP( op ) == 0x17 )
518               {
519                  sprintf( buffer, "op%s", s_gtesf[ GTE_SF( op ) ] );
520               }
521               break;
522            case 0x10:
523               if( INS_COFUN( op ) == 0x0780010 )
524               {
525                  sprintf( buffer, "dpcs" );
526               }
527               break;
528            case 0x11:
529               if( INS_COFUN( op ) == 0x0980011 )
530               {
531                  sprintf( buffer, "intpl" );
532               }
533               break;
534            case 0x12:
535               if( GTE_OP( op ) == 0x04 )
536               {
537                  sprintf( buffer, "mvmva%s %s + %s * %s (lm=%s)",
538                     s_gtesf[ GTE_SF( op ) ], s_gtecv[ GTE_CV( op ) ], s_gtemx[ GTE_MX( op ) ],
539                     s_gtev[ GTE_V( op ) ],  s_gtelm[ GTE_LM( op ) ] );
540               }
541               break;
542            case 0x13:
543               if( INS_COFUN( op ) == 0x0e80413 )
544               {
545                  sprintf( buffer, "ncds" );
546               }
547               break;
548            case 0x14:
549               if( INS_COFUN( op ) == 0x1280414 )
550               {
551                  sprintf( buffer, "cdp" );
552               }
553               break;
554            case 0x16:
555               if( INS_COFUN( op ) == 0x0f80416 )
556               {
557                  sprintf( buffer, "ncdt" );
558               }
559               break;
560            case 0x1b:
561               if( INS_COFUN( op ) == 0x108041b )
562               {
563                  sprintf( buffer, "nccs" );
564               }
565               break;
566            case 0x1c:
567               if( INS_COFUN( op ) == 0x138041c )
568               {
569                  sprintf( buffer, "cc" );
570               }
571               break;
572            case 0x1e:
573               if( INS_COFUN( op ) == 0x0c8041e )
574               {
575                  sprintf( buffer, "ncs" );
576               }
577               break;
578            case 0x20:
579               if( INS_COFUN( op ) == 0x0d80420 )
580               {
581                  sprintf( buffer, "nct" );
582               }
583               break;
584            case 0x28:
585               if( GTE_OP( op ) == 0x0a && GTE_LM( op ) == 1 )
586               {
587                  sprintf( buffer, "sqr%s", s_gtesf[ GTE_SF( op ) ] );
588               }
589               break;
590            case 0x29:
591               if( INS_COFUN( op ) == 0x0680029 )
592               {
593                  sprintf( buffer, "dcpl" );
594               }
595               break;
596            case 0x2a:
597               if( INS_COFUN( op ) == 0x0f8002a )
598               {
599                  sprintf( buffer, "dpct" );
600               }
601               break;
602            case 0x2d:
603               if( INS_COFUN( op ) == 0x158002d )
604               {
605                  sprintf( buffer, "avsz3" );
606               }
607               break;
608            case 0x2e:
609               if( INS_COFUN( op ) == 0x168002e )
610               {
611                  sprintf( buffer, "avsz4" );
612               }
613               break;
614            case 0x30:
615               if( INS_COFUN( op ) == 0x0280030 )
616               {
617                  sprintf( buffer, "rtpt" );
618               }
619               break;
620            case 0x3d:
621               if( GTE_OP( op ) == 0x09 ||
622                  GTE_OP( op ) == 0x19 )
623               {
624                  sprintf( buffer, "gpf%s", s_gtesf[ GTE_SF( op ) ] );
625               }
626               break;
627            case 0x3e:
628               if( GTE_OP( op ) == 0x1a )
629               {
630                  sprintf( buffer, "gpl%s", s_gtesf[ GTE_SF( op ) ] );
631               }
632               break;
633            case 0x3f:
634               if( INS_COFUN( op ) == 0x108043f ||
635                  INS_COFUN( op ) == 0x118043f )
636               {
637                  sprintf( buffer, "ncct" );
638               }
639               break;
640            }
641         }
642         break;
643      }
644      break;
645   case OP_COP3:
646      switch( INS_RS( op ) )
647      {
648      case RS_MFC:
649         sprintf( buffer, "mfc3    %s,%s",  s_cpugenreg[ INS_RT( op ) ], s_cp3genreg[ INS_RD( op ) ] );
650         break;
651      case RS_CFC:
652         sprintf( buffer, "cfc3    %s,%s",  s_cpugenreg[ INS_RT( op ) ], s_cp3ctlreg[ INS_RD( op ) ] );
653         break;
654      case RS_MTC:
655         sprintf( buffer, "mtc3    %s,%s",  s_cpugenreg[ INS_RT( op ) ], s_cp3genreg[ INS_RD( op ) ] );
656         break;
657      case RS_CTC:
658         sprintf( buffer, "ctc3    %s,%s",  s_cpugenreg[ INS_RT( op ) ], s_cp3ctlreg[ INS_RD( op ) ] );
659         break;
660      case RS_BC:
661      case RS_BC_ALT:
662         switch( INS_BC( op ) )
663         {
664         case BC_BCF:
665            sprintf( buffer, "bc3f    $%08x", relative_address( pc, op ) );
666            break;
667         case BC_BCT:
668            sprintf( buffer, "bc3t    $%08x", relative_address( pc, op ) );
669            break;
670         }
671         break;
672      default:
673         switch( INS_CO( op ) )
674         {
675         case 1:
676            sprintf( buffer, "cop3    $%07x", INS_COFUN( op ) );
677            break;
678         }
679         break;
680      }
681      break;
682   case OP_LB:
683      sprintf( buffer, "lb      %s,%s", s_cpugenreg[ INS_RT( op ) ], effective_address( pc, op ) );
684      break;
685   case OP_LH:
686      sprintf( buffer, "lh      %s,%s", s_cpugenreg[ INS_RT( op ) ], effective_address( pc, op ) );
687      break;
688   case OP_LWL:
689      sprintf( buffer, "lwl     %s,%s", s_cpugenreg[ INS_RT( op ) ], effective_address( pc, op ) );
690      break;
691   case OP_LW:
692      sprintf( buffer, "lw      %s,%s", s_cpugenreg[ INS_RT( op ) ], effective_address( pc, op ) );
693      break;
694   case OP_LBU:
695      sprintf( buffer, "lbu     %s,%s", s_cpugenreg[ INS_RT( op ) ], effective_address( pc, op ) );
696      break;
697   case OP_LHU:
698      sprintf( buffer, "lhu     %s,%s", s_cpugenreg[ INS_RT( op ) ], effective_address( pc, op ) );
699      break;
700   case OP_LWR:
701      sprintf( buffer, "lwr     %s,%s", s_cpugenreg[ INS_RT( op ) ], effective_address( pc, op ) );
702      break;
703   case OP_SB:
704      sprintf( buffer, "sb      %s,%s", s_cpugenreg[ INS_RT( op ) ], effective_address( pc, op ) );
705      break;
706   case OP_SH:
707      sprintf( buffer, "sh      %s,%s", s_cpugenreg[ INS_RT( op ) ], effective_address( pc, op ) );
708      break;
709   case OP_SWL:
710      sprintf( buffer, "swl     %s,%s", s_cpugenreg[ INS_RT( op ) ], effective_address( pc, op ) );
711      break;
712   case OP_SW:
713      sprintf( buffer, "sw      %s,%s", s_cpugenreg[ INS_RT( op ) ], effective_address( pc, op ) );
714      break;
715   case OP_SWR:
716      sprintf( buffer, "swr     %s,%s", s_cpugenreg[ INS_RT( op ) ], effective_address( pc, op ) );
717      break;
718   case OP_LWC0:
719      sprintf( buffer, "lwc0    %s,%s", s_cp0genreg[ INS_RT( op ) ], effective_address( pc, op ) );
720      break;
721   case OP_LWC1:
722      sprintf( buffer, "lwc1    %s,%s", s_cp1genreg[ INS_RT( op ) ], effective_address( pc, op ) );
723      break;
724   case OP_LWC2:
725      sprintf( buffer, "lwc2    %s,%s", s_cp2genreg[ INS_RT( op ) ], effective_address( pc, op ) );
726      break;
727   case OP_LWC3:
728      sprintf( buffer, "lwc3    %s,%s", s_cp2genreg[ INS_RT( op ) ], effective_address( pc, op ) );
729      break;
730   case OP_SWC0:
731      sprintf( buffer, "swc0    %s,%s", s_cp0genreg[ INS_RT( op ) ], effective_address( pc, op ) );
732      break;
733   case OP_SWC1:
734      sprintf( buffer, "swc1    %s,%s", s_cp1genreg[ INS_RT( op ) ], effective_address( pc, op ) );
735      break;
736   case OP_SWC2:
737      sprintf( buffer, "swc2    %s,%s", s_cp2genreg[ INS_RT( op ) ], effective_address( pc, op ) );
738      break;
739   case OP_SWC3:
740      sprintf( buffer, "swc3    %s,%s", s_cp2genreg[ INS_RT( op ) ], effective_address( pc, op ) );
741      break;
742   }
743   return ( opram - oldopram ) | flags | DASMFLAG_SUPPORTED;
744}

Previous 15994 Revisions Next


© 1998-2018 The MESS Team