Previous 15994 Revisions Next

r11461 Friday 6th May, 2011 at 20:24:22 UTC by Miodrag Milanović
Sync with MAME (r12444) (no whatsnew)
[src/emu]emu.mak
[src/emu/machine]6525tpi.c* 6525tpi.h* matsucd.c* matsucd.h* wd17xx.c* wd17xx.h*
[src/mame]mame.lst mame.mak
[src/mame/drivers]a3000.c* a310.c* a7000.c* ami1200.c* amiga.c* astrocdh.c* atari400.c* combatsc.c msx.c* n64.c* nes.c* ng_aes.c* pce.c* psx.c* snes.c*
[src/mame/includes]msx.h* msx_slot.h* nes.h* pce.h*
[src/mame/machine]aescart.c* aescart.h* amigacd.c* amigacd.h* amigacrt.c* amigacrt.h* amigafdc.c* amigafdc.h* amigakbd.c* amigakbd.h* ataricrt.c* ataridev.h* atarifdc.c* msx.c* msx_slot.c* nes.c* nes_ines.c* nes_mmc.c* nes_mmc.h* nes_pcb.c* nes_unif.c* pce.c* psxcard.c* psxcard.h* psxcd.c* psxcd.h* psxcddrv.c* psxcddrv.h* snescart.c* snescart.h*
[src/mame/video]nes.c*
[src/mess]mess.mak
[src/mess/devices]aescart.c aescart.h
[src/mess/drivers]a3000.c a310.c a7000.c ami1200.c amiga.c astrocde.c atari.c msx.c n64.c nes.c ng_aes.c pce.c psx.c snes.c
[src/mess/includes]msx.h msx_slot.h nes.h pce.h
[src/mess/machine]6525tpi.c 6525tpi.h amigacd.c amigacd.h amigacrt.c amigacrt.h amigafdc.c amigafdc.h amigakbd.c amigakbd.h ataricrt.c ataridev.h atarifdc.c matsucd.c matsucd.h msx.c msx_slot.c nes.c nes_ines.c nes_mmc.c nes_mmc.h nes_pcb.c nes_unif.c pce.c psxcard.c psxcard.h psxcd.c psxcd.h psxcddrv.c psxcddrv.h snescart.c snescart.h wd17xx.c wd17xx.h
[src/mess/video]nes.c

src/mame/mame.lst
r11460r11461
1227112271// due to the arcade units being based on stock retail console units.
1227212272
1227312273// 3DO
12274// (used by Orbatak prototype, and Beavis + Butthead prototype)
12274122753do
12275122763do_pal
1227612277
12278// Acorn Archimedies
12279// (hardware used by erotictac, Aristokrat MK5 and others)
12280//a310
12281//a7000
12282//a7000p
12283
12284// ASCII & Microsoft
12285// (hardware used by Sangho Soft games, and some bootlegs)
12286//msx      // 1983 MSX
12287//ax170
12288//canonv10
12289//canonv20
12290//dpc100   // 1984 MSX Korea
12291//dpc180   // 1984 MSX Korea
12292//dpc200   // 1984 MSX Korea
12293//gsfc200
12294//expert10  // 1983 MSX Brazil
12295//expert11  // 1984 MSX Brazil
12296//expert13  // 1984 MSX Brazil
12297//expertdp  // 1985 MSX Brazil
12298//expertpl  // 1984 MSX Brazil
12299//jvchc7gb
12300//mlf80
12301//mlfx1
12302//cf1200   // 1984 MSX Japan
12303//cf2000   // 1983 MSX Japan
12304//cf2700   // 1984 MSX Japan
12305//cf3000   // 1984 MSX Japan
12306//cf3300   // 1985 MSX Japan
12307//fs1300   // 1985 MSX Japan
12308//fs4000   // 1985 MSX Japan
12309//nms801
12310//vg8000
12311//vg8010
12312//vg8010f
12313//vg802000
12314//vg802020  // 1985 MSX
12315//piopx7
12316//mpc100
12317//hotbit11  // 1985 MSX Brazil
12318//hotbit12  // 1985 MSX Brazil
12319//hotbi13b  // 1985 MSX Brazil
12320//hotbi13p  // 1985 MSX Brazil
12321//hotbit20  // 1986 MSX2 Brazil
12322//hb10p
12323//hb20p
12324//hb201    // 1985 MSX Japan
12325//hb201p   // 1985 MSX
12326//hb501p   // 1984 MSX
12327//hb55d    // 1983 MSX Germany
12328//hb55p    // 1983 MSX
12329//hb75d    // 1983 MSX Germany
12330//hb75p    // 1983 MSX
12331//svi728   // 1985 MSX
12332//svi738   // 1985 MSX
12333//svi738sw  // 1985 MSX
12334//tadpc200
12335//tadpc20a
12336//hx10     // 1984 MSX
12337//hx10s    // 1984 MSX
12338//hx20     // 1984 MSX
12339//cx5m
12340//cx5m128
12341//cx5m2
12342//yis303
12343//yis503
12344//yis503ii
12345//y503iir
12346//y503iir2
12347//yis503m
12348//yc64
12349//bruc100
12350
12351//msx2     // 1985 MSX2
12352//ax350
12353//ax370
12354//hbf9p    // 1985 MSX2
12355//hbf9s    // 1985 MSX2
12356//hbf500p   // 1985 MSX2
12357//hbf700d   // 1985 MSX2 Germany
12358//hbf700f   // 1985 MSX2
12359//hbf700p   // 1985 MSX2
12360//hbf700s   // 1985 MSX2 Spain
12361//hbg900ap  // 1986 MSX2
12362//hbg900p   // 1986 MSX2
12363//nms8220   // 1986 MSX2
12364//nms8220a  // 1986 MSX2
12365//vg8230   // 1986 MSX2
12366//vg8235   // 1986 MSX2
12367//vg8235f   // 1986 MSX2
12368//vg8240 // 1986 MSX2
12369//nms8245   // 1986 MSX2
12370//nms8245f   // 1986 MSX2
12371//nms8250   // 1986 MSX2
12372//nms8255   // 1986 MSX2
12373//nms8280   // 1986 MSX2
12374//nms8280g   // 1986 MSX2
12375//tpc310   // 1986 MSX2
12376//hx23      // 1986 MSX2
12377//hx23f   // 1986 MSX2
12378//cx7m      // 1986 MSX2
12379//cx7m128   // 1986 MSX2
12380//fs5500   // 1985 MSX2 Japan
12381//fs4500   // 1986 MSX2 Japan
12382//fs4700   // 1986 MSX2 Japan
12383//fs5000   // 1986 MSX2 Japan
12384//fs4600   // 1986 MSX2 Japan
12385//fsa1     // 1986 MSX2 Japan
12386//fsa1a    // 1986 MSX2 Japan
12387//fsa1mk2   // 1987 MSX2 Japan
12388//fsa1f    // 1987 MSX2 Japan
12389//fsa1fm   // 1988 MSX2 Japan
12390//hbf500   // 1986 MSX2 Japan
12391//hbf900   // 1986 MSX2 Japan
12392//hbf900a   // 1986 MSX2 Japan
12393//hbf1     // 1986 MSX2 Japan
12394//hbf12    // 1987 MSX2 Japan
12395//hbf1xd   // 1987 MSX2 Japan
12396//hbf1xdm2  // 1988 MSX2 Japan
12397//phc23    // 1986 MSX2 Japan
12398//cpc300   // 1986 MSX2 Korea
12399//cpc300e   // 1986 MSX2 Korea
12400//cpc400   // 1986 MSX2 Korea
12401//cpc400s   // 1986 MSX2 Korea
12402//expert20 // 1986 MSX2 Korea
12403
12404//msx2p    // 1988 MSX2+ Japan
12405//fsa1fx   // 1988 MSX2+ Japan
12406//fsa1wx   // 1988 MSX2+ Japan
12407//fsa1wxa   // 1988 MSX2+ Japan
12408//fsa1wsx   // 1989 MSX2+ Japan
12409//hbf1xdj   // 1988 MSX2+ Japan
12410//hbf1xv   // 1989 MSX2+ Japan
12411//phc70fd   // 1988 MSX2+ Japan
12412//phc70fd2  // 1988 MSX2+ Japan
12413//phc35j   // 1989 MSX2+ Japan
12414
12415
12416// Atari A400
12417// (hardware used by Maxaflex and Barroom Baseball)
12418//a400
12419//a400pal
12420//a800
12421//a800pal
12422//a1200xl
12423//a600xl
12424//a800xl
12425//a800xlp
12426//a65xe
12427//a65xea
12428//a130xe
12429//a800xe
12430//xegs
12431//a5200
12432
12433
12434// Atari Jaguar
12435// (hardware used by CoJag)
12436//jaguar      // (c)1993 Atari
12437//jaguarcd   // (c)1995 Atari
12438
12439// Capcom CPS Changer
12440// (hardware is the same as CPS1)
12441//sfzch      // (c)1995 Capcom
12442//sfach      // (c)1995 Capcom
12443//sfzbch      // (c)1995 Capcom
12444//wofch      // (c)1995 Capcom
12445
12446// Commodore Amiga
12447// (hardware used by Arcadia and others)
12448//a1000n
12449//a1000p
12450//a500n
12451//a500p
12452//cdtv
12453//a3000
12454//a1200n
12455//a1200p
12456
12457// Commodore CD32
12458// (parent to Cubo32 sets)
12459cd32      // (c)1993 Commodore
12460
12461// GCE Vectrex
12462// (parent to Spectrum I+)
12463vectrex      // (c)1982 GCE
12464
12465// NEC PC Engine
12466// Hardware used by uapce.c, and several others (implementations could be merged)
12467//pce
12468//tg16
12469//sgx
12470
12471// Nintendo NES
12472// (used by vsnes, pc10, and others)
12473//nes
12474//nespal
12475//famicom
12476//fami_key
12477//famitwin
12478//m82
12479//drpcjr
12480//dendy
12481
12482// Nintendo SNES
12483// (used by Nintendo Super System and various bootlegs)
12484//snes
12485//snespal
12486//snesdsp
12487//snespdsp
12488//snessfx
12489//snespsfx
12490//snesst10
12491//snesst11
12492//snesst
12493//snesbsx
12494
12495// Nintendo N64
12496// (used by Aleck64)
12497//n64
12498
12499// Phillips CDI
12500// (parent to Quizzard sets)
12501cdimono1   // (c)1991 Philips
12502
12503// Sega SG1000
12504// (hardware used by Doki Doki Penguin Land + others)
12505//sg1000
12506//sg1000m2
12507//sc3000
12508//sc3000h
12509//sf7000
12510//omv1000
12511//omv2000
12512
12513// Sega SMS / Game Gear
12514// (Megatech runs some SMS games in the Genesis compatibility mode, VDPs used by Megatech, Megaplay, System E)
12515// (MAME currently uses it's own implementation)
12516//sg1000m3
12517//sms1
12518//sms1pal
12519//smssdisp
12520//smsj
12521//sms
12522//smspal
12523//sms2kr
12524//gamegear
12525//gamegeaj
12526
1227712527// Sega Megadrive / Genesis and related systems
1227812528// (hardware used by Megatech, Megaplay + many standalone boards)
1227912529//genesis      // (c)1989 Sega
r11460r11461
1230612556//vsaturn      // (c)1995 Sega/JVC
1230712557//hisaturn   // (c)1995 Sega/Hitachi
1230812558
12309// Atari Jaguar
12310// (hardware used by CoJag)
12311//jaguar      // (c)1993 Atari
12312//jaguarcd   // (c)1995 Atari
12559// Sega Dreamcast
12560// (hardware used by Naomi, Atomiswave etc.)
12561//dc
12562//dcjp
12563//dceu
12564//dcdev
1231312565
12314// Capcom CPS Changer
12315// (hardware is the same as CPS1)
12316//sfzch      // (c)1995 Capcom
12317//sfach      // (c)1995 Capcom
12318//sfzbch      // (c)1995 Capcom
12319//wofch      // (c)1995 Capcom
12320
12321// Phillips CDI
12322// (parent to Quizzard sets)
12323cdimono1   // (c)1991 Philips
12324
12325// Commodore CD32
12326// (parent to Cubo32 sets)
12327cd32      // (c)1993 Commodore
12328
12329// GCE Vectrex
12330// (parent to Spectrum I+)
12331vectrex      // (c)1982 GCE
12566// SNK NeoGeo AES
12567//aes
12568//neocd
12569//neocdz
src/mame/machine/psxcard.c
r0r11461
1/*
2    psxcard.c - Sony PlayStation memory card device
3
4    by pSXAuthor
5    MESS conversion by R. Belmont
6*/
7
8#include "emu.h"
9#include "psxcard.h"
10#include "includes/psx.h"
11
12//
13//
14//
15
16//#define debug_card
17
18//
19//
20//
21
22const device_type PSXCARD = &device_creator<psxcard_device>;
23
24enum transfer_states
25{
26   state_illegal=0,
27   state_command,
28   state_cmdack_1,
29   state_cmdack_2,
30   state_addr_hi,
31   state_addr_lo,
32   state_read,
33   state_write,
34   state_writeack_1,
35   state_writeack_2,
36   state_writechk
37};
38
39psxcard_device::psxcard_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
40    : device_t(mconfig, PSXCARD, "Sony PSX Memory Card", tag, owner, clock)
41{
42}
43
44void psxcard_device::device_start()
45{
46   cache=new unsigned char [128*1024];
47
48   memset(cache, 0, 128*1024);
49
50   // save state registrations
51/*  save_item(NAME(pkt));
52    save_item(NAME(pkt_ptr));
53    save_item(NAME(pkt_sz));
54    save_item(NAME(pkt));
55    save_item(NAME(cache));
56    save_item(NAME(addr));
57    save_item(NAME(state));*/
58}
59
60void psxcard_device::device_reset()
61{
62   state = state_illegal;
63   addr = 0;
64}
65
66//
67//
68//
69
70bool psxcard_device::transfer(UINT8 to, UINT8 *from)
71{
72   bool ret=true;
73
74   switch (state)
75   {
76      case state_illegal:
77         if (to == 0x81)
78         {
79//              printf("CARD: begin\n");
80            state = state_command;
81            *from = 0x00;
82         }
83         else
84         {
85            ret = false;
86         }
87         break;
88
89      case state_command:
90         cmd=to;
91         *from=0x00;
92         state=state_cmdack_1;
93         break;
94
95      case state_cmdack_1:
96         //assert(to==0);
97         *from=0x5a;
98         state=state_cmdack_2;
99         break;
100
101      case state_cmdack_2:
102         //assert(to==0);
103         *from=0x5d;
104         state=state_addr_hi;
105         break;
106
107      case state_addr_hi:
108         addr=(to<<8);
109//          printf("addr_hi: %02x, addr = %x\n", to, addr);
110         *from=0;
111         state=state_addr_lo;
112         break;
113
114      case state_addr_lo:
115         addr|=(to&0xff);
116//          printf("addr_lo: %02x, addr = %x, cmd = %x\n", to, addr, cmd);
117         *from=(addr>>8);
118
119         switch (cmd)
120         {
121            case 'R':   // 0x52
122            {
123               pkt[0]=0x5c;
124               pkt[1]=0x5d;
125               pkt[2]=(addr>>8);
126               pkt[3]=(addr&0xff);
127               read_card(addr,&pkt[4]);
128               pkt[4+128]=checksum_data(&pkt[2],128+2);
129               pkt[5+128]=0x47;
130               pkt_sz=6+128;
131               pkt_ptr=0;
132               state=state_read;
133               break;
134            }
135            case 'W':   // 0x57
136            {
137               pkt[0]=addr>>8;
138               pkt[1]=addr&0xff;
139               pkt_sz=129+2;
140               pkt_ptr=2;
141               state=state_write;
142               break;
143            }
144            default:
145               state=state_illegal;
146               break;
147         }
148         break;
149
150      case state_read:
151         //assert(to==0);
152//          printf("state_read: pkt_ptr = %d, pkt_sz = %d\n", pkt_ptr, pkt_sz);
153         *from=pkt[pkt_ptr++];
154         if (pkt_ptr==pkt_sz)
155         {
156            #ifdef debug_card
157               printf("card: read finished\n");
158            #endif
159
160            state=state_illegal;
161            ret=false;
162         }
163         break;
164
165      case state_write:
166         *from=(pkt_ptr==0)?(addr&0xff):pkt[pkt_ptr-1];
167         pkt[pkt_ptr++]=to;
168         if (pkt_ptr==pkt_sz)
169            state=state_writeack_1;
170         break;
171
172      case state_writeack_1:
173         *from=0x5c;
174         state=state_writeack_2;
175         break;
176
177      case state_writeack_2:
178         *from=0x5d;
179         state=state_writechk;
180         break;
181
182      case state_writechk:
183      {
184         unsigned char chk=checksum_data(pkt,128+2);
185         if (chk==pkt[128+2])
186         {
187            #ifdef debug_card
188               printf("card: write ok\n");
189            #endif
190
191            write_card(addr,pkt+2);
192
193            *from='G';
194         } else
195         {
196            #ifdef debug_card
197               printf("card: write fail\n");
198            #endif
199
200            *from='N';
201         }
202         state=state_illegal;
203         ret=false;
204         break;
205      }
206
207      default: /*assert(0);*/ ret=false; break;
208   }
209
210   #ifdef debug_card
211//      printf("card: transfer to=%02x from=%02x ret=%c\n",to,*from,ret ? 'T' : 'F');
212   #endif
213
214   return ret;
215}
216
217void psxcard_device::read_card(const unsigned short addr, unsigned char *buf)
218{
219   #ifdef debug_card
220      printf("card: read block %d\n",addr);
221   #endif
222
223   if (addr<1024)
224   {
225      memcpy(buf,cache+(addr*128),128);
226   } else
227   {
228      memset(buf,0,128);
229   }
230}
231
232//
233//
234//
235
236void psxcard_device::write_card(const unsigned short addr, unsigned char *buf)
237{
238   #ifdef debug_card
239      printf("card: write block %d\n",addr);
240   #endif
241
242   if (addr<1024)
243   {
244      memcpy(cache+(addr*128),buf,128);
245   }
246}
247
248//
249//
250//
251
252unsigned char psxcard_device::checksum_data(const unsigned char *buf, const unsigned int sz)
253{
254   unsigned char chk=*buf++;
255   int left=sz;
256   while (--left) chk^=*buf++;
257   return chk;
258}
src/mame/machine/ataricrt.c
r0r11461
1/***************************************************************************
2
3    MESS specific Atari init and Cartridge code for Atari 8 bit systems
4
5***************************************************************************/
6
7#include "emu.h"
8#include "emuopts.h"
9#include "includes/atari.h"
10#include "ataridev.h"
11#include "machine/ram.h"
12#include "hashfile.h"
13
14#define LEFT_CARTSLOT_MOUNTED  1
15#define RIGHT_CARTSLOT_MOUNTED 2
16
17/* PCB */
18enum
19{
20    A800_UNKNOWN = 0,
21   A800_4K, A800_8K, A800_12K, A800_16K,
22   A800_RIGHT_4K, A800_RIGHT_8K,
23   OSS_034M, OSS_M091, PHOENIX_8K, XEGS_32K,
24   BBSB, DIAMOND_64K, WILLIAMS_64K, EXPRESS_64,
25   SPARTADOS_X
26};
27
28static int a800_cart_loaded = 0;
29static int atari = 0;
30static int a800_cart_type = A800_UNKNOWN;
31
32/*************************************
33 *
34 *  Generic code
35 *
36 *************************************/
37
38
39// Currently, the drivers have fixed 40k RAM, however the function here is ready for different sizes too
40static void a800_setbank(running_machine &machine, int cart_mounted)
41{
42   offs_t ram_top;
43
44   // take care of 0x0000-0x7fff: RAM or NOP
45   ram_top = MIN(ram_get_size(machine.device(RAM_TAG)), 0x8000) - 1;
46   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0x0000, ram_top, "0000");
47   memory_set_bankptr(machine, "0000", ram_get_ptr(machine.device(RAM_TAG)));
48
49   // take care of 0x8000-0x9fff: A800 -> either right slot or RAM or NOP, others -> RAM or NOP
50   // is there anything in the right slot?
51   if (cart_mounted & RIGHT_CARTSLOT_MOUNTED)
52   {
53      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x8000, 0x9fff, "8000");
54      memory_set_bankptr(machine, "8000", machine.region("rslot")->base());
55      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0x8000, 0x9fff);
56   }
57   else if (a800_cart_type != BBSB)
58   {
59      ram_top = MIN(ram_get_size(machine.device(RAM_TAG)), 0xa000) - 1;
60      if (ram_top > 0x8000)
61      {
62         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0x8000, ram_top, "8000");
63         memory_set_bankptr(machine, "8000", ram_get_ptr(machine.device(RAM_TAG)) + 0x8000);
64      }
65   }
66
67   // take care of 0xa000-0xbfff: is there anything in the left slot?
68   if (cart_mounted & LEFT_CARTSLOT_MOUNTED)
69   {
70      // FIXME: this is an hack to keep XL working until we clean up its memory map as well!
71      if (atari == ATARI_800XL)
72      {
73         if (a800_cart_type == A800_16K)
74         {
75            machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x8000, 0x9fff, "8000");
76            memory_set_bankptr(machine, "8000", machine.region("lslot")->base());
77            machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0x8000, 0x9fff);
78
79            memcpy(machine.region("maincpu")->base() + 0x10000, machine.region("lslot")->base() + 0x2000, 0x2000);
80         }
81         else if (a800_cart_type == A800_8K)
82            memcpy(machine.region("maincpu")->base() + 0x10000, machine.region("lslot")->base(), 0x2000);
83         else
84            fatalerror("This type of cart is not supported yet in this driver. Please use a400 or a800.\n");
85      }
86      else if (a800_cart_type == A800_16K)
87      {
88         memory_set_bankptr(machine, "8000", machine.region("lslot")->base());
89         memory_set_bankptr(machine, "a000", machine.region("lslot")->base() + 0x2000);
90         machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0x8000, 0xbfff);
91      }
92      else if (a800_cart_type == BBSB)
93      {
94         // this requires separate banking in 0x8000 & 0x9000!
95         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x8000, 0x8fff, "8000");
96         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x9000, 0x9fff, "9000");
97         memory_set_bankptr(machine, "8000", machine.region("lslot")->base() + 0x0000);
98         memory_set_bankptr(machine, "9000", machine.region("lslot")->base() + 0x4000);
99         memory_set_bankptr(machine, "a000", machine.region("lslot")->base() + 0x8000);
100         machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xa000, 0xbfff);
101      }
102      else if (a800_cart_type == OSS_034M)
103      {
104         // this requires separate banking in 0xa000 & 0xb000!
105         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xa000, 0xafff, "a000");
106         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xb000, 0xbfff, "b000");
107         memory_set_bankptr(machine, "b000", machine.region("lslot")->base() + 0x3000);
108         machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xa000, 0xbfff);
109      }
110      else if (a800_cart_type == OSS_M091)
111      {
112         // this requires separate banking in 0xa000 & 0xb000!
113         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xa000, 0xafff, "a000");
114         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xb000, 0xbfff, "b000");
115         memory_set_bankptr(machine, "b000", machine.region("lslot")->base());
116         machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xa000, 0xbfff);
117      }
118      else if (a800_cart_type == XEGS_32K)
119      {
120         memory_set_bankptr(machine, "8000", machine.region("lslot")->base());
121         memory_set_bankptr(machine, "a000", machine.region("lslot")->base() + 0x6000);
122         machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0x8000, 0xbfff);
123      }
124      else
125      {
126         memory_set_bankptr(machine, "a000", machine.region("lslot")->base());
127         machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xa000, 0xbfff);
128      }
129   }
130}
131
132/* MESS specific parts that have to be started */
133static void ms_atari_machine_start(running_machine &machine, int type, int has_cart)
134{
135   /* set atari type (temporarily not used) */
136   atari = type;
137   a800_setbank(machine, a800_cart_loaded);
138}
139
140static void ms_atari800xl_machine_start(running_machine &machine, int type, int has_cart)
141{
142   /* set atari type (temporarily not used) */
143   atari = type;
144   a800_setbank(machine, a800_cart_loaded);
145}
146
147/*************************************
148 *
149 *  Atari 400
150 *
151 *************************************/
152
153MACHINE_START( a400 )
154{
155   atari_machine_start(machine);
156   ms_atari_machine_start(machine, ATARI_400, TRUE);
157}
158
159
160/*************************************
161 *
162 *  Atari 800
163 *
164 *************************************/
165
166MACHINE_START( a800 )
167{
168   atari_machine_start(machine);
169   ms_atari_machine_start(machine, ATARI_800, TRUE);
170}
171
172static WRITE8_HANDLER( x32_bank_w )
173{
174   //  printf("written %x\n", data);
175   int bank = data & 0x03;
176   memory_set_bankptr(space->machine(), "8000", space->machine().region("lslot")->base() + bank * 0x2000);
177}
178
179static WRITE8_HANDLER( w64_bank_w )
180{
181//  printf("write to %x\n", offset);
182
183   if (offset < 8)
184      memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base() + offset * 0x2000);
185   else
186      memory_set_bankptr(space->machine(), "a000", space->machine().region("maincpu")->base());
187   // FIXME: writes to 0x8-0xf should disable the cart
188}
189
190// this covers Express 64, Diamond 64 and SpartaDOS (same bankswitch, but at different addresses)
191static WRITE8_HANDLER( ex64_bank_w )
192{
193//  printf("write to %x\n", offset);
194
195   if (offset < 8)
196      memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base() + (7 - offset) * 0x2000);
197   else
198      memory_set_bankptr(space->machine(), "a000", space->machine().region("maincpu")->base());
199   // FIXME: writes to 0x8-0xf should disable the cart
200}
201
202static WRITE8_HANDLER( bbsb_bankl_w )
203{
204//  printf("write to %x\n", 0x8000 + offset);
205   if (offset >= 0xff6 && offset <= 0xff9)
206      memory_set_bankptr(space->machine(), "8000", space->machine().region("lslot")->base() + 0x0000 + (offset - 0xff6) * 0x1000);
207}
208
209static WRITE8_HANDLER( bbsb_bankh_w )
210{
211//  printf("write to %x\n", 0x9000 + offset);
212   if (offset >= 0xff6 && offset <= 0xff9)
213      memory_set_bankptr(space->machine(), "9000", space->machine().region("lslot")->base() + 0x4000 + (offset - 0xff6) * 0x1000);
214}
215
216static WRITE8_HANDLER( oss_034m_w )
217{
218   switch (offset & 0x0f)
219   {
220      case 0:
221      case 1:
222         memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base());
223         memory_set_bankptr(space->machine(), "b000", space->machine().region("lslot")->base() + 0x3000);
224         break;
225      case 2:
226      case 6:
227         // docs says this should put 0xff in the 0xa000 bank -> let's point to the end of the cart
228         memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base() + 0x4000);
229         memory_set_bankptr(space->machine(), "b000", space->machine().region("lslot")->base() + 0x3000);
230         break;
231      case 3:
232      case 7:
233         memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base() + 0x1000);
234         memory_set_bankptr(space->machine(), "b000", space->machine().region("lslot")->base() + 0x3000);
235         break;
236      case 4:
237      case 5:
238         memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base() + 0x2000);
239         memory_set_bankptr(space->machine(), "b000", space->machine().region("lslot")->base() + 0x3000);
240         break;
241      default:
242         memory_set_bankptr(space->machine(), "a000", space->machine().region("maincpu")->base() + 0xa000);
243         memory_set_bankptr(space->machine(), "b000", space->machine().region("maincpu")->base() + 0xb000);
244         break;
245   }
246}
247
248static WRITE8_HANDLER( oss_m091_w )
249{
250   switch (offset & 0x09)
251   {
252      case 0:
253         memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base() + 0x1000);
254         memory_set_bankptr(space->machine(), "b000", space->machine().region("lslot")->base());
255         break;
256      case 1:
257         memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base() + 0x3000);
258         memory_set_bankptr(space->machine(), "b000", space->machine().region("lslot")->base());
259         break;
260      case 8:
261         memory_set_bankptr(space->machine(), "a000", space->machine().region("maincpu")->base() + 0xa000);
262         memory_set_bankptr(space->machine(), "b000", space->machine().region("maincpu")->base() + 0xb000);
263         break;
264      case 9:
265         memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base() + 0x2000);
266         memory_set_bankptr(space->machine(), "b000", space->machine().region("lslot")->base());
267         break;
268   }
269}
270
271#if 0
272static int bbsb_bankl = 0;
273static int bbsb_bankh = 0;
274
275static WRITE8_HANDLER( bbsb_bankl_w )
276{
277   bbsb_bankl = offset; // 0,1,2,3
278}
279
280static WRITE8_HANDLER( bbsb_bankh_w )
281{
282   bbsb_bankh = offset; // 4,5,6,7
283}
284
285static READ8_HANDLER( bbsb_bankl_r )
286{
287   // return data from the selected bank (0,1,2,3)
288   UINT8 *mem = space->machine().region("lslot")->base();
289   return &mem[0x0000 + bbsb_bankl * 0x1000];
290}
291
292static READ8_HANDLER( bbsb_bankh_r )
293{
294   // return data from the selected bank (4,5,6,7)
295   UINT8 *mem = space->machine().region("lslot")->base();
296   return &mem[0x4000 + bbsb_bankh * 0x1000];
297}
298#endif
299
300typedef struct _a800_pcb  a800_pcb;
301struct _a800_pcb
302{
303   const char              *pcb_name;
304   int                     pcb_id;
305};
306
307// Here, we take the feature attribute from .xml (i.e. the PCB name) and we assign a unique ID to it
308// WARNING: most of these are still unsupported by the driver
309static const a800_pcb pcb_list[] =
310{
311   {"standard 4k", A800_8K},
312   {"standard 8k", A800_8K},
313   {"standard 12k", A800_16K},
314   {"standard 16k", A800_16K},
315   {"right slot 4k", A800_RIGHT_4K},
316   {"right slot 8k", A800_RIGHT_8K},
317
318   {"oss 034m", OSS_034M},
319   {"oss m091", OSS_M091},
320   {"phoenix 8k", PHOENIX_8K},
321   {"xegs 32k", XEGS_32K},
322   {"bbsb", BBSB},
323   {"diamond 64k", DIAMOND_64K},
324   {"williams 64k", WILLIAMS_64K},
325   {"express 64", EXPRESS_64},
326   {"spartados x", SPARTADOS_X},
327   {"N/A", A800_UNKNOWN}
328};
329
330static int a800_get_pcb_id(const char *pcb)
331{
332   int   i;
333
334   for (i = 0; i < ARRAY_LENGTH(pcb_list); i++)
335   {
336      if (!mame_stricmp(pcb_list[i].pcb_name, pcb))
337         return pcb_list[i].pcb_id;
338   }
339
340   return A800_UNKNOWN;
341}
342
343// currently this does nothing, but it will eventually install the memory handlers required by the mappers
344static void a800_setup_mappers(running_machine &machine, int type)
345{
346   switch (type)
347   {
348      case A800_4K:
349      case A800_RIGHT_4K:
350      case A800_12K:
351      case A800_8K:
352      case A800_16K:
353      case A800_RIGHT_8K:
354      case PHOENIX_8K:   // as normal 8k cart, but it can be disabled by writing to 0xd500-0xdfff
355         break;
356      case XEGS_32K:
357         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0xd500, 0xd5ff, FUNC(x32_bank_w));
358         break;
359      case OSS_034M:
360         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0xd500, 0xd5ff, FUNC(oss_034m_w));
361         break;
362      case OSS_M091:
363         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0xd500, 0xd5ff, FUNC(oss_m091_w));
364         break;
365      case BBSB:
366         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x8000, 0x8fff, FUNC(bbsb_bankl_w));
367         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x9000, 0x9fff, FUNC(bbsb_bankh_w));
368         break;
369      case WILLIAMS_64K:
370         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0xd500, 0xd50f, FUNC(w64_bank_w));
371         break;
372      case DIAMOND_64K:
373         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0xd5d0, 0xd5df, FUNC(ex64_bank_w));
374         break;
375      case EXPRESS_64:
376         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0xd570, 0xd57f, FUNC(ex64_bank_w));
377         break;
378      case SPARTADOS_X:
379         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0xd5e0, 0xd5ef, FUNC(ex64_bank_w));
380         break;
381      default:
382         break;
383   }
384}
385
386static int a800_get_type(device_image_interface &image)
387{
388   UINT8 header[16];
389   image.fread(header, 0x10);
390   int hdr_type, cart_type = A800_UNKNOWN;
391
392   // add check of CART format
393   if (strncmp((const char *)header, "CART", 4))
394      fatalerror("Invalid header detected!\n");
395
396   hdr_type = (header[4] << 24) + (header[5] << 16) +  (header[6] << 8) + (header[7] << 0);
397   switch (hdr_type)
398   {
399      case 1:
400         cart_type = A800_8K;
401         break;
402      case 2:
403         cart_type = A800_16K;
404         break;
405      case 3:
406         cart_type = OSS_034M;
407         break;
408      case 8:
409         cart_type = WILLIAMS_64K;
410         break;
411      case 9:
412         cart_type = DIAMOND_64K;
413         break;
414      case 10:
415         cart_type = EXPRESS_64;
416         break;
417      case 11:
418         cart_type = SPARTADOS_X;
419         break;
420      case 12:
421         cart_type = XEGS_32K;
422         break;
423      case 15:
424         cart_type = OSS_M091;
425         break;
426      case 18:
427         cart_type = BBSB;
428         break;
429      case 21:
430         cart_type = A800_RIGHT_8K;
431         break;
432      case 39:
433         cart_type = PHOENIX_8K;
434         break;
435      case 4:
436      case 6:
437      case 7:
438      case 16:
439      case 19:
440      case 20:
441         fatalerror("Cart type \"%d\" means this is an Atari 5200 cart.\n", hdr_type);
442         break;
443      default:
444         mame_printf_info("Cart type \"%d\" is currently unsupported.\n", hdr_type);
445         break;
446   }
447   return cart_type;
448}
449
450static int a800_check_cart_type(device_image_interface &image)
451{
452   const char   *pcb_name;
453   int type = A800_UNKNOWN;
454
455   if (image.software_entry() == NULL)
456   {
457      UINT32 size = image.length();
458
459      // check if there is an header, if so extract cart_type from it, otherwise
460      // try to guess the cart_type from the file size (notice that after the
461      // a800_get_type call, we point at the start of the data)
462      if ((size % 0x1000) == 0x10)
463         type = a800_get_type(image);
464      else if (size == 0x4000)
465         type = A800_16K;
466      else if (size == 0x2000)
467      {
468         if (strcmp(image.device().tag(),"cart2") == 0)
469            type = A800_RIGHT_8K;
470         else
471            type = A800_8K;
472      }
473   }
474   else
475   {
476      if ((pcb_name = image.get_feature("cart_type")) != NULL)
477         type = a800_get_pcb_id(pcb_name);
478
479      switch (type)
480      {
481         case A800_UNKNOWN:
482         case A800_4K:
483         case A800_RIGHT_4K:
484         case A800_12K:
485         case A800_8K:
486         case A800_16K:
487         case A800_RIGHT_8K:
488            break;
489         default:
490            mame_printf_info("Cart type \"%s\" currently unsupported.\n", pcb_name);
491            break;
492      }
493   }
494
495   if ((strcmp(image.device().tag(),"cart2") == 0) && (type != A800_RIGHT_8K))
496      fatalerror("You cannot load this image '%s' in the right slot", image.filename());
497
498   return type;
499}
500
501DEVICE_IMAGE_LOAD( a800_cart )
502{
503   UINT32 size, start = 0;
504
505   a800_cart_loaded = a800_cart_loaded & ~LEFT_CARTSLOT_MOUNTED;
506   a800_cart_type = a800_check_cart_type(image);
507
508   a800_setup_mappers(image.device().machine(), a800_cart_type);
509
510   if (image.software_entry() == NULL)
511   {
512      size = image.length();
513      // if there is an header, skip it
514      if ((size % 0x1000) == 0x10)
515      {
516         size -= 0x10;
517         start = 0x10;
518      }
519      image.fread(image.device().machine().region("lslot")->base(), size - start);
520   }
521   else
522   {
523      size = image.get_software_region_length("rom");
524      memcpy(image.device().machine().region("lslot")->base(), image.get_software_region("rom"), size);
525   }
526
527   a800_cart_loaded |= (size > 0x0000) ? 1 : 0;
528
529   logerror("%s loaded left cartridge '%s' size %dK\n", image.device().machine().system().name, image.filename(), size/1024);
530   return IMAGE_INIT_PASS;
531}
532
533DEVICE_IMAGE_LOAD( a800_cart_right )
534{
535   UINT32 size, start = 0;
536
537   a800_cart_loaded = a800_cart_loaded & ~RIGHT_CARTSLOT_MOUNTED;
538   a800_cart_type = a800_check_cart_type(image);
539
540   a800_setup_mappers(image.device().machine(), a800_cart_type);
541
542   if (image.software_entry() == NULL)
543   {
544      size = image.length();
545      // if there is an header, skip it
546      if ((size % 0x1000) == 0x10)
547      {
548         size -= 0x10;
549         start = 0x10;
550      }
551      image.fread(image.device().machine().region("rslot")->base(), size - start);
552   }
553   else
554   {
555      size = image.get_software_region_length("rom");
556      memcpy(image.device().machine().region("rslot")->base(), image.get_software_region("rom"), size);
557   }
558
559   a800_cart_loaded |= (size > 0x0000) ? 2 : 0;
560
561   logerror("%s loaded right cartridge '%s' size 8K\n", image.device().machine().system().name, image.filename());
562   return IMAGE_INIT_PASS;
563}
564
565DEVICE_IMAGE_UNLOAD( a800_cart )
566{
567   a800_cart_loaded = a800_cart_loaded & ~LEFT_CARTSLOT_MOUNTED;
568   a800_cart_type = A800_UNKNOWN;
569   a800_setbank(image.device().machine(), a800_cart_loaded);
570}
571
572DEVICE_IMAGE_UNLOAD( a800_cart_right )
573{
574   a800_cart_loaded = a800_cart_loaded & ~RIGHT_CARTSLOT_MOUNTED;
575   a800_cart_type = A800_UNKNOWN;
576   a800_setbank(image.device().machine(), a800_cart_loaded);
577}
578
579
580/*************************************
581 *
582 *  Atari 800XL
583 *
584 *************************************/
585
586MACHINE_START( a800xl )
587{
588   atari_machine_start(machine);
589   ms_atari800xl_machine_start(machine, ATARI_800XL, TRUE);
590}
591
592/*************************************
593 *
594 *  Atari 5200 console
595 *
596 *************************************/
597
598MACHINE_START( a5200 )
599{
600   atari_machine_start(machine);
601   ms_atari_machine_start(machine, ATARI_800XL, TRUE);
602}
603
604
605DEVICE_IMAGE_LOAD( a5200_cart )
606{
607   UINT8 *mem = image.device().machine().region("maincpu")->base();
608   UINT32 size;
609
610   if (image.software_entry() == NULL)
611   {
612      /* load an optional (dual) cartidge */
613      size = image.fread(&mem[0x4000], 0x8000);
614   }
615   else
616   {
617      size = image.get_software_region_length("rom");
618      memcpy(mem + 0x4000, image.get_software_region("rom"), size);
619   }
620
621   if (size<0x8000) memmove(mem+0x4000+0x8000-size, mem+0x4000, size);
622   // mirroring of smaller cartridges
623   if (size <= 0x1000) memcpy(mem+0xa000, mem+0xb000, 0x1000);
624   if (size <= 0x2000) memcpy(mem+0x8000, mem+0xa000, 0x2000);
625   if (size <= 0x4000)
626   {
627      const char *info = hashfile_extrainfo(image);
628      memcpy(&mem[0x4000], &mem[0x8000], 0x4000);
629      if (info && !strcmp(info, "A13MIRRORING"))
630      {
631         memcpy(&mem[0x8000], &mem[0xa000], 0x2000);
632         memcpy(&mem[0x6000], &mem[0x4000], 0x2000);
633      }
634   }
635   logerror("A5200 loaded cartridge '%s' size %dK\n", image.filename() , size/1024);
636   return IMAGE_INIT_PASS;
637}
638
639DEVICE_IMAGE_UNLOAD( a5200_cart )
640{
641   UINT8 *mem = image.device().machine().region("maincpu")->base();
642   /* zap the cartridge memory (again) */
643   memset(&mem[0x4000], 0x00, 0x8000);
644}
645
646/*************************************
647 *
648 *  Atari XEGS
649 *
650 *************************************/
651
652static UINT8 xegs_banks = 0;
653static UINT8 xegs_cart = 0;
654
655static WRITE8_HANDLER( xegs_bankswitch )
656{
657   UINT8 *cart = space->machine().region("user1")->base();
658   data &= xegs_banks - 1;
659   memory_set_bankptr(space->machine(), "bank0", cart + data * 0x2000);
660}
661
662MACHINE_START( xegs )
663{
664   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
665   UINT8 *cart = space->machine().region("user1")->base();
666   UINT8 *cpu  = space->machine().region("maincpu")->base();
667
668   atari_machine_start(machine);
669   space->install_legacy_write_handler(0xd500, 0xd5ff, FUNC(xegs_bankswitch));
670
671   if (xegs_cart)
672   {
673      memory_set_bankptr(machine, "bank0", cart);
674      memory_set_bankptr(machine, "bank1", cart + (xegs_banks - 1) * 0x2000);
675   }
676   else
677   {
678      // point to built-in Missile Command (this does not work well, though... FIXME!!)
679      memory_set_bankptr(machine, "bank0", cpu + 0x10000);
680      memory_set_bankptr(machine, "bank1", cpu + 0x10000);
681   }
682}
683
684DEVICE_IMAGE_LOAD( xegs_cart )
685{
686   UINT32 size;
687   UINT8 *ptr = image.device().machine().region("user1")->base();
688
689   if (image.software_entry() == NULL)
690   {
691      // skip the header
692      image.fseek(0x10, SEEK_SET);
693      size = image.length() - 0x10;
694      if (image.fread(ptr, size) != size)
695         return IMAGE_INIT_FAIL;
696   }
697   else
698   {
699      size = image.get_software_region_length("rom");
700      memcpy(ptr, image.get_software_region("rom"), size);
701   }
702
703   xegs_banks = size / 0x2000;
704   xegs_cart = 1;
705
706   return IMAGE_INIT_PASS;
707}
708
709DEVICE_IMAGE_UNLOAD( xegs_cart )
710{
711   xegs_cart = 0;
712   xegs_banks = 0;
713}
src/mame/machine/psxcard.h
r0r11461
1#pragma once
2
3#ifndef _PSXCARD_
4#define _PSXCARD_
5
6#include "emu.h"
7
8#define MCFG_PSXCARD_ADD(_tag) \
9    MCFG_DEVICE_ADD(_tag, PSXCARD, 0)
10
11struct psxcard_interface
12{
13};
14
15class psxcard_device : public device_t,
16                       public psxcard_interface
17{
18public:
19    psxcard_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
20
21private:
22   unsigned char pkt[0x8b], pkt_ptr, pkt_sz, cmd, *cache;
23   unsigned short addr;
24   int state;
25
26   void read_card(const unsigned short addr, unsigned char *buf);
27   void write_card(const unsigned short addr, unsigned char *buf);
28   unsigned char checksum_data(const unsigned char *buf, const unsigned int sz);
29
30public:
31   virtual void device_start();
32   virtual void device_reset();
33
34   bool transfer(UINT8 to, UINT8 *from);
35   void mess_io(running_machine *machine, UINT8 n_data);
36private:
37};
38
39// device type definition
40extern const device_type PSXCARD;
41
42#endif
src/mame/machine/ataridev.h
r0r11461
1/*
2    ataridev.h
3
4*/
5
6#ifndef _ATARIDEV_H
7#define _ATARIDEV_H
8
9#define ATARI_5200   0
10#define ATARI_400   1
11#define ATARI_800   2
12#define ATARI_600XL 3
13#define ATARI_800XL 4
14
15/*----------- defined in machine/ataricrt.c -----------*/
16
17MACHINE_START( a400 );
18MACHINE_START( a800 );
19MACHINE_START( a800xl );
20MACHINE_START( a5200 );
21MACHINE_START( xegs );
22
23DEVICE_IMAGE_LOAD( a800_cart );
24DEVICE_IMAGE_UNLOAD( a800_cart );
25
26DEVICE_IMAGE_LOAD( a800_cart_right );
27DEVICE_IMAGE_UNLOAD( a800_cart_right );
28
29DEVICE_IMAGE_LOAD( a5200_cart );
30DEVICE_IMAGE_UNLOAD( a5200_cart );
31
32DEVICE_IMAGE_LOAD( xegs_cart );
33DEVICE_IMAGE_UNLOAD( xegs_cart );
34
35
36/*----------- defined in machine/atarifdc.c -----------*/
37/***************************************************************************
38    MACROS
39***************************************************************************/
40
41DECLARE_LEGACY_DEVICE(ATARI_FDC, atari_fdc);
42
43#define MCFG_ATARI_FDC_ADD(_tag)   \
44   MCFG_DEVICE_ADD((_tag),  ATARI_FDC, 0)
45
46
47/***************************************************************************
48    FUNCTION PROTOTYPES
49***************************************************************************/
50READ8_DEVICE_HANDLER( atari_serin_r );
51WRITE8_DEVICE_HANDLER( atari_serout_w );
52WRITE_LINE_DEVICE_HANDLER( atarifdc_pia_cb2_w );
53
54#endif /* _ATARIDEV_H */
55
src/mame/machine/msx_slot.c
r0r11461
1/*
2 * msx_slot.c : definitions of the different slots
3 *
4 * Copyright (C) 2004 Sean Young
5 *
6 * Missing:
7 * - Holy Qu'ran
8 *   like ascii8, with switch address 5000h/5400h/5800h/5c00h, not working.
9 * - Harry Fox
10 *   16kb banks, 6000h and 7000h switch address; isn't it really an ascii16?
11 * - Halnote
12 *   writes to page 0?
13 * - Playball
14 *   Unemulated D7756C, same as src/drivers/homerun.c
15 * - Some ascii8 w/ sram need 32kb sram?
16 * - MegaRAM
17 * - fmsx painter.rom
18 */
19
20#include "emu.h"
21#include "emuopts.h"
22#include "machine/i8255.h"
23#include "includes/msx_slot.h"
24#include "includes/msx.h"
25#include "machine/wd17xx.h"
26#include "sound/k051649.h"
27#include "sound/2413intf.h"
28#include "sound/dac.h"
29#include "sound/ay8910.h"
30
31static void msx_cpu_setbank (running_machine &machine, int page, UINT8 *mem)
32{
33   msx_state *state = machine.driver_data<msx_state>();
34   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
35   switch (page)
36   {
37   case 1:
38      memory_set_bankptr (machine,"bank1", mem);
39      break;
40   case 2:
41      memory_set_bankptr (machine,"bank2", mem);
42      break;
43   case 3:
44      memory_set_bankptr (machine,"bank3", mem);
45      break;
46   case 4:
47      memory_set_bankptr (machine,"bank4", mem);
48      memory_set_bankptr (machine,"bank5", mem + 0x1ff8);
49      space->install_read_bank(0x7ff8, 0x7fff, "bank5");
50      break;
51   case 5:
52      memory_set_bankptr (machine,"bank6", mem);
53      memory_set_bankptr (machine,"bank7", mem + 0x1800);
54      space->install_read_bank(0x9800, 0x9fff, "bank7");
55      break;
56   case 6:
57      memory_set_bankptr (machine,"bank8", mem);
58      memory_set_bankptr (machine,"bank9", mem + 0x1800);
59      space->install_read_bank(0xb800, 0xbfff, "bank9");
60      break;
61   case 7:
62      memory_set_bankptr (machine,"bank10", mem);
63      break;
64   case 8:
65      memory_set_bankptr (machine,"bank11", mem);
66      state->m_top_page = mem;
67      break;
68   }
69}
70
71MSX_SLOT_INIT(empty)
72{
73   state->m_type = SLOT_EMPTY;
74
75   return 0;
76}
77
78MSX_SLOT_RESET(empty)
79{
80   /* reset void */
81}
82
83MSX_SLOT_MAP(empty)
84{
85   msx_state *drvstate = machine.driver_data<msx_state>();
86   msx_cpu_setbank (machine, page * 2 + 1, drvstate->m_empty);
87   msx_cpu_setbank (machine, page * 2 + 2, drvstate->m_empty);
88}
89
90MSX_SLOT_INIT(rom)
91{
92   state->m_type = SLOT_ROM;
93   state->m_mem = mem;
94   state->m_size = size;
95   state->m_start_page = page;
96
97   return 0;
98}
99
100MSX_SLOT_RESET(rom)
101{
102   /* state-less */
103}
104
105MSX_SLOT_MAP(rom)
106{
107   UINT8 *mem = state->m_mem + (page - state->m_start_page) * 0x4000;
108
109   msx_cpu_setbank (machine, page * 2 + 1, mem);
110   msx_cpu_setbank (machine, page * 2 + 2, mem + 0x2000);
111}
112
113MSX_SLOT_INIT(ram)
114{
115   state->m_mem = auto_alloc_array(machine, UINT8, size);
116   memset (state->m_mem, 0, size);
117   state->m_type = SLOT_RAM;
118   state->m_start_page = page;
119   state->m_size = size;
120
121   return 0;
122}
123
124MSX_SLOT_MAP(ram)
125{
126   msx_state *drvstate = machine.driver_data<msx_state>();
127   UINT8 *mem = state->m_mem + (page - state->m_start_page) * 0x4000;
128
129   drvstate->m_ram_pages[page] = mem;
130   msx_cpu_setbank (machine, page * 2 + 1, mem);
131   msx_cpu_setbank (machine, page * 2 + 2, mem + 0x2000);
132}
133
134MSX_SLOT_RESET(ram)
135{
136}
137
138MSX_SLOT_INIT(rammm)
139{
140   int i, mask, nsize;
141#ifdef MONMSX
142   FILE *f;
143#endif
144
145   nsize = 0x10000; /* 64 kb */
146   mask = 3;
147   for (i=0; i<6; i++)
148   {
149      if (size == nsize)
150      {
151         break;
152      }
153      mask = (mask << 1) | 1;
154      nsize <<= 1;
155   }
156   if (i == 6)
157   {
158      logerror ("ram mapper: error: must be 64kb, 128kb, 256kb, 512kb, "
159              "1mb, 2mb or 4mb\n");
160      return 1;
161   }
162   state->m_mem = auto_alloc_array(machine, UINT8, size);
163   memset (state->m_mem, 0, size);
164
165#ifdef MONMSX
166   f = fopen ("/home/sean/msx/hack/monmsx.bin", "r");
167   if (f)
168   {
169      fseek (f, 6L, SEEK_SET);
170      fread (state->m_mem, 1, 6151 - 6, f);
171      fclose (f);
172   }
173#endif
174
175   state->m_type = SLOT_RAM_MM;
176   state->m_start_page = page;
177   state->m_size = size;
178   state->m_bank_mask = mask;
179
180   return 0;
181}
182
183MSX_SLOT_RESET(rammm)
184{
185   msx_state *drvstate = machine.driver_data<msx_state>();
186   int i;
187
188   for (i=0; i<4; i++)
189   {
190      drvstate->m_ram_mapper[i] = 3 - i;
191   }
192}
193
194MSX_SLOT_MAP(rammm)
195{
196   msx_state *drvstate = machine.driver_data<msx_state>();
197   UINT8 *mem = state->m_mem +
198         0x4000 * (drvstate->m_ram_mapper[page] & state->m_bank_mask);
199
200   drvstate->m_ram_pages[page] = mem;
201   msx_cpu_setbank (machine, page * 2 + 1, mem);
202   msx_cpu_setbank (machine, page * 2 + 2, mem + 0x2000);
203}
204
205MSX_SLOT_INIT(msxdos2)
206{
207   if (size != 0x10000)
208   {
209      logerror ("msxdos2: error: rom file must be 64kb\n");
210      return 1;
211   }
212   state->m_type = SLOT_MSXDOS2;
213   state->m_mem = mem;
214   state->m_size = size;
215
216   return 0;
217}
218
219MSX_SLOT_RESET(msxdos2)
220{
221   state->m_banks[0] = 0;
222}
223
224MSX_SLOT_MAP(msxdos2)
225{
226   msx_state *drvstate = machine.driver_data<msx_state>();
227   if (page != 1)
228   {
229      msx_cpu_setbank (machine, page * 2 + 1, drvstate->m_empty);
230      msx_cpu_setbank (machine, page * 2 + 2, drvstate->m_empty);
231   }
232   else
233   {
234      msx_cpu_setbank (machine, 3, state->m_mem + state->m_banks[0] * 0x4000);
235      msx_cpu_setbank (machine, 4, state->m_mem + state->m_banks[0] * 0x4000 + 0x2000);
236   }
237}
238
239MSX_SLOT_WRITE(msxdos2)
240{
241   if (addr == 0x6000)
242   {
243      state->m_banks[0] = val & 3;
244      slot_msxdos2_map (machine, state, 1);
245   }
246}
247
248MSX_SLOT_INIT(konami)
249{
250   int banks;
251
252   if (size > 0x200000)
253   {
254      logerror ("konami: warning: truncating to 2mb\n");
255      size = 0x200000;
256      return 1;
257   }
258   banks = size / 0x2000;
259   if (size != banks * 0x2000 || (~(banks - 1) % banks))
260   {
261      logerror ("konami: error: must be a 2 power of 8kb\n");
262      return 1;
263   }
264   state->m_type = SLOT_KONAMI;
265   state->m_mem = mem;
266   state->m_size = size;
267   state->m_bank_mask = banks - 1;
268
269   return 0;
270}
271
272MSX_SLOT_RESET(konami)
273{
274   int i;
275
276   for (i=0; i<4; i++) state->m_banks[i] = i;
277}
278
279MSX_SLOT_MAP(konami)
280{
281   switch (page)
282   {
283   case 0:
284      msx_cpu_setbank (machine, 1, state->m_mem);
285      msx_cpu_setbank (machine, 2, state->m_mem + state->m_banks[1] * 0x2000);
286      break;
287   case 1:
288      msx_cpu_setbank (machine, 3, state->m_mem);
289      msx_cpu_setbank (machine, 4, state->m_mem + state->m_banks[1] * 0x2000);
290      break;
291   case 2:
292      msx_cpu_setbank (machine, 5, state->m_mem + state->m_banks[2] * 0x2000);
293      msx_cpu_setbank (machine, 6, state->m_mem + state->m_banks[3] * 0x2000);
294      break;
295   case 3:
296      msx_cpu_setbank (machine, 7, state->m_mem + state->m_banks[2] * 0x2000);
297      msx_cpu_setbank (machine, 8, state->m_mem + state->m_banks[3] * 0x2000);
298   }
299}
300
301MSX_SLOT_WRITE(konami)
302{
303   msx_state *drvstate = machine.driver_data<msx_state>();
304   switch (addr)
305   {
306   case 0x6000:
307      state->m_banks[1] = val & state->m_bank_mask;
308      slot_konami_map (machine, state, 1);
309      if (drvstate->m_state[0] == state)
310      {
311         slot_konami_map (machine, state, 0);
312      }
313      break;
314   case 0x8000:
315      state->m_banks[2] = val & state->m_bank_mask;
316      slot_konami_map (machine, state, 2);
317      if (drvstate->m_state[3] == state)
318      {
319         slot_konami_map (machine, state, 3);
320      }
321      break;
322   case 0xa000:
323      state->m_banks[3] = val & state->m_bank_mask;
324      slot_konami_map (machine, state, 2);
325      if (drvstate->m_state[3] == state)
326      {
327         slot_konami_map (machine, state, 3);
328      }
329   }
330}
331
332MSX_SLOT_INIT(konami_scc)
333{
334   int banks;
335
336   if (size > 0x200000)
337   {
338      logerror ("konami_scc: warning: truncating to 2mb\n");
339      size = 0x200000;
340      return 1;
341   }
342   banks = size / 0x2000;
343   if (size != banks * 0x2000 || (~(banks - 1) % banks))
344   {
345      logerror ("konami_scc: error: must be a 2 power of 8kb\n");
346      return 1;
347   }
348
349   state->m_type = SLOT_KONAMI_SCC;
350   state->m_mem = mem;
351   state->m_size = size;
352   state->m_bank_mask = banks - 1;
353
354   return 0;
355}
356
357MSX_SLOT_RESET(konami_scc)
358{
359   int i;
360
361   for (i=0; i<4; i++) state->m_banks[i] = i;
362   state->m_cart.scc.active = 0;
363}
364
365static READ8_HANDLER (konami_scc_bank5)
366{
367   if (offset & 0x80)
368   {
369#if 0
370      if ((offset & 0xff) >= 0xe0)
371      {
372         /* write 0xff to deformation register */
373      }
374#endif
375      return 0xff;
376   }
377   else
378   {
379      return k051649_waveform_r (space->machine().device("k051649"), offset & 0x7f);
380   }
381}
382
383MSX_SLOT_MAP(konami_scc)
384{
385   switch (page)
386   {
387   case 0:
388      msx_cpu_setbank (machine, 1, state->m_mem + state->m_banks[2] * 0x2000);
389      msx_cpu_setbank (machine, 2, state->m_mem + state->m_banks[3] * 0x2000);
390      break;
391   case 1:
392      msx_cpu_setbank (machine, 3, state->m_mem + state->m_banks[0] * 0x2000);
393      msx_cpu_setbank (machine, 4, state->m_mem + state->m_banks[1] * 0x2000);
394      break;
395   case 2:
396      msx_cpu_setbank (machine, 5, state->m_mem + state->m_banks[2] * 0x2000);
397      msx_cpu_setbank (machine, 6, state->m_mem + state->m_banks[3] * 0x2000);
398      if (state->m_cart.scc.active ) {
399         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_read_handler(0x9800, 0x9fff, FUNC(konami_scc_bank5));
400      } else {
401         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x9800, 0x9fff,"bank7");
402      }
403      break;
404   case 3:
405      msx_cpu_setbank (machine, 7, state->m_mem + state->m_banks[0] * 0x2000);
406      msx_cpu_setbank (machine, 8, state->m_mem + state->m_banks[1] * 0x2000);
407   }
408}
409
410MSX_SLOT_WRITE(konami_scc)
411{
412   msx_state *drvstate = machine.driver_data<msx_state>();
413   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
414   if (addr >= 0x5000 && addr < 0x5800)
415   {
416      state->m_banks[0] = val & state->m_bank_mask;
417      slot_konami_scc_map (machine, state, 1);
418      if (drvstate->m_state[3] == state)
419      {
420         slot_konami_scc_map (machine, state, 3);
421      }
422   }
423   else if (addr >= 0x7000 && addr < 0x7800)
424   {
425      state->m_banks[1] = val & state->m_bank_mask;
426      slot_konami_scc_map (machine, state, 1);
427      if (drvstate->m_state[3] == state)
428      {
429         slot_konami_scc_map (machine, state, 3);
430      }
431   }
432   else if (addr >= 0x9000 && addr < 0x9800)
433   {
434      state->m_banks[2] = val & state->m_bank_mask;
435      state->m_cart.scc.active = ((val & 0x3f) == 0x3f);
436      slot_konami_scc_map (machine, state, 2);
437      if (drvstate->m_state[0] == state)
438      {
439         slot_konami_scc_map (machine, state, 0);
440      }
441   }
442   else if (state->m_cart.scc.active && addr >= 0x9800 && addr < 0xa000)
443   {
444      device_t *k051649 = space->machine().device("k051649");
445      int offset = addr & 0xff;
446
447      if (offset < 0x80)
448      {
449         k051649_waveform_w (k051649, offset, val);
450      }
451      else if (offset < 0xa0)
452      {
453         offset &= 0xf;
454         if (offset < 0xa)
455         {
456            k051649_frequency_w (k051649, offset, val);
457         }
458         else if (offset < 0xf)
459         {
460            k051649_volume_w (k051649, offset - 0xa, val);
461         }
462         else
463         {
464            k051649_keyonoff_w (k051649, 0, val);
465         }
466      }
467#if 0
468      else if (offset >= 0xe0)
469      {
470         /* deformation register */
471      }
472#endif
473   }
474   else if (addr >= 0xb000 && addr < 0xb800)
475   {
476      state->m_banks[3] = val & state->m_bank_mask;
477      slot_konami_scc_map (machine, state, 2);
478      if (drvstate->m_state[0] == state)
479      {
480         slot_konami_scc_map (machine, state, 0);
481      }
482   }
483}
484
485MSX_SLOT_INIT(ascii8)
486{
487   int banks;
488
489   if (size > 0x200000)
490   {
491      logerror ("ascii8: warning: truncating to 2mb\n");
492      size = 0x200000;
493      return 1;
494   }
495   banks = size / 0x2000;
496   if (size != banks * 0x2000 || (~(banks - 1) % banks))
497   {
498      logerror ("ascii8: error: must be a 2 power of 8kb\n");
499      return 1;
500   }
501   state->m_type = SLOT_ASCII8;
502   state->m_mem = mem;
503   state->m_size = size;
504   state->m_bank_mask = banks - 1;
505
506   return 0;
507}
508
509MSX_SLOT_RESET(ascii8)
510{
511   int i;
512
513   for (i=0; i<4; i++) state->m_banks[i] = i;
514}
515
516MSX_SLOT_MAP(ascii8)
517{
518   msx_state *drvstate = machine.driver_data<msx_state>();
519   switch (page)
520   {
521   case 0:
522      msx_cpu_setbank (machine, 1, drvstate->m_empty);
523      msx_cpu_setbank (machine, 2, drvstate->m_empty);
524      break;
525   case 1:
526      msx_cpu_setbank (machine, 3, state->m_mem + state->m_banks[0] * 0x2000);
527      msx_cpu_setbank (machine, 4, state->m_mem + state->m_banks[1] * 0x2000);
528      break;
529   case 2:
530      msx_cpu_setbank (machine, 5, state->m_mem + state->m_banks[2] * 0x2000);
531      msx_cpu_setbank (machine, 6, state->m_mem + state->m_banks[3] * 0x2000);
532      break;
533   case 3:
534      msx_cpu_setbank (machine, 7, drvstate->m_empty);
535      msx_cpu_setbank (machine, 8, drvstate->m_empty);
536   }
537}
538
539MSX_SLOT_WRITE(ascii8)
540{
541   msx_state *drvstate = machine.driver_data<msx_state>();
542   int bank;
543
544   if (addr >= 0x6000 && addr < 0x8000)
545   {
546      bank = (addr / 0x800) & 3;
547
548      state->m_banks[bank] = val & state->m_bank_mask;
549      if (bank <= 1)
550      {
551         slot_ascii8_map (machine, state, 1);
552      }
553      else if (drvstate->m_state[2] == state)
554      {
555         slot_ascii8_map (machine, state, 2);
556      }
557   }
558}
559
560MSX_SLOT_INIT(ascii16)
561{
562   int banks;
563
564   if (size > 0x400000)
565   {
566      logerror ("ascii16: warning: truncating to 4mb\n");
567      size = 0x400000;
568   }
569   banks = size / 0x4000;
570   if (size != banks * 0x4000 || (~(banks - 1) % banks))
571   {
572      logerror ("ascii16: error: must be a 2 power of 16kb\n");
573      return 1;
574   }
575
576   state->m_type = SLOT_ASCII16;
577   state->m_mem = mem;
578   state->m_size = size;
579   state->m_bank_mask = banks - 1;
580
581   return 0;
582}
583
584MSX_SLOT_RESET(ascii16)
585{
586   int i;
587
588   for (i=0; i<2; i++) state->m_banks[i] = i;
589}
590
591MSX_SLOT_MAP(ascii16)
592{
593   msx_state *drvstate = machine.driver_data<msx_state>();
594   UINT8 *mem;
595
596   switch (page)
597   {
598   case 0:
599      msx_cpu_setbank (machine, 1, drvstate->m_empty);
600      msx_cpu_setbank (machine, 2, drvstate->m_empty);
601      break;
602   case 1:
603      mem = state->m_mem + state->m_banks[0] * 0x4000;
604      msx_cpu_setbank (machine, 3, mem);
605      msx_cpu_setbank (machine, 4, mem + 0x2000);
606      break;
607   case 2:
608      mem = state->m_mem + state->m_banks[1] * 0x4000;
609      msx_cpu_setbank (machine, 5, mem);
610      msx_cpu_setbank (machine, 6, mem + 0x2000);
611      break;
612   case 3:
613      msx_cpu_setbank (machine, 7, drvstate->m_empty);
614      msx_cpu_setbank (machine, 8, drvstate->m_empty);
615   }
616}
617
618MSX_SLOT_WRITE(ascii16)
619{
620   msx_state *drvstate = machine.driver_data<msx_state>();
621   if (addr >= 0x6000 && addr < 0x6800)
622   {
623      state->m_banks[0] = val & state->m_bank_mask;
624      slot_ascii16_map (machine, state, 1);
625   }
626   else if (addr >= 0x7000 && addr < 0x7800)
627   {
628      state->m_banks[1] = val & state->m_bank_mask;
629      if (drvstate->m_state[2] == state)
630      {
631         slot_ascii16_map (machine, state, 2);
632      }
633   }
634}
635
636MSX_SLOT_INIT(ascii8_sram)
637{
638   static const char sramfile[] = "ascii8";
639   int banks;
640
641   state->m_cart.sram.mem = auto_alloc_array(machine, UINT8, 0x2000);
642   if (size > 0x100000)
643   {
644      logerror ("ascii8_sram: warning: truncating to 1mb\n");
645      size = 0x100000;
646      return 1;
647   }
648   banks = size / 0x2000;
649   if (size != banks * 0x2000 || (~(banks - 1) % banks))
650   {
651      logerror ("ascii8_sram: error: must be a 2 power of 8kb\n");
652      return 1;
653   }
654   memset (state->m_cart.sram.mem, 0, 0x2000);
655   state->m_type = SLOT_ASCII8_SRAM;
656   state->m_mem = mem;
657   state->m_size = size;
658   state->m_bank_mask = banks - 1;
659   state->m_cart.sram.sram_mask = banks;
660   state->m_cart.sram.empty_mask = ~(banks | (banks - 1));
661   if (!state->m_sramfile)
662   {
663      state->m_sramfile = sramfile;
664   }
665
666   return 0;
667}
668
669MSX_SLOT_RESET(ascii8_sram)
670{
671   int i;
672
673   for (i=0; i<4; i++) state->m_banks[i] = i;
674}
675
676static UINT8 *ascii8_sram_bank_select (msx_state *drvstate, slot_state *state, int bankno)
677{
678   int bank = state->m_banks[bankno];
679
680   if (bank & state->m_cart.sram.empty_mask)
681   {
682      return drvstate->m_empty;
683   }
684   else if (bank & state->m_cart.sram.sram_mask)
685   {
686      return state->m_cart.sram.mem;
687   }
688   else
689   {
690      return state->m_mem + (bank & state->m_bank_mask) * 0x2000;
691   }
692}
693
694MSX_SLOT_MAP(ascii8_sram)
695{
696   msx_state *drvstate = machine.driver_data<msx_state>();
697   switch (page)
698   {
699   case 0:
700      msx_cpu_setbank (machine, 1, drvstate->m_empty);
701      msx_cpu_setbank (machine, 2, drvstate->m_empty);
702      break;
703   case 1:
704      msx_cpu_setbank (machine, 3, ascii8_sram_bank_select (drvstate, state, 0));
705      msx_cpu_setbank (machine, 4, ascii8_sram_bank_select (drvstate, state, 1));
706      break;
707   case 2:
708      msx_cpu_setbank (machine, 5, ascii8_sram_bank_select (drvstate, state, 2));
709      msx_cpu_setbank (machine, 6, ascii8_sram_bank_select (drvstate, state, 3));
710      break;
711   case 3:
712      msx_cpu_setbank (machine, 7, drvstate->m_empty);
713      msx_cpu_setbank (machine, 8, drvstate->m_empty);
714   }
715}
716
717MSX_SLOT_WRITE(ascii8_sram)
718{
719   msx_state *drvstate = machine.driver_data<msx_state>();
720   int bank;
721
722   if (addr >= 0x6000 && addr < 0x8000)
723   {
724      bank = (addr / 0x800) & 3;
725
726      state->m_banks[bank] = val;
727      if (bank <= 1)
728      {
729         slot_ascii8_sram_map (machine, state, 1);
730      }
731      else if (drvstate->m_state[2] == state)
732      {
733         slot_ascii8_sram_map (machine, state, 2);
734      }
735   }
736   if (addr >= 0x8000 && addr < 0xc000)
737   {
738      bank = addr < 0xa000 ? 2 : 3;
739      if (!(state->m_banks[bank] & state->m_cart.sram.empty_mask) &&
740           (state->m_banks[bank] & state->m_cart.sram.sram_mask))
741      {
742         state->m_cart.sram.mem[addr & 0x1fff] = val;
743      }
744   }
745}
746
747MSX_SLOT_LOADSRAM(ascii8_sram)
748{
749   if (!state->m_sramfile)
750   {
751      logerror ("ascii8_sram: error: no sram filename provided\n");
752      return 1;
753   }
754   emu_file f(machine.options().memcard_directory(), OPEN_FLAG_READ);
755   file_error filerr = f.open(state->m_sramfile);
756   if (filerr == FILERR_NONE)
757   {
758      if (f.read(state->m_cart.sram.mem, 0x2000) == 0x2000)
759      {
760         logerror ("ascii8_sram: info: sram loaded\n");
761         return 0;
762      }
763      memset (state->m_cart.sram.mem, 0, 0x2000);
764      logerror ("ascii8_sram: warning: could not read sram file\n");
765      return 1;
766   }
767
768   logerror ("ascii8_sram: warning: could not open sram file for reading\n");
769
770   return 1;
771}
772
773MSX_SLOT_SAVESRAM(ascii8_sram)
774{
775   if (!state->m_sramfile)
776   {
777      return 0;
778   }
779
780   emu_file f(machine.options().memcard_directory(), OPEN_FLAG_WRITE);
781   file_error filerr = f.open(state->m_sramfile);
782   if (filerr == FILERR_NONE)
783   {
784      f.write(state->m_cart.sram.mem, 0x2000);
785      logerror ("ascii8_sram: info: sram saved\n");
786
787      return 0;
788   }
789
790   logerror ("ascii8_sram: warning: could not open sram file for saving\n");
791
792   return 1;
793}
794
795MSX_SLOT_INIT(ascii16_sram)
796{
797   static const char sramfile[] = "ascii16";
798   int banks;
799
800   state->m_cart.sram.mem = auto_alloc_array(machine, UINT8, 0x4000);
801
802   if (size > 0x200000)
803   {
804      logerror ("ascii16_sram: warning: truncating to 2mb\n");
805      size = 0x200000;
806   }
807   banks = size / 0x4000;
808   if (size != banks * 0x4000 || (~(banks - 1) % banks))
809   {
810      logerror ("ascii16_sram: error: must be a 2 power of 16kb\n");
811      return 1;
812   }
813
814   memset (state->m_cart.sram.mem, 0, 0x4000);
815   state->m_type = SLOT_ASCII16_SRAM;
816   state->m_mem = mem;
817   state->m_size = size;
818   state->m_bank_mask = banks - 1;
819   state->m_cart.sram.sram_mask = banks;
820   state->m_cart.sram.empty_mask = ~(banks | (banks - 1));
821   if (!state->m_sramfile)
822   {
823      state->m_sramfile = sramfile;
824   }
825
826   return 0;
827}
828
829MSX_SLOT_RESET(ascii16_sram)
830{
831   int i;
832
833   for (i=0; i<2; i++) state->m_banks[i] = i;
834}
835
836static UINT8 *ascii16_sram_bank_select (msx_state *drvstate, slot_state *state, int bankno)
837{
838   int bank = state->m_banks[bankno];
839
840   if (bank & state->m_cart.sram.empty_mask)
841   {
842      return drvstate->m_empty;
843   }
844   else if (bank & state->m_cart.sram.sram_mask)
845   {
846      return state->m_cart.sram.mem;
847   }
848   else
849   {
850      return state->m_mem + (bank & state->m_bank_mask) * 0x4000;
851   }
852}
853
854MSX_SLOT_MAP(ascii16_sram)
855{
856   msx_state *drvstate = machine.driver_data<msx_state>();
857   UINT8 *mem;
858
859   switch (page)
860   {
861   case 0:
862      msx_cpu_setbank (machine, 1, drvstate->m_empty);
863      msx_cpu_setbank (machine, 2, drvstate->m_empty);
864      break;
865   case 1:
866      mem = ascii16_sram_bank_select (drvstate, state, 0);
867      msx_cpu_setbank (machine, 3, mem);
868      msx_cpu_setbank (machine, 4, mem + 0x2000);
869      break;
870   case 2:
871      mem = ascii16_sram_bank_select (drvstate, state, 1);
872      msx_cpu_setbank (machine, 5, mem);
873      msx_cpu_setbank (machine, 6, mem + 0x2000);
874      break;
875   case 3:
876      msx_cpu_setbank (machine, 7, drvstate->m_empty);
877      msx_cpu_setbank (machine, 8, drvstate->m_empty);
878   }
879}
880
881MSX_SLOT_WRITE(ascii16_sram)
882{
883   msx_state *drvstate = machine.driver_data<msx_state>();
884   if (addr >= 0x6000 && addr < 0x6800)
885   {
886      state->m_banks[0] = val;
887      slot_ascii16_sram_map (machine, state, 1);
888   }
889   else if (addr >= 0x7000 && addr < 0x7800)
890   {
891      state->m_banks[1] = val;
892      if (drvstate->m_state[2] == state)
893      {
894         slot_ascii16_sram_map (machine, state, 2);
895      }
896   }
897   else if (addr >= 0x8000 && addr < 0xc000)
898   {
899      if (!(state->m_banks[1] & state->m_cart.sram.empty_mask) &&
900           (state->m_banks[1] & state->m_cart.sram.sram_mask))
901      {
902         int offset, i;
903
904         offset = addr & 0x07ff;
905         for (i=0; i<8; i++)
906         {
907            state->m_cart.sram.mem[offset] = val;
908            offset += 0x0800;
909         }
910      }
911   }
912}
913
914MSX_SLOT_LOADSRAM(ascii16_sram)
915{
916   UINT8 *p;
917
918   if (!state->m_sramfile)
919   {
920      logerror ("ascii16_sram: error: no sram filename provided\n");
921      return 1;
922   }
923
924   emu_file f(machine.options().memcard_directory(), OPEN_FLAG_READ);
925   file_error filerr = f.open(state->m_sramfile);
926   if (filerr == FILERR_NONE)
927   {
928      p = state->m_cart.sram.mem;
929
930      if (f.read(state->m_cart.sram.mem, 0x200) == 0x200)
931      {
932         int /*offset,*/ i;
933         //offset = 0;
934         for (i=0; i<7; i++)
935         {
936            memcpy (p + 0x800, p, 0x800);
937            p += 0x800;
938         }
939
940         logerror ("ascii16_sram: info: sram loaded\n");
941         return 0;
942      }
943      memset (state->m_cart.sram.mem, 0, 0x4000);
944      logerror ("ascii16_sram: warning: could not read sram file\n");
945      return 1;
946   }
947
948   logerror ("ascii16_sram: warning: could not open sram file for reading\n");
949
950   return 1;
951}
952
953MSX_SLOT_SAVESRAM(ascii16_sram)
954{
955   if (!state->m_sramfile)
956   {
957      return 0;
958   }
959   emu_file f(machine.options().memcard_directory(), OPEN_FLAG_WRITE);
960   file_error filerr = f.open(state->m_sramfile);
961   if (filerr == FILERR_NONE)
962   {
963      f.write(state->m_cart.sram.mem, 0x200);
964      logerror ("ascii16_sram: info: sram saved\n");
965
966      return 0;
967   }
968
969   logerror ("ascii16_sram: warning: could not open sram file for saving\n");
970
971   return 1;
972}
973
974MSX_SLOT_INIT(rtype)
975{
976   if (!(size == 0x60000 || size == 0x80000))
977   {
978      logerror ("rtype: error: rom file should be exactly 384kb\n");
979      return 1;
980   }
981
982   state->m_type = SLOT_RTYPE;
983   state->m_mem = mem;
984   state->m_size = size;
985
986   return 0;
987}
988
989MSX_SLOT_RESET(rtype)
990{
991   state->m_banks[0] = 15;
992}
993
994MSX_SLOT_MAP(rtype)
995{
996   msx_state *drvstate = machine.driver_data<msx_state>();
997   UINT8 *mem;
998
999   switch (page)
1000   {
1001   case 0:
1002      msx_cpu_setbank (machine, 1, drvstate->m_empty);
1003      msx_cpu_setbank (machine, 2, drvstate->m_empty);
1004      break;
1005   case 1:
1006      mem = state->m_mem + 15 * 0x4000;
1007      msx_cpu_setbank (machine, 3, mem);
1008      msx_cpu_setbank (machine, 4, mem + 0x2000);
1009      break;
1010   case 2:
1011      mem = state->m_mem + state->m_banks[0] * 0x4000;
1012      msx_cpu_setbank (machine, 5, mem);
1013      msx_cpu_setbank (machine, 6, mem + 0x2000);
1014      break;
1015   case 3:
1016      msx_cpu_setbank (machine, 7, drvstate->m_empty);
1017      msx_cpu_setbank (machine, 8, drvstate->m_empty);
1018   }
1019}
1020
1021MSX_SLOT_WRITE(rtype)
1022{
1023   msx_state *drvstate = machine.driver_data<msx_state>();
1024   if (addr >= 0x7000 && addr < 0x8000)
1025   {
1026      int data ;
1027
1028      if (val & 0x10)
1029      {
1030         data = 0x10 | (val & 7);
1031      }
1032      else
1033      {
1034         data = val & 0x0f;
1035      }
1036      state->m_banks[0] = data;
1037      if (drvstate->m_state[2] == state)
1038      {
1039         slot_rtype_map (machine, state, 2);
1040      }
1041   }
1042}
1043
1044MSX_SLOT_INIT(gmaster2)
1045{
1046   UINT8 *p;
1047   static const char sramfile[] = "GameMaster2";
1048
1049   if (size != 0x20000)
1050   {
1051      logerror ("gmaster2: error: rom file should be 128kb\n");
1052      return 1;
1053   }
1054   state->m_type = SLOT_GAMEMASTER2;
1055   state->m_size = size;
1056   state->m_mem = mem;
1057
1058   p = auto_alloc_array(machine, UINT8, 0x4000);
1059   memset (p, 0, 0x4000);
1060   state->m_cart.sram.mem = p;
1061   if (!state->m_sramfile)
1062   {
1063      state->m_sramfile = sramfile;
1064   }
1065
1066   return 0;
1067}
1068
1069MSX_SLOT_RESET(gmaster2)
1070{
1071   int i;
1072
1073   for (i=0; i<4; i++)
1074   {
1075      state->m_banks[i] = i;
1076   }
1077}
1078
1079MSX_SLOT_MAP(gmaster2)
1080{
1081   switch (page)
1082   {
1083   case 0:
1084   case 1:
1085      msx_cpu_setbank (machine, 1 + page * 2, state->m_mem); /* bank 0 is hardwired */
1086      if (state->m_banks[1] > 15)
1087      {
1088         msx_cpu_setbank (machine, 2 + page * 2, state->m_cart.sram.mem +
1089               (state->m_banks[1] - 16) * 0x2000);
1090      }
1091      else
1092      {
1093         msx_cpu_setbank (machine, 2 + page * 2, state->m_mem + state->m_banks[1] * 0x2000);
1094      }
1095      break;
1096   case 2:
1097   case 3:
1098      if (state->m_banks[2] > 15)
1099      {
1100         msx_cpu_setbank (machine, 5 + page * 2, state->m_cart.sram.mem +
1101               (state->m_banks[2] - 16) * 0x2000);
1102      }
1103      else
1104      {
1105         msx_cpu_setbank (machine, 5 + page * 2, state->m_mem + state->m_banks[2] * 0x2000);
1106      }
1107      if (state->m_banks[3] > 15)
1108      {
1109         msx_cpu_setbank (machine, 6 + page * 2, state->m_cart.sram.mem +
1110               (state->m_banks[3] - 16) * 0x2000);
1111      }
1112      else
1113      {
1114         msx_cpu_setbank (machine, 6 + page * 2, state->m_mem + state->m_banks[3] * 0x2000);
1115      }
1116      break;
1117   }
1118}
1119
1120MSX_SLOT_WRITE(gmaster2)
1121{
1122   msx_state *drvstate = machine.driver_data<msx_state>();
1123   if (addr >= 0x6000 && addr < 0x7000)
1124   {
1125      if (val & 0x10)
1126      {
1127         val = val & 0x20 ? 17 : 16;
1128      }
1129      else
1130      {
1131         val = val & 15;
1132      }
1133      state->m_banks[1] = val;
1134      slot_gmaster2_map (machine, state, 1);
1135      if (drvstate->m_state[0] == state)
1136      {
1137         slot_gmaster2_map (machine, state, 0);
1138      }
1139   }
1140   else if (addr >= 0x8000 && addr < 0x9000)
1141   {
1142      if (val & 0x10)
1143      {
1144         val = val & 0x20 ? 17 : 16;
1145      }
1146      else
1147      {
1148         val = val & 15;
1149      }
1150      state->m_banks[2] = val;
1151      slot_gmaster2_map (machine, state, 2);
1152      if (drvstate->m_state[3] == state)
1153      {
1154         slot_gmaster2_map (machine, state, 3);
1155      }
1156   }
1157   else if (addr >= 0xa000 && addr < 0xb000)
1158   {
1159      if (val & 0x10)
1160      {
1161         val = val & 0x20 ? 17 : 16;
1162      }
1163      else
1164      {
1165         val = val & 15;
1166      }
1167      state->m_banks[3] = val;
1168      slot_gmaster2_map (machine, state, 2);
1169      if (drvstate->m_state[3] == state)
1170      {
1171         slot_gmaster2_map (machine, state, 3);
1172      }
1173   }
1174   else if (addr >= 0xb000 && addr < 0xc000)
1175   {
1176      addr &= 0x0fff;
1177      switch (state->m_banks[3])
1178      {
1179      case 16:
1180         state->m_cart.sram.mem[addr] = val;
1181         state->m_cart.sram.mem[addr + 0x1000] = val;
1182         break;
1183      case 17:
1184         state->m_cart.sram.mem[addr + 0x2000] = val;
1185         state->m_cart.sram.mem[addr + 0x3000] = val;
1186         break;
1187      }
1188   }
1189}
1190
1191MSX_SLOT_LOADSRAM(gmaster2)
1192{
1193   UINT8 *p;
1194
1195   p = state->m_cart.sram.mem;
1196
1197   emu_file f(machine.options().memcard_directory(), OPEN_FLAG_READ);
1198   file_error filerr = f.open(state->m_sramfile);
1199   if (filerr == FILERR_NONE)
1200   {
1201      if (f.read(p + 0x1000, 0x2000) == 0x2000)
1202      {
1203         memcpy (p, p + 0x1000, 0x1000);
1204         memcpy (p + 0x3000, p + 0x2000, 0x1000);
1205         logerror ("gmaster2: info: sram loaded\n");
1206         return 0;
1207      }
1208      memset (p, 0, 0x4000);
1209      logerror ("gmaster2: warning: could not read sram file\n");
1210      return 1;
1211   }
1212
1213   logerror ("gmaster2: warning: could not open sram file for reading\n");
1214
1215   return 1;
1216}
1217
1218MSX_SLOT_SAVESRAM(gmaster2)
1219{
1220   emu_file f(machine.options().memcard_directory(), OPEN_FLAG_WRITE);
1221   file_error filerr = f.open(state->m_sramfile);
1222   if (filerr == FILERR_NONE)
1223   {
1224      f.write(state->m_cart.sram.mem + 0x1000, 0x2000);
1225      logerror ("gmaster2: info: sram saved\n");
1226
1227      return 0;
1228   }
1229
1230   logerror ("gmaster2: warning: could not open sram file for saving\n");
1231
1232   return 1;
1233}
1234
1235MSX_SLOT_INIT(diskrom)
1236{
1237   if (size != 0x4000)
1238   {
1239      logerror ("diskrom: error: the diskrom should be 16kb\n");
1240      return 1;
1241   }
1242
1243   state->m_type = SLOT_DISK_ROM;
1244   state->m_mem = mem;
1245   state->m_size = size;
1246
1247   return 0;
1248}
1249
1250MSX_SLOT_RESET(diskrom)
1251{
1252   device_t *fdc = machine.device("wd179x");
1253   wd17xx_reset(fdc);
1254}
1255
1256static READ8_HANDLER (msx_diskrom_page1_r)
1257{
1258   msx_state *state = space->machine().driver_data<msx_state>();
1259   device_t *fdc = space->machine().device("wd179x");
1260   switch (offset)
1261   {
1262   case 0: return wd17xx_status_r (fdc, 0);
1263   case 1: return wd17xx_track_r (fdc, 0);
1264   case 2: return wd17xx_sector_r (fdc, 0);
1265   case 3: return wd17xx_data_r (fdc, 0);
1266   case 7: return state->m_dsk_stat;
1267   default:
1268      return state->m_state[1]->m_mem[offset + 0x3ff8];
1269   }
1270}
1271
1272static READ8_HANDLER (msx_diskrom_page2_r)
1273{
1274   msx_state *state = space->machine().driver_data<msx_state>();
1275   device_t *fdc = space->machine().device("wd179x");
1276   if (offset >= 0x7f8)
1277   {
1278      switch (offset)
1279      {
1280      case 0x7f8:
1281         return wd17xx_status_r (fdc, 0);
1282      case 0x7f9:
1283         return wd17xx_track_r (fdc, 0);
1284      case 0x7fa:
1285         return wd17xx_sector_r (fdc, 0);
1286      case 0x7fb:
1287         return wd17xx_data_r (fdc, 0);
1288      case 0x7ff:
1289         return state->m_dsk_stat;
1290      default:
1291         return state->m_state[2]->m_mem[offset + 0x3800];
1292      }
1293   }
1294   else
1295   {
1296      return 0xff;
1297   }
1298}
1299
1300MSX_SLOT_MAP(diskrom)
1301{
1302   msx_state *drvstate = machine.driver_data<msx_state>();
1303   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
1304   switch (page)
1305   {
1306   case 0:
1307      msx_cpu_setbank (machine, 1, drvstate->m_empty);
1308      msx_cpu_setbank (machine, 2, drvstate->m_empty);
1309      break;
1310   case 1:
1311      msx_cpu_setbank (machine, 3, state->m_mem);
1312      msx_cpu_setbank (machine, 4, state->m_mem + 0x2000);
1313      space->install_legacy_read_handler(0x7ff8, 0x7fff, FUNC(msx_diskrom_page1_r));
1314      break;
1315   case 2:
1316      msx_cpu_setbank (machine, 5, drvstate->m_empty);
1317      msx_cpu_setbank (machine, 6, drvstate->m_empty);
1318      space->install_legacy_read_handler(0xb800, 0xbfff, FUNC(msx_diskrom_page2_r));
1319      break;
1320   case 3:
1321      msx_cpu_setbank (machine, 7, drvstate->m_empty);
1322      msx_cpu_setbank (machine, 8, drvstate->m_empty);
1323      break;
1324   }
1325}
1326
1327MSX_SLOT_WRITE(diskrom)
1328{
1329   device_t *fdc = machine.device("wd179x");
1330   if (addr >= 0xa000 && addr < 0xc000)
1331   {
1332      addr -= 0x4000;
1333   }
1334   switch (addr)
1335   {
1336   case 0x7ff8:
1337      wd17xx_command_w (fdc, 0, val);
1338      break;
1339   case 0x7ff9:
1340      wd17xx_track_w (fdc, 0, val);
1341      break;
1342   case 0x7ffa:
1343      wd17xx_sector_w (fdc, 0, val);
1344      break;
1345   case 0x7ffb:
1346      wd17xx_data_w (fdc, 0, val);
1347      break;
1348   case 0x7ffc:
1349      wd17xx_set_side (fdc,val & 1);
1350      state->m_mem[0x3ffc] = val | 0xfe;
1351      break;
1352   case 0x7ffd:
1353      wd17xx_set_drive (fdc,val & 1);
1354      if ((state->m_mem[0x3ffd] ^ val) & 0x40)
1355      {
1356         set_led_status (machine, 0, !(val & 0x40));
1357      }
1358      state->m_mem[0x3ffd] = (val | 0x7c) & ~0x04;
1359      break;
1360   }
1361}
1362
1363MSX_SLOT_INIT(diskrom2)
1364{
1365   if (size != 0x4000)
1366   {
1367      logerror ("diskrom2: error: the diskrom2 should be 16kb\n");
1368      return 1;
1369   }
1370
1371   state->m_type = SLOT_DISK_ROM2;
1372   state->m_mem = mem;
1373   state->m_size = size;
1374
1375   return 0;
1376}
1377
1378MSX_SLOT_RESET(diskrom2)
1379{
1380   device_t *fdc = machine.device("wd179x");
1381   wd17xx_reset (fdc);
1382}
1383
1384static READ8_HANDLER (msx_diskrom2_page1_r)
1385{
1386   msx_state *state = space->machine().driver_data<msx_state>();
1387   device_t *fdc = space->machine().device("wd179x");
1388   switch (offset)
1389   {
1390   case 0: return wd17xx_status_r(fdc, 0);
1391   case 1: return wd17xx_track_r(fdc, 0);
1392   case 2: return wd17xx_sector_r(fdc, 0);
1393   case 3: return wd17xx_data_r(fdc, 0);
1394   case 4: return state->m_dsk_stat;
1395   default:
1396      return state->m_state[1]->m_mem[offset + 0x3ff8];
1397   }
1398}
1399
1400static  READ8_HANDLER (msx_diskrom2_page2_r)
1401{
1402   msx_state *state = space->machine().driver_data<msx_state>();
1403   device_t *fdc = space->machine().device("wd179x");
1404   if (offset >= 0x7b8)
1405   {
1406      switch (offset)
1407      {
1408      case 0x7b8:
1409         return wd17xx_status_r (fdc, 0);
1410      case 0x7b9:
1411         return wd17xx_track_r (fdc, 0);
1412      case 0x7ba:
1413         return wd17xx_sector_r (fdc, 0);
1414      case 0x7bb:
1415         return wd17xx_data_r (fdc, 0);
1416      case 0x7bc:
1417         return state->m_dsk_stat;
1418      default:
1419         return state->m_state[2]->m_mem[offset + 0x3800];
1420      }
1421   }
1422   else
1423   {
1424      return 0xff;
1425   }
1426}
1427
1428MSX_SLOT_MAP(diskrom2)
1429{
1430   msx_state *drvstate = machine.driver_data<msx_state>();
1431   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
1432   switch (page)
1433   {
1434   case 0:
1435      msx_cpu_setbank (machine, 1, drvstate->m_empty);
1436      msx_cpu_setbank (machine, 2, drvstate->m_empty);
1437      break;
1438   case 1:
1439      msx_cpu_setbank (machine, 3, state->m_mem);
1440      msx_cpu_setbank (machine, 4, state->m_mem + 0x2000);
1441      space->install_legacy_read_handler(0x7fb8, 0x7fbc, FUNC(msx_diskrom2_page1_r));
1442      break;
1443   case 2:
1444      msx_cpu_setbank (machine, 5, drvstate->m_empty);
1445      msx_cpu_setbank (machine, 6, drvstate->m_empty);
1446      space->install_legacy_read_handler(0xb800, 0xbfbc, FUNC(msx_diskrom2_page2_r));
1447      break;
1448   case 3:
1449      msx_cpu_setbank (machine, 7, drvstate->m_empty);
1450      msx_cpu_setbank (machine, 8, drvstate->m_empty);
1451   }
1452}
1453
1454MSX_SLOT_WRITE(diskrom2)
1455{
1456   device_t *fdc = machine.device("wd179x");
1457   if (addr >= 0xa000 && addr < 0xc000)
1458   {
1459      addr -= 0x4000;
1460   }
1461   switch (addr)
1462   {
1463   case 0x7fb8:
1464      wd17xx_command_w (fdc, 0, val);
1465      break;
1466   case 0x7fb9:
1467      wd17xx_track_w (fdc, 0, val);
1468      break;
1469   case 0x7fba:
1470      wd17xx_sector_w (fdc, 0, val);
1471      break;
1472   case 0x7fbb:
1473      wd17xx_data_w (fdc, 0, val);
1474      break;
1475   case 0x7fbc:
1476      wd17xx_set_side (fdc,val & 1);
1477      state->m_mem[0x3fbc] = val | 0xfe;
1478      wd17xx_set_drive (fdc,val & 1);
1479      if ((state->m_mem[0x3fbc] ^ val) & 0x40)
1480      {
1481         set_led_status (machine, 0, !(val & 0x40));
1482      }
1483      state->m_mem[0x3fbc] = (val | 0x7c) & ~0x04;
1484      break;
1485   }
1486}
1487
1488MSX_SLOT_INIT(synthesizer)
1489{
1490   if (size != 0x8000)
1491   {
1492      logerror ("synthesizer: error: rom file must be 32kb\n");
1493      return 1;
1494   }
1495   state->m_type = SLOT_SYNTHESIZER;
1496   state->m_mem = mem;
1497   state->m_size = size;
1498
1499   return 0;
1500}
1501
1502MSX_SLOT_RESET(synthesizer)
1503{
1504   /* empty */
1505}
1506
1507MSX_SLOT_MAP(synthesizer)
1508{
1509   msx_state *drvstate = machine.driver_data<msx_state>();
1510   switch (page)
1511   {
1512   case 0:
1513      msx_cpu_setbank (machine, 1, drvstate->m_empty);
1514      msx_cpu_setbank (machine, 2, drvstate->m_empty);
1515      break;
1516   case 1:
1517      msx_cpu_setbank (machine, 3, state->m_mem);
1518      msx_cpu_setbank (machine, 4, state->m_mem + 0x2000);
1519      break;
1520   case 2:
1521      msx_cpu_setbank (machine, 5, state->m_mem + 0x4000);
1522      msx_cpu_setbank (machine, 6, state->m_mem + 0x6000);
1523      break;
1524   case 3:
1525      msx_cpu_setbank (machine, 7, drvstate->m_empty);
1526      msx_cpu_setbank (machine, 8, drvstate->m_empty);
1527   }
1528}
1529
1530MSX_SLOT_WRITE(synthesizer)
1531{
1532   if (addr >= 0x4000 && addr < 0x8000 && !(addr & 0x0010))
1533   {
1534      dac_data_w (machine.device("dac"), val);
1535   }
1536}
1537
1538MSX_SLOT_INIT(majutsushi)
1539{
1540   if (size != 0x20000)
1541   {
1542      logerror ("majutsushi: error: rom file must be 128kb\n");
1543      return 1;
1544   }
1545   state->m_type = SLOT_MAJUTSUSHI;
1546   state->m_mem = mem;
1547   state->m_size = size;
1548   state->m_bank_mask = 0x0f;
1549
1550   return 0;
1551}
1552
1553MSX_SLOT_RESET(majutsushi)
1554{
1555   int i;
1556
1557   for (i=0; i<4; i++)
1558   {
1559      state->m_banks[i] = i;
1560   }
1561}
1562
1563MSX_SLOT_MAP(majutsushi)
1564{
1565   switch (page)
1566   {
1567   case 0:
1568      msx_cpu_setbank (machine, 1, state->m_mem + state->m_banks[0] * 0x2000);
1569      msx_cpu_setbank (machine, 2, state->m_mem + state->m_banks[1] * 0x2000);
1570      break;
1571   case 1:
1572      msx_cpu_setbank (machine, 3, state->m_mem + state->m_banks[0] * 0x2000);
1573      msx_cpu_setbank (machine, 4, state->m_mem + state->m_banks[1] * 0x2000);
1574      break;
1575   case 2:
1576      msx_cpu_setbank (machine, 5, state->m_mem + state->m_banks[2] * 0x2000);
1577      msx_cpu_setbank (machine, 6, state->m_mem + state->m_banks[3] * 0x2000);
1578      break;
1579   case 3:
1580      msx_cpu_setbank (machine, 7, state->m_mem + state->m_banks[2] * 0x2000);
1581      msx_cpu_setbank (machine, 8, state->m_mem + state->m_banks[3] * 0x2000);
1582      break;
1583   }
1584}
1585
1586MSX_SLOT_WRITE(majutsushi)
1587{
1588   msx_state *drvstate = machine.driver_data<msx_state>();
1589   if (addr >= 0x5000 && addr < 0x6000)
1590   {
1591      dac_data_w (machine.device("dac"), val);
1592   }
1593   else if (addr >= 0x6000 && addr < 0x8000)
1594   {
1595      state->m_banks[1] = val & 0x0f;
1596      slot_majutsushi_map (machine, state, 1);
1597      if (drvstate->m_state[0] == state)
1598      {
1599         slot_konami_map (machine, state, 0);
1600      }
1601   }
1602   else if (addr >= 0x8000 && addr < 0xc000)
1603   {
1604      state->m_banks[addr < 0xa000 ? 2 : 3] = val & 0x0f;
1605      slot_majutsushi_map (machine, state, 2);
1606      if (drvstate->m_state[3] == state)
1607      {
1608         slot_konami_map (machine, state, 3);
1609      }
1610   }
1611}
1612
1613MSX_SLOT_INIT(fmpac)
1614{
1615   static const char sramfile[] = "fmpac.rom";
1616   UINT8 *p;
1617   int banks;
1618
1619   if (size > 0x400000)
1620   {
1621      logerror ("fmpac: warning: truncating rom to 4mb\n");
1622      size = 0x400000;
1623   }
1624   banks = size / 0x4000;
1625   if (size != banks * 0x4000 || (~(banks - 1) % banks))
1626   {
1627      logerror ("fmpac: error: must be a 2 power of 16kb\n");
1628      return 1;
1629   }
1630
1631   if (!strncmp ((char*)mem + 0x18, "PAC2", 4))
1632   {
1633      state->m_cart.fmpac.sram_support = 1;
1634      p = auto_alloc_array(machine, UINT8, 0x4000);
1635      memset (p, 0, 0x2000);
1636      memset (p + 0x2000, 0xff, 0x2000);
1637      state->m_cart.fmpac.mem = p;
1638   }
1639   else
1640   {
1641      state->m_cart.fmpac.sram_support = 0;
1642      state->m_cart.fmpac.mem = NULL;
1643   }
1644
1645   state->m_type = SLOT_FMPAC;
1646   state->m_size = size;
1647   state->m_mem = mem;
1648   state->m_bank_mask = banks - 1;
1649   if (!state->m_sramfile)
1650   {
1651      state->m_sramfile = sramfile;
1652   }
1653
1654   return 0;
1655}
1656
1657MSX_SLOT_RESET(fmpac)
1658{
1659   msx_state *drvstate = machine.driver_data<msx_state>();
1660   int i;
1661
1662   state->m_banks[0] = 0;
1663   state->m_cart.fmpac.sram_active = 0;
1664   state->m_cart.fmpac.opll_active = 0;
1665   drvstate->m_opll_active = 0;
1666   for (i=0; i<=state->m_bank_mask; i++)
1667   {
1668      state->m_mem[0x3ff6 + i * 0x4000] = 0;
1669   }
1670
1671   /* NPW 21-Feb-2004 - Adding check for null */
1672   if (state->m_cart.fmpac.mem)
1673   {
1674      state->m_cart.fmpac.mem[0x3ff6] = 0;
1675      state->m_cart.fmpac.mem[0x3ff7] = 0;
1676   }
1677
1678   /* IMPROVE: reset sound chip */
1679}
1680
1681MSX_SLOT_MAP(fmpac)
1682{
1683   msx_state *drvstate = machine.driver_data<msx_state>();
1684   if (page == 1)
1685   {
1686      if (state->m_cart.fmpac.sram_active)
1687      {
1688         msx_cpu_setbank (machine, 3, state->m_cart.fmpac.mem);
1689         msx_cpu_setbank (machine, 4, state->m_cart.fmpac.mem + 0x2000);
1690      }
1691      else
1692      {
1693         msx_cpu_setbank (machine, 3, state->m_mem + state->m_banks[0] * 0x4000);
1694         msx_cpu_setbank (machine, 4, state->m_mem + state->m_banks[0] * 0x4000 + 0x2000);
1695      }
1696   }
1697   else
1698   {
1699      msx_cpu_setbank (machine, page * 2 + 1, drvstate->m_empty);
1700      msx_cpu_setbank (machine, page * 2 + 2, drvstate->m_empty);
1701   }
1702}
1703
1704MSX_SLOT_WRITE(fmpac)
1705{
1706   msx_state *drvstate = machine.driver_data<msx_state>();
1707   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
1708   int i, data;
1709
1710   if (addr >= 0x4000 && addr < 0x6000 && state->m_cart.fmpac.sram_support)
1711   {
1712      if (state->m_cart.fmpac.sram_active || addr >= 0x5ffe)
1713      {
1714         state->m_cart.fmpac.mem[addr & 0x1fff] = val;
1715      }
1716
1717      state->m_cart.fmpac.sram_active =
1718            (state->m_cart.fmpac.mem[0x1ffe] == 0x4d &&
1719             state->m_cart.fmpac.mem[0x1fff] == 0x69);
1720   }
1721
1722   switch (addr)
1723   {
1724   case 0x7ff4:
1725      if (state->m_cart.fmpac.opll_active)
1726      {
1727         ym2413_w (space->machine().device("ay8910"), 0, val);
1728      }
1729      break;
1730   case 0x7ff5:
1731      if (state->m_cart.fmpac.opll_active)
1732      {
1733         ym2413_w (space->machine().device("ay8910"), 1, val);
1734      }
1735      break;
1736   case 0x7ff6:
1737      data = val & 0x11;
1738      for (i=0; i<=state->m_bank_mask; i++)
1739      {
1740         state->m_mem[0x3ff6 + i * 0x4000] = data;
1741      }
1742      state->m_cart.fmpac.mem[0x3ff6] = data;
1743      state->m_cart.fmpac.opll_active = val & 1;
1744      if ((drvstate->m_opll_active ^ val) & 1)
1745      {
1746         logerror ("FM-PAC: OPLL %sactivated\n", val & 1 ? "" : "de");
1747      }
1748      drvstate->m_opll_active = val & 1;
1749      break;
1750   case 0x7ff7:
1751      state->m_banks[0] = val & state->m_bank_mask;
1752      state->m_cart.fmpac.mem[0x3ff7] = val & state->m_bank_mask;
1753      slot_fmpac_map (machine, state, 1);
1754      break;
1755   }
1756}
1757
1758static const char PAC_HEADER[] = "PAC2 BACKUP DATA";
1759#define PAC_HEADER_LEN (16)
1760
1761MSX_SLOT_LOADSRAM(fmpac)
1762{
1763   char buf[PAC_HEADER_LEN];
1764
1765   if (!state->m_cart.fmpac.sram_support)
1766   {
1767      logerror ("Your fmpac.rom does not support sram\n");
1768      return 1;
1769   }
1770
1771   if (!state->m_sramfile)
1772   {
1773      logerror ("No sram filename provided\n");
1774      return 1;
1775   }
1776   emu_file f(machine.options().memcard_directory(), OPEN_FLAG_READ);
1777   file_error filerr = f.open(state->m_sramfile);
1778   if (filerr == FILERR_NONE)
1779   {
1780      if ((f.read(buf, PAC_HEADER_LEN) == PAC_HEADER_LEN) &&
1781         !strncmp (buf, PAC_HEADER, PAC_HEADER_LEN) &&
1782         f.read(state->m_cart.fmpac.mem, 0x1ffe))
1783      {
1784         logerror ("fmpac: info: sram loaded\n");
1785         return 0;
1786      }
1787      else
1788      {
1789         logerror ("fmpac: warning: failed to load sram\n");
1790         return 1;
1791      }
1792   }
1793
1794   logerror ("fmpac: warning: could not open sram file\n");
1795   return 1;
1796}
1797
1798MSX_SLOT_SAVESRAM(fmpac)
1799{
1800   if (!state->m_cart.fmpac.sram_support || !state->m_sramfile)
1801   {
1802      return 0;
1803   }
1804
1805   emu_file f(machine.options().memcard_directory(), OPEN_FLAG_WRITE);
1806   file_error filerr = f.open(state->m_sramfile);
1807   if (filerr == FILERR_NONE)
1808   {
1809      if ((f.write(PAC_HEADER, PAC_HEADER_LEN) == PAC_HEADER_LEN) &&
1810         (f.write(state->m_cart.fmpac.mem, 0x1ffe) == 0x1ffe))
1811      {
1812         logerror ("fmpac: info: sram saved\n");
1813         return 0;
1814      }
1815      else
1816      {
1817         logerror ("fmpac: warning: sram save to file failed\n");
1818         return 1;
1819      }
1820   }
1821
1822   logerror ("fmpac: warning: could not open sram file for writing\n");
1823
1824   return 1;
1825}
1826
1827MSX_SLOT_INIT(superloadrunner)
1828{
1829   if (size != 0x20000)
1830   {
1831      logerror ("superloadrunner: error: rom file should be exactly "
1832              "128kb\n");
1833      return 1;
1834   }
1835   state->m_type = SLOT_SUPERLOADRUNNER;
1836   state->m_mem = mem;
1837   state->m_size = size;
1838   state->m_start_page = page;
1839   state->m_bank_mask = 7;
1840
1841   return 0;
1842}
1843
1844MSX_SLOT_RESET(superloadrunner)
1845{
1846   msx_state *drvstate = machine.driver_data<msx_state>();
1847   drvstate->m_superloadrunner_bank = 0;
1848}
1849
1850MSX_SLOT_MAP(superloadrunner)
1851{
1852   msx_state *drvstate = machine.driver_data<msx_state>();
1853   if (page == 2)
1854   {
1855      UINT8 *mem = state->m_mem +
1856            (drvstate->m_superloadrunner_bank & state->m_bank_mask) * 0x4000;
1857
1858      msx_cpu_setbank (machine, 5, mem);
1859      msx_cpu_setbank (machine, 6, mem + 0x2000);
1860   }
1861   else
1862   {
1863      msx_cpu_setbank (machine, page * 2 + 1, drvstate->m_empty);
1864      msx_cpu_setbank (machine, page * 2 + 2, drvstate->m_empty);
1865   }
1866}
1867
1868MSX_SLOT_INIT(crossblaim)
1869{
1870   if (size != 0x10000)
1871   {
1872      logerror ("crossblaim: error: rom file should be exactly 64kb\n");
1873      return 1;
1874   }
1875   state->m_type = SLOT_CROSS_BLAIM;
1876   state->m_mem = mem;
1877   state->m_size = size;
1878
1879   return 0;
1880}
1881
1882MSX_SLOT_RESET(crossblaim)
1883{
1884   state->m_banks[0] = 1;
1885}
1886
1887MSX_SLOT_MAP(crossblaim)
1888{
1889   msx_state *drvstate = machine.driver_data<msx_state>();
1890   UINT8 *mem;
1891
1892   /* This might look odd, but it's what happens on the real cartridge */
1893
1894   switch (page)
1895   {
1896   case 0:
1897      if (state->m_banks[0] < 2){
1898         mem = state->m_mem + state->m_banks[0] * 0x4000;
1899         msx_cpu_setbank (machine, 1, mem);
1900         msx_cpu_setbank (machine, 2, mem + 0x2000);
1901      }
1902      else
1903      {
1904         msx_cpu_setbank (machine, 1, drvstate->m_empty);
1905         msx_cpu_setbank (machine, 2, drvstate->m_empty);
1906      }
1907      break;
1908   case 1:
1909      msx_cpu_setbank (machine, 3, state->m_mem);
1910      msx_cpu_setbank (machine, 4, state->m_mem + 0x2000);
1911      break;
1912   case 2:
1913      mem = state->m_mem + state->m_banks[0] * 0x4000;
1914      msx_cpu_setbank (machine, 5, mem);
1915      msx_cpu_setbank (machine, 6, mem + 0x2000);
1916      break;
1917   case 3:
1918      if (state->m_banks[0] < 2){
1919         mem = state->m_mem + state->m_banks[0] * 0x4000;
1920         msx_cpu_setbank (machine, 7, mem);
1921         msx_cpu_setbank (machine, 8, mem + 0x2000);
1922      }
1923      else
1924      {
1925         msx_cpu_setbank (machine, 7, drvstate->m_empty);
1926         msx_cpu_setbank (machine, 8, drvstate->m_empty);
1927      }
1928   }
1929}
1930
1931MSX_SLOT_WRITE(crossblaim)
1932{
1933   msx_state *drvstate = machine.driver_data<msx_state>();
1934   UINT8 block = val & 3;
1935
1936   if (!block) block = 1;
1937   state->m_banks[0] = block;
1938
1939   if (drvstate->m_state[0] == state)
1940   {
1941      slot_crossblaim_map (machine, state, 0);
1942   }
1943   if (drvstate->m_state[2] == state)
1944   {
1945      slot_crossblaim_map (machine, state, 2);
1946   }
1947   if (drvstate->m_state[3] == state)
1948   {
1949      slot_crossblaim_map (machine, state, 3);
1950   }
1951}
1952
1953MSX_SLOT_INIT(korean80in1)
1954{
1955   int banks;
1956
1957   if (size > 0x200000)
1958   {
1959      logerror ("korean-80in1: warning: truncating to 2mb\n");
1960      size = 0x200000;
1961   }
1962   banks = size / 0x2000;
1963   if (size != banks * 0x2000 || (~(banks - 1) % banks))
1964   {
1965      logerror ("korean-80in1: error: must be a 2 power of 8kb\n");
1966      return 1;
1967   }
1968   state->m_type = SLOT_KOREAN_80IN1;
1969   state->m_mem = mem;
1970   state->m_size = size;
1971   state->m_bank_mask = banks - 1;
1972
1973   return 0;
1974}
1975
1976MSX_SLOT_RESET(korean80in1)
1977{
1978   int i;
1979
1980   for (i=0; i<4; i++)
1981   {
1982      state->m_banks[i] = i;
1983   }
1984}
1985
1986MSX_SLOT_MAP(korean80in1)
1987{
1988   msx_state *drvstate = machine.driver_data<msx_state>();
1989   switch (page)
1990   {
1991   case 0:
1992      msx_cpu_setbank (machine, 1, drvstate->m_empty);
1993      msx_cpu_setbank (machine, 2, drvstate->m_empty);
1994      break;
1995   case 1:
1996      msx_cpu_setbank (machine, 3, state->m_mem + state->m_banks[0] * 0x2000);
1997      msx_cpu_setbank (machine, 4, state->m_mem + state->m_banks[1] * 0x2000);
1998      break;
1999   case 2:
2000      msx_cpu_setbank (machine, 5, state->m_mem + state->m_banks[2] * 0x2000);
2001      msx_cpu_setbank (machine, 6, state->m_mem + state->m_banks[3] * 0x2000);
2002      break;
2003   case 3:
2004      msx_cpu_setbank (machine, 7, drvstate->m_empty);
2005      msx_cpu_setbank (machine, 8, drvstate->m_empty);
2006   }
2007}
2008
2009MSX_SLOT_WRITE(korean80in1)
2010{
2011   msx_state *drvstate = machine.driver_data<msx_state>();
2012   int bank;
2013
2014   if (addr >= 0x4000 && addr < 0x4004)
2015   {
2016      bank = addr & 3;
2017
2018      state->m_banks[bank] = val & state->m_bank_mask;
2019      if (bank <= 1)
2020      {
2021         slot_korean80in1_map (machine, state, 1);
2022      }
2023      else if (drvstate->m_state[2] == state)
2024      {
2025         slot_korean80in1_map (machine, state, 2);
2026      }
2027   }
2028}
2029
2030MSX_SLOT_INIT(korean90in1)
2031{
2032   int banks;
2033
2034   if (size > 0x100000)
2035   {
2036      logerror ("korean-90in1: warning: truncating to 1mb\n");
2037      size = 0x100000;
2038   }
2039   banks = size / 0x4000;
2040   if (size != banks * 0x4000 || (~(banks - 1) % banks))
2041   {
2042      logerror ("korean-90in1: error: must be a 2 power of 16kb\n");
2043      return 1;
2044   }
2045   state->m_type = SLOT_KOREAN_90IN1;
2046   state->m_mem = mem;
2047   state->m_size = size;
2048   state->m_bank_mask = banks - 1;
2049
2050   return 0;
2051}
2052
2053MSX_SLOT_RESET(korean90in1)
2054{
2055   msx_state *drvstate = machine.driver_data<msx_state>();
2056   drvstate->m_korean90in1_bank = 0;
2057}
2058
2059MSX_SLOT_MAP(korean90in1)
2060{
2061   msx_state *drvstate = machine.driver_data<msx_state>();
2062   UINT8 *mem;
2063   UINT8 mask = (drvstate->m_korean90in1_bank & 0xc0) == 0x80 ? 0x3e : 0x3f;
2064   mem = state->m_mem +
2065      ((drvstate->m_korean90in1_bank & mask) & state->m_bank_mask) * 0x4000;
2066
2067   switch (page)
2068   {
2069   case 0:
2070      msx_cpu_setbank (machine, 1, drvstate->m_empty);
2071      msx_cpu_setbank (machine, 2, drvstate->m_empty);
2072      break;
2073   case 1:
2074      msx_cpu_setbank (machine, 3, mem);
2075      msx_cpu_setbank (machine, 4, mem + 0x2000);
2076      break;
2077   case 2:
2078      switch (drvstate->m_korean90in1_bank & 0xc0)
2079      {
2080      case 0x80: /* 32 kb mode */
2081         mem += 0x4000;
2082      default: /* ie. 0x00 and 0x40: same memory as page 1 */
2083         msx_cpu_setbank (machine, 5, mem);
2084         msx_cpu_setbank (machine, 6, mem + 0x2000);
2085         break;
2086      case 0xc0: /* same memory as page 1, but swap lower/upper 8kb */
2087         msx_cpu_setbank (machine, 5, mem + 0x2000);
2088         msx_cpu_setbank (machine, 6, mem);
2089         break;
2090      }
2091      break;
2092   case 3:
2093      msx_cpu_setbank (machine, 7, drvstate->m_empty);
2094      msx_cpu_setbank (machine, 8, drvstate->m_empty);
2095   }
2096}
2097
2098MSX_SLOT_INIT(korean126in1)
2099{
2100   int banks;
2101
2102   if (size > 0x400000)
2103   {
2104      logerror ("korean-126in1: warning: truncating to 4mb\n");
2105      size = 0x400000;
2106   }
2107   banks = size / 0x4000;
2108   if (size != banks * 0x4000 || (~(banks - 1) % banks))
2109   {
2110      logerror ("korean-126in1: error: must be a 2 power of 16kb\n");
2111      return 1;
2112   }
2113
2114   state->m_type = SLOT_KOREAN_126IN1;
2115   state->m_mem = mem;
2116   state->m_size = size;
2117   state->m_bank_mask = banks - 1;
2118
2119   return 0;
2120}
2121
2122MSX_SLOT_RESET(korean126in1)
2123{
2124   int i;
2125
2126   for (i=0; i<2; i++) state->m_banks[i] = i;
2127}
2128
2129MSX_SLOT_MAP(korean126in1)
2130{
2131   msx_state *drvstate = machine.driver_data<msx_state>();
2132   UINT8 *mem;
2133
2134   switch (page)
2135   {
2136   case 0:
2137      msx_cpu_setbank (machine, 1, drvstate->m_empty);
2138      msx_cpu_setbank (machine, 2, drvstate->m_empty);
2139      break;
2140   case 1:
2141      mem = state->m_mem + state->m_banks[0] * 0x4000;
2142      msx_cpu_setbank (machine, 3, mem);
2143      msx_cpu_setbank (machine, 4, mem + 0x2000);
2144      break;
2145   case 2:
2146      mem = state->m_mem + state->m_banks[1] * 0x4000;
2147      msx_cpu_setbank (machine, 5, mem);
2148      msx_cpu_setbank (machine, 6, mem + 0x2000);
2149      break;
2150   case 3:
2151      msx_cpu_setbank (machine, 7, drvstate->m_empty);
2152      msx_cpu_setbank (machine, 8, drvstate->m_empty);
2153   }
2154}
2155
2156MSX_SLOT_WRITE(korean126in1)
2157{
2158   msx_state *drvstate = machine.driver_data<msx_state>();
2159   if (addr >= 0x4000 && addr < 0x4002)
2160   {
2161      int bank = addr & 1;
2162      state->m_banks[bank] = val & state->m_bank_mask;
2163      if (bank == 0)
2164      {
2165         slot_korean126in1_map (machine, state, 1);
2166      }
2167      else if (drvstate->m_state[2] == state)
2168      {
2169         slot_korean126in1_map (machine, state, 2);
2170      }
2171   }
2172}
2173
2174MSX_SLOT_INIT(soundcartridge)
2175{
2176   UINT8 *p;
2177
2178   p = auto_alloc_array(machine, UINT8, 0x20000);
2179   memset (p, 0, 0x20000);
2180
2181   state->m_mem = p;
2182   state->m_size = 0x20000;
2183   state->m_bank_mask = 15;
2184   state->m_type = SLOT_SOUNDCARTRIDGE;
2185
2186   return 0;
2187}
2188
2189MSX_SLOT_RESET(soundcartridge)
2190{
2191   int i;
2192
2193   for (i=0; i<4; i++)
2194   {
2195      state->m_banks[i] = i;
2196      state->m_cart.sccp.ram_mode[i] = 0;
2197      state->m_cart.sccp.banks_saved[i] = i;
2198   }
2199   state->m_cart.sccp.mode = 0;
2200   state->m_cart.sccp.scc_active = 0;
2201   state->m_cart.sccp.sccp_active = 0;
2202}
2203
2204static  READ8_HANDLER (soundcartridge_scc)
2205{
2206   msx_state *state = space->machine().driver_data<msx_state>();
2207   int reg;
2208
2209
2210   if (offset >= 0x7e0)
2211   {
2212      return state->m_state[2]->m_mem[
2213            state->m_state[2]->m_banks[2] * 0x2000 + 0x1800 + offset];
2214   }
2215
2216   reg = offset & 0xff;
2217
2218   if (reg < 0x80)
2219   {
2220      return k051649_waveform_r (space->machine().device("k051649"), reg);
2221   }
2222   else if (reg < 0xa0)
2223   {
2224      /* nothing */
2225   }
2226   else if (reg < 0xc0)
2227   {
2228      /* read wave 5 */
2229      return k051649_waveform_r (space->machine().device("k051649"), 0x80 + (reg & 0x1f));
2230   }
2231#if 0
2232   else if (reg < 0xe0)
2233   {
2234      /* write 0xff to deformation register */
2235   }
2236#endif
2237
2238   return 0xff;
2239}
2240
2241static  READ8_HANDLER (soundcartridge_sccp)
2242{
2243   msx_state *state = space->machine().driver_data<msx_state>();
2244   int reg;
2245
2246   if (offset >= 0x7e0)
2247   {
2248      return state->m_state[2]->m_mem[
2249            state->m_state[2]->m_banks[3] * 0x2000 + 0x1800 + offset];
2250   }
2251
2252   reg = offset & 0xff;
2253
2254   if (reg < 0xa0)
2255   {
2256      return k051649_waveform_r (space->machine().device("k051649"), reg);
2257   }
2258#if 0
2259   else if (reg >= 0xc0 && reg < 0xe0)
2260   {
2261      /* write 0xff to deformation register */
2262   }
2263#endif
2264
2265   return 0xff;
2266}
2267
2268MSX_SLOT_MAP(soundcartridge)
2269{
2270   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
2271   switch (page)
2272   {
2273   case 0:
2274      msx_cpu_setbank (machine, 1, state->m_mem + state->m_banks[2] * 0x2000);
2275      msx_cpu_setbank (machine, 2, state->m_mem + state->m_banks[3] * 0x2000);
2276      break;
2277   case 1:
2278      msx_cpu_setbank (machine, 3, state->m_mem + state->m_banks[0] * 0x2000);
2279      msx_cpu_setbank (machine, 4, state->m_mem + state->m_banks[1] * 0x2000);
2280      break;
2281   case 2:
2282      msx_cpu_setbank (machine, 5, state->m_mem + state->m_banks[2] * 0x2000);
2283      msx_cpu_setbank (machine, 6, state->m_mem + state->m_banks[3] * 0x2000);
2284      if (state->m_cart.sccp.scc_active) {
2285         space->install_legacy_read_handler(0x9800, 0x9fff, FUNC(soundcartridge_scc));
2286      } else {
2287         space->install_read_bank(0x9800, 0x9fff, "bank7");
2288      }
2289      if (state->m_cart.sccp.scc_active) {
2290         space->install_legacy_read_handler(0xb800, 0xbfff, FUNC(soundcartridge_sccp));
2291      } else {
2292         space->install_read_bank(0xb800, 0xbfff, "bank9");
2293      }
2294      break;
2295   case 3:
2296      msx_cpu_setbank (machine, 7, state->m_mem + state->m_banks[0] * 0x2000);
2297      msx_cpu_setbank (machine, 8, state->m_mem + state->m_banks[1] * 0x2000);
2298      break;
2299   }
2300}
2301
2302MSX_SLOT_WRITE(soundcartridge)
2303{
2304   msx_state *drvstate = machine.driver_data<msx_state>();
2305   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
2306   int i;
2307
2308   if (addr < 0x4000)
2309   {
2310      return;
2311   }
2312   else if (addr < 0x6000)
2313   {
2314      if (state->m_cart.sccp.ram_mode[0])
2315      {
2316         state->m_mem[state->m_banks[0] * 0x2000 + (addr & 0x1fff)] = val;
2317      }
2318      else if (addr >= 0x5000 && addr < 0x5800)
2319      {
2320         state->m_banks[0] = val & state->m_bank_mask;
2321         state->m_cart.sccp.banks_saved[0] = val;
2322         slot_soundcartridge_map (machine, state, 1);
2323         if (drvstate->m_state[3] == state)
2324         {
2325            slot_soundcartridge_map (machine, state, 3);
2326         }
2327      }
2328   }
2329   else if (addr < 0x8000)
2330   {
2331      if (state->m_cart.sccp.ram_mode[1])
2332      {
2333         state->m_mem[state->m_banks[1] * 0x2000 + (addr & 0x1fff)] = val;
2334      }
2335      else if (addr >= 0x7000 && addr < 0x7800)
2336      {
2337         state->m_banks[1] = val & state->m_bank_mask;
2338         state->m_cart.sccp.banks_saved[1] = val;
2339         if (drvstate->m_state[3] == state)
2340         {
2341            slot_soundcartridge_map (machine, state, 3);
2342         }
2343         slot_soundcartridge_map (machine, state, 1);
2344      }
2345   }
2346   else if (addr < 0xa000)
2347   {
2348      if (state->m_cart.sccp.ram_mode[2])
2349      {
2350         state->m_mem[state->m_banks[2] * 0x2000 + (addr & 0x1fff)] = val;
2351      }
2352      else if (addr >= 0x9000 && addr < 0x9800)
2353      {
2354         state->m_banks[2] = val & state->m_bank_mask;
2355         state->m_cart.sccp.banks_saved[2] = val;
2356         state->m_cart.sccp.scc_active =
2357               (((val & 0x3f) == 0x3f) && !(state->m_cart.sccp.mode & 0x20));
2358
2359         slot_soundcartridge_map (machine, state, 2);
2360         if (drvstate->m_state[0] == state)
2361         {
2362            slot_soundcartridge_map (machine, state, 0);
2363         }
2364      }
2365      else if (addr >= 0x9800 && state->m_cart.sccp.scc_active)
2366      {
2367         device_t *k051649 = space->machine().device("k051649");
2368         int offset = addr & 0xff;
2369
2370         if (offset < 0x80)
2371         {
2372            k051649_waveform_w (k051649, offset, val);
2373         }
2374         else if (offset < 0xa0)
2375         {
2376            offset &= 0xf;
2377
2378            if (offset < 0xa)
2379            {
2380               k051649_frequency_w (k051649, offset, val);
2381            }
2382            else if (offset < 0x0f)
2383            {
2384               k051649_volume_w (k051649, offset - 0xa, val);
2385            }
2386            else if (offset == 0x0f)
2387            {
2388               k051649_keyonoff_w (k051649, 0, val);
2389            }
2390         }
2391#if 0
2392         else if (offset < 0xe0)
2393         {
2394            /* write to deformation register */
2395         }
2396#endif
2397      }
2398   }
2399   else if (addr < 0xbffe)
2400   {
2401      if (state->m_cart.sccp.ram_mode[3])
2402      {
2403         state->m_mem[state->m_banks[3] * 0x2000 + (addr & 0x1fff)] = val;
2404      }
2405      else if (addr >= 0xb000 && addr < 0xb800)
2406      {
2407         state->m_cart.sccp.banks_saved[3] = val;
2408         state->m_banks[3] = val & state->m_bank_mask;
2409         state->m_cart.sccp.sccp_active =
2410               (val & 0x80) && (state->m_cart.sccp.mode & 0x20);
2411         slot_soundcartridge_map (machine, state, 2);
2412         if (drvstate->m_state[0] == state)
2413         {
2414            slot_soundcartridge_map (machine, state, 0);
2415         }
2416      }
2417      else if (addr >= 0xb800 && state->m_cart.sccp.sccp_active)
2418      {
2419         device_t *k051649 = space->machine().device("k051649");
2420         int offset = addr & 0xff;
2421
2422         if (offset < 0xa0)
2423         {
2424            k052539_waveform_w (k051649, offset, val);
2425         }
2426         else if (offset < 0xc0)
2427         {
2428            offset &= 0x0f;
2429
2430            if (offset < 0x0a)
2431            {
2432               k051649_frequency_w (k051649, offset, val);
2433            }
2434            else if (offset < 0x0f)
2435            {
2436               k051649_volume_w (k051649, offset - 0x0a, val);
2437            }
2438            else if (offset == 0x0f)
2439            {
2440               k051649_keyonoff_w (k051649, 0, val);
2441            }
2442         }
2443#if 0
2444         else if (offset < 0xe0)
2445         {
2446            /* write to deformation register */
2447         }
2448#endif
2449      }
2450   }
2451   else if (addr < 0xc000)
2452   {
2453      /* write to mode register */
2454      if ((state->m_cart.sccp.mode ^ val) & 0x20)
2455      {
2456         logerror ("soundcartrige: changed to %s mode\n",
2457                     val & 0x20 ? "scc+" : "scc");
2458      }
2459      state->m_cart.sccp.mode = val;
2460      if (val & 0x10)
2461      {
2462         /* all ram mode */
2463         for (i=0; i<4; i++)
2464         {
2465            state->m_cart.sccp.ram_mode[i] = 1;
2466         }
2467      }
2468      else
2469      {
2470         state->m_cart.sccp.ram_mode[0] = val & 1;
2471         state->m_cart.sccp.ram_mode[1] = val & 2;
2472         state->m_cart.sccp.ram_mode[2] = (val & 4) && (val & 0x20);
2473         state->m_cart.sccp.ram_mode[3] = 0;
2474
2475      }
2476
2477      state->m_cart.sccp.scc_active =
2478         (((state->m_cart.sccp.banks_saved[2] & 0x3f) == 0x3f) &&
2479         !(val & 0x20));
2480
2481      state->m_cart.sccp.sccp_active =
2482            ((state->m_cart.sccp.banks_saved[3] & 0x80) && (val & 0x20));
2483
2484      slot_soundcartridge_map (machine, state, 2);
2485   }
2486}
2487
2488MSX_SLOT_START
2489   MSX_SLOT_ROM (SLOT_EMPTY, empty)
2490   MSX_SLOT (SLOT_MSXDOS2, msxdos2)
2491   MSX_SLOT (SLOT_KONAMI_SCC, konami_scc)
2492   MSX_SLOT (SLOT_KONAMI, konami)
2493   MSX_SLOT (SLOT_ASCII8, ascii8)
2494   MSX_SLOT (SLOT_ASCII16, ascii16)
2495   MSX_SLOT_SRAM (SLOT_GAMEMASTER2, gmaster2)
2496   MSX_SLOT_SRAM (SLOT_ASCII8_SRAM, ascii8_sram)
2497   MSX_SLOT_SRAM (SLOT_ASCII16_SRAM, ascii16_sram)
2498   MSX_SLOT (SLOT_RTYPE, rtype)
2499   MSX_SLOT (SLOT_MAJUTSUSHI, majutsushi)
2500   MSX_SLOT_SRAM (SLOT_FMPAC, fmpac)
2501   MSX_SLOT_ROM (SLOT_SUPERLOADRUNNER, superloadrunner)
2502   MSX_SLOT (SLOT_SYNTHESIZER, synthesizer)
2503   MSX_SLOT (SLOT_CROSS_BLAIM, crossblaim)
2504   MSX_SLOT (SLOT_DISK_ROM, diskrom)
2505   MSX_SLOT (SLOT_KOREAN_80IN1, korean80in1)
2506   MSX_SLOT (SLOT_KOREAN_126IN1, korean126in1)
2507   MSX_SLOT_ROM (SLOT_KOREAN_90IN1, korean90in1)
2508   MSX_SLOT (SLOT_SOUNDCARTRIDGE, soundcartridge)
2509   MSX_SLOT_ROM (SLOT_ROM, rom)
2510   MSX_SLOT_RAM (SLOT_RAM, ram)
2511   MSX_SLOT_RAM (SLOT_RAM_MM, rammm)
2512   MSX_SLOT_NULL (SLOT_CARTRIDGE1)
2513   MSX_SLOT_NULL (SLOT_CARTRIDGE2)
2514   MSX_SLOT (SLOT_DISK_ROM2, diskrom2)
2515MSX_SLOT_END
2516
src/mame/machine/psxcd.c
r0r11461
1#include "emu.h"
2#include "includes/psx.h"
3#include "psxcd.h"
4#include "machine/devhelpr.h"
5#include "sound/spu.h"
6#include "debugger.h"
7
8//
9//
10//
11
12//#define debug_cdrom
13//#define debug_cdrom_registers
14//#define skip_reads
15//#define dump_subheader
16//#define disable_xa_prefetch
17//#define disable_cdda_prefetch
18
19//
20//
21//
22
23enum cdrom_events
24{
25   event_cmd_complete=0,
26   event_preread_sector,
27   event_read_sector,
28   event_play_sector
29};
30
31//
32//
33//
34
35enum intr_status
36{
37   intr_nointr=0,
38   intr_dataready,
39   intr_acknowledge,
40   intr_complete,
41   intr_dataend,
42   intr_diskerror
43};
44
45enum mode_flags
46{
47   mode_double_speed=0x80,
48   mode_adpcm=0x40,
49   mode_size=0x20,
50   mode_size2=0x10,
51   mode_size_shift=4,
52   mode_size_mask=(3<<mode_size_shift),
53   mode_channel=0x08,
54   mode_report=0x04,
55   mode_autopause=0x02,
56   mode_cdda=0x01
57};
58
59enum status_f
60{
61   status_playing=0x80,
62   status_seeking=0x40,
63   status_reading=0x20,
64   status_shellopen=0x10,
65   status_seekerror=0x04,
66   status_standby=0x02,
67   status_error=0x01
68};
69
70struct subheader
71{
72   unsigned char file,
73                        channel,
74                        submode,
75                        coding;
76};
77
78enum submode_flags
79{
80   submode_eof=0x80,
81   submode_realtime=0x40,
82   submode_form=0x20,
83   submode_trigger=0x10,
84   submode_data=0x08,
85   submode_audio=0x04,
86   submode_video=0x02,
87   submode_eor=0x01
88};
89
90//
91//
92//
93
94static const unsigned int max_xa_prefetch_distance=32,
95                                       max_cdda_prefetch_distance=32;
96
97//**************************************************************************
98//  DEVICE DEFINITIONS
99//**************************************************************************
100
101const device_type PSXCD = &device_creator<psxcd_device>;
102
103void psxcd_device::static_set_devname(device_t &device, const char *devname)
104{
105   psxcd_device &psxcd = downcast<psxcd_device &>(device);
106   psxcd.m_devname = devname;
107}
108
109psxcd_device::psxcd_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
110   : device_t(mconfig, PSXCD, "PSXCD", tag, owner, clock)
111{
112}
113
114void psxcd_device::device_start()
115{
116   unsigned int sysclk=machine().device<cpu_device>("maincpu")->clock()/2;
117   start_read_delay=(sysclk/60);
118   read_sector_cycles=(sysclk/75);
119   preread_delay=(read_sector_cycles>>2)-500;
120
121   m_sysclock = sysclk;
122
123   secleft = 0;
124   secsize = 2048;
125   res_queue = NULL;
126   cur_res = NULL;
127   open = false;
128   streaming = false;
129   sechead = 0;
130   sectail = 0;
131   secin = 0;
132   secskip = 0;
133   next_read_event = NULL;
134   cbp = cmdbuf;
135   first_open = true;
136
137   status=status_standby;
138   sr=8|1;
139   res=0;
140   ir=0;
141   mode=0;
142
143   driver = NULL;
144
145   for (int i = 0; i < MAX_PSXCD_TIMERS; i++)
146   {
147      m_timers[i] = timer_alloc(i, NULL);
148      m_timerinuse[i] = false;
149   }
150}
151
152//
153//
154//
155
156void psxcd_device::device_reset()
157{
158   stop_read();
159   open=false;
160
161   for (int i = 0; i < MAX_PSXCD_TIMERS; i++)
162   {
163      m_timerinuse[i] = false;
164   }
165
166   m_cddevice = machine().device(m_devname);
167   if (m_cddevice)
168   {
169      m_cd = cd_get_cdrom_file(m_cddevice);
170
171      if (m_cd)
172      {
173//          printf("psxcd: found disc!\n");
174         driver = open_mess_drv();
175         driver->set_machine(machine());
176         driver->set_cdrom_file(m_cd);
177      }
178      else
179      {
180         driver = NULL;
181//          printf("psxcd: Found device, but no disc\n");
182      }
183   }
184   else
185   {
186      driver = NULL;
187//      printf("psxcd: Device [%s] not found!\n", m_devname);
188   }
189
190}
191
192//
193//
194//
195
196unsigned char psxcd_device::read_byte(const unsigned int addr)
197{
198   unsigned char ret = 0;
199
200   switch (addr&3)
201   {
202      case 0: ret=sr; break;
203      case 1:
204         ret=res;
205         if ((cur_res) && (rdp<cur_res->sz))
206         {
207            res=cur_res->data[rdp++];
208            sr|=(1<<5);
209         } else
210         {
211            if ((cur_res) && (cur_res->res&0x10))
212            {
213               global_free(cur_res);
214               cur_res=NULL;
215            }
216
217            sr&=~(1<<5);
218         }
219         break;
220      case 2: ret=0; break;
221      case 3: ret=ir; break;
222   }
223
224   #ifdef debug_cdrom_registers
225      printf("cdrom: read byte %08x = %02x (PC=%x)\n",addr,ret,cpu_get_pc(machine().device("maincpu")));
226   #endif
227
228   return ret;
229}
230
231//
232//
233//
234
235void psxcd_device::write_byte(const unsigned int addr, const unsigned char byte)
236{
237   #ifdef debug_cdrom_registers
238      printf("cdrom: write byte %08x = %02x (PC=%x)\n",addr,byte,cpu_get_pc(machine().device("maincpu")));
239   #endif
240
241   switch (addr&3)
242   {
243      case 0:
244         cmdmode=byte&1;
245         if (cmdmode==0)
246         {
247            cbp=cmdbuf;
248         } else
249         {
250            if (! cur_res)
251            {
252               if (cur_res) global_free(cur_res);
253
254               if (res_queue)
255               {
256                  #ifdef debug_cdrom_registers
257                     printf("cdrom: nextres\n");
258                  #endif
259
260                  cur_res=res_queue;
261                  res_queue=res_queue->next;
262                  ir=cur_res->res&0xf;
263                  rdp=0;
264
265                  if (cur_res->sz)
266                  {
267                     res=cur_res->data[rdp++];
268                     sr|=(1<<5);
269                  } else
270                  {
271                     sr&=~(1<<5);
272                  }
273               } else
274               {
275                  //ir=0;
276                  cur_res=NULL;
277               }
278            }
279            /*else
280                {
281                    if (rdp>=cur_res->sz)
282                    {
283                        sr&=~(1<<5);
284                    } else
285                    {
286                        sr|=~(1<<5);
287                        res=cur_res->data[rdp++];
288                    }
289                }
290                */
291         }
292         break;
293
294      case 1:
295         if (cmdmode==0)
296         {
297            write_command(byte);
298         }
299         break;
300
301      case 2:
302         if (cmdmode==0)
303         {
304            *cbp++=byte;
305         } else
306         {
307            // ?flush buffer?
308         }
309         break;
310
311      case 3:
312         if (byte==0x07)
313         {
314            if (cur_res)
315            {
316               global_free(cur_res);
317               cur_res=NULL;
318               sr&=~(1<<5);
319            }
320            ir=0;
321         }
322         break;
323   }
324}
325
326psxcd_device::command_info psxcd_device::cmd_table[num_commands]=
327{
328   { &psxcd_device::cdcmd_sync,            "sync"         },   // 00
329   { &psxcd_device::cdcmd_nop,            "nop"            },   // 01
330   { &psxcd_device::cdcmd_setloc,         "setloc"      },   // 02
331   { &psxcd_device::cdcmd_play,            "play"         },   // 03
332   { &psxcd_device::cdcmd_forward,      "forward"      },   // 04
333   { &psxcd_device::cdcmd_backward,      "backward"   },   // 05
334   { &psxcd_device::cdcmd_readn,         "readn"         },   // 06
335   { &psxcd_device::cdcmd_standby,      "standby"      },   // 07
336   { &psxcd_device::cdcmd_stop,            "stop"         },   // 08
337   { &psxcd_device::cdcmd_pause,         "pause"         },   // 09
338   { &psxcd_device::cdcmd_init,            "init"         },   // 0a
339   { &psxcd_device::cdcmd_mute,            "mute"         },   // 0b
340   { &psxcd_device::cdcmd_demute,         "demute"      },   // 0c
341   { &psxcd_device::cdcmd_setfilter,   "setfilter"   },   // 0d
342   { &psxcd_device::cdcmd_setmode,      "setmode"      },   // 0e
343   { &psxcd_device::cdcmd_getparam,      "getparam"   },   // 0f
344   { &psxcd_device::cdcmd_getlocl,      "getlocl"      },   // 10
345   { &psxcd_device::cdcmd_getlocp,      "getlocp"      },   // 11
346   { &psxcd_device::cdcmd_illegal,      "illegal"      },   // 12
347   { &psxcd_device::cdcmd_gettn,         "gettn"         },   // 13
348   { &psxcd_device::cdcmd_gettd,         "gettd"         },   // 14
349   { &psxcd_device::cdcmd_seekl,         "seekl"         },   // 15
350   { &psxcd_device::cdcmd_seekp,         "seekp"         },   // 16
351   { &psxcd_device::cdcmd_illegal,      "illegal"      },   // 17
352   { &psxcd_device::cdcmd_illegal,      "illegal"      },   // 18
353   { &psxcd_device::cdcmd_test,            "test"         },   // 19
354   { &psxcd_device::cdcmd_id,               "id"            },   // 1a
355   { &psxcd_device::cdcmd_reads,         "reads"         },   // 1b
356   { &psxcd_device::cdcmd_reset,         "reset"         },   // 1c
357   { &psxcd_device::cdcmd_illegal,      "illegal"      },   // 1d
358   { &psxcd_device::cdcmd_readtoc,      "readtoc"      },   // 1e
359};
360
361//
362//
363//
364
365void psxcd_device::write_command(const unsigned char byte)
366{
367   assert(byte<num_commands);
368   (this->*cmd_table[byte].func)();
369}
370
371//
372//
373//
374
375void psxcd_device::cdcmd_sync()
376{
377   #ifdef debug_cdrom
378      printf("cdrom: sync\n");
379   #endif
380
381   stop_read();
382   send_result(intr_acknowledge);
383}
384
385static int open_nops=0;
386
387void psxcd_device::cdcmd_nop()
388{
389   #ifdef debug_cdrom
390      printf("cdrom: nop\n");
391   #endif
392
393   //stop_read();
394
395   if ((! open) && (driver))
396   {
397      if (open_nops==0)
398      {
399         open=driver->read_toc();
400      } else
401      {
402         open_nops--;
403      }
404   }
405
406   send_result(intr_complete);
407}
408
409void psxcd_device::cdcmd_setloc()
410{
411   #ifdef debug_cdrom
412      printf("cdrom: setloc %08x:%08x:%08x\n",
413            cmdbuf[0],
414            cmdbuf[1],
415            cmdbuf[2]);
416   #endif
417
418   stop_read();
419
420   unsigned char l[3];
421   l[0]=bcd_to_decimal(cmdbuf[0]);
422   l[1]=bcd_to_decimal(cmdbuf[1]);
423   l[2]=bcd_to_decimal(cmdbuf[2]);
424
425   if ((l[0]>0) || (l[1]>=2))
426   {
427      loc[0]=l[0];
428      loc[1]=l[1];
429      loc[2]=l[2];
430   } else
431   {
432      printf("setloc out of range: %02d:%02d:%02d\n",
433                l[0],l[1],l[2]);
434   }
435
436   send_result(intr_complete);
437}
438
439void psxcd_device::cdcmd_play()
440{
441   #ifdef debug_cdrom
442      printf("cdrom: play %02x %02x %02x => %d\n", loc[0], loc[1], loc[2], msf_to_sector(loc));
443   #endif
444
445   curpos[0]=loc[0];
446   curpos[1]=loc[1];
447   curpos[2]=loc[2];
448
449   if ((curpos[0]==0) &&
450         (curpos[1]==0) &&
451         (curpos[2]==0))
452   {
453      send_result(intr_acknowledge);
454   } else
455   {
456      stop_read();
457      start_play();
458      send_result(intr_acknowledge);
459   }
460}
461
462void psxcd_device::cdcmd_forward()
463{
464   #ifdef debug_cdrom
465      printf("cdrom: forward\n");
466   #endif
467}
468
469void psxcd_device::cdcmd_backward()
470{
471   #ifdef debug_cdrom
472      printf("cdrom: backward\n");
473   #endif
474}
475
476void psxcd_device::cdcmd_readn()
477{
478   if (driver)
479   {
480      #ifdef debug_cdrom
481         printf("cdrom: readn\n");
482      #endif
483
484      curpos[0]=loc[0];
485      curpos[1]=loc[1];
486      curpos[2]=loc[2];
487
488      stop_read();
489      start_read();
490      send_result(intr_complete);
491   } else
492   {
493      printf("read without driver\n");
494      send_result(intr_diskerror);
495   }
496}
497
498void psxcd_device::cdcmd_standby()
499{
500   #ifdef debug_cdrom
501      printf("cdrom: standby\n");
502   #endif
503
504   stop_read();
505   send_result(intr_acknowledge);
506}
507
508void psxcd_device::cdcmd_stop()
509{
510   #ifdef debug_cdrom
511      printf("cdrom: stop\n");
512   #endif
513
514   stop_read();
515   send_result(intr_acknowledge);
516}
517
518void psxcd_device::cdcmd_pause()
519{
520   #ifdef debug_cdrom
521      printf("cdrom: pause\n");
522   #endif
523
524   stop_read();
525
526   send_result(intr_acknowledge);
527}
528
529void psxcd_device::cdcmd_init()
530{
531   #ifdef debug_cdrom
532      printf("cdrom: init\n");
533   #endif
534
535   stop_read();
536   mode=0;
537   sr|=0x10;
538
539   send_result(intr_acknowledge);
540}
541
542void psxcd_device::cdcmd_mute()
543{
544   #ifdef debug_cdrom
545      printf("cdrom: mute\n");
546   #endif
547
548   send_result(intr_acknowledge);
549}
550
551void psxcd_device::cdcmd_demute()
552{
553   #ifdef debug_cdrom
554      printf("cdrom: demute\n");
555   #endif
556
557   send_result(intr_acknowledge);
558}
559
560void psxcd_device::cdcmd_setfilter()
561{
562   #ifdef debug_cdrom
563      printf("cdrom: setfilter %08x,%08x\n",cmdbuf[0],cmdbuf[1]);
564   #endif
565
566   filter_file=cmdbuf[0];
567   filter_channel=cmdbuf[1];
568
569   send_result(intr_acknowledge);
570}
571
572void psxcd_device::cdcmd_setmode()
573{
574   #ifdef debug_cdrom
575      printf("cdrom: setmode %08x\n",cmdbuf[0]);
576   #endif
577
578   mode=cmdbuf[0];
579
580   switch ((mode&mode_size_mask)>>mode_size_shift)
581   {
582      case 1:
583         secsize=2328;
584         secskip=24;
585         break;
586
587      case 2:
588         secsize=2340;
589         secskip=12;
590         break;
591
592      default:
593         secsize=2048;
594         secskip=24;
595         break;
596   }
597
598   send_result(intr_complete);
599}
600
601void psxcd_device::cdcmd_getparam()
602{
603   unsigned char data[6]=
604   {
605      status,
606      mode,
607      filter_file,
608      filter_channel,
609      0,
610      0
611   };
612
613   #ifdef debug_cdrom
614      printf("cdrom: getparam [%02x %02x %02x %02x %02x %02x]\n",
615                           data[0],
616                           data[1],
617                           data[2],
618                           data[3],
619                           data[4],
620                           data[5]);
621   #endif
622
623   send_result(intr_complete,data,6);
624}
625
626#if 0
627static void add_loc(unsigned char *dst, const unsigned char *src1, const unsigned char *src2)
628{
629   int f=src1[2]+src2[2],
630         s=src1[1]+src2[1],
631         m=src1[0]+src2[0];
632   while (f>=75) { s++; f-=75; }
633   while (s>=60) { m++; s-=60; }
634
635   dst[0]=m;
636   dst[1]=s;
637   dst[2]=f;
638}
639#endif
640static void sub_loc(unsigned char *dst, const unsigned char *src1, const unsigned char *src2)
641{
642   int f=src1[2]-src2[2],
643         s=src1[1]-src2[1],
644         m=src1[0]-src2[0];
645   while (f<0) { s--; f+=75; }
646   while (s<0) { m--; s+=60; }
647
648   if (m<0)
649      m=s=f=0;
650
651   dst[0]=m;
652   dst[1]=s;
653   dst[2]=f;
654}
655
656void psxcd_device::cdcmd_getlocl()
657{
658   #ifdef debug_cdrom
659      printf("cdrom: getlocl\n");
660   #endif
661
662   #ifdef debug_cdrom
663      printf("cdrom: getlocl [%02x %02x %02x %02x %02x %02x %02x %02x]\n",
664                           lastsechdr[0],
665                           lastsechdr[1],
666                           lastsechdr[2],
667                           lastsechdr[3],
668                           lastsechdr[4],
669                           lastsechdr[5],
670                           lastsechdr[6],
671                           lastsechdr[7]);
672   #endif
673
674   send_result(intr_complete,lastsechdr,8);
675}
676
677void psxcd_device::cdcmd_getlocp()
678{
679   unsigned char tloc[3],
680                        twosec[3]={ 0,2,0 };
681   sub_loc(tloc,loc,twosec);
682
683   unsigned char data[8]=
684   {
685      0x01,                     // track
686      0x01,                     // index
687      decimal_to_bcd(tloc[0]),   // min
688      decimal_to_bcd(tloc[1]),   // sec
689      decimal_to_bcd(tloc[2]),   // frame
690      decimal_to_bcd(loc[0]),   // amin
691      decimal_to_bcd(loc[1]),   // asec
692      decimal_to_bcd(loc[2])   // aframe
693   };
694
695   //unsigned char data[8]={ 2,1,0,0xff,0xff,0xff,0xff,0xff };
696
697   #ifdef debug_cdrom
698      printf("cdrom: getlocp [%02x %02x %02x %02x %02x %02x %02x %02x]\n",
699                           data[0],
700                           data[1],
701                           data[2],
702                           data[3],
703                           data[4],
704                           data[5],
705                           data[6],
706                           data[7]);
707   #endif
708
709   send_result(intr_complete,data,8);
710}
711
712void psxcd_device::cdcmd_illegal()
713{
714   assert(0);
715}
716
717void psxcd_device::cdcmd_gettn()
718{
719   #ifdef debug_cdrom
720      printf("cdrom: gettn\n");
721   #endif
722
723   assert(driver);
724
725   unsigned char data[3]=
726   {
727      status,
728      decimal_to_bcd(driver->get_first_track()),
729      decimal_to_bcd(driver->get_num_tracks())
730   };
731
732   //stop_read();
733   send_result(intr_acknowledge,data,3);
734}
735
736void psxcd_device::cdcmd_gettd()
737{
738   unsigned char addr[3];
739   driver->get_track_address(bcd_to_decimal(cmdbuf[0]), addr);
740
741   unsigned char data[3]=
742   {
743      status,
744      decimal_to_bcd(addr[0]),
745      decimal_to_bcd(addr[1])
746   };
747
748   #ifdef debug_cdrom
749      printf("cdrom: gettd %02x [%02x %02x %02x]\n",
750                                     cmdbuf[0],
751                                     data[0],
752                                     data[1],
753                                     data[2]);
754   #endif
755
756   //stop_read();
757   send_result(intr_acknowledge,data,3);
758}
759
760void psxcd_device::cdcmd_seekl()
761{
762   #ifdef debug_cdrom
763      printf("cdrom: seekl [%02d:%02d:%02d]\n",loc[0],loc[1],loc[2]);
764   #endif
765
766   curpos[0]=loc[0];
767   curpos[1]=loc[1];
768   curpos[2]=loc[2];
769
770   send_result(intr_acknowledge);
771}
772
773void psxcd_device::cdcmd_seekp()
774{
775   #ifdef debug_cdrom
776      printf("cdrom: seekp\n");
777   #endif
778
779   curpos[0]=loc[0];
780   curpos[1]=loc[1];
781   curpos[2]=loc[2];
782
783   send_result(intr_acknowledge);
784}
785
786void psxcd_device::cdcmd_test()
787{
788   #ifdef debug_cdrom
789      printf("cdrom: test %08x\n",cmdbuf[0]);
790   #endif
791
792   static unsigned char data[4]=
793   {
794      0x95,
795      0x07,
796      0x06,
797      0xff
798   };
799
800   send_result(intr_complete,data,4);
801}
802
803void psxcd_device::cdcmd_id()
804{
805   #ifdef debug_cdrom
806      printf("cdrom: id\n");
807   #endif
808
809   if (! open)
810   {
811      if (driver)
812         open=driver->read_toc();
813   }
814
815   if (open)
816   {
817      static unsigned char gamedata[8] = { 0x08, 0x00, 0x00, 0x00, 'S', 'C', 'E', 'A' };
818      static unsigned char audiodata[8] = { 0x08, 0x90, 0x00, 0x00, 'S', 'C', 'E', 'A' };   // drops into the audio CD player.  08 80 goes to the menu.
819
820      if (cdrom_get_track_type(m_cd, 0) == CD_TRACK_AUDIO)
821      {
822         send_result(intr_acknowledge,audiodata,8);
823      }
824      else
825      {
826         send_result(intr_acknowledge,gamedata,8);
827      }
828   } else
829   {
830      status=status_error|status_shellopen;
831      send_result(intr_diskerror);
832   }
833}
834
835void psxcd_device::cdcmd_reads()
836{
837   curpos[0]=loc[0];
838   curpos[1]=loc[1];
839   curpos[2]=loc[2];
840
841   #ifdef skip_reads
842      #ifdef debug_cdrom
843         log("cdrom: reads [SKIPPING - RETURN COMPLETE]\n");
844      #endif
845
846      send_result(intr_complete);
847   #else
848      #ifdef debug_cdrom
849         printf("cdrom: reads\n");
850      #endif
851
852      stop_read();
853      start_streaming();
854   #endif
855}
856
857void psxcd_device::cdcmd_reset()
858{
859   #ifdef debug_cdrom
860      printf("cdrom: reset\n");
861   #endif
862}
863
864void psxcd_device::cdcmd_readtoc()
865{
866   #ifdef debug_cdrom
867      printf("cdrom: readtoc\n");
868   #endif
869
870   static unsigned char data[4]=
871   {
872      0x00,
873      0x00,
874      0xff,
875      0xfe
876   };
877
878   send_result(intr_complete|0x10,data,2);
879}
880
881//
882//
883//
884
885void psxcd_device::cmd_complete(command_result *res)
886{
887   bool doint=((res->res&0x10)==0);
888   #ifdef debug_cdrom
889   command_result *rf;
890   #endif
891
892   if (doint)
893   {
894      psx_irq_set(machine(), 0x0004);
895   }
896
897   add_result(res);
898
899   #ifdef debug_cdrom
900      if (doint)
901      {
902         printf("cdrom: irq [");
903         for (rf=res_queue; ((rf) && (rf->next)); rf=rf->next);
904            printf("%d ",rf->res);
905         printf("]\n");
906      }
907   #endif
908}
909
910//
911//
912//
913
914void psxcd_device::add_result(command_result *res)
915{
916   command_result *rf;
917
918   if (res_queue)
919   {
920      for (rf=res_queue; rf->next; rf=rf->next);
921      rf->next=res;
922   } else
923   {
924      res_queue=res;
925   }
926
927   res->next=NULL;
928}
929
930//
931//
932//
933
934event *psxcd_device::send_result(const unsigned int res,
935                                          const unsigned char *data,
936                                          const unsigned int sz,
937                                             const unsigned int delay)
938{
939   // Update shell open status
940
941   if (! open)
942   {
943      status=status_error|status_shellopen;
944   }
945   else
946   {
947      if (status&status_shellopen)
948         status=status_standby;
949   }
950
951   // Prepare event
952
953   event *ev=new event;
954   ev->t=delay;
955   ev->type=event_cmd_complete;
956
957   command_result *cr=(command_result *)ev->data;
958
959   cr->res=res;
960   if (sz)
961   {
962      assert(sz<sizeof(cr->data));
963      memcpy(cr->data,data,sz);
964      cr->sz=sz;
965   } else
966   {
967      cr->data[0]=status;
968      cr->sz=1;
969   }
970
971   // Avoid returning results after sector read results -
972   // delay the sector read slightly if necessary
973
974   UINT64 systime = machine().device<cpu_device>("maincpu")->total_cycles();
975   if ((next_read_event) && ((systime+ev->t)>(next_sector_t)))
976   {
977      UINT32 hz = m_sysclock / (delay + 2000);
978      next_read_event->timer->adjust(attotime::from_hz(hz), 0, attotime::never);
979
980      for (int i = 0; i < MAX_PSXCD_TIMERS; i++)
981      {
982         if (m_eventfortimer[i] == next_read_event)
983         {
984            printf("Adjusting timer %d to %d hz]n", i, hz);
985         }
986      }
987   }
988
989   add_system_event(ev);
990   return ev;
991}
992
993//
994//
995//
996
997void psxcd_device::start_dma(UINT8 *mainram, UINT32 size)
998{
999   if ((int)size>secleft)
1000   {
1001      printf("cdrom: dma past end of sector (secleft=%d sz=%d)\n",secleft,size);
1002   }
1003
1004//  printf("cdrom: start dma %d bytes, %d remaining, secptr %p\n", size, secleft, secptr);
1005   #ifdef debug_cdrom
1006   if (size==12)
1007   {
1008      char poo[1024],*pp=poo;
1009      for (unsigned int i=0; i<12; i++)
1010      {
1011         sprintf(pp,"%02x ",secptr[i]);
1012         pp+=3;
1013      }
1014      printf("cdrom: data=%s\n",poo);
1015   }
1016   #endif
1017
1018   memcpy(mainram, secptr, size);
1019   memset(secptr, 0xff, size);
1020
1021   secptr += size;
1022   secleft -= size;
1023
1024   if (secleft<0) secleft=0;
1025   if (secleft==0) sr&=~0x40;
1026}
1027
1028//
1029//
1030//
1031
1032void psxcd_device::prefetch_next_sector()
1033{
1034   unsigned int pos=msf_to_sector(curpos);
1035   assert(driver);
1036   driver->prefetch_sector(pos);
1037}
1038
1039//
1040//
1041//
1042
1043bool psxcd_device::read_next_sector(const bool block)
1044{
1045   unsigned int pos=msf_to_sector(curpos);
1046   unsigned char *buf=&secbuf[sechead*raw_sector_size];
1047   assert(driver);
1048   assert(secin<sector_buffer_size);
1049
1050//  printf("read_next_sector: sec %d, sechead %d, raw_sector_size %d\n", pos, sechead, raw_sector_size);
1051   if (driver->read_sector(pos, buf, block))
1052   {
1053//      printf("buf contents = %02x %02x | %02x %02x\n", buf[0], buf[1], buf[0x20], buf[0x21]);
1054
1055      sechead=(sechead+1)&(sector_buffer_size-1);
1056      secin++;
1057
1058      memcpy(lastsechdr,&secbuf[raw_sector_size*sectail]+12,8);
1059
1060      return true;
1061   } else
1062   {
1063      return false;
1064   }
1065}
1066
1067//
1068//
1069//
1070
1071void psxcd_device::read_sector()
1072{
1073   next_read_event=NULL;
1074
1075   if (status & status_reading)
1076   {
1077      bool isend=false;
1078
1079      if (read_next_sector(false))
1080      {
1081         unsigned char *rawsec;
1082
1083         if ((mode&mode_adpcm) && (streaming))
1084         {
1085            rawsec=&secbuf[raw_sector_size*sectail];
1086            secptr=rawsec+24;
1087            secleft=2048;
1088         }
1089         else
1090         {
1091            rawsec=&secbuf[raw_sector_size*sectail];
1092            secptr=rawsec+secskip;
1093            secleft=secsize;
1094         }
1095
1096         secin--;
1097         sectail=(sectail+1)&(sector_buffer_size-1);
1098
1099         //
1100
1101         bool isxa=false;
1102
1103         subheader *sub=(subheader *)(rawsec+16);
1104
1105         #ifdef dump_subheader
1106            printf("cdrom: subheader file=%02x chan=%02x submode=%02x coding=%02x [%02x%02x%02x%02x]\n",
1107                  sub->file,
1108                  sub->channel,
1109                  sub->submode,
1110                  sub->coding,
1111                  rawsec[0xc],
1112                  rawsec[0xd],
1113                  rawsec[0xe],
1114                  rawsec[0xf]);
1115         #endif
1116
1117         status&=~status_playing;
1118         isxa=((mode&mode_adpcm) && (sub->submode&submode_audio));
1119
1120         if (((mode&mode_channel)==0) ||
1121               ((sub->file==filter_file) && (sub->channel==filter_channel)))
1122         {
1123            if (isxa)
1124            {
1125               if (sub->submode&submode_eof)
1126               {
1127                  isend=true;
1128                  //printf("end of file\n");
1129               }
1130
1131               #ifndef disable_xa_prefetch
1132                  unsigned int cursec=msf_to_sector(curpos);
1133
1134                  if (xa_prefetch_sector==-1)
1135                  {
1136                     xa_prefetch_sector=cursec;
1137                     machine().device<spu_device>("spu")->flush_xa();
1138                  }
1139
1140                  unsigned char *xaptr;
1141                  unsigned int xasecsz;
1142
1143                  while (1)
1144                  {
1145                     int dist=xa_prefetch_sector-cursec;
1146                     if (dist>max_xa_prefetch_distance) break;
1147
1148                     xaptr=driver->get_prefetch_sector(xa_prefetch_sector,&xasecsz);
1149                     if (! xaptr) break;
1150
1151                     switch (xasecsz)
1152                     {
1153                        case 2336:
1154                           break;
1155
1156                        default:
1157                           xaptr+=16;
1158                           break;
1159                     }
1160
1161                     subheader *xasub=(subheader *)xaptr;
1162
1163                     if ((xasub->submode&submode_audio) &&
1164                           (((mode&mode_channel)==0) ||
1165                            ((xasub->file==sub->file) &&
1166                              (xasub->channel==sub->channel))))
1167                     {
1168                        if (! machine().device<spu_device>("spu")->play_xa(xa_prefetch_sector,xaptr))
1169                           break;
1170                     }
1171                     xa_prefetch_sector++;
1172                  }
1173               #else
1174                  machine().device<spu_device>("spu")->play_xa(0,rawsec+16);
1175               #endif
1176
1177               status|=status_playing;
1178            }
1179         }
1180
1181         if ((mode&mode_autopause)==0)
1182            isend=false;
1183
1184         //
1185
1186         curpos[2]++;
1187         if (curpos[2]==75)
1188         {
1189            curpos[2]=0;
1190            curpos[1]++;
1191            if (curpos[1]==60)
1192            {
1193               curpos[1]=0;
1194               curpos[0]++;
1195            }
1196         }
1197
1198         loc[0]=curpos[0];
1199         loc[1]=curpos[1];
1200         loc[2]=curpos[2];
1201
1202         //
1203
1204         command_result *res=new command_result;
1205         res->res=isend?intr_dataend:intr_dataready;
1206         res->data[0]=status;
1207         res->sz=1;
1208
1209         sr|=0x40;
1210
1211         if ((streaming) && (isxa))
1212         {
1213            global_free(res);
1214            res=NULL;
1215         }
1216
1217         if (res)
1218         {
1219            #ifdef debug_cdrom
1220               printf("cdrom:: data ready\n");
1221            #endif
1222
1223            cmd_complete(res);
1224         }
1225      }
1226
1227      if (! isend)
1228      {
1229         unsigned int cyc=read_sector_cycles;
1230         if (mode&mode_double_speed) cyc>>=1;
1231
1232         next_sector_t+=cyc;
1233
1234         event *ev=new event;
1235         ev->t=cyc;
1236         ev->type=event_read_sector;
1237         next_read_event=ev;
1238         add_system_event(ev);
1239
1240         //read_next_sector();
1241      } else
1242      {
1243         printf("autopause xa\n");
1244         stop_read();
1245      }
1246   }
1247}
1248
1249//
1250//
1251//
1252
1253bool psxcd_device::play_cdda_sector(const unsigned int sector,
1254                                                 unsigned char *rawsec)
1255{
1256   bool isdata=true;
1257
1258   if (rawsec[0]!=0)
1259   {
1260      isdata=false;
1261   } else
1262   {
1263      for (int i=0; i<10; i++)
1264         if (rawsec[i+1]!=0xff)
1265         {
1266            isdata=false;
1267            break;
1268         }
1269   }
1270
1271   if (! isdata)
1272   {
1273      return machine().device<spu_device>("spu")->play_cdda(sector,rawsec);
1274   } else
1275   {
1276      return true;
1277   }
1278}
1279
1280//
1281//
1282//
1283
1284void psxcd_device::play_sector()
1285{
1286   next_read_event=NULL;
1287
1288   if (status&status_playing)
1289   {
1290      #ifdef disable_cdda_prefetch
1291      unsigned char *rawsec=&secbuf[raw_sector_size*sectail];
1292      #endif
1293      secin--;
1294      sectail=(sectail+1)&(sector_buffer_size-1);
1295
1296      //
1297
1298      #ifndef disable_cdda_prefetch
1299         unsigned int cursec=msf_to_sector(curpos);
1300
1301         if (cdda_prefetch_sector==-1)
1302         {
1303            cdda_prefetch_sector=cursec;
1304            machine().device<spu_device>("spu")->flush_cdda();
1305         }
1306
1307         unsigned char *cddaptr;
1308//          bool full=false;
1309         unsigned int cddasecsz;
1310
1311         while (1)
1312         {
1313            int dist=cdda_prefetch_sector-cursec;
1314            if (dist>max_cdda_prefetch_distance) break;
1315
1316            cddaptr=driver->get_prefetch_sector(cdda_prefetch_sector,&cddasecsz);
1317            if (! cddaptr) break;
1318
1319            if (! play_cdda_sector(cdda_prefetch_sector,cddaptr))
1320               break;
1321
1322            cdda_prefetch_sector++;
1323         }
1324      #else
1325         play_cdda_sector(0,rawsec);
1326      #endif
1327
1328      //
1329
1330      curpos[2]++;
1331      if (curpos[2]==75)
1332      {
1333         curpos[2]=0;
1334         curpos[1]++;
1335         if (curpos[1]==60)
1336         {
1337            curpos[1]=0;
1338            curpos[0]++;
1339         }
1340      }
1341
1342      loc[0]=curpos[0];
1343      loc[1]=curpos[1];
1344      loc[2]=curpos[2];
1345
1346      //
1347
1348      if (mode&mode_autopause)
1349      {
1350         if (msf_to_sector(loc)>=autopause_sector)
1351         {
1352            printf("autopause cdda\n");
1353
1354            command_result *res=new command_result;
1355            res->res=intr_dataend;
1356            res->data[0]=status_standby;
1357            res->sz=1;
1358            cmd_complete(res);
1359            stop_read();
1360            return;
1361         }
1362      }
1363
1364      if (mode&mode_report)
1365      {
1366         command_result *res=new command_result;
1367         res->res=intr_complete;   //dataready;
1368
1369         res->data[0]=status_playing|status_standby;
1370         res->data[1]=0x01;
1371         res->data[2]=0x80;
1372         res->data[3]=decimal_to_bcd(loc[0]);
1373         res->data[4]=decimal_to_bcd(loc[1])|0x80;
1374         res->data[5]=decimal_to_bcd(loc[2]);
1375
1376         res->sz=8;
1377
1378         cmd_complete(res);
1379      }
1380
1381      unsigned int cyc=read_sector_cycles;
1382
1383      event *ev=new event;
1384      ev->t=next_sector_t - machine().device<cpu_device>("maincpu")->total_cycles();
1385      ev->type=event_play_sector;
1386
1387      next_sector_t+=cyc;
1388
1389      next_read_event=ev;
1390      add_system_event(ev);
1391
1392      read_next_sector();
1393   }
1394}
1395
1396
1397//
1398//
1399//
1400
1401void psxcd_device::preread_sector()
1402{
1403   next_read_event=NULL;
1404
1405   //
1406
1407   event *ev=new event;
1408
1409   unsigned int pos=msf_to_sector(curpos);
1410   unsigned char *buf=&secbuf[sechead*raw_sector_size];
1411   if (! driver->read_sector(pos,buf,false))
1412   {
1413      ev->t=(m_sysclock/60);
1414      ev->type=event_preread_sector;
1415
1416      unsigned int cyc=read_sector_cycles;
1417      if (mode&mode_double_speed) cyc>>=1;
1418      next_sector_t=ev->t+(cyc-preread_delay)+machine().device<cpu_device>("maincpu")->total_cycles();
1419   } else
1420   {
1421      memcpy(lastsechdr,buf+12,8);
1422
1423      //
1424
1425      command_result *res=new command_result;
1426      res->res=intr_complete;
1427      res->data[0]=status;
1428      res->sz=1;
1429
1430      #ifdef debug_cdrom
1431         printf("cdrom: read acknowledge\n");
1432      #endif
1433
1434      cmd_complete(res);
1435
1436      //
1437
1438      ev->t=next_sector_t - machine().device<cpu_device>("maincpu")->total_cycles();
1439      ev->type=event_read_sector;
1440
1441      //read_next_sector();
1442   }
1443
1444   next_read_event=ev;
1445   add_system_event(ev);
1446}
1447
1448//
1449//
1450//
1451
1452void psxcd_device::start_read()
1453{
1454   #ifdef debug_cdrom
1455      printf("cdrom: start read\n");
1456   #endif
1457
1458   assert((status&(status_reading|status_playing))==0);
1459
1460   status|=status_reading;
1461
1462   secin=sechead=sectail=0;
1463   xa_prefetch_sector=-1;
1464
1465   unsigned int cyc=read_sector_cycles;
1466   if (mode&mode_double_speed) cyc>>=1;
1467
1468   INT64 systime=machine().device<cpu_device>("maincpu")->total_cycles();
1469
1470   systime+=start_read_delay;
1471
1472   event *ev=new event;
1473   ev->t=start_read_delay+preread_delay;
1474   ev->type=event_preread_sector;
1475
1476   next_sector_t=systime+cyc;
1477   next_read_event=ev;
1478   add_system_event(ev);
1479
1480   prefetch_next_sector();
1481}
1482
1483//
1484//
1485//
1486
1487void psxcd_device::start_streaming()
1488{
1489   assert(! streaming);
1490
1491   streaming=true;
1492   start_read();
1493}
1494
1495//
1496//
1497//
1498
1499void psxcd_device::start_play()
1500{
1501   #ifdef debug_cdrom
1502      printf("cdrom: start play\n");
1503   #endif
1504
1505   status|=status_playing;
1506
1507   secin=sechead=sectail=0;
1508   cdda_prefetch_sector=-1;
1509
1510   if (mode&mode_autopause)
1511   {
1512      unsigned int pos=msf_to_sector(curpos);
1513      driver->find_track(pos+150,NULL,&autopause_sector);
1514//      printf("pos=%d auto=%d\n",pos,autopause_sector);
1515   }
1516
1517   unsigned int cyc=read_sector_cycles;
1518
1519   next_sector_t=machine().device<cpu_device>("maincpu")->total_cycles()+cyc;
1520
1521   event *ev=new event;
1522   ev->t=next_sector_t - machine().device<cpu_device>("maincpu")->total_cycles();
1523   ev->type=event_play_sector;
1524
1525   next_sector_t+=cyc;
1526
1527   next_read_event=ev;
1528   add_system_event(ev);
1529
1530   read_next_sector();
1531}
1532
1533//
1534//
1535//
1536
1537void psxcd_device::stop_read()
1538{
1539   #ifdef debug_cdrom
1540      if (status&status_reading)
1541         printf("cdrom: stop read\n");
1542   #endif
1543   status&=~(status_reading|status_playing);
1544   streaming=false;
1545
1546   if (next_read_event)
1547   {
1548      next_read_event->timer->adjust(attotime::never, 0, attotime::never);
1549      for (int i = 0; i < MAX_PSXCD_TIMERS; i++)
1550      {
1551         if (m_timers[i] == next_read_event->timer)
1552         {
1553            m_timerinuse[i] = false;
1554            m_eventfortimer[i] = false;
1555            break;
1556         }
1557      }
1558      global_free(next_read_event);
1559      next_read_event=NULL;
1560   }
1561
1562   unsigned int sector=msf_to_sector(curpos);
1563   machine().device<spu_device>("spu")->flush_xa(sector);
1564   machine().device<spu_device>("spu")->flush_cdda(sector);
1565}
1566
1567//
1568//
1569//
1570
1571void psxcd_device::set_driver(cdrom_driver *d)
1572{
1573   char err[1024];
1574
1575   if (d)
1576   {
1577      if (d->is_usable(err,1024))
1578      {
1579         driver=d;
1580         open=false;
1581
1582         if (! first_open)
1583         {
1584            command_result *res=new command_result;
1585            res->res=intr_acknowledge;
1586            res->data[0]=status_standby;
1587            res->sz=1;
1588
1589            cmd_complete(res);
1590
1591            open_nops=10;
1592         }
1593
1594         first_open=false;
1595      }
1596   } else
1597   {
1598      driver=NULL;
1599      open=false;
1600
1601      command_result *res=new command_result;
1602      res->res=intr_acknowledge;
1603      res->data[0]=status_shellopen;
1604      res->sz=1;
1605
1606      cmd_complete(res);
1607   }
1608}
1609
1610//
1611//
1612//
1613void psxcd_device::device_timer(emu_timer &timer, device_timer_id tid, int param, void *ptr)
1614{
1615   event *ev = m_eventfortimer[tid];
1616
1617//  printf("timer %d fired, performing event type %d\n", tid, ev->type);
1618
1619   switch (ev->type)
1620   {
1621      case event_cmd_complete:
1622      {
1623         #ifdef debug_cdrom
1624            printf("cdrom:: event cmd complete\n");
1625         #endif
1626
1627         command_result *res=new command_result;
1628         memcpy(res,ev->data,sizeof(command_result));
1629         cmd_complete(res);
1630         break;
1631      }
1632
1633      case event_preread_sector:
1634         preread_sector();
1635         break;
1636
1637      case event_read_sector:
1638         read_sector();
1639         break;
1640
1641      case event_play_sector:
1642         play_sector();
1643         break;
1644   }
1645
1646   // free the timer
1647//  printf("Freeing timer %d\n", tid);
1648   m_timers[tid]->adjust(attotime::never, 0, attotime::never);
1649   m_timerinuse[tid] = false;
1650   m_eventfortimer[tid] = NULL;
1651
1652   global_free(ev);
1653}
1654
1655void psxcd_device::add_system_event(event *ev)
1656{
1657   emu_timer *timer = NULL;
1658   int tnum = -1;
1659
1660   // allocate a timer for this event
1661   for (int i = 0; i < MAX_PSXCD_TIMERS; i++)
1662   {
1663      if (!m_timerinuse[i])
1664      {
1665         tnum = i;
1666         timer = m_timers[i];
1667         m_timerinuse[i] = true;
1668         m_eventfortimer[i] = ev;
1669         break;
1670      }
1671   }
1672
1673   if (tnum == -1)
1674   {
1675      fatalerror("PSXCD: ran out of timers!\n");
1676   }
1677
1678   // ev->t is in maincpu clock cycles
1679   UINT32 hz = m_sysclock / ev->t;
1680//  printf("add_system_event: event type %d for %d hz (using timer %d)\n", ev->type, hz, tnum);
1681   timer->adjust(attotime::from_hz(hz), tnum, attotime::never);
1682
1683   // back-reference the timer from the event
1684   ev->timer = timer;
1685}
1686
src/mame/machine/psxcd.h
r0r11461
1#ifndef _included_psxcdrom_
2#define _included_psxcdrom_
3
4#include "imagedev/chd_cd.h"
5#include "psxcddrv.h"
6
7#define MAX_PSXCD_TIMERS   (4)
8
9class event;
10
11//
12//
13//
14
15const int num_commands=0x20;
16
17//
18//
19//
20
21#define PSXCD_TAG   "psxcd"
22
23//**************************************************************************
24//  INTERFACE CONFIGURATION MACROS
25//**************************************************************************
26
27#define MCFG_PSXCD_ADD(_devname) \
28    MCFG_DEVICE_ADD(PSXCD_TAG, PSXCD, 0) \
29   MCFG_PSXCD_DEVNAME(_devname)
30
31#define MCFG_PSXCD_DEVNAME(_name) \
32   psxcd_device::static_set_devname(*device, _name); \
33
34struct psxcd_interface
35{
36};
37
38class psxcd_device : public device_t,
39                     public psxcd_interface
40{
41public:
42
43    psxcd_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
44   // inline configuration helpers
45   static void static_set_devname(device_t &device, const char *devname);
46private:
47   struct command_result
48   {
49      unsigned char data[32], sz, res;
50      command_result *next;
51   };
52
53   static const unsigned int sector_buffer_size=16, default_irq_delay=16000;   //480;  //8000; //2000<<2;
54
55   unsigned char sr,res,ir,cmdmode,
56                        cmdbuf[64],*cbp,
57                        mode,
58                        loc[3],
59                        curpos[3],
60                        secbuf[raw_sector_size*sector_buffer_size],
61                        *secptr,
62                        filter_file,
63                        filter_channel,
64                        lastsechdr[8],
65                        status;
66   int rdp,secsize,secleft,secskip,
67         sechead,sectail,
68         secin;
69   command_result *res_queue,
70                         *cur_res;
71   bool open,
72          streaming,
73          first_open;
74   event *next_read_event;
75   INT64 next_sector_t;
76   unsigned int autopause_sector,
77                      xa_prefetch_sector,
78                      cdda_prefetch_sector;
79
80   cdrom_driver *driver;
81
82   unsigned int start_read_delay,
83                      read_sector_cycles,
84                      preread_delay;
85
86   void write_command(const unsigned char byte);
87
88   struct command_info
89   {
90      void (psxcd_device::*func)();
91      const char *name;
92   };
93
94   void cdcmd_sync();
95   void cdcmd_nop();
96   void cdcmd_setloc();
97   void cdcmd_play();
98   void cdcmd_forward();
99   void cdcmd_backward();
100   void cdcmd_readn();
101   void cdcmd_standby();
102   void cdcmd_stop();
103   void cdcmd_pause();
104   void cdcmd_init();
105   void cdcmd_mute();
106   void cdcmd_demute();
107   void cdcmd_setfilter();
108   void cdcmd_setmode();
109   void cdcmd_getparam();
110   void cdcmd_getlocl();
111   void cdcmd_getlocp();
112   void cdcmd_illegal();
113   void cdcmd_gettn();
114   void cdcmd_gettd();
115   void cdcmd_seekl();
116   void cdcmd_seekp();
117   void cdcmd_test();
118   void cdcmd_id();
119   void cdcmd_reads();
120   void cdcmd_reset();
121   void cdcmd_readtoc();
122
123   static command_info cmd_table[num_commands];
124
125   void cmd_complete(command_result *res);
126   void add_result(command_result *res);
127   event *send_result(const unsigned int res,
128                               const unsigned char *data=NULL,
129                               const unsigned int sz=0,
130                               const unsigned int delay=default_irq_delay);
131
132   void start_read();
133   void start_play();
134   void start_streaming();
135   void stop_read();
136   void read_sector();
137   void prefetch_next_sector();
138   bool read_next_sector(const bool block=true);
139   bool play_cdda_sector(const unsigned int sector, unsigned char *rawsec);
140   void play_sector();
141   void preread_sector();
142
143public:
144   void set_driver(cdrom_driver *d);
145   cdrom_driver *get_driver() const { return driver; }
146
147   virtual void device_start();
148   virtual void device_reset();
149   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
150
151   void start_dma(UINT8 *mainram, UINT32 size);
152
153   unsigned char read_byte(const unsigned int addr);
154   void write_byte(const unsigned int addr, const unsigned char byte);
155
156private:
157   emu_timer *m_timer;
158   UINT32 m_sysclock;
159   const char *m_devname;
160   device_t *m_cddevice;
161   cdrom_file   *m_cd;
162   emu_timer *m_timers[MAX_PSXCD_TIMERS];
163   event *m_eventfortimer[MAX_PSXCD_TIMERS];
164   bool m_timerinuse[MAX_PSXCD_TIMERS];
165   
166   void add_system_event(event *ev);
167};
168
169
170// miniature version of pSX's event class, which we emulate with device timers
171const int max_event_data=64;
172
173class event
174{
175public:
176   UINT64 t;            // expire time
177   unsigned int type;
178   unsigned char data[max_event_data];
179   emu_timer *timer;
180};
181
182
183// device type definition
184extern const device_type PSXCD;
185
186#endif
src/mame/machine/amigafdc.c
r0r11461
1/****************************************************f***********************
2
3    Amiga floppy disk controller emulation
4
5    - The drive spins at 300 RPM = 1 Rev every 200ms
6    - At 2usec per bit, that's 12500 bytes per track, or 6250 words per track
7    - At 4usec per bit, that's 6250 bytes per track, or 3125 words per track
8    - Each standard amiga sector has 544 words per sector, and 11 sectors per track = 11968 bytes
9    - ( 12500(max) - 11968(actual) ) = 532 per track gap bytes
10
11***************************************************************************/
12
13
14#include "emu.h"
15#include "includes/amiga.h"
16#include "imagedev/flopdrv.h"
17#include "formats/ami_dsk.h"
18#include "amigafdc.h"
19#include "machine/6526cia.h"
20
21
22#define MAX_TRACK_BYTES         12500
23#define ACTUAL_TRACK_BYTES      11968
24#define GAP_TRACK_BYTES         ( MAX_TRACK_BYTES - ACTUAL_TRACK_BYTES )
25#define ONE_SECTOR_BYTES      (544*2)
26#define ONE_REV_TIME         200 /* ms */
27#define MAX_WORDS_PER_DMA_CYCLE   32 /* 64 bytes per dma cycle */
28#define DISK_DETECT_DELAY      1
29#define MAX_TRACKS            160
30#define MAX_MFM_TRACK_LEN      16384
31
32#define NUM_DRIVES 2
33
34/* required prototype */
35static void setup_fdc_buffer( device_t *device,int drive );
36
37/***************************************************************************
38    TYPE DEFINITIONS
39***************************************************************************/
40typedef struct {
41   int motor_on;
42   int side;
43   int dir;
44   int wprot;
45   int disk_changed;
46   device_image_interface *f;
47   UINT32 extinfo[MAX_TRACKS];
48   UINT32 extoffs[MAX_TRACKS];
49   int is_ext_image;
50   int cyl;
51   int tracklen;
52   UINT8 mfm[MAX_MFM_TRACK_LEN];
53   int   cached;
54   emu_timer *rev_timer;
55   emu_timer *sync_timer;
56   emu_timer *dma_timer;
57   int rev_timer_started;
58   int pos;
59   int len;
60   offs_t ptr;
61} fdc_def;
62
63typedef struct _amiga_fdc_t amiga_fdc_t;
64struct _amiga_fdc_t
65{
66   fdc_def fdc_status[NUM_DRIVES];
67
68   /* signals */
69   int fdc_sel;
70   int fdc_dir;
71   int fdc_side;
72   int fdc_step;
73   int fdc_rdy;
74};
75
76/*****************************************************************************
77    INLINE FUNCTIONS
78*****************************************************************************/
79INLINE amiga_fdc_t *get_safe_token(device_t *device)
80{
81   assert(device != NULL);
82   assert(device->type() == AMIGA_FDC);
83
84   return (amiga_fdc_t *)downcast<legacy_device_base *>(device)->token();
85}
86
87static TIMER_CALLBACK(fdc_rev_proc);
88static TIMER_CALLBACK(fdc_dma_proc);
89static TIMER_CALLBACK(fdc_sync_proc);
90static void check_extended_image( device_t *device, int id );
91
92static void amiga_load_proc(device_image_interface &image)
93{
94   amiga_fdc_t *fdc = get_safe_token(image.device().owner());
95   int id = floppy_get_drive(&image.device());
96   fdc->fdc_status[id].disk_changed = DISK_DETECT_DELAY;
97   fdc->fdc_status[id].f = &image;
98   fdc->fdc_status[id].cached = -1;
99   fdc->fdc_status[id].motor_on = 0;
100   fdc->fdc_status[id].rev_timer_started = 0;
101   fdc->fdc_status[id].rev_timer->reset(  );
102   fdc->fdc_status[id].sync_timer->reset(  );
103   fdc->fdc_status[id].dma_timer->reset(  );
104   fdc->fdc_rdy = 0;
105
106   check_extended_image( image.device().owner(), id );
107}
108
109static void amiga_unload_proc(device_image_interface &image)
110{
111   amiga_fdc_t *fdc = get_safe_token(image.device().owner());
112   int id = floppy_get_drive(&image.device());
113   fdc->fdc_status[id].disk_changed = DISK_DETECT_DELAY;
114   fdc->fdc_status[id].f = NULL;
115   fdc->fdc_status[id].cached = -1;
116   fdc->fdc_status[id].motor_on = 0;
117   fdc->fdc_status[id].rev_timer_started = 0;
118   fdc->fdc_status[id].rev_timer->reset(  );
119   fdc->fdc_status[id].sync_timer->reset(  );
120   fdc->fdc_status[id].dma_timer->reset(  );
121   fdc->fdc_rdy = 0;
122}
123
124/*-------------------------------------------------
125    DEVICE_START(amiga_fdc)
126-------------------------------------------------*/
127device_t *amiga_floppy_get_device_child(device_t *device,int drive)
128{
129   switch(drive) {
130      case 0 : return device->subdevice(FLOPPY_0);
131      case 1 : return device->subdevice(FLOPPY_1);
132   }
133   return NULL;
134}
135
136static DEVICE_START(amiga_fdc)
137{
138   amiga_fdc_t *fdc = get_safe_token(device);
139   int id;
140   for(id=0;id<2;id++)
141   {
142      fdc->fdc_status[id].rev_timer = device->machine().scheduler().timer_alloc(FUNC(fdc_rev_proc), (void*)device);
143      fdc->fdc_status[id].dma_timer = device->machine().scheduler().timer_alloc(FUNC(fdc_dma_proc), (void*)device);
144      fdc->fdc_status[id].sync_timer = device->machine().scheduler().timer_alloc(FUNC(fdc_sync_proc), (void*)device);
145      floppy_install_load_proc(amiga_floppy_get_device_child(device, id), amiga_load_proc);
146      floppy_install_unload_proc(amiga_floppy_get_device_child(device, id), amiga_unload_proc);
147      fdc->fdc_status[id].motor_on = 0;
148      fdc->fdc_status[id].side = 0;
149      fdc->fdc_status[id].dir = 0;
150      fdc->fdc_status[id].wprot = 1;
151      fdc->fdc_status[id].cyl = 0;
152      fdc->fdc_status[id].rev_timer_started = 0;
153      fdc->fdc_status[id].cached = -1;
154      fdc->fdc_status[id].pos = 0;
155      fdc->fdc_status[id].len = 0;
156      fdc->fdc_status[id].ptr = 0;
157      fdc->fdc_status[id].f = NULL;
158      fdc->fdc_status[id].is_ext_image = 0;
159      fdc->fdc_status[id].tracklen = MAX_TRACK_BYTES;
160      fdc->fdc_status[id].disk_changed = DISK_DETECT_DELAY;
161      fdc->fdc_status[id].rev_timer->reset(  );
162      fdc->fdc_status[id].sync_timer->reset(  );
163      fdc->fdc_status[id].dma_timer->reset(  );
164      memset( fdc->fdc_status[id].mfm, 0xaa, MAX_MFM_TRACK_LEN );
165   }
166   fdc->fdc_sel = 0x0f;
167   fdc->fdc_dir = 0;
168   fdc->fdc_side = 1;
169   fdc->fdc_step = 1;
170   fdc->fdc_rdy = 0;
171
172}
173
174
175/*-------------------------------------------------
176    DEVICE_RESET(amiga_fdc)
177-------------------------------------------------*/
178
179static DEVICE_RESET(amiga_fdc)
180{
181}
182
183static void check_extended_image( device_t *device, int id )
184{
185   UINT8   header[8], data[4];
186   amiga_fdc_t *fdc = get_safe_token(device);
187
188   fdc->fdc_status[id].is_ext_image = 0;
189
190   if ( fdc->fdc_status[id].f->fseek( 0, SEEK_SET ) )
191   {
192      logerror("FDC: image_fseek failed!\n" );
193      return;
194   }
195
196   fdc->fdc_status[id].f->fread( &header, sizeof( header ) );
197
198   if ( memcmp( header, "UAE--ADF", sizeof( header ) ) == 0 )
199   {
200      int      i;
201
202      for( i = 0; i < MAX_TRACKS; i++ )
203      {
204         fdc->fdc_status[id].f->fread( &data, sizeof( data ) );
205
206         /* data[0,1] = SYNC - data[2,3] = LEN */
207
208         fdc->fdc_status[id].extinfo[i] = data[0];
209         fdc->fdc_status[id].extinfo[i] <<= 8;
210         fdc->fdc_status[id].extinfo[i] |= data[1];
211         fdc->fdc_status[id].extinfo[i] <<= 8;
212         fdc->fdc_status[id].extinfo[i] |= data[2];
213         fdc->fdc_status[id].extinfo[i] <<= 8;
214         fdc->fdc_status[id].extinfo[i] |= data[3];
215
216         if ( i == 0 )
217            fdc->fdc_status[id].extoffs[i] = sizeof( header ) + ( MAX_TRACKS * sizeof( data ) );
218         else
219            fdc->fdc_status[id].extoffs[i] = fdc->fdc_status[id].extoffs[i-1] + ( fdc->fdc_status[id].extinfo[i-1] & 0xffff );
220      }
221
222      fdc->fdc_status[id].is_ext_image = 1;
223   }
224}
225
226static int fdc_get_curpos( device_t *device, int drive )
227{
228   amiga_state *state = device->machine().driver_data<amiga_state>();
229   double elapsed;
230   int speed;
231   int   bytes;
232   int pos;
233   amiga_fdc_t *fdc = get_safe_token(device);
234
235   if ( fdc->fdc_status[drive].rev_timer_started == 0 ) {
236      logerror("Rev timer not started on drive %d, cant get position!\n", drive );
237      return 0;
238   }
239
240   elapsed = fdc->fdc_status[drive].rev_timer ->elapsed( ).as_double();
241   speed = ( CUSTOM_REG(REG_ADKCON) & 0x100 ) ? 2 : 4;
242
243   bytes = elapsed /  attotime::from_usec( speed * 8 ).as_double();
244   pos = bytes % ( fdc->fdc_status[drive].tracklen );
245
246   return pos;
247}
248
249UINT16 amiga_fdc_get_byte (device_t *device)
250{
251   amiga_state *state = device->machine().driver_data<amiga_state>();
252   int pos;
253   int i, drive = -1;
254   UINT16 ret;
255   amiga_fdc_t *fdc = get_safe_token(device);
256
257   ret = ( ( CUSTOM_REG(REG_DSKLEN) >> 1 ) & 0x4000 ) & ( ( CUSTOM_REG(REG_DMACON) << 10 ) & 0x4000 );
258   ret |= ( CUSTOM_REG(REG_DSKLEN) >> 1 ) & 0x2000;
259
260   for ( i = 0; i < NUM_DRIVES; i++ ) {
261      if ( !( fdc->fdc_sel & ( 1 << i ) ) )
262         drive = i;
263   }
264
265   if ( drive == -1 )
266      return ret;
267
268   if ( fdc->fdc_status[drive].disk_changed )
269      return ret;
270
271   setup_fdc_buffer( device,drive );
272
273   pos = fdc_get_curpos( device, drive );
274
275   if ( fdc->fdc_status[drive].mfm[pos] == ( CUSTOM_REG(REG_DSRSYNC) >> 8 ) &&
276       fdc->fdc_status[drive].mfm[pos+1] == ( CUSTOM_REG(REG_DSRSYNC) & 0xff ) )
277         ret |= 0x1000;
278
279   if ( pos != fdc->fdc_status[drive].pos ) {
280      ret |= 0x8000;
281      fdc->fdc_status[drive].pos = pos;
282   }
283
284   ret |= fdc->fdc_status[drive].mfm[pos];
285
286   return ret;
287}
288
289static TIMER_CALLBACK(fdc_sync_proc)
290{
291   amiga_state *state = machine.driver_data<amiga_state>();
292   int drive = param;
293   UINT16         sync = CUSTOM_REG(REG_DSRSYNC);
294   int            cur_pos;
295   int            sector;
296   int            time;
297   amiga_fdc_t *fdc = get_safe_token((device_t*)ptr);
298
299   /* if floppy got ejected, stop */
300   if ( fdc->fdc_status[drive].disk_changed )
301      goto bail;
302
303   if ( fdc->fdc_status[drive].motor_on == 0 )
304      goto bail;
305
306   cur_pos = fdc_get_curpos( (device_t*)ptr, drive );
307
308   if ( cur_pos <= ( GAP_TRACK_BYTES + 6 ) )
309   {
310      sector = 0;
311   }
312   else
313   {
314      sector = ( cur_pos - ( GAP_TRACK_BYTES + 6 ) ) / ONE_SECTOR_BYTES;
315   }
316
317   setup_fdc_buffer( (device_t*)ptr, drive );
318
319   if ( cur_pos < 2 )
320      cur_pos = 2;
321
322   if ( fdc->fdc_status[drive].mfm[cur_pos-2] == ( ( sync >> 8 ) & 0xff ) &&
323       fdc->fdc_status[drive].mfm[cur_pos-1] == ( sync & 0xff ) )
324   {
325      address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
326
327      amiga_custom_w(space, REG_INTREQ, 0x8000 | INTENA_DSKSYN, 0xffff);
328   }
329
330   if ( sector < 10 )
331   {
332      /* start the sync timer */
333      time = ONE_SECTOR_BYTES;
334      time *= ( CUSTOM_REG(REG_ADKCON) & 0x0100 ) ? 2 : 4;
335      time *= 8;
336      fdc->fdc_status[drive].sync_timer->adjust(attotime::from_usec( time ), drive);
337      return;
338   }
339
340bail:
341   fdc->fdc_status[drive].sync_timer->reset(  );
342}
343
344static TIMER_CALLBACK(fdc_dma_proc)
345{
346   amiga_state *state = machine.driver_data<amiga_state>();
347   int drive = param;
348   amiga_fdc_t *fdc = get_safe_token((device_t*)ptr);
349
350   /* if DMA got disabled by the time we got here, stop operations */
351   if ( ( CUSTOM_REG(REG_DSKLEN) & 0x8000 ) == 0 )
352      goto bail;
353
354   if ( ( CUSTOM_REG(REG_DMACON) & 0x0210 ) == 0 )
355      goto bail;
356
357   /* if floppy got ejected, also stop */
358   if ( fdc->fdc_status[drive].disk_changed )
359      goto bail;
360
361   if ( fdc->fdc_status[drive].motor_on == 0 )
362      goto bail;
363
364   setup_fdc_buffer( (device_t*)ptr, drive );
365
366   if ( CUSTOM_REG(REG_DSKLEN) & 0x4000 ) /* disk write case, unsupported yet */
367   {
368      if ( fdc->fdc_status[drive].len > 0 )
369      {
370         address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
371
372         logerror("Write to disk unsupported yet\n" );
373
374         amiga_custom_w(space, REG_INTREQ, 0x8000 | INTENA_DSKBLK, 0xffff);
375      }
376   }
377   else
378   {
379      offs_t offset = fdc->fdc_status[drive].ptr;
380      int cur_pos = fdc->fdc_status[drive].pos;
381      int len = fdc->fdc_status[drive].len;
382
383      if ( len > MAX_WORDS_PER_DMA_CYCLE ) len = MAX_WORDS_PER_DMA_CYCLE;
384
385      fdc->fdc_status[drive].len -= len;
386
387      while ( len-- )
388      {
389         int dat = ( fdc->fdc_status[drive].mfm[cur_pos++] ) << 8;
390
391         cur_pos %= ( fdc->fdc_status[drive].tracklen );
392
393         dat |= fdc->fdc_status[drive].mfm[cur_pos++];
394
395         cur_pos %= ( fdc->fdc_status[drive].tracklen );
396
397         (*state->m_chip_ram_w)(state, offset, dat);
398
399         offset += 2;
400      }
401
402      fdc->fdc_status[drive].ptr = offset;
403      fdc->fdc_status[drive].pos = cur_pos;
404
405      if ( fdc->fdc_status[drive].len <= 0 )
406      {
407         address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
408
409         amiga_custom_w(space, REG_INTREQ, 0x8000 | INTENA_DSKBLK, 0xffff);
410      }
411      else
412      {
413         int time;
414         double   len_words = fdc->fdc_status[drive].len;
415         if ( len_words > MAX_WORDS_PER_DMA_CYCLE ) len_words = MAX_WORDS_PER_DMA_CYCLE;
416
417         time = len_words * 2;
418         time *= ( CUSTOM_REG(REG_ADKCON) & 0x0100 ) ? 2 : 4;
419         time *= 8;
420         fdc->fdc_status[drive].dma_timer->adjust(attotime::from_usec( time ), drive);
421         return;
422      }
423   }
424
425bail:
426   fdc->fdc_status[drive].dma_timer->reset(  );
427}
428
429void amiga_fdc_setup_dma( device_t *device ) {
430   amiga_state *state = device->machine().driver_data<amiga_state>();
431   int i, cur_pos, drive = -1, len_words = 0;
432   int time = 0;
433   amiga_fdc_t *fdc = get_safe_token(device);
434
435   for ( i = 0; i < NUM_DRIVES; i++ ) {
436      if ( !( fdc->fdc_sel & ( 1 << i ) ) )
437         drive = i;
438   }
439
440   if ( drive == -1 ) {
441      address_space *space = device->machine().device("maincpu")->memory().space(AS_PROGRAM);
442
443      logerror("Disk DMA started with no drive selected!\n" );
444      amiga_custom_w(space, REG_INTREQ, 0x8000 | INTENA_DSKBLK, 0xffff);
445      return;
446   }
447
448   if ( ( CUSTOM_REG(REG_DSKLEN) & 0x8000 ) == 0 )
449      goto bail;
450
451   if ( ( CUSTOM_REG(REG_DMACON) & 0x0210 ) == 0 )
452      goto bail;
453
454   if ( fdc->fdc_status[drive].disk_changed )
455      goto bail;
456
457   setup_fdc_buffer( device,drive );
458
459   fdc->fdc_status[drive].len = CUSTOM_REG(REG_DSKLEN) & 0x3fff;
460   fdc->fdc_status[drive].ptr = CUSTOM_REG_LONG(REG_DSKPTH);
461   fdc->fdc_status[drive].pos = cur_pos = fdc_get_curpos( device, drive );
462
463   /* we'll do a set amount at a time */
464   len_words = fdc->fdc_status[drive].len;
465   if ( len_words > MAX_WORDS_PER_DMA_CYCLE ) len_words = MAX_WORDS_PER_DMA_CYCLE;
466
467   if ( CUSTOM_REG(REG_ADKCON) & 0x0400 ) { /* Wait for sync */
468      if ( CUSTOM_REG(REG_DSRSYNC) != 0x4489 ) {
469         logerror("Attempting to read a non-standard SYNC\n" );
470      }
471
472      i = cur_pos;
473      do {
474         if ( fdc->fdc_status[drive].mfm[i] == ( CUSTOM_REG(REG_DSRSYNC) >> 8 ) &&
475             fdc->fdc_status[drive].mfm[i+1] == ( CUSTOM_REG(REG_DSRSYNC) & 0xff ) )
476               break;
477
478         i++;
479         i %= ( fdc->fdc_status[drive].tracklen );
480         time++;
481      } while( i != cur_pos );
482
483      if ( i == cur_pos && time != 0 ) {
484         logerror("SYNC not found on track!\n" );
485         return;
486      } else {
487         fdc->fdc_status[drive].pos = i + 2;
488         time += 2;
489      }
490   }
491
492   time += len_words * 2;
493   time *= ( CUSTOM_REG(REG_ADKCON) & 0x0100 ) ? 2 : 4;
494   time *= 8;
495   fdc->fdc_status[drive].dma_timer->adjust(attotime::from_usec( time ), drive);
496
497   return;
498
499bail:
500   fdc->fdc_status[drive].dma_timer->reset(  );
501}
502
503static void setup_fdc_buffer( device_t *device,int drive )
504{
505   int      sector, offset, len;
506   UINT8   temp_cyl[512*11];
507   amiga_fdc_t *fdc = get_safe_token(device);
508
509   /* no disk in drive */
510   if ( fdc->fdc_status[drive].f == NULL ) {
511      memset( &fdc->fdc_status[drive].mfm[0], 0xaa, 32 );
512      fdc->fdc_status[drive].disk_changed = DISK_DETECT_DELAY;
513      return;
514   }
515
516   len = 512*11;
517
518   offset = ( fdc->fdc_status[drive].cyl << 1 ) | fdc->fdc_side;
519
520   if ( fdc->fdc_status[drive].cached == offset )
521      return;
522
523#if 0
524   popmessage("T:%d S:%d", fdc->fdc_status[drive].cyl, fdc_side );
525#endif
526
527   if ( fdc->fdc_status[drive].is_ext_image )
528   {
529      len = fdc->fdc_status[drive].extinfo[offset] & 0xffff;
530
531      if ( len > ( MAX_MFM_TRACK_LEN - 2 ) )
532         len = MAX_MFM_TRACK_LEN - 2;
533
534      if ( fdc->fdc_status[drive].f->fseek( fdc->fdc_status[drive].extoffs[offset], SEEK_SET ) )
535      {
536         logerror("FDC: image_fseek failed!\n" );
537         fdc->fdc_status[drive].f = NULL;
538         fdc->fdc_status[drive].disk_changed = DISK_DETECT_DELAY;
539         return;
540      }
541
542      /* if SYNC is 0000, then its a regular amiga dos track image */
543      if ( ( fdc->fdc_status[drive].extinfo[offset] >> 16 ) == 0x0000 )
544      {
545         fdc->fdc_status[drive].f->fread( temp_cyl, len );
546         /* fall through to regular load */
547      }
548      else /* otherwise, it's a raw track */
549      {
550         fdc->fdc_status[drive].mfm[0] = ( fdc->fdc_status[drive].extinfo[offset] >> 24 ) & 0xff;
551         fdc->fdc_status[drive].mfm[1] = ( fdc->fdc_status[drive].extinfo[offset] >> 16 ) & 0xff;
552         fdc->fdc_status[drive].f->fread( &fdc->fdc_status[drive].mfm[2], len );
553         fdc->fdc_status[drive].tracklen = len + 2;
554         fdc->fdc_status[drive].cached = offset;
555         return;
556      }
557   }
558   else
559   {
560      if ( fdc->fdc_status[drive].f->fseek( offset * len, SEEK_SET ) )
561      {
562         logerror("FDC: image_fseek failed!\n" );
563         fdc->fdc_status[drive].f = NULL;
564         fdc->fdc_status[drive].disk_changed = DISK_DETECT_DELAY;
565         return;
566      }
567
568      fdc->fdc_status[drive].f->fread( temp_cyl, len );
569   }
570
571   fdc->fdc_status[drive].tracklen = MAX_TRACK_BYTES;
572
573   memset( &fdc->fdc_status[drive].mfm[ONE_SECTOR_BYTES*11], 0xaa, GAP_TRACK_BYTES );
574
575   for ( sector = 0; sector < 11; sector++ ) {
576      int x;
577       UINT8 *dest = ( &fdc->fdc_status[drive].mfm[(ONE_SECTOR_BYTES*sector)] );
578       UINT8 *src = &temp_cyl[sector*512];
579      UINT32 tmp;
580      UINT32 even, odd;
581      UINT32 hck = 0, dck = 0;
582
583      /* Preamble and sync */
584      *(dest + 0) = 0xaa;
585      *(dest + 1) = 0xaa;
586      *(dest + 2) = 0xaa;
587      *(dest + 3) = 0xaa;
588      *(dest + 4) = 0x44;
589      *(dest + 5) = 0x89;
590      *(dest + 6) = 0x44;
591      *(dest + 7) = 0x89;
592
593      /* Track and sector info */
594
595      tmp = 0xff000000 | (offset<<16) | (sector<<8) | (11 - sector);
596      odd = (tmp & 0x55555555) | 0xaaaaaaaa;
597      even = ( ( tmp >> 1 ) & 0x55555555 ) | 0xaaaaaaaa;
598      *(dest +  8) = (UINT8) ((even & 0xff000000)>>24);
599      *(dest +  9) = (UINT8) ((even & 0xff0000)>>16);
600      *(dest + 10) = (UINT8) ((even & 0xff00)>>8);
601      *(dest + 11) = (UINT8) ((even & 0xff));
602      *(dest + 12) = (UINT8) ((odd & 0xff000000)>>24);
603      *(dest + 13) = (UINT8) ((odd & 0xff0000)>>16);
604      *(dest + 14) = (UINT8) ((odd & 0xff00)>>8);
605      *(dest + 15) = (UINT8) ((odd & 0xff));
606
607      /* Fill unused space */
608
609      for (x = 16 ; x < 48; x++)
610         *(dest + x) = 0xaa;
611
612      /* Encode data section of sector */
613
614      for (x = 64 ; x < 576; x++)
615      {
616         tmp = *(src + x - 64);
617         odd = (tmp & 0x55);
618         even = (tmp>>1) & 0x55;
619         *(dest + x) = (UINT8) (even | 0xaa);
620         *(dest + x + 512) = (UINT8) (odd | 0xaa);
621      }
622
623      /* Calculate checksum for unused space */
624
625      for(x = 8; x < 48; x += 4)
626          hck ^= (((UINT32) *(dest + x))<<24) | (((UINT32) *(dest + x + 1))<<16) |
627                (((UINT32) *(dest + x + 2))<<8) | ((UINT32) *(dest + x + 3));
628
629      even = odd = hck;
630      odd >>= 1;
631      even |= 0xaaaaaaaa;
632      odd |= 0xaaaaaaaa;
633
634      *(dest + 48) = (UINT8) ((odd & 0xff000000)>>24);
635      *(dest + 49) = (UINT8) ((odd & 0xff0000)>>16);
636      *(dest + 50) = (UINT8) ((odd & 0xff00)>>8);
637      *(dest + 51) = (UINT8) (odd & 0xff);
638      *(dest + 52) = (UINT8) ((even & 0xff000000)>>24);
639      *(dest + 53) = (UINT8) ((even & 0xff0000)>>16);
640      *(dest + 54) = (UINT8) ((even & 0xff00)>>8);
641      *(dest + 55) = (UINT8) (even & 0xff);
642
643      /* Calculate checksum for data section */
644
645      for(x = 64; x < 1088; x += 4)
646         dck ^= (((UINT32) *(dest + x))<<24) | (((UINT32) *(dest + x + 1))<<16) |
647               (((UINT32) *(dest + x + 2))<< 8) |  ((UINT32) *(dest + x + 3));
648      even = odd = dck;
649      odd >>= 1;
650      even |= 0xaaaaaaaa;
651      odd |= 0xaaaaaaaa;
652      *(dest + 56) = (UINT8) ((odd & 0xff000000)>>24);
653      *(dest + 57) = (UINT8) ((odd & 0xff0000)>>16);
654      *(dest + 58) = (UINT8) ((odd & 0xff00)>>8);
655      *(dest + 59) = (UINT8) (odd & 0xff);
656      *(dest + 60) = (UINT8) ((even & 0xff000000)>>24);
657      *(dest + 61) = (UINT8) ((even & 0xff0000)>>16);
658      *(dest + 62) = (UINT8) ((even & 0xff00)>>8);
659      *(dest + 63) = (UINT8) (even & 0xff);
660   }
661
662   // update MFM data with proper CLK signal
663   int lastbit= 0;
664   for(int i=0;i<MAX_TRACK_BYTES ;i++)
665   {
666      UINT8 c=fdc->fdc_status[drive].mfm[i];
667      UINT8 dat = 0;
668      for(int j=0;j<8;j=j+2)
669      {
670         UINT8 c1=(c>>(6-j))&0x3;
671         if(c1&0x1)
672         {
673            dat |= (0x01<<(6-j));
674            lastbit=1;
675         }
676         else
677         {
678            if(lastbit==0 && (c1&0x2))
679            {
680               dat |= (0x02<<(6-j));
681            }
682            else
683            {
684               dat |= (0x00<<(6-j));
685            }
686            lastbit=0;
687         }
688      }
689      fdc->fdc_status[drive].mfm[i] = dat;
690   }
691   fdc->fdc_status[drive].cached = offset;
692}
693
694static TIMER_CALLBACK(fdc_rev_proc)
695{
696   amiga_state *state = machine.driver_data<amiga_state>();
697   int drive = param;
698   int time;
699   device_t *cia;
700   amiga_fdc_t *fdc = get_safe_token((device_t*)ptr);
701
702   /* Issue a index pulse when a disk revolution completes */
703   cia = machine.device("cia_1");
704   mos6526_flag_w(cia, 0);
705   mos6526_flag_w(cia, 1);
706
707   fdc->fdc_status[drive].rev_timer->adjust(attotime::from_msec( ONE_REV_TIME ), drive);
708   fdc->fdc_status[drive].rev_timer_started = 1;
709
710   if ( fdc->fdc_status[drive].is_ext_image == 0 )
711   {
712      /* also start the sync timer */
713      time = GAP_TRACK_BYTES + 6;
714      time *= ( CUSTOM_REG(REG_ADKCON) & 0x0100 ) ? 2 : 4;
715      time *= 8;
716      fdc->fdc_status[drive].sync_timer->adjust(attotime::from_usec( time ), drive);
717   }
718}
719
720static void start_rev_timer( device_t *device,int drive ) {
721//  double time;
722   amiga_fdc_t *fdc = get_safe_token(device);
723
724   if ( fdc->fdc_status[drive].rev_timer_started ) {
725      logerror("Revolution timer started twice?!\n" );
726      return;
727   }
728
729   fdc->fdc_status[drive].rev_timer->adjust(attotime::from_msec( ONE_REV_TIME ), drive);
730   fdc->fdc_status[drive].rev_timer_started = 1;
731}
732
733static void stop_rev_timer( device_t *device,int drive ) {
734   amiga_fdc_t *fdc = get_safe_token(device);
735
736   if ( fdc->fdc_status[drive].rev_timer_started == 0 ) {
737      logerror("Revolution timer never started?!\n" );
738      return;
739   }
740
741   fdc->fdc_status[drive].rev_timer->reset(  );
742   fdc->fdc_status[drive].rev_timer_started = 0;
743   fdc->fdc_status[drive].dma_timer->reset(  );
744   fdc->fdc_status[drive].sync_timer->reset(  );
745}
746
747static void fdc_setup_leds(device_t *device, int drive ) {
748
749   char portname[12];
750   amiga_fdc_t *fdc = get_safe_token(device);
751   sprintf(portname, "drive_%d_led", drive);
752   output_set_value(portname, fdc->fdc_status[drive].motor_on == 0 ? 0 : 1);
753
754   if ( drive == 0 )
755      set_led_status(device->machine(), 1, fdc->fdc_status[drive].motor_on ); /* update internal drive led */
756
757   if ( drive == 1 )
758      set_led_status(device->machine(), 2, fdc->fdc_status[drive].motor_on ); /* update external drive led */
759}
760
761static void fdc_stepdrive( device_t *device,int drive ) {
762   amiga_fdc_t *fdc = get_safe_token(device);
763
764   if ( fdc->fdc_dir ) {
765      if ( fdc->fdc_status[drive].cyl )
766         fdc->fdc_status[drive].cyl--;
767   } else {
768      if ( fdc->fdc_status[drive].cyl < 79 )
769         fdc->fdc_status[drive].cyl++;
770   }
771
772   /* Update disk detection if applicable */
773   if ( fdc->fdc_status[drive].f != NULL )
774   {
775      if ( fdc->fdc_status[drive].disk_changed > 0 )
776         fdc->fdc_status[drive].disk_changed--;
777   }
778}
779
780static void fdc_motor( device_t *device,int drive, int off ) {
781   amiga_fdc_t *fdc = get_safe_token(device);
782   int on = !off;
783
784   if ( ( fdc->fdc_status[drive].motor_on == 0 ) && on ) {
785      fdc->fdc_status[drive].pos = 0;
786
787      start_rev_timer( device,drive );
788
789   } else {
790      if ( fdc->fdc_status[drive].motor_on && off )
791         stop_rev_timer(device, drive );
792   }
793
794   fdc->fdc_status[drive].motor_on = on;
795}
796
797WRITE8_DEVICE_HANDLER( amiga_fdc_control_w )
798{
799   int step_pulse;
800   int drive;
801
802   amiga_fdc_t *fdc = get_safe_token(device);
803
804   if ( fdc->fdc_sel != ( ( data >> 3 ) & 15 ) )
805      fdc->fdc_rdy = 0;
806
807   fdc->fdc_sel = ( data >> 3 ) & 15;
808    fdc->fdc_side = 1 - ( ( data >> 2 ) & 1 );
809   fdc->fdc_dir = ( data >> 1 ) & 1;
810
811   step_pulse = data & 1;
812
813    if ( fdc->fdc_step != step_pulse ) {
814      fdc->fdc_step = step_pulse;
815
816       if ( fdc->fdc_step == 0 ) {
817          for ( drive = 0; drive < NUM_DRIVES; drive++ ) {
818            if ( !( fdc->fdc_sel & ( 1 << drive ) ) )
819                fdc_stepdrive( device, drive );
820         }
821      }
822   }
823
824   for ( drive = 0; drive < NUM_DRIVES; drive++ ) {
825      if ( !( fdc->fdc_sel & ( 1 << drive ) ) ) {
826         fdc_motor( device, drive, ( data >> 7 ) & 1 );
827         fdc_setup_leds( device,drive );
828      }
829    }
830}
831
832UINT8  amiga_fdc_status_r (device_t *device)
833{
834   int drive = -1, ret = 0x3c;
835   amiga_fdc_t *fdc = get_safe_token(device);
836   for ( drive = 0; drive < NUM_DRIVES; drive++ ) {
837      if ( !( fdc->fdc_sel & ( 1 << drive ) ) ) {
838
839         if ( fdc->fdc_status[drive].motor_on ) {
840            if ( fdc->fdc_rdy ) ret &= ~0x20;
841            fdc->fdc_rdy = 1;
842         } else {
843            /* return drive id */
844            ret &= ~0x20;
845         }
846
847         if ( fdc->fdc_status[drive].cyl == 0 )
848            ret &= ~0x10;
849
850         if ( fdc->fdc_status[drive].wprot )
851            ret &= ~0x08;
852
853         if ( fdc->fdc_status[drive].disk_changed )
854            ret &= ~0x04;
855
856         return ret;
857      }
858   }
859
860   return ret;
861}
862
863static const floppy_config amiga_floppy_config =
864{
865   DEVCB_NULL,
866   DEVCB_NULL,
867   DEVCB_NULL,
868   DEVCB_NULL,
869   DEVCB_NULL,
870   FLOPPY_STANDARD_3_5_DSHD,
871   FLOPPY_OPTIONS_NAME(amiga_only),
872   NULL
873};
874
875static MACHINE_CONFIG_FRAGMENT( amiga_fdc )
876   MCFG_FLOPPY_2_DRIVES_ADD(amiga_floppy_config)
877MACHINE_CONFIG_END
878
879
880DEVICE_GET_INFO( amiga_fdc )
881{
882   switch (state)
883   {
884      /* --- the following bits of info are returned as 64-bit signed integers --- */
885      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                                    break;
886      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(amiga_fdc_t);                        break;
887
888      /* --- the following bits of info are returned as pointers --- */
889      case DEVINFO_PTR_MACHINE_CONFIG:            info->machine_config = MACHINE_CONFIG_NAME(amiga_fdc);      break;
890
891      /* --- the following bits of info are returned as pointers to data or functions --- */
892      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(amiga_fdc);               break;
893      case DEVINFO_FCT_STOP:                     /* Nothing */                                    break;
894      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(amiga_fdc);               break;
895
896      /* --- the following bits of info are returned as NULL-terminated strings --- */
897      case DEVINFO_STR_NAME:                     strcpy(info->s, "Amiga FDC");                        break;
898      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "Amiga FDC");                        break;
899      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                              break;
900      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);                           break;
901      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright the MESS Team");             break;
902   }
903}
904
905DEFINE_LEGACY_DEVICE(AMIGA_FDC, amiga_fdc);
src/mame/machine/amigakbd.c
r0r11461
1/***************************************************************************
2
3    Amiga keyboard controller emulation
4
5***************************************************************************/
6
7
8#include "emu.h"
9#include "includes/amiga.h"
10#include "amigakbd.h"
11#include "machine/6526cia.h"
12
13
14#define KEYBOARD_BUFFER_SIZE   256
15
16typedef struct
17{
18   UINT8 *buf;
19   int buf_pos;
20   int cur_pos;
21   emu_timer *timer;
22} amigakbd_t;
23static amigakbd_t kbd;
24
25static void kbd_sendscancode( running_machine &machine, UINT8 scancode )
26{
27   int j;
28   device_t *cia = machine.device("cia_0");
29
30   /* send over to the cia A */
31   for( j = 0; j < 8; j++ )
32   {
33      mos6526_cnt_w( cia, 0 );   /* lower cnt */
34      mos6526_sp_w( cia, BIT(scancode << j, 7) ); /* set the serial data */
35      mos6526_cnt_w( cia, 1 );   /* raise cnt */
36   }
37}
38
39static TIMER_CALLBACK( kbd_update_callback )
40{
41   UINT8   scancode;
42
43   (void)param;
44
45   /* if we don't have pending data, bail */
46
47   if ( kbd.buf_pos == kbd.cur_pos )
48      return;
49
50   /* fetch the next scan code and send it to the Amiga */
51   scancode = kbd.buf[kbd.cur_pos++];
52   kbd.cur_pos %= KEYBOARD_BUFFER_SIZE;
53   kbd_sendscancode( machine, scancode );
54
55   /* if we still have more data, schedule another update */
56   if ( kbd.buf_pos != kbd.cur_pos )
57   {
58      kbd.timer->adjust(machine.primary_screen->frame_period() / 4);
59   }
60}
61
62static INPUT_CHANGED( kbd_update )
63{
64   int   index = (int)(FPTR)param, i;
65   UINT32   oldvalue = oldval * field->mask, newvalue = newval * field->mask;
66   UINT32   delta = oldvalue ^ newvalue;
67
68   /* Special case Page UP, which we will use as Action Replay button */
69   if ( (index == 3) && ( delta & 0x80000000 ) && ( newvalue & 0x80000000 ) )
70   {
71      const amiga_machine_interface *amiga_intf = amiga_get_interface(field->port->machine());
72
73      if ( amiga_intf != NULL && amiga_intf->nmi_callback )
74      {
75         (*amiga_intf->nmi_callback)(field->port->machine());
76      }
77   }
78   else
79   {
80      int key_buf_was_empty = ( kbd.buf_pos == kbd.cur_pos ) ? 1 : 0;
81
82      for( i = 0; i < 32; i++ )
83      {
84         if ( delta & ( 1 << i ) )
85         {
86            int down = ( newvalue & ( 1 << i ) ) ? 0 : 1;
87            int scancode = ( ( (index*32)+i ) << 1 ) | down;
88            int amigacode = ~scancode;
89
90            /* add the keycode to the buffer */
91            kbd.buf[kbd.buf_pos++] = amigacode & 0xff;
92            kbd.buf_pos %= KEYBOARD_BUFFER_SIZE;
93         }
94      }
95
96      /* if the buffer was empty and we have new data, start a timer to send the keystrokes */
97      if ( key_buf_was_empty && ( kbd.buf_pos != kbd.cur_pos ) )
98      {
99         kbd.timer->adjust(field->port->machine().primary_screen->frame_period() / 4);
100      }
101   }
102}
103
104void amigakbd_init( running_machine &machine )
105{
106   /* allocate a keyboard buffer */
107   kbd.buf = auto_alloc_array(machine, UINT8, KEYBOARD_BUFFER_SIZE);
108   kbd.buf_pos = 0;
109   kbd.cur_pos = 0;
110   kbd.timer = machine.scheduler().timer_alloc(FUNC(kbd_update_callback));
111   kbd.timer->reset();
112}
113
114/*********************************************************************************************/
115
116/* Layout is for the US A500 keyboard */
117
118INPUT_PORTS_START( amiga_us_keyboard )
119   PORT_START("amiga_keyboard_0")
120   PORT_BIT( 0x00000001, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_TILDE) PORT_CHAR('`') PORT_CHAR('~')      // 00
121   PORT_BIT( 0x00000002, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')         // 01
122   PORT_BIT( 0x00000004, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('@')         // 02
123   PORT_BIT( 0x00000008, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')         // 03
124   PORT_BIT( 0x00000010, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')         // 04
125   PORT_BIT( 0x00000020, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')         // 05
126   PORT_BIT( 0x00000040, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('^')         // 06
127   PORT_BIT( 0x00000080, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('&')         // 07
128   PORT_BIT( 0x00000100, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_CHAR('*')         // 08
129   PORT_BIT( 0x00000200, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_9) PORT_CHAR('9') PORT_CHAR('(')         // 09
130   PORT_BIT( 0x00000400, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_0) PORT_CHAR('0') PORT_CHAR(')')         // 0A
131   PORT_BIT( 0x00000800, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_MINUS) PORT_CHAR('-') PORT_CHAR('_')      // 0B
132   PORT_BIT( 0x00001000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_EQUALS) PORT_CHAR('=') PORT_CHAR('+')      // 0C
133   PORT_BIT( 0x00002000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_BACKSLASH2) PORT_CHAR('\\') PORT_CHAR('\xA6')   // 0D
134   PORT_BIT( 0x00004000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 0)                           // 0E
135   PORT_BIT( 0x00008000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_0_PAD) PORT_CHAR(UCHAR_MAMEKEY(0_PAD))   // 0F
136   PORT_BIT( 0x00010000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_Q) PORT_CHAR('q') PORT_CHAR('Q')         // 10
137   PORT_BIT( 0x00020000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_W) PORT_CHAR('w') PORT_CHAR('W')         // 11
138   PORT_BIT( 0x00040000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_E) PORT_CHAR('e') PORT_CHAR('E')         // 12
139   PORT_BIT( 0x00080000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_R) PORT_CHAR('r') PORT_CHAR('R')         // 13
140   PORT_BIT( 0x00100000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_T) PORT_CHAR('t') PORT_CHAR('T')         // 14
141   PORT_BIT( 0x00200000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_Y) PORT_CHAR('y') PORT_CHAR('Y')         // 15
142   PORT_BIT( 0x00400000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_U) PORT_CHAR('u') PORT_CHAR('U')         // 16
143   PORT_BIT( 0x00800000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_I) PORT_CHAR('i') PORT_CHAR('I')         // 17
144   PORT_BIT( 0x01000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_O) PORT_CHAR('o') PORT_CHAR('O')         // 18
145   PORT_BIT( 0x02000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_P) PORT_CHAR('p') PORT_CHAR('P')         // 19
146   PORT_BIT( 0x04000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_OPENBRACE) PORT_CHAR('[') PORT_CHAR('{')   // 1A
147   PORT_BIT( 0x08000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_CLOSEBRACE) PORT_CHAR(']') PORT_CHAR('}')   // 1B
148   PORT_BIT( 0x10000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 0)                           // 1C
149   PORT_BIT( 0x20000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_1_PAD) PORT_CHAR(UCHAR_MAMEKEY(1_PAD))   // 1D
150   PORT_BIT( 0x40000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_2_PAD) PORT_CHAR(UCHAR_MAMEKEY(2_PAD))   // 1E
151   PORT_BIT( 0x80000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_3_PAD) PORT_CHAR(UCHAR_MAMEKEY(3_PAD))   // 1F
152
153   PORT_START("amiga_keyboard_1")
154   PORT_BIT( 0x00000001, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_A) PORT_CHAR('a') PORT_CHAR('A')         // 20
155   PORT_BIT( 0x00000002, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_S) PORT_CHAR('s') PORT_CHAR('S')         // 21
156   PORT_BIT( 0x00000004, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_D) PORT_CHAR('d') PORT_CHAR('D')         // 22
157   PORT_BIT( 0x00000008, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_F) PORT_CHAR('f') PORT_CHAR('F')         // 23
158   PORT_BIT( 0x00000010, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_G) PORT_CHAR('g') PORT_CHAR('G')         // 24
159   PORT_BIT( 0x00000020, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_H) PORT_CHAR('h') PORT_CHAR('H')         // 25
160   PORT_BIT( 0x00000040, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_J) PORT_CHAR('j') PORT_CHAR('J')         // 26
161   PORT_BIT( 0x00000080, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_K) PORT_CHAR('k') PORT_CHAR('K')         // 27
162   PORT_BIT( 0x00000100, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_L) PORT_CHAR('l') PORT_CHAR('L')         // 28
163   PORT_BIT( 0x00000200, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_COLON) PORT_CHAR(';') PORT_CHAR(':')      // 29
164   PORT_BIT( 0x00000400, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR('\'') PORT_CHAR('"')      // 2A
165   PORT_BIT( 0x00000800, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 1)                           // 2B
166   PORT_BIT( 0x00001000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 1)                           // 2C
167   PORT_BIT( 0x00002000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_4_PAD) PORT_CHAR(UCHAR_MAMEKEY(4_PAD))   // 2D
168   PORT_BIT( 0x00004000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_5_PAD) PORT_CHAR(UCHAR_MAMEKEY(5_PAD))   // 2E
169   PORT_BIT( 0x00008000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_6_PAD) PORT_CHAR(UCHAR_MAMEKEY(6_PAD))   // 2F
170   PORT_BIT( 0x00010000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 1)                           // 30
171   PORT_BIT( 0x00020000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_Z) PORT_CHAR('z') PORT_CHAR('Z')         // 31
172   PORT_BIT( 0x00040000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_X) PORT_CHAR('x') PORT_CHAR('X')         // 32
173   PORT_BIT( 0x00080000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_C) PORT_CHAR('c') PORT_CHAR('C')         // 33
174   PORT_BIT( 0x00100000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_V) PORT_CHAR('v') PORT_CHAR('V')         // 34
175   PORT_BIT( 0x00200000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_B) PORT_CHAR('b') PORT_CHAR('B')         // 35
176   PORT_BIT( 0x00400000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_N) PORT_CHAR('n') PORT_CHAR('N')         // 36
177   PORT_BIT( 0x00800000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_M) PORT_CHAR('m') PORT_CHAR('M')         // 37
178   PORT_BIT( 0x01000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_COMMA) PORT_CHAR(',') PORT_CHAR('<')      // 38
179   PORT_BIT( 0x02000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_STOP)    PORT_CHAR('.') PORT_CHAR('>')      // 39
180   PORT_BIT( 0x04000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_SLASH) PORT_CHAR('/') PORT_CHAR('?')      // 3A
181   PORT_BIT( 0x08000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 1)                           // 3B
182   PORT_BIT( 0x10000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_DEL_PAD) PORT_CHAR(UCHAR_MAMEKEY(DEL_PAD))// 3C
183   PORT_BIT( 0x20000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_7_PAD) PORT_CHAR(UCHAR_MAMEKEY(7_PAD))   // 3D
184   PORT_BIT( 0x40000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_8_PAD) PORT_CHAR(UCHAR_MAMEKEY(8_PAD))   // 3E
185   PORT_BIT( 0x80000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_9_PAD) PORT_CHAR(UCHAR_MAMEKEY(9_PAD))   // 3F
186
187   PORT_START("amiga_keyboard_2")
188   PORT_BIT( 0x00000001, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_SPACE) PORT_CHAR(' ')                  // 40
189   PORT_BIT( 0x00000002, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_BACKSPACE) PORT_CHAR(8)               // 41
190   PORT_BIT( 0x00000004, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_TAB) PORT_CHAR('\t')                  // 42
191   PORT_BIT( 0x00000008, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_ENTER_PAD) PORT_CHAR(UCHAR_MAMEKEY(ENTER_PAD))   // 43
192   PORT_BIT( 0x00000010, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)                  // 44
193   PORT_BIT( 0x00000020, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_ESC) PORT_CHAR(UCHAR_MAMEKEY(ESC))      // 45
194   PORT_BIT( 0x00000040, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_DEL) PORT_CHAR(UCHAR_MAMEKEY(DEL))      // 46
195   PORT_BIT( 0x00000080, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 2)                           // 47
196   PORT_BIT( 0x00000100, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 2)                           // 48
197   PORT_BIT( 0x00000200, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 2)                           // 49
198   PORT_BIT( 0x00000400, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_MINUS_PAD) PORT_CHAR(UCHAR_MAMEKEY(MINUS_PAD))   // 4A
199   PORT_BIT( 0x00000800, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 2)                           // 4B
200   PORT_BIT( 0x00001000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_UP) PORT_CHAR(UCHAR_MAMEKEY(UP))         // 4C
201   PORT_BIT( 0x00002000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_DOWN) PORT_CHAR(UCHAR_MAMEKEY(DOWN))      // 4D
202   PORT_BIT( 0x00004000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_RIGHT) PORT_CHAR(UCHAR_MAMEKEY(RIGHT))   // 4E
203   PORT_BIT( 0x00008000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_LEFT) PORT_CHAR(UCHAR_MAMEKEY(LEFT))      // 4F
204   PORT_BIT( 0x00010000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F1) PORT_CHAR(UCHAR_MAMEKEY(F1))         // 50
205   PORT_BIT( 0x00020000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F2) PORT_CHAR(UCHAR_MAMEKEY(F2))         // 51
206   PORT_BIT( 0x00040000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F3) PORT_CHAR(UCHAR_MAMEKEY(F3))         // 52
207   PORT_BIT( 0x00080000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F4) PORT_CHAR(UCHAR_MAMEKEY(F4))         // 53
208   PORT_BIT( 0x00100000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F5) PORT_CHAR(UCHAR_MAMEKEY(F5))         // 54
209   PORT_BIT( 0x00200000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F6) PORT_CHAR(UCHAR_MAMEKEY(F6))         // 55
210   PORT_BIT( 0x00400000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F7) PORT_CHAR(UCHAR_MAMEKEY(F7))         // 56
211   PORT_BIT( 0x00800000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F8) PORT_CHAR(UCHAR_MAMEKEY(F8))         // 57
212   PORT_BIT( 0x01000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F9) PORT_CHAR(UCHAR_MAMEKEY(F9))         // 58
213   PORT_BIT( 0x02000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F10) PORT_CHAR(UCHAR_MAMEKEY(F10))      // 59
214   PORT_BIT( 0x04000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 2)                           // 5A
215   PORT_BIT( 0x08000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 2)                           // 5B
216   PORT_BIT( 0x10000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_SLASH_PAD) PORT_CHAR(UCHAR_MAMEKEY(SLASH_PAD))   // 5C
217   PORT_BIT( 0x20000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_ASTERISK) PORT_CHAR(UCHAR_MAMEKEY(ASTERISK))   // 5D
218   PORT_BIT( 0x40000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_PLUS_PAD) PORT_CHAR(UCHAR_MAMEKEY(PLUS_PAD))   // 5E
219   PORT_BIT( 0x80000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_INSERT) PORT_CHAR(UCHAR_MAMEKEY(INSERT))   // 5F
220
221   PORT_START("amiga_keyboard_3")
222   PORT_BIT( 0x00000001, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3) PORT_NAME("Shift (Left)") PORT_CODE(KEYCODE_LSHIFT) PORT_CHAR(UCHAR_SHIFT_1)   // 60
223   PORT_BIT( 0x00000002, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3) PORT_NAME("Shift (Right)") PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)   // 61
224   PORT_BIT( 0x00000004, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3) PORT_NAME("Caps Lock") PORT_CODE(KEYCODE_CAPSLOCK)         // 62
225   PORT_BIT( 0x00000008, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3) PORT_NAME("Ctrl") PORT_CODE(KEYCODE_LCONTROL) PORT_CHAR(UCHAR_MAMEKEY(LCONTROL))// 63
226   PORT_BIT( 0x00000010, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3) PORT_NAME("Alt (Left)") PORT_CODE(KEYCODE_LALT) PORT_CHAR(UCHAR_MAMEKEY(LALT))   // 64
227   PORT_BIT( 0x00000020, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3) PORT_NAME("Alt (Right)") PORT_CODE(KEYCODE_RALT) PORT_CHAR(UCHAR_MAMEKEY(RALT))   // 65
228   PORT_BIT( 0x00000040, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3) PORT_NAME("Amiga A (Left)") PORT_CODE(KEYCODE_LWIN)            // 66
229   PORT_BIT( 0x00000080, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3) PORT_NAME("Amiga A (Right)")  PORT_CODE(KEYCODE_RWIN)         // 67
230   PORT_BIT( 0x00000100, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 68
231   PORT_BIT( 0x00000200, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 69
232   PORT_BIT( 0x00000400, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 6A
233   PORT_BIT( 0x00000800, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 6B
234   PORT_BIT( 0x00001000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 6C
235   PORT_BIT( 0x00002000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 6D
236   PORT_BIT( 0x00004000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 6E
237   PORT_BIT( 0x00008000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 6F
238   PORT_BIT( 0x00010000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 70
239   PORT_BIT( 0x00020000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 71
240   PORT_BIT( 0x00040000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 72
241   PORT_BIT( 0x00080000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 73
242   PORT_BIT( 0x00100000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 74
243   PORT_BIT( 0x00200000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 75
244   PORT_BIT( 0x00400000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 76
245   PORT_BIT( 0x00800000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 77
246   PORT_BIT( 0x01000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 78
247   PORT_BIT( 0x02000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 79
248   PORT_BIT( 0x04000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 7A
249   PORT_BIT( 0x08000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 7B
250   PORT_BIT( 0x10000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 7C
251   PORT_BIT( 0x20000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 7D
252   PORT_BIT( 0x40000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 7E
253   PORT_BIT( 0x80000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3)   PORT_CODE(KEYCODE_PGUP)         // 7F NMI button
254INPUT_PORTS_END
src/mame/machine/amigafdc.h
r0r11461
1#ifndef AMIGAFDC_H
2#define AMIGAFDC_H
3
4WRITE8_DEVICE_HANDLER( amiga_fdc_control_w );
5UINT8  amiga_fdc_status_r (device_t *device);
6UINT16 amiga_fdc_get_byte (device_t *device);
7void amiga_fdc_setup_dma( device_t *device );
8
9/***************************************************************************
10    MACROS
11***************************************************************************/
12
13DECLARE_LEGACY_DEVICE(AMIGA_FDC, amiga_fdc);
14
15#define MCFG_AMIGA_FDC_ADD(_tag)   \
16   MCFG_DEVICE_ADD((_tag),  AMIGA_FDC, 0)
17
18#endif /* AMIGAFDC_H */
src/mame/machine/amigakbd.h
r0r11461
1#ifndef AMIGAKBD_H
2#define AMIGAKBD_H
3
4void amigakbd_init( running_machine &machine );
5
6INPUT_PORTS_EXTERN( amiga_us_keyboard );
7
8#endif /* AMIGAKBD_H */
src/mame/machine/amigacrt.c
r0r11461
1/***************************************************************************
2
3    Amiga cartridge emulation
4
5TODO:
6- Investigate why the AR2/3 sometimes garble the video on exit from the cart
7- Add Nordic Power and similar carts
8- Add HRTMon A1200 cart
9
10***************************************************************************/
11
12
13#include "emu.h"
14#include "includes/amiga.h"
15#include "cpu/m68000/m68000.h"
16#include "machine/6526cia.h"
17#include "machine/amigacrt.h"
18
19enum
20{
21   /* supported cartridges */
22   ACTION_REPLAY            =   0,
23   ACTION_REPLAY_MKII,
24   ACTION_REPLAY_MKIII
25};
26
27typedef struct
28{
29   int cart_type;
30   int ar1_spurious;
31   UINT16 ar23_mode;
32} amigacrt_t;
33static amigacrt_t amigacrt;
34
35/***************************************************************************
36
37  Utilities
38
39***************************************************************************/
40
41static int check_kickstart_12_13( running_machine &machine, const char *cart_name )
42{
43   UINT16 * ksmem = (UINT16 *)machine.region( "user1" )->base();
44
45   if ( ksmem[2] == 0x00FC )
46      return 1;
47
48   logerror( "%s requires Kickstart version 1.2 or 1.3 - Cart not installed\n", cart_name );
49
50   return 0;
51}
52
53/***************************************************************************
54
55  Amiga Action Replay 1
56
57  Whenever you push the button, an NMI interrupt is generated.
58
59  The cartridge protects itself from being removed from memory by
60  generating an interrupt whenever either the spurious interrupt
61  vector is written at $60, or the nmi interrupt vector is written at
62  $7c. If the spurious interrupt vector at $60 is written, then
63  a NMI is generated, and the spurious irq vector is restored. If the
64  NMI vector at $7c is written, then a spurious interrupt is generated,
65  and the NMI vector is restored.
66
67  When breakpoints are set, the target address is replaced by a trap
68  instruction, and the original contents of the address are kept in
69  the cartridge's RAM. A trap handler is installed pointing to $40
70  in RAM, where code that clears memory address $60 followed by two
71  nops are written. There seems to be a small delay between the write
72  to $60 and until the actual NMI is generated, since the cart expects
73  the PC to be at $46 (at the second nop).
74
75***************************************************************************/
76
77static IRQ_CALLBACK(amiga_ar1_irqack)
78{
79   if ( irqline == 7 && amigacrt.ar1_spurious )
80   {
81      return M68K_INT_ACK_SPURIOUS;
82   }
83
84   return (24+irqline);
85}
86
87static TIMER_CALLBACK( amiga_ar1_delayed_nmi )
88{
89   (void)param;
90   cputag_set_input_line(machine, "maincpu", 7, PULSE_LINE);
91}
92
93static void amiga_ar1_nmi( running_machine &machine )
94{
95   amiga_state *state = machine.driver_data<amiga_state>();
96   /* get the cart's built-in ram */
97   UINT16 *ar_ram = (UINT16 *)machine.device("maincpu")->memory().space(AS_PROGRAM)->get_write_ptr(0x9fc000);
98
99   if ( ar_ram != NULL )
100   {
101      int i;
102
103      /* copy custom register values */
104      for( i = 0; i < 256; i++ )
105         ar_ram[0x1800+i] = CUSTOM_REG(i);
106
107      /* trigger NMI irq */
108      amigacrt.ar1_spurious = 0;
109      machine.scheduler().timer_set(machine.device<cpu_device>("maincpu")->cycles_to_attotime(28), FUNC(amiga_ar1_delayed_nmi));
110   }
111}
112
113static WRITE16_HANDLER( amiga_ar1_chipmem_w )
114{
115   amiga_state *state = space->machine().driver_data<amiga_state>();
116   int pc = cpu_get_pc(&space->device());
117
118   /* see if we're inside the AR1 rom */
119   if ( ((pc >> 16) & 0xff ) != 0xf0 )
120   {
121      /* if we're not, see if either the Spurious IRQ vector
122           or the NMI vector are being overwritten */
123      if ( offset == (0x60/2) || offset == (0x7c/2) )
124      {
125         /* trigger an NMI or spurious irq */
126         amigacrt.ar1_spurious = (offset == 0x60/2) ? 0 : 1;
127         space->machine().scheduler().timer_set(space->machine().device<cpu_device>("maincpu")->cycles_to_attotime(28), FUNC(amiga_ar1_delayed_nmi));
128      }
129   }
130
131   (*state->m_chip_ram_w)(state,  offset * 2, data );
132}
133
134static void amiga_ar1_check_overlay( running_machine &machine )
135{
136   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x000000, 0x00007f, FUNC(amiga_ar1_chipmem_w));
137}
138
139static void amiga_ar1_init( running_machine &machine )
140{
141   void *ar_ram;
142
143   /* check kickstart version */
144   if ( !check_kickstart_12_13( machine, "Amiga Action Replay" ) )
145   {
146      amigacrt.cart_type = -1;
147      return;
148   }
149
150   /* setup the cart ram */
151   ar_ram = auto_alloc_array(machine, UINT8, 0x4000);
152   memset(ar_ram, 0, 0x4000);
153
154   /* Install ROM */
155   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xf00000, 0xf7ffff, "bank2");
156   machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xf00000, 0xf7ffff);
157
158   /* Install RAM */
159   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0x9fc000, 0x9fffff, "bank3");
160
161   /* Configure Banks */
162   memory_set_bankptr(machine, "bank2", machine.region("user2")->base());
163   memory_set_bankptr(machine, "bank3", ar_ram);
164
165   amigacrt.ar1_spurious = 0;
166
167   /* Install IRQ ACK callback */
168   device_set_irq_callback(machine.device("maincpu"), amiga_ar1_irqack);
169}
170
171/***************************************************************************
172
173  Amiga Action Replay MKII/MKIII
174
175  Whenever you push the button, an overlay of the cartridge appears
176  in RAM and an NMI interrupt is generated. Only reads are overlayed.
177  Writes go directly to chipmem (so that the CPU can write the stack
178  information for the NMI). Once the interrupt is taken, the cart
179  disables the ROM overlay and checks it's internal mode register
180  to see why it was invoked.
181
182  When a breakpoint is set the cart replaces the target instruction
183  with a trap, and adds a trap handler that it locates in the $100-$120
184  area. The handler simply has one instruction: TST.B $BFE001. This cia
185  access is monitored, and the conditions match (PC < 120 and a previous
186  command requested the monitoring of the cia) then the cart is invoked.
187
188***************************************************************************/
189
190static void amiga_ar23_freeze( running_machine &machine );
191
192static READ16_HANDLER( amiga_ar23_cia_r )
193{
194   int pc = cpu_get_pc(&space->device());
195
196   if ( ACCESSING_BITS_0_7 && offset == 2048 && pc >= 0x40 && pc < 0x120 )
197   {
198      amiga_ar23_freeze(space->machine());
199   }
200
201   return amiga_cia_r( space, offset, mem_mask );
202}
203
204static WRITE16_HANDLER( amiga_ar23_mode_w )
205{
206   if ( data & 2 )
207   {
208      space->install_legacy_read_handler(0xbfd000, 0xbfefff, FUNC(amiga_ar23_cia_r));
209   }
210   else
211   {
212      space->install_legacy_read_handler(0xbfd000, 0xbfefff, FUNC(amiga_cia_r));
213   }
214
215   amigacrt.ar23_mode = (data&0x3);
216   if ( amigacrt.ar23_mode == 0 )
217      amigacrt.ar23_mode = 1;
218
219}
220
221static READ16_HANDLER( amiga_ar23_mode_r )
222{
223   amiga_state *state = space->machine().driver_data<amiga_state>();
224   UINT16 *mem = (UINT16 *)space->machine().region( "user2" )->base();
225
226   if ( ACCESSING_BITS_0_7 )
227   {
228      if ( offset < 2 )
229         return (mem[offset] | (amigacrt.ar23_mode&3));
230
231      if ( offset == 0x03 ) /* disable cart oberlay on chip mem */
232      {
233         UINT32 mirror_mask = state->m_chip_ram_size;
234
235         memory_set_bank(space->machine(), "bank1", 0);
236
237         while( (mirror_mask<<1) < 0x100000 )
238         {
239            mirror_mask |= ( mirror_mask << 1 );
240         }
241
242         /* overlay disabled, map RAM on 0x000000 */
243         space->install_write_bank(0x000000, state->m_chip_ram_size - 1, 0, mirror_mask, "bank1");
244      }
245   }
246
247   return mem[offset];
248}
249
250static WRITE16_HANDLER( amiga_ar23_chipmem_w )
251{
252   amiga_state *state = space->machine().driver_data<amiga_state>();
253   if ( offset == (0x08/2) )
254   {
255      if ( amigacrt.ar23_mode & 1 )
256         amiga_ar23_freeze(space->machine());
257   }
258
259   (*state->m_chip_ram_w)(state,  offset * 2, data );
260}
261
262static void amiga_ar23_freeze( running_machine &machine )
263{
264   amiga_state *state = machine.driver_data<amiga_state>();
265   int pc = cpu_get_pc(machine.device("maincpu"));
266
267   /* only freeze if we're not inside the cart's ROM */
268   if ( ((pc >> 16) & 0xfe ) != 0x40 )
269   {
270      /* get the cart's built-in ram */
271      UINT16 *ar_ram = (UINT16 *)machine.device("maincpu")->memory().space(AS_PROGRAM)->get_write_ptr(0x440000);
272
273      if ( ar_ram != NULL )
274      {
275         int      i;
276
277         for( i = 0; i < 0x100; i++ )
278            ar_ram[0x7800+i] = CUSTOM_REG(i);
279      }
280
281      /* overlay the cart rom's in chipram */
282      memory_set_bank(machine, "bank1", 2);
283
284      /* writes go to chipram */
285      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x000000, state->m_chip_ram_size - 1, FUNC(amiga_ar23_chipmem_w));
286
287      /* trigger NMI irq */
288      cputag_set_input_line(machine, "maincpu", 7, PULSE_LINE);
289   }
290}
291
292static void amiga_ar23_nmi( running_machine &machine )
293{
294   amigacrt.ar23_mode = 0;
295   amiga_ar23_freeze(machine);
296}
297
298#if 0
299static WRITE16_HANDLER( amiga_ar23_custom_w )
300{
301   int pc = cpu_get_pc(&space->device());
302
303   /* see if we're inside the AR2 rom */
304   if ( ((pc >> 16) & 0xfe ) != 0x40 )
305   {
306      /* get the cart's built-in ram */
307      UINT16 *ar_ram = (UINT16 *)memory_get_write_ptr(0, AS_PROGRAM, 0x440000);
308
309      if ( ar_ram != NULL )
310      {
311         ar_ram[0x7800+offset] = data;
312      }
313   }
314
315   amiga_custom_w( offset, data, mem_mask );
316}
317
318static READ16_HANDLER( amiga_ar23_custom_r )
319{
320   UINT16 data = amiga_custom_r( offset, mem_mask );
321
322   int pc = cpu_get_pc(&space->device());
323
324   /* see if we're inside the AR2 rom */
325   if ( ((pc >> 16) & 0xfe ) != 0x40 )
326   {
327      /* get the cart's built-in ram */
328      UINT16 *ar_ram = (UINT16 *)memory_get_write_ptr(0, AS_PROGRAM, 0x440000);
329
330      if ( ar_ram != NULL )
331      {
332         ar_ram[0x7800+offset] = data;
333      }
334   }
335
336   return data;
337}
338#endif
339
340static void amiga_ar23_check_overlay( running_machine &machine )
341{
342   amigacrt.ar23_mode = 3;
343   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x000000, 0x00000f, FUNC(amiga_ar23_chipmem_w));
344}
345
346static void amiga_ar23_init( running_machine &machine, int ar3 )
347{
348   amiga_state *state = machine.driver_data<amiga_state>();
349   UINT32 mirror = 0x20000, size = 0x1ffff;
350   void *ar_ram;
351
352   /* check kickstart version */
353   if ( !check_kickstart_12_13( machine, "Action Replay MKII or MKIII" ) )
354   {
355      amigacrt.cart_type = -1;
356      return;
357   }
358
359   /* setup the cart ram */
360   ar_ram = auto_alloc_array_clear(machine, UINT8,0x10000);
361
362   if ( ar3 )
363   {
364      mirror = 0;
365      size = 0x3ffff;
366   }
367
368   /* Install ROM */
369   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x400000, 0x400000+size, 0, mirror, "bank2");
370   machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0x400000, 0x400000+size, 0, mirror);
371
372   /* Install RAM */
373   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x440000, 0x44ffff, "bank3");
374   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_write_bank(0x440000, 0x44ffff, "bank3");
375
376   /* Install Custom chip monitor */
377//  machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_read_handler(0xdff000, 0xdff1ff, FUNC(amiga_ar23_custom_r));
378//  machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0xdff000, 0xdff1ff, FUNC(amiga_ar23_custom_w));
379
380   /* Install status/mode handlers */
381   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_read_handler(0x400000, 0x400007, 0, mirror, FUNC(amiga_ar23_mode_r));
382   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x400000, 0x400003, 0, mirror, FUNC(amiga_ar23_mode_w));
383
384   /* Configure Banks */
385   memory_set_bankptr(machine, "bank2", machine.region("user2")->base());
386   memory_set_bankptr(machine, "bank3", ar_ram);
387
388   memory_configure_bank(machine, "bank1", 0, 2, state->m_chip_ram, 0);
389   memory_configure_bank(machine, "bank1", 1, 2, machine.region("user1")->base(), 0);
390   memory_configure_bank(machine, "bank1", 2, 2, machine.region("user2")->base(), 0);
391
392   amigacrt.ar23_mode = 3;
393}
394
395/***************************************************************************
396
397    MAME/MESS hooks
398
399***************************************************************************/
400
401void amiga_cart_init( running_machine &machine )
402{
403   /* see what is there */
404   UINT16 *mem = (UINT16 *)machine.region( "user2" )->base();
405
406   amigacrt.cart_type = -1;
407
408   if ( mem != NULL )
409   {
410      if ( mem[0x00] == 0x1111 )
411      {
412         amigacrt.cart_type = ACTION_REPLAY;
413         amiga_ar1_init(machine);
414      }
415      else if ( mem[0x0C] == 0x4D6B )
416      {
417         amigacrt.cart_type = ACTION_REPLAY_MKII;
418         amiga_ar23_init(machine, 0);
419      }
420      else if ( mem[0x0C] == 0x4D4B )
421      {
422         amigacrt.cart_type = ACTION_REPLAY_MKIII;
423         amiga_ar23_init(machine, 1);
424      }
425   }
426}
427
428void amiga_cart_check_overlay( running_machine &machine )
429{
430   if ( amigacrt.cart_type < 0 )
431      return;
432
433   switch( amigacrt.cart_type )
434   {
435      case ACTION_REPLAY:
436         amiga_ar1_check_overlay(machine);
437      break;
438
439      case ACTION_REPLAY_MKII:
440      case ACTION_REPLAY_MKIII:
441         amiga_ar23_check_overlay(machine);
442      break;
443   }
444}
445
446void amiga_cart_nmi( running_machine &machine )
447{
448   if ( amigacrt.cart_type < 0 )
449      return;
450
451   switch( amigacrt.cart_type )
452   {
453      case ACTION_REPLAY:
454         amiga_ar1_nmi(machine);
455      break;
456
457      case ACTION_REPLAY_MKII:
458      case ACTION_REPLAY_MKIII:
459         amiga_ar23_nmi(machine);
460      break;
461   }
462}
src/mame/machine/amigacrt.h
r0r11461
1#ifndef AMIGACRT_H
2#define AMIGACRT_H
3
4void amiga_cart_init( running_machine &machine );
5void amiga_cart_check_overlay( running_machine &machine );
6void amiga_cart_nmi( running_machine &machine );
7
8#endif /* AMIGACRT_H */
src/mame/machine/psxcddrv.c
r0r11461
1#include "emu.h"
2#include "includes/psx.h"
3#include "psxcd.h"
4#include "psxcddrv.h"
5
6//#define debug_mess_driver
7
8//
9//
10//
11
12static const unsigned int   num_pf_sectors=32, num_pf_buffers=16;
13
14//
15//
16//
17
18cdrom_driver::cdrom_driver()
19{
20   pf_head = 0;
21   pf_tail = 0;
22   num_pf = 0;
23   pf_head_sector = 0;
24   pf_status = NULL;
25   native_sector_size = raw_sector_size;
26   last_pf_status = NULL;
27   m_cd = NULL;
28   m_machine = NULL;
29
30//  printf("cdrom_driver base class init, pf_buffer size is %d\n", num_pf_sectors*num_pf_buffers*raw_sector_size);
31
32   pf_buffer=new unsigned char [num_pf_sectors*num_pf_buffers*raw_sector_size];
33
34   timestamp_frequency = 1;
35}
36
37cdrom_driver::~cdrom_driver()
38{
39   global_free(pf_buffer);
40}
41
42//
43//
44//
45
46void cdrom_driver::set_native_sector_size(const unsigned int sz)
47{
48   native_sector_size=sz;
49}
50
51//
52//
53//
54
55void cdrom_driver::cancel_io()
56{
57   if (pf_status)
58   {
59      pf_status->cancel();
60      pf_status->release();
61   }
62
63   pf_status=NULL;
64}
65
66//
67//
68//
69
70void cdrom_driver::prefetch_sector(const unsigned int sec)
71{
72   int numpfsec=num_pf*num_pf_sectors,
73         pfsec=sec-pf_head_sector;
74
75//  printf("prefetch_sector: %d\n", sec);
76
77   if ((pfsec<0) || (pfsec>numpfsec))
78   {
79      // Sector is not in prefetch buffer, abort current prefetch
80
81      if (pf_status)
82      {
83         pf_status->cancel();
84         pf_status->release();
85      }
86
87      // Reset the buffer and begin a new prefetch
88
89      pf_head=0;
90      pf_tail=0;
91      num_pf=1;
92      pf_head_sector=sec;
93
94      last_pf_status=NULL;
95      pf_status=read_sectors(sec, num_pf_sectors, pf_buffer);
96   }
97}
98
99//
100//
101//
102
103bool cdrom_driver::is_prefetch_sector_loaded(const unsigned int sec)
104{
105   int numpfsec=num_pf*num_pf_sectors,
106         pfsec=sec-pf_head_sector;
107
108   if ((pfsec<0) || (pfsec>=numpfsec))
109   {
110      // Requested sector is not in prefetch buffer, begin a new prefetch
111
112      prefetch_sector(sec);
113      pfsec=sec-pf_head_sector;
114      numpfsec=num_pf*num_pf_sectors;
115   }
116
117   int blk=pfsec/num_pf_sectors;
118
119   if (blk>0)
120   {
121      // Discard blocks below the prefetch point
122
123      pf_head=(pf_head+blk)%num_pf_buffers;
124      pf_head_sector+=num_pf_sectors*blk;
125      pfsec-=num_pf_sectors*blk;
126      num_pf-=blk;
127      blk=0;
128   }
129
130   bool comp=((! pf_status) || (pf_status->complete()));
131
132   if (! comp)
133   {
134      INT64 curtime=m_machine->device<cpu_device>("maincpu")->total_cycles();
135
136      if (last_pf_status!=pf_status)
137      {
138         last_pf_status=pf_status;
139         pf_timeout_begin=curtime;
140      }
141
142      INT64 timeout=curtime-pf_timeout_begin;
143      int timeout_sec=(int)(timeout/timestamp_frequency);
144      if (timeout_sec>20)
145      {
146         printf("cdrom: prefetch timed out, trying again...\n");
147         num_pf=0;
148         pf_head_sector=-1;
149         prefetch_sector(sec);
150         return is_prefetch_sector_loaded(sec);
151      }
152   }
153
154   if ((num_pf<num_pf_buffers) && (comp))
155   {
156      // The prefetch buffer is not full and we are not waiting on IO,
157      // prefetch the next block
158
159      pf_tail=(pf_tail+1)%num_pf_buffers;
160      num_pf++;
161
162      int nxtsec=pf_head_sector+((num_pf-1)*num_pf_sectors);
163      unsigned char *ptr=pf_buffer+((pf_tail*num_pf_sectors)*native_sector_size);
164
165      if (pf_status)
166      {
167         pf_status->release();
168         pf_status=last_pf_status=NULL;
169      }
170
171      pf_status=read_sectors(nxtsec, num_pf_sectors, ptr);
172   }
173
174   if (blk==(num_pf-1))
175   {
176      // The sector we want is in the last block in the prefetch buffer
177      // which might still be loading, check if the sector we want is loaded
178#if 0 // we do not load async in MESS
179      INT64 trans=pf_status->bytes_transferred();
180      unsigned int secmod=pfsec%num_pf_sectors,
181                         needbytes=(secmod+1)*native_sector_size;
182
183      if (trans<needbytes)
184      {
185         // The sector is not loaded yet
186
187         return false;
188      } else
189#endif
190      {
191         // The sector is loaded
192
193         return true;
194      }
195   } else
196   {
197      // The sector is not in the last block so it must be loaded
198
199      return true;
200   }
201}
202
203//
204//
205//
206
207unsigned char *cdrom_driver::get_prefetch_sector(const unsigned int sec, unsigned int *sz)
208{
209   int numpfsec=num_pf*num_pf_sectors,
210         pfsec=sec-pf_head_sector;
211   if ((pfsec>=0) && (pfsec<numpfsec))
212   {
213      int   blk=(pf_head+(pfsec/num_pf_sectors))%num_pf_buffers,
214            off=((blk*num_pf_sectors)+(pfsec%num_pf_sectors))*native_sector_size;
215      *sz=native_sector_size;
216      return pf_buffer+off;
217   } else
218   {
219      return NULL;
220   }
221}
222
223//
224//
225//
226
227bool cdrom_driver::read_sector(const unsigned int sec, unsigned char *buf, const bool block)
228{
229   bool loaded=is_prefetch_sector_loaded(sec);
230
231//  printf("read_sector: %d (loaded=%c)\n", sec, loaded ? 'Y' : 'N');
232
233   if ((! loaded) && (block))
234   {
235      pf_status->block_until_complete();
236      loaded=true;
237   }
238
239   if (loaded)
240   {
241      unsigned int secsz=0;
242      unsigned char *ptr=get_prefetch_sector(sec,&secsz);
243      assert(ptr);
244
245//      printf("got sector %d @ %p, size %d = %02x %02x | %02x %02x\n", sec, ptr, secsz, ptr[0], ptr[1], ptr[0x20], ptr[0x21]);
246
247      if (secsz<2352)
248      {
249         // Add sector header
250
251         buf[0]=0;
252         memset(buf+1,0xff,10);
253         buf[11]=0;
254         sector_to_msf(sec,buf+12);
255         buf[12]=decimal_to_bcd(buf[12]);
256         buf[13]=decimal_to_bcd(buf[13]);
257         buf[14]=decimal_to_bcd(buf[14]);
258         buf[15]=2;
259
260         if (secsz<2336)
261         {
262            memset(buf+16,0xff,8);
263         }
264      }
265
266      switch (secsz)
267      {
268         case 2048:
269            memcpy(buf+24,ptr,2048);
270            break;
271
272         case 2336:
273            memcpy(buf+16,ptr,2336);
274            break;
275
276         case 2352:
277            memcpy(buf,ptr,raw_sector_size);
278            break;
279      }
280
281      return true;
282   } else
283   {
284      return false;
285   }
286}
287
288void cdrom_driver::set_machine(const running_machine &machine)
289{
290   m_machine = (running_machine *)&machine;
291
292   timestamp_frequency = m_machine->device<cpu_device>("maincpu")->clock();
293
294//  printf("cdrom_driver::set_machine: timestamp frequency = %d\n", timestamp_frequency);
295}
296
297/*
298    MAME/MESS driver implementation
299*/
300
301class mess_cdrom_driver : public cdrom_driver
302{
303   enum track_type
304   {
305      track_illegal=-1,
306      track_mode1_2048=0,
307      track_mode2_2352,
308      track_mode2_2336,
309      track_audio
310   };
311
312   struct toc_entry
313   {
314      unsigned int type;
315      unsigned char address[3];
316   };
317
318   int num_sectors, num_tracks;
319   toc_entry toc[100];
320   int bin_sector_size;
321   const char *err;
322
323   io_status *read_sectors(const unsigned int startsec, const unsigned int numsec, unsigned char *buf);
324
325public:
326   mess_cdrom_driver();
327   ~mess_cdrom_driver();
328
329   bool is_usable(char *error_msg, const int msglen) const
330   {
331      return true;
332   }
333
334   bool read_toc();
335   unsigned int get_first_track() const;
336   unsigned int get_num_tracks() const;
337   bool get_track_address(const unsigned int track,unsigned char *address) const;
338   tracktype get_track_type(const unsigned int track) const;
339   unsigned int find_track(const unsigned int sector, unsigned int *start_sector, unsigned int *end_sector) const;
340   cdromtype get_type() const;
341};
342
343mess_cdrom_driver::mess_cdrom_driver()
344   : err(NULL)
345{
346   for (int i=0; i<100; i++)
347      toc[i].type=track_illegal;
348   num_tracks=0;
349   num_sectors=0;
350}
351
352//
353//
354//
355
356mess_cdrom_driver::~mess_cdrom_driver()
357{
358   cancel_io();
359}
360
361//
362//
363//
364
365bool mess_cdrom_driver::read_toc()
366{
367   if (m_cd)
368   {
369      const cdrom_toc *toc = cdrom_get_toc(m_cd);
370
371      num_tracks = cdrom_get_last_track(m_cd);
372
373      switch (toc->tracks[0].trktype)
374      {
375         case CD_TRACK_MODE1: bin_sector_size=2048; break;
376         case CD_TRACK_MODE2_FORM1: bin_sector_size=2048; break;
377         case CD_TRACK_MODE2: bin_sector_size=2336; break;
378         case CD_TRACK_MODE2_FORM_MIX: bin_sector_size=2336; break;
379         default: bin_sector_size=2352; break;
380      }
381
382      set_native_sector_size(bin_sector_size);
383      num_sectors = cdrom_get_track_start(m_cd, num_tracks) + toc->tracks[num_tracks].frames;
384
385//      printf("mess_cdrom_driver: %d sectors, native size %d\n",num_sectors, bin_sector_size);
386
387      return true;
388   }
389
390   return false;
391}
392
393//
394//
395//
396
397io_status *mess_cdrom_driver::read_sectors(const unsigned int startsec, const unsigned int numsec, unsigned char *buf)
398{
399   const cdrom_toc *toc = cdrom_get_toc(m_cd);
400   UINT32 track = cdrom_get_track(m_cd, startsec);
401   UINT32 secsize = toc->tracks[track].datasize;
402
403   #ifdef debug_mess_driver
404   printf("mess: read %d sectors from %d (secsize %d)\n",numsec,startsec,secsize);
405   #endif
406
407   if ((startsec>=0)) // && ((int)startsec<num_sectors))
408   {
409//      fin->seek((INT64)startsec*(INT64)bin_sector_size);
410
411//      io_status *ios=fin->async_read(buf,numsec*bin_sector_size);
412//      if (! ios)
413      for (int i = 0; i < numsec; i++)
414      {
415//          printf("[%d/%d] Reading to pf_buffer %p at offset %d, size %d\n", i, numsec, &buf[secsize*i], secsize*i, secsize);
416         cdrom_read_data(m_cd, startsec+i, &buf[secsize*i], CD_TRACK_RAW_DONTCARE);
417      }
418
419      return NULL;
420
421//      return ios;
422   }
423   else
424   {
425      printf("mess: read sector out of range (%d, max=%d)\n",
426                startsec,
427                num_sectors);
428
429      memset(buf,0xff,numsec*bin_sector_size);
430      return NULL;
431   }
432}
433
434//
435//
436//
437
438unsigned int mess_cdrom_driver::get_first_track() const
439{
440   return 1;
441}
442
443unsigned int mess_cdrom_driver::get_num_tracks() const
444{
445//  printf("get_num_tracks = %d\n", num_tracks);
446   return num_tracks;
447}
448
449bool mess_cdrom_driver::get_track_address(const unsigned int track, unsigned char *address) const
450{
451   if ((track>=1) && ((int)track<=num_tracks))
452   {
453      UINT32 trkstart = cdrom_get_track_start(m_cd, track);
454
455      sector_to_msf(trkstart, address);
456
457      address[0] = address[0];
458      address[1] = address[1];
459      address[2] = address[2];
460
461//      printf("get_track_address %d = %02x:%02x:%02x\n", track, address[0], address[1], address[2]);
462
463      return true;
464   }
465   else
466   {
467      address[0]=address[1]=address[2]=0;
468      return false;
469   }
470}
471
472unsigned int mess_cdrom_driver::find_track(const unsigned int sector, unsigned int *start_sector, unsigned int *end_sector) const
473{
474   const cdrom_toc *toc = cdrom_get_toc(m_cd);
475   UINT32 track = cdrom_get_track(m_cd, sector);
476   int start;
477
478   start = cdrom_get_track_start(m_cd, track);
479
480   if (start_sector != NULL)
481   {
482      *start_sector = start;
483   }
484
485   if (end_sector != NULL)
486   {
487      *end_sector = start + toc->tracks[track].frames;
488   }
489
490   printf("find_track: track %d start %d end %d\n", track, start, *end_sector);
491
492   return -1;
493}
494
495//
496//
497//
498
499cdromtype mess_cdrom_driver::get_type() const
500{
501//  printf("get_type\n");
502   return cdromtype_cd;
503}
504
505//
506//
507//
508
509tracktype mess_cdrom_driver::get_track_type(const unsigned int track) const
510{
511   const cdrom_toc *toc = cdrom_get_toc(m_cd);
512
513//  printf("get_track_type %d = %d\n", track, toc->tracks[track].trktype);
514
515   switch (toc->tracks[track].trktype)
516   {
517      case CD_TRACK_MODE1: return tracktype_mode1;
518      case CD_TRACK_MODE2_RAW: return tracktype_mode2;
519      case CD_TRACK_MODE2_FORM_MIX: return tracktype_mode2;
520      case CD_TRACK_AUDIO: return tracktype_audio;
521      default: return tracktype_unknown;
522   }
523}
524
525//
526//
527//
528
529cdrom_driver *open_mess_drv()
530{
531   return new mess_cdrom_driver();
532}
533
src/mame/machine/psxcddrv.h
r0r11461
1#ifndef _included_psxcddriver_
2#define _included_psxcddriver_
3
4const unsigned int raw_sector_size=2352;
5
6class io_status
7{
8protected:
9   virtual ~io_status() {}
10
11public:
12   io_status() { }
13
14   virtual void cancel()=0;
15   virtual void release()=0;
16   virtual bool complete() const=0;
17   virtual bool block_until_complete() const=0;
18   virtual INT64 bytes_transferred() const=0;
19};
20
21enum cdromtype
22{
23   cdromtype_cd=0,
24   cdromtype_dvd
25};
26
27enum tracktype
28{
29   tracktype_unknown=0,
30   tracktype_mode1,
31   tracktype_mode2,
32   tracktype_audio
33};
34
35class cdrom_driver
36{
37   int pf_head,
38         pf_tail,
39         num_pf,
40         pf_head_sector;
41   unsigned char *pf_buffer;
42   io_status *pf_status,
43                  *last_pf_status;
44   INT64 pf_timeout_begin;
45
46   int native_sector_size;
47
48   virtual io_status *read_sectors(const unsigned int sec, const unsigned int numsec, unsigned char *buf)=0;
49
50   bool is_prefetch_sector_loaded(const unsigned int pfsec);
51
52protected:
53   void cancel_io();
54   void set_native_sector_size(const unsigned int sz);
55   UINT32 timestamp_frequency;
56   cdrom_file   *m_cd;
57private:
58   running_machine *m_machine;
59
60public:
61   cdrom_driver();
62   virtual ~cdrom_driver();
63
64   void set_machine(const running_machine &machine);
65   void set_cdrom_file(cdrom_file *cdfile) { m_cd = cdfile; }
66
67   virtual bool is_usable(char *error_msg=NULL, const int msglen=0) const=0;
68   virtual bool read_toc()=0;
69
70   void prefetch_sector(const unsigned int sec);
71   bool read_sector(const unsigned int sec,
72                            unsigned char *buf,
73                            const bool block=true);
74   unsigned char *get_prefetch_sector(const unsigned int pfsec,
75                                                       unsigned int *sz);
76
77   virtual unsigned int get_first_track() const=0;
78   virtual unsigned int get_num_tracks() const=0;
79   virtual bool get_track_address(const unsigned int track,
80                                                 unsigned char *address) const=0;
81   virtual tracktype get_track_type(const unsigned int track) const=0;
82   virtual unsigned int find_track(const unsigned int sector,
83                                                   unsigned int *start_sector=NULL,
84                                                   unsigned int *end_sector=NULL) const=0;
85
86   virtual cdromtype get_type() const { return cdromtype_cd; }
87};
88
89//
90//
91//
92
93inline unsigned int msf_to_sector(const unsigned char *msf)
94{
95   unsigned int sec=msf[2]+(msf[1]*75)+(msf[0]*(60*75));
96   if (sec>=150)
97   {
98      return sec-150;
99   }
100   else
101   {
102      return 0;
103   }
104}
105
106inline void sector_to_msf(const unsigned int sec, unsigned char *msf)
107{
108   unsigned int s=sec+150;
109   msf[0]=s/(60*75);
110   s-=msf[0]*(60*75);
111   msf[1]=s/75;
112   s-=msf[1]*75;
113   msf[2]=s;
114}
115
116//
117//
118//
119
120inline unsigned char bcd_to_decimal(const unsigned char bcd)
121{
122   return ((bcd>>4)*10)+(bcd&0xf);
123}
124
125inline unsigned char decimal_to_bcd(const unsigned char dec)
126{
127   //assert(dec<100);
128   return ((dec/10)<<4)|(dec%10);
129}
130
131cdrom_driver *open_mess_drv();
132
133#endif
src/mame/machine/nes_pcb.c
r0r11461
1/*****************************************************************************************
2
3    NES Cart PCBs Emulation
4
5****************************************************************************************/
6
7typedef struct _nes_pcb  nes_pcb;
8struct _nes_pcb
9{
10   const char              *pcb_name;
11   int                     pcb_id;
12};
13
14// Here, we take the feature attribute from .xml (i.e. the PCB name) and we assign a unique ID to it
15static const nes_pcb pcb_list[] =
16{
17   /* Nintendo HROM, NROM, RROM, SROM & STROM */
18   { "HVC-HROM",         STD_NROM },
19   { "HVC-NROM",         STD_NROM },
20   { "HVC-NROM-128",     STD_NROM },
21   { "HVC-NROM-256",     STD_NROM },
22   { "HVC-RROM",         STD_NROM },
23   { "HVC-RROM-128",     STD_NROM },
24   { "HVC-RTROM",        STD_NROM },
25   { "HVC-SROM",         STD_NROM },
26   { "HVC-STROM",        STD_NROM },
27   { "NES-HROM",         STD_NROM },
28   { "NES-NROM",         STD_NROM },
29   { "NES-NROM-128",     STD_NROM },
30   { "NES-NROM-256",     STD_NROM },
31   { "NES-RROM",         STD_NROM },
32   { "NES-RROM-128",     STD_NROM },
33   { "NES-SROM",         STD_NROM },
34   { "NES-STROM",        STD_NROM },
35   /* "No mapper" boards by other manufacturer */
36   { "IREM-NROM-128",    STD_NROM },
37   { "IREM-NROM-256",    STD_NROM },
38   { "BANDAI-NROM-128",  STD_NROM },
39   { "BANDAI-NROM-256",  STD_NROM },
40   { "KONAMI-NROM-128",  STD_NROM },
41   { "SETA-NROM-128",    STD_NROM },
42   { "SUNSOFT-NROM-128", STD_NROM },
43   { "SUNSOFT-NROM-256", STD_NROM },
44   { "TAITO-NROM-128",   STD_NROM },
45   { "TAITO-NROM-256",   STD_NROM },
46   { "NAMCOT-3301",      STD_NROM },
47   { "NAMCOT-3302",      STD_NROM },
48   { "NAMCOT-3303",      STD_NROM },
49   { "NAMCOT-3304",      STD_NROM },
50   { "NAMCOT-3305",      STD_NROM },
51   { "NAMCOT-3311",      STD_NROM },
52   { "NAMCOT-3312",      STD_NROM },
53   { "NAMCOT-3411",      STD_NROM },
54   { "JALECO-JF-01",     STD_NROM },
55   { "JALECO-JF-02",     STD_NROM },
56   { "JALECO-JF-03",     STD_NROM },
57   { "JALECO-JF-04",     STD_NROM },
58   { "TENGEN-800003",    STD_NROM },
59   { "SACHEN-NROM",      STD_NROM },
60   /* Nintendo Family BASIC pcb (NROM + 2K or 4K WRAM) */
61   { "HVC-FAMILYBASIC",  HVC_FAMBASIC },
62   /* Game Genie */
63   { "CAMERICA-GAMEGENIE", GG_NROM },
64//
65   /* Nintendo UNROM/UOROM */
66   { "HVC-UNROM",        STD_UXROM },
67   { "HVC-UNEPROM",      STD_UXROM },
68   { "HVC-UOROM",        STD_UXROM },
69   { "NES-UNROM",        STD_UXROM },
70   { "NES-UNEPROM",      STD_UXROM },
71   { "NES-UOROM",        STD_UXROM },
72   { "HVC-UNROM+74HC08", UXROM_CC },
73   /* UxROM boards by other manufacturer */
74   { "IREM-UNROM",       STD_UXROM },
75   { "KONAMI-UNROM",     STD_UXROM },
76   { "TAITO-UNROM",      STD_UXROM },
77   { "JALECO-JF-15",     STD_UXROM },
78   { "JALECO-JF-18",     STD_UXROM },
79   { "JALECO-JF-39",     STD_UXROM },
80//
81   /* Nintendo CNROM */
82   { "HVC-CNROM",        STD_CNROM },
83   { "NES-CNROM",        STD_CNROM },
84   /* CxROM boards by other manufacturer */
85   { "BANDAI-CNROM",     STD_CNROM },
86   { "BANDAI-74*161/32", STD_CNROM },
87   { "KONAMI-CNROM",     STD_CNROM },
88   { "NAMCOT-CNROM+WRAM", STD_CNROM },
89   { "TAITO-CNROM",      STD_CNROM },
90   { "AVE-74*161",       STD_CNROM },
91   { "NTDEC-N715061",    STD_CNROM },
92   { "NTDEC-N715062",    STD_CNROM },
93   { "SACHEN-CNROM",     STD_CNROM },
94   /* Bandai Aerobics Studio (CNROM boards + special audio chip) */
95   { "BANDAI-PT-554",    BANDAI_PT554 },
96   /* FIXME: Is this the same as mapper 3? */
97   { "TENGEN-800008",    TENGEN_800008 },
98//
99   /* Nintendo AxROM */
100   { "HVC-AMROM",        STD_AXROM },
101   { "HVC-AN1ROM",       STD_AXROM },
102   { "HVC-ANROM",        STD_AXROM },
103   { "HVC-AOROM",        STD_AXROM },
104   { "NES-AMROM",        STD_AXROM },
105   { "NES-AN1ROM",       STD_AXROM },
106   { "NES-ANROM",        STD_AXROM },
107   { "NES-AOROM",        STD_AXROM },
108   /* AxROM boards by other manufacturer */
109   { "ACCLAIM-AOROM",    STD_AXROM },
110//
111   /* Nintendo PxROM */
112   { "HVC-PEEOROM",      STD_PXROM },
113   { "HVC-PNROM",        STD_PXROM },
114   { "NES-PEEOROM",      STD_PXROM },
115   { "NES-PNROM",        STD_PXROM },
116//
117   /* Nintendo FxROM */
118   { "HVC-FJROM",        STD_FXROM },
119   { "HVC-FKROM",        STD_FXROM },
120   { "NES-FJROM",        STD_FXROM },
121   { "NES-FKROM",        STD_FXROM },
122//
123   /* Nintendo BXROM */
124   { "HVC-BNROM",        STD_BXROM },
125   { "NES-BNROM",        STD_BXROM },
126   /* BxROM boards by other manufacturer */
127   { "IREM-BNROM",       STD_BXROM },
128//
129   /* Nintendo CPROM */
130   { "HVC-CPROM",        STD_CPROM },
131   { "NES-CPROM",        STD_CPROM },
132//
133   /* Nintendo GNROM & MHROM */
134   { "HVC-GNROM",        STD_GXROM },
135   { "NES-GNROM",        STD_GXROM },
136   { "HVC-MHROM",        STD_MXROM },
137   { "NES-MHROM",        STD_MXROM },
138   { "PAL-MH",           STD_MXROM },
139   /* GxROM boards by other manufacturer */
140   { "BANDAI-GNROM",     STD_GXROM },
141//
142   /* Nintendo NxROM */
143   { "HVC-NTBROM",       STD_NXROM },
144   { "NES-NTBROM",       STD_NXROM },
145   /* NxROM boards by other manufacturer (this board was mainly used by Sunsoft?) */
146   { "SUNSOFT-4",        STD_NXROM },
147   { "SUNSOFT-DCS",      SUNSOFT_DCS },
148   { "TENGEN-800042",    STD_NXROM },
149//
150   /* Nintendo JxROM */
151   { "HVC-JLROM",        STD_JXROM },
152   { "HVC-JSROM",        STD_JXROM },
153   { "NES-JLROM",        STD_JXROM },
154   { "NES-JSROM",        STD_JXROM },
155   { "NES-BTR",          STD_JXROM },
156   /* JxROM boards by other manufacturer (this board was mainly used by Sunsoft?) */
157   { "SUNSOFT-5A",       STD_JXROM },
158   { "SUNSOFT-5B",       STD_JXROM },
159   { "SUNSOFT-FME-7",    STD_JXROM },
160//
161   /* Nintendo UN1ROM */
162   { "HVC-UN1ROM",       STD_UN1ROM },
163   { "NES-UN1ROM",       STD_UN1ROM },
164//
165   /* Nintendo SxROM */
166   { "HVC-SAROM",        STD_SXROM },
167   { "HVC-SBROM",        STD_SXROM },
168   { "HVC-SC1ROM",       STD_SXROM },
169   { "HVC-SCROM",        STD_SXROM },
170   { "HVC-SEROM",        STD_SXROM },
171   { "HVC-SF1ROM",       STD_SXROM },
172   { "HVC-SFROM",        STD_SXROM },
173   { "HVC-SGROM",        STD_SXROM },
174   { "HVC-SH1ROM",       STD_SXROM },
175   { "HVC-SHROM",        STD_SXROM },
176   { "HVC-SIROM",        STD_SXROM },
177   { "HVC-SJROM",        STD_SXROM },
178   { "HVC-SKROM",        STD_SXROM },
179   { "HVC-SKEPROM",      STD_SXROM },
180   { "HVC-SL1ROM",       STD_SXROM },
181   { "HVC-SL2ROM",       STD_SXROM },
182   { "HVC-SL3ROM",       STD_SXROM },
183   { "HVC-SLROM",        STD_SXROM },
184   { "HVC-SLRROM",       STD_SXROM },
185   { "HVC-SMROM",        STD_SXROM },
186   { "HVC-SNROM",        STD_SXROM },
187   { "HVC-SUROM",        STD_SXROM },
188   { "HVC-SXROM",        STD_SXROM },
189   { "NES-SAROM",        STD_SXROM },
190   { "NES-SBROM",        STD_SXROM },
191   { "NES-SC1ROM",       STD_SXROM },
192   { "NES-SCROM",        STD_SXROM },
193   { "NES-SEROM",        STD_SXROM },
194   { "NES-SF1ROM",       STD_SXROM },
195   { "NES-SFROM",        STD_SXROM },
196   { "NES-SGROM",        STD_SXROM },
197   { "NES-SH1ROM",       STD_SXROM },
198   { "NES-SHROM",        STD_SXROM },
199   { "NES-SIROM",        STD_SXROM },
200   { "NES-SJROM",        STD_SXROM },
201   { "NES-SKROM",        STD_SXROM },
202   { "NES-SKEPROM",      STD_SXROM },
203   { "NES-SL1ROM",       STD_SXROM },
204   { "NES-SL2ROM",       STD_SXROM },
205   { "NES-SL3ROM",       STD_SXROM },
206   { "NES-SLROM",        STD_SXROM },
207   { "NES-SLRROM",       STD_SXROM },
208   { "NES-SMROM",        STD_SXROM },
209   { "NES-SNROM",        STD_SXROM },
210   { "NES-SUROM",        STD_SXROM },
211   { "NES-SXROM",        STD_SXROM },
212   { "NES-WH",           STD_SXROM },
213   { "NES-SOROM",        STD_SOROM },
214   { "HVC-SOROM",        STD_SOROM },
215   /* SxROM boards by other manufacturer */
216   { "KONAMI-SLROM",     STD_SXROM },
217   { "VIRGIN-SNROM",     STD_SXROM },
218//
219   /* Nintendo TxROM */
220   { "HVC-TBROM",        STD_TXROM },
221   { "HVC-TEROM",        STD_TXROM },
222   { "HVC-TFROM",        STD_TXROM },
223   { "HVC-TGROM",        STD_TXROM },
224   { "HVC-TKROM",        STD_TXROM },
225   { "HVC-TL1ROM",       STD_TXROM },
226   { "HVC-TL2ROM",       STD_TXROM },
227   { "HVC-TLROM",        STD_TXROM },
228   { "HVC-TNROM",        STD_TXROM },
229   { "HVC-TR1ROM",       STD_TVROM },
230   { "HVC-TSROM",        STD_TXROM },
231   { "HVC-TVROM",        STD_TVROM },
232   { "NES-B4",           STD_TXROM },
233   { "NES-TBROM",        STD_TXROM },
234   { "NES-TEROM",        STD_TXROM },
235   { "NES-TFROM",        STD_TXROM },
236   { "NES-TGROM",        STD_TXROM },
237   { "NES-TKROM",        STD_TXROM },
238   { "NES-TL1ROM",       STD_TXROM },
239   { "NES-TL2ROM",       STD_TXROM },
240   { "NES-TLROM",        STD_TXROM },
241   { "NES-TNROM",        STD_TXROM },
242   { "NES-TR1ROM",       STD_TVROM },
243   { "NES-TSROM",        STD_TXROM },
244   { "NES-TVROM",        STD_TVROM },
245   /* TxROM boards by other manufacturer */
246   { "ACCLAIM-MC-ACC",   STD_TXROM },
247   { "ACCLAIM-TLROM",    STD_TXROM },
248   { "KONAMI-TLROM",     STD_TXROM },
249//
250   /* Nintendo DxROM */
251   { "HVC-DE1ROM",       STD_DXROM },
252   { "HVC-DEROM",        STD_DXROM },
253   { "HVC-DRROM",        STD_DRROM },
254   { "NES-DE1ROM",       STD_DXROM },
255   { "NES-DEROM",        STD_DXROM },
256   { "NES-DRROM",        STD_DRROM },
257   /* DxROM boards by other manufacturer */
258   { "NAMCOT-3401",      STD_DXROM },
259   { "NAMCOT-3405",      STD_DXROM },
260   { "NAMCOT-3406",      STD_DXROM },
261   { "NAMCOT-3407",      STD_DXROM },
262   { "NAMCOT-3413",      STD_DXROM },
263   { "NAMCOT-3414",      STD_DXROM },
264   { "NAMCOT-3415",      STD_DXROM },
265   { "NAMCOT-3416",      STD_DXROM },
266   { "NAMCOT-3417",      STD_DXROM },
267   { "NAMCOT-3451",      STD_DXROM },
268   { "TENGEN-800002",    STD_DXROM },
269   { "TENGEN-800004",    STD_DRROM },
270   { "TENGEN-800030",    STD_DXROM },
271//
272   /* Nintendo HKROM */
273   { "HVC-HKROM",        STD_HKROM },
274   { "NES-HKROM",        STD_HKROM },
275//
276   /* Nintendo BNROM */
277   { "HVC-TQROM",        STD_TQROM },
278   { "NES-TQROM",        STD_TQROM },
279//
280   /* Nintendo TxSROM */
281   { "HVC-TKSROM",       STD_TXSROM },
282   { "HVC-TLSROM",       STD_TXSROM },
283   { "NES-TKSROM",       STD_TXSROM },
284   { "NES-TLSROM",       STD_TXSROM },
285//
286   /* Nintendo ExROM */
287   { "HVC-EKROM",        STD_EXROM },
288   { "HVC-ELROM",        STD_EXROM },
289   { "HVC-ETROM",        STD_EXROM },
290   { "HVC-EWROM",        STD_EXROM },
291   { "NES-EKROM",        STD_EXROM },
292   { "NES-ELROM",        STD_EXROM },
293   { "NES-ETROM",        STD_EXROM },
294   { "NES-EWROM",        STD_EXROM },
295//
296   /* Nintendo Custom boards */
297   { "PAL-ZZ",           PAL_ZZ },
298   { "NES-QJ",           NES_QJ },
299   { "NES-EVENT",        UNSUPPORTED_BOARD },
300//
301   /* Discrete board IC_74x139x74 */
302   { "JALECO-JF-05",     DIS_74X139X74 },
303   { "JALECO-JF-06",     DIS_74X139X74 },
304   { "JALECO-JF-07",     DIS_74X139X74 },
305   { "JALECO-JF-08",     DIS_74X139X74 },
306   { "JALECO-JF-09",     DIS_74X139X74 },
307   { "JALECO-JF-10",     DIS_74X139X74 },
308   { "KONAMI-74*139/74", DIS_74X139X74 },
309   { "TAITO-74*139/74",  DIS_74X139X74 },
310   /* Discrete board IC_74x377 */
311   { "AGCI-47516",       DIS_74X377 },
312   { "AVE-NINA-07",      DIS_74X377 },
313   { "COLORDREAMS-74*377", DIS_74X377 },
314   /* Discrete board IC_74x161x161x32 */
315   { "BANDAI-74*161/161/32", DIS_74X161X161X32 },
316   { "TAITO-74*161/161/32", DIS_74X161X161X32 },
317   /* Discrete board IC_74x161x138 */
318   { "BIT-CORP-74*161/138", DIS_74X161X138 },
319//
320   { "BANDAI-LZ93D50",   BANDAI_LZ93 },
321   { "BANDAI-LZ93D50+24C01", BANDAI_LZ93EX },
322   { "BANDAI-LZ93D50+24C02", BANDAI_LZ93EX },
323   { "BANDAI-FCG-1",     BANDAI_FCG },
324   { "BANDAI-FCG-2",     BANDAI_FCG },
325   { "BANDAI-JUMP2",     BANDAI_JUMP2 },
326   { "BANDAI-DATACH",    BANDAI_DATACH },
327   { "BANDAI-KARAOKE",   BANDAI_KARAOKE },
328   { "BANDAI-OEKAKIDS",  BANDAI_OEKAKIDS },
329   { "IREM-FCG-1",       BANDAI_FCG },
330//
331   { "IREM-G101",        IREM_G101 },
332   { "IREM-74*161/161/21/138", IREM_LROG017 },
333   { "IREM-H-3001",      IREM_H3001 },
334   { "IREM-H3001",       IREM_H3001 },
335   { "IREM-HOLYDIVER",   IREM_HOLYDIV },
336   { "IREM-TAM-S1",      IREM_TAM_S1 },
337//
338   { "JALECO-JF-23",     JALECO_SS88006 },
339   { "JALECO-JF-24",     JALECO_SS88006 },
340   { "JALECO-JF-25",     JALECO_SS88006 },
341   { "JALECO-JF-27",     JALECO_SS88006 },
342   { "JALECO-JF-29",     JALECO_SS88006 },
343   { "JALECO-JF-30",     JALECO_SS88006 },
344   { "JALECO-JF-31",     JALECO_SS88006 },
345   { "JALECO-JF-32",     JALECO_SS88006 },
346   { "JALECO-JF-33",     JALECO_SS88006 },
347   { "JALECO-JF-34",     JALECO_SS88006 },
348   { "JALECO-JF-35",     JALECO_SS88006 },
349   { "JALECO-JF-36",     JALECO_SS88006 },
350   { "JALECO-JF-37",     JALECO_SS88006 },
351   { "JALECO-JF-38",     JALECO_SS88006 },
352   { "JALECO-JF-40",     JALECO_SS88006 },
353   { "JALECO-JF-41",     JALECO_SS88006 },
354   { "JALECO-JF-11",     JALECO_JF11 },
355   { "JALECO-JF-12",     JALECO_JF11 },
356   { "JALECO-JF-14",     JALECO_JF11 },
357   { "JALECO-JF-13",     JALECO_JF13 },
358   { "JALECO-JF-16",     JALECO_JF16 },
359   { "JALECO-JF-17",     JALECO_JF17 },
360   { "JALECO-JF-26",     JALECO_JF17 },
361   { "JALECO-JF-28",     JALECO_JF17 },
362   { "JALECO-JF-19",     JALECO_JF19 },
363   { "JALECO-JF-21",     JALECO_JF19 },
364//
365   { "KONAMI-VRC-1",     KONAMI_VRC1 },
366   { "JALECO-JF-20",     KONAMI_VRC1 },
367   { "JALECO-JF-22",     KONAMI_VRC1 },
368   { "KONAMI-VRC-2",     KONAMI_VRC2 },
369   { "KONAMI-VRC-3",     KONAMI_VRC3 },
370   { "KONAMI-VRC-4",     KONAMI_VRC4 },
371   { "KONAMI-VRC-6",     KONAMI_VRC6 },
372   { "KONAMI-VRC-7",     KONAMI_VRC7 },
373   { "UNL-VRC7",         KONAMI_VRC7 },
374//
375   { "NAMCOT-163",       NAMCOT_163 },
376   { "NAMCOT-175",       NAMCOT_163 },
377   { "NAMCOT-340",       NAMCOT_163 },
378   { "NAMCOT-3425",      NAMCOT_3425 },
379   { "NAMCOT-3433",      NAMCOT_34X3 },
380   { "NAMCOT-3443",      NAMCOT_34X3 },
381   { "NAMCOT-3446",      NAMCOT_3446 },
382   { "NAMCOT-3453",      NAMCOT_3453 },
383//
384   { "SUNSOFT-1",        SUNSOFT_1 },
385   { "SUNSOFT-2",        SUNSOFT_2 },
386   { "SUNSOFT-3",        SUNSOFT_3 },
387   //
388   { "TAITO-TC0190FMC",  TAITO_TC0190FMC },
389   { "TAITO-TC0190FMC+PAL16R4", TAITO_TC0190FMCP },
390   { "TAITO-TC0350FMR",  TAITO_TC0190FMC },
391   { "TAITO-X1-005",     TAITO_X1_005 },   // two variants exist, depending on pin17 & pin31 connections
392   { "TAITO-X1-017",     TAITO_X1_017 },
393//
394   { "AGCI-50282",       AGCI_50282 },
395   { "AVE-NINA-01",      AVE_NINA01 },
396   { "AVE-NINA-02",      AVE_NINA01 },
397   { "AVE-NINA-03",      AVE_NINA06 },
398   { "AVE-NINA-06",      AVE_NINA06 },
399   { "AVE-MB-91",        AVE_NINA06 },
400   { "TXC-74*138/175",   AVE_NINA06 },
401   { "UNL-SA-016-1M",    AVE_NINA06 },
402   { "CAMERICA-ALGN",    CAMERICA_BF9093 },
403   { "CAMERICA-BF9093",  CAMERICA_BF9093 },
404   { "CAMERICA-BF9097",  CAMERICA_BF9097 },
405   { "CAMERICA-ALGQ",    CAMERICA_BF9096 },
406   { "CAMERICA-BF9096",  CAMERICA_BF9096 },
407   { "CAMERICA-GOLDENFIVE", CAMERICA_GOLDENFIVE },
408   { "CNE-DECATHLON",    CNE_DECATHLON },
409   { "CNE-PSB",          CNE_FSB },
410   { "CNE-SHLZ",         CNE_SHLZ },
411   { "JYCOMPANY-A",      UNSUPPORTED_BOARD },   // mapper 90
412   { "JYCOMPANY-B",      UNSUPPORTED_BOARD },   // mapper 209
413   { "JYCOMPANY-C",      UNSUPPORTED_BOARD },   // mapper 211
414   { "NTDEC-112",        NTDEC_ASDER },   // mapper 112 (better rename this board tag, to avoid confusion with TC-112!!
415   { "NTDEC-TC-112",     NTDEC_FIGHTINGHERO },
416   { "NTDEC-193",        NTDEC_FIGHTINGHERO },   // mapper 193
417   { "UNL-TEK90",        UNSUPPORTED_BOARD },   // related to JY Company? (i.e. mappers 90, 209, 211?)
418   { "UNL-SA-002",       SACHEN_TCU02 },
419   { "UNL-SA-009",       SACHEN_SA009 },
420   { "UNL-SA-0036",      SACHEN_SA0036 },
421   { "UNL-SA-0037",      SACHEN_SA0037 },
422   { "UNL-SA-72007",     SACHEN_SA72007 },
423   { "UNL-SA-72008",     SACHEN_SA72008 },
424   { "UNL-SA-NROM",      SACHEN_TCA01 },
425   { "UNL-SACHEN-TCA01", SACHEN_TCA01 },
426   { "SACHEN-8259A",     SACHEN_8259A },
427   { "UNL-SACHEN-8259A", SACHEN_8259A },
428   { "SACHEN-8259B",     SACHEN_8259B },
429   { "UNL-SACHEN-8259B", SACHEN_8259B },
430   { "SACHEN-8259C",     SACHEN_8259C },
431   { "UNL-SACHEN-8259C", SACHEN_8259C },
432   { "SACHEN-8259D",     SACHEN_8259D },
433   { "UNL-SACHEN-8259D", SACHEN_8259D },
434   { "UNL-SACHEN-74LS374N", SACHEN_74LS374 },
435   { "UNL-SACHEN-74LS374N-A", SACHEN_74LS374_A },   /* FIXME: Made up boards the different mirroring handling */
436   { "UNL-TC-U01-1.5M",  SACHEN_TCU01 },
437   { "TENGEN-800032",    TENGEN_800032 },
438   { "TENGEN-800037",    TENGEN_800037 },
439   { "WAIXING-A",        WAIXING_TYPE_A },
440   { "WAIXING-A-1",      WAIXING_TYPE_A_1 },   /* FIXME: Made up boards the different CHRRAM banks (see Ji Jia Zhan Shi) */
441   { "WAIXING-B",        WAIXING_TYPE_B },
442   { "WAIXING-C",        WAIXING_TYPE_C },
443   { "WAIXING-D",        WAIXING_TYPE_D },
444   { "WAIXING-E",        WAIXING_TYPE_E },
445   { "WAIXING-F",        WAIXING_TYPE_F },
446   { "WAIXING-G",        WAIXING_TYPE_G },
447   { "WAIXING-H",        WAIXING_TYPE_H },
448   { "WAIXING-I",        WAIXING_TYPE_I },
449   { "WAIXING-J",        WAIXING_TYPE_J },
450   { "WAIXING-SGZLZ",    WAIXING_SGZLZ },
451   { "WAIXING-SEC",      WAIXING_SECURITY },
452   { "WAIXING-SGZ",      WAIXING_SGZ },
453   { "WAIXING-PS2",      WAIXING_PS2 },
454   { "WAIXING-FFV",      WAIXING_FFV },
455   { "WAIXING-ZS",       WAIXING_ZS },
456   { "WAIXING-DQ8",      WAIXING_DQ8 },
457   { "WAIXING-SH2",      WAIXING_SH2 },
458//
459   { "TXC-TW",           TXC_TW },
460   { "TXC-STRIKEWOLF",   TXC_STRIKEWOLF },
461   { "TXC-MXMDHTWO",     TXC_MXMDHTWO },
462   { "UNL-22211",        TXC_22211A },
463   /* FIXME: Made up boards the different mirroring handling */
464   { "UNL-22211-A",      TXC_22211A },
465   { "UNL-22211-B",      TXC_22211B },
466   { "UNL-22211-C",      TXC_22211C },
467   { "UNL-REXSOFT-DBZ5", REXSOFT_DBZ5 },
468   { "UNL-SL1632",       REXSOFT_SL1632 },
469   { "SUBOR-BOARD-0",    SUBOR_TYPE0 },
470   { "SUBOR-BOARD-1",    SUBOR_TYPE1 },
471   { "SOMERITEAM-SL-12", SOMERI_SL12 }, // mapper 116
472   { "UNL-CONY",         CONY_BOARD },
473   { "UNL-GOUDER",       GOUDER_37017 },
474   { "UNL-NITRA",        NITRA_TDA },
475   { "UNL-HOSENKAN",     HOSENKAN_BOARD },
476   { "UNL-SUPERGAME",    SUPERGAME_LIONKING },
477   { "UNL-PANDAPRINCE",  KAY_PANDAPRINCE },
478   { "DREAMTECH01",      DREAMTECH_BOARD },
479   { "DAOU-306",         OPENCORP_DAOU306 },
480   { "HES",              HES_BOARD },
481   /* FIXME: Made up boards the different mirroring handling? */
482   { "HES-6IN1",         HES6IN1_BOARD },
483   { "SUPERGAME-BOOGERMAN", SUPERGAME_BOOGERMAN },
484   { "FUTUREMEDIA",      FUTUREMEDIA_BOARD },
485   { "FUKUTAKE",         FUKUTAKE_BOARD },
486   { "MAGICSERIES",      MAGICSERIES_MD },
487   { "KASING",           KASING_BOARD },
488   { "HENGGEDIANZI",     HENGEDIANZI_BOARD },
489   { "HENGGEDIANZI-XJZB", HENGEDIANZI_XJZB },
490   { "KAISER-KS7058",    KAISER_KS7058 },
491   { "KAISER-KS202",     KAISER_KS202 },// mapper 56
492   { "KAISER-KS7022",    KAISER_KS7022 },// mapper 175
493   { "UNL-KS7017",       KAISER_KS7017 },
494   { "UNL-KS7032",       KAISER_KS7032 }, //  mapper 142
495   { "RCM-GS2015",       RCM_GS2015 },
496   { "RCM-TETRISFAMILY", RCM_TETRISFAMILY },
497   { "UNL-NINJARYU",     UNSUPPORTED_BOARD },// mapper 111
498   { "UNL-NANJING",      NANJING_BOARD },// mapper 163
499   { "WHIRLWIND-2706",   WHIRLWIND_2706 },
500   { "UNL-H2288",        UNL_H2288 },
501   { "UNL-DANCE",        UNSUPPORTED_BOARD },
502   { "UNL-EDU2000",      UNL_EDU2K },
503   { "UNL-SHERO",        UNSUPPORTED_BOARD /*SACHEN_SHERO*/ },
504   { "UNL-TF1201",       UNSUPPORTED_BOARD /*UNL_TF1201*/ },
505   { "RUMBLESTATION",    RUMBLESTATION_BOARD },   // mapper 46
506   { "UNL-WORLDHERO",    UNSUPPORTED_BOARD },// mapper 27
507   { "UNL-A9746",        UNSUPPORTED_BOARD },// mapper 219
508   { "UNL-603-5052",     UNL_603_5052 },// mapper 238?
509   { "UNL-SHJY3",        UNL_SHJY3 },// mapper 253
510   { "UNL-RACERMATE",    UNL_RACERMATE },// mapper 168
511   { "UNL-N625092",      UNL_N625092 },
512   { "BMC-N625092",      UNL_N625092 },
513   { "UNL-SC-127",       UNL_SC127 },
514   { "UNL-SMB2J",        UNL_SMB2J },
515   { "BTL-SMB2C",        UNL_SMB2J },
516   { "UNL-MK2",          UNL_MK2 },
517   { "UNL-XZY",          UNL_XZY },
518   { "UNL-KOF96",        UNL_KOF96 },
519   { "UNL-SUPERFIGHTER3", UNL_SUPERFIGHTER3 },
520   { "UNL-8237",         UNL_8237 },
521   { "UNL-AX5705",       UNL_AX5705 },
522   { "UNL-CC-21",        UNL_CC21 },
523   { "UNL-KOF97",        UNL_KOF97 },
524   { "UNL-T-230",        UNL_T230 },
525   { "UNL-STUDYNGAME",   UNL_STUDYNGAME },   // mapper 39
526   { "UNL-OneBus",       UNSUPPORTED_BOARD },
527//
528   { "BTL-SMB2A",         BTL_SMB2A },
529   { "BTL-MARIOBABY",     BTL_MARIOBABY },
530   { "BTL-AISENSHINICOL", BTL_AISENSHINICOL },
531   { "BTL-SMB2B",         BTL_SMB2B },
532   { "BTL-SMB3",          BTL_SMB3 },
533   { "BTL-SUPERBROS11",   BTL_SUPERBROS11 },
534   { "BTL-DRAGONNINJA",   BTL_DRAGONNINJA },
535   { "BTL-MARIO1-MALEE2", UNSUPPORTED_BOARD },   // mapper 55?
536   { "BTL-2708",          UNSUPPORTED_BOARD },// mapper 103
537   { "BTL-TOBIDASEDAISAKUSEN", BTL_TOBIDASE },// mapper 120
538   { "BTL-SHUIGUANPIPE",  UNSUPPORTED_BOARD },// mapper 183
539   { "BTL-PIKACHUY2K",    BTL_PIKACHUY2K },// mapper 254
540//
541   { "BMC-190IN1",          BMC_190IN1 },
542   { "BMC-64IN1NOREPEAT",   BMC_64IN1NR },
543   { "BMC-A65AS",           BMC_A65AS },
544   { "BMC-GS-2004",         BMC_GS2004 },
545   { "BMC-GS-2013",         BMC_GS2013 },
546   { "BMC-NOVELDIAMOND9999999IN1", BMC_NOVELDIAMOND },
547   { "BMC-9999999IN1",      BMC_9999999IN1 }, // mapper 213... same as BMC-NOVELDIAMOND9999999IN1 ??
548   { "BMC-SUPER24IN1SC03",  BMC_S24IN1SC03 },
549   { "BMC-SUPERHIK8IN1",    BMC_HIK8IN1 },
550   { "BMC-T-262",           BMC_T262 },
551   { "BMC-WS",              BMC_WS },
552   { "MLT-ACTION52",        ACTENT_ACT52 },
553   { "MLT-CALTRON6IN1",     CALTRON_6IN1 },
554   { "MLT-MAXI15",          UNSUPPORTED_BOARD}, //  mapper 234
555   { "BMC-SUPERBIG-7IN1",   BMC_SUPERBIG_7IN1 },
556   { "BMC-SUPERHIK-4IN1",   BMC_SUPERHIK_4IN1 },
557   { "BMC-BALLGAMES-11IN1", BMC_BALLGAMES_11IN1 },
558   { "BMC-MARIOPARTY-7IN1", BMC_MARIOPARTY_7IN1 },
559   { "BMC-GKA",             BMC_GKA },
560   { "BMC-GKB",             BMC_GKB },
561   { "BMC-SUPER700IN1",     BMC_SUPER_700IN1 },
562   { "BMC-FAMILY-4646B",    BMC_FAMILY_4646B },
563   { "BMC-36IN1",           BMC_36IN1 },
564   { "BMC-21IN1",           BMC_21IN1 },
565   { "BMC-150IN1",          BMC_150IN1 },
566   { "BMC-35IN1",           BMC_35IN1 },
567   { "BMC-64IN1",           BMC_64IN1 },
568   { "BMC-15IN1",           BMC_15IN1 },
569   { "BMC-SUPERHIK-300IN1", BMC_SUPERHIK_300IN1 },
570   { "BMC-SUPERGUN-20IN1",  BMC_SUPERGUN_20IN1 },
571   { "BMC-GOLDENCARD-6IN1", BMC_GOLDENCARD_6IN1 },
572   { "BMC-72IN1",           BMC_72IN1 },
573   { "BMC-76IN1",           BMC_76IN1 },
574   { "BMC-SUPER42IN1",      BMC_SUPER_42IN1 },
575   { "BMC-1200IN1",         BMC_1200IN1 },
576   { "BMC-31IN1",           BMC_31IN1 },
577   { "BMC-22GAMES",         BMC_22GAMES },
578   { "BMC-20IN1",           BMC_20IN1 },
579   { "BMC-110IN1",          BMC_110IN1 },
580   { "BMC-810544-C-A1",     BMC_810544 },
581   { "BMC-411120-C",        UNSUPPORTED_BOARD },
582   { "BMC-830118C",         UNSUPPORTED_BOARD },
583   { "BMC-12-IN-1",         UNSUPPORTED_BOARD },
584   { "BMC-NTD-03",          BMC_NTD_03 },
585   { "BMC-8157",            UNSUPPORTED_BOARD /*BMC_8157*/ },
586   { "BMC-BS-5",            BMC_BENSHENG_BS5 },
587   { "BMC-FK23C",           BMC_FK23C },
588   { "BMC-FK23CA",          BMC_FK23CA },
589   { "BMC-GHOSTBUSTERS63IN1", BMC_G63IN1 },
590   { "BMC-SUPERVISION16IN1", UNSUPPORTED_BOARD },   // mapper 53
591   { "BMC-RESETBASED-4IN1", UNSUPPORTED_BOARD },// mapper 60 with 64k prg and 32k chr
592   { "BMC-VT5201",          BMC_VT5201 },// mapper 60 otherwise
593   { "BMC-D1038",           BMC_VT5201 }, // mapper 60?
594   { "BMC-42IN1RESETSWITCH", UNSUPPORTED_BOARD },   // mapper 60?
595   { "BMC-SUPER22GAMES",    UNSUPPORTED_BOARD },// mapper 233
596   { "BMC-GOLDENGAME-150IN1", UNSUPPORTED_BOARD },// mapper 235 with 2M PRG
597   { "BMC-GOLDENGAME-260IN1", UNSUPPORTED_BOARD },// mapper 235 with 4M PRG
598   { "BMC-70IN1",           UNSUPPORTED_BOARD },   // mapper 236?
599   { "BMC-70IN1B",          UNSUPPORTED_BOARD },   // mapper 236?
600   { "BMC-SUPERHIK-KOF",    UNSUPPORTED_BOARD },// mapper 251
601   { "BMC-POWERJOY",        BMC_PJOY84 },
602// are there dumps of games with these boards?
603   { "BMC-13IN1JY110",   UNSUPPORTED_BOARD }, //  [mentioned in FCEUMM source - we need more info]
604   { "BMC-GK-192",       UNSUPPORTED_BOARD }, //  [mentioned in FCEUMM source - we need more info]
605   { "KONAMI-QTAI",      UNSUPPORTED_BOARD }, //  [mentioned in FCEUMM source - we need more info]
606   { "UNL-3D-BLOCK",     UNSUPPORTED_BOARD }, //  [mentioned in FCEUMM source - we need more info]
607   { "UNL-C-N22M",       UNSUPPORTED_BOARD }, //  [mentioned in FCEUMM source - we need more info]
608   { "UNL-PEC-586",      UNSUPPORTED_BOARD }, //  [mentioned in FCEUMM source - we need more info]
609//
610   { "UNKNOWN",          UNKNOWN_BOARD }  //  a few pirate dumps uses the wrong mapper...
611};
612
613const nes_pcb *nes_pcb_lookup( const char *board )
614{
615   int i;
616   for (i = 0; i < ARRAY_LENGTH(pcb_list); i++)
617   {
618      if (!mame_stricmp(pcb_list[i].pcb_name, board))
619         return &pcb_list[i];
620   }
621   return NULL;
622}
623
624int nes_get_pcb_id( running_machine &machine, const char *feature )
625{
626   const nes_pcb *pcb = nes_pcb_lookup(feature);
627
628   if (pcb == NULL)
629      fatalerror("Unimplemented PCB type %s\n", feature);
630
631   return pcb->pcb_id;
632}
633
634/************************************************
635
636   PCB Emulation (to be moved to MAME later)
637
638   In the end, iNES, UNIF and xml should be
639   simply handled through a look-up table
640   which associates the mapper/board/feature
641   to the correct pcb_id and then the core
642   function pcb_handlers_setup should be called
643   to set-up the expected handlers and callbacks
644
645   Similarly, PC-10, VSNES and NES-based
646   multigame boards, should simply call
647   pcb_handlers_setup with the proper pcb_id
648   at the beginning, rather than use ad hoc
649   implementations.
650
651************************************************/
652
653// helper function for the few mappers reading from 0x8000-0xffff for protection
654INLINE UINT8 mmc_hi_access_rom( running_machine &machine, UINT32 offset )
655{
656   nes_state *state = machine.driver_data<nes_state>();
657
658   // usual ROM access
659   switch (offset & 0x6000)
660   {
661      case 0x0000:
662         return state->m_rom[0x10000 + state->m_prg_bank[0] * 0x2000 + (offset & 0x1fff)];
663      case 0x2000:
664         return state->m_rom[0x10000 + state->m_prg_bank[1] * 0x2000 + (offset & 0x1fff)];
665      case 0x4000:
666         return state->m_rom[0x10000 + state->m_prg_bank[2] * 0x2000 + (offset & 0x1fff)];
667      case 0x6000:
668         return state->m_rom[0x10000 + state->m_prg_bank[3] * 0x2000 + (offset & 0x1fff)];
669   }
670   return 0;
671}
672
673/*************************************************************
674
675 NROM board emulation
676
677 Games: Mario Bros., Super Mario Bros., Tennis and most of
678 the first generation games
679
680 iNES: mapper 0
681
682 In MESS: Supported, no need of specific handlers or IRQ
683
684 *************************************************************/
685
686/*************************************************************
687
688 UxROM board emulation
689
690 Games: Castlevania, Dragon Quest II, Duck Tales, MegaMan,
691 Metal Gear
692
693 writes to 0x8000-0xffff change PRG 16K lower banks
694
695 missing BC?
696
697 iNES: mapper 2
698
699 In MESS: Supported.
700
701 *************************************************************/
702
703static WRITE8_HANDLER( uxrom_w )
704{
705   LOG_MMC(("uxrom_w, offset: %04x, data: %02x\n", offset, data));
706
707   prg16_89ab(space->machine(), data);
708}
709
710/*************************************************************
711
712 Nihon Bussan UNROM M5
713
714 Games: Crazy Climber Jpn
715
716 Very simple mapper: prg16_89ab is always set to bank 0,
717 while prg16_cdef is set by writes to 0x8000-0xffff. The game
718 uses a custom controller.
719
720 iNES: mapper 180
721
722 In MESS: Supported.
723
724 *************************************************************/
725
726static WRITE8_HANDLER( uxrom_cc_w )
727{
728   LOG_MMC(("uxrom_cc_w, offset: %04x, data: %02x\n", offset, data));
729
730   prg16_cdef(space->machine(), data);
731}
732
733/*************************************************************
734
735 UN1ROM board emulation
736
737 Games: Senjou no Okami
738
739 writes to 0x8000-0xffff change PRG 16K lower banks
740
741 missing BC?
742
743 iNES: mapper 94
744
745 In MESS: Supported.
746
747 *************************************************************/
748
749static WRITE8_HANDLER( un1rom_w )
750{
751   LOG_MMC(("un1rom_w, offset: %04x, data: %02x\n", offset, data));
752
753   prg16_89ab(space->machine(), data >> 2);
754}
755
756/*************************************************************
757
758 CNROM board emulation
759
760 Games: B-Wings, Mighty Bomb Jack, Seicross, Spy vs. Spy,
761 Adventure Island, Flipull, Friday 13th, GeGeGe no
762 Kitarou, Ghostbusters, Gradius, Hokuto no Ken, Milon's
763 Secret Castle
764
765 writes to 0x8000-0xffff change CHR 8K banks
766
767 missing BC?
768
769 iNES: mappers 3 & 185 (the latter for games using Pins as
770 protection)
771
772 Notice that BANDAI_PT554 board (Aerobics Studio) uses very
773 similar hardware but with an additional sound chip which
774 gets writes to 0x6000 (currently unemulated in MESS)
775
776 In MESS: Supported
777
778 *************************************************************/
779
780static WRITE8_HANDLER( cnrom_w )
781{
782   nes_state *state = space->machine().driver_data<nes_state>();
783   LOG_MMC(("cnrom_w, offset: %04x, data: %02x\n", offset, data));
784
785   if (state->m_ce_mask)
786   {
787      chr8(space->machine(), data & ~state->m_ce_mask, CHRROM);
788
789      if ((data & state->m_ce_mask) == state->m_ce_state)
790         state->m_chr_open_bus = 0;
791      else
792         state->m_chr_open_bus = 1;
793   }
794   else
795      chr8(space->machine(), data, CHRROM);
796}
797
798/*************************************************************
799
800 Bandai PT-554 board emulation
801
802 This is used by Aerobics Studio. It is basically a CNROM board
803 with an additional sound chip which is not currently emulated by
804 MESS
805
806 iNES: mapper 3?
807
808 *************************************************************/
809
810static WRITE8_HANDLER( bandai_pt554_m_w )
811{
812   LOG_MMC(("Bandai PT-554 Sound write, data: %02x\n", data));
813
814   // according to NEStopia, this is the effect
815   if (!BIT(data, 6))
816   {
817      // send command (data & 0x07) to sound chip
818   }
819}
820
821/*************************************************************
822
823 CPROM board emulation
824
825 Games: Videomation
826
827 writes to 0x8000-0xffff change CHR 4K lower banks
828
829 iNES: mapper 13
830
831 In MESS: Supported
832
833 *************************************************************/
834
835static WRITE8_HANDLER( cprom_w )
836{
837   LOG_MMC(("cprom_w, offset: %04x, data: %02x\n", offset, data));
838   chr4_4(space->machine(), data, CHRRAM);
839}
840
841/*************************************************************
842
843 AxROM board emulation
844
845 Games: Arch Rivals, Battletoads, Cabal, Commando, Solstice
846
847 writes to 0x8000-0xffff change PRG banks + sets mirroring
848
849 missing BC for AMROM?
850
851 iNES: mapper 7
852
853 In MESS: Supported
854
855 *************************************************************/
856
857static WRITE8_HANDLER( axrom_w )
858{
859   LOG_MMC(("axrom_w, offset: %04x, data: %02x\n", offset, data));
860
861   set_nt_mirroring(space->machine(), BIT(data, 4) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
862   prg32(space->machine(), data);
863}
864
865/*************************************************************
866
867 BxROM board emulation
868
869 writes to 0x8000-0xffff change PRG banks
870
871 missing BC?
872
873 iNES: mapper 34
874
875 *************************************************************/
876
877static WRITE8_HANDLER( bxrom_w )
878{
879   /* This portion of the mapper is nearly identical to Mapper 7, except no one-screen mirroring */
880   /* Deadly Towers is really a BxROM game - the demo screens look wrong using mapper 7. */
881   LOG_MMC(("bxrom_w, offset: %04x, data: %02x\n", offset, data));
882
883   prg32(space->machine(), data);
884}
885
886/*************************************************************
887
888 GxROM/MxROM board emulation
889
890 writes to 0x8000-0xffff change PRG and CHR banks
891
892 missing BC?
893
894 iNES: mapper 66
895
896 *************************************************************/
897
898static WRITE8_HANDLER( gxrom_w )
899{
900   LOG_MMC(("gxrom_w, offset %04x, data: %02x\n", offset, data));
901
902   prg32(space->machine(), (data & 0xf0) >> 4);
903   chr8(space->machine(), data & 0x0f, CHRROM);
904}
905
906/*************************************************************
907
908 SxROM (MMC1 based) board emulation
909
910 iNES: mapper 1 (and 155 for the MMC1A variant which does not
911 have WRAM disable bit)
912
913 *************************************************************/
914
915static TIMER_CALLBACK( mmc1_resync_callback )
916{
917   nes_state *state = machine.driver_data<nes_state>();
918   state->m_mmc1_reg_write_enable = 1;
919}
920
921
922static void mmc1_set_wram( address_space *space, int board )
923{
924   running_machine &machine = space->machine();
925   nes_state *state = machine.driver_data<nes_state>();
926   UINT8 bank = BIT(state->m_mmc_reg[0], 4) ? BIT(state->m_mmc_reg[1], 4) : BIT(state->m_mmc_reg[1], 3);
927
928   switch (board)
929   {
930      case STD_SXROM:      // here also reads are disabled!
931         if (!BIT(state->m_mmc_reg[3], 4))
932            space->install_readwrite_bank(0x6000, 0x7fff, "bank5");
933         else
934         {
935            space->unmap_readwrite(0x6000, 0x7fff);
936            break;
937         }
938      case STD_SXROM_A:   // ignore WRAM enable bit
939         if (state->m_battery_size > 0x2000)
940            wram_bank(machine, ((state->m_mmc_reg[1] & 3) >> 2), NES_BATTERY);
941         else if (state->m_battery_size)
942            wram_bank(machine, 0, NES_BATTERY);
943         break;
944      case STD_SOROM:      // there are 2 WRAM banks only and battery is bank 2 for the cart (hence, we invert bank, because we have battery first)
945         if (!BIT(state->m_mmc_reg[3], 4))
946            space->install_readwrite_bank(0x6000, 0x7fff, "bank5");
947         else
948         {
949            space->unmap_readwrite(0x6000, 0x7fff);
950            break;
951         }
952      case STD_SOROM_A:   // ignore WRAM enable bit
953         wram_bank(machine, 0, bank ? NES_BATTERY : NES_WRAM);
954         break;
955   }
956}
957
958static void mmc1_set_prg( running_machine &machine )
959{
960   nes_state *state = machine.driver_data<nes_state>();
961   UINT8 prg_mode, prg_offset;
962
963   prg_mode = state->m_mmc_reg[0] & 0x0c;
964   /* prg_mode&0x8 determines bank size: 32k (if 0) or 16k (if 1)? when in 16k mode,
965     prg_mode&0x4 determines which half of the PRG space we can swap: if it is 4,
966     mmc_reg[3] sets banks at 0x8000; if it is 0, mmc_reg[3] sets banks at 0xc000. */
967
968   prg_offset = state->m_mmc_reg[1] & 0x10;
969   /* In principle, mmc_reg[2]&0x10 might affect "extended" banks as well, when chr_mode=1.
970     However, quoting Disch's docs: When in 4k CHR mode, 0x10 in both $A000 and $C000 *must* be
971     set to the same value, or else pages will constantly be swapped as graphics render!
972     Hence, we use only mmc_reg[1]&0x10 for prg_offset */
973
974   switch (prg_mode)
975   {
976      case 0x00:
977      case 0x04:
978//          printf("PRG 32 bank %d \n", (prg_offset + state->m_mmc_reg[3]) >> 1);
979         prg32(machine, (prg_offset + state->m_mmc_reg[3]) >> 1);
980         break;
981      case 0x08:
982//          printf("PRG 16 bank %d (high) \n", prg_offset + state->m_mmc_reg[3]);
983         prg16_89ab(machine, prg_offset + 0);
984         prg16_cdef(machine, prg_offset + state->m_mmc_reg[3]);
985         break;
986      case 0x0c:
987//          printf("PRG 16 bank %d (low) \n", prg_offset + state->m_mmc_reg[3]);
988         prg16_89ab(machine, prg_offset + state->m_mmc_reg[3]);
989         prg16_cdef(machine, prg_offset + 0x0f);
990         break;
991   }
992}
993
994static void mmc1_set_prg_wram( address_space *space, int board )
995{
996   mmc1_set_prg(space->machine());
997   mmc1_set_wram(space, board);
998}
999
1000static void mmc1_set_chr( running_machine &machine )
1001{
1002   nes_state *state = machine.driver_data<nes_state>();
1003   UINT8 chr_mode = BIT(state->m_mmc_reg[0], 4);
1004
1005   if (chr_mode)
1006   {
1007      chr4_0(machine, state->m_mmc_reg[1] & 0x1f, state->m_mmc_chr_source);
1008      chr4_4(machine, state->m_mmc_reg[2] & 0x1f, state->m_mmc_chr_source);
1009   }
1010   else
1011      chr8(machine, (state->m_mmc_reg[1] & 0x1f) >> 1, state->m_mmc_chr_source);
1012}
1013
1014static void common_sxrom_write_handler( address_space *space, offs_t offset, UINT8 data, int board )
1015{
1016   running_machine &machine = space->machine();
1017   nes_state *state = machine.driver_data<nes_state>();
1018   /* Note that there is only one latch and shift counter, shared amongst the 4 regs */
1019   /* Space Shuttle will not work if they have independent variables. */
1020
1021   /* here we would need to add an if(cpu_cycles_passed>1) test, and
1022     if requirement is not met simply return without writing anything.
1023     Some games (AD&D Hillsfar, Bill & Ted Excellent Adventure, Cosmic
1024     Wars, Rocket Ranger, Sesame Street 123 and Snow Brothers) rely on
1025     this behavior!! */
1026   if (state->m_mmc1_reg_write_enable == 0)
1027   {
1028      return;
1029   }
1030   else
1031   {
1032      state->m_mmc1_reg_write_enable = 0;
1033      space->machine().scheduler().synchronize(FUNC(mmc1_resync_callback));
1034   }
1035
1036   if (data & 0x80)
1037   {
1038      state->m_mmc1_count = 0;
1039      state->m_mmc1_latch = 0;
1040
1041      /* Set reg at 0x8000 to size 16k and lower half swap - needed for Robocop 3, Dynowars */
1042      state->m_mmc_reg[0] |= 0x0c;
1043      mmc1_set_prg_wram(space, board);
1044      return;
1045   }
1046
1047   if (state->m_mmc1_count < 5)
1048   {
1049      if (state->m_mmc1_count == 0) state->m_mmc1_latch = 0;
1050      state->m_mmc1_latch >>= 1;
1051      state->m_mmc1_latch |= (data & 0x01) ? 0x10 : 0x00;
1052      state->m_mmc1_count++;
1053   }
1054
1055   if (state->m_mmc1_count == 5)
1056   {
1057      switch (offset & 0x6000)   /* Which reg shall we write to? */
1058      {
1059         case 0x0000:
1060            state->m_mmc_reg[0] = state->m_mmc1_latch;
1061
1062            switch (state->m_mmc_reg[0] & 0x03)
1063            {
1064            case 0: set_nt_mirroring(machine, PPU_MIRROR_LOW); break;
1065            case 1: set_nt_mirroring(machine, PPU_MIRROR_HIGH); break;
1066            case 2: set_nt_mirroring(machine, PPU_MIRROR_VERT); break;
1067            case 3: set_nt_mirroring(machine, PPU_MIRROR_HORZ); break;
1068            }
1069            mmc1_set_chr(machine);
1070            mmc1_set_prg_wram(space, board);
1071            break;
1072         case 0x2000:
1073            state->m_mmc_reg[1] = state->m_mmc1_latch;
1074            mmc1_set_chr(machine);
1075            mmc1_set_prg_wram(space, board);
1076            break;
1077         case 0x4000:
1078            state->m_mmc_reg[2] = state->m_mmc1_latch;
1079            mmc1_set_chr(machine);
1080            break;
1081         case 0x6000:
1082            state->m_mmc_reg[3] = state->m_mmc1_latch;
1083            mmc1_set_prg_wram(space, board);
1084            break;
1085      }
1086      state->m_mmc1_count = 0;
1087   }
1088}
1089
1090static WRITE8_HANDLER( sxrom_w )
1091{
1092   nes_state *state = space->machine().driver_data<nes_state>();
1093
1094   LOG_MMC(("sxrom_w, offset: %04x, data: %02x\n", offset, data));
1095   common_sxrom_write_handler(space, offset, data, state->m_pcb_id);
1096}
1097
1098/*************************************************************
1099
1100 PxROM (MMC2 based) board emulation
1101
1102 Games: Punch Out!!, Mike Tyson's Punch Out!!
1103
1104 iNES: mapper 9
1105
1106 In MESS: Supported
1107
1108 *************************************************************/
1109
1110static void mmc2_latch( device_t *device, offs_t offset )
1111{
1112   nes_state *state = device->machine().driver_data<nes_state>();
1113   if ((offset & 0x3ff0) == 0x0fd0)
1114   {
1115      LOG_MMC(("mmc2 vrom latch switch (bank 0 low): %02x\n", state->m_mmc_reg[0]));
1116      state->m_mmc_latch1 = 0xfd;
1117      chr4_0(device->machine(), state->m_mmc_reg[0], CHRROM);
1118   }
1119   else if ((offset & 0x3ff0) == 0x0fe0)
1120   {
1121      LOG_MMC(("mmc2 vrom latch switch (bank 0 high): %02x\n", state->m_mmc_reg[1]));
1122      state->m_mmc_latch1 = 0xfe;
1123      chr4_0(device->machine(), state->m_mmc_reg[1], CHRROM);
1124   }
1125   else if ((offset & 0x3ff0) == 0x1fd0)
1126   {
1127      LOG_MMC(("mmc2 vrom latch switch (bank 1 low): %02x\n", state->m_mmc_reg[2]));
1128      state->m_mmc_latch2 = 0xfd;
1129      chr4_4(device->machine(), state->m_mmc_reg[2], CHRROM);
1130   }
1131   else if ((offset & 0x3ff0) == 0x1fe0)
1132   {
1133      LOG_MMC(("mmc2 vrom latch switch (bank 0 high): %02x\n", state->m_mmc_reg[3]));
1134      state->m_mmc_latch2 = 0xfe;
1135      chr4_4(device->machine(), state->m_mmc_reg[3], CHRROM);
1136   }
1137}
1138
1139static WRITE8_HANDLER( pxrom_w )
1140{
1141   nes_state *state = space->machine().driver_data<nes_state>();
1142   LOG_MMC(("pxrom_w, offset: %04x, data: %02x\n", offset, data));
1143   switch (offset & 0x7000)
1144   {
1145      case 0x2000:
1146         prg8_89(space->machine(), data);
1147         break;
1148      case 0x3000:
1149         state->m_mmc_reg[0] = data;
1150         if (state->m_mmc_latch1 == 0xfd)
1151            chr4_0(space->machine(), state->m_mmc_reg[0], CHRROM);
1152         break;
1153      case 0x4000:
1154         state->m_mmc_reg[1] = data;
1155         if (state->m_mmc_latch1 == 0xfe)
1156            chr4_0(space->machine(), state->m_mmc_reg[1], CHRROM);
1157         break;
1158      case 0x5000:
1159         state->m_mmc_reg[2] = data;
1160         if (state->m_mmc_latch2 == 0xfd)
1161            chr4_4(space->machine(), state->m_mmc_reg[2], CHRROM);
1162         break;
1163      case 0x6000:
1164         state->m_mmc_reg[3] = data;
1165         if (state->m_mmc_latch2 == 0xfe)
1166            chr4_4(space->machine(), state->m_mmc_reg[3], CHRROM);
1167         break;
1168      case 0x7000:
1169         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1170         break;
1171      default:
1172         LOG_MMC(("MMC2 uncaught w: %04x:%02x\n", offset, data));
1173         break;
1174   }
1175}
1176
1177/*************************************************************
1178
1179 FxROM (MMC4 based) board emulation
1180
1181 Games: Famicom Wars, Fire Emblem, Fire Emblem Gaiden
1182
1183 iNES: mapper 10
1184
1185 In MESS: Supported
1186
1187*************************************************************/
1188
1189static WRITE8_HANDLER( fxrom_w )
1190{
1191   LOG_MMC(("fxrom_w, offset: %04x, data: %02x\n", offset, data));
1192   switch (offset & 0x7000)
1193   {
1194      case 0x2000:
1195         prg16_89ab(space->machine(), data);
1196         break;
1197      default:
1198         pxrom_w(space, offset, data);
1199         break;
1200   }
1201}
1202
1203/*************************************************************
1204
1205 TxROM (MMC3 based) board emulation
1206
1207 iNES: mapper 4
1208
1209 *************************************************************/
1210
1211static void mmc3_set_wram( address_space *space )
1212{
1213   running_machine &machine = space->machine();
1214   nes_state *state = machine.driver_data<nes_state>();
1215
1216   // skip this function if we are emulating a MMC3 clone with mid writes
1217   if (state->m_mmc_write_mid != NULL)
1218      return;
1219
1220   if (BIT(state->m_mmc3_wram_protect, 7))
1221      space->install_readwrite_bank(0x6000, 0x7fff, "bank5");
1222   else
1223   {
1224      space->unmap_readwrite(0x6000, 0x7fff);
1225      return;
1226   }
1227
1228   if (!BIT(state->m_mmc3_wram_protect, 6))
1229      space->install_write_bank(0x6000, 0x7fff, "bank5");
1230   else
1231   {
1232      space->unmap_write(0x6000, 0x7fff);
1233      return;
1234   }
1235}
1236
1237static void mmc3_set_prg( running_machine &machine, int prg_base, int prg_mask )
1238{
1239   nes_state *state = machine.driver_data<nes_state>();
1240   UINT8 prg_flip = (state->m_mmc3_latch & 0x40) ? 2 : 0;
1241
1242   state->m_mmc3_prg_cb(machine, 0, prg_base | (state->m_mmc_prg_bank[0 ^ prg_flip] & prg_mask));
1243   state->m_mmc3_prg_cb(machine, 1, prg_base | (state->m_mmc_prg_bank[1] & prg_mask));
1244   state->m_mmc3_prg_cb(machine, 2, prg_base | (state->m_mmc_prg_bank[2 ^ prg_flip] & prg_mask));
1245   state->m_mmc3_prg_cb(machine, 3, prg_base | (state->m_mmc_prg_bank[3] & prg_mask));
1246}
1247
1248static void mmc3_set_chr( running_machine &machine, UINT8 chr, int chr_base, int chr_mask )
1249{
1250   nes_state *state = machine.driver_data<nes_state>();
1251   UINT8 chr_page = (state->m_mmc3_latch & 0x80) >> 5;
1252
1253   state->m_mmc3_chr_cb(machine, chr_page ^ 0, chr_base | ((state->m_mmc_vrom_bank[0] & ~0x01) & chr_mask), chr);
1254   state->m_mmc3_chr_cb(machine, chr_page ^ 1, chr_base | ((state->m_mmc_vrom_bank[0] |  0x01) & chr_mask), chr);
1255   state->m_mmc3_chr_cb(machine, chr_page ^ 2, chr_base | ((state->m_mmc_vrom_bank[1] & ~0x01) & chr_mask), chr);
1256   state->m_mmc3_chr_cb(machine, chr_page ^ 3, chr_base | ((state->m_mmc_vrom_bank[1] |  0x01) & chr_mask), chr);
1257   state->m_mmc3_chr_cb(machine, chr_page ^ 4, chr_base | (state->m_mmc_vrom_bank[2] & chr_mask), chr);
1258   state->m_mmc3_chr_cb(machine, chr_page ^ 5, chr_base | (state->m_mmc_vrom_bank[3] & chr_mask), chr);
1259   state->m_mmc3_chr_cb(machine, chr_page ^ 6, chr_base | (state->m_mmc_vrom_bank[4] & chr_mask), chr);
1260   state->m_mmc3_chr_cb(machine, chr_page ^ 7, chr_base | (state->m_mmc_vrom_bank[5] & chr_mask), chr);
1261}
1262
1263/* Here, IRQ counter decrements every scanline. */
1264static void mmc3_irq( device_t *device, int scanline, int vblank, int blanked )
1265{
1266   nes_state *state = device->machine().driver_data<nes_state>();
1267
1268   if (scanline < PPU_BOTTOM_VISIBLE_SCANLINE)
1269   {
1270      int priorCount = state->m_IRQ_count;
1271      if ((state->m_IRQ_count == 0) || state->m_IRQ_clear)
1272         state->m_IRQ_count = state->m_IRQ_count_latch;
1273      else
1274         state->m_IRQ_count--;
1275
1276      if (state->m_IRQ_enable && !blanked && (state->m_IRQ_count == 0) && (priorCount || state->m_IRQ_clear /*|| !state->m_mmc3_alt_irq*/)) // according to blargg the latter should be present as well, but it breaks Rampart and Joe & Mac US: they probably use the alt irq!
1277      {
1278         LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
1279                device->machine().primary_screen->vpos(), device->machine().primary_screen->hpos()));
1280         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
1281      }
1282   }
1283   state->m_IRQ_clear = 0;
1284}
1285
1286static WRITE8_HANDLER( txrom_w )
1287{
1288   nes_state *state = space->machine().driver_data<nes_state>();
1289   UINT8 mmc_helper, cmd;
1290
1291   LOG_MMC(("txrom_w, offset: %04x, data: %02x\n", offset, data));
1292
1293   switch (offset & 0x6001)
1294   {
1295      case 0x0000:
1296         mmc_helper = state->m_mmc3_latch ^ data;
1297         state->m_mmc3_latch = data;
1298
1299         /* Has PRG Mode changed? */
1300         if (mmc_helper & 0x40)
1301            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
1302
1303         /* Has CHR Mode changed? */
1304         if (mmc_helper & 0x80)
1305            mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
1306         break;
1307
1308      case 0x0001:
1309         cmd = state->m_mmc3_latch & 0x07;
1310         switch (cmd)
1311         {
1312         case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
1313         case 2: case 3: case 4: case 5:
1314            state->m_mmc_vrom_bank[cmd] = data;
1315            mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
1316            break;
1317         case 6:
1318         case 7:
1319            state->m_mmc_prg_bank[cmd - 6] = data;
1320            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
1321            break;
1322         }
1323         break;
1324
1325      case 0x2000:
1326         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1327         break;
1328
1329      case 0x2001:
1330         state->m_mmc3_wram_protect = data;
1331         mmc3_set_wram(space);
1332         break;
1333
1334      case 0x4000:
1335         state->m_IRQ_count_latch = data;
1336         break;
1337
1338      case 0x4001:
1339         state->m_IRQ_count = 0;
1340         break;
1341
1342      case 0x6000:
1343         state->m_IRQ_enable = 0;
1344         break;
1345
1346      case 0x6001:
1347         state->m_IRQ_enable = 1;
1348         break;
1349
1350      default:
1351         logerror("txrom_w uncaught: %04x value: %02x\n", offset + 0x8000, data);
1352         break;
1353   }
1354}
1355
1356/*************************************************************
1357
1358 HKROM (MMC6 based) board emulation
1359
1360 iNES: mapper 4
1361
1362 *************************************************************/
1363
1364static WRITE8_HANDLER( hkrom_m_w )
1365{
1366   nes_state *state = space->machine().driver_data<nes_state>();
1367   UINT8 write_hi, write_lo;
1368   LOG_MMC(("hkrom_m_w, offset: %04x, data: %02x\n", offset, data));
1369
1370   if (offset < 0x1000)
1371      return;
1372
1373   // banks can be written only if both read & write is enabled!
1374   write_hi = ((state->m_mmc6_reg & 0xc0) == 0xc0);
1375   write_lo = ((state->m_mmc6_reg & 0x30) == 0x30);
1376
1377   if (BIT(offset, 9) && write_hi)   // access to upper 1k
1378      state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)] = data;
1379
1380   if (!BIT(offset, 9) && write_lo)   // access to lower 1k
1381      state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)] = data;
1382}
1383
1384static READ8_HANDLER( hkrom_m_r )
1385{
1386   nes_state *state = space->machine().driver_data<nes_state>();
1387   LOG_MMC(("hkrom_m_r, offset: %04x\n", offset));
1388
1389   if (offset < 0x1000)
1390      return 0xff;   // here it should be open bus
1391
1392   if (!(state->m_mmc6_reg & 0xa0))
1393      return 0xff;   // here it should be open bus
1394
1395   if (BIT(offset, 9) && BIT(state->m_mmc6_reg, 7))   // access to upper 1k when upper read is enabled
1396      return state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)];
1397
1398   if (!BIT(offset, 9) && BIT(state->m_mmc6_reg, 5))   // access to lower 1k when lower read is enabled
1399      return state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)];
1400
1401   // If only one bank is enabled for reading, the other reads back as zero
1402   return 0x00;
1403}
1404
1405static WRITE8_HANDLER( hkrom_w )
1406{
1407   nes_state *state = space->machine().driver_data<nes_state>();
1408   UINT8 mmc6_helper;
1409   LOG_MMC(("hkrom_w, offset: %04x, data: %02x\n", offset, data));
1410
1411   switch (offset & 0x6001)
1412   {
1413      case 0x0000:
1414         mmc6_helper = state->m_mmc3_latch ^ data;
1415         state->m_mmc3_latch = data;
1416
1417         if (!state->m_mmc_latch2 && BIT(data, 5))   // if WRAM is disabled and has to be enabled, write
1418            state->m_mmc_latch2 = BIT(data, 5);   // (once WRAM has been enabled, it cannot be disabled without resetting the game)
1419
1420         /* Has PRG Mode changed? */
1421         if (BIT(mmc6_helper, 6))
1422            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
1423
1424         /* Has CHR Mode changed? */
1425         if (BIT(mmc6_helper, 7))
1426            mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
1427         break;
1428
1429      case 0x2001:
1430         if (state->m_mmc_latch2)
1431            state->m_mmc6_reg = data;
1432         break;
1433
1434      case 0x4001:
1435         state->m_IRQ_count = 0;
1436         state->m_IRQ_clear = 1;
1437         break;
1438
1439      default:
1440         txrom_w(space, offset, data);
1441         break;
1442   }
1443}
1444
1445/*************************************************************
1446
1447 TxSROM (MMC3 based) board emulation
1448
1449 Games: Armadillo, Play Action Football, Pro Hockey, RPG
1450 Jinsei Game, Y's 3
1451
1452 iNES: mapper 118
1453
1454 In MESS: Supported. It also uses mmc3_irq.
1455
1456 *************************************************************/
1457
1458static void txsrom_set_mirror( running_machine &machine )
1459{
1460   nes_state *state = machine.driver_data<nes_state>();
1461   if (state->m_mmc3_latch & 0x80)
1462   {
1463      set_nt_page(machine, 0, CIRAM, (state->m_mmc_vrom_bank[2] & 0x80) >> 7, 1);
1464      set_nt_page(machine, 1, CIRAM, (state->m_mmc_vrom_bank[3] & 0x80) >> 7, 1);
1465      set_nt_page(machine, 2, CIRAM, (state->m_mmc_vrom_bank[4] & 0x80) >> 7, 1);
1466      set_nt_page(machine, 3, CIRAM, (state->m_mmc_vrom_bank[5] & 0x80) >> 7, 1);
1467   }
1468   else
1469   {
1470      set_nt_page(machine, 0, CIRAM, (state->m_mmc_vrom_bank[0] & 0x80) >> 7, 1);
1471      set_nt_page(machine, 1, CIRAM, (state->m_mmc_vrom_bank[0] & 0x80) >> 7, 1);
1472      set_nt_page(machine, 2, CIRAM, (state->m_mmc_vrom_bank[1] & 0x80) >> 7, 1);
1473      set_nt_page(machine, 3, CIRAM, (state->m_mmc_vrom_bank[1] & 0x80) >> 7, 1);
1474   }
1475}
1476
1477static void txsrom_chr_cb( running_machine &machine, int start, int bank, int source )
1478{
1479   txsrom_set_mirror(machine);   // we could probably update only for one (e.g. the first) call, to slightly optimize the code
1480   chr1_x(machine, start, bank, source);
1481}
1482
1483static WRITE8_HANDLER( txsrom_w )
1484{
1485   LOG_MMC(("txsrom_w, offset: %04x, data: %02x\n", offset, data));
1486
1487   switch (offset & 0x6001)
1488   {
1489      case 0x2000:
1490         break;
1491
1492      default:
1493         txrom_w(space, offset, data);
1494         break;
1495   }
1496}
1497
1498/*************************************************************
1499
1500 TQROM (MMC3 based) board emulation
1501
1502 Games: Pin Bot, High Speed
1503
1504 iNES: mapper 119
1505
1506 In MESS: Supported. It also uses mmc3_irq.
1507
1508 *************************************************************/
1509
1510static void tqrom_set_chr( running_machine &machine )
1511{
1512   nes_state *state = machine.driver_data<nes_state>();
1513   UINT8 chr_page = (state->m_mmc3_latch & 0x80) >> 5;
1514   UINT8 chr_src[6], chr_mask[6];
1515   int i;
1516
1517   for (i = 0; i < 6; i++)
1518   {
1519      chr_src[i] = (state->m_mmc_vrom_bank[i] & 0x40) ? CHRRAM : CHRROM;
1520      chr_mask[i] =  (state->m_mmc_vrom_bank[i] & 0x40) ? 0x07 : 0x3f;
1521   }
1522
1523   chr1_x(machine, chr_page ^ 0, ((state->m_mmc_vrom_bank[0] & ~0x01) & chr_mask[0]), chr_src[0]);
1524   chr1_x(machine, chr_page ^ 1, ((state->m_mmc_vrom_bank[0] |  0x01) & chr_mask[0]), chr_src[0]);
1525   chr1_x(machine, chr_page ^ 2, ((state->m_mmc_vrom_bank[1] & ~0x01) & chr_mask[1]), chr_src[1]);
1526   chr1_x(machine, chr_page ^ 3, ((state->m_mmc_vrom_bank[1] |  0x01) & chr_mask[1]), chr_src[1]);
1527   chr1_x(machine, chr_page ^ 4, (state->m_mmc_vrom_bank[2] & chr_mask[2]), chr_src[2]);
1528   chr1_x(machine, chr_page ^ 5, (state->m_mmc_vrom_bank[3] & chr_mask[3]), chr_src[3]);
1529   chr1_x(machine, chr_page ^ 6, (state->m_mmc_vrom_bank[4] & chr_mask[4]), chr_src[4]);
1530   chr1_x(machine, chr_page ^ 7, (state->m_mmc_vrom_bank[5] & chr_mask[5]), chr_src[5]);
1531}
1532
1533static WRITE8_HANDLER( tqrom_w )
1534{
1535   nes_state *state = space->machine().driver_data<nes_state>();
1536   UINT8 mmc_helper, cmd;
1537   LOG_MMC(("tqrom_w, offset: %04x, data: %02x\n", offset, data));
1538
1539   switch (offset & 0x6001)
1540   {
1541      case 0x0000:
1542         mmc_helper = state->m_mmc3_latch ^ data;
1543         state->m_mmc3_latch = data;
1544
1545         /* Has PRG Mode changed? */
1546         if (mmc_helper & 0x40)
1547            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
1548
1549         /* Has CHR Mode changed? */
1550         if (mmc_helper & 0x80)
1551            tqrom_set_chr(space->machine());
1552         break;
1553      case 0x0001: /* $8001 */
1554         cmd = state->m_mmc3_latch & 0x07;
1555         switch (cmd)
1556         {
1557         case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
1558         case 2: case 3: case 4: case 5:
1559            state->m_mmc_vrom_bank[cmd] = data;
1560            tqrom_set_chr(space->machine());
1561            break;
1562         case 6:
1563         case 7:
1564            state->m_mmc_prg_bank[cmd - 6] = data;
1565            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
1566            break;
1567         }
1568         break;
1569
1570      default:
1571         txrom_w(space, offset, data);
1572         break;
1573   }
1574}
1575
1576/*************************************************************
1577
1578 PAL-ZZ board (MMC3 variant for European 3-in-1 Nintendo cart
1579 Super Mario Bros. + Tetris + Nintendo World Cup)
1580
1581 iNES: mapper 37
1582
1583 *************************************************************/
1584
1585static WRITE8_HANDLER( zz_m_w )
1586{
1587   nes_state *state = space->machine().driver_data<nes_state>();
1588   UINT8 mmc_helper = data & 0x07;
1589   LOG_MMC(("zz_m_w, offset: %04x, data: %02x\n", offset, data));
1590
1591   state->m_mmc_prg_base = (BIT(mmc_helper, 2) << 4) | (((mmc_helper & 0x03) == 0x03) ? 0x08 : 0);
1592   state->m_mmc_prg_mask = (mmc_helper << 1) | 0x07;
1593   state->m_mmc_chr_base = BIT(mmc_helper, 2) << 7;
1594   state->m_mmc_chr_mask = 0x7f;
1595   mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
1596   mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
1597}
1598
1599/*************************************************************
1600
1601 NES-QJ board (MMC3 variant for US 2-in-1 Nintendo cart
1602 Super Spike V'Ball + Nintendo World Cup)
1603
1604 iNES: mapper 47
1605
1606 *************************************************************/
1607
1608static WRITE8_HANDLER( qj_m_w )
1609{
1610   nes_state *state = space->machine().driver_data<nes_state>();
1611   LOG_MMC(("qj_m_w, offset: %04x, data: %02x\n", offset, data));
1612
1613   state->m_mmc_prg_base = BIT(data, 0) << 4;
1614   state->m_mmc_prg_mask = 0x0f;
1615   state->m_mmc_chr_base = BIT(data, 0) << 7;
1616   state->m_mmc_chr_mask = 0x7f;
1617   mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
1618   mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
1619}
1620
1621/*************************************************************
1622
1623 ExROM (MMC5 based) board emulation
1624
1625 Games: Castlevania III, Just Breed, many Koei titles
1626
1627 iNES: mapper 5
1628
1629 MESS status: Mostly Unsupported
1630
1631 *************************************************************/
1632
1633#if 0
1634static void mmc5_update_chr_a( running_machine &machine )
1635{
1636   nes_state *state = machine.driver_data<nes_state>();
1637   switch (state->m_mmc5_chr_mode)
1638   {
1639      case 0:   // 8k banks
1640         chr8(machine, state->m_mmc5_vrom_regA[7] & 0xff, CHRROM);
1641         break;
1642
1643      case 1:   // 4k banks
1644         chr4_0(machine, state->m_mmc5_vrom_regA[3] & 0xff, CHRROM);
1645         chr4_4(machine, state->m_mmc5_vrom_regA[7] & 0xff, CHRROM);
1646         break;
1647
1648      case 2:   // 2k banks
1649         chr2_0(machine, state->m_mmc5_vrom_regA[1], CHRROM);
1650         chr2_2(machine, state->m_mmc5_vrom_regA[3], CHRROM);
1651         chr2_4(machine, state->m_mmc5_vrom_regA[5], CHRROM);
1652         chr2_6(machine, state->m_mmc5_vrom_regA[7], CHRROM);
1653         break;
1654
1655      case 3:   // 1k banks
1656         chr1_0(machine, state->m_mmc5_vrom_regA[0], CHRROM);
1657         chr1_1(machine, state->m_mmc5_vrom_regA[1], CHRROM);
1658         chr1_2(machine, state->m_mmc5_vrom_regA[2], CHRROM);
1659         chr1_3(machine, state->m_mmc5_vrom_regA[3], CHRROM);
1660         chr1_4(machine, state->m_mmc5_vrom_regA[4], CHRROM);
1661         chr1_5(machine, state->m_mmc5_vrom_regA[5], CHRROM);
1662         chr1_6(machine, state->m_mmc5_vrom_regA[6], CHRROM);
1663         chr1_7(machine, state->m_mmc5_vrom_regA[7], CHRROM);
1664         break;
1665   }
1666}
1667
1668static void mmc5_update_chr_b( running_machine &machine )
1669{
1670   nes_state *state = machine.driver_data<nes_state>();
1671   switch (state->m_mmc5_chr_mode)
1672   {
1673      case 0:   // 8k banks
1674         chr8(machine, state->m_mmc5_vrom_regB[3] & 0xff, CHRROM);
1675         break;
1676
1677      case 1:   // 4k banks
1678         chr4_0(machine, state->m_mmc5_vrom_regB[3] & 0xff, CHRROM);
1679         chr4_4(machine, state->m_mmc5_vrom_regB[3] & 0xff, CHRROM);
1680         break;
1681
1682      case 2:   // 2k banks
1683         chr2_0(machine, state->m_mmc5_vrom_regB[1], CHRROM);
1684         chr2_2(machine, state->m_mmc5_vrom_regB[3], CHRROM);
1685         chr2_4(machine, state->m_mmc5_vrom_regB[1], CHRROM);
1686         chr2_6(machine, state->m_mmc5_vrom_regB[3], CHRROM);
1687         break;
1688
1689      case 3:   // 1k banks
1690         chr1_0(machine, state->m_mmc5_vrom_regB[0], CHRROM);
1691         chr1_1(machine, state->m_mmc5_vrom_regB[1], CHRROM);
1692         chr1_2(machine, state->m_mmc5_vrom_regB[2], CHRROM);
1693         chr1_3(machine, state->m_mmc5_vrom_regB[3], CHRROM);
1694         chr1_4(machine, state->m_mmc5_vrom_regB[0], CHRROM);
1695         chr1_5(machine, state->m_mmc5_vrom_regB[1], CHRROM);
1696         chr1_6(machine, state->m_mmc5_vrom_regB[2], CHRROM);
1697         chr1_7(machine, state->m_mmc5_vrom_regB[3], CHRROM);
1698         break;
1699   }
1700}
1701#endif
1702
1703static void mmc5_update_prg( running_machine &machine )
1704{
1705   nes_state *state = machine.driver_data<nes_state>();
1706   int bank1, bank2, bank3;
1707
1708   switch (state->m_mmc5_prg_mode)
1709   {
1710      case 0:   // 32k banks
1711         prg32(machine, state->m_mmc5_prg_regs[3] >> 2);
1712         break;
1713
1714      case 1:   // 16k banks
1715         //          printf("problema 1: %x\n", state->m_mmc5_prg_regs[1]);
1716         bank1 = state->m_mmc5_prg_regs[1];
1717
1718         if (!BIT(bank1, 7))
1719         {
1720            state->m_prg_bank[0] = state->m_prg_chunks + (bank1 & 0x06);
1721            state->m_prg_bank[1] = state->m_prg_chunks + (bank1 & 0x06) + 1;
1722            memory_set_bank(machine, "bank1", state->m_prg_bank[0]);
1723            memory_set_bank(machine, "bank2", state->m_prg_bank[1]);
1724         }
1725         else
1726            prg16_89ab(machine, bank1 >> 1);
1727
1728         prg16_cdef(machine, state->m_mmc5_prg_regs[3] >> 1);
1729         break;
1730
1731      case 2:   // 16k-8k banks
1732         //          printf("problema 2: %x %x\n", state->m_mmc5_prg_regs[1], state->m_mmc5_prg_regs[2]);
1733         bank1 = state->m_mmc5_prg_regs[1];
1734         bank3 = state->m_mmc5_prg_regs[2];
1735
1736         if (!BIT(bank1, 7))
1737         {
1738            state->m_prg_bank[0] = state->m_prg_chunks + (bank1 & 0x06);
1739            state->m_prg_bank[1] = state->m_prg_chunks + (bank1 & 0x06) + 1;
1740            memory_set_bank(machine, "bank1", state->m_prg_bank[0]);
1741            memory_set_bank(machine, "bank2", state->m_prg_bank[1]);
1742         }
1743         else
1744            prg16_89ab(machine, (bank1 & 0x7f) >> 1);
1745
1746         if (!BIT(bank3, 7))
1747         {
1748            state->m_prg_bank[2] = state->m_prg_chunks + (bank3 & 0x07);
1749            memory_set_bank(machine, "bank3", state->m_prg_bank[2]);
1750         }
1751         else
1752            prg8_cd(machine, bank3 & 0x7f);
1753
1754         prg8_ef(machine, state->m_mmc5_prg_regs[3]);
1755         break;
1756
1757      case 3:   // 8k banks
1758         //          printf("problema 3: %x %x %x\n", state->m_mmc5_prg_regs[0], state->m_mmc5_prg_regs[1], state->m_mmc5_prg_regs[2]);
1759         bank1 = state->m_mmc5_prg_regs[0];
1760         bank2 = state->m_mmc5_prg_regs[1];
1761         bank3 = state->m_mmc5_prg_regs[2];
1762
1763         if (!BIT(bank1, 7))
1764         {
1765            state->m_prg_bank[0] = state->m_prg_chunks + (bank1 & 0x07);
1766            memory_set_bank(machine, "bank1", state->m_prg_bank[0]);
1767         }
1768         else
1769            prg8_89(machine, bank1 & 0x7f);
1770
1771         if (!BIT(bank2, 7))
1772         {
1773            state->m_prg_bank[1] = state->m_prg_chunks + (bank2 & 0x07);
1774            memory_set_bank(machine, "bank2", state->m_prg_bank[1]);
1775         }
1776         else
1777            prg8_ab(machine, bank2 & 0x7f);
1778
1779         if (!BIT(bank3, 7))
1780         {
1781            state->m_prg_bank[2] = state->m_prg_chunks + (bank3 & 0x07);
1782            memory_set_bank(machine, "bank3", state->m_prg_bank[2]);
1783         }
1784         else
1785            prg8_cd(machine, bank3 & 0x7f);
1786
1787         prg8_ef(machine, state->m_mmc5_prg_regs[3]);
1788         break;
1789   }
1790}
1791
1792static void mmc5_update_render_mode( running_machine &machine )
1793{
1794}
1795
1796static void mmc5_irq( device_t *device, int scanline, int vblank, int blanked )
1797{
1798   nes_state *state = device->machine().driver_data<nes_state>();
1799
1800#if 1
1801   if (scanline == 0)
1802      state->m_IRQ_status |= 0x40;
1803   else if (scanline > PPU_BOTTOM_VISIBLE_SCANLINE)
1804      state->m_IRQ_status &= ~0x40;
1805#endif
1806
1807   if (scanline == state->m_IRQ_count)
1808   {
1809      if (state->m_IRQ_enable)
1810         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
1811
1812      state->m_IRQ_status = 0xff;
1813   }
1814
1815   /* FIXME: this is ok, but then we would need to update them again when we have the BG Hblank
1816     I leave it commented out until the PPU is updated for this */
1817   //  if (ppu2c0x_is_sprite_8x16(state->m_ppu) || state->m_mmc5_last_chr_a)
1818   //      mmc5_update_chr_a(device->machine());
1819   //  else
1820   //      mmc5_update_chr_b(device->machine());
1821}
1822
1823static void mmc5_ppu_mirror( running_machine &machine, int page, int src )
1824{
1825   switch (src)
1826   {
1827      case 0:   /* CIRAM0 */
1828         set_nt_page(machine, page, CIRAM, 0, 1);
1829         break;
1830      case 1:   /* CIRAM1 */
1831         set_nt_page(machine, page, CIRAM, 1, 1);
1832         break;
1833      case 2:   /* ExRAM */
1834         set_nt_page(machine, page, EXRAM, 0, 1);   // actually only works during rendering.
1835         break;
1836      case 3: /* Fill Registers */
1837         set_nt_page(machine, page, MMC5FILL, 0, 0);
1838         break;
1839      default:
1840         fatalerror("This should never happen");
1841         break;
1842   }
1843}
1844
1845static READ8_HANDLER( exrom_l_r )
1846{
1847   nes_state *state = space->machine().driver_data<nes_state>();
1848   int retVal;
1849
1850   /* $5c00 - $5fff: extended videoram attributes */
1851   if ((offset >= 0x1b00) && (offset <= 0x1eff))
1852   {
1853      return state->m_mapper_ram[offset - 0x1b00];
1854   }
1855
1856   switch (offset)
1857   {
1858      case 0x1104: /* $5204 */
1859#if 0
1860         if (current_scanline == MMC5_scanline)
1861            return 0x80;
1862         else
1863            return 0x00;
1864#else
1865         retVal = state->m_IRQ_status;
1866         state->m_IRQ_status &= ~0x80;
1867         return retVal;
1868#endif
1869
1870      case 0x1105: /* $5205 */
1871         return (state->m_mult1 * state->m_mult2) & 0xff;
1872      case 0x1106: /* $5206 */
1873         return ((state->m_mult1 * state->m_mult2) & 0xff00) >> 8;
1874
1875      default:
1876         logerror("** MMC5 uncaught read, offset: %04x\n", offset + 0x4100);
1877         return 0x00;
1878   }
1879}
1880
1881
1882static WRITE8_HANDLER( exrom_l_w )
1883{
1884   nes_state *state = space->machine().driver_data<nes_state>();
1885
1886   //  LOG_MMC(("Mapper 5 write, offset: %04x, data: %02x\n", offset + 0x4100, data));
1887   /* Send $5000-$5015 to the sound chip */
1888   if ((offset >= 0xf00) && (offset <= 0xf15))
1889   {
1890      nes_psg_w(state->m_sound, offset & 0x1f, data);
1891      return;
1892   }
1893
1894   /* $5c00 - $5fff: extended videoram attributes */
1895   if ((offset >= 0x1b00) && (offset <= 0x1eff))
1896   {
1897      if (state->m_MMC5_vram_protect == 0x03)
1898         state->m_mapper_ram[offset - 0x1b00] = data;
1899      return;
1900   }
1901
1902   switch (offset)
1903   {
1904      case 0x1000: /* $5100 */
1905         state->m_mmc5_prg_mode = data & 0x03;
1906         //          mmc5_update_prg(space->machine());
1907         LOG_MMC(("MMC5 rom bank mode: %02x\n", data));
1908         break;
1909
1910      case 0x1001: /* $5101 */
1911         state->m_mmc5_chr_mode = data & 0x03;
1912         // update chr
1913         LOG_MMC(("MMC5 vrom bank mode: %02x\n", data));
1914         break;
1915
1916      case 0x1002: /* $5102 */
1917         if (data == 0x02)
1918            state->m_MMC5_vram_protect |= 1;
1919         else
1920            state->m_MMC5_vram_protect = 0;
1921         LOG_MMC(("MMC5 vram protect 1: %02x\n", data));
1922         break;
1923      case 0x1003: /* 5103 */
1924         if (data == 0x01)
1925            state->m_MMC5_vram_protect |= 2;
1926         else
1927            state->m_MMC5_vram_protect = 0;
1928         LOG_MMC(("MMC5 vram protect 2: %02x\n", data));
1929         break;
1930
1931      case 0x1004: /* $5104 - Extra VRAM (EXRAM) control */
1932         state->m_mmc5_vram_control = data & 0x03;
1933         // update render
1934         mmc5_update_render_mode(space->machine());
1935         LOG_MMC(("MMC5 exram control: %02x\n", data));
1936         break;
1937
1938      case 0x1005: /* $5105 */
1939         mmc5_ppu_mirror(space->machine(), 0, data & 0x03);
1940         mmc5_ppu_mirror(space->machine(), 1, (data & 0x0c) >> 2);
1941         mmc5_ppu_mirror(space->machine(), 2, (data & 0x30) >> 4);
1942         mmc5_ppu_mirror(space->machine(), 3, (data & 0xc0) >> 6);
1943         // update render
1944         mmc5_update_render_mode(space->machine());
1945         break;
1946
1947         /* tile data for MMC5 flood-fill NT mode */
1948      case 0x1006:
1949         state->m_MMC5_floodtile = data;
1950         break;
1951
1952         /* attr data for MMC5 flood-fill NT mode */
1953      case 0x1007:
1954         switch (data & 3)
1955      {
1956         default:
1957         case 0: state->m_MMC5_floodattr = 0x00; break;
1958         case 1: state->m_MMC5_floodattr = 0x55; break;
1959         case 2: state->m_MMC5_floodattr = 0xaa; break;
1960         case 3: state->m_MMC5_floodattr = 0xff; break;
1961      }
1962         break;
1963
1964      case 0x1013: /* $5113 */
1965         LOG_MMC(("MMC5 mid RAM bank select: %02x\n", data & 0x07));
1966         // FIXME: a few Koei games have both WRAM & BWRAM but here we don't support this (yet)
1967         if (state->m_battery)
1968            wram_bank(space->machine(), data, NES_BATTERY);
1969         else
1970            wram_bank(space->machine(), data, NES_WRAM);
1971         break;
1972
1973
1974      case 0x1014: /* $5114 */
1975      case 0x1015: /* $5115 */
1976      case 0x1016: /* $5116 */
1977      case 0x1017: /* $5117 */
1978         state->m_mmc5_prg_regs[offset & 3] = data;
1979         mmc5_update_prg(space->machine());
1980         break;
1981
1982#if 0
1983      // these do not work as expected... I guess we definitely need the bank update at proper times (with BG vs. sprite timing)
1984      case 0x1020: /* $5120 */
1985      case 0x1021: /* $5121 */
1986      case 0x1022: /* $5122 */
1987      case 0x1023: /* $5123 */
1988      case 0x1024: /* $5124 */
1989      case 0x1025: /* $5125 */
1990      case 0x1026: /* $5126 */
1991      case 0x1027: /* $5127 */
1992         data |= (state->m_mmc5_chr_high << 8);
1993         if (!state->m_mmc5_last_chr_a)
1994         {
1995            state->m_mmc5_vrom_regA[offset & 0x07] = data;
1996            state->m_mmc5_last_chr_a = 1;
1997            if (ppu2c0x_get_current_scanline(state->m_ppu) == 240 || !ppu2c0x_is_sprite_8x16(state->m_ppu))
1998               mmc5_update_chr_a(space->machine());
1999         }
2000         break;
2001
2002
2003      case 0x1028: /* $5128 */
2004      case 0x1029: /* $5129 */
2005      case 0x102a: /* $512a */
2006      case 0x102b: /* $512b */
2007         data |= (state->m_mmc5_chr_high << 8);
2008         state->m_mmc5_vrom_regB[offset & 0x03] = data;
2009         state->m_mmc5_last_chr_a = 0;
2010         if (ppu2c0x_get_current_scanline(state->m_ppu) == 240 || !ppu2c0x_is_sprite_8x16(state->m_ppu))
2011            mmc5_update_chr_b(space->machine());
2012         break;
2013
2014      case 0x1030: /* $5130 */
2015         state->m_mmc5_chr_high = data & 0x03;
2016         if (state->m_mmc5_vram_control == 1)
2017         {
2018            // in this case state->m_mmc5_chr_high selects which 256KB of CHR ROM
2019            // is to be used for all background tiles on the screen.
2020         }
2021         break;
2022
2023#endif
2024
2025      case 0x1020: /* $5120 */
2026         LOG_MMC(("MMC5 $5120 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2027         switch (state->m_mmc5_chr_mode)
2028      {
2029         case 0x03:
2030            /* 1k switch */
2031            state->m_MMC5_vrom_bank[0] = data | (state->m_mmc5_high_chr << 8);
2032            //                  mapper5_sync_vrom(0);
2033            chr1_0(space->machine(), state->m_MMC5_vrom_bank[0], CHRROM);
2034            //                  state->m_nes_vram_sprite[0] = state->m_MMC5_vrom_bank[0] * 64;
2035            //                  vrom_next[0] = 4;
2036            //                  vrom_page_a = 1;
2037            //                  vrom_page_b = 0;
2038            break;
2039      }
2040         break;
2041      case 0x1021: /* $5121 */
2042         LOG_MMC(("MMC5 $5121 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2043         switch (state->m_mmc5_chr_mode)
2044      {
2045         case 0x02:
2046            /* 2k switch */
2047            chr2_0(space->machine(), data | (state->m_mmc5_high_chr << 8), CHRROM);
2048            break;
2049         case 0x03:
2050            /* 1k switch */
2051            state->m_MMC5_vrom_bank[1] = data | (state->m_mmc5_high_chr << 8);
2052            //                  mapper5_sync_vrom(0);
2053            chr1_1(space->machine(), state->m_MMC5_vrom_bank[1], CHRROM);
2054            //                  state->m_nes_vram_sprite[1] = state->m_MMC5_vrom_bank[0] * 64;
2055            //                  vrom_next[1] = 5;
2056            //                  vrom_page_a = 1;
2057            //                  vrom_page_b = 0;
2058            break;
2059      }
2060         break;
2061      case 0x1022: /* $5122 */
2062         LOG_MMC(("MMC5 $5122 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2063         switch (state->m_mmc5_chr_mode)
2064      {
2065         case 0x03:
2066            /* 1k switch */
2067            state->m_MMC5_vrom_bank[2] = data | (state->m_mmc5_high_chr << 8);
2068            //                  mapper5_sync_vrom(0);
2069            chr1_2(space->machine(), state->m_MMC5_vrom_bank[2], CHRROM);
2070            //                  state->m_nes_vram_sprite[2] = state->m_MMC5_vrom_bank[0] * 64;
2071            //                  vrom_next[2] = 6;
2072            //                  vrom_page_a = 1;
2073            //                  vrom_page_b = 0;
2074            break;
2075      }
2076         break;
2077      case 0x1023: /* $5123 */
2078         LOG_MMC(("MMC5 $5123 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2079         switch (state->m_mmc5_chr_mode)
2080      {
2081         case 0x01:
2082            chr4_0(space->machine(), data, CHRROM);
2083            break;
2084         case 0x02:
2085            /* 2k switch */
2086            chr2_2(space->machine(), data | (state->m_mmc5_high_chr << 8), CHRROM);
2087            break;
2088         case 0x03:
2089            /* 1k switch */
2090            state->m_MMC5_vrom_bank[3] = data | (state->m_mmc5_high_chr << 8);
2091            //                  mapper5_sync_vrom(0);
2092            chr1_3(space->machine(), state->m_MMC5_vrom_bank[3], CHRROM);
2093            //                  state->m_nes_vram_sprite[3] = state->m_MMC5_vrom_bank[0] * 64;
2094            //                  vrom_next[3] = 7;
2095            //                  vrom_page_a = 1;
2096            //                  vrom_page_b = 0;
2097            break;
2098      }
2099         break;
2100      case 0x1024: /* $5124 */
2101         LOG_MMC(("MMC5 $5124 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2102         switch (state->m_mmc5_chr_mode)
2103      {
2104         case 0x03:
2105            /* 1k switch */
2106            state->m_MMC5_vrom_bank[4] = data | (state->m_mmc5_high_chr << 8);
2107            //                  mapper5_sync_vrom(0);
2108            chr1_4(space->machine(), state->m_MMC5_vrom_bank[4], CHRROM);
2109            //                  state->m_nes_vram_sprite[4] = state->m_MMC5_vrom_bank[0] * 64;
2110            //                  vrom_next[0] = 0;
2111            //                  vrom_page_a = 0;
2112            //                  vrom_page_b = 0;
2113            break;
2114      }
2115         break;
2116      case 0x1025: /* $5125 */
2117         LOG_MMC(("MMC5 $5125 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2118         switch (state->m_mmc5_chr_mode)
2119      {
2120         case 0x02:
2121            /* 2k switch */
2122            chr2_4(space->machine(), data | (state->m_mmc5_high_chr << 8), CHRROM);
2123            break;
2124         case 0x03:
2125            /* 1k switch */
2126            state->m_MMC5_vrom_bank[5] = data | (state->m_mmc5_high_chr << 8);
2127            //                  mapper5_sync_vrom(0);
2128            chr1_5(space->machine(), state->m_MMC5_vrom_bank[5], CHRROM);
2129            //                  state->m_nes_vram_sprite[5] = state->m_MMC5_vrom_bank[0] * 64;
2130            //                  vrom_next[1] = 1;
2131            //                  vrom_page_a = 0;
2132            //                  vrom_page_b = 0;
2133            break;
2134      }
2135         break;
2136      case 0x1026: /* $5126 */
2137         LOG_MMC(("MMC5 $5126 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2138         switch (state->m_mmc5_chr_mode)
2139      {
2140         case 0x03:
2141            /* 1k switch */
2142            state->m_MMC5_vrom_bank[6] = data | (state->m_mmc5_high_chr << 8);
2143            //                  mapper5_sync_vrom(0);
2144            chr1_6(space->machine(), state->m_MMC5_vrom_bank[6], CHRROM);
2145            //                  state->m_nes_vram_sprite[6] = state->m_MMC5_vrom_bank[0] * 64;
2146            //                  vrom_next[2] = 2;
2147            //                  vrom_page_a = 0;
2148            //                  vrom_page_b = 0;
2149            break;
2150      }
2151         break;
2152      case 0x1027: /* $5127 */
2153         LOG_MMC(("MMC5 $5127 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2154         switch (state->m_mmc5_chr_mode)
2155      {
2156         case 0x00:
2157            /* 8k switch */
2158            chr8(space->machine(), data, CHRROM);
2159            break;
2160         case 0x01:
2161            /* 4k switch */
2162            chr4_4(space->machine(), data, CHRROM);
2163            break;
2164         case 0x02:
2165            /* 2k switch */
2166            chr2_6(space->machine(), data | (state->m_mmc5_high_chr << 8), CHRROM);
2167            break;
2168         case 0x03:
2169            /* 1k switch */
2170            state->m_MMC5_vrom_bank[7] = data | (state->m_mmc5_high_chr << 8);
2171            //                  mapper5_sync_vrom(0);
2172            chr1_7(space->machine(), state->m_MMC5_vrom_bank[7], CHRROM);
2173            //                  state->m_nes_vram_sprite[7] = state->m_MMC5_vrom_bank[0] * 64;
2174            //                  vrom_next[3] = 3;
2175            //                  vrom_page_a = 0;
2176            //                  vrom_page_b = 0;
2177            break;
2178      }
2179         break;
2180      case 0x1028: /* $5128 */
2181         LOG_MMC(("MMC5 $5128 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2182         switch (state->m_mmc5_chr_mode)
2183      {
2184         case 0x03:
2185            /* 1k switch */
2186            state->m_MMC5_vrom_bank[8] = data | (state->m_mmc5_high_chr << 8);
2187            //                  nes_vram[vrom_next[0]] = data * 64;
2188            //                  nes_vram[0 + (vrom_page_a*4)] = data * 64;
2189            //                  nes_vram[0] = data * 64;
2190            chr1_4(space->machine(), state->m_MMC5_vrom_bank[8], CHRROM);
2191            //                  mapper5_sync_vrom(1);
2192            if (!state->m_vrom_page_b)
2193            {
2194               state->m_vrom_page_a ^= 0x01;
2195               state->m_vrom_page_b = 1;
2196            }
2197            break;
2198      }
2199         break;
2200      case 0x1029: /* $5129 */
2201         LOG_MMC(("MMC5 $5129 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2202         switch (state->m_mmc5_chr_mode)
2203      {
2204         case 0x02:
2205            /* 2k switch */
2206            chr2_0(space->machine(), data | (state->m_mmc5_high_chr << 8), CHRROM);
2207            chr2_4(space->machine(), data | (state->m_mmc5_high_chr << 8), CHRROM);
2208            break;
2209         case 0x03:
2210            /* 1k switch */
2211            state->m_MMC5_vrom_bank[9] = data | (state->m_mmc5_high_chr << 8);
2212            //                  nes_vram[vrom_next[1]] = data * 64;
2213            //                  nes_vram[1 + (vrom_page_a*4)] = data * 64;
2214            //                  nes_vram[1] = data * 64;
2215            chr1_5(space->machine(), state->m_MMC5_vrom_bank[9], CHRROM);
2216            //                  mapper5_sync_vrom(1);
2217            if (!state->m_vrom_page_b)
2218            {
2219               state->m_vrom_page_a ^= 0x01;
2220               state->m_vrom_page_b = 1;
2221            }
2222            break;
2223      }
2224         break;
2225      case 0x102a: /* $512a */
2226         LOG_MMC(("MMC5 $512a vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2227         switch (state->m_mmc5_chr_mode)
2228      {
2229         case 0x03:
2230            /* 1k switch */
2231            state->m_MMC5_vrom_bank[10] = data | (state->m_mmc5_high_chr << 8);
2232            //                  nes_vram[vrom_next[2]] = data * 64;
2233            //                  nes_vram[2 + (vrom_page_a*4)] = data * 64;
2234            //                  nes_vram[2] = data * 64;
2235            chr1_6(space->machine(), state->m_MMC5_vrom_bank[10], CHRROM);
2236            //                  mapper5_sync_vrom(1);
2237            if (!state->m_vrom_page_b)
2238            {
2239               state->m_vrom_page_a ^= 0x01;
2240               state->m_vrom_page_b = 1;
2241            }
2242            break;
2243      }
2244         break;
2245      case 0x102b: /* $512b */
2246         LOG_MMC(("MMC5 $512b vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2247         switch (state->m_mmc5_chr_mode)
2248      {
2249         case 0x00:
2250            /* 8k switch */
2251            /* switches in first half of an 8K bank!) */
2252            chr4_0(space->machine(), data << 1, CHRROM);
2253            chr4_4(space->machine(), data << 1, CHRROM);
2254            break;
2255         case 0x01:
2256            /* 4k switch */
2257            chr4_0(space->machine(), data, CHRROM);
2258            chr4_4(space->machine(), data, CHRROM);
2259            break;
2260         case 0x02:
2261            /* 2k switch */
2262            chr2_2(space->machine(), data | (state->m_mmc5_high_chr << 8), CHRROM);
2263            chr2_6(space->machine(), data | (state->m_mmc5_high_chr << 8), CHRROM);
2264            break;
2265         case 0x03:
2266            /* 1k switch */
2267            state->m_MMC5_vrom_bank[11] = data | (state->m_mmc5_high_chr << 8);
2268            //                  nes_vram[vrom_next[3]] = data * 64;
2269            //                  nes_vram[3 + (vrom_page_a*4)] = data * 64;
2270            //                  nes_vram[3] = data * 64;
2271            chr1_7(space->machine(), state->m_MMC5_vrom_bank[11], CHRROM);
2272            //                  mapper5_sync_vrom(1);
2273            if (!state->m_vrom_page_b)
2274            {
2275               state->m_vrom_page_a ^= 0x01;
2276               state->m_vrom_page_b = 1;
2277            }
2278            break;
2279      }
2280         break;
2281
2282      case 0x1030: /* $5130 */
2283         state->m_mmc5_high_chr = data & 0x03;
2284         if (state->m_mmc5_vram_control == 1)
2285         {
2286            // in this case state->m_mmc5_high_chr selects which 256KB of CHR ROM
2287            // is to be used for all background tiles on the screen.
2288         }
2289         break;
2290
2291
2292      case 0x1100: /* $5200 */
2293         state->m_mmc5_split_scr = data;
2294         // in EX2 and EX3 modes, no split screen
2295         if (state->m_mmc5_vram_control & 0x02)
2296            state->m_mmc5_split_scr &= 0x7f;
2297         state->m_mmc5_split_ctrl = data;
2298         break;
2299
2300      case 0x1101: /* $5201 */
2301         state->m_mmc5_split_yst = (data >= 240) ? data - 16 : data;
2302         break;
2303
2304      case 0x1102: /* $5202 */
2305         state->m_mmc5_split_bank = data;
2306         break;
2307
2308      case 0x1103: /* $5203 */
2309         state->m_IRQ_count = data;
2310         state->m_MMC5_scanline = data;
2311         LOG_MMC(("MMC5 irq scanline: %d\n", state->m_IRQ_count));
2312         break;
2313      case 0x1104: /* $5204 */
2314         state->m_IRQ_enable = data & 0x80;
2315         LOG_MMC(("MMC5 irq enable: %02x\n", data));
2316         break;
2317      case 0x1105: /* $5205 */
2318         state->m_mult1 = data;
2319         break;
2320      case 0x1106: /* $5206 */
2321         state->m_mult2 = data;
2322         break;
2323
2324      default:
2325         logerror("** MMC5 uncaught write, offset: %04x, data: %02x\n", offset + 0x4100, data);
2326         break;
2327   }
2328}
2329
2330/*************************************************************
2331
2332 NTBROM & Sunsoft-4 board emulation
2333
2334 Part of this can be used also for Sunsoft Double Cassette
2335 System... which games use it?
2336
2337 iNES: mapper 68
2338
2339 *************************************************************/
2340
2341static void ntbrom_mirror( running_machine &machine, int mirror, int mirr0, int mirr1 )
2342{
2343   switch (mirror)
2344   {
2345      case 0x00:
2346         set_nt_mirroring(machine, PPU_MIRROR_HORZ);
2347         break;
2348      case 0x01:
2349         set_nt_mirroring(machine, PPU_MIRROR_VERT);
2350         break;
2351      case 0x02:
2352         set_nt_mirroring(machine, PPU_MIRROR_LOW);
2353         break;
2354      case 0x03:
2355         set_nt_mirroring(machine, PPU_MIRROR_HIGH);
2356         break;
2357      case 0x10:
2358         set_nt_page(machine, 0, ROM, mirr0 | 0x80, 0);
2359         set_nt_page(machine, 1, ROM, mirr1 | 0x80, 0);
2360         set_nt_page(machine, 2, ROM, mirr0 | 0x80, 0);
2361         set_nt_page(machine, 3, ROM, mirr1 | 0x80, 0);
2362         break;
2363      case 0x11:
2364         set_nt_page(machine, 0, ROM, mirr0 | 0x80, 0);
2365         set_nt_page(machine, 1, ROM, mirr0 | 0x80, 0);
2366         set_nt_page(machine, 2, ROM, mirr1 | 0x80, 0);
2367         set_nt_page(machine, 3, ROM, mirr1 | 0x80, 0);
2368         break;
2369      case 0x12:
2370         set_nt_page(machine, 0, ROM, mirr0 | 0x80, 0);
2371         set_nt_page(machine, 1, ROM, mirr0 | 0x80, 0);
2372         set_nt_page(machine, 2, ROM, mirr0 | 0x80, 0);
2373         set_nt_page(machine, 3, ROM, mirr0 | 0x80, 0);
2374         break;
2375      case 0x13:
2376         set_nt_page(machine, 0, ROM, mirr1 | 0x80, 0);
2377         set_nt_page(machine, 1, ROM, mirr1 | 0x80, 0);
2378         set_nt_page(machine, 2, ROM, mirr1 | 0x80, 0);
2379         set_nt_page(machine, 3, ROM, mirr1 | 0x80, 0);
2380         break;
2381   }
2382}
2383
2384static WRITE8_HANDLER( ntbrom_w )
2385{
2386   nes_state *state = space->machine().driver_data<nes_state>();
2387
2388   LOG_MMC(("ntbrom_w, offset %04x, data: %02x\n", offset, data));
2389
2390   switch (offset & 0x7000)
2391   {
2392      case 0x0000:
2393         chr2_0(space->machine(), data, CHRROM);
2394         break;
2395      case 0x1000:
2396         chr2_2(space->machine(), data, CHRROM);
2397         break;
2398      case 0x2000:
2399         chr2_4(space->machine(), data, CHRROM);
2400         break;
2401      case 0x3000:
2402         chr2_6(space->machine(), data, CHRROM);
2403         break;
2404      case 0x4000:
2405         state->m_mmc_latch1 = data & 0x7f;
2406         ntbrom_mirror(space->machine(), state->m_mmc_reg[0], state->m_mmc_latch1, state->m_mmc_latch2);
2407         break;
2408      case 0x5000:
2409         state->m_mmc_latch2 = data & 0x7f;
2410         ntbrom_mirror(space->machine(), state->m_mmc_reg[0], state->m_mmc_latch1, state->m_mmc_latch2);
2411         break;
2412      case 0x6000:
2413         state->m_mmc_reg[0] = data & 0x13;
2414         ntbrom_mirror(space->machine(), state->m_mmc_reg[0], state->m_mmc_latch1, state->m_mmc_latch2);
2415         break;
2416      case 0x7000:
2417         prg16_89ab(space->machine(), data);
2418         break;
2419      default:
2420         LOG_MMC(("ntbrom_w uncaught write, offset: %04x, data: %02x\n", offset, data));
2421         break;
2422   }
2423}
2424
2425/*************************************************************
2426
2427 JxROM & Sunsoft 5A / 5B / FME7 board emulation
2428
2429 Notice that Sunsoft-5B = FME7 + sound chip (the latter being
2430 currently unemulated in MESS)
2431
2432 iNES: mapper 69
2433
2434 *************************************************************/
2435
2436/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
2437 we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
2438 there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
2439static void jxrom_irq( device_t *device, int scanline, int vblank, int blanked )
2440{
2441   nes_state *state = device->machine().driver_data<nes_state>();
2442
2443   /* TODO: change to reflect the actual number of cycles spent */
2444   if ((state->m_IRQ_enable & 0x80) && (state->m_IRQ_enable & 0x01))
2445   {
2446      if (state->m_IRQ_count <= 114)
2447      {
2448         state->m_IRQ_count = 0xffff;
2449         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
2450      }
2451      else
2452         state->m_IRQ_count -= 114;
2453   }
2454   else if (state->m_IRQ_enable & 0x01)   // if enable bit 7 is not set, only decrement the counter!
2455   {
2456      if (state->m_IRQ_count <= 114)
2457         state->m_IRQ_count = 0xffff;
2458      else
2459         state->m_IRQ_count -= 114;
2460   }
2461}
2462
2463static WRITE8_HANDLER( jxrom_w )
2464{
2465   nes_state *state = space->machine().driver_data<nes_state>();
2466   LOG_MMC(("jxrom_w, offset %04x, data: %02x\n", offset, data));
2467
2468   switch (offset & 0x6000)
2469   {
2470      case 0x0000:
2471         state->m_mmc_latch1 = data & 0x0f;
2472         break;
2473
2474      case 0x2000:
2475         switch (state->m_mmc_latch1)
2476         {
2477         case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
2478            chr1_x(space->machine(), state->m_mmc_latch1, data, CHRROM);
2479            break;
2480
2481         case 8:
2482            if (!(data & 0x40))
2483            {
2484               // is PRG ROM
2485               space->unmap_write(0x6000, 0x7fff);
2486               prg8_67(space->machine(), data & 0x3f);
2487            }
2488            else if (data & 0x80)
2489            {
2490               // is PRG RAM
2491               space->install_write_bank(0x6000, 0x7fff, "bank5");
2492               state->m_prg_bank[4] = state->m_battery_bank5_start + (data & 0x3f);
2493               memory_set_bank(space->machine(), "bank5", state->m_prg_bank[4]);
2494            }
2495            break;
2496
2497         case 9:
2498            prg8_89(space->machine(), data);
2499            break;
2500         case 0x0a:
2501            prg8_ab(space->machine(), data);
2502            break;
2503         case 0x0b:
2504            prg8_cd(space->machine(), data);
2505            break;
2506         case 0x0c:
2507            switch (data & 0x03)
2508            {
2509            case 0x00: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
2510            case 0x01: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
2511            case 0x02: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
2512            case 0x03: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
2513            }
2514            break;
2515         case 0x0d:
2516            state->m_IRQ_enable = data;
2517            break;
2518         case 0x0e:
2519            state->m_IRQ_count = (state->m_IRQ_count & 0xff00) | data;
2520            break;
2521         case 0x0f:
2522            state->m_IRQ_count = (state->m_IRQ_count & 0x00ff) | (data << 8);
2523            break;
2524         }
2525         break;
2526
2527         /* Here we would have sound command for Sunsoft 5b variant */
2528         //      case 0x4000:
2529         //      case 0x6000:
2530
2531      case 0x4000:
2532         LOG_MMC(("Sunsoft-5B Sound: Register select write, data: %02x\n", data));
2533         break;
2534      case 0x6000:
2535         LOG_MMC(("Sunsoft-5B Sound: Register write, data: %02x\n", data));
2536         break;
2537      default:
2538         logerror("jxrom_w uncaught %04x value: %02x\n", offset + 0x8000, data);
2539         break;
2540   }
2541}
2542
2543/*************************************************************
2544
2545 DxROM & Namcot 3433 - 3443 board emulation
2546
2547 Games: Dragon Spirit - Aratanaru Densetsu, Namcot Mahjong, Quinty
2548
2549 These are the same board, but DRROM (and Tengen 800004) have
2550 4-screen mirroring
2551
2552 iNES: mappers 88, 206 (same as 88 but possibly 4-screen mirroring)
2553
2554 *************************************************************/
2555
2556static WRITE8_HANDLER( dxrom_w )
2557{
2558   nes_state *state = space->machine().driver_data<nes_state>();
2559   LOG_MMC(("dxrom_w, offset: %04x, data: %02x\n", offset, data));
2560
2561    if (offset >= 0x2000)
2562      return;
2563
2564   switch (offset & 1)
2565   {
2566      case 1:
2567         switch (state->m_mmc_latch1 & 0x07)
2568         {
2569         case 0: chr2_0(space->machine(), data >> 1, CHRROM); break;
2570         case 1: chr2_2(space->machine(), data >> 1, CHRROM); break;
2571         case 2: chr1_4(space->machine(), data | 0x40, CHRROM); break;
2572         case 3: chr1_5(space->machine(), data | 0x40, CHRROM); break;
2573         case 4: chr1_6(space->machine(), data | 0x40, CHRROM); break;
2574         case 5: chr1_7(space->machine(), data | 0x40, CHRROM); break;
2575         case 6: prg8_89(space->machine(), data); break;
2576         case 7: prg8_ab(space->machine(), data); break;
2577         }
2578         break;
2579      case 0:
2580         state->m_mmc_latch1 = data;
2581         break;
2582   }
2583}
2584
2585
2586/*************************************************************
2587
2588 Namcot 3453 board emulation
2589
2590 Games: Devil Man
2591
2592 These are the same as Namcot 34x3, but with additional mirroring
2593 control
2594
2595 iNES: mapper 154
2596
2597 *************************************************************/
2598
2599static WRITE8_HANDLER( namcot3453_w )
2600{
2601   LOG_MMC(("namcot3453_w, offset: %04x, data: %02x\n", offset, data));
2602
2603   // additional mirroring control when writing to even addresses
2604   if (!(offset & 1))
2605      set_nt_mirroring(space->machine(), BIT(data, 6) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
2606
2607   dxrom_w(space, offset, data);
2608}
2609
2610/*************************************************************
2611
2612 Namcot 3446 board emulation
2613
2614 Games: Digital Devil Monogatari - Megami Tensei
2615
2616 These are similar Namcot 34x3, but different bankswitch capabilities
2617
2618 iNES: mapper 76
2619
2620 *************************************************************/
2621
2622static WRITE8_HANDLER( namcot3446_w )
2623{
2624   nes_state *state = space->machine().driver_data<nes_state>();
2625   LOG_MMC(("namcot3446_w, offset: %04x, data: %02x\n", offset, data));
2626
2627   // NEStopia does not have this!
2628   if (offset >= 0x2000)
2629   {
2630      if (!(offset & 1))
2631         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
2632      return;
2633   }
2634
2635   switch (offset & 1)
2636   {
2637      case 1:
2638         switch (state->m_mmc_latch1 & 0x07)
2639         {
2640         case 2: chr2_0(space->machine(), data, CHRROM); break;
2641         case 3: chr2_2(space->machine(), data, CHRROM); break;
2642         case 4: chr2_4(space->machine(), data, CHRROM); break;
2643         case 5: chr2_6(space->machine(), data, CHRROM); break;
2644         case 6: BIT(state->m_mmc_latch1, 6) ? prg8_cd(space->machine(), data) : prg8_89(space->machine(), data); break;
2645         case 7: prg8_ab(space->machine(), data); break;
2646         }
2647         break;
2648      case 0:
2649         state->m_mmc_latch1 = data;
2650         break;
2651   }
2652}
2653
2654/*************************************************************
2655
2656 Namcot 3425 board emulation
2657
2658 Games: Dragon Buster
2659
2660 These are similar Namcot 34x3, but with NT mirroring (two
2661 different modes)
2662
2663 iNES: mapper 95
2664
2665 *************************************************************/
2666
2667static WRITE8_HANDLER( namcot3425_w )
2668{
2669   nes_state *state = space->machine().driver_data<nes_state>();
2670   UINT8 mode;
2671   LOG_MMC(("namcot3425_w, offset: %04x, data: %02x\n", offset, data));
2672   if (offset >= 0x2000)
2673      return;
2674
2675   switch (offset & 1)
2676   {
2677      case 1:
2678         mode = state->m_mmc_latch1 & 0x07;
2679         switch (mode)
2680         {
2681         case 0: chr2_0(space->machine(), data >> 1, CHRROM); break;
2682         case 1: chr2_2(space->machine(), data >> 1, CHRROM); break;
2683         case 2:
2684         case 3:
2685         case 4:
2686         case 5:
2687            chr1_x(space->machine(), 2 + mode, data, CHRROM);
2688            state->m_mmc_reg[mode - 2] = BIT(data, 5);
2689            if (!BIT(state->m_mmc_latch1, 7))
2690            {
2691                  set_nt_page(space->machine(), 0, CIRAM, state->m_mmc_reg[0], 1);
2692                  set_nt_page(space->machine(), 1, CIRAM, state->m_mmc_reg[1], 1);
2693                  set_nt_page(space->machine(), 2, CIRAM, state->m_mmc_reg[2], 1);
2694                  set_nt_page(space->machine(), 3, CIRAM, state->m_mmc_reg[3], 1);
2695            }
2696            else
2697               set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ);
2698            break;
2699         case 6: prg8_89(space->machine(), data); break;
2700         case 7: prg8_ab(space->machine(), data); break;
2701         }
2702         break;
2703      case 0:
2704         state->m_mmc_latch1 = data;
2705         break;
2706   }
2707}
2708
2709/*************************************************************
2710
2711 Discrete Logic board IC 74x377 by Color Dreams / Nina-007 emulation
2712
2713 Games: many Color Dreams and Wisdom Tree titles
2714
2715 iNES: mapper 11
2716
2717 In MESS: Supported
2718
2719 *************************************************************/
2720
2721static WRITE8_HANDLER( dis_74x377_w )
2722{
2723   nes_state *state = space->machine().driver_data<nes_state>();
2724   LOG_MMC(("dis_74x377_w, offset: %04x, data: %02x\n", offset, data));
2725
2726   chr8(space->machine(), data >> 4, state->m_mmc_chr_source);
2727   prg32(space->machine(), data & 0x0f);
2728}
2729
2730/*************************************************************
2731
2732 Discrete Logic board IC 74x139x74 by Konami & Jaleco
2733
2734 iNES: mapper 87
2735
2736 *************************************************************/
2737
2738static WRITE8_HANDLER( dis_74x139x74_m_w )
2739{
2740   LOG_MMC(("dis_74x139x74_m_w, offset: %04x, data: %02x\n", offset, data));
2741
2742   chr8(space->machine(), ((data & 0x02) >> 1) | ((data & 0x01) << 1), CHRROM);
2743}
2744
2745/*************************************************************
2746
2747 Discrete Logic board IC 74x161x138
2748
2749 Games: Crime Busters
2750
2751 iNES: mapper 38
2752
2753 *************************************************************/
2754
2755static WRITE8_HANDLER( dis_74x161x138_m_w )
2756{
2757   LOG_MMC(("dis_74x161x138_m_w, offset: %04x, data: %02x\n", offset, data));
2758
2759   chr8(space->machine(), data >> 2, CHRROM);
2760   prg32(space->machine(), data);
2761}
2762
2763/*************************************************************
2764
2765 Discrete Logic board IC 74x161x161x32
2766
2767 There are two variants (one with hardwired mirroring, the
2768 other with a mirroring control), making necessary two distinct
2769 mappers & pcb_id
2770
2771 iNES: mappers 70 & 152
2772
2773 *************************************************************/
2774
2775static WRITE8_HANDLER( dis_74x161x161x32_w )
2776{
2777   nes_state *state = space->machine().driver_data<nes_state>();
2778   LOG_MMC(("dis_74x161x161x32_w, offset: %04x, data: %02x\n", offset, data));
2779
2780   if (!state->m_hard_mirroring)   // there are two 'variants' depending on hardwired or mapper ctrl mirroring
2781      set_nt_mirroring(space->machine(), BIT(data, 7) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
2782   chr8(space->machine(), data, CHRROM);
2783   prg16_89ab(space->machine(), data >> 4);
2784}
2785
2786/*************************************************************
2787
2788 Bandai LZ93D50 boards emulation
2789
2790 There are several variants: plain board with or without SRAM,
2791 board + 24C01 EEPROM, board + 24C02 EEPROM, board + Barcode
2792 Reader (DATACH).
2793 We currently only emulate the base hardware.
2794
2795 Games: Crayon Shin-Chan - Ora to Poi Poi, Dragon Ball Z Gaiden,
2796 Dragon Ball Z II & III, Rokudenashi Blues, SD Gundam
2797 Gaiden - KGM2, Dragon Ball Z, Magical Taruruuto-kun, SD Gundam
2798 Gaiden [with EEPROM], Dragon Ball, Dragon Ball 3, Famicom Jump,
2799 Famicom Jump II [no EEPROM], Datach Games
2800
2801 At the moment, we don't support EEPROM I/O
2802
2803 iNES: mappers 16, 153, 157 & 159
2804
2805 In MESS: Supported
2806
2807 *************************************************************/
2808
2809/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
2810 we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
2811 there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
2812static void bandai_lz_irq( device_t *device, int scanline, int vblank, int blanked )
2813{
2814   nes_state *state = device->machine().driver_data<nes_state>();
2815
2816   /* 114 is the number of cycles per scanline */
2817   /* TODO: change to reflect the actual number of cycles spent */
2818   if (state->m_IRQ_enable)
2819   {
2820      if (state->m_IRQ_count <= 114)
2821      {
2822         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
2823         state->m_IRQ_count = (0xffff - 114 + state->m_IRQ_count);   // wrap around the 16 bits counter
2824      }
2825      state->m_IRQ_count -= 114;
2826   }
2827}
2828
2829static WRITE8_HANDLER( lz93d50_w )
2830{
2831   nes_state *state = space->machine().driver_data<nes_state>();
2832   LOG_MMC(("lz93d50_w, offset: %04x, data: %02x\n", offset, data));
2833
2834   switch (offset & 0x000f)
2835   {
2836      case 0: case 1: case 2: case 3:
2837      case 4: case 5: case 6: case 7:
2838         chr1_x(space->machine(), offset & 0x07, data, state->m_mmc_chr_source);
2839         break;
2840      case 8:
2841         prg16_89ab(space->machine(), data);
2842         break;
2843      case 9:
2844         switch (data & 0x03)
2845         {
2846         case 0: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
2847         case 1: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
2848         case 2: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
2849         case 3: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
2850         }
2851         break;
2852      case 0x0a:
2853         state->m_IRQ_enable = data & 0x01;
2854         break;
2855      case 0x0b:
2856         state->m_IRQ_count = (state->m_IRQ_count & 0xff00) | data;
2857         break;
2858      case 0x0c:
2859         state->m_IRQ_count = (state->m_IRQ_count & 0x00ff) | (data << 8);
2860         break;
2861      default:
2862         logerror("lz93d50_w uncaught write, offset: %04x, data: %02x\n", offset, data);
2863         break;
2864   }
2865}
2866
2867static WRITE8_HANDLER( lz93d50_m_w )
2868{
2869   nes_state *state = space->machine().driver_data<nes_state>();
2870   LOG_MMC(("lz93d50_m_w, offset: %04x, data: %02x\n", offset, data));
2871
2872   if (!state->m_battery && !state->m_wram)
2873      lz93d50_w(space, offset & 0x0f, data);
2874   else if (state->m_battery)
2875      state->m_battery_ram[offset] = data;
2876   else
2877      state->m_wram[offset] = data;
2878}
2879
2880static void fjump2_set_prg( running_machine &machine )
2881{
2882   nes_state *state = machine.driver_data<nes_state>();
2883   UINT8 mmc_helper = 0;
2884   int i;
2885
2886   for (i = 0; i < 8; i++)
2887      mmc_helper |= ((state->m_mmc_reg[i] & 0x01) << 4);
2888
2889   prg16_89ab(machine, mmc_helper | state->m_mmc_latch1);
2890   prg16_cdef(machine, mmc_helper | 0x0f);
2891}
2892
2893static WRITE8_HANDLER( fjump2_w )
2894{
2895   nes_state *state = space->machine().driver_data<nes_state>();
2896   LOG_MMC(("fjump2_w, offset: %04x, data: %02x\n", offset, data));
2897
2898   switch (offset & 0x000f)
2899   {
2900      case 0: case 1: case 2: case 3:
2901      case 4: case 5: case 6: case 7:
2902         state->m_mmc_reg[offset & 0x000f] = data;
2903         fjump2_set_prg(space->machine());
2904         break;
2905      case 8:
2906         state->m_mmc_latch1 = (data & 0x0f);
2907         fjump2_set_prg(space->machine());
2908         break;
2909      default:
2910         lz93d50_m_w(space, offset & 0x0f, data);
2911         break;
2912   }
2913}
2914
2915/*************************************************************
2916
2917 Bandai Karaoke Studio board emulation
2918
2919 Games: Karaoke Studio
2920
2921 Note: we currently do not emulate the mic
2922
2923 iNES: mapper 188
2924
2925 *************************************************************/
2926
2927static WRITE8_HANDLER( bandai_ks_w )
2928{
2929   LOG_MMC(("bandai_ks_w, offset: %04x, data: %02x\n", offset, data));
2930
2931   prg16_89ab(space->machine(), data ^ 0x08);
2932}
2933
2934/*************************************************************
2935
2936 Bandai Oeka Kids board emulation
2937
2938 Games: Oeka Kids - Anpanman no Hiragana Daisuki, Oeka
2939 Kids - Anpanman to Oekaki Shiyou!!
2940
2941 iNES: mapper 96
2942
2943 In MESS: Preliminary Support.
2944
2945 *************************************************************/
2946
2947static WRITE8_HANDLER( bandai_ok_w )
2948{
2949   nes_state *state = space->machine().driver_data<nes_state>();
2950   UINT8 mmc_helper;
2951   LOG_MMC(("mapper96_w, offset: %04x, data: %02x\n", offset, data));
2952
2953   prg32(space->machine(), data);
2954
2955   state->m_mmc_latch1 = data;
2956   mmc_helper = (state->m_mmc_latch1 & 0x03) | (data & 0x04);
2957   chr4_0(space->machine(), mmc_helper, CHRRAM);
2958   chr4_4(space->machine(), 0x03 | (data & 0x04), CHRRAM);
2959}
2960
2961/*************************************************************
2962
2963 Irem LROG017 - Discrete board emulation (74*161/161/21/138)
2964
2965 Games: Napoleon Senki
2966
2967 iNES: mapper 77
2968
2969 *************************************************************/
2970
2971static WRITE8_HANDLER( lrog017_w )
2972{
2973   LOG_MMC(("lrog017_w, offset: %04x, data: %02x\n", offset, data));
2974
2975   prg32(space->machine(), data);
2976   chr2_0(space->machine(), (data >> 4), CHRROM);
2977}
2978
2979/*************************************************************
2980
2981 Irem Holy Diver board emulation
2982
2983 iNES: mapper 78 (shared with JF-16)
2984
2985 *************************************************************/
2986
2987static WRITE8_HANDLER( irem_hd_w )
2988{
2989   LOG_MMC(("irem_hd_w, offset: %04x, data: %02x\n", offset, data));
2990
2991   set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
2992   chr8(space->machine(), data >> 4, CHRROM);
2993   prg16_89ab(space->machine(), data);
2994}
2995
2996/*************************************************************
2997
2998 Irem TAM-S1 board emulation
2999
3000 Games: Kaiketsu Yanchamaru
3001
3002 iNES: mapper 97
3003
3004 In MESS: Supported.
3005
3006 *************************************************************/
3007
3008static WRITE8_HANDLER( tam_s1_w )
3009{
3010   LOG_MMC(("tam_s1_w, offset: %04x, data: %02x\n", offset, data));
3011
3012   if (offset < 0x4000)
3013   {
3014      set_nt_mirroring(space->machine(), BIT(data, 7) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
3015      prg16_cdef(space->machine(), data);
3016   }
3017}
3018
3019/*************************************************************
3020
3021 Irem G-101 board emulation
3022
3023 Major League uses hardwired mirroring
3024
3025 iNES: mapper 32
3026
3027 *************************************************************/
3028
3029static WRITE8_HANDLER( g101_w )
3030{
3031   nes_state *state = space->machine().driver_data<nes_state>();
3032   LOG_MMC(("g101_w, offset: %04x, data: %02x\n", offset, data));
3033
3034   switch (offset & 0x7000)
3035   {
3036      case 0x0000:
3037         // NEStopia here differs a little bit
3038         state->m_mmc_latch1 ? prg8_cd(space->machine(), data) : prg8_89(space->machine(), data);
3039         break;
3040      case 0x1000:
3041         state->m_mmc_latch1 = BIT(data, 1);
3042         if (!state->m_hard_mirroring)   // there are two 'variants' depending on hardwired or mapper ctrl mirroring
3043            set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3044         break;
3045      case 0x2000:
3046         prg8_ab(space->machine(), data);
3047         break;
3048      case 0x3000:
3049         chr1_x(space->machine(), offset & 0x07, data, CHRROM);
3050         break;
3051   }
3052}
3053
3054/*************************************************************
3055
3056 Irem H-3001 board emulation
3057
3058 Games: Daiku no Gen San 2 - Akage no Dan no Gyakushuu,
3059 Kaiketsu Yanchamaru 3, Spartan X 2
3060
3061 iNES: mapper 65
3062
3063 In MESS: Supported.
3064
3065 *************************************************************/
3066
3067/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
3068 we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
3069 there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
3070static void h3001_irq( device_t *device, int scanline, int vblank, int blanked )
3071{
3072   nes_state *state = device->machine().driver_data<nes_state>();
3073   if (state->m_IRQ_enable)
3074   {
3075      state->m_IRQ_count -= 114;
3076
3077      if (state->m_IRQ_count <= 114)
3078      {
3079         state->m_IRQ_enable = 0;
3080         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
3081      }
3082   }
3083}
3084
3085static WRITE8_HANDLER( h3001_w )
3086{
3087   nes_state *state = space->machine().driver_data<nes_state>();
3088   LOG_MMC(("h3001_w, offset %04x, data: %02x\n", offset, data));
3089
3090   switch (offset & 0x7fff)
3091   {
3092      case 0x0000:
3093         prg8_89(space->machine(), data);
3094         break;
3095
3096      case 0x1001:
3097         set_nt_mirroring(space->machine(), BIT(data, 7) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3098         break;
3099
3100      case 0x1003:
3101         state->m_IRQ_enable = data & 0x80;
3102         break;
3103
3104      case 0x1004:
3105         state->m_IRQ_count = state->m_IRQ_count_latch;
3106         break;
3107
3108      case 0x1005:
3109         state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0x00ff) | (data << 8);
3110         break;
3111
3112      case 0x1006:
3113         state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0xff00) | data;
3114         break;
3115
3116      case 0x2000:
3117         prg8_ab(space->machine(), data);
3118         break;
3119
3120      case 0x3000: case 0x3001: case 0x3002: case 0x3003:
3121      case 0x3004: case 0x3005: case 0x3006: case 0x3007:
3122         chr1_x(space->machine(), offset & 0x07, data, CHRROM);
3123         break;
3124
3125      case 0x4000:
3126         prg8_cd(space->machine(), data);
3127         break;
3128
3129      default:
3130         break;
3131   }
3132}
3133
3134/*************************************************************
3135
3136 Jaleco SS88006 board emulation, aka JF-27, JF-29, JF-30, ...,
3137 JF-38, JF-40, JF-41
3138
3139 Games: Lord of King, Magic John, Moe Pro '90, Ninja Jajamaru,
3140 Pizza Pop, Plasma Ball
3141
3142 iNES: mapper 18
3143
3144 In MESS: Supported
3145
3146 *************************************************************/
3147
3148/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
3149 we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
3150 there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
3151static void ss88006_irq( device_t *device, int scanline, int vblank, int blanked )
3152{
3153   nes_state *state = device->machine().driver_data<nes_state>();
3154
3155   /* Increment & check the IRQ scanline counter */
3156   if (state->m_IRQ_enable)
3157   {
3158      LOG_MMC(("scanline: %d, irq count: %04x\n", scanline, state->m_IRQ_count));
3159      if (state->m_IRQ_mode & 0x08)
3160      {
3161         if ((state->m_IRQ_count & 0x000f) < 114)   // always true, but we only update the IRQ once per scanlines so we cannot be more precise :(
3162         {
3163            device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
3164            state->m_IRQ_count = (state->m_IRQ_count & ~0x000f) | (0x0f - (114 & 0x0f) + (state->m_IRQ_count & 0x000f)); // sort of wrap around the counter
3165         }
3166         // decrements should not affect upper bits, so we don't do anything here (114 > 0x0f)
3167      }
3168      else if (state->m_IRQ_mode & 0x04)
3169      {
3170         if ((state->m_IRQ_count & 0x00ff) < 114)
3171         {
3172            device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
3173            state->m_IRQ_count = (state->m_IRQ_count & ~0x00ff) | (0xff - 114 + (state->m_IRQ_count & 0x00ff));   // wrap around the 8 bits counter
3174         }
3175         else
3176            state->m_IRQ_count -= 114;
3177      }
3178      else if (state->m_IRQ_mode & 0x02)
3179      {
3180         if ((state->m_IRQ_count & 0x0fff)  < 114)
3181         {
3182            device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
3183            state->m_IRQ_count = (state->m_IRQ_count & ~0x0fff) | (0xfff - 114 + (state->m_IRQ_count & 0x0fff));   // wrap around the 12 bits counter
3184         }
3185         else
3186            state->m_IRQ_count -= 114;
3187      }
3188      else if (state->m_IRQ_count < 114)
3189      {
3190         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
3191         state->m_IRQ_count = (0xffff - 114 + state->m_IRQ_count);   // wrap around the 16 bits counter
3192      }
3193      else
3194         state->m_IRQ_count -= 114;
3195   }
3196}
3197
3198static WRITE8_HANDLER( ss88006_w )
3199{
3200   nes_state *state = space->machine().driver_data<nes_state>();
3201   UINT8 bank;
3202   LOG_MMC(("mapper18_w, offset: %04x, data: %02x\n", offset, data));
3203
3204   switch (offset & 0x7003)
3205   {
3206      case 0x0000:
3207         state->m_mmc_prg_bank[0] = (state->m_mmc_prg_bank[0] & 0xf0) | (data & 0x0f);
3208         prg8_89(space->machine(), state->m_mmc_prg_bank[0]);
3209         break;
3210      case 0x0001:
3211         state->m_mmc_prg_bank[0] = (state->m_mmc_prg_bank[0] & 0x0f) | (data << 4);
3212         prg8_89(space->machine(), state->m_mmc_prg_bank[0]);
3213         break;
3214      case 0x0002:
3215         state->m_mmc_prg_bank[1] = (state->m_mmc_prg_bank[1] & 0xf0) | (data & 0x0f);
3216         prg8_ab(space->machine(), state->m_mmc_prg_bank[1]);
3217         break;
3218      case 0x0003:
3219         state->m_mmc_prg_bank[1] = (state->m_mmc_prg_bank[1] & 0x0f) | (data << 4);
3220         prg8_ab(space->machine(), state->m_mmc_prg_bank[1]);
3221         break;
3222      case 0x1000:
3223         state->m_mmc_prg_bank[2] = (state->m_mmc_prg_bank[2] & 0xf0) | (data & 0x0f);
3224         prg8_cd(space->machine(), state->m_mmc_prg_bank[2]);
3225         break;
3226      case 0x1001:
3227         state->m_mmc_prg_bank[2] = (state->m_mmc_prg_bank[2] & 0x0f) | (data << 4);
3228         prg8_cd(space->machine(), state->m_mmc_prg_bank[2]);
3229         break;
3230
3231         /* $9002, 3 (1002, 3) uncaught = Jaleco Baseball writes 0 */
3232         /* believe it's related to battery-backed ram enable/disable */
3233
3234      case 0x2000: case 0x2001: case 0x2002: case 0x2003:
3235      case 0x3000: case 0x3001: case 0x3002: case 0x3003:
3236      case 0x4000: case 0x4001: case 0x4002: case 0x4003:
3237      case 0x5000: case 0x5001: case 0x5002: case 0x5003:
3238         bank = ((offset & 0x7000) - 0x2000) / 0x0800 + ((offset & 0x0002) >> 1);
3239         if (offset & 0x0001)
3240            state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0x0f) | ((data & 0x0f)<< 4);
3241         else
3242            state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0xf0) | (data & 0x0f);
3243
3244         chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], CHRROM);
3245         break;
3246
3247      case 0x6000:
3248         state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0xfff0) | (data & 0x0f);
3249         break;
3250      case 0x6001:
3251         state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0xff0f) | ((data & 0x0f) << 4);
3252         break;
3253      case 0x6002:
3254         state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0xf0ff) | ((data & 0x0f) << 8);
3255         break;
3256      case 0x6003:
3257         state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0x0fff) | ((data & 0x0f) << 12);
3258         break;
3259
3260      case 0x7000:
3261         state->m_IRQ_count = state->m_IRQ_count_latch;
3262         break;
3263      case 0x7001:
3264         state->m_IRQ_enable = data & 0x01;
3265         state->m_IRQ_mode = data & 0x0e;
3266         break;
3267
3268      case 0x7002:
3269         switch (data & 0x03)
3270         {
3271         case 0: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
3272         case 1: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
3273         case 2: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
3274         case 3: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
3275         }
3276         break;
3277
3278      default:
3279         logerror("Jaleco SS88006 uncaught write, addr: %04x, value: %02x\n", offset + 0x8000, data);
3280         break;
3281   }
3282}
3283
3284/*************************************************************
3285
3286 Jaleco JF-11, JF-12 & JF-14 boards emulation
3287
3288 Games: Bio Senshi Dan, Mississippi Satsujin Jiken
3289
3290 iNES: mapper 140
3291
3292 In MESS: Supported.
3293
3294 *************************************************************/
3295
3296static WRITE8_HANDLER( jf11_m_w )
3297{
3298   LOG_MMC(("jf11_m_w, offset: %04x, data: %02x\n", offset, data));
3299   chr8(space->machine(), data, CHRROM);
3300   prg32(space->machine(), data >> 4);
3301}
3302
3303/*************************************************************
3304
3305 Jaleco JF-13 board emulation
3306
3307 Games: Moero Pro Yakyuu
3308
3309 Note: we don't emulate the additional sound hardware.
3310
3311 iNES: mapper 86
3312
3313 In MESS: Supported.
3314
3315 *************************************************************/
3316
3317static WRITE8_HANDLER( jf13_m_w )
3318{
3319   LOG_MMC(("jf13_m_w, offset: %04x, data: %02x\n", offset, data));
3320
3321   if (offset == 0)
3322   {
3323      prg32(space->machine(), (data >> 4) & 0x03);
3324      chr8(space->machine(), ((data >> 4) & 0x04) | (data & 0x03), CHRROM);
3325   }
3326
3327   if (offset == 0x1000)
3328   {
3329      LOG_MMC(("Jaleco JF-13 sound write, data: %02x\n", data));
3330      // according to NEStopia, this is the effect
3331      if ((data & 0x30) == 0x20)
3332      {
3333         // send command (data & 0x1f) to sound chip
3334      }
3335   }
3336}
3337
3338/*************************************************************
3339
3340 Jaleco JF-16 board emulation
3341
3342 iNES: mapper 78 (shared with a diff Irem board)
3343
3344 *************************************************************/
3345
3346static WRITE8_HANDLER( jf16_w )
3347{
3348   LOG_MMC(("jf16_w, offset: %04x, data: %02x\n", offset, data));
3349
3350   set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
3351   chr8(space->machine(), data >> 4, CHRROM);
3352   prg16_89ab(space->machine(), data);
3353}
3354
3355/*************************************************************
3356
3357 Jaleco JF-17, JF-26 & JF-28 boards emulation
3358
3359 Note: we don't emulate the additional sound hardware.
3360
3361 Games: Moero!! Juudou Warriors, Moero!! Pro Tennis, Pinball
3362 Quest Jpn
3363
3364 iNES: mapper 72
3365
3366 In MESS: Supported.
3367
3368 *************************************************************/
3369
3370static WRITE8_HANDLER( jf17_w )
3371{
3372   LOG_MMC(("jf17_w, offset: %04x, data: %02x\n", offset, data));
3373
3374   if (BIT(data, 7))
3375      prg16_89ab(space->machine(), data & 0x0f);
3376   if (BIT(data, 6))
3377      chr8(space->machine(), data & 0x0f, CHRROM);
3378   if (BIT(data, 5) && !BIT(data,4))
3379      LOG_MMC(("Jaleco JF-17 sound write, data: %02x\n", data & 0x1f));
3380}
3381
3382/*************************************************************
3383
3384 Jaleco JF-19 & JF-21 boards emulation
3385
3386 Note: we don't emulate the additional sound hardware.
3387
3388 Games: Moero Pro Soccer, Moero Pro Yakyuu '88
3389
3390 iNES: mapper 92
3391
3392 In MESS: Supported (no samples).
3393
3394 *************************************************************/
3395
3396static WRITE8_HANDLER( jf19_w )
3397{
3398   LOG_MMC(("jf19_w, offset: %04x, data: %02x\n", offset, data));
3399
3400   if (BIT(data, 7))
3401      prg16_cdef(space->machine(), data & 0x0f);
3402   if (BIT(data, 6))
3403      chr8(space->machine(), data & 0x0f, CHRROM);
3404   if (BIT(data, 5) && !BIT(data,4))
3405      LOG_MMC(("Jaleco JF-19 sound write, data: %02x\n", data & 0x1f));
3406}
3407
3408/*************************************************************
3409
3410 Konami VRC1 and Jaleco JF20, JF22
3411
3412 Games: Exciting Boxing, Ganbare Goemon!, Tetsuwan Atom
3413
3414 iNES: mapper 75
3415
3416 In MESS: Supported.
3417
3418 *************************************************************/
3419
3420static WRITE8_HANDLER( konami_vrc1_w )
3421{
3422   nes_state *state = space->machine().driver_data<nes_state>();
3423   LOG_MMC(("konami_vrc1_w, offset: %04x, data: %02x\n", offset, data));
3424
3425   switch (offset & 0x7000)
3426   {
3427      case 0x0000:
3428         prg8_89(space->machine(), data);
3429         break;
3430      case 0x1000:
3431         set_nt_mirroring(space->machine(), (data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3432         state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & 0x0f) | ((data & 0x02) << 3);
3433         state->m_mmc_vrom_bank[1] = (state->m_mmc_vrom_bank[1] & 0x0f) | ((data & 0x04) << 2);
3434         chr4_0(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
3435         chr4_4(space->machine(), state->m_mmc_vrom_bank[1], CHRROM);
3436         break;
3437      case 0x2000:
3438         prg8_ab(space->machine(), data);
3439         break;
3440      case 0x4000:
3441         prg8_cd(space->machine(), data);
3442         break;
3443      case 0x6000:
3444         state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & 0x10) | (data & 0x0f);
3445         chr4_0(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
3446         break;
3447      case 0x7000:
3448         state->m_mmc_vrom_bank[1] = (state->m_mmc_vrom_bank[1] & 0x10) | (data & 0x0f);
3449         chr4_4(space->machine(), state->m_mmc_vrom_bank[1], CHRROM);
3450         break;
3451   }
3452}
3453
3454/*************************************************************
3455
3456 Konami VRC-2
3457
3458 In MESS: Supported.
3459
3460 *************************************************************/
3461
3462static WRITE8_HANDLER( konami_vrc2_w )
3463{
3464   nes_state *state = space->machine().driver_data<nes_state>();
3465   UINT8 bank, shift, mask;
3466   UINT32 shifted_offs = (offset & 0x7000)
3467                  | ((offset << (9 - state->m_vrc_ls_prg_a)) & 0x200)
3468                  | ((offset << (8 - state->m_vrc_ls_prg_b)) & 0x100);
3469   LOG_MMC(("konami_vrc2_w, offset: %04x, data: %02x\n", offset, data));
3470
3471   if (offset < 0x1000)
3472      prg8_89(space->machine(), data);
3473   else if (offset < 0x2000)
3474   {
3475      switch (data & 0x03)
3476      {
3477         case 0x00: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
3478         case 0x01: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
3479         case 0x02: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
3480         case 0x03: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
3481      }
3482   }
3483   else if (offset < 0x3000)
3484      prg8_ab(space->machine(), data);
3485   else if (offset < 0x7000)
3486   {
3487      bank = ((shifted_offs & 0x7000) - 0x3000) / 0x0800 + BIT(shifted_offs, 9);
3488      shift = BIT(shifted_offs, 8) * 4;
3489      mask = (0xf0 >> shift);
3490      state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & mask)
3491                           | (((data >> state->m_vrc_ls_chr) & 0x0f) << shift);
3492      chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], CHRROM);
3493   }
3494   else
3495      logerror("konami_vrc2_w uncaught write, addr: %04x value: %02x\n", offset + 0x8000, data);
3496}
3497
3498/*************************************************************
3499
3500 Konami VRC3
3501
3502 Games: Salamander
3503
3504 iNES: mapper 73
3505
3506 In MESS: Supported. It also uses konami_irq.
3507
3508 *************************************************************/
3509
3510static WRITE8_HANDLER( konami_vrc3_w )
3511{
3512   LOG_MMC(("konami_vrc3_w, offset: %04x, data: %02x\n", offset, data));
3513   nes_state *state = space->machine().driver_data<nes_state>();
3514
3515   switch (offset & 0x7000)
3516   {
3517      case 0x0000:
3518      case 0x1000:
3519         /* dunno which address controls these */
3520         state->m_IRQ_count_latch = data;
3521         state->m_IRQ_enable_latch = data;
3522         break;
3523      case 0x2000:
3524         state->m_IRQ_enable = data;
3525         break;
3526      case 0x3000:
3527         state->m_IRQ_count &= ~0x0f;
3528         state->m_IRQ_count |= data & 0x0f;
3529         break;
3530      case 0x4000:
3531         state->m_IRQ_count &= ~0xf0;
3532         state->m_IRQ_count |= (data & 0x0f) << 4;
3533         break;
3534      case 0x7000:
3535         prg16_89ab(space->machine(), data);
3536         break;
3537      default:
3538         logerror("konami_vrc3_w uncaught write, offset %04x, data: %02x\n", offset, data);
3539         break;
3540   }
3541}
3542
3543/*************************************************************
3544
3545 Konami VRC-4
3546
3547 In MESS: Supported
3548
3549 *************************************************************/
3550
3551static void vrc4_set_prg( running_machine &machine )
3552{
3553   nes_state *state = machine.driver_data<nes_state>();
3554   if (state->m_mmc_latch1 & 0x02)
3555   {
3556      prg8_89(machine, 0xfe);
3557      prg8_cd(machine, state->m_mmc_prg_bank[0]);
3558   }
3559   else
3560   {
3561      prg8_89(machine, state->m_mmc_prg_bank[0]);
3562      prg8_cd(machine, 0xfe);
3563   }
3564}
3565
3566static void konami_irq( device_t *device, int scanline, int vblank, int blanked )
3567{
3568   nes_state *state = device->machine().driver_data<nes_state>();
3569   /* Increment & check the IRQ scanline counter */
3570   if (state->m_IRQ_enable && (++state->m_IRQ_count == 0x100))
3571   {
3572      state->m_IRQ_count = state->m_IRQ_count_latch;
3573      state->m_IRQ_enable = state->m_IRQ_enable_latch;
3574      device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
3575   }
3576}
3577
3578static WRITE8_HANDLER( konami_vrc4_w )
3579{
3580   nes_state *state = space->machine().driver_data<nes_state>();
3581   UINT8 bank, shift, mask;
3582   UINT32 shifted_offs = (offset & 0x7000)
3583                  | ((offset << (9 - state->m_vrc_ls_prg_a)) & 0x200)
3584                  | ((offset << (8 - state->m_vrc_ls_prg_b)) & 0x100);
3585   LOG_MMC(("konami_vrc4_w, offset: %04x, data: %02x\n", offset, data));
3586
3587   if (offset < 0x1000)
3588   {
3589      state->m_mmc_prg_bank[0] = data;
3590      vrc4_set_prg(space->machine());
3591   }
3592   else if (offset >= 0x2000 && offset < 0x3000)
3593      prg8_ab(space->machine(), data);
3594   else
3595   {
3596      switch (shifted_offs & 0x7300)
3597      {
3598         case 0x1000:
3599         case 0x1100:
3600            switch (data & 0x03)
3601            {
3602            case 0x00: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
3603            case 0x01: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
3604            case 0x02: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
3605            case 0x03: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
3606            }
3607            break;
3608         case 0x1200:
3609         case 0x1300:
3610            state->m_mmc_latch1 = data & 0x02;
3611            vrc4_set_prg(space->machine());
3612            break;
3613         case 0x3000:
3614         case 0x3100:
3615         case 0x3200:
3616         case 0x3300:
3617         case 0x4000:
3618         case 0x4100:
3619         case 0x4200:
3620         case 0x4300:
3621         case 0x5000:
3622         case 0x5100:
3623         case 0x5200:
3624         case 0x5300:
3625         case 0x6000:
3626         case 0x6100:
3627         case 0x6200:
3628         case 0x6300:
3629            bank = ((shifted_offs & 0x7000) - 0x3000) / 0x0800 + BIT(shifted_offs, 9);
3630            shift = BIT(shifted_offs, 8) * 4;
3631            mask = (0xf0 >> shift);
3632            state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & mask) | ((data & 0x0f) << shift);
3633            chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], CHRROM);
3634            break;
3635         case 0x7000:
3636            state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0xf0) | (data & 0x0f);
3637            break;
3638         case 0x7100:
3639            state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0x0f) | ((data & 0x0f) << 4);
3640            break;
3641         case 0x7200:
3642            state->m_IRQ_mode = data & 0x04;   // currently not implemented: 0 = prescaler mode / 1 = CPU mode
3643            state->m_IRQ_enable = data & 0x02;
3644            state->m_IRQ_enable_latch = data & 0x01;
3645            if (data & 0x02)
3646               state->m_IRQ_count = state->m_IRQ_count_latch;
3647            break;
3648         case 0x7300:
3649            state->m_IRQ_enable = state->m_IRQ_enable_latch;
3650            break;
3651         default:
3652            logerror("konami_vrc4_w uncaught write, addr: %04x value: %02x\n", shifted_offs + 0x8000, data);
3653            break;
3654      }
3655   }
3656}
3657
3658/*************************************************************
3659
3660 Konami VRC-6
3661
3662 In MESS: Supported. It also uses konami_irq (there are IRQ
3663 issues though: see Akumajou Densetsu intro).
3664
3665 *************************************************************/
3666
3667static WRITE8_HANDLER( konami_vrc6_w )
3668{
3669   nes_state *state = space->machine().driver_data<nes_state>();
3670   UINT8 bank;
3671   UINT32 shifted_offs = (offset & 0x7000)
3672                  | ((offset << (9 - state->m_vrc_ls_prg_a)) & 0x200)
3673                  | ((offset << (8 - state->m_vrc_ls_prg_b)) & 0x100);
3674   LOG_MMC(("konami_vrc6_w, offset: %04x, data: %02x\n", offset, data));
3675
3676   if (offset < 0x1000)
3677      prg16_89ab(space->machine(), data);
3678   else if (offset >= 0x4000 && offset < 0x5000)
3679      prg8_cd(space->machine(), data);
3680   else
3681   {
3682      switch (shifted_offs & 0x7300)
3683      {
3684         case 0x1000:
3685         case 0x1100:
3686         case 0x1200:
3687         case 0x2000:
3688         case 0x2100:
3689         case 0x2200:
3690         case 0x3000:
3691         case 0x3100:
3692         case 0x3200:
3693            LOG_MMC(("Konami VRC-6 Sound write, offset: %04x, data: %02x\n", shifted_offs & 0x7300, data));
3694            break;
3695         case 0x3300:
3696            switch (data & 0x0c)
3697            {
3698            case 0x00: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
3699            case 0x04: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
3700            case 0x08: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
3701            case 0x0c: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
3702            }
3703            break;
3704         case 0x5000:
3705         case 0x5100:
3706         case 0x5200:
3707         case 0x5300:
3708         case 0x6000:
3709         case 0x6100:
3710         case 0x6200:
3711         case 0x6300:
3712            bank = ((shifted_offs & 0x7000) - 0x5000) / 0x0400 + ((shifted_offs & 0x0300) >> 8);
3713            chr1_x(space->machine(), bank, data, CHRROM);
3714            break;
3715         case 0x7000:
3716            state->m_IRQ_count_latch = data;
3717            break;
3718         case 0x7100:
3719            state->m_IRQ_mode = data & 0x04;   // currently not implemented: 0 = prescaler mode / 1 = CPU mode
3720            state->m_IRQ_enable = data & 0x02;
3721            state->m_IRQ_enable_latch = data & 0x01;
3722            if (data & 0x02)
3723               state->m_IRQ_count = state->m_IRQ_count_latch;
3724            break;
3725         case 0x7200:
3726            state->m_IRQ_enable = state->m_IRQ_enable_latch;
3727            break;
3728         default:
3729            logerror("konami_vrc6_w uncaught write, addr: %04x value: %02x\n", shifted_offs + 0x8000, data);
3730            break;
3731      }
3732   }
3733}
3734
3735/*************************************************************
3736
3737 Konami VRC7
3738
3739 Games: Lagrange Point, Tiny Toon Adventures 2
3740
3741 iNES: mapper 85
3742
3743 In MESS: Supported. It also uses konami_irq.
3744
3745 *************************************************************/
3746
3747static WRITE8_HANDLER( konami_vrc7_w )
3748{
3749   nes_state *state = space->machine().driver_data<nes_state>();
3750   UINT8 bank;
3751   LOG_MMC(("konami_vrc7_w, offset: %04x, data: %02x\n", offset, data));
3752
3753   switch (offset & 0x7018)
3754   {
3755      case 0x0000:
3756         prg8_89(space->machine(), data);
3757         break;
3758      case 0x0008:
3759      case 0x0010:
3760      case 0x0018:
3761         prg8_ab(space->machine(), data);
3762         break;
3763
3764      case 0x1000:
3765         prg8_cd(space->machine(), data);
3766         break;
3767
3768         /* TODO: there are sound regs in here */
3769
3770      case 0x2000:
3771      case 0x2008:
3772      case 0x2010:
3773      case 0x2018:
3774      case 0x3000:
3775      case 0x3008:
3776      case 0x3010:
3777      case 0x3018:
3778      case 0x4000:
3779      case 0x4008:
3780      case 0x4010:
3781      case 0x4018:
3782      case 0x5000:
3783      case 0x5008:
3784      case 0x5010:
3785      case 0x5018:
3786         bank = ((offset & 0x7000) - 0x2000) / 0x0800 + ((offset & 0x0018) ? 1 : 0);
3787         chr1_x(space->machine(), bank, data, state->m_mmc_chr_source);
3788         break;
3789
3790      case 0x6000:
3791         switch (data & 0x03)
3792         {
3793         case 0x00: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
3794         case 0x01: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
3795         case 0x02: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
3796         case 0x03: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
3797         }
3798         break;
3799      case 0x6008: case 0x6010: case 0x6018:
3800         state->m_IRQ_count_latch = data;
3801         break;
3802      case 0x7000:
3803         state->m_IRQ_mode = data & 0x04;   // currently not implemented: 0 = prescaler mode / 1 = CPU mode
3804         state->m_IRQ_enable = data & 0x02;
3805         state->m_IRQ_enable_latch = data & 0x01;
3806         if (data & 0x02)
3807            state->m_IRQ_count = state->m_IRQ_count_latch;
3808         break;
3809      case 0x7008: case 0x7010: case 0x7018:
3810         state->m_IRQ_enable = state->m_IRQ_enable_latch;
3811         break;
3812
3813      default:
3814         logerror("konami_vrc7_w uncaught write, addr: %04x value: %02x\n", offset + 0x8000, data);
3815         break;
3816   }
3817}
3818
3819/*************************************************************
3820
3821 Namcot-163 board emulation
3822
3823 Games: Battle Fleet, Family Circuit '91, Famista '90, '91,
3824 '92 & '94, Megami Tensei II, Top Striker, Wagyan Land 2 & 3
3825
3826 iNES: mapper 19
3827
3828 In MESS: Supported
3829
3830 *************************************************************/
3831
3832/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
3833 we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
3834 there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
3835static void namcot_irq( device_t *device, int scanline, int vblank, int blanked )
3836{
3837   nes_state *state = device->machine().driver_data<nes_state>();
3838
3839   if (state->m_IRQ_enable)
3840   {
3841      if (state->m_IRQ_count >= (0x7fff - 114))
3842      {
3843         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
3844         state->m_IRQ_count = 0;
3845      }
3846      else
3847         state->m_IRQ_count += 114;
3848   }
3849}
3850
3851static WRITE8_HANDLER( namcot163_l_w )
3852{
3853   nes_state *state = space->machine().driver_data<nes_state>();
3854   LOG_MMC(("namcot163_l_w, offset: %04x, data: %02x\n", offset, data));
3855   offset += 0x100;
3856
3857   switch (offset & 0x1800)
3858   {
3859      case 0x0800:
3860         LOG_MMC(("Namcot-163 sound reg write, data: %02x\n", data));
3861         break;
3862      case 0x1000: /* low byte of IRQ */
3863         state->m_IRQ_count = (state->m_IRQ_count & 0x7f00) | data;
3864         break;
3865      case 0x1800: /* high byte of IRQ, IRQ enable in high bit */
3866         state->m_IRQ_count = (state->m_IRQ_count & 0xff) | ((data & 0x7f) << 8);
3867         state->m_IRQ_enable = data & 0x80;
3868         break;
3869   }
3870}
3871
3872static READ8_HANDLER( namcot163_l_r )
3873{
3874   nes_state *state = space->machine().driver_data<nes_state>();
3875   LOG_MMC(("namcot163_l_r, offset: %04x\n", offset));
3876   offset += 0x100;
3877
3878   switch (offset & 0x1800)
3879   {
3880      case 0x1000:
3881         return state->m_IRQ_count & 0xff;
3882      case 0x1800:
3883         return (state->m_IRQ_count >> 8) & 0xff;
3884      case 0x0800:
3885         LOG_MMC(("Namcot-163 sound reg read\n"));
3886      default:
3887         return 0x00;
3888   }
3889}
3890
3891static void namcot163_set_mirror( running_machine &machine, UINT8 page, UINT8 data )
3892{
3893   if (!(data < 0xe0))
3894      set_nt_page(machine, page, CIRAM, data & 0x01, 1);
3895   else
3896      set_nt_page(machine, page, ROM, data, 0);
3897}
3898
3899static WRITE8_HANDLER( namcot163_w )
3900{
3901   nes_state *state = space->machine().driver_data<nes_state>();
3902   LOG_MMC(("namcot163_w, offset: %04x, data: %02x\n", offset, data));
3903   switch (offset & 0x7800)
3904   {
3905      case 0x0000: case 0x0800:
3906      case 0x1000: case 0x1800:
3907      case 0x2000: case 0x2800:
3908      case 0x3000: case 0x3800:
3909         chr1_x(space->machine(), offset / 0x800, data, CHRROM);
3910         break;
3911      case 0x4000:
3912         namcot163_set_mirror(space->machine(), 0, data);
3913         break;
3914      case 0x4800:
3915         namcot163_set_mirror(space->machine(), 1, data);
3916         break;
3917      case 0x5000:
3918         namcot163_set_mirror(space->machine(), 2, data);
3919         break;
3920      case 0x5800:
3921         namcot163_set_mirror(space->machine(), 3, data);
3922         break;
3923      case 0x6000:
3924         prg8_89(space->machine(), data & 0x3f);
3925         break;
3926      case 0x6800:
3927         state->m_mmc_latch1 = data & 0xc0;      // this should enable High CHRRAM, but we still have to properly implement it!
3928         prg8_ab(space->machine(), data & 0x3f);
3929         break;
3930      case 0x7000:
3931         prg8_cd(space->machine(), data & 0x3f);
3932         break;
3933      case 0x7800:
3934         LOG_MMC(("Namcot-163 sound address write, data: %02x\n", data));
3935         break;
3936   }
3937}
3938
3939/*************************************************************
3940
3941 Sunsoft-1 board emulation
3942
3943 Games: Atlantis no Nazo, Kanshakudama Nage Kantarou no
3944 Toukaidou Gojuusan Tsugi, Wing of Madoola, Fantasy Zone
3945
3946 iNES: mapper 184 (Fantasy Zone uses this board with no
3947 CHRROM, and the register switches PRG banks)
3948
3949 *************************************************************/
3950
3951static WRITE8_HANDLER( sunsoft1_m_w )
3952{
3953   nes_state *state = space->machine().driver_data<nes_state>();
3954   LOG_MMC(("sunsoft1_m_w, offset: %04x, data: %02x\n", offset, data));
3955
3956   if (state->m_chr_chunks)
3957   {
3958      chr4_0(space->machine(), data & 0x0f, CHRROM);
3959      chr4_4(space->machine(), data >> 4, CHRROM);
3960   }
3961   else
3962      prg16_89ab(space->machine(), data & 0x0f);
3963}
3964
3965/*************************************************************
3966
3967 Sunsoft-2 board emulation
3968
3969 The two games using this board have incompatible mirroring
3970 wiring, making necessary two distinct mappers & pcb_id
3971
3972 iNES: mapper 89 & 93
3973
3974 *************************************************************/
3975
3976static WRITE8_HANDLER( sunsoft2_w )
3977{
3978   nes_state *state = space->machine().driver_data<nes_state>();
3979   UINT8 sunsoft_helper = (data & 0x07) | ((data & 0x80) ? 0x08 : 0x00);
3980   LOG_MMC(("sunsoft2_w, offset: %04x, data: %02x\n", offset, data));
3981
3982   if (!state->m_hard_mirroring)   // there are two 'variants' depending on hardwired or mapper ctrl mirroring
3983      set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
3984   if (state->m_chr_chunks)
3985      chr8(space->machine(), sunsoft_helper, CHRROM);
3986
3987   prg16_89ab(space->machine(), data >> 4);
3988}
3989
3990/*************************************************************
3991
3992 Sunsoft-3 board emulation
3993
3994 The two games using this board have incompatible mirroring
3995 wiring, making necessary two distinct mappers & pcb_id
3996
3997 iNES: mapper 67
3998
3999 *************************************************************/
4000
4001/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
4002 we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
4003 there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
4004static void sunsoft3_irq( device_t *device, int scanline, int vblank, int blanked )
4005{
4006   nes_state *state = device->machine().driver_data<nes_state>();
4007
4008   /* TODO: change to reflect the actual number of cycles spent: both using 114 or cycling 114,114,113
4009     produces a 1-line glitch in Fantasy Zone 2: it really requires the counter to be updated each CPU cycle! */
4010   if (state->m_IRQ_enable)
4011   {
4012      if (state->m_IRQ_count <= 114)
4013      {
4014         state->m_IRQ_enable = 0;
4015         state->m_IRQ_count = 0xffff;
4016         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
4017      }
4018      else
4019         state->m_IRQ_count -= 114;
4020   }
4021}
4022
4023static WRITE8_HANDLER( sunsoft3_w )
4024{
4025   nes_state *state = space->machine().driver_data<nes_state>();
4026   LOG_MMC(("sunsoft3_w, offset %04x, data: %02x\n", offset, data));
4027
4028   switch (offset & 0x7800)
4029   {
4030      case 0x0800:
4031         chr2_0(space->machine(), data, CHRROM);
4032         break;
4033      case 0x1800:
4034         chr2_2(space->machine(), data, CHRROM);
4035         break;
4036      case 0x2800:
4037         chr2_4(space->machine(), data, CHRROM);
4038         break;
4039      case 0x3800:
4040         chr2_6(space->machine(), data, CHRROM);
4041         break;
4042      case 0x4000:
4043      case 0x4800:
4044         state->m_IRQ_toggle ^= 1;
4045         if (state->m_IRQ_toggle)
4046            state->m_IRQ_count = (state->m_IRQ_count & 0x00ff) | (data << 8);
4047         else
4048            state->m_IRQ_count = (state->m_IRQ_count & 0xff00) | data;
4049         break;
4050      case 0x5800:
4051         state->m_IRQ_enable = BIT(data, 4);
4052         state->m_IRQ_toggle = 0;
4053         break;
4054      case 0x6800:
4055         switch (data & 3)
4056         {
4057         case 0x00: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
4058         case 0x01: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
4059         case 0x02: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
4060         case 0x03: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
4061         }
4062         break;
4063      case 0x7800:
4064         prg16_89ab(space->machine(), data);
4065         break;
4066      default:
4067         LOG_MMC(("sunsoft3_w uncaught write, offset: %04x, data: %02x\n", offset, data));
4068         break;
4069   }
4070}
4071
4072/*************************************************************
4073
4074 Taito TC0190FMC + board emulation
4075
4076 Games: Akira, Bakushou!! Jinsei Gekijou, Don Doko Don,
4077 Insector X, Operation Wolf, Power Blazer, Takeshi no
4078 Sengoku Fuuunji
4079
4080 iNES: mapper 33
4081
4082 In MESS: Supported.
4083
4084 *************************************************************/
4085
4086static WRITE8_HANDLER( tc0190fmc_w )
4087{
4088   LOG_MMC(("tc0190fmc_w, offset: %04x, data: %02x\n", offset, data));
4089
4090   switch (offset & 0x7003)
4091   {
4092      case 0x0000:
4093         set_nt_mirroring(space->machine(), BIT(data, 6) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
4094         prg8_89(space->machine(), data);
4095         break;
4096      case 0x0001:
4097         prg8_ab(space->machine(), data);
4098         break;
4099      case 0x0002:
4100         chr2_0(space->machine(), data, CHRROM);
4101         break;
4102      case 0x0003:
4103         chr2_2(space->machine(), data, CHRROM);
4104         break;
4105      case 0x2000:
4106         chr1_4(space->machine(), data, CHRROM);
4107         break;
4108      case 0x2001:
4109         chr1_5(space->machine(), data, CHRROM);
4110         break;
4111      case 0x2002:
4112         chr1_6(space->machine(), data, CHRROM);
4113         break;
4114      case 0x2003:
4115         chr1_7(space->machine(), data, CHRROM);
4116         break;
4117   }
4118}
4119
4120/*************************************************************
4121
4122 Taito TC0190FMC + PAL16R4 board emulation
4123
4124 Games: Bakushou!! Jinsei Gekijou 3, Bubble Bobble 2,
4125 Captain Saver, Don Doko Don 2, Flintstones, Jetsons
4126
4127 This is basically Mapper 33 + IRQ. Notably, IRQ works the
4128 same as MMC3 irq, BUT latch values are "inverted" (XOR'ed
4129 with 0xff) and there is a little delay (not implemented yet)
4130 We simply use MMC3 IRQ and XOR the value written in the
4131 register 0xc000 below
4132
4133 iNES: mapper 48
4134
4135 In MESS: Supported.
4136
4137 *************************************************************/
4138
4139static WRITE8_HANDLER( tc0190fmc_p16_w )
4140{
4141   nes_state *state = space->machine().driver_data<nes_state>();
4142   LOG_MMC(("tc0190fmc_p16_w, offset: %04x, data: %02x\n", offset, data));
4143
4144   switch (offset & 0x7003)
4145   {
4146      case 0x0000:
4147         prg8_89(space->machine(), data);
4148         break;
4149      case 0x0001:
4150      case 0x0002:
4151      case 0x0003:
4152      case 0x2000:
4153      case 0x2001:
4154      case 0x2002:
4155      case 0x2003:
4156         tc0190fmc_w(space, offset, data);
4157         break;
4158      case 0x4000:
4159         state->m_IRQ_count_latch = (0x100 - data) & 0xff;
4160         break;
4161      case 0x4001:
4162         state->m_IRQ_count = state->m_IRQ_count_latch;
4163         break;
4164      case 0x4002:
4165         state->m_IRQ_enable = 1;
4166         break;
4167      case 0x4003:
4168         state->m_IRQ_enable = 0;
4169         break;
4170      case 0x6000:
4171         set_nt_mirroring(space->machine(), BIT(data, 6) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
4172         break;
4173   }
4174}
4175
4176/*************************************************************
4177
4178 Taito X1-005 board emulation
4179
4180 Actually, Fudou Myouou Den uses a variant of the board with
4181 CIRAM, making necessary two distinct mappers & pcb_id.
4182
4183 Also, we miss to emulate the security check at 0x7ef8 / 0x7ef9
4184 and the 0x80 ram!
4185
4186 iNES: mappers 80 & 207
4187
4188 *************************************************************/
4189
4190static WRITE8_HANDLER( x1005_m_w )
4191{
4192   nes_state *state = space->machine().driver_data<nes_state>();
4193   LOG_MMC(("x1005_m_w, offset: %04x, data: %02x\n", offset, data));
4194
4195   switch (offset)
4196   {
4197      case 0x1ef0:
4198         chr2_0(space->machine(), (data & 0x7f) >> 1, CHRROM);
4199         break;
4200      case 0x1ef1:
4201         chr2_2(space->machine(), (data & 0x7f) >> 1, CHRROM);
4202         break;
4203      case 0x1ef2:
4204         chr1_4(space->machine(), data, CHRROM);
4205         break;
4206      case 0x1ef3:
4207         chr1_5(space->machine(), data, CHRROM);
4208         break;
4209      case 0x1ef4:
4210         chr1_6(space->machine(), data, CHRROM);
4211         break;
4212      case 0x1ef5:
4213         chr1_7(space->machine(), data, CHRROM);
4214         break;
4215      case 0x1ef6:
4216      case 0x1ef7:
4217         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
4218         break;
4219      case 0x1ef8:
4220      case 0x1ef9:
4221         state->m_mmc_latch1 = data;
4222         break;
4223      case 0x1efa:
4224      case 0x1efb:
4225         prg8_89(space->machine(), data);
4226         break;
4227      case 0x1efc:
4228      case 0x1efd:
4229         prg8_ab(space->machine(), data);
4230         break;
4231      case 0x1efe:
4232      case 0x1eff:
4233         prg8_cd(space->machine(), data);
4234         break;
4235      default:
4236         logerror("mapper80_m_w uncaught addr: %04x, value: %02x\n", offset + 0x6000, data);
4237         break;
4238   }
4239
4240   if (offset >= 0x1f00 && state->m_mapper_ram != NULL && state->m_mmc_latch1 == 0xa3)
4241      state->m_mapper_ram[offset & (state->m_mapper_ram_size - 1)] = data;
4242   else if (offset >= 0x1f00 && state->m_mapper_bram != NULL && state->m_mmc_latch1 == 0xa3)
4243      state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)] = data;
4244}
4245
4246static READ8_HANDLER( x1005_m_r )
4247{
4248   nes_state *state = space->machine().driver_data<nes_state>();
4249   LOG_MMC(("x1005a_m_r, offset: %04x\n", offset));
4250
4251   if (offset >= 0x1f00 && state->m_mapper_ram != NULL && state->m_mmc_latch1 == 0xa3)
4252      return state->m_mapper_ram[offset & (state->m_mapper_ram_size - 1)];
4253   else if (offset >= 0x1f00 && state->m_mapper_bram != NULL && state->m_mmc_latch1 == 0xa3)
4254      return state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)];
4255
4256   return 0xff;
4257}
4258
4259static WRITE8_HANDLER( x1005a_m_w )
4260{
4261   LOG_MMC(("x1005a_m_w, offset: %04x, data: %02x\n", offset, data));
4262
4263   // similar to x1005_m_w but mirroring is handled differently
4264   if (offset == 0x1ef6 || offset == 0x1ef7)
4265      return;
4266
4267   switch (offset)
4268   {
4269      case 0x1ef0:
4270         set_nt_page(space->machine(), 0, CIRAM, (data & 0x80) ? 1 : 0, 1);
4271         set_nt_page(space->machine(), 1, CIRAM, (data & 0x80) ? 1 : 0, 1);
4272         break;
4273      case 0x1ef1:
4274         set_nt_page(space->machine(), 2, CIRAM, (data & 0x80) ? 1 : 0, 1);
4275         set_nt_page(space->machine(), 3, CIRAM, (data & 0x80) ? 1 : 0, 1);
4276         break;
4277   }
4278
4279   x1005_m_w(space, offset, data);
4280}
4281
4282/*************************************************************
4283
4284 Taito X1-017 board emulation
4285
4286 We miss to emulate the security check at 0x6000-0x73ff
4287 and the ram!
4288
4289 Games: Kyuukyoku Harikiri Koushien, Kyuukyoku Harikiri
4290 Stadium, SD Keiji - Blader
4291
4292 iNES: mapper 82
4293
4294 In MESS: Supported.
4295
4296 *************************************************************/
4297
4298static void x1017_set_chr( running_machine &machine )
4299{
4300   nes_state *state = machine.driver_data<nes_state>();
4301   if (state->m_mmc_latch1)
4302   {
4303      chr2_4(machine, state->m_mmc_vrom_bank[0] >> 1, CHRROM);
4304      chr2_6(machine, state->m_mmc_vrom_bank[1] >> 1, CHRROM);
4305   }
4306   else
4307   {
4308      chr2_0(machine, state->m_mmc_vrom_bank[0] >> 1, CHRROM);
4309      chr2_2(machine, state->m_mmc_vrom_bank[1] >> 1, CHRROM);
4310   }
4311   chr1_x(machine, 4 ^ state->m_mmc_latch1, state->m_mmc_vrom_bank[2], CHRROM);
4312   chr1_x(machine, 5 ^ state->m_mmc_latch1, state->m_mmc_vrom_bank[3], CHRROM);
4313   chr1_x(machine, 6 ^ state->m_mmc_latch1, state->m_mmc_vrom_bank[4], CHRROM);
4314   chr1_x(machine, 7 ^ state->m_mmc_latch1, state->m_mmc_vrom_bank[5], CHRROM);
4315}
4316
4317static WRITE8_HANDLER( x1017_m_w )
4318{
4319   nes_state *state = space->machine().driver_data<nes_state>();
4320   UINT8 reg = offset & 0x07;
4321   LOG_MMC(("x1017_m_w, offset: %04x, data: %02x\n", offset, data));
4322
4323   switch (offset)
4324   {
4325      case 0x1ef0:
4326      case 0x1ef1:
4327         if (state->m_mmc_vrom_bank[reg] != data)
4328         {
4329            state->m_mmc_vrom_bank[reg] = data;
4330            x1017_set_chr(space->machine());
4331         }
4332         break;
4333      case 0x1ef2:
4334      case 0x1ef3:
4335      case 0x1ef4:
4336      case 0x1ef5:
4337         if (state->m_mmc_vrom_bank[reg] != data)
4338         {
4339            state->m_mmc_vrom_bank[reg] = data;
4340            x1017_set_chr(space->machine());
4341         }
4342         break;
4343      case 0x1ef6:
4344         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
4345         state->m_mmc_latch1 = ((data & 0x02) << 1);
4346         x1017_set_chr(space->machine());
4347         break;
4348      case 0x1ef7:
4349      case 0x1ef8:
4350      case 0x1ef9:
4351         state->m_mmc_reg[(offset & 0x0f) - 7] = data;
4352         break;
4353      case 0x1efa:
4354         prg8_89(space->machine(), data >> 2);
4355         break;
4356      case 0x1efb:
4357         prg8_ab(space->machine(), data >> 2);
4358         break;
4359      case 0x1efc:
4360         prg8_cd(space->machine(), data >> 2);
4361         break;
4362      default:
4363         logerror("x1017_m_w uncaught write, addr: %04x, value: %02x\n", offset + 0x6000, data);
4364         break;
4365   }
4366}
4367
4368static READ8_HANDLER( x1017_m_r )
4369{
4370   nes_state *state = space->machine().driver_data<nes_state>();
4371   LOG_MMC(("x1017_m_r, offset: %04x\n", offset));
4372
4373   // 2+2+1 KB of Internal RAM can be independently enabled/disabled!
4374   if (offset < 0x0800 && state->m_mapper_bram != NULL && state->m_mmc_reg[0] == 0xca)
4375      return state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)];
4376   if (offset < 0x1000 && state->m_mapper_bram != NULL && state->m_mmc_reg[1] == 0x69)
4377      return state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)];
4378   if (offset < 0x1800 && state->m_mapper_bram != NULL && state->m_mmc_reg[2] == 0x84)
4379      return state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)];
4380
4381   return 0xff;
4382}
4383
4384/*************************************************************
4385
4386      MISC UNLICENSED BOARDS
4387
4388 *************************************************************/
4389
4390/*************************************************************
4391
4392 AGCI 50282 bootleg board emulation
4393
4394 Games: Death Race
4395
4396 iNES: mapper 144
4397
4398 In MESS: Supported.
4399
4400 *************************************************************/
4401
4402static WRITE8_HANDLER( agci_50282_w )
4403{
4404   LOG_MMC(("agci_50282_w, offset: %04x, data: %02x\n", offset, data));
4405
4406   offset += 0x8000;
4407   data |= (space->read_byte(offset) & 1);
4408
4409   chr8(space->machine(), data >> 4, CHRROM);
4410   prg32(space->machine(), data);
4411}
4412
4413/*************************************************************
4414
4415 AVE NINA-001 board emulation
4416
4417 iNES: mapper 34
4418
4419 *************************************************************/
4420
4421static WRITE8_HANDLER( nina01_m_w )
4422{
4423   LOG_MMC(("nina01_m_w, offset: %04x, data: %02x\n", offset, data));
4424
4425   switch (offset)
4426   {
4427      case 0x1ffd:
4428         prg32(space->machine(), data);
4429         break;
4430      case 0x1ffe:
4431         chr4_0(space->machine(), data, CHRROM);
4432         break;
4433      case 0x1fff:
4434         chr4_4(space->machine(), data, CHRROM);
4435         break;
4436   }
4437}
4438
4439/*************************************************************
4440
4441 AVE NINA-003, NINA-006 and MB-91 boards emulation
4442
4443 Games: Krazy Kreatures, Poke Block, Puzzle, Pyramid,
4444 Solitaire, Ultimate League Soccer
4445
4446 iNES: mapper 79
4447
4448 In MESS: Supported.
4449
4450 *************************************************************/
4451
4452static WRITE8_HANDLER( nina06_l_w )
4453{
4454   LOG_MMC(("nina06_l_w, offset: %04x, data: %02x\n", offset, data));
4455
4456   if (!(offset & 0x0100))
4457   {
4458      prg32(space->machine(), data >> 3);
4459      chr8(space->machine(), data, CHRROM);
4460   }
4461}
4462
4463/*************************************************************
4464
4465 Active Entertainment Action 52 board emulation
4466
4467 iNES: mapper 228
4468
4469 *************************************************************/
4470
4471static WRITE8_HANDLER( ae_act52_w )
4472{
4473   int pbank, cbank;
4474   UINT8 pmode;
4475   LOG_MMC(("ae_act52_w, offset: %04x, data: %02x\n", offset, data));
4476
4477   set_nt_mirroring(space->machine(), BIT(offset, 13) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
4478
4479   cbank = (data & 0x03) | ((offset & 0x0f) << 2);
4480   chr8(space->machine(), cbank, CHRROM);
4481
4482   pmode = offset & 0x20;
4483   pbank = (offset & 0x1fc0) >> 6;
4484   if (pmode)
4485   {
4486      prg16_89ab(space->machine(), pbank);
4487      prg16_cdef(space->machine(), pbank);
4488   }
4489   else
4490      prg32(space->machine(), pbank >> 1);
4491}
4492
4493
4494/*************************************************************
4495
4496 C & E Bootleg Board for Decathlon
4497
4498 Games: Decathlon
4499
4500 Pretty simple mapper: writes to 0x8065-0x80a4 set prg32 to
4501 data & 3; writes to 0x80a5-0x80e4 set chr8 to data & 7
4502
4503 iNES: mapper 244
4504
4505 In MESS: Supported.
4506
4507 *************************************************************/
4508
4509static WRITE8_HANDLER( cne_decathl_w )
4510{
4511   LOG_MMC(("cne_decathl_w, offset: %04x, data: %02x\n", offset, data));
4512
4513   if (offset < 0x0065)
4514      return;
4515   if (offset < 0x00a5)
4516   {
4517      prg32(space->machine(), (offset - 0x0065) & 0x03);
4518      return;
4519   }
4520   if (offset < 0x00e5)
4521   {
4522      chr8(space->machine(), (offset - 0x00a5) & 0x07, CHRROM);
4523   }
4524}
4525
4526/*************************************************************
4527
4528 C & E Bootleg Board for Fong Shen Bang
4529
4530 Games: Fong Shen Bang - Zhu Lu Zhi Zhan
4531
4532 Simple mapper: writes to 0x6000-0x67ff set PRG and CHR banks.
4533 Namely, 0x6000->0x6003 select resp. prg8_89, prg8_ab, prg8_cd
4534 and prg8_ef. 0x6004->0x6007 select resp. crh2_0, chr2_2,
4535 chr2_4 and chr2_6. In 0x6800-0x7fff lies WRAM.
4536
4537 iNES: mapper 246
4538
4539 In MESS: Supported.
4540
4541 *************************************************************/
4542
4543static WRITE8_HANDLER( cne_fsb_m_w )
4544{
4545   nes_state *state = space->machine().driver_data<nes_state>();
4546   LOG_MMC(("cne_fsb_m_w, offset: %04x, data: %02x\n", offset, data));
4547
4548   if (offset < 0x0800)
4549   {
4550      switch (offset & 0x0007)
4551      {
4552         case 0x0000:
4553            prg8_89(space->machine(), data);
4554            break;
4555         case 0x0001:
4556            prg8_ab(space->machine(), data);
4557            break;
4558         case 0x0002:
4559            prg8_cd(space->machine(), data);
4560            break;
4561         case 0x0003:
4562            prg8_ef(space->machine(), data);
4563            break;
4564         case 0x0004:
4565            chr2_0(space->machine(), data, CHRROM);
4566            break;
4567         case 0x0005:
4568            chr2_2(space->machine(), data, CHRROM);
4569            break;
4570         case 0x0006:
4571            chr2_4(space->machine(), data, CHRROM);
4572            break;
4573         case 0x0007:
4574            chr2_6(space->machine(), data, CHRROM);
4575            break;
4576      }
4577   }
4578   else
4579      state->m_battery_ram[offset] = data;
4580}
4581
4582/*************************************************************
4583
4584 C & E Bootleg Board for Sheng Huo Lie Zhuan
4585
4586 Games: Jing Ke Xin Zhuan, Sheng Huo Lie Zhuan
4587
4588 Simple Mapper: writes to 0x4020-0x5fff sets prg32 to
4589 data>>4 and chr8 to data&f. We currently do not map
4590 writes to 0x4020-0x40ff (to do: verify if this produces
4591 issues)
4592
4593 iNES: mapper 240
4594
4595 In MESS: Supported.
4596
4597 *************************************************************/
4598
4599static WRITE8_HANDLER( cne_shlz_l_w )
4600{
4601   LOG_MMC(("cne_shlz_l_w, offset: %04x, data: %02x\n", offset, data));
4602
4603   prg32(space->machine(), data >> 4);
4604   chr8(space->machine(), data & 0x0f, CHRROM);
4605}
4606
4607/*************************************************************
4608
4609 Caltron 6 in 1 Board
4610
4611 Games: 6 in 1 by Caltron
4612
4613 iNES: mapper 41
4614
4615 In MESS: Supported.
4616
4617 *************************************************************/
4618
4619static WRITE8_HANDLER( caltron6in1_m_w )
4620{
4621   nes_state *state = space->machine().driver_data<nes_state>();
4622   LOG_MMC(("caltron6in1_m_w, offset: %04x, data: %02x\n", offset, data));
4623
4624   state->m_mmc_latch1 = offset & 0xff;
4625   set_nt_mirroring(space->machine(), BIT(data, 5) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
4626   prg32(space->machine(), offset & 0x07);
4627}
4628
4629static WRITE8_HANDLER( caltron6in1_w )
4630{
4631   nes_state *state = space->machine().driver_data<nes_state>();
4632   LOG_MMC(("caltron6in1_w, offset: %04x, data: %02x\n", offset, data));
4633
4634   if (state->m_mmc_latch1 & 0x04)
4635      chr8(space->machine(), ((state->m_mmc_latch1 & 0x18) >> 1) | (data & 0x03), CHRROM);
4636}
4637
4638/*************************************************************
4639
4640 Camerica Boards (BF9093, BF9097, BF909X, ALGNV11)
4641
4642 Games: Linus Spacehead's Cosmic Crusade, Micro Machines,
4643 Mig-29, Stunt Kids
4644
4645 To emulate NT mirroring for BF9097 board (missing in BF9093)
4646 we use crc_hack, however Fire Hawk is broken (but without
4647 mirroring there would be no helicopter graphics).
4648
4649 iNES: mapper 71
4650
4651 In MESS: Partially Supported.
4652
4653 *************************************************************/
4654
4655static WRITE8_HANDLER( bf9093_w )
4656{
4657   nes_state *state = space->machine().driver_data<nes_state>();
4658   LOG_MMC(("bf9093_w, offset: %04x, data: %02x\n", offset, data));
4659
4660   switch (offset & 0x7000)
4661   {
4662      case 0x0000:
4663      case 0x1000:
4664         if (!state->m_hard_mirroring)
4665            set_nt_mirroring(space->machine(), BIT(data, 4) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
4666         break;
4667      case 0x4000:
4668      case 0x5000:
4669      case 0x6000:
4670      case 0x7000:
4671         prg16_89ab(space->machine(), data);
4672         break;
4673   }
4674}
4675
4676/*************************************************************
4677
4678 Camerica BF9096 & ALGQV11 Boards
4679
4680 Games: Quattro Adventure, Quattro Arcade, Quattro Sports
4681
4682 Writes to 0x8000-0x9fff set prg block to (data&0x18)>>1,
4683 writes to 0xa000-0xbfff set prg page to data&3. selected
4684 prg are: prg16_89ab = block|page, prg_cdef = 3|page.
4685 For more info on the hardware to bypass the NES lockout, see
4686 Kevtris' Camerica Mappers documentation.
4687
4688 iNES: mapper 232
4689
4690 In MESS: Supported.
4691
4692 *************************************************************/
4693
4694static void bf9096_set_prg( running_machine &machine )
4695{
4696   nes_state *state = machine.driver_data<nes_state>();
4697   prg16_89ab(machine, (state->m_mmc_latch2 & 0x03) | ((state->m_mmc_latch1 & 0x18) >> 1));
4698   prg16_cdef(machine, 0x03 | ((state->m_mmc_latch1 & 0x18) >> 1));
4699}
4700
4701static WRITE8_HANDLER( bf9096_w )
4702{
4703   nes_state *state = space->machine().driver_data<nes_state>();
4704   LOG_MMC(("bf9096_w, offset: %04x, data: %02x\n", offset, data));
4705
4706   if (offset < 0x2000)
4707      state->m_mmc_latch1 = data;
4708   else
4709      state->m_mmc_latch2 = data;
4710
4711   bf9096_set_prg(space->machine());
4712}
4713
4714/*************************************************************
4715
4716 Camerica Golden Five board
4717
4718 Games: Pegasus 5 in 1
4719
4720 iNES: mapper 104
4721
4722 In MESS: Supported.
4723
4724 *************************************************************/
4725
4726static WRITE8_HANDLER( golden5_w )
4727{
4728   nes_state *state = space->machine().driver_data<nes_state>();
4729   LOG_MMC(("golden5_w, offset: %04x, data: %02x\n", offset, data));
4730
4731   if (offset < 0x4000)
4732   {
4733      if (data & 0x08)
4734      {
4735         state->m_mmc_prg_bank[0] = ((data & 0x07) << 4) | (state->m_mmc_prg_bank[0] & 0x0f);
4736         prg16_89ab(space->machine(), state->m_mmc_prg_bank[0]);
4737         prg16_cdef(space->machine(), ((data & 0x07) << 4) | 0x0f);
4738      }
4739
4740   }
4741   else
4742   {
4743      state->m_mmc_prg_bank[0] = (state->m_mmc_prg_bank[0] & 0x70) | (data & 0x0f);
4744      prg16_89ab(space->machine(), state->m_mmc_prg_bank[0]);
4745   }
4746}
4747
4748/*************************************************************
4749
4750 Cony Bootleg Board
4751
4752 Games: Dragon Ball Party, Fatal Fury 2, Street Blaster II
4753 Pro, World Heroes 2
4754
4755 iNES: mapper 83
4756
4757 In MESS: Supported.
4758
4759 *************************************************************/
4760
4761static WRITE8_HANDLER( cony_l_w )
4762{
4763   nes_state *state = space->machine().driver_data<nes_state>();
4764   LOG_MMC(("cony_l_w, offset: %04x, data: %02x\n", offset, data));
4765
4766   if (offset >= 0x1000 && offset < 0x1103) // from 0x5100-0x51ff
4767      state->m_mapper83_low_reg[offset & 0x03] = data;
4768}
4769
4770static READ8_HANDLER( cony_l_r )
4771{
4772   nes_state *state = space->machine().driver_data<nes_state>();
4773   LOG_MMC(("cony_l_r, offset: %04x\n", offset));
4774
4775   if (offset == 0x0f00)   // 0x5000
4776   {
4777      // read dipswitch bit! - currently unimplemented
4778   }
4779   if (offset >= 0x1000 && offset < 0x1103) // from 0x5100-0x51ff
4780      return state->m_mapper83_low_reg[offset & 0x03];
4781   else
4782      return 0x00;
4783}
4784
4785static void cony_set_prg( running_machine &machine )
4786{
4787   nes_state *state = machine.driver_data<nes_state>();
4788   prg16_89ab(machine, state->m_mapper83_reg[8] & 0x3f);
4789   prg16_cdef(machine, (state->m_mapper83_reg[8] & 0x30) | 0x0f);
4790}
4791
4792static void cony_set_chr( running_machine &machine )
4793{
4794   nes_state *state = machine.driver_data<nes_state>();
4795   // FIXME: here we emulate at least 3 different boards!!!
4796   // one board switches 1k VROM banks only
4797   // one writes to 0x8000 and then switches 2k VROM banks only
4798   // one writes to 0x831n (n=2,3,4,5) and then switches 2k VROM banks only
4799   // we should split them and possibly document the proper behavior of each variant
4800   if (state->m_mmc_latch1 && !state->m_mmc_latch2)
4801   {
4802      chr2_0(machine, state->m_mapper83_reg[0], CHRROM);
4803      chr2_2(machine, state->m_mapper83_reg[1], CHRROM);
4804      chr2_4(machine, state->m_mapper83_reg[6], CHRROM);
4805      chr2_6(machine, state->m_mapper83_reg[7], CHRROM);
4806   }
4807   else
4808   {
4809      chr1_0(machine, state->m_mapper83_reg[0] | ((state->m_mapper83_reg[8] & 0x30) << 4), CHRROM);
4810      chr1_1(machine, state->m_mapper83_reg[1] | ((state->m_mapper83_reg[8] & 0x30) << 4), CHRROM);
4811      chr1_2(machine, state->m_mapper83_reg[2] | ((state->m_mapper83_reg[8] & 0x30) << 4), CHRROM);
4812      chr1_3(machine, state->m_mapper83_reg[3] | ((state->m_mapper83_reg[8] & 0x30) << 4), CHRROM);
4813      chr1_4(machine, state->m_mapper83_reg[4] | ((state->m_mapper83_reg[8] & 0x30) << 4), CHRROM);
4814      chr1_5(machine, state->m_mapper83_reg[5] | ((state->m_mapper83_reg[8] & 0x30) << 4), CHRROM);
4815      chr1_6(machine, state->m_mapper83_reg[6] | ((state->m_mapper83_reg[8] & 0x30) << 4), CHRROM);
4816      chr1_7(machine, state->m_mapper83_reg[7] | ((state->m_mapper83_reg[8] & 0x30) << 4), CHRROM);
4817   }
4818}
4819
4820static WRITE8_HANDLER( cony_w )
4821{
4822   nes_state *state = space->machine().driver_data<nes_state>();
4823   LOG_MMC(("cony_w, offset: %04x, data: %02x\n", offset, data));
4824
4825   switch (offset)
4826   {
4827      case 0x0000:
4828         state->m_mmc_latch1 = 1;
4829      case 0x3000:
4830      case 0x30ff:
4831      case 0x31ff:
4832         state->m_mapper83_reg[8] = data;
4833         cony_set_prg(space->machine());
4834         cony_set_chr(space->machine());
4835         break;
4836      case 0x0100:
4837         state->m_mmc_reg[0] = data & 0x80;
4838         switch (data & 0x03)
4839         {
4840         case 0:
4841            set_nt_mirroring(space->machine(), PPU_MIRROR_VERT);
4842            break;
4843         case 1:
4844            set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ);
4845            break;
4846         case 2:
4847            set_nt_mirroring(space->machine(), PPU_MIRROR_LOW);
4848            break;
4849         case 3:
4850            set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH);
4851            break;
4852         }
4853         break;
4854      case 0x0200:
4855         state->m_IRQ_count = (state->m_IRQ_count & 0xff00) | data;
4856         break;
4857      case 0x0201:
4858         state->m_IRQ_enable = state->m_mmc_reg[0];
4859         state->m_IRQ_count = (data << 8) | (state->m_IRQ_count & 0xff);
4860         break;
4861      case 0x0300:
4862         prg8_89(space->machine(), data);
4863         break;
4864      case 0x0301:
4865         prg8_ab(space->machine(), data);
4866         break;
4867      case 0x0302:
4868         prg8_cd(space->machine(), data);
4869         break;
4870      case 0x0312:
4871      case 0x0313:
4872      case 0x0314:
4873      case 0x0315:
4874         state->m_mmc_latch2 = 1;
4875      case 0x0310:
4876      case 0x0311:
4877      case 0x0316:
4878      case 0x0317:
4879         state->m_mapper83_reg[offset - 0x0310] = data;
4880         cony_set_chr(space->machine());
4881         break;
4882      case 0x0318:
4883         state->m_mapper83_reg[9] = data;
4884         cony_set_prg(space->machine());
4885         break;
4886   }
4887}
4888
4889/*************************************************************
4890
4891 Board DREAMTECH01
4892
4893 Games: Korean Igo
4894
4895 In MESS: Supported
4896
4897 *************************************************************/
4898
4899static WRITE8_HANDLER( dreamtech_l_w )
4900{
4901   LOG_MMC(("dreamtech_l_w offset: %04x, data: %02x\n", offset, data));
4902   offset += 0x100;
4903
4904   if (offset == 0x1020)   /* 0x5020 */
4905      prg16_89ab(space->machine(), data);
4906}
4907
4908/*************************************************************
4909
4910 Bootleg Board by Fukutake
4911
4912 Games: Study Box
4913
4914 iNES: mapper 186
4915
4916 In MESS: Unsupported.
4917
4918
4919 *************************************************************/
4920
4921static WRITE8_HANDLER( fukutake_l_w )
4922{
4923   nes_state *state = space->machine().driver_data<nes_state>();
4924   LOG_MMC(("fukutake_l_w offset: %04x, data: %02x\n", offset, data));
4925   offset += 0x100;
4926
4927   if (offset >= 0x200 && offset < 0x400)
4928   {
4929      if (offset & 1)
4930         prg16_89ab(space->machine(), data);
4931      else
4932         wram_bank(space->machine(), data >> 6, NES_WRAM);
4933   }
4934   else if (offset >= 0x400 && offset < 0xf00)
4935      state->m_mapper_ram[offset - 0x400] = data;
4936}
4937
4938static READ8_HANDLER( fukutake_l_r )
4939{
4940   nes_state *state = space->machine().driver_data<nes_state>();
4941   LOG_MMC(("fukutake_l_r offset: %04x\n", offset));
4942   offset += 0x100;
4943
4944   if (offset >= 0x200 && offset < 0x400)
4945   {
4946      if (offset == 0x200 || offset == 0x201 || offset == 0x203)
4947         return 0x00;
4948      else if (offset == 0x202)
4949         return 0x40;
4950      else
4951         return 0xff;
4952   }
4953   else if (offset >= 0x400 && offset < 0xf00)
4954      return state->m_mapper_ram[offset - 0x400];
4955
4956   return 0;
4957}
4958
4959/*************************************************************
4960
4961 Bootleg Board by Future Media
4962
4963 Games: Crayon Shin-chan (C), San Guo Zhi 4 - Chi Bi Feng Yun
4964
4965 iNES: mapper 117
4966
4967 In MESS: Unsupported.
4968
4969 *************************************************************/
4970
4971static void futuremedia_irq( device_t *device, int scanline, int vblank, int blanked )
4972{
4973   nes_state *state = device->machine().driver_data<nes_state>();
4974   //  if (scanline < PPU_BOTTOM_VISIBLE_SCANLINE)
4975   {
4976      if (state->m_IRQ_enable && state->m_IRQ_count)
4977      {
4978         state->m_IRQ_count--;
4979         if (!state->m_IRQ_count)
4980            device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
4981      }
4982   }
4983}
4984
4985static WRITE8_HANDLER( futuremedia_w )
4986{
4987   nes_state *state = space->machine().driver_data<nes_state>();
4988   LOG_MMC(("futuremedia_w, offset: %04x, data: %02x\n", offset, data));
4989
4990   switch (offset)
4991   {
4992      case 0x0000:
4993         prg8_89(space->machine(), data);
4994         break;
4995      case 0x0001:
4996         prg8_ab(space->machine(), data);
4997         break;
4998      case 0x0002:
4999         prg8_cd(space->machine(), data);
5000         break;
5001      case 0x0003:
5002         prg8_ef(space->machine(), data);
5003         break;
5004      case 0x2000:
5005      case 0x2001:
5006      case 0x2002:
5007      case 0x2003:
5008      case 0x2004:
5009      case 0x2005:
5010      case 0x2006:
5011      case 0x2007:
5012         chr1_x(space->machine(), offset & 0x07, data, CHRROM);
5013         break;
5014
5015      case 0x5000:
5016         set_nt_mirroring(space->machine(), BIT(data, 0) ?  PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5017         break;
5018
5019      case 0x4001:
5020         state->m_IRQ_count_latch = data;
5021         break;
5022      case 0x4002:
5023         // IRQ cleared
5024         break;
5025      case 0x4003:
5026         state->m_IRQ_count = state->m_IRQ_count_latch;
5027         break;
5028      case 0x6000:
5029         state->m_IRQ_enable = data & 0x01;
5030         break;
5031   }
5032}
5033
5034/*************************************************************
5035
5036 Bootleg Board 37017 (?) by Gouder
5037
5038 Games: Street Fighter IV
5039
5040 MMC3 clone. It also requires reads from 0x5000-0x7fff.
5041
5042 iNES: mapper 208
5043
5044 In MESS: Preliminary Support.
5045
5046 *************************************************************/
5047
5048static WRITE8_HANDLER( gouder_sf4_l_w )
5049{
5050   nes_state *state = space->machine().driver_data<nes_state>();
5051   static const UINT8 conv_table[256] =
5052   {
5053      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x49,0x19,0x09,0x59,0x49,0x19,0x09,
5054      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x51,0x41,0x11,0x01,0x51,0x41,0x11,0x01,
5055      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x49,0x19,0x09,0x59,0x49,0x19,0x09,
5056      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x51,0x41,0x11,0x01,0x51,0x41,0x11,0x01,
5057      0x00,0x10,0x40,0x50,0x00,0x10,0x40,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
5058      0x08,0x18,0x48,0x58,0x08,0x18,0x48,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
5059      0x00,0x10,0x40,0x50,0x00,0x10,0x40,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
5060      0x08,0x18,0x48,0x58,0x08,0x18,0x48,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
5061      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x58,0x48,0x18,0x08,0x58,0x48,0x18,0x08,
5062      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x50,0x40,0x10,0x00,0x50,0x40,0x10,0x00,
5063      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x58,0x48,0x18,0x08,0x58,0x48,0x18,0x08,
5064      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x50,0x40,0x10,0x00,0x50,0x40,0x10,0x00,
5065      0x01,0x11,0x41,0x51,0x01,0x11,0x41,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
5066      0x09,0x19,0x49,0x59,0x09,0x19,0x49,0x59,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
5067      0x01,0x11,0x41,0x51,0x01,0x11,0x41,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
5068      0x09,0x19,0x49,0x59,0x09,0x19,0x49,0x59,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
5069   };
5070
5071   LOG_MMC(("gouder_sf4_l_w, offset: %04x, data: %02x\n", offset, data));
5072
5073   if (!(offset < 0x1700))
5074      state->m_mmc_reg[offset & 0x03] = data ^ conv_table[state->m_mmc_reg[4]];
5075   else if (!(offset < 0xf00))
5076      state->m_mmc_reg[4] = data;
5077   else if (!(offset < 0x700))
5078      prg32(space->machine(), ((data >> 3) & 0x02) | (data & 0x01));
5079}
5080
5081static READ8_HANDLER( gouder_sf4_l_r )
5082{
5083   nes_state *state = space->machine().driver_data<nes_state>();
5084   LOG_MMC(("gouder_sf4_l_r, offset: %04x\n", offset));
5085
5086   if (!(offset < 0x1700))
5087      return state->m_mmc_reg[offset & 0x03];
5088
5089   return 0x00;
5090}
5091
5092/* writes to 0x8000-0xffff are like MMC3 but no PRG bankswitch (beacuse it is handled by low writes) */
5093static void gouder_sf4_prg_cb( running_machine &machine, int start, int bank )
5094{
5095   return;
5096}
5097
5098
5099/*************************************************************
5100
5101 Bootleg Board by Henggedianzi
5102
5103 Games: Mei Guo Fu Hao, Shang Gu Shen Jian , Wang Zi Fu
5104 Chou Ji
5105
5106 Writes to 0x8000-0xffff set prg32. Moreover, data&0x20 sets
5107 NT mirroring.
5108
5109 iNES: mapper 177
5110
5111 In MESS: Supported.
5112
5113 *************************************************************/
5114
5115static WRITE8_HANDLER( henggedianzi_w )
5116{
5117   LOG_MMC(("henggedianzi_w, offset: %04x, data: %02x\n", offset, data));
5118
5119   prg32(space->machine(), data);
5120   set_nt_mirroring(space->machine(), BIT(data, 5) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5121}
5122
5123/*************************************************************
5124
5125 Bootleg Board by Henggedianzi
5126
5127 Games: Xing He Zhan Shi
5128
5129 Writes to 0x5000-0x5fff set prg32 banks, writes to 0x8000-
5130 0xffff set NT mirroring
5131
5132 iNES: mapper 179
5133
5134 In MESS: Supported.
5135
5136 *************************************************************/
5137
5138static WRITE8_HANDLER( heng_xjzb_l_w )
5139{
5140   LOG_MMC(("heng_xjzb_l_w, offset: %04x, data: %02x\n", offset, data));
5141   offset += 0x4100;
5142
5143   if (offset & 0x5000)
5144      prg32(space->machine(), data >> 1);
5145}
5146
5147static WRITE8_HANDLER( heng_xjzb_w )
5148{
5149   LOG_MMC(("heng_xjzb_w, offset: %04x, data: %02x\n", offset, data));
5150
5151   set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5152}
5153
5154/*************************************************************
5155
5156 Bootleg Board by HES (also used by others)
5157
5158 Games: AV Hanafuda Club, AV Soccer, Papillon, Sidewinder,
5159 Total Funpack
5160
5161 Actually, two variant: one for HES 6-in-1 with mirroring control
5162 and one for AV Soccer and others with hardwired mirroring
5163
5164 iNES: mapper 113
5165
5166 In MESS: Supported.
5167
5168 *************************************************************/
5169
5170static WRITE8_HANDLER( hes6in1_l_w )
5171{
5172   LOG_MMC(("hes6in1_l_w, offset: %04x, data: %02x\n", offset, data));
5173
5174   if (!(offset & 0x100))
5175   {
5176      prg32(space->machine(), (data & 0x38) >> 3);
5177      chr8(space->machine(), (data & 0x07) | ((data & 0x40) >> 3), CHRROM);
5178      set_nt_mirroring(space->machine(), BIT(data, 7) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
5179   }
5180}
5181
5182static WRITE8_HANDLER( hes_l_w )
5183{
5184   LOG_MMC(("hes_l_w, offset: %04x, data: %02x\n", offset, data));
5185
5186   if (!(offset & 0x100))
5187   {
5188      prg32(space->machine(), (data & 0x38) >> 3);
5189      chr8(space->machine(), (data & 0x07) | ((data & 0x40) >> 3), CHRROM);
5190   }
5191}
5192
5193/*************************************************************
5194
5195 Bootleg Board by Hosenkan
5196
5197 Games: Pocahontas, Super Donkey Kong
5198
5199 iNES: mapper 182
5200
5201 In MESS: Supported.
5202
5203 *************************************************************/
5204
5205static WRITE8_HANDLER( hosenkan_w )
5206{
5207   nes_state *state = space->machine().driver_data<nes_state>();
5208   LOG_MMC(("hosenkan_w, offset: %04x, data: %02x\n", offset, data));
5209
5210   switch (offset & 0x7003)
5211   {
5212      case 0x0001:
5213         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5214         break;
5215      case 0x2000:
5216         state->m_mmc_latch1 = data;
5217         break;
5218      case 0x4000:
5219         switch (state->m_mmc_latch1)
5220      {
5221         case 0:
5222            chr2_0(space->machine(), data >> 1, CHRROM);
5223            break;
5224         case 1:
5225            chr1_5(space->machine(), data, CHRROM);
5226            break;
5227         case 2:
5228            chr2_2(space->machine(), data >> 1, CHRROM);
5229            break;
5230         case 3:
5231            chr1_7(space->machine(), data, CHRROM);
5232            break;
5233         case 4:
5234            prg8_89(space->machine(), data);
5235            break;
5236         case 5:
5237            prg8_ab(space->machine(), data);
5238            break;
5239         case 6:
5240            chr1_4(space->machine(), data, CHRROM);
5241            break;
5242         case 7:
5243            chr1_6(space->machine(), data, CHRROM);
5244            break;
5245      }
5246         break;
5247      case 0x6003:
5248         if (data)
5249         {
5250            state->m_IRQ_count = data;
5251            state->m_IRQ_enable = 1;
5252         }
5253         else
5254            state->m_IRQ_enable = 0;
5255         break;
5256   }
5257}
5258
5259/*************************************************************
5260
5261 Kaiser Board KS7058
5262
5263 Games: Tui Do Woo Ma Jeung
5264
5265 Writes to 0xf000-0xffff set 4k chr banks. Namely, if
5266 offset&0x80 is 0 the lower 4k are set, if it is 1 the
5267 upper 4k are set.
5268
5269 iNES: mapper 171
5270
5271 In MESS: Supported.
5272
5273 *************************************************************/
5274
5275static WRITE8_HANDLER( ks7058_w )
5276{
5277   LOG_MMC(("ks7058_w, offset: %04x, data: %02x\n", offset, data));
5278
5279   switch (offset & 0x7080)
5280   {
5281      case 0x7000:
5282         chr4_0(space->machine(), data, CHRROM);
5283         break;
5284      case 0x7080:
5285         chr4_4(space->machine(), data, CHRROM);
5286         break;
5287   }
5288}
5289
5290/*************************************************************
5291
5292 Kaiser Board KS7022
5293
5294 Games: 15 in 1
5295
5296 iNES: mapper 175
5297
5298 In MESS: Supported?
5299
5300 *************************************************************/
5301
5302static WRITE8_HANDLER( ks7022_w )
5303{
5304   nes_state *state = space->machine().driver_data<nes_state>();
5305   LOG_MMC(("ks7022_w, offset: %04x, data: %02x\n", offset, data));
5306
5307   if (offset == 0)
5308      set_nt_mirroring(space->machine(), BIT(data, 2) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5309
5310   if (offset == 0x2000)
5311      state->m_mmc_latch1 = data & 0x0f;
5312}
5313
5314static READ8_HANDLER( ks7022_r )
5315{
5316   nes_state *state = space->machine().driver_data<nes_state>();
5317   LOG_MMC(("ks7022_r, offset: %04x\n", offset));
5318
5319   if (offset == 0x7ffc)
5320   {
5321      chr8(space->machine(), state->m_mmc_latch1, CHRROM);
5322      prg16_89ab(space->machine(), state->m_mmc_latch1);
5323      prg16_cdef(space->machine(), state->m_mmc_latch1);
5324   }
5325
5326   return mmc_hi_access_rom(space->machine(), offset);
5327}
5328
5329/*************************************************************
5330
5331 Kaiser Board KS7032
5332
5333 Games:
5334
5335 iNES:
5336
5337 In MESS:
5338
5339 *************************************************************/
5340
5341static void ks7032_prg_update( running_machine &machine )
5342{
5343   nes_state *state = machine.driver_data<nes_state>();
5344
5345   prg8_67(machine, state->m_mmc_reg[4]);
5346   prg8_89(machine, state->m_mmc_reg[1]);
5347   prg8_ab(machine, state->m_mmc_reg[2]);
5348   prg8_cd(machine, state->m_mmc_reg[3]);
5349}
5350
5351static void ks7032_irq( device_t *device, int scanline, int vblank, int blanked )
5352{
5353   nes_state *state = device->machine().driver_data<nes_state>();
5354
5355   if (state->m_IRQ_enable)
5356   {
5357      if (state->m_IRQ_count >= (0xffff - 114))
5358      {
5359         state->m_IRQ_enable = 0;
5360         state->m_IRQ_count = state->m_IRQ_count_latch;
5361         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
5362      }
5363      else
5364         state->m_IRQ_count += 114;
5365   }
5366}
5367
5368static WRITE8_HANDLER( ks7032_w )
5369{
5370   nes_state *state = space->machine().driver_data<nes_state>();
5371   LOG_MMC(("ks7032_w, offset: %04x, data: %02x\n", offset, data));
5372
5373   switch (offset & 0x7000)
5374   {
5375      case 0x0000:
5376         state->m_IRQ_count = (state->m_IRQ_count & 0xfff0) | (data & 0x0f);
5377         break;
5378      case 0x1000:
5379         state->m_IRQ_count = (state->m_IRQ_count & 0xff0f) | ((data & 0x0f) << 4);
5380         break;
5381      case 0x2000:
5382         state->m_IRQ_count = (state->m_IRQ_count & 0xf0ff) | ((data & 0x0f) << 8);
5383         break;
5384      case 0x3000:
5385         state->m_IRQ_count = (state->m_IRQ_count & 0x0fff) | ((data & 0x0f) << 12);
5386         break;
5387      case 0x4000:
5388         state->m_IRQ_enable = 1;
5389         break;
5390      case 0x6000:
5391         state->m_mmc_latch1 = data & 0x07;
5392         break;
5393      case 0x7000:
5394         state->m_mmc_reg[state->m_mmc_latch1] = data;
5395         ks7032_prg_update(space->machine());
5396         break;
5397   }
5398}
5399
5400/*************************************************************
5401
5402 Kaiser Board KS202
5403
5404 Games:
5405
5406 iNES:
5407
5408 In MESS: Supported?
5409
5410 *************************************************************/
5411
5412
5413static WRITE8_HANDLER( ks202_w )
5414{
5415   nes_state *state = space->machine().driver_data<nes_state>();
5416   LOG_MMC(("ks202_w, offset: %04x, data: %02x\n", offset, data));
5417
5418   switch (offset & 0x7000)
5419   {
5420      case 0x0000:
5421         state->m_IRQ_count = (state->m_IRQ_count & 0xfff0) | (data & 0x0f);
5422         break;
5423      case 0x1000:
5424         state->m_IRQ_count = (state->m_IRQ_count & 0xff0f) | ((data & 0x0f) << 4);
5425         break;
5426      case 0x2000:
5427         state->m_IRQ_count = (state->m_IRQ_count & 0xf0ff) | ((data & 0x0f) << 8);
5428         break;
5429      case 0x3000:
5430         state->m_IRQ_count = (state->m_IRQ_count & 0x0fff) | ((data & 0x0f) << 12);
5431         break;
5432      case 0x4000:
5433         state->m_IRQ_enable = 1;
5434         break;
5435      case 0x6000:
5436         state->m_mmc_latch1 = data & 0x07;
5437         break;
5438      case 0x7000:
5439         state->m_mmc_reg[state->m_mmc_latch1] = data;
5440         ks7032_prg_update(space->machine());
5441         switch (offset & 0xc00)
5442         {
5443         case 0x800:
5444            set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
5445            break;
5446         case 0xc00:
5447            chr1_x(space->machine(), offset & 0x07, data, CHRROM);
5448            break;
5449         }
5450         break;
5451   }
5452}
5453
5454/*************************************************************
5455
5456 Kaiser Board KS7017
5457
5458 Games:
5459
5460 iNES:
5461
5462 In MESS: Not working
5463
5464 *************************************************************/
5465
5466static void mmc_fds_irq( device_t *device, int scanline, int vblank, int blanked )
5467{
5468   nes_state *state = device->machine().driver_data<nes_state>();
5469
5470   if (state->m_IRQ_enable)
5471   {
5472      if (state->m_IRQ_count <= 114)
5473      {
5474         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
5475         state->m_IRQ_enable = 0;
5476         state->m_IRQ_status |= 0x01;
5477      }
5478      else
5479         state->m_IRQ_count -= 114;
5480   }
5481}
5482
5483static WRITE8_HANDLER( ks7017_l_w )
5484{
5485   nes_state *state = space->machine().driver_data<nes_state>();
5486   LOG_MMC(("ks7022_w, offset: %04x, data: %02x\n", offset, data));
5487
5488   offset += 0x100;
5489
5490   if (offset >= 0xa00 && offset < 0xb00)
5491      state->m_mmc_latch1 = ((offset >> 2) & 0x03) | ((offset >> 4) & 0x04);
5492
5493   if (offset >= 0x1000 && offset < 0x1100)
5494      prg16_89ab(space->machine(), state->m_mmc_latch1);
5495}
5496
5497WRITE8_HANDLER( ks7017_extra_w )
5498{
5499   nes_state *state = space->machine().driver_data<nes_state>();
5500   LOG_MMC(("ks7017_extra_w, offset: %04x, data: %02x\n", offset, data));
5501
5502   offset += 0x20;
5503
5504   if (offset == 0x0020) /* 0x4020 */
5505      state->m_IRQ_count = (state->m_IRQ_count & 0xff00) | data;
5506
5507   if (offset == 0x0021) /* 0x4021 */
5508      state->m_IRQ_count = (state->m_IRQ_count & 0x00ff) | (data << 8);
5509
5510   if (offset == 0x0025) /* 0x4025 */
5511      set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5512}
5513
5514READ8_HANDLER( ks7017_extra_r )
5515{
5516   nes_state *state = space->machine().driver_data<nes_state>();
5517   LOG_MMC(("ks7017_extra_r, offset: %04x\n", offset));
5518
5519   state->m_IRQ_status &= ~0x01;
5520   return state->m_IRQ_status;
5521}
5522
5523/*************************************************************
5524
5525 Bootleg Board by Kay (for Panda Prince)
5526
5527 Games: The Panda Prince, Sonic 3d Blast 6, SFZ2 '97, YuYu '97
5528 (and its title hack MK6), UMK3, Super Lion King 2
5529
5530 MMC3 clone. This is basically KOF96 board + protection
5531
5532 iNES: mapper 121
5533
5534 In MESS: Most game works, with some graphical issues.
5535
5536 *************************************************************/
5537
5538static WRITE8_HANDLER( kay_pp_l_w )
5539{
5540   nes_state *state = space->machine().driver_data<nes_state>();
5541   LOG_MMC(("kay_pp_l_w, offset: %04x, data: %02x\n", offset, data));
5542   offset += 0x100;
5543
5544   if (offset >= 0x1000)
5545   {
5546      switch (data & 0x03)
5547      {
5548         case 0x00:
5549         case 0x01:
5550            state->m_mmc_reg[0] = 0x83;
5551            break;
5552         case 0x02:
5553            state->m_mmc_reg[0] = 0x42;
5554            break;
5555         case 0x03:
5556            state->m_mmc_reg[0] = 0x00;
5557            break;
5558      }
5559   }
5560}
5561
5562static READ8_HANDLER( kay_pp_l_r )
5563{
5564   nes_state *state = space->machine().driver_data<nes_state>();
5565   LOG_MMC(("kay_pp_l_r, offset: %04x\n", offset));
5566   offset += 0x100;
5567
5568   if (offset >= 0x1000)
5569      return state->m_mmc_reg[0];
5570   else
5571      return 0xff;
5572}
5573
5574static void kay_pp_update_regs( running_machine &machine )
5575{
5576   nes_state *state = machine.driver_data<nes_state>();
5577
5578   switch (state->m_mmc_reg[5] & 0x3f)
5579   {
5580      case 0x20:
5581      case 0x29:
5582      case 0x2b:
5583      case 0x3f:
5584         state->m_mmc_reg[7] = 1;
5585         state->m_mmc_reg[1] = state->m_mmc_reg[6];
5586         break;
5587      case 0x26:
5588         state->m_mmc_reg[7] = 0;
5589         state->m_mmc_reg[1] = state->m_mmc_reg[6];
5590         break;
5591      case 0x2c:
5592         state->m_mmc_reg[7] = 1;
5593         if (state->m_mmc_reg[6])
5594            state->m_mmc_reg[1] = state->m_mmc_reg[6];
5595         break;
5596
5597      case 0x28:
5598         state->m_mmc_reg[7] = 0;
5599         state->m_mmc_reg[2] = state->m_mmc_reg[6];
5600         break;
5601
5602      case 0x2a:
5603         state->m_mmc_reg[7] = 0;
5604         state->m_mmc_reg[3] = state->m_mmc_reg[6];
5605         break;
5606
5607      case 0x2f:
5608         break;
5609
5610      default:
5611         state->m_mmc_reg[5] = 0;
5612         break;
5613   }
5614}
5615
5616static void kay_pp_prg_cb( running_machine &machine, int start, int bank )
5617{
5618   nes_state *state = machine.driver_data<nes_state>();
5619
5620   if (state->m_mmc_reg[5] & 0x3f)
5621   {
5622      prg8_x(machine, start, bank & 0x3f);
5623      prg8_ef(machine, state->m_mmc_reg[1]);
5624      prg8_cd(machine, state->m_mmc_reg[2]);
5625      prg8_ab(machine, state->m_mmc_reg[3]);
5626   }
5627   else
5628      prg8_x(machine, start, bank & 0x3f);
5629}
5630
5631static void kay_pp_chr_cb( running_machine &machine, int start, int bank, int source )
5632{
5633   nes_state *state = machine.driver_data<nes_state>();
5634   UINT8 chr_page = (state->m_mmc3_latch & 0x80) >> 5;
5635
5636   if ((start & 0x04) == chr_page)
5637      bank |= 0x100;
5638
5639   chr1_x(machine, start, bank, source);
5640}
5641
5642static WRITE8_HANDLER( kay_pp_w )
5643{
5644   nes_state *state = space->machine().driver_data<nes_state>();
5645   LOG_MMC(("kay_pp_w, offset: %04x, data: %02x\n", offset, data));
5646
5647   switch (offset & 0x6003)
5648   {
5649      case 0x0000:
5650         txrom_w(space, offset, data);
5651         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
5652         break;
5653
5654      case 0x0001:
5655         state->m_mmc_reg[6] = (BIT(data, 0) << 5) | (BIT(data, 1) << 4) | (BIT(data, 2) << 3)
5656                        | (BIT(data, 3) << 2) | (BIT(data, 4) << 1) | BIT(data, 5);
5657         if (!state->m_mmc_reg[7])
5658            kay_pp_update_regs(space->machine());
5659         txrom_w(space, offset, data);
5660         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
5661         break;
5662
5663      case 0x0003:
5664         state->m_mmc_reg[5] = data;
5665         kay_pp_update_regs(space->machine());
5666         txrom_w(space, 0x0000, data);
5667         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
5668         break;
5669
5670      default:
5671         txrom_w(space, offset, data);
5672         break;
5673   }
5674}
5675
5676/*************************************************************
5677
5678 Bootleg Board by Kasing
5679
5680 Games: AV Jiu Ji Mahjong, Bao Qing Tian, Thunderbolt 2,
5681 Shisen Mahjong 2
5682
5683 MMC3 clone
5684
5685 iNES: mapper 115
5686
5687 In MESS: Supported
5688
5689 *************************************************************/
5690
5691static void kasing_prg_cb( running_machine &machine, int start, int bank )
5692{
5693   nes_state *state = machine.driver_data<nes_state>();
5694   if (BIT(state->m_mmc_reg[0], 7))
5695      prg32(machine, state->m_mmc_reg[0] >> 1);
5696   else
5697      prg8_x(machine, start, bank);
5698}
5699
5700static WRITE8_HANDLER( kasing_m_w )
5701{
5702   nes_state *state = space->machine().driver_data<nes_state>();
5703   LOG_MMC(("kasing_m_w, offset: %04x, data: %02x\n", offset, data));
5704
5705   switch (offset & 0x01)
5706   {
5707      case 0x00:
5708         state->m_mmc_reg[0] = data;
5709         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
5710         break;
5711      case 0x01:
5712         state->m_mmc_chr_base = (data & 0x01) ? 0x100 : 0x000;
5713         mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
5714         break;
5715   }
5716}
5717
5718/*************************************************************
5719
5720 Bootleg Board by Magic Series
5721
5722 Games: Magic Dragon
5723
5724 Very simple mapper: writes to 0x8000-0xffff set prg32 and chr8
5725 banks
5726
5727 iNES: mapper 107
5728
5729 In MESS: Supported.
5730
5731 *************************************************************/
5732
5733static WRITE8_HANDLER( magics_md_w )
5734{
5735   LOG_MMC(("magics_md_w, offset: %04x, data: %02x\n", offset, data));
5736
5737   prg32(space->machine(), data >> 1);
5738   chr8(space->machine(), data, CHRROM);
5739}
5740
5741/*************************************************************
5742
5743 Bootleg Board by Nanjing
5744
5745 Games: A lot of pirate originals
5746
5747 iNES: mapper 163
5748
5749 In MESS: Unsupported.
5750
5751 *************************************************************/
5752
5753static void nanjing_irq( device_t *device, int scanline, int vblank, int blanked )
5754{
5755   nes_state *state = device->machine().driver_data<nes_state>();
5756
5757   if (BIT(state->m_mmc_reg[0], 7))
5758   {
5759      if (scanline == 127)
5760      {
5761         chr4_0(device->machine(), 1, CHRRAM);
5762         chr4_4(device->machine(), 1, CHRRAM);
5763      }
5764
5765      if (scanline == 239)
5766      {
5767         chr4_0(device->machine(), 0, CHRRAM);
5768         chr4_4(device->machine(), 0, CHRRAM);
5769      }
5770   }
5771
5772}
5773
5774static WRITE8_HANDLER( nanjing_l_w )
5775{
5776   nes_state *state = space->machine().driver_data<nes_state>();
5777   LOG_MMC(("nanjing_l_w, offset: %04x, data: %02x\n", offset, data));
5778
5779   offset += 0x100;
5780
5781   if (offset < 0x1000)
5782      return;
5783
5784   if (offset == 0x1100)   // 0x5100
5785   {
5786      if (data == 6)
5787         prg32(space->machine(), 3);
5788      return;
5789   }
5790
5791   if (offset == 0x1101)   // 0x5101
5792   {
5793      UINT8 temp = state->m_mmc_count;
5794      state->m_mmc_count = data;
5795
5796      if (temp & !data)
5797         state->m_mmc_latch2 ^= 0xff;
5798   }
5799
5800   switch (offset & 0x300)
5801   {
5802      case 0x000:
5803      case 0x200:
5804         state->m_mmc_reg[BIT(offset, 9)] = data;
5805         if (!BIT(state->m_mmc_reg[0], 7) && ppu2c0x_get_current_scanline(state->m_ppu) <= 127)
5806            chr8(space->machine(), 0, CHRRAM);
5807         break;
5808      case 0x300:
5809         state->m_mmc_latch1 = data;
5810         break;
5811   }
5812
5813   prg32(space->machine(), (state->m_mmc_reg[0] & 0x0f) | ((state->m_mmc_reg[1] & 0x0f) << 4));
5814}
5815
5816static READ8_HANDLER( nanjing_l_r )
5817{
5818   nes_state *state = space->machine().driver_data<nes_state>();
5819   UINT8 value = 0;
5820   LOG_MMC(("nanjing_l_r, offset: %04x\n", offset));
5821
5822   offset += 0x100;
5823
5824   if (offset < 0x1000)
5825      return 0;
5826
5827   switch (offset & 0x700)
5828   {
5829      case 0x100:
5830         value = state->m_mmc_latch1;
5831         break;
5832      case 0x500:
5833         value = state->m_mmc_latch2 & state->m_mmc_latch1;
5834         break;
5835      case 0x000:
5836      case 0x200:
5837      case 0x300:
5838      case 0x400:
5839      case 0x600:
5840      case 0x700:
5841         value = 4;
5842         break;
5843   }
5844   return value;
5845}
5846
5847/*************************************************************
5848
5849 Bootleg Board by Nitra
5850
5851 Games: Time Diver Avenger
5852
5853 This acts basically like a MMC3 with different use of write
5854 address.
5855
5856 iNES: mapper 250
5857
5858 In MESS: Supported.
5859
5860 *************************************************************/
5861
5862static WRITE8_HANDLER( nitra_w )
5863{
5864   LOG_MMC(("nitra_w, offset: %04x, data: %02x\n", offset, data));
5865
5866   txrom_w(space, (offset & 0x6000) | ((offset & 0x400) >> 10), offset & 0xff);
5867}
5868
5869/*************************************************************
5870
5871 NTDEC ASDER Bootleg Board
5872
5873 Games: Cobra Mission, Fighting Hero III, Huang Di, Master
5874 Shooter
5875
5876 iNES: mapper 112
5877
5878 In MESS: Supported.
5879
5880 *************************************************************/
5881
5882static WRITE8_HANDLER( ntdec_asder_w )
5883{
5884   nes_state *state = space->machine().driver_data<nes_state>();
5885   LOG_MMC(("ntdec_asder_w, offset: %04x, data: %02x\n", offset, data));
5886
5887   switch (offset)
5888   {
5889      case 0x0000:
5890         state->m_mmc_latch1 = data & 0x07;
5891         break;
5892      case 0x2000:
5893         switch (state->m_mmc_latch1)
5894      {
5895         case 0:
5896            prg8_89(space->machine(), data);
5897            break;
5898         case 1:
5899            prg8_ab(space->machine(), data);
5900            break;
5901         case 2:
5902            data &= 0xfe;
5903            chr1_0(space->machine(), data, CHRROM);
5904            chr1_1(space->machine(), data + 1, CHRROM);
5905            break;
5906         case 3:
5907            data &= 0xfe;
5908            chr1_2(space->machine(), data, CHRROM);
5909            chr1_3(space->machine(), data + 1, CHRROM);
5910            break;
5911         case 4:
5912            chr1_4(space->machine(), data, CHRROM);
5913            break;
5914         case 5:
5915            chr1_5(space->machine(), data, CHRROM);
5916            break;
5917         case 6:
5918            chr1_6(space->machine(), data, CHRROM);
5919            break;
5920         case 7:
5921            chr1_7(space->machine(), data, CHRROM);
5922            break;
5923      }
5924         break;
5925      case 0x6000:
5926         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5927         break;
5928   }
5929}
5930
5931/*************************************************************
5932
5933 Bootleg Board by NTDEC for Fighting Hero
5934
5935 Games: Fighting Hero
5936
5937 Very simple mapper: writes to 0x6000-0x7fff swap PRG and
5938 CHR banks.
5939
5940 iNES: mapper 193
5941
5942 In MESS: Supported.
5943
5944 *************************************************************/
5945
5946static WRITE8_HANDLER( ntdec_fh_m_w )
5947{
5948   LOG_MMC(("ntdec_fh_m_w, offset: %04x, data: %02x\n", offset, data));
5949
5950   switch (offset & 0x03)
5951   {
5952      case 0:
5953         chr4_0(space->machine(), data >> 2, CHRROM);
5954         break;
5955      case 1:
5956         chr2_4(space->machine(), data >> 1, CHRROM);
5957         break;
5958      case 2:
5959         chr2_6(space->machine(), data >> 1 , CHRROM);
5960         break;
5961      case 3:
5962         prg8_89(space->machine(), data);
5963         break;
5964   }
5965}
5966
5967/*************************************************************
5968
5969 Open Corp DAOU306 board
5970
5971 Games: Metal Force (K)
5972
5973 iNES: mapper 156
5974
5975 In MESS: Supported.
5976
5977 *************************************************************/
5978
5979static WRITE8_HANDLER( daou306_w )
5980{
5981   LOG_MMC(("daou306_w, offset: %04x, data: %02x\n", offset, data));
5982
5983   switch (offset)
5984   {
5985      case 0x4000:
5986         chr1_0(space->machine(), data, CHRROM);
5987         break;
5988      case 0x4001:
5989         chr1_1(space->machine(), data, CHRROM);
5990         break;
5991      case 0x4002:
5992         chr1_2(space->machine(), data, CHRROM);
5993         break;
5994      case 0x4003:
5995         chr1_3(space->machine(), data, CHRROM);
5996         break;
5997      case 0x4008:
5998         chr1_4(space->machine(), data, CHRROM);
5999         break;
6000      case 0x4009:
6001         chr1_5(space->machine(), data, CHRROM);
6002         break;
6003      case 0x400a:
6004         chr1_6(space->machine(), data, CHRROM);
6005         break;
6006      case 0x400b:
6007         chr1_7(space->machine(), data, CHRROM);
6008         break;
6009      case 0x4010:
6010         prg16_89ab(space->machine(), data);
6011         break;
6012   }
6013}
6014
6015/*************************************************************
6016
6017 RCM GS2015 Board
6018
6019 Games: Bonza, Magic Jewelry 2
6020
6021 Very simple mapper: writes to 0x8000-0xffff sets prg32
6022 to offset and chr8 to offset>>1 (when chrrom is present)
6023
6024 iNES: mapper 216
6025
6026 In MESS: Supported.
6027
6028 *************************************************************/
6029
6030static WRITE8_HANDLER( gs2015_w )
6031{
6032   nes_state *state = space->machine().driver_data<nes_state>();
6033   LOG_MMC(("gs2015_w, offset: %04x, data: %02x\n", offset, data));
6034
6035   prg32(space->machine(), offset);
6036   chr8(space->machine(), offset >> 1, state->m_mmc_chr_source);
6037}
6038
6039/*************************************************************
6040
6041 Bootleg Board by RCM for Tetris Family
6042
6043 Games: Tetris Family 9 in 1, 20 in 1
6044
6045 Simple Mapper: prg/chr/nt are swapped depending on the offset
6046 of writes in 0x8000-0xffff. offset&0x80 set NT mirroring,
6047 when (offset&0x30) is 0,3 prg32 is set; when it is 1,2
6048 two 16k prg banks are set. See below for the values used in
6049 these banks.
6050
6051 iNES: mapper 61
6052
6053 In MESS: Supported.
6054
6055 *************************************************************/
6056
6057static WRITE8_HANDLER( rcm_tf_w )
6058{
6059   LOG_MMC(("rcm_tf_w, offset: %04x, data: %02x\n", offset, data));
6060
6061   switch (offset & 0x30)
6062   {
6063      case 0x00:
6064      case 0x30:
6065         prg32(space->machine(), offset & 0x0f);
6066         break;
6067      case 0x10:
6068      case 0x20:
6069         prg16_89ab(space->machine(), ((offset & 0x0f) << 1) | ((offset & 0x20) >> 4));
6070         prg16_cdef(space->machine(), ((offset & 0x0f) << 1) | ((offset & 0x20) >> 4));
6071         break;
6072   }
6073   set_nt_mirroring(space->machine(), BIT(data, 7) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
6074}
6075
6076/*************************************************************
6077
6078 Bootleg Board by Rex Soft
6079
6080 Games: Dragon Ball Z 5, Dragon Ball Z Super
6081
6082 MMC3 clone
6083
6084 iNES: mapper 12
6085
6086 In MESS: Supported
6087
6088 *************************************************************/
6089
6090static WRITE8_HANDLER( rex_dbz_l_w )
6091{
6092   nes_state *state = space->machine().driver_data<nes_state>();
6093   LOG_MMC(("rex_dbz_l_w, offset: %04x, data: %02x\n", offset, data));
6094
6095   state->m_mmc_reg[0] = data;
6096   mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6097}
6098
6099/* we would need to use this read handler in 0x6000-0x7fff as well */
6100static READ8_HANDLER( rex_dbz_l_r )
6101{
6102   LOG_MMC(("rex_dbz_l_r, offset: %04x\n", offset));
6103   return 0x01;
6104}
6105
6106static void rex_dbz_chr_cb( running_machine &machine, int start, int bank, int source )
6107{
6108   nes_state *state = machine.driver_data<nes_state>();
6109   int shift = (start < 4) ? 8 : 4;
6110
6111   bank |= ((state->m_mmc_reg[0] << shift) & 0x100);
6112   chr1_x(machine, start, bank, source);
6113}
6114
6115/*************************************************************
6116
6117 Rex Soft SL1632 Board
6118
6119 Games: Samurai Spirits
6120
6121 MMC3 clone
6122
6123 iNES: mapper 14
6124
6125 In MESS: Supported
6126
6127 *************************************************************/
6128
6129static void rex_sl1632_set_prg( running_machine &machine, int prg_base, int prg_mask )
6130{
6131   nes_state *state = machine.driver_data<nes_state>();
6132
6133   if (state->m_mmc_reg[0] & 0x02)
6134   {
6135      mmc3_set_prg(machine, prg_base, prg_mask);
6136   }
6137   else
6138   {
6139      prg8_89(machine, state->m_mmc_extra_bank[0]);
6140      prg8_ab(machine, state->m_mmc_extra_bank[1]);
6141      prg8_cd(machine, state->m_mmc_extra_bank[2]);
6142      prg8_ef(machine, state->m_mmc_extra_bank[3]);
6143   }
6144}
6145
6146static void rex_sl1632_set_chr( running_machine &machine, UINT8 chr, int chr_base, int chr_mask )
6147{
6148   nes_state *state = machine.driver_data<nes_state>();
6149   static const UINT8 conv_table[8] = {5, 5, 5, 5, 3, 3, 1, 1};
6150   UINT8 chr_page = (state->m_mmc3_latch & 0x80) >> 5;
6151   UINT8 bank[8];
6152   UINT8 chr_base2[8];
6153   int i;
6154
6155   if (state->m_mmc_reg[0] & 0x02)
6156   {
6157      for(i = 0; i < 8; i++)
6158      {
6159         bank[i] = state->m_mmc_vrom_bank[i];
6160         chr_base2[i] = chr_base | ((state->m_mmc_reg[0] << conv_table[i]) & 0x100);
6161      }
6162   }
6163   else
6164   {
6165      for(i = 0; i < 8; i++)
6166      {
6167         bank[i] = state->m_mmc_extra_bank[i + 4];   // first 4 state->m_mmc_extra_banks are PRG
6168         chr_base2[i] = chr_base;
6169      }
6170   }
6171
6172   chr1_x(machine, chr_page ^ 0, chr_base2[0] | (bank[0] & chr_mask), chr);
6173   chr1_x(machine, chr_page ^ 1, chr_base2[1] | (bank[1] & chr_mask), chr);
6174   chr1_x(machine, chr_page ^ 2, chr_base2[2] | (bank[2] & chr_mask), chr);
6175   chr1_x(machine, chr_page ^ 3, chr_base2[3] | (bank[3] & chr_mask), chr);
6176   chr1_x(machine, chr_page ^ 4, chr_base2[4] | (bank[4] & chr_mask), chr);
6177   chr1_x(machine, chr_page ^ 5, chr_base2[5] | (bank[5] & chr_mask), chr);
6178   chr1_x(machine, chr_page ^ 6, chr_base2[6] | (bank[6] & chr_mask), chr);
6179   chr1_x(machine, chr_page ^ 7, chr_base2[7] | (bank[7] & chr_mask), chr);
6180}
6181
6182static WRITE8_HANDLER( rex_sl1632_w )
6183{
6184   nes_state *state = space->machine().driver_data<nes_state>();
6185   UINT8 map14_helper1, map14_helper2, mmc_helper, cmd;
6186   LOG_MMC(("rex_sl1632_w, offset: %04x, data: %02x\n", offset, data));
6187
6188   if (offset == 0x2131)
6189   {
6190      state->m_mmc_reg[0] = data;
6191      rex_sl1632_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
6192      rex_sl1632_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6193
6194      if (!(state->m_mmc_reg[0] & 0x02))
6195         set_nt_mirroring(space->machine(), BIT(state->m_mmc_reg[1], 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
6196   }
6197
6198   if (state->m_mmc_reg[0] & 0x02)
6199   {
6200      switch (offset & 0x6001)
6201      {
6202         case 0x0000:
6203            mmc_helper = state->m_mmc3_latch ^ data;
6204            state->m_mmc3_latch = data;
6205
6206            /* Has PRG Mode changed? */
6207            if (mmc_helper & 0x40)
6208               rex_sl1632_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
6209
6210            /* Has CHR Mode changed? */
6211            if (mmc_helper & 0x80)
6212               rex_sl1632_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6213            break;
6214
6215         case 0x0001:
6216            cmd = state->m_mmc3_latch & 0x07;
6217            switch (cmd)
6218            {
6219            case 0: case 1:   // these have to be changed due to the different way rex_sl1632_set_chr works (it handles 1k banks)!
6220               state->m_mmc_vrom_bank[2 * cmd] = data;
6221               state->m_mmc_vrom_bank[2 * cmd + 1] = data;
6222               rex_sl1632_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6223               break;
6224            case 2: case 3: case 4: case 5:
6225               state->m_mmc_vrom_bank[cmd + 2] = data;
6226               rex_sl1632_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6227               break;
6228            case 6:
6229            case 7:
6230               state->m_mmc_prg_bank[cmd - 6] = data;
6231               rex_sl1632_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
6232               break;
6233            }
6234            break;
6235
6236         case 0x2000:
6237            set_nt_mirroring(space->machine(), BIT(state->m_mmc_reg[1], 0) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
6238            break;
6239
6240         default:
6241            txrom_w(space, offset, data);
6242            break;
6243      }
6244   }
6245   else if (offset >= 0x3000 && offset <= 0x6003 )
6246   {
6247      map14_helper1 = (offset & 0x01) << 2;
6248      offset = ((offset & 0x02) | (offset >> 10)) >> 1;
6249      map14_helper2 = ((offset + 2) & 0x07) + 4; // '+4' because first 4 state->m_mmc_extra_banks are for PRG!
6250      state->m_mmc_extra_bank[map14_helper2] = (state->m_mmc_extra_bank[map14_helper2] & (0xf0 >> map14_helper1)) | ((data & 0x0f) << map14_helper1);
6251      rex_sl1632_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6252   }
6253   else
6254   {
6255      switch (offset & 0x7003)
6256      {
6257         case 0x0000:
6258         case 0x2000:
6259            state->m_mmc_extra_bank[offset >> 13] = data;
6260            rex_sl1632_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
6261            break;
6262
6263         case 0x1000:
6264            state->m_mmc_reg[1] = data;
6265            set_nt_mirroring(space->machine(), BIT(state->m_mmc_reg[1], 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
6266            break;
6267      }
6268   }
6269}
6270
6271/*************************************************************
6272
6273 Rumblestation Board
6274
6275 Games: Rumblestation 15 in 1
6276
6277 iNES: mapper 46
6278
6279 In MESS: Supported.
6280
6281 *************************************************************/
6282
6283static WRITE8_HANDLER( rumblestation_m_w )
6284{
6285   nes_state *state = space->machine().driver_data<nes_state>();
6286   LOG_MMC(("rumblestation_m_w, offset: %04x, data: %02x\n", offset, data));
6287
6288   state->m_mmc_prg_bank[0] = (state->m_mmc_prg_bank[0] & 0x01) | ((data & 0x0f) << 1);
6289   state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & 0x07) | ((data & 0xf0) >> 1);
6290   prg32(space->machine(), state->m_mmc_prg_bank[0]);
6291   chr8(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
6292}
6293
6294static WRITE8_HANDLER( rumblestation_w )
6295{
6296   nes_state *state = space->machine().driver_data<nes_state>();
6297   LOG_MMC(("rumblestation_w, offset: %04x, data: %02x\n", offset, data));
6298
6299   state->m_mmc_prg_bank[0] = (state->m_mmc_prg_bank[0] & ~0x01) | (data & 0x01);
6300   state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & ~0x07) | ((data & 0x70) >> 4);
6301   prg32(space->machine(), state->m_mmc_prg_bank[0]);
6302   chr8(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
6303}
6304
6305/*************************************************************
6306
6307 Sachen 74x374 bootleg boards
6308
6309 Games: Chess Academy, Chinese Checkers Jpn, Mahjong Academy,
6310 Olympic IQ, Poker II, Tasac [150], Poker III [243]
6311
6312 iNES: mappers 150 & 243
6313
6314 *************************************************************/
6315
6316static void sachen_set_mirror( running_machine &machine, UINT8 nt ) // used by mappers 137, 138, 139, 141
6317{
6318   switch (nt)
6319   {
6320      case 0:
6321      case 1:
6322         set_nt_mirroring(machine, nt ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
6323         break;
6324      case 2:
6325         set_nt_page(machine, 0, CIRAM, 0, 1);
6326         set_nt_page(machine, 1, CIRAM, 1, 1);
6327         set_nt_page(machine, 2, CIRAM, 1, 1);
6328         set_nt_page(machine, 3, CIRAM, 1, 1);
6329         break;
6330      case 3:
6331         set_nt_mirroring(machine, PPU_MIRROR_LOW);
6332         break;
6333      default:
6334         LOG_MMC(("Mapper set NT to invalid value %02x", nt));
6335         break;
6336   }
6337}
6338
6339static WRITE8_HANDLER( sachen_74x374_l_w )
6340{
6341   nes_state *state = space->machine().driver_data<nes_state>();
6342   LOG_MMC(("sachen_74x374_l_w, offset: %04x, data: %02x\n", offset, data));
6343
6344   /* write happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
6345   if (!(offset & 0x100))
6346   {
6347      if (!(offset & 0x01))
6348         state->m_mmc_latch1 = data & 0x07;
6349      else
6350      {
6351         switch (state->m_mmc_latch1)
6352         {
6353            case 0x02:
6354               state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & ~0x08) | ((data << 3) & 0x08);
6355               chr8(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
6356               prg32(space->machine(), data & 0x01);
6357               break;
6358            case 0x04:
6359               state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & ~0x04) | ((data << 2) & 0x04);
6360               chr8(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
6361               break;
6362            case 0x05:
6363               prg32(space->machine(), data & 0x07);
6364               break;
6365            case 0x06:
6366               state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & ~0x03) | ((data << 0) & 0x03);
6367               chr8(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
6368               break;
6369            case 0x07:
6370               sachen_set_mirror(space->machine(), (data >> 1) & 0x03);
6371               break;
6372            default:
6373               break;
6374         }
6375      }
6376   }
6377}
6378
6379static READ8_HANDLER( sachen_74x374_l_r )
6380{
6381   nes_state *state = space->machine().driver_data<nes_state>();
6382   LOG_MMC(("sachen_74x374_l_r, offset: %04x", offset));
6383
6384   /* read  happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
6385   if (!(offset & 0x100))
6386      return (~state->m_mmc_latch1 & 0x3f) /* ^ dips*/;   // we would need to check the Dips here
6387   else
6388      return 0;
6389}
6390
6391static WRITE8_HANDLER( sachen_74x374a_l_w )
6392{
6393   nes_state *state = space->machine().driver_data<nes_state>();
6394   LOG_MMC(("sachen_74x374a_l_w, offset: %04x, data: %02x\n", offset, data));
6395
6396   /* write happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
6397   if (!(offset & 0x100))
6398   {
6399      if (!(offset & 0x01))
6400         state->m_mmc_latch1 = data;
6401      else
6402      {
6403         switch (state->m_mmc_latch1 & 0x07)
6404         {
6405            case 0x00:
6406               prg32(space->machine(), 0);
6407               chr8(space->machine(), 3, CHRROM);
6408               break;
6409            case 0x02:
6410               state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & ~0x08) | ((data << 3) & 0x08);
6411               chr8(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
6412               break;
6413            case 0x04:
6414               state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & ~0x01) | ((data << 0) & 0x01);
6415               chr8(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
6416               break;
6417            case 0x05:
6418               prg32(space->machine(), data & 0x01);
6419               break;
6420            case 0x06:
6421               state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & ~0x06) | ((data << 1) & 0x06);
6422               chr8(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
6423               break;
6424            case 0x07:
6425               sachen_set_mirror(space->machine(), BIT(data, 0));
6426               break;
6427            default:
6428               break;
6429         }
6430      }
6431   }
6432}
6433
6434/*************************************************************
6435
6436 Sachen S8259 bootleg boards
6437
6438 iNES: mapper 141 (A), 138 (B), 139 (C), 137 (D)
6439
6440 *************************************************************/
6441
6442static void common_s8259_write_handler( address_space *space, offs_t offset, UINT8 data, int board )
6443{
6444   nes_state *state = space->machine().driver_data<nes_state>();
6445   UINT8 bank_helper1, bank_helper2, shift, add1, add2, add3;
6446
6447   /* write happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
6448   if (!(offset & 0x100))
6449   {
6450      if (!(offset & 0x01))
6451         state->m_mmc_latch1 = data & 0x07;
6452      else
6453      {
6454         state->m_sachen_reg[state->m_mmc_latch1] = data;
6455
6456         switch (state->m_mmc_latch1)
6457         {
6458            case 0x05:
6459               prg32(space->machine(), data);
6460               break;
6461            case 0x07:
6462               sachen_set_mirror(space->machine(), BIT(data, 0) ? 0 : (data >> 1) & 0x03);
6463               break;
6464            default:
6465               if (board == SACHEN_8259D)
6466               {
6467                  if (state->m_mmc_chr_source == CHRROM)
6468                  {
6469                     chr1_0(space->machine(), (state->m_sachen_reg[0] & 0x07), CHRROM);
6470                     chr1_1(space->machine(), (state->m_sachen_reg[1] & 0x07) | (state->m_sachen_reg[4] << 4 & 0x10), CHRROM);
6471                     chr1_2(space->machine(), (state->m_sachen_reg[2] & 0x07) | (state->m_sachen_reg[4] << 3 & 0x10), CHRROM);
6472                     chr1_3(space->machine(), (state->m_sachen_reg[3] & 0x07) | (state->m_sachen_reg[4] << 2 & 0x10) | (state->m_sachen_reg[6] << 3 & 0x08), CHRROM);
6473                  }
6474               }
6475               else
6476               {
6477                  bank_helper1 = state->m_sachen_reg[7] & 0x01;
6478                  bank_helper2 = (state->m_sachen_reg[4] & 0x07) << 3;
6479                  shift = (board == SACHEN_8259A) ? 1 : (board == SACHEN_8259C) ? 2 : 0;
6480                  add1 = (board == SACHEN_8259B) ? 0 : 1;
6481                  add2 = (board == SACHEN_8259C) ? 2 : 0;
6482                  add3 = (board == SACHEN_8259A) ? 1 : (board == SACHEN_8259C) ? 3 : 0;
6483
6484                  if (state->m_mmc_chr_source == CHRROM)
6485                  {
6486                     chr2_0(space->machine(), ((state->m_sachen_reg[bank_helper1 ? 0 : 0] & 0x07) | bank_helper2) << shift, CHRROM);
6487                     chr2_2(space->machine(), ((state->m_sachen_reg[bank_helper1 ? 0 : 1] & 0x07) | bank_helper2) << shift | add1, CHRROM);
6488                     chr2_4(space->machine(), ((state->m_sachen_reg[bank_helper1 ? 0 : 2] & 0x07) | bank_helper2) << shift | add2, CHRROM);
6489                     chr2_6(space->machine(), ((state->m_sachen_reg[bank_helper1 ? 0 : 3] & 0x07) | bank_helper2) << shift | add3, CHRROM);
6490                  }
6491               }
6492               break;
6493         }
6494      }
6495   }
6496}
6497
6498static WRITE8_HANDLER( s8259_l_w )
6499{
6500   nes_state *state = space->machine().driver_data<nes_state>();
6501   LOG_MMC(("s8259_w, type: %d, offset: %04x, data: %02x\n", state->m_pcb_id, offset, data));
6502
6503   common_s8259_write_handler(space, offset, data, state->m_pcb_id);
6504}
6505
6506static WRITE8_HANDLER( s8259_m_w )
6507{
6508   nes_state *state = space->machine().driver_data<nes_state>();
6509   LOG_MMC(("s8259_w, type: %d, offset: %04x, data: %02x\n", state->m_pcb_id, offset, data));
6510
6511   common_s8259_write_handler(space, (offset + 0x100) & 0xfff, data, state->m_pcb_id);
6512}
6513
6514
6515/*************************************************************
6516
6517 Sachen SA009 bootleg boards
6518
6519 Games: Pipe 5
6520
6521 iNES: mapper 160
6522
6523 In MESS: Supported.
6524
6525 *************************************************************/
6526
6527static WRITE8_HANDLER( sa009_l_w )
6528{
6529   nes_state *state = space->machine().driver_data<nes_state>();
6530   LOG_MMC(("sa009_l_w, offset: %04x, data: %02x\n", offset, data));
6531
6532   chr8(space->machine(), data, state->m_mmc_chr_source);
6533}
6534
6535/*************************************************************
6536
6537 Sachen SA0036 bootleg boards
6538
6539 Games: Taiwan Mahjong 16
6540
6541 iNES: mapper 149
6542
6543 In MESS: Supported.
6544
6545 *************************************************************/
6546
6547static WRITE8_HANDLER( sa0036_w )
6548{
6549   LOG_MMC(("sa0036_w, offset: %04x, data: %02x\n", offset, data));
6550
6551   chr8(space->machine(), data >> 7, CHRROM);
6552}
6553
6554/*************************************************************
6555
6556 Sachen SA0037 bootleg boards
6557
6558 Games: Mahjong World, Shisen Mahjong
6559
6560 iNES: mapper 148
6561
6562 In MESS: Supported.
6563
6564 *************************************************************/
6565
6566static WRITE8_HANDLER( sa0037_w )
6567{
6568   LOG_MMC(("sa0037_w, offset: %04x, data: %02x\n", offset, data));
6569
6570   prg32(space->machine(), data >> 3);
6571   chr8(space->machine(), data, CHRROM);
6572}
6573
6574/*************************************************************
6575
6576 Sachen SA72007 bootleg boards
6577
6578 Games: Sidewinder
6579
6580 iNES: mapper 145
6581
6582 In MESS: Supported.
6583
6584 *************************************************************/
6585
6586static WRITE8_HANDLER( sa72007_l_w )
6587{
6588   LOG_MMC(("sa72007_l_w, offset: %04x, data: %02x\n", offset, data));
6589
6590   /* only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
6591   if (!(offset & 0x100))
6592      chr8(space->machine(), data >> 7, CHRROM);
6593}
6594
6595/*************************************************************
6596
6597 Sachen SA72008 bootleg boards
6598
6599 Games: Jovial Race, Qi Wang
6600
6601 iNES: mapper 133
6602
6603 In MESS: Supported.
6604
6605 *************************************************************/
6606
6607static WRITE8_HANDLER( sa72008_l_w )
6608{
6609   LOG_MMC(("sa72008_l_w, offset: %04x, data: %02x\n", offset, data));
6610
6611   prg32(space->machine(), data >> 2);
6612   chr8(space->machine(), data, CHRROM);
6613}
6614
6615/*************************************************************
6616
6617 Sachen TCA-01 bootleg boards
6618
6619 iNES: mapper 143
6620
6621 Games: Dancing Blocks, Magic Mathematic
6622
6623 In MESS: Supported.
6624
6625 *************************************************************/
6626
6627static READ8_HANDLER( tca01_l_r )
6628{
6629   LOG_MMC(("tca01_l_r, offset: %04x\n", offset));
6630
6631   /* the address is read only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
6632   if (!(offset & 0x100))
6633      return (~offset & 0x3f) | 0x40;
6634   else
6635      return 0x00;
6636}
6637
6638/*************************************************************
6639
6640 Sachen TCU-01 bootleg boards
6641
6642 Games: Challenge of the Dragon, Chinese Kungfu
6643
6644 iNES: mapper 147
6645
6646 In MESS: Supported.
6647
6648 *************************************************************/
6649
6650static WRITE8_HANDLER( tcu01_l_w )
6651{
6652   LOG_MMC(("tcu01_l_w, offset: %04x, data: %02x\n", offset, data));
6653
6654   if ((offset & 0x103) == 0x002)
6655   {
6656      prg32(space->machine(), ((data >> 6) & 0x02) | ((data >> 2) & 0x01));
6657      chr8(space->machine(), data >> 3, CHRROM);
6658   }
6659}
6660
6661static WRITE8_HANDLER( tcu01_m_w )
6662{
6663   LOG_MMC(("tcu01_m_w, offset: %04x, data: %02x\n", offset, data));
6664
6665   tcu01_l_w(space, (offset + 0x100) & 0xfff, data);
6666}
6667
6668static WRITE8_HANDLER( tcu01_w )
6669{
6670   LOG_MMC(("tcu01_w, offset: %04x, data: %02x\n", offset, data));
6671
6672   tcu01_l_w(space, (offset + 0x100) & 0xfff, data);
6673}
6674
6675/*************************************************************
6676
6677 Sachen TCU-02 bootleg boards
6678
6679 Games: Mei Loi Siu Ji
6680
6681 iNES: mapper 136
6682
6683 In MESS: Supported.
6684
6685 *************************************************************/
6686
6687static WRITE8_HANDLER( tcu02_l_w )
6688{
6689   nes_state *state = space->machine().driver_data<nes_state>();
6690   LOG_MMC(("tcu02_l_w, offset: %04x, data: %02x\n", offset, data));
6691
6692   if ((offset & 0x103) == 0x002)
6693   {
6694      state->m_mmc_latch1 = (data & 0x30) | ((data + 3) & 0x0f);
6695      chr8(space->machine(), state->m_mmc_latch1, CHRROM);
6696   }
6697}
6698
6699static READ8_HANDLER( tcu02_l_r )
6700{
6701   nes_state *state = space->machine().driver_data<nes_state>();
6702   LOG_MMC(("tcu02_l_r, offset: %04x\n", offset));
6703
6704   if ((offset & 0x103) == 0x000)
6705      return state->m_mmc_latch1 | 0x40;
6706   else
6707      return 0x00;
6708}
6709
6710
6711/*************************************************************
6712
6713 Subor bootleg board Type 0
6714
6715 iNES: mapper 167
6716
6717 *************************************************************/
6718
6719static WRITE8_HANDLER( subor0_w )
6720{
6721   nes_state *state = space->machine().driver_data<nes_state>();
6722   UINT8 subor_helper1, subor_helper2;
6723   LOG_MMC(("subor0_w, offset: %04x, data: %02x\n", offset, data));
6724
6725   state->m_subor_reg[(offset >> 13) & 0x03] = data;
6726   subor_helper1 = ((state->m_subor_reg[0] ^ state->m_subor_reg[1]) << 1) & 0x20;
6727   subor_helper2 = ((state->m_subor_reg[2] ^ state->m_subor_reg[3]) << 0) & 0x1f;
6728
6729   if (state->m_subor_reg[1] & 0x08)
6730   {
6731      subor_helper1 += subor_helper2 & 0xfe;
6732      subor_helper2 = subor_helper1;
6733      subor_helper1 += 1;
6734   }
6735   else if (state->m_subor_reg[1] & 0x04)
6736   {
6737      subor_helper2 += subor_helper1;
6738      subor_helper1 = 0x1f;
6739   }
6740   else
6741   {
6742      subor_helper1 += subor_helper2;
6743      subor_helper2 = 0x20;
6744   }
6745
6746   prg16_89ab(space->machine(), subor_helper1);
6747   prg16_cdef(space->machine(), subor_helper2);
6748}
6749
6750/*************************************************************
6751
6752 Subor bootleg board Type 1
6753
6754 iNES: mapper 166
6755
6756 *************************************************************/
6757
6758static WRITE8_HANDLER( subor1_w )
6759{
6760   nes_state *state = space->machine().driver_data<nes_state>();
6761   UINT8 subor_helper1, subor_helper2;
6762   LOG_MMC(("subor1_w, offset: %04x, data: %02x\n", offset, data));
6763
6764   state->m_subor_reg[(offset >> 13) & 0x03] = data;
6765   subor_helper1 = ((state->m_subor_reg[0] ^ state->m_subor_reg[1]) << 1) & 0x20;
6766   subor_helper2 = ((state->m_subor_reg[2] ^ state->m_subor_reg[3]) << 0) & 0x1f;
6767
6768   if (state->m_subor_reg[1] & 0x08)
6769   {
6770      subor_helper1 += subor_helper2 & 0xfe;
6771      subor_helper2 = subor_helper1;
6772      subor_helper2 += 1;
6773   }
6774   else if (state->m_subor_reg[1] & 0x04)
6775   {
6776      subor_helper2 += subor_helper1;
6777      subor_helper1 = 0x1f;
6778   }
6779   else
6780   {
6781      subor_helper1 += subor_helper2;
6782      subor_helper2 = 0x07;
6783   }
6784
6785   prg16_89ab(space->machine(), subor_helper1);
6786   prg16_cdef(space->machine(), subor_helper2);
6787}
6788
6789/*************************************************************
6790
6791 Bootleg Board by Super Game
6792
6793 Games: Boogerman, Mortal Kombat III
6794
6795 MMC3 clone. Also, it probably needs a hack to support both
6796 variants (Boogerman & MK3).
6797
6798 iNES: mapper 215
6799
6800 In MESS: Preliminary support.
6801
6802 *************************************************************/
6803
6804static void sgame_boog_prg_cb( running_machine &machine, int start, int bank )
6805{
6806   nes_state *state = machine.driver_data<nes_state>();
6807   if (!(state->m_mmc_reg[0] & 0x80))   // if this is != 0 we should never even arrive here
6808   {
6809      if (state->m_mmc_reg[1] & 0x08)
6810         bank = (bank & 0x1f) | 0x20;
6811      else
6812         bank = (bank & 0x0f) | (state->m_mmc_reg[1] & 0x10);
6813
6814      prg8_x(machine, start, bank);
6815   }
6816}
6817
6818static void sgame_boog_chr_cb( running_machine &machine, int start, int bank, int source )
6819{
6820   nes_state *state = machine.driver_data<nes_state>();
6821
6822   if ((state->m_mmc_reg[1] & 0x04))
6823      bank |= 0x100;
6824   else
6825      bank = (bank & 0x7f) | ((state->m_mmc_reg[1] & 0x10) << 3);
6826
6827   chr1_x(machine, start, bank, source);
6828}
6829
6830static void sgame_boog_set_prg( running_machine &machine )
6831{
6832   nes_state *state = machine.driver_data<nes_state>();
6833   if (state->m_mmc_reg[0] & 0x80)
6834   {
6835      prg16_89ab(machine, (state->m_mmc_reg[0] & 0xf0) | (state->m_mmc_reg[1] & 0x10));
6836      prg16_cdef(machine, (state->m_mmc_reg[0] & 0xf0) | (state->m_mmc_reg[1] & 0x10));
6837   }
6838   else
6839      mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
6840}
6841
6842static WRITE8_HANDLER( sgame_boog_l_w )
6843{
6844   nes_state *state = space->machine().driver_data<nes_state>();
6845   LOG_MMC(("sgame_boog_l_w, offset: %04x, data: %02x\n", offset, data));
6846   offset += 0x100;
6847
6848   if (offset == 0x1000)
6849   {
6850      state->m_mmc_reg[0] = data;
6851      sgame_boog_set_prg(space->machine());
6852   }
6853   else if (offset == 0x1001)
6854   {
6855      state->m_mmc_reg[1] = data;
6856      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6857   }
6858   else if (offset == 0x1007)
6859   {
6860      state->m_mmc3_latch = 0;
6861      state->m_mmc_reg[2] = data;
6862      sgame_boog_set_prg(space->machine());
6863      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6864   }
6865}
6866
6867static WRITE8_HANDLER( sgame_boog_m_w )
6868{
6869   nes_state *state = space->machine().driver_data<nes_state>();
6870   LOG_MMC(("sgame_boog_m_w, offset: %04x, data: %02x\n", offset, data));
6871
6872   if (offset == 0x0000)
6873   {
6874      state->m_mmc_reg[0] = data;
6875      sgame_boog_set_prg(space->machine());
6876   }
6877   else if (offset == 0x0001)
6878   {
6879      state->m_mmc_reg[1] = data;
6880      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6881   }
6882   else if (offset == 0x0007)
6883   {
6884      state->m_mmc3_latch = 0;
6885      state->m_mmc_reg[2] = data;
6886      sgame_boog_set_prg(space->machine());
6887      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6888   }
6889}
6890
6891static WRITE8_HANDLER( sgame_boog_w )
6892{
6893   nes_state *state = space->machine().driver_data<nes_state>();
6894   static const UINT8 conv_table[8] = {0,2,5,3,6,1,7,4};
6895   LOG_MMC(("sgame_boog_w, offset: %04x, data: %02x\n", offset, data));
6896
6897   switch (offset & 0x6001)
6898   {
6899      case 0x0000:
6900         if (!state->m_mmc_reg[2])
6901            txrom_w(space, 0x0000, data);
6902         break;
6903
6904      case 0x0001:
6905         if (!state->m_mmc_reg[2])
6906            txrom_w(space, 0x0001, data);
6907         else if (state->m_mmc_reg[3] && ((state->m_mmc_reg[0] & 0x80) == 0 || (state->m_mmc_latch1 & 0x07) < 6))   // if we use the prg16 banks and cmd=6,7 DON'T enter!
6908         {
6909            state->m_mmc_reg[3] = 0;
6910            txrom_w(space, 0x0001, data);
6911         }
6912         break;
6913
6914      case 0x2000:
6915         if (!state->m_mmc_reg[2])
6916            txrom_w(space, 0x2000, data);
6917         else
6918         {
6919            data = (data & 0xc0) | conv_table[data & 0x07];
6920            state->m_mmc_reg[3] = 1;
6921            txrom_w(space, 0x0000, data);
6922            break;
6923         }
6924         break;
6925
6926      case 0x4000:
6927         if (!state->m_mmc_reg[2])
6928            txrom_w(space, 0x4000, data);
6929         else
6930            set_nt_mirroring(space->machine(), ((data >> 7) | data) & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
6931         break;
6932
6933      case 0x4001:
6934         if (!state->m_mmc_reg[2])
6935            txrom_w(space, 0x4001, data);
6936         else
6937            txrom_w(space, 0x6001, data);
6938         break;
6939
6940      case 0x6001:
6941         if (!state->m_mmc_reg[2])
6942            txrom_w(space, 0x6001, data);
6943         else
6944         {
6945            txrom_w(space, 0x4000, data);
6946            txrom_w(space, 0x4001, data);
6947         }
6948         break;
6949
6950      default:
6951         txrom_w(space, offset, data);
6952         break;
6953   }
6954}
6955
6956/*************************************************************
6957
6958 Bootleg Board by Super Game
6959
6960 Games: The Lion King
6961
6962 MMC3 clone.
6963
6964 iNES: mapper 114
6965
6966 In MESS: Supported.
6967
6968 *************************************************************/
6969
6970static WRITE8_HANDLER( sgame_lion_m_w )
6971{
6972   nes_state *state = space->machine().driver_data<nes_state>();
6973   LOG_MMC(("sgame_lion_m_w, offset: %04x, data: %02x\n", offset, data));
6974
6975   state->m_map114_reg = data;
6976
6977   if (state->m_map114_reg & 0x80)
6978   {
6979      prg16_89ab(space->machine(), data & 0x1f);
6980      prg16_cdef(space->machine(), data & 0x1f);
6981   }
6982   else
6983      mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
6984
6985}
6986
6987static WRITE8_HANDLER( sgame_lion_w )
6988{
6989   nes_state *state = space->machine().driver_data<nes_state>();
6990   static const UINT8 conv_table[8] = {0, 3, 1, 5, 6, 7, 2, 4};
6991   LOG_MMC(("sgame_lion_w, offset: %04x, data: %02x\n", offset, data));
6992
6993   if (offset < 0x6000)
6994   {
6995      switch (offset & 0x6000)
6996      {
6997         case 0x0000:
6998            set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
6999            break;
7000         case 0x2000:
7001            state->m_map114_reg_enabled = 1;
7002            data = (data & 0xc0) | conv_table[data & 0x07];
7003            txrom_w(space, 0x0000, data);
7004            break;
7005         case 0x4000:
7006            if (state->m_map114_reg_enabled && (state->m_map114_reg & 0x80) == 0)
7007            {
7008               state->m_map114_reg_enabled = 0;
7009               txrom_w(space, 0x0001, data);
7010            }
7011            break;
7012      }
7013   }
7014   else
7015   {
7016      switch (offset & 0x03)
7017      {
7018         case 0x02:
7019            txrom_w(space, 0x6000, data);
7020            break;
7021         case 0x03:
7022            txrom_w(space, 0x6001, data);
7023            txrom_w(space, 0x4000, data);
7024            txrom_w(space, 0x4001, data);
7025            break;
7026      }
7027   }
7028}
7029
7030/*************************************************************
7031
7032 Tengen 800008 Board
7033
7034 iNES: mapper 3?
7035
7036 In MESS: Supported.
7037
7038 *************************************************************/
7039
7040static WRITE8_HANDLER( tengen_800008_w )
7041{
7042   LOG_MMC(("tengen_800008_w, offset: %04x, data: %02x\n", offset, data));
7043
7044   prg32(space->machine(), data >> 3);
7045   chr8(space->machine(), data, CHRROM);
7046}
7047
7048/*************************************************************
7049
7050 Tengen 800032 Board
7051
7052 Games: Klax, Road Runner, Rolling Thunder, Shinobi, Skulls
7053 & Croosbones, Xybots
7054
7055 iNES: mapper 64
7056
7057 In MESS: Partially Supported.
7058
7059 *************************************************************/
7060
7061static void tengen_800032_irq( device_t *device, int scanline, int vblank, int blanked )
7062{
7063   nes_state *state = device->machine().driver_data<nes_state>();
7064   if (!state->m_IRQ_mode)   // we are in scanline mode!
7065   {
7066      if (scanline < PPU_BOTTOM_VISIBLE_SCANLINE)
7067      {
7068         if (!state->m_IRQ_reset)
7069         {
7070            if (!state->m_IRQ_count)
7071               state->m_IRQ_count = state->m_IRQ_count_latch;
7072            else
7073            {
7074               state->m_IRQ_count--;
7075               if (state->m_IRQ_enable && !blanked && !state->m_IRQ_count)
7076               {
7077                  LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
7078                         device->machine().primary_screen->vpos(), device->machine().primary_screen->hpos()));
7079                  device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
7080               }
7081            }
7082         }
7083         else
7084         {
7085            state->m_IRQ_reset = 0;
7086            state->m_IRQ_count = state->m_IRQ_count_latch + 1;
7087         }
7088      }
7089   }
7090   /* otherwise, we are in CPU cycles mode --> decrement count of 114 every scanline
7091     --> in the meanwhile anything can have happened to IRQ_reset and we would not know
7092     --> Skulls and Crossbones does not show anything!! */
7093   else
7094   {
7095      //      if (!state->m_IRQ_reset)
7096      {
7097         if (state->m_IRQ_count <= 114)
7098            state->m_IRQ_count = state->m_IRQ_count_latch;
7099         else
7100         {
7101            state->m_IRQ_count -= 114;
7102            if (state->m_IRQ_enable && !blanked && (state->m_IRQ_count <= 114))
7103            {
7104               LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
7105                      device->machine().primary_screen->vpos(), device->machine().primary_screen->hpos()));
7106               device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
7107            }
7108         }
7109      }
7110      //      else
7111      //      {
7112      //          state->m_IRQ_reset = 0;
7113      //          state->m_IRQ_count = state->m_IRQ_count_latch + 1;
7114      //      }
7115   }
7116}
7117
7118static void tengen_800032_set_prg( running_machine &machine )
7119{
7120   nes_state *state = machine.driver_data<nes_state>();
7121   UINT8 prg_mode = state->m_mmc_latch1 & 0x40;
7122
7123   prg8_89(machine, state->m_mmc_prg_bank[prg_mode ? 2: 0]);
7124   prg8_ab(machine, state->m_mmc_prg_bank[prg_mode ? 0: 1]);
7125   prg8_cd(machine, state->m_mmc_prg_bank[prg_mode ? 1: 2]);
7126}
7127
7128static void tengen_800032_set_chr( running_machine &machine )
7129{
7130   nes_state *state = machine.driver_data<nes_state>();
7131   UINT8 chr_page = (state->m_mmc_latch1 & 0x80) >> 5;
7132
7133   if (state->m_mmc_latch1 & 0x20)
7134   {
7135      chr1_x(machine, 0 ^ chr_page, state->m_mmc_vrom_bank[0], CHRROM);
7136      chr1_x(machine, 1 ^ chr_page, state->m_mmc_vrom_bank[8], CHRROM);
7137      chr1_x(machine, 2 ^ chr_page, state->m_mmc_vrom_bank[1], CHRROM);
7138      chr1_x(machine, 3 ^ chr_page, state->m_mmc_vrom_bank[9], CHRROM);
7139   }
7140   else
7141   {
7142      chr1_x(machine, 0 ^ chr_page, state->m_mmc_vrom_bank[0] & ~0x01, CHRROM);
7143      chr1_x(machine, 1 ^ chr_page, state->m_mmc_vrom_bank[0] |  0x01, CHRROM);
7144      chr1_x(machine, 2 ^ chr_page, state->m_mmc_vrom_bank[1] & ~0x01, CHRROM);
7145      chr1_x(machine, 3 ^ chr_page, state->m_mmc_vrom_bank[1] |  0x01, CHRROM);
7146   }
7147
7148   chr1_x(machine, 4 ^ chr_page, state->m_mmc_vrom_bank[2], CHRROM);
7149   chr1_x(machine, 5 ^ chr_page, state->m_mmc_vrom_bank[3], CHRROM);
7150   chr1_x(machine, 6 ^ chr_page, state->m_mmc_vrom_bank[4], CHRROM);
7151   chr1_x(machine, 7 ^ chr_page, state->m_mmc_vrom_bank[5], CHRROM);
7152}
7153
7154static WRITE8_HANDLER( tengen_800032_w )
7155{
7156   nes_state *state = space->machine().driver_data<nes_state>();
7157   UINT8 map64_helper, cmd;
7158   LOG_MMC(("tengen_800032_w, offset: %04x, data: %02x\n", offset, data));
7159
7160   switch (offset & 0x6001)
7161   {
7162      case 0x0000:
7163         map64_helper = state->m_mmc_latch1 ^ data;
7164         state->m_mmc_latch1 = data;
7165
7166         /* Has PRG Mode changed? */
7167         if (map64_helper & 0x40)
7168            tengen_800032_set_prg(space->machine());
7169
7170         /* Has CHR Mode changed? */
7171         if (map64_helper & 0xa0)
7172            tengen_800032_set_chr(space->machine());
7173         break;
7174
7175      case 0x0001:
7176         cmd = state->m_mmc_latch1 & 0x0f;
7177         switch (cmd)
7178      {
7179         case 0: case 1:
7180         case 2: case 3:
7181         case 4: case 5:
7182            state->m_mmc_vrom_bank[cmd] = data;
7183            tengen_800032_set_chr(space->machine());
7184            break;
7185         case 6: case 7:
7186            state->m_mmc_prg_bank[cmd - 6] = data;
7187            tengen_800032_set_prg(space->machine());
7188            break;
7189         case 8: case 9:
7190            state->m_mmc_vrom_bank[cmd - 2] = data;
7191            tengen_800032_set_chr(space->machine());
7192            break;
7193         case 0x0f:
7194            state->m_mmc_prg_bank[2] = data;
7195            tengen_800032_set_prg(space->machine());
7196            break;
7197      }
7198         break;
7199
7200      case 0x2000:
7201         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
7202         break;
7203
7204      case 0x4000:
7205         state->m_IRQ_count_latch = data;
7206         break;
7207
7208      case 0x4001: /* $c001 - IRQ scanline latch */
7209         state->m_IRQ_mode = data & 0x01;
7210         state->m_IRQ_reset = 1;
7211         break;
7212
7213      case 0x6000:
7214         state->m_IRQ_enable = 0;
7215         break;
7216
7217      case 0x6001:
7218         state->m_IRQ_enable = 1;
7219         break;
7220
7221      default:
7222         LOG_MMC(("Mapper 64 write. addr: %04x value: %02x\n", offset + 0x8000, data));
7223         break;
7224   }
7225}
7226
7227/*************************************************************
7228
7229 Tengen 800037 Board
7230
7231 Games: Alien Syndrome
7232
7233 iNES: mapper 158
7234
7235 In MESS: Very preliminary support.
7236
7237 *************************************************************/
7238
7239// probably wrong...
7240static void tengen_800037_set_mirror( running_machine &machine )
7241{
7242   nes_state *state = machine.driver_data<nes_state>();
7243   UINT8 nt_mode = state->m_mmc_latch1 & 0x80;
7244
7245   set_nt_page(machine, 0, ROM, state->m_mmc_vrom_bank[nt_mode ? 2 : 0], 0);
7246   set_nt_page(machine, 1, ROM, state->m_mmc_vrom_bank[nt_mode ? 3 : 0], 0);
7247   set_nt_page(machine, 2, ROM, state->m_mmc_vrom_bank[nt_mode ? 4 : 1], 0);
7248   set_nt_page(machine, 3, ROM, state->m_mmc_vrom_bank[nt_mode ? 5 : 1], 0);
7249}
7250
7251static WRITE8_HANDLER( tengen_800037_w )
7252{
7253   nes_state *state = space->machine().driver_data<nes_state>();
7254   UINT8 map158_helper, cmd;
7255   LOG_MMC(("tengen_800037_w, offset: %04x, data: %02x\n", offset, data));
7256
7257   switch (offset & 0x6001)
7258   {
7259      case 0x0000:
7260         map158_helper = state->m_mmc_latch1 ^ data;
7261         state->m_mmc_latch1 = data;
7262
7263         /* Has PRG Mode changed? */
7264         if (map158_helper & 0x40)
7265            tengen_800032_set_prg(space->machine());
7266
7267         /* Has CHR Mode changed? */
7268         if (map158_helper & 0xa0)
7269         {
7270            tengen_800032_set_chr(space->machine());
7271            tengen_800037_set_mirror(space->machine());
7272         }
7273         break;
7274
7275      case 0x0001:
7276         cmd = state->m_mmc_latch1 & 0x0f;
7277         switch (cmd)
7278      {
7279         case 0: case 1:
7280         case 2: case 3:
7281         case 4: case 5:
7282            state->m_mmc_vrom_bank[cmd] = data;
7283            tengen_800032_set_chr(space->machine());
7284            tengen_800037_set_mirror(space->machine());
7285            break;
7286         case 6: case 7:
7287            state->m_mmc_prg_bank[cmd - 6] = data;
7288            tengen_800032_set_prg(space->machine());
7289            break;
7290         case 8: case 9:
7291            state->m_mmc_vrom_bank[cmd - 2] = data;
7292            tengen_800032_set_chr(space->machine());
7293            tengen_800037_set_mirror(space->machine());
7294            break;
7295         case 0x0f:
7296            state->m_mmc_prg_bank[2] = data;
7297            tengen_800032_set_prg(space->machine());
7298            break;
7299      }
7300         break;
7301
7302      case 0x2000:
7303         break;
7304
7305      default:
7306         tengen_800032_w(space, offset, data);
7307         break;
7308   }
7309}
7310
7311/*************************************************************
7312
7313 Bootleg Board 22211 by TXC (Type A)
7314
7315 Games: Creatom
7316
7317 Info from NEStopia: this mapper features write to four
7318 registers (0x4100-0x4103). The third one is used to select
7319 PRG and CHR banks.
7320
7321 iNES: mapper 132
7322
7323 In MESS: Supported.
7324
7325 *************************************************************/
7326
7327static WRITE8_HANDLER( txc_22211_l_w )
7328{
7329   nes_state *state = space->machine().driver_data<nes_state>();
7330   LOG_MMC(("txc_22211_l_w, offset: %04x, data: %02x\n", offset, data));
7331
7332   if (offset < 4)
7333      state->m_txc_reg[offset & 0x03] = data;
7334}
7335
7336static READ8_HANDLER( txc_22211_l_r )
7337{
7338   nes_state *state = space->machine().driver_data<nes_state>();
7339   LOG_MMC(("txc_22211_l_r, offset: %04x\n", offset));
7340
7341   if (offset == 0x0000)
7342      return (state->m_txc_reg[1] ^ state->m_txc_reg[2]) | 0x40;
7343   else
7344      return 0x00;
7345}
7346
7347static WRITE8_HANDLER( txc_22211_w )
7348{
7349   nes_state *state = space->machine().driver_data<nes_state>();
7350   LOG_MMC(("txc_22211_w, offset: %04x, data: %02x\n", offset, data));
7351
7352   prg32(space->machine(), state->m_txc_reg[2] >> 2);
7353   chr8(space->machine(), state->m_txc_reg[2], CHRROM);
7354}
7355
7356/*************************************************************
7357
7358 Bootleg Board 22211 by TXC (Type B)
7359
7360 Games: 1991 Du Ma Racing
7361
7362 This mapper is basically the same as Type A. Only difference is
7363 in the way CHR banks are selected (see below)
7364
7365 iNES: mapper 172
7366
7367 In MESS: Supported.
7368
7369 *************************************************************/
7370
7371static WRITE8_HANDLER( txc_22211b_w )
7372{
7373   nes_state *state = space->machine().driver_data<nes_state>();
7374   LOG_MMC(("txc_22211b_w, offset: %04x, data: %02x\n", offset, data));
7375
7376   prg32(space->machine(), state->m_txc_reg[2] >> 2);
7377   chr8(space->machine(), (((data ^ state->m_txc_reg[2]) >> 3) & 0x02) | (((data ^ state->m_txc_reg[2]) >> 5) & 0x01), CHRROM);
7378}
7379
7380/*************************************************************
7381
7382 Bootleg Board 22211 by TXC (Type C)
7383
7384 Games: Mahjong Block, Xiao Ma Li
7385
7386 This mapper is basically the same as 132 too. Only difference is
7387 in 0x4100 reads which expect also bit 0 to be set
7388
7389 iNES: mapper 172
7390
7391 In MESS: Supported.
7392
7393 *************************************************************/
7394
7395static READ8_HANDLER( txc_22211c_l_r )
7396{
7397   nes_state *state = space->machine().driver_data<nes_state>();
7398   LOG_MMC(("txc_22211c_l_r, offset: %04x\n", offset));
7399
7400   if (offset == 0x0000)
7401      return (state->m_txc_reg[1] ^ state->m_txc_reg[2]) | 0x41;
7402   else
7403      return 0x00;
7404}
7405
7406/*************************************************************
7407
7408 Bootleg Board 'Thunder Warrior' by TXC
7409
7410 Games: Master Fighter II, Master Fighter 3, Thunder Warrior
7411
7412 MMC3 clone
7413
7414 iNES: mapper 189
7415
7416 In MESS: Supported.
7417
7418 *************************************************************/
7419
7420static WRITE8_HANDLER( txc_tw_l_w )
7421{
7422   LOG_MMC(("txctw_l_w, offset: %04x, data: %02x\n", offset, data));
7423
7424   prg32(space->machine(), (data >> 4) | data);
7425}
7426
7427static WRITE8_HANDLER( txc_tw_m_w )
7428{
7429   LOG_MMC(("txctw_m_w, offset: %04x, data: %04x\n", offset, data));
7430
7431   txc_tw_l_w(space, offset & 0xff, data);   // offset does not really count for this mapper
7432}
7433
7434/* writes to 0x8000-0xffff are like MMC3 but no PRG bankswitch (beacuse it is handled by low writes) */
7435static void txc_tw_prg_cb( running_machine &machine, int start, int bank )
7436{
7437   return;
7438}
7439
7440/*************************************************************
7441
7442 Bootleg Board 'Strike Wolf' by TXC
7443
7444 Games: Strike Wolf (also Policeman?? according to Nestopia)
7445
7446 iNES: mapper 36
7447
7448 Known Boards: Bootleg Board by TXC
7449
7450 In MESS: Supported.
7451
7452 *************************************************************/
7453
7454static WRITE8_HANDLER( txc_strikewolf_w )
7455{
7456   LOG_MMC(("txc_strikewolf_w, offset: %04x, data: %02x\n", offset, data));
7457
7458   if ((offset >= 0x400) && (offset < 0x7fff))
7459   {
7460      prg32(space->machine(), data >> 4);
7461      chr8(space->machine(), data & 0x0f, CHRROM);
7462   }
7463}
7464
7465/*************************************************************
7466
7467 Bootleg Board MXMDHTWO by TXC
7468
7469 Games: Commandos, Journey to the West, Ma Bu Mi Zhen &
7470 Qu Wei Cheng Yu Wu, Si Lu Chuan Qi
7471
7472 Simple Mapper: writes to 0x8000-0xffff sets the prg32 bank.
7473 Not sure if returning 0x50 for reads in 0x4100-0x5000 is correct.
7474
7475 iNES: mapper 241
7476
7477 In MESS: Supported.
7478
7479 *************************************************************/
7480
7481static READ8_HANDLER( txc_mxmdhtwo_l_r )
7482{
7483   return 0x50;
7484}
7485
7486static WRITE8_HANDLER( txc_mxmdhtwo_w )
7487{
7488   LOG_MMC(("txc_mxmdhtwo_w, offset: %04x, data: %02x\n", offset, data));
7489
7490   prg32(space->machine(), data);
7491}
7492
7493/*************************************************************
7494
7495 Waixing Board Type A
7496
7497 Games: Columbus - Ougon no Yoake (C), Ji Jia Zhan Shi,
7498 Jia A Fung Yun, Wei Luo Chuan Qi
7499
7500 This mapper is quite similar to MMC3, but with two differences:
7501 mirroring is not the same, and when VROM banks 8,9 are accessed
7502 they point to CHRRAM and not CHRROM.
7503
7504 iNES: mapper 74
7505
7506 In MESS: Supported
7507
7508 *************************************************************/
7509
7510/* MIRROR_LOW and MIRROR_HIGH are swapped! */
7511static void waixing_set_mirror( running_machine &machine, UINT8 nt )
7512{
7513   switch (nt)
7514   {
7515      case 0:
7516      case 1:
7517         set_nt_mirroring(machine, nt ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
7518         break;
7519      case 2:
7520         set_nt_mirroring(machine, PPU_MIRROR_LOW);
7521         break;
7522      case 3:
7523         set_nt_mirroring(machine, PPU_MIRROR_HIGH);
7524         break;
7525      default:
7526         LOG_MMC(("Mapper set NT to invalid value %02x", nt));
7527         break;
7528   }
7529}
7530
7531/* Luo Ke Ren X only works with this */
7532static void waixing_a_chr_cb( running_machine &machine, int start, int bank, int source )
7533{
7534   int chr_src = (bank <= 9) ? CHRRAM : CHRROM;
7535   chr1_x(machine, start, bank, chr_src);
7536}
7537
7538/* Ji Jia Zhan Shi only works with this */
7539static void waixing_a1_chr_cb( running_machine &machine, int start, int bank, int source )
7540{
7541   int chr_src = ((bank == 8) || (bank == 9)) ? CHRRAM : CHRROM;
7542   chr1_x(machine, start, bank, chr_src);
7543}
7544
7545static WRITE8_HANDLER( waixing_a_w )
7546{
7547   LOG_MMC(("waixing_a_w, offset: %04x, data: %02x\n", offset, data));
7548
7549   switch (offset & 0x6001)
7550   {
7551      case 0x2000:
7552         waixing_set_mirror(space->machine(), data);   //maybe data & 0x03?
7553         break;
7554
7555      case 0x2001:
7556         break;
7557
7558      default:
7559         txrom_w(space, offset, data);
7560         break;
7561   }
7562}
7563
7564/*************************************************************
7565
7566 Waixing Board Type B
7567
7568 Games: Sugoro Quest (C)
7569
7570 MMC3 clone. This is a minor modification of Mapper 74,
7571 in the sense that it is the same board except for the
7572 CHRRAM pages.
7573
7574 iNES: mapper 191
7575
7576 In MESS: Supported.
7577
7578 *************************************************************/
7579
7580static void waixing_b_chr_cb( running_machine &machine, int start, int bank, int source )
7581{
7582   int chr_src = BIT(bank, 7) ? CHRRAM : CHRROM;
7583   chr1_x(machine, start, bank, chr_src);
7584}
7585
7586/*************************************************************
7587
7588 Waixing Board Type C
7589
7590 Games: Ying Lie Qun Xia Zhuan, Young Chivalry
7591
7592 MMC3 clone. This is a minor modification of Mapper 74,
7593 in the sense that it is the same board except for the
7594 CHRRAM pages.
7595
7596 iNES: mapper 192
7597
7598 In MESS: Supported.
7599
7600 *************************************************************/
7601
7602static void waixing_c_chr_cb( running_machine &machine, int start, int bank, int source )
7603{
7604   int chr_src = ((bank == 0x08) || (bank == 0x09) || (bank == 0x0a) || (bank == 0x0b)) ? CHRRAM : CHRROM;
7605   chr1_x(machine, start, bank, chr_src);
7606}
7607
7608/*************************************************************
7609
7610 Waixing Board Type D
7611
7612 Games: Super Robot Taisen (C)
7613
7614 MMC3 clone. This is a minor modification of Mapper 74,
7615 in the sense that it is the same board except for the
7616 CHRRAM pages.
7617
7618 iNES: mapper 194
7619
7620 In MESS: Supported.
7621
7622 *************************************************************/
7623
7624static void waixing_d_chr_cb( running_machine &machine, int start, int bank, int source )
7625{
7626   int chr_src = (bank < 0x02) ? CHRRAM : CHRROM;
7627   chr1_x(machine, start, bank, chr_src);
7628}
7629
7630/*************************************************************
7631
7632 Waixing Board Type E
7633
7634 Games: Captain Tsubasa Vol. II (C), Chaos World, God
7635 Slayer (C), Zu Qiu Xiao Jiang
7636
7637 MMC3 clone. This is a minor modification of Mapper 74,
7638 in the sense that it is the same board except for the
7639 CHRRAM pages.
7640
7641 iNES: mapper 195
7642
7643 In MESS: Supported.
7644
7645 *************************************************************/
7646
7647static void waixing_e_chr_cb( running_machine &machine, int start, int bank, int source )
7648{
7649   int chr_src = (bank < 0x04) ? CHRRAM : CHRROM;
7650   chr1_x(machine, start, bank, chr_src);
7651}
7652
7653/*************************************************************
7654
7655 Waixing Board Type F
7656
7657 Games: Tenchi wo Kurau II (C)
7658
7659 MMC3 clone.
7660
7661 iNES: mapper 198
7662
7663 In MESS: Preliminary support.
7664
7665 *************************************************************/
7666
7667static WRITE8_HANDLER( waixing_f_w )
7668{
7669   nes_state *state = space->machine().driver_data<nes_state>();
7670   UINT8 cmd;
7671   LOG_MMC(("waixing_f_w, offset: %04x, data: %02x\n", offset, data));
7672
7673   switch (offset & 0x6001)
7674   {
7675      case 0x0001:
7676         cmd = state->m_mmc_latch1 & 0x07;
7677         if (cmd >= 6)
7678         {
7679            state->m_mmc_prg_bank[cmd - 6] = data & ((data > 0x3f) ? 0x4f : 0x3f);
7680            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
7681         }
7682         else
7683            waixing_a_w(space, offset, data);
7684         break;
7685
7686      default:
7687         waixing_a_w(space, offset, data);
7688         break;
7689   }
7690}
7691
7692/*************************************************************
7693
7694 Waixing Board Type G
7695
7696 Games: San Guo Zhi 2, Dragon Ball Z Gaiden (C), Dragon
7697 Ball Z II (C)
7698
7699 MMC3 clone
7700
7701 iNES: mapper 199
7702
7703 In MESS: Supported.
7704
7705 *************************************************************/
7706
7707static void waixing_g_chr_cb( running_machine &machine, int start, int bank, int source )
7708{
7709   int chr_src = (bank < 0x08) ? CHRRAM : CHRROM;
7710   chr1_x(machine, start, bank, chr_src);
7711}
7712
7713static void waixing_g_set_chr( running_machine &machine, int chr_base, int chr_mask )
7714{
7715   nes_state *state = machine.driver_data<nes_state>();
7716   UINT8 chr_page = (state->m_mmc_latch1 & 0x80) >> 5;
7717
7718   state->m_mmc3_chr_cb(machine, chr_page ^ 0, chr_base | (state->m_mmc_vrom_bank[0] & chr_mask), state->m_mmc_chr_source);
7719   state->m_mmc3_chr_cb(machine, chr_page ^ 1, chr_base | (state->m_mmc_vrom_bank[6] & chr_mask), state->m_mmc_chr_source);
7720   state->m_mmc3_chr_cb(machine, chr_page ^ 2, chr_base | (state->m_mmc_vrom_bank[1] & chr_mask), state->m_mmc_chr_source);
7721   state->m_mmc3_chr_cb(machine, chr_page ^ 3, chr_base | (state->m_mmc_vrom_bank[7] & chr_mask), state->m_mmc_chr_source);
7722   state->m_mmc3_chr_cb(machine, chr_page ^ 4, chr_base | (state->m_mmc_vrom_bank[2] & chr_mask), state->m_mmc_chr_source);
7723   state->m_mmc3_chr_cb(machine, chr_page ^ 5, chr_base | (state->m_mmc_vrom_bank[3] & chr_mask), state->m_mmc_chr_source);
7724   state->m_mmc3_chr_cb(machine, chr_page ^ 6, chr_base | (state->m_mmc_vrom_bank[4] & chr_mask), state->m_mmc_chr_source);
7725   state->m_mmc3_chr_cb(machine, chr_page ^ 7, chr_base | (state->m_mmc_vrom_bank[5] & chr_mask), state->m_mmc_chr_source);
7726}
7727
7728static WRITE8_HANDLER( waixing_g_w )
7729{
7730   nes_state *state = space->machine().driver_data<nes_state>();
7731   UINT8 MMC3_helper, cmd;
7732   LOG_MMC(("waixing_g_w, offset: %04x, data: %02x\n", offset, data));
7733
7734   switch (offset & 0x6001)
7735   {
7736      case 0x0000:
7737         MMC3_helper = state->m_mmc_latch1 ^ data;
7738         state->m_mmc_latch1 = data;
7739
7740         /* Has PRG Mode changed? */
7741         if (MMC3_helper & 0x40)
7742            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
7743
7744         /* Has CHR Mode changed? */
7745         if (MMC3_helper & 0x80)
7746            waixing_g_set_chr(space->machine(), state->m_mmc_chr_base, state->m_mmc_chr_mask);
7747         break;
7748
7749      case 0x0001:
7750         cmd = state->m_mmc_latch1 & 0x0f;
7751         switch (cmd)
7752         {
7753         case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
7754         case 2: case 3: case 4: case 5:
7755            state->m_mmc_vrom_bank[cmd] = data;
7756            waixing_g_set_chr(space->machine(), state->m_mmc_chr_base, state->m_mmc_chr_mask);
7757            break;
7758         case 6:
7759         case 7:
7760         case 8:
7761         case 9:
7762            state->m_mmc_prg_bank[cmd - 6] = data;
7763            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
7764            break;
7765         case 0x0a: case 0x0b:
7766            state->m_mmc_vrom_bank[cmd - 4] = data;
7767            waixing_g_set_chr(space->machine(), state->m_mmc_chr_base, state->m_mmc_chr_mask);
7768            break;
7769         }
7770         break;
7771
7772      default:
7773         waixing_a_w(space, offset, data);
7774         break;
7775   }
7776}
7777
7778/*************************************************************
7779
7780 Waixing Board Type H
7781
7782 Games: Ying Xiong Yuan Yi Jing Chuan Qi, Yong Zhe Dou E
7783 Long - Dragon Quest VII
7784
7785 MMC3 clone. More info to come.
7786
7787 iNES: mapper 245
7788
7789 In MESS: Supported.
7790
7791 *************************************************************/
7792
7793static void waixing_h_chr_cb( running_machine &machine, int start, int bank, int source )
7794{
7795   if (source == CHRROM)
7796      chr1_x(machine, start, bank, source);
7797}
7798
7799static WRITE8_HANDLER( waixing_h_w )
7800{
7801   nes_state *state = space->machine().driver_data<nes_state>();
7802   UINT8 cmd;
7803   LOG_MMC(("waixing_h_w, offset: %04x, data: %02x\n", offset, data));
7804
7805   switch (offset & 0x6001)
7806   {
7807      case 0x0001:
7808         cmd = state->m_mmc3_latch & 0x07;
7809         switch (cmd)
7810         {
7811         case 0:    // in this case we set prg_base in addition to state->m_mmc_vrom_bank!
7812            state->m_mmc_prg_base = (data << 5) & 0x40;
7813            state->m_mmc_prg_mask = 0x3f;
7814            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
7815            txrom_w(space, offset, data);
7816         default:
7817            txrom_w(space, offset, data);
7818            break;
7819         }
7820         break;
7821
7822      case 0x2001:
7823         break;
7824
7825      default:
7826         txrom_w(space, offset, data);
7827         break;
7828   }
7829}
7830
7831/*************************************************************
7832
7833 Waixing San Guo Zhi Board
7834
7835 Games: San Guo Zhi
7836
7837 This board uses Konami IRQ
7838
7839 iNES: mapper 252
7840
7841 In MESS: Unsupported.
7842
7843 *************************************************************/
7844
7845static WRITE8_HANDLER( waixing_sgz_w )
7846{
7847   nes_state *state = space->machine().driver_data<nes_state>();
7848   UINT8 mmc_helper, bank;
7849   LOG_MMC(("waixing_sgz_w, offset: %04x, data: %02x\n", offset, data));
7850
7851   switch (offset & 0x7000)
7852   {
7853      case 0x0000:
7854         prg8_89(space->machine(), data);
7855         break;
7856      case 0x2000:
7857         prg8_ab(space->machine(), data);
7858         break;
7859      case 0x3000:
7860      case 0x4000:
7861      case 0x5000:
7862      case 0x6000:
7863         bank = ((offset & 0x7000) - 0x3000) / 0x0800 + ((offset & 0x0008) >> 3);
7864         mmc_helper = offset & 0x04;
7865         if (mmc_helper)
7866            state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0x0f) | ((data & 0x0f) << 4);
7867         else
7868            state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0xf0) | (data & 0x0f);
7869         chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], CHRROM);
7870         break;
7871      case 0x7000:
7872         switch (offset & 0x0c)
7873         {
7874         case 0x00:
7875            state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0xf0) | (data & 0x0f);
7876            break;
7877         case 0x04:
7878            state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0x0f) | ((data & 0x0f) << 4);
7879            break;
7880         case 0x08:
7881            state->m_IRQ_enable = data & 0x02;
7882            state->m_IRQ_enable_latch = data & 0x01;
7883            if (data & 0x02)
7884               state->m_IRQ_count = state->m_IRQ_count_latch;
7885            break;
7886         case 0x0c:
7887            state->m_IRQ_enable = state->m_IRQ_enable_latch;
7888            break;
7889         }
7890         break;
7891   }
7892}
7893
7894
7895/*************************************************************
7896
7897 Waixing San Guo Zhong Lie Zhuan Board
7898
7899 Games: Fan Kong Jing Ying, San Guo Zhong Lie Zhuan, Xing
7900 Ji Zheng Ba
7901
7902 iNES: mapper 178
7903
7904 In MESS: Supported.
7905
7906 *************************************************************/
7907
7908static WRITE8_HANDLER( waixing_sgzlz_l_w )
7909{
7910   nes_state *state = space->machine().driver_data<nes_state>();
7911   LOG_MMC(("waixing_sgzlz_l_w, offset: %04x, data: %02x\n", offset, data));
7912
7913   switch (offset)
7914   {
7915      case 0x700:
7916         set_nt_mirroring(space->machine(), data ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
7917         break;
7918      case 0x701:
7919         state->m_mmc_latch1 = (state->m_mmc_latch1 & 0x0c) | ((data >> 1) & 0x03);
7920         prg32(space->machine(), state->m_mmc_latch1);
7921         break;
7922      case 0x702:
7923         state->m_mmc_latch1 = (state->m_mmc_latch1 & 0x03) | ((data << 2) & 0x0c);
7924         break;
7925   }
7926}
7927
7928/*************************************************************
7929
7930 Waixing Final Fantasy V Board
7931
7932 Games: Darkseed, Digital Dragon, Final Fantasy V, Pocket
7933 Monster Red
7934
7935 iNES: mapper 164
7936
7937 In MESS: Supported.
7938
7939 *************************************************************/
7940
7941static WRITE8_HANDLER( waixing_ffv_l_w )
7942{
7943   nes_state *state = space->machine().driver_data<nes_state>();
7944   UINT8 mmc_helper;
7945   LOG_MMC(("waixing_ffv_l_w, offset: %04x, data: %02x\n", offset, data));
7946   offset += 0x100; /* the checks work better on addresses */
7947
7948   if (0x1000 == (offset & 0x1200))
7949   {
7950      state->m_mmc_reg[BIT(offset, 8)] = data;
7951      mmc_helper = BIT(state->m_mmc_reg[1], 0) << 5;
7952      switch (state->m_mmc_reg[0] & 0x70)
7953      {
7954         case 0x00:
7955         case 0x20:
7956         case 0x40:
7957         case 0x60:
7958            prg16_89ab(space->machine(), mmc_helper | ((state->m_mmc_reg[0] >> 1) & 0x10) | (state->m_mmc_reg[0] & 0x0f));
7959            prg16_cdef(space->machine(), mmc_helper & 0x1f);
7960            break;
7961         case 0x50:
7962            prg32(space->machine(), (mmc_helper >> 1) | (state->m_mmc_reg[0] & 0x0f));
7963            break;
7964         case 0x70:
7965            prg16_89ab(space->machine(), mmc_helper | ((state->m_mmc_reg[0] << 1) & 0x10) | (state->m_mmc_reg[0] & 0x0f));
7966            prg16_cdef(space->machine(), mmc_helper & 0x1f);
7967            break;
7968      }
7969   }
7970}
7971
7972/*************************************************************
7973
7974 Waixing Zhan Shi Board
7975
7976 Games: Wai Xing Zhan Shi
7977
7978 Simple mapper: writes to 0x8000-0xffff sets prg32 banks to
7979 (offset>>3)&f. written data&3 sets the mirroring (with
7980 switched high/low compared to the standard one).
7981
7982 A crc check is required to support Dragon Quest VIII (which
7983 uses a slightly different board)
7984
7985 iNES: mapper 242
7986
7987 In MESS: Supported.
7988
7989 *************************************************************/
7990
7991static WRITE8_HANDLER( waixing_zs_w )
7992{
7993   LOG_MMC(("waixing_zs_w, offset: %04x, data: %02x\n", offset, data));
7994
7995   prg32(space->machine(), offset >> 3);
7996
7997   switch (data & 0x03)
7998   {
7999      case 0: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
8000      case 1: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
8001      case 2: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
8002      case 3: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
8003   }
8004}
8005
8006/*************************************************************
8007
8008 Waixing Dragon Quest VIII Board
8009
8010 Games: Dragon Quest VIII
8011
8012 Simple mapper: writes to 0x8000-0xffff sets prg32 banks to
8013 (offset>>3)&f.
8014
8015 iNES: mapper 242
8016
8017 In MESS: Supported.
8018
8019 *************************************************************/
8020
8021static WRITE8_HANDLER( waixing_dq8_w )
8022{
8023   LOG_MMC(("waixing_dq8_w, offset: %04x, data: %02x\n", offset, data));
8024
8025   prg32(space->machine(), offset >> 3);
8026}
8027
8028
8029/*************************************************************
8030
8031 Waixing PS2 board
8032
8033 Games: Bao Xiao Tien Guo, Bio Hazard, Pokemon Gold, Subor (R)
8034
8035 iNES: mapper 15
8036
8037 In MESS: Supported
8038
8039 *************************************************************/
8040
8041static WRITE8_HANDLER( waixing_ps2_w )
8042{
8043   UINT8 map15_flip = (data & 0x80) >> 7;
8044   UINT8 map15_helper = (data & 0x7f) << 1;
8045
8046   LOG_MMC(("waixing_ps2_w, offset: %04x, data: %02x\n", offset, data));
8047
8048   set_nt_mirroring(space->machine(), BIT(data, 6) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8049
8050   switch (offset & 0x0fff)
8051   {
8052      case 0x000:
8053         prg8_89(space->machine(), (map15_helper + 0) ^ map15_flip);
8054         prg8_ab(space->machine(), (map15_helper + 1) ^ map15_flip);
8055         prg8_cd(space->machine(), (map15_helper + 2) ^ map15_flip);
8056         prg8_ef(space->machine(), (map15_helper + 3) ^ map15_flip);
8057         break;
8058      case 0x001:
8059         map15_helper |= map15_flip;
8060         prg8_89(space->machine(), map15_helper);
8061         prg8_ab(space->machine(), map15_helper + 1);
8062         prg8_cd(space->machine(), map15_helper + 1);
8063         prg8_ef(space->machine(), map15_helper + 1);
8064         break;
8065      case 0x002:
8066         map15_helper |= map15_flip;
8067         prg8_89(space->machine(), map15_helper);
8068         prg8_ab(space->machine(), map15_helper);
8069         prg8_cd(space->machine(), map15_helper);
8070         prg8_ef(space->machine(), map15_helper);
8071         break;
8072      case 0x003:
8073         map15_helper |= map15_flip;
8074         prg8_89(space->machine(), map15_helper);
8075         prg8_ab(space->machine(), map15_helper + 1);
8076         prg8_cd(space->machine(), map15_helper);
8077         prg8_ef(space->machine(), map15_helper + 1);
8078         break;
8079   }
8080}
8081
8082/*************************************************************
8083
8084 Waixing Board with Security Chip
8085
8086 Games: Duo Bao Xiao Ying Hao - Guang Ming yu An Hei Chuan Shuo,
8087 Myth Struggle, San Shi Liu Ji, Shui Hu Zhuan
8088
8089 MMC3 clone
8090
8091 iNES: mapper 249
8092
8093 In MESS: Partially Supported.
8094
8095 *************************************************************/
8096
8097static void waixing_sec_prg_cb( running_machine &machine, int start, int bank )
8098{
8099   nes_state *state = machine.driver_data<nes_state>();
8100
8101   if (state->m_mmc_reg[0])
8102      bank = ((bank & 0x01)) | ((bank >> 3) & 0x02) | ((bank >> 1) & 0x04) | ((bank << 2) & 0x18);
8103
8104   prg8_x(machine, start, bank);
8105}
8106
8107static void waixing_sec_chr_cb( running_machine &machine, int start, int bank, int source )
8108{
8109   nes_state *state = machine.driver_data<nes_state>();
8110
8111   if (state->m_mmc_reg[0])
8112      bank = ((bank & 0x03)) | ((bank >> 1) & 0x04) | ((bank >> 4) & 0x08) |
8113            ((bank >> 2) & 0x10) | ((bank << 3) & 0x20) | ((bank << 2) & 0xc0);
8114
8115   chr1_x(machine, start, bank, source);
8116}
8117
8118static WRITE8_HANDLER( waixing_sec_l_w )
8119{
8120   nes_state *state = space->machine().driver_data<nes_state>();
8121   LOG_MMC(("waixing_sec_l_w, offset: %04x, data: %02x\n", offset, data));
8122
8123   offset += 0x100;
8124
8125   if (offset == 0x1000)
8126   {
8127      state->m_mmc_reg[0] = data & 0x02;
8128      mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
8129      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
8130   }
8131}
8132
8133/*************************************************************
8134
8135 Waixing SH2 Board
8136
8137 Games: Fire Emblem (C) and Fire Emblem Gaiden (C)
8138
8139 MMC3 clone with different access to CHR
8140
8141 iNES: mapper 165
8142
8143 In MESS: Partially Supported.
8144
8145 *************************************************************/
8146
8147static void waixing_sh2_chr_cb( running_machine &machine, int start, int bank, int source )
8148{
8149   nes_state *state = machine.driver_data<nes_state>();
8150
8151   chr4_0(machine, state->m_mmc_reg[0], state->m_mmc_reg[0] ? CHRRAM : CHRROM);
8152   chr4_4(machine, state->m_mmc_reg[1], state->m_mmc_reg[1] ? CHRRAM : CHRROM);
8153}
8154
8155READ8_HANDLER( waixing_sh2_chr_r )
8156{
8157   nes_state *state = space->machine().driver_data<nes_state>();
8158   int bank = offset >> 10;
8159   UINT8 val = state->m_chr_map[bank].access[offset & 0x3ff];   // this would be usual return value
8160   int chr_helper;
8161
8162   switch (offset & 0xff8)
8163   {
8164      case 0xfd0: chr_helper = (bank & 0x4) | 0x0; break;
8165      case 0xfe8: chr_helper = (bank & 0x4) | 0x2; break;
8166      default: return val;
8167   }
8168
8169   state->m_mmc_reg[offset >> 12] = chr_helper;
8170   if (offset & 0x1000)
8171      chr4_4(space->machine(), state->m_mmc_reg[1], state->m_mmc_reg[1] ? CHRRAM : CHRROM);
8172   else
8173      chr4_0(space->machine(), state->m_mmc_reg[0], state->m_mmc_reg[0] ? CHRRAM : CHRROM);
8174
8175   return val;
8176}
8177
8178/*************************************************************
8179
8180 Board UNL-8237
8181
8182 Games: Pocahontas 2
8183
8184 MMC3 clone
8185
8186 In MESS: Supported
8187
8188 *************************************************************/
8189
8190static void unl_8237_prg_cb( running_machine &machine, int start, int bank )
8191{
8192   nes_state *state = machine.driver_data<nes_state>();
8193
8194   if (!(state->m_mmc_reg[0] & 0x80))
8195      prg8_x(machine, start, bank);
8196}
8197
8198static void unl_8237_chr_cb( running_machine &machine, int start, int bank, int source )
8199{
8200   nes_state *state = machine.driver_data<nes_state>();
8201   bank |= ((state->m_mmc_reg[1] << 6) & 0x100);
8202
8203   chr1_x(machine, start, bank, source);
8204}
8205
8206static WRITE8_HANDLER( unl_8237_l_w )
8207{
8208   nes_state *state = space->machine().driver_data<nes_state>();
8209   LOG_MMC(("unl_8237_l_w offset: %04x, data: %02x\n", offset, data));
8210   offset += 0x100;
8211
8212   if (offset == 0x1000)
8213   {
8214      state->m_mmc_reg[0] = data;
8215      if (state->m_mmc_reg[0] & 0x80)
8216      {
8217         if (state->m_mmc_reg[0] & 0x20)
8218            prg32(space->machine(), (state->m_mmc_reg[0] & 0x0f) >> 1);
8219         else
8220         {
8221            prg16_89ab(space->machine(), state->m_mmc_reg[0] & 0x1f);
8222            prg16_cdef(space->machine(), state->m_mmc_reg[0] & 0x1f);
8223         }
8224      }
8225      else
8226         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
8227   }
8228
8229   if (offset == 0x1001)
8230   {
8231      state->m_mmc_reg[1] = data;
8232      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
8233   }
8234}
8235
8236static WRITE8_HANDLER( unl_8237_w )
8237{
8238   nes_state *state = space->machine().driver_data<nes_state>();
8239   static const UINT8 conv_table[8] = {0, 2, 6, 1, 7, 3, 4, 5};
8240   LOG_MMC(("unl_8237_w offset: %04x, data: %02x\n", offset, data));
8241
8242   switch (offset & 0x7000)
8243   {
8244      case 0x0000:
8245      case 0x1000:
8246         set_nt_mirroring(space->machine(), (data | (data >> 7)) & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8247         break;
8248
8249      case 0x2000:
8250      case 0x3000:
8251         state->m_mmc_reg[2] = 1;
8252         data = (data & 0xc0) | conv_table[data & 0x07];
8253         txrom_w(space, 0x0000, data);
8254         break;
8255
8256      case 0x4000:
8257      case 0x5000:
8258         if (state->m_mmc_reg[2])
8259         {
8260            state->m_mmc_reg[2] = 0;
8261            txrom_w(space, 0x0001, data);
8262         }
8263         break;
8264
8265      case 0x6000:
8266         break;
8267
8268      case 0x7000:
8269         txrom_w(space, 0x6001, data);
8270         txrom_w(space, 0x4000, data);
8271         txrom_w(space, 0x4001, data);
8272         break;
8273   }
8274}
8275
8276/*************************************************************
8277
8278 Board UNL-AX5705
8279
8280 Games: Super Mario Bros. Pocker Mali (Crayon Shin-chan pirate hack)
8281
8282 In MESS: Supported
8283
8284 *************************************************************/
8285
8286static void unl_ax5705_set_prg( running_machine &machine )
8287{
8288   nes_state *state = machine.driver_data<nes_state>();
8289   prg8_89(machine, state->m_mmc_prg_bank[0]);
8290   prg8_ab(machine, state->m_mmc_prg_bank[1]);
8291}
8292
8293static WRITE8_HANDLER( unl_ax5705_w )
8294{
8295   nes_state *state = space->machine().driver_data<nes_state>();
8296   UINT8 bank;
8297   LOG_MMC(("unl_ax5705_w offset: %04x, data: %02x\n", offset, data));
8298
8299   switch (offset & 0x700f)
8300   {
8301      case 0x0000:
8302         state->m_mmc_prg_bank[0] = (data & 0x05) | ((data & 0x08) >> 2) | ((data & 0x02) << 2);
8303         unl_ax5705_set_prg(space->machine());
8304         break;
8305      case 0x0008:
8306         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8307         break;
8308      case 0x2000:
8309         state->m_mmc_prg_bank[1] = (data & 0x05) | ((data & 0x08) >> 2) | ((data & 0x02) << 2);
8310         unl_ax5705_set_prg(space->machine());
8311         break;
8312         /* CHR banks 0, 1, 4, 5 */
8313      case 0x2008:
8314      case 0x200a:
8315      case 0x4008:
8316      case 0x400a:
8317         bank = ((offset & 0x4000) ? 4 : 0) + ((offset & 0x0002) ? 1 : 0);
8318         state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0xf0) | (data & 0x0f);
8319         chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], CHRROM);
8320         break;
8321      case 0x2009:
8322      case 0x200b:
8323      case 0x4009:
8324      case 0x400b:
8325         bank = ((offset & 0x4000) ? 4 : 0) + ((offset & 0x0002) ? 1 : 0);
8326         state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0x0f) | ((data & 0x04) << 3) | ((data & 0x02) << 5) | ((data & 0x09) << 4);
8327         chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], CHRROM);
8328         break;
8329         /* CHR banks 2, 3, 6, 7 */
8330      case 0x4000:
8331      case 0x4002:
8332      case 0x6000:
8333      case 0x6002:
8334         bank = 2 + ((offset & 0x2000) ? 4 : 0) + ((offset & 0x0002) ? 1 : 0);
8335         state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0xf0) | (data & 0x0f);
8336         chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], CHRROM);
8337         break;
8338      case 0x4001:
8339      case 0x4003:
8340      case 0x6001:
8341      case 0x6003:
8342         bank = 2 + ((offset & 0x2000) ? 4 : 0) + ((offset & 0x0002) ? 1 : 0);
8343         state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0x0f) | ((data & 0x04) << 3) | ((data & 0x02) << 5) | ((data & 0x09) << 4);
8344         chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], CHRROM);
8345         break;
8346   }
8347}
8348
8349/*************************************************************
8350
8351 Board UNL-CC-21
8352
8353 Games: Mi Hun Che
8354
8355 In MESS: Supported
8356
8357 *************************************************************/
8358
8359static WRITE8_HANDLER( unl_cc21_w )
8360{
8361   LOG_MMC(("unl_cc21_w offset: %04x, data: %02x\n", offset, data));
8362
8363   set_nt_mirroring(space->machine(), BIT(data, 1) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
8364   chr8(space->machine(), (offset & 0x01), CHRROM);
8365}
8366
8367/*************************************************************
8368
8369 Board UNL-KOF97
8370
8371 Games: King of Fighters 97 (Rex Soft)
8372
8373 MMC3 clone
8374
8375 In MESS: Not working
8376
8377 *************************************************************/
8378
8379static UINT8 unl_kof97_unscramble( UINT8 data )
8380{
8381   return ((data >> 1) & 0x01) | ((data >> 4) & 0x02) | ((data << 2) & 0x04) | ((data >> 0) & 0xd8) | ((data << 3) & 0x20);
8382}
8383
8384static WRITE8_HANDLER( unl_kof97_w )
8385{
8386   LOG_MMC(("unl_kof97_w offset: %04x, data: %02x\n", offset, data));
8387
8388   /* Addresses 0x9000, 0xa000, 0xd000 & 0xf000 behaves differently than MMC3 */
8389   if (offset == 0x1000)
8390   {
8391      data = unl_kof97_unscramble(data);
8392      txrom_w(space, 0x0001, data);
8393   }
8394   else if (offset == 0x2000)
8395   {
8396      data = unl_kof97_unscramble(data);
8397      txrom_w(space, 0x0000, data);
8398   }
8399   else if (offset == 0x5000)
8400   {
8401      data = unl_kof97_unscramble(data);
8402      txrom_w(space, 0x4001, data);
8403   }
8404   else if (offset == 0x7000)
8405   {
8406      data = unl_kof97_unscramble(data);
8407      txrom_w(space, 0x6001, data);
8408   }
8409   else      /* Other addresses behaves like MMC3, up to unscrambling data */
8410   {
8411      switch (offset & 0x6001)
8412      {
8413         case 0x0000:
8414         case 0x0001:
8415         case 0x4000:
8416         case 0x4001:
8417         case 0x6000:
8418         case 0x6001:
8419         case 0x2000:   /* are these ever called?!? */
8420         case 0x2001:
8421            data = unl_kof97_unscramble(data);
8422            txrom_w(space, offset, data);
8423            break;
8424      }
8425   }
8426}
8427
8428/*************************************************************
8429
8430 Board UNL-T-230
8431
8432 Games: Dragon Ball Z IV (Unl)
8433
8434 In MESS: Supported
8435
8436 *************************************************************/
8437
8438static WRITE8_HANDLER( unl_t230_w )
8439{
8440   nes_state *state = space->machine().driver_data<nes_state>();
8441   UINT8 bank;
8442   LOG_MMC(("unl_t230_w offset: %04x, data: %02x\n", offset, data));
8443
8444   switch (offset & 0x700c)
8445   {
8446      case 0x0000:
8447         break;
8448      case 0x2000:
8449         prg16_89ab(space->machine(), data);
8450         break;
8451
8452      // the part below works like VRC-2. how was the original board wired up?
8453      // was there a VRC2? if so, we can use VRC-2 and add proper pin settings to xml!
8454      case 0x1000:
8455      case 0x1004:
8456      case 0x1008:
8457      case 0x100c:
8458         switch (data & 0x03)
8459         {
8460         case 0x00: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
8461         case 0x01: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
8462         case 0x02: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
8463         case 0x03: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
8464         }
8465         break;
8466
8467      case 0x3000:
8468      case 0x3004:
8469      case 0x3008:
8470      case 0x300c:
8471      case 0x4000:
8472      case 0x4004:
8473      case 0x4008:
8474      case 0x400c:
8475      case 0x5000:
8476      case 0x5004:
8477      case 0x5008:
8478      case 0x500c:
8479      case 0x6000:
8480      case 0x6004:
8481      case 0x6008:
8482      case 0x600c:
8483         bank = ((offset & 0x7000) - 0x3000) / 0x0800 + ((offset & 0x0008) >> 2);
8484         if (offset & 0x0004)
8485            state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0x0f) | (data << 4);
8486         else
8487            state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0xf0) | (data & 0x0f);
8488
8489         chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], state->m_mmc_chr_source);
8490         break;
8491      case 0x7000:
8492         state->m_IRQ_count_latch &= ~0x0f;
8493         state->m_IRQ_count_latch |= data & 0x0f;
8494         break;
8495      case 0x7004:
8496         state->m_IRQ_count_latch &= ~0xf0;
8497         state->m_IRQ_count_latch |= (data << 4) & 0xf0;
8498         break;
8499      case 0x7008:
8500         state->m_IRQ_mode = data & 0x04;   // currently not implemented: 0 = prescaler mode / 1 = CPU mode
8501         state->m_IRQ_enable = data & 0x02;
8502         state->m_IRQ_enable_latch = data & 0x01;
8503         if (data & 0x02)
8504            state->m_IRQ_count = state->m_IRQ_count_latch;
8505         break;
8506
8507      default:
8508         logerror("unl_t230_w uncaught offset: %04x value: %02x\n", offset, data);
8509         break;
8510   }
8511}
8512
8513/*************************************************************
8514
8515 Bootleg Board for KOF96
8516
8517 Games: The King of Fighters 96, Sonic 3D Blast 6, Street
8518 Fighter Zero 2
8519
8520 MMC3 clone
8521
8522 iNES: mapper 187
8523
8524 In MESS: Preliminary Support.
8525
8526 *************************************************************/
8527
8528static void kof96_prg_cb( running_machine &machine, int start, int bank )
8529{
8530   nes_state *state = machine.driver_data<nes_state>();
8531
8532   if (!(state->m_mmc_reg[0] & 0x80))
8533      prg8_x(machine, start, bank);
8534}
8535
8536static void kof96_chr_cb( running_machine &machine, int start, int bank, int source )
8537{
8538   nes_state *state = machine.driver_data<nes_state>();
8539   UINT8 chr_page = (state->m_mmc_latch1 & 0x80) >> 5;
8540
8541   if ((start & 0x04) == chr_page)
8542      bank |= 0x100;
8543
8544   chr1_x(machine, start, bank, source);
8545}
8546
8547static WRITE8_HANDLER( kof96_l_w )
8548{
8549   nes_state *state = space->machine().driver_data<nes_state>();
8550   UINT8 new_bank;
8551   LOG_MMC(("kof96_l_w, offset: %04x, data: %02x\n", offset, data));
8552   offset += 0x100;
8553
8554   if (offset == 0x1000)
8555   {
8556      state->m_mmc_reg[0] = data;
8557
8558      if (state->m_mmc_reg[0] & 0x80)
8559      {
8560         new_bank = (state->m_mmc_reg[0] & 0x1f);
8561
8562         if (state->m_mmc_reg[0] & 0x20)
8563            prg32(space->machine(), new_bank >> 2);
8564         else
8565         {
8566            prg16_89ab(space->machine(), new_bank);
8567            prg16_cdef(space->machine(), new_bank);
8568         }
8569      }
8570      else
8571         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
8572   }
8573
8574   if (offset >= 0x1000)
8575   {
8576      switch (data & 0x03)
8577      {
8578         case 0x00:
8579         case 0x01:
8580            state->m_mmc_reg[1] = 0x83;
8581            break;
8582         case 0x02:
8583            state->m_mmc_reg[1] = 0x42;
8584            break;
8585         case 0x03:
8586            state->m_mmc_reg[1] = 0x00;
8587            break;
8588      }
8589
8590   }
8591
8592   if (!state->m_mmc_reg[3] && offset > 0x1000)
8593   {
8594      state->m_mmc_reg[3] = 1;
8595      space->write_byte(0x4017, 0x40);
8596   }
8597}
8598
8599static READ8_HANDLER( kof96_l_r )
8600{
8601   nes_state *state = space->machine().driver_data<nes_state>();
8602   LOG_MMC(("kof96_l_r, offset: %04x\n", offset));
8603   offset += 0x100;
8604
8605   if (!(offset < 0x1000))
8606      return state->m_mmc_reg[1];
8607   else
8608      return 0;
8609}
8610
8611static WRITE8_HANDLER( kof96_w )
8612{
8613   nes_state *state = space->machine().driver_data<nes_state>();
8614   LOG_MMC(("kof96_w, offset: %04x, data: %02x\n", offset, data));
8615
8616   switch (offset & 0x6003)
8617   {
8618      case 0x0000:
8619         state->m_mmc_reg[2] = 1;
8620         txrom_w(space, 0x0000, data);
8621         break;
8622
8623      case 0x0001:
8624         if (state->m_mmc_reg[2])
8625            txrom_w(space, 0x0001, data);
8626         break;
8627
8628      case 0x0002:
8629         break;
8630
8631      case 0x0003:
8632         state->m_mmc_reg[2] = 0;
8633
8634         if (data == 0x28)
8635            prg8_cd(space->machine(), 0x17);
8636         else if (data == 0x2a)
8637            prg8_ab(space->machine(), 0x0f);
8638         break;
8639
8640      default:
8641         txrom_w(space, offset, data);
8642         break;
8643   }
8644}
8645
8646/*************************************************************
8647
8648 Bootleg Board for MK2
8649
8650 Games: Mortal Kombat II, Street Fighter III, Super Mario
8651 Kart Rider
8652
8653 This board uses an IRQ system very similar to MMC3. We indeed
8654 use mapper4_irq, but there is some small glitch!
8655
8656 iNES: mapper 91
8657
8658 In MESS: Supported.
8659
8660 *************************************************************/
8661
8662static WRITE8_HANDLER( mk2_m_w )
8663{
8664   nes_state *state = space->machine().driver_data<nes_state>();
8665   LOG_MMC(("mk2_m_w, offset: %04x, data: %02x\n", offset, data));
8666
8667   switch (offset & 0x1000)
8668   {
8669      case 0x0000:
8670         switch (offset & 0x03)
8671         {
8672         case 0x00: chr2_0(space->machine(), data, CHRROM); break;
8673         case 0x01: chr2_2(space->machine(), data, CHRROM); break;
8674         case 0x02: chr2_4(space->machine(), data, CHRROM); break;
8675         case 0x03: chr2_6(space->machine(), data, CHRROM); break;
8676         }
8677         break;
8678      case 0x1000:
8679         switch (offset & 0x03)
8680         {
8681         case 0x00: prg8_89(space->machine(), data); break;
8682         case 0x01: prg8_ab(space->machine(), data); break;
8683         case 0x02: state->m_IRQ_enable = 0; state->m_IRQ_count = 0; break;
8684         case 0x03: state->m_IRQ_enable = 1; state->m_IRQ_count = 7; break;
8685         }
8686         break;
8687      default:
8688         logerror("mk2_m_w uncaught addr: %04x value: %02x\n", offset + 0x6000, data);
8689         break;
8690   }
8691}
8692
8693/*************************************************************
8694
8695 Bootleg Board N625092
8696
8697 Games: 400 in 1, 700 in 1, 1000 in 1
8698
8699 iNES: mapper 221
8700
8701 In MESS: Supported.
8702
8703 *************************************************************/
8704
8705static void n625092_set_prg( running_machine &machine, UINT8 reg1, UINT8 reg2 )
8706{
8707   UINT8 map221_helper1, map221_helper2;
8708
8709   map221_helper1 = !(reg1 & 0x01) ? reg2 :
8710   (reg1 & 0x80) ? reg2 : (reg2 & 0x06) | 0x00;
8711   map221_helper2 = !(reg1 & 0x01) ? reg2 :
8712   (reg1 & 0x80) ? 0x07 : (reg2 & 0x06) | 0x01;
8713
8714   prg16_89ab(machine, map221_helper1 | ((reg1 & 0x70) >> 1));
8715   prg16_cdef(machine, map221_helper2 | ((reg1 & 0x70) >> 1));
8716}
8717
8718static WRITE8_HANDLER( n625092_w )
8719{
8720   nes_state *state = space->machine().driver_data<nes_state>();
8721   LOG_MMC(("n625092_w, offset: %04x, data: %02x\n", offset, data));
8722
8723   if (offset < 0x4000)
8724   {
8725      set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8726      offset = (offset >> 1) & 0xff;
8727
8728      if (state->m_mmc_latch1 != offset)
8729      {
8730         state->m_mmc_latch1 = offset;
8731         n625092_set_prg(space->machine(), state->m_mmc_latch1, state->m_mmc_latch2);
8732      }
8733   }
8734   else
8735   {
8736      offset &= 0x07;
8737
8738      if (state->m_mmc_latch2 != offset)
8739      {
8740         state->m_mmc_latch2 = offset;
8741         n625092_set_prg(space->machine(), state->m_mmc_latch1, state->m_mmc_latch2);
8742      }
8743   }
8744}
8745
8746/*************************************************************
8747
8748 SC-127 Board
8749
8750 Games: Wario World II (Kirby Hack)
8751
8752 iNES: mapper 35
8753
8754 In MESS: Supported
8755
8756 *************************************************************/
8757
8758static void sc127_irq( device_t *device, int scanline, int vblank, int blanked )
8759{
8760   nes_state *state = device->machine().driver_data<nes_state>();
8761
8762   if (scanline < PPU_BOTTOM_VISIBLE_SCANLINE && state->m_IRQ_enable)
8763   {
8764      state->m_IRQ_count--;
8765
8766      if (!blanked && (state->m_IRQ_count == 0))
8767      {
8768         LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
8769                device->machine().primary_screen->vpos(), device->machine().primary_screen->hpos()));
8770         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
8771         state->m_IRQ_enable = 0;
8772      }
8773   }
8774}
8775
8776static WRITE8_HANDLER( sc127_w )
8777{
8778   nes_state *state = space->machine().driver_data<nes_state>();
8779   LOG_MMC(("sc127_w, offset: %04x, data: %02x\n", offset, data));
8780
8781   switch (offset)
8782   {
8783      case 0x0000:
8784         prg8_89(space->machine(), data);
8785         break;
8786      case 0x0001:
8787         prg8_ab(space->machine(), data);
8788         break;
8789      case 0x0002:
8790         //      state->m_mmc_prg_bank[offset & 0x02] = data;
8791         prg8_cd(space->machine(), data);
8792         break;
8793      case 0x1000:
8794      case 0x1001:
8795      case 0x1002:
8796      case 0x1003:
8797      case 0x1004:
8798      case 0x1005:
8799      case 0x1006:
8800      case 0x1007:
8801         //      state->m_mmc_vrom_bank[offset & 0x07] = data;
8802         chr1_x(space->machine(), offset & 0x07, data, CHRROM);
8803         break;
8804      case 0x4002:
8805         state->m_IRQ_enable = 0;
8806         break;
8807      case 0x4003:
8808         state->m_IRQ_enable = 1;
8809         break;
8810      case 0x4005:
8811         state->m_IRQ_count = data;
8812         break;
8813      case 0x5001:
8814         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8815         break;
8816   }
8817}
8818
8819/*************************************************************
8820
8821 Bootleg Board SMB2J
8822
8823 Games: Super Mario Bros. 2 Pirate (LF36)
8824
8825 iNES: mapper 43
8826
8827 In MESS: Supported? The only image I found is not working
8828 (not even in NEStopia).
8829
8830 *************************************************************/
8831
8832static WRITE8_HANDLER( smb2j_w )
8833{
8834   nes_state *state = space->machine().driver_data<nes_state>();
8835   int bank = (((offset >> 8) & 0x03) * 0x20) + (offset & 0x1f);
8836
8837   LOG_MMC(("smb2j_w, offset: %04x, data: %02x\n", offset, data));
8838
8839   set_nt_mirroring(space->machine(), (offset & 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8840
8841   if (offset & 0x0800)
8842   {
8843      if (offset & 0x1000)
8844      {
8845         if (bank * 2 >= state->m_prg_chunks)
8846         {
8847            memory_set_bankptr(space->machine(), "bank3", state->m_wram);
8848            memory_set_bankptr(space->machine(), "bank4", state->m_wram);
8849         }
8850         else
8851         {
8852            LOG_MMC(("smb2j_w, selecting upper 16KB bank of #%02x\n", bank));
8853            prg16_cdef(space->machine(), 2 * bank + 1);
8854         }
8855      }
8856      else
8857      {
8858         if (bank * 2 >= state->m_prg_chunks)
8859         {
8860            memory_set_bankptr(space->machine(), "bank1", state->m_wram);
8861            memory_set_bankptr(space->machine(), "bank2", state->m_wram);
8862         }
8863         else
8864         {
8865            LOG_MMC(("smb2j_w, selecting lower 16KB bank of #%02x\n", bank));
8866            prg16_89ab(space->machine(), 2 * bank);
8867         }
8868      }
8869   }
8870   else
8871   {
8872      if (bank * 2 >= state->m_prg_chunks)
8873      {
8874         memory_set_bankptr(space->machine(), "bank1", state->m_wram);
8875         memory_set_bankptr(space->machine(), "bank2", state->m_wram);
8876         memory_set_bankptr(space->machine(), "bank3", state->m_wram);
8877         memory_set_bankptr(space->machine(), "bank4", state->m_wram);
8878      }
8879      else
8880      {
8881         LOG_MMC(("smb2j_w, selecting 32KB bank #%02x\n", bank));
8882         prg32(space->machine(), bank);
8883      }
8884   }
8885}
8886
8887/*************************************************************
8888
8889 BTL-SMB2B
8890
8891 Games: Super Mario Bros. 2 Pirate (Jpn version of SMB2)
8892
8893 This was marked as Alt. Levels. is it true?
8894
8895 iNES: mapper 50
8896
8897 In MESS: Supported.
8898
8899 *************************************************************/
8900
8901static void smb2jb_irq( device_t *device, int scanline, int vblank, int blanked )
8902{
8903   nes_state *state = device->machine().driver_data<nes_state>();
8904   if (state->m_IRQ_enable)
8905   {
8906      if (state->m_IRQ_count < 0x1000)
8907      {
8908         if ((0x1000 - state->m_IRQ_count) <= 114)
8909            device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
8910         else
8911            state->m_IRQ_count += 114;
8912      }
8913      else
8914         state->m_IRQ_count += 114;
8915
8916      state->m_IRQ_count &= 0xffff;   // according to docs is 16bit counter -> it wraps only after 0xffff
8917   }
8918}
8919
8920static WRITE8_HANDLER( smb2jb_l_w )
8921{
8922   nes_state *state = space->machine().driver_data<nes_state>();
8923   UINT8 prg;
8924   LOG_MMC(("smb2jb_l_w, offset: %04x, data: %02x\n", offset, data));
8925   offset += 0x100;
8926
8927   switch (offset & 0x160)
8928   {
8929      case 0x020:
8930         prg = (data & 0x08) | ((data & 0x06) >> 1) | ((data & 0x01) << 2);
8931         prg8_cd(space->machine(), prg);
8932         break;
8933      case 0x120:
8934         state->m_IRQ_enable = data & 0x01;
8935         break;
8936   }
8937}
8938
8939/* This goes to 0x4020-0x403f */
8940WRITE8_HANDLER( smb2jb_extra_w )
8941{
8942   UINT8 prg;
8943   LOG_MMC(("smb2jb_extra_w, offset: %04x, data: %02x\n", offset, data));
8944
8945   prg = (data & 0x08) | ((data & 0x06) >> 1) | ((data & 0x01) << 2);
8946   prg8_cd(space->machine(), prg);
8947}
8948
8949/*************************************************************
8950
8951 Bootleg Board for Super Fighter III
8952
8953 MMC3 clone
8954
8955 iNES: mapper 197
8956
8957 In MESS: Supported.
8958
8959 *************************************************************/
8960
8961static void unl_sf3_set_chr( running_machine &machine, UINT8 chr_source, int chr_base, int chr_mask )
8962{
8963   nes_state *state = machine.driver_data<nes_state>();
8964   chr4_0(machine, chr_base | ((state->m_mmc_vrom_bank[0] >> 1) & chr_mask), chr_source);
8965   chr2_4(machine, chr_base | (state->m_mmc_vrom_bank[1] & chr_mask), chr_source);
8966   chr2_6(machine, chr_base | (state->m_mmc_vrom_bank[2] & chr_mask), chr_source);
8967}
8968
8969static WRITE8_HANDLER( unl_sf3_w )
8970{
8971   nes_state *state = space->machine().driver_data<nes_state>();
8972   UINT8 mmc_helper, cmd;
8973   LOG_MMC(("unl_sf3_w, offset: %04x, data: %02x\n", offset, data));
8974
8975   switch (offset & 0x6001)
8976   {
8977      case 0x0000:
8978         mmc_helper = state->m_mmc3_latch ^ data;
8979         state->m_mmc3_latch = data;
8980
8981         /* Has PRG Mode changed? */
8982         if (mmc_helper & 0x40)
8983            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
8984
8985         /* Has CHR Mode changed? */
8986         if (mmc_helper & 0x80)
8987            unl_sf3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
8988         break;
8989
8990      case 0x0001:
8991         cmd = state->m_mmc3_latch & 0x0f;
8992         switch (cmd)
8993         {
8994         case 0: case 2: case 4:
8995            state->m_mmc_vrom_bank[cmd >> 1] = data;
8996            unl_sf3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
8997            break;
8998         case 6:
8999         case 7:
9000            state->m_mmc_prg_bank[cmd - 6] = data;
9001            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
9002            break;
9003         }
9004         break;
9005
9006      default:
9007         txrom_w(space, offset, data);
9008         break;
9009   }
9010}
9011
9012/*************************************************************
9013
9014 Bootleg Board for Xiao Zhuan Yuan
9015
9016 Games: Shu Qi Yu - Zhi Li Xiao Zhuan Yuan
9017
9018 Very simple mapper: writes to 0x5ff1 set prg32 (to data>>1),
9019 while writes to 0x5ff2 set chr8
9020
9021 iNES: mapper 176
9022
9023 In MESS: Supported.
9024
9025 *************************************************************/
9026
9027static WRITE8_HANDLER( unl_xzy_l_w )
9028{
9029   LOG_MMC(("unl_xzy_l_w, offset: %04x, data: %02x\n", offset, data));
9030
9031   switch (offset)
9032   {
9033      case 0x1ef1:   /* 0x5ff1 */
9034         prg32(space->machine(), data >> 1);
9035         break;
9036      case 0x1ef2:   /* 0x5ff2 */
9037         chr8(space->machine(), data, CHRROM);
9038         break;
9039   }
9040}
9041
9042/*************************************************************
9043
9044 Board UNL-RACERMATE
9045
9046 In MESS: *VERY* preliminary support. Also, it seems that this
9047 board saves to battery the CHRRAM!!!
9048
9049 *************************************************************/
9050
9051static void racmate_update_banks( running_machine &machine )
9052{
9053   nes_state *state = machine.driver_data<nes_state>();
9054   chr4_4(machine, state->m_mmc_latch1 & 0x0f, state->m_mmc_chr_source);
9055   prg16_89ab(machine, state->m_mmc_latch1 >> 1);
9056}
9057
9058static WRITE8_HANDLER( unl_racmate_w )
9059{
9060   nes_state *state = space->machine().driver_data<nes_state>();
9061   LOG_MMC(("unl_racmate_w offset: %04x, data: %02x\n", offset, data));
9062
9063   if (offset == 0x3000)
9064   {
9065      state->m_mmc_latch1 = data;
9066      racmate_update_banks(space->machine());
9067   }
9068}
9069
9070/*************************************************************
9071
9072        BOOTLEG CART VERSIONS OF FDS GAMES
9073
9074 *************************************************************/
9075
9076/*************************************************************
9077
9078 BTL-SUPERBROS11
9079
9080 Games: Super Mario Bros. 11, Super Mario Bros. 17
9081
9082 This acts basically like a MMC3 with different use of write
9083 address.
9084
9085 iNES: mapper 196
9086
9087 In MESS: Supported.
9088
9089 *************************************************************/
9090
9091static WRITE8_HANDLER( btl_smb11_w )
9092{
9093   LOG_MMC(("btl_smb11_w, offset: %04x, data: %02x\n", offset, data));
9094
9095   txrom_w(space, (offset & 0x6000) | ((offset & 0x04) >> 2), data);
9096}
9097
9098/*************************************************************
9099
9100 BTL-MARIOBABY
9101
9102 Games: Mario Baby, Ai Senshi Nicol
9103
9104 iNES: mapper 42
9105
9106 In MESS: Supported.
9107
9108 *************************************************************/
9109
9110// is the code fine for ai senshi nicol?!?
9111static WRITE8_HANDLER( btl_mariobaby_w )
9112{
9113   nes_state *state = space->machine().driver_data<nes_state>();
9114   LOG_MMC(("btl_mariobaby_w, offset: %04x, data: %02x\n", offset, data));
9115
9116   if (offset >= 0x7000)
9117   {
9118      switch (offset & 0x03)
9119      {
9120         case 0x00:
9121            prg8_67(space->machine(), data);
9122            break;
9123         case 0x01:
9124            set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9125            break;
9126         case 0x02:
9127            /* Check if IRQ is being enabled */
9128            if (!state->m_IRQ_enable && (data & 0x02))
9129            {
9130               state->m_IRQ_enable = 1;
9131               state->m_irq_timer->adjust(downcast<cpu_device *>(state->m_maincpu)->cycles_to_attotime(24576));
9132            }
9133            if (!(data & 0x02))
9134            {
9135               state->m_IRQ_enable = 0;
9136               state->m_irq_timer->adjust(attotime::never);
9137            }
9138            break;
9139      }
9140   }
9141}
9142
9143/*************************************************************
9144
9145 BTL-SMB2A
9146
9147 Games: Super Mario Bros. 2 Pirate (Jpn version of SMB2)
9148
9149 iNES: mapper 40
9150
9151 In MESS: Supported.
9152
9153 *************************************************************/
9154
9155static void btl_smb2a_irq( device_t *device, int scanline, int vblank, int blanked )
9156{
9157   nes_state *state = device->machine().driver_data<nes_state>();
9158
9159   if (state->m_IRQ_enable)
9160   {
9161      if ((0xfff - state->m_IRQ_count) <= 114)
9162      {
9163         state->m_IRQ_count = (state->m_IRQ_count + 1) & 0xfff;
9164         state->m_IRQ_enable = 0;
9165         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
9166      }
9167      else
9168         state->m_IRQ_count += 114;
9169   }
9170}
9171
9172static WRITE8_HANDLER( btl_smb2a_w )
9173{
9174   nes_state *state = space->machine().driver_data<nes_state>();
9175   LOG_MMC(("btl_smb2a_w, offset: %04x, data: %02x\n", offset, data));
9176
9177   switch (offset & 0x6000)
9178   {
9179      case 0x0000:
9180         state->m_IRQ_enable = 0;
9181         state->m_IRQ_count = 0;
9182         break;
9183      case 0x2000:
9184         state->m_IRQ_enable = 1;
9185         break;
9186      case 0x6000:
9187         prg8_cd(space->machine(), data);
9188         break;
9189   }
9190}
9191
9192/*************************************************************
9193
9194 WHIRLWIND-2706
9195
9196 Games: Meikyuu Jiin Dababa (FDS conversion)
9197
9198 iNES: mapper 108
9199
9200 In MESS: Supported.
9201
9202 *************************************************************/
9203
9204static WRITE8_HANDLER( whirl2706_w )
9205{
9206   LOG_MMC(("whirl2706_w, offset: %04x, data: %02x\n", offset, data));
9207   prg8_67(space->machine(), data);
9208}
9209
9210/*************************************************************
9211
9212 Bootleg Board used for FDS conversion
9213
9214 Games: Tobidase Daisakusen (FDS conversion)
9215
9216 iNES: mapper 120
9217
9218 In MESS: Partially Supported.
9219
9220 *************************************************************/
9221
9222static WRITE8_HANDLER( btl_tobi_l_w )
9223{
9224   LOG_MMC(("btl_tobi_l_w, offset: %04x, data: %02x\n", offset, data));
9225   offset += 0x100;
9226
9227   if ((offset & 0x43c0) == 0x41c0)
9228      prg8_67(space->machine(), data & 0x07);
9229}
9230
9231/*************************************************************
9232
9233 BTL-SMB3
9234
9235 Games: Super Mario Bros. 3 Pirate
9236
9237 iNES: mapper 106
9238
9239 In MESS: Supported.
9240
9241 *************************************************************/
9242
9243static void btl_smb3_irq( device_t *device, int scanline, int vblank, int blanked )
9244{
9245   nes_state *state = device->machine().driver_data<nes_state>();
9246
9247   if (state->m_IRQ_enable)
9248   {
9249      if ((0xffff - state->m_IRQ_count) < 114)
9250      {
9251         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
9252         state->m_IRQ_enable = 0;
9253      }
9254
9255      state->m_IRQ_count = (state->m_IRQ_count + 114) & 0xffff;
9256   }
9257}
9258
9259static WRITE8_HANDLER( btl_smb3_w )
9260{
9261   nes_state *state = space->machine().driver_data<nes_state>();
9262   LOG_MMC(("btl_smb3_w, offset: %04x, data: %02x\n", offset, data));
9263   switch (offset & 0x0f)
9264   {
9265      case 0x00:
9266      case 0x02:
9267         chr1_x(space->machine(), offset & 0x07, data & 0xfe, CHRROM);
9268         break;
9269      case 0x01:
9270      case 0x03:
9271         chr1_x(space->machine(), offset & 0x07, data | 0x01, CHRROM);
9272         break;
9273      case 0x04: case 0x05:
9274      case 0x06: case 0x07:
9275         chr1_x(space->machine(), offset & 0x07, data, CHRROM);
9276         break;
9277      case 0x08:
9278         prg8_89(space->machine(), data | 0x10);
9279         break;
9280      case 0x09:
9281         prg8_ab(space->machine(), data);
9282         break;
9283      case 0x0a:
9284         prg8_cd(space->machine(), data);
9285         break;
9286      case 0x0b:
9287         prg8_ef(space->machine(), data | 0x10);
9288         break;
9289      case 0x0c:
9290         set_nt_mirroring(space->machine(), BIT(data, 0) ?  PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9291         break;
9292      case 0x0d:
9293         state->m_IRQ_count = 0;
9294         state->m_IRQ_enable = 0;
9295         break;
9296      case 0x0e:
9297         state->m_IRQ_count = (state->m_IRQ_count & 0xff00) | data;
9298         break;
9299      case 0x0f:
9300         state->m_IRQ_count = (state->m_IRQ_count & 0x00ff) | (data << 8);
9301         state->m_IRQ_enable = 1;
9302         break;
9303   }
9304}
9305
9306/*************************************************************
9307
9308 BTL-DRAGONNINJA
9309
9310 Games: Dragon Ninja (Bootleg), Super Mario Bros. 8
9311
9312 iNES: mapper 222
9313
9314 In MESS: Unsupported.
9315
9316 *************************************************************/
9317
9318/* Scanline based IRQ ? */
9319static void btl_dn_irq( device_t *device, int scanline, int vblank, int blanked )
9320{
9321   nes_state *state = device->machine().driver_data<nes_state>();
9322   if (scanline < PPU_BOTTOM_VISIBLE_SCANLINE)
9323   {
9324      if (!state->m_IRQ_count || ++state->m_IRQ_count < 240)
9325         return;
9326
9327      state->m_IRQ_count = 0;
9328      LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
9329             device->machine().primary_screen->vpos(), device->machine().primary_screen->hpos()));
9330      device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
9331   }
9332}
9333
9334static WRITE8_HANDLER( btl_dn_w )
9335{
9336   nes_state *state = space->machine().driver_data<nes_state>();
9337   UINT8 bank;
9338   LOG_MMC(("btl_dn_w, offset: %04x, data: %02x\n", offset, data));
9339
9340   switch (offset & 0x7003)
9341   {
9342      case 0x0000:
9343         prg8_89(space->machine(), data);
9344         break;
9345      case 0x1000:
9346         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9347         break;
9348      case 0x2000:
9349         prg8_ab(space->machine(), data);
9350         break;
9351      case 0x3000:
9352      case 0x3002:
9353      case 0x4000:
9354      case 0x4002:
9355      case 0x5000:
9356      case 0x5002:
9357      case 0x6000:
9358      case 0x6002:
9359         bank = ((offset & 0x7000) - 0x3000) / 0x0800 + ((offset & 0x0002) >> 3);
9360         chr1_x(space->machine(), bank, data, CHRROM);
9361         break;
9362      case 0x7000:
9363         state->m_IRQ_count = data;
9364         break;
9365   }
9366}
9367
9368/*************************************************************
9369
9370 BTL-PIKACHUY2K
9371
9372 Games: Pikachu Y2k
9373
9374 iNES: mapper 254
9375
9376 In MESS:
9377
9378 *************************************************************/
9379
9380static WRITE8_HANDLER( btl_pika_y2k_w )
9381{
9382   nes_state *state = space->machine().driver_data<nes_state>();
9383   LOG_MMC(("btl_pika_y2k_w, offset: %04x, data: %02x\n", offset, data));
9384
9385   switch (offset & 0x6001)
9386   {
9387      case 0x2001:
9388         state->m_mmc_latch2 = data;
9389         break;
9390
9391      case 0x2000:
9392         state->m_mmc_reg[0] = 0;
9393      default:
9394         txrom_w(space, offset, data);
9395         break;
9396   }
9397}
9398
9399// strange WRAM usage: it is protected at start, and gets unprotected after the first write to 0xa000
9400static WRITE8_HANDLER( btl_pika_y2k_m_w )
9401{
9402   nes_state *state = space->machine().driver_data<nes_state>();
9403   LOG_MMC(("btl_pika_y2k_m_w, offset: %04x, data: %02x\n", offset, data));
9404
9405   state->m_wram[offset] = data;
9406}
9407
9408static READ8_HANDLER( btl_pika_y2k_m_r )
9409{
9410   nes_state *state = space->machine().driver_data<nes_state>();
9411   LOG_MMC(("btl_pika_y2k_m_r, offset: %04x\n", offset));
9412
9413   return   state->m_wram[offset] ^ (state->m_mmc_latch2 & state->m_mmc_reg[0]);
9414}
9415
9416/*************************************************************
9417
9418          MULTICART
9419
9420 *************************************************************/
9421
9422/*************************************************************
9423
9424 Board BMC-FK23C
9425
9426 In MESS: partially supported (still to sort initial banking
9427 for many games)
9428
9429 *************************************************************/
9430
9431#if 0
9432static void fk23c_prg_cb( running_machine &machine, int start, int bank )
9433{
9434   nes_state *state = machine.driver_data<nes_state>();
9435
9436   if (((state->m_mmc_reg[0] & 0x07) - 3) > 1 && (!(state->m_mmc_reg[3] & 0x02) || start < 2))
9437   {
9438      if (state->m_mmc_reg[0] & 0x03)
9439         bank = (bank & (0x3f >> (state->m_mmc_reg[0] & 0x03))) | (state->m_mmc_reg[1] << 1);
9440
9441      prg8_x(machine, start, bank);
9442   }
9443}
9444
9445static void fk23c_chr_cb( running_machine &machine, int start, int bank, int source )
9446{
9447   nes_state *state = machine.driver_data<nes_state>();
9448
9449   if (!(state->m_mmc_reg[0] & 0x40) && (!(state->m_mmc_reg[3] & 0x02) || (start != 1 && start != 3)))
9450      chr1_x(machine, start, ((state->m_mmc_reg[2] & 0x7f) << 3) | bank, source);
9451}
9452
9453#endif
9454
9455static void fk23c_prg_cb( running_machine &machine, int start, int bank )
9456{
9457   nes_state *state = machine.driver_data<nes_state>();
9458   UINT8 mask = (0x3f >> (state->m_mmc_reg[0] & 0x03));
9459
9460   if ((state->m_mmc_reg[0] & 0x07) < 3)
9461   {
9462      if (!(state->m_mmc_reg[0] & 0x03))
9463         bank = (bank & mask) | ((state->m_mmc_reg[1]  & (0x7f ^ mask)) << 1);
9464
9465      prg8_x(machine, start, bank);
9466   }
9467}
9468
9469static void fk23c_chr_cb( running_machine &machine, int start, int bank, int source )
9470{
9471   nes_state *state = machine.driver_data<nes_state>();
9472
9473   if (!(state->m_mmc_reg[0] & 0x40) && (!(state->m_mmc_reg[3] & 0x02) || (start != 1 && start != 3)))
9474      chr1_x(machine, start, ((state->m_mmc_reg[2] & 0x7f) << 3) | bank, source);
9475}
9476
9477static void fk23c_set_prg( running_machine &machine )
9478{
9479   nes_state *state = machine.driver_data<nes_state>();
9480
9481   if ((state->m_mmc_reg[0] & 0x07) == 4)
9482      prg32(machine, (state->m_mmc_reg[1] & 0x7f) >> 1);
9483   else if ((state->m_mmc_reg[0] & 0x07) == 3)
9484   {
9485      prg16_89ab(machine, state->m_mmc_reg[1] & 0x7f);
9486      prg16_cdef(machine, state->m_mmc_reg[1] & 0x7f);
9487   }
9488   else
9489   {
9490      if (state->m_mmc_reg[3] & 0x02)
9491      {
9492         prg8_cd(machine, state->m_mmc_reg[4]);
9493         prg8_ef(machine, state->m_mmc_reg[5]);
9494      }
9495
9496      mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
9497   }
9498}
9499
9500static void fk23c_set_chr( running_machine &machine )
9501{
9502   nes_state *state = machine.driver_data<nes_state>();
9503
9504   if (state->m_mmc_reg[0] & 0x40)
9505      chr8(machine, state->m_mmc_reg[2] | state->m_mmc_cmd1, state->m_mmc_chr_source);
9506   else
9507   {
9508      if (state->m_mmc_reg[3] & 0x02)
9509      {
9510         int base = (state->m_mmc_reg[2] & 0x7f) << 3;
9511         chr1_x(machine, 1, base | state->m_mmc_reg[6], state->m_mmc_chr_source);
9512         chr1_x(machine, 3, base | state->m_mmc_reg[7], state->m_mmc_chr_source);
9513      }
9514
9515      mmc3_set_chr(machine, state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
9516   }
9517}
9518
9519static WRITE8_HANDLER( fk23c_l_w )
9520{
9521   nes_state *state = space->machine().driver_data<nes_state>();
9522   LOG_MMC(("fk23c_l_w, offset: %04x, data: %02x\n", offset, data));
9523   offset += 0x100;
9524
9525   if (offset >= 0x1000)
9526   {
9527      if (offset & (1 << 4))   // here it should be (4 + state->m_mmc_dipsetting)
9528      {
9529         state->m_mmc_reg[offset & 0x03] = data;
9530
9531         fk23c_set_prg(space->machine());
9532         fk23c_set_chr(space->machine());
9533      }
9534   }
9535}
9536
9537static WRITE8_HANDLER( fk23c_w )
9538{
9539   nes_state *state = space->machine().driver_data<nes_state>();
9540   LOG_MMC(("fk23c_w, offset: %04x, data: %02x\n", offset, data));
9541
9542   if (state->m_mmc_reg[0] & 0x40)
9543   {
9544      if (state->m_mmc_reg[0] & 0x30)
9545         state->m_mmc_cmd1 = 0;
9546      else
9547      {
9548         state->m_mmc_cmd1 = data & 0x03;
9549         fk23c_set_chr(space->machine());
9550      }
9551   }
9552   else
9553   {
9554      switch (offset & 0x6001)
9555      {
9556         case 0x0001:
9557            if ((state->m_mmc_reg[3] & 0x02) && (state->m_mmc3_latch & 0x08))
9558            {
9559               state->m_mmc_reg[4 | (state->m_mmc3_latch & 0x03)] = data;
9560               fk23c_set_prg(space->machine());
9561               fk23c_set_chr(space->machine());
9562            }
9563            else
9564               txrom_w(space, offset, data);
9565            break;
9566
9567         case 0x2000:
9568            set_nt_mirroring(space->machine(), data ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9569            break;
9570
9571         default:
9572            txrom_w(space, offset, data);
9573            break;
9574      }
9575   }
9576}
9577
9578
9579/*************************************************************
9580
9581 Board BMC-64IN1NOREPEAT
9582
9583 Games: 64-in-1 Y2K
9584
9585 In MESS: Supported
9586
9587 *************************************************************/
9588
9589static void bmc_64in1nr_set_prg( running_machine &machine )
9590{
9591   nes_state *state = machine.driver_data<nes_state>();
9592   UINT8 helper1 = (state->m_mmc_reg[1] & 0x1f);
9593   UINT8 helper2 = (helper1 << 1) | ((state->m_mmc_reg[1] & 0x40) >> 6);
9594
9595   if (state->m_mmc_reg[0] & 0x80)
9596   {
9597      if (state->m_mmc_reg[1] & 0x80)
9598         prg32(machine, helper1);
9599      else
9600      {
9601         prg16_89ab(machine, helper2);
9602         prg16_cdef(machine, helper2);
9603      }
9604   }
9605   else
9606      prg16_cdef(machine, helper2);
9607}
9608
9609static WRITE8_HANDLER( bmc_64in1nr_l_w )
9610{
9611   nes_state *state = space->machine().driver_data<nes_state>();
9612   LOG_MMC(("bmc_64in1nr_l_w offset: %04x, data: %02x\n", offset, data));
9613   offset += 0x100;
9614
9615   switch (offset)
9616   {
9617      case 0x1000:
9618      case 0x1001:
9619      case 0x1002:
9620      case 0x1003:
9621         state->m_mmc_reg[offset & 0x03] = data;
9622         bmc_64in1nr_set_prg(space->machine());
9623         chr8(space->machine(), ((state->m_mmc_reg[0] >> 1) & 0x03) | (state->m_mmc_reg[2] << 2), CHRROM);
9624         break;
9625   }
9626   if (offset == 0x1000)   /* reg[0] also sets mirroring */
9627      set_nt_mirroring(space->machine(), BIT(data, 5) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9628}
9629
9630static WRITE8_HANDLER( bmc_64in1nr_w )
9631{
9632   nes_state *state = space->machine().driver_data<nes_state>();
9633   LOG_MMC(("bmc_64in1nr_w offset: %04x, data: %02x\n", offset, data));
9634
9635   state->m_mmc_reg[3] = data;   // reg[3] is currently unused?!?
9636}
9637
9638/*************************************************************
9639
9640 Board BMC-190IN1
9641
9642 Games: 190-in-1
9643
9644 In MESS: Supported
9645
9646 *************************************************************/
9647
9648static WRITE8_HANDLER( bmc_190in1_w )
9649{
9650   LOG_MMC(("bmc_190in1_w offset: %04x, data: %02x\n", offset, data));
9651
9652   set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9653   offset >>= 2;
9654   prg16_89ab(space->machine(), offset);
9655   prg16_cdef(space->machine(), offset);
9656   chr8(space->machine(), offset, CHRROM);
9657}
9658
9659/*************************************************************
9660
9661 Board BMC-A65AS
9662
9663 Games: 3-in-1 (N068)
9664
9665 In MESS: Supported
9666
9667 *************************************************************/
9668
9669static WRITE8_HANDLER( bmc_a65as_w )
9670{
9671   UINT8 helper = (data & 0x30) >> 1;
9672   LOG_MMC(("bmc_a65as_w offset: %04x, data: %02x\n", offset, data));
9673
9674   if (data & 0x80)
9675      set_nt_mirroring(space->machine(), BIT(data, 5) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
9676   else
9677      set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9678
9679   if (data & 0x40)
9680      prg32(space->machine(), data >> 1);
9681   else
9682   {
9683      prg16_89ab(space->machine(), helper | (data & 0x07));
9684      prg16_cdef(space->machine(), helper | 0x07);
9685   }
9686}
9687
9688/*************************************************************
9689
9690 Board BMC-GS2004
9691
9692 Games: Tetris Family 6-in-1
9693
9694 In MESS: Preliminary Support. It also misses WRAM handling
9695 (we need reads from 0x6000-0x7fff)
9696
9697 *************************************************************/
9698
9699static WRITE8_HANDLER( bmc_gs2004_w )
9700{
9701   LOG_MMC(("bmc_gs2004_w offset: %04x, data: %02x\n", offset, data));
9702
9703   prg32(space->machine(), data);
9704}
9705
9706/*************************************************************
9707
9708 Board BMC-GS2013
9709
9710 Games: Tetris Family 12-in-1
9711
9712 In MESS: Preliminary Support. It also misses WRAM handling
9713 (we need reads from 0x6000-0x7fff)
9714
9715 *************************************************************/
9716
9717static WRITE8_HANDLER( bmc_gs2013_w )
9718{
9719   LOG_MMC(("bmc_gs2013_w offset: %04x, data: %02x\n", offset, data));
9720
9721   if (data & 0x08)
9722      prg32(space->machine(), data & 0x09);
9723   else
9724      prg32(space->machine(), data & 0x07);
9725}
9726
9727/*************************************************************
9728
9729 Board BMC-SUPER24IN1SC03
9730
9731 Games: Super 24-in-1
9732
9733 In MESS: Partially Supported
9734
9735 *************************************************************/
9736
9737static void bmc_s24in1sc03_prg_cb( running_machine &machine, int start, int bank )
9738{
9739   nes_state *state = machine.driver_data<nes_state>();
9740   static const UINT8 masks[8] = {0x3f, 0x1f, 0x0f, 0x01, 0x03, 0x00, 0x00, 0x00};
9741   int prg_base = state->m_mmc_reg[1] << 1;
9742   int prg_mask = masks[state->m_mmc_reg[0] & 0x07];
9743
9744   bank = prg_base | (bank & prg_mask);
9745   prg8_x(machine, start, bank);
9746}
9747
9748static void bmc_s24in1sc03_chr_cb( running_machine &machine, int start, int bank, int source )
9749{
9750   nes_state *state = machine.driver_data<nes_state>();
9751   UINT8 chr = BIT(state->m_mmc_reg[0], 5) ? CHRRAM : CHRROM;
9752   int chr_base = (state->m_mmc_reg[2] << 3) & 0xf00;
9753
9754   chr1_x(machine, start, chr_base | bank, chr);
9755}
9756
9757static WRITE8_HANDLER( bmc_s24in1sc03_l_w )
9758{
9759   nes_state *state = space->machine().driver_data<nes_state>();
9760   LOG_MMC(("bmc_s24in1sc03_l_w offset: %04x, data: %02x\n", offset, data));
9761   offset += 0x100;
9762
9763   if (offset == 0x1ff0)
9764   {
9765      state->m_mmc_reg[0] = data;
9766      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
9767      mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
9768   }
9769
9770   if (offset == 0x1ff1)
9771   {
9772      state->m_mmc_reg[1] = data;
9773      mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
9774   }
9775
9776   if (offset == 0x1ff2)
9777   {
9778      state->m_mmc_reg[2] = data;
9779      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
9780   }
9781}
9782
9783/*************************************************************
9784
9785 Board BMC-T-262
9786
9787 Games: 4-in-1 (D-010), 8-in-1 (A-020)
9788
9789 In MESS: Supported
9790
9791 *************************************************************/
9792
9793static WRITE8_HANDLER( bmc_t262_w )
9794{
9795   nes_state *state = space->machine().driver_data<nes_state>();
9796   UINT8 mmc_helper;
9797   LOG_MMC(("bmc_t262_w offset: %04x, data: %02x\n", offset, data));
9798
9799   if (state->m_mmc_latch2 || offset == 0)
9800   {
9801      state->m_mmc_latch1 = (state->m_mmc_latch1 & 0x38) | (data & 0x07);
9802      prg16_89ab(space->machine(), state->m_mmc_latch1);
9803   }
9804   else
9805   {
9806      state->m_mmc_latch2 = 1;
9807      set_nt_mirroring(space->machine(), BIT(data, 1) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9808      mmc_helper = ((offset >> 3) & 0x20) | ((offset >> 2) & 0x18);
9809      state->m_mmc_latch1 = mmc_helper | (state->m_mmc_latch1 & 0x07);
9810      prg16_89ab(space->machine(), state->m_mmc_latch1);
9811      prg16_cdef(space->machine(), mmc_helper | 0x07);
9812   }
9813}
9814
9815/*************************************************************
9816
9817 Board BMC-WS
9818
9819 Games: Super 40-in-1
9820
9821 In MESS: Partially Supported (some games, like Galaxian, have
9822 issues)
9823
9824 *************************************************************/
9825
9826static WRITE8_HANDLER( bmc_ws_m_w )
9827{
9828   nes_state *state = space->machine().driver_data<nes_state>();
9829   UINT8 mmc_helper;
9830   LOG_MMC(("bmc_ws_m_w offset: %04x, data: %02x\n", offset, data));
9831
9832   if (offset < 0x1000)
9833   {
9834      switch (offset & 0x01)
9835      {
9836         case 0:
9837            if (!state->m_mmc_latch1)
9838            {
9839               state->m_mmc_latch1 = data & 0x20;
9840               set_nt_mirroring(space->machine(), BIT(data, 4) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9841               mmc_helper = (~data & 0x08) >> 3;
9842               prg16_89ab(space->machine(), data & ~mmc_helper);
9843               prg16_cdef(space->machine(), data |  mmc_helper);
9844            }
9845            break;
9846         case 1:
9847            if (!state->m_mmc_latch1)
9848            {
9849               chr8(space->machine(), data, CHRROM);
9850            }
9851            break;
9852      }
9853   }
9854}
9855
9856/*************************************************************
9857
9858 BMC-NOVELDIAMOND and BMC-999999in1
9859
9860 Unknown Bootleg Multigame Board
9861 Games: I only found 'Novel Diamond 999999-in-1.unf' using
9862 this mapper (hence the code is used for BMC_NOVELDIAMOND
9863 board). The code is included here in case a mapper 54
9864 dump arises.
9865
9866 iNES: mappers 54 and 213
9867
9868 In MESS: Partial Support.
9869
9870 *************************************************************/
9871
9872// Are this correct or should they work the same?
9873static WRITE8_HANDLER( novel1_w )
9874{
9875   LOG_MMC(("novel1_w, offset: %04x, data: %02x\n", offset, data));
9876
9877   prg32(space->machine(), offset & 0x03);
9878   chr8(space->machine(), offset & 0x07, CHRROM);
9879}
9880
9881static WRITE8_HANDLER( novel2_w )
9882{
9883   LOG_MMC(("novel2_w, offset: %04x, data: %02x\n", offset, data));
9884
9885   prg32(space->machine(), offset >> 1);
9886   chr8(space->machine(), offset >> 3, CHRROM);
9887}
9888
9889/*************************************************************
9890
9891 Board BMC-GKA
9892
9893 Unknown Bootleg Multigame Board
9894 Games: 6 in 1, 54 in 1, 106 in 1
9895
9896 iNES: mapper 57
9897
9898 In MESS: Supported.
9899
9900 *************************************************************/
9901
9902static WRITE8_HANDLER( bmc_gka_w )
9903{
9904   nes_state *state = space->machine().driver_data<nes_state>();
9905   LOG_MMC(("bmc_gka_w, offset: %04x, data: %02x\n", offset, data));
9906
9907   if (offset & 0x0800)
9908      state->m_mmc_latch2 = data;
9909   else
9910      state->m_mmc_latch1 = data;
9911
9912   if (state->m_mmc_latch2 & 0x80)
9913      prg32(space->machine(), 2 | (state->m_mmc_latch2 >> 6));
9914   else
9915   {
9916      prg16_89ab(space->machine(), (state->m_mmc_latch2 >> 5) & 0x03);
9917      prg16_cdef(space->machine(), (state->m_mmc_latch2 >> 5) & 0x03);
9918   }
9919
9920   set_nt_mirroring(space->machine(), (state->m_mmc_latch2 & 0x08) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9921
9922   chr8(space->machine(), (state->m_mmc_latch1 & 0x03) | (state->m_mmc_latch2 & 0x07) | ((state->m_mmc_latch2 & 0x10) >> 1), CHRROM);
9923}
9924
9925
9926/*************************************************************
9927
9928 Board UNL-STUDYNGAME
9929
9930 Games: Study n Game 32 in 1
9931
9932 iNES: mapper 39
9933
9934 In MESS: Partially Supported (problems with PRG bankswitch,
9935 only keyboard exercise work).
9936
9937 *************************************************************/
9938
9939static WRITE8_HANDLER( sng32_w )
9940{
9941   LOG_MMC(("sng32_w, offset: %04x, data: %02x\n", offset, data));
9942   prg32(space->machine(), data);
9943}
9944
9945/*************************************************************
9946
9947 Board BMC-GKB
9948
9949 Unknown Bootleg Multigame Board
9950 Games: 68 in 1, 73 in 1, 98 in 1
9951
9952 iNES: mapper 58
9953
9954 In MESS: Supported.
9955
9956 *************************************************************/
9957
9958static WRITE8_HANDLER( bmc_gkb_w )
9959{
9960   nes_state *state = space->machine().driver_data<nes_state>();
9961   UINT8 bank = (offset & 0x40) ? 0 : 1;
9962   LOG_MMC(("bmc_gkb_w, offset: %04x, data: %02x\n", offset, data));
9963
9964   prg16_89ab(space->machine(), offset & ~bank);
9965   prg16_cdef(space->machine(), offset | bank);
9966   chr8(space->machine(), offset >> 3, state->m_mmc_chr_source);
9967   set_nt_mirroring(space->machine(), BIT(data, 7) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9968}
9969
9970/*************************************************************
9971
9972 BMC-SUPER-700IN1
9973
9974 Unknown Bootleg Multigame Board
9975 Games: Super 700 in 1
9976
9977 iNES: mapper 62
9978
9979 In MESS: Supported.
9980
9981 *************************************************************/
9982
9983static WRITE8_HANDLER( bmc_super700in1_w )
9984{
9985   LOG_MMC(("bmc_super700in1_w, offset :%04x, data: %02x\n", offset, data));
9986
9987   chr8(space->machine(), ((offset & 0x1f) << 2) | (data & 0x03), CHRROM);
9988
9989   if (offset & 0x20)
9990   {
9991      prg16_89ab(space->machine(), (offset & 0x40) | ((offset >> 8) & 0x3f));
9992      prg16_cdef(space->machine(), (offset & 0x40) | ((offset >> 8) & 0x3f));
9993   }
9994   else
9995   {
9996      prg32(space->machine(), ((offset & 0x40) | ((offset >> 8) & 0x3f)) >> 1);
9997   }
9998
9999   set_nt_mirroring(space->machine(), BIT(data, 7) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10000}
10001
10002/*************************************************************
10003
10004 BMC-36IN1
10005
10006 Unknown Bootleg Multigame Board
10007 Games: 36 in 1, 1200 in 1
10008
10009 iNES: mapper 200
10010
10011 In MESS: Supported.
10012
10013 *************************************************************/
10014
10015static WRITE8_HANDLER( bmc_36in1_w )
10016{
10017   LOG_MMC(("bmc_36in1_w, offset: %04x, data: %02x\n", offset, data));
10018
10019   prg16_89ab(space->machine(), offset & 0x07);
10020   prg16_cdef(space->machine(), offset & 0x07);
10021   chr8(space->machine(), offset & 0x07, CHRROM);
10022
10023   set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10024}
10025
10026/*************************************************************
10027
10028 BMC-21IN1
10029
10030 Unknown Bootleg Multigame Board
10031 Games: 8 in 1, 21 in 1
10032
10033 iNES: mapper 201
10034
10035 In MESS: Supported.
10036
10037 *************************************************************/
10038
10039static WRITE8_HANDLER( bmc_21in1_w )
10040{
10041   LOG_MMC(("bmc_21in1_w, offset: %04x, data: %02x\n", offset, data));
10042
10043   prg32(space->machine(), offset & 0x03);
10044   chr8(space->machine(), offset & 0x03, CHRROM);
10045}
10046
10047/*************************************************************
10048
10049 BMC-150IN1
10050
10051 Unknown Bootleg Multigame Board
10052 Games: 150 in 1
10053
10054 iNES: mapper 202
10055
10056 In MESS: Supported.
10057
10058 *************************************************************/
10059
10060static WRITE8_HANDLER( bmc_150in1_w )
10061{
10062   int bank = (offset >> 1) & 0x07;
10063
10064   LOG_MMC(("bmc_150in1_w, offset: %04x, data: %02x\n", offset, data));
10065
10066   prg16_89ab(space->machine(), bank);
10067   prg16_cdef(space->machine(), bank + (((bank & 0x06) == 0x06) ? 1 : 0));
10068   chr8(space->machine(), bank, CHRROM);
10069
10070   set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ: PPU_MIRROR_VERT);
10071}
10072
10073/*************************************************************
10074
10075 BMC-35IN1
10076
10077 Unknown Bootleg Multigame Board
10078 Games: 35 in 1
10079
10080 iNES: mapper 203
10081
10082 In MESS: Supported.
10083
10084 *************************************************************/
10085
10086static WRITE8_HANDLER( bmc_35in1_w )
10087{
10088   LOG_MMC(("bmc_35in1_w, offset: %04x, data: %02x\n", offset, data));
10089
10090   prg16_89ab(space->machine(), (data >> 2) & 0x03);
10091   prg16_cdef(space->machine(), (data >> 2) & 0x03);
10092   chr8(space->machine(), data & 0x03, CHRROM);
10093}
10094
10095/*************************************************************
10096
10097 BMC-64IN1
10098
10099 Unknown Bootleg Multigame Board
10100 Games: 64 in 1
10101
10102 iNES: mapper 204
10103
10104 In MESS: Supported.
10105
10106 *************************************************************/
10107
10108static WRITE8_HANDLER( bmc_64in1_w )
10109{
10110   int bank = (offset >> 1) & (offset >> 2) & 0x01;
10111
10112   LOG_MMC(("bmc_64in1_w, offset: %04x, data: %02x\n", offset, data));
10113
10114   prg16_89ab(space->machine(), offset & ~bank);
10115   prg16_cdef(space->machine(), offset | bank);
10116   chr8(space->machine(), offset & ~bank, CHRROM);
10117
10118   set_nt_mirroring(space->machine(), BIT(data, 4) ? PPU_MIRROR_HORZ: PPU_MIRROR_VERT);
10119}
10120
10121/*************************************************************
10122
10123 BMC-15IN1
10124
10125 Unknown Bootleg Multigame Board
10126 Games: 3 in 1, 15 in 1
10127
10128 iNES: mapper 205, MMC3 clone
10129
10130 In MESS: Supported.
10131
10132 *************************************************************/
10133
10134static WRITE8_HANDLER( bmc_15in1_m_w )
10135{
10136   nes_state *state = space->machine().driver_data<nes_state>();
10137   LOG_MMC(("bmc_15in1_m_w, offset: %04x, data: %02x\n", offset, data));
10138
10139   if (offset & 0x0800)
10140   {
10141      state->m_mmc_prg_base = (data & 0x03) << 4;
10142      state->m_mmc_prg_mask = (data & 0x02) ? 0x0f : 0x1f;
10143      state->m_mmc_chr_base = (data & 0x03) << 7;
10144      state->m_mmc_chr_mask = (data & 0x02) ? 0x7f : 0xff;
10145      mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10146      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
10147   }
10148}
10149
10150/*************************************************************
10151
10152 BMC-SUPERHIK_300IN1
10153
10154 Unknown Bootleg Multigame Board
10155 Games: 100000 in 1, Super HIK 300 in 1, 1997 in 1
10156
10157 iNES: mapper 212
10158
10159 In MESS: Supported.
10160
10161 *************************************************************/
10162
10163static WRITE8_HANDLER( bmc_hik300_w )
10164{
10165   LOG_MMC(("bmc_hik300_w, offset: %04x, data: %02x\n", offset, data));
10166
10167   set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10168   chr8(space->machine(), offset, CHRROM);
10169
10170   if (offset < 0x4000)
10171   {
10172      prg16_89ab(space->machine(), offset);
10173      prg16_cdef(space->machine(), offset);
10174   }
10175   else
10176      prg32(space->machine(), offset >> 1);
10177}
10178
10179/*************************************************************
10180
10181 BMC-SUPERGUN-20IN1
10182
10183 Unknown Bootleg Multigame Board
10184 Games: Super Gun 20 in 1
10185
10186 iNES: mapper 214
10187
10188 In MESS: Supported.
10189
10190 *************************************************************/
10191
10192static WRITE8_HANDLER( supergun20in1_w )
10193{
10194   LOG_MMC(("supergun20in1_w, offset: %04x, data: %02x\n", offset, data));
10195
10196   prg16_89ab(space->machine(), offset >> 2);
10197   prg16_cdef(space->machine(), offset >> 2);
10198   chr8(space->machine(), offset, CHRROM);
10199}
10200
10201/*************************************************************
10202
10203 BMC-72IN1
10204
10205 Unknown Bootleg Multigame Board
10206 Games: 72 in 1, 115 in 1 and other multigame carts
10207
10208 iNES: mapper 225
10209
10210 In MESS: Supported.
10211
10212 *************************************************************/
10213
10214static WRITE8_HANDLER( bmc_72in1_w )
10215{
10216   int hi_bank;
10217   int size_16;
10218   int bank;
10219
10220   LOG_MMC(("bmc_72in1_w, offset: %04x, data: %02x\n", offset, data));
10221
10222   chr8(space->machine(), offset, CHRROM);
10223   set_nt_mirroring(space->machine(), (offset & 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10224
10225   hi_bank = offset & 0x40;
10226   size_16 = offset & 0x1000;
10227   bank = (offset & 0xf80) >> 7;
10228   if (size_16)
10229   {
10230      bank <<= 1;
10231      if (hi_bank)
10232         bank ++;
10233
10234      prg16_89ab(space->machine(), bank);
10235      prg16_cdef(space->machine(), bank);
10236   }
10237   else
10238      prg32(space->machine(), bank);
10239}
10240
10241/*************************************************************
10242
10243 BMC-76IN1
10244
10245 Unknown Bootleg Multigame Board
10246 Games: 76 in 1, Super 42 in 1
10247
10248 iNES: mapper 226
10249
10250 In MESS: Supported.
10251
10252 *************************************************************/
10253
10254// does this work for super42in1 as well?!?
10255static WRITE8_HANDLER( bmc_76in1_w )
10256{
10257   nes_state *state = space->machine().driver_data<nes_state>();
10258   int hi_bank;
10259   int size_16;
10260   int bank;
10261
10262   LOG_MMC(("bmc_76in1_w, offset: %04x, data: %02x\n", offset, data));
10263
10264   if (offset & 0x01)
10265      state->m_mmc_latch2 = data;
10266   else
10267      state->m_mmc_latch1 = data;
10268
10269   set_nt_mirroring(space->machine(), BIT(state->m_mmc_latch1, 6) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10270
10271   hi_bank = state->m_mmc_latch1 & 0x01;
10272   size_16 = state->m_mmc_latch1 & 0x20;
10273   bank = ((state->m_mmc_latch1 & 0x1e) >> 1) | ((state->m_mmc_latch1 & 0x80) >> 3) | ((state->m_mmc_latch2 & 0x01) << 5);
10274
10275   if (size_16)
10276   {
10277      bank <<= 1;
10278      if (hi_bank)
10279         bank ++;
10280
10281      prg16_89ab(space->machine(), bank);
10282      prg16_cdef(space->machine(), bank);
10283   }
10284   else
10285      prg32(space->machine(), bank);
10286}
10287
10288/*************************************************************
10289
10290 BMC-1200IN1
10291
10292 Unknown Bootleg Multigame Board
10293 Games: 1200 in 1, 295 in 1, 76 in 1
10294
10295 iNES: mapper 227
10296
10297 In MESS: Supported.
10298
10299 *************************************************************/
10300
10301static WRITE8_HANDLER( bmc_1200in1_w )
10302{
10303   int hi_bank;
10304   int size_32;
10305   int bank;
10306
10307   LOG_MMC(("bmc_1200in1_w, offset: %04x, data: %02x\n", offset, data));
10308
10309   hi_bank = offset & 0x04;
10310   size_32 = offset & 0x01;
10311   bank = ((offset & 0x78) >> 3) | ((offset & 0x0100) >> 4);
10312   if (!size_32)
10313   {
10314      bank <<= 1;
10315      if (hi_bank)
10316         bank ++;
10317
10318      prg16_89ab(space->machine(), bank);
10319      prg16_cdef(space->machine(), bank);
10320   }
10321   else
10322      prg32(space->machine(), bank);
10323
10324   if (!(offset & 0x80))
10325   {
10326      if (offset & 0x200)
10327         prg16_cdef(space->machine(), ((bank << 1) & 0x38) + 7);
10328      else
10329         prg16_cdef(space->machine(), ((bank << 1) & 0x38));
10330   }
10331
10332   set_nt_mirroring(space->machine(), BIT(data, 1) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10333}
10334
10335/*************************************************************
10336
10337 BMC-31IN1
10338
10339 Unknown Bootleg Multigame Board
10340 Games: 31 in 1
10341
10342 iNES: mapper 229
10343
10344 In MESS: Supported.
10345
10346 *************************************************************/
10347
10348static WRITE8_HANDLER( bmc_31in1_w )
10349{
10350   LOG_MMC(("bmc_31in1_w, offset: %04x, data: %02x\n", offset, data));
10351
10352   set_nt_mirroring(space->machine(), BIT(data, 5) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10353   chr8(space->machine(), offset, CHRROM);
10354
10355   if ((offset & 0x1e) == 0)
10356   {
10357      prg16_89ab(space->machine(), 0);
10358      prg16_89ab(space->machine(), 1);
10359   }
10360   else
10361   {
10362      prg16_89ab(space->machine(), offset & 0x1f);
10363      prg16_89ab(space->machine(), offset & 0x1f);
10364   }
10365}
10366
10367/*************************************************************
10368
10369 BMC-22GAMES
10370
10371 Unknown Bootleg Multigame Board
10372 Games: 22 in 1
10373
10374 iNES: mapper 230
10375
10376 In MESS: Partially Supported. It would need a reset
10377 to work (not possible yet)
10378
10379 *************************************************************/
10380
10381static WRITE8_HANDLER( bmc_22g_w )
10382{
10383   LOG_MMC(("bmc_22g_w, offset: %04x, data: %02x\n", offset, data));
10384
10385   if (1)   // this should flip at reset
10386   {
10387      prg16_89ab(space->machine(), data & 0x07);
10388   }
10389   else
10390   {
10391      if (data & 0x20)
10392      {
10393         prg16_89ab(space->machine(), (data & 0x1f) + 8);
10394         prg16_cdef(space->machine(), (data & 0x1f) + 8);
10395      }
10396      else
10397      {
10398         prg16_89ab(space->machine(), (data & 0x1f) + 8);
10399         prg16_cdef(space->machine(), (data & 0x1f) + 9);
10400      }
10401      set_nt_mirroring(space->machine(), BIT(data, 6) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
10402   }
10403}
10404
10405/*************************************************************
10406
10407 BMC-20IN1
10408
10409 Unknown Bootleg Multigame Board
10410 Games: 20 in 1
10411
10412 iNES: mapper 231
10413
10414 In MESS: Supported.
10415
10416 *************************************************************/
10417
10418static WRITE8_HANDLER( bmc_20in1_w )
10419{
10420   LOG_MMC(("bmc_20in1_w, offset: %04x, data: %02x\n", offset, data));
10421
10422   set_nt_mirroring(space->machine(), BIT(data, 7) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10423
10424   prg16_89ab(space->machine(), (offset & 0x1e));
10425   prg16_cdef(space->machine(), (offset & 0x1e) | ((offset & 0x20) ? 1 : 0));
10426}
10427
10428/*************************************************************
10429
10430 BMC-110IN1
10431
10432 Known Boards: Unknown Bootleg Board
10433 Games: 110 in 1
10434
10435 iNES: mapper 255
10436
10437 In MESS: Preliminary support.
10438
10439 *************************************************************/
10440
10441static WRITE8_HANDLER( bmc_110in1_w )
10442{
10443   UINT8 map255_helper1 = (offset >> 12) ? 0 : 1;
10444   UINT8 map255_helper2 = ((offset >> 8) & 0x40) | ((offset >> 6) & 0x3f);
10445
10446   LOG_MMC(("bmc_110in1_w, offset: %04x, data: %02x\n", offset, data));
10447
10448   set_nt_mirroring(space->machine(), (offset & 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10449   prg16_89ab(space->machine(), map255_helper1 & ~map255_helper2);
10450   prg16_cdef(space->machine(), map255_helper1 | map255_helper2);
10451   chr8(space->machine(), ((offset >> 8) & 0x40) | (offset & 0x3f), CHRROM);
10452}
10453
10454/*************************************************************
10455
10456 BMC-SUPERBIG-7IN1
10457
10458 Known Boards: Unknown Multigame Bootleg Board
10459 Games: Kunio 8 in 1, Super Big 7 in 1
10460
10461 iNES: mapper 44
10462
10463 In MESS: Supported. It also uses mmc3_irq.
10464
10465 *************************************************************/
10466
10467static WRITE8_HANDLER( bmc_sbig7_w )
10468{
10469   nes_state *state = space->machine().driver_data<nes_state>();
10470   UINT8 page;
10471   LOG_MMC(("bmc_sbig7_w, offset: %04x, data: %02x\n", offset, data));
10472
10473   switch (offset & 0x6001)
10474   {
10475      case 0x2001: /* $a001 - Select 128K ROM/VROM base (0..5) or last 256K ROM/VRAM base (6) */
10476         page = (data & 0x07);
10477         if (page > 6)
10478            page = 6;
10479
10480         state->m_mmc_prg_base = page << 4;
10481         state->m_mmc_prg_mask = (page > 5) ? 0x1f : 0x0f;
10482         state->m_mmc_chr_base = page << 7;
10483         state->m_mmc_chr_mask = (page > 5) ? 0xff : 0x7f;
10484         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10485         mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
10486         break;
10487
10488      default:
10489         txrom_w(space, offset, data);
10490         break;
10491   }
10492}
10493
10494/*************************************************************
10495
10496 BMC-HIK8IN1
10497
10498 Known Boards: Unknown Multigame Bootleg Board
10499 Games: Street Fighter V, various multigame carts
10500
10501 iNES: mapper 45
10502
10503 In MESS: Supported. It also uses mmc3_irq.
10504
10505 *************************************************************/
10506
10507static WRITE8_HANDLER( bmc_hik8_m_w )
10508{
10509   nes_state *state = space->machine().driver_data<nes_state>();
10510   LOG_MMC(("bmc_hik8_m_w, offset: %04x, data: %02x\n", offset, data));
10511
10512   /* This bit is the "register lock". Once register are locked, writes go to WRAM
10513     and there is no way to unlock them (except by resetting the machine) */
10514   if ((state->m_mmc_reg[3] & 0x40) && state->m_wram != NULL)
10515      state->m_wram[offset] = data;
10516   else
10517   {
10518      state->m_mmc_reg[state->m_mmc_count] = data;
10519      state->m_mmc_count = (state->m_mmc_count + 1) & 0x03;
10520
10521      if (!state->m_mmc_count)
10522      {
10523         LOG_MMC(("bmc_hik8_m_w, command completed %02x %02x %02x %02x\n", state->m_mmc_reg[3],
10524                state->m_mmc_reg[2], state->m_mmc_reg[1], state->m_mmc_reg[0]));
10525
10526         state->m_mmc_prg_base = state->m_mmc_reg[1];
10527         state->m_mmc_prg_mask = 0x3f ^ (state->m_mmc_reg[3] & 0x3f);
10528         state->m_mmc_chr_base = ((state->m_mmc_reg[2] & 0xf0) << 4) | state->m_mmc_reg[0];
10529         if (BIT(state->m_mmc_reg[2], 3))
10530            state->m_mmc_chr_mask = (1 << ((state->m_mmc_reg[2] & 7) + 1)) - 1;
10531         else if (state->m_mmc_reg[2])
10532            state->m_mmc_chr_mask = 0;
10533         else
10534            state->m_mmc_chr_mask = 0xff;   // i.e. we use the vrom_bank with no masking
10535
10536         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10537         mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
10538      }
10539   }
10540}
10541
10542/*************************************************************
10543
10544 BMC-SUPERHIK-4IN1
10545
10546 Known Boards: Unknown Multigame Bootleg Board
10547 Games: Super HIK 4 in 1
10548
10549 iNES: mapper 49
10550
10551 In MESS: Supported. It also uses mmc3_irq.
10552
10553 *************************************************************/
10554
10555static WRITE8_HANDLER( bmc_hik4in1_m_w )
10556{
10557   nes_state *state = space->machine().driver_data<nes_state>();
10558   LOG_MMC(("bmc_hik4in1_m_w, offset: %04x, data: %02x\n", offset, data));
10559
10560   /* mid writes only work when WRAM is enabled. not sure if I should
10561     change the condition to state->m_mmc_latch2==0x80 (i.e. what is the effect of
10562     the read-only bit?) */
10563   if (state->m_mmc3_wram_protect & 0x80)
10564   {
10565      if (data & 0x01)   /* if this is 0, then we have 32k PRG blocks */
10566      {
10567         state->m_mmc_prg_base = (data & 0xc0) >> 2;
10568         state->m_mmc_prg_mask = 0x0f;
10569         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10570      }
10571      else
10572         prg32(space->machine(), (data & 0x30) >> 4);
10573
10574      state->m_mmc_chr_base = (data & 0xc0) << 1;
10575      state->m_mmc_chr_mask = 0x7f;
10576      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
10577   }
10578}
10579
10580/*************************************************************
10581
10582 BMC-BALLGAMES-11IN1
10583
10584 Known Boards: Unknown Multigame Bootleg Board
10585 Games: 11 in 1 Ball Games
10586
10587 iNES: mapper 51
10588
10589 In MESS: Partially Supported.
10590
10591 *************************************************************/
10592
10593static void bmc_ball11_set_banks( running_machine &machine )
10594{
10595   nes_state *state = machine.driver_data<nes_state>();
10596   set_nt_mirroring(machine, (state->m_mmc_reg[0] == 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10597
10598   if (state->m_mmc_reg[0] & 0x01)
10599   {
10600      prg32(machine, state->m_mmc_reg[1]);
10601   }
10602   else
10603   {
10604      prg16_89ab(machine, (state->m_mmc_reg[1] << 1) | (state->m_mmc_reg[0] >> 1));
10605      prg16_cdef(machine, (state->m_mmc_reg[1] << 1) | 0x07);
10606   }
10607}
10608
10609static WRITE8_HANDLER( bmc_ball11_m_w )
10610{
10611   nes_state *state = space->machine().driver_data<nes_state>();
10612
10613   LOG_MMC(("bmc_ball11_m_w, offset: %04x, data: %02x\n", offset, data));
10614
10615   state->m_mmc_reg[0] = ((data >> 1) & 0x01) | ((data >> 3) & 0x02);
10616   bmc_ball11_set_banks(space->machine());
10617}
10618
10619static WRITE8_HANDLER( bmc_ball11_w )
10620{
10621   nes_state *state = space->machine().driver_data<nes_state>();
10622
10623   LOG_MMC(("bmc_ball11_w, offset: %04x, data: %02x\n", offset, data));
10624
10625   switch (offset & 0x6000)
10626   {
10627      case 0x4000:   // here we also update reg[0] upper bit
10628         state->m_mmc_reg[0] = (state->m_mmc_reg[0] & 0x01) | ((data >> 3) & 0x02);
10629      case 0x0000:
10630      case 0x2000:
10631      case 0x6000:
10632         state->m_mmc_reg[1] = data & 0x0f;
10633         bmc_ball11_set_banks(space->machine());
10634         break;
10635   }
10636}
10637
10638/*************************************************************
10639
10640 BMC-MARIOPARTY-7IN1
10641
10642 Known Boards: Unknown Multigame Bootleg Board
10643 Games: Mario 7 in 1
10644
10645 MMC3 clone
10646
10647 iNES: mapper 52
10648
10649 In MESS: Supported.
10650
10651 *************************************************************/
10652
10653static WRITE8_HANDLER( bmc_mario7in1_m_w )
10654{
10655   nes_state *state = space->machine().driver_data<nes_state>();
10656   UINT8 map52_helper1, map52_helper2;
10657   LOG_MMC(("bmc_mario7in1_m_w, offset: %04x, data: %02x\n", offset, data));
10658
10659   /* mid writes only work when WRAM is enabled. not sure if I should
10660     change the condition to state->m_mmc_latch2==0x80 (i.e. what is the effect of
10661     the read-only bit?) and it only can happen once! */
10662   if ((state->m_mmc3_wram_protect & 0x80) && !state->m_map52_reg_written)
10663   {
10664      map52_helper1 = (data & 0x08);
10665      map52_helper2 = (data & 0x40);
10666
10667      state->m_mmc_prg_base = map52_helper1 ? ((data & 0x07) << 4) : ((data & 0x06) << 4);
10668      state->m_mmc_prg_mask = map52_helper1 ? 0x0f : 0x1f;
10669      state->m_mmc_chr_base = ((data & 0x20) << 4) | ((data & 0x04) << 6) | (map52_helper2 ? ((data & 0x10) << 3) : 0);
10670      state->m_mmc_chr_mask = map52_helper2 ? 0x7f : 0xff;
10671      mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10672      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
10673
10674      state->m_map52_reg_written = 1;
10675   }
10676   else
10677      state->m_wram[offset] = data;
10678}
10679
10680/*************************************************************
10681
10682 BMC-GOLDENCARD-6IN1
10683
10684 Known Boards: Unknown Bootleg Multigame Board
10685 Games: Golden Card 6 in 1
10686
10687 MMC3 clone
10688
10689 iNES: mapper 217
10690
10691 In MESS: Supported.
10692
10693 *************************************************************/
10694
10695// remove mask & base parameters!
10696static void bmc_gc6in1_set_prg( running_machine &machine, int prg_base, int prg_mask )
10697{
10698   nes_state *state = machine.driver_data<nes_state>();
10699   state->m_mmc_prg_base = (state->m_mmc_reg[1] & 0x08) ? 0 : (state->m_mmc_reg[1] & 0x10);
10700   state->m_mmc_prg_mask = (state->m_mmc_reg[1] & 0x08) ? 0x1f : 0x0f;
10701
10702   state->m_mmc_prg_base |= ((state->m_mmc_reg[1] & 0x03) << 5);
10703
10704   mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
10705}
10706
10707static void bmc_gc6in1_set_chr( running_machine &machine, UINT8 chr )
10708{
10709   nes_state *state = machine.driver_data<nes_state>();
10710   UINT8 chr_page = (state->m_mmc_latch1 & 0x80) >> 5;
10711   int chr_base = (state->m_mmc_reg[1] & 0x08) ? 0x00 : ((state->m_mmc_reg[1] & 0x10) << 3);
10712   int chr_mask = (state->m_mmc_reg[1] & 0x08) ? 0xff : 0x7f;
10713
10714   chr_base |= ((state->m_mmc_reg[1] & 0x03) << 8);
10715
10716   chr1_x(machine, chr_page ^ 0, chr_base | ((state->m_mmc_vrom_bank[0] & ~0x01) & chr_mask), chr);
10717   chr1_x(machine, chr_page ^ 1, chr_base | ((state->m_mmc_vrom_bank[0] |  0x01) & chr_mask), chr);
10718   chr1_x(machine, chr_page ^ 2, chr_base | ((state->m_mmc_vrom_bank[1] & ~0x01) & chr_mask), chr);
10719   chr1_x(machine, chr_page ^ 3, chr_base | ((state->m_mmc_vrom_bank[1] |  0x01) & chr_mask), chr);
10720   chr1_x(machine, chr_page ^ 4, chr_base | (state->m_mmc_vrom_bank[2] & chr_mask), chr);
10721   chr1_x(machine, chr_page ^ 5, chr_base | (state->m_mmc_vrom_bank[3] & chr_mask), chr);
10722   chr1_x(machine, chr_page ^ 6, chr_base | (state->m_mmc_vrom_bank[4] & chr_mask), chr);
10723   chr1_x(machine, chr_page ^ 7, chr_base | (state->m_mmc_vrom_bank[5] & chr_mask), chr);
10724}
10725
10726static WRITE8_HANDLER( bmc_gc6in1_l_w )
10727{
10728   nes_state *state = space->machine().driver_data<nes_state>();
10729   UINT8 bank;
10730   LOG_MMC(("bmc_gc6in1_l_w, offset: %04x, data: %02x\n", offset, data));
10731   offset += 0x100;
10732
10733   if (offset == 0x1000)
10734   {
10735      state->m_mmc_reg[0] = data;
10736      if (data & 0x80)
10737      {
10738         bank = (data & 0x0f) | ((state->m_mmc_reg[1] & 0x03) << 4);
10739         prg16_89ab(space->machine(), bank);
10740         prg16_cdef(space->machine(), bank);
10741      }
10742      else
10743         bmc_gc6in1_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10744   }
10745   else if (offset == 0x1001)
10746   {
10747      state->m_mmc_reg[1] = data;
10748      bmc_gc6in1_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10749   }
10750   else if (offset == 0x1007)
10751   {
10752      state->m_mmc_reg[2] = data;
10753   }
10754}
10755
10756static WRITE8_HANDLER( bmc_gc6in1_w )
10757{
10758   nes_state *state = space->machine().driver_data<nes_state>();
10759   UINT8 mmc_helper, cmd;
10760   static const UINT8 conv_table[8] = {0, 6, 3, 7, 5, 2, 4, 1};
10761   LOG_MMC(("bmc_gc6in1_w, offset: %04x, data: %02x\n", offset, data));
10762
10763   if (!state->m_mmc_reg[2]) // in this case we act like MMC3, only with alt prg/chr handlers
10764   {
10765      switch (offset & 0x6001)
10766      {
10767         case 0x0000:
10768            mmc_helper = state->m_mmc3_latch ^ data;
10769            state->m_mmc3_latch = data;
10770
10771            /* Has PRG Mode changed? */
10772            if (mmc_helper & 0x40)
10773               bmc_gc6in1_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10774
10775            /* Has CHR Mode changed? */
10776            if (mmc_helper & 0x80)
10777               bmc_gc6in1_set_chr(space->machine(), state->m_mmc_chr_source);
10778            break;
10779
10780         case 0x0001:
10781            cmd = state->m_mmc3_latch & 0x07;
10782            switch (cmd)
10783         {
10784            case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
10785            case 2: case 3: case 4: case 5:
10786               state->m_mmc_vrom_bank[cmd] = data;
10787               bmc_gc6in1_set_chr(space->machine(), state->m_mmc_chr_source);
10788               break;
10789            case 6:
10790            case 7:
10791               state->m_mmc_prg_bank[cmd - 6] = data;
10792               bmc_gc6in1_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10793               break;
10794         }
10795            break;
10796
10797         default:
10798            txrom_w(space, offset, data);
10799            break;
10800      }
10801   }
10802   else
10803   {
10804      switch (offset & 0x6001)
10805      {
10806         case 0x0000:
10807            txrom_w(space, 0x4000, data);
10808            break;
10809
10810         case 0x0001:
10811            data = (data & 0xc0) | conv_table[data & 0x07];
10812            mmc_helper = state->m_mmc3_latch ^ data;
10813            state->m_mmc3_latch = data;
10814
10815            /* Has PRG Mode changed? */
10816            if (mmc_helper & 0x40)
10817               bmc_gc6in1_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10818
10819            /* Has CHR Mode changed? */
10820            if (mmc_helper & 0x80)
10821               bmc_gc6in1_set_chr(space->machine(), state->m_mmc_chr_source);
10822
10823            state->m_mmc_reg[3] = 1;
10824            break;
10825
10826         case 0x2000:
10827            cmd = state->m_mmc3_latch & 0x07;
10828            if (state->m_mmc_reg[3])
10829            {
10830               state->m_mmc_reg[3] = 0;
10831               switch (cmd)
10832               {
10833                  case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
10834                  case 2: case 3: case 4: case 5:
10835                     state->m_mmc_vrom_bank[cmd] = data;
10836                     bmc_gc6in1_set_chr(space->machine(), state->m_mmc_chr_source);
10837                     break;
10838                  case 6:
10839                  case 7:
10840                     state->m_mmc_prg_bank[cmd - 6] = data;
10841                     bmc_gc6in1_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10842                     break;
10843               }
10844            }
10845            break;
10846
10847
10848         case 0x2001:
10849            set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10850            break;
10851
10852         default:
10853            txrom_w(space, offset, data);
10854            break;
10855      }
10856   }
10857}
10858
10859/*************************************************************
10860
10861 BMC-FAMILY-4646B
10862
10863 Known Boards: Unknown Multigame Bootleg Board (4646B)
10864 Games: 2 in 1 - Family Kid & Aladdin 4
10865
10866 MMC3 clone
10867
10868 iNES: mapper 134
10869
10870 In MESS: Supported.
10871
10872 *************************************************************/
10873
10874static WRITE8_HANDLER( bmc_family4646_m_w )
10875{
10876   nes_state *state = space->machine().driver_data<nes_state>();
10877   LOG_MMC(("bmc_family4646_m_w, offset: %04x, data: %02x\n", offset, data));
10878
10879   if (offset == 0x01)
10880   {
10881      state->m_mmc_prg_base = (data & 0x02) << 4;
10882      state->m_mmc_prg_mask = 0x1f;
10883      state->m_mmc_chr_base = (data & 0x20) << 3;
10884      state->m_mmc_chr_mask = 0xff;
10885      mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10886      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
10887   }
10888}
10889
10890/*************************************************************
10891
10892 BMC-VT5201
10893
10894 *************************************************************/
10895
10896static WRITE8_HANDLER( bmc_vt5201_w )
10897{
10898   nes_state *state = space->machine().driver_data<nes_state>();
10899   LOG_MMC(("bmc_vt5201_w, offset: %04x, data: %02x\n", offset, data));
10900
10901   state->m_mmc_latch1 = BIT(offset, 8);
10902
10903   // not sure about this mirroring bit!!
10904   // without it TN 95 in 1 has glitches in Lunar Ball; with it TN 95 in 1 has glitches in Galaxian!
10905   set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10906   if (BIT(offset, 7))
10907   {
10908      prg16_89ab(space->machine(), (offset >> 4) & 0x07);
10909      prg16_cdef(space->machine(), (offset >> 4) & 0x07);
10910   }
10911   else
10912      prg32(space->machine(), (offset >> 5) & 0x03);
10913   chr8(space->machine(), offset, CHRROM);
10914}
10915
10916static READ8_HANDLER( bmc_vt5201_r )
10917{
10918   nes_state *state = space->machine().driver_data<nes_state>();
10919   LOG_MMC(("bmc_vt5201_r, offset: %04x\n", offset));
10920   //  state->m_mmc_dipsetting = input_port_read(space->machine(), "CARTDIPS");
10921
10922   if (state->m_mmc_latch1)
10923      return state->m_mmc_dipsetting; // cart mode, depending on the Dip Switches (always zero atm, given we have no way to add cart-based DIPs)
10924   else
10925      return mmc_hi_access_rom(space->machine(), offset);
10926}
10927
10928/*************************************************************
10929
10930 BMC-BS-5
10931
10932 Games: a few 4 in 1 multicarts
10933
10934 *************************************************************/
10935
10936static void bmc_bs5_update_banks( running_machine &machine )
10937{
10938   nes_state *state = machine.driver_data<nes_state>();
10939
10940   prg8_89(machine, state->m_mmc_prg_bank[0]);
10941   prg8_ab(machine, state->m_mmc_prg_bank[1]);
10942   prg8_cd(machine, state->m_mmc_prg_bank[2]);
10943   prg8_ef(machine, state->m_mmc_prg_bank[3]);
10944   chr2_0(machine, state->m_mmc_vrom_bank[0], CHRROM);
10945   chr2_2(machine, state->m_mmc_vrom_bank[1], CHRROM);
10946   chr2_4(machine, state->m_mmc_vrom_bank[2], CHRROM);
10947   chr2_6(machine, state->m_mmc_vrom_bank[3], CHRROM);
10948}
10949
10950static WRITE8_HANDLER( bmc_bs5_w )
10951{
10952   nes_state *state = space->machine().driver_data<nes_state>();
10953   UINT8 bs5_helper = (offset & 0xc00) >> 10;
10954   LOG_MMC(("bmc_bs5_w, offset: %04x, data: %02x\n", offset, data));
10955//  state->m_mmc_dipsetting = input_port_read(space->machine(), "CARTDIPS");
10956
10957   switch (offset & 0x7000)
10958   {
10959      case 0x0000:
10960         state->m_mmc_vrom_bank[bs5_helper] = offset & 0x1f;
10961         break;
10962      case 0x2000:
10963         if (BIT(offset, state->m_mmc_dipsetting + 4))   // mmc_dipsetting is always zero atm, given we have no way to add cart-based DIPs
10964            state->m_mmc_prg_bank[bs5_helper] = offset & 0x0f;
10965         break;
10966   }
10967   bmc_bs5_update_banks(space->machine());
10968}
10969
10970/*************************************************************
10971
10972 BMC-810544-C-A1
10973
10974 Games: 200-in-1 Elfland
10975
10976 *************************************************************/
10977
10978static WRITE8_HANDLER( bmc_810544_w )
10979{
10980   UINT8 bank = (offset >> 7);
10981   LOG_MMC(("bmc_810544_w, offset: %04x, data: %02x\n", offset, data));
10982
10983   if (!BIT(offset, 6))
10984   {
10985      prg16_89ab(space->machine(), (bank << 1) | BIT(offset, 5));
10986      prg16_cdef(space->machine(), (bank << 1) | BIT(offset, 5));
10987   }
10988   else
10989      prg32(space->machine(), bank);
10990
10991   set_nt_mirroring(space->machine(), BIT(offset, 4) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10992
10993   chr8(space->machine(), offset & 0x0f, CHRROM);
10994}
10995
10996/*************************************************************
10997
10998 BMC-NTD-03
10999
11000 *************************************************************/
11001
11002static WRITE8_HANDLER( bmc_ntd03_w )
11003{
11004   UINT8 pbank, cbank;
11005   LOG_MMC(("bmc_ntd03_w, offset: %04x, data: %02x\n", offset, data));
11006
11007   pbank = (offset >> 10) & 0x1e;
11008   cbank = ((offset & 0x300) >> 5) | (offset & 0x07);
11009
11010   if (BIT(offset, 7))
11011   {
11012      prg16_89ab(space->machine(), pbank | BIT(offset, 6));
11013      prg16_cdef(space->machine(), pbank | BIT(offset, 6));
11014   }
11015   else
11016      prg32(space->machine(), pbank >> 1);
11017
11018   set_nt_mirroring(space->machine(), BIT(offset, 10) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
11019
11020   chr8(space->machine(), cbank, CHRROM);
11021}
11022
11023/*************************************************************
11024
11025 BMC-GHOSTBUSTERS63IN1
11026
11027 in MESS: only preliminar support
11028
11029 *************************************************************/
11030
11031static void bmc_gb63_update( running_machine &machine )
11032{
11033   nes_state *state = machine.driver_data<nes_state>();
11034
11035   set_nt_mirroring(machine, BIT(state->m_mmc_reg[0], 6) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
11036
11037   if (BIT(state->m_mmc_reg[0], 5))
11038   {
11039      prg16_89ab(machine, state->m_mmc_reg[0] & 0x1f);   // FIXME: here probably we could also have PRGRAM, depending on mmc_latch1!
11040      prg16_cdef(machine, state->m_mmc_reg[0] & 0x1f);   // FIXME: here probably we could also have PRGRAM, depending on mmc_latch1!
11041   }
11042   else
11043      prg32(machine, (state->m_mmc_reg[0] & 0x1f) >> 1);   // FIXME: here probably we could also have PRGRAM, depending on mmc_latch1!
11044
11045   if (BIT(state->m_mmc_reg[1], 2))
11046      chr8(machine, 0, CHRRAM);
11047//  else
11048//      chr8(machine, 0, CHRROM);
11049}
11050
11051static WRITE8_HANDLER( bmc_gb63_w )
11052{
11053   nes_state *state = space->machine().driver_data<nes_state>();
11054   LOG_MMC(("bmc_gb63_w, offset: %04x, data: %02x\n", offset, data));
11055
11056   state->m_mmc_reg[offset & 1] = data;
11057   state->m_mmc_latch1 = BIT(state->m_mmc_reg[0], 7) | (BIT(state->m_mmc_reg[1], 0) << 1);
11058
11059}
11060
11061static READ8_HANDLER( bmc_gb63_r )
11062{
11063   nes_state *state = space->machine().driver_data<nes_state>();
11064   LOG_MMC(("bmc_gb63_r, offset: %04x\n", offset));
11065   //  state->m_mmc_dipsetting = input_port_read(space->machine(), "CARTDIPS");
11066
11067   if (state->m_mmc_latch1 == 1)
11068      return 0xff;   // open bus
11069   else
11070      return mmc_hi_access_rom(space->machine(), offset);
11071}
11072
11073/*************************************************************
11074
11075 UNL-EDU2000
11076
11077 *************************************************************/
11078
11079static WRITE8_HANDLER( edu2k_w )
11080{
11081   LOG_MMC(("edu2k_w, offset: %04x, data: %02x\n", offset, data));
11082
11083   prg32(space->machine(), data & 0x1f);
11084   wram_bank(space->machine(), (data & 0xc0) >> 6, NES_WRAM);
11085}
11086
11087/*************************************************************
11088
11089 UNL-H2288
11090
11091 *************************************************************/
11092
11093static void h2288_prg_cb( running_machine &machine, int start, int bank )
11094{
11095   nes_state *state = machine.driver_data<nes_state>();
11096
11097   if (!(state->m_mmc_reg[0] & 0x40))
11098      prg8_x(machine, start, bank);
11099}
11100
11101static WRITE8_HANDLER( h2288_l_w )
11102{
11103   nes_state *state = space->machine().driver_data<nes_state>();
11104   LOG_MMC(("h2288_l_w offset: %04x, data: %02x\n", offset, data));
11105   offset += 0x100;
11106
11107   if (offset >= 0x1800)
11108   {
11109      state->m_mmc_reg[offset & 1] = data;
11110      if (state->m_mmc_reg[0] & 0x40)
11111      {
11112         UINT8 helper1 = (state->m_mmc_reg[0] & 0x05) | ((state->m_mmc_reg[0] >> 2) & 0x0a);
11113         UINT8 helper2 = BIT(state->m_mmc_reg[0], 1);
11114         prg16_89ab(space->machine(), helper1 & ~helper2);
11115         prg16_cdef(space->machine(), helper1 |  helper2);
11116      }
11117      else
11118         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
11119   }
11120}
11121
11122static READ8_HANDLER( h2288_l_r )
11123{
11124   LOG_MMC(("h2288_l_r offset: %04x\n", offset));
11125   offset += 0x100;
11126
11127   if (offset >= 0x1000)
11128   {
11129      int helper = offset >> 8;
11130      if (offset & 1)
11131         return helper | 0x01;
11132      else
11133         return helper ^ 0x01;
11134   }
11135
11136   return 0;
11137}
11138
11139static WRITE8_HANDLER( h2288_w )
11140{
11141   static const UINT8 conv_table[8] = {0, 3, 1, 5, 6, 7, 2, 4};
11142   LOG_MMC(("h2288_w, offset: %04x, data: %02x\n", offset, data));
11143
11144   switch (offset & 0x6001)
11145   {
11146      case 0x0000:
11147         txrom_w(space, 0x0000, (data & 0xc0) | conv_table[data & 0x07]);
11148         break;
11149
11150      default:
11151         txrom_w(space, offset, data);
11152         break;
11153   }
11154}
11155
11156/*************************************************************
11157
11158 UNL-SHJY3
11159
11160 *************************************************************/
11161
11162/* I think the IRQ should only get fired if enough CPU cycles have passed, but we don't implement (yet) this part */
11163static void shjy3_irq( device_t *device, int scanline, int vblank, int blanked )
11164{
11165   nes_state *state = device->machine().driver_data<nes_state>();
11166   if (state->m_IRQ_enable & 0x02)
11167   {
11168      if (state->m_IRQ_count == 0xff)
11169      {
11170         state->m_IRQ_count = state->m_IRQ_count_latch;
11171         state->m_IRQ_enable = state->m_IRQ_enable | ((state->m_IRQ_enable & 0x01) << 1);
11172         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
11173      }
11174      else
11175         state->m_IRQ_count++;
11176   }
11177}
11178
11179static void shjy3_update( running_machine &machine )
11180{
11181   nes_state *state = machine.driver_data<nes_state>();
11182   int i;
11183
11184   prg8_89(machine, state->m_mmc_prg_bank[0]);
11185   prg8_ab(machine, state->m_mmc_prg_bank[1]);
11186
11187   for (i = 0; i < 8; i++)
11188   {
11189      UINT8 chr_bank = state->m_mmc_vrom_bank[i] | (state->m_mmc_extra_bank[i] << 4);
11190      if (state->m_mmc_vrom_bank[i] == 0xc8)
11191      {
11192         state->m_mmc_latch1 = 0;
11193         continue;
11194      }
11195      else if (state->m_mmc_vrom_bank[i] == 0x88)
11196      {
11197         state->m_mmc_latch1 = 1;
11198         continue;
11199      }
11200      if ((state->m_mmc_vrom_bank[i] == 4 || state->m_mmc_vrom_bank[i] == 5) && !state->m_mmc_latch1)
11201         chr1_x(machine, i, chr_bank & 1, CHRRAM);
11202      else
11203         chr1_x(machine, i, chr_bank, CHRROM);
11204   }
11205}
11206
11207static WRITE8_HANDLER( shjy3_w )
11208{
11209   nes_state *state = space->machine().driver_data<nes_state>();
11210   UINT8 mmc_helper, shift;
11211   LOG_MMC(("shjy3_w, offset: %04x, data: %02x\n", offset, data));
11212
11213   if (offset >= 0x3000 && offset <= 0x600c)
11214   {
11215      mmc_helper = ((offset & 8) | (offset >> 8)) >> 3;
11216      mmc_helper += 2;
11217      mmc_helper &= 7;
11218      shift = offset & 4;
11219
11220      state->m_mmc_vrom_bank[mmc_helper] = (state->m_mmc_vrom_bank[mmc_helper] & (0xf0 >> shift)) | ((data & 0x0f) << shift);
11221      if (shift)
11222         state->m_mmc_extra_bank[mmc_helper] = data >> 4;
11223   }
11224   else
11225   {
11226      switch (offset)
11227      {
11228         case 0x0010:
11229            state->m_mmc_prg_bank[0] = data;
11230            break;
11231         case 0x2010:
11232            state->m_mmc_prg_bank[1] = data;
11233            break;
11234         case 0x1400:
11235            switch (data & 0x03)
11236            {
11237               case 0: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
11238               case 1: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
11239               case 2: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
11240               case 3: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
11241            }
11242            break;
11243         case 0x7000:
11244            state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0xf0) | (data & 0x0f);
11245            break;
11246         case 0x7004:
11247            state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0x0f) | ((data & 0x0f) << 4);
11248            break;
11249         case 0x7008:
11250            state->m_IRQ_enable = data & 0x03;
11251            if (state->m_IRQ_enable & 0x02)
11252               state->m_IRQ_count = state->m_IRQ_count_latch;
11253            break;
11254      }
11255   }
11256   shjy3_update(space->machine());
11257}
11258
11259/*************************************************************
11260
11261 UNL-603-5052
11262
11263 MMC3 + protection access in 0x4020 - 0x7fff
11264
11265 in MESS: Partial support
11266
11267 *************************************************************/
11268
11269WRITE8_HANDLER( unl_6035052_extra_w )
11270{
11271   nes_state *state = space->machine().driver_data<nes_state>();
11272   LOG_MMC(("unl_6035052_extra_w, offset: %04x, data: %02x\n", offset, data));
11273   state->m_mmc_latch1 = data & 0x03;
11274   if (state->m_mmc_latch1 == 1)
11275      state->m_mmc_latch1 = 2;
11276}
11277
11278READ8_HANDLER( unl_6035052_extra_r )
11279{
11280   nes_state *state = space->machine().driver_data<nes_state>();
11281   LOG_MMC(("unl_6035052_extra_r, offset: %04x\n", offset));
11282   return state->m_mmc_latch1;
11283}
11284
11285
11286/*************************************************************
11287
11288 BMC-POWERJOY
11289
11290 *************************************************************/
11291
11292static void pjoy84_prg_cb( running_machine &machine, int start, int bank )
11293{
11294   nes_state *state = machine.driver_data<nes_state>();
11295   UINT8 flip = (state->m_mmc3_latch & 0x40) ? 2 : 0;
11296
11297   if (!(state->m_mmc_reg[3] & 0x03))
11298      prg8_x(machine, start, bank);
11299   else if (start == flip)
11300   {
11301      if ((state->m_mmc_reg[3] & 0x03) == 0x03)
11302         prg32(machine, bank >> 2);
11303      else
11304      {
11305         prg16_89ab(machine, bank >> 1);
11306         prg16_cdef(machine, bank >> 1);
11307      }
11308   }
11309}
11310
11311static void pjoy84_chr_cb( running_machine &machine, int start, int bank, int source )
11312{
11313   nes_state *state = machine.driver_data<nes_state>();
11314
11315   if (!(state->m_mmc_reg[3] & 0x10))
11316      chr1_x(machine, start, bank, source);
11317}
11318
11319INLINE void pjoy84_set_base_mask( running_machine &machine )
11320{
11321   nes_state *state = machine.driver_data<nes_state>();
11322
11323   state->m_mmc_prg_base = ((state->m_mmc_reg[0] & (0x06 | BIT(state->m_mmc_reg[0], 6))) << 4) |
11324                  (BIT(state->m_mmc_reg[0], 4) << 7);
11325
11326   state->m_mmc_chr_base = ((~state->m_mmc_reg[0] << 0) & 0x080 & state->m_mmc_reg[2]) |
11327                  ((state->m_mmc_reg[0] << 4) & 0x080 & state->m_mmc_reg[0]) |
11328                  ((state->m_mmc_reg[0] << 3) & 0x100) |
11329                  ((state->m_mmc_reg[0] << 5) & 0x200);
11330
11331   state->m_mmc_prg_mask = BIT(state->m_mmc_reg[0], 6) ? 0x0f : 0x1f;
11332   state->m_mmc_chr_mask = BIT(state->m_mmc_reg[0], 7) ? 0x7f : 0xff;
11333}
11334
11335static WRITE8_HANDLER( pjoy84_m_w )
11336{
11337   nes_state *state = space->machine().driver_data<nes_state>();
11338   LOG_MMC(("pjoy84_m_w offset: %04x, data: %02x\n", offset, data));
11339
11340   switch (offset & 0x03)
11341   {
11342      case 0x00:
11343      case 0x03:
11344         if (state->m_mmc_reg[3] & 0x80)
11345            return;   // else we act as if offset & 3 = 1,2
11346      case 0x01:
11347      case 0x02:
11348         state->m_mmc_reg[offset & 0x03] = data;
11349         pjoy84_set_base_mask(space->machine());
11350         if (state->m_mmc_reg[3] & 0x10)
11351            chr8(space->machine(), (state->m_mmc_chr_base >> 3) | (state->m_mmc_reg[2] & 0x0f), state->m_mmc_chr_source);
11352         else
11353            mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
11354         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
11355         break;
11356   }
11357}
11358
11359/*************************************************************
11360
11361 SOMERI TEAM
11362
11363 iNES: mapper 116
11364
11365 Emulation note about regs in MESS: currently,
11366 - state->m_mmc_cmd1 represent the board mode
11367 - state->m_mmc_reg[n] for n=0,1,2,3 represent the MMC1 regs
11368 - state->m_mmc_prg_bank[n] for n=0,...,3 represent the MMC3 PRG banks
11369 - state->m_mmc_vrom_bank[n] for n=0,...,5 represent the MMC3 CHR banks
11370 - state->m_mmc_prg_bank[n] for n=4,5 represent the VRC2 PRG banks
11371 - state->m_mmc_vrom_bank[n] for n=6,...,13 represent the VRC2 CHR banks
11372
11373 In MESS: Preliminary support
11374
11375 *************************************************************/
11376
11377// MMC1 Mode emulation
11378static void someri_mmc1_set_prg( running_machine &machine )
11379{
11380   nes_state *state = machine.driver_data<nes_state>();
11381   UINT8 prg_mode = state->m_mmc_reg[0] & 0x0c;
11382   UINT8 prg_offset = state->m_mmc_reg[1] & 0x10;
11383
11384   switch (prg_mode)
11385   {
11386      case 0x00:
11387      case 0x04:
11388         prg32(machine, (prg_offset + state->m_mmc_reg[3]) >> 1);
11389         break;
11390      case 0x08:
11391         prg16_89ab(machine, prg_offset + 0);
11392         prg16_cdef(machine, prg_offset + state->m_mmc_reg[3]);
11393         break;
11394      case 0x0c:
11395         prg16_89ab(machine, prg_offset + state->m_mmc_reg[3]);
11396         prg16_cdef(machine, prg_offset + 0x0f);
11397         break;
11398   }
11399}
11400
11401static void someri_mmc1_set_chr( running_machine &machine )
11402{
11403   nes_state *state = machine.driver_data<nes_state>();
11404   UINT8 chr_mode = BIT(state->m_mmc_reg[0], 4);
11405
11406   if (chr_mode)
11407   {
11408      chr4_0(machine, state->m_mmc_reg[1] & 0x1f, state->m_mmc_chr_source);
11409      chr4_4(machine, state->m_mmc_reg[2] & 0x1f, state->m_mmc_chr_source);
11410   }
11411   else
11412      chr8(machine, (state->m_mmc_reg[1] & 0x1f) >> 1, state->m_mmc_chr_source);
11413}
11414
11415static WRITE8_HANDLER( someri_mmc1_w )
11416{
11417   nes_state *state = space->machine().driver_data<nes_state>();
11418
11419   assert(state->m_mmc_cmd1 == 2);
11420
11421   if (data & 0x80)
11422   {
11423      state->m_mmc1_count = 0;
11424      state->m_mmc1_latch = 0;
11425
11426      state->m_mmc_reg[0] |= 0x0c;
11427      someri_mmc1_set_prg(space->machine());
11428      return;
11429   }
11430
11431   if (state->m_mmc1_count < 5)
11432   {
11433      if (state->m_mmc1_count == 0) state->m_mmc1_latch = 0;
11434      state->m_mmc1_latch >>= 1;
11435      state->m_mmc1_latch |= (data & 0x01) ? 0x10 : 0x00;
11436      state->m_mmc1_count++;
11437   }
11438
11439   if (state->m_mmc1_count == 5)
11440   {
11441      switch (offset & 0x6000)
11442      {
11443         case 0x0000:
11444            state->m_mmc_reg[0] = state->m_mmc1_latch;
11445            switch (state->m_mmc_reg[0] & 0x03)
11446            {
11447            case 0: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
11448            case 1: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
11449            case 2: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
11450            case 3: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
11451            }
11452            someri_mmc1_set_chr(space->machine());
11453            someri_mmc1_set_prg(space->machine());
11454            break;
11455         case 0x2000:
11456            state->m_mmc_reg[1] = state->m_mmc1_latch;
11457            someri_mmc1_set_chr(space->machine());
11458            someri_mmc1_set_prg(space->machine());
11459            break;
11460         case 0x4000:
11461            state->m_mmc_reg[2] = state->m_mmc1_latch;
11462            someri_mmc1_set_chr(space->machine());
11463            break;
11464         case 0x6000:
11465            state->m_mmc_reg[3] = state->m_mmc1_latch;
11466            someri_mmc1_set_prg(space->machine());
11467            break;
11468      }
11469
11470      state->m_mmc1_count = 0;
11471   }
11472}
11473
11474// MMC3 Mode emulation
11475static WRITE8_HANDLER( someri_mmc3_w )
11476{
11477   nes_state *state = space->machine().driver_data<nes_state>();
11478   UINT8 mmc_helper, cmd;
11479
11480   assert(state->m_mmc_cmd1 == 1);
11481   switch (offset & 0x6001)
11482   {
11483      case 0x0000:
11484         mmc_helper = state->m_mmc3_latch ^ data;
11485         state->m_mmc3_latch = data;
11486
11487         if (mmc_helper & 0x40)
11488            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
11489
11490         if (mmc_helper & 0x80)
11491            mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
11492         break;
11493
11494      case 0x0001:
11495         cmd = state->m_mmc3_latch & 0x07;
11496         switch (cmd)
11497         {
11498         case 0: case 1:
11499         case 2: case 3: case 4: case 5:
11500            state->m_mmc_vrom_bank[cmd] = data;
11501            mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
11502            break;
11503         case 6:
11504         case 7:
11505            state->m_mmc_prg_bank[cmd - 6] = data;
11506            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
11507            break;
11508         }
11509         break;
11510
11511      case 0x2000:
11512         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
11513         break;
11514      case 0x2001: break;
11515      case 0x4000: state->m_IRQ_count_latch = data; break;
11516      case 0x4001: state->m_IRQ_count = 0; break;
11517      case 0x6000: state->m_IRQ_enable = 0; break;
11518      case 0x6001: state->m_IRQ_enable = 1; break;
11519   }
11520}
11521
11522// VRC2 Mode emulation
11523static WRITE8_HANDLER( someri_vrc2_w )
11524{
11525   nes_state *state = space->machine().driver_data<nes_state>();
11526   UINT8 bank, shift;
11527
11528   assert(state->m_mmc_cmd1 == 0);
11529
11530   if (offset < 0x1000)
11531   {
11532      state->m_mmc_prg_bank[4] = data;
11533      prg8_89(space->machine(), state->m_mmc_prg_bank[4]);
11534   }
11535   else if (offset < 0x2000)
11536   {
11537      switch (data & 0x03)
11538      {
11539         case 0x00: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
11540         case 0x01: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
11541         case 0x02: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
11542         case 0x03: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
11543      }
11544   }
11545   else if (offset < 0x3000)
11546   {
11547      state->m_mmc_prg_bank[5] = data;
11548      prg8_ab(space->machine(), state->m_mmc_prg_bank[5]);
11549   }
11550   else if (offset < 0x7000)
11551   {
11552      bank = ((offset & 0x7000) - 0x3000) / 0x0800 + BIT(offset, 1);
11553      shift = BIT(offset, 2) * 4;
11554      data = (data & 0x0f) << shift;
11555      state->m_mmc_vrom_bank[6 + bank] = data | state->m_mmc_chr_base;
11556      chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[6 + bank], CHRROM);
11557   }
11558}
11559
11560static WRITE8_HANDLER( someri_w )
11561{
11562   nes_state *state = space->machine().driver_data<nes_state>();
11563   LOG_MMC(("someri_w mode %d, offset: %04x, data: %02x\n", state->m_mmc_cmd1, offset, data));
11564
11565   switch (state->m_mmc_cmd1)
11566   {
11567      case 0x00: someri_vrc2_w(space, offset, data); break;
11568      case 0x01: someri_mmc3_w(space, offset, data); break;
11569      case 0x02: someri_mmc1_w(space, offset, data); break;
11570   }
11571}
11572
11573static void someri_mode_update( running_machine &machine )
11574{
11575   nes_state *state = machine.driver_data<nes_state>();
11576   int i;
11577
11578   switch (state->m_mmc_cmd1)
11579   {
11580      case 0x00:
11581         prg8_89(machine, state->m_mmc_prg_bank[4]);
11582         prg8_ab(machine, state->m_mmc_prg_bank[5]);
11583         for (i = 0; i < 8; i++)
11584            chr1_x(machine, i, state->m_mmc_vrom_bank[6 + i], CHRROM);
11585         break;
11586      case 0x01:
11587         mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
11588         mmc3_set_chr(machine, state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
11589         break;
11590      case 0x02:
11591         someri_mmc1_set_prg(machine);
11592         someri_mmc1_set_chr(machine);
11593         break;
11594   }
11595}
11596
11597static WRITE8_HANDLER( someri_l_w )
11598{
11599   nes_state *state = space->machine().driver_data<nes_state>();
11600   LOG_MMC(("someri_l_w, offset: %04x, data: %02x\n", offset, data));
11601   offset += 0x100;
11602
11603   if (offset & 0x100)
11604   {
11605      state->m_mmc_cmd1 = data & 0x03;
11606      state->m_mmc_chr_base = ((state->m_mmc_cmd1 & 0x04) << 6);
11607      if (state->m_mmc_cmd1 != 1)
11608         state->m_IRQ_enable = 0;
11609      someri_mode_update(space->machine());
11610   }
11611}
11612
11613#ifdef UNUSED_FUNCTION
11614/*************************************************************
11615
11616 FUJIYA Board - mapper 170 according to NEStopia
11617
11618 Which games are supposed to use this?
11619
11620 *************************************************************/
11621
11622static WRITE8_HANDLER( fujiya_m_w )
11623{
11624   nes_state *state = space->machine().driver_data<nes_state>();
11625   LOG_MMC(("fujiya_m_w, offset: %04x, data: %02x\n", offset, data));
11626   offset += 0x6000;
11627
11628   if (offset == 0x6502 || offset == 0x7000)
11629      state->m_mmc_latch1 = (data & 0x40) << 1;
11630}
11631
11632static READ8_HANDLER( fujiya_m_r )
11633{
11634   nes_state *state = space->machine().driver_data<nes_state>();
11635   LOG_MMC(("fujiya_m_r, offset: %04x\n", offset));
11636   offset += 0x6000;
11637
11638   if (offset == 0x7001 || offset == 0x7777)
11639      return state->m_mmc_latch1 | ((offset >> 8) & 0x7f);
11640
11641   return 0;
11642}
11643#endif
11644
11645
11646
11647
11648typedef void (*nes_ppu_latch)(device_t *device, offs_t offset);
11649
11650struct nes_memory_accessor
11651{
11652   write8_space_func write;
11653   const char        *write_name;
11654   read8_space_func  read;
11655   const char        *read_name;
11656};
11657
11658typedef struct _nes_pcb_intf  nes_pcb_intf;
11659struct _nes_pcb_intf
11660{
11661   int                     mmc_pcb;
11662   nes_memory_accessor     mmc_l;  /* $4100-$5fff read/write routines */
11663   nes_memory_accessor     mmc_m;  /* $6000-$7fff read/write routines */
11664   nes_memory_accessor     mmc_h;  /* $8000-$ffff read/write routines */
11665   nes_ppu_latch           mmc_ppu_latch;
11666   ppu2c0x_scanline_cb      mmc_scanline;
11667   ppu2c0x_hblank_cb      mmc_hblank;
11668};
11669
11670#define NES_NOACCESS \
11671{FUNC_NULL, FUNC_NULL}
11672
11673#define NES_READONLY(a) \
11674{FUNC_NULL, FUNC(a)}
11675
11676#define NES_WRITEONLY(a) \
11677{FUNC(a), FUNC_NULL}
11678
11679static WRITE8_HANDLER( dummy_l_w )
11680{
11681   logerror("write access, offset: %04x, data: %02x\n", offset + 0x4100, data);
11682}
11683
11684static WRITE8_HANDLER( dummy_m_w )
11685{
11686   logerror("write access, offset: %04x, data: %02x\n", offset + 0x6000, data);
11687}
11688
11689static WRITE8_HANDLER( dummy_w )
11690{
11691   logerror("write access, offset: %04x, data: %02x\n", offset + 0x8000, data);
11692}
11693
11694static READ8_HANDLER( dummy_l_r )
11695{
11696   logerror("read access, offset: %04x\n", offset + 0x4100);
11697   return 0x00;
11698}
11699
11700static READ8_HANDLER( dummy_m_r )
11701{
11702   logerror("read access, offset: %04x\n", offset + 0x6000);
11703   return 0x00;
11704}
11705
11706static READ8_HANDLER( dummy_r )
11707{
11708   logerror("read access, offset: %04x\n", offset + 0x8000);
11709   return 0x00;
11710}
11711
11712static const nes_pcb_intf nes_intf_list[] =
11713{
11714   { STD_NROM,             NES_NOACCESS, NES_NOACCESS, NES_NOACCESS,                         NULL, NULL, NULL },
11715   { HVC_FAMBASIC,         NES_NOACCESS, NES_NOACCESS, NES_NOACCESS,                         NULL, NULL, NULL },
11716   { GG_NROM,              NES_NOACCESS, NES_NOACCESS, NES_NOACCESS,                         NULL, NULL, NULL },
11717   { STD_UXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(uxrom_w),               NULL, NULL, NULL },
11718   { STD_UN1ROM,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(un1rom_w),              NULL, NULL, NULL },
11719   { STD_CPROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(cprom_w),               NULL, NULL, NULL },
11720   { STD_CNROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(cnrom_w),               NULL, NULL, NULL },
11721   { BANDAI_PT554,         NES_NOACCESS, NES_WRITEONLY(bandai_pt554_m_w), NES_WRITEONLY(cnrom_w), NULL, NULL, NULL },
11722   { STD_AXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(axrom_w),               NULL, NULL, NULL },
11723   { STD_PXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(pxrom_w),               mmc2_latch, NULL, NULL },
11724   { STD_FXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(fxrom_w),               mmc2_latch, NULL, NULL },
11725   { STD_BXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bxrom_w),               NULL, NULL, NULL },
11726   { STD_GXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(gxrom_w),               NULL, NULL, NULL },
11727   { STD_MXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(gxrom_w),               NULL, NULL, NULL },
11728   { STD_NXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ntbrom_w),              NULL, NULL, NULL },
11729   { SUNSOFT_DCS,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ntbrom_w),              NULL, NULL, NULL },
11730   { STD_JXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(jxrom_w),               NULL, NULL, jxrom_irq },
11731   { STD_SXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sxrom_w),               NULL, NULL, NULL },
11732   { STD_SOROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sxrom_w),               NULL, NULL, NULL },
11733   { STD_SXROM_A,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sxrom_w),               NULL, NULL, NULL },
11734   { STD_SOROM_A,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sxrom_w),               NULL, NULL, NULL },
11735   { STD_TXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txrom_w),               NULL, NULL, mmc3_irq },
11736   { STD_TVROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txrom_w),               NULL, NULL, mmc3_irq },
11737   { STD_TKROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txrom_w),               NULL, NULL, mmc3_irq },
11738   { STD_HKROM,            NES_NOACCESS, {FUNC(hkrom_m_w), FUNC(hkrom_m_r)}, NES_WRITEONLY(hkrom_w),     NULL, NULL, mmc3_irq },
11739   { STD_TQROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(tqrom_w),               NULL, NULL, mmc3_irq },
11740   { STD_TXSROM,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txsrom_w),              NULL, NULL, mmc3_irq },
11741   { STD_DXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(dxrom_w),               NULL, NULL, NULL },
11742   { STD_DRROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(dxrom_w),               NULL, NULL, NULL },
11743   { NAMCOT_34X3,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(dxrom_w),               NULL, NULL, NULL },
11744   { NAMCOT_3425,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(namcot3425_w),          NULL, NULL, NULL },
11745   { NAMCOT_3446,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(namcot3446_w),          NULL, NULL, NULL },
11746   { NAMCOT_3453,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(namcot3453_w),          NULL, NULL, NULL },
11747   { STD_EXROM,            {FUNC(exrom_l_w), FUNC(exrom_l_r)}, NES_NOACCESS, NES_NOACCESS,               NULL, NULL, mmc5_irq },
11748   { NES_QJ,               NES_NOACCESS, NES_WRITEONLY(qj_m_w), NES_WRITEONLY(txrom_w),      NULL, NULL, mmc3_irq },
11749   { PAL_ZZ,               NES_NOACCESS, NES_WRITEONLY(zz_m_w), NES_WRITEONLY(txrom_w),      NULL, NULL, mmc3_irq },
11750   { UXROM_CC,             NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(uxrom_cc_w),            NULL, NULL, NULL },
11751   //
11752   { DIS_74X139X74,        NES_NOACCESS, NES_WRITEONLY(dis_74x139x74_m_w), NES_NOACCESS,     NULL, NULL, NULL },
11753   { DIS_74X377,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(dis_74x377_w),          NULL, NULL, NULL },
11754   { DIS_74X161X161X32,    NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(dis_74x161x161x32_w),   NULL, NULL, NULL },
11755   { DIS_74X161X138,       NES_NOACCESS, NES_WRITEONLY(dis_74x161x138_m_w), NES_NOACCESS,    NULL, NULL, NULL },
11756   { BANDAI_LZ93,          NES_NOACCESS, NES_WRITEONLY(lz93d50_m_w), NES_WRITEONLY(lz93d50_w), NULL, NULL, bandai_lz_irq },
11757   { BANDAI_LZ93EX,        NES_NOACCESS, NES_WRITEONLY(lz93d50_m_w), NES_WRITEONLY(lz93d50_w), NULL, NULL, bandai_lz_irq },
11758   { BANDAI_FCG,           NES_NOACCESS, NES_WRITEONLY(lz93d50_m_w), NES_WRITEONLY(lz93d50_w), NULL, NULL, bandai_lz_irq },
11759   { BANDAI_DATACH,        NES_NOACCESS, NES_WRITEONLY(lz93d50_m_w), NES_WRITEONLY(lz93d50_w), NULL, NULL, bandai_lz_irq },
11760   { BANDAI_JUMP2,         NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(fjump2_w),              NULL, NULL, bandai_lz_irq },
11761   { BANDAI_KARAOKE,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bandai_ks_w),           NULL, NULL, NULL },
11762   { BANDAI_OEKAKIDS,      NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bandai_ok_w),           NULL, NULL, NULL },
11763   { IREM_G101,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(g101_w),                NULL, NULL, NULL },
11764   { IREM_LROG017,         NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(lrog017_w),             NULL, NULL, NULL },
11765   { IREM_H3001,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(h3001_w),               NULL, NULL, h3001_irq },
11766   { IREM_TAM_S1,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(tam_s1_w),              NULL, NULL, NULL },
11767   { IREM_HOLYDIV,         NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(irem_hd_w),             NULL, NULL, NULL },
11768   { JALECO_SS88006,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ss88006_w),             NULL, NULL, ss88006_irq },
11769   { JALECO_JF11,          NES_NOACCESS, NES_WRITEONLY(jf11_m_w), NES_NOACCESS,              NULL, NULL, NULL },
11770   { JALECO_JF13,          NES_NOACCESS, NES_WRITEONLY(jf13_m_w), NES_NOACCESS,              NULL, NULL, NULL },
11771   { JALECO_JF16,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(jf16_w),                NULL, NULL, NULL },
11772   { JALECO_JF17,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(jf17_w),                NULL, NULL, NULL },
11773   { JALECO_JF19,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(jf19_w),                NULL, NULL, NULL },
11774   { KONAMI_VRC1,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(konami_vrc1_w),         NULL, NULL, NULL },
11775   { KONAMI_VRC2,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(konami_vrc2_w),         NULL, NULL, NULL },
11776   { KONAMI_VRC3,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(konami_vrc3_w),         NULL, NULL, konami_irq },
11777   { KONAMI_VRC4,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(konami_vrc4_w),         NULL, NULL, konami_irq },
11778   { KONAMI_VRC6,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(konami_vrc6_w),         NULL, NULL, konami_irq },
11779   { KONAMI_VRC7,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(konami_vrc7_w),         NULL, NULL, konami_irq },
11780   { NAMCOT_163,           {FUNC(namcot163_l_w), FUNC(namcot163_l_r) }, NES_NOACCESS, NES_WRITEONLY(namcot163_w), NULL, NULL, namcot_irq },
11781   { SUNSOFT_1,            NES_NOACCESS, NES_WRITEONLY(sunsoft1_m_w), NES_NOACCESS,          NULL, NULL, NULL },
11782   { SUNSOFT_2,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sunsoft2_w),            NULL, NULL, NULL },
11783   { SUNSOFT_3,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sunsoft3_w),            NULL, NULL, sunsoft3_irq },
11784   { TAITO_TC0190FMC,      NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(tc0190fmc_w),           NULL, NULL, NULL },
11785   { TAITO_TC0190FMCP,     NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(tc0190fmc_p16_w),       NULL, NULL, mmc3_irq },
11786   { TAITO_X1_005,         NES_NOACCESS, {FUNC(x1005_m_w), FUNC(x1005_m_r)}, NES_NOACCESS,               NULL, NULL, NULL },
11787   { TAITO_X1_005_A,       NES_NOACCESS, {FUNC(x1005a_m_w), FUNC(x1005_m_r)}, NES_NOACCESS,              NULL, NULL, NULL },
11788   { TAITO_X1_017,         NES_NOACCESS, {FUNC(x1017_m_w), FUNC(x1017_m_r)}, NES_NOACCESS,               NULL, NULL, NULL },
11789   //
11790   { AGCI_50282,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(agci_50282_w),          NULL, NULL, NULL },
11791   { ACTENT_ACT52,         NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ae_act52_w),            NULL, NULL, NULL },
11792   { AVE_NINA01,           NES_NOACCESS, NES_WRITEONLY(nina01_m_w), NES_NOACCESS,            NULL, NULL, NULL },
11793   { AVE_NINA06,           NES_WRITEONLY(nina06_l_w), NES_NOACCESS, NES_NOACCESS,            NULL, NULL, NULL },
11794   { CNE_DECATHLON,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(cne_decathl_w),         NULL, NULL, NULL },
11795   { CNE_FSB,              NES_NOACCESS, NES_WRITEONLY(cne_fsb_m_w), NES_NOACCESS,           NULL, NULL, NULL },
11796   { CNE_SHLZ,             NES_WRITEONLY(cne_shlz_l_w), NES_NOACCESS, NES_NOACCESS,          NULL, NULL, NULL },
11797   { CALTRON_6IN1,         NES_NOACCESS, NES_WRITEONLY(caltron6in1_m_w), NES_WRITEONLY(caltron6in1_w),      NULL, NULL, NULL },
11798   { CAMERICA_BF9093,      NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bf9093_w),              NULL, NULL, NULL },
11799   { CAMERICA_BF9097,      NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bf9093_w),              NULL, NULL, NULL },
11800   { CAMERICA_BF9096,      NES_NOACCESS, NES_WRITEONLY(bf9096_w), NES_WRITEONLY(bf9096_w),   NULL, NULL, NULL },
11801   { CAMERICA_GOLDENFIVE,  NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(golden5_w),             NULL, NULL, NULL },
11802   { CONY_BOARD,           {FUNC(cony_l_w), FUNC(cony_l_r)}, NES_NOACCESS, NES_WRITEONLY(cony_w),        NULL, NULL, sunsoft3_irq },
11803   { DREAMTECH_BOARD,      NES_WRITEONLY(dreamtech_l_w), NES_NOACCESS, NES_NOACCESS,         NULL, NULL, NULL },
11804   { FUTUREMEDIA_BOARD,    NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(futuremedia_w),         NULL, NULL, futuremedia_irq },
11805   { FUKUTAKE_BOARD,       {FUNC(fukutake_l_w), FUNC(fukutake_l_r)}, NES_NOACCESS, NES_NOACCESS,         NULL, NULL, NULL },
11806   { GOUDER_37017,         {FUNC(gouder_sf4_l_w), FUNC(gouder_sf4_l_r)}, NES_NOACCESS, NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11807   { HENGEDIANZI_BOARD,    NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(henggedianzi_w),        NULL, NULL, NULL },
11808   { HENGEDIANZI_XJZB,     NES_WRITEONLY(heng_xjzb_l_w), NES_NOACCESS, NES_WRITEONLY(heng_xjzb_w), NULL, NULL, NULL },
11809   { HES6IN1_BOARD,        NES_WRITEONLY(hes6in1_l_w), NES_NOACCESS, NES_NOACCESS,           NULL, NULL, NULL },
11810   { HES_BOARD,            NES_WRITEONLY(hes_l_w), NES_NOACCESS, NES_NOACCESS,               NULL, NULL, NULL },
11811   { HOSENKAN_BOARD,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(hosenkan_w),            NULL, NULL, mmc3_irq },
11812   { KAISER_KS7058,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ks7058_w),              NULL, NULL, NULL },
11813   { KAISER_KS7022,        NES_NOACCESS, NES_NOACCESS, {FUNC(ks7022_w), FUNC(ks7022_r)},                 NULL, NULL, NULL },
11814   { KAISER_KS7032,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ks7032_w),              NULL, NULL, ks7032_irq },
11815   { KAISER_KS202,         NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ks202_w),               NULL, NULL, ks7032_irq },
11816   { KAISER_KS7017,      NES_WRITEONLY(ks7017_l_w), NES_NOACCESS, NES_NOACCESS,            NULL, NULL, mmc_fds_irq },
11817   { KAY_PANDAPRINCE,      {FUNC(kay_pp_l_w), FUNC(kay_pp_l_r)}, NES_NOACCESS, NES_WRITEONLY(kay_pp_w),  NULL, NULL, mmc3_irq },
11818   { KASING_BOARD,         NES_NOACCESS, NES_WRITEONLY(kasing_m_w), NES_WRITEONLY(txrom_w),  NULL, NULL, mmc3_irq },
11819   { SACHEN_74LS374,       {FUNC(sachen_74x374_l_w), FUNC(sachen_74x374_l_r)}, NES_NOACCESS, NES_NOACCESS, NULL, NULL, NULL },
11820   { SACHEN_74LS374_A,     NES_WRITEONLY(sachen_74x374a_l_w), NES_NOACCESS, NES_NOACCESS,    NULL, NULL, NULL },
11821   { SACHEN_8259A,         NES_WRITEONLY(s8259_l_w), NES_WRITEONLY(s8259_m_w), NES_NOACCESS, NULL, NULL, NULL },
11822   { SACHEN_8259B,         NES_WRITEONLY(s8259_l_w), NES_WRITEONLY(s8259_m_w), NES_NOACCESS, NULL, NULL, NULL },
11823   { SACHEN_8259C,         NES_WRITEONLY(s8259_l_w), NES_WRITEONLY(s8259_m_w), NES_NOACCESS, NULL, NULL, NULL },
11824   { SACHEN_8259D,         NES_WRITEONLY(s8259_l_w), NES_WRITEONLY(s8259_m_w), NES_NOACCESS, NULL, NULL, NULL },
11825   { SACHEN_SA009,         NES_WRITEONLY(sa009_l_w), NES_NOACCESS, NES_NOACCESS,             NULL, NULL, NULL },
11826   { SACHEN_SA0036,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sa0036_w),              NULL, NULL, NULL },
11827   { SACHEN_SA0037,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sa0037_w),              NULL, NULL, NULL },
11828   { SACHEN_SA72007,       NES_WRITEONLY(sa72007_l_w), NES_NOACCESS, NES_NOACCESS,           NULL, NULL, NULL },
11829   { SACHEN_SA72008,       NES_WRITEONLY(sa72008_l_w), NES_NOACCESS, NES_NOACCESS,           NULL, NULL, NULL },
11830   { SACHEN_TCA01,         NES_READONLY(tca01_l_r), NES_NOACCESS, NES_NOACCESS,              NULL, NULL, NULL },
11831   { SACHEN_TCU01,         NES_WRITEONLY(tcu01_l_w), NES_WRITEONLY(tcu01_m_w), NES_WRITEONLY(tcu01_w), NULL, NULL, NULL },
11832   { SACHEN_TCU02,         {FUNC(tcu02_l_w), FUNC(tcu02_l_r)}, NES_NOACCESS, NES_NOACCESS,               NULL, NULL, NULL },
11833   { SUBOR_TYPE0,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(subor0_w),              NULL, NULL, NULL },
11834   { SUBOR_TYPE1,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(subor1_w),              NULL, NULL, NULL },
11835   { MAGICSERIES_MD,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(magics_md_w),           NULL, NULL, NULL },
11836   { NANJING_BOARD,        {FUNC(nanjing_l_w), FUNC(nanjing_l_r)}, NES_NOACCESS, NES_NOACCESS,           NULL, NULL, nanjing_irq },
11837   { NITRA_TDA,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(nitra_w),               NULL, NULL, mmc3_irq },
11838   { NTDEC_ASDER,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ntdec_asder_w),         NULL, NULL, NULL },
11839   { NTDEC_FIGHTINGHERO,   NES_NOACCESS, NES_WRITEONLY(ntdec_fh_m_w), NES_NOACCESS,          NULL, NULL, NULL },
11840   { OPENCORP_DAOU306,     NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(daou306_w),             NULL, NULL, NULL },
11841   { RCM_GS2015,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(gs2015_w),              NULL, NULL, NULL },
11842   { RCM_TETRISFAMILY,     NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(rcm_tf_w),              NULL, NULL, NULL },
11843   { REXSOFT_DBZ5,         {FUNC(rex_dbz_l_w), FUNC(rex_dbz_l_r)}, NES_READONLY(rex_dbz_l_r), NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11844   { REXSOFT_SL1632,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(rex_sl1632_w),          NULL, NULL, mmc3_irq },
11845   { RUMBLESTATION_BOARD,  NES_NOACCESS, NES_WRITEONLY(rumblestation_m_w), NES_WRITEONLY(rumblestation_w),      NULL, NULL, NULL },
11846   { SOMERI_SL12,          NES_WRITEONLY(someri_l_w), NES_NOACCESS, NES_WRITEONLY(someri_w), NULL, NULL, mmc3_irq },
11847   { SUPERGAME_BOOGERMAN,  NES_WRITEONLY(sgame_boog_l_w), NES_WRITEONLY(sgame_boog_m_w), NES_WRITEONLY(sgame_boog_w), NULL, NULL, mmc3_irq },
11848   { SUPERGAME_LIONKING,   NES_NOACCESS, NES_WRITEONLY(sgame_lion_m_w), NES_WRITEONLY(sgame_lion_w), NULL, NULL, mmc3_irq },
11849   { TENGEN_800008,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(tengen_800008_w),       NULL, NULL, NULL },
11850   { TENGEN_800032,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(tengen_800032_w),       NULL, NULL, tengen_800032_irq },
11851   { TENGEN_800037,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(tengen_800037_w),       NULL, NULL, tengen_800032_irq },
11852   { TXC_22211A,           {FUNC(txc_22211_l_w), FUNC(txc_22211_l_r)}, NES_NOACCESS, NES_WRITEONLY(txc_22211_w), NULL, NULL, NULL },
11853   { TXC_22211B,           {FUNC(txc_22211_l_w), FUNC(txc_22211_l_r)}, NES_NOACCESS, NES_WRITEONLY(txc_22211b_w), NULL, NULL, NULL },
11854   { TXC_22211C,           {FUNC(txc_22211_l_w), FUNC(txc_22211c_l_r)}, NES_NOACCESS, NES_WRITEONLY(txc_22211_w), NULL, NULL, NULL },
11855   { TXC_TW,               NES_WRITEONLY(txc_tw_l_w), NES_WRITEONLY(txc_tw_m_w), NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11856   { TXC_STRIKEWOLF,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txc_strikewolf_w),      NULL, NULL, NULL },
11857   { TXC_MXMDHTWO,         NES_READONLY(txc_mxmdhtwo_l_r), NES_NOACCESS, NES_WRITEONLY(txc_mxmdhtwo_w), NULL, NULL, NULL },
11858   { WAIXING_TYPE_A,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_a_w),           NULL, NULL, mmc3_irq },
11859   { WAIXING_TYPE_A_1,     NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_a_w),           NULL, NULL, mmc3_irq },
11860   { WAIXING_TYPE_B,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_a_w),           NULL, NULL, mmc3_irq },
11861   { WAIXING_TYPE_C,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_a_w),           NULL, NULL, mmc3_irq },
11862   { WAIXING_TYPE_D,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_a_w),           NULL, NULL, mmc3_irq },
11863   { WAIXING_TYPE_E,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_a_w),           NULL, NULL, mmc3_irq },
11864   { WAIXING_TYPE_F,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_f_w),           NULL, NULL, mmc3_irq },
11865   { WAIXING_TYPE_G,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_g_w),           NULL, NULL, mmc3_irq },
11866   { WAIXING_TYPE_H,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_h_w),           NULL, NULL, mmc3_irq },
11867   { WAIXING_TYPE_I,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txrom_w),               NULL, NULL, mmc3_irq },   // this is MMC3 + possibly additional WRAM added in 0x5000-0x5fff
11868   { WAIXING_TYPE_J,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txrom_w),               NULL, NULL, mmc3_irq },   // this is MMC3 + possibly additional WRAM added in 0x5000-0x5fff
11869   { WAIXING_SGZ,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_sgz_w),         NULL, NULL, konami_irq },
11870   { WAIXING_SGZLZ,        NES_WRITEONLY(waixing_sgzlz_l_w), NES_NOACCESS, NES_NOACCESS,     NULL, NULL, NULL },
11871   { WAIXING_FFV,          NES_WRITEONLY(waixing_ffv_l_w), NES_NOACCESS, NES_NOACCESS,       NULL, NULL, NULL },
11872   { WAIXING_ZS,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_zs_w),          NULL, NULL, NULL },
11873   { WAIXING_DQ8,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_dq8_w),         NULL, NULL, NULL },
11874   { WAIXING_SECURITY,     NES_WRITEONLY(waixing_sec_l_w), NES_NOACCESS, NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11875   { WAIXING_SH2,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txrom_w),               NULL, NULL, mmc3_irq },   // this is MMC3 + possibly additional WRAM added in 0x5000-0x5fff
11876   { WAIXING_PS2,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_ps2_w),         NULL, NULL, NULL },
11877   { UNL_8237,             NES_WRITEONLY(unl_8237_l_w), NES_NOACCESS, NES_WRITEONLY(unl_8237_w),      NULL, NULL, mmc3_irq },
11878   { UNL_AX5705,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(unl_ax5705_w),          NULL, NULL, NULL },
11879   { UNL_CC21,             NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(unl_cc21_w),            NULL, NULL, NULL },
11880   { UNL_KOF97,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(unl_kof97_w),           NULL, NULL, mmc3_irq },
11881   { UNL_T230,             NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(unl_t230_w),            NULL, NULL, konami_irq },
11882   { UNL_KOF96,            {FUNC(kof96_l_w), FUNC(kof96_l_r)}, NES_NOACCESS, NES_WRITEONLY(kof96_w),     NULL, NULL, mmc3_irq },
11883   { UNL_MK2,              NES_NOACCESS, NES_WRITEONLY(mk2_m_w), NES_NOACCESS,               NULL, NULL, mmc3_irq },
11884   { UNL_N625092,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(n625092_w),             NULL, NULL, NULL },
11885   { UNL_SC127,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sc127_w),               NULL, NULL, sc127_irq },
11886   { UNL_SMB2J,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(smb2j_w),               NULL, NULL, NULL },
11887   { UNL_SUPERFIGHTER3,    NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(unl_sf3_w),             NULL, NULL, mmc3_irq },
11888   { UNL_XZY,              NES_WRITEONLY(unl_xzy_l_w), NES_NOACCESS, NES_NOACCESS,           NULL, NULL, NULL },
11889   { UNL_RACERMATE,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(unl_racmate_w),         NULL, NULL, NULL },
11890   { UNL_STUDYNGAME,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sng32_w),               NULL, NULL, NULL },
11891   { UNL_603_5052,         {FUNC(unl_6035052_extra_w), FUNC(unl_6035052_extra_r)}, {FUNC(unl_6035052_extra_w), FUNC(unl_6035052_extra_r)}, NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11892   { UNL_EDU2K,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(edu2k_w),               NULL, NULL, NULL },
11893   { UNL_SHJY3,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(shjy3_w),               NULL, NULL, shjy3_irq },
11894   { UNL_H2288,            {FUNC(h2288_l_w), FUNC(h2288_l_r)}, NES_NOACCESS, NES_WRITEONLY(h2288_w),     NULL, NULL, mmc3_irq },
11895   //
11896   { BTL_AISENSHINICOL,    NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(btl_mariobaby_w),       NULL, NULL, NULL },
11897   { BTL_DRAGONNINJA,      NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(btl_dn_w),              NULL, NULL, btl_dn_irq },
11898   { BTL_MARIOBABY,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(btl_mariobaby_w),       NULL, NULL, NULL },
11899   { BTL_SMB2A,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(btl_smb2a_w),           NULL, NULL, btl_smb2a_irq },
11900   { BTL_SMB2B,            NES_WRITEONLY(smb2jb_l_w), NES_NOACCESS, NES_NOACCESS,            NULL, NULL, smb2jb_irq },
11901   { BTL_SMB3,             NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(btl_smb3_w),            NULL, NULL, btl_smb3_irq },
11902   { BTL_SUPERBROS11,      NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(btl_smb11_w),           NULL, NULL, mmc3_irq },
11903   { BTL_TOBIDASE,         NES_WRITEONLY(btl_tobi_l_w), NES_NOACCESS, NES_NOACCESS,          NULL, NULL, NULL },
11904   { BTL_PIKACHUY2K,       NES_NOACCESS, {FUNC(btl_pika_y2k_m_w), FUNC(btl_pika_y2k_m_r)}, NES_WRITEONLY(btl_pika_y2k_w),  NULL, NULL, mmc3_irq },
11905   { WHIRLWIND_2706,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(whirl2706_w),           NULL, NULL, NULL },
11906   //
11907   { BMC_190IN1,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_190in1_w),          NULL, NULL, NULL },
11908   { BMC_A65AS,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_a65as_w),           NULL, NULL, NULL },
11909   { BMC_GS2004,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_gs2004_w),          NULL, NULL, NULL },
11910   { BMC_GS2013,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_gs2013_w),          NULL, NULL, NULL },
11911   { BMC_NOVELDIAMOND,     NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(novel1_w),              NULL, NULL, NULL },
11912   { BMC_9999999IN1,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(novel2_w),              NULL, NULL, NULL },
11913   { BMC_T262,             NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_t262_w),            NULL, NULL, NULL },
11914   { BMC_WS,               NES_NOACCESS, NES_WRITEONLY(bmc_ws_m_w), NES_NOACCESS,            NULL, NULL, NULL },
11915   { BMC_GKA,              NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_gka_w),             NULL, NULL, NULL },
11916   { BMC_GKB,              NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_gkb_w),             NULL, NULL, NULL },
11917   { BMC_SUPER_700IN1,     NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_super700in1_w),     NULL, NULL, NULL },
11918   { BMC_36IN1,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_36in1_w),           NULL, NULL, NULL },
11919   { BMC_21IN1,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_21in1_w),           NULL, NULL, NULL },
11920   { BMC_150IN1,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_150in1_w),          NULL, NULL, NULL },
11921   { BMC_35IN1,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_35in1_w),           NULL, NULL, NULL },
11922   { BMC_64IN1,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_64in1_w),           NULL, NULL, NULL },
11923   { BMC_SUPERHIK_300IN1,  NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_hik300_w),          NULL, NULL, NULL },
11924   { BMC_SUPERGUN_20IN1,   NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(supergun20in1_w),       NULL, NULL, NULL },
11925   { BMC_72IN1,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_72in1_w),           NULL, NULL, NULL },
11926   { BMC_76IN1,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_76in1_w),           NULL, NULL, NULL },
11927   { BMC_SUPER_42IN1,      NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_76in1_w),           NULL, NULL, NULL },
11928   { BMC_1200IN1,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_1200in1_w),         NULL, NULL, NULL },
11929   { BMC_31IN1,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_31in1_w),           NULL, NULL, NULL },
11930   { BMC_22GAMES,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_22g_w),             NULL, NULL, NULL },
11931   { BMC_20IN1,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_20in1_w),           NULL, NULL, NULL },
11932   { BMC_110IN1,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_110in1_w),          NULL, NULL, NULL },
11933   { BMC_64IN1NR,          NES_WRITEONLY(bmc_64in1nr_l_w), NES_NOACCESS, NES_WRITEONLY(bmc_64in1nr_w), NULL, NULL, NULL },
11934   { BMC_S24IN1SC03,       NES_WRITEONLY(bmc_s24in1sc03_l_w), NES_NOACCESS, NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11935   { BMC_HIK8IN1,          NES_NOACCESS, NES_WRITEONLY(bmc_hik8_m_w), NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11936   { BMC_SUPERHIK_4IN1,    NES_NOACCESS, NES_WRITEONLY(bmc_hik4in1_m_w), NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11937   { BMC_SUPERBIG_7IN1,    NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_sbig7_w),           NULL, NULL, mmc3_irq },
11938   { BMC_MARIOPARTY_7IN1,  NES_NOACCESS, NES_WRITEONLY(bmc_mario7in1_m_w), NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11939   { BMC_FAMILY_4646B,     NES_NOACCESS, NES_WRITEONLY(bmc_family4646_m_w), NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11940   { BMC_15IN1,            NES_NOACCESS, NES_WRITEONLY(bmc_15in1_m_w), NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11941   { BMC_BALLGAMES_11IN1,  NES_NOACCESS, NES_WRITEONLY(bmc_ball11_m_w), NES_WRITEONLY(bmc_ball11_w), NULL, NULL, NULL },
11942   { BMC_GOLDENCARD_6IN1,  NES_WRITEONLY(bmc_gc6in1_l_w), NES_NOACCESS, NES_WRITEONLY(bmc_gc6in1_w), NULL, NULL, mmc3_irq },
11943   { BMC_VT5201,           NES_NOACCESS, NES_NOACCESS, {FUNC(bmc_vt5201_w), FUNC(bmc_vt5201_r)},         NULL, NULL, NULL },
11944   { BMC_BENSHENG_BS5,     NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_bs5_w),             NULL, NULL, NULL },
11945   { BMC_810544,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_810544_w),          NULL, NULL, NULL },
11946   { BMC_NTD_03,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_ntd03_w),           NULL, NULL, NULL },
11947   { BMC_G63IN1,           NES_NOACCESS, NES_NOACCESS, {FUNC(bmc_gb63_w), FUNC(bmc_gb63_r)},             NULL, NULL, NULL },
11948   { BMC_FK23C,            NES_WRITEONLY(fk23c_l_w), NES_NOACCESS, NES_WRITEONLY(fk23c_w),   NULL, NULL, mmc3_irq },
11949   { BMC_FK23CA,           NES_WRITEONLY(fk23c_l_w), NES_NOACCESS, NES_WRITEONLY(fk23c_w),   NULL, NULL, mmc3_irq },
11950   { BMC_PJOY84,           NES_NOACCESS, NES_WRITEONLY(pjoy84_m_w), NES_WRITEONLY(txrom_w),  NULL, NULL, mmc3_irq },
11951   //
11952   { FFE_MAPPER6,          NES_WRITEONLY(mapper6_l_w), NES_NOACCESS, NES_WRITEONLY(mapper6_w), NULL, NULL, ffe_irq },
11953   { FFE_MAPPER8,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(mapper8_w),             NULL, NULL, NULL },
11954   { FFE_MAPPER17,         NES_WRITEONLY(mapper17_l_w), NES_NOACCESS, NES_NOACCESS,          NULL, NULL, ffe_irq },
11955   // for debug and development
11956   { UNKNOWN_BOARD,        {FUNC(dummy_l_w), FUNC(dummy_l_r)}, {FUNC(dummy_m_w), FUNC(dummy_m_r)}, {FUNC(dummy_w), FUNC(dummy_r)}, NULL, NULL, NULL },
11957   //
11958   { UNSUPPORTED_BOARD,    NES_NOACCESS, NES_NOACCESS, NES_NOACCESS,                         NULL, NULL, NULL },
11959   //
11960};
11961
11962const nes_pcb_intf *nes_pcb_intf_lookup( int pcb_id )
11963{
11964   int i;
11965   for (i = 0; i < ARRAY_LENGTH(nes_intf_list); i++)
11966   {
11967      if (nes_intf_list[i].mmc_pcb == pcb_id)
11968         return &nes_intf_list[i];
11969   }
11970   return NULL;
11971}
11972
11973void pcb_handlers_setup( running_machine &machine )
11974{
11975   nes_state *state = machine.driver_data<nes_state>();
11976   const nes_pcb_intf *intf = nes_pcb_intf_lookup(state->m_pcb_id);
11977   device_t *ppu = machine.device("ppu");
11978
11979   if (intf == NULL)
11980      fatalerror("Missing PCB interface\n");
11981
11982   if (intf)
11983   {
11984      state->m_mmc_write_low = intf->mmc_l.write;
11985      state->m_mmc_write_low_name = intf->mmc_l.write_name;
11986      state->m_mmc_write_mid = intf->mmc_m.write;
11987      state->m_mmc_write_mid_name = intf->mmc_m.write_name;
11988      state->m_mmc_write = intf->mmc_h.write;
11989      state->m_mmc_write_name = intf->mmc_h.write_name;
11990      state->m_mmc_read_low = intf->mmc_l.read;
11991      state->m_mmc_read_low_name = intf->mmc_l.read_name;
11992      state->m_mmc_read_mid = intf->mmc_m.read;   // in progress
11993      state->m_mmc_read_mid_name = intf->mmc_m.read_name;
11994      state->m_mmc_read = intf->mmc_h.read;   // in progress
11995      state->m_mmc_read_name = intf->mmc_h.read_name;
11996      ppu2c0x_set_latch(ppu, intf->mmc_ppu_latch);
11997   }
11998   else
11999   {
12000      logerror("PCB %d is not yet supported, defaulting to no mapper.\n", state->m_pcb_id);
12001      state->m_mmc_write_low = NULL;
12002      state->m_mmc_write_mid = NULL;
12003      state->m_mmc_write = NULL;
12004      state->m_mmc_read_low = NULL;
12005      state->m_mmc_read_mid = NULL;   // in progress
12006      state->m_mmc_read = NULL;   // in progress
12007      ppu2c0x_set_latch(ppu, NULL);
12008   }
12009
12010   state->m_mmc3_prg_cb = prg8_x;
12011   state->m_mmc3_chr_cb = chr1_x;
12012
12013   switch (state->m_pcb_id)
12014   {
12015      case STD_TXSROM:
12016         state->m_mmc3_chr_cb = txsrom_chr_cb;
12017         break;
12018      case GOUDER_37017:
12019         state->m_mmc3_prg_cb = gouder_sf4_prg_cb;
12020         break;
12021      case KASING_BOARD:
12022         state->m_mmc3_prg_cb = kasing_prg_cb;
12023         break;
12024      case REXSOFT_DBZ5:
12025         state->m_mmc3_chr_cb = rex_dbz_chr_cb;
12026         break;
12027      case TXC_TW:
12028         state->m_mmc3_prg_cb = txc_tw_prg_cb;
12029         break;
12030      case WAIXING_TYPE_A:
12031         state->m_mmc3_chr_cb = waixing_a_chr_cb;
12032         break;
12033      case WAIXING_TYPE_A_1:
12034         state->m_mmc3_chr_cb = waixing_a1_chr_cb;
12035         break;
12036      case WAIXING_TYPE_B:
12037         state->m_mmc3_chr_cb = waixing_b_chr_cb;
12038         break;
12039      case WAIXING_TYPE_C:
12040         state->m_mmc3_chr_cb = waixing_c_chr_cb;
12041         break;
12042      case WAIXING_TYPE_D:
12043         state->m_mmc3_chr_cb = waixing_d_chr_cb;
12044         break;
12045      case WAIXING_TYPE_E:
12046         state->m_mmc3_chr_cb = waixing_e_chr_cb;
12047         break;
12048      case WAIXING_TYPE_G:
12049         state->m_mmc3_chr_cb = waixing_g_chr_cb;
12050         break;
12051      case WAIXING_TYPE_H:
12052         state->m_mmc3_chr_cb = waixing_h_chr_cb;
12053         break;
12054      case WAIXING_SECURITY:
12055         state->m_mmc3_prg_cb = waixing_sec_prg_cb;
12056         state->m_mmc3_chr_cb = waixing_sec_chr_cb;
12057         break;
12058      case WAIXING_SH2:
12059         state->m_mmc3_chr_cb = waixing_sh2_chr_cb;
12060         break;
12061      case UNL_8237:
12062         state->m_mmc3_prg_cb = unl_8237_prg_cb;
12063         state->m_mmc3_chr_cb = unl_8237_chr_cb;
12064         break;
12065      case UNL_H2288:
12066         state->m_mmc3_prg_cb = h2288_prg_cb;
12067         break;
12068      case SUPERGAME_BOOGERMAN:
12069         state->m_mmc3_prg_cb = sgame_boog_prg_cb;
12070         state->m_mmc3_chr_cb = sgame_boog_chr_cb;
12071         break;
12072      case UNL_KOF96:
12073         state->m_mmc3_prg_cb = kof96_prg_cb;
12074         state->m_mmc3_chr_cb = kof96_chr_cb;
12075         break;
12076      case KAY_PANDAPRINCE:
12077         state->m_mmc3_prg_cb = kay_pp_prg_cb;
12078         state->m_mmc3_chr_cb = kay_pp_chr_cb;
12079         break;
12080      case BMC_FK23C:
12081         state->m_mmc3_prg_cb = fk23c_prg_cb;
12082         state->m_mmc3_chr_cb = fk23c_chr_cb;
12083         break;
12084      case BMC_S24IN1SC03:
12085         state->m_mmc3_prg_cb = bmc_s24in1sc03_prg_cb;
12086         state->m_mmc3_chr_cb = bmc_s24in1sc03_chr_cb;
12087         break;
12088      case BMC_PJOY84:
12089         state->m_mmc3_prg_cb = pjoy84_prg_cb;
12090         state->m_mmc3_chr_cb = pjoy84_chr_cb;
12091         break;
12092   }
12093}
12094
12095/*************************************************************
12096
12097 pcb_initialize
12098
12099 Initialize all the necessary registers and quantities for
12100 emulation of each board
12101
12102 *************************************************************/
12103
12104/* this is used by many boards (MMC3, MMC6 + most MMC3 pirate clone boards) */
12105static void mmc3_common_initialize( running_machine &machine, int prg_mask, int chr_mask, int IRQ_type )
12106{
12107   nes_state *state = machine.driver_data<nes_state>();
12108
12109   state->m_mmc3_alt_irq = IRQ_type;      // later MMC3 boards seem to use MMC6-type IRQ... more investigations are in progress at NESDev...
12110   state->m_mmc_prg_bank[0] = state->m_mmc_prg_bank[2] = 0xfe;   // prg_bank[2] & prg_bank[3] remain always the same in most MMC3 variants
12111   state->m_mmc_prg_bank[1] = state->m_mmc_prg_bank[3] = 0xff;   // but some pirate clone mappers change them after writing certain registers
12112   state->m_mmc3_latch = 0;
12113   state->m_mmc3_wram_protect = 0x80;
12114   state->m_mmc_prg_base = state->m_mmc_chr_base = 0;
12115   state->m_mmc_prg_mask = prg_mask;
12116   state->m_mmc_chr_mask = chr_mask;
12117   mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
12118   mmc3_set_chr(machine, state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
12119}
12120
12121// WIP code
12122static int pcb_initialize( running_machine &machine, int idx )
12123{
12124   nes_state *state = machine.driver_data<nes_state>();
12125   int err = 0, i;
12126
12127   /* basic PRG config */
12128   prg32(machine, 0);
12129
12130   /* some boards will not use this, but directly CHRROM (resp. CHRRAM) if the board only has VROM (resp. VRAM) */
12131   state->m_mmc_chr_source = state->m_chr_chunks ? CHRROM : CHRRAM;
12132   chr8(machine, 0, state->m_mmc_chr_source);
12133
12134   /* Here, we init a few helpers: 4 prg banks and 16 chr banks - some mappers use them */
12135   for (i = 0; i < 4; i++)
12136      state->m_mmc_prg_bank[i] = 0;
12137   for (i = 0; i < 16; i++)
12138      state->m_mmc_vrom_bank[i] = 0;
12139   for (i = 0; i < 16; i++)
12140      state->m_mmc_extra_bank[i] = 0;
12141
12142   state->m_mmc_latch1 = 0;
12143   state->m_mmc_latch2 = 0;
12144
12145   /* Finally, we init IRQ-related quantities. */
12146   state->m_IRQ_enable = state->m_IRQ_enable_latch = 0;
12147   state->m_IRQ_count = state->m_IRQ_count_latch = 0;
12148   state->m_IRQ_toggle = 0;
12149
12150   switch (idx)
12151   {
12152         /* many boards only needs PRG to point at first 32k and CHR at first 8k */
12153      case STD_NROM:   // mapper 0
12154      case HVC_FAMBASIC:
12155      case GG_NROM:
12156      case UXROM_CC:   // mapper 180
12157      case STD_CNROM:   // mapper 3, 185
12158      case BANDAI_PT554:
12159      case TENGEN_800008:
12160      case STD_BXROM:   // mapper 34
12161      case STD_GXROM:   // mapper 66
12162      case STD_MXROM:
12163      case BANDAI_OEKAKIDS:   // mapper 96
12164      case JALECO_JF11:   // mapper 140
12165      case JALECO_JF13:   // mapper 86
12166      case JALECO_JF19:   // mapper 92
12167      case DIS_74X377:   // mapper 11
12168      case DIS_74X161X138:   // mapper 38
12169      case CALTRON_6IN1:   // mapper 41
12170      case TXC_STRIKEWOLF:   // mapper 36
12171      case UNL_STUDYNGAME:   // mapper 39
12172      case RUMBLESTATION_BOARD:   // mapper 46
12173      case BMC_GKB:   // mapper 58
12174      case RCM_TETRISFAMILY:   // mapper 61
12175      case BMC_SUPER_700IN1:   // mapper 62
12176      case MAGICSERIES_MD:   // mapper 107
12177      case HES_BOARD:   // mapper 113
12178      case HES6IN1_BOARD:   // mapper 113
12179      case SACHEN_SA72008:   // mapper 133
12180      case SACHEN_TCU02:   // mapper 136
12181      case SACHEN_SA72007:   // mapper 145
12182      case SACHEN_TCU01:   // mapper 147
12183      case SACHEN_SA009:   // mapper 160
12184      case SACHEN_SA0037:   // mapper 148
12185      case SACHEN_SA0036:   // mapper 149
12186      case AGCI_50282:   // mapper 144
12187      case KAISER_KS7058:   // mapper 171
12188      case HENGEDIANZI_BOARD:   // mapper 177
12189      case WAIXING_SGZLZ:   // mapper 178
12190      case HENGEDIANZI_XJZB:   // mapper 179
12191      case BMC_21IN1:   // mapper 201
12192      case BMC_9999999IN1:   // mapper 213
12193      case RCM_GS2015:   // mapper 216
12194      case BMC_72IN1:   // mapper 225
12195      case BMC_76IN1:   // mapper 226
12196      case BMC_SUPER_42IN1:   // mapper 226
12197      case ACTENT_ACT52:   // mapper 228
12198      case CNE_SHLZ:   // mapper 240
12199      case TXC_MXMDHTWO:   // mapper 241
12200      case WAIXING_ZS:   // mapper 242
12201      case WAIXING_DQ8:   // mapper 242
12202      case CNE_DECATHLON:   // mapper 244
12203      case UNL_CC21:
12204      case BMC_VT5201:
12205      case BMC_WS:
12206      case UNL_EDU2K:
12207         break;
12208
12209         /* other boards need additional initialization */
12210      case STD_UXROM:   // mapper 2
12211      case STD_UN1ROM:   // mapper 94
12212      case STD_JXROM:      // mapper 69
12213      case SUNSOFT_5B:
12214      case SUNSOFT_FME7:
12215      case NAMCOT_3425:   // mapper 95
12216      case DIS_74X139X74:   // mapper 87
12217      case DIS_74X161X161X32:   // mapper 152 & 70
12218      case BANDAI_LZ93:   // mapper 16, 157
12219      case BANDAI_LZ93EX:   // same + EEPROM
12220      case BANDAI_DATACH:
12221      case BANDAI_FCG:
12222      case IREM_HOLYDIV:   // mapper 78
12223      case IREM_G101:   // mapper 32
12224      case IREM_H3001:   // mapper 65
12225      case JALECO_SS88006:   // mapper 18
12226      case JALECO_JF16:   // mapper 78
12227      case JALECO_JF17:   // mapper 72
12228      case KONAMI_VRC1:   // mapper 75
12229      case KONAMI_VRC2:
12230      case KONAMI_VRC3:   // mapper 73
12231      case KONAMI_VRC4:
12232      case KONAMI_VRC6:
12233      case SUNSOFT_3:   // mapper 67
12234      case TAITO_TC0190FMC:   // mapper 33
12235      case TAITO_TC0190FMCP:   // mapper 48
12236      case TAITO_X1_005:   // mapper 80
12237      case TAITO_X1_005_A:   // mapper 207
12238      case TAITO_X1_017:   // mapper 82
12239      case NTDEC_ASDER:   // mapper 112
12240      case FUTUREMEDIA_BOARD:   // mapper 117
12241      case BTL_DRAGONNINJA:   // mapper 222
12242      case WAIXING_SGZ:   // mapper 252
12243      case UNL_T230:
12244      case BMC_NTD_03:
12245      case KAISER_KS7022:
12246      case UNL_SHJY3:
12247      case KAISER_KS7017:
12248      case KAISER_KS7032:
12249      case KAISER_KS202:
12250         prg16_89ab(machine, 0);
12251         prg16_cdef(machine, state->m_prg_chunks - 1);
12252         break;
12253
12254      case STD_CPROM:   // mapper 13
12255         chr4_0(machine, 0, CHRRAM);
12256         chr4_4(machine, 0, CHRRAM);
12257         break;
12258      case STD_AXROM:   // mapper 7
12259         set_nt_mirroring(machine, PPU_MIRROR_LOW);
12260         break;
12261      case STD_SXROM:   // mapper 1, 155
12262      case STD_SOROM:
12263      case STD_SXROM_A:
12264      case STD_SOROM_A:
12265         state->m_mmc1_latch = 0;
12266         state->m_mmc1_count = 0;
12267         state->m_mmc_reg[0] = 0x0f;
12268         state->m_mmc_reg[1] = state->m_mmc_reg[2] = state->m_mmc_reg[3] = 0;
12269         state->m_mmc1_reg_write_enable = 1;
12270         set_nt_mirroring(machine, PPU_MIRROR_HORZ);
12271         mmc1_set_chr(machine);
12272         mmc1_set_prg(machine);
12273         if (state->m_battery || state->m_wram)
12274            wram_bank(machine, 0, (idx == STD_SOROM) ? NES_WRAM : NES_BATTERY);
12275         break;
12276      case STD_PXROM:   // mapper 9
12277         state->m_mmc_reg[0] = state->m_mmc_reg[2] = 0;
12278         state->m_mmc_reg[1] = state->m_mmc_reg[3] = 0;
12279         state->m_mmc_latch1 = state->m_mmc_latch2 = 0xfe;
12280         prg8_89(machine, 0);
12281         prg8_ab(machine, (state->m_prg_chunks << 1) - 3);
12282         prg8_cd(machine, (state->m_prg_chunks << 1) - 2);
12283         prg8_ef(machine, (state->m_prg_chunks << 1) - 1);
12284         break;
12285      case STD_FXROM: // mapper 10
12286         state->m_mmc_reg[0] = state->m_mmc_reg[2] = 0;
12287         state->m_mmc_reg[1] = state->m_mmc_reg[3] = 0;
12288         state->m_mmc_latch1 = state->m_mmc_latch2 = 0xfe;
12289         prg16_89ab(machine, 0);
12290         prg16_cdef(machine, state->m_prg_chunks - 1);
12291         break;
12292      case STD_TXROM:   // mapper 4
12293      case STD_TVROM:
12294      case STD_TKROM:
12295      case REXSOFT_DBZ5:   // mapper 12
12296      case WAIXING_TYPE_A:   // mapper 74
12297      case WAIXING_TYPE_A_1:
12298      case STD_TXSROM:   // mapper 118
12299      case STD_TQROM:   // mapper 119
12300      case WAIXING_SH2:   // mapper 165
12301      case WAIXING_TYPE_B:   // mapper 191
12302      case WAIXING_TYPE_C:   // mapper 192
12303      case WAIXING_TYPE_D:   // mapper 194
12304      case WAIXING_TYPE_E:   // mapper 195
12305      case WAIXING_TYPE_H:   // mapper 245
12306      case BTL_SUPERBROS11:   // mapper 196
12307      case UNL_H2288:      // mapper 123
12308      case UNL_KOF97:
12309      case UNL_603_5052:
12310      case NITRA_TDA:   // mapper 250
12311         if (state->m_four_screen_vram)   // only TXROM and DXROM have 4-screen mirroring
12312         {
12313            set_nt_page(machine, 0, CART_NTRAM, 0, 1);
12314            set_nt_page(machine, 1, CART_NTRAM, 1, 1);
12315            set_nt_page(machine, 2, CART_NTRAM, 2, 1);
12316            set_nt_page(machine, 3, CART_NTRAM, 3, 1);
12317         }
12318         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12319         break;
12320      case STD_HKROM:   // MMC6 (basically the same as TxROM, but alt IRQ behaviour)
12321         mmc3_common_initialize(machine, 0xff, 0xff, 1);
12322         state->m_mmc6_reg = 0xf0;
12323         state->m_mmc_latch2 = 0;   // this is used differently here compared to MMC3
12324         break;
12325      case PAL_ZZ:   // mapper 37
12326         mmc3_common_initialize(machine, 0x07, 0x7f, 0);
12327         break;
12328      case NES_QJ:   // mapper 47
12329         mmc3_common_initialize(machine, 0x0f, 0x7f, 0);
12330         break;
12331      case STD_EXROM:   // mapper 5
12332         state->m_MMC5_rom_bank_mode = 3;
12333         state->m_MMC5_vrom_bank_mode = 0;
12334         state->m_MMC5_vram_protect = 0;
12335         state->m_mmc5_high_chr = 0;
12336         state->m_mmc5_vram_control = 0;
12337         state->m_mmc5_split_scr = 0;
12338         memset(state->m_MMC5_vrom_bank, 0, ARRAY_LENGTH(state->m_MMC5_vrom_bank));
12339         state->m_mmc5_prg_mode = 3;
12340         state->m_mmc5_last_chr_a = 1;
12341         state->m_mmc5_prg_regs[0] = 0xfc;
12342         state->m_mmc5_prg_regs[1] = 0xfd;
12343         state->m_mmc5_prg_regs[2] = 0xfe;
12344         state->m_mmc5_prg_regs[3] = 0xff;
12345         memset(state->m_mmc5_vrom_regA, ~0, ARRAY_LENGTH(state->m_mmc5_vrom_regA));
12346         memset(state->m_mmc5_vrom_regB, ~0, ARRAY_LENGTH(state->m_mmc5_vrom_regB));
12347         prg16_89ab(machine, state->m_prg_chunks - 2);
12348         prg16_cdef(machine, state->m_prg_chunks - 1);
12349         break;
12350      case STD_NXROM:      // mapper 68
12351      case SUNSOFT_DCS:      // mapper 68
12352         state->m_mmc_reg[0] = 0;
12353         prg16_89ab(machine, 0);
12354         prg16_cdef(machine, state->m_prg_chunks - 1);
12355         break;
12356      case NAMCOT_34X3:   // mapper 88
12357      case STD_DXROM:   // mapper 206
12358      case STD_DRROM:
12359         if (state->m_four_screen_vram)   // only TXROM and DXROM have 4-screen mirroring
12360         {
12361            set_nt_page(machine, 0, CART_NTRAM, 0, 1);
12362            set_nt_page(machine, 1, CART_NTRAM, 1, 1);
12363            set_nt_page(machine, 2, CART_NTRAM, 2, 1);
12364            set_nt_page(machine, 3, CART_NTRAM, 3, 1);
12365         }
12366      case NAMCOT_3453:   // mapper 154
12367         prg16_89ab(machine, state->m_prg_chunks - 2);
12368         prg16_cdef(machine, state->m_prg_chunks - 1);
12369         break;
12370      case NAMCOT_3446:   // mapper 76
12371         prg8_89(machine, 0);
12372         prg8_ab(machine, 1);
12373         prg16_cdef(machine, state->m_prg_chunks - 1);
12374         chr2_0(machine, 0, CHRROM);
12375         chr2_2(machine, 1, CHRROM);
12376         chr2_4(machine, 2, CHRROM);
12377         chr2_6(machine, 3, CHRROM);
12378         break;
12379      case BANDAI_JUMP2:   // mapper 153
12380         for (i = 0; i < 8; i++)
12381            state->m_mmc_reg[i] = 0;
12382         prg16_89ab(machine, 0);
12383         prg16_cdef(machine, state->m_prg_chunks - 1);
12384         fjump2_set_prg(machine);
12385         break;
12386      case BANDAI_KARAOKE:   // mapper 188
12387         prg16_89ab(machine, 0);
12388         prg16_cdef(machine, (state->m_prg_chunks - 1) ^ 0x08);
12389         break;
12390      case IREM_LROG017:   // mapper 77
12391         chr2_2(machine, 0, CHRROM);
12392         chr2_4(machine, 1, CHRROM);
12393         chr2_6(machine, 2, CHRROM);
12394         break;
12395      case IREM_TAM_S1:   // mapper 97
12396         prg16_89ab(machine, state->m_prg_chunks - 1);
12397         prg16_cdef(machine, 0);
12398         break;
12399      case KONAMI_VRC7:   // mapper 85
12400         prg8_89(machine, 0);
12401         prg8_ab(machine, 0);
12402         prg8_cd(machine, 0);
12403         prg8_ef(machine, 0xff);
12404         break;
12405      case NAMCOT_163:   // mapper 19
12406         prg16_89ab(machine, 0);
12407         prg16_cdef(machine, state->m_prg_chunks - 1);
12408         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12409         break;
12410      case SUNSOFT_1:   // mapper 184
12411      case SUNSOFT_2:   // mapper 89 & 93
12412         prg16_89ab(machine, 0);
12413         prg16_cdef(machine, state->m_prg_chunks - 1);
12414         if (!state->m_hard_mirroring)
12415            set_nt_mirroring(machine, PPU_MIRROR_LOW);
12416         break;
12417
12418         // mapper 14
12419      case REXSOFT_SL1632:
12420         state->m_mmc_extra_bank[2] = 0xfe;
12421         state->m_mmc_extra_bank[3] = 0xff;
12422         state->m_mmc_extra_bank[0] = state->m_mmc_extra_bank[1] = state->m_mmc_extra_bank[4] = state->m_mmc_extra_bank[5] = state->m_mmc_extra_bank[6] = 0;
12423         state->m_mmc_extra_bank[7] = state->m_mmc_extra_bank[8] = state->m_mmc_extra_bank[9] = state->m_mmc_extra_bank[0xa] = state->m_mmc_extra_bank[0xb] = 0;
12424         state->m_mmc_reg[0] = state->m_mmc_reg[1] = 0;
12425         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12426         break;
12427         // mapper 15
12428      case WAIXING_PS2:
12429         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12430         break;
12431
12432         // mapper 35
12433      case UNL_SC127:
12434         // mapper 42
12435      case BTL_MARIOBABY:
12436      case BTL_AISENSHINICOL:
12437         prg32(machine, 0xff);
12438         break;
12439
12440         // mapper 40
12441      case BTL_SMB2A:
12442         prg8_67(machine, 0xfe);
12443         prg8_89(machine, 0xfc);
12444         prg8_ab(machine, 0xfd);
12445         prg8_cd(machine, 0xfe);
12446         prg8_ef(machine, 0xff);
12447         break;
12448
12449         // mapper 43
12450      case UNL_SMB2J:
12451         if (state->m_battery)
12452            memset(state->m_battery_ram, 0x2000, 0xff);
12453         else if (state->m_prg_ram)
12454            memset(state->m_wram, 0x2000, 0xff);
12455         break;
12456         // mapper 44
12457      case BMC_SUPERBIG_7IN1:
12458         // mapper 49
12459      case BMC_SUPERHIK_4IN1:
12460         mmc3_common_initialize(machine, 0x0f, 0x7f, 0);
12461         break;
12462         // mapper 45
12463      case BMC_HIK8IN1:
12464         state->m_mmc_reg[0] = state->m_mmc_reg[1] = state->m_mmc_reg[2] = state->m_mmc_reg[3] = 0;
12465         mmc3_common_initialize(machine, 0x3f, 0xff, 0);
12466         break;
12467
12468         // mapper 50
12469      case BTL_SMB2B:
12470         prg8_67(machine, 0x0f);
12471         prg8_89(machine, 0x08);
12472         prg8_ab(machine, 0x09);
12473         prg8_cd(machine, 0);
12474         prg8_ef(machine, 0x0b);
12475         break;
12476         // mapper 51
12477      case BMC_BALLGAMES_11IN1:
12478         state->m_mmc_reg[0] = 0x01;
12479         state->m_mmc_reg[1] = 0x00;
12480         bmc_ball11_set_banks(machine);
12481         break;
12482         // mapper 52
12483      case BMC_MARIOPARTY_7IN1:
12484         state->m_map52_reg_written = 0;
12485         mmc3_common_initialize(machine, 0x1f, 0xff, 0);
12486         break;
12487         // mapper 54
12488      case BMC_NOVELDIAMOND:
12489         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12490         break;
12491         // mapper 57
12492      case BMC_GKA:
12493         prg16_89ab(machine, 0);
12494         prg16_cdef(machine, 0);
12495         break;
12496
12497         // mapper 64
12498      case TENGEN_800032:
12499         // mapper 158
12500      case TENGEN_800037:
12501         prg16_89ab(machine, state->m_prg_chunks - 1);
12502         prg16_cdef(machine, state->m_prg_chunks - 1);
12503         break;
12504         // mapper 71
12505      case CAMERICA_BF9097:
12506         set_nt_mirroring(machine, PPU_MIRROR_HORZ);
12507      case CAMERICA_BF9093:
12508         prg32(machine, 0xff);
12509         break;
12510
12511         // mapper 79 (& 146)
12512      case AVE_NINA06:
12513         set_nt_mirroring(machine, PPU_MIRROR_HORZ);
12514         break;
12515
12516         // mapper 83
12517      case CONY_BOARD:
12518         state->m_mapper83_reg[9] = 0x0f;
12519         prg8_cd(machine, 0x1e);
12520         prg8_ef(machine, 0x1f);
12521         break;
12522
12523         // mapper 91
12524      case UNL_MK2:
12525         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12526         prg16_89ab(machine, state->m_prg_chunks - 1);
12527         prg16_cdef(machine, state->m_prg_chunks - 1);
12528         break;
12529
12530         // mapper 104
12531      case CAMERICA_GOLDENFIVE:
12532         prg16_89ab(machine, 0x00);
12533         prg16_cdef(machine, 0x0f);
12534         break;
12535         // mapper 106
12536      case BTL_SMB3:
12537         prg8_89(machine, (state->m_prg_chunks << 1) - 1);
12538         prg8_ab(machine, 0);
12539         prg8_cd(machine, 0);
12540         prg8_ef(machine, (state->m_prg_chunks << 1) - 1);
12541         break;
12542
12543         // mapper 108
12544      case WHIRLWIND_2706:
12545         prg32(machine, 0xff);
12546         break;
12547
12548         // mapper 114
12549      case SUPERGAME_LIONKING:
12550         state->m_map114_reg = state->m_map114_reg_enabled = 0;
12551         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12552         break;
12553         // mapper 115
12554      case KASING_BOARD:
12555         state->m_mmc_reg[0] = 0;
12556         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12557         break;
12558         // mapper 116
12559      case SOMERI_SL12:
12560         state->m_mmc_prg_base = state->m_mmc_chr_base = 0;
12561         state->m_mmc_prg_mask = 0xff;
12562         state->m_mmc_chr_mask = 0xff;
12563         state->m_mmc_cmd1 = 2; // mode
12564         state->m_mmc3_latch = 0;
12565         state->m_mmc3_wram_protect = 0;
12566         // MMC1 regs
12567         state->m_mmc1_count = 0;
12568         state->m_mmc_reg[0] = 0x0c;
12569         state->m_mmc_reg[1] = 0x00;
12570         state->m_mmc_reg[2] = 0x00;
12571         state->m_mmc_reg[3] = 0x00;
12572         // MMC3 regs
12573         state->m_mmc_prg_bank[0] = 0x3c;
12574         state->m_mmc_prg_bank[1] = 0x3d;
12575         state->m_mmc_prg_bank[2] = 0xfe;
12576         state->m_mmc_prg_bank[3] = 0xff;
12577         state->m_mmc_vrom_bank[0] = 0x00;
12578         state->m_mmc_vrom_bank[1] = 0x01;
12579         state->m_mmc_vrom_bank[2] = 0x04;
12580         state->m_mmc_vrom_bank[3] = 0x05;
12581         state->m_mmc_vrom_bank[4] = 0x06;
12582         state->m_mmc_vrom_bank[5] = 0x07;
12583         // VRC2 regs
12584         state->m_mmc_prg_bank[4] = 0x00;
12585         state->m_mmc_prg_bank[5] = 0x01;
12586         for (i = 0; i < 8; ++i)
12587            state->m_mmc_vrom_bank[6 + i] = i;
12588         someri_mode_update(machine);
12589         break;
12590
12591         // mapper 120
12592      case BTL_TOBIDASE:
12593         prg32(machine, 2);
12594         break;
12595
12596         // mapper 121
12597      case KAY_PANDAPRINCE:
12598         state->m_mmc_reg[5] = state->m_mmc_reg[6] = state->m_mmc_reg[7] = 0;
12599         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12600         break;
12601
12602         // mapper 126
12603      case BMC_PJOY84:
12604         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12605         state->m_mmc_reg[0] = state->m_mmc_reg[1] = state->m_mmc_reg[2] = state->m_mmc_reg[3] = 0;
12606         pjoy84_set_base_mask(machine);
12607         mmc3_set_chr(machine, state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
12608         mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
12609         break;
12610
12611         // mapper 132
12612      case TXC_22211A:
12613         // mapper 172
12614      case TXC_22211B:
12615         // mapper 173
12616      case TXC_22211C:
12617         state->m_txc_reg[0] = state->m_txc_reg[1] = state->m_txc_reg[2] = state->m_txc_reg[3] = 0;
12618         break;
12619
12620         // mapper 134
12621      case BMC_FAMILY_4646B:
12622         mmc3_common_initialize(machine, 0x1f, 0xff, 0);
12623         break;
12624
12625         // mapper 137
12626      case SACHEN_8259D:
12627         chr8(machine, state->m_chr_chunks - 1, CHRROM);
12628         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12629         break;
12630         // mapper 138
12631      case SACHEN_8259B:
12632         // mapper 139
12633      case SACHEN_8259C:
12634         // mapper 141
12635      case SACHEN_8259A:
12636         // mapper 150
12637      case SACHEN_74LS374:
12638         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12639         break;
12640         // mapper 143
12641      case SACHEN_TCA01:
12642         prg16_89ab(machine, 0);
12643         prg16_cdef(machine, 1);
12644         break;
12645
12646         // mapper 156
12647      case OPENCORP_DAOU306:
12648         prg16_89ab(machine, state->m_prg_chunks - 2);
12649         prg16_cdef(machine, state->m_prg_chunks - 1);
12650         set_nt_mirroring(machine, PPU_MIRROR_LOW);
12651         break;
12652         // mapper 163
12653      case NANJING_BOARD:
12654         state->m_mmc_count = 0xff;
12655         state->m_mmc_reg[0] = 0xff;
12656         state->m_mmc_reg[1] = 0;
12657         prg16_89ab(machine, state->m_prg_chunks - 2);
12658         prg16_cdef(machine, state->m_prg_chunks - 1);
12659         break;
12660         // mapper 164
12661      case WAIXING_FFV:
12662         prg16_89ab(machine, 0);
12663         prg16_cdef(machine, 0x1f);
12664         break;
12665         // mapper 166
12666      case SUBOR_TYPE1:
12667         state->m_subor_reg[0] = state->m_subor_reg[1] = state->m_subor_reg[2] = state->m_subor_reg[3] = 0;
12668         prg16_89ab(machine, 0);
12669         prg16_cdef(machine, 0x07);
12670         break;
12671         // mapper 167
12672      case SUBOR_TYPE0:
12673         state->m_subor_reg[0] = state->m_subor_reg[1] = state->m_subor_reg[2] = state->m_subor_reg[3] = 0;
12674         prg16_89ab(machine, 0);
12675         prg16_cdef(machine, 0x20);
12676         break;
12677
12678         // mapper 176
12679      case UNL_XZY:
12680         // mapper 182
12681      case HOSENKAN_BOARD:
12682         prg32(machine, (state->m_prg_chunks - 1) >> 1);
12683         break;
12684
12685      case FUKUTAKE_BOARD:   // mapper 186
12686         prg16_89ab(machine, 0);
12687         prg16_cdef(machine, 0);
12688         break;
12689
12690         // mapper 187
12691      case UNL_KOF96:
12692         state->m_mmc_reg[0] = state->m_mmc_reg[1] = state->m_mmc_reg[2] = state->m_mmc_reg[3] = 0;
12693         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12694         break;
12695         // mapper 189
12696      case TXC_TW:
12697         state->m_mmc_latch1 = 0;
12698         state->m_mmc_latch2 = 0x80;
12699         state->m_mmc_chr_base = 0;
12700         state->m_mmc_chr_mask = 0xff;
12701         mmc3_set_chr(machine, state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
12702         break;
12703         // mapper 193
12704      case NTDEC_FIGHTINGHERO:
12705         prg32(machine, (state->m_prg_chunks - 1) >> 1);
12706         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12707         break;
12708         // mapper 197
12709      case UNL_SUPERFIGHTER3:
12710         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12711         unl_sf3_set_chr(machine, state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
12712         break;
12713         // mapper 198
12714      case WAIXING_TYPE_F:
12715         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12716         state->m_mmc_prg_bank[0] = 0x00;
12717         state->m_mmc_prg_bank[1] = 0x01;
12718         state->m_mmc_prg_bank[2] = 0x4e;
12719         state->m_mmc_prg_bank[3] = 0x4f;
12720         mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
12721         break;
12722         // mapper 199
12723      case WAIXING_TYPE_G:
12724         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12725         state->m_mmc_prg_bank[0] = 0x00;
12726         state->m_mmc_prg_bank[1] = 0x01;
12727         state->m_mmc_prg_bank[2] = 0x3e;
12728         state->m_mmc_prg_bank[3] = 0x3f;
12729         mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
12730         state->m_mmc_vrom_bank[0] = 0x00;
12731         state->m_mmc_vrom_bank[1] = 0x02;
12732         state->m_mmc_vrom_bank[2] = 0x04;
12733         state->m_mmc_vrom_bank[3] = 0x05;
12734         state->m_mmc_vrom_bank[4] = 0x06;
12735         state->m_mmc_vrom_bank[5] = 0x07;
12736         state->m_mmc_vrom_bank[6] = 0x01;
12737         state->m_mmc_vrom_bank[7] = 0x03;
12738         waixing_g_set_chr(machine, state->m_mmc_chr_base, state->m_mmc_chr_mask);
12739         break;
12740
12741         // mapper 200
12742      case BMC_36IN1:
12743         prg16_89ab(machine, state->m_prg_chunks - 1);
12744         prg16_cdef(machine, state->m_prg_chunks - 1);
12745         break;
12746
12747         // mapper 202
12748      case BMC_150IN1:
12749         // mapper 203
12750      case BMC_35IN1:
12751         // mapper 204
12752      case BMC_64IN1:
12753         // mapper 214
12754      case BMC_SUPERGUN_20IN1:
12755         prg16_89ab(machine, 0);
12756         prg16_cdef(machine, 0);
12757         break;
12758         // mapper 205
12759      case BMC_15IN1:
12760         mmc3_common_initialize(machine, 0x1f, 0xff, 0);
12761         state->m_mmc_prg_base = 0x10;   // this board has a diff prg_base
12762         mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
12763         break;
12764
12765         // mapper 208
12766      case GOUDER_37017:
12767         state->m_mmc_reg[0] = state->m_mmc_reg[1] = state->m_mmc_reg[2] = state->m_mmc_reg[3] = state->m_mmc_reg[4] = 0;
12768         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12769         break;
12770         // mapper 212
12771      case BMC_SUPERHIK_300IN1:
12772         chr8(machine, 0xff, CHRROM);
12773         prg32(machine, 0xff);
12774         break;
12775
12776         // mapper 215
12777      case SUPERGAME_BOOGERMAN:
12778         state->m_mmc_reg[0] = 0x00;
12779         state->m_mmc_reg[1] = 0xff;
12780         state->m_mmc_reg[2] = 0x04;
12781         state->m_mmc_reg[3] = 0;
12782         mmc3_common_initialize(machine, 0x1f, 0xff, 0);
12783         sgame_boog_set_prg(machine);
12784         mmc3_set_chr(machine, state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
12785         break;
12786
12787         // mapper 217
12788      case BMC_GOLDENCARD_6IN1:
12789         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12790         state->m_mmc_reg[0] = 0x00;
12791         state->m_mmc_reg[1] = 0xff;
12792         state->m_mmc_reg[2] = 0x03;
12793         state->m_mmc_reg[3] = 0;
12794         bmc_gc6in1_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
12795         bmc_gc6in1_set_chr(machine, state->m_mmc_chr_source);
12796         break;
12797         // mapper 221
12798      case UNL_N625092:
12799         prg16_89ab(machine, 0);
12800         prg16_cdef(machine, 0);
12801         break;
12802
12803         // mapper 223?
12804      case WAIXING_TYPE_I:
12805         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12806         state->m_mmc3_wram_protect = 0;
12807         break;
12808
12809         // mapper 224?
12810      case WAIXING_TYPE_J:
12811         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12812         state->m_mmc_prg_bank[0] = 0x01;
12813         state->m_mmc_prg_bank[1] = 0x02;
12814         state->m_mmc_prg_bank[2] = 0x7e;
12815         state->m_mmc_prg_bank[3] = 0x7f;
12816         mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
12817         break;
12818
12819         // mapper 227
12820      case BMC_1200IN1:
12821         prg16_89ab(machine, 0);
12822         prg16_cdef(machine, 0);
12823         break;
12824
12825         // mapper 229
12826      case BMC_31IN1:
12827         prg16_89ab(machine, 0);
12828         prg16_cdef(machine, 1);
12829         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12830         break;
12831         // mapper 230
12832      case BMC_22GAMES:
12833         prg16_89ab(machine, 0);
12834         prg16_cdef(machine, 7);
12835         break;
12836         // mapper 231
12837      case BMC_20IN1:
12838         prg16_89ab(machine, 0);
12839         prg16_cdef(machine, state->m_prg_chunks - 1);
12840         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12841         break;
12842         // mapper 232
12843      case CAMERICA_BF9096:
12844         state->m_mmc_latch1 = 0x18;
12845         state->m_mmc_latch2 = 0x00;
12846         bf9096_set_prg(machine);
12847         break;
12848
12849         // mapper 243
12850      case SACHEN_74LS374_A:
12851         state->m_mmc_vrom_bank[0] = 3;
12852         chr8(machine, 3, CHRROM);
12853         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12854         break;
12855
12856         // mapper 246
12857      case CNE_FSB:
12858         prg32(machine, 0xff);
12859         break;
12860         // mapper 249
12861      case WAIXING_SECURITY:
12862         state->m_mmc_reg[0] = 0;
12863         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12864         break;
12865
12866         // mapper 254
12867      case BTL_PIKACHUY2K:
12868         state->m_mmc_reg[0] = 0xff;
12869         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12870         break;
12871
12872         // mapper 255
12873      case BMC_110IN1:
12874         prg16_89ab(machine, 0);
12875         prg16_cdef(machine, 1);
12876         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12877         break;
12878
12879         // UNIF only
12880      case BMC_64IN1NR:
12881         state->m_mmc_reg[0] = 0x80;
12882         state->m_mmc_reg[1] = 0x43;
12883         state->m_mmc_reg[2] = state->m_mmc_reg[3] = 0;
12884         bmc_64in1nr_set_prg(machine);
12885         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12886         break;
12887      case BMC_190IN1:
12888         prg16_89ab(machine, 0);
12889         prg16_cdef(machine, 0);
12890         break;
12891      case BMC_A65AS:
12892         prg16_89ab(machine, 0);
12893         prg16_cdef(machine, 7);
12894         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12895         break;
12896      case BMC_GS2004:
12897      case BMC_GS2013:
12898         prg32(machine, 0xff);
12899         break;
12900      case BMC_S24IN1SC03:
12901         state->m_mmc_reg[0] = 0x24;
12902         state->m_mmc_reg[1] = 0x9f;
12903         state->m_mmc_reg[2] = 0;
12904         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12905         break;
12906      case BMC_T262:
12907         state->m_mmc_latch1 = 0;
12908         state->m_mmc_latch2 = 0;
12909         prg16_89ab(machine, 0);
12910         prg16_cdef(machine, 7);
12911         break;
12912      case DREAMTECH_BOARD:
12913         prg16_89ab(machine, 0);
12914         prg16_cdef(machine, 8);
12915         break;
12916      case UNL_8237:
12917         state->m_mmc_reg[0] = state->m_mmc_reg[1] = state->m_mmc_reg[2] = 0;
12918         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12919         break;
12920      case UNL_AX5705:
12921         state->m_mmc_prg_bank[0] = 0;
12922         state->m_mmc_prg_bank[1] = 1;
12923         prg8_89(machine, state->m_mmc_prg_bank[0]);
12924         prg8_ab(machine, state->m_mmc_prg_bank[1]);
12925         prg8_cd(machine, 0xfe);
12926         prg8_ef(machine, 0xff);
12927         break;
12928      case UNL_RACERMATE:
12929         chr4_0(machine, 0, state->m_mmc_chr_source);
12930         chr4_4(machine, 0, state->m_mmc_chr_source);
12931         prg16_89ab(machine, 0);
12932         prg16_cdef(machine, state->m_prg_chunks - 1);
12933         break;
12934
12935      case BMC_BENSHENG_BS5:
12936         state->m_mmc_prg_bank[0] = 0xff;
12937         state->m_mmc_prg_bank[1] = 0xff;
12938         state->m_mmc_prg_bank[2] = 0xff;
12939         state->m_mmc_prg_bank[3] = 0xff;
12940         bmc_bs5_update_banks(machine);
12941         break;
12942
12943      case BMC_810544:
12944         prg16_89ab(machine, 0);
12945         prg16_cdef(machine, 0);
12946         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12947         break;
12948
12949      case BMC_G63IN1:
12950         bmc_gb63_update(machine);
12951         break;
12952
12953      case BMC_FK23C:
12954         state->m_mmc_reg[0] = 4;
12955         state->m_mmc_reg[1] = 0xff;
12956         state->m_mmc_reg[2] = state->m_mmc_reg[3] = 0;
12957         state->m_mmc_reg[4] = state->m_mmc_reg[5] = state->m_mmc_reg[6] = state->m_mmc_reg[7] = 0xff;
12958         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12959         fk23c_set_prg(machine);
12960         fk23c_set_chr(machine);
12961         break;
12962
12963      case BMC_FK23CA:
12964         state->m_mmc_reg[0] = state->m_mmc_reg[1] = state->m_mmc_reg[2] = state->m_mmc_reg[3] = 0;
12965         state->m_mmc_reg[4] = state->m_mmc_reg[5] = state->m_mmc_reg[6] = state->m_mmc_reg[7] = 0xff;
12966         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12967         fk23c_set_prg(machine);
12968         fk23c_set_chr(machine);
12969         break;
12970
12971
12972      case FFE_MAPPER6:
12973         prg16_89ab(machine, 0);
12974         prg16_cdef(machine, 7);
12975         break;
12976      case FFE_MAPPER8:
12977         prg32(machine, 0);
12978         break;
12979      case FFE_MAPPER17:
12980         prg16_89ab(machine, 0);
12981         prg16_cdef(machine, state->m_prg_chunks - 1);
12982         break;
12983
12984      case UNSUPPORTED_BOARD:
12985      default:
12986         /* Mapper not supported */
12987         err = 2;
12988         break;
12989   }
12990
12991   return err;
12992}
12993
12994/*************************************************************
12995
12996 nes_pcb_reset
12997
12998 Resets the mmc bankswitch areas to their defaults.
12999 It returns a value "err" that indicates if it was
13000 successful. Possible values for err are:
13001
13002 0 = success
13003 1 = no pcb found
13004 2 = pcb not supported
13005
13006 *************************************************************/
13007
13008int nes_pcb_reset( running_machine &machine )
13009{
13010   nes_state *state = machine.driver_data<nes_state>();
13011   int err = 0;
13012   const nes_pcb_intf *intf = nes_pcb_intf_lookup(state->m_pcb_id);
13013
13014   if (intf == NULL)
13015      fatalerror("Missing PCB interface\n");
13016
13017   /* Set the mapper irq callback */
13018   ppu2c0x_set_scanline_callback(state->m_ppu, intf ? intf->mmc_scanline : NULL);
13019   ppu2c0x_set_hblank_callback(state->m_ppu, intf ? intf->mmc_hblank : NULL);
13020
13021   err = pcb_initialize(machine, state->m_pcb_id);
13022
13023   return err;
13024}
src/mame/machine/aescart.c
r0r11461
1/**********************************************************************
2
3    aescart.c
4
5    Neo-Geo AES cartridge management
6    R. Belmont, 2009
7
8    Based on ti99cart.c by Michael Zapf
9
10    We leave the support in place for multiple slots in case MAME
11    uses this at some future point for MVS multi-cart.
12
13*********************************************************************/
14#include "emu.h"
15#include "aescart.h"
16#include "imagedev/cartslot.h"
17#include "imagedev/multcart.h"
18#include "includes/neogeo.h"
19
20typedef int assmfct(running_machine &machine, device_t *);
21
22enum
23{
24   AESCART_FCT_ASSM = DEVINFO_FCT_DEVICE_SPECIFIC,
25   AESCART_FCT_DISASSM
26};
27
28struct _aes_multicart_t
29{
30   /* Reserves space for all cartridges. This is also used in the legacy
31       cartridge system, but only for slot 0. */
32   aescartridge_t cartridge[AES_NUMBER_OF_CARTRIDGE_SLOTS];
33
34   /* Determines which slot is currently active. This value is changed when there
35    are accesses to other GROM base addresses. */
36   int active_slot;
37
38   /* Used in order to enforce a special slot. This value is retrieved
39       from the dipswitch setting. A value of -1 means automatic, that is,
40       the grom base switch is used. Values 0 .. max refer to the
41       respective slot. */
42   int fixed_slot;
43
44   /* Holds the highest index of a cartridge being plugged in plus one.
45       If we only have one cartridge inserted, we don't want to get a
46       selection option, so we just mirror the memory contents. */
47   int next_free_slot;
48
49   /* Counts the number of slots which currently contain legacy format
50       cartridge images. */
51   int legacy_slots;
52
53   /* Counts the number of slots which currently contain new format
54       cartridge images. */
55   int multi_slots;
56};
57typedef struct _aes_multicart_t aes_multicart_t;
58
59#define AUTO -1
60
61/* Access to the pcb. Contained in the token of the pcb instance. */
62struct _aes_pcb_t
63{
64   /* Link up to the cartridge structure which contains this pcb. */
65   aescartridge_t *cartridge;
66
67   /* Function to assemble this cartridge. */
68   assmfct   *assemble;
69
70   /* Function to disassemble this cartridge. */
71   assmfct   *disassemble;
72};
73typedef struct _aes_pcb_t aes_pcb_t;
74
75INLINE aes_multicart_t *get_safe_token(device_t *device)
76{
77   assert(device != NULL);
78   assert(device->type() == AES_MULTICART);
79
80   return (aes_multicart_t *)downcast<legacy_device_base *>(device)->token();
81}
82
83INLINE aes_pcb_t *get_safe_pcb_token(device_t *device)
84{
85   assert(device != NULL);
86   assert(device->type() == AES_CARTRIDGE_PCB_NONE || device->type() == AES_CARTRIDGE_PCB_STD);
87
88   return (aes_pcb_t *)downcast<legacy_device_base *>(device)->token();
89}
90
91INLINE cartslot_t *get_safe_cartslot_token(device_t *device)
92{
93   assert(device != NULL);
94   assert(device->type() == CARTSLOT);
95
96   return (cartslot_t *)downcast<legacy_device_base *>(device)->token();
97}
98
99/*
100    Find the index of the cartridge name. We assume the format
101    <name><number>, i.e. the number is the longest string from the right
102    which can be interpreted as a number.
103*/
104static int get_index_from_tagname(device_t *image)
105{
106   const char *tag = image->tag();
107   int maxlen = strlen(tag);
108   int i;
109   for (i=maxlen-1; i >=0; i--)
110      if (tag[i] < 48 || tag[i] > 57) break;
111
112   return atoi(tag+i+1);
113}
114
115/*
116    Common routine to assemble cartridges from resources.
117*/
118static aescartridge_t *assemble_common(running_machine &machine, device_t *cartslot)
119{
120   /* Pointer to the cartridge structure. */
121   aescartridge_t *cartridge;
122   device_t *cartsys = cartslot->owner();
123   aes_multicart_t *cartslots = get_safe_token(cartsys);
124   UINT8 *socketcont, *romrgn;
125   int reslength, i, blockofs;
126   char sprname1[16], sprname2[16];
127
128   int slotnumber = get_index_from_tagname(cartslot)-1;
129   assert(slotnumber>=0 && slotnumber<AES_NUMBER_OF_CARTRIDGE_SLOTS);
130
131   /* There is a cartridge in this slot, check the maximum slot number. */
132   if (cartslots->next_free_slot <= slotnumber)
133   {
134      cartslots->next_free_slot = slotnumber+1;
135   }
136   cartridge = &cartslots->cartridge[slotnumber];
137
138   // check for up to 4 program ROMs
139   romrgn = (UINT8 *)machine.region("maincpu")->base();
140   blockofs = 0;
141   for (i = 0; i < 4; i++)
142   {
143      sprintf(sprname1, "p%d", i+1);
144
145      socketcont = (UINT8*)cartslot_get_socket(cartslot, sprname1);
146      reslength = cartslot_get_resource_length(cartslot, sprname1);
147
148      if (socketcont != NULL)
149      {
150         memcpy(romrgn+blockofs, socketcont, reslength);
151         blockofs += reslength;
152      }
153   }
154
155   // 1 m1 ROM
156   socketcont = (UINT8*)cartslot_get_socket(cartslot, "m1");
157   reslength = cartslot_get_resource_length(cartslot, "m1");
158   if (socketcont != NULL)
159   {
160      romrgn = (UINT8 *)machine.region("audiocpu")->base();
161
162      memcpy(romrgn, socketcont, reslength);
163      // mirror (how does this really work?)
164      memcpy(romrgn+0x10000, socketcont, reslength);
165   }
166
167   // up to 8 YM sample ROMs
168   romrgn = (UINT8 *)machine.region("ymsnd")->base();
169   blockofs = 0;
170   for (i = 0; i < 8; i++)
171   {
172      sprintf(sprname1, "v1%d", i+1);
173
174      socketcont = (UINT8*)cartslot_get_socket(cartslot, sprname1);
175      reslength = cartslot_get_resource_length(cartslot, sprname1);
176
177      if (socketcont != NULL)
178      {
179         memcpy(romrgn+blockofs, socketcont, reslength);
180         blockofs += reslength;
181      }
182   }
183
184   // up to 8 YM delta-T sample ROMs
185   romrgn = (UINT8 *)machine.region("ymsnd.deltat")->base();
186   blockofs = 0;
187   for (i = 0; i < 8; i++)
188   {
189      sprintf(sprname1, "v2%d", i+1);
190
191      socketcont = (UINT8*)cartslot_get_socket(cartslot, sprname1);
192      reslength = cartslot_get_resource_length(cartslot, sprname1);
193
194      if (socketcont != NULL)
195      {
196         memcpy(romrgn+blockofs, socketcont, reslength);
197         blockofs += reslength;
198      }
199   }
200
201   // 1 s1 ROM
202   socketcont = (UINT8*)cartslot_get_socket(cartslot, "s1");
203   reslength = cartslot_get_resource_length(cartslot, "s1");
204   if (socketcont != NULL)
205   {
206      romrgn = (UINT8 *)machine.region("fixed")->base();
207
208      memcpy(romrgn, socketcont, reslength);
209   }
210
211   // up to 8 sprite ROMs in byte-interleaved pairs
212   romrgn = (UINT8 *)machine.region("sprites")->base();
213   blockofs = 0;
214   for (i = 0; i < 8; i+=2)
215   {
216      UINT8 *spr1, *spr2;
217      int j;
218
219      sprintf(sprname1, "c%d", i+1);
220      sprintf(sprname2, "c%d", i+2);
221
222      spr1 = (UINT8*)cartslot_get_socket(cartslot, sprname1);
223      spr2 = (UINT8*)cartslot_get_socket(cartslot, sprname2);
224      reslength = cartslot_get_resource_length(cartslot, sprname1);
225
226      if ((spr1) && (spr2))
227      {
228         for (j = 0; j < reslength; j++)
229         {
230            romrgn[blockofs + (j*2)] = spr1[j];
231            romrgn[blockofs + (j*2) + 1] = spr2[j];
232         }
233
234         blockofs += reslength*2;
235      }
236   }
237
238   return cartridge;
239}
240
241static void set_pointers(device_t *pcb, int index)
242{
243   device_t *cartsys = pcb->owner()->owner();
244   aes_multicart_t *cartslots = get_safe_token(cartsys);
245   aes_pcb_t *pcb_def = get_safe_pcb_token(pcb);
246
247   pcb_def->assemble = (assmfct *)downcast<const legacy_cart_slot_device_base *>(pcb)->get_legacy_fct(AESCART_FCT_ASSM);
248   pcb_def->disassemble = (assmfct *)downcast<const legacy_cart_slot_device_base *>(pcb)->get_legacy_fct(AESCART_FCT_DISASSM);
249
250   pcb_def->cartridge = &cartslots->cartridge[index];
251   pcb_def->cartridge->pcb = pcb;
252}
253
254/*****************************************************************************
255  Cartridge type: None
256    This PCB device is just a pseudo device; the legacy mode is handled
257    by dedicated functions.
258******************************************************************************/
259static DEVICE_START(aes_pcb_none)
260{
261   /* device is aes_cartslot:cartridge:pcb */
262//  printf("DEVICE_START(aes_pcb_none), tag of device=%s\n", device->tag());
263   set_pointers(device, get_index_from_tagname(device->owner())-1);
264}
265
266/*****************************************************************************
267  Cartridge type: Standard
268    Most cartridges are built in this type. This includes word-swapped program,
269    z80 program, YM samples, delta-T samples, sprites, and sfix.
270******************************************************************************/
271
272static DEVICE_START(aes_pcb_std)
273{
274   /* device is aes_cartslot:cartridge:pcb */
275//  printf("DEVICE_START(aes_pcb_std), tag of device=%s\n", device->tag());
276   set_pointers(device, get_index_from_tagname(device->owner())-1);
277}
278
279/*
280    The standard cartridge assemble routine. We just call the common
281    function here.
282*/
283static int assemble_std(running_machine &machine, device_t *image)
284{
285//  aescartridge_t *cart;
286//  printf("assemble_std, %s\n", image->tag);
287   /*cart = */assemble_common(machine, image);
288
289   return IMAGE_INIT_PASS;
290}
291
292/*
293    Removes pointers and restores the state before plugging in the
294    cartridge.
295    The pointer to the location after the last cartridge is adjusted.
296    As it seems, we can use the same function for the disassembling of all
297    cartridge types.
298*/
299static int disassemble_std(device_t *image)
300{
301//  int slotnumber;
302//  int i;
303//  aescartridge_t *cart;
304//  device_t *cartsys = image->owner();
305//  aes_multicart_t *cartslots = (aes_multicart_t *)cartsys->token;
306
307//  slotnumber = get_index_from_tagname(image)-1;
308//  printf("Disassemble cartridge %d\n", slotnumber);
309#if 0
310   /* Search the highest remaining cartridge. */
311   cartslots->next_free_slot = 0;
312   for (i=AES_NUMBER_OF_CARTRIDGE_SLOTS-1; i >= 0; i--)
313   {
314      if (i != slotnumber)
315      {
316         if (0) //!slot_is_empty(cartsys, i))    (for future use?)
317         {
318            cartslots->next_free_slot = i+1;
319//              printf("Setting new next_free_slot to %d\n", cartslots->next_free_slot);
320            break;
321         }
322      }
323   }
324#endif
325   /* Do we have RAM? If so, swap the bytes (undo the BIG_ENDIANIZE) */
326//  cart = &cartslots->cartridge[slotnumber];
327
328//  clear_slot(cartsys, slotnumber);
329
330   return IMAGE_INIT_PASS;
331}
332
333/*****************************************************************************
334  Device metadata
335******************************************************************************/
336
337static DEVICE_GET_INFO(aes_cart_common)
338{
339   switch(state)
340   {
341      /* --- the following bits of info are returned as 64-bit signed integers --- */
342      case DEVINFO_INT_TOKEN_BYTES:
343         info->i = sizeof(aes_pcb_t);
344         break;
345      case DEVINFO_INT_INLINE_CONFIG_BYTES:
346         info->i = 0;
347         break;
348
349      /* --- the following bits of info are returned as pointers to functions --- */
350      case DEVINFO_FCT_START:
351         info->start = DEVICE_START_NAME(aes_pcb_std);
352         break;
353      case DEVINFO_FCT_STOP:
354         /* Nothing */
355         break;
356      case DEVINFO_FCT_RESET:
357         /* Nothing */
358         break;
359
360      case AESCART_FCT_ASSM:
361         info->f = (genf *) assemble_std;
362         break;
363
364      case AESCART_FCT_DISASSM:
365         info->f = (genf *) disassemble_std;
366         break;
367
368      /* --- the following bits of info are returned as NULL-terminated strings --- */
369      case DEVINFO_STR_NAME:
370         strcpy(info->s, "AES standard cartridge pcb");
371         break;
372      case DEVINFO_STR_FAMILY:
373         strcpy(info->s, "AES cartridge pcb");
374         break;
375      case DEVINFO_STR_VERSION:
376         strcpy(info->s, "1.0");
377         break;
378      case DEVINFO_STR_SOURCE_FILE:
379         strcpy(info->s, __FILE__);
380         break;
381      case DEVINFO_STR_CREDITS:
382         /* Nothing */
383         break;
384   }
385}
386
387DEVICE_GET_INFO(aes_cartridge_pcb_none)
388{
389   switch(state)
390   {
391      case DEVINFO_FCT_START:
392         info->start = DEVICE_START_NAME(aes_pcb_none);
393         break;
394
395      case DEVINFO_STR_NAME:
396         strcpy(info->s, "AES empty cartridge");
397         break;
398
399      default:
400         DEVICE_GET_INFO_CALL(aes_cart_common);
401         break;
402   }
403}
404
405DEVICE_GET_INFO(aes_cartridge_pcb_std)
406{
407   DEVICE_GET_INFO_CALL(aes_cart_common);
408}
409
410/*****************************************************************************
411  The cartridge handling of the multi-cartridge system.
412  Every cartridge contains a PCB device. The memory handlers delegate the calls
413  to the respective handlers of the cartridges.
414******************************************************************************/
415/*
416    Initialize a cartridge. Each cartridge contains a PCB device.
417*/
418static DEVICE_START( aes_cartridge )
419{
420   cartslot_t *cart = get_safe_cartslot_token(device);
421
422   /* find the PCB device */
423   cart->pcb_device = device->subdevice(TAG_PCB);
424}
425
426// handle protected carts
427static void install_protection(device_image_interface& image)
428{
429   neogeo_state *state = image.device().machine().driver_data<neogeo_state>();
430   const char *crypt_feature = image.get_feature( "crypt" );
431
432   if(crypt_feature == NULL)
433      return;
434
435   if(strcmp(crypt_feature,"fatfury2_prot") == 0)
436   {
437      fatfury2_install_protection(image.device().machine());
438      logerror("Installed Fatal Fury 2 protection\n");
439   }
440   if(strcmp(crypt_feature,"kof99_crypt") == 0)
441   {
442      kof99_decrypt_68k(image.device().machine());
443      state->m_fixed_layer_bank_type = 1;
444      kof99_neogeo_gfx_decrypt(image.device().machine(), 0x00);
445      kof99_install_protection(image.device().machine());
446      logerror("Decrypted KOF99 code and graphics.\n");
447   }
448   if(strcmp(crypt_feature,"mslug3_crypt") == 0)
449   {
450      state->m_fixed_layer_bank_type = 1;
451      kof99_neogeo_gfx_decrypt(image.device().machine(), 0xad);
452      logerror("Decrypted Metal Slug 3 graphics\n");
453   }
454   if(strcmp(crypt_feature,"matrim_crypt") == 0)
455   {
456      matrim_decrypt_68k(image.device().machine());
457      neo_pcm2_swap(image.device().machine(), 1);
458      state->m_fixed_layer_bank_type = 2;
459      neogeo_cmc50_m1_decrypt(image.device().machine());
460      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x6a);
461      logerror("Decrypted Matrimelee code, sound and graphics\n");
462   }
463   if(strcmp(crypt_feature,"svc_crypt") == 0)
464   {
465      svc_px_decrypt(image.device().machine());
466      neo_pcm2_swap(image.device().machine(), 3);
467      state->m_fixed_layer_bank_type = 2;
468      neogeo_cmc50_m1_decrypt(image.device().machine());
469      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x57);
470      install_pvc_protection(image.device().machine());
471      logerror("Decrypted SvC code, sound and graphics.\n");
472   }
473   if(strcmp(crypt_feature,"samsho5_crypt") == 0)
474   {
475      samsho5_decrypt_68k(image.device().machine());
476      neo_pcm2_swap(image.device().machine(), 4);
477      state->m_fixed_layer_bank_type = 1;
478      neogeo_cmc50_m1_decrypt(image.device().machine());
479      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x0f);
480      logerror("Decrypted Samurai Shodown V code, sound and graphics.\n");
481   }
482   if(strcmp(crypt_feature,"kof2000_crypt") == 0)
483   {
484      kof2000_decrypt_68k(image.device().machine());
485      state->m_fixed_layer_bank_type = 2;
486      neogeo_cmc50_m1_decrypt(image.device().machine());
487      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x00);
488      kof2000_install_protection(image.device().machine());
489      logerror("Decrypted KOF2000 code, sound and graphics.\n");
490   }
491   if(strcmp(crypt_feature,"kof2001_crypt") == 0)
492   {
493      state->m_fixed_layer_bank_type = 1;
494      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x1e);
495      neogeo_cmc50_m1_decrypt(image.device().machine());
496      logerror("Decrypted KOF2001 code and graphics.\n");
497   }
498   if(strcmp(crypt_feature,"kof2002_crypt") == 0)
499   {
500      kof2002_decrypt_68k(image.device().machine());
501      neo_pcm2_swap(image.device().machine(), 0);
502      neogeo_cmc50_m1_decrypt(image.device().machine());
503      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0xec);
504      logerror("Decrypted KOF2002 code, sound and graphics.\n");
505   }
506   if(strcmp(crypt_feature,"mslug4_crypt") == 0)
507   {
508      state->m_fixed_layer_bank_type = 1; /* USA violent content screen is wrong -- not a bug, confirmed on real hardware! */
509      neogeo_cmc50_m1_decrypt(image.device().machine());
510      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x31);
511      neo_pcm2_snk_1999(image.device().machine(), 8);
512      logerror("Decrypted Metal Slug 4 code, sound and graphics.\n");
513   }
514   if(strcmp(crypt_feature,"mslug5_crypt") == 0)
515   {
516      mslug5_decrypt_68k(image.device().machine());
517      neo_pcm2_swap(image.device().machine(), 2);
518      state->m_fixed_layer_bank_type = 1;
519      neogeo_cmc50_m1_decrypt(image.device().machine());
520      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x19);
521      install_pvc_protection(image.device().machine());
522      logerror("Decrypted Metal Slug 5 code and graphics, and installed protection routines.\n");
523   }
524   if(strcmp(crypt_feature,"kof2003_crypt") == 0)
525   {
526      kof2003h_decrypt_68k(image.device().machine());
527      neo_pcm2_swap(image.device().machine(), 5);
528      state->m_fixed_layer_bank_type = 2;
529      neogeo_cmc50_m1_decrypt(image.device().machine());
530      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x9d);
531      install_pvc_protection(image.device().machine());
532      logerror("Decrypted KOF2003 code and graphicss, and installed protection routines.\n");
533   }
534   if(strcmp(crypt_feature,"samsho5s_crypt") == 0)
535   {
536      samsh5sp_decrypt_68k(image.device().machine());
537      neo_pcm2_swap(image.device().machine(), 6);
538      state->m_fixed_layer_bank_type = 1;
539      neogeo_cmc50_m1_decrypt(image.device().machine());
540      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x0d);
541   }
542}
543
544/*
545    Load the cartridge image files. Apart from reading, we set pointers
546    to the image files so that during runtime we do not need search
547    operations.
548*/
549static DEVICE_IMAGE_LOAD( aes_cartridge )
550{
551   device_t *pcbdev = cartslot_get_pcb(image);
552   aes_pcb_t *pcb;
553   cartslot_t *cart;
554   multicart_open_error me;
555   UINT32 size;
556   device_t* ym = image.device().machine().device("ymsnd");
557
558   // first check software list
559   if(image.software_entry() != NULL)
560   {
561      // create memory regions
562      size = image.get_software_region_length("maincpu");
563      image.device().machine().region_free("maincpu");
564      image.device().machine().region_alloc("maincpu",size,1, ENDIANNESS_LITTLE);
565      memcpy(image.device().machine().region("maincpu")->base(),image.get_software_region("maincpu"),size);
566      size = image.get_software_region_length("fixed");
567      image.device().machine().region_free("fixed");
568      image.device().machine().region_alloc("fixed",size,1, ENDIANNESS_LITTLE);
569      memcpy(image.device().machine().region("fixed")->base(),image.get_software_region("fixed"),size);
570      size = image.get_software_region_length("audiocpu");
571      image.device().machine().region_free("audiocpu");
572      image.device().machine().region_alloc("audiocpu",size,1, ENDIANNESS_LITTLE);
573      memcpy(image.device().machine().region("audiocpu")->base(),image.get_software_region("audiocpu"),size);
574      size = image.get_software_region_length("ymsnd");
575      image.device().machine().region_free("ymsnd");
576      image.device().machine().region_alloc("ymsnd",size,1, ENDIANNESS_LITTLE);
577      memcpy(image.device().machine().region("ymsnd")->base(),image.get_software_region("ymsnd"),size);
578      if(image.get_software_region("ymsnd.deltat") != NULL)
579      {
580         size = image.get_software_region_length("ymsnd.deltat");
581         image.device().machine().region_free("ymsnd.deltat");
582         image.device().machine().region_alloc("ymsnd.deltat",size,1, ENDIANNESS_LITTLE);
583         memcpy(image.device().machine().region("ymsnd.deltat")->base(),image.get_software_region("ymsnd.deltat"),size);
584      }
585      else
586         image.device().machine().region_free("ymsnd.deltat");  // removing the region will fix sound glitches in non-Delta-T games
587      ym->reset();
588      size = image.get_software_region_length("sprites");
589      image.device().machine().region_free("sprites");
590      image.device().machine().region_alloc("sprites",size,1, ENDIANNESS_LITTLE);
591      memcpy(image.device().machine().region("sprites")->base(),image.get_software_region("sprites"),size);
592      if(image.get_software_region("audiocrypt") != NULL)  // encrypted Z80 code
593      {
594         size = image.get_software_region_length("audiocrypt");
595         image.device().machine().region_alloc("audiocrypt",size,1, ENDIANNESS_LITTLE);
596         memcpy(image.device().machine().region("audiocrypt")->base(),image.get_software_region("audiocrypt"),size);
597      }
598
599      // setup cartridge ROM area
600      image.device().machine().device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x000080,0x0fffff,"cart_rom");
601      memory_set_bankptr(image.device().machine(),"cart_rom",&image.device().machine().region("maincpu")->base()[0x80]);
602
603      // handle possible protection
604      install_protection(image);
605
606      return IMAGE_INIT_PASS;
607   }
608
609   if (pcbdev == NULL)
610      fatalerror("Error loading multicart: no pcb found.");
611
612   /* If we are here, we have a multicart. */
613   pcb = get_safe_pcb_token(pcbdev);
614   cart = get_safe_cartslot_token(&image.device());
615
616   /* try opening this as a multicart */
617   /* This line requires that cartslot_t be included in cartslot.h,
618    otherwise one cannot make use of multicart handling within such a
619    custom LOAD function. */
620   me = multicart_open(image.device().machine().options(), image.filename(), image.device().machine().system().name, MULTICART_FLAGS_LOAD_RESOURCES, &cart->mc);
621
622   /* Now that we have loaded the image files, let the PCB put them all
623    together. This means we put the images in a structure which allows
624    for a quick access by the memory handlers. Every PCB defines an
625    own assembly method. */
626    if (me != MCERR_NONE)
627      fatalerror("Error loading multicart: %s", multicart_error_text(me));
628
629   return pcb->assemble(pcbdev->machine(), image);
630}
631
632/*
633    This is called when the cartridge is unplugged (or the emulator is
634    stopped).
635*/
636static DEVICE_IMAGE_UNLOAD( aes_cartridge )
637{
638   device_t *pcbdev;
639
640   if (downcast<legacy_device_base *>(&image.device())->token() == NULL)
641   {
642      /* This means something went wrong during the pcb
643           identification (e.g. one of the cartridge files was not
644           found). We do not need to (and cannot) unload
645           the cartridge. */
646      return;
647   }
648   pcbdev = cartslot_get_pcb(image);
649
650   if (pcbdev != NULL)
651   {
652      aes_pcb_t *pcb = get_safe_pcb_token(pcbdev);
653      cartslot_t *cart = get_safe_cartslot_token(&image.device());
654
655      //  printf("unload\n");
656      if (cart->mc != NULL)
657      {
658         /* Remove pointers and de-big-endianize RAM contents. */
659         pcb->disassemble(pcbdev->machine(), image);
660
661         /* Close the multicart; all RAM resources will be
662               written to disk */
663         multicart_close(pcbdev->machine().options(), cart->mc);
664         cart->mc = NULL;
665      }
666//      else
667//          fatalerror("Lost pointer to multicart in cartridge. Report bug.");
668   }
669}
670
671/*****************************************************************************
672  The overall multi-cartridge slot system. It contains instances of
673  cartridges which contain PCB devices. The memory handlers delegate the calls
674  to the respective handlers of the cartridges.
675
676  Note that the term "multi-cartridge system" and "multicart" are not the same:
677  A "multicart" may contain multiple resources, organized on a PCB. The multi-
678  cart system may thus host multiple multicarts.
679
680  Actually, the name of the device should be changed (however, the device name
681  length is limited)
682******************************************************************************/
683/*
684    Instantiation of a multicart system for the Neo Geo AES.
685*/
686static DEVICE_START(aes_multicart)
687{
688   int i;
689//  printf("DEVICE_START(aes_multicart)\n");
690   aes_multicart_t *cartslots = get_safe_token(device);
691
692   /* Save this in the shortcut; we don't want to look for it each time
693       that we have a memory access. And currently we do not plan for
694       multiple multicart instances. */
695   cartslots->active_slot = 0;
696   cartslots->next_free_slot = 0;
697
698   for (i=0; i < AES_NUMBER_OF_CARTRIDGE_SLOTS; i++)
699   {
700      cartslots->cartridge[i].pcb = NULL;
701   }
702
703   cartslots->multi_slots = 0;
704
705   /* The cartslot system is initialized now. The cartridges themselves
706       need to check whether their parts are available. */
707}
708
709static DEVICE_STOP(aes_multicart)
710{
711//  printf("DEVICE_STOP(aes_multicart)\n");
712}
713
714static MACHINE_CONFIG_FRAGMENT(aes_multicart)
715   MCFG_CARTSLOT_ADD("cartridge1")
716   MCFG_CARTSLOT_EXTENSION_LIST("rpk,bin")
717   MCFG_CARTSLOT_PCBTYPE(0, "none", AES_CARTRIDGE_PCB_NONE)
718   MCFG_CARTSLOT_PCBTYPE(1, "standard", AES_CARTRIDGE_PCB_STD)
719
720   MCFG_CARTSLOT_START(aes_cartridge)
721   MCFG_CARTSLOT_LOAD(aes_cartridge)
722   MCFG_CARTSLOT_UNLOAD(aes_cartridge)
723   MCFG_CARTSLOT_INTERFACE("aes_cart")
724   MCFG_CARTSLOT_MANDATORY
725MACHINE_CONFIG_END
726
727
728DEVICE_GET_INFO(aes_multicart)
729{
730   switch (state)
731   {
732      /* --- the following bits of info are returned as pointers to data --- */
733      case DEVINFO_PTR_MACHINE_CONFIG:
734         info->machine_config = MACHINE_CONFIG_NAME(aes_multicart); break;
735
736      /* --- the following bits of info are returned as NULL-terminated strings --- */
737      case DEVINFO_STR_NAME:
738         strcpy(info->s, "AES Cartridge handler");
739         break;
740
741      case DEVINFO_INT_TOKEN_BYTES: /* private storage, automatically allocated */
742         info->i = sizeof(aes_multicart_t);
743         break;
744
745      case DEVINFO_STR_FAMILY:
746         strcpy(info->s, "Cartridge slot");
747         break;
748      case DEVINFO_STR_VERSION:
749         strcpy(info->s, "1.0");
750         break;
751      case DEVINFO_STR_SOURCE_FILE:
752         strcpy(info->s, __FILE__);
753         break;
754      /* --- the following bits of info are returned as pointers to functions --- */
755      case DEVINFO_FCT_START:
756         info->start = DEVICE_START_NAME(aes_multicart);
757         break;
758      case DEVINFO_FCT_STOP:
759         info->stop = DEVICE_STOP_NAME(aes_multicart);
760         break;
761      case DEVINFO_FCT_RESET:
762         /* Nothing */
763         break;
764   }
765}
766
767DEFINE_LEGACY_CART_SLOT_DEVICE(AES_MULTICART, aes_multicart);
768DEFINE_LEGACY_CART_SLOT_DEVICE(AES_CARTRIDGE_PCB_NONE, aes_cartridge_pcb_none);
769DEFINE_LEGACY_CART_SLOT_DEVICE(AES_CARTRIDGE_PCB_STD, aes_cartridge_pcb_std);
src/mame/machine/aescart.h
r0r11461
1/*********************************************************************
2
3    aescart.h
4
5    AES cartridge management
6
7*********************************************************************/
8
9#ifndef __AESCART_H__
10#define __AESCART_H__
11
12#include "image.h"
13#include "imagedev/cartslot.h"
14
15DECLARE_LEGACY_CART_SLOT_DEVICE(AES_MULTICART, aes_multicart);
16DECLARE_LEGACY_CART_SLOT_DEVICE(AES_CARTRIDGE_PCB_NONE, aes_cartridge_pcb_none);
17DECLARE_LEGACY_CART_SLOT_DEVICE(AES_CARTRIDGE_PCB_STD, aes_cartridge_pcb_std);
18
19/* There's only 1 slot in an AES */
20#define AES_NUMBER_OF_CARTRIDGE_SLOTS 1
21
22/* Generic AES cartridge structure. */
23struct _aescartridge_t
24{
25   /* PCB device associated to this cartridge. If NULL, the slot is empty. */
26   device_t *pcb;
27};
28typedef struct _aescartridge_t aescartridge_t;
29
30#define MCFG_AES_CARTRIDGE_ADD(_tag) \
31   MCFG_DEVICE_ADD(_tag, AES_MULTICART, 0)
32
33#endif /* __AESCART_H__ */
src/mame/machine/amigacd.c
r0r11461
1/***************************************************************************
2
3    Amiga CD-ROM controller emulation
4
5Notes:
6Many thanks to Toni Wilen for all the help and information about the
7DMAC controller.
8
9***************************************************************************/
10
11
12#include "emu.h"
13#include "includes/amiga.h"
14#include "amigacd.h"
15#include "machine/6525tpi.h"
16#include "machine/6526cia.h"
17#include "machine/wd33c93.h"
18#include "imagedev/chd_cd.h"
19#include "machine/matsucd.h"
20
21
22#define VERBOSE_DMAC 0
23
24#define LOG(x) do { if (VERBOSE_DMAC) logerror x; } while (0)
25
26/* constants */
27#define CD_SECTOR_TIME      (1000/((300*1024)/2048))   /* 2X CDROM sector time in msec (300KBps) */
28
29/***************************************************************************
30
31    DMAC
32
33***************************************************************************/
34
35/*
36 * value to go into DAWR
37 */
38#define DAWR_ATZSC      3       /* according to A3000T service-manual */
39
40/*
41 * bits defined for CNTR
42 */
43#define CNTR_TCEN       (1<<7)  /* Terminal Count Enable */
44#define CNTR_PREST      (1<<6)  /* Perp Reset (not implemented :-((( ) */
45#define CNTR_PDMD       (1<<5)  /* Perp Device Mode Select (1=SCSI,0=XT/AT) */
46#define CNTR_INTEN      (1<<4)  /* Interrupt Enable */
47#define CNTR_DDIR       (1<<3)  /* Device Direction. 1==rd host, wr to perp */
48
49/*
50 * bits defined for ISTR
51 */
52#define ISTR_INTX       (1<<8)  /* XT/AT Interrupt pending */
53#define ISTR_INT_F      (1<<7)  /* Interrupt Follow */
54#define ISTR_INTS       (1<<6)  /* SCSI Peripheral Interrupt */
55#define ISTR_E_INT      (1<<5)  /* End-Of-Process Interrupt */
56#define ISTR_INT_P      (1<<4)  /* Interrupt Pending */
57#define ISTR_UE_INT     (1<<3)  /* Under-Run FIFO Error Interrupt */
58#define ISTR_OE_INT     (1<<2)  /* Over-Run FIFO Error Interrupt */
59#define ISTR_FF_FLG     (1<<1)  /* FIFO-Full Flag */
60#define ISTR_FE_FLG     (1<<0)  /* FIFO-Empty Flag */
61
62typedef struct
63{
64   UINT16      istr;      /* Interrupt Status Register (R) */
65   UINT16      cntr;      /* Control Register (RW) */
66   UINT32      wtc;      /* Word Transfer Count Register (RW) */
67   UINT32      acr;      /* Address Count Register (RW) */
68   UINT16      dawr;      /* DACK Width Register (W) */
69   emu_timer *dma_timer;
70} _dmac_data;
71
72static _dmac_data dmac_data;
73
74static void check_interrupts( running_machine &machine )
75{
76   /* if interrupts are disabled, bail */
77   if ( (dmac_data.cntr & CNTR_INTEN) == 0 )
78      return;
79
80   /* if no interrupts are pending, bail */
81   if ( (dmac_data.istr & ISTR_INT_P) == 0 )
82      return;
83
84   /* otherwise, generate the IRQ */
85   amiga_custom_w(machine.device("maincpu")->memory().space(AS_PROGRAM), REG_INTREQ, 0x8000 | INTENA_PORTS, 0xffff);
86}
87
88static TIMER_CALLBACK(dmac_dma_proc)
89{
90   amiga_state *state = machine.driver_data<amiga_state>();
91   while( dmac_data.wtc > 0 )
92   {
93      UINT16   dat16;
94      UINT8   dat8;
95
96      if ( matsucd_get_next_byte( &dat8 ) < 0 )
97         break;
98
99      dat16 = dat8;
100
101      if ( matsucd_get_next_byte( &dat8 ) < 0 )
102         break;
103
104      dat16 <<= 8;
105      dat16 |= dat8;
106
107      (*state->m_chip_ram_w)(state, dmac_data.acr, dat16);
108
109      dmac_data.acr += 2;
110      dmac_data.wtc--;
111   }
112
113   if ( dmac_data.wtc > 0 )
114   {
115      matsucd_read_next_block();
116      dmac_data.dma_timer->adjust(attotime::from_msec( CD_SECTOR_TIME ));
117   }
118   else
119   {
120      dmac_data.istr |= ISTR_INT_P | ISTR_E_INT;
121      check_interrupts( machine );
122   }
123}
124
125static READ16_HANDLER( amiga_dmac_r )
126{
127   offset &= 0xff;
128
129   switch( offset )
130   {
131      case 0x20:
132      {
133         UINT8   v = dmac_data.istr;
134         LOG(( "DMAC: PC=%08x - ISTR Read(%04x)\n", cpu_get_pc(&space->device()), dmac_data.istr ));
135
136         dmac_data.istr &= ~0x0f;
137         return v;
138      }
139      break;
140
141      case 0x21:
142      {
143         LOG(( "DMAC: PC=%08x - CNTR Read(%04x)\n", cpu_get_pc(&space->device()), dmac_data.cntr ));
144         return dmac_data.cntr;
145      }
146      break;
147
148      case 0x40:   /* wtc hi */
149      {
150         LOG(( "DMAC: PC=%08x - WTC HI Read\n", cpu_get_pc(&space->device()) ));
151         return (dmac_data.wtc >> 16);
152      }
153      break;
154
155      case 0x41:   /* wtc lo */
156      {
157         LOG(( "DMAC: PC=%08x - WTC LO Read\n", cpu_get_pc(&space->device()) ));
158         return dmac_data.wtc;
159      }
160      break;
161
162      case 0x42:   /* acr hi */
163      {
164         LOG(( "DMAC: PC=%08x - ACR HI Read\n", cpu_get_pc(&space->device()) ));
165         return (dmac_data.acr >> 16);
166      }
167      break;
168
169      case 0x43:   /* acr lo */
170      {
171         LOG(( "DMAC: PC=%08x - ACR LO Read\n", cpu_get_pc(&space->device()) ));
172         return dmac_data.acr;
173      }
174      break;
175
176      case 0x48:   /* wd33c93 SCSI expansion */
177      case 0x49:
178      {
179         LOG(( "DMAC: PC=%08x - WD33C93 Read(%d)\n", cpu_get_pc(&space->device()), offset & 1 ));
180         return 0x00;   /* Not available without SCSI expansion */
181      }
182      break;
183
184      case 0x50:
185      {
186         LOG(( "DMAC: PC=%08x - CDROM RESP Read\n", cpu_get_pc(&space->device()) ));
187         return matsucd_response_r(space->machine());
188      }
189      break;
190
191      case 0x51:   /* XT IO */
192      case 0x52:
193      case 0x53:
194      {
195         LOG(( "DMAC: PC=%08x - XT IO Read(%d)\n", cpu_get_pc(&space->device()), (offset & 3)-1 ));
196         return 0xff;
197      }
198      break;
199
200      case 0x58:   /* TPI6525 */
201      case 0x59:
202      case 0x5A:
203      case 0x5B:
204      case 0x5C:
205      case 0x5D:
206      case 0x5E:
207      case 0x5F:
208      case 0x60:
209      case 0x61:
210      case 0x62:
211      case 0x63:
212      case 0x64:
213      case 0x65:
214      case 0x66:
215      case 0x67:
216      {
217         device_t *tpi = space->machine().device("tpi6525");
218         LOG(( "DMAC: PC=%08x - TPI6525 Read(%d)\n", cpu_get_pc(&space->device()), (offset - 0x58) ));
219         return tpi6525_r(tpi, offset - 0x58);
220      }
221      break;
222
223      case 0x70:   /* DMA start strobe */
224      {
225         LOG(( "DMAC: PC=%08x - DMA Start Strobe\n", cpu_get_pc(&space->device()) ));
226         dmac_data.dma_timer->adjust(attotime::from_msec( CD_SECTOR_TIME ));
227      }
228      break;
229
230      case 0x71:   /* DMA stop strobe */
231      {
232         LOG(( "DMAC: PC=%08x - DMA Stop Strobe\n", cpu_get_pc(&space->device()) ));
233         dmac_data.dma_timer->reset(  );
234      }
235      break;
236
237      case 0x72:   /* Clear IRQ strobe */
238      {
239         LOG(( "DMAC: PC=%08x - IRQ Clear Strobe\n", cpu_get_pc(&space->device()) ));
240         dmac_data.istr &= ~ISTR_INT_P;
241      }
242      break;
243
244      case 0x74:   /* Flush strobe */
245      {
246         LOG(( "DMAC: PC=%08x - Flush Strobe\n", cpu_get_pc(&space->device()) ));
247         dmac_data.istr |= ISTR_FE_FLG;
248      }
249      break;
250
251      default:
252         logerror( "DMAC-READ: PC=%08x, offset = %02x\n", cpu_get_pc(&space->device()), offset );
253      break;
254   }
255
256   return 0;
257}
258
259static WRITE16_HANDLER( amiga_dmac_w )
260{
261   offset &= 0xff;
262
263   switch( offset )
264   {
265      case 0x21:   /* control write */
266      {
267         LOG(( "DMAC: PC=%08x - CNTR Write(%04x)\n", cpu_get_pc(&space->device()), data ));
268         dmac_data.cntr = data;
269         check_interrupts(space->machine());
270      }
271      break;
272
273      case 0x40:   /* wtc hi */
274      {
275         LOG(( "DMAC: PC=%08x - WTC HI Write - data = %04x\n", cpu_get_pc(&space->device()), data ));
276         dmac_data.wtc &= 0x0000ffff;
277         dmac_data.wtc |= ((UINT32)data) << 16;
278      }
279      break;
280
281      case 0x41:   /* wtc lo */
282      {
283         LOG(( "DMAC: PC=%08x - WTC LO Write - data = %04x\n", cpu_get_pc(&space->device()), data ));
284         dmac_data.wtc &= 0xffff0000;
285         dmac_data.wtc |= data;
286      }
287      break;
288
289      case 0x42:   /* acr hi */
290      {
291         LOG(( "DMAC: PC=%08x - ACR HI Write - data = %04x\n", cpu_get_pc(&space->device()), data ));
292         dmac_data.acr &= 0x0000ffff;
293         dmac_data.acr |= ((UINT32)data) << 16;
294      }
295      break;
296
297      case 0x43:   /* acr lo */
298      {
299         LOG(( "DMAC: PC=%08x - ACR LO Write - data = %04x\n", cpu_get_pc(&space->device()), data ));
300         dmac_data.acr &= 0xffff0000;
301         dmac_data.acr |= data;
302      }
303      break;
304
305      case 0x47:   /* dawr */
306      {
307         LOG(( "DMAC: PC=%08x - DAWR Write - data = %04x\n", cpu_get_pc(&space->device()), data ));
308         dmac_data.dawr = data;
309      }
310      break;
311
312      case 0x48:   /* wd33c93 SCSI expansion */
313      case 0x49:
314      {
315         LOG(( "DMAC: PC=%08x - WD33C93 Write(%d) - data = %04x\n", cpu_get_pc(&space->device()), offset & 1, data ));
316         /* Not available without SCSI expansion */
317      }
318      break;
319
320      case 0x50:
321      {
322         LOG(( "DMAC: PC=%08x - CDROM CMD Write - data = %04x\n", cpu_get_pc(&space->device()), data ));
323         matsucd_command_w(space->machine(), data );
324      }
325      break;
326
327      case 0x58:   /* TPI6525 */
328      case 0x59:
329      case 0x5A:
330      case 0x5B:
331      case 0x5C:
332      case 0x5D:
333      case 0x5E:
334      case 0x5F:
335      case 0x60:
336      case 0x61:
337      case 0x62:
338      case 0x63:
339      case 0x64:
340      case 0x65:
341      case 0x66:
342      case 0x67:
343      {
344         device_t *tpi = space->machine().device("tpi6525");
345         LOG(( "DMAC: PC=%08x - TPI6525 Write(%d) - data = %04x\n", cpu_get_pc(&space->device()), (offset - 0x58), data ));
346         tpi6525_w(tpi, offset - 0x58, data);
347      }
348      break;
349
350      case 0x70:   /* DMA start strobe */
351      {
352         LOG(( "DMAC: PC=%08x - DMA Start Strobe\n", cpu_get_pc(&space->device()) ));
353         dmac_data.dma_timer->adjust(attotime::from_msec( CD_SECTOR_TIME ));
354      }
355      break;
356
357      case 0x71:   /* DMA stop strobe */
358      {
359         LOG(( "DMAC: PC=%08x - DMA Stop Strobe\n", cpu_get_pc(&space->device()) ));
360         dmac_data.dma_timer->reset(  );
361      }
362      break;
363
364      case 0x72:   /* Clear IRQ strobe */
365      {
366         LOG(( "DMAC: PC=%08x - IRQ Clear Strobe\n", cpu_get_pc(&space->device()) ));
367         dmac_data.istr &= ~ISTR_INT_P;
368      }
369      break;
370
371      case 0x74:   /* Flush Strobe */
372      {
373         LOG(( "DMAC: PC=%08x - Flush Strobe\n", cpu_get_pc(&space->device()) ));
374         dmac_data.istr |= ISTR_FE_FLG;
375      }
376      break;
377
378      default:
379         logerror( "DMAC-WRITE: PC=%08x, offset = %02x, data = %04x\n", cpu_get_pc(&space->device()), offset, data );
380      break;
381   }
382}
383
384/***************************************************************************
385
386    Autoconfig
387
388***************************************************************************/
389
390static void   dmac_install(running_machine &machine, offs_t base)
391{
392   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
393   space->install_legacy_read_handler(base, base + 0xFFFF, FUNC(amiga_dmac_r));
394   space->install_legacy_write_handler(base, base + 0xFFFF, FUNC(amiga_dmac_w));
395}
396
397static void   dmac_uninstall(running_machine &machine, offs_t base)
398{
399   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
400   space->unmap_readwrite(base, base + 0xFFFF);
401}
402
403static const amiga_autoconfig_device dmac_device =
404{
405   0,            /* link into free memory list */
406   0,            /* ROM vector offset valid */
407   0,            /* multiple devices on card */
408   1,            /* number of 64k pages */
409   3,            /* product number (DMAC) */
410   0,            /* prefer 8MB address space */
411   0,            /* can be shut up */
412   0x0202,         /* manufacturers number (Commodore) */
413   0,            /* serial number */
414   0,            /* ROM vector offset */
415   NULL,         /* interrupt control read */
416   NULL,         /* interrupt control write */
417   dmac_install,   /* memory installation */
418   dmac_uninstall   /* memory uninstallation */
419};
420
421/***************************************************************************
422
423    TPI6525
424
425***************************************************************************/
426
427READ8_DEVICE_HANDLER( amigacd_tpi6525_portc_r )
428{
429   int   ret = 0;
430
431   if ( (tpi6525_get_ddr_c(device) & 0x04) == 0 ) /* if pin 2 is set to input */
432   {
433      ret |= matsucd_stch_r() ? 0x00 : 0x04;   /* read status change signal */
434   }
435
436   if ( (tpi6525_get_ddr_c(device) & 0x08) == 0 ) /* if pin 3 is set to input */
437      ret |= matsucd_sten_r() ? 0x08 : 0x00;   /* read enable signal */
438
439   return ret;
440}
441
442WRITE8_DEVICE_HANDLER( amigacd_tpi6525_portb_w )
443{
444   if ( tpi6525_get_ddr_b(device) & 0x01 ) /* if pin 0 is set to output */
445      matsucd_cmd_w( data & 1 ); /* write to the /CMD signal */
446
447   if ( tpi6525_get_ddr_b(device) & 0x02 ) /* if pin 1 is set to output */
448      matsucd_enable_w( data & 2 ); /* write to the /ENABLE signal */
449}
450
451static emu_timer *tp6525_delayed_timer;
452
453static TIMER_CALLBACK(tp6525_delayed_irq)
454{
455   amiga_state *state = machine.driver_data<amiga_state>();
456   (void)param;
457
458   if ( (CUSTOM_REG(REG_INTREQ) & INTENA_PORTS) == 0 )
459   {
460      amiga_custom_w(machine.device("maincpu")->memory().space(AS_PROGRAM), REG_INTREQ, 0x8000 | INTENA_PORTS, 0xffff);
461   }
462   else
463   {
464      tp6525_delayed_timer->adjust(attotime::from_msec(1));
465   }
466}
467
468static void amigacd_tpi6525_irq_trampoline(device_t *device, int level)
469{
470   amiga_state *state = device->machine().driver_data<amiga_state>();
471   LOG(( "TPI6525 Interrupt: level = %d\n", level ));
472
473   if ( level )
474   {
475      if ( (CUSTOM_REG(REG_INTREQ) & INTENA_PORTS) == 0 )
476      {
477         amiga_custom_w(device->machine().device("maincpu")->memory().space(AS_PROGRAM), REG_INTREQ, 0x8000 | INTENA_PORTS, 0xffff);
478      }
479      else
480      {
481         /* we *have to* deliver the irq, so if we can't, delay it and try again later */
482         tp6525_delayed_timer->adjust(attotime::from_msec(1));
483      }
484   }
485}
486
487WRITE_LINE_DEVICE_HANDLER( amigacd_tpi6525_irq )
488{
489   amigacd_tpi6525_irq_trampoline(device, state);
490}
491
492static void cdrom_status_enabled( running_machine &machine, int level )
493{
494   device_t *tpi = machine.device("tpi6525");
495
496   /* PC3 on the 6525 */
497   tpi6525_i3_w(tpi, level);
498}
499
500static void cdrom_status_change( running_machine &machine, int level )
501{
502   device_t *tpi = machine.device("tpi6525");
503
504   /* invert */
505   level = level ? 0 : 1;
506
507   /* PC2 on the 6525 */
508   tpi6525_i2_w(tpi, level);
509}
510
511static void cdrom_subcode_ready( running_machine &machine, int level )
512{
513   device_t *tpi = machine.device("tpi6525");
514
515   /* PC1 on the 6525 */
516   tpi6525_i1_w(tpi, level);
517}
518
519MACHINE_START( amigacd )
520{
521   /* initialize the dmac */
522   memset( &dmac_data, 0, sizeof( dmac_data ) );
523
524   dmac_data.dma_timer = machine.scheduler().timer_alloc(FUNC(dmac_dma_proc));
525   tp6525_delayed_timer = machine.scheduler().timer_alloc(FUNC(tp6525_delayed_irq));
526
527   /* set up DMAC with autoconfig */
528   amiga_add_autoconfig( machine, &dmac_device );
529
530   matsucd_init( machine.device("cdrom"), "cdda" );
531}
532
533MACHINE_RESET( amigacd )
534{
535   /* initialize the cdrom */
536   matsucd_set_status_enabled_callback( cdrom_status_enabled );
537   matsucd_set_status_changed_callback( cdrom_status_change );
538   matsucd_set_subcode_ready_callback( cdrom_subcode_ready );
539}
src/mame/machine/nes.c
r0r11461
1#include "emu.h"
2#include "crsshair.h"
3#include "hash.h"
4#include "cpu/m6502/m6502.h"
5#include "video/ppu2c0x.h"
6#include "includes/nes.h"
7#include "machine/nes_mmc.h"
8#include "imagedev/cartslot.h"
9#include "imagedev/flopdrv.h"
10#include "hashfile.h"
11
12/***************************************************************************
13    CONSTANTS
14***************************************************************************/
15
16/* Set to dump info about the inputs to the errorlog */
17#define LOG_JOY      0
18
19/* Set to generate prg & chr files when the cart is loaded */
20#define SPLIT_PRG   0
21#define SPLIT_CHR   0
22
23/***************************************************************************
24    FUNCTION PROTOTYPES
25***************************************************************************/
26
27static void init_nes_core(running_machine &machine);
28static void nes_machine_stop(running_machine &machine);
29static READ8_HANDLER(nes_fds_r);
30static WRITE8_HANDLER(nes_fds_w);
31static void fds_irq(device_t *device, int scanline, int vblank, int blanked);
32
33/***************************************************************************
34    FUNCTIONS
35***************************************************************************/
36
37static void init_nes_core( running_machine &machine )
38{
39   nes_state *state = machine.driver_data<nes_state>();
40   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
41   static const char *const bank_names[] = { "bank1", "bank2", "bank3", "bank4" };
42   int prg_banks = (state->m_prg_chunks == 1) ? (2 * 2) : (state->m_prg_chunks * 2);
43   int i;
44
45   /* We set these here in case they weren't set in the cart loader */
46   state->m_rom = machine.region("maincpu")->base();
47   state->m_vrom = machine.region("gfx1")->base();
48   state->m_vram = machine.region("gfx2")->base();
49   state->m_ciram = machine.region("gfx3")->base();
50
51   /* Brutal hack put in as a consequence of the new memory system; we really need to fix the NES code */
52   space->install_readwrite_bank(0x0000, 0x07ff, 0, 0x1800, "bank10");
53
54   machine.device("ppu")->memory().space(AS_PROGRAM)->install_legacy_readwrite_handler(0, 0x1fff, FUNC(nes_chr_r), FUNC(nes_chr_w));
55   machine.device("ppu")->memory().space(AS_PROGRAM)->install_legacy_readwrite_handler(0x2000, 0x3eff, FUNC(nes_nt_r), FUNC(nes_nt_w));
56
57   memory_set_bankptr(machine, "bank10", state->m_rom);
58
59   /* If there is Disk Expansion and no cart has been loaded, setup memory accordingly */
60   if (state->m_disk_expansion && state->m_pcb_id == NO_BOARD)
61   {
62      /* If we are loading a disk we have already filled state->m_fds_data and we don't want to overwrite it,
63         if we are loading a cart image identified as mapper 20 (probably wrong mapper...) we need to alloc
64         memory for use in nes_fds_r/nes_fds_w. Same goes for allocation of fds_ram (used for bank2)  */
65      if (state->m_fds_data == NULL)
66      {
67         UINT32 size = machine.region("maincpu")->bytes() - 0x10000;
68         state->m_fds_data = auto_alloc_array_clear(machine, UINT8, size);
69         memcpy(state->m_fds_data, state->m_rom, size);   // copy in fds_data the cart PRG
70      }
71      if (state->m_fds_ram == NULL)
72         state->m_fds_ram = auto_alloc_array(machine, UINT8, 0x8000);
73
74      space->install_legacy_read_handler(0x4030, 0x403f, FUNC(nes_fds_r));
75      space->install_read_bank(0x6000, 0xdfff, "bank2");
76      space->install_read_bank(0xe000, 0xffff, "bank1");
77
78      space->install_legacy_write_handler(0x4020, 0x402f, FUNC(nes_fds_w));
79      space->install_write_bank(0x6000, 0xdfff, "bank2");
80
81      memory_set_bankptr(machine, "bank1", &state->m_rom[0xe000]);
82      memory_set_bankptr(machine, "bank2", state->m_fds_ram);
83      return;
84   }
85
86   /* Set up the mapper callbacks */
87   pcb_handlers_setup(machine);
88
89   /* Set up the memory handlers for the mapper */
90   space->install_read_bank(0x8000, 0x9fff, "bank1");
91   space->install_read_bank(0xa000, 0xbfff, "bank2");
92   space->install_read_bank(0xc000, 0xdfff, "bank3");
93   space->install_read_bank(0xe000, 0xffff, "bank4");
94   space->install_readwrite_bank(0x6000, 0x7fff, "bank5");
95
96   /* configure banks 1-4 */
97   for (i = 0; i < 4; i++)
98   {
99      memory_configure_bank(machine, bank_names[i], 0, prg_banks, machine.region("maincpu")->base() + 0x10000, 0x2000);
100      // some mappers (e.g. MMC5) can map PRG RAM in  0x8000-0xffff as well
101      if (state->m_prg_ram)
102         memory_configure_bank(machine, bank_names[i], prg_banks, state->m_wram_size / 0x2000, state->m_wram, 0x2000);
103      // however, at start we point to PRG ROM
104      memory_set_bank(machine, bank_names[i], i);
105      state->m_prg_bank[i] = i;
106   }
107
108   /* bank 5 configuration is more delicate, since it can have PRG RAM, PRG ROM or SRAM mapped to it */
109   /* we first map PRG ROM banks, then the battery bank (if a battery is present), and finally PRG RAM (state->m_wram) */
110   memory_configure_bank(machine, "bank5", 0, prg_banks, machine.region("maincpu")->base() + 0x10000, 0x2000);
111   state->m_battery_bank5_start = prg_banks;
112   state->m_prgram_bank5_start = prg_banks;
113   state->m_empty_bank5_start = prg_banks;
114
115   /* add battery ram, but only if there's no trainer since they share overlapping memory. */
116   if (state->m_battery && !state->m_trainer)
117   {
118      UINT32 bank_size = (state->m_battery_size > 0x2000) ? 0x2000 : state->m_battery_size;
119      int bank_num = (state->m_battery_size > 0x2000) ? state->m_battery_size / 0x2000 : 1;
120      memory_configure_bank(machine, "bank5", prg_banks, bank_num, state->m_battery_ram, bank_size);
121      state->m_prgram_bank5_start += bank_num;
122      state->m_empty_bank5_start += bank_num;
123   }
124   /* add prg ram. */
125   if (state->m_prg_ram)
126   {
127      memory_configure_bank(machine, "bank5", state->m_prgram_bank5_start, state->m_wram_size / 0x2000, state->m_wram, 0x2000);
128      state->m_empty_bank5_start += state->m_wram_size / 0x2000;
129   }
130
131   memory_configure_bank(machine, "bank5", state->m_empty_bank5_start, 1, state->m_rom + 0x6000, 0x2000);
132
133   /* if we have any additional PRG RAM, point bank5 to its first bank */
134   if (state->m_battery || state->m_prg_ram)
135      state->m_prg_bank[4] = state->m_battery_bank5_start;
136   else
137      state->m_prg_bank[4] = state->m_empty_bank5_start; // or shall we point to "maincpu" region at 0x6000? point is that we should never access this region if no sram or wram is present!
138
139   memory_set_bank(machine, "bank5", state->m_prg_bank[4]);
140
141   if (state->m_four_screen_vram)
142   {
143      state->m_extended_ntram = auto_alloc_array(machine, UINT8, 0x2000);
144      state->save_pointer(NAME(state->m_extended_ntram), 0x2000);
145   }
146
147   // there are still some quirk about writes to bank5... I hope to fix them soon. (mappers 34,45,52,246 have both mid_w and WRAM-->check)
148   if (state->m_mmc_write_mid)
149      space->install_legacy_write_handler(0x6000, 0x7fff, state->m_mmc_write_mid,state->m_mmc_write_mid_name);
150   if (state->m_mmc_write)
151      space->install_legacy_write_handler(0x8000, 0xffff, state->m_mmc_write, state->m_mmc_write_name);
152
153   // In fact, we also allow single pcbs to overwrite the bank read handlers defined above,
154   // because some pcbs (mainly pirate ones) require protection values to be read instead of
155   // the expected ROM banks: these handlers, though, must take care of the ROM access as well
156   if (state->m_mmc_read_mid)
157      space->install_legacy_read_handler(0x6000, 0x7fff, state->m_mmc_read_mid,state->m_mmc_read_mid_name);
158   if (state->m_mmc_read)
159      space->install_legacy_read_handler(0x8000, 0xffff, state->m_mmc_read,state->m_mmc_read_name);
160
161   // install additional handlers
162   if (state->m_pcb_id == BTL_SMB2B || state->m_mapper == 50)
163   {
164      space->install_legacy_write_handler(0x4020, 0x403f, FUNC(smb2jb_extra_w));
165      space->install_legacy_write_handler(0x40a0, 0x40bf, FUNC(smb2jb_extra_w));
166   }
167
168   if (state->m_pcb_id == KAISER_KS7017)
169   {
170      space->install_legacy_read_handler(0x4030, 0x4030, FUNC(ks7017_extra_r));
171      space->install_legacy_write_handler(0x4020, 0x40ff, FUNC(ks7017_extra_w));
172   }
173
174   if (state->m_pcb_id == UNL_603_5052)
175   {
176      space->install_legacy_read_handler(0x4020, 0x40ff, FUNC(unl_6035052_extra_r));
177      space->install_legacy_write_handler(0x4020, 0x40ff, FUNC(unl_6035052_extra_w));
178   }
179
180   if (state->m_pcb_id == WAIXING_SH2)
181      machine.device("ppu")->memory().space(AS_PROGRAM)->install_legacy_read_handler(0, 0x1fff, FUNC(waixing_sh2_chr_r));
182}
183
184// to be probably removed (it does nothing since a long time)
185int nes_ppu_vidaccess( device_t *device, int address, int data )
186{
187   return data;
188}
189
190MACHINE_RESET( nes )
191{
192   nes_state *state = machine.driver_data<nes_state>();
193
194   /* Reset the mapper variables. Will also mark the char-gen ram as dirty */
195   if (state->m_disk_expansion && state->m_pcb_id == NO_BOARD)
196      ppu2c0x_set_hblank_callback(state->m_ppu, fds_irq);
197   else
198      nes_pcb_reset(machine);
199
200   /* Reset the serial input ports */
201   state->m_in_0.shift = 0;
202   state->m_in_1.shift = 0;
203
204   machine.device("maincpu")->reset();
205}
206
207static TIMER_CALLBACK( nes_irq_callback )
208{
209   nes_state *state = machine.driver_data<nes_state>();
210   device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
211   state->m_irq_timer->adjust(attotime::never);
212}
213
214static void nes_banks_restore(nes_state *state)
215{
216   memory_set_bank(state->machine(), "bank1", state->m_prg_bank[0]);
217   memory_set_bank(state->machine(), "bank2", state->m_prg_bank[1]);
218   memory_set_bank(state->machine(), "bank3", state->m_prg_bank[2]);
219   memory_set_bank(state->machine(), "bank4", state->m_prg_bank[3]);
220   memory_set_bank(state->machine(), "bank5", state->m_prg_bank[4]);
221}
222
223static void nes_state_register( running_machine &machine )
224{
225   nes_state *state = machine.driver_data<nes_state>();
226
227   state->save_item(NAME(state->m_prg_bank));
228
229   state->save_item(NAME(state->m_MMC5_floodtile));
230   state->save_item(NAME(state->m_MMC5_floodattr));
231   state->save_item(NAME(state->m_mmc5_vram_control));
232
233   state->save_item(NAME(state->m_nes_vram_sprite));
234   state->save_item(NAME(state->m_last_frame_flip));
235
236   // shared mapper variables
237   state->save_item(NAME(state->m_IRQ_enable));
238   state->save_item(NAME(state->m_IRQ_enable_latch));
239   state->save_item(NAME(state->m_IRQ_count));
240   state->save_item(NAME(state->m_IRQ_count_latch));
241   state->save_item(NAME(state->m_IRQ_toggle));
242   state->save_item(NAME(state->m_IRQ_reset));
243   state->save_item(NAME(state->m_IRQ_status));
244   state->save_item(NAME(state->m_IRQ_mode));
245   state->save_item(NAME(state->m_mult1));
246   state->save_item(NAME(state->m_mult2));
247   state->save_item(NAME(state->m_mmc_chr_source));
248   state->save_item(NAME(state->m_mmc_cmd1));
249   state->save_item(NAME(state->m_mmc_cmd2));
250   state->save_item(NAME(state->m_mmc_count));
251   state->save_item(NAME(state->m_mmc_prg_base));
252   state->save_item(NAME(state->m_mmc_prg_mask));
253   state->save_item(NAME(state->m_mmc_chr_base));
254   state->save_item(NAME(state->m_mmc_chr_mask));
255   state->save_item(NAME(state->m_mmc_prg_bank));
256   state->save_item(NAME(state->m_mmc_vrom_bank));
257   state->save_item(NAME(state->m_mmc_extra_bank));
258
259   state->save_item(NAME(state->m_fds_motor_on));
260   state->save_item(NAME(state->m_fds_door_closed));
261   state->save_item(NAME(state->m_fds_current_side));
262   state->save_item(NAME(state->m_fds_head_position));
263   state->save_item(NAME(state->m_fds_status0));
264   state->save_item(NAME(state->m_fds_read_mode));
265   state->save_item(NAME(state->m_fds_write_reg));
266   state->save_item(NAME(state->m_fds_last_side));
267   state->save_item(NAME(state->m_fds_count));
268
269   state->save_pointer(NAME(state->m_wram), state->m_wram_size);
270   if (state->m_battery)
271      state->save_pointer(NAME(state->m_battery_ram), state->m_battery_size);
272
273   machine.save().register_postload(save_prepost_delegate(FUNC(nes_banks_restore), state));
274}
275
276MACHINE_START( nes )
277{
278   nes_state *state = machine.driver_data<nes_state>();
279
280   init_nes_core(machine);
281   machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(nes_machine_stop),&machine));
282
283   state->m_maincpu = machine.device("maincpu");
284   state->m_ppu = machine.device("ppu");
285   state->m_sound = machine.device("nessound");
286   state->m_cart = machine.device("cart");
287
288   state->m_irq_timer = machine.scheduler().timer_alloc(FUNC(nes_irq_callback));
289   nes_state_register(machine);
290}
291
292static void nes_machine_stop( running_machine &machine )
293{
294   nes_state *state = machine.driver_data<nes_state>();
295   device_image_interface *image = dynamic_cast<device_image_interface *>(state->m_cart);
296   /* Write out the battery file if necessary */
297   if (state->m_battery)
298      image->battery_save(state->m_battery_ram, state->m_battery_size);
299
300   if (state->m_mapper_bram_size)
301      image->battery_save(state->m_mapper_bram, state->m_mapper_bram_size);
302}
303
304
305
306READ8_HANDLER( nes_IN0_r )
307{
308   nes_state *state = space->machine().driver_data<nes_state>();
309   int cfg = input_port_read(space->machine(), "CTRLSEL");
310   int ret;
311
312   if ((cfg & 0x000f) >= 0x07)   // for now we treat the FC keyboard separately from other inputs!
313   {
314      // here we should have the tape input
315      ret = 0;
316   }
317   else
318   {
319      /* Some games expect bit 6 to be set because the last entry on the data bus shows up */
320      /* in the unused upper 3 bits, so typically a read from $4016 leaves 0x40 there. */
321      ret = 0x40;
322
323      ret |= ((state->m_in_0.i0 >> state->m_in_0.shift) & 0x01);
324
325      /* zapper */
326      if ((cfg & 0x000f) == 0x0002)
327      {
328         int x = state->m_in_0.i1;   /* read Zapper x-position */
329         int y = state->m_in_0.i2;   /* read Zapper y-position */
330         UINT32 pix, color_base;
331
332         /* get the pixel at the gun position */
333         pix = ppu2c0x_get_pixel(state->m_ppu, x, y);
334
335         /* get the color base from the ppu */
336         color_base = ppu2c0x_get_colorbase(state->m_ppu);
337
338         /* look at the screen and see if the cursor is over a bright pixel */
339         if ((pix == color_base + 0x20) || (pix == color_base + 0x30) ||
340            (pix == color_base + 0x33) || (pix == color_base + 0x34))
341         {
342            ret &= ~0x08; /* sprite hit */
343         }
344         else
345            ret |= 0x08;  /* no sprite hit */
346
347         /* If button 1 is pressed, indicate the light gun trigger is pressed */
348         ret |= ((state->m_in_0.i0 & 0x01) << 4);
349      }
350
351      if (LOG_JOY)
352         logerror("joy 0 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc(&space->device()), state->m_in_0.shift, state->m_in_0.i0);
353
354      state->m_in_0.shift++;
355   }
356
357   return ret;
358}
359
360// row of the keyboard matrix are read 4-bits at time, and gets returned as bit1->bit4
361static UINT8 nes_read_fc_keyboard_line( running_machine &machine, UINT8 scan, UINT8 mode )
362{
363   static const char *const fc_keyport_names[] = { "FCKEY0", "FCKEY1", "FCKEY2", "FCKEY3", "FCKEY4", "FCKEY5", "FCKEY6", "FCKEY7", "FCKEY8" };
364   return ((input_port_read(machine, fc_keyport_names[scan]) >> (mode * 4)) & 0x0f) << 1;
365}
366
367static UINT8 nes_read_subor_keyboard_line( running_machine &machine, UINT8 scan, UINT8 mode )
368{
369   static const char *const sub_keyport_names[] = { "SUBKEY0", "SUBKEY1", "SUBKEY2", "SUBKEY3", "SUBKEY4",
370      "SUBKEY5", "SUBKEY6", "SUBKEY7", "SUBKEY8", "SUBKEY9", "SUBKEY10", "SUBKEY11", "SUBKEY12" };
371   return ((input_port_read(machine, sub_keyport_names[scan]) >> (mode * 4)) & 0x0f) << 1;
372}
373
374READ8_HANDLER( nes_IN1_r )
375{
376   nes_state *state = space->machine().driver_data<nes_state>();
377   int cfg = input_port_read(space->machine(), "CTRLSEL");
378   int ret;
379
380   if ((cfg & 0x000f) == 0x07)   // for now we treat the FC keyboard separately from other inputs!
381   {
382      if (state->m_fck_scan < 9)
383         ret = ~nes_read_fc_keyboard_line(space->machine(), state->m_fck_scan, state->m_fck_mode) & 0x1e;
384      else
385         ret = 0x1e;
386   }
387   else if ((cfg & 0x000f) == 0x08)   // for now we treat the Subor keyboard separately from other inputs!
388   {
389      if (state->m_fck_scan < 12)
390         ret = ~nes_read_subor_keyboard_line(space->machine(), state->m_fck_scan, state->m_fck_mode) & 0x1e;
391      else
392         ret = 0x1e;
393   }
394   else
395   {
396      /* Some games expect bit 6 to be set because the last entry on the data bus shows up */
397      /* in the unused upper 3 bits, so typically a read from $4017 leaves 0x40 there. */
398      ret = 0x40;
399
400      /* Handle data line 0's serial output */
401      ret |= ((state->m_in_1.i0 >> state->m_in_1.shift) & 0x01);
402
403      /* zapper */
404      if ((cfg & 0x00f0) == 0x0030)
405      {
406         int x = state->m_in_1.i1;   /* read Zapper x-position */
407         int y = state->m_in_1.i2;   /* read Zapper y-position */
408         UINT32 pix, color_base;
409
410         /* get the pixel at the gun position */
411         pix = ppu2c0x_get_pixel(state->m_ppu, x, y);
412
413         /* get the color base from the ppu */
414         color_base = ppu2c0x_get_colorbase(state->m_ppu);
415
416         /* look at the screen and see if the cursor is over a bright pixel */
417         if ((pix == color_base + 0x20) || (pix == color_base + 0x30) ||
418            (pix == color_base + 0x33) || (pix == color_base + 0x34))
419         {
420            ret &= ~0x08; /* sprite hit */
421         }
422         else
423            ret |= 0x08;  /* no sprite hit */
424
425         /* If button 1 is pressed, indicate the light gun trigger is pressed */
426         ret |= ((state->m_in_1.i0 & 0x01) << 4);
427      }
428
429      /* arkanoid dial */
430      else if ((cfg & 0x00f0) == 0x0040)
431      {
432         /* Handle data line 2's serial output */
433         ret |= ((state->m_in_1.i2 >> state->m_in_1.shift) & 0x01) << 3;
434
435         /* Handle data line 3's serial output - bits are reversed */
436         /* NPW 27-Nov-2007 - there is no third subscript! commenting out */
437         /* ret |= ((state->m_in_1[3] >> state->m_in_1.shift) & 0x01) << 4; */
438         /* ret |= ((state->m_in_1[3] << state->m_in_1.shift) & 0x80) >> 3; */
439      }
440
441      if (LOG_JOY)
442         logerror("joy 1 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc(&space->device()), state->m_in_1.shift, state->m_in_1.i0);
443
444      state->m_in_1.shift++;
445   }
446
447   return ret;
448}
449
450
451// FIXME: this is getting messier and messier (no pun intended). inputs reading should be simplified and port_categories cleaned up
452// to also emulate the fact that nothing should be in Port 2 if there is a Crazy Climber pad, etc.
453static void nes_read_input_device( running_machine &machine, int cfg, nes_input *vals, int pad_port, int supports_zapper )
454{
455   nes_state *state = machine.driver_data<nes_state>();
456   static const char *const padnames[] = { "PAD1", "PAD2", "PAD3", "PAD4", "CC_LEFT", "CC_RIGHT" };
457
458   vals->i0 = 0;
459   vals->i1 = 0;
460   vals->i2 = 0;
461
462   switch (cfg & 0x0f)
463   {
464      case 0x01:   /* gamepad */
465         if (pad_port >= 0)
466            vals->i0 = input_port_read(machine, padnames[pad_port]);
467         break;
468
469      case 0x02:   /* zapper 1 */
470         if (supports_zapper)
471         {
472            vals->i0 = input_port_read(machine, "ZAPPER1_T");
473            vals->i1 = input_port_read(machine, "ZAPPER1_X");
474            vals->i2 = input_port_read(machine, "ZAPPER1_Y");
475         }
476         break;
477
478      case 0x03:   /* zapper 2 */
479         if (supports_zapper)
480         {
481            vals->i0 = input_port_read(machine, "ZAPPER2_T");
482            vals->i1 = input_port_read(machine, "ZAPPER2_X");
483            vals->i2 = input_port_read(machine, "ZAPPER2_Y");
484         }
485         break;
486
487      case 0x04:   /* arkanoid paddle */
488         if (pad_port == 1)
489            vals->i0 = (UINT8) ((UINT8) input_port_read(machine, "PADDLE") + (UINT8)0x52) ^ 0xff;
490         break;
491
492      case 0x05:   /* crazy climber controller */
493         if (pad_port == 0)
494         {
495            state->m_in_0.i0 = input_port_read(machine, padnames[4]);
496            state->m_in_1.i0 = input_port_read(machine, padnames[5]);
497         }
498         break;
499   }
500}
501
502
503static TIMER_CALLBACK( lightgun_tick )
504{
505   if ((input_port_read(machine, "CTRLSEL") & 0x000f) == 0x0002)
506   {
507      /* enable lightpen crosshair */
508      crosshair_set_screen(machine, 0, CROSSHAIR_SCREEN_ALL);
509   }
510   else
511   {
512      /* disable lightpen crosshair */
513      crosshair_set_screen(machine, 0, CROSSHAIR_SCREEN_NONE);
514   }
515
516   if ((input_port_read(machine, "CTRLSEL") & 0x00f0) == 0x0030)
517   {
518      /* enable lightpen crosshair */
519      crosshair_set_screen(machine, 1, CROSSHAIR_SCREEN_ALL);
520   }
521   else
522   {
523      /* disable lightpen crosshair */
524      crosshair_set_screen(machine, 1, CROSSHAIR_SCREEN_NONE);
525   }
526}
527
528WRITE8_HANDLER( nes_IN0_w )
529{
530   nes_state *state = space->machine().driver_data<nes_state>();
531   int cfg = input_port_read(space->machine(), "CTRLSEL");
532
533   /* Check if lightgun has been chosen as input: if so, enable crosshair */
534   space->machine().scheduler().timer_set(attotime::zero, FUNC(lightgun_tick));
535
536   if ((cfg & 0x000f) >= 0x07)   // for now we treat the FC keyboard separately from other inputs!
537   {
538      // here we should also have the tape output
539
540      if (BIT(data, 2))   // keyboard active
541      {
542         int lines = ((cfg & 0x000f) == 0x04) ? 9 : 12;
543         UINT8 out = BIT(data, 1);   // scan
544
545         if (state->m_fck_mode && !out && ++state->m_fck_scan > lines)
546            state->m_fck_scan = 0;
547
548         state->m_fck_mode = out;   // access lower or upper 4 bits
549
550         if (BIT(data, 0))   // reset
551            state->m_fck_scan = 0;
552      }
553   }
554   else
555   {
556      if (data & 0x01)
557         return;
558
559      if (LOG_JOY)
560         logerror("joy 0 bits read: %d\n", state->m_in_0.shift);
561
562      /* Toggling bit 0 high then low resets both controllers */
563      state->m_in_0.shift = 0;
564      state->m_in_1.shift = 0;
565
566      /* Read the input devices */
567      if ((cfg & 0x000f) != 0x06)
568      {
569         nes_read_input_device(space->machine(), cfg >>  0, &state->m_in_0, 0,  TRUE);
570         nes_read_input_device(space->machine(), cfg >>  4, &state->m_in_1, 1,  TRUE);
571         nes_read_input_device(space->machine(), cfg >>  8, &state->m_in_2, 2, FALSE);
572         nes_read_input_device(space->machine(), cfg >> 12, &state->m_in_3, 3, FALSE);
573      }
574      else // crazy climber pad
575      {
576         nes_read_input_device(space->machine(), 0, &state->m_in_1, 1,  TRUE);
577         nes_read_input_device(space->machine(), 0, &state->m_in_2, 2, FALSE);
578         nes_read_input_device(space->machine(), 0, &state->m_in_3, 3, FALSE);
579         nes_read_input_device(space->machine(), cfg >>  0, &state->m_in_0, 0,  TRUE);
580      }
581
582      if (cfg & 0x0f00)
583         state->m_in_0.i0 |= (state->m_in_2.i0 << 8) | (0x08 << 16);
584
585      if (cfg & 0xf000)
586         state->m_in_1.i0 |= (state->m_in_3.i0 << 8) | (0x04 << 16);
587   }
588}
589
590
591WRITE8_HANDLER( nes_IN1_w )
592{
593}
594
595struct nes_cart_lines
596{
597   const char *tag;
598   int line;
599};
600
601static const struct nes_cart_lines nes_cart_lines_table[] =
602{
603   { "PRG A0",    0 },
604   { "PRG A1",    1 },
605   { "PRG A2",    2 },
606   { "PRG A3",    3 },
607   { "PRG A4",    4 },
608   { "PRG A5",    5 },
609   { "PRG A6",    6 },
610   { "PRG A7",    7 },
611   { "CHR A10",  10 },
612   { "CHR A11",  11 },
613   { "CHR A12",  12 },
614   { "CHR A13",  13 },
615   { "CHR A14",  14 },
616   { "CHR A15",  15 },
617   { "CHR A16",  16 },
618   { "CHR A17",  17 },
619   { "NC",      127 },
620   { 0 }
621};
622
623static int nes_cart_get_line( const char *feature )
624{
625   const struct nes_cart_lines *nes_line = &nes_cart_lines_table[0];
626
627   if (feature == NULL)
628      return 128;
629
630   while (nes_line->tag)
631   {
632      if (strcmp(nes_line->tag, feature) == 0)
633         break;
634
635      nes_line++;
636   }
637
638   return nes_line->line;
639}
640
641DEVICE_IMAGE_LOAD( nes_cart )
642{
643   nes_state *state = image.device().machine().driver_data<nes_state>();
644   state->m_pcb_id = NO_BOARD;   // initialization
645
646   if (image.software_entry() == NULL)
647   {
648      const char *mapinfo = NULL;
649      int mapint1 = 0, mapint2 = 0, mapint3 = 0, mapint4 = 0, goodcrcinfo = 0;
650      char magic[4], extend[5];
651      int local_options = 0;
652      char m;
653
654      /* Check first 4 bytes of the image to decide if it is UNIF or iNES */
655      /* Unfortunately, many .unf files have been released as .nes, so we cannot rely on extensions only */
656      memset(magic, '\0', sizeof(magic));
657      image.fread(magic, 4);
658
659      if ((magic[0] == 'N') && (magic[1] == 'E') && (magic[2] == 'S'))   /* If header starts with 'NES' it is iNES */
660      {
661         UINT32 prg_size;
662         state->m_ines20 = 0;
663         state->m_battery_size = NES_BATTERY_SIZE; // with iNES we can only support 8K WRAM battery (iNES 2.0 might fix this)
664         state->m_prg_ram = 1;   // always map state->m_wram in bank5 (eventually, this should be enabled only for some mappers)
665
666         // check if the image is recognized by nes.hsi
667         mapinfo = hashfile_extrainfo(image);
668
669         // image_extrainfo() resets the file position back to start.
670         // Let's skip past the magic header once again.
671         image.fseek(4, SEEK_SET);
672
673         image.fread(&state->m_prg_chunks, 1);
674         image.fread(&state->m_chr_chunks, 1);
675         /* Read the first ROM option byte (offset 6) */
676         image.fread(&m, 1);
677
678         /* Interpret the iNES header flags */
679         state->m_mapper = (m & 0xf0) >> 4;
680         local_options = m & 0x0f;
681
682         /* Read the second ROM option byte (offset 7) */
683         image.fread(&m, 1);
684
685         switch (m & 0xc)
686         {
687            case 0x4:
688            case 0xc:
689               // probably the header got corrupted: don't trust upper bits for mapper
690               break;
691
692            case 0x8:   // it's iNES 2.0 format
693               state->m_ines20 = 1;
694            case 0x0:
695            default:
696               state->m_mapper = state->m_mapper | (m & 0xf0);
697               break;
698         }
699
700         if (mapinfo /* && !state->m_ines20 */)
701         {
702            if (4 == sscanf(mapinfo,"%d %d %d %d", &mapint1, &mapint2, &mapint3, &mapint4))
703            {
704               /* image is present in nes.hsi: overwrite the header settings with these */
705               state->m_mapper = mapint1;
706               local_options = mapint2 & 0x0f;
707               state->m_crc_hack = (mapint2 & 0xf0) >> 4;   // this is used to differentiate among variants of the same Mapper (see below)
708               state->m_prg_chunks = mapint3;
709               state->m_chr_chunks = mapint4;
710               logerror("NES.HSI info: %d %d %d %d\n", mapint1, mapint2, mapint3, mapint4);
711//                  mame_printf_error("NES.HSI info: %d %d %d %d\n", mapint1, mapint2, mapint3, mapint4);
712               goodcrcinfo = 1;
713               state->m_ines20 = 0;
714            }
715            else
716            {
717               logerror("NES: [%s], Invalid mapinfo found\n", mapinfo);
718            }
719         }
720         else
721         {
722            logerror("NES: No extrainfo found\n");
723         }
724
725         state->m_hard_mirroring = (local_options & 0x01) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ;
726//          mame_printf_error("%s\n", state->m_hard_mirroring & 0x01 ? "Vertical" : "Horizontal");
727         state->m_battery = local_options & 0x02;
728         state->m_trainer = local_options & 0x04;
729         state->m_four_screen_vram = local_options & 0x08;
730
731         if (state->m_battery)
732            logerror("-- Battery found\n");
733
734         if (state->m_trainer)
735            logerror("-- Trainer found\n");
736
737         if (state->m_four_screen_vram)
738            logerror("-- 4-screen VRAM\n");
739
740         if (state->m_ines20)
741         {
742            logerror("Extended iNES format:\n");
743            image.fread(&extend, 5);
744            state->m_mapper |= (extend[0] & 0x0f) << 8;
745            logerror("-- mapper: %d\n", state->m_mapper);
746            logerror("-- submapper: %d\n", (extend[0] & 0xf0) >> 4);
747            state->m_prg_chunks |= ((extend[1] & 0x0f) << 8);
748            state->m_chr_chunks |= ((extend[1] & 0xf0) << 4);
749            logerror("-- PRG chunks: %d\n", state->m_prg_chunks);
750            logerror("-- CHR chunks: %d\n", state->m_chr_chunks);
751            logerror("-- PRG NVWRAM: %d\n", extend[2] & 0x0f);
752            logerror("-- PRG WRAM: %d\n", (extend[2] & 0xf0) >> 4);
753            logerror("-- CHR NVWRAM: %d\n", extend[3] & 0x0f);
754            logerror("-- CHR WRAM: %d\n", (extend[3] & 0xf0) >> 4);
755            logerror("-- TV System: %d\n", extend[4] & 3);
756         }
757
758         /* Free the regions that were allocated by the ROM loader */
759         image.device().machine().region_free("maincpu");
760         image.device().machine().region_free("gfx1");
761
762         /* Allocate them again with the proper size */
763         prg_size = (state->m_prg_chunks == 1) ? 2 * 0x4000 : state->m_prg_chunks * 0x4000;
764         image.device().machine().region_alloc("maincpu", 0x10000 + prg_size, 1, ENDIANNESS_LITTLE);
765         if (state->m_chr_chunks)
766            image.device().machine().region_alloc("gfx1", state->m_chr_chunks * 0x2000, 1, ENDIANNESS_LITTLE);
767
768         state->m_rom = image.device().machine().region("maincpu")->base();
769         state->m_vrom = image.device().machine().region("gfx1")->base();
770
771         state->m_vram_chunks = image.device().machine().region("gfx2")->bytes() / 0x2000;
772         state->m_vram = image.device().machine().region("gfx2")->base();
773         // FIXME: this should only be allocated if there is actual wram in the cart (i.e. if state->m_prg_ram = 1)!
774         // or if there is a trainer, I think
775         state->m_wram_size = 0x10000;
776         state->m_wram = auto_alloc_array(image.device().machine(), UINT8, state->m_wram_size);
777
778         /* Setup PCB type (needed to add proper handlers later) */
779         state->m_pcb_id = nes_get_mmc_id(image.device().machine(), state->m_mapper);
780
781         // a few mappers correspond to multiple PCBs, so we need a few additional checks
782         switch (state->m_pcb_id)
783         {
784            case STD_CNROM:
785               if (state->m_mapper == 185)
786               {
787                  switch (state->m_crc_hack)
788                  {
789                     case 0x0: // pin26: CE, pin27: CE (B-Wings, Bird Week)
790                        state->m_ce_mask = 0x03;
791                        state->m_ce_state = 0x03;
792                        break;
793                     case 0x4: // pin26: CE, pin27: /CE (Mighty Bomb Jack, Spy Vs. Spy)
794                        state->m_ce_mask = 0x03;
795                        state->m_ce_state = 0x01;
796                        break;
797                     case 0x8: // pin26: /CE, pin27: CE (Sansu 1, 2, 3 Nen)
798                        state->m_ce_mask = 0x03;
799                        state->m_ce_state = 0x02;
800                        break;
801                     case 0xc: // pin26: /CE, pin27: /CE (Seicross v2.0)
802                        state->m_ce_mask = 0x03;
803                        state->m_ce_state = 0x00;
804                        break;
805                  }
806               }
807               break;
808            case KONAMI_VRC2:
809               if (state->m_mapper == 22)
810               {
811                  state->m_vrc_ls_prg_a = 0;
812                  state->m_vrc_ls_prg_b = 1;
813                  state->m_vrc_ls_chr = 1;
814               }
815               if (state->m_mapper == 23 && !state->m_crc_hack)
816               {
817                  state->m_vrc_ls_prg_a = 1;
818                  state->m_vrc_ls_prg_b = 0;
819                  state->m_vrc_ls_chr = 0;
820               }
821               if (state->m_mapper == 23 && state->m_crc_hack)
822               {
823                  // here there are also Akumajou Special, Crisis Force, Parodius da!, Tiny Toons which are VRC-4
824                  state->m_vrc_ls_prg_a = 3;
825                  state->m_vrc_ls_prg_b = 2;
826                  state->m_pcb_id = KONAMI_VRC4; // this allows for konami_irq to be installed at reset
827               }
828               break;
829            case KONAMI_VRC4:
830               if (state->m_mapper == 21)
831               {
832                  // Wai Wai World 2 & Ganbare Goemon Gaiden 2 (the latter with crc_hack)
833                  state->m_vrc_ls_prg_a = state->m_crc_hack ? 7 : 2;
834                  state->m_vrc_ls_prg_b = state->m_crc_hack ? 6 : 1;
835               }
836               if (state->m_mapper == 25)   // here there is also Ganbare Goemon Gaiden which is VRC-2
837               {
838                  state->m_vrc_ls_prg_a = state->m_crc_hack ? 2 : 0;
839                  state->m_vrc_ls_prg_b = state->m_crc_hack ? 3 : 1;
840               }
841               break;
842            case KONAMI_VRC6:
843               if (state->m_mapper == 24)
844               {
845                  state->m_vrc_ls_prg_a = 1;
846                  state->m_vrc_ls_prg_b = 0;
847               }
848               if (state->m_mapper == 26)
849               {
850                  state->m_vrc_ls_prg_a = 0;
851                  state->m_vrc_ls_prg_b = 1;
852               }
853               break;
854            case IREM_G101:
855               if (state->m_crc_hack)
856                  state->m_hard_mirroring = PPU_MIRROR_HIGH;   // Major League has hardwired mirroring
857               break;
858            case DIS_74X161X161X32:
859               if (state->m_mapper == 70)
860                  state->m_hard_mirroring = PPU_MIRROR_VERT;   // only hardwired mirroring makes different mappers 70 & 152
861               break;
862            case SUNSOFT_2:
863               if (state->m_mapper == 93)
864                  state->m_hard_mirroring = PPU_MIRROR_VERT;   // only hardwired mirroring makes different mappers 89 & 93
865               break;
866            case STD_BXROM:
867               if (state->m_crc_hack)
868                  state->m_pcb_id = AVE_NINA01;   // Mapper 34 is used for 2 diff boards
869               break;
870            case BANDAI_LZ93:
871               if (state->m_crc_hack)
872                  state->m_pcb_id = BANDAI_JUMP2;   // Mapper 153 is used for 2 diff boards
873               break;
874            case IREM_HOLYDIV:
875               if (state->m_crc_hack)
876                  state->m_pcb_id = JALECO_JF16;   // Mapper 78 is used for 2 diff boards
877               break;
878            case CAMERICA_BF9093:
879               if (state->m_crc_hack)
880                  state->m_pcb_id = CAMERICA_BF9097;   // Mapper 71 is used for 2 diff boards
881               break;
882            case HES_BOARD:
883               if (state->m_crc_hack)
884                  state->m_pcb_id = HES6IN1_BOARD;   // Mapper 113 is used for 2 diff boards
885               break;
886            case WAIXING_ZS:
887               if (state->m_crc_hack)
888                  state->m_pcb_id = WAIXING_DQ8;   // Mapper 242 is used for 2 diff boards
889               break;
890            //FIXME: we also have to fix Action 52 PRG loading somewhere...
891         }
892
893         /* Allocate internal Mapper RAM for boards which require it */
894         if (state->m_pcb_id == STD_EXROM)
895            state->m_mapper_ram = auto_alloc_array(image.device().machine(), UINT8, 0x400);
896
897         if (state->m_pcb_id == TAITO_X1_005 || state->m_pcb_id == TAITO_X1_005_A)
898            state->m_mapper_bram = auto_alloc_array(image.device().machine(), UINT8, 0x80);
899
900         if (state->m_pcb_id == TAITO_X1_017)
901            state->m_mapper_bram = auto_alloc_array(image.device().machine(), UINT8, 0x1400);
902
903         if (state->m_pcb_id == NAMCOT_163)
904            state->m_mapper_ram = auto_alloc_array(image.device().machine(), UINT8, 0x2000);
905
906         if (state->m_pcb_id == FUKUTAKE_BOARD)
907            state->m_mapper_ram = auto_alloc_array(image.device().machine(), UINT8, 2816);
908
909         /* Position past the header */
910         image.fseek(16, SEEK_SET);
911
912         /* Load the 0x200 byte trainer at 0x7000 if it exists */
913         if (state->m_trainer)
914            image.fread(&state->m_wram[0x1000], 0x200);
915
916         /* Read in the program chunks */
917         image.fread(&state->m_rom[0x10000], 0x4000 * state->m_prg_chunks);
918         if (state->m_prg_chunks == 1)
919            memcpy(&state->m_rom[0x14000], &state->m_rom[0x10000], 0x4000);
920
921#if SPLIT_PRG
922         {
923            FILE *prgout;
924            char outname[255];
925
926            sprintf(outname, "%s.prg", image.filename());
927            prgout = fopen(outname, "wb");
928            if (prgout)
929            {
930               fwrite(&state->m_rom[0x10000], 1, 0x4000 * state->m_prg_chunks, prgout);
931               mame_printf_error("Created PRG chunk\n");
932            }
933
934            fclose(prgout);
935         }
936#endif
937
938         logerror("**\n");
939         logerror("Mapper: %d\n", state->m_mapper);
940         logerror("PRG chunks: %02x, size: %06x\n", state->m_prg_chunks, 0x4000 * state->m_prg_chunks);
941         // mame_printf_error("Mapper: %d\n", state->m_mapper);
942         // mame_printf_error("PRG chunks: %02x, size: %06x\n", state->m_prg_chunks, 0x4000 * state->m_prg_chunks);
943
944         /* Read in any chr chunks */
945         if (state->m_chr_chunks > 0)
946         {
947            image.fread(state->m_vrom, state->m_chr_chunks * 0x2000);
948            if (state->m_mapper == 2)
949               logerror("Warning: VROM has been found in VRAM-based mapper. Either the mapper is set wrong or the ROM image is incorrect.\n");
950         }
951
952#if SPLIT_CHR
953         if (state->m_chr_chunks > 0)
954         {
955            FILE *chrout;
956            char outname[255];
957
958            sprintf(outname, "%s.chr", image.filename());
959            chrout= fopen(outname, "wb");
960            if (chrout)
961            {
962               fwrite(state->m_vrom, 1, 0x2000 * state->m_chr_chunks, chrout);
963               mame_printf_error("Created CHR chunk\n");
964            }
965            fclose(chrout);
966         }
967#endif
968
969         logerror("CHR chunks: %02x, size: %06x\n", state->m_chr_chunks, 0x2000 * state->m_chr_chunks);
970         logerror("**\n");
971         // mame_printf_error("CHR chunks: %02x, size: %06x\n", state->m_chr_chunks, 0x2000 * state->m_chr_chunks);
972         // mame_printf_error("**\n");
973      }
974      else if ((magic[0] == 'U') && (magic[1] == 'N') && (magic[2] == 'I') && (magic[3] == 'F')) /* If header starts with 'UNIF' it is UNIF */
975      {
976         UINT32 unif_ver = 0;
977         char magic2[4];
978         UINT8 buffer[4];
979         UINT32 chunk_length = 0, read_length = 0x20;
980         UINT32 prg_start = 0, chr_start = 0, prg_size;
981         char unif_mapr[32];   // here we should store MAPR chunks
982         UINT32 size = image.length();
983         int mapr_chunk_found = 0;
984         // allocate space to temporarily store PRG & CHR banks
985         UINT8 *temp_prg = auto_alloc_array(image.device().machine(), UINT8, 256 * 0x4000);
986         UINT8 *temp_chr = auto_alloc_array(image.device().machine(), UINT8, 256 * 0x2000);
987         UINT8 temp_byte = 0;
988
989         /* init prg/chr chunks to 0: the exact number of chunks will be determined while reading the file */
990         state->m_prg_chunks = 0;
991         state->m_chr_chunks = 0;
992
993         image.fread(&buffer, 4);
994         unif_ver = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
995         logerror("UNIF file found, version %d\n", unif_ver);
996
997         if (size <= 0x20)
998         {
999            logerror("%s only contains the UNIF header and no data.\n", image.filename());
1000            return IMAGE_INIT_FAIL;
1001         }
1002
1003         do
1004         {
1005            image.fseek(read_length, SEEK_SET);
1006
1007            memset(magic2, '\0', sizeof(magic2));
1008            image.fread(&magic2, 4);
1009
1010            /* We first run through the whole image to find a [MAPR] chunk. This is needed
1011                 because, unfortunately, the MAPR chunk is not always the first chunk (see
1012                 Super 24-in-1). When such a chunk is found, we set mapr_chunk_found=1 and
1013                 we go back to load other chunks! */
1014            if (!mapr_chunk_found)
1015            {
1016               if ((magic2[0] == 'M') && (magic2[1] == 'A') && (magic2[2] == 'P') && (magic2[3] == 'R'))
1017               {
1018                  mapr_chunk_found = 1;
1019                  logerror("[MAPR] chunk found: ");
1020                  image.fread(&buffer, 4);
1021                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1022
1023                  if (chunk_length <= 0x20)
1024                     image.fread(&unif_mapr, chunk_length);
1025
1026                  // find out prg/chr size, battery, wram, etc.
1027                  unif_mapr_setup(image.device().machine(), unif_mapr);
1028
1029                  /* now that we found the MAPR chunk, we can go back to load other chunks */
1030                  image.fseek(0x20, SEEK_SET);
1031                  read_length = 0x20;
1032               }
1033               else
1034               {
1035                  logerror("Skip this chunk. We need a [MAPR] chunk before anything else.\n");
1036                  image.fread(&buffer, 4);
1037                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1038
1039                  read_length += (chunk_length + 8);
1040               }
1041            }
1042            else
1043            {
1044               /* What kind of chunk do we have here? */
1045               if ((magic2[0] == 'M') && (magic2[1] == 'A') && (magic2[2] == 'P') && (magic2[3] == 'R'))
1046               {
1047                  /* The [MAPR] chunk has already been read, so we skip it */
1048                  /* TO DO: it would be nice to check if more than one MAPR chunk is present */
1049                  logerror("[MAPR] chunk found (in the 2nd run). Already loaded.\n");
1050                  image.fread(&buffer, 4);
1051                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1052
1053                  read_length += (chunk_length + 8);
1054               }
1055               else if ((magic2[0] == 'R') && (magic2[1] == 'E') && (magic2[2] == 'A') && (magic2[3] == 'D'))
1056               {
1057                  logerror("[READ] chunk found. No support yet.\n");
1058                  image.fread(&buffer, 4);
1059                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1060
1061                  read_length += (chunk_length + 8);
1062               }
1063               else if ((magic2[0] == 'N') && (magic2[1] == 'A') && (magic2[2] == 'M') && (magic2[3] == 'E'))
1064               {
1065                  logerror("[NAME] chunk found. No support yet.\n");
1066                  image.fread(&buffer, 4);
1067                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1068
1069                  read_length += (chunk_length + 8);
1070               }
1071               else if ((magic2[0] == 'W') && (magic2[1] == 'R') && (magic2[2] == 'T') && (magic2[3] == 'R'))
1072               {
1073                  logerror("[WRTR] chunk found. No support yet.\n");
1074                  image.fread(&buffer, 4);
1075                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1076
1077                  read_length += (chunk_length + 8);
1078               }
1079               else if ((magic2[0] == 'T') && (magic2[1] == 'V') && (magic2[2] == 'C') && (magic2[3] == 'I'))
1080               {
1081                  logerror("[TVCI] chunk found.\n");
1082                  image.fread(&buffer, 4);
1083                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1084
1085                  image.fread(&temp_byte, 1);
1086                  logerror("Television Standard : %s\n", (temp_byte == 0) ? "NTSC" : (temp_byte == 1) ? "PAL" : "Does not matter");
1087
1088                  read_length += (chunk_length + 8);
1089               }
1090               else if ((magic2[0] == 'T') && (magic2[1] == 'V') && (magic2[2] == 'S') && (magic2[3] == 'C')) // is this the same as TVCI??
1091               {
1092                  logerror("[TVSC] chunk found. No support yet.\n");
1093                  image.fread(&buffer, 4);
1094                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1095
1096                  read_length += (chunk_length + 8);
1097               }
1098               else if ((magic2[0] == 'D') && (magic2[1] == 'I') && (magic2[2] == 'N') && (magic2[3] == 'F'))
1099               {
1100                  logerror("[DINF] chunk found. No support yet.\n");
1101                  image.fread(&buffer, 4);
1102                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1103
1104                  read_length += (chunk_length + 8);
1105               }
1106               else if ((magic2[0] == 'C') && (magic2[1] == 'T') && (magic2[2] == 'R') && (magic2[3] == 'L'))
1107               {
1108                  logerror("[CTRL] chunk found. No support yet.\n");
1109                  image.fread(&buffer, 4);
1110                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1111
1112                  read_length += (chunk_length + 8);
1113               }
1114               else if ((magic2[0] == 'B') && (magic2[1] == 'A') && (magic2[2] == 'T') && (magic2[3] == 'R'))
1115               {
1116                  logerror("[BATR] chunk found. No support yet.\n");
1117                  image.fread(&buffer, 4);
1118                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1119
1120                  read_length += (chunk_length + 8);
1121               }
1122               else if ((magic2[0] == 'V') && (magic2[1] == 'R') && (magic2[2] == 'O') && (magic2[3] == 'R'))
1123               {
1124                  logerror("[VROR] chunk found. No support yet.\n");
1125                  image.fread(&buffer, 4);
1126                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1127
1128                  read_length += (chunk_length + 8);
1129               }
1130               else if ((magic2[0] == 'M') && (magic2[1] == 'I') && (magic2[2] == 'R') && (magic2[3] == 'R'))
1131               {
1132                  logerror("[MIRR] chunk found.\n");
1133                  image.fread(&buffer, 4);
1134                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1135
1136                  image.fread(&temp_byte, 1);
1137                  switch (temp_byte)
1138                  {
1139                     case 0:   // Horizontal Mirroring (Hard Wired)
1140                        state->m_hard_mirroring = PPU_MIRROR_HORZ;
1141                        break;
1142                     case 1:   // Vertical Mirroring (Hard Wired)
1143                        state->m_hard_mirroring = PPU_MIRROR_VERT;
1144                        break;
1145                     case 2:   // Mirror All Pages From $2000 (Hard Wired)
1146                        state->m_hard_mirroring = PPU_MIRROR_LOW;
1147                        break;
1148                     case 3:   // Mirror All Pages From $2400 (Hard Wired)
1149                        state->m_hard_mirroring = PPU_MIRROR_HIGH;
1150                        break;
1151                     case 4:   // Four Screens of VRAM (Hard Wired)
1152                        state->m_four_screen_vram = 1;
1153                        break;
1154                     case 5:   // Mirroring Controlled By Mapper Hardware
1155                        logerror("Mirroring handled by the board hardware.\n");
1156                        // default to horizontal at start
1157                        state->m_hard_mirroring = PPU_MIRROR_HORZ;
1158                        break;
1159                     default:
1160                        logerror("Undocumented mirroring value.\n");
1161                        // default to horizontal
1162                        state->m_hard_mirroring = PPU_MIRROR_HORZ;
1163                        break;
1164                  }
1165
1166                  read_length += (chunk_length + 8);
1167               }
1168               else if ((magic2[0] == 'P') && (magic2[1] == 'C') && (magic2[2] == 'K'))
1169               {
1170                  logerror("[PCK%c] chunk found. No support yet.\n", magic2[3]);
1171                  image.fread(&buffer, 4);
1172                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1173
1174                  read_length += (chunk_length + 8);
1175               }
1176               else if ((magic2[0] == 'C') && (magic2[1] == 'C') && (magic2[2] == 'K'))
1177               {
1178                  logerror("[CCK%c] chunk found. No support yet.\n", magic2[3]);
1179                  image.fread(&buffer, 4);
1180                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1181
1182                  read_length += (chunk_length + 8);
1183               }
1184               else if ((magic2[0] == 'P') && (magic2[1] == 'R') && (magic2[2] == 'G'))
1185               {
1186                  logerror("[PRG%c] chunk found. ", magic2[3]);
1187                  image.fread(&buffer, 4);
1188                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1189
1190                  // FIXME: we currently don't support PRG chunks smaller than 16K!
1191                  state->m_prg_chunks += (chunk_length / 0x4000);
1192
1193                  if (chunk_length / 0x4000)
1194                     logerror("It consists of %d 16K-blocks.\n", chunk_length / 0x4000);
1195                  else
1196                     logerror("This chunk is smaller than 16K: the emulation might have issues. Please report this file to the MESS forums.\n");
1197
1198                  /* Read in the program chunks */
1199                  image.fread(&temp_prg[prg_start], chunk_length);
1200
1201                  prg_start += chunk_length;
1202                  read_length += (chunk_length + 8);
1203               }
1204               else if ((magic2[0] == 'C') && (magic2[1] == 'H') && (magic2[2] == 'R'))
1205               {
1206                  logerror("[CHR%c] chunk found. ", magic2[3]);
1207                  image.fread(&buffer, 4);
1208                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1209
1210                  state->m_chr_chunks += (chunk_length / 0x2000);
1211
1212                  logerror("It consists of %d 8K-blocks.\n", chunk_length / 0x2000);
1213
1214                  /* Read in the vrom chunks */
1215                  image.fread(&temp_chr[chr_start], chunk_length);
1216
1217                  chr_start += chunk_length;
1218                  read_length += (chunk_length + 8);
1219               }
1220               else
1221               {
1222                  logerror("Unsupported UNIF chunk or corrupted header. Please report the problem at MESS Board.\n");
1223                  read_length = size;
1224               }
1225            }
1226         } while (size > read_length);
1227
1228         if (!mapr_chunk_found)
1229         {
1230            auto_free(image.device().machine(), temp_prg);
1231            auto_free(image.device().machine(), temp_chr);
1232            fatalerror("UNIF should have a [MAPR] chunk to work. Check if your image has been corrupted");
1233         }
1234
1235         if (!prg_start)
1236         {
1237            auto_free(image.device().machine(), temp_prg);
1238            auto_free(image.device().machine(), temp_chr);
1239            fatalerror("Unsupported UNIF chunk or corrupted header. Please report the problem at MESS Board.\n");
1240         }
1241
1242         /* Free the regions that were allocated by the ROM loader */
1243         image.device().machine().region_free("maincpu");
1244         image.device().machine().region_free("gfx1");
1245         image.device().machine().region_free("gfx2");
1246
1247         /* Allocate them again, and copy PRG/CHR from temp buffers */
1248         /* Take care of PRG */
1249         prg_size = (state->m_prg_chunks == 1) ? 2 * 0x4000 : state->m_prg_chunks * 0x4000;
1250         image.device().machine().region_alloc("maincpu", 0x10000 + prg_size, 1, ENDIANNESS_LITTLE);
1251         state->m_rom = image.device().machine().region("maincpu")->base();
1252         memcpy(&state->m_rom[0x10000], &temp_prg[0x00000], state->m_prg_chunks * 0x4000);
1253         /* If only a single 16K PRG chunk is present, mirror it! */
1254         if (state->m_prg_chunks == 1)
1255            memcpy(&state->m_rom[0x14000], &state->m_rom[0x10000], 0x4000);
1256
1257         /* Take care of CHR ROM */
1258         if (state->m_chr_chunks)
1259         {
1260            image.device().machine().region_alloc("gfx1", state->m_chr_chunks * 0x2000, 1, ENDIANNESS_LITTLE);
1261            state->m_vrom = image.device().machine().region("gfx1")->base();
1262            memcpy(&state->m_vrom[0x00000], &temp_chr[0x00000], state->m_chr_chunks * 0x2000);
1263         }
1264
1265         /* Take care of CHR RAM */
1266         if (state->m_vram_chunks)
1267         {
1268            image.device().machine().region_alloc("gfx2", state->m_vram_chunks * 0x2000, 1, ENDIANNESS_LITTLE);
1269            state->m_vram = image.device().machine().region("gfx2")->base();
1270         }
1271
1272         // FIXME: this should only be allocated if there is actual wram in the cart (i.e. if state->m_prg_ram = 1)!
1273         state->m_wram_size = 0x10000;
1274         state->m_wram = auto_alloc_array(image.device().machine(), UINT8, state->m_wram_size);
1275
1276#if SPLIT_PRG
1277         {
1278            FILE *prgout;
1279            char outname[255];
1280
1281            sprintf(outname, "%s.prg", image.filename());
1282            prgout = fopen(outname, "wb");
1283            if (prgout)
1284            {
1285               fwrite(&state->m_rom[0x10000], 1, 0x4000 * state->m_prg_chunks, prgout);
1286               mame_printf_error("Created PRG chunk\n");
1287            }
1288
1289            fclose(prgout);
1290         }
1291#endif
1292
1293#if SPLIT_CHR
1294         if (state->m_chr_chunks > 0)
1295         {
1296            FILE *chrout;
1297            char outname[255];
1298
1299            sprintf(outname, "%s.chr", image.filename());
1300            chrout= fopen(outname, "wb");
1301            if (chrout)
1302            {
1303               fwrite(state->m_vrom, 1, 0x2000 * state->m_chr_chunks, chrout);
1304               mame_printf_error("Created CHR chunk\n");
1305            }
1306            fclose(chrout);
1307         }
1308#endif
1309         // free the temporary copy of PRG/CHR
1310         auto_free(image.device().machine(), temp_prg);
1311         auto_free(image.device().machine(), temp_chr);
1312         logerror("UNIF support is only very preliminary.\n");
1313      }
1314      else
1315      {
1316         logerror("%s is NOT a file in either iNES or UNIF format.\n", image.filename());
1317         return IMAGE_INIT_FAIL;
1318      }
1319   }
1320   else
1321   {
1322      UINT32 prg_size = image.get_software_region_length("prg");
1323      UINT32 chr_size = image.get_software_region_length("chr");
1324      UINT32 vram_size = image.get_software_region_length("vram");
1325      vram_size += image.get_software_region_length("vram2");
1326
1327      /* Free the regions that were allocated by the ROM loader */
1328      image.device().machine().region_free("maincpu");
1329      image.device().machine().region_free("gfx1");
1330      image.device().machine().region_free("gfx2");
1331
1332      /* Allocate them again with the proper size */
1333      image.device().machine().region_alloc("maincpu", 0x10000 + prg_size, 1, ENDIANNESS_LITTLE);
1334
1335      // validate the xml fields
1336      if (!prg_size)
1337         fatalerror("No PRG entry for this software! Please check if the xml list got corrupted");
1338      if (prg_size < 0x8000)
1339         fatalerror("PRG entry is too small! Please check if the xml list got corrupted");
1340
1341      if (chr_size)
1342         image.device().machine().region_alloc("gfx1", chr_size, 1, ENDIANNESS_LITTLE);
1343
1344      if (vram_size)
1345         image.device().machine().region_alloc("gfx2", vram_size, 1, ENDIANNESS_LITTLE);
1346
1347      state->m_rom = image.device().machine().region("maincpu")->base();
1348      state->m_vrom = image.device().machine().region("gfx1")->base();
1349      state->m_vram = image.device().machine().region("gfx2")->base();
1350
1351      memcpy(state->m_rom + 0x10000, image.get_software_region("prg"), prg_size);
1352
1353      if (chr_size)
1354         memcpy(state->m_vrom, image.get_software_region("chr"), chr_size);
1355
1356      state->m_prg_chunks = prg_size / 0x4000;
1357      state->m_chr_chunks = chr_size / 0x2000;
1358      state->m_vram_chunks = vram_size / 0x2000;
1359
1360      state->m_pcb_id = nes_get_pcb_id(image.device().machine(), image.get_feature("pcb"));
1361
1362      if (state->m_pcb_id == STD_TVROM || state->m_pcb_id == STD_DRROM || state->m_pcb_id == IREM_LROG017)
1363         state->m_four_screen_vram = 1;
1364      else
1365         state->m_four_screen_vram = 0;
1366
1367      state->m_battery = (image.get_software_region("bwram") != NULL) ? 1 : 0;
1368      state->m_battery_size = image.get_software_region_length("bwram");
1369
1370      if (state->m_pcb_id == BANDAI_LZ93EX)
1371      {
1372         // allocate the 24C01 or 24C02 EEPROM
1373         state->m_battery = 1;
1374         state->m_battery_size += 0x2000;
1375      }
1376
1377      if (state->m_pcb_id == BANDAI_DATACH)
1378      {
1379         // allocate the 24C01 and 24C02 EEPROM
1380         state->m_battery = 1;
1381         state->m_battery_size += 0x4000;
1382      }
1383
1384      state->m_prg_ram = (image.get_software_region("wram") != NULL) ? 1 : 0;
1385      state->m_wram_size = image.get_software_region_length("wram");
1386      state->m_mapper_ram_size = image.get_software_region_length("mapper_ram");
1387      state->m_mapper_bram_size = image.get_software_region_length("mapper_bram");
1388
1389      if (state->m_prg_ram)
1390         state->m_wram = auto_alloc_array(image.device().machine(), UINT8, state->m_wram_size);
1391      if (state->m_mapper_ram_size)
1392         state->m_mapper_ram = auto_alloc_array(image.device().machine(), UINT8, state->m_mapper_ram_size);
1393      if (state->m_mapper_bram_size)
1394         state->m_mapper_bram = auto_alloc_array(image.device().machine(), UINT8, state->m_mapper_bram_size);
1395
1396      /* Check for mirroring */
1397      if (image.get_feature("mirroring") != NULL)
1398      {
1399         const char *mirroring = image.get_feature("mirroring");
1400         if (!strcmp(mirroring, "horizontal"))
1401            state->m_hard_mirroring = PPU_MIRROR_HORZ;
1402         if (!strcmp(mirroring, "vertical"))
1403            state->m_hard_mirroring = PPU_MIRROR_VERT;
1404         if (!strcmp(mirroring, "high"))
1405            state->m_hard_mirroring = PPU_MIRROR_HIGH;
1406         if (!strcmp(mirroring, "low"))
1407            state->m_hard_mirroring = PPU_MIRROR_LOW;
1408      }
1409
1410      state->m_chr_open_bus = 0;
1411      state->m_ce_mask = 0;
1412      state->m_ce_state = 0;
1413      state->m_vrc_ls_prg_a = 0;
1414      state->m_vrc_ls_prg_b = 0;
1415      state->m_vrc_ls_chr = 0;
1416
1417      /* Check for pins in specific boards which require them */
1418      if (state->m_pcb_id == STD_CNROM)
1419      {
1420         if (image.get_feature("chr-pin26") != NULL)
1421         {
1422            state->m_ce_mask |= 0x01;
1423            state->m_ce_state |= !strcmp(image.get_feature("chr-pin26"), "CE") ? 0x01 : 0;
1424         }
1425         if (image.get_feature("chr-pin27") != NULL)
1426         {
1427            state->m_ce_mask |= 0x02;
1428            state->m_ce_state |= !strcmp(image.get_feature("chr-pin27"), "CE") ? 0x02 : 0;
1429         }
1430      }
1431
1432      if (state->m_pcb_id == TAITO_X1_005 && image.get_feature("x1-pin17") != NULL && image.get_feature("x1-pin31") != NULL)
1433      {
1434         if (!strcmp(image.get_feature("x1-pin17"), "CIRAM A10") && !strcmp(image.get_feature("x1-pin31"), "NC"))
1435            state->m_pcb_id = TAITO_X1_005_A;
1436      }
1437
1438      if (state->m_pcb_id == KONAMI_VRC2)
1439      {
1440         state->m_vrc_ls_prg_a = nes_cart_get_line(image.get_feature("vrc2-pin3"));
1441         state->m_vrc_ls_prg_b = nes_cart_get_line(image.get_feature("vrc2-pin4"));
1442         state->m_vrc_ls_chr = (nes_cart_get_line(image.get_feature("vrc2-pin21")) != 10) ? 1 : 0;
1443//          mame_printf_error("VRC-2, pin3: A%d, pin4: A%d, pin21: %s\n", state->m_vrc_ls_prg_a, state->m_vrc_ls_prg_b, state->m_vrc_ls_chr ? "NC" : "A10");
1444      }
1445
1446      if (state->m_pcb_id == KONAMI_VRC4)
1447      {
1448         state->m_vrc_ls_prg_a = nes_cart_get_line(image.get_feature("vrc4-pin3"));
1449         state->m_vrc_ls_prg_b = nes_cart_get_line(image.get_feature("vrc4-pin4"));
1450//          mame_printf_error("VRC-4, pin3: A%d, pin4: A%d\n", state->m_vrc_ls_prg_a, state->m_vrc_ls_prg_b);
1451      }
1452
1453      if (state->m_pcb_id == KONAMI_VRC6)
1454      {
1455         state->m_vrc_ls_prg_a = nes_cart_get_line(image.get_feature("vrc6-pin9"));
1456         state->m_vrc_ls_prg_b = nes_cart_get_line(image.get_feature("vrc6-pin10"));
1457//          mame_printf_error("VRC-6, pin9: A%d, pin10: A%d\n", state->m_vrc_ls_prg_a, state->m_vrc_ls_prg_b);
1458      }
1459
1460      /* Check for other misc board variants */
1461      if (state->m_pcb_id == STD_SOROM)
1462      {
1463         if (image.get_feature("mmc1_type") != NULL && !strcmp(image.get_feature("mmc1_type"), "MMC1A"))
1464            state->m_pcb_id = STD_SOROM_A;   // in MMC1-A PRG RAM is always enabled
1465      }
1466
1467      if (state->m_pcb_id == STD_SXROM)
1468      {
1469         if (image.get_feature("mmc1_type") != NULL && !strcmp(image.get_feature("mmc1_type"), "MMC1A"))
1470            state->m_pcb_id = STD_SXROM_A;   // in MMC1-A PRG RAM is always enabled
1471      }
1472
1473      if (state->m_pcb_id == STD_NXROM || state->m_pcb_id == SUNSOFT_DCS)
1474      {
1475         if (image.get_software_region("minicart") != NULL)   // check for dual minicart
1476         {
1477            state->m_pcb_id = SUNSOFT_DCS;
1478            // we shall load somewhere the minicart, but we still do not support this
1479         }
1480      }
1481
1482#if 0
1483      if (state->m_pcb_id == UNSUPPORTED_BOARD)
1484         mame_printf_error("This board (%s) is currently not supported by MESS\n", image.get_feature("pcb"));
1485      mame_printf_error("PCB Feature: %s\n", image.get_feature("pcb"));
1486      mame_printf_error("PRG chunks: %d\n", state->m_prg_chunks);
1487      mame_printf_error("CHR chunks: %d\n", state->m_chr_chunks);
1488      mame_printf_error("VRAM: Present %s, size: %d\n", state->m_vram_chunks ? "Yes" : "No", vram_size);
1489      mame_printf_error("NVWRAM: Present %s, size: %d\n", state->m_battery ? "Yes" : "No", state->m_battery_size);
1490      mame_printf_error("WRAM:   Present %s, size: %d\n", state->m_prg_ram ? "Yes" : "No", state->m_wram_size);
1491#endif
1492   }
1493
1494   // Attempt to load a battery file for this ROM
1495   // A few boards have internal RAM with a battery (MMC6, Taito X1-005 & X1-017, etc.)
1496   if (state->m_battery || state->m_mapper_bram_size)
1497   {
1498      UINT8 *temp_nvram = auto_alloc_array(image.device().machine(), UINT8, state->m_battery_size + state->m_mapper_bram_size);
1499      image.battery_load(temp_nvram, state->m_battery_size + state->m_mapper_bram_size, 0x00);
1500      if (state->m_battery)
1501      {
1502         state->m_battery_ram = auto_alloc_array(image.device().machine(), UINT8, state->m_battery_size);
1503         memcpy(state->m_battery_ram, temp_nvram, state->m_battery_size);
1504      }
1505      if (state->m_mapper_bram_size)
1506         memcpy(state->m_mapper_bram, temp_nvram + state->m_battery_size, state->m_mapper_bram_size);
1507
1508      auto_free(image.device().machine(), temp_nvram);
1509   }
1510
1511   return IMAGE_INIT_PASS;
1512}
1513
1514
1515
1516void nes_partialhash(hash_collection &dest, const unsigned char *data,
1517   unsigned long length, const char *functions)
1518{
1519   if (length <= 16)
1520      return;
1521   dest.compute(&data[16], length - 16, functions);
1522}
1523
1524/**************************
1525
1526 Disk System emulation
1527
1528**************************/
1529
1530static void fds_irq( device_t *device, int scanline, int vblank, int blanked )
1531{
1532   nes_state *state = device->machine().driver_data<nes_state>();
1533
1534   if (state->m_IRQ_enable_latch)
1535      device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
1536
1537   if (state->m_IRQ_enable)
1538   {
1539      if (state->m_IRQ_count <= 114)
1540      {
1541         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
1542         state->m_IRQ_enable = 0;
1543         state->m_fds_status0 |= 0x01;
1544      }
1545      else
1546         state->m_IRQ_count -= 114;
1547   }
1548}
1549
1550static READ8_HANDLER( nes_fds_r )
1551{
1552   nes_state *state = space->machine().driver_data<nes_state>();
1553   UINT8 ret = 0x00;
1554
1555   switch (offset)
1556   {
1557      case 0x00: /* $4030 - disk status 0 */
1558         ret = state->m_fds_status0;
1559         /* clear the disk IRQ detect flag */
1560         state->m_fds_status0 &= ~0x01;
1561         break;
1562      case 0x01: /* $4031 - data latch */
1563         /* don't read data if disk is unloaded */
1564         if (state->m_fds_data == NULL)
1565            ret = 0;
1566         else if (state->m_fds_current_side)
1567            ret = state->m_fds_data[(state->m_fds_current_side - 1) * 65500 + state->m_fds_head_position++];
1568         else
1569            ret = 0;
1570         break;
1571      case 0x02: /* $4032 - disk status 1 */
1572         /* return "no disk" status if disk is unloaded */
1573         if (state->m_fds_data == NULL)
1574            ret = 1;
1575         else if (state->m_fds_last_side != state->m_fds_current_side)
1576         {
1577            /* If we've switched disks, report "no disk" for a few reads */
1578            ret = 1;
1579            state->m_fds_count++;
1580            if (state->m_fds_count == 50)
1581            {
1582               state->m_fds_last_side = state->m_fds_current_side;
1583               state->m_fds_count = 0;
1584            }
1585         }
1586         else
1587            ret = (state->m_fds_current_side == 0); /* 0 if a disk is inserted */
1588         break;
1589      case 0x03: /* $4033 */
1590         ret = 0x80;
1591         break;
1592      default:
1593         ret = 0x00;
1594         break;
1595   }
1596
1597   return ret;
1598}
1599
1600static WRITE8_HANDLER( nes_fds_w )
1601{
1602   nes_state *state = space->machine().driver_data<nes_state>();
1603
1604   switch (offset)
1605   {
1606      case 0x00:
1607         state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0xff00) | data;
1608         break;
1609      case 0x01:
1610         state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0x00ff) | (data << 8);
1611         break;
1612      case 0x02:
1613         state->m_IRQ_count = state->m_IRQ_count_latch;
1614         state->m_IRQ_enable = data;
1615         break;
1616      case 0x03:
1617         // d0 = sound io (1 = enable)
1618         // d1 = disk io (1 = enable)
1619         break;
1620      case 0x04:
1621         /* write data out to disk */
1622         break;
1623      case 0x05:
1624         state->m_fds_motor_on = BIT(data, 0);
1625
1626         if (BIT(data, 1))
1627            state->m_fds_head_position = 0;
1628
1629         state->m_fds_read_mode = BIT(data, 2);
1630         set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1631
1632         if ((!(data & 0x40)) && (state->m_fds_write_reg & 0x40))
1633            state->m_fds_head_position -= 2; // ???
1634
1635         state->m_IRQ_enable_latch = BIT(data, 7);
1636         state->m_fds_write_reg = data;
1637         break;
1638   }
1639}
1640
1641static void nes_load_proc( device_image_interface &image )
1642{
1643   nes_state *state = image.device().machine().driver_data<nes_state>();
1644   int header = 0;
1645   state->m_fds_sides = 0;
1646
1647   if (image.length() % 65500)
1648      header = 0x10;
1649
1650   state->m_fds_sides = (image.length() - header) / 65500;
1651
1652   if (state->m_fds_data == NULL)
1653      state->m_fds_data = (UINT8*)image.image_malloc(state->m_fds_sides * 65500);   // I don't think we can arrive here ever, probably it can be removed...
1654
1655   /* if there is an header, skip it */
1656   image.fseek(header, SEEK_SET);
1657
1658   image.fread(state->m_fds_data, 65500 * state->m_fds_sides);
1659   return;
1660}
1661
1662static void nes_unload_proc( device_image_interface &image )
1663{
1664   nes_state *state = image.device().machine().driver_data<nes_state>();
1665
1666   /* TODO: should write out changes here as well */
1667   state->m_fds_sides =  0;
1668}
1669
1670DRIVER_INIT( famicom )
1671{
1672   nes_state *state = machine.driver_data<nes_state>();
1673   int i;
1674
1675   /* clear some of the variables we don't use */
1676   state->m_trainer = 0;
1677   state->m_battery = 0;
1678   state->m_prg_ram = 0;
1679   state->m_four_screen_vram = 0;
1680   state->m_hard_mirroring = 0;
1681   state->m_prg_chunks = state->m_chr_chunks = 0;
1682
1683   /* initialize the disk system */
1684   state->m_disk_expansion = 1;
1685   state->m_pcb_id = NO_BOARD;
1686
1687   state->m_fds_sides = 0;
1688   state->m_fds_last_side = 0;
1689   state->m_fds_count = 0;
1690   state->m_fds_motor_on = 0;
1691   state->m_fds_door_closed = 0;
1692   state->m_fds_current_side = 1;
1693   state->m_fds_head_position = 0;
1694   state->m_fds_status0 = 0;
1695   state->m_fds_read_mode = state->m_fds_write_reg = 0;
1696
1697   state->m_fds_data = auto_alloc_array_clear(machine, UINT8, 65500 * 2);
1698   state->m_fds_ram = auto_alloc_array_clear(machine, UINT8, 0x8000);
1699   state->save_pointer(NAME(state->m_fds_ram), 0x8000);
1700
1701   // setup CHR accesses to 8k VRAM
1702   state->m_vram = machine.region("gfx2")->base();
1703   for (i = 0; i < 8; i++)
1704   {
1705      state->m_chr_map[i].source = CHRRAM;
1706      state->m_chr_map[i].origin = i * 0x400; // for save state uses!
1707      state->m_chr_map[i].access = &state->m_vram[state->m_chr_map[i].origin];
1708   }
1709
1710   floppy_install_load_proc(floppy_get_device(machine, 0), nes_load_proc);
1711   floppy_install_unload_proc(floppy_get_device(machine, 0), nes_unload_proc);
1712}
src/mame/machine/amigacd.h
r0r11461
1#ifndef __AMIGACD_H__
2#define __AMIGACD_H__
3
4
5MACHINE_START( amigacd );
6MACHINE_RESET( amigacd );
7
8/* 6525tpi */
9READ8_DEVICE_HANDLER( amigacd_tpi6525_portc_r );
10WRITE8_DEVICE_HANDLER( amigacd_tpi6525_portb_w );
11WRITE_LINE_DEVICE_HANDLER( amigacd_tpi6525_irq );
12
13
14#endif /* __AMIGACD_H__ */
src/mame/machine/nes_unif.c
r0r11461
1/*****************************************************************************************
2
3    NES MMC Emulation - UNIF boards
4
5    Very preliminary support for UNIF boards
6
7    TODO:
8    - properly support WRAM, etc.
9
10****************************************************************************************/
11
12typedef struct __unif
13{
14   const char *board; /* UNIF board */
15
16   int nvwram;
17   int wram;
18   int chrram;
19   int board_idx;
20} unif;
21
22
23/*************************************************************
24
25    Constants
26
27*************************************************************/
28
29/* CHRRAM sizes */
30enum
31{
32   CHRRAM_0 = 0,
33   CHRRAM_1,
34   CHRRAM_2,
35   CHRRAM_4,
36   CHRRAM_6,
37   CHRRAM_8,
38   CHRRAM_16,
39   CHRRAM_32
40};
41
42/*************************************************************
43
44    unif_list
45
46    Supported UNIF boards and corresponding handlers
47
48*************************************************************/
49
50static const unif unif_list[] =
51{
52/*       UNIF                       NVW  WRAM  CRAM     IDX*/
53   { "DREAMTECH01",                0,    0, CHRRAM_8,  DREAMTECH_BOARD},      //UNIF only!
54   { "NES-ANROM",                  0,    0, CHRRAM_8,  STD_AXROM},
55   { "NES-AOROM",                  0,    0, CHRRAM_8,  STD_AXROM},
56   { "NES-CNROM",                  0,    0, CHRRAM_0,  STD_CNROM},
57   { "NES-NROM",                   0,    0, CHRRAM_0,  STD_NROM},
58   { "NES-NROM-128",               0,    0, CHRRAM_0,  STD_NROM},
59   { "NES-NROM-256",               0,    0, CHRRAM_0,  STD_NROM},
60   { "NES-NTBROM",                 8,    0, CHRRAM_0,  STD_NXROM},
61   { "NES-SLROM",                  0,    0, CHRRAM_0,  STD_SXROM},
62   { "NES-TBROM",                  0,    0, CHRRAM_0,  STD_TXROM},
63   { "NES-TFROM",                  0,    0, CHRRAM_0,  STD_TXROM},
64   { "NES-TKROM",                  8,    0, CHRRAM_0,  STD_TXROM},
65   { "NES-TLROM",                  0,    0, CHRRAM_0,  STD_TXROM},
66   { "NES-UOROM",                  0,    0, CHRRAM_8,  STD_UXROM},
67   { "UNL-22211",                  0,    0, CHRRAM_0,  TXC_22211A},
68   // mapper 172 & 173 are variant of this one... no UNIF?
69   { "UNL-KOF97",                  0,    0, CHRRAM_0,  UNL_KOF97},
70   { "UNL-SA-NROM",                0,    0, CHRRAM_0,  SACHEN_TCA01},
71   { "UNL-VRC7",                   0,    0, CHRRAM_0,  KONAMI_VRC7},
72   { "UNL-T-230",                  0,    0, CHRRAM_8,  UNL_T230},
73   { "UNL-CC-21",                  0,    0, CHRRAM_0,  UNL_CC21},
74   { "UNL-AX5705",                 0,    0, CHRRAM_0,  UNL_AX5705},
75   { "UNL-SMB2J",                  8,    8, CHRRAM_0,  UNL_SMB2J},
76   { "UNL-8237",                   0,    0, CHRRAM_0,  UNL_8237},
77   { "UNL-SL1632",                 0,    0, CHRRAM_0,  REXSOFT_SL1632},
78   { "UNL-SACHEN-74LS374N",        0,    0, CHRRAM_0,  SACHEN_74LS374},
79   // mapper 243 variant exists! how to distinguish?!?  mapper243_l_w, NULL, NULL, NULL, NULL, NULL, NULL (also uses NT_VERT!)
80   { "UNL-TC-U01-1.5M",            0,    0, CHRRAM_0,  SACHEN_TCU01},
81   { "UNL-SACHEN-8259C",           0,    0, CHRRAM_0,  SACHEN_8259C},
82   { "UNL-SA-016-1M",              0,    0, CHRRAM_0,  AVE_NINA06},   // actually this is Mapper 146, but works like 79!
83   { "UNL-SACHEN-8259D",           0,    0, CHRRAM_0,  SACHEN_8259D},
84   { "UNL-SA-72007",               0,    0, CHRRAM_0,  SACHEN_SA72007},
85   { "UNL-SA-72008",               0,    0, CHRRAM_0,  SACHEN_SA72008},
86   { "UNL-SA-0037",                0,    0, CHRRAM_0,  SACHEN_SA0037},
87   { "UNL-SA-0036",                0,    0, CHRRAM_0,  SACHEN_SA0036},
88   { "UNL-SACHEN-8259A",           0,    0, CHRRAM_0,  SACHEN_8259A},
89   { "UNL-SACHEN-8259B",           0,    0, CHRRAM_0,  SACHEN_8259B},
90   { "BMC-190IN1",                 0,    0, CHRRAM_0,  BMC_190IN1},
91   { "BMC-64IN1NOREPEAT",          0,    0, CHRRAM_0,  BMC_64IN1NR},      //UNIF only!
92   { "BMC-A65AS",                  0,    0, CHRRAM_8,  BMC_A65AS},      //UNIF only!
93   { "BMC-GS-2004",                0,    0, CHRRAM_8,  BMC_GS2004},      //UNIF only!
94   { "BMC-GS-2013",                0,    0, CHRRAM_8,  BMC_GS2013},      //UNIF only!
95   { "BMC-NOVELDIAMOND9999999IN1", 0,    0, CHRRAM_0,  BMC_NOVELDIAMOND},
96   { "BMC-SUPER24IN1SC03",         8,    0, CHRRAM_8,  BMC_S24IN1SC03},
97   { "BMC-SUPERHIK8IN1",           8,    0, CHRRAM_0,  BMC_HIK8IN1},
98   { "BMC-T-262",                  0,    0, CHRRAM_8,  BMC_T262},      //UNIF only!
99   { "BMC-WS",                     0,    0, CHRRAM_0,  BMC_WS},      //UNIF only!
100   { "BMC-N625092",                0,    0, CHRRAM_0,  UNL_N625092},
101   // below are boards which are not yet supported, but are used by some UNIF files. they are here as a reminder to what is missing to be added
102   { "UNL-TEK90",                  0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},   // related to JY Company? (i.e. mappers 90, 209, 211?)
103   { "UNL-KS7017",                 0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},
104   { "UNL-KS7032",                 0,    0, CHRRAM_0,  KAISER_KS7032}, //  mapper 142
105   { "UNL-DANCE",                  0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},
106   { "UNL-603-5052",               0,    0, CHRRAM_0,  UNL_603_5052}, // mapper 238?
107   { "UNL-EDU2000",               32,    0, CHRRAM_8,  UNL_EDU2K},
108   { "UNL-H2288",                  0,    0, CHRRAM_0,  UNL_H2288},   // mapper 123
109   { "UNL-SHERO",                  0,    0, CHRRAM_8,  UNSUPPORTED_BOARD /*SACHEN_SHERO*/},
110   { "UNL-TF1201",                 0,    0, CHRRAM_0,  UNSUPPORTED_BOARD /*UNL_TF1201*/},
111   { "UNL-DRIPGAME",               0,    0, CHRRAM_0,  UNSUPPORTED_BOARD}, // [by Quietust - we need more info]}
112   { "UNL-OneBus",                 0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},
113   { "BTL-MARIO1-MALEE2",          0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},   // mapper 55?
114   { "BMC-FK23C",                  0,    0, CHRRAM_0,  BMC_FK23C},
115   { "BMC-FK23CA",                 0,    0, CHRRAM_0,  BMC_FK23CA},
116   { "BMC-GHOSTBUSTERS63IN1",      0,    0, CHRRAM_8,  BMC_G63IN1 },
117   { "BMC-BS-5",                   0,    0, CHRRAM_0,  BMC_BENSHENG_BS5},
118   { "BMC-810544-C-A1",            0,    0, CHRRAM_0,  BMC_810544},
119   { "BMC-411120-C",               0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},
120   { "BMC-8157",                   0,    0, CHRRAM_8,  UNSUPPORTED_BOARD /*BMC_8157*/},
121   { "BMC-42IN1RESETSWITCH",       0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},   // mapper 60?
122   { "BMC-830118C",                0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},
123   { "BMC-D1038",                  0,    0, CHRRAM_0,  BMC_VT5201}, // mapper 60?
124   { "BMC-12-IN-1",                0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},
125   { "BMC-70IN1",                  0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},   // mapper 236?
126   { "BMC-70IN1B",                 0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},   // mapper 236?
127   { "BMC-SUPERVISION16IN1",       0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},   // mapper 53
128   { "BMC-NTD-03",                 0,    0, CHRRAM_0,  BMC_NTD_03}
129};
130
131const unif *nes_unif_lookup( const char *board )
132{
133   int i;
134   for (i = 0; i < ARRAY_LENGTH(unif_list); i++)
135   {
136      if (!mame_stricmp(unif_list[i].board, board))
137         return &unif_list[i];
138   }
139   return NULL;
140}
141
142/*************************************************************
143
144 unif_mapr_setup
145
146 setup the board specific variables (wram, nvwram, pcb_id etc.)
147 for a given board (after reading the MAPR chunk of the UNIF file)
148
149 *************************************************************/
150
151void unif_mapr_setup( running_machine &machine, const char *board )
152{
153   nes_state *state = machine.driver_data<nes_state>();
154   const unif *unif_board = nes_unif_lookup(board);
155
156   logerror("%s\n", board);
157
158   if (unif_board == NULL)
159      fatalerror("Unknown UNIF board %s.", board);
160
161   state->m_pcb_id = unif_board->board_idx;
162   state->m_battery = unif_board->nvwram;   // we should implement battery banks based on the size of this...
163   state->m_battery_size = NES_BATTERY_SIZE; // FIXME: we should allow for smaller battery!
164   state->m_prg_ram = unif_board->wram;   // we should implement WRAM banks based on the size of this...
165
166   if (unif_board->chrram <= CHRRAM_8)
167      state->m_vram_chunks = 1;
168   else if (unif_board->chrram == CHRRAM_16)
169      state->m_vram_chunks = 2;
170   else if (unif_board->chrram == CHRRAM_32)
171      state->m_vram_chunks = 4;
172}
src/mame/machine/msx.c
r0r11461
1/*
2 * msx.c: MSX emulation
3 *
4 * Copyright (C) 2004 Sean Young
5 *
6 * Todo:
7 *
8 * - fix mouse support
9 * - cassette support doesn't work
10 * - Ensure changing cartridge after boot works
11 * - wd2793, nms8255
12 */
13
14#include "emu.h"
15#include "machine/i8255.h"
16#include "includes/msx_slot.h"
17#include "includes/msx.h"
18#include "machine/rp5c01.h"
19#include "machine/wd17xx.h"
20#include "imagedev/flopdrv.h"
21#include "formats/basicdsk.h"
22#include "video/tms9928a.h"
23#include "cpu/z80/z80.h"
24#include "video/v9938.h"
25#include "machine/ctronics.h"
26#include "imagedev/cassette.h"
27#include "osdepend.h"
28#include "sound/ay8910.h"
29#include "sound/2413intf.h"
30#include "sound/dac.h"
31#include "hashfile.h"
32
33#define VERBOSE 0
34
35static void msx_memory_map_all (running_machine &machine);
36static void msx_memory_map_page (running_machine &machine, int page);
37static void msx_memory_init (running_machine &machine);
38static void msx_memory_set_carts (running_machine &machine);
39static void msx_memory_reset (running_machine &machine);
40
41
42
43static int msx_probe_type (UINT8* pmem, int size)
44{
45   int kon4, kon5, asc8, asc16, i;
46
47   if (size <= 0x10000) return 0;
48
49   if ( (pmem[0x10] == 'Y') && (pmem[0x11] == 'Z') && (size > 0x18000) )
50      return 6;
51
52   kon4 = kon5 = asc8 = asc16 = 0;
53
54   for (i=0;i<size-3;i++)
55   {
56      if (pmem[i] == 0x32 && pmem[i+1] == 0)
57      {
58         switch (pmem[i+2]) {
59         case 0x60:
60         case 0x70:
61            asc16++;
62            asc8++;
63            break;
64         case 0x68:
65         case 0x78:
66            asc8++;
67            asc16--;
68         }
69
70         switch (pmem[i+2]) {
71         case 0x60:
72         case 0x80:
73         case 0xa0:
74            kon4++;
75            break;
76         case 0x50:
77         case 0x70:
78         case 0x90:
79         case 0xb0:
80            kon5++;
81         }
82      }
83   }
84
85   if (MAX (kon4, kon5) > MAX (asc8, asc16) )
86      return (kon5 > kon4) ? 2 : 3;
87   else
88      return (asc8 > asc16) ? 4 : 5;
89}
90
91DEVICE_IMAGE_LOAD (msx_cart)
92{
93   msx_state *state = image.device().machine().driver_data<msx_state>();
94   int size;
95   int size_aligned;
96   UINT8 *mem;
97   int type;
98   const char *extra = NULL;
99   char *sramfile;
100   slot_state *st;
101   int id = -1;
102
103   if (strcmp(image.device().tag(),"cart1")==0) {
104      id = 0;
105   }
106   if (strcmp(image.device().tag(),"cart2")==0) {
107      id = 1;
108   }
109
110   if( id == -1 ) {
111      //logerror ("error: invalid cart tag '%s'\n", image->tag);
112      return IMAGE_INIT_FAIL;
113   }
114
115   size = image.length ();
116   if (size < 0x2000) {
117      logerror ("cart #%d: error: file is smaller than 2kb, too small "
118              "to be true!\n", id);
119      return IMAGE_INIT_FAIL;
120   }
121
122   /* allocate memory and load */
123   size_aligned = 0x2000;
124   while (size_aligned < size) {
125      size_aligned *= 2;
126   }
127   mem = (UINT8*)image.image_malloc(size_aligned);
128   if (!mem) {
129      logerror ("cart #%d: error: failed to allocate memory for cartridge\n",
130                  id);
131      return IMAGE_INIT_FAIL;
132   }
133   if (size < size_aligned) {
134      memset (mem, 0xff, size_aligned);
135   }
136   if (image.fread(mem, size) != size) {
137      logerror ("cart #%d: %s: can't read full %d bytes\n",
138                  id, image.filename (), size);
139      return IMAGE_INIT_FAIL;
140   }
141
142   /* see if msx.crc will tell us more */
143   extra = hashfile_extrainfo(image);
144
145   if (!extra)
146   {
147      logerror("cart #%d: warning: no information in crc file\n", id);
148      type = -1;
149   }
150   else if ((1 != sscanf(extra, "%d", &type) ) ||
151         type < 0 || type > SLOT_LAST_CARTRIDGE_TYPE)
152   {
153      logerror("cart #%d: warning: information in crc file not valid\n", id);
154      type = -1;
155   }
156   else
157   {
158      logerror ("cart #%d: info: cart extra info: '%s' = %s\n", id, extra,
159                  msx_slot_list[type].name);
160   }
161
162   /* if not, attempt autodetection */
163   if (type < 0)
164   {
165      type = msx_probe_type (mem, size);
166
167      if (mem[0] != 'A' || mem[1] != 'B') {
168         logerror("cart #%d: %s: May not be a valid ROM file\n",
169                     id, image.filename ());
170      }
171
172      logerror("cart #%d: Probed cartridge mapper %d/%s\n", id,
173                  type, msx_slot_list[type].name);
174   }
175
176   /* mapper type 0 always needs 64kB */
177   if (!type && size_aligned != 0x10000)
178   {
179      size_aligned = 0x10000;
180      mem = (UINT8*)image.image_realloc(mem, 0x10000);
181      if (!mem) {
182         logerror ("cart #%d: error: cannot allocate memory\n", id);
183         return IMAGE_INIT_FAIL;
184      }
185
186      if (size < 0x10000) {
187         memset (mem + size, 0xff, 0x10000 - size);
188      }
189      if (size > 0x10000) {
190         logerror ("cart #%d: warning: rom truncated to 64kb due to "
191                 "mapperless type (possibly detected)\n", id);
192
193         size = 0x10000;
194      }
195   }
196
197   /* mapper type 0 (ROM) might need moving around a bit */
198   if (!type) {
199      int i, page = 1;
200
201      /* find the correct page */
202      if (mem[0] == 'A' && mem[1] == 'B') {
203         for (i=2; i<=8; i += 2) {
204            if (mem[i] || mem[i+1]) {
205               page = mem[i+1] / 0x40;
206               break;
207            }
208         }
209      }
210
211      if (size <= 0x4000) {
212         if (page == 1 || page == 2) {
213            /* copy to the respective page */
214            memcpy (mem + (page * 0x4000), mem, 0x4000);
215            memset (mem, 0xff, 0x4000);
216         }
217         else {
218            /* memory is repeated 4 times */
219            page = -1;
220            memcpy (mem + 0x4000, mem, 0x4000);
221            memcpy (mem + 0x8000, mem, 0x4000);
222            memcpy (mem + 0xc000, mem, 0x4000);
223         }
224      }
225      else /*if (size <= 0xc000) */ {
226         if (page) {
227            /* shift up 16kB; custom memcpy so overlapping memory
228                   isn't corrupted. ROM starts in page 1 (0x4000) */
229            UINT8 *m;
230
231            page = 1;
232            i = 0xc000; m = mem + 0xffff;
233            while (i--) {
234               *m = *(m - 0x4000); m--;
235            }
236            memset (mem, 0xff, 0x4000);
237         }
238      }
239
240      if (page) {
241         logerror ("cart #%d: info: rom in page %d\n", id, page);
242      }
243      else {
244         logerror ("cart #%d: info: rom duplicted in all pages\n", id);
245      }
246   }
247
248   /* kludge */
249   if (type == 0) {
250      type = SLOT_ROM;
251   }
252
253   /* allocate and set slot_state for this cartridge */
254   st = (slot_state*) image.image_malloc(sizeof (slot_state));
255   if (!st)
256   {
257      logerror ("cart #%d: error: cannot allocate memory for "
258              "cartridge state\n", id);
259      return IMAGE_INIT_FAIL;
260   }
261   memset (st, 0, sizeof (slot_state));
262
263   st->m_type = type;
264   sramfile = (char*)image.image_malloc(strlen (image.filename () + 1));
265
266   if (sramfile) {
267      char *ext;
268
269      strcpy (sramfile, image.basename ());
270      ext = strrchr (sramfile, '.');
271      if (ext) {
272         *ext = 0;
273      }
274      st->m_sramfile = sramfile;
275   }
276
277   if (msx_slot_list[type].init (image.device().machine(), st, 0, mem, size_aligned)) {
278      return IMAGE_INIT_FAIL;
279   }
280   if (msx_slot_list[type].loadsram) {
281      msx_slot_list[type].loadsram (image.device().machine(), st);
282   }
283
284   state->m_cart_state[id] = st;
285   msx_memory_set_carts (image.device().machine());
286
287   return IMAGE_INIT_PASS;
288}
289
290DEVICE_IMAGE_UNLOAD (msx_cart)
291{
292   msx_state *state = image.device().machine().driver_data<msx_state>();
293   int id = -1;
294
295   if (strcmp(image.device().tag(),"cart1")==0) {
296      id = 0;
297   }
298   if (strcmp(image.device().tag(),"cart2")==0) {
299      id = 1;
300   }
301
302   if( id == -1 ) {
303      //logerror ("error: invalid cart tag '%s'\n", image->tag);
304      return;
305   }
306
307   if (msx_slot_list[state->m_cart_state[id]->m_type].savesram)
308   {
309      msx_slot_list[state->m_cart_state[id]->m_type].savesram (image.device().machine(), state->m_cart_state[id]);
310   }
311}
312
313void msx_vdp_interrupt(running_machine &machine, int i)
314{
315   cputag_set_input_line (machine, "maincpu", 0, (i ? HOLD_LINE : CLEAR_LINE));
316}
317
318static void msx_ch_reset_core (running_machine &machine)
319{
320   msx_memory_reset (machine);
321   msx_memory_map_all (machine);
322}
323
324static const TMS9928a_interface tms9928a_interface =
325{
326   TMS99x8A,
327   0x4000,
328   0, 0,
329   msx_vdp_interrupt
330};
331
332MACHINE_START( msx )
333{
334   TMS9928A_configure(&tms9928a_interface);
335   MACHINE_START_CALL( msx2 );
336}
337
338MACHINE_START( msx2 )
339{
340   msx_state *state = machine.driver_data<msx_state>();
341   state->m_port_c_old = 0xff;
342   state->m_dsk_stat = 0x7f;
343}
344
345MACHINE_RESET( msx )
346{
347   TMS9928A_reset ();
348   msx_ch_reset_core (machine);
349}
350
351MACHINE_RESET( msx2 )
352{
353   v9938_reset (0);
354   msx_ch_reset_core (machine);
355}
356
357static WRITE8_DEVICE_HANDLER ( msx_ppi_port_a_w );
358static WRITE8_DEVICE_HANDLER ( msx_ppi_port_c_w );
359static READ8_DEVICE_HANDLER (msx_ppi_port_b_r );
360
361I8255_INTERFACE( msx_ppi8255_interface )
362{
363   DEVCB_NULL,
364   DEVCB_HANDLER(msx_ppi_port_a_w),
365   DEVCB_HANDLER(msx_ppi_port_b_r),
366   DEVCB_NULL,
367   DEVCB_NULL,
368   DEVCB_HANDLER(msx_ppi_port_c_w)
369};
370
371
372static const UINT8 cc_op[0x100] = {
373 4+1,10+1, 7+1, 6+1, 4+1, 4+1, 7+1, 4+1, 4+1,11+1, 7+1, 6+1, 4+1, 4+1, 7+1, 4+1,
374 8+1,10+1, 7+1, 6+1, 4+1, 4+1, 7+1, 4+1,12+1,11+1, 7+1, 6+1, 4+1, 4+1, 7+1, 4+1,
375 7+1,10+1,16+1, 6+1, 4+1, 4+1, 7+1, 4+1, 7+1,11+1,16+1, 6+1, 4+1, 4+1, 7+1, 4+1,
376 7+1,10+1,13+1, 6+1,11+1,11+1,10+1, 4+1, 7+1,11+1,13+1, 6+1, 4+1, 4+1, 7+1, 4+1,
377 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1,
378 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1,
379 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1,
380 7+1, 7+1, 7+1, 7+1, 7+1, 7+1, 4+1, 7+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1,
381 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1,
382 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1,
383 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1,
384 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1,
385 5+1,10+1,10+1,10+1,10+1,11+1, 7+1,11+1, 5+1,10+1,10+1, 0+1,10+1,17+1, 7+1,11+1,
386 5+1,10+1,10+1,11+1,10+1,11+1, 7+1,11+1, 5+1, 4+1,10+1,11+1,10+1, 0+1, 7+1,11+1,
387 5+1,10+1,10+1,19+1,10+1,11+1, 7+1,11+1, 5+1, 4+1,10+1, 4+1,10+1, 0+1, 7+1,11+1,
388 5+1,10+1,10+1, 4+1,10+1,11+1, 7+1,11+1, 5+1, 6+1,10+1, 4+1,10+1, 0+1, 7+1,11+1
389};
390
391static const UINT8 cc_cb[0x100] = {
392 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
393 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
394 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
395 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
396 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,12+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,12+2, 8+2,
397 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,12+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,12+2, 8+2,
398 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,12+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,12+2, 8+2,
399 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,12+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,12+2, 8+2,
400 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
401 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
402 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
403 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
404 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
405 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
406 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
407 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2
408};
409
410static const UINT8 cc_ed[0x100] = {
411 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
412 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
413 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
414 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
41512+2,12+2,15+2,20+2, 8+2,14+2, 8+2, 9+2,12+2,12+2,15+2,20+2, 8+2,14+2, 8+2, 9+2,
41612+2,12+2,15+2,20+2, 8+2,14+2, 8+2, 9+2,12+2,12+2,15+2,20+2, 8+2,14+2, 8+2, 9+2,
41712+2,12+2,15+2,20+2, 8+2,14+2, 8+2,18+2,12+2,12+2,15+2,20+2, 8+2,14+2, 8+2,18+2,
41812+2,12+2,15+2,20+2, 8+2,14+2, 8+2, 8+2,12+2,12+2,15+2,20+2, 8+2,14+2, 8+2, 8+2,
419 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
420 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
42116+2,16+2,16+2,16+2, 8+2, 8+2, 8+2, 8+2,16+2,16+2,16+2,16+2, 8+2, 8+2, 8+2, 8+2,
42216+2,16+2,16+2,16+2, 8+2, 8+2, 8+2, 8+2,16+2,16+2,16+2,16+2, 8+2, 8+2, 8+2, 8+2,
423 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
424 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
425 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
426 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2
427};
428
429static const UINT8 cc_xy[0x100] = {
430 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2,15+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2,
431 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2,15+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2,
432 4+2,14+2,20+2,10+2, 9+2, 9+2, 9+2, 4+2, 4+2,15+2,20+2,10+2, 9+2, 9+2, 9+2, 4+2,
433 4+2, 4+2, 4+2, 4+2,23+2,23+2,19+2, 4+2, 4+2,15+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2,
434 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2, 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2,
435 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2, 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2,
436 9+2, 9+2, 9+2, 9+2, 9+2, 9+2,19+2, 9+2, 9+2, 9+2, 9+2, 9+2, 9+2, 9+2,19+2, 9+2,
43719+2,19+2,19+2,19+2,19+2,19+2, 4+2,19+2, 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2,
438 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2, 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2,
439 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2, 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2,
440 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2, 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2,
441 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2, 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2,
442 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 0+2, 4+2, 4+2, 4+2, 4+2,
443 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2,
444 4+2,14+2, 4+2,23+2, 4+2,15+2, 4+2, 4+2, 4+2, 8+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2,
445 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2,10+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2
446};
447
448static const UINT8 cc_xycb[0x100] = {
44923+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
45023+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
45123+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
45223+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
45320+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,
45420+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,
45520+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,
45620+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,
45723+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
45823+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
45923+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
46023+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
46123+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
46223+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
46323+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
46423+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2
465};
466
467/* extra cycles if jr/jp/call taken and 'interrupt latency' on rst 0-7 */
468static const UINT8 cc_ex[0x100] = {
469 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
470 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   /* DJNZ */
471 5, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,   /* JR NZ/JR Z */
472 5, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,   /* JR NC/JR C */
473 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
474 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
475 0, 0, 0, 0, 0, 0, 0+1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
476 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
477 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
478 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
479 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
480 5, 5, 5, 5, 0, 0, 0, 0, 5, 5, 5, 5, 0, 0, 0, 0,   /* LDIR/CPIR/INIR/OTIR LDDR/CPDR/INDR/OTDR */
481 6, 0, 0, 0, 7, 0, 0, 2, 6, 0, 0, 0, 7, 0, 0, 2,
482 6, 0, 0, 0, 7, 0, 0, 2, 6, 0, 0, 0, 7, 0, 0, 2,
483 6, 0, 0, 0, 7, 0, 0, 2, 6, 0, 0, 0, 7, 0, 0, 2,
484 6, 0, 0, 0, 7, 0, 0, 2, 6, 0, 0, 0, 7, 0, 0, 2+1
485};
486
487
488DRIVER_INIT( msx )
489{
490   device_set_input_line_vector (machine.device("maincpu"), 0, 0xff);
491
492   msx_memory_init (machine);
493
494   z80_set_cycle_tables( machine.device("maincpu"), cc_op, cc_cb, cc_ed, cc_xy, cc_xycb, cc_ex );
495}
496
497INTERRUPT_GEN( msx2_interrupt )
498{
499   v9938_set_sprite_limit(0, input_port_read(device->machine(), "DSW") & 0x20);
500   v9938_set_resolution(0, input_port_read(device->machine(), "DSW") & 0x03);
501   v9938_interrupt(device->machine(), 0);
502}
503
504INTERRUPT_GEN( msx_interrupt )
505{
506   msx_state *state = device->machine().driver_data<msx_state>();
507   int i;
508
509   for (i=0; i<2; i++)
510   {
511      state->m_mouse[i] = input_port_read(device->machine(), i ? "MOUSE1" : "MOUSE0");
512      state->m_mouse_stat[i] = -1;
513   }
514
515   TMS9928A_set_spriteslimit (input_port_read(device->machine(), "DSW") & 0x20);
516   TMS9928A_interrupt(device->machine());
517}
518
519/*
520** The I/O funtions
521*/
522
523static device_t *cassette_device_image(running_machine &machine)
524{
525   return machine.device("cassette");
526}
527
528READ8_HANDLER ( msx_psg_port_a_r )
529{
530   msx_state *state = space->machine().driver_data<msx_state>();
531   int data, inp;
532
533   data = (cassette_input(cassette_device_image(space->machine())) > 0.0038 ? 0x80 : 0);
534
535   if ( (state->m_psg_b ^ input_port_read(space->machine(), "DSW") ) & 0x40)
536      {
537      /* game port 2 */
538      inp = input_port_read(space->machine(), "JOY1") & 0x7f;
539#if 0
540      if ( !(inp & 0x80) )
541         {
542#endif
543         /* joystick */
544         return (inp & 0x7f) | data;
545#if 0
546         }
547      else
548         {
549         /* mouse */
550         data |= inp & 0x70;
551         if (state->m_mouse_stat[1] < 0)
552            inp = 0xf;
553         else
554            inp = ~(state->m_mouse[1] >> (4*state->m_mouse_stat[1]) ) & 15;
555
556         return data | inp;
557         }
558#endif
559      }
560   else
561      {
562      /* game port 1 */
563      inp = input_port_read(space->machine(), "JOY0") & 0x7f;
564#if 0
565      if ( !(inp & 0x80) )
566         {
567#endif
568         /* joystick */
569         return (inp & 0x7f) | data;
570#if 0
571         }
572      else
573         {
574         /* mouse */
575         data |= inp & 0x70;
576         if (state->m_mouse_stat[0] < 0)
577            inp = 0xf;
578         else
579            inp = ~(state->m_mouse[0] >> (4*state->m_mouse_stat[0]) ) & 15;
580
581         return data | inp;
582         }
583#endif
584      }
585
586   return 0;
587}
588
589READ8_HANDLER ( msx_psg_port_b_r )
590{
591   msx_state *state = space->machine().driver_data<msx_state>();
592   return state->m_psg_b;
593}
594
595WRITE8_HANDLER ( msx_psg_port_a_w )
596{
597}
598
599WRITE8_HANDLER ( msx_psg_port_b_w )
600{
601   msx_state *state = space->machine().driver_data<msx_state>();
602   /* Arabic or kana mode led */
603   if ( (data ^ state->m_psg_b) & 0x80)
604      set_led_status (space->machine(), 2, !(data & 0x80) );
605
606   if ( (state->m_psg_b ^ data) & 0x10)
607   {
608      if (++state->m_mouse_stat[0] > 3) state->m_mouse_stat[0] = -1;
609   }
610   if ( (state->m_psg_b ^ data) & 0x20)
611   {
612      if (++state->m_mouse_stat[1] > 3) state->m_mouse_stat[1] = -1;
613   }
614
615   state->m_psg_b = data;
616}
617
618WRITE8_DEVICE_HANDLER( msx_printer_strobe_w )
619{
620   centronics_strobe_w(device, BIT(data, 1));
621}
622
623WRITE8_DEVICE_HANDLER( msx_printer_data_w )
624{
625   if (input_port_read(device->machine(), "DSW") & 0x80)
626   {
627      /* SIMPL emulation */
628      dac_signed_data_w(device->machine().device("dac"), data);
629   }
630   else
631   {
632      centronics_data_w(device, 0, data);
633   }
634}
635
636READ8_DEVICE_HANDLER( msx_printer_status_r )
637{
638   UINT8 result = 0xfd;
639
640   if (input_port_read(device->machine(), "DSW") & 0x80)
641      return 0xff;
642
643   result |= centronics_busy_r(device) << 1;
644
645   return result;
646}
647
648WRITE8_HANDLER (msx_fmpac_w)
649{
650   msx_state *state = space->machine().driver_data<msx_state>();
651   if (state->m_opll_active)
652   {
653      device_t *ym = space->machine().device("ym2413");
654
655      if (offset == 1)
656         ym2413_w (ym, 1, data);
657      else
658         ym2413_w (ym, 0, data);
659   }
660}
661
662/*
663** RTC functions
664*/
665
666WRITE8_HANDLER (msx_rtc_latch_w)
667{
668   msx_state *state = space->machine().driver_data<msx_state>();
669   state->m_rtc_latch = data & 15;
670}
671
672WRITE8_HANDLER (msx_rtc_reg_w)
673{
674   msx_state *state = space->machine().driver_data<msx_state>();
675   rp5c01_device *rtc = space->machine().device<rp5c01_device>(TC8521_TAG);
676   rtc->write(*space, state->m_rtc_latch, data);
677}
678
679READ8_HANDLER (msx_rtc_reg_r)
680{
681   msx_state *state = space->machine().driver_data<msx_state>();
682   rp5c01_device *rtc = space->machine().device<rp5c01_device>(TC8521_TAG);
683   return rtc->read(*space, state->m_rtc_latch);
684}
685
686/*
687From: erbo@xs4all.nl (erik de boer)
688
689sony and philips have used (almost) the same design
690and this is the memory layout
691but it is not a msx standard !
692
693WD1793 or wd2793 registers
694
695adress
696
6977FF8H read  status register
698      write command register
6997FF9H  r/w  track register (r/o on NMS 8245 and Sony)
7007FFAH  r/w  sector register (r/o on NMS 8245 and Sony)
7017FFBH  r/w  data register
702
703
704hardware registers
705
706adress
707
7087FFCH r/w  bit 0 side select
7097FFDH r/w  b7>M-on , b6>in-use , b1>ds1 , b0>ds0  (all neg. logic)
7107FFEH         not used
7117FFFH read b7>drq , b6>intrq
712
713set on 7FFDH bit 2 always to 0 (some use it as disk change reset)
714
715*/
716
717static WRITE_LINE_DEVICE_HANDLER( msx_wd179x_intrq_w )
718{
719   msx_state *drvstate = device->machine().driver_data<msx_state>();
720   if (state)
721      drvstate->m_dsk_stat &= ~0x40;
722   else
723      drvstate->m_dsk_stat |= 0x40;
724}
725
726static WRITE_LINE_DEVICE_HANDLER( msx_wd179x_drq_w )
727{
728   msx_state *drvstate = device->machine().driver_data<msx_state>();
729   if (state)
730      drvstate->m_dsk_stat &= ~0x80;
731   else
732      drvstate->m_dsk_stat |= 0x80;
733}
734
735const wd17xx_interface msx_wd17xx_interface =
736{
737   DEVCB_LINE_VCC,
738   DEVCB_LINE(msx_wd179x_intrq_w),
739   DEVCB_LINE(msx_wd179x_drq_w),
740   {FLOPPY_0, FLOPPY_1, NULL, NULL}
741};
742
743FLOPPY_OPTIONS_START(msx)
744   FLOPPY_OPTION(msx, "dsk", "MSX SS", basicdsk_identify_default, basicdsk_construct_default, NULL,
745      HEADS([1])
746      TRACKS([80])
747      SECTORS([9])
748      SECTOR_LENGTH([512])
749      FIRST_SECTOR_ID([1]))
750   FLOPPY_OPTION(msx, "dsk", "MSX DS", basicdsk_identify_default, basicdsk_construct_default, NULL,
751      HEADS([2])
752      TRACKS([80])
753      SECTORS([9])
754      SECTOR_LENGTH([512])
755      FIRST_SECTOR_ID([1]))
756FLOPPY_OPTIONS_END
757
758/*
759** The PPI functions
760*/
761
762static WRITE8_DEVICE_HANDLER ( msx_ppi_port_a_w )
763{
764   msx_state *state = device->machine().driver_data<msx_state>();
765   state->m_primary_slot = data;
766
767   if (VERBOSE)
768      logerror ("write to primary slot select: %02x\n", state->m_primary_slot);
769   msx_memory_map_all (device->machine());
770}
771
772static WRITE8_DEVICE_HANDLER ( msx_ppi_port_c_w )
773{
774   msx_state *state = device->machine().driver_data<msx_state>();
775   
776   state->keylatch = data & 0x0f;
777
778   /* caps lock */
779   if ( (state->m_port_c_old ^ data) & 0x40)
780      set_led_status (device->machine(),1, !(data & 0x40) );
781
782   /* key click */
783   if ( (state->m_port_c_old ^ data) & 0x80)
784      dac_signed_data_w (device->machine().device("dac"), (data & 0x80 ? 0x7f : 0));
785
786   /* cassette motor on/off */
787   if ( (state->m_port_c_old ^ data) & 0x10)
788      cassette_change_state(cassette_device_image(device->machine()),
789                  (data & 0x10) ? CASSETTE_MOTOR_DISABLED :
790                              CASSETTE_MOTOR_ENABLED,
791                  CASSETTE_MASK_MOTOR);
792
793   /* cassette signal write */
794   if ( (state->m_port_c_old ^ data) & 0x20)
795      cassette_output(cassette_device_image(device->machine()), (data & 0x20) ? -1.0 : 1.0);
796
797   state->m_port_c_old = data;
798}
799
800static READ8_DEVICE_HANDLER( msx_ppi_port_b_r )
801{
802   msx_state *state = device->machine().driver_data<msx_state>();
803   UINT8 result = 0xff;
804   int row, data;
805   static const char *const keynames[] = { "KEY0", "KEY1", "KEY2", "KEY3", "KEY4", "KEY5" };
806
807   row = state->keylatch;
808   if (row <= 10)
809   {
810      data = input_port_read(device->machine(), keynames[row / 2]);
811
812      if (row & 1)
813         data >>= 8;
814      result = data & 0xff;
815   }
816   return result;
817}
818
819/************************************************************************
820 *
821 * New memory emulation !!
822 *
823 ***********************************************************************/
824
825static void msx_memory_init (running_machine &machine)
826{
827   msx_state *state = machine.driver_data<msx_state>();
828   int   prim, sec, page, extent, option;
829   int size = 0;
830   const msx_slot_layout *layout= (msx_slot_layout*)NULL;
831   const msx_slot *slot;
832   const msx_driver_struct *driver;
833   slot_state *st;
834   UINT8 *mem = NULL;
835
836   state->m_empty = auto_alloc_array(machine, UINT8, 0x4000);
837   memset (state->m_empty, 0xff, 0x4000);
838
839   for (prim=0; prim<4; prim++) {
840      for (sec=0; sec<4; sec++) {
841         for (page=0; page<4; page++) {
842            state->m_all_state[prim][sec][page]= (slot_state*)NULL;
843         }
844      }
845   }
846
847   for (driver = msx_driver_list; driver->name[0]; driver++) {
848      if (!strcmp (driver->name, machine.system().name)) {
849         layout = driver->layout;
850      }
851   }
852
853   if (!layout) {
854      logerror ("msx_memory_init: error: missing layout definition in "
855              "msx_driver_list\n");
856      return;
857   }
858
859   state->layout = layout;
860
861   for (; layout->entry != MSX_LAYOUT_LAST; layout++) {
862
863      switch (layout->entry) {
864      case MSX_LAYOUT_SLOT_ENTRY:
865         prim = layout->slot_primary;
866         sec = layout->slot_secondary;
867         page = layout->slot_page;
868         extent = layout->page_extent;
869
870         if (layout->slot_secondary) {
871            state->m_slot_expanded[layout->slot_primary]= TRUE;
872         }
873
874         slot = &msx_slot_list[layout->type];
875         if (slot->slot_type != layout->type) {
876            logerror ("internal error: msx_slot_list[%d].type != %d\n",
877                     slot->slot_type, slot->slot_type);
878         }
879
880         size = layout->size;
881         option = layout->option;
882
883         if (VERBOSE)
884         {
885            logerror ("slot %d/%d/%d-%d: type %s, size 0x%x\n",
886               prim, sec, page, page + extent - 1, slot->name, size);
887         }
888
889         st = (slot_state*)NULL;
890         if (layout->type == SLOT_CARTRIDGE1) {
891            st = state->m_cart_state[0];
892            if (!st) {
893               slot = &msx_slot_list[SLOT_SOUNDCARTRIDGE];
894               size = 0x20000;
895            }
896         }
897         if (layout->type == SLOT_CARTRIDGE2) {
898            st = state->m_cart_state[1];
899            if (!st) {
900               /* Check whether the optional FM-PAC rom is present */
901               option = 0x10000;
902               size = 0x10000;
903               mem = machine.region("maincpu")->base() + option;
904               if (machine.region("maincpu")->bytes() >= size + option && mem[0] == 'A' && mem[1] == 'B') {
905                  slot = &msx_slot_list[SLOT_FMPAC];
906               }
907               else {
908                  slot = &msx_slot_list[SLOT_EMPTY];
909               }
910            }
911         }
912
913         if (!st) {
914            switch (slot->mem_type) {
915
916            case MSX_MEM_HANDLER:
917            case MSX_MEM_ROM:
918               mem = machine.region("maincpu")->base() + option;
919               break;
920            case MSX_MEM_RAM:
921               mem = NULL;
922               break;
923            }
924            st = auto_alloc_clear (machine, slot_state);
925            memset (st, 0, sizeof (slot_state));
926
927            if (slot->init (machine, st, layout->slot_page, mem, size)) {
928               continue;
929            }
930         }
931
932         while (extent--) {
933            if (page > 3) {
934               logerror ("internal error: msx_slot_layout wrong, "
935                   "page + extent > 3\n");
936               break;
937            }
938            state->m_all_state[prim][sec][page] = st;
939            page++;
940         }
941         break;
942      case MSX_LAYOUT_KANJI_ENTRY:
943         state->m_kanji_mem = machine.region("maincpu")->base() + layout->option;
944         break;
945      case MSX_LAYOUT_RAMIO_SET_BITS_ENTRY:
946         state->m_ramio_set_bits = (UINT8)layout->option;
947         break;
948      }
949   }
950}
951
952static void msx_memory_reset (running_machine &machine)
953{
954   msx_state *state = machine.driver_data<msx_state>();
955   slot_state *st, *last_st = (slot_state*)NULL;
956   int prim, sec, page;
957
958   state->m_primary_slot = 0;
959
960   for (prim=0; prim<4; prim++) {
961      state->m_secondary_slot[prim] = 0;
962      for (sec=0; sec<4; sec++) {
963         for (page=0; page<4; page++) {
964            st = state->m_all_state[prim][sec][page];
965            if (st && st != last_st) {
966               msx_slot_list[st->m_type].reset (machine, st);
967            }
968            last_st = st;
969         }
970      }
971   }
972}
973
974static void msx_memory_set_carts (running_machine &machine)
975{
976   msx_state *state = machine.driver_data<msx_state>();
977   const msx_slot_layout *layout;
978   int page;
979
980   if (!state->layout) {
981      return;
982   }
983
984   for (layout = state->layout; layout->entry != MSX_LAYOUT_LAST; layout++) {
985
986      if (layout->entry == MSX_LAYOUT_SLOT_ENTRY) {
987
988         switch (layout->type) {
989         case SLOT_CARTRIDGE1:
990            for (page=0; page<4; page++) {
991               state->m_all_state[layout->slot_primary]
992                          [layout->slot_secondary]
993                          [page] = state->m_cart_state[0];
994            }
995            break;
996         case SLOT_CARTRIDGE2:
997            for (page=0; page<4; page++) {
998               state->m_all_state[layout->slot_primary]
999                          [layout->slot_secondary]
1000                          [page] = state->m_cart_state[1];
1001            }
1002            break;
1003         }
1004      }
1005   }
1006}
1007
1008static void msx_memory_map_page (running_machine &machine, int page)
1009{
1010   msx_state *state = machine.driver_data<msx_state>();
1011   int slot_primary;
1012   int slot_secondary;
1013   slot_state *st;
1014   const msx_slot *slot;
1015
1016   slot_primary = (state->m_primary_slot >> (page * 2)) & 3;
1017   slot_secondary = (state->m_secondary_slot[slot_primary] >> (page * 2)) & 3;
1018
1019   st = state->m_all_state[slot_primary][slot_secondary][page];
1020   slot = st ? &msx_slot_list[st->m_type] : &msx_slot_list[SLOT_EMPTY];
1021   state->m_state[page] = st;
1022   state->m_slot[page] = slot;
1023
1024   if (VERBOSE)
1025   {
1026      logerror ("mapping %s in %d/%d/%d\n", slot->name, slot_primary,
1027         slot_secondary, page);
1028   }
1029   slot->map (machine, st, page);
1030}
1031
1032static void msx_memory_map_all (running_machine &machine)
1033{
1034   int i;
1035
1036   for (i=0; i<4; i++) {
1037      msx_memory_map_page (machine, i);
1038   }
1039}
1040
1041WRITE8_HANDLER (msx_page0_w)
1042{
1043   msx_state *state = space->machine().driver_data<msx_state>();
1044   if ( offset == 0 )
1045   {
1046      state->m_superloadrunner_bank = data;
1047      if (state->m_slot[2]->slot_type == SLOT_SUPERLOADRUNNER) {
1048         state->m_slot[2]->map (space->machine(), state->m_state[2], 2);
1049      }
1050   }
1051
1052   switch (state->m_slot[0]->mem_type) {
1053   case MSX_MEM_RAM:
1054      state->m_ram_pages[0][offset] = data;
1055      break;
1056   case MSX_MEM_HANDLER:
1057      state->m_slot[0]->write (space->machine(), state->m_state[0], offset, data);
1058   }
1059}
1060
1061WRITE8_HANDLER (msx_page0_1_w)
1062{
1063   msx_page0_w( space, 0x2000 + offset, data );
1064}
1065
1066WRITE8_HANDLER (msx_page1_w)
1067{
1068   msx_state *state = space->machine().driver_data<msx_state>();
1069   switch (state->m_slot[1]->mem_type) {
1070   case MSX_MEM_RAM:
1071      state->m_ram_pages[1][offset] = data;
1072      break;
1073   case MSX_MEM_HANDLER:
1074      state->m_slot[1]->write (space->machine(), state->m_state[1], 0x4000 + offset, data);
1075   }
1076}
1077
1078WRITE8_HANDLER (msx_page1_1_w)
1079{
1080   msx_page1_w( space, 0x2000 + offset, data );
1081}
1082
1083WRITE8_HANDLER (msx_page1_2_w)
1084{
1085   msx_page1_w( space, 0x3ff8 + offset, data );
1086}
1087
1088WRITE8_HANDLER (msx_page2_w)
1089{
1090   msx_state *state = space->machine().driver_data<msx_state>();
1091   switch (state->m_slot[2]->mem_type) {
1092   case MSX_MEM_RAM:
1093      state->m_ram_pages[2][offset] = data;
1094      break;
1095   case MSX_MEM_HANDLER:
1096      state->m_slot[2]->write (space->machine(), state->m_state[2], 0x8000 + offset, data);
1097   }
1098}
1099
1100WRITE8_HANDLER (msx_page2_1_w)
1101{
1102   msx_page2_w( space, 0x1800 + offset, data );
1103}
1104
1105WRITE8_HANDLER (msx_page2_2_w)
1106{
1107   msx_page2_w( space, 0x2000 + offset, data );
1108}
1109
1110WRITE8_HANDLER (msx_page2_3_w)
1111{
1112   msx_page2_w( space, 0x3800 + offset, data );
1113}
1114
1115WRITE8_HANDLER (msx_page3_w)
1116{
1117   msx_state *state = space->machine().driver_data<msx_state>();
1118   switch (state->m_slot[3]->mem_type) {
1119   case MSX_MEM_RAM:
1120      state->m_ram_pages[3][offset] = data;
1121      break;
1122   case MSX_MEM_HANDLER:
1123      state->m_slot[3]->write (space->machine(), state->m_state[3], 0xc000 + offset, data);
1124   }
1125}
1126
1127WRITE8_HANDLER (msx_page3_1_w)
1128{
1129   msx_page3_w( space, 0x2000 + offset, data );
1130}
1131
1132WRITE8_HANDLER (msx_sec_slot_w)
1133{
1134   msx_state *state = space->machine().driver_data<msx_state>();
1135   int slot = state->m_primary_slot >> 6;
1136   if (state->m_slot_expanded[slot])
1137   {
1138      if (VERBOSE)
1139         logerror ("write to secondary slot %d select: %02x\n", slot, data);
1140
1141      state->m_secondary_slot[slot] = data;
1142      msx_memory_map_all (space->machine());
1143   }
1144   else {
1145      msx_page3_w(space, 0x3fff, data);
1146   }
1147}
1148
1149READ8_HANDLER (msx_sec_slot_r)
1150{
1151   msx_state *state = space->machine().driver_data<msx_state>();
1152   UINT8 result;
1153   int slot = state->m_primary_slot >> 6;
1154
1155   if (state->m_slot_expanded[slot])
1156      result = ~state->m_secondary_slot[slot];
1157   else
1158      result = state->m_top_page[0x1fff];
1159
1160   return result;
1161}
1162
1163WRITE8_HANDLER (msx_ram_mapper_w)
1164{
1165   msx_state *state = space->machine().driver_data<msx_state>();
1166   state->m_ram_mapper[offset] = data;
1167   if (state->m_slot[offset]->slot_type == SLOT_RAM_MM) {
1168      state->m_slot[offset]->map (space->machine(), state->m_state[offset], offset);
1169   }
1170}
1171
1172READ8_HANDLER (msx_ram_mapper_r)
1173{
1174   msx_state *state = space->machine().driver_data<msx_state>();
1175   return state->m_ram_mapper[offset] | state->m_ramio_set_bits;
1176}
1177
1178WRITE8_HANDLER (msx_90in1_w)
1179{
1180   msx_state *state = space->machine().driver_data<msx_state>();
1181   state->m_korean90in1_bank = data;
1182   if (state->m_slot[1]->slot_type == SLOT_KOREAN_90IN1)
1183   {
1184      state->m_slot[1]->map (space->machine(), state->m_state[1], 1);
1185   }
1186   if (state->m_slot[2]->slot_type == SLOT_KOREAN_90IN1)
1187   {
1188      state->m_slot[2]->map (space->machine(), state->m_state[2], 2);
1189   }
1190}
1191
1192READ8_HANDLER (msx_kanji_r)
1193{
1194   msx_state *state = space->machine().driver_data<msx_state>();
1195   UINT8 result = 0xff;
1196
1197   if (offset && state->m_kanji_mem)
1198   {
1199      int latch;
1200      UINT8 ret;
1201
1202      latch = state->m_kanji_latch;
1203      ret = state->m_kanji_mem[latch++];
1204
1205      state->m_kanji_latch &= ~0x1f;
1206      state->m_kanji_latch |= latch & 0x1f;
1207
1208      result = ret;
1209   }
1210   return result;
1211}
1212
1213WRITE8_HANDLER (msx_kanji_w)
1214{
1215   msx_state *state = space->machine().driver_data<msx_state>();
1216   if (offset)
1217   {
1218      state->m_kanji_latch =
1219            (state->m_kanji_latch & 0x007E0) | ((data & 0x3f) << 11);
1220   }
1221   else
1222   {
1223      state->m_kanji_latch =
1224            (state->m_kanji_latch & 0x1f800) | ((data & 0x3f) << 5);
1225   }
1226}
src/mame/machine/nes_mmc.c
r0r11461
1/*****************************************************************************************
2
3    NES MMC Emulation
4
5
6    MESS source file to handle various Multi-Memory Controllers (aka Mappers) used by NES carts.
7
8    Many information about the mappers below come from the wonderful doc written by Disch.
9    Current info (when used) are based on v0.6.1 of his docs.
10    You can find the latest version of the doc at http://www.romhacking.net/docs/362/
11
12
13    Missing components:
14    * Currently, we are not emulating 4-screen mirroring (only 3 games use it)
15    * We need a better way to implement CPU cycle based IRQ. Currently we update their counter once every scanline
16      but, with this approach, every time 114 clocks have passed and for certain games it is too much!
17    * We need to emulate additional sound hardware in mappers 019, 024, 026, 069, 085 (and possibly other ones)
18    * We need to emulate EEPROM in mapper 016 and 159
19    * Barcode World (mapper 069) and Datach games (mapper 157) need Barcode Reader emulation
20      Notice that for mapper 157, the barcode reader enters in the irq, so glitches may be related to this!
21    * Karaoke Studio (mapper 188) misses input devices
22
23    Known issues on specific mappers:
24
25    * 000 F1 Race requires more precise PPU timing. It currently has plenty of 1-line glitches.
26    * 001 Yoshi flashes in-game. Back to the Future have heavily corrupted graphics (since forever).
27    * 001 SOROM boards do not properly handle the two WRAM/Battery banks
28    * 002, 003, 094, 097, 152 Bus conflict?
29    * 003 Firehouse Rescue has flashing graphics
30    * 004 Mendel Palace has never worked properly
31    * 004 Ninja Gaiden 2 has flashing bg graphics in the second level
32    * 005 has issues (see e.g. Just Breed or Metal Slader Glory), RAM banking needs hardware flags to determine size
33    * 007 Marble Madness has small graphics corruptions
34    * 014 in-game graphics is glitched
35    * 015 Shanghai Tycoon has corrupted graphics
36    * 033 has still some graphics problem (e.g. missing text in Akira)
37    * 034 Impossible Mission II does not show graphics
38    * 038 seems to miss inputs. separate reads?
39    * 042 Ai Senshi Nicol has broken graphics (our Mapper 42 implementation does not handle CHR banks)
40    * 048 Don Doko Don 2 freezes when you reach the first boss
41    * 051 only half of the games work
42    * 064 has many IRQ problems (due to the way we implement CPU based IRQ) - see Skull & Crossbones.
43          Klax has problems as well (even if it uses scanline based IRQ, according to Disch's docs).
44    * 067 some 1-line glitches that cannot be solved without a better implementation for cycle-based IRQs
45    * 071 Fire Hawk is flashing all the times.
46    * 072, 086, 092 lack samples support (maybe others as well)
47    * 073 16 bit IRQ mode is not implemented
48    * 077 Requires 4-screen mirroring. Currently, it is very glitchy
49    * 083 has serious glitches
50    * 088 Quinty has never worked properly
51    * 096 is preliminary (no correct chr switch in connection to PPU)
52    * 104 Not all the games work
53    * 107 Are the scrolling glitches (check status bar) correct? NEStopia behaves similarly
54    * 112 Master Shooter is not working and misses some graphics
55    * 117 In-game glitches
56    * 119 Pin Bot has glitches when the ball is in the upper half of the screen
57    * 133 Qi Wang starts with corrupted graphics (ingame seems better)
58    * 143 are Dancing Block borders (in the intro) correct?
59    * 158 In addition to IRQ problems (same as 64), mirroring was just a guess (wrong?). info needed!
60    * 164 preliminary - no sprites?
61    * 176 has some graphics problem
62    * 178 Fan Kong Jin Ying is not working (but not even in NEStopia)
63    * 180 Crazy Climber controller?
64    * 187, 198, 208, 215 have some PRG banking issues - preliminary!
65    * 188 needs mic input (reads from 0x6000-0x7fff)
66    * 197 Super Fighter 3 has some glitch in-game (maybe mirroring?)
67    * 222 is only preliminar (wrong IRQ, mirroring or CHR banking?)
68    * 225 115-in-1 has glitches in the menu (games seem fine)
69    * 229 is preliminary
70    * 230 not working yet (needs a value to flip at reset)
71    * 232 has graphics glitches
72    * 241 Commandos is not working (but not even in NEStopia)
73    * 242 In Dragon Quest VIII graphics of the main character is not drawn (it seems similar to Shanghai Tycoon [map15]
74          because in place of the missing graphics we get glitches in the left border)
75    * 249 only half of the games work (and Du Bao Ying Hao seems to suffer the same problem as DQ8 and Shanghai Tycoon)
76    * 255 does not really select game (same in NEStopia apparently)
77
78    A few Mappers suffer of hardware conflict: original dumpers have used the same mapper number for more than
79    a kind of boards. In these cases (and only in these cases) we exploit nes.hsi to set up accordingly
80    emulation. Games which requires this hack are the following:
81    * 032 - Major League needs hardwired mirroring (missing windows and glitched field in top view, otherwise)
82    * 034 - Impossible Mission II is not like BxROM games (it writes to 0x7ffd-0x7fff, instead of 0x8000). It is still
83          unplayable though (see above)
84    * 071 - Fire Hawk is different from other Camerica games (no hardwired mirroring). Without crc_hack no helicopter graphics
85    * 078 - Cosmo Carrier needs a different mirroring than Holy Diver
86    * 113 - HES 6-in-1 requires mirroring (check Bookyman playfield), while other games break with this (check AV Soccer)
87    * 153 - Famicom Jump II uses a different board (or the same in a very different way)
88    * 242 - DQ8 has no mirroring (missing graphics is due to other reasons though)
89
90    crc_hacks have been added also to handle a few wiring settings which would require submappers:
91    * CHR protection pins for mapper 185
92    * VRC-2, VRC-4 and VRC-6 line wiring
93
94    Known issues on specific UNIF boards:
95    * BMC-GS2004 is not working
96    * BMC-GS2013 is not working
97    * BMC-WS some games have corrupted graphics (e.g. Galaxian)
98    * UNL-8237 is not working
99    * UNL-KOF97 is not working
100
101    Details to investigate:
102    * 034 writes to 0x8000-0xffff should not be used for NINA-001 and BNROM, only unlicensed BxROM...
103    * 144 we ignore writes to 0x8000 while NEStopia does not. is it a problem?
104    * 240 we do not map writes to 0x4020-0x40ff. is this a problem?
105    * some other emus uses mapper 210 for mapper 019 games without additional sound hardware and mirroring capabilities
106      (in 210 mirroring is hardwired). However, simply initializing mirroring to Vertical in 019 seems to fix all glitches
107      in 210 games, so there seems to be no reason to have this duplicate mapper
108
109    Some mappers copy PRG rom in SRAM region. Below is a list of those which does it (in MESS) to further
110    investigate if we are supporting them in the right way (e.g. do any of the following have conflicts with SRAM?):
111    * 065 (Gimmick! breaks badly without it)
112    * 040, 042, 050
113
114    Remember that the MMC # does not equal the mapper #. In particular, Mapper 4 is
115    in fact MMC3, Mapper 9 is MMC2 and Mapper 10 is MMC4. Makes perfect sense, right?
116
117    TODO:
118    - add more info
119    - add missing mappers
120
121****************************************************************************************/
122
123#include "emu.h"
124#include "cpu/m6502/m6502.h"
125#include "video/ppu2c0x.h"
126#include "includes/nes.h"
127#include "nes_mmc.h"
128#include "sound/nes_apu.h"
129
130#ifdef MAME_DEBUG
131#define VERBOSE 1
132#else
133#define VERBOSE 0
134#endif
135
136#define LOG_MMC(x) do { if (VERBOSE) logerror x; } while (0)
137#define LOG_FDS(x) do { if (VERBOSE) logerror x; } while (0)
138
139static void ffe_irq( device_t *device, int scanline, int vblank, int blanked );
140static WRITE8_HANDLER( mapper6_l_w );
141static WRITE8_HANDLER( mapper6_w );
142static WRITE8_HANDLER( mapper8_w );
143static WRITE8_HANDLER( mapper17_l_w );
144
145/*************************************************************
146
147    Base emulation (see drivers/nes.c):
148    memory 0x0000-0x1fff RAM
149           0x2000-0x3fff PPU
150           0x4000-0x4017 APU
151           0x4018-0x5fff Expansion Area
152           0x6000-0x7fff PRG RAM
153           0x8000-0xffff PRG ROM
154
155    nes_chr_r/w take care of RAM, nes_nt_r/w take care of PPU.
156    for mapper specific emulation, we generically setup the
157    following handlers:
158    - nes_low_mapper_r/w take care of accesses to 0x4100-0x5fff
159      (calling state->m_mmc_write_low/state->m_mmc_read_low)
160    - state->m_mmc_write/read_mid take care of 0x6000-0x7fff
161    - state->m_mmc_write/read take care of access to 0x8000-0xffff
162      (most mappers only writes in this area)
163    some mappers may access 0x4018-0x4100: this must be taken
164    care separately in init_nes_core
165
166*************************************************************/
167
168WRITE8_HANDLER( nes_chr_w )
169{
170   nes_state *state = space->machine().driver_data<nes_state>();
171   int bank = offset >> 10;
172
173   if (state->m_chr_map[bank].source == CHRRAM)
174   {
175      state->m_chr_map[bank].access[offset & 0x3ff] = data;
176   }
177}
178
179READ8_HANDLER( nes_chr_r )
180{
181   nes_state *state = space->machine().driver_data<nes_state>();
182   int bank = offset >> 10;
183
184   // a few CNROM boards contained copy protection schemes through
185   // suitably configured diodes, so that subsequent CHR reads can
186   // give actual VROM content or open bus values.
187   // For most boards, chr_open_bus remains always zero.
188   if (state->m_chr_open_bus)
189      return 0xff;
190
191   return state->m_chr_map[bank].access[offset & 0x3ff];
192}
193
194WRITE8_HANDLER( nes_nt_w )
195{
196   nes_state *state = space->machine().driver_data<nes_state>();
197   int page = ((offset & 0xc00) >> 10);
198
199   if (state->m_nt_page[page].writable == 0)
200      return;
201
202   state->m_nt_page[page].access[offset & 0x3ff] = data;
203}
204
205READ8_HANDLER( nes_nt_r )
206{
207   nes_state *state = space->machine().driver_data<nes_state>();
208   int page = ((offset & 0xc00) >> 10);
209
210   if (state->m_nt_page[page].source == MMC5FILL)
211   {
212      if ((offset & 0x3ff) >= 0x3c0)
213         return state->m_MMC5_floodattr;
214
215      return state->m_MMC5_floodtile;
216   }
217   return state->m_nt_page[page].access[offset & 0x3ff];
218}
219
220WRITE8_HANDLER( nes_low_mapper_w )
221{
222   nes_state *state = space->machine().driver_data<nes_state>();
223
224   if (state->m_mmc_write_low)
225      (*state->m_mmc_write_low)(space, offset, data);
226   else
227      logerror("Unimplemented LOW mapper write, offset: %04x, data: %02x\n", offset + 0x4100, data);
228}
229
230READ8_HANDLER( nes_low_mapper_r )
231{
232   nes_state *state = space->machine().driver_data<nes_state>();
233
234   if (state->m_mmc_read_low)
235      return (*state->m_mmc_read_low)(space, offset);
236   else
237      logerror("Unimplemented LOW mapper read, offset: %04x\n", offset + 0x4100);
238
239   return 0;
240}
241
242/*************************************************************
243
244    Helpers to handle MMC
245
246*************************************************************/
247
248static void wram_bank( running_machine &machine, int bank, int source )
249{
250   nes_state *state = machine.driver_data<nes_state>();
251
252   assert(state->m_battery || state->m_prg_ram);
253   if (source == NES_BATTERY)
254   {
255      bank &= (state->m_battery_size / 0x2000) - 1;
256      state->m_prg_bank[4] = state->m_battery_bank5_start + bank;
257   }
258   else
259   {
260      bank &= (state->m_wram_size / 0x2000) - 1;
261      state->m_prg_bank[4] = state->m_prgram_bank5_start + bank;
262   }
263   memory_set_bank(machine, "bank5", state->m_prg_bank[4]);
264}
265
266INLINE void prg_bank_refresh( running_machine &machine )
267{
268   nes_state *state = machine.driver_data<nes_state>();
269   memory_set_bank(machine, "bank1", state->m_prg_bank[0]);
270   memory_set_bank(machine, "bank2", state->m_prg_bank[1]);
271   memory_set_bank(machine, "bank3", state->m_prg_bank[2]);
272   memory_set_bank(machine, "bank4", state->m_prg_bank[3]);
273}
274
275/* PRG ROM in 8K, 16K or 32K blocks */
276
277static void prg32( running_machine &machine, int bank )
278{
279   nes_state *state = machine.driver_data<nes_state>();
280
281   /* if there is only 16k PRG, return */
282   if (!(state->m_prg_chunks >> 1))
283      return;
284
285   /* assumes that bank references a 32k chunk */
286   bank &= ((state->m_prg_chunks >> 1) - 1);
287
288   state->m_prg_bank[0] = bank * 4 + 0;
289   state->m_prg_bank[1] = bank * 4 + 1;
290   state->m_prg_bank[2] = bank * 4 + 2;
291   state->m_prg_bank[3] = bank * 4 + 3;
292   prg_bank_refresh(machine);
293}
294
295static void prg16_89ab( running_machine &machine, int bank )
296{
297   nes_state *state = machine.driver_data<nes_state>();
298
299   /* assumes that bank references a 16k chunk */
300   bank &= (state->m_prg_chunks - 1);
301
302   state->m_prg_bank[0] = bank * 2 + 0;
303   state->m_prg_bank[1] = bank * 2 + 1;
304   prg_bank_refresh(machine);
305}
306
307static void prg16_cdef( running_machine &machine, int bank )
308{
309   nes_state *state = machine.driver_data<nes_state>();
310
311   /* assumes that bank references a 16k chunk */
312   bank &= (state->m_prg_chunks - 1);
313
314   state->m_prg_bank[2] = bank * 2 + 0;
315   state->m_prg_bank[3] = bank * 2 + 1;
316   prg_bank_refresh(machine);
317}
318
319static void prg8_89( running_machine &machine, int bank )
320{
321   nes_state *state = machine.driver_data<nes_state>();
322
323   /* assumes that bank references an 8k chunk */
324   bank &= ((state->m_prg_chunks << 1) - 1);
325
326   state->m_prg_bank[0] = bank;
327   prg_bank_refresh(machine);
328}
329
330static void prg8_ab( running_machine &machine, int bank )
331{
332   nes_state *state = machine.driver_data<nes_state>();
333
334   /* assumes that bank references an 8k chunk */
335   bank &= ((state->m_prg_chunks << 1) - 1);
336
337   state->m_prg_bank[1] = bank;
338   prg_bank_refresh(machine);
339}
340
341static void prg8_cd( running_machine &machine, int bank )
342{
343   nes_state *state = machine.driver_data<nes_state>();
344
345   /* assumes that bank references an 8k chunk */
346   bank &= ((state->m_prg_chunks << 1) - 1);
347
348   state->m_prg_bank[2] = bank;
349   prg_bank_refresh(machine);
350}
351
352static void prg8_ef( running_machine &machine, int bank )
353{
354   nes_state *state = machine.driver_data<nes_state>();
355
356   /* assumes that bank references an 8k chunk */
357   bank &= ((state->m_prg_chunks << 1) - 1);
358
359   state->m_prg_bank[3] = bank;
360   prg_bank_refresh(machine);
361}
362
363/* We define an additional helper to map PRG-ROM to 0x6000-0x7000 */
364// TODO: are we implementing this correctly in the mappers which uses it? check!
365
366static void prg8_67( running_machine &machine, int bank )
367{
368   nes_state *state = machine.driver_data<nes_state>();
369
370   /* assumes that bank references an 8k chunk */
371   bank &= ((state->m_prg_chunks << 1) - 1);
372
373   state->m_prg_bank[4] = bank;
374   memory_set_bank(machine, "bank5", state->m_prg_bank[4]);
375}
376
377/* We also define an additional helper to map 8k PRG-ROM to one of the banks (passed as parameter) */
378static void prg8_x( running_machine &machine, int start, int bank )
379{
380   nes_state *state = machine.driver_data<nes_state>();
381
382   assert(start < 4);
383
384   /* assumes that bank references an 8k chunk */
385   bank &= ((state->m_prg_chunks << 1) - 1);
386
387   state->m_prg_bank[start] = bank;
388   prg_bank_refresh(machine);
389}
390
391/* CHR ROM in 1K, 2K, 4K or 8K blocks */
392
393// this can be probably removed later, but it is useful while testing xml and unf handling with VRAM & VROM
394INLINE void chr_sanity_check( running_machine &machine, int source )
395{
396   nes_state *state = machine.driver_data<nes_state>();
397
398   if (source == CHRRAM && state->m_vram == NULL)
399      fatalerror("CHRRAM bankswitch with no VRAM");
400
401   if (source == CHRROM && state->m_vrom == NULL)
402      fatalerror("CHRROM bankswitch with no VROM");
403}
404
405static void chr8( running_machine &machine, int bank, int source )
406{
407   nes_state *state = machine.driver_data<nes_state>();
408   int i;
409
410   chr_sanity_check(machine, source);
411
412   if (source == CHRRAM)
413   {
414      bank &= (state->m_vram_chunks - 1);
415      for (i = 0; i < 8; i++)
416      {
417         state->m_chr_map[i].source = source;
418         state->m_chr_map[i].origin = (bank * 0x2000) + (i * 0x400); // for save state uses!
419         state->m_chr_map[i].access = &state->m_vram[state->m_chr_map[i].origin];
420      }
421   }
422   else
423   {
424      bank &= (state->m_chr_chunks - 1);
425      for (i = 0; i < 8; i++)
426      {
427         state->m_chr_map[i].source = source;
428         state->m_chr_map[i].origin = (bank * 0x2000) + (i * 0x400); // for save state uses!
429         state->m_chr_map[i].access = &state->m_vrom[state->m_chr_map[i].origin];
430      }
431   }
432}
433
434static void chr4_x( running_machine &machine, int start, int bank, int source )
435{
436   nes_state *state = machine.driver_data<nes_state>();
437   int i;
438
439   chr_sanity_check(machine, source);
440
441   if (source == CHRRAM)
442   {
443      bank &= ((state->m_vram_chunks << 1) - 1);
444      for (i = 0; i < 4; i++)
445      {
446         state->m_chr_map[i + start].source = source;
447         state->m_chr_map[i + start].origin = (bank * 0x1000) + (i * 0x400); // for save state uses!
448         state->m_chr_map[i + start].access = &state->m_vram[state->m_chr_map[i + start].origin];
449      }
450   }
451   else
452   {
453      bank &= ((state->m_chr_chunks << 1) - 1);
454      for (i = 0; i < 4; i++)
455      {
456         state->m_chr_map[i + start].source = source;
457         state->m_chr_map[i + start].origin = (bank * 0x1000) + (i * 0x400); // for save state uses!
458         state->m_chr_map[i + start].access = &state->m_vrom[state->m_chr_map[i + start].origin];
459      }
460   }
461}
462
463static void chr4_0( running_machine &machine, int bank, int source )
464{
465   chr4_x(machine, 0, bank, source);
466}
467
468static void chr4_4( running_machine &machine, int bank, int source )
469{
470   chr4_x(machine, 4, bank, source);
471}
472
473static void chr2_x( running_machine &machine, int start, int bank, int source )
474{
475   nes_state *state = machine.driver_data<nes_state>();
476   int i;
477
478   chr_sanity_check(machine, source);
479
480   if (source == CHRRAM)
481   {
482      bank &= ((state->m_vram_chunks << 2) - 1);
483      for (i = 0; i < 2; i++)
484      {
485         state->m_chr_map[i + start].source = source;
486         state->m_chr_map[i + start].origin = (bank * 0x800) + (i * 0x400); // for save state uses!
487         state->m_chr_map[i + start].access = &state->m_vram[state->m_chr_map[i + start].origin];
488      }
489   }
490   else
491   {
492      bank &= ((state->m_chr_chunks << 2) - 1);
493      for (i = 0; i < 2; i++)
494      {
495         state->m_chr_map[i + start].source = source;
496         state->m_chr_map[i + start].origin = (bank * 0x800) + (i * 0x400); // for save state uses!
497         state->m_chr_map[i + start].access = &state->m_vrom[state->m_chr_map[i + start].origin];
498      }
499   }
500}
501
502static void chr2_0( running_machine &machine, int bank, int source )
503{
504   chr2_x(machine, 0, bank, source);
505}
506
507static void chr2_2( running_machine &machine, int bank, int source )
508{
509   chr2_x(machine, 2, bank, source);
510}
511
512static void chr2_4( running_machine &machine, int bank, int source )
513{
514   chr2_x(machine, 4, bank, source);
515}
516
517static void chr2_6( running_machine &machine, int bank, int source )
518{
519   chr2_x(machine, 6, bank, source);
520}
521
522static void chr1_x( running_machine &machine, int start, int bank, int source )
523{
524   nes_state *state = machine.driver_data<nes_state>();
525
526   chr_sanity_check(machine, source);
527
528   if (source == CHRRAM)
529   {
530      bank &= ((state->m_vram_chunks << 3) - 1);
531      state->m_chr_map[start].source = source;
532      state->m_chr_map[start].origin = (bank * 0x400); // for save state uses!
533      state->m_chr_map[start].access = &state->m_vram[state->m_chr_map[start].origin];
534   }
535   else
536   {
537      bank &= ((state->m_chr_chunks << 3) - 1);
538      state->m_chr_map[start].source = source;
539      state->m_chr_map[start].origin = (bank * 0x400); // for save state uses!
540      state->m_chr_map[start].access = &state->m_vrom[state->m_chr_map[start].origin];
541   }
542}
543
544static void chr1_0 (running_machine &machine, int bank, int source)
545{
546   chr1_x(machine, 0, bank, source);
547}
548
549static void chr1_1( running_machine &machine, int bank, int source )
550{
551   chr1_x(machine, 1, bank, source);
552}
553
554static void chr1_2( running_machine &machine, int bank, int source )
555{
556   chr1_x(machine, 2, bank, source);
557}
558
559static void chr1_3( running_machine &machine, int bank, int source )
560{
561   chr1_x(machine, 3, bank, source);
562}
563
564static void chr1_4( running_machine &machine, int bank, int source )
565{
566   chr1_x(machine, 4, bank, source);
567}
568
569static void chr1_5( running_machine &machine, int bank, int source )
570{
571   chr1_x(machine, 5, bank, source);
572}
573
574static void chr1_6( running_machine &machine, int bank, int source )
575{
576   chr1_x(machine, 6, bank, source);
577}
578
579static void chr1_7( running_machine &machine, int bank, int source )
580{
581   chr1_x(machine, 7, bank, source);
582}
583
584
585/* NameTable paging and mirroring */
586
587static void set_nt_page( running_machine &machine, int page, int source, int bank, int writable )
588{
589   nes_state *state = machine.driver_data<nes_state>();
590   UINT8* base_ptr;
591
592   switch (source)
593   {
594      case CART_NTRAM:
595         base_ptr = state->m_extended_ntram;
596         break;
597      case MMC5FILL:
598         base_ptr = NULL;
599         break;
600      case ROM:
601         base_ptr = state->m_vrom;
602         break;
603      case EXRAM:
604         base_ptr = state->m_mapper_ram;
605         break;
606      case CIRAM:
607      default:
608         base_ptr = state->m_ciram;
609         break;
610   }
611
612   page &= 3; /* mask down to the 4 logical pages */
613   state->m_nt_page[page].source = source;
614
615   if (base_ptr != NULL)
616   {
617      state->m_nt_page[page].origin = bank * 0x400;
618      state->m_nt_page[page].access = base_ptr + state->m_nt_page[page].origin;
619   }
620
621   state->m_nt_page[page].writable = writable;
622}
623
624void set_nt_mirroring( running_machine &machine, int mirroring )
625{
626   /* setup our videomem handlers based on mirroring */
627   switch (mirroring)
628   {
629      case PPU_MIRROR_VERT:
630         set_nt_page(machine, 0, CIRAM, 0, 1);
631         set_nt_page(machine, 1, CIRAM, 1, 1);
632         set_nt_page(machine, 2, CIRAM, 0, 1);
633         set_nt_page(machine, 3, CIRAM, 1, 1);
634         break;
635
636      case PPU_MIRROR_HORZ:
637         set_nt_page(machine, 0, CIRAM, 0, 1);
638         set_nt_page(machine, 1, CIRAM, 0, 1);
639         set_nt_page(machine, 2, CIRAM, 1, 1);
640         set_nt_page(machine, 3, CIRAM, 1, 1);
641         break;
642
643      case PPU_MIRROR_HIGH:
644         set_nt_page(machine, 0, CIRAM, 1, 1);
645         set_nt_page(machine, 1, CIRAM, 1, 1);
646         set_nt_page(machine, 2, CIRAM, 1, 1);
647         set_nt_page(machine, 3, CIRAM, 1, 1);
648         break;
649
650      case PPU_MIRROR_LOW:
651         set_nt_page(machine, 0, CIRAM, 0, 1);
652         set_nt_page(machine, 1, CIRAM, 0, 1);
653         set_nt_page(machine, 2, CIRAM, 0, 1);
654         set_nt_page(machine, 3, CIRAM, 0, 1);
655         break;
656
657      case PPU_MIRROR_NONE:
658      case PPU_MIRROR_4SCREEN:
659      default:
660         /* external RAM needs to be used somehow. */
661         /* but as a default, we'll arbitrarily set vertical so as not to crash*/
662         /* mappers should use set_nt_page and assign which pages are which */
663
664         logerror("Mapper set 4-screen mirroring without supplying external nametable memory!\n");
665
666         set_nt_page(machine, 0, CIRAM, 0, 1);
667         set_nt_page(machine, 1, CIRAM, 0, 1);
668         set_nt_page(machine, 2, CIRAM, 1, 1);
669         set_nt_page(machine, 3, CIRAM, 1, 1);
670         break;
671   }
672}
673
674/*  Other custom mirroring helpers are defined below: Waixing games use waixing_set_mirror (which swaps
675    MIRROR_HIGH and MIRROR_LOW compared to the above) and Sachen games use sachen_set_mirror (which has
676    a slightly different MIRROR_HIGH, with page 0 set to 0) */
677
678
679/*************************************************************
680
681 Support for xml list
682
683 *************************************************************/
684
685/* Include emulation of NES PCBs for softlist */
686#include "machine/nes_pcb.c"
687
688
689/*************************************************************
690
691    Support for .unf Files
692
693*************************************************************/
694
695/* Include emulation of UNIF Boards for .unf files */
696#include "machine/nes_unif.c"
697
698
699/*************************************************************
700
701 Support for .nes Files
702
703 *************************************************************/
704
705/* Include emulation of iNES Mappers for .nes files */
706#include "machine/nes_ines.c"
707
src/mame/machine/nes_mmc.h
r0r11461
1#ifndef __MMC_H
2#define __MMC_H
3
4/* Boards */
5enum
6{
7   STD_NROM = 0,
8   STD_AXROM, STD_BXROM, STD_CNROM, STD_CPROM,
9   STD_DXROM, STD_EXROM, STD_FXROM, STD_GXROM,
10   STD_HKROM, STD_JXROM, STD_MXROM, STD_NXROM,
11   STD_PXROM, STD_SXROM, STD_TXROM, STD_TXSROM,
12   STD_TKROM, STD_TQROM, STD_TVROM,
13   STD_UN1ROM, STD_UXROM,
14   HVC_FAMBASIC, NES_QJ, PAL_ZZ, UXROM_CC,
15   STD_DRROM, STD_SXROM_A, STD_SOROM, STD_SOROM_A,
16   /* Discrete components boards (by various manufacturer) */
17   DIS_74X161X138, DIS_74X139X74,
18   DIS_74X377, DIS_74X161X161X32,
19   /* Active Enterprises */
20   ACTENT_ACT52,
21   /* AGCI */
22   AGCI_50282,
23   /* AVE */
24   AVE_NINA01, AVE_NINA06,
25   /* Bandai */
26   BANDAI_JUMP2, BANDAI_PT554,
27   BANDAI_DATACH, BANDAI_KARAOKE, BANDAI_OEKAKIDS,
28   BANDAI_FCG, BANDAI_LZ93, BANDAI_LZ93EX,
29   /* Caltron */
30   CALTRON_6IN1,
31   /* Camerica */
32   CAMERICA_BF9093, CAMERICA_BF9097, CAMERICA_BF9096,
33   CAMERICA_GOLDENFIVE, GG_NROM,
34   /* Dreamtech */
35   DREAMTECH_BOARD,
36   /* Irem */
37   IREM_G101, IREM_H3001, IREM_LROG017,
38   IREM_TAM_S1, IREM_HOLYDIV,
39   /* Jaleco */
40   JALECO_SS88006, JALECO_JF11, JALECO_JF13,
41   JALECO_JF16, JALECO_JF17, JALECO_JF19,
42   /* Konami */
43   KONAMI_VRC1, KONAMI_VRC2, KONAMI_VRC3,
44   KONAMI_VRC4, KONAMI_VRC6, KONAMI_VRC7,
45   /* Namcot */
46   NAMCOT_163, NAMCOT_3453,
47   NAMCOT_3425, NAMCOT_34X3, NAMCOT_3446,
48   /* NTDEC */
49   NTDEC_ASDER, NTDEC_FIGHTINGHERO,
50   /* Rex Soft */
51   REXSOFT_SL1632, REXSOFT_DBZ5,
52   /* Sachen */
53   SACHEN_8259A, SACHEN_8259B, SACHEN_8259C, SACHEN_8259D,
54   SACHEN_SA009, SACHEN_SA0036, SACHEN_SA0037,
55   SACHEN_SA72007, SACHEN_SA72008, SACHEN_TCA01,
56   SACHEN_TCU01, SACHEN_TCU02,
57   SACHEN_74LS374, SACHEN_74LS374_A,
58   /* Sunsoft */
59   SUNSOFT_1, SUNSOFT_2, SUNSOFT_3, SUNSOFT_4,
60   SUNSOFT_DCS, SUNSOFT_5B, SUNSOFT_FME7,
61   /* Taito */
62   TAITO_TC0190FMC, TAITO_TC0190FMCP,
63   TAITO_X1_005, TAITO_X1_005_A, TAITO_X1_017,
64   /* Tengen */
65   TENGEN_800008, TENGEN_800032, TENGEN_800037,
66   /* TXC */
67   TXC_22211A, TXC_22211B, TXC_22211C,
68   TXC_MXMDHTWO, TXC_TW, TXC_STRIKEWOLF,
69   /* Multigame Carts */
70   BMC_64IN1NR, BMC_190IN1, BMC_A65AS, BMC_GS2004, BMC_GS2013,
71   BMC_HIK8IN1, BMC_NOVELDIAMOND, BMC_S24IN1SC03, BMC_T262,
72   BMC_WS, BMC_SUPERBIG_7IN1, BMC_SUPERHIK_4IN1, BMC_BALLGAMES_11IN1,
73   BMC_MARIOPARTY_7IN1, BMC_SUPER_700IN1, BMC_FAMILY_4646B,
74   BMC_36IN1, BMC_21IN1, BMC_150IN1, BMC_35IN1, BMC_64IN1,
75   BMC_15IN1, BMC_SUPERHIK_300IN1, BMC_9999999IN1, BMC_SUPERGUN_20IN1,
76   BMC_GOLDENCARD_6IN1, BMC_72IN1, BMC_SUPER_42IN1, BMC_76IN1,
77   BMC_1200IN1, BMC_31IN1, BMC_22GAMES, BMC_20IN1, BMC_110IN1,
78   BMC_GKA, BMC_GKB, BMC_VT5201, BMC_BENSHENG_BS5, BMC_810544,
79   BMC_NTD_03, BMC_G63IN1, BMC_FK23C, BMC_FK23CA, BMC_PJOY84,
80   /* Unlicensed */
81   UNL_8237, UNL_CC21, UNL_AX5705, UNL_KOF97,
82   UNL_N625092, UNL_SC127, UNL_SMB2J, UNL_T230,
83   UNL_UXROM, UNL_MK2, UNL_XZY, UNL_KOF96,
84   UNL_SUPERFIGHTER3, UNL_RACERMATE, UNL_EDU2K,
85   UNL_SHJY3, UNL_STUDYNGAME, UNL_603_5052, UNL_H2288,
86   /* Bootleg boards */
87   BTL_SMB2A, BTL_MARIOBABY, BTL_AISENSHINICOL, BTL_TOBIDASE,
88   BTL_SMB2B, BTL_SMB3, BTL_SUPERBROS11, BTL_DRAGONNINJA,
89   BTL_PIKACHUY2K,
90   /* Misc: these are needed to convert mappers to boards, I will sort them later */
91   OPENCORP_DAOU306, HES_BOARD, HES6IN1_BOARD, RUMBLESTATION_BOARD,
92   MAGICSERIES_MD, KASING_BOARD, FUTUREMEDIA_BOARD, FUKUTAKE_BOARD, SOMERI_SL12,
93   HENGEDIANZI_BOARD, HENGEDIANZI_XJZB, SUBOR_TYPE0, SUBOR_TYPE1,
94   KAISER_KS7058, KAISER_KS7032, KAISER_KS7022, KAISER_KS7017, KAISER_KS202, CONY_BOARD,
95   CNE_DECATHLON, CNE_FSB, CNE_SHLZ, RCM_GS2015, RCM_TETRISFAMILY,
96   WAIXING_TYPE_A, WAIXING_TYPE_A_1, WAIXING_TYPE_B, WAIXING_TYPE_C, WAIXING_TYPE_D,
97   WAIXING_TYPE_E, WAIXING_TYPE_F, WAIXING_TYPE_G, WAIXING_TYPE_H,
98   WAIXING_TYPE_I, WAIXING_TYPE_J,
99   WAIXING_SGZLZ, WAIXING_SGZ, WAIXING_ZS, WAIXING_SECURITY, WAIXING_SH2,
100   WAIXING_DQ8, WAIXING_FFV, WAIXING_PS2, SUPERGAME_LIONKING, SUPERGAME_BOOGERMAN,
101   KAY_PANDAPRINCE, HOSENKAN_BOARD, NITRA_TDA, GOUDER_37017, NANJING_BOARD,
102   WHIRLWIND_2706,
103   /* FFE boards, for mappers 6, 8, 17 */
104   FFE_MAPPER6, FFE_MAPPER8, FFE_MAPPER17,
105   /* Unsupported (for place-holder boards, with no working emulation) & no-board (at init) */
106   UNSUPPORTED_BOARD, UNKNOWN_BOARD, NO_BOARD
107};
108
109// these are used to setup the proper PCB ID, for each supported type of files
110int nes_get_pcb_id(running_machine &machine, const char *feature);   // for softlist
111void unif_mapr_setup(running_machine &machine, const char *board);   // for UNIF files
112int nes_get_mmc_id(running_machine &machine, int mapper);   // for iNES files
113
114// these are used to setup handlers and callbacks necessary to the emulation (resp. at start and reset)
115void pcb_handlers_setup(running_machine &machine);
116int nes_pcb_reset(running_machine &machine);
117
118
119WRITE8_HANDLER( nes_low_mapper_w );
120READ8_HANDLER( nes_low_mapper_r );
121WRITE8_HANDLER( nes_chr_w );
122READ8_HANDLER( nes_chr_r );
123WRITE8_HANDLER( nes_nt_w );
124READ8_HANDLER( nes_nt_r );
125
126WRITE8_HANDLER( smb2jb_extra_w );
127WRITE8_HANDLER( ks7017_extra_w );
128READ8_HANDLER( ks7017_extra_r );
129WRITE8_HANDLER( unl_6035052_extra_w );
130READ8_HANDLER( unl_6035052_extra_r );
131READ8_HANDLER( waixing_sh2_chr_r );
132
133//TEMPORARY PPU STUFF
134
135/* mirroring types */
136#define PPU_MIRROR_NONE      0
137#define PPU_MIRROR_VERT      1
138#define PPU_MIRROR_HORZ      2
139#define PPU_MIRROR_HIGH      3
140#define PPU_MIRROR_LOW      4
141#define PPU_MIRROR_4SCREEN   5   // Same effect as NONE, but signals that we should never mirror
142
143void set_nt_mirroring(running_machine &machine, int mirroring);
144
145
146#endif
src/mame/machine/nes_ines.c
r0r11461
1/*****************************************************************************************
2
3    NES MMC Emulation
4
5    Support for iNES Mappers
6
7****************************************************************************************/
8
9typedef struct _nes_mmc  nes_mmc;
10struct _nes_mmc
11{
12   int    iNesMapper; /* iNES Mapper # */
13   int    pcb_id;
14};
15
16/*************************************************************
17
18    Mapper 6
19
20    Known Boards: FFE4 Copier Board
21    Games: Hacked versions of games
22
23    In MESS: Supported? Not sure if we could also have ExRAM or not...
24       However, priority is pretty low for this mapper.
25
26*************************************************************/
27
28/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
29we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
30there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
31static void ffe_irq( device_t *device, int scanline, int vblank, int blanked )
32{
33   nes_state *state = device->machine().driver_data<nes_state>();
34
35   /* 114 is the number of cycles per scanline */
36   /* TODO: change to reflect the actual number of cycles spent */
37   if (state->m_IRQ_enable)
38   {
39      if ((0xffff - state->m_IRQ_count) < 114)
40      {
41         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
42         state->m_IRQ_count = 0xffff;
43         state->m_IRQ_enable = 0;
44      }
45      state->m_IRQ_count -= 114;
46   }
47}
48
49static WRITE8_HANDLER( mapper6_l_w )
50{
51   nes_state *state = space->machine().driver_data<nes_state>();
52   LOG_MMC(("mapper6_l_w, offset: %04x, data: %02x\n", offset, data));
53
54   switch (offset)
55   {
56      case 0x1fe:
57         state->m_mmc_latch1 = data & 0x80;
58         set_nt_mirroring(space->machine(), BIT(data, 4) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
59         break;
60      case 0x1ff:
61         set_nt_mirroring(space->machine(), BIT(data, 4) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
62         break;
63
64      case 0x401:
65         state->m_IRQ_enable = data & 0x01;
66         break;
67      case 0x402:
68         state->m_IRQ_count = (state->m_IRQ_count & 0xff00) | data;
69         break;
70      case 0x403:
71         state->m_IRQ_enable = 1;
72         state->m_IRQ_count = (state->m_IRQ_count & 0x00ff) | (data << 8);
73         break;
74   }
75}
76
77static WRITE8_HANDLER( mapper6_w )
78{
79   nes_state *state = space->machine().driver_data<nes_state>();
80   LOG_MMC(("mapper6_w, offset: %04x, data: %02x\n", offset, data));
81
82   if (!state->m_mmc_latch1)   // when in "FFE mode" we are forced to use CHRRAM/EXRAM bank?
83   {
84      prg16_89ab(space->machine(), data >> 2);
85      // chr8(space->machine(), data & 0x03, ???);
86      // due to lack of info on the exact behavior, we simply act as if mmc_latch1=1
87      if (state->m_mmc_chr_source == CHRROM)
88         chr8(space->machine(), data & 0x03, CHRROM);
89   }
90   else if (state->m_mmc_chr_source == CHRROM)         // otherwise, we can use CHRROM (when present)
91      chr8(space->machine(), data, CHRROM);
92}
93
94/*************************************************************
95
96    Mapper 8
97
98    Known Boards: FFE3 Copier Board
99    Games: Hacked versions of games
100
101    In MESS: Supported? (I have no games to test this)
102
103*************************************************************/
104
105static WRITE8_HANDLER( mapper8_w )
106{
107   LOG_MMC(("mapper8_w, offset: %04x, data: %02x\n", offset, data));
108
109   chr8(space->machine(), data & 0x07, CHRROM);
110   prg16_89ab(space->machine(), data >> 3);
111}
112
113/*************************************************************
114
115    Mapper 17
116
117    Known Boards: FFE8 Copier Board
118    Games: Hacked versions of games
119
120    In MESS: Supported?. IRQ support is just a guess (used to
121      use MMC3 IRQ but it was wrong and it never enabled it)
122
123*************************************************************/
124
125static WRITE8_HANDLER( mapper17_l_w )
126{
127   nes_state *state = space->machine().driver_data<nes_state>();
128   LOG_MMC(("mapper17_l_w, offset: %04x, data: %02x\n", offset, data));
129
130   switch (offset)
131   {
132      case 0x1fe:
133         set_nt_mirroring(space->machine(), BIT(data, 4) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
134         break;
135      case 0x1ff:
136         set_nt_mirroring(space->machine(), BIT(data, 4) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
137         break;
138
139      case 0x401:
140         state->m_IRQ_enable = data & 0x01;
141         break;
142      case 0x402:
143         state->m_IRQ_count = (state->m_IRQ_count & 0xff00) | data;
144         break;
145      case 0x403:
146         state->m_IRQ_enable = 1;
147         state->m_IRQ_count = (state->m_IRQ_count & 0x00ff) | (data << 8);
148         break;
149
150      case 0x404:
151         prg8_89(space->machine(), data);
152         break;
153      case 0x405:
154         prg8_ab(space->machine(), data);
155         break;
156      case 0x406:
157         prg8_cd(space->machine(), data);
158         break;
159      case 0x407:
160         prg8_ef(space->machine(), data);
161         break;
162
163      case 0x410:
164      case 0x411:
165      case 0x412:
166      case 0x413:
167      case 0x414:
168      case 0x415:
169      case 0x416:
170      case 0x417:
171         chr1_x(space->machine(), offset & 7, data, CHRROM);
172         break;
173   }
174}
175
176/*************************************************************
177
178    mmc_list
179
180    Supported mappers and corresponding pcb id
181
182*************************************************************/
183
184static const nes_mmc mmc_list[] =
185{
186/*  INES   DESC                          LOW_W, LOW_R, MED_W, HIGH_W, PPU_latch, scanline CB, hblank CB */
187   {  0, STD_NROM },
188   {  1, STD_SXROM },
189   {  2, STD_UXROM },
190   {  3, STD_CNROM },
191   {  4, STD_TXROM },
192   {  5, STD_EXROM },
193   {  6, FFE_MAPPER6 },
194   {  7, STD_AXROM },
195   {  8, FFE_MAPPER8 },
196   {  9, STD_PXROM },
197   { 10, STD_FXROM },
198   { 11, DIS_74X377 },
199   { 12, REXSOFT_DBZ5 },
200   { 13, STD_CPROM },
201   { 14, REXSOFT_SL1632 },
202   { 15, WAIXING_PS2 },
203   { 16, BANDAI_LZ93EX },   // with 24c02
204   { 17, FFE_MAPPER17 },
205   { 18, JALECO_SS88006 },
206   { 19, NAMCOT_163 },
207   { 21, KONAMI_VRC4 },
208   { 22, KONAMI_VRC2 },
209   { 23, KONAMI_VRC2 },
210   { 24, KONAMI_VRC6 },
211   { 25, KONAMI_VRC4 },
212   { 26, KONAMI_VRC6 },
213   // 27 World Hero board - Unsupported
214   // 28 Unused
215   // 29 Unused
216   // 30 Unused
217   // 31 Unused
218   { 32, IREM_G101 },
219   { 33, TAITO_TC0190FMC },
220   { 34, STD_BXROM },
221   { 35, UNL_SC127 },
222   { 36, TXC_STRIKEWOLF },
223   { 37, PAL_ZZ },
224   { 38, DIS_74X161X138 },
225   { 39, UNL_STUDYNGAME },
226   { 40, BTL_SMB2A },
227   { 41, CALTRON_6IN1 },
228   { 42, BTL_MARIOBABY },   // ai senshi nicol?
229   { 43, UNL_SMB2J },
230   { 44, BMC_SUPERBIG_7IN1 },
231   { 45, BMC_HIK8IN1 },
232   { 46, RUMBLESTATION_BOARD },
233   { 47, NES_QJ },
234   { 48, TAITO_TC0190FMCP },
235   { 49, BMC_SUPERHIK_4IN1 },
236   { 50, BTL_SMB2B },
237   { 51, BMC_BALLGAMES_11IN1 },
238   { 52, BMC_MARIOPARTY_7IN1 },
239   // 53 Supervision 16-in-1 - Unsupported
240   { 54, BMC_NOVELDIAMOND },
241   // 55 Genius SMB - No info (nor images) available
242   { 56, KAISER_KS202 },
243   { 57, BMC_GKA },
244   { 58, BMC_GKB },
245   // 59 Unused
246   // 60 4-in-1, 35-in-1 Reset based
247   { 61, RCM_TETRISFAMILY },
248   { 62, BMC_SUPER_700IN1 },
249   // 63 CH001 X-in-1 - No info (nor images) available
250   { 64, TENGEN_800032 },
251   { 65, IREM_H3001 },
252   { 66, STD_GXROM },
253   { 67, SUNSOFT_3 },
254   { 68, STD_NXROM },
255   { 69, STD_JXROM },
256   { 70, DIS_74X161X161X32 },
257   { 71, CAMERICA_BF9093 },
258   { 72, JALECO_JF17 },
259   { 73, KONAMI_VRC3 },
260   { 74, WAIXING_TYPE_A },
261   { 75, KONAMI_VRC1 },
262   { 76, NAMCOT_3446 },
263   { 77, IREM_LROG017 },
264   { 78, IREM_HOLYDIV },
265   { 79, AVE_NINA06 },
266   { 80, TAITO_X1_005 },
267   // 81 Unused
268   { 82, TAITO_X1_017 },
269   { 83, CONY_BOARD },
270   // 84 Pasofami hacked images?
271   { 85, KONAMI_VRC7 },
272   { 86, JALECO_JF13 },
273   { 87, DIS_74X139X74 },
274   { 88, NAMCOT_34X3 },
275   { 89, SUNSOFT_2 },
276   // 90 JY Company Type A (Aladdin, Final Fight 3, Super Mario World, Tekken 2) - Unsupported
277   { 91, UNL_MK2 },
278   { 92, JALECO_JF19 },
279   { 93, SUNSOFT_2 },
280   { 94, STD_UN1ROM },
281   { 95, NAMCOT_3425 },
282   { 96, BANDAI_OEKAKIDS },
283   { 97, IREM_TAM_S1 },
284   // 98 Unused
285   // 99 VS. system - Not going to be implemented (use MAME instead)
286   // 100 images hacked to work with nesticle?
287   // 101 Unused (Urusei Yatsura had been assigned to this mapper, but it's Mapper 87)
288   // 102 Unused
289   // 103 Bootleg cart 2708 (Doki Doki Panic - FDS Conversion) - Unsupported
290   { 104, CAMERICA_GOLDENFIVE },
291   // 105 Nintendo World Championship - Unsupported
292   { 106, BTL_SMB3 },
293   { 107, MAGICSERIES_MD },
294   { 108, WHIRLWIND_2706 },
295   // 109 Unused
296   // 110 Unused
297   // 111 Ninja Ryuukenden Chinese? - Unsupported
298   { 112, NTDEC_ASDER },
299   { 113, HES_BOARD },
300   { 114, SUPERGAME_LIONKING },
301   { 115, KASING_BOARD },
302   { 116, SOMERI_SL12 },
303   { 117, FUTUREMEDIA_BOARD },
304   { 118, STD_TXSROM },
305   { 119, STD_TQROM },
306   { 120, BTL_TOBIDASE },
307   { 121, KAY_PANDAPRINCE },
308   // 122 Unused
309   { 123, UNL_H2288 },
310   // 124 Unused
311   // 125 Unused
312   { 126, BMC_PJOY84 },
313   // 127 Unused
314   // 128 Unused
315   // 129 Unused
316   // 130 Unused
317   // 131 Unused
318   { 132, TXC_22211B },
319   { 133, SACHEN_SA72008 },
320   { 134, BMC_FAMILY_4646B },
321   // 135 Unused
322   { 136, SACHEN_TCU02 },
323   { 137, SACHEN_8259D },
324   { 138, SACHEN_8259B },
325   { 139, SACHEN_8259C },
326   { 140, JALECO_JF11 },
327   { 141, SACHEN_8259A },
328   { 142, KAISER_KS7032},
329   { 143, SACHEN_TCA01 },
330   { 144, AGCI_50282 },
331   { 145, SACHEN_SA72007 },
332   { 146, AVE_NINA06 }, // basically same as Mapper 79 (Nina006)
333   { 147, SACHEN_TCU01 },
334   { 148, SACHEN_SA0037 },
335   { 149, SACHEN_SA0036 },
336   { 150, SACHEN_74LS374 },
337   // 151 VS. system by Konami - Not going to be implemented (use MAME instead)
338   { 152, DIS_74X161X161X32 },
339   { 153, BANDAI_LZ93 },
340   { 154, NAMCOT_3453 },
341   { 155, STD_SXROM_A }, // diff compared to MMC1 concern WRAM
342   { 156, OPENCORP_DAOU306 },
343   { 157, BANDAI_DATACH },   // no Datach Reader -> we fall back to mapper 16
344   { 158, TENGEN_800037 },
345   { 159, BANDAI_LZ93EX },   // with 24c01
346   { 160, SACHEN_SA009 },
347   // 161 Unused
348   // 162 Unused
349   { 163, NANJING_BOARD},
350   { 164, WAIXING_FFV },
351   { 165, WAIXING_SH2 },
352   { 166, SUBOR_TYPE1 },
353   { 167, SUBOR_TYPE0 },
354   { 168, UNL_RACERMATE },
355   // 169 Unused
356   // 170 Fujiya
357   { 171, KAISER_KS7058 },
358   { 172, TXC_22211B },
359   { 173, TXC_22211C },
360   // 174 Unused
361   { 175, KAISER_KS7022},
362   { 176, UNL_XZY },
363   { 177, HENGEDIANZI_BOARD },
364   { 178, WAIXING_SGZLZ },
365   { 179, HENGEDIANZI_XJZB },
366   { 180, UXROM_CC },
367   // 181 Unused
368   { 182, HOSENKAN_BOARD },
369   // 183 FDS bootleg (Shui Guan Pipe) - Unsupported
370   { 184, SUNSOFT_1 },
371   { 185, STD_CNROM },
372   { 186, FUKUTAKE_BOARD },
373   { 187, UNL_KOF96 },
374   { 188, BANDAI_KARAOKE },
375   { 189, TXC_TW },
376   // 190 Unused
377   { 191, WAIXING_TYPE_B },
378   { 192, WAIXING_TYPE_C },
379   { 193, NTDEC_FIGHTINGHERO },
380   { 194, WAIXING_TYPE_D },
381   { 195, WAIXING_TYPE_E },
382   { 196, BTL_SUPERBROS11 },
383   { 197, UNL_SUPERFIGHTER3 },
384   { 198, WAIXING_TYPE_F },
385   { 199, WAIXING_TYPE_G },
386   { 200, BMC_36IN1 },
387   { 201, BMC_21IN1 },
388   { 202, BMC_150IN1 },
389   { 203, BMC_35IN1 },
390   { 204, BMC_64IN1 },
391   { 205, BMC_15IN1 },
392   { 206, STD_DXROM },
393   { 207, TAITO_X1_005_A },
394   { 208, GOUDER_37017 },
395   // 209 JY Company Type B (Power Rangers 3 & 4, Shin Samurai Spirits 2) - Unsupported
396   // 210 Some emu uses this as Mapper 19 without some features
397   // 211 JY Company Type C (Tiny Toon Adventures 6, Donkey Kong Country 4) - Unsupported
398   { 212, BMC_SUPERHIK_300IN1 },
399   { 213, BMC_9999999IN1 },
400   { 214, BMC_SUPERGUN_20IN1 },
401   { 215, SUPERGAME_BOOGERMAN },
402   { 216, RCM_GS2015 },
403   { 217, BMC_GOLDENCARD_6IN1 },
404   // 218 Unused
405   // 219 Bootleg A9746 - Unsupported
406   // 220 Unused
407   { 221, UNL_N625092 },
408   { 222, BTL_DRAGONNINJA },
409   { 223, WAIXING_TYPE_I },   // (according to NEStopia source, it's MMC3 with more WRAM)
410   { 224, WAIXING_TYPE_J },   // (according to NEStopia source, it's MMC3 with more WRAM)
411   { 225, BMC_72IN1 },
412   { 226, BMC_76IN1 },
413   { 227, BMC_1200IN1 },
414   { 228, ACTENT_ACT52 },
415   { 229, BMC_31IN1 },
416   { 230, BMC_22GAMES },
417   { 231, BMC_20IN1 },
418   { 232, CAMERICA_BF9096 },
419   // 233 Super 22 Games - Unsupported
420   // 234 AVE Maxi 15 - Unsupported
421   // 235 Golden Game x-in-1 - Unsupported
422   // 236 Game 800-in-1 - Unsupported
423   // 237 Unused
424   { 238, UNL_603_5052 },
425   // 239 Unused
426   { 240, CNE_SHLZ },
427   { 241, TXC_MXMDHTWO },
428   { 242, WAIXING_ZS },
429   { 243, SACHEN_74LS374_A },
430   { 244, CNE_DECATHLON },
431   { 245, WAIXING_TYPE_H },
432   { 246, CNE_FSB },
433   // 247 Unused
434   // 248 Unused
435   { 249, WAIXING_SECURITY },
436   { 250, NITRA_TDA },
437   // 251 Shen Hua Jian Yun III?? - Unsupported
438   { 252, WAIXING_SGZ },
439   // 253 Super 8-in-1 99 King Fighter?? - Unsupported
440   { 254, BTL_PIKACHUY2K },
441   { 255, BMC_110IN1 },
442};
443
444const nes_mmc *nes_mapper_lookup( int mapper )
445{
446   int i;
447
448   for (i = 0; i < ARRAY_LENGTH(mmc_list); i++)
449   {
450      if (mmc_list[i].iNesMapper == mapper)
451         return &mmc_list[i];
452   }
453
454   return NULL;
455}
456
457int nes_get_mmc_id( running_machine &machine, int mapper )
458{
459   const nes_mmc *mmc = nes_mapper_lookup(mapper);
460
461   if (mmc == NULL)
462      fatalerror("Unimplemented Mapper %d", mapper);
463
464   return mmc->pcb_id;
465}
src/mame/machine/snescart.c
r0r11461
1/***************************************************************************
2
3  snescart.c
4
5  Machine file to handle cart loading in the Nintendo Super NES emulation.
6
7***************************************************************************/
8
9#include "emu.h"
10#include "includes/snes.h"
11#include "imagedev/cartslot.h"
12#include "snescart.h"
13
14#define SNES_CART_DEBUG 0
15
16/****** Strings for Cart Header Logging ******/
17
18#define UNK "Unknown"
19
20/* Some known type of cart */
21static const char *const types[] =
22{
23   "ROM",
24   "ROM, DSP-1",
25   "ROM, DSP-2",
26   "ROM, DSP-3",
27   "ROM, DSP-4",
28   "ROM, Super FX / FX2",
29   "ROM, SA-1",
30   "ROM, S-DD1",
31   "ROM, OBC-1",
32   "ROM, S-RTC",
33   "ROM, Z80GB (Super Game Boy)",
34   "ROM, C4",
35   "ROM, Seta ST-010",
36   "ROM, Seta ST-011",
37   "ROM, Seta ST-018",
38   "ROM, SPC7110",
39   "ROM, SPC7110, RTC",
40   UNK,                     // to add: Satellaview BS-X detection
41};
42
43/* Some known countries */
44static const char *const countries[] =
45{
46/* 0*/   "Japan (NTSC)", "USA & Canada (NTSC)", "Europe, Oceania & Asia (PAL)", "Sweden (PAL)",
47/* 4*/   "Finland (PAL)", "Denmark (PAL)", "France (PAL)", "Holland (PAL)",
48/* 8*/   "Spain (PAL)", "Germany, Austria & Switzerland (PAL)", "Italy (PAL)", "Hong Kong & China (PAL)",
49/* c*/   "Indonesia (PAL)", "South Korea (NTSC)", UNK, UNK,
50};
51
52/* Some known companies (integrations to the list from Snes9x) */
53static const char *const companies[] =
54{
55/* 0*/   "Invalid", "Nintendo", "Ajinomoto", "Imagineer-Zoom", "Chris Gray Enterprises Inc.", "Zamuse", "Falcom", UNK,
56/* 8*/   "Capcom", "HOT-B", "Jaleco", "Coconuts", "Rage Software", "Micronet", "Technos", "Mebio Software",
57/*10*/   "SHOUEi System", "Starfish", "Gremlin Graphics", "Electronic Arts", "NCS / Masaya", "COBRA Team", "Human/Field", "KOEI",
58/*18*/   "Hudson Soft", "Game Village", "Yanoman", UNK, "Tecmo", UNK, "Open System", "Virgin Games",
59/*20*/   "KSS", "Sunsoft", "POW", "Micro World", UNK, UNK, "Enix", "Loriciel/Electro Brain",
60/*28*/   "Kemco", "Seta Co.,Ltd.", "Culture Brain", "Irem Japan", "Pal Soft", "Visit Co.,Ltd.", "INTEC Inc.", "System Sacom Corp.",
61/*30*/   "Viacom New Media", "Carrozzeria", "Dynamic", "Nintendo", "Magifact", "Hect", UNK, UNK,
62/*38*/   "Capcom Europe", "Accolade Europe", UNK, "Arcade Zone", "Empire Software", "Loriciel", "Gremlin Graphics", UNK,
63/*40*/   "Seika Corp.", "UBI Soft", UNK, UNK, "LifeFitness Exertainment", UNK, "System 3", "Spectrum Holobyte",
64/*48*/   UNK, "Irem", UNK, "Raya Systems/Sculptured Software", "Renovation Products", "Malibu Games/Black Pearl", UNK, "U.S. Gold",
65/*50*/   "Absolute Entertainment", "Acclaim", "Activision", "American Sammy", "GameTek", "Hi Tech Expressions", "LJN Toys", UNK,
66/*58*/   UNK, UNK, "Mindscape", "Romstar, Inc.", UNK, "Tradewest", UNK, "American Softworks Corp.",
67/*60*/   "Titus", "Virgin Interactive Entertainment", "Maxis", "Origin/FCI/Pony Canyon", UNK, UNK, UNK, "Ocean",
68/*68*/   UNK, "Electronic Arts", UNK, "Laser Beam", UNK, UNK, "Elite", "Electro Brain",
69/*70*/   "Infogrames", "Interplay", "LucasArts", "Parker Brothers", "Konami", "STORM", UNK, UNK,
70/*78*/   "THQ Software", "Accolade Inc.", "Triffix Entertainment", UNK, "Microprose", UNK, UNK, "Kemco",
71/*80*/   "Misawa", "Teichio", "Namco Ltd.", "Lozc", "Koei", UNK, "Tokuma Shoten Intermedia", "Tsukuda Original",
72/*88*/   "DATAM-Polystar", UNK, UNK, "Bullet-Proof Software", "Vic Tokai", UNK, "Character Soft", "I\'\'Max",
73/*90*/   "Takara", "CHUN Soft", "Video System Co., Ltd.", "BEC", UNK, "Varie", "Yonezawa / S'Pal Corp.", "Kaneco",
74/*98*/   UNK, "Pack in Video", "Nichibutsu", "TECMO", "Imagineer Co.", UNK, UNK, UNK,
75/*a0*/   "Telenet", "Hori", UNK, UNK, "Konami", "K.Amusement Leasing Co.", UNK, "Takara",
76/*a8*/   UNK, "Technos Jap.", "JVC", UNK, "Toei Animation", "Toho", UNK, "Namco Ltd.",
77/*b0*/   "Media Rings Corp.", "ASCII Co. Activison", "Bandai", UNK, "Enix America", UNK, "Halken", UNK,
78/*b8*/   UNK, UNK, "Culture Brain", "Sunsoft", "Toshiba EMI", "Sony Imagesoft", UNK, "Sammy",
79/*c0*/   "Taito", UNK, "Kemco", "Square", "Tokuma Soft", "Data East", "Tonkin House", UNK,
80/*c8*/   "KOEI", UNK, "Konami USA", "NTVIC", UNK, "Meldac", "Pony Canyon", "Sotsu Agency/Sunrise",
81/*d0*/   "Disco/Taito", "Sofel", "Quest Corp.", "Sigma", "Ask Kodansha Co., Ltd.", UNK, "Naxat", UNK,
82/*d8*/   "Capcom Co., Ltd.", "Banpresto", "Tomy", "Acclaim", UNK, "NCS", "Human Entertainment", "Altron",
83/*e0*/   "Jaleco", UNK, "Yutaka", UNK, "T&ESoft", "EPOCH Co.,Ltd.", UNK, "Athena",
84/*e8*/   "Asmik", "Natsume", "King Records", "Atlus", "Sony Music Entertainment", UNK, "IGS", UNK,
85/*f0*/   UNK, "Motown Software", "Left Field Entertainment", "Beam Software", "Tec Magik", UNK, UNK, UNK,
86/*f8*/   UNK, "Cybersoft", UNK, "Psygnosis", UNK, UNK, "Davidson", UNK,
87};
88
89
90/* We use this to convert the company_id in the header to int value to be passed in companies[] */
91static int char_to_int_conv( char id )
92{
93   int value;
94
95   if (id == '1') value = 0x01;
96   else if (id == '2') value = 0x02;
97   else if (id == '3') value = 0x03;
98   else if (id == '4') value = 0x04;
99   else if (id == '5') value = 0x05;
100   else if (id == '6') value = 0x06;
101   else if (id == '7') value = 0x07;
102   else if (id == '8') value = 0x08;
103   else if (id == '9') value = 0x09;
104   else if (id == 'A') value = 0x0a;
105   else if (id == 'B') value = 0x0b;
106   else if (id == 'C') value = 0x0c;
107   else if (id == 'D') value = 0x0d;
108   else if (id == 'E') value = 0x0e;
109   else if (id == 'F') value = 0x0f;
110   else value = 0x00;
111
112   return value;
113}
114
115
116/***************************************************************************
117
118  SRAM handling
119
120***************************************************************************/
121
122/* Loads the battery backed RAM into the appropriate memory area */
123static void snes_load_sram(running_machine &machine)
124{
125   snes_state *state = machine.driver_data<snes_state>();
126   UINT8 ii;
127   UINT8 *battery_ram, *ptr;
128
129   battery_ram = (UINT8*)malloc(state->m_cart[0].sram_max);
130   ptr = battery_ram;
131   device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("cart"));
132   image->battery_load(battery_ram, state->m_cart[0].sram_max, 0xff);
133
134   if (state->m_cart[0].mode == SNES_MODE_20)
135   {
136      UINT32 size = state->m_cart[0].small_sram ? 0x8000 : 0x10000;
137
138      /* There could be some larger image needing banks 0x70 to 0x7f at address 0x8000 for ROM
139         * mirroring. These should be treated separately or data would be overwritten by SRAM */
140      for (ii = 0; ii < 16; ii++)
141      {
142         /* loading */
143         memmove(&snes_ram[0x700000 + (ii * 0x010000)], ptr, size);
144         /* mirroring */
145         memcpy(&snes_ram[0xf00000 + (ii * 0x010000)], &snes_ram[0x700000 + (ii * 0x010000)], size);
146         ptr += size;
147      }
148   }
149   else if (state->m_cart[0].mode == SNES_MODE_21)
150   {
151      for (ii = 0; ii < 16; ii++)
152      {
153         /* loading */
154         memmove(&snes_ram[0x306000 + (ii * 0x010000)], ptr, 0x2000);
155         /* mirroring */
156         memcpy(&snes_ram[0xb06000 + (ii * 0x010000)], &snes_ram[0x306000 + (ii * 0x010000)], 0x2000);
157         ptr += 0x2000;
158      }
159   }
160   else if (state->m_cart[0].mode == SNES_MODE_25)
161   {
162      for (ii = 0; ii < 16; ii++)
163      {
164         memmove(&snes_ram[0xb06000 + (ii * 0x010000)], ptr, 0x2000);
165         ptr += 0x2000;
166      }
167   }
168
169   free(battery_ram);
170}
171
172/* Saves the battery backed RAM from the appropriate memory area */
173static void snes_save_sram(running_machine &machine)
174{
175   snes_state *state = machine.driver_data<snes_state>();
176   UINT8 ii;
177   UINT8 *battery_ram, *ptr;
178
179   battery_ram = (UINT8*)malloc(state->m_cart[0].sram_max);
180   ptr = battery_ram;
181
182   if (state->m_cart[0].mode == SNES_MODE_20)
183   {
184      UINT32 size = state->m_cart[0].small_sram ? 0x8000 : 0x10000;
185
186      for (ii = 0; ii < 16; ii++)
187      {
188         memmove(ptr, &snes_ram[0x700000 + (ii * 0x010000)], size);
189         ptr += size;
190      }
191   }
192   else if (state->m_cart[0].mode == SNES_MODE_21)
193   {
194      for (ii = 0; ii < 16; ii++)
195      {
196         memmove(ptr, &snes_ram[0x306000 + (ii * 0x010000)], 0x2000);
197         ptr += 0x2000;
198      }
199   }
200   else if (state->m_cart[0].mode == SNES_MODE_25)
201   {
202      for (ii = 0; ii < 16; ii++)
203      {
204         memmove(ptr, &snes_ram[0xb06000 + (ii * 0x010000)], 0x2000);
205         ptr += 0x2000;
206      }
207   }
208   device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("cart"));
209   image->battery_save(battery_ram, state->m_cart[0].sram_max);
210
211   free(battery_ram);
212}
213
214static void snes_machine_stop(running_machine &machine)
215{
216   snes_state *state = machine.driver_data<snes_state>();
217
218   /* Save SRAM */
219   if (state->m_cart[0].sram > 0)
220      snes_save_sram(machine);
221}
222
223MACHINE_START( snes_mess )
224{
225   machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(snes_machine_stop),&machine));
226   MACHINE_START_CALL(snes);
227}
228
229
230static void sufami_load_sram(running_machine &machine, const char *cart_tag)
231{
232   UINT8 ii;
233   UINT8 *battery_ram, *ptr;
234   int st_sram_offset = 0;
235
236   battery_ram = (UINT8*)malloc(0x20000);
237   ptr = battery_ram;
238   device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device(cart_tag));
239   image->battery_load(battery_ram, 0x20000, 0);
240
241   if (strcmp(cart_tag, "slot_a") == 0)
242      st_sram_offset = 0x608000;
243
244   if (strcmp(cart_tag, "slot_b") == 0)
245      st_sram_offset = 0x708000;
246
247   /* Cart RAM is at 0x60-0x63:0x8000-0xffff (+0x10 for slot2) */
248   for (ii = 0; ii < 4; ii++)
249   {
250      /* loading */
251      memcpy(&snes_ram[st_sram_offset + (ii * 0x010000)], ptr + (ii * 0x8000), 0x8000);
252      /* mirroring */
253      memcpy(&snes_ram[0x800000 + st_sram_offset + (ii * 0x010000)], &snes_ram[st_sram_offset + (ii * 0x010000)], 0x8000);
254   }
255
256   free(battery_ram);
257}
258
259static void sufami_machine_stop(running_machine &machine)
260{
261   snes_state *state = machine.driver_data<snes_state>();
262   UINT8 ii;
263   UINT8 *battery_ram, *ptr;
264
265   battery_ram = (UINT8*)malloc(0x20000);
266   ptr = battery_ram;
267
268   if (state->m_cart[0].slot_in_use)
269   {
270      for (ii = 0; ii < 4; ii++)
271      {
272         memmove(ptr + ii * 0x8000, &snes_ram[0x608000 + (ii * 0x010000)], 0x8000);
273      }
274      device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("slot_a"));
275      image->battery_save(battery_ram, 0x20000);
276   }
277
278   if (state->m_cart[1].slot_in_use)
279   {
280      for (ii = 0; ii < 4; ii++)
281      {
282         memmove(ptr + ii * 0x8000, &snes_ram[0x708000 + (ii * 0x010000)], 0x8000);
283      }
284      device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("slot_b"));
285      image->battery_save(battery_ram, 0x20000);
286   }
287
288   free(battery_ram);
289}
290
291MACHINE_START( snesst )
292{
293   machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(sufami_machine_stop),&machine));
294   MACHINE_START_CALL(snes);
295}
296
297
298/***************************************************************************
299
300  Cart handling
301
302***************************************************************************/
303
304/* This function assign a 'score' to data immediately after 'offset' to measure how valid they are
305as information block (to decide if the image is HiRom, LoRom, ExLoRom or ExHiRom) */
306/* Code from bsnes, courtesy of byuu - http://byuu.cinnamonpirate.com/ */
307static int snes_validate_infoblock( UINT8 *infoblock, UINT32 offset )
308{
309   int score = 0;
310   UINT16 reset_vector = infoblock[offset + 0x3c] | (infoblock[offset + 0x3d] << 8);
311   UINT16 checksum     = infoblock[offset + 0x1e] | (infoblock[offset + 0x1f] << 8);
312   UINT16 ichecksum    = infoblock[offset + 0x1c] | (infoblock[offset + 0x1d] << 8);
313   UINT8 reset_opcode  = infoblock[(offset & ~0x7fff) | (reset_vector & 0x7fff)];   //first opcode executed upon reset
314   UINT8 mapper        = infoblock[offset + 0x15] & ~0x10;                     //mask off irrelevent FastROM-capable bit
315
316   /* $00:[000-7fff] contains uninitialized RAM and MMIO.
317    reset vector must point to ROM at $00:[8000-ffff] to be considered valid. */
318   if (reset_vector < 0x8000)
319      return 0;
320
321   /* some images duplicate the header in multiple locations, and others have completely
322    invalid header information that cannot be relied upon. The code below will analyze
323    the first opcode executed at the specified reset vector to determine the probability
324    that this is the correct header. Score is assigned accordingly. */
325
326   /* most likely opcodes */
327   if (reset_opcode == 0x78      //sei
328      || reset_opcode == 0x18      //clc (clc; xce)
329      || reset_opcode == 0x38      //sec (sec; xce)
330      || reset_opcode == 0x9c      //stz $nnnn (stz $4200)
331      || reset_opcode == 0x4c      //jmp $nnnn
332      || reset_opcode == 0x5c      //jml $nnnnnn
333   )
334      score += 8;
335
336   /* plausible opcodes */
337   if (reset_opcode == 0xc2      //rep #$nn
338      || reset_opcode == 0xe2      //sep #$nn
339      || reset_opcode == 0xad      //lda $nnnn
340      || reset_opcode == 0xae      //ldx $nnnn
341      || reset_opcode == 0xac      //ldy $nnnn
342      || reset_opcode == 0xaf      //lda $nnnnnn
343      || reset_opcode == 0xa9      //lda #$nn
344      || reset_opcode == 0xa2      //ldx #$nn
345      || reset_opcode == 0xa0      //ldy #$nn
346      || reset_opcode == 0x20      //jsr $nnnn
347      || reset_opcode == 0x22      //jsl $nnnnnn
348   )
349      score += 4;
350
351   /* implausible opcodes */
352   if (reset_opcode == 0x40      //rti
353      || reset_opcode == 0x60      //rts
354      || reset_opcode == 0x6b      //rtl
355      || reset_opcode == 0xcd      //cmp $nnnn
356      || reset_opcode == 0xec      //cpx $nnnn
357      || reset_opcode == 0xcc      //cpy $nnnn
358   )
359      score -= 4;
360
361   /* least likely opcodes */
362   if (reset_opcode == 0x00      //brk #$nn
363      || reset_opcode == 0x02      //cop #$nn
364      || reset_opcode == 0xdb      //stp
365      || reset_opcode == 0x42      //wdm
366      || reset_opcode == 0xff      //sbc $nnnnnn,x
367   )
368      score -= 8;
369
370   /* Sometimes, both the header and reset vector's first opcode will match ...
371    fallback and rely on info validity in these cases to determine more likely header. */
372
373   /* a valid checksum is the biggest indicator of a valid header. */
374   if ((checksum + ichecksum) == 0xffff && (checksum != 0) && (ichecksum != 0))
375      score += 4;
376
377   /* then there are the expected mapper values */
378   if (offset == 0x007fc0 && mapper == 0x20)   // 0x20 is usually LoROM
379      score += 2;
380
381   if (offset == 0x00ffc0 && mapper == 0x21)   // 0x21 is usually HiROM
382      score += 2;
383
384   if (offset == 0x007fc0 && mapper == 0x22)   // 0x22 is usually ExLoROM
385      score += 2;
386
387   if (offset == 0x40ffc0 && mapper == 0x25)   // 0x25 is usually ExHiROM
388      score += 2;
389
390   /* finally, there are valid values in the Company, Region etc. fields */
391   if (infoblock[offset + 0x1a] == 0x33)         // Company field: 0x33 indicates extended header
392      score += 2;
393
394   if (infoblock[offset + 0x16] < 0x08)         // ROM Type field
395      score++;
396
397   if (infoblock[offset + 0x17] < 0x10)         // ROM Size field
398      score++;
399
400   if (infoblock[offset + 0x18] < 0x08)         // SRAM Size field
401      score++;
402
403   if (infoblock[offset + 0x19] < 14)            // Region field
404      score++;
405
406   /* do we still have a positive score? */
407   if (score < 0)
408      score = 0;
409
410   return score;
411}
412
413/* Here we add a couple of cart utilities, to avoid duplicating the code in each DEVICE_IMAGE_LOAD */
414static UINT32 snes_skip_header( device_image_interface &image, UINT32 snes_rom_size )
415{
416   UINT8 header[512];
417   UINT32 offset = 512;
418
419   /* Check for a header (512 bytes) */
420   if (image.software_entry() == NULL)
421      image.fread( header, 512);
422   else
423      memcpy(header, image.get_software_region("rom"), 512);
424
425   if ((header[8] == 0xaa) && (header[9] == 0xbb) && (header[10] == 0x04))
426   {
427      /* Found an SWC identifier */
428      logerror("Found header (SWC) - Skipped\n");
429   }
430   else if ((header[0] | (header[1] << 8)) == (((snes_rom_size - 512) / 1024) / 8))
431   {
432      /* Some headers have the rom size at the start, if this matches with the actual rom size, we probably have a header */
433      logerror("Found header (size) - Skipped\n");
434   }
435   else if ((snes_rom_size % 0x8000) == 512)
436   {
437      /* As a last check we'll see if there's exactly 512 bytes extra to this image. */
438      logerror("Found header (extra) - Skipped\n");
439   }
440   else
441   {
442      /* No header found so go back to the start of the file */
443      logerror("No header found.\n");
444      offset = 0;
445   }
446
447   return offset;
448}
449
450
451/* This determines if a cart is in Mode 20, 21, 22 or 25; sets state->m_cart[0].mode and
452 state->m_cart[0].sram accordingly; and returns the offset of the internal header (needed to
453 detect BSX and ST carts) */
454static UINT32 snes_find_hilo_mode( device_image_interface &image, UINT8 *buffer, UINT32 offset, int cartid )
455{
456   snes_state *state = image.device().machine().driver_data<snes_state>();
457   UINT8 valid_mode20, valid_mode21, valid_mode25;
458   UINT32 retvalue;
459
460   /* Now to determine if this is a lo-ROM, a hi-ROM or an extended lo/hi-ROM */
461   valid_mode20 = snes_validate_infoblock(buffer, 0x007fc0);
462   valid_mode21 = snes_validate_infoblock(buffer, 0x00ffc0);
463   valid_mode25 = snes_validate_infoblock(buffer, 0x40ffc0);
464
465   /* Images larger than 32mbits are likely ExHiRom */
466   if (valid_mode25)
467      valid_mode25 += 4;
468
469   if ((valid_mode20 >= valid_mode21) && (valid_mode20 >= valid_mode25))
470   {
471      if ((buffer[0x007fd5] == 0x32) || ((state->m_cart_size - offset) > 0x401000))
472         state->m_cart[cartid].mode = SNES_MODE_22;   // ExLoRom
473      else
474         state->m_cart[cartid].mode = SNES_MODE_20;   // LoRom
475
476      retvalue = 0x007fc0;
477
478      /* a few games require 512k, however we store twice as much to be sure to cover the various mirrors */
479      state->m_cart[cartid].sram_max = 0x100000;
480   }
481   else if (valid_mode21 >= valid_mode25)
482   {
483      state->m_cart[cartid].mode = SNES_MODE_21;   // HiRom
484      retvalue = 0x00ffc0;
485      state->m_cart[cartid].sram_max = 0x20000;
486   }
487   else
488   {
489      state->m_cart[cartid].mode = SNES_MODE_25;   // ExHiRom
490      retvalue = 0x40ffc0;
491      state->m_cart[cartid].sram_max = 0x20000;
492   }
493
494   logerror( "\t HiROM/LoROM id: %s (LoROM: %d , HiROM: %d, ExHiROM: %d)\n",
495          (state->m_cart[cartid].mode == SNES_MODE_20) ? "LoROM" :
496          (state->m_cart[cartid].mode == SNES_MODE_21) ? "HiROM" :
497          (state->m_cart[cartid].mode == SNES_MODE_22) ? "ExLoROM" :
498          (state->m_cart[cartid].mode == SNES_MODE_25) ? "ExHiROM" : "Other (BSX or ST)",
499          valid_mode20, valid_mode21, valid_mode25);
500
501   return retvalue;
502}
503
504static int snes_find_addon_chip( running_machine &machine )
505{
506   snes_state *state = machine.driver_data<snes_state>();
507   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
508   int supported_type = 1;
509   int dsp_prg_offset = 0;
510
511   /* Info mostly taken from http://snesemu.black-ship.net/misc/-from%20nsrt.edgeemu.com-chipinfo.htm */
512   switch (snes_r_bank1(space, 0x00ffd6))
513   {
514      case 0x00:
515      case 0x01:
516      case 0x02:
517         state->m_has_addon_chip = HAS_NONE;
518         break;
519
520      case 0x03:
521         if (snes_r_bank1(space, 0x00ffd5) == 0x30)
522         {
523            state->m_has_addon_chip = HAS_DSP4;
524            dsp_prg_offset = SNES_DSP4_OFFSET;
525         }
526         else
527         {
528            state->m_has_addon_chip = HAS_DSP1;
529            dsp_prg_offset = SNES_DSP1B_OFFSET;
530         }
531         break;
532
533      case 0x04:
534         state->m_has_addon_chip = HAS_DSP1;
535         dsp_prg_offset = SNES_DSP1B_OFFSET;
536         break;
537
538      case 0x05:
539         if (snes_r_bank1(space, 0x00ffd5) == 0x20)
540         {
541            state->m_has_addon_chip = HAS_DSP2;
542            dsp_prg_offset = SNES_DSP2_OFFSET;
543         }
544         /* DSP-3 is hard to detect. We exploit the fact that the only game has been manufactured by Bandai */
545         else if ((snes_r_bank1(space, 0x00ffd5) == 0x30) && (snes_r_bank1(space, 0x00ffda) == 0xb2))
546         {
547            state->m_has_addon_chip = HAS_DSP3;
548            dsp_prg_offset = SNES_DSP3_OFFSET;
549         }
550         else
551         {
552            state->m_has_addon_chip = HAS_DSP1;
553            dsp_prg_offset = SNES_DSP1B_OFFSET;
554         }
555         break;
556
557      case 0x13:   // Mario Chip 1
558      case 0x14:   // GSU-x
559      case 0x15:   // GSU-x
560      case 0x1a:   // GSU-1 (21 MHz at start)
561         if (snes_r_bank1(space, 0x00ffd5) == 0x20)
562            state->m_has_addon_chip = HAS_SUPERFX;
563         break;
564
565      case 0x25:
566         state->m_has_addon_chip = HAS_OBC1;
567         break;
568
569      case 0x32:   // needed by a Sample game (according to ZSNES)
570      case 0x34:
571      case 0x35:
572         if (snes_r_bank1(space, 0x00ffd5) == 0x23)
573         {
574            state->m_has_addon_chip = HAS_SA1;
575            supported_type = 0;
576            mame_printf_error("This is a SA-1 type game, currently unsupported by the driver\n");
577         }
578         break;
579
580      case 0x43:
581      case 0x45:
582         if (snes_r_bank1(space, 0x00ffd5) == 0x32)
583         {
584            state->m_has_addon_chip = HAS_SDD1;
585         }
586         break;
587
588      case 0x55:
589         if (snes_r_bank1(space, 0x00ffd5) == 0x35)
590         {
591            state->m_has_addon_chip = HAS_RTC;
592         }
593         break;
594
595      case 0xe3:
596         state->m_has_addon_chip = HAS_Z80GB;
597         supported_type = 0;
598         break;
599
600      case 0xf3:
601         state->m_has_addon_chip = HAS_CX4;
602         break;
603
604      case 0xf5:
605         if (snes_r_bank1(space, 0x00ffd5) == 0x30)
606         {
607            state->m_has_addon_chip = HAS_ST018;
608            supported_type = 0;
609         }
610         else if (snes_r_bank1(space, 0x00ffd5) == 0x3a)
611         {
612            state->m_has_addon_chip = HAS_SPC7110;
613         }
614         break;
615
616      case 0xf6:
617         /* These Seta ST-01X chips have both 0x30 at 0x00ffd5,
618             they only differ for the 'size' at 0x00ffd7 */
619         if (snes_r_bank1(space, 0x00ffd7) < 0x0a)
620            state->m_has_addon_chip = HAS_ST011;
621         else
622            state->m_has_addon_chip = HAS_ST010;
623
624         // if we are loading the game in a driver without the ST01X DSP, revert to HAS_NONE to avoid crash
625         if (!state->m_upd96050)
626            state->m_has_addon_chip = HAS_NONE;
627         break;
628
629      case 0xf9:
630         if (snes_r_bank1(space, 0x00ffd5) == 0x3a)
631         {
632            state->m_has_addon_chip = HAS_SPC7110_RTC;
633            supported_type = 0;
634         }
635         break;
636
637      default:
638         state->m_has_addon_chip = HAS_UNK;
639         supported_type = 0;
640         break;
641   }
642
643   if ((state->m_has_addon_chip >= HAS_DSP1) && (state->m_has_addon_chip <= HAS_DSP4))
644   {
645      UINT8 *dspsrc = (UINT8 *)machine.region("addons")->base();
646      UINT32 *dspprg = (UINT32 *)machine.region("dspprg")->base();
647      UINT16 *dspdata = (UINT16 *)machine.region("dspdata")->base();
648
649      // copy DSP program
650      for (int i = 0; i < 0x2000; i+= 4)
651      {
652         *dspprg = dspsrc[dsp_prg_offset+0+i]<<24 | dspsrc[dsp_prg_offset+1+i]<<16 | dspsrc[dsp_prg_offset+2+i]<<8;
653         dspprg++;
654      }
655
656      // copy DSP data
657      for (int i = 0; i < 0x800; i+= 2)
658      {
659         *dspdata++ = dspsrc[dsp_prg_offset+0x2000+i]<<8 | dspsrc[dsp_prg_offset+0x2001+i];
660      }
661   }
662
663   if ((state->m_has_addon_chip == HAS_ST010) || (state->m_has_addon_chip == HAS_ST011))
664   {
665      UINT8 *dspsrc = (UINT8 *)machine.region("addons")->base();
666      UINT32 *dspprg = (UINT32 *)machine.region("dspprg")->base();
667      UINT16 *dspdata = (UINT16 *)machine.region("dspdata")->base();
668
669      // copy DSP program
670      for (int i = 0; i < 0x10000; i+= 4)
671      {
672         *dspprg = dspsrc[0+i]<<24 | dspsrc[1+i]<<16 | dspsrc[2+i]<<8;
673         dspprg++;
674      }
675
676      // copy DSP data
677      for (int i = 0; i < 0x1000; i+= 2)
678      {
679         *dspdata++ = dspsrc[0x10000+i]<<8 | dspsrc[0x10001+i];
680      }
681   }
682
683   return supported_type;
684}
685
686static void snes_cart_log_info( running_machine &machine, int total_blocks, int supported )
687{
688   snes_state *state = machine.driver_data<snes_state>();
689   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
690   char title[21], rom_id[4], company_id[2];
691   int i, company, has_ram = 0, has_sram = 0;
692
693   /* Company */
694   for (i = 0; i < 2; i++)
695      company_id[i] = snes_r_bank1(space, 0x00ffb0 + i);
696   company = (char_to_int_conv(company_id[0]) << 4) + char_to_int_conv(company_id[1]);
697   if (company == 0)
698      company = snes_r_bank1(space, 0x00ffda);
699
700   /* ROM ID */
701   for( i = 0; i < 4; i++ )
702      rom_id[i] = snes_r_bank1(space, 0x00ffb2 + i);
703
704   /* Title */
705   for( i = 0; i < 21; i++ )
706      title[i] = snes_r_bank1(space, 0x00ffc0 + i);
707
708   /* RAM */
709   if (((snes_r_bank1(space, 0x00ffd6) & 0xf) == 1) ||
710      ((snes_r_bank1(space, 0x00ffd6) & 0xf) == 2) ||
711      ((snes_r_bank1(space, 0x00ffd6) & 0xf) == 4) ||
712      ((snes_r_bank1(space, 0x00ffd6) & 0xf) == 5))
713      has_ram = 1;
714
715   /* SRAM */
716   if (((snes_r_bank1(space, 0x00ffd6) & 0xf) == 2) ||
717      ((snes_r_bank1(space, 0x00ffd6) & 0xf) == 5) ||
718      ((snes_r_bank1(space, 0x00ffd6) & 0xf) == 6))
719      has_sram = 1;
720
721   logerror( "ROM DETAILS\n" );
722   logerror( "===========\n\n" );
723   logerror( "\tTotal blocks:  %d (%dmb)\n", total_blocks, total_blocks / (state->m_cart[0].mode & 5 ? 32 : 16) );
724   logerror( "\tROM bank size: %s \n",
725          (state->m_cart[0].mode == SNES_MODE_20) ? "LoROM" :
726          (state->m_cart[0].mode == SNES_MODE_21) ? "HiROM" :
727          (state->m_cart[0].mode == SNES_MODE_22) ? "ExLoROM" :
728          (state->m_cart[0].mode == SNES_MODE_25) ? "ExHiROM" : "Other (BSX or ST)" );
729   logerror( "\tCompany:       %s [%.2s]\n", companies[company], company_id );
730   logerror( "\tROM ID:        %.4s\n\n", rom_id );
731
732   logerror( "HEADER DETAILS\n" );
733   logerror( "==============\n\n" );
734   logerror( "\tName:          %.21s\n", title );
735   logerror( "\tSpeed:         %s [%d]\n", ((snes_r_bank1(space, 0x00ffd5) & 0xf0)) ? "FastROM" : "SlowROM", (snes_r_bank1(space, 0x00ffd5) & 0xf0) >> 4 );
736   logerror( "\tBank size:     %s [%d]\n", (snes_r_bank1(space, 0x00ffd5) & 0xf) ? "HiROM" : "LoROM", snes_r_bank1(space, 0x00ffd5) & 0xf );
737
738   logerror( "\tType:          %s", types[state->m_has_addon_chip]);
739   if (has_ram)
740      logerror( ", RAM");
741   if (has_sram)
742      logerror( ", SRAM");
743   logerror( " [%d]\n", snes_r_bank1(space, 0x00ffd6) );
744
745   logerror( "\tSize:          %d megabits [%d]\n", 1 << (snes_r_bank1(space, 0x00ffd7) - 7), snes_r_bank1(space, 0x00ffd7) );
746   logerror( "\tSRAM:          %d kilobits [%d]\n", state->m_cart[0].sram * 8, snes_ram[0xffd8] );
747   logerror( "\tCountry:       %s [%d]\n", countries[snes_r_bank1(space, 0x00ffd9)], snes_r_bank1(space, 0x00ffd9) );
748   logerror( "\tLicense:       %s [%X]\n", companies[snes_r_bank1(space, 0x00ffda)], snes_r_bank1(space, 0x00ffda) );
749   logerror( "\tVersion:       1.%d\n", snes_r_bank1(space, 0x00ffdb) );
750   logerror( "\tInv Checksum:  %X %X\n", snes_r_bank1(space, 0x00ffdd), snes_r_bank1(space, 0x00ffdc) );
751   logerror( "\tChecksum:      %X %X\n", snes_r_bank1(space, 0x00ffdf), snes_r_bank1(space, 0x00ffde) );
752   logerror( "\tNMI Address:   %2X%2Xh\n", snes_r_bank1(space, 0x00fffb), snes_r_bank1(space, 0x00fffa) );
753   logerror( "\tStart Address: %2X%2Xh\n\n", snes_r_bank1(space, 0x00fffd), snes_r_bank1(space, 0x00fffc) );
754
755   logerror( "\tMode: %d\n", state->m_cart[0].mode);
756
757   if (!supported)
758      logerror("WARNING: This cart type \"%s\" is not supported yet!\n", types[state->m_has_addon_chip]);
759}
760
761static DEVICE_IMAGE_LOAD( snes_cart )
762{
763   int supported_type = 1, i, j;
764   running_machine &machine = image.device().machine();
765   snes_state *state = machine.driver_data<snes_state>();
766   address_space *space = machine.device( "maincpu")->memory().space( AS_PROGRAM );
767   int total_blocks, read_blocks, has_bsx_slot = 0, st_bios = 0;
768   UINT32 offset, int_header_offs;
769   UINT8 *ROM = image.device().machine().region("cart")->base();
770
771   if (image.software_entry() == NULL)
772      state->m_cart_size = image.length();
773   else
774      state->m_cart_size = image.get_software_region_length("rom");
775
776   /* Check for a header (512 bytes), and skip it if found */
777   offset = snes_skip_header(image, state->m_cart_size);
778
779   if (image.software_entry() == NULL)
780   {
781      image.fseek(offset, SEEK_SET);
782      image.fread( ROM, state->m_cart_size - offset);
783   }
784   else
785      memcpy(ROM, image.get_software_region("rom") + offset, state->m_cart_size - offset);
786
787   if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", state->m_cart_size - offset);
788
789   /* First, look if the cart is HiROM or LoROM (and set snes_cart accordingly) */
790   int_header_offs = snes_find_hilo_mode(image, ROM, offset, 0);
791
792   /* Then, detect BS-X carts */
793   // Detect presence of BS-X Flash Cart
794   if ((ROM[int_header_offs + 0x13] == 0x00 || ROM[int_header_offs + 0x13] == 0xff) &&
795         ROM[int_header_offs + 0x14] == 0x00)
796   {
797      UINT8 n15 = ROM[int_header_offs + 0x15];
798      if (n15 == 0x00 || n15 == 0x80 || n15 == 0x84 || n15 == 0x9c || n15 == 0xbc || n15 == 0xfc)
799      {
800         if (ROM[int_header_offs + 0x1a] == 0x33 || ROM[int_header_offs + 0x1a] == 0xff)
801         {
802            // BS-X Flash Cart
803            state->m_cart[0].mode = SNES_MODE_BSX;
804         }
805      }
806   }
807
808   // Detect presence of BS-X flash cartridge connector
809   if ((ROM[int_header_offs - 14] == 'Z') && (ROM[int_header_offs - 11] == 'J'))
810   {
811      UINT8 n13 = ROM[int_header_offs - 13];
812      if ((n13 >= 'A' && n13 <= 'Z') || (n13 >= '0' && n13 <= '9'))
813      {
814         if (ROM[int_header_offs + 0x1a] == 0x33 ||
815            (ROM[int_header_offs - 10] == 0x00 && ROM[int_header_offs - 4] == 0x00))
816         {
817            has_bsx_slot = 1;
818         }
819      }
820   }
821
822   // If there is a BS-X connector, detect if it is the Base Cart or a compatible slotted cart
823   if (has_bsx_slot)
824   {
825      if (!memcmp(ROM + int_header_offs, "Satellaview BS-X     ", 21))
826      {
827         //BS-X Base Cart
828         state->m_cart[0].mode = SNES_MODE_BSX;
829         // handle RAM
830      }
831      else
832      {
833         state->m_cart[0].mode = (int_header_offs ==0x007fc0) ? SNES_MODE_BSLO : SNES_MODE_BSHI;
834         // handle RAM?
835      }
836   }
837
838   /* Then, detect Sufami Turbo carts */
839   if (!memcmp(ROM, "BANDAI SFC-ADX", 14))
840   {
841      state->m_cart[0].mode = SNES_MODE_ST;
842      if (!memcmp(ROM + 16, "SFC-ADX BACKUP", 14))
843         st_bios = 1;
844   }
845
846   if (SNES_CART_DEBUG) mame_printf_error("mode %d\n", state->m_cart[0].mode);
847
848   /* FIXME: Insert crc check here? */
849
850   /* How many blocks of data are available to be loaded? */
851   total_blocks = ((state->m_cart_size - offset) / (state->m_cart[0].mode & 0xa5 ? 0x8000 : 0x10000));
852   read_blocks = 0;
853
854   if (SNES_CART_DEBUG) mame_printf_error("blocks %d\n", total_blocks);
855
856   /* Loading all the data blocks from cart, we only partially cover banks 0x00 to 0x7f. Therefore, we
857     * have to mirror the blocks until we reach the end. E.g. for a 11Mbits image (44 blocks), we proceed
858     * as follows:
859     * 11 Mbits = 8 Mbits (blocks 1->32) + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44).
860     * Hence, we fill memory up to 16 Mbits (banks 0x00 to 0x3f) mirroring as follows
861     * 8 Mbits (blocks 1->32) + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44) + 1 Mbit (blocks 41->44)
862     *   + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44) + 1 Mbit (blocks 41->44)
863     * and we repeat the same blocks in the second half of the banks (banks 0x40 to 0x7f).
864     * This is likely what happens in the real SNES as well, because the unit cannot be aware of the exact
865     * size of data in the cart (procedure confirmed by byuu)
866     */
867   switch (state->m_cart[0].mode)
868   {
869      case SNES_MODE_21:
870      /* HiROM carts load data in banks 0xc0 to 0xff. Each bank is fully mirrored in banks 0x40 to 0x7f
871         * (actually up to 0x7d, because 0x7e and 0x7f are overwritten by WRAM). The top half (address
872         * range 0x8000 - 0xffff) of each bank is also mirrored in banks 0x00 to 0x3f and 0x80 to 0xbf.
873         */
874         /* SPC7110 games needs this different loading routine */
875         if ((ROM[0x00ffd6] == 0xf9 || ROM[0x00ffd6] == 0xf5) && (ROM[0x00ffd5] == 0x3a))
876         {
877            while (read_blocks < 16 && read_blocks < total_blocks)
878            {
879               /* Loading data */
880               memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x10000], 0x10000);
881               /* Mirroring */
882               memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
883               memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
884               read_blocks++;
885            }
886         }
887         else
888         {
889            while (read_blocks < 64 && read_blocks < total_blocks)
890            {
891               /* Loading data */
892               memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x10000], 0x10000);
893               /* Mirroring */
894               memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
895               memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0xc00000 + read_blocks * 0x10000], 0x10000);
896               memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
897               read_blocks++;
898            }
899            /* Filling banks up to 0xff and their mirrors */
900            while (read_blocks % 64)
901            {
902               int j = 0, repeat_blocks;
903               while ((read_blocks % (64 >> j)) && j < 6)
904                  j++;
905               repeat_blocks = read_blocks % (64 >> (j - 1));
906
907               memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &snes_ram[0xc00000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
908               memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
909               memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0x400000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
910               memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[0x800000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
911               read_blocks += repeat_blocks;
912            }
913         }
914         break;
915
916      case SNES_MODE_25:
917      /* Extendend HiROM carts start to load data in banks 0xc0 to 0xff. However, they exceed the
918         * available space in these banks, and continue loading at banks 0x40 to 0x7f. The top half
919         * (address range 0x8000 - 0xffff) of each bank is also mirrored either to banks 0x00 to 0x3f
920         * (for data in banks 0x40 to 0x7f) or to banks 0x80 to 0xbf (for data in banks 0xc0 to 0xff).
921         * Notice that banks 0x7e and 0x7f are overwritten by WRAM, but they could contain data at
922         * address > 0x8000 because the mirrors at 0x3e and 0x3f are not overwritten.
923         */
924         /* Reading the first 64 blocks */
925         while (read_blocks < 64 && read_blocks < total_blocks)
926         {
927            /* Loading data */
928            memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x10000], 0x10000);
929            /* Mirroring */
930            memcpy( &snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
931            read_blocks++;
932         }
933         /* ExHiROMs are supposed to be larger than 32Mbits! */
934         if (read_blocks < 64)
935         {
936            logerror("This image has been identified as ExHiROM, but it's too small!\n");
937            logerror("Please verify if it's corrupted. If it's not please report this as a bug.\n");
938            return IMAGE_INIT_FAIL;
939         }
940         /* Scaling down the counter */
941         read_blocks -= 64;
942         /* Reading the next blocks */
943         while (read_blocks < 64  && read_blocks < (total_blocks - 64))
944         {
945            /* Loading data */
946            memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &ROM[0x400000 + read_blocks * 0x10000], 0x10000);
947            /* Mirroring */
948            memcpy(&snes_ram[0x8000 + read_blocks * 0x10000], &snes_ram[0x408000 + read_blocks * 0x10000], 0x8000);
949            read_blocks++;
950         }
951         /* Filling banks up to 0x7f and their mirrors */
952         while (read_blocks % 64)
953         {
954            int j = 0, repeat_blocks;
955            while ((read_blocks % (64 >> j)) && j < 6)
956               j++;
957            repeat_blocks = read_blocks % (64 >> (j - 1));
958
959            memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0x400000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
960            memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
961            read_blocks += repeat_blocks;
962         }
963         break;
964
965      case SNES_MODE_22:
966      /* "Extendend LoROM" carts have their data loaded in banks 0x00 to 0x3f at address 0x8000.
967         * These are then mirrored in banks 0x40 to 0x7f, both at address 0x0000 and at address
968         * 0x8000, in banks 0x80 to 0xbf at address 0x8000 and in banks 0xc0 to 0xff, both at address
969         * 0x0000 and at address 0x8000. Notice that SDD-1 games (Star Ocean and Street Fighter Zero 2)
970         * use SNES_MODE_22
971         */
972         while (read_blocks < 64 && read_blocks < total_blocks)
973         {
974            /* Loading and mirroring data */
975            memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000);
976            memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000);
977            memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x10000], 0x10000);
978            memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x10000], 0x10000);
979            read_blocks++;
980         }
981         /* Filling banks up to 0x3f and their mirrors */
982         while (read_blocks % 64)
983         {
984            int j = 0, repeat_blocks;
985            while ((read_blocks % (64 >> j)) && j < 6)
986               j++;
987            repeat_blocks = read_blocks % (64 >> (j - 1));
988
989            memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
990            memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[0x800000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
991            memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0x400000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
992            memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &snes_ram[0xc00000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
993            read_blocks += repeat_blocks;
994         }
995         break;
996
997      case SNES_MODE_ST:
998         if (!st_bios)
999         {
1000            mame_printf_error("This is a Sufami Turbo data cart and cannot be loaded for snes/snespal in MESS.\n");
1001            mame_printf_error("Please use snesst driver to load it, instead.\n");
1002            return IMAGE_INIT_FAIL;
1003         }
1004         else
1005         {
1006            // The Base ST cart consists of 8 * 0x8000 block which have to be loaded (and mirrored)
1007            // at 0x00-0x1f:0x8000-0xffff and 0x80-0x9f:0x8000-0xffff
1008            for (i = 0; i < 8; i++)
1009            {
1010               /* Loading data */
1011               memcpy(&snes_ram[0x008000 + i * 0x10000], &ROM[0x000000 + i * 0x8000], 0x8000);
1012               /* Mirroring */
1013               memcpy(&snes_ram[0x808000 + i * 0x10000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000);
1014
1015               /* Additional mirrors (to fill snes_ram up to 0x1fffff) */
1016               for (j = 1; j < 4; j++)
1017               {
1018                  memcpy(&snes_ram[0x008000 + i * 0x10000 + j * 0x80000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000);
1019                  memcpy(&snes_ram[0x808000 + i * 0x10000 + j * 0x80000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000);
1020               }
1021            }
1022         }
1023         break;
1024
1025      case SNES_MODE_BSX:
1026      case SNES_MODE_BSLO:
1027      case SNES_MODE_BSHI:
1028         /* not handled yet */
1029         mame_printf_error("This is a BS-X Satellaview image: MESS does not support these yet, sorry.\n");
1030#if 0
1031         // shall we force incompatibility of flash carts without a base unit?
1032         if (!has_bsx_slot)
1033         {
1034            mame_printf_error("This is a BS-X flash cart and cannot be loaded in snes/snespal.\n");
1035//              mame_printf_error("Please use snesbsx driver to load it, instead.\n");
1036            return IMAGE_INIT_FAIL;
1037         }
1038#endif
1039         break;
1040
1041      default:
1042      case SNES_MODE_20:
1043      /* LoROM carts load data in banks 0x00 to 0x7f at address 0x8000 (actually up to 0x7d, because 0x7e and
1044         * 0x7f are overwritten by WRAM). Each block is also mirrored in banks 0x80 to 0xff (up to 0xff for real)
1045         */
1046         /* SuperFX games needs this different loading routine */
1047         if (((ROM[0x007fd6] >= 0x13 && ROM[0x007fd6] <= 0x15) || ROM[0x007fd6] == 0x1a) && (ROM[0x007fd5] == 0x20))
1048         {
1049            while (read_blocks < 64 && read_blocks < total_blocks)
1050            {
1051               /* Loading data primary: banks 0-3f from 8000-ffff*/
1052               memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000);
1053               /* Mirroring at banks 80-bf from 8000-ffff */
1054               memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0x8000 + (read_blocks * 0x10000)], 0x8000);
1055               /* Mirroring at banks 40-5f and c0-df */
1056               memcpy(&snes_ram[0x400000 + read_blocks * 0x8000], &snes_ram[0x8000 + (read_blocks * 0x10000)], total_blocks * 0x8000);
1057               memcpy(&snes_ram[0xc00000 + read_blocks * 0x8000], &snes_ram[0x8000 + (read_blocks * 0x10000)], total_blocks * 0x8000);
1058
1059               read_blocks++;
1060            }
1061            /* SuperFX games are supposed to contain 64 blocks! */
1062            if (read_blocks < total_blocks)
1063            {
1064               logerror("This image has been identified as a SuperFX game, but it's too large!\n");
1065               logerror("Please verify if it's corrupted. If it's not please report this as a bug.\n");
1066               return IMAGE_INIT_FAIL;
1067            }
1068         }
1069         else
1070         {
1071            while (read_blocks < 128 && read_blocks < total_blocks)
1072            {
1073               /* Loading data */
1074               memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000);
1075               /* Mirroring */
1076               memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0x8000 + (read_blocks * 0x10000)], 0x8000);
1077               read_blocks++;
1078            }
1079            /* Filling banks up to 0x7f and their mirrors */
1080            while (read_blocks % 128)
1081            {
1082               int j = 0, repeat_blocks;
1083               while ((read_blocks % (128 >> j)) && j < 7)
1084                  j++;
1085               repeat_blocks = read_blocks % (128 >> (j - 1));
1086
1087               memcpy( &snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1088               memcpy( &snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1089               read_blocks += repeat_blocks;
1090            }
1091         }
1092         break;
1093   }
1094
1095   /* Detect special chips */
1096   supported_type = snes_find_addon_chip(machine);
1097
1098   /* Find the amount of cart ram (even if we call it sram...) */
1099   if (image.software_entry() == NULL)
1100   {
1101      if ((state->m_has_addon_chip != HAS_SUPERFX))
1102         state->m_cart[0].sram = snes_r_bank1(space, 0x00ffd8);
1103      else
1104         state->m_cart[0].sram = (snes_r_bank1(space, 0x00ffbd) & 0x07);
1105
1106      if (state->m_cart[0].sram > 0)
1107      {
1108         state->m_cart[0].sram = (1024 << state->m_cart[0].sram);
1109         if (state->m_cart[0].sram > state->m_cart[0].sram_max)
1110            state->m_cart[0].sram = state->m_cart[0].sram_max;
1111      }
1112//      printf("size %x\n", state->m_cart[0].sram);
1113   }
1114   else
1115   {
1116      // if we are loading from softlist, take sram from the xml
1117      state->m_cart[0].sram = image.get_software_region("sram") ? image.get_software_region_length("sram") : 0;
1118
1119      if (state->m_cart[0].sram > 0)
1120      {
1121         if (state->m_cart[0].sram > state->m_cart[0].sram_max)
1122            fatalerror("Found more SRAM than max allowed (found: %x, max: %x), check xml file!\n", state->m_cart[0].sram, state->m_cart[0].sram_max);
1123      }
1124      // TODO: Eventually sram handlers should point to the allocated cart:sram region!
1125      // For now, we only use the region as a placeholder to carry size info...
1126//      printf("size %x\n", state->m_cart[0].sram);
1127   }
1128
1129   /* adjust size for very large carts */
1130   if (state->m_cart[0].mode == SNES_MODE_20 && ((state->m_cart_size - offset) > 0x200000 || state->m_cart[0].sram > (32 * 1024)))
1131      state->m_cart[0].small_sram = 1;
1132   else
1133      state->m_cart[0].small_sram = 0;
1134
1135   /* Log snes_cart information */
1136   snes_cart_log_info(machine, total_blocks, supported_type);
1137
1138   /* Load SRAM */
1139   snes_load_sram(machine);
1140
1141   /* All done */
1142   return IMAGE_INIT_PASS;
1143}
1144
1145static DEVICE_IMAGE_LOAD( sufami_cart )
1146{
1147   running_machine &machine = image.device().machine();
1148   snes_state *state = machine.driver_data<snes_state>();
1149   int total_blocks, read_blocks;
1150   int st_bios = 0, slot_id = 0;
1151   UINT32 offset, st_data_offset = 0;
1152   UINT8 *ROM = image.device().machine().region(image.device().tag())->base();
1153
1154   snes_ram = machine.region("maincpu")->base();
1155
1156   if (strcmp(image.device().tag(), "slot_a") == 0)
1157   {
1158      st_data_offset = 0x200000;
1159      slot_id = 0;
1160   }
1161
1162   if (strcmp(image.device().tag(), "slot_b") == 0)
1163   {
1164      st_data_offset = 0x400000;
1165      slot_id = 1;
1166   }
1167
1168   if (image.software_entry() == NULL)
1169      state->m_cart_size = image.length();
1170   else
1171      state->m_cart_size = image.get_software_region_length("rom");
1172
1173   /* Check for a header (512 bytes), and skip it if found */
1174   offset = snes_skip_header(image, state->m_cart_size);
1175
1176   if (image.software_entry() == NULL)
1177   {
1178      image.fseek(offset, SEEK_SET);
1179      image.fread( ROM, state->m_cart_size - offset);
1180   }
1181   else
1182      memcpy(ROM, image.get_software_region("rom") + offset, state->m_cart_size - offset);
1183
1184   if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", state->m_cart_size - offset);
1185
1186   /* Detect Sufami Turbo carts */
1187   if (!memcmp(ROM, "BANDAI SFC-ADX", 14))
1188   {
1189      state->m_cart[slot_id].mode = SNES_MODE_ST;
1190      if (!memcmp(ROM + 16, "SFC-ADX BACKUP", 14))
1191         st_bios = 1;
1192   }
1193   else
1194   {
1195      mame_printf_error("This is not a Sufami Turbo data pack.\n");
1196      mame_printf_error("This image cannot be loaded in snesst (Use snes or snespal drivers, instead).\n");
1197      return IMAGE_INIT_FAIL;
1198   }
1199
1200   if (st_bios == 1)
1201   {
1202      mame_printf_error("This is the Sufami Turbo BIOS and not a Sufami Turbo data pack.\n");
1203      mame_printf_error("This image cannot be loaded in snesst.\n");
1204      return IMAGE_INIT_FAIL;
1205   }
1206
1207   /* FIXME: Insert crc check here? */
1208
1209   /* How many blocks of data are available to be loaded? */
1210   total_blocks = (state->m_cart_size - offset) / 0x8000;
1211   read_blocks = 0;
1212
1213   if (SNES_CART_DEBUG)
1214      mame_printf_error("blocks %d\n", total_blocks);
1215
1216   // actually load the cart
1217   while (read_blocks < 32 && read_blocks < total_blocks)
1218   {
1219      /* Loading data */
1220      // CART (either A or B)
1221      memcpy(&snes_ram[0x008000 + st_data_offset + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000);
1222      /* Mirroring */
1223      memcpy(&snes_ram[0x808000 + st_data_offset + read_blocks * 0x10000], &snes_ram[0x8000 + st_data_offset + (read_blocks * 0x10000)], 0x8000);
1224
1225      read_blocks++;
1226   }
1227
1228   /* Filling banks up to 0x1f and their mirrors */
1229   while (read_blocks % 32)
1230   {
1231      int j = 0, repeat_blocks;
1232      while ((read_blocks % (32 >> j)) && j < 5)
1233         j++;
1234      repeat_blocks = read_blocks % (32 >> (j - 1));
1235
1236      memcpy(&snes_ram[st_data_offset + read_blocks * 0x10000], &snes_ram[st_data_offset + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1237      memcpy(&snes_ram[0x800000 + st_data_offset + read_blocks * 0x10000], &snes_ram[st_data_offset + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1238      read_blocks += repeat_blocks;
1239   }
1240
1241   sufami_load_sram(machine, image.device().tag());
1242
1243   state->m_cart[slot_id].slot_in_use = 1;   // aknowledge the cart in this slot, for saving sram at exit
1244
1245   auto_free(image.device().machine(), ROM);
1246
1247   return IMAGE_INIT_PASS;
1248}
1249
1250static DEVICE_IMAGE_LOAD( bsx_cart )
1251{
1252   running_machine &machine = image.device().machine();
1253   snes_state *state = machine.driver_data<snes_state>();
1254   int total_blocks, read_blocks;
1255   int has_bsx_slot = 0;
1256   UINT32 offset, int_header_offs;
1257   UINT8 *ROM = image.device().machine().region("cart")->base();
1258
1259   if (image.software_entry() == NULL)
1260      state->m_cart_size = image.length();
1261   else
1262      state->m_cart_size = image.get_software_region_length("rom");
1263
1264   /* Check for a header (512 bytes), and skip it if found */
1265   offset = snes_skip_header(image, state->m_cart_size);
1266
1267   if (image.software_entry() == NULL)
1268   {
1269      image.fseek(offset, SEEK_SET);
1270      image.fread( ROM, state->m_cart_size - offset);
1271   }
1272   else
1273      memcpy(ROM, image.get_software_region("rom") + offset, state->m_cart_size - offset);
1274
1275   if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", state->m_cart_size - offset);
1276
1277   /* First, look if the cart is HiROM or LoROM (and set snes_cart accordingly) */
1278   int_header_offs = snes_find_hilo_mode(image, ROM, offset, 0);
1279
1280   // Detect presence of BS-X flash cartridge connector
1281   if ((ROM[int_header_offs - 14] == 'Z') && (ROM[int_header_offs - 11] == 'J'))
1282   {
1283      UINT8 n13 = ROM[int_header_offs - 13];
1284      if ((n13 >= 'A' && n13 <= 'Z') || (n13 >= '0' && n13 <= '9'))
1285      {
1286         if (ROM[int_header_offs + 0x1a] == 0x33 ||
1287            (ROM[int_header_offs - 10] == 0x00 && ROM[int_header_offs - 4] == 0x00))
1288         {
1289            has_bsx_slot = 1;
1290         }
1291      }
1292   }
1293
1294   // If there is a BS-X connector, detect if it is the Base Cart or a compatible slotted cart
1295   if (has_bsx_slot)
1296   {
1297      if (!memcmp(ROM + int_header_offs, "Satellaview BS-X     ", 21))
1298      {
1299         //BS-X Base Cart
1300         state->m_cart[0].mode = SNES_MODE_BSX;
1301         // handle RAM
1302      }
1303      else
1304      {
1305         state->m_cart[0].mode = (int_header_offs ==0x007fc0) ? SNES_MODE_BSLO : SNES_MODE_BSHI;
1306         // handle RAM?
1307      }
1308   }
1309   else
1310   {
1311      mame_printf_error("This is not a BS-X compatible cart.\n");
1312      mame_printf_error("This image cannot be loaded in the first cartslot of snesbsx.\n");
1313      return IMAGE_INIT_FAIL;
1314   }
1315
1316
1317   /* FIXME: Insert crc check here? */
1318
1319   /* How many blocks of data are available to be loaded? */
1320   total_blocks = (state->m_cart_size - offset) / 0x8000;
1321   read_blocks = 0;
1322
1323   if (SNES_CART_DEBUG) mame_printf_error("blocks %d\n", total_blocks);
1324
1325   // actually load the cart
1326   while (read_blocks < 64 && read_blocks < total_blocks)
1327   {
1328      /* Loading data */
1329      memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000);
1330      /* Mirroring */
1331      memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0x8000 + (read_blocks * 0x10000)], 0x8000);
1332
1333      read_blocks++;
1334   }
1335
1336   /* Filling banks up to 0x3f and their mirrors */
1337   while (read_blocks % 64)
1338   {
1339      int j = 0, repeat_blocks;
1340      while ((read_blocks % (64 >> j)) && j < 6)
1341         j++;
1342      repeat_blocks = read_blocks % (64 >> (j - 1));
1343
1344      memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1345      memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1346      read_blocks += repeat_blocks;
1347   }
1348
1349   return IMAGE_INIT_PASS;
1350}
1351
1352static DEVICE_IMAGE_LOAD( bsx2slot_cart )
1353{
1354   running_machine &machine = image.device().machine();
1355   snes_state *state = machine.driver_data<snes_state>();
1356   UINT32 offset, int_header_offs;
1357   UINT8 *ROM = image.device().machine().region("flash")->base();
1358
1359   if (image.software_entry() == NULL)
1360      state->m_cart_size = image.length();
1361   else
1362      state->m_cart_size = image.get_software_region_length("rom");
1363
1364   /* Check for a header (512 bytes), and skip it if found */
1365   offset = snes_skip_header(image, state->m_cart_size);
1366
1367   if (image.software_entry() == NULL)
1368   {
1369      image.fseek(offset, SEEK_SET);
1370      image.fread( ROM, state->m_cart_size - offset);
1371   }
1372   else
1373      memcpy(ROM, image.get_software_region("rom") + offset, state->m_cart_size - offset);
1374
1375   if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", state->m_cart_size - offset);
1376
1377   /* First, look if the cart is HiROM or LoROM (and set snes_cart accordingly) */
1378   int_header_offs = snes_find_hilo_mode(image, ROM, offset, 1);
1379
1380   // Detect presence of BS-X Flash Cart
1381   if ((ROM[int_header_offs + 0x13] == 0x00 || ROM[int_header_offs + 0x13] == 0xff) &&
1382      ROM[int_header_offs + 0x14] == 0x00)
1383   {
1384      UINT8 n15 = ROM[int_header_offs + 0x15];
1385      if (n15 == 0x00 || n15 == 0x80 || n15 == 0x84 || n15 == 0x9c || n15 == 0xbc || n15 == 0xfc)
1386      {
1387         if (ROM[int_header_offs + 0x1a] == 0x33 || ROM[int_header_offs + 0x1a] == 0xff)
1388         {
1389            // BS-X Flash Cart
1390            state->m_cart[1].mode = SNES_MODE_BSX;
1391         }
1392      }
1393   }
1394
1395   if (state->m_cart[1].mode != SNES_MODE_BSX)
1396   {
1397      mame_printf_error("This is not a BS-X flash cart.\n");
1398      mame_printf_error("This image cannot be loaded in the second cartslot of snesbsx.\n");
1399      return IMAGE_INIT_FAIL;
1400   }
1401
1402   // actually load the cart
1403   return IMAGE_INIT_PASS;
1404}
1405
1406MACHINE_CONFIG_FRAGMENT( snes_cartslot )
1407   MCFG_CARTSLOT_ADD("cart")
1408   MCFG_CARTSLOT_EXTENSION_LIST("sfc,smc,fig,swc,bin")
1409   MCFG_CARTSLOT_NOT_MANDATORY
1410   MCFG_CARTSLOT_INTERFACE("snes_cart")
1411   MCFG_CARTSLOT_LOAD(snes_cart)
1412   MCFG_SOFTWARE_LIST_ADD("cart_list","snes")
1413MACHINE_CONFIG_END
1414
1415// This (hackily) emulates a SNES unit with a Sufami Turbo Unit cart inserted:
1416// hence, the user can mount two data cart in the two slots available on the ST Unit
1417MACHINE_CONFIG_FRAGMENT( sufami_cartslot )
1418   MCFG_CARTSLOT_ADD("slot_a")
1419   MCFG_CARTSLOT_EXTENSION_LIST("st,sfc")
1420   MCFG_CARTSLOT_NOT_MANDATORY
1421   MCFG_CARTSLOT_INTERFACE("sufami_cart")
1422   MCFG_CARTSLOT_LOAD(sufami_cart)
1423
1424   MCFG_CARTSLOT_ADD("slot_b")
1425   MCFG_CARTSLOT_EXTENSION_LIST("st,sfc")
1426   MCFG_CARTSLOT_NOT_MANDATORY
1427   MCFG_CARTSLOT_INTERFACE("sufami_cart")
1428   MCFG_CARTSLOT_LOAD(sufami_cart)
1429
1430//  MCFG_SOFTWARE_LIST_ADD("cart_list","snes")
1431MACHINE_CONFIG_END
1432
1433// This (hackily) emulates a SNES unit where you want to load a BS-X compatible cart:
1434// hence, the user can mount a SNES cart in the first slot (either a BS-X BIOS cart, or a
1435// BS-X compatible one, e.g. Same Game), and there is a second slot for the 8M data pack
1436// (in a real SNES this would have been inserted in the smaller slot on the cart itself)
1437MACHINE_CONFIG_FRAGMENT( bsx_cartslot )
1438   MCFG_CARTSLOT_ADD("cart")
1439   MCFG_CARTSLOT_EXTENSION_LIST("sfc,smc,fig,swc,bin")
1440   MCFG_CARTSLOT_NOT_MANDATORY
1441   MCFG_CARTSLOT_INTERFACE("snes_cart")
1442   MCFG_CARTSLOT_LOAD(bsx_cart)
1443
1444   MCFG_CARTSLOT_ADD("slot2")
1445   MCFG_CARTSLOT_EXTENSION_LIST("bs,sfc")
1446   MCFG_CARTSLOT_NOT_MANDATORY
1447   MCFG_CARTSLOT_INTERFACE("bsx_cart")
1448   MCFG_CARTSLOT_LOAD(bsx2slot_cart)
1449
1450//  MCFG_SOFTWARE_LIST_ADD("cart_list","snes")
1451MACHINE_CONFIG_END
1452
1453DRIVER_INIT( snes_mess )
1454{
1455   snes_ram = machine.region("maincpu")->base();
1456   memset(snes_ram, 0, 0x1000000);
1457}
1458
1459DRIVER_INIT( snesst )
1460{
1461   snes_state *state = machine.driver_data<snes_state>();
1462   UINT8 *STBIOS = machine.region("sufami")->base();
1463   int i, j;
1464
1465   state->m_cart[0].slot_in_use = 0;
1466   state->m_cart[1].slot_in_use = 0;
1467
1468   DRIVER_INIT_CALL(snes_mess);
1469
1470   // the Base ST cart consists of 8 * 0x8000 block which have to be loaded (and mirrored)
1471   // at 0x00-0x1f:0x8000-0xffff and 0x80-0x9f:0x8000-0xffff
1472   for (i = 0; i < 8; i++)
1473   {
1474      /* Loading data */
1475      memcpy(&snes_ram[0x008000 + i * 0x10000], &STBIOS[0x000000 + i * 0x8000], 0x8000);
1476      /* Mirroring */
1477      memcpy(&snes_ram[0x808000 + i * 0x10000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000);
1478
1479      /* Additional mirrors (to fill snes_ram up to 0x1fffff) */
1480      for (j = 1; j < 4; j++)
1481      {
1482         memcpy(&snes_ram[0x008000 + i * 0x10000 + j * 0x80000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000);
1483         memcpy(&snes_ram[0x808000 + i * 0x10000 + j * 0x80000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000);
1484      }
1485   }
1486
1487}
src/mame/machine/snescart.h
r0r11461
1/*
2    snescart.h
3
4*/
5
6#ifndef _SNESCART_H
7#define _SNESCART_H
8
9#include "imagedev/cartslot.h"
10
11MACHINE_START( snes_mess );
12MACHINE_START( snesst );
13
14DRIVER_INIT( snes_mess );
15DRIVER_INIT( snesst );
16
17MACHINE_CONFIG_EXTERN( snes_cartslot );
18MACHINE_CONFIG_EXTERN( sufami_cartslot );
19MACHINE_CONFIG_EXTERN( bsx_cartslot );
20
21#endif /* _SNESCART_H */
22
src/mame/machine/pce.c
r0r11461
1/************************************************************
2
3PC Engine CD HW notes:
4
5CD Interface Register 0x00 - CDC status
6x--- ---- busy signal
7-x-- ---- request signal
8---x ---- cd signal
9---- x--- i/o signal
10
11CD Interface Register 0x03 - BRAM lock / CD status
12-x-- ---- acknowledge signal
13--x- ---- done signal
14---x ---- bram signal
15---- x--- ADPCM 2
16---- -x-- ADPCM 1
17---- --x- CDDA left/right speaker select
18
19CD Interface Register 0x05 - CD-DA Volume low 8-bit port
20
21CD Interface Register 0x06 - CD-DA Volume high 8-bit port
22
23CD Interface Register 0x07 - BRAM unlock / CD status
24x--- ---- Enables BRAM
25
26CD Interface Register 0x0c - ADPCM status
27x--- ---- ADPCM is reading data
28---- x--- ADPCM playback (0) stopped (1) currently playing
29---- -x-- pending ADPCM data write
30---- ---x ADPCM playback (1) stopped (0) currently playing
31
32CD Interface Register 0x0d - ADPCM address control
33x--- ---- ADPCM reset
34-x-- ---- ADPCM play
35--x- ---- ADPCM repeat
36---x ---- ADPCM set length
37---- x--- ADPCM set read address
38---- --xx ADPCM set write address
39(note: some games reads bit 5 and wants it to be low otherwise they hangs, surely NOT an ADPCM repeat flag read because it doesn't make sense)
40
41CD Interface Register 0x0e - ADPCM playback rate
42
43CD Interface Register 0x0f - ADPCM fade in/out register
44---- xxxx command setting:
450x00 ADPCM/CD-DA Fade-in
460x01 CD-DA fade-in
470x08 CD-DA fade-out (short) ADPCM fade-in
480x09 CD-DA fade-out (long)
490x0a ADPCM fade-out (long)
500x0c CD-DA fade-out (short) ADPCM fade-in
510x0d CD-DA fade-out (short)
520x0e ADPCM fade-out (short)
53
54*************************************************************/
55
56#include "emu.h"
57#include "coreutil.h"
58#include "cpu/h6280/h6280.h"
59#include "includes/pce.h"
60#include "imagedev/chd_cd.h"
61#include "sound/msm5205.h"
62#include "sound/cdda.h"
63#include "hashfile.h"
64
65
66#define PCE_BRAM_SIZE            0x800
67#define PCE_ADPCM_RAM_SIZE         0x10000
68#define PCE_ACARD_RAM_SIZE         0x200000
69#define PCE_CD_COMMAND_BUFFER_SIZE   0x100
70
71#define PCE_CD_IRQ_TRANSFER_READY      0x40
72#define PCE_CD_IRQ_TRANSFER_DONE      0x20
73#define PCE_CD_IRQ_SAMPLE_FULL_PLAY      0x08
74#define PCE_CD_IRQ_SAMPLE_HALF_PLAY      0x04
75
76#define PCE_CD_ADPCM_PLAY_FLAG      0x08
77#define PCE_CD_ADPCM_STOP_FLAG      0x01
78
79#define PCE_CD_DATA_FRAMES_PER_SECOND   75
80
81enum {
82   PCE_CD_CDDA_OFF=0,
83   PCE_CD_CDDA_PLAYING,
84   PCE_CD_CDDA_PAUSED
85};
86
87
88/* CD Unit RAM */
89
90/* MSM5205 ADPCM decoder definition */
91static void pce_cd_msm5205_int(device_t *device);
92const msm5205_interface pce_cd_msm5205_interface = {
93   pce_cd_msm5205_int,   /* interrupt function */
94   MSM5205_S48_4B      /* 1/48 prescaler, 4bit data */
95};
96
97
98/* joystick related data*/
99
100#define JOY_CLOCK   0x01
101#define JOY_RESET   0x02
102
103
104/* prototypes */
105static void pce_cd_init( running_machine &machine );
106static void pce_cd_set_irq_line( running_machine &machine, int num, int state );
107static TIMER_CALLBACK( pce_cd_adpcm_dma_timer_callback );
108static TIMER_CALLBACK( pce_cd_cdda_fadeout_callback );
109static TIMER_CALLBACK( pce_cd_cdda_fadein_callback );
110static TIMER_CALLBACK( pce_cd_adpcm_fadeout_callback );
111static TIMER_CALLBACK( pce_cd_adpcm_fadein_callback );
112
113static WRITE8_HANDLER( pce_sf2_banking_w )
114{
115   memory_set_bankptr( space->machine(), "bank2", space->machine().region("user1")->base() + offset * 0x080000 + 0x080000 );
116   memory_set_bankptr( space->machine(), "bank3", space->machine().region("user1")->base() + offset * 0x080000 + 0x088000 );
117   memory_set_bankptr( space->machine(), "bank4", space->machine().region("user1")->base() + offset * 0x080000 + 0x0D0000 );
118}
119
120static WRITE8_HANDLER( pce_cartridge_ram_w )
121{
122   pce_state *state = space->machine().driver_data<pce_state>();
123   state->m_cartridge_ram[offset] = data;
124}
125
126DEVICE_IMAGE_LOAD(pce_cart)
127{
128   pce_state *state = image.device().machine().driver_data<pce_state>();
129   UINT32 size;
130   int split_rom = 0, offset = 0;
131   const char *extrainfo = NULL;
132   unsigned char *ROM;
133   logerror("*** DEVICE_IMAGE_LOAD(pce_cart) : %s\n", image.filename());
134
135   /* open file to get size */
136   ROM = image.device().machine().region("user1")->base();
137
138   if (image.software_entry() == NULL)
139      size = image.length();
140   else
141      size = image.get_software_region_length("rom");
142
143   /* handle header accordingly */
144   if ((size / 512) & 1)
145   {
146      logerror("*** DEVICE_IMAGE_LOAD(pce_cart) : Header present\n");
147      size -= 512;
148      offset = 512;
149   }
150
151   if (size > PCE_ROM_MAXSIZE)
152      size = PCE_ROM_MAXSIZE;
153
154   if (image.software_entry() == NULL)
155   {
156      image.fseek(offset, SEEK_SET);
157      image.fread( ROM, size);
158      extrainfo = hashfile_extrainfo(image);
159   }
160   else
161      memcpy(ROM, image.get_software_region("rom") + offset, size);
162
163   if (extrainfo)
164   {
165      logerror("extrainfo: %s\n", extrainfo);
166      if (strstr(extrainfo, "ROM_SPLIT"))
167         split_rom = 1;
168   }
169
170   if (ROM[0x1fff] < 0xe0)
171   {
172      int i;
173      UINT8 decrypted[256];
174
175      logerror( "*** DEVICE_IMAGE_LOAD(pce_cart) : ROM image seems encrypted, decrypting...\n" );
176
177      /* Initialize decryption table */
178      for (i = 0; i < 256; i++)
179         decrypted[i] = ((i & 0x01) << 7) | ((i & 0x02) << 5) | ((i & 0x04) << 3) | ((i & 0x08) << 1) | ((i & 0x10) >> 1) | ((i & 0x20 ) >> 3) | ((i & 0x40) >> 5) | ((i & 0x80) >> 7);
180
181      /* Decrypt ROM image */
182      for (i = 0; i < size; i++)
183         ROM[i] = decrypted[ROM[i]];
184   }
185
186   /* check if we're dealing with a split rom image */
187   if (size == 384 * 1024)
188   {
189      split_rom = 1;
190      /* Mirror the upper 128KB part of the image */
191      memcpy(ROM + 0x060000, ROM + 0x040000, 0x020000);   /* Set up 060000 - 07FFFF mirror */
192   }
193
194   /* set up the memory for a split rom image */
195   if (split_rom)
196   {
197      logerror("Split rom detected, setting up memory accordingly\n");
198      /* Set up ROM address space as follows:          */
199      /* 000000 - 03FFFF : ROM data 000000 - 03FFFF    */
200      /* 040000 - 07FFFF : ROM data 000000 - 03FFFF    */
201      /* 080000 - 0BFFFF : ROM data 040000 - 07FFFF    */
202      /* 0C0000 - 0FFFFF : ROM data 040000 - 07FFFF    */
203      memcpy(ROM + 0x080000, ROM + 0x040000, 0x040000);   /* Set up 080000 - 0BFFFF region */
204      memcpy(ROM + 0x0C0000, ROM + 0x040000, 0x040000);   /* Set up 0C0000 - 0FFFFF region */
205      memcpy(ROM + 0x040000, ROM, 0x040000);      /* Set up 040000 - 07FFFF region */
206   }
207   else
208   {
209      /* mirror 256KB rom data */
210      if (size <= 0x040000)
211         memcpy(ROM + 0x040000, ROM, 0x040000);
212
213      /* mirror 512KB rom data */
214      if (size <= 0x080000)
215         memcpy(ROM + 0x080000, ROM, 0x080000);
216   }
217
218   memory_set_bankptr(image.device().machine(), "bank1", ROM);
219   memory_set_bankptr(image.device().machine(), "bank2", ROM + 0x080000);
220   memory_set_bankptr(image.device().machine(), "bank3", ROM + 0x088000);
221   memory_set_bankptr(image.device().machine(), "bank4", ROM + 0x0d0000);
222
223   /* Check for Street fighter 2 */
224   if (size == PCE_ROM_MAXSIZE)
225   {
226      image.device().machine().device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x01ff0, 0x01ff3, FUNC(pce_sf2_banking_w));
227   }
228
229   /* Check for Populous */
230   if (!memcmp(ROM + 0x1F26, "POPULOUS", 8))
231   {
232      state->m_cartridge_ram = auto_alloc_array(image.device().machine(), UINT8, 0x8000);
233      memory_set_bankptr(image.device().machine(), "bank2", state->m_cartridge_ram);
234      image.device().machine().device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x080000, 0x087FFF, FUNC(pce_cartridge_ram_w));
235   }
236
237   /* Check for CD system card */
238   state->m_sys3_card = 0;
239   if (!memcmp(ROM + 0x3FFB6, "PC Engine CD-ROM SYSTEM", 23))
240   {
241      /* Check if 192KB additional system card ram should be used */
242      if(!memcmp(ROM + 0x29D1, "VER. 3.", 7))       { state->m_sys3_card = 1; } // JP version
243      else if(!memcmp(ROM + 0x29C4, "VER. 3.", 7 ))   { state->m_sys3_card = 3; } // US version
244
245      if(state->m_sys3_card)
246      {
247         state->m_cartridge_ram = auto_alloc_array(image.device().machine(), UINT8, 0x30000);
248         memory_set_bankptr(image.device().machine(), "bank4", state->m_cartridge_ram);
249         image.device().machine().device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x0D0000, 0x0FFFFF, FUNC(pce_cartridge_ram_w));
250         image.device().machine().device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_readwrite_handler(0x080000, 0x087FFF, FUNC(pce_cd_acard_wram_r),FUNC(pce_cd_acard_wram_w));
251      }
252   }
253   return 0;
254}
255
256#ifdef MESS
257DRIVER_INIT( pce )
258{
259   pce_state *state = machine.driver_data<pce_state>();
260   state->m_io_port_options = PCE_JOY_SIG | CONST_SIG;
261}
262#endif
263
264DRIVER_INIT( tg16 )
265{
266   pce_state *state = machine.driver_data<pce_state>();
267   state->m_io_port_options = TG_16_JOY_SIG | CONST_SIG;
268}
269
270DRIVER_INIT( sgx )
271{
272   pce_state *state = machine.driver_data<pce_state>();
273   state->m_io_port_options = PCE_JOY_SIG | CONST_SIG;
274}
275
276MACHINE_START( pce )
277{
278   pce_cd_init( machine );
279}
280
281#ifdef MESS
282MACHINE_RESET( pce )
283{
284   pce_state *state = machine.driver_data<pce_state>();
285   pce_cd_t &pce_cd = state->m_cd;
286   int joy_i;
287
288   for (joy_i = 0; joy_i < 5; joy_i++)
289      state->m_joy_6b_packet[joy_i] = 0;
290
291   pce_cd.adpcm_read_buf = 0;
292   pce_cd.adpcm_write_buf = 0;
293
294   // TODO: add CD-DA stop command here
295
296   pce_cd.regs[0x0c] |= PCE_CD_ADPCM_STOP_FLAG;
297   pce_cd.regs[0x0c] &= ~PCE_CD_ADPCM_PLAY_FLAG;
298   //pce_cd.regs[0x03] = (pce_cd.regs[0x03] & ~0x0c) | (PCE_CD_SAMPLE_STOP_PLAY);
299
300   /* Note: Arcade Card BIOS contents are the same as System 3, only internal HW differs.
301       We use a category to select between modes (some games can be run in either S-CD or A-CD modes) */
302   state->m_acard = input_port_read(machine, "A_CARD") & 1;
303}
304
305/* todo: how many input ports does the PCE have? */
306WRITE8_HANDLER ( pce_joystick_w )
307{
308   pce_state *state = space->machine().driver_data<pce_state>();
309   int joy_i;
310   UINT8 joy_type = input_port_read(space->machine(),"JOY_TYPE");
311
312   h6280io_set_buffer(&space->device(), data);
313
314    /* bump counter on a low-to-high transition of bit 1 */
315    if ((!state->m_joystick_data_select) && (data & JOY_CLOCK))
316    {
317        state->m_joystick_port_select = (state->m_joystick_port_select + 1) & 0x07;
318    }
319
320    /* do we want buttons or direction? */
321    state->m_joystick_data_select = data & JOY_CLOCK;
322
323    /* clear counter if bit 2 is set */
324    if (data & JOY_RESET)
325    {
326      state->m_joystick_port_select = 0;
327
328      for (joy_i = 0; joy_i < 5; joy_i++)
329      {
330         if (((joy_type >> (joy_i*2)) & 3) == 2)
331              state->m_joy_6b_packet[joy_i] ^= 1;
332      }
333    }
334}
335
336READ8_HANDLER ( pce_joystick_r )
337{
338   pce_state *state = space->machine().driver_data<pce_state>();
339   static const char *const joyname[4][5] = {
340      { "JOY_P1", "JOY_P2", "JOY_P3", "JOY_P4", "JOY_P5" },
341      { },
342      { "JOY6B_P1", "JOY6B_P2", "JOY6B_P3", "JOY6B_P4", "JOY6B_P5" },
343      { }
344   };
345   UINT8 joy_type = input_port_read(space->machine(), "JOY_TYPE");
346   UINT8 ret, data;
347
348   if (state->m_joystick_port_select <= 4)
349   {
350      switch((joy_type >> (state->m_joystick_port_select*2)) & 3)
351      {
352         case 0: //2-buttons pad
353            data = input_port_read(space->machine(), joyname[0][state->m_joystick_port_select]);
354            break;
355         case 2: //6-buttons pad
356            /*
357                Two packets:
358                1st packet: directions + I, II, Run, Select
359                2nd packet: 6 buttons "header" (high 4 bits active low) + III, IV, V, VI
360                Note that six buttons pad just doesn't work with (almost?) every single 2-button-only games, it's really just an after-thought and it is like this
361                on real HW.
362                */
363            data = input_port_read(space->machine(), joyname[2][state->m_joystick_port_select]) >> (state->m_joy_6b_packet[state->m_joystick_port_select]*8);
364            break;
365         default:
366            data = 0xff;
367            break;
368      }
369   }
370   else
371      data = 0xff;
372
373
374   if (state->m_joystick_data_select)
375      data >>= 4;
376
377   ret = (data & 0x0f) | state->m_io_port_options;
378#ifdef UNIFIED_PCE
379   ret &= ~0x40;
380#endif
381
382   return (ret);
383}
384#endif
385NVRAM_HANDLER( pce )
386{
387   pce_state *state = machine.driver_data<pce_state>();
388   pce_cd_t &pce_cd = state->m_cd;
389   if (read_or_write)
390   {
391      file->write(pce_cd.bram, PCE_BRAM_SIZE);
392   }
393   else
394   {
395      /* load battery backed memory from disk */
396      if (file)
397         file->read(pce_cd.bram, PCE_BRAM_SIZE);
398   }
399}
400
401static void pce_set_cd_bram( running_machine &machine )
402{
403   pce_state *state = machine.driver_data<pce_state>();
404   pce_cd_t &pce_cd = state->m_cd;
405   memory_set_bankptr( machine, "bank10", pce_cd.bram + ( pce_cd.bram_locked ? PCE_BRAM_SIZE : 0 ) );
406}
407
408static void adpcm_stop(running_machine &machine)
409{
410   pce_state *state = machine.driver_data<pce_state>();
411   pce_cd_t &pce_cd = state->m_cd;
412   pce_cd.regs[0x0c] |= PCE_CD_ADPCM_STOP_FLAG;
413   pce_cd.regs[0x0c] &= ~PCE_CD_ADPCM_PLAY_FLAG;
414   //pce_cd.regs[0x03] = (pce_cd.regs[0x03] & ~0x0c) | (PCE_CD_SAMPLE_STOP_PLAY);
415   pce_cd_set_irq_line( machine, PCE_CD_IRQ_SAMPLE_FULL_PLAY, ASSERT_LINE );
416   pce_cd.regs[0x0d] &= ~0x60;
417   pce_cd.msm_idle = 1;
418}
419
420static void adpcm_play(running_machine &machine)
421{
422   pce_state *state = machine.driver_data<pce_state>();
423   pce_cd_t &pce_cd = state->m_cd;
424   pce_cd.regs[0x0c] &= ~PCE_CD_ADPCM_STOP_FLAG;
425   pce_cd.regs[0x0c] |= PCE_CD_ADPCM_PLAY_FLAG;
426   pce_cd_set_irq_line( machine, PCE_CD_IRQ_SAMPLE_FULL_PLAY, CLEAR_LINE );
427   pce_cd.regs[0x03] = (pce_cd.regs[0x03] & ~0x0c);
428   pce_cd.msm_idle = 0;
429}
430
431
432/* Callback for new data from the MSM5205.
433  The PCE cd unit actually divides the clock signal supplied to
434  the MSM5205. Currently we can only use static clocks for the
435  MSM5205.
436 */
437static void pce_cd_msm5205_int(device_t *device)
438{
439   pce_state *state = device->machine().driver_data<pce_state>();
440   pce_cd_t &pce_cd = state->m_cd;
441   UINT8 msm_data;
442
443//  popmessage("%08x %08x %08x %02x %02x",pce_cd.msm_start_addr,pce_cd.msm_end_addr,pce_cd.msm_half_addr,pce_cd.regs[0x0c],pce_cd.regs[0x0d]);
444
445   if ( pce_cd.msm_idle )
446      return;
447
448   /* Supply new ADPCM data */
449   msm_data = (pce_cd.msm_nibble) ? (pce_cd.adpcm_ram[pce_cd.msm_start_addr] & 0x0f) : ((pce_cd.adpcm_ram[pce_cd.msm_start_addr] & 0xf0) >> 4);
450
451   msm5205_data_w(device, msm_data);
452   pce_cd.msm_nibble ^= 1;
453
454   if(pce_cd.msm_nibble == 0)
455   {
456      pce_cd.msm_start_addr++;
457
458      if(pce_cd.msm_start_addr == pce_cd.msm_half_addr)
459      {
460         //pce_cd_set_irq_line( device->machine(), PCE_CD_IRQ_SAMPLE_FULL_PLAY, CLEAR_LINE );
461         //pce_cd_set_irq_line( device->machine(), PCE_CD_IRQ_SAMPLE_HALF_PLAY, ASSERT_LINE );
462      }
463
464      if(pce_cd.msm_start_addr > pce_cd.msm_end_addr)
465      {
466         //pce_cd_set_irq_line( device->machine(), PCE_CD_IRQ_SAMPLE_HALF_PLAY, CLEAR_LINE );
467         //pce_cd_set_irq_line( device->machine(), PCE_CD_IRQ_SAMPLE_FULL_PLAY, CLEAR_LINE );
468         adpcm_stop(device->machine());
469         msm5205_reset_w(device, 1);
470      }
471   }
472}
473
474#define   SCSI_STATUS_OK         0x00
475#define SCSI_CHECK_CONDITION   0x02
476
477static void pce_cd_reply_status_byte( pce_state *state, UINT8 status )
478{
479   pce_cd_t &pce_cd = state->m_cd;
480logerror("Setting CD in reply_status_byte\n");
481   pce_cd.scsi_CD = pce_cd.scsi_IO = pce_cd.scsi_REQ = 1;
482   pce_cd.scsi_MSG = 0;
483   pce_cd.message_after_status = 1;
484   pce_cd.status_sent = pce_cd.message_sent = 0;
485
486   if ( status == SCSI_STATUS_OK )
487   {
488      pce_cd.regs[0x01] = 0x00;
489   }
490   else
491   {
492      pce_cd.regs[0x01] = 0x01;
493   }
494}
495
496/* 0x00 - TEST UNIT READY */
497static void pce_cd_test_unit_ready( running_machine &machine )
498{
499   pce_state *state = machine.driver_data<pce_state>();
500   pce_cd_t &pce_cd = state->m_cd;
501   logerror("test unit ready\n");
502   if ( pce_cd.cd )
503   {
504      logerror( "Sending STATUS_OK status\n" );
505      pce_cd_reply_status_byte( state, SCSI_STATUS_OK );
506   }
507   else
508   {
509      logerror( "Sending CHECK_CONDITION status\n" );
510      pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
511   }
512}
513
514/* 0x08 - READ (6) */
515static void pce_cd_read_6( running_machine &machine )
516{
517   pce_state *state = machine.driver_data<pce_state>();
518   pce_cd_t &pce_cd = state->m_cd;
519   UINT32 frame = ( ( pce_cd.command_buffer[1] & 0x1F ) << 16 ) | ( pce_cd.command_buffer[2] << 8 ) | pce_cd.command_buffer[3];
520   UINT32 frame_count = pce_cd.command_buffer[4];
521
522   /* Check for presence of a CD */
523   if ( ! pce_cd.cd )
524   {
525      pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
526      return;
527   }
528
529   if ( pce_cd.cdda_status != PCE_CD_CDDA_OFF )
530   {
531      pce_cd.cdda_status = PCE_CD_CDDA_OFF;
532      cdda_stop_audio( machine.device( "cdda" ) );
533      pce_cd.end_mark = 0;
534   }
535
536   pce_cd.current_frame = frame;
537   pce_cd.end_frame = frame + frame_count;
538
539   if ( frame_count == 0 )
540   {
541      /* Star Breaker uses this */
542      popmessage("Read Sector frame count == 0, contact MESSdev");
543      pce_cd_reply_status_byte( state, SCSI_STATUS_OK );
544   }
545   else
546   {
547      pce_cd.data_timer->adjust(attotime::from_hz( PCE_CD_DATA_FRAMES_PER_SECOND ), 0, attotime::from_hz( PCE_CD_DATA_FRAMES_PER_SECOND ));
548   }
549}
550
551/* 0xD8 - SET AUDIO PLAYBACK START POSITION (NEC) */
552static void pce_cd_nec_set_audio_start_position( running_machine &machine )
553{
554   pce_state *state = machine.driver_data<pce_state>();
555   pce_cd_t &pce_cd = state->m_cd;
556   UINT32   frame = 0;
557
558   if ( ! pce_cd.cd )
559   {
560      /* Throw some error here */
561      pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
562      return;
563   }
564
565   switch( pce_cd.command_buffer[9] & 0xC0 )
566   {
567   case 0x00:
568      popmessage("CD-DA set start mode 0x00, contact MESSdev");
569      frame = ( pce_cd.command_buffer[3] << 16 ) | ( pce_cd.command_buffer[4] << 8 ) | pce_cd.command_buffer[5];
570      break;
571   case 0x40:
572   {
573      UINT8 m,s,f;
574
575      m = bcd_2_dec( pce_cd.command_buffer[2]);
576      s = bcd_2_dec( pce_cd.command_buffer[3]);
577      f = bcd_2_dec( pce_cd.command_buffer[4]);
578
579      frame = f + 75 * (s + m * 60);
580      if(frame >= 525) // TODO: seven seconds gap? O_o
581         frame -= 525;
582      break;
583   }
584   case 0x80:
585      frame = pce_cd.toc->tracks[ bcd_2_dec( pce_cd.command_buffer[2] ) - 1 ].physframeofs;
586      break;
587   default:
588      popmessage("CD-DA set start mode 0xc0, contact MESSdev");
589      //assert( NULL == pce_cd_nec_set_audio_start_position );
590      break;
591   }
592
593   pce_cd.current_frame = frame;
594
595   if ( pce_cd.cdda_status == PCE_CD_CDDA_PAUSED )
596   {
597      pce_cd.cdda_status = PCE_CD_CDDA_OFF;
598      cdda_stop_audio( machine.device( "cdda" ) );
599      pce_cd.end_frame = pce_cd.last_frame;
600      pce_cd.end_mark = 0;
601   }
602   else
603   {
604      if(pce_cd.command_buffer[1] & 0x03)
605      {
606         pce_cd.cdda_status = PCE_CD_CDDA_PLAYING;
607         pce_cd.end_frame = pce_cd.last_frame; //get the end of the CD
608         cdda_start_audio( machine.device( "cdda" ), pce_cd.current_frame, pce_cd.end_frame - pce_cd.current_frame );
609         pce_cd.cdda_play_mode = (pce_cd.command_buffer[1] & 0x02) ? 2 : 3; // mode 2 sets IRQ at end
610         pce_cd.end_mark =  (pce_cd.command_buffer[1] & 0x02) ? 1 : 0;
611      }
612      else
613      {
614         pce_cd.cdda_status = PCE_CD_CDDA_PLAYING;
615         pce_cd.end_frame = pce_cd.toc->tracks[ cdrom_get_track(pce_cd.cd, pce_cd.current_frame) + 1 ].physframeofs; //get the end of THIS track
616         cdda_start_audio( machine.device( "cdda" ), pce_cd.current_frame, pce_cd.end_frame - pce_cd.current_frame );
617         pce_cd.end_mark = 0;
618         pce_cd.cdda_play_mode = 3;
619      }
620   }
621
622   pce_cd_reply_status_byte( state, SCSI_STATUS_OK );
623   pce_cd_set_irq_line( machine, PCE_CD_IRQ_TRANSFER_DONE, ASSERT_LINE );
624}
625
626/* 0xD9 - SET AUDIO PLAYBACK END POSITION (NEC) */
627static void pce_cd_nec_set_audio_stop_position( running_machine &machine )
628{
629   pce_state *state = machine.driver_data<pce_state>();
630   pce_cd_t &pce_cd = state->m_cd;
631   UINT32  frame = 0;
632
633   if ( ! pce_cd.cd )
634   {
635      /* Throw some error here */
636      pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
637      return;
638   }
639
640   switch( pce_cd.command_buffer[9] & 0xC0 )
641   {
642   case 0x00:
643      popmessage("CD-DA set end mode 0x00, contact MESSdev");
644      frame = ( pce_cd.command_buffer[3] << 16 ) | ( pce_cd.command_buffer[4] << 8 ) | pce_cd.command_buffer[5];
645      break;
646   case 0x40:
647   {
648      UINT8 m,s,f;
649
650      m = bcd_2_dec( pce_cd.command_buffer[2]);
651      s = bcd_2_dec( pce_cd.command_buffer[3]);
652      f = bcd_2_dec( pce_cd.command_buffer[4]);
653
654      frame = f + 75 * (s + m * 60);
655      if(frame >= 525) // TODO: seven seconds gap? O_o
656         frame -= 525;
657      break;
658   }
659   case 0x80:
660      frame = pce_cd.toc->tracks[ bcd_2_dec( pce_cd.command_buffer[2] ) - 1 ].physframeofs;
661      break;
662   default:
663      popmessage("CD-DA set end mode 0xc0, contact MESSdev");
664      //assert( NULL == pce_cd_nec_set_audio_start_position );
665      break;
666   }
667
668   pce_cd.end_frame = frame;
669   pce_cd.cdda_play_mode = pce_cd.command_buffer[1] & 0x03;
670
671   if ( pce_cd.cdda_play_mode )
672   {
673      if ( pce_cd.cdda_status == PCE_CD_CDDA_PAUSED )
674      {
675         cdda_pause_audio( machine.device( "cdda" ), 0 );
676      }
677      else
678      {
679         cdda_start_audio( machine.device( "cdda" ), pce_cd.current_frame, pce_cd.end_frame - pce_cd.current_frame );
680         pce_cd.end_mark = 1;
681      }
682      pce_cd.cdda_status = PCE_CD_CDDA_PLAYING;
683   }
684   else
685   {
686      pce_cd.cdda_status = PCE_CD_CDDA_OFF;
687      cdda_stop_audio( machine.device( "cdda" ) );
688      pce_cd.end_frame = pce_cd.last_frame;
689      pce_cd.end_mark = 0;
690//      assert( NULL == pce_cd_nec_set_audio_stop_position );
691   }
692
693   pce_cd_reply_status_byte( state, SCSI_STATUS_OK );
694   pce_cd_set_irq_line( machine, PCE_CD_IRQ_TRANSFER_DONE, ASSERT_LINE );
695}
696
697/* 0xDA - PAUSE (NEC) */
698static void pce_cd_nec_pause( running_machine &machine )
699{
700   pce_state *state = machine.driver_data<pce_state>();
701   pce_cd_t &pce_cd = state->m_cd;
702
703   /* If no cd mounted throw an error */
704   if ( ! pce_cd.cd )
705   {
706      pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
707      return;
708   }
709
710   /* If there was no cdda playing, throw an error */
711   if ( pce_cd.cdda_status == PCE_CD_CDDA_OFF )
712   {
713      pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
714      return;
715   }
716
717   pce_cd.cdda_status = PCE_CD_CDDA_PAUSED;
718   pce_cd.current_frame = cdda_get_audio_lba( machine.device( "cdda" ) );
719   cdda_pause_audio( machine.device( "cdda" ), 1 );
720   pce_cd_reply_status_byte( state, SCSI_STATUS_OK );
721}
722
723/* 0xDD - READ SUBCHANNEL Q (NEC) */
724static void pce_cd_nec_get_subq( running_machine &machine )
725{
726   pce_state *state = machine.driver_data<pce_state>();
727   pce_cd_t &pce_cd = state->m_cd;
728   /* WP - I do not have access to chds with subchannel information yet, so I'm faking something here */
729   UINT32 msf_abs, msf_rel, track, frame;
730
731   if ( ! pce_cd.cd )
732   {
733      /* Throw some error here */
734      pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
735      return;
736   }
737
738   frame = pce_cd.current_frame;
739
740   switch( pce_cd.cdda_status )
741   {
742   case PCE_CD_CDDA_PAUSED:
743      pce_cd.data_buffer[0] = 2;
744      frame = cdda_get_audio_lba( machine.device( "cdda" ) );
745      break;
746   case PCE_CD_CDDA_PLAYING:
747      pce_cd.data_buffer[0] = 0;
748      frame = cdda_get_audio_lba( machine.device( "cdda" ) );
749      break;
750   default:
751      pce_cd.data_buffer[0] = 3;
752      break;
753   }
754
755   msf_abs = lba_to_msf( frame );
756   track = cdrom_get_track( pce_cd.cd, frame );
757   msf_rel = lba_to_msf( frame - cdrom_get_track_start( pce_cd.cd, track ) );
758
759   pce_cd.data_buffer[1] = 0;
760   pce_cd.data_buffer[2] = dec_2_bcd( track+1 );      /* track */
761   pce_cd.data_buffer[3] = 1;                     /* index */
762   pce_cd.data_buffer[4] = ( msf_rel >> 16 ) & 0xFF;   /* M (relative) */
763   pce_cd.data_buffer[5] = ( msf_rel >> 8 ) & 0xFF;   /* S (relative) */
764   pce_cd.data_buffer[6] = msf_rel & 0xFF;            /* F (relative) */
765   pce_cd.data_buffer[7] = ( msf_abs >> 16 ) & 0xFF;   /* M (absolute) */
766   pce_cd.data_buffer[8] = ( msf_abs >> 8 ) & 0xFF;   /* S (absolute) */
767   pce_cd.data_buffer[9] = msf_abs & 0xFF;            /* F (absolute) */
768   pce_cd.data_buffer_size = 10;
769
770   pce_cd.data_buffer_index = 0;
771   pce_cd.data_transferred = 1;
772   pce_cd.scsi_IO = 1;
773   pce_cd.scsi_CD = 0;
774}
775
776/* 0xDE - GET DIR INFO (NEC) */
777static void pce_cd_nec_get_dir_info( running_machine &machine )
778{
779   pce_state *state = machine.driver_data<pce_state>();
780   pce_cd_t &pce_cd = state->m_cd;
781   UINT32 frame, msf, track = 0;
782   const cdrom_toc   *toc;
783   logerror("nec get dir info\n");
784
785   if ( ! pce_cd.cd )
786   {
787      /* Throw some error here */
788      pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
789   }
790
791   toc = cdrom_get_toc( pce_cd.cd );
792
793   switch( pce_cd.command_buffer[1] )
794   {
795   case 0x00:      /* Get first and last track numbers */
796      pce_cd.data_buffer[0] = dec_2_bcd(1);
797      pce_cd.data_buffer[1] = dec_2_bcd(toc->numtrks);
798      pce_cd.data_buffer_size = 2;
799      break;
800   case 0x01:      /* Get total disk size in MSF format */
801      frame = toc->tracks[toc->numtrks-1].physframeofs;
802      frame += toc->tracks[toc->numtrks-1].frames;
803      msf = lba_to_msf( frame + 150 );
804
805      pce_cd.data_buffer[0] = ( msf >> 16 ) & 0xFF;   /* M */
806      pce_cd.data_buffer[1] = ( msf >> 8 ) & 0xFF;   /* S */
807      pce_cd.data_buffer[2] = msf & 0xFF;            /* F */
808      pce_cd.data_buffer_size = 3;
809      break;
810   case 0x02:      /* Get track information */
811      if ( pce_cd.command_buffer[2] == 0xAA )
812      {
813         frame = toc->tracks[toc->numtrks-1].physframeofs;
814         frame += toc->tracks[toc->numtrks-1].frames;
815         pce_cd.data_buffer[3] = 0x04;   /* correct? */
816      } else
817      {
818         track = MAX( bcd_2_dec( pce_cd.command_buffer[2] ), 1 );
819         frame = toc->tracks[track-1].physframeofs;
820         pce_cd.data_buffer[3] = ( toc->tracks[track-1].trktype == CD_TRACK_AUDIO ) ? 0x00 : 0x04;
821      }
822      logerror("track = %d, frame = %d\n", track, frame );
823      msf = lba_to_msf( frame + 150 );
824      pce_cd.data_buffer[0] = ( msf >> 16 ) & 0xFF;   /* M */
825      pce_cd.data_buffer[1] = ( msf >> 8 ) & 0xFF;   /* S */
826      pce_cd.data_buffer[2] = msf & 0xFF;            /* F */
827      pce_cd.data_buffer_size = 4;
828      break;
829   default:
830//      assert( pce_cd_nec_get_dir_info == NULL );  // Not implemented yet
831      break;
832   }
833
834   pce_cd.data_buffer_index = 0;
835   pce_cd.data_transferred = 1;
836   pce_cd.scsi_IO = 1;
837   pce_cd.scsi_CD = 0;
838}
839
840static void pce_cd_end_of_list( running_machine &machine )
841{
842   pce_state *state = machine.driver_data<pce_state>();
843   pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
844}
845
846static void pce_cd_handle_data_output( running_machine &machine )
847{
848   pce_state *state = machine.driver_data<pce_state>();
849   pce_cd_t &pce_cd = state->m_cd;
850   static const struct {
851      UINT8   command_byte;
852      UINT8   command_size;
853      void   (*command_handler)(running_machine &machine);
854   } pce_cd_commands[] = {
855      { 0x00, 6, pce_cd_test_unit_ready },            /* TEST UNIT READY */
856      { 0x08, 6, pce_cd_read_6 },                     /* READ (6) */
857      { 0xD8,10, pce_cd_nec_set_audio_start_position },   /* NEC SET AUDIO PLAYBACK START POSITION */
858      { 0xD9,10, pce_cd_nec_set_audio_stop_position },   /* NEC SET AUDIO PLAYBACK END POSITION */
859      { 0xDA,10, pce_cd_nec_pause },                  /* NEC PAUSE */
860      { 0xDD,10, pce_cd_nec_get_subq },               /* NEC GET SUBCHANNEL Q */
861      { 0xDE,10, pce_cd_nec_get_dir_info },            /* NEC GET DIR INFO */
862      { 0xFF, 1, pce_cd_end_of_list }                  /* end of list marker */
863   };
864
865   if ( pce_cd.scsi_REQ && pce_cd.scsi_ACK )
866   {
867      /* Command byte received */
868      logerror( "Command byte $%02X received\n", pce_cd.regs[0x01] );
869
870      /* Check for buffer overflow */
871      assert( pce_cd.command_buffer_index < PCE_CD_COMMAND_BUFFER_SIZE );
872
873      pce_cd.command_buffer[pce_cd.command_buffer_index] = pce_cd.regs[0x01];
874      pce_cd.command_buffer_index++;
875      pce_cd.scsi_REQ = 0;
876   }
877
878   if ( ! pce_cd.scsi_REQ && ! pce_cd.scsi_ACK && pce_cd.command_buffer_index )
879   {
880      int i = 0;
881
882      logerror( "Check if command done\n" );
883
884      for( i = 0; pce_cd.command_buffer[0] > pce_cd_commands[i].command_byte; i++ );
885
886      /* Check for unknown commands */
887      if ( pce_cd.command_buffer[0] != pce_cd_commands[i].command_byte )
888      {
889         logerror("Unrecognized command: %02X\n", pce_cd.command_buffer[0] );
890         if(pce_cd.command_buffer[0] == 0x03)
891            popmessage("CD command 0x03 issued (Request Sense), contact MESSdev");
892      }
893      assert( pce_cd.command_buffer[0] == pce_cd_commands[i].command_byte );
894
895      if ( pce_cd.command_buffer_index == pce_cd_commands[i].command_size )
896      {
897         (pce_cd_commands[i].command_handler)( machine );
898         pce_cd.command_buffer_index = 0;
899      }
900      else
901      {
902         pce_cd.scsi_REQ = 1;
903      }
904   }
905}
906
907static void pce_cd_handle_data_input( running_machine &machine )
908{
909   pce_state *state = machine.driver_data<pce_state>();
910   pce_cd_t &pce_cd = state->m_cd;
911   if ( pce_cd.scsi_CD )
912   {
913      /* Command / Status byte */
914      if ( pce_cd.scsi_REQ && pce_cd.scsi_ACK )
915      {
916         logerror( "status sent\n" );
917         pce_cd.scsi_REQ = 0;
918         pce_cd.status_sent = 1;
919      }
920
921      if ( ! pce_cd.scsi_REQ && ! pce_cd.scsi_ACK && pce_cd.status_sent )
922      {
923         pce_cd.status_sent = 0;
924         if ( pce_cd.message_after_status )
925         {
926            logerror( "message after status\n" );
927            pce_cd.message_after_status = 0;
928            pce_cd.scsi_MSG = pce_cd.scsi_REQ = 1;
929            pce_cd.regs[0x01] = 0;
930         }
931      }
932   }
933   else
934   {
935      /* Data */
936      if ( pce_cd.scsi_REQ && pce_cd.scsi_ACK )
937      {
938         pce_cd.scsi_REQ = 0;
939      }
940
941      if ( ! pce_cd.scsi_REQ && ! pce_cd.scsi_ACK )
942      {
943         if ( pce_cd.data_buffer_index == pce_cd.data_buffer_size )
944         {
945            pce_cd_set_irq_line( machine, PCE_CD_IRQ_TRANSFER_READY, CLEAR_LINE );
946            if ( pce_cd.data_transferred )
947            {
948               pce_cd.data_transferred = 0;
949               pce_cd_reply_status_byte( state, SCSI_STATUS_OK );
950               pce_cd_set_irq_line( machine, PCE_CD_IRQ_TRANSFER_DONE, ASSERT_LINE );
951            }
952         }
953         else
954         {
955            logerror("Transfer byte from offset %d\n", pce_cd.data_buffer_index);
956            pce_cd.regs[0x01] = pce_cd.data_buffer[pce_cd.data_buffer_index];
957            pce_cd.data_buffer_index++;
958            pce_cd.scsi_REQ = 1;
959         }
960      }
961   }
962}
963
964static void pce_cd_handle_message_output( pce_state *state )
965{
966   pce_cd_t &pce_cd = state->m_cd;
967   if ( pce_cd.scsi_REQ && pce_cd.scsi_ACK )
968   {
969      pce_cd.scsi_REQ = 0;
970   }
971}
972
973static void pce_cd_handle_message_input( pce_state *state )
974{
975   pce_cd_t &pce_cd = state->m_cd;
976   if ( pce_cd.scsi_REQ && pce_cd.scsi_ACK )
977   {
978      pce_cd.scsi_REQ = 0;
979      pce_cd.message_sent = 1;
980   }
981
982   if ( ! pce_cd.scsi_REQ && ! pce_cd.scsi_ACK && pce_cd.message_sent )
983   {
984      pce_cd.message_sent = 0;
985      pce_cd.scsi_BSY = 0;
986   }
987}
988
989/* Update internal CD statuses */
990static void pce_cd_update( running_machine &machine )
991{
992   pce_state *state = machine.driver_data<pce_state>();
993   pce_cd_t &pce_cd = state->m_cd;
994   /* Check for reset of CD unit */
995   if ( pce_cd.scsi_RST != pce_cd.scsi_last_RST )
996   {
997      if ( pce_cd.scsi_RST )
998      {
999         logerror("Performing CD reset\n");
1000         /* Reset internal data */
1001         pce_cd.scsi_BSY = pce_cd.scsi_SEL = pce_cd.scsi_CD = pce_cd.scsi_IO = 0;
1002         pce_cd.scsi_MSG = pce_cd.scsi_REQ = pce_cd.scsi_ATN = 0;
1003         pce_cd.cd_motor_on = 0;
1004         pce_cd.selected = 0;
1005         pce_cd.cdda_status = PCE_CD_CDDA_OFF;
1006         cdda_stop_audio( machine.device( "cdda" ) );
1007         pce_cd.adpcm_dma_timer->adjust(attotime::never); // stop ADPCM DMA here
1008      }
1009      pce_cd.scsi_last_RST = pce_cd.scsi_RST;
1010   }
1011
1012   /* Check if bus can be freed */
1013   if ( ! pce_cd.scsi_SEL && ! pce_cd.scsi_BSY && pce_cd.selected )
1014   {
1015      logerror( "freeing bus\n" );
1016      pce_cd.selected = 0;
1017      pce_cd.scsi_CD = pce_cd.scsi_MSG = pce_cd.scsi_IO = pce_cd.scsi_REQ = 0;
1018      pce_cd_set_irq_line( machine, PCE_CD_IRQ_TRANSFER_DONE, CLEAR_LINE );
1019   }
1020
1021   /* Select the CD device */
1022   if ( pce_cd.scsi_SEL )
1023   {
1024      if ( ! pce_cd.selected )
1025      {
1026         pce_cd.selected = 1;
1027         logerror("Setting CD in device selection\n");
1028         pce_cd.scsi_BSY = pce_cd.scsi_REQ = pce_cd.scsi_CD = 1;
1029         pce_cd.scsi_MSG = pce_cd.scsi_IO = 0;
1030      }
1031   }
1032
1033   if ( pce_cd.scsi_ATN )
1034   {
1035   }
1036   else
1037   {
1038      /* Check for data and pessage phases */
1039      if ( pce_cd.scsi_BSY )
1040      {
1041         if ( pce_cd.scsi_MSG )
1042         {
1043            /* message phase */
1044            if ( pce_cd.scsi_IO )
1045            {
1046               pce_cd_handle_message_input(state);
1047            }
1048            else
1049            {
1050               pce_cd_handle_message_output(state);
1051            }
1052         }
1053         else
1054         {
1055            /* data phase */
1056            if ( pce_cd.scsi_IO )
1057            {
1058               /* Reading data from target */
1059               pce_cd_handle_data_input( machine );
1060            }
1061            else
1062            {
1063               /* Sending data to target */
1064               pce_cd_handle_data_output( machine );
1065            }
1066         }
1067      }
1068   }
1069
1070   /* FIXME: presumably CD-DA needs an irq interface for this */
1071   if(cdda_audio_ended(machine.device("cdda")) && pce_cd.end_mark == 1)
1072   {
1073      switch(pce_cd.cdda_play_mode & 3)
1074      {
1075         case 1: cdda_start_audio( machine.device( "cdda" ), pce_cd.current_frame, pce_cd.end_frame - pce_cd.current_frame ); pce_cd.end_mark = 1; break; //play with repeat
1076         case 2: pce_cd_set_irq_line( machine, PCE_CD_IRQ_TRANSFER_DONE, ASSERT_LINE ); pce_cd.end_mark = 0; break; //irq when finished
1077         case 3: pce_cd.end_mark = 0; break; //play without repeat
1078      }
1079   }
1080}
1081
1082static void pce_cd_set_irq_line( running_machine &machine, int num, int state )
1083{
1084   pce_state *drvstate = machine.driver_data<pce_state>();
1085   pce_cd_t &pce_cd = drvstate->m_cd;
1086   switch( num )
1087   {
1088   case PCE_CD_IRQ_TRANSFER_DONE:
1089      if ( state == ASSERT_LINE )
1090      {
1091         pce_cd.regs[0x03] |= PCE_CD_IRQ_TRANSFER_DONE;
1092      }
1093      else
1094      {
1095         pce_cd.regs[0x03] &= ~ PCE_CD_IRQ_TRANSFER_DONE;
1096      }
1097      break;
1098   case PCE_CD_IRQ_TRANSFER_READY:
1099      if ( state == ASSERT_LINE )
1100      {
1101         pce_cd.regs[0x03] |= PCE_CD_IRQ_TRANSFER_READY;
1102      }
1103      else
1104      {
1105         pce_cd.regs[0x03] &= ~ PCE_CD_IRQ_TRANSFER_READY;
1106      }
1107      break;
1108   case PCE_CD_IRQ_SAMPLE_FULL_PLAY:
1109      if ( state == ASSERT_LINE )
1110      {
1111         pce_cd.regs[0x03] |= PCE_CD_IRQ_SAMPLE_FULL_PLAY;
1112         //printf("x %02x %02x\n",pce_cd.regs[0x02],pce_cd.regs[0x03]);
1113      }
1114      else
1115      {
1116         pce_cd.regs[0x03] &= ~ PCE_CD_IRQ_SAMPLE_FULL_PLAY;
1117      }
1118      break;
1119   case PCE_CD_IRQ_SAMPLE_HALF_PLAY:
1120      if ( state == ASSERT_LINE )
1121      {
1122         pce_cd.regs[0x03] |= PCE_CD_IRQ_SAMPLE_HALF_PLAY;
1123         //printf("y %02x %02x\n",pce_cd.regs[0x02],pce_cd.regs[0x03]);
1124      }
1125      else
1126      {
1127         pce_cd.regs[0x03] &= ~ PCE_CD_IRQ_SAMPLE_HALF_PLAY;
1128      }
1129      break;
1130   default:
1131      break;
1132   }
1133
1134   if ( pce_cd.regs[0x02] & pce_cd.regs[0x03] & ( PCE_CD_IRQ_TRANSFER_DONE | PCE_CD_IRQ_TRANSFER_READY | PCE_CD_IRQ_SAMPLE_HALF_PLAY | PCE_CD_IRQ_SAMPLE_FULL_PLAY) )
1135   {
1136      cputag_set_input_line(machine, "maincpu", 1, ASSERT_LINE );
1137   }
1138   else
1139   {
1140      cputag_set_input_line(machine, "maincpu", 1, CLEAR_LINE );
1141   }
1142}
1143
1144static TIMER_CALLBACK( pce_cd_data_timer_callback )
1145{
1146   pce_state *state = machine.driver_data<pce_state>();
1147   pce_cd_t &pce_cd = state->m_cd;
1148   if ( pce_cd.data_buffer_index == pce_cd.data_buffer_size )
1149   {
1150      /* Read next data sector */
1151      logerror("read sector %d\n", pce_cd.current_frame );
1152      if ( ! cdrom_read_data( pce_cd.cd, pce_cd.current_frame, pce_cd.data_buffer, CD_TRACK_MODE1 ) )
1153      {
1154         logerror("Mode1 CD read failed for frame #%d\n", pce_cd.current_frame );
1155      }
1156      else
1157      {
1158         logerror("Succesfully read mode1 frame #%d\n", pce_cd.current_frame );
1159      }
1160
1161      pce_cd.data_buffer_index = 0;
1162      pce_cd.data_buffer_size = 2048;
1163      pce_cd.current_frame++;
1164
1165      pce_cd.scsi_IO = 1;
1166      pce_cd.scsi_CD = 0;
1167
1168      if ( pce_cd.current_frame == pce_cd.end_frame )
1169      {
1170         /* We are done, disable the timer */
1171         logerror("Last frame read from CD\n");
1172         pce_cd.data_transferred = 1;
1173         pce_cd.data_timer->adjust(attotime::never);
1174      }
1175      else
1176      {
1177         pce_cd.data_transferred = 0;
1178      }
1179   }
1180}
1181
1182static void pce_cd_init( running_machine &machine )
1183{
1184   pce_state *state = machine.driver_data<pce_state>();
1185   pce_cd_t &pce_cd = state->m_cd;
1186   device_t *device;
1187
1188   /* Initialize pce_cd struct */
1189   memset( &pce_cd, 0, sizeof(pce_cd) );
1190
1191   /* Initialize BRAM */
1192   pce_cd.bram = auto_alloc_array(machine, UINT8, PCE_BRAM_SIZE * 2 );
1193   memset( pce_cd.bram, 0, PCE_BRAM_SIZE );
1194   memset( pce_cd.bram + PCE_BRAM_SIZE, 0xFF, PCE_BRAM_SIZE );
1195   pce_cd.bram_locked = 1;
1196   pce_set_cd_bram(machine);
1197
1198   /* set up adpcm related things */
1199   pce_cd.adpcm_ram = auto_alloc_array(machine, UINT8, PCE_ADPCM_RAM_SIZE );
1200   memset( pce_cd.adpcm_ram, 0, PCE_ADPCM_RAM_SIZE );
1201   pce_cd.adpcm_clock_divider = 1;
1202   msm5205_change_clock_w(machine.device("msm5205"), (PCE_CD_CLOCK / 6) / pce_cd.adpcm_clock_divider);
1203
1204   /* Set up cd command buffer */
1205   pce_cd.command_buffer = auto_alloc_array(machine, UINT8, PCE_CD_COMMAND_BUFFER_SIZE );
1206   memset( pce_cd.command_buffer, 0, PCE_CD_COMMAND_BUFFER_SIZE );
1207   pce_cd.command_buffer_index = 0;
1208
1209   /* Set up Arcade Card RAM buffer */
1210   pce_cd.acard_ram = auto_alloc_array(machine, UINT8, PCE_ACARD_RAM_SIZE );
1211   memset( pce_cd.acard_ram, 0, PCE_ACARD_RAM_SIZE );
1212
1213   pce_cd.data_buffer = auto_alloc_array(machine, UINT8, 8192 );
1214   memset( pce_cd.data_buffer, 0, 8192 );
1215   pce_cd.data_buffer_size = 0;
1216   pce_cd.data_buffer_index = 0;
1217
1218   pce_cd.subcode_buffer = auto_alloc_array(machine, UINT8, 96 );
1219
1220   device = machine.device("cdrom");
1221   if ( device )
1222   {
1223      pce_cd.cd = cd_get_cdrom_file(device);
1224      if ( pce_cd.cd )
1225      {
1226         pce_cd.toc = cdrom_get_toc( pce_cd.cd );
1227         cdda_set_cdrom( machine.device("cdda"), pce_cd.cd );
1228         pce_cd.last_frame = cdrom_get_track_start( pce_cd.cd, cdrom_get_last_track( pce_cd.cd ) - 1 );
1229         pce_cd.last_frame += pce_cd.toc->tracks[ cdrom_get_last_track( pce_cd.cd ) - 1 ].frames;
1230         pce_cd.end_frame = pce_cd.last_frame;
1231      }
1232   }
1233
1234   pce_cd.data_timer = machine.scheduler().timer_alloc(FUNC(pce_cd_data_timer_callback));
1235   pce_cd.data_timer->adjust(attotime::never);
1236   pce_cd.adpcm_dma_timer = machine.scheduler().timer_alloc(FUNC(pce_cd_adpcm_dma_timer_callback));
1237   pce_cd.adpcm_dma_timer->adjust(attotime::never);
1238
1239   pce_cd.cdda_fadeout_timer = machine.scheduler().timer_alloc(FUNC(pce_cd_cdda_fadeout_callback));
1240   pce_cd.cdda_fadeout_timer->adjust(attotime::never);
1241   pce_cd.cdda_fadein_timer = machine.scheduler().timer_alloc(FUNC(pce_cd_cdda_fadein_callback));
1242   pce_cd.cdda_fadein_timer->adjust(attotime::never);
1243
1244   pce_cd.adpcm_fadeout_timer = machine.scheduler().timer_alloc(FUNC(pce_cd_adpcm_fadeout_callback));
1245   pce_cd.adpcm_fadeout_timer->adjust(attotime::never);
1246   pce_cd.adpcm_fadein_timer = machine.scheduler().timer_alloc(FUNC(pce_cd_adpcm_fadein_callback));
1247   pce_cd.adpcm_fadein_timer->adjust(attotime::never);
1248}
1249
1250WRITE8_HANDLER( pce_cd_bram_w )
1251{
1252   pce_state *state = space->machine().driver_data<pce_state>();
1253   pce_cd_t &pce_cd = state->m_cd;
1254   if ( ! pce_cd.bram_locked )
1255   {
1256      pce_cd.bram[ offset ] = data;
1257   }
1258}
1259
1260static void pce_cd_set_adpcm_ram_byte(running_machine &machine, UINT8 val)
1261{
1262   pce_state *state = machine.driver_data<pce_state>();
1263   pce_cd_t &pce_cd = state->m_cd;
1264   if(pce_cd.adpcm_write_buf > 0)
1265   {
1266      pce_cd.adpcm_write_buf--;
1267   }
1268   else
1269   {
1270      pce_cd.adpcm_ram[pce_cd.adpcm_write_ptr] = val;
1271      pce_cd.adpcm_write_ptr = ((pce_cd.adpcm_write_ptr + 1) & 0xffff);
1272      //TODO: length + 1
1273   }
1274}
1275
1276static TIMER_CALLBACK( pce_cd_cdda_fadeout_callback )
1277{
1278   pce_state *state = machine.driver_data<pce_state>();
1279   pce_cd_t &pce_cd = state->m_cd;
1280   pce_cd.cdda_volume-= 0.1;
1281
1282   if(pce_cd.cdda_volume <= 0)
1283   {
1284      pce_cd.cdda_volume = 0.0;
1285      cdda_set_volume(machine.device("cdda"), 0.0);
1286      pce_cd.cdda_fadeout_timer->adjust(attotime::never);
1287   }
1288   else
1289   {
1290      cdda_set_volume(machine.device("cdda"), pce_cd.cdda_volume);
1291      pce_cd.cdda_fadeout_timer->adjust(attotime::from_usec(param), param);
1292   }
1293}
1294
1295static TIMER_CALLBACK( pce_cd_cdda_fadein_callback )
1296{
1297   pce_state *state = machine.driver_data<pce_state>();
1298   pce_cd_t &pce_cd = state->m_cd;
1299   pce_cd.cdda_volume+= 0.1;
1300
1301   if(pce_cd.cdda_volume >= 100.0)
1302   {
1303      pce_cd.cdda_volume = 100.0;
1304      cdda_set_volume(machine.device("cdda"), 100.0);
1305      pce_cd.cdda_fadein_timer->adjust(attotime::never);
1306   }
1307   else
1308   {
1309      cdda_set_volume(machine.device("cdda"), pce_cd.cdda_volume);
1310      pce_cd.cdda_fadein_timer->adjust(attotime::from_usec(param), param);
1311   }
1312}
1313
1314static TIMER_CALLBACK( pce_cd_adpcm_fadeout_callback )
1315{
1316   pce_state *state = machine.driver_data<pce_state>();
1317   pce_cd_t &pce_cd = state->m_cd;
1318   pce_cd.adpcm_volume-= 0.1;
1319
1320   if(pce_cd.adpcm_volume <= 0)
1321   {
1322      pce_cd.adpcm_volume = 0.0;
1323      msm5205_set_volume(machine.device("msm5205"), 0.0);
1324      pce_cd.adpcm_fadeout_timer->adjust(attotime::never);
1325   }
1326   else
1327   {
1328      msm5205_set_volume(machine.device("msm5205"), pce_cd.adpcm_volume);
1329      pce_cd.adpcm_fadeout_timer->adjust(attotime::from_usec(param), param);
1330   }
1331}
1332
1333static TIMER_CALLBACK( pce_cd_adpcm_fadein_callback )
1334{
1335   pce_state *state = machine.driver_data<pce_state>();
1336   pce_cd_t &pce_cd = state->m_cd;
1337   pce_cd.adpcm_volume+= 0.1;
1338
1339   if(pce_cd.adpcm_volume >= 100.0)
1340   {
1341      pce_cd.adpcm_volume = 100.0;
1342      msm5205_set_volume(machine.device("msm5205"), 100.0);
1343      pce_cd.adpcm_fadein_timer->adjust(attotime::never);
1344   }
1345   else
1346   {
1347      msm5205_set_volume(machine.device("msm5205"), pce_cd.adpcm_volume);
1348      pce_cd.adpcm_fadein_timer->adjust(attotime::from_usec(param), param);
1349   }
1350}
1351
1352
1353WRITE8_HANDLER( pce_cd_intf_w )
1354{
1355   pce_state *state = space->machine().driver_data<pce_state>();
1356   pce_cd_t &pce_cd = state->m_cd;
1357   pce_cd_update(space->machine());
1358
1359   if(offset & 0x200 && state->m_sys3_card && state->m_acard) // route Arcade Card handling ports
1360      return pce_cd_acard_w(space,offset,data);
1361
1362   logerror("%04X: write to CD interface offset %02X, data %02X\n", cpu_get_pc(&space->device()), offset, data );
1363
1364   switch( offset & 0xf )
1365   {
1366   case 0x00:   /* CDC status */
1367      /* select device (which bits??) */
1368      pce_cd.scsi_SEL = 1;
1369      pce_cd_update(space->machine());
1370      pce_cd.scsi_SEL = 0;
1371      pce_cd.adpcm_dma_timer->adjust(attotime::never); // stop ADPCM DMA here
1372      /* any write here clears CD transfer irqs */
1373      pce_cd.regs[0x03] &= ~0x70;
1374      cputag_set_input_line(space->machine(), "maincpu", 1, CLEAR_LINE );
1375      break;
1376   case 0x01:   /* CDC command / status / data */
1377      break;
1378   case 0x02:   /* ADPCM / CD control / IRQ enable/disable */
1379            /* bit 6 - transfer ready irq */
1380            /* bit 5 - transfer done irq */
1381            /* bit 4 - ?? irq */
1382            /* bit 3 - ?? irq */
1383            /* bit 2 - ?? irq */
1384      pce_cd.scsi_ACK = data & 0x80;
1385      /* Don't set or reset any irq lines, but just verify the current state */
1386      pce_cd_set_irq_line( space->machine(), 0, 0 );
1387      break;
1388   case 0x03:   /* BRAM lock / CD status / IRQ - Read Only register */
1389      break;
1390   case 0x04:   /* CD reset */
1391      pce_cd.scsi_RST = data & 0x02;
1392      break;
1393   case 0x05:   /* Convert PCM data / PCM data */
1394   case 0x06:   /* PCM data */
1395      break;
1396   case 0x07:   /* BRAM unlock / CD status */
1397      if ( data & 0x80 )
1398      {
1399         pce_cd.bram_locked = 0;
1400         pce_set_cd_bram(space->machine());
1401      }
1402      break;
1403   case 0x08:   /* ADPCM address (LSB) / CD data */
1404      break;
1405   case 0x09:   /* ADPCM address (MSB) */
1406      break;
1407   case 0x0A:   /* ADPCM RAM data port */
1408      pce_cd_set_adpcm_ram_byte(space->machine(), data);
1409      break;
1410   case 0x0B:   /* ADPCM DMA control */
1411      if ( data & 0x03 )
1412      {
1413         /* Start CD to ADPCM transfer */
1414         pce_cd.adpcm_dma_timer->adjust(attotime::from_hz( PCE_CD_DATA_FRAMES_PER_SECOND * 2048 ), 0, attotime::from_hz( PCE_CD_DATA_FRAMES_PER_SECOND * 2048 ) );
1415         pce_cd.regs[0x0c] |= 4;
1416      }
1417      break;
1418   case 0x0C:   /* ADPCM status */
1419      break;
1420   case 0x0D:   /* ADPCM address control */
1421      if ( ( pce_cd.regs[0x0D] & 0x80 ) && ! ( data & 0x80 ) ) // ADPCM reset
1422      {
1423         /* Reset ADPCM hardware */
1424         pce_cd.adpcm_read_ptr = 0;
1425         pce_cd.adpcm_write_ptr = 0;
1426         pce_cd.msm_start_addr = 0;
1427         pce_cd.msm_end_addr = 0;
1428         pce_cd.msm_half_addr = 0;
1429         pce_cd.msm_nibble = 0;
1430         adpcm_stop(space->machine());
1431         msm5205_reset_w( space->machine().device( "msm5205"), 1 );
1432      }
1433
1434      if(data & 0x20)
1435         pce_cd.msm_half_addr = (pce_cd.adpcm_read_ptr + (pce_cd.adpcm_length / ((data & 0x40) ? 2 : 1))) & 0xffff;
1436
1437      if ( ( data & 0x40) && ((pce_cd.regs[0x0D] & 0x40) == 0) ) // ADPCM play
1438      {
1439         pce_cd.msm_start_addr = (pce_cd.adpcm_read_ptr);
1440         pce_cd.msm_end_addr = (pce_cd.adpcm_read_ptr + pce_cd.adpcm_length) & 0xffff;
1441         pce_cd.msm_nibble = 0;
1442         adpcm_play(space->machine());
1443         msm5205_reset_w( space->machine().device( "msm5205"), 0 );
1444
1445         //popmessage("%08x %08x",pce_cd.adpcm_read_ptr,pce_cd.adpcm_length);
1446      }
1447      else if ( (data & 0x40) == 0 )
1448      {
1449         /* used by Buster Bros to cancel an in-flight sample */
1450         adpcm_stop(space->machine());
1451         msm5205_reset_w( space->machine().device( "msm5205"), 1 );
1452      }
1453
1454      if ( data & 0x10 ) //ADPCM set length
1455      {
1456         pce_cd.adpcm_length = ( pce_cd.regs[0x09] << 8 ) | pce_cd.regs[0x08];
1457      }
1458      if ( data & 0x08 ) //ADPCM set read address
1459      {
1460         pce_cd.adpcm_read_ptr = ( pce_cd.regs[0x09] << 8 ) | pce_cd.regs[0x08];
1461         pce_cd.adpcm_read_buf = 2;
1462      }
1463      if ( ( data & 0x02 ) == 0x02 ) //ADPCM set write address
1464      {
1465         pce_cd.adpcm_write_ptr = ( pce_cd.regs[0x09] << 8 ) | pce_cd.regs[0x08];
1466         pce_cd.adpcm_write_buf = data & 1;
1467      }
1468      break;
1469   case 0x0E:   /* ADPCM playback rate */
1470      pce_cd.adpcm_clock_divider = 0x10 - ( data & 0x0F );
1471      msm5205_change_clock_w(space->machine().device("msm5205"), (PCE_CD_CLOCK / 6) / pce_cd.adpcm_clock_divider);
1472      break;
1473   case 0x0F:   /* ADPCM and CD audio fade timer */
1474      /* TODO: timers needs HW tests */
1475      if(pce_cd.regs[0xf] != data)
1476      {
1477         switch(data & 0xf)
1478         {
1479            case 0x00: //CD-DA / ADPCM enable (100 msecs)
1480               pce_cd.cdda_volume = 0.0;
1481               pce_cd.cdda_fadein_timer->adjust(attotime::from_usec(100), 100);
1482               pce_cd.adpcm_volume = 0.0;
1483               pce_cd.adpcm_fadein_timer->adjust(attotime::from_usec(100), 100);
1484               pce_cd.cdda_fadeout_timer->adjust(attotime::never);
1485               pce_cd.adpcm_fadeout_timer->adjust(attotime::never);
1486               break;
1487            case 0x01: //CD-DA enable (100 msecs)
1488               pce_cd.cdda_volume = 0.0;
1489               pce_cd.cdda_fadein_timer->adjust(attotime::from_usec(100), 100);
1490               pce_cd.cdda_fadeout_timer->adjust(attotime::never);
1491               break;
1492            case 0x08: //CD-DA short (1500 msecs) fade out / ADPCM enable
1493               pce_cd.cdda_volume = 100.0;
1494               pce_cd.cdda_fadeout_timer->adjust(attotime::from_usec(1500), 1500);
1495               pce_cd.adpcm_volume = 0.0;
1496               pce_cd.adpcm_fadein_timer->adjust(attotime::from_usec(100), 100);
1497               pce_cd.cdda_fadein_timer->adjust(attotime::never);
1498               pce_cd.adpcm_fadeout_timer->adjust(attotime::never);
1499               break;
1500            case 0x09: //CD-DA long (5000 msecs) fade out
1501               pce_cd.cdda_volume = 100.0;
1502               pce_cd.cdda_fadeout_timer->adjust(attotime::from_usec(5000), 5000);
1503               pce_cd.cdda_fadein_timer->adjust(attotime::never);
1504               break;
1505            case 0x0a: //ADPCM long (5000 msecs) fade out
1506               pce_cd.adpcm_volume = 100.0;
1507               pce_cd.adpcm_fadeout_timer->adjust(attotime::from_usec(5000), 5000);
1508               pce_cd.adpcm_fadein_timer->adjust(attotime::never);
1509               break;
1510            case 0x0c: //CD-DA short (1500 msecs) fade out / ADPCM enable
1511               pce_cd.cdda_volume = 100.0;
1512               pce_cd.cdda_fadeout_timer->adjust(attotime::from_usec(1500), 1500);
1513               pce_cd.adpcm_volume = 0.0;
1514               pce_cd.adpcm_fadein_timer->adjust(attotime::from_usec(100), 100);
1515               pce_cd.cdda_fadein_timer->adjust(attotime::never);
1516               pce_cd.adpcm_fadeout_timer->adjust(attotime::never);
1517               break;
1518            case 0x0d: //CD-DA short (1500 msecs) fade out
1519               pce_cd.cdda_volume = 100.0;
1520               pce_cd.cdda_fadeout_timer->adjust(attotime::from_usec(1500), 1500);
1521               pce_cd.cdda_fadein_timer->adjust(attotime::never);
1522               break;
1523            case 0x0e: //ADPCM short (1500 msecs) fade out
1524               pce_cd.adpcm_volume = 100.0;
1525               pce_cd.adpcm_fadeout_timer->adjust(attotime::from_usec(1500), 1500);
1526               pce_cd.adpcm_fadein_timer->adjust(attotime::never);
1527               break;
1528            default:
1529               popmessage("CD-DA / ADPCM Fade effect mode %02x, contact MESSdev",data & 0x0f);
1530               break;
1531         }
1532      }
1533      break;
1534   default:
1535      return;
1536   }
1537   pce_cd.regs[offset & 0xf] = data;
1538   pce_cd_update(space->machine());
1539}
1540
1541static TIMER_CALLBACK( pce_cd_clear_ack )
1542{
1543   pce_state *state = machine.driver_data<pce_state>();
1544   pce_cd_t &pce_cd = state->m_cd;
1545   pce_cd_update(machine);
1546   pce_cd.scsi_ACK = 0;
1547   pce_cd_update(machine);
1548   if ( pce_cd.scsi_CD )
1549   {
1550      pce_cd.regs[0x0B] &= 0xFE;
1551   }
1552}
1553
1554static UINT8 pce_cd_get_cd_data_byte(running_machine &machine)
1555{
1556   pce_state *state = machine.driver_data<pce_state>();
1557   pce_cd_t &pce_cd = state->m_cd;
1558   UINT8 data = pce_cd.regs[0x01];
1559   if ( pce_cd.scsi_REQ && ! pce_cd.scsi_ACK && ! pce_cd.scsi_CD )
1560   {
1561      if ( pce_cd.scsi_IO )
1562      {
1563         pce_cd.scsi_ACK = 1;
1564         machine.scheduler().timer_set(machine.device<cpu_device>("maincpu")->cycles_to_attotime(15), FUNC(pce_cd_clear_ack));
1565      }
1566   }
1567   return data;
1568}
1569
1570
1571static TIMER_CALLBACK( pce_cd_adpcm_dma_timer_callback )
1572{
1573   pce_state *state = machine.driver_data<pce_state>();
1574   pce_cd_t &pce_cd = state->m_cd;
1575   if ( pce_cd.scsi_REQ && ! pce_cd.scsi_ACK && ! pce_cd.scsi_CD && pce_cd.scsi_IO  )
1576   {
1577      pce_cd.adpcm_ram[pce_cd.adpcm_write_ptr] = pce_cd_get_cd_data_byte(machine);
1578      pce_cd.adpcm_write_ptr = ( pce_cd.adpcm_write_ptr + 1 ) & 0xFFFF;
1579
1580      pce_cd.regs[0x0c] &= ~4;
1581   }
1582}
1583
1584static UINT8 pce_cd_get_adpcm_ram_byte(running_machine &machine)
1585{
1586   pce_state *state = machine.driver_data<pce_state>();
1587   pce_cd_t &pce_cd = state->m_cd;
1588   if(pce_cd.adpcm_read_buf > 0)
1589   {
1590      pce_cd.adpcm_read_buf--;
1591      return 0;
1592   }
1593   else
1594   {
1595      UINT8 res;
1596
1597      res = pce_cd.adpcm_ram[pce_cd.adpcm_read_ptr];
1598      pce_cd.adpcm_read_ptr = ((pce_cd.adpcm_read_ptr + 1) & 0xffff);
1599
1600      return res;
1601   }
1602}
1603
1604READ8_HANDLER( pce_cd_intf_r )
1605{
1606   pce_state *state = space->machine().driver_data<pce_state>();
1607   pce_cd_t &pce_cd = state->m_cd;
1608   UINT8 data = pce_cd.regs[offset & 0x0F];
1609
1610   pce_cd_update(space->machine());
1611
1612   if(offset & 0x200 && state->m_sys3_card && state->m_acard) // route Arcade Card handling ports
1613      return pce_cd_acard_r(space,offset);
1614
1615   logerror("%04X: read from CD interface offset %02X\n", cpu_get_pc(&space->device()), offset );
1616
1617   if((offset & 0xc0) == 0xc0 && state->m_sys3_card) //System 3 Card header handling
1618   {
1619      switch(offset & 0xcf)
1620      {
1621         case 0xc1: return 0xaa;
1622         case 0xc2: return 0x55;
1623         case 0xc3: return 0x00;
1624         case 0xc5: return (state->m_sys3_card & 2) ? 0x55 : 0xaa;
1625         case 0xc6: return (state->m_sys3_card & 2) ? 0xaa : 0x55;
1626         case 0xc7: return 0x03;
1627      }
1628   }
1629
1630   switch( offset & 0xf )
1631   {
1632   case 0x00:   /* CDC status */
1633      data &= 0x07;
1634      data |= pce_cd.scsi_BSY ? 0x80 : 0;
1635      data |= pce_cd.scsi_REQ ? 0x40 : 0;
1636      data |= pce_cd.scsi_MSG ? 0x20 : 0;
1637      data |= pce_cd.scsi_CD  ? 0x10 : 0;
1638      data |= pce_cd.scsi_IO  ? 0x08 : 0;
1639      break;
1640   case 0x01:   /* CDC command / status / data */
1641      break;
1642   case 0x02:   /* ADPCM / CD control */
1643      break;
1644   case 0x03:   /* BRAM lock / CD status */
1645      /* bit 4 set when CD motor is on */
1646      /* bit 2 set when less than half of the ADPCM data is remaining ?? */
1647      pce_cd.bram_locked = 1;
1648      pce_set_cd_bram(space->machine());
1649      data = data & 0x6E;
1650      data |= ( pce_cd.cd_motor_on ? 0x10 : 0 );
1651      pce_cd.regs[0x03] ^= 0x02;         /* TODO: get rid of this hack */
1652      break;
1653   case 0x04:   /* CD reset */
1654      break;
1655   case 0x05:   /* Convert PCM data / PCM data */
1656   case 0x06:   /* PCM data */
1657      break;
1658   case 0x07:   /* BRAM unlock / CD status */
1659      data = ( pce_cd.bram_locked ? ( data & 0x7F ) : ( data | 0x80 ) );
1660      break;
1661   case 0x08:   /* ADPCM address (LSB) / CD data */
1662      data = pce_cd_get_cd_data_byte(space->machine());
1663      break;
1664   case 0x0A:   /* ADPCM RAM data port */
1665      data = pce_cd_get_adpcm_ram_byte(space->machine());
1666      break;
1667   case 0x0B:   /* ADPCM DMA control */
1668      break;
1669   case 0x0C:   /* ADPCM status */
1670      break;
1671   case 0x0D:   /* ADPCM address control */
1672      break;
1673   /* These are read-only registers */
1674   case 0x09:   /* ADPCM address (MSB) */
1675   case 0x0E:   /* ADPCM playback rate */
1676   case 0x0F:   /* ADPCM and CD audio fade timer */
1677      return 0;
1678   default:
1679      data = 0xFF;
1680      break;
1681   }
1682
1683   return data;
1684}
1685
1686
1687/*
1688
1689PC Engine Arcade Card emulation
1690
1691*/
1692
1693READ8_HANDLER( pce_cd_acard_r )
1694{
1695   pce_state *state = space->machine().driver_data<pce_state>();
1696   pce_cd_t &pce_cd = state->m_cd;
1697   UINT8 r_num;
1698
1699   if((offset & 0x2e0) == 0x2e0)
1700   {
1701      switch(offset & 0x2ef)
1702      {
1703         case 0x2e0: return (pce_cd.acard_shift >> 0)  & 0xff;
1704         case 0x2e1: return (pce_cd.acard_shift >> 8)  & 0xff;
1705         case 0x2e2: return (pce_cd.acard_shift >> 16) & 0xff;
1706         case 0x2e3: return (pce_cd.acard_shift >> 24) & 0xff;
1707         case 0x2e4: return (pce_cd.acard_shift_reg);
1708         case 0x2e5: return pce_cd.acard_latch;
1709         case 0x2ee: return 0x10;
1710         case 0x2ef: return 0x51;
1711      }
1712
1713      return 0;
1714   }
1715
1716   r_num = (offset & 0x30) >> 4;
1717
1718   switch(offset & 0x0f)
1719   {
1720      case 0x00:
1721      case 0x01:
1722      {
1723         UINT8 res;
1724         if(pce_cd.acard_ctrl[r_num] & 2)
1725            res = pce_cd.acard_ram[(pce_cd.acard_base_addr[r_num] + pce_cd.acard_addr_offset[r_num]) & 0x1fffff];
1726         else
1727            res = pce_cd.acard_ram[pce_cd.acard_base_addr[r_num] & 0x1fffff];
1728
1729         if(pce_cd.acard_ctrl[r_num] & 0x1)
1730         {
1731            if(pce_cd.acard_ctrl[r_num] & 0x10)
1732            {
1733               pce_cd.acard_base_addr[r_num] += pce_cd.acard_addr_inc[r_num];
1734               pce_cd.acard_base_addr[r_num] &= 0xffffff;
1735            }
1736            else
1737            {
1738               pce_cd.acard_addr_offset[r_num] += pce_cd.acard_addr_inc[r_num];
1739            }
1740         }
1741
1742         return res;
1743      }
1744      case 0x02: return (pce_cd.acard_base_addr[r_num] >> 0) & 0xff;
1745      case 0x03: return (pce_cd.acard_base_addr[r_num] >> 8) & 0xff;
1746      case 0x04: return (pce_cd.acard_base_addr[r_num] >> 16) & 0xff;
1747      case 0x05: return (pce_cd.acard_addr_offset[r_num] >> 0) & 0xff;
1748      case 0x06: return (pce_cd.acard_addr_offset[r_num] >> 8) & 0xff;
1749      case 0x07: return (pce_cd.acard_addr_inc[r_num] >> 0) & 0xff;
1750      case 0x08: return (pce_cd.acard_addr_inc[r_num] >> 8) & 0xff;
1751      case 0x09: return pce_cd.acard_ctrl[r_num];
1752      default:   return 0;
1753   }
1754
1755   return 0;
1756}
1757
1758WRITE8_HANDLER( pce_cd_acard_w )
1759{
1760   pce_state *state = space->machine().driver_data<pce_state>();
1761   pce_cd_t &pce_cd = state->m_cd;
1762   UINT8 w_num;
1763
1764   if((offset & 0x2e0) == 0x2e0)
1765   {
1766      switch(offset & 0x0f)
1767      {
1768         case 0: pce_cd.acard_shift = (data & 0xff) | (pce_cd.acard_shift & 0xffffff00); break;
1769         case 1: pce_cd.acard_shift = (data << 8)   | (pce_cd.acard_shift & 0xffff00ff); break;
1770         case 2: pce_cd.acard_shift = (data << 16)  | (pce_cd.acard_shift & 0xff00ffff); break;
1771         case 3: pce_cd.acard_shift = (data << 24)  | (pce_cd.acard_shift & 0x00ffffff); break;
1772         case 4:
1773            {
1774               pce_cd.acard_shift_reg = data & 0x0f;
1775
1776               if(pce_cd.acard_shift_reg != 0)
1777               {
1778                   pce_cd.acard_shift = (pce_cd.acard_shift_reg < 8) ?
1779                                 (pce_cd.acard_shift << pce_cd.acard_shift_reg)
1780                                 : (pce_cd.acard_shift >> (16 - pce_cd.acard_shift_reg));
1781               }
1782            }
1783            break;
1784         case 5: pce_cd.acard_latch = data; break;
1785      }
1786   }
1787   else
1788   {
1789      w_num = (offset & 0x30) >> 4;
1790
1791      switch(offset & 0x0f)
1792      {
1793         case 0x00:
1794         case 0x01:
1795            if(pce_cd.acard_ctrl[w_num] & 2)
1796               pce_cd.acard_ram[(pce_cd.acard_base_addr[w_num] + pce_cd.acard_addr_offset[w_num]) & 0x1fffff] = data;
1797            else
1798               pce_cd.acard_ram[pce_cd.acard_base_addr[w_num] & 0x1FFFFF] = data;
1799
1800            if(pce_cd.acard_ctrl[w_num] & 0x1)
1801            {
1802               if(pce_cd.acard_ctrl[w_num] & 0x10)
1803               {
1804                  pce_cd.acard_base_addr[w_num] += pce_cd.acard_addr_inc[w_num];
1805                  pce_cd.acard_base_addr[w_num] &= 0xffffff;
1806               }
1807               else
1808               {
1809                  pce_cd.acard_addr_offset[w_num] += pce_cd.acard_addr_inc[w_num];
1810               }
1811            }
1812
1813            break;
1814
1815         case 0x02: pce_cd.acard_base_addr[w_num] = (data & 0xff) | (pce_cd.acard_base_addr[w_num] & 0xffff00);   break;
1816         case 0x03: pce_cd.acard_base_addr[w_num] = (data << 8) | (pce_cd.acard_base_addr[w_num] & 0xff00ff);      break;
1817         case 0x04: pce_cd.acard_base_addr[w_num] = (data << 16) | (pce_cd.acard_base_addr[w_num] & 0x00ffff);   break;
1818         case 0x05: pce_cd.acard_addr_offset[w_num] = (data & 0xff) | (pce_cd.acard_addr_offset[w_num] & 0xff00);   break;
1819         case 0x06:
1820            pce_cd.acard_addr_offset[w_num] = (data << 8) | (pce_cd.acard_addr_offset[w_num] & 0x00ff);
1821
1822            if((pce_cd.acard_ctrl[w_num] & 0x60) == 0x40)
1823            {
1824               pce_cd.acard_base_addr[w_num] += pce_cd.acard_addr_offset[w_num] + ((pce_cd.acard_ctrl[w_num] & 0x08) ? 0xff0000 : 0);
1825               pce_cd.acard_base_addr[w_num] &= 0xffffff;
1826            }
1827            break;
1828         case 0x07: pce_cd.acard_addr_inc[w_num] = (data & 0xff) | (pce_cd.acard_addr_inc[w_num] & 0xff00);      break;
1829         case 0x08: pce_cd.acard_addr_inc[w_num] = (data << 8) | (pce_cd.acard_addr_inc[w_num] & 0x00ff);         break;
1830         case 0x09: pce_cd.acard_ctrl[w_num] = data & 0x7f;                                    break;
1831         case 0x0a:
1832            if((pce_cd.acard_ctrl[w_num] & 0x60) == 0x60)
1833            {
1834               pce_cd.acard_base_addr[w_num] += pce_cd.acard_addr_offset[w_num];
1835               pce_cd.acard_base_addr[w_num] &= 0xffffff;
1836            }
1837            break;
1838      }
1839   }
1840}
1841
1842READ8_HANDLER( pce_cd_acard_wram_r )
1843{
1844   return pce_cd_intf_r(space,0x200 | (offset & 0x6000) >> 9);
1845}
1846
1847WRITE8_HANDLER( pce_cd_acard_wram_w )
1848{
1849   pce_cd_intf_w(space,0x200 | (offset & 0x6000) >> 9,data);
1850}
1851
src/mame/machine/atarifdc.c
r0r11461
1/***************************************************************************
2
3    Atari 400/800
4
5    Floppy Disk Controller code
6
7    Juergen Buchmueller, June 1998
8
9***************************************************************************/
10
11#include <ctype.h>
12
13#include "emu.h"
14#include "cpu/m6502/m6502.h"
15#include "includes/atari.h"
16#include "ataridev.h"
17#include "sound/pokey.h"
18#include "machine/6821pia.h"
19#include "imagedev/flopdrv.h"
20#include "image.h"
21
22#define VERBOSE_SERIAL   0
23#define VERBOSE_CHKSUM   0
24
25typedef struct _atari_drive atari_drive;
26struct _atari_drive
27{
28   UINT8 *image;      /* malloc'd image */
29   int type;         /* type of image (XFD, ATR, DSK) */
30   int mode;         /* 0 read only, != 0 read/write */
31   int density;      /* 0 SD, 1 MD, 2 DD */
32   int header_skip;   /* number of bytes in format header */
33   int tracks;       /* number of tracks (35,40,77,80) */
34   int heads;         /* number of heads (1,2) */
35   int spt;         /* sectors per track (18,26) */
36   int seclen;       /* sector length (128,256) */
37   int bseclen;      /* boot sector length (sectors 1..3) */
38   int sectors;      /* total sectors, ie. tracks x heads x spt */
39};
40
41typedef struct _atari_fdc_t atari_fdc_t;
42struct _atari_fdc_t
43{
44   int  serout_count;
45   int  serout_offs;
46   UINT8 serout_buff[512];
47   UINT8 serout_chksum;
48   int  serout_delay;
49
50   int  serin_count;
51   int  serin_offs;
52   UINT8 serin_buff[512];
53   UINT8 serin_chksum;
54   int  serin_delay;
55
56   atari_drive drv[4];
57};
58
59/*************************************
60 *
61 *  Disk stuff
62 *
63 *************************************/
64
65#define FORMAT_XFD   0
66#define FORMAT_ATR   1
67#define FORMAT_DSK   2
68
69/*****************************************************************************
70    INLINE FUNCTIONS
71*****************************************************************************/
72INLINE atari_fdc_t *get_safe_token(device_t *device)
73{
74   assert(device != NULL);
75   assert(device->type() == ATARI_FDC);
76
77   return (atari_fdc_t *)downcast<legacy_device_base *>(device)->token();
78}
79
80/*****************************************************************************
81 * This is the structure I used in my own Atari 800 emulator some years ago
82 * Though it's a bit overloaded, I used it as it is the maximum of all
83 * supported formats:
84 * XFD no header at all
85 * ATR 16 bytes header
86 * DSK this struct
87 * It is used to determine the format of a XFD image by it's size only
88 *****************************************************************************/
89
90typedef struct _dsk_format dsk_format;
91struct _dsk_format
92{
93   UINT8 density;
94   UINT8 tracks;
95   UINT8 door;
96   UINT8 sta1;
97   UINT8 spt;
98   UINT8 doublesided;
99   UINT8 highdensity;
100   UINT8 seclen_hi;
101   UINT8 seclen_lo;
102   UINT8 status;
103   UINT8 sta2;
104   UINT8 sta3;
105   UINT8 sta4;
106   UINT8 cr;
107   UINT8 info[65+1];
108};
109
110/* combined with the size the image should have */
111typedef struct _xfd_format xfd_format;
112struct _xfd_format
113{
114   int size;
115   dsk_format dsk;
116};
117
118/* here's a table of known xfd formats */
119static const xfd_format xfd_formats[] =
120{
121   {35 * 18 * 1 * 128,             {0,35,1,0,18,0,0,0,128,255,0,0,0,13,"35 SS/SD"}},
122   {35 * 26 * 1 * 128,             {1,35,1,0,26,0,4,0,128,255,0,0,0,13,"35 SS/MD"}},
123   {(35 * 18 * 1 - 3) * 256 + 3 * 128, {2,35,1,0,18,0,4,1,  0,255,0,0,0,13,"35 SS/DD"}},
124   {40 * 18 * 1 * 128,             {0,40,1,0,18,0,0,0,128,255,0,0,0,13,"40 SS/SD"}},
125   {40 * 26 * 1 * 128,             {1,40,1,0,26,0,4,0,128,255,0,0,0,13,"40 SS/MD"}},
126   {(40 * 18 * 1 - 3) * 256 + 3 * 128, {2,40,1,0,18,0,4,1,  0,255,0,0,0,13,"40 SS/DD"}},
127   {40 * 18 * 2 * 128,             {0,40,1,0,18,1,0,0,128,255,0,0,0,13,"40 DS/SD"}},
128   {40 * 26 * 2 * 128,             {1,40,1,0,26,1,4,0,128,255,0,0,0,13,"40 DS/MD"}},
129   {(40 * 18 * 2 - 3) * 256 + 3 * 128, {2,40,1,0,18,1,4,1,  0,255,0,0,0,13,"40 DS/DD"}},
130   {77 * 18 * 1 * 128,             {0,77,1,0,18,0,0,0,128,255,0,0,0,13,"77 SS/SD"}},
131   {77 * 26 * 1 * 128,             {1,77,1,0,26,0,4,0,128,255,0,0,0,13,"77 SS/MD"}},
132   {(77 * 18 * 1 - 3) * 256 + 3 * 128, {2,77,1,0,18,0,4,1,  0,255,0,0,0,13,"77 SS/DD"}},
133   {77 * 18 * 2 * 128,             {0,77,1,0,18,1,0,0,128,255,0,0,0,13,"77 DS/SD"}},
134   {77 * 26 * 2 * 128,             {1,77,1,0,26,1,4,0,128,255,0,0,0,13,"77 DS/MD"}},
135   {(77 * 18 * 2 - 3) * 256 + 3 * 128, {2,77,1,0,18,1,4,1,  0,255,0,0,0,13,"77 DS/DD"}},
136   {80 * 18 * 2 * 128,             {0,80,1,0,18,1,0,0,128,255,0,0,0,13,"80 DS/SD"}},
137   {80 * 26 * 2 * 128,             {1,80,1,0,26,1,4,0,128,255,0,0,0,13,"80 DS/MD"}},
138   {(80 * 18 * 2 - 3) * 256 + 3 * 128, {2,80,1,0,18,1,4,1,  0,255,0,0,0,13,"80 DS/DD"}},
139   {0, {0,}}
140};
141
142/*****************************************************************************
143 *
144 * Open a floppy image for drive 'drive' if it is not yet openend
145 * and a name was given. Determine the image geometry depending on the
146 * type of image and store the results into the global drv[] structure
147 *
148 *****************************************************************************/
149
150#define MAXSIZE 5760 * 256 + 80
151static void atari_load_proc(device_image_interface &image)
152{
153   atari_fdc_t *fdc = get_safe_token(image.device().owner());
154   int id = floppy_get_drive(image);
155   int size, i;
156   const char *ext;
157
158   fdc->drv[id].image = (UINT8*)image.image_malloc(MAXSIZE);
159   if (!fdc->drv[id].image)
160      return;
161
162   /* tell whether the image is writable */
163   fdc->drv[id].mode = !image.is_readonly();
164   /* set up image if it has been created */
165   if (image.has_been_created())
166   {
167      int sector;
168      char buff[256];
169      memset(buff, 0, sizeof(buff));
170      /* default to 720 sectors */
171      for( sector = 0; sector < 720; sector++ )
172         image.fwrite(buff, 256);
173      image.fseek(0, SEEK_SET);
174   }
175
176   size = image.fread(fdc->drv[id].image, MAXSIZE);
177   if( size <= 0 )
178   {
179      fdc->drv[id].image = NULL;
180      return;
181   }
182   /* re allocate the buffer; we don't want to be too lazy ;) */
183    fdc->drv[id].image = (UINT8*)image.image_realloc(fdc->drv[id].image, size);
184
185   ext = image.filetype();
186    /* no extension: assume XFD format (no header) */
187    if (!ext)
188    {
189        fdc->drv[id].type = FORMAT_XFD;
190        fdc->drv[id].header_skip = 0;
191    }
192    else
193    /* XFD extension */
194    if( toupper(ext[0])=='X' && toupper(ext[1])=='F' && toupper(ext[2])=='D' )
195    {
196        fdc->drv[id].type = FORMAT_XFD;
197        fdc->drv[id].header_skip = 0;
198    }
199    else
200    /* ATR extension */
201    if( toupper(ext[0])=='A' && toupper(ext[1])=='T' && toupper(ext[2])=='R' )
202    {
203        fdc->drv[id].type = FORMAT_ATR;
204        fdc->drv[id].header_skip = 16;
205    }
206    else
207    /* DSK extension */
208    if( toupper(ext[0])=='D' && toupper(ext[1])=='S' && toupper(ext[2])=='K' )
209    {
210        fdc->drv[id].type = FORMAT_DSK;
211        fdc->drv[id].header_skip = sizeof(dsk_format);
212    }
213    else
214    {
215      fdc->drv[id].type = FORMAT_XFD;
216        fdc->drv[id].header_skip = 0;
217    }
218
219   if( fdc->drv[id].type == FORMAT_ATR &&
220      (fdc->drv[id].image[0] != 0x96 || fdc->drv[id].image[1] != 0x02) )
221   {
222      fdc->drv[id].type = FORMAT_XFD;
223      fdc->drv[id].header_skip = 0;
224   }
225
226   switch (fdc->drv[id].type)
227   {
228   /* XFD or unknown format: find a matching size from the table */
229   case FORMAT_XFD:
230      for( i = 0; xfd_formats[i].size; i++ )
231      {
232         if( size == xfd_formats[i].size )
233         {
234            fdc->drv[id].density = xfd_formats[i].dsk.density;
235            fdc->drv[id].tracks = xfd_formats[i].dsk.tracks;
236            fdc->drv[id].spt = xfd_formats[i].dsk.spt;
237            fdc->drv[id].heads = (xfd_formats[i].dsk.doublesided) ? 2 : 1;
238            fdc->drv[id].bseclen = 128;
239            fdc->drv[id].seclen = 256 * xfd_formats[i].dsk.seclen_hi + xfd_formats[i].dsk.seclen_lo;
240            fdc->drv[id].sectors = fdc->drv[id].tracks * fdc->drv[id].heads * fdc->drv[id].spt;
241            break;
242         }
243      }
244      break;
245   /* ATR format: find a size including the 16 bytes header */
246   case FORMAT_ATR:
247      {
248         int s;
249
250         fdc->drv[id].bseclen = 128;
251         /* get sectors from ATR header */
252         s = (size - 16) / 128;
253         /* 3 + odd number of sectors ? */
254         if ( fdc->drv[id].image[4] == 128 || (s % 18) == 0 || (s % 26) == 0 || ((s - 3) % 1) != 0 )
255         {
256            fdc->drv[id].sectors = s;
257            fdc->drv[id].seclen = 128;
258            /* sector size 128 or count not evenly dividable by 26 ? */
259            if( fdc->drv[id].seclen == 128 || (s % 26) != 0 )
260            {
261               /* yup! single density */
262               fdc->drv[id].density = 0;
263               fdc->drv[id].spt = 18;
264               fdc->drv[id].heads = 1;
265               fdc->drv[id].tracks = s / 18;
266               if( s % 18 != 0 )
267                  fdc->drv[id].tracks += 1;
268               if( fdc->drv[id].tracks % 2 == 0 && fdc->drv[id].tracks > 80 )
269               {
270                  fdc->drv[id].heads = 2;
271                  fdc->drv[id].tracks /= 2;
272               }
273            }
274            else
275            {
276               /* yes: medium density */
277               fdc->drv[id].density = 0;
278               fdc->drv[id].spt = 26;
279               fdc->drv[id].heads = 1;
280               fdc->drv[id].tracks = s / 26;
281               if( s % 26 != 0 )
282                  fdc->drv[id].tracks += 1;
283               if( fdc->drv[id].tracks % 2 == 0 && fdc->drv[id].tracks > 80 )
284               {
285                  fdc->drv[id].heads = 2;
286                  fdc->drv[id].tracks /= 2;
287               }
288            }
289         }
290         else
291         {
292            /* it's double density */
293            s = (s - 3) / 2 + 3;
294            fdc->drv[id].sectors = s;
295            fdc->drv[id].density = 2;
296            fdc->drv[id].seclen = 256;
297            fdc->drv[id].spt = 18;
298            fdc->drv[id].heads = 1;
299            fdc->drv[id].tracks = s / 18;
300            if( s % 18 != 0 )
301               fdc->drv[id].tracks += 1;
302            if( fdc->drv[id].tracks % 2 == 0 && fdc->drv[id].tracks > 80 )
303            {
304               fdc->drv[id].heads = 2;
305               fdc->drv[id].tracks /= 2;
306            }
307         }
308      }
309      break;
310   /* DSK format: it's all in the header */
311   case FORMAT_DSK:
312      {
313         dsk_format *dsk = (dsk_format *) fdc->drv[id].image;
314
315         fdc->drv[id].tracks = dsk->tracks;
316         fdc->drv[id].spt = dsk->spt;
317         fdc->drv[id].heads = (dsk->doublesided) ? 2 : 1;
318         fdc->drv[id].seclen = 256 * dsk->seclen_hi + dsk->seclen_lo;
319         fdc->drv[id].bseclen = fdc->drv[id].seclen;
320         fdc->drv[id].sectors = fdc->drv[id].tracks * fdc->drv[id].heads * fdc->drv[id].spt;
321      }
322      break;
323   }
324   logerror("atari opened floppy '%s', %d sectors (%d %s%s) %d bytes/sector\n",
325         image.filename(),
326         fdc->drv[id].sectors,
327         fdc->drv[id].tracks,
328         (fdc->drv[id].heads == 1) ? "SS" : "DS",
329         (fdc->drv[id].density == 0) ? "SD" : (fdc->drv[id].density == 1) ? "MD" : "DD",
330         fdc->drv[id].seclen);
331   return;
332}
333
334
335
336/*****************************************************************************
337 *
338 * This is a description of the data flow between Atari (A) and the
339 * Floppy (F) for the supported commands.
340 *
341 * A->F     DEV  CMD  AUX1 AUX2 CKS
342 *          '1'  'S'  00   00                 get status
343 * F->A     ACK  CPL  04   FF   E0   00   CKS
344 *                     ^    ^
345 *                     |    |
346 *                     |    bit 7 : door closed
347 *                     |
348 *                     bit7  : MD 128 bytes/sector, 26 sectors/track
349 *                     bit5  : DD 256 bytes/sector, 18 sectors/track
350 *                     else  : SD 128 bytes/sector, 18 sectors/track
351 *
352 * A->F     DEV  CMD  AUX1 AUX2 CKS
353 *          '1'  'R'  SECL SECH               read sector
354 * F->A     ACK                               command acknowledge
355 *               ***                          now read the sector
356 * F->A              CPL                      complete: sector read
357 * F->A                  128/256 byte CKS
358 *
359 * A->F     DEV  CMD  AUX1 AUX2 CKS
360 *          '1'  'W'  SECL SECH               write with verify
361 * F->A     ACK                               command acknowledge
362 * A->F          128/256 data CKS
363 * F->A                            CPL        complete: CKS okay
364 *          execute writing the sector
365 * F->A                                 CPL   complete: sector written
366 *
367 * A->F     DEV  CMD  AUX1 AUX2 CKS
368 *          '1'  'P'  SECL SECH               put sector
369 * F->A     ACK                               command acknowledge
370 * A->F          128/256 data CKS
371 * F->A                            CPL        complete: CKS okay
372 *          execute writing the sector
373 * F->A                                 CPL   complete: sector written
374 *
375 * A->F     DEV  CMD  AUX1 AUX2 CKS
376 *           '1' '!'  xx   xx                 single density format
377 * F->A     ACK                               command acknowledge
378 *          execute formatting
379 * F->A               CPL                     complete: format
380 * F->A                    128/256 byte CKS   bad sector table
381 *
382 *
383 * A->F     DEV  CMD  AUX1 AUX2 CKS
384 *          '1'  '"'  xx   xx                 double density format
385 * F->A     ACK                               command acknowledge
386 *          execute formatting
387 * F->A               CPL                     complete: format
388 * F->A                    128/256 byte CKS   bad sector table
389 *
390 *****************************************************************************/
391static void make_chksum(UINT8 * chksum, UINT8 data)
392{
393   UINT8 newone;
394   newone= *chksum + data;
395   if (newone < *chksum)
396      newone++;
397
398   if (VERBOSE_CHKSUM)
399      logerror("atari chksum old $%02x + data $%02x -> new $%02x\n", *chksum, data, newone);
400
401   *chksum = newone;
402}
403
404static void clr_serout(device_t *device,int expect_data)
405{
406   atari_fdc_t *fdc = get_safe_token(device);
407
408   fdc->serout_chksum = 0;
409   fdc->serout_offs = 0;
410   fdc->serout_count = expect_data + 1;
411}
412
413static void add_serout(device_t *device,int expect_data)
414{
415   atari_fdc_t *fdc = get_safe_token(device);
416
417   fdc->serout_chksum = 0;
418   fdc->serout_count = expect_data + 1;
419}
420
421static void clr_serin(device_t *device, int ser_delay)
422{
423   atari_fdc_t *fdc = get_safe_token(device);
424   device_t *pokey = device->machine().device("pokey");
425   fdc->serin_chksum = 0;
426   fdc->serin_offs = 0;
427   fdc->serin_count = 0;
428   pokey_serin_ready(pokey, ser_delay * 40);
429}
430
431static void add_serin(device_t *device,UINT8 data, int with_checksum)
432{
433   atari_fdc_t *fdc = get_safe_token(device);
434   fdc->serin_buff[fdc->serin_count++] = data;
435   if (with_checksum)
436      make_chksum(&fdc->serin_chksum, data);
437}
438
439static void ATTR_PRINTF(2,3) atari_set_frame_message(device_t *device,const char *fmt, ...)
440{
441   va_list arg;
442   va_start(arg, fmt);
443
444   vsprintf(atari_frame_message, fmt, arg);
445   atari_frame_counter = 30; /* FIXME */
446
447   va_end(arg);
448}
449
450static void a800_serial_command(device_t *device)
451{
452   int i, drive, sector, offset;
453   atari_fdc_t *fdc = get_safe_token(device);
454
455   if( !fdc->serout_offs )
456   {
457      if (VERBOSE_SERIAL)
458         logerror("atari serout command offset = 0\n");
459      return;
460   }
461   clr_serin(device, 10);
462
463   if (VERBOSE_SERIAL)
464   {
465      logerror("atari serout command %d: %02X %02X %02X %02X %02X : %02X ",
466         fdc->serout_offs,
467         fdc->serout_buff[0], fdc->serout_buff[1], fdc->serout_buff[2],
468         fdc->serout_buff[3], fdc->serout_buff[4], fdc->serout_chksum);
469   }
470
471   if (fdc->serout_chksum == 0)
472   {
473      if (VERBOSE_SERIAL)
474         logerror("OK\n");
475
476      drive = fdc->serout_buff[0] - '1';   /* drive # */
477      /* sector # */
478      if (drive < 0 || drive > 3)          /* ignore unknown drives */
479      {
480         logerror("atari unsupported drive #%d\n", drive+1);
481         atari_set_frame_message(device, "DRIVE #%d not supported", drive+1);
482         return;
483      }
484
485      /* extract sector number from the command buffer */
486      sector = fdc->serout_buff[2] + 256 * fdc->serout_buff[3];
487
488      switch (fdc->serout_buff[1]) /* command ? */
489      {
490         case 'S':   /* status */
491            atari_set_frame_message(device, "DRIVE #%d STATUS", drive+1);
492
493            if (VERBOSE_SERIAL)
494               logerror("atari status\n");
495
496            add_serin(device,'A',0);
497            add_serin(device,'C',0);
498            if (!fdc->drv[drive].mode) /* read only mode ? */
499            {
500               if (fdc->drv[drive].spt == 26)
501                  add_serin(device,0x80,1);   /* MD: 0x80 */
502               else
503               if (fdc->drv[drive].seclen == 128)
504                  add_serin(device,0x00,1);   /* SD: 0x00 */
505               else
506                  add_serin(device,0x20,1);   /* DD: 0x20 */
507            }
508            else
509            {
510               if (fdc->drv[drive].spt == 26)
511                  add_serin(device,0x84,1);   /* MD: 0x84 */
512               else
513               if (fdc->drv[drive].seclen == 128)
514                  add_serin(device,0x04,1);   /* SD: 0x04 */
515               else
516                  add_serin(device,0x24,1);   /* DD: 0x24 */
517            }
518            if (fdc->drv[drive].image)
519               add_serin(device,0xff,1);   /* door closed: 0xff */
520            else
521               add_serin(device,0x7f,1);   /* door open: 0x7f */
522            add_serin(device,0xe0,1);   /* dunno */
523            add_serin(device,0x00,1);   /* dunno */
524            add_serin(device,fdc->serin_chksum,0);
525            break;
526
527         case 'R':   /* read sector */
528            if (VERBOSE_SERIAL)
529               logerror("atari read sector #%d\n", sector);
530
531            if( sector < 1 || sector > fdc->drv[drive].sectors )
532            {
533               atari_set_frame_message(device, "DRIVE #%d READ SECTOR #%3d - ERR", drive+1, sector);
534
535               if (VERBOSE_SERIAL)
536                  logerror("atari bad sector #\n");
537
538               add_serin(device,'E',0);
539               break;
540            }
541            add_serin(device,'A',0);   /* acknowledge */
542            add_serin(device,'C',0);   /* completed */
543            if (sector < 4)    /* sector 1 .. 3 might be different length */
544            {
545               atari_set_frame_message(device, "DRIVE #%d READ SECTOR #%3d - SD", drive+1, sector);
546               offset = (sector - 1) * fdc->drv[drive].bseclen + fdc->drv[drive].header_skip;
547               for (i = 0; i < 128; i++)
548                  add_serin(device,fdc->drv[drive].image[offset++],1);
549            }
550            else
551            {
552               atari_set_frame_message(device, "DRIVE #%d READ SECTOR #%3d - %cD", drive+1, sector, (fdc->drv[drive].seclen == 128) ? 'S' : 'D');
553                    offset = (sector - 1) * fdc->drv[drive].seclen + fdc->drv[drive].header_skip;
554               for (i = 0; i < fdc->drv[drive].seclen; i++)
555                  add_serin(device,fdc->drv[drive].image[offset++],1);
556            }
557            add_serin(device,fdc->serin_chksum,0);
558            break;
559
560         case 'W':   /* write sector with verify */
561            if (VERBOSE_SERIAL)
562               logerror("atari write sector #%d\n", sector);
563
564            add_serin(device,'A',0);
565            if (sector < 4)    /* sector 1 .. 3 might be different length */
566            {
567               add_serout(device,fdc->drv[drive].bseclen);
568               atari_set_frame_message(device, "DRIVE #%d WRITE SECTOR #%3d - SD", drive+1, sector);
569                }
570            else
571            {
572               add_serout(device,fdc->drv[drive].seclen);
573               atari_set_frame_message(device, "DRIVE #%d WRITE SECTOR #%3d - %cD", drive+1, sector, (fdc->drv[drive].seclen == 128) ? 'S' : 'D');
574                }
575            break;
576
577         case 'P':   /* put sector (no verify) */
578            if (VERBOSE_SERIAL)
579               logerror("atari put sector #%d\n", sector);
580
581            add_serin(device,'A',0);
582            if (sector < 4)    /* sector 1 .. 3 might be different length */
583            {
584               add_serout(device,fdc->drv[drive].bseclen);
585               atari_set_frame_message(device, "DRIVE #%d PUT SECTOR #%3d - SD", drive+1, sector);
586                }
587            else
588            {
589               add_serout(device,fdc->drv[drive].seclen);
590               atari_set_frame_message(device, "DRIVE #%d PUT SECTOR #%3d - %cD", drive+1, sector, (fdc->drv[drive].seclen == 128) ? 'S' : 'D');
591                }
592            break;
593
594         case '!':   /* SD format */
595            if (VERBOSE_SERIAL)
596               logerror("atari format SD drive #%d\n", drive+1);
597
598            atari_set_frame_message(device, "DRIVE #%d FORMAT SD", drive+1);
599                add_serin(device,'A',0);   /* acknowledge */
600            add_serin(device,'C',0);   /* completed */
601            for (i = 0; i < 128; i++)
602               add_serin(device,0,1);
603            add_serin(device,fdc->serin_chksum,0);
604            break;
605
606         case '"':   /* DD format */
607            if (VERBOSE_SERIAL)
608               logerror("atari format DD drive #%d\n", drive+1);
609
610            atari_set_frame_message(device, "DRIVE #%d FORMAT DD", drive+1);
611                add_serin(device,'A',0);   /* acknowledge */
612            add_serin(device,'C',0);   /* completed */
613            for (i = 0; i < 256; i++)
614               add_serin(device,0,1);
615            add_serin(device,fdc->serin_chksum,0);
616            break;
617
618         default:
619            if (VERBOSE_SERIAL)
620               logerror("atari unknown command #%c\n", fdc->serout_buff[1]);
621
622            atari_set_frame_message(device, "DRIVE #%d UNKNOWN CMD '%c'", drive+1, fdc->serout_buff[1]);
623                add_serin(device,'N',0);   /* negative acknowledge */
624      }
625   }
626   else
627   {
628      atari_set_frame_message(device, "serial cmd chksum error");
629      if (VERBOSE_SERIAL)
630         logerror("BAD\n");
631
632      add_serin(device,'E',0);
633   }
634   if (VERBOSE_SERIAL)
635      logerror("atari %d bytes to read\n", fdc->serin_count);
636}
637
638static void a800_serial_write(device_t *device)
639{
640   int i, drive, sector, offset;
641   atari_fdc_t *fdc = get_safe_token(device);
642
643   if (VERBOSE_SERIAL)
644   {
645      logerror("atari serout %d bytes written : %02X ",
646         fdc->serout_offs, fdc->serout_chksum);
647   }
648
649   clr_serin(device, 80);
650   if (fdc->serout_chksum == 0)
651   {
652      if (VERBOSE_SERIAL)
653         logerror("OK\n");
654
655      add_serin(device,'C',0);
656      /* write the sector */
657      drive = fdc->serout_buff[0] - '1';   /* drive # */
658      /* not write protected and image available ? */
659      if (fdc->drv[drive].mode && fdc->drv[drive].image)
660      {
661         /* extract sector number from the command buffer */
662         sector = fdc->serout_buff[2] + 256 * fdc->serout_buff[3];
663         if (sector < 4)    /* sector 1 .. 3 might be different length */
664         {
665            offset = (sector - 1) * fdc->drv[drive].bseclen + fdc->drv[drive].header_skip;
666
667            if (VERBOSE_SERIAL)
668               logerror("atari storing 128 byte sector %d at offset 0x%08X", sector, offset );
669
670            for (i = 0; i < 128; i++)
671               fdc->drv[drive].image[offset++] = fdc->serout_buff[5+i];
672            atari_set_frame_message(device, "DRIVE #%d WROTE SECTOR #%3d - SD", drive+1, sector);
673            }
674         else
675         {
676            offset = (sector - 1) * fdc->drv[drive].seclen + fdc->drv[drive].header_skip;
677
678            if (VERBOSE_SERIAL)
679               logerror("atari storing %d byte sector %d at offset 0x%08X", fdc->drv[drive].seclen, sector, offset );
680
681            for (i = 0; i < fdc->drv[drive].seclen; i++)
682               fdc->drv[drive].image[offset++] = fdc->serout_buff[5+i];
683            atari_set_frame_message(device, "DRIVE #%d WROTE SECTOR #%3d - %cD", drive+1, sector, (fdc->drv[drive].seclen == 128) ? 'S' : 'D');
684            }
685         add_serin(device,'C',0);
686      }
687      else
688      {
689         add_serin(device,'E',0);
690      }
691   }
692   else
693   {
694      if (VERBOSE_SERIAL)
695         logerror("BAD\n");
696
697      add_serin(device,'E',0);
698   }
699}
700
701READ8_DEVICE_HANDLER ( atari_serin_r )
702{
703   int data = 0x00;
704   int ser_delay = 0;
705   atari_fdc_t *fdc = get_safe_token(device);
706
707   if (fdc->serin_count)
708   {
709      device_t *pokey = device->machine().device("pokey");
710
711      data = fdc->serin_buff[fdc->serin_offs];
712      ser_delay = 2 * 40;
713      if (fdc->serin_offs < 3)
714      {
715         ser_delay = 4 * 40;
716         if (fdc->serin_offs < 2)
717            ser_delay = 200 * 40;
718      }
719      fdc->serin_offs++;
720      if (--fdc->serin_count == 0)
721         fdc->serin_offs = 0;
722      else
723         pokey_serin_ready(pokey, ser_delay);
724   }
725
726   if (VERBOSE_SERIAL)
727      logerror("atari serin[$%04x] -> $%02x; delay %d\n", fdc->serin_offs, data, ser_delay);
728
729   return data;
730}
731
732WRITE8_DEVICE_HANDLER ( atari_serout_w )
733{
734   pia6821_device *pia = device->machine().device<pia6821_device>( "pia" );
735   atari_fdc_t *fdc = get_safe_token(device);
736
737   /* ignore serial commands if no floppy image is specified */
738   if( !fdc->drv[0].image )
739      return;
740   if (fdc->serout_count)
741   {
742      /* store data */
743      fdc->serout_buff[fdc->serout_offs] = data;
744
745      if (VERBOSE_SERIAL)
746         logerror("atari serout[$%04x] <- $%02x; count %d\n", fdc->serout_offs, data, fdc->serout_count);
747
748      fdc->serout_offs++;
749      if (--fdc->serout_count == 0)
750      {
751         /* exclusive or written checksum with calculated */
752         fdc->serout_chksum ^= data;
753         /* if the attention line is high, this should be data */
754         if (pia->irq_b_state())
755            a800_serial_write(device);
756      }
757      else
758      {
759         make_chksum(&fdc->serout_chksum, data);
760      }
761   }
762}
763
764WRITE_LINE_DEVICE_HANDLER(atarifdc_pia_cb2_w)
765{
766   atari_fdc_t *fdc = get_safe_token(device);
767   if (!state)
768   {
769      clr_serout(device,4); /* expect 4 command bytes + checksum */
770   }
771   else
772   {
773      fdc->serin_delay = 0;
774      a800_serial_command(device);
775   }
776}
777
778static FLOPPY_IDENTIFY( atari_dsk_identify )
779{
780   *vote = 100;
781   return FLOPPY_ERROR_SUCCESS;
782}
783
784
785static FLOPPY_CONSTRUCT( atari_dsk_construct )
786{
787   return FLOPPY_ERROR_SUCCESS;
788}
789
790FLOPPY_OPTIONS_START( atari_only )
791   FLOPPY_OPTION(
792      atari_dsk,
793      "atr,dsk,xfd",
794      "Atari floppy disk image",
795      atari_dsk_identify,
796      atari_dsk_construct,
797      NULL,
798      NULL
799   )
800FLOPPY_OPTIONS_END0
801
802static const floppy_config atari_floppy_config =
803{
804   DEVCB_NULL,
805   DEVCB_NULL,
806   DEVCB_NULL,
807   DEVCB_NULL,
808   DEVCB_NULL,
809   FLOPPY_STANDARD_5_25_DSHD,
810   FLOPPY_OPTIONS_NAME(atari_only),
811   NULL
812};
813
814static MACHINE_CONFIG_FRAGMENT( atari_fdc )
815   MCFG_FLOPPY_4_DRIVES_ADD(atari_floppy_config)
816MACHINE_CONFIG_END
817
818device_t *atari_floppy_get_device_child(device_t *device,int drive)
819{
820   switch(drive) {
821      case 0 : return device->subdevice(FLOPPY_0);
822      case 1 : return device->subdevice(FLOPPY_1);
823      case 2 : return device->subdevice(FLOPPY_2);
824      case 3 : return device->subdevice(FLOPPY_3);
825   }
826   return NULL;
827}
828
829static DEVICE_START(atari_fdc)
830{
831   int id;
832   for(id=0;id<4;id++)
833   {
834      floppy_install_load_proc(atari_floppy_get_device_child(device, id), atari_load_proc);
835   }
836}
837
838static DEVICE_RESET(atari_fdc)
839{
840}
841
842DEVICE_GET_INFO( atari_fdc )
843{
844   switch (state)
845   {
846      /* --- the following bits of info are returned as 64-bit signed integers --- */
847      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                                    break;
848      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(atari_fdc_t);                        break;
849
850      /* --- the following bits of info are returned as pointers --- */
851      case DEVINFO_PTR_MACHINE_CONFIG:            info->machine_config = MACHINE_CONFIG_NAME(atari_fdc);      break;
852
853      /* --- the following bits of info are returned as pointers to data or functions --- */
854      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(atari_fdc);               break;
855      case DEVINFO_FCT_STOP:                     /* Nothing */                                    break;
856      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(atari_fdc);               break;
857
858      /* --- the following bits of info are returned as NULL-terminated strings --- */
859      case DEVINFO_STR_NAME:                     strcpy(info->s, "Atari FDC");                        break;
860      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "Atari FDC");                        break;
861      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                              break;
862      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);                           break;
863      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright the MESS Team");             break;
864   }
865}
866
867DEFINE_LEGACY_DEVICE(ATARI_FDC, atari_fdc);
src/mame/includes/msx_slot.h
r0r11461
1/*****************************************************************************
2 *
3 * includes/msx_slot.h
4 *
5 ****************************************************************************/
6
7#ifndef MSX_SLOT_H_
8#define MSX_SLOT_H_
9
10
11enum {
12   MSX_LAYOUT_SLOT_ENTRY,
13   MSX_LAYOUT_KANJI_ENTRY,
14   MSX_LAYOUT_RAMIO_SET_BITS_ENTRY,
15   MSX_LAYOUT_LAST
16};
17
18typedef struct {
19   int entry;
20   int type;
21   int slot_primary, slot_secondary, slot_page, page_extent;
22   int size, option;
23} msx_slot_layout;
24
25#define MSX_LAYOUT_INIT(msx) \
26static const msx_slot_layout msx_slot_layout_##msx[] = {
27
28#define MSX_LAYOUT_SLOT(prim, sec, page, extend, type, size, option) \
29   {                        \
30      MSX_LAYOUT_SLOT_ENTRY,      \
31      SLOT_##type,            \
32      prim,                  \
33      sec,                  \
34      page,                  \
35      extend,                  \
36      size,                  \
37      option                  \
38   },
39
40#define MSX_LAYOUT_KANJI(offset) \
41   {                        \
42      MSX_LAYOUT_KANJI_ENTRY,      \
43      SLOT_EMPTY,               \
44      0,                     \
45      0,                     \
46      0,                     \
47      0,                     \
48      0,                     \
49      offset                  \
50   },
51
52#define MSX_LAYOUT_RAMIO_SET_BITS(offset) \
53   {                        \
54      MSX_LAYOUT_RAMIO_SET_BITS_ENTRY,      \
55      SLOT_EMPTY,               \
56      0,                     \
57      0,                     \
58      0,                     \
59      0,                     \
60      0,                     \
61      offset                  \
62   },
63
64#define MSX_LAYOUT_END \
65   {                        \
66      MSX_LAYOUT_LAST,         \
67      SLOT_END,               \
68      0,                     \
69      0,                     \
70      0,                     \
71      0,                     \
72      0,                     \
73      0                     \
74   }                        \
75};
76
77
78enum msx_slot_type {
79   SLOT_EMPTY = 0,
80   SLOT_MSXDOS2,
81   SLOT_KONAMI_SCC,
82   SLOT_KONAMI,
83   SLOT_ASCII8,
84   SLOT_ASCII16,
85   SLOT_GAMEMASTER2,
86   SLOT_ASCII8_SRAM,
87   SLOT_ASCII16_SRAM,
88   SLOT_RTYPE,
89   SLOT_MAJUTSUSHI,
90   SLOT_FMPAC,
91   SLOT_SUPERLOADRUNNER,
92   SLOT_SYNTHESIZER,
93   SLOT_CROSS_BLAIM,
94   SLOT_DISK_ROM,
95   SLOT_KOREAN_80IN1,
96   SLOT_KOREAN_126IN1,
97   SLOT_KOREAN_90IN1,
98   SLOT_LAST_CARTRIDGE_TYPE = SLOT_KOREAN_90IN1,
99   SLOT_SOUNDCARTRIDGE,
100   SLOT_ROM,
101   SLOT_RAM,
102   SLOT_RAM_MM,
103   SLOT_CARTRIDGE1,
104   SLOT_CARTRIDGE2,
105        SLOT_DISK_ROM2,
106   SLOT_END
107};
108
109enum msx_mem_type {
110   MSX_MEM_ROM,
111   MSX_MEM_RAM,
112   MSX_MEM_HANDLER
113};
114
115typedef struct {
116   int m_type;
117   int m_start_page;
118   int m_bank_mask;
119   int m_banks[4];
120   int m_size;
121   UINT8 *m_mem;
122   const char *m_sramfile;
123   union {
124      struct {
125         UINT8 *mem;
126         int sram_support;
127         int sram_active;
128         int opll_active;
129      } fmpac;
130      struct {
131         int active;
132      } scc;
133      struct {
134         UINT8 *mem;
135         int sram_mask;
136         int empty_mask;
137      } sram;
138      struct {
139         int scc_active;
140         int sccp_active;
141         int ram_mode[4];
142         int banks_saved[4];
143         int mode;
144      } sccp;
145   } m_cart;
146} slot_state;
147
148typedef struct {
149   int slot_type;
150   int mem_type;
151   char name[32];
152   int (*init)(running_machine &machine, slot_state*, int page, UINT8 *mem, int size);
153   void (*reset)(running_machine &machine, slot_state*);
154   void (*map)(running_machine &machine, slot_state*, int page);
155   void (*write)(running_machine &machine, slot_state*, UINT16, UINT8);
156   int (*loadsram)(running_machine &machine, slot_state*);
157   int (*savesram)(running_machine &machine, slot_state*);
158} msx_slot;
159
160extern const msx_slot msx_slot_list[];
161
162#define MSX_SLOT_START \
163const msx_slot msx_slot_list[] = {
164
165#define MSX_SLOT_ROM(type, ent) { \
166   type,                     \
167   MSX_MEM_ROM,               \
168   #type,                     \
169   slot_##ent##_init,            \
170   slot_##ent##_reset,            \
171   slot_##ent##_map,            \
172   NULL,                     \
173   NULL,                     \
174   NULL                     \
175},
176
177#define MSX_SLOT_RAM(type, ent) { \
178   type,                     \
179   MSX_MEM_RAM,               \
180   #type,                     \
181   slot_##ent##_init,            \
182   slot_##ent##_reset,            \
183   slot_##ent##_map,            \
184   NULL,                     \
185   NULL,                     \
186   NULL                     \
187},
188
189#define MSX_SLOT(type, ent) { \
190   type,                     \
191   MSX_MEM_HANDLER,            \
192   #type,                     \
193   slot_##ent##_init,            \
194   slot_##ent##_reset,            \
195   slot_##ent##_map,            \
196   slot_##ent##_write,            \
197   NULL,                     \
198   NULL                     \
199},
200
201#define MSX_SLOT_SRAM(type, ent) { \
202   type,                     \
203   MSX_MEM_HANDLER,            \
204   #type,                     \
205   slot_##ent##_init,            \
206   slot_##ent##_reset,            \
207   slot_##ent##_map,            \
208   slot_##ent##_write,            \
209   slot_##ent##_loadsram,         \
210   slot_##ent##_savesram         \
211},
212
213#define MSX_SLOT_NULL(type) { \
214   type,                     \
215   MSX_MEM_ROM,               \
216   #type,                     \
217   NULL,                     \
218   NULL,                     \
219   NULL,                     \
220   NULL,                     \
221   NULL,                     \
222   NULL                     \
223},
224
225#define MSX_SLOT_END \
226   { SLOT_END, 0, "", NULL, NULL, NULL, NULL, NULL } \
227};
228
229#define MSX_SLOT_INIT(nm)          static int \
230   slot_##nm##_init (running_machine &machine, slot_state *state, int page, UINT8 *mem, int size)
231#define MSX_SLOT_MAP(nm)         \
232   static void slot_##nm##_map (running_machine &machine, slot_state *state, int page)
233#define MSX_SLOT_WRITE(nm)         \
234   static void slot_##nm##_write (running_machine &machine, slot_state *state, UINT16 addr, UINT8 val)
235#define MSX_SLOT_RESET(nm)         \
236   static void slot_##nm##_reset (running_machine &machine, slot_state *state)
237#define MSX_SLOT_LOADSRAM(nm)      \
238   static int slot_##nm##_loadsram (running_machine &machine, slot_state *state)
239#define MSX_SLOT_SAVESRAM(nm)      \
240   static int slot_##nm##_savesram (running_machine &machine, slot_state *state)
241
242typedef struct {
243   char name[9];
244   const msx_slot_layout *layout;
245} msx_driver_struct;
246
247extern const msx_driver_struct msx_driver_list[];
248
249#define MSX_DRIVER_LIST      \
250const msx_driver_struct msx_driver_list[] = {
251#define MSX_DRIVER(foo)      \
252      { #foo, msx_slot_layout_##foo },
253#define MSX_DRIVER_END      \
254      { "", NULL }      \
255};
256
257
258#endif /* MSX_SLOT_H_ */
src/mame/includes/nes.h
r0r11461
1/*****************************************************************************
2 *
3 * includes/nes.h
4 *
5 * Nintendo Entertainment System (Famicom)
6 *
7 ****************************************************************************/
8
9#ifndef NES_H_
10#define NES_H_
11
12
13/***************************************************************************
14    CONSTANTS
15***************************************************************************/
16
17#define NTSC_CLOCK           N2A03_DEFAULTCLOCK     /* 1.789772 MHz */
18#define PAL_CLOCK              (26601712.0/16)        /* 1.662607 MHz */
19
20#define NES_BATTERY_SIZE 0x2000
21
22
23/***************************************************************************
24    TYPE DEFINITIONS
25***************************************************************************/
26
27struct nes_input
28{
29   UINT32 shift;
30   UINT32 i0, i1, i2;
31};
32
33/*PPU fast banking constants and structures */
34
35#define CHRROM 0
36#define CHRRAM 1
37
38typedef struct
39{
40   int source;   //defines source of base pointer
41   int origin; //defines offset of 0x400 byte segment at base pointer
42   UINT8* access;   //source translated + origin -> valid pointer!
43} chr_bank;
44
45/*PPU nametable fast banking constants and structures */
46
47#define CIRAM 0
48#define ROM 1
49#define EXRAM 2
50#define MMC5FILL 3
51#define CART_NTRAM 4
52
53#define NES_BATTERY 0
54#define NES_WRAM 1
55
56typedef struct
57{
58   int source;      /* defines source of base pointer */
59   int origin;      /* defines offset of 0x400 byte segment at base pointer */
60   int writable;   /* ExRAM, at least, can be write-protected AND used as nametable */
61   UINT8* access;   /* direct access when possible */
62} name_table;
63
64typedef void (*nes_prg_callback)(running_machine &machine, int start, int bank);
65typedef void (*nes_chr_callback)(running_machine &machine, int start, int bank, int source);
66
67class nes_state : public driver_device
68{
69public:
70   nes_state(const machine_config &mconfig, device_type type, const char *tag)
71      : driver_device(mconfig, type, tag) { }
72
73   /* input_related - this part has to be cleaned up (e.g. in_2 and in_3 are not really necessary here...) */
74   nes_input m_in_0, m_in_1, m_in_2, m_in_3;
75   UINT8 m_fck_scan, m_fck_mode;
76
77   int           m_prg_bank[5];
78   chr_bank      m_chr_map[8];  //quick banking structure, because some of this changes multiple times per scanline!
79   name_table    m_nt_page[4];  //quick banking structure for a maximum of 4K of RAM/ROM/ExRAM
80
81   int m_chr_open_bus;
82   int m_prgram_bank5_start, m_battery_bank5_start, m_empty_bank5_start;
83
84   UINT8 m_ce_mask, m_ce_state;
85   UINT8 m_vrc_ls_prg_a, m_vrc_ls_prg_b, m_vrc_ls_chr;
86
87   int m_MMC5_floodtile;
88   int m_MMC5_floodattr;
89   int m_mmc5_vram_control;
90   UINT8 m_mmc5_high_chr;
91   UINT8 m_mmc5_split_scr;
92   UINT8 *m_extended_ntram;
93
94   UINT8 m_mmc5_last_chr_a;
95   UINT16 m_mmc5_vrom_regA[8];
96   UINT16 m_mmc5_vrom_regB[4];
97   UINT8 m_mmc5_prg_regs[4];
98   UINT8 m_mmc5_bank_security;
99   UINT8 m_mmc5_prg_mode;
100   UINT8 m_mmc5_chr_mode;
101   UINT8 m_mmc5_chr_high;
102   UINT8 m_mmc5_split_ctrl;
103   UINT8 m_mmc5_split_yst;
104   UINT8 m_mmc5_split_bank;
105
106   /* video-related */
107   int m_nes_vram_sprite[8]; /* Used only by mmc5 for now */
108   int m_last_frame_flip;
109
110   /* misc */
111   write8_space_func   m_mmc_write_low;
112   const char        *m_mmc_write_low_name;
113   write8_space_func   m_mmc_write_mid;
114   const char        *m_mmc_write_mid_name;
115   write8_space_func   m_mmc_write;
116   const char        *m_mmc_write_name;
117   read8_space_func    m_mmc_read_low;
118   const char        *m_mmc_read_low_name;
119   read8_space_func    m_mmc_read_mid;
120   const char        *m_mmc_read_mid_name;
121   read8_space_func    m_mmc_read;
122   const char        *m_mmc_read_name;
123   emu_timer           *m_irq_timer;
124
125   nes_prg_callback    m_mmc3_prg_cb;   // these are used to simplify a lot emulation of some MMC3 pirate clones
126   nes_chr_callback    m_mmc3_chr_cb;
127
128   /* devices */
129   device_t      *m_maincpu;
130   device_t      *m_ppu;
131   device_t      *m_sound;
132   device_t      *m_cart;
133
134   /* misc region to be allocated at init */
135   // variables which don't change at run-time
136   UINT8      *m_rom;
137   UINT8      *m_vrom;
138   UINT8      *m_vram;
139   UINT8      *m_wram;
140   UINT8      *m_ciram; //PPU nametable RAM - external to PPU!
141   UINT8      *m_battery_ram;
142   UINT8      *m_mapper_ram;
143   UINT8      *m_mapper_bram;
144
145   /***** Mapper-related variables *****/
146
147   // common ones
148   int        m_IRQ_enable, m_IRQ_enable_latch;
149   UINT16     m_IRQ_count, m_IRQ_count_latch;
150   UINT8      m_IRQ_toggle;
151   UINT8      m_IRQ_reset;
152   UINT8      m_IRQ_status;
153   UINT8      m_IRQ_mode;
154   UINT8      m_IRQ_clear;
155   int        m_mult1, m_mult2;
156
157   UINT8 m_mmc_chr_source;         // This is set at init to CHRROM or CHRRAM. a few mappers can swap between
158                           // the two (this is done in the specific handlers).
159
160   UINT8 m_mmc_cmd1, m_mmc_cmd2;      // These represent registers where the mapper writes important values
161   UINT8 m_mmc_count;            // This is used as counter in mappers like 1 and 45
162
163   int m_mmc_prg_base, m_mmc_prg_mask;   // MMC3 based multigame carts select a block of banks by using these (and then act like normal MMC3),
164   int m_mmc_chr_base, m_mmc_chr_mask;   // while MMC3 and clones (mapper 118 & 119) simply set them as 0 and 0xff resp.
165
166   UINT8 m_mmc_prg_bank[6];            // Many mappers writes only some bits of the selected bank (for both PRG and CHR),
167   UINT8 m_mmc_vrom_bank[16];         // hence these are handy to latch bank values.
168
169   UINT16 m_MMC5_vrom_bank[12];         // MMC5 has 10bit wide VROM regs!
170   UINT8 m_mmc_extra_bank[16];         // some MMC3 clone have 2 series of PRG/CHR banks...
171                              // we collect them all here: first 4 elements PRG banks, then 6/8 CHR banks
172
173   UINT8 m_mmc_latch1, m_mmc_latch2;
174   UINT8 m_mmc_reg[16];
175
176   UINT8 m_mmc_dipsetting;
177
178   // misc mapper related variables which should be merged with the above one, where possible
179   int m_mmc1_reg_write_enable;
180   int m_mmc1_latch;
181   int m_mmc1_count;
182
183   int m_mmc3_latch;
184   int m_mmc3_wram_protect;
185   int m_mmc3_alt_irq;
186
187   int m_MMC5_rom_bank_mode;
188   int m_MMC5_vrom_bank_mode;
189   int m_MMC5_vram_protect;
190   int m_MMC5_scanline;
191   int m_vrom_page_a;
192   int m_vrom_page_b;
193   // int vrom_next[4];
194
195   UINT8 m_mmc6_reg;
196
197   // these might be unified in single mmc_reg[] array, together with state->m_mmc_cmd1 & state->m_mmc_cmd2
198   // but be careful that MMC3 clones often use state->m_mmc_cmd1/state->m_mmc_cmd2 (from base MMC3) AND additional regs below!
199   UINT8 m_mapper83_reg[10];
200   UINT8 m_mapper83_low_reg[4];
201   UINT8 m_txc_reg[4];   // used by mappers 132, 172 & 173
202   UINT8 m_subor_reg[4];   // used by mappers 166 & 167
203   UINT8 m_sachen_reg[8];   // used by mappers 137, 138, 139 & 141
204   UINT8 m_map52_reg_written;
205   UINT8 m_map114_reg, m_map114_reg_enabled;
206
207   /***** NES-cart related *****/
208
209   /* load-time cart variables which remain constant */
210   UINT16 m_prg_chunks;      // iNES 2.0 allows for more chunks (a recently dumped multigame cart has 256 chunks of both PRG & CHR!)
211   UINT16 m_chr_chunks;
212   UINT16 m_vram_chunks;
213   UINT8 m_trainer;
214   UINT8 m_battery;         // if there is PRG RAM with battery backup
215   UINT32 m_battery_size;
216   UINT8 m_prg_ram;         // if there is PRG RAM with no backup
217   UINT32 m_wram_size;
218   UINT32 m_mapper_ram_size;
219   UINT32 m_mapper_bram_size;
220
221   /* system variables which don't change at run-time */
222   UINT16 m_mapper;      // for iNES
223   UINT16 m_pcb_id;      // for UNIF & xml
224   UINT8 m_four_screen_vram;
225   UINT8 m_hard_mirroring;
226   UINT8 m_crc_hack;   // this is needed to detect different boards sharing the same Mappers (shame on .nes format)
227   UINT8 m_ines20;
228
229   /***** FDS-floppy related *****/
230
231   int     m_disk_expansion;
232
233   UINT8   m_fds_sides;
234   UINT8   *m_fds_data;   // here, we store a copy of the disk
235   UINT8   *m_fds_ram;   // here, we emulate the RAM adapter
236
237   /* Variables which can change */
238   UINT8   m_fds_motor_on;
239   UINT8   m_fds_door_closed;
240   UINT8   m_fds_current_side;
241   UINT32  m_fds_head_position;
242   UINT8   m_fds_status0;
243   UINT8   m_fds_read_mode;
244   UINT8   m_fds_write_reg;
245
246   /* these are used in the mapper 20 handlers */
247   int     m_fds_last_side;
248   int     m_fds_count;
249};
250
251
252/*----------- defined in machine/nes.c -----------*/
253
254WRITE8_HANDLER ( nes_IN0_w );
255WRITE8_HANDLER ( nes_IN1_w );
256
257/* protos */
258
259DEVICE_IMAGE_LOAD(nes_cart);
260DEVICE_START(nes_disk);
261DEVICE_IMAGE_LOAD(nes_disk);
262DEVICE_IMAGE_UNLOAD(nes_disk);
263
264MACHINE_START( nes );
265MACHINE_RESET( nes );
266
267DRIVER_INIT( famicom );
268
269READ8_HANDLER( nes_IN0_r );
270READ8_HANDLER( nes_IN1_r );
271
272int nes_ppu_vidaccess( device_t *device, int address, int data );
273
274void nes_partialhash(hash_collection &dest, const unsigned char *data, unsigned long length, const char *functions);
275
276/*----------- defined in video/nes.c -----------*/
277
278PALETTE_INIT( nes );
279VIDEO_START( nes );
280SCREEN_UPDATE( nes );
281
282
283#endif /* NES_H_ */
src/mame/includes/pce.h
r0r11461
1/*****************************************************************************
2 *
3 * includes/pce.h
4 *
5 * NEC PC Engine/TurboGrafx16
6 *
7 ****************************************************************************/
8
9#ifndef PCE_H_
10#define PCE_H_
11
12#include "cdrom.h"
13#include "sound/msm5205.h"
14
15#define C6280_TAG         "c6280"
16
17#define   MAIN_CLOCK      21477270
18#define PCE_CD_CLOCK   9216000
19
20#define PCE_HEADER_SIZE      512
21
22#define TG_16_JOY_SIG      0x00
23#define PCE_JOY_SIG         0x40
24#define NO_CD_SIG         0x80
25#define CD_SIG            0x00
26/* these might be used to indicate something, but they always seem to return 1 */
27#define CONST_SIG         0x30
28
29/* the largest possible cartridge image (street fighter 2 - 2.5MB) */
30#define PCE_ROM_MAXSIZE      0x280000
31
32typedef struct
33{
34   UINT8   regs[16];
35   UINT8   *bram;
36   UINT8   *adpcm_ram;
37   int      bram_locked;
38   int      adpcm_read_ptr;
39   UINT8   adpcm_read_buf;
40   int      adpcm_write_ptr;
41   UINT8   adpcm_write_buf;
42   int      adpcm_length;
43   int      adpcm_clock_divider;
44   UINT32  msm_start_addr;
45   UINT32   msm_end_addr;
46   UINT32   msm_half_addr;
47   UINT8   msm_nibble;
48   UINT8   msm_idle;
49
50   /* SCSI signals */
51   int      scsi_BSY;   /* Busy. Bus in use */
52   int      scsi_SEL;   /* Select. Initiator has won arbitration and has selected a target */
53   int      scsi_CD;   /* Control/Data. Target is sending control (data) information */
54   int      scsi_IO;   /* Input/Output. Target is sending (receiving) information */
55   int      scsi_MSG;   /* Message. Target is sending or receiving a message */
56   int      scsi_REQ;   /* Request. Target is requesting a data transfer */
57   int      scsi_ACK;   /* Acknowledge. Initiator acknowledges that it is ready for a data transfer */
58   int      scsi_ATN;   /* Attention. Initiator has a message ready for the target */
59   int      scsi_RST;   /* Reset. Initiator forces all targets and any other initiators to do a warm reset */
60   int      scsi_last_RST;   /* To catch setting of RST signal */
61   int      cd_motor_on;
62   int      selected;
63   UINT8   *command_buffer;
64   int      command_buffer_index;
65   int      status_sent;
66   int      message_after_status;
67   int      message_sent;
68   UINT8   *data_buffer;
69   int      data_buffer_size;
70   int      data_buffer_index;
71   int      data_transferred;
72
73   /* Arcade Card specific */
74   UINT8   *acard_ram;
75   UINT8   acard_latch;
76   UINT8   acard_ctrl[4];
77   UINT32   acard_base_addr[4];
78   UINT16   acard_addr_offset[4];
79   UINT16   acard_addr_inc[4];
80   UINT32   acard_shift;
81   UINT8   acard_shift_reg;
82
83   UINT32   current_frame;
84   UINT32   end_frame;
85   UINT32   last_frame;
86   UINT8   cdda_status;
87   UINT8   cdda_play_mode;
88   UINT8   *subcode_buffer;
89   UINT8   end_mark;
90   cdrom_file   *cd;
91   const cdrom_toc*   toc;
92   emu_timer   *data_timer;
93   emu_timer   *adpcm_dma_timer;
94
95   emu_timer   *cdda_fadeout_timer;
96   emu_timer   *cdda_fadein_timer;
97   double   cdda_volume;
98   emu_timer   *adpcm_fadeout_timer;
99   emu_timer   *adpcm_fadein_timer;
100   double   adpcm_volume;
101} pce_cd_t;
102
103
104class pce_state : public driver_device
105{
106public:
107   pce_state(const machine_config &mconfig, device_type type, const char *tag)
108      : driver_device(mconfig, type, tag) { }
109
110   unsigned char *m_user_ram;
111   UINT8 *m_cd_ram;
112   UINT8 m_io_port_options;
113   UINT8 m_sys3_card;
114   UINT8 m_acard;
115   pce_cd_t m_cd;
116   UINT8 *m_cartridge_ram;
117   int m_joystick_port_select;
118   int m_joystick_data_select;
119   UINT8 m_joy_6b_packet[5];
120};
121
122
123/*----------- defined in machine/pce.c -----------*/
124
125DEVICE_IMAGE_LOAD(pce_cart);
126NVRAM_HANDLER( pce );
127WRITE8_HANDLER ( pce_joystick_w );
128 READ8_HANDLER ( pce_joystick_r );
129
130extern const msm5205_interface pce_cd_msm5205_interface;
131WRITE8_HANDLER( pce_cd_bram_w );
132WRITE8_HANDLER( pce_cd_intf_w );
133READ8_HANDLER( pce_cd_intf_r );
134WRITE8_HANDLER( pce_cd_acard_w );
135READ8_HANDLER( pce_cd_acard_r );
136WRITE8_HANDLER( pce_cd_acard_wram_w );
137READ8_HANDLER( pce_cd_acard_wram_r );
138
139DRIVER_INIT( pce );
140DRIVER_INIT( tg16 );
141DRIVER_INIT( sgx );
142MACHINE_START( pce );
143MACHINE_RESET( pce );
144
145
146#endif /* PCE_H_ */
src/mame/includes/msx.h
r0r11461
1/*****************************************************************************
2 *
3 * includes/msx.h
4 *
5 ****************************************************************************/
6
7#ifndef __MSX_H__
8#define __MSX_H__
9
10#include "machine/wd17xx.h"
11#include "formats/flopimg.h"
12
13#define MSX_MAX_CARTS   (2)
14
15#define TC8521_TAG   "rtc"
16
17class msx_state : public driver_device
18{
19public:
20   msx_state(const machine_config &mconfig, device_type type, const char *tag)
21      : driver_device(mconfig, type, tag) { }
22
23   /* PSG */
24   int m_psg_b;
25   int m_opll_active;
26   /* mouse */
27   UINT16 m_mouse[2];
28   int m_mouse_stat[2];
29   /* rtc */
30   int m_rtc_latch;
31   /* disk */
32   UINT8 m_dsk_stat;
33   /* kanji */
34   UINT8 *m_kanji_mem;
35   int m_kanji_latch;
36   /* memory */
37   const msx_slot_layout *layout;
38   slot_state *m_cart_state[MSX_MAX_CARTS];
39   slot_state *m_state[4];
40   const msx_slot *m_slot[4];
41   UINT8 *m_ram_pages[4];
42   UINT8 *m_empty, m_ram_mapper[4];
43   UINT8 m_ramio_set_bits;
44   slot_state *m_all_state[4][4][4];
45   int m_slot_expanded[4];
46   UINT8 m_primary_slot;
47   UINT8 m_secondary_slot[4];
48   UINT8 m_superloadrunner_bank;
49   UINT8 m_korean90in1_bank;
50   UINT8 *m_top_page;
51   int m_port_c_old;
52   int keylatch;
53};
54
55
56/*----------- defined in machine/msx.c -----------*/
57
58extern const i8255_interface msx_ppi8255_interface;
59extern const wd17xx_interface msx_wd17xx_interface;
60/* start/stop functions */
61extern DRIVER_INIT( msx );
62extern MACHINE_START( msx );
63extern MACHINE_START( msx2 );
64extern MACHINE_RESET( msx );
65extern MACHINE_RESET( msx2 );
66extern INTERRUPT_GEN( msx_interrupt );
67extern INTERRUPT_GEN( msx2_interrupt );
68
69DEVICE_IMAGE_LOAD( msx_cart );
70DEVICE_IMAGE_UNLOAD( msx_cart );
71
72void msx_vdp_interrupt(running_machine &machine, int i);
73
74/* I/O functions */
75READ8_DEVICE_HANDLER( msx_printer_status_r );
76WRITE8_DEVICE_HANDLER( msx_printer_strobe_w );
77WRITE8_DEVICE_HANDLER( msx_printer_data_w );
78
79WRITE8_HANDLER ( msx_psg_port_a_w );
80READ8_HANDLER ( msx_psg_port_a_r );
81WRITE8_HANDLER ( msx_psg_port_b_w );
82READ8_HANDLER ( msx_psg_port_b_r );
83WRITE8_HANDLER ( msx_fmpac_w );
84READ8_HANDLER ( msx_rtc_reg_r );
85WRITE8_HANDLER ( msx_rtc_reg_w );
86WRITE8_HANDLER ( msx_rtc_latch_w );
87WRITE8_HANDLER ( msx_90in1_w );
88
89/* new memory emulation */
90WRITE8_HANDLER (msx_page0_w);
91WRITE8_HANDLER (msx_page0_1_w);
92WRITE8_HANDLER (msx_page1_w);
93WRITE8_HANDLER (msx_page1_1_w);
94WRITE8_HANDLER (msx_page1_2_w);
95WRITE8_HANDLER (msx_page2_w);
96WRITE8_HANDLER (msx_page2_1_w);
97WRITE8_HANDLER (msx_page2_2_w);
98WRITE8_HANDLER (msx_page2_3_w);
99WRITE8_HANDLER (msx_page3_w);
100WRITE8_HANDLER (msx_page3_1_w);
101WRITE8_HANDLER (msx_sec_slot_w);
102 READ8_HANDLER (msx_sec_slot_r);
103WRITE8_HANDLER (msx_ram_mapper_w);
104 READ8_HANDLER (msx_ram_mapper_r);
105 READ8_HANDLER (msx_kanji_r);
106WRITE8_HANDLER (msx_kanji_w);
107
108#endif /* __MSX_H__ */
src/mame/mame.mak
r11460r11461
2727   $(VIDEO) \
2828
2929
30
3130#-------------------------------------------------
3231# specify available CPU cores
3332#-------------------------------------------------
r11460r11461
240239#-------------------------------------------------
241240
242241DRVLIBS += \
242   $(MAMEOBJ)/acorn.a \
243243   $(MAMEOBJ)/alba.a \
244244   $(MAMEOBJ)/alliedl.a \
245245   $(MAMEOBJ)/alpha.a \
246246   $(MAMEOBJ)/amiga.a \
247247   $(MAMEOBJ)/aristocr.a \
248   $(MAMEOBJ)/ascii.a \
248249   $(MAMEOBJ)/atari.a \
249250   $(MAMEOBJ)/atlus.a \
250251   $(MAMEOBJ)/barcrest.a \
r11460r11461
284285   $(MAMEOBJ)/midcoin.a \
285286   $(MAMEOBJ)/midw8080.a \
286287   $(MAMEOBJ)/midway.a \
287   $(MAMEOBJ)/msx.a \
288288   $(MAMEOBJ)/namco.a \
289289   $(MAMEOBJ)/nasco.a \
290290   $(MAMEOBJ)/neogeo.a \
r11460r11461
309309   $(MAMEOBJ)/seta.a \
310310   $(MAMEOBJ)/sigma.a \
311311   $(MAMEOBJ)/snk.a \
312   $(MAMEOBJ)/sony.a \
312313   $(MAMEOBJ)/stern.a \
313314   $(MAMEOBJ)/subsino.a \
314315   $(MAMEOBJ)/sun.a \
r11460r11461
335336   $(MAMEOBJ)/misc.a \
336337   $(MAMEOBJ)/pinball.a \
337338   $(MAMEOBJ)/shared.a \
338   $(MAMEOBJ)/formats.a \
339339
340340
341341
r11460r11461
357357# manufacturer-specific groupings for drivers
358358#-------------------------------------------------
359359
360$(MAMEOBJ)/acorn.a: \
361   $(DRIVERS)/a310.o \
362   $(DRIVERS)/a7000.o \
363   $(DRIVERS)/ertictac.o \
364   $(DRIVERS)/ssfindo.o \
365   $(DRIVERS)/aristmk5.o \
366   $(MACHINE)/archimds.o \
367   $(VIDEO)/archimds.o \
368
360369$(MAMEOBJ)/alba.a: \
361370   $(DRIVERS)/albazc.o \
362371   $(DRIVERS)/albazg.o \
r11460r11461
374383   $(DRIVERS)/shougi.o \
375384
376385$(MAMEOBJ)/amiga.a: \
386   $(MACHINE)/amigafdc.o   \
387   $(MACHINE)/amigacrt.o   \
388   $(MACHINE)/amigacd.o   \
389   $(MACHINE)/amigakbd.o   \
390   $(DRIVERS)/amiga.o      \
391   $(DRIVERS)/a3000.o      \
392   $(DRIVERS)/ami1200.o   \
377393   $(DRIVERS)/alg.o \
378394   $(MACHINE)/amiga.o $(AUDIO)/amiga.o $(VIDEO)/amiga.o $(VIDEO)/amigaaga.o\
379395   $(DRIVERS)/arcadia.o \
r11460r11461
383399
384400$(MAMEOBJ)/aristocr.a: \
385401   $(DRIVERS)/aristmk4.o \
386   $(DRIVERS)/aristmk5.o \
387402   $(DRIVERS)/caswin.o \
388   $(MACHINE)/archimds.o \
389   $(VIDEO)/archimds.o \
390403
404
405$(MAMEOBJ)/ascii.a: \
406   $(DRIVERS)/msx.o \
407   $(MACHINE)/msx_slot.o \
408   $(MACHINE)/msx.o \
409   $(DRIVERS)/big10.o \
410   $(DRIVERS)/forte2.o \
411   $(DRIVERS)/pengadvb.o \
412   $(DRIVERS)/sangho.o \
413   $(DRIVERS)/sfkick.o \
414
391415$(MAMEOBJ)/atari.a: \
392416   $(DRIVERS)/arcadecl.o $(VIDEO)/arcadecl.o \
393417   $(DRIVERS)/asteroid.o $(MACHINE)/asteroid.o $(AUDIO)/asteroid.o $(AUDIO)/llander.o \
r11460r11461
531555   $(DRIVERS)/srumbler.o $(VIDEO)/srumbler.o \
532556   $(DRIVERS)/tigeroad.o $(VIDEO)/tigeroad.o \
533557   $(DRIVERS)/vulgus.o $(VIDEO)/vulgus.o \
534   $(DRIVERS)/zn.o $(MACHINE)/znsec.o \
535   $(DRIVERS)/taitogn.o \
536558   $(MACHINE)/cps2crpt.o \
537559   $(MACHINE)/kabuki.o \
538560
r11460r11461
661683   $(DRIVERS)/circus.o $(AUDIO)/circus.o $(VIDEO)/circus.o \
662684   $(DRIVERS)/exidy.o $(AUDIO)/exidy.o $(VIDEO)/exidy.o \
663685   $(DRIVERS)/exidy440.o $(AUDIO)/exidy440.o $(VIDEO)/exidy440.o \
664   $(DRIVERS)/maxaflex.o $(MACHINE)/atari.o $(VIDEO)/atari.o $(VIDEO)/antic.o $(VIDEO)/gtia.o \
686   $(DRIVERS)/atari400.o $(DRIVERS)/maxaflex.o $(MACHINE)/atari.o $(VIDEO)/atari.o $(VIDEO)/antic.o $(VIDEO)/gtia.o \
687   $(MACHINE)/atarifdc.o $(MACHINE)/ataricrt.o \
665688   $(DRIVERS)/starfire.o $(VIDEO)/starfire.o \
666689   $(DRIVERS)/vertigo.o $(MACHINE)/vertigo.o $(VIDEO)/vertigo.o \
667690   $(DRIVERS)/victory.o $(VIDEO)/victory.o \
r11460r11461
928951   $(DRIVERS)/sspeedr.o $(VIDEO)/sspeedr.o \
929952
930953$(MAMEOBJ)/midway.a: \
931   $(DRIVERS)/astrocde.o $(VIDEO)/astrocde.o \
954   $(DRIVERS)/astrocde.o $(DRIVERS)/astrocdh.o $(VIDEO)/astrocde.o \
932955   $(DRIVERS)/balsente.o $(MACHINE)/balsente.o $(VIDEO)/balsente.o \
933956   $(DRIVERS)/gridlee.o $(AUDIO)/gridlee.o $(VIDEO)/gridlee.o \
934957   $(DRIVERS)/mcr.o $(MACHINE)/mcr.o $(AUDIO)/mcr.o $(VIDEO)/mcr.o \
r11460r11461
951974   $(AUDIO)/gorf.o \
952975   $(AUDIO)/wow.o \
953976
954$(MAMEOBJ)/msx.a: \
955   $(DRIVERS)/big10.o \
956   $(DRIVERS)/forte2.o \
957   $(DRIVERS)/pengadvb.o \
958   $(DRIVERS)/sangho.o \
959   $(DRIVERS)/sfkick.o \
960
961977$(MAMEOBJ)/namco.a: \
962978   $(DRIVERS)/20pacgal.o $(VIDEO)/20pacgal.o \
963979   $(DRIVERS)/baraduke.o $(VIDEO)/baraduke.o \
r11460r11461
10161032   $(MACHINE)/neoboot.o \
10171033   $(MACHINE)/neocrypt.o \
10181034   $(MACHINE)/neoprot.o \
1035   $(DRIVERS)/ng_aes.o \
1036   $(MACHINE)/aescart.o \
10191037
10201038$(MAMEOBJ)/nichibut.a: \
10211039   $(DRIVERS)/armedf.o $(VIDEO)/armedf.o \
r11460r11461
10601078   $(DRIVERS)/spacefb.o $(AUDIO)/spacefb.o  $(VIDEO)/spacefb.o \
10611079   $(DRIVERS)/vsnes.o $(MACHINE)/vsnes.o $(VIDEO)/vsnes.o \
10621080   $(VIDEO)/ppu2c0x.o \
1081   $(MACHINE)/nes_mmc.o   \
1082   $(VIDEO)/nes.o      \
1083   $(MACHINE)/nes.o      \
1084   $(DRIVERS)/nes.o      \
1085   $(MACHINE)/snescart.o   \
1086   $(DRIVERS)/snes.o      \
1087   $(DRIVERS)/n64.o      \
10631088
1089
1090
10641091$(MAMEOBJ)/nix.a: \
10651092   $(DRIVERS)/fitfight.o $(VIDEO)/fitfight.o \
10661093   $(DRIVERS)/pirates.o $(VIDEO)/pirates.o \
r11460r11461
11081135   $(MACHINE)/theglobp.o \
11091136
11101137$(MAMEOBJ)/pce.a: \
1138   $(DRIVERS)/pce.o \
1139   $(MACHINE)/pce.o \
11111140   $(DRIVERS)/ggconnie.o \
11121141   $(DRIVERS)/paranoia.o \
11131142   $(DRIVERS)/uapce.o \
r11460r11461
12891318   $(DRIVERS)/snk.o $(VIDEO)/snk.o \
12901319   $(DRIVERS)/snk68.o $(VIDEO)/snk68.o \
12911320
1321$(MAMEOBJ)/sony.a: \
1322   $(DRIVERS)/zn.o $(MACHINE)/znsec.o \
1323   $(DRIVERS)/taitogn.o \
1324   $(DRIVERS)/psx.o \
1325   $(MACHINE)/psxcd.o \
1326   $(MACHINE)/psxcddrv.o   \
1327   $(MACHINE)/psxcard.o   \
1328
12921329$(MAMEOBJ)/stern.a: \
12931330   $(DRIVERS)/astinvad.o \
12941331   $(DRIVERS)/berzerk.o \
r11460r11461
16691706   $(DRIVERS)/dwarfd.o \
16701707   $(DRIVERS)/dynadice.o \
16711708   $(DRIVERS)/epos.o $(VIDEO)/epos.o \
1672   $(DRIVERS)/ertictac.o \
16731709   $(DRIVERS)/esd16.o $(VIDEO)/esd16.o \
16741710   $(DRIVERS)/esh.o \
16751711   $(DRIVERS)/esripsys.o $(VIDEO)/esripsys.o \
r11460r11461
17771813   $(DRIVERS)/sothello.o \
17781814   $(DRIVERS)/spool99.o \
17791815   $(DRIVERS)/sprcros2.o $(VIDEO)/sprcros2.o \
1780   $(DRIVERS)/ssfindo.o \
17811816   $(DRIVERS)/ssingles.o \
17821817   $(DRIVERS)/sstrangr.o \
17831818   $(DRIVERS)/statriv2.o \
r11460r11461
19511986
19521987$(DRIVERS)/neogeo.o:   $(LAYOUT)/neogeo.lh
19531988
1989$(DRIVERS)/ng_aes.o:   $(LAYOUT)/neogeo.lh
1990
19541991$(DRIVERS)/norautp.o:   $(LAYOUT)/noraut11.lh \
19551992         $(LAYOUT)/noraut12.lh
19561993
r11460r11461
20722109         $(MAMESRC)/machine/snessdd1.c \
20732110         $(MAMESRC)/machine/snes7110.c \
20742111         $(MAMESRC)/machine/snesbsx.c
2112$(MACHINE)/nes_mmc.o:   $(MAMESRC)/machine/nes_ines.c \
2113         $(MAMESRC)/machine/nes_pcb.c \
2114         $(MAMESRC)/machine/nes_unif.c
20752115$(VIDEO)/jaguar.o:   $(MAMESRC)/video/jagobj.c \
20762116         $(MAMESRC)/video/jagblit.c
20772117$(VIDEO)/model2.o:   $(MAMESRC)/video/model2rd.c
src/mame/video/nes.c
r0r11461
1/***************************************************************************
2
3  video/nes.c
4
5  Routines to control the unique NES video hardware/PPU.
6
7***************************************************************************/
8
9#include "emu.h"
10#include "video/ppu2c0x.h"
11#include "includes/nes.h"
12#include "machine/nes_mmc.h"
13
14static void nes_vh_reset( running_machine &machine )
15{
16   nes_state *state = machine.driver_data<nes_state>();
17   ppu2c0x_set_vidaccess_callback(machine.device("ppu"), nes_ppu_vidaccess);
18
19   if (state->m_four_screen_vram)
20      set_nt_mirroring(machine, PPU_MIRROR_4SCREEN);
21   else
22   {
23      switch (state->m_hard_mirroring)
24      {
25         case PPU_MIRROR_HORZ:
26         case PPU_MIRROR_VERT:
27         case PPU_MIRROR_HIGH:
28         case PPU_MIRROR_LOW:
29            set_nt_mirroring(machine, state->m_hard_mirroring);
30            break;
31         default:
32            set_nt_mirroring(machine, PPU_MIRROR_NONE);
33            break;
34      }
35   }
36}
37
38VIDEO_START( nes )
39{
40   nes_state *state = machine.driver_data<nes_state>();
41
42   state->m_last_frame_flip =  0;
43
44   machine.add_notifier(MACHINE_NOTIFY_RESET, machine_notify_delegate(FUNC(nes_vh_reset),&machine));
45}
46
47PALETTE_INIT( nes )
48{
49   ppu2c0x_init_palette(machine, 0);
50}
51
52
53/***************************************************************************
54
55  Display refresh
56
57***************************************************************************/
58
59SCREEN_UPDATE( nes )
60{
61   nes_state *state = screen->machine().driver_data<nes_state>();
62
63   /* render the ppu */
64   ppu2c0x_render(state->m_ppu, bitmap, 0, 0, 0, 0);
65
66   /* if this is a disk system game, check for the flip-disk key */
67   if (state->m_disk_expansion && state->m_pcb_id == NO_BOARD)
68   {
69      // latch this input so it doesn't go at warp speed
70      if ((input_port_read(screen->machine(), "FLIPDISK") & 0x01) && (!state->m_last_frame_flip))
71      {
72         state->m_last_frame_flip = 1;
73         state->m_fds_current_side++;
74         if (state->m_fds_current_side > state->m_fds_sides)
75            state->m_fds_current_side = 0;
76
77         if (state->m_fds_current_side == 0)
78            popmessage("No disk inserted.");
79         else
80            popmessage("Disk set to side %d", state->m_fds_current_side);
81      }
82
83      if (!(input_port_read(screen->machine(), "FLIPDISK") & 0x01))
84         state->m_last_frame_flip = 0;
85   }
86   return 0;
87}
src/mame/drivers/ng_aes.c
r0r11461
1/***************************************************************************
2
3    Neo-Geo AES hardware
4
5    Credits (from MAME neogeo.c, since this is just a minor edit of that driver):
6        * This driver was made possible by the research done by
7          Charles MacDonald.  For a detailed description of the Neo-Geo
8          hardware, please visit his page at:
9          http://cgfm2.emuviews.com/temp/mvstech.txt
10        * Presented to you by the Shin Emu Keikaku team.
11        * The following people have all spent probably far
12          too much time on this:
13          AVDB
14          Bryan McPhail
15          Fuzz
16          Ernesto Corvi
17          Andrew Prime
18          Zsolt Vasvari
19
20    MESS cartridge support by R. Belmont based on work by Michael Zapf
21
22    Current status:
23        - Cartridges run.
24
25    ToDo :
26        - Change input code to allow selection of the mahjong panel in PORT_CATEGORY.
27        - Clean up code, to reduce duplication of MAME source
28
29****************************************************************************/
30
31#include "emu.h"
32#include "cpu/m68000/m68000.h"
33#include "includes/neogeo.h"
34#include "machine/pd4990a.h"
35#include "cpu/z80/z80.h"
36#include "sound/2610intf.h"
37#include "machine/aescart.h"
38#include "imagedev/cartslot.h"
39#ifdef MESS
40#include "neogeo.lh"
41#else
42extern const char layout_neogeo[];
43#endif
44
45
46// CD-ROM / DMA control registers
47typedef struct
48{
49   UINT8 area_sel;
50   UINT8 pcm_bank_sel;
51   UINT8 spr_bank_sel;
52   UINT32 addr_source; // target if in fill mode
53   UINT32 addr_target;
54   UINT16 fill_word;
55   UINT32 word_count;
56   UINT16 dma_mode[10];
57} neocd_ctrl_t;
58
59class ng_aes_state : public neogeo_state
60{
61public:
62   ng_aes_state(const machine_config &mconfig, device_type type, const char *tag)
63      : neogeo_state(mconfig, type, tag) { }
64
65   UINT8 *m_memcard_data;
66   neocd_ctrl_t m_neocd_ctrl;
67};
68
69
70
71#define LOG_VIDEO_SYSTEM      (0)
72#define LOG_CPU_COMM         (0)
73#define LOG_MAIN_CPU_BANKING   (1)
74#define LOG_AUDIO_CPU_BANKING   (1)
75
76#define NEOCD_AREA_SPR    0
77#define NEOCD_AREA_PCM    1
78#define NEOCD_AREA_AUDIO  4
79#define NEOCD_AREA_FIX    5
80
81/*************************************
82 *
83 *  Global variables
84 *
85 *************************************/
86
87//static UINT16 *save_ram;
88
89UINT16* neocd_work_ram;
90
91/*************************************
92 *
93 *  Forward declarations
94 *
95 *************************************/
96
97//static void set_output_latch(running_machine &machine, UINT8 data);
98//static void set_output_data(running_machine &machine, UINT8 data);
99
100
101/*************************************
102 *
103 *  Main CPU interrupt generation
104 *
105 *************************************/
106
107#define IRQ2CTRL_ENABLE            (0x10)
108#define IRQ2CTRL_LOAD_RELATIVE      (0x20)
109#define IRQ2CTRL_AUTOLOAD_VBLANK   (0x40)
110#define IRQ2CTRL_AUTOLOAD_REPEAT   (0x80)
111
112
113static void adjust_display_position_interrupt_timer( running_machine &machine )
114{
115   neogeo_state *state = machine.driver_data<neogeo_state>();
116
117   if ((state->m_display_counter + 1) != 0)
118   {
119      attotime period = (attotime::from_hz(NEOGEO_PIXEL_CLOCK) * (state->m_display_counter + 1));
120      if (LOG_VIDEO_SYSTEM) logerror("adjust_display_position_interrupt_timer  current y: %02x  current x: %02x   target y: %x  target x: %x\n", machine.primary_screen->vpos(), machine.primary_screen->hpos(), (state->m_display_counter + 1) / NEOGEO_HTOTAL, (state->m_display_counter + 1) % NEOGEO_HTOTAL);
121
122      state->m_display_position_interrupt_timer->adjust(period);
123   }
124}
125
126#ifdef MESS
127void neogeo_set_display_position_interrupt_control( running_machine &machine, UINT16 data )
128{
129   neogeo_state *state = machine.driver_data<neogeo_state>();
130   state->m_display_position_interrupt_control = data;
131}
132
133
134void neogeo_set_display_counter_msb( address_space *space, UINT16 data )
135{
136   neogeo_state *state = space->machine().driver_data<neogeo_state>();
137
138   state->m_display_counter = (state->m_display_counter & 0x0000ffff) | ((UINT32)data << 16);
139
140   if (LOG_VIDEO_SYSTEM) logerror("PC %06x: set_display_counter %08x\n", cpu_get_pc(&space->device()), state->m_display_counter);
141}
142
143
144void neogeo_set_display_counter_lsb( address_space *space, UINT16 data )
145{
146   neogeo_state *state = space->machine().driver_data<neogeo_state>();
147
148   state->m_display_counter = (state->m_display_counter & 0xffff0000) | data;
149
150   if (LOG_VIDEO_SYSTEM) logerror("PC %06x: set_display_counter %08x\n", cpu_get_pc(&space->device()), state->m_display_counter);
151
152   if (state->m_display_position_interrupt_control & IRQ2CTRL_LOAD_RELATIVE)
153   {
154      if (LOG_VIDEO_SYSTEM) logerror("AUTOLOAD_RELATIVE ");
155      adjust_display_position_interrupt_timer(space->machine());
156   }
157}
158#endif
159
160static void update_interrupts( running_machine &machine )
161{
162   neogeo_state *state = machine.driver_data<neogeo_state>();
163
164   if(strcmp((char*)machine.system().name,"aes") != 0)
165   {  // raster and vblank IRQs are swapped on the NeoCD.
166      cputag_set_input_line(machine, "maincpu", 2, state->m_vblank_interrupt_pending ? ASSERT_LINE : CLEAR_LINE);
167      cputag_set_input_line(machine, "maincpu", 1, state->m_display_position_interrupt_pending ? ASSERT_LINE : CLEAR_LINE);
168      cputag_set_input_line(machine, "maincpu", 3, state->m_irq3_pending ? ASSERT_LINE : CLEAR_LINE);
169   }
170   else
171   {
172      cputag_set_input_line(machine, "maincpu", 1, state->m_vblank_interrupt_pending ? ASSERT_LINE : CLEAR_LINE);
173      cputag_set_input_line(machine, "maincpu", 2, state->m_display_position_interrupt_pending ? ASSERT_LINE : CLEAR_LINE);
174      cputag_set_input_line(machine, "maincpu", 3, state->m_irq3_pending ? ASSERT_LINE : CLEAR_LINE);
175   }
176}
177
178#ifdef MESS
179void neogeo_acknowledge_interrupt( running_machine &machine, UINT16 data )
180{
181   neogeo_state *state = machine.driver_data<neogeo_state>();
182
183   if (data & 0x01)
184      state->m_irq3_pending = 0;
185   if (data & 0x02)
186      state->m_display_position_interrupt_pending = 0;
187   if (data & 0x04)
188      state->m_vblank_interrupt_pending = 0;
189
190   update_interrupts(machine);
191}
192#endif
193
194static TIMER_CALLBACK( display_position_interrupt_callback )
195{
196   neogeo_state *state = machine.driver_data<neogeo_state>();
197
198   if (LOG_VIDEO_SYSTEM) logerror("--- Scanline @ %d,%d\n", machine.primary_screen->vpos(), machine.primary_screen->hpos());
199
200   if (state->m_display_position_interrupt_control & IRQ2CTRL_ENABLE)
201   {
202      if (LOG_VIDEO_SYSTEM) logerror("*** Scanline interrupt (IRQ2) ***  y: %02x  x: %02x\n", machine.primary_screen->vpos(), machine.primary_screen->hpos());
203      state->m_display_position_interrupt_pending = 1;
204
205      update_interrupts(machine);
206   }
207
208   if (state->m_display_position_interrupt_control & IRQ2CTRL_AUTOLOAD_REPEAT)
209   {
210      if (LOG_VIDEO_SYSTEM) logerror("AUTOLOAD_REPEAT ");
211      adjust_display_position_interrupt_timer(machine);
212   }
213}
214
215
216static TIMER_CALLBACK( display_position_vblank_callback )
217{
218   neogeo_state *state = machine.driver_data<neogeo_state>();
219
220   if (state->m_display_position_interrupt_control & IRQ2CTRL_AUTOLOAD_VBLANK)
221   {
222      if (LOG_VIDEO_SYSTEM) logerror("AUTOLOAD_VBLANK ");
223      adjust_display_position_interrupt_timer(machine);
224   }
225
226   /* set timer for next screen */
227   state->m_display_position_vblank_timer->adjust(machine.primary_screen->time_until_pos(NEOGEO_VBSTART, NEOGEO_VBLANK_RELOAD_HPOS));
228}
229
230
231static TIMER_CALLBACK( vblank_interrupt_callback )
232{
233   neogeo_state *state = machine.driver_data<neogeo_state>();
234
235   if (LOG_VIDEO_SYSTEM) logerror("+++ VBLANK @ %d,%d\n", machine.primary_screen->vpos(), machine.primary_screen->hpos());
236
237   /* add a timer tick to the pd4990a */
238   upd4990a_addretrace(state->m_upd4990a);
239
240   state->m_vblank_interrupt_pending = 1;
241
242   update_interrupts(machine);
243
244   /* set timer for next screen */
245   state->m_vblank_interrupt_timer->adjust(machine.primary_screen->time_until_pos(NEOGEO_VBSTART, 0));
246}
247
248
249static void create_interrupt_timers( running_machine &machine )
250{
251   neogeo_state *state = machine.driver_data<neogeo_state>();
252   state->m_display_position_interrupt_timer = machine.scheduler().timer_alloc(FUNC(display_position_interrupt_callback));
253   state->m_display_position_vblank_timer = machine.scheduler().timer_alloc(FUNC(display_position_vblank_callback));
254   state->m_vblank_interrupt_timer = machine.scheduler().timer_alloc(FUNC(vblank_interrupt_callback));
255}
256
257
258static void start_interrupt_timers( running_machine &machine )
259{
260   neogeo_state *state = machine.driver_data<neogeo_state>();
261   state->m_vblank_interrupt_timer->adjust(machine.primary_screen->time_until_pos(NEOGEO_VBSTART, 0));
262   state->m_display_position_vblank_timer->adjust(machine.primary_screen->time_until_pos(NEOGEO_VBSTART, NEOGEO_VBLANK_RELOAD_HPOS));
263}
264
265
266
267/*************************************
268 *
269 *  Audio CPU interrupt generation
270 *
271 *************************************/
272
273static void audio_cpu_irq(device_t *device, int assert)
274{
275   neogeo_state *state = device->machine().driver_data<neogeo_state>();
276   device_set_input_line(state->m_audiocpu, 0, assert ? ASSERT_LINE : CLEAR_LINE);
277}
278
279
280static void audio_cpu_assert_nmi(running_machine &machine)
281{
282   neogeo_state *state = machine.driver_data<neogeo_state>();
283   device_set_input_line(state->m_audiocpu, INPUT_LINE_NMI, ASSERT_LINE);
284}
285
286
287static WRITE8_HANDLER( audio_cpu_clear_nmi_w )
288{
289   neogeo_state *state = space->machine().driver_data<neogeo_state>();
290   device_set_input_line(state->m_audiocpu, INPUT_LINE_NMI, CLEAR_LINE);
291}
292
293
294
295/*************************************
296 *
297 *  Input ports / Controllers
298 *
299 *************************************/
300
301static void select_controller( running_machine &machine, UINT8 data )
302{
303   neogeo_state *state = machine.driver_data<neogeo_state>();
304   state->m_controller_select = data;
305}
306
307
308#if 0
309static CUSTOM_INPUT( multiplexed_controller_r )
310{
311   int port = (FPTR)param;
312
313   static const char *const cntrl[2][2] =
314      {
315         { "IN0-0", "IN0-1" }, { "IN1-0", "IN1-1" }
316      };
317
318   return input_port_read_safe(field->port->machine(), cntrl[port][controller_select & 0x01], 0x00);
319}
320
321
322static CUSTOM_INPUT( mahjong_controller_r )
323{
324   UINT32 ret;
325
326/*
327cpu #0 (PC=00C18B9A): unmapped memory word write to 00380000 = 0012 & 00FF
328cpu #0 (PC=00C18BB6): unmapped memory word write to 00380000 = 001B & 00FF
329cpu #0 (PC=00C18D54): unmapped memory word write to 00380000 = 0024 & 00FF
330cpu #0 (PC=00C18D6C): unmapped memory word write to 00380000 = 0009 & 00FF
331cpu #0 (PC=00C18C40): unmapped memory word write to 00380000 = 0000 & 00FF
332*/
333   switch (controller_select)
334   {
335   default:
336   case 0x00: ret = 0x0000; break; /* nothing? */
337   case 0x09: ret = input_port_read(field->port->machine(), "MAHJONG1"); break;
338   case 0x12: ret = input_port_read(field->port->machine(), "MAHJONG2"); break;
339   case 0x1b: ret = input_port_read(field->port->machine(), "MAHJONG3"); break; /* player 1 normal inputs? */
340   case 0x24: ret = input_port_read(field->port->machine(), "MAHJONG4"); break;
341   }
342
343   return ret;
344}
345
346#endif
347
348static WRITE16_HANDLER( io_control_w )
349{
350   neogeo_state *state = space->machine().driver_data<neogeo_state>();
351   switch (offset)
352   {
353   case 0x00: select_controller(space->machine(), data & 0x00ff); break;
354//  case 0x18: set_output_latch(space->machine(), data & 0x00ff); break;
355//  case 0x20: set_output_data(space->machine(), data & 0x00ff); break;
356   case 0x28: upd4990a_control_16_w(state->m_upd4990a, 0, data, mem_mask); break;
357//  case 0x30: break; // coin counters
358//  case 0x31: break; // coin counters
359//  case 0x32: break; // coin lockout
360//  case 0x33: break; // coui lockout
361
362   default:
363      logerror("PC: %x  Unmapped I/O control write.  Offset: %x  Data: %x\n", cpu_get_pc(&space->device()), offset, data);
364      break;
365   }
366}
367
368
369
370/*************************************
371 *
372 *  Unmapped memory access
373 *
374 *************************************/
375#ifdef MESS
376READ16_HANDLER( neogeo_unmapped_r )
377{
378   neogeo_state *state = space->machine().driver_data<neogeo_state>();
379   UINT16 ret;
380
381   /* unmapped memory returns the last word on the data bus, which is almost always the opcode
382       of the next instruction due to prefetch */
383
384   /* prevent recursion */
385   if (state->m_recurse)
386      ret = 0xffff;
387   else
388   {
389      state->m_recurse = 1;
390      ret = space->read_word(cpu_get_pc(&space->device()));
391      state->m_recurse = 0;
392   }
393
394   return ret;
395}
396#endif
397
398
399
400/*************************************
401 *
402 *  uPD4990A calendar chip
403 *
404 *************************************/
405#if 0
406static void calendar_init(running_machine &machine)
407{
408   /* set the celander IC to 'right now' */
409   system_time systime;
410   system_tm time;
411
412   machine.base_datetime(&systime);
413   time = systime.local_time;
414
415   pd4990a.seconds = ((time.second / 10) << 4) + (time.second % 10);
416   pd4990a.minutes = ((time.minute / 10) << 4) + (time.minute % 10);
417   pd4990a.hours = ((time.hour / 10) <<4 ) + (time.hour % 10);
418   pd4990a.days = ((time.mday / 10) << 4) + (time.mday % 10);
419   pd4990a.month = time.month + 1;
420   pd4990a.year = ((((time.year - 1900) % 100) / 10) << 4) + ((time.year - 1900) % 10);
421   pd4990a.weekday = time.weekday;
422}
423
424
425static void calendar_clock(void)
426{
427//  pd4990a_addretrace();
428}
429#endif
430
431static CUSTOM_INPUT( get_calendar_status )
432{
433   neogeo_state *state = field->port->machine().driver_data<neogeo_state>();
434   return (upd4990a_databit_r(state->m_upd4990a, 0) << 1) | upd4990a_testbit_r(state->m_upd4990a, 0);
435}
436
437
438
439/*************************************
440 *
441 *  NVRAM (Save RAM)
442 *
443 *************************************/
444#if 0
445static NVRAM_HANDLER( neogeo )
446{
447   if (read_or_write)
448      /* save the SRAM settings */
449      mame_fwrite(file, save_ram, 0x2000);
450   else
451   {
452      /* load the SRAM settings */
453      if (file)
454         mame_fread(file, save_ram, 0x2000);
455      else
456         memset(save_ram, 0, 0x10000);
457   }
458}
459
460
461static void set_save_ram_unlock( running_machine &machine, UINT8 data )
462{
463   neogeo_state *state = machine.driver_data<neogeo_state>();
464   state->m_save_ram_unlocked = data;
465}
466
467
468static WRITE16_HANDLER( save_ram_w )
469{
470   neogeo_state *state = space->machine().driver_data<neogeo_state>();
471
472   if (state->m_save_ram_unlocked)
473      COMBINE_DATA(&save_ram[offset]);
474}
475#endif
476
477
478/*************************************
479 *
480 *  Memory card
481 *
482 *************************************/
483
484#define MEMCARD_SIZE   0x0800
485
486static CUSTOM_INPUT( get_memcard_status )
487{
488   /* D0 and D1 are memcard presence indicators, D2 indicates memcard
489       write protect status (we are always write enabled) */
490   if(strcmp((char*)field->port->machine().system().name,"aes") != 0)
491      return 0x00;  // On the Neo Geo CD, the memory card is internal and therefore always present.
492   else
493      return (memcard_present(field->port->machine()) == -1) ? 0x07 : 0x00;
494}
495
496static READ16_HANDLER( memcard_r )
497{
498   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
499   UINT16 ret;
500
501   if (memcard_present(space->machine()) != -1)
502      ret = state->m_memcard_data[offset] | 0xff00;
503   else
504      ret = 0xffff;
505
506   return ret;
507}
508
509
510static WRITE16_HANDLER( memcard_w )
511{
512   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
513   if (ACCESSING_BITS_0_7)
514   {
515      if (memcard_present(space->machine()) != -1)
516         state->m_memcard_data[offset] = data;
517   }
518}
519
520/* The NeoCD has an 8kB internal memory card, instead of memcard slots like the MVS and AES */
521static READ16_HANDLER( neocd_memcard_r )
522{
523   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
524   return state->m_memcard_data[offset] | 0xff00;
525}
526
527
528static WRITE16_HANDLER( neocd_memcard_w )
529{
530   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
531   if (ACCESSING_BITS_0_7)
532   {
533      state->m_memcard_data[offset] = data;
534   }
535}
536
537static MEMCARD_HANDLER( neogeo )
538{
539   ng_aes_state *state = machine.driver_data<ng_aes_state>();
540   switch (action)
541   {
542   case MEMCARD_CREATE:
543      memset(state->m_memcard_data, 0, MEMCARD_SIZE);
544      file.write(state->m_memcard_data, MEMCARD_SIZE);
545      break;
546
547   case MEMCARD_INSERT:
548      file.read(state->m_memcard_data, MEMCARD_SIZE);
549      break;
550
551   case MEMCARD_EJECT:
552      file.write(state->m_memcard_data, MEMCARD_SIZE);
553      break;
554   }
555}
556
557
558
559/*************************************
560 *
561 *  Inter-CPU communications
562 *
563 *************************************/
564
565static WRITE16_HANDLER( audio_command_w )
566{
567   /* accessing the LSB only is not mapped */
568   if (mem_mask != 0x00ff)
569   {
570      soundlatch_w(space, 0, data >> 8);
571
572      audio_cpu_assert_nmi(space->machine());
573
574      /* boost the interleave to let the audio CPU read the command */
575      space->machine().scheduler().boost_interleave(attotime::zero, attotime::from_usec(50));
576
577      if (LOG_CPU_COMM) logerror("MAIN CPU PC %06x: audio_command_w %04x - %04x\n", cpu_get_pc(&space->device()), data, mem_mask);
578   }
579}
580
581
582static READ8_HANDLER( audio_command_r )
583{
584   UINT8 ret = soundlatch_r(space, 0);
585
586   if (LOG_CPU_COMM) logerror(" AUD CPU PC   %04x: audio_command_r %02x\n", cpu_get_pc(&space->device()), ret);
587
588   /* this is a guess */
589   audio_cpu_clear_nmi_w(space, 0, 0);
590
591   return ret;
592}
593
594
595static WRITE8_HANDLER( audio_result_w )
596{
597   neogeo_state *state = space->machine().driver_data<neogeo_state>();
598
599   if (LOG_CPU_COMM && (state->m_audio_result != data)) logerror(" AUD CPU PC   %04x: audio_result_w %02x\n", cpu_get_pc(&space->device()), data);
600
601   state->m_audio_result = data;
602}
603
604
605static CUSTOM_INPUT( get_audio_result )
606{
607   neogeo_state *state = field->port->machine().driver_data<neogeo_state>();
608   UINT32 ret = state->m_audio_result;
609
610//  if (LOG_CPU_COMM) logerror("MAIN CPU PC %06x: audio_result_r %02x\n", cpu_get_pc(field->port->machine().device("maincpu")), ret);
611
612   return ret;
613}
614
615
616
617/*************************************
618 *
619 *  Main CPU banking
620 *
621 *************************************/
622
623static void _set_main_cpu_vector_table_source( running_machine &machine )
624{
625   neogeo_state *state = machine.driver_data<neogeo_state>();
626   memory_set_bank(machine, NEOGEO_BANK_VECTORS, state->m_main_cpu_vector_table_source);
627}
628
629
630static void set_main_cpu_vector_table_source( running_machine &machine, UINT8 data )
631{
632   neogeo_state *state = machine.driver_data<neogeo_state>();
633   state->m_main_cpu_vector_table_source = data;
634
635   _set_main_cpu_vector_table_source(machine);
636}
637
638
639static void _set_main_cpu_bank_address( running_machine &machine )
640{
641   neogeo_state *state = machine.driver_data<neogeo_state>();
642   memory_set_bankptr(machine, NEOGEO_BANK_CARTRIDGE, &machine.region("maincpu")->base()[state->m_main_cpu_bank_address]);
643}
644
645#ifdef MESS
646void neogeo_set_main_cpu_bank_address( address_space *space, UINT32 bank_address )
647{
648   neogeo_state *state = space->machine().driver_data<neogeo_state>();
649
650   if (LOG_MAIN_CPU_BANKING) logerror("MAIN CPU PC %06x: neogeo_set_main_cpu_bank_address %06x\n", cpu_get_pc(&space->device()), bank_address);
651
652   state->m_main_cpu_bank_address = bank_address;
653
654   _set_main_cpu_bank_address(space->machine());
655}
656#endif
657
658static WRITE16_HANDLER( main_cpu_bank_select_w )
659{
660   UINT32 bank_address;
661   UINT32 len = space->machine().region("maincpu")->bytes();
662
663   if ((len <= 0x100000) && (data & 0x07))
664      logerror("PC %06x: warning: bankswitch to %02x but no banks available\n", cpu_get_pc(&space->device()), data);
665   else
666   {
667      bank_address = ((data & 0x07) + 1) * 0x100000;
668
669      if (bank_address >= len)
670      {
671         logerror("PC %06x: warning: bankswitch to empty bank %02x\n", cpu_get_pc(&space->device()), data);
672         bank_address = 0x100000;
673      }
674
675      neogeo_set_main_cpu_bank_address(space, bank_address);
676   }
677}
678
679
680static void main_cpu_banking_init( running_machine &machine )
681{
682   address_space *mainspace = machine.device("maincpu")->memory().space(AS_PROGRAM);
683
684   /* create vector banks */
685   memory_configure_bank(machine, NEOGEO_BANK_VECTORS, 0, 1, machine.region("mainbios")->base(), 0);
686   memory_configure_bank(machine, NEOGEO_BANK_VECTORS, 1, 1, machine.region("maincpu")->base(), 0);
687
688   /* set initial main CPU bank */
689   if (machine.region("maincpu")->bytes() > 0x100000)
690      neogeo_set_main_cpu_bank_address(mainspace, 0x100000);
691   else
692      neogeo_set_main_cpu_bank_address(mainspace, 0x000000);
693}
694
695
696
697/*************************************
698 *
699 *  Audio CPU banking
700 *
701 *************************************/
702
703static void set_audio_cpu_banking( running_machine &machine )
704{
705   neogeo_state *state = machine.driver_data<neogeo_state>();
706   int region;
707
708   for (region = 0; region < 4; region++)
709      memory_set_bank(machine, NEOGEO_BANK_AUDIO_CPU_CART_BANK + region, state->m_audio_cpu_banks[region]);
710}
711
712
713static void audio_cpu_bank_select( address_space *space, int region, UINT8 bank )
714{
715   neogeo_state *state = space->machine().driver_data<neogeo_state>();
716
717   if (LOG_AUDIO_CPU_BANKING) logerror("Audio CPU PC %03x: audio_cpu_bank_select: Region: %d   Bank: %02x\n", cpu_get_pc(&space->device()), region, bank);
718
719   state->m_audio_cpu_banks[region] = bank;
720
721   set_audio_cpu_banking(space->machine());
722}
723
724
725static READ8_HANDLER( audio_cpu_bank_select_f000_f7ff_r )
726{
727   audio_cpu_bank_select(space, 0, offset >> 8);
728
729   return 0;
730}
731
732
733static READ8_HANDLER( audio_cpu_bank_select_e000_efff_r )
734{
735   audio_cpu_bank_select(space, 1, offset >> 8);
736
737   return 0;
738}
739
740
741static READ8_HANDLER( audio_cpu_bank_select_c000_dfff_r )
742{
743   audio_cpu_bank_select(space, 2, offset >> 8);
744
745   return 0;
746}
747
748
749static READ8_HANDLER( audio_cpu_bank_select_8000_bfff_r )
750{
751   audio_cpu_bank_select(space, 3, offset >> 8);
752
753   return 0;
754}
755
756
757static void _set_audio_cpu_rom_source( address_space *space )
758{
759   neogeo_state *state = space->machine().driver_data<neogeo_state>();
760
761/*  if (!machine.region("audiobios")->base())   */
762      state->m_audio_cpu_rom_source = 1;
763
764   memory_set_bank(space->machine(), NEOGEO_BANK_AUDIO_CPU_MAIN_BANK, state->m_audio_cpu_rom_source);
765
766   /* reset CPU if the source changed -- this is a guess */
767   if (state->m_audio_cpu_rom_source != state->m_audio_cpu_rom_source_last)
768   {
769      state->m_audio_cpu_rom_source_last = state->m_audio_cpu_rom_source;
770
771      cputag_set_input_line(space->machine(), "audiocpu", INPUT_LINE_RESET, PULSE_LINE);
772
773      if (LOG_AUDIO_CPU_BANKING) logerror("Audio CPU PC %03x: selectign %s ROM\n", cpu_get_pc(&space->device()), state->m_audio_cpu_rom_source ? "CARTRIDGE" : "BIOS");
774   }
775}
776
777
778static void set_audio_cpu_rom_source( address_space *space, UINT8 data )
779{
780   neogeo_state *state = space->machine().driver_data<neogeo_state>();
781   state->m_audio_cpu_rom_source = data;
782
783   _set_audio_cpu_rom_source(space);
784}
785
786
787static void audio_cpu_banking_init( running_machine &machine )
788{
789   neogeo_state *state = machine.driver_data<neogeo_state>();
790   int region;
791   int bank;
792   UINT8 *rgn;
793   UINT32 address_mask;
794
795   /* audio bios/cartridge selection */
796   if (machine.region("audiobios")->base())
797      memory_configure_bank(machine, NEOGEO_BANK_AUDIO_CPU_MAIN_BANK, 0, 1, machine.region("audiobios")->base(), 0);
798   memory_configure_bank(machine, NEOGEO_BANK_AUDIO_CPU_MAIN_BANK, 1, 1, machine.region("audiocpu")->base(), 0);
799
800   /* audio banking */
801   address_mask = machine.region("audiocpu")->bytes() - 0x10000 - 1;
802
803   rgn = machine.region("audiocpu")->base();
804   for (region = 0; region < 4; region++)
805   {
806      for (bank = 0; bank < 0x100; bank++)
807      {
808         UINT32 bank_address = 0x10000 + (((bank << (11 + region)) & 0x3ffff) & address_mask);
809         memory_configure_bank(machine, NEOGEO_BANK_AUDIO_CPU_CART_BANK + region, bank, 1, &rgn[bank_address], 0);
810      }
811   }
812
813   /* set initial audio banks --
814       how does this really work, or is it even neccessary? */
815   state->m_audio_cpu_banks[0] = 0x1e;
816   state->m_audio_cpu_banks[1] = 0x0e;
817   state->m_audio_cpu_banks[2] = 0x06;
818   state->m_audio_cpu_banks[3] = 0x02;
819
820   set_audio_cpu_banking(machine);
821
822   state->m_audio_cpu_rom_source_last = 0;
823   set_audio_cpu_rom_source(machine.device("maincpu")->memory().space(AS_PROGRAM), 0);
824}
825
826
827
828/*************************************
829 *
830 *  System control register
831 *
832 *************************************/
833
834static WRITE16_HANDLER( system_control_w )
835{
836   if (ACCESSING_BITS_0_7)
837   {
838      UINT8 bit = (offset >> 3) & 0x01;
839
840      switch (offset & 0x07)
841      {
842      default:
843      case 0x00: neogeo_set_screen_dark(space->machine(), bit); break;
844      case 0x01: set_main_cpu_vector_table_source(space->machine(), bit);
845               set_audio_cpu_rom_source(space, bit); /* this is a guess */
846               break;
847      case 0x05: neogeo_set_fixed_layer_source(space->machine(), bit); break;
848//      case 0x06: set_save_ram_unlock(space->machine(), bit); break;
849      case 0x07: neogeo_set_palette_bank(space->machine(), bit); break;
850
851      case 0x02: /* unknown - HC32 middle pin 1 */
852      case 0x03: /* unknown - uPD4990 pin ? */
853      case 0x04: /* unknown - HC32 middle pin 10 */
854         logerror("PC: %x  Unmapped system control write.  Offset: %x  Data: %x\n", cpu_get_pc(&space->device()), offset & 0x07, bit);
855         break;
856      }
857
858      if (LOG_VIDEO_SYSTEM && ((offset & 0x07) != 0x06)) logerror("PC: %x  System control write.  Offset: %x  Data: %x\n", cpu_get_pc(&space->device()), offset & 0x07, bit);
859   }
860}
861
862/*
863 *  CD-ROM / DMA control
864 *
865 *  DMA
866
867    FF0061  Write 0x40 means start DMA transfer
868    FF0064  Source address (in copy mode), Target address (in filll mode)
869    FF0068  Target address (in copy mode)
870    FF006C  Fill word
871    FF0070  Words count
872    FF007E  \
873    ......   | DMA programming words?   NeoGeoCD uses Sanyo Puppet LC8359 chip to
874    FF008E  /                           interface with CD, and do DMA transfers
875
876    Memory access control
877
878    FF011C  DIP SWITCH (Region code)
879    FF0105  Area Selector (5 = FIX, 0 = SPR, 4 = Z80, 1 = PCM)
880    FF01A1  Sprite bank selector
881    FF01A3  PCM bank selector
882    FF0120  Prepare sprite area for transfer
883    FF0122  Prepare PCM area for transfer
884    FF0126  Prepare Z80 area for transfer
885    FF0128  Prepare Fix area for transfer
886    FF0140  Terminate work on Spr Area  (Sprites must be decoded here)
887    FF0142  Terminate work on Pcm Area
888    FF0146  Terminate work on Z80 Area  (Z80 needs to be reset)
889    FF0148  Terminate work on Fix Area
890
891    CD-ROM:
892    0xff0102 == 0xF0 start cd transfer
893    int m=bcd(fast_r8(0x10f6c8));
894    int s=bcd(fast_r8(0x10f6c9));
895    int f=bcd(fast_r8(0x10f6ca));
896    int seccount=fast_r16(0x10f688);
897
898    inisec=((m*60)+s)*75+f;
899    inisec-=150;
900    dstaddr=0x111204; // this must come from somewhere
901
902    the value @ 0x10f688 is decremented each time a sector is read until it's 0.
903
904 *
905 */
906
907static void neocd_do_dma(address_space* space)
908{
909   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
910   // TODO: Proper DMA timing and control
911   int count;
912//  UINT16 word;
913
914   switch(state->m_neocd_ctrl.dma_mode[0])
915   {
916   case 0xffdd:
917      for(count=0;count<state->m_neocd_ctrl.word_count;count++)
918      {
919         //word = space->read_word(state->m_neocd_ctrl.addr_source);
920         space->write_word(state->m_neocd_ctrl.addr_source+(count*2),state->m_neocd_ctrl.fill_word);
921      }
922      logerror("CTRL: DMA word-fill transfer of %i bytes\n",count*2);
923      break;
924   case 0xfef5:
925      for(count=0;count<state->m_neocd_ctrl.word_count;count++)
926      {
927         //word = space->read_word(state->m_neocd_ctrl.addr_source);
928         space->write_word(state->m_neocd_ctrl.addr_source+(count*4),(state->m_neocd_ctrl.addr_source+(count*4)) >> 16);
929         space->write_word(state->m_neocd_ctrl.addr_source+(count*4)+2,(state->m_neocd_ctrl.addr_source+(count*4)) & 0xffff);
930      }
931      logerror("CTRL: DMA mode 2 transfer of %i bytes\n",count*4);
932      break;
933   case 0xcffd:
934      for(count=0;count<state->m_neocd_ctrl.word_count;count++)
935      {
936         //word = space->read_word(state->m_neocd_ctrl.addr_source);
937         space->write_word(state->m_neocd_ctrl.addr_source+(count*8),((state->m_neocd_ctrl.addr_source+(count*8)) >> 24) | 0xff00);
938         space->write_word(state->m_neocd_ctrl.addr_source+(count*8)+2,((state->m_neocd_ctrl.addr_source+(count*8)) >> 16) | 0xff00);
939         space->write_word(state->m_neocd_ctrl.addr_source+(count*8)+4,((state->m_neocd_ctrl.addr_source+(count*8)) >> 8) | 0xff00);
940         space->write_word(state->m_neocd_ctrl.addr_source+(count*8)+6,(state->m_neocd_ctrl.addr_source+(count*8)) | 0xff00);
941      }
942      logerror("CTRL: DMA mode 3 transfer of %i bytes\n",count*8);
943      break;
944   default:
945      logerror("CTRL: Unknown DMA transfer mode %04x\n",state->m_neocd_ctrl.dma_mode[0]);
946   }
947}
948
949static READ16_HANDLER( neocd_control_r )
950{
951   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
952
953   switch(offset)
954   {
955   case 0x64/2: // source address, high word
956      return (state->m_neocd_ctrl.addr_source >> 16) & 0xffff;
957   case 0x66/2: // source address, low word
958      return state->m_neocd_ctrl.addr_source & 0xffff;
959   case 0x68/2: // target address, high word
960      return (state->m_neocd_ctrl.addr_target >> 16) & 0xffff;
961   case 0x6a/2: // target address, low word
962      return state->m_neocd_ctrl.addr_target & 0xffff;
963   case 0x6c/2: // fill word
964      return state->m_neocd_ctrl.fill_word;
965   case 0x70/2: // word count
966      return (state->m_neocd_ctrl.word_count >> 16) & 0xffff;
967   case 0x72/2:
968      return state->m_neocd_ctrl.word_count & 0xffff;
969   case 0x7e/2:  // DMA parameters
970   case 0x80/2:
971   case 0x82/2:
972   case 0x84/2:
973   case 0x86/2:
974   case 0x88/2:
975   case 0x8a/2:
976   case 0x8c/2:
977   case 0x8e/2:
978      return state->m_neocd_ctrl.dma_mode[offset-(0x7e/2)];
979      break;
980   case 0x105/2:
981      return state->m_neocd_ctrl.area_sel;
982   case 0x11c/2:
983      logerror("CTRL: Read region code.\n");
984      return 0x0600;  // we'll just force USA region for now
985   case 0x1a0/2:
986      return state->m_neocd_ctrl.spr_bank_sel;
987      break;
988   case 0x1a2/2:
989      return state->m_neocd_ctrl.pcm_bank_sel;
990      break;
991   default:
992      logerror("CTRL: Read offset %04x\n",offset);
993   }
994
995   return 0;
996}
997
998static WRITE16_HANDLER( neocd_control_w )
999{
1000   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
1001   switch(offset)
1002   {
1003   case 0x60/2: // Start DMA transfer
1004      if((data & 0xff) == 0x40)
1005         neocd_do_dma(space);
1006      break;
1007   case 0x64/2: // source address, high word
1008      state->m_neocd_ctrl.addr_source = (state->m_neocd_ctrl.addr_source & 0x0000ffff) | (data << 16);
1009      logerror("CTRL: Set source address to %08x\n",state->m_neocd_ctrl.addr_source);
1010      break;
1011   case 0x66/2: // source address, low word
1012      state->m_neocd_ctrl.addr_source = (state->m_neocd_ctrl.addr_source & 0xffff0000) | data;
1013      logerror("CTRL: Set source address to %08x\n",state->m_neocd_ctrl.addr_source);
1014      break;
1015   case 0x68/2: // target address, high word
1016      state->m_neocd_ctrl.addr_target = (state->m_neocd_ctrl.addr_target & 0x0000ffff) | (data << 16);
1017      logerror("CTRL: Set target address to %08x\n",state->m_neocd_ctrl.addr_target);
1018      break;
1019   case 0x6a/2: // target address, low word
1020      state->m_neocd_ctrl.addr_target = (state->m_neocd_ctrl.addr_target & 0xffff0000) | data;
1021      logerror("CTRL: Set target address to %08x\n",state->m_neocd_ctrl.addr_target);
1022      break;
1023   case 0x6c/2: // fill word
1024      state->m_neocd_ctrl.fill_word = data;
1025      logerror("CTRL: Set fill word to %04x\n",data);
1026      break;
1027   case 0x70/2: // word count
1028      state->m_neocd_ctrl.word_count = (state->m_neocd_ctrl.word_count & 0x0000ffff) | (data << 16);
1029      logerror("CTRL: Set word count to %i\n",state->m_neocd_ctrl.word_count);
1030      break;
1031   case 0x72/2: // word count (low word)
1032      state->m_neocd_ctrl.word_count = (state->m_neocd_ctrl.word_count & 0xffff0000) | data;
1033      logerror("CTRL: Set word count to %i\n",state->m_neocd_ctrl.word_count);
1034      break;
1035   case 0x7e/2:  // DMA parameters
1036   case 0x80/2:
1037   case 0x82/2:
1038   case 0x84/2:
1039   case 0x86/2:
1040   case 0x88/2:
1041   case 0x8a/2:
1042   case 0x8c/2:
1043   case 0x8e/2:
1044      state->m_neocd_ctrl.dma_mode[offset-(0x7e/2)] = data;
1045      logerror("CTRL: DMA parameter %i set to %04x\n",offset-(0x7e/2),data);
1046      break;
1047   case 0x104/2:
1048      state->m_neocd_ctrl.area_sel = data & 0x00ff;
1049      logerror("CTRL: 0xExxxxx set to area %i\n",data & 0xff);
1050      break;
1051   case 0x140/2:  // end sprite transfer
1052      video_reset_neogeo(space->machine());
1053      break;
1054   case 0x142/2:  // end PCM transfer
1055      break;
1056   case 0x146/2:  // end Z80 transfer
1057      cputag_set_input_line(space->machine(),"audiocpu",INPUT_LINE_RESET,PULSE_LINE);
1058      break;
1059   case 0x148/2:  // end FIX transfer
1060      video_reset_neogeo(space->machine());
1061      break;
1062   case 0x1a0/2:
1063      state->m_neocd_ctrl.spr_bank_sel = data & 0xff;
1064      logerror("CTRL: Sprite area set to bank %i\n",data & 0xff);
1065      break;
1066   case 0x1a2/2:
1067      state->m_neocd_ctrl.pcm_bank_sel = data & 0xff;
1068      logerror("CTRL: PCM area set to bank %i\n",data & 0xff);
1069      break;
1070   default:
1071      logerror("CTRL: Write offset %04x, data %04x\n",offset*2,data);
1072   }
1073}
1074
1075/*
1076 *  Handling NeoCD banked RAM
1077 *  When the Z80 space is banked in to 0xe00000, only the low byte of each word is used
1078 */
1079
1080static READ16_HANDLER(neocd_transfer_r)
1081{
1082   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
1083   UINT16 ret = 0x0000;
1084   UINT8* Z80 = space->machine().region("audiocpu")->base();
1085   UINT8* PCM = space->machine().region("ymsnd")->base();
1086   UINT8* FIX = space->machine().region("fixed")->base();
1087   UINT16* SPR = (UINT16*)space->machine().region("sprites")->base();
1088
1089   switch(state->m_neocd_ctrl.area_sel)
1090   {
1091   case NEOCD_AREA_AUDIO:
1092      ret = Z80[offset & 0xffff] | 0xff00;
1093      break;
1094   case NEOCD_AREA_PCM:
1095      ret = PCM[offset + (0x100000*state->m_neocd_ctrl.pcm_bank_sel)] | 0xff00;
1096      break;
1097   case NEOCD_AREA_SPR:
1098      ret = SPR[offset + (0x80000*state->m_neocd_ctrl.spr_bank_sel)];
1099      break;
1100   case NEOCD_AREA_FIX:
1101      ret = FIX[offset & 0x1ffff] | 0xff00;
1102      break;
1103   }
1104
1105   return ret;
1106}
1107
1108static WRITE16_HANDLER(neocd_transfer_w)
1109{
1110   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
1111   UINT8* Z80 = space->machine().region("audiocpu")->base();
1112   UINT8* PCM = space->machine().region("ymsnd")->base();
1113   UINT8* FIX = space->machine().region("fixed")->base();
1114   UINT16* SPR = (UINT16*)space->machine().region("sprites")->base();
1115
1116   switch(state->m_neocd_ctrl.area_sel)
1117   {
1118   case NEOCD_AREA_AUDIO:
1119      Z80[offset & 0xffff] = data & 0xff;
1120      break;
1121   case NEOCD_AREA_PCM:
1122      PCM[offset + (0x100000*state->m_neocd_ctrl.pcm_bank_sel)] = data & 0xff;
1123      break;
1124   case NEOCD_AREA_SPR:
1125      COMBINE_DATA(SPR+(offset + (0x80000*state->m_neocd_ctrl.spr_bank_sel)));
1126      break;
1127   case NEOCD_AREA_FIX:
1128      FIX[offset & 0x1ffff] = data & 0xff;
1129      break;
1130   }
1131
1132}
1133
1134/*
1135 * Handling selectable controller types
1136 */
1137
1138static READ16_HANDLER( aes_in0_r )
1139{
1140   neogeo_state *state = space->machine().driver_data<neogeo_state>();
1141   UINT32 ret = 0xffff;
1142   UINT32 ctrl = input_port_read(space->machine(),"CTRLSEL");
1143
1144   switch(ctrl & 0x0f)
1145   {
1146   case 0x00:
1147      ret = 0xffff;
1148      break;
1149   case 0x01:
1150      ret = input_port_read(space->machine(),"IN0");
1151      break;
1152   case 0x02:
1153      switch (state->m_controller_select)
1154      {
1155         case 0x09: ret = input_port_read(space->machine(), "MJ01_P1"); break;
1156         case 0x12: ret = input_port_read(space->machine(), "MJ02_P1"); break;
1157         case 0x1b: ret = input_port_read(space->machine(), "MJ03_P1"); break; /* player 1 normal inputs? */
1158         case 0x24: ret = input_port_read(space->machine(), "MJ04_P1"); break;
1159         default:
1160            ret = input_port_read(space->machine(),"IN0");
1161            break;
1162      }
1163      break;
1164   }
1165
1166   return ret;
1167}
1168
1169static READ16_HANDLER( aes_in1_r )
1170{
1171   neogeo_state *state = space->machine().driver_data<neogeo_state>();
1172   UINT32 ret = 0xffff;
1173   UINT32 ctrl = input_port_read(space->machine(),"CTRLSEL");
1174
1175   switch(ctrl & 0xf0)
1176   {
1177   case 0x00:
1178      ret = 0xffff;
1179      break;
1180   case 0x10:
1181      ret = input_port_read(space->machine(),"IN1");
1182      break;
1183   case 0x20:
1184      switch (state->m_controller_select)
1185      {
1186         case 0x09: ret = input_port_read(space->machine(), "MJ01_P2"); break;
1187         case 0x12: ret = input_port_read(space->machine(), "MJ02_P2"); break;
1188         case 0x1b: ret = input_port_read(space->machine(), "MJ03_P2"); break; /* player 2 normal inputs? */
1189         case 0x24: ret = input_port_read(space->machine(), "MJ04_P2"); break;
1190         default:
1191            ret = input_port_read(space->machine(),"IN1");
1192            break;
1193      }
1194      break;
1195   }
1196
1197   return ret;
1198}
1199
1200
1201static READ16_HANDLER(aes_in2_r)
1202{
1203   UINT32 in2 = input_port_read(space->machine(),"IN2");
1204   UINT32 ret = in2;
1205   UINT32 sel = input_port_read(space->machine(),"CTRLSEL");
1206   neogeo_state *state = space->machine().driver_data<neogeo_state>();
1207
1208   if((sel & 0x02) && (state->m_controller_select == 0x24))
1209      ret ^= 0x0200;
1210
1211   if((sel & 0x20) && (state->m_controller_select == 0x24))
1212      ret ^= 0x0800;
1213
1214   return ret;
1215}
1216
1217
1218/*************************************
1219 *
1220 *  Machine initialization
1221 *
1222 *************************************/
1223
1224static void aes_postload(neogeo_state *state)
1225{
1226   _set_main_cpu_bank_address(state->machine());
1227   _set_main_cpu_vector_table_source(state->machine());
1228   set_audio_cpu_banking(state->machine());
1229   _set_audio_cpu_rom_source(state->machine().device("maincpu")->memory().space(AS_PROGRAM));
1230}
1231
1232static void common_machine_start(running_machine &machine)
1233{
1234   neogeo_state *state = machine.driver_data<neogeo_state>();
1235
1236   /* set the BIOS bank */
1237   memory_set_bankptr(machine, NEOGEO_BANK_BIOS, machine.region("mainbios")->base());
1238
1239   /* set the initial main CPU bank */
1240   main_cpu_banking_init(machine);
1241
1242   /* set the initial audio CPU ROM banks */
1243   audio_cpu_banking_init(machine);
1244
1245   create_interrupt_timers(machine);
1246
1247   /* start with an IRQ3 - but NOT on a reset */
1248   state->m_irq3_pending = 1;
1249
1250   /* get devices */
1251   state->m_maincpu = machine.device("maincpu");
1252   state->m_audiocpu = machine.device("audiocpu");
1253   state->m_upd4990a = machine.device("upd4990a");
1254
1255   /* register state save */
1256   state->save_item(NAME(state->m_display_position_interrupt_control));
1257   state->save_item(NAME(state->m_display_counter));
1258   state->save_item(NAME(state->m_vblank_interrupt_pending));
1259   state->save_item(NAME(state->m_display_position_interrupt_pending));
1260   state->save_item(NAME(state->m_irq3_pending));
1261   state->save_item(NAME(state->m_audio_result));
1262   state->save_item(NAME(state->m_controller_select));
1263   state->save_item(NAME(state->m_main_cpu_bank_address));
1264   state->save_item(NAME(state->m_main_cpu_vector_table_source));
1265   state->save_item(NAME(state->m_audio_cpu_banks));
1266   state->save_item(NAME(state->m_audio_cpu_rom_source));
1267   state->save_item(NAME(state->m_audio_cpu_rom_source_last));
1268   state->save_item(NAME(state->m_save_ram_unlocked));
1269   state->save_item(NAME(state->m_output_data));
1270   state->save_item(NAME(state->m_output_latch));
1271   state->save_item(NAME(state->m_el_value));
1272   state->save_item(NAME(state->m_led1_value));
1273   state->save_item(NAME(state->m_led2_value));
1274   state->save_item(NAME(state->m_recurse));
1275
1276   machine.save().register_postload(save_prepost_delegate(FUNC(aes_postload), state));
1277}
1278
1279static MACHINE_START( neogeo )
1280{
1281   ng_aes_state *state = machine.driver_data<ng_aes_state>();
1282   common_machine_start(machine);
1283
1284   /* initialize the memcard data structure */
1285   state->m_memcard_data = auto_alloc_array_clear(machine, UINT8, MEMCARD_SIZE);
1286   state->save_pointer(NAME(state->m_memcard_data), 0x0800);
1287}
1288
1289static MACHINE_START(neocd)
1290{
1291   ng_aes_state *state = machine.driver_data<ng_aes_state>();
1292   UINT8* ROM = machine.region("mainbios")->base();
1293   UINT8* RAM = machine.region("maincpu")->base();
1294   UINT8* Z80bios = machine.region("audiobios")->base();
1295   UINT8* FIXbios = machine.region("fixedbios")->base();
1296   int x;
1297
1298   common_machine_start(machine);
1299
1300   /* initialize the memcard data structure */
1301   /* NeoCD doesn't have memcard slots, rather, it has a larger internal memory which works the same */
1302   state->m_memcard_data = auto_alloc_array_clear(machine, UINT8, 0x2000);
1303   state->save_pointer(NAME(state->m_memcard_data), 0x2000);
1304
1305   // copy initial 68k vectors into RAM
1306   memcpy(RAM,ROM,0x80);
1307
1308   // copy Z80 code into Z80 space (from 0x20000)
1309   for(x=0;x<0x10000;x+=2)
1310   {
1311      Z80bios[x] = ROM[x+0x20001];
1312      Z80bios[x+1] = ROM[x+0x20000];
1313   }
1314
1315   // copy fixed tiles into FIX space (from 0x70000)
1316   memcpy(FIXbios,ROM+0x70000,0x10000);
1317}
1318
1319//static DEVICE_IMAGE_LOAD(aes_cart)
1320//{
1321//  else
1322//      return IMAGE_INIT_FAIL;
1323
1324//  return IMAGE_INIT_PASS;
1325//}
1326
1327/*************************************
1328 *
1329 *  Machine reset
1330 *
1331 *************************************/
1332
1333static MACHINE_RESET( neogeo )
1334{
1335   neogeo_state *state = machine.driver_data<neogeo_state>();
1336   offs_t offs;
1337   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
1338
1339   /* reset system control registers */
1340   for (offs = 0; offs < 8; offs++)
1341      system_control_w(space, offs, 0, 0x00ff);
1342
1343   machine.device("maincpu")->reset();
1344
1345   neogeo_reset_rng(machine);
1346
1347   start_interrupt_timers(machine);
1348
1349   /* trigger the IRQ3 that was set by MACHINE_START */
1350   update_interrupts(machine);
1351
1352   state->m_recurse = 0;
1353
1354   /* AES apparently always uses the cartridge's fixed bank mode */
1355   neogeo_set_fixed_layer_source(machine,1);
1356}
1357
1358
1359
1360/*************************************
1361 *
1362 *  Main CPU memory handlers
1363 *
1364 *************************************/
1365
1366static ADDRESS_MAP_START( main_map, AS_PROGRAM, 16 )
1367   AM_RANGE(0x000000, 0x00007f) AM_ROMBANK(NEOGEO_BANK_VECTORS)
1368   AM_RANGE(0x000080, 0x0fffff) AM_ROM
1369   AM_RANGE(0x100000, 0x10ffff) AM_MIRROR(0x0f0000) AM_RAM
1370   /* some games have protection devices in the 0x200000 region, it appears to map to cart space, not surprising, the ROM is read here too */
1371   AM_RANGE(0x200000, 0x2fffff) AM_ROMBANK(NEOGEO_BANK_CARTRIDGE)
1372   AM_RANGE(0x2ffff0, 0x2fffff) AM_WRITE(main_cpu_bank_select_w)
1373   AM_RANGE(0x300000, 0x300001) AM_MIRROR(0x01ff7e) AM_READ(aes_in0_r)
1374   AM_RANGE(0x300080, 0x300081) AM_MIRROR(0x01ff7e) AM_READ_PORT("IN4")
1375   AM_RANGE(0x300000, 0x300001) AM_MIRROR(0x01ffe0) AM_READ(neogeo_unmapped_r) AM_WRITENOP   // AES has no watchdog
1376   AM_RANGE(0x320000, 0x320001) AM_MIRROR(0x01fffe) AM_READ_PORT("IN3") AM_WRITE(audio_command_w)
1377   AM_RANGE(0x340000, 0x340001) AM_MIRROR(0x01fffe) AM_READ(aes_in1_r)
1378   AM_RANGE(0x360000, 0x37ffff) AM_READ(neogeo_unmapped_r)
1379   AM_RANGE(0x380000, 0x380001) AM_MIRROR(0x01fffe) AM_READ(aes_in2_r)
1380   AM_RANGE(0x380000, 0x38007f) AM_MIRROR(0x01ff80) AM_WRITE(io_control_w)
1381   AM_RANGE(0x3a0000, 0x3a001f) AM_MIRROR(0x01ffe0) AM_READWRITE(neogeo_unmapped_r, system_control_w)
1382   AM_RANGE(0x3c0000, 0x3c0007) AM_MIRROR(0x01fff8) AM_READ(neogeo_video_register_r)
1383   AM_RANGE(0x3c0000, 0x3c000f) AM_MIRROR(0x01fff0) AM_WRITE(neogeo_video_register_w)
1384   AM_RANGE(0x3e0000, 0x3fffff) AM_READ(neogeo_unmapped_r)
1385   AM_RANGE(0x400000, 0x401fff) AM_MIRROR(0x3fe000) AM_READWRITE(neogeo_paletteram_r, neogeo_paletteram_w)
1386   AM_RANGE(0x800000, 0x800fff) AM_READWRITE(memcard_r, memcard_w)
1387   AM_RANGE(0xc00000, 0xc1ffff) AM_MIRROR(0x0e0000) AM_ROMBANK(NEOGEO_BANK_BIOS)
1388   AM_RANGE(0xd00000, 0xd0ffff) AM_MIRROR(0x0f0000) AM_READ(neogeo_unmapped_r) //AM_RAM_WRITE(save_ram_w) AM_BASE(&save_ram)
1389   AM_RANGE(0xe00000, 0xffffff) AM_READ(neogeo_unmapped_r)
1390ADDRESS_MAP_END
1391
1392static ADDRESS_MAP_START( neocd_main_map, AS_PROGRAM, 16 )
1393   AM_RANGE(0x000000, 0x00007f) AM_RAMBANK(NEOGEO_BANK_VECTORS)
1394   AM_RANGE(0x000080, 0x0fffff) AM_RAM
1395   AM_RANGE(0x100000, 0x10ffff) AM_MIRROR(0x0f0000) AM_RAM AM_BASE(&neocd_work_ram)
1396   /* some games have protection devices in the 0x200000 region, it appears to map to cart space, not surprising, the ROM is read here too */
1397   AM_RANGE(0x200000, 0x2fffff) AM_ROMBANK(NEOGEO_BANK_CARTRIDGE)
1398   AM_RANGE(0x2ffff0, 0x2fffff) AM_WRITE(main_cpu_bank_select_w)
1399   AM_RANGE(0x300000, 0x300001) AM_MIRROR(0x01ff7e) AM_READ(aes_in0_r)
1400   AM_RANGE(0x300080, 0x300081) AM_MIRROR(0x01ff7e) AM_READ_PORT("IN4")
1401   AM_RANGE(0x300000, 0x300001) AM_MIRROR(0x01ffe0) AM_READ(neogeo_unmapped_r) AM_WRITENOP   // AES has no watchdog
1402   AM_RANGE(0x320000, 0x320001) AM_MIRROR(0x01fffe) AM_READ_PORT("IN3") AM_WRITE(audio_command_w)
1403   AM_RANGE(0x340000, 0x340001) AM_MIRROR(0x01fffe) AM_READ(aes_in1_r)
1404   AM_RANGE(0x360000, 0x37ffff) AM_READ(neogeo_unmapped_r)
1405   AM_RANGE(0x380000, 0x380001) AM_MIRROR(0x01fffe) AM_READ(aes_in2_r)
1406   AM_RANGE(0x380000, 0x38007f) AM_MIRROR(0x01ff80) AM_WRITE(io_control_w)
1407   AM_RANGE(0x3a0000, 0x3a001f) AM_MIRROR(0x01ffe0) AM_READWRITE(neogeo_unmapped_r, system_control_w)
1408   AM_RANGE(0x3c0000, 0x3c0007) AM_MIRROR(0x01fff8) AM_READ(neogeo_video_register_r)
1409   AM_RANGE(0x3c0000, 0x3c000f) AM_MIRROR(0x01fff0) AM_WRITE(neogeo_video_register_w)
1410   AM_RANGE(0x3e0000, 0x3fffff) AM_READ(neogeo_unmapped_r)
1411   AM_RANGE(0x400000, 0x401fff) AM_MIRROR(0x3fe000) AM_READWRITE(neogeo_paletteram_r, neogeo_paletteram_w)
1412   AM_RANGE(0x800000, 0x803fff) AM_READWRITE(neocd_memcard_r, neocd_memcard_w)
1413   AM_RANGE(0xc00000, 0xcfffff) AM_ROMBANK(NEOGEO_BANK_BIOS)
1414   AM_RANGE(0xd00000, 0xd0ffff) AM_MIRROR(0x0f0000) AM_READ(neogeo_unmapped_r) //AM_RAM_WRITE(save_ram_w) AM_BASE(&save_ram)
1415   AM_RANGE(0xe00000, 0xefffff) AM_READWRITE(neocd_transfer_r,neocd_transfer_w)
1416   AM_RANGE(0xf00000, 0xfeffff) AM_READ(neogeo_unmapped_r)
1417   AM_RANGE(0xff0000, 0xff01ff) AM_READWRITE(neocd_control_r, neocd_control_w) // CDROM / DMA
1418   AM_RANGE(0xff0200, 0xffffff) AM_READ(neogeo_unmapped_r)
1419ADDRESS_MAP_END
1420
1421
1422/*************************************
1423 *
1424 *  Audio CPU memory handlers
1425 *
1426 *************************************/
1427
1428static ADDRESS_MAP_START( audio_map, AS_PROGRAM, 8 )
1429   AM_RANGE(0x0000, 0x7fff) AM_ROMBANK(NEOGEO_BANK_AUDIO_CPU_MAIN_BANK)
1430   AM_RANGE(0x8000, 0xbfff) AM_ROMBANK(NEOGEO_BANK_AUDIO_CPU_CART_BANK + 3)
1431   AM_RANGE(0xc000, 0xdfff) AM_ROMBANK(NEOGEO_BANK_AUDIO_CPU_CART_BANK + 2)
1432   AM_RANGE(0xe000, 0xefff) AM_ROMBANK(NEOGEO_BANK_AUDIO_CPU_CART_BANK + 1)
1433   AM_RANGE(0xf000, 0xf7ff) AM_ROMBANK(NEOGEO_BANK_AUDIO_CPU_CART_BANK + 0)
1434   AM_RANGE(0xf800, 0xffff) AM_RAM
1435ADDRESS_MAP_END
1436
1437
1438
1439/*************************************
1440 *
1441 *  Audio CPU port handlers
1442 *
1443 *************************************/
1444
1445static ADDRESS_MAP_START( audio_io_map, AS_IO, 8 )
1446  /*AM_RANGE(0x00, 0x00) AM_MIRROR(0xff00) AM_READWRITE(audio_command_r, audio_cpu_clear_nmi_w);*/  /* may not and NMI clear */
1447   AM_RANGE(0x00, 0x00) AM_MIRROR(0xff00) AM_READ(audio_command_r)
1448   AM_RANGE(0x04, 0x07) AM_MIRROR(0xff00) AM_DEVREADWRITE("ymsnd", ym2610_r, ym2610_w)
1449   AM_RANGE(0x08, 0x08) AM_MIRROR(0xff00) /* write - NMI enable / acknowledge? (the data written doesn't matter) */
1450   AM_RANGE(0x08, 0x08) AM_MIRROR(0xfff0) AM_MASK(0xfff0) AM_READ(audio_cpu_bank_select_f000_f7ff_r)
1451   AM_RANGE(0x09, 0x09) AM_MIRROR(0xfff0) AM_MASK(0xfff0) AM_READ(audio_cpu_bank_select_e000_efff_r)
1452   AM_RANGE(0x0a, 0x0a) AM_MIRROR(0xfff0) AM_MASK(0xfff0) AM_READ(audio_cpu_bank_select_c000_dfff_r)
1453   AM_RANGE(0x0b, 0x0b) AM_MIRROR(0xfff0) AM_MASK(0xfff0) AM_READ(audio_cpu_bank_select_8000_bfff_r)
1454   AM_RANGE(0x0c, 0x0c) AM_MIRROR(0xff00) AM_WRITE(audio_result_w)
1455   AM_RANGE(0x18, 0x18) AM_MIRROR(0xff00) /* write - NMI disable? (the data written doesn't matter) */
1456ADDRESS_MAP_END
1457
1458
1459
1460/*************************************
1461 *
1462 *  Audio interface
1463 *
1464 *************************************/
1465
1466static const ym2610_interface ym2610_config =
1467{
1468   audio_cpu_irq
1469};
1470
1471
1472
1473/*************************************
1474 *
1475 *  Standard Neo-Geo DIPs and
1476 *  input port definition
1477 *
1478 *************************************/
1479
1480#define STANDARD_DIPS                                                      \
1481   PORT_DIPNAME( 0x0001, 0x0001, "Test Switch" ) PORT_DIPLOCATION("SW:1")               \
1482   PORT_DIPSETTING(     0x0001, DEF_STR( Off ) )                                 \
1483   PORT_DIPSETTING(     0x0000, DEF_STR( On ) )                                 \
1484   PORT_DIPNAME( 0x0002, 0x0002, "Coin Chutes?" ) PORT_DIPLOCATION("SW:2")               \
1485   PORT_DIPSETTING(     0x0000, "1?" )                                       \
1486   PORT_DIPSETTING(     0x0002, "2?" )                                       \
1487   PORT_DIPNAME( 0x0004, 0x0004, "Autofire (in some games)" ) PORT_DIPLOCATION("SW:3")      \
1488   PORT_DIPSETTING(     0x0004, DEF_STR( Off ) )                                 \
1489   PORT_DIPSETTING(     0x0000, DEF_STR( On ) )                                 \
1490   PORT_DIPNAME( 0x0018, 0x0018, "COMM Setting (Cabinet No.)" ) PORT_DIPLOCATION("SW:4,5")   \
1491   PORT_DIPSETTING(     0x0018, "1" )                                          \
1492   PORT_DIPSETTING(     0x0008, "2" )                                          \
1493   PORT_DIPSETTING(     0x0010, "3" )                                          \
1494   PORT_DIPSETTING(     0x0000, "4" )                                          \
1495   PORT_DIPNAME( 0x0020, 0x0020, "COMM Setting (Link Enable)" ) PORT_DIPLOCATION("SW:6")   \
1496   PORT_DIPSETTING(     0x0020, DEF_STR( Off ) )                                 \
1497   PORT_DIPSETTING(     0x0000, DEF_STR( On ) )                                 \
1498   PORT_DIPNAME( 0x0040, 0x0040, DEF_STR( Free_Play ) ) PORT_DIPLOCATION("SW:7")         \
1499   PORT_DIPSETTING(     0x0040, DEF_STR( Off ) )                                 \
1500   PORT_DIPSETTING(     0x0000, DEF_STR( On ) )                                 \
1501   PORT_DIPNAME( 0x0080, 0x0080, "Freeze" ) PORT_DIPLOCATION("SW:8")                  \
1502   PORT_DIPSETTING(     0x0080, DEF_STR( Off ) )                                 \
1503   PORT_DIPSETTING(     0x0000, DEF_STR( On ) )
1504
1505#define STANDARD_IN2                                                            \
1506   PORT_START("IN2")                                                            \
1507   PORT_BIT( 0x00ff, IP_ACTIVE_LOW, IPT_UNUSED )                                       \
1508   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_START1 )                           \
1509   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON5) PORT_NAME("1P Select") PORT_CODE(KEYCODE_5) PORT_PLAYER(1)   \
1510   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_START2 )                           \
1511   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON5) PORT_NAME("2P Select") PORT_CODE(KEYCODE_6) PORT_PLAYER(2)   \
1512   PORT_BIT( 0x7000, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(get_memcard_status, NULL)         \
1513   PORT_BIT( 0x8000, IP_ACTIVE_HIGH, IPT_UNKNOWN )  /* Matrimelee expects this bit to be active high when on an AES */
1514
1515#define STANDARD_IN3                                                            \
1516   PORT_START("IN3")                                                            \
1517   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_UNUSED )  /* Coin 1 - AES has no coin slots, it's a console */   \
1518   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_UNUSED )  /* Coin 2 - AES has no coin slots, it's a console */   \
1519   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_UNUSED )  /* Service Coin - not used, AES is a console */   \
1520   PORT_BIT( 0x0008, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* having this ACTIVE_HIGH causes you to start with 2 credits using USA bios roms */   \
1521   PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* having this ACTIVE_HIGH causes you to start with 2 credits using USA bios roms */   \
1522   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_SPECIAL ) /* what is this? */                        \
1523   PORT_BIT( 0x00c0, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(get_calendar_status, NULL)         \
1524   PORT_BIT( 0xff00, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(get_audio_result, NULL)
1525
1526
1527#define STANDARD_IN4                                                         \
1528   PORT_START("IN4")                                                         \
1529   PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_UNKNOWN )                                    \
1530   PORT_BIT( 0x0002, IP_ACTIVE_HIGH, IPT_UNKNOWN )                                    \
1531   PORT_BIT( 0x0004, IP_ACTIVE_HIGH, IPT_UNKNOWN )                                    \
1532   PORT_BIT( 0x0008, IP_ACTIVE_HIGH, IPT_UNKNOWN )                                    \
1533   PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_UNKNOWN )                                    \
1534   PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_UNKNOWN )                                    \
1535   PORT_BIT( 0x0040, IP_ACTIVE_HIGH, IPT_SPECIAL ) /* what is this? - is 0 for 1 or 2 slot MVS (and AES?)*/                     \
1536   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("Enter BIOS") PORT_CODE(KEYCODE_F2)   \
1537   PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNUSED )
1538
1539static INPUT_PORTS_START( controller )
1540   PORT_START("IN0")
1541   PORT_BIT( 0x00ff, IP_ACTIVE_LOW, IPT_UNUSED )
1542   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1) PORT_CATEGORY (1)
1543   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) PORT_CATEGORY (1)
1544   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) PORT_CATEGORY (1)
1545   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) PORT_CATEGORY (1)
1546   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_CATEGORY (1)
1547   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_CATEGORY (1)
1548   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_CATEGORY (1)
1549   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_CATEGORY (1)
1550
1551
1552   PORT_START("IN1")
1553   PORT_BIT( 0x00ff, IP_ACTIVE_LOW, IPT_UNUSED )
1554   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2) PORT_CATEGORY (2)
1555   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) PORT_CATEGORY (2)
1556   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) PORT_CATEGORY (2)
1557   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) PORT_CATEGORY (2)
1558   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_CATEGORY (2)
1559   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_CATEGORY (2)
1560   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_CATEGORY (2)
1561   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) PORT_CATEGORY (2)
1562INPUT_PORTS_END
1563
1564static INPUT_PORTS_START( mjpanel )
1565   PORT_START("MJ01_P1")
1566   PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED )
1567   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_MAHJONG_A ) PORT_PLAYER(1) PORT_CATEGORY (3)
1568   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_B ) PORT_PLAYER(1) PORT_CATEGORY (3)
1569   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_C ) PORT_PLAYER(1) PORT_CATEGORY (3)
1570   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_MAHJONG_D ) PORT_PLAYER(1) PORT_CATEGORY (3)
1571   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_E ) PORT_PLAYER(1) PORT_CATEGORY (3)
1572   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_MAHJONG_F ) PORT_PLAYER(1) PORT_CATEGORY (3)
1573   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_MAHJONG_G ) PORT_PLAYER(1) PORT_CATEGORY (3)
1574   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1575
1576   PORT_START("MJ02_P1")
1577   PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED )
1578   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_MAHJONG_H ) PORT_PLAYER(1) PORT_CATEGORY (3)
1579   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_I ) PORT_PLAYER(1) PORT_CATEGORY (3)
1580   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_J ) PORT_PLAYER(1) PORT_CATEGORY (3)
1581   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_MAHJONG_K ) PORT_PLAYER(1) PORT_CATEGORY (3)
1582   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_L ) PORT_PLAYER(1) PORT_CATEGORY (3)
1583   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_MAHJONG_M ) PORT_PLAYER(1) PORT_CATEGORY (3)
1584   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_MAHJONG_N ) PORT_PLAYER(1) PORT_CATEGORY (3)
1585   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(1) PORT_CATEGORY (3)
1586
1587   PORT_START("MJ03_P1")
1588   PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED )
1589   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1) PORT_CATEGORY (3)
1590   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) PORT_CATEGORY (3)
1591   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) PORT_CATEGORY (3)
1592   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) PORT_CATEGORY (3)
1593   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_CATEGORY (3)
1594   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_CATEGORY (3)
1595   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_CATEGORY (3)
1596   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_CATEGORY (3)
1597
1598   PORT_START("MJ04_P1")
1599   PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED )
1600   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_MAHJONG_PON ) PORT_PLAYER(1) PORT_CATEGORY (3)
1601   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_CHI ) PORT_PLAYER(1) PORT_CATEGORY (3)
1602   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_KAN ) PORT_PLAYER(1) PORT_CATEGORY (3)
1603   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_MAHJONG_RON ) PORT_PLAYER(1) PORT_CATEGORY (3)
1604   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_REACH ) PORT_PLAYER(1) PORT_CATEGORY (3)
1605   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1606   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1607   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1608
1609   PORT_START("MJ01_P2")
1610   PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED )
1611   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_MAHJONG_A ) PORT_PLAYER(2) PORT_CATEGORY (4)
1612   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_B ) PORT_PLAYER(2) PORT_CATEGORY (4)
1613   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_C ) PORT_PLAYER(2) PORT_CATEGORY (4)
1614   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_MAHJONG_D ) PORT_PLAYER(2) PORT_CATEGORY (4)
1615   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_E ) PORT_PLAYER(2) PORT_CATEGORY (4)
1616   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_MAHJONG_F ) PORT_PLAYER(2) PORT_CATEGORY (4)
1617   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_MAHJONG_G ) PORT_PLAYER(2) PORT_CATEGORY (4)
1618   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1619
1620   PORT_START("MJ02_P2")
1621   PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED )
1622   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_MAHJONG_H ) PORT_PLAYER(2) PORT_CATEGORY (4)
1623   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_I ) PORT_PLAYER(2) PORT_CATEGORY (4)
1624   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_J ) PORT_PLAYER(2) PORT_CATEGORY (4)
1625   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_MAHJONG_K ) PORT_PLAYER(2) PORT_CATEGORY (4)
1626   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_L ) PORT_PLAYER(2) PORT_CATEGORY (4)
1627   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_MAHJONG_M ) PORT_PLAYER(2) PORT_CATEGORY (4)
1628   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_MAHJONG_N ) PORT_PLAYER(2) PORT_CATEGORY (4)
1629   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1630
1631   PORT_START("MJ03_P2")
1632   PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED )
1633   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2) PORT_CATEGORY (4)
1634   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) PORT_CATEGORY (4)
1635   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) PORT_CATEGORY (4)
1636   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) PORT_CATEGORY (4)
1637   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_CATEGORY (4)
1638   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_CATEGORY (4)
1639   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_CATEGORY (4)
1640   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) PORT_CATEGORY (4)
1641
1642   PORT_START("MJ04_P2")
1643   PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED )
1644   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_MAHJONG_PON ) PORT_PLAYER(2) PORT_CATEGORY (4)
1645   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_CHI ) PORT_PLAYER(2) PORT_CATEGORY (4)
1646   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_KAN ) PORT_PLAYER(2) PORT_CATEGORY (4)
1647   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_MAHJONG_RON ) PORT_PLAYER(2) PORT_CATEGORY (4)
1648   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_REACH ) PORT_PLAYER(2) PORT_CATEGORY (4)
1649   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1650   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1651   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1652
1653INPUT_PORTS_END
1654
1655static INPUT_PORTS_START( aes )
1656// was there anyting in place of dipswitch in the home console?
1657/*  PORT_START("IN0")
1658    PORT_BIT( 0x00ff, IP_ACTIVE_LOW, IPT_UNUSED )
1659//  PORT_DIPNAME( 0x0001, 0x0001, "Test Switch" ) PORT_DIPLOCATION("SW:1")
1660//  PORT_DIPSETTING(      0x0001, DEF_STR( Off ) )
1661//  PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
1662//  PORT_DIPNAME( 0x0002, 0x0002, "Coin Chutes?" ) PORT_DIPLOCATION("SW:2")
1663//  PORT_DIPSETTING(      0x0000, "1?" )
1664//  PORT_DIPSETTING(      0x0002, "2?" )
1665//  PORT_DIPNAME( 0x0004, 0x0000, "Mahjong Control Panel (or Auto Fire)" ) PORT_DIPLOCATION("SW:3")
1666//  PORT_DIPSETTING(      0x0004, DEF_STR( Off ) )
1667//  PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
1668//  PORT_DIPNAME( 0x0018, 0x0018, "COMM Setting (Cabinet No.)" ) PORT_DIPLOCATION("SW:4,5")
1669//  PORT_DIPSETTING(      0x0018, "1" )
1670//  PORT_DIPSETTING(      0x0008, "2" )
1671//  PORT_DIPSETTING(      0x0010, "3" )
1672//  PORT_DIPSETTING(      0x0000, "4" )
1673//  PORT_DIPNAME( 0x0020, 0x0020, "COMM Setting (Link Enable)" ) PORT_DIPLOCATION("SW:6")
1674//  PORT_DIPSETTING(      0x0020, DEF_STR( Off ) )
1675//  PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
1676//  PORT_DIPNAME( 0x0040, 0x0040, DEF_STR( Free_Play ) ) PORT_DIPLOCATION("SW:7")
1677//  PORT_DIPSETTING(      0x0040, DEF_STR( Off ) )
1678//  PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
1679//  PORT_DIPNAME( 0x0080, 0x0080, "Freeze" ) PORT_DIPLOCATION("SW:8")
1680//  PORT_DIPSETTING(      0x0080, DEF_STR( Off ) )
1681//  PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
1682    PORT_BIT( 0xff00, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(aes_controller_r, NULL) */
1683
1684   PORT_START("CTRLSEL")  /* Select Controller Type */
1685   PORT_CATEGORY_CLASS( 0x0f, 0x01, "P1 Controller")
1686   PORT_CATEGORY_ITEM(  0x00, "Unconnected",         0 )
1687   PORT_CATEGORY_ITEM(  0x01, "NeoGeo Controller",      1 )
1688   PORT_CATEGORY_ITEM(  0x02, "NeoGeo Mahjong Panel",   3 )
1689   PORT_CATEGORY_CLASS( 0xf0, 0x10, "P2 Controller")
1690   PORT_CATEGORY_ITEM(  0x00, "Unconnected",      0 )
1691   PORT_CATEGORY_ITEM(  0x10, "NeoGeo Controller",      2 )
1692   PORT_CATEGORY_ITEM(  0x20, "NeoGeo Mahjong Panel",   4 )
1693
1694   PORT_INCLUDE( controller )
1695
1696   PORT_INCLUDE( mjpanel )
1697
1698// were some of these present in the AES?!?
1699   STANDARD_IN2
1700
1701   STANDARD_IN3
1702
1703   STANDARD_IN4
1704INPUT_PORTS_END
1705
1706
1707
1708/*************************************
1709 *
1710 *  Machine driver
1711 *
1712 *************************************/
1713
1714static MACHINE_CONFIG_START( neogeo, ng_aes_state )
1715
1716   /* basic machine hardware */
1717   MCFG_CPU_ADD("maincpu", M68000, NEOGEO_MAIN_CPU_CLOCK)
1718   MCFG_CPU_PROGRAM_MAP(main_map)
1719
1720   MCFG_CPU_ADD("audiocpu", Z80, NEOGEO_AUDIO_CPU_CLOCK)
1721   MCFG_CPU_PROGRAM_MAP(audio_map)
1722   MCFG_CPU_IO_MAP(audio_io_map)
1723
1724   MCFG_MACHINE_START(neogeo)
1725   MCFG_MACHINE_RESET(neogeo)
1726
1727   /* video hardware */
1728   MCFG_VIDEO_START(neogeo)
1729   MCFG_VIDEO_RESET(neogeo)
1730   MCFG_DEFAULT_LAYOUT(layout_neogeo)
1731
1732   MCFG_SCREEN_ADD("screen", RASTER)
1733   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
1734   MCFG_SCREEN_RAW_PARAMS(NEOGEO_PIXEL_CLOCK, NEOGEO_HTOTAL, NEOGEO_HBEND, NEOGEO_HBSTART, NEOGEO_VTOTAL, NEOGEO_VBEND, NEOGEO_VBSTART)
1735   MCFG_SCREEN_UPDATE(neogeo)
1736
1737   /* audio hardware */
1738   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
1739
1740   MCFG_SOUND_ADD("ymsnd", YM2610, NEOGEO_YM2610_CLOCK)
1741   MCFG_SOUND_CONFIG(ym2610_config)
1742   MCFG_SOUND_ROUTE(0, "lspeaker",  0.60)
1743   MCFG_SOUND_ROUTE(0, "rspeaker", 0.60)
1744   MCFG_SOUND_ROUTE(1, "lspeaker",  1.0)
1745   MCFG_SOUND_ROUTE(2, "rspeaker", 1.0)
1746
1747   /* NEC uPD4990A RTC */
1748   MCFG_UPD4990A_ADD("upd4990a")
1749MACHINE_CONFIG_END
1750
1751static MACHINE_CONFIG_DERIVED( aes, neogeo )
1752
1753   MCFG_MEMCARD_HANDLER(neogeo)
1754
1755   MCFG_AES_CARTRIDGE_ADD("aes_multicart")
1756//  MCFG_CARTSLOT_ADD("cart")
1757//  MCFG_CARTSLOT_MANDATORY
1758
1759//  MCFG_CARTSLOT_LOAD(aes_cart)
1760
1761   MCFG_SOFTWARE_LIST_ADD("cart_list","aes")
1762MACHINE_CONFIG_END
1763
1764static MACHINE_CONFIG_DERIVED( neocd, neogeo )
1765
1766   MCFG_CPU_MODIFY("maincpu")
1767   MCFG_CPU_PROGRAM_MAP(neocd_main_map)
1768
1769   MCFG_MACHINE_START(neocd)
1770MACHINE_CONFIG_END
1771
1772/*************************************
1773 *
1774 *  Driver initalization
1775 *
1776 *************************************/
1777
1778static DRIVER_INIT( neogeo )
1779{
1780}
1781
1782
1783ROM_START( aes )
1784   ROM_REGION16_BE( 0x80000, "mainbios", 0 )
1785   ROM_SYSTEM_BIOS( 0, "jap-aes",   "Japan AES" )
1786   ROMX_LOAD("neo-po.bin",  0x00000, 0x020000, CRC(16d0c132) SHA1(4e4a440cae46f3889d20234aebd7f8d5f522e22c), ROM_GROUPWORD | ROM_REVERSE | ROM_BIOS(1))   /* AES Console (Japan) Bios */
1787   ROM_SYSTEM_BIOS( 1, "asia-aes",   "Asia AES" )
1788   ROMX_LOAD("neo-epo.bin", 0x00000, 0x020000, CRC(d27a71f1) SHA1(1b3b22092f30c4d1b2c15f04d1670eb1e9fbea07), ROM_GROUPWORD | ROM_REVERSE | ROM_BIOS(2))   /* AES Console (Asia?) Bios */
1789//  ROM_SYSTEM_BIOS( 2, "uni-bios_2_3","Universe Bios (Hack, Ver. 2.3)" )
1790//  ROMX_LOAD( "uni-bios_2_3.rom",  0x00000, 0x020000, CRC(27664eb5) SHA1(5b02900a3ccf3df168bdcfc98458136fd2b92ac0), ROM_GROUPWORD | ROM_REVERSE | ROM_BIOS(3) ) /* Universe Bios v2.3 (hack) */
1791
1792   ROM_REGION( 0x200000, "maincpu", ROMREGION_ERASEFF )
1793
1794   ROM_REGION( 0x20000, "audiobios", 0 )
1795   ROM_LOAD( "sm1.sm1", 0x00000, 0x20000, CRC(94416d67) SHA1(42f9d7ddd6c0931fd64226a60dc73602b2819dcf) )
1796
1797   ROM_REGION( 0x90000, "audiocpu", ROMREGION_ERASEFF )
1798
1799   ROM_REGION( 0x20000, "zoomy", 0 )
1800   ROM_LOAD( "000-lo.lo", 0x00000, 0x20000, CRC(5a86cff2) SHA1(5992277debadeb64d1c1c64b0a92d9293eaf7e4a) )
1801
1802   ROM_REGION( 0x20000, "fixedbios", 0 )
1803   ROM_LOAD( "sfix.sfix", 0x000000, 0x20000, CRC(c2ea0cfd) SHA1(fd4a618cdcdbf849374f0a50dd8efe9dbab706c3) )
1804
1805   ROM_REGION( 0x20000, "fixed", ROMREGION_ERASEFF )
1806
1807   ROM_REGION( 0x1000000, "ymsnd", ROMREGION_ERASEFF )
1808
1809   ROM_REGION( 0x1000000, "ymsnd.deltat", ROMREGION_ERASEFF )
1810
1811   ROM_REGION( 0x900000, "sprites", ROMREGION_ERASEFF )
1812ROM_END
1813
1814ROM_START( neocd )
1815   ROM_REGION16_BE( 0x100000, "mainbios", 0 )
1816   ROM_LOAD16_WORD_SWAP( "top-sp1.bin",    0x00000, 0x80000, CRC(19f0ad1a) SHA1(b3e2f8467e9a642c122428d075024a9bd1fe0679) )
1817
1818   ROM_REGION( 0x200000, "maincpu", ROMREGION_ERASEFF )
1819
1820   ROM_REGION( 0x100000, "audiobios", ROMREGION_ERASEFF )
1821
1822   ROM_REGION( 0x10000, "audiocpu", ROMREGION_ERASEFF )
1823
1824   ROM_REGION( 0x20000, "zoomy", 0 )
1825   ROM_LOAD( "000-lo.lo", 0x00000, 0x20000, CRC(5a86cff2) SHA1(5992277debadeb64d1c1c64b0a92d9293eaf7e4a) )
1826
1827   ROM_REGION( 0x20000, "fixedbios", ROMREGION_ERASEFF )
1828
1829   ROM_REGION( 0x20000, "fixed", ROMREGION_ERASEFF )
1830
1831   ROM_REGION( 0x400000, "ymsnd", ROMREGION_ERASEFF )
1832
1833//    NO_DELTAT_REGION
1834
1835   ROM_REGION( 0x400000, "sprites", ROMREGION_ERASEFF )
1836ROM_END
1837
1838ROM_START( neocdz )
1839   ROM_REGION16_BE( 0x100000, "mainbios", 0 )
1840   ROM_LOAD16_WORD_SWAP( "neocd.bin",    0x00000, 0x80000, CRC(df9de490) SHA1(7bb26d1e5d1e930515219cb18bcde5b7b23e2eda) )
1841
1842   ROM_REGION( 0x200000, "maincpu", ROMREGION_ERASEFF )
1843
1844   ROM_REGION( 0x20000, "audiobios", ROMREGION_ERASEFF )
1845
1846   ROM_REGION( 0x10000, "audiocpu", ROMREGION_ERASEFF )
1847
1848   ROM_REGION( 0x20000, "zoomy", 0 )
1849   ROM_LOAD( "000-lo.lo", 0x00000, 0x20000, CRC(5a86cff2) SHA1(5992277debadeb64d1c1c64b0a92d9293eaf7e4a) )
1850
1851   ROM_REGION( 0x20000, "fixedbios", ROMREGION_ERASEFF )
1852
1853   ROM_REGION( 0x20000, "fixed", ROMREGION_ERASEFF )
1854
1855   ROM_REGION( 0x400000, "ymsnd", ROMREGION_ERASEFF )
1856
1857//    NO_DELTAT_REGION
1858
1859   ROM_REGION( 0x400000, "sprites", ROMREGION_ERASEFF )
1860ROM_END
1861
1862/*    YEAR  NAME  PARENT COMPAT MACHINE INPUT  INIT     COMPANY      FULLNAME            FLAGS */
1863CONS( 1990, aes,    0,   0,   aes,      aes,   neogeo,  "SNK", "Neo-Geo AES", 0)
1864CONS( 1994, neocd,  aes, 0,   neocd,    aes,   neogeo,  "SNK", "Neo-Geo CD", GAME_NOT_WORKING )
1865CONS( 1996, neocdz, aes, 0,   neocd,    aes,   neogeo,  "SNK", "Neo-Geo CDZ", GAME_NOT_WORKING )
src/mame/drivers/nes.c
r0r11461
1/***************************************************************************
2
3  nes.c
4
5  Driver file to handle emulation of the Nintendo Entertainment System (Famicom).
6
7  MESS driver by Brad Oliver (bradman@pobox.com), NES sound code by Matt Conte.
8  Based in part on the old xNes code, by Nicolas Hamel, Chuck Mason, Brad Oliver,
9  Richard Bannister and Jeff Mitchell.
10
11***************************************************************************/
12
13#include "emu.h"
14#include "video/ppu2c0x.h"
15#include "machine/nes_mmc.h"
16#include "includes/nes.h"
17#include "cpu/m6502/m6502.h"
18#include "imagedev/cartslot.h"
19#include "sound/nes_apu.h"
20#include "imagedev/flopdrv.h"
21#include "formats/nes_dsk.h"
22
23
24static READ8_DEVICE_HANDLER( psg_4015_r )
25{
26   return nes_psg_r(device, 0x15);
27}
28
29static WRITE8_DEVICE_HANDLER( psg_4015_w )
30{
31   nes_psg_w(device, 0x15, data);
32}
33
34static WRITE8_DEVICE_HANDLER( psg_4017_w )
35{
36   nes_psg_w(device, 0x17, data);
37}
38
39static WRITE8_HANDLER(nes_vh_sprite_dma_w)
40{
41   nes_state *state = space->machine().driver_data<nes_state>();
42   ppu2c0x_spriteram_dma(space, state->m_ppu, data);
43}
44
45static ADDRESS_MAP_START( nes_map, AS_PROGRAM, 8 )
46   AM_RANGE(0x0000, 0x07ff) AM_RAM AM_MIRROR(0x1800)               /* RAM */
47   AM_RANGE(0x2000, 0x3fff) AM_DEVREADWRITE("ppu", ppu2c0x_r, ppu2c0x_w)      /* PPU registers */
48   AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE("nessound", nes_psg_r, nes_psg_w)      /* PSG primary registers */
49   AM_RANGE(0x4014, 0x4014) AM_WRITE(nes_vh_sprite_dma_w)            /* stupid address space hole */
50   AM_RANGE(0x4015, 0x4015) AM_DEVREADWRITE("nessound", psg_4015_r, psg_4015_w)      /* PSG status / first control register */
51   AM_RANGE(0x4016, 0x4016) AM_READWRITE(nes_IN0_r, nes_IN0_w)         /* IN0 - input port 1 */
52   AM_RANGE(0x4017, 0x4017) AM_READ(nes_IN1_r)                     /* IN1 - input port 2 */
53   AM_RANGE(0x4017, 0x4017) AM_DEVWRITE("nessound", psg_4017_w)      /* PSG second control register */
54   AM_RANGE(0x4100, 0x5fff) AM_READWRITE(nes_low_mapper_r, nes_low_mapper_w)   /* Perform unholy acts on the machine */
55ADDRESS_MAP_END
56
57
58static INPUT_PORTS_START( nes_controllers )
59   PORT_START("CTRLSEL")  /* Select Controller Type */
60   PORT_CATEGORY_CLASS( 0x000f, 0x0001, "P1 Controller")
61   PORT_CATEGORY_ITEM(  0x0000, "Unconnected",      0 )
62   PORT_CATEGORY_ITEM(  0x0001, "Gamepad",         1 )
63   PORT_CATEGORY_ITEM(  0x0002, "Zapper",         5 )
64   PORT_CATEGORY_ITEM(  0x0006, "Crazy Climber pad", 10 )
65   PORT_CATEGORY_CLASS( 0x00f0, 0x0010, "P2 Controller")
66   PORT_CATEGORY_ITEM(  0x0000, "Unconnected",      0 )
67   PORT_CATEGORY_ITEM(  0x0010, "Gamepad",         2 )
68   PORT_CATEGORY_ITEM(  0x0030, "Zapper",         6 )
69   PORT_CATEGORY_ITEM(  0x0040, "Arkanoid paddle",   7 )
70//  PORT_CATEGORY_ITEM(  0x0050, "Family Trainer",  11 )
71   PORT_CATEGORY_CLASS( 0x0f00, 0x0000, "P3 Controller")
72   PORT_CATEGORY_ITEM(  0x0000, "Unconnected",      0 )
73   PORT_CATEGORY_ITEM(  0x0100, "Gamepad",         3 )
74   PORT_CATEGORY_CLASS( 0xf000, 0x0000, "P4 Controller")
75   PORT_CATEGORY_ITEM(  0x0000, "Unconnected",      0 )
76   PORT_CATEGORY_ITEM(  0x1000, "Gamepad",         4 )
77
78   PORT_START("PAD1")   /* Joypad 1 */
79   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P1 A") PORT_CATEGORY(1) PORT_PLAYER(1)
80   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P1 B") PORT_CATEGORY(1) PORT_PLAYER(1)
81   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_CATEGORY(1) PORT_PLAYER(1)
82   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_START ) PORT_CATEGORY(1) PORT_PLAYER(1)
83   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_CATEGORY(1) PORT_PLAYER(1)
84   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_CATEGORY(1) PORT_PLAYER(1)
85   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_CATEGORY(1) PORT_PLAYER(1)
86   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_CATEGORY(1) PORT_PLAYER(1)
87
88   PORT_START("PAD2")   /* Joypad 2 */
89   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P2 A") PORT_CATEGORY(2) PORT_PLAYER(2)
90   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P2 B") PORT_CATEGORY(2) PORT_PLAYER(2)
91   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_CATEGORY(2) PORT_PLAYER(2)
92   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_START ) PORT_CATEGORY(2) PORT_PLAYER(2)
93   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_CATEGORY(2) PORT_PLAYER(2)
94   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_CATEGORY(2) PORT_PLAYER(2)
95   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_CATEGORY(2) PORT_PLAYER(2)
96   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_CATEGORY(2) PORT_PLAYER(2)
97
98   PORT_START("PAD3")   /* Joypad 3 */
99   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P3 A") PORT_CATEGORY(3) PORT_PLAYER(3)
100   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P3 B") PORT_CATEGORY(3) PORT_PLAYER(3)
101   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_CATEGORY(3) PORT_PLAYER(3)
102   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_START ) PORT_CATEGORY(3) PORT_PLAYER(3)
103   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_CATEGORY(3) PORT_PLAYER(3)
104   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_CATEGORY(3) PORT_PLAYER(3)
105   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_CATEGORY(3) PORT_PLAYER(3)
106   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_CATEGORY(3) PORT_PLAYER(3)
107
108   PORT_START("PAD4")   /* Joypad 4 */
109   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P4 A") PORT_CATEGORY(4) PORT_PLAYER(4)
110   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P4 B") PORT_CATEGORY(4) PORT_PLAYER(4)
111   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_CATEGORY(4) PORT_PLAYER(4)
112   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_START ) PORT_CATEGORY(4) PORT_PLAYER(4)
113   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_CATEGORY(4) PORT_PLAYER(4)
114   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_CATEGORY(4) PORT_PLAYER(4)
115   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_CATEGORY(4) PORT_PLAYER(4)
116   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_CATEGORY(4) PORT_PLAYER(4)
117
118   PORT_START("ZAPPER1_X")  /* P1 zapper */
119   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(70) PORT_KEYDELTA(30) PORT_MINMAX(0,255)                                          PORT_CATEGORY(5) PORT_PLAYER(1)
120   PORT_START("ZAPPER1_Y")  /* P1 zapper */
121   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(50) PORT_KEYDELTA(30) PORT_MINMAX(0,255)                                          PORT_CATEGORY(5) PORT_PLAYER(1)
122   PORT_START("ZAPPER1_T")  /* P1 zapper trigger */
123   PORT_BIT( 0x03, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("P1 Lightgun Trigger") PORT_CATEGORY(5) PORT_PLAYER(1)
124
125   PORT_START("ZAPPER2_X")  /* P2 zapper */
126   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(70) PORT_KEYDELTA(30) PORT_MINMAX(0,255 )                                          PORT_CATEGORY(6) PORT_PLAYER(2)
127   PORT_START("ZAPPER2_Y")  /* P2 zapper */
128   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(50) PORT_KEYDELTA(30) PORT_MINMAX(0,255 )                                          PORT_CATEGORY(6) PORT_PLAYER(2)
129   PORT_START("ZAPPER2_T")  /* P2 zapper trigger */
130   PORT_BIT( 0x03, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("P2 Lightgun Trigger") PORT_CATEGORY(6) PORT_PLAYER(2)
131
132   PORT_START("PADDLE")  /* Arkanoid paddle */
133   PORT_BIT( 0xff, 0x7f, IPT_PADDLE) PORT_SENSITIVITY(25) PORT_KEYDELTA(3) PORT_MINMAX(0x62,0xf2)                                                   PORT_CATEGORY(7)
134
135   PORT_START("CC_LEFT")
136   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED ) PORT_CATEGORY(10) PORT_PLAYER(1)
137   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNUSED ) PORT_CATEGORY(10) PORT_PLAYER(1)
138   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_CATEGORY(10) PORT_PLAYER(1)
139   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_START ) PORT_CATEGORY(10) PORT_PLAYER(1)
140   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICKLEFT_UP ) PORT_CATEGORY(10) PORT_PLAYER(1)
141   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICKLEFT_DOWN ) PORT_CATEGORY(10) PORT_PLAYER(1)
142   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICKLEFT_LEFT ) PORT_CATEGORY(10) PORT_PLAYER(1)
143   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICKLEFT_RIGHT ) PORT_CATEGORY(10) PORT_PLAYER(1)
144
145   PORT_START("CC_RIGHT")
146   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED ) PORT_CATEGORY(10) PORT_PLAYER(1)
147   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNUSED ) PORT_CATEGORY(10) PORT_PLAYER(1)
148   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED ) PORT_CATEGORY(10) PORT_PLAYER(1)
149   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED ) PORT_CATEGORY(10) PORT_PLAYER(1)
150   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICKRIGHT_UP ) PORT_CATEGORY(10) PORT_PLAYER(1)
151   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICKRIGHT_DOWN ) PORT_CATEGORY(10) PORT_PLAYER(1)
152   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICKRIGHT_LEFT ) PORT_CATEGORY(10) PORT_PLAYER(1)
153   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICKRIGHT_RIGHT ) PORT_CATEGORY(10) PORT_PLAYER(1)
154
155INPUT_PORTS_END
156
157static INPUT_PORTS_START( nes )
158   PORT_INCLUDE( nes_controllers )
159
160   PORT_START("CONFIG")  /* configuration */
161   PORT_CONFNAME( 0x01, 0x00, "Draw Top/Bottom 8 Lines")
162   PORT_CONFSETTING(    0x01, DEF_STR(No) )
163   PORT_CONFSETTING(    0x00, DEF_STR(Yes) )
164   PORT_CONFNAME( 0x02, 0x00, "Enforce 8 Sprites/line")
165   PORT_CONFSETTING(    0x02, DEF_STR(No) )
166   PORT_CONFSETTING(    0x00, DEF_STR(Yes) )
167INPUT_PORTS_END
168
169static INPUT_PORTS_START( famicom )
170   PORT_INCLUDE( nes_controllers )
171
172   PORT_START("FLIPDISK") /* fake keys */
173   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("Change Disk Side")
174INPUT_PORTS_END
175
176static INPUT_PORTS_START( fc_keyboard )
177   PORT_START("FCKEY0")
178   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F8) PORT_CHAR(UCHAR_MAMEKEY(F8))
179   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)
180   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR('[')
181   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_BACKSLASH)   PORT_CHAR(']')
182   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_NAME("Kana")
183   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_RSHIFT)
184   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_BACKSLASH2)   PORT_CHAR('\\')
185   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_NAME("Stop") PORT_CODE(KEYCODE_BACKSPACE)
186
187   PORT_START("FCKEY1")
188   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F7) PORT_CHAR(UCHAR_MAMEKEY(F7))
189   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_OPENBRACE)   PORT_CHAR('@')
190   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_COLON)   PORT_CHAR(':')
191   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_QUOTE)   PORT_CHAR(';')
192   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CHAR('_')
193   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CHAR('/')
194   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_MINUS)   PORT_CHAR('-')
195   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_EQUALS)   PORT_CHAR('^')
196
197   PORT_START("FCKEY2")
198   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F6) PORT_CHAR(UCHAR_MAMEKEY(F6))
199   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_O)   PORT_CHAR('O')
200   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_L)   PORT_CHAR('L')
201   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_K)   PORT_CHAR('K')
202   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_STOP)   PORT_CHAR('.')
203   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_COMMA)   PORT_CHAR(',')
204   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_P)   PORT_CHAR('P')
205   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_0)   PORT_CHAR('0')
206
207   PORT_START("FCKEY3")
208   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F5) PORT_CHAR(UCHAR_MAMEKEY(F5))
209   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_I)   PORT_CHAR('I')
210   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_U)   PORT_CHAR('U')
211   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_J)   PORT_CHAR('J')
212   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_M)   PORT_CHAR('M')
213   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_N)   PORT_CHAR('N')
214   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_9)   PORT_CHAR('9')
215   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_8)   PORT_CHAR('8')
216
217   PORT_START("FCKEY4")
218   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F4) PORT_CHAR(UCHAR_MAMEKEY(F4))
219   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_Y)   PORT_CHAR('Y')
220   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_G)   PORT_CHAR('G')
221   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_H)   PORT_CHAR('H')
222   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_B)   PORT_CHAR('B')
223   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_V)   PORT_CHAR('V')
224   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_7)   PORT_CHAR('7')
225   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_6)   PORT_CHAR('6')
226
227   PORT_START("FCKEY5")
228   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F3) PORT_CHAR(UCHAR_MAMEKEY(F3))
229   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_T)   PORT_CHAR('T')
230   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_R)   PORT_CHAR('R')
231   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_D)   PORT_CHAR('D')
232   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F)   PORT_CHAR('F')
233   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_C)   PORT_CHAR('C')
234   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_5)   PORT_CHAR('5')
235   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_4)   PORT_CHAR('4')
236
237   PORT_START("FCKEY6")
238   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F2) PORT_CHAR(UCHAR_MAMEKEY(F2))
239   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_W)   PORT_CHAR('W')
240   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_S)   PORT_CHAR('S')
241   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_A)   PORT_CHAR('A')
242   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_X)   PORT_CHAR('X')
243   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_Z)   PORT_CHAR('Z')
244   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_E)   PORT_CHAR('E')
245   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_3)   PORT_CHAR('3')
246
247   PORT_START("FCKEY7")
248   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F1) PORT_CHAR(UCHAR_MAMEKEY(F1))
249   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_TAB) PORT_CHAR(UCHAR_MAMEKEY(ESC))
250   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_Q)   PORT_CHAR('Q')
251   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_LCONTROL)      PORT_CHAR(UCHAR_SHIFT_2)
252   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_LSHIFT)      PORT_CHAR(UCHAR_SHIFT_1)
253   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_NAME("Grph") PORT_CODE(KEYCODE_LALT)
254   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_1)   PORT_CHAR('1')
255   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_2)   PORT_CHAR('2')
256
257   PORT_START("FCKEY8")
258   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_NAME("Clr")
259   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_UP)   PORT_CHAR(UCHAR_MAMEKEY(UP))
260   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_RIGHT) PORT_CHAR(UCHAR_MAMEKEY(RIGHT))
261   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_LEFT) PORT_CHAR(UCHAR_MAMEKEY(LEFT))
262   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_DOWN) PORT_CHAR(UCHAR_MAMEKEY(DOWN))
263   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_SPACE)      PORT_CHAR(' ')
264   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_NAME("Del") PORT_CODE(KEYCODE_DEL)
265   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_NAME("Ins") PORT_CODE(KEYCODE_INSERT)
266
267INPUT_PORTS_END
268
269static INPUT_PORTS_START( subor_keyboard )
270   PORT_START("SUBKEY0")
271   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_4)   PORT_CHAR('4')
272   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_G)   PORT_CHAR('G')
273   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F)   PORT_CHAR('F')
274   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_C)   PORT_CHAR('C')
275   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F2) PORT_CHAR(UCHAR_MAMEKEY(F2))
276   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_E)   PORT_CHAR('E')
277   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_5)   PORT_CHAR('5')
278   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_V)   PORT_CHAR('V')
279
280   PORT_START("SUBKEY1")
281   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_2)   PORT_CHAR('2')
282   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_D)   PORT_CHAR('D')
283   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_S)   PORT_CHAR('S')
284   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_END) PORT_CHAR(UCHAR_MAMEKEY(END))
285   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F1) PORT_CHAR(UCHAR_MAMEKEY(F1))
286   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_W)   PORT_CHAR('W')
287   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_3)   PORT_CHAR('3')
288   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_X)   PORT_CHAR('X')
289
290   PORT_START("SUBKEY2")
291   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_INSERT) PORT_CHAR(UCHAR_MAMEKEY(INSERT))
292   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_BACKSPACE)   PORT_CHAR(8)
293   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_NAME("NEXT")
294   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_RIGHT) PORT_CHAR(UCHAR_MAMEKEY(RIGHT))
295   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F8) PORT_CHAR(UCHAR_MAMEKEY(F8))
296   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_NAME("PRIOR")
297   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_DEL) PORT_CHAR(UCHAR_MAMEKEY(DEL))
298   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_HOME) PORT_CHAR(UCHAR_MAMEKEY(HOME))
299
300   PORT_START("SUBKEY3")
301   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_9)   PORT_CHAR('9')
302   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_I)   PORT_CHAR('I')
303   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_L)   PORT_CHAR('L')
304   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_COMMA)   PORT_CHAR(',')
305   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F5) PORT_CHAR(UCHAR_MAMEKEY(F5))
306   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_O)   PORT_CHAR('O')
307   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_0)   PORT_CHAR('0')
308   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_STOP)   PORT_CHAR('.')
309
310   PORT_START("SUBKEY4")
311   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR(']')
312   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_ENTER)   PORT_CHAR(13)
313   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_UP) PORT_CHAR(UCHAR_MAMEKEY(UP))
314   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_LEFT) PORT_CHAR(UCHAR_MAMEKEY(LEFT))
315   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F7) PORT_CHAR(UCHAR_MAMEKEY(F7))
316   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_OPENBRACE)   PORT_CHAR('[')
317   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_BACKSLASH)   PORT_CHAR('\\')
318   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_DOWN) PORT_CHAR(UCHAR_MAMEKEY(DOWN))
319
320   PORT_START("SUBKEY5")
321   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_Q)   PORT_CHAR('Q')
322   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_CAPSLOCK) PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
323   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_Z)   PORT_CHAR('Z')
324   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_TAB)   PORT_CHAR('\t')
325   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_ESC) PORT_CHAR(UCHAR_MAMEKEY(ESC))
326   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_A)   PORT_CHAR('A')
327   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_1)   PORT_CHAR('1')
328   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_LCONTROL)      PORT_CHAR(UCHAR_SHIFT_2)
329
330   PORT_START("SUBKEY6")
331   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_7)   PORT_CHAR('7')
332   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_Y)   PORT_CHAR('Y')
333   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_K)   PORT_CHAR('K')
334   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_M)   PORT_CHAR('M')
335   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F4) PORT_CHAR(UCHAR_MAMEKEY(F4))
336   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_U)   PORT_CHAR('U')
337   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_8)   PORT_CHAR('8')
338   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_J)   PORT_CHAR('J')
339
340   PORT_START("SUBKEY7")
341   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_MINUS)   PORT_CHAR('-')
342   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_COLON)   PORT_CHAR(':')
343   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_QUOTE)   PORT_CHAR('\'')
344   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_SLASH)   PORT_CHAR('/')
345   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F6) PORT_CHAR(UCHAR_MAMEKEY(F6))
346   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_P)      PORT_CHAR('P')
347   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_EQUALS)   PORT_CHAR('=')
348   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_LSHIFT)   PORT_CHAR(UCHAR_SHIFT_1)
349
350   PORT_START("SUBKEY8")
351   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_T)   PORT_CHAR('T')
352   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_H)   PORT_CHAR('H')
353   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_N)   PORT_CHAR('N')
354   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_SPACE)   PORT_CHAR(' ')
355   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F3) PORT_CHAR(UCHAR_MAMEKEY(F3))
356   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_R)   PORT_CHAR('R')
357   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_6)   PORT_CHAR('6')
358   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_B)   PORT_CHAR('B')
359
360   PORT_START("SUBKEY9")
361   PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNUSED ) PORT_CATEGORY(9)
362
363   PORT_START("SUBKEY10")
364   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_NAME("LMENU")
365   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_4_PAD)   PORT_CHAR(UCHAR_MAMEKEY(4_PAD))
366   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_7_PAD)   PORT_CHAR(UCHAR_MAMEKEY(7_PAD))
367   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F11)      PORT_CHAR(UCHAR_MAMEKEY(F11))
368   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F12)      PORT_CHAR(UCHAR_MAMEKEY(F12))
369   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_1_PAD)   PORT_CHAR(UCHAR_MAMEKEY(1_PAD))
370   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_2_PAD)   PORT_CHAR(UCHAR_MAMEKEY(2_PAD))
371   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_8_PAD)   PORT_CHAR(UCHAR_MAMEKEY(8_PAD))
372
373   PORT_START("SUBKEY11")
374   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_MINUS_PAD)PORT_CHAR(UCHAR_MAMEKEY(MINUS_PAD))
375   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_PLUS_PAD)   PORT_CHAR(UCHAR_MAMEKEY(PLUS_PAD))
376   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_ASTERISK)   PORT_CHAR(UCHAR_MAMEKEY(ASTERISK))
377   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_9_PAD)   PORT_CHAR(UCHAR_MAMEKEY(9_PAD))
378   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F10) PORT_CHAR(UCHAR_MAMEKEY(F10))
379   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_5_PAD)   PORT_CHAR(UCHAR_MAMEKEY(5_PAD))
380   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_SLASH_PAD)PORT_CHAR(UCHAR_MAMEKEY(SLASH_PAD))
381   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_NUMLOCK)   PORT_CHAR(UCHAR_MAMEKEY(NUMLOCK))
382
383   PORT_START("SUBKEY12")
384   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_TILDE)   PORT_CHAR('`')
385   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_6_PAD)   PORT_CHAR(UCHAR_MAMEKEY(6_PAD))
386   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_NAME("PAUSE")
387   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_NAME("SPACE2")
388   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F9) PORT_CHAR(UCHAR_MAMEKEY(F9))
389   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_3_PAD)   PORT_CHAR(UCHAR_MAMEKEY(3_PAD))
390   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_NAME("Keypad .") PORT_CODE(KEYCODE_DEL_PAD)
391   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_0_PAD)   PORT_CHAR(UCHAR_MAMEKEY(0_PAD))
392
393INPUT_PORTS_END
394
395static INPUT_PORTS_START( famikey )
396   PORT_INCLUDE( famicom )
397   PORT_INCLUDE( fc_keyboard )
398   PORT_INCLUDE( subor_keyboard )
399
400   PORT_MODIFY("CTRLSEL")  /* Select Controller Type */
401   PORT_CATEGORY_CLASS( 0x000f, 0x0004, "P1 Controller")
402   PORT_CATEGORY_ITEM(  0x0000, "Unconnected",      0 )
403   PORT_CATEGORY_ITEM(  0x0001, "Gamepad",         1 )
404   PORT_CATEGORY_ITEM(  0x0002, "Zapper",         5 )
405   PORT_CATEGORY_ITEM(  0x0006, "Crazy Climber pad", 10 )
406   PORT_CATEGORY_ITEM(  0x0007, "FC Keyboard",      8 )
407   PORT_CATEGORY_ITEM(  0x0008, "Subor Keyboard",   9 )
408   PORT_CATEGORY_CLASS( 0x00f0, 0x0010, "P2 Controller")
409   PORT_CATEGORY_ITEM(  0x0000, "Unconnected",      0 )
410   PORT_CATEGORY_ITEM(  0x0010, "Gamepad",         2 )
411   PORT_CATEGORY_ITEM(  0x0030, "Zapper",         6 )
412   PORT_CATEGORY_ITEM(  0x0040, "Arkanoid paddle",   7 )
413//  PORT_CATEGORY_ITEM(  0x0050, "Family Trainer",  11 )
414   PORT_CATEGORY_CLASS( 0x0f00, 0x0000, "P3 Controller")
415   PORT_CATEGORY_ITEM(  0x0000, "Unconnected",      0 )
416   PORT_CATEGORY_ITEM(  0x0100, "Gamepad",         3 )
417   PORT_CATEGORY_CLASS( 0xf000, 0x0000, "P4 Controller")
418   PORT_CATEGORY_ITEM(  0x0000, "Unconnected",      0 )
419   PORT_CATEGORY_ITEM(  0x1000, "Gamepad",         4 )
420INPUT_PORTS_END
421
422#ifdef UNUSED_FUNCTION
423/* This layout is not changed at runtime */
424gfx_layout nes_vram_charlayout =
425{
426    8,8,    /* 8*8 characters */
427    512,    /* 512 characters */
428    2,  /* 2 bits per pixel */
429    { 8*8, 0 }, /* the two bitplanes are separated */
430    { 0, 1, 2, 3, 4, 5, 6, 7 },
431    { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
432    16*8    /* every char takes 16 consecutive bytes */
433};
434#endif
435
436static const nes_interface nes_apu_interface =
437{
438   "maincpu"
439};
440
441
442static void ppu_nmi(device_t *device, int *ppu_regs)
443{
444   cputag_set_input_line(device->machine(), "maincpu", INPUT_LINE_NMI, PULSE_LINE);
445}
446
447
448static const ppu2c0x_interface nes_ppu_interface =
449{
450   0,
451   0,
452   PPU_MIRROR_NONE,
453   ppu_nmi
454};
455
456static const floppy_config nes_floppy_config =
457{
458   DEVCB_NULL,
459   DEVCB_NULL,
460   DEVCB_NULL,
461   DEVCB_NULL,
462   DEVCB_NULL,
463   FLOPPY_STANDARD_5_25_DSHD,
464   FLOPPY_OPTIONS_NAME(nes_only),
465   NULL
466};
467
468
469static MACHINE_CONFIG_START( nes, nes_state )
470   /* basic machine hardware */
471   MCFG_CPU_ADD("maincpu", N2A03, NTSC_CLOCK)
472   MCFG_CPU_PROGRAM_MAP(nes_map)
473
474   MCFG_MACHINE_START( nes )
475   MCFG_MACHINE_RESET( nes )
476
477   MCFG_SCREEN_ADD("screen", RASTER)
478   MCFG_SCREEN_REFRESH_RATE(60.098)
479   // This isn't used so much to calulate the vblank duration (the PPU code tracks that manually) but to determine
480   // the number of cycles in each scanline for the PPU scanline timer. Since the PPU has 20 vblank scanlines + 2
481   // non-rendering scanlines, we compensate. This ends up being 2500 cycles for the non-rendering portion, 2273
482   // cycles for the actual vblank period.
483   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC((113.66/(NTSC_CLOCK/1000000)) * (PPU_VBLANK_LAST_SCANLINE_NTSC-PPU_VBLANK_FIRST_SCANLINE+1+2)))
484   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
485   MCFG_SCREEN_SIZE(32*8, 262)
486   MCFG_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 0*8, 30*8-1)
487   MCFG_SCREEN_UPDATE(nes)
488
489   MCFG_PALETTE_INIT(nes)
490   MCFG_VIDEO_START(nes)
491
492   MCFG_PALETTE_LENGTH(4*16*8)
493
494   MCFG_PPU2C02_ADD( "ppu", nes_ppu_interface )
495
496   /* sound hardware */
497   MCFG_SPEAKER_STANDARD_MONO("mono")
498   MCFG_SOUND_ADD("nessound", NES, NTSC_CLOCK)
499   MCFG_SOUND_CONFIG(nes_apu_interface)
500   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90)
501
502   MCFG_CARTSLOT_ADD("cart")
503   MCFG_CARTSLOT_EXTENSION_LIST("nes,unf")
504   MCFG_CARTSLOT_MANDATORY
505   MCFG_CARTSLOT_INTERFACE("nes_cart")
506   MCFG_CARTSLOT_LOAD(nes_cart)
507   MCFG_CARTSLOT_PARTIALHASH(nes_partialhash)
508   MCFG_SOFTWARE_LIST_ADD("cart_list","nes")
509MACHINE_CONFIG_END
510
511static MACHINE_CONFIG_DERIVED( nespal, nes )
512
513   /* basic machine hardware */
514   MCFG_CPU_MODIFY( "maincpu" )
515   MCFG_CPU_CLOCK( PAL_CLOCK )
516
517   MCFG_DEVICE_REMOVE( "ppu" )
518   MCFG_PPU2C07_ADD( "ppu", nes_ppu_interface )
519
520   /* video hardware */
521   MCFG_SCREEN_MODIFY("screen")
522   MCFG_SCREEN_REFRESH_RATE(53.355)
523   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC((106.53/(PAL_CLOCK/1000000)) * (PPU_VBLANK_LAST_SCANLINE_PAL-PPU_VBLANK_FIRST_SCANLINE+1+2)))
524   MCFG_VIDEO_START(nes)
525
526   /* sound hardware */
527   MCFG_SOUND_REPLACE("nessound", NES, PAL_CLOCK)
528   MCFG_SOUND_CONFIG(nes_apu_interface)
529   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90)
530MACHINE_CONFIG_END
531
532static MACHINE_CONFIG_DERIVED( dendy, nes )
533
534   /* basic machine hardware */
535   MCFG_CPU_MODIFY( "maincpu" )
536   MCFG_CPU_CLOCK( 26601712/15 ) /* 26.601712MHz / 15 == 1.77344746666... MHz */
537
538   MCFG_DEVICE_REMOVE( "ppu" )
539   MCFG_PPU2C07_ADD( "ppu", nes_ppu_interface )
540
541   /* video hardware */
542   MCFG_SCREEN_MODIFY("screen")
543   MCFG_SCREEN_REFRESH_RATE(50.00697796827)
544   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC((106.53/(PAL_CLOCK/1000000)) * (PPU_VBLANK_LAST_SCANLINE_PAL-PPU_VBLANK_FIRST_SCANLINE+1+2)))
545   MCFG_VIDEO_START(nes)
546
547   /* sound hardware */
548   MCFG_SOUND_REPLACE("nessound", NES, 26601712/15) /* 26.601712MHz / 15 == 1.77344746666... MHz */
549   MCFG_SOUND_CONFIG(nes_apu_interface)
550   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90)
551MACHINE_CONFIG_END
552
553static MACHINE_CONFIG_DERIVED( famicom, nes )
554
555   MCFG_CARTSLOT_MODIFY("cart")
556   MCFG_CARTSLOT_EXTENSION_LIST("nes,unf")
557   MCFG_CARTSLOT_NOT_MANDATORY
558   MCFG_CARTSLOT_LOAD(nes_cart)
559   MCFG_CARTSLOT_PARTIALHASH(nes_partialhash)
560
561   MCFG_FLOPPY_DRIVE_ADD(FLOPPY_0, nes_floppy_config)
562MACHINE_CONFIG_END
563
564
565/* rom regions are just place-holders: they get removed and re-allocated when a cart is loaded */
566ROM_START( nes )
567   ROM_REGION( 0x10000, "maincpu", ROMREGION_ERASE00 )  /* Main RAM + program banks */
568   ROM_REGION( 0x2000,  "gfx1", ROMREGION_ERASE00 )  /* VROM */
569   ROM_REGION( 0x4000,  "gfx2", ROMREGION_ERASE00 )  /* VRAM */
570   ROM_REGION( 0x800,   "gfx3", ROMREGION_ERASE00 )  /* CI RAM */
571ROM_END
572
573ROM_START( nespal )
574   ROM_REGION( 0x10000, "maincpu", ROMREGION_ERASE00 )  /* Main RAM + program banks */
575   ROM_REGION( 0x2000,  "gfx1", ROMREGION_ERASE00 )  /* VROM */
576   ROM_REGION( 0x4000,  "gfx2", ROMREGION_ERASE00 )  /* VRAM */
577   ROM_REGION( 0x800,   "gfx3", ROMREGION_ERASE00 )  /* CI RAM */
578ROM_END
579
580ROM_START( famicom )
581   ROM_REGION( 0x10000, "maincpu", 0 )  /* Main RAM + program banks */
582   ROM_LOAD_OPTIONAL( "disksys.rom", 0xe000, 0x2000, CRC(5e607dcf) SHA1(57fe1bdee955bb48d357e463ccbf129496930b62) )
583
584   ROM_REGION( 0x2000,  "gfx1", ROMREGION_ERASE00 )  /* VROM */
585   ROM_REGION( 0x4000,  "gfx2", ROMREGION_ERASE00 )  /* VRAM */
586   ROM_REGION( 0x800,   "gfx3", ROMREGION_ERASE00 )  /* CI RAM */
587ROM_END
588
589#define rom_fami_key rom_famicom
590
591ROM_START( famitwin )
592   ROM_REGION( 0x10000, "maincpu", 0 )  /* Main RAM + program banks */
593   ROM_LOAD_OPTIONAL( "disksyst.rom", 0xe000, 0x2000, CRC(4df24a6c) SHA1(e4e41472c454f928e53eb10e0509bf7d1146ecc1) )
594
595   ROM_REGION( 0x2000,  "gfx1", ROMREGION_ERASE00 )  /* VROM */
596   ROM_REGION( 0x4000,  "gfx2", ROMREGION_ERASE00 )  /* VRAM */
597   ROM_REGION( 0x800,   "gfx3", ROMREGION_ERASE00 )  /* CI RAM */
598ROM_END
599
600ROM_START( m82 )
601   ROM_REGION( 0x14000, "maincpu", 0 )  /* Main RAM + program banks */
602   /* Banks to be mapped at 0xe000? More investigations needed... */
603   ROM_LOAD( "m82_v1_0.bin", 0x10000, 0x4000, CRC(7d56840a) SHA1(cbd2d14fa073273ba58367758f40d67fd8a9106d) )
604
605   ROM_REGION( 0x2000,  "gfx1", ROMREGION_ERASE00 )  /* VROM */
606   ROM_REGION( 0x4000,  "gfx2", ROMREGION_ERASE00 )  /* VRAM */
607   ROM_REGION( 0x800,   "gfx3", ROMREGION_ERASE00 )  /* CI RAM */
608ROM_END
609
610// see http://www.disgruntleddesigner.com/chrisc/drpcjr/index.html
611// and http://www.disgruntleddesigner.com/chrisc/drpcjr/DrPCJrMemMap.txt
612ROM_START( drpcjr )
613   ROM_REGION( 0x18000, "maincpu", 0 )  /* Main RAM + program banks */
614   /* 4 banks to be mapped in 0xe000-0xffff (or 8 banks to be mapped in 0xe000-0xefff & 0xf000-0xffff).
615    Banks selected by writing at 0x4180 */
616   ROM_LOAD("drpcjr_bios.bin", 0x10000, 0x8000, CRC(c8fbef89) SHA1(2cb0a817b31400cdf27817d09bae7e69f41b062b) )   // bios vers. 1.0a
617   // Not sure if we should support this: hacked version 1.5a by Chris Covell with bugfixes and GameGenie support
618//  ROM_LOAD("drpcjr_v1_5_gg.bin", 0x10000, 0x8000, CRC(98f2033b) SHA1(93c114da787a19279d1a46667c2f69b49e25d4f1) )
619
620   ROM_REGION( 0x2000,  "gfx1", ROMREGION_ERASE00 )  /* VROM */
621   ROM_REGION( 0x4000,  "gfx2", ROMREGION_ERASE00 )  /* VRAM */
622   ROM_REGION( 0x800,   "gfx3", ROMREGION_ERASE00 )  /* CI RAM */
623ROM_END
624
625ROM_START( dendy )
626   ROM_REGION( 0x10000, "maincpu", ROMREGION_ERASE00 )  /* Main RAM + program banks */
627   ROM_REGION( 0x2000,  "gfx1", ROMREGION_ERASE00 )  /* VROM */
628   ROM_REGION( 0x4000,  "gfx2", ROMREGION_ERASE00 )  /* VRAM */
629   ROM_REGION( 0x800,   "gfx3", ROMREGION_ERASE00 )  /* CI RAM */
630ROM_END
631
632/***************************************************************************
633
634  Game driver(s)
635
636***************************************************************************/
637
638/*     YEAR  NAME      PARENT  COMPAT MACHINE   INPUT    INIT    COMPANY       FULLNAME */
639CONS( 1985, nes,       0,      0,     nes,      nes,     0,       "Nintendo",  "Nintendo Entertainment System / Famicom (NTSC)", GAME_IMPERFECT_GRAPHICS )
640CONS( 1987, nespal,    nes,    0,     nespal,   nes,     0,       "Nintendo",  "Nintendo Entertainment System (PAL)", GAME_IMPERFECT_GRAPHICS )
641CONS( 1983, famicom,   nes,    0,     famicom,  famicom, famicom, "Nintendo",  "Famicom (w/ Disk System add-on)", GAME_IMPERFECT_GRAPHICS )
642CONS( 1983, fami_key,  nes,    0,     famicom,  famikey, famicom, "Nintendo",  "Famicom (w/ Disk System add-on + Keyboard add-on)", GAME_IMPERFECT_GRAPHICS )
643CONS( 1986, famitwin,  nes,    0,     famicom,  famicom, famicom, "Sharp",     "Famicom Twin", GAME_IMPERFECT_GRAPHICS )
644CONS( 198?, m82,       nes,    0,     nes,      nes,     0,       "Nintendo",  "M82 Display Unit", GAME_IMPERFECT_GRAPHICS )
645CONS( 1996, drpcjr,    nes,    0,     famicom,  famicom, famicom, "Bung",      "Doctor PC Jr", GAME_IMPERFECT_GRAPHICS )
646CONS( 1992, dendy,     nes,    0,     dendy,    nes,     0,       "Steepler",  "Dendy Classic", GAME_IMPERFECT_GRAPHICS )
src/mame/drivers/snes.c
r0r11461
1/***************************************************************************
2
3  snes.c
4
5  Driver file to handle emulation of the Nintendo Super NES.
6
7  R. Belmont
8  Anthony Kruize
9  Angelo Salese
10  Fabio Priuli
11  byuu
12  Based on the original MESS driver by Lee Hammerton (aka Savoury Snax)
13
14  Driver is preliminary right now.
15
16  The memory map included below is setup in a way to make it easier to handle
17  Mode 20 and Mode 21 ROMs.
18
19  Todo (in no particular order):
20    - Fix additional sound bugs
21    - Emulate extra chips - superfx, dsp2, sa-1 etc.
22    - Add horizontal mosaic, hi-res. interlaced etc to video emulation.
23    - Fix support for Mode 7. (In Progress)
24    - Handle interleaved roms (maybe even multi-part roms, but how?)
25    - Add support for running at 3.58 MHz at the appropriate time.
26    - I'm sure there's lots more ...
27
28***************************************************************************/
29
30#include "emu.h"
31#include "audio/snes_snd.h"
32#include "cpu/spc700/spc700.h"
33#include "cpu/superfx/superfx.h"
34#include "cpu/g65816/g65816.h"
35#include "cpu/upd7725/upd7725.h"
36#include "includes/snes.h"
37#include "machine/snescart.h"
38#include "crsshair.h"
39
40#define MAX_SNES_CART_SIZE 0x600000
41
42/*************************************
43 *
44 *  Memory handlers
45 *
46 *************************************/
47
48static READ8_DEVICE_HANDLER( spc_ram_100_r )
49{
50   return spc_ram_r(device, offset + 0x100);
51}
52
53static WRITE8_DEVICE_HANDLER( spc_ram_100_w )
54{
55   spc_ram_w(device, offset + 0x100, data);
56}
57
58/*************************************
59 *
60 *  Address maps
61 *
62 *************************************/
63
64static ADDRESS_MAP_START( snes_map, AS_PROGRAM, 8)
65   AM_RANGE(0x000000, 0x2fffff) AM_READWRITE(snes_r_bank1, snes_w_bank1)   /* I/O and ROM (repeats for each bank) */
66   AM_RANGE(0x300000, 0x3fffff) AM_READWRITE(snes_r_bank2, snes_w_bank2)   /* I/O and ROM (repeats for each bank) */
67   AM_RANGE(0x400000, 0x5fffff) AM_READ(snes_r_bank3)      /* ROM (and reserved in Mode 20) */
68   AM_RANGE(0x600000, 0x6fffff) AM_READWRITE(snes_r_bank4, snes_w_bank4)   /* used by Mode 20 DSP-1 */
69   AM_RANGE(0x700000, 0x7dffff) AM_READWRITE(snes_r_bank5, snes_w_bank5)
70   AM_RANGE(0x7e0000, 0x7fffff) AM_RAM               /* 8KB Low RAM, 24KB High RAM, 96KB Expanded RAM */
71   AM_RANGE(0x800000, 0xbfffff) AM_READWRITE(snes_r_bank6, snes_w_bank6)   /* Mirror and ROM */
72   AM_RANGE(0xc00000, 0xffffff) AM_READWRITE(snes_r_bank7, snes_w_bank7)   /* Mirror and ROM */
73ADDRESS_MAP_END
74
75static ADDRESS_MAP_START( superfx_map, AS_PROGRAM, 8)
76   AM_RANGE(0x000000, 0x3fffff) AM_READWRITE(superfx_r_bank1, superfx_w_bank1)
77   AM_RANGE(0x400000, 0x5fffff) AM_READWRITE(superfx_r_bank2, superfx_w_bank2)
78   AM_RANGE(0x600000, 0x7dffff) AM_READWRITE(superfx_r_bank3, superfx_w_bank3)
79   AM_RANGE(0x800000, 0xbfffff) AM_READWRITE(superfx_r_bank1, superfx_w_bank1)
80   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(superfx_r_bank2, superfx_w_bank2)
81   AM_RANGE(0xe00000, 0xffffff) AM_READWRITE(superfx_r_bank3, superfx_w_bank3)
82ADDRESS_MAP_END
83
84static ADDRESS_MAP_START( spc_map, AS_PROGRAM, 8)
85   AM_RANGE(0x0000, 0x00ef) AM_DEVREADWRITE("spc700", spc_ram_r, spc_ram_w)   /* lower 32k ram */
86   AM_RANGE(0x00f0, 0x00ff) AM_DEVREADWRITE("spc700", spc_io_r, spc_io_w)     /* spc io */
87   AM_RANGE(0x0100, 0xffff) AM_DEVWRITE("spc700", spc_ram_100_w)
88   AM_RANGE(0x0100, 0xffbf) AM_DEVREAD("spc700", spc_ram_100_r)
89   AM_RANGE(0xffc0, 0xffff) AM_DEVREAD("spc700", spc_ipl_r)
90ADDRESS_MAP_END
91
92static ADDRESS_MAP_START( dsp_prg_map, AS_PROGRAM, 32 )
93   AM_RANGE(0x0000, 0x07ff) AM_ROM AM_REGION("dspprg", 0)
94ADDRESS_MAP_END
95
96static ADDRESS_MAP_START( dsp_data_map, AS_DATA, 16 )
97   AM_RANGE(0x0000, 0x03ff) AM_ROM AM_REGION("dspdata", 0)
98ADDRESS_MAP_END
99
100static ADDRESS_MAP_START( setadsp_prg_map, AS_PROGRAM, 32 )
101   AM_RANGE(0x0000, 0x3fff) AM_ROM AM_REGION("dspprg", 0)
102ADDRESS_MAP_END
103
104static ADDRESS_MAP_START( setadsp_data_map, AS_DATA, 16 )
105   AM_RANGE(0x0000, 0x07ff) AM_ROM AM_REGION("dspdata", 0)
106ADDRESS_MAP_END
107
108/*************************************
109 *
110 *  Input ports
111 *
112 *************************************/
113
114static CUSTOM_INPUT( snes_mouse_speed_input )
115{
116   snes_state *state = field->port->machine().driver_data<snes_state>();
117   int port = (FPTR)param;
118
119   if (snes_ram[OLDJOY1] & 0x1)
120   {
121      state->m_mouse[port].speed++;
122      if ((state->m_mouse[port].speed & 0x03) == 0x03)
123         state->m_mouse[port].speed = 0;
124   }
125
126   return state->m_mouse[port].speed;
127}
128
129static CUSTOM_INPUT( snes_superscope_offscreen_input )
130{
131   snes_state *state = field->port->machine().driver_data<snes_state>();
132   int port = (FPTR)param;
133   static const char *const portnames[2][3] =
134         {
135            { "SUPERSCOPE1", "SUPERSCOPE1_X", "SUPERSCOPE1_Y" },
136            { "SUPERSCOPE2", "SUPERSCOPE2_X", "SUPERSCOPE2_Y" },
137         };
138
139   INT16 x = input_port_read(field->port->machine(), portnames[port][1]);
140   INT16 y = input_port_read(field->port->machine(), portnames[port][2]);
141
142   /* these are the theoretical boundaries, but we currently are always onscreen... */
143   if (x < 0 || x >= SNES_SCR_WIDTH || y < 0 || y >= snes_ppu.beam.last_visible_line)
144      state->m_scope[port].offscreen = 1;
145   else
146      state->m_scope[port].offscreen = 0;
147
148   return state->m_scope[port].offscreen;
149}
150
151static TIMER_CALLBACK( lightgun_tick )
152{
153   if ((input_port_read(machine, "CTRLSEL") & 0x0f) == 0x03 || (input_port_read(machine, "CTRLSEL") & 0x0f) == 0x04)
154   {
155      /* enable lightpen crosshair */
156      crosshair_set_screen(machine, 0, CROSSHAIR_SCREEN_ALL);
157   }
158   else
159   {
160      /* disable lightpen crosshair */
161      crosshair_set_screen(machine, 0, CROSSHAIR_SCREEN_NONE);
162   }
163
164   if ((input_port_read(machine, "CTRLSEL") & 0xf0) == 0x30 || (input_port_read(machine, "CTRLSEL") & 0xf0) == 0x40)
165   {
166      /* enable lightpen crosshair */
167      crosshair_set_screen(machine, 1, CROSSHAIR_SCREEN_ALL);
168   }
169   else
170   {
171      /* disable lightpen crosshair */
172      crosshair_set_screen(machine, 1, CROSSHAIR_SCREEN_NONE);
173   }
174}
175
176
177static INPUT_PORTS_START( snes_joypads )
178   PORT_START("SERIAL1_DATA1_L")
179   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("P1 Button A") PORT_PLAYER(1) PORT_CATEGORY(11)
180   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("P1 Button X") PORT_PLAYER(1) PORT_CATEGORY(11)
181   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_NAME("P1 Button L") PORT_PLAYER(1) PORT_CATEGORY(11)
182   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_NAME("P1 Button R") PORT_PLAYER(1) PORT_CATEGORY(11)
183   PORT_START("SERIAL1_DATA1_H")
184   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P1 Button B") PORT_PLAYER(1) PORT_CATEGORY(11)
185   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P1 Button Y") PORT_PLAYER(1) PORT_CATEGORY(11)
186   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_PLAYER(1) PORT_CATEGORY(11)
187   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START1 ) PORT_PLAYER(1) PORT_CATEGORY(11)
188   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(1) PORT_CATEGORY(11)
189   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) PORT_CATEGORY(11)
190   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) PORT_CATEGORY(11)
191   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) PORT_CATEGORY(11)
192
193   PORT_START("SERIAL2_DATA1_L")
194   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("P2 Button A") PORT_PLAYER(2) PORT_CATEGORY(21)
195   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("P2 Button X") PORT_PLAYER(2) PORT_CATEGORY(21)
196   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_NAME("P2 Button L") PORT_PLAYER(2) PORT_CATEGORY(21)
197   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_NAME("P2 Button R") PORT_PLAYER(2) PORT_CATEGORY(21)
198   PORT_START("SERIAL2_DATA1_H")
199   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P2 Button B") PORT_PLAYER(2) PORT_CATEGORY(21)
200   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P2 Button Y") PORT_PLAYER(2) PORT_CATEGORY(21)
201   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_PLAYER(2) PORT_CATEGORY(21)
202   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START2 ) PORT_PLAYER(2) PORT_CATEGORY(21)
203   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(2) PORT_CATEGORY(21)
204   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) PORT_CATEGORY(21)
205   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) PORT_CATEGORY(21)
206   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) PORT_CATEGORY(21)
207
208   PORT_START("SERIAL1_DATA2_L")
209   PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNUSED )
210   PORT_START("SERIAL1_DATA2_H")
211   PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNUSED )
212
213   PORT_START("SERIAL2_DATA2_L")
214   PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNUSED )
215   PORT_START("SERIAL2_DATA2_H")
216   PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNUSED )
217INPUT_PORTS_END
218
219static INPUT_PORTS_START( snes_mouse )
220   PORT_START("MOUSE1")
221   /* bits 0,3 = mouse signature (must be 1) */
222   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
223   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNUSED )
224   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED )
225   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
226   /* bits 4,5 = mouse speed: 0 = slow, 1 = normal, 2 = fast, 3 = unused */
227   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(snes_mouse_speed_input, (void *)0)
228   /* bits 6,7 = mouse buttons */
229   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P1 Mouse Button Left") PORT_PLAYER(1) PORT_CATEGORY(12)
230   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P1 Mouse Button Right") PORT_PLAYER(1) PORT_CATEGORY(12)
231
232   PORT_START("MOUSE1_X")
233   PORT_BIT( 0xff, 0x00, IPT_TRACKBALL_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1) PORT_CATEGORY(12)
234
235   PORT_START("MOUSE1_Y")
236   PORT_BIT( 0xff, 0x00, IPT_TRACKBALL_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1) PORT_CATEGORY(12)
237
238   PORT_START("MOUSE2")
239   /* bits 0,3 = mouse signature (must be 1) */
240   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
241   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNUSED )
242   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED )
243   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
244   /* bits 4,5 = mouse speed: 0 = slow, 1 = normal, 2 = fast, 3 = unused */
245   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(snes_mouse_speed_input, (void *)1)
246   /* bits 6,7 = mouse buttons */
247   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P2 Mouse Button Left") PORT_PLAYER(2) PORT_CATEGORY(22)
248   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P2 Mouse Button Right") PORT_PLAYER(2) PORT_CATEGORY(22)
249
250   PORT_START("MOUSE2_X")
251   PORT_BIT( 0xff, 0x00, IPT_TRACKBALL_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(2) PORT_CATEGORY(22)
252
253   PORT_START("MOUSE2_Y")
254   PORT_BIT( 0xff, 0x00, IPT_TRACKBALL_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(2) PORT_CATEGORY(22)
255INPUT_PORTS_END
256
257static INPUT_PORTS_START( snes_superscope )
258   PORT_START("SUPERSCOPE1")
259   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED )   // Noise
260   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(snes_superscope_offscreen_input, (void *)0)
261   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED )
262   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
263   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("Port1 Superscope Pause") PORT_PLAYER(1) PORT_CATEGORY(13)
264   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("Port1 Superscope Turbo") PORT_TOGGLE PORT_PLAYER(1) PORT_CATEGORY(13)
265   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("Port1 Superscope Cursor") PORT_PLAYER(1) PORT_CATEGORY(13)
266   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("Port1 Superscope Fire") PORT_PLAYER(1) PORT_CATEGORY(13)
267
268   PORT_START("SUPERSCOPE1_X")
269   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X ) PORT_NAME("Port1 Superscope X Axis") PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_PLAYER(1) PORT_CATEGORY(13)
270
271   PORT_START("SUPERSCOPE1_Y")
272   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y) PORT_NAME("Port1 Superscope Y Axis") PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_PLAYER(1) PORT_CATEGORY(13)
273
274   PORT_START("SUPERSCOPE2")
275   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED )   // Noise
276   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(snes_superscope_offscreen_input, (void *)1)
277   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED )
278   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
279   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("Port2 Superscope Pause") PORT_PLAYER(2) PORT_CATEGORY(23)
280   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("Port2 Superscope Turbo") PORT_PLAYER(2) PORT_CATEGORY(23)
281   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("Port2 Superscope Cursor") PORT_PLAYER(2) PORT_CATEGORY(23)
282   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("Port2 Superscope Fire") PORT_PLAYER(2) PORT_CATEGORY(23)
283
284   PORT_START("SUPERSCOPE2_X")
285   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X ) PORT_NAME("Port2 Superscope X Axis") PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_PLAYER(2) PORT_CATEGORY(23)
286
287   PORT_START("SUPERSCOPE2_Y")
288   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y) PORT_NAME("Port2 Superscope Y Axis") PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_PLAYER(2) PORT_CATEGORY(23)
289INPUT_PORTS_END
290
291static INPUT_PORTS_START( snes )
292   PORT_START("CTRLSEL")  /* Select Controller Type */
293   PORT_CATEGORY_CLASS( 0x0f, 0x01, "P1 Controller")
294   PORT_CATEGORY_ITEM(  0x00, "Unconnected",      10 )
295   PORT_CATEGORY_ITEM(  0x01, "Gamepad",      11 )
296   PORT_CATEGORY_ITEM(  0x02, "Mouse",         12 )
297   PORT_CATEGORY_ITEM(  0x03, "Superscope",      13 )
298//  PORT_CATEGORY_ITEM(  0x04, "Justfier",      14 )
299//  PORT_CATEGORY_ITEM(  0x05, "Multitap",      15 )
300   PORT_CATEGORY_CLASS( 0xf0, 0x10, "P2 Controller")
301   PORT_CATEGORY_ITEM(  0x00, "Unconnected",      20 )
302   PORT_CATEGORY_ITEM(  0x10, "Gamepad",      21 )
303   PORT_CATEGORY_ITEM(  0x20, "Mouse",         22 )
304   PORT_CATEGORY_ITEM(  0x30, "Superscope",      23 )
305//  PORT_CATEGORY_ITEM(  0x40, "Justfier",      24 )
306//  PORT_CATEGORY_ITEM(  0x50, "Multitap",      25 )
307
308   PORT_INCLUDE(snes_joypads)
309   PORT_INCLUDE(snes_mouse)
310   PORT_INCLUDE(snes_superscope)
311
312   PORT_START("OPTIONS")
313   PORT_CONFNAME( 0x01, 0x00, "Hi-Res pixels blurring (TV effect)")
314   PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
315   PORT_CONFSETTING(    0x01, DEF_STR( On ) )
316
317#if SNES_LAYER_DEBUG
318   PORT_START("DEBUG1")
319   PORT_CONFNAME( 0x03, 0x00, "Select BG1 priority" )
320   PORT_CONFSETTING(    0x00, "All" )
321   PORT_CONFSETTING(    0x01, "BG1B (lower) only" )
322   PORT_CONFSETTING(    0x02, "BG1A (higher) only" )
323   PORT_CONFNAME( 0x0c, 0x00, "Select BG2 priority" )
324   PORT_CONFSETTING(    0x00, "All" )
325   PORT_CONFSETTING(    0x04, "BG2B (lower) only" )
326   PORT_CONFSETTING(    0x08, "BG2A (higher) only" )
327   PORT_CONFNAME( 0x30, 0x00, "Select BG3 priority" )
328   PORT_CONFSETTING(    0x00, "All" )
329   PORT_CONFSETTING(    0x10, "BG3B (lower) only" )
330   PORT_CONFSETTING(    0x20, "BG3A (higher) only" )
331   PORT_CONFNAME( 0xc0, 0x00, "Select BG4 priority" )
332   PORT_CONFSETTING(    0x00, "All" )
333   PORT_CONFSETTING(    0x40, "BG4B (lower) only" )
334   PORT_CONFSETTING(    0x80, "BG4A (higher) only" )
335
336   PORT_START("DEBUG2")
337   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 1") PORT_CODE(KEYCODE_1_PAD) PORT_TOGGLE
338   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 2") PORT_CODE(KEYCODE_2_PAD) PORT_TOGGLE
339   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 3") PORT_CODE(KEYCODE_3_PAD) PORT_TOGGLE
340   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 4") PORT_CODE(KEYCODE_4_PAD) PORT_TOGGLE
341   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Objects") PORT_CODE(KEYCODE_5_PAD) PORT_TOGGLE
342   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Main/Sub") PORT_CODE(KEYCODE_6_PAD) PORT_TOGGLE
343   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Color Math") PORT_CODE(KEYCODE_7_PAD) PORT_TOGGLE
344   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Windows") PORT_CODE(KEYCODE_8_PAD) PORT_TOGGLE
345
346   PORT_START("DEBUG3")
347   PORT_BIT( 0x4, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mosaic") PORT_CODE(KEYCODE_9_PAD) PORT_TOGGLE
348   PORT_CONFNAME( 0x70, 0x00, "Select OAM priority" )
349   PORT_CONFSETTING(    0x00, "All" )
350   PORT_CONFSETTING(    0x10, "OAM0 only" )
351   PORT_CONFSETTING(    0x20, "OAM1 only" )
352   PORT_CONFSETTING(    0x30, "OAM2 only" )
353   PORT_CONFSETTING(    0x40, "OAM3 only" )
354   PORT_CONFNAME( 0x80, 0x00, "Draw sprite in reverse order" )
355   PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
356   PORT_CONFSETTING(    0x80, DEF_STR( On ) )
357
358   PORT_START("DEBUG4")
359   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 0 draw") PORT_TOGGLE
360   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 1 draw") PORT_TOGGLE
361   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 2 draw") PORT_TOGGLE
362   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 3 draw") PORT_TOGGLE
363   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 4 draw") PORT_TOGGLE
364   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 5 draw") PORT_TOGGLE
365   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 6 draw") PORT_TOGGLE
366   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 7 draw") PORT_TOGGLE
367#endif
368INPUT_PORTS_END
369
370
371/*************************************
372 *
373 *  Input callbacks
374 *
375 *************************************/
376
377static void snes_gun_latch( running_machine &machine, INT16 x, INT16 y )
378{
379   /* these are the theoretical boundaries */
380   if (x < 0)
381      x = 0;
382   if (x > (SNES_SCR_WIDTH - 1))
383      x = SNES_SCR_WIDTH - 1;
384
385   if (y < 0)
386      y = 0;
387   if (y > (snes_ppu.beam.last_visible_line - 1))
388      y = snes_ppu.beam.last_visible_line - 1;
389
390   snes_ppu.beam.latch_horz = x;
391   snes_ppu.beam.latch_vert = y;
392   snes_ram[STAT78] |= 0x40;
393}
394
395static void snes_input_read_joy( running_machine &machine, int port )
396{
397   snes_state *state = machine.driver_data<snes_state>();
398   static const char *const portnames[2][4] =
399         {
400            { "SERIAL1_DATA1_L", "SERIAL1_DATA1_H", "SERIAL1_DATA2_L", "SERIAL1_DATA2_H" },
401            { "SERIAL2_DATA1_L", "SERIAL2_DATA1_H", "SERIAL2_DATA2_L", "SERIAL2_DATA2_H" },
402         };
403
404   state->m_data1[port] = input_port_read(machine, portnames[port][0]) | (input_port_read(machine, portnames[port][1]) << 8);
405   state->m_data2[port] = input_port_read(machine, portnames[port][2]) | (input_port_read(machine, portnames[port][3]) << 8);
406
407   // avoid sending signals that could crash games
408   // if left, no right
409   if (state->m_data1[port] & 0x200)
410      state->m_data1[port] &= ~0x100;
411   // if up, no down
412   if (state->m_data1[port] & 0x800)
413      state->m_data1[port] &= ~0x400;
414
415   state->m_joypad[port].buttons = state->m_data1[port];
416}
417
418static void snes_input_read_mouse( running_machine &machine, int port )
419{
420   snes_state *state = machine.driver_data<snes_state>();
421   INT16 var;
422   static const char *const portnames[2][3] =
423         {
424            { "MOUSE1", "MOUSE1_X", "MOUSE1_Y" },
425            { "MOUSE2", "MOUSE2_X", "MOUSE2_Y" },
426         };
427
428   state->m_mouse[port].buttons = input_port_read(machine, portnames[port][0]);
429   state->m_mouse[port].x = input_port_read(machine, portnames[port][1]);
430   state->m_mouse[port].y = input_port_read(machine, portnames[port][2]);
431   var = state->m_mouse[port].x - state->m_mouse[port].oldx;
432
433   if (var < -127)
434   {
435      state->m_mouse[port].deltax = 0xff;
436      state->m_mouse[port].oldx -= 127;
437   }
438   else if (var < 0)
439   {
440      state->m_mouse[port].deltax = 0x80 | (-var);
441      state->m_mouse[port].oldx = state->m_mouse[port].x;
442   }
443   else if (var > 127)
444   {
445      state->m_mouse[port].deltax = 0x7f;
446      state->m_mouse[port].oldx += 127;
447   }
448   else
449   {
450      state->m_mouse[port].deltax = var & 0xff;
451      state->m_mouse[port].oldx = state->m_mouse[port].x;
452   }
453
454   var = state->m_mouse[port].y - state->m_mouse[port].oldy;
455
456   if (var < -127)
457   {
458      state->m_mouse[port].deltay = 0xff;
459      state->m_mouse[port].oldy -= 127;
460   }
461   else if (var < 0)
462   {
463      state->m_mouse[port].deltay = 0x80 | (-var);
464      state->m_mouse[port].oldy = state->m_mouse[port].y;
465   }
466   else if (var > 127)
467   {
468      state->m_mouse[port].deltay = 0x7f;
469      state->m_mouse[port].oldy += 127;
470   }
471   else
472   {
473      state->m_mouse[port].deltay = var & 0xff;
474      state->m_mouse[port].oldy = state->m_mouse[port].y;
475   }
476
477   state->m_data1[port] = state->m_mouse[port].buttons | (0x00 << 8);
478   state->m_data2[port] = 0;
479}
480
481static void snes_input_read_superscope( running_machine &machine, int port )
482{
483   snes_state *state = machine.driver_data<snes_state>();
484   static const char *const portnames[2][3] =
485         {
486            { "SUPERSCOPE1", "SUPERSCOPE1_X", "SUPERSCOPE1_Y" },
487            { "SUPERSCOPE2", "SUPERSCOPE2_X", "SUPERSCOPE2_Y" },
488         };
489   UINT8 input;
490
491   /* first read input bits */
492   state->m_scope[port].x = input_port_read(machine, portnames[port][1]);
493   state->m_scope[port].y = input_port_read(machine, portnames[port][2]);
494   input = input_port_read(machine, portnames[port][0]);
495
496   /* then start elaborating input bits: only keep old turbo value */
497   state->m_scope[port].buttons &= 0x20;
498
499   /* set onscreen/offscreen */
500   state->m_scope[port].buttons |= BIT(input, 1);
501
502   /* turbo is a switch; toggle is edge sensitive */
503   if (BIT(input, 5) && !state->m_scope[port].turbo_lock)
504   {
505      state->m_scope[port].buttons ^= 0x20;
506      state->m_scope[port].turbo_lock = 1;
507   }
508   else if (!BIT(input, 5))
509      state->m_scope[port].turbo_lock = 0;
510
511   /* fire is a button; if turbo is active, trigger is level sensitive; otherwise it is edge sensitive */
512   if (BIT(input, 7) && (BIT(state->m_scope[port].buttons, 5) || !state->m_scope[port].fire_lock))
513   {
514      state->m_scope[port].buttons |= 0x80;
515      state->m_scope[port].fire_lock = 1;
516   }
517   else if (!BIT(input, 7))
518      state->m_scope[port].fire_lock = 0;
519
520   /* cursor is a button; it is always level sensitive */
521   state->m_scope[port].buttons |= BIT(input, 6);
522
523   /* pause is a button; it is always edge sensitive */
524   if (BIT(input, 4) && !state->m_scope[port].pause_lock)
525   {
526      state->m_scope[port].buttons |= 0x10;
527      state->m_scope[port].pause_lock = 1;
528   }
529   else if (!BIT(input, 4))
530      state->m_scope[port].pause_lock = 0;
531
532   /* If we have pressed fire or cursor and we are on-screen and SuperScope is in Port2, then latch video signal.
533    Notice that we only latch Port2 because its IOBit pin is connected to bit7 of the IO Port, while Port1 has
534    IOBit pin connected to bit6 of the IO Port, and the latter is not detected by the H/V Counters. In other
535    words, you can connect SuperScope to Port1, but there is no way SNES could detect its on-screen position */
536   if ((state->m_scope[port].buttons & 0xc0) && !(state->m_scope[port].buttons & 0x02) && port == 1)
537      snes_gun_latch(machine, state->m_scope[port].x, state->m_scope[port].y);
538
539   state->m_data1[port] = 0xff | (state->m_scope[port].buttons << 8);
540   state->m_data2[port] = 0;
541}
542
543static void snes_input_read( running_machine &machine )
544{
545   snes_state *state = machine.driver_data<snes_state>();
546   UINT8 ctrl1 = input_port_read(machine, "CTRLSEL") & 0x0f;
547   UINT8 ctrl2 = (input_port_read(machine, "CTRLSEL") & 0xf0) >> 4;
548
549   /* Check if lightgun has been chosen as input: if so, enable crosshair */
550   machine.scheduler().timer_set(attotime::zero, FUNC(lightgun_tick));
551
552   switch (ctrl1)
553   {
554   case 1:   /* SNES joypad */
555      snes_input_read_joy(machine, 0);
556      break;
557   case 2:   /* SNES Mouse */
558      snes_input_read_mouse(machine, 0);
559      break;
560   case 3:   /* SNES Superscope */
561      snes_input_read_superscope(machine, 0);
562      break;
563   case 0:   /* no controller in port1 */
564   default:
565      state->m_data1[0] = 0;
566      state->m_data2[0] = 0;
567      break;
568   }
569
570   switch (ctrl2)
571   {
572   case 1:   /* SNES joypad */
573      snes_input_read_joy(machine, 1);
574      break;
575   case 2:   /* SNES Mouse */
576      snes_input_read_mouse(machine, 1);
577      break;
578   case 3:   /* SNES Superscope */
579      snes_input_read_superscope(machine, 1);
580      break;
581   case 0:   /* no controller in port2 */
582   default:
583      state->m_data1[1] = 0;
584      state->m_data2[1] = 0;
585      break;
586   }
587
588   // is automatic reading on? if so, copy port data1/data2 to joy1l->joy4h
589   // this actually works like reading the first 16bits from oldjoy1/2 in reverse order
590   if (snes_ram[NMITIMEN] & 1)
591   {
592      state->m_joy1l = (state->m_data1[0] & 0x00ff) >> 0;
593      state->m_joy1h = (state->m_data1[0] & 0xff00) >> 8;
594      state->m_joy2l = (state->m_data1[1] & 0x00ff) >> 0;
595      state->m_joy2h = (state->m_data1[1] & 0xff00) >> 8;
596      state->m_joy3l = (state->m_data2[0] & 0x00ff) >> 0;
597      state->m_joy3h = (state->m_data2[0] & 0xff00) >> 8;
598      state->m_joy4l = (state->m_data2[1] & 0x00ff) >> 0;
599      state->m_joy4h = (state->m_data2[1] & 0xff00) >> 8;
600
601      // make sure read_idx starts returning all 1s because the auto-read reads it :-)
602      state->m_read_idx[0] = 16;
603      state->m_read_idx[1] = 16;
604   }
605
606}
607
608static UINT8 snes_oldjoy1_read( running_machine &machine )
609{
610   snes_state *state = machine.driver_data<snes_state>();
611   UINT8 ctrl1 = input_port_read(machine, "CTRLSEL") & 0x0f;
612   UINT8 res = 0;
613
614   switch (ctrl1)
615   {
616   case 1:   /* SNES joypad */
617      if (state->m_read_idx[0] >= 16)
618         res = 0x01;
619      else
620         res = (state->m_joypad[0].buttons >> (15 - state->m_read_idx[0]++)) & 0x01;
621      break;
622   case 2:   /* SNES Mouse */
623      if (state->m_read_idx[0] >= 32)
624         res = 0x01;
625      else if (state->m_read_idx[0] >= 24)
626         res = (state->m_mouse[0].deltax >> (31 - state->m_read_idx[0]++)) & 0x01;
627      else if (state->m_read_idx[0] >= 16)
628         res = (state->m_mouse[0].deltay >> (23 - state->m_read_idx[0]++)) & 0x01;
629      else if (state->m_read_idx[0] >= 8)
630         res = (state->m_mouse[0].buttons >> (15 - state->m_read_idx[0]++)) & 0x01;
631      else
632         res = 0;
633      break;
634   case 3:   /* SNES Superscope */
635      if (state->m_read_idx[0] >= 8)
636         res = 0x01;
637      else
638         res = (state->m_scope[0].buttons >> (7 - state->m_read_idx[0]++)) & 0x01;
639      break;
640   case 0:   /* no controller in port2 */
641   default:
642      break;
643   }
644
645   return res;
646}
647
648static UINT8 snes_oldjoy2_read( running_machine &machine )
649{
650   snes_state *state = machine.driver_data<snes_state>();
651   UINT8 ctrl2 = (input_port_read(machine, "CTRLSEL") & 0xf0) >> 4;
652   UINT8 res = 0;
653
654   switch (ctrl2)
655   {
656   case 1:   /* SNES joypad */
657      if (state->m_read_idx[1] >= 16)
658         res = 0x01;
659      else
660         res = (state->m_joypad[1].buttons >> (15 - state->m_read_idx[1]++)) & 0x01;
661      break;
662   case 2:   /* SNES Mouse */
663      if (state->m_read_idx[1] >= 32)
664         res = 0x01;
665      else if (state->m_read_idx[1] >= 24)
666         res = (state->m_mouse[1].deltax >> (31 - state->m_read_idx[1]++)) & 0x01;
667      else if (state->m_read_idx[1] >= 16)
668         res = (state->m_mouse[1].deltay >> (23 - state->m_read_idx[1]++)) & 0x01;
669      else if (state->m_read_idx[1] >= 8)
670         res = (state->m_mouse[1].buttons >> (15 - state->m_read_idx[1]++)) & 0x01;
671      else
672         res = 0;
673      break;
674   case 3:   /* SNES Superscope */
675      if (state->m_read_idx[1] >= 8)
676         res = 0x01;
677      else
678         res = (state->m_scope[1].buttons >> (7 - state->m_read_idx[1]++)) & 0x01;
679      break;
680   case 0:   /* no controller in port2 */
681   default:
682      break;
683   }
684
685   return res;
686}
687
688/*************************************
689 *
690 *  Machine driver
691 *
692 *************************************/
693
694static MACHINE_RESET( snes_mess )
695{
696   snes_state *state = machine.driver_data<snes_state>();
697
698   MACHINE_RESET_CALL(snes);
699
700   state->m_io_read = snes_input_read;
701   state->m_oldjoy1_read = snes_oldjoy1_read;
702   state->m_oldjoy2_read = snes_oldjoy2_read;
703}
704
705static MACHINE_CONFIG_START( snes_base, snes_state )
706
707   /* basic machine hardware */
708   MCFG_CPU_ADD("maincpu", _5A22, MCLK_NTSC)   /* 2.68 MHz, also 3.58 MHz */
709   MCFG_CPU_PROGRAM_MAP(snes_map)
710
711   MCFG_CPU_ADD("soundcpu", SPC700, 1024000)   /* 1.024 MHz */
712   MCFG_CPU_PROGRAM_MAP(spc_map)
713
714   //MCFG_QUANTUM_TIME(attotime::from_hz(48000))
715   MCFG_QUANTUM_PERFECT_CPU("maincpu")
716
717   MCFG_MACHINE_START(snes_mess)
718   MCFG_MACHINE_RESET(snes_mess)
719
720   /* video hardware */
721   MCFG_VIDEO_START(snes)
722
723   MCFG_SCREEN_ADD("screen", RASTER)
724   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
725   MCFG_SCREEN_RAW_PARAMS(DOTCLK_NTSC, SNES_HTOTAL, 0, SNES_SCR_WIDTH, SNES_VTOTAL_NTSC, 0, SNES_SCR_HEIGHT_NTSC)
726   MCFG_SCREEN_UPDATE(snes)
727
728   /* sound hardware */
729   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
730   MCFG_SOUND_ADD("spc700", SNES, 0)
731   MCFG_SOUND_ROUTE(0, "lspeaker", 1.00)
732   MCFG_SOUND_ROUTE(1, "rspeaker", 1.00)
733MACHINE_CONFIG_END
734
735static MACHINE_CONFIG_DERIVED( snes, snes_base )
736
737   MCFG_FRAGMENT_ADD(snes_cartslot)
738MACHINE_CONFIG_END
739
740static SUPERFX_CONFIG( snes_superfx_config )
741{
742   DEVCB_LINE(snes_extern_irq_w)   /* IRQ line from cart */
743};
744
745static MACHINE_CONFIG_DERIVED( snessfx, snes )
746
747   MCFG_CPU_ADD("superfx", SUPERFX, 21480000)   /* 21.48MHz */
748   MCFG_CPU_PROGRAM_MAP(superfx_map)
749   MCFG_CPU_CONFIG(snes_superfx_config)
750MACHINE_CONFIG_END
751
752static MACHINE_CONFIG_DERIVED( snesdsp, snes )
753
754   MCFG_CPU_ADD("dsp", UPD7725, 8000000)
755   MCFG_CPU_PROGRAM_MAP(dsp_prg_map)
756   MCFG_CPU_DATA_MAP(dsp_data_map)
757MACHINE_CONFIG_END
758
759static MACHINE_CONFIG_DERIVED( snesst10, snes )
760
761   MCFG_CPU_ADD("setadsp", UPD96050, 10000000)
762   MCFG_CPU_PROGRAM_MAP(setadsp_prg_map)
763   MCFG_CPU_DATA_MAP(setadsp_data_map)
764MACHINE_CONFIG_END
765
766static MACHINE_CONFIG_DERIVED( snesst11, snes )
767
768   MCFG_CPU_ADD("setadsp", UPD96050, 15000000)
769   MCFG_CPU_PROGRAM_MAP(setadsp_prg_map)
770   MCFG_CPU_DATA_MAP(setadsp_data_map)
771MACHINE_CONFIG_END
772
773static MACHINE_CONFIG_DERIVED( snespal, snes )
774   MCFG_CPU_MODIFY( "maincpu" )
775   MCFG_CPU_CLOCK( MCLK_PAL )
776
777   MCFG_SCREEN_MODIFY("screen")
778   MCFG_SCREEN_RAW_PARAMS(DOTCLK_PAL, SNES_HTOTAL, 0, SNES_SCR_WIDTH, SNES_VTOTAL_PAL, 0, SNES_SCR_HEIGHT_PAL)
779MACHINE_CONFIG_END
780
781static MACHINE_CONFIG_DERIVED( snespsfx, snespal )
782
783   MCFG_CPU_ADD("superfx", SUPERFX, 21480000)   /* 21.48MHz */
784   MCFG_CPU_PROGRAM_MAP(superfx_map)
785   MCFG_CPU_CONFIG(snes_superfx_config)
786MACHINE_CONFIG_END
787
788static MACHINE_CONFIG_DERIVED( snespdsp, snespal )
789
790   MCFG_CPU_ADD("dsp", UPD7725, 8000000)
791   MCFG_CPU_PROGRAM_MAP(dsp_prg_map)
792   MCFG_CPU_DATA_MAP(dsp_data_map)
793MACHINE_CONFIG_END
794
795static MACHINE_CONFIG_DERIVED( snesst, snes_base )
796
797   MCFG_MACHINE_START(snesst)
798
799   MCFG_FRAGMENT_ADD(sufami_cartslot)
800MACHINE_CONFIG_END
801
802static MACHINE_CONFIG_DERIVED( snesbsx, snes_base )
803
804   MCFG_FRAGMENT_ADD(bsx_cartslot)
805MACHINE_CONFIG_END
806
807
808/*************************************
809 *
810 *  ROM definition(s)
811 *
812 *************************************/
813
814ROM_START( snes )
815   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
816
817   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
818   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
819
820   ROM_REGION( 0x10000, "addons", ROMREGION_ERASE00 )      /* add-on chip ROMs (DSP, SFX, etc) */
821
822   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
823   ROM_REGION( 0x2000, "dspprg", ROMREGION_ERASEFF)
824   ROM_REGION( 0x800, "dspdata", ROMREGION_ERASEFF)
825ROM_END
826
827ROM_START( snesdsp )
828   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
829
830   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
831   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
832
833   ROM_REGION( 0x10000, "addons", 0 )      /* add-on chip ROMs (DSP, SFX, etc) */
834   ROM_LOAD( "dsp1b.bin", SNES_DSP1B_OFFSET, 0x002800, CRC(453557e0) SHA1(3a218b0e4572a8eba6d0121b17fdac9529609220) )
835   ROM_LOAD( "dsp1.bin",  SNES_DSP1_OFFSET,  0x002800, CRC(2838f9f5) SHA1(0a03ccb1fd2bea91151c745a4d1f217ae784f889) )
836   ROM_LOAD( "dsp2.bin",  SNES_DSP2_OFFSET,  0x002800, CRC(8e9fbd9b) SHA1(06dd9fcb118d18f6bbe234e013cb8780e06d6e63) )
837   ROM_LOAD( "dsp3.bin",  SNES_DSP3_OFFSET,  0x002800, CRC(6b86728a) SHA1(1b133741fad810eb7320c21ecfdd427d25a46da1) )
838   ROM_LOAD( "dsp4.bin",  SNES_DSP4_OFFSET,  0x002800, CRC(ce0c7783) SHA1(76fd25f7dc26c3b3f7868a3aa78c7684068713e5) )
839
840   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
841   ROM_REGION( 0x2000, "dspprg", ROMREGION_ERASEFF)
842   ROM_REGION( 0x800, "dspdata", ROMREGION_ERASEFF)
843ROM_END
844
845ROM_START( snesst10 )
846   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
847
848   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
849   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
850
851   ROM_REGION( 0x11000, "addons", 0 )      /* add-on chip ROMs (DSP, SFX, etc) */
852   ROM_LOAD( "st010.bin",    0x000000, 0x011000, CRC(aa11ee2d) SHA1(cc1984e989cb94e3dcbb5f99e085b5414e18a017) )
853
854   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
855   ROM_REGION( 0x10000, "dspprg", ROMREGION_ERASEFF)
856   ROM_REGION( 0x1000, "dspdata", ROMREGION_ERASEFF)
857ROM_END
858
859ROM_START( snesst11 )
860   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
861
862   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
863   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
864
865   ROM_REGION( 0x11000, "addons", 0 )      /* add-on chip ROMs (DSP, SFX, etc) */
866   ROM_LOAD( "st011.bin",    0x000000, 0x011000, CRC(34d2952c) SHA1(1375b8c1efc8cae4962b57dfe22f6b78e1ddacc8) )
867
868   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
869   ROM_REGION( 0x10000, "dspprg", ROMREGION_ERASEFF)
870   ROM_REGION( 0x1000, "dspdata", ROMREGION_ERASEFF)
871ROM_END
872
873ROM_START( snessfx )
874   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
875
876   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
877   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
878
879   ROM_REGION( 0x10000, "addons", ROMREGION_ERASE00 )      /* add-on chip ROMs (DSP, SFX, etc) */
880
881   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
882   ROM_REGION( 0x2000, "dspprg", ROMREGION_ERASEFF)
883   ROM_REGION( 0x800, "dspdata", ROMREGION_ERASEFF)
884ROM_END
885
886ROM_START( snespal )
887   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
888
889   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
890   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
891
892   ROM_REGION( 0x10000, "addons", ROMREGION_ERASE00 )      /* add-on chip ROMs (DSP, SFX, etc) */
893
894   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
895   ROM_REGION( 0x2000, "dspprg", ROMREGION_ERASEFF)
896   ROM_REGION( 0x800, "dspdata", ROMREGION_ERASEFF)
897ROM_END
898
899ROM_START( snespdsp )
900   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
901
902   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
903   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
904
905   ROM_REGION( 0x10000, "addons", 0 )      /* add-on chip ROMs (DSP, SFX, etc) */
906   ROM_LOAD( "dsp1b.bin", SNES_DSP1B_OFFSET, 0x002800, CRC(453557e0) SHA1(3a218b0e4572a8eba6d0121b17fdac9529609220) )
907   ROM_LOAD( "dsp1.bin",  SNES_DSP1_OFFSET,  0x002800, CRC(2838f9f5) SHA1(0a03ccb1fd2bea91151c745a4d1f217ae784f889) )
908   ROM_LOAD( "dsp2.bin",  SNES_DSP2_OFFSET,  0x002800, CRC(8e9fbd9b) SHA1(06dd9fcb118d18f6bbe234e013cb8780e06d6e63) )
909   ROM_LOAD( "dsp3.bin",  SNES_DSP3_OFFSET,  0x002800, CRC(6b86728a) SHA1(1b133741fad810eb7320c21ecfdd427d25a46da1) )
910   ROM_LOAD( "dsp4.bin",  SNES_DSP4_OFFSET,  0x002800, CRC(ce0c7783) SHA1(76fd25f7dc26c3b3f7868a3aa78c7684068713e5) )
911
912   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
913   ROM_REGION( 0x2000, "dspprg", ROMREGION_ERASEFF)
914   ROM_REGION( 0x800, "dspdata", ROMREGION_ERASEFF)
915ROM_END
916
917ROM_START( snespsfx )
918   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
919
920   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
921   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
922
923   ROM_REGION( 0x10000, "addons", ROMREGION_ERASE00 )      /* add-on chip ROMs (DSP, SFX, etc) */
924
925   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
926   ROM_REGION( 0x2000, "dspprg", ROMREGION_ERASEFF)
927   ROM_REGION( 0x800, "dspdata", ROMREGION_ERASEFF)
928ROM_END
929
930ROM_START( snesst )
931   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
932
933   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
934   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
935
936   ROM_REGION( 0x10000, "addons", ROMREGION_ERASE00 )      /* add-on chip ROMs (DSP, SFX, etc) */
937
938   ROM_REGION( 0x40000, "sufami", 0 )      /* add-on chip ROMs (DSP, SFX, etc) */
939   ROM_LOAD( "shvc-qh-0.bin", 0,   0x40000, CRC(9b4ca911) SHA1(ef86ea192eed03d5c413fdbbfd46043be1d7a127) )
940
941   ROM_REGION( MAX_SNES_CART_SIZE, "slot_a", ROMREGION_ERASE00 )
942   ROM_REGION( MAX_SNES_CART_SIZE, "slot_b", ROMREGION_ERASE00 )
943   ROM_REGION( 0x2000, "dspprg", ROMREGION_ERASEFF)
944   ROM_REGION( 0x800, "dspdata", ROMREGION_ERASEFF)
945ROM_END
946
947ROM_START( snesbsx )
948   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
949
950   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
951   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
952
953   ROM_REGION( 0x10000, "addons", 0 )      /* add-on chip ROMs (DSP, SFX, etc) */
954   ROM_LOAD( "dsp1b.bin", SNES_DSP1B_OFFSET, 0x002800, CRC(453557e0) SHA1(3a218b0e4572a8eba6d0121b17fdac9529609220) )
955   ROM_LOAD( "dsp1.bin",  SNES_DSP1_OFFSET,  0x002800, CRC(2838f9f5) SHA1(0a03ccb1fd2bea91151c745a4d1f217ae784f889) )
956   ROM_LOAD( "dsp2.bin",  SNES_DSP2_OFFSET,  0x002800, CRC(8e9fbd9b) SHA1(06dd9fcb118d18f6bbe234e013cb8780e06d6e63) )
957   ROM_LOAD( "dsp3.bin",  SNES_DSP3_OFFSET,  0x002800, CRC(6b86728a) SHA1(1b133741fad810eb7320c21ecfdd427d25a46da1) )
958   ROM_LOAD( "dsp4.bin",  SNES_DSP4_OFFSET,  0x002800, CRC(ce0c7783) SHA1(76fd25f7dc26c3b3f7868a3aa78c7684068713e5) )
959
960   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
961   ROM_REGION( MAX_SNES_CART_SIZE, "flash", ROMREGION_ERASE00 )
962   ROM_REGION( 0x2000, "dspprg", ROMREGION_ERASEFF)
963   ROM_REGION( 0x800, "dspdata", ROMREGION_ERASEFF)
964ROM_END
965
966
967
968/*************************************
969 *
970 *  Game driver(s)
971 *
972 *************************************/
973
974/*    YEAR  NAME      PARENT  COMPAT  MACHINE   INPUT  INIT          COMPANY     FULLNAME                                      FLAGS */
975CONS( 1989, snes,     0,      0,      snes,     snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System / Super Famicom (NTSC)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
976CONS( 1991, snespal,  snes,   0,      snespal,  snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System (PAL)",  GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
977
978// FIXME: the "hacked" drivers below, currently needed due to limitations in the core device design, should eventually be removed
979
980// These would require CPU to be added/removed depending on the cart which is loaded
981CONS( 1989, snesdsp,  snes,   0,      snesdsp,  snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System / Super Famicom (NTSC, w/DSP-x)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
982CONS( 1991, snespdsp, snes,   0,      snespdsp, snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System (PAL, w/DSP-x)",  GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
983CONS( 1989, snessfx,  snes,   0,      snessfx,  snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System / Super Famicom (NTSC, w/SuperFX)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
984CONS( 1991, snespsfx, snes,   0,      snespsfx, snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System (PAL, w/SuperFX)",  GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
985CONS( 1989, snesst10,  snes,   0,      snesst10,  snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System / Super Famicom (NTSC, w/ST-010)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
986CONS( 1989, snesst11,  snes,   0,      snesst11,  snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System / Super Famicom (NTSC, w/ST-011)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
987//CONS( 1989, snessa1,  snes,   0,      snessa1,  snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System / Super Famicom (NTSC, w/SA-1)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
988//CONS( 1991, snespsa1, snes,   0,      snespsa1, snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System (PAL, w/SA-1)",  GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
989
990// These would require cartslot to be added/removed depending on the cart which is loaded
991CONS( 1989, snesst,   snes,   0,      snesst,  snes,  snesst,       "Nintendo", "Super Nintendo Entertainment System / Super Famicom (NTSC, w/Sufami Turbo)", GAME_NOT_WORKING )
992CONS( 1989, snesbsx,  snes,   0,      snesbsx, snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System / Super Famicom (NTSC, w/BS-X Satellaview slotted cart)",  GAME_NOT_WORKING )
src/mame/drivers/a3000.c
r0r11461
1/***************************************************************************
2
3    Commodore Amiga 3000
4
5    Skeleton driver
6
7***************************************************************************/
8
9#include "emu.h"
10#include "cpu/m68000/m68000.h"
11
12
13class a3000_state : public driver_device
14{
15public:
16   a3000_state(const machine_config &mconfig, device_type type, const char *tag)
17      : driver_device(mconfig, type, tag) { }
18
19};
20
21
22
23/***************************************************************************
24    CONSTANTS
25***************************************************************************/
26
27#define XTAL_U104   XTAL_32MHz
28
29
30/***************************************************************************
31    ADDRESS MAPS
32***************************************************************************/
33
34static ADDRESS_MAP_START( a3000_mem, AS_PROGRAM, 32 )
35   ADDRESS_MAP_UNMAP_HIGH
36   AM_RANGE(0x000000, 0x1fffff) AM_RAMBANK("chipram")
37   AM_RANGE(0xf80000, 0xffffff) AM_ROM AM_REGION("kickstart", 0)
38ADDRESS_MAP_END
39
40
41/***************************************************************************
42    INPUT PORTS
43***************************************************************************/
44
45static INPUT_PORTS_START( a3000 )
46INPUT_PORTS_END
47
48
49/***************************************************************************
50    MACHINE DRIVERS
51***************************************************************************/
52
53static MACHINE_CONFIG_START( a3000, a3000_state )
54   MCFG_CPU_ADD("maincpu", M68030, XTAL_U104 / 2)
55   MCFG_CPU_PROGRAM_MAP(a3000_mem)
56
57   MCFG_SCREEN_ADD("screen", RASTER)
58   MCFG_SCREEN_REFRESH_RATE(60)
59   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
60   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
61   MCFG_SCREEN_SIZE(512*2, 312)
62   MCFG_SCREEN_VISIBLE_AREA((129-8-8)*2, (449+8-1+8)*2, 44-8, 300+8-1)
63MACHINE_CONFIG_END
64
65
66/***************************************************************************
67    ROM DEFINITIONS
68***************************************************************************/
69
70/* Note: I think those ROMs are correct, but they should be verified */
71ROM_START( a3000 )
72   ROM_REGION32_BE(0x80000, "kickstart", 0)
73   ROM_DEFAULT_BIOS("kick14")
74   ROM_SYSTEM_BIOS(0, "kick14", "Kickstart 1.4 (36.16)")
75   /* COPYRIGHT 1990 CAI // ALL RIGHTS RESERVED // ALPHA 5 ROM 0 CS=9713 */
76   ROMX_LOAD("390629-02.u182", 0x00000, 0x40000, CRC(58327536) SHA1(d1713d7f31474a5948e6d488e33686061cf3d1e2), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(1))
77   /* COPYRIGHT 1990 CAI // ALL RIGHTS RESERVED // ALPHA 5 ROM 1 CS=9B21 */
78   ROMX_LOAD("390630-02.u183", 0x00002, 0x40000, CRC(fe2f7fb9) SHA1(c05c9c52d014c66f9019152b3f2a2adc2c678794), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(1))
79   ROM_SYSTEM_BIOS(1, "kick204", "Kickstart 2.04 (37.175)")
80   ROMX_LOAD("390629-03.u182", 0x00000, 0x40000, CRC(a245dbdf) SHA1(83bab8e95d378b55b0c6ae6561385a96f638598f), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(2))
81   ROMX_LOAD("390630-03.u183", 0x00002, 0x40000, CRC(7db1332b) SHA1(48f14b31279da6757848df6feb5318818f8f576c), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(2))
82   ROM_SYSTEM_BIOS(2, "kick31", "Kickstart 3.1 (40.68)")
83   ROMX_LOAD("kick31.u182",    0x00000, 0x40000, CRC(286b9a0d) SHA1(6763a2258ec493f7408cf663110dae9a17803ad1), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(3))
84   ROMX_LOAD("kick31.u183",    0x00002, 0x40000, CRC(0b8cde6a) SHA1(5f02e97b48ebbba87d516a56b0400c6fc3434d8d), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(3))
85ROM_END
86
87
88/***************************************************************************
89    GAME DRIVERS
90***************************************************************************/
91
92/*    YEAR  NAME   PARENT  COMPAT  MACHINE  INPUT  INIT  COMPANY      FULLNAME      FLAGS */
93COMP( 1990, a3000, 0,      0,      a3000,   a3000, 0,    "Commodore Business Machines", "Amiga 3000", GAME_NOT_WORKING | GAME_NO_SOUND )
src/mame/drivers/atari400.c
r0r11461
1/******************************************************************************
2    Atari 400/800
3
4    MESS Driver
5
6    Juergen Buchmueller, June 1998
7
8    2009-05 FP changes:
9     Factored out MESS specific code from MAME
10     Added skeleton support for other XL/XE machines (VERY preliminary):
11     - a600xl based on maxaflex emulation in MAME
12     - a1200xl sharing a800xl code without BASIC
13     - a65xe, a65xea, a130xe, a800xe, xegs sharing a800xl code (and this is wrong
14      at least for xegs)
15     Added proper dumps and labels, thanks to Freddy Offenga researches (a few
16     are still marked BAD_DUMP while waiting for crc confirmation, since they
17     have been obtained by splitting whole dumps)
18
19     To Do:
20     - Find out why a600xl and a800xl don't work (xe machines should then follow)
21     - Investigate supported RAM sizes and OS versions in different models
22     - Implement differences between various models (currently most of the
23      XL/XE are exactly an a800xl, but this will change as soon as emulation
24      starts to work)
25     - Fix various keyboard differences
26     - Freddy emulation for 800XLF?
27     - Add support for proto boards and expansions (a1400xl, C/PM board, etc.)
28     - Clean up the whole driver + cart + floppy structure
29
30******************************************************************************/
31
32#include "emu.h"
33#include "deprecat.h"
34#include "cpu/m6502/m6502.h"
35#include "includes/atari.h"
36#include "machine/ataridev.h"
37#include "imagedev/cartslot.h"
38#include "sound/pokey.h"
39#include "machine/6821pia.h"
40#include "video/gtia.h"
41#include "sound/dac.h"
42#include "machine/ram.h"
43
44/******************************************************************************
45    Atari 800 memory map (preliminary)
46
47    ***************** read access *******************
48    range     short   description
49    0000-9FFF RAM     main memory
50    A000-BFFF RAM/ROM RAM or (banked) ROM cartridges
51    C000-CFFF ROM     unused or monitor ROM
52
53    ********* GTIA    ********************************
54
55    D000      m0pf    missile 0 playfield collisions
56    D001      m1pf    missile 1 playfield collisions
57    D002      m2pf    missile 2 playfield collisions
58    D003      m3pf    missile 3 playfield collisions
59    D004      p0pf    player 0 playfield collisions
60    D005      p1pf    player 1 playfield collisions
61    D006      p2pf    player 2 playfield collisions
62    D007      p3pf    player 3 playfield collisions
63    D008      m0pl    missile 0 player collisions
64    D009      m1pl    missile 1 player collisions
65    D00A      m2pl    missile 2 player collisions
66    D00B      m3pl    missile 3 player collisions
67    D00C      p0pl    player 0 player collisions
68    D00D      p1pl    player 1 player collisions
69    D00E      p2pl    player 2 player collisions
70    D00F      p3pl    player 3 player collisions
71    D010      but0    button stick 0
72    D011      but1    button stick 1
73    D012      but2    button stick 2
74    D013      but3    button stick 3
75    D014      xff     unused
76    D015      xff     unused
77    D016      xff     unused
78    D017      xff     unused
79    D018      xff     unused
80    D019      xff     unused
81    D01A      xff     unused
82    D01B      xff     unused
83    D01C      xff     unused
84    D01D      xff     unused
85    D01E      xff     unused
86    D01F      cons    console keys
87    D020-D0FF repeated 7 times
88
89    D100-D1FF xff
90
91    ********* POKEY   ********************************
92    D200      pot0    paddle 0
93    D201      pot1    paddle 1
94    D202      pot2    paddle 2
95    D203      pot3    paddle 3
96    D204      pot4    paddle 4
97    D205      pot5    paddle 5
98    D206      pot6    paddle 6
99    D207      pot7    paddle 7
100    D208      potb    all paddles
101    D209      kbcode  keyboard scan code
102    D20A      random  random number generator
103    D20B      xff     unused
104    D20C      xff     unused
105    D20D      serin   serial input
106    D20E      irqst   IRQ status
107    D20F      skstat  sk status
108    D210-D2FF repeated 15 times
109
110    ********* PIO     ********************************
111    D300      porta   read pio port A
112    D301      portb   read pio port B
113    D302      pactl   read pio port A control
114    D303      pbctl   read pio port B control
115    D304-D3FF repeated 63 times
116
117    ********* ANTIC   ********************************
118    D400      xff     unused
119    D401      xff     unused
120    D402      xff     unused
121    D403      xff     unused
122    D404      xff     unused
123    D405      xff     unused
124    D406      xff     unused
125    D407      xff     unused
126    D408      xff     unused
127    D409      xff     unused
128    D40A      xff     unused
129    D40B      vcount  vertical (scanline) counter
130    D40C      penh    light pen horizontal pos
131    D40D      penv    light pen vertical pos
132    D40E      xff     unused
133    D40F      nmist   NMI status
134
135    D500-D7FF xff     unused memory
136
137    D800-DFFF ROM     floating point ROM
138    E000-FFFF ROM     bios ROM
139
140    ***************** write access *******************
141    range     short   description
142    0000-9FFF RAM     main memory
143    A000-BFFF RAM/ROM RAM or (banked) ROM
144    C000-CFFF ROM     unused or monitor ROM
145
146    ********* GTIA    ********************************
147    D000      hposp0  player 0 horz position
148    D001      hposp1  player 1 horz position
149    D002      hposp2  player 2 horz position
150    D003      hposp3  player 3 horz position
151    D004      hposm0  missile 0 horz position
152    D005      hposm1  missile 0 horz position
153    D006      hposm2  missile 0 horz position
154    D007      hposm3  missile 0 horz position
155    D008      sizep0  size player 0
156    D009      sizep1  size player 0
157    D00A      sizep2  size player 0
158    D00B      sizep3  size player 0
159    D00C      sizem   size missiles
160    D00D      grafp0  graphics data for player 0
161    D00E      grafp1  graphics data for player 1
162    D00F      grafp2  graphics data for player 2
163    D010      grafp3  graphics data for player 3
164    D011      grafm   graphics data for missiles
165    D012      colpm0  color for player/missile 0
166    D013      colpm1  color for player/missile 1
167    D014      colpm2  color for player/missile 2
168    D015      colpm3  color for player/missile 3
169    D016      colpf0  color 0 playfield
170    D017      colpf1  color 1 playfield
171    D018      colpf2  color 2 playfield
172    D019      colpf3  color 3 playfield
173    D01A      colbk   background playfield
174    D01B      prior   priority select
175    D01C      vdelay  delay until vertical retrace
176    D01D      gractl  graphics control
177    D01E      hitclr  clear collisions
178    D01F      wcons   write console (speaker)
179    D020-D0FF repeated 7 times
180
181    D100-D1FF xff     unused
182
183    ********* POKEY   ********************************
184    D200      audf1   frequency audio chan #1
185    D201      audc1   control audio chan #1
186    D202      audf2   frequency audio chan #2
187    D203      audc2   control audio chan #2
188    D204      audf3   frequency audio chan #3
189    D205      audc3   control audio chan #3
190    D206      audf4   frequency audio chan #4
191    D207      audc4   control audio chan #4
192    D208      audctl  audio control
193    D209      stimer  start timer
194    D20A      skres   sk reset
195    D20B      potgo   start pot AD conversion
196    D20C      xff     unused
197    D20D      serout  serial output
198    D20E      irqen   IRQ enable
199    D20F      skctl   sk control
200    D210-D2FF repeated 15 times
201
202    ********* PIO     ********************************
203    D300      porta   write pio port A (output or mask)
204    D301      portb   write pio port B (output or mask)
205    D302      pactl   write pio port A control
206    D303      pbctl   write pio port B control
207    D304-D3FF         repeated
208
209    ********* ANTIC   ********************************
210    D400      dmactl  write DMA control
211    D401      chactl  write character control
212    D402      dlistl  write display list lo
213    D403      dlisth  write display list hi
214    D404      hscrol  write horz scroll
215    D405      vscrol  write vert scroll
216    D406      xff     unused
217    D407      pmbash  player/missile base addr hi
218    D408      xff     unused
219    D409      chbash  character generator base addr hi
220    D40A      wsync   wait for hsync
221    D40B      xff     unused
222    D40C      xff     unused
223    D40D      xff     unused
224    D40E      nmien   NMI enable
225    D40F      nmires  NMI reset
226
227    D500-D7FF xff     unused memory
228
229    D800-DFFF ROM     floating point ROM
230    E000-FFFF ROM     BIOS ROM
231******************************************************************************/
232
233/**************************************************************
234 *
235 * Memory maps
236 *
237 **************************************************************/
238
239
240static ADDRESS_MAP_START(a400_mem, AS_PROGRAM, 8)
241   AM_RANGE(0x0000, 0x9fff) AM_NOP   /* RAM installed at runtime */
242   AM_RANGE(0xa000, 0xbfff) AM_RAMBANK("a000")
243   AM_RANGE(0xc000, 0xcfff) AM_ROM
244   AM_RANGE(0xd000, 0xd0ff) AM_READWRITE(atari_gtia_r, atari_gtia_w)
245   AM_RANGE(0xd100, 0xd1ff) AM_NOP
246   AM_RANGE(0xd200, 0xd2ff) AM_DEVREADWRITE("pokey", pokey_r, pokey_w)
247   AM_RANGE(0xd300, 0xd3ff) AM_DEVREADWRITE_MODERN("pia", pia6821_device, read_alt, write_alt)
248   AM_RANGE(0xd400, 0xd4ff) AM_READWRITE(atari_antic_r, atari_antic_w)
249   AM_RANGE(0xd500, 0xd7ff) AM_NOP
250   AM_RANGE(0xd800, 0xffff) AM_ROM
251ADDRESS_MAP_END
252
253
254static ADDRESS_MAP_START(a800_mem, AS_PROGRAM, 8)
255   AM_RANGE(0x0000, 0x7fff) AM_RAMBANK("0000")
256   AM_RANGE(0x8000, 0x9fff) AM_RAMBANK("8000")
257   AM_RANGE(0xa000, 0xbfff) AM_RAMBANK("a000")
258   AM_RANGE(0xc000, 0xcfff) AM_ROM
259   AM_RANGE(0xd000, 0xd0ff) AM_READWRITE(atari_gtia_r, atari_gtia_w)
260   AM_RANGE(0xd100, 0xd1ff) AM_NOP
261   AM_RANGE(0xd200, 0xd2ff) AM_DEVREADWRITE("pokey", pokey_r, pokey_w)
262   AM_RANGE(0xd300, 0xd3ff) AM_DEVREADWRITE_MODERN("pia", pia6821_device, read_alt, write_alt)
263   AM_RANGE(0xd400, 0xd4ff) AM_READWRITE(atari_antic_r, atari_antic_w)
264   AM_RANGE(0xd500, 0xd7ff) AM_NOP
265   AM_RANGE(0xd800, 0xffff) AM_ROM
266ADDRESS_MAP_END
267
268
269static ADDRESS_MAP_START(a600xl_mem, AS_PROGRAM, 8)
270   AM_RANGE(0x0000, 0x3fff) AM_RAM
271   AM_RANGE(0x5000, 0x57ff) AM_ROM AM_REGION("maincpu", 0x5000)   /* self test */
272   AM_RANGE(0xa000, 0xbfff) AM_ROM   /* BASIC */
273   AM_RANGE(0xc000, 0xcfff) AM_ROM /* OS */
274   AM_RANGE(0xd000, 0xd0ff) AM_READWRITE(atari_gtia_r, atari_gtia_w)
275   AM_RANGE(0xd100, 0xd1ff) AM_NOP
276   AM_RANGE(0xd200, 0xd2ff) AM_DEVREADWRITE("pokey", pokey_r, pokey_w)
277   AM_RANGE(0xd300, 0xd3ff) AM_DEVREADWRITE_MODERN("pia", pia6821_device, read_alt, write_alt)
278   AM_RANGE(0xd400, 0xd4ff) AM_READWRITE(atari_antic_r, atari_antic_w)
279   AM_RANGE(0xd500, 0xd7ff) AM_NOP
280   AM_RANGE(0xd800, 0xffff) AM_ROM /* OS */
281ADDRESS_MAP_END
282
283
284static ADDRESS_MAP_START(a800xl_mem, AS_PROGRAM, 8)
285   AM_RANGE(0x0000, 0x4fff) AM_RAM
286   AM_RANGE(0x5000, 0x57ff) AM_RAMBANK("bank2")
287   AM_RANGE(0x5800, 0x9fff) AM_RAM
288   AM_RANGE(0xa000, 0xbfff) AM_RAMBANK("bank1")
289   AM_RANGE(0xc000, 0xcfff) AM_RAMBANK("bank3")
290   AM_RANGE(0xd000, 0xd0ff) AM_READWRITE(atari_gtia_r, atari_gtia_w)
291   AM_RANGE(0xd100, 0xd1ff) AM_NOP
292   AM_RANGE(0xd200, 0xd2ff) AM_DEVREADWRITE("pokey", pokey_r, pokey_w)
293   AM_RANGE(0xd300, 0xd3ff) AM_DEVREADWRITE_MODERN("pia", pia6821_device, read_alt, write_alt)
294   AM_RANGE(0xd400, 0xd4ff) AM_READWRITE(atari_antic_r, atari_antic_w)
295   AM_RANGE(0xd500, 0xd7ff) AM_NOP
296   AM_RANGE(0xd800, 0xffff) AM_RAMBANK("bank4")
297ADDRESS_MAP_END
298
299static ADDRESS_MAP_START(xegs_mem, AS_PROGRAM, 8)
300   AM_RANGE(0x0000, 0x4fff) AM_RAM
301   AM_RANGE(0x5000, 0x57ff) AM_RAMBANK("bank2")
302   AM_RANGE(0x5800, 0x7fff) AM_RAM
303   AM_RANGE(0x8000, 0x9fff) AM_ROMBANK("bank0")
304   AM_RANGE(0xa000, 0xbfff) AM_ROMBANK("bank1")
305   AM_RANGE(0xc000, 0xcfff) AM_RAMBANK("bank3")
306   AM_RANGE(0xd000, 0xd0ff) AM_READWRITE(atari_gtia_r, atari_gtia_w)
307   AM_RANGE(0xd100, 0xd1ff) AM_NOP
308   AM_RANGE(0xd200, 0xd2ff) AM_DEVREADWRITE("pokey", pokey_r, pokey_w)
309   AM_RANGE(0xd300, 0xd3ff) AM_DEVREADWRITE_MODERN("pia", pia6821_device, read_alt, write_alt)
310   AM_RANGE(0xd400, 0xd4ff) AM_READWRITE(atari_antic_r, atari_antic_w)
311   AM_RANGE(0xd500, 0xd7ff) AM_NOP
312   AM_RANGE(0xd800, 0xffff) AM_RAMBANK("bank4")
313ADDRESS_MAP_END
314
315
316static ADDRESS_MAP_START(a5200_mem, AS_PROGRAM, 8)
317   AM_RANGE(0x0000, 0x3fff) AM_RAM
318   AM_RANGE(0x4000, 0xbfff) AM_ROM
319   AM_RANGE(0xc000, 0xc0ff) AM_READWRITE(atari_gtia_r, atari_gtia_w)
320   AM_RANGE(0xd400, 0xd5ff) AM_READWRITE(atari_antic_r, atari_antic_w)
321   AM_RANGE(0xe800, 0xe8ff) AM_DEVREADWRITE("pokey", pokey_r, pokey_w)
322   AM_RANGE(0xf800, 0xffff) AM_ROM
323ADDRESS_MAP_END
324
325
326#ifdef MESS
327int atari_input_disabled(running_machine &machine)
328{
329   return 0;
330}
331#endif
332
333/**************************************************************
334 *
335 * Input ports
336 *
337 **************************************************************/
338
339
340#define JOYSTICK_DELTA         10
341#define JOYSTICK_SENSITIVITY   200
342
343static INPUT_PORTS_START( atari_artifacting )
344   PORT_START("artifacts")
345   PORT_CONFNAME(0x40, 0x00, "Television Artifacts" )
346   PORT_CONFSETTING(0x00, DEF_STR( Off ) )
347   PORT_CONFSETTING(0x40, DEF_STR( On ) )
348INPUT_PORTS_END
349
350
351
352static INPUT_PORTS_START( atari_console )
353   PORT_START("console")
354   PORT_BIT(0x04, 0x04, IPT_KEYBOARD) PORT_NAME("CONS.2: Option") PORT_CODE(KEYCODE_F3)
355   PORT_BIT(0x02, 0x02, IPT_KEYBOARD) PORT_NAME("CONS.1: Select") PORT_CODE(KEYCODE_F2)
356   PORT_BIT(0x01, 0x01, IPT_KEYBOARD) PORT_NAME("CONS.0: Start") PORT_CODE(KEYCODE_F1)
357INPUT_PORTS_END
358
359
360
361static INPUT_PORTS_START( atari_digital_joystick2 )
362   PORT_START("djoy_0_1")   /* IN1 digital joystick #1 + #2 (PIA port A) */
363   PORT_BIT(0x01, 0x01, IPT_JOYSTICK_UP)    PORT_CODE(KEYCODE_8_PAD) PORT_CODE(JOYCODE_Y_UP_SWITCH)    PORT_PLAYER(1)
364   PORT_BIT(0x02, 0x02, IPT_JOYSTICK_DOWN)  PORT_CODE(KEYCODE_2_PAD) PORT_CODE(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(1)
365   PORT_BIT(0x04, 0x04, IPT_JOYSTICK_LEFT)  PORT_CODE(KEYCODE_4_PAD) PORT_CODE(JOYCODE_X_LEFT_SWITCH)  PORT_PLAYER(1)
366   PORT_BIT(0x08, 0x08, IPT_JOYSTICK_RIGHT) PORT_CODE(KEYCODE_6_PAD) PORT_CODE(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(1)
367   PORT_BIT(0x10, 0x10, IPT_JOYSTICK_UP)    PORT_CODE(KEYCODE_8_PAD) PORT_CODE(JOYCODE_Y_UP_SWITCH)    PORT_PLAYER(2)
368   PORT_BIT(0x20, 0x20, IPT_JOYSTICK_DOWN)  PORT_CODE(KEYCODE_2_PAD) PORT_CODE(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(2)
369   PORT_BIT(0x40, 0x40, IPT_JOYSTICK_LEFT)  PORT_CODE(KEYCODE_4_PAD) PORT_CODE(JOYCODE_X_LEFT_SWITCH)  PORT_PLAYER(2)
370   PORT_BIT(0x80, 0x80, IPT_JOYSTICK_RIGHT) PORT_CODE(KEYCODE_6_PAD) PORT_CODE(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(2)
371
372   PORT_START("djoy_2_3")   /* IN2 digital joystick #3 + #4 (PIA port B) */
373   PORT_BIT(0x01, 0x01, IPT_UNUSED)
374   PORT_BIT(0x02, 0x02, IPT_UNUSED)
375   PORT_BIT(0x04, 0x04, IPT_UNUSED)
376   PORT_BIT(0x08, 0x08, IPT_UNUSED)
377   PORT_BIT(0x10, 0x10, IPT_UNUSED)
378   PORT_BIT(0x20, 0x20, IPT_UNUSED)
379   PORT_BIT(0x40, 0x40, IPT_UNUSED)
380   PORT_BIT(0x80, 0x80, IPT_UNUSED)
381
382   PORT_START("djoy_b")   /* IN3 digital joystick buttons (GTIA button bits) */
383   PORT_BIT(0x01, 0x01, IPT_BUTTON1) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_PLAYER(1)
384   PORT_BIT(0x02, 0x02, IPT_BUTTON1) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON2) PORT_PLAYER(2)
385   PORT_BIT(0x04, 0x04, IPT_UNUSED)
386   PORT_BIT(0x08, 0x08, IPT_UNUSED)
387   PORT_BIT(0x10, 0x10, IPT_BUTTON2) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_PLAYER(1)
388   PORT_BIT(0x20, 0x20, IPT_BUTTON2) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON2) PORT_PLAYER(2)
389   PORT_BIT(0x40, 0x40, IPT_UNUSED)
390   PORT_BIT(0x80, 0x80, IPT_UNUSED)
391INPUT_PORTS_END
392
393
394
395static INPUT_PORTS_START( atari_digital_joystick4 )
396   PORT_START("djoy_0_1")   /* digital joystick #1 + #2 (PIA port A) */
397   PORT_BIT(0x01, 0x01, IPT_JOYSTICK_UP)    PORT_CODE(KEYCODE_8_PAD) PORT_CODE(JOYCODE_Y_UP_SWITCH)    PORT_PLAYER(1)
398   PORT_BIT(0x02, 0x02, IPT_JOYSTICK_DOWN)  PORT_CODE(KEYCODE_2_PAD) PORT_CODE(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(1)
399   PORT_BIT(0x04, 0x04, IPT_JOYSTICK_LEFT)  PORT_CODE(KEYCODE_4_PAD) PORT_CODE(JOYCODE_X_LEFT_SWITCH)  PORT_PLAYER(1)
400   PORT_BIT(0x08, 0x08, IPT_JOYSTICK_RIGHT) PORT_CODE(KEYCODE_6_PAD) PORT_CODE(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(1)
401   PORT_BIT(0x10, 0x10, IPT_JOYSTICK_UP)    PORT_CODE(KEYCODE_8_PAD) PORT_CODE(JOYCODE_Y_UP_SWITCH)    PORT_PLAYER(2)
402   PORT_BIT(0x20, 0x20, IPT_JOYSTICK_DOWN)  PORT_CODE(KEYCODE_2_PAD) PORT_CODE(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(2)
403   PORT_BIT(0x40, 0x40, IPT_JOYSTICK_LEFT)  PORT_CODE(KEYCODE_4_PAD) PORT_CODE(JOYCODE_X_LEFT_SWITCH)  PORT_PLAYER(2)
404   PORT_BIT(0x80, 0x80, IPT_JOYSTICK_RIGHT) PORT_CODE(KEYCODE_6_PAD) PORT_CODE(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(2)
405
406   PORT_START("djoy_2_3")   /* digital joystick #3 + #4 (PIA port B) */
407   PORT_BIT(0x01, 0x01, IPT_JOYSTICK_UP)    PORT_CODE(KEYCODE_8_PAD) PORT_CODE(JOYCODE_Y_UP_SWITCH)    PORT_PLAYER(3)
408   PORT_BIT(0x02, 0x02, IPT_JOYSTICK_DOWN)  PORT_CODE(KEYCODE_2_PAD) PORT_CODE(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(3)
409   PORT_BIT(0x04, 0x04, IPT_JOYSTICK_LEFT)  PORT_CODE(KEYCODE_4_PAD) PORT_CODE(JOYCODE_X_LEFT_SWITCH)  PORT_PLAYER(3)
410   PORT_BIT(0x08, 0x08, IPT_JOYSTICK_RIGHT) PORT_CODE(KEYCODE_6_PAD) PORT_CODE(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(3)
411   PORT_BIT(0x10, 0x10, IPT_JOYSTICK_UP)    PORT_CODE(KEYCODE_8_PAD) PORT_CODE(JOYCODE_Y_UP_SWITCH)    PORT_PLAYER(4)
412   PORT_BIT(0x20, 0x20, IPT_JOYSTICK_DOWN)  PORT_CODE(KEYCODE_2_PAD) PORT_CODE(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(4)
413   PORT_BIT(0x40, 0x40, IPT_JOYSTICK_LEFT)  PORT_CODE(KEYCODE_4_PAD) PORT_CODE(JOYCODE_X_LEFT_SWITCH)  PORT_PLAYER(4)
414   PORT_BIT(0x80, 0x80, IPT_JOYSTICK_RIGHT) PORT_CODE(KEYCODE_6_PAD) PORT_CODE(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(4)
415
416   PORT_START("djoy_b")   /* digital joystick buttons (GTIA button bits) */
417   PORT_BIT(0x01, 0x01, IPT_BUTTON1) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_PLAYER(1)
418   PORT_BIT(0x02, 0x02, IPT_BUTTON1) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON2) PORT_PLAYER(2)
419   PORT_BIT(0x04, 0x04, IPT_BUTTON1) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON3) PORT_PLAYER(3)
420   PORT_BIT(0x08, 0x08, IPT_BUTTON1) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON4) PORT_PLAYER(4)
421   PORT_BIT(0x10, 0x10, IPT_BUTTON2) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_PLAYER(1)
422   PORT_BIT(0x20, 0x20, IPT_BUTTON2) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON2) PORT_PLAYER(2)
423   PORT_BIT(0x40, 0x40, IPT_BUTTON2) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON3) PORT_PLAYER(3)
424   PORT_BIT(0x80, 0x80, IPT_BUTTON2) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON4) PORT_PLAYER(4)
425INPUT_PORTS_END
426
427
428
429/* 2009-04 FP:
430Small note about natural keyboard support: currently,
431- "Break" is mapped to 'F1'
432- "Clear" is mapped to 'F2'
433- "Atari" is mapped to 'F3'                         */
434
435static INPUT_PORTS_START( atari_keyboard )
436   PORT_START("keyboard_0")
437   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_L) PORT_CHAR('l') PORT_CHAR('L')
438   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_J) PORT_CHAR('j') PORT_CHAR('J')
439   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_COLON) PORT_CHAR(';') PORT_CHAR(':')
440   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Break") PORT_CODE(KEYCODE_BACKSPACE) PORT_CHAR(UCHAR_MAMEKEY(F1))
441   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_UNUSED)
442   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_K) PORT_CHAR('k') PORT_CHAR('K')
443   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR('+') PORT_CHAR('\\')
444   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH) PORT_CHAR('*') PORT_CHAR('^')
445
446   PORT_START("keyboard_1")
447   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_O) PORT_CHAR('o') PORT_CHAR('O')
448   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) // None!
449   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_P) PORT_CHAR('p') PORT_CHAR('P')
450   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_U) PORT_CHAR('u') PORT_CHAR('U')
451   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Return") PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)
452   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_I) PORT_CHAR('i') PORT_CHAR('I')
453   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_OPENBRACE) PORT_CHAR('-') PORT_CHAR('_')
454   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_CLOSEBRACE) PORT_CHAR('=') PORT_CHAR('|')
455
456   PORT_START("keyboard_2")
457   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_V) PORT_CHAR('v') PORT_CHAR('V')
458   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_UNUSED)
459   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_C) PORT_CHAR('c') PORT_CHAR('C')
460   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_UNUSED)
461   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_UNUSED)
462   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_B) PORT_CHAR('b') PORT_CHAR('B')
463   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_X) PORT_CHAR('x') PORT_CHAR('X')
464   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_Z) PORT_CHAR('z') PORT_CHAR('Z')
465
466   PORT_START("keyboard_3")
467   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')
468   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_UNUSED)
469   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')
470   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('&')
471   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Escape") PORT_CODE(KEYCODE_ESC) PORT_CHAR(27)
472   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')
473   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('\"')
474   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')
475
476   PORT_START("keyboard_4")
477   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA) PORT_CHAR(',') PORT_CHAR('[')
478   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_SPACE) PORT_CHAR(' ')
479   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP) PORT_CHAR('.') PORT_CHAR(']')
480   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_N) PORT_CHAR('n') PORT_CHAR('N')
481   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_UNUSED)
482   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_M) PORT_CHAR('m') PORT_CHAR('M')
483   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH) PORT_CHAR('/') PORT_CHAR('?')
484   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Atari") PORT_CODE(KEYCODE_RCONTROL) PORT_CHAR(UCHAR_MAMEKEY(F3))
485
486   PORT_START("keyboard_5")
487   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_R) PORT_CHAR('r') PORT_CHAR('R')
488   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_UNUSED)
489   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_E) PORT_CHAR('e') PORT_CHAR('E')
490   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_Y) PORT_CHAR('y') PORT_CHAR('Y')
491   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_TAB) PORT_CHAR(UCHAR_MAMEKEY(TAB))
492   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_T) PORT_CHAR('t') PORT_CHAR('T')
493   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_W) PORT_CHAR('w') PORT_CHAR('W')
494   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_Q) PORT_CHAR('q') PORT_CHAR('Q')
495
496   PORT_START("keyboard_6")
497   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_9) PORT_CHAR('9') PORT_CHAR('(')
498   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_UNUSED)
499   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_0) PORT_CHAR('0') PORT_CHAR(')')
500   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('\'')
501   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("BackS  Delete") PORT_CODE(KEYCODE_BACKSLASH2) PORT_CHAR(8) PORT_CHAR(UCHAR_MAMEKEY(DEL))
502   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_CHAR('@')
503   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("<  Clear") PORT_CODE(KEYCODE_MINUS) PORT_CHAR('<') PORT_CHAR(UCHAR_MAMEKEY(F2))
504   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME(">  Insert") PORT_CODE(KEYCODE_EQUALS) PORT_CHAR('>') PORT_CHAR(UCHAR_MAMEKEY(INSERT))
505
506   PORT_START("keyboard_7")
507   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_F) PORT_CHAR('f') PORT_CHAR('F')
508   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_H) PORT_CHAR('h') PORT_CHAR('H')
509   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_D) PORT_CHAR('d') PORT_CHAR('D')
510   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_UNUSED)
511   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Caps") PORT_CODE(KEYCODE_CAPSLOCK) PORT_TOGGLE PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
512   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_G) PORT_CHAR('g') PORT_CHAR('G')
513   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_S) PORT_CHAR('s') PORT_CHAR('S')
514   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_A) PORT_CHAR('a') PORT_CHAR('A')
515
516   PORT_START("fake")
517   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Shift") PORT_CODE(KEYCODE_LSHIFT) PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)
518   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Ctrl") PORT_CODE(KEYCODE_LCONTROL) PORT_CHAR(UCHAR_SHIFT_2)
519INPUT_PORTS_END
520
521
522static INPUT_PORTS_START( atari_analog_paddles )
523   PORT_START("analog_0") /* IN8 analog in #1 */
524   PORT_BIT(0xff, 0x74, IPT_PADDLE) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(1) PORT_REVERSE
525
526   PORT_START("analog_1") /* IN9 analog in #2 */
527   PORT_BIT(0xff, 0x74, IPT_PADDLE) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(2) PORT_REVERSE
528
529   PORT_START("analog_2") /* IN10 analog in #3 */
530   PORT_BIT(0xff, 0x74, IPT_PADDLE) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(3) PORT_REVERSE
531
532   PORT_START("analog_3") /* IN11 analog in #4 */
533   PORT_BIT(0xff, 0x74, IPT_PADDLE) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(4) PORT_REVERSE
534
535   PORT_START("analog_4") /* IN12 analog in #5 */
536   PORT_BIT(0xff, 0x74, IPT_PADDLE) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_REVERSE /* PORT_PLAYER(5) */
537
538   PORT_START("analog_5") /* IN13 analog in #6 */
539   PORT_BIT(0xff, 0x74, IPT_PADDLE) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_REVERSE /* PORT_PLAYER(6) */
540
541   PORT_START("analog_6") /* IN14 analog in #7 */
542   PORT_BIT(0xff, 0x74, IPT_PADDLE) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_REVERSE /* PORT_PLAYER(7) */
543
544   PORT_START("analog_7") /* IN15 analog in #8 */
545   PORT_BIT(0xff, 0x74, IPT_PADDLE) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_REVERSE /* PORT_PLAYER(8) */
546INPUT_PORTS_END
547
548
549
550static INPUT_PORTS_START( a800 )
551   PORT_INCLUDE( atari_artifacting )
552   PORT_INCLUDE( atari_console )
553   PORT_INCLUDE( atari_digital_joystick4 )
554   PORT_INCLUDE( atari_keyboard )
555   PORT_INCLUDE( atari_analog_paddles )
556INPUT_PORTS_END
557
558
559
560static INPUT_PORTS_START( a800xl )
561   PORT_INCLUDE( atari_artifacting )
562   PORT_INCLUDE( atari_console )
563   PORT_INCLUDE( atari_digital_joystick2 )
564   PORT_INCLUDE( atari_keyboard )
565   PORT_INCLUDE( atari_analog_paddles )
566INPUT_PORTS_END
567
568
569
570static INPUT_PORTS_START( a5200 )
571   PORT_INCLUDE( atari_artifacting )
572
573   PORT_START("djoy_b")   /* lower/upper buttons */
574   PORT_BIT(0x01, 0x01, IPT_BUTTON1) PORT_PLAYER(1)
575   PORT_BIT(0x02, 0x02, IPT_BUTTON1) PORT_PLAYER(2)
576   PORT_BIT(0x04, 0x04, IPT_BUTTON1) PORT_PLAYER(3)
577   PORT_BIT(0x08, 0x08, IPT_BUTTON1) PORT_PLAYER(4)
578   PORT_BIT(0x10, 0x10, IPT_BUTTON2) PORT_PLAYER(1)
579   PORT_BIT(0x20, 0x20, IPT_BUTTON2) PORT_PLAYER(2)
580   PORT_BIT(0x40, 0x40, IPT_BUTTON2) PORT_PLAYER(3)
581   PORT_BIT(0x80, 0x80, IPT_BUTTON2) PORT_PLAYER(4)
582
583   PORT_START("keypad_0")
584   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("(Break)") PORT_CODE(KEYCODE_PAUSE)   // is this correct?
585   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[#]") PORT_CODE(KEYCODE_ENTER_PAD)
586   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[0]") PORT_CODE(KEYCODE_0_PAD)
587   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[*]") PORT_CODE(KEYCODE_PLUS_PAD)
588   PORT_BIT(0xf0, IP_ACTIVE_HIGH, IPT_UNUSED)
589
590   PORT_START("keypad_1")
591   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("Reset") PORT_CODE(KEYCODE_F3)
592   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[9]") PORT_CODE(KEYCODE_9_PAD)
593   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[8]") PORT_CODE(KEYCODE_8_PAD)
594   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[7]") PORT_CODE(KEYCODE_7_PAD)
595   PORT_BIT(0xf0, IP_ACTIVE_HIGH, IPT_UNUSED)
596
597   PORT_START("keypad_2")
598   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME(DEF_STR(Pause)) PORT_CODE(KEYCODE_F2)
599   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[6]") PORT_CODE(KEYCODE_6_PAD)
600   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[5]") PORT_CODE(KEYCODE_5_PAD)
601   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[4]") PORT_CODE(KEYCODE_4_PAD)
602   PORT_BIT(0xf0, IP_ACTIVE_HIGH, IPT_UNUSED)
603
604   PORT_START("keypad_3")
605   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_START)    PORT_NAME("Start")
606   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[3]") PORT_CODE(KEYCODE_3_PAD)
607   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[2]") PORT_CODE(KEYCODE_2_PAD)
608   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[1]") PORT_CODE(KEYCODE_1_PAD)
609   PORT_BIT(0xf0, IP_ACTIVE_HIGH, IPT_UNUSED)
610
611   PORT_START("analog_0")
612   PORT_BIT(0xff, 0x72, IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(1)
613
614   PORT_START("analog_1")
615   PORT_BIT(0xff, 0x72, IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(1)
616
617   PORT_START("analog_2")
618   PORT_BIT(0xff, 0x72, IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(2)
619
620   PORT_START("analog_3")
621   PORT_BIT(0xff, 0x72, IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(2)
622
623   PORT_START("analog_4")
624   PORT_BIT(0xff, 0x72, IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(3)
625
626   PORT_START("analog_5")
627   PORT_BIT(0xff, 0x72, IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(3)
628
629   PORT_START("analog_6")
630   PORT_BIT(0xff, 0x72, IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(4)
631
632   PORT_START("analog_7")
633   PORT_BIT(0xff, 0x72, IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(4)
634
635INPUT_PORTS_END
636
637
638/**************************************************************
639 *
640 * Palette
641 *
642 **************************************************************/
643
644static const UINT8 atari_palette[256*3] =
645{
646   /* Grey */
647   0x00,0x00,0x00, 0x25,0x25,0x25, 0x34,0x34,0x34, 0x4e,0x4e,0x4e,
648   0x68,0x68,0x68, 0x75,0x75,0x75, 0x8e,0x8e,0x8e, 0xa4,0xa4,0xa4,
649   0xb8,0xb8,0xb8, 0xc5,0xc5,0xc5, 0xd0,0xd0,0xd0, 0xd7,0xd7,0xd7,
650   0xe1,0xe1,0xe1, 0xea,0xea,0xea, 0xf4,0xf4,0xf4, 0xff,0xff,0xff,
651   /* Gold */
652   0x41,0x20,0x00, 0x54,0x28,0x00, 0x76,0x37,0x00, 0x9a,0x50,0x00,
653   0xc3,0x68,0x06, 0xe4,0x7b,0x07, 0xff,0x91,0x1a, 0xff,0xab,0x1d,
654   0xff,0xc5,0x1f, 0xff,0xd0,0x3b, 0xff,0xd8,0x4c, 0xff,0xe6,0x51,
655   0xff,0xf4,0x56, 0xff,0xf9,0x70, 0xff,0xff,0x90, 0xff,0xff,0xaa,
656   /* Orange */
657   0x45,0x19,0x04, 0x72,0x1e,0x11, 0x9f,0x24,0x1e, 0xb3,0x3a,0x20,
658   0xc8,0x51,0x20, 0xe3,0x69,0x20, 0xfc,0x81,0x20, 0xfd,0x8c,0x25,
659   0xfe,0x98,0x2c, 0xff,0xae,0x38, 0xff,0xb9,0x46, 0xff,0xbf,0x51,
660   0xff,0xc6,0x6d, 0xff,0xd5,0x87, 0xff,0xe4,0x98, 0xff,0xe6,0xab,
661   /* Red-Orange */
662   0x5d,0x1f,0x0c, 0x7a,0x24,0x0d, 0x98,0x2c,0x0e, 0xb0,0x2f,0x0f,
663   0xbf,0x36,0x24, 0xd3,0x4e,0x2a, 0xe7,0x62,0x3e, 0xf3,0x6e,0x4a,
664   0xfd,0x78,0x54, 0xff,0x8a,0x6a, 0xff,0x98,0x7c, 0xff,0xa4,0x8b,
665   0xff,0xb3,0x9e, 0xff,0xc2,0xb2, 0xff,0xd0,0xc3, 0xff,0xda,0xd0,
666   /* Pink */
667   0x4a,0x17,0x00, 0x72,0x1f,0x00, 0xa8,0x13,0x00, 0xc8,0x21,0x0a,
668   0xdf,0x25,0x12, 0xec,0x3b,0x24, 0xfa,0x52,0x36, 0xfc,0x61,0x48,
669   0xff,0x70,0x5f, 0xff,0x7e,0x7e, 0xff,0x8f,0x8f, 0xff,0x9d,0x9e,
670   0xff,0xab,0xad, 0xff,0xb9,0xbd, 0xff,0xc7,0xce, 0xff,0xca,0xde,
671   /* Purple */
672   0x49,0x00,0x36, 0x66,0x00,0x4b, 0x80,0x03,0x5f, 0x95,0x0f,0x74,
673   0xaa,0x22,0x88, 0xba,0x3d,0x99, 0xca,0x4d,0xa9, 0xd7,0x5a,0xb6,
674   0xe4,0x67,0xc3, 0xef,0x72,0xce, 0xfb,0x7e,0xda, 0xff,0x8d,0xe1,
675   0xff,0x9d,0xe5, 0xff,0xa5,0xe7, 0xff,0xaf,0xea, 0xff,0xb8,0xec,
676   /* Purple-Blue */
677   0x48,0x03,0x6c, 0x5c,0x04,0x88, 0x65,0x0d,0x90, 0x7b,0x23,0xa7,
678   0x93,0x3b,0xbf, 0x9d,0x45,0xc9, 0xa7,0x4f,0xd3, 0xb2,0x5a,0xde,
679   0xbd,0x65,0xe9, 0xc5,0x6d,0xf1, 0xce,0x76,0xfa, 0xd5,0x83,0xff,
680   0xda,0x90,0xff, 0xde,0x9c,0xff, 0xe2,0xa9,0xff, 0xe6,0xb6,0xff,
681   /* Blue 1 */
682   0x05,0x1e,0x81, 0x06,0x26,0xa5, 0x08,0x2f,0xca, 0x26,0x3d,0xd4,
683   0x44,0x4c,0xde, 0x4f,0x5a,0xec, 0x5a,0x68,0xff, 0x65,0x75,0xff,
684   0x71,0x83,0xff, 0x80,0x91,0xff, 0x90,0xa0,0xff, 0x97,0xa9,0xff,
685   0x9f,0xb2,0xff, 0xaf,0xbe,0xff, 0xc0,0xcb,0xff, 0xcd,0xd3,0xff,
686   /* Blue 2 */
687   0x0b,0x07,0x79, 0x20,0x1c,0x8e, 0x35,0x31,0xa3, 0x46,0x42,0xb4,
688   0x57,0x53,0xc5, 0x61,0x5d,0xcf, 0x6d,0x69,0xdb, 0x7b,0x77,0xe9,
689   0x89,0x85,0xf7, 0x91,0x8d,0xff, 0x9c,0x98,0xff, 0xa7,0xa4,0xff,
690   0xb2,0xaf,0xff, 0xbb,0xb8,0xff, 0xc3,0xc1,0xff, 0xd3,0xd1,0xff,
691   /* Light-Blue */
692   0x1d,0x29,0x5a, 0x1d,0x38,0x76, 0x1d,0x48,0x92, 0x1d,0x5c,0xac,
693   0x1d,0x71,0xc6, 0x32,0x86,0xcf, 0x48,0x9b,0xd9, 0x4e,0xa8,0xec,
694   0x55,0xb6,0xff, 0x69,0xca,0xff, 0x74,0xcb,0xff, 0x82,0xd3,0xff,
695   0x8d,0xda,0xff, 0x9f,0xd4,0xff, 0xb4,0xe2,0xff, 0xc0,0xeb,0xff,
696   /* Turquoise */
697   0x00,0x4b,0x59, 0x00,0x5d,0x6e, 0x00,0x6f,0x84, 0x00,0x84,0x9c,
698   0x00,0x99,0xbf, 0x00,0xab,0xca, 0x00,0xbc,0xde, 0x00,0xd0,0xf5,
699   0x10,0xdc,0xff, 0x3e,0xe1,0xff, 0x64,0xe7,0xff, 0x76,0xea,0xff,
700   0x8b,0xed,0xff, 0x9a,0xef,0xff, 0xb1,0xf3,0xff, 0xc7,0xf6,0xff,
701   /* Green-Blue */
702   0x00,0x48,0x00, 0x00,0x54,0x00, 0x03,0x6b,0x03, 0x0e,0x76,0x0e,
703   0x18,0x80,0x18, 0x27,0x92,0x27, 0x36,0xa4,0x36, 0x4e,0xb9,0x4e,
704   0x51,0xcd,0x51, 0x72,0xda,0x72, 0x7c,0xe4,0x7c, 0x85,0xed,0x85,
705   0x99,0xf2,0x99, 0xb3,0xf7,0xb3, 0xc3,0xf9,0xc3, 0xcd,0xfc,0xcd,
706   /* Green */
707   0x16,0x40,0x00, 0x1c,0x53,0x00, 0x23,0x66,0x00, 0x28,0x78,0x00,
708   0x2e,0x8c,0x00, 0x3a,0x98,0x0c, 0x47,0xa5,0x19, 0x51,0xaf,0x23,
709   0x5c,0xba,0x2e, 0x71,0xcf,0x43, 0x85,0xe3,0x57, 0x8d,0xeb,0x5f,
710   0x97,0xf5,0x69, 0xa0,0xfe,0x72, 0xb1,0xff,0x8a, 0xbc,0xff,0x9a,
711   /* Yellow-Green */
712   0x2c,0x35,0x00, 0x38,0x44,0x00, 0x44,0x52,0x00, 0x49,0x56,0x00,
713   0x60,0x71,0x00, 0x6c,0x7f,0x00, 0x79,0x8d,0x0a, 0x8b,0x9f,0x1c,
714   0x9e,0xb2,0x2f, 0xab,0xbf,0x3c, 0xb8,0xcc,0x49, 0xc2,0xd6,0x53,
715   0xcd,0xe1,0x53, 0xdb,0xef,0x6c, 0xe8,0xfc,0x79, 0xf2,0xff,0xab,
716   /* Orange-Green */
717   0x46,0x3a,0x09, 0x4d,0x3f,0x09, 0x54,0x45,0x09, 0x6c,0x58,0x09,
718   0x90,0x76,0x09, 0xab,0x8b,0x0a, 0xc1,0xa1,0x20, 0xd0,0xb0,0x2f,
719   0xde,0xbe,0x3d, 0xe6,0xc6,0x45, 0xed,0xcd,0x4c, 0xf5,0xd8,0x62,
720   0xfb,0xe2,0x76, 0xfc,0xee,0x98, 0xfd,0xf3,0xa9, 0xfd,0xf3,0xbe,
721   /* Light-Orange */
722   0x40,0x1a,0x02, 0x58,0x1f,0x05, 0x70,0x24,0x08, 0x8d,0x3a,0x13,
723   0xab,0x51,0x1f, 0xb5,0x64,0x27, 0xbf,0x77,0x30, 0xd0,0x85,0x3a,
724   0xe1,0x93,0x44, 0xed,0xa0,0x4e, 0xf9,0xad,0x58, 0xfc,0xb7,0x5c,
725   0xff,0xc1,0x60, 0xff,0xca,0x69, 0xff,0xcf,0x7e, 0xff,0xda,0x96
726};
727
728
729/* Initialise the palette */
730static PALETTE_INIT( mess_atari )
731{
732   int i;
733
734   for ( i = 0; i < sizeof(atari_palette) / 3; i++ )
735   {
736      palette_set_color_rgb(machine, i, atari_palette[i*3], atari_palette[i*3+1], atari_palette[i*3+2]);
737   }
738}
739
740/**************************************************************
741 *
742 * Memory banking
743 *
744 **************************************************************/
745
746static void a800xl_mmu(running_machine &machine, UINT8 new_mmu)
747{
748   UINT8 *base = machine.region("maincpu")->base();
749   UINT8 *base1, *base2, *base3, *base4;
750
751   /* check if memory C000-FFFF changed */
752   if( new_mmu & 0x01 )
753   {
754      logerror("%s MMU BIOS ROM\n", machine.system().name);
755      base3 = base + 0x14000;  /* 8K lo BIOS */
756      base4 = base + 0x15800;  /* 4K FP ROM + 8K hi BIOS */
757      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xc000, 0xcfff, "bank3");
758      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xc000, 0xcfff);
759      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xd800, 0xffff, "bank4");
760      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xd800, 0xffff);
761   }
762   else
763   {
764      logerror("%s MMU BIOS RAM\n", machine.system().name);
765      base3 = base + 0x0c000;  /* 8K RAM */
766      base4 = base + 0x0d800;  /* 4K RAM + 8K RAM */
767      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0xc000, 0xcfff, "bank3");
768      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0xd800, 0xffff, "bank4");
769   }
770   memory_set_bankptr(machine, "bank3", base3);
771   memory_set_bankptr(machine, "bank4", base4);
772
773   /* check if BASIC changed */
774   if( new_mmu & 0x02 )
775   {
776      logerror("%s MMU BASIC RAM\n", machine.system().name);
777      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0xa000, 0xbfff, "bank1");
778      base1 = base + 0x0a000;  /* 8K RAM */
779   }
780   else
781   {
782      logerror("%s MMU BASIC ROM\n", machine.system().name);
783      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xa000, 0xbfff, "bank1");
784      machine.device("maincpu")->memory().space(AS_PROGRAM)->nop_write(0xa000, 0xbfff);
785      base1 = base + 0x10000;  /* 8K BASIC */
786   }
787
788   memory_set_bankptr(machine, "bank1", base1);
789
790   /* check if self-test ROM changed */
791   if( new_mmu & 0x80 )
792   {
793      logerror("%s MMU SELFTEST RAM\n", machine.system().name);
794      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0x5000, 0x57ff, "bank2");
795      base2 = base + 0x05000;  /* 0x0800 bytes */
796   }
797   else
798   {
799      logerror("%s MMU SELFTEST ROM\n", machine.system().name);
800      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x5000, 0x57ff, "bank2");
801      machine.device("maincpu")->memory().space(AS_PROGRAM)->nop_write(0x5000, 0x57ff);
802      base2 = base + 0x15000;  /* 0x0800 bytes */
803   }
804   memory_set_bankptr(machine, "bank2", base2);
805}
806
807/* BASIC was available in a separate cart, so we don't test it */
808static void a1200xl_mmu(running_machine &machine, UINT8 new_mmu)
809{
810   UINT8 *base = machine.region("maincpu")->base();
811   UINT8 *base2, *base3, *base4;
812
813   /* check if memory C000-FFFF changed */
814   if( new_mmu & 0x01 )
815   {
816      logerror("%s MMU BIOS ROM\n", machine.system().name);
817      base3 = base + 0x14000;  /* 8K lo BIOS */
818      base4 = base + 0x15800;  /* 4K FP ROM + 8K hi BIOS */
819      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xc000, 0xcfff, "bank3");
820      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xc000, 0xcfff);
821      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xd800, 0xffff, "bank4");
822      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xd800, 0xffff);
823   }
824   else
825   {
826      logerror("%s MMU BIOS RAM\n", machine.system().name);
827      base3 = base + 0x0c000;  /* 8K RAM */
828      base4 = base + 0x0d800;  /* 4K RAM + 8K RAM */
829      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0xc000, 0xcfff, "bank3");
830      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0xd800, 0xffff, "bank4");
831   }
832   memory_set_bankptr(machine, "bank3", base3);
833   memory_set_bankptr(machine, "bank4", base4);
834
835   /* check if self-test ROM changed */
836   if( new_mmu & 0x80 )
837   {
838      logerror("%s MMU SELFTEST RAM\n", machine.system().name);
839      base2 = base + 0x05000;  /* 0x0800 bytes */
840      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0x5000, 0x57ff, "bank2");
841   }
842   else
843   {
844      logerror("%s MMU SELFTEST ROM\n", machine.system().name);
845      base2 = base + 0x15000;  /* 0x0800 bytes */
846      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x5000, 0x57ff, "bank2");
847      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0x5000, 0x57ff);
848   }
849   memory_set_bankptr(machine, "bank2", base2);
850}
851
852static void xegs_mmu(running_machine &machine, UINT8 new_mmu)
853{
854   UINT8 *base = machine.region("maincpu")->base();
855   UINT8 *base2, *base3, *base4;
856
857   /* check if memory C000-FFFF changed */
858   if( new_mmu & 0x01 )
859   {
860      logerror("%s MMU BIOS ROM\n", machine.system().name);
861      base3 = base + 0x14000;  /* 8K lo BIOS */
862      base4 = base + 0x15800;  /* 4K FP ROM + 8K hi BIOS */
863      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xc000, 0xcfff, "bank3");
864      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xc000, 0xcfff);
865      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xd800, 0xffff, "bank4");
866      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xd800, 0xffff);
867   }
868   else
869   {
870      logerror("%s MMU BIOS RAM\n", machine.system().name);
871      base3 = base + 0x0c000;  /* 8K RAM */
872      base4 = base + 0x0d800;  /* 4K RAM + 8K RAM */
873      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0xc000, 0xcfff, "bank3");
874      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0xd800, 0xffff, "bank4");
875   }
876   memory_set_bankptr(machine, "bank3", base3);
877   memory_set_bankptr(machine, "bank4", base4);
878
879
880   /* check if self-test ROM changed */
881   if( new_mmu & 0x80 )
882   {
883      logerror("%s MMU SELFTEST RAM\n", machine.system().name);
884      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0x5000, 0x57ff, "bank2");
885      base2 = base + 0x05000;  /* 0x0800 bytes */
886   }
887   else
888   {
889      logerror("%s MMU SELFTEST ROM\n", machine.system().name);
890      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x5000, 0x57ff, "bank2");
891      machine.device("maincpu")->memory().space(AS_PROGRAM)->nop_write(0x5000, 0x57ff);
892      base2 = base + 0x15000;  /* 0x0800 bytes */
893   }
894   memory_set_bankptr(machine, "bank2", base2);
895}
896
897/**************************************************************
898 *
899 * PIA interface
900 *
901 **************************************************************/
902
903static WRITE8_DEVICE_HANDLER(a1200xl_pia_pb_w) { a1200xl_mmu(device->machine(), data); }
904static WRITE8_DEVICE_HANDLER(a800xl_pia_pb_w)
905{
906   if (downcast<pia6821_device *>(device)->port_b_z_mask() != 0xff)
907      a800xl_mmu(device->machine(), data);
908}
909
910static WRITE8_DEVICE_HANDLER(xegs_pia_pb_w)
911{
912   if (downcast<pia6821_device *>(device)->port_b_z_mask() != 0xff)
913      xegs_mmu(device->machine(), data);
914}
915
916static const pokey_interface atari_pokey_interface =
917{
918   {
919      DEVCB_INPUT_PORT("analog_0"),
920      DEVCB_INPUT_PORT("analog_1"),
921      DEVCB_INPUT_PORT("analog_2"),
922      DEVCB_INPUT_PORT("analog_3"),
923      DEVCB_INPUT_PORT("analog_4"),
924      DEVCB_INPUT_PORT("analog_5"),
925      DEVCB_INPUT_PORT("analog_6"),
926      DEVCB_INPUT_PORT("analog_7")
927   },
928   DEVCB_NULL,
929   DEVCB_DEVICE_HANDLER("fdc", atari_serin_r),
930   DEVCB_DEVICE_HANDLER("fdc", atari_serout_w),
931   atari_interrupt_cb,
932};
933
934
935static const pia6821_interface atari_pia_interface =
936{
937   DEVCB_HANDLER(atari_pia_pa_r),      /* port A in */
938   DEVCB_HANDLER(atari_pia_pb_r),   /* port B in */
939   DEVCB_NULL,      /* line CA1 in */
940   DEVCB_NULL,      /* line CB1 in */
941   DEVCB_NULL,      /* line CA2 in */
942   DEVCB_NULL,      /* line CB2 in */
943   DEVCB_NULL,      /* port A out */
944   DEVCB_NULL,      /* port B out */
945   DEVCB_NULL,      /* line CA2 out */
946   DEVCB_DEVICE_LINE("fdc",atarifdc_pia_cb2_w),      /* port CB2 out */
947   DEVCB_NULL,      /* IRQA */
948   DEVCB_NULL      /* IRQB */
949};
950
951static const pia6821_interface a600xl_pia_interface =
952{
953   DEVCB_HANDLER(atari_pia_pa_r),      /* port A in */
954   DEVCB_HANDLER(atari_pia_pb_r),   /* port B in */
955   DEVCB_NULL,      /* line CA1 in */
956   DEVCB_NULL,      /* line CB1 in */
957   DEVCB_NULL,      /* line CA2 in */
958   DEVCB_NULL,      /* line CB2 in */
959   DEVCB_NULL,      /* port A out */
960   DEVCB_HANDLER(a600xl_pia_pb_w),      /* port B out */
961   DEVCB_NULL,      /* line CA2 out */
962   DEVCB_DEVICE_LINE("fdc",atarifdc_pia_cb2_w),      /* port CB2 out */
963   DEVCB_NULL,      /* IRQA */
964   DEVCB_NULL      /* IRQB */
965};
966
967static const pia6821_interface a1200xl_pia_interface =
968{
969   DEVCB_HANDLER(atari_pia_pa_r),      /* port A in */
970   DEVCB_HANDLER(atari_pia_pb_r),   /* port B in */
971   DEVCB_NULL,      /* line CA1 in */
972   DEVCB_NULL,      /* line CB1 in */
973   DEVCB_NULL,      /* line CA2 in */
974   DEVCB_NULL,      /* line CB2 in */
975   DEVCB_NULL,      /* port A out */
976   DEVCB_HANDLER(a1200xl_pia_pb_w),      /* port B out */
977   DEVCB_NULL,      /* line CA2 out */
978   DEVCB_DEVICE_LINE("fdc",atarifdc_pia_cb2_w),      /* port CB2 out */
979   DEVCB_NULL,      /* IRQA */
980   DEVCB_NULL      /* IRQB */
981};
982
983static const pia6821_interface a800xl_pia_interface =
984{
985   DEVCB_HANDLER(atari_pia_pa_r),      /* port A in */
986   DEVCB_HANDLER(atari_pia_pb_r),   /* port B in */
987   DEVCB_NULL,      /* line CA1 in */
988   DEVCB_NULL,      /* line CB1 in */
989   DEVCB_NULL,      /* line CA2 in */
990   DEVCB_NULL,      /* line CB2 in */
991   DEVCB_NULL,      /* port A out */
992   DEVCB_HANDLER(a800xl_pia_pb_w),      /* port B out */
993   DEVCB_NULL,      /* line CA2 out */
994   DEVCB_DEVICE_LINE("fdc",atarifdc_pia_cb2_w),      /* port CB2 out */
995   DEVCB_NULL,      /* IRQA */
996   DEVCB_NULL      /* IRQB */
997};
998
999static const pia6821_interface xegs_pia_interface =
1000{
1001   DEVCB_HANDLER(atari_pia_pa_r),      /* port A in */
1002   DEVCB_HANDLER(atari_pia_pb_r),   /* port B in */
1003   DEVCB_NULL,      /* line CA1 in */
1004   DEVCB_NULL,      /* line CB1 in */
1005   DEVCB_NULL,      /* line CA2 in */
1006   DEVCB_NULL,      /* line CB2 in */
1007   DEVCB_NULL,      /* port A out */
1008   DEVCB_HANDLER(xegs_pia_pb_w),      /* port B out */
1009   DEVCB_NULL,      /* line CA2 out */
1010   DEVCB_DEVICE_LINE("fdc",atarifdc_pia_cb2_w),      /* port CB2 out */
1011   DEVCB_NULL,      /* IRQA */
1012   DEVCB_NULL      /* IRQB */
1013};
1014
1015// FIXME: should there be anything connected where other system have the fdc?
1016static const pokey_interface a5200_pokey_interface =
1017{
1018   {
1019      DEVCB_INPUT_PORT("analog_0"),
1020      DEVCB_INPUT_PORT("analog_1"),
1021      DEVCB_INPUT_PORT("analog_2"),
1022      DEVCB_INPUT_PORT("analog_3"),
1023      DEVCB_INPUT_PORT("analog_4"),
1024      DEVCB_INPUT_PORT("analog_5"),
1025      DEVCB_INPUT_PORT("analog_6"),
1026      DEVCB_INPUT_PORT("analog_7")
1027   },
1028   DEVCB_NULL,
1029   DEVCB_NULL,   // FIXME: is there anything connected here?
1030   DEVCB_NULL,   // FIXME: is there anything connected here?
1031   atari_interrupt_cb,
1032};
1033
1034static const pia6821_interface a5200_pia_interface =
1035{
1036   DEVCB_HANDLER(atari_pia_pa_r),      /* port A in */
1037   DEVCB_HANDLER(atari_pia_pb_r),   /* port B in */
1038   DEVCB_NULL,      /* line CA1 in */
1039   DEVCB_NULL,      /* line CB1 in */
1040   DEVCB_NULL,      /* line CA2 in */
1041   DEVCB_NULL,      /* line CB2 in */
1042   DEVCB_NULL,      /* port A out */
1043   DEVCB_NULL,      /* port B out */
1044   DEVCB_NULL,      /* line CA2 out */
1045   DEVCB_NULL,      /* port CB2 out */   // FIXME: is there anything connected here
1046   DEVCB_NULL,      /* IRQA */
1047   DEVCB_NULL      /* IRQB */
1048};
1049
1050
1051/**************************************************************
1052 *
1053 * Machine drivers
1054 *
1055 **************************************************************/
1056
1057static MACHINE_CONFIG_FRAGMENT( a400_cartslot )
1058   MCFG_CARTSLOT_ADD("cart1")
1059   MCFG_CARTSLOT_EXTENSION_LIST("rom,bin")
1060   MCFG_CARTSLOT_NOT_MANDATORY
1061   MCFG_CARTSLOT_LOAD(a800_cart)
1062   MCFG_CARTSLOT_UNLOAD(a800_cart)
1063   MCFG_CARTSLOT_INTERFACE("a800_cart")
1064MACHINE_CONFIG_END
1065
1066static MACHINE_CONFIG_FRAGMENT( a800_cartslot )
1067   MCFG_CARTSLOT_ADD("cart1")
1068   MCFG_CARTSLOT_EXTENSION_LIST("rom,bin")
1069   MCFG_CARTSLOT_NOT_MANDATORY
1070   MCFG_CARTSLOT_LOAD(a800_cart)
1071   MCFG_CARTSLOT_UNLOAD(a800_cart)
1072   MCFG_CARTSLOT_INTERFACE("a800_cart")
1073
1074   MCFG_CARTSLOT_ADD("cart2")
1075   MCFG_CARTSLOT_EXTENSION_LIST("rom,bin")
1076   MCFG_CARTSLOT_NOT_MANDATORY
1077   MCFG_CARTSLOT_LOAD(a800_cart_right)
1078   MCFG_CARTSLOT_UNLOAD(a800_cart_right)
1079   MCFG_CARTSLOT_INTERFACE("a800_cart")
1080MACHINE_CONFIG_END
1081
1082static MACHINE_CONFIG_START( atari_common_nodac, driver_device )
1083   /* basic machine hardware */
1084   MCFG_CPU_ADD("maincpu", M6502, FREQ_17_EXACT)
1085
1086   /* video hardware */
1087   MCFG_SCREEN_ADD("screen", RASTER)
1088   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(1))
1089   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
1090   MCFG_SCREEN_VISIBLE_AREA(MIN_X, MAX_X, MIN_Y, MAX_Y)
1091   MCFG_PALETTE_LENGTH(sizeof(atari_palette) / 3)
1092   MCFG_PALETTE_INIT(mess_atari)
1093   MCFG_SCREEN_UPDATE(atari)
1094
1095   MCFG_VIDEO_START(atari)
1096
1097   MCFG_PIA6821_ADD( "pia", atari_pia_interface )
1098
1099   /* sound hardware */
1100   MCFG_SPEAKER_STANDARD_MONO("mono")
1101   MCFG_SOUND_ADD("pokey", POKEY, FREQ_17_EXACT)
1102   MCFG_SOUND_CONFIG(atari_pokey_interface)
1103   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
1104
1105   /* internal ram */
1106   MCFG_RAM_ADD(RAM_TAG)
1107   MCFG_RAM_DEFAULT_SIZE("40K")
1108MACHINE_CONFIG_END
1109
1110
1111static MACHINE_CONFIG_DERIVED( atari_common, atari_common_nodac )
1112   MCFG_SOUND_ADD("dac", DAC, 0)
1113   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
1114
1115   MCFG_ATARI_FDC_ADD("fdc")
1116MACHINE_CONFIG_END
1117
1118
1119static MACHINE_CONFIG_DERIVED( a400, atari_common )
1120
1121   MCFG_CPU_MODIFY( "maincpu" )
1122   MCFG_CPU_PROGRAM_MAP(a400_mem)
1123   MCFG_CPU_VBLANK_INT_HACK(a400_interrupt, TOTAL_LINES_60HZ)
1124
1125   MCFG_MACHINE_START( a400 )
1126
1127   MCFG_SCREEN_MODIFY("screen")
1128   MCFG_SCREEN_REFRESH_RATE(FRAME_RATE_60HZ)
1129   MCFG_SCREEN_SIZE(HWIDTH*8, TOTAL_LINES_60HZ)
1130
1131   MCFG_FRAGMENT_ADD(a400_cartslot)
1132
1133   /* software lists */
1134   MCFG_SOFTWARE_LIST_ADD("cart_list","a800")
1135MACHINE_CONFIG_END
1136
1137
1138static MACHINE_CONFIG_DERIVED( a400pal, atari_common )
1139
1140   MCFG_CPU_MODIFY( "maincpu" )
1141   MCFG_CPU_PROGRAM_MAP(a400_mem)
1142   MCFG_CPU_VBLANK_INT_HACK(a400_interrupt, TOTAL_LINES_50HZ)
1143
1144   MCFG_MACHINE_START( a400 )
1145
1146   MCFG_SCREEN_MODIFY("screen")
1147   MCFG_SCREEN_REFRESH_RATE(FRAME_RATE_50HZ)
1148   MCFG_SCREEN_SIZE(HWIDTH*8, TOTAL_LINES_50HZ)
1149
1150   MCFG_FRAGMENT_ADD(a400_cartslot)
1151
1152   /* software lists */
1153   MCFG_SOFTWARE_LIST_ADD("cart_list","a800")
1154MACHINE_CONFIG_END
1155
1156
1157static MACHINE_CONFIG_DERIVED( a800, atari_common )
1158
1159   MCFG_CPU_MODIFY( "maincpu" )
1160   MCFG_CPU_PROGRAM_MAP(a800_mem)
1161   MCFG_CPU_VBLANK_INT_HACK(a800_interrupt, TOTAL_LINES_60HZ)
1162
1163   MCFG_MACHINE_START( a800 )
1164
1165   MCFG_SCREEN_MODIFY("screen")
1166   MCFG_SCREEN_REFRESH_RATE(FRAME_RATE_60HZ)
1167   MCFG_SCREEN_SIZE(HWIDTH*8, TOTAL_LINES_60HZ)
1168
1169   MCFG_FRAGMENT_ADD(a800_cartslot)
1170
1171   /* software lists */
1172   MCFG_SOFTWARE_LIST_ADD("cart_list","a800")
1173MACHINE_CONFIG_END
1174
1175
1176static MACHINE_CONFIG_DERIVED( a800pal, atari_common )
1177
1178   MCFG_CPU_MODIFY( "maincpu" )
1179   MCFG_CPU_PROGRAM_MAP(a800_mem)
1180   MCFG_CPU_VBLANK_INT_HACK(a800_interrupt, TOTAL_LINES_50HZ)
1181
1182   MCFG_MACHINE_START( a800 )
1183
1184   MCFG_SCREEN_MODIFY("screen")
1185   MCFG_SCREEN_REFRESH_RATE(FRAME_RATE_50HZ)
1186   MCFG_SCREEN_SIZE(HWIDTH*8, TOTAL_LINES_50HZ)
1187
1188   MCFG_FRAGMENT_ADD(a800_cartslot)
1189
1190   /* software lists */
1191   MCFG_SOFTWARE_LIST_ADD("cart_list","a800")
1192MACHINE_CONFIG_END
1193
1194
1195static MACHINE_CONFIG_DERIVED( a600xl, atari_common )
1196
1197   MCFG_CPU_MODIFY( "maincpu" )
1198   MCFG_CPU_PROGRAM_MAP(a600xl_mem)   // FIXME?
1199   MCFG_CPU_VBLANK_INT_HACK(a800xl_interrupt, TOTAL_LINES_60HZ)
1200
1201   MCFG_PIA6821_MODIFY( "pia", a600xl_pia_interface )
1202
1203   MCFG_MACHINE_START( a800xl )   // FIXME?
1204
1205   MCFG_SCREEN_MODIFY("screen")
1206   MCFG_SCREEN_REFRESH_RATE(FRAME_RATE_60HZ)
1207   MCFG_SCREEN_SIZE(HWIDTH*8, TOTAL_LINES_60HZ)
1208
1209   MCFG_FRAGMENT_ADD(a400_cartslot)
1210
1211   /* software lists */
1212   MCFG_SOFTWARE_LIST_ADD("cart_list","a800")
1213
1214   /* internal ram */
1215   MCFG_RAM_MODIFY(RAM_TAG)
1216   MCFG_RAM_DEFAULT_SIZE("16K")
1217MACHINE_CONFIG_END
1218
1219
1220static MACHINE_CONFIG_DERIVED( a800xl, atari_common )
1221
1222   MCFG_CPU_MODIFY( "maincpu" )
1223   MCFG_CPU_PROGRAM_MAP(a800xl_mem)
1224   MCFG_CPU_VBLANK_INT_HACK(a800xl_interrupt, TOTAL_LINES_60HZ)
1225
1226   MCFG_PIA6821_MODIFY( "pia", a800xl_pia_interface )
1227
1228   MCFG_MACHINE_START( a800xl )
1229
1230   MCFG_SCREEN_MODIFY("screen")
1231   MCFG_SCREEN_REFRESH_RATE(FRAME_RATE_60HZ)
1232   MCFG_SCREEN_SIZE(HWIDTH*8, TOTAL_LINES_60HZ)
1233
1234   MCFG_FRAGMENT_ADD(a400_cartslot)
1235
1236   /* software lists */
1237   MCFG_SOFTWARE_LIST_ADD("cart_list","a800")
1238MACHINE_CONFIG_END
1239
1240static MACHINE_CONFIG_DERIVED( a800xlpal, a800xl )
1241
1242   MCFG_CPU_MODIFY( "maincpu" )
1243   MCFG_CPU_CLOCK( 1773000 )
1244   MCFG_CPU_VBLANK_INT_HACK(a800xl_interrupt, TOTAL_LINES_50HZ)
1245   MCFG_SCREEN_MODIFY("screen")
1246   MCFG_SCREEN_REFRESH_RATE(FRAME_RATE_50HZ)
1247   MCFG_SCREEN_SIZE(HWIDTH*8, TOTAL_LINES_50HZ)
1248
1249   MCFG_SOUND_MODIFY("pokey")
1250   MCFG_SOUND_CLOCK(1773000)
1251MACHINE_CONFIG_END
1252
1253static MACHINE_CONFIG_DERIVED( a1200xl, a800xl )
1254
1255   MCFG_PIA6821_MODIFY( "pia", a1200xl_pia_interface )
1256MACHINE_CONFIG_END
1257
1258static MACHINE_CONFIG_DERIVED( xegs, a800xl )
1259
1260   MCFG_CPU_MODIFY( "maincpu" )
1261   MCFG_CPU_PROGRAM_MAP(xegs_mem)
1262
1263   MCFG_MACHINE_START( xegs )
1264
1265   MCFG_PIA6821_MODIFY( "pia", xegs_pia_interface )
1266
1267   MCFG_DEVICE_REMOVE("cart1")
1268   MCFG_DEVICE_REMOVE("cart_list")
1269
1270   MCFG_CARTSLOT_ADD("cart1")
1271   MCFG_CARTSLOT_EXTENSION_LIST("rom,bin")
1272   MCFG_CARTSLOT_NOT_MANDATORY
1273   MCFG_CARTSLOT_LOAD(xegs_cart)
1274   MCFG_CARTSLOT_UNLOAD(xegs_cart)
1275   MCFG_CARTSLOT_INTERFACE("xegs_cart")
1276
1277   /* software lists */
1278   MCFG_SOFTWARE_LIST_ADD("cart_list","xegs")
1279MACHINE_CONFIG_END
1280
1281
1282static MACHINE_CONFIG_DERIVED( a5200, atari_common_nodac )
1283
1284   MCFG_CPU_MODIFY( "maincpu" )
1285   MCFG_CPU_PROGRAM_MAP(a5200_mem)
1286   MCFG_CPU_VBLANK_INT_HACK(a5200_interrupt, TOTAL_LINES_60HZ)
1287
1288   MCFG_DEVICE_REMOVE("pokey")
1289   MCFG_SOUND_ADD("pokey", POKEY, FREQ_17_EXACT)
1290   MCFG_SOUND_CONFIG(a5200_pokey_interface)
1291   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
1292
1293   MCFG_PIA6821_MODIFY( "pia", a5200_pia_interface )
1294
1295   MCFG_MACHINE_START( a5200 )
1296
1297   MCFG_SCREEN_MODIFY( "screen" )
1298   MCFG_SCREEN_REFRESH_RATE(FRAME_RATE_60HZ)
1299   MCFG_SCREEN_SIZE(HWIDTH*8, TOTAL_LINES_60HZ)
1300
1301   MCFG_CARTSLOT_ADD("cart")
1302   MCFG_CARTSLOT_EXTENSION_LIST("rom,bin,a52")
1303   MCFG_CARTSLOT_NOT_MANDATORY
1304   MCFG_CARTSLOT_LOAD(a5200_cart)
1305   MCFG_CARTSLOT_UNLOAD(a5200_cart)
1306   MCFG_CARTSLOT_INTERFACE("a5200_cart")
1307
1308   /* Software lists */
1309   MCFG_SOFTWARE_LIST_ADD("cart_list","a5200")
1310
1311   /* internal ram */
1312   MCFG_RAM_MODIFY(RAM_TAG)
1313   MCFG_RAM_DEFAULT_SIZE("16K")
1314MACHINE_CONFIG_END
1315
1316
1317/**************************************************************
1318 *
1319 * ROM loading
1320 *
1321 **************************************************************/
1322
1323ROM_START(a400)
1324   ROM_REGION(0x14000, "maincpu", 0) /* 64K for the CPU + 2 * 8K for cartridges */
1325   ROM_LOAD( "co12399b.rom", 0xd800, 0x0800, CRC(6a5d766e) SHA1(01a6044f7a81d409c938e7dfde0a1af5832229d2) )
1326   ROM_SYSTEM_BIOS(0, "default", "OS Rev. B")
1327   ROMX_LOAD( "co12499b.rom",  0xe000, 0x1000, BAD_DUMP CRC(d818f3e8) SHA1(bcdec2188f6a6a5bfc1df4e383bd828d34b5c4ac), ROM_BIOS(1) )   // CRC and label waiting for confirmation
1328   ROMX_LOAD( "co14599b.rom",  0xf000, 0x1000, BAD_DUMP CRC(c1690a9b) SHA1(c5248e8565574fd39ae1c3f4f356aa4cac07df95), ROM_BIOS(1) )   // CRC and label waiting for confirmation
1329   ROM_SYSTEM_BIOS(1, "reva", "OS Rev. A")
1330   ROMX_LOAD( "co12499a.rom",  0xe000, 0x1000, BAD_DUMP CRC(29f64e17) SHA1(abf7ec488c6b600f1b7f30bdc7f8a2bf6a727675), ROM_BIOS(2) )   // CRC and label waiting for confirmation
1331   ROMX_LOAD( "co14599a.rom",  0xf000, 0x1000, BAD_DUMP CRC(bc533f0c) SHA1(e217148495fa747fe5488132d8d22533e68c7e58), ROM_BIOS(2) )   // CRC and label waiting for confirmation
1332
1333   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1334ROM_END
1335
1336ROM_START(a400pal)
1337   ROM_REGION(0x14000, "maincpu", 0) /* 64K for the CPU + 2 * 8K for cartridges */
1338   ROM_LOAD( "co12399b.rom", 0xd800, 0x0800, CRC(6a5d766e) SHA1(01a6044f7a81d409c938e7dfde0a1af5832229d2) )
1339   ROM_LOAD( "co15199.rom", 0xe000, 0x1000, BAD_DUMP CRC(8e547f56) SHA1(1bd746ea798b723bfb18495a7facca113183d713) )   // Rev. A - CRC and label waiting for confirmation
1340   ROM_LOAD( "co15299.rom", 0xf000, 0x1000, BAD_DUMP CRC(be55b413) SHA1(d88afae49b08e75943d0258cb580e5d34756414a) )   // Rev. A - CRC and label waiting for confirmation
1341
1342   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1343ROM_END
1344
1345ROM_START(a800)
1346   ROM_REGION(0x14000, "maincpu", 0) /* 64K for the CPU + 2 * 8K for cartridges */
1347   ROM_LOAD( "co12399b.rom", 0xd800, 0x0800, CRC(6a5d766e) SHA1(01a6044f7a81d409c938e7dfde0a1af5832229d2) )
1348   ROM_SYSTEM_BIOS(0, "default", "OS Rev. B")
1349   ROMX_LOAD( "co12499b.rom",  0xe000, 0x1000, BAD_DUMP CRC(d818f3e8) SHA1(bcdec2188f6a6a5bfc1df4e383bd828d34b5c4ac), ROM_BIOS(1) )   // CRC and label waiting for confirmation
1350   ROMX_LOAD( "co14599b.rom",  0xf000, 0x1000, BAD_DUMP CRC(c1690a9b) SHA1(c5248e8565574fd39ae1c3f4f356aa4cac07df95), ROM_BIOS(1) )   // CRC and label waiting for confirmation
1351   ROM_SYSTEM_BIOS(1, "reva", "OS Rev. A")
1352   ROMX_LOAD( "co12499a.rom",  0xe000, 0x1000, BAD_DUMP CRC(29f64e17) SHA1(abf7ec488c6b600f1b7f30bdc7f8a2bf6a727675), ROM_BIOS(2) )   // CRC and label waiting for confirmation
1353   ROMX_LOAD( "co14599a.rom",  0xf000, 0x1000, BAD_DUMP CRC(bc533f0c) SHA1(e217148495fa747fe5488132d8d22533e68c7e58), ROM_BIOS(2) )   // CRC and label waiting for confirmation
1354
1355   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1356
1357   ROM_REGION(0x2000, "rslot", ROMREGION_ERASEFF)
1358ROM_END
1359
1360ROM_START(a800pal)
1361   ROM_REGION(0x14000, "maincpu", 0) /* 64K for the CPU + 2 * 8K for cartridges */
1362   ROM_LOAD( "co12399b.rom", 0xd800, 0x0800, CRC(6a5d766e) SHA1(01a6044f7a81d409c938e7dfde0a1af5832229d2) )
1363   ROM_LOAD( "co15199.rom", 0xe000, 0x1000, BAD_DUMP CRC(8e547f56) SHA1(1bd746ea798b723bfb18495a7facca113183d713) )   // Rev. A - CRC and label waiting for confirmation
1364   ROM_LOAD( "co15299.rom", 0xf000, 0x1000, BAD_DUMP CRC(be55b413) SHA1(d88afae49b08e75943d0258cb580e5d34756414a) )   // Rev. A - CRC and label waiting for confirmation
1365
1366   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1367
1368   ROM_REGION(0x2000, "rslot", ROMREGION_ERASEFF)
1369ROM_END
1370
1371ROM_START(a1200xl)
1372   ROM_REGION(0x18000, "maincpu", 0)
1373   ROM_SYSTEM_BIOS(0, "default", "OS Rev. 11")
1374   ROMX_LOAD( "co60616b.rom", 0x14000, 0x2000, BAD_DUMP CRC(6e29ec8d) SHA1(3f9c06d6b4d261f3d5bf4354e3cff0c17b9347b9), ROM_BIOS(1) )   // CRC and label waiting for confirmation
1375   ROMX_LOAD( "co60617b.rom", 0x16000, 0x2000, BAD_DUMP CRC(d73ce29a) SHA1(64790242d902643fe0c40dd842749f1fe461831b), ROM_BIOS(1) )   // CRC and label waiting for confirmation
1376   ROM_SYSTEM_BIOS(1, "rev10", "OS Rev. 10")
1377   ROMX_LOAD( "co60616a.rom", 0x14000, 0x2000, BAD_DUMP CRC(0391386b) SHA1(7c176657c88b89b8a69bf021fa8e0939efc0dff2), ROM_BIOS(2) )   // CRC and label waiting for confirmation
1378   ROMX_LOAD( "co60617a.rom", 0x16000, 0x2000, BAD_DUMP CRC(b502f1e7) SHA1(6688db57d97fa570aef5c15cef3e5fb2688879c2), ROM_BIOS(2) )   // CRC and label waiting for confirmation
1379
1380   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1381ROM_END
1382
1383ROM_START(a600xl)
1384   ROM_REGION(0x10000, "maincpu", 0)
1385   ROM_LOAD( "co60302a.rom", 0xa000, 0x2000, CRC(f0202fb3) SHA1(7ad88dd99ff4a6ee66f6d162074db6f8bef7a9b6) )   // Rev. B
1386   ROM_LOAD( "co62024.rom",  0xc000, 0x4000, CRC(643bcc98) SHA1(881d030656b40bbe48f15a696b28f22c0b752ab0) )   // Rev. 1
1387
1388   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1389ROM_END
1390
1391ROM_START(a800xl)
1392   ROM_REGION(0x18000, "maincpu", 0)
1393   ROM_FILL( 0, 0x10000, 0x00 )
1394   ROM_LOAD( "co60302a.rom", 0x10000, 0x2000, CRC(f0202fb3) SHA1(7ad88dd99ff4a6ee66f6d162074db6f8bef7a9b6) )   // Rev. B
1395   ROM_LOAD( "co61598b.rom", 0x14000, 0x4000, CRC(1f9cd270) SHA1(ae4f523ba08b6fd59f3cae515a2b2410bbd98f55) )   // Rev. 2
1396
1397   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1398ROM_END
1399
1400#define rom_a800xlp rom_a800xl
1401
1402ROM_START(a65xe)
1403   ROM_REGION(0x18000, "maincpu", 0)
1404   ROM_LOAD( "co24947a.rom", 0x10000, 0x2000, CRC(7d684184) SHA1(3693c9cb9bf3b41bae1150f7a8264992468fc8c0) )   // Rev. C
1405   ROM_LOAD( "co61598b.rom", 0x14000, 0x4000, CRC(1f9cd270) SHA1(ae4f523ba08b6fd59f3cae515a2b2410bbd98f55) )   // Rev. 2
1406
1407   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1408ROM_END
1409
1410ROM_START(a65xea)
1411   ROM_REGION(0x18000, "maincpu", 0)
1412   ROM_LOAD( "basic_ar.rom", 0x10000, 0x2000, CRC(c899f4d6) SHA1(043df191d1fe402e792266a108e147ffcda35130) )   // is this correct? or shall we use Rev. C?
1413//  ROM_LOAD( "c101700.rom",  0x14000, 0x4000, CRC(7f9a76c8) SHA1(57eb6d87850a763f11767f53d4eaede186f831a2) )   // this was from Savetz and has wrong bits!
1414   ROM_LOAD( "c101700.rom",  0x14000, 0x4000, CRC(45f47988) SHA1(a36b8b20f657580f172749bb0625c08706ed824c) )   // Rev. 3B ?
1415
1416   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1417ROM_END
1418
1419ROM_START(a130xe)
1420   ROM_REGION(0x18000, "maincpu", 0)
1421   ROM_LOAD( "co24947a.rom", 0x10000, 0x2000, CRC(7d684184) SHA1(3693c9cb9bf3b41bae1150f7a8264992468fc8c0) )   // Rev. C
1422   ROM_LOAD( "co61598b.rom", 0x14000, 0x4000, CRC(1f9cd270) SHA1(ae4f523ba08b6fd59f3cae515a2b2410bbd98f55) )   // Rev. 2
1423
1424   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1425ROM_END
1426
1427ROM_START(a800xe)
1428   ROM_REGION(0x18000, "maincpu", 0)
1429   ROM_LOAD( "co24947a.rom", 0x10000, 0x2000, CRC(7d684184) SHA1(3693c9cb9bf3b41bae1150f7a8264992468fc8c0) )   // Rev. C
1430   ROM_LOAD( "c300717.rom",  0x14000, 0x4000, CRC(29f133f7) SHA1(f03b9b93000ee84abb9cf8d6367241006f172182) )   // Rev. 3
1431
1432   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1433ROM_END
1434
1435ROM_START(xegs)
1436   ROM_REGION(0x1a000, "maincpu", 0)
1437   ROM_LOAD( "c101687.rom", 0x10000, 0x8000, CRC(d50260d1) SHA1(0e0625ab2473f8431640df3ac8af61925760b9b9) )   // Rev. C + Rev. 4 + Missile Command
1438
1439   ROM_REGION(0x20000, "user1", ROMREGION_ERASE00)
1440ROM_END
1441
1442
1443ROM_START(a5200)
1444   ROM_REGION(0x14000, "maincpu", 0) /* 64K for the CPU + 16K for cartridges */
1445   ROM_SYSTEM_BIOS(0, "default", "a5200")
1446   ROMX_LOAD( "5200.rom",  0xf800, 0x0800, CRC(4248d3e3) SHA1(6ad7a1e8c9fad486fbec9498cb48bf5bc3adc530), ROM_BIOS(1) )
1447   ROM_SYSTEM_BIOS(1, "alt", "a5200 (alt)")
1448   ROMX_LOAD( "5200a.rom", 0xf800, 0x0800, CRC(c2ba2613) SHA1(1d2a3f00109d75d2d79fecb565775eb95b7d04d5), ROM_BIOS(2) )
1449ROM_END
1450
1451/**************************************************************
1452 *
1453 * Driver initializations
1454 *
1455 **************************************************************/
1456
1457static DRIVER_INIT( a800xl )
1458{
1459   a800xl_mmu(machine, 0xff);
1460}
1461
1462static DRIVER_INIT( xegs )
1463{
1464   xegs_mmu(machine, 0xff);
1465}
1466
1467static DRIVER_INIT( a600xl )
1468{
1469   UINT8 *rom = machine.region("maincpu")->base();
1470   memcpy( rom + 0x5000, rom + 0xd000, 0x800 );
1471}
1472
1473/**************************************************************
1474 *
1475 * Game driver(s)
1476 *
1477 **************************************************************/
1478
1479/*     YEAR  NAME      PARENT    COMPAT MACHINE     INPUT    INIT      COMPANY    FULLNAME */
1480COMP ( 1979, a400,     0,        0,     a400,       a800,    0,      "Atari",   "Atari 400 (NTSC)", 0)
1481COMP ( 1979, a400pal,  a400,     0,     a400pal,    a800,    0,      "Atari",   "Atari 400 (PAL)",  0)
1482COMP ( 1979, a800,     0,        0,     a800,       a800,    0,      "Atari",   "Atari 800 (NTSC)", 0)
1483COMP ( 1979, a800pal,  a800,     0,     a800pal,    a800,    0,      "Atari",   "Atari 800 (PAL)",  0)
1484COMP ( 1982, a1200xl,  a800,     0,     a1200xl,    a800xl,  a800xl, "Atari",   "Atari 1200XL",     GAME_NOT_WORKING )      // 64k RAM
1485COMP ( 1983, a600xl,   a800xl,   0,     a600xl,     a800xl,  a600xl, "Atari",   "Atari 600XL",      GAME_NOT_WORKING )      // 16k RAM
1486COMP ( 1983, a800xl,   0,       0,     a800xl,     a800xl,  a800xl, "Atari",   "Atari 800XL (NTSC)",GAME_IMPERFECT_GRAPHICS )      // 64k RAM
1487COMP ( 1983, a800xlp,  a800xl,    0,     a800xlpal,  a800xl,  a800xl, "Atari",   "Atari 800XL (PAL)", GAME_IMPERFECT_GRAPHICS )      // 64k RAM
1488COMP ( 1986, a65xe,    a800xl,   0,     a800xl,     a800xl,  a800xl, "Atari",   "Atari 65XE",       GAME_NOT_WORKING )      // 64k RAM
1489COMP ( 1986, a65xea,   a800xl,   0,     a800xl,     a800xl,  a800xl, "Atari",   "Atari 65XE (Arabic)", GAME_NOT_WORKING )
1490COMP ( 1986, a130xe,   a800xl,   0,     a800xl,     a800xl,  a800xl, "Atari",   "Atari 130XE",      GAME_NOT_WORKING )      // 128k RAM
1491COMP ( 1986, a800xe,   a800xl,   0,     a800xl,     a800xl,  a800xl, "Atari",   "Atari 800XE",      GAME_NOT_WORKING )      // 64k RAM
1492COMP ( 1987, xegs,     0,        0,     xegs,       a800xl,  xegs,   "Atari",   "Atari XE Game System", GAME_NOT_WORKING )   // 64k RAM
1493
1494CONS ( 1982, a5200,    0,        0,     a5200,      a5200,   0,      "Atari",   "Atari 5200",       0)
src/mame/drivers/astrocdh.c
r0r11461
1/****************************************************************************
2
3    Bally Astrocade consumer hardware
4    driver by Nicola Salmoria, Mike Coates, Frank Palazzolo, Aaron Giles,
5    Dirk Best
6
7****************************************************************************/
8
9#include "emu.h"
10#include "cpu/z80/z80.h"
11#include "includes/astrocde.h"
12#include "sound/astrocde.h"
13#include "imagedev/cartslot.h"
14#include "machine/ram.h"
15
16MACHINE_RESET( astrocde );
17void get_ram_expansion_settings(address_space *space, int &ram_expansion_installed, int &write_protect_on, int &expansion_ram_start, int &expansion_ram_end, int &shadow_ram_end);
18
19/*************************************
20 *
21 *  Memory maps
22 *
23 * $0000 to $1FFF:  8K on-board ROM (could be one of three available BIOS dumps)
24 * $2000 to $3FFF:  8K cartridge ROM
25 * $4000 to $4FFF:  4K screen RAM
26 * $5000 to $FFFF:  44K address space not available in standard machine.  With a
27 * sufficiently large RAM expansion, all of this RAM can be added, and accessed
28 * by an extended BASIC program.  Bally and Astrocade BASIC can access from
29 * $5000 to $7FFF if available.
30 *
31 *  RAM Expansions
32 *
33 * Several third party RAM expansions have been made for the Astrocade.  These
34 * allow access to various ranges of the expansion memory ($5000 to $FFFF).
35 * A RAM expansion is required to use extended BASIC programs like Blue RAM BASIC
36 * and VIPERSoft BASIC.  All of the expansions also have a RAM protect switch, which
37 * can be flipped at any time to make the RAM act like ROM.  Extended BASIC
38 * programs need access to the RAM and won't work with RAM protect enabled, but
39 * this can be useful with Bally and Astrocade BASIC.  They also have a range switch
40 * (not implemented).  The default position is 6K, but it can be switched to
41 * 2K.  This means that the expanded memory starting at $6000 will instead be
42 * mapped to the cartridge memory starting at $2000.  So it would be possible to
43 * load a cartridge program from tape into the expansion memory, then flip the range
44 * switch and run it as a cartridge.  This is useful for cartridge development.
45 *
46 * NOTE:  If you have any trouble running cartridges with a RAM expansion installed, hit reset.
47 *
48 * Blue RAM -- available in 4K, 16K, and 32K.  These also use an INS8154 chip,
49 * (not yet implemented) which has an additional $80 bytes of RAM mapped
50 * immediately after the end of the expansion address space.  This memory
51 * can't be write protected.  The INS8154 has I/O features needed for loading
52 * tape programs into Blue RAM BASIC, as well as running the Blue RAM Utility cart.
53 * 4K:  $6000 to $6FFF (can't run VIPERSoft BASIC, because this program needs memory
54 * past this range)
55 * 16K:  $6000 to $9FFF
56 * 32K:  $6000 to $DFFF
57 *
58 * VIPER System 1 -- This is available in 16K only.  It also includes a keyboard (not implemented).
59 * 16K:  $6000 to $9FFF
60 *
61 * Lil' WHITE RAM -- This is available in 32K only.  Attempts to read and write
62 * to memory outside of its address range ($D000 to $FFFF) are mapped to the expansion
63 * memory $5000 to $7FFF.  The current implementation won't allow the shadow RAM area
64 * to be accessed when RAM protect is on, but there is no known software that will
65 * access the upper range of the expansion RAM when RAM protect is enabled.
66 * 32K:  $5000 to $CFFF
67 *
68 * R&L 64K RAM Board -- This is a highly configurable kit.  RAM can be installed in
69 * 2K increments.  So, the entire 44K expansion memory can be filled.  It is also
70 * possible to override the rest of the memory map with RAM (not implemented).
71 * There are 32 switches allowing users to activate and deactivate each 2K block (not implemented).
72 * RAM write protection can be implemented in three ranges through jumpers or by
73 * installing switches.  The ranges are $0000 to $0FFF (first 4K), $0000 to $3FFF (first 16K),
74 * and $0000 to $FFFF (all 64K).  The current implementation is for 44K expansion memory mapped from
75 * $5000 to $FFFF, with only a single write protect covering this entire range.
76 *
77 *************************************/
78
79static ADDRESS_MAP_START( astrocade_mem, AS_PROGRAM, 8 )
80   AM_RANGE(0x0000, 0x0fff) AM_ROM AM_WRITE(astrocade_funcgen_w)
81   AM_RANGE(0x1000, 0x3fff) AM_ROM /* Star Fortress writes in here?? */
82   AM_RANGE(0x4000, 0x4fff) AM_RAM AM_BASE_MEMBER(astrocde_state, m_videoram) /* ASG */
83ADDRESS_MAP_END
84
85
86static ADDRESS_MAP_START( astrocade_io, AS_IO, 8 )
87   AM_RANGE(0x00, 0x1f) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_READWRITE(astrocade_data_chip_register_r, astrocade_data_chip_register_w)
88ADDRESS_MAP_END
89
90static INPUT_CHANGED( set_write_protect )  // run when RAM expansion write protect switch is changed
91{
92   int ram_expansion_installed = 0, write_protect_on = 0, expansion_ram_start = 0, expansion_ram_end = 0, shadow_ram_end = 0;
93   address_space *space = field->port->machine().device("maincpu")->memory().space(AS_PROGRAM);
94   UINT8 *expram = ram_get_ptr(field->port->machine().device("ram_tag"));
95
96   get_ram_expansion_settings(space, ram_expansion_installed, write_protect_on, expansion_ram_start, expansion_ram_end, shadow_ram_end);  // passing by reference
97
98    if (ram_expansion_installed == 1)
99    {
100        if (write_protect_on == 0)  // write protect off, so install memory normally
101        {
102            space->install_ram(expansion_ram_start, expansion_ram_end, expram);
103            if (shadow_ram_end > expansion_ram_end)
104                space->install_ram(expansion_ram_end + 1, shadow_ram_end, expram);
105        }
106        else  // write protect on, so make memory read only
107        {
108            space->nop_write(expansion_ram_start, expansion_ram_end);
109        }
110     }
111}
112
113/*************************************
114 *
115 *  Input ports
116 *
117 *
118 *  The Astrocade has ports for four hand controllers.  Each controller has a
119 *  knob on top that can be simultaneously pushed as an eight-way joystick and
120 *  twisted as a paddle, in addition to a trigger button.  The knob can twist
121 *  through about 270 degrees, registering 256 unique positions.  It does not
122 *  autocenter.  When selecting options on the menu, twisting the knob to the
123 *  right gives lower numbers, and twisting to the left gives larger numbers.
124 *  Paddle games like Clowns have more intuitive behavior -- twisting to the
125 *  right moves the character right.
126 *
127 *  There is a 24-key keypad on the system itself (6 rows, 4 columns).  It is
128 *  labeled for the built-in calculator, but overlays were released for other
129 *  programs, the most popular being the BASIC cartridges, which allowed a
130 *  large number of inputs by making the bottom row shift buttons.  The labels
131 *  below first list the calculator key, then the BASIC keys in the order of no
132 *  shift, GREEN shift, RED shift, BLUE shift, WORDS shift.
133 *
134 *************************************/
135
136static INPUT_PORTS_START( astrocde )
137   PORT_START("P1HANDLE")
138   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP)    PORT_PLAYER(1) PORT_8WAY
139   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN)  PORT_PLAYER(1) PORT_8WAY
140   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT)  PORT_PLAYER(1) PORT_8WAY
141   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT) PORT_PLAYER(1) PORT_8WAY
142   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_BUTTON1)        PORT_PLAYER(1)
143   PORT_BIT(0xe0, IP_ACTIVE_HIGH, IPT_UNUSED)
144
145   PORT_START("P2HANDLE")
146   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP)    PORT_PLAYER(2) PORT_8WAY
147   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN)  PORT_PLAYER(2) PORT_8WAY
148   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT)  PORT_PLAYER(2) PORT_8WAY
149   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT) PORT_PLAYER(2) PORT_8WAY
150   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_BUTTON1)        PORT_PLAYER(2)
151   PORT_BIT(0xe0, IP_ACTIVE_HIGH, IPT_UNUSED)
152
153   PORT_START("P3HANDLE")
154   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP)    PORT_PLAYER(3) PORT_8WAY
155   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN)  PORT_PLAYER(3) PORT_8WAY
156   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT)  PORT_PLAYER(3) PORT_8WAY
157   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT) PORT_PLAYER(3) PORT_8WAY
158   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_BUTTON1)        PORT_PLAYER(3)
159   PORT_BIT(0xe0, IP_ACTIVE_HIGH, IPT_UNUSED)
160
161   PORT_START("P4HANDLE")
162   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP)    PORT_PLAYER(4) PORT_8WAY
163   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN)  PORT_PLAYER(4) PORT_8WAY
164   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT)  PORT_PLAYER(4) PORT_8WAY
165   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT) PORT_PLAYER(4) PORT_8WAY
166   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_BUTTON1)        PORT_PLAYER(4)
167   PORT_BIT(0xe0, IP_ACTIVE_HIGH, IPT_UNUSED)
168
169   PORT_START("KEYPAD0")
170   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("%   \xC3\xB7         [   ]   LIST") PORT_CODE(KEYCODE_O)
171   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("/   x     J   K   L   NEXT") PORT_CODE(KEYCODE_SLASH_PAD)
172   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("x   -     V   W   X   IF") PORT_CODE(KEYCODE_ASTERISK)
173   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("-   +     &   @   *   GOTO") PORT_CODE(KEYCODE_MINUS_PAD)
174   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("+   =     #   %   :   PRINT") PORT_CODE(KEYCODE_PLUS_PAD)
175   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("=   WORDS Shift") PORT_CODE(KEYCODE_ENTER_PAD)
176   PORT_BIT(0xc0, IP_ACTIVE_HIGH, IPT_UNUSED )
177
178   PORT_START("KEYPAD1")
179   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("\xE2\x86\x93   HALT              RUN") PORT_CODE(KEYCODE_PGDN)
180   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("CH  9     G   H   I   STEP") PORT_CODE(KEYCODE_H)
181   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("9   6     S   T   U   RND") PORT_CODE(KEYCODE_9)
182   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("6   3     \xE2\x86\x91   .   \xE2\x86\x93   BOX") PORT_CODE(KEYCODE_6)
183   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("3   ERASE (   ;   )") PORT_CODE(KEYCODE_3)
184   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME(".   BLUE Shift") PORT_CODE(KEYCODE_STOP)
185   PORT_BIT(0xc0, IP_ACTIVE_HIGH, IPT_UNUSED)
186
187   PORT_START("KEYPAD2")
188   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("\xE2\x86\x91   PAUSE     /   \\") PORT_CODE(KEYCODE_PGUP)
189   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("MS  8     D   E   F   TO") PORT_CODE(KEYCODE_S)
190   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("8   5     P   Q   R   RETN") PORT_CODE(KEYCODE_8)
191   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("5   2     \xE2\x86\x90   '   \xE2\x86\x92   LINE") PORT_CODE(KEYCODE_5)
192   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("2   0     <   \"   >   INPUT") PORT_CODE(KEYCODE_2)
193   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("0   RED Shift") PORT_CODE(KEYCODE_0)
194   PORT_BIT(0xc0, IP_ACTIVE_HIGH, IPT_UNUSED)
195
196   PORT_START("KEYPAD3")
197   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("C   GO                +10") PORT_CODE(KEYCODE_C)
198   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("MR  7     A   B   C   FOR") PORT_CODE(KEYCODE_R)
199   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("7   4     M   N   O   GOSB") PORT_CODE(KEYCODE_7)
200   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("4   1     Y   Z   !   CLEAR") PORT_CODE(KEYCODE_4)
201   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("1   SPACE $   ,   ?") PORT_CODE(KEYCODE_1)
202   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("CE  GREEN Shift") PORT_CODE(KEYCODE_E)
203   PORT_BIT(0xc0, IP_ACTIVE_HIGH, IPT_UNUSED)
204
205   PORT_START("P1_KNOB")
206   PORT_BIT(0xff, 0x00, IPT_PADDLE) PORT_INVERT PORT_SENSITIVITY(85) PORT_KEYDELTA(10) PORT_CENTERDELTA(0) PORT_MINMAX(0,255) PORT_CODE_DEC(KEYCODE_Z) PORT_CODE_INC(KEYCODE_X) PORT_PLAYER(1)
207
208   PORT_START("P2_KNOB")
209   PORT_BIT(0xff, 0x00, IPT_PADDLE) PORT_INVERT PORT_SENSITIVITY(85) PORT_KEYDELTA(10) PORT_CENTERDELTA(0) PORT_MINMAX(0,255) PORT_CODE_DEC(KEYCODE_N) PORT_CODE_INC(KEYCODE_M) PORT_PLAYER(2)
210
211   PORT_START("P3_KNOB")
212   PORT_BIT(0xff, 0x00, IPT_PADDLE) PORT_INVERT PORT_SENSITIVITY(85) PORT_KEYDELTA(10) PORT_CENTERDELTA(0) PORT_MINMAX(0,255) PORT_CODE_DEC(KEYCODE_Q) PORT_CODE_INC(KEYCODE_W) PORT_PLAYER(3)
213
214   PORT_START("P4_KNOB")
215   PORT_BIT(0xff, 0x00, IPT_PADDLE) PORT_INVERT PORT_SENSITIVITY(85) PORT_KEYDELTA(10) PORT_CENTERDELTA(0) PORT_MINMAX(0,255) PORT_CODE_DEC(KEYCODE_Y) PORT_CODE_INC(KEYCODE_U) PORT_PLAYER(4)
216
217    PORT_START("CFG")   /* machine config */
218   PORT_DIPNAME( 0x3f, 0x00, "RAM Expansion")
219   PORT_DIPSETTING(   0x00, "No RAM Expansion")
220   PORT_DIPSETTING(   0x01, "16KB Viper System 1 RAM Expansion")
221   PORT_DIPSETTING(   0x02, "32KB Lil' WHITE RAM Expansion")
222   PORT_DIPSETTING(   0x04, "R&L 64K RAM Board (44K installed)")
223   PORT_DIPSETTING(   0x08, "4KB Blue RAM Expansion")
224   PORT_DIPSETTING(   0x10, "16KB Blue RAM Expansion")
225   PORT_DIPSETTING(   0x20, "32KB Blue RAM Expansion")
226
227   PORT_START("PROTECT")  /* Write protect RAM */
228   PORT_DIPNAME( 0x01, 0x00, "Write Protect RAM") PORT_CHANGED(set_write_protect, 0)
229   PORT_DIPSETTING( 0x00, "Write Protect Off")
230   PORT_DIPSETTING( 0x01, "Write Protect On")
231INPUT_PORTS_END
232
233
234/*************************************
235 *
236 *  Machine drivers
237 *
238 *************************************/
239
240static MACHINE_CONFIG_START( astrocde, astrocde_state )
241   /* basic machine hardware */
242   MCFG_CPU_ADD("maincpu", Z80, ASTROCADE_CLOCK/4)        /* 1.789 MHz */
243   MCFG_CPU_PROGRAM_MAP(astrocade_mem)
244   MCFG_CPU_IO_MAP(astrocade_io)
245
246   MCFG_MACHINE_RESET( astrocde )
247
248   /* video hardware */
249   MCFG_SCREEN_ADD("screen", RASTER)
250   MCFG_SCREEN_RAW_PARAMS(ASTROCADE_CLOCK, 455, 0, 352, 262, 0, 240)
251   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
252   MCFG_SCREEN_UPDATE(astrocde)
253
254   MCFG_PALETTE_LENGTH(512)
255   MCFG_PALETTE_INIT(astrocde)
256
257   MCFG_VIDEO_START(astrocde)
258
259   /* sound hardware */
260   MCFG_SPEAKER_STANDARD_MONO("mono")
261   MCFG_SOUND_ADD("astrocade1", ASTROCADE, ASTROCADE_CLOCK/4)
262   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
263
264    /* optional expansion ram (installed in MACHINE_RESET)*/
265   MCFG_RAM_ADD("ram_tag")
266   MCFG_RAM_DEFAULT_SIZE("32k")
267
268   /* cartridge */
269   MCFG_CARTSLOT_ADD("cart")
270   MCFG_CARTSLOT_EXTENSION_LIST("bin")
271   MCFG_CARTSLOT_INTERFACE("astrocde_cart")
272
273   /* Software lists */
274   MCFG_SOFTWARE_LIST_ADD("cart_list","astrocde")
275MACHINE_CONFIG_END
276
277
278/*************************************
279 *
280 *  ROM definitions
281 *
282 *************************************/
283
284ROM_START( astrocde )
285   ROM_REGION( 0x10000, "maincpu", 0 )
286   ROM_LOAD( "astro.bin",  0x0000, 0x2000, CRC(ebc77f3a) SHA1(b902c941997c9d150a560435bf517c6a28137ecc) )
287   ROM_CART_LOAD( "cart", 0x2000, 0x8000, 0 )
288ROM_END
289
290ROM_START( astrocdl )
291   ROM_REGION( 0x10000, "maincpu", 0 )
292   ROM_LOAD( "ballyhlc.bin",  0x0000, 0x2000, CRC(d7c517ba) SHA1(6b2bef5d970e54ed204549f58ba6d197a8bfd3cc) )
293   ROM_CART_LOAD( "cart", 0x2000, 0x8000, 0 )
294ROM_END
295
296ROM_START( astrocdw )
297   ROM_REGION( 0x10000, "maincpu", 0 )
298   ROM_LOAD( "bioswhit.bin",  0x0000, 0x2000, CRC(6eb53e79) SHA1(d84341feec1a0a0e8aa6151b649bc3cf6ef69fbf) )
299   ROM_CART_LOAD( "cart", 0x2000, 0x8000, 0 )
300ROM_END
301
302/*************************************
303 *
304 *  Driver initialization
305 *
306 *************************************/
307
308static DRIVER_INIT( astrocde )
309{
310   astrocde_state *state = machine.driver_data<astrocde_state>();
311   state->m_video_config = AC_SOUND_PRESENT | AC_LIGHTPEN_INTS;
312}
313
314MACHINE_RESET( astrocde )
315{
316    int ram_expansion_installed = 0, write_protect_on = 0, expansion_ram_start = 0, expansion_ram_end = 0, shadow_ram_end = 0;
317    address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
318    UINT8 *expram = ram_get_ptr(machine.device("ram_tag"));
319    space->unmap_readwrite(0x5000, 0xffff);  // unmap any previously installed expansion RAM
320
321    get_ram_expansion_settings(space, ram_expansion_installed, write_protect_on, expansion_ram_start, expansion_ram_end, shadow_ram_end);  // passing by reference
322
323    if (ram_expansion_installed == 1)
324    {
325        if (write_protect_on == 0)  // write protect off, so install memory normally
326        {
327            space->install_ram(expansion_ram_start, expansion_ram_end, expram);
328            if (shadow_ram_end > expansion_ram_end)
329                space->install_ram(expansion_ram_end + 1, shadow_ram_end, expram);
330        }
331        else  // write protect on, so make memory read only
332        {
333            space->nop_write(expansion_ram_start, expansion_ram_end);
334        }
335     }
336}
337
338void get_ram_expansion_settings(address_space *space, int &ram_expansion_installed, int &write_protect_on, int &expansion_ram_start, int &expansion_ram_end, int &shadow_ram_end)
339{
340    if (input_port_read(space->machine(), "PROTECT") == 0x01)
341        write_protect_on = 1;
342    else
343        write_protect_on = 0;
344
345    ram_expansion_installed = 1;
346
347    switch(input_port_read(space->machine(), "CFG"))  // check RAM expansion configuration and set address ranges
348    {
349        case 0x00:  // No RAM Expansion
350             ram_expansion_installed = 0;
351             break;
352        case 0x01:  // 16KB Viper System 1 RAM Expansion
353             expansion_ram_start = 0x6000;
354             expansion_ram_end = 0x9fff;
355             shadow_ram_end = 0;
356             break;
357        case 0x02:  // "32KB Lil' WHITE RAM Expansion
358             expansion_ram_start = 0x5000;
359             expansion_ram_end = 0xcfff;
360             shadow_ram_end = 0xffff;
361             break;
362        case 0x04:  // R&L 64K RAM Board (44KB installed)
363             expansion_ram_start = 0x5000;
364             expansion_ram_end = 0xffff;
365             shadow_ram_end = 0;
366             break;
367        case 0x08:  // 4KB Blue RAM Expansion
368             expansion_ram_start = 0x6000;
369             expansion_ram_end = 0x6fff;
370             shadow_ram_end = 0;
371             break;
372        case 0x10:  // 16KB Blue RAM Expansion
373             expansion_ram_start = 0x6000;
374             expansion_ram_end = 0x9fff;
375             shadow_ram_end = 0;
376             break;
377        case 0x20:  // 32KB Blue RAM Expansion
378             expansion_ram_start = 0x6000;
379             expansion_ram_end = 0xdfff;
380             shadow_ram_end = 0;
381             break;
382        default:
383            break;
384    }
385}
386
387
388/*************************************
389 *
390 *  Driver definitions
391 *
392 *************************************/
393
394/*    YEAR  NAME      PARENT    COMPAT    MACHINE   INPUT     INIT      COMPANY                FULLNAME                     FLAGS */
395CONS( 1978, astrocde, 0,        0,        astrocde, astrocde, astrocde, "Bally Manufacturing", "Bally Professional Arcade", GAME_SUPPORTS_SAVE )
396CONS( 1977, astrocdl, astrocde, 0,        astrocde, astrocde, astrocde, "Bally Manufacturing", "Bally Home Library Computer", GAME_SUPPORTS_SAVE )
397CONS( 1977, astrocdw, astrocde, 0,        astrocde, astrocde, astrocde, "Bally Manufacturing", "Bally Computer System", GAME_SUPPORTS_SAVE )
src/mame/drivers/msx.c
r0r11461
1/*
2** msx.c : driver for MSX
3**
4** Todo:
5** - Add support for other MSX models (de,fr,jp,ru etc.)
6
7This following list is probably incomplete. Corrections are welcome.
8
9Al Alamiah AX-170
10Al Alamiah AX-350
11Al Alamiah AX-370
12Canon V-10
13Canon V-20
14Ciel Expert 3 IDE
15Ciel Expert 3 Turbo
16Daewoo CPC-300
17Daewoo CPC-400
18Daewoo CPC-400S
19Daewoo DPC-100
20Daewoo DPC-180
21Daewoo DPC-200
22Goldstar FC-200
23Gradiente Expert 1.0
24Gradiente Expert 1.1
25Gradiente Expert 1.3
26Gradiente Expert 2.0
27Gradiente Expert DDPlus
28Gradiente Expert Plus
29JVC HC-7GB
30Mitsubishi ML-F80
31Mitsubishi ML-FX1
32National CF-1200
33National CF-2000
34National CF-2700
35National CF-3000
36National CF-3300
37National FS-1300
38National FS-4000
39National FS-4500
40National FS-4600
41National FS-4700
42National FS-5000
43National FS-5500F1
44National FS-5500F2
45Panasonic FS-A1
46Panasonic FS-A1 MK2
47Panasonic FS-A1F
48Panasonic FS-A1FM
49Panasonic FS-A1FX
50Panasonic FS-A1GT
51Panasonic FS-A1ST
52Panasonic FS-A1WSX
53Panasonic FS-A1WX
54Philips NMS-801
55Philips NMS-8220
56Philips NMS-8245
57Philips NMS-8245F
58Philips NMS-8250
59Philips NMS-8255
60Philips NMS-8280
61Philips NMS-8280G
62Philips VG-8000
63Philips VG-8010
64Philips VG-8010F
65Philips VG-8020-00
66Philips VG-8020-20
67Philips VG-8020-40
68Philips VG-8230
69Philips VG-8235
70Philips VG-8235F
71Philips VG-8240
72===============
73
74PCB Layout missing
75
76
77Pioneer PX-7
78============
79
80|---------------------------------------|
81|  CN1     CN2                          |
82|                                       |
83|                                       |
84|  IC33                                 |---------------------------------|
85|                                                      CN3                |
86|   IC32   IC34            IC38  IC40                                     |
87|                                                               IC20      |
88|   IC15   IC18  IC43      IC8   IC35   IC6     |----IC3---|              |
89|                                               |----------|    IC21      |
90|   IC16   IC19  |---IC13---|    IC7    IC10                              |
91|                |----------|                   IC36  IC29      ---       |
92|   IC17   IC14                                     X2          | |       |
93|                |--IC12---|     |----IC1-----|       IC37      |I|       |
94|   IC28   IC11  |---------|     |------------|   X1            |C|       |
95|                                                               |2|       |
96|  |----IC4----| |----IC5----|   IC39  IC9      IC42  IC44      | |       |
97|  |-----------| |-----------|                                  ---       |
98|                                                                         |
99|       IC45   IC31    IC30      IC41                                     |
100|                                                                         |
101|  CN4 CN5  CN6  CN7                                  CN8                 |
102|-------------------------------------------------------------------------|
103
104Notes:
105  X1 - 3.579MHz
106  X2 - 500kHz
107  IC1 - Sharp LH0080A Z80A-CPU-D
108  IC2 - TMS91289NL
109  IC3 - MB111S112  Z10 (500kHz)
110  IC4  - M5L8255AP-5
111  IC5  - YM2149F
112  IC6,IC7,IC8,IC10,IC45 - SN74LS367AN
113  IC9 - SN74LS245N
114  IC11,IC34 - SN74LS139N
115  IC12 - YM2301-23908 / 53 18 85 A (might indicate a version)
116  IC13 - Pioneer PD5031 2364-213 514100 (M5L2764-213)
117  IC14,IC17,IC30,IC31 - SN74LS157N
118  IC15-IC19 - MB81416-12
119  IC20,IC21 - TMS4416-I5NL
120  IC28 - SN74LS153N
121  IC29 - SN74LS02N
122  IC32 - SN74LS374N
123  IC33 - M5218P
124  IC35 - SN74LS74AN
125  IC36 - SN74LS30N
126  IC37-IC39 - SN74LS04N
127  IC40,IC41 - SN74LS05N
128  IC42 - SN74LS08N
129  IC43,IC44 - SN74LS32N
130  CN1 - Printer
131  CN2 - Cassette recorder
132  CN3 - Expansion slot
133  CN4 - Keyboard
134  CN5 - Keyboard
135  CN6 - Controller #1
136  CN7 - Controller #2
137  CN8 - Expansion slot
138
139
140Sanyo MPC-100
141Sanyo PHC-28S
142Sanyo Wavy PHC-23
143Sanyo Wavy PHC-35J
144Sanyo Wavy PHC70FD1
145Sanyo Wavy PHC70FD2
146Sharp Epcom HotBit 1.1
147Sharp Epcom HotBit 1.2
148Sharp Epcom HotBit 1.3b
149Sharp Epcom HotBit 1.3p
150Sharp Epcom HotBit 2.0
151Sony HB-10P
152Sony HB-201
153Sony HB-201P
154Sony HB-501P
155Sony HB-55D
156Sony HB-55P
157Sony HB-75D
158Sony HB-75P
159Sony HB-F1
160Sony HB-F1II
161Sony HB-F1XD
162Sony HB-F1XD MK2
163Sony HB-F1XDJ
164Sony HB-F1XV
165Sony HB-F5
166Sony HB-F500
167Sony HB-F500P
168Sony HB-F700D
169Sony HB-F700F
170Sony HB-F700P
171Sony HB-F700S
172Sony HB-F900
173Sony HB-F9P
174Sony HB-F9S
175Sony HB-G900AP
176Sony HB-G900P
177Sony HB-T7
178Spectravideo SVI-728
179Spectravideo SVI-738
180Talent DPC-200
181Talent DPC-200A
182Talent TPC-310
183==============
184
185PCB Layouts missing
186
187
188Toshiba HX-10
189=============
190
191Code on PCB: MSX TUK
192        |---------------------------|-------------------|-------------|
193        |   CN1  CN2  CN3  CN4               CN5                      |
194        |                        |---------------------------|        |
195        |                        |---------------------------|        |
196        |                                    CN6                      |
197        |                        IC40                                 |
198        |                                                         CN7 |
199        |                      IC38     IC32     IC33     IC37        |
200        |                                                             |
201        |                      Q2       IC31     IC34     IC35        |
202        |    Q1                                                   CN8 |
203        |                                                 IC39        |
204        |   |--IC15------| |--IC2----|   |----IC1-----|               |
205        |   |------------| |---------|   |------------|               |
206        |                                                 IC30        |
207        |                 IC3    IC4                              CN9 |
208        |                               |-----IC15-------|            |
209        |  IC17   IC18    IC7    IC8    |----------------|            |
210        |                                                 IC27        |
211        |  IC19   IC20    IC9    IC10   |----IC25------|              |
212|----|  |                               |--------------|  IC26        |
213| Q  |  |  IC21   IC22    IC11   IC12                                 |
214|    |  |                                                             |
215| S  |  |  IC23   IC24    IC13   IC14    IC29             IC28        |
216|  L |  |                                                             |
217|    |  |                                 CN11   CN10                 |
218|----|  |-------------------------------------------------------------|
219
220Notes:
221  Mainboard components:
222   IC1               - Sharp LH0080A Z80A-CPU-D
223   IC2               - MB83256
224   IC3,IC4,IC27,IC28 - Texas Instruments SN74LS157N
225   IC7-IC14          - HM4864AP
226   IC15              - Toshiba TCX-1007 (64pin custom chip)
227   IC16              - 40pin chip covered with some kind of heatsink(?), probably TMS9929A
228   IC17-IC24         - 4116-3
229   IC25              - AY-3-8910A
230   IC26              - SN74LS09N
231   IC29              - HD74LS145P
232   IC30-IC34         - M74LS367AP
233   IC35              - MB74LS74A
234   IC37              - HD74LS373P
235   IC38              - Toshiba TC74HCU04P
236   IC39              - HD74LS08P
237   IC40              - TA75559P
238   Q1                - 10687.5
239   Q2                - 3579545
240   CN1               - Cassette connecter
241   CN2               - RF connector
242   CN3               - Audio connector
243   CN4               - Video connector
244   CN5               - Expansion connector
245   CN6               - Cartridge connector
246   CN7               - Printer connector
247   CN8               - Joystick 2 connector
248   CN9               - Joystick 1 connector
249   CN10              - Keyboard connector 1
250   CN11              - Keyboard connector 2
251
252  Extra pcb (video related?) components::
253   Q - 4.433619
254   S - 74LS04
255   L - LVA510
256
257
258Toshiba HX-10S
259Toshiba HX-20
260Toshiba HX-23
261Toshiba HX-23F
262Yamaha CX5M
263Yamaha CX5M-128
264Yamaha CX7M
265Yamaha CX7M-128
266Yamaha YIS-303
267Yamaha YIS-503
268Yamaha YIS-503M
269Yamaha YIS-503
270Yashica YC-64
271=============
272
273PCB Layouts missing
274
275
276*/
277
278#include "emu.h"
279#include "cpu/z80/z80.h"
280#include "deprecat.h"
281#include "machine/i8255.h"
282#include "machine/rp5c01.h"
283#include "machine/wd17xx.h"
284#include "video/tms9928a.h"
285#include "video/v9938.h"
286#include "machine/ctronics.h"
287#include "includes/msx_slot.h"
288#include "includes/msx.h"
289#include "imagedev/flopdrv.h"
290#include "imagedev/cartslot.h"
291#include "imagedev/cassette.h"
292#include "formats/fmsx_cas.h"
293#include "formats/msx_dsk.h"
294#include "sound/ay8910.h"
295#include "sound/dac.h"
296#include "sound/wave.h"
297#include "sound/k051649.h"
298#include "sound/2413intf.h"
299
300static ADDRESS_MAP_START (msx_memory_map, AS_PROGRAM, 8)
301   AM_RANGE( 0x0000, 0x1fff) AM_READ_BANK("bank1") AM_WRITE( msx_page0_w )
302   AM_RANGE( 0x2000, 0x3fff) AM_READ_BANK("bank2") AM_WRITE( msx_page0_1_w )
303   AM_RANGE( 0x4000, 0x5fff) AM_READ_BANK("bank3") AM_WRITE( msx_page1_w )
304   AM_RANGE( 0x6000, 0x7ff7) AM_READ_BANK("bank4") AM_WRITE( msx_page1_1_w )
305   AM_RANGE( 0x7ff8, 0x7fff) AM_READ_BANK("bank5") AM_WRITE( msx_page1_2_w )
306   AM_RANGE( 0x8000, 0x97ff) AM_READ_BANK("bank6") AM_WRITE( msx_page2_w )
307   AM_RANGE( 0x9800, 0x9fff) AM_READ_BANK("bank7") AM_WRITE(msx_page2_1_w )
308   AM_RANGE( 0xa000, 0xb7ff) AM_READ_BANK("bank8") AM_WRITE( msx_page2_2_w )
309   AM_RANGE( 0xb800, 0xbfff) AM_READ_BANK("bank9") AM_WRITE( msx_page2_3_w )
310   AM_RANGE( 0xc000, 0xdfff) AM_READ_BANK("bank10") AM_WRITE( msx_page3_w )
311   AM_RANGE( 0xe000, 0xfffe) AM_READ_BANK("bank11") AM_WRITE( msx_page3_1_w )
312   AM_RANGE( 0xffff, 0xffff) AM_READWRITE( msx_sec_slot_r, msx_sec_slot_w )
313ADDRESS_MAP_END
314
315
316static WRITE8_DEVICE_HANDLER( msx_ay8910_w )
317{
318   if ( offset & 1 )
319      ay8910_data_w( device, offset, data );
320   else
321      ay8910_address_w( device, offset, data );
322}
323
324
325static ADDRESS_MAP_START (msx_io_map, AS_IO, 8)
326   ADDRESS_MAP_UNMAP_HIGH
327   ADDRESS_MAP_GLOBAL_MASK(0xff)
328   AM_RANGE( 0x77, 0x77) AM_WRITE( msx_90in1_w )
329   AM_RANGE( 0x7c, 0x7d) AM_WRITE( msx_fmpac_w )
330   AM_RANGE( 0x90, 0x90) AM_DEVREADWRITE("centronics", msx_printer_status_r, msx_printer_strobe_w)
331   AM_RANGE( 0x91, 0x91) AM_DEVWRITE("centronics", msx_printer_data_w)
332   AM_RANGE( 0xa0, 0xa7) AM_DEVREADWRITE("ay8910", ay8910_r, msx_ay8910_w )
333   AM_RANGE( 0xa8, 0xab) AM_DEVREADWRITE_MODERN("ppi8255", i8255_device, read, write)
334   AM_RANGE( 0x98, 0x98) AM_READWRITE( TMS9928A_vram_r, TMS9928A_vram_w )
335   AM_RANGE( 0x99, 0x99) AM_READWRITE( TMS9928A_register_r, TMS9928A_register_w )
336   AM_RANGE( 0xd8, 0xd9) AM_READWRITE( msx_kanji_r, msx_kanji_w )
337ADDRESS_MAP_END
338
339
340static ADDRESS_MAP_START (msx2_io_map, AS_IO, 8)
341   ADDRESS_MAP_UNMAP_HIGH
342   ADDRESS_MAP_GLOBAL_MASK(0xff)
343   AM_RANGE( 0x77, 0x77) AM_WRITE( msx_90in1_w )
344   AM_RANGE( 0x7c, 0x7d) AM_WRITE( msx_fmpac_w )
345   AM_RANGE( 0x90, 0x90) AM_DEVREADWRITE("centronics", msx_printer_status_r, msx_printer_strobe_w)
346   AM_RANGE( 0x91, 0x91) AM_DEVWRITE("centronics", msx_printer_data_w)
347   AM_RANGE( 0xa0, 0xa7) AM_DEVREADWRITE("ay8910", ay8910_r, msx_ay8910_w )
348   AM_RANGE( 0xa8, 0xab) AM_DEVREADWRITE_MODERN("ppi8255", i8255_device, read, write)
349   AM_RANGE( 0x98, 0x98) AM_READWRITE( v9938_0_vram_r, v9938_0_vram_w )
350   AM_RANGE( 0x99, 0x99) AM_READWRITE( v9938_0_status_r, v9938_0_command_w )
351   AM_RANGE( 0x9a, 0x9a) AM_WRITE( v9938_0_palette_w )
352   AM_RANGE( 0x9b, 0x9b) AM_WRITE( v9938_0_register_w )
353   AM_RANGE( 0xb4, 0xb4) AM_WRITE( msx_rtc_latch_w )
354   AM_RANGE( 0xb5, 0xb5) AM_READWRITE( msx_rtc_reg_r, msx_rtc_reg_w )
355   AM_RANGE( 0xd8, 0xd9) AM_READWRITE( msx_kanji_r, msx_kanji_w )
356   AM_RANGE( 0xfc, 0xff) AM_READWRITE( msx_ram_mapper_r, msx_ram_mapper_w )
357ADDRESS_MAP_END
358
359
360static INPUT_PORTS_START( msx_dips )
361   PORT_START("JOY0")
362   PORT_BIT (0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP)
363   PORT_BIT (0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN)
364   PORT_BIT (0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT)
365   PORT_BIT (0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT)
366   PORT_BIT (0x10, IP_ACTIVE_LOW, IPT_BUTTON1)
367   PORT_BIT (0x20, IP_ACTIVE_LOW, IPT_BUTTON2)
368   PORT_BIT (0x40, IP_ACTIVE_LOW, IPT_UNUSED)
369   PORT_DIPNAME( 0x80, 0, "Game port 1")
370   PORT_DIPSETTING(    0x00, DEF_STR( Joystick ))
371   PORT_DIPSETTING(    0x80, "Mouse")
372
373   PORT_START("JOY1")
374   PORT_BIT (0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP)     PORT_PLAYER(2)
375   PORT_BIT (0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN)     PORT_PLAYER(2)
376   PORT_BIT (0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT)     PORT_PLAYER(2)
377   PORT_BIT (0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT)      PORT_PLAYER(2)
378   PORT_BIT (0x10, IP_ACTIVE_LOW, IPT_BUTTON1)     PORT_PLAYER(2)
379   PORT_BIT (0x20, IP_ACTIVE_LOW, IPT_BUTTON2)     PORT_PLAYER(2)
380   PORT_BIT (0x40, IP_ACTIVE_LOW, IPT_UNUSED)
381   PORT_DIPNAME( 0x80, 0, "Game port 2")
382   PORT_DIPSETTING( 0x00, DEF_STR( Joystick ))
383   PORT_DIPSETTING( 0x80, "Mouse")
384
385   PORT_START("DSW")
386   PORT_DIPNAME( 0x40, 0, "Swap game port 1 and 2")
387   PORT_DIPSETTING( 0, DEF_STR( No ) )
388   PORT_DIPSETTING( 0x40, DEF_STR( Yes ) )
389   PORT_DIPNAME( 0x80, 0, "SIMPL")
390   PORT_DIPSETTING( 0x00, DEF_STR ( Off ) )
391   PORT_DIPSETTING( 0x80, DEF_STR ( On ) )
392   PORT_DIPNAME( 0x20, 0x20, "Enforce 4/8 sprites/line")
393   PORT_DIPSETTING( 0, DEF_STR( No ) )
394   PORT_DIPSETTING( 0x20, DEF_STR( Yes ) )
395   PORT_DIPNAME ( 0x03, 0, "Render resolution")
396   PORT_DIPSETTING( 0, DEF_STR( High ))
397   PORT_DIPSETTING( 1, DEF_STR( Low ))
398   PORT_DIPSETTING( 2, "Auto" )
399
400   PORT_START("MOUSE0")
401   PORT_BIT( 0xff00, 0x00, IPT_TRACKBALL_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1)
402   PORT_BIT( 0x00ff, 0x00, IPT_TRACKBALL_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1)
403
404   PORT_START("MOUSE1")
405   PORT_BIT( 0xff00, 0x00, IPT_TRACKBALL_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(2)
406   PORT_BIT( 0x00ff, 0x00, IPT_TRACKBALL_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(2)
407INPUT_PORTS_END
408
409
410/* 2008-05 FP: About keyboards
411
412Even if some later Philips (and maybe others) models started to use a layout similar to current
413PC keyboards, common MSX keyboards have a couple of keys which do not fit usual mapping
414- the key in the 1st row before 'Backspace', 3rd key from '0', here re-mapped to KEYCODE_BACKSLASH2
415- the last key in the 4th row, 4th key from 'M' (not counting Shift), here re-mapped to KEYCODE_TILDE
416
417These keys corresponds to the following symbols
418
419    input_port  | msx   | msxuk | msxjp | msxkr |hotbit |expert |
420    -------------------------------------------------------------
421    BACKSLASH2  |  \ |  |  \ |  |  ? |  | won | |  \ ^  |  { }  |
422    -------------------------------------------------------------
423    TILDE       |  DK*  |  DK*  |  _    |  _    |  < >  |  / ?  |
424
425* DK = "Dead Key"
426Notice that 'expert' input_ports covers both versions 1.0 and 1.1.
427msx2 input_ports have the same symbols as their msx counterparts.
428
429TO DO:
430- check Expert 1.0 layout with the real thing
431- check Korean layout
432- fix natural support in systems using msx inputs but with different mapping
433(these systems could have different uses for keys mapped at the following
434locations: COLON, QUOTE, BACKSLASH, OPENBRACE, CLOSEBRACE, BACKSLASH2, TILDE.
435The corresponding symbols would not work properly in -natural mode).
436
437Additional note about natural keyboard support: currently,
438- "Keypad ," is not mapped
439- "Graph" is mapped to 'F6' (this key could be labeled "L Graph")
440- "Code" is mapped to 'F7' (this key could be labeled "R Graph", "Kana" or "Hangul")
441- "Stop" is mapped to 'F8'
442- "Select" is mapped to 'F9'
443*/
444
445#define KEYB_ROW0   \
446   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_0) PORT_CHAR('0') PORT_CHAR(')')   \
447   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')   \
448   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('@')   \
449   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')   \
450   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')   \
451   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')   \
452   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('^')   \
453   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('&')
454
455#define KEYB_EXPERT11_ROW0    \
456   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_0) PORT_CHAR('0') PORT_CHAR(')')   \
457   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')   \
458   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('"')   \
459   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')   \
460   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')   \
461   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')   \
462   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('^')   \
463   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('&')
464
465#define KEYB_HOTBIT_ROW0    \
466   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_0) PORT_CHAR('0') PORT_CHAR(')')   \
467   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')   \
468   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('@')   \
469   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')   \
470   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')   \
471   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')   \
472   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('"')   \
473   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('&')
474
475#define KEYB_ROW1   \
476   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_8)            PORT_CHAR('8') PORT_CHAR('*')   \
477   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_9)            PORT_CHAR('9') PORT_CHAR('(')   \
478   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS)         PORT_CHAR('-') PORT_CHAR('_')   \
479   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_EQUALS)      PORT_CHAR('=') PORT_CHAR('+')   \
480   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH2)   PORT_CHAR('\\') PORT_CHAR('|')   \
481   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_OPENBRACE)      PORT_CHAR('[') PORT_CHAR('{')   \
482   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR(']') PORT_CHAR('}')   \
483   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COLON)         PORT_CHAR(';') PORT_CHAR(':')
484
485#define KEYB_HOTBIT_ROW1    \
486   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_8)            PORT_CHAR('8') PORT_CHAR('*')   \
487   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_9)            PORT_CHAR('9') PORT_CHAR('(')   \
488   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS)         PORT_CHAR('-') PORT_CHAR('_')   \
489   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_EQUALS)      PORT_CHAR('=') PORT_CHAR('+')   \
490   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH2)   PORT_CHAR('\\') PORT_CHAR('^')   \
491   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_OPENBRACE)      PORT_CHAR('\'') PORT_CHAR('`')   \
492   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR('"') PORT_CHAR('`')   \
493   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COLON)         PORT_CHAR('\xC7') PORT_CHAR('\xE7')
494
495#define KEYB_EXPERT11_ROW1    \
496   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_8)            PORT_CHAR('8') PORT_CHAR('\'')   \
497   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_9)            PORT_CHAR('9') PORT_CHAR('(')   \
498   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS)         PORT_CHAR('-') PORT_CHAR('_')   \
499   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_EQUALS)      PORT_CHAR('=') PORT_CHAR('+')   \
500   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH2)   PORT_CHAR('{') PORT_CHAR('}')   \
501   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_OPENBRACE)      PORT_CHAR('\'') PORT_CHAR('`')   \
502   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR('[') PORT_CHAR(']')   \
503   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE)         PORT_CHAR('~') PORT_CHAR('^')
504
505#define KEYB_ROW2   \
506   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE)      PORT_CHAR('\'') PORT_CHAR('"')   \
507   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH)   PORT_CHAR('`') PORT_CHAR('~')   \
508   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA)      PORT_CHAR(',') PORT_CHAR('<')   \
509   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP)      PORT_CHAR('.') PORT_CHAR('>')   \
510   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH)      PORT_CHAR('/') PORT_CHAR('?')   \
511   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("Dead Key") PORT_CODE(KEYCODE_TILDE)            \
512   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_A)         PORT_CHAR('a') PORT_CHAR('A')   \
513   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_B)         PORT_CHAR('b') PORT_CHAR('B')
514
515#define KEYB_HOTBIT_ROW2    \
516   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE)         PORT_CHAR('~') PORT_CHAR('^')   \
517   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH)      PORT_CHAR('[') PORT_CHAR(']')   \
518   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA)         PORT_CHAR(',') PORT_CHAR(';')   \
519   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP)         PORT_CHAR('.') PORT_CHAR(':')   \
520   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH)         PORT_CHAR('/') PORT_CHAR('?')   \
521   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_TILDE)         PORT_CHAR('<') PORT_CHAR('>')   \
522   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_A)            PORT_CHAR('a') PORT_CHAR('A')   \
523   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_B)            PORT_CHAR('b') PORT_CHAR('B')
524
525#define KEYB_EXPERT10_ROW2    \
526   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE)      PORT_CHAR('\'') PORT_CHAR('"')   \
527   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH)   PORT_CHAR('\xC7') PORT_CHAR('\xE7')   \
528   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA)      PORT_CHAR(',') PORT_CHAR('<')   \
529   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP)      PORT_CHAR('.') PORT_CHAR('>')   \
530   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH)      PORT_CHAR('/') PORT_CHAR('?')   \
531   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("Dead Key") PORT_CODE(KEYCODE_TILDE)            \
532   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_A)         PORT_CHAR('a') PORT_CHAR('A')   \
533   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_B)         PORT_CHAR('b') PORT_CHAR('B')
534
535#define KEYB_EXPERT11_ROW2    \
536   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH)   PORT_CHAR('*') PORT_CHAR('@')   \
537   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COLON)      PORT_CHAR('\xC7') PORT_CHAR('\xE7')   \
538   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA)      PORT_CHAR(',') PORT_CHAR('<')   \
539   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP)      PORT_CHAR('.') PORT_CHAR('>')   \
540   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_TILDE)      PORT_CHAR('/') PORT_CHAR('?')   \
541   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH)      PORT_CHAR(';') PORT_CHAR(':')   \
542   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_A)         PORT_CHAR('a') PORT_CHAR('A')   \
543   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_B)         PORT_CHAR('b') PORT_CHAR('B')
544
545#define KEYB_ROW3   \
546   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_C) PORT_CHAR('c') PORT_CHAR('C')   \
547   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_D) PORT_CHAR('d') PORT_CHAR('D')   \
548   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_E) PORT_CHAR('e') PORT_CHAR('E')   \
549   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_F) PORT_CHAR('f') PORT_CHAR('F')   \
550   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_G) PORT_CHAR('g') PORT_CHAR('G')   \
551   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_H) PORT_CHAR('h') PORT_CHAR('H')   \
552   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_I) PORT_CHAR('i') PORT_CHAR('I')   \
553   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_J) PORT_CHAR('j') PORT_CHAR('J')
554
555#define KEYB_ROW4   \
556   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_K) PORT_CHAR('k') PORT_CHAR('K')   \
557   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_L) PORT_CHAR('l') PORT_CHAR('L')   \
558   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_M) PORT_CHAR('m') PORT_CHAR('M')   \
559   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_N) PORT_CHAR('n') PORT_CHAR('N')   \
560   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_O) PORT_CHAR('o') PORT_CHAR('O')   \
561   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_P) PORT_CHAR('p') PORT_CHAR('P')   \
562   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_Q) PORT_CHAR('q') PORT_CHAR('Q')   \
563   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_R) PORT_CHAR('r') PORT_CHAR('R')
564
565#define KEYB_ROW5   \
566   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_S) PORT_CHAR('s') PORT_CHAR('S')   \
567   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_T) PORT_CHAR('t') PORT_CHAR('T')   \
568   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_U) PORT_CHAR('u') PORT_CHAR('U')   \
569   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_V) PORT_CHAR('v') PORT_CHAR('V')   \
570   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_W) PORT_CHAR('w') PORT_CHAR('W')   \
571   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_X) PORT_CHAR('x') PORT_CHAR('X')   \
572   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_Y) PORT_CHAR('y') PORT_CHAR('Y')   \
573   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_Z) PORT_CHAR('z') PORT_CHAR('Z')
574
575#define KEYB_ROW6   \
576   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LSHIFT)                  PORT_CHAR(UCHAR_SHIFT_1)         \
577   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LCONTROL)                  PORT_CHAR(UCHAR_SHIFT_2)         \
578   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("GRAPH") PORT_CODE(KEYCODE_PGUP)      PORT_CHAR(UCHAR_MAMEKEY(F6))      \
579   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CAPS") PORT_CODE(KEYCODE_CAPSLOCK)   PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))   \
580   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CODE") PORT_CODE(KEYCODE_PGDN)      PORT_CHAR(UCHAR_MAMEKEY(F7))      \
581   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F1  F6") PORT_CODE(KEYCODE_F1)      PORT_CHAR(UCHAR_MAMEKEY(F1))      \
582   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F2  F7") PORT_CODE(KEYCODE_F2)      PORT_CHAR(UCHAR_MAMEKEY(F2))      \
583   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F3  F8") PORT_CODE(KEYCODE_F3)      PORT_CHAR(UCHAR_MAMEKEY(F3))
584
585#define KEYB_EXPERT11_ROW6    \
586   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LSHIFT)                     PORT_CHAR(UCHAR_SHIFT_1)         \
587   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CONTROL") PORT_CODE(KEYCODE_LCONTROL)      PORT_CHAR(UCHAR_SHIFT_2)         \
588   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("L GRA") PORT_CODE(KEYCODE_PGUP)         PORT_CHAR(UCHAR_MAMEKEY(F6))      \
589   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CAPS LOCK") PORT_CODE(KEYCODE_CAPSLOCK)   PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))   \
590   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("R GRA") PORT_CODE(KEYCODE_PGDN)         PORT_CHAR(UCHAR_MAMEKEY(F7))      \
591   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F1  F6") PORT_CODE(KEYCODE_F1)         PORT_CHAR(UCHAR_MAMEKEY(F1))      \
592   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F2  F7") PORT_CODE(KEYCODE_F2)         PORT_CHAR(UCHAR_MAMEKEY(F2))      \
593   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F3  F8") PORT_CODE(KEYCODE_F3)         PORT_CHAR(UCHAR_MAMEKEY(F3))
594
595#define KEYB_ROW7   \
596   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F4  F9") PORT_CODE(KEYCODE_F4)      PORT_CHAR(UCHAR_MAMEKEY(F4))   \
597   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F5  F10") PORT_CODE(KEYCODE_F5)      PORT_CHAR(UCHAR_MAMEKEY(F5))   \
598   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_ESC)                     PORT_CHAR(UCHAR_MAMEKEY(ESC))   \
599   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_TAB)                     PORT_CHAR('\t')               \
600   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("STOP") PORT_CODE(KEYCODE_RCONTROL)   PORT_CHAR(UCHAR_MAMEKEY(F8))   \
601   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSPACE)                  PORT_CHAR(8)               \
602   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("SELECT") PORT_CODE(KEYCODE_END)      PORT_CHAR(UCHAR_MAMEKEY(F9))   \
603   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_ENTER)                     PORT_CHAR(13)
604
605#define KEYB_ROW8   \
606   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SPACE)               PORT_CHAR(' ')               \
607   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_HOME)               PORT_CHAR(UCHAR_MAMEKEY(HOME))   \
608   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_INSERT)            PORT_CHAR(UCHAR_MAMEKEY(INSERT))\
609   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("DEL") PORT_CODE(KEYCODE_DEL)   PORT_CHAR(UCHAR_MAMEKEY(DEL))   \
610   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LEFT)               PORT_CHAR(UCHAR_MAMEKEY(LEFT))   \
611   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_UP)               PORT_CHAR(UCHAR_MAMEKEY(UP))   \
612   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_DOWN)               PORT_CHAR(UCHAR_MAMEKEY(DOWN))   \
613   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_RIGHT)               PORT_CHAR(UCHAR_MAMEKEY(RIGHT))
614
615#define KEYB_ROW9   \
616   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_ASTERISK)   PORT_CHAR(UCHAR_MAMEKEY(ASTERISK))   \
617   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_PLUS_PAD)   PORT_CHAR(UCHAR_MAMEKEY(PLUS_PAD))   \
618   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH_PAD)   PORT_CHAR(UCHAR_MAMEKEY(SLASH_PAD))   \
619   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_0_PAD)      PORT_CHAR(UCHAR_MAMEKEY(0_PAD))      \
620   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_1_PAD)      PORT_CHAR(UCHAR_MAMEKEY(1_PAD))      \
621   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_2_PAD)      PORT_CHAR(UCHAR_MAMEKEY(2_PAD))      \
622   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_3_PAD)      PORT_CHAR(UCHAR_MAMEKEY(3_PAD))      \
623   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_4_PAD)      PORT_CHAR(UCHAR_MAMEKEY(4_PAD))
624
625#define KEYB_ROW10   \
626   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_5_PAD)      PORT_CHAR(UCHAR_MAMEKEY(5_PAD))      \
627   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_6_PAD)      PORT_CHAR(UCHAR_MAMEKEY(6_PAD))      \
628   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_7_PAD)      PORT_CHAR(UCHAR_MAMEKEY(7_PAD))      \
629   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_8_PAD)      PORT_CHAR(UCHAR_MAMEKEY(8_PAD))      \
630   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_9_PAD)      PORT_CHAR(UCHAR_MAMEKEY(9_PAD))      \
631   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS_PAD)   PORT_CHAR(UCHAR_MAMEKEY(MINUS_PAD))   \
632   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("Keypad ,") PORT_CODE(KEYCODE_ENTER_PAD)            \
633   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_DEL_PAD)   PORT_CHAR(UCHAR_MAMEKEY(DEL_PAD))
634
635static INPUT_PORTS_START( msx )
636   PORT_START("KEY0")
637   KEYB_ROW0
638   KEYB_ROW1
639
640   PORT_START("KEY1")
641   KEYB_ROW2
642   KEYB_ROW3
643
644   PORT_START("KEY2")
645   KEYB_ROW4
646   KEYB_ROW5
647
648   PORT_START("KEY3")
649   KEYB_ROW6
650   KEYB_ROW7
651
652   PORT_START("KEY4")
653   KEYB_ROW8
654   PORT_BIT (0xff00, IP_ACTIVE_LOW, IPT_UNUSED)
655
656   PORT_START("KEY5")
657   PORT_BIT (0xffff, IP_ACTIVE_LOW, IPT_UNUSED)
658
659   PORT_INCLUDE( msx_dips )
660INPUT_PORTS_END
661
662static INPUT_PORTS_START( msxuk )
663   PORT_START("KEY0")
664   KEYB_ROW0
665   KEYB_ROW1
666
667   PORT_START("KEY1")
668   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE)         PORT_CHAR('\'') PORT_CHAR('"')
669   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH)      PORT_CHAR('\xA3') PORT_CHAR('~')
670   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA)         PORT_CHAR(',') PORT_CHAR('<')
671   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP)         PORT_CHAR('.') PORT_CHAR('>')
672   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH)         PORT_CHAR('/') PORT_CHAR('?')
673   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("Dead Key") PORT_CODE(KEYCODE_TILDE)
674   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_A)            PORT_CHAR('a') PORT_CHAR('A')
675   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_B)            PORT_CHAR('b') PORT_CHAR('B')
676   KEYB_ROW3
677
678   PORT_START("KEY2")
679   KEYB_ROW4
680   KEYB_ROW5
681
682   PORT_START("KEY3")
683   KEYB_ROW6
684   KEYB_ROW7
685
686   PORT_START("KEY4")
687   KEYB_ROW8
688   PORT_BIT (0xff00, IP_ACTIVE_LOW, IPT_UNUSED)
689
690   PORT_START("KEY5")
691   PORT_BIT (0xffff, IP_ACTIVE_LOW, IPT_UNUSED)
692
693   PORT_INCLUDE( msx_dips )
694INPUT_PORTS_END
695
696#define KEYB_JAP_ROW0   \
697   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_0) PORT_CHAR('0')               \
698   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')   \
699   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('"')   \
700   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')   \
701   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')   \
702   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')   \
703   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('&')   \
704   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('\'')
705
706#define KEYB_JAP_ROW1   \
707   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_8)            PORT_CHAR('8') PORT_CHAR('(')   \
708   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_9)            PORT_CHAR('9') PORT_CHAR(')')   \
709   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS)         PORT_CHAR('-') PORT_CHAR('=')   \
710   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_EQUALS)      PORT_CHAR('^') PORT_CHAR('~')   \
711   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH2)   PORT_CHAR('\xA5') PORT_CHAR('|')\
712   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_OPENBRACE)      PORT_CHAR('@') PORT_CHAR('`')   \
713   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR('[') PORT_CHAR('{')   \
714   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COLON)         PORT_CHAR(';') PORT_CHAR('+')
715
716#define KEYB_KOR_ROW1   \
717   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_8)            PORT_CHAR('8') PORT_CHAR('(')   \
718   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_9)            PORT_CHAR('9') PORT_CHAR(')')   \
719   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS)         PORT_CHAR('-') PORT_CHAR('=')   \
720   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_EQUALS)      PORT_CHAR('^') PORT_CHAR('~')   \
721   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("\xE2\x82\xA9 |") PORT_CODE(KEYCODE_BACKSLASH2) PORT_CHAR(0xffe6) PORT_CHAR('|') \
722   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_OPENBRACE)      PORT_CHAR('@') PORT_CHAR('`')   \
723   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR('[') PORT_CHAR('{')   \
724   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COLON)         PORT_CHAR(';') PORT_CHAR('+')
725
726#define KEYB_JAP_ROW2   \
727   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE)      PORT_CHAR(':') PORT_CHAR('*')   \
728   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH)   PORT_CHAR(']') PORT_CHAR('}')   \
729   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA)      PORT_CHAR(',') PORT_CHAR('<')   \
730   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP)      PORT_CHAR('.') PORT_CHAR('>')   \
731   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH)      PORT_CHAR('/') PORT_CHAR('?')   \
732   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("_") PORT_CODE(KEYCODE_TILDE) PORT_CHAR('_')      \
733   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_A)         PORT_CHAR('a') PORT_CHAR('A')   \
734   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_B)         PORT_CHAR('b') PORT_CHAR('B')
735
736static INPUT_PORTS_START( msxjp )
737   PORT_START("KEY0")
738   KEYB_JAP_ROW0
739   KEYB_JAP_ROW1
740
741   PORT_START("KEY1")
742   KEYB_JAP_ROW2
743   KEYB_ROW3
744
745   PORT_START("KEY2")
746   KEYB_ROW4
747   KEYB_ROW5
748
749   PORT_START("KEY3")
750   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LSHIFT)                  PORT_CHAR(UCHAR_SHIFT_1)
751   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LCONTROL)                  PORT_CHAR(UCHAR_SHIFT_2)
752   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("GRAPH") PORT_CODE(KEYCODE_PGUP)      PORT_CHAR(UCHAR_MAMEKEY(F6))
753   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CAPS") PORT_CODE(KEYCODE_CAPSLOCK)   PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
754   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("KANA") PORT_CODE(KEYCODE_PGDN)      PORT_CHAR(UCHAR_MAMEKEY(F7))
755   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F1  F6") PORT_CODE(KEYCODE_F1)      PORT_CHAR(UCHAR_MAMEKEY(F1))
756   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F2  F7") PORT_CODE(KEYCODE_F2)      PORT_CHAR(UCHAR_MAMEKEY(F2))
757   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F3  F8") PORT_CODE(KEYCODE_F3)      PORT_CHAR(UCHAR_MAMEKEY(F3))
758   KEYB_ROW7
759
760   PORT_START("KEY4")
761   KEYB_ROW8
762   PORT_BIT (0xff00, IP_ACTIVE_LOW, IPT_UNUSED)
763
764   PORT_START("KEY5")
765   PORT_BIT (0xffff, IP_ACTIVE_LOW, IPT_UNUSED)
766
767   PORT_INCLUDE( msx_dips )
768INPUT_PORTS_END
769
770static INPUT_PORTS_START( msxkr )
771   PORT_START("KEY0")
772   KEYB_JAP_ROW0
773   KEYB_KOR_ROW1
774
775   PORT_START("KEY1")
776   KEYB_JAP_ROW2
777   KEYB_ROW3
778
779   PORT_START("KEY2")
780   KEYB_ROW4
781   KEYB_ROW5
782
783   PORT_START("KEY3")
784   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LSHIFT)                  PORT_CHAR(UCHAR_SHIFT_1)
785   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LCONTROL)                  PORT_CHAR(UCHAR_SHIFT_2)
786   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("GRAPH") PORT_CODE(KEYCODE_PGUP)      PORT_CHAR(UCHAR_MAMEKEY(F6))
787   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CAPS") PORT_CODE(KEYCODE_CAPSLOCK)   PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
788   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("Hangul") PORT_CODE(KEYCODE_PGDN)      PORT_CHAR(UCHAR_MAMEKEY(F7))
789   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F1  F6") PORT_CODE(KEYCODE_F1)      PORT_CHAR(UCHAR_MAMEKEY(F1))
790   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F2  F7") PORT_CODE(KEYCODE_F2)      PORT_CHAR(UCHAR_MAMEKEY(F2))
791   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F3  F8") PORT_CODE(KEYCODE_F3)      PORT_CHAR(UCHAR_MAMEKEY(F3))
792   KEYB_ROW7
793
794   PORT_START("KEY4")
795   KEYB_ROW8
796   PORT_BIT (0xff00, IP_ACTIVE_LOW, IPT_UNUSED)
797
798   PORT_START("KEY5")
799   PORT_BIT (0xffff, IP_ACTIVE_LOW, IPT_UNUSED)
800
801   PORT_INCLUDE( msx_dips )
802INPUT_PORTS_END
803
804static INPUT_PORTS_START( hotbit )
805   PORT_START("KEY0")
806   KEYB_HOTBIT_ROW0
807   KEYB_HOTBIT_ROW1
808
809   PORT_START("KEY1")
810   KEYB_HOTBIT_ROW2
811   KEYB_ROW3
812
813   PORT_START("KEY2")
814   KEYB_ROW4
815   KEYB_ROW5
816
817   PORT_START("KEY3")
818   KEYB_ROW6
819   KEYB_ROW7
820
821   PORT_START("KEY4")
822   KEYB_ROW8
823   PORT_BIT (0xff00, IP_ACTIVE_LOW, IPT_UNUSED)
824
825   PORT_START("KEY5")
826   PORT_BIT (0xffff, IP_ACTIVE_LOW, IPT_UNUSED)
827
828   PORT_INCLUDE( msx_dips )
829INPUT_PORTS_END
830
831/* 2008-05 FP: I guess these belong to the keypad */
832#define KEYB_EXPERT11_ROW9   \
833   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_PLUS_PAD)      PORT_CHAR(UCHAR_MAMEKEY(PLUS_PAD))   \
834   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS_PAD)      PORT_CHAR(UCHAR_MAMEKEY(MINUS_PAD))   \
835   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_ASTERISK)      PORT_CHAR(UCHAR_MAMEKEY(ASTERISK))   \
836   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH_PAD)      PORT_CHAR(UCHAR_MAMEKEY(SLASH_PAD))   \
837   PORT_BIT (0xf000, IP_ACTIVE_LOW, IPT_UNUSED)   \
838
839static INPUT_PORTS_START( expert11 )
840   PORT_START("KEY0")
841   KEYB_EXPERT11_ROW0
842   KEYB_EXPERT11_ROW1
843
844   PORT_START("KEY1")
845   KEYB_EXPERT11_ROW2
846   KEYB_ROW3
847
848   PORT_START("KEY2")
849   KEYB_ROW4
850   KEYB_ROW5
851
852   PORT_START("KEY3")
853   KEYB_EXPERT11_ROW6
854   KEYB_ROW7
855
856   PORT_START("KEY4")
857   KEYB_ROW8
858   KEYB_EXPERT11_ROW9
859
860   PORT_START("KEY5")
861   PORT_BIT (0xffff, IP_ACTIVE_LOW, IPT_UNUSED)
862
863   PORT_INCLUDE( msx_dips )
864INPUT_PORTS_END
865
866static INPUT_PORTS_START( expert10 )
867   PORT_START("KEY0")
868   KEYB_ROW0
869   KEYB_ROW1
870
871   PORT_START("KEY1")
872   KEYB_EXPERT10_ROW2
873   KEYB_ROW3
874
875   PORT_START("KEY2")
876   KEYB_ROW4
877   KEYB_ROW5
878
879   PORT_START("KEY3")
880   KEYB_EXPERT11_ROW6
881   KEYB_ROW7
882
883   PORT_START("KEY4")
884   KEYB_ROW8
885   KEYB_EXPERT11_ROW9
886
887   PORT_START("KEY5")
888   PORT_BIT (0xffff, IP_ACTIVE_LOW, IPT_UNUSED)
889
890   PORT_INCLUDE( msx_dips )
891INPUT_PORTS_END
892
893static INPUT_PORTS_START( msx2 )
894   PORT_START("KEY0")
895   KEYB_ROW0
896   KEYB_ROW1
897
898   PORT_START("KEY1")
899   KEYB_ROW2
900   KEYB_ROW3
901
902   PORT_START("KEY2")
903   KEYB_ROW4
904   KEYB_ROW5
905
906   PORT_START("KEY3")
907   KEYB_ROW6
908   KEYB_ROW7
909
910   PORT_START("KEY4")
911   KEYB_ROW8
912   KEYB_ROW9
913
914   PORT_START("KEY5")
915   KEYB_ROW10
916
917   PORT_INCLUDE( msx_dips )
918INPUT_PORTS_END
919
920static INPUT_PORTS_START( msx2jp )
921   PORT_START("KEY0")
922   KEYB_JAP_ROW0
923   KEYB_JAP_ROW1
924
925   PORT_START("KEY1")
926   KEYB_JAP_ROW2
927   KEYB_ROW3
928
929   PORT_START("KEY2")
930   KEYB_ROW4
931   KEYB_ROW5
932
933   PORT_START("KEY3")
934   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LSHIFT)                  PORT_CHAR(UCHAR_SHIFT_1)
935   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LCONTROL)                  PORT_CHAR(UCHAR_SHIFT_2)
936   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("GRAPH") PORT_CODE(KEYCODE_PGUP)      PORT_CHAR(UCHAR_MAMEKEY(F6))
937   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CAPS") PORT_CODE(KEYCODE_CAPSLOCK)   PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
938   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("KANA") PORT_CODE(KEYCODE_PGDN)      PORT_CHAR(UCHAR_MAMEKEY(F7))
939   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F1  F6") PORT_CODE(KEYCODE_F1)      PORT_CHAR(UCHAR_MAMEKEY(F1))
940   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F2  F7") PORT_CODE(KEYCODE_F2)      PORT_CHAR(UCHAR_MAMEKEY(F2))
941   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F3  F8") PORT_CODE(KEYCODE_F3)      PORT_CHAR(UCHAR_MAMEKEY(F3))
942   KEYB_ROW7
943
944   PORT_START("KEY4")
945   KEYB_ROW8
946   KEYB_ROW9
947
948   PORT_START("KEY5")
949   KEYB_ROW10
950
951   PORT_INCLUDE( msx_dips )
952INPUT_PORTS_END
953
954static INPUT_PORTS_START( msx2kr )
955   PORT_START("KEY0")
956   KEYB_JAP_ROW0
957   KEYB_KOR_ROW1
958
959   PORT_START("KEY1")
960   KEYB_JAP_ROW2
961   KEYB_ROW3
962
963   PORT_START("KEY2")
964   KEYB_ROW4
965   KEYB_ROW5
966
967   PORT_START("KEY3")
968   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LSHIFT)                  PORT_CHAR(UCHAR_SHIFT_1)
969   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LCONTROL)                  PORT_CHAR(UCHAR_SHIFT_2)
970   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("GRAPH") PORT_CODE(KEYCODE_PGUP)      PORT_CHAR(UCHAR_MAMEKEY(F6))
971   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CAPS") PORT_CODE(KEYCODE_CAPSLOCK)   PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
972   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("Hangul") PORT_CODE(KEYCODE_PGDN)      PORT_CHAR(UCHAR_MAMEKEY(F7))
973   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F1  F6") PORT_CODE(KEYCODE_F1)      PORT_CHAR(UCHAR_MAMEKEY(F1))
974   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F2  F7") PORT_CODE(KEYCODE_F2)      PORT_CHAR(UCHAR_MAMEKEY(F2))
975   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F3  F8") PORT_CODE(KEYCODE_F3)      PORT_CHAR(UCHAR_MAMEKEY(F3))
976   KEYB_ROW7
977
978   PORT_START("KEY4")
979   KEYB_ROW8
980   PORT_BIT (0xff00, IP_ACTIVE_LOW, IPT_UNUSED)
981
982   PORT_START("KEY5")
983   PORT_BIT (0xffff, IP_ACTIVE_LOW, IPT_UNUSED)
984
985   PORT_INCLUDE( msx_dips )
986INPUT_PORTS_END
987
988static const ay8910_interface msx_ay8910_interface =
989{
990   AY8910_LEGACY_OUTPUT,
991   AY8910_DEFAULT_LOADS,
992   DEVCB_MEMORY_HANDLER("maincpu", PROGRAM, msx_psg_port_a_r),
993   DEVCB_MEMORY_HANDLER("maincpu", PROGRAM, msx_psg_port_b_r),
994   DEVCB_MEMORY_HANDLER("maincpu", PROGRAM, msx_psg_port_a_w),
995   DEVCB_MEMORY_HANDLER("maincpu", PROGRAM, msx_psg_port_b_w)
996};
997
998static VIDEO_START( msx2 )
999{
1000   VIDEO_START_CALL(generic_bitmapped);
1001   v9938_init(machine, 0, *machine.primary_screen, machine.generic.tmpbitmap, MODEL_V9938, 0x20000, msx_vdp_interrupt);
1002}
1003
1004#define MSX_XBORDER_PIXELS      15
1005#define MSX_YBORDER_PIXELS      27
1006#define MSX_TOTAL_XRES_PIXELS      256 + (MSX_XBORDER_PIXELS * 2)
1007#define MSX_TOTAL_YRES_PIXELS      192 + (MSX_YBORDER_PIXELS * 2)
1008#define MSX_VISIBLE_XBORDER_PIXELS   8
1009#define MSX_VISIBLE_YBORDER_PIXELS   24
1010
1011static const cassette_config msx_cassette_config =
1012{
1013   fmsx_cassette_formats,
1014   NULL,
1015   (cassette_state)(CASSETTE_PLAY),
1016   NULL
1017};
1018
1019static const floppy_config msx_floppy_config =
1020{
1021   DEVCB_NULL,
1022   DEVCB_NULL,
1023   DEVCB_NULL,
1024   DEVCB_NULL,
1025   DEVCB_NULL,
1026   FLOPPY_STANDARD_5_25_DSHD,
1027   FLOPPY_OPTIONS_NAME(msx),
1028   NULL
1029};
1030
1031static MACHINE_CONFIG_FRAGMENT( msx_cartslot )
1032   MCFG_CARTSLOT_ADD("cart1")
1033   MCFG_CARTSLOT_EXTENSION_LIST("mx1,rom")
1034   MCFG_CARTSLOT_NOT_MANDATORY
1035   MCFG_CARTSLOT_LOAD(msx_cart)
1036   MCFG_CARTSLOT_UNLOAD(msx_cart)
1037
1038   MCFG_CARTSLOT_ADD("cart2")
1039   MCFG_CARTSLOT_EXTENSION_LIST("mx1,rom")
1040   MCFG_CARTSLOT_NOT_MANDATORY
1041   MCFG_CARTSLOT_LOAD(msx_cart)
1042   MCFG_CARTSLOT_UNLOAD(msx_cart)
1043MACHINE_CONFIG_END
1044
1045static MACHINE_CONFIG_START( msx, msx_state )
1046   /* basic machine hardware */
1047   MCFG_CPU_ADD("maincpu", Z80, 3579545)        /* 3.579545 MHz */
1048   MCFG_CPU_PROGRAM_MAP(msx_memory_map)
1049   MCFG_CPU_IO_MAP(msx_io_map)
1050   MCFG_CPU_VBLANK_INT("screen", msx_interrupt)
1051   MCFG_QUANTUM_TIME(attotime::from_hz(60))
1052
1053   MCFG_MACHINE_START( msx )
1054   MCFG_MACHINE_RESET( msx )
1055
1056   MCFG_I8255_ADD( "ppi8255", msx_ppi8255_interface )
1057
1058   /* video hardware */
1059   MCFG_FRAGMENT_ADD(tms9928a)
1060   MCFG_SCREEN_MODIFY("screen")
1061   MCFG_SCREEN_REFRESH_RATE(60)
1062   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
1063   MCFG_SCREEN_SIZE(MSX_TOTAL_XRES_PIXELS, MSX_TOTAL_YRES_PIXELS)
1064   MCFG_SCREEN_VISIBLE_AREA(MSX_XBORDER_PIXELS - MSX_VISIBLE_XBORDER_PIXELS, MSX_TOTAL_XRES_PIXELS - MSX_XBORDER_PIXELS + MSX_VISIBLE_XBORDER_PIXELS - 1, MSX_YBORDER_PIXELS - MSX_VISIBLE_YBORDER_PIXELS, MSX_TOTAL_YRES_PIXELS - MSX_YBORDER_PIXELS + MSX_VISIBLE_YBORDER_PIXELS - 1)
1065
1066   /* sound hardware */
1067   MCFG_SPEAKER_STANDARD_MONO("mono")
1068   MCFG_SOUND_ADD("dac", DAC, 0)
1069   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.10)
1070   MCFG_SOUND_WAVE_ADD("wave", "cassette")
1071   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
1072   MCFG_SOUND_ADD("ay8910", AY8910, 1789773)
1073   MCFG_SOUND_CONFIG(msx_ay8910_interface)
1074   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.10)
1075   MCFG_SOUND_ADD("k051649", K051649, 1789773)
1076   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
1077   MCFG_SOUND_ADD("ym2413", YM2413, 3579545)
1078   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.40)
1079
1080   /* printer */
1081   MCFG_CENTRONICS_ADD("centronics", standard_centronics)
1082
1083   MCFG_CASSETTE_ADD( "cassette", msx_cassette_config )
1084
1085   MCFG_WD179X_ADD("wd179x", msx_wd17xx_interface )
1086
1087   MCFG_FLOPPY_2_DRIVES_ADD(msx_floppy_config)
1088
1089   MCFG_FRAGMENT_ADD(msx_cartslot)
1090MACHINE_CONFIG_END
1091
1092
1093static MACHINE_CONFIG_DERIVED( msx_pal, msx )
1094   MCFG_SCREEN_MODIFY("screen")
1095   MCFG_SCREEN_REFRESH_RATE(50)
1096MACHINE_CONFIG_END
1097
1098#define MSX2_XBORDER_PIXELS      16
1099#define MSX2_YBORDER_PIXELS      28
1100#define MSX2_TOTAL_XRES_PIXELS      256 * 2 + (MSX2_XBORDER_PIXELS * 2)
1101#define MSX2_TOTAL_YRES_PIXELS      212 * 2 + (MSX2_YBORDER_PIXELS * 2)
1102#define MSX2_VISIBLE_XBORDER_PIXELS   8 * 2
1103#define MSX2_VISIBLE_YBORDER_PIXELS   14 * 2
1104
1105static RP5C01_INTERFACE( rtc_intf )
1106{
1107   DEVCB_NULL
1108};
1109
1110static MACHINE_CONFIG_START( msx2, msx_state )
1111   /* basic machine hardware */
1112   MCFG_CPU_ADD("maincpu", Z80, 3579545)        /* 3.579545 MHz */
1113   MCFG_CPU_PROGRAM_MAP(msx_memory_map)
1114   MCFG_CPU_IO_MAP(msx2_io_map)
1115   MCFG_CPU_VBLANK_INT_HACK(msx2_interrupt, 262)
1116   MCFG_QUANTUM_TIME(attotime::from_hz(60))
1117
1118   MCFG_MACHINE_START( msx2 )
1119   MCFG_MACHINE_RESET( msx2 )
1120
1121   MCFG_I8255_ADD( "ppi8255", msx_ppi8255_interface )
1122
1123   /* video hardware */
1124   MCFG_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK)
1125   MCFG_SCREEN_ADD("screen", RASTER)
1126   MCFG_SCREEN_REFRESH_RATE(60)
1127   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
1128   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
1129   MCFG_SCREEN_SIZE(MSX2_TOTAL_XRES_PIXELS, MSX2_TOTAL_YRES_PIXELS)
1130   MCFG_SCREEN_VISIBLE_AREA(MSX2_XBORDER_PIXELS - MSX2_VISIBLE_XBORDER_PIXELS, MSX2_TOTAL_XRES_PIXELS - MSX2_XBORDER_PIXELS + MSX2_VISIBLE_XBORDER_PIXELS - 1, MSX2_YBORDER_PIXELS - MSX2_VISIBLE_YBORDER_PIXELS, MSX2_TOTAL_YRES_PIXELS - MSX2_YBORDER_PIXELS + MSX2_VISIBLE_YBORDER_PIXELS - 1)
1131   MCFG_SCREEN_UPDATE(generic_bitmapped)
1132
1133   MCFG_PALETTE_LENGTH(512)
1134   MCFG_PALETTE_INIT(v9938)
1135
1136   MCFG_VIDEO_START(msx2)
1137
1138   /* sound hardware */
1139   MCFG_SPEAKER_STANDARD_MONO("mono")
1140   MCFG_SOUND_ADD("dac", DAC, 0)
1141   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.10)
1142   MCFG_SOUND_WAVE_ADD("wave", "cassette")
1143   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
1144   MCFG_SOUND_ADD("ay8910", AY8910, 1789773)
1145   MCFG_SOUND_CONFIG(msx_ay8910_interface)
1146   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.10)
1147   MCFG_SOUND_ADD("k051649", K051649, 1789773)
1148   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
1149   MCFG_SOUND_ADD("ym2413", YM2413, 3579545)
1150   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.40)
1151
1152   /* printer */
1153   MCFG_CENTRONICS_ADD("centronics", standard_centronics)
1154
1155   /* cassette */
1156   MCFG_CASSETTE_ADD( "cassette", msx_cassette_config )
1157
1158   /* real time clock */
1159   MCFG_RP5C01_ADD("rtc", XTAL_32_768kHz, rtc_intf)
1160
1161   MCFG_WD179X_ADD("wd179x", msx_wd17xx_interface )
1162
1163   MCFG_FLOPPY_2_DRIVES_ADD(msx_floppy_config)
1164
1165   MCFG_FRAGMENT_ADD(msx_cartslot)
1166MACHINE_CONFIG_END
1167
1168
1169static MACHINE_CONFIG_DERIVED( msx2_pal, msx2 )
1170   MCFG_SCREEN_MODIFY("screen")
1171   MCFG_SCREEN_REFRESH_RATE(50)
1172MACHINE_CONFIG_END
1173
1174
1175/***************************************************************************
1176
1177  Game driver(s)
1178
1179***************************************************************************/
1180
1181/********************************  MSX 1 **********************************/
1182
1183/* MSX */
1184
1185ROM_START (msx)
1186   ROM_REGION (0x8000, "maincpu", 0)
1187   ROM_LOAD ("msx.rom", 0x0000, 0x8000, CRC(8205795e) SHA1(829c00c3114f25b3dae5157c0a238b52a3ac37db))
1188ROM_END
1189
1190MSX_LAYOUT_INIT (msx)
1191   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1192   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1193   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1194   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1195MSX_LAYOUT_END
1196
1197/* MSX - Al Alamiah AX-170 */
1198
1199ROM_START (ax170)
1200   ROM_REGION (0x10000, "maincpu", 0)
1201   ROM_LOAD ("ax170bios.rom", 0x0000, 0x8000, CRC(bd95c436) SHA1(5e094fca95ab8e91873ee372a3f1239b9a48a48d))
1202   ROM_LOAD ("ax170arab.rom", 0x8000, 0x8000, CRC(339cd1aa) SHA1(0287b2ec897b9196788cd9f10c99e1487d7adbbb))
1203ROM_END
1204
1205MSX_LAYOUT_INIT (ax170)
1206   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1207   MSX_LAYOUT_SLOT (1, 0, 1, 2, ROM, 0x8000, 0x8000)
1208   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1209   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1210   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1211MSX_LAYOUT_END
1212
1213/* MSX - Canon V-10 */
1214
1215ROM_START (canonv10)
1216   ROM_REGION (0x8000, "maincpu", 0)
1217   ROM_LOAD ("v10bios.rom", 0x0000, 0x8000, CRC(e9ccd789) SHA1(8963fc041975f31dc2ab1019cfdd4967999de53e))
1218ROM_END
1219
1220MSX_LAYOUT_INIT (canonv10)
1221   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1222   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1223   MSX_LAYOUT_SLOT (2, 0, 3, 1, RAM, 0x4000, 0xC000)   /* 16KB RAM */
1224   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1225MSX_LAYOUT_END
1226
1227/* MSX - Canon V-20 */
1228ROM_START (canonv20)
1229   ROM_REGION (0x8000, "maincpu", 0)
1230   ROM_LOAD ("v20bios.rom", 0x0000, 0x8000, CRC(e9ccd789) SHA1(8963fc041975f31dc2ab1019cfdd4967999de53e))
1231ROM_END
1232
1233MSX_LAYOUT_INIT (canonv20)
1234   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1235   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1236   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1237   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1238MSX_LAYOUT_END
1239
1240/* MSX - Daewoo DPC-100 */
1241
1242ROM_START (dpc100)
1243   ROM_REGION (0xc000, "maincpu", 0)
1244   ROM_LOAD ("100bios.rom", 0x0000, 0x8000, CRC(3ab0cd3b) SHA1(171b587bd5a947a13f3114120b6e7baca3b57d78))
1245   ROM_LOAD ("100han.rom", 0x8000, 0x4000, CRC(97478efb) SHA1(4421fa2504cbce18f7c84b5ea97f04e017007f07))
1246ROM_END
1247
1248MSX_LAYOUT_INIT (dpc100)
1249   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1250   MSX_LAYOUT_SLOT (0, 0, 2, 1, ROM, 0x4000, 0x8000)
1251   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1252   MSX_LAYOUT_SLOT (2, 0, 3, 1, RAM, 0x4000, 0xC000)   /* 16KB RAM */
1253   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1254MSX_LAYOUT_END
1255
1256/* MSX - Daewoo DPC-180 */
1257
1258ROM_START (dpc180)
1259   ROM_REGION (0xc000, "maincpu", 0)
1260   ROM_LOAD ("180bios.rom", 0x0000, 0x8000, CRC(3ab0cd3b) SHA1(171b587bd5a947a13f3114120b6e7baca3b57d78))
1261   ROM_LOAD ("180han.rom", 0x8000, 0x4000, CRC(97478efb) SHA1(4421fa2504cbce18f7c84b5ea97f04e017007f07))
1262ROM_END
1263
1264MSX_LAYOUT_INIT (dpc180)
1265   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1266   MSX_LAYOUT_SLOT (0, 0, 2, 1, ROM, 0x4000, 0x8000)
1267   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1268   MSX_LAYOUT_SLOT (2, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
1269   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1270MSX_LAYOUT_END
1271
1272/* MSX - Daewoo DPC-200 */
1273
1274ROM_START (dpc200)
1275   ROM_REGION (0xc000, "maincpu", 0)
1276   ROM_LOAD ("200bios.rom", 0x0000, 0x8000, CRC(3ab0cd3b) SHA1(171b587bd5a947a13f3114120b6e7baca3b57d78))
1277   ROM_LOAD ("200han.rom", 0x8000, 0x4000, CRC(97478efb) SHA1(4421fa2504cbce18f7c84b5ea97f04e017007f07))
1278ROM_END
1279
1280MSX_LAYOUT_INIT (dpc200)
1281   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1282   MSX_LAYOUT_SLOT (0, 0, 2, 1, ROM, 0x4000, 0x8000)
1283   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1284   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1285   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1286MSX_LAYOUT_END
1287
1288/* MSX - Goldstar FC-200 */
1289
1290ROM_START (gsfc200)
1291   ROM_REGION (0x8000, "maincpu", 0)
1292   ROM_LOAD ("fc200bios.rom.u5a", 0x0000, 0x4000, CRC(61f473fb) SHA1(c425750bbb2ae1d278216b45029d303e37d8df2f))
1293   ROM_LOAD ("fc200bios.rom.u5b", 0x4000, 0x4000, CRC(1a99b1a1) SHA1(e18f72271b64693a2a2bc226e1b9ebd0448e07c0))
1294ROM_END
1295
1296MSX_LAYOUT_INIT (gsfc200)
1297   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1298   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1299   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1300   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1301MSX_LAYOUT_END
1302
1303/* MSX - Gradiente Expert 1.0 */
1304
1305ROM_START (expert10)
1306   ROM_REGION (0x8000, "maincpu",0)
1307   ROM_LOAD ("expbios.rom", 0x0000, 0x8000, CRC(07610d77) SHA1(ef3e010eb57e4476700a3bbff9d2119ab3acdf62))
1308ROM_END
1309
1310MSX_LAYOUT_INIT (expert10)
1311   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1312   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1313   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1314   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1315MSX_LAYOUT_END
1316
1317/* MSX - Gradiente Expert 1.1 */
1318ROM_START (expert11)
1319   ROM_REGION (0xc000, "maincpu",0)
1320   ROM_LOAD ("expbios11.rom", 0x0000, 0x8000, CRC(efb4b972) SHA1(d6720845928ee848cfa88a86accb067397685f02))
1321ROM_END
1322
1323MSX_LAYOUT_INIT (expert11)
1324   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1325   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1326   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1327   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1328MSX_LAYOUT_END
1329
1330/* MSX - Gradiente Expert 1.3 */
1331ROM_START (expert13)
1332   ROM_REGION (0x8000, "maincpu",0)
1333   ROM_LOAD ("expbios13.rom", 0x0000, 0x8000, CRC(5638bc38) SHA1(605f5af3f358c6811f54e0173bad908614a198c0))
1334ROM_END
1335
1336MSX_LAYOUT_INIT (expert13)
1337   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1338   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1339   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
1340   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1341MSX_LAYOUT_END
1342
1343/* MSX - Gradiente Expert DDPlus */
1344ROM_START (expertdp)
1345   ROM_REGION (0xc000, "maincpu",0)
1346   ROM_LOAD ("eddpbios.rom", 0x0000, 0x8000, CRC(efb4b972) SHA1(d6720845928ee848cfa88a86accb067397685f02))
1347   ROM_LOAD ("eddpdisk.rom", 0x8000, 0x4000, CRC(549f1d90) SHA1(f1525de4e0b60a6687156c2a96f8a8b2044b6c56))
1348ROM_END
1349
1350MSX_LAYOUT_INIT (expertdp)
1351   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1352   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1353   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1354   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
1355  MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM2, 0x4000, 0x8000)
1356MSX_LAYOUT_END
1357
1358/* MSX - Gradiente Expert Plus */
1359
1360ROM_START (expertpl)
1361   ROM_REGION (0xc000, "maincpu",0)
1362   ROM_LOAD ("exppbios.rom", 0x0000, 0x8000, CRC(efb4b972) SHA1(d6720845928ee848cfa88a86accb067397685f02))
1363   ROM_LOAD ("exppdemo.rom", 0x8000, 0x4000, CRC(a9bbef64) SHA1(d4cea8c815f3eeabe0c6a1c845f902ec4318bf6b))
1364ROM_END
1365
1366MSX_LAYOUT_INIT (expertpl)
1367   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1368   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1369   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1370   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1371   MSX_LAYOUT_SLOT (3, 3, 2, 1, ROM, 0x4000, 0x8000)
1372MSX_LAYOUT_END
1373
1374/* MSX - JVC HC-7GB */
1375
1376ROM_START (jvchc7gb)
1377   ROM_REGION (0x8000, "maincpu", 0)
1378   ROM_LOAD ("hc7gbbios.rom", 0x0000, 0x8000, CRC(e9ccd789) SHA1(8963fc041975f31dc2ab1019cfdd4967999de53e))
1379ROM_END
1380
1381MSX_LAYOUT_INIT (jvchc7gb)
1382   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1383   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1384   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1385   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1386MSX_LAYOUT_END
1387
1388/* MSX - Mitsubishi ML-F80 */
1389
1390ROM_START (mlf80)
1391   ROM_REGION (0x8000, "maincpu", 0)
1392   ROM_LOAD ("mlf80bios.rom", 0x0000, 0x8000, CRC(e9ccd789) SHA1(8963fc041975f31dc2ab1019cfdd4967999de53e))
1393ROM_END
1394
1395MSX_LAYOUT_INIT (mlf80)
1396   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1397   MSX_LAYOUT_SLOT (1, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1398   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1399   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1400MSX_LAYOUT_END
1401
1402/* MSX - Mitsubishi ML-FX1 */
1403
1404ROM_START (mlfx1)
1405   ROM_REGION (0x8000, "maincpu", 0)
1406   ROM_LOAD ("mlfx1bios.rom", 0x0000, 0x8000, CRC(62867dce) SHA1(0cbe0df4af45e8f531e9c761403ac9e71808f20c))
1407ROM_END
1408
1409MSX_LAYOUT_INIT (mlfx1)
1410   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1411   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1412   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1413   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1414MSX_LAYOUT_END
1415
1416/* MSX - National CF-1200 */
1417
1418ROM_START (cf1200)
1419   ROM_REGION (0x8000, "maincpu", 0)
1420   ROM_LOAD ("1200bios.rom", 0x0000, 0x8000, CRC(5ad03407) SHA1(c7a2c5baee6a9f0e1c6ee7d76944c0ab1886796c))
1421ROM_END
1422
1423MSX_LAYOUT_INIT (cf1200)
1424   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1425   MSX_LAYOUT_SLOT (0, 0, 3, 1, RAM, 0x4000, 0xC000)   /* 16KB RAM */
1426   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1427   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1428MSX_LAYOUT_END
1429
1430/* MSX - National CF-2000 */
1431
1432ROM_START (cf2000)
1433   ROM_REGION (0x8000, "maincpu", 0)
1434   ROM_LOAD ("2000bios.rom", 0x0000, 0x8000, CRC(ee229390) SHA1(302afb5d8be26c758309ca3df611ae69cced2821))
1435ROM_END
1436
1437MSX_LAYOUT_INIT (cf2000)
1438   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1439   MSX_LAYOUT_SLOT (0, 0, 3, 1, RAM, 0x4000, 0xC000)   /* 16KB RAM */
1440   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1441   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1442MSX_LAYOUT_END
1443
1444/* MSX - National CF-2700 */
1445ROM_START (cf2700)
1446   ROM_REGION (0x8000, "maincpu", 0)
1447   ROM_LOAD ("2700bios.rom.ic32", 0x0000, 0x8000, CRC(5ad03407) SHA1(c7a2c5baee6a9f0e1c6ee7d76944c0ab1886796c))
1448ROM_END
1449
1450MSX_LAYOUT_INIT (cf2700)
1451   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1452   MSX_LAYOUT_SLOT (0, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
1453   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1454   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1455MSX_LAYOUT_END
1456
1457/* MSX - National CF-3000 */
1458
1459ROM_START (cf3000)
1460   ROM_REGION (0x8000, "maincpu", 0)
1461   ROM_LOAD ("3000bios.rom", 0x0000, 0x8000, CRC(5ad03407) SHA1(c7a2c5baee6a9f0e1c6ee7d76944c0ab1886796c))
1462ROM_END
1463
1464MSX_LAYOUT_INIT (cf3000)
1465   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1466   MSX_LAYOUT_SLOT (1, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
1467   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1468   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1469MSX_LAYOUT_END
1470
1471/* MSX - National CF-3300 */
1472ROM_START (cf3300)
1473   ROM_REGION (0xc000, "maincpu", 0)
1474   ROM_LOAD ("3300bios.rom", 0x0000, 0x8000, CRC(5ad03407) SHA1(c7a2c5baee6a9f0e1c6ee7d76944c0ab1886796c))
1475   ROM_LOAD ("3300disk.rom", 0x8000, 0x4000, CRC(549f1d90) SHA1(f1525de4e0b60a6687156c2a96f8a8b2044b6c56))
1476ROM_END
1477
1478MSX_LAYOUT_INIT (cf3300)
1479   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1480   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1481   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1482   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
1483  MSX_LAYOUT_SLOT (3, 1, 1, 2, DISK_ROM2, 0x4000, 0x8000)
1484MSX_LAYOUT_END
1485
1486/* MSX - National FS-1300 */
1487
1488ROM_START (fs1300)
1489   ROM_REGION (0x8000, "maincpu", 0)
1490   ROM_LOAD ("1300bios.rom", 0x0000, 0x8000, CRC(5ad03407) SHA1(c7a2c5baee6a9f0e1c6ee7d76944c0ab1886796c))
1491ROM_END
1492
1493MSX_LAYOUT_INIT (fs1300)
1494   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1495   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1496   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1497   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
1498MSX_LAYOUT_END
1499
1500/* MSX - National FS-4000 */
1501ROM_START (fs4000)
1502   ROM_REGION (0x38000 ,"maincpu", 0)
1503   ROM_LOAD ("4000bios.rom", 0x0000, 0x8000, CRC(071135e0) SHA1(df48902f5f12af8867ae1a87f255145f0e5e0774))
1504   ROM_LOAD ("4000word.rom", 0x8000, 0x8000, CRC(950b6c87) SHA1(931d6318774bd495a32ec3dabf8d0edfc9913324))
1505   ROM_LOAD ("4000kdr.rom", 0x10000, 0x8000, CRC(ebaa5a1e) SHA1(77bd67d5d10d459d343e79eafcd8e17eb0f209dd))
1506   ROM_LOAD ("4000kfn.rom", 0x18000, 0x20000, CRC(956dc96d) SHA1(9ed3ab6d893632b9246e91b412cd5db519e7586b))
1507ROM_END
1508
1509MSX_LAYOUT_INIT (fs4000)
1510   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1511   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1512   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1513   MSX_LAYOUT_SLOT (3, 0, 0, 2, ROM, 0x8000, 0x8000)
1514   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x10000)
1515   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1516   MSX_LAYOUT_KANJI (0x18000)
1517MSX_LAYOUT_END
1518
1519/* MSX - Philips NMS-801 */
1520
1521ROM_START (nms801)
1522   ROM_REGION (0x8000, "maincpu", 0)
1523   ROM_LOAD ("801bios.rom", 0x0000, 0x8000, CRC(fa089461) SHA1(21329398c0f350e330b353f45f21aa7ba338fc8d))
1524ROM_END
1525
1526MSX_LAYOUT_INIT (nms801)
1527   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1528   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1529   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1530   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1531MSX_LAYOUT_END
1532
1533/* MSX - Philips VG-8000 */
1534
1535ROM_START (vg8000)
1536   ROM_REGION (0x8000, "maincpu", 0)
1537   ROM_LOAD ("8000bios.rom", 0x0000, 0x8000, CRC(efd970b0) SHA1(42252cf87deeb58181a7bfec7c874190a1351779))
1538ROM_END
1539
1540MSX_LAYOUT_INIT (vg8000)
1541   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1542   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1543   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1544   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x4000, 0xC000)   /* 16KB RAM */
1545MSX_LAYOUT_END
1546
1547/* MSX - Philips VG-8010 */
1548
1549ROM_START (vg8010)
1550   ROM_REGION (0x8000, "maincpu", 0)
1551   ROM_LOAD ("8010bios.rom", 0x0000, 0x8000, CRC(efd970b0) SHA1(42252cf87deeb58181a7bfec7c874190a1351779))
1552ROM_END
1553
1554MSX_LAYOUT_INIT (vg8010)
1555   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1556   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1557   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1558   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x8000, 0x8000)   /* 32KB RAM */
1559MSX_LAYOUT_END
1560
1561/* MSX - Philips VG-8010F */
1562
1563ROM_START (vg8010f)
1564   ROM_REGION (0x8000, "maincpu", 0)
1565   ROM_LOAD ("8010fbios.rom", 0x0000, 0x8000, CRC(df57c9ca) SHA1(898630ad1497dc9a329580c682ee55c4bcb9c30c))
1566ROM_END
1567
1568MSX_LAYOUT_INIT (vg8010f)
1569   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1570   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1571   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1572   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x8000, 0x8000)   /* 32KB RAM */
1573MSX_LAYOUT_END
1574
1575/* MSX - Philips VG-8020-00 */
1576
1577ROM_START (vg802000)
1578   ROM_REGION (0x8000, "maincpu", 0)
1579   ROM_LOAD ("8020-00bios.rom", 0x0000, 0x8000, CRC(8205795e) SHA1(829c00c3114f25b3dae5157c0a238b52a3ac37db))
1580ROM_END
1581
1582MSX_LAYOUT_INIT (vg802000)
1583   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1584   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1585   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1586   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1587MSX_LAYOUT_END
1588
1589/* MSX - Philips VG-8020-20 */
1590
1591ROM_START (vg802020)
1592   ROM_REGION (0x8000, "maincpu", 0)
1593   ROM_LOAD ("8020-20bios.rom", 0x0000, 0x8000, CRC(A317E6B4) SHA1(E998F0C441F4F1800EF44E42CD1659150206CF79))
1594ROM_END
1595
1596MSX_LAYOUT_INIT (vg802020)
1597   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1598   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1599   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1600   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
1601MSX_LAYOUT_END
1602
1603/* MSX - Pioneer PX-7 */
1604
1605ROM_START (piopx7)
1606   ROM_REGION (0xc000, "maincpu", 0)
1607   ROM_LOAD ("ym2301.ic12", 0x0000, 0x8000, CRC(e9ccd789) SHA1(8963fc041975f31dc2ab1019cfdd4967999de53e))
1608   ROM_LOAD ("pd5031.ic13", 0x8000, 0x2000, CRC(91e0df72) SHA1(4f0102cdc27216fd9bcdb9663db728d2ccd8ca6d))
1609   ROM_FILL( 0xa000, 0x2000, 0x6E )
1610ROM_END
1611
1612MSX_LAYOUT_INIT (piopx7)
1613   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1614   MSX_LAYOUT_SLOT (0, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
1615   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1616   MSX_LAYOUT_SLOT (2, 0, 1, 2, ROM, 0x4000, 0x8000)
1617   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1618MSX_LAYOUT_END
1619
1620/* MSX - Sanyo MPC-100 */
1621
1622ROM_START (mpc100)
1623   ROM_REGION (0x8000, "maincpu", 0)
1624   ROM_LOAD ("mpc100bios.rom", 0x0000, 0x8000, CRC(e9ccd789) SHA1(8963fc041975f31dc2ab1019cfdd4967999de53e))
1625ROM_END
1626
1627MSX_LAYOUT_INIT (mpc100)
1628   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1629   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1630   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1631   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1632MSX_LAYOUT_END
1633
1634/* MSX - Sharp Epcom HotBit 1.1 */
1635
1636ROM_START (hotbit11)
1637   ROM_REGION (0x8000, "maincpu",0)
1638   ROM_LOAD ("hotbit11.rom", 0x0000, 0x8000, CRC(b6942694) SHA1(663f8c512d04d213fa616b0db5eefe3774012a4b))
1639ROM_END
1640
1641MSX_LAYOUT_INIT (hotbit11)
1642   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1643   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1644   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1645   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1646MSX_LAYOUT_END
1647
1648/* MSX - Sharp Epcom HotBit 1.2 */
1649
1650ROM_START (hotbit12)
1651   ROM_REGION (0x8000, "maincpu",0)
1652   ROM_LOAD ("hotbit12.rom", 0x0000, 0x8000, CRC(f59a4a0c) SHA1(9425815446d468058705bae545ffa13646744a87))
1653ROM_END
1654
1655MSX_LAYOUT_INIT (hotbit12)
1656   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1657   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1658   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1659   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1660MSX_LAYOUT_END
1661
1662/* MSX - Sharp Epcom HotBit 1.3b */
1663
1664ROM_START (hotbi13b)
1665   ROM_REGION (0x8000, "maincpu",0)
1666   ROM_LOAD ("hotbit13b.rom", 0x0000, 0x8000, CRC(7a19820e) SHA1(e0c2bfb078562d15acabc5831020a2370ea87052))
1667ROM_END
1668
1669MSX_LAYOUT_INIT (hotbi13b)
1670   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1671   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1672   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1673   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
1674MSX_LAYOUT_END
1675
1676/* MSX - Sharp Epcom HotBit 1.3p */
1677
1678ROM_START (hotbi13p)
1679   ROM_REGION (0x8000, "maincpu",0)
1680   ROM_LOAD ("hotbit13p.rom", 0x0000, 0x8000, CRC(150e239c) SHA1(942f9507d206cd8156f15601fe8032fcf0e3875b))
1681ROM_END
1682
1683MSX_LAYOUT_INIT (hotbi13p)
1684   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1685   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1686   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1687   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
1688MSX_LAYOUT_END
1689
1690/* MSX - Sony HB-10P */
1691
1692ROM_START (hb10p)
1693   ROM_REGION (0x10000, "maincpu", 0)
1694   ROM_LOAD ("10pbios.rom", 0x0000, 0x8000, CRC(0f488dd8) SHA1(5e7c8eab238712d1e18b0219c0f4d4dae180420d))
1695ROM_END
1696
1697MSX_LAYOUT_INIT (hb10p)
1698   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1699   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1700   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1701   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1702MSX_LAYOUT_END
1703
1704/* MSX - Sony HB-20P */
1705
1706ROM_START (hb20p)
1707   ROM_REGION (0x10000, "maincpu", 0)
1708   ROM_LOAD ("20pbios.rom", 0x0000, 0x8000, CRC(21af423f) SHA1(365c93d7652c9f727221689bcc348652832a7b7a))
1709ROM_END
1710
1711MSX_LAYOUT_INIT (hb20p)
1712   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1713   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1714   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1715   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1716MSX_LAYOUT_END
1717
1718/* MSX - Sony HB-201 */
1719
1720ROM_START (hb201)
1721   ROM_REGION (0x10000, "maincpu", 0)
1722   ROM_LOAD ("201bios.rom.ic9", 0x0000, 0x8000, CRC(ee229390) SHA1(302afb5d8be26c758309ca3df611ae69cced2821))
1723   ROM_LOAD ("201note.rom.ic8", 0x8000, 0x4000, CRC(74567244) SHA1(0f4f09f1a6ef7535b243afabfb44a3a0eb0498d9))
1724   ROM_FILL( 0xc000, 0x4000, 0xff )
1725ROM_END
1726
1727MSX_LAYOUT_INIT (hb201)
1728   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1729   MSX_LAYOUT_SLOT (0, 0, 2, 2, ROM, 0x8000, 0x8000)
1730   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1731   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1732   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1733MSX_LAYOUT_END
1734
1735/* MSX - Sony HB-201P */
1736
1737ROM_START (hb201p)
1738   ROM_REGION (0xc000, "maincpu", 0)
1739   ROM_LOAD ("201pbios.rom.ic9", 0x0000, 0x8000, CRC(0f488dd8) SHA1(5e7c8eab238712d1e18b0219c0f4d4dae180420d))
1740   ROM_LOAD ("201pnote.rom.ic8", 0x8000, 0x4000, CRC(1ff9b6ec) SHA1(e84d3ec7a595ee36b50e979683c84105c1871857))
1741ROM_END
1742
1743MSX_LAYOUT_INIT (hb201p)
1744   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1745   MSX_LAYOUT_SLOT (0, 0, 2, 1, ROM, 0x4000, 0x8000)
1746   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1747   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1748   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1749MSX_LAYOUT_END
1750
1751/* MSX - Sony HB-501P */
1752
1753ROM_START (hb501p)
1754   ROM_REGION (0x8000, "maincpu", 0)
1755   ROM_LOAD ("501pbios.rom", 0x0000, 0x8000, CRC(0f488dd8) SHA1(5e7c8eab238712d1e18b0219c0f4d4dae180420d))
1756ROM_END
1757
1758MSX_LAYOUT_INIT (hb501p)
1759   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1760   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1761   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1762   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1763MSX_LAYOUT_END
1764
1765/* MSX - Sony HB-55D */
1766
1767ROM_START (hb55d)
1768   ROM_REGION (0xc000, "maincpu", 0)
1769   ROM_LOAD ("55dbios.rom", 0x0000, 0x8000, CRC(7e2b32dd) SHA1(38a645febd0e0fe86d594f27c2d14be995acc730))
1770   ROM_LOAD ("55dnote.rom", 0x8000, 0x4000, CRC(8aae0494) SHA1(97ce59892573cac3c440efff6d74c8a1c29a5ad3))
1771ROM_END
1772
1773MSX_LAYOUT_INIT (hb55d)
1774   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1775   MSX_LAYOUT_SLOT (0, 0, 2, 1, ROM, 0x4000, 0x8000)
1776   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1777   MSX_LAYOUT_SLOT (2, 0, 3, 1, RAM, 0x4000, 0xC000)   /* 16KB RAM */
1778   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1779MSX_LAYOUT_END
1780
1781/* MSX - Sony HB-55P */
1782
1783ROM_START (hb55p)
1784   ROM_REGION (0xc000, "maincpu", 0)
1785   ROM_LOAD ("55pbios.ic42", 0x0000, 0x4000, CRC(24c198be) SHA1(7f8c94cb8913db32a696dec80ffc78e46693f1b7))
1786   ROM_LOAD ("55pbios.ic43", 0x4000, 0x4000, CRC(e516e7e5) SHA1(05fedd4b9bfcf4949020c79d32c4c3f03a54fb62))
1787   ROM_LOAD ("55pnote.ic44", 0x8000, 0x4000, CRC(492b12f8) SHA1(b262aedc71b445303f84efe5e865cbb71fd7d952))
1788ROM_END
1789
1790MSX_LAYOUT_INIT (hb55p)
1791   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1792   MSX_LAYOUT_SLOT (0, 0, 2, 1, ROM, 0x4000, 0x8000)
1793   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1794   MSX_LAYOUT_SLOT (2, 0, 3, 1, RAM, 0x4000, 0xC000)   /* 16KB RAM */
1795   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1796MSX_LAYOUT_END
1797
1798/* MSX - Sony HB-75D */
1799
1800ROM_START (hb75d)
1801   ROM_REGION (0xc000, "maincpu", 0)
1802   ROM_LOAD ("75dbios.rom", 0x0000, 0x8000, CRC(7e2b32dd) SHA1(38a645febd0e0fe86d594f27c2d14be995acc730))
1803   ROM_LOAD ("75dnote.rom", 0x8000, 0x4000, CRC(8aae0494) SHA1(97ce59892573cac3c440efff6d74c8a1c29a5ad3))
1804ROM_END
1805
1806MSX_LAYOUT_INIT (hb75d)
1807   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1808   MSX_LAYOUT_SLOT (0, 0, 2, 1, ROM, 0x4000, 0x8000)
1809   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1810   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1811   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1812MSX_LAYOUT_END
1813
1814/* MSX - Sony HB-75P */
1815
1816ROM_START (hb75p)
1817   ROM_REGION (0xc000, "maincpu", 0)
1818   ROM_LOAD ("75pbios.ic42", 0x0000, 0x4000, CRC(24c198be) SHA1(7f8c94cb8913db32a696dec80ffc78e46693f1b7))
1819   ROM_LOAD ("75pbios.ic43", 0x4000, 0x4000, CRC(e516e7e5) SHA1(05fedd4b9bfcf4949020c79d32c4c3f03a54fb62))
1820   ROM_LOAD ("75pnote.ic44", 0x8000, 0x4000, CRC(492b12f8) SHA1(b262aedc71b445303f84efe5e865cbb71fd7d952))
1821ROM_END
1822
1823MSX_LAYOUT_INIT (hb75p)
1824   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1825   MSX_LAYOUT_SLOT (0, 0, 2, 1, ROM, 0x4000, 0x8000)
1826   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1827   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1828   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1829MSX_LAYOUT_END
1830
1831/* MSX - Spectravideo SVI-728 */
1832
1833ROM_START (svi728)
1834   ROM_REGION (0xc000, "maincpu", 0)
1835   ROM_LOAD ("728bios.rom", 0x0000, 0x8000, CRC(1ce9246c) SHA1(ea6a82cf8c6e65eb30b98755c8577cde8d9186c0))
1836   ROM_LOAD ("707disk.rom", 0x8000, 0x4000, CRC(f9978853) SHA1(6aa856cc56eb98863c9da7a566571605682b5c6b))
1837ROM_END
1838
1839MSX_LAYOUT_INIT (svi728)
1840   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1841   MSX_LAYOUT_SLOT (1, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
1842   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1843   MSX_LAYOUT_SLOT (3, 0, 1, 1, DISK_ROM2, 0x4000, 0x8000)
1844   MSX_LAYOUT_SLOT (3, 1, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1845MSX_LAYOUT_END
1846
1847/* MSX - Spectravideo SVI-738 */
1848
1849ROM_START (svi738)
1850   ROM_REGION (0x10000, "maincpu", 0)
1851   ROM_LOAD ("738bios.rom", 0x0000, 0x8000, CRC(ad007d62) SHA1(c53b3f2c00f31683914f7452f3f4d94ae2929c0d))
1852   ROM_LOAD ("738disk.rom", 0x8000, 0x4000, CRC(acd27a36) SHA1(99a40266bc296cef1d432cb0caa8df1a7e570be4))
1853   ROM_LOAD ("738232c.rom", 0xc000, 0x2000, CRC(3353dcc6) SHA1(4e9384c9d137f0ab65ffc5a78f04cd8c9df6c8b7))
1854   ROM_FILL (0xe000, 0x2000, 0xff)
1855ROM_END
1856
1857MSX_LAYOUT_INIT (svi738)
1858   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1859   MSX_LAYOUT_SLOT (1, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
1860   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1861   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0xc000)
1862   MSX_LAYOUT_SLOT (3, 1, 1, 2, DISK_ROM2, 0x4000, 0x8000)
1863   MSX_LAYOUT_SLOT (3, 2, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1864MSX_LAYOUT_END
1865
1866/* MSX - Spectravideo SVI-738 Swedish */
1867
1868ROM_START (svi738sw)
1869   ROM_REGION (0x10000, "maincpu", 0)
1870   ROM_LOAD ("738sebios.rom", 0x0000, 0x8000, CRC(c8ccdaa0) SHA1(87f4d0fa58cfe9cef818a3185df2735e6da6168c))
1871   ROM_LOAD ("738sedisk.rom", 0x8000, 0x4000, CRC(fb884df4) SHA1(6d3a530ae822ec91f6444c681c9b08b9efadc7e7))
1872   ROM_LOAD ("738se232c.rom", 0xc000, 0x2000, CRC(3353dcc6) SHA1(4e9384c9d137f0ab65ffc5a78f04cd8c9df6c8b7))
1873   ROM_FILL (0xe000, 0x2000, 0xff)
1874ROM_END
1875
1876MSX_LAYOUT_INIT (svi738sw)
1877   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1878   MSX_LAYOUT_SLOT (1, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
1879   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1880   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0xc000)
1881   MSX_LAYOUT_SLOT (3, 1, 1, 2, DISK_ROM2, 0x4000, 0x8000)
1882   MSX_LAYOUT_SLOT (3, 2, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1883MSX_LAYOUT_END
1884
1885
1886/* MSX - Talent DPC-200 */
1887
1888ROM_START (tadpc200)
1889   ROM_REGION (0x8000, "maincpu", 0)
1890   ROM_LOAD ("dpc200bios.rom", 0x0000, 0x8000, CRC(8205795e) SHA1(829c00c3114f25b3dae5157c0a238b52a3ac37db))
1891ROM_END
1892
1893MSX_LAYOUT_INIT (tadpc200)
1894   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1895   MSX_LAYOUT_SLOT (1, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1896   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1897   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1898MSX_LAYOUT_END
1899
1900
1901/* MSX - Talent DPC-200A */
1902
1903ROM_START (tadpc20a)
1904   ROM_REGION (0x8000, "maincpu", 0)
1905   ROM_LOAD ("dpc200abios.rom", 0x0000, 0x8000, CRC(8205795e) SHA1(829c00c3114f25b3dae5157c0a238b52a3ac37db))
1906ROM_END
1907
1908MSX_LAYOUT_INIT (tadpc20a)
1909   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1910   MSX_LAYOUT_SLOT (1, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1911   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1912   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1913MSX_LAYOUT_END
1914
1915/* MSX - Toshiba HX-10 */
1916/* The BIOS on the Toshiba HX-10 is inside a big 64pin Toshiba chip label TCX-1007 */
1917
1918ROM_START (hx10)
1919   ROM_REGION (0x8000, "maincpu",0)
1920   ROM_LOAD ("tcx-1007.ic15", 0x0000, 0x8000, CRC(5486b711) SHA1(4dad9de7c28b452351cc12910849b51bd9a37ab3))
1921ROM_END
1922
1923MSX_LAYOUT_INIT (hx10)
1924   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1925   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1926   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1927   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1928MSX_LAYOUT_END
1929
1930/* MSX - Toshiba HX-10S */
1931
1932ROM_START (hx10s)
1933   ROM_REGION (0x8000, "maincpu",0)
1934   ROM_LOAD ("hx10sbios.rom", 0x0000, 0x8000, CRC(5486b711) SHA1(4dad9de7c28b452351cc12910849b51bd9a37ab3))
1935ROM_END
1936
1937MSX_LAYOUT_INIT (hx10s)
1938   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1939   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1940   MSX_LAYOUT_SLOT (2, 0, 3, 1, RAM, 0x4000, 0xC000)   /* 16KB RAM */
1941   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1942MSX_LAYOUT_END
1943
1944/* MSX - Toshiba HX-20 */
1945
1946ROM_START (hx20)
1947   ROM_REGION (0x10000, "maincpu",0)
1948   ROM_LOAD ("hx20bios.rom", 0x0000, 0x8000, CRC(8205795e) SHA1(829c00c3114f25b3dae5157c0a238b52a3ac37db))
1949   ROM_LOAD ("hx20word.rom", 0x8000, 0x8000, CRC(39b3e1c0) SHA1(9f7cfa932bd7dfd0d9ecaadc51655fb557c2e125))
1950ROM_END
1951
1952MSX_LAYOUT_INIT (hx20)
1953   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1954   MSX_LAYOUT_SLOT (0, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
1955   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1956   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1957   MSX_LAYOUT_SLOT (3, 0, 2, 0, RAM, 0x8000, 0x0000)   /* 32KB RAM */
1958   MSX_LAYOUT_SLOT (3, 3, 1, 2, ROM, 0x8000, 0x8000)
1959MSX_LAYOUT_END
1960
1961/* MSX - Yamaha CX5M */
1962
1963ROM_START (cx5m)
1964   ROM_REGION (0x10000, "maincpu",0)
1965   ROM_LOAD ("cx5mbios.rom", 0x0000, 0x8000, CRC(e2242b53) SHA1(706dd67036baeec7127e4ccd8c8db8f6ce7d0e4c))
1966   ROM_LOAD ("sfg05m.rom",       0x8000, 0x8000, CRC(6c2545c9) SHA1(bc4b242647116f4886bb92e86421f97b1be51938))
1967ROM_END
1968
1969MSX_LAYOUT_INIT (cx5m)
1970   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1971   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1972   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1973   MSX_LAYOUT_SLOT (3, 0, 0, 2, ROM, 0x8000, 0x8000)
1974   MSX_LAYOUT_SLOT (3, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
1975MSX_LAYOUT_END
1976
1977/* MSX - Yamaha CX5M-128 */
1978
1979ROM_START (cx5m128)
1980   ROM_REGION (0x18000, "maincpu",0)
1981   ROM_LOAD ("cx5m128bios.rom", 0x0000, 0x8000, CRC(507b2caa) SHA1(0dde59e8d98fa524961cd37b0e100dbfb42cf576))
1982   ROM_LOAD ("cx5m128ext.rom",  0x8000, 0x4000, CRC(feada82e) SHA1(48b0c2ff1f1e407cc44394219f7b3878efaa919f))
1983   ROM_LOAD ("sfg05.rom",      0xc000, 0x8000, CRC(2425c279) SHA1(d956167e234f60ad916120437120f86fc8c3c321))
1984   ROM_LOAD ("yrm502.rom",    0x14000,0x4000, CRC(5330fe21) SHA1(7b1798561ee1844a7d6432924fbee9b4fc591c19))
1985ROM_END
1986
1987MSX_LAYOUT_INIT (cx5m128)
1988   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1989   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1990   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1991   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0x8000)
1992   MSX_LAYOUT_SLOT (3, 1, 1, 1, ROM, 0x4000, 0x14000) /* YRM-502 */
1993   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
1994   MSX_LAYOUT_SLOT (3, 3, 0, 2, ROM, 0x8000, 0xc000) /* SFG-05 */
1995MSX_LAYOUT_END
1996
1997/* MSX - Yamaha CX5MII */
1998
1999ROM_START (cx5m2)
2000   ROM_REGION (0x14000, "maincpu",0)
2001   ROM_LOAD ("cx5m2bios.rom", 0x0000, 0x8000, CRC(507b2caa) SHA1(0dde59e8d98fa524961cd37b0e100dbfb42cf576))
2002   ROM_LOAD ("cx5m2ext.rom",  0x8000, 0x4000, CRC(feada82e) SHA1(48b0c2ff1f1e407cc44394219f7b3878efaa919f))
2003   ROM_LOAD ("sfg05.rom",       0xc000, 0x8000, CRC(2425c279) SHA1(d956167e234f60ad916120437120f86fc8c3c321))
2004ROM_END
2005
2006MSX_LAYOUT_INIT (cx5m2)
2007   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2008   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2009   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2010   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0x8000)
2011   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2012   MSX_LAYOUT_SLOT (3, 3, 0, 2, ROM, 0x8000, 0xc000)
2013MSX_LAYOUT_END
2014
2015/* MSX - Yamaha YIS303 */
2016
2017ROM_START (yis303)
2018   ROM_REGION (0x14000, "maincpu",0)
2019   ROM_LOAD ("yis303bios.rom", 0x0000, 0x8000, CRC(e2242b53) SHA1(706dd67036baeec7127e4ccd8c8db8f6ce7d0e4c))
2020   ROM_FILL( 0x8000, 0xc000, 0xff )
2021ROM_END
2022
2023MSX_LAYOUT_INIT (yis303)
2024   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2025   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2026   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2027   MSX_LAYOUT_SLOT (3, 0, 0, 3, ROM, 0xC000, 0x0000)   /* Fill FF */
2028   MSX_LAYOUT_SLOT (3, 0, 3, 1, RAM, 0x4000, 0xC000)   /* 16KB RAM */
2029MSX_LAYOUT_END
2030
2031/* MSX - Yamaha YIS503 */
2032
2033ROM_START (yis503)
2034   ROM_REGION (0x10000, "maincpu",0)
2035   ROM_LOAD ("yis503bios.rom", 0x0000, 0x8000, CRC(e2242b53) SHA1(706dd67036baeec7127e4ccd8c8db8f6ce7d0e4c))
2036   ROM_FILL( 0x8000, 0x8000, 0xff )
2037ROM_END
2038
2039MSX_LAYOUT_INIT (yis503)
2040   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2041   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2042   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2043   MSX_LAYOUT_SLOT (3, 0, 0, 2, ROM, 0xC000, 0x0000)   /* Fill FF */
2044   MSX_LAYOUT_SLOT (3, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
2045MSX_LAYOUT_END
2046
2047/* MSX - Yamaha YIS503II */
2048
2049ROM_START (yis503ii)
2050   ROM_REGION (0x8000, "maincpu",0)
2051   ROM_LOAD ("yis503iibios.rom", 0x0000, 0x8000, CRC(e2242b53) SHA1(706dd67036baeec7127e4ccd8c8db8f6ce7d0e4c))
2052ROM_END
2053
2054MSX_LAYOUT_INIT (yis503ii)
2055   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2056   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2057   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2058   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
2059MSX_LAYOUT_END
2060
2061/* MSX - Yamaha YIS503IIR Russian */
2062
2063ROM_START (y503iir)
2064   ROM_REGION (0xe000, "maincpu",0)
2065   ROM_LOAD ("yis503iirbios.rom",  0x0000, 0x8000, CRC(225a4f9e) SHA1(5173ac403e26c462f904f85c9ef5e7b1e19253e7))
2066   ROM_LOAD ("yis503iirdisk.rom", 0x8000, 0x4000, CRC(9eb7e24d) SHA1(3a481c7b7e4f0406a55952bc5b9f8cf9d699376c))
2067   ROM_LOAD ("yis503iirnet.rom",  0xc000, 0x2000, CRC(0731db3f) SHA1(264fbb2de69fdb03f87dc5413428f6aa19511a7f))
2068ROM_END
2069
2070MSX_LAYOUT_INIT (y503iir)
2071   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2072   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2073   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2074   MSX_LAYOUT_SLOT (3, 1, 1, 2, DISK_ROM2, 0x4000, 0x8000) /* National disk */
2075   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
2076   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x2000, 0xc000)   /* Net */
2077MSX_LAYOUT_END
2078
2079/* MSX - Yamaha YIS503IIR Estonian */
2080
2081ROM_START (y503iir2)
2082   ROM_REGION (0xe000, "maincpu",0)
2083   ROM_LOAD ("yis503ii2bios.rom",  0x0000, 0x8000, CRC(1548cee3) SHA1(42c7fff25b1bd90776ac0aea971241aedce8947d))
2084   ROM_LOAD ("yis503iirdisk.rom", 0x8000, 0x4000, CRC(9eb7e24d) SHA1(3a481c7b7e4f0406a55952bc5b9f8cf9d699376c))
2085   ROM_LOAD ("yis503iirnet.rom",  0xc000, 0x2000, CRC(0731db3f) SHA1(264fbb2de69fdb03f87dc5413428f6aa19511a7f))
2086ROM_END
2087
2088MSX_LAYOUT_INIT (y503iir2)
2089   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2090   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2091   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2092   MSX_LAYOUT_SLOT (3, 1, 1, 2, DISK_ROM2, 0x4000, 0x8000) /* National disk */
2093   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
2094   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x2000, 0xc000)   /* Net */
2095MSX_LAYOUT_END
2096
2097/* MSX - Yamaha YIS503M */
2098
2099ROM_START (yis503m)
2100   ROM_REGION (0x10000, "maincpu",0)
2101   ROM_LOAD ("yis503mbios.rom", 0x0000, 0x8000, CRC(e2242b53) SHA1(706dd67036baeec7127e4ccd8c8db8f6ce7d0e4c))
2102   ROM_LOAD ("sfg05m.rom",       0x8000, 0x8000, CRC(6c2545c9) SHA1(bc4b242647116f4886bb92e86421f97b1be51938))
2103ROM_END
2104
2105MSX_LAYOUT_INIT (yis503m)
2106   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2107   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2108   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2109   MSX_LAYOUT_SLOT (3, 0, 0, 2, ROM, 0x8000, 0x8000)
2110   MSX_LAYOUT_SLOT (3, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
2111MSX_LAYOUT_END
2112
2113/* MSX - Yashica YC-64 */
2114
2115ROM_START (yc64)
2116   ROM_REGION (0x8000, "maincpu",0)
2117   ROM_LOAD ("yc64bios.rom", 0x0000, 0x8000, CRC(e9ccd789) SHA1(8963fc041975f31dc2ab1019cfdd4967999de53e))
2118ROM_END
2119
2120MSX_LAYOUT_INIT (yc64)
2121   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2122   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2123   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2124   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
2125MSX_LAYOUT_END
2126
2127/* MSX - Frael Bruc 100-1 */
2128
2129ROM_START (bruc100)
2130   ROM_REGION (0x8000, "maincpu",0)
2131    ROM_LOAD( "bruc100-1bios.rom", 0x0000, 0x8000, CRC(c7bc4298) SHA1(3abca440cba16ac5e162b602557d30169f77adab))
2132ROM_END
2133
2134MSX_LAYOUT_INIT (bruc100)
2135   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2136   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2137   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2138   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB RAM */
2139MSX_LAYOUT_END
2140
2141
2142/********************************  MSX 2 **********************************/
2143
2144/* MSX2 */
2145
2146ROM_START (msx2)
2147   ROM_REGION (0x20000, "maincpu",0)
2148   ROM_LOAD ("msx2.rom", 0x0000, 0x8000, CRC(f05ed518) SHA1(5e1a4bd6826b29302a1eb88c340477e7cbd0b50a))
2149   ROM_LOAD ("msx2ext.rom", 0x8000, 0x4000, CRC(95db2959) SHA1(e7905d16d2ccd57a013c122dc432106cd59ef52c))
2150   ROM_LOAD_OPTIONAL ("disk.rom", 0xc000, 0x4000, CRC(b7c58fad) SHA1(bc517b4a248c3a1338c5efc937b0128b6a783808))
2151   ROM_LOAD_OPTIONAL ("fmpac.rom", 0x10000, 0x10000, CRC(0e84505d) SHA1(9d789166e3caf28e4742fe933d962e99618c633d))
2152ROM_END
2153
2154MSX_LAYOUT_INIT (msx2)
2155   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2156   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2157   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2158   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2159   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
2160   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2161   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2162MSX_LAYOUT_END
2163
2164/* MSX2 - Al Alamiah AX-350 */
2165
2166ROM_START (ax350)
2167   ROM_REGION (0x44000, "maincpu", 0)
2168   ROM_LOAD ("ax350bios.rom",  0x0000,  0x8000, CRC(ea306155) SHA1(35195ab67c289a0b470883464df66bc6ea5b00d3))
2169   ROM_LOAD ("ax350ext.rom",   0x8000,  0x4000, CRC(7c7540b7) SHA1(ebb76f9061e875365023523607db610f2eda1d26))
2170   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2171   ROM_FILL (0xc000, 0x14000, 0)
2172   ROM_LOAD ("ax350arab.rom", 0x20000,  0x8000, CRC(c0d8fc85) SHA1(2c9600c6e0025fee10d249e97448ecaa37e38c42))
2173   ROM_LOAD ("ax350swp.rom",  0x28000,  0x8000, CRC(076f40fc) SHA1(4b4508131dca6d811694ae6379f41364c477de58))
2174   ROM_LOAD ("ax350paint.rom",0x30000, 0x10000, CRC(18956e3a) SHA1(ace202e87337fbc54fea21e22c0b3af0abe6f4ae))
2175   ROM_LOAD ("ax350disk.rom", 0x40000,  0x4000, CRC(1e7d6512) SHA1(78cd7f847e77fd8cd51a647efb2725ba93f4c471))
2176ROM_END
2177
2178MSX_LAYOUT_INIT (ax350)
2179   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000,  0x0000)  /* Bios */
2180   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000,  0x8000)  /* Ext */
2181   MSX_LAYOUT_SLOT (0, 1, 1, 2, ROM, 0x8000,  0x20000)  /* Arab */
2182   MSX_LAYOUT_SLOT (0, 2, 1, 2, ROM, 0x8000,  0x28000) /* SWP */
2183   MSX_LAYOUT_SLOT (0, 3, 0, 4, ROM, 0x10000, 0x30000)  /* Paint */
2184   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2185   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2186   MSX_LAYOUT_SLOT (3, 1, 1, 2, DISK_ROM2, 0x4000, 0x40000) /* Disk */
2187   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2188   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2189MSX_LAYOUT_END
2190
2191/* MSX2 - Al Alamiah AX-370 */
2192
2193ROM_START (ax370)
2194   ROM_REGION (0x44000, "maincpu", 0)
2195   ROM_LOAD ("ax370bios.rom",  0x0000,  0x8000, CRC(ea306155) SHA1(35195ab67c289a0b470883464df66bc6ea5b00d3))
2196   ROM_LOAD ("ax370ext.rom",   0x8000,  0x4000, CRC(7c7540b7) SHA1(ebb76f9061e875365023523607db610f2eda1d26))
2197   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2198   ROM_FILL (0xc000, 0x14000, 0)
2199   ROM_LOAD ("ax370arab.rom", 0x20000,  0x8000, CRC(c0d8fc85) SHA1(2c9600c6e0025fee10d249e97448ecaa37e38c42))
2200   ROM_LOAD ("ax370swp.rom",  0x28000,  0x8000, CRC(076f40fc) SHA1(4b4508131dca6d811694ae6379f41364c477de58))
2201   ROM_LOAD ("ax370paint.rom",0x30000, 0x10000, CRC(18956e3a) SHA1(ace202e87337fbc54fea21e22c0b3af0abe6f4ae))
2202   ROM_LOAD ("ax370disk.rom", 0x40000,  0x4000, CRC(60f8baba) SHA1(95de8809d2758fc0a743390ea5085b602e59e101))
2203ROM_END
2204
2205MSX_LAYOUT_INIT (ax370)
2206   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000,  0x0000)  /* Bios */
2207   MSX_LAYOUT_SLOT (0, 2, 1, 2, ROM, 0x8000,  0x28000) /* SWP */
2208   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2209   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2210  MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2211   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000,  0x8000)  /* Ext */
2212   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000,  0x20000)  /* Arab */
2213   //MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0x40000) /* TC8566AF Disk controller*/
2214   MSX_LAYOUT_SLOT (3, 3, 0, 4, ROM, 0x10000, 0x30000)  /* Paint */
2215   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2216MSX_LAYOUT_END
2217
2218/* MSX2 - Daewoo CPC-300 */
2219
2220ROM_START (cpc300)
2221   ROM_REGION (0x30000, "maincpu", 0)
2222   ROM_LOAD ("300bios.rom", 0x0000, 0x8000, CRC(53850907) SHA1(affa3c5cd8db79a1450ad8a7f405a425b251653d))
2223   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2224   ROM_FILL (0xc000, 0x14000, 0)
2225   ROM_LOAD ("300ext.rom", 0x20000, 0x8000, CRC(d64da39c) SHA1(fb51c505adfbc174df94289fa894ef969f5357bc))
2226   ROM_LOAD ("300han.rom", 0x28000, 0x8000, CRC(e78cd87f) SHA1(47a9d9a24e4fc6f9467c6e7d61a02d45f5a753ef))
2227ROM_END
2228
2229MSX_LAYOUT_INIT (cpc300)
2230   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2231   MSX_LAYOUT_SLOT (0, 1, 1, 2, ROM, 0x8000, 0x28000)
2232   MSX_LAYOUT_SLOT (0, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2233   MSX_LAYOUT_SLOT (0, 3, 0, 2, ROM, 0x8000, 0x20000)
2234   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2235   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2236   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2237MSX_LAYOUT_END
2238
2239/* MSX2 - Daewoo CPC-300E */
2240
2241ROM_START (cpc300e)
2242   ROM_REGION (0x30000, "maincpu", 0)
2243   ROM_LOAD ("300ebios.rom", 0x0000, 0x8000, CRC(53850907) SHA1(affa3c5cd8db79a1450ad8a7f405a425b251653d))
2244   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2245   ROM_FILL (0xc000, 0x14000, 0)
2246   ROM_LOAD ("300eext.rom", 0x20000, 0x8000, CRC(d64da39c) SHA1(fb51c505adfbc174df94289fa894ef969f5357bc))
2247   ROM_LOAD ("300ehan.rom", 0x28000, 0x4000, CRC(5afea78d) SHA1(f08c91f8c78d681e1f02eaaaaafb87ad81112b60))
2248ROM_END
2249
2250MSX_LAYOUT_INIT (cpc300e)
2251   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2252   MSX_LAYOUT_SLOT (0, 1, 1, 1, ROM, 0x4000, 0x28000)
2253   MSX_LAYOUT_SLOT (0, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2254   MSX_LAYOUT_SLOT (0, 3, 0, 2, ROM, 0x8000, 0x20000)
2255   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2256   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2257   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2258MSX_LAYOUT_END
2259
2260/* MSX2 - Daewoo CPC-400 */
2261ROM_START (cpc400)
2262   ROM_REGION (0x50000, "maincpu", 0)
2263   ROM_LOAD ("400bios.rom", 0x0000, 0x8000, CRC(53850907) SHA1(affa3c5cd8db79a1450ad8a7f405a425b251653d))
2264   ROM_LOAD ("400disk.rom", 0x8000, 0x4000, CRC(5fa517df) SHA1(914f6ccb25d78621186001f2f5e2aaa2d628cd0c))
2265   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2266   ROM_FILL (0xc000, 0x14000, 0)
2267   ROM_LOAD ("400ext.rom", 0x20000, 0x8000, CRC(2ba104a3) SHA1(b6d3649a6647fa9f6bd61efc317485a20901128f))
2268   ROM_LOAD ("400han.rom", 0x28000, 0x8000, CRC(a8ead5e3) SHA1(87936f808423dddfd00629056d6807b4be1dc63e))
2269   ROM_LOAD ("400kfn.rom", 0x30000, 0x20000, CRC(b663c605) SHA1(965f4982790f1817bcbabbb38c8777183b231a55))
2270ROM_END
2271
2272MSX_LAYOUT_INIT (cpc400)
2273   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2274   MSX_LAYOUT_SLOT (0, 1, 1, 2, ROM, 0x8000, 0x28000)
2275   MSX_LAYOUT_SLOT (0, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2276   MSX_LAYOUT_SLOT (0, 3, 0, 2, ROM, 0x8000, 0x20000)
2277   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2278   MSX_LAYOUT_SLOT (2, 0, 1, 2, DISK_ROM2, 0x4000, 0x8000)
2279   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2280   MSX_LAYOUT_KANJI (0x30000)
2281   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2282MSX_LAYOUT_END
2283
2284/* MSX2 - Daewoo CPC-400S */
2285
2286ROM_START (cpc400s)
2287   ROM_REGION (0x50000, "maincpu", 0)
2288   ROM_LOAD ("400sbios.rom", 0x0000, 0x8000, CRC(53850907) SHA1(affa3c5cd8db79a1450ad8a7f405a425b251653d))
2289   ROM_LOAD ("400sdisk.rom", 0x8000, 0x4000, CRC(5fa517df) SHA1(914f6ccb25d78621186001f2f5e2aaa2d628cd0c))
2290   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2291   ROM_FILL (0xc000, 0x14000, 0)
2292   ROM_LOAD ("400sext.rom", 0x20000, 0x8000, CRC(2ba104a3) SHA1(b6d3649a6647fa9f6bd61efc317485a20901128f))
2293   ROM_LOAD ("400shan.rom", 0x28000, 0x8000, CRC(975e7a31) SHA1(6a50295ea35e720ba6f4ba5616c3441128b384ed))
2294   ROM_LOAD ("400skfn.rom", 0x30000, 0x20000, CRC(fa85368c) SHA1(30fff22e3e3d464993707488442721a5e56a9707))
2295ROM_END
2296
2297MSX_LAYOUT_INIT (cpc400s)
2298   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2299   MSX_LAYOUT_SLOT (0, 1, 1, 2, ROM, 0x8000, 0x28000)
2300   MSX_LAYOUT_SLOT (0, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2301   MSX_LAYOUT_SLOT (0, 3, 0, 2, ROM, 0x8000, 0x20000)
2302   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2303   MSX_LAYOUT_SLOT (2, 0, 1, 2, DISK_ROM2, 0x4000, 0x8000)
2304   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2305   MSX_LAYOUT_KANJI (0x30000)
2306   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2307MSX_LAYOUT_END
2308
2309/* MSX2 - Gradiente Expert 2.0 */
2310
2311ROM_START (expert20)
2312   ROM_REGION (0x28000, "maincpu", 0)
2313   ROM_LOAD ("exp20bios.rom", 0x0000, 0x8000, CRC(6BACDCE4) SHA1(9c43106dba3ae2829e9a11dffa9d000ed6d6454c))
2314   ROM_LOAD ("exp20ext.rom",  0x8000, 0x4000, CRC(08CED880) SHA1(4f2a7e0172f0214f025f23845f6e053d0ffd28e8))
2315   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2316   ROM_FILL (0xc000, 0x14000, 0)
2317   ROM_LOAD ("xbasic2.rom", 0x20000, 0x4000, CRC(2825b1a0) SHA1(47370bec7ca1f0615a54eda548b07fbc0c7ef398))
2318   ROM_LOAD ("microsoldisk.rom", 0x24000, 0x4000, CRC(6704ef81) SHA1(a3028515ed829e900cc8deb403e17b09a38bf9b0))
2319ROM_END
2320
2321MSX_LAYOUT_INIT (expert20)
2322   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2323   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2324   MSX_LAYOUT_SLOT (1, 1, 0, 1, ROM, 0x4000, 0x8000) /* EXT */
2325   MSX_LAYOUT_SLOT (1, 1, 1, 1, ROM, 0x4000, 0x20000) /* BASIC */
2326   MSX_LAYOUT_SLOT (1, 3, 1, 1, DISK_ROM, 0x4000, 0x24000) /* Microsol controller */
2327   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2328   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2329   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2330MSX_LAYOUT_END
2331
2332
2333/* MSX2 - National FS-4500 */
2334
2335ROM_START (fs4500)
2336   ROM_REGION (0x94000, "maincpu",0)
2337   ROM_LOAD ("4500bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2338   ROM_LOAD ("4500ext.rom", 0x8000, 0x4000, CRC(4a48779c) SHA1(b8e30d604d319d511cbfbc61e5d8c38fbb9c5a33))
2339   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2340   ROM_FILL (0xc000, 0x14000, 0)
2341   ROM_LOAD ("4500font.rom", 0x20000, 0x4000, CRC(4bd54f95) SHA1(3ce8e35790eb4689b21e14c7ecdd4b63943ee158))
2342   ROM_LOAD ("4500buns.rom", 0x24000, 0x8000, CRC(c9398e11) SHA1(e89ea1e8e583392e2dd9debb8a4b6a162f58ba91))
2343   ROM_LOAD ("4500jush.rom", 0x2c000, 0x8000, CRC(4debfd2d) SHA1(6442c1c5cece64c6dae90cc6ae3675f070d93e06))
2344   ROM_LOAD ("4500wor1.rom", 0x34000, 0xc000, CRC(0c8b5cfb) SHA1(3f047469b62d93904005a0ea29092e892724ce0b))
2345   ROM_LOAD ("4500wor2.rom", 0x40000, 0xc000, CRC(d9909451) SHA1(4c8ea05c09b40c41888fa18db065575a317fda16))
2346   ROM_LOAD ("4500kdr1.rom", 0x4c000, 0x4000, CRC(f8c7f0db) SHA1(df07e89fa0b1c7874f9cdf184c136f964fea4ff4))
2347   ROM_LOAD ("4500kdr2.rom", 0x50000, 0x4000, CRC(69e87c31) SHA1(c63db26660da96af56f8a7d3ea18544b9ae5a37c))
2348   ROM_LOAD ("4500kfn.rom", 0x54000, 0x20000, CRC(956dc96d) SHA1(9ed3ab6d893632b9246e91b412cd5db519e7586b))
2349   ROM_LOAD ("4500budi.rom", 0x74000, 0x20000, CRC(f94590f8) SHA1(1ebb06062428fcdc66808a03761818db2bba3c73))
2350ROM_END
2351
2352MSX_LAYOUT_INIT (fs4500)
2353   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2354   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
2355   MSX_LAYOUT_SLOT (0, 2, 0, 1, ROM, 0x4000, 0x20000)
2356   MSX_LAYOUT_SLOT (0, 3, 1, 2, ROM, 0x8000, 0x2c000)
2357   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2358   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2359   MSX_LAYOUT_SLOT (3, 0, 0, 3, ROM, 0xc000, 0x34000)
2360   MSX_LAYOUT_SLOT (3, 0, 3, 1, ROM, 0x4000, 0x4c000)
2361   MSX_LAYOUT_SLOT (3, 1, 0, 3, ROM, 0xc000, 0x40000)
2362   MSX_LAYOUT_SLOT (3, 1, 3, 1, ROM, 0x4000, 0x50000)
2363   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
2364   MSX_LAYOUT_KANJI (0x54000)
2365/*  MSX_LAYOUT_BUNSETSU (0x74000) */ /* Matsushita Bunsetsu Henkan ROM must be emulated */
2366MSX_LAYOUT_END
2367
2368/* MSX2 - National FS-4600 */
2369
2370ROM_START (fs4600)
2371   ROM_REGION (0x170000, "maincpu",0)
2372   ROM_LOAD ("4600bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2373   ROM_LOAD ("4600ext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2374   ROM_LOAD ("4600disk.rom", 0xc000, 0x4000, CRC(ae4e65b7) SHA1(073feb8bb645d935e099afaf61e6f04f52adee42))
2375   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2376   ROM_FILL (0x10000, 0x10000, 0)
2377   ROM_LOAD ("4600fon1.rom", 0x20000, 0x4000, CRC(7391389b) SHA1(31292b9ca9fe7d1d8833530f44c0a5671bfefe4e))
2378   ROM_LOAD ("4600fon2.rom", 0x24000, 0x4000, CRC(c3a6b445) SHA1(02155fc25c9bd23e1654fe81c74486351e1ecc28))
2379   ROM_LOAD ("4600kdr.rom", 0x28000, 0x8000, CRC(b2db6bf5) SHA1(3a9a942ed888dd641cddf8deada1879c454df3c6))
2380   ROM_LOAD ("4600kfn.rom", 0x30000, 0x20000, CRC(c61ddc5d) SHA1(5e872d5853698731a0ed22fb72dbcdfd59cd19c3))
2381   ROM_LOAD ("4600kf12.rom", 0x50000, 0x20000, CRC(340d1ef7) SHA1(a7a23dc01314e88381eee88b4878b39931ab4818))
2382   ROM_LOAD ("4600firm.rom", 0x70000, 0x100000, CRC(1df57472) SHA1(005794c10a4237de3907ba4a44d436078d3c06c2))
2383ROM_END
2384
2385MSX_LAYOUT_INIT (fs4600)
2386   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2387   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
2388   MSX_LAYOUT_SLOT (0, 2, 0, 1, ROM, 0x4000, 0x20000)
2389   MSX_LAYOUT_SLOT (0, 2, 1, 2, ROM, 0x8000, 0x28000)
2390   MSX_LAYOUT_SLOT (0, 3, 0, 1, ROM, 0x4000, 0x24000)
2391   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2392   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2393   MSX_LAYOUT_SLOT (3, 1, 0, 4, ASCII16, 0x100000, 0x70000) /* National FS-4600 Mapper must be emulated */
2394   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2395   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM2, 0x4000, 0xc000)
2396   MSX_LAYOUT_KANJI (0x30000)
2397/*  MSX_LAYOUT_KANJI_12 (0x50000) */ /* Matsushita 12 dots Kanji ROM must be emulated */
2398   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2399MSX_LAYOUT_END
2400
2401/* MSX2 - National FS-4700 */
2402
2403ROM_START (fs4700)
2404   ROM_REGION (0x94000, "maincpu",0)
2405   ROM_LOAD ("4700bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2406   ROM_LOAD ("4700ext.rom", 0x8000, 0x4000, CRC(4a48779c) SHA1(b8e30d604d319d511cbfbc61e5d8c38fbb9c5a33))
2407   ROM_LOAD ("4700disk.rom", 0xc000, 0x4000, CRC(1e7d6512) SHA1(78cd7f847e77fd8cd51a647efb2725ba93f4c471))
2408   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2409   ROM_FILL (0x10000, 0x10000, 0)
2410   ROM_LOAD ("4700font.rom", 0x20000, 0x4000, CRC(4bd54f95) SHA1(3ce8e35790eb4689b21e14c7ecdd4b63943ee158))
2411   ROM_LOAD ("4700buns.rom", 0x24000, 0x8000, CRC(c9398e11) SHA1(e89ea1e8e583392e2dd9debb8a4b6a162f58ba91))
2412   ROM_LOAD ("4700jush.rom", 0x2c000, 0x8000, CRC(4debfd2d) SHA1(6442c1c5cece64c6dae90cc6ae3675f070d93e06))
2413   ROM_LOAD ("4700wor1.rom", 0x34000, 0xc000, CRC(5f39a727) SHA1(f5af1d2a8bcf247f78847e1a9d995e581df87e8e))
2414   ROM_LOAD ("4700wor2.rom", 0x40000, 0xc000, CRC(d9909451) SHA1(4c8ea05c09b40c41888fa18db065575a317fda16))
2415   ROM_LOAD ("4700kdr1.rom", 0x4c000, 0x4000, CRC(f8c7f0db) SHA1(df07e89fa0b1c7874f9cdf184c136f964fea4ff4))
2416   ROM_LOAD ("4700kdr2.rom", 0x50000, 0x4000, CRC(69e87c31) SHA1(c63db26660da96af56f8a7d3ea18544b9ae5a37c))
2417   ROM_LOAD ("4700kfn.rom", 0x54000, 0x20000, CRC(956dc96d) SHA1(9ed3ab6d893632b9246e91b412cd5db519e7586b))
2418   ROM_LOAD ("4700budi.rom", 0x74000, 0x20000, CRC(f94590f8) SHA1(1ebb06062428fcdc66808a03761818db2bba3c73))
2419ROM_END
2420
2421MSX_LAYOUT_INIT (fs4700)
2422   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2423   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
2424   MSX_LAYOUT_SLOT (0, 2, 0, 1, ROM, 0x4000, 0x20000)
2425   MSX_LAYOUT_SLOT (0, 3, 1, 2, ROM, 0x8000, 0x2c000)
2426   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2427   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2428   MSX_LAYOUT_SLOT (3, 0, 0, 3, ROM, 0xc000, 0x34000)
2429   MSX_LAYOUT_SLOT (3, 0, 3, 1, ROM, 0x4000, 0x4c000)
2430   MSX_LAYOUT_SLOT (3, 1, 0, 3, ROM, 0xc000, 0x40000)
2431   MSX_LAYOUT_SLOT (3, 1, 3, 1, ROM, 0x4000, 0x50000)
2432   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
2433   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM2, 0x4000, 0xc000)
2434   MSX_LAYOUT_KANJI (0x54000)
2435/*  MSX_LAYOUT_BUNSETSU (0x74000) */ /* Matsushita Bunsetsu Henkan ROM must be emulated */
2436MSX_LAYOUT_END
2437
2438/* MSX2 - National FS-5000 */
2439
2440ROM_START (fs5000)
2441   ROM_REGION (0x50000, "maincpu",0)
2442   ROM_LOAD ("5000bios.rom", 0x0000, 0x8000, CRC(a44ea707) SHA1(59967765d6e9328909dee4dac1cbe4cf9d47d315))
2443   ROM_LOAD ("5000ext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2444   ROM_LOAD ("5000disk.rom", 0xc000, 0x4000, CRC(ae4e65b7) SHA1(073feb8bb645d935e099afaf61e6f04f52adee42))
2445   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2446   ROM_FILL (0x10000, 0x10000, 0xff)
2447   ROM_LOAD ("5000rtc.rom", 0x20000, 0x8000, CRC(03351598) SHA1(98bbfa3ab07b7a5cad55d7ddf7cbd9440caa2a86))
2448   ROM_LOAD ("5000kdr.rom", 0x28000, 0x8000, CRC(b2db6bf5) SHA1(3a9a942ed888dd641cddf8deada1879c454df3c6))
2449   ROM_LOAD ("5000kfn.rom", 0x30000, 0x20000, CRC(c61ddc5d) SHA1(5e872d5853698731a0ed22fb72dbcdfd59cd19c3))
2450ROM_END
2451
2452MSX_LAYOUT_INIT (fs5000)
2453   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2454   MSX_LAYOUT_SLOT (0, 1, 0, 4, ROM, 0x10000, 0x10000)
2455   MSX_LAYOUT_SLOT (0, 2, 0, 4, ROM, 0x10000, 0x10000)
2456   MSX_LAYOUT_SLOT (0, 3, 0, 4, ROM, 0x10000, 0x10000)
2457   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2458   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2459   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2460   MSX_LAYOUT_SLOT (3, 0, 1, 2, ROM, 0x8000, 0x28000)
2461   MSX_LAYOUT_SLOT (3, 1, 1, 1, ROM, 0x8000, 0x20000)
2462   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2463   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM2, 0x4000, 0xc000)
2464   MSX_LAYOUT_KANJI (0x30000)
2465   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2466MSX_LAYOUT_END
2467
2468/* MSX2 - National FS-5500F1/F2*/
2469
2470ROM_START (fs5500)
2471   ROM_REGION (0x50000, "maincpu",0)
2472   ROM_LOAD ("5500bios.rom", 0x0000, 0x8000, CRC(5bf38e13) SHA1(44e0dd215b2a9f0770dd76fb49187c05b083eed9))
2473   ROM_LOAD ("5500ext.rom", 0x8000, 0x4000, CRC(3c42c367) SHA1(4be8371f3b03e70ddaca495958345f3c4f8e2d36))
2474   ROM_LOAD ("5500disk.rom", 0xc000, 0x4000, CRC(1e7d6512) SHA1(78cd7f847e77fd8cd51a647efb2725ba93f4c471))
2475   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2476   ROM_FILL (0x10000, 0x10000, 0xff)
2477   ROM_LOAD ("5500imp.rom", 0x20000, 0x8000, CRC(6173a88c) SHA1(b677a861b67e8763a11d5dcf52416b42493ade57))
2478   ROM_LOAD ("5500kdr.rom", 0x28000, 0x8000, CRC(b2db6bf5) SHA1(3a9a942ed888dd641cddf8deada1879c454df3c6))
2479   ROM_LOAD ("5500kfn.rom", 0x30000, 0x20000, CRC(956dc96d) SHA1(9ed3ab6d893632b9246e91b412cd5db519e7586b))
2480ROM_END
2481
2482MSX_LAYOUT_INIT (fs5500)
2483   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2484   MSX_LAYOUT_SLOT (0, 1, 0, 4, ROM, 0x10000, 0x10000)
2485   MSX_LAYOUT_SLOT (0, 2, 0, 4, ROM, 0x10000, 0x10000)
2486   MSX_LAYOUT_SLOT (0, 3, 0, 4, ROM, 0x10000, 0x10000)
2487   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2488   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2489   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2490   MSX_LAYOUT_SLOT (3, 0, 1, 2, ROM, 0x8000, 0x28000)
2491   MSX_LAYOUT_SLOT (3, 1, 1, 1, ROM, 0x8000, 0x20000)
2492   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
2493   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM2, 0x4000, 0xc000)
2494   MSX_LAYOUT_KANJI (0x30000)
2495MSX_LAYOUT_END
2496
2497
2498/* MSX2 - Panasonic FS-A1 */
2499
2500ROM_START (fsa1)
2501   ROM_REGION (0x30000, "maincpu",0)
2502   ROM_LOAD ("a1bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2503   ROM_LOAD ("a1ext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2504   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2505   ROM_FILL (0xc000, 0x14000, 0)
2506   ROM_LOAD ("a1desk1.rom", 0x20000, 0x8000, CRC(99c48147) SHA1(63098f27beac9eca6b39d837d2a552395df33fe1))
2507   ROM_LOAD ("a1desk2.rom", 0x28000, 0x8000, CRC(7f6f4aa1) SHA1(7f5b76605e3d898cc4b5aacf1d7682b82fe84353))
2508ROM_END
2509
2510MSX_LAYOUT_INIT (fsa1)
2511   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2512   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2513   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2514   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64 KB RAM */
2515   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
2516   MSX_LAYOUT_SLOT (3, 2, 1, 2, ROM, 0x8000, 0x20000)
2517   MSX_LAYOUT_SLOT (3, 3, 1, 2, ROM, 0x8000, 0x28000)
2518MSX_LAYOUT_END
2519
2520/* MSX2 - Panasonic FS-A1 (a) */
2521
2522ROM_START (fsa1a)
2523   ROM_REGION (0x30000, "maincpu",0)
2524   ROM_LOAD ("a1bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2525   ROM_LOAD ("a1ext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2526   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2527   ROM_FILL (0xc000, 0x14000, 0)
2528   ROM_LOAD ("a1desk1a.rom", 0x20000, 0x8000, CRC(25b5b170) SHA1(d9307bfdaab1312d25e38af7c0d3a7671a9f716b))
2529   ROM_LOAD ("a1desk2.rom", 0x28000, 0x8000, CRC(7f6f4aa1) SHA1(7f5b76605e3d898cc4b5aacf1d7682b82fe84353))
2530ROM_END
2531
2532MSX_LAYOUT_INIT (fsa1a)
2533   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2534   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2535   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2536   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
2537   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
2538   MSX_LAYOUT_SLOT (3, 2, 1, 2, ROM, 0x8000, 0x20000)
2539   MSX_LAYOUT_SLOT (3, 3, 1, 2, ROM, 0x8000, 0x28000)
2540MSX_LAYOUT_END
2541
2542/* MSX2 - Panasonic FS-A1F */
2543
2544ROM_START (fsa1f)
2545   ROM_REGION (0x50000, "maincpu",0)
2546   ROM_LOAD ("a1fbios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2547   ROM_LOAD ("a1fext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2548   ROM_LOAD ("a1fdisk.rom", 0xc000, 0x4000, CRC(e25cacca) SHA1(607cfca605eaf82e3efa33459d6583efb7ecc13b))
2549   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2550   ROM_FILL (0x10000, 0x10000, 0)
2551   ROM_LOAD ("a1fkdr.rom", 0x20000, 0x8000, CRC(2dbea5ec) SHA1(ea35cc2cad9cfdf56cae224d8ee41579de37f000))
2552   ROM_LOAD ("a1fcock.rom", 0x28000, 0x8000, CRC(5c2948cd) SHA1(4a99f2444f29c2b642efd6f084081d6fd96bfa9b))
2553   ROM_LOAD ("a1fkfn.rom", 0x30000, 0x20000, CRC(c61ddc5d) SHA1(5e872d5853698731a0ed22fb72dbcdfd59cd19c3))
2554ROM_END
2555
2556MSX_LAYOUT_INIT (fsa1f)
2557   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2558   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2559   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2560   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2561   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
2562   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
2563/*  MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000) */ /* FDC Emulation of TC8566AF must be emulated */
2564   MSX_LAYOUT_SLOT (3, 3, 1, 2, ROM, 0x8000, 0x28000)
2565   MSX_LAYOUT_KANJI (0x30000)
2566   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2567MSX_LAYOUT_END
2568
2569/* MSX2 - Panasonic FS-A1FM */
2570
2571ROM_START (fsa1fm)
2572   ROM_REGION (0x180000, "maincpu",0)
2573   ROM_LOAD ("a1fmbios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2574   ROM_LOAD ("a1fmext.rom", 0x8000, 0x4000, CRC(ad295b5d) SHA1(d552319a19814494e3016de4b8f010e8f7b97e02))
2575   ROM_LOAD ("a1fmdisk.rom", 0xc000, 0x4000, CRC(e25cacca) SHA1(607cfca605eaf82e3efa33459d6583efb7ecc13b))
2576   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2577   ROM_FILL (0x10000, 0x10000, 0)
2578   ROM_LOAD ("a1fmkfn.rom", 0x40000, 0x20000, CRC(c61ddc5d) SHA1(5e872d5853698731a0ed22fb72dbcdfd59cd19c3))
2579   ROM_LOAD ("a1fmkf12.rom", 0x60000, 0x20000, CRC(340d1ef7) SHA1(a7a23dc01314e88381eee88b4878b39931ab4818))
2580   ROM_LOAD ("a1fmfirm.rom", 0x80000, 0x100000, CRC(8ce0ece7) SHA1(f89e3d8f3b6855c29d71d3149cc762e0f6918ad5))
2581ROM_END
2582
2583MSX_LAYOUT_INIT (fsa1fm)
2584   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2585   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2586   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2587   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2588   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
2589/*  MSX_LAYOUT_SLOT (3, 1, 1, 2, MODEM_ROM, 0x20000, 0x20000) */ /* Modem Mapper of FS-CM1/A1FM must be emulated */
2590/*  MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000) */ /* FDC Emulation of TC8566AF must be emulated */
2591/*  MSX_LAYOUT_SLOT (3, 3, 0, 4, FSA1FM_ROM, 0x100000, 0x80000) */ /* Panasonic FS-A1FM Mapper must be emulated */
2592   MSX_LAYOUT_KANJI (0x40000)
2593/*  MSX_LAYOUT_KANJI_12 (0x60000) */ /* Matsushita 12 dots Kanji ROM must be emulated */
2594   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2595MSX_LAYOUT_END
2596
2597/* MSX2 - Panasonic FS-A1MK2 */
2598
2599ROM_START (fsa1mk2)
2600   ROM_REGION (0x34000, "maincpu",0)
2601   ROM_LOAD ("a1mkbios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2602   ROM_LOAD ("a1mk2ext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2603   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2604   ROM_FILL (0xc000, 0x14000, 0)
2605   ROM_LOAD ("a1mkcoc1.rom", 0x20000, 0x8000, CRC(0eda3f57) SHA1(2752cd89754c05abdf7c23cba132d38e3ef0f27d))
2606   ROM_LOAD ("a1mkcoc2.rom", 0x28000, 0x4000, CRC(756d7128) SHA1(e194d290ebfa4595ce0349ea2fc15442508485b0))
2607   ROM_LOAD ("a1mkcoc3.rom", 0x2c000, 0x8000, CRC(c1945676) SHA1(a3f4e2e4934074925d775afe30ac72f150ede543))
2608ROM_END
2609
2610MSX_LAYOUT_INIT (fsa1mk2)
2611   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2612   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2613   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2614   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64 KB Mapper RAM */
2615   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
2616   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
2617   MSX_LAYOUT_SLOT (3, 2, 1, 1, ROM, 0x4000, 0x28000)
2618   MSX_LAYOUT_SLOT (3, 3, 1, 2, ROM, 0x8000, 0x2c000)
2619   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2620MSX_LAYOUT_END
2621
2622/* MSX2 - Philips NMS-8220 - 2 possible sets (/00 /16) */
2623
2624ROM_START (nms8220)
2625   ROM_REGION (0x20000, "maincpu", 0)
2626   ROM_LOAD ("8220bios.rom.u14", 0x0000, 0x8000, BAD_DUMP CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
2627   ROM_LOAD ("8220ext.rom.u14", 0x8000, 0x4000, BAD_DUMP CRC(06e4f5e6) SHA1(f5eb0a396097572589f2a6efeed045044e9425e4))
2628   ROM_LOAD ("8220pen.rom.u13", 0xc000, 0x4000, CRC(3d38c53e) SHA1(cb754aed85b3e97a7d3c5894310df7ca18f89f41))
2629   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2630   ROM_FILL (0x10000, 0x10000, 0)
2631ROM_END
2632
2633MSX_LAYOUT_INIT (nms8220)
2634   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2635   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2636   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2637   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2638   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2639   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x4000, 0xc000)
2640   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2641MSX_LAYOUT_END
2642
2643/* MSX2 - Philips NMS-8220 (a) */
2644
2645ROM_START (nms8220a)
2646   ROM_REGION (0x20000, "maincpu", 0)
2647   ROM_LOAD ("8220bios.rom.u14", 0x0000, 0x8000, BAD_DUMP CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
2648   ROM_LOAD ("8220ext.rom.u14", 0x8000, 0x4000, BAD_DUMP CRC(06e4f5e6) SHA1(f5eb0a396097572589f2a6efeed045044e9425e4))
2649   ROM_LOAD ("8220pena.rom.u13", 0xc000, 0x4000, CRC(17817b5a) SHA1(5df95d033ae70b107697b69470126ce1b7ae9eb5))
2650   /* 0x10000 - 0x1ffff reserved for optional fmpac rom from msx2 parent set */
2651   ROM_FILL (0x10000, 0x10000, 0)
2652ROM_END
2653
2654MSX_LAYOUT_INIT (nms8220a)
2655   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2656   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2657   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2658   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2659   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2660   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x4000, 0xc000)
2661   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2662MSX_LAYOUT_END
2663
2664/* MSX2 - Philips NMS-8245 - 2 possible sets (/00 /16) */
2665
2666ROM_START (nms8245)
2667   ROM_REGION (0x40000, "maincpu", 0)
2668   /* 0x10000 - 0x1ffff reserved for optional fmpac rom from msx2 parent set */
2669   ROM_FILL (0x10000, 0x10000, 0)
2670   ROM_LOAD ("nms8245.u7", 0x20000, 0x20000, BAD_DUMP CRC(0c827d5f) SHA1(064e706cb1f12b99b329944ceeedc0efc3b2d9be))
2671ROM_END
2672
2673MSX_LAYOUT_INIT (nms8245)
2674   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x20000)
2675   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2676   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2677   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x28000)
2678   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2679   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0x2c000)
2680   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2681MSX_LAYOUT_END
2682
2683/* MSX2 - Philips NMS-8245F */
2684
2685ROM_START (nms8245f)
2686   ROM_REGION (0x40000, "maincpu", 0)
2687   /* 0x10000 - 0x1ffff reserved for optional fmpac rom from msx2 parent set */
2688   ROM_FILL (0x10000, 0x10000, 0)
2689   ROM_LOAD ("nms8245.u7", 0x20000, 0x20000, BAD_DUMP CRC(0c827d5f) SHA1(064e706cb1f12b99b329944ceeedc0efc3b2d9be))
2690ROM_END
2691
2692MSX_LAYOUT_INIT (nms8245f)
2693   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x30000)
2694   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2695   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2696   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x38000)
2697   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2698   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0x3c000)
2699   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2700MSX_LAYOUT_END
2701
2702/* MSX2 - Philips NMS-8250 */
2703/* Labels taken from an NMS-8250/00 */
2704
2705ROM_START (nms8250)
2706   ROM_REGION (0x20000, "maincpu", 0)
2707   ROM_LOAD ("d23c256eac.ic119", 0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
2708   ROM_LOAD ("d23128ec.ic118", 0x8000, 0x4000, CRC(66237ecf) SHA1(5c1f9c7fb655e43d38e5dd1fcc6b942b2ff68b02))
2709   ROM_LOAD ("jq00014.ic117", 0xc000, 0x04000, CRC(ca3307d3) SHA1(c3efedda7ab947a06d9345f7b8261076fa7ceeef))
2710   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2711   ROM_FILL (0x10000, 0x10000, 0)
2712ROM_END
2713
2714MSX_LAYOUT_INIT (nms8250)
2715   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2716   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2717   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2718   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2719   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2720   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0xc000)
2721   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2722MSX_LAYOUT_END
2723
2724/* MSX2 - Philips NMS-8255 */
2725
2726ROM_START (nms8255)
2727   ROM_REGION (0x20000, "maincpu", 0)
2728   ROM_LOAD ("8255bios.rom.ic119", 0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
2729   ROM_LOAD ("8255ext.rom.ic118", 0x8000, 0x4000, CRC(66237ecf) SHA1(5c1f9c7fb655e43d38e5dd1fcc6b942b2ff68b02))
2730   ROM_LOAD ("8255disk.rom.ic117", 0xc000, 0x04000, CRC(ca3307d3) SHA1(c3efedda7ab947a06d9345f7b8261076fa7ceeef))
2731   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2732   ROM_FILL (0x10000, 0x10000, 0)
2733ROM_END
2734
2735MSX_LAYOUT_INIT (nms8255)
2736   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2737   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2738   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2739   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2740   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2741   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0xc000)
2742   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2743MSX_LAYOUT_END
2744
2745/* MSX2 - Philips NMS-8280 - 2 possible sets (/00 /16) */
2746
2747ROM_START (nms8280)
2748   ROM_REGION (0x20000, "maincpu", 0)
2749   ROM_LOAD ("8280bios.rom.ic119", 0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
2750   ROM_LOAD ("8280ext.rom.ic118", 0x8000, 0x4000, CRC(66237ecf) SHA1(5c1f9c7fb655e43d38e5dd1fcc6b942b2ff68b02))
2751   ROM_LOAD ("8280disk.rom.ic117", 0xc000, 0x04000, CRC(ca3307d3) SHA1(c3efedda7ab947a06d9345f7b8261076fa7ceeef))
2752   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2753   ROM_FILL (0x10000, 0x10000, 0)
2754ROM_END
2755
2756MSX_LAYOUT_INIT (nms8280)
2757   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2758   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2759   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2760   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2761   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2762   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0xc000)
2763   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2764MSX_LAYOUT_END
2765
2766/* MSX2 - Philips NMS-8280G */
2767
2768ROM_START (nms8280g)
2769   ROM_REGION (0x20000, "maincpu", 0)
2770   ROM_LOAD ("8280gbios.rom.ic119", 0x0000, 0x8000, CRC(8fa060e2) SHA1(b17d9bea0eb16a1aa2d0ccbd7c9488da9f57698e))
2771   ROM_LOAD ("8280gext.rom.ic118", 0x8000, 0x4000, CRC(41e36d03) SHA1(4ab7b2030d022f5486abaab22aaeaf8aa23e05f3))
2772   ROM_LOAD ("8280gdisk.rom.ic117", 0xc000, 0x04000, CRC(d0beebb8) SHA1(d1001f93c87ff7fb389e418e33bf7bc81bdbb65f))
2773   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2774   ROM_FILL (0x10000, 0x10000, 0)
2775ROM_END
2776
2777MSX_LAYOUT_INIT (nms8280g)
2778   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2779   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2780   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2781   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2782   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2783   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0xc000)
2784   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2785MSX_LAYOUT_END
2786
2787/* MSX2 - Philips VG-8230 (u11 - exp, u12 - basic, u13 - disk */
2788
2789ROM_START (vg8230)
2790   ROM_REGION (0x20000, "maincpu", 0)
2791   ROM_LOAD ("8230bios.rom.u12", 0x0000, 0x8000, CRC(b31c851d) SHA1(0de3c802057560560a03d7965fcc4cff69f8575c))
2792   ROM_LOAD ("8230ext.rom.u11", 0x8000, 0x4000, CRC(8f84f783) SHA1(3288894e1be6af705871499b23c85732dbc40993))
2793   ROM_LOAD ("8230disk.rom.u13", 0xc000, 0x4000, CRC(77c4e5bc) SHA1(849f93867ff7846b27f84d0be418569faf058ac2))
2794   /* 0x10000 - 0x1ffff reserved for optional fmpac rom from msx2 parent set */
2795   ROM_FILL (0x10000, 0x10000, 0)
2796ROM_END
2797
2798MSX_LAYOUT_INIT (vg8230)
2799   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2800   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2801   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2802   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2803   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2804   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0xc000)
2805   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2806MSX_LAYOUT_END
2807
2808/* MSX2 - Philips VG-8235 3 psosible basic and ext roms (/00 /02 /19) */
2809
2810ROM_START (vg8235)
2811   ROM_REGION (0x20000, "maincpu", 0)
2812   ROM_LOAD ("8235bios.rom.u48", 0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
2813   ROM_LOAD ("8235ext.rom.u49", 0x8000, 0x4000, CRC(66237ecf) SHA1(5c1f9c7fb655e43d38e5dd1fcc6b942b2ff68b02))
2814   ROM_LOAD ("8235disk.rom.u50", 0xc000, 0x4000, CRC(51daeb25) SHA1(8954e59aa79310c7b719ecf0cde1e82fb731dcd1))
2815   /* 0x10000 - 0x1ffff reserved for optional fmpac rom from msx2 parent set */
2816   ROM_FILL (0x10000, 0x10000, 0)
2817ROM_END
2818
2819MSX_LAYOUT_INIT (vg8235)
2820   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2821   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2822   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2823   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2824   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2825   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0xc000)
2826   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2827MSX_LAYOUT_END
2828
2829/* MSX2 - Philips VG-8235F */
2830
2831ROM_START (vg8235f)
2832   ROM_REGION (0x20000, "maincpu", 0)
2833   ROM_LOAD ("8235fbios.rom.u48", 0x0000, 0x8000, CRC(c0577a50) SHA1(3926cdd91fa89657a811463e48cfbdb350676e51))
2834   ROM_LOAD ("8235fext.rom.u49", 0x8000, 0x4000, CRC(e235d5c8) SHA1(792e6b2814ab783d06c7576c1e3ccd6a9bbac34a))
2835   ROM_LOAD ("8235fdisk.rom.u50", 0xc000, 0x4000, CRC(77c4e5bc) SHA1(849f93867ff7846b27f84d0be418569faf058ac2))
2836   /* 0x10000 - 0x1ffff reserved for optional fmpac rom from msx2 parent set */
2837   ROM_FILL (0x10000, 0x10000, 0)
2838ROM_END
2839
2840MSX_LAYOUT_INIT (vg8235f)
2841   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2842   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2843   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2844   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2845   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2846   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0xc000)
2847   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2848MSX_LAYOUT_END
2849
2850/* MSX2 - Philips VG-8240 */
2851
2852ROM_START (vg8240)
2853   ROM_REGION (0x20000, "maincpu", 0)
2854   ROM_LOAD ("8240bios.rom", 0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
2855   ROM_LOAD ("8240ext.rom", 0x8000, 0x4000, CRC(66237ecf) SHA1(5c1f9c7fb655e43d38e5dd1fcc6b942b2ff68b02))
2856   ROM_LOAD ("8240disk.rom", 0xc000, 0x4000, CRC(ca3307d3) SHA1(c3efedda7ab947a06d9345f7b8261076fa7ceeef))
2857   /* 0x10000 - 0x1ffff reserved for optional fmpac rom from msx2 parent set */
2858   ROM_FILL (0x10000, 0x10000, 0)
2859ROM_END
2860
2861MSX_LAYOUT_INIT (vg8240)
2862   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2863   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2864   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2865   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2866   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2867   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0xc000)
2868   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2869MSX_LAYOUT_END
2870
2871/* MSX2 - Sanyo Wavy PHC-23 */
2872
2873ROM_START (phc23)
2874   ROM_REGION (0x20000, "maincpu",0)
2875   ROM_LOAD ("23bios.rom", 0x0000, 0x8000, CRC(ba81b3dd) SHA1(4ce41fcc1a603411ec4e99556409c442078f0ecf))
2876   ROM_LOAD ("23ext.rom", 0x8000, 0x4000, CRC(90ca25b5) SHA1(fd9fa78bac25aa3c0792425b21d14e364cf7eea4))
2877   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2878   ROM_FILL (0xc000, 0x14000, 0)
2879ROM_END
2880
2881MSX_LAYOUT_INIT (phc23)
2882   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2883   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2884   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2885   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2886   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
2887MSX_LAYOUT_END
2888
2889/* MSX2 - Sharp Epcom HotBit 2.0 */
2890
2891ROM_START (hotbit20)
2892   ROM_REGION (0x28000, "maincpu", 0)
2893   ROM_LOAD ("hb2bios.rom", 0x0000, 0x8000, CRC(0160e8c9) SHA1(d0cfc35f22b150a1cb10decae4841dfe63b78251))
2894   ROM_LOAD ("hb2ext.rom",  0x8000, 0x4000, CRC(08ced880) SHA1(4f2a7e0172f0214f025f23845f6e053d0ffd28e8))
2895   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2896   ROM_FILL (0xc000, 0x14000, 0)
2897   ROM_LOAD ("xbasic2.rom", 0x20000, 0x4000, CRC(2825b1a0) SHA1(47370bec7ca1f0615a54eda548b07fbc0c7ef398))
2898   ROM_LOAD ("microsoldisk.rom", 0x24000, 0x4000, CRC(6704ef81) SHA1(a3028515ed829e900cc8deb403e17b09a38bf9b0))
2899ROM_END
2900
2901MSX_LAYOUT_INIT (hotbit20)
2902   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2903   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2904   MSX_LAYOUT_SLOT (1, 1, 0, 1, ROM, 0x4000, 0x8000) /* EXT */
2905   MSX_LAYOUT_SLOT (1, 1, 1, 1, ROM, 0x4000, 0x20000) /* BASIC */
2906   MSX_LAYOUT_SLOT (1, 3, 1, 1, DISK_ROM, 0x4000, 0x24000) /* Microsol controller */
2907   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2908   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2909   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2910MSX_LAYOUT_END
2911
2912/* MSX2 - Sony HB-F1 */
2913
2914ROM_START (hbf1)
2915   ROM_REGION (0x34000, "maincpu",0)
2916   ROM_LOAD ("f1bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2917   ROM_LOAD ("f1ext.rom", 0x8000, 0x4000, CRC(4a48779c) SHA1(b8e30d604d319d511cbfbc61e5d8c38fbb9c5a33))
2918   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2919   ROM_FILL (0xc000, 0x14000, 0)
2920   ROM_LOAD ("f1note1.rom", 0x20000, 0x4000, CRC(84810ea8) SHA1(9db72bb78792595a12499c821048504dc96ef848))
2921   ROM_LOAD ("f1note2.rom", 0x24000, 0x8000, CRC(e32e5ee0) SHA1(aa78fc9bcd2343f84cf790310a768ee47f90c841))
2922   ROM_LOAD ("f1note3.rom", 0x2c000, 0x8000, CRC(73eb9329) SHA1(58accf41a90693874b86ce98d8d43c27beb8b6dc))
2923ROM_END
2924
2925MSX_LAYOUT_INIT (hbf1)
2926   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2927   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2928   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2929   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2930   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0x20000)
2931   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x24000)
2932   MSX_LAYOUT_SLOT (3, 2, 1, 2, ROM, 0x8000, 0x2c000)
2933   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
2934MSX_LAYOUT_END
2935
2936/* MSX2 - Sony HB-F1II */
2937
2938ROM_START (hbf12)
2939   ROM_REGION (0x34000, "maincpu",0)
2940   ROM_LOAD ("f12bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2941   ROM_LOAD ("f12ext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2942   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2943   ROM_FILL (0xc000, 0x14000, 0)
2944   ROM_LOAD ("f12note1.rom", 0x20000, 0x4000, CRC(dcacf970) SHA1(30d914cda2180889a40a3328e0a0c1327f4eaa10))
2945   ROM_LOAD ("f12note2.rom", 0x24000, 0x8000, CRC(b0241a61) SHA1(ed2fea5c2a3c2e58d4f69f9d636e08574486a2b1))
2946   ROM_LOAD ("f12note3.rom", 0x2c000, 0x8000, CRC(44a10e6a) SHA1(917d1c079e03c4a44de864f123d03c4e32c8daae))
2947ROM_END
2948
2949MSX_LAYOUT_INIT (hbf12)
2950   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2951   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2952   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2953   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2954   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0x20000)
2955   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x24000)
2956   MSX_LAYOUT_SLOT (3, 2, 1, 2, ROM, 0x8000, 0x2c000)
2957   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2958   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2959MSX_LAYOUT_END
2960
2961/* MSX2 - Sony HB-F1XD */
2962
2963ROM_START (hbf1xd)
2964   ROM_REGION (0x20000, "maincpu",0)
2965   ROM_LOAD ("f1xdbios.rom.ic27", 0x0000, 0x8000, BAD_DUMP CRC(ba81b3dd) SHA1(4ce41fcc1a603411ec4e99556409c442078f0ecf))
2966   ROM_LOAD ("f1xdext.rom.ic27", 0x8000, 0x4000, BAD_DUMP CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2967   ROM_LOAD ("f1xddisk.rom.ic27", 0xc000, 0x4000, BAD_DUMP CRC(54c73ad6) SHA1(12f2cc79b3d09723840bae774be48c0d721ec1c6))
2968   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2969   ROM_FILL (0x10000, 0x10000, 0)
2970ROM_END
2971
2972MSX_LAYOUT_INIT (hbf1xd)
2973   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2974   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2975   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2976   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2977   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
2978   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2979   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2980MSX_LAYOUT_END
2981
2982/* MSX2 - Sony HB-F1XDMK2 */
2983
2984ROM_START (hbf1xdm2)
2985   ROM_REGION (0x20000, "maincpu",0)
2986   ROM_LOAD ("f1m2bios.rom.ic27", 0x0000, 0x8000, BAD_DUMP CRC(ba81b3dd) SHA1(4ce41fcc1a603411ec4e99556409c442078f0ecf))
2987   ROM_LOAD ("f1m2ext.rom.ic27", 0x8000, 0x4000, BAD_DUMP CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2988   ROM_LOAD ("f1m2disk.rom.ic27", 0xc000, 0x4000, BAD_DUMP CRC(54c73ad6) SHA1(12f2cc79b3d09723840bae774be48c0d721ec1c6))
2989   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2990   ROM_FILL (0x10000, 0x10000, 0)
2991ROM_END
2992
2993MSX_LAYOUT_INIT (hbf1xdm2)
2994   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2995   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2996   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2997   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2998   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
2999   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3000   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3001MSX_LAYOUT_END
3002
3003/* MSX2 - Sony HB-F500 */
3004
3005ROM_START (hbf500)
3006   ROM_REGION (0x40000, "maincpu", 0)
3007   ROM_LOAD ("f500bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
3008   ROM_LOAD ("f500ext.rom", 0x8000, 0x4000, CRC(4a48779c) SHA1(b8e30d604d319d511cbfbc61e5d8c38fbb9c5a33))
3009   ROM_LOAD ("f500disk.rom", 0xc000, 0x4000, CRC(f7f5b0ea) SHA1(e93b8da1e8dddbb3742292b0e5e58731b90e9313))
3010   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3011   ROM_FILL (0x10000, 0x10000, 0)
3012   ROM_LOAD ("f500kfn.rom", 0x20000, 0x20000, CRC(5a59926e) SHA1(6acaf2eeb57f65f7408235d5e07b7563229de799))
3013ROM_END
3014
3015MSX_LAYOUT_INIT (hbf500)
3016   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3017   MSX_LAYOUT_SLOT (0, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
3018   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
3019   MSX_LAYOUT_SLOT (0, 1, 1, 2, DISK_ROM, 0x4000, 0xc000)
3020   MSX_LAYOUT_SLOT (0, 2, 0, 2, RAM, 0x8000, 0x0000)   /* 32KB RAM */
3021   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3022   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3023   MSX_LAYOUT_KANJI (0x20000)
3024MSX_LAYOUT_END
3025
3026/* MSX2 - Sony HB-F500P */
3027
3028ROM_START (hbf500p)
3029   ROM_REGION (0x20000, "maincpu", 0)
3030   ROM_LOAD ("500pbios.rom.ic41", 0x0000, 0x8000, CRC(b31c851d) SHA1(0de3c802057560560a03d7965fcc4cff69f8575c))
3031   ROM_LOAD ("500pext.ic47", 0x8000, 0x8000, CRC(cdd4824a) SHA1(505031f1e8396a6e0cb11c1540e6e7f6999d1191))
3032   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3033   ROM_FILL (0x10000, 0x10000, 0)
3034ROM_END
3035
3036MSX_LAYOUT_INIT (hbf500p)
3037   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3038   MSX_LAYOUT_SLOT (0, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
3039   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
3040   MSX_LAYOUT_SLOT (0, 1, 1, 2, DISK_ROM, 0x4000, 0xc000)
3041   MSX_LAYOUT_SLOT (0, 2, 0, 2, RAM, 0x8000, 0x0000)   /* 32KB RAM */
3042   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3043   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3044   MSX_LAYOUT_SLOT (3, 0, 0, 4, ROM, 0x10000, 0x10000)
3045MSX_LAYOUT_END
3046
3047/* MSX2 - Sony HB-F700D */
3048
3049ROM_START (hbf700d)
3050   ROM_REGION (0x20000, "maincpu", 0)
3051   ROM_LOAD ("700dbios.rom.ic5", 0x0000, 0x8000, CRC(e975aa79) SHA1(cef16eb95502ba6ab2265fcafcedde470a101541))
3052   ROM_LOAD ("700dext.ic6", 0x8000, 0x8000, CRC(100cf756) SHA1(317722fa36c2ed31c07c5218b43490fd5badf1f8))
3053   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3054   ROM_FILL (0x10000, 0x10000, 0)
3055ROM_END
3056
3057MSX_LAYOUT_INIT (hbf700d)
3058   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3059   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3060   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3061   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3062   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
3063   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM_MM, 0x40000, 0x0000)   /* 256KB Mapper RAM */
3064   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3065MSX_LAYOUT_END
3066
3067/* MSX2 - Sony HB-F700F */
3068
3069ROM_START (hbf700f)
3070   ROM_REGION (0x20000, "maincpu", 0)
3071   ROM_LOAD ("700fbios.ic5", 0x0000, 0x8000, CRC(440dae3c) SHA1(fedd9b682d056ddd1e9b3d281723e12f859b2e69))
3072   ROM_LOAD ("700fext.ic6", 0x8000, 0x8000, CRC(7c8b07b1) SHA1(ecacb20ba0a9bbd25e8c0f128d64dd66f8cd8bee))
3073   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3074   ROM_FILL (0x10000, 0x10000, 0)
3075ROM_END
3076
3077MSX_LAYOUT_INIT (hbf700f)
3078   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3079   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3080   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3081   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3082   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
3083   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM_MM, 0x40000, 0x0000)   /* 256KB Mapper RAM */
3084   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3085MSX_LAYOUT_END
3086
3087/* MSX2 - Sony HB-F700P */
3088
3089ROM_START (hbf700p)
3090   ROM_REGION (0x20000, "maincpu", 0)
3091   ROM_LOAD ("700pbios.rom.ic5", 0x0000, 0x8000, CRC(b31c851d) SHA1(0de3c802057560560a03d7965fcc4cff69f8575c))
3092   ROM_LOAD ("700pext.ic6", 0x8000, 0x8000, CRC(63e1bffc) SHA1(496698a60432490dc1306c8cc1d4a6ded275261a))
3093   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3094   ROM_FILL (0x10000, 0x10000, 0)
3095ROM_END
3096
3097MSX_LAYOUT_INIT (hbf700p)
3098   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3099   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3100   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3101   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3102   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
3103   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM_MM, 0x40000, 0x0000)   /* 256KB Mapper RAM */
3104   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3105MSX_LAYOUT_END
3106
3107/* MSX2 - Sony HB-F700S */
3108
3109ROM_START (hbf700s)
3110   ROM_REGION (0x20000, "maincpu", 0)
3111   ROM_LOAD ("700sbios.rom.ic5", 0x0000, 0x8000, CRC(c2b889a5) SHA1(4811956f878c3e03da46317f787cdc4bebc86f47))
3112   ROM_LOAD ("700sext.ic6", 0x8000, 0x8000, CRC(28d1badf) SHA1(ae3ed88a2d7034178e08f7bdf5409f462bf67fc9))
3113   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3114   ROM_FILL (0x10000, 0x10000, 0)
3115ROM_END
3116
3117MSX_LAYOUT_INIT (hbf700s)
3118   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3119   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3120   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3121   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3122   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
3123   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM_MM, 0x40000, 0x0000)   /* 256KB Mapper RAM */
3124   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3125MSX_LAYOUT_END
3126
3127/* MSX2 - Sony HB-F900 */
3128ROM_START (hbf900)
3129   ROM_REGION (0x44000, "maincpu", 0)
3130   ROM_LOAD ("f900bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
3131   ROM_LOAD ("f900ext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
3132   ROM_LOAD ("f900disk.rom", 0xc000, 0x4000, CRC(f83d0ea6) SHA1(fc760d1d7b16370abc7eea39955f230b95b37df6))
3133   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3134   ROM_FILL (0x10000, 0x10000, 0)
3135   ROM_LOAD ("f900util.rom", 0x20000, 0x4000, CRC(bc6c7c66) SHA1(558b7383544542cf7333700ff90c3efbf93ba2a3))
3136   ROM_LOAD ("f900kfn.rom", 0x24000, 0x20000, CRC(5a59926e) SHA1(6acaf2eeb57f65f7408235d5e07b7563229de799))
3137ROM_END
3138
3139MSX_LAYOUT_INIT (hbf900)
3140   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3141   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3142   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3143   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3144   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
3145   MSX_LAYOUT_SLOT (3, 1, 0, 4, RAM_MM, 0x40000, 0x0000)   /* 256KB Mapper RAM */
3146   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x4000, 0x10000)
3147   MSX_LAYOUT_KANJI (0x24000)
3148   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3149MSX_LAYOUT_END
3150
3151/* MSX2 - Sony HB-F900 (a) */
3152ROM_START (hbf900a)
3153   ROM_REGION (0x44000, "maincpu", 0)
3154   ROM_LOAD ("f900bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
3155   ROM_LOAD ("f900ext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
3156   ROM_LOAD ("f900disa.rom", 0xc000, 0x4000, CRC(54c73ad6) SHA1(12f2cc79b3d09723840bae774be48c0d721ec1c6))
3157   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3158   ROM_FILL (0x10000, 0x10000, 0)
3159   ROM_LOAD ("f900util.rom", 0x20000, 0x4000, CRC(bc6c7c66) SHA1(558b7383544542cf7333700ff90c3efbf93ba2a3))
3160   ROM_LOAD ("f900kfn.rom", 0x24000, 0x20000, CRC(5a59926e) SHA1(6acaf2eeb57f65f7408235d5e07b7563229de799))
3161ROM_END
3162
3163MSX_LAYOUT_INIT (hbf900a)
3164   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3165   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3166   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3167   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3168   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
3169   MSX_LAYOUT_SLOT (3, 1, 0, 4, RAM_MM, 0x40000, 0x0000)   /* 256KB Mapper RAM */
3170   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x4000, 0x10000)
3171   MSX_LAYOUT_KANJI (0x24000)
3172   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3173MSX_LAYOUT_END
3174
3175/* MSX2 - Sony HB-F9P */
3176
3177ROM_START (hbf9p)
3178   ROM_REGION (0x28000, "maincpu", 0)
3179   ROM_LOAD ("f9pbios.rom.ic11", 0x0000, 0x8000, CRC(b31c851d) SHA1(0de3c802057560560a03d7965fcc4cff69f8575c))
3180   ROM_LOAD ("f9pfirm1.ic12", 0x8000, 0x8000, CRC(524f67aa) SHA1(41a186afced50ca6312cb5b6c4adb684faca6232))
3181   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3182   ROM_FILL (0x10000, 0x10000, 0)
3183   ROM_LOAD ("f9pfirm2.rom.ic13", 0x20000, 0x8000, CRC(ea97069f) SHA1(2d1880d1f5a6944fcb1b198b997a3d90ecd1903d))
3184ROM_END
3185
3186MSX_LAYOUT_INIT (hbf9p)
3187   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3188   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3189   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3190   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3191   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0xc000)
3192   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3193   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
3194   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3195MSX_LAYOUT_END
3196
3197/* MSX2 - Sony HB-F9P Russian */
3198
3199/* MSX2 - Sony HB-F9S */
3200ROM_START (hbf9s)
3201   ROM_REGION (0x28000, "maincpu", 0)
3202   ROM_LOAD ("f9sbios.ic11", 0x0000, 0x8000, CRC(c2b889a5) SHA1(4811956f878c3e03da46317f787cdc4bebc86f47))
3203   ROM_LOAD ("f9sfirm1.ic12", 0x8000, 0x8000, CRC(cf39620b) SHA1(1166a93d7185ba024bdf2bfa9a30e1c447fb6db1))
3204   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3205   ROM_FILL (0x10000, 0x10000, 0)
3206   ROM_LOAD ("f9sfirm2.ic13", 0x20000, 0x8000, CRC(ea97069f) SHA1(2d1880d1f5a6944fcb1b198b997a3d90ecd1903d))
3207ROM_END
3208
3209MSX_LAYOUT_INIT (hbf9s)
3210   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3211   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3212   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3213   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3214   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0xc000)
3215   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3216   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
3217   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3218MSX_LAYOUT_END
3219
3220/* MSX2 - Sony HB-G900AP */
3221
3222/* IC109 - 32KB Basic ROM SLOT#00 0000-7FFF */
3223/* IC112 - 16KB Basic ROM SLOT#01 0000-3FFF */
3224/* IC117 - 16KB Disk ROM SLOT#01 4000-7FFF */
3225/* IC123 - 32KB ROM RS232C ROM SLOT#02 4000-7FFF / Video Utility ROM SLOT#03 4000-7FFF */
3226
3227/* MSX2 - Sony HB-G900AP */
3228ROM_START (hbg900ap)
3229   ROM_REGION (0x28000, "maincpu", 0)
3230   ROM_LOAD ("g900bios.rom", 0x0000, 0x8000, CRC(b31c851d) SHA1(0de3c802057560560a03d7965fcc4cff69f8575c))
3231   ROM_LOAD ("g900ext.rom", 0x8000, 0x4000, CRC(8f84f783) SHA1(3288894e1be6af705871499b23c85732dbc40993))
3232   ROM_LOAD ("g900disk.rom", 0xc000, 0x4000, CRC(54c73ad6) SHA1(12f2cc79b3d09723840bae774be48c0d721ec1c6))
3233   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3234   ROM_FILL (0x10000, 0x10000, 0)
3235   ROM_LOAD ("g900232c.rom", 0x20000, 0x4000, CRC(06cf1da6) SHA1(373aa82d0426830880a7344ef98f7309d93814c7))
3236   ROM_LOAD ("g900util.rom", 0x24000, 0x4000, CRC(d0417c20) SHA1(8779b004e7605a3c419825f0373a5d8fa84e1d5b))
3237ROM_END
3238
3239MSX_LAYOUT_INIT (hbg900ap)
3240   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3241   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
3242   MSX_LAYOUT_SLOT (0, 1, 1, 2, DISK_ROM, 0x4000, 0xc000)
3243/*  MSX_LAYOUT_SLOT (0, 2, 1, 1, ROM, 0x4000, 0x20000) */ /* RS232C must be emulated */
3244   MSX_LAYOUT_SLOT (0, 3, 1, 1, ROM, 0x4000, 0x24000)
3245   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3246   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3247   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x80000, 0x0000)   /* 512KB Mapper RAM */
3248   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3249MSX_LAYOUT_END
3250
3251
3252/* MSX2 - Sony HB-G900P - 3x 32KB ROMs */
3253
3254ROM_START (hbg900p)
3255   ROM_REGION (0x28000, "maincpu", 0)
3256   ROM_LOAD ("g900bios.rom", 0x0000, 0x8000, CRC(b31c851d) SHA1(0de3c802057560560a03d7965fcc4cff69f8575c))
3257   ROM_LOAD ("g900ext.rom", 0x8000, 0x4000, CRC(8f84f783) SHA1(3288894e1be6af705871499b23c85732dbc40993))
3258   ROM_LOAD ("g900disk.rom", 0xc000, 0x4000, CRC(54c73ad6) SHA1(12f2cc79b3d09723840bae774be48c0d721ec1c6))
3259   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3260   ROM_FILL (0x10000, 0x10000, 0)
3261   ROM_LOAD ("g900232c.rom", 0x20000, 0x4000, CRC(06cf1da6) SHA1(373aa82d0426830880a7344ef98f7309d93814c7))
3262   ROM_LOAD ("g900util.rom", 0x24000, 0x4000, CRC(d0417c20) SHA1(8779b004e7605a3c419825f0373a5d8fa84e1d5b))
3263ROM_END
3264
3265MSX_LAYOUT_INIT (hbg900p)
3266   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3267   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
3268   MSX_LAYOUT_SLOT (0, 1, 1, 2, DISK_ROM, 0x4000, 0xc000)
3269/*  MSX_LAYOUT_SLOT (0, 2, 1, 1, ROM, 0x4000, 0x20000) */ /* RS232C must be emulated */
3270   MSX_LAYOUT_SLOT (0, 3, 1, 1, ROM, 0x4000, 0x24000)
3271   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3272   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3273   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3274   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3275MSX_LAYOUT_END
3276
3277/* MSX2 - Talent TPC-310 */
3278ROM_START (tpc310)
3279   ROM_REGION (0x2c000, "maincpu", 0)
3280   ROM_LOAD ("tpc310bios.rom",  0x0000, 0x8000, CRC(8cd3e845) SHA1(7bba23669b7abfb6a142f9e1735b847d6e4e8267))
3281   ROM_LOAD ("tpc310ext.rom",   0x8000, 0x4000, CRC(094a9e7a) SHA1(39dfc46260f99b670916b1e55f67a5d4136e6e54))
3282   ROM_LOAD ("dpf550disk.rom",  0xc000, 0x4000, CRC(347b1b44) SHA1(c1d83c559e1e6a6da961eafa55aab105681c634c))
3283   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3284   ROM_FILL (0x10000, 0x10000, 0)
3285   ROM_LOAD ("tpc310turbo.rom",0x20000, 0x4000, CRC(0ea62a4d) SHA1(181bf58da7184e128cd419da3109b93344a543cf))
3286   ROM_LOAD ("tpc310acc.rom",  0x24000, 0x8000, CRC(4fb8fab3) SHA1(cdeb0ed8adecaaadb78d5a5364fd603238591685))
3287ROM_END
3288
3289MSX_LAYOUT_INIT (tpc310)
3290   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3291   MSX_LAYOUT_SLOT (1, 0, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
3292   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3293   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3294   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0x20000)
3295   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x24000)
3296   MSX_LAYOUT_SLOT (3, 2, 1, 1, DISK_ROM2, 0x4000, 0xc000)
3297   MSX_LAYOUT_SLOT (3, 3, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3298   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3299MSX_LAYOUT_END
3300
3301/* MSX2 - Toshiba HX-23 */
3302
3303ROM_START (hx23)
3304   ROM_REGION (0x30000, "maincpu", 0)
3305   ROM_LOAD ("hx23bios.rom",  0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
3306   ROM_LOAD ("hx23ext.rom",   0x8000, 0x4000, CRC(06e4f5e6) SHA1(f5eb0a396097572589f2a6efeed045044e9425e4))
3307   /* 0xc000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3308   ROM_FILL (0xc000, 0x14000, 0)
3309   ROM_LOAD ("hx23word.rom", 0x20000, 0x8000, CRC(39b3e1c0) SHA1(9f7cfa932bd7dfd0d9ecaadc51655fb557c2e125))
3310   ROM_FILL (0x28000, 0x8000, 0)
3311ROM_END
3312
3313MSX_LAYOUT_INIT (hx23)
3314   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3315   MSX_LAYOUT_SLOT (0, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
3316   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3317   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3318   MSX_LAYOUT_SLOT (3, 0, 0, 2, RAM, 0x8000, 0x0000)   /* 32KB RAM */
3319   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3320   MSX_LAYOUT_SLOT (3, 3, 0, 4, ROM, 0x10000, 0x20000)
3321   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3322MSX_LAYOUT_END
3323
3324/* MSX2 - Toshiba HX-23F */
3325
3326ROM_START (hx23f)
3327   ROM_REGION (0x30000, "maincpu", 0)
3328   ROM_LOAD ("hx23fbios.rom",  0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
3329   ROM_LOAD ("hx23fext.rom",   0x8000, 0x4000, CRC(06e4f5e6) SHA1(f5eb0a396097572589f2a6efeed045044e9425e4))
3330   /* 0xc000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3331   ROM_FILL (0xc000, 0x14000, 0)
3332   ROM_LOAD ("hx23fword.rom", 0x20000, 0x8000, CRC(39b3e1c0) SHA1(9f7cfa932bd7dfd0d9ecaadc51655fb557c2e125))
3333   ROM_FILL (0x28000, 0x8000, 0)
3334ROM_END
3335
3336MSX_LAYOUT_INIT (hx23f)
3337   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3338   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3339   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3340   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
3341   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3342   MSX_LAYOUT_SLOT (3, 3, 0, 4, ROM, 0x10000, 0x20000)
3343   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3344MSX_LAYOUT_END
3345
3346/* MSX2 - Yamaha CX7M */
3347
3348ROM_START (cx7m)
3349   ROM_REGION (0x28000, "maincpu", 0)
3350   ROM_LOAD ("cx7mbios.rom",  0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
3351   ROM_LOAD ("cx7mext.rom",   0x8000, 0x4000, CRC(66237ecf) SHA1(5c1f9c7fb655e43d38e5dd1fcc6b942b2ff68b02))
3352   /* 0xc000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3353   ROM_FILL (0xc000, 0x14000, 0)
3354   ROM_LOAD ("sfg05m.rom", 0x20000, 0x8000, CRC(6c2545c9) SHA1(bc4b242647116f4886bb92e86421f97b1be51938))
3355ROM_END
3356
3357MSX_LAYOUT_INIT (cx7m)
3358   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3359   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
3360   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3361   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3362   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3363   MSX_LAYOUT_SLOT (3, 3, 0, 2, ROM, 0x8000, 0x20000)
3364   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3365MSX_LAYOUT_END
3366
3367/* MSX2 - Yamaha CX7M-128 */
3368
3369ROM_START (cx7m128)
3370   ROM_REGION (0x2c000, "maincpu", 0)
3371   ROM_LOAD ("cx7mbios.rom",  0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
3372   ROM_LOAD ("cx7mext.rom",   0x8000, 0x4000, CRC(66237ecf) SHA1(5c1f9c7fb655e43d38e5dd1fcc6b942b2ff68b02))
3373   /* 0xc000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3374   ROM_FILL (0xc000, 0x14000, 0)
3375   ROM_LOAD ("sfg05m.rom", 0x20000, 0x8000, CRC(6c2545c9) SHA1(bc4b242647116f4886bb92e86421f97b1be51938))
3376   ROM_LOAD ("yrm502.rom", 0x28000, 0x4000, CRC(51f7ddd1) SHA1(2a4b4a4657e3077df8a88f98210b76883d3702b1))
3377ROM_END
3378
3379MSX_LAYOUT_INIT (cx7m128)
3380   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3381   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
3382   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3383   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3384   MSX_LAYOUT_SLOT (3, 1, 1, 1, ROM, 0x4000, 0x28000)
3385   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3386   MSX_LAYOUT_SLOT (3, 3, 0, 2, ROM, 0x8000, 0x20000)
3387   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3388MSX_LAYOUT_END
3389
3390/********************************  MSX 2+ **********************************/
3391
3392/* MSX2+ */
3393
3394ROM_START (msx2p)
3395   ROM_REGION (0x48000, "maincpu",0)
3396   ROM_LOAD ("msx2p.rom", 0x0000, 0x8000, CRC(00870134) SHA1(e2fbd56e42da637609d23ae9df9efd1b4241b18a))
3397   ROM_LOAD ("msx2pext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3398   ROM_LOAD_OPTIONAL ("disk.rom", 0xc000, 0x4000, CRC(b7c58fad) SHA1(bc517b4a248c3a1338c5efc937b0128b6a783808))
3399   ROM_LOAD_OPTIONAL ("fmpac.rom", 0x10000, 0x10000, CRC(0e84505d) SHA1(9d789166e3caf28e4742fe933d962e99618c633d))
3400   ROM_LOAD ("msx2pkdr.rom", 0x20000, 0x8000, CRC(a068cba9) SHA1(1ef3956f7f918873fb9b031339bba45d1e5e5878))
3401   ROM_LOAD ("msx2pkfn.rom", 0x28000, 0x20000, CRC(b244f6cf) SHA1(e0e99cd91e88ce2676445663f832c835d74d6fd4))
3402ROM_END
3403
3404MSX_LAYOUT_INIT (msx2p)
3405   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3406   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3407   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3408   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
3409   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3410   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3411   MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000)
3412   MSX_LAYOUT_KANJI (0x28000)
3413   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3414MSX_LAYOUT_END
3415
3416/* MSX2+ - Panasonic FS-A1FX */
3417
3418ROM_START (fsa1fx)
3419   ROM_REGION (0x50000, "maincpu",0)
3420   ROM_LOAD ("a1fxbios.rom", 0x0000, 0x8000, CRC(19771608) SHA1(e90f80a61d94c617850c415e12ad70ac41e66bb7))
3421   ROM_LOAD ("a1fxext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3422   ROM_LOAD ("a1fxdisk.rom", 0xc000, 0x4000, CRC(2bda0184) SHA1(2a0d228afde36ac7c5d3c2aac9c7c664dd071a8c))
3423   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2p parent set */
3424   ROM_FILL (0x10000, 0x10000, 0)
3425   ROM_LOAD ("a1fxkdr.rom", 0x20000, 0x8000, CRC(a068cba9) SHA1(1ef3956f7f918873fb9b031339bba45d1e5e5878))
3426   ROM_LOAD ("a1fxcock.rom", 0x28000, 0x8000, CRC(f662e6eb) SHA1(9d67fab55b85f4ac4f5924323a70020eb8589057))
3427   ROM_LOAD ("a1fxkfn.rom", 0x30000, 0x20000, CRC(b244f6cf) SHA1(e0e99cd91e88ce2676445663f832c835d74d6fd4))
3428ROM_END
3429
3430MSX_LAYOUT_INIT (fsa1fx)
3431   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3432   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3433   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3434   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3435   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3436   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3437/*  MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000) */ /* FDC Emulation of TC8566AF must be emulated */
3438   MSX_LAYOUT_SLOT (3, 3, 1, 2, ROM, 0x8000, 0x28000)
3439   MSX_LAYOUT_KANJI (0x30000)
3440   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3441MSX_LAYOUT_END
3442
3443/* MSX2+ - Panasonic FS-A1WSX */
3444
3445ROM_START (fsa1wsx)
3446   ROM_REGION (0x270000, "maincpu",0)
3447   ROM_LOAD ("a1wsbios.rom", 0x0000, 0x8000, CRC(358ec547) SHA1(f4433752d3bf876bfefb363c749d4d2e08a218b6))
3448   ROM_LOAD ("a1wsext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3449   ROM_LOAD ("a1wsdisk.rom", 0xc000, 0x4000, CRC(ac7d92b4) SHA1(b7068e2aab02072852ca249596b7550ac632c4c2))
3450   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2p parent set */
3451   ROM_FILL (0x10000, 0x10000, 0)
3452   ROM_LOAD ("a1wskdr.rom", 0x20000, 0x8000, CRC(b4fc574d) SHA1(dcc3a67732aa01c4f2ee8d1ad886444a4dbafe06))
3453   ROM_LOAD ("a1wsmusp.rom", 0x28000, 0x4000, CRC(456e494e) SHA1(6354ccc5c100b1c558c9395fa8c00784d2e9b0a3))
3454   ROM_FILL (0x2c000, 0x4000, 0)
3455   ROM_LOAD ("a1wskfn.rom", 0x30000, 0x40000, CRC(1f6406fb) SHA1(5aff2d9b6efc723bc395b0f96f0adfa83cc54a49))
3456   ROM_LOAD ("a1wsfirm.rom", 0x70000, 0x200000, CRC(e363595d) SHA1(3330d9b6b76e3c4ccb7cf252496ed15d08b95d3f))
3457ROM_END
3458
3459MSX_LAYOUT_INIT (fsa1wsx)
3460   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3461   MSX_LAYOUT_SLOT (0, 2, 1, 1, ROM, 0x4000, 0x28000)
3462   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3463   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3464   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3465   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3466   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3467/*  MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000) */ /* FDC Emulation of TC8566AF must be emulated */
3468/*  MSX_LAYOUT_SLOT (3, 3, 1, 4, PANASONIC08, 0x200000, 0x70000) */ /* Panasonic 08KB Mapper must be emulated */
3469   MSX_LAYOUT_KANJI (0x30000)
3470   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3471MSX_LAYOUT_END
3472
3473/* MSX2+ - Panasonic FS-A1WX */
3474
3475ROM_START (fsa1wx)
3476   ROM_REGION (0x270000, "maincpu",0)
3477   ROM_LOAD ("a1wxbios.rom", 0x0000, 0x8000, CRC(19771608) SHA1(e90f80a61d94c617850c415e12ad70ac41e66bb7))
3478   ROM_LOAD ("a1wxext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3479   ROM_LOAD ("a1wxdisk.rom", 0xc000, 0x4000, CRC(2bda0184) SHA1(2a0d228afde36ac7c5d3c2aac9c7c664dd071a8c))
3480   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2p parent set */
3481   ROM_FILL (0x10000, 0x10000, 0)
3482   ROM_LOAD ("a1wxkdr.rom", 0x20000, 0x8000, CRC(a068cba9) SHA1(1ef3956f7f918873fb9b031339bba45d1e5e5878))
3483   ROM_LOAD ("a1wxmusp.rom", 0x28000, 0x4000, CRC(456e494e) SHA1(6354ccc5c100b1c558c9395fa8c00784d2e9b0a3))
3484   ROM_FILL (0x2c000, 0x4000, 0)
3485   ROM_LOAD ("a1wxkfn.rom", 0x30000, 0x40000, CRC(1f6406fb) SHA1(5aff2d9b6efc723bc395b0f96f0adfa83cc54a49))
3486   ROM_LOAD ("a1wxfirm.rom", 0x70000, 0x200000, CRC(283f3250) SHA1(d37ab4bd2bfddd8c97476cbe7347ae581a6f2972))
3487ROM_END
3488
3489MSX_LAYOUT_INIT (fsa1wx)
3490   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3491   MSX_LAYOUT_SLOT (0, 2, 1, 1, ROM, 0x4000, 0x28000)
3492   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3493   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3494   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3495   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3496   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3497/*  MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000) */ /* FDC Emulation of TC8566AF must be emulated */
3498/*  MSX_LAYOUT_SLOT (3, 3, 1, 4, PANASONIC08, 0x200000, 0x70000) */ /* Panasonic 08KB Mapper must be emulated */
3499   MSX_LAYOUT_KANJI (0x30000)
3500   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3501MSX_LAYOUT_END
3502
3503/* MSX2+ - Panasonic FS-A1WX (a) */
3504ROM_START (fsa1wxa)
3505   ROM_REGION (0x270000, "maincpu",0)
3506   ROM_LOAD ("a1wxbios.rom", 0x0000, 0x8000, CRC(19771608) SHA1(e90f80a61d94c617850c415e12ad70ac41e66bb7))
3507   ROM_LOAD ("a1wxext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3508   ROM_LOAD ("a1wxdisk.rom", 0xc000, 0x4000, CRC(2bda0184) SHA1(2a0d228afde36ac7c5d3c2aac9c7c664dd071a8c))
3509   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2p parent set */
3510   ROM_FILL (0x10000, 0x10000, 0)
3511   ROM_LOAD ("a1wxkdr.rom", 0x20000, 0x8000, CRC(a068cba9) SHA1(1ef3956f7f918873fb9b031339bba45d1e5e5878))
3512   ROM_LOAD ("a1wxmusp.rom", 0x28000, 0x4000, CRC(456e494e) SHA1(6354ccc5c100b1c558c9395fa8c00784d2e9b0a3))
3513   ROM_FILL (0x2c000, 0x4000, 0)
3514   ROM_LOAD ("a1wxkfn.rom", 0x30000, 0x40000, CRC(1f6406fb) SHA1(5aff2d9b6efc723bc395b0f96f0adfa83cc54a49))
3515   ROM_LOAD ("a1wxfira.rom", 0x70000, 0x200000, CRC(58440a8e) SHA1(8e0d4a77e7d5736e8225c2df4701509363eb230f))
3516ROM_END
3517
3518MSX_LAYOUT_INIT (fsa1wxa)
3519   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3520   MSX_LAYOUT_SLOT (0, 2, 1, 1, ROM, 0x4000, 0x28000)
3521   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3522   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3523   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3524   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3525   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3526/*  MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000) */ /* FDC Emulation of TC8566AF must be emulated */
3527/*  MSX_LAYOUT_SLOT (3, 3, 1, 4, PANASONIC08, 0x200000, 0x70000) */ /* Panasonic 08KB Mapper must be emulated */
3528   MSX_LAYOUT_KANJI (0x30000)
3529   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3530MSX_LAYOUT_END
3531
3532/* MSX2+ - Sanyo Wavy PHC-35J */
3533
3534ROM_START (phc35j)
3535   ROM_REGION (0x48000, "maincpu",0)
3536   ROM_LOAD ("35jbios.rom", 0x0000, 0x8000, CRC(358ec547) SHA1(f4433752d3bf876bfefb363c749d4d2e08a218b6))
3537   ROM_LOAD ("35jext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3538   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2p parent set */
3539   ROM_FILL (0xc000, 0x14000, 0)
3540   ROM_LOAD ("35jkdr.rom", 0x20000, 0x8000, CRC(b4fc574d) SHA1(dcc3a67732aa01c4f2ee8d1ad886444a4dbafe06))
3541   ROM_LOAD ("35jkfn.rom", 0x28000, 0x20000, CRC(c9651b32) SHA1(84a645becec0a25d3ab7a909cde1b242699a8662))
3542ROM_END
3543
3544MSX_LAYOUT_INIT (phc35j)
3545   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3546   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3547   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3548   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3549   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3550   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3551   MSX_LAYOUT_KANJI (0x28000)
3552   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3553MSX_LAYOUT_END
3554
3555/* MSX2+ - Sanyo Wavy PHC-70FD1 */
3556
3557ROM_START (phc70fd)
3558   ROM_REGION (0x50000, "maincpu",0)
3559   ROM_LOAD ("70fdbios.rom", 0x0000, 0x8000, CRC(19771608) SHA1(e90f80a61d94c617850c415e12ad70ac41e66bb7))
3560   ROM_LOAD ("70fdext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3561   ROM_LOAD ("70fddisk.rom", 0xc000, 0x4000, CRC(db7f1125) SHA1(9efa744be8355675e7bfdd3976bbbfaf85d62e1d))
3562   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2p parent set */
3563   ROM_FILL (0x10000, 0x10000, 0)
3564   ROM_LOAD ("70fdkdr.rom", 0x20000, 0x8000, CRC(a068cba9) SHA1(1ef3956f7f918873fb9b031339bba45d1e5e5878))
3565   ROM_LOAD ("70fdmus.rom", 0x28000, 0x4000, CRC(5c32eb29) SHA1(aad42ba4289b33d8eed225d42cea930b7fc5c228))
3566   ROM_LOAD ("70fdbas.rom", 0x2c000, 0x4000, CRC(da7be246) SHA1(22b3191d865010264001b9d896186a9818478a6b))
3567   ROM_LOAD ("70fdkfn.rom", 0x30000, 0x20000, CRC(c9651b32) SHA1(84a645becec0a25d3ab7a909cde1b242699a8662))
3568ROM_END
3569
3570MSX_LAYOUT_INIT (phc70fd)
3571   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3572   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3573   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3574   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3575   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3576   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3577/*  MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000) */ /* FDC Emulation of TC8566AF must be emulated */
3578   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x4000, 0x28000)
3579   MSX_LAYOUT_SLOT (3, 3, 2, 1, ROM, 0x4000, 0x2c000)
3580   MSX_LAYOUT_KANJI (0x30000)
3581   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3582MSX_LAYOUT_END
3583
3584/* MSX2+ - Sanyo Wavy PHC-70FD2 */
3585ROM_START (phc70fd2)
3586   ROM_REGION (0x70000, "maincpu",0)
3587   ROM_LOAD ("70f2bios.rom", 0x0000, 0x8000, CRC(19771608) SHA1(e90f80a61d94c617850c415e12ad70ac41e66bb7))
3588   ROM_LOAD ("70f2ext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3589   ROM_LOAD ("70f2disk.rom", 0xc000, 0x4000, CRC(db7f1125) SHA1(9efa744be8355675e7bfdd3976bbbfaf85d62e1d))
3590   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2p parent set */
3591   ROM_FILL (0x10000, 0x10000, 0)
3592   ROM_LOAD ("70f2kdr.rom", 0x20000, 0x8000, CRC(a068cba9) SHA1(1ef3956f7f918873fb9b031339bba45d1e5e5878))
3593   ROM_LOAD ("70f2mus.rom", 0x28000, 0x4000, CRC(5c32eb29) SHA1(aad42ba4289b33d8eed225d42cea930b7fc5c228))
3594   ROM_LOAD ("70f2bas.rom", 0x2c000, 0x4000, CRC(da7be246) SHA1(22b3191d865010264001b9d896186a9818478a6b))
3595   ROM_LOAD ("70f2kfn.rom", 0x30000, 0x40000, CRC(9a850db9) SHA1(bcdb4dae303dfe5234f372d70a5e0271d3202c36))
3596ROM_END
3597
3598MSX_LAYOUT_INIT (phc70fd2)
3599   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3600   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3601   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3602   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3603   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3604   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3605/*  MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000) */ /* FDC Emulation of TC8566AF must be emulated */
3606   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x4000, 0x28000)
3607   MSX_LAYOUT_SLOT (3, 3, 2, 1, ROM, 0x4000, 0x2c000)
3608   MSX_LAYOUT_KANJI (0x30000)
3609   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3610MSX_LAYOUT_END
3611
3612/* MSX2+ - Sony HB-F1XDJ */
3613
3614ROM_START (hbf1xdj)
3615   ROM_REGION (0x170000, "maincpu",0)
3616   ROM_LOAD ("f1xjbios.rom", 0x0000, 0x8000, CRC(00870134) SHA1(e2fbd56e42da637609d23ae9df9efd1b4241b18a))
3617   ROM_LOAD ("f1xjext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3618   ROM_LOAD ("f1xjdisk.rom", 0xc000, 0x4000, CRC(a21f5266) SHA1(c1bb307a570ab833e3bfcc4a58a4f4e12dc1df0f))
3619   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2p parent set */
3620   ROM_FILL (0x10000, 0x10000, 0)
3621   ROM_LOAD ("f1xjkdr.rom", 0x20000, 0x8000, CRC(a068cba9) SHA1(1ef3956f7f918873fb9b031339bba45d1e5e5878))
3622   ROM_LOAD ("f1xjmus.rom", 0x28000, 0x4000, CRC(5c32eb29) SHA1(aad42ba4289b33d8eed225d42cea930b7fc5c228))
3623   ROM_FILL (0x2c000, 0x4000, 0)
3624   ROM_LOAD ("f1xjkfn.rom", 0x30000, 0x40000, CRC(7016dfd0) SHA1(218d91eb6df2823c924d3774a9f455492a10aecb))
3625   ROM_LOAD ("f1xjfirm.rom", 0x70000, 0x100000, CRC(77be583f) SHA1(ade0c5ba5574f8114d7079050317099b4519e88f))
3626ROM_END
3627
3628MSX_LAYOUT_INIT (hbf1xdj)
3629   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3630/*  MSX_LAYOUT_SLOT (0, 3, 1, 4, SONY08, 0x100000, 0x70000) */ /* Sony 08KB MSX-JE Mapper must be emulated */
3631   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3632   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3633   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3634   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3635   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3636   MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000)
3637   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x4000, 0x28000)
3638   MSX_LAYOUT_KANJI (0x30000)
3639   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3640MSX_LAYOUT_END
3641
3642/* MSX2+ - Sony HB-F1XV */
3643
3644ROM_START (hbf1xv)
3645   ROM_REGION (0x170000, "maincpu",0)
3646   ROM_LOAD ("f1xvbios.rom", 0x0000, 0x8000, CRC(2c7ed27b) SHA1(174c9254f09d99361ff7607630248ff9d7d8d4d6))
3647   ROM_LOAD ("f1xvext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3648   ROM_LOAD ("f1xvdisk.rom", 0xc000, 0x4000, CRC(04e4e533) SHA1(5a4e7dbbfb759109c7d2a3b38bda9c60bf6ffef5))
3649   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2p parent set */
3650   ROM_FILL (0x10000, 0x10000, 0)
3651   ROM_LOAD ("f1xvkdr.rom", 0x20000, 0x8000, CRC(b4fc574d) SHA1(dcc3a67732aa01c4f2ee8d1ad886444a4dbafe06))
3652   ROM_LOAD ("f1xvmus.rom", 0x28000, 0x4000, CRC(5c32eb29) SHA1(aad42ba4289b33d8eed225d42cea930b7fc5c228))
3653   ROM_FILL (0x2c000, 0x4000, 0)
3654   ROM_LOAD ("f1xvkfn.rom", 0x30000, 0x40000, CRC(7016dfd0) SHA1(218d91eb6df2823c924d3774a9f455492a10aecb))
3655   ROM_LOAD ("f1xvfirm.rom", 0x70000, 0x100000, CRC(77be583f) SHA1(ade0c5ba5574f8114d7079050317099b4519e88f))
3656ROM_END
3657
3658MSX_LAYOUT_INIT (hbf1xv)
3659   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3660/*  MSX_LAYOUT_SLOT (0, 3, 1, 4, SONY08, 0x100000, 0x70000) */ /* Sony 08KB MSX-JE Mapper must be emulated */
3661   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3662   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3663   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3664   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3665   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3666   MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000)
3667   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x4000, 0x28000)
3668   MSX_LAYOUT_KANJI (0x30000)
3669   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3670MSX_LAYOUT_END
3671
3672MSX_DRIVER_LIST
3673  /* MSX 1 */
3674   MSX_DRIVER (msx)
3675  MSX_DRIVER (ax170)
3676   MSX_DRIVER (canonv10)
3677   MSX_DRIVER (canonv20)
3678   MSX_DRIVER (dpc100)
3679   MSX_DRIVER (dpc180)
3680   MSX_DRIVER (dpc200)
3681   MSX_DRIVER (gsfc200)
3682   MSX_DRIVER (expert10)
3683   MSX_DRIVER (expert11)
3684   MSX_DRIVER (expert13)
3685   MSX_DRIVER (expert20)
3686   MSX_DRIVER (expertdp)
3687   MSX_DRIVER (expertpl)
3688   MSX_DRIVER (jvchc7gb)
3689   MSX_DRIVER (mlf80)
3690   MSX_DRIVER (mlfx1)
3691   MSX_DRIVER (cf1200)
3692   MSX_DRIVER (cf2000)
3693   MSX_DRIVER (cf2700)
3694   MSX_DRIVER (cf3000)
3695   MSX_DRIVER (cf3300)
3696   MSX_DRIVER (fs1300)
3697   MSX_DRIVER (fs4000)
3698   MSX_DRIVER (nms801)
3699   MSX_DRIVER (vg802000)
3700   MSX_DRIVER (vg802020)
3701   MSX_DRIVER (piopx7)
3702   MSX_DRIVER (mpc100)
3703   MSX_DRIVER (hotbit11)
3704   MSX_DRIVER (hotbit12)
3705   MSX_DRIVER (hotbi13b)
3706   MSX_DRIVER (hotbi13p)
3707   MSX_DRIVER (hotbit20)
3708   MSX_DRIVER (hb10p)
3709   MSX_DRIVER (hb20p)
3710   MSX_DRIVER (hb201)
3711   MSX_DRIVER (hb201p)
3712   MSX_DRIVER (hb501p)
3713   MSX_DRIVER (hb55d)
3714   MSX_DRIVER (hb55p)
3715   MSX_DRIVER (hb75d)
3716   MSX_DRIVER (hb75p)
3717   MSX_DRIVER (svi728)
3718   MSX_DRIVER (svi738)
3719   MSX_DRIVER (svi738sw)
3720   MSX_DRIVER (tadpc200)
3721   MSX_DRIVER (tadpc20a)
3722   MSX_DRIVER (hx10)
3723   MSX_DRIVER (hx10s)
3724   MSX_DRIVER (hx20)
3725   MSX_DRIVER (cx5m)
3726   MSX_DRIVER (cx5m128)
3727   MSX_DRIVER (cx5m2)
3728   MSX_DRIVER (yis303)
3729   MSX_DRIVER (yis503)
3730   MSX_DRIVER (yis503ii)
3731   MSX_DRIVER (y503iir)
3732   MSX_DRIVER (y503iir2)
3733   MSX_DRIVER (yis503m)
3734   MSX_DRIVER (yc64)
3735   MSX_DRIVER (bruc100)
3736
3737
3738
3739   MSX_DRIVER (msx2)
3740   MSX_DRIVER (ax350)
3741   MSX_DRIVER (ax370)
3742   MSX_DRIVER (nms8220)
3743   MSX_DRIVER (nms8220a)
3744   MSX_DRIVER (vg8230)
3745   MSX_DRIVER (vg8235)
3746   MSX_DRIVER (vg8235f)
3747   MSX_DRIVER (vg8240)
3748   MSX_DRIVER (nms8245)
3749   MSX_DRIVER (nms8245f)
3750   MSX_DRIVER (nms8250)
3751   MSX_DRIVER (nms8255)
3752   MSX_DRIVER (nms8280)
3753   MSX_DRIVER (nms8280g)
3754   MSX_DRIVER (hbf9p)
3755   MSX_DRIVER (hbf9s)
3756   MSX_DRIVER (hbf500p)
3757   MSX_DRIVER (hbf700d)
3758   MSX_DRIVER (hbf700f)
3759   MSX_DRIVER (hbf700p)
3760   MSX_DRIVER (hbf700s)
3761   MSX_DRIVER (hbg900ap)
3762   MSX_DRIVER (hbg900p)
3763   MSX_DRIVER (fs5500)
3764   MSX_DRIVER (fs4500)
3765   MSX_DRIVER (fs4700)
3766   MSX_DRIVER (fs5000)
3767   MSX_DRIVER (fs4600)
3768   MSX_DRIVER (fsa1)
3769   MSX_DRIVER (fsa1a)
3770   MSX_DRIVER (fsa1mk2)
3771   MSX_DRIVER (fsa1f)
3772   MSX_DRIVER (fsa1fm)
3773   MSX_DRIVER (hbf500)
3774   MSX_DRIVER (hbf900)
3775   MSX_DRIVER (hbf900a)
3776   MSX_DRIVER (hbf1)
3777   MSX_DRIVER (hbf12)
3778   MSX_DRIVER (hbf1xd)
3779   MSX_DRIVER (hbf1xdm2)
3780   MSX_DRIVER (phc23)
3781   MSX_DRIVER (cpc300)
3782   MSX_DRIVER (cpc300e)
3783   MSX_DRIVER (cpc400)
3784   MSX_DRIVER (cpc400s)
3785   MSX_DRIVER (msx2p)
3786   MSX_DRIVER (fsa1fx)
3787   MSX_DRIVER (fsa1wx)
3788   MSX_DRIVER (fsa1wxa)
3789   MSX_DRIVER (fsa1wsx)
3790   MSX_DRIVER (hbf1xdj)
3791   MSX_DRIVER (hbf1xv)
3792   MSX_DRIVER (phc70fd)
3793   MSX_DRIVER (phc70fd2)
3794   MSX_DRIVER (phc35j)
3795
3796   MSX_DRIVER (tpc310)
3797   MSX_DRIVER (hx23)
3798   MSX_DRIVER (hx23f)
3799   MSX_DRIVER (cx7m)
3800   MSX_DRIVER (cx7m128)
3801
3802MSX_DRIVER_END
3803
3804
3805/*    YEAR  NAME      PARENT    COMPAT  MACHINE  INPUT     INIT   COMPANY              FULLNAME */
3806COMP(1983, msx,        0,      0,   msx_pal,  msx,       msx,      "ASCII & Microsoft", "MSX" , 0)
3807
3808COMP(1983, ax170,   msx,   0,   msx_pal,  msx,      msx,     "Al Alamiah", "AX-170" , 0)
3809COMP(1983, canonv10,  msx,   0,   msx_pal,  msx,      msx,     "Canon", "V-10" , 0)
3810COMP(1983, canonv20,  msx,   0,   msx_pal,  msx,      msx,     "Canon", "V-20" , 0)
3811COMP(1984, dpc100,   msx,   0,   msx,     msxkr,    msx,     "Daewoo", "IQ-1000 DPC-100 (Korea)" , 0)
3812COMP(1984, dpc180,   msx,   0,   msx,     msxkr,    msx,     "Daewoo", "IQ-1000 DPC-180 (Korea)" , 0)
3813COMP(1984, dpc200,   msx,   0,   msx,     msxkr,    msx,     "Daewoo", "IQ-1000 DPC-200 (Korea)" , 0)
3814COMP(1983, gsfc200,   msx,   0,   msx_pal,  msx,      msx,     "Goldstar", "FC-200" , 0)
3815COMP(1983, expert10, msx,   0,   msx,     expert10, msx,     "Gradiente", "Expert 1.0 (Brazil)" , 0)
3816COMP(1984, expert11, msx,   0,   msx,     expert11, msx,     "Gradiente", "Expert 1.1 (Brazil)" , 0)
3817COMP(1984, expert13, msx,   0,   msx,     expert11, msx,     "Gradiente", "Expert 1.3 (Brazil)" , 0)
3818COMP(1985, expertdp, msx,   0,   msx,     expert11, msx,     "Gradiente", "Expert DDPlus (Brazil)", 0 )
3819COMP(1984, expertpl, msx,   0,   msx,     expert11, msx,     "Gradiente", "Expert Plus (Brazil)" , 0)
3820COMP(1983, jvchc7gb,  msx,   0,   msx_pal,  msx,      msx,     "JVC", "HC-7GB" , 0)
3821COMP(1983, mlf80,     msx,   0,   msx_pal,  msx,      msx,     "Mitsubishi", "ML-F80" , 0)
3822COMP(1983, mlfx1,     msx,   0,   msx_pal,  msx,      msx,     "Mitsubishi", "ML-FX1" , 0)
3823COMP(1984, cf1200,   msx,   0,  msx,      msxjp,    msx,     "National / Matsushita", "CF-1200 (Japan)" , 0)
3824COMP(1983, cf2000,   msx,   0,  msx,      msxjp,    msx,     "National / Matsushita", "CF-2000 (Japan)" , 0)
3825COMP(1984, cf2700,   msx,   0,  msx,      msxjp,    msx,     "National / Matsushita", "CF-2700 (Japan)" , 0)
3826COMP(1984, cf3000,   msx,   0,  msx,      msxjp,    msx,     "National / Matsushita", "CF-3000 (Japan)" , 0)
3827COMP(1985, cf3300,   msx,   0,  msx,      msxjp,    msx,     "National / Matsushita", "CF-3300 (Japan)", 0 )
3828COMP(1985, fs1300,   msx,   0,  msx,      msxjp,    msx,     "National / Matsushita", "FS-1300 (Japan)" , 0)
3829COMP(1985, fs4000,   msx,   0,  msx,      msxjp,    msx,     "National / Matsushita", "FS-4000 (Japan)" , 0)
3830COMP(1983, nms801,     msx,   0,   msx_pal,  msx,      msx,     "Philips", "NMS-801" , 0)
3831COMP(1984, vg8000,  msx,   0,   msx,     msx,      msx,     "Philips",    "VG-8000" , GAME_NOT_WORKING)
3832COMP(1984, vg8010,  msx,   0,   msx,     msx,      msx,     "Philips",    "VG-8010" , GAME_NOT_WORKING)
3833COMP(1984, vg8010f,  msx,   0,   msx,     msx,      msx,     "Philips",    "VG-8010F" , GAME_NOT_WORKING)
3834COMP(1985, vg802000,  msx,   0,   msx,     msx,      msx,     "Philips",    "VG-8020-00" , 0)
3835COMP(1985, vg802020, msx,   0,   msx,     msx,      msx,     "Philips",    "VG-8020-20" , 0)
3836COMP(1985, piopx7,     msx,   0,   msx_pal,  msx,      msx,     "Pioneer",    "PX-07" , 0)
3837COMP(1985, mpc100,     msx,   0,   msx_pal,  msx,      msx,     "Sanyo",    "MPC-100" , 0)
3838COMP(1985, hotbit11, msx,   0,   msx,     hotbit,   msx,     "Sharp / Epcom",    "HB-8000 Hotbit 1.1" , 0)
3839COMP(1985, hotbit12, msx,   0,   msx,     hotbit,   msx,     "Sharp / Epcom",    "HB-8000 Hotbit 1.2" , 0)
3840COMP(1985, hotbi13b, msx,   0,   msx,     hotbit,   msx,     "Sharp / Epcom",    "HB-8000 Hotbit 1.3b" , 0)
3841COMP(1985, hotbi13p, msx,   0,   msx,     hotbit,   msx,     "Sharp / Epcom",    "HB-8000 Hotbit 1.3p" , 0)
3842COMP(1985, hb10p,    msx,   0,  msx_pal,  msx,     msx,     "Sony", "HB-10P" , 0)
3843COMP(1985, hb20p,    msx,   0,  msx_pal,  msx,     msx,     "Sony", "HB-20P (Spanish)" , 0)
3844COMP(1985, hb201,    msx,   0,  msx,      msxjp,    msx,     "Sony", "HB-201 (Japan)" , 0)
3845COMP(1985, hb201p,   msx,   0,   msx_pal,  msx,      msx,     "Sony", "HB-201P" , 0)
3846COMP(1984, hb501p,   msx,   0,   msx_pal,  msx,      msx,     "Sony", "HB-501P" , 0)
3847COMP(1983, hb55d,    msx,   0,   msx_pal,  msx,      msx,     "Sony", "HB-55D (Germany)" , 0)
3848COMP(1983, hb55p,    msx,   0,   msx_pal,  msx,      msx,     "Sony", "HB-55P" , 0)
3849COMP(1983, hb75d,    msx,   0,   msx_pal,  msx,      msx,     "Sony", "HB-75D (Germany)" , 0)
3850COMP(1983, hb75p,    msx,   0,   msx_pal,  msx,      msx,     "Sony", "HB-75P" , 0)
3851COMP(1985, svi728,   msx,   0,   msx_pal,  msx,      msx,     "Spectravideo", "SVI-728", 0 )
3852COMP(1985, svi738,   msx,   0,   msx_pal,  msx,      msx,     "Spectravideo", "SVI-738", 0 )
3853COMP(1985, svi738sw, msx,   0,   msx_pal,  msx,      msx,     "Spectravideo", "SVI-738 (Swedish)", 0 )
3854COMP(1983, tadpc200,  msx,   0,   msx_pal,  msx,      msx,     "Talent", "DPC-200" , 0)
3855COMP(1983, tadpc20a,  msx,   0,   msx_pal,  msx,      msx,     "Talent", "DPC-200A" , 0)
3856COMP(1984, hx10,     msx,   0,   msx_pal,  msx,      msx,     "Toshiba",    "HX-10" , 0)
3857COMP(1984, hx10s,     msx,   0,   msx_pal,  msx,      msx,     "Toshiba",    "HX-10S" , 0)
3858COMP(1984, hx20,     msx,   0,   msx_pal,  msx,      msx,     "Toshiba",    "HX-20" , 0)
3859COMP(1984, cx5m,     msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "CX5M" , GAME_NOT_WORKING)
3860COMP(1984, cx5m128,  msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "CX5M-128" , GAME_NOT_WORKING)
3861COMP(1984, cx5m2,   msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "CX5MII" , GAME_NOT_WORKING)
3862COMP(1984, yis303,  msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "YIS303" , 0)
3863COMP(1984, yis503,   msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "YIS503" , 0)
3864COMP(1984, yis503ii,msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "YIS503II" , 0)
3865COMP(1986, y503iir, msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "YIS503IIR (Russian)" , 0)
3866COMP(1986, y503iir2, msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "YIS503IIR (Estonian)" , 0)
3867COMP(1984, yis503m, msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "YIS503M" , GAME_NOT_WORKING)
3868COMP(1984, yc64,   msx,   0,   msx_pal,  msx,      msx,     "Yashica", "YC-64" , 0)
3869COMP(1984, bruc100, msx,   0,   msx_pal,  msx,      msx,     "Frael", "Bruc 100-1" , 0)
3870
3871COMP(1985, msx2,     0,      msx,msx2_pal, msx2,       msx,     "ASCII & Microsoft", "MSX2", 0)
3872COMP(1986, ax350,    msx2,   0,   msx2_pal, msx2,       msx,     "Al Alamiah", "AX-350", 0)
3873COMP(1986, ax370,    msx2,   0,   msx2_pal, msx2,       msx,     "Al Alamiah", "AX-370", 0)
3874COMP(1986, expert20, msx2,   0,   msx2_pal, msx2,    msx,     "Gradiente", "Expert 2.0 (Brazil)" , GAME_NOT_WORKING)
3875COMP(1986, nms8220,  msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "NMS-8220 (12-jun-1986)", 0)
3876COMP(1986, nms8220a, msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "NMS-8220 (13-aug-1986)", 0)
3877COMP(1986, vg8230,   msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "VG-8230", 0)
3878COMP(1986, vg8235,   msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "VG-8235", 0)
3879COMP(1986, vg8235f,  msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "VG-8235F", 0)
3880COMP(1986, vg8240,   msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "VG-8240", 0)
3881COMP(1986, nms8245,  msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "NMS-8245", 0)
3882COMP(1986, nms8245f, msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "NMS-8245F", 0)
3883COMP(1986, nms8250,  msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "NMS-8250", 0)
3884COMP(1986, nms8255,  msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "NMS-8255", 0)
3885COMP(1986, nms8280,  msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "NMS-8280", 0)
3886COMP(1986, nms8280g, msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "NMS-8280G", 0)
3887COMP(1985, hbf9p,    msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-F9P" , 0)
3888COMP(1985, hbf9s,    msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-F9S" , 0)
3889COMP(1985, hbf500p,  msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-F500P", 0)
3890COMP(1985, hbf700d,  msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-F700D (Germany)" , 0)
3891COMP(1985, hbf700f,  msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-F700F" , 0)
3892COMP(1985, hbf700p,  msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-F700P" , 0)
3893COMP(1985, hbf700s,  msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-F700S (Spain)", 0)
3894COMP(1986, hbg900ap, msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-G900AP", 0 )
3895COMP(1986, hbg900p,  msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-G900P", 0 )
3896COMP(1986, hotbit20, msx2,   0,   msx2_pal, msx2,    msx,     "Sharp / Epcom",    "HB-8000 Hotbit 2.0" , GAME_NOT_WORKING)
3897COMP(1986, tpc310,   msx2,   0,  msx2_pal, msx2,     msx,     "Talent", "TPC-310", 0)
3898COMP(1986, hx23,     msx2,   0,  msx2_pal, msx2,     msx,     "Toshiba", "HX-23", 0)
3899COMP(1986, hx23f,    msx2,   0,  msx2_pal, msx2,     msx,     "Toshiba", "HX-23F", 0)
3900COMP(1986, cx7m,     msx2,   0,   msx2_pal,msx2,      msx,     "Yamaha",    "CX7M" , GAME_NOT_WORKING)
3901COMP(1986, cx7m128,  msx2,   0,   msx2_pal,msx2,      msx,     "Yamaha",    "CX7M-128" , GAME_NOT_WORKING)
3902COMP(1985, fs5500,   msx2,   0,  msx2,     msx2jp,   msx,     "National / Matsushita", "FS-5500F1/F2 (Japan)", 0 )
3903COMP(1986, fs4500,   msx2,   0,  msx2,     msx2jp,   msx,     "National / Matsushita", "FS-4500 (Japan)", 0 )
3904COMP(1986, fs4700,   msx2,   0,  msx2,     msx2jp,   msx,     "National / Matsushita", "FS-4700 (Japan)", 0 )
3905COMP(1986, fs5000,   msx2,   0,  msx2,     msx2jp,   msx,     "National / Matsushita", "FS-5000F2 (Japan)", 0 )
3906COMP(1986, fs4600,   msx2,   0,  msx2,     msx2jp,   msx,     "National / Matsushita", "FS-4600 (Japan)", 0 )
3907COMP(1986, fsa1,     msx2,   0,  msx2,     msx2jp,   msx,     "Panasonic / Matsushita", "FS-A1 / 1st released version (Japan)", 0)
3908COMP(1986, fsa1a,    msx2,   0,  msx2,     msx2jp,   msx,     "Panasonic / Matsushita", "FS-A1 / 2nd released version (Japan)", 0)
3909COMP(1987, fsa1mk2,  msx2,   0,  msx2,     msx2jp,   msx,     "Panasonic / Matsushita", "FS-A1MK2 (Japan)", 0)
3910COMP(1987, fsa1f,    msx2,   0,  msx2,     msx2jp,   msx,     "Panasonic / Matsushita", "FS-A1F (Japan)", 0 )
3911COMP(1987, fsa1fm,   msx2,   0,  msx2,     msx2jp,   msx,     "Panasonic / Matsushita", "FS-A1FM (Japan)", 0 )
3912COMP(1986, hbf500,   msx2,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F500 (Japan)", 0)
3913COMP(1986, hbf900,   msx2,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F900 / 1st released version (Japan)", 0)
3914COMP(1986, hbf900a,  msx2,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F900 / 2nd released version (Japan)", 0)
3915COMP(1986, hbf1,     msx2,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F1 (Japan)", GAME_NOT_WORKING )
3916COMP(1987, hbf12,    msx2,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F1II (Japan)", GAME_NOT_WORKING )
3917COMP(1987, hbf1xd,   msx2,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F1XD (Japan)", 0)
3918COMP(1988, hbf1xdm2, msx2,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F1XDMK2 (Japan)", 0)
3919COMP(1988, phc23,    msx2,   0,  msx2,     msx2jp,   msx,     "Sanyo", "WAVY PHC-23 (Japan)", 0)
3920
3921COMP(1986, cpc300,   msx2,   0,   msx2,     msx2kr,   msx,     "Daewoo", "IQ-2000 CPC-300 (Korea)", 0)
3922COMP(1986, cpc300e,  msx2,   0,   msx2,     msx2kr,   msx,     "Daewoo", "IQ-2000 CPC-300E (Korea)", 0)
3923COMP(1986, cpc400,   msx2,   0,   msx2,     msx2kr,   msx,     "Daewoo", "X-II CPC-400 (Korea)", 0 )
3924COMP(1986, cpc400s,  msx2,   0,   msx2,     msx2kr,   msx,     "Daewoo", "X-II CPC-400S (Korea)", 0 )
3925COMP(1988, msx2p,    0,      msx,msx2,     msx2jp,   msx,     "ASCII & Microsoft", "MSX2+", 0)
3926COMP(1988, fsa1fx,   msx2p,   0,  msx2,     msx2jp,   msx,     "Panasonic / Matsushita", "FS-A1FX (Japan)", 0 )
3927COMP(1988, fsa1wx,   msx2p,   0,  msx2,     msx2jp,   msx,     "Panasonic / Matsushita", "FS-A1WX / 1st released version (Japan)", 0 )
3928COMP(1988, fsa1wxa,  msx2p,   0,  msx2,     msx2jp,   msx,    "Panasonic / Matsushita", "FS-A1WX / 2nd released version (Japan)", 0 )
3929COMP(1989, fsa1wsx,  msx2p,   0,  msx2,     msx2jp,   msx,     "Panasonic / Matsushita", "FS-A1WSX (Japan)", 0 )
3930COMP(1988, hbf1xdj,  msx2p,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F1XDJ (Japan)", 0 )
3931COMP(1989, hbf1xv,   msx2p,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F1XV (Japan)", 0 )
3932COMP(1988, phc70fd,  msx2p,   0,  msx2,     msx2jp,   msx,     "Sanyo", "WAVY PHC-70FD (Japan)", 0 )
3933COMP(1988, phc70fd2, msx2p,   0,  msx2,     msx2jp,   msx,     "Sanyo", "WAVY PHC-70FD2 (Japan)", 0 )
3934COMP(1989, phc35j,   msx2p,   0,  msx2,     msx2jp,   msx,     "Sanyo", "WAVY PHC-35J (Japan)", 0)
3935
src/mame/drivers/amiga.c
r0r11461
1/***************************************************************************
2Commodore Amiga - (c) 1985, Commodore Business Machines Co.
3
4Preliminary driver by:
5
6Ernesto Corvi
7
8Note 1: The 'fast-mem' memory detector in Kickstart 1.2 expects to
9see the custom chips at the end of any present fast memory (mapped
10from $C00000 onwards). I assume this is a bug, given that the routine
11was entirely rewritten for Kickstart 1.3. So the strategy is, for
12any machine that can run Kickstart 1.2 (a500,a1000 and a2000), we
13map a mirror of the custom chips right after any fast-mem we mapped.
14If we didn't map any, then we still put a mirror, but where fast-mem
15would commence ($C00000).
16
17***************************************************************************/
18
19/* Core includes */
20#include "emu.h"
21#include "includes/amiga.h"
22
23/* Components */
24#include "cpu/m68000/m68000.h"
25#include "cpu/m6502/m6502.h"
26#include "machine/6525tpi.h"
27#include "machine/6526cia.h"
28#include "machine/amigafdc.h"
29#include "machine/amigakbd.h"
30#include "machine/amigacd.h"
31#include "machine/amigacrt.h"
32#include "machine/msm6242.h"
33#include "machine/ctronics.h"
34#include "machine/nvram.h"
35#include "sound/cdda.h"
36
37/* Devices */
38#include "imagedev/chd_cd.h"
39#include "imagedev/cartslot.h"
40
41
42static READ8_DEVICE_HANDLER( amiga_cia_0_portA_r );
43static READ8_DEVICE_HANDLER( amiga_cia_0_cdtv_portA_r );
44static WRITE8_DEVICE_HANDLER( amiga_cia_0_portA_w );
45
46/***************************************************************************
47  Battery Backed-Up Clock (MSM6264)
48***************************************************************************/
49
50static READ16_HANDLER( amiga_clock_r )
51{
52   device_t *rtc = space->machine().device("rtc");
53   return msm6242_r(rtc, offset / 2);
54}
55
56
57static WRITE16_HANDLER( amiga_clock_w )
58{
59   device_t *rtc = space->machine().device("rtc");
60   msm6242_w(rtc, offset / 2, data);
61}
62
63
64/***************************************************************************
65    CENTRONICS PORT
66***************************************************************************/
67
68static READ8_DEVICE_HANDLER( amiga_cia_1_porta_r )
69{
70   UINT8 result = 0;
71
72   /* centronics status is stored in PA0 to PA2 */
73   result |= centronics_busy_r(device) << 0;
74   result |= !centronics_pe_r(device) << 1;
75   result |= centronics_vcc_r(device) << 2;
76
77   /* PA3 to PA7 store the serial line status (not emulated) */
78
79   return result;
80}
81
82static const centronics_interface amiga_centronics_config =
83{
84   FALSE,
85   DEVCB_DEVICE_LINE("cia_0", mos6526_flag_w),
86   DEVCB_NULL,
87   DEVCB_NULL
88};
89
90
91/***************************************************************************
92  Address maps
93***************************************************************************/
94
95static ADDRESS_MAP_START(amiga_mem, AS_PROGRAM, 16)
96   ADDRESS_MAP_UNMAP_HIGH
97   AM_RANGE(0x000000, 0x07ffff) AM_MIRROR(0x80000) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(amiga_state, m_chip_ram, m_chip_ram_size)
98   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia_r, amiga_cia_w)
99   AM_RANGE(0xc00000, 0xc7ffff) AM_RAM /* slow-mem */
100   AM_RANGE(0xc80000, 0xcfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w)   /* see Note 1 above */
101   AM_RANGE(0xdf0000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE_MEMBER(amiga_state, m_custom_regs)   /* Custom Chips */
102   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE(amiga_autoconfig_r, amiga_autoconfig_w)
103   AM_RANGE(0xf80000, 0xffffff) AM_ROM AM_REGION("user1", 0)   /* System ROM - mirror */
104ADDRESS_MAP_END
105
106static ADDRESS_MAP_START(keyboard_mem, AS_PROGRAM, 8)
107   AM_RANGE(0x0000, 0x003f) AM_RAM /* internal user ram */
108   AM_RANGE(0x0040, 0x007f) AM_NOP /* unassigned */
109   AM_RANGE(0x0080, 0x0080) AM_NOP /* port a */
110   AM_RANGE(0x0081, 0x0081) AM_NOP /* port b */
111   AM_RANGE(0x0082, 0x0082) AM_NOP /* port c */
112   AM_RANGE(0x0083, 0x0083) AM_NOP /* port d */
113   AM_RANGE(0x0084, 0x0085) AM_NOP /* latch */
114   AM_RANGE(0x0086, 0x0087) AM_NOP /* count */
115   AM_RANGE(0x0088, 0x0088) AM_NOP /* upper latch & transfer latch to counter */
116   AM_RANGE(0x0089, 0x0089) AM_NOP /* clear pa0 pos edge detected */
117   AM_RANGE(0x008a, 0x008a) AM_NOP /* clear pa1 neg edge detected */
118   AM_RANGE(0x008b, 0x008e) AM_NOP /* unassigned */
119   AM_RANGE(0x008f, 0x008f) AM_NOP /* control register */
120   AM_RANGE(0x0090, 0x07ff) AM_NOP /* unassigned */
121   AM_RANGE(0x0800, 0x0fff) AM_ROM AM_REGION("keyboard", 0) /* internal mask rom */
122ADDRESS_MAP_END
123
124
125/*
126 * CDTV memory map (source: http://www.l8r.net/technical/cdtv-technical.html)
127 *
128 * 000000-0FFFFF Chip memory
129 * 100000-1FFFFF Space for extra chip memory (Megachip)
130 * 200000-9FFFFF Space for AutoConfig memory
131 * A00000-BFFFFF CIA chips
132 * C00000-C7FFFF Space for slow-fast memory
133 * C80000-DBFFFF Space
134 * DC0000-DC7FFF Power backed-up real time clock
135 * DC8000-DC87FF Non-volatile RAM
136 * DC8800-DCFFFF Space in non-volatile RAM decoded area
137 * DD0000-DEFFFF Space
138 * DF0000-DFFFFF Custom chips
139 * E00000-E7FFFF Memory card address space for front panel memory card
140 * E80000-E8FFFF AutoConfig configuration space
141 * E90000-E9FFFF First AutoConfig device, used by DMAC
142 * EA0000-EFFFFF Space for other AutoConfig devices
143 * F00000-F3FFFF CDTV ROM
144 * F40000-F7FFFF Space in CDTV ROM decoded area
145 * F80000-FBFFFF Space in Kickstart ROM decoded area (used by Kickstart 2)
146 * FC0000-FFFFFF Kickstart ROM
147 *
148 */
149
150static ADDRESS_MAP_START(cdtv_mem, AS_PROGRAM, 16)
151   AM_RANGE(0x000000, 0x0fffff) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(amiga_state, m_chip_ram, m_chip_ram_size)
152   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia_r, amiga_cia_w)
153   AM_RANGE(0xdc0000, 0xdc003f) AM_READWRITE(amiga_clock_r, amiga_clock_w)
154   AM_RANGE(0xdc8000, 0xdc87ff) AM_RAM AM_SHARE("nvram")
155   AM_RANGE(0xdf0000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE_MEMBER(amiga_state, m_custom_regs)   /* Custom Chips */
156   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE(amiga_autoconfig_r, amiga_autoconfig_w)
157   AM_RANGE(0xf00000, 0xffffff) AM_ROM AM_REGION("user1", 0)   /* CDTV & System ROM */
158ADDRESS_MAP_END
159
160static ADDRESS_MAP_START(cdtv_rcmcu_mem, AS_PROGRAM, 8)
161   AM_RANGE(0x0000, 0x003f) AM_RAM /* internal user ram */
162   AM_RANGE(0x0040, 0x007f) AM_NOP /* unassigned */
163   AM_RANGE(0x0080, 0x0080) AM_NOP /* port a */
164   AM_RANGE(0x0081, 0x0081) AM_NOP /* port b */
165   AM_RANGE(0x0082, 0x0082) AM_NOP /* port c */
166   AM_RANGE(0x0083, 0x0083) AM_NOP /* port d */
167   AM_RANGE(0x0084, 0x0085) AM_NOP /* latch */
168   AM_RANGE(0x0086, 0x0087) AM_NOP /* count */
169   AM_RANGE(0x0088, 0x0088) AM_NOP /* upper latch & transfer latch to counter */
170   AM_RANGE(0x0089, 0x0089) AM_NOP /* clear pa0 pos edge detected */
171   AM_RANGE(0x008a, 0x008a) AM_NOP /* clear pa1 neg edge detected */
172   AM_RANGE(0x008b, 0x008e) AM_NOP /* unassigned */
173   AM_RANGE(0x008f, 0x008f) AM_NOP /* control register */
174   AM_RANGE(0x0090, 0x07ff) AM_NOP /* unassigned */
175   AM_RANGE(0x0800, 0x0fff) AM_ROM AM_REGION("rcmcu", 0) /* internal mask rom */
176ADDRESS_MAP_END
177
178static ADDRESS_MAP_START(a1000_mem, AS_PROGRAM, 16)
179   AM_RANGE(0x000000, 0x03ffff) AM_MIRROR(0xc0000) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(amiga_state, m_chip_ram, m_chip_ram_size)
180   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia_r, amiga_cia_w)
181   AM_RANGE(0xc00000, 0xc3ffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) /* See Note 1 above */
182   AM_RANGE(0xdf0000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE_MEMBER(amiga_state, m_custom_regs)   /* Custom Chips */
183   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE(amiga_autoconfig_r, amiga_autoconfig_w)
184   AM_RANGE(0xf80000, 0xfbffff) AM_ROM AM_REGION("user1", 0)   /* Bootstrap ROM */
185   AM_RANGE(0xfc0000, 0xffffff) AM_RAMBANK("bank2")   /* Writable Control Store RAM */
186ADDRESS_MAP_END
187
188
189/***************************************************************************
190  Inputs
191***************************************************************************/
192
193static INPUT_PORTS_START( amiga_common )
194   PORT_START("input")
195   PORT_CONFNAME( 0x20, 0x00, "Input Port 0 Device")
196   PORT_CONFSETTING( 0x00, "Mouse" )
197   PORT_CONFSETTING( 0x20, DEF_STR(Joystick) )
198   PORT_CONFNAME( 0x10, 0x10, "Input Port 1 Device")
199   PORT_CONFSETTING( 0x00, "Mouse" )
200   PORT_CONFSETTING( 0x10, DEF_STR(Joystick) )
201
202   PORT_START("CIA0PORTA")
203   PORT_BIT( 0x3f, IP_ACTIVE_LOW, IPT_SPECIAL )
204   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
205   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
206
207   PORT_START("JOY0DAT")
208   PORT_BIT( 0x0303, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(amiga_joystick_convert, "P1JOY")
209   PORT_BIT( 0xfcfc, IP_ACTIVE_HIGH, IPT_UNUSED )
210
211   PORT_START("JOY1DAT")
212   PORT_BIT( 0x0303, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(amiga_joystick_convert, "P2JOY")
213   PORT_BIT( 0xfcfc, IP_ACTIVE_HIGH, IPT_UNUSED )
214
215   PORT_START("POTGO")
216   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNUSED )
217   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
218   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_UNUSED )
219   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
220   PORT_BIT( 0xaaff, IP_ACTIVE_HIGH, IPT_UNUSED )
221
222   PORT_START("P1JOY")
223   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
224   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1)
225   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1)
226   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
227
228   PORT_START("P2JOY")
229   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(2)
230   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
231   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2)
232   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
233
234   PORT_START("P0MOUSEX")
235   PORT_BIT( 0xff, 0x00, IPT_MOUSE_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_PLAYER(1)
236
237   PORT_START("P0MOUSEY")
238   PORT_BIT( 0xff, 0x00, IPT_MOUSE_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_PLAYER(1)
239
240   PORT_START("P1MOUSEX")
241   PORT_BIT( 0xff, 0x00, IPT_MOUSE_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_PLAYER(2)
242
243   PORT_START("P1MOUSEY")
244   PORT_BIT( 0xff, 0x00, IPT_MOUSE_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_PLAYER(2)
245
246   PORT_INCLUDE( amiga_us_keyboard )
247
248INPUT_PORTS_END
249
250
251static INPUT_PORTS_START( amiga )
252   PORT_START("hardware")
253   PORT_CONFNAME( 0x08, 0x08, "Battery backed-up RTC")
254   PORT_CONFSETTING( 0x00, "Not Installed" )
255   PORT_CONFSETTING( 0x08, "Installed" )
256
257   PORT_INCLUDE( amiga_common )
258INPUT_PORTS_END
259
260
261/* TODO: Support for the CDTV remote control */
262static INPUT_PORTS_START( cdtv )
263   PORT_INCLUDE( amiga_common )
264INPUT_PORTS_END
265
266/***************************************************************************
267  Machine drivers
268***************************************************************************/
269
270static MACHINE_START( cdtv )
271{
272   MACHINE_START_CALL( amigacd );
273}
274
275
276static MACHINE_RESET( cdtv )
277{
278   MACHINE_RESET_CALL( amiga );
279
280   /* initialize the cdrom controller */
281   MACHINE_RESET_CALL( amigacd );
282}
283
284static const mos6526_interface cia_0_ntsc_intf =
285{
286   60,                                          /* tod_clock */
287   DEVCB_LINE(amiga_cia_0_irq),                     /* irq_func */
288   DEVCB_DEVICE_LINE("centronics", centronics_strobe_w),   /* pc_func */
289   DEVCB_NULL,
290   DEVCB_NULL,
291   DEVCB_HANDLER(amiga_cia_0_portA_r),
292   DEVCB_HANDLER(amiga_cia_0_portA_w),                  /* port A */
293   DEVCB_NULL,
294   DEVCB_DEVICE_HANDLER("centronics", centronics_data_w)   /* port B */
295};
296
297static const mos6526_interface cia_0_pal_intf =
298{
299   50,                                          /* tod_clock */
300   DEVCB_LINE(amiga_cia_0_irq),                     /* irq_func */
301   DEVCB_DEVICE_LINE("centronics", centronics_strobe_w),   /* pc_func */
302   DEVCB_NULL,
303   DEVCB_NULL,
304   DEVCB_HANDLER(amiga_cia_0_portA_r),
305   DEVCB_HANDLER(amiga_cia_0_portA_w),                  /* port A */
306   DEVCB_NULL,
307   DEVCB_DEVICE_HANDLER("centronics", centronics_data_w)   /* port B */
308};
309
310static const mos6526_interface cia_1_intf =
311{
312   0,                                          /* tod_clock */
313   DEVCB_LINE(amiga_cia_1_irq),                     /* irq_func */
314   DEVCB_NULL,                                    /* pc_func */
315   DEVCB_NULL,
316   DEVCB_NULL,
317   DEVCB_DEVICE_HANDLER("centronics", amiga_cia_1_porta_r),
318   DEVCB_NULL,                                    /* port A */
319   DEVCB_NULL,
320   DEVCB_DEVICE_HANDLER("fdc", amiga_fdc_control_w)      /* port B */
321};
322
323static const mos6526_interface cia_0_cdtv_intf =
324{
325   0,                                          /* tod_clock */
326   DEVCB_LINE(amiga_cia_0_irq),                     /* irq_func */
327   DEVCB_DEVICE_LINE("centronics", centronics_strobe_w),   /* pc_func */
328   DEVCB_NULL,
329   DEVCB_NULL,
330   DEVCB_HANDLER(amiga_cia_0_cdtv_portA_r),
331   DEVCB_HANDLER(amiga_cia_0_portA_w),                  /* port A */
332   DEVCB_NULL,
333   DEVCB_DEVICE_HANDLER("centronics", centronics_data_w)   /* port B */
334};
335
336static const mos6526_interface cia_1_cdtv_intf =
337{
338   0,                                          /* tod_clock */
339   DEVCB_LINE(amiga_cia_1_irq),                     /* irq_func */
340   DEVCB_NULL,   /* pc_func */
341   DEVCB_NULL,
342   DEVCB_NULL,
343   DEVCB_DEVICE_HANDLER("centronics", amiga_cia_1_porta_r),
344   DEVCB_NULL,                                    /* port A */
345   DEVCB_NULL,
346   DEVCB_NULL                                    /* port B */
347};
348
349static const tpi6525_interface cdtv_tpi_intf =
350{
351   DEVCB_LINE(amigacd_tpi6525_irq),
352   DEVCB_NULL,
353   DEVCB_NULL,
354   DEVCB_NULL,
355   DEVCB_HANDLER(amigacd_tpi6525_portb_w),
356   DEVCB_HANDLER(amigacd_tpi6525_portc_r),
357   DEVCB_NULL,
358   DEVCB_NULL,
359   DEVCB_NULL
360};
361
362
363static MACHINE_CONFIG_FRAGMENT( amiga_cartslot )
364   MCFG_CARTSLOT_ADD("cart")
365   MCFG_CARTSLOT_EXTENSION_LIST("rom,bin")
366   MCFG_CARTSLOT_NOT_MANDATORY
367MACHINE_CONFIG_END
368
369static MACHINE_CONFIG_START( ntsc, amiga_state )
370   /* basic machine hardware */
371   MCFG_CPU_ADD("maincpu", M68000, AMIGA_68000_NTSC_CLOCK)
372   MCFG_CPU_PROGRAM_MAP(amiga_mem)
373
374   MCFG_CPU_ADD("keyboard", M6502, XTAL_1MHz) /* 1 MHz? */
375   MCFG_CPU_PROGRAM_MAP(keyboard_mem)
376
377   MCFG_SCREEN_ADD("screen", RASTER)
378   MCFG_SCREEN_REFRESH_RATE(59.997)
379   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
380
381   MCFG_MACHINE_RESET( amiga )
382
383    /* video hardware */
384   MCFG_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK)
385   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
386   MCFG_SCREEN_SIZE(228*4, 262)
387   MCFG_SCREEN_VISIBLE_AREA(214, (228*4)-1, 34, 262-1)
388   MCFG_SCREEN_UPDATE(amiga)
389
390   MCFG_PALETTE_LENGTH(4096)
391   MCFG_PALETTE_INIT( amiga )
392
393   MCFG_VIDEO_START(amiga)
394
395   /* devices */
396   MCFG_MSM6242_ADD("rtc")
397   MCFG_CENTRONICS_ADD("centronics", amiga_centronics_config)
398
399   /* sound hardware */
400   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
401
402   MCFG_SOUND_ADD("amiga", AMIGA, 3579545)
403   MCFG_SOUND_ROUTE(0, "lspeaker", 0.50)
404   MCFG_SOUND_ROUTE(1, "rspeaker", 0.50)
405   MCFG_SOUND_ROUTE(2, "rspeaker", 0.50)
406   MCFG_SOUND_ROUTE(3, "lspeaker", 0.50)
407
408   /* cia */
409   MCFG_MOS8520_ADD("cia_0", AMIGA_68000_NTSC_CLOCK / 10, cia_0_ntsc_intf)
410   MCFG_MOS8520_ADD("cia_1", AMIGA_68000_NTSC_CLOCK, cia_1_intf)
411
412   MCFG_AMIGA_FDC_ADD("fdc")
413MACHINE_CONFIG_END
414
415static MACHINE_CONFIG_DERIVED( a1000n, ntsc )
416   MCFG_CPU_MODIFY("maincpu")
417   MCFG_CPU_PROGRAM_MAP(a1000_mem)
418MACHINE_CONFIG_END
419
420static MACHINE_CONFIG_DERIVED( a500n, ntsc )
421   MCFG_FRAGMENT_ADD(amiga_cartslot)
422MACHINE_CONFIG_END
423
424
425static MACHINE_CONFIG_DERIVED( cdtv, ntsc )
426   MCFG_CPU_REPLACE("maincpu", M68000, CDTV_CLOCK_X1 / 4)
427   MCFG_CPU_PROGRAM_MAP(cdtv_mem)
428
429   MCFG_DEVICE_REMOVE("keyboard")
430
431   MCFG_CPU_ADD("rcmcu", M6502, XTAL_1MHz) /* 1 MHz? */
432   MCFG_CPU_PROGRAM_MAP(cdtv_rcmcu_mem)
433   MCFG_DEVICE_DISABLE()
434
435//  MCFG_CPU_ADD("lcd", LC6554, XTAL_4MHz) /* 4 MHz? */
436//  MCFG_CPU_PROGRAM_MAP(cdtv_lcd_mem)
437
438   MCFG_MACHINE_START( cdtv )
439   MCFG_MACHINE_RESET( cdtv )
440
441   MCFG_NVRAM_ADD_0FILL("nvram")
442
443   MCFG_SOUND_ADD( "cdda", CDDA, 0 )
444   MCFG_SOUND_ROUTE( 0, "lspeaker", 1.0 )
445   MCFG_SOUND_ROUTE( 1, "rspeaker", 1.0 )
446
447   /* cdrom */
448   MCFG_CDROM_ADD( "cdrom" )
449   MCFG_CDROM_INTERFACE("cdrom")
450   MCFG_SOFTWARE_LIST_ADD("cd_list", "cdtv")
451
452   MCFG_TPI6525_ADD("tpi6525", cdtv_tpi_intf)
453
454   /* cia */
455   MCFG_DEVICE_REMOVE("cia_0")
456   MCFG_DEVICE_REMOVE("cia_1")
457   MCFG_MOS8520_ADD("cia_0", CDTV_CLOCK_X1 / 40, cia_0_cdtv_intf)
458   MCFG_MOS8520_ADD("cia_1", CDTV_CLOCK_X1 / 4, cia_1_cdtv_intf)
459MACHINE_CONFIG_END
460
461
462static MACHINE_CONFIG_DERIVED( pal, ntsc )
463
464   /* adjust for PAL specs */
465   MCFG_CPU_MODIFY("maincpu")
466   MCFG_CPU_CLOCK( AMIGA_68000_PAL_CLOCK)
467
468   MCFG_SCREEN_MODIFY("screen")
469   MCFG_SCREEN_REFRESH_RATE(50)
470   MCFG_SCREEN_SIZE(228*4, 312)
471   MCFG_SCREEN_VISIBLE_AREA(214, (228*4)-1, 34, 312-1)
472
473   /* cia */
474   MCFG_DEVICE_REMOVE("cia_0")
475   MCFG_MOS8520_ADD("cia_0", AMIGA_68000_PAL_CLOCK / 10, cia_0_pal_intf)
476MACHINE_CONFIG_END
477
478static MACHINE_CONFIG_DERIVED( a500p, pal )
479   MCFG_FRAGMENT_ADD(amiga_cartslot)
480MACHINE_CONFIG_END
481
482static MACHINE_CONFIG_DERIVED( a1000p, pal )
483   MCFG_CPU_MODIFY("maincpu")
484   MCFG_CPU_PROGRAM_MAP(a1000_mem)
485MACHINE_CONFIG_END
486
487/***************************************************************************
488
489  Amiga specific stuff
490
491***************************************************************************/
492
493
494static READ8_DEVICE_HANDLER( amiga_cia_0_portA_r )
495{
496   UINT8 ret = input_port_read(device->machine(), "CIA0PORTA") & 0xc0;   /* Gameport 1 and 0 buttons */
497   ret |= amiga_fdc_status_r(device->machine().device("fdc"));
498   return ret;
499}
500
501
502static READ8_DEVICE_HANDLER( amiga_cia_0_cdtv_portA_r )
503{
504   return input_port_read(device->machine(), "CIA0PORTA") & 0xc0;   /* Gameport 1 and 0 buttons */
505}
506
507
508static WRITE8_DEVICE_HANDLER( amiga_cia_0_portA_w )
509{
510   amiga_state *state = device->machine().driver_data<amiga_state>();
511   /* switch banks as appropriate */
512   memory_set_bank(device->machine(), "bank1", data & 1);
513
514   /* swap the write handlers between ROM and bank 1 based on the bit */
515   if ((data & 1) == 0) {
516      UINT32 mirror_mask = state->m_chip_ram_size;
517
518      while( (mirror_mask<<1) < 0x100000 ) {
519         mirror_mask |= ( mirror_mask << 1 );
520      }
521
522      /* overlay disabled, map RAM on 0x000000 */
523      device->machine().device("maincpu")->memory().space(AS_PROGRAM)->install_write_bank(0x000000, state->m_chip_ram_size - 1, 0, mirror_mask, "bank1");
524
525      /* if there is a cart region, check for cart overlay */
526      if (device->machine().region("user2")->base() != NULL)
527         amiga_cart_check_overlay(device->machine());
528   }
529   else
530      /* overlay enabled, map Amiga system ROM on 0x000000 */
531      device->machine().device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0x000000, state->m_chip_ram_size - 1);
532
533   set_led_status( device->machine(), 0, ( data & 2 ) ? 0 : 1 ); /* bit 2 = Power Led on Amiga */
534   output_set_value("power_led", ( data & 2 ) ? 0 : 1);
535}
536
537static UINT16 amiga_read_joy0dat(running_machine &machine)
538{
539   if ( input_port_read(machine, "input") & 0x20 ) {
540      /* Joystick */
541      return input_port_read_safe(machine, "JOY0DAT", 0xffff);
542   } else {
543      /* Mouse */
544      int input;
545      input  = ( input_port_read(machine, "P0MOUSEX") & 0xff );
546      input |= ( input_port_read(machine, "P0MOUSEY") & 0xff ) << 8;
547      return input;
548   }
549}
550
551static UINT16 amiga_read_joy1dat(running_machine &machine)
552{
553   if ( input_port_read(machine, "input") & 0x10 ) {
554      /* Joystick */
555      return input_port_read_safe(machine, "JOY1DAT", 0xffff);
556   } else {
557      /* Mouse */
558      int input;
559      input  = ( input_port_read(machine, "P1MOUSEX") & 0xff );
560      input |= ( input_port_read(machine, "P1MOUSEY") & 0xff ) << 8;
561      return input;
562   }
563}
564
565static UINT16 amiga_read_dskbytr(running_machine &machine)
566{
567   return amiga_fdc_get_byte(machine.device("fdc"));
568}
569
570static void amiga_write_dsklen(running_machine &machine, UINT16 data)
571{
572   amiga_state *state = machine.driver_data<amiga_state>();
573   if ( data & 0x8000 ) {
574      if ( CUSTOM_REG(REG_DSKLEN) & 0x8000 )
575         amiga_fdc_setup_dma(machine.device("fdc"));
576   }
577}
578
579
580static void amiga_reset(running_machine &machine)
581{
582   if (input_port_read(machine, "hardware") & 0x08)
583   {
584      /* Install RTC */
585      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_readwrite_handler(0xdc0000, 0xdc003f, FUNC(amiga_clock_r), FUNC(amiga_clock_w));
586   }
587   else
588   {
589      /* No RTC support */
590      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_readwrite(0xdc0000, 0xdc003f);
591   }
592}
593
594static DRIVER_INIT( amiga )
595{
596   amiga_state *state = machine.driver_data<amiga_state>();
597   static const amiga_machine_interface amiga_intf =
598   {
599      ANGUS_CHIP_RAM_MASK,
600      amiga_read_joy0dat,   amiga_read_joy1dat,  /* joy0dat_r & joy1dat_r */
601      NULL,                                    /* potgo_w */
602      amiga_read_dskbytr,   amiga_write_dsklen,  /* dskbytr_r & dsklen_w */
603      NULL,                                    /* serdat_w */
604      NULL,                                    /* scanline0_callback */
605      amiga_reset,                             /* reset_callback */
606      amiga_cart_nmi,                          /* nmi_callback */
607      0                                        /* flags */
608   };
609
610   amiga_machine_config(machine, &amiga_intf);
611
612   /* set up memory */
613   memory_configure_bank(machine, "bank1", 0, 1, state->m_chip_ram, 0);
614   memory_configure_bank(machine, "bank1", 1, 1, machine.region("user1")->base(), 0);
615
616   /* initialize cartridge (if present) */
617   amiga_cart_init(machine);
618
619   /* initialize keyboard */
620   amigakbd_init(machine);
621}
622
623#ifdef UNUSED_FUNCTION
624static DRIVER_INIT( amiga_ecs )
625{
626   static const amiga_machine_interface amiga_intf =
627   {
628      ECS_CHIP_RAM_MASK,
629      amiga_cia_0_portA_r, NULL,               /* CIA0 port A & B read */
630      amiga_cia_0_portA_w, NULL,               /* CIA0 port A & B write */
631      NULL, NULL,                              /* CIA1 port A & B read */
632      NULL, amiga_fdc_control_w,               /* CIA1 port A & B write */
633      amiga_read_joy0dat,   amiga_read_joy1dat,  /* joy0dat_r & joy1dat_r */
634      NULL,                                    /* potgo_w */
635      amiga_read_dskbytr,   amiga_write_dsklen,  /* dskbytr_r & dsklen_w */
636      NULL,                                    /* serdat_w */
637      NULL,                                    /* scanline0_callback */
638      amiga_reset,                             /* reset_callback */
639      amiga_cart_nmi,                          /* nmi_callback */
640      0                                        /* flags */
641   };
642
643   amiga_machine_config(machine, &amiga_intf);
644
645   /* set up memory */
646   memory_configure_bank(1, 0, 1, state->m_chip_ram, 0);
647   memory_configure_bank(1, 1, 1, machine.region("user1")->base(), 0);
648
649   /* initialize Action Replay (if present) */
650   amiga_cart_init(machine);
651
652   /* initialize keyboard */
653   amigakbd_init(machine);
654}
655#endif
656
657static DRIVER_INIT( cdtv )
658{
659   amiga_state *state = machine.driver_data<amiga_state>();
660   static const amiga_machine_interface amiga_intf =
661   {
662      ECS_CHIP_RAM_MASK,
663      amiga_read_joy0dat,   amiga_read_joy1dat,  /* joy0dat_r & joy1dat_r */
664      NULL,                                    /* potgo_w */
665      amiga_read_dskbytr,   amiga_write_dsklen,  /* dskbytr_r & dsklen_w */
666      NULL,                                    /* serdat_w */
667      NULL,                                    /* scanline0_callback */
668      NULL,                                    /* reset_callback */
669      NULL,                                    /* nmi_callback */
670      0                                        /* flags */
671   };
672
673   amiga_machine_config(machine, &amiga_intf);
674
675   /* set up memory */
676   memory_configure_bank(machine, "bank1", 0, 1, state->m_chip_ram, 0);
677   memory_configure_bank(machine, "bank1", 1, 1, machine.region("user1")->base(), 0);
678
679   /* initialize keyboard - in cdtv we can use a standard Amiga keyboard*/
680   amigakbd_init(machine);
681}
682
683
684/***************************************************************************
685    ROM DEFINITIONS
686***************************************************************************/
687
688ROM_START( a500n )
689   ROM_REGION16_BE(0x080000, "user1", 0)
690   ROM_DEFAULT_BIOS("kick13")
691   ROM_SYSTEM_BIOS(0, "kick12",  "Kickstart 1.2 (33.180)")
692   ROMX_LOAD("315093-01.u6", 0x000000, 0x040000, CRC(a6ce1636) SHA1(11f9e62cf299f72184835b7b2a70a16333fc0d88), ROM_GROUPWORD | ROM_BIOS(1))
693   ROM_SYSTEM_BIOS(1, "kick13",  "Kickstart 1.3 (34.5)")
694   ROMX_LOAD("315093-02.u6", 0x000000, 0x040000, CRC(c4f0f55f) SHA1(891e9a547772fe0c6c19b610baf8bc4ea7fcb785), ROM_GROUPWORD | ROM_BIOS(2))
695   ROM_COPY("user1", 0x000000, 0x040000, 0x040000)
696   ROM_SYSTEM_BIOS(2, "kick204", "Kickstart 2.04 (37.175)")
697   ROMX_LOAD("390979-01.u6", 0x000000, 0x080000, CRC(c3bdb240) SHA1(c5839f5cb98a7a8947065c3ed2f14f5f42e334a1), ROM_GROUPWORD | ROM_BIOS(3))   /* identical to 363968.01 */
698   ROM_SYSTEM_BIOS(3, "kick31",  "Kickstart 3.1 (40.63)")
699   ROMX_LOAD("kick40063.u6", 0x000000, 0x080000, CRC(fc24ae0d) SHA1(3b7f1493b27e212830f989f26ca76c02049f09ca), ROM_GROUPWORD | ROM_BIOS(4))   /* part number? */
700
701   /* action replay cartridge */
702   ROM_REGION16_BE(0x080000, "user2", ROMREGION_ERASEFF )
703   ROM_CART_LOAD("cart", 0x0000, 0x080000, ROM_NOMIRROR | ROM_OPTIONAL)
704
705   /* keyboard controller, mos 6500/1 mcu */
706   ROM_REGION(0x800, "keyboard", 0)
707   ROM_LOAD("328191-02.ic1", 0x000, 0x800, NO_DUMP)
708ROM_END
709
710#define rom_a500p    rom_a500n
711
712
713ROM_START( a1000n )
714   ROM_REGION16_BE(0x080000, "user1", 0)
715   ROM_LOAD16_BYTE("252179-01.u5n", 0x000000, 0x001000, CRC(42553bc4) SHA1(8855a97f7a44e3f62d1c88d938fee1f4c606af5b))
716   ROM_LOAD16_BYTE("252180-01.u5p", 0x000001, 0x001000, CRC(8e5b9a37) SHA1(d10f1564b99f5ffe108fa042362e877f569de2c3))
717
718   /* keyboard controller, mos 6500/1 mcu */
719   ROM_REGION(0x800, "keyboard", 0)
720   ROM_LOAD("328191-01.bin", 0x000, 0x800, NO_DUMP)
721ROM_END
722
723#define rom_a1000p    rom_a1000n
724
725
726ROM_START( cdtv )
727   ROM_REGION16_BE(0x100000, "user1", 0)
728   ROM_LOAD16_BYTE("391008-01.u34", 0x000000, 0x020000, CRC(791cb14b) SHA1(277a1778924496353ffe56be68063d2a334360e4))
729   ROM_LOAD16_BYTE("391009-01.u35", 0x000001, 0x020000, CRC(accbbc2e) SHA1(41b06d1679c6e6933c3378b7626025f7641ebc5c))
730   ROM_COPY("user1", 0x000000, 0x040000, 0x040000)
731   ROMX_LOAD(      "315093-02.u13", 0x080000, 0x040000, CRC(c4f0f55f) SHA1(891e9a547772fe0c6c19b610baf8bc4ea7fcb785), ROM_GROUPWORD)
732   ROM_COPY("user1", 0x080000, 0x0c0000, 0x040000)
733
734   /* remote control input converter, mos 6500/1 mcu */
735   ROM_REGION(0x800, "rcmcu", 0)
736   ROM_LOAD("252609-02.u75", 0x000, 0x800, NO_DUMP)
737
738   /* lcd controller, sanyo lc6554h */
739   ROM_REGION(0x1000, "lcd", 0)
740   ROM_LOAD("252608-01.u62", 0x000, 0x1000, NO_DUMP)
741ROM_END
742
743/***************************************************************************
744    GAME DRIVERS
745***************************************************************************/
746
747/*    YEAR  NAME    PARENT  COMPAT  MACHINE INPUT   INIT    COMPANY                             FULLNAME                 FLAGS */
748COMP( 1985, a1000n, 0,      0,      a1000n, amiga,  amiga,  "Commodore Business Machines",  "Amiga 1000 (NTSC)",     GAME_IMPERFECT_GRAPHICS )
749COMP( 1985, a1000p, a1000n, 0,      a1000p, amiga,  amiga,  "Commodore Business Machines",  "Amiga 1000 (PAL)",      GAME_IMPERFECT_GRAPHICS )
750COMP( 1987, a500n,  0,      0,      a500n,  amiga,  amiga,  "Commodore Business Machines",  "Amiga 500 (NTSC, OCS)", GAME_IMPERFECT_GRAPHICS )
751COMP( 1987, a500p,  a500n,  0,      a500p,  amiga,  amiga,  "Commodore Business Machines",  "Amiga 500 (PAL, OCS)",  GAME_IMPERFECT_GRAPHICS )
752COMP( 1991, cdtv,   0,      0,      cdtv,   cdtv,   cdtv,   "Commodore Business Machines",  "CDTV (NTSC)",           GAME_IMPERFECT_GRAPHICS )
src/mame/drivers/a7000.c
r0r11461
1/***************************************************************************
2
3    Acorn Archimedes 7000/7000+
4
5    preliminary driver by Angelo Salese,
6    based on work by Tomasz Slanina and Tom Walker
7
8    ???
9    bp (0382827C) (second trigger)
10    do R13 = SR13
11
12****************************************************************************/
13
14#include "emu.h"
15#include "cpu/arm7/arm7.h"
16#include "cpu/arm7/arm7core.h"
17
18
19class a7000_state : public driver_device
20{
21public:
22   a7000_state(const machine_config &mconfig, device_type type, const char *tag)
23      : driver_device(mconfig, type, tag) { }
24
25   UINT8 m_vidc20_pal_index;
26   UINT16 m_vidc20_horz_reg[0x10];
27   UINT16 m_vidc20_vert_reg[0x10];
28   UINT8 m_vidc20_bpp_mode;
29   emu_timer *m_flyback_timer;
30   UINT16 m_timer_in[2];
31   UINT16 m_timer_out[2];
32   int m_timer_counter[2];
33   emu_timer *m_IOMD_timer[2];
34   UINT8 m_IRQ_status_A;
35   UINT8 m_IRQ_mask_A;
36   UINT8 m_IOMD_IO_ctrl;
37   UINT8 m_IOMD_keyb_ctrl;
38   UINT16 m_io_id;
39   UINT8 m_viddma_status;
40   UINT32 m_viddma_addr_start;
41   UINT32 m_viddma_addr_end;
42   UINT8 m_t0readinc;
43   UINT8 m_t1readinc;
44};
45
46
47/*
48 *
49 * VIDC20 chip emulation
50 *
51 */
52
53
54static const char *const vidc20_regnames[] =
55{
56   "Video Palette",               // 0
57   "Video Palette Address",         // 1
58   "RESERVED",                   // 2
59   "LCD offset",                  // 3
60   "Border Colour",               // 4
61   "Cursor Palette Logical Colour 1",   // 5
62   "Cursor Palette Logical Colour 2",   // 6
63   "Cursor Palette Logical Colour 3",   // 7
64   "Horizontal",                  // 8
65   "Vertical",                     // 9
66   "Stereo Image",                  // A
67   "Sound",                     // B
68   "External",                     // C
69   "Frequency Synthesis",            // D
70   "Control",                     // E
71   "Data Control"                  // F
72};
73
74static const char *const vidc20_horz_regnames[] =
75{
76   "Horizontal Cycle",             // 0x80 HCR
77   "Horizontal Sync Width",         // 0x81 HSWR
78   "Horizontal Border Start",         // 0x82 HBSR
79   "Horizontal Display Start",         // 0x83 HDSR
80   "Horizontal Display End",         // 0x84 HDER
81   "Horizontal Border End",         // 0x85 HBER
82   "Horizontal Cursor Start",         // 0x86 HCSR
83   "Horizontal Interlace",          // 0x87 HIR
84   "Horizontal Counter TEST",         // 0x88
85   "Horizontal <UNDEFINED>",         // 0x89
86   "Horizontal <UNDEFINED>",         // 0x8a
87   "Horizontal <UNDEFINED>",         // 0x8b
88   "Horizontal All TEST",            // 0x8c
89   "Horizontal <UNDEFINED>",         // 0x8d
90   "Horizontal <UNDEFINED>",         // 0x8e
91   "Horizontal <UNDEFINED>"         // 0x8f
92};
93
94#define HCR  0
95#define HSWR 1
96#define HBSR 2
97#define HDSR 3
98#define HDER 4
99#define HBER 5
100#define HCSR 6
101#define HIR  7
102
103static const char *const vidc20_vert_regnames[] =
104{
105   "Vertical Cycle",               // 0x90 VCR
106   "Vertical Sync Width",            // 0x91 VSWR
107   "Vertical Border Start",         // 0x92 VBSR
108   "Vertical Display Start",         // 0x93 VDSR
109   "Vertical Display End",          // 0x94 VDER
110   "Vertical Border End",            // 0x95 VBER
111   "Vertical Cursor Start",         // 0x96 VCSR
112   "Vertical Cursor End",            // 0x97 VCER
113   "Vertical Counter TEST",         // 0x98
114   "Horizontal <UNDEFINED>",         // 0x99
115   "Vertical Counter Increment TEST",   // 0x9a
116   "Horizontal <UNDEFINED>",         // 0x9b
117   "Vertical All TEST",            // 0x9c
118   "Horizontal <UNDEFINED>",         // 0x9d
119   "Horizontal <UNDEFINED>",         // 0x9e
120   "Horizontal <UNDEFINED>"         // 0x9f
121};
122
123#define VCR  0
124#define VSWR 1
125#define VBSR 2
126#define VDSR 3
127#define VDER 4
128#define VBER 5
129#define VCSR 6
130#define VCER 7
131
132static void vidc20_dynamic_screen_change(running_machine &machine)
133{
134   a7000_state *state = machine.driver_data<a7000_state>();
135   /* sanity checks - first pass */
136   /*
137    total cycles + border start/end
138    */
139   if(state->m_vidc20_horz_reg[HCR] && state->m_vidc20_horz_reg[HBSR] && state->m_vidc20_horz_reg[HBER] &&
140      state->m_vidc20_vert_reg[VCR] && state->m_vidc20_vert_reg[VBSR] && state->m_vidc20_vert_reg[VBER])
141   {
142      /* sanity checks - second pass */
143      /*
144        total cycles > border end > border start
145        */
146      if((state->m_vidc20_horz_reg[HCR] > state->m_vidc20_horz_reg[HBER]) &&
147         (state->m_vidc20_horz_reg[HBER] > state->m_vidc20_horz_reg[HBSR]) &&
148         (state->m_vidc20_vert_reg[VCR] > state->m_vidc20_vert_reg[VBER]) &&
149         (state->m_vidc20_vert_reg[VBER] > state->m_vidc20_vert_reg[VBSR]))
150      {
151         /* finally ready to change the resolution */
152         int hblank_period,vblank_period;
153         rectangle visarea = machine.primary_screen->visible_area();
154         hblank_period = (state->m_vidc20_horz_reg[HCR] & 0x3ffc);
155         vblank_period = (state->m_vidc20_vert_reg[VCR] & 0x3fff);
156         /* note that we use the border registers as the visible area */
157         visarea.min_x = (state->m_vidc20_horz_reg[HBSR] & 0x3ffe);
158         visarea.max_x = (state->m_vidc20_horz_reg[HBER] & 0x3ffe)-1;
159         visarea.min_y = (state->m_vidc20_vert_reg[VBSR] & 0x1fff);
160         visarea.max_y = (state->m_vidc20_vert_reg[VBER] & 0x1fff)-1;
161
162         machine.primary_screen->configure(hblank_period, vblank_period, visarea, machine.primary_screen->frame_period().attoseconds );
163         logerror("VIDC20: successfully changed the screen to:\n Display Size = %d x %d\n Border Size %d x %d\n Cycle Period %d x %d\n",
164                    (state->m_vidc20_horz_reg[HDER]-state->m_vidc20_horz_reg[HDSR]),(state->m_vidc20_vert_reg[VDER]-state->m_vidc20_vert_reg[VDSR]),
165                    (state->m_vidc20_horz_reg[HBER]-state->m_vidc20_horz_reg[HBSR]),(state->m_vidc20_vert_reg[VBER]-state->m_vidc20_vert_reg[VBSR]),
166                    hblank_period,vblank_period);
167      }
168   }
169}
170
171static WRITE32_HANDLER( a7000_vidc20_w )
172{
173   a7000_state *state = space->machine().driver_data<a7000_state>();
174   int reg = data >> 28;
175
176   switch(reg)
177   {
178      case 0: // Video Palette
179      {
180         int r,g,b;
181
182         r = (data & 0x0000ff) >> 0;
183         g = (data & 0x00ff00) >> 8;
184         b = (data & 0xff0000) >> 16;
185
186         palette_set_color_rgb(space->machine(),state->m_vidc20_pal_index & 0xff,r,g,b);
187
188         /* auto-increment & wrap-around */
189         state->m_vidc20_pal_index++;
190         state->m_vidc20_pal_index &= 0xff;
191      }
192      break;
193      case 1: // Video Palette Address
194      {
195         // according to RPCEmu, these mustn't be set
196         if (data & 0x0fffff00)
197            return;
198
199         state->m_vidc20_pal_index = data & 0xff;
200      }
201      break;
202
203      case 4: // Border Color
204      {
205         int r,g,b;
206
207         r = (data & 0x0000ff) >> 0;
208         g = (data & 0x00ff00) >> 8;
209         b = (data & 0xff0000) >> 16;
210
211         palette_set_color_rgb(space->machine(),0x100,r,g,b);
212      }
213      break;
214      case 5: // Cursor Palette Logical Colour n
215      case 6:
216      case 7:
217      {
218         int r,g,b;
219         int cursor_index = 0x100 + reg - 4; // 0x101,0x102 and 0x103 (plus 0x100 of above, 2bpp)
220
221         r = (data & 0x0000ff) >> 0;
222         g = (data & 0x00ff00) >> 8;
223         b = (data & 0xff0000) >> 16;
224
225         palette_set_color_rgb(space->machine(),cursor_index,r,g,b);
226      }
227      break;
228      case 8: // Horizontal
229      {
230         int horz_reg;
231
232         horz_reg = (data >> 24) & 0xf;
233         state->m_vidc20_horz_reg[horz_reg] = data & 0x3fff;
234         if(horz_reg == 0 || horz_reg == 2 || horz_reg == 5)
235            vidc20_dynamic_screen_change(space->machine());
236
237         // logerror("VIDC20: %s Register write = %08x (%d)\n",vidc20_horz_regnames[horz_reg],val,val);
238      }
239      break;
240      case 9: // Vertical
241      {
242         int vert_reg;
243
244         vert_reg = (data >> 24) & 0xf;
245         state->m_vidc20_vert_reg[vert_reg] = data & 0x1fff;
246         if(vert_reg == 0 || vert_reg == 2 || vert_reg == 5)
247            vidc20_dynamic_screen_change(space->machine());
248
249         if(vert_reg == 4)
250         {
251            if(state->m_vidc20_vert_reg[VDER] != 0)
252               state->m_flyback_timer->adjust(space->machine().primary_screen->time_until_pos(state->m_vidc20_vert_reg[VDER]));
253            else
254               state->m_flyback_timer->adjust(attotime::never);
255         }
256
257         // logerror("VIDC20: %s Register write = %08x (%d)\n",vidc20_vert_regnames[vert_reg],val,val);
258
259      }
260      break;
261      case 0x0e: // Control
262      {
263         state->m_vidc20_bpp_mode = (data & 0xe0) >> 5;
264      }
265      break;
266      default: logerror("VIDC20: %s Register write = %08x\n",vidc20_regnames[reg],data & 0xfffffff);
267   }
268}
269
270static VIDEO_START( a7000 )
271{
272}
273
274static SCREEN_UPDATE( a7000 )
275{
276   a7000_state *state = screen->machine().driver_data<a7000_state>();
277   int x_size,y_size,x_start,y_start;
278   int x,y,xi;
279   UINT32 count;
280   UINT8 *vram = screen->machine().region("vram")->base();
281
282   bitmap_fill(bitmap, cliprect, screen->machine().pens[0x100]);
283
284   x_size = (state->m_vidc20_horz_reg[HDER]-state->m_vidc20_horz_reg[HDSR]);
285   y_size = (state->m_vidc20_vert_reg[VDER]-state->m_vidc20_vert_reg[VDSR]);
286   x_start = state->m_vidc20_horz_reg[HDSR];
287   y_start = state->m_vidc20_vert_reg[VDSR];
288
289   /* check if display is enabled */
290   if(x_size <= 0 || y_size <= 0)
291      return 0;
292
293//  popmessage("%d",state->m_vidc20_bpp_mode);
294
295   count = 0;
296
297   switch(state->m_vidc20_bpp_mode)
298   {
299      case 0: /* 1 bpp */
300      {
301         for(y=0;y<y_size;y++)
302         {
303            for(x=0;x<x_size;x+=8)
304            {
305               for(xi=0;xi<8;xi++)
306                  *BITMAP_ADDR32(bitmap, y+y_start, x+xi+x_start) = screen->machine().pens[(vram[count]>>(xi))&1];
307
308               count++;
309            }
310         }
311      }
312      break;
313      case 1: /* 2 bpp */
314      {
315         for(y=0;y<y_size;y++)
316         {
317            for(x=0;x<x_size;x+=4)
318            {
319               for(xi=0;xi<4;xi++)
320                  *BITMAP_ADDR32(bitmap, y+y_start, x+xi+x_start) = screen->machine().pens[(vram[count]>>(xi*2))&3];
321
322               count++;
323            }
324         }
325      }
326      break;
327      case 2: /* 4 bpp */
328      {
329         for(y=0;y<y_size;y++)
330         {
331            for(x=0;x<x_size;x+=2)
332            {
333               for(xi=0;xi<2;xi++)
334                  *BITMAP_ADDR32(bitmap, y+y_start, x+xi+x_start) = screen->machine().pens[(vram[count]>>(xi*4))&0xf];
335
336               count++;
337            }
338         }
339      }
340      break;
341      case 3: /* 8 bpp */
342      {
343         for(y=0;y<y_size;y++)
344         {
345            for(x=0;x<x_size;x++)
346            {
347               *BITMAP_ADDR32(bitmap, y+y_start, x+x_start) = screen->machine().pens[(vram[count])&0xff];
348
349               count++;
350            }
351         }
352      }
353      break;
354      case 4: /* 16 bpp */
355      {
356         for(y=0;y<y_size;y++)
357         {
358            for(x=0;x<x_size;x++)
359            {
360               int r,g,b,pen;
361
362               pen = ((vram[count]<<8)|(vram[count+1]))&0xffff;
363               r = (pen & 0x000f);
364               g = (pen & 0x00f0) >> 4;
365               b = (pen & 0x0f00) >> 8;
366               r = (r << 4) | (r & 0xf);
367               g = (g << 4) | (g & 0xf);
368               b = (b << 4) | (b & 0xf);
369
370               *BITMAP_ADDR32(bitmap, y+y_start, x+x_start) =  b | g << 8 | r << 16;
371
372               count+=2;
373            }
374         }
375      }
376      break;
377      case 6: /* 32 bpp */
378      {
379         for(y=0;y<y_size;y++)
380         {
381            for(x=0;x<x_size;x++)
382            {
383               int r,g,b,pen;
384
385               pen = ((vram[count]<<24)|(vram[count+1]<<16)|(vram[count+2]<<8)|(vram[count+3]<<0));
386               r = (pen & 0x0000ff);
387               g = (pen & 0x00ff00) >> 8;
388               b = (pen & 0xff0000) >> 16;
389
390               *BITMAP_ADDR32(bitmap, y+y_start, x+x_start) =  b | g << 8 | r << 16;
391
392               count+=4;
393            }
394         }
395      }
396      break;
397      default:
398         //fatalerror("VIDC20 %08x BPP mode not supported\n",state->m_vidc20_bpp_mode);
399         break;
400   }
401
402    return 0;
403}
404
405/*
406*
407* IOMD / ARM7500 / ARM7500FE chip emulation
408*
409*/
410
411/* TODO: some of these registers are actually ARM7500 specific */
412static const char *const iomd_regnames[] =
413{
414   "I/O Control",                  // 0x000 IOCR
415   "Keyboard Data",               // 0x004 KBDDAT
416   "Keyboard Control",               // 0x008 KBDCR
417   "General Purpose I/O Lines",      // 0x00c IOLINES
418   "IRQA Status",                  // 0x010 IRQSTA
419   "IRQA Request/clear",            // 0x014 IRQRQA
420   "IRQA Mask",                  // 0x018 IRQMSKA
421   "Enter SUSPEND Mode",            // 0x01c SUSMODE
422   "IRQB Status",                  // 0x020 IRQSTB
423   "IRQB Request/clear",            // 0x024 IRQRQB
424   "IRQB Mask",                  // 0x028 IRQMSKB
425   "Enter STOP Mode",               // 0x02c STOPMODE
426   "FIQ Status",                  // 0x030 FIQST
427   "FIQ Request/clear",            // 0x034 FIQRQ
428   "FIQ Mask",                     // 0x038 FIQMSK
429   "Clock divider control",         // 0x03c CLKCTL
430   "Timer 0 Low Bits",               // 0x040 T0LOW
431   "Timer 0 High Bits",            // 0x044 T0HIGH
432   "Timer 0 Go Command",            // 0x048 T0GO
433   "Timer 0 Latch Command",         // 0x04c T0LATCH
434   "Timer 1 Low Bits",               // 0x050 T1LOW
435   "Timer 1 High Bits",            // 0x054 T1HIGH
436   "Timer 1 Go Command",            // 0x058 T1GO
437   "Timer 1 Latch Command",         // 0x05c T1LATCH
438   "IRQC Status",                  // 0x060 IRQSTC
439   "IRQC Request/clear",            // 0x064 IRQRQC
440   "IRQC Mask",                  // 0x068 IRQMSKC
441   "LCD and IIS Control Bits",         // 0x06c VIDIMUX
442   "IRQD Status",                  // 0x070 IRQSTD
443   "IRQD Request/clear",            // 0x074 IRQRQD
444   "IRQD Mask",                  // 0x078 IRQMSKD
445   "<RESERVED>",                  // 0x07c
446   "ROM Control Bank 0",            // 0x080 ROMCR0
447   "ROM Control Bank 1",            // 0x084 ROMCR1
448   "DRAM Control (IOMD)",            // 0x088 DRAMCR
449   "VRAM and Refresh Control",         // 0x08c VREFCR
450   "Flyback Line Size",            // 0x090 FSIZE
451   "Chip ID no. Low Byte",            // 0x094 ID0
452   "Chip ID no. High Byte",         // 0x098 ID1
453   "Chip Version Number",            // 0x09c VERSION
454   "Mouse X Position",               // 0x0a0 MOUSEX
455   "Mouse Y Position",               // 0x0a4 MOUSEY
456   "Mouse Data",                  // 0x0a8 MSEDAT
457   "Mouse Control",               // 0x0ac MSECR
458   "<RESERVED>",                  // 0x0b0
459   "<RESERVED>",                  // 0x0b4
460   "<RESERVED>",                  // 0x0b8
461   "<RESERVED>",                  // 0x0bc
462   "DACK Timing Control",            // 0x0c0 DMATCR
463   "I/O Timing Control",            // 0x0c4 IOTCR
464   "Expansion Card Timing",         // 0x0c8 ECTCR
465   "DMA External Control",            // 0x0cc DMAEXT (IOMD) / ASTCR (ARM7500)
466   "DRAM Width Control",            // 0x0d0 DRAMWID
467   "Force CAS/RAS Lines Low",         // 0x0d4 SELFREF
468   "<RESERVED>",                  // 0x0d8
469   "<RESERVED>",                  // 0x0dc
470   "A to D IRQ Control",            // 0x0e0 ATODICR
471   "A to D IRQ Status",            // 0x0e4 ATODCC
472   "A to D IRQ Converter Control",      // 0x0e8 ATODICR
473   "A to D IRQ Counter 1",            // 0x0ec ATODCNT1
474   "A to D IRQ Counter 2",            // 0x0f0 ATODCNT2
475   "A to D IRQ Counter 3",            // 0x0f4 ATODCNT3
476   "A to D IRQ Counter 4",            // 0x0f8 ATODCNT4
477   "<RESERVED>",                  // 0x0fc
478   "I/O DMA 0 CurA",               // 0x100 IO0CURA
479   "I/O DMA 0 EndA",               // 0x104 IO0ENDA
480   "I/O DMA 0 CurB",               // 0x108 IO0CURB
481   "I/O DMA 0 EndB",               // 0x10c IO0ENDB
482   "I/O DMA 0 Control",            // 0x110 IO0CR
483   "I/O DMA 0 Status",               // 0x114 IO0ST
484   "<RESERVED>",                  // 0x118
485   "<RESERVED>",                  // 0x11c
486   "I/O DMA 1 CurA",               // 0x120 IO1CURA
487   "I/O DMA 1 EndA",               // 0x124 IO1ENDA
488   "I/O DMA 1 CurB",               // 0x128 IO1CURB
489   "I/O DMA 1 EndB",               // 0x12c IO1ENDB
490   "I/O DMA 1 Control",            // 0x130 IO1CR
491   "I/O DMA 1 Status",               // 0x134 IO1ST
492   "<RESERVED>",                  // 0x138
493   "<RESERVED>",                  // 0x13c
494   "I/O DMA 2 CurA",               // 0x140 IO2CURA
495   "I/O DMA 2 EndA",               // 0x144 IO2ENDA
496   "I/O DMA 2 CurB",               // 0x148 IO2CURB
497   "I/O DMA 2 EndB",               // 0x14c IO2ENDB
498   "I/O DMA 2 Control",            // 0x150 IO2CR
499   "I/O DMA 2 Status",               // 0x154 IO2ST
500   "<RESERVED>",                  // 0x158
501   "<RESERVED>",                  // 0x15c
502   "I/O DMA 3 CurA",               // 0x160 IO3CURA
503   "I/O DMA 3 EndA",               // 0x164 IO3ENDA
504   "I/O DMA 3 CurB",               // 0x168 IO3CURB
505   "I/O DMA 3 EndB",               // 0x16c IO3ENDB
506   "I/O DMA 3 Control",            // 0x170 IO3CR
507   "I/O DMA 3 Status",               // 0x174 IO3ST
508   "<RESERVED>",                  // 0x178
509   "<RESERVED>",                  // 0x17c
510   "Sound DMA 0 CurA",               // 0x180 SD0CURA
511   "Sound DMA 0 EndA",               // 0x184 SD0ENDA
512   "Sound DMA 0 CurB",               // 0x188 SD0CURB
513   "Sound DMA 0 EndB",               // 0x18c SD0ENDB
514   "Sound DMA 0 Control",            // 0x190 SD0CR
515   "Sound DMA 0 Status",            // 0x194 SD0ST
516   "<RESERVED>",                  // 0x198
517   "<RESERVED>",                  // 0x19c
518   "Sound DMA 1 CurA",               // 0x1a0 SD1CURA
519   "Sound DMA 1 EndA",               // 0x1a4 SD1ENDA
520   "Sound DMA 1 CurB",               // 0x1a8 SD1CURB
521   "Sound DMA 1 EndB",               // 0x1ac SD1ENDB
522   "Sound DMA 1 Control",            // 0x1b0 SD1CR
523   "Sound DMA 1 Status",            // 0x1b4 SD1ST
524   "<RESERVED>",                  // 0x1b8
525   "<RESERVED>",                  // 0x1bc
526   "Cursor DMA Current",            // 0x1c0 CURSCUR
527   "Cursor DMA Init",               // 0x1c4 CURSINIT
528   "Duplex LCD Current B",            // 0x1c8 VIDCURB
529   "<RESERVED>",                  // 0x1cc
530   "Video DMA Current",            // 0x1d0 VIDCUR
531   "Video DMA End",               // 0x1d4 VIDEND
532   "Video DMA Start",               // 0x1d8 VIDSTART
533   "Video DMA Init",               // 0x1dc VIDINIT
534   "Video DMA Control",            // 0x1e0 VIDCR
535   "<RESERVED>",                  // 0x1e4
536   "Duplex LCD Init B",            // 0x1e8 VIDINITB
537   "<RESERVED>",                  // 0x1ec
538   "DMA IRQ Status",               // 0x1f0 DMAST
539   "DMA IRQ Request",               // 0x1f4 DMARQ
540   "DMA IRQ Mask",                  // 0x1f8 DMAMSK
541   "<RESERVED>"                  // 0x1fc
542};
543
544#define IOMD_IOCR      0x000/4
545#define IOMD_KBDDAT      0x004/4
546#define IOMD_KBDCR      0x008/4
547
548#define IOMD_IRQSTA      0x010/4
549#define IOMD_IRQRQA    0x014/4
550#define IOMD_IRQMSKA   0x018/4
551
552#define IOMD_T0LOW      0x040/4
553#define IOMD_T0HIGH    0x044/4
554#define IOMD_T0GO      0x048/4
555#define IOMD_T0LATCH   0x04c/4
556
557#define IOMD_T1LOW      0x050/4
558#define IOMD_T1HIGH    0x054/4
559#define IOMD_T1GO      0x058/4
560#define IOMD_T1LATCH   0x05c/4
561
562#define IOMD_ID0      0x094/4
563#define IOMD_ID1      0x098/4
564#define IOMD_VERSION   0x09c/4
565
566#define IOMD_VIDCUR      0x1d0/4
567#define IOMD_VIDEND      0x1d4/4
568#define IOMD_VIDSTART   0x1d8/4
569#define IOMD_VIDINIT   0x1dc/4
570#define IOMD_VIDCR      0x1e0/4
571
572
573
574static void fire_iomd_timer(a7000_state *state, int timer)
575{
576   int timer_count = state->m_timer_counter[timer];
577   int val = timer_count / 2; // correct?
578
579   if(val==0)
580      state->m_IOMD_timer[timer]->adjust(attotime::never);
581   else
582      state->m_IOMD_timer[timer]->adjust(attotime::from_usec(val), 0, attotime::from_usec(val));
583}
584
585static TIMER_CALLBACK( IOMD_timer0_callback )
586{
587   a7000_state *state = machine.driver_data<a7000_state>();
588   state->m_IRQ_status_A|=0x20;
589   if(state->m_IRQ_mask_A&0x20)
590   {
591      generic_pulse_irq_line(machine.device("maincpu"), ARM7_IRQ_LINE);
592   }
593}
594
595static TIMER_CALLBACK( IOMD_timer1_callback )
596{
597   a7000_state *state = machine.driver_data<a7000_state>();
598   state->m_IRQ_status_A|=0x40;
599   if(state->m_IRQ_mask_A&0x40)
600   {
601      generic_pulse_irq_line(machine.device("maincpu"), ARM7_IRQ_LINE);
602   }
603}
604
605static TIMER_CALLBACK( flyback_timer_callback )
606{
607   a7000_state *state = machine.driver_data<a7000_state>();
608   state->m_IRQ_status_A|=0x08;
609   if(state->m_IRQ_mask_A&0x08)
610   {
611      generic_pulse_irq_line(machine.device("maincpu"), ARM7_IRQ_LINE);
612   }
613
614   state->m_flyback_timer->adjust(machine.primary_screen->time_until_pos(state->m_vidc20_vert_reg[VDER]));
615}
616
617static void viddma_transfer_start(address_space *space)
618{
619   a7000_state *state = space->machine().driver_data<a7000_state>();
620   UINT32 src = state->m_viddma_addr_start;
621   UINT32 dst = 0;
622   UINT32 size = state->m_viddma_addr_end;
623   UINT32 dma_index;
624   UINT8 *vram = space->machine().region("vram")->base();
625
626   /* TODO: this should actually be a qword transfer */
627   for(dma_index = 0;dma_index < size;dma_index++)
628   {
629      vram[dst] = space->read_byte(src);
630
631      src++;
632      dst++;
633   }
634}
635
636static READ32_HANDLER( a7000_iomd_r )
637{
638   a7000_state *state = space->machine().driver_data<a7000_state>();
639//  if(offset != IOMD_KBDCR)
640//      logerror("IOMD: %s Register (%04x) read\n",iomd_regnames[offset & (0x1ff >> 2)],offset*4);
641
642
643   switch(offset)
644   {
645      case IOMD_IOCR:
646      {
647         UINT8 flyback;
648         int vert_pos;
649
650         vert_pos = space->machine().primary_screen->vpos();
651         flyback = (vert_pos <= state->m_vidc20_vert_reg[VDSR] || vert_pos >= state->m_vidc20_vert_reg[VDER]) ? 0x80 : 0x00;
652
653         return state->m_IOMD_IO_ctrl | 0x34 | flyback;
654      }
655      case IOMD_KBDCR:   return state->m_IOMD_keyb_ctrl | 0x80; //IOMD Keyb status
656
657      /*
658        1--- ---- always high
659        -x-- ---- Timer 1
660        --x- ---- Timer 0
661        ---x ---- Power On Reset
662        ---- x--- Flyback
663        ---- -x-- nINT1
664        ---- --0- always low
665        ---- ---x INT2
666        */
667      case IOMD_IRQSTA:   return (state->m_IRQ_status_A & ~2) | 0x80;
668      case IOMD_IRQRQA:   return (state->m_IRQ_status_A & state->m_IRQ_mask_A) | 0x80;
669      case IOMD_IRQMSKA:   return (state->m_IRQ_mask_A);
670
671      case IOMD_T0LOW:   return state->m_timer_out[0] & 0xff;
672      case IOMD_T0HIGH:   return (state->m_timer_out[0] >> 8) & 0xff;
673
674      case IOMD_T1LOW:   return state->m_timer_out[1] & 0xff;
675      case IOMD_T1HIGH:   return (state->m_timer_out[1] >> 8) & 0xff;
676
677      case IOMD_ID0:      return state->m_io_id & 0xff; // IOMD ID low
678      case IOMD_ID1:      return (state->m_io_id >> 8) & 0xff; // IOMD ID high
679      case IOMD_VERSION:   return 0;
680
681      case IOMD_VIDEND:   return (state->m_viddma_addr_end & 0x00fffff8); //bits 31:24 undefined
682      case IOMD_VIDSTART: return (state->m_viddma_addr_start & 0x1ffffff8); //bits 31, 30, 29 undefined
683      case IOMD_VIDCR:   return (state->m_viddma_status & 0xa0) | 0x50; //bit 6 = DRAM mode, bit 4 = QWORD transfer
684
685      default:   logerror("IOMD: %s Register (%04x) read\n",iomd_regnames[offset & (0x1ff >> 2)],offset*4); break;
686   }
687
688   return 0;
689}
690
691static WRITE32_HANDLER( a7000_iomd_w )
692{
693   a7000_state *state = space->machine().driver_data<a7000_state>();
694//  logerror("IOMD: %s Register (%04x) write = %08x\n",iomd_regnames[offset & (0x1ff >> 2)],offset*4,data);
695
696   switch(offset)
697   {
698      case IOMD_IOCR:      state->m_IOMD_IO_ctrl = data & ~0xf4; break;
699
700      case IOMD_KBDCR:
701         state->m_IOMD_keyb_ctrl = data & ~0xf4;
702         //keyboard_ctrl_write(data & 0x08);
703         break;
704
705      case IOMD_IRQRQA:   state->m_IRQ_status_A &= ~data; break;
706      case IOMD_IRQMSKA:   state->m_IRQ_mask_A = (data & ~2) | 0x80; break;
707
708      case IOMD_T0LOW:   state->m_timer_in[0] = (state->m_timer_in[0] & 0xff00) | (data & 0xff); break;
709      case IOMD_T0HIGH:   state->m_timer_in[0] = (state->m_timer_in[0] & 0x00ff) | ((data & 0xff) << 8); break;
710      case IOMD_T0GO:
711         state->m_timer_counter[0] = state->m_timer_in[0];
712         fire_iomd_timer(state,0);
713         break;
714      case IOMD_T0LATCH:
715         {
716            state->m_t0readinc^=1;
717            state->m_timer_out[0] = state->m_timer_counter[0];
718            if(state->m_t0readinc)
719            {
720               state->m_timer_counter[0]--;
721               if(state->m_timer_counter[0] < 0)
722                  state->m_timer_counter[0]+= state->m_timer_in[0];
723            }
724         }
725         break;
726
727      case IOMD_T1LOW:   state->m_timer_in[1] = (state->m_timer_in[1] & 0xff00) | (data & 0xff); break;
728      case IOMD_T1HIGH:   state->m_timer_in[1] = (state->m_timer_in[1] & 0x00ff) | ((data & 0xff) << 8); break;
729      case IOMD_T1GO:
730         state->m_timer_counter[1] = state->m_timer_in[1];
731         fire_iomd_timer(state,1);
732         break;
733      case IOMD_T1LATCH:
734         {
735            state->m_t1readinc^=1;
736            state->m_timer_out[1] = state->m_timer_counter[1];
737            if(state->m_t1readinc)
738            {
739               state->m_timer_counter[1]--;
740               if(state->m_timer_counter[1] < 0)
741                  state->m_timer_counter[1]+= state->m_timer_in[1];
742            }
743         }
744         break;
745
746      case IOMD_VIDEND:   state->m_viddma_addr_end = data & 0x00fffff8; //bits 31:24 unused
747      case IOMD_VIDSTART: state->m_viddma_addr_start = data & 0x1ffffff8; //bits 31, 30, 29 unused
748      case IOMD_VIDCR:
749         state->m_viddma_status = data & 0xa0; if(data & 0x20) { viddma_transfer_start(space); }
750         break;
751
752
753      default: logerror("IOMD: %s Register (%04x) write = %08x\n",iomd_regnames[offset & (0x1ff >> 2)],offset*4,data);
754   }
755}
756
757static ADDRESS_MAP_START( a7000_mem, AS_PROGRAM, 32)
758   AM_RANGE(0x00000000, 0x003fffff) AM_MIRROR(0x00800000) AM_ROM AM_REGION("user1", 0x0)
759//  AM_RANGE(0x01000000, 0x01ffffff) AM_NOP //expansion ROM
760//  AM_RANGE(0x02000000, 0x02ffffff) AM_RAM //VRAM
761//  I/O 03000000 - 033fffff
762//  AM_RANGE(0x03010000, 0x03011fff) //Super IO
763//  AM_RANGE(0x03012000, 0x03029fff) //FDC
764//  AM_RANGE(0x0302b000, 0x0302bfff) //Network podule
765//  AM_RANGE(0x03040000, 0x0304ffff) //podule space 0,1,2,3
766//  AM_RANGE(0x03070000, 0x0307ffff) //podule space 4,5,6,7
767   AM_RANGE(0x03200000, 0x032001ff) AM_READWRITE(a7000_iomd_r,a7000_iomd_w) //IOMD Registers //mirrored at 0x03000000-0x1ff?
768//  AM_RANGE(0x03310000, 0x03310003) //Mouse Buttons
769
770   AM_RANGE(0x03400000, 0x037fffff) AM_WRITE(a7000_vidc20_w)
771//  AM_RANGE(0x08000000, 0x08ffffff) AM_MIRROR(0x07000000) //EASI space
772   AM_RANGE(0x10000000, 0x13ffffff) AM_RAM //SIMM 0 bank 0
773   AM_RANGE(0x14000000, 0x17ffffff) AM_RAM //SIMM 0 bank 1
774//  AM_RANGE(0x18000000, 0x18ffffff) AM_MIRROR(0x03000000) AM_RAM //SIMM 1 bank 0
775//  AM_RANGE(0x1c000000, 0x1cffffff) AM_MIRROR(0x03000000) AM_RAM //SIMM 1 bank 1
776ADDRESS_MAP_END
777
778
779/* Input ports */
780static INPUT_PORTS_START( a7000 )
781INPUT_PORTS_END
782
783static MACHINE_START(a7000)
784{
785   a7000_state *state = machine.driver_data<a7000_state>();
786   state->m_IOMD_timer[0] = machine.scheduler().timer_alloc(FUNC(IOMD_timer0_callback));
787   state->m_IOMD_timer[1] = machine.scheduler().timer_alloc(FUNC(IOMD_timer1_callback));
788   state->m_flyback_timer = machine.scheduler().timer_alloc(FUNC(flyback_timer_callback));
789
790   state->m_io_id = 0xd4e7;
791}
792
793static MACHINE_RESET(a7000)
794{
795   a7000_state *state = machine.driver_data<a7000_state>();
796   state->m_IOMD_IO_ctrl = 0x0b | 0x34; //bit 0,1 and 3 set high on reset plus 2,4,5 always high
797//  state->m_IRQ_status_A = 0x10; // set POR bit ON
798   state->m_IRQ_mask_A = 0x00;
799
800   state->m_IOMD_keyb_ctrl = 0x00;
801
802   state->m_IOMD_timer[0]->adjust( attotime::never);
803   state->m_IOMD_timer[1]->adjust( attotime::never);
804   state->m_flyback_timer->adjust( attotime::never);
805}
806
807static MACHINE_CONFIG_START( a7000, a7000_state )
808
809   /* Basic machine hardware */
810   MCFG_CPU_ADD( "maincpu", ARM7, XTAL_32MHz )
811   MCFG_CPU_PROGRAM_MAP(a7000_mem)
812
813   MCFG_MACHINE_START( a7000 )
814   MCFG_MACHINE_RESET( a7000 )
815
816   /* video hardware */
817   MCFG_SCREEN_ADD("screen", RASTER)
818   MCFG_SCREEN_REFRESH_RATE(60)
819   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
820   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
821   MCFG_SCREEN_SIZE(1900, 1080) //max available size
822   MCFG_SCREEN_VISIBLE_AREA(0, 1900-1, 0, 1080-1)
823   MCFG_SCREEN_UPDATE(a7000)
824   MCFG_PALETTE_LENGTH(0x200)
825//  MCFG_PALETTE_INIT(black_and_white)
826
827   MCFG_VIDEO_START(a7000)
828MACHINE_CONFIG_END
829
830static MACHINE_CONFIG_DERIVED( a7000p, a7000 )
831
832   MCFG_CPU_MODIFY("maincpu")
833   MCFG_CPU_CLOCK(XTAL_48MHz)
834MACHINE_CONFIG_END
835
836ROM_START(a7000)
837   ROM_REGION( 0x800000, "user1", ROMREGION_ERASEFF )
838   ROM_LOAD( "rom1.bin", 0x000000, 0x100000, CRC(ff0e3d12) SHA1(fa489bebede3d13dc43cddec5b5c9b6829a28914) )
839   ROM_LOAD( "rom2.bin", 0x100000, 0x100000, CRC(4ae4fd8b) SHA1(1b30d5905d5364dfa48bad69257b0ef8190e9bf6) )
840   ROM_LOAD( "rom3.bin", 0x200000, 0x100000, CRC(3108fb2b) SHA1(865b01583f3fb5f4ed5e9201676db327cdeb40b3) )
841   ROM_LOAD( "rom4.bin", 0x300000, 0x100000, CRC(55a51980) SHA1(a7191727edd5babf679ebbdea6585833a1fb34e6) )
842
843   ROM_REGION( 0x800000, "vram", ROMREGION_ERASE00 )
844ROM_END
845
846ROM_START(a7000p)
847   ROM_REGION( 0x800000, "user1", ROMREGION_ERASEFF )
848   ROM_LOAD( "riscos-3.71.rom", 0x000000, 0x400000, CRC(211cf888) SHA1(c5fe0645e48894fb4b245abeefdc9a65d659af59))
849
850   ROM_REGION( 0x800000, "vram", ROMREGION_ERASE00 )
851ROM_END
852
853/***************************************************************************
854
855  Game driver(s)
856
857***************************************************************************/
858
859/*    YEAR  NAME        PARENT  COMPAT  MACHINE     INPUT   INIT    COMPANY FULLNAME        FLAGS */
860COMP( 1995, a7000,      0,      0,      a7000,      a7000,   0,      "Acorn",  "Archimedes A7000",   GAME_NOT_WORKING | GAME_NO_SOUND )
861COMP( 1997, a7000p,     a7000,  0,      a7000p,     a7000,   0,      "Acorn",  "Archimedes A7000+",  GAME_NOT_WORKING | GAME_NO_SOUND )
src/mame/drivers/psx.c
r0r11461
1/***************************************************************************
2
3  Sony Playstaion
4  ===============
5  Preliminary driver by smf
6  Additional development by pSXAuthor and R. Belmont
7
8***************************************************************************/
9
10#include "emu.h"
11#include "cpu/psx/psx.h"
12#include "imagedev/snapquik.h"
13#include "imagedev/chd_cd.h"
14#include "includes/psx.h"
15#include "sound/spu.h"
16#include "debugger.h"
17#include "zlib.h"
18#include "machine/psxcd.h"
19#include "machine/psxcard.h"
20
21typedef struct
22{
23   UINT8 n_shiftin;
24   UINT8 n_shiftout;
25   int n_bits;
26   int n_state;
27   int n_byte;
28   int b_lastclock;
29   int b_ack;
30} pad_t;
31
32
33class psx1_state : public psx_state
34{
35public:
36   psx1_state(const machine_config &mconfig, device_type type, const char *tag)
37      : psx_state(mconfig, type, tag) { }
38
39   UINT8 *m_exe_buffer;
40   int m_exe_size;
41   pad_t m_pad[ 2 ];
42   int m_cd_param_p;
43   int m_cd_result_p;
44   int m_cd_result_c;
45   int m_cd_result_ready;
46   int m_cd_reset;
47   UINT8 m_cd_stat;
48   UINT8 m_cd_io_status;
49   UINT8 m_cd_param[8];
50   UINT8 m_cd_result[8];
51};
52
53
54#define VERBOSE_LEVEL ( 0 )
55
56INLINE void ATTR_PRINTF(3,4) verboselog( running_machine &machine, int n_level, const char *s_fmt, ... )
57{
58   if( VERBOSE_LEVEL >= n_level )
59   {
60      va_list v;
61      char buf[ 32768 ];
62      va_start( v, s_fmt );
63      vsprintf( buf, s_fmt, v );
64      va_end( v );
65      logerror( "%s: %s", machine.describe_context(), buf );
66   }
67}
68
69
70static void psxexe_conv32( UINT32 *p_uint32 )
71{
72   UINT8 *p_uint8;
73
74   p_uint8 = (UINT8 *)p_uint32;
75
76   *( p_uint32 ) = p_uint8[ 0 ] |
77      ( p_uint8[ 1 ] << 8 ) |
78      ( p_uint8[ 2 ] << 16 ) |
79      ( p_uint8[ 3 ] << 24 );
80}
81
82static int load_psxexe( device_t *cpu, unsigned char *p_n_file, int n_len )
83{
84   psx_state *state = cpu->machine().driver_data<psx_state>();
85   struct PSXEXE_HEADER
86   {
87      UINT8 id[ 8 ];
88      UINT32 text;   /* SCE only */
89      UINT32 data;   /* SCE only */
90      UINT32 pc0;
91      UINT32 gp0;      /* SCE only */
92      UINT32 t_addr;
93      UINT32 t_size;
94      UINT32 d_addr;   /* SCE only */
95      UINT32 d_size;   /* SCE only */
96      UINT32 b_addr;   /* SCE only */
97      UINT32 b_size;   /* SCE only */
98      UINT32 s_addr;
99      UINT32 s_size;
100      UINT32 SavedSP;
101      UINT32 SavedFP;
102      UINT32 SavedGP;
103      UINT32 SavedRA;
104      UINT32 SavedS0;
105      UINT8 dummy[ 0x800 - 76 ];
106   };
107
108   struct PSXEXE_HEADER *psxexe_header = (struct PSXEXE_HEADER *)p_n_file;
109
110   if( n_len >= sizeof( struct PSXEXE_HEADER ) &&
111      memcmp( psxexe_header->id, "PS-X EXE", 8 ) == 0 )
112   {
113      UINT8 *p_ram;
114      UINT8 *p_psxexe;
115      UINT32 n_stack;
116      UINT32 n_ram;
117      UINT32 n_address;
118      UINT32 n_size;
119
120      psxexe_conv32( &psxexe_header->text );
121      psxexe_conv32( &psxexe_header->data );
122      psxexe_conv32( &psxexe_header->pc0 );
123      psxexe_conv32( &psxexe_header->gp0 );
124      psxexe_conv32( &psxexe_header->t_addr );
125      psxexe_conv32( &psxexe_header->t_size );
126      psxexe_conv32( &psxexe_header->d_addr );
127      psxexe_conv32( &psxexe_header->d_size );
128      psxexe_conv32( &psxexe_header->b_addr );
129      psxexe_conv32( &psxexe_header->b_size );
130      psxexe_conv32( &psxexe_header->s_addr );
131      psxexe_conv32( &psxexe_header->s_size );
132      psxexe_conv32( &psxexe_header->SavedSP );
133      psxexe_conv32( &psxexe_header->SavedFP );
134      psxexe_conv32( &psxexe_header->SavedGP );
135      psxexe_conv32( &psxexe_header->SavedRA );
136      psxexe_conv32( &psxexe_header->SavedS0 );
137
138      /* todo: check size.. */
139
140      logerror( "psx_exe_load: pc    %08x\n", psxexe_header->pc0 );
141      logerror( "psx_exe_load: org   %08x\n", psxexe_header->t_addr );
142      logerror( "psx_exe_load: len   %08x\n", psxexe_header->t_size );
143      logerror( "psx_exe_load: sp    %08x\n", psxexe_header->s_addr );
144      logerror( "psx_exe_load: len   %08x\n", psxexe_header->s_size );
145
146      p_ram = (UINT8 *)state->m_p_n_psxram;
147      n_ram = state->m_n_psxramsize;
148
149      p_psxexe = p_n_file + sizeof( struct PSXEXE_HEADER );
150
151      n_address = psxexe_header->t_addr;
152      n_size = psxexe_header->t_size;
153      while( n_size != 0 )
154      {
155         p_ram[ BYTE4_XOR_LE( n_address ) % n_ram ] = *( p_psxexe );
156         n_address++;
157         p_psxexe++;
158         n_size--;
159      }
160
161      cpu_set_reg( cpu, PSXCPU_PC, psxexe_header->pc0 );
162      cpu_set_reg( cpu, PSXCPU_R28, psxexe_header->gp0 );
163      n_stack = psxexe_header->s_addr + psxexe_header->s_size;
164      if( n_stack != 0 )
165      {
166         cpu_set_reg( cpu, PSXCPU_R29, n_stack );
167         cpu_set_reg( cpu, PSXCPU_R30, n_stack );
168      }
169
170      return 1;
171   }
172   return 0;
173}
174
175static void cpe_set_register( device_t *cpu, int n_reg, int n_value )
176{
177   if( n_reg < 0x80 && ( n_reg % 4 ) == 0 )
178   {
179      logerror( "psx_exe_load: r%-2d   %08x\n", n_reg / 4, n_value );
180      cpu_set_reg( cpu, PSXCPU_R0 + ( n_reg / 4 ), n_value );
181   }
182   else if( n_reg == 0x80 )
183   {
184      logerror( "psx_exe_load: lo    %08x\n", n_value );
185      cpu_set_reg( cpu, PSXCPU_LO, n_value );
186   }
187   else if( n_reg == 0x84 )
188   {
189      logerror( "psx_exe_load: hi    %08x\n", n_value );
190      cpu_set_reg( cpu, PSXCPU_HI, n_value );
191   }
192   else if( n_reg == 0x88 )
193   {
194      logerror( "psx_exe_load: sr    %08x\n", n_value );
195      cpu_set_reg( cpu, PSXCPU_CP0R12, n_value );
196   }
197   else if( n_reg == 0x8c )
198   {
199      logerror( "psx_exe_load: cause %08x\n", n_value );
200      cpu_set_reg( cpu, PSXCPU_CP0R13, n_value );
201   }
202   else if( n_reg == 0x90 )
203   {
204      logerror( "psx_exe_load: pc    %08x\n", n_value );
205      cpu_set_reg( cpu, PSXCPU_PC, n_value );
206   }
207   else if( n_reg == 0x94 )
208   {
209      logerror( "psx_exe_load: prid  %08x\n", n_value );
210      cpu_set_reg( cpu, PSXCPU_CP0R15, n_value );
211   }
212   else
213   {
214      logerror( "psx_exe_load: invalid register %04x/%08x\n", n_reg, n_value );
215   }
216}
217
218static int load_cpe( device_t *cpu, unsigned char *p_n_file, int n_len )
219{
220   psx_state *state = cpu->machine().driver_data<psx_state>();
221   if( n_len >= 4 &&
222      memcmp( p_n_file, "CPE\001", 4 ) == 0 )
223   {
224      int n_offset = 4;
225
226      for( ;; )
227      {
228         if( n_offset >= n_len || p_n_file[ n_offset ] > 8 )
229         {
230            break;
231         }
232
233         switch( p_n_file[ n_offset++ ] )
234         {
235         case 0:
236            /* end of file */
237            return 1;
238         case 1:
239            /* read bytes */
240            {
241               int n_address = ( (int)p_n_file[ n_offset + 0 ] << 0 ) |
242                  ( (int)p_n_file[ n_offset + 1 ] << 8 ) |
243                  ( (int)p_n_file[ n_offset + 2 ] << 16 ) |
244                  ( (int)p_n_file[ n_offset + 3 ] << 24 );
245               int n_size = ( (int)p_n_file[ n_offset + 4 ] << 0 ) |
246                  ( (int)p_n_file[ n_offset + 5 ] << 8 ) |
247                  ( (int)p_n_file[ n_offset + 6 ] << 16 ) |
248                  ( (int)p_n_file[ n_offset + 7 ] << 24 );
249
250               UINT8 *p_ram = (UINT8 *)state->m_p_n_psxram;
251               UINT32 n_ram = state->m_n_psxramsize;
252
253               n_offset += 8;
254
255               logerror( "psx_exe_load: org   %08x\n", n_address );
256               logerror( "psx_exe_load: len   %08x\n", n_size );
257
258               while( n_size > 0 )
259               {
260                  p_ram[ BYTE4_XOR_LE( n_address ) % n_ram ] = p_n_file[ n_offset++ ];
261                  n_address++;
262                  n_size--;
263               }
264               break;
265            }
266         case 2:
267            /* run address: not tested */
268            {
269               int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ) |
270                  ( (int)p_n_file[ n_offset + 3 ] << 8 ) |
271                  ( (int)p_n_file[ n_offset + 4 ] << 16 ) |
272                  ( (int)p_n_file[ n_offset + 5 ] << 24 );
273
274               n_offset += 4;
275
276               cpe_set_register( cpu, 0x90, n_value );
277               break;
278            }
279         case 3:
280            /* set reg to longword */
281            {
282               int n_reg = ( (int)p_n_file[ n_offset + 0 ] << 0 ) |
283                  ( (int)p_n_file[ n_offset + 1 ] << 8 );
284               int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ) |
285                  ( (int)p_n_file[ n_offset + 3 ] << 8 ) |
286                  ( (int)p_n_file[ n_offset + 4 ] << 16 ) |
287                  ( (int)p_n_file[ n_offset + 5 ] << 24 );
288
289               n_offset += 6;
290
291               cpe_set_register( cpu, n_reg, n_value );
292               break;
293            }
294         case 4:
295            /* set reg to word: not tested */
296            {
297               int n_reg = ( (int)p_n_file[ n_offset + 0 ] << 0 ) |
298                  ( (int)p_n_file[ n_offset + 1 ] << 8 );
299               int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ) |
300                  ( (int)p_n_file[ n_offset + 3 ] << 8 );
301
302               n_offset += 4;
303
304               cpe_set_register( cpu, n_reg, n_value );
305               break;
306            }
307         case 5:
308            /* set reg to byte: not tested */
309            {
310               int n_reg = ( (int)p_n_file[ n_offset + 0 ] << 0 ) |
311                  ( (int)p_n_file[ n_offset + 1 ] << 8 );
312               int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 );
313
314               n_offset += 3;
315
316               cpe_set_register( cpu, n_reg, n_value );
317               break;
318            }
319         case 6:
320            /* set reg to 3-byte: not tested */
321            {
322               int n_reg = ( (int)p_n_file[ n_offset + 0 ] << 0 ) |
323                  ( (int)p_n_file[ n_offset + 1 ] << 8 );
324               int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ) |
325                  ( (int)p_n_file[ n_offset + 3 ] << 8 ) |
326                  ( (int)p_n_file[ n_offset + 4 ] << 16 );
327
328               n_offset += 5;
329
330               cpe_set_register( cpu, n_reg, n_value );
331               break;
332            }
333         case 7:
334            /* workspace: not tested */
335            n_offset += 4;
336            break;
337         case 8:
338            /* unit */
339            {
340               int n_unit = p_n_file[ n_offset + 0 ];
341
342               n_offset++;
343
344               logerror( "psx_exe_load: unit  %08x\n", n_unit );
345            }
346            break;
347         }
348      }
349   }
350   return 0;
351}
352
353static int load_psf( device_t *cpu, unsigned char *p_n_file, int n_len )
354{
355   int n_return;
356   unsigned long n_crc;
357   unsigned long n_compressed;
358   unsigned char *p_n_compressed;
359   unsigned long n_uncompressed;
360   unsigned char *p_n_uncompressed;
361
362   struct PSF_HEADER
363   {
364      unsigned char id[ 4 ];
365      UINT32 reserved_size;
366      UINT32 exe_size;
367      UINT32 exe_crc;
368   };
369
370   struct PSF_HEADER *psf_header = (struct PSF_HEADER *)p_n_file;
371
372   n_return = 0;
373
374   if( n_len >= sizeof( struct PSF_HEADER ) &&
375      memcmp( p_n_file, "PSF", 3 ) == 0 )
376   {
377      psxexe_conv32( &psf_header->reserved_size );
378      psxexe_conv32( &psf_header->exe_size );
379      psxexe_conv32( &psf_header->exe_crc );
380
381      logerror( "psx_exe_load: reserved_size %08x\n", psf_header->reserved_size );
382      logerror( "psx_exe_load: exe_size      %08x\n", psf_header->exe_size );
383      logerror( "psx_exe_load: exe_crc       %08x\n", psf_header->exe_crc );
384
385      n_compressed = psf_header->exe_size;
386      p_n_compressed = p_n_file + sizeof( struct PSF_HEADER ) + psf_header->reserved_size;
387
388      n_crc = crc32( crc32( 0L, Z_NULL, 0 ), p_n_compressed, n_compressed );
389      if( n_crc != psf_header->exe_crc )
390      {
391         logerror( "psx_exe_load: psf invalid crc\n" );
392         return 0;
393      }
394
395      n_uncompressed = 0x200000;
396      p_n_uncompressed = (unsigned char *)malloc( n_uncompressed );
397
398      if( uncompress( p_n_uncompressed, &n_uncompressed, p_n_compressed, n_compressed ) != Z_OK )
399      {
400         logerror( "psx_exe_load: psf uncompress failed\n" );
401      }
402      else if( !load_psxexe( cpu, p_n_uncompressed, n_uncompressed ) )
403      {
404         logerror( "psx_exe_load: psf load failed\n" );
405      }
406      else
407      {
408         n_return = 1;
409      }
410
411      free( p_n_uncompressed );
412   }
413   return n_return;
414}
415
416DIRECT_UPDATE_HANDLER( psx_default )
417{
418   return address;
419}
420
421DIRECT_UPDATE_HANDLER( psx_setopbase )
422{
423   psx1_state *state = machine.driver_data<psx1_state>();
424   if( address == 0x80030000 )
425   {
426      device_t *cpu = machine.device("maincpu");
427
428      machine.device("maincpu")->memory().space(AS_PROGRAM)->set_direct_update_handler(direct_update_delegate(FUNC(psx_default), &machine));
429
430      if( load_psxexe( cpu, state->m_exe_buffer, state->m_exe_size ) ||
431         load_cpe( cpu, state->m_exe_buffer, state->m_exe_size ) ||
432         load_psf( cpu, state->m_exe_buffer, state->m_exe_size ) )
433      {
434/*          DEBUGGER_BREAK; */
435
436         address = cpu_get_reg( cpu, PSXCPU_PC );
437      }
438      else
439      {
440         logerror( "psx_exe_load: invalid exe\n" );
441      }
442
443      state->m_exe_size = 0;
444      free( state->m_exe_buffer );
445   }
446   return address;
447}
448
449static QUICKLOAD_LOAD( psx_exe_load )
450{
451   psx1_state *state = image.device().machine().driver_data<psx1_state>();
452   address_space *space = image.device().machine().device( "maincpu")->memory().space( AS_PROGRAM );
453
454   state->m_exe_size = 0;
455   state->m_exe_buffer = (UINT8*)malloc( quickload_size );
456   if( state->m_exe_buffer == NULL )
457   {
458      logerror( "psx_exe_load: out of memory\n" );
459      return IMAGE_INIT_FAIL;
460   }
461   if( image.fread( state->m_exe_buffer, quickload_size ) != quickload_size )
462   {
463      free( state->m_exe_buffer );
464      return IMAGE_INIT_FAIL;
465   }
466   state->m_exe_size = quickload_size;
467   space->set_direct_update_handler(direct_update_delegate(FUNC(psx_setopbase), &image.device().machine()));
468
469   return IMAGE_INIT_PASS;
470}
471
472/* PAD emulation */
473
474#define PAD_STATE_IDLE ( 0 )
475#define PAD_STATE_LISTEN ( 1 )
476#define PAD_STATE_ACTIVE ( 2 )
477#define PAD_STATE_READ ( 3 )
478#define PAD_STATE_UNLISTEN ( 4 )
479#define PAD_STATE_MEMCARD ( 5 )
480
481#define PAD_TYPE_STANDARD ( 4 )
482#define PAD_BYTES_STANDARD ( 2 )
483
484#define PAD_CMD_START ( 0x01 )
485#define PAD_CMD_READ  ( 0x42 ) /* B */
486
487#define PAD_DATA_OK   ( 0x5a ) /* Z */
488#define PAD_DATA_IDLE ( 0xff )
489
490static TIMER_CALLBACK(psx_pad_ack)
491{
492   psx1_state *state = machine.driver_data<psx1_state>();
493   int n_port = param;
494   pad_t *pad = &state->m_pad[ n_port ];
495
496   if( pad->n_state != PAD_STATE_IDLE )
497   {
498      psx_sio_input( machine, 0, PSX_SIO_IN_DSR, pad->b_ack * PSX_SIO_IN_DSR );
499      if( !pad->b_ack )
500      {
501         pad->b_ack = 1;
502         machine.scheduler().timer_set(attotime::from_usec( 2 ), FUNC(psx_pad_ack) , n_port);
503      }
504   }
505}
506
507static void psx_pad( running_machine &machine, int n_port, int n_data )
508{
509   psx1_state *state = machine.driver_data<psx1_state>();
510   pad_t *pad = &state->m_pad[ n_port ];
511   int b_sel;
512   int b_clock;
513   int b_data;
514   int b_ack;
515   int b_ready;
516   static const char *const portnames[] = { "IN0", "IN1", "IN2", "IN3" };
517   psxcard_device *psxcard = NULL;
518
519   if (n_port == 0)
520   {
521      psxcard = machine.device<psxcard_device>("card1");
522   }
523   else
524   {
525      psxcard = machine.device<psxcard_device>("card2");
526   }
527
528   b_sel = ( n_data & PSX_SIO_OUT_DTR ) / PSX_SIO_OUT_DTR;
529   b_clock = ( n_data & PSX_SIO_OUT_CLOCK ) / PSX_SIO_OUT_CLOCK;
530   b_data = ( n_data & PSX_SIO_OUT_DATA ) / PSX_SIO_OUT_DATA;
531   b_ready = 0;
532   b_ack = 0;
533
534   if( b_sel )
535   {
536      pad->n_state = PAD_STATE_IDLE;
537   }
538
539   switch( pad->n_state )
540   {
541   case PAD_STATE_LISTEN:
542   case PAD_STATE_ACTIVE:
543   case PAD_STATE_READ:
544   case PAD_STATE_MEMCARD:
545      if( pad->b_lastclock && !b_clock )
546      {
547         psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( pad->n_shiftout & 1 ) * PSX_SIO_IN_DATA );
548         pad->n_shiftout >>= 1;
549      }
550      if( !pad->b_lastclock && b_clock )
551      {
552         pad->n_shiftin >>= 1;
553         pad->n_shiftin |= b_data << 7;
554         pad->n_bits++;
555
556         if( pad->n_bits == 8 )
557         {
558            pad->n_bits = 0;
559            b_ready = 1;
560         }
561      }
562      break;
563   }
564
565   pad->b_lastclock = b_clock;
566
567   switch( pad->n_state )
568   {
569   case PAD_STATE_IDLE:
570      if( !b_sel )
571      {
572         pad->n_state = PAD_STATE_LISTEN;
573         pad->n_shiftout = PAD_DATA_IDLE;
574         pad->n_bits = 0;
575      }
576      break;
577   case PAD_STATE_LISTEN:
578      if( b_ready )
579      {
580         if( pad->n_shiftin == PAD_CMD_START )
581         {
582            pad->n_state = PAD_STATE_ACTIVE;
583            pad->n_shiftout = ( PAD_TYPE_STANDARD << 4 ) | ( PAD_BYTES_STANDARD >> 1 );
584            b_ack = 1;
585         }
586         else if( psxcard->transfer(pad->n_shiftin, &pad->n_shiftout) )
587         {
588            pad->n_state = PAD_STATE_MEMCARD;
589            b_ack = 1;
590         }
591         else
592         {
593            pad->n_state = PAD_STATE_UNLISTEN;
594         }
595      }
596      break;
597   case PAD_STATE_MEMCARD:
598      if( b_ready )
599      {
600         if( psxcard->transfer(pad->n_shiftin, &pad->n_shiftout) )
601         {
602            b_ack = 1;
603         }
604         else
605         {
606            b_ack = 0;
607            pad->n_state = PAD_STATE_IDLE;
608         }
609      }
610      break;
611   case PAD_STATE_ACTIVE:
612      if( b_ready )
613      {
614         if( pad->n_shiftin == PAD_CMD_READ )
615         {
616            pad->n_state = PAD_STATE_READ;
617            pad->n_shiftout = PAD_DATA_OK;
618            pad->n_byte = 0;
619            b_ack = 1;
620         }
621         else
622         {
623            pad->n_state = PAD_STATE_UNLISTEN;
624         }
625      }
626      break;
627   case PAD_STATE_READ:
628      if( b_ready )
629      {
630         if( pad->n_byte < PAD_BYTES_STANDARD )
631         {
632            pad->n_shiftout = input_port_read(machine, portnames[pad->n_byte + ( n_port * PAD_BYTES_STANDARD )]);
633            pad->n_byte++;
634            b_ack = 1;
635         }
636         else
637         {
638            pad->n_state = PAD_STATE_LISTEN;
639         }
640      }
641      break;
642   }
643
644   if( b_ack )
645   {
646      pad->b_ack = 0;
647      machine.scheduler().timer_set(attotime::from_usec( 10 ), FUNC(psx_pad_ack), n_port);
648   }
649}
650
651static void psx_sio0( running_machine &machine, int n_data )
652{
653   /* todo: raise data & ack when nothing is driving it low */
654   psx_pad( machine, 0, n_data );
655   psx_pad( machine, 1, n_data ^ PSX_SIO_OUT_DTR );
656}
657
658/* ----------------------------------------------------------------------- */
659
660static void cd_dma_read( running_machine &machine, UINT32 n_address, INT32 n_size )
661{
662   psxcd_device *psxcd = machine.device<psxcd_device>("psxcd");
663   UINT8 *psxram = (UINT8 *)memory_get_shared(machine, "share1");
664
665   psxcd->start_dma(psxram + n_address, n_size*4);
666}
667
668static void cd_dma_write( running_machine &machine, UINT32 n_address, INT32 n_size )
669{
670   printf("cd_dma_write?!: addr %x, size %x\n", n_address, n_size);
671}
672
673static READ8_HANDLER( psx_cd_r )
674{
675   psxcd_device *psxcd = space->machine().device<psxcd_device>(PSXCD_TAG);
676
677   return psxcd->read_byte(offset);
678}
679
680static WRITE8_HANDLER( psx_cd_w )
681{
682   psxcd_device *psxcd = space->machine().device<psxcd_device>(PSXCD_TAG);
683
684   psxcd->write_byte(offset, data);
685}
686
687static ADDRESS_MAP_START( psx_map, AS_PROGRAM, 32 )
688   AM_RANGE(0x00000000, 0x001fffff) AM_RAM   AM_SHARE("share1") /* ram */
689   AM_RANGE(0x1f801800, 0x1f801803) AM_READWRITE8(psx_cd_r, psx_cd_w, 0xffffffff)
690   AM_RANGE(0x1fc00000, 0x1fc7ffff) AM_ROM AM_SHARE("share2") AM_REGION("user1", 0) /* bios */
691   AM_RANGE(0x80000000, 0x801fffff) AM_RAM AM_SHARE("share1") /* ram mirror */
692   AM_RANGE(0x80600000, 0x807fffff) AM_RAM AM_SHARE("share1") /* ram mirror */
693   AM_RANGE(0x9fc00000, 0x9fc7ffff) AM_ROM AM_SHARE("share2") /* bios mirror */
694   AM_RANGE(0xa0000000, 0xa01fffff) AM_RAM AM_SHARE("share1") /* ram mirror */
695   AM_RANGE(0xbfc00000, 0xbfc7ffff) AM_ROM AM_SHARE("share2") /* bios mirror */
696   AM_RANGE(0xfffe0130, 0xfffe0133) AM_WRITENOP
697ADDRESS_MAP_END
698
699
700static MACHINE_RESET( psx )
701{
702   psx_machine_init(machine);
703   psx_sio_install_handler( machine, 0, psx_sio0 );
704
705   psx_dma_install_read_handler(machine, 3, cd_dma_read);
706   psx_dma_install_write_handler(machine, 3, cd_dma_write);
707}
708
709static DRIVER_INIT( psx )
710{
711   psx_driver_init(machine);
712}
713
714static INPUT_PORTS_START( psx )
715   PORT_START("IN0")
716   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT )  PORT_PLAYER(1)
717   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN )  PORT_PLAYER(1)
718   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
719   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP )   PORT_PLAYER(1)
720   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START )  PORT_PLAYER(1)
721   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(1)
722   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(1)
723   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SELECT ) PORT_PLAYER(1)
724
725   PORT_START("IN1")
726   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("P1 Square")
727   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("P1 Cross")
728   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_NAME("P1 Circle")
729   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_NAME("P1 Triangle")
730   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(1) PORT_NAME("P1 R1")
731   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(1) PORT_NAME("P1 L1")
732   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_PLAYER(1) PORT_NAME("P1 R2")
733   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_PLAYER(1) PORT_NAME("P1 L2")
734
735   PORT_START("IN2")
736   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT )  PORT_PLAYER(2)
737   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN )  PORT_PLAYER(2)
738   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
739   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP )   PORT_PLAYER(2)
740   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START )  PORT_PLAYER(2)
741   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(2)
742   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(2)
743   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SELECT ) PORT_PLAYER(2)
744
745   PORT_START("IN3")
746   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_NAME("P2 Square")
747   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_NAME("P2 Cross")
748   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_NAME("P2 Circle")
749   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) PORT_NAME("P2 Triangle")
750   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(2) PORT_NAME("P2 R1")
751   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(2) PORT_NAME("P2 L1")
752   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_PLAYER(2) PORT_NAME("P2 R2")
753   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_PLAYER(2) PORT_NAME("P2 L2")
754INPUT_PORTS_END
755
756static void spu_irq(device_t *device, UINT32 data)
757{
758   if (data)
759   {
760      psx_irq_set(device->machine(), 1<<9);
761   }
762}
763
764static MACHINE_CONFIG_START( psxntsc, psx1_state )
765   /* basic machine hardware */
766   MCFG_CPU_ADD( "maincpu", CXD8530AQ, XTAL_67_7376MHz )
767   MCFG_CPU_PROGRAM_MAP( psx_map)
768   MCFG_CPU_VBLANK_INT("screen", psx_vblank)
769
770   MCFG_SCREEN_ADD("screen", RASTER)
771   MCFG_SCREEN_REFRESH_RATE( 60 )
772   MCFG_SCREEN_VBLANK_TIME(0)
773
774   MCFG_MACHINE_RESET( psx )
775
776   /* video hardware */
777   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
778   MCFG_SCREEN_SIZE( 1024, 512 )
779   MCFG_SCREEN_VISIBLE_AREA( 0, 639, 0, 479 )
780   MCFG_SCREEN_UPDATE( psx )
781
782   MCFG_PALETTE_LENGTH( 65536 )
783
784   MCFG_PALETTE_INIT( psx )
785   MCFG_VIDEO_START( psx_type2 )
786
787   /* sound hardware */
788   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
789   MCFG_SPU_ADD( "spu", XTAL_67_7376MHz/2, &spu_irq )
790   MCFG_SOUND_ROUTE( 0, "lspeaker", 1.00 )
791   MCFG_SOUND_ROUTE( 1, "rspeaker", 1.00 )
792
793   /* quickload */
794   MCFG_QUICKLOAD_ADD("quickload", psx_exe_load, "cpe,exe,psf,psx", 0)
795
796   MCFG_CDROM_ADD("cdrom")
797   MCFG_PSXCD_ADD("cdrom")
798   MCFG_PSXCARD_ADD("card1")
799   MCFG_PSXCARD_ADD("card2")
800MACHINE_CONFIG_END
801
802static MACHINE_CONFIG_START( psxpal, psx1_state )
803   /* basic machine hardware */
804   MCFG_CPU_ADD( "maincpu", CXD8530AQ, XTAL_67_7376MHz )
805   MCFG_CPU_PROGRAM_MAP( psx_map)
806   MCFG_CPU_VBLANK_INT("screen", psx_vblank)
807
808   MCFG_SCREEN_ADD("screen", RASTER)
809   MCFG_SCREEN_REFRESH_RATE( 50 )
810   MCFG_SCREEN_VBLANK_TIME(0)
811
812   MCFG_MACHINE_RESET( psx )
813
814   /* video hardware */
815   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
816   MCFG_SCREEN_SIZE( 1024, 512 )
817   MCFG_SCREEN_VISIBLE_AREA( 0, 639, 0, 511 )
818   MCFG_SCREEN_UPDATE( psx )
819   MCFG_PALETTE_LENGTH( 65536 )
820
821   MCFG_PALETTE_INIT( psx )
822   MCFG_VIDEO_START( psx_type2 )
823
824   /* sound hardware */
825   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
826   MCFG_SPU_ADD( "spu", XTAL_67_7376MHz/2, &spu_irq )
827   MCFG_SOUND_ROUTE( 0, "lspeaker", 1.00 )
828   MCFG_SOUND_ROUTE( 1, "rspeaker", 1.00 )
829
830   /* quickload */
831   MCFG_QUICKLOAD_ADD("quickload", psx_exe_load, "cpe,exe,psf,psx", 0)
832
833   MCFG_CDROM_ADD("cdrom")
834   MCFG_PSXCD_ADD("cdrom")
835   MCFG_PSXCARD_ADD("card1")
836   MCFG_PSXCARD_ADD("card2")
837MACHINE_CONFIG_END
838
839ROM_START( psj )
840   ROM_REGION32_LE( 0x080000, "user1", 0 )
841
842   ROM_SYSTEM_BIOS( 0, "1.0J", "SCPH-1000/DTL-H1000" ) // 22091994
843   ROMX_LOAD( "ps-10j.bin",    0x0000000, 0x080000, CRC(3b601fc8) SHA1(343883a7b555646da8cee54aadd2795b6e7dd070), ROM_BIOS(1) )
844
845   ROM_SYSTEM_BIOS( 1, "1.1J", "SCPH-3000/DTL-H1000H (Version 1.1 01/22/95)" ) // 22091994
846   ROMX_LOAD( "ps-11j.bin",    0x0000000, 0x080000, CRC(3539def6) SHA1(b06f4a861f74270be819aa2a07db8d0563a7cc4e), ROM_BIOS(2) )
847
848   ROM_SYSTEM_BIOS( 2, "2.1J", "SCPH-3500 (Version 2.1 07/17/95 J)" ) // 22091994
849   ROMX_LOAD( "ps-21j.bin",    0x0000000, 0x080000, CRC(bc190209) SHA1(e38466a4ba8005fba7e9e3c7b9efeba7205bee3f), ROM_BIOS(3) )
850
851   ROM_SYSTEM_BIOS( 3, "2.2J", "SCPH-5000/DTL-H1200 (Version 2.2 12/04/95 J)" ) // 04121995
852/*  ROMX_LOAD( "ps-22j.bad",    0x0000000, 0x080000, BAD_DUMP CRC(8c93a399) SHA1(e340db2696274dda5fdc25e434a914db71e8b02b), ROM_BIOS(4) ) */
853   ROMX_LOAD( "ps-22j.bin",    0x0000000, 0x080000, CRC(24fc7e17) SHA1(ffa7f9a7fb19d773a0c3985a541c8e5623d2c30d), ROM_BIOS(4) )
854
855   ROM_SYSTEM_BIOS( 4, "2.2D", "DTL-H1100 (Version 2.2 03/06/96 D)" ) // 04121995
856   ROMX_LOAD( "ps-22d.bin",    0x0000000, 0x080000, CRC(decb22f5) SHA1(73107d468fc7cb1d2c5b18b269715dd889ecef06), ROM_BIOS(5) )
857
858   ROM_SYSTEM_BIOS( 5, "3.0J", "SCPH-5500 (Version 3.0 09/09/96 J)" ) // 04121995
859   ROMX_LOAD( "ps-30j.bin",    0x0000000, 0x080000, CRC(ff3eeb8c) SHA1(b05def971d8ec59f346f2d9ac21fb742e3eb6917), ROM_BIOS(6) )
860
861   ROM_SYSTEM_BIOS( 6, "4.0J", "SCPH-7000/SCPH-9000 (Version 4.0 08/18/97 J)" ) // 29051997
862   ROMX_LOAD( "ps-40j.bin",    0x0000000, 0x080000, CRC(ec541cd0) SHA1(77b10118d21ac7ffa9b35f9c4fd814da240eb3e9), ROM_BIOS(7) )
863
864   ROM_SYSTEM_BIOS( 7, "4.3J", "SCPH-100 (Version 4.3 03/11/00 J)" ) // 04121995
865   ROMX_LOAD( "psone-43j.bin", 0x0000000, 0x080000, CRC(f2af798b) SHA1(339a48f4fcf63e10b5b867b8c93cfd40945faf6c), ROM_BIOS(8) )
866ROM_END
867
868ROM_START( psu )
869   ROM_REGION32_LE( 0x080000, "user1", 0 )
870
871   ROM_SYSTEM_BIOS( 0, "2.0A", "DTL-H1001 (Version 2.0 05/07/95 A)" ) // 22091994
872   ROMX_LOAD( "ps-20a.bin",    0x0000000, 0x080000, CRC(55847d8c) SHA1(649895efd79d14790eabb362e94eb0622093dfb9), ROM_BIOS(1) )
873
874   ROM_SYSTEM_BIOS( 1, "2.1A", "DTL-H1101 (Version 2.1 07/17/95 A)" ) // 22091994
875   ROMX_LOAD( "ps-21a.bin",    0x0000000, 0x080000, CRC(aff00f2f) SHA1(ca7af30b50d9756cbd764640126c454cff658479), ROM_BIOS(2) )
876
877   ROM_SYSTEM_BIOS( 2, "2.2A", "SCPH-1001/DTL-H1201/DTL-H3001 (Version 2.2 12/04/95 A)" ) // 04121995
878   ROMX_LOAD( "ps-22a.bin",    0x0000000, 0x080000, CRC(37157331) SHA1(10155d8d6e6e832d6ea66db9bc098321fb5e8ebf), ROM_BIOS(3) )
879
880   ROM_SYSTEM_BIOS( 3, "3.0A", "SCPH-5501/SCPH-7003 (Version 3.0 11/18/96 A)" ) // 04121995
881   ROMX_LOAD( "ps-30a.bin",    0x0000000, 0x080000, CRC(8d8cb7e4) SHA1(0555c6fae8906f3f09baf5988f00e55f88e9f30b), ROM_BIOS(4) )
882
883   ROM_SYSTEM_BIOS( 4, "4.1A", "SCPH-7001/SCPH-7501/SCPH-7503/SCPH-9001 (Version 4.1 12/16/97 A)" ) // 04121995
884   ROMX_LOAD( "ps-41a.bin",    0x0000000, 0x080000, CRC(502224b6) SHA1(14df4f6c1e367ce097c11deae21566b4fe5647a9), ROM_BIOS(5) )
885
886   ROM_SYSTEM_BIOS( 5, "4.5A", "SCPH-101 (Version 4.5 05/25/00 A)" ) // 04121995
887   ROMX_LOAD( "psone-45a.bin", 0x0000000, 0x080000, CRC(171bdcec) SHA1(dcffe16bd90a723499ad46c641424981338d8378), ROM_BIOS(6) )
888ROM_END
889
890ROM_START( pse )
891   ROM_REGION32_LE( 0x080000, "user1", 0 )
892
893   ROM_SYSTEM_BIOS( 0, "2.0E", "DTL-H1002/SCPH-1002 (Version 2.0 05/10/95 E)" ) // 22091994
894   ROMX_LOAD( "ps-20e.bin",    0x0000000, 0x080000, CRC(9bb87c4b) SHA1(20b98f3d80f11cbf5a7bfd0779b0e63760ecc62c), ROM_BIOS(1) )
895
896   ROM_SYSTEM_BIOS( 1, "2.1E", "SCPH-1002/DTL-H1102 (Version 2.1 07/17/95 E)" ) // 22091994
897   ROMX_LOAD( "ps-21e.bin",    0x0000000, 0x080000, CRC(86c30531) SHA1(76cf6b1b2a7c571a6ad07f2bac0db6cd8f71e2cc), ROM_BIOS(2) )
898
899   ROM_SYSTEM_BIOS( 2, "2.2E", "SCPH-1002/DTL-H1202/DTL-H3002 (Version 2.2 12/04/95 E)" ) // 04121995
900   ROMX_LOAD( "ps-22e.bin",    0x0000000, 0x080000, CRC(1e26792f) SHA1(b6a11579caef3875504fcf3831b8e3922746df2c), ROM_BIOS(3) )
901
902   ROM_SYSTEM_BIOS( 3, "3.0E", "SCPH-5502/SCPH-5552 (Version 3.0 01/06/97 E)" ) // 04121995
903/*  ROMX_LOAD( "ps-30e.bad",    0x0000000, 0x080000, BAD_DUMP CRC(4d9e7c86) SHA1(f8de9325fc36fcfa4b29124d291c9251094f2e54), ROM_BIOS(4) ) */
904   ROMX_LOAD( "ps-30e.bin",    0x0000000, 0x080000, CRC(d786f0b9) SHA1(f6bc2d1f5eb6593de7d089c425ac681d6fffd3f0), ROM_BIOS(4) )
905
906   ROM_SYSTEM_BIOS( 4, "4.1E", "SCPH-7002/SCPH-7502/SCPH-9002 (Version 4.1 12/16/97 E)" ) // 04121995
907   ROMX_LOAD( "ps-41e.bin",    0x0000000, 0x080000, CRC(318178bf) SHA1(8d5de56a79954f29e9006929ba3fed9b6a418c1d), ROM_BIOS(5) )
908
909   ROM_SYSTEM_BIOS( 5, "4.4E", "SCPH-102 (Version 4.4 03/24/00 E)" ) // 04121995
910   ROMX_LOAD( "psone-44e.bin", 0x0000000, 0x080000, CRC(0bad7ea9) SHA1(beb0ac693c0dc26daf5665b3314db81480fa5c7c), ROM_BIOS(6) )
911
912   ROM_SYSTEM_BIOS( 6, "4.5E", "SCPH-102 (Version 4.5 05/25/00 E)" ) // 04121995
913   ROMX_LOAD( "psone-45e.bin", 0x0000000, 0x080000, CRC(76b880e5) SHA1(dbc7339e5d85827c095764fc077b41f78fd2ecae), ROM_BIOS(7) )
914ROM_END
915
916ROM_START( psa )
917   ROM_REGION32_LE( 0x080000, "user1", 0 )
918
919   ROM_SYSTEM_BIOS( 0, "3.0A", "SCPH-5501/SCPH-7003 (Version 3.0 11/18/96 A)" ) // 04121995
920   ROMX_LOAD( "ps-30a.bin",    0x0000000, 0x080000, CRC(8d8cb7e4) SHA1(0555c6fae8906f3f09baf5988f00e55f88e9f30b), ROM_BIOS(1) )
921
922   ROM_SYSTEM_BIOS( 1, "4.1A", "SCPH-7001/SCPH-7501/SCPH-7503/SCPH-9001 (Version 4.1 12/16/97 A)" ) // 04121995
923   ROMX_LOAD( "ps-41a.bin",    0x0000000, 0x080000, CRC(502224b6) SHA1(14df4f6c1e367ce097c11deae21566b4fe5647a9), ROM_BIOS(2) )
924ROM_END
925
926/*
927The version number & release date is stored in ascii text at the end of every bios, except for scph1000.
928There is also a BCD encoded date at offset 0x100, but this is set to 22091994 for versions prior to 2.2
929and 04121995 for all versions from 2.2 ( except Version 4.0J which is 29051997 ).
930
931Consoles not dumped:
932
933DTL-H1001H
934DTL-H3000
935SCPH-5001
936SCPH-5002
937SCPH-5003
938SCPH-5503
939SCPH-7500
940SCPH-9003
941SCPH-103
942
943Holes in version numbers:
944
945Version 2.0 J
946Version 4.1 J
947Version 4.2 J
948Version 4.4 J
949Version 4.5 J
950Version 4.0 A
951Version 4.2 A
952Version 4.3 A
953Version 4.4 A
954Version 4.0 E
955Version 4.2 E
956Version 4.3 E
957
958*/
959
960/*    YEAR  NAME    PARENT  COMPAT  MACHINE     INPUT   INIT    COMPANY                             FULLNAME                            FLAGS */
961CONS( 1994, psj,    0,      0,      psxntsc,    psx,    psx,    "Sony Computer Entertainment Inc", "Sony PlayStation (Japan)",         GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
962CONS( 1995, pse,    psj,    0,      psxpal,     psx,    psx,    "Sony Computer Entertainment Inc", "Sony PlayStation (Europe)",        GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
963CONS( 1995, psu,    psj,    0,      psxntsc,    psx,    psx,    "Sony Computer Entertainment Inc", "Sony PlayStation (USA)",           GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
964CONS( 1995, psa,    psj,    0,      psxntsc,    psx,    psx,    "Sony Computer Entertainment Inc", "Sony PlayStation (Asia-Pacific)",  GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
src/mame/drivers/ami1200.c
r0r11461
1/*
2    Amiga 1200
3
4    Preliminary MAME driver by Mariusz Wojcieszek
5    CD-ROM controller by Ernesto Corvi
6    Borrowed by incog for MESS
7
8    2009-05 Fabio Priuli:
9    Amiga 1200 support is just sketched (I basically took cd32 and removed Akiko). I connected
10    the floppy drive in the same way as in amiga.c but it seems to be not working, since I
11    tried to load WB3.1 with no success. However, this problem may be due to anything: maybe
12    the floppy code must be connected elsewhere, or the .adf image is broken, or I made some
13    stupid mistake in the CIA interfaces.
14    Later, it could be wise to re-factor this source and merge the non-AGA code with
15    mess/drivers/amiga.c
16*/
17
18#include "emu.h"
19#include "cpu/m68000/m68000.h"
20#include "machine/6526cia.h"
21#include "machine/i2cmem.h"
22#include "machine/amigafdc.h"
23#include "machine/amigakbd.h"
24
25#include "includes/amiga.h"
26#include "includes/cd32.h"
27
28
29
30class ami1200_state : public cd32_state
31{
32public:
33   ami1200_state(const machine_config &mconfig, device_type type, const char *tag)
34      : cd32_state(mconfig, type, tag) { }
35
36   UINT16 potgo_value;
37   int cd32_shifter[2];
38   int oldstate[2];
39};
40
41
42
43#define A1200PAL_XTAL_X1  XTAL_28_37516MHz
44#define A1200PAL_XTAL_X2  XTAL_4_433619MHz
45
46
47
48static void handle_cd32_joystick_cia(ami1200_state *state, UINT8 pra, UINT8 dra);
49
50static WRITE32_HANDLER( aga_overlay_w )
51{
52   if (ACCESSING_BITS_16_23)
53   {
54      data = (data >> 16) & 1;
55
56      /* switch banks as appropriate */
57      memory_set_bank(space->machine(), "bank1", data & 1);
58
59      /* swap the write handlers between ROM and bank 1 based on the bit */
60      if ((data & 1) == 0)
61         /* overlay disabled, map RAM on 0x000000 */
62         space->install_write_bank(0x000000, 0x1fffff, "bank1");
63      else
64         /* overlay enabled, map Amiga system ROM on 0x000000 */
65         space->unmap_write(0x000000, 0x1fffff);
66   }
67}
68
69/*************************************
70 *
71 *  CIA-A port A access:
72 *
73 *  PA7 = game port 1, pin 6 (fire)
74 *  PA6 = game port 0, pin 6 (fire)
75 *  PA5 = /RDY (disk ready)
76 *  PA4 = /TK0 (disk track 00)
77 *  PA3 = /WPRO (disk write protect)
78 *  PA2 = /CHNG (disk change)
79 *  PA1 = /LED (LED, 0=bright / audio filter control)
80 *  PA0 = MUTE
81 *
82 *************************************/
83
84static WRITE8_DEVICE_HANDLER( ami1200_cia_0_porta_w )
85{
86   ami1200_state *state = device->machine().driver_data<ami1200_state>();
87
88   /* bit 2 = Power Led on Amiga */
89   set_led_status(device->machine(), 0, !BIT(data, 1));
90
91   handle_cd32_joystick_cia(state, data, mos6526_r(device, 2));
92}
93
94/*************************************
95 *
96 *  CIA-A port B access:
97 *
98 *  PB7 = parallel data 7
99 *  PB6 = parallel data 6
100 *  PB5 = parallel data 5
101 *  PB4 = parallel data 4
102 *  PB3 = parallel data 3
103 *  PB2 = parallel data 2
104 *  PB1 = parallel data 1
105 *  PB0 = parallel data 0
106 *
107 *************************************/
108
109static READ8_DEVICE_HANDLER( ami1200_cia_0_portb_r )
110{
111   /* parallel port */
112   logerror("%s:CIA0_portb_r\n", device->machine().describe_context());
113   return 0xff;
114}
115
116static WRITE8_DEVICE_HANDLER( ami1200_cia_0_portb_w )
117{
118   /* parallel port */
119   logerror("%s:CIA0_portb_w(%02x)\n", device->machine().describe_context(), data);
120}
121
122static ADDRESS_MAP_START( a1200_map, AS_PROGRAM, 32 )
123   ADDRESS_MAP_UNMAP_HIGH
124   AM_RANGE(0x000000, 0x1fffff) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(cd32_state, m_chip_ram, m_chip_ram_size)
125   AM_RANGE(0xbfa000, 0xbfa003) AM_WRITE(aga_overlay_w)
126   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE16(amiga_cia_r, amiga_cia_w, 0xffffffff)
127   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE16(amiga_custom_r, amiga_custom_w, 0xffffffff) AM_BASE_MEMBER(cd32_state, m_custom_regs)
128   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE16(amiga_autoconfig_r, amiga_autoconfig_w, 0xffffffff)
129   AM_RANGE(0xf80000, 0xffffff) AM_ROM AM_REGION("user1", 0)   /* Kickstart */
130ADDRESS_MAP_END
131
132
133//int cd32_input_port_val = 0;
134//int cd32_input_select = 0;
135
136static void cd32_potgo_w(running_machine &machine, UINT16 data)
137{
138   ami1200_state *state = machine.driver_data<ami1200_state>();
139   int i;
140
141   state->m_potgo_value = state->m_potgo_value & 0x5500;
142   state->m_potgo_value |= data & 0xaa00;
143
144   for (i = 0; i < 8; i += 2)
145   {
146      UINT16 dir = 0x0200 << i;
147      if (data & dir)
148      {
149         UINT16 d = 0x0100 << i;
150         state->m_potgo_value &= ~d;
151         state->m_potgo_value |= data & d;
152      }
153   }
154   for (i = 0; i < 2; i++)
155   {
156      UINT16 p5dir = 0x0200 << (i * 4); /* output enable P5 */
157      UINT16 p5dat = 0x0100 << (i * 4); /* data P5 */
158      if ((state->m_potgo_value & p5dir) && (state->m_potgo_value & p5dat))
159         state->m_cd32_shifter[i] = 8;
160   }
161}
162
163static void handle_cd32_joystick_cia(ami1200_state *state, UINT8 pra, UINT8 dra)
164{
165   int i;
166
167   for (i = 0; i < 2; i++)
168   {
169      UINT8 but = 0x40 << i;
170      UINT16 p5dir = 0x0200 << (i * 4); /* output enable P5 */
171      UINT16 p5dat = 0x0100 << (i * 4); /* data P5 */
172      if (!(state->m_potgo_value & p5dir) || !(state->m_potgo_value & p5dat))
173      {
174         if ((dra & but) && (pra & but) != state->m_oldstate[i])
175         {
176            if (!(pra & but))
177            {
178               state->m_cd32_shifter[i]--;
179               if (state->m_cd32_shifter[i] < 0)
180                  state->m_cd32_shifter[i] = 0;
181            }
182         }
183      }
184      state->m_oldstate[i] = pra & but;
185   }
186}
187
188
189static INPUT_PORTS_START( a1200 )
190   PORT_START("CIA0PORTA")
191   PORT_BIT( 0x3f, IP_ACTIVE_LOW, IPT_SPECIAL )
192   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
193   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
194
195   PORT_START("CIA0PORTB")
196   PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNUSED )
197
198   PORT_START("JOY0DAT")
199   PORT_BIT( 0x0303, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(amiga_joystick_convert, "P1JOY")
200   PORT_BIT( 0xfcfc, IP_ACTIVE_HIGH, IPT_UNUSED )
201
202   PORT_START("JOY1DAT")
203   PORT_BIT( 0x0303, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(amiga_joystick_convert, "P2JOY")
204   PORT_BIT( 0xfcfc, IP_ACTIVE_HIGH, IPT_UNUSED )
205
206   PORT_START("POTGO")
207   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNUSED )
208   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
209   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_UNUSED )
210   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
211   PORT_BIT( 0xaaff, IP_ACTIVE_HIGH, IPT_UNUSED )
212
213   PORT_START("P1JOY")
214   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
215   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1)
216   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1)
217   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
218
219   PORT_START("P2JOY")
220   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(2)
221   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
222   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2)
223   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
224
225   PORT_START("P0MOUSEX")
226   PORT_BIT( 0xff, 0x00, IPT_MOUSE_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_PLAYER(1)
227
228   PORT_START("P0MOUSEY")
229   PORT_BIT( 0xff, 0x00, IPT_MOUSE_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_PLAYER(1)
230
231   PORT_START("P1MOUSEX")
232   PORT_BIT( 0xff, 0x00, IPT_MOUSE_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_PLAYER(2)
233
234   PORT_START("P1MOUSEY")
235   PORT_BIT( 0xff, 0x00, IPT_MOUSE_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_PLAYER(2)
236
237   PORT_INCLUDE( amiga_us_keyboard )
238INPUT_PORTS_END
239
240
241/*************************************
242 *
243 *  Sound definitions
244 *
245 *************************************/
246
247static READ8_DEVICE_HANDLER( a1200_cia_0_portA_r )
248{
249   UINT8 ret = input_port_read(device->machine(), "CIA0PORTA") & 0xc0;   /* Gameport 1 and 0 buttons */
250   ret |= amiga_fdc_status_r(device->machine().device("fdc"));
251   return ret;
252}
253
254
255static const mos6526_interface a1200_cia_0_intf =
256{
257   0,                                       /* tod_clock */
258   DEVCB_LINE(amiga_cia_0_irq),                           /* irq_func */
259   DEVCB_NULL,   /* pc_func */
260   DEVCB_NULL,
261   DEVCB_NULL,
262   DEVCB_HANDLER(a1200_cia_0_portA_r),
263   DEVCB_HANDLER(ami1200_cia_0_porta_w),      /* port A */
264   DEVCB_HANDLER(ami1200_cia_0_portb_r),
265   DEVCB_HANDLER(ami1200_cia_0_portb_w)      /* port B */
266};
267
268static const mos6526_interface a1200_cia_1_intf =
269{
270   0,                                       /* tod_clock */
271   DEVCB_LINE(amiga_cia_1_irq),                           /* irq_func */
272   DEVCB_NULL,   /* pc_func */
273   DEVCB_NULL,
274   DEVCB_NULL,
275   DEVCB_NULL,
276   DEVCB_NULL,                           /* port A */
277   DEVCB_NULL,
278   DEVCB_DEVICE_HANDLER("fdc", amiga_fdc_control_w)         /* port B */
279};
280
281
282static MACHINE_CONFIG_START( a1200n, ami1200_state )
283
284   /* basic machine hardware */
285   MCFG_CPU_ADD("maincpu", M68EC020, AMIGA_68EC020_NTSC_CLOCK) /* 14.3 Mhz */
286   MCFG_CPU_PROGRAM_MAP(a1200_map)
287
288//  MCFG_CPU_ADD("keyboard_mpu", MC68HC05)
289
290   MCFG_MACHINE_RESET(amiga)
291
292   /* video hardware */
293   MCFG_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK)
294
295   MCFG_SCREEN_ADD("screen", RASTER)
296   MCFG_SCREEN_REFRESH_RATE(59.997)
297   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
298   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
299   MCFG_SCREEN_SIZE(512*2, 312)
300   MCFG_SCREEN_VISIBLE_AREA((129-8-8)*2, (449+8-1+8)*2, 44-8, 300+8-1)
301   MCFG_SCREEN_UPDATE(amiga_aga)
302
303   MCFG_VIDEO_START(amiga_aga)
304
305   /* sound hardware */
306   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
307
308   MCFG_SOUND_ADD("amiga", AMIGA, XTAL_28_63636MHz/8)
309   MCFG_SOUND_ROUTE(0, "lspeaker", 0.25)
310   MCFG_SOUND_ROUTE(1, "rspeaker", 0.25)
311   MCFG_SOUND_ROUTE(2, "rspeaker", 0.25)
312   MCFG_SOUND_ROUTE(3, "lspeaker", 0.25)
313
314   /* cia */
315   MCFG_MOS8520_ADD("cia_0", AMIGA_68EC020_NTSC_CLOCK / 10, a1200_cia_0_intf)
316   MCFG_MOS8520_ADD("cia_1", AMIGA_68EC020_NTSC_CLOCK / 10, a1200_cia_1_intf)
317
318   MCFG_AMIGA_FDC_ADD("fdc")
319MACHINE_CONFIG_END
320
321static MACHINE_CONFIG_DERIVED( a1200p, a1200n )
322
323   /* adjust for PAL specs */
324   MCFG_CPU_MODIFY("maincpu")
325   MCFG_CPU_CLOCK(A1200PAL_XTAL_X1/2) /* 14.18758 MHz */
326
327   /* video hardware */
328   MCFG_SCREEN_MODIFY("screen")
329   MCFG_SCREEN_REFRESH_RATE(50)
330
331   /* sound hardware */
332   MCFG_SOUND_MODIFY("amiga")
333   MCFG_SOUND_CLOCK(A1200PAL_XTAL_X1/8) /* 3.546895 MHz */
334
335   /* cia */
336   MCFG_DEVICE_MODIFY("cia_0")
337   MCFG_DEVICE_CLOCK(A1200PAL_XTAL_X1/20)
338   MCFG_DEVICE_MODIFY("cia_1")
339   MCFG_DEVICE_CLOCK(A1200PAL_XTAL_X1/20)
340MACHINE_CONFIG_END
341
342
343/***************************************************************************
344    ROM DEFINITIONS
345***************************************************************************/
346
347ROM_START( a1200n )
348   ROM_REGION32_BE(0x080000, "user1", 0)
349   ROM_DEFAULT_BIOS("kick31")
350   ROM_SYSTEM_BIOS(0, "kick30", "Kickstart 3.0 (39.106)")
351   ROMX_LOAD("391523-01.u6a", 0x000000, 0x040000, CRC(c742a412) SHA1(999eb81c65dfd07a71ee19315d99c7eb858ab186), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(1))
352   ROMX_LOAD("391524-01.u6b", 0x000002, 0x040000, CRC(d55c6ec6) SHA1(3341108d3a402882b5ef9d3b242cbf3c8ab1a3e9), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(1))
353   ROM_SYSTEM_BIOS(1, "kick31", "Kickstart 3.1 (40.068)")
354   ROMX_LOAD("391773-01.u6a", 0x000000, 0x040000, CRC(08dbf275) SHA1(b8800f5f909298109ea69690b1b8523fa22ddb37), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(2))   // ROM_LOAD32_WORD_SWAP!
355   ROMX_LOAD("391774-01.u6b", 0x000002, 0x040000, CRC(16c07bf8) SHA1(90e331be1970b0e53f53a9b0390b51b59b3869c2), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(2))
356
357   // COMMODORE | 391508-01 REV0 | KEYBOARD MPU
358   ROM_REGION(0x1040, "keyboard_rev0", 0)
359   ROM_LOAD("391508-01.u13", 0x0000, 0x1040, NO_DUMP)
360
361   // Amiga Tech REV1 Keyboard MPU
362   ROM_REGION(0x2f40, "keyboard_rev1", 0)
363   ROM_LOAD("391508-02.u13", 0x0000, 0x2f40, NO_DUMP)
364ROM_END
365
366#define rom_a1200p    rom_a1200n
367
368
369/***************************************************************************************************/
370
371// these come directly from amiga.c
372
373static UINT16 a1200_read_dskbytr(running_machine &machine)
374{
375   return amiga_fdc_get_byte(machine.device("fdc"));
376}
377
378static void a1200_write_dsklen(running_machine &machine, UINT16 data)
379{
380   cd32_state *state = machine.driver_data<cd32_state>();
381   if ( data & 0x8000 )
382   {
383      if ( CUSTOM_REG(REG_DSKLEN) & 0x8000 )
384         amiga_fdc_setup_dma(machine.device("fdc"));
385   }
386}
387
388
389static DRIVER_INIT( a1200 )
390{
391   cd32_state *state = machine.driver_data<cd32_state>();
392   static const amiga_machine_interface cd32_intf =
393   {
394      AGA_CHIP_RAM_MASK,
395      NULL, NULL,         /* joy0dat_r & joy1dat_r */
396      cd32_potgo_w,      /* potgo_w */
397      a1200_read_dskbytr, a1200_write_dsklen, /* dskbytr_r & dsklen_w */
398      NULL,            /* serdat_w */
399      NULL,            /* scanline0_callback */
400      NULL,            /* reset_callback */
401      NULL,            /* nmi_callback */
402      FLAGS_AGA_CHIPSET   /* flags */
403   };
404
405   /* configure our Amiga setup */
406   amiga_machine_config(machine, &cd32_intf);
407
408   /* set up memory */
409   memory_configure_bank(machine, "bank1", 0, 1, state->m_chip_ram, 0);
410   memory_configure_bank(machine, "bank1", 1, 1, machine.region("user1")->base(), 0);
411
412   /* initialize keyboard */
413   amigakbd_init(machine);
414}
415
416
417/***************************************************************************************************/
418
419/*    YEAR  NAME     PARENT   COMPAT  MACHINE INPUT   INIT      COMPANY       FULLNAME */
420COMP( 1992, a1200n,  0,       0,      a1200n, a1200,  a1200,  "Commodore Business Machines",  "Amiga 1200 (NTSC)" , GAME_NOT_WORKING )
421COMP( 1992, a1200p,  a1200n,  0,      a1200p, a1200,  a1200,  "Commodore Business Machines",  "Amiga 1200 (PAL)" , GAME_NOT_WORKING  )
src/mame/drivers/pce.c
r0r11461
1/****************************************************************************
2
3 PC-Engine / Turbo Grafx 16 driver
4 by Charles Mac Donald
5 E-Mail: cgfm2@hooked.net
6
7 Thanks to David Shadoff and Brian McPhail for help with the driver.
8
9****************************************************************************/
10
11/**********************************************************************
12          To-Do List:
13- convert h6280-based drivers to internal memory map for the I/O region
14- test sprite collision and overflow interrupts
15- sprite precaching
16- rewrite the base renderer loop
17- Add CD support
18- Add 6 button joystick support
19- Add 263 line mode
20- Sprite DMA should use vdc VRAM functions
21- properly implement the pixel clocks instead of the simple scaling we do now
22
23Banking
24=======
25
26Normally address spacebanks 00-F6 are assigned to regular HuCard ROM space. There
27are a couple of special situations:
28
29Street Fighter II:
30  - address space banks 40-7F switchable by writing to 1FF0-1FF3
31    1FF0 - select rom banks 40-7F
32    1FF1 - select rom banks 80-BF
33    1FF2 - select rom banks C0-FF
34    1FF3 - select rom banks 100-13F
35
36Populous:
37  - address space banks 40-43 contains 32KB RAM
38
39CDRom units:
40  - address space banks 80-87 contains 64KB RAM
41
42Super System Card:
43  - address space banks 68-7F contains 192KB RAM
44
45**********************************************************************/
46
47/**********************************************************************
48                          Known Bugs
49***********************************************************************
50- Benkei Gaiden: hangs after a few Sunsoft logo spins.
51- Busou Keiji Cyber Cross: hangs on attract mode
52- Cadash: After choosing character and name, the game starts and the display 'jiggles' like tracking if off a VCR
53- Fighting Run: has color and sprite issues during gameplay;
54- Hisou Kihei - Xserd: black screen;
55**********************************************************************/
56
57#include "emu.h"
58#include "deprecat.h"
59#include "video/vdc.h"
60#include "cpu/h6280/h6280.h"
61#include "includes/pce.h"
62#include "imagedev/cartslot.h"
63#include "imagedev/chd_cd.h"
64#include "sound/c6280.h"
65#include "sound/cdda.h"
66#include "sound/msm5205.h"
67#include "hash.h"
68
69
70static ADDRESS_MAP_START( pce_mem , AS_PROGRAM, 8)
71   AM_RANGE( 0x000000, 0x07FFFF) AM_ROMBANK("bank1")
72   AM_RANGE( 0x080000, 0x087FFF) AM_ROMBANK("bank2")
73   AM_RANGE( 0x088000, 0x0CFFFF) AM_ROMBANK("bank3")
74   AM_RANGE( 0x0D0000, 0x0FFFFF) AM_ROMBANK("bank4")
75   AM_RANGE( 0x100000, 0x10FFFF) AM_RAM AM_BASE_MEMBER( pce_state, m_cd_ram )
76   AM_RANGE( 0x110000, 0x1EDFFF) AM_NOP
77   AM_RANGE( 0x1EE000, 0x1EE7FF) AM_ROMBANK("bank10") AM_WRITE( pce_cd_bram_w )
78   AM_RANGE( 0x1EE800, 0x1EFFFF) AM_NOP
79   AM_RANGE( 0x1F0000, 0x1F1FFF) AM_RAM AM_MIRROR(0x6000) AM_BASE_MEMBER( pce_state, m_user_ram )
80   AM_RANGE( 0x1FE000, 0x1FE3FF) AM_READWRITE( vdc_0_r, vdc_0_w )
81   AM_RANGE( 0x1FE400, 0x1FE7FF) AM_READWRITE( vce_r, vce_w )
82   AM_RANGE( 0x1FE800, 0x1FEBFF) AM_DEVREADWRITE(C6280_TAG, c6280_r, c6280_w )
83   AM_RANGE( 0x1FEC00, 0x1FEFFF) AM_READWRITE( h6280_timer_r, h6280_timer_w )
84   AM_RANGE( 0x1FF000, 0x1FF3FF) AM_READWRITE( pce_joystick_r, pce_joystick_w )
85   AM_RANGE( 0x1FF400, 0x1FF7FF) AM_READWRITE( h6280_irq_status_r, h6280_irq_status_w )
86   AM_RANGE( 0x1FF800, 0x1FFBFF) AM_READWRITE( pce_cd_intf_r, pce_cd_intf_w )
87ADDRESS_MAP_END
88
89static ADDRESS_MAP_START( pce_io , AS_IO, 8)
90   AM_RANGE( 0x00, 0x03) AM_READWRITE( vdc_0_r, vdc_0_w )
91ADDRESS_MAP_END
92
93static ADDRESS_MAP_START( sgx_mem , AS_PROGRAM, 8)
94   AM_RANGE( 0x000000, 0x07FFFF) AM_ROMBANK("bank1")
95   AM_RANGE( 0x080000, 0x087FFF) AM_ROMBANK("bank2")
96   AM_RANGE( 0x088000, 0x0CFFFF) AM_ROMBANK("bank3")
97   AM_RANGE( 0x0D0000, 0x0FFFFF) AM_ROMBANK("bank4")
98   AM_RANGE( 0x100000, 0x10FFFF) AM_RAM AM_BASE_MEMBER( pce_state, m_cd_ram )
99   AM_RANGE( 0x110000, 0x1EDFFF) AM_NOP
100   AM_RANGE( 0x1EE000, 0x1EE7FF) AM_ROMBANK("bank10") AM_WRITE( pce_cd_bram_w )
101   AM_RANGE( 0x1EE800, 0x1EFFFF) AM_NOP
102   AM_RANGE( 0x1F0000, 0x1F7FFF) AM_RAM AM_BASE_MEMBER( pce_state, m_user_ram )
103   AM_RANGE( 0x1FE000, 0x1FE007) AM_READWRITE( vdc_0_r, vdc_0_w ) AM_MIRROR(0x03E0)
104   AM_RANGE( 0x1FE008, 0x1FE00F) AM_READWRITE( vpc_r, vpc_w ) AM_MIRROR(0x03E0)
105   AM_RANGE( 0x1FE010, 0x1FE017) AM_READWRITE( vdc_1_r, vdc_1_w ) AM_MIRROR(0x03E0)
106   AM_RANGE( 0x1FE400, 0x1FE7FF) AM_READWRITE( vce_r, vce_w )
107   AM_RANGE( 0x1FE800, 0x1FEBFF) AM_DEVREADWRITE(C6280_TAG, c6280_r, c6280_w )
108   AM_RANGE( 0x1FEC00, 0x1FEFFF) AM_READWRITE( h6280_timer_r, h6280_timer_w )
109   AM_RANGE( 0x1FF000, 0x1FF3FF) AM_READWRITE( pce_joystick_r, pce_joystick_w )
110   AM_RANGE( 0x1FF400, 0x1FF7FF) AM_READWRITE( h6280_irq_status_r, h6280_irq_status_w )
111   AM_RANGE( 0x1FF800, 0x1FFBFF) AM_READWRITE( pce_cd_intf_r, pce_cd_intf_w )
112ADDRESS_MAP_END
113
114static ADDRESS_MAP_START( sgx_io , AS_IO, 8)
115   AM_RANGE( 0x00, 0x03) AM_READWRITE( sgx_vdc_r, sgx_vdc_w )
116ADDRESS_MAP_END
117
118/* todo: alternate forms of input (multitap, mouse, etc.) */
119static INPUT_PORTS_START( pce )
120
121   PORT_START("JOY_P1")
122   /* II is left of I on the original pad so we map them in reverse order */
123   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P1 Button I") PORT_PLAYER(1) PORT_CATEGORY(10)
124   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P1 Button II") PORT_PLAYER(1) PORT_CATEGORY(10)
125   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P1 Select") PORT_PLAYER(1) PORT_CATEGORY(10)
126   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P1 Run") PORT_PLAYER(1) PORT_CATEGORY(10)
127   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1) PORT_CATEGORY(10)
128   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) PORT_CATEGORY(10)
129   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) PORT_CATEGORY(10)
130   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) PORT_CATEGORY(10)
131
132   PORT_START("JOY_P2")
133   /* II is left of I on the original pad so we map them in reverse order */
134   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P2 Button I") PORT_PLAYER(2) PORT_CATEGORY(20)
135   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P2 Button II") PORT_PLAYER(2) PORT_CATEGORY(20)
136   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P2 Select") PORT_PLAYER(2) PORT_CATEGORY(20)
137   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P2 Run") PORT_PLAYER(2) PORT_CATEGORY(20)
138   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2) PORT_CATEGORY(20)
139   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) PORT_CATEGORY(20)
140   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) PORT_CATEGORY(20)
141   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) PORT_CATEGORY(20)
142
143   PORT_START("JOY_P3")
144   /* II is left of I on the original pad so we map them in reverse order */
145   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P3 Button I") PORT_PLAYER(3) PORT_CATEGORY(30)
146   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P3 Button II") PORT_PLAYER(3) PORT_CATEGORY(30)
147   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P3 Select") PORT_PLAYER(3) PORT_CATEGORY(30)
148   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P3 Run") PORT_PLAYER(3) PORT_CATEGORY(30)
149   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(3) PORT_CATEGORY(30)
150   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(3) PORT_CATEGORY(30)
151   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(3) PORT_CATEGORY(30)
152   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(3) PORT_CATEGORY(30)
153
154   PORT_START("JOY_P4")
155   /* II is left of I on the original pad so we map them in reverse order */
156   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P4 Button I") PORT_PLAYER(4) PORT_CATEGORY(40)
157   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P4 Button II") PORT_PLAYER(4) PORT_CATEGORY(40)
158   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P4 Select") PORT_PLAYER(4) PORT_CATEGORY(40)
159   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P4 Run") PORT_PLAYER(4) PORT_CATEGORY(40)
160   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(4) PORT_CATEGORY(40)
161   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(4) PORT_CATEGORY(40)
162   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(4) PORT_CATEGORY(40)
163   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(4) PORT_CATEGORY(40)
164
165   PORT_START("JOY_P5")
166   /* II is left of I on the original pad so we map them in reverse order */
167   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P5 Button I") PORT_PLAYER(5) PORT_CATEGORY(50)
168   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P5 Button II") PORT_PLAYER(5) PORT_CATEGORY(50)
169   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P5 Select") PORT_PLAYER(5) PORT_CATEGORY(50)
170   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P5 Run") PORT_PLAYER(5) PORT_CATEGORY(50)
171   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(5) PORT_CATEGORY(50)
172   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(5) PORT_CATEGORY(50)
173   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(5) PORT_CATEGORY(50)
174   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(5) PORT_CATEGORY(50)
175
176   PORT_START("JOY6B_P1")
177   /* II is left of I on the original pad so we map them in reverse order */
178   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P1 Button I") PORT_PLAYER(1) PORT_CATEGORY(11)
179   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P1 Button II") PORT_PLAYER(1) PORT_CATEGORY(11)
180   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P1 Select") PORT_PLAYER(1) PORT_CATEGORY(11)
181   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P1 Run") PORT_PLAYER(1) PORT_CATEGORY(11)
182   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1) PORT_CATEGORY(11)
183   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) PORT_CATEGORY(11)
184   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) PORT_CATEGORY(11)
185   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) PORT_CATEGORY(11)
186   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P1 Button III") PORT_PLAYER(1) PORT_CATEGORY(11)
187   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("P1 Button IV") PORT_PLAYER(1) PORT_CATEGORY(11)
188   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("P1 Button V") PORT_PLAYER(1) PORT_CATEGORY(11)
189   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("P1 Button VI") PORT_PLAYER(1) PORT_CATEGORY(11)
190   PORT_BIT( 0xf000, IP_ACTIVE_HIGH,IPT_UNUSED ) //6-button pad header
191
192   PORT_START("JOY6B_P2")  /* Player 2 controls */
193   /* II is left of I on the original pad so we map them in reverse order */
194   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P2 Button I") PORT_PLAYER(2) PORT_CATEGORY(21)
195   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P2 Button II") PORT_PLAYER(2) PORT_CATEGORY(21)
196   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P2 Select") PORT_PLAYER(2) PORT_CATEGORY(21)
197   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P2 Run") PORT_PLAYER(2) PORT_CATEGORY(21)
198   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2) PORT_CATEGORY(21)
199   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) PORT_CATEGORY(21)
200   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) PORT_CATEGORY(21)
201   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) PORT_CATEGORY(21)
202   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P2 Button III") PORT_PLAYER(2) PORT_CATEGORY(21)
203   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("P2 Button IV") PORT_PLAYER(2) PORT_CATEGORY(21)
204   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("P2 Button V") PORT_PLAYER(2) PORT_CATEGORY(21)
205   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("P2 Button VI") PORT_PLAYER(2) PORT_CATEGORY(21)
206   PORT_BIT( 0xf000, IP_ACTIVE_HIGH,IPT_UNUSED ) //6-button pad header
207
208   PORT_START("JOY6B_P3")  /* Player 3 controls */
209   /* II is left of I on the original pad so we map them in reverse order */
210   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P3 Button I") PORT_PLAYER(3) PORT_CATEGORY(31)
211   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P3 Button II") PORT_PLAYER(3) PORT_CATEGORY(31)
212   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P3 Select") PORT_PLAYER(3) PORT_CATEGORY(31)
213   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P3 Run") PORT_PLAYER(3) PORT_CATEGORY(31)
214   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(3) PORT_CATEGORY(31)
215   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(3) PORT_CATEGORY(31)
216   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(3) PORT_CATEGORY(31)
217   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(3) PORT_CATEGORY(31)
218   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P3 Button III") PORT_PLAYER(3) PORT_CATEGORY(31)
219   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("P3 Button IV") PORT_PLAYER(3) PORT_CATEGORY(31)
220   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("P3 Button V") PORT_PLAYER(3) PORT_CATEGORY(31)
221   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("P3 Button VI") PORT_PLAYER(3) PORT_CATEGORY(31)
222   PORT_BIT( 0xf000, IP_ACTIVE_HIGH,IPT_UNUSED ) //6-button pad header
223
224   PORT_START("JOY6B_P4")  /* Player 4 controls */
225   /* II is left of I on the original pad so we map them in reverse order */
226   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P4 Button I") PORT_PLAYER(4) PORT_CATEGORY(41)
227   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P4 Button II") PORT_PLAYER(4) PORT_CATEGORY(41)
228   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P4 Select") PORT_PLAYER(4) PORT_CATEGORY(41)
229   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P4 Run") PORT_PLAYER(4) PORT_CATEGORY(41)
230   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(4) PORT_CATEGORY(41)
231   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(4) PORT_CATEGORY(41)
232   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(4) PORT_CATEGORY(41)
233   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(4) PORT_CATEGORY(41)
234   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P3 Button III") PORT_PLAYER(4) PORT_CATEGORY(41)
235   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("P3 Button IV") PORT_PLAYER(4) PORT_CATEGORY(41)
236   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("P3 Button V") PORT_PLAYER(4) PORT_CATEGORY(41)
237   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("P3 Button VI") PORT_PLAYER(4) PORT_CATEGORY(41)
238   PORT_BIT( 0xf000, IP_ACTIVE_HIGH,IPT_UNUSED ) //6-button pad header
239
240   PORT_START("JOY6B_P5")  /* Player 5 controls */
241   /* II is left of I on the original pad so we map them in reverse order */
242   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P5 Button I") PORT_PLAYER(5) PORT_CATEGORY(51)
243   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P5 Button II") PORT_PLAYER(5) PORT_CATEGORY(51)
244   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P5 Select") PORT_PLAYER(5) PORT_CATEGORY(51)
245   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P5 Run") PORT_PLAYER(5) PORT_CATEGORY(51)
246   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(5) PORT_CATEGORY(51)
247   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(5) PORT_CATEGORY(51)
248   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(5) PORT_CATEGORY(51)
249   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(5) PORT_CATEGORY(51)
250   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P5 Button III") PORT_PLAYER(5) PORT_CATEGORY(51)
251   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("P5 Button IV") PORT_PLAYER(5) PORT_CATEGORY(51)
252   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("P5 Button V") PORT_PLAYER(5) PORT_CATEGORY(51)
253   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("P5 Button VI") PORT_PLAYER(5) PORT_CATEGORY(51)
254   PORT_BIT( 0xf000, IP_ACTIVE_HIGH,IPT_UNUSED ) //6-button pad header
255
256   PORT_START("JOY_TYPE")
257   PORT_CATEGORY_CLASS(0x0003,0x0000,"Joystick Type Player 1")
258   PORT_CATEGORY_ITEM( 0x0000,"2-buttons", 10)
259//  PORT_CATEGORY_ITEM( 0x0001,"3-buttons", xx)
260   PORT_CATEGORY_ITEM( 0x0002,"6-buttons", 11)
261//  PORT_CATEGORY_ITEM( 0x0003,"Mouse",     xx)
262   PORT_CATEGORY_CLASS(0x000c,0x0000,"Joystick Type Player 2")
263   PORT_CATEGORY_ITEM( 0x0000,"2-buttons", 20)
264//  PORT_CATEGORY_ITEM( 0x0004,"3-buttons", xx)
265   PORT_CATEGORY_ITEM( 0x0008,"6-buttons", 21)
266//  PORT_CATEGORY_ITEM( 0x000c,"Mouse",     xx)
267   PORT_CATEGORY_CLASS(0x0030,0x0000,"Joystick Type Player 3")
268   PORT_CATEGORY_ITEM( 0x0000,"2-buttons", 30)
269//  PORT_CATEGORY_ITEM( 0x0010,"3-buttons", xx)
270   PORT_CATEGORY_ITEM( 0x0020,"6-buttons", 31)
271//  PORT_CATEGORY_ITEM( 0x0030,"Mouse",     xx)
272   PORT_CATEGORY_CLASS(0x00c0,0x0000,"Joystick Type Player 4")
273   PORT_CATEGORY_ITEM( 0x0000,"2-buttons", 40)
274//  PORT_CATEGORY_ITEM( 0x0040,"3-buttons", xx)
275   PORT_CATEGORY_ITEM( 0x0080,"6-buttons", 41)
276//  PORT_CATEGORY_ITEM( 0x00c0,"Mouse",     xx)
277   PORT_CATEGORY_CLASS(0x0300,0x0000,"Joystick Type Player 5")
278   PORT_CATEGORY_ITEM( 0x0000,"2-buttons", 50)
279//  PORT_CATEGORY_ITEM( 0x0100,"3-buttons", xx)
280   PORT_CATEGORY_ITEM( 0x0200,"6-buttons", 51)
281//  PORT_CATEGORY_ITEM( 0x0300,"Mouse",     xx)
282
283   PORT_START("A_CARD")
284   PORT_CONFNAME( 0x01, 0x01, "Arcade Card" )
285   PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
286   PORT_CONFSETTING(    0x01, DEF_STR( On ) )
287INPUT_PORTS_END
288
289
290static void pce_partialhash(hash_collection &dest, const unsigned char *data,
291   unsigned long length, const char *functions)
292{
293   if ( ( length <= PCE_HEADER_SIZE ) || ( length & PCE_HEADER_SIZE ) ) {
294         dest.compute(&data[PCE_HEADER_SIZE], length - PCE_HEADER_SIZE, functions);
295   } else {
296      dest.compute(data, length, functions);
297   }
298}
299
300static const c6280_interface c6280_config =
301{
302   "maincpu"
303};
304static MACHINE_CONFIG_FRAGMENT( pce_cdslot )
305   MCFG_CDROM_ADD( "cdrom" )
306   MCFG_CDROM_INTERFACE("pce_cdrom")
307
308   MCFG_SOFTWARE_LIST_ADD("cd_list","pcecd")
309MACHINE_CONFIG_END
310
311static MACHINE_CONFIG_FRAGMENT( pce_cartslot )
312   MCFG_CARTSLOT_ADD("cart")
313   MCFG_CARTSLOT_EXTENSION_LIST("pce,bin")
314   MCFG_CARTSLOT_MANDATORY
315   MCFG_CARTSLOT_INTERFACE("pce_cart")
316   MCFG_CARTSLOT_LOAD(pce_cart)
317   MCFG_CARTSLOT_PARTIALHASH(pce_partialhash)
318   MCFG_SOFTWARE_LIST_ADD("cart_list","pce")
319MACHINE_CONFIG_END
320
321static MACHINE_CONFIG_FRAGMENT( tg16_cartslot )
322   MCFG_CARTSLOT_ADD("cart")
323   MCFG_CARTSLOT_EXTENSION_LIST("pce,bin")
324   MCFG_CARTSLOT_MANDATORY
325   MCFG_CARTSLOT_INTERFACE("tg16_cart")
326   MCFG_CARTSLOT_LOAD(pce_cart)
327   MCFG_CARTSLOT_PARTIALHASH(pce_partialhash)
328   MCFG_SOFTWARE_LIST_ADD("cart_list","tg16")
329MACHINE_CONFIG_END
330
331static MACHINE_CONFIG_FRAGMENT( sgx_cartslot )
332   MCFG_CARTSLOT_ADD("cart")
333   MCFG_CARTSLOT_EXTENSION_LIST("pce,bin")
334   MCFG_CARTSLOT_MANDATORY
335   MCFG_CARTSLOT_INTERFACE("pce_cart")
336   MCFG_CARTSLOT_LOAD(pce_cart)
337   MCFG_CARTSLOT_PARTIALHASH(pce_partialhash)
338   MCFG_SOFTWARE_LIST_ADD("cart_list","sgx")
339MACHINE_CONFIG_END
340
341static MACHINE_CONFIG_START( pce_common, pce_state )
342   /* basic machine hardware */
343   MCFG_CPU_ADD("maincpu", H6280, MAIN_CLOCK/3)
344   MCFG_CPU_PROGRAM_MAP(pce_mem)
345   MCFG_CPU_IO_MAP(pce_io)
346   MCFG_CPU_VBLANK_INT_HACK(pce_interrupt, VDC_LPF)
347   MCFG_QUANTUM_TIME(attotime::from_hz(60))
348
349   MCFG_MACHINE_START( pce )
350   MCFG_MACHINE_RESET( pce )
351
352    /* video hardware */
353   MCFG_SCREEN_ADD("screen", RASTER)
354   MCFG_SCREEN_REFRESH_RATE(60)
355   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
356   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
357   MCFG_SCREEN_RAW_PARAMS(MAIN_CLOCK/2, VDC_WPF, 70, 70 + 512 + 32, VDC_LPF, 14, 14+242)
358   MCFG_SCREEN_UPDATE( pce )
359
360   /* MCFG_GFXDECODE( pce ) */
361   MCFG_PALETTE_LENGTH(1024)
362   MCFG_PALETTE_INIT( vce )
363
364   MCFG_VIDEO_START( pce )
365
366   MCFG_NVRAM_HANDLER( pce )
367   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
368   MCFG_SOUND_ADD(C6280_TAG, C6280, MAIN_CLOCK/6)
369   MCFG_SOUND_CONFIG(c6280_config)
370   MCFG_SOUND_ROUTE( 0, "lspeaker", 1.00 )
371   MCFG_SOUND_ROUTE( 1, "rspeaker", 1.00 )
372
373   MCFG_SOUND_ADD( "msm5205", MSM5205, PCE_CD_CLOCK / 6 )
374   MCFG_SOUND_CONFIG( pce_cd_msm5205_interface )
375   MCFG_SOUND_ROUTE( ALL_OUTPUTS, "lspeaker", 0.50 )
376   MCFG_SOUND_ROUTE( ALL_OUTPUTS, "rspeaker", 0.50 )
377
378   MCFG_SOUND_ADD( "cdda", CDDA, 0 )
379   MCFG_SOUND_ROUTE( 0, "lspeaker", 1.00 )
380   MCFG_SOUND_ROUTE( 1, "rspeaker", 1.00 )
381MACHINE_CONFIG_END
382
383static MACHINE_CONFIG_DERIVED( pce, pce_common )
384   MCFG_FRAGMENT_ADD( pce_cartslot )
385   MCFG_FRAGMENT_ADD( pce_cdslot )
386MACHINE_CONFIG_END
387
388static MACHINE_CONFIG_DERIVED( tg16, pce_common )
389   MCFG_FRAGMENT_ADD( tg16_cartslot )
390   MCFG_FRAGMENT_ADD( pce_cdslot )
391MACHINE_CONFIG_END
392
393static MACHINE_CONFIG_START( sgx, pce_state )
394   /* basic machine hardware */
395   MCFG_CPU_ADD("maincpu", H6280, MAIN_CLOCK/3)
396   MCFG_CPU_PROGRAM_MAP(sgx_mem)
397   MCFG_CPU_IO_MAP(sgx_io)
398   MCFG_CPU_VBLANK_INT_HACK(sgx_interrupt, VDC_LPF)
399   MCFG_QUANTUM_TIME(attotime::from_hz(60))
400
401   MCFG_MACHINE_START( pce )
402   MCFG_MACHINE_RESET( pce )
403
404   /* video hardware */
405   MCFG_SCREEN_ADD("screen", RASTER)
406   MCFG_SCREEN_REFRESH_RATE(60)
407   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
408   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
409   MCFG_SCREEN_RAW_PARAMS(MAIN_CLOCK/2, VDC_WPF, 70, 70 + 512 + 32, VDC_LPF, 14, 14+242)
410   MCFG_SCREEN_UPDATE( pce )
411
412   MCFG_PALETTE_LENGTH(1024)
413   MCFG_PALETTE_INIT( vce )
414
415   MCFG_VIDEO_START( pce )
416
417   MCFG_NVRAM_HANDLER( pce )
418   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
419   MCFG_SOUND_ADD(C6280_TAG, C6280, MAIN_CLOCK/6)
420   MCFG_SOUND_CONFIG(c6280_config)
421   MCFG_SOUND_ROUTE(0, "lspeaker", 1.00)
422   MCFG_SOUND_ROUTE(1, "rspeaker", 1.00)
423
424   MCFG_SOUND_ADD( "msm5205", MSM5205, PCE_CD_CLOCK / 6 )
425   MCFG_SOUND_CONFIG( pce_cd_msm5205_interface )
426   MCFG_SOUND_ROUTE( ALL_OUTPUTS, "lspeaker", 0.00 )
427   MCFG_SOUND_ROUTE( ALL_OUTPUTS, "rspeaker", 0.00 )
428
429   MCFG_SOUND_ADD( "cdda", CDDA, 0 )
430   MCFG_SOUND_ROUTE( 0, "lspeaker", 1.00 )
431   MCFG_SOUND_ROUTE( 1, "rspeaker", 1.00 )
432
433   MCFG_FRAGMENT_ADD( sgx_cartslot )
434   MCFG_FRAGMENT_ADD( pce_cdslot )
435MACHINE_CONFIG_END
436
437/***************************************************************************
438
439  Game driver(s)
440
441***************************************************************************/
442
443ROM_START( pce )
444   ROM_REGION( PCE_ROM_MAXSIZE, "user1", 0 )      /* Cartridge ROM area */
445   ROM_FILL( 0, PCE_ROM_MAXSIZE, 0xFF )
446ROM_END
447
448#define rom_tg16 rom_pce
449#define rom_sgx rom_pce
450
451/*    YEAR  NAME    PARENT  COMPAT  MACHINE INPUT    INIT   COMPANY  FULLNAME */
452CONS( 1987, pce,    0,      0,      pce,    pce,     pce,   "Nippon Electronic Company", "PC Engine", GAME_IMPERFECT_SOUND)
453CONS( 1989, tg16,   pce,    0,      tg16,   pce,     tg16,  "Nippon Electronic Company", "TurboGrafx 16", GAME_IMPERFECT_SOUND)
454CONS( 1989, sgx,    pce,    0,      sgx,    pce,     sgx,   "Nippon Electronic Company", "SuperGrafx", GAME_IMPERFECT_SOUND)
src/mame/drivers/combatsc.c
r11460r11461
124124#include "cpu/z80/z80.h"
125125#include "sound/2203intf.h"
126126#include "sound/upd7759.h"
127#include "sound/msm5205.h"
127128#include "video/konicdev.h"
128129#include "includes/combatsc.h"
129130
r11460r11461
152153{
153154   combatsc_state *state = space->machine().driver_data<combatsc_state>();
154155   soundlatch_w(space, offset, data);
155   device_set_input_line_and_vector(state->m_audiocpu, 0, HOLD_LINE, 0xff);
156   device_set_input_line(state->m_audiocpu, INPUT_LINE_NMI, PULSE_LINE);
156157}
157158
158159static READ8_HANDLER( combatscb_io_r )
r11460r11461
419420   AM_RANGE(0x8000, 0xffff) AM_ROM                        /* ROM */
420421ADDRESS_MAP_END
421422
422#if 0
423static ADDRESS_MAP_START( sound_map, AS_PROGRAM, 8 )
424   AM_RANGE(0x0000, 0x7fff) AM_ROM                              /* ROM */
425   AM_RANGE(0x8000, 0x87ef) AM_RAM                              /* RAM */
426   AM_RANGE(0x87f0, 0x87ff) AM_RAM                              /* ??? */
427   AM_RANGE(0x9000, 0x9001) AM_DEVREADWRITE("ymsnd", ym2203_r, ym2203_w)   /* YM 2203 */
428   AM_RANGE(0x9008, 0x9009) AM_DEVREAD("ymsnd", ym2203_r)               /* ??? */
429   AM_RANGE(0xa000, 0xa000) AM_READ(soundlatch_r)                  /* soundlatch_r? */
430   AM_RANGE(0x8800, 0xfffb) AM_ROM                              /* ROM? */
431   AM_RANGE(0xfffc, 0xffff) AM_RAM                              /* ??? */
432ADDRESS_MAP_END
433#endif
434
435423static ADDRESS_MAP_START( combatsc_sound_map, AS_PROGRAM, 8 )
436424   AM_RANGE(0x0000, 0x7fff) AM_ROM                                    /* ROM */
437425   AM_RANGE(0x8000, 0x87ff) AM_RAM                                    /* RAM */
r11460r11461
445433   AM_RANGE(0xe000, 0xe001) AM_DEVREADWRITE("ymsnd", combatsc_ym2203_r, ym2203_w)   /* YM 2203 intercepted */
446434ADDRESS_MAP_END
447435
436static WRITE8_DEVICE_HANDLER( combatscb_dac_w )
437{
438   if(data & 0xe0)
439      printf("%02x\n",data);
448440
441   //msm5205_reset_w(device, (data >> 4) & 1);
442   msm5205_data_w(device, (data & 0x0f));
443   msm5205_vclk_w(device, 1);
444   msm5205_vclk_w(device, 0);
445}
446
447static ADDRESS_MAP_START( combatscb_sound_map, AS_PROGRAM, 8 )
448   AM_RANGE(0x0000, 0x7fff) AM_ROM                              /* ROM */
449   AM_RANGE(0x8000, 0x87ff) AM_RAM                              /* RAM */
450   AM_RANGE(0x9000, 0x9001) AM_DEVREADWRITE("ymsnd", ym2203_r, ym2203_w)   /* YM 2203 */
451   AM_RANGE(0x9008, 0x9009) AM_DEVREAD("ymsnd", ym2203_r)               /* ??? */
452   AM_RANGE(0x9800, 0x9800) AM_DEVWRITE("msm5205",combatscb_dac_w)
453   AM_RANGE(0xa000, 0xa000) AM_READ(soundlatch_r)                  /* soundlatch_r? */
454ADDRESS_MAP_END
455
449456/*************************************
450457 *
451458 *  Input ports
r11460r11461
677684   NULL
678685};
679686
687static const ym2203_interface ym2203_bootleg_config =
688{
689   {
690      AY8910_LEGACY_OUTPUT,
691      AY8910_DEFAULT_LOADS,
692      DEVCB_NULL,
693      DEVCB_NULL,
694      DEVCB_NULL,
695      DEVCB_NULL
696   },
697   NULL
698};
680699
681700static MACHINE_START( combatsc )
682701{
r11460r11461
776795   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.70)
777796MACHINE_CONFIG_END
778797
798
799static const msm5205_interface msm5205_config =
800{
801   0,            /* interrupt function */
802   MSM5205_SEX_4B   /* 8KHz playback ?    */
803};
804
779805/* combat school (bootleg on different hardware) */
780806static MACHINE_CONFIG_START( combatscb, combatsc_state )
781807
r11460r11461
785811   MCFG_CPU_VBLANK_INT("screen", irq0_line_hold)
786812
787813   MCFG_CPU_ADD("audiocpu", Z80,3579545)   /* 3.579545 MHz */
788   MCFG_CPU_PROGRAM_MAP(combatsc_sound_map) /* FAKE */
814   MCFG_CPU_PROGRAM_MAP(combatscb_sound_map)
815   MCFG_CPU_PERIODIC_INT(irq0_line_hold,4800) // controls BGM tempo
789816
790817   MCFG_QUANTUM_TIME(attotime::from_hz(1200))
791818
r11460r11461
807834   MCFG_PALETTE_INIT(combatscb)
808835   MCFG_VIDEO_START(combatscb)
809836
810   /* We are using the original sound subsystem */
811837   MCFG_SPEAKER_STANDARD_MONO("mono")
812838
813839   MCFG_SOUND_ADD("ymsnd", YM2203, 3000000)
814   MCFG_SOUND_CONFIG(ym2203_config)
840   MCFG_SOUND_CONFIG(ym2203_bootleg_config)
815841   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.20)
816842
817   MCFG_SOUND_ADD("upd", UPD7759, UPD7759_STANDARD_CLOCK)
818   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.70)
843   MCFG_SOUND_ADD("msm5205", MSM5205, 384000)
844   MCFG_SOUND_CONFIG(msm5205_config)
845   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.30)
819846MACHINE_CONFIG_END
820847
821848
r11460r11461
953980
954981   ROM_REGION( 0x10000 , "audiocpu", 0 ) /* sound CPU */
955982   ROM_LOAD( "combat.001",  0x00000, 0x10000, CRC(61456b3b) SHA1(320db628283dd1bec465e95020d1a1158e6d6ae4) )
956   ROM_LOAD( "611g03.rom",  0x00000, 0x08000, CRC(2a544db5) SHA1(94a97c3c54bf13ccc665aa5057ac6b1d700fae2d) ) /* FAKE - from Konami set! */
957983
958984   ROM_REGION( 0x80000, "gfx1", ROMREGION_INVERT )
959985   ROM_LOAD( "combat.006",  0x00000, 0x10000, CRC(8dc29a1f) SHA1(564dd7c6acff34db93b8e300dda563f5f38ba159) ) /* tiles, bank 0 */
r11460r11461
9781004   ROM_REGION( 0x0200, "proms", 0 )
9791005   ROM_LOAD( "prom.d10",    0x0000, 0x0100, CRC(265f4c97) SHA1(76f1b75a593d3d77ef6173a1948f842d5b27d418) ) /* sprites lookup table */
9801006   ROM_LOAD( "prom.c11",    0x0100, 0x0100, CRC(a7a5c0b4) SHA1(48bfc3af40b869599a988ebb3ed758141bcfd4fc) ) /* priority? */
981
982   ROM_REGION( 0x20000, "upd", 0 )   /* uPD7759 data */
983   ROM_LOAD( "611g04.rom",  0x00000, 0x20000, CRC(2987e158) SHA1(87c5129161d3be29a339083349807e60b625c3f7) )   /* FAKE - from Konami set! */
9841007ROM_END
9851008
9861009
r11460r11461
10071030GAME( 1987, combatsct, combatsc, combatsc,  combatsct, 0,         ROT0, "Konami",  "Combat School (trackball)", 0 )
10081031GAME( 1987, combatscj, combatsc, combatsc,  combatsct, 0,         ROT0, "Konami",  "Combat School (Japan trackball)", 0 )
10091032GAME( 1987, bootcamp,  combatsc, combatsc,  combatsct, 0,         ROT0, "Konami",  "Boot Camp", 0 )
1010GAME( 1988, combatscb, combatsc, combatscb, combatscb, 0,         ROT0, "bootleg", "Combat School (bootleg)", GAME_IMPERFECT_COLORS )
1033GAME( 1988, combatscb, combatsc, combatscb, combatscb, 0,         ROT0, "bootleg", "Combat School (bootleg)", GAME_IMPERFECT_COLORS | GAME_IMPERFECT_SOUND )
src/mame/drivers/n64.c
r0r11461
1/*
2    Nintendo 64
3
4    Driver by Ville Linde
5    Reformatted to share hardware by R. Belmont
6    Additional work by Ryan Holtz
7    Porting from Mupen64 by Harmony
8*/
9
10#include "emu.h"
11#include "cpu/rsp/rsp.h"
12#include "cpu/mips/mips3.h"
13#include "sound/dmadac.h"
14#include "imagedev/cartslot.h"
15#include "includes/n64.h"
16
17
18static ADDRESS_MAP_START( n64_map, AS_PROGRAM, 32 )
19   AM_RANGE(0x00000000, 0x007fffff) AM_RAM   AM_BASE(&rdram)            // RDRAM
20   AM_RANGE(0x03f00000, 0x03f00027) AM_READWRITE(n64_rdram_reg_r, n64_rdram_reg_w)
21   AM_RANGE(0x04000000, 0x04000fff) AM_RAM AM_SHARE("dmem")               // RSP DMEM
22   AM_RANGE(0x04001000, 0x04001fff) AM_RAM AM_SHARE("imem")               // RSP IMEM
23   AM_RANGE(0x04040000, 0x040fffff) AM_DEVREADWRITE("rsp", n64_sp_reg_r, n64_sp_reg_w)   // RSP
24   AM_RANGE(0x04100000, 0x041fffff) AM_DEVREADWRITE("rsp", n64_dp_reg_r, n64_dp_reg_w)   // RDP
25   AM_RANGE(0x04300000, 0x043fffff) AM_READWRITE(n64_mi_reg_r, n64_mi_reg_w)   // MIPS Interface
26   AM_RANGE(0x04400000, 0x044fffff) AM_READWRITE(n64_vi_reg_r, n64_vi_reg_w)   // Video Interface
27   AM_RANGE(0x04500000, 0x045fffff) AM_READWRITE(n64_ai_reg_r, n64_ai_reg_w)   // Audio Interface
28   AM_RANGE(0x04600000, 0x046fffff) AM_READWRITE(n64_pi_reg_r, n64_pi_reg_w)   // Peripheral Interface
29   AM_RANGE(0x04700000, 0x047fffff) AM_READWRITE(n64_ri_reg_r, n64_ri_reg_w)   // RDRAM Interface
30   AM_RANGE(0x04800000, 0x048fffff) AM_READWRITE(n64_si_reg_r, n64_si_reg_w)   // Serial Interface
31   //AM_RANGE(0x08000000, 0x08007fff) AM_RAM                                   // Cartridge SRAM
32   AM_RANGE(0x10000000, 0x13ffffff) AM_ROM AM_REGION("user2", 0)   // Cartridge
33   AM_RANGE(0x1fc00000, 0x1fc007bf) AM_ROM AM_REGION("user1", 0)   // PIF ROM
34   AM_RANGE(0x1fc007c0, 0x1fc007ff) AM_READWRITE(n64_pif_ram_r, n64_pif_ram_w)
35ADDRESS_MAP_END
36
37static ADDRESS_MAP_START( rsp_map, AS_PROGRAM, 32 )
38   AM_RANGE(0x00000000, 0x00000fff) AM_RAM AM_SHARE("dmem")
39   AM_RANGE(0x00001000, 0x00001fff) AM_RAM AM_SHARE("imem")
40   AM_RANGE(0x04000000, 0x04000fff) AM_RAM AM_BASE(&rsp_dmem) AM_SHARE("dmem")
41   AM_RANGE(0x04001000, 0x04001fff) AM_RAM AM_BASE(&rsp_imem) AM_SHARE("imem")
42ADDRESS_MAP_END
43
44static INPUT_PORTS_START( n64 )
45   PORT_START("P1")
46   PORT_BIT( 0x8000, IP_ACTIVE_HIGH, IPT_BUTTON1 )        PORT_PLAYER(1) PORT_NAME("P1 Button A")
47   PORT_BIT( 0x4000, IP_ACTIVE_HIGH, IPT_BUTTON2 )        PORT_PLAYER(1) PORT_NAME("P1 Button B")
48   PORT_BIT( 0x2000, IP_ACTIVE_HIGH, IPT_BUTTON3 )        PORT_PLAYER(1) PORT_NAME("P1 Button Z")
49   PORT_BIT( 0x1000, IP_ACTIVE_HIGH, IPT_START )          PORT_PLAYER(1) PORT_NAME("P1 Start")
50   PORT_BIT( 0x0800, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP )    PORT_PLAYER(1) PORT_NAME("P1 Joypad \xE2\x86\x91") /* Up */
51   PORT_BIT( 0x0400, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN )  PORT_PLAYER(1) PORT_NAME("P1 Joypad \xE2\x86\x93") /* Down */
52   PORT_BIT( 0x0200, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT )  PORT_PLAYER(1) PORT_NAME("P1 Joypad \xE2\x86\x90") /* Left */
53   PORT_BIT( 0x0100, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) PORT_NAME("P1 Joypad \xE2\x86\x92") /* Right */
54   PORT_BIT( 0x00c0, IP_ACTIVE_HIGH, IPT_UNUSED )
55   PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_BUTTON4 )        PORT_PLAYER(1) PORT_NAME("P1 Button L")
56   PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_BUTTON5 )        PORT_PLAYER(1) PORT_NAME("P1 Button R")
57   PORT_BIT( 0x0008, IP_ACTIVE_HIGH, IPT_BUTTON6 )        PORT_PLAYER(1) PORT_NAME("P1 Button C \xE2\x86\x91") /* Up */
58   PORT_BIT( 0x0004, IP_ACTIVE_HIGH, IPT_BUTTON7 )        PORT_PLAYER(1) PORT_NAME("P1 Button C \xE2\x86\x93") /* Down */
59   PORT_BIT( 0x0002, IP_ACTIVE_HIGH, IPT_BUTTON8 )        PORT_PLAYER(1) PORT_NAME("P1 Button C \xE2\x86\x90") /* Left */
60   PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_BUTTON9 )        PORT_PLAYER(1) PORT_NAME("P1 Button C \xE2\x86\x92") /* Right */
61
62   PORT_START("P1_ANALOG_X")
63   PORT_BIT( 0xff, 0x80, IPT_AD_STICK_X ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(30) PORT_KEYDELTA(30) PORT_PLAYER(1)
64
65   PORT_START("P1_ANALOG_Y")
66   PORT_BIT( 0xff, 0x80, IPT_AD_STICK_Y ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(30) PORT_KEYDELTA(30) PORT_PLAYER(1) PORT_REVERSE
67
68   PORT_START("P2")
69   PORT_BIT( 0x8000, IP_ACTIVE_HIGH, IPT_BUTTON1 )        PORT_PLAYER(2) PORT_NAME("P2 Button A")
70   PORT_BIT( 0x4000, IP_ACTIVE_HIGH, IPT_BUTTON2 )        PORT_PLAYER(2) PORT_NAME("P2 Button B")
71   PORT_BIT( 0x2000, IP_ACTIVE_HIGH, IPT_BUTTON3 )        PORT_PLAYER(2) PORT_NAME("P2 Button Z")
72   PORT_BIT( 0x1000, IP_ACTIVE_HIGH, IPT_START )          PORT_PLAYER(2) PORT_NAME("P2 Start")
73   PORT_BIT( 0x0800, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP )    PORT_PLAYER(2) PORT_NAME("P2 Joypad \xE2\x86\x91") /* Up */
74   PORT_BIT( 0x0400, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN )  PORT_PLAYER(2) PORT_NAME("P2 Joypad \xE2\x86\x93") /* Down */
75   PORT_BIT( 0x0200, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT )  PORT_PLAYER(2) PORT_NAME("P2 Joypad \xE2\x86\x90") /* Left */
76   PORT_BIT( 0x0100, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) PORT_NAME("P2 Joypad \xE2\x86\x92") /* Right */
77   PORT_BIT( 0x00c0, IP_ACTIVE_HIGH, IPT_UNUSED )
78   PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_BUTTON4 )        PORT_PLAYER(2) PORT_NAME("P2 Button L")
79   PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_BUTTON5 )        PORT_PLAYER(2) PORT_NAME("P2 Button R")
80   PORT_BIT( 0x0008, IP_ACTIVE_HIGH, IPT_BUTTON6 )        PORT_PLAYER(2) PORT_NAME("P2 Button C \xE2\x86\x91") /* Up */
81   PORT_BIT( 0x0004, IP_ACTIVE_HIGH, IPT_BUTTON7 )        PORT_PLAYER(2) PORT_NAME("P2 Button C \xE2\x86\x93") /* Down */
82   PORT_BIT( 0x0002, IP_ACTIVE_HIGH, IPT_BUTTON8 )        PORT_PLAYER(2) PORT_NAME("P2 Button C \xE2\x86\x90") /* Left */
83   PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_BUTTON9 )        PORT_PLAYER(2) PORT_NAME("P2 Button C \xE2\x86\x92") /* Right */
84
85   PORT_START("P2_ANALOG_X")
86   PORT_BIT( 0xff, 0x80, IPT_AD_STICK_X ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(30) PORT_KEYDELTA(30) PORT_PLAYER(2)
87
88   PORT_START("P2_ANALOG_Y")
89   PORT_BIT( 0xff, 0x80, IPT_AD_STICK_Y ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(30) PORT_KEYDELTA(30) PORT_PLAYER(2) PORT_REVERSE
90
91INPUT_PORTS_END
92
93/* ?? */
94static const mips3_config config =
95{
96   16384,            /* code cache size */
97   8192,            /* data cache size */
98   62500000         /* system clock */
99};
100
101static INTERRUPT_GEN( n64_vblank )
102{
103   signal_rcp_interrupt(device->machine(), VI_INTERRUPT);
104}
105
106static DEVICE_IMAGE_LOAD(n64_cart)
107{
108   int i, length;
109   UINT8 *cart = image.device().machine().region("user2")->base();
110
111   if (image.software_entry() == NULL)
112   {
113      length = image.fread( cart, 0x4000000);
114   }
115   else
116   {
117      length = image.get_software_region_length("rom");
118      memcpy(cart, image.get_software_region("rom"), length);
119   }
120
121   if (cart[0] == 0x37 && cart[1] == 0x80)
122   {
123      for (i = 0; i < length; i += 4)
124      {
125         UINT8 b1 = cart[i + 0];
126         UINT8 b2 = cart[i + 1];
127         UINT8 b3 = cart[i + 2];
128         UINT8 b4 = cart[i + 3];
129         cart[i + 0] = b3;
130         cart[i + 1] = b4;
131         cart[i + 2] = b1;
132         cart[i + 3] = b2;
133      }
134   }
135   else
136   {
137      for (i = 0; i < length; i += 4)
138      {
139         UINT8 b1 = cart[i + 0];
140         UINT8 b2 = cart[i + 1];
141         UINT8 b3 = cart[i + 2];
142         UINT8 b4 = cart[i + 3];
143         cart[i + 0] = b4;
144         cart[i + 1] = b3;
145         cart[i + 2] = b2;
146         cart[i + 3] = b1;
147      }
148   }
149
150   logerror("cart length = %d\n", length);
151   return IMAGE_INIT_PASS;
152}
153
154static MACHINE_CONFIG_START( n64, _n64_state )
155
156   /* basic machine hardware */
157   MCFG_CPU_ADD("maincpu", VR4300BE, 93750000)
158   MCFG_CPU_CONFIG(config)
159   MCFG_CPU_PROGRAM_MAP(n64_map)
160   MCFG_CPU_VBLANK_INT("screen", n64_vblank)
161
162   MCFG_CPU_ADD("rsp", RSP, 62500000)
163   MCFG_CPU_CONFIG(n64_rsp_config)
164   MCFG_CPU_PROGRAM_MAP(rsp_map)
165
166   MCFG_MACHINE_START( n64 )
167   MCFG_MACHINE_RESET( n64 )
168   MCFG_QUANTUM_TIME(attotime::from_hz(600))
169
170   /* video hardware */
171   MCFG_SCREEN_ADD("screen", RASTER)
172   MCFG_SCREEN_REFRESH_RATE(60)
173   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
174   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
175   MCFG_SCREEN_SIZE(640, 525)
176   MCFG_SCREEN_VISIBLE_AREA(0, 639, 0, 239)
177   MCFG_SCREEN_UPDATE(n64)
178
179   MCFG_PALETTE_LENGTH(0x1000)
180
181   MCFG_VIDEO_START(n64)
182
183   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
184
185   MCFG_SOUND_ADD("dac2", DMADAC, 0)
186   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 1.0)
187   MCFG_SOUND_ADD("dac1", DMADAC, 0)
188   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 1.0)
189
190   /* cartridge */
191   MCFG_CARTSLOT_ADD("cart")
192   MCFG_CARTSLOT_EXTENSION_LIST("v64,z64,rom,n64,bin")
193   MCFG_CARTSLOT_MANDATORY
194   MCFG_CARTSLOT_INTERFACE("n64_cart")
195   MCFG_CARTSLOT_LOAD(n64_cart)
196
197   /* software lists */
198   MCFG_SOFTWARE_LIST_ADD("cart_list","n64")
199MACHINE_CONFIG_END
200
201ROM_START( n64 )
202   ROM_REGION( 0x800000, "maincpu", ROMREGION_ERASEFF )      /* dummy region for R4300 */
203
204   ROM_REGION32_BE( 0x800, "user1", 0 )
205   ROM_LOAD( "pifdata.bin", 0x0000, 0x0800, CRC(5ec82be9) SHA1(9174eadc0f0ea2654c95fd941406ab46b9dc9bdd) )
206
207   ROM_REGION32_BE( 0x4000000, "user2", ROMREGION_ERASEFF)
208
209   ROM_REGION16_BE( 0x80, "normpoint", 0 )
210   ROM_LOAD( "normpnt.rom", 0x00, 0x80, CRC(e7f2a005) SHA1(c27b4a364a24daeee6e99fd286753fd6216362b4) )
211
212   ROM_REGION16_BE( 0x80, "normslope", 0 )
213   ROM_LOAD( "normslp.rom", 0x00, 0x80, CRC(4f2ae525) SHA1(eab43f8cc52c8551d9cff6fced18ef80eaba6f05) )
214ROM_END
215
216CONS(1996, n64,    0,      0,      n64,   n64,   0,   "Nintendo", "Nintendo 64", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
src/mame/drivers/a310.c
r0r11461
1/******************************************************************************
2 *
3 *  Acorn Archimedes 310
4 *
5 *  Skeleton: Juergen Buchmueller <pullmoll@t-online.de>, Jul 2000
6 *  Enhanced: R. Belmont, June 2007
7 *  Angelo Salese, August 2010
8 *
9 *  TODO:
10 *  - try to understand why bios 2 was working at some point and now isn't
11 *  - fix RISC OS / Arthur booting, possible causes:
12 *  \- missing reset page size hook-up
13 *  \- some subtle memory paging fault
14 *  \- missing RAM max size
15 *  \- ARM bug?
16 *
17 *
18=======================================================================================
19 *
20 *      Memory map (from http://b-em.bbcmicro.com/arculator/archdocs.txt)
21 *
22 *  0000000 - 1FFFFFF - logical RAM (32 meg)
23 *  2000000 - 2FFFFFF - physical RAM (supervisor only - max 16MB - requires quad MEMCs)
24 *  3000000 - 33FFFFF - IOC (IO controllers - supervisor only)
25 *  3310000 - FDC - WD1772
26 *  33A0000 - Econet - 6854
27 *  33B0000 - Serial - 6551
28 *  3240000 - 33FFFFF - internal expansion cards
29 *  32D0000 - hard disc controller (not IDE) - HD63463
30 *  3350010 - printer
31 *  3350018 - latch A
32 *  3350040 - latch B
33 *  3270000 - external expansion cards
34 *
35 *  3400000 - 3FFFFFF - ROM (read - 12 meg - Arthur and RiscOS 2 512k, RiscOS 3 2MB)
36 *  3400000 - 37FFFFF - Low ROM  (4 meg, I think this is expansion ROMs)
37 *  3800000 - 3FFFFFF - High ROM (main OS ROM)
38 *
39 *  3400000 - 35FFFFF - VICD10 (write - supervisor only)
40 *  3600000 - 3FFFFFF - MEMC (write - supervisor only)
41 *
42 *****************************************************************************/
43/*
44    DASM of code (bios 2 / RISC OS 2)
45    0x380d4e0: MEMC: control to 0x10c (page size 32 kbytes, DRAM ram refresh only during flyback)
46    0x380d4f0: VIDC: params (screen + sound frequency)
47    0x380d51c: IOC: sets control to 0xff, clear IRQA and FIQ masks, sets IRQB mask to 0x80 (keyboard receive full irq)
48    0x380d530: IOC: sets timer 0 to 0x4e20, go command
49        0x380e0a8: work RAM physical check, max size etc.
50    0x380e1f8: IOC: Disables DRAM ram refresh, sets timer 1 to 0x7ffe, go command, then it tests the latch of this timer, enables DRAM refresh
51        0x380d00c: Set up default logical space
52        0x380d16c: Set up case by case logical space
53
54
55*/
56
57
58#include "emu.h"
59#include "machine/wd17xx.h"
60#include "imagedev/flopdrv.h"
61#include "cpu/arm/arm.h"
62#include "sound/dac.h"
63#include "includes/archimds.h"
64#include "machine/i2cmem.h"
65#include "machine/ram.h"
66
67
68class a310_state : public driver_device
69{
70public:
71   a310_state(const machine_config &mconfig, device_type type, const char *tag)
72      : driver_device(mconfig, type, tag) { }
73
74};
75
76
77static WRITE_LINE_DEVICE_HANDLER( a310_wd177x_intrq_w )
78{
79   if (state)
80      archimedes_request_fiq(device->machine(), ARCHIMEDES_FIQ_FLOPPY);
81   else
82      archimedes_clear_fiq(device->machine(), ARCHIMEDES_FIQ_FLOPPY);
83}
84
85static WRITE_LINE_DEVICE_HANDLER( a310_wd177x_drq_w )
86{
87   if (state)
88      archimedes_request_fiq(device->machine(), ARCHIMEDES_FIQ_FLOPPY_DRQ);
89   else
90      archimedes_clear_fiq(device->machine(), ARCHIMEDES_FIQ_FLOPPY_DRQ);
91}
92
93static READ32_HANDLER( a310_psy_wram_r )
94{
95   return archimedes_memc_physmem[offset];
96}
97
98static WRITE32_HANDLER( a310_psy_wram_w )
99{
100   COMBINE_DATA(&archimedes_memc_physmem[offset]);
101}
102
103
104static DRIVER_INIT(a310)
105{
106   UINT32 ram_size = ram_get_size(machine.device(RAM_TAG));
107
108   archimedes_memc_physmem = auto_alloc_array(machine, UINT32, 0x01000000);
109
110   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_readwrite_handler( 0x02000000, 0x02000000+(ram_size-1), FUNC(a310_psy_wram_r), FUNC(a310_psy_wram_w) );
111
112   archimedes_driver_init(machine);
113}
114
115static MACHINE_START( a310 )
116{
117   archimedes_init(machine);
118
119   // reset the DAC to centerline
120   //dac_signed_data_w(machine.device("dac"), 0x80);
121}
122
123static MACHINE_RESET( a310 )
124{
125   archimedes_reset(machine);
126}
127
128static ADDRESS_MAP_START( a310_mem, AS_PROGRAM, 32 )
129   AM_RANGE(0x00000000, 0x01ffffff) AM_READWRITE(archimedes_memc_logical_r, archimedes_memc_logical_w)
130//  AM_RANGE(0x02000000, 0x02ffffff) AM_RAM AM_BASE(&archimedes_memc_physmem) /* physical RAM - 16 MB for now, should be 512k for the A310 */
131   AM_RANGE(0x03000000, 0x033fffff) AM_READWRITE(archimedes_ioc_r, archimedes_ioc_w)
132   AM_RANGE(0x03400000, 0x035fffff) AM_READWRITE(archimedes_vidc_r, archimedes_vidc_w)
133   AM_RANGE(0x03600000, 0x037fffff) AM_READWRITE(archimedes_memc_r, archimedes_memc_w)
134   AM_RANGE(0x03800000, 0x03ffffff) AM_ROM AM_REGION("maincpu", 0) AM_WRITE(archimedes_memc_page_w)
135ADDRESS_MAP_END
136
137
138static INPUT_PORTS_START( a310 )
139   PORT_START("dip") /* DIP switches */
140   PORT_BIT(0xfd, 0xfd, IPT_UNUSED)
141
142   PORT_START("key0") /* KEY ROW 0 */
143   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("ESC") PORT_CODE(KEYCODE_ESC)
144   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("1  !") PORT_CODE(KEYCODE_1)
145   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("2  \"") PORT_CODE(KEYCODE_2)
146   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("3  #") PORT_CODE(KEYCODE_3)
147   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("4  $") PORT_CODE(KEYCODE_4)
148   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME("5  %") PORT_CODE(KEYCODE_5)
149   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("6  &") PORT_CODE(KEYCODE_6)
150   PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("7  '") PORT_CODE(KEYCODE_7)
151
152   PORT_START("key1") /* KEY ROW 1 */
153   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("8  *") PORT_CODE(KEYCODE_8)
154   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("9  (") PORT_CODE(KEYCODE_9)
155   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("0  )") PORT_CODE(KEYCODE_0)
156   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("-  _") PORT_CODE(KEYCODE_MINUS)
157   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("=  +") PORT_CODE(KEYCODE_EQUALS)
158   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME("`  ~") PORT_CODE(KEYCODE_TILDE)
159   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("BACK SPACE") PORT_CODE(KEYCODE_BACKSPACE)
160   PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("TAB") PORT_CODE(KEYCODE_TAB)
161
162   PORT_START("key2") /* KEY ROW 2 */
163   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("q  Q") PORT_CODE(KEYCODE_Q)
164   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("w  W") PORT_CODE(KEYCODE_W)
165   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("e  E") PORT_CODE(KEYCODE_E)
166   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("r  R") PORT_CODE(KEYCODE_R)
167   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("t  T") PORT_CODE(KEYCODE_T)
168   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME("y  Y") PORT_CODE(KEYCODE_Y)
169   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("u  U") PORT_CODE(KEYCODE_U)
170   PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("i  I") PORT_CODE(KEYCODE_I)
171
172   PORT_START("key3") /* KEY ROW 3 */
173   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("o  O") PORT_CODE(KEYCODE_O)
174   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("p  P") PORT_CODE(KEYCODE_P)
175   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("[  {") PORT_CODE(KEYCODE_OPENBRACE)
176   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("]  }") PORT_CODE(KEYCODE_CLOSEBRACE)
177   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("RETURN") PORT_CODE(KEYCODE_ENTER)
178   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME("DEL") PORT_CODE(KEYCODE_DEL)
179   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("CTRL") PORT_CODE(KEYCODE_LCONTROL)
180   PORT_BIT(0x80, 0x80, IPT_KEYBOARD) PORT_NAME("CAPS LOCK") PORT_CODE(KEYCODE_CAPSLOCK) PORT_TOGGLE
181
182   PORT_START("key4") /* KEY ROW 4 */
183   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("a  A") PORT_CODE(KEYCODE_A)
184   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("s  S") PORT_CODE(KEYCODE_S)
185   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("d  D") PORT_CODE(KEYCODE_D)
186   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("f  F") PORT_CODE(KEYCODE_F)
187   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("g  G") PORT_CODE(KEYCODE_G)
188   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME("h  H") PORT_CODE(KEYCODE_H)
189   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("j  J") PORT_CODE(KEYCODE_J)
190   PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("k  K") PORT_CODE(KEYCODE_K)
191
192   PORT_START("key5") /* KEY ROW 5 */
193   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("l  L") PORT_CODE(KEYCODE_L)
194   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME(";  :") PORT_CODE(KEYCODE_COLON)
195   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("'  \"") PORT_CODE(KEYCODE_QUOTE)
196   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("\\  |") PORT_CODE(KEYCODE_ASTERISK)
197   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("SHIFT (L)") PORT_CODE(KEYCODE_LSHIFT)
198   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME("z  Z") PORT_CODE(KEYCODE_Z)
199   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("x  X") PORT_CODE(KEYCODE_X)
200   PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("c  C") PORT_CODE(KEYCODE_C)
201
202   PORT_START("key6") /* KEY ROW 6 */
203   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("v  V") PORT_CODE(KEYCODE_V)
204   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("b  B") PORT_CODE(KEYCODE_B)
205   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("n  N") PORT_CODE(KEYCODE_N)
206   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("m  M") PORT_CODE(KEYCODE_M)
207   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME(",  <") PORT_CODE(KEYCODE_COMMA)
208   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME(".  >") PORT_CODE(KEYCODE_STOP)
209   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("/  ?") PORT_CODE(KEYCODE_SLASH)
210   PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("SHIFT (R)") PORT_CODE(KEYCODE_RSHIFT)
211
212   PORT_START("key7") /* KEY ROW 7 */
213   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("LINE FEED")
214   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("SPACE") PORT_CODE(KEYCODE_SPACE)
215   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("- (KP)") PORT_CODE(KEYCODE_MINUS_PAD)
216   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME(", (KP)") PORT_CODE(KEYCODE_PLUS_PAD)
217   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("ENTER (KP)") PORT_CODE(KEYCODE_ENTER_PAD)
218   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME(". (KP)") PORT_CODE(KEYCODE_DEL_PAD)
219   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("0 (KP)") PORT_CODE(KEYCODE_0_PAD)
220   PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("1 (KP)") PORT_CODE(KEYCODE_1_PAD)
221
222   PORT_START("key8") /* KEY ROW 8 */
223   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("2 (KP)") PORT_CODE(KEYCODE_2_PAD)
224   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("3 (KP)") PORT_CODE(KEYCODE_3_PAD)
225   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("4 (KP)") PORT_CODE(KEYCODE_4_PAD)
226   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("5 (KP)") PORT_CODE(KEYCODE_5_PAD)
227   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("6 (KP)") PORT_CODE(KEYCODE_6_PAD)
228   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME("7 (KP)") PORT_CODE(KEYCODE_7_PAD)
229   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("8 (KP)") PORT_CODE(KEYCODE_8_PAD)
230   PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("9 (KP)") PORT_CODE(KEYCODE_9_PAD)
231
232   PORT_START("via1a") /* VIA #1 PORT A */
233   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START) PORT_PLAYER(1)
234   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START) PORT_PLAYER(2)
235   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1                )
236   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON2                )
237   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT) PORT_4WAY
238   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_UP) PORT_4WAY
239   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT) PORT_4WAY
240   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN) PORT_4WAY
241
242   PORT_START("tape")/* tape control */
243   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("TAPE STOP") PORT_CODE(KEYCODE_F5)
244   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("TAPE PLAY") PORT_CODE(KEYCODE_F6)
245   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("TAPE REW") PORT_CODE(KEYCODE_F7)
246   PORT_BIT (0xf8, 0x80, IPT_UNUSED)
247INPUT_PORTS_END
248
249static const wd17xx_interface a310_wd17xx_interface =
250{
251   DEVCB_NULL,
252   DEVCB_LINE(a310_wd177x_intrq_w),
253   DEVCB_LINE(a310_wd177x_drq_w),
254   {FLOPPY_0, FLOPPY_1, FLOPPY_2, FLOPPY_3}
255};
256
257static const i2cmem_interface i2cmem_interface =
258{
259   I2CMEM_SLAVE_ADDRESS, 0, 0x100
260};
261
262static MACHINE_CONFIG_START( a310, a310_state )
263   /* basic machine hardware */
264   MCFG_CPU_ADD("maincpu", ARM, 8000000)        /* 8 MHz */
265   MCFG_CPU_PROGRAM_MAP(a310_mem)
266
267   MCFG_MACHINE_START( a310 )
268   MCFG_MACHINE_RESET( a310 )
269
270   MCFG_I2CMEM_ADD("i2cmem",i2cmem_interface)
271
272   /* video hardware */
273   MCFG_SCREEN_ADD("screen", RASTER)
274   MCFG_SCREEN_REFRESH_RATE(60)
275   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
276   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
277   MCFG_SCREEN_SIZE(1280, 1024) //TODO: default screen size
278   MCFG_SCREEN_VISIBLE_AREA(0*8, 1280 - 1, 0*16, 1024 - 1)
279   MCFG_SCREEN_UPDATE(archimds_vidc)
280
281   MCFG_PALETTE_LENGTH(32768)
282
283   MCFG_VIDEO_START(archimds_vidc)
284
285   MCFG_RAM_ADD(RAM_TAG)
286   MCFG_RAM_DEFAULT_SIZE("2M")
287   MCFG_RAM_EXTRA_OPTIONS("512K, 1M, 4M, 8M, 16M")
288
289   MCFG_WD1772_ADD("wd1772", a310_wd17xx_interface )
290
291   //MCFG_FLOPPY_4_DRIVES_ADD(a310_floppy_config)
292
293   MCFG_SPEAKER_STANDARD_MONO("mono")
294   MCFG_SOUND_ADD("dac0", DAC, 0)
295   MCFG_SOUND_ROUTE(0, "mono", 0.10)
296
297   MCFG_SOUND_ADD("dac1", DAC, 0)
298   MCFG_SOUND_ROUTE(0, "mono", 0.10)
299
300   MCFG_SOUND_ADD("dac2", DAC, 0)
301   MCFG_SOUND_ROUTE(0, "mono", 0.10)
302
303   MCFG_SOUND_ADD("dac3", DAC, 0)
304   MCFG_SOUND_ROUTE(0, "mono", 0.10)
305
306   MCFG_SOUND_ADD("dac4", DAC, 0)
307   MCFG_SOUND_ROUTE(0, "mono", 0.10)
308
309   MCFG_SOUND_ADD("dac5", DAC, 0)
310   MCFG_SOUND_ROUTE(0, "mono", 0.10)
311
312   MCFG_SOUND_ADD("dac6", DAC, 0)
313   MCFG_SOUND_ROUTE(0, "mono", 0.10)
314
315   MCFG_SOUND_ADD("dac7", DAC, 0)
316   MCFG_SOUND_ROUTE(0, "mono", 0.10)
317MACHINE_CONFIG_END
318
319ROM_START(a310)
320   ROM_REGION( 0x800000, "maincpu", 0 )
321   ROM_SYSTEM_BIOS( 0, "311", "RiscOS 3.11 (29 Sep 1992)" )
322   ROMX_LOAD( "ic24.rom", 0x000000, 0x80000, CRC(c1adde84) SHA1(12d060e0401dd0523d44453f947bdc55dd2c3240), ROM_BIOS(1) )
323   ROMX_LOAD( "ic25.rom", 0x080000, 0x80000, CRC(15d89664) SHA1(78f5d0e6f1e8ee603317807f53ff8fe65a3b3518), ROM_BIOS(1) )
324   ROMX_LOAD( "ic26.rom", 0x100000, 0x80000, CRC(a81ceb7c) SHA1(46b870876bc1f68f242726415f0c49fef7be0c72), ROM_BIOS(1) )
325   ROMX_LOAD( "ic27.rom", 0x180000, 0x80000, CRC(707b0c6c) SHA1(345199a33fed23996374b9db8170a52ab63f0380), ROM_BIOS(1) )
326   ROM_SYSTEM_BIOS( 1, "120", "Arthur/RiscOS 1.20 (25 Sep 1987)" )
327   ROMX_LOAD( "arthur.bin",   0x000000, 0x080000, CRC(eb3fda57) SHA1(1181ff9c2c2f3d6d414054ec33b2260404bafc81), ROM_BIOS(2) )
328   ROM_SYSTEM_BIOS( 2, "200", "RiscOS 2.0 (05 Oct 1988)" )
329   ROMX_LOAD( "riscos2.bin",  0x000000, 0x080000, CRC(89c4ad36) SHA1(b82a78830dac386f9b649b6d32a34f9c6910546d), ROM_BIOS(3) )
330
331   ROM_REGION( 0x200000, "vram", ROMREGION_ERASE00 )
332
333   ROM_REGION( 0x100, "i2cmem", ROMREGION_ERASE00 )
334ROM_END
335
336/*    YEAR  NAME  PARENT  COMPAT  MACHINE  INPUT  INIT   COMPANY  FULLNAME */
337COMP( 1988, a310, 0,      0,      a310,    a310,  a310,   "Acorn", "Archimedes 310", GAME_NOT_WORKING)
src/emu/emu.mak
r11460r11461
138138EMUMACHINEOBJS = \
139139   $(EMUMACHINE)/53c810.o      \
140140   $(EMUMACHINE)/6522via.o      \
141   $(EMUMACHINE)/6525tpi.o      \
141142   $(EMUMACHINE)/6526cia.o      \
142143   $(EMUMACHINE)/6532riot.o   \
143144   $(EMUMACHINE)/6821pia.o      \
r11460r11461
192193   $(EMUMACHINE)/ldpr8210.o   \
193194   $(EMUMACHINE)/ldv1000.o      \
194195   $(EMUMACHINE)/ldvp931.o      \
196   $(EMUMACHINE)/matsucd.o      \
195197   $(EMUMACHINE)/mb14241.o      \
196198   $(EMUMACHINE)/mb3773.o      \
197199   $(EMUMACHINE)/mb87078.o      \
r11460r11461
236238   $(EMUMACHINE)/upd4701.o      \
237239   $(EMUMACHINE)/upd7201.o      \
238240   $(EMUMACHINE)/upd765.o      \
241   $(EMUMACHINE)/wd17xx.o      \
239242   $(EMUMACHINE)/wd33c93.o      \
240243   $(EMUMACHINE)/x2212.o      \
241244   $(EMUMACHINE)/x76f041.o      \
src/emu/machine/matsucd.c
r0r11461
1/***************************************************************************
2
3    Matsushita/Panasonic CDR521/522 type CDROM drive emulation
4
5Notes:
6This version implements the drive found in Amiga CDTV. There are
7different drives supporting this command-set (look in the sbpcd driver
8in Linux for examples). Most drives support the exact same command
9structure, but the command numbers differ. Eventually this driver
10can be expanded with support for the other drives as needed.
11
12***************************************************************************/
13
14
15#include "emu.h"
16#include "imagedev/chd_cd.h"
17#include "sound/cdda.h"
18#include "machine/matsucd.h"
19
20
21#define MATSU_STATUS_READY      ( 1 << 0 )   /* driver ready */
22#define MATSU_STATUS_DOORLOCKED   ( 1 << 1 )   /* door locked */
23#define MATSU_STATUS_PLAYING   ( 1 << 2 )   /* drive playing */
24#define MATSU_STATUS_SUCCESS   ( 1 << 3 )   /* last command was succesful */
25#define MATSU_STATUS_ERROR      ( 1 << 4 )   /* last command failed */
26#define MATSU_STATUS_MOTOR      ( 1 << 5 )   /* spinning */
27#define MATSU_STATUS_MEDIA      ( 1 << 6 )   /* media present (in caddy or tray) */
28#define MATSU_STATUS_DOORCLOSED   ( 1 << 7 )   /* tray status */
29
30typedef struct
31{
32   UINT8   enabled;      /* /ENABLE - Unit enabled */
33   UINT8   cmd_signal;      /* /CMD - Command mode   */
34   UINT8   stch_signal;   /* /STCH - Status Changed */
35   UINT8   sten_signal;   /* /STEN - Status Enabled */
36   UINT8   scor_signal;   /* /STEN - Subcode Ready */
37   UINT8   input[16];
38   UINT8   input_pos;
39   UINT8   output[16];
40   UINT8   output_pos;
41   UINT8   output_len;
42   UINT8   status;
43   UINT8   motor;
44   UINT16   sector_size;
45   UINT32   lba;
46   UINT16   num_blocks;
47   UINT16   xfer_offset;
48   UINT8   sector_buffer[CD_MAX_SECTOR_DATA];
49   UINT8   cdda_set;
50   void (*sten_cb)( running_machine &machine, int level );   /* Status enabled callback */
51   void (*stch_cb)( running_machine &machine, int level );   /* Status changed callback */
52   void (*scor_cb)( running_machine &machine, int level );   /* Subcode ready callback */
53   cdrom_file *cdrom;
54   device_t *cdda;
55   emu_timer *frame_timer;
56} matsucd;
57
58static matsucd cd;
59
60#define MSF2LBA(msf) (((msf >> 16) & 0xff) * 60 * 75 + ((msf >> 8) & 0xff) * 75 + ((msf >> 0) & 0xff))
61#define LBA2MSF(lba) (((lba / (75 * 60)) << 16) | (((lba / 75) % 60) << 8) | (lba % 75))
62
63static TIMER_CALLBACK(matsu_subcode_proc);
64
65void matsucd_init( device_t *cdrom_device, const char *cdda_tag )
66{
67   memset(&cd, 0, sizeof( matsucd ) );
68
69   cd.cdrom = cd_get_cdrom_file( cdrom_device );
70   cd.cdda = cdrom_device->machine().device(cdda_tag);
71
72   cd.frame_timer = cdrom_device->machine().scheduler().timer_alloc(FUNC(matsu_subcode_proc));
73
74   cd.stch_signal = 1;
75}
76
77void matsucd_set_status_enabled_callback( void (*sten_cb)( running_machine &machine, int level ) )
78{
79   /* add the callback for status enabled signal */
80   cd.sten_cb = sten_cb;
81}
82
83void matsucd_set_status_changed_callback( void (*stch_cb)( running_machine &machine, int level ) )
84{
85   /* add the callback for status changed signal */
86   cd.stch_cb = stch_cb;
87}
88
89void matsucd_set_subcode_ready_callback( void (*scor_cb)( running_machine &machine, int level ) )
90{
91   /* add the callback for subcode ready signal */
92   cd.scor_cb = scor_cb;
93}
94
95static int matsucd_getsector_type( void )
96{
97   switch( cd.sector_size )
98   {
99      case 2048: return CD_TRACK_MODE1;
100      case 2324: return CD_TRACK_MODE2_FORM2;
101      case 2336: return CD_TRACK_MODE2;
102      case 2352: return CD_TRACK_MODE2_RAW;
103
104      default: logerror( "MATSUCD: Sector size %d unsupported!\n", cd.sector_size ); break;
105   }
106
107   return CD_TRACK_RAW_DONTCARE;
108}
109
110void matsucd_read_next_block( void )
111{
112   cd.xfer_offset = 0;
113
114   if ( cd.num_blocks )
115   {
116      cd.lba++;
117      cd.num_blocks--;
118
119      if (!cdrom_read_data(cd.cdrom, cd.lba, cd.sector_buffer, matsucd_getsector_type()))
120      {
121         logerror( "MATSUCD - Warning: Read error on CD!\n" );
122      }
123   }
124}
125
126int matsucd_get_next_byte( UINT8 *data )
127{
128   /* no more data to read on this sector */
129   if ( cd.xfer_offset >= cd.sector_size )
130      return -1;
131
132   if ( data )
133      *data = cd.sector_buffer[cd.xfer_offset++];
134
135   return 0;
136}
137
138static void matsucd_cdda_stop( running_machine &machine )
139{
140   device_t *cdda = cdda_from_cdrom(machine, cd.cdrom);
141
142   if (cdda != NULL)
143   {
144      cdda_stop_audio(cdda);
145      cd.frame_timer->reset(  );
146   }
147}
148
149static void matsucd_cdda_play( running_machine &machine, UINT32 lba, UINT32 num_blocks )
150{
151   device_t *cdda = cdda_from_cdrom(machine, cd.cdrom);
152   if (cdda != NULL)
153   {
154      cdda_start_audio(cdda, lba, num_blocks);
155      cd.frame_timer->adjust(attotime::from_hz( 75 ));
156   }
157}
158
159static void matsucd_cdda_pause( running_machine &machine, int pause )
160{
161   device_t *cdda = cdda_from_cdrom(machine, cd.cdrom);
162   if (cdda != NULL)
163   {
164      cdda_pause_audio(cdda, pause);
165
166      if ( pause )
167      {
168         cd.frame_timer->reset(  );
169      }
170      else
171      {
172         cd.frame_timer->adjust(attotime::from_hz( 75 ));
173      }
174   }
175}
176
177static UINT8 matsucd_cdda_getstatus( running_machine &machine, UINT32 *lba )
178{
179   device_t *cdda = cdda_from_cdrom(machine, cd.cdrom);
180
181   if ( lba ) *lba = 0;
182
183   if (cdda != NULL)
184   {
185      if (cdda_audio_active(cdda))
186      {
187         if ( lba ) *lba = cdda_get_audio_lba(cdda);
188
189         if (cdda_audio_paused(cdda))
190         {
191            return 0x12;   /* audio paused */
192         }
193         else
194         {
195            return 0x11;   /* audio in progress */
196         }
197      }
198      else if (cdda_audio_ended(cdda))
199      {
200         return 0x13;   /* audio ended */
201      }
202   }
203
204   return 0x15;   /* no audio status */
205}
206
207void matsucd_enable_w( int level )
208{
209   cd.enabled = ( level ) ? 0 : 1;
210}
211
212void matsucd_cmd_w( int level )
213{
214   cd.cmd_signal = ( level ) ? 0 : 1;
215}
216
217int matsucd_stch_r( void )
218{
219   return cd.stch_signal ? 0 : 1;
220}
221
222int matsucd_sten_r( void )
223{
224   return cd.sten_signal ? 0 : 1;
225}
226
227int matsucd_scor_r( void )
228{
229   return cd.scor_signal ? 0 : 1;
230}
231
232static void update_status_enable( running_machine &machine, int level )
233{
234   cd.sten_signal = level;
235
236   if ( cd.sten_cb )
237   {
238      (*cd.sten_cb)(machine, cd.sten_signal);
239   }
240}
241
242static void update_status_changed( running_machine &machine, int level )
243{
244   cd.stch_signal = level;
245
246   if ( cd.stch_cb )
247   {
248      (*cd.stch_cb)(machine, cd.stch_signal);
249   }
250}
251
252static void update_subcode_ready( running_machine &machine, int level )
253{
254   cd.scor_signal = level;
255
256   if ( cd.scor_cb )
257   {
258      (*cd.scor_cb)(machine, cd.scor_signal);
259   }
260}
261
262static TIMER_CALLBACK(matsucd_set_status_end)
263{
264   update_status_changed( machine, 1 );
265}
266
267static void matsucd_set_status( running_machine &machine, UINT8 status )
268{
269   if ( status != cd.status )
270   {
271      cd.status = status;
272
273      if ( cd.stch_signal != 0 )
274      {
275         update_status_changed( machine, 0 );
276         machine.scheduler().timer_set(attotime::from_msec(1), FUNC(matsucd_set_status_end));
277      }
278   }
279}
280
281static TIMER_CALLBACK(matsu_subcode_proc)
282{
283   device_t *cdda = cdda_from_cdrom(machine, cd.cdrom);
284
285   (void)param;
286
287   if (cdda != NULL)
288   {
289      UINT8   s = matsucd_cdda_getstatus(machine, NULL);
290      UINT8   newstatus = cd.status;
291
292      if ( s == 0x11 || s == 0x12 )
293      {
294         if ( s == 0x11 )
295         {
296            update_subcode_ready( machine, 1 );
297            update_subcode_ready( machine, 0 );
298         }
299
300         newstatus |= MATSU_STATUS_PLAYING;
301
302         cd.frame_timer->adjust(attotime::from_hz( 75 ));
303      }
304      else
305      {
306         newstatus &= ~MATSU_STATUS_PLAYING;
307      }
308
309      matsucd_set_status( machine, newstatus );
310   }
311}
312
313static void matsucd_command_error( running_machine &machine )
314{
315   UINT8   newstatus = cd.status;
316
317   newstatus &= ~MATSU_STATUS_SUCCESS;
318   newstatus |= MATSU_STATUS_ERROR;
319
320   matsucd_set_status( machine, newstatus );
321}
322
323static void matsucd_complete_cmd( running_machine &machine, UINT8 len )
324{
325   UINT8   newstatus = cd.status;
326
327   cd.input_pos = 0;
328   cd.output_pos = 0;
329   cd.output_len = len;
330
331   newstatus &= ~MATSU_STATUS_ERROR;
332   newstatus |= MATSU_STATUS_SUCCESS;
333
334   matsucd_set_status( machine, newstatus );
335
336   update_status_enable( machine, 1 );
337   update_status_enable( machine, 0 );
338}
339
340UINT8 matsucd_response_r( running_machine &machine )
341{
342   UINT8   v = cd.output[cd.output_pos++];
343
344   if ( cd.output_pos < cd.output_len )
345   {
346      update_status_enable( machine, 1 );
347      update_status_enable( machine, 0 );
348   }
349
350   return v;
351}
352
353void matsucd_command_w( running_machine &machine, UINT8 data )
354{
355   UINT8   cmd;
356
357   /* make sure we're enabled */
358   if ( cd.enabled == 0 )
359      return;
360
361   /* make sure /CMD is asserted */
362   if ( cd.cmd_signal == 0 )
363      return;
364
365   if ( cd.cdda_set == 0 )
366   {
367      // 2009-10, FP: for some reason, cdda_from_cdrom was not returning the correct
368      // CDDA device. Hence, as a temp workaround, I added the cdda to the struct
369      // and its tag is configured in matsucd_init
370      if ( cd.cdrom )
371         cdda_set_cdrom( cd.cdda, cd.cdrom);
372
373      cd.cdda_set = 1;
374   }
375
376   cd.input[cd.input_pos++] = data;
377
378   cmd = cd.input[0];
379
380   switch( cmd )
381   {
382      case 0x01:   /* seek */
383      {
384         if ( cd.input_pos < 7 )
385            return;
386
387         /* stop CDDA audio if necessary */
388         matsucd_cdda_stop(machine);
389
390         cd.motor = 1;
391
392         memset( cd.output, 0, 6 );
393         matsucd_complete_cmd( machine, 0 );
394      }
395      break;
396
397      case 0x02:   /* read sectors */
398      {
399         if ( cd.input_pos < 7 )
400            return;
401
402         /* stop CDDA audio if necessary */
403         matsucd_cdda_stop(machine);
404
405         /* LBA */
406         cd.lba = cd.input[1];
407         cd.lba <<= 8;
408         cd.lba |= cd.input[2];
409         cd.lba <<= 8;
410         cd.lba |= cd.input[3];
411
412         /* Number of blocks */
413         cd.num_blocks = cd.input[4];
414         cd.num_blocks <<= 8;
415         cd.num_blocks |= cd.input[5];
416
417         /* Reset transfer count */
418         cd.xfer_offset = 0;
419
420         /* go ahead and cache the first block */
421         if (!cdrom_read_data(cd.cdrom, cd.lba, cd.sector_buffer, matsucd_getsector_type()))
422         {
423            logerror( "MATSUCD - Warning: Read error on CD!\n" );
424            matsucd_command_error( machine );
425            return;
426         }
427
428         cd.motor = 1;
429
430         memset( cd.output, 0, 6 );
431         matsucd_complete_cmd( machine, 0 );
432      }
433      break;
434
435      case 0x04:   /* motor on */
436      {
437         if ( cd.input_pos < 7 )
438            return;
439
440         cd.motor = 1;
441
442         memset( cd.output, 0, 6 );
443         matsucd_complete_cmd( machine, 0 );
444      }
445      break;
446
447      case 0x05:   /* motor off */
448      {
449         if ( cd.input_pos < 7 )
450            return;
451
452         /* stop CDDA audio if necessary */
453         matsucd_cdda_stop(machine);
454
455         cd.motor = 0;
456
457         memset( cd.output, 0, 6 );
458         matsucd_complete_cmd( machine, 0 );
459      }
460      break;
461
462      case 0x09:   /* play audio cd, LBA mode */
463      {
464         UINT32   lba, numblocks;
465
466         if ( cd.input_pos < 7 )
467            return;
468
469         lba = cd.input[1];
470         lba <<= 8;
471         lba |= cd.input[2];
472         lba <<= 8;
473         lba |= cd.input[3];
474
475         numblocks = cd.input[4];
476         numblocks <<= 8;
477         numblocks |= cd.input[5];
478         numblocks <<= 8;
479         numblocks |= cd.input[6];
480
481         matsucd_cdda_play( machine, lba, numblocks );
482
483         cd.motor = 1;
484
485         memset( cd.output, 0, 6 );
486         matsucd_complete_cmd( machine, 0 );
487      }
488      break;
489
490      case 0x0a:   /* play audio cd, MSF mode */
491      {
492         UINT32   start, end, lba_start, lba_end;
493
494         if ( cd.input_pos < 7 )
495            return;
496
497         start = cd.input[1];
498         start <<= 8;
499         start |= cd.input[2];
500         start <<= 8;
501         start |= cd.input[3];
502
503         end = cd.input[4];
504         end <<= 8;
505         end |= cd.input[5];
506         end <<= 8;
507         end |= cd.input[6];
508
509         lba_start = MSF2LBA( start );
510         lba_end = MSF2LBA( end );
511
512         if ( end == 0xffffff )
513         {
514            lba_end = cdrom_get_track_start(cd.cdrom,cdrom_get_last_track(cd.cdrom)-1);
515            lba_end += cdrom_get_toc(cd.cdrom)->tracks[cdrom_get_last_track(cd.cdrom)-1].frames;
516         }
517
518         if ( lba_end <= lba_start )
519         {
520            matsucd_cdda_stop(machine);
521         }
522         else
523         {
524            matsucd_cdda_play( machine, lba_start, lba_end - lba_start );
525            cd.motor = 1;
526         }
527
528         memset( cd.output, 0, 6 );
529         matsucd_complete_cmd( machine, 0 );
530      }
531      break;
532
533      case 0x0b:   /* play audio track and index */
534      {
535         UINT8   track_start = cd.input[1];
536         UINT8   index_start = cd.input[2];
537         UINT8   track_end = cd.input[3];
538         UINT8   index_end = cd.input[4];
539         UINT32   lba_start, lba_end;
540
541         /* TODO: Add index support once the CDDA engine supports it */
542         (void)index_start;
543         (void)index_end;
544
545         /* sanitize values */
546         if ( track_start == 0 ) track_start++;
547         if ( track_end == 0 ) track_end++;
548         if ( track_end > cdrom_get_last_track(cd.cdrom) )
549            track_end = cdrom_get_last_track(cd.cdrom);
550
551         /* find the start and stop positions */
552         lba_start = cdrom_get_track_start(cd.cdrom,track_start-1);
553         lba_end = cdrom_get_track_start(cd.cdrom,track_end-1);
554
555         lba_end += cdrom_get_toc(cd.cdrom)->tracks[track_end-1].frames;
556
557         if ( lba_end <= lba_start )
558         {
559            matsucd_cdda_stop(machine);
560         }
561         else
562         {
563            matsucd_cdda_play( machine, lba_start, lba_end - lba_start );
564            cd.motor = 1;
565         }
566
567         memset( cd.output, 0, 6 );
568         matsucd_complete_cmd( machine, 0 );
569      }
570      break;
571
572      case 0x81:   /* status read */
573      {
574         UINT8   newstatus = cd.status;
575
576         newstatus &= MATSU_STATUS_SUCCESS | MATSU_STATUS_ERROR | MATSU_STATUS_PLAYING;
577         newstatus |= MATSU_STATUS_READY;
578
579         if (cd.cdrom)
580         {
581            newstatus |= MATSU_STATUS_MEDIA;
582         }
583
584         if (cd.motor)
585            newstatus |= MATSU_STATUS_MOTOR;
586
587         cd.output[0] = newstatus;
588
589         matsucd_set_status( machine, newstatus );
590
591         matsucd_complete_cmd( machine, 1 );
592      }
593      break;
594
595      case 0x82:   /* error read */
596      {
597         if ( cd.input_pos < 7 )
598            return;
599
600         memset( cd.output, 0, 6 );
601         matsucd_complete_cmd( machine, 6 );
602      }
603      break;
604
605      case 0x84:   /* set mode */
606      {
607         if ( cd.input_pos < 7 )
608            return;
609
610         cd.sector_size = cd.input[2];
611         cd.sector_size <<= 8;
612         cd.sector_size |= cd.input[3];
613
614         memset( cd.output, 0, 6 );
615         matsucd_complete_cmd( machine, 0 );
616      }
617      break;
618
619      case 0x87:   /* read SUBQ */
620      {
621         int      msfmode;
622         UINT32   lba;
623         UINT8   track;
624
625         if ( cd.input_pos < 7 )
626            return;
627
628         msfmode = (cd.input[1] & 0x02) ? 1 : 0;
629
630         memset( cd.output, 0, 13 );
631
632         cd.output[0] = matsucd_cdda_getstatus( machine, &lba );
633
634         if ( lba > 0 )
635         {
636            UINT32   disk_pos;
637            UINT32   track_pos;
638
639            track = cdrom_get_track(cd.cdrom, lba);
640
641            cd.output[1] = cdrom_get_adr_control(cd.cdrom, track);
642            cd.output[2] = track+1;
643            cd.output[3] = 0; /* index */
644
645            disk_pos = lba;
646            if ( msfmode ) disk_pos = LBA2MSF(disk_pos);
647
648            cd.output[4] = (disk_pos >> 24) & 0xff;
649            cd.output[5] = (disk_pos >> 16) & 0xff;
650            cd.output[6] = (disk_pos >> 8) & 0xff;
651            cd.output[7] = (disk_pos) & 0xff;
652
653            track_pos = lba - cdrom_get_track_start(cd.cdrom, track);
654            if ( msfmode ) track_pos = LBA2MSF(track_pos);
655
656            cd.output[8] = (track_pos >> 24) & 0xff;
657            cd.output[9] = (track_pos >> 16) & 0xff;
658            cd.output[10] = (track_pos >> 8) & 0xff;
659            cd.output[11] = (track_pos) & 0xff;
660
661            /* TODO: UPC flag at offset 12 */
662            cd.output[12] = 0;
663         }
664
665         matsucd_complete_cmd( machine, 13 );
666      }
667      break;
668
669      case 0x89:   /* read disk info */
670      {
671         UINT32   end;
672
673         if ( cd.input_pos < 7 )
674            return;
675
676         memset( cd.output, 0, 5 );
677
678         cd.output[0] = cdrom_get_last_track(cd.cdrom) ? 1 : 0;
679         cd.output[1] = cdrom_get_last_track(cd.cdrom);
680         end = cdrom_get_track_start(cd.cdrom,cd.output[1]-1);
681         end += cdrom_get_toc(cd.cdrom)->tracks[cd.output[1]-1].frames;
682         end = LBA2MSF(end);
683         cd.output[2] = (end >> 16) & 0xff;
684         cd.output[3] = (end >> 8) & 0xff;
685         cd.output[4] = (end) & 0xff;
686
687         matsucd_complete_cmd( machine, 5 );
688      }
689      break;
690
691      case 0x8a:   /* read toc */
692      {
693         UINT8   track;
694         int      msfmode;
695         UINT32   track_start;
696
697         if ( cd.input_pos < 7 )
698            return;
699
700         /* stop CDDA audio if necessary */
701         matsucd_cdda_stop(machine);
702
703         track = cd.input[2];
704         msfmode = (cd.input[1] & 0x02) ? 1 : 0;
705
706         if ( cd.cdrom == NULL )
707         {
708            logerror( "MATSUCD - Warning: Reading TOC without a CD!\n" );
709            matsucd_command_error( machine );
710            return;
711         }
712
713         if ( track > cdrom_get_last_track(cd.cdrom) )
714         {
715            logerror( "MATSUCD - Warning: Reading invalid track entry from TOC!\n" );
716            matsucd_command_error( machine );
717            return;
718         }
719
720         memset( cd.output, 0, 7 );
721
722         track_start = cdrom_get_track_start(cd.cdrom, track > 0 ? (track-1) : track );
723         if ( msfmode ) track_start = LBA2MSF( track_start );
724
725         cd.output[1] = cdrom_get_adr_control(cd.cdrom, track > 0 ? (track-1) : track);
726         cd.output[2] = track;
727         cd.output[3] = (track == 0 ) ? cdrom_get_last_track(cd.cdrom) : 0;
728         cd.output[4] = (track_start >> 24) & 0xff;
729         cd.output[5] = (track_start >> 16) & 0xff;
730         cd.output[6] = (track_start >> 8) & 0xff;
731         cd.output[7] = (track_start) & 0xff;
732
733         cd.motor = 1;
734
735         matsucd_complete_cmd( machine, 8 );
736      }
737      break;
738
739      case 0x8b:   /* pause audio */
740      {
741         if ( cd.input_pos < 7 )
742            return;
743
744         matsucd_cdda_pause( machine, (cd.input[1] == 0) ? 1 : 0 );
745         memset( cd.output, 0, 7 );
746         matsucd_complete_cmd( machine, 0 );
747      }
748      break;
749
750      case 0xa3:   /* front panel */
751      {
752         if ( cd.input_pos < 7 )
753            return;
754
755         /* TODO: ??? */
756
757         memset( cd.output, 0, 7 );
758         matsucd_complete_cmd( machine, 0 );
759      }
760      break;
761
762      default:
763         logerror( "MATSUCD: Unknown/inimplemented command %08x\n", cmd );
764      break;
765   }
766}
src/emu/machine/matsucd.h
r0r11461
1/***************************************************************************
2
3    Matsushita/Panasonic CDR521/522 type CDROM drive emulation
4
5***************************************************************************/
6
7/* initialization */
8void matsucd_init( device_t *cdrom_device, const char *cdda_tag );
9
10
11/* signaling */
12extern void matsucd_enable_w( int level );   /* /ENABLE pin */
13extern void matsucd_cmd_w( int level );      /* /CMD pin */
14extern int matsucd_stch_r( void );         /* /STCH pin */
15extern int matsucd_sten_r( void );         /* /STEN pin */
16extern int matsucd_scor_r( void );         /* /SCOR pin */
17
18/* callback for signal changes */
19extern void matsucd_set_status_enabled_callback( void (*sten_cb)( running_machine &machine, int level ) );
20extern void matsucd_set_status_changed_callback( void (*stch_cb)( running_machine &machine, int level ) );
21extern void matsucd_set_subcode_ready_callback( void (*scor_cb)( running_machine &machine, int level ) );
22
23/* data transfer routines */
24extern void matsucd_read_next_block( void );
25extern int matsucd_get_next_byte( UINT8 *data );
26
27/* main command interface */
28extern void matsucd_command_w( running_machine &machine, UINT8 data );
29extern UINT8 matsucd_response_r( running_machine &machine );
src/emu/machine/6525tpi.c
r0r11461
1/***************************************************************************
2    mos tri port interface 6525
3    mos triple interface adapter 6523
4
5    peter.trauner@jk.uni-linz.ac.at
6
7    used in commodore b series
8    used in commodore c1551 floppy disk drive
9***************************************************************************/
10
11/*
12 mos tpi 6525
13 40 pin package
14 3 8 bit ports (pa, pb, pc)
15 8 registers to pc
16 0 port a 0 in low
17 1 port a data direction register 1 output
18 2 port b
19 3 port b ddr
20 4 port c
21  handshaking, interrupt mode
22  0 interrupt 0 input, 1 interrupt enabled
23   interrupt set on falling edge
24  1 interrupt 1 input
25  2 interrupt 2 input
26  3 interrupt 3 input
27  4 interrupt 4 input
28  5 irq output
29  6 ca handshake line (read handshake answer on I3 preferred)
30  7 cb handshake line (write handshake clear on I4 preferred)
31 5 port c ddr
32
33 6 cr configuration register
34  0 mc
35    0 port c normal input output mode like port a and b
36    1 port c used for handshaking and interrupt input
37  1 1 interrupt prioritized
38  2 i3 configure edge
39    1 interrupt set on positive edge
40  3 i4 configure edge
41  5,4 ca handshake
42   00 on read
43      rising edge of i3 sets ca high
44      read a data from computers sets ca low
45   01 pulse output
46      1 microsecond low after read a operation
47   10 manual output low
48   11 manual output high
49  7,6 cb handshake
50   00 handshake on write
51      write b data from computer sets cb 0
52      rising edge of i4 sets cb high
53   01 pulse output
54      1 microsecond low after write b operation
55   10 manual output low
56   11 manual output high
57 7 air active interrupt register
58   0 I0 occurred
59   1 I1 occurred
60   2 I2 occurred
61   3 I3 occurred
62   4 I4 occurred
63   read clears interrupt
64
65 non prioritized interrupts
66  interrupt is set when occurred
67  read clears all interrupts
68
69 prioritized interrupts
70  I4>I3>I2>I1>I0
71  highest interrupt can be found in air register
72  read clears highest interrupt
73*/
74
75#include "emu.h"
76#include "6525tpi.h"
77
78
79/***************************************************************************
80    CONSTANTS
81***************************************************************************/
82
83#define VERBOSE_LEVEL 0
84#define DBG_LOG( MACHINE, N, M, A ) \
85   do { \
86      if(VERBOSE_LEVEL >= N) \
87      { \
88         if( M ) \
89            logerror("%11.6f: %-24s", MACHINE.time().as_double(), (char*) M ); \
90         logerror A; \
91      } \
92   } while (0)
93
94
95#define INTERRUPT_MODE (tpi6525->cr & 1)
96#define PRIORIZED_INTERRUPTS (tpi6525->cr & 2)
97#define INTERRUPT3_RISING_EDGE (tpi6525->cr & 4)
98#define INTERRUPT4_RISING_EDGE (tpi6525->cr & 8)
99#define CA_MANUAL_OUT (tpi6525->cr & 0x20)
100#define CA_MANUAL_LEVEL ((tpi6525->cr & 0x10) ? 1 : 0)
101#define CB_MANUAL_OUT (tpi6525->cr & 0x80)
102#define CB_MANUAL_LEVEL ((tpi6525->cr & 0x40) ? 1 : 0)
103
104
105/***************************************************************************
106    TYPE DEFINITIONS
107***************************************************************************/
108
109typedef struct _tpi6525_state tpi6525_state;
110struct _tpi6525_state
111{
112   devcb_resolved_write_line   out_irq_func;
113   devcb_resolved_read8      in_pa_func;
114   devcb_resolved_write8      out_pa_func;
115   devcb_resolved_read8      in_pb_func;
116   devcb_resolved_write8      out_pb_func;
117   devcb_resolved_read8      in_pc_func;
118   devcb_resolved_write8      out_pc_func;
119   devcb_resolved_write_line   out_ca_func;
120   devcb_resolved_write_line   out_cb_func;
121
122   UINT8 port_a, ddr_a, in_a;
123   UINT8 port_b, ddr_b, in_b;
124   UINT8 port_c, ddr_c, in_c;
125
126   UINT8 ca_level, cb_level, interrupt_level;
127
128   UINT8 cr;
129   UINT8 air;
130
131   UINT8 irq_level[5];
132};
133
134
135/*****************************************************************************
136    INLINE FUNCTIONS
137*****************************************************************************/
138
139INLINE tpi6525_state *get_safe_token(device_t *device)
140{
141   assert(device != NULL);
142   assert(device->type() == TPI6525);
143
144   return (tpi6525_state *)downcast<legacy_device_base *>(device)->token();
145}
146
147
148/*****************************************************************************
149    DEVICE INTERFACE
150*****************************************************************************/
151
152static DEVICE_START( tpi6525 )
153{
154   tpi6525_state *tpi6525 = get_safe_token(device);
155   const tpi6525_interface *intf = (const tpi6525_interface*)device->static_config();
156
157   // resolve callbacks
158   tpi6525->out_irq_func.resolve(intf->out_irq_func, *device);
159   tpi6525->in_pa_func.resolve(intf->in_pa_func, *device);
160   tpi6525->out_pa_func.resolve(intf->out_pa_func, *device);
161   tpi6525->in_pb_func.resolve(intf->in_pb_func, *device);
162   tpi6525->out_pb_func.resolve(intf->out_pb_func, *device);
163   tpi6525->in_pc_func.resolve(intf->in_pc_func, *device);
164   tpi6525->out_pc_func.resolve(intf->out_pc_func, *device);
165   tpi6525->out_ca_func.resolve(intf->out_ca_func, *device);
166   tpi6525->out_cb_func.resolve(intf->out_cb_func, *device);
167
168   /* verify that we have an interface assigned */
169   assert(device->static_config() != NULL);
170
171   /* register for state saving */
172   device->save_item(NAME(tpi6525->port_a));
173   device->save_item(NAME(tpi6525->ddr_a));
174   device->save_item(NAME(tpi6525->in_a));
175   device->save_item(NAME(tpi6525->port_b));
176   device->save_item(NAME(tpi6525->ddr_b));
177   device->save_item(NAME(tpi6525->in_b));
178   device->save_item(NAME(tpi6525->port_c));
179   device->save_item(NAME(tpi6525->ddr_c));
180   device->save_item(NAME(tpi6525->in_c));
181   device->save_item(NAME(tpi6525->ca_level));
182   device->save_item(NAME(tpi6525->cb_level));
183   device->save_item(NAME(tpi6525->interrupt_level));
184   device->save_item(NAME(tpi6525->cr));
185   device->save_item(NAME(tpi6525->air));
186   device->save_item(NAME(tpi6525->irq_level));
187}
188
189
190static DEVICE_RESET( tpi6525 )
191{
192   tpi6525_state *tpi6525 = get_safe_token(device);
193
194   /* setup some initial values */
195   tpi6525->in_a = 0xff;
196   tpi6525->in_b = 0xff;
197   tpi6525->in_c = 0xff;
198}
199
200
201DEVICE_GET_INFO( tpi6525 )
202{
203   switch (state)
204   {
205      /* --- the following bits of info are returned as 64-bit signed integers --- */
206      case DEVINFO_INT_TOKEN_BYTES:         info->i = sizeof(tpi6525_state);      break;
207
208      /* --- the following bits of info are returned as pointers to data or functions --- */
209      case DEVINFO_FCT_START:               info->start = DEVICE_START_NAME( tpi6525 );         break;
210      case DEVINFO_FCT_STOP:               /* Nothing */                              break;
211      case DEVINFO_FCT_RESET:               info->reset = DEVICE_RESET_NAME( tpi6525 );         break;
212
213      /* --- the following bits of info are returned as NULL-terminated strings --- */
214      case DEVINFO_STR_NAME:               strcpy(info->s, "6525 TPI");         break;
215      case DEVINFO_STR_FAMILY:            strcpy(info->s, "6525 TPI");         break;
216      case DEVINFO_STR_VERSION:            strcpy(info->s, "1.0");               break;
217      case DEVINFO_STR_SOURCE_FILE:         strcpy(info->s, __FILE__);            break;
218      case DEVINFO_STR_CREDITS:            strcpy(info->s, "Copyright MESS Team");   break;
219   }
220}
221
222
223/***************************************************************************
224    IMPLEMENTATION
225***************************************************************************/
226
227static void tpi6525_set_interrupt(device_t *device)
228{
229   tpi6525_state *tpi6525 = get_safe_token(device);
230
231   if (!tpi6525->interrupt_level && (tpi6525->air != 0))
232   {
233      tpi6525->interrupt_level = 1;
234
235      DBG_LOG(device->machine(), 3, "tpi6525", ("%s set interrupt\n", device->tag()));
236
237      tpi6525->out_irq_func(tpi6525->interrupt_level);
238   }
239}
240
241
242static void tpi6525_clear_interrupt(device_t *device)
243{
244   tpi6525_state *tpi6525 = get_safe_token(device);
245
246   if (tpi6525->interrupt_level && (tpi6525->air == 0))
247   {
248      tpi6525->interrupt_level = 0;
249
250      DBG_LOG(device->machine(), 3, "tpi6525", ("%s clear interrupt\n", device->tag()));
251
252      tpi6525->out_irq_func(tpi6525->interrupt_level);
253   }
254}
255
256
257WRITE_LINE_DEVICE_HANDLER( tpi6525_i0_w )
258{
259   tpi6525_state *tpi6525 = get_safe_token(device);
260
261   if (INTERRUPT_MODE && (state != tpi6525->irq_level[0]))
262   {
263      tpi6525->irq_level[0] = state;
264
265      if ((state == 0) && !(tpi6525->air & 1) && (tpi6525->ddr_c & 1))
266      {
267         tpi6525->air |= 1;
268         tpi6525_set_interrupt(device);
269      }
270   }
271}
272
273
274WRITE_LINE_DEVICE_HANDLER( tpi6525_i1_w )
275{
276   tpi6525_state *tpi6525 = get_safe_token(device);
277
278   if (INTERRUPT_MODE && (state != tpi6525->irq_level[1]))
279   {
280      tpi6525->irq_level[1] = state;
281
282      if ((state == 0) && !(tpi6525->air & 2) && (tpi6525->ddr_c & 2))
283      {
284         tpi6525->air |= 2;
285         tpi6525_set_interrupt(device);
286      }
287   }
288}
289
290
291WRITE_LINE_DEVICE_HANDLER( tpi6525_i2_w )
292{
293   tpi6525_state *tpi6525 = get_safe_token(device);
294
295   if (INTERRUPT_MODE && (state != tpi6525->irq_level[2]))
296   {
297      tpi6525->irq_level[2] = state;
298
299      if ((state == 0) && !(tpi6525->air & 4) && (tpi6525->ddr_c & 4))
300      {
301         tpi6525->air |= 4;
302         tpi6525_set_interrupt(device);
303      }
304   }
305}
306
307
308WRITE_LINE_DEVICE_HANDLER( tpi6525_i3_w )
309{
310   tpi6525_state *tpi6525 = get_safe_token(device);
311
312   if (INTERRUPT_MODE && (state != tpi6525->irq_level[3]))
313   {
314      tpi6525->irq_level[3] = state;
315
316      if (((INTERRUPT3_RISING_EDGE && (state == 1))
317         || (!INTERRUPT3_RISING_EDGE && (state == 0)))
318         && !(tpi6525->air & 8) && (tpi6525->ddr_c & 8))
319      {
320         tpi6525->air |= 8;
321         tpi6525_set_interrupt(device);
322      }
323   }
324}
325
326
327WRITE_LINE_DEVICE_HANDLER( tpi6525_i4_w )
328{
329   tpi6525_state *tpi6525 = get_safe_token(device);
330
331   if (INTERRUPT_MODE && (state != tpi6525->irq_level[4]) )
332   {
333      tpi6525->irq_level[4] = state;
334
335      if (((INTERRUPT4_RISING_EDGE && (state == 1))
336         ||(!INTERRUPT4_RISING_EDGE&&(state == 0)))
337         && !(tpi6525->air & 0x10) && (tpi6525->ddr_c & 0x10))
338      {
339         tpi6525->air |= 0x10;
340         tpi6525_set_interrupt(device);
341      }
342   }
343}
344
345
346READ8_DEVICE_HANDLER( tpi6525_porta_r )
347{
348   tpi6525_state *tpi6525 = get_safe_token(device);
349   UINT8 data = tpi6525->in_a;
350
351   if (!tpi6525->in_pa_func.isnull())
352      data = tpi6525->in_pa_func(offset);
353
354   data = (data & ~tpi6525->ddr_a) | (tpi6525->ddr_a & tpi6525->port_a);
355
356   return data;
357}
358
359
360WRITE8_DEVICE_HANDLER( tpi6525_porta_w )
361{
362   tpi6525_state *tpi6525 = get_safe_token(device);
363
364   tpi6525->in_a = data;
365}
366
367
368READ8_DEVICE_HANDLER( tpi6525_portb_r )
369{
370   tpi6525_state *tpi6525 = get_safe_token(device);
371   UINT8 data = tpi6525->in_b;
372
373   if (!tpi6525->in_pb_func.isnull())
374      data = tpi6525->in_pb_func(offset);
375
376   data = (data & ~tpi6525->ddr_b) | (tpi6525->ddr_b & tpi6525->port_b);
377
378   return data;
379}
380
381
382WRITE8_DEVICE_HANDLER( tpi6525_portb_w )
383{
384   tpi6525_state *tpi6525 = get_safe_token(device);
385
386   tpi6525->in_b = data;
387}
388
389
390READ8_DEVICE_HANDLER( tpi6525_portc_r )
391{
392   tpi6525_state *tpi6525 = get_safe_token(device);
393   UINT8 data = tpi6525->in_c;
394
395   if (!tpi6525->in_pc_func.isnull())
396      data &= tpi6525->in_pc_func(offset);
397
398   data = (data & ~tpi6525->ddr_c) | (tpi6525->ddr_c & tpi6525->port_c);
399
400   return data;
401}
402
403
404WRITE8_DEVICE_HANDLER( tpi6525_portc_w )
405{
406   tpi6525_state *tpi6525 = get_safe_token(device);
407
408   tpi6525->in_c = data;
409}
410
411
412READ8_DEVICE_HANDLER( tpi6525_r )
413{
414   tpi6525_state *tpi6525 = get_safe_token(device);
415   UINT8 data = 0xff;
416
417   switch (offset & 7)
418   {
419   case 0:
420      data = tpi6525->in_a;
421
422      if (!tpi6525->in_pa_func.isnull())
423         data &= tpi6525->in_pa_func(0);
424
425      data = (data & ~tpi6525->ddr_a) | (tpi6525->ddr_a & tpi6525->port_a);
426
427      break;
428
429   case 1:
430      data = tpi6525->in_b;
431
432      if (!tpi6525->in_pb_func.isnull())
433         data &= tpi6525->in_pb_func(0);
434
435      data = (data & ~tpi6525->ddr_b) | (tpi6525->ddr_b & tpi6525->port_b);
436
437      break;
438
439   case 2:
440      if (INTERRUPT_MODE)
441      {
442         data = 0;
443
444         if (tpi6525->irq_level[0]) data |= 0x01;
445         if (tpi6525->irq_level[1]) data |= 0x02;
446         if (tpi6525->irq_level[2]) data |= 0x04;
447         if (tpi6525->irq_level[3]) data |= 0x08;
448         if (tpi6525->irq_level[4]) data |= 0x10;
449         if (!tpi6525->interrupt_level) data |= 0x20;
450         if (tpi6525->ca_level) data |= 0x40;
451         if (tpi6525->cb_level) data |= 0x80;
452      }
453      else
454      {
455         data = tpi6525->in_c;
456
457         if (!tpi6525->in_pc_func.isnull())
458            data &= tpi6525->in_pc_func(0);
459
460         data = (data & ~tpi6525->ddr_c) | (tpi6525->ddr_c & tpi6525->port_c);
461      }
462
463      DBG_LOG(device->machine(), 2, "tpi6525", ("%s read %.2x %.2x\n", device->tag(), offset, data));
464      break;
465
466   case 3:
467      data = tpi6525->ddr_a;
468      break;
469
470   case 4:
471      data = tpi6525->ddr_b;
472      break;
473
474   case 5:
475      data = tpi6525->ddr_c;
476      break;
477
478   case 6:
479      data = tpi6525->cr;
480      break;
481
482   case 7: /* air */
483      if (PRIORIZED_INTERRUPTS)
484      {
485         if (tpi6525->air & 0x10)
486         {
487            data = 0x10;
488            tpi6525->air &= ~0x10;
489         }
490         else if (tpi6525->air & 8)
491         {
492            data = 8;
493            tpi6525->air &= ~8;
494         }
495         else if (tpi6525->air & 4)
496         {
497            data = 4;
498            tpi6525->air &= ~4;
499         }
500         else if (tpi6525->air & 2)
501         {
502            data = 2;
503            tpi6525->air &= ~2;
504         }
505         else if (tpi6525->air & 1)
506         {
507            data = 1;
508            tpi6525->air &= ~1;
509         }
510      }
511      else
512      {
513         data = tpi6525->air;
514         tpi6525->air = 0;
515      }
516
517      tpi6525_clear_interrupt(device);
518      break;
519
520   }
521
522   DBG_LOG(device->machine(), 3, "tpi6525", ("%s read %.2x %.2x\n", device->tag(), offset, data));
523
524   return data;
525}
526
527
528WRITE8_DEVICE_HANDLER( tpi6525_w )
529{
530   tpi6525_state *tpi6525 = get_safe_token(device);
531
532   DBG_LOG(device->machine(), 2, "tpi6525", ("%s write %.2x %.2x\n", device->tag(), offset, data));
533
534   switch (offset & 7)
535   {
536   case 0:
537      tpi6525->port_a = data;
538      tpi6525->out_pa_func(0, tpi6525->port_a & tpi6525->ddr_a);
539      break;
540
541   case 1:
542      tpi6525->port_b = data;
543      tpi6525->out_pb_func(0, tpi6525->port_b & tpi6525->ddr_b);
544      break;
545
546   case 2:
547      tpi6525->port_c = data;
548
549      if (!INTERRUPT_MODE)
550         tpi6525->out_pc_func(0, tpi6525->port_c & tpi6525->ddr_c);
551      break;
552
553   case 3:
554      tpi6525->ddr_a = data;
555      tpi6525->out_pa_func(0, tpi6525->port_a & tpi6525->ddr_a);
556
557      break;
558
559   case 4:
560      tpi6525->ddr_b = data;
561      tpi6525->out_pb_func(0, tpi6525->port_b & tpi6525->ddr_b);
562      break;
563
564   case 5:
565      tpi6525->ddr_c = data;
566
567      if (!INTERRUPT_MODE)
568         tpi6525->out_pc_func(0, tpi6525->port_c & tpi6525->ddr_c);
569      break;
570
571   case 6:
572      tpi6525->cr = data;
573
574      if (INTERRUPT_MODE)
575      {
576         if (CA_MANUAL_OUT)
577         {
578            if (tpi6525->ca_level != CA_MANUAL_LEVEL)
579            {
580               tpi6525->ca_level = CA_MANUAL_LEVEL;
581               tpi6525->out_ca_func(tpi6525->ca_level);
582            }
583         }
584         if (CB_MANUAL_OUT)
585         {
586            if (tpi6525->cb_level != CB_MANUAL_LEVEL)
587            {
588               tpi6525->cb_level = CB_MANUAL_LEVEL;
589               tpi6525->out_cb_func(tpi6525->cb_level);
590            }
591         }
592      }
593
594      break;
595
596   case 7:
597      /* tpi6525->air = data; */
598      break;
599   }
600}
601
602
603/* this should probably be done better, needed for amigacd.c */
604
605UINT8 tpi6525_get_ddr_a(device_t *device)
606{
607   tpi6525_state *tpi6525 = get_safe_token(device);
608   return tpi6525->ddr_a;
609}
610
611UINT8 tpi6525_get_ddr_b(device_t *device)
612{
613   tpi6525_state *tpi6525 = get_safe_token(device);
614   return tpi6525->ddr_b;
615}
616
617UINT8 tpi6525_get_ddr_c(device_t *device)
618{
619   tpi6525_state *tpi6525 = get_safe_token(device);
620   return tpi6525->ddr_c;
621}
622
623DEFINE_LEGACY_DEVICE(TPI6525, tpi6525);
src/emu/machine/6525tpi.h
r0r11461
1/*****************************************************************************
2 *
3 * machine/tpi6525.h
4 *
5 * mos tri port interface 6525
6 * mos triple interface adapter 6523
7 *
8 * peter.trauner@jk.uni-linz.ac.at
9 *
10 * used in commodore b series
11 * used in commodore c1551 floppy disk drive
12 *
13 * tia6523 is a tpi6525 without control register!?
14 *
15 * tia6523
16 *   only some lines of port b and c are in the pinout!
17 *
18 * connector to floppy c1551 (delivered with c1551 as c16 expansion)
19 *   port a for data read/write
20 *   port b
21 *   0 status 0
22 *   1 status 1
23 *   port c
24 *   6 dav output edge data on port a available
25 *   7 ack input edge ready for next datum
26 *
27 ****************************************************************************/
28
29#ifndef __TPI6525_H__
30#define __TPI6525_H__
31
32
33/***************************************************************************
34    TYPE DEFINITIONS
35***************************************************************************/
36
37typedef struct _tpi6525_interface tpi6525_interface;
38struct _tpi6525_interface
39{
40   devcb_write_line   out_irq_func;
41
42   devcb_read8         in_pa_func;
43   devcb_write8      out_pa_func;
44
45   devcb_read8         in_pb_func;
46   devcb_write8      out_pb_func;
47
48   devcb_read8         in_pc_func;
49   devcb_write8      out_pc_func;
50
51   devcb_write_line   out_ca_func;
52   devcb_write_line   out_cb_func;
53};
54
55
56/***************************************************************************
57    DEVICE CONFIGURATION MACROS
58***************************************************************************/
59
60DECLARE_LEGACY_DEVICE(TPI6525, tpi6525);
61
62#define MCFG_TPI6525_ADD(_tag, _intrf) \
63   MCFG_DEVICE_ADD(_tag, TPI6525, 0) \
64   MCFG_DEVICE_CONFIG(_intrf)
65
66
67/***************************************************************************
68    FUNCTION PROTOTYPES
69***************************************************************************/
70
71READ8_DEVICE_HANDLER( tpi6525_r );
72WRITE8_DEVICE_HANDLER( tpi6525_w );
73
74READ8_DEVICE_HANDLER( tpi6525_porta_r );
75WRITE8_DEVICE_HANDLER( tpi6525_porta_w );
76
77READ8_DEVICE_HANDLER( tpi6525_portb_r );
78WRITE8_DEVICE_HANDLER( tpi6525_portb_w );
79
80READ8_DEVICE_HANDLER( tpi6525_portc_r );
81WRITE8_DEVICE_HANDLER( tpi6525_portc_w );
82
83WRITE_LINE_DEVICE_HANDLER( tpi6525_i0_w );
84WRITE_LINE_DEVICE_HANDLER( tpi6525_i1_w );
85WRITE_LINE_DEVICE_HANDLER( tpi6525_i2_w );
86WRITE_LINE_DEVICE_HANDLER( tpi6525_i3_w );
87WRITE_LINE_DEVICE_HANDLER( tpi6525_i4_w );
88
89UINT8 tpi6525_get_ddr_a(device_t *device);
90UINT8 tpi6525_get_ddr_b(device_t *device);
91UINT8 tpi6525_get_ddr_c(device_t *device);
92
93
94#endif /* __TPI6525_H__ */
src/emu/machine/wd17xx.c
r0r11461
1/***************************************************************************
2
3    wd17xx.c
4
5    Implementations of the Western Digital 17xx and 27xx families of
6    floppy disk controllers
7
8
9    Models:
10
11              DAL   DD   Side   Clock       Remark
12      ---------------------------------------------------------
13      FD1771                    1 or 2 MHz  First model
14      FD1781         x          1 or 2 MHz
15      FD1791         x          1 or 2 MHz
16      FD1792                    1 or 2 MHz
17      FD1793   x     x          1 or 2 MHz
18      FD1794   x                1 or 2 MHz
19      FD1795         x     x    1 or 2 MHz
20      FD1797   x     x     x    1 or 2 MHz
21      FD1761         x          1 MHz
22      FD1762                    1 MHz       ?
23      FD1763   x     x          1 MHz
24      FD1764   x                1 MHz       ?
25      FD1765         x     x    1 MHz
26      FD1767   x     x     x    1 MHz
27      WD2791         x          1 or 2 MHz  Internal data separator
28      WD2793   x     x          1 or 2 MHz  Internal data separator
29      WD2795         x     x    1 or 2 MHz  Internal data separator
30      WD2797   x     x     x    1 or 2 MHz  Internal data separator
31      WD1770         x          8 MHz       Motor On signal
32      WD1772         x          8 MHz       Motor On signal, Faster stepping rates
33      WD1773         x          8 MHz       Enable precomp line
34
35      Notes: - In general, later models include all features of earlier models
36             - DAL: Data access lines, x = TRUE; otherwise inverted
37             - DD: Double density support
38             - Side: Has side select support
39             - ?: Unknown if it really exists
40
41    Clones:
42
43      - SMC FD179x
44      - Fujitsu MB8876 -> FD1791, MB8877 -> FD1793
45      - VLSI VL177x
46
47
48    Changelog:
49
50    Kevin Thacker
51        - Removed disk image code and replaced it with floppy drive functions.
52          Any disc image is now useable with this code.
53        - Fixed write protect
54
55    2005-Apr-16 P.Harvey-Smith:
56        - Increased the delay in wd17xx_timed_read_sector_request and
57          wd17xx_timed_write_sector_request, to 40us to more closely match
58          what happens on the real hardware, this has fixed the NitrOS9 boot
59          problems.
60
61    2007-Nov-01 Wilbert Pol:
62        Needed these changes to get the MB8877 for Osborne-1 to work:
63        - Added support for multiple record read
64        - Changed the wd17xx_read_id to not return after DATADONEDELAY, but
65          the host should read the id data through the data register. This
66          was accomplished by making this change in the wd17xx_read_id
67          function:
68            -               wd17xx_complete_command(device, DELAY_DATADONE);
69            +               wd17xx_set_data_request();
70
71    2009-May-10 Robbbert:
72        Further change to get the Kaypro II to work
73        - When wd17xx_read_id has generated the 6 data bytes, it should make
74          an IRQ and turn off the busy status. The timing for Osborne is
75          critical, it must be between 300 and 700 usec, I've settled on 400.
76          The Kaypro doesn't care timewise, but the busy flag must turn off
77          sometime or it hangs.
78            -       w->status |= STA_2_BUSY;
79            +       wd17xx_set_busy(device, attotime::from_usec(400));
80
81    2009-June-4 Roberto Lavarone:
82        - Initial support for wd1771
83        - Added simulation of head loaded feedback from drive
84        - Bugfix: busy flag was cleared too early
85
86    2009-June-21 Robbbert:
87    - The Bugfix above, while valid, caused the Osborne1 to fail. This
88      is because the delay must not exceed 14usec (found by extensive testing).
89    - The minimum delay is 1usec, need by z80netf while formatting a disk.
90    - http://www.bannister.org/forums/ubbthreads.php?ubb=showflat&Number=50889#Post50889
91      explains the problems, testing done, and the test procedure for the z80netf.
92    - Thus, the delay is set to 10usec, and all the disks I have (not many)
93      seem to work.
94    - Note to anyone who wants to change something: Make sure that the
95      Osborne1 boots up! It is extremely sensitive to timing!
96    - For testing only: The osborne1 rom can be patched to make it much
97      more stable, by changing the byte at 0x0da7 from 0x28 to 0x18.
98
99    2009-June-25 Robbbert:
100    - Turns out kayproii not working, 10usec is too short.. but 11usec is ok.
101      Setting it to 12usec.
102      Really, this whole thing needs a complete rewrite.
103
104    2009-July-08 Roberto Lavarone:
105    - Fixed a bug in head load flag handling: einstein and samcoupe now working again
106
107    2009-September-30 Robbbert:
108    - Modified what status flags are returned after a Forced Interrupt,
109      to allow Microbee to boot CP/M.
110
111    2010-Jan-31 Phill Harvey-Smith
112    - The above bugfixes for the Kaypro/Osborne1 have borked the booting on the Dragon
113      Alpha. The Alpha it seems needs a delay of ay least 17us or the NMI generated by
114      INTRQ happens too early and doen't break out of the read/write bytes loops.
115
116      I have made the delay settable by calling wd17xx_set_complete_command_delay, and
117      let it default to 12us, as required above, so that the Dragon Alpha works again.
118      This hopefully should not break the other machines.
119
120      This should probably be considdered a minor hack but it does seem to work !
121
122    2010-02-04 Phill Harvey-Smith
123    - Added multiple sector write as the RM Nimbus needs it.
124
125    2010-March-22 Curt Coder:
126    - Implemented immediate and index pulse interrupts.
127
128    2010-Dec-31 Phill Harvey-Smith
129    - Copied multi-sector write code from r7263, for some reason this had been
130      silently removed, but is required for the rmnimbus driver.
131
132    2011-Mar-08 Phill Harvey-Smith
133    - Triggering intrq now clears the DRQ bit in the status as well as the busy bit.
134      Execution of the READ_DAM command now correctly sets w->command.
135
136    2011-Apr-01 Curt Coder
137    - Set complete command delay to 16 usec (DD) / 32 usec (SD) and removed
138      the external delay setting hack.
139
140    TODO:
141        - What happens if a track is read that doesn't have any id's on it?
142         (e.g. unformatted disc)
143
144***************************************************************************/
145
146
147#include "emu.h"
148#include "formats/imageutl.h"
149#include "machine/wd17xx.h"
150#include "imagedev/flopdrv.h"
151
152/***************************************************************************
153    CONSTANTS
154***************************************************************************/
155
156#define VERBOSE         0   /* General logging */
157#define VERBOSE_DATA   0   /* Logging of each byte during read and write */
158
159#define DELAY_ERROR      3
160#define DELAY_NOTREADY   1
161#define DELAY_DATADONE   3
162
163#define TYPE_I         1
164#define TYPE_II       2
165#define TYPE_III      3
166#define TYPE_IV       4
167
168#define FDC_STEP_RATE   0x03    /* Type I additional flags */
169#define FDC_STEP_VERIFY 0x04   /* verify track number */
170#define FDC_STEP_HDLOAD 0x08   /* load head */
171#define FDC_STEP_UPDATE 0x10   /* update track register */
172
173#define FDC_RESTORE    0x00   /* Type I commands */
174#define FDC_SEEK      0x10
175#define FDC_STEP      0x20
176#define FDC_STEP_IN    0x40
177#define FDC_STEP_OUT   0x60
178
179#define FDC_MASK_TYPE_I       (FDC_STEP_HDLOAD|FDC_STEP_VERIFY|FDC_STEP_RATE)
180
181/* Type I commands status */
182#define STA_1_BUSY      0x01   /* controller is busy */
183#define STA_1_IPL      0x02   /* index pulse */
184#define STA_1_TRACK0   0x04   /* track 0 detected */
185#define STA_1_CRC_ERR   0x08   /* CRC error */
186#define STA_1_SEEK_ERR   0x10   /* seek error */
187#define STA_1_HD_LOADED 0x20   /* head loaded */
188#define STA_1_WRITE_PRO 0x40   /* floppy is write protected */
189#define STA_1_NOT_READY 0x80   /* drive not ready */
190#define STA_1_MOTOR_ON   0x80   /* status of the Motor On output (WD1770 and WD1772 only) */
191
192/* Type II and III additional flags */
193#define FDC_DELETED_AM   0x01   /* read/write deleted address mark */
194#define FDC_SIDE_CMP_T   0x02   /* side compare track data */
195#define FDC_15MS_DELAY   0x04   /* delay 15ms before command */
196#define FDC_SIDE_CMP_S   0x08   /* side compare sector data */
197#define FDC_MULTI_REC   0x10   /* only for type II commands */
198
199/* Type II commands */
200#define FDC_READ_SEC   0x80   /* read sector */
201#define FDC_WRITE_SEC   0xA0   /* write sector */
202
203#define FDC_MASK_TYPE_II      (FDC_MULTI_REC|FDC_SIDE_CMP_S|FDC_15MS_DELAY|FDC_SIDE_CMP_T|FDC_DELETED_AM)
204
205/* Type II commands status */
206#define STA_2_BUSY      0x01
207#define STA_2_DRQ      0x02
208#define STA_2_LOST_DAT   0x04
209#define STA_2_CRC_ERR   0x08
210#define STA_2_REC_N_FND 0x10
211#define STA_2_REC_TYPE   0x20
212#define STA_2_WRITE_PRO 0x40
213#define STA_2_NOT_READY 0x80
214
215#define FDC_MASK_TYPE_III      (FDC_SIDE_CMP_S|FDC_15MS_DELAY|FDC_SIDE_CMP_T|FDC_DELETED_AM)
216
217/* Type III commands */
218#define FDC_READ_DAM   0xc0   /* read data address mark */
219#define FDC_READ_TRK   0xe0   /* read track */
220#define FDC_WRITE_TRK   0xf0   /* write track (format) */
221
222/* Type IV additional flags */
223#define FDC_IM0       0x01   /* interrupt mode 0 */
224#define FDC_IM1       0x02   /* interrupt mode 1 */
225#define FDC_IM2       0x04   /* interrupt mode 2 */
226#define FDC_IM3       0x08   /* interrupt mode 3 */
227
228#define FDC_MASK_TYPE_IV      (FDC_IM3|FDC_IM2|FDC_IM1|FDC_IM0)
229
230/* Type IV commands */
231#define FDC_FORCE_INT   0xd0   /* force interrupt */
232
233/* structure describing a double density track */
234#define TRKSIZE_DD      6144
235#if 0
236static const UINT8 track_DD[][2] = {
237   {16, 0x4e},    /* 16 * 4E (track lead in)               */
238   { 8, 0x00},    /*  8 * 00 (pre DAM)                     */
239   { 3, 0xf5},    /*  3 * F5 (clear CRC)                   */
240
241   { 1, 0xfe},    /* *** sector *** FE (DAM)               */
242   { 1, 0x80},    /*  4 bytes track,head,sector,seclen     */
243   { 1, 0xf7},    /*  1 * F7 (CRC)                         */
244   {22, 0x4e},    /* 22 * 4E (sector lead in)              */
245   {12, 0x00},    /* 12 * 00 (pre AM)                      */
246   { 3, 0xf5},    /*  3 * F5 (clear CRC)                   */
247   { 1, 0xfb},    /*  1 * FB (AM)                          */
248   { 1, 0x81},    /*  x bytes sector data                  */
249   { 1, 0xf7},    /*  1 * F7 (CRC)                         */
250   {16, 0x4e},    /* 16 * 4E (sector lead out)             */
251   { 8, 0x00},    /*  8 * 00 (post sector)                 */
252   { 0, 0x00},    /* end of data                           */
253};
254#endif
255
256/* structure describing a single density track */
257#define TRKSIZE_SD      3172
258#if 0
259static const UINT8 track_SD[][2] = {
260   {16, 0xff},    /* 16 * FF (track lead in)               */
261   { 8, 0x00},    /*  8 * 00 (pre DAM)                     */
262   { 1, 0xfc},    /*  1 * FC (clear CRC)                   */
263
264   {11, 0xff},    /* *** sector *** 11 * FF                */
265   { 6, 0x00},    /*  6 * 00 (pre DAM)                     */
266   { 1, 0xfe},    /*  1 * FE (DAM)                         */
267   { 1, 0x80},    /*  4 bytes track,head,sector,seclen     */
268   { 1, 0xf7},    /*  1 * F7 (CRC)                         */
269   {10, 0xff},    /* 10 * FF (sector lead in)              */
270   { 4, 0x00},    /*  4 * 00 (pre AM)                      */
271   { 1, 0xfb},    /*  1 * FB (AM)                          */
272   { 1, 0x81},    /*  x bytes sector data                  */
273   { 1, 0xf7},    /*  1 * F7 (CRC)                         */
274   { 0, 0x00},    /* end of data                           */
275};
276#endif
277
278
279/***************************************************************************
280    TYPE DEFINITIONS
281***************************************************************************/
282
283typedef struct _wd1770_state wd1770_state;
284struct _wd1770_state
285{
286   /* callbacks */
287   devcb_resolved_read_line in_dden_func;
288   devcb_resolved_write_line out_intrq_func;
289   devcb_resolved_write_line out_drq_func;
290
291   /* input lines */
292   int mr;            /* master reset */
293   int rdy;           /* ready, enable precomp */
294   int tr00;          /* track 00 */
295   int idx;           /* index */
296   int wprt;          /* write protect */
297   int dden;          /* double density */
298
299   /* output lines */
300   int mo;            /* motor on */
301   int dirc;          /* direction */
302   int drq;           /* data request */
303   int intrq;         /* interrupt request */
304
305   /* register */
306   UINT8 data_shift;
307   UINT8 data;
308   UINT8 track;
309   UINT8 sector;
310   UINT8 command;
311   UINT8 status;
312   UINT8 interrupt;
313
314   int stepping_rate[4];  /* track stepping rate in ms */
315
316        unsigned short  crc;    /* Holds the current CRC value for write_track CRC calculation */
317        int     crc_active;   /* Flag indicating that CRC calculation in write_track is active. */
318
319   UINT8   track_reg;            /* value of track register */
320   UINT8   command_type;         /* last command type */
321   UINT8   head;               /* current head # */
322
323   UINT8   read_cmd;            /* last read command issued */
324   UINT8   write_cmd;            /* last write command issued */
325   INT8   direction;            /* last step direction */
326   UINT8   last_command_data;      /* last command data */
327
328   UINT8   status_drq;          /* status register data request bit */
329   UINT8   busy_count;          /* how long to keep busy bit set */
330
331   UINT8   buffer[6144];         /* I/O buffer (holds up to a whole track) */
332   UINT32   data_offset;         /* offset into I/O buffer */
333   INT32   data_count;          /* transfer count from/into I/O buffer */
334
335   UINT8   *fmt_sector_data[256];   /* pointer to data after formatting a track */
336
337   UINT8   dam_list[256][4];      /* list of data address marks while formatting */
338   int    dam_data[256];         /* offset to data inside buffer while formatting */
339   int    dam_cnt;            /* valid number of entries in the dam_list */
340   UINT16   sector_length;         /* sector length (byte) */
341
342   UINT8   ddam;               /* ddam of sector found - used when reading */
343   UINT8   sector_data_id;
344   int      data_direction;
345
346   int     hld_count;            /* head loaded counter */
347
348   /* timers to delay execution/completion of commands */
349   emu_timer *timer_cmd, *timer_data, *timer_rs, *timer_ws;
350
351   /* this is the drive currently selected */
352   device_t *drive;
353
354   /* this is the head currently selected */
355   UINT8 hd;
356
357   /* pause time when writing/reading sector */
358   int pause_time;
359
360   /* Were we busy when we received a FORCE_INT command */
361   UINT8   was_busy;
362
363   /* Pointer to interface */
364   const wd17xx_interface *intf;
365};
366
367
368/***************************************************************************
369    DEFAULT INTERFACES
370***************************************************************************/
371
372const wd17xx_interface default_wd17xx_interface =
373{
374   DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, { FLOPPY_0, FLOPPY_1, FLOPPY_2, FLOPPY_3}
375};
376
377const wd17xx_interface default_wd17xx_interface_2_drives =
378{
379   DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, { FLOPPY_0, FLOPPY_1, NULL, NULL}
380};
381
382
383/***************************************************************************
384    PROTOTYPES
385***************************************************************************/
386
387static void wd17xx_complete_command(device_t *device, int delay);
388static void wd17xx_timed_data_request(device_t *device);
389static void wd17xx_index_pulse_callback(device_t *controller, device_t *img, int state);
390static int wd17xx_locate_sector(device_t *device);
391static void wd17xx_timed_read_sector_request(device_t *device);
392
393
394/*****************************************************************************
395    INLINE FUNCTIONS
396*****************************************************************************/
397
398INLINE wd1770_state *get_safe_token(device_t *device)
399{
400   assert(device != NULL);
401   assert(device->type() == WD1770 || device->type() == WD1771 || device->type() == WD1772 || device->type() == WD1773 ||
402      device->type() == WD1793 ||   device->type() == WD1795 || device->type() == WD1797 ||
403      device->type() == WD2793 || device->type() == WD2795 || device->type() == WD2797 ||
404      device->type() == WD177X || device->type() == WD179X || device->type() == MB8877);
405
406   return (wd1770_state *)downcast<legacy_device_base *>(device)->token();
407}
408
409
410/***************************************************************************
411    HELPER FUNCTIONS
412***************************************************************************/
413
414static int wd17xx_has_side_select(device_t *device)
415{
416   return (device->type() == WD1795 || device->type() == WD1797 ||
417         device->type() == WD2795 || device->type() == WD2797);
418}
419
420static int wd17xx_dden(device_t *device)
421{
422   wd1770_state *w = get_safe_token(device);
423
424   if (!w->in_dden_func.isnull())
425      return w->in_dden_func();
426   else
427      return w->dden;
428}
429
430
431/***************************************************************************
432    IMPLEMENTATION
433***************************************************************************/
434
435/* clear a data request */
436static void wd17xx_clear_drq(device_t *device)
437{
438   wd1770_state *w = get_safe_token(device);
439
440   w->status &= ~STA_2_DRQ;
441
442   w->drq = CLEAR_LINE;
443   w->out_drq_func(w->drq);
444}
445
446/* set data request */
447static void wd17xx_set_drq(device_t *device)
448{
449   wd1770_state *w = get_safe_token(device);
450
451   if (w->status & STA_2_DRQ)
452      w->status |= STA_2_LOST_DAT;
453
454   w->status |= STA_2_DRQ;
455
456   w->drq = ASSERT_LINE;
457   w->out_drq_func(w->drq);
458}
459
460/* clear interrupt request */
461static void   wd17xx_clear_intrq(device_t *device)
462{
463   wd1770_state *w = get_safe_token(device);
464
465   w->intrq = CLEAR_LINE;
466   w->out_intrq_func(w->intrq);
467}
468
469/* set interrupt request */
470static void   wd17xx_set_intrq(device_t *device)
471{
472   wd1770_state *w = get_safe_token(device);
473
474   w->status &= ~STA_2_BUSY;
475   w->status &= ~STA_2_DRQ;
476
477   w->intrq = ASSERT_LINE;
478   w->out_intrq_func(w->intrq);
479}
480
481/* set intrq after delay */
482static TIMER_CALLBACK( wd17xx_command_callback )
483{
484   device_t *device = (device_t *)ptr;
485   wd1770_state *w = get_safe_token(device);
486
487   if (w->last_command_data != FDC_FORCE_INT)
488   {
489      wd17xx_set_intrq(device);
490   }
491}
492
493/* write next byte to data register and set drq */
494static TIMER_CALLBACK( wd17xx_data_callback )
495{
496   device_t *device = (device_t *)ptr;
497   wd1770_state *w = get_safe_token(device);
498
499   /* check if this is a write command */
500   if( (w->command_type == TYPE_II && w->command == FDC_WRITE_SEC) ||
501         (w->command_type == TYPE_III && w->command == FDC_WRITE_TRK) )
502   {
503      /* we are ready for new data */
504      wd17xx_set_drq(device);
505
506      return;
507   }
508
509   /* any bytes remaining? */
510   if (w->data_count >= 1)
511   {
512      /* yes */
513      w->data = w->buffer[w->data_offset++];
514
515      if (VERBOSE_DATA)
516         logerror("wd17xx_data_callback: $%02X (data_count %d)\n", w->data, w->data_count);
517
518      wd17xx_set_drq(device);
519
520      /* any bytes remaining? */
521      if (--w->data_count < 1)
522      {
523         /* no */
524         w->data_offset = 0;
525
526         /* clear ddam type */
527         w->status &=~STA_2_REC_TYPE;
528
529         /* read a sector with ddam set? */
530         if (w->command_type == TYPE_II && w->ddam != 0)
531         {
532            /* set it */
533            w->status |= STA_2_REC_TYPE;
534         }
535
536         /* check if we should handle the next sector for a multi record read */
537         if (w->command_type == TYPE_II && w->command == FDC_READ_SEC && (w->read_cmd & 0x10))
538         {
539            if (VERBOSE)
540               logerror("wd17xx_data_callback: multi sector read\n");
541
542            if (w->sector == 0xff)
543               w->sector = 0x01;
544            else
545               w->sector++;
546
547            wd17xx_timed_read_sector_request(device);
548         }
549         else
550         {
551            /* Delay the INTRQ 3 byte times because we need to read two CRC bytes and
552                   compare them with a calculated CRC */
553            wd17xx_complete_command(device, DELAY_DATADONE);
554
555            if (VERBOSE)
556               logerror("wd17xx_data_callback: data read completed\n");
557         }
558      }
559      else
560      {
561         /* requeue us for more data */
562         w->timer_data->adjust(attotime::from_usec(wd17xx_dden(device) ? 128 : 32));
563      }
564   }
565   else
566   {
567      logerror("wd17xx_data_callback: (no new data) $%02X (data_count %d)\n", w->data, w->data_count);
568   }
569}
570
571
572static void wd17xx_set_busy(device_t *device, attotime duration)
573{
574   wd1770_state *w = get_safe_token(device);
575
576   w->status |= STA_1_BUSY;
577
578   w->timer_cmd->adjust(duration);
579}
580
581
582/* BUSY COUNT DOESN'T WORK PROPERLY! */
583
584static void wd17xx_command_restore(device_t *device)
585{
586   wd1770_state *w = get_safe_token(device);
587   UINT8 step_counter;
588
589   if (w->drive == NULL)
590      return;
591
592   step_counter = 255;
593
594#if 0
595   w->status |= STA_1_BUSY;
596#endif
597
598   /* setup step direction */
599   w->direction = -1;
600
601   w->command_type = TYPE_I;
602
603   /* reset busy count */
604   w->busy_count = 0;
605
606   if (1) // image_slotexists(w->drive) : FIXME
607   {
608      /* keep stepping until track 0 is received or 255 steps have been done */
609      while (floppy_tk00_r(w->drive) && (step_counter != 0))
610      {
611         /* update time to simulate seek time busy signal */
612         w->busy_count++;
613         floppy_drive_seek(w->drive, w->direction);
614         step_counter--;
615      }
616   }
617
618   /* update track reg */
619   w->track = 0;
620#if 0
621   /* simulate seek time busy signal */
622   w->busy_count = 0;   //w->busy_count * ((w->data & FDC_STEP_RATE) + 1);
623
624   /* when command completes set irq */
625   wd17xx_set_intrq(device);
626#endif
627   wd17xx_set_busy(device, attotime::from_usec(100));
628}
629
630/*
631    Write an entire track. Formats which do not define a write_track
632    function pointer will cause a silent return.
633    What is written to the image depends on the selected format. Sector
634    dumps have to extract the sectors in the track, while track dumps
635    may directly write the bytes.
636    (The if-part below may thus be removed.)
637*/
638static void write_track(device_t *device)
639{
640   wd1770_state *w = get_safe_token(device);
641   floppy_image *floppy;
642#if 0
643   int i;
644   for (i=0;i+4<w->data_offset;)
645   {
646      if (w->buffer[i]==0xfe)
647      {
648         /* got address mark */
649         int track   = w->buffer[i+1];
650         int side    = w->buffer[i+2];
651         int sector  = w->buffer[i+3];
652         //int len     = w->buffer[i+4];
653         int filler  = 0xe5; /* IBM and Thomson */
654         int density = w->density;
655         floppy_drive_format_sector(w->drive,side,sector,track,
656                  w->hd,sector,density?1:0,filler);
657         i += 128; /* at least... */
658      }
659      else
660         i++;
661   }
662#endif
663
664   /* Get the size in bytes of the current track. For real hardware this
665    may vary per system in small degree, and there even for each track
666    and head, so we should not assume a fixed value here.
667    As we are using a buffered track writing, we have to find out how long
668    the track will become. The only object which can tell us is the
669    selected format.
670    */
671   w->data_count = 0;
672   floppy = flopimg_get_image(w->drive);
673   if (floppy != NULL)
674      w->data_count = floppy_get_track_size(floppy, w->hd, w->track);
675
676        if (w->data_count==0)
677        {
678                if (device->type() == WD1771)
679                        w->data_count = TRKSIZE_SD;
680                else
681         w->data_count = wd17xx_dden(device) ? TRKSIZE_SD : TRKSIZE_DD;
682        }
683
684   floppy_drive_write_track_data_info_buffer( w->drive, w->hd, (char *)w->buffer, &(w->data_count) );
685
686   w->data_offset = 0;
687
688   wd17xx_set_drq(device);
689   w->status |= STA_2_BUSY;
690   w->busy_count = 0;
691}
692
693/*
694    Read an entire track. It is up to the format to deliver the data. Sector
695    dumps may be required to fantasize the missing track bytes, while track
696    dumps can directly deliver them.
697    (The if-part below may thus be removed.)
698*/
699static void read_track(device_t *device)
700{
701   wd1770_state *w = get_safe_token(device);
702   floppy_image *floppy;
703#if 0
704   UINT8 *psrc;      /* pointer to track format structure */
705   UINT8 *pdst;      /* pointer to track buffer */
706   int cnt;         /* number of bytes to fill in */
707   UINT16 crc;       /* id or data CRC */
708   UINT8 d;         /* data */
709   UINT8 t = w->track; /* track of DAM */
710   UINT8 h = w->head;   /* head of DAM */
711   UINT8 s = w->sector_dam;      /* sector of DAM */
712   UINT16 l = w->sector_length;   /* sector length of DAM */
713   int i;
714
715   for (i = 0; i < w->sec_per_track; i++)
716   {
717      w->dam_list[i][0] = t;
718      w->dam_list[i][1] = h;
719      w->dam_list[i][2] = i;
720      w->dam_list[i][3] = l >> 8;
721   }
722
723   pdst = w->buffer;
724
725   if (w->density)
726   {
727      psrc = track_DD[0];    /* double density track format */
728      cnt = TRKSIZE_DD;
729   }
730   else
731   {
732      psrc = track_SD[0];    /* single density track format */
733      cnt = TRKSIZE_SD;
734   }
735
736   while (cnt > 0)
737   {
738      if (psrc[0] == 0)      /* no more track format info ? */
739      {
740         if (w->dam_cnt < w->sec_per_track) /* but more DAM info ? */
741         {
742            if (w->density)/* DD track ? */
743               psrc = track_DD[3];
744            else
745               psrc = track_SD[3];
746         }
747      }
748
749      if (psrc[0] != 0)      /* more track format info ? */
750      {
751         cnt -= psrc[0];    /* subtract size */
752         d = psrc[1];
753
754         if (d == 0xf5)      /* clear CRC ? */
755         {
756            crc = 0xffff;
757            d = 0xa1;      /* store A1 */
758         }
759
760         for (i = 0; i < *psrc; i++)
761            *pdst++ = d;   /* fill data */
762
763         if (d == 0xf7)      /* store CRC ? */
764         {
765            pdst--;       /* go back one byte */
766            *pdst++ = crc & 255;   /* put CRC low */
767            *pdst++ = crc / 256;   /* put CRC high */
768            cnt -= 1;      /* count one more byte */
769         }
770         else if (d == 0xfe)/* address mark ? */
771         {
772            crc = 0xffff;   /* reset CRC */
773         }
774         else if (d == 0x80)/* sector ID ? */
775         {
776            pdst--;       /* go back one byte */
777            t = *pdst++ = w->dam_list[w->dam_cnt][0]; /* track number */
778            h = *pdst++ = w->dam_list[w->dam_cnt][1]; /* head number */
779            s = *pdst++ = w->dam_list[w->dam_cnt][2]; /* sector number */
780            l = *pdst++ = w->dam_list[w->dam_cnt][3]; /* sector length code */
781            w->dam_cnt++;
782            crc = ccitt_crc16_one(crc, t);   /* build CRC */
783            crc = ccitt_crc16_one(crc, h);   /* build CRC */
784            crc = ccitt_crc16_one(crc, s);   /* build CRC */
785            crc = ccitt_crc16_one(crc, l);   /* build CRC */
786            l = (l == 0) ? 128 : l << 8;
787         }
788         else if (d == 0xfb)// data address mark ?
789         {
790            crc = 0xffff;   // reset CRC
791         }
792         else if (d == 0x81)// sector DATA ?
793         {
794            pdst--;       /* go back one byte */
795            if (seek(w, t, h, s) == 0)
796            {
797               if (mame_fread(w->image_file, pdst, l) != l)
798               {
799                  w->status = STA_2_CRC_ERR;
800                  return;
801               }
802            }
803            else
804            {
805               w->status = STA_2_REC_N_FND;
806               return;
807            }
808            for (i = 0; i < l; i++) // build CRC of all data
809               crc = ccitt_crc16_one(crc, *pdst++);
810            cnt -= l;
811         }
812         psrc += 2;
813      }
814      else
815      {
816         *pdst++ = 0xff;    /* fill track */
817         cnt--;            /* until end */
818      }
819   }
820#endif
821   /* Determine the track size. We cannot allow different sizes in this
822    design (see above, write_track). */
823   w->data_count = 0;
824   floppy = flopimg_get_image(w->drive);
825   if (floppy != NULL)
826      w->data_count = floppy_get_track_size(floppy, w->hd, w->track);
827
828        if (w->data_count==0)
829        {
830                if (device->type() == WD1771)
831                        w->data_count = TRKSIZE_SD;
832                else
833         w->data_count = wd17xx_dden(device) ? TRKSIZE_SD : TRKSIZE_DD;
834        }
835
836   floppy_drive_read_track_data_info_buffer( w->drive, w->hd, (char *)w->buffer, &(w->data_count) );
837
838   w->data_offset = 0;
839
840   wd17xx_set_drq(device);
841   w->status |= STA_2_BUSY;
842   w->busy_count = 0;
843}
844
845
846/* read the next data address mark */
847static void wd17xx_read_id(device_t *device)
848{
849   chrn_id id;
850   wd1770_state *w = get_safe_token(device);
851
852   w->status &= ~(STA_2_CRC_ERR | STA_2_REC_N_FND);
853
854   /* get next id from disc */
855   if (floppy_drive_get_next_id(w->drive, w->hd, &id))
856   {
857      UINT16 crc = 0xffff;
858
859      w->data_offset = 0;
860      w->data_count = 6;
861
862      /* for MFM */
863      /* crc includes 3x0x0a1, and 1x0x0fe (id mark) */
864      crc = ccitt_crc16_one(crc,0x0a1);
865      crc = ccitt_crc16_one(crc,0x0a1);
866      crc = ccitt_crc16_one(crc,0x0a1);
867      crc = ccitt_crc16_one(crc,0x0fe);
868
869      w->buffer[0] = id.C;
870      w->buffer[1] = id.H;
871      w->buffer[2] = id.R;
872      w->buffer[3] = id.N;
873      crc = ccitt_crc16_one(crc, w->buffer[0]);
874      crc = ccitt_crc16_one(crc, w->buffer[1]);
875      crc = ccitt_crc16_one(crc, w->buffer[2]);
876      crc = ccitt_crc16_one(crc, w->buffer[3]);
877      /* crc is stored hi-byte followed by lo-byte */
878      w->buffer[4] = crc>>8;
879      w->buffer[5] = crc & 255;
880
881      w->sector = id.C;
882
883      if (VERBOSE)
884         logerror("wd17xx_read_id: read id succeeded.\n");
885
886      wd17xx_timed_data_request(device);
887   }
888   else
889   {
890      /* record not found */
891      w->status |= STA_2_REC_N_FND;
892      //w->sector = w->track;
893      if (VERBOSE)
894         logerror("wd17xx_read_id: read id failed\n");
895
896      wd17xx_complete_command(device, DELAY_ERROR);
897   }
898}
899
900
901
902static void wd17xx_index_pulse_callback(device_t *controller, device_t *img, int state)
903{
904   wd1770_state *w = get_safe_token(controller);
905
906   if (img != w->drive)
907      return;
908
909   w->idx = state;
910
911   if (!state && w->idx && BIT(w->interrupt, 2))
912      wd17xx_set_intrq(controller);
913
914   if (w->hld_count)
915      w->hld_count--;
916}
917
918
919
920static int wd17xx_locate_sector(device_t *device)
921{
922   UINT8 revolution_count;
923   chrn_id id;
924   wd1770_state *w = get_safe_token(device);
925
926   revolution_count = 0;
927
928   w->status &= ~STA_2_REC_N_FND;
929
930   while (revolution_count!=4)
931   {
932      if (floppy_drive_get_next_id(w->drive, w->hd, &id))
933      {
934         /* compare track */
935         if (id.C == w->track)
936         {
937            /* compare head, if we were asked to */
938            if (!wd17xx_has_side_select(device) || (id.H == w->head) || (w->head == (UINT8) ~0))
939            {
940               /* compare id */
941               if (id.R == w->sector)
942               {
943                  w->sector_length = 1<<(id.N+7);
944                  w->sector_data_id = id.data_id;
945                  /* get ddam status */
946                  w->ddam = id.flags & ID_FLAG_DELETED_DATA;
947                  /* got record type here */
948                  if (VERBOSE)
949                     logerror("sector found! C:$%02x H:$%02x R:$%02x N:$%02x%s\n", id.C, id.H, id.R, id.N, w->ddam ? " DDAM" : "");
950                  return 1;
951               }
952            }
953         }
954      }
955
956       /* index set? */
957      if (floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_INDEX))
958      {
959         /* update revolution count */
960         revolution_count++;
961      }
962   }
963   return 0;
964}
965
966
967static int wd17xx_find_sector(device_t *device)
968{
969   wd1770_state *w = get_safe_token(device);
970   if ( wd17xx_locate_sector(device) )
971   {
972      return 1;
973   }
974
975   /* record not found */
976   w->status |= STA_2_REC_N_FND;
977
978   if (VERBOSE)
979      logerror("track %d sector %d not found!\n", w->track, w->sector);
980
981   wd17xx_complete_command(device, DELAY_ERROR);
982
983   return 0;
984}
985
986
987
988/* read a sector */
989static void wd17xx_read_sector(device_t *device)
990{
991   wd1770_state *w = get_safe_token(device);
992   w->data_offset = 0;
993
994   /* side compare? */
995   if (w->read_cmd & 0x02)
996      w->head = (w->read_cmd & 0x08) ? 1 : 0;
997   else
998      w->head = ~0;
999
1000   if (wd17xx_find_sector(device))
1001   {
1002      w->data_count = w->sector_length;
1003
1004      /* read data */
1005      floppy_drive_read_sector_data(w->drive, w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length);
1006
1007      wd17xx_timed_data_request(device);
1008
1009      w->status |= STA_2_BUSY;
1010      w->busy_count = 0;
1011   }
1012}
1013
1014
1015/* called on error, or when command is actually completed */
1016/* KT - I have used a timer for systems that use interrupt driven transfers.
1017A interrupt occurs after the last byte has been read. If it occurs at the time
1018when the last byte has been read it causes problems - same byte read again
1019or bytes missed */
1020/* TJL - I have add a parameter to allow the emulation to specify the delay
1021*/
1022static void wd17xx_complete_command(device_t *device, int delay)
1023{
1024   wd1770_state *w = get_safe_token(device);
1025
1026   w->data_count = 0;
1027
1028   w->hld_count = 2;
1029
1030   /* set new timer */
1031   int usecs = wd17xx_dden(device) ? 32 : 16;
1032   w->timer_cmd->adjust(attotime::from_usec(usecs));
1033
1034   /* Kill onshot read/write sector timers */
1035   w->timer_rs->adjust(attotime::never);
1036   w->timer_ws->adjust(attotime::never);
1037}
1038
1039
1040
1041static void wd17xx_write_sector(device_t *device)
1042{
1043   wd1770_state *w = get_safe_token(device);
1044   /* at this point, the disc is write enabled, and data
1045     * has been transfered into our buffer - now write it to
1046     * the disc image or to the real disc
1047     */
1048
1049   /* side compare? */
1050   if (w->write_cmd & 0x02)
1051      w->head = (w->write_cmd & 0x08) ? 1 : 0;
1052   else
1053      w->head = ~0;
1054
1055   /* find sector */
1056   if (wd17xx_find_sector(device))
1057   {
1058      w->data_count = w->sector_length;
1059
1060      /* write data */
1061      floppy_drive_write_sector_data(w->drive, w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length, w->write_cmd & 0x01);
1062   }
1063}
1064
1065
1066
1067/* verify the seek operation by looking for a id that has a matching track value */
1068static void wd17xx_verify_seek(device_t *device)
1069{
1070   UINT8 revolution_count;
1071   chrn_id id;
1072   wd1770_state *w = get_safe_token(device);
1073
1074   revolution_count = 0;
1075
1076   if (VERBOSE)
1077      logerror("doing seek verify\n");
1078
1079   w->status &= ~STA_1_SEEK_ERR;
1080
1081   /* must be found within 5 revolutions otherwise error */
1082   while (revolution_count!=5)
1083   {
1084      if (floppy_drive_get_next_id(w->drive, w->hd, &id))
1085      {
1086         /* compare track */
1087         if (id.C == w->track)
1088         {
1089            if (VERBOSE)
1090               logerror("seek verify succeeded!\n");
1091            return;
1092         }
1093      }
1094
1095       /* index set? */
1096      if (floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_INDEX))
1097      {
1098         /* update revolution count */
1099         revolution_count++;
1100      }
1101   }
1102
1103   w->status |= STA_1_SEEK_ERR;
1104
1105   if (VERBOSE)
1106      logerror("failed seek verify!\n");
1107}
1108
1109
1110
1111/* callback to initiate read sector */
1112static TIMER_CALLBACK( wd17xx_read_sector_callback )
1113{
1114   device_t *device = (device_t *)ptr;
1115   wd1770_state *w = get_safe_token(device);
1116
1117   /* ok, start that read! */
1118
1119   if (VERBOSE)
1120      logerror("wd179x: Read Sector callback.\n");
1121
1122   if (!floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY))
1123      wd17xx_complete_command(device, DELAY_NOTREADY);
1124   else
1125      wd17xx_read_sector(device);
1126}
1127
1128
1129
1130/* callback to initiate write sector */
1131static TIMER_CALLBACK( wd17xx_write_sector_callback )
1132{
1133   device_t *device = (device_t *)ptr;
1134   wd1770_state *w = get_safe_token(device);
1135
1136   /* ok, start that write! */
1137
1138   if (VERBOSE)
1139      logerror("wd179x: Write Sector callback.\n");
1140
1141   if (!floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY))
1142      wd17xx_complete_command(device, DELAY_NOTREADY);
1143   else
1144   {
1145
1146      /* drive write protected? */
1147      if (floppy_wpt_r(w->drive) == CLEAR_LINE)
1148      {
1149         w->status |= STA_2_WRITE_PRO;
1150
1151         wd17xx_complete_command(device, DELAY_ERROR);
1152      }
1153      else
1154      {
1155         /* side compare? */
1156         if (w->write_cmd & 0x02)
1157            w->head = (w->write_cmd & 0x08) ? 1 : 0;
1158         else
1159            w->head = ~0;
1160
1161         /* attempt to find it first before getting data from cpu */
1162         if (wd17xx_find_sector(device))
1163         {
1164            /* request data */
1165            w->data_offset = 0;
1166            w->data_count = w->sector_length;
1167
1168            wd17xx_set_drq(device);
1169
1170            w->status |= STA_2_BUSY;
1171            w->busy_count = 0;
1172         }
1173      }
1174   }
1175}
1176
1177
1178
1179/* setup a timed data request - data request will be triggered in a few usecs time */
1180static void wd17xx_timed_data_request(device_t *device)
1181{
1182   wd1770_state *w = get_safe_token(device);
1183
1184   /* set new timer */
1185   w->timer_data->adjust(attotime::from_usec(wd17xx_dden(device) ? 128 : 32));
1186}
1187
1188
1189
1190/* setup a timed read sector - read sector will be triggered in a few usecs time */
1191static void wd17xx_timed_read_sector_request(device_t *device)
1192{
1193   wd1770_state *w = get_safe_token(device);
1194
1195   /* set new timer */
1196   w->timer_rs->adjust(attotime::from_usec(w->pause_time));
1197}
1198
1199
1200
1201/* setup a timed write sector - write sector will be triggered in a few usecs time */
1202static void wd17xx_timed_write_sector_request(device_t *device)
1203{
1204   wd1770_state *w = get_safe_token(device);
1205
1206   /* set new timer */
1207   w->timer_ws->adjust(attotime::from_usec(w->pause_time));
1208}
1209
1210
1211/***************************************************************************
1212    INTERFACE
1213***************************************************************************/
1214
1215/* use this to determine which drive is controlled by WD */
1216void wd17xx_set_drive(device_t *device, UINT8 drive)
1217{
1218   wd1770_state *w = get_safe_token(device);
1219
1220   if (VERBOSE)
1221      logerror("wd17xx_set_drive: $%02x\n", drive);
1222
1223   if (w->intf->floppy_drive_tags[drive] != NULL)
1224   {
1225      if (device->owner() != NULL) {
1226         w->drive = device->owner()->subdevice(w->intf->floppy_drive_tags[drive]);
1227         if (w->drive == NULL) {
1228            w->drive = device->machine().device(w->intf->floppy_drive_tags[drive]);
1229         }
1230      }
1231      else
1232         w->drive = device->machine().device(w->intf->floppy_drive_tags[drive]);
1233   }
1234}
1235
1236void wd17xx_set_side(device_t *device, UINT8 head)
1237{
1238   wd1770_state *w = get_safe_token(device);
1239
1240   if (VERBOSE)
1241   {
1242      if (head != w->hd)
1243         logerror("wd17xx_set_side: $%02x\n", head);
1244   }
1245
1246   w->hd = head;
1247}
1248
1249void wd17xx_set_pause_time(device_t *device, int usec)
1250{
1251   wd1770_state *w = get_safe_token(device);
1252   w->pause_time = usec;
1253}
1254
1255
1256/***************************************************************************
1257    DEVICE HANDLERS
1258***************************************************************************/
1259
1260/* master reset */
1261WRITE_LINE_DEVICE_HANDLER( wd17xx_mr_w )
1262{
1263   wd1770_state *w = get_safe_token(device);
1264
1265   /* reset device when going from high to low */
1266   if (w->mr && state == CLEAR_LINE)
1267   {
1268      w->command = 0x03;
1269      w->status &= ~STA_1_NOT_READY; /* ? */
1270   }
1271
1272   /* execute restore command when going from low to high */
1273   if (w->mr == CLEAR_LINE && state)
1274   {
1275      wd17xx_command_restore(device);
1276      w->sector = 0x01;
1277   }
1278
1279   w->mr = state;
1280}
1281
1282/* ready and enable precomp (1773 only) */
1283WRITE_LINE_DEVICE_HANDLER( wd17xx_rdy_w )
1284{
1285   wd1770_state *w = get_safe_token(device);
1286   w->rdy = state;
1287}
1288
1289/* motor on, 1770 and 1772 only */
1290READ_LINE_DEVICE_HANDLER( wd17xx_mo_r )
1291{
1292   wd1770_state *w = get_safe_token(device);
1293   return w->mo;
1294}
1295
1296/* track zero */
1297WRITE_LINE_DEVICE_HANDLER( wd17xx_tr00_w )
1298{
1299   wd1770_state *w = get_safe_token(device);
1300   w->tr00 = state;
1301}
1302
1303/* index pulse */
1304WRITE_LINE_DEVICE_HANDLER( wd17xx_idx_w )
1305{
1306   wd1770_state *w = get_safe_token(device);
1307   w->idx = state;
1308
1309   if (!state && w->idx && BIT(w->interrupt, 2))
1310      wd17xx_set_intrq(device);
1311}
1312
1313/* write protect status */
1314WRITE_LINE_DEVICE_HANDLER( wd17xx_wprt_w )
1315{
1316   wd1770_state *w = get_safe_token(device);
1317   w->wprt = state;
1318}
1319
1320/* double density enable */
1321WRITE_LINE_DEVICE_HANDLER( wd17xx_dden_w )
1322{
1323   wd1770_state *w = get_safe_token(device);
1324
1325   /* not supported on FD1771, FD1792, FD1794, FD1762 and FD1764 */
1326   if (device->type() == WD1771)
1327      fatalerror("wd17xx_dden_w: double density input not supported on this model!");
1328   else if (!w->in_dden_func.isnull())
1329      logerror("wd17xx_dden_w: write has no effect because a read handler is already defined!\n");
1330   else
1331      w->dden = state;
1332}
1333
1334/* data request */
1335READ_LINE_DEVICE_HANDLER( wd17xx_drq_r )
1336{
1337   wd1770_state *w = get_safe_token(device);
1338   return w->drq;
1339}
1340
1341/* interrupt request */
1342READ_LINE_DEVICE_HANDLER( wd17xx_intrq_r )
1343{
1344   wd1770_state *w = get_safe_token(device);
1345   return w->intrq;
1346}
1347
1348/* read the FDC status register. This clears IRQ line too */
1349READ8_DEVICE_HANDLER( wd17xx_status_r )
1350{
1351   wd1770_state *w = get_safe_token(device);
1352   int result;
1353
1354   if (!BIT(w->interrupt, 3))
1355   {
1356      wd17xx_clear_intrq(device);
1357   }
1358
1359   /* bit 7, 'not ready' or 'motor on' */
1360   if (device->type() == WD1770 || device->type() == WD1772)
1361   {
1362      w->status &= ~STA_1_MOTOR_ON;
1363      w->status |= w->mo << 7;
1364   }
1365   else
1366   {
1367      w->status &= ~STA_1_NOT_READY;
1368      if (!floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY))
1369         w->status |= STA_1_NOT_READY;
1370   }
1371
1372   result = w->status;
1373
1374   /* type 1 command or force int command? */
1375   if ((w->command_type==TYPE_I) || (w->command_type==TYPE_IV && ! w->was_busy))
1376   {
1377      result &= ~(STA_1_IPL | STA_1_TRACK0);
1378
1379      /* bit 1, index pulse */
1380      result |= w->idx << 1;
1381
1382      /* bit 2, track 0 state, inverted */
1383      result |= !floppy_tk00_r(w->drive) << 2;
1384
1385      if (w->command_type==TYPE_I)
1386      {
1387         if (w->hld_count)
1388            w->status |= STA_1_HD_LOADED;
1389         else
1390            w->status &= ~ STA_1_HD_LOADED;
1391      }
1392
1393      /* bit 6, write protect, inverted */
1394      result |= !floppy_wpt_r(w->drive) << 6;
1395   }
1396
1397   /* eventually set data request bit */
1398//  w->status |= w->status_drq;
1399
1400   if (VERBOSE)
1401   {
1402      if (w->data_count < 4)
1403         logerror("%s: wd17xx_status_r: $%02X (data_count %d)\n", device->machine().describe_context(), result, w->data_count);
1404   }
1405
1406   return result;
1407}
1408
1409/* read the FDC track register */
1410READ8_DEVICE_HANDLER( wd17xx_track_r )
1411{
1412   wd1770_state *w = get_safe_token(device);
1413
1414   if (VERBOSE)
1415      logerror("%s: wd17xx_track_r: $%02X\n", device->machine().describe_context(), w->track);
1416
1417   return w->track;
1418}
1419
1420/* read the FDC sector register */
1421READ8_DEVICE_HANDLER( wd17xx_sector_r )
1422{
1423   wd1770_state *w = get_safe_token(device);
1424
1425   if (VERBOSE)
1426      logerror("%s: wd17xx_sector_r: $%02X\n", device->machine().describe_context(), w->sector);
1427
1428   return w->sector;
1429}
1430
1431/* read the FDC data register */
1432READ8_DEVICE_HANDLER( wd17xx_data_r )
1433{
1434   wd1770_state *w = get_safe_token(device);
1435
1436   if (VERBOSE_DATA)
1437      logerror("%s: wd17xx_data_r: %02x\n", device->machine().describe_context(), w->data);
1438
1439   /* clear data request */
1440   wd17xx_clear_drq(device);
1441
1442   return w->data;
1443}
1444
1445/* write the FDC command register */
1446WRITE8_DEVICE_HANDLER( wd17xx_command_w )
1447{
1448   wd1770_state *w = get_safe_token(device);
1449
1450   w->last_command_data = data;
1451
1452   /* only the WD1770 and WD1772 have a 'motor on' line */
1453   if (device->type() == WD1770 || device->type() == WD1772)
1454   {
1455      w->mo = ASSERT_LINE;
1456      floppy_mon_w(w->drive, CLEAR_LINE);
1457   }
1458
1459   floppy_drive_set_ready_state(w->drive, 1,0);
1460
1461   if (!BIT(w->interrupt, 3))
1462   {
1463      wd17xx_clear_intrq(device);
1464   }
1465
1466   /* clear write protected. On read sector, read track and read dam, write protected bit is clear */
1467   w->status &= ~((1<<6) | (1<<5) | (1<<4));
1468
1469   if ((data & ~FDC_MASK_TYPE_IV) == FDC_FORCE_INT)
1470   {
1471      if (VERBOSE)
1472         logerror("%s: wd17xx_command_w $%02X FORCE_INT (data_count %d)\n", device->machine().describe_context(), data, w->data_count);
1473
1474      w->data_count = 0;
1475      w->data_offset = 0;
1476      w->was_busy = w->status & STA_2_BUSY;
1477      w->status &= ~STA_2_BUSY;
1478
1479      wd17xx_clear_drq(device);
1480
1481      if (!BIT(w->interrupt, 3) && BIT(data, 3))
1482      {
1483         /* set immediate interrupt */
1484         wd17xx_set_intrq(device);
1485      }
1486
1487      if (BIT(w->interrupt, 3))
1488      {
1489         if (data == FDC_FORCE_INT)
1490         {
1491            /* clear immediate interrupt */
1492            w->interrupt = data & 0x0f;
1493         }
1494         else
1495         {
1496            /* keep immediate interrupt */
1497            w->interrupt = 0x08 | (data & 0x07);
1498         }
1499      }
1500      else
1501      {
1502         w->interrupt = data & 0x0f;
1503      }
1504
1505      /* terminate command */
1506      wd17xx_complete_command(device, DELAY_ERROR);
1507
1508      w->busy_count = 0;
1509      w->command_type = TYPE_IV;
1510      return;
1511   }
1512
1513   if (data & 0x80)
1514   {
1515      /*w->status_ipl = 0;*/
1516
1517      if ((data & ~FDC_MASK_TYPE_II) == FDC_READ_SEC)
1518      {
1519         if (VERBOSE)
1520            {
1521            logerror("%s: wd17xx_command_w $%02X READ_SEC (", device->machine().describe_context(), data);
1522                logerror("cmd=%02X, trk=%02X, sec=%02X, dat=%02X)\n",w->command,w->track,w->sector,w->data);
1523            }
1524         w->read_cmd = data;
1525         w->command = data & ~FDC_MASK_TYPE_II;
1526         w->command_type = TYPE_II;
1527         w->status &= ~STA_2_LOST_DAT;
1528         w->status |= STA_2_BUSY;
1529         wd17xx_clear_drq(device);
1530
1531         wd17xx_timed_read_sector_request(device);
1532
1533         return;
1534      }
1535
1536      if ((data & ~FDC_MASK_TYPE_II) == FDC_WRITE_SEC)
1537      {
1538         if (VERBOSE)
1539            {
1540            logerror("%s: wd17xx_command_w $%02X WRITE_SEC (", device->machine().describe_context(), data);
1541                logerror("cmd=%02X, trk=%02X, sec=%02X, dat=%02X)\n",w->command,w->track,w->sector,w->data);
1542            }
1543
1544         w->write_cmd = data;
1545         w->command = data & ~FDC_MASK_TYPE_II;
1546         w->command_type = TYPE_II;
1547         w->status &= ~STA_2_LOST_DAT;
1548         w->status |= STA_2_BUSY;
1549         wd17xx_clear_drq(device);
1550
1551         wd17xx_timed_write_sector_request(device);
1552
1553         return;
1554      }
1555
1556      if ((data & ~FDC_MASK_TYPE_III) == FDC_READ_TRK)
1557      {
1558         if (VERBOSE)
1559            logerror("%s: wd17xx_command_w $%02X READ_TRK\n", device->machine().describe_context(), data);
1560
1561         w->command = data & ~FDC_MASK_TYPE_III;
1562         w->command_type = TYPE_III;
1563         w->status &= ~STA_2_LOST_DAT;
1564         wd17xx_clear_drq(device);
1565#if 1
1566//          w->status = seek(w, w->track, w->head, w->sector);
1567         if (w->status == 0)
1568            read_track(device);
1569#endif
1570         return;
1571      }
1572
1573      if ((data & ~FDC_MASK_TYPE_III) == FDC_WRITE_TRK)
1574      {
1575         if (VERBOSE)
1576            logerror("%s: wd17xx_command_w $%02X WRITE_TRK\n", device->machine().describe_context(), data);
1577
1578         w->command_type = TYPE_III;
1579         w->status &= ~STA_2_LOST_DAT;
1580         wd17xx_clear_drq(device);
1581
1582         if (!floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY))
1583         {
1584            wd17xx_complete_command(device, DELAY_NOTREADY);
1585         }
1586         else
1587         {
1588
1589            /* drive write protected? */
1590            if (floppy_wpt_r(w->drive) == CLEAR_LINE)
1591            {
1592            /* yes */
1593               w->status |= STA_2_WRITE_PRO;
1594            /* quit command */
1595               wd17xx_complete_command(device, DELAY_ERROR);
1596            }
1597            else
1598            {
1599            w->command = data & ~FDC_MASK_TYPE_III;
1600            w->data_offset = 0;
1601            if (device->type() == WD1771)
1602               w->data_count = TRKSIZE_SD;
1603            else
1604               w->data_count = wd17xx_dden(device) ? TRKSIZE_SD : TRKSIZE_DD;
1605
1606            wd17xx_set_drq(device);
1607            w->status |= STA_2_BUSY;
1608            w->busy_count = 0;
1609            }
1610         }
1611         return;
1612      }
1613
1614      if ((data & ~FDC_MASK_TYPE_III) == FDC_READ_DAM)
1615      {
1616         if (VERBOSE)
1617            logerror("%s: wd17xx_command_w $%02X READ_DAM\n", device->machine().describe_context(), data);
1618
1619         w->command_type = TYPE_III;
1620         w->command = data & ~FDC_MASK_TYPE_III;
1621         w->status &= ~STA_2_LOST_DAT;
1622         w->status |= STA_2_BUSY;
1623
1624         wd17xx_clear_drq(device);
1625
1626         if (floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY))
1627            wd17xx_read_id(device);
1628         else
1629            wd17xx_complete_command(device, DELAY_NOTREADY);
1630
1631         return;
1632      }
1633
1634      if (VERBOSE)
1635         logerror("%s: wd17xx_command_w $%02X unknown\n", device->machine().describe_context(), data);
1636
1637      return;
1638   }
1639
1640   w->status |= STA_1_BUSY;
1641
1642   /* clear CRC error */
1643   w->status &=~STA_1_CRC_ERR;
1644
1645   if ((data & ~FDC_MASK_TYPE_I) == FDC_RESTORE)
1646   {
1647      if (VERBOSE)
1648         logerror("%s: wd17xx_command_w $%02X RESTORE\n", device->machine().describe_context(), data);
1649
1650      wd17xx_command_restore(device);
1651   }
1652
1653   if ((data & ~FDC_MASK_TYPE_I) == FDC_SEEK)
1654   {
1655      UINT8 newtrack;
1656
1657      if (VERBOSE)
1658         logerror("old track: $%02x new track: $%02x\n", w->track, w->data);
1659      w->command_type = TYPE_I;
1660
1661      /* setup step direction */
1662      if (w->track < w->data)
1663      {
1664         if (VERBOSE)
1665            logerror("direction: +1\n");
1666
1667         w->direction = 1;
1668      }
1669      else if (w->track > w->data)
1670      {
1671         if (VERBOSE)
1672            logerror("direction: -1\n");
1673
1674         w->direction = -1;
1675      }
1676
1677      newtrack = w->data;
1678      if (VERBOSE)
1679         logerror("%s: wd17xx_command_w $%02X SEEK (data_reg is $%02X)\n", device->machine().describe_context(), data, newtrack);
1680
1681      /* reset busy count */
1682      w->busy_count = 0;
1683
1684      /* keep stepping until reached track programmed */
1685      while (w->track != newtrack)
1686      {
1687         /* update time to simulate seek time busy signal */
1688         w->busy_count++;
1689
1690         /* update track reg */
1691         w->track += w->direction;
1692
1693         floppy_drive_seek(w->drive, w->direction);
1694      }
1695
1696      /* simulate seek time busy signal */
1697      w->busy_count = 0;   //w->busy_count * ((data & FDC_STEP_RATE) + 1);
1698#if 0
1699      wd17xx_set_intrq(device);
1700#endif
1701      wd17xx_set_busy(device, attotime::from_usec(100));
1702
1703   }
1704
1705   if ((data & ~(FDC_STEP_UPDATE | FDC_MASK_TYPE_I)) == FDC_STEP)
1706   {
1707      if (VERBOSE)
1708         logerror("%s: wd17xx_command_w $%02X STEP dir %+d\n", device->machine().describe_context(), data, w->direction);
1709
1710      w->command_type = TYPE_I;
1711        /* if it is a real floppy, issue a step command */
1712      /* simulate seek time busy signal */
1713      w->busy_count = 0;   //((data & FDC_STEP_RATE) + 1);
1714
1715      floppy_drive_seek(w->drive, w->direction);
1716
1717      if (data & FDC_STEP_UPDATE)
1718         w->track += w->direction;
1719
1720#if 0
1721      wd17xx_set_intrq(device);
1722#endif
1723      wd17xx_set_busy(device, attotime::from_usec(100));
1724
1725
1726   }
1727
1728   if ((data & ~(FDC_STEP_UPDATE | FDC_MASK_TYPE_I)) == FDC_STEP_IN)
1729   {
1730      if (VERBOSE)
1731         logerror("%s: wd17xx_command_w $%02X STEP_IN\n", device->machine().describe_context(), data);
1732
1733      w->command_type = TYPE_I;
1734      w->direction = +1;
1735      /* simulate seek time busy signal */
1736      w->busy_count = 0;   //((data & FDC_STEP_RATE) + 1);
1737
1738      floppy_drive_seek(w->drive, w->direction);
1739
1740      if (data & FDC_STEP_UPDATE)
1741         w->track += w->direction;
1742#if 0
1743      wd17xx_set_intrq(device);
1744#endif
1745      wd17xx_set_busy(device, attotime::from_usec(100));
1746
1747   }
1748
1749   if ((data & ~(FDC_STEP_UPDATE | FDC_MASK_TYPE_I)) == FDC_STEP_OUT)
1750   {
1751      if (VERBOSE)
1752         logerror("%s: wd17xx_command_w $%02X STEP_OUT\n", device->machine().describe_context(), data);
1753
1754      w->command_type = TYPE_I;
1755      w->direction = -1;
1756      /* simulate seek time busy signal */
1757      w->busy_count = 0;   //((data & FDC_STEP_RATE) + 1);
1758
1759      /* for now only allows a single drive to be selected */
1760      floppy_drive_seek(w->drive, w->direction);
1761
1762      if (data & FDC_STEP_UPDATE)
1763         w->track += w->direction;
1764
1765#if 0
1766      wd17xx_set_intrq(device);
1767#endif
1768      wd17xx_set_busy(device, attotime::from_usec(100));
1769   }
1770
1771   if (w->command_type == TYPE_I)
1772   {
1773      /* 0 is enable spin up sequence, 1 is disable spin up sequence */
1774      if ((data & FDC_STEP_HDLOAD)==0)
1775      {
1776         w->status |= STA_1_HD_LOADED;
1777         w->hld_count = 2;
1778      }
1779      else
1780         w->status &= ~STA_1_HD_LOADED;
1781
1782      if (data & FDC_STEP_VERIFY)
1783      {
1784         /* verify seek */
1785         wd17xx_verify_seek(device);
1786      }
1787   }
1788}
1789
1790/* write the FDC track register */
1791WRITE8_DEVICE_HANDLER( wd17xx_track_w )
1792{
1793   wd1770_state *w = get_safe_token(device);
1794
1795   w->track = data;
1796
1797   if (VERBOSE)
1798      logerror("%s: wd17xx_track_w $%02X\n", device->machine().describe_context(), data);
1799}
1800
1801/* write the FDC sector register */
1802WRITE8_DEVICE_HANDLER( wd17xx_sector_w )
1803{
1804   wd1770_state *w = get_safe_token(device);
1805
1806   w->sector = data;
1807
1808   if (VERBOSE)
1809      logerror("%s: wd17xx_sector_w $%02X\n", device->machine().describe_context(), data);
1810}
1811
1812/* write the FDC data register */
1813WRITE8_DEVICE_HANDLER( wd17xx_data_w )
1814{
1815   wd1770_state *w = get_safe_token(device);
1816
1817   if (w->data_count > 0)
1818   {
1819      wd17xx_clear_drq(device);
1820
1821      /* put byte into buffer */
1822      if (VERBOSE_DATA)
1823         logerror("wd17xx_info buffered data: $%02X at offset %d.\n", data, w->data_offset);
1824
1825      w->buffer[w->data_offset++] = data;
1826
1827                if (--w->data_count < 1)
1828                {
1829                        if (w->command == FDC_WRITE_TRK)
1830                                write_track(device);
1831                        else
1832                                wd17xx_write_sector(device);
1833
1834                        w->data_offset = 0;
1835
1836                  /* Check we should handle the next sector for a multi record write */
1837                  if ( w->command_type == TYPE_II && w->command == FDC_WRITE_SEC && ( w->write_cmd & FDC_MULTI_REC ) )
1838                  {
1839                     w->sector++;
1840                     if (wd17xx_locate_sector(device))
1841                     {
1842                        w->data_count = w->sector_length;
1843
1844                        w->status |= STA_2_BUSY;
1845                        w->busy_count = 0;
1846
1847                        wd17xx_timed_data_request(device);
1848                     }
1849                  }
1850                  else
1851                  {
1852                     wd17xx_complete_command(device, DELAY_DATADONE);
1853                     if (VERBOSE)
1854                        logerror("wd17xx_data_w(): multi data write completed\n");
1855                  }
1856//                       wd17xx_complete_command(device, DELAY_DATADONE);
1857                }
1858                else
1859                {
1860                        if (w->command == FDC_WRITE_TRK)
1861                        {
1862                                /* Process special data values according to WD17xx specification.
1863                   Note that as CRC values take up two bytes which are written on
1864                   every 0xf7 byte, this will cause the actual image to
1865                   grow larger than what was written from the system. So we need
1866                   to take the value of data_offset when writing the track.
1867                                */
1868                                if (wd17xx_dden(device))
1869                                {
1870                                        switch (data)
1871                                        {
1872                                        case 0xf5:
1873                                        case 0xf6:
1874                                                /* not allowed in FM. */
1875                                                /* Take back the last write. */
1876                                                w->data_offset--;
1877                                                break;
1878                                        case 0xf7:
1879                                                /* Take back the last write. */
1880                                                w->data_offset--;
1881                                                /* write two crc bytes */
1882                                                w->buffer[w->data_offset++] = (w->crc>>8)&0xff;
1883                                                w->buffer[w->data_offset++] = (w->crc&0xff);
1884                                                w->crc_active = FALSE;
1885                                                break;
1886                                        case 0xf8:
1887                                        case 0xf9:
1888                                        case 0xfa:
1889                                        case 0xfb:
1890                                        case 0xfe:
1891                                                /* Preset crc */
1892                                                w->crc = 0xffff;
1893                  /* AM is included in the CRC */
1894                  w->crc = ccitt_crc16_one(w->crc, data);
1895                                                w->crc_active = TRUE;
1896                                                break;
1897                                        case 0xfc:
1898                                                /* Write index mark. No effect here as we do not store clock patterns.
1899                           Maybe later. */
1900                                                break;
1901                                        case 0xfd:
1902                                                /* Just write, don't use for CRC. */
1903                                                break;
1904                                        default:
1905                                                /* Byte already written. */
1906                                                if (w->crc_active)
1907                                                        w->crc = ccitt_crc16_one(w->crc, data);
1908                                        }
1909                                }
1910                                else  /* MFM */
1911                                {
1912                                        switch (data)
1913                                        {
1914                                        case 0xf5:
1915                                                /* Take back the last write. */
1916                                                w->data_offset--;
1917                                                /* Write a1 */
1918                                                w->buffer[w->data_offset++] = 0xa1;
1919                                                /* Preset CRC */
1920                                                w->crc = 0xffff;
1921                                                w->crc_active = TRUE;
1922                                                break;
1923                                        case 0xf6:
1924                                                /* Take back the last write. */
1925                                                w->data_offset--;
1926                                                /* Write c2 */
1927                                                w->buffer[w->data_offset++] = 0xc2;
1928                                                break;
1929                                        case 0xf7:
1930                                                /* Take back the last write. */
1931                                                w->data_offset--;
1932                                                /* write two crc bytes */
1933                                                w->buffer[w->data_offset++] = (w->crc>>8)&0xff;
1934                                                w->buffer[w->data_offset++] = (w->crc&0xff);
1935                                                w->crc_active = FALSE;
1936                                                break;
1937                                        case 0xf8:
1938                                        case 0xf9:
1939                                        case 0xfa:
1940                                        case 0xfb:
1941                                        case 0xfc:
1942                                        case 0xfd:
1943                                                /* Just write, don't use for CRC. */
1944                                                break;
1945                                        case 0xfe:
1946                  /* AM is included in the CRC */
1947                  if (w->crc_active)
1948                     w->crc = ccitt_crc16_one(w->crc, data);
1949                                                break;
1950                                        default:
1951                                                /* Byte already written. */
1952                                                if (w->crc_active)
1953                                                        w->crc = ccitt_crc16_one(w->crc, data);
1954                                        }
1955                                }
1956                        }
1957                        /* yes... setup a timed data request */
1958                        wd17xx_timed_data_request(device);
1959                }
1960   }
1961   else
1962   {
1963      if (VERBOSE)
1964         logerror("%s: wd17xx_data_w $%02X\n", device->machine().describe_context(), data);
1965   }
1966   w->data = data;
1967}
1968
1969READ8_DEVICE_HANDLER( wd17xx_r )
1970{
1971   switch (offset & 0x03)
1972   {
1973   case 0: return wd17xx_status_r(device, 0);
1974   case 1:   return wd17xx_track_r(device, 0);
1975   case 2:   return wd17xx_sector_r(device, 0);
1976   case 3:   return wd17xx_data_r(device, 0);
1977   }
1978
1979   return 0;
1980}
1981
1982WRITE8_DEVICE_HANDLER( wd17xx_w )
1983{
1984   switch (offset & 0x03)
1985   {
1986   case 0: wd17xx_command_w(device, 0, data); break;
1987   case 1:   wd17xx_track_w(device, 0, data);   break;
1988   case 2: wd17xx_sector_w(device, 0, data);  break;
1989   case 3: wd17xx_data_w(device, 0, data);    break;
1990   }
1991}
1992
1993
1994/***************************************************************************
1995    MAME DEVICE INTERFACE
1996***************************************************************************/
1997
1998static DEVICE_START( wd1770 )
1999{
2000   wd1770_state *w = get_safe_token(device);
2001
2002   assert(device->static_config() != NULL);
2003
2004   w->intf = (const wd17xx_interface*)device->static_config();
2005
2006   w->status = STA_1_TRACK0;
2007   w->pause_time = 1000;
2008
2009   /* allocate timers */
2010   w->timer_cmd = device->machine().scheduler().timer_alloc(FUNC(wd17xx_command_callback), (void *)device);
2011   w->timer_data = device->machine().scheduler().timer_alloc(FUNC(wd17xx_data_callback), (void *)device);
2012   w->timer_rs = device->machine().scheduler().timer_alloc(FUNC(wd17xx_read_sector_callback), (void *)device);
2013   w->timer_ws = device->machine().scheduler().timer_alloc(FUNC(wd17xx_write_sector_callback), (void *)device);
2014
2015   /* resolve callbacks */
2016   w->in_dden_func.resolve(w->intf->in_dden_func, *device);
2017   w->out_intrq_func.resolve(w->intf->out_intrq_func, *device);
2018   w->out_drq_func.resolve(w->intf->out_drq_func, *device);
2019
2020   /* stepping rate depends on the clock */
2021   w->stepping_rate[0] = 6;
2022   w->stepping_rate[1] = 12;
2023   w->stepping_rate[2] = 20;
2024   w->stepping_rate[3] = 30;
2025}
2026
2027static DEVICE_START( wd1772 )
2028{
2029   wd1770_state *w = get_safe_token(device);
2030
2031   DEVICE_START_CALL(wd1770);
2032
2033   /* the 1772 has faster track stepping rates */
2034   w->stepping_rate[0] = 6;
2035   w->stepping_rate[1] = 12;
2036   w->stepping_rate[2] = 2;
2037   w->stepping_rate[3] = 3;
2038}
2039
2040static DEVICE_RESET( wd1770 )
2041{
2042   wd1770_state *w = get_safe_token(device);
2043   int i;
2044
2045   /* set the default state of some input lines */
2046   w->mr = ASSERT_LINE;
2047   w->wprt = ASSERT_LINE;
2048   w->dden = ASSERT_LINE;
2049
2050   for (i = 0; i < 4; i++)
2051   {
2052      if(w->intf->floppy_drive_tags[i]!=NULL) {
2053         device_t *img = NULL;
2054
2055         if (device->owner() != NULL)
2056            img = device->owner()->subdevice(w->intf->floppy_drive_tags[i]);
2057            if (img == NULL) {
2058               img = device->machine().device(w->intf->floppy_drive_tags[i]);
2059            }
2060
2061         else
2062            img = device->machine().device(w->intf->floppy_drive_tags[i]);
2063
2064         if (img!=NULL) {
2065            floppy_drive_set_controller(img,device);
2066            floppy_drive_set_index_pulse_callback(img, wd17xx_index_pulse_callback);
2067            floppy_drive_set_rpm( img, 300.);
2068         }
2069      }
2070   }
2071
2072   wd17xx_set_drive(device, 0);
2073
2074   w->hd = 0;
2075   w->hld_count = 0;
2076   w->sector = 1;
2077   wd17xx_command_restore(device);
2078}
2079
2080void wd17xx_reset(device_t *device)
2081{
2082   DEVICE_RESET_CALL( wd1770 );
2083}
2084
2085
2086/***************************************************************************
2087    DEVICE GETINFO
2088***************************************************************************/
2089
2090static const char DEVTEMPLATE_SOURCE[] = __FILE__;
2091
2092#define DEVTEMPLATE_ID(p,s)            p##wd1770##s
2093#define DEVTEMPLATE_FEATURES         DT_HAS_START | DT_HAS_RESET
2094#define DEVTEMPLATE_NAME            "WD1770"
2095#define DEVTEMPLATE_FAMILY            "WD17xx"
2096#define DEVTEMPLATE_VERSION            "1.0"
2097#define DEVTEMPLATE_CREDITS            "Copyright MESS Team"
2098#include "devtempl.h"
2099
2100#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd1771##s
2101#define DEVTEMPLATE_DERIVED_FEATURES   0
2102#define DEVTEMPLATE_DERIVED_NAME      "WD1771"
2103#include "devtempl.h"
2104
2105#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd1772##s
2106#define DEVTEMPLATE_DERIVED_FEATURES   DT_HAS_START
2107#define DEVTEMPLATE_DERIVED_NAME      "WD1772"
2108#include "devtempl.h"
2109
2110#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd1773##s
2111#define DEVTEMPLATE_DERIVED_FEATURES   0
2112#define DEVTEMPLATE_DERIVED_NAME      "WD1773"
2113#include "devtempl.h"
2114
2115#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd1793##s
2116#define DEVTEMPLATE_DERIVED_FEATURES   0
2117#define DEVTEMPLATE_DERIVED_NAME      "WD1793"
2118#include "devtempl.h"
2119
2120#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd1795##s
2121#define DEVTEMPLATE_DERIVED_FEATURES   0
2122#define DEVTEMPLATE_DERIVED_NAME      "WD1795"
2123#include "devtempl.h"
2124
2125#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd1797##s
2126#define DEVTEMPLATE_DERIVED_FEATURES   0
2127#define DEVTEMPLATE_DERIVED_NAME      "WD1797"
2128#include "devtempl.h"
2129
2130#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd2793##s
2131#define DEVTEMPLATE_DERIVED_FEATURES   0
2132#define DEVTEMPLATE_DERIVED_NAME      "WD2793"
2133#include "devtempl.h"
2134
2135#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd2795##s
2136#define DEVTEMPLATE_DERIVED_FEATURES   0
2137#define DEVTEMPLATE_DERIVED_NAME      "WD2795"
2138#include "devtempl.h"
2139
2140#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd2797##s
2141#define DEVTEMPLATE_DERIVED_FEATURES   0
2142#define DEVTEMPLATE_DERIVED_NAME      "WD2797"
2143#include "devtempl.h"
2144
2145#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd177x##s
2146#define DEVTEMPLATE_DERIVED_FEATURES   0
2147#define DEVTEMPLATE_DERIVED_NAME      "WD179x"
2148#include "devtempl.h"
2149
2150#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd179x##s
2151#define DEVTEMPLATE_DERIVED_FEATURES   0
2152#define DEVTEMPLATE_DERIVED_NAME      "WD179x"
2153#include "devtempl.h"
2154
2155#define DEVTEMPLATE_DERIVED_ID(p,s)      p##mb8877##s
2156#define DEVTEMPLATE_DERIVED_FEATURES   0
2157#define DEVTEMPLATE_DERIVED_NAME      "MB8877"
2158#include "devtempl.h"
2159
2160DEFINE_LEGACY_DEVICE(WD1770, wd1770);
2161DEFINE_LEGACY_DEVICE(WD1771, wd1771);
2162DEFINE_LEGACY_DEVICE(WD1772, wd1772);
2163DEFINE_LEGACY_DEVICE(WD1773, wd1773);
2164DEFINE_LEGACY_DEVICE(WD1793, wd1793);
2165DEFINE_LEGACY_DEVICE(WD1795, wd1795);
2166DEFINE_LEGACY_DEVICE(WD1797, wd1797);
2167DEFINE_LEGACY_DEVICE(WD2793, wd2793);
2168DEFINE_LEGACY_DEVICE(WD2795, wd2795);
2169DEFINE_LEGACY_DEVICE(WD2797, wd2797);
2170DEFINE_LEGACY_DEVICE(WD177X, wd177x);
2171DEFINE_LEGACY_DEVICE(WD179X, wd179x);
2172DEFINE_LEGACY_DEVICE(MB8877, mb8877);
2173
src/emu/machine/wd17xx.h
r0r11461
1/*********************************************************************
2
3    wd17xx.h
4
5    Implementations of the Western Digital 17xx and 27xx families of
6    floppy disk controllers
7
8*********************************************************************/
9
10#ifndef __WD17XX_H__
11#define __WD17XX_H__
12
13#include "devcb.h"
14
15
16/***************************************************************************
17    MACROS
18***************************************************************************/
19
20DECLARE_LEGACY_DEVICE(WD1770, wd1770);
21DECLARE_LEGACY_DEVICE(WD1771, wd1771);
22DECLARE_LEGACY_DEVICE(WD1772, wd1772);
23DECLARE_LEGACY_DEVICE(WD1773, wd1773);
24DECLARE_LEGACY_DEVICE(WD1793, wd1793);
25DECLARE_LEGACY_DEVICE(WD1795, wd1795);
26DECLARE_LEGACY_DEVICE(WD1797, wd1797);
27DECLARE_LEGACY_DEVICE(WD2793, wd2793);
28DECLARE_LEGACY_DEVICE(WD2795, wd2795);
29DECLARE_LEGACY_DEVICE(WD2797, wd2797);
30DECLARE_LEGACY_DEVICE(WD177X, wd177x);
31DECLARE_LEGACY_DEVICE(WD179X, wd179x);
32DECLARE_LEGACY_DEVICE(MB8877, mb8877);
33
34
35/***************************************************************************
36    TYPE DEFINITIONS
37***************************************************************************/
38
39/* Interface */
40typedef struct _wd17xx_interface wd17xx_interface;
41struct _wd17xx_interface
42{
43   devcb_read_line in_dden_func;
44   devcb_write_line out_intrq_func;
45   devcb_write_line out_drq_func;
46   const char *floppy_drive_tags[4];
47};
48
49
50/***************************************************************************
51    FUNCTION PROTOTYPES
52***************************************************************************/
53void wd17xx_reset(device_t *device);
54
55/* the following are not strictly part of the wd179x hardware/emulation
56but will be put here for now until the flopdrv code has been finalised more */
57void wd17xx_set_drive(device_t *device, UINT8);      /* set drive wd179x is accessing */
58void wd17xx_set_side(device_t *device, UINT8);      /* set side wd179x is accessing */
59
60void wd17xx_set_pause_time(device_t *device, int usec);       /* default is 40 usec if not set */
61
62READ8_DEVICE_HANDLER( wd17xx_status_r );
63READ8_DEVICE_HANDLER( wd17xx_track_r );
64READ8_DEVICE_HANDLER( wd17xx_sector_r );
65READ8_DEVICE_HANDLER( wd17xx_data_r );
66
67WRITE8_DEVICE_HANDLER( wd17xx_command_w );
68WRITE8_DEVICE_HANDLER( wd17xx_track_w );
69WRITE8_DEVICE_HANDLER( wd17xx_sector_w );
70WRITE8_DEVICE_HANDLER( wd17xx_data_w );
71
72READ8_DEVICE_HANDLER( wd17xx_r );
73WRITE8_DEVICE_HANDLER( wd17xx_w );
74
75WRITE_LINE_DEVICE_HANDLER( wd17xx_mr_w );
76WRITE_LINE_DEVICE_HANDLER( wd17xx_rdy_w );
77READ_LINE_DEVICE_HANDLER( wd17xx_mo_r );
78WRITE_LINE_DEVICE_HANDLER( wd17xx_tr00_w );
79WRITE_LINE_DEVICE_HANDLER( wd17xx_idx_w );
80WRITE_LINE_DEVICE_HANDLER( wd17xx_wprt_w );
81WRITE_LINE_DEVICE_HANDLER( wd17xx_dden_w );
82READ_LINE_DEVICE_HANDLER( wd17xx_drq_r );
83READ_LINE_DEVICE_HANDLER( wd17xx_intrq_r );
84
85extern const wd17xx_interface default_wd17xx_interface;
86extern const wd17xx_interface default_wd17xx_interface_2_drives;
87
88
89/***************************************************************************
90    DEVICE CONFIGURATION MACROS
91***************************************************************************/
92
93#define MCFG_WD1770_ADD(_tag, _intrf) \
94   MCFG_DEVICE_ADD(_tag, WD1770, 0) \
95   MCFG_DEVICE_CONFIG(_intrf)
96
97#define MCFG_WD1771_ADD(_tag, _intrf) \
98   MCFG_DEVICE_ADD(_tag, WD1771, 0) \
99   MCFG_DEVICE_CONFIG(_intrf)
100
101#define MCFG_WD1772_ADD(_tag, _intrf) \
102   MCFG_DEVICE_ADD(_tag, WD1772, 0) \
103   MCFG_DEVICE_CONFIG(_intrf)
104
105#define MCFG_WD1773_ADD(_tag, _intrf) \
106   MCFG_DEVICE_ADD(_tag, WD1773, 0) \
107   MCFG_DEVICE_CONFIG(_intrf)
108
109#define MCFG_WD1793_ADD(_tag, _intrf) \
110   MCFG_DEVICE_ADD(_tag, WD1793, 0) \
111   MCFG_DEVICE_CONFIG(_intrf)
112
113#define MCFG_WD1795_ADD(_tag, _intrf) \
114   MCFG_DEVICE_ADD(_tag, WD1795, 0) \
115   MCFG_DEVICE_CONFIG(_intrf)
116
117#define MCFG_WD1797_ADD(_tag, _intrf) \
118   MCFG_DEVICE_ADD(_tag, WD1797, 0) \
119   MCFG_DEVICE_CONFIG(_intrf)
120
121#define MCFG_WD2793_ADD(_tag, _intrf) \
122   MCFG_DEVICE_ADD(_tag, WD2793, 0) \
123   MCFG_DEVICE_CONFIG(_intrf)
124
125#define MCFG_WD2795_ADD(_tag, _intrf) \
126   MCFG_DEVICE_ADD(_tag, WD2795, 0) \
127   MCFG_DEVICE_CONFIG(_intrf)
128
129#define MCFG_WD2797_ADD(_tag, _intrf) \
130   MCFG_DEVICE_ADD(_tag, WD2797, 0) \
131   MCFG_DEVICE_CONFIG(_intrf)
132
133#define MCFG_WD177X_ADD(_tag, _intrf) \
134   MCFG_DEVICE_ADD(_tag, WD177X, 0) \
135   MCFG_DEVICE_CONFIG(_intrf)
136
137#define MCFG_WD179X_ADD(_tag, _intrf) \
138   MCFG_DEVICE_ADD(_tag, WD179X, 0) \
139   MCFG_DEVICE_CONFIG(_intrf)
140
141#define MCFG_MB8877_ADD(_tag, _intrf) \
142   MCFG_DEVICE_ADD(_tag, MB8877, 0) \
143   MCFG_DEVICE_CONFIG(_intrf)
144
145
146#endif /* __WD17XX_H__ */
src/mess/devices/aescart.c
r11460r11461
1/**********************************************************************
2
3    aescart.c
4
5    Neo-Geo AES cartridge management
6    R. Belmont, 2009
7
8    Based on ti99cart.c by Michael Zapf
9
10    We leave the support in place for multiple slots in case MAME
11    uses this at some future point for MVS multi-cart.
12
13*********************************************************************/
14#include "emu.h"
15#include "aescart.h"
16#include "imagedev/cartslot.h"
17#include "imagedev/multcart.h"
18#include "includes/neogeo.h"
19
20typedef int assmfct(running_machine &machine, device_t *);
21
22enum
23{
24   AESCART_FCT_ASSM = DEVINFO_FCT_DEVICE_SPECIFIC,
25   AESCART_FCT_DISASSM
26};
27
28struct _aes_multicart_t
29{
30   /* Reserves space for all cartridges. This is also used in the legacy
31       cartridge system, but only for slot 0. */
32   aescartridge_t cartridge[AES_NUMBER_OF_CARTRIDGE_SLOTS];
33
34   /* Determines which slot is currently active. This value is changed when there
35    are accesses to other GROM base addresses. */
36   int active_slot;
37
38   /* Used in order to enforce a special slot. This value is retrieved
39       from the dipswitch setting. A value of -1 means automatic, that is,
40       the grom base switch is used. Values 0 .. max refer to the
41       respective slot. */
42   int fixed_slot;
43
44   /* Holds the highest index of a cartridge being plugged in plus one.
45       If we only have one cartridge inserted, we don't want to get a
46       selection option, so we just mirror the memory contents. */
47   int next_free_slot;
48
49   /* Counts the number of slots which currently contain legacy format
50       cartridge images. */
51   int legacy_slots;
52
53   /* Counts the number of slots which currently contain new format
54       cartridge images. */
55   int multi_slots;
56};
57typedef struct _aes_multicart_t aes_multicart_t;
58
59#define AUTO -1
60
61/* Access to the pcb. Contained in the token of the pcb instance. */
62struct _aes_pcb_t
63{
64   /* Link up to the cartridge structure which contains this pcb. */
65   aescartridge_t *cartridge;
66
67   /* Function to assemble this cartridge. */
68   assmfct   *assemble;
69
70   /* Function to disassemble this cartridge. */
71   assmfct   *disassemble;
72};
73typedef struct _aes_pcb_t aes_pcb_t;
74
75INLINE aes_multicart_t *get_safe_token(device_t *device)
76{
77   assert(device != NULL);
78   assert(device->type() == AES_MULTICART);
79
80   return (aes_multicart_t *)downcast<legacy_device_base *>(device)->token();
81}
82
83INLINE aes_pcb_t *get_safe_pcb_token(device_t *device)
84{
85   assert(device != NULL);
86   assert(device->type() == AES_CARTRIDGE_PCB_NONE || device->type() == AES_CARTRIDGE_PCB_STD);
87
88   return (aes_pcb_t *)downcast<legacy_device_base *>(device)->token();
89}
90
91INLINE cartslot_t *get_safe_cartslot_token(device_t *device)
92{
93   assert(device != NULL);
94   assert(device->type() == CARTSLOT);
95
96   return (cartslot_t *)downcast<legacy_device_base *>(device)->token();
97}
98
99/*
100    Find the index of the cartridge name. We assume the format
101    <name><number>, i.e. the number is the longest string from the right
102    which can be interpreted as a number.
103*/
104static int get_index_from_tagname(device_t *image)
105{
106   const char *tag = image->tag();
107   int maxlen = strlen(tag);
108   int i;
109   for (i=maxlen-1; i >=0; i--)
110      if (tag[i] < 48 || tag[i] > 57) break;
111
112   return atoi(tag+i+1);
113}
114
115/*
116    Common routine to assemble cartridges from resources.
117*/
118static aescartridge_t *assemble_common(running_machine &machine, device_t *cartslot)
119{
120   /* Pointer to the cartridge structure. */
121   aescartridge_t *cartridge;
122   device_t *cartsys = cartslot->owner();
123   aes_multicart_t *cartslots = get_safe_token(cartsys);
124   UINT8 *socketcont, *romrgn;
125   int reslength, i, blockofs;
126   char sprname1[16], sprname2[16];
127
128   int slotnumber = get_index_from_tagname(cartslot)-1;
129   assert(slotnumber>=0 && slotnumber<AES_NUMBER_OF_CARTRIDGE_SLOTS);
130
131   /* There is a cartridge in this slot, check the maximum slot number. */
132   if (cartslots->next_free_slot <= slotnumber)
133   {
134      cartslots->next_free_slot = slotnumber+1;
135   }
136   cartridge = &cartslots->cartridge[slotnumber];
137
138   // check for up to 4 program ROMs
139   romrgn = (UINT8 *)machine.region("maincpu")->base();
140   blockofs = 0;
141   for (i = 0; i < 4; i++)
142   {
143      sprintf(sprname1, "p%d", i+1);
144
145      socketcont = (UINT8*)cartslot_get_socket(cartslot, sprname1);
146      reslength = cartslot_get_resource_length(cartslot, sprname1);
147
148      if (socketcont != NULL)
149      {
150         memcpy(romrgn+blockofs, socketcont, reslength);
151         blockofs += reslength;
152      }
153   }
154
155   // 1 m1 ROM
156   socketcont = (UINT8*)cartslot_get_socket(cartslot, "m1");
157   reslength = cartslot_get_resource_length(cartslot, "m1");
158   if (socketcont != NULL)
159   {
160      romrgn = (UINT8 *)machine.region("audiocpu")->base();
161
162      memcpy(romrgn, socketcont, reslength);
163      // mirror (how does this really work?)
164      memcpy(romrgn+0x10000, socketcont, reslength);
165   }
166
167   // up to 8 YM sample ROMs
168   romrgn = (UINT8 *)machine.region("ymsnd")->base();
169   blockofs = 0;
170   for (i = 0; i < 8; i++)
171   {
172      sprintf(sprname1, "v1%d", i+1);
173
174      socketcont = (UINT8*)cartslot_get_socket(cartslot, sprname1);
175      reslength = cartslot_get_resource_length(cartslot, sprname1);
176
177      if (socketcont != NULL)
178      {
179         memcpy(romrgn+blockofs, socketcont, reslength);
180         blockofs += reslength;
181      }
182   }
183
184   // up to 8 YM delta-T sample ROMs
185   romrgn = (UINT8 *)machine.region("ymsnd.deltat")->base();
186   blockofs = 0;
187   for (i = 0; i < 8; i++)
188   {
189      sprintf(sprname1, "v2%d", i+1);
190
191      socketcont = (UINT8*)cartslot_get_socket(cartslot, sprname1);
192      reslength = cartslot_get_resource_length(cartslot, sprname1);
193
194      if (socketcont != NULL)
195      {
196         memcpy(romrgn+blockofs, socketcont, reslength);
197         blockofs += reslength;
198      }
199   }
200
201   // 1 s1 ROM
202   socketcont = (UINT8*)cartslot_get_socket(cartslot, "s1");
203   reslength = cartslot_get_resource_length(cartslot, "s1");
204   if (socketcont != NULL)
205   {
206      romrgn = (UINT8 *)machine.region("fixed")->base();
207
208      memcpy(romrgn, socketcont, reslength);
209   }
210
211   // up to 8 sprite ROMs in byte-interleaved pairs
212   romrgn = (UINT8 *)machine.region("sprites")->base();
213   blockofs = 0;
214   for (i = 0; i < 8; i+=2)
215   {
216      UINT8 *spr1, *spr2;
217      int j;
218
219      sprintf(sprname1, "c%d", i+1);
220      sprintf(sprname2, "c%d", i+2);
221
222      spr1 = (UINT8*)cartslot_get_socket(cartslot, sprname1);
223      spr2 = (UINT8*)cartslot_get_socket(cartslot, sprname2);
224      reslength = cartslot_get_resource_length(cartslot, sprname1);
225
226      if ((spr1) && (spr2))
227      {
228         for (j = 0; j < reslength; j++)
229         {
230            romrgn[blockofs + (j*2)] = spr1[j];
231            romrgn[blockofs + (j*2) + 1] = spr2[j];
232         }
233
234         blockofs += reslength*2;
235      }
236   }
237
238   return cartridge;
239}
240
241static void set_pointers(device_t *pcb, int index)
242{
243   device_t *cartsys = pcb->owner()->owner();
244   aes_multicart_t *cartslots = get_safe_token(cartsys);
245   aes_pcb_t *pcb_def = get_safe_pcb_token(pcb);
246
247   pcb_def->assemble = (assmfct *)downcast<const legacy_cart_slot_device_base *>(pcb)->get_legacy_fct(AESCART_FCT_ASSM);
248   pcb_def->disassemble = (assmfct *)downcast<const legacy_cart_slot_device_base *>(pcb)->get_legacy_fct(AESCART_FCT_DISASSM);
249
250   pcb_def->cartridge = &cartslots->cartridge[index];
251   pcb_def->cartridge->pcb = pcb;
252}
253
254/*****************************************************************************
255  Cartridge type: None
256    This PCB device is just a pseudo device; the legacy mode is handled
257    by dedicated functions.
258******************************************************************************/
259static DEVICE_START(aes_pcb_none)
260{
261   /* device is aes_cartslot:cartridge:pcb */
262//  printf("DEVICE_START(aes_pcb_none), tag of device=%s\n", device->tag());
263   set_pointers(device, get_index_from_tagname(device->owner())-1);
264}
265
266/*****************************************************************************
267  Cartridge type: Standard
268    Most cartridges are built in this type. This includes word-swapped program,
269    z80 program, YM samples, delta-T samples, sprites, and sfix.
270******************************************************************************/
271
272static DEVICE_START(aes_pcb_std)
273{
274   /* device is aes_cartslot:cartridge:pcb */
275//  printf("DEVICE_START(aes_pcb_std), tag of device=%s\n", device->tag());
276   set_pointers(device, get_index_from_tagname(device->owner())-1);
277}
278
279/*
280    The standard cartridge assemble routine. We just call the common
281    function here.
282*/
283static int assemble_std(running_machine &machine, device_t *image)
284{
285//  aescartridge_t *cart;
286//  printf("assemble_std, %s\n", image->tag);
287   /*cart = */assemble_common(machine, image);
288
289   return IMAGE_INIT_PASS;
290}
291
292/*
293    Removes pointers and restores the state before plugging in the
294    cartridge.
295    The pointer to the location after the last cartridge is adjusted.
296    As it seems, we can use the same function for the disassembling of all
297    cartridge types.
298*/
299static int disassemble_std(device_t *image)
300{
301//  int slotnumber;
302//  int i;
303//  aescartridge_t *cart;
304//  device_t *cartsys = image->owner();
305//  aes_multicart_t *cartslots = (aes_multicart_t *)cartsys->token;
306
307//  slotnumber = get_index_from_tagname(image)-1;
308//  printf("Disassemble cartridge %d\n", slotnumber);
309#if 0
310   /* Search the highest remaining cartridge. */
311   cartslots->next_free_slot = 0;
312   for (i=AES_NUMBER_OF_CARTRIDGE_SLOTS-1; i >= 0; i--)
313   {
314      if (i != slotnumber)
315      {
316         if (0) //!slot_is_empty(cartsys, i))    (for future use?)
317         {
318            cartslots->next_free_slot = i+1;
319//              printf("Setting new next_free_slot to %d\n", cartslots->next_free_slot);
320            break;
321         }
322      }
323   }
324#endif
325   /* Do we have RAM? If so, swap the bytes (undo the BIG_ENDIANIZE) */
326//  cart = &cartslots->cartridge[slotnumber];
327
328//  clear_slot(cartsys, slotnumber);
329
330   return IMAGE_INIT_PASS;
331}
332
333/*****************************************************************************
334  Device metadata
335******************************************************************************/
336
337static DEVICE_GET_INFO(aes_cart_common)
338{
339   switch(state)
340   {
341      /* --- the following bits of info are returned as 64-bit signed integers --- */
342      case DEVINFO_INT_TOKEN_BYTES:
343         info->i = sizeof(aes_pcb_t);
344         break;
345      case DEVINFO_INT_INLINE_CONFIG_BYTES:
346         info->i = 0;
347         break;
348
349      /* --- the following bits of info are returned as pointers to functions --- */
350      case DEVINFO_FCT_START:
351         info->start = DEVICE_START_NAME(aes_pcb_std);
352         break;
353      case DEVINFO_FCT_STOP:
354         /* Nothing */
355         break;
356      case DEVINFO_FCT_RESET:
357         /* Nothing */
358         break;
359
360      case AESCART_FCT_ASSM:
361         info->f = (genf *) assemble_std;
362         break;
363
364      case AESCART_FCT_DISASSM:
365         info->f = (genf *) disassemble_std;
366         break;
367
368      /* --- the following bits of info are returned as NULL-terminated strings --- */
369      case DEVINFO_STR_NAME:
370         strcpy(info->s, "AES standard cartridge pcb");
371         break;
372      case DEVINFO_STR_FAMILY:
373         strcpy(info->s, "AES cartridge pcb");
374         break;
375      case DEVINFO_STR_VERSION:
376         strcpy(info->s, "1.0");
377         break;
378      case DEVINFO_STR_SOURCE_FILE:
379         strcpy(info->s, __FILE__);
380         break;
381      case DEVINFO_STR_CREDITS:
382         /* Nothing */
383         break;
384   }
385}
386
387DEVICE_GET_INFO(aes_cartridge_pcb_none)
388{
389   switch(state)
390   {
391      case DEVINFO_FCT_START:
392         info->start = DEVICE_START_NAME(aes_pcb_none);
393         break;
394
395      case DEVINFO_STR_NAME:
396         strcpy(info->s, "AES empty cartridge");
397         break;
398
399      default:
400         DEVICE_GET_INFO_CALL(aes_cart_common);
401         break;
402   }
403}
404
405DEVICE_GET_INFO(aes_cartridge_pcb_std)
406{
407   DEVICE_GET_INFO_CALL(aes_cart_common);
408}
409
410/*****************************************************************************
411  The cartridge handling of the multi-cartridge system.
412  Every cartridge contains a PCB device. The memory handlers delegate the calls
413  to the respective handlers of the cartridges.
414******************************************************************************/
415/*
416    Initialize a cartridge. Each cartridge contains a PCB device.
417*/
418static DEVICE_START( aes_cartridge )
419{
420   cartslot_t *cart = get_safe_cartslot_token(device);
421
422   /* find the PCB device */
423   cart->pcb_device = device->subdevice(TAG_PCB);
424}
425
426// handle protected carts
427static void install_protection(device_image_interface& image)
428{
429   neogeo_state *state = image.device().machine().driver_data<neogeo_state>();
430   const char *crypt_feature = image.get_feature( "crypt" );
431
432   if(crypt_feature == NULL)
433      return;
434
435   if(strcmp(crypt_feature,"fatfury2_prot") == 0)
436   {
437      fatfury2_install_protection(image.device().machine());
438      logerror("Installed Fatal Fury 2 protection\n");
439   }
440   if(strcmp(crypt_feature,"kof99_crypt") == 0)
441   {
442      kof99_decrypt_68k(image.device().machine());
443      state->m_fixed_layer_bank_type = 1;
444      kof99_neogeo_gfx_decrypt(image.device().machine(), 0x00);
445      kof99_install_protection(image.device().machine());
446      logerror("Decrypted KOF99 code and graphics.\n");
447   }
448   if(strcmp(crypt_feature,"mslug3_crypt") == 0)
449   {
450      state->m_fixed_layer_bank_type = 1;
451      kof99_neogeo_gfx_decrypt(image.device().machine(), 0xad);
452      logerror("Decrypted Metal Slug 3 graphics\n");
453   }
454   if(strcmp(crypt_feature,"matrim_crypt") == 0)
455   {
456      matrim_decrypt_68k(image.device().machine());
457      neo_pcm2_swap(image.device().machine(), 1);
458      state->m_fixed_layer_bank_type = 2;
459      neogeo_cmc50_m1_decrypt(image.device().machine());
460      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x6a);
461      logerror("Decrypted Matrimelee code, sound and graphics\n");
462   }
463   if(strcmp(crypt_feature,"svc_crypt") == 0)
464   {
465      svc_px_decrypt(image.device().machine());
466      neo_pcm2_swap(image.device().machine(), 3);
467      state->m_fixed_layer_bank_type = 2;
468      neogeo_cmc50_m1_decrypt(image.device().machine());
469      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x57);
470      install_pvc_protection(image.device().machine());
471      logerror("Decrypted SvC code, sound and graphics.\n");
472   }
473   if(strcmp(crypt_feature,"samsho5_crypt") == 0)
474   {
475      samsho5_decrypt_68k(image.device().machine());
476      neo_pcm2_swap(image.device().machine(), 4);
477      state->m_fixed_layer_bank_type = 1;
478      neogeo_cmc50_m1_decrypt(image.device().machine());
479      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x0f);
480      logerror("Decrypted Samurai Shodown V code, sound and graphics.\n");
481   }
482   if(strcmp(crypt_feature,"kof2000_crypt") == 0)
483   {
484      kof2000_decrypt_68k(image.device().machine());
485      state->m_fixed_layer_bank_type = 2;
486      neogeo_cmc50_m1_decrypt(image.device().machine());
487      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x00);
488      kof2000_install_protection(image.device().machine());
489      logerror("Decrypted KOF2000 code, sound and graphics.\n");
490   }
491   if(strcmp(crypt_feature,"kof2001_crypt") == 0)
492   {
493      state->m_fixed_layer_bank_type = 1;
494      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x1e);
495      neogeo_cmc50_m1_decrypt(image.device().machine());
496      logerror("Decrypted KOF2001 code and graphics.\n");
497   }
498   if(strcmp(crypt_feature,"kof2002_crypt") == 0)
499   {
500      kof2002_decrypt_68k(image.device().machine());
501      neo_pcm2_swap(image.device().machine(), 0);
502      neogeo_cmc50_m1_decrypt(image.device().machine());
503      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0xec);
504      logerror("Decrypted KOF2002 code, sound and graphics.\n");
505   }
506   if(strcmp(crypt_feature,"mslug4_crypt") == 0)
507   {
508      state->m_fixed_layer_bank_type = 1; /* USA violent content screen is wrong -- not a bug, confirmed on real hardware! */
509      neogeo_cmc50_m1_decrypt(image.device().machine());
510      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x31);
511      neo_pcm2_snk_1999(image.device().machine(), 8);
512      logerror("Decrypted Metal Slug 4 code, sound and graphics.\n");
513   }
514   if(strcmp(crypt_feature,"mslug5_crypt") == 0)
515   {
516      mslug5_decrypt_68k(image.device().machine());
517      neo_pcm2_swap(image.device().machine(), 2);
518      state->m_fixed_layer_bank_type = 1;
519      neogeo_cmc50_m1_decrypt(image.device().machine());
520      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x19);
521      install_pvc_protection(image.device().machine());
522      logerror("Decrypted Metal Slug 5 code and graphics, and installed protection routines.\n");
523   }
524   if(strcmp(crypt_feature,"kof2003_crypt") == 0)
525   {
526      kof2003h_decrypt_68k(image.device().machine());
527      neo_pcm2_swap(image.device().machine(), 5);
528      state->m_fixed_layer_bank_type = 2;
529      neogeo_cmc50_m1_decrypt(image.device().machine());
530      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x9d);
531      install_pvc_protection(image.device().machine());
532      logerror("Decrypted KOF2003 code and graphicss, and installed protection routines.\n");
533   }
534   if(strcmp(crypt_feature,"samsho5s_crypt") == 0)
535   {
536      samsh5sp_decrypt_68k(image.device().machine());
537      neo_pcm2_swap(image.device().machine(), 6);
538      state->m_fixed_layer_bank_type = 1;
539      neogeo_cmc50_m1_decrypt(image.device().machine());
540      kof2000_neogeo_gfx_decrypt(image.device().machine(), 0x0d);
541   }
542}
543
544/*
545    Load the cartridge image files. Apart from reading, we set pointers
546    to the image files so that during runtime we do not need search
547    operations.
548*/
549static DEVICE_IMAGE_LOAD( aes_cartridge )
550{
551   device_t *pcbdev = cartslot_get_pcb(image);
552   aes_pcb_t *pcb;
553   cartslot_t *cart;
554   multicart_open_error me;
555   UINT32 size;
556   device_t* ym = image.device().machine().device("ymsnd");
557
558   // first check software list
559   if(image.software_entry() != NULL)
560   {
561      // create memory regions
562      size = image.get_software_region_length("maincpu");
563      image.device().machine().region_free("maincpu");
564      image.device().machine().region_alloc("maincpu",size,1, ENDIANNESS_LITTLE);
565      memcpy(image.device().machine().region("maincpu")->base(),image.get_software_region("maincpu"),size);
566      size = image.get_software_region_length("fixed");
567      image.device().machine().region_free("fixed");
568      image.device().machine().region_alloc("fixed",size,1, ENDIANNESS_LITTLE);
569      memcpy(image.device().machine().region("fixed")->base(),image.get_software_region("fixed"),size);
570      size = image.get_software_region_length("audiocpu");
571      image.device().machine().region_free("audiocpu");
572      image.device().machine().region_alloc("audiocpu",size,1, ENDIANNESS_LITTLE);
573      memcpy(image.device().machine().region("audiocpu")->base(),image.get_software_region("audiocpu"),size);
574      size = image.get_software_region_length("ymsnd");
575      image.device().machine().region_free("ymsnd");
576      image.device().machine().region_alloc("ymsnd",size,1, ENDIANNESS_LITTLE);
577      memcpy(image.device().machine().region("ymsnd")->base(),image.get_software_region("ymsnd"),size);
578      if(image.get_software_region("ymsnd.deltat") != NULL)
579      {
580         size = image.get_software_region_length("ymsnd.deltat");
581         image.device().machine().region_free("ymsnd.deltat");
582         image.device().machine().region_alloc("ymsnd.deltat",size,1, ENDIANNESS_LITTLE);
583         memcpy(image.device().machine().region("ymsnd.deltat")->base(),image.get_software_region("ymsnd.deltat"),size);
584      }
585      else
586         image.device().machine().region_free("ymsnd.deltat");  // removing the region will fix sound glitches in non-Delta-T games
587      ym->reset();
588      size = image.get_software_region_length("sprites");
589      image.device().machine().region_free("sprites");
590      image.device().machine().region_alloc("sprites",size,1, ENDIANNESS_LITTLE);
591      memcpy(image.device().machine().region("sprites")->base(),image.get_software_region("sprites"),size);
592      if(image.get_software_region("audiocrypt") != NULL)  // encrypted Z80 code
593      {
594         size = image.get_software_region_length("audiocrypt");
595         image.device().machine().region_alloc("audiocrypt",size,1, ENDIANNESS_LITTLE);
596         memcpy(image.device().machine().region("audiocrypt")->base(),image.get_software_region("audiocrypt"),size);
597      }
598
599      // setup cartridge ROM area
600      image.device().machine().device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x000080,0x0fffff,"cart_rom");
601      memory_set_bankptr(image.device().machine(),"cart_rom",&image.device().machine().region("maincpu")->base()[0x80]);
602
603      // handle possible protection
604      install_protection(image);
605
606      return IMAGE_INIT_PASS;
607   }
608
609   if (pcbdev == NULL)
610      fatalerror("Error loading multicart: no pcb found.");
611
612   /* If we are here, we have a multicart. */
613   pcb = get_safe_pcb_token(pcbdev);
614   cart = get_safe_cartslot_token(&image.device());
615
616   /* try opening this as a multicart */
617   /* This line requires that cartslot_t be included in cartslot.h,
618    otherwise one cannot make use of multicart handling within such a
619    custom LOAD function. */
620   me = multicart_open(image.device().machine().options(), image.filename(), image.device().machine().system().name, MULTICART_FLAGS_LOAD_RESOURCES, &cart->mc);
621
622   /* Now that we have loaded the image files, let the PCB put them all
623    together. This means we put the images in a structure which allows
624    for a quick access by the memory handlers. Every PCB defines an
625    own assembly method. */
626    if (me != MCERR_NONE)
627      fatalerror("Error loading multicart: %s", multicart_error_text(me));
628
629   return pcb->assemble(pcbdev->machine(), image);
630}
631
632/*
633    This is called when the cartridge is unplugged (or the emulator is
634    stopped).
635*/
636static DEVICE_IMAGE_UNLOAD( aes_cartridge )
637{
638   device_t *pcbdev;
639
640   if (downcast<legacy_device_base *>(&image.device())->token() == NULL)
641   {
642      /* This means something went wrong during the pcb
643           identification (e.g. one of the cartridge files was not
644           found). We do not need to (and cannot) unload
645           the cartridge. */
646      return;
647   }
648   pcbdev = cartslot_get_pcb(image);
649
650   if (pcbdev != NULL)
651   {
652      aes_pcb_t *pcb = get_safe_pcb_token(pcbdev);
653      cartslot_t *cart = get_safe_cartslot_token(&image.device());
654
655      //  printf("unload\n");
656      if (cart->mc != NULL)
657      {
658         /* Remove pointers and de-big-endianize RAM contents. */
659         pcb->disassemble(pcbdev->machine(), image);
660
661         /* Close the multicart; all RAM resources will be
662               written to disk */
663         multicart_close(pcbdev->machine().options(), cart->mc);
664         cart->mc = NULL;
665      }
666//      else
667//          fatalerror("Lost pointer to multicart in cartridge. Report bug.");
668   }
669}
670
671/*****************************************************************************
672  The overall multi-cartridge slot system. It contains instances of
673  cartridges which contain PCB devices. The memory handlers delegate the calls
674  to the respective handlers of the cartridges.
675
676  Note that the term "multi-cartridge system" and "multicart" are not the same:
677  A "multicart" may contain multiple resources, organized on a PCB. The multi-
678  cart system may thus host multiple multicarts.
679
680  Actually, the name of the device should be changed (however, the device name
681  length is limited)
682******************************************************************************/
683/*
684    Instantiation of a multicart system for the Neo Geo AES.
685*/
686static DEVICE_START(aes_multicart)
687{
688   int i;
689//  printf("DEVICE_START(aes_multicart)\n");
690   aes_multicart_t *cartslots = get_safe_token(device);
691
692   /* Save this in the shortcut; we don't want to look for it each time
693       that we have a memory access. And currently we do not plan for
694       multiple multicart instances. */
695   cartslots->active_slot = 0;
696   cartslots->next_free_slot = 0;
697
698   for (i=0; i < AES_NUMBER_OF_CARTRIDGE_SLOTS; i++)
699   {
700      cartslots->cartridge[i].pcb = NULL;
701   }
702
703   cartslots->multi_slots = 0;
704
705   /* The cartslot system is initialized now. The cartridges themselves
706       need to check whether their parts are available. */
707}
708
709static DEVICE_STOP(aes_multicart)
710{
711//  printf("DEVICE_STOP(aes_multicart)\n");
712}
713
714static MACHINE_CONFIG_FRAGMENT(aes_multicart)
715   MCFG_CARTSLOT_ADD("cartridge1")
716   MCFG_CARTSLOT_EXTENSION_LIST("rpk,bin")
717   MCFG_CARTSLOT_PCBTYPE(0, "none", AES_CARTRIDGE_PCB_NONE)
718   MCFG_CARTSLOT_PCBTYPE(1, "standard", AES_CARTRIDGE_PCB_STD)
719
720   MCFG_CARTSLOT_START(aes_cartridge)
721   MCFG_CARTSLOT_LOAD(aes_cartridge)
722   MCFG_CARTSLOT_UNLOAD(aes_cartridge)
723   MCFG_CARTSLOT_INTERFACE("aes_cart")
724   MCFG_CARTSLOT_MANDATORY
725MACHINE_CONFIG_END
726
727
728DEVICE_GET_INFO(aes_multicart)
729{
730   switch (state)
731   {
732      /* --- the following bits of info are returned as pointers to data --- */
733      case DEVINFO_PTR_MACHINE_CONFIG:
734         info->machine_config = MACHINE_CONFIG_NAME(aes_multicart); break;
735
736      /* --- the following bits of info are returned as NULL-terminated strings --- */
737      case DEVINFO_STR_NAME:
738         strcpy(info->s, "AES Cartridge handler");
739         break;
740
741      case DEVINFO_INT_TOKEN_BYTES: /* private storage, automatically allocated */
742         info->i = sizeof(aes_multicart_t);
743         break;
744
745      case DEVINFO_STR_FAMILY:
746         strcpy(info->s, "Cartridge slot");
747         break;
748      case DEVINFO_STR_VERSION:
749         strcpy(info->s, "1.0");
750         break;
751      case DEVINFO_STR_SOURCE_FILE:
752         strcpy(info->s, __FILE__);
753         break;
754      /* --- the following bits of info are returned as pointers to functions --- */
755      case DEVINFO_FCT_START:
756         info->start = DEVICE_START_NAME(aes_multicart);
757         break;
758      case DEVINFO_FCT_STOP:
759         info->stop = DEVICE_STOP_NAME(aes_multicart);
760         break;
761      case DEVINFO_FCT_RESET:
762         /* Nothing */
763         break;
764   }
765}
766
767DEFINE_LEGACY_CART_SLOT_DEVICE(AES_MULTICART, aes_multicart);
768DEFINE_LEGACY_CART_SLOT_DEVICE(AES_CARTRIDGE_PCB_NONE, aes_cartridge_pcb_none);
769DEFINE_LEGACY_CART_SLOT_DEVICE(AES_CARTRIDGE_PCB_STD, aes_cartridge_pcb_std);
src/mess/devices/aescart.h
r11460r11461
1/*********************************************************************
2
3    aescart.h
4
5    AES cartridge management
6
7*********************************************************************/
8
9#ifndef __AESCART_H__
10#define __AESCART_H__
11
12#include "image.h"
13#include "imagedev/cartslot.h"
14
15DECLARE_LEGACY_CART_SLOT_DEVICE(AES_MULTICART, aes_multicart);
16DECLARE_LEGACY_CART_SLOT_DEVICE(AES_CARTRIDGE_PCB_NONE, aes_cartridge_pcb_none);
17DECLARE_LEGACY_CART_SLOT_DEVICE(AES_CARTRIDGE_PCB_STD, aes_cartridge_pcb_std);
18
19/* There's only 1 slot in an AES */
20#define AES_NUMBER_OF_CARTRIDGE_SLOTS 1
21
22/* Generic AES cartridge structure. */
23struct _aescartridge_t
24{
25   /* PCB device associated to this cartridge. If NULL, the slot is empty. */
26   device_t *pcb;
27};
28typedef struct _aescartridge_t aescartridge_t;
29
30#define MCFG_AES_CARTRIDGE_ADD(_tag) \
31   MCFG_DEVICE_ADD(_tag, AES_MULTICART, 0)
32
33#endif /* __AESCART_H__ */
src/mess/machine/psxcard.c
r11460r11461
1/*
2    psxcard.c - Sony PlayStation memory card device
3
4    by pSXAuthor
5    MESS conversion by R. Belmont
6*/
7
8#include "emu.h"
9#include "psxcard.h"
10#include "includes/psx.h"
11
12//
13//
14//
15
16//#define debug_card
17
18//
19//
20//
21
22const device_type PSXCARD = &device_creator<psxcard_device>;
23
24enum transfer_states
25{
26   state_illegal=0,
27   state_command,
28   state_cmdack_1,
29   state_cmdack_2,
30   state_addr_hi,
31   state_addr_lo,
32   state_read,
33   state_write,
34   state_writeack_1,
35   state_writeack_2,
36   state_writechk
37};
38
39psxcard_device::psxcard_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
40    : device_t(mconfig, PSXCARD, "Sony PSX Memory Card", tag, owner, clock)
41{
42}
43
44void psxcard_device::device_start()
45{
46   cache=new unsigned char [128*1024];
47
48   memset(cache, 0, 128*1024);
49
50   // save state registrations
51/*  save_item(NAME(pkt));
52    save_item(NAME(pkt_ptr));
53    save_item(NAME(pkt_sz));
54    save_item(NAME(pkt));
55    save_item(NAME(cache));
56    save_item(NAME(addr));
57    save_item(NAME(state));*/
58}
59
60void psxcard_device::device_reset()
61{
62   state = state_illegal;
63   addr = 0;
64}
65
66//
67//
68//
69
70bool psxcard_device::transfer(UINT8 to, UINT8 *from)
71{
72   bool ret=true;
73
74   switch (state)
75   {
76      case state_illegal:
77         if (to == 0x81)
78         {
79//              printf("CARD: begin\n");
80            state = state_command;
81            *from = 0x00;
82         }
83         else
84         {
85            ret = false;
86         }
87         break;
88
89      case state_command:
90         cmd=to;
91         *from=0x00;
92         state=state_cmdack_1;
93         break;
94
95      case state_cmdack_1:
96         //assert(to==0);
97         *from=0x5a;
98         state=state_cmdack_2;
99         break;
100
101      case state_cmdack_2:
102         //assert(to==0);
103         *from=0x5d;
104         state=state_addr_hi;
105         break;
106
107      case state_addr_hi:
108         addr=(to<<8);
109//          printf("addr_hi: %02x, addr = %x\n", to, addr);
110         *from=0;
111         state=state_addr_lo;
112         break;
113
114      case state_addr_lo:
115         addr|=(to&0xff);
116//          printf("addr_lo: %02x, addr = %x, cmd = %x\n", to, addr, cmd);
117         *from=(addr>>8);
118
119         switch (cmd)
120         {
121            case 'R':   // 0x52
122            {
123               pkt[0]=0x5c;
124               pkt[1]=0x5d;
125               pkt[2]=(addr>>8);
126               pkt[3]=(addr&0xff);
127               read_card(addr,&pkt[4]);
128               pkt[4+128]=checksum_data(&pkt[2],128+2);
129               pkt[5+128]=0x47;
130               pkt_sz=6+128;
131               pkt_ptr=0;
132               state=state_read;
133               break;
134            }
135            case 'W':   // 0x57
136            {
137               pkt[0]=addr>>8;
138               pkt[1]=addr&0xff;
139               pkt_sz=129+2;
140               pkt_ptr=2;
141               state=state_write;
142               break;
143            }
144            default:
145               state=state_illegal;
146               break;
147         }
148         break;
149
150      case state_read:
151         //assert(to==0);
152//          printf("state_read: pkt_ptr = %d, pkt_sz = %d\n", pkt_ptr, pkt_sz);
153         *from=pkt[pkt_ptr++];
154         if (pkt_ptr==pkt_sz)
155         {
156            #ifdef debug_card
157               printf("card: read finished\n");
158            #endif
159
160            state=state_illegal;
161            ret=false;
162         }
163         break;
164
165      case state_write:
166         *from=(pkt_ptr==0)?(addr&0xff):pkt[pkt_ptr-1];
167         pkt[pkt_ptr++]=to;
168         if (pkt_ptr==pkt_sz)
169            state=state_writeack_1;
170         break;
171
172      case state_writeack_1:
173         *from=0x5c;
174         state=state_writeack_2;
175         break;
176
177      case state_writeack_2:
178         *from=0x5d;
179         state=state_writechk;
180         break;
181
182      case state_writechk:
183      {
184         unsigned char chk=checksum_data(pkt,128+2);
185         if (chk==pkt[128+2])
186         {
187            #ifdef debug_card
188               printf("card: write ok\n");
189            #endif
190
191            write_card(addr,pkt+2);
192
193            *from='G';
194         } else
195         {
196            #ifdef debug_card
197               printf("card: write fail\n");
198            #endif
199
200            *from='N';
201         }
202         state=state_illegal;
203         ret=false;
204         break;
205      }
206
207      default: /*assert(0);*/ ret=false; break;
208   }
209
210   #ifdef debug_card
211//      printf("card: transfer to=%02x from=%02x ret=%c\n",to,*from,ret ? 'T' : 'F');
212   #endif
213
214   return ret;
215}
216
217void psxcard_device::read_card(const unsigned short addr, unsigned char *buf)
218{
219   #ifdef debug_card
220      printf("card: read block %d\n",addr);
221   #endif
222
223   if (addr<1024)
224   {
225      memcpy(buf,cache+(addr*128),128);
226   } else
227   {
228      memset(buf,0,128);
229   }
230}
231
232//
233//
234//
235
236void psxcard_device::write_card(const unsigned short addr, unsigned char *buf)
237{
238   #ifdef debug_card
239      printf("card: write block %d\n",addr);
240   #endif
241
242   if (addr<1024)
243   {
244      memcpy(cache+(addr*128),buf,128);
245   }
246}
247
248//
249//
250//
251
252unsigned char psxcard_device::checksum_data(const unsigned char *buf, const unsigned int sz)
253{
254   unsigned char chk=*buf++;
255   int left=sz;
256   while (--left) chk^=*buf++;
257   return chk;
258}
src/mess/machine/psxcard.h
r11460r11461
1#pragma once
2
3#ifndef _PSXCARD_
4#define _PSXCARD_
5
6#include "emu.h"
7
8#define MCFG_PSXCARD_ADD(_tag) \
9    MCFG_DEVICE_ADD(_tag, PSXCARD, 0)
10
11struct psxcard_interface
12{
13};
14
15class psxcard_device : public device_t,
16                       public psxcard_interface
17{
18public:
19    psxcard_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
20
21private:
22   unsigned char pkt[0x8b], pkt_ptr, pkt_sz, cmd, *cache;
23   unsigned short addr;
24   int state;
25
26   void read_card(const unsigned short addr, unsigned char *buf);
27   void write_card(const unsigned short addr, unsigned char *buf);
28   unsigned char checksum_data(const unsigned char *buf, const unsigned int sz);
29
30public:
31   virtual void device_start();
32   virtual void device_reset();
33
34   bool transfer(UINT8 to, UINT8 *from);
35   void mess_io(running_machine *machine, UINT8 n_data);
36private:
37};
38
39// device type definition
40extern const device_type PSXCARD;
41
42#endif
src/mess/machine/ataricrt.c
r11460r11461
1/***************************************************************************
2
3    MESS specific Atari init and Cartridge code for Atari 8 bit systems
4
5***************************************************************************/
6
7#include "emu.h"
8#include "emuopts.h"
9#include "includes/atari.h"
10#include "ataridev.h"
11#include "machine/ram.h"
12#include "hashfile.h"
13
14#define LEFT_CARTSLOT_MOUNTED  1
15#define RIGHT_CARTSLOT_MOUNTED 2
16
17/* PCB */
18enum
19{
20    A800_UNKNOWN = 0,
21   A800_4K, A800_8K, A800_12K, A800_16K,
22   A800_RIGHT_4K, A800_RIGHT_8K,
23   OSS_034M, OSS_M091, PHOENIX_8K, XEGS_32K,
24   BBSB, DIAMOND_64K, WILLIAMS_64K, EXPRESS_64,
25   SPARTADOS_X
26};
27
28static int a800_cart_loaded = 0;
29static int atari = 0;
30static int a800_cart_type = A800_UNKNOWN;
31
32/*************************************
33 *
34 *  Generic code
35 *
36 *************************************/
37
38
39// Currently, the drivers have fixed 40k RAM, however the function here is ready for different sizes too
40static void a800_setbank(running_machine &machine, int cart_mounted)
41{
42   offs_t ram_top;
43
44   // take care of 0x0000-0x7fff: RAM or NOP
45   ram_top = MIN(ram_get_size(machine.device(RAM_TAG)), 0x8000) - 1;
46   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0x0000, ram_top, "0000");
47   memory_set_bankptr(machine, "0000", ram_get_ptr(machine.device(RAM_TAG)));
48
49   // take care of 0x8000-0x9fff: A800 -> either right slot or RAM or NOP, others -> RAM or NOP
50   // is there anything in the right slot?
51   if (cart_mounted & RIGHT_CARTSLOT_MOUNTED)
52   {
53      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x8000, 0x9fff, "8000");
54      memory_set_bankptr(machine, "8000", machine.region("rslot")->base());
55      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0x8000, 0x9fff);
56   }
57   else if (a800_cart_type != BBSB)
58   {
59      ram_top = MIN(ram_get_size(machine.device(RAM_TAG)), 0xa000) - 1;
60      if (ram_top > 0x8000)
61      {
62         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0x8000, ram_top, "8000");
63         memory_set_bankptr(machine, "8000", ram_get_ptr(machine.device(RAM_TAG)) + 0x8000);
64      }
65   }
66
67   // take care of 0xa000-0xbfff: is there anything in the left slot?
68   if (cart_mounted & LEFT_CARTSLOT_MOUNTED)
69   {
70      // FIXME: this is an hack to keep XL working until we clean up its memory map as well!
71      if (atari == ATARI_800XL)
72      {
73         if (a800_cart_type == A800_16K)
74         {
75            machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x8000, 0x9fff, "8000");
76            memory_set_bankptr(machine, "8000", machine.region("lslot")->base());
77            machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0x8000, 0x9fff);
78
79            memcpy(machine.region("maincpu")->base() + 0x10000, machine.region("lslot")->base() + 0x2000, 0x2000);
80         }
81         else if (a800_cart_type == A800_8K)
82            memcpy(machine.region("maincpu")->base() + 0x10000, machine.region("lslot")->base(), 0x2000);
83         else
84            fatalerror("This type of cart is not supported yet in this driver. Please use a400 or a800.\n");
85      }
86      else if (a800_cart_type == A800_16K)
87      {
88         memory_set_bankptr(machine, "8000", machine.region("lslot")->base());
89         memory_set_bankptr(machine, "a000", machine.region("lslot")->base() + 0x2000);
90         machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0x8000, 0xbfff);
91      }
92      else if (a800_cart_type == BBSB)
93      {
94         // this requires separate banking in 0x8000 & 0x9000!
95         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x8000, 0x8fff, "8000");
96         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x9000, 0x9fff, "9000");
97         memory_set_bankptr(machine, "8000", machine.region("lslot")->base() + 0x0000);
98         memory_set_bankptr(machine, "9000", machine.region("lslot")->base() + 0x4000);
99         memory_set_bankptr(machine, "a000", machine.region("lslot")->base() + 0x8000);
100         machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xa000, 0xbfff);
101      }
102      else if (a800_cart_type == OSS_034M)
103      {
104         // this requires separate banking in 0xa000 & 0xb000!
105         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xa000, 0xafff, "a000");
106         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xb000, 0xbfff, "b000");
107         memory_set_bankptr(machine, "b000", machine.region("lslot")->base() + 0x3000);
108         machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xa000, 0xbfff);
109      }
110      else if (a800_cart_type == OSS_M091)
111      {
112         // this requires separate banking in 0xa000 & 0xb000!
113         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xa000, 0xafff, "a000");
114         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xb000, 0xbfff, "b000");
115         memory_set_bankptr(machine, "b000", machine.region("lslot")->base());
116         machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xa000, 0xbfff);
117      }
118      else if (a800_cart_type == XEGS_32K)
119      {
120         memory_set_bankptr(machine, "8000", machine.region("lslot")->base());
121         memory_set_bankptr(machine, "a000", machine.region("lslot")->base() + 0x6000);
122         machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0x8000, 0xbfff);
123      }
124      else
125      {
126         memory_set_bankptr(machine, "a000", machine.region("lslot")->base());
127         machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xa000, 0xbfff);
128      }
129   }
130}
131
132/* MESS specific parts that have to be started */
133static void ms_atari_machine_start(running_machine &machine, int type, int has_cart)
134{
135   /* set atari type (temporarily not used) */
136   atari = type;
137   a800_setbank(machine, a800_cart_loaded);
138}
139
140static void ms_atari800xl_machine_start(running_machine &machine, int type, int has_cart)
141{
142   /* set atari type (temporarily not used) */
143   atari = type;
144   a800_setbank(machine, a800_cart_loaded);
145}
146
147/*************************************
148 *
149 *  Atari 400
150 *
151 *************************************/
152
153MACHINE_START( a400 )
154{
155   atari_machine_start(machine);
156   ms_atari_machine_start(machine, ATARI_400, TRUE);
157}
158
159
160/*************************************
161 *
162 *  Atari 800
163 *
164 *************************************/
165
166MACHINE_START( a800 )
167{
168   atari_machine_start(machine);
169   ms_atari_machine_start(machine, ATARI_800, TRUE);
170}
171
172static WRITE8_HANDLER( x32_bank_w )
173{
174   //  printf("written %x\n", data);
175   int bank = data & 0x03;
176   memory_set_bankptr(space->machine(), "8000", space->machine().region("lslot")->base() + bank * 0x2000);
177}
178
179static WRITE8_HANDLER( w64_bank_w )
180{
181//  printf("write to %x\n", offset);
182
183   if (offset < 8)
184      memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base() + offset * 0x2000);
185   else
186      memory_set_bankptr(space->machine(), "a000", space->machine().region("maincpu")->base());
187   // FIXME: writes to 0x8-0xf should disable the cart
188}
189
190// this covers Express 64, Diamond 64 and SpartaDOS (same bankswitch, but at different addresses)
191static WRITE8_HANDLER( ex64_bank_w )
192{
193//  printf("write to %x\n", offset);
194
195   if (offset < 8)
196      memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base() + (7 - offset) * 0x2000);
197   else
198      memory_set_bankptr(space->machine(), "a000", space->machine().region("maincpu")->base());
199   // FIXME: writes to 0x8-0xf should disable the cart
200}
201
202static WRITE8_HANDLER( bbsb_bankl_w )
203{
204//  printf("write to %x\n", 0x8000 + offset);
205   if (offset >= 0xff6 && offset <= 0xff9)
206      memory_set_bankptr(space->machine(), "8000", space->machine().region("lslot")->base() + 0x0000 + (offset - 0xff6) * 0x1000);
207}
208
209static WRITE8_HANDLER( bbsb_bankh_w )
210{
211//  printf("write to %x\n", 0x9000 + offset);
212   if (offset >= 0xff6 && offset <= 0xff9)
213      memory_set_bankptr(space->machine(), "9000", space->machine().region("lslot")->base() + 0x4000 + (offset - 0xff6) * 0x1000);
214}
215
216static WRITE8_HANDLER( oss_034m_w )
217{
218   switch (offset & 0x0f)
219   {
220      case 0:
221      case 1:
222         memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base());
223         memory_set_bankptr(space->machine(), "b000", space->machine().region("lslot")->base() + 0x3000);
224         break;
225      case 2:
226      case 6:
227         // docs says this should put 0xff in the 0xa000 bank -> let's point to the end of the cart
228         memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base() + 0x4000);
229         memory_set_bankptr(space->machine(), "b000", space->machine().region("lslot")->base() + 0x3000);
230         break;
231      case 3:
232      case 7:
233         memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base() + 0x1000);
234         memory_set_bankptr(space->machine(), "b000", space->machine().region("lslot")->base() + 0x3000);
235         break;
236      case 4:
237      case 5:
238         memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base() + 0x2000);
239         memory_set_bankptr(space->machine(), "b000", space->machine().region("lslot")->base() + 0x3000);
240         break;
241      default:
242         memory_set_bankptr(space->machine(), "a000", space->machine().region("maincpu")->base() + 0xa000);
243         memory_set_bankptr(space->machine(), "b000", space->machine().region("maincpu")->base() + 0xb000);
244         break;
245   }
246}
247
248static WRITE8_HANDLER( oss_m091_w )
249{
250   switch (offset & 0x09)
251   {
252      case 0:
253         memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base() + 0x1000);
254         memory_set_bankptr(space->machine(), "b000", space->machine().region("lslot")->base());
255         break;
256      case 1:
257         memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base() + 0x3000);
258         memory_set_bankptr(space->machine(), "b000", space->machine().region("lslot")->base());
259         break;
260      case 8:
261         memory_set_bankptr(space->machine(), "a000", space->machine().region("maincpu")->base() + 0xa000);
262         memory_set_bankptr(space->machine(), "b000", space->machine().region("maincpu")->base() + 0xb000);
263         break;
264      case 9:
265         memory_set_bankptr(space->machine(), "a000", space->machine().region("lslot")->base() + 0x2000);
266         memory_set_bankptr(space->machine(), "b000", space->machine().region("lslot")->base());
267         break;
268   }
269}
270
271#if 0
272static int bbsb_bankl = 0;
273static int bbsb_bankh = 0;
274
275static WRITE8_HANDLER( bbsb_bankl_w )
276{
277   bbsb_bankl = offset; // 0,1,2,3
278}
279
280static WRITE8_HANDLER( bbsb_bankh_w )
281{
282   bbsb_bankh = offset; // 4,5,6,7
283}
284
285static READ8_HANDLER( bbsb_bankl_r )
286{
287   // return data from the selected bank (0,1,2,3)
288   UINT8 *mem = space->machine().region("lslot")->base();
289   return &mem[0x0000 + bbsb_bankl * 0x1000];
290}
291
292static READ8_HANDLER( bbsb_bankh_r )
293{
294   // return data from the selected bank (4,5,6,7)
295   UINT8 *mem = space->machine().region("lslot")->base();
296   return &mem[0x4000 + bbsb_bankh * 0x1000];
297}
298#endif
299
300typedef struct _a800_pcb  a800_pcb;
301struct _a800_pcb
302{
303   const char              *pcb_name;
304   int                     pcb_id;
305};
306
307// Here, we take the feature attribute from .xml (i.e. the PCB name) and we assign a unique ID to it
308// WARNING: most of these are still unsupported by the driver
309static const a800_pcb pcb_list[] =
310{
311   {"standard 4k", A800_8K},
312   {"standard 8k", A800_8K},
313   {"standard 12k", A800_16K},
314   {"standard 16k", A800_16K},
315   {"right slot 4k", A800_RIGHT_4K},
316   {"right slot 8k", A800_RIGHT_8K},
317
318   {"oss 034m", OSS_034M},
319   {"oss m091", OSS_M091},
320   {"phoenix 8k", PHOENIX_8K},
321   {"xegs 32k", XEGS_32K},
322   {"bbsb", BBSB},
323   {"diamond 64k", DIAMOND_64K},
324   {"williams 64k", WILLIAMS_64K},
325   {"express 64", EXPRESS_64},
326   {"spartados x", SPARTADOS_X},
327   {"N/A", A800_UNKNOWN}
328};
329
330static int a800_get_pcb_id(const char *pcb)
331{
332   int   i;
333
334   for (i = 0; i < ARRAY_LENGTH(pcb_list); i++)
335   {
336      if (!mame_stricmp(pcb_list[i].pcb_name, pcb))
337         return pcb_list[i].pcb_id;
338   }
339
340   return A800_UNKNOWN;
341}
342
343// currently this does nothing, but it will eventually install the memory handlers required by the mappers
344static void a800_setup_mappers(running_machine &machine, int type)
345{
346   switch (type)
347   {
348      case A800_4K:
349      case A800_RIGHT_4K:
350      case A800_12K:
351      case A800_8K:
352      case A800_16K:
353      case A800_RIGHT_8K:
354      case PHOENIX_8K:   // as normal 8k cart, but it can be disabled by writing to 0xd500-0xdfff
355         break;
356      case XEGS_32K:
357         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0xd500, 0xd5ff, FUNC(x32_bank_w));
358         break;
359      case OSS_034M:
360         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0xd500, 0xd5ff, FUNC(oss_034m_w));
361         break;
362      case OSS_M091:
363         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0xd500, 0xd5ff, FUNC(oss_m091_w));
364         break;
365      case BBSB:
366         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x8000, 0x8fff, FUNC(bbsb_bankl_w));
367         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x9000, 0x9fff, FUNC(bbsb_bankh_w));
368         break;
369      case WILLIAMS_64K:
370         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0xd500, 0xd50f, FUNC(w64_bank_w));
371         break;
372      case DIAMOND_64K:
373         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0xd5d0, 0xd5df, FUNC(ex64_bank_w));
374         break;
375      case EXPRESS_64:
376         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0xd570, 0xd57f, FUNC(ex64_bank_w));
377         break;
378      case SPARTADOS_X:
379         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0xd5e0, 0xd5ef, FUNC(ex64_bank_w));
380         break;
381      default:
382         break;
383   }
384}
385
386static int a800_get_type(device_image_interface &image)
387{
388   UINT8 header[16];
389   image.fread(header, 0x10);
390   int hdr_type, cart_type = A800_UNKNOWN;
391
392   // add check of CART format
393   if (strncmp((const char *)header, "CART", 4))
394      fatalerror("Invalid header detected!\n");
395
396   hdr_type = (header[4] << 24) + (header[5] << 16) +  (header[6] << 8) + (header[7] << 0);
397   switch (hdr_type)
398   {
399      case 1:
400         cart_type = A800_8K;
401         break;
402      case 2:
403         cart_type = A800_16K;
404         break;
405      case 3:
406         cart_type = OSS_034M;
407         break;
408      case 8:
409         cart_type = WILLIAMS_64K;
410         break;
411      case 9:
412         cart_type = DIAMOND_64K;
413         break;
414      case 10:
415         cart_type = EXPRESS_64;
416         break;
417      case 11:
418         cart_type = SPARTADOS_X;
419         break;
420      case 12:
421         cart_type = XEGS_32K;
422         break;
423      case 15:
424         cart_type = OSS_M091;
425         break;
426      case 18:
427         cart_type = BBSB;
428         break;
429      case 21:
430         cart_type = A800_RIGHT_8K;
431         break;
432      case 39:
433         cart_type = PHOENIX_8K;
434         break;
435      case 4:
436      case 6:
437      case 7:
438      case 16:
439      case 19:
440      case 20:
441         fatalerror("Cart type \"%d\" means this is an Atari 5200 cart.\n", hdr_type);
442         break;
443      default:
444         mame_printf_info("Cart type \"%d\" is currently unsupported.\n", hdr_type);
445         break;
446   }
447   return cart_type;
448}
449
450static int a800_check_cart_type(device_image_interface &image)
451{
452   const char   *pcb_name;
453   int type = A800_UNKNOWN;
454
455   if (image.software_entry() == NULL)
456   {
457      UINT32 size = image.length();
458
459      // check if there is an header, if so extract cart_type from it, otherwise
460      // try to guess the cart_type from the file size (notice that after the
461      // a800_get_type call, we point at the start of the data)
462      if ((size % 0x1000) == 0x10)
463         type = a800_get_type(image);
464      else if (size == 0x4000)
465         type = A800_16K;
466      else if (size == 0x2000)
467      {
468         if (strcmp(image.device().tag(),"cart2") == 0)
469            type = A800_RIGHT_8K;
470         else
471            type = A800_8K;
472      }
473   }
474   else
475   {
476      if ((pcb_name = image.get_feature("cart_type")) != NULL)
477         type = a800_get_pcb_id(pcb_name);
478
479      switch (type)
480      {
481         case A800_UNKNOWN:
482         case A800_4K:
483         case A800_RIGHT_4K:
484         case A800_12K:
485         case A800_8K:
486         case A800_16K:
487         case A800_RIGHT_8K:
488            break;
489         default:
490            mame_printf_info("Cart type \"%s\" currently unsupported.\n", pcb_name);
491            break;
492      }
493   }
494
495   if ((strcmp(image.device().tag(),"cart2") == 0) && (type != A800_RIGHT_8K))
496      fatalerror("You cannot load this image '%s' in the right slot", image.filename());
497
498   return type;
499}
500
501DEVICE_IMAGE_LOAD( a800_cart )
502{
503   UINT32 size, start = 0;
504
505   a800_cart_loaded = a800_cart_loaded & ~LEFT_CARTSLOT_MOUNTED;
506   a800_cart_type = a800_check_cart_type(image);
507
508   a800_setup_mappers(image.device().machine(), a800_cart_type);
509
510   if (image.software_entry() == NULL)
511   {
512      size = image.length();
513      // if there is an header, skip it
514      if ((size % 0x1000) == 0x10)
515      {
516         size -= 0x10;
517         start = 0x10;
518      }
519      image.fread(image.device().machine().region("lslot")->base(), size - start);
520   }
521   else
522   {
523      size = image.get_software_region_length("rom");
524      memcpy(image.device().machine().region("lslot")->base(), image.get_software_region("rom"), size);
525   }
526
527   a800_cart_loaded |= (size > 0x0000) ? 1 : 0;
528
529   logerror("%s loaded left cartridge '%s' size %dK\n", image.device().machine().system().name, image.filename(), size/1024);
530   return IMAGE_INIT_PASS;
531}
532
533DEVICE_IMAGE_LOAD( a800_cart_right )
534{
535   UINT32 size, start = 0;
536
537   a800_cart_loaded = a800_cart_loaded & ~RIGHT_CARTSLOT_MOUNTED;
538   a800_cart_type = a800_check_cart_type(image);
539
540   a800_setup_mappers(image.device().machine(), a800_cart_type);
541
542   if (image.software_entry() == NULL)
543   {
544      size = image.length();
545      // if there is an header, skip it
546      if ((size % 0x1000) == 0x10)
547      {
548         size -= 0x10;
549         start = 0x10;
550      }
551      image.fread(image.device().machine().region("rslot")->base(), size - start);
552   }
553   else
554   {
555      size = image.get_software_region_length("rom");
556      memcpy(image.device().machine().region("rslot")->base(), image.get_software_region("rom"), size);
557   }
558
559   a800_cart_loaded |= (size > 0x0000) ? 2 : 0;
560
561   logerror("%s loaded right cartridge '%s' size 8K\n", image.device().machine().system().name, image.filename());
562   return IMAGE_INIT_PASS;
563}
564
565DEVICE_IMAGE_UNLOAD( a800_cart )
566{
567   a800_cart_loaded = a800_cart_loaded & ~LEFT_CARTSLOT_MOUNTED;
568   a800_cart_type = A800_UNKNOWN;
569   a800_setbank(image.device().machine(), a800_cart_loaded);
570}
571
572DEVICE_IMAGE_UNLOAD( a800_cart_right )
573{
574   a800_cart_loaded = a800_cart_loaded & ~RIGHT_CARTSLOT_MOUNTED;
575   a800_cart_type = A800_UNKNOWN;
576   a800_setbank(image.device().machine(), a800_cart_loaded);
577}
578
579
580/*************************************
581 *
582 *  Atari 800XL
583 *
584 *************************************/
585
586MACHINE_START( a800xl )
587{
588   atari_machine_start(machine);
589   ms_atari800xl_machine_start(machine, ATARI_800XL, TRUE);
590}
591
592/*************************************
593 *
594 *  Atari 5200 console
595 *
596 *************************************/
597
598MACHINE_START( a5200 )
599{
600   atari_machine_start(machine);
601   ms_atari_machine_start(machine, ATARI_800XL, TRUE);
602}
603
604
605DEVICE_IMAGE_LOAD( a5200_cart )
606{
607   UINT8 *mem = image.device().machine().region("maincpu")->base();
608   UINT32 size;
609
610   if (image.software_entry() == NULL)
611   {
612      /* load an optional (dual) cartidge */
613      size = image.fread(&mem[0x4000], 0x8000);
614   }
615   else
616   {
617      size = image.get_software_region_length("rom");
618      memcpy(mem + 0x4000, image.get_software_region("rom"), size);
619   }
620
621   if (size<0x8000) memmove(mem+0x4000+0x8000-size, mem+0x4000, size);
622   // mirroring of smaller cartridges
623   if (size <= 0x1000) memcpy(mem+0xa000, mem+0xb000, 0x1000);
624   if (size <= 0x2000) memcpy(mem+0x8000, mem+0xa000, 0x2000);
625   if (size <= 0x4000)
626   {
627      const char *info = hashfile_extrainfo(image);
628      memcpy(&mem[0x4000], &mem[0x8000], 0x4000);
629      if (info && !strcmp(info, "A13MIRRORING"))
630      {
631         memcpy(&mem[0x8000], &mem[0xa000], 0x2000);
632         memcpy(&mem[0x6000], &mem[0x4000], 0x2000);
633      }
634   }
635   logerror("A5200 loaded cartridge '%s' size %dK\n", image.filename() , size/1024);
636   return IMAGE_INIT_PASS;
637}
638
639DEVICE_IMAGE_UNLOAD( a5200_cart )
640{
641   UINT8 *mem = image.device().machine().region("maincpu")->base();
642   /* zap the cartridge memory (again) */
643   memset(&mem[0x4000], 0x00, 0x8000);
644}
645
646/*************************************
647 *
648 *  Atari XEGS
649 *
650 *************************************/
651
652static UINT8 xegs_banks = 0;
653static UINT8 xegs_cart = 0;
654
655static WRITE8_HANDLER( xegs_bankswitch )
656{
657   UINT8 *cart = space->machine().region("user1")->base();
658   data &= xegs_banks - 1;
659   memory_set_bankptr(space->machine(), "bank0", cart + data * 0x2000);
660}
661
662MACHINE_START( xegs )
663{
664   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
665   UINT8 *cart = space->machine().region("user1")->base();
666   UINT8 *cpu  = space->machine().region("maincpu")->base();
667
668   atari_machine_start(machine);
669   space->install_legacy_write_handler(0xd500, 0xd5ff, FUNC(xegs_bankswitch));
670
671   if (xegs_cart)
672   {
673      memory_set_bankptr(machine, "bank0", cart);
674      memory_set_bankptr(machine, "bank1", cart + (xegs_banks - 1) * 0x2000);
675   }
676   else
677   {
678      // point to built-in Missile Command (this does not work well, though... FIXME!!)
679      memory_set_bankptr(machine, "bank0", cpu + 0x10000);
680      memory_set_bankptr(machine, "bank1", cpu + 0x10000);
681   }
682}
683
684DEVICE_IMAGE_LOAD( xegs_cart )
685{
686   UINT32 size;
687   UINT8 *ptr = image.device().machine().region("user1")->base();
688
689   if (image.software_entry() == NULL)
690   {
691      // skip the header
692      image.fseek(0x10, SEEK_SET);
693      size = image.length() - 0x10;
694      if (image.fread(ptr, size) != size)
695         return IMAGE_INIT_FAIL;
696   }
697   else
698   {
699      size = image.get_software_region_length("rom");
700      memcpy(ptr, image.get_software_region("rom"), size);
701   }
702
703   xegs_banks = size / 0x2000;
704   xegs_cart = 1;
705
706   return IMAGE_INIT_PASS;
707}
708
709DEVICE_IMAGE_UNLOAD( xegs_cart )
710{
711   xegs_cart = 0;
712   xegs_banks = 0;
713}
src/mess/machine/ataridev.h
r11460r11461
1/*
2    ataridev.h
3
4*/
5
6#ifndef _ATARIDEV_H
7#define _ATARIDEV_H
8
9#define ATARI_5200   0
10#define ATARI_400   1
11#define ATARI_800   2
12#define ATARI_600XL 3
13#define ATARI_800XL 4
14
15/*----------- defined in machine/ataricrt.c -----------*/
16
17MACHINE_START( a400 );
18MACHINE_START( a800 );
19MACHINE_START( a800xl );
20MACHINE_START( a5200 );
21MACHINE_START( xegs );
22
23DEVICE_IMAGE_LOAD( a800_cart );
24DEVICE_IMAGE_UNLOAD( a800_cart );
25
26DEVICE_IMAGE_LOAD( a800_cart_right );
27DEVICE_IMAGE_UNLOAD( a800_cart_right );
28
29DEVICE_IMAGE_LOAD( a5200_cart );
30DEVICE_IMAGE_UNLOAD( a5200_cart );
31
32DEVICE_IMAGE_LOAD( xegs_cart );
33DEVICE_IMAGE_UNLOAD( xegs_cart );
34
35
36/*----------- defined in machine/atarifdc.c -----------*/
37/***************************************************************************
38    MACROS
39***************************************************************************/
40
41DECLARE_LEGACY_DEVICE(ATARI_FDC, atari_fdc);
42
43#define MCFG_ATARI_FDC_ADD(_tag)   \
44   MCFG_DEVICE_ADD((_tag),  ATARI_FDC, 0)
45
46
47/***************************************************************************
48    FUNCTION PROTOTYPES
49***************************************************************************/
50READ8_DEVICE_HANDLER( atari_serin_r );
51WRITE8_DEVICE_HANDLER( atari_serout_w );
52WRITE_LINE_DEVICE_HANDLER( atarifdc_pia_cb2_w );
53
54#endif /* _ATARIDEV_H */
55
src/mess/machine/msx_slot.c
r11460r11461
1/*
2 * msx_slot.c : definitions of the different slots
3 *
4 * Copyright (C) 2004 Sean Young
5 *
6 * Missing:
7 * - Holy Qu'ran
8 *   like ascii8, with switch address 5000h/5400h/5800h/5c00h, not working.
9 * - Harry Fox
10 *   16kb banks, 6000h and 7000h switch address; isn't it really an ascii16?
11 * - Halnote
12 *   writes to page 0?
13 * - Playball
14 *   Unemulated D7756C, same as src/drivers/homerun.c
15 * - Some ascii8 w/ sram need 32kb sram?
16 * - MegaRAM
17 * - fmsx painter.rom
18 */
19
20#include "emu.h"
21#include "emuopts.h"
22#include "machine/i8255.h"
23#include "includes/msx_slot.h"
24#include "includes/msx.h"
25#include "machine/wd17xx.h"
26#include "sound/k051649.h"
27#include "sound/2413intf.h"
28#include "sound/dac.h"
29#include "sound/ay8910.h"
30
31static void msx_cpu_setbank (running_machine &machine, int page, UINT8 *mem)
32{
33   msx_state *state = machine.driver_data<msx_state>();
34   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
35   switch (page)
36   {
37   case 1:
38      memory_set_bankptr (machine,"bank1", mem);
39      break;
40   case 2:
41      memory_set_bankptr (machine,"bank2", mem);
42      break;
43   case 3:
44      memory_set_bankptr (machine,"bank3", mem);
45      break;
46   case 4:
47      memory_set_bankptr (machine,"bank4", mem);
48      memory_set_bankptr (machine,"bank5", mem + 0x1ff8);
49      space->install_read_bank(0x7ff8, 0x7fff, "bank5");
50      break;
51   case 5:
52      memory_set_bankptr (machine,"bank6", mem);
53      memory_set_bankptr (machine,"bank7", mem + 0x1800);
54      space->install_read_bank(0x9800, 0x9fff, "bank7");
55      break;
56   case 6:
57      memory_set_bankptr (machine,"bank8", mem);
58      memory_set_bankptr (machine,"bank9", mem + 0x1800);
59      space->install_read_bank(0xb800, 0xbfff, "bank9");
60      break;
61   case 7:
62      memory_set_bankptr (machine,"bank10", mem);
63      break;
64   case 8:
65      memory_set_bankptr (machine,"bank11", mem);
66      state->m_top_page = mem;
67      break;
68   }
69}
70
71MSX_SLOT_INIT(empty)
72{
73   state->m_type = SLOT_EMPTY;
74
75   return 0;
76}
77
78MSX_SLOT_RESET(empty)
79{
80   /* reset void */
81}
82
83MSX_SLOT_MAP(empty)
84{
85   msx_state *drvstate = machine.driver_data<msx_state>();
86   msx_cpu_setbank (machine, page * 2 + 1, drvstate->m_empty);
87   msx_cpu_setbank (machine, page * 2 + 2, drvstate->m_empty);
88}
89
90MSX_SLOT_INIT(rom)
91{
92   state->m_type = SLOT_ROM;
93   state->m_mem = mem;
94   state->m_size = size;
95   state->m_start_page = page;
96
97   return 0;
98}
99
100MSX_SLOT_RESET(rom)
101{
102   /* state-less */
103}
104
105MSX_SLOT_MAP(rom)
106{
107   UINT8 *mem = state->m_mem + (page - state->m_start_page) * 0x4000;
108
109   msx_cpu_setbank (machine, page * 2 + 1, mem);
110   msx_cpu_setbank (machine, page * 2 + 2, mem + 0x2000);
111}
112
113MSX_SLOT_INIT(ram)
114{
115   state->m_mem = auto_alloc_array(machine, UINT8, size);
116   memset (state->m_mem, 0, size);
117   state->m_type = SLOT_RAM;
118   state->m_start_page = page;
119   state->m_size = size;
120
121   return 0;
122}
123
124MSX_SLOT_MAP(ram)
125{
126   msx_state *drvstate = machine.driver_data<msx_state>();
127   UINT8 *mem = state->m_mem + (page - state->m_start_page) * 0x4000;
128
129   drvstate->m_ram_pages[page] = mem;
130   msx_cpu_setbank (machine, page * 2 + 1, mem);
131   msx_cpu_setbank (machine, page * 2 + 2, mem + 0x2000);
132}
133
134MSX_SLOT_RESET(ram)
135{
136}
137
138MSX_SLOT_INIT(rammm)
139{
140   int i, mask, nsize;
141#ifdef MONMSX
142   FILE *f;
143#endif
144
145   nsize = 0x10000; /* 64 kb */
146   mask = 3;
147   for (i=0; i<6; i++)
148   {
149      if (size == nsize)
150      {
151         break;
152      }
153      mask = (mask << 1) | 1;
154      nsize <<= 1;
155   }
156   if (i == 6)
157   {
158      logerror ("ram mapper: error: must be 64kb, 128kb, 256kb, 512kb, "
159              "1mb, 2mb or 4mb\n");
160      return 1;
161   }
162   state->m_mem = auto_alloc_array(machine, UINT8, size);
163   memset (state->m_mem, 0, size);
164
165#ifdef MONMSX
166   f = fopen ("/home/sean/msx/hack/monmsx.bin", "r");
167   if (f)
168   {
169      fseek (f, 6L, SEEK_SET);
170      fread (state->m_mem, 1, 6151 - 6, f);
171      fclose (f);
172   }
173#endif
174
175   state->m_type = SLOT_RAM_MM;
176   state->m_start_page = page;
177   state->m_size = size;
178   state->m_bank_mask = mask;
179
180   return 0;
181}
182
183MSX_SLOT_RESET(rammm)
184{
185   msx_state *drvstate = machine.driver_data<msx_state>();
186   int i;
187
188   for (i=0; i<4; i++)
189   {
190      drvstate->m_ram_mapper[i] = 3 - i;
191   }
192}
193
194MSX_SLOT_MAP(rammm)
195{
196   msx_state *drvstate = machine.driver_data<msx_state>();
197   UINT8 *mem = state->m_mem +
198         0x4000 * (drvstate->m_ram_mapper[page] & state->m_bank_mask);
199
200   drvstate->m_ram_pages[page] = mem;
201   msx_cpu_setbank (machine, page * 2 + 1, mem);
202   msx_cpu_setbank (machine, page * 2 + 2, mem + 0x2000);
203}
204
205MSX_SLOT_INIT(msxdos2)
206{
207   if (size != 0x10000)
208   {
209      logerror ("msxdos2: error: rom file must be 64kb\n");
210      return 1;
211   }
212   state->m_type = SLOT_MSXDOS2;
213   state->m_mem = mem;
214   state->m_size = size;
215
216   return 0;
217}
218
219MSX_SLOT_RESET(msxdos2)
220{
221   state->m_banks[0] = 0;
222}
223
224MSX_SLOT_MAP(msxdos2)
225{
226   msx_state *drvstate = machine.driver_data<msx_state>();
227   if (page != 1)
228   {
229      msx_cpu_setbank (machine, page * 2 + 1, drvstate->m_empty);
230      msx_cpu_setbank (machine, page * 2 + 2, drvstate->m_empty);
231   }
232   else
233   {
234      msx_cpu_setbank (machine, 3, state->m_mem + state->m_banks[0] * 0x4000);
235      msx_cpu_setbank (machine, 4, state->m_mem + state->m_banks[0] * 0x4000 + 0x2000);
236   }
237}
238
239MSX_SLOT_WRITE(msxdos2)
240{
241   if (addr == 0x6000)
242   {
243      state->m_banks[0] = val & 3;
244      slot_msxdos2_map (machine, state, 1);
245   }
246}
247
248MSX_SLOT_INIT(konami)
249{
250   int banks;
251
252   if (size > 0x200000)
253   {
254      logerror ("konami: warning: truncating to 2mb\n");
255      size = 0x200000;
256      return 1;
257   }
258   banks = size / 0x2000;
259   if (size != banks * 0x2000 || (~(banks - 1) % banks))
260   {
261      logerror ("konami: error: must be a 2 power of 8kb\n");
262      return 1;
263   }
264   state->m_type = SLOT_KONAMI;
265   state->m_mem = mem;
266   state->m_size = size;
267   state->m_bank_mask = banks - 1;
268
269   return 0;
270}
271
272MSX_SLOT_RESET(konami)
273{
274   int i;
275
276   for (i=0; i<4; i++) state->m_banks[i] = i;
277}
278
279MSX_SLOT_MAP(konami)
280{
281   switch (page)
282   {
283   case 0:
284      msx_cpu_setbank (machine, 1, state->m_mem);
285      msx_cpu_setbank (machine, 2, state->m_mem + state->m_banks[1] * 0x2000);
286      break;
287   case 1:
288      msx_cpu_setbank (machine, 3, state->m_mem);
289      msx_cpu_setbank (machine, 4, state->m_mem + state->m_banks[1] * 0x2000);
290      break;
291   case 2:
292      msx_cpu_setbank (machine, 5, state->m_mem + state->m_banks[2] * 0x2000);
293      msx_cpu_setbank (machine, 6, state->m_mem + state->m_banks[3] * 0x2000);
294      break;
295   case 3:
296      msx_cpu_setbank (machine, 7, state->m_mem + state->m_banks[2] * 0x2000);
297      msx_cpu_setbank (machine, 8, state->m_mem + state->m_banks[3] * 0x2000);
298   }
299}
300
301MSX_SLOT_WRITE(konami)
302{
303   msx_state *drvstate = machine.driver_data<msx_state>();
304   switch (addr)
305   {
306   case 0x6000:
307      state->m_banks[1] = val & state->m_bank_mask;
308      slot_konami_map (machine, state, 1);
309      if (drvstate->m_state[0] == state)
310      {
311         slot_konami_map (machine, state, 0);
312      }
313      break;
314   case 0x8000:
315      state->m_banks[2] = val & state->m_bank_mask;
316      slot_konami_map (machine, state, 2);
317      if (drvstate->m_state[3] == state)
318      {
319         slot_konami_map (machine, state, 3);
320      }
321      break;
322   case 0xa000:
323      state->m_banks[3] = val & state->m_bank_mask;
324      slot_konami_map (machine, state, 2);
325      if (drvstate->m_state[3] == state)
326      {
327         slot_konami_map (machine, state, 3);
328      }
329   }
330}
331
332MSX_SLOT_INIT(konami_scc)
333{
334   int banks;
335
336   if (size > 0x200000)
337   {
338      logerror ("konami_scc: warning: truncating to 2mb\n");
339      size = 0x200000;
340      return 1;
341   }
342   banks = size / 0x2000;
343   if (size != banks * 0x2000 || (~(banks - 1) % banks))
344   {
345      logerror ("konami_scc: error: must be a 2 power of 8kb\n");
346      return 1;
347   }
348
349   state->m_type = SLOT_KONAMI_SCC;
350   state->m_mem = mem;
351   state->m_size = size;
352   state->m_bank_mask = banks - 1;
353
354   return 0;
355}
356
357MSX_SLOT_RESET(konami_scc)
358{
359   int i;
360
361   for (i=0; i<4; i++) state->m_banks[i] = i;
362   state->m_cart.scc.active = 0;
363}
364
365static READ8_HANDLER (konami_scc_bank5)
366{
367   if (offset & 0x80)
368   {
369#if 0
370      if ((offset & 0xff) >= 0xe0)
371      {
372         /* write 0xff to deformation register */
373      }
374#endif
375      return 0xff;
376   }
377   else
378   {
379      return k051649_waveform_r (space->machine().device("k051649"), offset & 0x7f);
380   }
381}
382
383MSX_SLOT_MAP(konami_scc)
384{
385   switch (page)
386   {
387   case 0:
388      msx_cpu_setbank (machine, 1, state->m_mem + state->m_banks[2] * 0x2000);
389      msx_cpu_setbank (machine, 2, state->m_mem + state->m_banks[3] * 0x2000);
390      break;
391   case 1:
392      msx_cpu_setbank (machine, 3, state->m_mem + state->m_banks[0] * 0x2000);
393      msx_cpu_setbank (machine, 4, state->m_mem + state->m_banks[1] * 0x2000);
394      break;
395   case 2:
396      msx_cpu_setbank (machine, 5, state->m_mem + state->m_banks[2] * 0x2000);
397      msx_cpu_setbank (machine, 6, state->m_mem + state->m_banks[3] * 0x2000);
398      if (state->m_cart.scc.active ) {
399         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_read_handler(0x9800, 0x9fff, FUNC(konami_scc_bank5));
400      } else {
401         machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x9800, 0x9fff,"bank7");
402      }
403      break;
404   case 3:
405      msx_cpu_setbank (machine, 7, state->m_mem + state->m_banks[0] * 0x2000);
406      msx_cpu_setbank (machine, 8, state->m_mem + state->m_banks[1] * 0x2000);
407   }
408}
409
410MSX_SLOT_WRITE(konami_scc)
411{
412   msx_state *drvstate = machine.driver_data<msx_state>();
413   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
414   if (addr >= 0x5000 && addr < 0x5800)
415   {
416      state->m_banks[0] = val & state->m_bank_mask;
417      slot_konami_scc_map (machine, state, 1);
418      if (drvstate->m_state[3] == state)
419      {
420         slot_konami_scc_map (machine, state, 3);
421      }
422   }
423   else if (addr >= 0x7000 && addr < 0x7800)
424   {
425      state->m_banks[1] = val & state->m_bank_mask;
426      slot_konami_scc_map (machine, state, 1);
427      if (drvstate->m_state[3] == state)
428      {
429         slot_konami_scc_map (machine, state, 3);
430      }
431   }
432   else if (addr >= 0x9000 && addr < 0x9800)
433   {
434      state->m_banks[2] = val & state->m_bank_mask;
435      state->m_cart.scc.active = ((val & 0x3f) == 0x3f);
436      slot_konami_scc_map (machine, state, 2);
437      if (drvstate->m_state[0] == state)
438      {
439         slot_konami_scc_map (machine, state, 0);
440      }
441   }
442   else if (state->m_cart.scc.active && addr >= 0x9800 && addr < 0xa000)
443   {
444      device_t *k051649 = space->machine().device("k051649");
445      int offset = addr & 0xff;
446
447      if (offset < 0x80)
448      {
449         k051649_waveform_w (k051649, offset, val);
450      }
451      else if (offset < 0xa0)
452      {
453         offset &= 0xf;
454         if (offset < 0xa)
455         {
456            k051649_frequency_w (k051649, offset, val);
457         }
458         else if (offset < 0xf)
459         {
460            k051649_volume_w (k051649, offset - 0xa, val);
461         }
462         else
463         {
464            k051649_keyonoff_w (k051649, 0, val);
465         }
466      }
467#if 0
468      else if (offset >= 0xe0)
469      {
470         /* deformation register */
471      }
472#endif
473   }
474   else if (addr >= 0xb000 && addr < 0xb800)
475   {
476      state->m_banks[3] = val & state->m_bank_mask;
477      slot_konami_scc_map (machine, state, 2);
478      if (drvstate->m_state[0] == state)
479      {
480         slot_konami_scc_map (machine, state, 0);
481      }
482   }
483}
484
485MSX_SLOT_INIT(ascii8)
486{
487   int banks;
488
489   if (size > 0x200000)
490   {
491      logerror ("ascii8: warning: truncating to 2mb\n");
492      size = 0x200000;
493      return 1;
494   }
495   banks = size / 0x2000;
496   if (size != banks * 0x2000 || (~(banks - 1) % banks))
497   {
498      logerror ("ascii8: error: must be a 2 power of 8kb\n");
499      return 1;
500   }
501   state->m_type = SLOT_ASCII8;
502   state->m_mem = mem;
503   state->m_size = size;
504   state->m_bank_mask = banks - 1;
505
506   return 0;
507}
508
509MSX_SLOT_RESET(ascii8)
510{
511   int i;
512
513   for (i=0; i<4; i++) state->m_banks[i] = i;
514}
515
516MSX_SLOT_MAP(ascii8)
517{
518   msx_state *drvstate = machine.driver_data<msx_state>();
519   switch (page)
520   {
521   case 0:
522      msx_cpu_setbank (machine, 1, drvstate->m_empty);
523      msx_cpu_setbank (machine, 2, drvstate->m_empty);
524      break;
525   case 1:
526      msx_cpu_setbank (machine, 3, state->m_mem + state->m_banks[0] * 0x2000);
527      msx_cpu_setbank (machine, 4, state->m_mem + state->m_banks[1] * 0x2000);
528      break;
529   case 2:
530      msx_cpu_setbank (machine, 5, state->m_mem + state->m_banks[2] * 0x2000);
531      msx_cpu_setbank (machine, 6, state->m_mem + state->m_banks[3] * 0x2000);
532      break;
533   case 3:
534      msx_cpu_setbank (machine, 7, drvstate->m_empty);
535      msx_cpu_setbank (machine, 8, drvstate->m_empty);
536   }
537}
538
539MSX_SLOT_WRITE(ascii8)
540{
541   msx_state *drvstate = machine.driver_data<msx_state>();
542   int bank;
543
544   if (addr >= 0x6000 && addr < 0x8000)
545   {
546      bank = (addr / 0x800) & 3;
547
548      state->m_banks[bank] = val & state->m_bank_mask;
549      if (bank <= 1)
550      {
551         slot_ascii8_map (machine, state, 1);
552      }
553      else if (drvstate->m_state[2] == state)
554      {
555         slot_ascii8_map (machine, state, 2);
556      }
557   }
558}
559
560MSX_SLOT_INIT(ascii16)
561{
562   int banks;
563
564   if (size > 0x400000)
565   {
566      logerror ("ascii16: warning: truncating to 4mb\n");
567      size = 0x400000;
568   }
569   banks = size / 0x4000;
570   if (size != banks * 0x4000 || (~(banks - 1) % banks))
571   {
572      logerror ("ascii16: error: must be a 2 power of 16kb\n");
573      return 1;
574   }
575
576   state->m_type = SLOT_ASCII16;
577   state->m_mem = mem;
578   state->m_size = size;
579   state->m_bank_mask = banks - 1;
580
581   return 0;
582}
583
584MSX_SLOT_RESET(ascii16)
585{
586   int i;
587
588   for (i=0; i<2; i++) state->m_banks[i] = i;
589}
590
591MSX_SLOT_MAP(ascii16)
592{
593   msx_state *drvstate = machine.driver_data<msx_state>();
594   UINT8 *mem;
595
596   switch (page)
597   {
598   case 0:
599      msx_cpu_setbank (machine, 1, drvstate->m_empty);
600      msx_cpu_setbank (machine, 2, drvstate->m_empty);
601      break;
602   case 1:
603      mem = state->m_mem + state->m_banks[0] * 0x4000;
604      msx_cpu_setbank (machine, 3, mem);
605      msx_cpu_setbank (machine, 4, mem + 0x2000);
606      break;
607   case 2:
608      mem = state->m_mem + state->m_banks[1] * 0x4000;
609      msx_cpu_setbank (machine, 5, mem);
610      msx_cpu_setbank (machine, 6, mem + 0x2000);
611      break;
612   case 3:
613      msx_cpu_setbank (machine, 7, drvstate->m_empty);
614      msx_cpu_setbank (machine, 8, drvstate->m_empty);
615   }
616}
617
618MSX_SLOT_WRITE(ascii16)
619{
620   msx_state *drvstate = machine.driver_data<msx_state>();
621   if (addr >= 0x6000 && addr < 0x6800)
622   {
623      state->m_banks[0] = val & state->m_bank_mask;
624      slot_ascii16_map (machine, state, 1);
625   }
626   else if (addr >= 0x7000 && addr < 0x7800)
627   {
628      state->m_banks[1] = val & state->m_bank_mask;
629      if (drvstate->m_state[2] == state)
630      {
631         slot_ascii16_map (machine, state, 2);
632      }
633   }
634}
635
636MSX_SLOT_INIT(ascii8_sram)
637{
638   static const char sramfile[] = "ascii8";
639   int banks;
640
641   state->m_cart.sram.mem = auto_alloc_array(machine, UINT8, 0x2000);
642   if (size > 0x100000)
643   {
644      logerror ("ascii8_sram: warning: truncating to 1mb\n");
645      size = 0x100000;
646      return 1;
647   }
648   banks = size / 0x2000;
649   if (size != banks * 0x2000 || (~(banks - 1) % banks))
650   {
651      logerror ("ascii8_sram: error: must be a 2 power of 8kb\n");
652      return 1;
653   }
654   memset (state->m_cart.sram.mem, 0, 0x2000);
655   state->m_type = SLOT_ASCII8_SRAM;
656   state->m_mem = mem;
657   state->m_size = size;
658   state->m_bank_mask = banks - 1;
659   state->m_cart.sram.sram_mask = banks;
660   state->m_cart.sram.empty_mask = ~(banks | (banks - 1));
661   if (!state->m_sramfile)
662   {
663      state->m_sramfile = sramfile;
664   }
665
666   return 0;
667}
668
669MSX_SLOT_RESET(ascii8_sram)
670{
671   int i;
672
673   for (i=0; i<4; i++) state->m_banks[i] = i;
674}
675
676static UINT8 *ascii8_sram_bank_select (msx_state *drvstate, slot_state *state, int bankno)
677{
678   int bank = state->m_banks[bankno];
679
680   if (bank & state->m_cart.sram.empty_mask)
681   {
682      return drvstate->m_empty;
683   }
684   else if (bank & state->m_cart.sram.sram_mask)
685   {
686      return state->m_cart.sram.mem;
687   }
688   else
689   {
690      return state->m_mem + (bank & state->m_bank_mask) * 0x2000;
691   }
692}
693
694MSX_SLOT_MAP(ascii8_sram)
695{
696   msx_state *drvstate = machine.driver_data<msx_state>();
697   switch (page)
698   {
699   case 0:
700      msx_cpu_setbank (machine, 1, drvstate->m_empty);
701      msx_cpu_setbank (machine, 2, drvstate->m_empty);
702      break;
703   case 1:
704      msx_cpu_setbank (machine, 3, ascii8_sram_bank_select (drvstate, state, 0));
705      msx_cpu_setbank (machine, 4, ascii8_sram_bank_select (drvstate, state, 1));
706      break;
707   case 2:
708      msx_cpu_setbank (machine, 5, ascii8_sram_bank_select (drvstate, state, 2));
709      msx_cpu_setbank (machine, 6, ascii8_sram_bank_select (drvstate, state, 3));
710      break;
711   case 3:
712      msx_cpu_setbank (machine, 7, drvstate->m_empty);
713      msx_cpu_setbank (machine, 8, drvstate->m_empty);
714   }
715}
716
717MSX_SLOT_WRITE(ascii8_sram)
718{
719   msx_state *drvstate = machine.driver_data<msx_state>();
720   int bank;
721
722   if (addr >= 0x6000 && addr < 0x8000)
723   {
724      bank = (addr / 0x800) & 3;
725
726      state->m_banks[bank] = val;
727      if (bank <= 1)
728      {
729         slot_ascii8_sram_map (machine, state, 1);
730      }
731      else if (drvstate->m_state[2] == state)
732      {
733         slot_ascii8_sram_map (machine, state, 2);
734      }
735   }
736   if (addr >= 0x8000 && addr < 0xc000)
737   {
738      bank = addr < 0xa000 ? 2 : 3;
739      if (!(state->m_banks[bank] & state->m_cart.sram.empty_mask) &&
740           (state->m_banks[bank] & state->m_cart.sram.sram_mask))
741      {
742         state->m_cart.sram.mem[addr & 0x1fff] = val;
743      }
744   }
745}
746
747MSX_SLOT_LOADSRAM(ascii8_sram)
748{
749   if (!state->m_sramfile)
750   {
751      logerror ("ascii8_sram: error: no sram filename provided\n");
752      return 1;
753   }
754   emu_file f(machine.options().memcard_directory(), OPEN_FLAG_READ);
755   file_error filerr = f.open(state->m_sramfile);
756   if (filerr == FILERR_NONE)
757   {
758      if (f.read(state->m_cart.sram.mem, 0x2000) == 0x2000)
759      {
760         logerror ("ascii8_sram: info: sram loaded\n");
761         return 0;
762      }
763      memset (state->m_cart.sram.mem, 0, 0x2000);
764      logerror ("ascii8_sram: warning: could not read sram file\n");
765      return 1;
766   }
767
768   logerror ("ascii8_sram: warning: could not open sram file for reading\n");
769
770   return 1;
771}
772
773MSX_SLOT_SAVESRAM(ascii8_sram)
774{
775   if (!state->m_sramfile)
776   {
777      return 0;
778   }
779
780   emu_file f(machine.options().memcard_directory(), OPEN_FLAG_WRITE);
781   file_error filerr = f.open(state->m_sramfile);
782   if (filerr == FILERR_NONE)
783   {
784      f.write(state->m_cart.sram.mem, 0x2000);
785      logerror ("ascii8_sram: info: sram saved\n");
786
787      return 0;
788   }
789
790   logerror ("ascii8_sram: warning: could not open sram file for saving\n");
791
792   return 1;
793}
794
795MSX_SLOT_INIT(ascii16_sram)
796{
797   static const char sramfile[] = "ascii16";
798   int banks;
799
800   state->m_cart.sram.mem = auto_alloc_array(machine, UINT8, 0x4000);
801
802   if (size > 0x200000)
803   {
804      logerror ("ascii16_sram: warning: truncating to 2mb\n");
805      size = 0x200000;
806   }
807   banks = size / 0x4000;
808   if (size != banks * 0x4000 || (~(banks - 1) % banks))
809   {
810      logerror ("ascii16_sram: error: must be a 2 power of 16kb\n");
811      return 1;
812   }
813
814   memset (state->m_cart.sram.mem, 0, 0x4000);
815   state->m_type = SLOT_ASCII16_SRAM;
816   state->m_mem = mem;
817   state->m_size = size;
818   state->m_bank_mask = banks - 1;
819   state->m_cart.sram.sram_mask = banks;
820   state->m_cart.sram.empty_mask = ~(banks | (banks - 1));
821   if (!state->m_sramfile)
822   {
823      state->m_sramfile = sramfile;
824   }
825
826   return 0;
827}
828
829MSX_SLOT_RESET(ascii16_sram)
830{
831   int i;
832
833   for (i=0; i<2; i++) state->m_banks[i] = i;
834}
835
836static UINT8 *ascii16_sram_bank_select (msx_state *drvstate, slot_state *state, int bankno)
837{
838   int bank = state->m_banks[bankno];
839
840   if (bank & state->m_cart.sram.empty_mask)
841   {
842      return drvstate->m_empty;
843   }
844   else if (bank & state->m_cart.sram.sram_mask)
845   {
846      return state->m_cart.sram.mem;
847   }
848   else
849   {
850      return state->m_mem + (bank & state->m_bank_mask) * 0x4000;
851   }
852}
853
854MSX_SLOT_MAP(ascii16_sram)
855{
856   msx_state *drvstate = machine.driver_data<msx_state>();
857   UINT8 *mem;
858
859   switch (page)
860   {
861   case 0:
862      msx_cpu_setbank (machine, 1, drvstate->m_empty);
863      msx_cpu_setbank (machine, 2, drvstate->m_empty);
864      break;
865   case 1:
866      mem = ascii16_sram_bank_select (drvstate, state, 0);
867      msx_cpu_setbank (machine, 3, mem);
868      msx_cpu_setbank (machine, 4, mem + 0x2000);
869      break;
870   case 2:
871      mem = ascii16_sram_bank_select (drvstate, state, 1);
872      msx_cpu_setbank (machine, 5, mem);
873      msx_cpu_setbank (machine, 6, mem + 0x2000);
874      break;
875   case 3:
876      msx_cpu_setbank (machine, 7, drvstate->m_empty);
877      msx_cpu_setbank (machine, 8, drvstate->m_empty);
878   }
879}
880
881MSX_SLOT_WRITE(ascii16_sram)
882{
883   msx_state *drvstate = machine.driver_data<msx_state>();
884   if (addr >= 0x6000 && addr < 0x6800)
885   {
886      state->m_banks[0] = val;
887      slot_ascii16_sram_map (machine, state, 1);
888   }
889   else if (addr >= 0x7000 && addr < 0x7800)
890   {
891      state->m_banks[1] = val;
892      if (drvstate->m_state[2] == state)
893      {
894         slot_ascii16_sram_map (machine, state, 2);
895      }
896   }
897   else if (addr >= 0x8000 && addr < 0xc000)
898   {
899      if (!(state->m_banks[1] & state->m_cart.sram.empty_mask) &&
900           (state->m_banks[1] & state->m_cart.sram.sram_mask))
901      {
902         int offset, i;
903
904         offset = addr & 0x07ff;
905         for (i=0; i<8; i++)
906         {
907            state->m_cart.sram.mem[offset] = val;
908            offset += 0x0800;
909         }
910      }
911   }
912}
913
914MSX_SLOT_LOADSRAM(ascii16_sram)
915{
916   UINT8 *p;
917
918   if (!state->m_sramfile)
919   {
920      logerror ("ascii16_sram: error: no sram filename provided\n");
921      return 1;
922   }
923
924   emu_file f(machine.options().memcard_directory(), OPEN_FLAG_READ);
925   file_error filerr = f.open(state->m_sramfile);
926   if (filerr == FILERR_NONE)
927   {
928      p = state->m_cart.sram.mem;
929
930      if (f.read(state->m_cart.sram.mem, 0x200) == 0x200)
931      {
932         int /*offset,*/ i;
933         //offset = 0;
934         for (i=0; i<7; i++)
935         {
936            memcpy (p + 0x800, p, 0x800);
937            p += 0x800;
938         }
939
940         logerror ("ascii16_sram: info: sram loaded\n");
941         return 0;
942      }
943      memset (state->m_cart.sram.mem, 0, 0x4000);
944      logerror ("ascii16_sram: warning: could not read sram file\n");
945      return 1;
946   }
947
948   logerror ("ascii16_sram: warning: could not open sram file for reading\n");
949
950   return 1;
951}
952
953MSX_SLOT_SAVESRAM(ascii16_sram)
954{
955   if (!state->m_sramfile)
956   {
957      return 0;
958   }
959   emu_file f(machine.options().memcard_directory(), OPEN_FLAG_WRITE);
960   file_error filerr = f.open(state->m_sramfile);
961   if (filerr == FILERR_NONE)
962   {
963      f.write(state->m_cart.sram.mem, 0x200);
964      logerror ("ascii16_sram: info: sram saved\n");
965
966      return 0;
967   }
968
969   logerror ("ascii16_sram: warning: could not open sram file for saving\n");
970
971   return 1;
972}
973
974MSX_SLOT_INIT(rtype)
975{
976   if (!(size == 0x60000 || size == 0x80000))
977   {
978      logerror ("rtype: error: rom file should be exactly 384kb\n");
979      return 1;
980   }
981
982   state->m_type = SLOT_RTYPE;
983   state->m_mem = mem;
984   state->m_size = size;
985
986   return 0;
987}
988
989MSX_SLOT_RESET(rtype)
990{
991   state->m_banks[0] = 15;
992}
993
994MSX_SLOT_MAP(rtype)
995{
996   msx_state *drvstate = machine.driver_data<msx_state>();
997   UINT8 *mem;
998
999   switch (page)
1000   {
1001   case 0:
1002      msx_cpu_setbank (machine, 1, drvstate->m_empty);
1003      msx_cpu_setbank (machine, 2, drvstate->m_empty);
1004      break;
1005   case 1:
1006      mem = state->m_mem + 15 * 0x4000;
1007      msx_cpu_setbank (machine, 3, mem);
1008      msx_cpu_setbank (machine, 4, mem + 0x2000);
1009      break;
1010   case 2:
1011      mem = state->m_mem + state->m_banks[0] * 0x4000;
1012      msx_cpu_setbank (machine, 5, mem);
1013      msx_cpu_setbank (machine, 6, mem + 0x2000);
1014      break;
1015   case 3:
1016      msx_cpu_setbank (machine, 7, drvstate->m_empty);
1017      msx_cpu_setbank (machine, 8, drvstate->m_empty);
1018   }
1019}
1020
1021MSX_SLOT_WRITE(rtype)
1022{
1023   msx_state *drvstate = machine.driver_data<msx_state>();
1024   if (addr >= 0x7000 && addr < 0x8000)
1025   {
1026      int data ;
1027
1028      if (val & 0x10)
1029      {
1030         data = 0x10 | (val & 7);
1031      }
1032      else
1033      {
1034         data = val & 0x0f;
1035      }
1036      state->m_banks[0] = data;
1037      if (drvstate->m_state[2] == state)
1038      {
1039         slot_rtype_map (machine, state, 2);
1040      }
1041   }
1042}
1043
1044MSX_SLOT_INIT(gmaster2)
1045{
1046   UINT8 *p;
1047   static const char sramfile[] = "GameMaster2";
1048
1049   if (size != 0x20000)
1050   {
1051      logerror ("gmaster2: error: rom file should be 128kb\n");
1052      return 1;
1053   }
1054   state->m_type = SLOT_GAMEMASTER2;
1055   state->m_size = size;
1056   state->m_mem = mem;
1057
1058   p = auto_alloc_array(machine, UINT8, 0x4000);
1059   memset (p, 0, 0x4000);
1060   state->m_cart.sram.mem = p;
1061   if (!state->m_sramfile)
1062   {
1063      state->m_sramfile = sramfile;
1064   }
1065
1066   return 0;
1067}
1068
1069MSX_SLOT_RESET(gmaster2)
1070{
1071   int i;
1072
1073   for (i=0; i<4; i++)
1074   {
1075      state->m_banks[i] = i;
1076   }
1077}
1078
1079MSX_SLOT_MAP(gmaster2)
1080{
1081   switch (page)
1082   {
1083   case 0:
1084   case 1:
1085      msx_cpu_setbank (machine, 1 + page * 2, state->m_mem); /* bank 0 is hardwired */
1086      if (state->m_banks[1] > 15)
1087      {
1088         msx_cpu_setbank (machine, 2 + page * 2, state->m_cart.sram.mem +
1089               (state->m_banks[1] - 16) * 0x2000);
1090      }
1091      else
1092      {
1093         msx_cpu_setbank (machine, 2 + page * 2, state->m_mem + state->m_banks[1] * 0x2000);
1094      }
1095      break;
1096   case 2:
1097   case 3:
1098      if (state->m_banks[2] > 15)
1099      {
1100         msx_cpu_setbank (machine, 5 + page * 2, state->m_cart.sram.mem +
1101               (state->m_banks[2] - 16) * 0x2000);
1102      }
1103      else
1104      {
1105         msx_cpu_setbank (machine, 5 + page * 2, state->m_mem + state->m_banks[2] * 0x2000);
1106      }
1107      if (state->m_banks[3] > 15)
1108      {
1109         msx_cpu_setbank (machine, 6 + page * 2, state->m_cart.sram.mem +
1110               (state->m_banks[3] - 16) * 0x2000);
1111      }
1112      else
1113      {
1114         msx_cpu_setbank (machine, 6 + page * 2, state->m_mem + state->m_banks[3] * 0x2000);
1115      }
1116      break;
1117   }
1118}
1119
1120MSX_SLOT_WRITE(gmaster2)
1121{
1122   msx_state *drvstate = machine.driver_data<msx_state>();
1123   if (addr >= 0x6000 && addr < 0x7000)
1124   {
1125      if (val & 0x10)
1126      {
1127         val = val & 0x20 ? 17 : 16;
1128      }
1129      else
1130      {
1131         val = val & 15;
1132      }
1133      state->m_banks[1] = val;
1134      slot_gmaster2_map (machine, state, 1);
1135      if (drvstate->m_state[0] == state)
1136      {
1137         slot_gmaster2_map (machine, state, 0);
1138      }
1139   }
1140   else if (addr >= 0x8000 && addr < 0x9000)
1141   {
1142      if (val & 0x10)
1143      {
1144         val = val & 0x20 ? 17 : 16;
1145      }
1146      else
1147      {
1148         val = val & 15;
1149      }
1150      state->m_banks[2] = val;
1151      slot_gmaster2_map (machine, state, 2);
1152      if (drvstate->m_state[3] == state)
1153      {
1154         slot_gmaster2_map (machine, state, 3);
1155      }
1156   }
1157   else if (addr >= 0xa000 && addr < 0xb000)
1158   {
1159      if (val & 0x10)
1160      {
1161         val = val & 0x20 ? 17 : 16;
1162      }
1163      else
1164      {
1165         val = val & 15;
1166      }
1167      state->m_banks[3] = val;
1168      slot_gmaster2_map (machine, state, 2);
1169      if (drvstate->m_state[3] == state)
1170      {
1171         slot_gmaster2_map (machine, state, 3);
1172      }
1173   }
1174   else if (addr >= 0xb000 && addr < 0xc000)
1175   {
1176      addr &= 0x0fff;
1177      switch (state->m_banks[3])
1178      {
1179      case 16:
1180         state->m_cart.sram.mem[addr] = val;
1181         state->m_cart.sram.mem[addr + 0x1000] = val;
1182         break;
1183      case 17:
1184         state->m_cart.sram.mem[addr + 0x2000] = val;
1185         state->m_cart.sram.mem[addr + 0x3000] = val;
1186         break;
1187      }
1188   }
1189}
1190
1191MSX_SLOT_LOADSRAM(gmaster2)
1192{
1193   UINT8 *p;
1194
1195   p = state->m_cart.sram.mem;
1196
1197   emu_file f(machine.options().memcard_directory(), OPEN_FLAG_READ);
1198   file_error filerr = f.open(state->m_sramfile);
1199   if (filerr == FILERR_NONE)
1200   {
1201      if (f.read(p + 0x1000, 0x2000) == 0x2000)
1202      {
1203         memcpy (p, p + 0x1000, 0x1000);
1204         memcpy (p + 0x3000, p + 0x2000, 0x1000);
1205         logerror ("gmaster2: info: sram loaded\n");
1206         return 0;
1207      }
1208      memset (p, 0, 0x4000);
1209      logerror ("gmaster2: warning: could not read sram file\n");
1210      return 1;
1211   }
1212
1213   logerror ("gmaster2: warning: could not open sram file for reading\n");
1214
1215   return 1;
1216}
1217
1218MSX_SLOT_SAVESRAM(gmaster2)
1219{
1220   emu_file f(machine.options().memcard_directory(), OPEN_FLAG_WRITE);
1221   file_error filerr = f.open(state->m_sramfile);
1222   if (filerr == FILERR_NONE)
1223   {
1224      f.write(state->m_cart.sram.mem + 0x1000, 0x2000);
1225      logerror ("gmaster2: info: sram saved\n");
1226
1227      return 0;
1228   }
1229
1230   logerror ("gmaster2: warning: could not open sram file for saving\n");
1231
1232   return 1;
1233}
1234
1235MSX_SLOT_INIT(diskrom)
1236{
1237   if (size != 0x4000)
1238   {
1239      logerror ("diskrom: error: the diskrom should be 16kb\n");
1240      return 1;
1241   }
1242
1243   state->m_type = SLOT_DISK_ROM;
1244   state->m_mem = mem;
1245   state->m_size = size;
1246
1247   return 0;
1248}
1249
1250MSX_SLOT_RESET(diskrom)
1251{
1252   device_t *fdc = machine.device("wd179x");
1253   wd17xx_reset(fdc);
1254}
1255
1256static READ8_HANDLER (msx_diskrom_page1_r)
1257{
1258   msx_state *state = space->machine().driver_data<msx_state>();
1259   device_t *fdc = space->machine().device("wd179x");
1260   switch (offset)
1261   {
1262   case 0: return wd17xx_status_r (fdc, 0);
1263   case 1: return wd17xx_track_r (fdc, 0);
1264   case 2: return wd17xx_sector_r (fdc, 0);
1265   case 3: return wd17xx_data_r (fdc, 0);
1266   case 7: return state->m_dsk_stat;
1267   default:
1268      return state->m_state[1]->m_mem[offset + 0x3ff8];
1269   }
1270}
1271
1272static READ8_HANDLER (msx_diskrom_page2_r)
1273{
1274   msx_state *state = space->machine().driver_data<msx_state>();
1275   device_t *fdc = space->machine().device("wd179x");
1276   if (offset >= 0x7f8)
1277   {
1278      switch (offset)
1279      {
1280      case 0x7f8:
1281         return wd17xx_status_r (fdc, 0);
1282      case 0x7f9:
1283         return wd17xx_track_r (fdc, 0);
1284      case 0x7fa:
1285         return wd17xx_sector_r (fdc, 0);
1286      case 0x7fb:
1287         return wd17xx_data_r (fdc, 0);
1288      case 0x7ff:
1289         return state->m_dsk_stat;
1290      default:
1291         return state->m_state[2]->m_mem[offset + 0x3800];
1292      }
1293   }
1294   else
1295   {
1296      return 0xff;
1297   }
1298}
1299
1300MSX_SLOT_MAP(diskrom)
1301{
1302   msx_state *drvstate = machine.driver_data<msx_state>();
1303   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
1304   switch (page)
1305   {
1306   case 0:
1307      msx_cpu_setbank (machine, 1, drvstate->m_empty);
1308      msx_cpu_setbank (machine, 2, drvstate->m_empty);
1309      break;
1310   case 1:
1311      msx_cpu_setbank (machine, 3, state->m_mem);
1312      msx_cpu_setbank (machine, 4, state->m_mem + 0x2000);
1313      space->install_legacy_read_handler(0x7ff8, 0x7fff, FUNC(msx_diskrom_page1_r));
1314      break;
1315   case 2:
1316      msx_cpu_setbank (machine, 5, drvstate->m_empty);
1317      msx_cpu_setbank (machine, 6, drvstate->m_empty);
1318      space->install_legacy_read_handler(0xb800, 0xbfff, FUNC(msx_diskrom_page2_r));
1319      break;
1320   case 3:
1321      msx_cpu_setbank (machine, 7, drvstate->m_empty);
1322      msx_cpu_setbank (machine, 8, drvstate->m_empty);
1323      break;
1324   }
1325}
1326
1327MSX_SLOT_WRITE(diskrom)
1328{
1329   device_t *fdc = machine.device("wd179x");
1330   if (addr >= 0xa000 && addr < 0xc000)
1331   {
1332      addr -= 0x4000;
1333   }
1334   switch (addr)
1335   {
1336   case 0x7ff8:
1337      wd17xx_command_w (fdc, 0, val);
1338      break;
1339   case 0x7ff9:
1340      wd17xx_track_w (fdc, 0, val);
1341      break;
1342   case 0x7ffa:
1343      wd17xx_sector_w (fdc, 0, val);
1344      break;
1345   case 0x7ffb:
1346      wd17xx_data_w (fdc, 0, val);
1347      break;
1348   case 0x7ffc:
1349      wd17xx_set_side (fdc,val & 1);
1350      state->m_mem[0x3ffc] = val | 0xfe;
1351      break;
1352   case 0x7ffd:
1353      wd17xx_set_drive (fdc,val & 1);
1354      if ((state->m_mem[0x3ffd] ^ val) & 0x40)
1355      {
1356         set_led_status (machine, 0, !(val & 0x40));
1357      }
1358      state->m_mem[0x3ffd] = (val | 0x7c) & ~0x04;
1359      break;
1360   }
1361}
1362
1363MSX_SLOT_INIT(diskrom2)
1364{
1365   if (size != 0x4000)
1366   {
1367      logerror ("diskrom2: error: the diskrom2 should be 16kb\n");
1368      return 1;
1369   }
1370
1371   state->m_type = SLOT_DISK_ROM2;
1372   state->m_mem = mem;
1373   state->m_size = size;
1374
1375   return 0;
1376}
1377
1378MSX_SLOT_RESET(diskrom2)
1379{
1380   device_t *fdc = machine.device("wd179x");
1381   wd17xx_reset (fdc);
1382}
1383
1384static READ8_HANDLER (msx_diskrom2_page1_r)
1385{
1386   msx_state *state = space->machine().driver_data<msx_state>();
1387   device_t *fdc = space->machine().device("wd179x");
1388   switch (offset)
1389   {
1390   case 0: return wd17xx_status_r(fdc, 0);
1391   case 1: return wd17xx_track_r(fdc, 0);
1392   case 2: return wd17xx_sector_r(fdc, 0);
1393   case 3: return wd17xx_data_r(fdc, 0);
1394   case 4: return state->m_dsk_stat;
1395   default:
1396      return state->m_state[1]->m_mem[offset + 0x3ff8];
1397   }
1398}
1399
1400static  READ8_HANDLER (msx_diskrom2_page2_r)
1401{
1402   msx_state *state = space->machine().driver_data<msx_state>();
1403   device_t *fdc = space->machine().device("wd179x");
1404   if (offset >= 0x7b8)
1405   {
1406      switch (offset)
1407      {
1408      case 0x7b8:
1409         return wd17xx_status_r (fdc, 0);
1410      case 0x7b9:
1411         return wd17xx_track_r (fdc, 0);
1412      case 0x7ba:
1413         return wd17xx_sector_r (fdc, 0);
1414      case 0x7bb:
1415         return wd17xx_data_r (fdc, 0);
1416      case 0x7bc:
1417         return state->m_dsk_stat;
1418      default:
1419         return state->m_state[2]->m_mem[offset + 0x3800];
1420      }
1421   }
1422   else
1423   {
1424      return 0xff;
1425   }
1426}
1427
1428MSX_SLOT_MAP(diskrom2)
1429{
1430   msx_state *drvstate = machine.driver_data<msx_state>();
1431   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
1432   switch (page)
1433   {
1434   case 0:
1435      msx_cpu_setbank (machine, 1, drvstate->m_empty);
1436      msx_cpu_setbank (machine, 2, drvstate->m_empty);
1437      break;
1438   case 1:
1439      msx_cpu_setbank (machine, 3, state->m_mem);
1440      msx_cpu_setbank (machine, 4, state->m_mem + 0x2000);
1441      space->install_legacy_read_handler(0x7fb8, 0x7fbc, FUNC(msx_diskrom2_page1_r));
1442      break;
1443   case 2:
1444      msx_cpu_setbank (machine, 5, drvstate->m_empty);
1445      msx_cpu_setbank (machine, 6, drvstate->m_empty);
1446      space->install_legacy_read_handler(0xb800, 0xbfbc, FUNC(msx_diskrom2_page2_r));
1447      break;
1448   case 3:
1449      msx_cpu_setbank (machine, 7, drvstate->m_empty);
1450      msx_cpu_setbank (machine, 8, drvstate->m_empty);
1451   }
1452}
1453
1454MSX_SLOT_WRITE(diskrom2)
1455{
1456   device_t *fdc = machine.device("wd179x");
1457   if (addr >= 0xa000 && addr < 0xc000)
1458   {
1459      addr -= 0x4000;
1460   }
1461   switch (addr)
1462   {
1463   case 0x7fb8:
1464      wd17xx_command_w (fdc, 0, val);
1465      break;
1466   case 0x7fb9:
1467      wd17xx_track_w (fdc, 0, val);
1468      break;
1469   case 0x7fba:
1470      wd17xx_sector_w (fdc, 0, val);
1471      break;
1472   case 0x7fbb:
1473      wd17xx_data_w (fdc, 0, val);
1474      break;
1475   case 0x7fbc:
1476      wd17xx_set_side (fdc,val & 1);
1477      state->m_mem[0x3fbc] = val | 0xfe;
1478      wd17xx_set_drive (fdc,val & 1);
1479      if ((state->m_mem[0x3fbc] ^ val) & 0x40)
1480      {
1481         set_led_status (machine, 0, !(val & 0x40));
1482      }
1483      state->m_mem[0x3fbc] = (val | 0x7c) & ~0x04;
1484      break;
1485   }
1486}
1487
1488MSX_SLOT_INIT(synthesizer)
1489{
1490   if (size != 0x8000)
1491   {
1492      logerror ("synthesizer: error: rom file must be 32kb\n");
1493      return 1;
1494   }
1495   state->m_type = SLOT_SYNTHESIZER;
1496   state->m_mem = mem;
1497   state->m_size = size;
1498
1499   return 0;
1500}
1501
1502MSX_SLOT_RESET(synthesizer)
1503{
1504   /* empty */
1505}
1506
1507MSX_SLOT_MAP(synthesizer)
1508{
1509   msx_state *drvstate = machine.driver_data<msx_state>();
1510   switch (page)
1511   {
1512   case 0:
1513      msx_cpu_setbank (machine, 1, drvstate->m_empty);
1514      msx_cpu_setbank (machine, 2, drvstate->m_empty);
1515      break;
1516   case 1:
1517      msx_cpu_setbank (machine, 3, state->m_mem);
1518      msx_cpu_setbank (machine, 4, state->m_mem + 0x2000);
1519      break;
1520   case 2:
1521      msx_cpu_setbank (machine, 5, state->m_mem + 0x4000);
1522      msx_cpu_setbank (machine, 6, state->m_mem + 0x6000);
1523      break;
1524   case 3:
1525      msx_cpu_setbank (machine, 7, drvstate->m_empty);
1526      msx_cpu_setbank (machine, 8, drvstate->m_empty);
1527   }
1528}
1529
1530MSX_SLOT_WRITE(synthesizer)
1531{
1532   if (addr >= 0x4000 && addr < 0x8000 && !(addr & 0x0010))
1533   {
1534      dac_data_w (machine.device("dac"), val);
1535   }
1536}
1537
1538MSX_SLOT_INIT(majutsushi)
1539{
1540   if (size != 0x20000)
1541   {
1542      logerror ("majutsushi: error: rom file must be 128kb\n");
1543      return 1;
1544   }
1545   state->m_type = SLOT_MAJUTSUSHI;
1546   state->m_mem = mem;
1547   state->m_size = size;
1548   state->m_bank_mask = 0x0f;
1549
1550   return 0;
1551}
1552
1553MSX_SLOT_RESET(majutsushi)
1554{
1555   int i;
1556
1557   for (i=0; i<4; i++)
1558   {
1559      state->m_banks[i] = i;
1560   }
1561}
1562
1563MSX_SLOT_MAP(majutsushi)
1564{
1565   switch (page)
1566   {
1567   case 0:
1568      msx_cpu_setbank (machine, 1, state->m_mem + state->m_banks[0] * 0x2000);
1569      msx_cpu_setbank (machine, 2, state->m_mem + state->m_banks[1] * 0x2000);
1570      break;
1571   case 1:
1572      msx_cpu_setbank (machine, 3, state->m_mem + state->m_banks[0] * 0x2000);
1573      msx_cpu_setbank (machine, 4, state->m_mem + state->m_banks[1] * 0x2000);
1574      break;
1575   case 2:
1576      msx_cpu_setbank (machine, 5, state->m_mem + state->m_banks[2] * 0x2000);
1577      msx_cpu_setbank (machine, 6, state->m_mem + state->m_banks[3] * 0x2000);
1578      break;
1579   case 3:
1580      msx_cpu_setbank (machine, 7, state->m_mem + state->m_banks[2] * 0x2000);
1581      msx_cpu_setbank (machine, 8, state->m_mem + state->m_banks[3] * 0x2000);
1582      break;
1583   }
1584}
1585
1586MSX_SLOT_WRITE(majutsushi)
1587{
1588   msx_state *drvstate = machine.driver_data<msx_state>();
1589   if (addr >= 0x5000 && addr < 0x6000)
1590   {
1591      dac_data_w (machine.device("dac"), val);
1592   }
1593   else if (addr >= 0x6000 && addr < 0x8000)
1594   {
1595      state->m_banks[1] = val & 0x0f;
1596      slot_majutsushi_map (machine, state, 1);
1597      if (drvstate->m_state[0] == state)
1598      {
1599         slot_konami_map (machine, state, 0);
1600      }
1601   }
1602   else if (addr >= 0x8000 && addr < 0xc000)
1603   {
1604      state->m_banks[addr < 0xa000 ? 2 : 3] = val & 0x0f;
1605      slot_majutsushi_map (machine, state, 2);
1606      if (drvstate->m_state[3] == state)
1607      {
1608         slot_konami_map (machine, state, 3);
1609      }
1610   }
1611}
1612
1613MSX_SLOT_INIT(fmpac)
1614{
1615   static const char sramfile[] = "fmpac.rom";
1616   UINT8 *p;
1617   int banks;
1618
1619   if (size > 0x400000)
1620   {
1621      logerror ("fmpac: warning: truncating rom to 4mb\n");
1622      size = 0x400000;
1623   }
1624   banks = size / 0x4000;
1625   if (size != banks * 0x4000 || (~(banks - 1) % banks))
1626   {
1627      logerror ("fmpac: error: must be a 2 power of 16kb\n");
1628      return 1;
1629   }
1630
1631   if (!strncmp ((char*)mem + 0x18, "PAC2", 4))
1632   {
1633      state->m_cart.fmpac.sram_support = 1;
1634      p = auto_alloc_array(machine, UINT8, 0x4000);
1635      memset (p, 0, 0x2000);
1636      memset (p + 0x2000, 0xff, 0x2000);
1637      state->m_cart.fmpac.mem = p;
1638   }
1639   else
1640   {
1641      state->m_cart.fmpac.sram_support = 0;
1642      state->m_cart.fmpac.mem = NULL;
1643   }
1644
1645   state->m_type = SLOT_FMPAC;
1646   state->m_size = size;
1647   state->m_mem = mem;
1648   state->m_bank_mask = banks - 1;
1649   if (!state->m_sramfile)
1650   {
1651      state->m_sramfile = sramfile;
1652   }
1653
1654   return 0;
1655}
1656
1657MSX_SLOT_RESET(fmpac)
1658{
1659   msx_state *drvstate = machine.driver_data<msx_state>();
1660   int i;
1661
1662   state->m_banks[0] = 0;
1663   state->m_cart.fmpac.sram_active = 0;
1664   state->m_cart.fmpac.opll_active = 0;
1665   drvstate->m_opll_active = 0;
1666   for (i=0; i<=state->m_bank_mask; i++)
1667   {
1668      state->m_mem[0x3ff6 + i * 0x4000] = 0;
1669   }
1670
1671   /* NPW 21-Feb-2004 - Adding check for null */
1672   if (state->m_cart.fmpac.mem)
1673   {
1674      state->m_cart.fmpac.mem[0x3ff6] = 0;
1675      state->m_cart.fmpac.mem[0x3ff7] = 0;
1676   }
1677
1678   /* IMPROVE: reset sound chip */
1679}
1680
1681MSX_SLOT_MAP(fmpac)
1682{
1683   msx_state *drvstate = machine.driver_data<msx_state>();
1684   if (page == 1)
1685   {
1686      if (state->m_cart.fmpac.sram_active)
1687      {
1688         msx_cpu_setbank (machine, 3, state->m_cart.fmpac.mem);
1689         msx_cpu_setbank (machine, 4, state->m_cart.fmpac.mem + 0x2000);
1690      }
1691      else
1692      {
1693         msx_cpu_setbank (machine, 3, state->m_mem + state->m_banks[0] * 0x4000);
1694         msx_cpu_setbank (machine, 4, state->m_mem + state->m_banks[0] * 0x4000 + 0x2000);
1695      }
1696   }
1697   else
1698   {
1699      msx_cpu_setbank (machine, page * 2 + 1, drvstate->m_empty);
1700      msx_cpu_setbank (machine, page * 2 + 2, drvstate->m_empty);
1701   }
1702}
1703
1704MSX_SLOT_WRITE(fmpac)
1705{
1706   msx_state *drvstate = machine.driver_data<msx_state>();
1707   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
1708   int i, data;
1709
1710   if (addr >= 0x4000 && addr < 0x6000 && state->m_cart.fmpac.sram_support)
1711   {
1712      if (state->m_cart.fmpac.sram_active || addr >= 0x5ffe)
1713      {
1714         state->m_cart.fmpac.mem[addr & 0x1fff] = val;
1715      }
1716
1717      state->m_cart.fmpac.sram_active =
1718            (state->m_cart.fmpac.mem[0x1ffe] == 0x4d &&
1719             state->m_cart.fmpac.mem[0x1fff] == 0x69);
1720   }
1721
1722   switch (addr)
1723   {
1724   case 0x7ff4:
1725      if (state->m_cart.fmpac.opll_active)
1726      {
1727         ym2413_w (space->machine().device("ay8910"), 0, val);
1728      }
1729      break;
1730   case 0x7ff5:
1731      if (state->m_cart.fmpac.opll_active)
1732      {
1733         ym2413_w (space->machine().device("ay8910"), 1, val);
1734      }
1735      break;
1736   case 0x7ff6:
1737      data = val & 0x11;
1738      for (i=0; i<=state->m_bank_mask; i++)
1739      {
1740         state->m_mem[0x3ff6 + i * 0x4000] = data;
1741      }
1742      state->m_cart.fmpac.mem[0x3ff6] = data;
1743      state->m_cart.fmpac.opll_active = val & 1;
1744      if ((drvstate->m_opll_active ^ val) & 1)
1745      {
1746         logerror ("FM-PAC: OPLL %sactivated\n", val & 1 ? "" : "de");
1747      }
1748      drvstate->m_opll_active = val & 1;
1749      break;
1750   case 0x7ff7:
1751      state->m_banks[0] = val & state->m_bank_mask;
1752      state->m_cart.fmpac.mem[0x3ff7] = val & state->m_bank_mask;
1753      slot_fmpac_map (machine, state, 1);
1754      break;
1755   }
1756}
1757
1758static const char PAC_HEADER[] = "PAC2 BACKUP DATA";
1759#define PAC_HEADER_LEN (16)
1760
1761MSX_SLOT_LOADSRAM(fmpac)
1762{
1763   char buf[PAC_HEADER_LEN];
1764
1765   if (!state->m_cart.fmpac.sram_support)
1766   {
1767      logerror ("Your fmpac.rom does not support sram\n");
1768      return 1;
1769   }
1770
1771   if (!state->m_sramfile)
1772   {
1773      logerror ("No sram filename provided\n");
1774      return 1;
1775   }
1776   emu_file f(machine.options().memcard_directory(), OPEN_FLAG_READ);
1777   file_error filerr = f.open(state->m_sramfile);
1778   if (filerr == FILERR_NONE)
1779   {
1780      if ((f.read(buf, PAC_HEADER_LEN) == PAC_HEADER_LEN) &&
1781         !strncmp (buf, PAC_HEADER, PAC_HEADER_LEN) &&
1782         f.read(state->m_cart.fmpac.mem, 0x1ffe))
1783      {
1784         logerror ("fmpac: info: sram loaded\n");
1785         return 0;
1786      }
1787      else
1788      {
1789         logerror ("fmpac: warning: failed to load sram\n");
1790         return 1;
1791      }
1792   }
1793
1794   logerror ("fmpac: warning: could not open sram file\n");
1795   return 1;
1796}
1797
1798MSX_SLOT_SAVESRAM(fmpac)
1799{
1800   if (!state->m_cart.fmpac.sram_support || !state->m_sramfile)
1801   {
1802      return 0;
1803   }
1804
1805   emu_file f(machine.options().memcard_directory(), OPEN_FLAG_WRITE);
1806   file_error filerr = f.open(state->m_sramfile);
1807   if (filerr == FILERR_NONE)
1808   {
1809      if ((f.write(PAC_HEADER, PAC_HEADER_LEN) == PAC_HEADER_LEN) &&
1810         (f.write(state->m_cart.fmpac.mem, 0x1ffe) == 0x1ffe))
1811      {
1812         logerror ("fmpac: info: sram saved\n");
1813         return 0;
1814      }
1815      else
1816      {
1817         logerror ("fmpac: warning: sram save to file failed\n");
1818         return 1;
1819      }
1820   }
1821
1822   logerror ("fmpac: warning: could not open sram file for writing\n");
1823
1824   return 1;
1825}
1826
1827MSX_SLOT_INIT(superloadrunner)
1828{
1829   if (size != 0x20000)
1830   {
1831      logerror ("superloadrunner: error: rom file should be exactly "
1832              "128kb\n");
1833      return 1;
1834   }
1835   state->m_type = SLOT_SUPERLOADRUNNER;
1836   state->m_mem = mem;
1837   state->m_size = size;
1838   state->m_start_page = page;
1839   state->m_bank_mask = 7;
1840
1841   return 0;
1842}
1843
1844MSX_SLOT_RESET(superloadrunner)
1845{
1846   msx_state *drvstate = machine.driver_data<msx_state>();
1847   drvstate->m_superloadrunner_bank = 0;
1848}
1849
1850MSX_SLOT_MAP(superloadrunner)
1851{
1852   msx_state *drvstate = machine.driver_data<msx_state>();
1853   if (page == 2)
1854   {
1855      UINT8 *mem = state->m_mem +
1856            (drvstate->m_superloadrunner_bank & state->m_bank_mask) * 0x4000;
1857
1858      msx_cpu_setbank (machine, 5, mem);
1859      msx_cpu_setbank (machine, 6, mem + 0x2000);
1860   }
1861   else
1862   {
1863      msx_cpu_setbank (machine, page * 2 + 1, drvstate->m_empty);
1864      msx_cpu_setbank (machine, page * 2 + 2, drvstate->m_empty);
1865   }
1866}
1867
1868MSX_SLOT_INIT(crossblaim)
1869{
1870   if (size != 0x10000)
1871   {
1872      logerror ("crossblaim: error: rom file should be exactly 64kb\n");
1873      return 1;
1874   }
1875   state->m_type = SLOT_CROSS_BLAIM;
1876   state->m_mem = mem;
1877   state->m_size = size;
1878
1879   return 0;
1880}
1881
1882MSX_SLOT_RESET(crossblaim)
1883{
1884   state->m_banks[0] = 1;
1885}
1886
1887MSX_SLOT_MAP(crossblaim)
1888{
1889   msx_state *drvstate = machine.driver_data<msx_state>();
1890   UINT8 *mem;
1891
1892   /* This might look odd, but it's what happens on the real cartridge */
1893
1894   switch (page)
1895   {
1896   case 0:
1897      if (state->m_banks[0] < 2){
1898         mem = state->m_mem + state->m_banks[0] * 0x4000;
1899         msx_cpu_setbank (machine, 1, mem);
1900         msx_cpu_setbank (machine, 2, mem + 0x2000);
1901      }
1902      else
1903      {
1904         msx_cpu_setbank (machine, 1, drvstate->m_empty);
1905         msx_cpu_setbank (machine, 2, drvstate->m_empty);
1906      }
1907      break;
1908   case 1:
1909      msx_cpu_setbank (machine, 3, state->m_mem);
1910      msx_cpu_setbank (machine, 4, state->m_mem + 0x2000);
1911      break;
1912   case 2:
1913      mem = state->m_mem + state->m_banks[0] * 0x4000;
1914      msx_cpu_setbank (machine, 5, mem);
1915      msx_cpu_setbank (machine, 6, mem + 0x2000);
1916      break;
1917   case 3:
1918      if (state->m_banks[0] < 2){
1919         mem = state->m_mem + state->m_banks[0] * 0x4000;
1920         msx_cpu_setbank (machine, 7, mem);
1921         msx_cpu_setbank (machine, 8, mem + 0x2000);
1922      }
1923      else
1924      {
1925         msx_cpu_setbank (machine, 7, drvstate->m_empty);
1926         msx_cpu_setbank (machine, 8, drvstate->m_empty);
1927      }
1928   }
1929}
1930
1931MSX_SLOT_WRITE(crossblaim)
1932{
1933   msx_state *drvstate = machine.driver_data<msx_state>();
1934   UINT8 block = val & 3;
1935
1936   if (!block) block = 1;
1937   state->m_banks[0] = block;
1938
1939   if (drvstate->m_state[0] == state)
1940   {
1941      slot_crossblaim_map (machine, state, 0);
1942   }
1943   if (drvstate->m_state[2] == state)
1944   {
1945      slot_crossblaim_map (machine, state, 2);
1946   }
1947   if (drvstate->m_state[3] == state)
1948   {
1949      slot_crossblaim_map (machine, state, 3);
1950   }
1951}
1952
1953MSX_SLOT_INIT(korean80in1)
1954{
1955   int banks;
1956
1957   if (size > 0x200000)
1958   {
1959      logerror ("korean-80in1: warning: truncating to 2mb\n");
1960      size = 0x200000;
1961   }
1962   banks = size / 0x2000;
1963   if (size != banks * 0x2000 || (~(banks - 1) % banks))
1964   {
1965      logerror ("korean-80in1: error: must be a 2 power of 8kb\n");
1966      return 1;
1967   }
1968   state->m_type = SLOT_KOREAN_80IN1;
1969   state->m_mem = mem;
1970   state->m_size = size;
1971   state->m_bank_mask = banks - 1;
1972
1973   return 0;
1974}
1975
1976MSX_SLOT_RESET(korean80in1)
1977{
1978   int i;
1979
1980   for (i=0; i<4; i++)
1981   {
1982      state->m_banks[i] = i;
1983   }
1984}
1985
1986MSX_SLOT_MAP(korean80in1)
1987{
1988   msx_state *drvstate = machine.driver_data<msx_state>();
1989   switch (page)
1990   {
1991   case 0:
1992      msx_cpu_setbank (machine, 1, drvstate->m_empty);
1993      msx_cpu_setbank (machine, 2, drvstate->m_empty);
1994      break;
1995   case 1:
1996      msx_cpu_setbank (machine, 3, state->m_mem + state->m_banks[0] * 0x2000);
1997      msx_cpu_setbank (machine, 4, state->m_mem + state->m_banks[1] * 0x2000);
1998      break;
1999   case 2:
2000      msx_cpu_setbank (machine, 5, state->m_mem + state->m_banks[2] * 0x2000);
2001      msx_cpu_setbank (machine, 6, state->m_mem + state->m_banks[3] * 0x2000);
2002      break;
2003   case 3:
2004      msx_cpu_setbank (machine, 7, drvstate->m_empty);
2005      msx_cpu_setbank (machine, 8, drvstate->m_empty);
2006   }
2007}
2008
2009MSX_SLOT_WRITE(korean80in1)
2010{
2011   msx_state *drvstate = machine.driver_data<msx_state>();
2012   int bank;
2013
2014   if (addr >= 0x4000 && addr < 0x4004)
2015   {
2016      bank = addr & 3;
2017
2018      state->m_banks[bank] = val & state->m_bank_mask;
2019      if (bank <= 1)
2020      {
2021         slot_korean80in1_map (machine, state, 1);
2022      }
2023      else if (drvstate->m_state[2] == state)
2024      {
2025         slot_korean80in1_map (machine, state, 2);
2026      }
2027   }
2028}
2029
2030MSX_SLOT_INIT(korean90in1)
2031{
2032   int banks;
2033
2034   if (size > 0x100000)
2035   {
2036      logerror ("korean-90in1: warning: truncating to 1mb\n");
2037      size = 0x100000;
2038   }
2039   banks = size / 0x4000;
2040   if (size != banks * 0x4000 || (~(banks - 1) % banks))
2041   {
2042      logerror ("korean-90in1: error: must be a 2 power of 16kb\n");
2043      return 1;
2044   }
2045   state->m_type = SLOT_KOREAN_90IN1;
2046   state->m_mem = mem;
2047   state->m_size = size;
2048   state->m_bank_mask = banks - 1;
2049
2050   return 0;
2051}
2052
2053MSX_SLOT_RESET(korean90in1)
2054{
2055   msx_state *drvstate = machine.driver_data<msx_state>();
2056   drvstate->m_korean90in1_bank = 0;
2057}
2058
2059MSX_SLOT_MAP(korean90in1)
2060{
2061   msx_state *drvstate = machine.driver_data<msx_state>();
2062   UINT8 *mem;
2063   UINT8 mask = (drvstate->m_korean90in1_bank & 0xc0) == 0x80 ? 0x3e : 0x3f;
2064   mem = state->m_mem +
2065      ((drvstate->m_korean90in1_bank & mask) & state->m_bank_mask) * 0x4000;
2066
2067   switch (page)
2068   {
2069   case 0:
2070      msx_cpu_setbank (machine, 1, drvstate->m_empty);
2071      msx_cpu_setbank (machine, 2, drvstate->m_empty);
2072      break;
2073   case 1:
2074      msx_cpu_setbank (machine, 3, mem);
2075      msx_cpu_setbank (machine, 4, mem + 0x2000);
2076      break;
2077   case 2:
2078      switch (drvstate->m_korean90in1_bank & 0xc0)
2079      {
2080      case 0x80: /* 32 kb mode */
2081         mem += 0x4000;
2082      default: /* ie. 0x00 and 0x40: same memory as page 1 */
2083         msx_cpu_setbank (machine, 5, mem);
2084         msx_cpu_setbank (machine, 6, mem + 0x2000);
2085         break;
2086      case 0xc0: /* same memory as page 1, but swap lower/upper 8kb */
2087         msx_cpu_setbank (machine, 5, mem + 0x2000);
2088         msx_cpu_setbank (machine, 6, mem);
2089         break;
2090      }
2091      break;
2092   case 3:
2093      msx_cpu_setbank (machine, 7, drvstate->m_empty);
2094      msx_cpu_setbank (machine, 8, drvstate->m_empty);
2095   }
2096}
2097
2098MSX_SLOT_INIT(korean126in1)
2099{
2100   int banks;
2101
2102   if (size > 0x400000)
2103   {
2104      logerror ("korean-126in1: warning: truncating to 4mb\n");
2105      size = 0x400000;
2106   }
2107   banks = size / 0x4000;
2108   if (size != banks * 0x4000 || (~(banks - 1) % banks))
2109   {
2110      logerror ("korean-126in1: error: must be a 2 power of 16kb\n");
2111      return 1;
2112   }
2113
2114   state->m_type = SLOT_KOREAN_126IN1;
2115   state->m_mem = mem;
2116   state->m_size = size;
2117   state->m_bank_mask = banks - 1;
2118
2119   return 0;
2120}
2121
2122MSX_SLOT_RESET(korean126in1)
2123{
2124   int i;
2125
2126   for (i=0; i<2; i++) state->m_banks[i] = i;
2127}
2128
2129MSX_SLOT_MAP(korean126in1)
2130{
2131   msx_state *drvstate = machine.driver_data<msx_state>();
2132   UINT8 *mem;
2133
2134   switch (page)
2135   {
2136   case 0:
2137      msx_cpu_setbank (machine, 1, drvstate->m_empty);
2138      msx_cpu_setbank (machine, 2, drvstate->m_empty);
2139      break;
2140   case 1:
2141      mem = state->m_mem + state->m_banks[0] * 0x4000;
2142      msx_cpu_setbank (machine, 3, mem);
2143      msx_cpu_setbank (machine, 4, mem + 0x2000);
2144      break;
2145   case 2:
2146      mem = state->m_mem + state->m_banks[1] * 0x4000;
2147      msx_cpu_setbank (machine, 5, mem);
2148      msx_cpu_setbank (machine, 6, mem + 0x2000);
2149      break;
2150   case 3:
2151      msx_cpu_setbank (machine, 7, drvstate->m_empty);
2152      msx_cpu_setbank (machine, 8, drvstate->m_empty);
2153   }
2154}
2155
2156MSX_SLOT_WRITE(korean126in1)
2157{
2158   msx_state *drvstate = machine.driver_data<msx_state>();
2159   if (addr >= 0x4000 && addr < 0x4002)
2160   {
2161      int bank = addr & 1;
2162      state->m_banks[bank] = val & state->m_bank_mask;
2163      if (bank == 0)
2164      {
2165         slot_korean126in1_map (machine, state, 1);
2166      }
2167      else if (drvstate->m_state[2] == state)
2168      {
2169         slot_korean126in1_map (machine, state, 2);
2170      }
2171   }
2172}
2173
2174MSX_SLOT_INIT(soundcartridge)
2175{
2176   UINT8 *p;
2177
2178   p = auto_alloc_array(machine, UINT8, 0x20000);
2179   memset (p, 0, 0x20000);
2180
2181   state->m_mem = p;
2182   state->m_size = 0x20000;
2183   state->m_bank_mask = 15;
2184   state->m_type = SLOT_SOUNDCARTRIDGE;
2185
2186   return 0;
2187}
2188
2189MSX_SLOT_RESET(soundcartridge)
2190{
2191   int i;
2192
2193   for (i=0; i<4; i++)
2194   {
2195      state->m_banks[i] = i;
2196      state->m_cart.sccp.ram_mode[i] = 0;
2197      state->m_cart.sccp.banks_saved[i] = i;
2198   }
2199   state->m_cart.sccp.mode = 0;
2200   state->m_cart.sccp.scc_active = 0;
2201   state->m_cart.sccp.sccp_active = 0;
2202}
2203
2204static  READ8_HANDLER (soundcartridge_scc)
2205{
2206   msx_state *state = space->machine().driver_data<msx_state>();
2207   int reg;
2208
2209
2210   if (offset >= 0x7e0)
2211   {
2212      return state->m_state[2]->m_mem[
2213            state->m_state[2]->m_banks[2] * 0x2000 + 0x1800 + offset];
2214   }
2215
2216   reg = offset & 0xff;
2217
2218   if (reg < 0x80)
2219   {
2220      return k051649_waveform_r (space->machine().device("k051649"), reg);
2221   }
2222   else if (reg < 0xa0)
2223   {
2224      /* nothing */
2225   }
2226   else if (reg < 0xc0)
2227   {
2228      /* read wave 5 */
2229      return k051649_waveform_r (space->machine().device("k051649"), 0x80 + (reg & 0x1f));
2230   }
2231#if 0
2232   else if (reg < 0xe0)
2233   {
2234      /* write 0xff to deformation register */
2235   }
2236#endif
2237
2238   return 0xff;
2239}
2240
2241static  READ8_HANDLER (soundcartridge_sccp)
2242{
2243   msx_state *state = space->machine().driver_data<msx_state>();
2244   int reg;
2245
2246   if (offset >= 0x7e0)
2247   {
2248      return state->m_state[2]->m_mem[
2249            state->m_state[2]->m_banks[3] * 0x2000 + 0x1800 + offset];
2250   }
2251
2252   reg = offset & 0xff;
2253
2254   if (reg < 0xa0)
2255   {
2256      return k051649_waveform_r (space->machine().device("k051649"), reg);
2257   }
2258#if 0
2259   else if (reg >= 0xc0 && reg < 0xe0)
2260   {
2261      /* write 0xff to deformation register */
2262   }
2263#endif
2264
2265   return 0xff;
2266}
2267
2268MSX_SLOT_MAP(soundcartridge)
2269{
2270   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
2271   switch (page)
2272   {
2273   case 0:
2274      msx_cpu_setbank (machine, 1, state->m_mem + state->m_banks[2] * 0x2000);
2275      msx_cpu_setbank (machine, 2, state->m_mem + state->m_banks[3] * 0x2000);
2276      break;
2277   case 1:
2278      msx_cpu_setbank (machine, 3, state->m_mem + state->m_banks[0] * 0x2000);
2279      msx_cpu_setbank (machine, 4, state->m_mem + state->m_banks[1] * 0x2000);
2280      break;
2281   case 2:
2282      msx_cpu_setbank (machine, 5, state->m_mem + state->m_banks[2] * 0x2000);
2283      msx_cpu_setbank (machine, 6, state->m_mem + state->m_banks[3] * 0x2000);
2284      if (state->m_cart.sccp.scc_active) {
2285         space->install_legacy_read_handler(0x9800, 0x9fff, FUNC(soundcartridge_scc));
2286      } else {
2287         space->install_read_bank(0x9800, 0x9fff, "bank7");
2288      }
2289      if (state->m_cart.sccp.scc_active) {
2290         space->install_legacy_read_handler(0xb800, 0xbfff, FUNC(soundcartridge_sccp));
2291      } else {
2292         space->install_read_bank(0xb800, 0xbfff, "bank9");
2293      }
2294      break;
2295   case 3:
2296      msx_cpu_setbank (machine, 7, state->m_mem + state->m_banks[0] * 0x2000);
2297      msx_cpu_setbank (machine, 8, state->m_mem + state->m_banks[1] * 0x2000);
2298      break;
2299   }
2300}
2301
2302MSX_SLOT_WRITE(soundcartridge)
2303{
2304   msx_state *drvstate = machine.driver_data<msx_state>();
2305   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
2306   int i;
2307
2308   if (addr < 0x4000)
2309   {
2310      return;
2311   }
2312   else if (addr < 0x6000)
2313   {
2314      if (state->m_cart.sccp.ram_mode[0])
2315      {
2316         state->m_mem[state->m_banks[0] * 0x2000 + (addr & 0x1fff)] = val;
2317      }
2318      else if (addr >= 0x5000 && addr < 0x5800)
2319      {
2320         state->m_banks[0] = val & state->m_bank_mask;
2321         state->m_cart.sccp.banks_saved[0] = val;
2322         slot_soundcartridge_map (machine, state, 1);
2323         if (drvstate->m_state[3] == state)
2324         {
2325            slot_soundcartridge_map (machine, state, 3);
2326         }
2327      }
2328   }
2329   else if (addr < 0x8000)
2330   {
2331      if (state->m_cart.sccp.ram_mode[1])
2332      {
2333         state->m_mem[state->m_banks[1] * 0x2000 + (addr & 0x1fff)] = val;
2334      }
2335      else if (addr >= 0x7000 && addr < 0x7800)
2336      {
2337         state->m_banks[1] = val & state->m_bank_mask;
2338         state->m_cart.sccp.banks_saved[1] = val;
2339         if (drvstate->m_state[3] == state)
2340         {
2341            slot_soundcartridge_map (machine, state, 3);
2342         }
2343         slot_soundcartridge_map (machine, state, 1);
2344      }
2345   }
2346   else if (addr < 0xa000)
2347   {
2348      if (state->m_cart.sccp.ram_mode[2])
2349      {
2350         state->m_mem[state->m_banks[2] * 0x2000 + (addr & 0x1fff)] = val;
2351      }
2352      else if (addr >= 0x9000 && addr < 0x9800)
2353      {
2354         state->m_banks[2] = val & state->m_bank_mask;
2355         state->m_cart.sccp.banks_saved[2] = val;
2356         state->m_cart.sccp.scc_active =
2357               (((val & 0x3f) == 0x3f) && !(state->m_cart.sccp.mode & 0x20));
2358
2359         slot_soundcartridge_map (machine, state, 2);
2360         if (drvstate->m_state[0] == state)
2361         {
2362            slot_soundcartridge_map (machine, state, 0);
2363         }
2364      }
2365      else if (addr >= 0x9800 && state->m_cart.sccp.scc_active)
2366      {
2367         device_t *k051649 = space->machine().device("k051649");
2368         int offset = addr & 0xff;
2369
2370         if (offset < 0x80)
2371         {
2372            k051649_waveform_w (k051649, offset, val);
2373         }
2374         else if (offset < 0xa0)
2375         {
2376            offset &= 0xf;
2377
2378            if (offset < 0xa)
2379            {
2380               k051649_frequency_w (k051649, offset, val);
2381            }
2382            else if (offset < 0x0f)
2383            {
2384               k051649_volume_w (k051649, offset - 0xa, val);
2385            }
2386            else if (offset == 0x0f)
2387            {
2388               k051649_keyonoff_w (k051649, 0, val);
2389            }
2390         }
2391#if 0
2392         else if (offset < 0xe0)
2393         {
2394            /* write to deformation register */
2395         }
2396#endif
2397      }
2398   }
2399   else if (addr < 0xbffe)
2400   {
2401      if (state->m_cart.sccp.ram_mode[3])
2402      {
2403         state->m_mem[state->m_banks[3] * 0x2000 + (addr & 0x1fff)] = val;
2404      }
2405      else if (addr >= 0xb000 && addr < 0xb800)
2406      {
2407         state->m_cart.sccp.banks_saved[3] = val;
2408         state->m_banks[3] = val & state->m_bank_mask;
2409         state->m_cart.sccp.sccp_active =
2410               (val & 0x80) && (state->m_cart.sccp.mode & 0x20);
2411         slot_soundcartridge_map (machine, state, 2);
2412         if (drvstate->m_state[0] == state)
2413         {
2414            slot_soundcartridge_map (machine, state, 0);
2415         }
2416      }
2417      else if (addr >= 0xb800 && state->m_cart.sccp.sccp_active)
2418      {
2419         device_t *k051649 = space->machine().device("k051649");
2420         int offset = addr & 0xff;
2421
2422         if (offset < 0xa0)
2423         {
2424            k052539_waveform_w (k051649, offset, val);
2425         }
2426         else if (offset < 0xc0)
2427         {
2428            offset &= 0x0f;
2429
2430            if (offset < 0x0a)
2431            {
2432               k051649_frequency_w (k051649, offset, val);
2433            }
2434            else if (offset < 0x0f)
2435            {
2436               k051649_volume_w (k051649, offset - 0x0a, val);
2437            }
2438            else if (offset == 0x0f)
2439            {
2440               k051649_keyonoff_w (k051649, 0, val);
2441            }
2442         }
2443#if 0
2444         else if (offset < 0xe0)
2445         {
2446            /* write to deformation register */
2447         }
2448#endif
2449      }
2450   }
2451   else if (addr < 0xc000)
2452   {
2453      /* write to mode register */
2454      if ((state->m_cart.sccp.mode ^ val) & 0x20)
2455      {
2456         logerror ("soundcartrige: changed to %s mode\n",
2457                     val & 0x20 ? "scc+" : "scc");
2458      }
2459      state->m_cart.sccp.mode = val;
2460      if (val & 0x10)
2461      {
2462         /* all ram mode */
2463         for (i=0; i<4; i++)
2464         {
2465            state->m_cart.sccp.ram_mode[i] = 1;
2466         }
2467      }
2468      else
2469      {
2470         state->m_cart.sccp.ram_mode[0] = val & 1;
2471         state->m_cart.sccp.ram_mode[1] = val & 2;
2472         state->m_cart.sccp.ram_mode[2] = (val & 4) && (val & 0x20);
2473         state->m_cart.sccp.ram_mode[3] = 0;
2474
2475      }
2476
2477      state->m_cart.sccp.scc_active =
2478         (((state->m_cart.sccp.banks_saved[2] & 0x3f) == 0x3f) &&
2479         !(val & 0x20));
2480
2481      state->m_cart.sccp.sccp_active =
2482            ((state->m_cart.sccp.banks_saved[3] & 0x80) && (val & 0x20));
2483
2484      slot_soundcartridge_map (machine, state, 2);
2485   }
2486}
2487
2488MSX_SLOT_START
2489   MSX_SLOT_ROM (SLOT_EMPTY, empty)
2490   MSX_SLOT (SLOT_MSXDOS2, msxdos2)
2491   MSX_SLOT (SLOT_KONAMI_SCC, konami_scc)
2492   MSX_SLOT (SLOT_KONAMI, konami)
2493   MSX_SLOT (SLOT_ASCII8, ascii8)
2494   MSX_SLOT (SLOT_ASCII16, ascii16)
2495   MSX_SLOT_SRAM (SLOT_GAMEMASTER2, gmaster2)
2496   MSX_SLOT_SRAM (SLOT_ASCII8_SRAM, ascii8_sram)
2497   MSX_SLOT_SRAM (SLOT_ASCII16_SRAM, ascii16_sram)
2498   MSX_SLOT (SLOT_RTYPE, rtype)
2499   MSX_SLOT (SLOT_MAJUTSUSHI, majutsushi)
2500   MSX_SLOT_SRAM (SLOT_FMPAC, fmpac)
2501   MSX_SLOT_ROM (SLOT_SUPERLOADRUNNER, superloadrunner)
2502   MSX_SLOT (SLOT_SYNTHESIZER, synthesizer)
2503   MSX_SLOT (SLOT_CROSS_BLAIM, crossblaim)
2504   MSX_SLOT (SLOT_DISK_ROM, diskrom)
2505   MSX_SLOT (SLOT_KOREAN_80IN1, korean80in1)
2506   MSX_SLOT (SLOT_KOREAN_126IN1, korean126in1)
2507   MSX_SLOT_ROM (SLOT_KOREAN_90IN1, korean90in1)
2508   MSX_SLOT (SLOT_SOUNDCARTRIDGE, soundcartridge)
2509   MSX_SLOT_ROM (SLOT_ROM, rom)
2510   MSX_SLOT_RAM (SLOT_RAM, ram)
2511   MSX_SLOT_RAM (SLOT_RAM_MM, rammm)
2512   MSX_SLOT_NULL (SLOT_CARTRIDGE1)
2513   MSX_SLOT_NULL (SLOT_CARTRIDGE2)
2514   MSX_SLOT (SLOT_DISK_ROM2, diskrom2)
2515MSX_SLOT_END
2516
src/mess/machine/psxcd.c
r11460r11461
1#include "emu.h"
2#include "includes/psx.h"
3#include "psxcd.h"
4#include "machine/devhelpr.h"
5#include "sound/spu.h"
6#include "debugger.h"
7
8//
9//
10//
11
12//#define debug_cdrom
13//#define debug_cdrom_registers
14//#define skip_reads
15//#define dump_subheader
16//#define disable_xa_prefetch
17//#define disable_cdda_prefetch
18
19//
20//
21//
22
23enum cdrom_events
24{
25   event_cmd_complete=0,
26   event_preread_sector,
27   event_read_sector,
28   event_play_sector
29};
30
31//
32//
33//
34
35enum intr_status
36{
37   intr_nointr=0,
38   intr_dataready,
39   intr_acknowledge,
40   intr_complete,
41   intr_dataend,
42   intr_diskerror
43};
44
45enum mode_flags
46{
47   mode_double_speed=0x80,
48   mode_adpcm=0x40,
49   mode_size=0x20,
50   mode_size2=0x10,
51   mode_size_shift=4,
52   mode_size_mask=(3<<mode_size_shift),
53   mode_channel=0x08,
54   mode_report=0x04,
55   mode_autopause=0x02,
56   mode_cdda=0x01
57};
58
59enum status_f
60{
61   status_playing=0x80,
62   status_seeking=0x40,
63   status_reading=0x20,
64   status_shellopen=0x10,
65   status_seekerror=0x04,
66   status_standby=0x02,
67   status_error=0x01
68};
69
70struct subheader
71{
72   unsigned char file,
73                        channel,
74                        submode,
75                        coding;
76};
77
78enum submode_flags
79{
80   submode_eof=0x80,
81   submode_realtime=0x40,
82   submode_form=0x20,
83   submode_trigger=0x10,
84   submode_data=0x08,
85   submode_audio=0x04,
86   submode_video=0x02,
87   submode_eor=0x01
88};
89
90//
91//
92//
93
94static const unsigned int max_xa_prefetch_distance=32,
95                                       max_cdda_prefetch_distance=32;
96
97//**************************************************************************
98//  DEVICE DEFINITIONS
99//**************************************************************************
100
101const device_type PSXCD = &device_creator<psxcd_device>;
102
103void psxcd_device::static_set_devname(device_t &device, const char *devname)
104{
105   psxcd_device &psxcd = downcast<psxcd_device &>(device);
106   psxcd.m_devname = devname;
107}
108
109psxcd_device::psxcd_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
110   : device_t(mconfig, PSXCD, "PSXCD", tag, owner, clock)
111{
112}
113
114void psxcd_device::device_start()
115{
116   unsigned int sysclk=machine().device<cpu_device>("maincpu")->clock()/2;
117   start_read_delay=(sysclk/60);
118   read_sector_cycles=(sysclk/75);
119   preread_delay=(read_sector_cycles>>2)-500;
120
121   m_sysclock = sysclk;
122
123   secleft = 0;
124   secsize = 2048;
125   res_queue = NULL;
126   cur_res = NULL;
127   open = false;
128   streaming = false;
129   sechead = 0;
130   sectail = 0;
131   secin = 0;
132   secskip = 0;
133   next_read_event = NULL;
134   cbp = cmdbuf;
135   first_open = true;
136
137   status=status_standby;
138   sr=8|1;
139   res=0;
140   ir=0;
141   mode=0;
142
143   driver = NULL;
144
145   for (int i = 0; i < MAX_PSXCD_TIMERS; i++)
146   {
147      m_timers[i] = timer_alloc(i, NULL);
148      m_timerinuse[i] = false;
149   }
150}
151
152//
153//
154//
155
156void psxcd_device::device_reset()
157{
158   stop_read();
159   open=false;
160
161   for (int i = 0; i < MAX_PSXCD_TIMERS; i++)
162   {
163      m_timerinuse[i] = false;
164   }
165
166   m_cddevice = machine().device(m_devname);
167   if (m_cddevice)
168   {
169      m_cd = cd_get_cdrom_file(m_cddevice);
170
171      if (m_cd)
172      {
173//          printf("psxcd: found disc!\n");
174         driver = open_mess_drv();
175         driver->set_machine(machine());
176         driver->set_cdrom_file(m_cd);
177      }
178      else
179      {
180         driver = NULL;
181//          printf("psxcd: Found device, but no disc\n");
182      }
183   }
184   else
185   {
186      driver = NULL;
187//      printf("psxcd: Device [%s] not found!\n", m_devname);
188   }
189
190}
191
192//
193//
194//
195
196unsigned char psxcd_device::read_byte(const unsigned int addr)
197{
198   unsigned char ret = 0;
199
200   switch (addr&3)
201   {
202      case 0: ret=sr; break;
203      case 1:
204         ret=res;
205         if ((cur_res) && (rdp<cur_res->sz))
206         {
207            res=cur_res->data[rdp++];
208            sr|=(1<<5);
209         } else
210         {
211            if ((cur_res) && (cur_res->res&0x10))
212            {
213               global_free(cur_res);
214               cur_res=NULL;
215            }
216
217            sr&=~(1<<5);
218         }
219         break;
220      case 2: ret=0; break;
221      case 3: ret=ir; break;
222   }
223
224   #ifdef debug_cdrom_registers
225      printf("cdrom: read byte %08x = %02x (PC=%x)\n",addr,ret,cpu_get_pc(machine().device("maincpu")));
226   #endif
227
228   return ret;
229}
230
231//
232//
233//
234
235void psxcd_device::write_byte(const unsigned int addr, const unsigned char byte)
236{
237   #ifdef debug_cdrom_registers
238      printf("cdrom: write byte %08x = %02x (PC=%x)\n",addr,byte,cpu_get_pc(machine().device("maincpu")));
239   #endif
240
241   switch (addr&3)
242   {
243      case 0:
244         cmdmode=byte&1;
245         if (cmdmode==0)
246         {
247            cbp=cmdbuf;
248         } else
249         {
250            if (! cur_res)
251            {
252               if (cur_res) global_free(cur_res);
253
254               if (res_queue)
255               {
256                  #ifdef debug_cdrom_registers
257                     printf("cdrom: nextres\n");
258                  #endif
259
260                  cur_res=res_queue;
261                  res_queue=res_queue->next;
262                  ir=cur_res->res&0xf;
263                  rdp=0;
264
265                  if (cur_res->sz)
266                  {
267                     res=cur_res->data[rdp++];
268                     sr|=(1<<5);
269                  } else
270                  {
271                     sr&=~(1<<5);
272                  }
273               } else
274               {
275                  //ir=0;
276                  cur_res=NULL;
277               }
278            }
279            /*else
280                {
281                    if (rdp>=cur_res->sz)
282                    {
283                        sr&=~(1<<5);
284                    } else
285                    {
286                        sr|=~(1<<5);
287                        res=cur_res->data[rdp++];
288                    }
289                }
290                */
291         }
292         break;
293
294      case 1:
295         if (cmdmode==0)
296         {
297            write_command(byte);
298         }
299         break;
300
301      case 2:
302         if (cmdmode==0)
303         {
304            *cbp++=byte;
305         } else
306         {
307            // ?flush buffer?
308         }
309         break;
310
311      case 3:
312         if (byte==0x07)
313         {
314            if (cur_res)
315            {
316               global_free(cur_res);
317               cur_res=NULL;
318               sr&=~(1<<5);
319            }
320            ir=0;
321         }
322         break;
323   }
324}
325
326psxcd_device::command_info psxcd_device::cmd_table[num_commands]=
327{
328   { &psxcd_device::cdcmd_sync,            "sync"         },   // 00
329   { &psxcd_device::cdcmd_nop,            "nop"            },   // 01
330   { &psxcd_device::cdcmd_setloc,         "setloc"      },   // 02
331   { &psxcd_device::cdcmd_play,            "play"         },   // 03
332   { &psxcd_device::cdcmd_forward,      "forward"      },   // 04
333   { &psxcd_device::cdcmd_backward,      "backward"   },   // 05
334   { &psxcd_device::cdcmd_readn,         "readn"         },   // 06
335   { &psxcd_device::cdcmd_standby,      "standby"      },   // 07
336   { &psxcd_device::cdcmd_stop,            "stop"         },   // 08
337   { &psxcd_device::cdcmd_pause,         "pause"         },   // 09
338   { &psxcd_device::cdcmd_init,            "init"         },   // 0a
339   { &psxcd_device::cdcmd_mute,            "mute"         },   // 0b
340   { &psxcd_device::cdcmd_demute,         "demute"      },   // 0c
341   { &psxcd_device::cdcmd_setfilter,   "setfilter"   },   // 0d
342   { &psxcd_device::cdcmd_setmode,      "setmode"      },   // 0e
343   { &psxcd_device::cdcmd_getparam,      "getparam"   },   // 0f
344   { &psxcd_device::cdcmd_getlocl,      "getlocl"      },   // 10
345   { &psxcd_device::cdcmd_getlocp,      "getlocp"      },   // 11
346   { &psxcd_device::cdcmd_illegal,      "illegal"      },   // 12
347   { &psxcd_device::cdcmd_gettn,         "gettn"         },   // 13
348   { &psxcd_device::cdcmd_gettd,         "gettd"         },   // 14
349   { &psxcd_device::cdcmd_seekl,         "seekl"         },   // 15
350   { &psxcd_device::cdcmd_seekp,         "seekp"         },   // 16
351   { &psxcd_device::cdcmd_illegal,      "illegal"      },   // 17
352   { &psxcd_device::cdcmd_illegal,      "illegal"      },   // 18
353   { &psxcd_device::cdcmd_test,            "test"         },   // 19
354   { &psxcd_device::cdcmd_id,               "id"            },   // 1a
355   { &psxcd_device::cdcmd_reads,         "reads"         },   // 1b
356   { &psxcd_device::cdcmd_reset,         "reset"         },   // 1c
357   { &psxcd_device::cdcmd_illegal,      "illegal"      },   // 1d
358   { &psxcd_device::cdcmd_readtoc,      "readtoc"      },   // 1e
359};
360
361//
362//
363//
364
365void psxcd_device::write_command(const unsigned char byte)
366{
367   assert(byte<num_commands);
368   (this->*cmd_table[byte].func)();
369}
370
371//
372//
373//
374
375void psxcd_device::cdcmd_sync()
376{
377   #ifdef debug_cdrom
378      printf("cdrom: sync\n");
379   #endif
380
381   stop_read();
382   send_result(intr_acknowledge);
383}
384
385static int open_nops=0;
386
387void psxcd_device::cdcmd_nop()
388{
389   #ifdef debug_cdrom
390      printf("cdrom: nop\n");
391   #endif
392
393   //stop_read();
394
395   if ((! open) && (driver))
396   {
397      if (open_nops==0)
398      {
399         open=driver->read_toc();
400      } else
401      {
402         open_nops--;
403      }
404   }
405
406   send_result(intr_complete);
407}
408
409void psxcd_device::cdcmd_setloc()
410{
411   #ifdef debug_cdrom
412      printf("cdrom: setloc %08x:%08x:%08x\n",
413            cmdbuf[0],
414            cmdbuf[1],
415            cmdbuf[2]);
416   #endif
417
418   stop_read();
419
420   unsigned char l[3];
421   l[0]=bcd_to_decimal(cmdbuf[0]);
422   l[1]=bcd_to_decimal(cmdbuf[1]);
423   l[2]=bcd_to_decimal(cmdbuf[2]);
424
425   if ((l[0]>0) || (l[1]>=2))
426   {
427      loc[0]=l[0];
428      loc[1]=l[1];
429      loc[2]=l[2];
430   } else
431   {
432      printf("setloc out of range: %02d:%02d:%02d\n",
433                l[0],l[1],l[2]);
434   }
435
436   send_result(intr_complete);
437}
438
439void psxcd_device::cdcmd_play()
440{
441   #ifdef debug_cdrom
442      printf("cdrom: play %02x %02x %02x => %d\n", loc[0], loc[1], loc[2], msf_to_sector(loc));
443   #endif
444
445   curpos[0]=loc[0];
446   curpos[1]=loc[1];
447   curpos[2]=loc[2];
448
449   if ((curpos[0]==0) &&
450         (curpos[1]==0) &&
451         (curpos[2]==0))
452   {
453      send_result(intr_acknowledge);
454   } else
455   {
456      stop_read();
457      start_play();
458      send_result(intr_acknowledge);
459   }
460}
461
462void psxcd_device::cdcmd_forward()
463{
464   #ifdef debug_cdrom
465      printf("cdrom: forward\n");
466   #endif
467}
468
469void psxcd_device::cdcmd_backward()
470{
471   #ifdef debug_cdrom
472      printf("cdrom: backward\n");
473   #endif
474}
475
476void psxcd_device::cdcmd_readn()
477{
478   if (driver)
479   {
480      #ifdef debug_cdrom
481         printf("cdrom: readn\n");
482      #endif
483
484      curpos[0]=loc[0];
485      curpos[1]=loc[1];
486      curpos[2]=loc[2];
487
488      stop_read();
489      start_read();
490      send_result(intr_complete);
491   } else
492   {
493      printf("read without driver\n");
494      send_result(intr_diskerror);
495   }
496}
497
498void psxcd_device::cdcmd_standby()
499{
500   #ifdef debug_cdrom
501      printf("cdrom: standby\n");
502   #endif
503
504   stop_read();
505   send_result(intr_acknowledge);
506}
507
508void psxcd_device::cdcmd_stop()
509{
510   #ifdef debug_cdrom
511      printf("cdrom: stop\n");
512   #endif
513
514   stop_read();
515   send_result(intr_acknowledge);
516}
517
518void psxcd_device::cdcmd_pause()
519{
520   #ifdef debug_cdrom
521      printf("cdrom: pause\n");
522   #endif
523
524   stop_read();
525
526   send_result(intr_acknowledge);
527}
528
529void psxcd_device::cdcmd_init()
530{
531   #ifdef debug_cdrom
532      printf("cdrom: init\n");
533   #endif
534
535   stop_read();
536   mode=0;
537   sr|=0x10;
538
539   send_result(intr_acknowledge);
540}
541
542void psxcd_device::cdcmd_mute()
543{
544   #ifdef debug_cdrom
545      printf("cdrom: mute\n");
546   #endif
547
548   send_result(intr_acknowledge);
549}
550
551void psxcd_device::cdcmd_demute()
552{
553   #ifdef debug_cdrom
554      printf("cdrom: demute\n");
555   #endif
556
557   send_result(intr_acknowledge);
558}
559
560void psxcd_device::cdcmd_setfilter()
561{
562   #ifdef debug_cdrom
563      printf("cdrom: setfilter %08x,%08x\n",cmdbuf[0],cmdbuf[1]);
564   #endif
565
566   filter_file=cmdbuf[0];
567   filter_channel=cmdbuf[1];
568
569   send_result(intr_acknowledge);
570}
571
572void psxcd_device::cdcmd_setmode()
573{
574   #ifdef debug_cdrom
575      printf("cdrom: setmode %08x\n",cmdbuf[0]);
576   #endif
577
578   mode=cmdbuf[0];
579
580   switch ((mode&mode_size_mask)>>mode_size_shift)
581   {
582      case 1:
583         secsize=2328;
584         secskip=24;
585         break;
586
587      case 2:
588         secsize=2340;
589         secskip=12;
590         break;
591
592      default:
593         secsize=2048;
594         secskip=24;
595         break;
596   }
597
598   send_result(intr_complete);
599}
600
601void psxcd_device::cdcmd_getparam()
602{
603   unsigned char data[6]=
604   {
605      status,
606      mode,
607      filter_file,
608      filter_channel,
609      0,
610      0
611   };
612
613   #ifdef debug_cdrom
614      printf("cdrom: getparam [%02x %02x %02x %02x %02x %02x]\n",
615                           data[0],
616                           data[1],
617                           data[2],
618                           data[3],
619                           data[4],
620                           data[5]);
621   #endif
622
623   send_result(intr_complete,data,6);
624}
625
626#if 0
627static void add_loc(unsigned char *dst, const unsigned char *src1, const unsigned char *src2)
628{
629   int f=src1[2]+src2[2],
630         s=src1[1]+src2[1],
631         m=src1[0]+src2[0];
632   while (f>=75) { s++; f-=75; }
633   while (s>=60) { m++; s-=60; }
634
635   dst[0]=m;
636   dst[1]=s;
637   dst[2]=f;
638}
639#endif
640static void sub_loc(unsigned char *dst, const unsigned char *src1, const unsigned char *src2)
641{
642   int f=src1[2]-src2[2],
643         s=src1[1]-src2[1],
644         m=src1[0]-src2[0];
645   while (f<0) { s--; f+=75; }
646   while (s<0) { m--; s+=60; }
647
648   if (m<0)
649      m=s=f=0;
650
651   dst[0]=m;
652   dst[1]=s;
653   dst[2]=f;
654}
655
656void psxcd_device::cdcmd_getlocl()
657{
658   #ifdef debug_cdrom
659      printf("cdrom: getlocl\n");
660   #endif
661
662   #ifdef debug_cdrom
663      printf("cdrom: getlocl [%02x %02x %02x %02x %02x %02x %02x %02x]\n",
664                           lastsechdr[0],
665                           lastsechdr[1],
666                           lastsechdr[2],
667                           lastsechdr[3],
668                           lastsechdr[4],
669                           lastsechdr[5],
670                           lastsechdr[6],
671                           lastsechdr[7]);
672   #endif
673
674   send_result(intr_complete,lastsechdr,8);
675}
676
677void psxcd_device::cdcmd_getlocp()
678{
679   unsigned char tloc[3],
680                        twosec[3]={ 0,2,0 };
681   sub_loc(tloc,loc,twosec);
682
683   unsigned char data[8]=
684   {
685      0x01,                     // track
686      0x01,                     // index
687      decimal_to_bcd(tloc[0]),   // min
688      decimal_to_bcd(tloc[1]),   // sec
689      decimal_to_bcd(tloc[2]),   // frame
690      decimal_to_bcd(loc[0]),   // amin
691      decimal_to_bcd(loc[1]),   // asec
692      decimal_to_bcd(loc[2])   // aframe
693   };
694
695   //unsigned char data[8]={ 2,1,0,0xff,0xff,0xff,0xff,0xff };
696
697   #ifdef debug_cdrom
698      printf("cdrom: getlocp [%02x %02x %02x %02x %02x %02x %02x %02x]\n",
699                           data[0],
700                           data[1],
701                           data[2],
702                           data[3],
703                           data[4],
704                           data[5],
705                           data[6],
706                           data[7]);
707   #endif
708
709   send_result(intr_complete,data,8);
710}
711
712void psxcd_device::cdcmd_illegal()
713{
714   assert(0);
715}
716
717void psxcd_device::cdcmd_gettn()
718{
719   #ifdef debug_cdrom
720      printf("cdrom: gettn\n");
721   #endif
722
723   assert(driver);
724
725   unsigned char data[3]=
726   {
727      status,
728      decimal_to_bcd(driver->get_first_track()),
729      decimal_to_bcd(driver->get_num_tracks())
730   };
731
732   //stop_read();
733   send_result(intr_acknowledge,data,3);
734}
735
736void psxcd_device::cdcmd_gettd()
737{
738   unsigned char addr[3];
739   driver->get_track_address(bcd_to_decimal(cmdbuf[0]), addr);
740
741   unsigned char data[3]=
742   {
743      status,
744      decimal_to_bcd(addr[0]),
745      decimal_to_bcd(addr[1])
746   };
747
748   #ifdef debug_cdrom
749      printf("cdrom: gettd %02x [%02x %02x %02x]\n",
750                                     cmdbuf[0],
751                                     data[0],
752                                     data[1],
753                                     data[2]);
754   #endif
755
756   //stop_read();
757   send_result(intr_acknowledge,data,3);
758}
759
760void psxcd_device::cdcmd_seekl()
761{
762   #ifdef debug_cdrom
763      printf("cdrom: seekl [%02d:%02d:%02d]\n",loc[0],loc[1],loc[2]);
764   #endif
765
766   curpos[0]=loc[0];
767   curpos[1]=loc[1];
768   curpos[2]=loc[2];
769
770   send_result(intr_acknowledge);
771}
772
773void psxcd_device::cdcmd_seekp()
774{
775   #ifdef debug_cdrom
776      printf("cdrom: seekp\n");
777   #endif
778
779   curpos[0]=loc[0];
780   curpos[1]=loc[1];
781   curpos[2]=loc[2];
782
783   send_result(intr_acknowledge);
784}
785
786void psxcd_device::cdcmd_test()
787{
788   #ifdef debug_cdrom
789      printf("cdrom: test %08x\n",cmdbuf[0]);
790   #endif
791
792   static unsigned char data[4]=
793   {
794      0x95,
795      0x07,
796      0x06,
797      0xff
798   };
799
800   send_result(intr_complete,data,4);
801}
802
803void psxcd_device::cdcmd_id()
804{
805   #ifdef debug_cdrom
806      printf("cdrom: id\n");
807   #endif
808
809   if (! open)
810   {
811      if (driver)
812         open=driver->read_toc();
813   }
814
815   if (open)
816   {
817      static unsigned char gamedata[8] = { 0x08, 0x00, 0x00, 0x00, 'S', 'C', 'E', 'A' };
818      static unsigned char audiodata[8] = { 0x08, 0x90, 0x00, 0x00, 'S', 'C', 'E', 'A' };   // drops into the audio CD player.  08 80 goes to the menu.
819
820      if (cdrom_get_track_type(m_cd, 0) == CD_TRACK_AUDIO)
821      {
822         send_result(intr_acknowledge,audiodata,8);
823      }
824      else
825      {
826         send_result(intr_acknowledge,gamedata,8);
827      }
828   } else
829   {
830      status=status_error|status_shellopen;
831      send_result(intr_diskerror);
832   }
833}
834
835void psxcd_device::cdcmd_reads()
836{
837   curpos[0]=loc[0];
838   curpos[1]=loc[1];
839   curpos[2]=loc[2];
840
841   #ifdef skip_reads
842      #ifdef debug_cdrom
843         log("cdrom: reads [SKIPPING - RETURN COMPLETE]\n");
844      #endif
845
846      send_result(intr_complete);
847   #else
848      #ifdef debug_cdrom
849         printf("cdrom: reads\n");
850      #endif
851
852      stop_read();
853      start_streaming();
854   #endif
855}
856
857void psxcd_device::cdcmd_reset()
858{
859   #ifdef debug_cdrom
860      printf("cdrom: reset\n");
861   #endif
862}
863
864void psxcd_device::cdcmd_readtoc()
865{
866   #ifdef debug_cdrom
867      printf("cdrom: readtoc\n");
868   #endif
869
870   static unsigned char data[4]=
871   {
872      0x00,
873      0x00,
874      0xff,
875      0xfe
876   };
877
878   send_result(intr_complete|0x10,data,2);
879}
880
881//
882//
883//
884
885void psxcd_device::cmd_complete(command_result *res)
886{
887   bool doint=((res->res&0x10)==0);
888   #ifdef debug_cdrom
889   command_result *rf;
890   #endif
891
892   if (doint)
893   {
894      psx_irq_set(machine(), 0x0004);
895   }
896
897   add_result(res);
898
899   #ifdef debug_cdrom
900      if (doint)
901      {
902         printf("cdrom: irq [");
903         for (rf=res_queue; ((rf) && (rf->next)); rf=rf->next);
904            printf("%d ",rf->res);
905         printf("]\n");
906      }
907   #endif
908}
909
910//
911//
912//
913
914void psxcd_device::add_result(command_result *res)
915{
916   command_result *rf;
917
918   if (res_queue)
919   {
920      for (rf=res_queue; rf->next; rf=rf->next);
921      rf->next=res;
922   } else
923   {
924      res_queue=res;
925   }
926
927   res->next=NULL;
928}
929
930//
931//
932//
933
934event *psxcd_device::send_result(const unsigned int res,
935                                          const unsigned char *data,
936                                          const unsigned int sz,
937                                             const unsigned int delay)
938{
939   // Update shell open status
940
941   if (! open)
942   {
943      status=status_error|status_shellopen;
944   }
945   else
946   {
947      if (status&status_shellopen)
948         status=status_standby;
949   }
950
951   // Prepare event
952
953   event *ev=new event;
954   ev->t=delay;
955   ev->type=event_cmd_complete;
956
957   command_result *cr=(command_result *)ev->data;
958
959   cr->res=res;
960   if (sz)
961   {
962      assert(sz<sizeof(cr->data));
963      memcpy(cr->data,data,sz);
964      cr->sz=sz;
965   } else
966   {
967      cr->data[0]=status;
968      cr->sz=1;
969   }
970
971   // Avoid returning results after sector read results -
972   // delay the sector read slightly if necessary
973
974   UINT64 systime = machine().device<cpu_device>("maincpu")->total_cycles();
975   if ((next_read_event) && ((systime+ev->t)>(next_sector_t)))
976   {
977      UINT32 hz = m_sysclock / (delay + 2000);
978      next_read_event->timer->adjust(attotime::from_hz(hz), 0, attotime::never);
979
980      for (int i = 0; i < MAX_PSXCD_TIMERS; i++)
981      {
982         if (m_eventfortimer[i] == next_read_event)
983         {
984            printf("Adjusting timer %d to %d hz]n", i, hz);
985         }
986      }
987   }
988
989   add_system_event(ev);
990   return ev;
991}
992
993//
994//
995//
996
997void psxcd_device::start_dma(UINT8 *mainram, UINT32 size)
998{
999   if ((int)size>secleft)
1000   {
1001      printf("cdrom: dma past end of sector (secleft=%d sz=%d)\n",secleft,size);
1002   }
1003
1004//  printf("cdrom: start dma %d bytes, %d remaining, secptr %p\n", size, secleft, secptr);
1005   #ifdef debug_cdrom
1006   if (size==12)
1007   {
1008      char poo[1024],*pp=poo;
1009      for (unsigned int i=0; i<12; i++)
1010      {
1011         sprintf(pp,"%02x ",secptr[i]);
1012         pp+=3;
1013      }
1014      printf("cdrom: data=%s\n",poo);
1015   }
1016   #endif
1017
1018   memcpy(mainram, secptr, size);
1019   memset(secptr, 0xff, size);
1020
1021   secptr += size;
1022   secleft -= size;
1023
1024   if (secleft<0) secleft=0;
1025   if (secleft==0) sr&=~0x40;
1026}
1027
1028//
1029//
1030//
1031
1032void psxcd_device::prefetch_next_sector()
1033{
1034   unsigned int pos=msf_to_sector(curpos);
1035   assert(driver);
1036   driver->prefetch_sector(pos);
1037}
1038
1039//
1040//
1041//
1042
1043bool psxcd_device::read_next_sector(const bool block)
1044{
1045   unsigned int pos=msf_to_sector(curpos);
1046   unsigned char *buf=&secbuf[sechead*raw_sector_size];
1047   assert(driver);
1048   assert(secin<sector_buffer_size);
1049
1050//  printf("read_next_sector: sec %d, sechead %d, raw_sector_size %d\n", pos, sechead, raw_sector_size);
1051   if (driver->read_sector(pos, buf, block))
1052   {
1053//      printf("buf contents = %02x %02x | %02x %02x\n", buf[0], buf[1], buf[0x20], buf[0x21]);
1054
1055      sechead=(sechead+1)&(sector_buffer_size-1);
1056      secin++;
1057
1058      memcpy(lastsechdr,&secbuf[raw_sector_size*sectail]+12,8);
1059
1060      return true;
1061   } else
1062   {
1063      return false;
1064   }
1065}
1066
1067//
1068//
1069//
1070
1071void psxcd_device::read_sector()
1072{
1073   next_read_event=NULL;
1074
1075   if (status & status_reading)
1076   {
1077      bool isend=false;
1078
1079      if (read_next_sector(false))
1080      {
1081         unsigned char *rawsec;
1082
1083         if ((mode&mode_adpcm) && (streaming))
1084         {
1085            rawsec=&secbuf[raw_sector_size*sectail];
1086            secptr=rawsec+24;
1087            secleft=2048;
1088         }
1089         else
1090         {
1091            rawsec=&secbuf[raw_sector_size*sectail];
1092            secptr=rawsec+secskip;
1093            secleft=secsize;
1094         }
1095
1096         secin--;
1097         sectail=(sectail+1)&(sector_buffer_size-1);
1098
1099         //
1100
1101         bool isxa=false;
1102
1103         subheader *sub=(subheader *)(rawsec+16);
1104
1105         #ifdef dump_subheader
1106            printf("cdrom: subheader file=%02x chan=%02x submode=%02x coding=%02x [%02x%02x%02x%02x]\n",
1107                  sub->file,
1108                  sub->channel,
1109                  sub->submode,
1110                  sub->coding,
1111                  rawsec[0xc],
1112                  rawsec[0xd],
1113                  rawsec[0xe],
1114                  rawsec[0xf]);
1115         #endif
1116
1117         status&=~status_playing;
1118         isxa=((mode&mode_adpcm) && (sub->submode&submode_audio));
1119
1120         if (((mode&mode_channel)==0) ||
1121               ((sub->file==filter_file) && (sub->channel==filter_channel)))
1122         {
1123            if (isxa)
1124            {
1125               if (sub->submode&submode_eof)
1126               {
1127                  isend=true;
1128                  //printf("end of file\n");
1129               }
1130
1131               #ifndef disable_xa_prefetch
1132                  unsigned int cursec=msf_to_sector(curpos);
1133
1134                  if (xa_prefetch_sector==-1)
1135                  {
1136                     xa_prefetch_sector=cursec;
1137                     machine().device<spu_device>("spu")->flush_xa();
1138                  }
1139
1140                  unsigned char *xaptr;
1141                  unsigned int xasecsz;
1142
1143                  while (1)
1144                  {
1145                     int dist=xa_prefetch_sector-cursec;
1146                     if (dist>max_xa_prefetch_distance) break;
1147
1148                     xaptr=driver->get_prefetch_sector(xa_prefetch_sector,&xasecsz);
1149                     if (! xaptr) break;
1150
1151                     switch (xasecsz)
1152                     {
1153                        case 2336:
1154                           break;
1155
1156                        default:
1157                           xaptr+=16;
1158                           break;
1159                     }
1160
1161                     subheader *xasub=(subheader *)xaptr;
1162
1163                     if ((xasub->submode&submode_audio) &&
1164                           (((mode&mode_channel)==0) ||
1165                            ((xasub->file==sub->file) &&
1166                              (xasub->channel==sub->channel))))
1167                     {
1168                        if (! machine().device<spu_device>("spu")->play_xa(xa_prefetch_sector,xaptr))
1169                           break;
1170                     }
1171                     xa_prefetch_sector++;
1172                  }
1173               #else
1174                  machine().device<spu_device>("spu")->play_xa(0,rawsec+16);
1175               #endif
1176
1177               status|=status_playing;
1178            }
1179         }
1180
1181         if ((mode&mode_autopause)==0)
1182            isend=false;
1183
1184         //
1185
1186         curpos[2]++;
1187         if (curpos[2]==75)
1188         {
1189            curpos[2]=0;
1190            curpos[1]++;
1191            if (curpos[1]==60)
1192            {
1193               curpos[1]=0;
1194               curpos[0]++;
1195            }
1196         }
1197
1198         loc[0]=curpos[0];
1199         loc[1]=curpos[1];
1200         loc[2]=curpos[2];
1201
1202         //
1203
1204         command_result *res=new command_result;
1205         res->res=isend?intr_dataend:intr_dataready;
1206         res->data[0]=status;
1207         res->sz=1;
1208
1209         sr|=0x40;
1210
1211         if ((streaming) && (isxa))
1212         {
1213            global_free(res);
1214            res=NULL;
1215         }
1216
1217         if (res)
1218         {
1219            #ifdef debug_cdrom
1220               printf("cdrom:: data ready\n");
1221            #endif
1222
1223            cmd_complete(res);
1224         }
1225      }
1226
1227      if (! isend)
1228      {
1229         unsigned int cyc=read_sector_cycles;
1230         if (mode&mode_double_speed) cyc>>=1;
1231
1232         next_sector_t+=cyc;
1233
1234         event *ev=new event;
1235         ev->t=cyc;
1236         ev->type=event_read_sector;
1237         next_read_event=ev;
1238         add_system_event(ev);
1239
1240         //read_next_sector();
1241      } else
1242      {
1243         printf("autopause xa\n");
1244         stop_read();
1245      }
1246   }
1247}
1248
1249//
1250//
1251//
1252
1253bool psxcd_device::play_cdda_sector(const unsigned int sector,
1254                                                 unsigned char *rawsec)
1255{
1256   bool isdata=true;
1257
1258   if (rawsec[0]!=0)
1259   {
1260      isdata=false;
1261   } else
1262   {
1263      for (int i=0; i<10; i++)
1264         if (rawsec[i+1]!=0xff)
1265         {
1266            isdata=false;
1267            break;
1268         }
1269   }
1270
1271   if (! isdata)
1272   {
1273      return machine().device<spu_device>("spu")->play_cdda(sector,rawsec);
1274   } else
1275   {
1276      return true;
1277   }
1278}
1279
1280//
1281//
1282//
1283
1284void psxcd_device::play_sector()
1285{
1286   next_read_event=NULL;
1287
1288   if (status&status_playing)
1289   {
1290      #ifdef disable_cdda_prefetch
1291      unsigned char *rawsec=&secbuf[raw_sector_size*sectail];
1292      #endif
1293      secin--;
1294      sectail=(sectail+1)&(sector_buffer_size-1);
1295
1296      //
1297
1298      #ifndef disable_cdda_prefetch
1299         unsigned int cursec=msf_to_sector(curpos);
1300
1301         if (cdda_prefetch_sector==-1)
1302         {
1303            cdda_prefetch_sector=cursec;
1304            machine().device<spu_device>("spu")->flush_cdda();
1305         }
1306
1307         unsigned char *cddaptr;
1308//          bool full=false;
1309         unsigned int cddasecsz;
1310
1311         while (1)
1312         {
1313            int dist=cdda_prefetch_sector-cursec;
1314            if (dist>max_cdda_prefetch_distance) break;
1315
1316            cddaptr=driver->get_prefetch_sector(cdda_prefetch_sector,&cddasecsz);
1317            if (! cddaptr) break;
1318
1319            if (! play_cdda_sector(cdda_prefetch_sector,cddaptr))
1320               break;
1321
1322            cdda_prefetch_sector++;
1323         }
1324      #else
1325         play_cdda_sector(0,rawsec);
1326      #endif
1327
1328      //
1329
1330      curpos[2]++;
1331      if (curpos[2]==75)
1332      {
1333         curpos[2]=0;
1334         curpos[1]++;
1335         if (curpos[1]==60)
1336         {
1337            curpos[1]=0;
1338            curpos[0]++;
1339         }
1340      }
1341
1342      loc[0]=curpos[0];
1343      loc[1]=curpos[1];
1344      loc[2]=curpos[2];
1345
1346      //
1347
1348      if (mode&mode_autopause)
1349      {
1350         if (msf_to_sector(loc)>=autopause_sector)
1351         {
1352            printf("autopause cdda\n");
1353
1354            command_result *res=new command_result;
1355            res->res=intr_dataend;
1356            res->data[0]=status_standby;
1357            res->sz=1;
1358            cmd_complete(res);
1359            stop_read();
1360            return;
1361         }
1362      }
1363
1364      if (mode&mode_report)
1365      {
1366         command_result *res=new command_result;
1367         res->res=intr_complete;   //dataready;
1368
1369         res->data[0]=status_playing|status_standby;
1370         res->data[1]=0x01;
1371         res->data[2]=0x80;
1372         res->data[3]=decimal_to_bcd(loc[0]);
1373         res->data[4]=decimal_to_bcd(loc[1])|0x80;
1374         res->data[5]=decimal_to_bcd(loc[2]);
1375
1376         res->sz=8;
1377
1378         cmd_complete(res);
1379      }
1380
1381      unsigned int cyc=read_sector_cycles;
1382
1383      event *ev=new event;
1384      ev->t=next_sector_t - machine().device<cpu_device>("maincpu")->total_cycles();
1385      ev->type=event_play_sector;
1386
1387      next_sector_t+=cyc;
1388
1389      next_read_event=ev;
1390      add_system_event(ev);
1391
1392      read_next_sector();
1393   }
1394}
1395
1396
1397//
1398//
1399//
1400
1401void psxcd_device::preread_sector()
1402{
1403   next_read_event=NULL;
1404
1405   //
1406
1407   event *ev=new event;
1408
1409   unsigned int pos=msf_to_sector(curpos);
1410   unsigned char *buf=&secbuf[sechead*raw_sector_size];
1411   if (! driver->read_sector(pos,buf,false))
1412   {
1413      ev->t=(m_sysclock/60);
1414      ev->type=event_preread_sector;
1415
1416      unsigned int cyc=read_sector_cycles;
1417      if (mode&mode_double_speed) cyc>>=1;
1418      next_sector_t=ev->t+(cyc-preread_delay)+machine().device<cpu_device>("maincpu")->total_cycles();
1419   } else
1420   {
1421      memcpy(lastsechdr,buf+12,8);
1422
1423      //
1424
1425      command_result *res=new command_result;
1426      res->res=intr_complete;
1427      res->data[0]=status;
1428      res->sz=1;
1429
1430      #ifdef debug_cdrom
1431         printf("cdrom: read acknowledge\n");
1432      #endif
1433
1434      cmd_complete(res);
1435
1436      //
1437
1438      ev->t=next_sector_t - machine().device<cpu_device>("maincpu")->total_cycles();
1439      ev->type=event_read_sector;
1440
1441      //read_next_sector();
1442   }
1443
1444   next_read_event=ev;
1445   add_system_event(ev);
1446}
1447
1448//
1449//
1450//
1451
1452void psxcd_device::start_read()
1453{
1454   #ifdef debug_cdrom
1455      printf("cdrom: start read\n");
1456   #endif
1457
1458   assert((status&(status_reading|status_playing))==0);
1459
1460   status|=status_reading;
1461
1462   secin=sechead=sectail=0;
1463   xa_prefetch_sector=-1;
1464
1465   unsigned int cyc=read_sector_cycles;
1466   if (mode&mode_double_speed) cyc>>=1;
1467
1468   INT64 systime=machine().device<cpu_device>("maincpu")->total_cycles();
1469
1470   systime+=start_read_delay;
1471
1472   event *ev=new event;
1473   ev->t=start_read_delay+preread_delay;
1474   ev->type=event_preread_sector;
1475
1476   next_sector_t=systime+cyc;
1477   next_read_event=ev;
1478   add_system_event(ev);
1479
1480   prefetch_next_sector();
1481}
1482
1483//
1484//
1485//
1486
1487void psxcd_device::start_streaming()
1488{
1489   assert(! streaming);
1490
1491   streaming=true;
1492   start_read();
1493}
1494
1495//
1496//
1497//
1498
1499void psxcd_device::start_play()
1500{
1501   #ifdef debug_cdrom
1502      printf("cdrom: start play\n");
1503   #endif
1504
1505   status|=status_playing;
1506
1507   secin=sechead=sectail=0;
1508   cdda_prefetch_sector=-1;
1509
1510   if (mode&mode_autopause)
1511   {
1512      unsigned int pos=msf_to_sector(curpos);
1513      driver->find_track(pos+150,NULL,&autopause_sector);
1514//      printf("pos=%d auto=%d\n",pos,autopause_sector);
1515   }
1516
1517   unsigned int cyc=read_sector_cycles;
1518
1519   next_sector_t=machine().device<cpu_device>("maincpu")->total_cycles()+cyc;
1520
1521   event *ev=new event;
1522   ev->t=next_sector_t - machine().device<cpu_device>("maincpu")->total_cycles();
1523   ev->type=event_play_sector;
1524
1525   next_sector_t+=cyc;
1526
1527   next_read_event=ev;
1528   add_system_event(ev);
1529
1530   read_next_sector();
1531}
1532
1533//
1534//
1535//
1536
1537void psxcd_device::stop_read()
1538{
1539   #ifdef debug_cdrom
1540      if (status&status_reading)
1541         printf("cdrom: stop read\n");
1542   #endif
1543   status&=~(status_reading|status_playing);
1544   streaming=false;
1545
1546   if (next_read_event)
1547   {
1548      next_read_event->timer->adjust(attotime::never, 0, attotime::never);
1549      for (int i = 0; i < MAX_PSXCD_TIMERS; i++)
1550      {
1551         if (m_timers[i] == next_read_event->timer)
1552         {
1553            m_timerinuse[i] = false;
1554            m_eventfortimer[i] = false;
1555            break;
1556         }
1557      }
1558      global_free(next_read_event);
1559      next_read_event=NULL;
1560   }
1561
1562   unsigned int sector=msf_to_sector(curpos);
1563   machine().device<spu_device>("spu")->flush_xa(sector);
1564   machine().device<spu_device>("spu")->flush_cdda(sector);
1565}
1566
1567//
1568//
1569//
1570
1571void psxcd_device::set_driver(cdrom_driver *d)
1572{
1573   char err[1024];
1574
1575   if (d)
1576   {
1577      if (d->is_usable(err,1024))
1578      {
1579         driver=d;
1580         open=false;
1581
1582         if (! first_open)
1583         {
1584            command_result *res=new command_result;
1585            res->res=intr_acknowledge;
1586            res->data[0]=status_standby;
1587            res->sz=1;
1588
1589            cmd_complete(res);
1590
1591            open_nops=10;
1592         }
1593
1594         first_open=false;
1595      }
1596   } else
1597   {
1598      driver=NULL;
1599      open=false;
1600
1601      command_result *res=new command_result;
1602      res->res=intr_acknowledge;
1603      res->data[0]=status_shellopen;
1604      res->sz=1;
1605
1606      cmd_complete(res);
1607   }
1608}
1609
1610//
1611//
1612//
1613void psxcd_device::device_timer(emu_timer &timer, device_timer_id tid, int param, void *ptr)
1614{
1615   event *ev = m_eventfortimer[tid];
1616
1617//  printf("timer %d fired, performing event type %d\n", tid, ev->type);
1618
1619   switch (ev->type)
1620   {
1621      case event_cmd_complete:
1622      {
1623         #ifdef debug_cdrom
1624            printf("cdrom:: event cmd complete\n");
1625         #endif
1626
1627         command_result *res=new command_result;
1628         memcpy(res,ev->data,sizeof(command_result));
1629         cmd_complete(res);
1630         break;
1631      }
1632
1633      case event_preread_sector:
1634         preread_sector();
1635         break;
1636
1637      case event_read_sector:
1638         read_sector();
1639         break;
1640
1641      case event_play_sector:
1642         play_sector();
1643         break;
1644   }
1645
1646   // free the timer
1647//  printf("Freeing timer %d\n", tid);
1648   m_timers[tid]->adjust(attotime::never, 0, attotime::never);
1649   m_timerinuse[tid] = false;
1650   m_eventfortimer[tid] = NULL;
1651
1652   global_free(ev);
1653}
1654
1655void psxcd_device::add_system_event(event *ev)
1656{
1657   emu_timer *timer = NULL;
1658   int tnum = -1;
1659
1660   // allocate a timer for this event
1661   for (int i = 0; i < MAX_PSXCD_TIMERS; i++)
1662   {
1663      if (!m_timerinuse[i])
1664      {
1665         tnum = i;
1666         timer = m_timers[i];
1667         m_timerinuse[i] = true;
1668         m_eventfortimer[i] = ev;
1669         break;
1670      }
1671   }
1672
1673   if (tnum == -1)
1674   {
1675      fatalerror("PSXCD: ran out of timers!\n");
1676   }
1677
1678   // ev->t is in maincpu clock cycles
1679   UINT32 hz = m_sysclock / ev->t;
1680//  printf("add_system_event: event type %d for %d hz (using timer %d)\n", ev->type, hz, tnum);
1681   timer->adjust(attotime::from_hz(hz), tnum, attotime::never);
1682
1683   // back-reference the timer from the event
1684   ev->timer = timer;
1685}
1686
src/mess/machine/psxcd.h
r11460r11461
1#ifndef _included_psxcdrom_
2#define _included_psxcdrom_
3
4#include "imagedev/chd_cd.h"
5#include "psxcddrv.h"
6
7#define MAX_PSXCD_TIMERS   (4)
8
9class event;
10
11//
12//
13//
14
15const int num_commands=0x20;
16
17//
18//
19//
20
21#define PSXCD_TAG   "psxcd"
22
23//**************************************************************************
24//  INTERFACE CONFIGURATION MACROS
25//**************************************************************************
26
27#define MCFG_PSXCD_ADD(_devname) \
28    MCFG_DEVICE_ADD(PSXCD_TAG, PSXCD, 0) \
29   MCFG_PSXCD_DEVNAME(_devname)
30
31#define MCFG_PSXCD_DEVNAME(_name) \
32   psxcd_device::static_set_devname(*device, _name); \
33
34struct psxcd_interface
35{
36};
37
38class psxcd_device : public device_t,
39                     public psxcd_interface
40{
41public:
42
43    psxcd_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
44   // inline configuration helpers
45   static void static_set_devname(device_t &device, const char *devname);
46private:
47   struct command_result
48   {
49      unsigned char data[32], sz, res;
50      command_result *next;
51   };
52
53   static const unsigned int sector_buffer_size=16, default_irq_delay=16000;   //480;  //8000; //2000<<2;
54
55   unsigned char sr,res,ir,cmdmode,
56                        cmdbuf[64],*cbp,
57                        mode,
58                        loc[3],
59                        curpos[3],
60                        secbuf[raw_sector_size*sector_buffer_size],
61                        *secptr,
62                        filter_file,
63                        filter_channel,
64                        lastsechdr[8],
65                        status;
66   int rdp,secsize,secleft,secskip,
67         sechead,sectail,
68         secin;
69   command_result *res_queue,
70                         *cur_res;
71   bool open,
72          streaming,
73          first_open;
74   event *next_read_event;
75   INT64 next_sector_t;
76   unsigned int autopause_sector,
77                      xa_prefetch_sector,
78                      cdda_prefetch_sector;
79
80   cdrom_driver *driver;
81
82   unsigned int start_read_delay,
83                      read_sector_cycles,
84                      preread_delay;
85
86   void write_command(const unsigned char byte);
87
88   struct command_info
89   {
90      void (psxcd_device::*func)();
91      const char *name;
92   };
93
94   void cdcmd_sync();
95   void cdcmd_nop();
96   void cdcmd_setloc();
97   void cdcmd_play();
98   void cdcmd_forward();
99   void cdcmd_backward();
100   void cdcmd_readn();
101   void cdcmd_standby();
102   void cdcmd_stop();
103   void cdcmd_pause();
104   void cdcmd_init();
105   void cdcmd_mute();
106   void cdcmd_demute();
107   void cdcmd_setfilter();
108   void cdcmd_setmode();
109   void cdcmd_getparam();
110   void cdcmd_getlocl();
111   void cdcmd_getlocp();
112   void cdcmd_illegal();
113   void cdcmd_gettn();
114   void cdcmd_gettd();
115   void cdcmd_seekl();
116   void cdcmd_seekp();
117   void cdcmd_test();
118   void cdcmd_id();
119   void cdcmd_reads();
120   void cdcmd_reset();
121   void cdcmd_readtoc();
122
123   static command_info cmd_table[num_commands];
124
125   void cmd_complete(command_result *res);
126   void add_result(command_result *res);
127   event *send_result(const unsigned int res,
128                               const unsigned char *data=NULL,
129                               const unsigned int sz=0,
130                               const unsigned int delay=default_irq_delay);
131
132   void start_read();
133   void start_play();
134   void start_streaming();
135   void stop_read();
136   void read_sector();
137   void prefetch_next_sector();
138   bool read_next_sector(const bool block=true);
139   bool play_cdda_sector(const unsigned int sector, unsigned char *rawsec);
140   void play_sector();
141   void preread_sector();
142
143public:
144   void set_driver(cdrom_driver *d);
145   cdrom_driver *get_driver() const { return driver; }
146
147   virtual void device_start();
148   virtual void device_reset();
149   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
150
151   void start_dma(UINT8 *mainram, UINT32 size);
152
153   unsigned char read_byte(const unsigned int addr);
154   void write_byte(const unsigned int addr, const unsigned char byte);
155
156private:
157   emu_timer *m_timer;
158   UINT32 m_sysclock;
159   const char *m_devname;
160   device_t *m_cddevice;
161   cdrom_file   *m_cd;
162   emu_timer *m_timers[MAX_PSXCD_TIMERS];
163   event *m_eventfortimer[MAX_PSXCD_TIMERS];
164   bool m_timerinuse[MAX_PSXCD_TIMERS];
165   
166   void add_system_event(event *ev);
167};
168
169
170// miniature version of pSX's event class, which we emulate with device timers
171const int max_event_data=64;
172
173class event
174{
175public:
176   UINT64 t;            // expire time
177   unsigned int type;
178   unsigned char data[max_event_data];
179   emu_timer *timer;
180};
181
182
183// device type definition
184extern const device_type PSXCD;
185
186#endif
src/mess/machine/amigafdc.c
r11460r11461
1/****************************************************f***********************
2
3    Amiga floppy disk controller emulation
4
5    - The drive spins at 300 RPM = 1 Rev every 200ms
6    - At 2usec per bit, that's 12500 bytes per track, or 6250 words per track
7    - At 4usec per bit, that's 6250 bytes per track, or 3125 words per track
8    - Each standard amiga sector has 544 words per sector, and 11 sectors per track = 11968 bytes
9    - ( 12500(max) - 11968(actual) ) = 532 per track gap bytes
10
11***************************************************************************/
12
13
14#include "emu.h"
15#include "includes/amiga.h"
16#include "imagedev/flopdrv.h"
17#include "formats/ami_dsk.h"
18#include "amigafdc.h"
19#include "machine/6526cia.h"
20
21
22#define MAX_TRACK_BYTES         12500
23#define ACTUAL_TRACK_BYTES      11968
24#define GAP_TRACK_BYTES         ( MAX_TRACK_BYTES - ACTUAL_TRACK_BYTES )
25#define ONE_SECTOR_BYTES      (544*2)
26#define ONE_REV_TIME         200 /* ms */
27#define MAX_WORDS_PER_DMA_CYCLE   32 /* 64 bytes per dma cycle */
28#define DISK_DETECT_DELAY      1
29#define MAX_TRACKS            160
30#define MAX_MFM_TRACK_LEN      16384
31
32#define NUM_DRIVES 2
33
34/* required prototype */
35static void setup_fdc_buffer( device_t *device,int drive );
36
37/***************************************************************************
38    TYPE DEFINITIONS
39***************************************************************************/
40typedef struct {
41   int motor_on;
42   int side;
43   int dir;
44   int wprot;
45   int disk_changed;
46   device_image_interface *f;
47   UINT32 extinfo[MAX_TRACKS];
48   UINT32 extoffs[MAX_TRACKS];
49   int is_ext_image;
50   int cyl;
51   int tracklen;
52   UINT8 mfm[MAX_MFM_TRACK_LEN];
53   int   cached;
54   emu_timer *rev_timer;
55   emu_timer *sync_timer;
56   emu_timer *dma_timer;
57   int rev_timer_started;
58   int pos;
59   int len;
60   offs_t ptr;
61} fdc_def;
62
63typedef struct _amiga_fdc_t amiga_fdc_t;
64struct _amiga_fdc_t
65{
66   fdc_def fdc_status[NUM_DRIVES];
67
68   /* signals */
69   int fdc_sel;
70   int fdc_dir;
71   int fdc_side;
72   int fdc_step;
73   int fdc_rdy;
74};
75
76/*****************************************************************************
77    INLINE FUNCTIONS
78*****************************************************************************/
79INLINE amiga_fdc_t *get_safe_token(device_t *device)
80{
81   assert(device != NULL);
82   assert(device->type() == AMIGA_FDC);
83
84   return (amiga_fdc_t *)downcast<legacy_device_base *>(device)->token();
85}
86
87static TIMER_CALLBACK(fdc_rev_proc);
88static TIMER_CALLBACK(fdc_dma_proc);
89static TIMER_CALLBACK(fdc_sync_proc);
90static void check_extended_image( device_t *device, int id );
91
92static void amiga_load_proc(device_image_interface &image)
93{
94   amiga_fdc_t *fdc = get_safe_token(image.device().owner());
95   int id = floppy_get_drive(&image.device());
96   fdc->fdc_status[id].disk_changed = DISK_DETECT_DELAY;
97   fdc->fdc_status[id].f = &image;
98   fdc->fdc_status[id].cached = -1;
99   fdc->fdc_status[id].motor_on = 0;
100   fdc->fdc_status[id].rev_timer_started = 0;
101   fdc->fdc_status[id].rev_timer->reset(  );
102   fdc->fdc_status[id].sync_timer->reset(  );
103   fdc->fdc_status[id].dma_timer->reset(  );
104   fdc->fdc_rdy = 0;
105
106   check_extended_image( image.device().owner(), id );
107}
108
109static void amiga_unload_proc(device_image_interface &image)
110{
111   amiga_fdc_t *fdc = get_safe_token(image.device().owner());
112   int id = floppy_get_drive(&image.device());
113   fdc->fdc_status[id].disk_changed = DISK_DETECT_DELAY;
114   fdc->fdc_status[id].f = NULL;
115   fdc->fdc_status[id].cached = -1;
116   fdc->fdc_status[id].motor_on = 0;
117   fdc->fdc_status[id].rev_timer_started = 0;
118   fdc->fdc_status[id].rev_timer->reset(  );
119   fdc->fdc_status[id].sync_timer->reset(  );
120   fdc->fdc_status[id].dma_timer->reset(  );
121   fdc->fdc_rdy = 0;
122}
123
124/*-------------------------------------------------
125    DEVICE_START(amiga_fdc)
126-------------------------------------------------*/
127device_t *amiga_floppy_get_device_child(device_t *device,int drive)
128{
129   switch(drive) {
130      case 0 : return device->subdevice(FLOPPY_0);
131      case 1 : return device->subdevice(FLOPPY_1);
132   }
133   return NULL;
134}
135
136static DEVICE_START(amiga_fdc)
137{
138   amiga_fdc_t *fdc = get_safe_token(device);
139   int id;
140   for(id=0;id<2;id++)
141   {
142      fdc->fdc_status[id].rev_timer = device->machine().scheduler().timer_alloc(FUNC(fdc_rev_proc), (void*)device);
143      fdc->fdc_status[id].dma_timer = device->machine().scheduler().timer_alloc(FUNC(fdc_dma_proc), (void*)device);
144      fdc->fdc_status[id].sync_timer = device->machine().scheduler().timer_alloc(FUNC(fdc_sync_proc), (void*)device);
145      floppy_install_load_proc(amiga_floppy_get_device_child(device, id), amiga_load_proc);
146      floppy_install_unload_proc(amiga_floppy_get_device_child(device, id), amiga_unload_proc);
147      fdc->fdc_status[id].motor_on = 0;
148      fdc->fdc_status[id].side = 0;
149      fdc->fdc_status[id].dir = 0;
150      fdc->fdc_status[id].wprot = 1;
151      fdc->fdc_status[id].cyl = 0;
152      fdc->fdc_status[id].rev_timer_started = 0;
153      fdc->fdc_status[id].cached = -1;
154      fdc->fdc_status[id].pos = 0;
155      fdc->fdc_status[id].len = 0;
156      fdc->fdc_status[id].ptr = 0;
157      fdc->fdc_status[id].f = NULL;
158      fdc->fdc_status[id].is_ext_image = 0;
159      fdc->fdc_status[id].tracklen = MAX_TRACK_BYTES;
160      fdc->fdc_status[id].disk_changed = DISK_DETECT_DELAY;
161      fdc->fdc_status[id].rev_timer->reset(  );
162      fdc->fdc_status[id].sync_timer->reset(  );
163      fdc->fdc_status[id].dma_timer->reset(  );
164      memset( fdc->fdc_status[id].mfm, 0xaa, MAX_MFM_TRACK_LEN );
165   }
166   fdc->fdc_sel = 0x0f;
167   fdc->fdc_dir = 0;
168   fdc->fdc_side = 1;
169   fdc->fdc_step = 1;
170   fdc->fdc_rdy = 0;
171
172}
173
174
175/*-------------------------------------------------
176    DEVICE_RESET(amiga_fdc)
177-------------------------------------------------*/
178
179static DEVICE_RESET(amiga_fdc)
180{
181}
182
183static void check_extended_image( device_t *device, int id )
184{
185   UINT8   header[8], data[4];
186   amiga_fdc_t *fdc = get_safe_token(device);
187
188   fdc->fdc_status[id].is_ext_image = 0;
189
190   if ( fdc->fdc_status[id].f->fseek( 0, SEEK_SET ) )
191   {
192      logerror("FDC: image_fseek failed!\n" );
193      return;
194   }
195
196   fdc->fdc_status[id].f->fread( &header, sizeof( header ) );
197
198   if ( memcmp( header, "UAE--ADF", sizeof( header ) ) == 0 )
199   {
200      int      i;
201
202      for( i = 0; i < MAX_TRACKS; i++ )
203      {
204         fdc->fdc_status[id].f->fread( &data, sizeof( data ) );
205
206         /* data[0,1] = SYNC - data[2,3] = LEN */
207
208         fdc->fdc_status[id].extinfo[i] = data[0];
209         fdc->fdc_status[id].extinfo[i] <<= 8;
210         fdc->fdc_status[id].extinfo[i] |= data[1];
211         fdc->fdc_status[id].extinfo[i] <<= 8;
212         fdc->fdc_status[id].extinfo[i] |= data[2];
213         fdc->fdc_status[id].extinfo[i] <<= 8;
214         fdc->fdc_status[id].extinfo[i] |= data[3];
215
216         if ( i == 0 )
217            fdc->fdc_status[id].extoffs[i] = sizeof( header ) + ( MAX_TRACKS * sizeof( data ) );
218         else
219            fdc->fdc_status[id].extoffs[i] = fdc->fdc_status[id].extoffs[i-1] + ( fdc->fdc_status[id].extinfo[i-1] & 0xffff );
220      }
221
222      fdc->fdc_status[id].is_ext_image = 1;
223   }
224}
225
226static int fdc_get_curpos( device_t *device, int drive )
227{
228   amiga_state *state = device->machine().driver_data<amiga_state>();
229   double elapsed;
230   int speed;
231   int   bytes;
232   int pos;
233   amiga_fdc_t *fdc = get_safe_token(device);
234
235   if ( fdc->fdc_status[drive].rev_timer_started == 0 ) {
236      logerror("Rev timer not started on drive %d, cant get position!\n", drive );
237      return 0;
238   }
239
240   elapsed = fdc->fdc_status[drive].rev_timer ->elapsed( ).as_double();
241   speed = ( CUSTOM_REG(REG_ADKCON) & 0x100 ) ? 2 : 4;
242
243   bytes = elapsed /  attotime::from_usec( speed * 8 ).as_double();
244   pos = bytes % ( fdc->fdc_status[drive].tracklen );
245
246   return pos;
247}
248
249UINT16 amiga_fdc_get_byte (device_t *device)
250{
251   amiga_state *state = device->machine().driver_data<amiga_state>();
252   int pos;
253   int i, drive = -1;
254   UINT16 ret;
255   amiga_fdc_t *fdc = get_safe_token(device);
256
257   ret = ( ( CUSTOM_REG(REG_DSKLEN) >> 1 ) & 0x4000 ) & ( ( CUSTOM_REG(REG_DMACON) << 10 ) & 0x4000 );
258   ret |= ( CUSTOM_REG(REG_DSKLEN) >> 1 ) & 0x2000;
259
260   for ( i = 0; i < NUM_DRIVES; i++ ) {
261      if ( !( fdc->fdc_sel & ( 1 << i ) ) )
262         drive = i;
263   }
264
265   if ( drive == -1 )
266      return ret;
267
268   if ( fdc->fdc_status[drive].disk_changed )
269      return ret;
270
271   setup_fdc_buffer( device,drive );
272
273   pos = fdc_get_curpos( device, drive );
274
275   if ( fdc->fdc_status[drive].mfm[pos] == ( CUSTOM_REG(REG_DSRSYNC) >> 8 ) &&
276       fdc->fdc_status[drive].mfm[pos+1] == ( CUSTOM_REG(REG_DSRSYNC) & 0xff ) )
277         ret |= 0x1000;
278
279   if ( pos != fdc->fdc_status[drive].pos ) {
280      ret |= 0x8000;
281      fdc->fdc_status[drive].pos = pos;
282   }
283
284   ret |= fdc->fdc_status[drive].mfm[pos];
285
286   return ret;
287}
288
289static TIMER_CALLBACK(fdc_sync_proc)
290{
291   amiga_state *state = machine.driver_data<amiga_state>();
292   int drive = param;
293   UINT16         sync = CUSTOM_REG(REG_DSRSYNC);
294   int            cur_pos;
295   int            sector;
296   int            time;
297   amiga_fdc_t *fdc = get_safe_token((device_t*)ptr);
298
299   /* if floppy got ejected, stop */
300   if ( fdc->fdc_status[drive].disk_changed )
301      goto bail;
302
303   if ( fdc->fdc_status[drive].motor_on == 0 )
304      goto bail;
305
306   cur_pos = fdc_get_curpos( (device_t*)ptr, drive );
307
308   if ( cur_pos <= ( GAP_TRACK_BYTES + 6 ) )
309   {
310      sector = 0;
311   }
312   else
313   {
314      sector = ( cur_pos - ( GAP_TRACK_BYTES + 6 ) ) / ONE_SECTOR_BYTES;
315   }
316
317   setup_fdc_buffer( (device_t*)ptr, drive );
318
319   if ( cur_pos < 2 )
320      cur_pos = 2;
321
322   if ( fdc->fdc_status[drive].mfm[cur_pos-2] == ( ( sync >> 8 ) & 0xff ) &&
323       fdc->fdc_status[drive].mfm[cur_pos-1] == ( sync & 0xff ) )
324   {
325      address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
326
327      amiga_custom_w(space, REG_INTREQ, 0x8000 | INTENA_DSKSYN, 0xffff);
328   }
329
330   if ( sector < 10 )
331   {
332      /* start the sync timer */
333      time = ONE_SECTOR_BYTES;
334      time *= ( CUSTOM_REG(REG_ADKCON) & 0x0100 ) ? 2 : 4;
335      time *= 8;
336      fdc->fdc_status[drive].sync_timer->adjust(attotime::from_usec( time ), drive);
337      return;
338   }
339
340bail:
341   fdc->fdc_status[drive].sync_timer->reset(  );
342}
343
344static TIMER_CALLBACK(fdc_dma_proc)
345{
346   amiga_state *state = machine.driver_data<amiga_state>();
347   int drive = param;
348   amiga_fdc_t *fdc = get_safe_token((device_t*)ptr);
349
350   /* if DMA got disabled by the time we got here, stop operations */
351   if ( ( CUSTOM_REG(REG_DSKLEN) & 0x8000 ) == 0 )
352      goto bail;
353
354   if ( ( CUSTOM_REG(REG_DMACON) & 0x0210 ) == 0 )
355      goto bail;
356
357   /* if floppy got ejected, also stop */
358   if ( fdc->fdc_status[drive].disk_changed )
359      goto bail;
360
361   if ( fdc->fdc_status[drive].motor_on == 0 )
362      goto bail;
363
364   setup_fdc_buffer( (device_t*)ptr, drive );
365
366   if ( CUSTOM_REG(REG_DSKLEN) & 0x4000 ) /* disk write case, unsupported yet */
367   {
368      if ( fdc->fdc_status[drive].len > 0 )
369      {
370         address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
371
372         logerror("Write to disk unsupported yet\n" );
373
374         amiga_custom_w(space, REG_INTREQ, 0x8000 | INTENA_DSKBLK, 0xffff);
375      }
376   }
377   else
378   {
379      offs_t offset = fdc->fdc_status[drive].ptr;
380      int cur_pos = fdc->fdc_status[drive].pos;
381      int len = fdc->fdc_status[drive].len;
382
383      if ( len > MAX_WORDS_PER_DMA_CYCLE ) len = MAX_WORDS_PER_DMA_CYCLE;
384
385      fdc->fdc_status[drive].len -= len;
386
387      while ( len-- )
388      {
389         int dat = ( fdc->fdc_status[drive].mfm[cur_pos++] ) << 8;
390
391         cur_pos %= ( fdc->fdc_status[drive].tracklen );
392
393         dat |= fdc->fdc_status[drive].mfm[cur_pos++];
394
395         cur_pos %= ( fdc->fdc_status[drive].tracklen );
396
397         (*state->m_chip_ram_w)(state, offset, dat);
398
399         offset += 2;
400      }
401
402      fdc->fdc_status[drive].ptr = offset;
403      fdc->fdc_status[drive].pos = cur_pos;
404
405      if ( fdc->fdc_status[drive].len <= 0 )
406      {
407         address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
408
409         amiga_custom_w(space, REG_INTREQ, 0x8000 | INTENA_DSKBLK, 0xffff);
410      }
411      else
412      {
413         int time;
414         double   len_words = fdc->fdc_status[drive].len;
415         if ( len_words > MAX_WORDS_PER_DMA_CYCLE ) len_words = MAX_WORDS_PER_DMA_CYCLE;
416
417         time = len_words * 2;
418         time *= ( CUSTOM_REG(REG_ADKCON) & 0x0100 ) ? 2 : 4;
419         time *= 8;
420         fdc->fdc_status[drive].dma_timer->adjust(attotime::from_usec( time ), drive);
421         return;
422      }
423   }
424
425bail:
426   fdc->fdc_status[drive].dma_timer->reset(  );
427}
428
429void amiga_fdc_setup_dma( device_t *device ) {
430   amiga_state *state = device->machine().driver_data<amiga_state>();
431   int i, cur_pos, drive = -1, len_words = 0;
432   int time = 0;
433   amiga_fdc_t *fdc = get_safe_token(device);
434
435   for ( i = 0; i < NUM_DRIVES; i++ ) {
436      if ( !( fdc->fdc_sel & ( 1 << i ) ) )
437         drive = i;
438   }
439
440   if ( drive == -1 ) {
441      address_space *space = device->machine().device("maincpu")->memory().space(AS_PROGRAM);
442
443      logerror("Disk DMA started with no drive selected!\n" );
444      amiga_custom_w(space, REG_INTREQ, 0x8000 | INTENA_DSKBLK, 0xffff);
445      return;
446   }
447
448   if ( ( CUSTOM_REG(REG_DSKLEN) & 0x8000 ) == 0 )
449      goto bail;
450
451   if ( ( CUSTOM_REG(REG_DMACON) & 0x0210 ) == 0 )
452      goto bail;
453
454   if ( fdc->fdc_status[drive].disk_changed )
455      goto bail;
456
457   setup_fdc_buffer( device,drive );
458
459   fdc->fdc_status[drive].len = CUSTOM_REG(REG_DSKLEN) & 0x3fff;
460   fdc->fdc_status[drive].ptr = CUSTOM_REG_LONG(REG_DSKPTH);
461   fdc->fdc_status[drive].pos = cur_pos = fdc_get_curpos( device, drive );
462
463   /* we'll do a set amount at a time */
464   len_words = fdc->fdc_status[drive].len;
465   if ( len_words > MAX_WORDS_PER_DMA_CYCLE ) len_words = MAX_WORDS_PER_DMA_CYCLE;
466
467   if ( CUSTOM_REG(REG_ADKCON) & 0x0400 ) { /* Wait for sync */
468      if ( CUSTOM_REG(REG_DSRSYNC) != 0x4489 ) {
469         logerror("Attempting to read a non-standard SYNC\n" );
470      }
471
472      i = cur_pos;
473      do {
474         if ( fdc->fdc_status[drive].mfm[i] == ( CUSTOM_REG(REG_DSRSYNC) >> 8 ) &&
475             fdc->fdc_status[drive].mfm[i+1] == ( CUSTOM_REG(REG_DSRSYNC) & 0xff ) )
476               break;
477
478         i++;
479         i %= ( fdc->fdc_status[drive].tracklen );
480         time++;
481      } while( i != cur_pos );
482
483      if ( i == cur_pos && time != 0 ) {
484         logerror("SYNC not found on track!\n" );
485         return;
486      } else {
487         fdc->fdc_status[drive].pos = i + 2;
488         time += 2;
489      }
490   }
491
492   time += len_words * 2;
493   time *= ( CUSTOM_REG(REG_ADKCON) & 0x0100 ) ? 2 : 4;
494   time *= 8;
495   fdc->fdc_status[drive].dma_timer->adjust(attotime::from_usec( time ), drive);
496
497   return;
498
499bail:
500   fdc->fdc_status[drive].dma_timer->reset(  );
501}
502
503static void setup_fdc_buffer( device_t *device,int drive )
504{
505   int      sector, offset, len;
506   UINT8   temp_cyl[512*11];
507   amiga_fdc_t *fdc = get_safe_token(device);
508
509   /* no disk in drive */
510   if ( fdc->fdc_status[drive].f == NULL ) {
511      memset( &fdc->fdc_status[drive].mfm[0], 0xaa, 32 );
512      fdc->fdc_status[drive].disk_changed = DISK_DETECT_DELAY;
513      return;
514   }
515
516   len = 512*11;
517
518   offset = ( fdc->fdc_status[drive].cyl << 1 ) | fdc->fdc_side;
519
520   if ( fdc->fdc_status[drive].cached == offset )
521      return;
522
523#if 0
524   popmessage("T:%d S:%d", fdc->fdc_status[drive].cyl, fdc_side );
525#endif
526
527   if ( fdc->fdc_status[drive].is_ext_image )
528   {
529      len = fdc->fdc_status[drive].extinfo[offset] & 0xffff;
530
531      if ( len > ( MAX_MFM_TRACK_LEN - 2 ) )
532         len = MAX_MFM_TRACK_LEN - 2;
533
534      if ( fdc->fdc_status[drive].f->fseek( fdc->fdc_status[drive].extoffs[offset], SEEK_SET ) )
535      {
536         logerror("FDC: image_fseek failed!\n" );
537         fdc->fdc_status[drive].f = NULL;
538         fdc->fdc_status[drive].disk_changed = DISK_DETECT_DELAY;
539         return;
540      }
541
542      /* if SYNC is 0000, then its a regular amiga dos track image */
543      if ( ( fdc->fdc_status[drive].extinfo[offset] >> 16 ) == 0x0000 )
544      {
545         fdc->fdc_status[drive].f->fread( temp_cyl, len );
546         /* fall through to regular load */
547      }
548      else /* otherwise, it's a raw track */
549      {
550         fdc->fdc_status[drive].mfm[0] = ( fdc->fdc_status[drive].extinfo[offset] >> 24 ) & 0xff;
551         fdc->fdc_status[drive].mfm[1] = ( fdc->fdc_status[drive].extinfo[offset] >> 16 ) & 0xff;
552         fdc->fdc_status[drive].f->fread( &fdc->fdc_status[drive].mfm[2], len );
553         fdc->fdc_status[drive].tracklen = len + 2;
554         fdc->fdc_status[drive].cached = offset;
555         return;
556      }
557   }
558   else
559   {
560      if ( fdc->fdc_status[drive].f->fseek( offset * len, SEEK_SET ) )
561      {
562         logerror("FDC: image_fseek failed!\n" );
563         fdc->fdc_status[drive].f = NULL;
564         fdc->fdc_status[drive].disk_changed = DISK_DETECT_DELAY;
565         return;
566      }
567
568      fdc->fdc_status[drive].f->fread( temp_cyl, len );
569   }
570
571   fdc->fdc_status[drive].tracklen = MAX_TRACK_BYTES;
572
573   memset( &fdc->fdc_status[drive].mfm[ONE_SECTOR_BYTES*11], 0xaa, GAP_TRACK_BYTES );
574
575   for ( sector = 0; sector < 11; sector++ ) {
576      int x;
577       UINT8 *dest = ( &fdc->fdc_status[drive].mfm[(ONE_SECTOR_BYTES*sector)] );
578       UINT8 *src = &temp_cyl[sector*512];
579      UINT32 tmp;
580      UINT32 even, odd;
581      UINT32 hck = 0, dck = 0;
582
583      /* Preamble and sync */
584      *(dest + 0) = 0xaa;
585      *(dest + 1) = 0xaa;
586      *(dest + 2) = 0xaa;
587      *(dest + 3) = 0xaa;
588      *(dest + 4) = 0x44;
589      *(dest + 5) = 0x89;
590      *(dest + 6) = 0x44;
591      *(dest + 7) = 0x89;
592
593      /* Track and sector info */
594
595      tmp = 0xff000000 | (offset<<16) | (sector<<8) | (11 - sector);
596      odd = (tmp & 0x55555555) | 0xaaaaaaaa;
597      even = ( ( tmp >> 1 ) & 0x55555555 ) | 0xaaaaaaaa;
598      *(dest +  8) = (UINT8) ((even & 0xff000000)>>24);
599      *(dest +  9) = (UINT8) ((even & 0xff0000)>>16);
600      *(dest + 10) = (UINT8) ((even & 0xff00)>>8);
601      *(dest + 11) = (UINT8) ((even & 0xff));
602      *(dest + 12) = (UINT8) ((odd & 0xff000000)>>24);
603      *(dest + 13) = (UINT8) ((odd & 0xff0000)>>16);
604      *(dest + 14) = (UINT8) ((odd & 0xff00)>>8);
605      *(dest + 15) = (UINT8) ((odd & 0xff));
606
607      /* Fill unused space */
608
609      for (x = 16 ; x < 48; x++)
610         *(dest + x) = 0xaa;
611
612      /* Encode data section of sector */
613
614      for (x = 64 ; x < 576; x++)
615      {
616         tmp = *(src + x - 64);
617         odd = (tmp & 0x55);
618         even = (tmp>>1) & 0x55;
619         *(dest + x) = (UINT8) (even | 0xaa);
620         *(dest + x + 512) = (UINT8) (odd | 0xaa);
621      }
622
623      /* Calculate checksum for unused space */
624
625      for(x = 8; x < 48; x += 4)
626          hck ^= (((UINT32) *(dest + x))<<24) | (((UINT32) *(dest + x + 1))<<16) |
627                (((UINT32) *(dest + x + 2))<<8) | ((UINT32) *(dest + x + 3));
628
629      even = odd = hck;
630      odd >>= 1;
631      even |= 0xaaaaaaaa;
632      odd |= 0xaaaaaaaa;
633
634      *(dest + 48) = (UINT8) ((odd & 0xff000000)>>24);
635      *(dest + 49) = (UINT8) ((odd & 0xff0000)>>16);
636      *(dest + 50) = (UINT8) ((odd & 0xff00)>>8);
637      *(dest + 51) = (UINT8) (odd & 0xff);
638      *(dest + 52) = (UINT8) ((even & 0xff000000)>>24);
639      *(dest + 53) = (UINT8) ((even & 0xff0000)>>16);
640      *(dest + 54) = (UINT8) ((even & 0xff00)>>8);
641      *(dest + 55) = (UINT8) (even & 0xff);
642
643      /* Calculate checksum for data section */
644
645      for(x = 64; x < 1088; x += 4)
646         dck ^= (((UINT32) *(dest + x))<<24) | (((UINT32) *(dest + x + 1))<<16) |
647               (((UINT32) *(dest + x + 2))<< 8) |  ((UINT32) *(dest + x + 3));
648      even = odd = dck;
649      odd >>= 1;
650      even |= 0xaaaaaaaa;
651      odd |= 0xaaaaaaaa;
652      *(dest + 56) = (UINT8) ((odd & 0xff000000)>>24);
653      *(dest + 57) = (UINT8) ((odd & 0xff0000)>>16);
654      *(dest + 58) = (UINT8) ((odd & 0xff00)>>8);
655      *(dest + 59) = (UINT8) (odd & 0xff);
656      *(dest + 60) = (UINT8) ((even & 0xff000000)>>24);
657      *(dest + 61) = (UINT8) ((even & 0xff0000)>>16);
658      *(dest + 62) = (UINT8) ((even & 0xff00)>>8);
659      *(dest + 63) = (UINT8) (even & 0xff);
660   }
661
662   // update MFM data with proper CLK signal
663   int lastbit= 0;
664   for(int i=0;i<MAX_TRACK_BYTES ;i++)
665   {
666      UINT8 c=fdc->fdc_status[drive].mfm[i];
667      UINT8 dat = 0;
668      for(int j=0;j<8;j=j+2)
669      {
670         UINT8 c1=(c>>(6-j))&0x3;
671         if(c1&0x1)
672         {
673            dat |= (0x01<<(6-j));
674            lastbit=1;
675         }
676         else
677         {
678            if(lastbit==0 && (c1&0x2))
679            {
680               dat |= (0x02<<(6-j));
681            }
682            else
683            {
684               dat |= (0x00<<(6-j));
685            }
686            lastbit=0;
687         }
688      }
689      fdc->fdc_status[drive].mfm[i] = dat;
690   }
691   fdc->fdc_status[drive].cached = offset;
692}
693
694static TIMER_CALLBACK(fdc_rev_proc)
695{
696   amiga_state *state = machine.driver_data<amiga_state>();
697   int drive = param;
698   int time;
699   device_t *cia;
700   amiga_fdc_t *fdc = get_safe_token((device_t*)ptr);
701
702   /* Issue a index pulse when a disk revolution completes */
703   cia = machine.device("cia_1");
704   mos6526_flag_w(cia, 0);
705   mos6526_flag_w(cia, 1);
706
707   fdc->fdc_status[drive].rev_timer->adjust(attotime::from_msec( ONE_REV_TIME ), drive);
708   fdc->fdc_status[drive].rev_timer_started = 1;
709
710   if ( fdc->fdc_status[drive].is_ext_image == 0 )
711   {
712      /* also start the sync timer */
713      time = GAP_TRACK_BYTES + 6;
714      time *= ( CUSTOM_REG(REG_ADKCON) & 0x0100 ) ? 2 : 4;
715      time *= 8;
716      fdc->fdc_status[drive].sync_timer->adjust(attotime::from_usec( time ), drive);
717   }
718}
719
720static void start_rev_timer( device_t *device,int drive ) {
721//  double time;
722   amiga_fdc_t *fdc = get_safe_token(device);
723
724   if ( fdc->fdc_status[drive].rev_timer_started ) {
725      logerror("Revolution timer started twice?!\n" );
726      return;
727   }
728
729   fdc->fdc_status[drive].rev_timer->adjust(attotime::from_msec( ONE_REV_TIME ), drive);
730   fdc->fdc_status[drive].rev_timer_started = 1;
731}
732
733static void stop_rev_timer( device_t *device,int drive ) {
734   amiga_fdc_t *fdc = get_safe_token(device);
735
736   if ( fdc->fdc_status[drive].rev_timer_started == 0 ) {
737      logerror("Revolution timer never started?!\n" );
738      return;
739   }
740
741   fdc->fdc_status[drive].rev_timer->reset(  );
742   fdc->fdc_status[drive].rev_timer_started = 0;
743   fdc->fdc_status[drive].dma_timer->reset(  );
744   fdc->fdc_status[drive].sync_timer->reset(  );
745}
746
747static void fdc_setup_leds(device_t *device, int drive ) {
748
749   char portname[12];
750   amiga_fdc_t *fdc = get_safe_token(device);
751   sprintf(portname, "drive_%d_led", drive);
752   output_set_value(portname, fdc->fdc_status[drive].motor_on == 0 ? 0 : 1);
753
754   if ( drive == 0 )
755      set_led_status(device->machine(), 1, fdc->fdc_status[drive].motor_on ); /* update internal drive led */
756
757   if ( drive == 1 )
758      set_led_status(device->machine(), 2, fdc->fdc_status[drive].motor_on ); /* update external drive led */
759}
760
761static void fdc_stepdrive( device_t *device,int drive ) {
762   amiga_fdc_t *fdc = get_safe_token(device);
763
764   if ( fdc->fdc_dir ) {
765      if ( fdc->fdc_status[drive].cyl )
766         fdc->fdc_status[drive].cyl--;
767   } else {
768      if ( fdc->fdc_status[drive].cyl < 79 )
769         fdc->fdc_status[drive].cyl++;
770   }
771
772   /* Update disk detection if applicable */
773   if ( fdc->fdc_status[drive].f != NULL )
774   {
775      if ( fdc->fdc_status[drive].disk_changed > 0 )
776         fdc->fdc_status[drive].disk_changed--;
777   }
778}
779
780static void fdc_motor( device_t *device,int drive, int off ) {
781   amiga_fdc_t *fdc = get_safe_token(device);
782   int on = !off;
783
784   if ( ( fdc->fdc_status[drive].motor_on == 0 ) && on ) {
785      fdc->fdc_status[drive].pos = 0;
786
787      start_rev_timer( device,drive );
788
789   } else {
790      if ( fdc->fdc_status[drive].motor_on && off )
791         stop_rev_timer(device, drive );
792   }
793
794   fdc->fdc_status[drive].motor_on = on;
795}
796
797WRITE8_DEVICE_HANDLER( amiga_fdc_control_w )
798{
799   int step_pulse;
800   int drive;
801
802   amiga_fdc_t *fdc = get_safe_token(device);
803
804   if ( fdc->fdc_sel != ( ( data >> 3 ) & 15 ) )
805      fdc->fdc_rdy = 0;
806
807   fdc->fdc_sel = ( data >> 3 ) & 15;
808    fdc->fdc_side = 1 - ( ( data >> 2 ) & 1 );
809   fdc->fdc_dir = ( data >> 1 ) & 1;
810
811   step_pulse = data & 1;
812
813    if ( fdc->fdc_step != step_pulse ) {
814      fdc->fdc_step = step_pulse;
815
816       if ( fdc->fdc_step == 0 ) {
817          for ( drive = 0; drive < NUM_DRIVES; drive++ ) {
818            if ( !( fdc->fdc_sel & ( 1 << drive ) ) )
819                fdc_stepdrive( device, drive );
820         }
821      }
822   }
823
824   for ( drive = 0; drive < NUM_DRIVES; drive++ ) {
825      if ( !( fdc->fdc_sel & ( 1 << drive ) ) ) {
826         fdc_motor( device, drive, ( data >> 7 ) & 1 );
827         fdc_setup_leds( device,drive );
828      }
829    }
830}
831
832UINT8  amiga_fdc_status_r (device_t *device)
833{
834   int drive = -1, ret = 0x3c;
835   amiga_fdc_t *fdc = get_safe_token(device);
836   for ( drive = 0; drive < NUM_DRIVES; drive++ ) {
837      if ( !( fdc->fdc_sel & ( 1 << drive ) ) ) {
838
839         if ( fdc->fdc_status[drive].motor_on ) {
840            if ( fdc->fdc_rdy ) ret &= ~0x20;
841            fdc->fdc_rdy = 1;
842         } else {
843            /* return drive id */
844            ret &= ~0x20;
845         }
846
847         if ( fdc->fdc_status[drive].cyl == 0 )
848            ret &= ~0x10;
849
850         if ( fdc->fdc_status[drive].wprot )
851            ret &= ~0x08;
852
853         if ( fdc->fdc_status[drive].disk_changed )
854            ret &= ~0x04;
855
856         return ret;
857      }
858   }
859
860   return ret;
861}
862
863static const floppy_config amiga_floppy_config =
864{
865   DEVCB_NULL,
866   DEVCB_NULL,
867   DEVCB_NULL,
868   DEVCB_NULL,
869   DEVCB_NULL,
870   FLOPPY_STANDARD_3_5_DSHD,
871   FLOPPY_OPTIONS_NAME(amiga_only),
872   NULL
873};
874
875static MACHINE_CONFIG_FRAGMENT( amiga_fdc )
876   MCFG_FLOPPY_2_DRIVES_ADD(amiga_floppy_config)
877MACHINE_CONFIG_END
878
879
880DEVICE_GET_INFO( amiga_fdc )
881{
882   switch (state)
883   {
884      /* --- the following bits of info are returned as 64-bit signed integers --- */
885      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                                    break;
886      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(amiga_fdc_t);                        break;
887
888      /* --- the following bits of info are returned as pointers --- */
889      case DEVINFO_PTR_MACHINE_CONFIG:            info->machine_config = MACHINE_CONFIG_NAME(amiga_fdc);      break;
890
891      /* --- the following bits of info are returned as pointers to data or functions --- */
892      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(amiga_fdc);               break;
893      case DEVINFO_FCT_STOP:                     /* Nothing */                                    break;
894      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(amiga_fdc);               break;
895
896      /* --- the following bits of info are returned as NULL-terminated strings --- */
897      case DEVINFO_STR_NAME:                     strcpy(info->s, "Amiga FDC");                        break;
898      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "Amiga FDC");                        break;
899      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                              break;
900      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);                           break;
901      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright the MESS Team");             break;
902   }
903}
904
905DEFINE_LEGACY_DEVICE(AMIGA_FDC, amiga_fdc);
src/mess/machine/amigakbd.c
r11460r11461
1/***************************************************************************
2
3    Amiga keyboard controller emulation
4
5***************************************************************************/
6
7
8#include "emu.h"
9#include "includes/amiga.h"
10#include "amigakbd.h"
11#include "machine/6526cia.h"
12
13
14#define KEYBOARD_BUFFER_SIZE   256
15
16typedef struct
17{
18   UINT8 *buf;
19   int buf_pos;
20   int cur_pos;
21   emu_timer *timer;
22} amigakbd_t;
23static amigakbd_t kbd;
24
25static void kbd_sendscancode( running_machine &machine, UINT8 scancode )
26{
27   int j;
28   device_t *cia = machine.device("cia_0");
29
30   /* send over to the cia A */
31   for( j = 0; j < 8; j++ )
32   {
33      mos6526_cnt_w( cia, 0 );   /* lower cnt */
34      mos6526_sp_w( cia, BIT(scancode << j, 7) ); /* set the serial data */
35      mos6526_cnt_w( cia, 1 );   /* raise cnt */
36   }
37}
38
39static TIMER_CALLBACK( kbd_update_callback )
40{
41   UINT8   scancode;
42
43   (void)param;
44
45   /* if we don't have pending data, bail */
46
47   if ( kbd.buf_pos == kbd.cur_pos )
48      return;
49
50   /* fetch the next scan code and send it to the Amiga */
51   scancode = kbd.buf[kbd.cur_pos++];
52   kbd.cur_pos %= KEYBOARD_BUFFER_SIZE;
53   kbd_sendscancode( machine, scancode );
54
55   /* if we still have more data, schedule another update */
56   if ( kbd.buf_pos != kbd.cur_pos )
57   {
58      kbd.timer->adjust(machine.primary_screen->frame_period() / 4);
59   }
60}
61
62static INPUT_CHANGED( kbd_update )
63{
64   int   index = (int)(FPTR)param, i;
65   UINT32   oldvalue = oldval * field->mask, newvalue = newval * field->mask;
66   UINT32   delta = oldvalue ^ newvalue;
67
68   /* Special case Page UP, which we will use as Action Replay button */
69   if ( (index == 3) && ( delta & 0x80000000 ) && ( newvalue & 0x80000000 ) )
70   {
71      const amiga_machine_interface *amiga_intf = amiga_get_interface(field->port->machine());
72
73      if ( amiga_intf != NULL && amiga_intf->nmi_callback )
74      {
75         (*amiga_intf->nmi_callback)(field->port->machine());
76      }
77   }
78   else
79   {
80      int key_buf_was_empty = ( kbd.buf_pos == kbd.cur_pos ) ? 1 : 0;
81
82      for( i = 0; i < 32; i++ )
83      {
84         if ( delta & ( 1 << i ) )
85         {
86            int down = ( newvalue & ( 1 << i ) ) ? 0 : 1;
87            int scancode = ( ( (index*32)+i ) << 1 ) | down;
88            int amigacode = ~scancode;
89
90            /* add the keycode to the buffer */
91            kbd.buf[kbd.buf_pos++] = amigacode & 0xff;
92            kbd.buf_pos %= KEYBOARD_BUFFER_SIZE;
93         }
94      }
95
96      /* if the buffer was empty and we have new data, start a timer to send the keystrokes */
97      if ( key_buf_was_empty && ( kbd.buf_pos != kbd.cur_pos ) )
98      {
99         kbd.timer->adjust(field->port->machine().primary_screen->frame_period() / 4);
100      }
101   }
102}
103
104void amigakbd_init( running_machine &machine )
105{
106   /* allocate a keyboard buffer */
107   kbd.buf = auto_alloc_array(machine, UINT8, KEYBOARD_BUFFER_SIZE);
108   kbd.buf_pos = 0;
109   kbd.cur_pos = 0;
110   kbd.timer = machine.scheduler().timer_alloc(FUNC(kbd_update_callback));
111   kbd.timer->reset();
112}
113
114/*********************************************************************************************/
115
116/* Layout is for the US A500 keyboard */
117
118INPUT_PORTS_START( amiga_us_keyboard )
119   PORT_START("amiga_keyboard_0")
120   PORT_BIT( 0x00000001, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_TILDE) PORT_CHAR('`') PORT_CHAR('~')      // 00
121   PORT_BIT( 0x00000002, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')         // 01
122   PORT_BIT( 0x00000004, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('@')         // 02
123   PORT_BIT( 0x00000008, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')         // 03
124   PORT_BIT( 0x00000010, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')         // 04
125   PORT_BIT( 0x00000020, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')         // 05
126   PORT_BIT( 0x00000040, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('^')         // 06
127   PORT_BIT( 0x00000080, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('&')         // 07
128   PORT_BIT( 0x00000100, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_CHAR('*')         // 08
129   PORT_BIT( 0x00000200, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_9) PORT_CHAR('9') PORT_CHAR('(')         // 09
130   PORT_BIT( 0x00000400, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_0) PORT_CHAR('0') PORT_CHAR(')')         // 0A
131   PORT_BIT( 0x00000800, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_MINUS) PORT_CHAR('-') PORT_CHAR('_')      // 0B
132   PORT_BIT( 0x00001000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_EQUALS) PORT_CHAR('=') PORT_CHAR('+')      // 0C
133   PORT_BIT( 0x00002000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_BACKSLASH2) PORT_CHAR('\\') PORT_CHAR('\xA6')   // 0D
134   PORT_BIT( 0x00004000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 0)                           // 0E
135   PORT_BIT( 0x00008000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_0_PAD) PORT_CHAR(UCHAR_MAMEKEY(0_PAD))   // 0F
136   PORT_BIT( 0x00010000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_Q) PORT_CHAR('q') PORT_CHAR('Q')         // 10
137   PORT_BIT( 0x00020000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_W) PORT_CHAR('w') PORT_CHAR('W')         // 11
138   PORT_BIT( 0x00040000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_E) PORT_CHAR('e') PORT_CHAR('E')         // 12
139   PORT_BIT( 0x00080000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_R) PORT_CHAR('r') PORT_CHAR('R')         // 13
140   PORT_BIT( 0x00100000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_T) PORT_CHAR('t') PORT_CHAR('T')         // 14
141   PORT_BIT( 0x00200000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_Y) PORT_CHAR('y') PORT_CHAR('Y')         // 15
142   PORT_BIT( 0x00400000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_U) PORT_CHAR('u') PORT_CHAR('U')         // 16
143   PORT_BIT( 0x00800000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_I) PORT_CHAR('i') PORT_CHAR('I')         // 17
144   PORT_BIT( 0x01000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_O) PORT_CHAR('o') PORT_CHAR('O')         // 18
145   PORT_BIT( 0x02000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_P) PORT_CHAR('p') PORT_CHAR('P')         // 19
146   PORT_BIT( 0x04000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_OPENBRACE) PORT_CHAR('[') PORT_CHAR('{')   // 1A
147   PORT_BIT( 0x08000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_CLOSEBRACE) PORT_CHAR(']') PORT_CHAR('}')   // 1B
148   PORT_BIT( 0x10000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 0)                           // 1C
149   PORT_BIT( 0x20000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_1_PAD) PORT_CHAR(UCHAR_MAMEKEY(1_PAD))   // 1D
150   PORT_BIT( 0x40000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_2_PAD) PORT_CHAR(UCHAR_MAMEKEY(2_PAD))   // 1E
151   PORT_BIT( 0x80000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 0) PORT_CODE(KEYCODE_3_PAD) PORT_CHAR(UCHAR_MAMEKEY(3_PAD))   // 1F
152
153   PORT_START("amiga_keyboard_1")
154   PORT_BIT( 0x00000001, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_A) PORT_CHAR('a') PORT_CHAR('A')         // 20
155   PORT_BIT( 0x00000002, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_S) PORT_CHAR('s') PORT_CHAR('S')         // 21
156   PORT_BIT( 0x00000004, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_D) PORT_CHAR('d') PORT_CHAR('D')         // 22
157   PORT_BIT( 0x00000008, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_F) PORT_CHAR('f') PORT_CHAR('F')         // 23
158   PORT_BIT( 0x00000010, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_G) PORT_CHAR('g') PORT_CHAR('G')         // 24
159   PORT_BIT( 0x00000020, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_H) PORT_CHAR('h') PORT_CHAR('H')         // 25
160   PORT_BIT( 0x00000040, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_J) PORT_CHAR('j') PORT_CHAR('J')         // 26
161   PORT_BIT( 0x00000080, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_K) PORT_CHAR('k') PORT_CHAR('K')         // 27
162   PORT_BIT( 0x00000100, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_L) PORT_CHAR('l') PORT_CHAR('L')         // 28
163   PORT_BIT( 0x00000200, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_COLON) PORT_CHAR(';') PORT_CHAR(':')      // 29
164   PORT_BIT( 0x00000400, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR('\'') PORT_CHAR('"')      // 2A
165   PORT_BIT( 0x00000800, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 1)                           // 2B
166   PORT_BIT( 0x00001000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 1)                           // 2C
167   PORT_BIT( 0x00002000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_4_PAD) PORT_CHAR(UCHAR_MAMEKEY(4_PAD))   // 2D
168   PORT_BIT( 0x00004000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_5_PAD) PORT_CHAR(UCHAR_MAMEKEY(5_PAD))   // 2E
169   PORT_BIT( 0x00008000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_6_PAD) PORT_CHAR(UCHAR_MAMEKEY(6_PAD))   // 2F
170   PORT_BIT( 0x00010000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 1)                           // 30
171   PORT_BIT( 0x00020000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_Z) PORT_CHAR('z') PORT_CHAR('Z')         // 31
172   PORT_BIT( 0x00040000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_X) PORT_CHAR('x') PORT_CHAR('X')         // 32
173   PORT_BIT( 0x00080000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_C) PORT_CHAR('c') PORT_CHAR('C')         // 33
174   PORT_BIT( 0x00100000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_V) PORT_CHAR('v') PORT_CHAR('V')         // 34
175   PORT_BIT( 0x00200000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_B) PORT_CHAR('b') PORT_CHAR('B')         // 35
176   PORT_BIT( 0x00400000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_N) PORT_CHAR('n') PORT_CHAR('N')         // 36
177   PORT_BIT( 0x00800000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_M) PORT_CHAR('m') PORT_CHAR('M')         // 37
178   PORT_BIT( 0x01000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_COMMA) PORT_CHAR(',') PORT_CHAR('<')      // 38
179   PORT_BIT( 0x02000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_STOP)    PORT_CHAR('.') PORT_CHAR('>')      // 39
180   PORT_BIT( 0x04000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_SLASH) PORT_CHAR('/') PORT_CHAR('?')      // 3A
181   PORT_BIT( 0x08000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 1)                           // 3B
182   PORT_BIT( 0x10000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_DEL_PAD) PORT_CHAR(UCHAR_MAMEKEY(DEL_PAD))// 3C
183   PORT_BIT( 0x20000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_7_PAD) PORT_CHAR(UCHAR_MAMEKEY(7_PAD))   // 3D
184   PORT_BIT( 0x40000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_8_PAD) PORT_CHAR(UCHAR_MAMEKEY(8_PAD))   // 3E
185   PORT_BIT( 0x80000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 1) PORT_CODE(KEYCODE_9_PAD) PORT_CHAR(UCHAR_MAMEKEY(9_PAD))   // 3F
186
187   PORT_START("amiga_keyboard_2")
188   PORT_BIT( 0x00000001, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_SPACE) PORT_CHAR(' ')                  // 40
189   PORT_BIT( 0x00000002, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_BACKSPACE) PORT_CHAR(8)               // 41
190   PORT_BIT( 0x00000004, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_TAB) PORT_CHAR('\t')                  // 42
191   PORT_BIT( 0x00000008, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_ENTER_PAD) PORT_CHAR(UCHAR_MAMEKEY(ENTER_PAD))   // 43
192   PORT_BIT( 0x00000010, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)                  // 44
193   PORT_BIT( 0x00000020, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_ESC) PORT_CHAR(UCHAR_MAMEKEY(ESC))      // 45
194   PORT_BIT( 0x00000040, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_DEL) PORT_CHAR(UCHAR_MAMEKEY(DEL))      // 46
195   PORT_BIT( 0x00000080, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 2)                           // 47
196   PORT_BIT( 0x00000100, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 2)                           // 48
197   PORT_BIT( 0x00000200, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 2)                           // 49
198   PORT_BIT( 0x00000400, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_MINUS_PAD) PORT_CHAR(UCHAR_MAMEKEY(MINUS_PAD))   // 4A
199   PORT_BIT( 0x00000800, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 2)                           // 4B
200   PORT_BIT( 0x00001000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_UP) PORT_CHAR(UCHAR_MAMEKEY(UP))         // 4C
201   PORT_BIT( 0x00002000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_DOWN) PORT_CHAR(UCHAR_MAMEKEY(DOWN))      // 4D
202   PORT_BIT( 0x00004000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_RIGHT) PORT_CHAR(UCHAR_MAMEKEY(RIGHT))   // 4E
203   PORT_BIT( 0x00008000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_LEFT) PORT_CHAR(UCHAR_MAMEKEY(LEFT))      // 4F
204   PORT_BIT( 0x00010000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F1) PORT_CHAR(UCHAR_MAMEKEY(F1))         // 50
205   PORT_BIT( 0x00020000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F2) PORT_CHAR(UCHAR_MAMEKEY(F2))         // 51
206   PORT_BIT( 0x00040000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F3) PORT_CHAR(UCHAR_MAMEKEY(F3))         // 52
207   PORT_BIT( 0x00080000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F4) PORT_CHAR(UCHAR_MAMEKEY(F4))         // 53
208   PORT_BIT( 0x00100000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F5) PORT_CHAR(UCHAR_MAMEKEY(F5))         // 54
209   PORT_BIT( 0x00200000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F6) PORT_CHAR(UCHAR_MAMEKEY(F6))         // 55
210   PORT_BIT( 0x00400000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F7) PORT_CHAR(UCHAR_MAMEKEY(F7))         // 56
211   PORT_BIT( 0x00800000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F8) PORT_CHAR(UCHAR_MAMEKEY(F8))         // 57
212   PORT_BIT( 0x01000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F9) PORT_CHAR(UCHAR_MAMEKEY(F9))         // 58
213   PORT_BIT( 0x02000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_F10) PORT_CHAR(UCHAR_MAMEKEY(F10))      // 59
214   PORT_BIT( 0x04000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 2)                           // 5A
215   PORT_BIT( 0x08000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 2)                           // 5B
216   PORT_BIT( 0x10000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_SLASH_PAD) PORT_CHAR(UCHAR_MAMEKEY(SLASH_PAD))   // 5C
217   PORT_BIT( 0x20000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_ASTERISK) PORT_CHAR(UCHAR_MAMEKEY(ASTERISK))   // 5D
218   PORT_BIT( 0x40000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_PLUS_PAD) PORT_CHAR(UCHAR_MAMEKEY(PLUS_PAD))   // 5E
219   PORT_BIT( 0x80000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 2) PORT_CODE(KEYCODE_INSERT) PORT_CHAR(UCHAR_MAMEKEY(INSERT))   // 5F
220
221   PORT_START("amiga_keyboard_3")
222   PORT_BIT( 0x00000001, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3) PORT_NAME("Shift (Left)") PORT_CODE(KEYCODE_LSHIFT) PORT_CHAR(UCHAR_SHIFT_1)   // 60
223   PORT_BIT( 0x00000002, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3) PORT_NAME("Shift (Right)") PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)   // 61
224   PORT_BIT( 0x00000004, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3) PORT_NAME("Caps Lock") PORT_CODE(KEYCODE_CAPSLOCK)         // 62
225   PORT_BIT( 0x00000008, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3) PORT_NAME("Ctrl") PORT_CODE(KEYCODE_LCONTROL) PORT_CHAR(UCHAR_MAMEKEY(LCONTROL))// 63
226   PORT_BIT( 0x00000010, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3) PORT_NAME("Alt (Left)") PORT_CODE(KEYCODE_LALT) PORT_CHAR(UCHAR_MAMEKEY(LALT))   // 64
227   PORT_BIT( 0x00000020, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3) PORT_NAME("Alt (Right)") PORT_CODE(KEYCODE_RALT) PORT_CHAR(UCHAR_MAMEKEY(RALT))   // 65
228   PORT_BIT( 0x00000040, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3) PORT_NAME("Amiga A (Left)") PORT_CODE(KEYCODE_LWIN)            // 66
229   PORT_BIT( 0x00000080, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3) PORT_NAME("Amiga A (Right)")  PORT_CODE(KEYCODE_RWIN)         // 67
230   PORT_BIT( 0x00000100, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 68
231   PORT_BIT( 0x00000200, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 69
232   PORT_BIT( 0x00000400, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 6A
233   PORT_BIT( 0x00000800, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 6B
234   PORT_BIT( 0x00001000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 6C
235   PORT_BIT( 0x00002000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 6D
236   PORT_BIT( 0x00004000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 6E
237   PORT_BIT( 0x00008000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 6F
238   PORT_BIT( 0x00010000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 70
239   PORT_BIT( 0x00020000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 71
240   PORT_BIT( 0x00040000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 72
241   PORT_BIT( 0x00080000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 73
242   PORT_BIT( 0x00100000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 74
243   PORT_BIT( 0x00200000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 75
244   PORT_BIT( 0x00400000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 76
245   PORT_BIT( 0x00800000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 77
246   PORT_BIT( 0x01000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 78
247   PORT_BIT( 0x02000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 79
248   PORT_BIT( 0x04000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 7A
249   PORT_BIT( 0x08000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 7B
250   PORT_BIT( 0x10000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 7C
251   PORT_BIT( 0x20000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 7D
252   PORT_BIT( 0x40000000, IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CHANGED(kbd_update, 3)                           // 7E
253   PORT_BIT( 0x80000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CHANGED(kbd_update, 3)   PORT_CODE(KEYCODE_PGUP)         // 7F NMI button
254INPUT_PORTS_END
src/mess/machine/amigafdc.h
r11460r11461
1#ifndef AMIGAFDC_H
2#define AMIGAFDC_H
3
4WRITE8_DEVICE_HANDLER( amiga_fdc_control_w );
5UINT8  amiga_fdc_status_r (device_t *device);
6UINT16 amiga_fdc_get_byte (device_t *device);
7void amiga_fdc_setup_dma( device_t *device );
8
9/***************************************************************************
10    MACROS
11***************************************************************************/
12
13DECLARE_LEGACY_DEVICE(AMIGA_FDC, amiga_fdc);
14
15#define MCFG_AMIGA_FDC_ADD(_tag)   \
16   MCFG_DEVICE_ADD((_tag),  AMIGA_FDC, 0)
17
18#endif /* AMIGAFDC_H */
src/mess/machine/matsucd.c
r11460r11461
1/***************************************************************************
2
3    Matsushita/Panasonic CDR521/522 type CDROM drive emulation
4
5Notes:
6This version implements the drive found in Amiga CDTV. There are
7different drives supporting this command-set (look in the sbpcd driver
8in Linux for examples). Most drives support the exact same command
9structure, but the command numbers differ. Eventually this driver
10can be expanded with support for the other drives as needed.
11
12***************************************************************************/
13
14
15#include "emu.h"
16#include "imagedev/chd_cd.h"
17#include "sound/cdda.h"
18#include "machine/matsucd.h"
19
20
21#define MATSU_STATUS_READY      ( 1 << 0 )   /* driver ready */
22#define MATSU_STATUS_DOORLOCKED   ( 1 << 1 )   /* door locked */
23#define MATSU_STATUS_PLAYING   ( 1 << 2 )   /* drive playing */
24#define MATSU_STATUS_SUCCESS   ( 1 << 3 )   /* last command was succesful */
25#define MATSU_STATUS_ERROR      ( 1 << 4 )   /* last command failed */
26#define MATSU_STATUS_MOTOR      ( 1 << 5 )   /* spinning */
27#define MATSU_STATUS_MEDIA      ( 1 << 6 )   /* media present (in caddy or tray) */
28#define MATSU_STATUS_DOORCLOSED   ( 1 << 7 )   /* tray status */
29
30typedef struct
31{
32   UINT8   enabled;      /* /ENABLE - Unit enabled */
33   UINT8   cmd_signal;      /* /CMD - Command mode   */
34   UINT8   stch_signal;   /* /STCH - Status Changed */
35   UINT8   sten_signal;   /* /STEN - Status Enabled */
36   UINT8   scor_signal;   /* /STEN - Subcode Ready */
37   UINT8   input[16];
38   UINT8   input_pos;
39   UINT8   output[16];
40   UINT8   output_pos;
41   UINT8   output_len;
42   UINT8   status;
43   UINT8   motor;
44   UINT16   sector_size;
45   UINT32   lba;
46   UINT16   num_blocks;
47   UINT16   xfer_offset;
48   UINT8   sector_buffer[CD_MAX_SECTOR_DATA];
49   UINT8   cdda_set;
50   void (*sten_cb)( running_machine &machine, int level );   /* Status enabled callback */
51   void (*stch_cb)( running_machine &machine, int level );   /* Status changed callback */
52   void (*scor_cb)( running_machine &machine, int level );   /* Subcode ready callback */
53   cdrom_file *cdrom;
54   device_t *cdda;
55   emu_timer *frame_timer;
56} matsucd;
57
58static matsucd cd;
59
60#define MSF2LBA(msf) (((msf >> 16) & 0xff) * 60 * 75 + ((msf >> 8) & 0xff) * 75 + ((msf >> 0) & 0xff))
61#define LBA2MSF(lba) (((lba / (75 * 60)) << 16) | (((lba / 75) % 60) << 8) | (lba % 75))
62
63static TIMER_CALLBACK(matsu_subcode_proc);
64
65void matsucd_init( device_t *cdrom_device, const char *cdda_tag )
66{
67   memset(&cd, 0, sizeof( matsucd ) );
68
69   cd.cdrom = cd_get_cdrom_file( cdrom_device );
70   cd.cdda = cdrom_device->machine().device(cdda_tag);
71
72   cd.frame_timer = cdrom_device->machine().scheduler().timer_alloc(FUNC(matsu_subcode_proc));
73
74   cd.stch_signal = 1;
75}
76
77void matsucd_set_status_enabled_callback( void (*sten_cb)( running_machine &machine, int level ) )
78{
79   /* add the callback for status enabled signal */
80   cd.sten_cb = sten_cb;
81}
82
83void matsucd_set_status_changed_callback( void (*stch_cb)( running_machine &machine, int level ) )
84{
85   /* add the callback for status changed signal */
86   cd.stch_cb = stch_cb;
87}
88
89void matsucd_set_subcode_ready_callback( void (*scor_cb)( running_machine &machine, int level ) )
90{
91   /* add the callback for subcode ready signal */
92   cd.scor_cb = scor_cb;
93}
94
95static int matsucd_getsector_type( void )
96{
97   switch( cd.sector_size )
98   {
99      case 2048: return CD_TRACK_MODE1;
100      case 2324: return CD_TRACK_MODE2_FORM2;
101      case 2336: return CD_TRACK_MODE2;
102      case 2352: return CD_TRACK_MODE2_RAW;
103
104      default: logerror( "MATSUCD: Sector size %d unsupported!\n", cd.sector_size ); break;
105   }
106
107   return CD_TRACK_RAW_DONTCARE;
108}
109
110void matsucd_read_next_block( void )
111{
112   cd.xfer_offset = 0;
113
114   if ( cd.num_blocks )
115   {
116      cd.lba++;
117      cd.num_blocks--;
118
119      if (!cdrom_read_data(cd.cdrom, cd.lba, cd.sector_buffer, matsucd_getsector_type()))
120      {
121         logerror( "MATSUCD - Warning: Read error on CD!\n" );
122      }
123   }
124}
125
126int matsucd_get_next_byte( UINT8 *data )
127{
128   /* no more data to read on this sector */
129   if ( cd.xfer_offset >= cd.sector_size )
130      return -1;
131
132   if ( data )
133      *data = cd.sector_buffer[cd.xfer_offset++];
134
135   return 0;
136}
137
138static void matsucd_cdda_stop( running_machine &machine )
139{
140   device_t *cdda = cdda_from_cdrom(machine, cd.cdrom);
141
142   if (cdda != NULL)
143   {
144      cdda_stop_audio(cdda);
145      cd.frame_timer->reset(  );
146   }
147}
148
149static void matsucd_cdda_play( running_machine &machine, UINT32 lba, UINT32 num_blocks )
150{
151   device_t *cdda = cdda_from_cdrom(machine, cd.cdrom);
152   if (cdda != NULL)
153   {
154      cdda_start_audio(cdda, lba, num_blocks);
155      cd.frame_timer->adjust(attotime::from_hz( 75 ));
156   }
157}
158
159static void matsucd_cdda_pause( running_machine &machine, int pause )
160{
161   device_t *cdda = cdda_from_cdrom(machine, cd.cdrom);
162   if (cdda != NULL)
163   {
164      cdda_pause_audio(cdda, pause);
165
166      if ( pause )
167      {
168         cd.frame_timer->reset(  );
169      }
170      else
171      {
172         cd.frame_timer->adjust(attotime::from_hz( 75 ));
173      }
174   }
175}
176
177static UINT8 matsucd_cdda_getstatus( running_machine &machine, UINT32 *lba )
178{
179   device_t *cdda = cdda_from_cdrom(machine, cd.cdrom);
180
181   if ( lba ) *lba = 0;
182
183   if (cdda != NULL)
184   {
185      if (cdda_audio_active(cdda))
186      {
187         if ( lba ) *lba = cdda_get_audio_lba(cdda);
188
189         if (cdda_audio_paused(cdda))
190         {
191            return 0x12;   /* audio paused */
192         }
193         else
194         {
195            return 0x11;   /* audio in progress */
196         }
197      }
198      else if (cdda_audio_ended(cdda))
199      {
200         return 0x13;   /* audio ended */
201      }
202   }
203
204   return 0x15;   /* no audio status */
205}
206
207void matsucd_enable_w( int level )
208{
209   cd.enabled = ( level ) ? 0 : 1;
210}
211
212void matsucd_cmd_w( int level )
213{
214   cd.cmd_signal = ( level ) ? 0 : 1;
215}
216
217int matsucd_stch_r( void )
218{
219   return cd.stch_signal ? 0 : 1;
220}
221
222int matsucd_sten_r( void )
223{
224   return cd.sten_signal ? 0 : 1;
225}
226
227int matsucd_scor_r( void )
228{
229   return cd.scor_signal ? 0 : 1;
230}
231
232static void update_status_enable( running_machine &machine, int level )
233{
234   cd.sten_signal = level;
235
236   if ( cd.sten_cb )
237   {
238      (*cd.sten_cb)(machine, cd.sten_signal);
239   }
240}
241
242static void update_status_changed( running_machine &machine, int level )
243{
244   cd.stch_signal = level;
245
246   if ( cd.stch_cb )
247   {
248      (*cd.stch_cb)(machine, cd.stch_signal);
249   }
250}
251
252static void update_subcode_ready( running_machine &machine, int level )
253{
254   cd.scor_signal = level;
255
256   if ( cd.scor_cb )
257   {
258      (*cd.scor_cb)(machine, cd.scor_signal);
259   }
260}
261
262static TIMER_CALLBACK(matsucd_set_status_end)
263{
264   update_status_changed( machine, 1 );
265}
266
267static void matsucd_set_status( running_machine &machine, UINT8 status )
268{
269   if ( status != cd.status )
270   {
271      cd.status = status;
272
273      if ( cd.stch_signal != 0 )
274      {
275         update_status_changed( machine, 0 );
276         machine.scheduler().timer_set(attotime::from_msec(1), FUNC(matsucd_set_status_end));
277      }
278   }
279}
280
281static TIMER_CALLBACK(matsu_subcode_proc)
282{
283   device_t *cdda = cdda_from_cdrom(machine, cd.cdrom);
284
285   (void)param;
286
287   if (cdda != NULL)
288   {
289      UINT8   s = matsucd_cdda_getstatus(machine, NULL);
290      UINT8   newstatus = cd.status;
291
292      if ( s == 0x11 || s == 0x12 )
293      {
294         if ( s == 0x11 )
295         {
296            update_subcode_ready( machine, 1 );
297            update_subcode_ready( machine, 0 );
298         }
299
300         newstatus |= MATSU_STATUS_PLAYING;
301
302         cd.frame_timer->adjust(attotime::from_hz( 75 ));
303      }
304      else
305      {
306         newstatus &= ~MATSU_STATUS_PLAYING;
307      }
308
309      matsucd_set_status( machine, newstatus );
310   }
311}
312
313static void matsucd_command_error( running_machine &machine )
314{
315   UINT8   newstatus = cd.status;
316
317   newstatus &= ~MATSU_STATUS_SUCCESS;
318   newstatus |= MATSU_STATUS_ERROR;
319
320   matsucd_set_status( machine, newstatus );
321}
322
323static void matsucd_complete_cmd( running_machine &machine, UINT8 len )
324{
325   UINT8   newstatus = cd.status;
326
327   cd.input_pos = 0;
328   cd.output_pos = 0;
329   cd.output_len = len;
330
331   newstatus &= ~MATSU_STATUS_ERROR;
332   newstatus |= MATSU_STATUS_SUCCESS;
333
334   matsucd_set_status( machine, newstatus );
335
336   update_status_enable( machine, 1 );
337   update_status_enable( machine, 0 );
338}
339
340UINT8 matsucd_response_r( running_machine &machine )
341{
342   UINT8   v = cd.output[cd.output_pos++];
343
344   if ( cd.output_pos < cd.output_len )
345   {
346      update_status_enable( machine, 1 );
347      update_status_enable( machine, 0 );
348   }
349
350   return v;
351}
352
353void matsucd_command_w( running_machine &machine, UINT8 data )
354{
355   UINT8   cmd;
356
357   /* make sure we're enabled */
358   if ( cd.enabled == 0 )
359      return;
360
361   /* make sure /CMD is asserted */
362   if ( cd.cmd_signal == 0 )
363      return;
364
365   if ( cd.cdda_set == 0 )
366   {
367      // 2009-10, FP: for some reason, cdda_from_cdrom was not returning the correct
368      // CDDA device. Hence, as a temp workaround, I added the cdda to the struct
369      // and its tag is configured in matsucd_init
370      if ( cd.cdrom )
371         cdda_set_cdrom( cd.cdda, cd.cdrom);
372
373      cd.cdda_set = 1;
374   }
375
376   cd.input[cd.input_pos++] = data;
377
378   cmd = cd.input[0];
379
380   switch( cmd )
381   {
382      case 0x01:   /* seek */
383      {
384         if ( cd.input_pos < 7 )
385            return;
386
387         /* stop CDDA audio if necessary */
388         matsucd_cdda_stop(machine);
389
390         cd.motor = 1;
391
392         memset( cd.output, 0, 6 );
393         matsucd_complete_cmd( machine, 0 );
394      }
395      break;
396
397      case 0x02:   /* read sectors */
398      {
399         if ( cd.input_pos < 7 )
400            return;
401
402         /* stop CDDA audio if necessary */
403         matsucd_cdda_stop(machine);
404
405         /* LBA */
406         cd.lba = cd.input[1];
407         cd.lba <<= 8;
408         cd.lba |= cd.input[2];
409         cd.lba <<= 8;
410         cd.lba |= cd.input[3];
411
412         /* Number of blocks */
413         cd.num_blocks = cd.input[4];
414         cd.num_blocks <<= 8;
415         cd.num_blocks |= cd.input[5];
416
417         /* Reset transfer count */
418         cd.xfer_offset = 0;
419
420         /* go ahead and cache the first block */
421         if (!cdrom_read_data(cd.cdrom, cd.lba, cd.sector_buffer, matsucd_getsector_type()))
422         {
423            logerror( "MATSUCD - Warning: Read error on CD!\n" );
424            matsucd_command_error( machine );
425            return;
426         }
427
428         cd.motor = 1;
429
430         memset( cd.output, 0, 6 );
431         matsucd_complete_cmd( machine, 0 );
432      }
433      break;
434
435      case 0x04:   /* motor on */
436      {
437         if ( cd.input_pos < 7 )
438            return;
439
440         cd.motor = 1;
441
442         memset( cd.output, 0, 6 );
443         matsucd_complete_cmd( machine, 0 );
444      }
445      break;
446
447      case 0x05:   /* motor off */
448      {
449         if ( cd.input_pos < 7 )
450            return;
451
452         /* stop CDDA audio if necessary */
453         matsucd_cdda_stop(machine);
454
455         cd.motor = 0;
456
457         memset( cd.output, 0, 6 );
458         matsucd_complete_cmd( machine, 0 );
459      }
460      break;
461
462      case 0x09:   /* play audio cd, LBA mode */
463      {
464         UINT32   lba, numblocks;
465
466         if ( cd.input_pos < 7 )
467            return;
468
469         lba = cd.input[1];
470         lba <<= 8;
471         lba |= cd.input[2];
472         lba <<= 8;
473         lba |= cd.input[3];
474
475         numblocks = cd.input[4];
476         numblocks <<= 8;
477         numblocks |= cd.input[5];
478         numblocks <<= 8;
479         numblocks |= cd.input[6];
480
481         matsucd_cdda_play( machine, lba, numblocks );
482
483         cd.motor = 1;
484
485         memset( cd.output, 0, 6 );
486         matsucd_complete_cmd( machine, 0 );
487      }
488      break;
489
490      case 0x0a:   /* play audio cd, MSF mode */
491      {
492         UINT32   start, end, lba_start, lba_end;
493
494         if ( cd.input_pos < 7 )
495            return;
496
497         start = cd.input[1];
498         start <<= 8;
499         start |= cd.input[2];
500         start <<= 8;
501         start |= cd.input[3];
502
503         end = cd.input[4];
504         end <<= 8;
505         end |= cd.input[5];
506         end <<= 8;
507         end |= cd.input[6];
508
509         lba_start = MSF2LBA( start );
510         lba_end = MSF2LBA( end );
511
512         if ( end == 0xffffff )
513         {
514            lba_end = cdrom_get_track_start(cd.cdrom,cdrom_get_last_track(cd.cdrom)-1);
515            lba_end += cdrom_get_toc(cd.cdrom)->tracks[cdrom_get_last_track(cd.cdrom)-1].frames;
516         }
517
518         if ( lba_end <= lba_start )
519         {
520            matsucd_cdda_stop(machine);
521         }
522         else
523         {
524            matsucd_cdda_play( machine, lba_start, lba_end - lba_start );
525            cd.motor = 1;
526         }
527
528         memset( cd.output, 0, 6 );
529         matsucd_complete_cmd( machine, 0 );
530      }
531      break;
532
533      case 0x0b:   /* play audio track and index */
534      {
535         UINT8   track_start = cd.input[1];
536         UINT8   index_start = cd.input[2];
537         UINT8   track_end = cd.input[3];
538         UINT8   index_end = cd.input[4];
539         UINT32   lba_start, lba_end;
540
541         /* TODO: Add index support once the CDDA engine supports it */
542         (void)index_start;
543         (void)index_end;
544
545         /* sanitize values */
546         if ( track_start == 0 ) track_start++;
547         if ( track_end == 0 ) track_end++;
548         if ( track_end > cdrom_get_last_track(cd.cdrom) )
549            track_end = cdrom_get_last_track(cd.cdrom);
550
551         /* find the start and stop positions */
552         lba_start = cdrom_get_track_start(cd.cdrom,track_start-1);
553         lba_end = cdrom_get_track_start(cd.cdrom,track_end-1);
554
555         lba_end += cdrom_get_toc(cd.cdrom)->tracks[track_end-1].frames;
556
557         if ( lba_end <= lba_start )
558         {
559            matsucd_cdda_stop(machine);
560         }
561         else
562         {
563            matsucd_cdda_play( machine, lba_start, lba_end - lba_start );
564            cd.motor = 1;
565         }
566
567         memset( cd.output, 0, 6 );
568         matsucd_complete_cmd( machine, 0 );
569      }
570      break;
571
572      case 0x81:   /* status read */
573      {
574         UINT8   newstatus = cd.status;
575
576         newstatus &= MATSU_STATUS_SUCCESS | MATSU_STATUS_ERROR | MATSU_STATUS_PLAYING;
577         newstatus |= MATSU_STATUS_READY;
578
579         if (cd.cdrom)
580         {
581            newstatus |= MATSU_STATUS_MEDIA;
582         }
583
584         if (cd.motor)
585            newstatus |= MATSU_STATUS_MOTOR;
586
587         cd.output[0] = newstatus;
588
589         matsucd_set_status( machine, newstatus );
590
591         matsucd_complete_cmd( machine, 1 );
592      }
593      break;
594
595      case 0x82:   /* error read */
596      {
597         if ( cd.input_pos < 7 )
598            return;
599
600         memset( cd.output, 0, 6 );
601         matsucd_complete_cmd( machine, 6 );
602      }
603      break;
604
605      case 0x84:   /* set mode */
606      {
607         if ( cd.input_pos < 7 )
608            return;
609
610         cd.sector_size = cd.input[2];
611         cd.sector_size <<= 8;
612         cd.sector_size |= cd.input[3];
613
614         memset( cd.output, 0, 6 );
615         matsucd_complete_cmd( machine, 0 );
616      }
617      break;
618
619      case 0x87:   /* read SUBQ */
620      {
621         int      msfmode;
622         UINT32   lba;
623         UINT8   track;
624
625         if ( cd.input_pos < 7 )
626            return;
627
628         msfmode = (cd.input[1] & 0x02) ? 1 : 0;
629
630         memset( cd.output, 0, 13 );
631
632         cd.output[0] = matsucd_cdda_getstatus( machine, &lba );
633
634         if ( lba > 0 )
635         {
636            UINT32   disk_pos;
637            UINT32   track_pos;
638
639            track = cdrom_get_track(cd.cdrom, lba);
640
641            cd.output[1] = cdrom_get_adr_control(cd.cdrom, track);
642            cd.output[2] = track+1;
643            cd.output[3] = 0; /* index */
644
645            disk_pos = lba;
646            if ( msfmode ) disk_pos = LBA2MSF(disk_pos);
647
648            cd.output[4] = (disk_pos >> 24) & 0xff;
649            cd.output[5] = (disk_pos >> 16) & 0xff;
650            cd.output[6] = (disk_pos >> 8) & 0xff;
651            cd.output[7] = (disk_pos) & 0xff;
652
653            track_pos = lba - cdrom_get_track_start(cd.cdrom, track);
654            if ( msfmode ) track_pos = LBA2MSF(track_pos);
655
656            cd.output[8] = (track_pos >> 24) & 0xff;
657            cd.output[9] = (track_pos >> 16) & 0xff;
658            cd.output[10] = (track_pos >> 8) & 0xff;
659            cd.output[11] = (track_pos) & 0xff;
660
661            /* TODO: UPC flag at offset 12 */
662            cd.output[12] = 0;
663         }
664
665         matsucd_complete_cmd( machine, 13 );
666      }
667      break;
668
669      case 0x89:   /* read disk info */
670      {
671         UINT32   end;
672
673         if ( cd.input_pos < 7 )
674            return;
675
676         memset( cd.output, 0, 5 );
677
678         cd.output[0] = cdrom_get_last_track(cd.cdrom) ? 1 : 0;
679         cd.output[1] = cdrom_get_last_track(cd.cdrom);
680         end = cdrom_get_track_start(cd.cdrom,cd.output[1]-1);
681         end += cdrom_get_toc(cd.cdrom)->tracks[cd.output[1]-1].frames;
682         end = LBA2MSF(end);
683         cd.output[2] = (end >> 16) & 0xff;
684         cd.output[3] = (end >> 8) & 0xff;
685         cd.output[4] = (end) & 0xff;
686
687         matsucd_complete_cmd( machine, 5 );
688      }
689      break;
690
691      case 0x8a:   /* read toc */
692      {
693         UINT8   track;
694         int      msfmode;
695         UINT32   track_start;
696
697         if ( cd.input_pos < 7 )
698            return;
699
700         /* stop CDDA audio if necessary */
701         matsucd_cdda_stop(machine);
702
703         track = cd.input[2];
704         msfmode = (cd.input[1] & 0x02) ? 1 : 0;
705
706         if ( cd.cdrom == NULL )
707         {
708            logerror( "MATSUCD - Warning: Reading TOC without a CD!\n" );
709            matsucd_command_error( machine );
710            return;
711         }
712
713         if ( track > cdrom_get_last_track(cd.cdrom) )
714         {
715            logerror( "MATSUCD - Warning: Reading invalid track entry from TOC!\n" );
716            matsucd_command_error( machine );
717            return;
718         }
719
720         memset( cd.output, 0, 7 );
721
722         track_start = cdrom_get_track_start(cd.cdrom, track > 0 ? (track-1) : track );
723         if ( msfmode ) track_start = LBA2MSF( track_start );
724
725         cd.output[1] = cdrom_get_adr_control(cd.cdrom, track > 0 ? (track-1) : track);
726         cd.output[2] = track;
727         cd.output[3] = (track == 0 ) ? cdrom_get_last_track(cd.cdrom) : 0;
728         cd.output[4] = (track_start >> 24) & 0xff;
729         cd.output[5] = (track_start >> 16) & 0xff;
730         cd.output[6] = (track_start >> 8) & 0xff;
731         cd.output[7] = (track_start) & 0xff;
732
733         cd.motor = 1;
734
735         matsucd_complete_cmd( machine, 8 );
736      }
737      break;
738
739      case 0x8b:   /* pause audio */
740      {
741         if ( cd.input_pos < 7 )
742            return;
743
744         matsucd_cdda_pause( machine, (cd.input[1] == 0) ? 1 : 0 );
745         memset( cd.output, 0, 7 );
746         matsucd_complete_cmd( machine, 0 );
747      }
748      break;
749
750      case 0xa3:   /* front panel */
751      {
752         if ( cd.input_pos < 7 )
753            return;
754
755         /* TODO: ??? */
756
757         memset( cd.output, 0, 7 );
758         matsucd_complete_cmd( machine, 0 );
759      }
760      break;
761
762      default:
763         logerror( "MATSUCD: Unknown/inimplemented command %08x\n", cmd );
764      break;
765   }
766}
src/mess/machine/amigakbd.h
r11460r11461
1#ifndef AMIGAKBD_H
2#define AMIGAKBD_H
3
4void amigakbd_init( running_machine &machine );
5
6INPUT_PORTS_EXTERN( amiga_us_keyboard );
7
8#endif /* AMIGAKBD_H */
src/mess/machine/matsucd.h
r11460r11461
1/***************************************************************************
2
3    Matsushita/Panasonic CDR521/522 type CDROM drive emulation
4
5***************************************************************************/
6
7/* initialization */
8void matsucd_init( device_t *cdrom_device, const char *cdda_tag );
9
10
11/* signaling */
12extern void matsucd_enable_w( int level );   /* /ENABLE pin */
13extern void matsucd_cmd_w( int level );      /* /CMD pin */
14extern int matsucd_stch_r( void );         /* /STCH pin */
15extern int matsucd_sten_r( void );         /* /STEN pin */
16extern int matsucd_scor_r( void );         /* /SCOR pin */
17
18/* callback for signal changes */
19extern void matsucd_set_status_enabled_callback( void (*sten_cb)( running_machine &machine, int level ) );
20extern void matsucd_set_status_changed_callback( void (*stch_cb)( running_machine &machine, int level ) );
21extern void matsucd_set_subcode_ready_callback( void (*scor_cb)( running_machine &machine, int level ) );
22
23/* data transfer routines */
24extern void matsucd_read_next_block( void );
25extern int matsucd_get_next_byte( UINT8 *data );
26
27/* main command interface */
28extern void matsucd_command_w( running_machine &machine, UINT8 data );
29extern UINT8 matsucd_response_r( running_machine &machine );
src/mess/machine/amigacrt.c
r11460r11461
1/***************************************************************************
2
3    Amiga cartridge emulation
4
5TODO:
6- Investigate why the AR2/3 sometimes garble the video on exit from the cart
7- Add Nordic Power and similar carts
8- Add HRTMon A1200 cart
9
10***************************************************************************/
11
12
13#include "emu.h"
14#include "includes/amiga.h"
15#include "cpu/m68000/m68000.h"
16#include "machine/6526cia.h"
17#include "machine/amigacrt.h"
18
19enum
20{
21   /* supported cartridges */
22   ACTION_REPLAY            =   0,
23   ACTION_REPLAY_MKII,
24   ACTION_REPLAY_MKIII
25};
26
27typedef struct
28{
29   int cart_type;
30   int ar1_spurious;
31   UINT16 ar23_mode;
32} amigacrt_t;
33static amigacrt_t amigacrt;
34
35/***************************************************************************
36
37  Utilities
38
39***************************************************************************/
40
41static int check_kickstart_12_13( running_machine &machine, const char *cart_name )
42{
43   UINT16 * ksmem = (UINT16 *)machine.region( "user1" )->base();
44
45   if ( ksmem[2] == 0x00FC )
46      return 1;
47
48   logerror( "%s requires Kickstart version 1.2 or 1.3 - Cart not installed\n", cart_name );
49
50   return 0;
51}
52
53/***************************************************************************
54
55  Amiga Action Replay 1
56
57  Whenever you push the button, an NMI interrupt is generated.
58
59  The cartridge protects itself from being removed from memory by
60  generating an interrupt whenever either the spurious interrupt
61  vector is written at $60, or the nmi interrupt vector is written at
62  $7c. If the spurious interrupt vector at $60 is written, then
63  a NMI is generated, and the spurious irq vector is restored. If the
64  NMI vector at $7c is written, then a spurious interrupt is generated,
65  and the NMI vector is restored.
66
67  When breakpoints are set, the target address is replaced by a trap
68  instruction, and the original contents of the address are kept in
69  the cartridge's RAM. A trap handler is installed pointing to $40
70  in RAM, where code that clears memory address $60 followed by two
71  nops are written. There seems to be a small delay between the write
72  to $60 and until the actual NMI is generated, since the cart expects
73  the PC to be at $46 (at the second nop).
74
75***************************************************************************/
76
77static IRQ_CALLBACK(amiga_ar1_irqack)
78{
79   if ( irqline == 7 && amigacrt.ar1_spurious )
80   {
81      return M68K_INT_ACK_SPURIOUS;
82   }
83
84   return (24+irqline);
85}
86
87static TIMER_CALLBACK( amiga_ar1_delayed_nmi )
88{
89   (void)param;
90   cputag_set_input_line(machine, "maincpu", 7, PULSE_LINE);
91}
92
93static void amiga_ar1_nmi( running_machine &machine )
94{
95   amiga_state *state = machine.driver_data<amiga_state>();
96   /* get the cart's built-in ram */
97   UINT16 *ar_ram = (UINT16 *)machine.device("maincpu")->memory().space(AS_PROGRAM)->get_write_ptr(0x9fc000);
98
99   if ( ar_ram != NULL )
100   {
101      int i;
102
103      /* copy custom register values */
104      for( i = 0; i < 256; i++ )
105         ar_ram[0x1800+i] = CUSTOM_REG(i);
106
107      /* trigger NMI irq */
108      amigacrt.ar1_spurious = 0;
109      machine.scheduler().timer_set(machine.device<cpu_device>("maincpu")->cycles_to_attotime(28), FUNC(amiga_ar1_delayed_nmi));
110   }
111}
112
113static WRITE16_HANDLER( amiga_ar1_chipmem_w )
114{
115   amiga_state *state = space->machine().driver_data<amiga_state>();
116   int pc = cpu_get_pc(&space->device());
117
118   /* see if we're inside the AR1 rom */
119   if ( ((pc >> 16) & 0xff ) != 0xf0 )
120   {
121      /* if we're not, see if either the Spurious IRQ vector
122           or the NMI vector are being overwritten */
123      if ( offset == (0x60/2) || offset == (0x7c/2) )
124      {
125         /* trigger an NMI or spurious irq */
126         amigacrt.ar1_spurious = (offset == 0x60/2) ? 0 : 1;
127         space->machine().scheduler().timer_set(space->machine().device<cpu_device>("maincpu")->cycles_to_attotime(28), FUNC(amiga_ar1_delayed_nmi));
128      }
129   }
130
131   (*state->m_chip_ram_w)(state,  offset * 2, data );
132}
133
134static void amiga_ar1_check_overlay( running_machine &machine )
135{
136   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x000000, 0x00007f, FUNC(amiga_ar1_chipmem_w));
137}
138
139static void amiga_ar1_init( running_machine &machine )
140{
141   void *ar_ram;
142
143   /* check kickstart version */
144   if ( !check_kickstart_12_13( machine, "Amiga Action Replay" ) )
145   {
146      amigacrt.cart_type = -1;
147      return;
148   }
149
150   /* setup the cart ram */
151   ar_ram = auto_alloc_array(machine, UINT8, 0x4000);
152   memset(ar_ram, 0, 0x4000);
153
154   /* Install ROM */
155   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xf00000, 0xf7ffff, "bank2");
156   machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xf00000, 0xf7ffff);
157
158   /* Install RAM */
159   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0x9fc000, 0x9fffff, "bank3");
160
161   /* Configure Banks */
162   memory_set_bankptr(machine, "bank2", machine.region("user2")->base());
163   memory_set_bankptr(machine, "bank3", ar_ram);
164
165   amigacrt.ar1_spurious = 0;
166
167   /* Install IRQ ACK callback */
168   device_set_irq_callback(machine.device("maincpu"), amiga_ar1_irqack);
169}
170
171/***************************************************************************
172
173  Amiga Action Replay MKII/MKIII
174
175  Whenever you push the button, an overlay of the cartridge appears
176  in RAM and an NMI interrupt is generated. Only reads are overlayed.
177  Writes go directly to chipmem (so that the CPU can write the stack
178  information for the NMI). Once the interrupt is taken, the cart
179  disables the ROM overlay and checks it's internal mode register
180  to see why it was invoked.
181
182  When a breakpoint is set the cart replaces the target instruction
183  with a trap, and adds a trap handler that it locates in the $100-$120
184  area. The handler simply has one instruction: TST.B $BFE001. This cia
185  access is monitored, and the conditions match (PC < 120 and a previous
186  command requested the monitoring of the cia) then the cart is invoked.
187
188***************************************************************************/
189
190static void amiga_ar23_freeze( running_machine &machine );
191
192static READ16_HANDLER( amiga_ar23_cia_r )
193{
194   int pc = cpu_get_pc(&space->device());
195
196   if ( ACCESSING_BITS_0_7 && offset == 2048 && pc >= 0x40 && pc < 0x120 )
197   {
198      amiga_ar23_freeze(space->machine());
199   }
200
201   return amiga_cia_r( space, offset, mem_mask );
202}
203
204static WRITE16_HANDLER( amiga_ar23_mode_w )
205{
206   if ( data & 2 )
207   {
208      space->install_legacy_read_handler(0xbfd000, 0xbfefff, FUNC(amiga_ar23_cia_r));
209   }
210   else
211   {
212      space->install_legacy_read_handler(0xbfd000, 0xbfefff, FUNC(amiga_cia_r));
213   }
214
215   amigacrt.ar23_mode = (data&0x3);
216   if ( amigacrt.ar23_mode == 0 )
217      amigacrt.ar23_mode = 1;
218
219}
220
221static READ16_HANDLER( amiga_ar23_mode_r )
222{
223   amiga_state *state = space->machine().driver_data<amiga_state>();
224   UINT16 *mem = (UINT16 *)space->machine().region( "user2" )->base();
225
226   if ( ACCESSING_BITS_0_7 )
227   {
228      if ( offset < 2 )
229         return (mem[offset] | (amigacrt.ar23_mode&3));
230
231      if ( offset == 0x03 ) /* disable cart oberlay on chip mem */
232      {
233         UINT32 mirror_mask = state->m_chip_ram_size;
234
235         memory_set_bank(space->machine(), "bank1", 0);
236
237         while( (mirror_mask<<1) < 0x100000 )
238         {
239            mirror_mask |= ( mirror_mask << 1 );
240         }
241
242         /* overlay disabled, map RAM on 0x000000 */
243         space->install_write_bank(0x000000, state->m_chip_ram_size - 1, 0, mirror_mask, "bank1");
244      }
245   }
246
247   return mem[offset];
248}
249
250static WRITE16_HANDLER( amiga_ar23_chipmem_w )
251{
252   amiga_state *state = space->machine().driver_data<amiga_state>();
253   if ( offset == (0x08/2) )
254   {
255      if ( amigacrt.ar23_mode & 1 )
256         amiga_ar23_freeze(space->machine());
257   }
258
259   (*state->m_chip_ram_w)(state,  offset * 2, data );
260}
261
262static void amiga_ar23_freeze( running_machine &machine )
263{
264   amiga_state *state = machine.driver_data<amiga_state>();
265   int pc = cpu_get_pc(machine.device("maincpu"));
266
267   /* only freeze if we're not inside the cart's ROM */
268   if ( ((pc >> 16) & 0xfe ) != 0x40 )
269   {
270      /* get the cart's built-in ram */
271      UINT16 *ar_ram = (UINT16 *)machine.device("maincpu")->memory().space(AS_PROGRAM)->get_write_ptr(0x440000);
272
273      if ( ar_ram != NULL )
274      {
275         int      i;
276
277         for( i = 0; i < 0x100; i++ )
278            ar_ram[0x7800+i] = CUSTOM_REG(i);
279      }
280
281      /* overlay the cart rom's in chipram */
282      memory_set_bank(machine, "bank1", 2);
283
284      /* writes go to chipram */
285      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x000000, state->m_chip_ram_size - 1, FUNC(amiga_ar23_chipmem_w));
286
287      /* trigger NMI irq */
288      cputag_set_input_line(machine, "maincpu", 7, PULSE_LINE);
289   }
290}
291
292static void amiga_ar23_nmi( running_machine &machine )
293{
294   amigacrt.ar23_mode = 0;
295   amiga_ar23_freeze(machine);
296}
297
298#if 0
299static WRITE16_HANDLER( amiga_ar23_custom_w )
300{
301   int pc = cpu_get_pc(&space->device());
302
303   /* see if we're inside the AR2 rom */
304   if ( ((pc >> 16) & 0xfe ) != 0x40 )
305   {
306      /* get the cart's built-in ram */
307      UINT16 *ar_ram = (UINT16 *)memory_get_write_ptr(0, AS_PROGRAM, 0x440000);
308
309      if ( ar_ram != NULL )
310      {
311         ar_ram[0x7800+offset] = data;
312      }
313   }
314
315   amiga_custom_w( offset, data, mem_mask );
316}
317
318static READ16_HANDLER( amiga_ar23_custom_r )
319{
320   UINT16 data = amiga_custom_r( offset, mem_mask );
321
322   int pc = cpu_get_pc(&space->device());
323
324   /* see if we're inside the AR2 rom */
325   if ( ((pc >> 16) & 0xfe ) != 0x40 )
326   {
327      /* get the cart's built-in ram */
328      UINT16 *ar_ram = (UINT16 *)memory_get_write_ptr(0, AS_PROGRAM, 0x440000);
329
330      if ( ar_ram != NULL )
331      {
332         ar_ram[0x7800+offset] = data;
333      }
334   }
335
336   return data;
337}
338#endif
339
340static void amiga_ar23_check_overlay( running_machine &machine )
341{
342   amigacrt.ar23_mode = 3;
343   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x000000, 0x00000f, FUNC(amiga_ar23_chipmem_w));
344}
345
346static void amiga_ar23_init( running_machine &machine, int ar3 )
347{
348   amiga_state *state = machine.driver_data<amiga_state>();
349   UINT32 mirror = 0x20000, size = 0x1ffff;
350   void *ar_ram;
351
352   /* check kickstart version */
353   if ( !check_kickstart_12_13( machine, "Action Replay MKII or MKIII" ) )
354   {
355      amigacrt.cart_type = -1;
356      return;
357   }
358
359   /* setup the cart ram */
360   ar_ram = auto_alloc_array_clear(machine, UINT8,0x10000);
361
362   if ( ar3 )
363   {
364      mirror = 0;
365      size = 0x3ffff;
366   }
367
368   /* Install ROM */
369   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x400000, 0x400000+size, 0, mirror, "bank2");
370   machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0x400000, 0x400000+size, 0, mirror);
371
372   /* Install RAM */
373   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x440000, 0x44ffff, "bank3");
374   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_write_bank(0x440000, 0x44ffff, "bank3");
375
376   /* Install Custom chip monitor */
377//  machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_read_handler(0xdff000, 0xdff1ff, FUNC(amiga_ar23_custom_r));
378//  machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0xdff000, 0xdff1ff, FUNC(amiga_ar23_custom_w));
379
380   /* Install status/mode handlers */
381   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_read_handler(0x400000, 0x400007, 0, mirror, FUNC(amiga_ar23_mode_r));
382   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x400000, 0x400003, 0, mirror, FUNC(amiga_ar23_mode_w));
383
384   /* Configure Banks */
385   memory_set_bankptr(machine, "bank2", machine.region("user2")->base());
386   memory_set_bankptr(machine, "bank3", ar_ram);
387
388   memory_configure_bank(machine, "bank1", 0, 2, state->m_chip_ram, 0);
389   memory_configure_bank(machine, "bank1", 1, 2, machine.region("user1")->base(), 0);
390   memory_configure_bank(machine, "bank1", 2, 2, machine.region("user2")->base(), 0);
391
392   amigacrt.ar23_mode = 3;
393}
394
395/***************************************************************************
396
397    MAME/MESS hooks
398
399***************************************************************************/
400
401void amiga_cart_init( running_machine &machine )
402{
403   /* see what is there */
404   UINT16 *mem = (UINT16 *)machine.region( "user2" )->base();
405
406   amigacrt.cart_type = -1;
407
408   if ( mem != NULL )
409   {
410      if ( mem[0x00] == 0x1111 )
411      {
412         amigacrt.cart_type = ACTION_REPLAY;
413         amiga_ar1_init(machine);
414      }
415      else if ( mem[0x0C] == 0x4D6B )
416      {
417         amigacrt.cart_type = ACTION_REPLAY_MKII;
418         amiga_ar23_init(machine, 0);
419      }
420      else if ( mem[0x0C] == 0x4D4B )
421      {
422         amigacrt.cart_type = ACTION_REPLAY_MKIII;
423         amiga_ar23_init(machine, 1);
424      }
425   }
426}
427
428void amiga_cart_check_overlay( running_machine &machine )
429{
430   if ( amigacrt.cart_type < 0 )
431      return;
432
433   switch( amigacrt.cart_type )
434   {
435      case ACTION_REPLAY:
436         amiga_ar1_check_overlay(machine);
437      break;
438
439      case ACTION_REPLAY_MKII:
440      case ACTION_REPLAY_MKIII:
441         amiga_ar23_check_overlay(machine);
442      break;
443   }
444}
445
446void amiga_cart_nmi( running_machine &machine )
447{
448   if ( amigacrt.cart_type < 0 )
449      return;
450
451   switch( amigacrt.cart_type )
452   {
453      case ACTION_REPLAY:
454         amiga_ar1_nmi(machine);
455      break;
456
457      case ACTION_REPLAY_MKII:
458      case ACTION_REPLAY_MKIII:
459         amiga_ar23_nmi(machine);
460      break;
461   }
462}
src/mess/machine/amigacrt.h
r11460r11461
1#ifndef AMIGACRT_H
2#define AMIGACRT_H
3
4void amiga_cart_init( running_machine &machine );
5void amiga_cart_check_overlay( running_machine &machine );
6void amiga_cart_nmi( running_machine &machine );
7
8#endif /* AMIGACRT_H */
src/mess/machine/psxcddrv.c
r11460r11461
1#include "emu.h"
2#include "includes/psx.h"
3#include "psxcd.h"
4#include "psxcddrv.h"
5
6//#define debug_mess_driver
7
8//
9//
10//
11
12static const unsigned int   num_pf_sectors=32, num_pf_buffers=16;
13
14//
15//
16//
17
18cdrom_driver::cdrom_driver()
19{
20   pf_head = 0;
21   pf_tail = 0;
22   num_pf = 0;
23   pf_head_sector = 0;
24   pf_status = NULL;
25   native_sector_size = raw_sector_size;
26   last_pf_status = NULL;
27   m_cd = NULL;
28   m_machine = NULL;
29
30//  printf("cdrom_driver base class init, pf_buffer size is %d\n", num_pf_sectors*num_pf_buffers*raw_sector_size);
31
32   pf_buffer=new unsigned char [num_pf_sectors*num_pf_buffers*raw_sector_size];
33
34   timestamp_frequency = 1;
35}
36
37cdrom_driver::~cdrom_driver()
38{
39   global_free(pf_buffer);
40}
41
42//
43//
44//
45
46void cdrom_driver::set_native_sector_size(const unsigned int sz)
47{
48   native_sector_size=sz;
49}
50
51//
52//
53//
54
55void cdrom_driver::cancel_io()
56{
57   if (pf_status)
58   {
59      pf_status->cancel();
60      pf_status->release();
61   }
62
63   pf_status=NULL;
64}
65
66//
67//
68//
69
70void cdrom_driver::prefetch_sector(const unsigned int sec)
71{
72   int numpfsec=num_pf*num_pf_sectors,
73         pfsec=sec-pf_head_sector;
74
75//  printf("prefetch_sector: %d\n", sec);
76
77   if ((pfsec<0) || (pfsec>numpfsec))
78   {
79      // Sector is not in prefetch buffer, abort current prefetch
80
81      if (pf_status)
82      {
83         pf_status->cancel();
84         pf_status->release();
85      }
86
87      // Reset the buffer and begin a new prefetch
88
89      pf_head=0;
90      pf_tail=0;
91      num_pf=1;
92      pf_head_sector=sec;
93
94      last_pf_status=NULL;
95      pf_status=read_sectors(sec, num_pf_sectors, pf_buffer);
96   }
97}
98
99//
100//
101//
102
103bool cdrom_driver::is_prefetch_sector_loaded(const unsigned int sec)
104{
105   int numpfsec=num_pf*num_pf_sectors,
106         pfsec=sec-pf_head_sector;
107
108   if ((pfsec<0) || (pfsec>=numpfsec))
109   {
110      // Requested sector is not in prefetch buffer, begin a new prefetch
111
112      prefetch_sector(sec);
113      pfsec=sec-pf_head_sector;
114      numpfsec=num_pf*num_pf_sectors;
115   }
116
117   int blk=pfsec/num_pf_sectors;
118
119   if (blk>0)
120   {
121      // Discard blocks below the prefetch point
122
123      pf_head=(pf_head+blk)%num_pf_buffers;
124      pf_head_sector+=num_pf_sectors*blk;
125      pfsec-=num_pf_sectors*blk;
126      num_pf-=blk;
127      blk=0;
128   }
129
130   bool comp=((! pf_status) || (pf_status->complete()));
131
132   if (! comp)
133   {
134      INT64 curtime=m_machine->device<cpu_device>("maincpu")->total_cycles();
135
136      if (last_pf_status!=pf_status)
137      {
138         last_pf_status=pf_status;
139         pf_timeout_begin=curtime;
140      }
141
142      INT64 timeout=curtime-pf_timeout_begin;
143      int timeout_sec=(int)(timeout/timestamp_frequency);
144      if (timeout_sec>20)
145      {
146         printf("cdrom: prefetch timed out, trying again...\n");
147         num_pf=0;
148         pf_head_sector=-1;
149         prefetch_sector(sec);
150         return is_prefetch_sector_loaded(sec);
151      }
152   }
153
154   if ((num_pf<num_pf_buffers) && (comp))
155   {
156      // The prefetch buffer is not full and we are not waiting on IO,
157      // prefetch the next block
158
159      pf_tail=(pf_tail+1)%num_pf_buffers;
160      num_pf++;
161
162      int nxtsec=pf_head_sector+((num_pf-1)*num_pf_sectors);
163      unsigned char *ptr=pf_buffer+((pf_tail*num_pf_sectors)*native_sector_size);
164
165      if (pf_status)
166      {
167         pf_status->release();
168         pf_status=last_pf_status=NULL;
169      }
170
171      pf_status=read_sectors(nxtsec, num_pf_sectors, ptr);
172   }
173
174   if (blk==(num_pf-1))
175   {
176      // The sector we want is in the last block in the prefetch buffer
177      // which might still be loading, check if the sector we want is loaded
178#if 0 // we do not load async in MESS
179      INT64 trans=pf_status->bytes_transferred();
180      unsigned int secmod=pfsec%num_pf_sectors,
181                         needbytes=(secmod+1)*native_sector_size;
182
183      if (trans<needbytes)
184      {
185         // The sector is not loaded yet
186
187         return false;
188      } else
189#endif
190      {
191         // The sector is loaded
192
193         return true;
194      }
195   } else
196   {
197      // The sector is not in the last block so it must be loaded
198
199      return true;
200   }
201}
202
203//
204//
205//
206
207unsigned char *cdrom_driver::get_prefetch_sector(const unsigned int sec, unsigned int *sz)
208{
209   int numpfsec=num_pf*num_pf_sectors,
210         pfsec=sec-pf_head_sector;
211   if ((pfsec>=0) && (pfsec<numpfsec))
212   {
213      int   blk=(pf_head+(pfsec/num_pf_sectors))%num_pf_buffers,
214            off=((blk*num_pf_sectors)+(pfsec%num_pf_sectors))*native_sector_size;
215      *sz=native_sector_size;
216      return pf_buffer+off;
217   } else
218   {
219      return NULL;
220   }
221}
222
223//
224//
225//
226
227bool cdrom_driver::read_sector(const unsigned int sec, unsigned char *buf, const bool block)
228{
229   bool loaded=is_prefetch_sector_loaded(sec);
230
231//  printf("read_sector: %d (loaded=%c)\n", sec, loaded ? 'Y' : 'N');
232
233   if ((! loaded) && (block))
234   {
235      pf_status->block_until_complete();
236      loaded=true;
237   }
238
239   if (loaded)
240   {
241      unsigned int secsz=0;
242      unsigned char *ptr=get_prefetch_sector(sec,&secsz);
243      assert(ptr);
244
245//      printf("got sector %d @ %p, size %d = %02x %02x | %02x %02x\n", sec, ptr, secsz, ptr[0], ptr[1], ptr[0x20], ptr[0x21]);
246
247      if (secsz<2352)
248      {
249         // Add sector header
250
251         buf[0]=0;
252         memset(buf+1,0xff,10);
253         buf[11]=0;
254         sector_to_msf(sec,buf+12);
255         buf[12]=decimal_to_bcd(buf[12]);
256         buf[13]=decimal_to_bcd(buf[13]);
257         buf[14]=decimal_to_bcd(buf[14]);
258         buf[15]=2;
259
260         if (secsz<2336)
261         {
262            memset(buf+16,0xff,8);
263         }
264      }
265
266      switch (secsz)
267      {
268         case 2048:
269            memcpy(buf+24,ptr,2048);
270            break;
271
272         case 2336:
273            memcpy(buf+16,ptr,2336);
274            break;
275
276         case 2352:
277            memcpy(buf,ptr,raw_sector_size);
278            break;
279      }
280
281      return true;
282   } else
283   {
284      return false;
285   }
286}
287
288void cdrom_driver::set_machine(const running_machine &machine)
289{
290   m_machine = (running_machine *)&machine;
291
292   timestamp_frequency = m_machine->device<cpu_device>("maincpu")->clock();
293
294//  printf("cdrom_driver::set_machine: timestamp frequency = %d\n", timestamp_frequency);
295}
296
297/*
298    MAME/MESS driver implementation
299*/
300
301class mess_cdrom_driver : public cdrom_driver
302{
303   enum track_type
304   {
305      track_illegal=-1,
306      track_mode1_2048=0,
307      track_mode2_2352,
308      track_mode2_2336,
309      track_audio
310   };
311
312   struct toc_entry
313   {
314      unsigned int type;
315      unsigned char address[3];
316   };
317
318   int num_sectors, num_tracks;
319   toc_entry toc[100];
320   int bin_sector_size;
321   const char *err;
322
323   io_status *read_sectors(const unsigned int startsec, const unsigned int numsec, unsigned char *buf);
324
325public:
326   mess_cdrom_driver();
327   ~mess_cdrom_driver();
328
329   bool is_usable(char *error_msg, const int msglen) const
330   {
331      return true;
332   }
333
334   bool read_toc();
335   unsigned int get_first_track() const;
336   unsigned int get_num_tracks() const;
337   bool get_track_address(const unsigned int track,unsigned char *address) const;
338   tracktype get_track_type(const unsigned int track) const;
339   unsigned int find_track(const unsigned int sector, unsigned int *start_sector, unsigned int *end_sector) const;
340   cdromtype get_type() const;
341};
342
343mess_cdrom_driver::mess_cdrom_driver()
344   : err(NULL)
345{
346   for (int i=0; i<100; i++)
347      toc[i].type=track_illegal;
348   num_tracks=0;
349   num_sectors=0;
350}
351
352//
353//
354//
355
356mess_cdrom_driver::~mess_cdrom_driver()
357{
358   cancel_io();
359}
360
361//
362//
363//
364
365bool mess_cdrom_driver::read_toc()
366{
367   if (m_cd)
368   {
369      const cdrom_toc *toc = cdrom_get_toc(m_cd);
370
371      num_tracks = cdrom_get_last_track(m_cd);
372
373      switch (toc->tracks[0].trktype)
374      {
375         case CD_TRACK_MODE1: bin_sector_size=2048; break;
376         case CD_TRACK_MODE2_FORM1: bin_sector_size=2048; break;
377         case CD_TRACK_MODE2: bin_sector_size=2336; break;
378         case CD_TRACK_MODE2_FORM_MIX: bin_sector_size=2336; break;
379         default: bin_sector_size=2352; break;
380      }
381
382      set_native_sector_size(bin_sector_size);
383      num_sectors = cdrom_get_track_start(m_cd, num_tracks) + toc->tracks[num_tracks].frames;
384
385//      printf("mess_cdrom_driver: %d sectors, native size %d\n",num_sectors, bin_sector_size);
386
387      return true;
388   }
389
390   return false;
391}
392
393//
394//
395//
396
397io_status *mess_cdrom_driver::read_sectors(const unsigned int startsec, const unsigned int numsec, unsigned char *buf)
398{
399   const cdrom_toc *toc = cdrom_get_toc(m_cd);
400   UINT32 track = cdrom_get_track(m_cd, startsec);
401   UINT32 secsize = toc->tracks[track].datasize;
402
403   #ifdef debug_mess_driver
404   printf("mess: read %d sectors from %d (secsize %d)\n",numsec,startsec,secsize);
405   #endif
406
407   if ((startsec>=0)) // && ((int)startsec<num_sectors))
408   {
409//      fin->seek((INT64)startsec*(INT64)bin_sector_size);
410
411//      io_status *ios=fin->async_read(buf,numsec*bin_sector_size);
412//      if (! ios)
413      for (int i = 0; i < numsec; i++)
414      {
415//          printf("[%d/%d] Reading to pf_buffer %p at offset %d, size %d\n", i, numsec, &buf[secsize*i], secsize*i, secsize);
416         cdrom_read_data(m_cd, startsec+i, &buf[secsize*i], CD_TRACK_RAW_DONTCARE);
417      }
418
419      return NULL;
420
421//      return ios;
422   }
423   else
424   {
425      printf("mess: read sector out of range (%d, max=%d)\n",
426                startsec,
427                num_sectors);
428
429      memset(buf,0xff,numsec*bin_sector_size);
430      return NULL;
431   }
432}
433
434//
435//
436//
437
438unsigned int mess_cdrom_driver::get_first_track() const
439{
440   return 1;
441}
442
443unsigned int mess_cdrom_driver::get_num_tracks() const
444{
445//  printf("get_num_tracks = %d\n", num_tracks);
446   return num_tracks;
447}
448
449bool mess_cdrom_driver::get_track_address(const unsigned int track, unsigned char *address) const
450{
451   if ((track>=1) && ((int)track<=num_tracks))
452   {
453      UINT32 trkstart = cdrom_get_track_start(m_cd, track);
454
455      sector_to_msf(trkstart, address);
456
457      address[0] = address[0];
458      address[1] = address[1];
459      address[2] = address[2];
460
461//      printf("get_track_address %d = %02x:%02x:%02x\n", track, address[0], address[1], address[2]);
462
463      return true;
464   }
465   else
466   {
467      address[0]=address[1]=address[2]=0;
468      return false;
469   }
470}
471
472unsigned int mess_cdrom_driver::find_track(const unsigned int sector, unsigned int *start_sector, unsigned int *end_sector) const
473{
474   const cdrom_toc *toc = cdrom_get_toc(m_cd);
475   UINT32 track = cdrom_get_track(m_cd, sector);
476   int start;
477
478   start = cdrom_get_track_start(m_cd, track);
479
480   if (start_sector != NULL)
481   {
482      *start_sector = start;
483   }
484
485   if (end_sector != NULL)
486   {
487      *end_sector = start + toc->tracks[track].frames;
488   }
489
490   printf("find_track: track %d start %d end %d\n", track, start, *end_sector);
491
492   return -1;
493}
494
495//
496//
497//
498
499cdromtype mess_cdrom_driver::get_type() const
500{
501//  printf("get_type\n");
502   return cdromtype_cd;
503}
504
505//
506//
507//
508
509tracktype mess_cdrom_driver::get_track_type(const unsigned int track) const
510{
511   const cdrom_toc *toc = cdrom_get_toc(m_cd);
512
513//  printf("get_track_type %d = %d\n", track, toc->tracks[track].trktype);
514
515   switch (toc->tracks[track].trktype)
516   {
517      case CD_TRACK_MODE1: return tracktype_mode1;
518      case CD_TRACK_MODE2_RAW: return tracktype_mode2;
519      case CD_TRACK_MODE2_FORM_MIX: return tracktype_mode2;
520      case CD_TRACK_AUDIO: return tracktype_audio;
521      default: return tracktype_unknown;
522   }
523}
524
525//
526//
527//
528
529cdrom_driver *open_mess_drv()
530{
531   return new mess_cdrom_driver();
532}
533
src/mess/machine/wd17xx.c
r11460r11461
1/***************************************************************************
2
3    wd17xx.c
4
5    Implementations of the Western Digital 17xx and 27xx families of
6    floppy disk controllers
7
8
9    Models:
10
11              DAL   DD   Side   Clock       Remark
12      ---------------------------------------------------------
13      FD1771                    1 or 2 MHz  First model
14      FD1781         x          1 or 2 MHz
15      FD1791         x          1 or 2 MHz
16      FD1792                    1 or 2 MHz
17      FD1793   x     x          1 or 2 MHz
18      FD1794   x                1 or 2 MHz
19      FD1795         x     x    1 or 2 MHz
20      FD1797   x     x     x    1 or 2 MHz
21      FD1761         x          1 MHz
22      FD1762                    1 MHz       ?
23      FD1763   x     x          1 MHz
24      FD1764   x                1 MHz       ?
25      FD1765         x     x    1 MHz
26      FD1767   x     x     x    1 MHz
27      WD2791         x          1 or 2 MHz  Internal data separator
28      WD2793   x     x          1 or 2 MHz  Internal data separator
29      WD2795         x     x    1 or 2 MHz  Internal data separator
30      WD2797   x     x     x    1 or 2 MHz  Internal data separator
31      WD1770         x          8 MHz       Motor On signal
32      WD1772         x          8 MHz       Motor On signal, Faster stepping rates
33      WD1773         x          8 MHz       Enable precomp line
34
35      Notes: - In general, later models include all features of earlier models
36             - DAL: Data access lines, x = TRUE; otherwise inverted
37             - DD: Double density support
38             - Side: Has side select support
39             - ?: Unknown if it really exists
40
41    Clones:
42
43      - SMC FD179x
44      - Fujitsu MB8876 -> FD1791, MB8877 -> FD1793
45      - VLSI VL177x
46
47
48    Changelog:
49
50    Kevin Thacker
51        - Removed disk image code and replaced it with floppy drive functions.
52          Any disc image is now useable with this code.
53        - Fixed write protect
54
55    2005-Apr-16 P.Harvey-Smith:
56        - Increased the delay in wd17xx_timed_read_sector_request and
57          wd17xx_timed_write_sector_request, to 40us to more closely match
58          what happens on the real hardware, this has fixed the NitrOS9 boot
59          problems.
60
61    2007-Nov-01 Wilbert Pol:
62        Needed these changes to get the MB8877 for Osborne-1 to work:
63        - Added support for multiple record read
64        - Changed the wd17xx_read_id to not return after DATADONEDELAY, but
65          the host should read the id data through the data register. This
66          was accomplished by making this change in the wd17xx_read_id
67          function:
68            -               wd17xx_complete_command(device, DELAY_DATADONE);
69            +               wd17xx_set_data_request();
70
71    2009-May-10 Robbbert:
72        Further change to get the Kaypro II to work
73        - When wd17xx_read_id has generated the 6 data bytes, it should make
74          an IRQ and turn off the busy status. The timing for Osborne is
75          critical, it must be between 300 and 700 usec, I've settled on 400.
76          The Kaypro doesn't care timewise, but the busy flag must turn off
77          sometime or it hangs.
78            -       w->status |= STA_2_BUSY;
79            +       wd17xx_set_busy(device, attotime::from_usec(400));
80
81    2009-June-4 Roberto Lavarone:
82        - Initial support for wd1771
83        - Added simulation of head loaded feedback from drive
84        - Bugfix: busy flag was cleared too early
85
86    2009-June-21 Robbbert:
87    - The Bugfix above, while valid, caused the Osborne1 to fail. This
88      is because the delay must not exceed 14usec (found by extensive testing).
89    - The minimum delay is 1usec, need by z80netf while formatting a disk.
90    - http://www.bannister.org/forums/ubbthreads.php?ubb=showflat&Number=50889#Post50889
91      explains the problems, testing done, and the test procedure for the z80netf.
92    - Thus, the delay is set to 10usec, and all the disks I have (not many)
93      seem to work.
94    - Note to anyone who wants to change something: Make sure that the
95      Osborne1 boots up! It is extremely sensitive to timing!
96    - For testing only: The osborne1 rom can be patched to make it much
97      more stable, by changing the byte at 0x0da7 from 0x28 to 0x18.
98
99    2009-June-25 Robbbert:
100    - Turns out kayproii not working, 10usec is too short.. but 11usec is ok.
101      Setting it to 12usec.
102      Really, this whole thing needs a complete rewrite.
103
104    2009-July-08 Roberto Lavarone:
105    - Fixed a bug in head load flag handling: einstein and samcoupe now working again
106
107    2009-September-30 Robbbert:
108    - Modified what status flags are returned after a Forced Interrupt,
109      to allow Microbee to boot CP/M.
110
111    2010-Jan-31 Phill Harvey-Smith
112    - The above bugfixes for the Kaypro/Osborne1 have borked the booting on the Dragon
113      Alpha. The Alpha it seems needs a delay of ay least 17us or the NMI generated by
114      INTRQ happens too early and doen't break out of the read/write bytes loops.
115
116      I have made the delay settable by calling wd17xx_set_complete_command_delay, and
117      let it default to 12us, as required above, so that the Dragon Alpha works again.
118      This hopefully should not break the other machines.
119
120      This should probably be considdered a minor hack but it does seem to work !
121
122    2010-02-04 Phill Harvey-Smith
123    - Added multiple sector write as the RM Nimbus needs it.
124
125    2010-March-22 Curt Coder:
126    - Implemented immediate and index pulse interrupts.
127
128    2010-Dec-31 Phill Harvey-Smith
129    - Copied multi-sector write code from r7263, for some reason this had been
130      silently removed, but is required for the rmnimbus driver.
131
132    2011-Mar-08 Phill Harvey-Smith
133    - Triggering intrq now clears the DRQ bit in the status as well as the busy bit.
134      Execution of the READ_DAM command now correctly sets w->command.
135
136    2011-Apr-01 Curt Coder
137    - Set complete command delay to 16 usec (DD) / 32 usec (SD) and removed
138      the external delay setting hack.
139
140    TODO:
141        - What happens if a track is read that doesn't have any id's on it?
142         (e.g. unformatted disc)
143
144***************************************************************************/
145
146
147#include "emu.h"
148#include "formats/imageutl.h"
149#include "machine/wd17xx.h"
150#include "imagedev/flopdrv.h"
151#include "formats/flopimg.h"
152
153/***************************************************************************
154    CONSTANTS
155***************************************************************************/
156
157#define VERBOSE         0   /* General logging */
158#define VERBOSE_DATA   0   /* Logging of each byte during read and write */
159
160#define DELAY_ERROR      3
161#define DELAY_NOTREADY   1
162#define DELAY_DATADONE   3
163
164#define TYPE_I         1
165#define TYPE_II       2
166#define TYPE_III      3
167#define TYPE_IV       4
168
169#define FDC_STEP_RATE   0x03    /* Type I additional flags */
170#define FDC_STEP_VERIFY 0x04   /* verify track number */
171#define FDC_STEP_HDLOAD 0x08   /* load head */
172#define FDC_STEP_UPDATE 0x10   /* update track register */
173
174#define FDC_RESTORE    0x00   /* Type I commands */
175#define FDC_SEEK      0x10
176#define FDC_STEP      0x20
177#define FDC_STEP_IN    0x40
178#define FDC_STEP_OUT   0x60
179
180#define FDC_MASK_TYPE_I       (FDC_STEP_HDLOAD|FDC_STEP_VERIFY|FDC_STEP_RATE)
181
182/* Type I commands status */
183#define STA_1_BUSY      0x01   /* controller is busy */
184#define STA_1_IPL      0x02   /* index pulse */
185#define STA_1_TRACK0   0x04   /* track 0 detected */
186#define STA_1_CRC_ERR   0x08   /* CRC error */
187#define STA_1_SEEK_ERR   0x10   /* seek error */
188#define STA_1_HD_LOADED 0x20   /* head loaded */
189#define STA_1_WRITE_PRO 0x40   /* floppy is write protected */
190#define STA_1_NOT_READY 0x80   /* drive not ready */
191#define STA_1_MOTOR_ON   0x80   /* status of the Motor On output (WD1770 and WD1772 only) */
192
193/* Type II and III additional flags */
194#define FDC_DELETED_AM   0x01   /* read/write deleted address mark */
195#define FDC_SIDE_CMP_T   0x02   /* side compare track data */
196#define FDC_15MS_DELAY   0x04   /* delay 15ms before command */
197#define FDC_SIDE_CMP_S   0x08   /* side compare sector data */
198#define FDC_MULTI_REC   0x10   /* only for type II commands */
199
200/* Type II commands */
201#define FDC_READ_SEC   0x80   /* read sector */
202#define FDC_WRITE_SEC   0xA0   /* write sector */
203
204#define FDC_MASK_TYPE_II      (FDC_MULTI_REC|FDC_SIDE_CMP_S|FDC_15MS_DELAY|FDC_SIDE_CMP_T|FDC_DELETED_AM)
205
206/* Type II commands status */
207#define STA_2_BUSY      0x01
208#define STA_2_DRQ      0x02
209#define STA_2_LOST_DAT   0x04
210#define STA_2_CRC_ERR   0x08
211#define STA_2_REC_N_FND 0x10
212#define STA_2_REC_TYPE   0x20
213#define STA_2_WRITE_PRO 0x40
214#define STA_2_NOT_READY 0x80
215
216#define FDC_MASK_TYPE_III      (FDC_SIDE_CMP_S|FDC_15MS_DELAY|FDC_SIDE_CMP_T|FDC_DELETED_AM)
217
218/* Type III commands */
219#define FDC_READ_DAM   0xc0   /* read data address mark */
220#define FDC_READ_TRK   0xe0   /* read track */
221#define FDC_WRITE_TRK   0xf0   /* write track (format) */
222
223/* Type IV additional flags */
224#define FDC_IM0       0x01   /* interrupt mode 0 */
225#define FDC_IM1       0x02   /* interrupt mode 1 */
226#define FDC_IM2       0x04   /* interrupt mode 2 */
227#define FDC_IM3       0x08   /* interrupt mode 3 */
228
229#define FDC_MASK_TYPE_IV      (FDC_IM3|FDC_IM2|FDC_IM1|FDC_IM0)
230
231/* Type IV commands */
232#define FDC_FORCE_INT   0xd0   /* force interrupt */
233
234/* structure describing a double density track */
235#define TRKSIZE_DD      6144
236#if 0
237static const UINT8 track_DD[][2] = {
238   {16, 0x4e},    /* 16 * 4E (track lead in)               */
239   { 8, 0x00},    /*  8 * 00 (pre DAM)                     */
240   { 3, 0xf5},    /*  3 * F5 (clear CRC)                   */
241
242   { 1, 0xfe},    /* *** sector *** FE (DAM)               */
243   { 1, 0x80},    /*  4 bytes track,head,sector,seclen     */
244   { 1, 0xf7},    /*  1 * F7 (CRC)                         */
245   {22, 0x4e},    /* 22 * 4E (sector lead in)              */
246   {12, 0x00},    /* 12 * 00 (pre AM)                      */
247   { 3, 0xf5},    /*  3 * F5 (clear CRC)                   */
248   { 1, 0xfb},    /*  1 * FB (AM)                          */
249   { 1, 0x81},    /*  x bytes sector data                  */
250   { 1, 0xf7},    /*  1 * F7 (CRC)                         */
251   {16, 0x4e},    /* 16 * 4E (sector lead out)             */
252   { 8, 0x00},    /*  8 * 00 (post sector)                 */
253   { 0, 0x00},    /* end of data                           */
254};
255#endif
256
257/* structure describing a single density track */
258#define TRKSIZE_SD      3172
259#if 0
260static const UINT8 track_SD[][2] = {
261   {16, 0xff},    /* 16 * FF (track lead in)               */
262   { 8, 0x00},    /*  8 * 00 (pre DAM)                     */
263   { 1, 0xfc},    /*  1 * FC (clear CRC)                   */
264
265   {11, 0xff},    /* *** sector *** 11 * FF                */
266   { 6, 0x00},    /*  6 * 00 (pre DAM)                     */
267   { 1, 0xfe},    /*  1 * FE (DAM)                         */
268   { 1, 0x80},    /*  4 bytes track,head,sector,seclen     */
269   { 1, 0xf7},    /*  1 * F7 (CRC)                         */
270   {10, 0xff},    /* 10 * FF (sector lead in)              */
271   { 4, 0x00},    /*  4 * 00 (pre AM)                      */
272   { 1, 0xfb},    /*  1 * FB (AM)                          */
273   { 1, 0x81},    /*  x bytes sector data                  */
274   { 1, 0xf7},    /*  1 * F7 (CRC)                         */
275   { 0, 0x00},    /* end of data                           */
276};
277#endif
278
279
280/***************************************************************************
281    TYPE DEFINITIONS
282***************************************************************************/
283
284typedef struct _wd1770_state wd1770_state;
285struct _wd1770_state
286{
287   /* callbacks */
288   devcb_resolved_read_line in_dden_func;
289   devcb_resolved_write_line out_intrq_func;
290   devcb_resolved_write_line out_drq_func;
291
292   /* input lines */
293   int mr;            /* master reset */
294   int rdy;           /* ready, enable precomp */
295   int tr00;          /* track 00 */
296   int idx;           /* index */
297   int wprt;          /* write protect */
298   int dden;          /* double density */
299
300   /* output lines */
301   int mo;            /* motor on */
302   int dirc;          /* direction */
303   int drq;           /* data request */
304   int intrq;         /* interrupt request */
305
306   /* register */
307   UINT8 data_shift;
308   UINT8 data;
309   UINT8 track;
310   UINT8 sector;
311   UINT8 command;
312   UINT8 status;
313   UINT8 interrupt;
314
315   int stepping_rate[4];  /* track stepping rate in ms */
316
317        unsigned short  crc;    /* Holds the current CRC value for write_track CRC calculation */
318        int     crc_active;   /* Flag indicating that CRC calculation in write_track is active. */
319
320   UINT8   track_reg;            /* value of track register */
321   UINT8   command_type;         /* last command type */
322   UINT8   head;               /* current head # */
323
324   UINT8   read_cmd;            /* last read command issued */
325   UINT8   write_cmd;            /* last write command issued */
326   INT8   direction;            /* last step direction */
327   UINT8   last_command_data;      /* last command data */
328
329   UINT8   status_drq;          /* status register data request bit */
330   UINT8   busy_count;          /* how long to keep busy bit set */
331
332   UINT8   buffer[6144];         /* I/O buffer (holds up to a whole track) */
333   UINT32   data_offset;         /* offset into I/O buffer */
334   INT32   data_count;          /* transfer count from/into I/O buffer */
335
336   UINT8   *fmt_sector_data[256];   /* pointer to data after formatting a track */
337
338   UINT8   dam_list[256][4];      /* list of data address marks while formatting */
339   int    dam_data[256];         /* offset to data inside buffer while formatting */
340   int    dam_cnt;            /* valid number of entries in the dam_list */
341   UINT16   sector_length;         /* sector length (byte) */
342
343   UINT8   ddam;               /* ddam of sector found - used when reading */
344   UINT8   sector_data_id;
345   int      data_direction;
346
347   int     hld_count;            /* head loaded counter */
348
349   /* timers to delay execution/completion of commands */
350   emu_timer *timer_cmd, *timer_data, *timer_rs, *timer_ws;
351
352   /* this is the drive currently selected */
353   device_t *drive;
354
355   /* this is the head currently selected */
356   UINT8 hd;
357
358   /* pause time when writing/reading sector */
359   int pause_time;
360
361   /* Were we busy when we received a FORCE_INT command */
362   UINT8   was_busy;
363
364   /* Pointer to interface */
365   const wd17xx_interface *intf;
366};
367
368
369/***************************************************************************
370    DEFAULT INTERFACES
371***************************************************************************/
372
373const wd17xx_interface default_wd17xx_interface =
374{
375   DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, { FLOPPY_0, FLOPPY_1, FLOPPY_2, FLOPPY_3}
376};
377
378const wd17xx_interface default_wd17xx_interface_2_drives =
379{
380   DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, { FLOPPY_0, FLOPPY_1, NULL, NULL}
381};
382
383
384/***************************************************************************
385    PROTOTYPES
386***************************************************************************/
387
388static void wd17xx_complete_command(device_t *device, int delay);
389static void wd17xx_timed_data_request(device_t *device);
390static void wd17xx_index_pulse_callback(device_t *controller, device_t *img, int state);
391static int wd17xx_locate_sector(device_t *device);
392static void wd17xx_timed_read_sector_request(device_t *device);
393
394
395/*****************************************************************************
396    INLINE FUNCTIONS
397*****************************************************************************/
398
399INLINE wd1770_state *get_safe_token(device_t *device)
400{
401   assert(device != NULL);
402   assert(device->type() == WD1770 || device->type() == WD1771 || device->type() == WD1772 || device->type() == WD1773 ||
403      device->type() == WD1793 ||   device->type() == WD1795 || device->type() == WD1797 ||
404      device->type() == WD2793 || device->type() == WD2795 || device->type() == WD2797 ||
405      device->type() == WD177X || device->type() == WD179X || device->type() == MB8877);
406
407   return (wd1770_state *)downcast<legacy_device_base *>(device)->token();
408}
409
410
411/***************************************************************************
412    HELPER FUNCTIONS
413***************************************************************************/
414
415static int wd17xx_has_side_select(device_t *device)
416{
417   return (device->type() == WD1795 || device->type() == WD1797 ||
418         device->type() == WD2795 || device->type() == WD2797);
419}
420
421static int wd17xx_dden(device_t *device)
422{
423   wd1770_state *w = get_safe_token(device);
424
425   if (!w->in_dden_func.isnull())
426      return w->in_dden_func();
427   else
428      return w->dden;
429}
430
431
432/***************************************************************************
433    IMPLEMENTATION
434***************************************************************************/
435
436/* clear a data request */
437static void wd17xx_clear_drq(device_t *device)
438{
439   wd1770_state *w = get_safe_token(device);
440
441   w->status &= ~STA_2_DRQ;
442
443   w->drq = CLEAR_LINE;
444   w->out_drq_func(w->drq);
445}
446
447/* set data request */
448static void wd17xx_set_drq(device_t *device)
449{
450   wd1770_state *w = get_safe_token(device);
451
452   if (w->status & STA_2_DRQ)
453      w->status |= STA_2_LOST_DAT;
454
455   w->status |= STA_2_DRQ;
456
457   w->drq = ASSERT_LINE;
458   w->out_drq_func(w->drq);
459}
460
461/* clear interrupt request */
462static void   wd17xx_clear_intrq(device_t *device)
463{
464   wd1770_state *w = get_safe_token(device);
465
466   w->intrq = CLEAR_LINE;
467   w->out_intrq_func(w->intrq);
468}
469
470/* set interrupt request */
471static void   wd17xx_set_intrq(device_t *device)
472{
473   wd1770_state *w = get_safe_token(device);
474
475   w->status &= ~STA_2_BUSY;
476   w->status &= ~STA_2_DRQ;
477
478   w->intrq = ASSERT_LINE;
479   w->out_intrq_func(w->intrq);
480}
481
482/* set intrq after delay */
483static TIMER_CALLBACK( wd17xx_command_callback )
484{
485   device_t *device = (device_t *)ptr;
486   wd1770_state *w = get_safe_token(device);
487
488   if (w->last_command_data != FDC_FORCE_INT)
489   {
490      wd17xx_set_intrq(device);
491   }
492}
493
494/* write next byte to data register and set drq */
495static TIMER_CALLBACK( wd17xx_data_callback )
496{
497   device_t *device = (device_t *)ptr;
498   wd1770_state *w = get_safe_token(device);
499
500   /* check if this is a write command */
501   if( (w->command_type == TYPE_II && w->command == FDC_WRITE_SEC) ||
502         (w->command_type == TYPE_III && w->command == FDC_WRITE_TRK) )
503   {
504      /* we are ready for new data */
505      wd17xx_set_drq(device);
506
507      return;
508   }
509
510   /* any bytes remaining? */
511   if (w->data_count >= 1)
512   {
513      /* yes */
514      w->data = w->buffer[w->data_offset++];
515
516      if (VERBOSE_DATA)
517         logerror("wd17xx_data_callback: $%02X (data_count %d)\n", w->data, w->data_count);
518
519      wd17xx_set_drq(device);
520
521      /* any bytes remaining? */
522      if (--w->data_count < 1)
523      {
524         /* no */
525         w->data_offset = 0;
526
527         /* clear ddam type */
528         w->status &=~STA_2_REC_TYPE;
529
530         /* read a sector with ddam set? */
531         if (w->command_type == TYPE_II && w->ddam != 0)
532         {
533            /* set it */
534            w->status |= STA_2_REC_TYPE;
535         }
536
537         /* check if we should handle the next sector for a multi record read */
538         if (w->command_type == TYPE_II && w->command == FDC_READ_SEC && (w->read_cmd & 0x10))
539         {
540            if (VERBOSE)
541               logerror("wd17xx_data_callback: multi sector read\n");
542
543            if (w->sector == 0xff)
544               w->sector = 0x01;
545            else
546               w->sector++;
547
548            wd17xx_timed_read_sector_request(device);
549         }
550         else
551         {
552            /* Delay the INTRQ 3 byte times because we need to read two CRC bytes and
553                   compare them with a calculated CRC */
554            wd17xx_complete_command(device, DELAY_DATADONE);
555
556            if (VERBOSE)
557               logerror("wd17xx_data_callback: data read completed\n");
558         }
559      }
560      else
561      {
562         /* requeue us for more data */
563         w->timer_data->adjust(attotime::from_usec(wd17xx_dden(device) ? 128 : 32));
564      }
565   }
566   else
567   {
568      logerror("wd17xx_data_callback: (no new data) $%02X (data_count %d)\n", w->data, w->data_count);
569   }
570}
571
572
573static void wd17xx_set_busy(device_t *device, attotime duration)
574{
575   wd1770_state *w = get_safe_token(device);
576
577   w->status |= STA_1_BUSY;
578
579   w->timer_cmd->adjust(duration);
580}
581
582
583/* BUSY COUNT DOESN'T WORK PROPERLY! */
584
585static void wd17xx_command_restore(device_t *device)
586{
587   wd1770_state *w = get_safe_token(device);
588   UINT8 step_counter;
589
590   if (w->drive == NULL)
591      return;
592
593   step_counter = 255;
594
595#if 0
596   w->status |= STA_1_BUSY;
597#endif
598
599   /* setup step direction */
600   w->direction = -1;
601
602   w->command_type = TYPE_I;
603
604   /* reset busy count */
605   w->busy_count = 0;
606
607   if (1) // image_slotexists(w->drive) : FIXME
608   {
609      /* keep stepping until track 0 is received or 255 steps have been done */
610      while (floppy_tk00_r(w->drive) && (step_counter != 0))
611      {
612         /* update time to simulate seek time busy signal */
613         w->busy_count++;
614         floppy_drive_seek(w->drive, w->direction);
615         step_counter--;
616      }
617   }
618
619   /* update track reg */
620   w->track = 0;
621#if 0
622   /* simulate seek time busy signal */
623   w->busy_count = 0;   //w->busy_count * ((w->data & FDC_STEP_RATE) + 1);
624
625   /* when command completes set irq */
626   wd17xx_set_intrq(device);
627#endif
628   wd17xx_set_busy(device, attotime::from_usec(100));
629}
630
631/*
632    Write an entire track. Formats which do not define a write_track
633    function pointer will cause a silent return.
634    What is written to the image depends on the selected format. Sector
635    dumps have to extract the sectors in the track, while track dumps
636    may directly write the bytes.
637    (The if-part below may thus be removed.)
638*/
639static void write_track(device_t *device)
640{
641   wd1770_state *w = get_safe_token(device);
642   floppy_image *floppy;
643#if 0
644   int i;
645   for (i=0;i+4<w->data_offset;)
646   {
647      if (w->buffer[i]==0xfe)
648      {
649         /* got address mark */
650         int track   = w->buffer[i+1];
651         int side    = w->buffer[i+2];
652         int sector  = w->buffer[i+3];
653         //int len     = w->buffer[i+4];
654         int filler  = 0xe5; /* IBM and Thomson */
655         int density = w->density;
656         floppy_drive_format_sector(w->drive,side,sector,track,
657                  w->hd,sector,density?1:0,filler);
658         i += 128; /* at least... */
659      }
660      else
661         i++;
662   }
663#endif
664
665   /* Get the size in bytes of the current track. For real hardware this
666    may vary per system in small degree, and there even for each track
667    and head, so we should not assume a fixed value here.
668    As we are using a buffered track writing, we have to find out how long
669    the track will become. The only object which can tell us is the
670    selected format.
671    */
672   w->data_count = 0;
673   floppy = flopimg_get_image(w->drive);
674   if (floppy != NULL)
675      w->data_count = floppy_get_track_size(floppy, w->hd, w->track);
676
677        if (w->data_count==0)
678        {
679                if (device->type() == WD1771)
680                        w->data_count = TRKSIZE_SD;
681                else
682         w->data_count = wd17xx_dden(device) ? TRKSIZE_SD : TRKSIZE_DD;
683        }
684
685   floppy_drive_write_track_data_info_buffer( w->drive, w->hd, (char *)w->buffer, &(w->data_count) );
686
687   w->data_offset = 0;
688
689   wd17xx_set_drq(device);
690   w->status |= STA_2_BUSY;
691   w->busy_count = 0;
692}
693
694/*
695    Read an entire track. It is up to the format to deliver the data. Sector
696    dumps may be required to fantasize the missing track bytes, while track
697    dumps can directly deliver them.
698    (The if-part below may thus be removed.)
699*/
700static void read_track(device_t *device)
701{
702   wd1770_state *w = get_safe_token(device);
703   floppy_image *floppy;
704#if 0
705   UINT8 *psrc;      /* pointer to track format structure */
706   UINT8 *pdst;      /* pointer to track buffer */
707   int cnt;         /* number of bytes to fill in */
708   UINT16 crc;       /* id or data CRC */
709   UINT8 d;         /* data */
710   UINT8 t = w->track; /* track of DAM */
711   UINT8 h = w->head;   /* head of DAM */
712   UINT8 s = w->sector_dam;      /* sector of DAM */
713   UINT16 l = w->sector_length;   /* sector length of DAM */
714   int i;
715
716   for (i = 0; i < w->sec_per_track; i++)
717   {
718      w->dam_list[i][0] = t;
719      w->dam_list[i][1] = h;
720      w->dam_list[i][2] = i;
721      w->dam_list[i][3] = l >> 8;
722   }
723
724   pdst = w->buffer;
725
726   if (w->density)
727   {
728      psrc = track_DD[0];    /* double density track format */
729      cnt = TRKSIZE_DD;
730   }
731   else
732   {
733      psrc = track_SD[0];    /* single density track format */
734      cnt = TRKSIZE_SD;
735   }
736
737   while (cnt > 0)
738   {
739      if (psrc[0] == 0)      /* no more track format info ? */
740      {
741         if (w->dam_cnt < w->sec_per_track) /* but more DAM info ? */
742         {
743            if (w->density)/* DD track ? */
744               psrc = track_DD[3];
745            else
746               psrc = track_SD[3];
747         }
748      }
749
750      if (psrc[0] != 0)      /* more track format info ? */
751      {
752         cnt -= psrc[0];    /* subtract size */
753         d = psrc[1];
754
755         if (d == 0xf5)      /* clear CRC ? */
756         {
757            crc = 0xffff;
758            d = 0xa1;      /* store A1 */
759         }
760
761         for (i = 0; i < *psrc; i++)
762            *pdst++ = d;   /* fill data */
763
764         if (d == 0xf7)      /* store CRC ? */
765         {
766            pdst--;       /* go back one byte */
767            *pdst++ = crc & 255;   /* put CRC low */
768            *pdst++ = crc / 256;   /* put CRC high */
769            cnt -= 1;      /* count one more byte */
770         }
771         else if (d == 0xfe)/* address mark ? */
772         {
773            crc = 0xffff;   /* reset CRC */
774         }
775         else if (d == 0x80)/* sector ID ? */
776         {
777            pdst--;       /* go back one byte */
778            t = *pdst++ = w->dam_list[w->dam_cnt][0]; /* track number */
779            h = *pdst++ = w->dam_list[w->dam_cnt][1]; /* head number */
780            s = *pdst++ = w->dam_list[w->dam_cnt][2]; /* sector number */
781            l = *pdst++ = w->dam_list[w->dam_cnt][3]; /* sector length code */
782            w->dam_cnt++;
783            crc = ccitt_crc16_one(crc, t);   /* build CRC */
784            crc = ccitt_crc16_one(crc, h);   /* build CRC */
785            crc = ccitt_crc16_one(crc, s);   /* build CRC */
786            crc = ccitt_crc16_one(crc, l);   /* build CRC */
787            l = (l == 0) ? 128 : l << 8;
788         }
789         else if (d == 0xfb)// data address mark ?
790         {
791            crc = 0xffff;   // reset CRC
792         }
793         else if (d == 0x81)// sector DATA ?
794         {
795            pdst--;       /* go back one byte */
796            if (seek(w, t, h, s) == 0)
797            {
798               if (mame_fread(w->image_file, pdst, l) != l)
799               {
800                  w->status = STA_2_CRC_ERR;
801                  return;
802               }
803            }
804            else
805            {
806               w->status = STA_2_REC_N_FND;
807               return;
808            }
809            for (i = 0; i < l; i++) // build CRC of all data
810               crc = ccitt_crc16_one(crc, *pdst++);
811            cnt -= l;
812         }
813         psrc += 2;
814      }
815      else
816      {
817         *pdst++ = 0xff;    /* fill track */
818         cnt--;            /* until end */
819      }
820   }
821#endif
822   /* Determine the track size. We cannot allow different sizes in this
823    design (see above, write_track). */
824   w->data_count = 0;
825   floppy = flopimg_get_image(w->drive);
826   if (floppy != NULL)
827      w->data_count = floppy_get_track_size(floppy, w->hd, w->track);
828
829        if (w->data_count==0)
830        {
831                if (device->type() == WD1771)
832                        w->data_count = TRKSIZE_SD;
833                else
834         w->data_count = wd17xx_dden(device) ? TRKSIZE_SD : TRKSIZE_DD;
835        }
836
837   floppy_drive_read_track_data_info_buffer( w->drive, w->hd, (char *)w->buffer, &(w->data_count) );
838
839   w->data_offset = 0;
840
841   wd17xx_set_drq(device);
842   w->status |= STA_2_BUSY;
843   w->busy_count = 0;
844}
845
846
847/* read the next data address mark */
848static void wd17xx_read_id(device_t *device)
849{
850   chrn_id id;
851   wd1770_state *w = get_safe_token(device);
852
853   w->status &= ~(STA_2_CRC_ERR | STA_2_REC_N_FND);
854
855   /* get next id from disc */
856   if (floppy_drive_get_next_id(w->drive, w->hd, &id))
857   {
858      UINT16 crc = 0xffff;
859
860      w->data_offset = 0;
861      w->data_count = 6;
862
863      /* for MFM */
864      /* crc includes 3x0x0a1, and 1x0x0fe (id mark) */
865      crc = ccitt_crc16_one(crc,0x0a1);
866      crc = ccitt_crc16_one(crc,0x0a1);
867      crc = ccitt_crc16_one(crc,0x0a1);
868      crc = ccitt_crc16_one(crc,0x0fe);
869
870      w->buffer[0] = id.C;
871      w->buffer[1] = id.H;
872      w->buffer[2] = id.R;
873      w->buffer[3] = id.N;
874      crc = ccitt_crc16_one(crc, w->buffer[0]);
875      crc = ccitt_crc16_one(crc, w->buffer[1]);
876      crc = ccitt_crc16_one(crc, w->buffer[2]);
877      crc = ccitt_crc16_one(crc, w->buffer[3]);
878      /* crc is stored hi-byte followed by lo-byte */
879      w->buffer[4] = crc>>8;
880      w->buffer[5] = crc & 255;
881
882      w->sector = id.C;
883
884      if (VERBOSE)
885         logerror("wd17xx_read_id: read id succeeded.\n");
886
887      wd17xx_timed_data_request(device);
888   }
889   else
890   {
891      /* record not found */
892      w->status |= STA_2_REC_N_FND;
893      //w->sector = w->track;
894      if (VERBOSE)
895         logerror("wd17xx_read_id: read id failed\n");
896
897      wd17xx_complete_command(device, DELAY_ERROR);
898   }
899}
900
901
902
903static void wd17xx_index_pulse_callback(device_t *controller, device_t *img, int state)
904{
905   wd1770_state *w = get_safe_token(controller);
906
907   if (img != w->drive)
908      return;
909
910   w->idx = state;
911
912   if (!state && w->idx && BIT(w->interrupt, 2))
913      wd17xx_set_intrq(controller);
914
915   if (w->hld_count)
916      w->hld_count--;
917}
918
919
920
921static int wd17xx_locate_sector(device_t *device)
922{
923   UINT8 revolution_count;
924   chrn_id id;
925   wd1770_state *w = get_safe_token(device);
926
927   revolution_count = 0;
928
929   w->status &= ~STA_2_REC_N_FND;
930
931   while (revolution_count!=4)
932   {
933      if (floppy_drive_get_next_id(w->drive, w->hd, &id))
934      {
935         /* compare track */
936         if (id.C == w->track)
937         {
938            /* compare head, if we were asked to */
939            if (!wd17xx_has_side_select(device) || (id.H == w->head) || (w->head == (UINT8) ~0))
940            {
941               /* compare id */
942               if (id.R == w->sector)
943               {
944                  w->sector_length = 1<<(id.N+7);
945                  w->sector_data_id = id.data_id;
946                  /* get ddam status */
947                  w->ddam = id.flags & ID_FLAG_DELETED_DATA;
948                  /* got record type here */
949                  if (VERBOSE)
950                     logerror("sector found! C:$%02x H:$%02x R:$%02x N:$%02x%s\n", id.C, id.H, id.R, id.N, w->ddam ? " DDAM" : "");
951                  return 1;
952               }
953            }
954         }
955      }
956
957       /* index set? */
958      if (floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_INDEX))
959      {
960         /* update revolution count */
961         revolution_count++;
962      }
963   }
964   return 0;
965}
966
967
968static int wd17xx_find_sector(device_t *device)
969{
970   wd1770_state *w = get_safe_token(device);
971   if ( wd17xx_locate_sector(device) )
972   {
973      return 1;
974   }
975
976   /* record not found */
977   w->status |= STA_2_REC_N_FND;
978
979   if (VERBOSE)
980      logerror("track %d sector %d not found!\n", w->track, w->sector);
981
982   wd17xx_complete_command(device, DELAY_ERROR);
983
984   return 0;
985}
986
987
988
989/* read a sector */
990static void wd17xx_read_sector(device_t *device)
991{
992   wd1770_state *w = get_safe_token(device);
993   w->data_offset = 0;
994
995   /* side compare? */
996   if (w->read_cmd & 0x02)
997      w->head = (w->read_cmd & 0x08) ? 1 : 0;
998   else
999      w->head = ~0;
1000
1001   if (wd17xx_find_sector(device))
1002   {
1003      w->data_count = w->sector_length;
1004
1005      /* read data */
1006      floppy_drive_read_sector_data(w->drive, w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length);
1007
1008      wd17xx_timed_data_request(device);
1009
1010      w->status |= STA_2_BUSY;
1011      w->busy_count = 0;
1012   }
1013}
1014
1015
1016/* called on error, or when command is actually completed */
1017/* KT - I have used a timer for systems that use interrupt driven transfers.
1018A interrupt occurs after the last byte has been read. If it occurs at the time
1019when the last byte has been read it causes problems - same byte read again
1020or bytes missed */
1021/* TJL - I have add a parameter to allow the emulation to specify the delay
1022*/
1023static void wd17xx_complete_command(device_t *device, int delay)
1024{
1025   wd1770_state *w = get_safe_token(device);
1026
1027   w->data_count = 0;
1028
1029   w->hld_count = 2;
1030
1031   /* set new timer */
1032   int usecs = wd17xx_dden(device) ? 32 : 16;
1033   w->timer_cmd->adjust(attotime::from_usec(usecs));
1034
1035   /* Kill onshot read/write sector timers */
1036   w->timer_rs->adjust(attotime::never);
1037   w->timer_ws->adjust(attotime::never);
1038}
1039
1040
1041
1042static void wd17xx_write_sector(device_t *device)
1043{
1044   wd1770_state *w = get_safe_token(device);
1045   /* at this point, the disc is write enabled, and data
1046     * has been transfered into our buffer - now write it to
1047     * the disc image or to the real disc
1048     */
1049
1050   /* side compare? */
1051   if (w->write_cmd & 0x02)
1052      w->head = (w->write_cmd & 0x08) ? 1 : 0;
1053   else
1054      w->head = ~0;
1055
1056   /* find sector */
1057   if (wd17xx_find_sector(device))
1058   {
1059      w->data_count = w->sector_length;
1060
1061      /* write data */
1062      floppy_drive_write_sector_data(w->drive, w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length, w->write_cmd & 0x01);
1063   }
1064}
1065
1066
1067
1068/* verify the seek operation by looking for a id that has a matching track value */
1069static void wd17xx_verify_seek(device_t *device)
1070{
1071   UINT8 revolution_count;
1072   chrn_id id;
1073   wd1770_state *w = get_safe_token(device);
1074
1075   revolution_count = 0;
1076
1077   if (VERBOSE)
1078      logerror("doing seek verify\n");
1079
1080   w->status &= ~STA_1_SEEK_ERR;
1081
1082   /* must be found within 5 revolutions otherwise error */
1083   while (revolution_count!=5)
1084   {
1085      if (floppy_drive_get_next_id(w->drive, w->hd, &id))
1086      {
1087         /* compare track */
1088         if (id.C == w->track)
1089         {
1090            if (VERBOSE)
1091               logerror("seek verify succeeded!\n");
1092            return;
1093         }
1094      }
1095
1096       /* index set? */
1097      if (floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_INDEX))
1098      {
1099         /* update revolution count */
1100         revolution_count++;
1101      }
1102   }
1103
1104   w->status |= STA_1_SEEK_ERR;
1105
1106   if (VERBOSE)
1107      logerror("failed seek verify!\n");
1108}
1109
1110
1111
1112/* callback to initiate read sector */
1113static TIMER_CALLBACK( wd17xx_read_sector_callback )
1114{
1115   device_t *device = (device_t *)ptr;
1116   wd1770_state *w = get_safe_token(device);
1117
1118   /* ok, start that read! */
1119
1120   if (VERBOSE)
1121      logerror("wd179x: Read Sector callback.\n");
1122
1123   if (!floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY))
1124      wd17xx_complete_command(device, DELAY_NOTREADY);
1125   else
1126      wd17xx_read_sector(device);
1127}
1128
1129
1130
1131/* callback to initiate write sector */
1132static TIMER_CALLBACK( wd17xx_write_sector_callback )
1133{
1134   device_t *device = (device_t *)ptr;
1135   wd1770_state *w = get_safe_token(device);
1136
1137   /* ok, start that write! */
1138
1139   if (VERBOSE)
1140      logerror("wd179x: Write Sector callback.\n");
1141
1142   if (!floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY))
1143      wd17xx_complete_command(device, DELAY_NOTREADY);
1144   else
1145   {
1146
1147      /* drive write protected? */
1148      if (floppy_wpt_r(w->drive) == CLEAR_LINE)
1149      {
1150         w->status |= STA_2_WRITE_PRO;
1151
1152         wd17xx_complete_command(device, DELAY_ERROR);
1153      }
1154      else
1155      {
1156         /* side compare? */
1157         if (w->write_cmd & 0x02)
1158            w->head = (w->write_cmd & 0x08) ? 1 : 0;
1159         else
1160            w->head = ~0;
1161
1162         /* attempt to find it first before getting data from cpu */
1163         if (wd17xx_find_sector(device))
1164         {
1165            /* request data */
1166            w->data_offset = 0;
1167            w->data_count = w->sector_length;
1168
1169            wd17xx_set_drq(device);
1170
1171            w->status |= STA_2_BUSY;
1172            w->busy_count = 0;
1173         }
1174      }
1175   }
1176}
1177
1178
1179
1180/* setup a timed data request - data request will be triggered in a few usecs time */
1181static void wd17xx_timed_data_request(device_t *device)
1182{
1183   wd1770_state *w = get_safe_token(device);
1184
1185   /* set new timer */
1186   w->timer_data->adjust(attotime::from_usec(wd17xx_dden(device) ? 128 : 32));
1187}
1188
1189
1190
1191/* setup a timed read sector - read sector will be triggered in a few usecs time */
1192static void wd17xx_timed_read_sector_request(device_t *device)
1193{
1194   wd1770_state *w = get_safe_token(device);
1195
1196   /* set new timer */
1197   w->timer_rs->adjust(attotime::from_usec(w->pause_time));
1198}
1199
1200
1201
1202/* setup a timed write sector - write sector will be triggered in a few usecs time */
1203static void wd17xx_timed_write_sector_request(device_t *device)
1204{
1205   wd1770_state *w = get_safe_token(device);
1206
1207   /* set new timer */
1208   w->timer_ws->adjust(attotime::from_usec(w->pause_time));
1209}
1210
1211
1212/***************************************************************************
1213    INTERFACE
1214***************************************************************************/
1215
1216/* use this to determine which drive is controlled by WD */
1217void wd17xx_set_drive(device_t *device, UINT8 drive)
1218{
1219   wd1770_state *w = get_safe_token(device);
1220
1221   if (VERBOSE)
1222      logerror("wd17xx_set_drive: $%02x\n", drive);
1223
1224   if (w->intf->floppy_drive_tags[drive] != NULL)
1225   {
1226      if (device->owner() != NULL) {
1227         w->drive = device->owner()->subdevice(w->intf->floppy_drive_tags[drive]);
1228         if (w->drive == NULL) {
1229            w->drive = device->machine().device(w->intf->floppy_drive_tags[drive]);
1230         }
1231      }
1232      else
1233         w->drive = device->machine().device(w->intf->floppy_drive_tags[drive]);
1234   }
1235}
1236
1237void wd17xx_set_side(device_t *device, UINT8 head)
1238{
1239   wd1770_state *w = get_safe_token(device);
1240
1241   if (VERBOSE)
1242   {
1243      if (head != w->hd)
1244         logerror("wd17xx_set_side: $%02x\n", head);
1245   }
1246
1247   w->hd = head;
1248}
1249
1250void wd17xx_set_pause_time(device_t *device, int usec)
1251{
1252   wd1770_state *w = get_safe_token(device);
1253   w->pause_time = usec;
1254}
1255
1256
1257/***************************************************************************
1258    DEVICE HANDLERS
1259***************************************************************************/
1260
1261/* master reset */
1262WRITE_LINE_DEVICE_HANDLER( wd17xx_mr_w )
1263{
1264   wd1770_state *w = get_safe_token(device);
1265
1266   /* reset device when going from high to low */
1267   if (w->mr && state == CLEAR_LINE)
1268   {
1269      w->command = 0x03;
1270      w->status &= ~STA_1_NOT_READY; /* ? */
1271   }
1272
1273   /* execute restore command when going from low to high */
1274   if (w->mr == CLEAR_LINE && state)
1275   {
1276      wd17xx_command_restore(device);
1277      w->sector = 0x01;
1278   }
1279
1280   w->mr = state;
1281}
1282
1283/* ready and enable precomp (1773 only) */
1284WRITE_LINE_DEVICE_HANDLER( wd17xx_rdy_w )
1285{
1286   wd1770_state *w = get_safe_token(device);
1287   w->rdy = state;
1288}
1289
1290/* motor on, 1770 and 1772 only */
1291READ_LINE_DEVICE_HANDLER( wd17xx_mo_r )
1292{
1293   wd1770_state *w = get_safe_token(device);
1294   return w->mo;
1295}
1296
1297/* track zero */
1298WRITE_LINE_DEVICE_HANDLER( wd17xx_tr00_w )
1299{
1300   wd1770_state *w = get_safe_token(device);
1301   w->tr00 = state;
1302}
1303
1304/* index pulse */
1305WRITE_LINE_DEVICE_HANDLER( wd17xx_idx_w )
1306{
1307   wd1770_state *w = get_safe_token(device);
1308   w->idx = state;
1309
1310   if (!state && w->idx && BIT(w->interrupt, 2))
1311      wd17xx_set_intrq(device);
1312}
1313
1314/* write protect status */
1315WRITE_LINE_DEVICE_HANDLER( wd17xx_wprt_w )
1316{
1317   wd1770_state *w = get_safe_token(device);
1318   w->wprt = state;
1319}
1320
1321/* double density enable */
1322WRITE_LINE_DEVICE_HANDLER( wd17xx_dden_w )
1323{
1324   wd1770_state *w = get_safe_token(device);
1325
1326   /* not supported on FD1771, FD1792, FD1794, FD1762 and FD1764 */
1327   if (device->type() == WD1771)
1328      fatalerror("wd17xx_dden_w: double density input not supported on this model!");
1329   else if (!w->in_dden_func.isnull())
1330      logerror("wd17xx_dden_w: write has no effect because a read handler is already defined!\n");
1331   else
1332      w->dden = state;
1333}
1334
1335/* data request */
1336READ_LINE_DEVICE_HANDLER( wd17xx_drq_r )
1337{
1338   wd1770_state *w = get_safe_token(device);
1339   return w->drq;
1340}
1341
1342/* interrupt request */
1343READ_LINE_DEVICE_HANDLER( wd17xx_intrq_r )
1344{
1345   wd1770_state *w = get_safe_token(device);
1346   return w->intrq;
1347}
1348
1349/* read the FDC status register. This clears IRQ line too */
1350READ8_DEVICE_HANDLER( wd17xx_status_r )
1351{
1352   wd1770_state *w = get_safe_token(device);
1353   int result;
1354
1355   if (!BIT(w->interrupt, 3))
1356   {
1357      wd17xx_clear_intrq(device);
1358   }
1359
1360   /* bit 7, 'not ready' or 'motor on' */
1361   if (device->type() == WD1770 || device->type() == WD1772)
1362   {
1363      w->status &= ~STA_1_MOTOR_ON;
1364      w->status |= w->mo << 7;
1365   }
1366   else
1367   {
1368      w->status &= ~STA_1_NOT_READY;
1369      if (!floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY))
1370         w->status |= STA_1_NOT_READY;
1371   }
1372
1373   result = w->status;
1374
1375   /* type 1 command or force int command? */
1376   if ((w->command_type==TYPE_I) || (w->command_type==TYPE_IV && ! w->was_busy))
1377   {
1378      result &= ~(STA_1_IPL | STA_1_TRACK0);
1379
1380      /* bit 1, index pulse */
1381      result |= w->idx << 1;
1382
1383      /* bit 2, track 0 state, inverted */
1384      result |= !floppy_tk00_r(w->drive) << 2;
1385
1386      if (w->command_type==TYPE_I)
1387      {
1388         if (w->hld_count)
1389            w->status |= STA_1_HD_LOADED;
1390         else
1391            w->status &= ~ STA_1_HD_LOADED;
1392      }
1393
1394      /* bit 6, write protect, inverted */
1395      result |= !floppy_wpt_r(w->drive) << 6;
1396   }
1397
1398   /* eventually set data request bit */
1399//  w->status |= w->status_drq;
1400
1401   if (VERBOSE)
1402   {
1403      if (w->data_count < 4)
1404         logerror("%s: wd17xx_status_r: $%02X (data_count %d)\n", device->machine().describe_context(), result, w->data_count);
1405   }
1406
1407   return result;
1408}
1409
1410/* read the FDC track register */
1411READ8_DEVICE_HANDLER( wd17xx_track_r )
1412{
1413   wd1770_state *w = get_safe_token(device);
1414
1415   if (VERBOSE)
1416      logerror("%s: wd17xx_track_r: $%02X\n", device->machine().describe_context(), w->track);
1417
1418   return w->track;
1419}
1420
1421/* read the FDC sector register */
1422READ8_DEVICE_HANDLER( wd17xx_sector_r )
1423{
1424   wd1770_state *w = get_safe_token(device);
1425
1426   if (VERBOSE)
1427      logerror("%s: wd17xx_sector_r: $%02X\n", device->machine().describe_context(), w->sector);
1428
1429   return w->sector;
1430}
1431
1432/* read the FDC data register */
1433READ8_DEVICE_HANDLER( wd17xx_data_r )
1434{
1435   wd1770_state *w = get_safe_token(device);
1436
1437   if (VERBOSE_DATA)
1438      logerror("%s: wd17xx_data_r: %02x\n", device->machine().describe_context(), w->data);
1439
1440   /* clear data request */
1441   wd17xx_clear_drq(device);
1442
1443   return w->data;
1444}
1445
1446/* write the FDC command register */
1447WRITE8_DEVICE_HANDLER( wd17xx_command_w )
1448{
1449   wd1770_state *w = get_safe_token(device);
1450
1451   w->last_command_data = data;
1452
1453   /* only the WD1770 and WD1772 have a 'motor on' line */
1454   if (device->type() == WD1770 || device->type() == WD1772)
1455   {
1456      w->mo = ASSERT_LINE;
1457      floppy_mon_w(w->drive, CLEAR_LINE);
1458   }
1459
1460   floppy_drive_set_ready_state(w->drive, 1,0);
1461
1462   if (!BIT(w->interrupt, 3))
1463   {
1464      wd17xx_clear_intrq(device);
1465   }
1466
1467   /* clear write protected. On read sector, read track and read dam, write protected bit is clear */
1468   w->status &= ~((1<<6) | (1<<5) | (1<<4));
1469
1470   if ((data & ~FDC_MASK_TYPE_IV) == FDC_FORCE_INT)
1471   {
1472      if (VERBOSE)
1473         logerror("%s: wd17xx_command_w $%02X FORCE_INT (data_count %d)\n", device->machine().describe_context(), data, w->data_count);
1474
1475      w->data_count = 0;
1476      w->data_offset = 0;
1477      w->was_busy = w->status & STA_2_BUSY;
1478      w->status &= ~STA_2_BUSY;
1479
1480      wd17xx_clear_drq(device);
1481
1482      if (!BIT(w->interrupt, 3) && BIT(data, 3))
1483      {
1484         /* set immediate interrupt */
1485         wd17xx_set_intrq(device);
1486      }
1487
1488      if (BIT(w->interrupt, 3))
1489      {
1490         if (data == FDC_FORCE_INT)
1491         {
1492            /* clear immediate interrupt */
1493            w->interrupt = data & 0x0f;
1494         }
1495         else
1496         {
1497            /* keep immediate interrupt */
1498            w->interrupt = 0x08 | (data & 0x07);
1499         }
1500      }
1501      else
1502      {
1503         w->interrupt = data & 0x0f;
1504      }
1505
1506      /* terminate command */
1507      wd17xx_complete_command(device, DELAY_ERROR);
1508
1509      w->busy_count = 0;
1510      w->command_type = TYPE_IV;
1511      return;
1512   }
1513
1514   if (data & 0x80)
1515   {
1516      /*w->status_ipl = 0;*/
1517
1518      if ((data & ~FDC_MASK_TYPE_II) == FDC_READ_SEC)
1519      {
1520         if (VERBOSE)
1521            {
1522            logerror("%s: wd17xx_command_w $%02X READ_SEC (", device->machine().describe_context(), data);
1523                logerror("cmd=%02X, trk=%02X, sec=%02X, dat=%02X)\n",w->command,w->track,w->sector,w->data);
1524            }
1525         w->read_cmd = data;
1526         w->command = data & ~FDC_MASK_TYPE_II;
1527         w->command_type = TYPE_II;
1528         w->status &= ~STA_2_LOST_DAT;
1529         w->status |= STA_2_BUSY;
1530         wd17xx_clear_drq(device);
1531
1532         wd17xx_timed_read_sector_request(device);
1533
1534         return;
1535      }
1536
1537      if ((data & ~FDC_MASK_TYPE_II) == FDC_WRITE_SEC)
1538      {
1539         if (VERBOSE)
1540            {
1541            logerror("%s: wd17xx_command_w $%02X WRITE_SEC (", device->machine().describe_context(), data);
1542                logerror("cmd=%02X, trk=%02X, sec=%02X, dat=%02X)\n",w->command,w->track,w->sector,w->data);
1543            }
1544
1545         w->write_cmd = data;
1546         w->command = data & ~FDC_MASK_TYPE_II;
1547         w->command_type = TYPE_II;
1548         w->status &= ~STA_2_LOST_DAT;
1549         w->status |= STA_2_BUSY;
1550         wd17xx_clear_drq(device);
1551
1552         wd17xx_timed_write_sector_request(device);
1553
1554         return;
1555      }
1556
1557      if ((data & ~FDC_MASK_TYPE_III) == FDC_READ_TRK)
1558      {
1559         if (VERBOSE)
1560            logerror("%s: wd17xx_command_w $%02X READ_TRK\n", device->machine().describe_context(), data);
1561
1562         w->command = data & ~FDC_MASK_TYPE_III;
1563         w->command_type = TYPE_III;
1564         w->status &= ~STA_2_LOST_DAT;
1565         wd17xx_clear_drq(device);
1566#if 1
1567//          w->status = seek(w, w->track, w->head, w->sector);
1568         if (w->status == 0)
1569            read_track(device);
1570#endif
1571         return;
1572      }
1573
1574      if ((data & ~FDC_MASK_TYPE_III) == FDC_WRITE_TRK)
1575      {
1576         if (VERBOSE)
1577            logerror("%s: wd17xx_command_w $%02X WRITE_TRK\n", device->machine().describe_context(), data);
1578
1579         w->command_type = TYPE_III;
1580         w->status &= ~STA_2_LOST_DAT;
1581         wd17xx_clear_drq(device);
1582
1583         if (!floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY))
1584         {
1585            wd17xx_complete_command(device, DELAY_NOTREADY);
1586         }
1587         else
1588         {
1589
1590            /* drive write protected? */
1591            if (floppy_wpt_r(w->drive) == CLEAR_LINE)
1592            {
1593            /* yes */
1594               w->status |= STA_2_WRITE_PRO;
1595            /* quit command */
1596               wd17xx_complete_command(device, DELAY_ERROR);
1597            }
1598            else
1599            {
1600            w->command = data & ~FDC_MASK_TYPE_III;
1601            w->data_offset = 0;
1602            if (device->type() == WD1771)
1603               w->data_count = TRKSIZE_SD;
1604            else
1605               w->data_count = wd17xx_dden(device) ? TRKSIZE_SD : TRKSIZE_DD;
1606
1607            wd17xx_set_drq(device);
1608            w->status |= STA_2_BUSY;
1609            w->busy_count = 0;
1610            }
1611         }
1612         return;
1613      }
1614
1615      if ((data & ~FDC_MASK_TYPE_III) == FDC_READ_DAM)
1616      {
1617         if (VERBOSE)
1618            logerror("%s: wd17xx_command_w $%02X READ_DAM\n", device->machine().describe_context(), data);
1619
1620         w->command_type = TYPE_III;
1621         w->command = data & ~FDC_MASK_TYPE_III;
1622         w->status &= ~STA_2_LOST_DAT;
1623         w->status |= STA_2_BUSY;
1624
1625         wd17xx_clear_drq(device);
1626
1627         if (floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY))
1628            wd17xx_read_id(device);
1629         else
1630            wd17xx_complete_command(device, DELAY_NOTREADY);
1631
1632         return;
1633      }
1634
1635      if (VERBOSE)
1636         logerror("%s: wd17xx_command_w $%02X unknown\n", device->machine().describe_context(), data);
1637
1638      return;
1639   }
1640
1641   w->status |= STA_1_BUSY;
1642
1643   /* clear CRC error */
1644   w->status &=~STA_1_CRC_ERR;
1645
1646   if ((data & ~FDC_MASK_TYPE_I) == FDC_RESTORE)
1647   {
1648      if (VERBOSE)
1649         logerror("%s: wd17xx_command_w $%02X RESTORE\n", device->machine().describe_context(), data);
1650
1651      wd17xx_command_restore(device);
1652   }
1653
1654   if ((data & ~FDC_MASK_TYPE_I) == FDC_SEEK)
1655   {
1656      UINT8 newtrack;
1657
1658      if (VERBOSE)
1659         logerror("old track: $%02x new track: $%02x\n", w->track, w->data);
1660      w->command_type = TYPE_I;
1661
1662      /* setup step direction */
1663      if (w->track < w->data)
1664      {
1665         if (VERBOSE)
1666            logerror("direction: +1\n");
1667
1668         w->direction = 1;
1669      }
1670      else if (w->track > w->data)
1671      {
1672         if (VERBOSE)
1673            logerror("direction: -1\n");
1674
1675         w->direction = -1;
1676      }
1677
1678      newtrack = w->data;
1679      if (VERBOSE)
1680         logerror("%s: wd17xx_command_w $%02X SEEK (data_reg is $%02X)\n", device->machine().describe_context(), data, newtrack);
1681
1682      /* reset busy count */
1683      w->busy_count = 0;
1684
1685      /* keep stepping until reached track programmed */
1686      while (w->track != newtrack)
1687      {
1688         /* update time to simulate seek time busy signal */
1689         w->busy_count++;
1690
1691         /* update track reg */
1692         w->track += w->direction;
1693
1694         floppy_drive_seek(w->drive, w->direction);
1695      }
1696
1697      /* simulate seek time busy signal */
1698      w->busy_count = 0;   //w->busy_count * ((data & FDC_STEP_RATE) + 1);
1699#if 0
1700      wd17xx_set_intrq(device);
1701#endif
1702      wd17xx_set_busy(device, attotime::from_usec(100));
1703
1704   }
1705
1706   if ((data & ~(FDC_STEP_UPDATE | FDC_MASK_TYPE_I)) == FDC_STEP)
1707   {
1708      if (VERBOSE)
1709         logerror("%s: wd17xx_command_w $%02X STEP dir %+d\n", device->machine().describe_context(), data, w->direction);
1710
1711      w->command_type = TYPE_I;
1712        /* if it is a real floppy, issue a step command */
1713      /* simulate seek time busy signal */
1714      w->busy_count = 0;   //((data & FDC_STEP_RATE) + 1);
1715
1716      floppy_drive_seek(w->drive, w->direction);
1717
1718      if (data & FDC_STEP_UPDATE)
1719         w->track += w->direction;
1720
1721#if 0
1722      wd17xx_set_intrq(device);
1723#endif
1724      wd17xx_set_busy(device, attotime::from_usec(100));
1725
1726
1727   }
1728
1729   if ((data & ~(FDC_STEP_UPDATE | FDC_MASK_TYPE_I)) == FDC_STEP_IN)
1730   {
1731      if (VERBOSE)
1732         logerror("%s: wd17xx_command_w $%02X STEP_IN\n", device->machine().describe_context(), data);
1733
1734      w->command_type = TYPE_I;
1735      w->direction = +1;
1736      /* simulate seek time busy signal */
1737      w->busy_count = 0;   //((data & FDC_STEP_RATE) + 1);
1738
1739      floppy_drive_seek(w->drive, w->direction);
1740
1741      if (data & FDC_STEP_UPDATE)
1742         w->track += w->direction;
1743#if 0
1744      wd17xx_set_intrq(device);
1745#endif
1746      wd17xx_set_busy(device, attotime::from_usec(100));
1747
1748   }
1749
1750   if ((data & ~(FDC_STEP_UPDATE | FDC_MASK_TYPE_I)) == FDC_STEP_OUT)
1751   {
1752      if (VERBOSE)
1753         logerror("%s: wd17xx_command_w $%02X STEP_OUT\n", device->machine().describe_context(), data);
1754
1755      w->command_type = TYPE_I;
1756      w->direction = -1;
1757      /* simulate seek time busy signal */
1758      w->busy_count = 0;   //((data & FDC_STEP_RATE) + 1);
1759
1760      /* for now only allows a single drive to be selected */
1761      floppy_drive_seek(w->drive, w->direction);
1762
1763      if (data & FDC_STEP_UPDATE)
1764         w->track += w->direction;
1765
1766#if 0
1767      wd17xx_set_intrq(device);
1768#endif
1769      wd17xx_set_busy(device, attotime::from_usec(100));
1770   }
1771
1772   if (w->command_type == TYPE_I)
1773   {
1774      /* 0 is enable spin up sequence, 1 is disable spin up sequence */
1775      if ((data & FDC_STEP_HDLOAD)==0)
1776      {
1777         w->status |= STA_1_HD_LOADED;
1778         w->hld_count = 2;
1779      }
1780      else
1781         w->status &= ~STA_1_HD_LOADED;
1782
1783      if (data & FDC_STEP_VERIFY)
1784      {
1785         /* verify seek */
1786         wd17xx_verify_seek(device);
1787      }
1788   }
1789}
1790
1791/* write the FDC track register */
1792WRITE8_DEVICE_HANDLER( wd17xx_track_w )
1793{
1794   wd1770_state *w = get_safe_token(device);
1795
1796   w->track = data;
1797
1798   if (VERBOSE)
1799      logerror("%s: wd17xx_track_w $%02X\n", device->machine().describe_context(), data);
1800}
1801
1802/* write the FDC sector register */
1803WRITE8_DEVICE_HANDLER( wd17xx_sector_w )
1804{
1805   wd1770_state *w = get_safe_token(device);
1806
1807   w->sector = data;
1808
1809   if (VERBOSE)
1810      logerror("%s: wd17xx_sector_w $%02X\n", device->machine().describe_context(), data);
1811}
1812
1813/* write the FDC data register */
1814WRITE8_DEVICE_HANDLER( wd17xx_data_w )
1815{
1816   wd1770_state *w = get_safe_token(device);
1817
1818   if (w->data_count > 0)
1819   {
1820      wd17xx_clear_drq(device);
1821
1822      /* put byte into buffer */
1823      if (VERBOSE_DATA)
1824         logerror("wd17xx_info buffered data: $%02X at offset %d.\n", data, w->data_offset);
1825
1826      w->buffer[w->data_offset++] = data;
1827
1828                if (--w->data_count < 1)
1829                {
1830                        if (w->command == FDC_WRITE_TRK)
1831                                write_track(device);
1832                        else
1833                                wd17xx_write_sector(device);
1834
1835                        w->data_offset = 0;
1836
1837                  /* Check we should handle the next sector for a multi record write */
1838                  if ( w->command_type == TYPE_II && w->command == FDC_WRITE_SEC && ( w->write_cmd & FDC_MULTI_REC ) )
1839                  {
1840                     w->sector++;
1841                     if (wd17xx_locate_sector(device))
1842                     {
1843                        w->data_count = w->sector_length;
1844
1845                        w->status |= STA_2_BUSY;
1846                        w->busy_count = 0;
1847
1848                        wd17xx_timed_data_request(device);
1849                     }
1850                  }
1851                  else
1852                  {
1853                     wd17xx_complete_command(device, DELAY_DATADONE);
1854                     if (VERBOSE)
1855                        logerror("wd17xx_data_w(): multi data write completed\n");
1856                  }
1857//                       wd17xx_complete_command(device, DELAY_DATADONE);
1858                }
1859                else
1860                {
1861                        if (w->command == FDC_WRITE_TRK)
1862                        {
1863                                /* Process special data values according to WD17xx specification.
1864                   Note that as CRC values take up two bytes which are written on
1865                   every 0xf7 byte, this will cause the actual image to
1866                   grow larger than what was written from the system. So we need
1867                   to take the value of data_offset when writing the track.
1868                                */
1869                                if (wd17xx_dden(device))
1870                                {
1871                                        switch (data)
1872                                        {
1873                                        case 0xf5:
1874                                        case 0xf6:
1875                                                /* not allowed in FM. */
1876                                                /* Take back the last write. */
1877                                                w->data_offset--;
1878                                                break;
1879                                        case 0xf7:
1880                                                /* Take back the last write. */
1881                                                w->data_offset--;
1882                                                /* write two crc bytes */
1883                                                w->buffer[w->data_offset++] = (w->crc>>8)&0xff;
1884                                                w->buffer[w->data_offset++] = (w->crc&0xff);
1885                                                w->crc_active = FALSE;
1886                                                break;
1887                                        case 0xf8:
1888                                        case 0xf9:
1889                                        case 0xfa:
1890                                        case 0xfb:
1891                                        case 0xfe:
1892                                                /* Preset crc */
1893                                                w->crc = 0xffff;
1894                  /* AM is included in the CRC */
1895                  w->crc = ccitt_crc16_one(w->crc, data);
1896                                                w->crc_active = TRUE;
1897                                                break;
1898                                        case 0xfc:
1899                                                /* Write index mark. No effect here as we do not store clock patterns.
1900                           Maybe later. */
1901                                                break;
1902                                        case 0xfd:
1903                                                /* Just write, don't use for CRC. */
1904                                                break;
1905                                        default:
1906                                                /* Byte already written. */
1907                                                if (w->crc_active)
1908                                                        w->crc = ccitt_crc16_one(w->crc, data);
1909                                        }
1910                                }
1911                                else  /* MFM */
1912                                {
1913                                        switch (data)
1914                                        {
1915                                        case 0xf5:
1916                                                /* Take back the last write. */
1917                                                w->data_offset--;
1918                                                /* Write a1 */
1919                                                w->buffer[w->data_offset++] = 0xa1;
1920                                                /* Preset CRC */
1921                                                w->crc = 0xffff;
1922                                                w->crc_active = TRUE;
1923                                                break;
1924                                        case 0xf6:
1925                                                /* Take back the last write. */
1926                                                w->data_offset--;
1927                                                /* Write c2 */
1928                                                w->buffer[w->data_offset++] = 0xc2;
1929                                                break;
1930                                        case 0xf7:
1931                                                /* Take back the last write. */
1932                                                w->data_offset--;
1933                                                /* write two crc bytes */
1934                                                w->buffer[w->data_offset++] = (w->crc>>8)&0xff;
1935                                                w->buffer[w->data_offset++] = (w->crc&0xff);
1936                                                w->crc_active = FALSE;
1937                                                break;
1938                                        case 0xf8:
1939                                        case 0xf9:
1940                                        case 0xfa:
1941                                        case 0xfb:
1942                                        case 0xfc:
1943                                        case 0xfd:
1944                                                /* Just write, don't use for CRC. */
1945                                                break;
1946                                        case 0xfe:
1947                  /* AM is included in the CRC */
1948                  if (w->crc_active)
1949                     w->crc = ccitt_crc16_one(w->crc, data);
1950                                                break;
1951                                        default:
1952                                                /* Byte already written. */
1953                                                if (w->crc_active)
1954                                                        w->crc = ccitt_crc16_one(w->crc, data);
1955                                        }
1956                                }
1957                        }
1958                        /* yes... setup a timed data request */
1959                        wd17xx_timed_data_request(device);
1960                }
1961   }
1962   else
1963   {
1964      if (VERBOSE)
1965         logerror("%s: wd17xx_data_w $%02X\n", device->machine().describe_context(), data);
1966   }
1967   w->data = data;
1968}
1969
1970READ8_DEVICE_HANDLER( wd17xx_r )
1971{
1972   switch (offset & 0x03)
1973   {
1974   case 0: return wd17xx_status_r(device, 0);
1975   case 1:   return wd17xx_track_r(device, 0);
1976   case 2:   return wd17xx_sector_r(device, 0);
1977   case 3:   return wd17xx_data_r(device, 0);
1978   }
1979
1980   return 0;
1981}
1982
1983WRITE8_DEVICE_HANDLER( wd17xx_w )
1984{
1985   switch (offset & 0x03)
1986   {
1987   case 0: wd17xx_command_w(device, 0, data); break;
1988   case 1:   wd17xx_track_w(device, 0, data);   break;
1989   case 2: wd17xx_sector_w(device, 0, data);  break;
1990   case 3: wd17xx_data_w(device, 0, data);    break;
1991   }
1992}
1993
1994
1995/***************************************************************************
1996    MAME DEVICE INTERFACE
1997***************************************************************************/
1998
1999static DEVICE_START( wd1770 )
2000{
2001   wd1770_state *w = get_safe_token(device);
2002
2003   assert(device->static_config() != NULL);
2004
2005   w->intf = (const wd17xx_interface*)device->static_config();
2006
2007   w->status = STA_1_TRACK0;
2008   w->pause_time = 1000;
2009
2010   /* allocate timers */
2011   w->timer_cmd = device->machine().scheduler().timer_alloc(FUNC(wd17xx_command_callback), (void *)device);
2012   w->timer_data = device->machine().scheduler().timer_alloc(FUNC(wd17xx_data_callback), (void *)device);
2013   w->timer_rs = device->machine().scheduler().timer_alloc(FUNC(wd17xx_read_sector_callback), (void *)device);
2014   w->timer_ws = device->machine().scheduler().timer_alloc(FUNC(wd17xx_write_sector_callback), (void *)device);
2015
2016   /* resolve callbacks */
2017   w->in_dden_func.resolve(w->intf->in_dden_func, *device);
2018   w->out_intrq_func.resolve(w->intf->out_intrq_func, *device);
2019   w->out_drq_func.resolve(w->intf->out_drq_func, *device);
2020
2021   /* stepping rate depends on the clock */
2022   w->stepping_rate[0] = 6;
2023   w->stepping_rate[1] = 12;
2024   w->stepping_rate[2] = 20;
2025   w->stepping_rate[3] = 30;
2026}
2027
2028static DEVICE_START( wd1772 )
2029{
2030   wd1770_state *w = get_safe_token(device);
2031
2032   DEVICE_START_CALL(wd1770);
2033
2034   /* the 1772 has faster track stepping rates */
2035   w->stepping_rate[0] = 6;
2036   w->stepping_rate[1] = 12;
2037   w->stepping_rate[2] = 2;
2038   w->stepping_rate[3] = 3;
2039}
2040
2041static DEVICE_RESET( wd1770 )
2042{
2043   wd1770_state *w = get_safe_token(device);
2044   int i;
2045
2046   /* set the default state of some input lines */
2047   w->mr = ASSERT_LINE;
2048   w->wprt = ASSERT_LINE;
2049   w->dden = ASSERT_LINE;
2050
2051   for (i = 0; i < 4; i++)
2052   {
2053      if(w->intf->floppy_drive_tags[i]!=NULL) {
2054         device_t *img = NULL;
2055
2056         if (device->owner() != NULL)
2057            img = device->owner()->subdevice(w->intf->floppy_drive_tags[i]);
2058            if (img == NULL) {
2059               img = device->machine().device(w->intf->floppy_drive_tags[i]);
2060            }
2061
2062         else
2063            img = device->machine().device(w->intf->floppy_drive_tags[i]);
2064
2065         if (img!=NULL) {
2066            floppy_drive_set_controller(img,device);
2067            floppy_drive_set_index_pulse_callback(img, wd17xx_index_pulse_callback);
2068            floppy_drive_set_rpm( img, 300.);
2069         }
2070      }
2071   }
2072
2073   wd17xx_set_drive(device, 0);
2074
2075   w->hd = 0;
2076   w->hld_count = 0;
2077   w->sector = 1;
2078   wd17xx_command_restore(device);
2079}
2080
2081void wd17xx_reset(device_t *device)
2082{
2083   DEVICE_RESET_CALL( wd1770 );
2084}
2085
2086
2087/***************************************************************************
2088    DEVICE GETINFO
2089***************************************************************************/
2090
2091static const char DEVTEMPLATE_SOURCE[] = __FILE__;
2092
2093#define DEVTEMPLATE_ID(p,s)            p##wd1770##s
2094#define DEVTEMPLATE_FEATURES         DT_HAS_START | DT_HAS_RESET
2095#define DEVTEMPLATE_NAME            "WD1770"
2096#define DEVTEMPLATE_FAMILY            "WD17xx"
2097#define DEVTEMPLATE_VERSION            "1.0"
2098#define DEVTEMPLATE_CREDITS            "Copyright MESS Team"
2099#include "devtempl.h"
2100
2101#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd1771##s
2102#define DEVTEMPLATE_DERIVED_FEATURES   0
2103#define DEVTEMPLATE_DERIVED_NAME      "WD1771"
2104#include "devtempl.h"
2105
2106#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd1772##s
2107#define DEVTEMPLATE_DERIVED_FEATURES   DT_HAS_START
2108#define DEVTEMPLATE_DERIVED_NAME      "WD1772"
2109#include "devtempl.h"
2110
2111#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd1773##s
2112#define DEVTEMPLATE_DERIVED_FEATURES   0
2113#define DEVTEMPLATE_DERIVED_NAME      "WD1773"
2114#include "devtempl.h"
2115
2116#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd1793##s
2117#define DEVTEMPLATE_DERIVED_FEATURES   0
2118#define DEVTEMPLATE_DERIVED_NAME      "WD1793"
2119#include "devtempl.h"
2120
2121#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd1795##s
2122#define DEVTEMPLATE_DERIVED_FEATURES   0
2123#define DEVTEMPLATE_DERIVED_NAME      "WD1795"
2124#include "devtempl.h"
2125
2126#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd1797##s
2127#define DEVTEMPLATE_DERIVED_FEATURES   0
2128#define DEVTEMPLATE_DERIVED_NAME      "WD1797"
2129#include "devtempl.h"
2130
2131#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd2793##s
2132#define DEVTEMPLATE_DERIVED_FEATURES   0
2133#define DEVTEMPLATE_DERIVED_NAME      "WD2793"
2134#include "devtempl.h"
2135
2136#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd2795##s
2137#define DEVTEMPLATE_DERIVED_FEATURES   0
2138#define DEVTEMPLATE_DERIVED_NAME      "WD2795"
2139#include "devtempl.h"
2140
2141#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd2797##s
2142#define DEVTEMPLATE_DERIVED_FEATURES   0
2143#define DEVTEMPLATE_DERIVED_NAME      "WD2797"
2144#include "devtempl.h"
2145
2146#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd177x##s
2147#define DEVTEMPLATE_DERIVED_FEATURES   0
2148#define DEVTEMPLATE_DERIVED_NAME      "WD179x"
2149#include "devtempl.h"
2150
2151#define DEVTEMPLATE_DERIVED_ID(p,s)      p##wd179x##s
2152#define DEVTEMPLATE_DERIVED_FEATURES   0
2153#define DEVTEMPLATE_DERIVED_NAME      "WD179x"
2154#include "devtempl.h"
2155
2156#define DEVTEMPLATE_DERIVED_ID(p,s)      p##mb8877##s
2157#define DEVTEMPLATE_DERIVED_FEATURES   0
2158#define DEVTEMPLATE_DERIVED_NAME      "MB8877"
2159#include "devtempl.h"
2160
2161DEFINE_LEGACY_DEVICE(WD1770, wd1770);
2162DEFINE_LEGACY_DEVICE(WD1771, wd1771);
2163DEFINE_LEGACY_DEVICE(WD1772, wd1772);
2164DEFINE_LEGACY_DEVICE(WD1773, wd1773);
2165DEFINE_LEGACY_DEVICE(WD1793, wd1793);
2166DEFINE_LEGACY_DEVICE(WD1795, wd1795);
2167DEFINE_LEGACY_DEVICE(WD1797, wd1797);
2168DEFINE_LEGACY_DEVICE(WD2793, wd2793);
2169DEFINE_LEGACY_DEVICE(WD2795, wd2795);
2170DEFINE_LEGACY_DEVICE(WD2797, wd2797);
2171DEFINE_LEGACY_DEVICE(WD177X, wd177x);
2172DEFINE_LEGACY_DEVICE(WD179X, wd179x);
2173DEFINE_LEGACY_DEVICE(MB8877, mb8877);
2174
src/mess/machine/psxcddrv.h
r11460r11461
1#ifndef _included_psxcddriver_
2#define _included_psxcddriver_
3
4const unsigned int raw_sector_size=2352;
5
6class io_status
7{
8protected:
9   virtual ~io_status() {}
10
11public:
12   io_status() { }
13
14   virtual void cancel()=0;
15   virtual void release()=0;
16   virtual bool complete() const=0;
17   virtual bool block_until_complete() const=0;
18   virtual INT64 bytes_transferred() const=0;
19};
20
21enum cdromtype
22{
23   cdromtype_cd=0,
24   cdromtype_dvd
25};
26
27enum tracktype
28{
29   tracktype_unknown=0,
30   tracktype_mode1,
31   tracktype_mode2,
32   tracktype_audio
33};
34
35class cdrom_driver
36{
37   int pf_head,
38         pf_tail,
39         num_pf,
40         pf_head_sector;
41   unsigned char *pf_buffer;
42   io_status *pf_status,
43                  *last_pf_status;
44   INT64 pf_timeout_begin;
45
46   int native_sector_size;
47
48   virtual io_status *read_sectors(const unsigned int sec, const unsigned int numsec, unsigned char *buf)=0;
49
50   bool is_prefetch_sector_loaded(const unsigned int pfsec);
51
52protected:
53   void cancel_io();
54   void set_native_sector_size(const unsigned int sz);
55   UINT32 timestamp_frequency;
56   cdrom_file   *m_cd;
57private:
58   running_machine *m_machine;
59
60public:
61   cdrom_driver();
62   virtual ~cdrom_driver();
63
64   void set_machine(const running_machine &machine);
65   void set_cdrom_file(cdrom_file *cdfile) { m_cd = cdfile; }
66
67   virtual bool is_usable(char *error_msg=NULL, const int msglen=0) const=0;
68   virtual bool read_toc()=0;
69
70   void prefetch_sector(const unsigned int sec);
71   bool read_sector(const unsigned int sec,
72                            unsigned char *buf,
73                            const bool block=true);
74   unsigned char *get_prefetch_sector(const unsigned int pfsec,
75                                                       unsigned int *sz);
76
77   virtual unsigned int get_first_track() const=0;
78   virtual unsigned int get_num_tracks() const=0;
79   virtual bool get_track_address(const unsigned int track,
80                                                 unsigned char *address) const=0;
81   virtual tracktype get_track_type(const unsigned int track) const=0;
82   virtual unsigned int find_track(const unsigned int sector,
83                                                   unsigned int *start_sector=NULL,
84                                                   unsigned int *end_sector=NULL) const=0;
85
86   virtual cdromtype get_type() const { return cdromtype_cd; }
87};
88
89//
90//
91//
92
93inline unsigned int msf_to_sector(const unsigned char *msf)
94{
95   unsigned int sec=msf[2]+(msf[1]*75)+(msf[0]*(60*75));
96   if (sec>=150)
97   {
98      return sec-150;
99   }
100   else
101   {
102      return 0;
103   }
104}
105
106inline void sector_to_msf(const unsigned int sec, unsigned char *msf)
107{
108   unsigned int s=sec+150;
109   msf[0]=s/(60*75);
110   s-=msf[0]*(60*75);
111   msf[1]=s/75;
112   s-=msf[1]*75;
113   msf[2]=s;
114}
115
116//
117//
118//
119
120inline unsigned char bcd_to_decimal(const unsigned char bcd)
121{
122   return ((bcd>>4)*10)+(bcd&0xf);
123}
124
125inline unsigned char decimal_to_bcd(const unsigned char dec)
126{
127   //assert(dec<100);
128   return ((dec/10)<<4)|(dec%10);
129}
130
131cdrom_driver *open_mess_drv();
132
133#endif
src/mess/machine/wd17xx.h
r11460r11461
1/*********************************************************************
2
3    wd17xx.h
4
5    Implementations of the Western Digital 17xx and 27xx families of
6    floppy disk controllers
7
8*********************************************************************/
9
10#ifndef __WD17XX_H__
11#define __WD17XX_H__
12
13#include "devcb.h"
14
15
16/***************************************************************************
17    MACROS
18***************************************************************************/
19
20DECLARE_LEGACY_DEVICE(WD1770, wd1770);
21DECLARE_LEGACY_DEVICE(WD1771, wd1771);
22DECLARE_LEGACY_DEVICE(WD1772, wd1772);
23DECLARE_LEGACY_DEVICE(WD1773, wd1773);
24DECLARE_LEGACY_DEVICE(WD1793, wd1793);
25DECLARE_LEGACY_DEVICE(WD1795, wd1795);
26DECLARE_LEGACY_DEVICE(WD1797, wd1797);
27DECLARE_LEGACY_DEVICE(WD2793, wd2793);
28DECLARE_LEGACY_DEVICE(WD2795, wd2795);
29DECLARE_LEGACY_DEVICE(WD2797, wd2797);
30DECLARE_LEGACY_DEVICE(WD177X, wd177x);
31DECLARE_LEGACY_DEVICE(WD179X, wd179x);
32DECLARE_LEGACY_DEVICE(MB8877, mb8877);
33
34
35/***************************************************************************
36    TYPE DEFINITIONS
37***************************************************************************/
38
39/* Interface */
40typedef struct _wd17xx_interface wd17xx_interface;
41struct _wd17xx_interface
42{
43   devcb_read_line in_dden_func;
44   devcb_write_line out_intrq_func;
45   devcb_write_line out_drq_func;
46   const char *floppy_drive_tags[4];
47};
48
49
50/***************************************************************************
51    FUNCTION PROTOTYPES
52***************************************************************************/
53void wd17xx_reset(device_t *device);
54
55/* the following are not strictly part of the wd179x hardware/emulation
56but will be put here for now until the flopdrv code has been finalised more */
57void wd17xx_set_drive(device_t *device, UINT8);      /* set drive wd179x is accessing */
58void wd17xx_set_side(device_t *device, UINT8);      /* set side wd179x is accessing */
59
60void wd17xx_set_pause_time(device_t *device, int usec);       /* default is 40 usec if not set */
61
62READ8_DEVICE_HANDLER( wd17xx_status_r );
63READ8_DEVICE_HANDLER( wd17xx_track_r );
64READ8_DEVICE_HANDLER( wd17xx_sector_r );
65READ8_DEVICE_HANDLER( wd17xx_data_r );
66
67WRITE8_DEVICE_HANDLER( wd17xx_command_w );
68WRITE8_DEVICE_HANDLER( wd17xx_track_w );
69WRITE8_DEVICE_HANDLER( wd17xx_sector_w );
70WRITE8_DEVICE_HANDLER( wd17xx_data_w );
71
72READ8_DEVICE_HANDLER( wd17xx_r );
73WRITE8_DEVICE_HANDLER( wd17xx_w );
74
75WRITE_LINE_DEVICE_HANDLER( wd17xx_mr_w );
76WRITE_LINE_DEVICE_HANDLER( wd17xx_rdy_w );
77READ_LINE_DEVICE_HANDLER( wd17xx_mo_r );
78WRITE_LINE_DEVICE_HANDLER( wd17xx_tr00_w );
79WRITE_LINE_DEVICE_HANDLER( wd17xx_idx_w );
80WRITE_LINE_DEVICE_HANDLER( wd17xx_wprt_w );
81WRITE_LINE_DEVICE_HANDLER( wd17xx_dden_w );
82READ_LINE_DEVICE_HANDLER( wd17xx_drq_r );
83READ_LINE_DEVICE_HANDLER( wd17xx_intrq_r );
84
85extern const wd17xx_interface default_wd17xx_interface;
86extern const wd17xx_interface default_wd17xx_interface_2_drives;
87
88
89/***************************************************************************
90    DEVICE CONFIGURATION MACROS
91***************************************************************************/
92
93#define MCFG_WD1770_ADD(_tag, _intrf) \
94   MCFG_DEVICE_ADD(_tag, WD1770, 0) \
95   MCFG_DEVICE_CONFIG(_intrf)
96
97#define MCFG_WD1771_ADD(_tag, _intrf) \
98   MCFG_DEVICE_ADD(_tag, WD1771, 0) \
99   MCFG_DEVICE_CONFIG(_intrf)
100
101#define MCFG_WD1772_ADD(_tag, _intrf) \
102   MCFG_DEVICE_ADD(_tag, WD1772, 0) \
103   MCFG_DEVICE_CONFIG(_intrf)
104
105#define MCFG_WD1773_ADD(_tag, _intrf) \
106   MCFG_DEVICE_ADD(_tag, WD1773, 0) \
107   MCFG_DEVICE_CONFIG(_intrf)
108
109#define MCFG_WD1793_ADD(_tag, _intrf) \
110   MCFG_DEVICE_ADD(_tag, WD1793, 0) \
111   MCFG_DEVICE_CONFIG(_intrf)
112
113#define MCFG_WD1795_ADD(_tag, _intrf) \
114   MCFG_DEVICE_ADD(_tag, WD1795, 0) \
115   MCFG_DEVICE_CONFIG(_intrf)
116
117#define MCFG_WD1797_ADD(_tag, _intrf) \
118   MCFG_DEVICE_ADD(_tag, WD1797, 0) \
119   MCFG_DEVICE_CONFIG(_intrf)
120
121#define MCFG_WD2793_ADD(_tag, _intrf) \
122   MCFG_DEVICE_ADD(_tag, WD2793, 0) \
123   MCFG_DEVICE_CONFIG(_intrf)
124
125#define MCFG_WD2795_ADD(_tag, _intrf) \
126   MCFG_DEVICE_ADD(_tag, WD2795, 0) \
127   MCFG_DEVICE_CONFIG(_intrf)
128
129#define MCFG_WD2797_ADD(_tag, _intrf) \
130   MCFG_DEVICE_ADD(_tag, WD2797, 0) \
131   MCFG_DEVICE_CONFIG(_intrf)
132
133#define MCFG_WD177X_ADD(_tag, _intrf) \
134   MCFG_DEVICE_ADD(_tag, WD177X, 0) \
135   MCFG_DEVICE_CONFIG(_intrf)
136
137#define MCFG_WD179X_ADD(_tag, _intrf) \
138   MCFG_DEVICE_ADD(_tag, WD179X, 0) \
139   MCFG_DEVICE_CONFIG(_intrf)
140
141#define MCFG_MB8877_ADD(_tag, _intrf) \
142   MCFG_DEVICE_ADD(_tag, MB8877, 0) \
143   MCFG_DEVICE_CONFIG(_intrf)
144
145
146#endif /* __WD17XX_H__ */
src/mess/machine/nes_pcb.c
r11460r11461
1/*****************************************************************************************
2
3    NES Cart PCBs Emulation
4
5****************************************************************************************/
6
7typedef struct _nes_pcb  nes_pcb;
8struct _nes_pcb
9{
10   const char              *pcb_name;
11   int                     pcb_id;
12};
13
14// Here, we take the feature attribute from .xml (i.e. the PCB name) and we assign a unique ID to it
15static const nes_pcb pcb_list[] =
16{
17   /* Nintendo HROM, NROM, RROM, SROM & STROM */
18   { "HVC-HROM",         STD_NROM },
19   { "HVC-NROM",         STD_NROM },
20   { "HVC-NROM-128",     STD_NROM },
21   { "HVC-NROM-256",     STD_NROM },
22   { "HVC-RROM",         STD_NROM },
23   { "HVC-RROM-128",     STD_NROM },
24   { "HVC-RTROM",        STD_NROM },
25   { "HVC-SROM",         STD_NROM },
26   { "HVC-STROM",        STD_NROM },
27   { "NES-HROM",         STD_NROM },
28   { "NES-NROM",         STD_NROM },
29   { "NES-NROM-128",     STD_NROM },
30   { "NES-NROM-256",     STD_NROM },
31   { "NES-RROM",         STD_NROM },
32   { "NES-RROM-128",     STD_NROM },
33   { "NES-SROM",         STD_NROM },
34   { "NES-STROM",        STD_NROM },
35   /* "No mapper" boards by other manufacturer */
36   { "IREM-NROM-128",    STD_NROM },
37   { "IREM-NROM-256",    STD_NROM },
38   { "BANDAI-NROM-128",  STD_NROM },
39   { "BANDAI-NROM-256",  STD_NROM },
40   { "KONAMI-NROM-128",  STD_NROM },
41   { "SETA-NROM-128",    STD_NROM },
42   { "SUNSOFT-NROM-128", STD_NROM },
43   { "SUNSOFT-NROM-256", STD_NROM },
44   { "TAITO-NROM-128",   STD_NROM },
45   { "TAITO-NROM-256",   STD_NROM },
46   { "NAMCOT-3301",      STD_NROM },
47   { "NAMCOT-3302",      STD_NROM },
48   { "NAMCOT-3303",      STD_NROM },
49   { "NAMCOT-3304",      STD_NROM },
50   { "NAMCOT-3305",      STD_NROM },
51   { "NAMCOT-3311",      STD_NROM },
52   { "NAMCOT-3312",      STD_NROM },
53   { "NAMCOT-3411",      STD_NROM },
54   { "JALECO-JF-01",     STD_NROM },
55   { "JALECO-JF-02",     STD_NROM },
56   { "JALECO-JF-03",     STD_NROM },
57   { "JALECO-JF-04",     STD_NROM },
58   { "TENGEN-800003",    STD_NROM },
59   { "SACHEN-NROM",      STD_NROM },
60   /* Nintendo Family BASIC pcb (NROM + 2K or 4K WRAM) */
61   { "HVC-FAMILYBASIC",  HVC_FAMBASIC },
62   /* Game Genie */
63   { "CAMERICA-GAMEGENIE", GG_NROM },
64//
65   /* Nintendo UNROM/UOROM */
66   { "HVC-UNROM",        STD_UXROM },
67   { "HVC-UNEPROM",      STD_UXROM },
68   { "HVC-UOROM",        STD_UXROM },
69   { "NES-UNROM",        STD_UXROM },
70   { "NES-UNEPROM",      STD_UXROM },
71   { "NES-UOROM",        STD_UXROM },
72   { "HVC-UNROM+74HC08", UXROM_CC },
73   /* UxROM boards by other manufacturer */
74   { "IREM-UNROM",       STD_UXROM },
75   { "KONAMI-UNROM",     STD_UXROM },
76   { "TAITO-UNROM",      STD_UXROM },
77   { "JALECO-JF-15",     STD_UXROM },
78   { "JALECO-JF-18",     STD_UXROM },
79   { "JALECO-JF-39",     STD_UXROM },
80//
81   /* Nintendo CNROM */
82   { "HVC-CNROM",        STD_CNROM },
83   { "NES-CNROM",        STD_CNROM },
84   /* CxROM boards by other manufacturer */
85   { "BANDAI-CNROM",     STD_CNROM },
86   { "BANDAI-74*161/32", STD_CNROM },
87   { "KONAMI-CNROM",     STD_CNROM },
88   { "NAMCOT-CNROM+WRAM", STD_CNROM },
89   { "TAITO-CNROM",      STD_CNROM },
90   { "AVE-74*161",       STD_CNROM },
91   { "NTDEC-N715061",    STD_CNROM },
92   { "NTDEC-N715062",    STD_CNROM },
93   { "SACHEN-CNROM",     STD_CNROM },
94   /* Bandai Aerobics Studio (CNROM boards + special audio chip) */
95   { "BANDAI-PT-554",    BANDAI_PT554 },
96   /* FIXME: Is this the same as mapper 3? */
97   { "TENGEN-800008",    TENGEN_800008 },
98//
99   /* Nintendo AxROM */
100   { "HVC-AMROM",        STD_AXROM },
101   { "HVC-AN1ROM",       STD_AXROM },
102   { "HVC-ANROM",        STD_AXROM },
103   { "HVC-AOROM",        STD_AXROM },
104   { "NES-AMROM",        STD_AXROM },
105   { "NES-AN1ROM",       STD_AXROM },
106   { "NES-ANROM",        STD_AXROM },
107   { "NES-AOROM",        STD_AXROM },
108   /* AxROM boards by other manufacturer */
109   { "ACCLAIM-AOROM",    STD_AXROM },
110//
111   /* Nintendo PxROM */
112   { "HVC-PEEOROM",      STD_PXROM },
113   { "HVC-PNROM",        STD_PXROM },
114   { "NES-PEEOROM",      STD_PXROM },
115   { "NES-PNROM",        STD_PXROM },
116//
117   /* Nintendo FxROM */
118   { "HVC-FJROM",        STD_FXROM },
119   { "HVC-FKROM",        STD_FXROM },
120   { "NES-FJROM",        STD_FXROM },
121   { "NES-FKROM",        STD_FXROM },
122//
123   /* Nintendo BXROM */
124   { "HVC-BNROM",        STD_BXROM },
125   { "NES-BNROM",        STD_BXROM },
126   /* BxROM boards by other manufacturer */
127   { "IREM-BNROM",       STD_BXROM },
128//
129   /* Nintendo CPROM */
130   { "HVC-CPROM",        STD_CPROM },
131   { "NES-CPROM",        STD_CPROM },
132//
133   /* Nintendo GNROM & MHROM */
134   { "HVC-GNROM",        STD_GXROM },
135   { "NES-GNROM",        STD_GXROM },
136   { "HVC-MHROM",        STD_MXROM },
137   { "NES-MHROM",        STD_MXROM },
138   { "PAL-MH",           STD_MXROM },
139   /* GxROM boards by other manufacturer */
140   { "BANDAI-GNROM",     STD_GXROM },
141//
142   /* Nintendo NxROM */
143   { "HVC-NTBROM",       STD_NXROM },
144   { "NES-NTBROM",       STD_NXROM },
145   /* NxROM boards by other manufacturer (this board was mainly used by Sunsoft?) */
146   { "SUNSOFT-4",        STD_NXROM },
147   { "SUNSOFT-DCS",      SUNSOFT_DCS },
148   { "TENGEN-800042",    STD_NXROM },
149//
150   /* Nintendo JxROM */
151   { "HVC-JLROM",        STD_JXROM },
152   { "HVC-JSROM",        STD_JXROM },
153   { "NES-JLROM",        STD_JXROM },
154   { "NES-JSROM",        STD_JXROM },
155   { "NES-BTR",          STD_JXROM },
156   /* JxROM boards by other manufacturer (this board was mainly used by Sunsoft?) */
157   { "SUNSOFT-5A",       STD_JXROM },
158   { "SUNSOFT-5B",       STD_JXROM },
159   { "SUNSOFT-FME-7",    STD_JXROM },
160//
161   /* Nintendo UN1ROM */
162   { "HVC-UN1ROM",       STD_UN1ROM },
163   { "NES-UN1ROM",       STD_UN1ROM },
164//
165   /* Nintendo SxROM */
166   { "HVC-SAROM",        STD_SXROM },
167   { "HVC-SBROM",        STD_SXROM },
168   { "HVC-SC1ROM",       STD_SXROM },
169   { "HVC-SCROM",        STD_SXROM },
170   { "HVC-SEROM",        STD_SXROM },
171   { "HVC-SF1ROM",       STD_SXROM },
172   { "HVC-SFROM",        STD_SXROM },
173   { "HVC-SGROM",        STD_SXROM },
174   { "HVC-SH1ROM",       STD_SXROM },
175   { "HVC-SHROM",        STD_SXROM },
176   { "HVC-SIROM",        STD_SXROM },
177   { "HVC-SJROM",        STD_SXROM },
178   { "HVC-SKROM",        STD_SXROM },
179   { "HVC-SKEPROM",      STD_SXROM },
180   { "HVC-SL1ROM",       STD_SXROM },
181   { "HVC-SL2ROM",       STD_SXROM },
182   { "HVC-SL3ROM",       STD_SXROM },
183   { "HVC-SLROM",        STD_SXROM },
184   { "HVC-SLRROM",       STD_SXROM },
185   { "HVC-SMROM",        STD_SXROM },
186   { "HVC-SNROM",        STD_SXROM },
187   { "HVC-SUROM",        STD_SXROM },
188   { "HVC-SXROM",        STD_SXROM },
189   { "NES-SAROM",        STD_SXROM },
190   { "NES-SBROM",        STD_SXROM },
191   { "NES-SC1ROM",       STD_SXROM },
192   { "NES-SCROM",        STD_SXROM },
193   { "NES-SEROM",        STD_SXROM },
194   { "NES-SF1ROM",       STD_SXROM },
195   { "NES-SFROM",        STD_SXROM },
196   { "NES-SGROM",        STD_SXROM },
197   { "NES-SH1ROM",       STD_SXROM },
198   { "NES-SHROM",        STD_SXROM },
199   { "NES-SIROM",        STD_SXROM },
200   { "NES-SJROM",        STD_SXROM },
201   { "NES-SKROM",        STD_SXROM },
202   { "NES-SKEPROM",      STD_SXROM },
203   { "NES-SL1ROM",       STD_SXROM },
204   { "NES-SL2ROM",       STD_SXROM },
205   { "NES-SL3ROM",       STD_SXROM },
206   { "NES-SLROM",        STD_SXROM },
207   { "NES-SLRROM",       STD_SXROM },
208   { "NES-SMROM",        STD_SXROM },
209   { "NES-SNROM",        STD_SXROM },
210   { "NES-SUROM",        STD_SXROM },
211   { "NES-SXROM",        STD_SXROM },
212   { "NES-WH",           STD_SXROM },
213   { "NES-SOROM",        STD_SOROM },
214   { "HVC-SOROM",        STD_SOROM },
215   /* SxROM boards by other manufacturer */
216   { "KONAMI-SLROM",     STD_SXROM },
217   { "VIRGIN-SNROM",     STD_SXROM },
218//
219   /* Nintendo TxROM */
220   { "HVC-TBROM",        STD_TXROM },
221   { "HVC-TEROM",        STD_TXROM },
222   { "HVC-TFROM",        STD_TXROM },
223   { "HVC-TGROM",        STD_TXROM },
224   { "HVC-TKROM",        STD_TXROM },
225   { "HVC-TL1ROM",       STD_TXROM },
226   { "HVC-TL2ROM",       STD_TXROM },
227   { "HVC-TLROM",        STD_TXROM },
228   { "HVC-TNROM",        STD_TXROM },
229   { "HVC-TR1ROM",       STD_TVROM },
230   { "HVC-TSROM",        STD_TXROM },
231   { "HVC-TVROM",        STD_TVROM },
232   { "NES-B4",           STD_TXROM },
233   { "NES-TBROM",        STD_TXROM },
234   { "NES-TEROM",        STD_TXROM },
235   { "NES-TFROM",        STD_TXROM },
236   { "NES-TGROM",        STD_TXROM },
237   { "NES-TKROM",        STD_TXROM },
238   { "NES-TL1ROM",       STD_TXROM },
239   { "NES-TL2ROM",       STD_TXROM },
240   { "NES-TLROM",        STD_TXROM },
241   { "NES-TNROM",        STD_TXROM },
242   { "NES-TR1ROM",       STD_TVROM },
243   { "NES-TSROM",        STD_TXROM },
244   { "NES-TVROM",        STD_TVROM },
245   /* TxROM boards by other manufacturer */
246   { "ACCLAIM-MC-ACC",   STD_TXROM },
247   { "ACCLAIM-TLROM",    STD_TXROM },
248   { "KONAMI-TLROM",     STD_TXROM },
249//
250   /* Nintendo DxROM */
251   { "HVC-DE1ROM",       STD_DXROM },
252   { "HVC-DEROM",        STD_DXROM },
253   { "HVC-DRROM",        STD_DRROM },
254   { "NES-DE1ROM",       STD_DXROM },
255   { "NES-DEROM",        STD_DXROM },
256   { "NES-DRROM",        STD_DRROM },
257   /* DxROM boards by other manufacturer */
258   { "NAMCOT-3401",      STD_DXROM },
259   { "NAMCOT-3405",      STD_DXROM },
260   { "NAMCOT-3406",      STD_DXROM },
261   { "NAMCOT-3407",      STD_DXROM },
262   { "NAMCOT-3413",      STD_DXROM },
263   { "NAMCOT-3414",      STD_DXROM },
264   { "NAMCOT-3415",      STD_DXROM },
265   { "NAMCOT-3416",      STD_DXROM },
266   { "NAMCOT-3417",      STD_DXROM },
267   { "NAMCOT-3451",      STD_DXROM },
268   { "TENGEN-800002",    STD_DXROM },
269   { "TENGEN-800004",    STD_DRROM },
270   { "TENGEN-800030",    STD_DXROM },
271//
272   /* Nintendo HKROM */
273   { "HVC-HKROM",        STD_HKROM },
274   { "NES-HKROM",        STD_HKROM },
275//
276   /* Nintendo BNROM */
277   { "HVC-TQROM",        STD_TQROM },
278   { "NES-TQROM",        STD_TQROM },
279//
280   /* Nintendo TxSROM */
281   { "HVC-TKSROM",       STD_TXSROM },
282   { "HVC-TLSROM",       STD_TXSROM },
283   { "NES-TKSROM",       STD_TXSROM },
284   { "NES-TLSROM",       STD_TXSROM },
285//
286   /* Nintendo ExROM */
287   { "HVC-EKROM",        STD_EXROM },
288   { "HVC-ELROM",        STD_EXROM },
289   { "HVC-ETROM",        STD_EXROM },
290   { "HVC-EWROM",        STD_EXROM },
291   { "NES-EKROM",        STD_EXROM },
292   { "NES-ELROM",        STD_EXROM },
293   { "NES-ETROM",        STD_EXROM },
294   { "NES-EWROM",        STD_EXROM },
295//
296   /* Nintendo Custom boards */
297   { "PAL-ZZ",           PAL_ZZ },
298   { "NES-QJ",           NES_QJ },
299   { "NES-EVENT",        UNSUPPORTED_BOARD },
300//
301   /* Discrete board IC_74x139x74 */
302   { "JALECO-JF-05",     DIS_74X139X74 },
303   { "JALECO-JF-06",     DIS_74X139X74 },
304   { "JALECO-JF-07",     DIS_74X139X74 },
305   { "JALECO-JF-08",     DIS_74X139X74 },
306   { "JALECO-JF-09",     DIS_74X139X74 },
307   { "JALECO-JF-10",     DIS_74X139X74 },
308   { "KONAMI-74*139/74", DIS_74X139X74 },
309   { "TAITO-74*139/74",  DIS_74X139X74 },
310   /* Discrete board IC_74x377 */
311   { "AGCI-47516",       DIS_74X377 },
312   { "AVE-NINA-07",      DIS_74X377 },
313   { "COLORDREAMS-74*377", DIS_74X377 },
314   /* Discrete board IC_74x161x161x32 */
315   { "BANDAI-74*161/161/32", DIS_74X161X161X32 },
316   { "TAITO-74*161/161/32", DIS_74X161X161X32 },
317   /* Discrete board IC_74x161x138 */
318   { "BIT-CORP-74*161/138", DIS_74X161X138 },
319//
320   { "BANDAI-LZ93D50",   BANDAI_LZ93 },
321   { "BANDAI-LZ93D50+24C01", BANDAI_LZ93EX },
322   { "BANDAI-LZ93D50+24C02", BANDAI_LZ93EX },
323   { "BANDAI-FCG-1",     BANDAI_FCG },
324   { "BANDAI-FCG-2",     BANDAI_FCG },
325   { "BANDAI-JUMP2",     BANDAI_JUMP2 },
326   { "BANDAI-DATACH",    BANDAI_DATACH },
327   { "BANDAI-KARAOKE",   BANDAI_KARAOKE },
328   { "BANDAI-OEKAKIDS",  BANDAI_OEKAKIDS },
329   { "IREM-FCG-1",       BANDAI_FCG },
330//
331   { "IREM-G101",        IREM_G101 },
332   { "IREM-74*161/161/21/138", IREM_LROG017 },
333   { "IREM-H-3001",      IREM_H3001 },
334   { "IREM-H3001",       IREM_H3001 },
335   { "IREM-HOLYDIVER",   IREM_HOLYDIV },
336   { "IREM-TAM-S1",      IREM_TAM_S1 },
337//
338   { "JALECO-JF-23",     JALECO_SS88006 },
339   { "JALECO-JF-24",     JALECO_SS88006 },
340   { "JALECO-JF-25",     JALECO_SS88006 },
341   { "JALECO-JF-27",     JALECO_SS88006 },
342   { "JALECO-JF-29",     JALECO_SS88006 },
343   { "JALECO-JF-30",     JALECO_SS88006 },
344   { "JALECO-JF-31",     JALECO_SS88006 },
345   { "JALECO-JF-32",     JALECO_SS88006 },
346   { "JALECO-JF-33",     JALECO_SS88006 },
347   { "JALECO-JF-34",     JALECO_SS88006 },
348   { "JALECO-JF-35",     JALECO_SS88006 },
349   { "JALECO-JF-36",     JALECO_SS88006 },
350   { "JALECO-JF-37",     JALECO_SS88006 },
351   { "JALECO-JF-38",     JALECO_SS88006 },
352   { "JALECO-JF-40",     JALECO_SS88006 },
353   { "JALECO-JF-41",     JALECO_SS88006 },
354   { "JALECO-JF-11",     JALECO_JF11 },
355   { "JALECO-JF-12",     JALECO_JF11 },
356   { "JALECO-JF-14",     JALECO_JF11 },
357   { "JALECO-JF-13",     JALECO_JF13 },
358   { "JALECO-JF-16",     JALECO_JF16 },
359   { "JALECO-JF-17",     JALECO_JF17 },
360   { "JALECO-JF-26",     JALECO_JF17 },
361   { "JALECO-JF-28",     JALECO_JF17 },
362   { "JALECO-JF-19",     JALECO_JF19 },
363   { "JALECO-JF-21",     JALECO_JF19 },
364//
365   { "KONAMI-VRC-1",     KONAMI_VRC1 },
366   { "JALECO-JF-20",     KONAMI_VRC1 },
367   { "JALECO-JF-22",     KONAMI_VRC1 },
368   { "KONAMI-VRC-2",     KONAMI_VRC2 },
369   { "KONAMI-VRC-3",     KONAMI_VRC3 },
370   { "KONAMI-VRC-4",     KONAMI_VRC4 },
371   { "KONAMI-VRC-6",     KONAMI_VRC6 },
372   { "KONAMI-VRC-7",     KONAMI_VRC7 },
373   { "UNL-VRC7",         KONAMI_VRC7 },
374//
375   { "NAMCOT-163",       NAMCOT_163 },
376   { "NAMCOT-175",       NAMCOT_163 },
377   { "NAMCOT-340",       NAMCOT_163 },
378   { "NAMCOT-3425",      NAMCOT_3425 },
379   { "NAMCOT-3433",      NAMCOT_34X3 },
380   { "NAMCOT-3443",      NAMCOT_34X3 },
381   { "NAMCOT-3446",      NAMCOT_3446 },
382   { "NAMCOT-3453",      NAMCOT_3453 },
383//
384   { "SUNSOFT-1",        SUNSOFT_1 },
385   { "SUNSOFT-2",        SUNSOFT_2 },
386   { "SUNSOFT-3",        SUNSOFT_3 },
387   //
388   { "TAITO-TC0190FMC",  TAITO_TC0190FMC },
389   { "TAITO-TC0190FMC+PAL16R4", TAITO_TC0190FMCP },
390   { "TAITO-TC0350FMR",  TAITO_TC0190FMC },
391   { "TAITO-X1-005",     TAITO_X1_005 },   // two variants exist, depending on pin17 & pin31 connections
392   { "TAITO-X1-017",     TAITO_X1_017 },
393//
394   { "AGCI-50282",       AGCI_50282 },
395   { "AVE-NINA-01",      AVE_NINA01 },
396   { "AVE-NINA-02",      AVE_NINA01 },
397   { "AVE-NINA-03",      AVE_NINA06 },
398   { "AVE-NINA-06",      AVE_NINA06 },
399   { "AVE-MB-91",        AVE_NINA06 },
400   { "TXC-74*138/175",   AVE_NINA06 },
401   { "UNL-SA-016-1M",    AVE_NINA06 },
402   { "CAMERICA-ALGN",    CAMERICA_BF9093 },
403   { "CAMERICA-BF9093",  CAMERICA_BF9093 },
404   { "CAMERICA-BF9097",  CAMERICA_BF9097 },
405   { "CAMERICA-ALGQ",    CAMERICA_BF9096 },
406   { "CAMERICA-BF9096",  CAMERICA_BF9096 },
407   { "CAMERICA-GOLDENFIVE", CAMERICA_GOLDENFIVE },
408   { "CNE-DECATHLON",    CNE_DECATHLON },
409   { "CNE-PSB",          CNE_FSB },
410   { "CNE-SHLZ",         CNE_SHLZ },
411   { "JYCOMPANY-A",      UNSUPPORTED_BOARD },   // mapper 90
412   { "JYCOMPANY-B",      UNSUPPORTED_BOARD },   // mapper 209
413   { "JYCOMPANY-C",      UNSUPPORTED_BOARD },   // mapper 211
414   { "NTDEC-112",        NTDEC_ASDER },   // mapper 112 (better rename this board tag, to avoid confusion with TC-112!!
415   { "NTDEC-TC-112",     NTDEC_FIGHTINGHERO },
416   { "NTDEC-193",        NTDEC_FIGHTINGHERO },   // mapper 193
417   { "UNL-TEK90",        UNSUPPORTED_BOARD },   // related to JY Company? (i.e. mappers 90, 209, 211?)
418   { "UNL-SA-002",       SACHEN_TCU02 },
419   { "UNL-SA-009",       SACHEN_SA009 },
420   { "UNL-SA-0036",      SACHEN_SA0036 },
421   { "UNL-SA-0037",      SACHEN_SA0037 },
422   { "UNL-SA-72007",     SACHEN_SA72007 },
423   { "UNL-SA-72008",     SACHEN_SA72008 },
424   { "UNL-SA-NROM",      SACHEN_TCA01 },
425   { "UNL-SACHEN-TCA01", SACHEN_TCA01 },
426   { "SACHEN-8259A",     SACHEN_8259A },
427   { "UNL-SACHEN-8259A", SACHEN_8259A },
428   { "SACHEN-8259B",     SACHEN_8259B },
429   { "UNL-SACHEN-8259B", SACHEN_8259B },
430   { "SACHEN-8259C",     SACHEN_8259C },
431   { "UNL-SACHEN-8259C", SACHEN_8259C },
432   { "SACHEN-8259D",     SACHEN_8259D },
433   { "UNL-SACHEN-8259D", SACHEN_8259D },
434   { "UNL-SACHEN-74LS374N", SACHEN_74LS374 },
435   { "UNL-SACHEN-74LS374N-A", SACHEN_74LS374_A },   /* FIXME: Made up boards the different mirroring handling */
436   { "UNL-TC-U01-1.5M",  SACHEN_TCU01 },
437   { "TENGEN-800032",    TENGEN_800032 },
438   { "TENGEN-800037",    TENGEN_800037 },
439   { "WAIXING-A",        WAIXING_TYPE_A },
440   { "WAIXING-A-1",      WAIXING_TYPE_A_1 },   /* FIXME: Made up boards the different CHRRAM banks (see Ji Jia Zhan Shi) */
441   { "WAIXING-B",        WAIXING_TYPE_B },
442   { "WAIXING-C",        WAIXING_TYPE_C },
443   { "WAIXING-D",        WAIXING_TYPE_D },
444   { "WAIXING-E",        WAIXING_TYPE_E },
445   { "WAIXING-F",        WAIXING_TYPE_F },
446   { "WAIXING-G",        WAIXING_TYPE_G },
447   { "WAIXING-H",        WAIXING_TYPE_H },
448   { "WAIXING-I",        WAIXING_TYPE_I },
449   { "WAIXING-J",        WAIXING_TYPE_J },
450   { "WAIXING-SGZLZ",    WAIXING_SGZLZ },
451   { "WAIXING-SEC",      WAIXING_SECURITY },
452   { "WAIXING-SGZ",      WAIXING_SGZ },
453   { "WAIXING-PS2",      WAIXING_PS2 },
454   { "WAIXING-FFV",      WAIXING_FFV },
455   { "WAIXING-ZS",       WAIXING_ZS },
456   { "WAIXING-DQ8",      WAIXING_DQ8 },
457   { "WAIXING-SH2",      WAIXING_SH2 },
458//
459   { "TXC-TW",           TXC_TW },
460   { "TXC-STRIKEWOLF",   TXC_STRIKEWOLF },
461   { "TXC-MXMDHTWO",     TXC_MXMDHTWO },
462   { "UNL-22211",        TXC_22211A },
463   /* FIXME: Made up boards the different mirroring handling */
464   { "UNL-22211-A",      TXC_22211A },
465   { "UNL-22211-B",      TXC_22211B },
466   { "UNL-22211-C",      TXC_22211C },
467   { "UNL-REXSOFT-DBZ5", REXSOFT_DBZ5 },
468   { "UNL-SL1632",       REXSOFT_SL1632 },
469   { "SUBOR-BOARD-0",    SUBOR_TYPE0 },
470   { "SUBOR-BOARD-1",    SUBOR_TYPE1 },
471   { "SOMERITEAM-SL-12", SOMERI_SL12 }, // mapper 116
472   { "UNL-CONY",         CONY_BOARD },
473   { "UNL-GOUDER",       GOUDER_37017 },
474   { "UNL-NITRA",        NITRA_TDA },
475   { "UNL-HOSENKAN",     HOSENKAN_BOARD },
476   { "UNL-SUPERGAME",    SUPERGAME_LIONKING },
477   { "UNL-PANDAPRINCE",  KAY_PANDAPRINCE },
478   { "DREAMTECH01",      DREAMTECH_BOARD },
479   { "DAOU-306",         OPENCORP_DAOU306 },
480   { "HES",              HES_BOARD },
481   /* FIXME: Made up boards the different mirroring handling? */
482   { "HES-6IN1",         HES6IN1_BOARD },
483   { "SUPERGAME-BOOGERMAN", SUPERGAME_BOOGERMAN },
484   { "FUTUREMEDIA",      FUTUREMEDIA_BOARD },
485   { "FUKUTAKE",         FUKUTAKE_BOARD },
486   { "MAGICSERIES",      MAGICSERIES_MD },
487   { "KASING",           KASING_BOARD },
488   { "HENGGEDIANZI",     HENGEDIANZI_BOARD },
489   { "HENGGEDIANZI-XJZB", HENGEDIANZI_XJZB },
490   { "KAISER-KS7058",    KAISER_KS7058 },
491   { "KAISER-KS202",     KAISER_KS202 },// mapper 56
492   { "KAISER-KS7022",    KAISER_KS7022 },// mapper 175
493   { "UNL-KS7017",       KAISER_KS7017 },
494   { "UNL-KS7032",       KAISER_KS7032 }, //  mapper 142
495   { "RCM-GS2015",       RCM_GS2015 },
496   { "RCM-TETRISFAMILY", RCM_TETRISFAMILY },
497   { "UNL-NINJARYU",     UNSUPPORTED_BOARD },// mapper 111
498   { "UNL-NANJING",      NANJING_BOARD },// mapper 163
499   { "WHIRLWIND-2706",   WHIRLWIND_2706 },
500   { "UNL-H2288",        UNL_H2288 },
501   { "UNL-DANCE",        UNSUPPORTED_BOARD },
502   { "UNL-EDU2000",      UNL_EDU2K },
503   { "UNL-SHERO",        UNSUPPORTED_BOARD /*SACHEN_SHERO*/ },
504   { "UNL-TF1201",       UNSUPPORTED_BOARD /*UNL_TF1201*/ },
505   { "RUMBLESTATION",    RUMBLESTATION_BOARD },   // mapper 46
506   { "UNL-WORLDHERO",    UNSUPPORTED_BOARD },// mapper 27
507   { "UNL-A9746",        UNSUPPORTED_BOARD },// mapper 219
508   { "UNL-603-5052",     UNL_603_5052 },// mapper 238?
509   { "UNL-SHJY3",        UNL_SHJY3 },// mapper 253
510   { "UNL-RACERMATE",    UNL_RACERMATE },// mapper 168
511   { "UNL-N625092",      UNL_N625092 },
512   { "BMC-N625092",      UNL_N625092 },
513   { "UNL-SC-127",       UNL_SC127 },
514   { "UNL-SMB2J",        UNL_SMB2J },
515   { "BTL-SMB2C",        UNL_SMB2J },
516   { "UNL-MK2",          UNL_MK2 },
517   { "UNL-XZY",          UNL_XZY },
518   { "UNL-KOF96",        UNL_KOF96 },
519   { "UNL-SUPERFIGHTER3", UNL_SUPERFIGHTER3 },
520   { "UNL-8237",         UNL_8237 },
521   { "UNL-AX5705",       UNL_AX5705 },
522   { "UNL-CC-21",        UNL_CC21 },
523   { "UNL-KOF97",        UNL_KOF97 },
524   { "UNL-T-230",        UNL_T230 },
525   { "UNL-STUDYNGAME",   UNL_STUDYNGAME },   // mapper 39
526   { "UNL-OneBus",       UNSUPPORTED_BOARD },
527//
528   { "BTL-SMB2A",         BTL_SMB2A },
529   { "BTL-MARIOBABY",     BTL_MARIOBABY },
530   { "BTL-AISENSHINICOL", BTL_AISENSHINICOL },
531   { "BTL-SMB2B",         BTL_SMB2B },
532   { "BTL-SMB3",          BTL_SMB3 },
533   { "BTL-SUPERBROS11",   BTL_SUPERBROS11 },
534   { "BTL-DRAGONNINJA",   BTL_DRAGONNINJA },
535   { "BTL-MARIO1-MALEE2", UNSUPPORTED_BOARD },   // mapper 55?
536   { "BTL-2708",          UNSUPPORTED_BOARD },// mapper 103
537   { "BTL-TOBIDASEDAISAKUSEN", BTL_TOBIDASE },// mapper 120
538   { "BTL-SHUIGUANPIPE",  UNSUPPORTED_BOARD },// mapper 183
539   { "BTL-PIKACHUY2K",    BTL_PIKACHUY2K },// mapper 254
540//
541   { "BMC-190IN1",          BMC_190IN1 },
542   { "BMC-64IN1NOREPEAT",   BMC_64IN1NR },
543   { "BMC-A65AS",           BMC_A65AS },
544   { "BMC-GS-2004",         BMC_GS2004 },
545   { "BMC-GS-2013",         BMC_GS2013 },
546   { "BMC-NOVELDIAMOND9999999IN1", BMC_NOVELDIAMOND },
547   { "BMC-9999999IN1",      BMC_9999999IN1 }, // mapper 213... same as BMC-NOVELDIAMOND9999999IN1 ??
548   { "BMC-SUPER24IN1SC03",  BMC_S24IN1SC03 },
549   { "BMC-SUPERHIK8IN1",    BMC_HIK8IN1 },
550   { "BMC-T-262",           BMC_T262 },
551   { "BMC-WS",              BMC_WS },
552   { "MLT-ACTION52",        ACTENT_ACT52 },
553   { "MLT-CALTRON6IN1",     CALTRON_6IN1 },
554   { "MLT-MAXI15",          UNSUPPORTED_BOARD}, //  mapper 234
555   { "BMC-SUPERBIG-7IN1",   BMC_SUPERBIG_7IN1 },
556   { "BMC-SUPERHIK-4IN1",   BMC_SUPERHIK_4IN1 },
557   { "BMC-BALLGAMES-11IN1", BMC_BALLGAMES_11IN1 },
558   { "BMC-MARIOPARTY-7IN1", BMC_MARIOPARTY_7IN1 },
559   { "BMC-GKA",             BMC_GKA },
560   { "BMC-GKB",             BMC_GKB },
561   { "BMC-SUPER700IN1",     BMC_SUPER_700IN1 },
562   { "BMC-FAMILY-4646B",    BMC_FAMILY_4646B },
563   { "BMC-36IN1",           BMC_36IN1 },
564   { "BMC-21IN1",           BMC_21IN1 },
565   { "BMC-150IN1",          BMC_150IN1 },
566   { "BMC-35IN1",           BMC_35IN1 },
567   { "BMC-64IN1",           BMC_64IN1 },
568   { "BMC-15IN1",           BMC_15IN1 },
569   { "BMC-SUPERHIK-300IN1", BMC_SUPERHIK_300IN1 },
570   { "BMC-SUPERGUN-20IN1",  BMC_SUPERGUN_20IN1 },
571   { "BMC-GOLDENCARD-6IN1", BMC_GOLDENCARD_6IN1 },
572   { "BMC-72IN1",           BMC_72IN1 },
573   { "BMC-76IN1",           BMC_76IN1 },
574   { "BMC-SUPER42IN1",      BMC_SUPER_42IN1 },
575   { "BMC-1200IN1",         BMC_1200IN1 },
576   { "BMC-31IN1",           BMC_31IN1 },
577   { "BMC-22GAMES",         BMC_22GAMES },
578   { "BMC-20IN1",           BMC_20IN1 },
579   { "BMC-110IN1",          BMC_110IN1 },
580   { "BMC-810544-C-A1",     BMC_810544 },
581   { "BMC-411120-C",        UNSUPPORTED_BOARD },
582   { "BMC-830118C",         UNSUPPORTED_BOARD },
583   { "BMC-12-IN-1",         UNSUPPORTED_BOARD },
584   { "BMC-NTD-03",          BMC_NTD_03 },
585   { "BMC-8157",            UNSUPPORTED_BOARD /*BMC_8157*/ },
586   { "BMC-BS-5",            BMC_BENSHENG_BS5 },
587   { "BMC-FK23C",           BMC_FK23C },
588   { "BMC-FK23CA",          BMC_FK23CA },
589   { "BMC-GHOSTBUSTERS63IN1", BMC_G63IN1 },
590   { "BMC-SUPERVISION16IN1", UNSUPPORTED_BOARD },   // mapper 53
591   { "BMC-RESETBASED-4IN1", UNSUPPORTED_BOARD },// mapper 60 with 64k prg and 32k chr
592   { "BMC-VT5201",          BMC_VT5201 },// mapper 60 otherwise
593   { "BMC-D1038",           BMC_VT5201 }, // mapper 60?
594   { "BMC-42IN1RESETSWITCH", UNSUPPORTED_BOARD },   // mapper 60?
595   { "BMC-SUPER22GAMES",    UNSUPPORTED_BOARD },// mapper 233
596   { "BMC-GOLDENGAME-150IN1", UNSUPPORTED_BOARD },// mapper 235 with 2M PRG
597   { "BMC-GOLDENGAME-260IN1", UNSUPPORTED_BOARD },// mapper 235 with 4M PRG
598   { "BMC-70IN1",           UNSUPPORTED_BOARD },   // mapper 236?
599   { "BMC-70IN1B",          UNSUPPORTED_BOARD },   // mapper 236?
600   { "BMC-SUPERHIK-KOF",    UNSUPPORTED_BOARD },// mapper 251
601   { "BMC-POWERJOY",        BMC_PJOY84 },
602// are there dumps of games with these boards?
603   { "BMC-13IN1JY110",   UNSUPPORTED_BOARD }, //  [mentioned in FCEUMM source - we need more info]
604   { "BMC-GK-192",       UNSUPPORTED_BOARD }, //  [mentioned in FCEUMM source - we need more info]
605   { "KONAMI-QTAI",      UNSUPPORTED_BOARD }, //  [mentioned in FCEUMM source - we need more info]
606   { "UNL-3D-BLOCK",     UNSUPPORTED_BOARD }, //  [mentioned in FCEUMM source - we need more info]
607   { "UNL-C-N22M",       UNSUPPORTED_BOARD }, //  [mentioned in FCEUMM source - we need more info]
608   { "UNL-PEC-586",      UNSUPPORTED_BOARD }, //  [mentioned in FCEUMM source - we need more info]
609//
610   { "UNKNOWN",          UNKNOWN_BOARD }  //  a few pirate dumps uses the wrong mapper...
611};
612
613const nes_pcb *nes_pcb_lookup( const char *board )
614{
615   int i;
616   for (i = 0; i < ARRAY_LENGTH(pcb_list); i++)
617   {
618      if (!mame_stricmp(pcb_list[i].pcb_name, board))
619         return &pcb_list[i];
620   }
621   return NULL;
622}
623
624int nes_get_pcb_id( running_machine &machine, const char *feature )
625{
626   const nes_pcb *pcb = nes_pcb_lookup(feature);
627
628   if (pcb == NULL)
629      fatalerror("Unimplemented PCB type %s\n", feature);
630
631   return pcb->pcb_id;
632}
633
634/************************************************
635
636   PCB Emulation (to be moved to MAME later)
637
638   In the end, iNES, UNIF and xml should be
639   simply handled through a look-up table
640   which associates the mapper/board/feature
641   to the correct pcb_id and then the core
642   function pcb_handlers_setup should be called
643   to set-up the expected handlers and callbacks
644
645   Similarly, PC-10, VSNES and NES-based
646   multigame boards, should simply call
647   pcb_handlers_setup with the proper pcb_id
648   at the beginning, rather than use ad hoc
649   implementations.
650
651************************************************/
652
653// helper function for the few mappers reading from 0x8000-0xffff for protection
654INLINE UINT8 mmc_hi_access_rom( running_machine &machine, UINT32 offset )
655{
656   nes_state *state = machine.driver_data<nes_state>();
657
658   // usual ROM access
659   switch (offset & 0x6000)
660   {
661      case 0x0000:
662         return state->m_rom[0x10000 + state->m_prg_bank[0] * 0x2000 + (offset & 0x1fff)];
663      case 0x2000:
664         return state->m_rom[0x10000 + state->m_prg_bank[1] * 0x2000 + (offset & 0x1fff)];
665      case 0x4000:
666         return state->m_rom[0x10000 + state->m_prg_bank[2] * 0x2000 + (offset & 0x1fff)];
667      case 0x6000:
668         return state->m_rom[0x10000 + state->m_prg_bank[3] * 0x2000 + (offset & 0x1fff)];
669   }
670   return 0;
671}
672
673/*************************************************************
674
675 NROM board emulation
676
677 Games: Mario Bros., Super Mario Bros., Tennis and most of
678 the first generation games
679
680 iNES: mapper 0
681
682 In MESS: Supported, no need of specific handlers or IRQ
683
684 *************************************************************/
685
686/*************************************************************
687
688 UxROM board emulation
689
690 Games: Castlevania, Dragon Quest II, Duck Tales, MegaMan,
691 Metal Gear
692
693 writes to 0x8000-0xffff change PRG 16K lower banks
694
695 missing BC?
696
697 iNES: mapper 2
698
699 In MESS: Supported.
700
701 *************************************************************/
702
703static WRITE8_HANDLER( uxrom_w )
704{
705   LOG_MMC(("uxrom_w, offset: %04x, data: %02x\n", offset, data));
706
707   prg16_89ab(space->machine(), data);
708}
709
710/*************************************************************
711
712 Nihon Bussan UNROM M5
713
714 Games: Crazy Climber Jpn
715
716 Very simple mapper: prg16_89ab is always set to bank 0,
717 while prg16_cdef is set by writes to 0x8000-0xffff. The game
718 uses a custom controller.
719
720 iNES: mapper 180
721
722 In MESS: Supported.
723
724 *************************************************************/
725
726static WRITE8_HANDLER( uxrom_cc_w )
727{
728   LOG_MMC(("uxrom_cc_w, offset: %04x, data: %02x\n", offset, data));
729
730   prg16_cdef(space->machine(), data);
731}
732
733/*************************************************************
734
735 UN1ROM board emulation
736
737 Games: Senjou no Okami
738
739 writes to 0x8000-0xffff change PRG 16K lower banks
740
741 missing BC?
742
743 iNES: mapper 94
744
745 In MESS: Supported.
746
747 *************************************************************/
748
749static WRITE8_HANDLER( un1rom_w )
750{
751   LOG_MMC(("un1rom_w, offset: %04x, data: %02x\n", offset, data));
752
753   prg16_89ab(space->machine(), data >> 2);
754}
755
756/*************************************************************
757
758 CNROM board emulation
759
760 Games: B-Wings, Mighty Bomb Jack, Seicross, Spy vs. Spy,
761 Adventure Island, Flipull, Friday 13th, GeGeGe no
762 Kitarou, Ghostbusters, Gradius, Hokuto no Ken, Milon's
763 Secret Castle
764
765 writes to 0x8000-0xffff change CHR 8K banks
766
767 missing BC?
768
769 iNES: mappers 3 & 185 (the latter for games using Pins as
770 protection)
771
772 Notice that BANDAI_PT554 board (Aerobics Studio) uses very
773 similar hardware but with an additional sound chip which
774 gets writes to 0x6000 (currently unemulated in MESS)
775
776 In MESS: Supported
777
778 *************************************************************/
779
780static WRITE8_HANDLER( cnrom_w )
781{
782   nes_state *state = space->machine().driver_data<nes_state>();
783   LOG_MMC(("cnrom_w, offset: %04x, data: %02x\n", offset, data));
784
785   if (state->m_ce_mask)
786   {
787      chr8(space->machine(), data & ~state->m_ce_mask, CHRROM);
788
789      if ((data & state->m_ce_mask) == state->m_ce_state)
790         state->m_chr_open_bus = 0;
791      else
792         state->m_chr_open_bus = 1;
793   }
794   else
795      chr8(space->machine(), data, CHRROM);
796}
797
798/*************************************************************
799
800 Bandai PT-554 board emulation
801
802 This is used by Aerobics Studio. It is basically a CNROM board
803 with an additional sound chip which is not currently emulated by
804 MESS
805
806 iNES: mapper 3?
807
808 *************************************************************/
809
810static WRITE8_HANDLER( bandai_pt554_m_w )
811{
812   LOG_MMC(("Bandai PT-554 Sound write, data: %02x\n", data));
813
814   // according to NEStopia, this is the effect
815   if (!BIT(data, 6))
816   {
817      // send command (data & 0x07) to sound chip
818   }
819}
820
821/*************************************************************
822
823 CPROM board emulation
824
825 Games: Videomation
826
827 writes to 0x8000-0xffff change CHR 4K lower banks
828
829 iNES: mapper 13
830
831 In MESS: Supported
832
833 *************************************************************/
834
835static WRITE8_HANDLER( cprom_w )
836{
837   LOG_MMC(("cprom_w, offset: %04x, data: %02x\n", offset, data));
838   chr4_4(space->machine(), data, CHRRAM);
839}
840
841/*************************************************************
842
843 AxROM board emulation
844
845 Games: Arch Rivals, Battletoads, Cabal, Commando, Solstice
846
847 writes to 0x8000-0xffff change PRG banks + sets mirroring
848
849 missing BC for AMROM?
850
851 iNES: mapper 7
852
853 In MESS: Supported
854
855 *************************************************************/
856
857static WRITE8_HANDLER( axrom_w )
858{
859   LOG_MMC(("axrom_w, offset: %04x, data: %02x\n", offset, data));
860
861   set_nt_mirroring(space->machine(), BIT(data, 4) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
862   prg32(space->machine(), data);
863}
864
865/*************************************************************
866
867 BxROM board emulation
868
869 writes to 0x8000-0xffff change PRG banks
870
871 missing BC?
872
873 iNES: mapper 34
874
875 *************************************************************/
876
877static WRITE8_HANDLER( bxrom_w )
878{
879   /* This portion of the mapper is nearly identical to Mapper 7, except no one-screen mirroring */
880   /* Deadly Towers is really a BxROM game - the demo screens look wrong using mapper 7. */
881   LOG_MMC(("bxrom_w, offset: %04x, data: %02x\n", offset, data));
882
883   prg32(space->machine(), data);
884}
885
886/*************************************************************
887
888 GxROM/MxROM board emulation
889
890 writes to 0x8000-0xffff change PRG and CHR banks
891
892 missing BC?
893
894 iNES: mapper 66
895
896 *************************************************************/
897
898static WRITE8_HANDLER( gxrom_w )
899{
900   LOG_MMC(("gxrom_w, offset %04x, data: %02x\n", offset, data));
901
902   prg32(space->machine(), (data & 0xf0) >> 4);
903   chr8(space->machine(), data & 0x0f, CHRROM);
904}
905
906/*************************************************************
907
908 SxROM (MMC1 based) board emulation
909
910 iNES: mapper 1 (and 155 for the MMC1A variant which does not
911 have WRAM disable bit)
912
913 *************************************************************/
914
915static TIMER_CALLBACK( mmc1_resync_callback )
916{
917   nes_state *state = machine.driver_data<nes_state>();
918   state->m_mmc1_reg_write_enable = 1;
919}
920
921
922static void mmc1_set_wram( address_space *space, int board )
923{
924   running_machine &machine = space->machine();
925   nes_state *state = machine.driver_data<nes_state>();
926   UINT8 bank = BIT(state->m_mmc_reg[0], 4) ? BIT(state->m_mmc_reg[1], 4) : BIT(state->m_mmc_reg[1], 3);
927
928   switch (board)
929   {
930      case STD_SXROM:      // here also reads are disabled!
931         if (!BIT(state->m_mmc_reg[3], 4))
932            space->install_readwrite_bank(0x6000, 0x7fff, "bank5");
933         else
934         {
935            space->unmap_readwrite(0x6000, 0x7fff);
936            break;
937         }
938      case STD_SXROM_A:   // ignore WRAM enable bit
939         if (state->m_battery_size > 0x2000)
940            wram_bank(machine, ((state->m_mmc_reg[1] & 3) >> 2), NES_BATTERY);
941         else if (state->m_battery_size)
942            wram_bank(machine, 0, NES_BATTERY);
943         break;
944      case STD_SOROM:      // there are 2 WRAM banks only and battery is bank 2 for the cart (hence, we invert bank, because we have battery first)
945         if (!BIT(state->m_mmc_reg[3], 4))
946            space->install_readwrite_bank(0x6000, 0x7fff, "bank5");
947         else
948         {
949            space->unmap_readwrite(0x6000, 0x7fff);
950            break;
951         }
952      case STD_SOROM_A:   // ignore WRAM enable bit
953         wram_bank(machine, 0, bank ? NES_BATTERY : NES_WRAM);
954         break;
955   }
956}
957
958static void mmc1_set_prg( running_machine &machine )
959{
960   nes_state *state = machine.driver_data<nes_state>();
961   UINT8 prg_mode, prg_offset;
962
963   prg_mode = state->m_mmc_reg[0] & 0x0c;
964   /* prg_mode&0x8 determines bank size: 32k (if 0) or 16k (if 1)? when in 16k mode,
965     prg_mode&0x4 determines which half of the PRG space we can swap: if it is 4,
966     mmc_reg[3] sets banks at 0x8000; if it is 0, mmc_reg[3] sets banks at 0xc000. */
967
968   prg_offset = state->m_mmc_reg[1] & 0x10;
969   /* In principle, mmc_reg[2]&0x10 might affect "extended" banks as well, when chr_mode=1.
970     However, quoting Disch's docs: When in 4k CHR mode, 0x10 in both $A000 and $C000 *must* be
971     set to the same value, or else pages will constantly be swapped as graphics render!
972     Hence, we use only mmc_reg[1]&0x10 for prg_offset */
973
974   switch (prg_mode)
975   {
976      case 0x00:
977      case 0x04:
978//          printf("PRG 32 bank %d \n", (prg_offset + state->m_mmc_reg[3]) >> 1);
979         prg32(machine, (prg_offset + state->m_mmc_reg[3]) >> 1);
980         break;
981      case 0x08:
982//          printf("PRG 16 bank %d (high) \n", prg_offset + state->m_mmc_reg[3]);
983         prg16_89ab(machine, prg_offset + 0);
984         prg16_cdef(machine, prg_offset + state->m_mmc_reg[3]);
985         break;
986      case 0x0c:
987//          printf("PRG 16 bank %d (low) \n", prg_offset + state->m_mmc_reg[3]);
988         prg16_89ab(machine, prg_offset + state->m_mmc_reg[3]);
989         prg16_cdef(machine, prg_offset + 0x0f);
990         break;
991   }
992}
993
994static void mmc1_set_prg_wram( address_space *space, int board )
995{
996   mmc1_set_prg(space->machine());
997   mmc1_set_wram(space, board);
998}
999
1000static void mmc1_set_chr( running_machine &machine )
1001{
1002   nes_state *state = machine.driver_data<nes_state>();
1003   UINT8 chr_mode = BIT(state->m_mmc_reg[0], 4);
1004
1005   if (chr_mode)
1006   {
1007      chr4_0(machine, state->m_mmc_reg[1] & 0x1f, state->m_mmc_chr_source);
1008      chr4_4(machine, state->m_mmc_reg[2] & 0x1f, state->m_mmc_chr_source);
1009   }
1010   else
1011      chr8(machine, (state->m_mmc_reg[1] & 0x1f) >> 1, state->m_mmc_chr_source);
1012}
1013
1014static void common_sxrom_write_handler( address_space *space, offs_t offset, UINT8 data, int board )
1015{
1016   running_machine &machine = space->machine();
1017   nes_state *state = machine.driver_data<nes_state>();
1018   /* Note that there is only one latch and shift counter, shared amongst the 4 regs */
1019   /* Space Shuttle will not work if they have independent variables. */
1020
1021   /* here we would need to add an if(cpu_cycles_passed>1) test, and
1022     if requirement is not met simply return without writing anything.
1023     Some games (AD&D Hillsfar, Bill & Ted Excellent Adventure, Cosmic
1024     Wars, Rocket Ranger, Sesame Street 123 and Snow Brothers) rely on
1025     this behavior!! */
1026   if (state->m_mmc1_reg_write_enable == 0)
1027   {
1028      return;
1029   }
1030   else
1031   {
1032      state->m_mmc1_reg_write_enable = 0;
1033      space->machine().scheduler().synchronize(FUNC(mmc1_resync_callback));
1034   }
1035
1036   if (data & 0x80)
1037   {
1038      state->m_mmc1_count = 0;
1039      state->m_mmc1_latch = 0;
1040
1041      /* Set reg at 0x8000 to size 16k and lower half swap - needed for Robocop 3, Dynowars */
1042      state->m_mmc_reg[0] |= 0x0c;
1043      mmc1_set_prg_wram(space, board);
1044      return;
1045   }
1046
1047   if (state->m_mmc1_count < 5)
1048   {
1049      if (state->m_mmc1_count == 0) state->m_mmc1_latch = 0;
1050      state->m_mmc1_latch >>= 1;
1051      state->m_mmc1_latch |= (data & 0x01) ? 0x10 : 0x00;
1052      state->m_mmc1_count++;
1053   }
1054
1055   if (state->m_mmc1_count == 5)
1056   {
1057      switch (offset & 0x6000)   /* Which reg shall we write to? */
1058      {
1059         case 0x0000:
1060            state->m_mmc_reg[0] = state->m_mmc1_latch;
1061
1062            switch (state->m_mmc_reg[0] & 0x03)
1063            {
1064            case 0: set_nt_mirroring(machine, PPU_MIRROR_LOW); break;
1065            case 1: set_nt_mirroring(machine, PPU_MIRROR_HIGH); break;
1066            case 2: set_nt_mirroring(machine, PPU_MIRROR_VERT); break;
1067            case 3: set_nt_mirroring(machine, PPU_MIRROR_HORZ); break;
1068            }
1069            mmc1_set_chr(machine);
1070            mmc1_set_prg_wram(space, board);
1071            break;
1072         case 0x2000:
1073            state->m_mmc_reg[1] = state->m_mmc1_latch;
1074            mmc1_set_chr(machine);
1075            mmc1_set_prg_wram(space, board);
1076            break;
1077         case 0x4000:
1078            state->m_mmc_reg[2] = state->m_mmc1_latch;
1079            mmc1_set_chr(machine);
1080            break;
1081         case 0x6000:
1082            state->m_mmc_reg[3] = state->m_mmc1_latch;
1083            mmc1_set_prg_wram(space, board);
1084            break;
1085      }
1086      state->m_mmc1_count = 0;
1087   }
1088}
1089
1090static WRITE8_HANDLER( sxrom_w )
1091{
1092   nes_state *state = space->machine().driver_data<nes_state>();
1093
1094   LOG_MMC(("sxrom_w, offset: %04x, data: %02x\n", offset, data));
1095   common_sxrom_write_handler(space, offset, data, state->m_pcb_id);
1096}
1097
1098/*************************************************************
1099
1100 PxROM (MMC2 based) board emulation
1101
1102 Games: Punch Out!!, Mike Tyson's Punch Out!!
1103
1104 iNES: mapper 9
1105
1106 In MESS: Supported
1107
1108 *************************************************************/
1109
1110static void mmc2_latch( device_t *device, offs_t offset )
1111{
1112   nes_state *state = device->machine().driver_data<nes_state>();
1113   if ((offset & 0x3ff0) == 0x0fd0)
1114   {
1115      LOG_MMC(("mmc2 vrom latch switch (bank 0 low): %02x\n", state->m_mmc_reg[0]));
1116      state->m_mmc_latch1 = 0xfd;
1117      chr4_0(device->machine(), state->m_mmc_reg[0], CHRROM);
1118   }
1119   else if ((offset & 0x3ff0) == 0x0fe0)
1120   {
1121      LOG_MMC(("mmc2 vrom latch switch (bank 0 high): %02x\n", state->m_mmc_reg[1]));
1122      state->m_mmc_latch1 = 0xfe;
1123      chr4_0(device->machine(), state->m_mmc_reg[1], CHRROM);
1124   }
1125   else if ((offset & 0x3ff0) == 0x1fd0)
1126   {
1127      LOG_MMC(("mmc2 vrom latch switch (bank 1 low): %02x\n", state->m_mmc_reg[2]));
1128      state->m_mmc_latch2 = 0xfd;
1129      chr4_4(device->machine(), state->m_mmc_reg[2], CHRROM);
1130   }
1131   else if ((offset & 0x3ff0) == 0x1fe0)
1132   {
1133      LOG_MMC(("mmc2 vrom latch switch (bank 0 high): %02x\n", state->m_mmc_reg[3]));
1134      state->m_mmc_latch2 = 0xfe;
1135      chr4_4(device->machine(), state->m_mmc_reg[3], CHRROM);
1136   }
1137}
1138
1139static WRITE8_HANDLER( pxrom_w )
1140{
1141   nes_state *state = space->machine().driver_data<nes_state>();
1142   LOG_MMC(("pxrom_w, offset: %04x, data: %02x\n", offset, data));
1143   switch (offset & 0x7000)
1144   {
1145      case 0x2000:
1146         prg8_89(space->machine(), data);
1147         break;
1148      case 0x3000:
1149         state->m_mmc_reg[0] = data;
1150         if (state->m_mmc_latch1 == 0xfd)
1151            chr4_0(space->machine(), state->m_mmc_reg[0], CHRROM);
1152         break;
1153      case 0x4000:
1154         state->m_mmc_reg[1] = data;
1155         if (state->m_mmc_latch1 == 0xfe)
1156            chr4_0(space->machine(), state->m_mmc_reg[1], CHRROM);
1157         break;
1158      case 0x5000:
1159         state->m_mmc_reg[2] = data;
1160         if (state->m_mmc_latch2 == 0xfd)
1161            chr4_4(space->machine(), state->m_mmc_reg[2], CHRROM);
1162         break;
1163      case 0x6000:
1164         state->m_mmc_reg[3] = data;
1165         if (state->m_mmc_latch2 == 0xfe)
1166            chr4_4(space->machine(), state->m_mmc_reg[3], CHRROM);
1167         break;
1168      case 0x7000:
1169         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1170         break;
1171      default:
1172         LOG_MMC(("MMC2 uncaught w: %04x:%02x\n", offset, data));
1173         break;
1174   }
1175}
1176
1177/*************************************************************
1178
1179 FxROM (MMC4 based) board emulation
1180
1181 Games: Famicom Wars, Fire Emblem, Fire Emblem Gaiden
1182
1183 iNES: mapper 10
1184
1185 In MESS: Supported
1186
1187*************************************************************/
1188
1189static WRITE8_HANDLER( fxrom_w )
1190{
1191   LOG_MMC(("fxrom_w, offset: %04x, data: %02x\n", offset, data));
1192   switch (offset & 0x7000)
1193   {
1194      case 0x2000:
1195         prg16_89ab(space->machine(), data);
1196         break;
1197      default:
1198         pxrom_w(space, offset, data);
1199         break;
1200   }
1201}
1202
1203/*************************************************************
1204
1205 TxROM (MMC3 based) board emulation
1206
1207 iNES: mapper 4
1208
1209 *************************************************************/
1210
1211static void mmc3_set_wram( address_space *space )
1212{
1213   running_machine &machine = space->machine();
1214   nes_state *state = machine.driver_data<nes_state>();
1215
1216   // skip this function if we are emulating a MMC3 clone with mid writes
1217   if (state->m_mmc_write_mid != NULL)
1218      return;
1219
1220   if (BIT(state->m_mmc3_wram_protect, 7))
1221      space->install_readwrite_bank(0x6000, 0x7fff, "bank5");
1222   else
1223   {
1224      space->unmap_readwrite(0x6000, 0x7fff);
1225      return;
1226   }
1227
1228   if (!BIT(state->m_mmc3_wram_protect, 6))
1229      space->install_write_bank(0x6000, 0x7fff, "bank5");
1230   else
1231   {
1232      space->unmap_write(0x6000, 0x7fff);
1233      return;
1234   }
1235}
1236
1237static void mmc3_set_prg( running_machine &machine, int prg_base, int prg_mask )
1238{
1239   nes_state *state = machine.driver_data<nes_state>();
1240   UINT8 prg_flip = (state->m_mmc3_latch & 0x40) ? 2 : 0;
1241
1242   state->m_mmc3_prg_cb(machine, 0, prg_base | (state->m_mmc_prg_bank[0 ^ prg_flip] & prg_mask));
1243   state->m_mmc3_prg_cb(machine, 1, prg_base | (state->m_mmc_prg_bank[1] & prg_mask));
1244   state->m_mmc3_prg_cb(machine, 2, prg_base | (state->m_mmc_prg_bank[2 ^ prg_flip] & prg_mask));
1245   state->m_mmc3_prg_cb(machine, 3, prg_base | (state->m_mmc_prg_bank[3] & prg_mask));
1246}
1247
1248static void mmc3_set_chr( running_machine &machine, UINT8 chr, int chr_base, int chr_mask )
1249{
1250   nes_state *state = machine.driver_data<nes_state>();
1251   UINT8 chr_page = (state->m_mmc3_latch & 0x80) >> 5;
1252
1253   state->m_mmc3_chr_cb(machine, chr_page ^ 0, chr_base | ((state->m_mmc_vrom_bank[0] & ~0x01) & chr_mask), chr);
1254   state->m_mmc3_chr_cb(machine, chr_page ^ 1, chr_base | ((state->m_mmc_vrom_bank[0] |  0x01) & chr_mask), chr);
1255   state->m_mmc3_chr_cb(machine, chr_page ^ 2, chr_base | ((state->m_mmc_vrom_bank[1] & ~0x01) & chr_mask), chr);
1256   state->m_mmc3_chr_cb(machine, chr_page ^ 3, chr_base | ((state->m_mmc_vrom_bank[1] |  0x01) & chr_mask), chr);
1257   state->m_mmc3_chr_cb(machine, chr_page ^ 4, chr_base | (state->m_mmc_vrom_bank[2] & chr_mask), chr);
1258   state->m_mmc3_chr_cb(machine, chr_page ^ 5, chr_base | (state->m_mmc_vrom_bank[3] & chr_mask), chr);
1259   state->m_mmc3_chr_cb(machine, chr_page ^ 6, chr_base | (state->m_mmc_vrom_bank[4] & chr_mask), chr);
1260   state->m_mmc3_chr_cb(machine, chr_page ^ 7, chr_base | (state->m_mmc_vrom_bank[5] & chr_mask), chr);
1261}
1262
1263/* Here, IRQ counter decrements every scanline. */
1264static void mmc3_irq( device_t *device, int scanline, int vblank, int blanked )
1265{
1266   nes_state *state = device->machine().driver_data<nes_state>();
1267
1268   if (scanline < PPU_BOTTOM_VISIBLE_SCANLINE)
1269   {
1270      int priorCount = state->m_IRQ_count;
1271      if ((state->m_IRQ_count == 0) || state->m_IRQ_clear)
1272         state->m_IRQ_count = state->m_IRQ_count_latch;
1273      else
1274         state->m_IRQ_count--;
1275
1276      if (state->m_IRQ_enable && !blanked && (state->m_IRQ_count == 0) && (priorCount || state->m_IRQ_clear /*|| !state->m_mmc3_alt_irq*/)) // according to blargg the latter should be present as well, but it breaks Rampart and Joe & Mac US: they probably use the alt irq!
1277      {
1278         LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
1279                device->machine().primary_screen->vpos(), device->machine().primary_screen->hpos()));
1280         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
1281      }
1282   }
1283   state->m_IRQ_clear = 0;
1284}
1285
1286static WRITE8_HANDLER( txrom_w )
1287{
1288   nes_state *state = space->machine().driver_data<nes_state>();
1289   UINT8 mmc_helper, cmd;
1290
1291   LOG_MMC(("txrom_w, offset: %04x, data: %02x\n", offset, data));
1292
1293   switch (offset & 0x6001)
1294   {
1295      case 0x0000:
1296         mmc_helper = state->m_mmc3_latch ^ data;
1297         state->m_mmc3_latch = data;
1298
1299         /* Has PRG Mode changed? */
1300         if (mmc_helper & 0x40)
1301            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
1302
1303         /* Has CHR Mode changed? */
1304         if (mmc_helper & 0x80)
1305            mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
1306         break;
1307
1308      case 0x0001:
1309         cmd = state->m_mmc3_latch & 0x07;
1310         switch (cmd)
1311         {
1312         case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
1313         case 2: case 3: case 4: case 5:
1314            state->m_mmc_vrom_bank[cmd] = data;
1315            mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
1316            break;
1317         case 6:
1318         case 7:
1319            state->m_mmc_prg_bank[cmd - 6] = data;
1320            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
1321            break;
1322         }
1323         break;
1324
1325      case 0x2000:
1326         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1327         break;
1328
1329      case 0x2001:
1330         state->m_mmc3_wram_protect = data;
1331         mmc3_set_wram(space);
1332         break;
1333
1334      case 0x4000:
1335         state->m_IRQ_count_latch = data;
1336         break;
1337
1338      case 0x4001:
1339         state->m_IRQ_count = 0;
1340         break;
1341
1342      case 0x6000:
1343         state->m_IRQ_enable = 0;
1344         break;
1345
1346      case 0x6001:
1347         state->m_IRQ_enable = 1;
1348         break;
1349
1350      default:
1351         logerror("txrom_w uncaught: %04x value: %02x\n", offset + 0x8000, data);
1352         break;
1353   }
1354}
1355
1356/*************************************************************
1357
1358 HKROM (MMC6 based) board emulation
1359
1360 iNES: mapper 4
1361
1362 *************************************************************/
1363
1364static WRITE8_HANDLER( hkrom_m_w )
1365{
1366   nes_state *state = space->machine().driver_data<nes_state>();
1367   UINT8 write_hi, write_lo;
1368   LOG_MMC(("hkrom_m_w, offset: %04x, data: %02x\n", offset, data));
1369
1370   if (offset < 0x1000)
1371      return;
1372
1373   // banks can be written only if both read & write is enabled!
1374   write_hi = ((state->m_mmc6_reg & 0xc0) == 0xc0);
1375   write_lo = ((state->m_mmc6_reg & 0x30) == 0x30);
1376
1377   if (BIT(offset, 9) && write_hi)   // access to upper 1k
1378      state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)] = data;
1379
1380   if (!BIT(offset, 9) && write_lo)   // access to lower 1k
1381      state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)] = data;
1382}
1383
1384static READ8_HANDLER( hkrom_m_r )
1385{
1386   nes_state *state = space->machine().driver_data<nes_state>();
1387   LOG_MMC(("hkrom_m_r, offset: %04x\n", offset));
1388
1389   if (offset < 0x1000)
1390      return 0xff;   // here it should be open bus
1391
1392   if (!(state->m_mmc6_reg & 0xa0))
1393      return 0xff;   // here it should be open bus
1394
1395   if (BIT(offset, 9) && BIT(state->m_mmc6_reg, 7))   // access to upper 1k when upper read is enabled
1396      return state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)];
1397
1398   if (!BIT(offset, 9) && BIT(state->m_mmc6_reg, 5))   // access to lower 1k when lower read is enabled
1399      return state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)];
1400
1401   // If only one bank is enabled for reading, the other reads back as zero
1402   return 0x00;
1403}
1404
1405static WRITE8_HANDLER( hkrom_w )
1406{
1407   nes_state *state = space->machine().driver_data<nes_state>();
1408   UINT8 mmc6_helper;
1409   LOG_MMC(("hkrom_w, offset: %04x, data: %02x\n", offset, data));
1410
1411   switch (offset & 0x6001)
1412   {
1413      case 0x0000:
1414         mmc6_helper = state->m_mmc3_latch ^ data;
1415         state->m_mmc3_latch = data;
1416
1417         if (!state->m_mmc_latch2 && BIT(data, 5))   // if WRAM is disabled and has to be enabled, write
1418            state->m_mmc_latch2 = BIT(data, 5);   // (once WRAM has been enabled, it cannot be disabled without resetting the game)
1419
1420         /* Has PRG Mode changed? */
1421         if (BIT(mmc6_helper, 6))
1422            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
1423
1424         /* Has CHR Mode changed? */
1425         if (BIT(mmc6_helper, 7))
1426            mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
1427         break;
1428
1429      case 0x2001:
1430         if (state->m_mmc_latch2)
1431            state->m_mmc6_reg = data;
1432         break;
1433
1434      case 0x4001:
1435         state->m_IRQ_count = 0;
1436         state->m_IRQ_clear = 1;
1437         break;
1438
1439      default:
1440         txrom_w(space, offset, data);
1441         break;
1442   }
1443}
1444
1445/*************************************************************
1446
1447 TxSROM (MMC3 based) board emulation
1448
1449 Games: Armadillo, Play Action Football, Pro Hockey, RPG
1450 Jinsei Game, Y's 3
1451
1452 iNES: mapper 118
1453
1454 In MESS: Supported. It also uses mmc3_irq.
1455
1456 *************************************************************/
1457
1458static void txsrom_set_mirror( running_machine &machine )
1459{
1460   nes_state *state = machine.driver_data<nes_state>();
1461   if (state->m_mmc3_latch & 0x80)
1462   {
1463      set_nt_page(machine, 0, CIRAM, (state->m_mmc_vrom_bank[2] & 0x80) >> 7, 1);
1464      set_nt_page(machine, 1, CIRAM, (state->m_mmc_vrom_bank[3] & 0x80) >> 7, 1);
1465      set_nt_page(machine, 2, CIRAM, (state->m_mmc_vrom_bank[4] & 0x80) >> 7, 1);
1466      set_nt_page(machine, 3, CIRAM, (state->m_mmc_vrom_bank[5] & 0x80) >> 7, 1);
1467   }
1468   else
1469   {
1470      set_nt_page(machine, 0, CIRAM, (state->m_mmc_vrom_bank[0] & 0x80) >> 7, 1);
1471      set_nt_page(machine, 1, CIRAM, (state->m_mmc_vrom_bank[0] & 0x80) >> 7, 1);
1472      set_nt_page(machine, 2, CIRAM, (state->m_mmc_vrom_bank[1] & 0x80) >> 7, 1);
1473      set_nt_page(machine, 3, CIRAM, (state->m_mmc_vrom_bank[1] & 0x80) >> 7, 1);
1474   }
1475}
1476
1477static void txsrom_chr_cb( running_machine &machine, int start, int bank, int source )
1478{
1479   txsrom_set_mirror(machine);   // we could probably update only for one (e.g. the first) call, to slightly optimize the code
1480   chr1_x(machine, start, bank, source);
1481}
1482
1483static WRITE8_HANDLER( txsrom_w )
1484{
1485   LOG_MMC(("txsrom_w, offset: %04x, data: %02x\n", offset, data));
1486
1487   switch (offset & 0x6001)
1488   {
1489      case 0x2000:
1490         break;
1491
1492      default:
1493         txrom_w(space, offset, data);
1494         break;
1495   }
1496}
1497
1498/*************************************************************
1499
1500 TQROM (MMC3 based) board emulation
1501
1502 Games: Pin Bot, High Speed
1503
1504 iNES: mapper 119
1505
1506 In MESS: Supported. It also uses mmc3_irq.
1507
1508 *************************************************************/
1509
1510static void tqrom_set_chr( running_machine &machine )
1511{
1512   nes_state *state = machine.driver_data<nes_state>();
1513   UINT8 chr_page = (state->m_mmc3_latch & 0x80) >> 5;
1514   UINT8 chr_src[6], chr_mask[6];
1515   int i;
1516
1517   for (i = 0; i < 6; i++)
1518   {
1519      chr_src[i] = (state->m_mmc_vrom_bank[i] & 0x40) ? CHRRAM : CHRROM;
1520      chr_mask[i] =  (state->m_mmc_vrom_bank[i] & 0x40) ? 0x07 : 0x3f;
1521   }
1522
1523   chr1_x(machine, chr_page ^ 0, ((state->m_mmc_vrom_bank[0] & ~0x01) & chr_mask[0]), chr_src[0]);
1524   chr1_x(machine, chr_page ^ 1, ((state->m_mmc_vrom_bank[0] |  0x01) & chr_mask[0]), chr_src[0]);
1525   chr1_x(machine, chr_page ^ 2, ((state->m_mmc_vrom_bank[1] & ~0x01) & chr_mask[1]), chr_src[1]);
1526   chr1_x(machine, chr_page ^ 3, ((state->m_mmc_vrom_bank[1] |  0x01) & chr_mask[1]), chr_src[1]);
1527   chr1_x(machine, chr_page ^ 4, (state->m_mmc_vrom_bank[2] & chr_mask[2]), chr_src[2]);
1528   chr1_x(machine, chr_page ^ 5, (state->m_mmc_vrom_bank[3] & chr_mask[3]), chr_src[3]);
1529   chr1_x(machine, chr_page ^ 6, (state->m_mmc_vrom_bank[4] & chr_mask[4]), chr_src[4]);
1530   chr1_x(machine, chr_page ^ 7, (state->m_mmc_vrom_bank[5] & chr_mask[5]), chr_src[5]);
1531}
1532
1533static WRITE8_HANDLER( tqrom_w )
1534{
1535   nes_state *state = space->machine().driver_data<nes_state>();
1536   UINT8 mmc_helper, cmd;
1537   LOG_MMC(("tqrom_w, offset: %04x, data: %02x\n", offset, data));
1538
1539   switch (offset & 0x6001)
1540   {
1541      case 0x0000:
1542         mmc_helper = state->m_mmc3_latch ^ data;
1543         state->m_mmc3_latch = data;
1544
1545         /* Has PRG Mode changed? */
1546         if (mmc_helper & 0x40)
1547            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
1548
1549         /* Has CHR Mode changed? */
1550         if (mmc_helper & 0x80)
1551            tqrom_set_chr(space->machine());
1552         break;
1553      case 0x0001: /* $8001 */
1554         cmd = state->m_mmc3_latch & 0x07;
1555         switch (cmd)
1556         {
1557         case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
1558         case 2: case 3: case 4: case 5:
1559            state->m_mmc_vrom_bank[cmd] = data;
1560            tqrom_set_chr(space->machine());
1561            break;
1562         case 6:
1563         case 7:
1564            state->m_mmc_prg_bank[cmd - 6] = data;
1565            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
1566            break;
1567         }
1568         break;
1569
1570      default:
1571         txrom_w(space, offset, data);
1572         break;
1573   }
1574}
1575
1576/*************************************************************
1577
1578 PAL-ZZ board (MMC3 variant for European 3-in-1 Nintendo cart
1579 Super Mario Bros. + Tetris + Nintendo World Cup)
1580
1581 iNES: mapper 37
1582
1583 *************************************************************/
1584
1585static WRITE8_HANDLER( zz_m_w )
1586{
1587   nes_state *state = space->machine().driver_data<nes_state>();
1588   UINT8 mmc_helper = data & 0x07;
1589   LOG_MMC(("zz_m_w, offset: %04x, data: %02x\n", offset, data));
1590
1591   state->m_mmc_prg_base = (BIT(mmc_helper, 2) << 4) | (((mmc_helper & 0x03) == 0x03) ? 0x08 : 0);
1592   state->m_mmc_prg_mask = (mmc_helper << 1) | 0x07;
1593   state->m_mmc_chr_base = BIT(mmc_helper, 2) << 7;
1594   state->m_mmc_chr_mask = 0x7f;
1595   mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
1596   mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
1597}
1598
1599/*************************************************************
1600
1601 NES-QJ board (MMC3 variant for US 2-in-1 Nintendo cart
1602 Super Spike V'Ball + Nintendo World Cup)
1603
1604 iNES: mapper 47
1605
1606 *************************************************************/
1607
1608static WRITE8_HANDLER( qj_m_w )
1609{
1610   nes_state *state = space->machine().driver_data<nes_state>();
1611   LOG_MMC(("qj_m_w, offset: %04x, data: %02x\n", offset, data));
1612
1613   state->m_mmc_prg_base = BIT(data, 0) << 4;
1614   state->m_mmc_prg_mask = 0x0f;
1615   state->m_mmc_chr_base = BIT(data, 0) << 7;
1616   state->m_mmc_chr_mask = 0x7f;
1617   mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
1618   mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
1619}
1620
1621/*************************************************************
1622
1623 ExROM (MMC5 based) board emulation
1624
1625 Games: Castlevania III, Just Breed, many Koei titles
1626
1627 iNES: mapper 5
1628
1629 MESS status: Mostly Unsupported
1630
1631 *************************************************************/
1632
1633#if 0
1634static void mmc5_update_chr_a( running_machine &machine )
1635{
1636   nes_state *state = machine.driver_data<nes_state>();
1637   switch (state->m_mmc5_chr_mode)
1638   {
1639      case 0:   // 8k banks
1640         chr8(machine, state->m_mmc5_vrom_regA[7] & 0xff, CHRROM);
1641         break;
1642
1643      case 1:   // 4k banks
1644         chr4_0(machine, state->m_mmc5_vrom_regA[3] & 0xff, CHRROM);
1645         chr4_4(machine, state->m_mmc5_vrom_regA[7] & 0xff, CHRROM);
1646         break;
1647
1648      case 2:   // 2k banks
1649         chr2_0(machine, state->m_mmc5_vrom_regA[1], CHRROM);
1650         chr2_2(machine, state->m_mmc5_vrom_regA[3], CHRROM);
1651         chr2_4(machine, state->m_mmc5_vrom_regA[5], CHRROM);
1652         chr2_6(machine, state->m_mmc5_vrom_regA[7], CHRROM);
1653         break;
1654
1655      case 3:   // 1k banks
1656         chr1_0(machine, state->m_mmc5_vrom_regA[0], CHRROM);
1657         chr1_1(machine, state->m_mmc5_vrom_regA[1], CHRROM);
1658         chr1_2(machine, state->m_mmc5_vrom_regA[2], CHRROM);
1659         chr1_3(machine, state->m_mmc5_vrom_regA[3], CHRROM);
1660         chr1_4(machine, state->m_mmc5_vrom_regA[4], CHRROM);
1661         chr1_5(machine, state->m_mmc5_vrom_regA[5], CHRROM);
1662         chr1_6(machine, state->m_mmc5_vrom_regA[6], CHRROM);
1663         chr1_7(machine, state->m_mmc5_vrom_regA[7], CHRROM);
1664         break;
1665   }
1666}
1667
1668static void mmc5_update_chr_b( running_machine &machine )
1669{
1670   nes_state *state = machine.driver_data<nes_state>();
1671   switch (state->m_mmc5_chr_mode)
1672   {
1673      case 0:   // 8k banks
1674         chr8(machine, state->m_mmc5_vrom_regB[3] & 0xff, CHRROM);
1675         break;
1676
1677      case 1:   // 4k banks
1678         chr4_0(machine, state->m_mmc5_vrom_regB[3] & 0xff, CHRROM);
1679         chr4_4(machine, state->m_mmc5_vrom_regB[3] & 0xff, CHRROM);
1680         break;
1681
1682      case 2:   // 2k banks
1683         chr2_0(machine, state->m_mmc5_vrom_regB[1], CHRROM);
1684         chr2_2(machine, state->m_mmc5_vrom_regB[3], CHRROM);
1685         chr2_4(machine, state->m_mmc5_vrom_regB[1], CHRROM);
1686         chr2_6(machine, state->m_mmc5_vrom_regB[3], CHRROM);
1687         break;
1688
1689      case 3:   // 1k banks
1690         chr1_0(machine, state->m_mmc5_vrom_regB[0], CHRROM);
1691         chr1_1(machine, state->m_mmc5_vrom_regB[1], CHRROM);
1692         chr1_2(machine, state->m_mmc5_vrom_regB[2], CHRROM);
1693         chr1_3(machine, state->m_mmc5_vrom_regB[3], CHRROM);
1694         chr1_4(machine, state->m_mmc5_vrom_regB[0], CHRROM);
1695         chr1_5(machine, state->m_mmc5_vrom_regB[1], CHRROM);
1696         chr1_6(machine, state->m_mmc5_vrom_regB[2], CHRROM);
1697         chr1_7(machine, state->m_mmc5_vrom_regB[3], CHRROM);
1698         break;
1699   }
1700}
1701#endif
1702
1703static void mmc5_update_prg( running_machine &machine )
1704{
1705   nes_state *state = machine.driver_data<nes_state>();
1706   int bank1, bank2, bank3;
1707
1708   switch (state->m_mmc5_prg_mode)
1709   {
1710      case 0:   // 32k banks
1711         prg32(machine, state->m_mmc5_prg_regs[3] >> 2);
1712         break;
1713
1714      case 1:   // 16k banks
1715         //          printf("problema 1: %x\n", state->m_mmc5_prg_regs[1]);
1716         bank1 = state->m_mmc5_prg_regs[1];
1717
1718         if (!BIT(bank1, 7))
1719         {
1720            state->m_prg_bank[0] = state->m_prg_chunks + (bank1 & 0x06);
1721            state->m_prg_bank[1] = state->m_prg_chunks + (bank1 & 0x06) + 1;
1722            memory_set_bank(machine, "bank1", state->m_prg_bank[0]);
1723            memory_set_bank(machine, "bank2", state->m_prg_bank[1]);
1724         }
1725         else
1726            prg16_89ab(machine, bank1 >> 1);
1727
1728         prg16_cdef(machine, state->m_mmc5_prg_regs[3] >> 1);
1729         break;
1730
1731      case 2:   // 16k-8k banks
1732         //          printf("problema 2: %x %x\n", state->m_mmc5_prg_regs[1], state->m_mmc5_prg_regs[2]);
1733         bank1 = state->m_mmc5_prg_regs[1];
1734         bank3 = state->m_mmc5_prg_regs[2];
1735
1736         if (!BIT(bank1, 7))
1737         {
1738            state->m_prg_bank[0] = state->m_prg_chunks + (bank1 & 0x06);
1739            state->m_prg_bank[1] = state->m_prg_chunks + (bank1 & 0x06) + 1;
1740            memory_set_bank(machine, "bank1", state->m_prg_bank[0]);
1741            memory_set_bank(machine, "bank2", state->m_prg_bank[1]);
1742         }
1743         else
1744            prg16_89ab(machine, (bank1 & 0x7f) >> 1);
1745
1746         if (!BIT(bank3, 7))
1747         {
1748            state->m_prg_bank[2] = state->m_prg_chunks + (bank3 & 0x07);
1749            memory_set_bank(machine, "bank3", state->m_prg_bank[2]);
1750         }
1751         else
1752            prg8_cd(machine, bank3 & 0x7f);
1753
1754         prg8_ef(machine, state->m_mmc5_prg_regs[3]);
1755         break;
1756
1757      case 3:   // 8k banks
1758         //          printf("problema 3: %x %x %x\n", state->m_mmc5_prg_regs[0], state->m_mmc5_prg_regs[1], state->m_mmc5_prg_regs[2]);
1759         bank1 = state->m_mmc5_prg_regs[0];
1760         bank2 = state->m_mmc5_prg_regs[1];
1761         bank3 = state->m_mmc5_prg_regs[2];
1762
1763         if (!BIT(bank1, 7))
1764         {
1765            state->m_prg_bank[0] = state->m_prg_chunks + (bank1 & 0x07);
1766            memory_set_bank(machine, "bank1", state->m_prg_bank[0]);
1767         }
1768         else
1769            prg8_89(machine, bank1 & 0x7f);
1770
1771         if (!BIT(bank2, 7))
1772         {
1773            state->m_prg_bank[1] = state->m_prg_chunks + (bank2 & 0x07);
1774            memory_set_bank(machine, "bank2", state->m_prg_bank[1]);
1775         }
1776         else
1777            prg8_ab(machine, bank2 & 0x7f);
1778
1779         if (!BIT(bank3, 7))
1780         {
1781            state->m_prg_bank[2] = state->m_prg_chunks + (bank3 & 0x07);
1782            memory_set_bank(machine, "bank3", state->m_prg_bank[2]);
1783         }
1784         else
1785            prg8_cd(machine, bank3 & 0x7f);
1786
1787         prg8_ef(machine, state->m_mmc5_prg_regs[3]);
1788         break;
1789   }
1790}
1791
1792static void mmc5_update_render_mode( running_machine &machine )
1793{
1794}
1795
1796static void mmc5_irq( device_t *device, int scanline, int vblank, int blanked )
1797{
1798   nes_state *state = device->machine().driver_data<nes_state>();
1799
1800#if 1
1801   if (scanline == 0)
1802      state->m_IRQ_status |= 0x40;
1803   else if (scanline > PPU_BOTTOM_VISIBLE_SCANLINE)
1804      state->m_IRQ_status &= ~0x40;
1805#endif
1806
1807   if (scanline == state->m_IRQ_count)
1808   {
1809      if (state->m_IRQ_enable)
1810         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
1811
1812      state->m_IRQ_status = 0xff;
1813   }
1814
1815   /* FIXME: this is ok, but then we would need to update them again when we have the BG Hblank
1816     I leave it commented out until the PPU is updated for this */
1817   //  if (ppu2c0x_is_sprite_8x16(state->m_ppu) || state->m_mmc5_last_chr_a)
1818   //      mmc5_update_chr_a(device->machine());
1819   //  else
1820   //      mmc5_update_chr_b(device->machine());
1821}
1822
1823static void mmc5_ppu_mirror( running_machine &machine, int page, int src )
1824{
1825   switch (src)
1826   {
1827      case 0:   /* CIRAM0 */
1828         set_nt_page(machine, page, CIRAM, 0, 1);
1829         break;
1830      case 1:   /* CIRAM1 */
1831         set_nt_page(machine, page, CIRAM, 1, 1);
1832         break;
1833      case 2:   /* ExRAM */
1834         set_nt_page(machine, page, EXRAM, 0, 1);   // actually only works during rendering.
1835         break;
1836      case 3: /* Fill Registers */
1837         set_nt_page(machine, page, MMC5FILL, 0, 0);
1838         break;
1839      default:
1840         fatalerror("This should never happen");
1841         break;
1842   }
1843}
1844
1845static READ8_HANDLER( exrom_l_r )
1846{
1847   nes_state *state = space->machine().driver_data<nes_state>();
1848   int retVal;
1849
1850   /* $5c00 - $5fff: extended videoram attributes */
1851   if ((offset >= 0x1b00) && (offset <= 0x1eff))
1852   {
1853      return state->m_mapper_ram[offset - 0x1b00];
1854   }
1855
1856   switch (offset)
1857   {
1858      case 0x1104: /* $5204 */
1859#if 0
1860         if (current_scanline == MMC5_scanline)
1861            return 0x80;
1862         else
1863            return 0x00;
1864#else
1865         retVal = state->m_IRQ_status;
1866         state->m_IRQ_status &= ~0x80;
1867         return retVal;
1868#endif
1869
1870      case 0x1105: /* $5205 */
1871         return (state->m_mult1 * state->m_mult2) & 0xff;
1872      case 0x1106: /* $5206 */
1873         return ((state->m_mult1 * state->m_mult2) & 0xff00) >> 8;
1874
1875      default:
1876         logerror("** MMC5 uncaught read, offset: %04x\n", offset + 0x4100);
1877         return 0x00;
1878   }
1879}
1880
1881
1882static WRITE8_HANDLER( exrom_l_w )
1883{
1884   nes_state *state = space->machine().driver_data<nes_state>();
1885
1886   //  LOG_MMC(("Mapper 5 write, offset: %04x, data: %02x\n", offset + 0x4100, data));
1887   /* Send $5000-$5015 to the sound chip */
1888   if ((offset >= 0xf00) && (offset <= 0xf15))
1889   {
1890      nes_psg_w(state->m_sound, offset & 0x1f, data);
1891      return;
1892   }
1893
1894   /* $5c00 - $5fff: extended videoram attributes */
1895   if ((offset >= 0x1b00) && (offset <= 0x1eff))
1896   {
1897      if (state->m_MMC5_vram_protect == 0x03)
1898         state->m_mapper_ram[offset - 0x1b00] = data;
1899      return;
1900   }
1901
1902   switch (offset)
1903   {
1904      case 0x1000: /* $5100 */
1905         state->m_mmc5_prg_mode = data & 0x03;
1906         //          mmc5_update_prg(space->machine());
1907         LOG_MMC(("MMC5 rom bank mode: %02x\n", data));
1908         break;
1909
1910      case 0x1001: /* $5101 */
1911         state->m_mmc5_chr_mode = data & 0x03;
1912         // update chr
1913         LOG_MMC(("MMC5 vrom bank mode: %02x\n", data));
1914         break;
1915
1916      case 0x1002: /* $5102 */
1917         if (data == 0x02)
1918            state->m_MMC5_vram_protect |= 1;
1919         else
1920            state->m_MMC5_vram_protect = 0;
1921         LOG_MMC(("MMC5 vram protect 1: %02x\n", data));
1922         break;
1923      case 0x1003: /* 5103 */
1924         if (data == 0x01)
1925            state->m_MMC5_vram_protect |= 2;
1926         else
1927            state->m_MMC5_vram_protect = 0;
1928         LOG_MMC(("MMC5 vram protect 2: %02x\n", data));
1929         break;
1930
1931      case 0x1004: /* $5104 - Extra VRAM (EXRAM) control */
1932         state->m_mmc5_vram_control = data & 0x03;
1933         // update render
1934         mmc5_update_render_mode(space->machine());
1935         LOG_MMC(("MMC5 exram control: %02x\n", data));
1936         break;
1937
1938      case 0x1005: /* $5105 */
1939         mmc5_ppu_mirror(space->machine(), 0, data & 0x03);
1940         mmc5_ppu_mirror(space->machine(), 1, (data & 0x0c) >> 2);
1941         mmc5_ppu_mirror(space->machine(), 2, (data & 0x30) >> 4);
1942         mmc5_ppu_mirror(space->machine(), 3, (data & 0xc0) >> 6);
1943         // update render
1944         mmc5_update_render_mode(space->machine());
1945         break;
1946
1947         /* tile data for MMC5 flood-fill NT mode */
1948      case 0x1006:
1949         state->m_MMC5_floodtile = data;
1950         break;
1951
1952         /* attr data for MMC5 flood-fill NT mode */
1953      case 0x1007:
1954         switch (data & 3)
1955      {
1956         default:
1957         case 0: state->m_MMC5_floodattr = 0x00; break;
1958         case 1: state->m_MMC5_floodattr = 0x55; break;
1959         case 2: state->m_MMC5_floodattr = 0xaa; break;
1960         case 3: state->m_MMC5_floodattr = 0xff; break;
1961      }
1962         break;
1963
1964      case 0x1013: /* $5113 */
1965         LOG_MMC(("MMC5 mid RAM bank select: %02x\n", data & 0x07));
1966         // FIXME: a few Koei games have both WRAM & BWRAM but here we don't support this (yet)
1967         if (state->m_battery)
1968            wram_bank(space->machine(), data, NES_BATTERY);
1969         else
1970            wram_bank(space->machine(), data, NES_WRAM);
1971         break;
1972
1973
1974      case 0x1014: /* $5114 */
1975      case 0x1015: /* $5115 */
1976      case 0x1016: /* $5116 */
1977      case 0x1017: /* $5117 */
1978         state->m_mmc5_prg_regs[offset & 3] = data;
1979         mmc5_update_prg(space->machine());
1980         break;
1981
1982#if 0
1983      // these do not work as expected... I guess we definitely need the bank update at proper times (with BG vs. sprite timing)
1984      case 0x1020: /* $5120 */
1985      case 0x1021: /* $5121 */
1986      case 0x1022: /* $5122 */
1987      case 0x1023: /* $5123 */
1988      case 0x1024: /* $5124 */
1989      case 0x1025: /* $5125 */
1990      case 0x1026: /* $5126 */
1991      case 0x1027: /* $5127 */
1992         data |= (state->m_mmc5_chr_high << 8);
1993         if (!state->m_mmc5_last_chr_a)
1994         {
1995            state->m_mmc5_vrom_regA[offset & 0x07] = data;
1996            state->m_mmc5_last_chr_a = 1;
1997            if (ppu2c0x_get_current_scanline(state->m_ppu) == 240 || !ppu2c0x_is_sprite_8x16(state->m_ppu))
1998               mmc5_update_chr_a(space->machine());
1999         }
2000         break;
2001
2002
2003      case 0x1028: /* $5128 */
2004      case 0x1029: /* $5129 */
2005      case 0x102a: /* $512a */
2006      case 0x102b: /* $512b */
2007         data |= (state->m_mmc5_chr_high << 8);
2008         state->m_mmc5_vrom_regB[offset & 0x03] = data;
2009         state->m_mmc5_last_chr_a = 0;
2010         if (ppu2c0x_get_current_scanline(state->m_ppu) == 240 || !ppu2c0x_is_sprite_8x16(state->m_ppu))
2011            mmc5_update_chr_b(space->machine());
2012         break;
2013
2014      case 0x1030: /* $5130 */
2015         state->m_mmc5_chr_high = data & 0x03;
2016         if (state->m_mmc5_vram_control == 1)
2017         {
2018            // in this case state->m_mmc5_chr_high selects which 256KB of CHR ROM
2019            // is to be used for all background tiles on the screen.
2020         }
2021         break;
2022
2023#endif
2024
2025      case 0x1020: /* $5120 */
2026         LOG_MMC(("MMC5 $5120 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2027         switch (state->m_mmc5_chr_mode)
2028      {
2029         case 0x03:
2030            /* 1k switch */
2031            state->m_MMC5_vrom_bank[0] = data | (state->m_mmc5_high_chr << 8);
2032            //                  mapper5_sync_vrom(0);
2033            chr1_0(space->machine(), state->m_MMC5_vrom_bank[0], CHRROM);
2034            //                  state->m_nes_vram_sprite[0] = state->m_MMC5_vrom_bank[0] * 64;
2035            //                  vrom_next[0] = 4;
2036            //                  vrom_page_a = 1;
2037            //                  vrom_page_b = 0;
2038            break;
2039      }
2040         break;
2041      case 0x1021: /* $5121 */
2042         LOG_MMC(("MMC5 $5121 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2043         switch (state->m_mmc5_chr_mode)
2044      {
2045         case 0x02:
2046            /* 2k switch */
2047            chr2_0(space->machine(), data | (state->m_mmc5_high_chr << 8), CHRROM);
2048            break;
2049         case 0x03:
2050            /* 1k switch */
2051            state->m_MMC5_vrom_bank[1] = data | (state->m_mmc5_high_chr << 8);
2052            //                  mapper5_sync_vrom(0);
2053            chr1_1(space->machine(), state->m_MMC5_vrom_bank[1], CHRROM);
2054            //                  state->m_nes_vram_sprite[1] = state->m_MMC5_vrom_bank[0] * 64;
2055            //                  vrom_next[1] = 5;
2056            //                  vrom_page_a = 1;
2057            //                  vrom_page_b = 0;
2058            break;
2059      }
2060         break;
2061      case 0x1022: /* $5122 */
2062         LOG_MMC(("MMC5 $5122 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2063         switch (state->m_mmc5_chr_mode)
2064      {
2065         case 0x03:
2066            /* 1k switch */
2067            state->m_MMC5_vrom_bank[2] = data | (state->m_mmc5_high_chr << 8);
2068            //                  mapper5_sync_vrom(0);
2069            chr1_2(space->machine(), state->m_MMC5_vrom_bank[2], CHRROM);
2070            //                  state->m_nes_vram_sprite[2] = state->m_MMC5_vrom_bank[0] * 64;
2071            //                  vrom_next[2] = 6;
2072            //                  vrom_page_a = 1;
2073            //                  vrom_page_b = 0;
2074            break;
2075      }
2076         break;
2077      case 0x1023: /* $5123 */
2078         LOG_MMC(("MMC5 $5123 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2079         switch (state->m_mmc5_chr_mode)
2080      {
2081         case 0x01:
2082            chr4_0(space->machine(), data, CHRROM);
2083            break;
2084         case 0x02:
2085            /* 2k switch */
2086            chr2_2(space->machine(), data | (state->m_mmc5_high_chr << 8), CHRROM);
2087            break;
2088         case 0x03:
2089            /* 1k switch */
2090            state->m_MMC5_vrom_bank[3] = data | (state->m_mmc5_high_chr << 8);
2091            //                  mapper5_sync_vrom(0);
2092            chr1_3(space->machine(), state->m_MMC5_vrom_bank[3], CHRROM);
2093            //                  state->m_nes_vram_sprite[3] = state->m_MMC5_vrom_bank[0] * 64;
2094            //                  vrom_next[3] = 7;
2095            //                  vrom_page_a = 1;
2096            //                  vrom_page_b = 0;
2097            break;
2098      }
2099         break;
2100      case 0x1024: /* $5124 */
2101         LOG_MMC(("MMC5 $5124 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2102         switch (state->m_mmc5_chr_mode)
2103      {
2104         case 0x03:
2105            /* 1k switch */
2106            state->m_MMC5_vrom_bank[4] = data | (state->m_mmc5_high_chr << 8);
2107            //                  mapper5_sync_vrom(0);
2108            chr1_4(space->machine(), state->m_MMC5_vrom_bank[4], CHRROM);
2109            //                  state->m_nes_vram_sprite[4] = state->m_MMC5_vrom_bank[0] * 64;
2110            //                  vrom_next[0] = 0;
2111            //                  vrom_page_a = 0;
2112            //                  vrom_page_b = 0;
2113            break;
2114      }
2115         break;
2116      case 0x1025: /* $5125 */
2117         LOG_MMC(("MMC5 $5125 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2118         switch (state->m_mmc5_chr_mode)
2119      {
2120         case 0x02:
2121            /* 2k switch */
2122            chr2_4(space->machine(), data | (state->m_mmc5_high_chr << 8), CHRROM);
2123            break;
2124         case 0x03:
2125            /* 1k switch */
2126            state->m_MMC5_vrom_bank[5] = data | (state->m_mmc5_high_chr << 8);
2127            //                  mapper5_sync_vrom(0);
2128            chr1_5(space->machine(), state->m_MMC5_vrom_bank[5], CHRROM);
2129            //                  state->m_nes_vram_sprite[5] = state->m_MMC5_vrom_bank[0] * 64;
2130            //                  vrom_next[1] = 1;
2131            //                  vrom_page_a = 0;
2132            //                  vrom_page_b = 0;
2133            break;
2134      }
2135         break;
2136      case 0x1026: /* $5126 */
2137         LOG_MMC(("MMC5 $5126 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2138         switch (state->m_mmc5_chr_mode)
2139      {
2140         case 0x03:
2141            /* 1k switch */
2142            state->m_MMC5_vrom_bank[6] = data | (state->m_mmc5_high_chr << 8);
2143            //                  mapper5_sync_vrom(0);
2144            chr1_6(space->machine(), state->m_MMC5_vrom_bank[6], CHRROM);
2145            //                  state->m_nes_vram_sprite[6] = state->m_MMC5_vrom_bank[0] * 64;
2146            //                  vrom_next[2] = 2;
2147            //                  vrom_page_a = 0;
2148            //                  vrom_page_b = 0;
2149            break;
2150      }
2151         break;
2152      case 0x1027: /* $5127 */
2153         LOG_MMC(("MMC5 $5127 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2154         switch (state->m_mmc5_chr_mode)
2155      {
2156         case 0x00:
2157            /* 8k switch */
2158            chr8(space->machine(), data, CHRROM);
2159            break;
2160         case 0x01:
2161            /* 4k switch */
2162            chr4_4(space->machine(), data, CHRROM);
2163            break;
2164         case 0x02:
2165            /* 2k switch */
2166            chr2_6(space->machine(), data | (state->m_mmc5_high_chr << 8), CHRROM);
2167            break;
2168         case 0x03:
2169            /* 1k switch */
2170            state->m_MMC5_vrom_bank[7] = data | (state->m_mmc5_high_chr << 8);
2171            //                  mapper5_sync_vrom(0);
2172            chr1_7(space->machine(), state->m_MMC5_vrom_bank[7], CHRROM);
2173            //                  state->m_nes_vram_sprite[7] = state->m_MMC5_vrom_bank[0] * 64;
2174            //                  vrom_next[3] = 3;
2175            //                  vrom_page_a = 0;
2176            //                  vrom_page_b = 0;
2177            break;
2178      }
2179         break;
2180      case 0x1028: /* $5128 */
2181         LOG_MMC(("MMC5 $5128 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2182         switch (state->m_mmc5_chr_mode)
2183      {
2184         case 0x03:
2185            /* 1k switch */
2186            state->m_MMC5_vrom_bank[8] = data | (state->m_mmc5_high_chr << 8);
2187            //                  nes_vram[vrom_next[0]] = data * 64;
2188            //                  nes_vram[0 + (vrom_page_a*4)] = data * 64;
2189            //                  nes_vram[0] = data * 64;
2190            chr1_4(space->machine(), state->m_MMC5_vrom_bank[8], CHRROM);
2191            //                  mapper5_sync_vrom(1);
2192            if (!state->m_vrom_page_b)
2193            {
2194               state->m_vrom_page_a ^= 0x01;
2195               state->m_vrom_page_b = 1;
2196            }
2197            break;
2198      }
2199         break;
2200      case 0x1029: /* $5129 */
2201         LOG_MMC(("MMC5 $5129 vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2202         switch (state->m_mmc5_chr_mode)
2203      {
2204         case 0x02:
2205            /* 2k switch */
2206            chr2_0(space->machine(), data | (state->m_mmc5_high_chr << 8), CHRROM);
2207            chr2_4(space->machine(), data | (state->m_mmc5_high_chr << 8), CHRROM);
2208            break;
2209         case 0x03:
2210            /* 1k switch */
2211            state->m_MMC5_vrom_bank[9] = data | (state->m_mmc5_high_chr << 8);
2212            //                  nes_vram[vrom_next[1]] = data * 64;
2213            //                  nes_vram[1 + (vrom_page_a*4)] = data * 64;
2214            //                  nes_vram[1] = data * 64;
2215            chr1_5(space->machine(), state->m_MMC5_vrom_bank[9], CHRROM);
2216            //                  mapper5_sync_vrom(1);
2217            if (!state->m_vrom_page_b)
2218            {
2219               state->m_vrom_page_a ^= 0x01;
2220               state->m_vrom_page_b = 1;
2221            }
2222            break;
2223      }
2224         break;
2225      case 0x102a: /* $512a */
2226         LOG_MMC(("MMC5 $512a vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2227         switch (state->m_mmc5_chr_mode)
2228      {
2229         case 0x03:
2230            /* 1k switch */
2231            state->m_MMC5_vrom_bank[10] = data | (state->m_mmc5_high_chr << 8);
2232            //                  nes_vram[vrom_next[2]] = data * 64;
2233            //                  nes_vram[2 + (vrom_page_a*4)] = data * 64;
2234            //                  nes_vram[2] = data * 64;
2235            chr1_6(space->machine(), state->m_MMC5_vrom_bank[10], CHRROM);
2236            //                  mapper5_sync_vrom(1);
2237            if (!state->m_vrom_page_b)
2238            {
2239               state->m_vrom_page_a ^= 0x01;
2240               state->m_vrom_page_b = 1;
2241            }
2242            break;
2243      }
2244         break;
2245      case 0x102b: /* $512b */
2246         LOG_MMC(("MMC5 $512b vrom select: %02x (mode: %d)\n", data, state->m_mmc5_chr_mode));
2247         switch (state->m_mmc5_chr_mode)
2248      {
2249         case 0x00:
2250            /* 8k switch */
2251            /* switches in first half of an 8K bank!) */
2252            chr4_0(space->machine(), data << 1, CHRROM);
2253            chr4_4(space->machine(), data << 1, CHRROM);
2254            break;
2255         case 0x01:
2256            /* 4k switch */
2257            chr4_0(space->machine(), data, CHRROM);
2258            chr4_4(space->machine(), data, CHRROM);
2259            break;
2260         case 0x02:
2261            /* 2k switch */
2262            chr2_2(space->machine(), data | (state->m_mmc5_high_chr << 8), CHRROM);
2263            chr2_6(space->machine(), data | (state->m_mmc5_high_chr << 8), CHRROM);
2264            break;
2265         case 0x03:
2266            /* 1k switch */
2267            state->m_MMC5_vrom_bank[11] = data | (state->m_mmc5_high_chr << 8);
2268            //                  nes_vram[vrom_next[3]] = data * 64;
2269            //                  nes_vram[3 + (vrom_page_a*4)] = data * 64;
2270            //                  nes_vram[3] = data * 64;
2271            chr1_7(space->machine(), state->m_MMC5_vrom_bank[11], CHRROM);
2272            //                  mapper5_sync_vrom(1);
2273            if (!state->m_vrom_page_b)
2274            {
2275               state->m_vrom_page_a ^= 0x01;
2276               state->m_vrom_page_b = 1;
2277            }
2278            break;
2279      }
2280         break;
2281
2282      case 0x1030: /* $5130 */
2283         state->m_mmc5_high_chr = data & 0x03;
2284         if (state->m_mmc5_vram_control == 1)
2285         {
2286            // in this case state->m_mmc5_high_chr selects which 256KB of CHR ROM
2287            // is to be used for all background tiles on the screen.
2288         }
2289         break;
2290
2291
2292      case 0x1100: /* $5200 */
2293         state->m_mmc5_split_scr = data;
2294         // in EX2 and EX3 modes, no split screen
2295         if (state->m_mmc5_vram_control & 0x02)
2296            state->m_mmc5_split_scr &= 0x7f;
2297         state->m_mmc5_split_ctrl = data;
2298         break;
2299
2300      case 0x1101: /* $5201 */
2301         state->m_mmc5_split_yst = (data >= 240) ? data - 16 : data;
2302         break;
2303
2304      case 0x1102: /* $5202 */
2305         state->m_mmc5_split_bank = data;
2306         break;
2307
2308      case 0x1103: /* $5203 */
2309         state->m_IRQ_count = data;
2310         state->m_MMC5_scanline = data;
2311         LOG_MMC(("MMC5 irq scanline: %d\n", state->m_IRQ_count));
2312         break;
2313      case 0x1104: /* $5204 */
2314         state->m_IRQ_enable = data & 0x80;
2315         LOG_MMC(("MMC5 irq enable: %02x\n", data));
2316         break;
2317      case 0x1105: /* $5205 */
2318         state->m_mult1 = data;
2319         break;
2320      case 0x1106: /* $5206 */
2321         state->m_mult2 = data;
2322         break;
2323
2324      default:
2325         logerror("** MMC5 uncaught write, offset: %04x, data: %02x\n", offset + 0x4100, data);
2326         break;
2327   }
2328}
2329
2330/*************************************************************
2331
2332 NTBROM & Sunsoft-4 board emulation
2333
2334 Part of this can be used also for Sunsoft Double Cassette
2335 System... which games use it?
2336
2337 iNES: mapper 68
2338
2339 *************************************************************/
2340
2341static void ntbrom_mirror( running_machine &machine, int mirror, int mirr0, int mirr1 )
2342{
2343   switch (mirror)
2344   {
2345      case 0x00:
2346         set_nt_mirroring(machine, PPU_MIRROR_HORZ);
2347         break;
2348      case 0x01:
2349         set_nt_mirroring(machine, PPU_MIRROR_VERT);
2350         break;
2351      case 0x02:
2352         set_nt_mirroring(machine, PPU_MIRROR_LOW);
2353         break;
2354      case 0x03:
2355         set_nt_mirroring(machine, PPU_MIRROR_HIGH);
2356         break;
2357      case 0x10:
2358         set_nt_page(machine, 0, ROM, mirr0 | 0x80, 0);
2359         set_nt_page(machine, 1, ROM, mirr1 | 0x80, 0);
2360         set_nt_page(machine, 2, ROM, mirr0 | 0x80, 0);
2361         set_nt_page(machine, 3, ROM, mirr1 | 0x80, 0);
2362         break;
2363      case 0x11:
2364         set_nt_page(machine, 0, ROM, mirr0 | 0x80, 0);
2365         set_nt_page(machine, 1, ROM, mirr0 | 0x80, 0);
2366         set_nt_page(machine, 2, ROM, mirr1 | 0x80, 0);
2367         set_nt_page(machine, 3, ROM, mirr1 | 0x80, 0);
2368         break;
2369      case 0x12:
2370         set_nt_page(machine, 0, ROM, mirr0 | 0x80, 0);
2371         set_nt_page(machine, 1, ROM, mirr0 | 0x80, 0);
2372         set_nt_page(machine, 2, ROM, mirr0 | 0x80, 0);
2373         set_nt_page(machine, 3, ROM, mirr0 | 0x80, 0);
2374         break;
2375      case 0x13:
2376         set_nt_page(machine, 0, ROM, mirr1 | 0x80, 0);
2377         set_nt_page(machine, 1, ROM, mirr1 | 0x80, 0);
2378         set_nt_page(machine, 2, ROM, mirr1 | 0x80, 0);
2379         set_nt_page(machine, 3, ROM, mirr1 | 0x80, 0);
2380         break;
2381   }
2382}
2383
2384static WRITE8_HANDLER( ntbrom_w )
2385{
2386   nes_state *state = space->machine().driver_data<nes_state>();
2387
2388   LOG_MMC(("ntbrom_w, offset %04x, data: %02x\n", offset, data));
2389
2390   switch (offset & 0x7000)
2391   {
2392      case 0x0000:
2393         chr2_0(space->machine(), data, CHRROM);
2394         break;
2395      case 0x1000:
2396         chr2_2(space->machine(), data, CHRROM);
2397         break;
2398      case 0x2000:
2399         chr2_4(space->machine(), data, CHRROM);
2400         break;
2401      case 0x3000:
2402         chr2_6(space->machine(), data, CHRROM);
2403         break;
2404      case 0x4000:
2405         state->m_mmc_latch1 = data & 0x7f;
2406         ntbrom_mirror(space->machine(), state->m_mmc_reg[0], state->m_mmc_latch1, state->m_mmc_latch2);
2407         break;
2408      case 0x5000:
2409         state->m_mmc_latch2 = data & 0x7f;
2410         ntbrom_mirror(space->machine(), state->m_mmc_reg[0], state->m_mmc_latch1, state->m_mmc_latch2);
2411         break;
2412      case 0x6000:
2413         state->m_mmc_reg[0] = data & 0x13;
2414         ntbrom_mirror(space->machine(), state->m_mmc_reg[0], state->m_mmc_latch1, state->m_mmc_latch2);
2415         break;
2416      case 0x7000:
2417         prg16_89ab(space->machine(), data);
2418         break;
2419      default:
2420         LOG_MMC(("ntbrom_w uncaught write, offset: %04x, data: %02x\n", offset, data));
2421         break;
2422   }
2423}
2424
2425/*************************************************************
2426
2427 JxROM & Sunsoft 5A / 5B / FME7 board emulation
2428
2429 Notice that Sunsoft-5B = FME7 + sound chip (the latter being
2430 currently unemulated in MESS)
2431
2432 iNES: mapper 69
2433
2434 *************************************************************/
2435
2436/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
2437 we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
2438 there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
2439static void jxrom_irq( device_t *device, int scanline, int vblank, int blanked )
2440{
2441   nes_state *state = device->machine().driver_data<nes_state>();
2442
2443   /* TODO: change to reflect the actual number of cycles spent */
2444   if ((state->m_IRQ_enable & 0x80) && (state->m_IRQ_enable & 0x01))
2445   {
2446      if (state->m_IRQ_count <= 114)
2447      {
2448         state->m_IRQ_count = 0xffff;
2449         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
2450      }
2451      else
2452         state->m_IRQ_count -= 114;
2453   }
2454   else if (state->m_IRQ_enable & 0x01)   // if enable bit 7 is not set, only decrement the counter!
2455   {
2456      if (state->m_IRQ_count <= 114)
2457         state->m_IRQ_count = 0xffff;
2458      else
2459         state->m_IRQ_count -= 114;
2460   }
2461}
2462
2463static WRITE8_HANDLER( jxrom_w )
2464{
2465   nes_state *state = space->machine().driver_data<nes_state>();
2466   LOG_MMC(("jxrom_w, offset %04x, data: %02x\n", offset, data));
2467
2468   switch (offset & 0x6000)
2469   {
2470      case 0x0000:
2471         state->m_mmc_latch1 = data & 0x0f;
2472         break;
2473
2474      case 0x2000:
2475         switch (state->m_mmc_latch1)
2476         {
2477         case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
2478            chr1_x(space->machine(), state->m_mmc_latch1, data, CHRROM);
2479            break;
2480
2481         case 8:
2482            if (!(data & 0x40))
2483            {
2484               // is PRG ROM
2485               space->unmap_write(0x6000, 0x7fff);
2486               prg8_67(space->machine(), data & 0x3f);
2487            }
2488            else if (data & 0x80)
2489            {
2490               // is PRG RAM
2491               space->install_write_bank(0x6000, 0x7fff, "bank5");
2492               state->m_prg_bank[4] = state->m_battery_bank5_start + (data & 0x3f);
2493               memory_set_bank(space->machine(), "bank5", state->m_prg_bank[4]);
2494            }
2495            break;
2496
2497         case 9:
2498            prg8_89(space->machine(), data);
2499            break;
2500         case 0x0a:
2501            prg8_ab(space->machine(), data);
2502            break;
2503         case 0x0b:
2504            prg8_cd(space->machine(), data);
2505            break;
2506         case 0x0c:
2507            switch (data & 0x03)
2508            {
2509            case 0x00: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
2510            case 0x01: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
2511            case 0x02: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
2512            case 0x03: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
2513            }
2514            break;
2515         case 0x0d:
2516            state->m_IRQ_enable = data;
2517            break;
2518         case 0x0e:
2519            state->m_IRQ_count = (state->m_IRQ_count & 0xff00) | data;
2520            break;
2521         case 0x0f:
2522            state->m_IRQ_count = (state->m_IRQ_count & 0x00ff) | (data << 8);
2523            break;
2524         }
2525         break;
2526
2527         /* Here we would have sound command for Sunsoft 5b variant */
2528         //      case 0x4000:
2529         //      case 0x6000:
2530
2531      case 0x4000:
2532         LOG_MMC(("Sunsoft-5B Sound: Register select write, data: %02x\n", data));
2533         break;
2534      case 0x6000:
2535         LOG_MMC(("Sunsoft-5B Sound: Register write, data: %02x\n", data));
2536         break;
2537      default:
2538         logerror("jxrom_w uncaught %04x value: %02x\n", offset + 0x8000, data);
2539         break;
2540   }
2541}
2542
2543/*************************************************************
2544
2545 DxROM & Namcot 3433 - 3443 board emulation
2546
2547 Games: Dragon Spirit - Aratanaru Densetsu, Namcot Mahjong, Quinty
2548
2549 These are the same board, but DRROM (and Tengen 800004) have
2550 4-screen mirroring
2551
2552 iNES: mappers 88, 206 (same as 88 but possibly 4-screen mirroring)
2553
2554 *************************************************************/
2555
2556static WRITE8_HANDLER( dxrom_w )
2557{
2558   nes_state *state = space->machine().driver_data<nes_state>();
2559   LOG_MMC(("dxrom_w, offset: %04x, data: %02x\n", offset, data));
2560
2561    if (offset >= 0x2000)
2562      return;
2563
2564   switch (offset & 1)
2565   {
2566      case 1:
2567         switch (state->m_mmc_latch1 & 0x07)
2568         {
2569         case 0: chr2_0(space->machine(), data >> 1, CHRROM); break;
2570         case 1: chr2_2(space->machine(), data >> 1, CHRROM); break;
2571         case 2: chr1_4(space->machine(), data | 0x40, CHRROM); break;
2572         case 3: chr1_5(space->machine(), data | 0x40, CHRROM); break;
2573         case 4: chr1_6(space->machine(), data | 0x40, CHRROM); break;
2574         case 5: chr1_7(space->machine(), data | 0x40, CHRROM); break;
2575         case 6: prg8_89(space->machine(), data); break;
2576         case 7: prg8_ab(space->machine(), data); break;
2577         }
2578         break;
2579      case 0:
2580         state->m_mmc_latch1 = data;
2581         break;
2582   }
2583}
2584
2585
2586/*************************************************************
2587
2588 Namcot 3453 board emulation
2589
2590 Games: Devil Man
2591
2592 These are the same as Namcot 34x3, but with additional mirroring
2593 control
2594
2595 iNES: mapper 154
2596
2597 *************************************************************/
2598
2599static WRITE8_HANDLER( namcot3453_w )
2600{
2601   LOG_MMC(("namcot3453_w, offset: %04x, data: %02x\n", offset, data));
2602
2603   // additional mirroring control when writing to even addresses
2604   if (!(offset & 1))
2605      set_nt_mirroring(space->machine(), BIT(data, 6) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
2606
2607   dxrom_w(space, offset, data);
2608}
2609
2610/*************************************************************
2611
2612 Namcot 3446 board emulation
2613
2614 Games: Digital Devil Monogatari - Megami Tensei
2615
2616 These are similar Namcot 34x3, but different bankswitch capabilities
2617
2618 iNES: mapper 76
2619
2620 *************************************************************/
2621
2622static WRITE8_HANDLER( namcot3446_w )
2623{
2624   nes_state *state = space->machine().driver_data<nes_state>();
2625   LOG_MMC(("namcot3446_w, offset: %04x, data: %02x\n", offset, data));
2626
2627   // NEStopia does not have this!
2628   if (offset >= 0x2000)
2629   {
2630      if (!(offset & 1))
2631         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
2632      return;
2633   }
2634
2635   switch (offset & 1)
2636   {
2637      case 1:
2638         switch (state->m_mmc_latch1 & 0x07)
2639         {
2640         case 2: chr2_0(space->machine(), data, CHRROM); break;
2641         case 3: chr2_2(space->machine(), data, CHRROM); break;
2642         case 4: chr2_4(space->machine(), data, CHRROM); break;
2643         case 5: chr2_6(space->machine(), data, CHRROM); break;
2644         case 6: BIT(state->m_mmc_latch1, 6) ? prg8_cd(space->machine(), data) : prg8_89(space->machine(), data); break;
2645         case 7: prg8_ab(space->machine(), data); break;
2646         }
2647         break;
2648      case 0:
2649         state->m_mmc_latch1 = data;
2650         break;
2651   }
2652}
2653
2654/*************************************************************
2655
2656 Namcot 3425 board emulation
2657
2658 Games: Dragon Buster
2659
2660 These are similar Namcot 34x3, but with NT mirroring (two
2661 different modes)
2662
2663 iNES: mapper 95
2664
2665 *************************************************************/
2666
2667static WRITE8_HANDLER( namcot3425_w )
2668{
2669   nes_state *state = space->machine().driver_data<nes_state>();
2670   UINT8 mode;
2671   LOG_MMC(("namcot3425_w, offset: %04x, data: %02x\n", offset, data));
2672   if (offset >= 0x2000)
2673      return;
2674
2675   switch (offset & 1)
2676   {
2677      case 1:
2678         mode = state->m_mmc_latch1 & 0x07;
2679         switch (mode)
2680         {
2681         case 0: chr2_0(space->machine(), data >> 1, CHRROM); break;
2682         case 1: chr2_2(space->machine(), data >> 1, CHRROM); break;
2683         case 2:
2684         case 3:
2685         case 4:
2686         case 5:
2687            chr1_x(space->machine(), 2 + mode, data, CHRROM);
2688            state->m_mmc_reg[mode - 2] = BIT(data, 5);
2689            if (!BIT(state->m_mmc_latch1, 7))
2690            {
2691                  set_nt_page(space->machine(), 0, CIRAM, state->m_mmc_reg[0], 1);
2692                  set_nt_page(space->machine(), 1, CIRAM, state->m_mmc_reg[1], 1);
2693                  set_nt_page(space->machine(), 2, CIRAM, state->m_mmc_reg[2], 1);
2694                  set_nt_page(space->machine(), 3, CIRAM, state->m_mmc_reg[3], 1);
2695            }
2696            else
2697               set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ);
2698            break;
2699         case 6: prg8_89(space->machine(), data); break;
2700         case 7: prg8_ab(space->machine(), data); break;
2701         }
2702         break;
2703      case 0:
2704         state->m_mmc_latch1 = data;
2705         break;
2706   }
2707}
2708
2709/*************************************************************
2710
2711 Discrete Logic board IC 74x377 by Color Dreams / Nina-007 emulation
2712
2713 Games: many Color Dreams and Wisdom Tree titles
2714
2715 iNES: mapper 11
2716
2717 In MESS: Supported
2718
2719 *************************************************************/
2720
2721static WRITE8_HANDLER( dis_74x377_w )
2722{
2723   nes_state *state = space->machine().driver_data<nes_state>();
2724   LOG_MMC(("dis_74x377_w, offset: %04x, data: %02x\n", offset, data));
2725
2726   chr8(space->machine(), data >> 4, state->m_mmc_chr_source);
2727   prg32(space->machine(), data & 0x0f);
2728}
2729
2730/*************************************************************
2731
2732 Discrete Logic board IC 74x139x74 by Konami & Jaleco
2733
2734 iNES: mapper 87
2735
2736 *************************************************************/
2737
2738static WRITE8_HANDLER( dis_74x139x74_m_w )
2739{
2740   LOG_MMC(("dis_74x139x74_m_w, offset: %04x, data: %02x\n", offset, data));
2741
2742   chr8(space->machine(), ((data & 0x02) >> 1) | ((data & 0x01) << 1), CHRROM);
2743}
2744
2745/*************************************************************
2746
2747 Discrete Logic board IC 74x161x138
2748
2749 Games: Crime Busters
2750
2751 iNES: mapper 38
2752
2753 *************************************************************/
2754
2755static WRITE8_HANDLER( dis_74x161x138_m_w )
2756{
2757   LOG_MMC(("dis_74x161x138_m_w, offset: %04x, data: %02x\n", offset, data));
2758
2759   chr8(space->machine(), data >> 2, CHRROM);
2760   prg32(space->machine(), data);
2761}
2762
2763/*************************************************************
2764
2765 Discrete Logic board IC 74x161x161x32
2766
2767 There are two variants (one with hardwired mirroring, the
2768 other with a mirroring control), making necessary two distinct
2769 mappers & pcb_id
2770
2771 iNES: mappers 70 & 152
2772
2773 *************************************************************/
2774
2775static WRITE8_HANDLER( dis_74x161x161x32_w )
2776{
2777   nes_state *state = space->machine().driver_data<nes_state>();
2778   LOG_MMC(("dis_74x161x161x32_w, offset: %04x, data: %02x\n", offset, data));
2779
2780   if (!state->m_hard_mirroring)   // there are two 'variants' depending on hardwired or mapper ctrl mirroring
2781      set_nt_mirroring(space->machine(), BIT(data, 7) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
2782   chr8(space->machine(), data, CHRROM);
2783   prg16_89ab(space->machine(), data >> 4);
2784}
2785
2786/*************************************************************
2787
2788 Bandai LZ93D50 boards emulation
2789
2790 There are several variants: plain board with or without SRAM,
2791 board + 24C01 EEPROM, board + 24C02 EEPROM, board + Barcode
2792 Reader (DATACH).
2793 We currently only emulate the base hardware.
2794
2795 Games: Crayon Shin-Chan - Ora to Poi Poi, Dragon Ball Z Gaiden,
2796 Dragon Ball Z II & III, Rokudenashi Blues, SD Gundam
2797 Gaiden - KGM2, Dragon Ball Z, Magical Taruruuto-kun, SD Gundam
2798 Gaiden [with EEPROM], Dragon Ball, Dragon Ball 3, Famicom Jump,
2799 Famicom Jump II [no EEPROM], Datach Games
2800
2801 At the moment, we don't support EEPROM I/O
2802
2803 iNES: mappers 16, 153, 157 & 159
2804
2805 In MESS: Supported
2806
2807 *************************************************************/
2808
2809/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
2810 we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
2811 there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
2812static void bandai_lz_irq( device_t *device, int scanline, int vblank, int blanked )
2813{
2814   nes_state *state = device->machine().driver_data<nes_state>();
2815
2816   /* 114 is the number of cycles per scanline */
2817   /* TODO: change to reflect the actual number of cycles spent */
2818   if (state->m_IRQ_enable)
2819   {
2820      if (state->m_IRQ_count <= 114)
2821      {
2822         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
2823         state->m_IRQ_count = (0xffff - 114 + state->m_IRQ_count);   // wrap around the 16 bits counter
2824      }
2825      state->m_IRQ_count -= 114;
2826   }
2827}
2828
2829static WRITE8_HANDLER( lz93d50_w )
2830{
2831   nes_state *state = space->machine().driver_data<nes_state>();
2832   LOG_MMC(("lz93d50_w, offset: %04x, data: %02x\n", offset, data));
2833
2834   switch (offset & 0x000f)
2835   {
2836      case 0: case 1: case 2: case 3:
2837      case 4: case 5: case 6: case 7:
2838         chr1_x(space->machine(), offset & 0x07, data, state->m_mmc_chr_source);
2839         break;
2840      case 8:
2841         prg16_89ab(space->machine(), data);
2842         break;
2843      case 9:
2844         switch (data & 0x03)
2845         {
2846         case 0: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
2847         case 1: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
2848         case 2: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
2849         case 3: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
2850         }
2851         break;
2852      case 0x0a:
2853         state->m_IRQ_enable = data & 0x01;
2854         break;
2855      case 0x0b:
2856         state->m_IRQ_count = (state->m_IRQ_count & 0xff00) | data;
2857         break;
2858      case 0x0c:
2859         state->m_IRQ_count = (state->m_IRQ_count & 0x00ff) | (data << 8);
2860         break;
2861      default:
2862         logerror("lz93d50_w uncaught write, offset: %04x, data: %02x\n", offset, data);
2863         break;
2864   }
2865}
2866
2867static WRITE8_HANDLER( lz93d50_m_w )
2868{
2869   nes_state *state = space->machine().driver_data<nes_state>();
2870   LOG_MMC(("lz93d50_m_w, offset: %04x, data: %02x\n", offset, data));
2871
2872   if (!state->m_battery && !state->m_wram)
2873      lz93d50_w(space, offset & 0x0f, data);
2874   else if (state->m_battery)
2875      state->m_battery_ram[offset] = data;
2876   else
2877      state->m_wram[offset] = data;
2878}
2879
2880static void fjump2_set_prg( running_machine &machine )
2881{
2882   nes_state *state = machine.driver_data<nes_state>();
2883   UINT8 mmc_helper = 0;
2884   int i;
2885
2886   for (i = 0; i < 8; i++)
2887      mmc_helper |= ((state->m_mmc_reg[i] & 0x01) << 4);
2888
2889   prg16_89ab(machine, mmc_helper | state->m_mmc_latch1);
2890   prg16_cdef(machine, mmc_helper | 0x0f);
2891}
2892
2893static WRITE8_HANDLER( fjump2_w )
2894{
2895   nes_state *state = space->machine().driver_data<nes_state>();
2896   LOG_MMC(("fjump2_w, offset: %04x, data: %02x\n", offset, data));
2897
2898   switch (offset & 0x000f)
2899   {
2900      case 0: case 1: case 2: case 3:
2901      case 4: case 5: case 6: case 7:
2902         state->m_mmc_reg[offset & 0x000f] = data;
2903         fjump2_set_prg(space->machine());
2904         break;
2905      case 8:
2906         state->m_mmc_latch1 = (data & 0x0f);
2907         fjump2_set_prg(space->machine());
2908         break;
2909      default:
2910         lz93d50_m_w(space, offset & 0x0f, data);
2911         break;
2912   }
2913}
2914
2915/*************************************************************
2916
2917 Bandai Karaoke Studio board emulation
2918
2919 Games: Karaoke Studio
2920
2921 Note: we currently do not emulate the mic
2922
2923 iNES: mapper 188
2924
2925 *************************************************************/
2926
2927static WRITE8_HANDLER( bandai_ks_w )
2928{
2929   LOG_MMC(("bandai_ks_w, offset: %04x, data: %02x\n", offset, data));
2930
2931   prg16_89ab(space->machine(), data ^ 0x08);
2932}
2933
2934/*************************************************************
2935
2936 Bandai Oeka Kids board emulation
2937
2938 Games: Oeka Kids - Anpanman no Hiragana Daisuki, Oeka
2939 Kids - Anpanman to Oekaki Shiyou!!
2940
2941 iNES: mapper 96
2942
2943 In MESS: Preliminary Support.
2944
2945 *************************************************************/
2946
2947static WRITE8_HANDLER( bandai_ok_w )
2948{
2949   nes_state *state = space->machine().driver_data<nes_state>();
2950   UINT8 mmc_helper;
2951   LOG_MMC(("mapper96_w, offset: %04x, data: %02x\n", offset, data));
2952
2953   prg32(space->machine(), data);
2954
2955   state->m_mmc_latch1 = data;
2956   mmc_helper = (state->m_mmc_latch1 & 0x03) | (data & 0x04);
2957   chr4_0(space->machine(), mmc_helper, CHRRAM);
2958   chr4_4(space->machine(), 0x03 | (data & 0x04), CHRRAM);
2959}
2960
2961/*************************************************************
2962
2963 Irem LROG017 - Discrete board emulation (74*161/161/21/138)
2964
2965 Games: Napoleon Senki
2966
2967 iNES: mapper 77
2968
2969 *************************************************************/
2970
2971static WRITE8_HANDLER( lrog017_w )
2972{
2973   LOG_MMC(("lrog017_w, offset: %04x, data: %02x\n", offset, data));
2974
2975   prg32(space->machine(), data);
2976   chr2_0(space->machine(), (data >> 4), CHRROM);
2977}
2978
2979/*************************************************************
2980
2981 Irem Holy Diver board emulation
2982
2983 iNES: mapper 78 (shared with JF-16)
2984
2985 *************************************************************/
2986
2987static WRITE8_HANDLER( irem_hd_w )
2988{
2989   LOG_MMC(("irem_hd_w, offset: %04x, data: %02x\n", offset, data));
2990
2991   set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
2992   chr8(space->machine(), data >> 4, CHRROM);
2993   prg16_89ab(space->machine(), data);
2994}
2995
2996/*************************************************************
2997
2998 Irem TAM-S1 board emulation
2999
3000 Games: Kaiketsu Yanchamaru
3001
3002 iNES: mapper 97
3003
3004 In MESS: Supported.
3005
3006 *************************************************************/
3007
3008static WRITE8_HANDLER( tam_s1_w )
3009{
3010   LOG_MMC(("tam_s1_w, offset: %04x, data: %02x\n", offset, data));
3011
3012   if (offset < 0x4000)
3013   {
3014      set_nt_mirroring(space->machine(), BIT(data, 7) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
3015      prg16_cdef(space->machine(), data);
3016   }
3017}
3018
3019/*************************************************************
3020
3021 Irem G-101 board emulation
3022
3023 Major League uses hardwired mirroring
3024
3025 iNES: mapper 32
3026
3027 *************************************************************/
3028
3029static WRITE8_HANDLER( g101_w )
3030{
3031   nes_state *state = space->machine().driver_data<nes_state>();
3032   LOG_MMC(("g101_w, offset: %04x, data: %02x\n", offset, data));
3033
3034   switch (offset & 0x7000)
3035   {
3036      case 0x0000:
3037         // NEStopia here differs a little bit
3038         state->m_mmc_latch1 ? prg8_cd(space->machine(), data) : prg8_89(space->machine(), data);
3039         break;
3040      case 0x1000:
3041         state->m_mmc_latch1 = BIT(data, 1);
3042         if (!state->m_hard_mirroring)   // there are two 'variants' depending on hardwired or mapper ctrl mirroring
3043            set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3044         break;
3045      case 0x2000:
3046         prg8_ab(space->machine(), data);
3047         break;
3048      case 0x3000:
3049         chr1_x(space->machine(), offset & 0x07, data, CHRROM);
3050         break;
3051   }
3052}
3053
3054/*************************************************************
3055
3056 Irem H-3001 board emulation
3057
3058 Games: Daiku no Gen San 2 - Akage no Dan no Gyakushuu,
3059 Kaiketsu Yanchamaru 3, Spartan X 2
3060
3061 iNES: mapper 65
3062
3063 In MESS: Supported.
3064
3065 *************************************************************/
3066
3067/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
3068 we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
3069 there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
3070static void h3001_irq( device_t *device, int scanline, int vblank, int blanked )
3071{
3072   nes_state *state = device->machine().driver_data<nes_state>();
3073   if (state->m_IRQ_enable)
3074   {
3075      state->m_IRQ_count -= 114;
3076
3077      if (state->m_IRQ_count <= 114)
3078      {
3079         state->m_IRQ_enable = 0;
3080         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
3081      }
3082   }
3083}
3084
3085static WRITE8_HANDLER( h3001_w )
3086{
3087   nes_state *state = space->machine().driver_data<nes_state>();
3088   LOG_MMC(("h3001_w, offset %04x, data: %02x\n", offset, data));
3089
3090   switch (offset & 0x7fff)
3091   {
3092      case 0x0000:
3093         prg8_89(space->machine(), data);
3094         break;
3095
3096      case 0x1001:
3097         set_nt_mirroring(space->machine(), BIT(data, 7) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3098         break;
3099
3100      case 0x1003:
3101         state->m_IRQ_enable = data & 0x80;
3102         break;
3103
3104      case 0x1004:
3105         state->m_IRQ_count = state->m_IRQ_count_latch;
3106         break;
3107
3108      case 0x1005:
3109         state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0x00ff) | (data << 8);
3110         break;
3111
3112      case 0x1006:
3113         state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0xff00) | data;
3114         break;
3115
3116      case 0x2000:
3117         prg8_ab(space->machine(), data);
3118         break;
3119
3120      case 0x3000: case 0x3001: case 0x3002: case 0x3003:
3121      case 0x3004: case 0x3005: case 0x3006: case 0x3007:
3122         chr1_x(space->machine(), offset & 0x07, data, CHRROM);
3123         break;
3124
3125      case 0x4000:
3126         prg8_cd(space->machine(), data);
3127         break;
3128
3129      default:
3130         break;
3131   }
3132}
3133
3134/*************************************************************
3135
3136 Jaleco SS88006 board emulation, aka JF-27, JF-29, JF-30, ...,
3137 JF-38, JF-40, JF-41
3138
3139 Games: Lord of King, Magic John, Moe Pro '90, Ninja Jajamaru,
3140 Pizza Pop, Plasma Ball
3141
3142 iNES: mapper 18
3143
3144 In MESS: Supported
3145
3146 *************************************************************/
3147
3148/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
3149 we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
3150 there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
3151static void ss88006_irq( device_t *device, int scanline, int vblank, int blanked )
3152{
3153   nes_state *state = device->machine().driver_data<nes_state>();
3154
3155   /* Increment & check the IRQ scanline counter */
3156   if (state->m_IRQ_enable)
3157   {
3158      LOG_MMC(("scanline: %d, irq count: %04x\n", scanline, state->m_IRQ_count));
3159      if (state->m_IRQ_mode & 0x08)
3160      {
3161         if ((state->m_IRQ_count & 0x000f) < 114)   // always true, but we only update the IRQ once per scanlines so we cannot be more precise :(
3162         {
3163            device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
3164            state->m_IRQ_count = (state->m_IRQ_count & ~0x000f) | (0x0f - (114 & 0x0f) + (state->m_IRQ_count & 0x000f)); // sort of wrap around the counter
3165         }
3166         // decrements should not affect upper bits, so we don't do anything here (114 > 0x0f)
3167      }
3168      else if (state->m_IRQ_mode & 0x04)
3169      {
3170         if ((state->m_IRQ_count & 0x00ff) < 114)
3171         {
3172            device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
3173            state->m_IRQ_count = (state->m_IRQ_count & ~0x00ff) | (0xff - 114 + (state->m_IRQ_count & 0x00ff));   // wrap around the 8 bits counter
3174         }
3175         else
3176            state->m_IRQ_count -= 114;
3177      }
3178      else if (state->m_IRQ_mode & 0x02)
3179      {
3180         if ((state->m_IRQ_count & 0x0fff)  < 114)
3181         {
3182            device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
3183            state->m_IRQ_count = (state->m_IRQ_count & ~0x0fff) | (0xfff - 114 + (state->m_IRQ_count & 0x0fff));   // wrap around the 12 bits counter
3184         }
3185         else
3186            state->m_IRQ_count -= 114;
3187      }
3188      else if (state->m_IRQ_count < 114)
3189      {
3190         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
3191         state->m_IRQ_count = (0xffff - 114 + state->m_IRQ_count);   // wrap around the 16 bits counter
3192      }
3193      else
3194         state->m_IRQ_count -= 114;
3195   }
3196}
3197
3198static WRITE8_HANDLER( ss88006_w )
3199{
3200   nes_state *state = space->machine().driver_data<nes_state>();
3201   UINT8 bank;
3202   LOG_MMC(("mapper18_w, offset: %04x, data: %02x\n", offset, data));
3203
3204   switch (offset & 0x7003)
3205   {
3206      case 0x0000:
3207         state->m_mmc_prg_bank[0] = (state->m_mmc_prg_bank[0] & 0xf0) | (data & 0x0f);
3208         prg8_89(space->machine(), state->m_mmc_prg_bank[0]);
3209         break;
3210      case 0x0001:
3211         state->m_mmc_prg_bank[0] = (state->m_mmc_prg_bank[0] & 0x0f) | (data << 4);
3212         prg8_89(space->machine(), state->m_mmc_prg_bank[0]);
3213         break;
3214      case 0x0002:
3215         state->m_mmc_prg_bank[1] = (state->m_mmc_prg_bank[1] & 0xf0) | (data & 0x0f);
3216         prg8_ab(space->machine(), state->m_mmc_prg_bank[1]);
3217         break;
3218      case 0x0003:
3219         state->m_mmc_prg_bank[1] = (state->m_mmc_prg_bank[1] & 0x0f) | (data << 4);
3220         prg8_ab(space->machine(), state->m_mmc_prg_bank[1]);
3221         break;
3222      case 0x1000:
3223         state->m_mmc_prg_bank[2] = (state->m_mmc_prg_bank[2] & 0xf0) | (data & 0x0f);
3224         prg8_cd(space->machine(), state->m_mmc_prg_bank[2]);
3225         break;
3226      case 0x1001:
3227         state->m_mmc_prg_bank[2] = (state->m_mmc_prg_bank[2] & 0x0f) | (data << 4);
3228         prg8_cd(space->machine(), state->m_mmc_prg_bank[2]);
3229         break;
3230
3231         /* $9002, 3 (1002, 3) uncaught = Jaleco Baseball writes 0 */
3232         /* believe it's related to battery-backed ram enable/disable */
3233
3234      case 0x2000: case 0x2001: case 0x2002: case 0x2003:
3235      case 0x3000: case 0x3001: case 0x3002: case 0x3003:
3236      case 0x4000: case 0x4001: case 0x4002: case 0x4003:
3237      case 0x5000: case 0x5001: case 0x5002: case 0x5003:
3238         bank = ((offset & 0x7000) - 0x2000) / 0x0800 + ((offset & 0x0002) >> 1);
3239         if (offset & 0x0001)
3240            state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0x0f) | ((data & 0x0f)<< 4);
3241         else
3242            state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0xf0) | (data & 0x0f);
3243
3244         chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], CHRROM);
3245         break;
3246
3247      case 0x6000:
3248         state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0xfff0) | (data & 0x0f);
3249         break;
3250      case 0x6001:
3251         state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0xff0f) | ((data & 0x0f) << 4);
3252         break;
3253      case 0x6002:
3254         state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0xf0ff) | ((data & 0x0f) << 8);
3255         break;
3256      case 0x6003:
3257         state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0x0fff) | ((data & 0x0f) << 12);
3258         break;
3259
3260      case 0x7000:
3261         state->m_IRQ_count = state->m_IRQ_count_latch;
3262         break;
3263      case 0x7001:
3264         state->m_IRQ_enable = data & 0x01;
3265         state->m_IRQ_mode = data & 0x0e;
3266         break;
3267
3268      case 0x7002:
3269         switch (data & 0x03)
3270         {
3271         case 0: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
3272         case 1: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
3273         case 2: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
3274         case 3: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
3275         }
3276         break;
3277
3278      default:
3279         logerror("Jaleco SS88006 uncaught write, addr: %04x, value: %02x\n", offset + 0x8000, data);
3280         break;
3281   }
3282}
3283
3284/*************************************************************
3285
3286 Jaleco JF-11, JF-12 & JF-14 boards emulation
3287
3288 Games: Bio Senshi Dan, Mississippi Satsujin Jiken
3289
3290 iNES: mapper 140
3291
3292 In MESS: Supported.
3293
3294 *************************************************************/
3295
3296static WRITE8_HANDLER( jf11_m_w )
3297{
3298   LOG_MMC(("jf11_m_w, offset: %04x, data: %02x\n", offset, data));
3299   chr8(space->machine(), data, CHRROM);
3300   prg32(space->machine(), data >> 4);
3301}
3302
3303/*************************************************************
3304
3305 Jaleco JF-13 board emulation
3306
3307 Games: Moero Pro Yakyuu
3308
3309 Note: we don't emulate the additional sound hardware.
3310
3311 iNES: mapper 86
3312
3313 In MESS: Supported.
3314
3315 *************************************************************/
3316
3317static WRITE8_HANDLER( jf13_m_w )
3318{
3319   LOG_MMC(("jf13_m_w, offset: %04x, data: %02x\n", offset, data));
3320
3321   if (offset == 0)
3322   {
3323      prg32(space->machine(), (data >> 4) & 0x03);
3324      chr8(space->machine(), ((data >> 4) & 0x04) | (data & 0x03), CHRROM);
3325   }
3326
3327   if (offset == 0x1000)
3328   {
3329      LOG_MMC(("Jaleco JF-13 sound write, data: %02x\n", data));
3330      // according to NEStopia, this is the effect
3331      if ((data & 0x30) == 0x20)
3332      {
3333         // send command (data & 0x1f) to sound chip
3334      }
3335   }
3336}
3337
3338/*************************************************************
3339
3340 Jaleco JF-16 board emulation
3341
3342 iNES: mapper 78 (shared with a diff Irem board)
3343
3344 *************************************************************/
3345
3346static WRITE8_HANDLER( jf16_w )
3347{
3348   LOG_MMC(("jf16_w, offset: %04x, data: %02x\n", offset, data));
3349
3350   set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
3351   chr8(space->machine(), data >> 4, CHRROM);
3352   prg16_89ab(space->machine(), data);
3353}
3354
3355/*************************************************************
3356
3357 Jaleco JF-17, JF-26 & JF-28 boards emulation
3358
3359 Note: we don't emulate the additional sound hardware.
3360
3361 Games: Moero!! Juudou Warriors, Moero!! Pro Tennis, Pinball
3362 Quest Jpn
3363
3364 iNES: mapper 72
3365
3366 In MESS: Supported.
3367
3368 *************************************************************/
3369
3370static WRITE8_HANDLER( jf17_w )
3371{
3372   LOG_MMC(("jf17_w, offset: %04x, data: %02x\n", offset, data));
3373
3374   if (BIT(data, 7))
3375      prg16_89ab(space->machine(), data & 0x0f);
3376   if (BIT(data, 6))
3377      chr8(space->machine(), data & 0x0f, CHRROM);
3378   if (BIT(data, 5) && !BIT(data,4))
3379      LOG_MMC(("Jaleco JF-17 sound write, data: %02x\n", data & 0x1f));
3380}
3381
3382/*************************************************************
3383
3384 Jaleco JF-19 & JF-21 boards emulation
3385
3386 Note: we don't emulate the additional sound hardware.
3387
3388 Games: Moero Pro Soccer, Moero Pro Yakyuu '88
3389
3390 iNES: mapper 92
3391
3392 In MESS: Supported (no samples).
3393
3394 *************************************************************/
3395
3396static WRITE8_HANDLER( jf19_w )
3397{
3398   LOG_MMC(("jf19_w, offset: %04x, data: %02x\n", offset, data));
3399
3400   if (BIT(data, 7))
3401      prg16_cdef(space->machine(), data & 0x0f);
3402   if (BIT(data, 6))
3403      chr8(space->machine(), data & 0x0f, CHRROM);
3404   if (BIT(data, 5) && !BIT(data,4))
3405      LOG_MMC(("Jaleco JF-19 sound write, data: %02x\n", data & 0x1f));
3406}
3407
3408/*************************************************************
3409
3410 Konami VRC1 and Jaleco JF20, JF22
3411
3412 Games: Exciting Boxing, Ganbare Goemon!, Tetsuwan Atom
3413
3414 iNES: mapper 75
3415
3416 In MESS: Supported.
3417
3418 *************************************************************/
3419
3420static WRITE8_HANDLER( konami_vrc1_w )
3421{
3422   nes_state *state = space->machine().driver_data<nes_state>();
3423   LOG_MMC(("konami_vrc1_w, offset: %04x, data: %02x\n", offset, data));
3424
3425   switch (offset & 0x7000)
3426   {
3427      case 0x0000:
3428         prg8_89(space->machine(), data);
3429         break;
3430      case 0x1000:
3431         set_nt_mirroring(space->machine(), (data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3432         state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & 0x0f) | ((data & 0x02) << 3);
3433         state->m_mmc_vrom_bank[1] = (state->m_mmc_vrom_bank[1] & 0x0f) | ((data & 0x04) << 2);
3434         chr4_0(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
3435         chr4_4(space->machine(), state->m_mmc_vrom_bank[1], CHRROM);
3436         break;
3437      case 0x2000:
3438         prg8_ab(space->machine(), data);
3439         break;
3440      case 0x4000:
3441         prg8_cd(space->machine(), data);
3442         break;
3443      case 0x6000:
3444         state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & 0x10) | (data & 0x0f);
3445         chr4_0(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
3446         break;
3447      case 0x7000:
3448         state->m_mmc_vrom_bank[1] = (state->m_mmc_vrom_bank[1] & 0x10) | (data & 0x0f);
3449         chr4_4(space->machine(), state->m_mmc_vrom_bank[1], CHRROM);
3450         break;
3451   }
3452}
3453
3454/*************************************************************
3455
3456 Konami VRC-2
3457
3458 In MESS: Supported.
3459
3460 *************************************************************/
3461
3462static WRITE8_HANDLER( konami_vrc2_w )
3463{
3464   nes_state *state = space->machine().driver_data<nes_state>();
3465   UINT8 bank, shift, mask;
3466   UINT32 shifted_offs = (offset & 0x7000)
3467                  | ((offset << (9 - state->m_vrc_ls_prg_a)) & 0x200)
3468                  | ((offset << (8 - state->m_vrc_ls_prg_b)) & 0x100);
3469   LOG_MMC(("konami_vrc2_w, offset: %04x, data: %02x\n", offset, data));
3470
3471   if (offset < 0x1000)
3472      prg8_89(space->machine(), data);
3473   else if (offset < 0x2000)
3474   {
3475      switch (data & 0x03)
3476      {
3477         case 0x00: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
3478         case 0x01: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
3479         case 0x02: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
3480         case 0x03: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
3481      }
3482   }
3483   else if (offset < 0x3000)
3484      prg8_ab(space->machine(), data);
3485   else if (offset < 0x7000)
3486   {
3487      bank = ((shifted_offs & 0x7000) - 0x3000) / 0x0800 + BIT(shifted_offs, 9);
3488      shift = BIT(shifted_offs, 8) * 4;
3489      mask = (0xf0 >> shift);
3490      state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & mask)
3491                           | (((data >> state->m_vrc_ls_chr) & 0x0f) << shift);
3492      chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], CHRROM);
3493   }
3494   else
3495      logerror("konami_vrc2_w uncaught write, addr: %04x value: %02x\n", offset + 0x8000, data);
3496}
3497
3498/*************************************************************
3499
3500 Konami VRC3
3501
3502 Games: Salamander
3503
3504 iNES: mapper 73
3505
3506 In MESS: Supported. It also uses konami_irq.
3507
3508 *************************************************************/
3509
3510static WRITE8_HANDLER( konami_vrc3_w )
3511{
3512   LOG_MMC(("konami_vrc3_w, offset: %04x, data: %02x\n", offset, data));
3513   nes_state *state = space->machine().driver_data<nes_state>();
3514
3515   switch (offset & 0x7000)
3516   {
3517      case 0x0000:
3518      case 0x1000:
3519         /* dunno which address controls these */
3520         state->m_IRQ_count_latch = data;
3521         state->m_IRQ_enable_latch = data;
3522         break;
3523      case 0x2000:
3524         state->m_IRQ_enable = data;
3525         break;
3526      case 0x3000:
3527         state->m_IRQ_count &= ~0x0f;
3528         state->m_IRQ_count |= data & 0x0f;
3529         break;
3530      case 0x4000:
3531         state->m_IRQ_count &= ~0xf0;
3532         state->m_IRQ_count |= (data & 0x0f) << 4;
3533         break;
3534      case 0x7000:
3535         prg16_89ab(space->machine(), data);
3536         break;
3537      default:
3538         logerror("konami_vrc3_w uncaught write, offset %04x, data: %02x\n", offset, data);
3539         break;
3540   }
3541}
3542
3543/*************************************************************
3544
3545 Konami VRC-4
3546
3547 In MESS: Supported
3548
3549 *************************************************************/
3550
3551static void vrc4_set_prg( running_machine &machine )
3552{
3553   nes_state *state = machine.driver_data<nes_state>();
3554   if (state->m_mmc_latch1 & 0x02)
3555   {
3556      prg8_89(machine, 0xfe);
3557      prg8_cd(machine, state->m_mmc_prg_bank[0]);
3558   }
3559   else
3560   {
3561      prg8_89(machine, state->m_mmc_prg_bank[0]);
3562      prg8_cd(machine, 0xfe);
3563   }
3564}
3565
3566static void konami_irq( device_t *device, int scanline, int vblank, int blanked )
3567{
3568   nes_state *state = device->machine().driver_data<nes_state>();
3569   /* Increment & check the IRQ scanline counter */
3570   if (state->m_IRQ_enable && (++state->m_IRQ_count == 0x100))
3571   {
3572      state->m_IRQ_count = state->m_IRQ_count_latch;
3573      state->m_IRQ_enable = state->m_IRQ_enable_latch;
3574      device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
3575   }
3576}
3577
3578static WRITE8_HANDLER( konami_vrc4_w )
3579{
3580   nes_state *state = space->machine().driver_data<nes_state>();
3581   UINT8 bank, shift, mask;
3582   UINT32 shifted_offs = (offset & 0x7000)
3583                  | ((offset << (9 - state->m_vrc_ls_prg_a)) & 0x200)
3584                  | ((offset << (8 - state->m_vrc_ls_prg_b)) & 0x100);
3585   LOG_MMC(("konami_vrc4_w, offset: %04x, data: %02x\n", offset, data));
3586
3587   if (offset < 0x1000)
3588   {
3589      state->m_mmc_prg_bank[0] = data;
3590      vrc4_set_prg(space->machine());
3591   }
3592   else if (offset >= 0x2000 && offset < 0x3000)
3593      prg8_ab(space->machine(), data);
3594   else
3595   {
3596      switch (shifted_offs & 0x7300)
3597      {
3598         case 0x1000:
3599         case 0x1100:
3600            switch (data & 0x03)
3601            {
3602            case 0x00: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
3603            case 0x01: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
3604            case 0x02: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
3605            case 0x03: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
3606            }
3607            break;
3608         case 0x1200:
3609         case 0x1300:
3610            state->m_mmc_latch1 = data & 0x02;
3611            vrc4_set_prg(space->machine());
3612            break;
3613         case 0x3000:
3614         case 0x3100:
3615         case 0x3200:
3616         case 0x3300:
3617         case 0x4000:
3618         case 0x4100:
3619         case 0x4200:
3620         case 0x4300:
3621         case 0x5000:
3622         case 0x5100:
3623         case 0x5200:
3624         case 0x5300:
3625         case 0x6000:
3626         case 0x6100:
3627         case 0x6200:
3628         case 0x6300:
3629            bank = ((shifted_offs & 0x7000) - 0x3000) / 0x0800 + BIT(shifted_offs, 9);
3630            shift = BIT(shifted_offs, 8) * 4;
3631            mask = (0xf0 >> shift);
3632            state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & mask) | ((data & 0x0f) << shift);
3633            chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], CHRROM);
3634            break;
3635         case 0x7000:
3636            state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0xf0) | (data & 0x0f);
3637            break;
3638         case 0x7100:
3639            state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0x0f) | ((data & 0x0f) << 4);
3640            break;
3641         case 0x7200:
3642            state->m_IRQ_mode = data & 0x04;   // currently not implemented: 0 = prescaler mode / 1 = CPU mode
3643            state->m_IRQ_enable = data & 0x02;
3644            state->m_IRQ_enable_latch = data & 0x01;
3645            if (data & 0x02)
3646               state->m_IRQ_count = state->m_IRQ_count_latch;
3647            break;
3648         case 0x7300:
3649            state->m_IRQ_enable = state->m_IRQ_enable_latch;
3650            break;
3651         default:
3652            logerror("konami_vrc4_w uncaught write, addr: %04x value: %02x\n", shifted_offs + 0x8000, data);
3653            break;
3654      }
3655   }
3656}
3657
3658/*************************************************************
3659
3660 Konami VRC-6
3661
3662 In MESS: Supported. It also uses konami_irq (there are IRQ
3663 issues though: see Akumajou Densetsu intro).
3664
3665 *************************************************************/
3666
3667static WRITE8_HANDLER( konami_vrc6_w )
3668{
3669   nes_state *state = space->machine().driver_data<nes_state>();
3670   UINT8 bank;
3671   UINT32 shifted_offs = (offset & 0x7000)
3672                  | ((offset << (9 - state->m_vrc_ls_prg_a)) & 0x200)
3673                  | ((offset << (8 - state->m_vrc_ls_prg_b)) & 0x100);
3674   LOG_MMC(("konami_vrc6_w, offset: %04x, data: %02x\n", offset, data));
3675
3676   if (offset < 0x1000)
3677      prg16_89ab(space->machine(), data);
3678   else if (offset >= 0x4000 && offset < 0x5000)
3679      prg8_cd(space->machine(), data);
3680   else
3681   {
3682      switch (shifted_offs & 0x7300)
3683      {
3684         case 0x1000:
3685         case 0x1100:
3686         case 0x1200:
3687         case 0x2000:
3688         case 0x2100:
3689         case 0x2200:
3690         case 0x3000:
3691         case 0x3100:
3692         case 0x3200:
3693            LOG_MMC(("Konami VRC-6 Sound write, offset: %04x, data: %02x\n", shifted_offs & 0x7300, data));
3694            break;
3695         case 0x3300:
3696            switch (data & 0x0c)
3697            {
3698            case 0x00: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
3699            case 0x04: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
3700            case 0x08: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
3701            case 0x0c: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
3702            }
3703            break;
3704         case 0x5000:
3705         case 0x5100:
3706         case 0x5200:
3707         case 0x5300:
3708         case 0x6000:
3709         case 0x6100:
3710         case 0x6200:
3711         case 0x6300:
3712            bank = ((shifted_offs & 0x7000) - 0x5000) / 0x0400 + ((shifted_offs & 0x0300) >> 8);
3713            chr1_x(space->machine(), bank, data, CHRROM);
3714            break;
3715         case 0x7000:
3716            state->m_IRQ_count_latch = data;
3717            break;
3718         case 0x7100:
3719            state->m_IRQ_mode = data & 0x04;   // currently not implemented: 0 = prescaler mode / 1 = CPU mode
3720            state->m_IRQ_enable = data & 0x02;
3721            state->m_IRQ_enable_latch = data & 0x01;
3722            if (data & 0x02)
3723               state->m_IRQ_count = state->m_IRQ_count_latch;
3724            break;
3725         case 0x7200:
3726            state->m_IRQ_enable = state->m_IRQ_enable_latch;
3727            break;
3728         default:
3729            logerror("konami_vrc6_w uncaught write, addr: %04x value: %02x\n", shifted_offs + 0x8000, data);
3730            break;
3731      }
3732   }
3733}
3734
3735/*************************************************************
3736
3737 Konami VRC7
3738
3739 Games: Lagrange Point, Tiny Toon Adventures 2
3740
3741 iNES: mapper 85
3742
3743 In MESS: Supported. It also uses konami_irq.
3744
3745 *************************************************************/
3746
3747static WRITE8_HANDLER( konami_vrc7_w )
3748{
3749   nes_state *state = space->machine().driver_data<nes_state>();
3750   UINT8 bank;
3751   LOG_MMC(("konami_vrc7_w, offset: %04x, data: %02x\n", offset, data));
3752
3753   switch (offset & 0x7018)
3754   {
3755      case 0x0000:
3756         prg8_89(space->machine(), data);
3757         break;
3758      case 0x0008:
3759      case 0x0010:
3760      case 0x0018:
3761         prg8_ab(space->machine(), data);
3762         break;
3763
3764      case 0x1000:
3765         prg8_cd(space->machine(), data);
3766         break;
3767
3768         /* TODO: there are sound regs in here */
3769
3770      case 0x2000:
3771      case 0x2008:
3772      case 0x2010:
3773      case 0x2018:
3774      case 0x3000:
3775      case 0x3008:
3776      case 0x3010:
3777      case 0x3018:
3778      case 0x4000:
3779      case 0x4008:
3780      case 0x4010:
3781      case 0x4018:
3782      case 0x5000:
3783      case 0x5008:
3784      case 0x5010:
3785      case 0x5018:
3786         bank = ((offset & 0x7000) - 0x2000) / 0x0800 + ((offset & 0x0018) ? 1 : 0);
3787         chr1_x(space->machine(), bank, data, state->m_mmc_chr_source);
3788         break;
3789
3790      case 0x6000:
3791         switch (data & 0x03)
3792         {
3793         case 0x00: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
3794         case 0x01: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
3795         case 0x02: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
3796         case 0x03: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
3797         }
3798         break;
3799      case 0x6008: case 0x6010: case 0x6018:
3800         state->m_IRQ_count_latch = data;
3801         break;
3802      case 0x7000:
3803         state->m_IRQ_mode = data & 0x04;   // currently not implemented: 0 = prescaler mode / 1 = CPU mode
3804         state->m_IRQ_enable = data & 0x02;
3805         state->m_IRQ_enable_latch = data & 0x01;
3806         if (data & 0x02)
3807            state->m_IRQ_count = state->m_IRQ_count_latch;
3808         break;
3809      case 0x7008: case 0x7010: case 0x7018:
3810         state->m_IRQ_enable = state->m_IRQ_enable_latch;
3811         break;
3812
3813      default:
3814         logerror("konami_vrc7_w uncaught write, addr: %04x value: %02x\n", offset + 0x8000, data);
3815         break;
3816   }
3817}
3818
3819/*************************************************************
3820
3821 Namcot-163 board emulation
3822
3823 Games: Battle Fleet, Family Circuit '91, Famista '90, '91,
3824 '92 & '94, Megami Tensei II, Top Striker, Wagyan Land 2 & 3
3825
3826 iNES: mapper 19
3827
3828 In MESS: Supported
3829
3830 *************************************************************/
3831
3832/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
3833 we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
3834 there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
3835static void namcot_irq( device_t *device, int scanline, int vblank, int blanked )
3836{
3837   nes_state *state = device->machine().driver_data<nes_state>();
3838
3839   if (state->m_IRQ_enable)
3840   {
3841      if (state->m_IRQ_count >= (0x7fff - 114))
3842      {
3843         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
3844         state->m_IRQ_count = 0;
3845      }
3846      else
3847         state->m_IRQ_count += 114;
3848   }
3849}
3850
3851static WRITE8_HANDLER( namcot163_l_w )
3852{
3853   nes_state *state = space->machine().driver_data<nes_state>();
3854   LOG_MMC(("namcot163_l_w, offset: %04x, data: %02x\n", offset, data));
3855   offset += 0x100;
3856
3857   switch (offset & 0x1800)
3858   {
3859      case 0x0800:
3860         LOG_MMC(("Namcot-163 sound reg write, data: %02x\n", data));
3861         break;
3862      case 0x1000: /* low byte of IRQ */
3863         state->m_IRQ_count = (state->m_IRQ_count & 0x7f00) | data;
3864         break;
3865      case 0x1800: /* high byte of IRQ, IRQ enable in high bit */
3866         state->m_IRQ_count = (state->m_IRQ_count & 0xff) | ((data & 0x7f) << 8);
3867         state->m_IRQ_enable = data & 0x80;
3868         break;
3869   }
3870}
3871
3872static READ8_HANDLER( namcot163_l_r )
3873{
3874   nes_state *state = space->machine().driver_data<nes_state>();
3875   LOG_MMC(("namcot163_l_r, offset: %04x\n", offset));
3876   offset += 0x100;
3877
3878   switch (offset & 0x1800)
3879   {
3880      case 0x1000:
3881         return state->m_IRQ_count & 0xff;
3882      case 0x1800:
3883         return (state->m_IRQ_count >> 8) & 0xff;
3884      case 0x0800:
3885         LOG_MMC(("Namcot-163 sound reg read\n"));
3886      default:
3887         return 0x00;
3888   }
3889}
3890
3891static void namcot163_set_mirror( running_machine &machine, UINT8 page, UINT8 data )
3892{
3893   if (!(data < 0xe0))
3894      set_nt_page(machine, page, CIRAM, data & 0x01, 1);
3895   else
3896      set_nt_page(machine, page, ROM, data, 0);
3897}
3898
3899static WRITE8_HANDLER( namcot163_w )
3900{
3901   nes_state *state = space->machine().driver_data<nes_state>();
3902   LOG_MMC(("namcot163_w, offset: %04x, data: %02x\n", offset, data));
3903   switch (offset & 0x7800)
3904   {
3905      case 0x0000: case 0x0800:
3906      case 0x1000: case 0x1800:
3907      case 0x2000: case 0x2800:
3908      case 0x3000: case 0x3800:
3909         chr1_x(space->machine(), offset / 0x800, data, CHRROM);
3910         break;
3911      case 0x4000:
3912         namcot163_set_mirror(space->machine(), 0, data);
3913         break;
3914      case 0x4800:
3915         namcot163_set_mirror(space->machine(), 1, data);
3916         break;
3917      case 0x5000:
3918         namcot163_set_mirror(space->machine(), 2, data);
3919         break;
3920      case 0x5800:
3921         namcot163_set_mirror(space->machine(), 3, data);
3922         break;
3923      case 0x6000:
3924         prg8_89(space->machine(), data & 0x3f);
3925         break;
3926      case 0x6800:
3927         state->m_mmc_latch1 = data & 0xc0;      // this should enable High CHRRAM, but we still have to properly implement it!
3928         prg8_ab(space->machine(), data & 0x3f);
3929         break;
3930      case 0x7000:
3931         prg8_cd(space->machine(), data & 0x3f);
3932         break;
3933      case 0x7800:
3934         LOG_MMC(("Namcot-163 sound address write, data: %02x\n", data));
3935         break;
3936   }
3937}
3938
3939/*************************************************************
3940
3941 Sunsoft-1 board emulation
3942
3943 Games: Atlantis no Nazo, Kanshakudama Nage Kantarou no
3944 Toukaidou Gojuusan Tsugi, Wing of Madoola, Fantasy Zone
3945
3946 iNES: mapper 184 (Fantasy Zone uses this board with no
3947 CHRROM, and the register switches PRG banks)
3948
3949 *************************************************************/
3950
3951static WRITE8_HANDLER( sunsoft1_m_w )
3952{
3953   nes_state *state = space->machine().driver_data<nes_state>();
3954   LOG_MMC(("sunsoft1_m_w, offset: %04x, data: %02x\n", offset, data));
3955
3956   if (state->m_chr_chunks)
3957   {
3958      chr4_0(space->machine(), data & 0x0f, CHRROM);
3959      chr4_4(space->machine(), data >> 4, CHRROM);
3960   }
3961   else
3962      prg16_89ab(space->machine(), data & 0x0f);
3963}
3964
3965/*************************************************************
3966
3967 Sunsoft-2 board emulation
3968
3969 The two games using this board have incompatible mirroring
3970 wiring, making necessary two distinct mappers & pcb_id
3971
3972 iNES: mapper 89 & 93
3973
3974 *************************************************************/
3975
3976static WRITE8_HANDLER( sunsoft2_w )
3977{
3978   nes_state *state = space->machine().driver_data<nes_state>();
3979   UINT8 sunsoft_helper = (data & 0x07) | ((data & 0x80) ? 0x08 : 0x00);
3980   LOG_MMC(("sunsoft2_w, offset: %04x, data: %02x\n", offset, data));
3981
3982   if (!state->m_hard_mirroring)   // there are two 'variants' depending on hardwired or mapper ctrl mirroring
3983      set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
3984   if (state->m_chr_chunks)
3985      chr8(space->machine(), sunsoft_helper, CHRROM);
3986
3987   prg16_89ab(space->machine(), data >> 4);
3988}
3989
3990/*************************************************************
3991
3992 Sunsoft-3 board emulation
3993
3994 The two games using this board have incompatible mirroring
3995 wiring, making necessary two distinct mappers & pcb_id
3996
3997 iNES: mapper 67
3998
3999 *************************************************************/
4000
4001/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
4002 we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
4003 there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
4004static void sunsoft3_irq( device_t *device, int scanline, int vblank, int blanked )
4005{
4006   nes_state *state = device->machine().driver_data<nes_state>();
4007
4008   /* TODO: change to reflect the actual number of cycles spent: both using 114 or cycling 114,114,113
4009     produces a 1-line glitch in Fantasy Zone 2: it really requires the counter to be updated each CPU cycle! */
4010   if (state->m_IRQ_enable)
4011   {
4012      if (state->m_IRQ_count <= 114)
4013      {
4014         state->m_IRQ_enable = 0;
4015         state->m_IRQ_count = 0xffff;
4016         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
4017      }
4018      else
4019         state->m_IRQ_count -= 114;
4020   }
4021}
4022
4023static WRITE8_HANDLER( sunsoft3_w )
4024{
4025   nes_state *state = space->machine().driver_data<nes_state>();
4026   LOG_MMC(("sunsoft3_w, offset %04x, data: %02x\n", offset, data));
4027
4028   switch (offset & 0x7800)
4029   {
4030      case 0x0800:
4031         chr2_0(space->machine(), data, CHRROM);
4032         break;
4033      case 0x1800:
4034         chr2_2(space->machine(), data, CHRROM);
4035         break;
4036      case 0x2800:
4037         chr2_4(space->machine(), data, CHRROM);
4038         break;
4039      case 0x3800:
4040         chr2_6(space->machine(), data, CHRROM);
4041         break;
4042      case 0x4000:
4043      case 0x4800:
4044         state->m_IRQ_toggle ^= 1;
4045         if (state->m_IRQ_toggle)
4046            state->m_IRQ_count = (state->m_IRQ_count & 0x00ff) | (data << 8);
4047         else
4048            state->m_IRQ_count = (state->m_IRQ_count & 0xff00) | data;
4049         break;
4050      case 0x5800:
4051         state->m_IRQ_enable = BIT(data, 4);
4052         state->m_IRQ_toggle = 0;
4053         break;
4054      case 0x6800:
4055         switch (data & 3)
4056         {
4057         case 0x00: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
4058         case 0x01: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
4059         case 0x02: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
4060         case 0x03: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
4061         }
4062         break;
4063      case 0x7800:
4064         prg16_89ab(space->machine(), data);
4065         break;
4066      default:
4067         LOG_MMC(("sunsoft3_w uncaught write, offset: %04x, data: %02x\n", offset, data));
4068         break;
4069   }
4070}
4071
4072/*************************************************************
4073
4074 Taito TC0190FMC + board emulation
4075
4076 Games: Akira, Bakushou!! Jinsei Gekijou, Don Doko Don,
4077 Insector X, Operation Wolf, Power Blazer, Takeshi no
4078 Sengoku Fuuunji
4079
4080 iNES: mapper 33
4081
4082 In MESS: Supported.
4083
4084 *************************************************************/
4085
4086static WRITE8_HANDLER( tc0190fmc_w )
4087{
4088   LOG_MMC(("tc0190fmc_w, offset: %04x, data: %02x\n", offset, data));
4089
4090   switch (offset & 0x7003)
4091   {
4092      case 0x0000:
4093         set_nt_mirroring(space->machine(), BIT(data, 6) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
4094         prg8_89(space->machine(), data);
4095         break;
4096      case 0x0001:
4097         prg8_ab(space->machine(), data);
4098         break;
4099      case 0x0002:
4100         chr2_0(space->machine(), data, CHRROM);
4101         break;
4102      case 0x0003:
4103         chr2_2(space->machine(), data, CHRROM);
4104         break;
4105      case 0x2000:
4106         chr1_4(space->machine(), data, CHRROM);
4107         break;
4108      case 0x2001:
4109         chr1_5(space->machine(), data, CHRROM);
4110         break;
4111      case 0x2002:
4112         chr1_6(space->machine(), data, CHRROM);
4113         break;
4114      case 0x2003:
4115         chr1_7(space->machine(), data, CHRROM);
4116         break;
4117   }
4118}
4119
4120/*************************************************************
4121
4122 Taito TC0190FMC + PAL16R4 board emulation
4123
4124 Games: Bakushou!! Jinsei Gekijou 3, Bubble Bobble 2,
4125 Captain Saver, Don Doko Don 2, Flintstones, Jetsons
4126
4127 This is basically Mapper 33 + IRQ. Notably, IRQ works the
4128 same as MMC3 irq, BUT latch values are "inverted" (XOR'ed
4129 with 0xff) and there is a little delay (not implemented yet)
4130 We simply use MMC3 IRQ and XOR the value written in the
4131 register 0xc000 below
4132
4133 iNES: mapper 48
4134
4135 In MESS: Supported.
4136
4137 *************************************************************/
4138
4139static WRITE8_HANDLER( tc0190fmc_p16_w )
4140{
4141   nes_state *state = space->machine().driver_data<nes_state>();
4142   LOG_MMC(("tc0190fmc_p16_w, offset: %04x, data: %02x\n", offset, data));
4143
4144   switch (offset & 0x7003)
4145   {
4146      case 0x0000:
4147         prg8_89(space->machine(), data);
4148         break;
4149      case 0x0001:
4150      case 0x0002:
4151      case 0x0003:
4152      case 0x2000:
4153      case 0x2001:
4154      case 0x2002:
4155      case 0x2003:
4156         tc0190fmc_w(space, offset, data);
4157         break;
4158      case 0x4000:
4159         state->m_IRQ_count_latch = (0x100 - data) & 0xff;
4160         break;
4161      case 0x4001:
4162         state->m_IRQ_count = state->m_IRQ_count_latch;
4163         break;
4164      case 0x4002:
4165         state->m_IRQ_enable = 1;
4166         break;
4167      case 0x4003:
4168         state->m_IRQ_enable = 0;
4169         break;
4170      case 0x6000:
4171         set_nt_mirroring(space->machine(), BIT(data, 6) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
4172         break;
4173   }
4174}
4175
4176/*************************************************************
4177
4178 Taito X1-005 board emulation
4179
4180 Actually, Fudou Myouou Den uses a variant of the board with
4181 CIRAM, making necessary two distinct mappers & pcb_id.
4182
4183 Also, we miss to emulate the security check at 0x7ef8 / 0x7ef9
4184 and the 0x80 ram!
4185
4186 iNES: mappers 80 & 207
4187
4188 *************************************************************/
4189
4190static WRITE8_HANDLER( x1005_m_w )
4191{
4192   nes_state *state = space->machine().driver_data<nes_state>();
4193   LOG_MMC(("x1005_m_w, offset: %04x, data: %02x\n", offset, data));
4194
4195   switch (offset)
4196   {
4197      case 0x1ef0:
4198         chr2_0(space->machine(), (data & 0x7f) >> 1, CHRROM);
4199         break;
4200      case 0x1ef1:
4201         chr2_2(space->machine(), (data & 0x7f) >> 1, CHRROM);
4202         break;
4203      case 0x1ef2:
4204         chr1_4(space->machine(), data, CHRROM);
4205         break;
4206      case 0x1ef3:
4207         chr1_5(space->machine(), data, CHRROM);
4208         break;
4209      case 0x1ef4:
4210         chr1_6(space->machine(), data, CHRROM);
4211         break;
4212      case 0x1ef5:
4213         chr1_7(space->machine(), data, CHRROM);
4214         break;
4215      case 0x1ef6:
4216      case 0x1ef7:
4217         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
4218         break;
4219      case 0x1ef8:
4220      case 0x1ef9:
4221         state->m_mmc_latch1 = data;
4222         break;
4223      case 0x1efa:
4224      case 0x1efb:
4225         prg8_89(space->machine(), data);
4226         break;
4227      case 0x1efc:
4228      case 0x1efd:
4229         prg8_ab(space->machine(), data);
4230         break;
4231      case 0x1efe:
4232      case 0x1eff:
4233         prg8_cd(space->machine(), data);
4234         break;
4235      default:
4236         logerror("mapper80_m_w uncaught addr: %04x, value: %02x\n", offset + 0x6000, data);
4237         break;
4238   }
4239
4240   if (offset >= 0x1f00 && state->m_mapper_ram != NULL && state->m_mmc_latch1 == 0xa3)
4241      state->m_mapper_ram[offset & (state->m_mapper_ram_size - 1)] = data;
4242   else if (offset >= 0x1f00 && state->m_mapper_bram != NULL && state->m_mmc_latch1 == 0xa3)
4243      state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)] = data;
4244}
4245
4246static READ8_HANDLER( x1005_m_r )
4247{
4248   nes_state *state = space->machine().driver_data<nes_state>();
4249   LOG_MMC(("x1005a_m_r, offset: %04x\n", offset));
4250
4251   if (offset >= 0x1f00 && state->m_mapper_ram != NULL && state->m_mmc_latch1 == 0xa3)
4252      return state->m_mapper_ram[offset & (state->m_mapper_ram_size - 1)];
4253   else if (offset >= 0x1f00 && state->m_mapper_bram != NULL && state->m_mmc_latch1 == 0xa3)
4254      return state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)];
4255
4256   return 0xff;
4257}
4258
4259static WRITE8_HANDLER( x1005a_m_w )
4260{
4261   LOG_MMC(("x1005a_m_w, offset: %04x, data: %02x\n", offset, data));
4262
4263   // similar to x1005_m_w but mirroring is handled differently
4264   if (offset == 0x1ef6 || offset == 0x1ef7)
4265      return;
4266
4267   switch (offset)
4268   {
4269      case 0x1ef0:
4270         set_nt_page(space->machine(), 0, CIRAM, (data & 0x80) ? 1 : 0, 1);
4271         set_nt_page(space->machine(), 1, CIRAM, (data & 0x80) ? 1 : 0, 1);
4272         break;
4273      case 0x1ef1:
4274         set_nt_page(space->machine(), 2, CIRAM, (data & 0x80) ? 1 : 0, 1);
4275         set_nt_page(space->machine(), 3, CIRAM, (data & 0x80) ? 1 : 0, 1);
4276         break;
4277   }
4278
4279   x1005_m_w(space, offset, data);
4280}
4281
4282/*************************************************************
4283
4284 Taito X1-017 board emulation
4285
4286 We miss to emulate the security check at 0x6000-0x73ff
4287 and the ram!
4288
4289 Games: Kyuukyoku Harikiri Koushien, Kyuukyoku Harikiri
4290 Stadium, SD Keiji - Blader
4291
4292 iNES: mapper 82
4293
4294 In MESS: Supported.
4295
4296 *************************************************************/
4297
4298static void x1017_set_chr( running_machine &machine )
4299{
4300   nes_state *state = machine.driver_data<nes_state>();
4301   if (state->m_mmc_latch1)
4302   {
4303      chr2_4(machine, state->m_mmc_vrom_bank[0] >> 1, CHRROM);
4304      chr2_6(machine, state->m_mmc_vrom_bank[1] >> 1, CHRROM);
4305   }
4306   else
4307   {
4308      chr2_0(machine, state->m_mmc_vrom_bank[0] >> 1, CHRROM);
4309      chr2_2(machine, state->m_mmc_vrom_bank[1] >> 1, CHRROM);
4310   }
4311   chr1_x(machine, 4 ^ state->m_mmc_latch1, state->m_mmc_vrom_bank[2], CHRROM);
4312   chr1_x(machine, 5 ^ state->m_mmc_latch1, state->m_mmc_vrom_bank[3], CHRROM);
4313   chr1_x(machine, 6 ^ state->m_mmc_latch1, state->m_mmc_vrom_bank[4], CHRROM);
4314   chr1_x(machine, 7 ^ state->m_mmc_latch1, state->m_mmc_vrom_bank[5], CHRROM);
4315}
4316
4317static WRITE8_HANDLER( x1017_m_w )
4318{
4319   nes_state *state = space->machine().driver_data<nes_state>();
4320   UINT8 reg = offset & 0x07;
4321   LOG_MMC(("x1017_m_w, offset: %04x, data: %02x\n", offset, data));
4322
4323   switch (offset)
4324   {
4325      case 0x1ef0:
4326      case 0x1ef1:
4327         if (state->m_mmc_vrom_bank[reg] != data)
4328         {
4329            state->m_mmc_vrom_bank[reg] = data;
4330            x1017_set_chr(space->machine());
4331         }
4332         break;
4333      case 0x1ef2:
4334      case 0x1ef3:
4335      case 0x1ef4:
4336      case 0x1ef5:
4337         if (state->m_mmc_vrom_bank[reg] != data)
4338         {
4339            state->m_mmc_vrom_bank[reg] = data;
4340            x1017_set_chr(space->machine());
4341         }
4342         break;
4343      case 0x1ef6:
4344         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
4345         state->m_mmc_latch1 = ((data & 0x02) << 1);
4346         x1017_set_chr(space->machine());
4347         break;
4348      case 0x1ef7:
4349      case 0x1ef8:
4350      case 0x1ef9:
4351         state->m_mmc_reg[(offset & 0x0f) - 7] = data;
4352         break;
4353      case 0x1efa:
4354         prg8_89(space->machine(), data >> 2);
4355         break;
4356      case 0x1efb:
4357         prg8_ab(space->machine(), data >> 2);
4358         break;
4359      case 0x1efc:
4360         prg8_cd(space->machine(), data >> 2);
4361         break;
4362      default:
4363         logerror("x1017_m_w uncaught write, addr: %04x, value: %02x\n", offset + 0x6000, data);
4364         break;
4365   }
4366}
4367
4368static READ8_HANDLER( x1017_m_r )
4369{
4370   nes_state *state = space->machine().driver_data<nes_state>();
4371   LOG_MMC(("x1017_m_r, offset: %04x\n", offset));
4372
4373   // 2+2+1 KB of Internal RAM can be independently enabled/disabled!
4374   if (offset < 0x0800 && state->m_mapper_bram != NULL && state->m_mmc_reg[0] == 0xca)
4375      return state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)];
4376   if (offset < 0x1000 && state->m_mapper_bram != NULL && state->m_mmc_reg[1] == 0x69)
4377      return state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)];
4378   if (offset < 0x1800 && state->m_mapper_bram != NULL && state->m_mmc_reg[2] == 0x84)
4379      return state->m_mapper_bram[offset & (state->m_mapper_bram_size - 1)];
4380
4381   return 0xff;
4382}
4383
4384/*************************************************************
4385
4386      MISC UNLICENSED BOARDS
4387
4388 *************************************************************/
4389
4390/*************************************************************
4391
4392 AGCI 50282 bootleg board emulation
4393
4394 Games: Death Race
4395
4396 iNES: mapper 144
4397
4398 In MESS: Supported.
4399
4400 *************************************************************/
4401
4402static WRITE8_HANDLER( agci_50282_w )
4403{
4404   LOG_MMC(("agci_50282_w, offset: %04x, data: %02x\n", offset, data));
4405
4406   offset += 0x8000;
4407   data |= (space->read_byte(offset) & 1);
4408
4409   chr8(space->machine(), data >> 4, CHRROM);
4410   prg32(space->machine(), data);
4411}
4412
4413/*************************************************************
4414
4415 AVE NINA-001 board emulation
4416
4417 iNES: mapper 34
4418
4419 *************************************************************/
4420
4421static WRITE8_HANDLER( nina01_m_w )
4422{
4423   LOG_MMC(("nina01_m_w, offset: %04x, data: %02x\n", offset, data));
4424
4425   switch (offset)
4426   {
4427      case 0x1ffd:
4428         prg32(space->machine(), data);
4429         break;
4430      case 0x1ffe:
4431         chr4_0(space->machine(), data, CHRROM);
4432         break;
4433      case 0x1fff:
4434         chr4_4(space->machine(), data, CHRROM);
4435         break;
4436   }
4437}
4438
4439/*************************************************************
4440
4441 AVE NINA-003, NINA-006 and MB-91 boards emulation
4442
4443 Games: Krazy Kreatures, Poke Block, Puzzle, Pyramid,
4444 Solitaire, Ultimate League Soccer
4445
4446 iNES: mapper 79
4447
4448 In MESS: Supported.
4449
4450 *************************************************************/
4451
4452static WRITE8_HANDLER( nina06_l_w )
4453{
4454   LOG_MMC(("nina06_l_w, offset: %04x, data: %02x\n", offset, data));
4455
4456   if (!(offset & 0x0100))
4457   {
4458      prg32(space->machine(), data >> 3);
4459      chr8(space->machine(), data, CHRROM);
4460   }
4461}
4462
4463/*************************************************************
4464
4465 Active Entertainment Action 52 board emulation
4466
4467 iNES: mapper 228
4468
4469 *************************************************************/
4470
4471static WRITE8_HANDLER( ae_act52_w )
4472{
4473   int pbank, cbank;
4474   UINT8 pmode;
4475   LOG_MMC(("ae_act52_w, offset: %04x, data: %02x\n", offset, data));
4476
4477   set_nt_mirroring(space->machine(), BIT(offset, 13) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
4478
4479   cbank = (data & 0x03) | ((offset & 0x0f) << 2);
4480   chr8(space->machine(), cbank, CHRROM);
4481
4482   pmode = offset & 0x20;
4483   pbank = (offset & 0x1fc0) >> 6;
4484   if (pmode)
4485   {
4486      prg16_89ab(space->machine(), pbank);
4487      prg16_cdef(space->machine(), pbank);
4488   }
4489   else
4490      prg32(space->machine(), pbank >> 1);
4491}
4492
4493
4494/*************************************************************
4495
4496 C & E Bootleg Board for Decathlon
4497
4498 Games: Decathlon
4499
4500 Pretty simple mapper: writes to 0x8065-0x80a4 set prg32 to
4501 data & 3; writes to 0x80a5-0x80e4 set chr8 to data & 7
4502
4503 iNES: mapper 244
4504
4505 In MESS: Supported.
4506
4507 *************************************************************/
4508
4509static WRITE8_HANDLER( cne_decathl_w )
4510{
4511   LOG_MMC(("cne_decathl_w, offset: %04x, data: %02x\n", offset, data));
4512
4513   if (offset < 0x0065)
4514      return;
4515   if (offset < 0x00a5)
4516   {
4517      prg32(space->machine(), (offset - 0x0065) & 0x03);
4518      return;
4519   }
4520   if (offset < 0x00e5)
4521   {
4522      chr8(space->machine(), (offset - 0x00a5) & 0x07, CHRROM);
4523   }
4524}
4525
4526/*************************************************************
4527
4528 C & E Bootleg Board for Fong Shen Bang
4529
4530 Games: Fong Shen Bang - Zhu Lu Zhi Zhan
4531
4532 Simple mapper: writes to 0x6000-0x67ff set PRG and CHR banks.
4533 Namely, 0x6000->0x6003 select resp. prg8_89, prg8_ab, prg8_cd
4534 and prg8_ef. 0x6004->0x6007 select resp. crh2_0, chr2_2,
4535 chr2_4 and chr2_6. In 0x6800-0x7fff lies WRAM.
4536
4537 iNES: mapper 246
4538
4539 In MESS: Supported.
4540
4541 *************************************************************/
4542
4543static WRITE8_HANDLER( cne_fsb_m_w )
4544{
4545   nes_state *state = space->machine().driver_data<nes_state>();
4546   LOG_MMC(("cne_fsb_m_w, offset: %04x, data: %02x\n", offset, data));
4547
4548   if (offset < 0x0800)
4549   {
4550      switch (offset & 0x0007)
4551      {
4552         case 0x0000:
4553            prg8_89(space->machine(), data);
4554            break;
4555         case 0x0001:
4556            prg8_ab(space->machine(), data);
4557            break;
4558         case 0x0002:
4559            prg8_cd(space->machine(), data);
4560            break;
4561         case 0x0003:
4562            prg8_ef(space->machine(), data);
4563            break;
4564         case 0x0004:
4565            chr2_0(space->machine(), data, CHRROM);
4566            break;
4567         case 0x0005:
4568            chr2_2(space->machine(), data, CHRROM);
4569            break;
4570         case 0x0006:
4571            chr2_4(space->machine(), data, CHRROM);
4572            break;
4573         case 0x0007:
4574            chr2_6(space->machine(), data, CHRROM);
4575            break;
4576      }
4577   }
4578   else
4579      state->m_battery_ram[offset] = data;
4580}
4581
4582/*************************************************************
4583
4584 C & E Bootleg Board for Sheng Huo Lie Zhuan
4585
4586 Games: Jing Ke Xin Zhuan, Sheng Huo Lie Zhuan
4587
4588 Simple Mapper: writes to 0x4020-0x5fff sets prg32 to
4589 data>>4 and chr8 to data&f. We currently do not map
4590 writes to 0x4020-0x40ff (to do: verify if this produces
4591 issues)
4592
4593 iNES: mapper 240
4594
4595 In MESS: Supported.
4596
4597 *************************************************************/
4598
4599static WRITE8_HANDLER( cne_shlz_l_w )
4600{
4601   LOG_MMC(("cne_shlz_l_w, offset: %04x, data: %02x\n", offset, data));
4602
4603   prg32(space->machine(), data >> 4);
4604   chr8(space->machine(), data & 0x0f, CHRROM);
4605}
4606
4607/*************************************************************
4608
4609 Caltron 6 in 1 Board
4610
4611 Games: 6 in 1 by Caltron
4612
4613 iNES: mapper 41
4614
4615 In MESS: Supported.
4616
4617 *************************************************************/
4618
4619static WRITE8_HANDLER( caltron6in1_m_w )
4620{
4621   nes_state *state = space->machine().driver_data<nes_state>();
4622   LOG_MMC(("caltron6in1_m_w, offset: %04x, data: %02x\n", offset, data));
4623
4624   state->m_mmc_latch1 = offset & 0xff;
4625   set_nt_mirroring(space->machine(), BIT(data, 5) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
4626   prg32(space->machine(), offset & 0x07);
4627}
4628
4629static WRITE8_HANDLER( caltron6in1_w )
4630{
4631   nes_state *state = space->machine().driver_data<nes_state>();
4632   LOG_MMC(("caltron6in1_w, offset: %04x, data: %02x\n", offset, data));
4633
4634   if (state->m_mmc_latch1 & 0x04)
4635      chr8(space->machine(), ((state->m_mmc_latch1 & 0x18) >> 1) | (data & 0x03), CHRROM);
4636}
4637
4638/*************************************************************
4639
4640 Camerica Boards (BF9093, BF9097, BF909X, ALGNV11)
4641
4642 Games: Linus Spacehead's Cosmic Crusade, Micro Machines,
4643 Mig-29, Stunt Kids
4644
4645 To emulate NT mirroring for BF9097 board (missing in BF9093)
4646 we use crc_hack, however Fire Hawk is broken (but without
4647 mirroring there would be no helicopter graphics).
4648
4649 iNES: mapper 71
4650
4651 In MESS: Partially Supported.
4652
4653 *************************************************************/
4654
4655static WRITE8_HANDLER( bf9093_w )
4656{
4657   nes_state *state = space->machine().driver_data<nes_state>();
4658   LOG_MMC(("bf9093_w, offset: %04x, data: %02x\n", offset, data));
4659
4660   switch (offset & 0x7000)
4661   {
4662      case 0x0000:
4663      case 0x1000:
4664         if (!state->m_hard_mirroring)
4665            set_nt_mirroring(space->machine(), BIT(data, 4) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
4666         break;
4667      case 0x4000:
4668      case 0x5000:
4669      case 0x6000:
4670      case 0x7000:
4671         prg16_89ab(space->machine(), data);
4672         break;
4673   }
4674}
4675
4676/*************************************************************
4677
4678 Camerica BF9096 & ALGQV11 Boards
4679
4680 Games: Quattro Adventure, Quattro Arcade, Quattro Sports
4681
4682 Writes to 0x8000-0x9fff set prg block to (data&0x18)>>1,
4683 writes to 0xa000-0xbfff set prg page to data&3. selected
4684 prg are: prg16_89ab = block|page, prg_cdef = 3|page.
4685 For more info on the hardware to bypass the NES lockout, see
4686 Kevtris' Camerica Mappers documentation.
4687
4688 iNES: mapper 232
4689
4690 In MESS: Supported.
4691
4692 *************************************************************/
4693
4694static void bf9096_set_prg( running_machine &machine )
4695{
4696   nes_state *state = machine.driver_data<nes_state>();
4697   prg16_89ab(machine, (state->m_mmc_latch2 & 0x03) | ((state->m_mmc_latch1 & 0x18) >> 1));
4698   prg16_cdef(machine, 0x03 | ((state->m_mmc_latch1 & 0x18) >> 1));
4699}
4700
4701static WRITE8_HANDLER( bf9096_w )
4702{
4703   nes_state *state = space->machine().driver_data<nes_state>();
4704   LOG_MMC(("bf9096_w, offset: %04x, data: %02x\n", offset, data));
4705
4706   if (offset < 0x2000)
4707      state->m_mmc_latch1 = data;
4708   else
4709      state->m_mmc_latch2 = data;
4710
4711   bf9096_set_prg(space->machine());
4712}
4713
4714/*************************************************************
4715
4716 Camerica Golden Five board
4717
4718 Games: Pegasus 5 in 1
4719
4720 iNES: mapper 104
4721
4722 In MESS: Supported.
4723
4724 *************************************************************/
4725
4726static WRITE8_HANDLER( golden5_w )
4727{
4728   nes_state *state = space->machine().driver_data<nes_state>();
4729   LOG_MMC(("golden5_w, offset: %04x, data: %02x\n", offset, data));
4730
4731   if (offset < 0x4000)
4732   {
4733      if (data & 0x08)
4734      {
4735         state->m_mmc_prg_bank[0] = ((data & 0x07) << 4) | (state->m_mmc_prg_bank[0] & 0x0f);
4736         prg16_89ab(space->machine(), state->m_mmc_prg_bank[0]);
4737         prg16_cdef(space->machine(), ((data & 0x07) << 4) | 0x0f);
4738      }
4739
4740   }
4741   else
4742   {
4743      state->m_mmc_prg_bank[0] = (state->m_mmc_prg_bank[0] & 0x70) | (data & 0x0f);
4744      prg16_89ab(space->machine(), state->m_mmc_prg_bank[0]);
4745   }
4746}
4747
4748/*************************************************************
4749
4750 Cony Bootleg Board
4751
4752 Games: Dragon Ball Party, Fatal Fury 2, Street Blaster II
4753 Pro, World Heroes 2
4754
4755 iNES: mapper 83
4756
4757 In MESS: Supported.
4758
4759 *************************************************************/
4760
4761static WRITE8_HANDLER( cony_l_w )
4762{
4763   nes_state *state = space->machine().driver_data<nes_state>();
4764   LOG_MMC(("cony_l_w, offset: %04x, data: %02x\n", offset, data));
4765
4766   if (offset >= 0x1000 && offset < 0x1103) // from 0x5100-0x51ff
4767      state->m_mapper83_low_reg[offset & 0x03] = data;
4768}
4769
4770static READ8_HANDLER( cony_l_r )
4771{
4772   nes_state *state = space->machine().driver_data<nes_state>();
4773   LOG_MMC(("cony_l_r, offset: %04x\n", offset));
4774
4775   if (offset == 0x0f00)   // 0x5000
4776   {
4777      // read dipswitch bit! - currently unimplemented
4778   }
4779   if (offset >= 0x1000 && offset < 0x1103) // from 0x5100-0x51ff
4780      return state->m_mapper83_low_reg[offset & 0x03];
4781   else
4782      return 0x00;
4783}
4784
4785static void cony_set_prg( running_machine &machine )
4786{
4787   nes_state *state = machine.driver_data<nes_state>();
4788   prg16_89ab(machine, state->m_mapper83_reg[8] & 0x3f);
4789   prg16_cdef(machine, (state->m_mapper83_reg[8] & 0x30) | 0x0f);
4790}
4791
4792static void cony_set_chr( running_machine &machine )
4793{
4794   nes_state *state = machine.driver_data<nes_state>();
4795   // FIXME: here we emulate at least 3 different boards!!!
4796   // one board switches 1k VROM banks only
4797   // one writes to 0x8000 and then switches 2k VROM banks only
4798   // one writes to 0x831n (n=2,3,4,5) and then switches 2k VROM banks only
4799   // we should split them and possibly document the proper behavior of each variant
4800   if (state->m_mmc_latch1 && !state->m_mmc_latch2)
4801   {
4802      chr2_0(machine, state->m_mapper83_reg[0], CHRROM);
4803      chr2_2(machine, state->m_mapper83_reg[1], CHRROM);
4804      chr2_4(machine, state->m_mapper83_reg[6], CHRROM);
4805      chr2_6(machine, state->m_mapper83_reg[7], CHRROM);
4806   }
4807   else
4808   {
4809      chr1_0(machine, state->m_mapper83_reg[0] | ((state->m_mapper83_reg[8] & 0x30) << 4), CHRROM);
4810      chr1_1(machine, state->m_mapper83_reg[1] | ((state->m_mapper83_reg[8] & 0x30) << 4), CHRROM);
4811      chr1_2(machine, state->m_mapper83_reg[2] | ((state->m_mapper83_reg[8] & 0x30) << 4), CHRROM);
4812      chr1_3(machine, state->m_mapper83_reg[3] | ((state->m_mapper83_reg[8] & 0x30) << 4), CHRROM);
4813      chr1_4(machine, state->m_mapper83_reg[4] | ((state->m_mapper83_reg[8] & 0x30) << 4), CHRROM);
4814      chr1_5(machine, state->m_mapper83_reg[5] | ((state->m_mapper83_reg[8] & 0x30) << 4), CHRROM);
4815      chr1_6(machine, state->m_mapper83_reg[6] | ((state->m_mapper83_reg[8] & 0x30) << 4), CHRROM);
4816      chr1_7(machine, state->m_mapper83_reg[7] | ((state->m_mapper83_reg[8] & 0x30) << 4), CHRROM);
4817   }
4818}
4819
4820static WRITE8_HANDLER( cony_w )
4821{
4822   nes_state *state = space->machine().driver_data<nes_state>();
4823   LOG_MMC(("cony_w, offset: %04x, data: %02x\n", offset, data));
4824
4825   switch (offset)
4826   {
4827      case 0x0000:
4828         state->m_mmc_latch1 = 1;
4829      case 0x3000:
4830      case 0x30ff:
4831      case 0x31ff:
4832         state->m_mapper83_reg[8] = data;
4833         cony_set_prg(space->machine());
4834         cony_set_chr(space->machine());
4835         break;
4836      case 0x0100:
4837         state->m_mmc_reg[0] = data & 0x80;
4838         switch (data & 0x03)
4839         {
4840         case 0:
4841            set_nt_mirroring(space->machine(), PPU_MIRROR_VERT);
4842            break;
4843         case 1:
4844            set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ);
4845            break;
4846         case 2:
4847            set_nt_mirroring(space->machine(), PPU_MIRROR_LOW);
4848            break;
4849         case 3:
4850            set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH);
4851            break;
4852         }
4853         break;
4854      case 0x0200:
4855         state->m_IRQ_count = (state->m_IRQ_count & 0xff00) | data;
4856         break;
4857      case 0x0201:
4858         state->m_IRQ_enable = state->m_mmc_reg[0];
4859         state->m_IRQ_count = (data << 8) | (state->m_IRQ_count & 0xff);
4860         break;
4861      case 0x0300:
4862         prg8_89(space->machine(), data);
4863         break;
4864      case 0x0301:
4865         prg8_ab(space->machine(), data);
4866         break;
4867      case 0x0302:
4868         prg8_cd(space->machine(), data);
4869         break;
4870      case 0x0312:
4871      case 0x0313:
4872      case 0x0314:
4873      case 0x0315:
4874         state->m_mmc_latch2 = 1;
4875      case 0x0310:
4876      case 0x0311:
4877      case 0x0316:
4878      case 0x0317:
4879         state->m_mapper83_reg[offset - 0x0310] = data;
4880         cony_set_chr(space->machine());
4881         break;
4882      case 0x0318:
4883         state->m_mapper83_reg[9] = data;
4884         cony_set_prg(space->machine());
4885         break;
4886   }
4887}
4888
4889/*************************************************************
4890
4891 Board DREAMTECH01
4892
4893 Games: Korean Igo
4894
4895 In MESS: Supported
4896
4897 *************************************************************/
4898
4899static WRITE8_HANDLER( dreamtech_l_w )
4900{
4901   LOG_MMC(("dreamtech_l_w offset: %04x, data: %02x\n", offset, data));
4902   offset += 0x100;
4903
4904   if (offset == 0x1020)   /* 0x5020 */
4905      prg16_89ab(space->machine(), data);
4906}
4907
4908/*************************************************************
4909
4910 Bootleg Board by Fukutake
4911
4912 Games: Study Box
4913
4914 iNES: mapper 186
4915
4916 In MESS: Unsupported.
4917
4918
4919 *************************************************************/
4920
4921static WRITE8_HANDLER( fukutake_l_w )
4922{
4923   nes_state *state = space->machine().driver_data<nes_state>();
4924   LOG_MMC(("fukutake_l_w offset: %04x, data: %02x\n", offset, data));
4925   offset += 0x100;
4926
4927   if (offset >= 0x200 && offset < 0x400)
4928   {
4929      if (offset & 1)
4930         prg16_89ab(space->machine(), data);
4931      else
4932         wram_bank(space->machine(), data >> 6, NES_WRAM);
4933   }
4934   else if (offset >= 0x400 && offset < 0xf00)
4935      state->m_mapper_ram[offset - 0x400] = data;
4936}
4937
4938static READ8_HANDLER( fukutake_l_r )
4939{
4940   nes_state *state = space->machine().driver_data<nes_state>();
4941   LOG_MMC(("fukutake_l_r offset: %04x\n", offset));
4942   offset += 0x100;
4943
4944   if (offset >= 0x200 && offset < 0x400)
4945   {
4946      if (offset == 0x200 || offset == 0x201 || offset == 0x203)
4947         return 0x00;
4948      else if (offset == 0x202)
4949         return 0x40;
4950      else
4951         return 0xff;
4952   }
4953   else if (offset >= 0x400 && offset < 0xf00)
4954      return state->m_mapper_ram[offset - 0x400];
4955
4956   return 0;
4957}
4958
4959/*************************************************************
4960
4961 Bootleg Board by Future Media
4962
4963 Games: Crayon Shin-chan (C), San Guo Zhi 4 - Chi Bi Feng Yun
4964
4965 iNES: mapper 117
4966
4967 In MESS: Unsupported.
4968
4969 *************************************************************/
4970
4971static void futuremedia_irq( device_t *device, int scanline, int vblank, int blanked )
4972{
4973   nes_state *state = device->machine().driver_data<nes_state>();
4974   //  if (scanline < PPU_BOTTOM_VISIBLE_SCANLINE)
4975   {
4976      if (state->m_IRQ_enable && state->m_IRQ_count)
4977      {
4978         state->m_IRQ_count--;
4979         if (!state->m_IRQ_count)
4980            device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
4981      }
4982   }
4983}
4984
4985static WRITE8_HANDLER( futuremedia_w )
4986{
4987   nes_state *state = space->machine().driver_data<nes_state>();
4988   LOG_MMC(("futuremedia_w, offset: %04x, data: %02x\n", offset, data));
4989
4990   switch (offset)
4991   {
4992      case 0x0000:
4993         prg8_89(space->machine(), data);
4994         break;
4995      case 0x0001:
4996         prg8_ab(space->machine(), data);
4997         break;
4998      case 0x0002:
4999         prg8_cd(space->machine(), data);
5000         break;
5001      case 0x0003:
5002         prg8_ef(space->machine(), data);
5003         break;
5004      case 0x2000:
5005      case 0x2001:
5006      case 0x2002:
5007      case 0x2003:
5008      case 0x2004:
5009      case 0x2005:
5010      case 0x2006:
5011      case 0x2007:
5012         chr1_x(space->machine(), offset & 0x07, data, CHRROM);
5013         break;
5014
5015      case 0x5000:
5016         set_nt_mirroring(space->machine(), BIT(data, 0) ?  PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5017         break;
5018
5019      case 0x4001:
5020         state->m_IRQ_count_latch = data;
5021         break;
5022      case 0x4002:
5023         // IRQ cleared
5024         break;
5025      case 0x4003:
5026         state->m_IRQ_count = state->m_IRQ_count_latch;
5027         break;
5028      case 0x6000:
5029         state->m_IRQ_enable = data & 0x01;
5030         break;
5031   }
5032}
5033
5034/*************************************************************
5035
5036 Bootleg Board 37017 (?) by Gouder
5037
5038 Games: Street Fighter IV
5039
5040 MMC3 clone. It also requires reads from 0x5000-0x7fff.
5041
5042 iNES: mapper 208
5043
5044 In MESS: Preliminary Support.
5045
5046 *************************************************************/
5047
5048static WRITE8_HANDLER( gouder_sf4_l_w )
5049{
5050   nes_state *state = space->machine().driver_data<nes_state>();
5051   static const UINT8 conv_table[256] =
5052   {
5053      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x49,0x19,0x09,0x59,0x49,0x19,0x09,
5054      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x51,0x41,0x11,0x01,0x51,0x41,0x11,0x01,
5055      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x49,0x19,0x09,0x59,0x49,0x19,0x09,
5056      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x51,0x41,0x11,0x01,0x51,0x41,0x11,0x01,
5057      0x00,0x10,0x40,0x50,0x00,0x10,0x40,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
5058      0x08,0x18,0x48,0x58,0x08,0x18,0x48,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
5059      0x00,0x10,0x40,0x50,0x00,0x10,0x40,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
5060      0x08,0x18,0x48,0x58,0x08,0x18,0x48,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
5061      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x58,0x48,0x18,0x08,0x58,0x48,0x18,0x08,
5062      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x50,0x40,0x10,0x00,0x50,0x40,0x10,0x00,
5063      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x58,0x48,0x18,0x08,0x58,0x48,0x18,0x08,
5064      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x50,0x40,0x10,0x00,0x50,0x40,0x10,0x00,
5065      0x01,0x11,0x41,0x51,0x01,0x11,0x41,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
5066      0x09,0x19,0x49,0x59,0x09,0x19,0x49,0x59,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
5067      0x01,0x11,0x41,0x51,0x01,0x11,0x41,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
5068      0x09,0x19,0x49,0x59,0x09,0x19,0x49,0x59,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
5069   };
5070
5071   LOG_MMC(("gouder_sf4_l_w, offset: %04x, data: %02x\n", offset, data));
5072
5073   if (!(offset < 0x1700))
5074      state->m_mmc_reg[offset & 0x03] = data ^ conv_table[state->m_mmc_reg[4]];
5075   else if (!(offset < 0xf00))
5076      state->m_mmc_reg[4] = data;
5077   else if (!(offset < 0x700))
5078      prg32(space->machine(), ((data >> 3) & 0x02) | (data & 0x01));
5079}
5080
5081static READ8_HANDLER( gouder_sf4_l_r )
5082{
5083   nes_state *state = space->machine().driver_data<nes_state>();
5084   LOG_MMC(("gouder_sf4_l_r, offset: %04x\n", offset));
5085
5086   if (!(offset < 0x1700))
5087      return state->m_mmc_reg[offset & 0x03];
5088
5089   return 0x00;
5090}
5091
5092/* writes to 0x8000-0xffff are like MMC3 but no PRG bankswitch (beacuse it is handled by low writes) */
5093static void gouder_sf4_prg_cb( running_machine &machine, int start, int bank )
5094{
5095   return;
5096}
5097
5098
5099/*************************************************************
5100
5101 Bootleg Board by Henggedianzi
5102
5103 Games: Mei Guo Fu Hao, Shang Gu Shen Jian , Wang Zi Fu
5104 Chou Ji
5105
5106 Writes to 0x8000-0xffff set prg32. Moreover, data&0x20 sets
5107 NT mirroring.
5108
5109 iNES: mapper 177
5110
5111 In MESS: Supported.
5112
5113 *************************************************************/
5114
5115static WRITE8_HANDLER( henggedianzi_w )
5116{
5117   LOG_MMC(("henggedianzi_w, offset: %04x, data: %02x\n", offset, data));
5118
5119   prg32(space->machine(), data);
5120   set_nt_mirroring(space->machine(), BIT(data, 5) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5121}
5122
5123/*************************************************************
5124
5125 Bootleg Board by Henggedianzi
5126
5127 Games: Xing He Zhan Shi
5128
5129 Writes to 0x5000-0x5fff set prg32 banks, writes to 0x8000-
5130 0xffff set NT mirroring
5131
5132 iNES: mapper 179
5133
5134 In MESS: Supported.
5135
5136 *************************************************************/
5137
5138static WRITE8_HANDLER( heng_xjzb_l_w )
5139{
5140   LOG_MMC(("heng_xjzb_l_w, offset: %04x, data: %02x\n", offset, data));
5141   offset += 0x4100;
5142
5143   if (offset & 0x5000)
5144      prg32(space->machine(), data >> 1);
5145}
5146
5147static WRITE8_HANDLER( heng_xjzb_w )
5148{
5149   LOG_MMC(("heng_xjzb_w, offset: %04x, data: %02x\n", offset, data));
5150
5151   set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5152}
5153
5154/*************************************************************
5155
5156 Bootleg Board by HES (also used by others)
5157
5158 Games: AV Hanafuda Club, AV Soccer, Papillon, Sidewinder,
5159 Total Funpack
5160
5161 Actually, two variant: one for HES 6-in-1 with mirroring control
5162 and one for AV Soccer and others with hardwired mirroring
5163
5164 iNES: mapper 113
5165
5166 In MESS: Supported.
5167
5168 *************************************************************/
5169
5170static WRITE8_HANDLER( hes6in1_l_w )
5171{
5172   LOG_MMC(("hes6in1_l_w, offset: %04x, data: %02x\n", offset, data));
5173
5174   if (!(offset & 0x100))
5175   {
5176      prg32(space->machine(), (data & 0x38) >> 3);
5177      chr8(space->machine(), (data & 0x07) | ((data & 0x40) >> 3), CHRROM);
5178      set_nt_mirroring(space->machine(), BIT(data, 7) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
5179   }
5180}
5181
5182static WRITE8_HANDLER( hes_l_w )
5183{
5184   LOG_MMC(("hes_l_w, offset: %04x, data: %02x\n", offset, data));
5185
5186   if (!(offset & 0x100))
5187   {
5188      prg32(space->machine(), (data & 0x38) >> 3);
5189      chr8(space->machine(), (data & 0x07) | ((data & 0x40) >> 3), CHRROM);
5190   }
5191}
5192
5193/*************************************************************
5194
5195 Bootleg Board by Hosenkan
5196
5197 Games: Pocahontas, Super Donkey Kong
5198
5199 iNES: mapper 182
5200
5201 In MESS: Supported.
5202
5203 *************************************************************/
5204
5205static WRITE8_HANDLER( hosenkan_w )
5206{
5207   nes_state *state = space->machine().driver_data<nes_state>();
5208   LOG_MMC(("hosenkan_w, offset: %04x, data: %02x\n", offset, data));
5209
5210   switch (offset & 0x7003)
5211   {
5212      case 0x0001:
5213         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5214         break;
5215      case 0x2000:
5216         state->m_mmc_latch1 = data;
5217         break;
5218      case 0x4000:
5219         switch (state->m_mmc_latch1)
5220      {
5221         case 0:
5222            chr2_0(space->machine(), data >> 1, CHRROM);
5223            break;
5224         case 1:
5225            chr1_5(space->machine(), data, CHRROM);
5226            break;
5227         case 2:
5228            chr2_2(space->machine(), data >> 1, CHRROM);
5229            break;
5230         case 3:
5231            chr1_7(space->machine(), data, CHRROM);
5232            break;
5233         case 4:
5234            prg8_89(space->machine(), data);
5235            break;
5236         case 5:
5237            prg8_ab(space->machine(), data);
5238            break;
5239         case 6:
5240            chr1_4(space->machine(), data, CHRROM);
5241            break;
5242         case 7:
5243            chr1_6(space->machine(), data, CHRROM);
5244            break;
5245      }
5246         break;
5247      case 0x6003:
5248         if (data)
5249         {
5250            state->m_IRQ_count = data;
5251            state->m_IRQ_enable = 1;
5252         }
5253         else
5254            state->m_IRQ_enable = 0;
5255         break;
5256   }
5257}
5258
5259/*************************************************************
5260
5261 Kaiser Board KS7058
5262
5263 Games: Tui Do Woo Ma Jeung
5264
5265 Writes to 0xf000-0xffff set 4k chr banks. Namely, if
5266 offset&0x80 is 0 the lower 4k are set, if it is 1 the
5267 upper 4k are set.
5268
5269 iNES: mapper 171
5270
5271 In MESS: Supported.
5272
5273 *************************************************************/
5274
5275static WRITE8_HANDLER( ks7058_w )
5276{
5277   LOG_MMC(("ks7058_w, offset: %04x, data: %02x\n", offset, data));
5278
5279   switch (offset & 0x7080)
5280   {
5281      case 0x7000:
5282         chr4_0(space->machine(), data, CHRROM);
5283         break;
5284      case 0x7080:
5285         chr4_4(space->machine(), data, CHRROM);
5286         break;
5287   }
5288}
5289
5290/*************************************************************
5291
5292 Kaiser Board KS7022
5293
5294 Games: 15 in 1
5295
5296 iNES: mapper 175
5297
5298 In MESS: Supported?
5299
5300 *************************************************************/
5301
5302static WRITE8_HANDLER( ks7022_w )
5303{
5304   nes_state *state = space->machine().driver_data<nes_state>();
5305   LOG_MMC(("ks7022_w, offset: %04x, data: %02x\n", offset, data));
5306
5307   if (offset == 0)
5308      set_nt_mirroring(space->machine(), BIT(data, 2) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5309
5310   if (offset == 0x2000)
5311      state->m_mmc_latch1 = data & 0x0f;
5312}
5313
5314static READ8_HANDLER( ks7022_r )
5315{
5316   nes_state *state = space->machine().driver_data<nes_state>();
5317   LOG_MMC(("ks7022_r, offset: %04x\n", offset));
5318
5319   if (offset == 0x7ffc)
5320   {
5321      chr8(space->machine(), state->m_mmc_latch1, CHRROM);
5322      prg16_89ab(space->machine(), state->m_mmc_latch1);
5323      prg16_cdef(space->machine(), state->m_mmc_latch1);
5324   }
5325
5326   return mmc_hi_access_rom(space->machine(), offset);
5327}
5328
5329/*************************************************************
5330
5331 Kaiser Board KS7032
5332
5333 Games:
5334
5335 iNES:
5336
5337 In MESS:
5338
5339 *************************************************************/
5340
5341static void ks7032_prg_update( running_machine &machine )
5342{
5343   nes_state *state = machine.driver_data<nes_state>();
5344
5345   prg8_67(machine, state->m_mmc_reg[4]);
5346   prg8_89(machine, state->m_mmc_reg[1]);
5347   prg8_ab(machine, state->m_mmc_reg[2]);
5348   prg8_cd(machine, state->m_mmc_reg[3]);
5349}
5350
5351static void ks7032_irq( device_t *device, int scanline, int vblank, int blanked )
5352{
5353   nes_state *state = device->machine().driver_data<nes_state>();
5354
5355   if (state->m_IRQ_enable)
5356   {
5357      if (state->m_IRQ_count >= (0xffff - 114))
5358      {
5359         state->m_IRQ_enable = 0;
5360         state->m_IRQ_count = state->m_IRQ_count_latch;
5361         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
5362      }
5363      else
5364         state->m_IRQ_count += 114;
5365   }
5366}
5367
5368static WRITE8_HANDLER( ks7032_w )
5369{
5370   nes_state *state = space->machine().driver_data<nes_state>();
5371   LOG_MMC(("ks7032_w, offset: %04x, data: %02x\n", offset, data));
5372
5373   switch (offset & 0x7000)
5374   {
5375      case 0x0000:
5376         state->m_IRQ_count = (state->m_IRQ_count & 0xfff0) | (data & 0x0f);
5377         break;
5378      case 0x1000:
5379         state->m_IRQ_count = (state->m_IRQ_count & 0xff0f) | ((data & 0x0f) << 4);
5380         break;
5381      case 0x2000:
5382         state->m_IRQ_count = (state->m_IRQ_count & 0xf0ff) | ((data & 0x0f) << 8);
5383         break;
5384      case 0x3000:
5385         state->m_IRQ_count = (state->m_IRQ_count & 0x0fff) | ((data & 0x0f) << 12);
5386         break;
5387      case 0x4000:
5388         state->m_IRQ_enable = 1;
5389         break;
5390      case 0x6000:
5391         state->m_mmc_latch1 = data & 0x07;
5392         break;
5393      case 0x7000:
5394         state->m_mmc_reg[state->m_mmc_latch1] = data;
5395         ks7032_prg_update(space->machine());
5396         break;
5397   }
5398}
5399
5400/*************************************************************
5401
5402 Kaiser Board KS202
5403
5404 Games:
5405
5406 iNES:
5407
5408 In MESS: Supported?
5409
5410 *************************************************************/
5411
5412
5413static WRITE8_HANDLER( ks202_w )
5414{
5415   nes_state *state = space->machine().driver_data<nes_state>();
5416   LOG_MMC(("ks202_w, offset: %04x, data: %02x\n", offset, data));
5417
5418   switch (offset & 0x7000)
5419   {
5420      case 0x0000:
5421         state->m_IRQ_count = (state->m_IRQ_count & 0xfff0) | (data & 0x0f);
5422         break;
5423      case 0x1000:
5424         state->m_IRQ_count = (state->m_IRQ_count & 0xff0f) | ((data & 0x0f) << 4);
5425         break;
5426      case 0x2000:
5427         state->m_IRQ_count = (state->m_IRQ_count & 0xf0ff) | ((data & 0x0f) << 8);
5428         break;
5429      case 0x3000:
5430         state->m_IRQ_count = (state->m_IRQ_count & 0x0fff) | ((data & 0x0f) << 12);
5431         break;
5432      case 0x4000:
5433         state->m_IRQ_enable = 1;
5434         break;
5435      case 0x6000:
5436         state->m_mmc_latch1 = data & 0x07;
5437         break;
5438      case 0x7000:
5439         state->m_mmc_reg[state->m_mmc_latch1] = data;
5440         ks7032_prg_update(space->machine());
5441         switch (offset & 0xc00)
5442         {
5443         case 0x800:
5444            set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
5445            break;
5446         case 0xc00:
5447            chr1_x(space->machine(), offset & 0x07, data, CHRROM);
5448            break;
5449         }
5450         break;
5451   }
5452}
5453
5454/*************************************************************
5455
5456 Kaiser Board KS7017
5457
5458 Games:
5459
5460 iNES:
5461
5462 In MESS: Not working
5463
5464 *************************************************************/
5465
5466static void mmc_fds_irq( device_t *device, int scanline, int vblank, int blanked )
5467{
5468   nes_state *state = device->machine().driver_data<nes_state>();
5469
5470   if (state->m_IRQ_enable)
5471   {
5472      if (state->m_IRQ_count <= 114)
5473      {
5474         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
5475         state->m_IRQ_enable = 0;
5476         state->m_IRQ_status |= 0x01;
5477      }
5478      else
5479         state->m_IRQ_count -= 114;
5480   }
5481}
5482
5483static WRITE8_HANDLER( ks7017_l_w )
5484{
5485   nes_state *state = space->machine().driver_data<nes_state>();
5486   LOG_MMC(("ks7022_w, offset: %04x, data: %02x\n", offset, data));
5487
5488   offset += 0x100;
5489
5490   if (offset >= 0xa00 && offset < 0xb00)
5491      state->m_mmc_latch1 = ((offset >> 2) & 0x03) | ((offset >> 4) & 0x04);
5492
5493   if (offset >= 0x1000 && offset < 0x1100)
5494      prg16_89ab(space->machine(), state->m_mmc_latch1);
5495}
5496
5497WRITE8_HANDLER( ks7017_extra_w )
5498{
5499   nes_state *state = space->machine().driver_data<nes_state>();
5500   LOG_MMC(("ks7017_extra_w, offset: %04x, data: %02x\n", offset, data));
5501
5502   offset += 0x20;
5503
5504   if (offset == 0x0020) /* 0x4020 */
5505      state->m_IRQ_count = (state->m_IRQ_count & 0xff00) | data;
5506
5507   if (offset == 0x0021) /* 0x4021 */
5508      state->m_IRQ_count = (state->m_IRQ_count & 0x00ff) | (data << 8);
5509
5510   if (offset == 0x0025) /* 0x4025 */
5511      set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5512}
5513
5514READ8_HANDLER( ks7017_extra_r )
5515{
5516   nes_state *state = space->machine().driver_data<nes_state>();
5517   LOG_MMC(("ks7017_extra_r, offset: %04x\n", offset));
5518
5519   state->m_IRQ_status &= ~0x01;
5520   return state->m_IRQ_status;
5521}
5522
5523/*************************************************************
5524
5525 Bootleg Board by Kay (for Panda Prince)
5526
5527 Games: The Panda Prince, Sonic 3d Blast 6, SFZ2 '97, YuYu '97
5528 (and its title hack MK6), UMK3, Super Lion King 2
5529
5530 MMC3 clone. This is basically KOF96 board + protection
5531
5532 iNES: mapper 121
5533
5534 In MESS: Most game works, with some graphical issues.
5535
5536 *************************************************************/
5537
5538static WRITE8_HANDLER( kay_pp_l_w )
5539{
5540   nes_state *state = space->machine().driver_data<nes_state>();
5541   LOG_MMC(("kay_pp_l_w, offset: %04x, data: %02x\n", offset, data));
5542   offset += 0x100;
5543
5544   if (offset >= 0x1000)
5545   {
5546      switch (data & 0x03)
5547      {
5548         case 0x00:
5549         case 0x01:
5550            state->m_mmc_reg[0] = 0x83;
5551            break;
5552         case 0x02:
5553            state->m_mmc_reg[0] = 0x42;
5554            break;
5555         case 0x03:
5556            state->m_mmc_reg[0] = 0x00;
5557            break;
5558      }
5559   }
5560}
5561
5562static READ8_HANDLER( kay_pp_l_r )
5563{
5564   nes_state *state = space->machine().driver_data<nes_state>();
5565   LOG_MMC(("kay_pp_l_r, offset: %04x\n", offset));
5566   offset += 0x100;
5567
5568   if (offset >= 0x1000)
5569      return state->m_mmc_reg[0];
5570   else
5571      return 0xff;
5572}
5573
5574static void kay_pp_update_regs( running_machine &machine )
5575{
5576   nes_state *state = machine.driver_data<nes_state>();
5577
5578   switch (state->m_mmc_reg[5] & 0x3f)
5579   {
5580      case 0x20:
5581      case 0x29:
5582      case 0x2b:
5583      case 0x3f:
5584         state->m_mmc_reg[7] = 1;
5585         state->m_mmc_reg[1] = state->m_mmc_reg[6];
5586         break;
5587      case 0x26:
5588         state->m_mmc_reg[7] = 0;
5589         state->m_mmc_reg[1] = state->m_mmc_reg[6];
5590         break;
5591      case 0x2c:
5592         state->m_mmc_reg[7] = 1;
5593         if (state->m_mmc_reg[6])
5594            state->m_mmc_reg[1] = state->m_mmc_reg[6];
5595         break;
5596
5597      case 0x28:
5598         state->m_mmc_reg[7] = 0;
5599         state->m_mmc_reg[2] = state->m_mmc_reg[6];
5600         break;
5601
5602      case 0x2a:
5603         state->m_mmc_reg[7] = 0;
5604         state->m_mmc_reg[3] = state->m_mmc_reg[6];
5605         break;
5606
5607      case 0x2f:
5608         break;
5609
5610      default:
5611         state->m_mmc_reg[5] = 0;
5612         break;
5613   }
5614}
5615
5616static void kay_pp_prg_cb( running_machine &machine, int start, int bank )
5617{
5618   nes_state *state = machine.driver_data<nes_state>();
5619
5620   if (state->m_mmc_reg[5] & 0x3f)
5621   {
5622      prg8_x(machine, start, bank & 0x3f);
5623      prg8_ef(machine, state->m_mmc_reg[1]);
5624      prg8_cd(machine, state->m_mmc_reg[2]);
5625      prg8_ab(machine, state->m_mmc_reg[3]);
5626   }
5627   else
5628      prg8_x(machine, start, bank & 0x3f);
5629}
5630
5631static void kay_pp_chr_cb( running_machine &machine, int start, int bank, int source )
5632{
5633   nes_state *state = machine.driver_data<nes_state>();
5634   UINT8 chr_page = (state->m_mmc3_latch & 0x80) >> 5;
5635
5636   if ((start & 0x04) == chr_page)
5637      bank |= 0x100;
5638
5639   chr1_x(machine, start, bank, source);
5640}
5641
5642static WRITE8_HANDLER( kay_pp_w )
5643{
5644   nes_state *state = space->machine().driver_data<nes_state>();
5645   LOG_MMC(("kay_pp_w, offset: %04x, data: %02x\n", offset, data));
5646
5647   switch (offset & 0x6003)
5648   {
5649      case 0x0000:
5650         txrom_w(space, offset, data);
5651         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
5652         break;
5653
5654      case 0x0001:
5655         state->m_mmc_reg[6] = (BIT(data, 0) << 5) | (BIT(data, 1) << 4) | (BIT(data, 2) << 3)
5656                        | (BIT(data, 3) << 2) | (BIT(data, 4) << 1) | BIT(data, 5);
5657         if (!state->m_mmc_reg[7])
5658            kay_pp_update_regs(space->machine());
5659         txrom_w(space, offset, data);
5660         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
5661         break;
5662
5663      case 0x0003:
5664         state->m_mmc_reg[5] = data;
5665         kay_pp_update_regs(space->machine());
5666         txrom_w(space, 0x0000, data);
5667         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
5668         break;
5669
5670      default:
5671         txrom_w(space, offset, data);
5672         break;
5673   }
5674}
5675
5676/*************************************************************
5677
5678 Bootleg Board by Kasing
5679
5680 Games: AV Jiu Ji Mahjong, Bao Qing Tian, Thunderbolt 2,
5681 Shisen Mahjong 2
5682
5683 MMC3 clone
5684
5685 iNES: mapper 115
5686
5687 In MESS: Supported
5688
5689 *************************************************************/
5690
5691static void kasing_prg_cb( running_machine &machine, int start, int bank )
5692{
5693   nes_state *state = machine.driver_data<nes_state>();
5694   if (BIT(state->m_mmc_reg[0], 7))
5695      prg32(machine, state->m_mmc_reg[0] >> 1);
5696   else
5697      prg8_x(machine, start, bank);
5698}
5699
5700static WRITE8_HANDLER( kasing_m_w )
5701{
5702   nes_state *state = space->machine().driver_data<nes_state>();
5703   LOG_MMC(("kasing_m_w, offset: %04x, data: %02x\n", offset, data));
5704
5705   switch (offset & 0x01)
5706   {
5707      case 0x00:
5708         state->m_mmc_reg[0] = data;
5709         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
5710         break;
5711      case 0x01:
5712         state->m_mmc_chr_base = (data & 0x01) ? 0x100 : 0x000;
5713         mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
5714         break;
5715   }
5716}
5717
5718/*************************************************************
5719
5720 Bootleg Board by Magic Series
5721
5722 Games: Magic Dragon
5723
5724 Very simple mapper: writes to 0x8000-0xffff set prg32 and chr8
5725 banks
5726
5727 iNES: mapper 107
5728
5729 In MESS: Supported.
5730
5731 *************************************************************/
5732
5733static WRITE8_HANDLER( magics_md_w )
5734{
5735   LOG_MMC(("magics_md_w, offset: %04x, data: %02x\n", offset, data));
5736
5737   prg32(space->machine(), data >> 1);
5738   chr8(space->machine(), data, CHRROM);
5739}
5740
5741/*************************************************************
5742
5743 Bootleg Board by Nanjing
5744
5745 Games: A lot of pirate originals
5746
5747 iNES: mapper 163
5748
5749 In MESS: Unsupported.
5750
5751 *************************************************************/
5752
5753static void nanjing_irq( device_t *device, int scanline, int vblank, int blanked )
5754{
5755   nes_state *state = device->machine().driver_data<nes_state>();
5756
5757   if (BIT(state->m_mmc_reg[0], 7))
5758   {
5759      if (scanline == 127)
5760      {
5761         chr4_0(device->machine(), 1, CHRRAM);
5762         chr4_4(device->machine(), 1, CHRRAM);
5763      }
5764
5765      if (scanline == 239)
5766      {
5767         chr4_0(device->machine(), 0, CHRRAM);
5768         chr4_4(device->machine(), 0, CHRRAM);
5769      }
5770   }
5771
5772}
5773
5774static WRITE8_HANDLER( nanjing_l_w )
5775{
5776   nes_state *state = space->machine().driver_data<nes_state>();
5777   LOG_MMC(("nanjing_l_w, offset: %04x, data: %02x\n", offset, data));
5778
5779   offset += 0x100;
5780
5781   if (offset < 0x1000)
5782      return;
5783
5784   if (offset == 0x1100)   // 0x5100
5785   {
5786      if (data == 6)
5787         prg32(space->machine(), 3);
5788      return;
5789   }
5790
5791   if (offset == 0x1101)   // 0x5101
5792   {
5793      UINT8 temp = state->m_mmc_count;
5794      state->m_mmc_count = data;
5795
5796      if (temp & !data)
5797         state->m_mmc_latch2 ^= 0xff;
5798   }
5799
5800   switch (offset & 0x300)
5801   {
5802      case 0x000:
5803      case 0x200:
5804         state->m_mmc_reg[BIT(offset, 9)] = data;
5805         if (!BIT(state->m_mmc_reg[0], 7) && ppu2c0x_get_current_scanline(state->m_ppu) <= 127)
5806            chr8(space->machine(), 0, CHRRAM);
5807         break;
5808      case 0x300:
5809         state->m_mmc_latch1 = data;
5810         break;
5811   }
5812
5813   prg32(space->machine(), (state->m_mmc_reg[0] & 0x0f) | ((state->m_mmc_reg[1] & 0x0f) << 4));
5814}
5815
5816static READ8_HANDLER( nanjing_l_r )
5817{
5818   nes_state *state = space->machine().driver_data<nes_state>();
5819   UINT8 value = 0;
5820   LOG_MMC(("nanjing_l_r, offset: %04x\n", offset));
5821
5822   offset += 0x100;
5823
5824   if (offset < 0x1000)
5825      return 0;
5826
5827   switch (offset & 0x700)
5828   {
5829      case 0x100:
5830         value = state->m_mmc_latch1;
5831         break;
5832      case 0x500:
5833         value = state->m_mmc_latch2 & state->m_mmc_latch1;
5834         break;
5835      case 0x000:
5836      case 0x200:
5837      case 0x300:
5838      case 0x400:
5839      case 0x600:
5840      case 0x700:
5841         value = 4;
5842         break;
5843   }
5844   return value;
5845}
5846
5847/*************************************************************
5848
5849 Bootleg Board by Nitra
5850
5851 Games: Time Diver Avenger
5852
5853 This acts basically like a MMC3 with different use of write
5854 address.
5855
5856 iNES: mapper 250
5857
5858 In MESS: Supported.
5859
5860 *************************************************************/
5861
5862static WRITE8_HANDLER( nitra_w )
5863{
5864   LOG_MMC(("nitra_w, offset: %04x, data: %02x\n", offset, data));
5865
5866   txrom_w(space, (offset & 0x6000) | ((offset & 0x400) >> 10), offset & 0xff);
5867}
5868
5869/*************************************************************
5870
5871 NTDEC ASDER Bootleg Board
5872
5873 Games: Cobra Mission, Fighting Hero III, Huang Di, Master
5874 Shooter
5875
5876 iNES: mapper 112
5877
5878 In MESS: Supported.
5879
5880 *************************************************************/
5881
5882static WRITE8_HANDLER( ntdec_asder_w )
5883{
5884   nes_state *state = space->machine().driver_data<nes_state>();
5885   LOG_MMC(("ntdec_asder_w, offset: %04x, data: %02x\n", offset, data));
5886
5887   switch (offset)
5888   {
5889      case 0x0000:
5890         state->m_mmc_latch1 = data & 0x07;
5891         break;
5892      case 0x2000:
5893         switch (state->m_mmc_latch1)
5894      {
5895         case 0:
5896            prg8_89(space->machine(), data);
5897            break;
5898         case 1:
5899            prg8_ab(space->machine(), data);
5900            break;
5901         case 2:
5902            data &= 0xfe;
5903            chr1_0(space->machine(), data, CHRROM);
5904            chr1_1(space->machine(), data + 1, CHRROM);
5905            break;
5906         case 3:
5907            data &= 0xfe;
5908            chr1_2(space->machine(), data, CHRROM);
5909            chr1_3(space->machine(), data + 1, CHRROM);
5910            break;
5911         case 4:
5912            chr1_4(space->machine(), data, CHRROM);
5913            break;
5914         case 5:
5915            chr1_5(space->machine(), data, CHRROM);
5916            break;
5917         case 6:
5918            chr1_6(space->machine(), data, CHRROM);
5919            break;
5920         case 7:
5921            chr1_7(space->machine(), data, CHRROM);
5922            break;
5923      }
5924         break;
5925      case 0x6000:
5926         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5927         break;
5928   }
5929}
5930
5931/*************************************************************
5932
5933 Bootleg Board by NTDEC for Fighting Hero
5934
5935 Games: Fighting Hero
5936
5937 Very simple mapper: writes to 0x6000-0x7fff swap PRG and
5938 CHR banks.
5939
5940 iNES: mapper 193
5941
5942 In MESS: Supported.
5943
5944 *************************************************************/
5945
5946static WRITE8_HANDLER( ntdec_fh_m_w )
5947{
5948   LOG_MMC(("ntdec_fh_m_w, offset: %04x, data: %02x\n", offset, data));
5949
5950   switch (offset & 0x03)
5951   {
5952      case 0:
5953         chr4_0(space->machine(), data >> 2, CHRROM);
5954         break;
5955      case 1:
5956         chr2_4(space->machine(), data >> 1, CHRROM);
5957         break;
5958      case 2:
5959         chr2_6(space->machine(), data >> 1 , CHRROM);
5960         break;
5961      case 3:
5962         prg8_89(space->machine(), data);
5963         break;
5964   }
5965}
5966
5967/*************************************************************
5968
5969 Open Corp DAOU306 board
5970
5971 Games: Metal Force (K)
5972
5973 iNES: mapper 156
5974
5975 In MESS: Supported.
5976
5977 *************************************************************/
5978
5979static WRITE8_HANDLER( daou306_w )
5980{
5981   LOG_MMC(("daou306_w, offset: %04x, data: %02x\n", offset, data));
5982
5983   switch (offset)
5984   {
5985      case 0x4000:
5986         chr1_0(space->machine(), data, CHRROM);
5987         break;
5988      case 0x4001:
5989         chr1_1(space->machine(), data, CHRROM);
5990         break;
5991      case 0x4002:
5992         chr1_2(space->machine(), data, CHRROM);
5993         break;
5994      case 0x4003:
5995         chr1_3(space->machine(), data, CHRROM);
5996         break;
5997      case 0x4008:
5998         chr1_4(space->machine(), data, CHRROM);
5999         break;
6000      case 0x4009:
6001         chr1_5(space->machine(), data, CHRROM);
6002         break;
6003      case 0x400a:
6004         chr1_6(space->machine(), data, CHRROM);
6005         break;
6006      case 0x400b:
6007         chr1_7(space->machine(), data, CHRROM);
6008         break;
6009      case 0x4010:
6010         prg16_89ab(space->machine(), data);
6011         break;
6012   }
6013}
6014
6015/*************************************************************
6016
6017 RCM GS2015 Board
6018
6019 Games: Bonza, Magic Jewelry 2
6020
6021 Very simple mapper: writes to 0x8000-0xffff sets prg32
6022 to offset and chr8 to offset>>1 (when chrrom is present)
6023
6024 iNES: mapper 216
6025
6026 In MESS: Supported.
6027
6028 *************************************************************/
6029
6030static WRITE8_HANDLER( gs2015_w )
6031{
6032   nes_state *state = space->machine().driver_data<nes_state>();
6033   LOG_MMC(("gs2015_w, offset: %04x, data: %02x\n", offset, data));
6034
6035   prg32(space->machine(), offset);
6036   chr8(space->machine(), offset >> 1, state->m_mmc_chr_source);
6037}
6038
6039/*************************************************************
6040
6041 Bootleg Board by RCM for Tetris Family
6042
6043 Games: Tetris Family 9 in 1, 20 in 1
6044
6045 Simple Mapper: prg/chr/nt are swapped depending on the offset
6046 of writes in 0x8000-0xffff. offset&0x80 set NT mirroring,
6047 when (offset&0x30) is 0,3 prg32 is set; when it is 1,2
6048 two 16k prg banks are set. See below for the values used in
6049 these banks.
6050
6051 iNES: mapper 61
6052
6053 In MESS: Supported.
6054
6055 *************************************************************/
6056
6057static WRITE8_HANDLER( rcm_tf_w )
6058{
6059   LOG_MMC(("rcm_tf_w, offset: %04x, data: %02x\n", offset, data));
6060
6061   switch (offset & 0x30)
6062   {
6063      case 0x00:
6064      case 0x30:
6065         prg32(space->machine(), offset & 0x0f);
6066         break;
6067      case 0x10:
6068      case 0x20:
6069         prg16_89ab(space->machine(), ((offset & 0x0f) << 1) | ((offset & 0x20) >> 4));
6070         prg16_cdef(space->machine(), ((offset & 0x0f) << 1) | ((offset & 0x20) >> 4));
6071         break;
6072   }
6073   set_nt_mirroring(space->machine(), BIT(data, 7) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
6074}
6075
6076/*************************************************************
6077
6078 Bootleg Board by Rex Soft
6079
6080 Games: Dragon Ball Z 5, Dragon Ball Z Super
6081
6082 MMC3 clone
6083
6084 iNES: mapper 12
6085
6086 In MESS: Supported
6087
6088 *************************************************************/
6089
6090static WRITE8_HANDLER( rex_dbz_l_w )
6091{
6092   nes_state *state = space->machine().driver_data<nes_state>();
6093   LOG_MMC(("rex_dbz_l_w, offset: %04x, data: %02x\n", offset, data));
6094
6095   state->m_mmc_reg[0] = data;
6096   mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6097}
6098
6099/* we would need to use this read handler in 0x6000-0x7fff as well */
6100static READ8_HANDLER( rex_dbz_l_r )
6101{
6102   LOG_MMC(("rex_dbz_l_r, offset: %04x\n", offset));
6103   return 0x01;
6104}
6105
6106static void rex_dbz_chr_cb( running_machine &machine, int start, int bank, int source )
6107{
6108   nes_state *state = machine.driver_data<nes_state>();
6109   int shift = (start < 4) ? 8 : 4;
6110
6111   bank |= ((state->m_mmc_reg[0] << shift) & 0x100);
6112   chr1_x(machine, start, bank, source);
6113}
6114
6115/*************************************************************
6116
6117 Rex Soft SL1632 Board
6118
6119 Games: Samurai Spirits
6120
6121 MMC3 clone
6122
6123 iNES: mapper 14
6124
6125 In MESS: Supported
6126
6127 *************************************************************/
6128
6129static void rex_sl1632_set_prg( running_machine &machine, int prg_base, int prg_mask )
6130{
6131   nes_state *state = machine.driver_data<nes_state>();
6132
6133   if (state->m_mmc_reg[0] & 0x02)
6134   {
6135      mmc3_set_prg(machine, prg_base, prg_mask);
6136   }
6137   else
6138   {
6139      prg8_89(machine, state->m_mmc_extra_bank[0]);
6140      prg8_ab(machine, state->m_mmc_extra_bank[1]);
6141      prg8_cd(machine, state->m_mmc_extra_bank[2]);
6142      prg8_ef(machine, state->m_mmc_extra_bank[3]);
6143   }
6144}
6145
6146static void rex_sl1632_set_chr( running_machine &machine, UINT8 chr, int chr_base, int chr_mask )
6147{
6148   nes_state *state = machine.driver_data<nes_state>();
6149   static const UINT8 conv_table[8] = {5, 5, 5, 5, 3, 3, 1, 1};
6150   UINT8 chr_page = (state->m_mmc3_latch & 0x80) >> 5;
6151   UINT8 bank[8];
6152   UINT8 chr_base2[8];
6153   int i;
6154
6155   if (state->m_mmc_reg[0] & 0x02)
6156   {
6157      for(i = 0; i < 8; i++)
6158      {
6159         bank[i] = state->m_mmc_vrom_bank[i];
6160         chr_base2[i] = chr_base | ((state->m_mmc_reg[0] << conv_table[i]) & 0x100);
6161      }
6162   }
6163   else
6164   {
6165      for(i = 0; i < 8; i++)
6166      {
6167         bank[i] = state->m_mmc_extra_bank[i + 4];   // first 4 state->m_mmc_extra_banks are PRG
6168         chr_base2[i] = chr_base;
6169      }
6170   }
6171
6172   chr1_x(machine, chr_page ^ 0, chr_base2[0] | (bank[0] & chr_mask), chr);
6173   chr1_x(machine, chr_page ^ 1, chr_base2[1] | (bank[1] & chr_mask), chr);
6174   chr1_x(machine, chr_page ^ 2, chr_base2[2] | (bank[2] & chr_mask), chr);
6175   chr1_x(machine, chr_page ^ 3, chr_base2[3] | (bank[3] & chr_mask), chr);
6176   chr1_x(machine, chr_page ^ 4, chr_base2[4] | (bank[4] & chr_mask), chr);
6177   chr1_x(machine, chr_page ^ 5, chr_base2[5] | (bank[5] & chr_mask), chr);
6178   chr1_x(machine, chr_page ^ 6, chr_base2[6] | (bank[6] & chr_mask), chr);
6179   chr1_x(machine, chr_page ^ 7, chr_base2[7] | (bank[7] & chr_mask), chr);
6180}
6181
6182static WRITE8_HANDLER( rex_sl1632_w )
6183{
6184   nes_state *state = space->machine().driver_data<nes_state>();
6185   UINT8 map14_helper1, map14_helper2, mmc_helper, cmd;
6186   LOG_MMC(("rex_sl1632_w, offset: %04x, data: %02x\n", offset, data));
6187
6188   if (offset == 0x2131)
6189   {
6190      state->m_mmc_reg[0] = data;
6191      rex_sl1632_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
6192      rex_sl1632_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6193
6194      if (!(state->m_mmc_reg[0] & 0x02))
6195         set_nt_mirroring(space->machine(), BIT(state->m_mmc_reg[1], 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
6196   }
6197
6198   if (state->m_mmc_reg[0] & 0x02)
6199   {
6200      switch (offset & 0x6001)
6201      {
6202         case 0x0000:
6203            mmc_helper = state->m_mmc3_latch ^ data;
6204            state->m_mmc3_latch = data;
6205
6206            /* Has PRG Mode changed? */
6207            if (mmc_helper & 0x40)
6208               rex_sl1632_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
6209
6210            /* Has CHR Mode changed? */
6211            if (mmc_helper & 0x80)
6212               rex_sl1632_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6213            break;
6214
6215         case 0x0001:
6216            cmd = state->m_mmc3_latch & 0x07;
6217            switch (cmd)
6218            {
6219            case 0: case 1:   // these have to be changed due to the different way rex_sl1632_set_chr works (it handles 1k banks)!
6220               state->m_mmc_vrom_bank[2 * cmd] = data;
6221               state->m_mmc_vrom_bank[2 * cmd + 1] = data;
6222               rex_sl1632_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6223               break;
6224            case 2: case 3: case 4: case 5:
6225               state->m_mmc_vrom_bank[cmd + 2] = data;
6226               rex_sl1632_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6227               break;
6228            case 6:
6229            case 7:
6230               state->m_mmc_prg_bank[cmd - 6] = data;
6231               rex_sl1632_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
6232               break;
6233            }
6234            break;
6235
6236         case 0x2000:
6237            set_nt_mirroring(space->machine(), BIT(state->m_mmc_reg[1], 0) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
6238            break;
6239
6240         default:
6241            txrom_w(space, offset, data);
6242            break;
6243      }
6244   }
6245   else if (offset >= 0x3000 && offset <= 0x6003 )
6246   {
6247      map14_helper1 = (offset & 0x01) << 2;
6248      offset = ((offset & 0x02) | (offset >> 10)) >> 1;
6249      map14_helper2 = ((offset + 2) & 0x07) + 4; // '+4' because first 4 state->m_mmc_extra_banks are for PRG!
6250      state->m_mmc_extra_bank[map14_helper2] = (state->m_mmc_extra_bank[map14_helper2] & (0xf0 >> map14_helper1)) | ((data & 0x0f) << map14_helper1);
6251      rex_sl1632_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6252   }
6253   else
6254   {
6255      switch (offset & 0x7003)
6256      {
6257         case 0x0000:
6258         case 0x2000:
6259            state->m_mmc_extra_bank[offset >> 13] = data;
6260            rex_sl1632_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
6261            break;
6262
6263         case 0x1000:
6264            state->m_mmc_reg[1] = data;
6265            set_nt_mirroring(space->machine(), BIT(state->m_mmc_reg[1], 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
6266            break;
6267      }
6268   }
6269}
6270
6271/*************************************************************
6272
6273 Rumblestation Board
6274
6275 Games: Rumblestation 15 in 1
6276
6277 iNES: mapper 46
6278
6279 In MESS: Supported.
6280
6281 *************************************************************/
6282
6283static WRITE8_HANDLER( rumblestation_m_w )
6284{
6285   nes_state *state = space->machine().driver_data<nes_state>();
6286   LOG_MMC(("rumblestation_m_w, offset: %04x, data: %02x\n", offset, data));
6287
6288   state->m_mmc_prg_bank[0] = (state->m_mmc_prg_bank[0] & 0x01) | ((data & 0x0f) << 1);
6289   state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & 0x07) | ((data & 0xf0) >> 1);
6290   prg32(space->machine(), state->m_mmc_prg_bank[0]);
6291   chr8(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
6292}
6293
6294static WRITE8_HANDLER( rumblestation_w )
6295{
6296   nes_state *state = space->machine().driver_data<nes_state>();
6297   LOG_MMC(("rumblestation_w, offset: %04x, data: %02x\n", offset, data));
6298
6299   state->m_mmc_prg_bank[0] = (state->m_mmc_prg_bank[0] & ~0x01) | (data & 0x01);
6300   state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & ~0x07) | ((data & 0x70) >> 4);
6301   prg32(space->machine(), state->m_mmc_prg_bank[0]);
6302   chr8(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
6303}
6304
6305/*************************************************************
6306
6307 Sachen 74x374 bootleg boards
6308
6309 Games: Chess Academy, Chinese Checkers Jpn, Mahjong Academy,
6310 Olympic IQ, Poker II, Tasac [150], Poker III [243]
6311
6312 iNES: mappers 150 & 243
6313
6314 *************************************************************/
6315
6316static void sachen_set_mirror( running_machine &machine, UINT8 nt ) // used by mappers 137, 138, 139, 141
6317{
6318   switch (nt)
6319   {
6320      case 0:
6321      case 1:
6322         set_nt_mirroring(machine, nt ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
6323         break;
6324      case 2:
6325         set_nt_page(machine, 0, CIRAM, 0, 1);
6326         set_nt_page(machine, 1, CIRAM, 1, 1);
6327         set_nt_page(machine, 2, CIRAM, 1, 1);
6328         set_nt_page(machine, 3, CIRAM, 1, 1);
6329         break;
6330      case 3:
6331         set_nt_mirroring(machine, PPU_MIRROR_LOW);
6332         break;
6333      default:
6334         LOG_MMC(("Mapper set NT to invalid value %02x", nt));
6335         break;
6336   }
6337}
6338
6339static WRITE8_HANDLER( sachen_74x374_l_w )
6340{
6341   nes_state *state = space->machine().driver_data<nes_state>();
6342   LOG_MMC(("sachen_74x374_l_w, offset: %04x, data: %02x\n", offset, data));
6343
6344   /* write happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
6345   if (!(offset & 0x100))
6346   {
6347      if (!(offset & 0x01))
6348         state->m_mmc_latch1 = data & 0x07;
6349      else
6350      {
6351         switch (state->m_mmc_latch1)
6352         {
6353            case 0x02:
6354               state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & ~0x08) | ((data << 3) & 0x08);
6355               chr8(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
6356               prg32(space->machine(), data & 0x01);
6357               break;
6358            case 0x04:
6359               state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & ~0x04) | ((data << 2) & 0x04);
6360               chr8(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
6361               break;
6362            case 0x05:
6363               prg32(space->machine(), data & 0x07);
6364               break;
6365            case 0x06:
6366               state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & ~0x03) | ((data << 0) & 0x03);
6367               chr8(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
6368               break;
6369            case 0x07:
6370               sachen_set_mirror(space->machine(), (data >> 1) & 0x03);
6371               break;
6372            default:
6373               break;
6374         }
6375      }
6376   }
6377}
6378
6379static READ8_HANDLER( sachen_74x374_l_r )
6380{
6381   nes_state *state = space->machine().driver_data<nes_state>();
6382   LOG_MMC(("sachen_74x374_l_r, offset: %04x", offset));
6383
6384   /* read  happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
6385   if (!(offset & 0x100))
6386      return (~state->m_mmc_latch1 & 0x3f) /* ^ dips*/;   // we would need to check the Dips here
6387   else
6388      return 0;
6389}
6390
6391static WRITE8_HANDLER( sachen_74x374a_l_w )
6392{
6393   nes_state *state = space->machine().driver_data<nes_state>();
6394   LOG_MMC(("sachen_74x374a_l_w, offset: %04x, data: %02x\n", offset, data));
6395
6396   /* write happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
6397   if (!(offset & 0x100))
6398   {
6399      if (!(offset & 0x01))
6400         state->m_mmc_latch1 = data;
6401      else
6402      {
6403         switch (state->m_mmc_latch1 & 0x07)
6404         {
6405            case 0x00:
6406               prg32(space->machine(), 0);
6407               chr8(space->machine(), 3, CHRROM);
6408               break;
6409            case 0x02:
6410               state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & ~0x08) | ((data << 3) & 0x08);
6411               chr8(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
6412               break;
6413            case 0x04:
6414               state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & ~0x01) | ((data << 0) & 0x01);
6415               chr8(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
6416               break;
6417            case 0x05:
6418               prg32(space->machine(), data & 0x01);
6419               break;
6420            case 0x06:
6421               state->m_mmc_vrom_bank[0] = (state->m_mmc_vrom_bank[0] & ~0x06) | ((data << 1) & 0x06);
6422               chr8(space->machine(), state->m_mmc_vrom_bank[0], CHRROM);
6423               break;
6424            case 0x07:
6425               sachen_set_mirror(space->machine(), BIT(data, 0));
6426               break;
6427            default:
6428               break;
6429         }
6430      }
6431   }
6432}
6433
6434/*************************************************************
6435
6436 Sachen S8259 bootleg boards
6437
6438 iNES: mapper 141 (A), 138 (B), 139 (C), 137 (D)
6439
6440 *************************************************************/
6441
6442static void common_s8259_write_handler( address_space *space, offs_t offset, UINT8 data, int board )
6443{
6444   nes_state *state = space->machine().driver_data<nes_state>();
6445   UINT8 bank_helper1, bank_helper2, shift, add1, add2, add3;
6446
6447   /* write happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
6448   if (!(offset & 0x100))
6449   {
6450      if (!(offset & 0x01))
6451         state->m_mmc_latch1 = data & 0x07;
6452      else
6453      {
6454         state->m_sachen_reg[state->m_mmc_latch1] = data;
6455
6456         switch (state->m_mmc_latch1)
6457         {
6458            case 0x05:
6459               prg32(space->machine(), data);
6460               break;
6461            case 0x07:
6462               sachen_set_mirror(space->machine(), BIT(data, 0) ? 0 : (data >> 1) & 0x03);
6463               break;
6464            default:
6465               if (board == SACHEN_8259D)
6466               {
6467                  if (state->m_mmc_chr_source == CHRROM)
6468                  {
6469                     chr1_0(space->machine(), (state->m_sachen_reg[0] & 0x07), CHRROM);
6470                     chr1_1(space->machine(), (state->m_sachen_reg[1] & 0x07) | (state->m_sachen_reg[4] << 4 & 0x10), CHRROM);
6471                     chr1_2(space->machine(), (state->m_sachen_reg[2] & 0x07) | (state->m_sachen_reg[4] << 3 & 0x10), CHRROM);
6472                     chr1_3(space->machine(), (state->m_sachen_reg[3] & 0x07) | (state->m_sachen_reg[4] << 2 & 0x10) | (state->m_sachen_reg[6] << 3 & 0x08), CHRROM);
6473                  }
6474               }
6475               else
6476               {
6477                  bank_helper1 = state->m_sachen_reg[7] & 0x01;
6478                  bank_helper2 = (state->m_sachen_reg[4] & 0x07) << 3;
6479                  shift = (board == SACHEN_8259A) ? 1 : (board == SACHEN_8259C) ? 2 : 0;
6480                  add1 = (board == SACHEN_8259B) ? 0 : 1;
6481                  add2 = (board == SACHEN_8259C) ? 2 : 0;
6482                  add3 = (board == SACHEN_8259A) ? 1 : (board == SACHEN_8259C) ? 3 : 0;
6483
6484                  if (state->m_mmc_chr_source == CHRROM)
6485                  {
6486                     chr2_0(space->machine(), ((state->m_sachen_reg[bank_helper1 ? 0 : 0] & 0x07) | bank_helper2) << shift, CHRROM);
6487                     chr2_2(space->machine(), ((state->m_sachen_reg[bank_helper1 ? 0 : 1] & 0x07) | bank_helper2) << shift | add1, CHRROM);
6488                     chr2_4(space->machine(), ((state->m_sachen_reg[bank_helper1 ? 0 : 2] & 0x07) | bank_helper2) << shift | add2, CHRROM);
6489                     chr2_6(space->machine(), ((state->m_sachen_reg[bank_helper1 ? 0 : 3] & 0x07) | bank_helper2) << shift | add3, CHRROM);
6490                  }
6491               }
6492               break;
6493         }
6494      }
6495   }
6496}
6497
6498static WRITE8_HANDLER( s8259_l_w )
6499{
6500   nes_state *state = space->machine().driver_data<nes_state>();
6501   LOG_MMC(("s8259_w, type: %d, offset: %04x, data: %02x\n", state->m_pcb_id, offset, data));
6502
6503   common_s8259_write_handler(space, offset, data, state->m_pcb_id);
6504}
6505
6506static WRITE8_HANDLER( s8259_m_w )
6507{
6508   nes_state *state = space->machine().driver_data<nes_state>();
6509   LOG_MMC(("s8259_w, type: %d, offset: %04x, data: %02x\n", state->m_pcb_id, offset, data));
6510
6511   common_s8259_write_handler(space, (offset + 0x100) & 0xfff, data, state->m_pcb_id);
6512}
6513
6514
6515/*************************************************************
6516
6517 Sachen SA009 bootleg boards
6518
6519 Games: Pipe 5
6520
6521 iNES: mapper 160
6522
6523 In MESS: Supported.
6524
6525 *************************************************************/
6526
6527static WRITE8_HANDLER( sa009_l_w )
6528{
6529   nes_state *state = space->machine().driver_data<nes_state>();
6530   LOG_MMC(("sa009_l_w, offset: %04x, data: %02x\n", offset, data));
6531
6532   chr8(space->machine(), data, state->m_mmc_chr_source);
6533}
6534
6535/*************************************************************
6536
6537 Sachen SA0036 bootleg boards
6538
6539 Games: Taiwan Mahjong 16
6540
6541 iNES: mapper 149
6542
6543 In MESS: Supported.
6544
6545 *************************************************************/
6546
6547static WRITE8_HANDLER( sa0036_w )
6548{
6549   LOG_MMC(("sa0036_w, offset: %04x, data: %02x\n", offset, data));
6550
6551   chr8(space->machine(), data >> 7, CHRROM);
6552}
6553
6554/*************************************************************
6555
6556 Sachen SA0037 bootleg boards
6557
6558 Games: Mahjong World, Shisen Mahjong
6559
6560 iNES: mapper 148
6561
6562 In MESS: Supported.
6563
6564 *************************************************************/
6565
6566static WRITE8_HANDLER( sa0037_w )
6567{
6568   LOG_MMC(("sa0037_w, offset: %04x, data: %02x\n", offset, data));
6569
6570   prg32(space->machine(), data >> 3);
6571   chr8(space->machine(), data, CHRROM);
6572}
6573
6574/*************************************************************
6575
6576 Sachen SA72007 bootleg boards
6577
6578 Games: Sidewinder
6579
6580 iNES: mapper 145
6581
6582 In MESS: Supported.
6583
6584 *************************************************************/
6585
6586static WRITE8_HANDLER( sa72007_l_w )
6587{
6588   LOG_MMC(("sa72007_l_w, offset: %04x, data: %02x\n", offset, data));
6589
6590   /* only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
6591   if (!(offset & 0x100))
6592      chr8(space->machine(), data >> 7, CHRROM);
6593}
6594
6595/*************************************************************
6596
6597 Sachen SA72008 bootleg boards
6598
6599 Games: Jovial Race, Qi Wang
6600
6601 iNES: mapper 133
6602
6603 In MESS: Supported.
6604
6605 *************************************************************/
6606
6607static WRITE8_HANDLER( sa72008_l_w )
6608{
6609   LOG_MMC(("sa72008_l_w, offset: %04x, data: %02x\n", offset, data));
6610
6611   prg32(space->machine(), data >> 2);
6612   chr8(space->machine(), data, CHRROM);
6613}
6614
6615/*************************************************************
6616
6617 Sachen TCA-01 bootleg boards
6618
6619 iNES: mapper 143
6620
6621 Games: Dancing Blocks, Magic Mathematic
6622
6623 In MESS: Supported.
6624
6625 *************************************************************/
6626
6627static READ8_HANDLER( tca01_l_r )
6628{
6629   LOG_MMC(("tca01_l_r, offset: %04x\n", offset));
6630
6631   /* the address is read only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
6632   if (!(offset & 0x100))
6633      return (~offset & 0x3f) | 0x40;
6634   else
6635      return 0x00;
6636}
6637
6638/*************************************************************
6639
6640 Sachen TCU-01 bootleg boards
6641
6642 Games: Challenge of the Dragon, Chinese Kungfu
6643
6644 iNES: mapper 147
6645
6646 In MESS: Supported.
6647
6648 *************************************************************/
6649
6650static WRITE8_HANDLER( tcu01_l_w )
6651{
6652   LOG_MMC(("tcu01_l_w, offset: %04x, data: %02x\n", offset, data));
6653
6654   if ((offset & 0x103) == 0x002)
6655   {
6656      prg32(space->machine(), ((data >> 6) & 0x02) | ((data >> 2) & 0x01));
6657      chr8(space->machine(), data >> 3, CHRROM);
6658   }
6659}
6660
6661static WRITE8_HANDLER( tcu01_m_w )
6662{
6663   LOG_MMC(("tcu01_m_w, offset: %04x, data: %02x\n", offset, data));
6664
6665   tcu01_l_w(space, (offset + 0x100) & 0xfff, data);
6666}
6667
6668static WRITE8_HANDLER( tcu01_w )
6669{
6670   LOG_MMC(("tcu01_w, offset: %04x, data: %02x\n", offset, data));
6671
6672   tcu01_l_w(space, (offset + 0x100) & 0xfff, data);
6673}
6674
6675/*************************************************************
6676
6677 Sachen TCU-02 bootleg boards
6678
6679 Games: Mei Loi Siu Ji
6680
6681 iNES: mapper 136
6682
6683 In MESS: Supported.
6684
6685 *************************************************************/
6686
6687static WRITE8_HANDLER( tcu02_l_w )
6688{
6689   nes_state *state = space->machine().driver_data<nes_state>();
6690   LOG_MMC(("tcu02_l_w, offset: %04x, data: %02x\n", offset, data));
6691
6692   if ((offset & 0x103) == 0x002)
6693   {
6694      state->m_mmc_latch1 = (data & 0x30) | ((data + 3) & 0x0f);
6695      chr8(space->machine(), state->m_mmc_latch1, CHRROM);
6696   }
6697}
6698
6699static READ8_HANDLER( tcu02_l_r )
6700{
6701   nes_state *state = space->machine().driver_data<nes_state>();
6702   LOG_MMC(("tcu02_l_r, offset: %04x\n", offset));
6703
6704   if ((offset & 0x103) == 0x000)
6705      return state->m_mmc_latch1 | 0x40;
6706   else
6707      return 0x00;
6708}
6709
6710
6711/*************************************************************
6712
6713 Subor bootleg board Type 0
6714
6715 iNES: mapper 167
6716
6717 *************************************************************/
6718
6719static WRITE8_HANDLER( subor0_w )
6720{
6721   nes_state *state = space->machine().driver_data<nes_state>();
6722   UINT8 subor_helper1, subor_helper2;
6723   LOG_MMC(("subor0_w, offset: %04x, data: %02x\n", offset, data));
6724
6725   state->m_subor_reg[(offset >> 13) & 0x03] = data;
6726   subor_helper1 = ((state->m_subor_reg[0] ^ state->m_subor_reg[1]) << 1) & 0x20;
6727   subor_helper2 = ((state->m_subor_reg[2] ^ state->m_subor_reg[3]) << 0) & 0x1f;
6728
6729   if (state->m_subor_reg[1] & 0x08)
6730   {
6731      subor_helper1 += subor_helper2 & 0xfe;
6732      subor_helper2 = subor_helper1;
6733      subor_helper1 += 1;
6734   }
6735   else if (state->m_subor_reg[1] & 0x04)
6736   {
6737      subor_helper2 += subor_helper1;
6738      subor_helper1 = 0x1f;
6739   }
6740   else
6741   {
6742      subor_helper1 += subor_helper2;
6743      subor_helper2 = 0x20;
6744   }
6745
6746   prg16_89ab(space->machine(), subor_helper1);
6747   prg16_cdef(space->machine(), subor_helper2);
6748}
6749
6750/*************************************************************
6751
6752 Subor bootleg board Type 1
6753
6754 iNES: mapper 166
6755
6756 *************************************************************/
6757
6758static WRITE8_HANDLER( subor1_w )
6759{
6760   nes_state *state = space->machine().driver_data<nes_state>();
6761   UINT8 subor_helper1, subor_helper2;
6762   LOG_MMC(("subor1_w, offset: %04x, data: %02x\n", offset, data));
6763
6764   state->m_subor_reg[(offset >> 13) & 0x03] = data;
6765   subor_helper1 = ((state->m_subor_reg[0] ^ state->m_subor_reg[1]) << 1) & 0x20;
6766   subor_helper2 = ((state->m_subor_reg[2] ^ state->m_subor_reg[3]) << 0) & 0x1f;
6767
6768   if (state->m_subor_reg[1] & 0x08)
6769   {
6770      subor_helper1 += subor_helper2 & 0xfe;
6771      subor_helper2 = subor_helper1;
6772      subor_helper2 += 1;
6773   }
6774   else if (state->m_subor_reg[1] & 0x04)
6775   {
6776      subor_helper2 += subor_helper1;
6777      subor_helper1 = 0x1f;
6778   }
6779   else
6780   {
6781      subor_helper1 += subor_helper2;
6782      subor_helper2 = 0x07;
6783   }
6784
6785   prg16_89ab(space->machine(), subor_helper1);
6786   prg16_cdef(space->machine(), subor_helper2);
6787}
6788
6789/*************************************************************
6790
6791 Bootleg Board by Super Game
6792
6793 Games: Boogerman, Mortal Kombat III
6794
6795 MMC3 clone. Also, it probably needs a hack to support both
6796 variants (Boogerman & MK3).
6797
6798 iNES: mapper 215
6799
6800 In MESS: Preliminary support.
6801
6802 *************************************************************/
6803
6804static void sgame_boog_prg_cb( running_machine &machine, int start, int bank )
6805{
6806   nes_state *state = machine.driver_data<nes_state>();
6807   if (!(state->m_mmc_reg[0] & 0x80))   // if this is != 0 we should never even arrive here
6808   {
6809      if (state->m_mmc_reg[1] & 0x08)
6810         bank = (bank & 0x1f) | 0x20;
6811      else
6812         bank = (bank & 0x0f) | (state->m_mmc_reg[1] & 0x10);
6813
6814      prg8_x(machine, start, bank);
6815   }
6816}
6817
6818static void sgame_boog_chr_cb( running_machine &machine, int start, int bank, int source )
6819{
6820   nes_state *state = machine.driver_data<nes_state>();
6821
6822   if ((state->m_mmc_reg[1] & 0x04))
6823      bank |= 0x100;
6824   else
6825      bank = (bank & 0x7f) | ((state->m_mmc_reg[1] & 0x10) << 3);
6826
6827   chr1_x(machine, start, bank, source);
6828}
6829
6830static void sgame_boog_set_prg( running_machine &machine )
6831{
6832   nes_state *state = machine.driver_data<nes_state>();
6833   if (state->m_mmc_reg[0] & 0x80)
6834   {
6835      prg16_89ab(machine, (state->m_mmc_reg[0] & 0xf0) | (state->m_mmc_reg[1] & 0x10));
6836      prg16_cdef(machine, (state->m_mmc_reg[0] & 0xf0) | (state->m_mmc_reg[1] & 0x10));
6837   }
6838   else
6839      mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
6840}
6841
6842static WRITE8_HANDLER( sgame_boog_l_w )
6843{
6844   nes_state *state = space->machine().driver_data<nes_state>();
6845   LOG_MMC(("sgame_boog_l_w, offset: %04x, data: %02x\n", offset, data));
6846   offset += 0x100;
6847
6848   if (offset == 0x1000)
6849   {
6850      state->m_mmc_reg[0] = data;
6851      sgame_boog_set_prg(space->machine());
6852   }
6853   else if (offset == 0x1001)
6854   {
6855      state->m_mmc_reg[1] = data;
6856      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6857   }
6858   else if (offset == 0x1007)
6859   {
6860      state->m_mmc3_latch = 0;
6861      state->m_mmc_reg[2] = data;
6862      sgame_boog_set_prg(space->machine());
6863      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6864   }
6865}
6866
6867static WRITE8_HANDLER( sgame_boog_m_w )
6868{
6869   nes_state *state = space->machine().driver_data<nes_state>();
6870   LOG_MMC(("sgame_boog_m_w, offset: %04x, data: %02x\n", offset, data));
6871
6872   if (offset == 0x0000)
6873   {
6874      state->m_mmc_reg[0] = data;
6875      sgame_boog_set_prg(space->machine());
6876   }
6877   else if (offset == 0x0001)
6878   {
6879      state->m_mmc_reg[1] = data;
6880      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6881   }
6882   else if (offset == 0x0007)
6883   {
6884      state->m_mmc3_latch = 0;
6885      state->m_mmc_reg[2] = data;
6886      sgame_boog_set_prg(space->machine());
6887      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
6888   }
6889}
6890
6891static WRITE8_HANDLER( sgame_boog_w )
6892{
6893   nes_state *state = space->machine().driver_data<nes_state>();
6894   static const UINT8 conv_table[8] = {0,2,5,3,6,1,7,4};
6895   LOG_MMC(("sgame_boog_w, offset: %04x, data: %02x\n", offset, data));
6896
6897   switch (offset & 0x6001)
6898   {
6899      case 0x0000:
6900         if (!state->m_mmc_reg[2])
6901            txrom_w(space, 0x0000, data);
6902         break;
6903
6904      case 0x0001:
6905         if (!state->m_mmc_reg[2])
6906            txrom_w(space, 0x0001, data);
6907         else if (state->m_mmc_reg[3] && ((state->m_mmc_reg[0] & 0x80) == 0 || (state->m_mmc_latch1 & 0x07) < 6))   // if we use the prg16 banks and cmd=6,7 DON'T enter!
6908         {
6909            state->m_mmc_reg[3] = 0;
6910            txrom_w(space, 0x0001, data);
6911         }
6912         break;
6913
6914      case 0x2000:
6915         if (!state->m_mmc_reg[2])
6916            txrom_w(space, 0x2000, data);
6917         else
6918         {
6919            data = (data & 0xc0) | conv_table[data & 0x07];
6920            state->m_mmc_reg[3] = 1;
6921            txrom_w(space, 0x0000, data);
6922            break;
6923         }
6924         break;
6925
6926      case 0x4000:
6927         if (!state->m_mmc_reg[2])
6928            txrom_w(space, 0x4000, data);
6929         else
6930            set_nt_mirroring(space->machine(), ((data >> 7) | data) & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
6931         break;
6932
6933      case 0x4001:
6934         if (!state->m_mmc_reg[2])
6935            txrom_w(space, 0x4001, data);
6936         else
6937            txrom_w(space, 0x6001, data);
6938         break;
6939
6940      case 0x6001:
6941         if (!state->m_mmc_reg[2])
6942            txrom_w(space, 0x6001, data);
6943         else
6944         {
6945            txrom_w(space, 0x4000, data);
6946            txrom_w(space, 0x4001, data);
6947         }
6948         break;
6949
6950      default:
6951         txrom_w(space, offset, data);
6952         break;
6953   }
6954}
6955
6956/*************************************************************
6957
6958 Bootleg Board by Super Game
6959
6960 Games: The Lion King
6961
6962 MMC3 clone.
6963
6964 iNES: mapper 114
6965
6966 In MESS: Supported.
6967
6968 *************************************************************/
6969
6970static WRITE8_HANDLER( sgame_lion_m_w )
6971{
6972   nes_state *state = space->machine().driver_data<nes_state>();
6973   LOG_MMC(("sgame_lion_m_w, offset: %04x, data: %02x\n", offset, data));
6974
6975   state->m_map114_reg = data;
6976
6977   if (state->m_map114_reg & 0x80)
6978   {
6979      prg16_89ab(space->machine(), data & 0x1f);
6980      prg16_cdef(space->machine(), data & 0x1f);
6981   }
6982   else
6983      mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
6984
6985}
6986
6987static WRITE8_HANDLER( sgame_lion_w )
6988{
6989   nes_state *state = space->machine().driver_data<nes_state>();
6990   static const UINT8 conv_table[8] = {0, 3, 1, 5, 6, 7, 2, 4};
6991   LOG_MMC(("sgame_lion_w, offset: %04x, data: %02x\n", offset, data));
6992
6993   if (offset < 0x6000)
6994   {
6995      switch (offset & 0x6000)
6996      {
6997         case 0x0000:
6998            set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
6999            break;
7000         case 0x2000:
7001            state->m_map114_reg_enabled = 1;
7002            data = (data & 0xc0) | conv_table[data & 0x07];
7003            txrom_w(space, 0x0000, data);
7004            break;
7005         case 0x4000:
7006            if (state->m_map114_reg_enabled && (state->m_map114_reg & 0x80) == 0)
7007            {
7008               state->m_map114_reg_enabled = 0;
7009               txrom_w(space, 0x0001, data);
7010            }
7011            break;
7012      }
7013   }
7014   else
7015   {
7016      switch (offset & 0x03)
7017      {
7018         case 0x02:
7019            txrom_w(space, 0x6000, data);
7020            break;
7021         case 0x03:
7022            txrom_w(space, 0x6001, data);
7023            txrom_w(space, 0x4000, data);
7024            txrom_w(space, 0x4001, data);
7025            break;
7026      }
7027   }
7028}
7029
7030/*************************************************************
7031
7032 Tengen 800008 Board
7033
7034 iNES: mapper 3?
7035
7036 In MESS: Supported.
7037
7038 *************************************************************/
7039
7040static WRITE8_HANDLER( tengen_800008_w )
7041{
7042   LOG_MMC(("tengen_800008_w, offset: %04x, data: %02x\n", offset, data));
7043
7044   prg32(space->machine(), data >> 3);
7045   chr8(space->machine(), data, CHRROM);
7046}
7047
7048/*************************************************************
7049
7050 Tengen 800032 Board
7051
7052 Games: Klax, Road Runner, Rolling Thunder, Shinobi, Skulls
7053 & Croosbones, Xybots
7054
7055 iNES: mapper 64
7056
7057 In MESS: Partially Supported.
7058
7059 *************************************************************/
7060
7061static void tengen_800032_irq( device_t *device, int scanline, int vblank, int blanked )
7062{
7063   nes_state *state = device->machine().driver_data<nes_state>();
7064   if (!state->m_IRQ_mode)   // we are in scanline mode!
7065   {
7066      if (scanline < PPU_BOTTOM_VISIBLE_SCANLINE)
7067      {
7068         if (!state->m_IRQ_reset)
7069         {
7070            if (!state->m_IRQ_count)
7071               state->m_IRQ_count = state->m_IRQ_count_latch;
7072            else
7073            {
7074               state->m_IRQ_count--;
7075               if (state->m_IRQ_enable && !blanked && !state->m_IRQ_count)
7076               {
7077                  LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
7078                         device->machine().primary_screen->vpos(), device->machine().primary_screen->hpos()));
7079                  device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
7080               }
7081            }
7082         }
7083         else
7084         {
7085            state->m_IRQ_reset = 0;
7086            state->m_IRQ_count = state->m_IRQ_count_latch + 1;
7087         }
7088      }
7089   }
7090   /* otherwise, we are in CPU cycles mode --> decrement count of 114 every scanline
7091     --> in the meanwhile anything can have happened to IRQ_reset and we would not know
7092     --> Skulls and Crossbones does not show anything!! */
7093   else
7094   {
7095      //      if (!state->m_IRQ_reset)
7096      {
7097         if (state->m_IRQ_count <= 114)
7098            state->m_IRQ_count = state->m_IRQ_count_latch;
7099         else
7100         {
7101            state->m_IRQ_count -= 114;
7102            if (state->m_IRQ_enable && !blanked && (state->m_IRQ_count <= 114))
7103            {
7104               LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
7105                      device->machine().primary_screen->vpos(), device->machine().primary_screen->hpos()));
7106               device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
7107            }
7108         }
7109      }
7110      //      else
7111      //      {
7112      //          state->m_IRQ_reset = 0;
7113      //          state->m_IRQ_count = state->m_IRQ_count_latch + 1;
7114      //      }
7115   }
7116}
7117
7118static void tengen_800032_set_prg( running_machine &machine )
7119{
7120   nes_state *state = machine.driver_data<nes_state>();
7121   UINT8 prg_mode = state->m_mmc_latch1 & 0x40;
7122
7123   prg8_89(machine, state->m_mmc_prg_bank[prg_mode ? 2: 0]);
7124   prg8_ab(machine, state->m_mmc_prg_bank[prg_mode ? 0: 1]);
7125   prg8_cd(machine, state->m_mmc_prg_bank[prg_mode ? 1: 2]);
7126}
7127
7128static void tengen_800032_set_chr( running_machine &machine )
7129{
7130   nes_state *state = machine.driver_data<nes_state>();
7131   UINT8 chr_page = (state->m_mmc_latch1 & 0x80) >> 5;
7132
7133   if (state->m_mmc_latch1 & 0x20)
7134   {
7135      chr1_x(machine, 0 ^ chr_page, state->m_mmc_vrom_bank[0], CHRROM);
7136      chr1_x(machine, 1 ^ chr_page, state->m_mmc_vrom_bank[8], CHRROM);
7137      chr1_x(machine, 2 ^ chr_page, state->m_mmc_vrom_bank[1], CHRROM);
7138      chr1_x(machine, 3 ^ chr_page, state->m_mmc_vrom_bank[9], CHRROM);
7139   }
7140   else
7141   {
7142      chr1_x(machine, 0 ^ chr_page, state->m_mmc_vrom_bank[0] & ~0x01, CHRROM);
7143      chr1_x(machine, 1 ^ chr_page, state->m_mmc_vrom_bank[0] |  0x01, CHRROM);
7144      chr1_x(machine, 2 ^ chr_page, state->m_mmc_vrom_bank[1] & ~0x01, CHRROM);
7145      chr1_x(machine, 3 ^ chr_page, state->m_mmc_vrom_bank[1] |  0x01, CHRROM);
7146   }
7147
7148   chr1_x(machine, 4 ^ chr_page, state->m_mmc_vrom_bank[2], CHRROM);
7149   chr1_x(machine, 5 ^ chr_page, state->m_mmc_vrom_bank[3], CHRROM);
7150   chr1_x(machine, 6 ^ chr_page, state->m_mmc_vrom_bank[4], CHRROM);
7151   chr1_x(machine, 7 ^ chr_page, state->m_mmc_vrom_bank[5], CHRROM);
7152}
7153
7154static WRITE8_HANDLER( tengen_800032_w )
7155{
7156   nes_state *state = space->machine().driver_data<nes_state>();
7157   UINT8 map64_helper, cmd;
7158   LOG_MMC(("tengen_800032_w, offset: %04x, data: %02x\n", offset, data));
7159
7160   switch (offset & 0x6001)
7161   {
7162      case 0x0000:
7163         map64_helper = state->m_mmc_latch1 ^ data;
7164         state->m_mmc_latch1 = data;
7165
7166         /* Has PRG Mode changed? */
7167         if (map64_helper & 0x40)
7168            tengen_800032_set_prg(space->machine());
7169
7170         /* Has CHR Mode changed? */
7171         if (map64_helper & 0xa0)
7172            tengen_800032_set_chr(space->machine());
7173         break;
7174
7175      case 0x0001:
7176         cmd = state->m_mmc_latch1 & 0x0f;
7177         switch (cmd)
7178      {
7179         case 0: case 1:
7180         case 2: case 3:
7181         case 4: case 5:
7182            state->m_mmc_vrom_bank[cmd] = data;
7183            tengen_800032_set_chr(space->machine());
7184            break;
7185         case 6: case 7:
7186            state->m_mmc_prg_bank[cmd - 6] = data;
7187            tengen_800032_set_prg(space->machine());
7188            break;
7189         case 8: case 9:
7190            state->m_mmc_vrom_bank[cmd - 2] = data;
7191            tengen_800032_set_chr(space->machine());
7192            break;
7193         case 0x0f:
7194            state->m_mmc_prg_bank[2] = data;
7195            tengen_800032_set_prg(space->machine());
7196            break;
7197      }
7198         break;
7199
7200      case 0x2000:
7201         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
7202         break;
7203
7204      case 0x4000:
7205         state->m_IRQ_count_latch = data;
7206         break;
7207
7208      case 0x4001: /* $c001 - IRQ scanline latch */
7209         state->m_IRQ_mode = data & 0x01;
7210         state->m_IRQ_reset = 1;
7211         break;
7212
7213      case 0x6000:
7214         state->m_IRQ_enable = 0;
7215         break;
7216
7217      case 0x6001:
7218         state->m_IRQ_enable = 1;
7219         break;
7220
7221      default:
7222         LOG_MMC(("Mapper 64 write. addr: %04x value: %02x\n", offset + 0x8000, data));
7223         break;
7224   }
7225}
7226
7227/*************************************************************
7228
7229 Tengen 800037 Board
7230
7231 Games: Alien Syndrome
7232
7233 iNES: mapper 158
7234
7235 In MESS: Very preliminary support.
7236
7237 *************************************************************/
7238
7239// probably wrong...
7240static void tengen_800037_set_mirror( running_machine &machine )
7241{
7242   nes_state *state = machine.driver_data<nes_state>();
7243   UINT8 nt_mode = state->m_mmc_latch1 & 0x80;
7244
7245   set_nt_page(machine, 0, ROM, state->m_mmc_vrom_bank[nt_mode ? 2 : 0], 0);
7246   set_nt_page(machine, 1, ROM, state->m_mmc_vrom_bank[nt_mode ? 3 : 0], 0);
7247   set_nt_page(machine, 2, ROM, state->m_mmc_vrom_bank[nt_mode ? 4 : 1], 0);
7248   set_nt_page(machine, 3, ROM, state->m_mmc_vrom_bank[nt_mode ? 5 : 1], 0);
7249}
7250
7251static WRITE8_HANDLER( tengen_800037_w )
7252{
7253   nes_state *state = space->machine().driver_data<nes_state>();
7254   UINT8 map158_helper, cmd;
7255   LOG_MMC(("tengen_800037_w, offset: %04x, data: %02x\n", offset, data));
7256
7257   switch (offset & 0x6001)
7258   {
7259      case 0x0000:
7260         map158_helper = state->m_mmc_latch1 ^ data;
7261         state->m_mmc_latch1 = data;
7262
7263         /* Has PRG Mode changed? */
7264         if (map158_helper & 0x40)
7265            tengen_800032_set_prg(space->machine());
7266
7267         /* Has CHR Mode changed? */
7268         if (map158_helper & 0xa0)
7269         {
7270            tengen_800032_set_chr(space->machine());
7271            tengen_800037_set_mirror(space->machine());
7272         }
7273         break;
7274
7275      case 0x0001:
7276         cmd = state->m_mmc_latch1 & 0x0f;
7277         switch (cmd)
7278      {
7279         case 0: case 1:
7280         case 2: case 3:
7281         case 4: case 5:
7282            state->m_mmc_vrom_bank[cmd] = data;
7283            tengen_800032_set_chr(space->machine());
7284            tengen_800037_set_mirror(space->machine());
7285            break;
7286         case 6: case 7:
7287            state->m_mmc_prg_bank[cmd - 6] = data;
7288            tengen_800032_set_prg(space->machine());
7289            break;
7290         case 8: case 9:
7291            state->m_mmc_vrom_bank[cmd - 2] = data;
7292            tengen_800032_set_chr(space->machine());
7293            tengen_800037_set_mirror(space->machine());
7294            break;
7295         case 0x0f:
7296            state->m_mmc_prg_bank[2] = data;
7297            tengen_800032_set_prg(space->machine());
7298            break;
7299      }
7300         break;
7301
7302      case 0x2000:
7303         break;
7304
7305      default:
7306         tengen_800032_w(space, offset, data);
7307         break;
7308   }
7309}
7310
7311/*************************************************************
7312
7313 Bootleg Board 22211 by TXC (Type A)
7314
7315 Games: Creatom
7316
7317 Info from NEStopia: this mapper features write to four
7318 registers (0x4100-0x4103). The third one is used to select
7319 PRG and CHR banks.
7320
7321 iNES: mapper 132
7322
7323 In MESS: Supported.
7324
7325 *************************************************************/
7326
7327static WRITE8_HANDLER( txc_22211_l_w )
7328{
7329   nes_state *state = space->machine().driver_data<nes_state>();
7330   LOG_MMC(("txc_22211_l_w, offset: %04x, data: %02x\n", offset, data));
7331
7332   if (offset < 4)
7333      state->m_txc_reg[offset & 0x03] = data;
7334}
7335
7336static READ8_HANDLER( txc_22211_l_r )
7337{
7338   nes_state *state = space->machine().driver_data<nes_state>();
7339   LOG_MMC(("txc_22211_l_r, offset: %04x\n", offset));
7340
7341   if (offset == 0x0000)
7342      return (state->m_txc_reg[1] ^ state->m_txc_reg[2]) | 0x40;
7343   else
7344      return 0x00;
7345}
7346
7347static WRITE8_HANDLER( txc_22211_w )
7348{
7349   nes_state *state = space->machine().driver_data<nes_state>();
7350   LOG_MMC(("txc_22211_w, offset: %04x, data: %02x\n", offset, data));
7351
7352   prg32(space->machine(), state->m_txc_reg[2] >> 2);
7353   chr8(space->machine(), state->m_txc_reg[2], CHRROM);
7354}
7355
7356/*************************************************************
7357
7358 Bootleg Board 22211 by TXC (Type B)
7359
7360 Games: 1991 Du Ma Racing
7361
7362 This mapper is basically the same as Type A. Only difference is
7363 in the way CHR banks are selected (see below)
7364
7365 iNES: mapper 172
7366
7367 In MESS: Supported.
7368
7369 *************************************************************/
7370
7371static WRITE8_HANDLER( txc_22211b_w )
7372{
7373   nes_state *state = space->machine().driver_data<nes_state>();
7374   LOG_MMC(("txc_22211b_w, offset: %04x, data: %02x\n", offset, data));
7375
7376   prg32(space->machine(), state->m_txc_reg[2] >> 2);
7377   chr8(space->machine(), (((data ^ state->m_txc_reg[2]) >> 3) & 0x02) | (((data ^ state->m_txc_reg[2]) >> 5) & 0x01), CHRROM);
7378}
7379
7380/*************************************************************
7381
7382 Bootleg Board 22211 by TXC (Type C)
7383
7384 Games: Mahjong Block, Xiao Ma Li
7385
7386 This mapper is basically the same as 132 too. Only difference is
7387 in 0x4100 reads which expect also bit 0 to be set
7388
7389 iNES: mapper 172
7390
7391 In MESS: Supported.
7392
7393 *************************************************************/
7394
7395static READ8_HANDLER( txc_22211c_l_r )
7396{
7397   nes_state *state = space->machine().driver_data<nes_state>();
7398   LOG_MMC(("txc_22211c_l_r, offset: %04x\n", offset));
7399
7400   if (offset == 0x0000)
7401      return (state->m_txc_reg[1] ^ state->m_txc_reg[2]) | 0x41;
7402   else
7403      return 0x00;
7404}
7405
7406/*************************************************************
7407
7408 Bootleg Board 'Thunder Warrior' by TXC
7409
7410 Games: Master Fighter II, Master Fighter 3, Thunder Warrior
7411
7412 MMC3 clone
7413
7414 iNES: mapper 189
7415
7416 In MESS: Supported.
7417
7418 *************************************************************/
7419
7420static WRITE8_HANDLER( txc_tw_l_w )
7421{
7422   LOG_MMC(("txctw_l_w, offset: %04x, data: %02x\n", offset, data));
7423
7424   prg32(space->machine(), (data >> 4) | data);
7425}
7426
7427static WRITE8_HANDLER( txc_tw_m_w )
7428{
7429   LOG_MMC(("txctw_m_w, offset: %04x, data: %04x\n", offset, data));
7430
7431   txc_tw_l_w(space, offset & 0xff, data);   // offset does not really count for this mapper
7432}
7433
7434/* writes to 0x8000-0xffff are like MMC3 but no PRG bankswitch (beacuse it is handled by low writes) */
7435static void txc_tw_prg_cb( running_machine &machine, int start, int bank )
7436{
7437   return;
7438}
7439
7440/*************************************************************
7441
7442 Bootleg Board 'Strike Wolf' by TXC
7443
7444 Games: Strike Wolf (also Policeman?? according to Nestopia)
7445
7446 iNES: mapper 36
7447
7448 Known Boards: Bootleg Board by TXC
7449
7450 In MESS: Supported.
7451
7452 *************************************************************/
7453
7454static WRITE8_HANDLER( txc_strikewolf_w )
7455{
7456   LOG_MMC(("txc_strikewolf_w, offset: %04x, data: %02x\n", offset, data));
7457
7458   if ((offset >= 0x400) && (offset < 0x7fff))
7459   {
7460      prg32(space->machine(), data >> 4);
7461      chr8(space->machine(), data & 0x0f, CHRROM);
7462   }
7463}
7464
7465/*************************************************************
7466
7467 Bootleg Board MXMDHTWO by TXC
7468
7469 Games: Commandos, Journey to the West, Ma Bu Mi Zhen &
7470 Qu Wei Cheng Yu Wu, Si Lu Chuan Qi
7471
7472 Simple Mapper: writes to 0x8000-0xffff sets the prg32 bank.
7473 Not sure if returning 0x50 for reads in 0x4100-0x5000 is correct.
7474
7475 iNES: mapper 241
7476
7477 In MESS: Supported.
7478
7479 *************************************************************/
7480
7481static READ8_HANDLER( txc_mxmdhtwo_l_r )
7482{
7483   return 0x50;
7484}
7485
7486static WRITE8_HANDLER( txc_mxmdhtwo_w )
7487{
7488   LOG_MMC(("txc_mxmdhtwo_w, offset: %04x, data: %02x\n", offset, data));
7489
7490   prg32(space->machine(), data);
7491}
7492
7493/*************************************************************
7494
7495 Waixing Board Type A
7496
7497 Games: Columbus - Ougon no Yoake (C), Ji Jia Zhan Shi,
7498 Jia A Fung Yun, Wei Luo Chuan Qi
7499
7500 This mapper is quite similar to MMC3, but with two differences:
7501 mirroring is not the same, and when VROM banks 8,9 are accessed
7502 they point to CHRRAM and not CHRROM.
7503
7504 iNES: mapper 74
7505
7506 In MESS: Supported
7507
7508 *************************************************************/
7509
7510/* MIRROR_LOW and MIRROR_HIGH are swapped! */
7511static void waixing_set_mirror( running_machine &machine, UINT8 nt )
7512{
7513   switch (nt)
7514   {
7515      case 0:
7516      case 1:
7517         set_nt_mirroring(machine, nt ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
7518         break;
7519      case 2:
7520         set_nt_mirroring(machine, PPU_MIRROR_LOW);
7521         break;
7522      case 3:
7523         set_nt_mirroring(machine, PPU_MIRROR_HIGH);
7524         break;
7525      default:
7526         LOG_MMC(("Mapper set NT to invalid value %02x", nt));
7527         break;
7528   }
7529}
7530
7531/* Luo Ke Ren X only works with this */
7532static void waixing_a_chr_cb( running_machine &machine, int start, int bank, int source )
7533{
7534   int chr_src = (bank <= 9) ? CHRRAM : CHRROM;
7535   chr1_x(machine, start, bank, chr_src);
7536}
7537
7538/* Ji Jia Zhan Shi only works with this */
7539static void waixing_a1_chr_cb( running_machine &machine, int start, int bank, int source )
7540{
7541   int chr_src = ((bank == 8) || (bank == 9)) ? CHRRAM : CHRROM;
7542   chr1_x(machine, start, bank, chr_src);
7543}
7544
7545static WRITE8_HANDLER( waixing_a_w )
7546{
7547   LOG_MMC(("waixing_a_w, offset: %04x, data: %02x\n", offset, data));
7548
7549   switch (offset & 0x6001)
7550   {
7551      case 0x2000:
7552         waixing_set_mirror(space->machine(), data);   //maybe data & 0x03?
7553         break;
7554
7555      case 0x2001:
7556         break;
7557
7558      default:
7559         txrom_w(space, offset, data);
7560         break;
7561   }
7562}
7563
7564/*************************************************************
7565
7566 Waixing Board Type B
7567
7568 Games: Sugoro Quest (C)
7569
7570 MMC3 clone. This is a minor modification of Mapper 74,
7571 in the sense that it is the same board except for the
7572 CHRRAM pages.
7573
7574 iNES: mapper 191
7575
7576 In MESS: Supported.
7577
7578 *************************************************************/
7579
7580static void waixing_b_chr_cb( running_machine &machine, int start, int bank, int source )
7581{
7582   int chr_src = BIT(bank, 7) ? CHRRAM : CHRROM;
7583   chr1_x(machine, start, bank, chr_src);
7584}
7585
7586/*************************************************************
7587
7588 Waixing Board Type C
7589
7590 Games: Ying Lie Qun Xia Zhuan, Young Chivalry
7591
7592 MMC3 clone. This is a minor modification of Mapper 74,
7593 in the sense that it is the same board except for the
7594 CHRRAM pages.
7595
7596 iNES: mapper 192
7597
7598 In MESS: Supported.
7599
7600 *************************************************************/
7601
7602static void waixing_c_chr_cb( running_machine &machine, int start, int bank, int source )
7603{
7604   int chr_src = ((bank == 0x08) || (bank == 0x09) || (bank == 0x0a) || (bank == 0x0b)) ? CHRRAM : CHRROM;
7605   chr1_x(machine, start, bank, chr_src);
7606}
7607
7608/*************************************************************
7609
7610 Waixing Board Type D
7611
7612 Games: Super Robot Taisen (C)
7613
7614 MMC3 clone. This is a minor modification of Mapper 74,
7615 in the sense that it is the same board except for the
7616 CHRRAM pages.
7617
7618 iNES: mapper 194
7619
7620 In MESS: Supported.
7621
7622 *************************************************************/
7623
7624static void waixing_d_chr_cb( running_machine &machine, int start, int bank, int source )
7625{
7626   int chr_src = (bank < 0x02) ? CHRRAM : CHRROM;
7627   chr1_x(machine, start, bank, chr_src);
7628}
7629
7630/*************************************************************
7631
7632 Waixing Board Type E
7633
7634 Games: Captain Tsubasa Vol. II (C), Chaos World, God
7635 Slayer (C), Zu Qiu Xiao Jiang
7636
7637 MMC3 clone. This is a minor modification of Mapper 74,
7638 in the sense that it is the same board except for the
7639 CHRRAM pages.
7640
7641 iNES: mapper 195
7642
7643 In MESS: Supported.
7644
7645 *************************************************************/
7646
7647static void waixing_e_chr_cb( running_machine &machine, int start, int bank, int source )
7648{
7649   int chr_src = (bank < 0x04) ? CHRRAM : CHRROM;
7650   chr1_x(machine, start, bank, chr_src);
7651}
7652
7653/*************************************************************
7654
7655 Waixing Board Type F
7656
7657 Games: Tenchi wo Kurau II (C)
7658
7659 MMC3 clone.
7660
7661 iNES: mapper 198
7662
7663 In MESS: Preliminary support.
7664
7665 *************************************************************/
7666
7667static WRITE8_HANDLER( waixing_f_w )
7668{
7669   nes_state *state = space->machine().driver_data<nes_state>();
7670   UINT8 cmd;
7671   LOG_MMC(("waixing_f_w, offset: %04x, data: %02x\n", offset, data));
7672
7673   switch (offset & 0x6001)
7674   {
7675      case 0x0001:
7676         cmd = state->m_mmc_latch1 & 0x07;
7677         if (cmd >= 6)
7678         {
7679            state->m_mmc_prg_bank[cmd - 6] = data & ((data > 0x3f) ? 0x4f : 0x3f);
7680            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
7681         }
7682         else
7683            waixing_a_w(space, offset, data);
7684         break;
7685
7686      default:
7687         waixing_a_w(space, offset, data);
7688         break;
7689   }
7690}
7691
7692/*************************************************************
7693
7694 Waixing Board Type G
7695
7696 Games: San Guo Zhi 2, Dragon Ball Z Gaiden (C), Dragon
7697 Ball Z II (C)
7698
7699 MMC3 clone
7700
7701 iNES: mapper 199
7702
7703 In MESS: Supported.
7704
7705 *************************************************************/
7706
7707static void waixing_g_chr_cb( running_machine &machine, int start, int bank, int source )
7708{
7709   int chr_src = (bank < 0x08) ? CHRRAM : CHRROM;
7710   chr1_x(machine, start, bank, chr_src);
7711}
7712
7713static void waixing_g_set_chr( running_machine &machine, int chr_base, int chr_mask )
7714{
7715   nes_state *state = machine.driver_data<nes_state>();
7716   UINT8 chr_page = (state->m_mmc_latch1 & 0x80) >> 5;
7717
7718   state->m_mmc3_chr_cb(machine, chr_page ^ 0, chr_base | (state->m_mmc_vrom_bank[0] & chr_mask), state->m_mmc_chr_source);
7719   state->m_mmc3_chr_cb(machine, chr_page ^ 1, chr_base | (state->m_mmc_vrom_bank[6] & chr_mask), state->m_mmc_chr_source);
7720   state->m_mmc3_chr_cb(machine, chr_page ^ 2, chr_base | (state->m_mmc_vrom_bank[1] & chr_mask), state->m_mmc_chr_source);
7721   state->m_mmc3_chr_cb(machine, chr_page ^ 3, chr_base | (state->m_mmc_vrom_bank[7] & chr_mask), state->m_mmc_chr_source);
7722   state->m_mmc3_chr_cb(machine, chr_page ^ 4, chr_base | (state->m_mmc_vrom_bank[2] & chr_mask), state->m_mmc_chr_source);
7723   state->m_mmc3_chr_cb(machine, chr_page ^ 5, chr_base | (state->m_mmc_vrom_bank[3] & chr_mask), state->m_mmc_chr_source);
7724   state->m_mmc3_chr_cb(machine, chr_page ^ 6, chr_base | (state->m_mmc_vrom_bank[4] & chr_mask), state->m_mmc_chr_source);
7725   state->m_mmc3_chr_cb(machine, chr_page ^ 7, chr_base | (state->m_mmc_vrom_bank[5] & chr_mask), state->m_mmc_chr_source);
7726}
7727
7728static WRITE8_HANDLER( waixing_g_w )
7729{
7730   nes_state *state = space->machine().driver_data<nes_state>();
7731   UINT8 MMC3_helper, cmd;
7732   LOG_MMC(("waixing_g_w, offset: %04x, data: %02x\n", offset, data));
7733
7734   switch (offset & 0x6001)
7735   {
7736      case 0x0000:
7737         MMC3_helper = state->m_mmc_latch1 ^ data;
7738         state->m_mmc_latch1 = data;
7739
7740         /* Has PRG Mode changed? */
7741         if (MMC3_helper & 0x40)
7742            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
7743
7744         /* Has CHR Mode changed? */
7745         if (MMC3_helper & 0x80)
7746            waixing_g_set_chr(space->machine(), state->m_mmc_chr_base, state->m_mmc_chr_mask);
7747         break;
7748
7749      case 0x0001:
7750         cmd = state->m_mmc_latch1 & 0x0f;
7751         switch (cmd)
7752         {
7753         case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
7754         case 2: case 3: case 4: case 5:
7755            state->m_mmc_vrom_bank[cmd] = data;
7756            waixing_g_set_chr(space->machine(), state->m_mmc_chr_base, state->m_mmc_chr_mask);
7757            break;
7758         case 6:
7759         case 7:
7760         case 8:
7761         case 9:
7762            state->m_mmc_prg_bank[cmd - 6] = data;
7763            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
7764            break;
7765         case 0x0a: case 0x0b:
7766            state->m_mmc_vrom_bank[cmd - 4] = data;
7767            waixing_g_set_chr(space->machine(), state->m_mmc_chr_base, state->m_mmc_chr_mask);
7768            break;
7769         }
7770         break;
7771
7772      default:
7773         waixing_a_w(space, offset, data);
7774         break;
7775   }
7776}
7777
7778/*************************************************************
7779
7780 Waixing Board Type H
7781
7782 Games: Ying Xiong Yuan Yi Jing Chuan Qi, Yong Zhe Dou E
7783 Long - Dragon Quest VII
7784
7785 MMC3 clone. More info to come.
7786
7787 iNES: mapper 245
7788
7789 In MESS: Supported.
7790
7791 *************************************************************/
7792
7793static void waixing_h_chr_cb( running_machine &machine, int start, int bank, int source )
7794{
7795   if (source == CHRROM)
7796      chr1_x(machine, start, bank, source);
7797}
7798
7799static WRITE8_HANDLER( waixing_h_w )
7800{
7801   nes_state *state = space->machine().driver_data<nes_state>();
7802   UINT8 cmd;
7803   LOG_MMC(("waixing_h_w, offset: %04x, data: %02x\n", offset, data));
7804
7805   switch (offset & 0x6001)
7806   {
7807      case 0x0001:
7808         cmd = state->m_mmc3_latch & 0x07;
7809         switch (cmd)
7810         {
7811         case 0:    // in this case we set prg_base in addition to state->m_mmc_vrom_bank!
7812            state->m_mmc_prg_base = (data << 5) & 0x40;
7813            state->m_mmc_prg_mask = 0x3f;
7814            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
7815            txrom_w(space, offset, data);
7816         default:
7817            txrom_w(space, offset, data);
7818            break;
7819         }
7820         break;
7821
7822      case 0x2001:
7823         break;
7824
7825      default:
7826         txrom_w(space, offset, data);
7827         break;
7828   }
7829}
7830
7831/*************************************************************
7832
7833 Waixing San Guo Zhi Board
7834
7835 Games: San Guo Zhi
7836
7837 This board uses Konami IRQ
7838
7839 iNES: mapper 252
7840
7841 In MESS: Unsupported.
7842
7843 *************************************************************/
7844
7845static WRITE8_HANDLER( waixing_sgz_w )
7846{
7847   nes_state *state = space->machine().driver_data<nes_state>();
7848   UINT8 mmc_helper, bank;
7849   LOG_MMC(("waixing_sgz_w, offset: %04x, data: %02x\n", offset, data));
7850
7851   switch (offset & 0x7000)
7852   {
7853      case 0x0000:
7854         prg8_89(space->machine(), data);
7855         break;
7856      case 0x2000:
7857         prg8_ab(space->machine(), data);
7858         break;
7859      case 0x3000:
7860      case 0x4000:
7861      case 0x5000:
7862      case 0x6000:
7863         bank = ((offset & 0x7000) - 0x3000) / 0x0800 + ((offset & 0x0008) >> 3);
7864         mmc_helper = offset & 0x04;
7865         if (mmc_helper)
7866            state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0x0f) | ((data & 0x0f) << 4);
7867         else
7868            state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0xf0) | (data & 0x0f);
7869         chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], CHRROM);
7870         break;
7871      case 0x7000:
7872         switch (offset & 0x0c)
7873         {
7874         case 0x00:
7875            state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0xf0) | (data & 0x0f);
7876            break;
7877         case 0x04:
7878            state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0x0f) | ((data & 0x0f) << 4);
7879            break;
7880         case 0x08:
7881            state->m_IRQ_enable = data & 0x02;
7882            state->m_IRQ_enable_latch = data & 0x01;
7883            if (data & 0x02)
7884               state->m_IRQ_count = state->m_IRQ_count_latch;
7885            break;
7886         case 0x0c:
7887            state->m_IRQ_enable = state->m_IRQ_enable_latch;
7888            break;
7889         }
7890         break;
7891   }
7892}
7893
7894
7895/*************************************************************
7896
7897 Waixing San Guo Zhong Lie Zhuan Board
7898
7899 Games: Fan Kong Jing Ying, San Guo Zhong Lie Zhuan, Xing
7900 Ji Zheng Ba
7901
7902 iNES: mapper 178
7903
7904 In MESS: Supported.
7905
7906 *************************************************************/
7907
7908static WRITE8_HANDLER( waixing_sgzlz_l_w )
7909{
7910   nes_state *state = space->machine().driver_data<nes_state>();
7911   LOG_MMC(("waixing_sgzlz_l_w, offset: %04x, data: %02x\n", offset, data));
7912
7913   switch (offset)
7914   {
7915      case 0x700:
7916         set_nt_mirroring(space->machine(), data ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
7917         break;
7918      case 0x701:
7919         state->m_mmc_latch1 = (state->m_mmc_latch1 & 0x0c) | ((data >> 1) & 0x03);
7920         prg32(space->machine(), state->m_mmc_latch1);
7921         break;
7922      case 0x702:
7923         state->m_mmc_latch1 = (state->m_mmc_latch1 & 0x03) | ((data << 2) & 0x0c);
7924         break;
7925   }
7926}
7927
7928/*************************************************************
7929
7930 Waixing Final Fantasy V Board
7931
7932 Games: Darkseed, Digital Dragon, Final Fantasy V, Pocket
7933 Monster Red
7934
7935 iNES: mapper 164
7936
7937 In MESS: Supported.
7938
7939 *************************************************************/
7940
7941static WRITE8_HANDLER( waixing_ffv_l_w )
7942{
7943   nes_state *state = space->machine().driver_data<nes_state>();
7944   UINT8 mmc_helper;
7945   LOG_MMC(("waixing_ffv_l_w, offset: %04x, data: %02x\n", offset, data));
7946   offset += 0x100; /* the checks work better on addresses */
7947
7948   if (0x1000 == (offset & 0x1200))
7949   {
7950      state->m_mmc_reg[BIT(offset, 8)] = data;
7951      mmc_helper = BIT(state->m_mmc_reg[1], 0) << 5;
7952      switch (state->m_mmc_reg[0] & 0x70)
7953      {
7954         case 0x00:
7955         case 0x20:
7956         case 0x40:
7957         case 0x60:
7958            prg16_89ab(space->machine(), mmc_helper | ((state->m_mmc_reg[0] >> 1) & 0x10) | (state->m_mmc_reg[0] & 0x0f));
7959            prg16_cdef(space->machine(), mmc_helper & 0x1f);
7960            break;
7961         case 0x50:
7962            prg32(space->machine(), (mmc_helper >> 1) | (state->m_mmc_reg[0] & 0x0f));
7963            break;
7964         case 0x70:
7965            prg16_89ab(space->machine(), mmc_helper | ((state->m_mmc_reg[0] << 1) & 0x10) | (state->m_mmc_reg[0] & 0x0f));
7966            prg16_cdef(space->machine(), mmc_helper & 0x1f);
7967            break;
7968      }
7969   }
7970}
7971
7972/*************************************************************
7973
7974 Waixing Zhan Shi Board
7975
7976 Games: Wai Xing Zhan Shi
7977
7978 Simple mapper: writes to 0x8000-0xffff sets prg32 banks to
7979 (offset>>3)&f. written data&3 sets the mirroring (with
7980 switched high/low compared to the standard one).
7981
7982 A crc check is required to support Dragon Quest VIII (which
7983 uses a slightly different board)
7984
7985 iNES: mapper 242
7986
7987 In MESS: Supported.
7988
7989 *************************************************************/
7990
7991static WRITE8_HANDLER( waixing_zs_w )
7992{
7993   LOG_MMC(("waixing_zs_w, offset: %04x, data: %02x\n", offset, data));
7994
7995   prg32(space->machine(), offset >> 3);
7996
7997   switch (data & 0x03)
7998   {
7999      case 0: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
8000      case 1: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
8001      case 2: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
8002      case 3: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
8003   }
8004}
8005
8006/*************************************************************
8007
8008 Waixing Dragon Quest VIII Board
8009
8010 Games: Dragon Quest VIII
8011
8012 Simple mapper: writes to 0x8000-0xffff sets prg32 banks to
8013 (offset>>3)&f.
8014
8015 iNES: mapper 242
8016
8017 In MESS: Supported.
8018
8019 *************************************************************/
8020
8021static WRITE8_HANDLER( waixing_dq8_w )
8022{
8023   LOG_MMC(("waixing_dq8_w, offset: %04x, data: %02x\n", offset, data));
8024
8025   prg32(space->machine(), offset >> 3);
8026}
8027
8028
8029/*************************************************************
8030
8031 Waixing PS2 board
8032
8033 Games: Bao Xiao Tien Guo, Bio Hazard, Pokemon Gold, Subor (R)
8034
8035 iNES: mapper 15
8036
8037 In MESS: Supported
8038
8039 *************************************************************/
8040
8041static WRITE8_HANDLER( waixing_ps2_w )
8042{
8043   UINT8 map15_flip = (data & 0x80) >> 7;
8044   UINT8 map15_helper = (data & 0x7f) << 1;
8045
8046   LOG_MMC(("waixing_ps2_w, offset: %04x, data: %02x\n", offset, data));
8047
8048   set_nt_mirroring(space->machine(), BIT(data, 6) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8049
8050   switch (offset & 0x0fff)
8051   {
8052      case 0x000:
8053         prg8_89(space->machine(), (map15_helper + 0) ^ map15_flip);
8054         prg8_ab(space->machine(), (map15_helper + 1) ^ map15_flip);
8055         prg8_cd(space->machine(), (map15_helper + 2) ^ map15_flip);
8056         prg8_ef(space->machine(), (map15_helper + 3) ^ map15_flip);
8057         break;
8058      case 0x001:
8059         map15_helper |= map15_flip;
8060         prg8_89(space->machine(), map15_helper);
8061         prg8_ab(space->machine(), map15_helper + 1);
8062         prg8_cd(space->machine(), map15_helper + 1);
8063         prg8_ef(space->machine(), map15_helper + 1);
8064         break;
8065      case 0x002:
8066         map15_helper |= map15_flip;
8067         prg8_89(space->machine(), map15_helper);
8068         prg8_ab(space->machine(), map15_helper);
8069         prg8_cd(space->machine(), map15_helper);
8070         prg8_ef(space->machine(), map15_helper);
8071         break;
8072      case 0x003:
8073         map15_helper |= map15_flip;
8074         prg8_89(space->machine(), map15_helper);
8075         prg8_ab(space->machine(), map15_helper + 1);
8076         prg8_cd(space->machine(), map15_helper);
8077         prg8_ef(space->machine(), map15_helper + 1);
8078         break;
8079   }
8080}
8081
8082/*************************************************************
8083
8084 Waixing Board with Security Chip
8085
8086 Games: Duo Bao Xiao Ying Hao - Guang Ming yu An Hei Chuan Shuo,
8087 Myth Struggle, San Shi Liu Ji, Shui Hu Zhuan
8088
8089 MMC3 clone
8090
8091 iNES: mapper 249
8092
8093 In MESS: Partially Supported.
8094
8095 *************************************************************/
8096
8097static void waixing_sec_prg_cb( running_machine &machine, int start, int bank )
8098{
8099   nes_state *state = machine.driver_data<nes_state>();
8100
8101   if (state->m_mmc_reg[0])
8102      bank = ((bank & 0x01)) | ((bank >> 3) & 0x02) | ((bank >> 1) & 0x04) | ((bank << 2) & 0x18);
8103
8104   prg8_x(machine, start, bank);
8105}
8106
8107static void waixing_sec_chr_cb( running_machine &machine, int start, int bank, int source )
8108{
8109   nes_state *state = machine.driver_data<nes_state>();
8110
8111   if (state->m_mmc_reg[0])
8112      bank = ((bank & 0x03)) | ((bank >> 1) & 0x04) | ((bank >> 4) & 0x08) |
8113            ((bank >> 2) & 0x10) | ((bank << 3) & 0x20) | ((bank << 2) & 0xc0);
8114
8115   chr1_x(machine, start, bank, source);
8116}
8117
8118static WRITE8_HANDLER( waixing_sec_l_w )
8119{
8120   nes_state *state = space->machine().driver_data<nes_state>();
8121   LOG_MMC(("waixing_sec_l_w, offset: %04x, data: %02x\n", offset, data));
8122
8123   offset += 0x100;
8124
8125   if (offset == 0x1000)
8126   {
8127      state->m_mmc_reg[0] = data & 0x02;
8128      mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
8129      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
8130   }
8131}
8132
8133/*************************************************************
8134
8135 Waixing SH2 Board
8136
8137 Games: Fire Emblem (C) and Fire Emblem Gaiden (C)
8138
8139 MMC3 clone with different access to CHR
8140
8141 iNES: mapper 165
8142
8143 In MESS: Partially Supported.
8144
8145 *************************************************************/
8146
8147static void waixing_sh2_chr_cb( running_machine &machine, int start, int bank, int source )
8148{
8149   nes_state *state = machine.driver_data<nes_state>();
8150
8151   chr4_0(machine, state->m_mmc_reg[0], state->m_mmc_reg[0] ? CHRRAM : CHRROM);
8152   chr4_4(machine, state->m_mmc_reg[1], state->m_mmc_reg[1] ? CHRRAM : CHRROM);
8153}
8154
8155READ8_HANDLER( waixing_sh2_chr_r )
8156{
8157   nes_state *state = space->machine().driver_data<nes_state>();
8158   int bank = offset >> 10;
8159   UINT8 val = state->m_chr_map[bank].access[offset & 0x3ff];   // this would be usual return value
8160   int chr_helper;
8161
8162   switch (offset & 0xff8)
8163   {
8164      case 0xfd0: chr_helper = (bank & 0x4) | 0x0; break;
8165      case 0xfe8: chr_helper = (bank & 0x4) | 0x2; break;
8166      default: return val;
8167   }
8168
8169   state->m_mmc_reg[offset >> 12] = chr_helper;
8170   if (offset & 0x1000)
8171      chr4_4(space->machine(), state->m_mmc_reg[1], state->m_mmc_reg[1] ? CHRRAM : CHRROM);
8172   else
8173      chr4_0(space->machine(), state->m_mmc_reg[0], state->m_mmc_reg[0] ? CHRRAM : CHRROM);
8174
8175   return val;
8176}
8177
8178/*************************************************************
8179
8180 Board UNL-8237
8181
8182 Games: Pocahontas 2
8183
8184 MMC3 clone
8185
8186 In MESS: Supported
8187
8188 *************************************************************/
8189
8190static void unl_8237_prg_cb( running_machine &machine, int start, int bank )
8191{
8192   nes_state *state = machine.driver_data<nes_state>();
8193
8194   if (!(state->m_mmc_reg[0] & 0x80))
8195      prg8_x(machine, start, bank);
8196}
8197
8198static void unl_8237_chr_cb( running_machine &machine, int start, int bank, int source )
8199{
8200   nes_state *state = machine.driver_data<nes_state>();
8201   bank |= ((state->m_mmc_reg[1] << 6) & 0x100);
8202
8203   chr1_x(machine, start, bank, source);
8204}
8205
8206static WRITE8_HANDLER( unl_8237_l_w )
8207{
8208   nes_state *state = space->machine().driver_data<nes_state>();
8209   LOG_MMC(("unl_8237_l_w offset: %04x, data: %02x\n", offset, data));
8210   offset += 0x100;
8211
8212   if (offset == 0x1000)
8213   {
8214      state->m_mmc_reg[0] = data;
8215      if (state->m_mmc_reg[0] & 0x80)
8216      {
8217         if (state->m_mmc_reg[0] & 0x20)
8218            prg32(space->machine(), (state->m_mmc_reg[0] & 0x0f) >> 1);
8219         else
8220         {
8221            prg16_89ab(space->machine(), state->m_mmc_reg[0] & 0x1f);
8222            prg16_cdef(space->machine(), state->m_mmc_reg[0] & 0x1f);
8223         }
8224      }
8225      else
8226         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
8227   }
8228
8229   if (offset == 0x1001)
8230   {
8231      state->m_mmc_reg[1] = data;
8232      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
8233   }
8234}
8235
8236static WRITE8_HANDLER( unl_8237_w )
8237{
8238   nes_state *state = space->machine().driver_data<nes_state>();
8239   static const UINT8 conv_table[8] = {0, 2, 6, 1, 7, 3, 4, 5};
8240   LOG_MMC(("unl_8237_w offset: %04x, data: %02x\n", offset, data));
8241
8242   switch (offset & 0x7000)
8243   {
8244      case 0x0000:
8245      case 0x1000:
8246         set_nt_mirroring(space->machine(), (data | (data >> 7)) & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8247         break;
8248
8249      case 0x2000:
8250      case 0x3000:
8251         state->m_mmc_reg[2] = 1;
8252         data = (data & 0xc0) | conv_table[data & 0x07];
8253         txrom_w(space, 0x0000, data);
8254         break;
8255
8256      case 0x4000:
8257      case 0x5000:
8258         if (state->m_mmc_reg[2])
8259         {
8260            state->m_mmc_reg[2] = 0;
8261            txrom_w(space, 0x0001, data);
8262         }
8263         break;
8264
8265      case 0x6000:
8266         break;
8267
8268      case 0x7000:
8269         txrom_w(space, 0x6001, data);
8270         txrom_w(space, 0x4000, data);
8271         txrom_w(space, 0x4001, data);
8272         break;
8273   }
8274}
8275
8276/*************************************************************
8277
8278 Board UNL-AX5705
8279
8280 Games: Super Mario Bros. Pocker Mali (Crayon Shin-chan pirate hack)
8281
8282 In MESS: Supported
8283
8284 *************************************************************/
8285
8286static void unl_ax5705_set_prg( running_machine &machine )
8287{
8288   nes_state *state = machine.driver_data<nes_state>();
8289   prg8_89(machine, state->m_mmc_prg_bank[0]);
8290   prg8_ab(machine, state->m_mmc_prg_bank[1]);
8291}
8292
8293static WRITE8_HANDLER( unl_ax5705_w )
8294{
8295   nes_state *state = space->machine().driver_data<nes_state>();
8296   UINT8 bank;
8297   LOG_MMC(("unl_ax5705_w offset: %04x, data: %02x\n", offset, data));
8298
8299   switch (offset & 0x700f)
8300   {
8301      case 0x0000:
8302         state->m_mmc_prg_bank[0] = (data & 0x05) | ((data & 0x08) >> 2) | ((data & 0x02) << 2);
8303         unl_ax5705_set_prg(space->machine());
8304         break;
8305      case 0x0008:
8306         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8307         break;
8308      case 0x2000:
8309         state->m_mmc_prg_bank[1] = (data & 0x05) | ((data & 0x08) >> 2) | ((data & 0x02) << 2);
8310         unl_ax5705_set_prg(space->machine());
8311         break;
8312         /* CHR banks 0, 1, 4, 5 */
8313      case 0x2008:
8314      case 0x200a:
8315      case 0x4008:
8316      case 0x400a:
8317         bank = ((offset & 0x4000) ? 4 : 0) + ((offset & 0x0002) ? 1 : 0);
8318         state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0xf0) | (data & 0x0f);
8319         chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], CHRROM);
8320         break;
8321      case 0x2009:
8322      case 0x200b:
8323      case 0x4009:
8324      case 0x400b:
8325         bank = ((offset & 0x4000) ? 4 : 0) + ((offset & 0x0002) ? 1 : 0);
8326         state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0x0f) | ((data & 0x04) << 3) | ((data & 0x02) << 5) | ((data & 0x09) << 4);
8327         chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], CHRROM);
8328         break;
8329         /* CHR banks 2, 3, 6, 7 */
8330      case 0x4000:
8331      case 0x4002:
8332      case 0x6000:
8333      case 0x6002:
8334         bank = 2 + ((offset & 0x2000) ? 4 : 0) + ((offset & 0x0002) ? 1 : 0);
8335         state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0xf0) | (data & 0x0f);
8336         chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], CHRROM);
8337         break;
8338      case 0x4001:
8339      case 0x4003:
8340      case 0x6001:
8341      case 0x6003:
8342         bank = 2 + ((offset & 0x2000) ? 4 : 0) + ((offset & 0x0002) ? 1 : 0);
8343         state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0x0f) | ((data & 0x04) << 3) | ((data & 0x02) << 5) | ((data & 0x09) << 4);
8344         chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], CHRROM);
8345         break;
8346   }
8347}
8348
8349/*************************************************************
8350
8351 Board UNL-CC-21
8352
8353 Games: Mi Hun Che
8354
8355 In MESS: Supported
8356
8357 *************************************************************/
8358
8359static WRITE8_HANDLER( unl_cc21_w )
8360{
8361   LOG_MMC(("unl_cc21_w offset: %04x, data: %02x\n", offset, data));
8362
8363   set_nt_mirroring(space->machine(), BIT(data, 1) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
8364   chr8(space->machine(), (offset & 0x01), CHRROM);
8365}
8366
8367/*************************************************************
8368
8369 Board UNL-KOF97
8370
8371 Games: King of Fighters 97 (Rex Soft)
8372
8373 MMC3 clone
8374
8375 In MESS: Not working
8376
8377 *************************************************************/
8378
8379static UINT8 unl_kof97_unscramble( UINT8 data )
8380{
8381   return ((data >> 1) & 0x01) | ((data >> 4) & 0x02) | ((data << 2) & 0x04) | ((data >> 0) & 0xd8) | ((data << 3) & 0x20);
8382}
8383
8384static WRITE8_HANDLER( unl_kof97_w )
8385{
8386   LOG_MMC(("unl_kof97_w offset: %04x, data: %02x\n", offset, data));
8387
8388   /* Addresses 0x9000, 0xa000, 0xd000 & 0xf000 behaves differently than MMC3 */
8389   if (offset == 0x1000)
8390   {
8391      data = unl_kof97_unscramble(data);
8392      txrom_w(space, 0x0001, data);
8393   }
8394   else if (offset == 0x2000)
8395   {
8396      data = unl_kof97_unscramble(data);
8397      txrom_w(space, 0x0000, data);
8398   }
8399   else if (offset == 0x5000)
8400   {
8401      data = unl_kof97_unscramble(data);
8402      txrom_w(space, 0x4001, data);
8403   }
8404   else if (offset == 0x7000)
8405   {
8406      data = unl_kof97_unscramble(data);
8407      txrom_w(space, 0x6001, data);
8408   }
8409   else      /* Other addresses behaves like MMC3, up to unscrambling data */
8410   {
8411      switch (offset & 0x6001)
8412      {
8413         case 0x0000:
8414         case 0x0001:
8415         case 0x4000:
8416         case 0x4001:
8417         case 0x6000:
8418         case 0x6001:
8419         case 0x2000:   /* are these ever called?!? */
8420         case 0x2001:
8421            data = unl_kof97_unscramble(data);
8422            txrom_w(space, offset, data);
8423            break;
8424      }
8425   }
8426}
8427
8428/*************************************************************
8429
8430 Board UNL-T-230
8431
8432 Games: Dragon Ball Z IV (Unl)
8433
8434 In MESS: Supported
8435
8436 *************************************************************/
8437
8438static WRITE8_HANDLER( unl_t230_w )
8439{
8440   nes_state *state = space->machine().driver_data<nes_state>();
8441   UINT8 bank;
8442   LOG_MMC(("unl_t230_w offset: %04x, data: %02x\n", offset, data));
8443
8444   switch (offset & 0x700c)
8445   {
8446      case 0x0000:
8447         break;
8448      case 0x2000:
8449         prg16_89ab(space->machine(), data);
8450         break;
8451
8452      // the part below works like VRC-2. how was the original board wired up?
8453      // was there a VRC2? if so, we can use VRC-2 and add proper pin settings to xml!
8454      case 0x1000:
8455      case 0x1004:
8456      case 0x1008:
8457      case 0x100c:
8458         switch (data & 0x03)
8459         {
8460         case 0x00: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
8461         case 0x01: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
8462         case 0x02: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
8463         case 0x03: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
8464         }
8465         break;
8466
8467      case 0x3000:
8468      case 0x3004:
8469      case 0x3008:
8470      case 0x300c:
8471      case 0x4000:
8472      case 0x4004:
8473      case 0x4008:
8474      case 0x400c:
8475      case 0x5000:
8476      case 0x5004:
8477      case 0x5008:
8478      case 0x500c:
8479      case 0x6000:
8480      case 0x6004:
8481      case 0x6008:
8482      case 0x600c:
8483         bank = ((offset & 0x7000) - 0x3000) / 0x0800 + ((offset & 0x0008) >> 2);
8484         if (offset & 0x0004)
8485            state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0x0f) | (data << 4);
8486         else
8487            state->m_mmc_vrom_bank[bank] = (state->m_mmc_vrom_bank[bank] & 0xf0) | (data & 0x0f);
8488
8489         chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[bank], state->m_mmc_chr_source);
8490         break;
8491      case 0x7000:
8492         state->m_IRQ_count_latch &= ~0x0f;
8493         state->m_IRQ_count_latch |= data & 0x0f;
8494         break;
8495      case 0x7004:
8496         state->m_IRQ_count_latch &= ~0xf0;
8497         state->m_IRQ_count_latch |= (data << 4) & 0xf0;
8498         break;
8499      case 0x7008:
8500         state->m_IRQ_mode = data & 0x04;   // currently not implemented: 0 = prescaler mode / 1 = CPU mode
8501         state->m_IRQ_enable = data & 0x02;
8502         state->m_IRQ_enable_latch = data & 0x01;
8503         if (data & 0x02)
8504            state->m_IRQ_count = state->m_IRQ_count_latch;
8505         break;
8506
8507      default:
8508         logerror("unl_t230_w uncaught offset: %04x value: %02x\n", offset, data);
8509         break;
8510   }
8511}
8512
8513/*************************************************************
8514
8515 Bootleg Board for KOF96
8516
8517 Games: The King of Fighters 96, Sonic 3D Blast 6, Street
8518 Fighter Zero 2
8519
8520 MMC3 clone
8521
8522 iNES: mapper 187
8523
8524 In MESS: Preliminary Support.
8525
8526 *************************************************************/
8527
8528static void kof96_prg_cb( running_machine &machine, int start, int bank )
8529{
8530   nes_state *state = machine.driver_data<nes_state>();
8531
8532   if (!(state->m_mmc_reg[0] & 0x80))
8533      prg8_x(machine, start, bank);
8534}
8535
8536static void kof96_chr_cb( running_machine &machine, int start, int bank, int source )
8537{
8538   nes_state *state = machine.driver_data<nes_state>();
8539   UINT8 chr_page = (state->m_mmc_latch1 & 0x80) >> 5;
8540
8541   if ((start & 0x04) == chr_page)
8542      bank |= 0x100;
8543
8544   chr1_x(machine, start, bank, source);
8545}
8546
8547static WRITE8_HANDLER( kof96_l_w )
8548{
8549   nes_state *state = space->machine().driver_data<nes_state>();
8550   UINT8 new_bank;
8551   LOG_MMC(("kof96_l_w, offset: %04x, data: %02x\n", offset, data));
8552   offset += 0x100;
8553
8554   if (offset == 0x1000)
8555   {
8556      state->m_mmc_reg[0] = data;
8557
8558      if (state->m_mmc_reg[0] & 0x80)
8559      {
8560         new_bank = (state->m_mmc_reg[0] & 0x1f);
8561
8562         if (state->m_mmc_reg[0] & 0x20)
8563            prg32(space->machine(), new_bank >> 2);
8564         else
8565         {
8566            prg16_89ab(space->machine(), new_bank);
8567            prg16_cdef(space->machine(), new_bank);
8568         }
8569      }
8570      else
8571         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
8572   }
8573
8574   if (offset >= 0x1000)
8575   {
8576      switch (data & 0x03)
8577      {
8578         case 0x00:
8579         case 0x01:
8580            state->m_mmc_reg[1] = 0x83;
8581            break;
8582         case 0x02:
8583            state->m_mmc_reg[1] = 0x42;
8584            break;
8585         case 0x03:
8586            state->m_mmc_reg[1] = 0x00;
8587            break;
8588      }
8589
8590   }
8591
8592   if (!state->m_mmc_reg[3] && offset > 0x1000)
8593   {
8594      state->m_mmc_reg[3] = 1;
8595      space->write_byte(0x4017, 0x40);
8596   }
8597}
8598
8599static READ8_HANDLER( kof96_l_r )
8600{
8601   nes_state *state = space->machine().driver_data<nes_state>();
8602   LOG_MMC(("kof96_l_r, offset: %04x\n", offset));
8603   offset += 0x100;
8604
8605   if (!(offset < 0x1000))
8606      return state->m_mmc_reg[1];
8607   else
8608      return 0;
8609}
8610
8611static WRITE8_HANDLER( kof96_w )
8612{
8613   nes_state *state = space->machine().driver_data<nes_state>();
8614   LOG_MMC(("kof96_w, offset: %04x, data: %02x\n", offset, data));
8615
8616   switch (offset & 0x6003)
8617   {
8618      case 0x0000:
8619         state->m_mmc_reg[2] = 1;
8620         txrom_w(space, 0x0000, data);
8621         break;
8622
8623      case 0x0001:
8624         if (state->m_mmc_reg[2])
8625            txrom_w(space, 0x0001, data);
8626         break;
8627
8628      case 0x0002:
8629         break;
8630
8631      case 0x0003:
8632         state->m_mmc_reg[2] = 0;
8633
8634         if (data == 0x28)
8635            prg8_cd(space->machine(), 0x17);
8636         else if (data == 0x2a)
8637            prg8_ab(space->machine(), 0x0f);
8638         break;
8639
8640      default:
8641         txrom_w(space, offset, data);
8642         break;
8643   }
8644}
8645
8646/*************************************************************
8647
8648 Bootleg Board for MK2
8649
8650 Games: Mortal Kombat II, Street Fighter III, Super Mario
8651 Kart Rider
8652
8653 This board uses an IRQ system very similar to MMC3. We indeed
8654 use mapper4_irq, but there is some small glitch!
8655
8656 iNES: mapper 91
8657
8658 In MESS: Supported.
8659
8660 *************************************************************/
8661
8662static WRITE8_HANDLER( mk2_m_w )
8663{
8664   nes_state *state = space->machine().driver_data<nes_state>();
8665   LOG_MMC(("mk2_m_w, offset: %04x, data: %02x\n", offset, data));
8666
8667   switch (offset & 0x1000)
8668   {
8669      case 0x0000:
8670         switch (offset & 0x03)
8671         {
8672         case 0x00: chr2_0(space->machine(), data, CHRROM); break;
8673         case 0x01: chr2_2(space->machine(), data, CHRROM); break;
8674         case 0x02: chr2_4(space->machine(), data, CHRROM); break;
8675         case 0x03: chr2_6(space->machine(), data, CHRROM); break;
8676         }
8677         break;
8678      case 0x1000:
8679         switch (offset & 0x03)
8680         {
8681         case 0x00: prg8_89(space->machine(), data); break;
8682         case 0x01: prg8_ab(space->machine(), data); break;
8683         case 0x02: state->m_IRQ_enable = 0; state->m_IRQ_count = 0; break;
8684         case 0x03: state->m_IRQ_enable = 1; state->m_IRQ_count = 7; break;
8685         }
8686         break;
8687      default:
8688         logerror("mk2_m_w uncaught addr: %04x value: %02x\n", offset + 0x6000, data);
8689         break;
8690   }
8691}
8692
8693/*************************************************************
8694
8695 Bootleg Board N625092
8696
8697 Games: 400 in 1, 700 in 1, 1000 in 1
8698
8699 iNES: mapper 221
8700
8701 In MESS: Supported.
8702
8703 *************************************************************/
8704
8705static void n625092_set_prg( running_machine &machine, UINT8 reg1, UINT8 reg2 )
8706{
8707   UINT8 map221_helper1, map221_helper2;
8708
8709   map221_helper1 = !(reg1 & 0x01) ? reg2 :
8710   (reg1 & 0x80) ? reg2 : (reg2 & 0x06) | 0x00;
8711   map221_helper2 = !(reg1 & 0x01) ? reg2 :
8712   (reg1 & 0x80) ? 0x07 : (reg2 & 0x06) | 0x01;
8713
8714   prg16_89ab(machine, map221_helper1 | ((reg1 & 0x70) >> 1));
8715   prg16_cdef(machine, map221_helper2 | ((reg1 & 0x70) >> 1));
8716}
8717
8718static WRITE8_HANDLER( n625092_w )
8719{
8720   nes_state *state = space->machine().driver_data<nes_state>();
8721   LOG_MMC(("n625092_w, offset: %04x, data: %02x\n", offset, data));
8722
8723   if (offset < 0x4000)
8724   {
8725      set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8726      offset = (offset >> 1) & 0xff;
8727
8728      if (state->m_mmc_latch1 != offset)
8729      {
8730         state->m_mmc_latch1 = offset;
8731         n625092_set_prg(space->machine(), state->m_mmc_latch1, state->m_mmc_latch2);
8732      }
8733   }
8734   else
8735   {
8736      offset &= 0x07;
8737
8738      if (state->m_mmc_latch2 != offset)
8739      {
8740         state->m_mmc_latch2 = offset;
8741         n625092_set_prg(space->machine(), state->m_mmc_latch1, state->m_mmc_latch2);
8742      }
8743   }
8744}
8745
8746/*************************************************************
8747
8748 SC-127 Board
8749
8750 Games: Wario World II (Kirby Hack)
8751
8752 iNES: mapper 35
8753
8754 In MESS: Supported
8755
8756 *************************************************************/
8757
8758static void sc127_irq( device_t *device, int scanline, int vblank, int blanked )
8759{
8760   nes_state *state = device->machine().driver_data<nes_state>();
8761
8762   if (scanline < PPU_BOTTOM_VISIBLE_SCANLINE && state->m_IRQ_enable)
8763   {
8764      state->m_IRQ_count--;
8765
8766      if (!blanked && (state->m_IRQ_count == 0))
8767      {
8768         LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
8769                device->machine().primary_screen->vpos(), device->machine().primary_screen->hpos()));
8770         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
8771         state->m_IRQ_enable = 0;
8772      }
8773   }
8774}
8775
8776static WRITE8_HANDLER( sc127_w )
8777{
8778   nes_state *state = space->machine().driver_data<nes_state>();
8779   LOG_MMC(("sc127_w, offset: %04x, data: %02x\n", offset, data));
8780
8781   switch (offset)
8782   {
8783      case 0x0000:
8784         prg8_89(space->machine(), data);
8785         break;
8786      case 0x0001:
8787         prg8_ab(space->machine(), data);
8788         break;
8789      case 0x0002:
8790         //      state->m_mmc_prg_bank[offset & 0x02] = data;
8791         prg8_cd(space->machine(), data);
8792         break;
8793      case 0x1000:
8794      case 0x1001:
8795      case 0x1002:
8796      case 0x1003:
8797      case 0x1004:
8798      case 0x1005:
8799      case 0x1006:
8800      case 0x1007:
8801         //      state->m_mmc_vrom_bank[offset & 0x07] = data;
8802         chr1_x(space->machine(), offset & 0x07, data, CHRROM);
8803         break;
8804      case 0x4002:
8805         state->m_IRQ_enable = 0;
8806         break;
8807      case 0x4003:
8808         state->m_IRQ_enable = 1;
8809         break;
8810      case 0x4005:
8811         state->m_IRQ_count = data;
8812         break;
8813      case 0x5001:
8814         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8815         break;
8816   }
8817}
8818
8819/*************************************************************
8820
8821 Bootleg Board SMB2J
8822
8823 Games: Super Mario Bros. 2 Pirate (LF36)
8824
8825 iNES: mapper 43
8826
8827 In MESS: Supported? The only image I found is not working
8828 (not even in NEStopia).
8829
8830 *************************************************************/
8831
8832static WRITE8_HANDLER( smb2j_w )
8833{
8834   nes_state *state = space->machine().driver_data<nes_state>();
8835   int bank = (((offset >> 8) & 0x03) * 0x20) + (offset & 0x1f);
8836
8837   LOG_MMC(("smb2j_w, offset: %04x, data: %02x\n", offset, data));
8838
8839   set_nt_mirroring(space->machine(), (offset & 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8840
8841   if (offset & 0x0800)
8842   {
8843      if (offset & 0x1000)
8844      {
8845         if (bank * 2 >= state->m_prg_chunks)
8846         {
8847            memory_set_bankptr(space->machine(), "bank3", state->m_wram);
8848            memory_set_bankptr(space->machine(), "bank4", state->m_wram);
8849         }
8850         else
8851         {
8852            LOG_MMC(("smb2j_w, selecting upper 16KB bank of #%02x\n", bank));
8853            prg16_cdef(space->machine(), 2 * bank + 1);
8854         }
8855      }
8856      else
8857      {
8858         if (bank * 2 >= state->m_prg_chunks)
8859         {
8860            memory_set_bankptr(space->machine(), "bank1", state->m_wram);
8861            memory_set_bankptr(space->machine(), "bank2", state->m_wram);
8862         }
8863         else
8864         {
8865            LOG_MMC(("smb2j_w, selecting lower 16KB bank of #%02x\n", bank));
8866            prg16_89ab(space->machine(), 2 * bank);
8867         }
8868      }
8869   }
8870   else
8871   {
8872      if (bank * 2 >= state->m_prg_chunks)
8873      {
8874         memory_set_bankptr(space->machine(), "bank1", state->m_wram);
8875         memory_set_bankptr(space->machine(), "bank2", state->m_wram);
8876         memory_set_bankptr(space->machine(), "bank3", state->m_wram);
8877         memory_set_bankptr(space->machine(), "bank4", state->m_wram);
8878      }
8879      else
8880      {
8881         LOG_MMC(("smb2j_w, selecting 32KB bank #%02x\n", bank));
8882         prg32(space->machine(), bank);
8883      }
8884   }
8885}
8886
8887/*************************************************************
8888
8889 BTL-SMB2B
8890
8891 Games: Super Mario Bros. 2 Pirate (Jpn version of SMB2)
8892
8893 This was marked as Alt. Levels. is it true?
8894
8895 iNES: mapper 50
8896
8897 In MESS: Supported.
8898
8899 *************************************************************/
8900
8901static void smb2jb_irq( device_t *device, int scanline, int vblank, int blanked )
8902{
8903   nes_state *state = device->machine().driver_data<nes_state>();
8904   if (state->m_IRQ_enable)
8905   {
8906      if (state->m_IRQ_count < 0x1000)
8907      {
8908         if ((0x1000 - state->m_IRQ_count) <= 114)
8909            device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
8910         else
8911            state->m_IRQ_count += 114;
8912      }
8913      else
8914         state->m_IRQ_count += 114;
8915
8916      state->m_IRQ_count &= 0xffff;   // according to docs is 16bit counter -> it wraps only after 0xffff
8917   }
8918}
8919
8920static WRITE8_HANDLER( smb2jb_l_w )
8921{
8922   nes_state *state = space->machine().driver_data<nes_state>();
8923   UINT8 prg;
8924   LOG_MMC(("smb2jb_l_w, offset: %04x, data: %02x\n", offset, data));
8925   offset += 0x100;
8926
8927   switch (offset & 0x160)
8928   {
8929      case 0x020:
8930         prg = (data & 0x08) | ((data & 0x06) >> 1) | ((data & 0x01) << 2);
8931         prg8_cd(space->machine(), prg);
8932         break;
8933      case 0x120:
8934         state->m_IRQ_enable = data & 0x01;
8935         break;
8936   }
8937}
8938
8939/* This goes to 0x4020-0x403f */
8940WRITE8_HANDLER( smb2jb_extra_w )
8941{
8942   UINT8 prg;
8943   LOG_MMC(("smb2jb_extra_w, offset: %04x, data: %02x\n", offset, data));
8944
8945   prg = (data & 0x08) | ((data & 0x06) >> 1) | ((data & 0x01) << 2);
8946   prg8_cd(space->machine(), prg);
8947}
8948
8949/*************************************************************
8950
8951 Bootleg Board for Super Fighter III
8952
8953 MMC3 clone
8954
8955 iNES: mapper 197
8956
8957 In MESS: Supported.
8958
8959 *************************************************************/
8960
8961static void unl_sf3_set_chr( running_machine &machine, UINT8 chr_source, int chr_base, int chr_mask )
8962{
8963   nes_state *state = machine.driver_data<nes_state>();
8964   chr4_0(machine, chr_base | ((state->m_mmc_vrom_bank[0] >> 1) & chr_mask), chr_source);
8965   chr2_4(machine, chr_base | (state->m_mmc_vrom_bank[1] & chr_mask), chr_source);
8966   chr2_6(machine, chr_base | (state->m_mmc_vrom_bank[2] & chr_mask), chr_source);
8967}
8968
8969static WRITE8_HANDLER( unl_sf3_w )
8970{
8971   nes_state *state = space->machine().driver_data<nes_state>();
8972   UINT8 mmc_helper, cmd;
8973   LOG_MMC(("unl_sf3_w, offset: %04x, data: %02x\n", offset, data));
8974
8975   switch (offset & 0x6001)
8976   {
8977      case 0x0000:
8978         mmc_helper = state->m_mmc3_latch ^ data;
8979         state->m_mmc3_latch = data;
8980
8981         /* Has PRG Mode changed? */
8982         if (mmc_helper & 0x40)
8983            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
8984
8985         /* Has CHR Mode changed? */
8986         if (mmc_helper & 0x80)
8987            unl_sf3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
8988         break;
8989
8990      case 0x0001:
8991         cmd = state->m_mmc3_latch & 0x0f;
8992         switch (cmd)
8993         {
8994         case 0: case 2: case 4:
8995            state->m_mmc_vrom_bank[cmd >> 1] = data;
8996            unl_sf3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
8997            break;
8998         case 6:
8999         case 7:
9000            state->m_mmc_prg_bank[cmd - 6] = data;
9001            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
9002            break;
9003         }
9004         break;
9005
9006      default:
9007         txrom_w(space, offset, data);
9008         break;
9009   }
9010}
9011
9012/*************************************************************
9013
9014 Bootleg Board for Xiao Zhuan Yuan
9015
9016 Games: Shu Qi Yu - Zhi Li Xiao Zhuan Yuan
9017
9018 Very simple mapper: writes to 0x5ff1 set prg32 (to data>>1),
9019 while writes to 0x5ff2 set chr8
9020
9021 iNES: mapper 176
9022
9023 In MESS: Supported.
9024
9025 *************************************************************/
9026
9027static WRITE8_HANDLER( unl_xzy_l_w )
9028{
9029   LOG_MMC(("unl_xzy_l_w, offset: %04x, data: %02x\n", offset, data));
9030
9031   switch (offset)
9032   {
9033      case 0x1ef1:   /* 0x5ff1 */
9034         prg32(space->machine(), data >> 1);
9035         break;
9036      case 0x1ef2:   /* 0x5ff2 */
9037         chr8(space->machine(), data, CHRROM);
9038         break;
9039   }
9040}
9041
9042/*************************************************************
9043
9044 Board UNL-RACERMATE
9045
9046 In MESS: *VERY* preliminary support. Also, it seems that this
9047 board saves to battery the CHRRAM!!!
9048
9049 *************************************************************/
9050
9051static void racmate_update_banks( running_machine &machine )
9052{
9053   nes_state *state = machine.driver_data<nes_state>();
9054   chr4_4(machine, state->m_mmc_latch1 & 0x0f, state->m_mmc_chr_source);
9055   prg16_89ab(machine, state->m_mmc_latch1 >> 1);
9056}
9057
9058static WRITE8_HANDLER( unl_racmate_w )
9059{
9060   nes_state *state = space->machine().driver_data<nes_state>();
9061   LOG_MMC(("unl_racmate_w offset: %04x, data: %02x\n", offset, data));
9062
9063   if (offset == 0x3000)
9064   {
9065      state->m_mmc_latch1 = data;
9066      racmate_update_banks(space->machine());
9067   }
9068}
9069
9070/*************************************************************
9071
9072        BOOTLEG CART VERSIONS OF FDS GAMES
9073
9074 *************************************************************/
9075
9076/*************************************************************
9077
9078 BTL-SUPERBROS11
9079
9080 Games: Super Mario Bros. 11, Super Mario Bros. 17
9081
9082 This acts basically like a MMC3 with different use of write
9083 address.
9084
9085 iNES: mapper 196
9086
9087 In MESS: Supported.
9088
9089 *************************************************************/
9090
9091static WRITE8_HANDLER( btl_smb11_w )
9092{
9093   LOG_MMC(("btl_smb11_w, offset: %04x, data: %02x\n", offset, data));
9094
9095   txrom_w(space, (offset & 0x6000) | ((offset & 0x04) >> 2), data);
9096}
9097
9098/*************************************************************
9099
9100 BTL-MARIOBABY
9101
9102 Games: Mario Baby, Ai Senshi Nicol
9103
9104 iNES: mapper 42
9105
9106 In MESS: Supported.
9107
9108 *************************************************************/
9109
9110// is the code fine for ai senshi nicol?!?
9111static WRITE8_HANDLER( btl_mariobaby_w )
9112{
9113   nes_state *state = space->machine().driver_data<nes_state>();
9114   LOG_MMC(("btl_mariobaby_w, offset: %04x, data: %02x\n", offset, data));
9115
9116   if (offset >= 0x7000)
9117   {
9118      switch (offset & 0x03)
9119      {
9120         case 0x00:
9121            prg8_67(space->machine(), data);
9122            break;
9123         case 0x01:
9124            set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9125            break;
9126         case 0x02:
9127            /* Check if IRQ is being enabled */
9128            if (!state->m_IRQ_enable && (data & 0x02))
9129            {
9130               state->m_IRQ_enable = 1;
9131               state->m_irq_timer->adjust(downcast<cpu_device *>(state->m_maincpu)->cycles_to_attotime(24576));
9132            }
9133            if (!(data & 0x02))
9134            {
9135               state->m_IRQ_enable = 0;
9136               state->m_irq_timer->adjust(attotime::never);
9137            }
9138            break;
9139      }
9140   }
9141}
9142
9143/*************************************************************
9144
9145 BTL-SMB2A
9146
9147 Games: Super Mario Bros. 2 Pirate (Jpn version of SMB2)
9148
9149 iNES: mapper 40
9150
9151 In MESS: Supported.
9152
9153 *************************************************************/
9154
9155static void btl_smb2a_irq( device_t *device, int scanline, int vblank, int blanked )
9156{
9157   nes_state *state = device->machine().driver_data<nes_state>();
9158
9159   if (state->m_IRQ_enable)
9160   {
9161      if ((0xfff - state->m_IRQ_count) <= 114)
9162      {
9163         state->m_IRQ_count = (state->m_IRQ_count + 1) & 0xfff;
9164         state->m_IRQ_enable = 0;
9165         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
9166      }
9167      else
9168         state->m_IRQ_count += 114;
9169   }
9170}
9171
9172static WRITE8_HANDLER( btl_smb2a_w )
9173{
9174   nes_state *state = space->machine().driver_data<nes_state>();
9175   LOG_MMC(("btl_smb2a_w, offset: %04x, data: %02x\n", offset, data));
9176
9177   switch (offset & 0x6000)
9178   {
9179      case 0x0000:
9180         state->m_IRQ_enable = 0;
9181         state->m_IRQ_count = 0;
9182         break;
9183      case 0x2000:
9184         state->m_IRQ_enable = 1;
9185         break;
9186      case 0x6000:
9187         prg8_cd(space->machine(), data);
9188         break;
9189   }
9190}
9191
9192/*************************************************************
9193
9194 WHIRLWIND-2706
9195
9196 Games: Meikyuu Jiin Dababa (FDS conversion)
9197
9198 iNES: mapper 108
9199
9200 In MESS: Supported.
9201
9202 *************************************************************/
9203
9204static WRITE8_HANDLER( whirl2706_w )
9205{
9206   LOG_MMC(("whirl2706_w, offset: %04x, data: %02x\n", offset, data));
9207   prg8_67(space->machine(), data);
9208}
9209
9210/*************************************************************
9211
9212 Bootleg Board used for FDS conversion
9213
9214 Games: Tobidase Daisakusen (FDS conversion)
9215
9216 iNES: mapper 120
9217
9218 In MESS: Partially Supported.
9219
9220 *************************************************************/
9221
9222static WRITE8_HANDLER( btl_tobi_l_w )
9223{
9224   LOG_MMC(("btl_tobi_l_w, offset: %04x, data: %02x\n", offset, data));
9225   offset += 0x100;
9226
9227   if ((offset & 0x43c0) == 0x41c0)
9228      prg8_67(space->machine(), data & 0x07);
9229}
9230
9231/*************************************************************
9232
9233 BTL-SMB3
9234
9235 Games: Super Mario Bros. 3 Pirate
9236
9237 iNES: mapper 106
9238
9239 In MESS: Supported.
9240
9241 *************************************************************/
9242
9243static void btl_smb3_irq( device_t *device, int scanline, int vblank, int blanked )
9244{
9245   nes_state *state = device->machine().driver_data<nes_state>();
9246
9247   if (state->m_IRQ_enable)
9248   {
9249      if ((0xffff - state->m_IRQ_count) < 114)
9250      {
9251         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
9252         state->m_IRQ_enable = 0;
9253      }
9254
9255      state->m_IRQ_count = (state->m_IRQ_count + 114) & 0xffff;
9256   }
9257}
9258
9259static WRITE8_HANDLER( btl_smb3_w )
9260{
9261   nes_state *state = space->machine().driver_data<nes_state>();
9262   LOG_MMC(("btl_smb3_w, offset: %04x, data: %02x\n", offset, data));
9263   switch (offset & 0x0f)
9264   {
9265      case 0x00:
9266      case 0x02:
9267         chr1_x(space->machine(), offset & 0x07, data & 0xfe, CHRROM);
9268         break;
9269      case 0x01:
9270      case 0x03:
9271         chr1_x(space->machine(), offset & 0x07, data | 0x01, CHRROM);
9272         break;
9273      case 0x04: case 0x05:
9274      case 0x06: case 0x07:
9275         chr1_x(space->machine(), offset & 0x07, data, CHRROM);
9276         break;
9277      case 0x08:
9278         prg8_89(space->machine(), data | 0x10);
9279         break;
9280      case 0x09:
9281         prg8_ab(space->machine(), data);
9282         break;
9283      case 0x0a:
9284         prg8_cd(space->machine(), data);
9285         break;
9286      case 0x0b:
9287         prg8_ef(space->machine(), data | 0x10);
9288         break;
9289      case 0x0c:
9290         set_nt_mirroring(space->machine(), BIT(data, 0) ?  PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9291         break;
9292      case 0x0d:
9293         state->m_IRQ_count = 0;
9294         state->m_IRQ_enable = 0;
9295         break;
9296      case 0x0e:
9297         state->m_IRQ_count = (state->m_IRQ_count & 0xff00) | data;
9298         break;
9299      case 0x0f:
9300         state->m_IRQ_count = (state->m_IRQ_count & 0x00ff) | (data << 8);
9301         state->m_IRQ_enable = 1;
9302         break;
9303   }
9304}
9305
9306/*************************************************************
9307
9308 BTL-DRAGONNINJA
9309
9310 Games: Dragon Ninja (Bootleg), Super Mario Bros. 8
9311
9312 iNES: mapper 222
9313
9314 In MESS: Unsupported.
9315
9316 *************************************************************/
9317
9318/* Scanline based IRQ ? */
9319static void btl_dn_irq( device_t *device, int scanline, int vblank, int blanked )
9320{
9321   nes_state *state = device->machine().driver_data<nes_state>();
9322   if (scanline < PPU_BOTTOM_VISIBLE_SCANLINE)
9323   {
9324      if (!state->m_IRQ_count || ++state->m_IRQ_count < 240)
9325         return;
9326
9327      state->m_IRQ_count = 0;
9328      LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
9329             device->machine().primary_screen->vpos(), device->machine().primary_screen->hpos()));
9330      device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
9331   }
9332}
9333
9334static WRITE8_HANDLER( btl_dn_w )
9335{
9336   nes_state *state = space->machine().driver_data<nes_state>();
9337   UINT8 bank;
9338   LOG_MMC(("btl_dn_w, offset: %04x, data: %02x\n", offset, data));
9339
9340   switch (offset & 0x7003)
9341   {
9342      case 0x0000:
9343         prg8_89(space->machine(), data);
9344         break;
9345      case 0x1000:
9346         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9347         break;
9348      case 0x2000:
9349         prg8_ab(space->machine(), data);
9350         break;
9351      case 0x3000:
9352      case 0x3002:
9353      case 0x4000:
9354      case 0x4002:
9355      case 0x5000:
9356      case 0x5002:
9357      case 0x6000:
9358      case 0x6002:
9359         bank = ((offset & 0x7000) - 0x3000) / 0x0800 + ((offset & 0x0002) >> 3);
9360         chr1_x(space->machine(), bank, data, CHRROM);
9361         break;
9362      case 0x7000:
9363         state->m_IRQ_count = data;
9364         break;
9365   }
9366}
9367
9368/*************************************************************
9369
9370 BTL-PIKACHUY2K
9371
9372 Games: Pikachu Y2k
9373
9374 iNES: mapper 254
9375
9376 In MESS:
9377
9378 *************************************************************/
9379
9380static WRITE8_HANDLER( btl_pika_y2k_w )
9381{
9382   nes_state *state = space->machine().driver_data<nes_state>();
9383   LOG_MMC(("btl_pika_y2k_w, offset: %04x, data: %02x\n", offset, data));
9384
9385   switch (offset & 0x6001)
9386   {
9387      case 0x2001:
9388         state->m_mmc_latch2 = data;
9389         break;
9390
9391      case 0x2000:
9392         state->m_mmc_reg[0] = 0;
9393      default:
9394         txrom_w(space, offset, data);
9395         break;
9396   }
9397}
9398
9399// strange WRAM usage: it is protected at start, and gets unprotected after the first write to 0xa000
9400static WRITE8_HANDLER( btl_pika_y2k_m_w )
9401{
9402   nes_state *state = space->machine().driver_data<nes_state>();
9403   LOG_MMC(("btl_pika_y2k_m_w, offset: %04x, data: %02x\n", offset, data));
9404
9405   state->m_wram[offset] = data;
9406}
9407
9408static READ8_HANDLER( btl_pika_y2k_m_r )
9409{
9410   nes_state *state = space->machine().driver_data<nes_state>();
9411   LOG_MMC(("btl_pika_y2k_m_r, offset: %04x\n", offset));
9412
9413   return   state->m_wram[offset] ^ (state->m_mmc_latch2 & state->m_mmc_reg[0]);
9414}
9415
9416/*************************************************************
9417
9418          MULTICART
9419
9420 *************************************************************/
9421
9422/*************************************************************
9423
9424 Board BMC-FK23C
9425
9426 In MESS: partially supported (still to sort initial banking
9427 for many games)
9428
9429 *************************************************************/
9430
9431#if 0
9432static void fk23c_prg_cb( running_machine &machine, int start, int bank )
9433{
9434   nes_state *state = machine.driver_data<nes_state>();
9435
9436   if (((state->m_mmc_reg[0] & 0x07) - 3) > 1 && (!(state->m_mmc_reg[3] & 0x02) || start < 2))
9437   {
9438      if (state->m_mmc_reg[0] & 0x03)
9439         bank = (bank & (0x3f >> (state->m_mmc_reg[0] & 0x03))) | (state->m_mmc_reg[1] << 1);
9440
9441      prg8_x(machine, start, bank);
9442   }
9443}
9444
9445static void fk23c_chr_cb( running_machine &machine, int start, int bank, int source )
9446{
9447   nes_state *state = machine.driver_data<nes_state>();
9448
9449   if (!(state->m_mmc_reg[0] & 0x40) && (!(state->m_mmc_reg[3] & 0x02) || (start != 1 && start != 3)))
9450      chr1_x(machine, start, ((state->m_mmc_reg[2] & 0x7f) << 3) | bank, source);
9451}
9452
9453#endif
9454
9455static void fk23c_prg_cb( running_machine &machine, int start, int bank )
9456{
9457   nes_state *state = machine.driver_data<nes_state>();
9458   UINT8 mask = (0x3f >> (state->m_mmc_reg[0] & 0x03));
9459
9460   if ((state->m_mmc_reg[0] & 0x07) < 3)
9461   {
9462      if (!(state->m_mmc_reg[0] & 0x03))
9463         bank = (bank & mask) | ((state->m_mmc_reg[1]  & (0x7f ^ mask)) << 1);
9464
9465      prg8_x(machine, start, bank);
9466   }
9467}
9468
9469static void fk23c_chr_cb( running_machine &machine, int start, int bank, int source )
9470{
9471   nes_state *state = machine.driver_data<nes_state>();
9472
9473   if (!(state->m_mmc_reg[0] & 0x40) && (!(state->m_mmc_reg[3] & 0x02) || (start != 1 && start != 3)))
9474      chr1_x(machine, start, ((state->m_mmc_reg[2] & 0x7f) << 3) | bank, source);
9475}
9476
9477static void fk23c_set_prg( running_machine &machine )
9478{
9479   nes_state *state = machine.driver_data<nes_state>();
9480
9481   if ((state->m_mmc_reg[0] & 0x07) == 4)
9482      prg32(machine, (state->m_mmc_reg[1] & 0x7f) >> 1);
9483   else if ((state->m_mmc_reg[0] & 0x07) == 3)
9484   {
9485      prg16_89ab(machine, state->m_mmc_reg[1] & 0x7f);
9486      prg16_cdef(machine, state->m_mmc_reg[1] & 0x7f);
9487   }
9488   else
9489   {
9490      if (state->m_mmc_reg[3] & 0x02)
9491      {
9492         prg8_cd(machine, state->m_mmc_reg[4]);
9493         prg8_ef(machine, state->m_mmc_reg[5]);
9494      }
9495
9496      mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
9497   }
9498}
9499
9500static void fk23c_set_chr( running_machine &machine )
9501{
9502   nes_state *state = machine.driver_data<nes_state>();
9503
9504   if (state->m_mmc_reg[0] & 0x40)
9505      chr8(machine, state->m_mmc_reg[2] | state->m_mmc_cmd1, state->m_mmc_chr_source);
9506   else
9507   {
9508      if (state->m_mmc_reg[3] & 0x02)
9509      {
9510         int base = (state->m_mmc_reg[2] & 0x7f) << 3;
9511         chr1_x(machine, 1, base | state->m_mmc_reg[6], state->m_mmc_chr_source);
9512         chr1_x(machine, 3, base | state->m_mmc_reg[7], state->m_mmc_chr_source);
9513      }
9514
9515      mmc3_set_chr(machine, state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
9516   }
9517}
9518
9519static WRITE8_HANDLER( fk23c_l_w )
9520{
9521   nes_state *state = space->machine().driver_data<nes_state>();
9522   LOG_MMC(("fk23c_l_w, offset: %04x, data: %02x\n", offset, data));
9523   offset += 0x100;
9524
9525   if (offset >= 0x1000)
9526   {
9527      if (offset & (1 << 4))   // here it should be (4 + state->m_mmc_dipsetting)
9528      {
9529         state->m_mmc_reg[offset & 0x03] = data;
9530
9531         fk23c_set_prg(space->machine());
9532         fk23c_set_chr(space->machine());
9533      }
9534   }
9535}
9536
9537static WRITE8_HANDLER( fk23c_w )
9538{
9539   nes_state *state = space->machine().driver_data<nes_state>();
9540   LOG_MMC(("fk23c_w, offset: %04x, data: %02x\n", offset, data));
9541
9542   if (state->m_mmc_reg[0] & 0x40)
9543   {
9544      if (state->m_mmc_reg[0] & 0x30)
9545         state->m_mmc_cmd1 = 0;
9546      else
9547      {
9548         state->m_mmc_cmd1 = data & 0x03;
9549         fk23c_set_chr(space->machine());
9550      }
9551   }
9552   else
9553   {
9554      switch (offset & 0x6001)
9555      {
9556         case 0x0001:
9557            if ((state->m_mmc_reg[3] & 0x02) && (state->m_mmc3_latch & 0x08))
9558            {
9559               state->m_mmc_reg[4 | (state->m_mmc3_latch & 0x03)] = data;
9560               fk23c_set_prg(space->machine());
9561               fk23c_set_chr(space->machine());
9562            }
9563            else
9564               txrom_w(space, offset, data);
9565            break;
9566
9567         case 0x2000:
9568            set_nt_mirroring(space->machine(), data ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9569            break;
9570
9571         default:
9572            txrom_w(space, offset, data);
9573            break;
9574      }
9575   }
9576}
9577
9578
9579/*************************************************************
9580
9581 Board BMC-64IN1NOREPEAT
9582
9583 Games: 64-in-1 Y2K
9584
9585 In MESS: Supported
9586
9587 *************************************************************/
9588
9589static void bmc_64in1nr_set_prg( running_machine &machine )
9590{
9591   nes_state *state = machine.driver_data<nes_state>();
9592   UINT8 helper1 = (state->m_mmc_reg[1] & 0x1f);
9593   UINT8 helper2 = (helper1 << 1) | ((state->m_mmc_reg[1] & 0x40) >> 6);
9594
9595   if (state->m_mmc_reg[0] & 0x80)
9596   {
9597      if (state->m_mmc_reg[1] & 0x80)
9598         prg32(machine, helper1);
9599      else
9600      {
9601         prg16_89ab(machine, helper2);
9602         prg16_cdef(machine, helper2);
9603      }
9604   }
9605   else
9606      prg16_cdef(machine, helper2);
9607}
9608
9609static WRITE8_HANDLER( bmc_64in1nr_l_w )
9610{
9611   nes_state *state = space->machine().driver_data<nes_state>();
9612   LOG_MMC(("bmc_64in1nr_l_w offset: %04x, data: %02x\n", offset, data));
9613   offset += 0x100;
9614
9615   switch (offset)
9616   {
9617      case 0x1000:
9618      case 0x1001:
9619      case 0x1002:
9620      case 0x1003:
9621         state->m_mmc_reg[offset & 0x03] = data;
9622         bmc_64in1nr_set_prg(space->machine());
9623         chr8(space->machine(), ((state->m_mmc_reg[0] >> 1) & 0x03) | (state->m_mmc_reg[2] << 2), CHRROM);
9624         break;
9625   }
9626   if (offset == 0x1000)   /* reg[0] also sets mirroring */
9627      set_nt_mirroring(space->machine(), BIT(data, 5) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9628}
9629
9630static WRITE8_HANDLER( bmc_64in1nr_w )
9631{
9632   nes_state *state = space->machine().driver_data<nes_state>();
9633   LOG_MMC(("bmc_64in1nr_w offset: %04x, data: %02x\n", offset, data));
9634
9635   state->m_mmc_reg[3] = data;   // reg[3] is currently unused?!?
9636}
9637
9638/*************************************************************
9639
9640 Board BMC-190IN1
9641
9642 Games: 190-in-1
9643
9644 In MESS: Supported
9645
9646 *************************************************************/
9647
9648static WRITE8_HANDLER( bmc_190in1_w )
9649{
9650   LOG_MMC(("bmc_190in1_w offset: %04x, data: %02x\n", offset, data));
9651
9652   set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9653   offset >>= 2;
9654   prg16_89ab(space->machine(), offset);
9655   prg16_cdef(space->machine(), offset);
9656   chr8(space->machine(), offset, CHRROM);
9657}
9658
9659/*************************************************************
9660
9661 Board BMC-A65AS
9662
9663 Games: 3-in-1 (N068)
9664
9665 In MESS: Supported
9666
9667 *************************************************************/
9668
9669static WRITE8_HANDLER( bmc_a65as_w )
9670{
9671   UINT8 helper = (data & 0x30) >> 1;
9672   LOG_MMC(("bmc_a65as_w offset: %04x, data: %02x\n", offset, data));
9673
9674   if (data & 0x80)
9675      set_nt_mirroring(space->machine(), BIT(data, 5) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
9676   else
9677      set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9678
9679   if (data & 0x40)
9680      prg32(space->machine(), data >> 1);
9681   else
9682   {
9683      prg16_89ab(space->machine(), helper | (data & 0x07));
9684      prg16_cdef(space->machine(), helper | 0x07);
9685   }
9686}
9687
9688/*************************************************************
9689
9690 Board BMC-GS2004
9691
9692 Games: Tetris Family 6-in-1
9693
9694 In MESS: Preliminary Support. It also misses WRAM handling
9695 (we need reads from 0x6000-0x7fff)
9696
9697 *************************************************************/
9698
9699static WRITE8_HANDLER( bmc_gs2004_w )
9700{
9701   LOG_MMC(("bmc_gs2004_w offset: %04x, data: %02x\n", offset, data));
9702
9703   prg32(space->machine(), data);
9704}
9705
9706/*************************************************************
9707
9708 Board BMC-GS2013
9709
9710 Games: Tetris Family 12-in-1
9711
9712 In MESS: Preliminary Support. It also misses WRAM handling
9713 (we need reads from 0x6000-0x7fff)
9714
9715 *************************************************************/
9716
9717static WRITE8_HANDLER( bmc_gs2013_w )
9718{
9719   LOG_MMC(("bmc_gs2013_w offset: %04x, data: %02x\n", offset, data));
9720
9721   if (data & 0x08)
9722      prg32(space->machine(), data & 0x09);
9723   else
9724      prg32(space->machine(), data & 0x07);
9725}
9726
9727/*************************************************************
9728
9729 Board BMC-SUPER24IN1SC03
9730
9731 Games: Super 24-in-1
9732
9733 In MESS: Partially Supported
9734
9735 *************************************************************/
9736
9737static void bmc_s24in1sc03_prg_cb( running_machine &machine, int start, int bank )
9738{
9739   nes_state *state = machine.driver_data<nes_state>();
9740   static const UINT8 masks[8] = {0x3f, 0x1f, 0x0f, 0x01, 0x03, 0x00, 0x00, 0x00};
9741   int prg_base = state->m_mmc_reg[1] << 1;
9742   int prg_mask = masks[state->m_mmc_reg[0] & 0x07];
9743
9744   bank = prg_base | (bank & prg_mask);
9745   prg8_x(machine, start, bank);
9746}
9747
9748static void bmc_s24in1sc03_chr_cb( running_machine &machine, int start, int bank, int source )
9749{
9750   nes_state *state = machine.driver_data<nes_state>();
9751   UINT8 chr = BIT(state->m_mmc_reg[0], 5) ? CHRRAM : CHRROM;
9752   int chr_base = (state->m_mmc_reg[2] << 3) & 0xf00;
9753
9754   chr1_x(machine, start, chr_base | bank, chr);
9755}
9756
9757static WRITE8_HANDLER( bmc_s24in1sc03_l_w )
9758{
9759   nes_state *state = space->machine().driver_data<nes_state>();
9760   LOG_MMC(("bmc_s24in1sc03_l_w offset: %04x, data: %02x\n", offset, data));
9761   offset += 0x100;
9762
9763   if (offset == 0x1ff0)
9764   {
9765      state->m_mmc_reg[0] = data;
9766      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
9767      mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
9768   }
9769
9770   if (offset == 0x1ff1)
9771   {
9772      state->m_mmc_reg[1] = data;
9773      mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
9774   }
9775
9776   if (offset == 0x1ff2)
9777   {
9778      state->m_mmc_reg[2] = data;
9779      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
9780   }
9781}
9782
9783/*************************************************************
9784
9785 Board BMC-T-262
9786
9787 Games: 4-in-1 (D-010), 8-in-1 (A-020)
9788
9789 In MESS: Supported
9790
9791 *************************************************************/
9792
9793static WRITE8_HANDLER( bmc_t262_w )
9794{
9795   nes_state *state = space->machine().driver_data<nes_state>();
9796   UINT8 mmc_helper;
9797   LOG_MMC(("bmc_t262_w offset: %04x, data: %02x\n", offset, data));
9798
9799   if (state->m_mmc_latch2 || offset == 0)
9800   {
9801      state->m_mmc_latch1 = (state->m_mmc_latch1 & 0x38) | (data & 0x07);
9802      prg16_89ab(space->machine(), state->m_mmc_latch1);
9803   }
9804   else
9805   {
9806      state->m_mmc_latch2 = 1;
9807      set_nt_mirroring(space->machine(), BIT(data, 1) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9808      mmc_helper = ((offset >> 3) & 0x20) | ((offset >> 2) & 0x18);
9809      state->m_mmc_latch1 = mmc_helper | (state->m_mmc_latch1 & 0x07);
9810      prg16_89ab(space->machine(), state->m_mmc_latch1);
9811      prg16_cdef(space->machine(), mmc_helper | 0x07);
9812   }
9813}
9814
9815/*************************************************************
9816
9817 Board BMC-WS
9818
9819 Games: Super 40-in-1
9820
9821 In MESS: Partially Supported (some games, like Galaxian, have
9822 issues)
9823
9824 *************************************************************/
9825
9826static WRITE8_HANDLER( bmc_ws_m_w )
9827{
9828   nes_state *state = space->machine().driver_data<nes_state>();
9829   UINT8 mmc_helper;
9830   LOG_MMC(("bmc_ws_m_w offset: %04x, data: %02x\n", offset, data));
9831
9832   if (offset < 0x1000)
9833   {
9834      switch (offset & 0x01)
9835      {
9836         case 0:
9837            if (!state->m_mmc_latch1)
9838            {
9839               state->m_mmc_latch1 = data & 0x20;
9840               set_nt_mirroring(space->machine(), BIT(data, 4) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9841               mmc_helper = (~data & 0x08) >> 3;
9842               prg16_89ab(space->machine(), data & ~mmc_helper);
9843               prg16_cdef(space->machine(), data |  mmc_helper);
9844            }
9845            break;
9846         case 1:
9847            if (!state->m_mmc_latch1)
9848            {
9849               chr8(space->machine(), data, CHRROM);
9850            }
9851            break;
9852      }
9853   }
9854}
9855
9856/*************************************************************
9857
9858 BMC-NOVELDIAMOND and BMC-999999in1
9859
9860 Unknown Bootleg Multigame Board
9861 Games: I only found 'Novel Diamond 999999-in-1.unf' using
9862 this mapper (hence the code is used for BMC_NOVELDIAMOND
9863 board). The code is included here in case a mapper 54
9864 dump arises.
9865
9866 iNES: mappers 54 and 213
9867
9868 In MESS: Partial Support.
9869
9870 *************************************************************/
9871
9872// Are this correct or should they work the same?
9873static WRITE8_HANDLER( novel1_w )
9874{
9875   LOG_MMC(("novel1_w, offset: %04x, data: %02x\n", offset, data));
9876
9877   prg32(space->machine(), offset & 0x03);
9878   chr8(space->machine(), offset & 0x07, CHRROM);
9879}
9880
9881static WRITE8_HANDLER( novel2_w )
9882{
9883   LOG_MMC(("novel2_w, offset: %04x, data: %02x\n", offset, data));
9884
9885   prg32(space->machine(), offset >> 1);
9886   chr8(space->machine(), offset >> 3, CHRROM);
9887}
9888
9889/*************************************************************
9890
9891 Board BMC-GKA
9892
9893 Unknown Bootleg Multigame Board
9894 Games: 6 in 1, 54 in 1, 106 in 1
9895
9896 iNES: mapper 57
9897
9898 In MESS: Supported.
9899
9900 *************************************************************/
9901
9902static WRITE8_HANDLER( bmc_gka_w )
9903{
9904   nes_state *state = space->machine().driver_data<nes_state>();
9905   LOG_MMC(("bmc_gka_w, offset: %04x, data: %02x\n", offset, data));
9906
9907   if (offset & 0x0800)
9908      state->m_mmc_latch2 = data;
9909   else
9910      state->m_mmc_latch1 = data;
9911
9912   if (state->m_mmc_latch2 & 0x80)
9913      prg32(space->machine(), 2 | (state->m_mmc_latch2 >> 6));
9914   else
9915   {
9916      prg16_89ab(space->machine(), (state->m_mmc_latch2 >> 5) & 0x03);
9917      prg16_cdef(space->machine(), (state->m_mmc_latch2 >> 5) & 0x03);
9918   }
9919
9920   set_nt_mirroring(space->machine(), (state->m_mmc_latch2 & 0x08) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9921
9922   chr8(space->machine(), (state->m_mmc_latch1 & 0x03) | (state->m_mmc_latch2 & 0x07) | ((state->m_mmc_latch2 & 0x10) >> 1), CHRROM);
9923}
9924
9925
9926/*************************************************************
9927
9928 Board UNL-STUDYNGAME
9929
9930 Games: Study n Game 32 in 1
9931
9932 iNES: mapper 39
9933
9934 In MESS: Partially Supported (problems with PRG bankswitch,
9935 only keyboard exercise work).
9936
9937 *************************************************************/
9938
9939static WRITE8_HANDLER( sng32_w )
9940{
9941   LOG_MMC(("sng32_w, offset: %04x, data: %02x\n", offset, data));
9942   prg32(space->machine(), data);
9943}
9944
9945/*************************************************************
9946
9947 Board BMC-GKB
9948
9949 Unknown Bootleg Multigame Board
9950 Games: 68 in 1, 73 in 1, 98 in 1
9951
9952 iNES: mapper 58
9953
9954 In MESS: Supported.
9955
9956 *************************************************************/
9957
9958static WRITE8_HANDLER( bmc_gkb_w )
9959{
9960   nes_state *state = space->machine().driver_data<nes_state>();
9961   UINT8 bank = (offset & 0x40) ? 0 : 1;
9962   LOG_MMC(("bmc_gkb_w, offset: %04x, data: %02x\n", offset, data));
9963
9964   prg16_89ab(space->machine(), offset & ~bank);
9965   prg16_cdef(space->machine(), offset | bank);
9966   chr8(space->machine(), offset >> 3, state->m_mmc_chr_source);
9967   set_nt_mirroring(space->machine(), BIT(data, 7) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9968}
9969
9970/*************************************************************
9971
9972 BMC-SUPER-700IN1
9973
9974 Unknown Bootleg Multigame Board
9975 Games: Super 700 in 1
9976
9977 iNES: mapper 62
9978
9979 In MESS: Supported.
9980
9981 *************************************************************/
9982
9983static WRITE8_HANDLER( bmc_super700in1_w )
9984{
9985   LOG_MMC(("bmc_super700in1_w, offset :%04x, data: %02x\n", offset, data));
9986
9987   chr8(space->machine(), ((offset & 0x1f) << 2) | (data & 0x03), CHRROM);
9988
9989   if (offset & 0x20)
9990   {
9991      prg16_89ab(space->machine(), (offset & 0x40) | ((offset >> 8) & 0x3f));
9992      prg16_cdef(space->machine(), (offset & 0x40) | ((offset >> 8) & 0x3f));
9993   }
9994   else
9995   {
9996      prg32(space->machine(), ((offset & 0x40) | ((offset >> 8) & 0x3f)) >> 1);
9997   }
9998
9999   set_nt_mirroring(space->machine(), BIT(data, 7) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10000}
10001
10002/*************************************************************
10003
10004 BMC-36IN1
10005
10006 Unknown Bootleg Multigame Board
10007 Games: 36 in 1, 1200 in 1
10008
10009 iNES: mapper 200
10010
10011 In MESS: Supported.
10012
10013 *************************************************************/
10014
10015static WRITE8_HANDLER( bmc_36in1_w )
10016{
10017   LOG_MMC(("bmc_36in1_w, offset: %04x, data: %02x\n", offset, data));
10018
10019   prg16_89ab(space->machine(), offset & 0x07);
10020   prg16_cdef(space->machine(), offset & 0x07);
10021   chr8(space->machine(), offset & 0x07, CHRROM);
10022
10023   set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10024}
10025
10026/*************************************************************
10027
10028 BMC-21IN1
10029
10030 Unknown Bootleg Multigame Board
10031 Games: 8 in 1, 21 in 1
10032
10033 iNES: mapper 201
10034
10035 In MESS: Supported.
10036
10037 *************************************************************/
10038
10039static WRITE8_HANDLER( bmc_21in1_w )
10040{
10041   LOG_MMC(("bmc_21in1_w, offset: %04x, data: %02x\n", offset, data));
10042
10043   prg32(space->machine(), offset & 0x03);
10044   chr8(space->machine(), offset & 0x03, CHRROM);
10045}
10046
10047/*************************************************************
10048
10049 BMC-150IN1
10050
10051 Unknown Bootleg Multigame Board
10052 Games: 150 in 1
10053
10054 iNES: mapper 202
10055
10056 In MESS: Supported.
10057
10058 *************************************************************/
10059
10060static WRITE8_HANDLER( bmc_150in1_w )
10061{
10062   int bank = (offset >> 1) & 0x07;
10063
10064   LOG_MMC(("bmc_150in1_w, offset: %04x, data: %02x\n", offset, data));
10065
10066   prg16_89ab(space->machine(), bank);
10067   prg16_cdef(space->machine(), bank + (((bank & 0x06) == 0x06) ? 1 : 0));
10068   chr8(space->machine(), bank, CHRROM);
10069
10070   set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ: PPU_MIRROR_VERT);
10071}
10072
10073/*************************************************************
10074
10075 BMC-35IN1
10076
10077 Unknown Bootleg Multigame Board
10078 Games: 35 in 1
10079
10080 iNES: mapper 203
10081
10082 In MESS: Supported.
10083
10084 *************************************************************/
10085
10086static WRITE8_HANDLER( bmc_35in1_w )
10087{
10088   LOG_MMC(("bmc_35in1_w, offset: %04x, data: %02x\n", offset, data));
10089
10090   prg16_89ab(space->machine(), (data >> 2) & 0x03);
10091   prg16_cdef(space->machine(), (data >> 2) & 0x03);
10092   chr8(space->machine(), data & 0x03, CHRROM);
10093}
10094
10095/*************************************************************
10096
10097 BMC-64IN1
10098
10099 Unknown Bootleg Multigame Board
10100 Games: 64 in 1
10101
10102 iNES: mapper 204
10103
10104 In MESS: Supported.
10105
10106 *************************************************************/
10107
10108static WRITE8_HANDLER( bmc_64in1_w )
10109{
10110   int bank = (offset >> 1) & (offset >> 2) & 0x01;
10111
10112   LOG_MMC(("bmc_64in1_w, offset: %04x, data: %02x\n", offset, data));
10113
10114   prg16_89ab(space->machine(), offset & ~bank);
10115   prg16_cdef(space->machine(), offset | bank);
10116   chr8(space->machine(), offset & ~bank, CHRROM);
10117
10118   set_nt_mirroring(space->machine(), BIT(data, 4) ? PPU_MIRROR_HORZ: PPU_MIRROR_VERT);
10119}
10120
10121/*************************************************************
10122
10123 BMC-15IN1
10124
10125 Unknown Bootleg Multigame Board
10126 Games: 3 in 1, 15 in 1
10127
10128 iNES: mapper 205, MMC3 clone
10129
10130 In MESS: Supported.
10131
10132 *************************************************************/
10133
10134static WRITE8_HANDLER( bmc_15in1_m_w )
10135{
10136   nes_state *state = space->machine().driver_data<nes_state>();
10137   LOG_MMC(("bmc_15in1_m_w, offset: %04x, data: %02x\n", offset, data));
10138
10139   if (offset & 0x0800)
10140   {
10141      state->m_mmc_prg_base = (data & 0x03) << 4;
10142      state->m_mmc_prg_mask = (data & 0x02) ? 0x0f : 0x1f;
10143      state->m_mmc_chr_base = (data & 0x03) << 7;
10144      state->m_mmc_chr_mask = (data & 0x02) ? 0x7f : 0xff;
10145      mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10146      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
10147   }
10148}
10149
10150/*************************************************************
10151
10152 BMC-SUPERHIK_300IN1
10153
10154 Unknown Bootleg Multigame Board
10155 Games: 100000 in 1, Super HIK 300 in 1, 1997 in 1
10156
10157 iNES: mapper 212
10158
10159 In MESS: Supported.
10160
10161 *************************************************************/
10162
10163static WRITE8_HANDLER( bmc_hik300_w )
10164{
10165   LOG_MMC(("bmc_hik300_w, offset: %04x, data: %02x\n", offset, data));
10166
10167   set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10168   chr8(space->machine(), offset, CHRROM);
10169
10170   if (offset < 0x4000)
10171   {
10172      prg16_89ab(space->machine(), offset);
10173      prg16_cdef(space->machine(), offset);
10174   }
10175   else
10176      prg32(space->machine(), offset >> 1);
10177}
10178
10179/*************************************************************
10180
10181 BMC-SUPERGUN-20IN1
10182
10183 Unknown Bootleg Multigame Board
10184 Games: Super Gun 20 in 1
10185
10186 iNES: mapper 214
10187
10188 In MESS: Supported.
10189
10190 *************************************************************/
10191
10192static WRITE8_HANDLER( supergun20in1_w )
10193{
10194   LOG_MMC(("supergun20in1_w, offset: %04x, data: %02x\n", offset, data));
10195
10196   prg16_89ab(space->machine(), offset >> 2);
10197   prg16_cdef(space->machine(), offset >> 2);
10198   chr8(space->machine(), offset, CHRROM);
10199}
10200
10201/*************************************************************
10202
10203 BMC-72IN1
10204
10205 Unknown Bootleg Multigame Board
10206 Games: 72 in 1, 115 in 1 and other multigame carts
10207
10208 iNES: mapper 225
10209
10210 In MESS: Supported.
10211
10212 *************************************************************/
10213
10214static WRITE8_HANDLER( bmc_72in1_w )
10215{
10216   int hi_bank;
10217   int size_16;
10218   int bank;
10219
10220   LOG_MMC(("bmc_72in1_w, offset: %04x, data: %02x\n", offset, data));
10221
10222   chr8(space->machine(), offset, CHRROM);
10223   set_nt_mirroring(space->machine(), (offset & 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10224
10225   hi_bank = offset & 0x40;
10226   size_16 = offset & 0x1000;
10227   bank = (offset & 0xf80) >> 7;
10228   if (size_16)
10229   {
10230      bank <<= 1;
10231      if (hi_bank)
10232         bank ++;
10233
10234      prg16_89ab(space->machine(), bank);
10235      prg16_cdef(space->machine(), bank);
10236   }
10237   else
10238      prg32(space->machine(), bank);
10239}
10240
10241/*************************************************************
10242
10243 BMC-76IN1
10244
10245 Unknown Bootleg Multigame Board
10246 Games: 76 in 1, Super 42 in 1
10247
10248 iNES: mapper 226
10249
10250 In MESS: Supported.
10251
10252 *************************************************************/
10253
10254// does this work for super42in1 as well?!?
10255static WRITE8_HANDLER( bmc_76in1_w )
10256{
10257   nes_state *state = space->machine().driver_data<nes_state>();
10258   int hi_bank;
10259   int size_16;
10260   int bank;
10261
10262   LOG_MMC(("bmc_76in1_w, offset: %04x, data: %02x\n", offset, data));
10263
10264   if (offset & 0x01)
10265      state->m_mmc_latch2 = data;
10266   else
10267      state->m_mmc_latch1 = data;
10268
10269   set_nt_mirroring(space->machine(), BIT(state->m_mmc_latch1, 6) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10270
10271   hi_bank = state->m_mmc_latch1 & 0x01;
10272   size_16 = state->m_mmc_latch1 & 0x20;
10273   bank = ((state->m_mmc_latch1 & 0x1e) >> 1) | ((state->m_mmc_latch1 & 0x80) >> 3) | ((state->m_mmc_latch2 & 0x01) << 5);
10274
10275   if (size_16)
10276   {
10277      bank <<= 1;
10278      if (hi_bank)
10279         bank ++;
10280
10281      prg16_89ab(space->machine(), bank);
10282      prg16_cdef(space->machine(), bank);
10283   }
10284   else
10285      prg32(space->machine(), bank);
10286}
10287
10288/*************************************************************
10289
10290 BMC-1200IN1
10291
10292 Unknown Bootleg Multigame Board
10293 Games: 1200 in 1, 295 in 1, 76 in 1
10294
10295 iNES: mapper 227
10296
10297 In MESS: Supported.
10298
10299 *************************************************************/
10300
10301static WRITE8_HANDLER( bmc_1200in1_w )
10302{
10303   int hi_bank;
10304   int size_32;
10305   int bank;
10306
10307   LOG_MMC(("bmc_1200in1_w, offset: %04x, data: %02x\n", offset, data));
10308
10309   hi_bank = offset & 0x04;
10310   size_32 = offset & 0x01;
10311   bank = ((offset & 0x78) >> 3) | ((offset & 0x0100) >> 4);
10312   if (!size_32)
10313   {
10314      bank <<= 1;
10315      if (hi_bank)
10316         bank ++;
10317
10318      prg16_89ab(space->machine(), bank);
10319      prg16_cdef(space->machine(), bank);
10320   }
10321   else
10322      prg32(space->machine(), bank);
10323
10324   if (!(offset & 0x80))
10325   {
10326      if (offset & 0x200)
10327         prg16_cdef(space->machine(), ((bank << 1) & 0x38) + 7);
10328      else
10329         prg16_cdef(space->machine(), ((bank << 1) & 0x38));
10330   }
10331
10332   set_nt_mirroring(space->machine(), BIT(data, 1) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10333}
10334
10335/*************************************************************
10336
10337 BMC-31IN1
10338
10339 Unknown Bootleg Multigame Board
10340 Games: 31 in 1
10341
10342 iNES: mapper 229
10343
10344 In MESS: Supported.
10345
10346 *************************************************************/
10347
10348static WRITE8_HANDLER( bmc_31in1_w )
10349{
10350   LOG_MMC(("bmc_31in1_w, offset: %04x, data: %02x\n", offset, data));
10351
10352   set_nt_mirroring(space->machine(), BIT(data, 5) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10353   chr8(space->machine(), offset, CHRROM);
10354
10355   if ((offset & 0x1e) == 0)
10356   {
10357      prg16_89ab(space->machine(), 0);
10358      prg16_89ab(space->machine(), 1);
10359   }
10360   else
10361   {
10362      prg16_89ab(space->machine(), offset & 0x1f);
10363      prg16_89ab(space->machine(), offset & 0x1f);
10364   }
10365}
10366
10367/*************************************************************
10368
10369 BMC-22GAMES
10370
10371 Unknown Bootleg Multigame Board
10372 Games: 22 in 1
10373
10374 iNES: mapper 230
10375
10376 In MESS: Partially Supported. It would need a reset
10377 to work (not possible yet)
10378
10379 *************************************************************/
10380
10381static WRITE8_HANDLER( bmc_22g_w )
10382{
10383   LOG_MMC(("bmc_22g_w, offset: %04x, data: %02x\n", offset, data));
10384
10385   if (1)   // this should flip at reset
10386   {
10387      prg16_89ab(space->machine(), data & 0x07);
10388   }
10389   else
10390   {
10391      if (data & 0x20)
10392      {
10393         prg16_89ab(space->machine(), (data & 0x1f) + 8);
10394         prg16_cdef(space->machine(), (data & 0x1f) + 8);
10395      }
10396      else
10397      {
10398         prg16_89ab(space->machine(), (data & 0x1f) + 8);
10399         prg16_cdef(space->machine(), (data & 0x1f) + 9);
10400      }
10401      set_nt_mirroring(space->machine(), BIT(data, 6) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
10402   }
10403}
10404
10405/*************************************************************
10406
10407 BMC-20IN1
10408
10409 Unknown Bootleg Multigame Board
10410 Games: 20 in 1
10411
10412 iNES: mapper 231
10413
10414 In MESS: Supported.
10415
10416 *************************************************************/
10417
10418static WRITE8_HANDLER( bmc_20in1_w )
10419{
10420   LOG_MMC(("bmc_20in1_w, offset: %04x, data: %02x\n", offset, data));
10421
10422   set_nt_mirroring(space->machine(), BIT(data, 7) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10423
10424   prg16_89ab(space->machine(), (offset & 0x1e));
10425   prg16_cdef(space->machine(), (offset & 0x1e) | ((offset & 0x20) ? 1 : 0));
10426}
10427
10428/*************************************************************
10429
10430 BMC-110IN1
10431
10432 Known Boards: Unknown Bootleg Board
10433 Games: 110 in 1
10434
10435 iNES: mapper 255
10436
10437 In MESS: Preliminary support.
10438
10439 *************************************************************/
10440
10441static WRITE8_HANDLER( bmc_110in1_w )
10442{
10443   UINT8 map255_helper1 = (offset >> 12) ? 0 : 1;
10444   UINT8 map255_helper2 = ((offset >> 8) & 0x40) | ((offset >> 6) & 0x3f);
10445
10446   LOG_MMC(("bmc_110in1_w, offset: %04x, data: %02x\n", offset, data));
10447
10448   set_nt_mirroring(space->machine(), (offset & 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10449   prg16_89ab(space->machine(), map255_helper1 & ~map255_helper2);
10450   prg16_cdef(space->machine(), map255_helper1 | map255_helper2);
10451   chr8(space->machine(), ((offset >> 8) & 0x40) | (offset & 0x3f), CHRROM);
10452}
10453
10454/*************************************************************
10455
10456 BMC-SUPERBIG-7IN1
10457
10458 Known Boards: Unknown Multigame Bootleg Board
10459 Games: Kunio 8 in 1, Super Big 7 in 1
10460
10461 iNES: mapper 44
10462
10463 In MESS: Supported. It also uses mmc3_irq.
10464
10465 *************************************************************/
10466
10467static WRITE8_HANDLER( bmc_sbig7_w )
10468{
10469   nes_state *state = space->machine().driver_data<nes_state>();
10470   UINT8 page;
10471   LOG_MMC(("bmc_sbig7_w, offset: %04x, data: %02x\n", offset, data));
10472
10473   switch (offset & 0x6001)
10474   {
10475      case 0x2001: /* $a001 - Select 128K ROM/VROM base (0..5) or last 256K ROM/VRAM base (6) */
10476         page = (data & 0x07);
10477         if (page > 6)
10478            page = 6;
10479
10480         state->m_mmc_prg_base = page << 4;
10481         state->m_mmc_prg_mask = (page > 5) ? 0x1f : 0x0f;
10482         state->m_mmc_chr_base = page << 7;
10483         state->m_mmc_chr_mask = (page > 5) ? 0xff : 0x7f;
10484         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10485         mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
10486         break;
10487
10488      default:
10489         txrom_w(space, offset, data);
10490         break;
10491   }
10492}
10493
10494/*************************************************************
10495
10496 BMC-HIK8IN1
10497
10498 Known Boards: Unknown Multigame Bootleg Board
10499 Games: Street Fighter V, various multigame carts
10500
10501 iNES: mapper 45
10502
10503 In MESS: Supported. It also uses mmc3_irq.
10504
10505 *************************************************************/
10506
10507static WRITE8_HANDLER( bmc_hik8_m_w )
10508{
10509   nes_state *state = space->machine().driver_data<nes_state>();
10510   LOG_MMC(("bmc_hik8_m_w, offset: %04x, data: %02x\n", offset, data));
10511
10512   /* This bit is the "register lock". Once register are locked, writes go to WRAM
10513     and there is no way to unlock them (except by resetting the machine) */
10514   if ((state->m_mmc_reg[3] & 0x40) && state->m_wram != NULL)
10515      state->m_wram[offset] = data;
10516   else
10517   {
10518      state->m_mmc_reg[state->m_mmc_count] = data;
10519      state->m_mmc_count = (state->m_mmc_count + 1) & 0x03;
10520
10521      if (!state->m_mmc_count)
10522      {
10523         LOG_MMC(("bmc_hik8_m_w, command completed %02x %02x %02x %02x\n", state->m_mmc_reg[3],
10524                state->m_mmc_reg[2], state->m_mmc_reg[1], state->m_mmc_reg[0]));
10525
10526         state->m_mmc_prg_base = state->m_mmc_reg[1];
10527         state->m_mmc_prg_mask = 0x3f ^ (state->m_mmc_reg[3] & 0x3f);
10528         state->m_mmc_chr_base = ((state->m_mmc_reg[2] & 0xf0) << 4) | state->m_mmc_reg[0];
10529         if (BIT(state->m_mmc_reg[2], 3))
10530            state->m_mmc_chr_mask = (1 << ((state->m_mmc_reg[2] & 7) + 1)) - 1;
10531         else if (state->m_mmc_reg[2])
10532            state->m_mmc_chr_mask = 0;
10533         else
10534            state->m_mmc_chr_mask = 0xff;   // i.e. we use the vrom_bank with no masking
10535
10536         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10537         mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
10538      }
10539   }
10540}
10541
10542/*************************************************************
10543
10544 BMC-SUPERHIK-4IN1
10545
10546 Known Boards: Unknown Multigame Bootleg Board
10547 Games: Super HIK 4 in 1
10548
10549 iNES: mapper 49
10550
10551 In MESS: Supported. It also uses mmc3_irq.
10552
10553 *************************************************************/
10554
10555static WRITE8_HANDLER( bmc_hik4in1_m_w )
10556{
10557   nes_state *state = space->machine().driver_data<nes_state>();
10558   LOG_MMC(("bmc_hik4in1_m_w, offset: %04x, data: %02x\n", offset, data));
10559
10560   /* mid writes only work when WRAM is enabled. not sure if I should
10561     change the condition to state->m_mmc_latch2==0x80 (i.e. what is the effect of
10562     the read-only bit?) */
10563   if (state->m_mmc3_wram_protect & 0x80)
10564   {
10565      if (data & 0x01)   /* if this is 0, then we have 32k PRG blocks */
10566      {
10567         state->m_mmc_prg_base = (data & 0xc0) >> 2;
10568         state->m_mmc_prg_mask = 0x0f;
10569         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10570      }
10571      else
10572         prg32(space->machine(), (data & 0x30) >> 4);
10573
10574      state->m_mmc_chr_base = (data & 0xc0) << 1;
10575      state->m_mmc_chr_mask = 0x7f;
10576      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
10577   }
10578}
10579
10580/*************************************************************
10581
10582 BMC-BALLGAMES-11IN1
10583
10584 Known Boards: Unknown Multigame Bootleg Board
10585 Games: 11 in 1 Ball Games
10586
10587 iNES: mapper 51
10588
10589 In MESS: Partially Supported.
10590
10591 *************************************************************/
10592
10593static void bmc_ball11_set_banks( running_machine &machine )
10594{
10595   nes_state *state = machine.driver_data<nes_state>();
10596   set_nt_mirroring(machine, (state->m_mmc_reg[0] == 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10597
10598   if (state->m_mmc_reg[0] & 0x01)
10599   {
10600      prg32(machine, state->m_mmc_reg[1]);
10601   }
10602   else
10603   {
10604      prg16_89ab(machine, (state->m_mmc_reg[1] << 1) | (state->m_mmc_reg[0] >> 1));
10605      prg16_cdef(machine, (state->m_mmc_reg[1] << 1) | 0x07);
10606   }
10607}
10608
10609static WRITE8_HANDLER( bmc_ball11_m_w )
10610{
10611   nes_state *state = space->machine().driver_data<nes_state>();
10612
10613   LOG_MMC(("bmc_ball11_m_w, offset: %04x, data: %02x\n", offset, data));
10614
10615   state->m_mmc_reg[0] = ((data >> 1) & 0x01) | ((data >> 3) & 0x02);
10616   bmc_ball11_set_banks(space->machine());
10617}
10618
10619static WRITE8_HANDLER( bmc_ball11_w )
10620{
10621   nes_state *state = space->machine().driver_data<nes_state>();
10622
10623   LOG_MMC(("bmc_ball11_w, offset: %04x, data: %02x\n", offset, data));
10624
10625   switch (offset & 0x6000)
10626   {
10627      case 0x4000:   // here we also update reg[0] upper bit
10628         state->m_mmc_reg[0] = (state->m_mmc_reg[0] & 0x01) | ((data >> 3) & 0x02);
10629      case 0x0000:
10630      case 0x2000:
10631      case 0x6000:
10632         state->m_mmc_reg[1] = data & 0x0f;
10633         bmc_ball11_set_banks(space->machine());
10634         break;
10635   }
10636}
10637
10638/*************************************************************
10639
10640 BMC-MARIOPARTY-7IN1
10641
10642 Known Boards: Unknown Multigame Bootleg Board
10643 Games: Mario 7 in 1
10644
10645 MMC3 clone
10646
10647 iNES: mapper 52
10648
10649 In MESS: Supported.
10650
10651 *************************************************************/
10652
10653static WRITE8_HANDLER( bmc_mario7in1_m_w )
10654{
10655   nes_state *state = space->machine().driver_data<nes_state>();
10656   UINT8 map52_helper1, map52_helper2;
10657   LOG_MMC(("bmc_mario7in1_m_w, offset: %04x, data: %02x\n", offset, data));
10658
10659   /* mid writes only work when WRAM is enabled. not sure if I should
10660     change the condition to state->m_mmc_latch2==0x80 (i.e. what is the effect of
10661     the read-only bit?) and it only can happen once! */
10662   if ((state->m_mmc3_wram_protect & 0x80) && !state->m_map52_reg_written)
10663   {
10664      map52_helper1 = (data & 0x08);
10665      map52_helper2 = (data & 0x40);
10666
10667      state->m_mmc_prg_base = map52_helper1 ? ((data & 0x07) << 4) : ((data & 0x06) << 4);
10668      state->m_mmc_prg_mask = map52_helper1 ? 0x0f : 0x1f;
10669      state->m_mmc_chr_base = ((data & 0x20) << 4) | ((data & 0x04) << 6) | (map52_helper2 ? ((data & 0x10) << 3) : 0);
10670      state->m_mmc_chr_mask = map52_helper2 ? 0x7f : 0xff;
10671      mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10672      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
10673
10674      state->m_map52_reg_written = 1;
10675   }
10676   else
10677      state->m_wram[offset] = data;
10678}
10679
10680/*************************************************************
10681
10682 BMC-GOLDENCARD-6IN1
10683
10684 Known Boards: Unknown Bootleg Multigame Board
10685 Games: Golden Card 6 in 1
10686
10687 MMC3 clone
10688
10689 iNES: mapper 217
10690
10691 In MESS: Supported.
10692
10693 *************************************************************/
10694
10695// remove mask & base parameters!
10696static void bmc_gc6in1_set_prg( running_machine &machine, int prg_base, int prg_mask )
10697{
10698   nes_state *state = machine.driver_data<nes_state>();
10699   state->m_mmc_prg_base = (state->m_mmc_reg[1] & 0x08) ? 0 : (state->m_mmc_reg[1] & 0x10);
10700   state->m_mmc_prg_mask = (state->m_mmc_reg[1] & 0x08) ? 0x1f : 0x0f;
10701
10702   state->m_mmc_prg_base |= ((state->m_mmc_reg[1] & 0x03) << 5);
10703
10704   mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
10705}
10706
10707static void bmc_gc6in1_set_chr( running_machine &machine, UINT8 chr )
10708{
10709   nes_state *state = machine.driver_data<nes_state>();
10710   UINT8 chr_page = (state->m_mmc_latch1 & 0x80) >> 5;
10711   int chr_base = (state->m_mmc_reg[1] & 0x08) ? 0x00 : ((state->m_mmc_reg[1] & 0x10) << 3);
10712   int chr_mask = (state->m_mmc_reg[1] & 0x08) ? 0xff : 0x7f;
10713
10714   chr_base |= ((state->m_mmc_reg[1] & 0x03) << 8);
10715
10716   chr1_x(machine, chr_page ^ 0, chr_base | ((state->m_mmc_vrom_bank[0] & ~0x01) & chr_mask), chr);
10717   chr1_x(machine, chr_page ^ 1, chr_base | ((state->m_mmc_vrom_bank[0] |  0x01) & chr_mask), chr);
10718   chr1_x(machine, chr_page ^ 2, chr_base | ((state->m_mmc_vrom_bank[1] & ~0x01) & chr_mask), chr);
10719   chr1_x(machine, chr_page ^ 3, chr_base | ((state->m_mmc_vrom_bank[1] |  0x01) & chr_mask), chr);
10720   chr1_x(machine, chr_page ^ 4, chr_base | (state->m_mmc_vrom_bank[2] & chr_mask), chr);
10721   chr1_x(machine, chr_page ^ 5, chr_base | (state->m_mmc_vrom_bank[3] & chr_mask), chr);
10722   chr1_x(machine, chr_page ^ 6, chr_base | (state->m_mmc_vrom_bank[4] & chr_mask), chr);
10723   chr1_x(machine, chr_page ^ 7, chr_base | (state->m_mmc_vrom_bank[5] & chr_mask), chr);
10724}
10725
10726static WRITE8_HANDLER( bmc_gc6in1_l_w )
10727{
10728   nes_state *state = space->machine().driver_data<nes_state>();
10729   UINT8 bank;
10730   LOG_MMC(("bmc_gc6in1_l_w, offset: %04x, data: %02x\n", offset, data));
10731   offset += 0x100;
10732
10733   if (offset == 0x1000)
10734   {
10735      state->m_mmc_reg[0] = data;
10736      if (data & 0x80)
10737      {
10738         bank = (data & 0x0f) | ((state->m_mmc_reg[1] & 0x03) << 4);
10739         prg16_89ab(space->machine(), bank);
10740         prg16_cdef(space->machine(), bank);
10741      }
10742      else
10743         bmc_gc6in1_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10744   }
10745   else if (offset == 0x1001)
10746   {
10747      state->m_mmc_reg[1] = data;
10748      bmc_gc6in1_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10749   }
10750   else if (offset == 0x1007)
10751   {
10752      state->m_mmc_reg[2] = data;
10753   }
10754}
10755
10756static WRITE8_HANDLER( bmc_gc6in1_w )
10757{
10758   nes_state *state = space->machine().driver_data<nes_state>();
10759   UINT8 mmc_helper, cmd;
10760   static const UINT8 conv_table[8] = {0, 6, 3, 7, 5, 2, 4, 1};
10761   LOG_MMC(("bmc_gc6in1_w, offset: %04x, data: %02x\n", offset, data));
10762
10763   if (!state->m_mmc_reg[2]) // in this case we act like MMC3, only with alt prg/chr handlers
10764   {
10765      switch (offset & 0x6001)
10766      {
10767         case 0x0000:
10768            mmc_helper = state->m_mmc3_latch ^ data;
10769            state->m_mmc3_latch = data;
10770
10771            /* Has PRG Mode changed? */
10772            if (mmc_helper & 0x40)
10773               bmc_gc6in1_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10774
10775            /* Has CHR Mode changed? */
10776            if (mmc_helper & 0x80)
10777               bmc_gc6in1_set_chr(space->machine(), state->m_mmc_chr_source);
10778            break;
10779
10780         case 0x0001:
10781            cmd = state->m_mmc3_latch & 0x07;
10782            switch (cmd)
10783         {
10784            case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
10785            case 2: case 3: case 4: case 5:
10786               state->m_mmc_vrom_bank[cmd] = data;
10787               bmc_gc6in1_set_chr(space->machine(), state->m_mmc_chr_source);
10788               break;
10789            case 6:
10790            case 7:
10791               state->m_mmc_prg_bank[cmd - 6] = data;
10792               bmc_gc6in1_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10793               break;
10794         }
10795            break;
10796
10797         default:
10798            txrom_w(space, offset, data);
10799            break;
10800      }
10801   }
10802   else
10803   {
10804      switch (offset & 0x6001)
10805      {
10806         case 0x0000:
10807            txrom_w(space, 0x4000, data);
10808            break;
10809
10810         case 0x0001:
10811            data = (data & 0xc0) | conv_table[data & 0x07];
10812            mmc_helper = state->m_mmc3_latch ^ data;
10813            state->m_mmc3_latch = data;
10814
10815            /* Has PRG Mode changed? */
10816            if (mmc_helper & 0x40)
10817               bmc_gc6in1_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10818
10819            /* Has CHR Mode changed? */
10820            if (mmc_helper & 0x80)
10821               bmc_gc6in1_set_chr(space->machine(), state->m_mmc_chr_source);
10822
10823            state->m_mmc_reg[3] = 1;
10824            break;
10825
10826         case 0x2000:
10827            cmd = state->m_mmc3_latch & 0x07;
10828            if (state->m_mmc_reg[3])
10829            {
10830               state->m_mmc_reg[3] = 0;
10831               switch (cmd)
10832               {
10833                  case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
10834                  case 2: case 3: case 4: case 5:
10835                     state->m_mmc_vrom_bank[cmd] = data;
10836                     bmc_gc6in1_set_chr(space->machine(), state->m_mmc_chr_source);
10837                     break;
10838                  case 6:
10839                  case 7:
10840                     state->m_mmc_prg_bank[cmd - 6] = data;
10841                     bmc_gc6in1_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10842                     break;
10843               }
10844            }
10845            break;
10846
10847
10848         case 0x2001:
10849            set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10850            break;
10851
10852         default:
10853            txrom_w(space, offset, data);
10854            break;
10855      }
10856   }
10857}
10858
10859/*************************************************************
10860
10861 BMC-FAMILY-4646B
10862
10863 Known Boards: Unknown Multigame Bootleg Board (4646B)
10864 Games: 2 in 1 - Family Kid & Aladdin 4
10865
10866 MMC3 clone
10867
10868 iNES: mapper 134
10869
10870 In MESS: Supported.
10871
10872 *************************************************************/
10873
10874static WRITE8_HANDLER( bmc_family4646_m_w )
10875{
10876   nes_state *state = space->machine().driver_data<nes_state>();
10877   LOG_MMC(("bmc_family4646_m_w, offset: %04x, data: %02x\n", offset, data));
10878
10879   if (offset == 0x01)
10880   {
10881      state->m_mmc_prg_base = (data & 0x02) << 4;
10882      state->m_mmc_prg_mask = 0x1f;
10883      state->m_mmc_chr_base = (data & 0x20) << 3;
10884      state->m_mmc_chr_mask = 0xff;
10885      mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
10886      mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
10887   }
10888}
10889
10890/*************************************************************
10891
10892 BMC-VT5201
10893
10894 *************************************************************/
10895
10896static WRITE8_HANDLER( bmc_vt5201_w )
10897{
10898   nes_state *state = space->machine().driver_data<nes_state>();
10899   LOG_MMC(("bmc_vt5201_w, offset: %04x, data: %02x\n", offset, data));
10900
10901   state->m_mmc_latch1 = BIT(offset, 8);
10902
10903   // not sure about this mirroring bit!!
10904   // without it TN 95 in 1 has glitches in Lunar Ball; with it TN 95 in 1 has glitches in Galaxian!
10905   set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10906   if (BIT(offset, 7))
10907   {
10908      prg16_89ab(space->machine(), (offset >> 4) & 0x07);
10909      prg16_cdef(space->machine(), (offset >> 4) & 0x07);
10910   }
10911   else
10912      prg32(space->machine(), (offset >> 5) & 0x03);
10913   chr8(space->machine(), offset, CHRROM);
10914}
10915
10916static READ8_HANDLER( bmc_vt5201_r )
10917{
10918   nes_state *state = space->machine().driver_data<nes_state>();
10919   LOG_MMC(("bmc_vt5201_r, offset: %04x\n", offset));
10920   //  state->m_mmc_dipsetting = input_port_read(space->machine(), "CARTDIPS");
10921
10922   if (state->m_mmc_latch1)
10923      return state->m_mmc_dipsetting; // cart mode, depending on the Dip Switches (always zero atm, given we have no way to add cart-based DIPs)
10924   else
10925      return mmc_hi_access_rom(space->machine(), offset);
10926}
10927
10928/*************************************************************
10929
10930 BMC-BS-5
10931
10932 Games: a few 4 in 1 multicarts
10933
10934 *************************************************************/
10935
10936static void bmc_bs5_update_banks( running_machine &machine )
10937{
10938   nes_state *state = machine.driver_data<nes_state>();
10939
10940   prg8_89(machine, state->m_mmc_prg_bank[0]);
10941   prg8_ab(machine, state->m_mmc_prg_bank[1]);
10942   prg8_cd(machine, state->m_mmc_prg_bank[2]);
10943   prg8_ef(machine, state->m_mmc_prg_bank[3]);
10944   chr2_0(machine, state->m_mmc_vrom_bank[0], CHRROM);
10945   chr2_2(machine, state->m_mmc_vrom_bank[1], CHRROM);
10946   chr2_4(machine, state->m_mmc_vrom_bank[2], CHRROM);
10947   chr2_6(machine, state->m_mmc_vrom_bank[3], CHRROM);
10948}
10949
10950static WRITE8_HANDLER( bmc_bs5_w )
10951{
10952   nes_state *state = space->machine().driver_data<nes_state>();
10953   UINT8 bs5_helper = (offset & 0xc00) >> 10;
10954   LOG_MMC(("bmc_bs5_w, offset: %04x, data: %02x\n", offset, data));
10955//  state->m_mmc_dipsetting = input_port_read(space->machine(), "CARTDIPS");
10956
10957   switch (offset & 0x7000)
10958   {
10959      case 0x0000:
10960         state->m_mmc_vrom_bank[bs5_helper] = offset & 0x1f;
10961         break;
10962      case 0x2000:
10963         if (BIT(offset, state->m_mmc_dipsetting + 4))   // mmc_dipsetting is always zero atm, given we have no way to add cart-based DIPs
10964            state->m_mmc_prg_bank[bs5_helper] = offset & 0x0f;
10965         break;
10966   }
10967   bmc_bs5_update_banks(space->machine());
10968}
10969
10970/*************************************************************
10971
10972 BMC-810544-C-A1
10973
10974 Games: 200-in-1 Elfland
10975
10976 *************************************************************/
10977
10978static WRITE8_HANDLER( bmc_810544_w )
10979{
10980   UINT8 bank = (offset >> 7);
10981   LOG_MMC(("bmc_810544_w, offset: %04x, data: %02x\n", offset, data));
10982
10983   if (!BIT(offset, 6))
10984   {
10985      prg16_89ab(space->machine(), (bank << 1) | BIT(offset, 5));
10986      prg16_cdef(space->machine(), (bank << 1) | BIT(offset, 5));
10987   }
10988   else
10989      prg32(space->machine(), bank);
10990
10991   set_nt_mirroring(space->machine(), BIT(offset, 4) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10992
10993   chr8(space->machine(), offset & 0x0f, CHRROM);
10994}
10995
10996/*************************************************************
10997
10998 BMC-NTD-03
10999
11000 *************************************************************/
11001
11002static WRITE8_HANDLER( bmc_ntd03_w )
11003{
11004   UINT8 pbank, cbank;
11005   LOG_MMC(("bmc_ntd03_w, offset: %04x, data: %02x\n", offset, data));
11006
11007   pbank = (offset >> 10) & 0x1e;
11008   cbank = ((offset & 0x300) >> 5) | (offset & 0x07);
11009
11010   if (BIT(offset, 7))
11011   {
11012      prg16_89ab(space->machine(), pbank | BIT(offset, 6));
11013      prg16_cdef(space->machine(), pbank | BIT(offset, 6));
11014   }
11015   else
11016      prg32(space->machine(), pbank >> 1);
11017
11018   set_nt_mirroring(space->machine(), BIT(offset, 10) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
11019
11020   chr8(space->machine(), cbank, CHRROM);
11021}
11022
11023/*************************************************************
11024
11025 BMC-GHOSTBUSTERS63IN1
11026
11027 in MESS: only preliminar support
11028
11029 *************************************************************/
11030
11031static void bmc_gb63_update( running_machine &machine )
11032{
11033   nes_state *state = machine.driver_data<nes_state>();
11034
11035   set_nt_mirroring(machine, BIT(state->m_mmc_reg[0], 6) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
11036
11037   if (BIT(state->m_mmc_reg[0], 5))
11038   {
11039      prg16_89ab(machine, state->m_mmc_reg[0] & 0x1f);   // FIXME: here probably we could also have PRGRAM, depending on mmc_latch1!
11040      prg16_cdef(machine, state->m_mmc_reg[0] & 0x1f);   // FIXME: here probably we could also have PRGRAM, depending on mmc_latch1!
11041   }
11042   else
11043      prg32(machine, (state->m_mmc_reg[0] & 0x1f) >> 1);   // FIXME: here probably we could also have PRGRAM, depending on mmc_latch1!
11044
11045   if (BIT(state->m_mmc_reg[1], 2))
11046      chr8(machine, 0, CHRRAM);
11047//  else
11048//      chr8(machine, 0, CHRROM);
11049}
11050
11051static WRITE8_HANDLER( bmc_gb63_w )
11052{
11053   nes_state *state = space->machine().driver_data<nes_state>();
11054   LOG_MMC(("bmc_gb63_w, offset: %04x, data: %02x\n", offset, data));
11055
11056   state->m_mmc_reg[offset & 1] = data;
11057   state->m_mmc_latch1 = BIT(state->m_mmc_reg[0], 7) | (BIT(state->m_mmc_reg[1], 0) << 1);
11058
11059}
11060
11061static READ8_HANDLER( bmc_gb63_r )
11062{
11063   nes_state *state = space->machine().driver_data<nes_state>();
11064   LOG_MMC(("bmc_gb63_r, offset: %04x\n", offset));
11065   //  state->m_mmc_dipsetting = input_port_read(space->machine(), "CARTDIPS");
11066
11067   if (state->m_mmc_latch1 == 1)
11068      return 0xff;   // open bus
11069   else
11070      return mmc_hi_access_rom(space->machine(), offset);
11071}
11072
11073/*************************************************************
11074
11075 UNL-EDU2000
11076
11077 *************************************************************/
11078
11079static WRITE8_HANDLER( edu2k_w )
11080{
11081   LOG_MMC(("edu2k_w, offset: %04x, data: %02x\n", offset, data));
11082
11083   prg32(space->machine(), data & 0x1f);
11084   wram_bank(space->machine(), (data & 0xc0) >> 6, NES_WRAM);
11085}
11086
11087/*************************************************************
11088
11089 UNL-H2288
11090
11091 *************************************************************/
11092
11093static void h2288_prg_cb( running_machine &machine, int start, int bank )
11094{
11095   nes_state *state = machine.driver_data<nes_state>();
11096
11097   if (!(state->m_mmc_reg[0] & 0x40))
11098      prg8_x(machine, start, bank);
11099}
11100
11101static WRITE8_HANDLER( h2288_l_w )
11102{
11103   nes_state *state = space->machine().driver_data<nes_state>();
11104   LOG_MMC(("h2288_l_w offset: %04x, data: %02x\n", offset, data));
11105   offset += 0x100;
11106
11107   if (offset >= 0x1800)
11108   {
11109      state->m_mmc_reg[offset & 1] = data;
11110      if (state->m_mmc_reg[0] & 0x40)
11111      {
11112         UINT8 helper1 = (state->m_mmc_reg[0] & 0x05) | ((state->m_mmc_reg[0] >> 2) & 0x0a);
11113         UINT8 helper2 = BIT(state->m_mmc_reg[0], 1);
11114         prg16_89ab(space->machine(), helper1 & ~helper2);
11115         prg16_cdef(space->machine(), helper1 |  helper2);
11116      }
11117      else
11118         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
11119   }
11120}
11121
11122static READ8_HANDLER( h2288_l_r )
11123{
11124   LOG_MMC(("h2288_l_r offset: %04x\n", offset));
11125   offset += 0x100;
11126
11127   if (offset >= 0x1000)
11128   {
11129      int helper = offset >> 8;
11130      if (offset & 1)
11131         return helper | 0x01;
11132      else
11133         return helper ^ 0x01;
11134   }
11135
11136   return 0;
11137}
11138
11139static WRITE8_HANDLER( h2288_w )
11140{
11141   static const UINT8 conv_table[8] = {0, 3, 1, 5, 6, 7, 2, 4};
11142   LOG_MMC(("h2288_w, offset: %04x, data: %02x\n", offset, data));
11143
11144   switch (offset & 0x6001)
11145   {
11146      case 0x0000:
11147         txrom_w(space, 0x0000, (data & 0xc0) | conv_table[data & 0x07]);
11148         break;
11149
11150      default:
11151         txrom_w(space, offset, data);
11152         break;
11153   }
11154}
11155
11156/*************************************************************
11157
11158 UNL-SHJY3
11159
11160 *************************************************************/
11161
11162/* I think the IRQ should only get fired if enough CPU cycles have passed, but we don't implement (yet) this part */
11163static void shjy3_irq( device_t *device, int scanline, int vblank, int blanked )
11164{
11165   nes_state *state = device->machine().driver_data<nes_state>();
11166   if (state->m_IRQ_enable & 0x02)
11167   {
11168      if (state->m_IRQ_count == 0xff)
11169      {
11170         state->m_IRQ_count = state->m_IRQ_count_latch;
11171         state->m_IRQ_enable = state->m_IRQ_enable | ((state->m_IRQ_enable & 0x01) << 1);
11172         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
11173      }
11174      else
11175         state->m_IRQ_count++;
11176   }
11177}
11178
11179static void shjy3_update( running_machine &machine )
11180{
11181   nes_state *state = machine.driver_data<nes_state>();
11182   int i;
11183
11184   prg8_89(machine, state->m_mmc_prg_bank[0]);
11185   prg8_ab(machine, state->m_mmc_prg_bank[1]);
11186
11187   for (i = 0; i < 8; i++)
11188   {
11189      UINT8 chr_bank = state->m_mmc_vrom_bank[i] | (state->m_mmc_extra_bank[i] << 4);
11190      if (state->m_mmc_vrom_bank[i] == 0xc8)
11191      {
11192         state->m_mmc_latch1 = 0;
11193         continue;
11194      }
11195      else if (state->m_mmc_vrom_bank[i] == 0x88)
11196      {
11197         state->m_mmc_latch1 = 1;
11198         continue;
11199      }
11200      if ((state->m_mmc_vrom_bank[i] == 4 || state->m_mmc_vrom_bank[i] == 5) && !state->m_mmc_latch1)
11201         chr1_x(machine, i, chr_bank & 1, CHRRAM);
11202      else
11203         chr1_x(machine, i, chr_bank, CHRROM);
11204   }
11205}
11206
11207static WRITE8_HANDLER( shjy3_w )
11208{
11209   nes_state *state = space->machine().driver_data<nes_state>();
11210   UINT8 mmc_helper, shift;
11211   LOG_MMC(("shjy3_w, offset: %04x, data: %02x\n", offset, data));
11212
11213   if (offset >= 0x3000 && offset <= 0x600c)
11214   {
11215      mmc_helper = ((offset & 8) | (offset >> 8)) >> 3;
11216      mmc_helper += 2;
11217      mmc_helper &= 7;
11218      shift = offset & 4;
11219
11220      state->m_mmc_vrom_bank[mmc_helper] = (state->m_mmc_vrom_bank[mmc_helper] & (0xf0 >> shift)) | ((data & 0x0f) << shift);
11221      if (shift)
11222         state->m_mmc_extra_bank[mmc_helper] = data >> 4;
11223   }
11224   else
11225   {
11226      switch (offset)
11227      {
11228         case 0x0010:
11229            state->m_mmc_prg_bank[0] = data;
11230            break;
11231         case 0x2010:
11232            state->m_mmc_prg_bank[1] = data;
11233            break;
11234         case 0x1400:
11235            switch (data & 0x03)
11236            {
11237               case 0: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
11238               case 1: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
11239               case 2: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
11240               case 3: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
11241            }
11242            break;
11243         case 0x7000:
11244            state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0xf0) | (data & 0x0f);
11245            break;
11246         case 0x7004:
11247            state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0x0f) | ((data & 0x0f) << 4);
11248            break;
11249         case 0x7008:
11250            state->m_IRQ_enable = data & 0x03;
11251            if (state->m_IRQ_enable & 0x02)
11252               state->m_IRQ_count = state->m_IRQ_count_latch;
11253            break;
11254      }
11255   }
11256   shjy3_update(space->machine());
11257}
11258
11259/*************************************************************
11260
11261 UNL-603-5052
11262
11263 MMC3 + protection access in 0x4020 - 0x7fff
11264
11265 in MESS: Partial support
11266
11267 *************************************************************/
11268
11269WRITE8_HANDLER( unl_6035052_extra_w )
11270{
11271   nes_state *state = space->machine().driver_data<nes_state>();
11272   LOG_MMC(("unl_6035052_extra_w, offset: %04x, data: %02x\n", offset, data));
11273   state->m_mmc_latch1 = data & 0x03;
11274   if (state->m_mmc_latch1 == 1)
11275      state->m_mmc_latch1 = 2;
11276}
11277
11278READ8_HANDLER( unl_6035052_extra_r )
11279{
11280   nes_state *state = space->machine().driver_data<nes_state>();
11281   LOG_MMC(("unl_6035052_extra_r, offset: %04x\n", offset));
11282   return state->m_mmc_latch1;
11283}
11284
11285
11286/*************************************************************
11287
11288 BMC-POWERJOY
11289
11290 *************************************************************/
11291
11292static void pjoy84_prg_cb( running_machine &machine, int start, int bank )
11293{
11294   nes_state *state = machine.driver_data<nes_state>();
11295   UINT8 flip = (state->m_mmc3_latch & 0x40) ? 2 : 0;
11296
11297   if (!(state->m_mmc_reg[3] & 0x03))
11298      prg8_x(machine, start, bank);
11299   else if (start == flip)
11300   {
11301      if ((state->m_mmc_reg[3] & 0x03) == 0x03)
11302         prg32(machine, bank >> 2);
11303      else
11304      {
11305         prg16_89ab(machine, bank >> 1);
11306         prg16_cdef(machine, bank >> 1);
11307      }
11308   }
11309}
11310
11311static void pjoy84_chr_cb( running_machine &machine, int start, int bank, int source )
11312{
11313   nes_state *state = machine.driver_data<nes_state>();
11314
11315   if (!(state->m_mmc_reg[3] & 0x10))
11316      chr1_x(machine, start, bank, source);
11317}
11318
11319INLINE void pjoy84_set_base_mask( running_machine &machine )
11320{
11321   nes_state *state = machine.driver_data<nes_state>();
11322
11323   state->m_mmc_prg_base = ((state->m_mmc_reg[0] & (0x06 | BIT(state->m_mmc_reg[0], 6))) << 4) |
11324                  (BIT(state->m_mmc_reg[0], 4) << 7);
11325
11326   state->m_mmc_chr_base = ((~state->m_mmc_reg[0] << 0) & 0x080 & state->m_mmc_reg[2]) |
11327                  ((state->m_mmc_reg[0] << 4) & 0x080 & state->m_mmc_reg[0]) |
11328                  ((state->m_mmc_reg[0] << 3) & 0x100) |
11329                  ((state->m_mmc_reg[0] << 5) & 0x200);
11330
11331   state->m_mmc_prg_mask = BIT(state->m_mmc_reg[0], 6) ? 0x0f : 0x1f;
11332   state->m_mmc_chr_mask = BIT(state->m_mmc_reg[0], 7) ? 0x7f : 0xff;
11333}
11334
11335static WRITE8_HANDLER( pjoy84_m_w )
11336{
11337   nes_state *state = space->machine().driver_data<nes_state>();
11338   LOG_MMC(("pjoy84_m_w offset: %04x, data: %02x\n", offset, data));
11339
11340   switch (offset & 0x03)
11341   {
11342      case 0x00:
11343      case 0x03:
11344         if (state->m_mmc_reg[3] & 0x80)
11345            return;   // else we act as if offset & 3 = 1,2
11346      case 0x01:
11347      case 0x02:
11348         state->m_mmc_reg[offset & 0x03] = data;
11349         pjoy84_set_base_mask(space->machine());
11350         if (state->m_mmc_reg[3] & 0x10)
11351            chr8(space->machine(), (state->m_mmc_chr_base >> 3) | (state->m_mmc_reg[2] & 0x0f), state->m_mmc_chr_source);
11352         else
11353            mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
11354         mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
11355         break;
11356   }
11357}
11358
11359/*************************************************************
11360
11361 SOMERI TEAM
11362
11363 iNES: mapper 116
11364
11365 Emulation note about regs in MESS: currently,
11366 - state->m_mmc_cmd1 represent the board mode
11367 - state->m_mmc_reg[n] for n=0,1,2,3 represent the MMC1 regs
11368 - state->m_mmc_prg_bank[n] for n=0,...,3 represent the MMC3 PRG banks
11369 - state->m_mmc_vrom_bank[n] for n=0,...,5 represent the MMC3 CHR banks
11370 - state->m_mmc_prg_bank[n] for n=4,5 represent the VRC2 PRG banks
11371 - state->m_mmc_vrom_bank[n] for n=6,...,13 represent the VRC2 CHR banks
11372
11373 In MESS: Preliminary support
11374
11375 *************************************************************/
11376
11377// MMC1 Mode emulation
11378static void someri_mmc1_set_prg( running_machine &machine )
11379{
11380   nes_state *state = machine.driver_data<nes_state>();
11381   UINT8 prg_mode = state->m_mmc_reg[0] & 0x0c;
11382   UINT8 prg_offset = state->m_mmc_reg[1] & 0x10;
11383
11384   switch (prg_mode)
11385   {
11386      case 0x00:
11387      case 0x04:
11388         prg32(machine, (prg_offset + state->m_mmc_reg[3]) >> 1);
11389         break;
11390      case 0x08:
11391         prg16_89ab(machine, prg_offset + 0);
11392         prg16_cdef(machine, prg_offset + state->m_mmc_reg[3]);
11393         break;
11394      case 0x0c:
11395         prg16_89ab(machine, prg_offset + state->m_mmc_reg[3]);
11396         prg16_cdef(machine, prg_offset + 0x0f);
11397         break;
11398   }
11399}
11400
11401static void someri_mmc1_set_chr( running_machine &machine )
11402{
11403   nes_state *state = machine.driver_data<nes_state>();
11404   UINT8 chr_mode = BIT(state->m_mmc_reg[0], 4);
11405
11406   if (chr_mode)
11407   {
11408      chr4_0(machine, state->m_mmc_reg[1] & 0x1f, state->m_mmc_chr_source);
11409      chr4_4(machine, state->m_mmc_reg[2] & 0x1f, state->m_mmc_chr_source);
11410   }
11411   else
11412      chr8(machine, (state->m_mmc_reg[1] & 0x1f) >> 1, state->m_mmc_chr_source);
11413}
11414
11415static WRITE8_HANDLER( someri_mmc1_w )
11416{
11417   nes_state *state = space->machine().driver_data<nes_state>();
11418
11419   assert(state->m_mmc_cmd1 == 2);
11420
11421   if (data & 0x80)
11422   {
11423      state->m_mmc1_count = 0;
11424      state->m_mmc1_latch = 0;
11425
11426      state->m_mmc_reg[0] |= 0x0c;
11427      someri_mmc1_set_prg(space->machine());
11428      return;
11429   }
11430
11431   if (state->m_mmc1_count < 5)
11432   {
11433      if (state->m_mmc1_count == 0) state->m_mmc1_latch = 0;
11434      state->m_mmc1_latch >>= 1;
11435      state->m_mmc1_latch |= (data & 0x01) ? 0x10 : 0x00;
11436      state->m_mmc1_count++;
11437   }
11438
11439   if (state->m_mmc1_count == 5)
11440   {
11441      switch (offset & 0x6000)
11442      {
11443         case 0x0000:
11444            state->m_mmc_reg[0] = state->m_mmc1_latch;
11445            switch (state->m_mmc_reg[0] & 0x03)
11446            {
11447            case 0: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
11448            case 1: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
11449            case 2: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
11450            case 3: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
11451            }
11452            someri_mmc1_set_chr(space->machine());
11453            someri_mmc1_set_prg(space->machine());
11454            break;
11455         case 0x2000:
11456            state->m_mmc_reg[1] = state->m_mmc1_latch;
11457            someri_mmc1_set_chr(space->machine());
11458            someri_mmc1_set_prg(space->machine());
11459            break;
11460         case 0x4000:
11461            state->m_mmc_reg[2] = state->m_mmc1_latch;
11462            someri_mmc1_set_chr(space->machine());
11463            break;
11464         case 0x6000:
11465            state->m_mmc_reg[3] = state->m_mmc1_latch;
11466            someri_mmc1_set_prg(space->machine());
11467            break;
11468      }
11469
11470      state->m_mmc1_count = 0;
11471   }
11472}
11473
11474// MMC3 Mode emulation
11475static WRITE8_HANDLER( someri_mmc3_w )
11476{
11477   nes_state *state = space->machine().driver_data<nes_state>();
11478   UINT8 mmc_helper, cmd;
11479
11480   assert(state->m_mmc_cmd1 == 1);
11481   switch (offset & 0x6001)
11482   {
11483      case 0x0000:
11484         mmc_helper = state->m_mmc3_latch ^ data;
11485         state->m_mmc3_latch = data;
11486
11487         if (mmc_helper & 0x40)
11488            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
11489
11490         if (mmc_helper & 0x80)
11491            mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
11492         break;
11493
11494      case 0x0001:
11495         cmd = state->m_mmc3_latch & 0x07;
11496         switch (cmd)
11497         {
11498         case 0: case 1:
11499         case 2: case 3: case 4: case 5:
11500            state->m_mmc_vrom_bank[cmd] = data;
11501            mmc3_set_chr(space->machine(), state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
11502            break;
11503         case 6:
11504         case 7:
11505            state->m_mmc_prg_bank[cmd - 6] = data;
11506            mmc3_set_prg(space->machine(), state->m_mmc_prg_base, state->m_mmc_prg_mask);
11507            break;
11508         }
11509         break;
11510
11511      case 0x2000:
11512         set_nt_mirroring(space->machine(), BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
11513         break;
11514      case 0x2001: break;
11515      case 0x4000: state->m_IRQ_count_latch = data; break;
11516      case 0x4001: state->m_IRQ_count = 0; break;
11517      case 0x6000: state->m_IRQ_enable = 0; break;
11518      case 0x6001: state->m_IRQ_enable = 1; break;
11519   }
11520}
11521
11522// VRC2 Mode emulation
11523static WRITE8_HANDLER( someri_vrc2_w )
11524{
11525   nes_state *state = space->machine().driver_data<nes_state>();
11526   UINT8 bank, shift;
11527
11528   assert(state->m_mmc_cmd1 == 0);
11529
11530   if (offset < 0x1000)
11531   {
11532      state->m_mmc_prg_bank[4] = data;
11533      prg8_89(space->machine(), state->m_mmc_prg_bank[4]);
11534   }
11535   else if (offset < 0x2000)
11536   {
11537      switch (data & 0x03)
11538      {
11539         case 0x00: set_nt_mirroring(space->machine(), PPU_MIRROR_VERT); break;
11540         case 0x01: set_nt_mirroring(space->machine(), PPU_MIRROR_HORZ); break;
11541         case 0x02: set_nt_mirroring(space->machine(), PPU_MIRROR_LOW); break;
11542         case 0x03: set_nt_mirroring(space->machine(), PPU_MIRROR_HIGH); break;
11543      }
11544   }
11545   else if (offset < 0x3000)
11546   {
11547      state->m_mmc_prg_bank[5] = data;
11548      prg8_ab(space->machine(), state->m_mmc_prg_bank[5]);
11549   }
11550   else if (offset < 0x7000)
11551   {
11552      bank = ((offset & 0x7000) - 0x3000) / 0x0800 + BIT(offset, 1);
11553      shift = BIT(offset, 2) * 4;
11554      data = (data & 0x0f) << shift;
11555      state->m_mmc_vrom_bank[6 + bank] = data | state->m_mmc_chr_base;
11556      chr1_x(space->machine(), bank, state->m_mmc_vrom_bank[6 + bank], CHRROM);
11557   }
11558}
11559
11560static WRITE8_HANDLER( someri_w )
11561{
11562   nes_state *state = space->machine().driver_data<nes_state>();
11563   LOG_MMC(("someri_w mode %d, offset: %04x, data: %02x\n", state->m_mmc_cmd1, offset, data));
11564
11565   switch (state->m_mmc_cmd1)
11566   {
11567      case 0x00: someri_vrc2_w(space, offset, data); break;
11568      case 0x01: someri_mmc3_w(space, offset, data); break;
11569      case 0x02: someri_mmc1_w(space, offset, data); break;
11570   }
11571}
11572
11573static void someri_mode_update( running_machine &machine )
11574{
11575   nes_state *state = machine.driver_data<nes_state>();
11576   int i;
11577
11578   switch (state->m_mmc_cmd1)
11579   {
11580      case 0x00:
11581         prg8_89(machine, state->m_mmc_prg_bank[4]);
11582         prg8_ab(machine, state->m_mmc_prg_bank[5]);
11583         for (i = 0; i < 8; i++)
11584            chr1_x(machine, i, state->m_mmc_vrom_bank[6 + i], CHRROM);
11585         break;
11586      case 0x01:
11587         mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
11588         mmc3_set_chr(machine, state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
11589         break;
11590      case 0x02:
11591         someri_mmc1_set_prg(machine);
11592         someri_mmc1_set_chr(machine);
11593         break;
11594   }
11595}
11596
11597static WRITE8_HANDLER( someri_l_w )
11598{
11599   nes_state *state = space->machine().driver_data<nes_state>();
11600   LOG_MMC(("someri_l_w, offset: %04x, data: %02x\n", offset, data));
11601   offset += 0x100;
11602
11603   if (offset & 0x100)
11604   {
11605      state->m_mmc_cmd1 = data & 0x03;
11606      state->m_mmc_chr_base = ((state->m_mmc_cmd1 & 0x04) << 6);
11607      if (state->m_mmc_cmd1 != 1)
11608         state->m_IRQ_enable = 0;
11609      someri_mode_update(space->machine());
11610   }
11611}
11612
11613#ifdef UNUSED_FUNCTION
11614/*************************************************************
11615
11616 FUJIYA Board - mapper 170 according to NEStopia
11617
11618 Which games are supposed to use this?
11619
11620 *************************************************************/
11621
11622static WRITE8_HANDLER( fujiya_m_w )
11623{
11624   nes_state *state = space->machine().driver_data<nes_state>();
11625   LOG_MMC(("fujiya_m_w, offset: %04x, data: %02x\n", offset, data));
11626   offset += 0x6000;
11627
11628   if (offset == 0x6502 || offset == 0x7000)
11629      state->m_mmc_latch1 = (data & 0x40) << 1;
11630}
11631
11632static READ8_HANDLER( fujiya_m_r )
11633{
11634   nes_state *state = space->machine().driver_data<nes_state>();
11635   LOG_MMC(("fujiya_m_r, offset: %04x\n", offset));
11636   offset += 0x6000;
11637
11638   if (offset == 0x7001 || offset == 0x7777)
11639      return state->m_mmc_latch1 | ((offset >> 8) & 0x7f);
11640
11641   return 0;
11642}
11643#endif
11644
11645
11646
11647
11648typedef void (*nes_ppu_latch)(device_t *device, offs_t offset);
11649
11650struct nes_memory_accessor
11651{
11652   write8_space_func write;
11653   const char        *write_name;
11654   read8_space_func  read;
11655   const char        *read_name;
11656};
11657
11658typedef struct _nes_pcb_intf  nes_pcb_intf;
11659struct _nes_pcb_intf
11660{
11661   int                     mmc_pcb;
11662   nes_memory_accessor     mmc_l;  /* $4100-$5fff read/write routines */
11663   nes_memory_accessor     mmc_m;  /* $6000-$7fff read/write routines */
11664   nes_memory_accessor     mmc_h;  /* $8000-$ffff read/write routines */
11665   nes_ppu_latch           mmc_ppu_latch;
11666   ppu2c0x_scanline_cb      mmc_scanline;
11667   ppu2c0x_hblank_cb      mmc_hblank;
11668};
11669
11670#define NES_NOACCESS \
11671{FUNC_NULL, FUNC_NULL}
11672
11673#define NES_READONLY(a) \
11674{FUNC_NULL, FUNC(a)}
11675
11676#define NES_WRITEONLY(a) \
11677{FUNC(a), FUNC_NULL}
11678
11679static WRITE8_HANDLER( dummy_l_w )
11680{
11681   logerror("write access, offset: %04x, data: %02x\n", offset + 0x4100, data);
11682}
11683
11684static WRITE8_HANDLER( dummy_m_w )
11685{
11686   logerror("write access, offset: %04x, data: %02x\n", offset + 0x6000, data);
11687}
11688
11689static WRITE8_HANDLER( dummy_w )
11690{
11691   logerror("write access, offset: %04x, data: %02x\n", offset + 0x8000, data);
11692}
11693
11694static READ8_HANDLER( dummy_l_r )
11695{
11696   logerror("read access, offset: %04x\n", offset + 0x4100);
11697   return 0x00;
11698}
11699
11700static READ8_HANDLER( dummy_m_r )
11701{
11702   logerror("read access, offset: %04x\n", offset + 0x6000);
11703   return 0x00;
11704}
11705
11706static READ8_HANDLER( dummy_r )
11707{
11708   logerror("read access, offset: %04x\n", offset + 0x8000);
11709   return 0x00;
11710}
11711
11712static const nes_pcb_intf nes_intf_list[] =
11713{
11714   { STD_NROM,             NES_NOACCESS, NES_NOACCESS, NES_NOACCESS,                         NULL, NULL, NULL },
11715   { HVC_FAMBASIC,         NES_NOACCESS, NES_NOACCESS, NES_NOACCESS,                         NULL, NULL, NULL },
11716   { GG_NROM,              NES_NOACCESS, NES_NOACCESS, NES_NOACCESS,                         NULL, NULL, NULL },
11717   { STD_UXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(uxrom_w),               NULL, NULL, NULL },
11718   { STD_UN1ROM,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(un1rom_w),              NULL, NULL, NULL },
11719   { STD_CPROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(cprom_w),               NULL, NULL, NULL },
11720   { STD_CNROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(cnrom_w),               NULL, NULL, NULL },
11721   { BANDAI_PT554,         NES_NOACCESS, NES_WRITEONLY(bandai_pt554_m_w), NES_WRITEONLY(cnrom_w), NULL, NULL, NULL },
11722   { STD_AXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(axrom_w),               NULL, NULL, NULL },
11723   { STD_PXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(pxrom_w),               mmc2_latch, NULL, NULL },
11724   { STD_FXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(fxrom_w),               mmc2_latch, NULL, NULL },
11725   { STD_BXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bxrom_w),               NULL, NULL, NULL },
11726   { STD_GXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(gxrom_w),               NULL, NULL, NULL },
11727   { STD_MXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(gxrom_w),               NULL, NULL, NULL },
11728   { STD_NXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ntbrom_w),              NULL, NULL, NULL },
11729   { SUNSOFT_DCS,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ntbrom_w),              NULL, NULL, NULL },
11730   { STD_JXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(jxrom_w),               NULL, NULL, jxrom_irq },
11731   { STD_SXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sxrom_w),               NULL, NULL, NULL },
11732   { STD_SOROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sxrom_w),               NULL, NULL, NULL },
11733   { STD_SXROM_A,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sxrom_w),               NULL, NULL, NULL },
11734   { STD_SOROM_A,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sxrom_w),               NULL, NULL, NULL },
11735   { STD_TXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txrom_w),               NULL, NULL, mmc3_irq },
11736   { STD_TVROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txrom_w),               NULL, NULL, mmc3_irq },
11737   { STD_TKROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txrom_w),               NULL, NULL, mmc3_irq },
11738   { STD_HKROM,            NES_NOACCESS, {FUNC(hkrom_m_w), FUNC(hkrom_m_r)}, NES_WRITEONLY(hkrom_w),     NULL, NULL, mmc3_irq },
11739   { STD_TQROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(tqrom_w),               NULL, NULL, mmc3_irq },
11740   { STD_TXSROM,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txsrom_w),              NULL, NULL, mmc3_irq },
11741   { STD_DXROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(dxrom_w),               NULL, NULL, NULL },
11742   { STD_DRROM,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(dxrom_w),               NULL, NULL, NULL },
11743   { NAMCOT_34X3,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(dxrom_w),               NULL, NULL, NULL },
11744   { NAMCOT_3425,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(namcot3425_w),          NULL, NULL, NULL },
11745   { NAMCOT_3446,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(namcot3446_w),          NULL, NULL, NULL },
11746   { NAMCOT_3453,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(namcot3453_w),          NULL, NULL, NULL },
11747   { STD_EXROM,            {FUNC(exrom_l_w), FUNC(exrom_l_r)}, NES_NOACCESS, NES_NOACCESS,               NULL, NULL, mmc5_irq },
11748   { NES_QJ,               NES_NOACCESS, NES_WRITEONLY(qj_m_w), NES_WRITEONLY(txrom_w),      NULL, NULL, mmc3_irq },
11749   { PAL_ZZ,               NES_NOACCESS, NES_WRITEONLY(zz_m_w), NES_WRITEONLY(txrom_w),      NULL, NULL, mmc3_irq },
11750   { UXROM_CC,             NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(uxrom_cc_w),            NULL, NULL, NULL },
11751   //
11752   { DIS_74X139X74,        NES_NOACCESS, NES_WRITEONLY(dis_74x139x74_m_w), NES_NOACCESS,     NULL, NULL, NULL },
11753   { DIS_74X377,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(dis_74x377_w),          NULL, NULL, NULL },
11754   { DIS_74X161X161X32,    NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(dis_74x161x161x32_w),   NULL, NULL, NULL },
11755   { DIS_74X161X138,       NES_NOACCESS, NES_WRITEONLY(dis_74x161x138_m_w), NES_NOACCESS,    NULL, NULL, NULL },
11756   { BANDAI_LZ93,          NES_NOACCESS, NES_WRITEONLY(lz93d50_m_w), NES_WRITEONLY(lz93d50_w), NULL, NULL, bandai_lz_irq },
11757   { BANDAI_LZ93EX,        NES_NOACCESS, NES_WRITEONLY(lz93d50_m_w), NES_WRITEONLY(lz93d50_w), NULL, NULL, bandai_lz_irq },
11758   { BANDAI_FCG,           NES_NOACCESS, NES_WRITEONLY(lz93d50_m_w), NES_WRITEONLY(lz93d50_w), NULL, NULL, bandai_lz_irq },
11759   { BANDAI_DATACH,        NES_NOACCESS, NES_WRITEONLY(lz93d50_m_w), NES_WRITEONLY(lz93d50_w), NULL, NULL, bandai_lz_irq },
11760   { BANDAI_JUMP2,         NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(fjump2_w),              NULL, NULL, bandai_lz_irq },
11761   { BANDAI_KARAOKE,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bandai_ks_w),           NULL, NULL, NULL },
11762   { BANDAI_OEKAKIDS,      NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bandai_ok_w),           NULL, NULL, NULL },
11763   { IREM_G101,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(g101_w),                NULL, NULL, NULL },
11764   { IREM_LROG017,         NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(lrog017_w),             NULL, NULL, NULL },
11765   { IREM_H3001,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(h3001_w),               NULL, NULL, h3001_irq },
11766   { IREM_TAM_S1,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(tam_s1_w),              NULL, NULL, NULL },
11767   { IREM_HOLYDIV,         NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(irem_hd_w),             NULL, NULL, NULL },
11768   { JALECO_SS88006,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ss88006_w),             NULL, NULL, ss88006_irq },
11769   { JALECO_JF11,          NES_NOACCESS, NES_WRITEONLY(jf11_m_w), NES_NOACCESS,              NULL, NULL, NULL },
11770   { JALECO_JF13,          NES_NOACCESS, NES_WRITEONLY(jf13_m_w), NES_NOACCESS,              NULL, NULL, NULL },
11771   { JALECO_JF16,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(jf16_w),                NULL, NULL, NULL },
11772   { JALECO_JF17,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(jf17_w),                NULL, NULL, NULL },
11773   { JALECO_JF19,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(jf19_w),                NULL, NULL, NULL },
11774   { KONAMI_VRC1,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(konami_vrc1_w),         NULL, NULL, NULL },
11775   { KONAMI_VRC2,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(konami_vrc2_w),         NULL, NULL, NULL },
11776   { KONAMI_VRC3,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(konami_vrc3_w),         NULL, NULL, konami_irq },
11777   { KONAMI_VRC4,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(konami_vrc4_w),         NULL, NULL, konami_irq },
11778   { KONAMI_VRC6,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(konami_vrc6_w),         NULL, NULL, konami_irq },
11779   { KONAMI_VRC7,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(konami_vrc7_w),         NULL, NULL, konami_irq },
11780   { NAMCOT_163,           {FUNC(namcot163_l_w), FUNC(namcot163_l_r) }, NES_NOACCESS, NES_WRITEONLY(namcot163_w), NULL, NULL, namcot_irq },
11781   { SUNSOFT_1,            NES_NOACCESS, NES_WRITEONLY(sunsoft1_m_w), NES_NOACCESS,          NULL, NULL, NULL },
11782   { SUNSOFT_2,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sunsoft2_w),            NULL, NULL, NULL },
11783   { SUNSOFT_3,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sunsoft3_w),            NULL, NULL, sunsoft3_irq },
11784   { TAITO_TC0190FMC,      NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(tc0190fmc_w),           NULL, NULL, NULL },
11785   { TAITO_TC0190FMCP,     NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(tc0190fmc_p16_w),       NULL, NULL, mmc3_irq },
11786   { TAITO_X1_005,         NES_NOACCESS, {FUNC(x1005_m_w), FUNC(x1005_m_r)}, NES_NOACCESS,               NULL, NULL, NULL },
11787   { TAITO_X1_005_A,       NES_NOACCESS, {FUNC(x1005a_m_w), FUNC(x1005_m_r)}, NES_NOACCESS,              NULL, NULL, NULL },
11788   { TAITO_X1_017,         NES_NOACCESS, {FUNC(x1017_m_w), FUNC(x1017_m_r)}, NES_NOACCESS,               NULL, NULL, NULL },
11789   //
11790   { AGCI_50282,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(agci_50282_w),          NULL, NULL, NULL },
11791   { ACTENT_ACT52,         NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ae_act52_w),            NULL, NULL, NULL },
11792   { AVE_NINA01,           NES_NOACCESS, NES_WRITEONLY(nina01_m_w), NES_NOACCESS,            NULL, NULL, NULL },
11793   { AVE_NINA06,           NES_WRITEONLY(nina06_l_w), NES_NOACCESS, NES_NOACCESS,            NULL, NULL, NULL },
11794   { CNE_DECATHLON,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(cne_decathl_w),         NULL, NULL, NULL },
11795   { CNE_FSB,              NES_NOACCESS, NES_WRITEONLY(cne_fsb_m_w), NES_NOACCESS,           NULL, NULL, NULL },
11796   { CNE_SHLZ,             NES_WRITEONLY(cne_shlz_l_w), NES_NOACCESS, NES_NOACCESS,          NULL, NULL, NULL },
11797   { CALTRON_6IN1,         NES_NOACCESS, NES_WRITEONLY(caltron6in1_m_w), NES_WRITEONLY(caltron6in1_w),      NULL, NULL, NULL },
11798   { CAMERICA_BF9093,      NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bf9093_w),              NULL, NULL, NULL },
11799   { CAMERICA_BF9097,      NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bf9093_w),              NULL, NULL, NULL },
11800   { CAMERICA_BF9096,      NES_NOACCESS, NES_WRITEONLY(bf9096_w), NES_WRITEONLY(bf9096_w),   NULL, NULL, NULL },
11801   { CAMERICA_GOLDENFIVE,  NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(golden5_w),             NULL, NULL, NULL },
11802   { CONY_BOARD,           {FUNC(cony_l_w), FUNC(cony_l_r)}, NES_NOACCESS, NES_WRITEONLY(cony_w),        NULL, NULL, sunsoft3_irq },
11803   { DREAMTECH_BOARD,      NES_WRITEONLY(dreamtech_l_w), NES_NOACCESS, NES_NOACCESS,         NULL, NULL, NULL },
11804   { FUTUREMEDIA_BOARD,    NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(futuremedia_w),         NULL, NULL, futuremedia_irq },
11805   { FUKUTAKE_BOARD,       {FUNC(fukutake_l_w), FUNC(fukutake_l_r)}, NES_NOACCESS, NES_NOACCESS,         NULL, NULL, NULL },
11806   { GOUDER_37017,         {FUNC(gouder_sf4_l_w), FUNC(gouder_sf4_l_r)}, NES_NOACCESS, NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11807   { HENGEDIANZI_BOARD,    NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(henggedianzi_w),        NULL, NULL, NULL },
11808   { HENGEDIANZI_XJZB,     NES_WRITEONLY(heng_xjzb_l_w), NES_NOACCESS, NES_WRITEONLY(heng_xjzb_w), NULL, NULL, NULL },
11809   { HES6IN1_BOARD,        NES_WRITEONLY(hes6in1_l_w), NES_NOACCESS, NES_NOACCESS,           NULL, NULL, NULL },
11810   { HES_BOARD,            NES_WRITEONLY(hes_l_w), NES_NOACCESS, NES_NOACCESS,               NULL, NULL, NULL },
11811   { HOSENKAN_BOARD,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(hosenkan_w),            NULL, NULL, mmc3_irq },
11812   { KAISER_KS7058,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ks7058_w),              NULL, NULL, NULL },
11813   { KAISER_KS7022,        NES_NOACCESS, NES_NOACCESS, {FUNC(ks7022_w), FUNC(ks7022_r)},                 NULL, NULL, NULL },
11814   { KAISER_KS7032,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ks7032_w),              NULL, NULL, ks7032_irq },
11815   { KAISER_KS202,         NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ks202_w),               NULL, NULL, ks7032_irq },
11816   { KAISER_KS7017,      NES_WRITEONLY(ks7017_l_w), NES_NOACCESS, NES_NOACCESS,            NULL, NULL, mmc_fds_irq },
11817   { KAY_PANDAPRINCE,      {FUNC(kay_pp_l_w), FUNC(kay_pp_l_r)}, NES_NOACCESS, NES_WRITEONLY(kay_pp_w),  NULL, NULL, mmc3_irq },
11818   { KASING_BOARD,         NES_NOACCESS, NES_WRITEONLY(kasing_m_w), NES_WRITEONLY(txrom_w),  NULL, NULL, mmc3_irq },
11819   { SACHEN_74LS374,       {FUNC(sachen_74x374_l_w), FUNC(sachen_74x374_l_r)}, NES_NOACCESS, NES_NOACCESS, NULL, NULL, NULL },
11820   { SACHEN_74LS374_A,     NES_WRITEONLY(sachen_74x374a_l_w), NES_NOACCESS, NES_NOACCESS,    NULL, NULL, NULL },
11821   { SACHEN_8259A,         NES_WRITEONLY(s8259_l_w), NES_WRITEONLY(s8259_m_w), NES_NOACCESS, NULL, NULL, NULL },
11822   { SACHEN_8259B,         NES_WRITEONLY(s8259_l_w), NES_WRITEONLY(s8259_m_w), NES_NOACCESS, NULL, NULL, NULL },
11823   { SACHEN_8259C,         NES_WRITEONLY(s8259_l_w), NES_WRITEONLY(s8259_m_w), NES_NOACCESS, NULL, NULL, NULL },
11824   { SACHEN_8259D,         NES_WRITEONLY(s8259_l_w), NES_WRITEONLY(s8259_m_w), NES_NOACCESS, NULL, NULL, NULL },
11825   { SACHEN_SA009,         NES_WRITEONLY(sa009_l_w), NES_NOACCESS, NES_NOACCESS,             NULL, NULL, NULL },
11826   { SACHEN_SA0036,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sa0036_w),              NULL, NULL, NULL },
11827   { SACHEN_SA0037,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sa0037_w),              NULL, NULL, NULL },
11828   { SACHEN_SA72007,       NES_WRITEONLY(sa72007_l_w), NES_NOACCESS, NES_NOACCESS,           NULL, NULL, NULL },
11829   { SACHEN_SA72008,       NES_WRITEONLY(sa72008_l_w), NES_NOACCESS, NES_NOACCESS,           NULL, NULL, NULL },
11830   { SACHEN_TCA01,         NES_READONLY(tca01_l_r), NES_NOACCESS, NES_NOACCESS,              NULL, NULL, NULL },
11831   { SACHEN_TCU01,         NES_WRITEONLY(tcu01_l_w), NES_WRITEONLY(tcu01_m_w), NES_WRITEONLY(tcu01_w), NULL, NULL, NULL },
11832   { SACHEN_TCU02,         {FUNC(tcu02_l_w), FUNC(tcu02_l_r)}, NES_NOACCESS, NES_NOACCESS,               NULL, NULL, NULL },
11833   { SUBOR_TYPE0,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(subor0_w),              NULL, NULL, NULL },
11834   { SUBOR_TYPE1,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(subor1_w),              NULL, NULL, NULL },
11835   { MAGICSERIES_MD,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(magics_md_w),           NULL, NULL, NULL },
11836   { NANJING_BOARD,        {FUNC(nanjing_l_w), FUNC(nanjing_l_r)}, NES_NOACCESS, NES_NOACCESS,           NULL, NULL, nanjing_irq },
11837   { NITRA_TDA,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(nitra_w),               NULL, NULL, mmc3_irq },
11838   { NTDEC_ASDER,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ntdec_asder_w),         NULL, NULL, NULL },
11839   { NTDEC_FIGHTINGHERO,   NES_NOACCESS, NES_WRITEONLY(ntdec_fh_m_w), NES_NOACCESS,          NULL, NULL, NULL },
11840   { OPENCORP_DAOU306,     NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(daou306_w),             NULL, NULL, NULL },
11841   { RCM_GS2015,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(gs2015_w),              NULL, NULL, NULL },
11842   { RCM_TETRISFAMILY,     NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(rcm_tf_w),              NULL, NULL, NULL },
11843   { REXSOFT_DBZ5,         {FUNC(rex_dbz_l_w), FUNC(rex_dbz_l_r)}, NES_READONLY(rex_dbz_l_r), NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11844   { REXSOFT_SL1632,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(rex_sl1632_w),          NULL, NULL, mmc3_irq },
11845   { RUMBLESTATION_BOARD,  NES_NOACCESS, NES_WRITEONLY(rumblestation_m_w), NES_WRITEONLY(rumblestation_w),      NULL, NULL, NULL },
11846   { SOMERI_SL12,          NES_WRITEONLY(someri_l_w), NES_NOACCESS, NES_WRITEONLY(someri_w), NULL, NULL, mmc3_irq },
11847   { SUPERGAME_BOOGERMAN,  NES_WRITEONLY(sgame_boog_l_w), NES_WRITEONLY(sgame_boog_m_w), NES_WRITEONLY(sgame_boog_w), NULL, NULL, mmc3_irq },
11848   { SUPERGAME_LIONKING,   NES_NOACCESS, NES_WRITEONLY(sgame_lion_m_w), NES_WRITEONLY(sgame_lion_w), NULL, NULL, mmc3_irq },
11849   { TENGEN_800008,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(tengen_800008_w),       NULL, NULL, NULL },
11850   { TENGEN_800032,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(tengen_800032_w),       NULL, NULL, tengen_800032_irq },
11851   { TENGEN_800037,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(tengen_800037_w),       NULL, NULL, tengen_800032_irq },
11852   { TXC_22211A,           {FUNC(txc_22211_l_w), FUNC(txc_22211_l_r)}, NES_NOACCESS, NES_WRITEONLY(txc_22211_w), NULL, NULL, NULL },
11853   { TXC_22211B,           {FUNC(txc_22211_l_w), FUNC(txc_22211_l_r)}, NES_NOACCESS, NES_WRITEONLY(txc_22211b_w), NULL, NULL, NULL },
11854   { TXC_22211C,           {FUNC(txc_22211_l_w), FUNC(txc_22211c_l_r)}, NES_NOACCESS, NES_WRITEONLY(txc_22211_w), NULL, NULL, NULL },
11855   { TXC_TW,               NES_WRITEONLY(txc_tw_l_w), NES_WRITEONLY(txc_tw_m_w), NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11856   { TXC_STRIKEWOLF,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txc_strikewolf_w),      NULL, NULL, NULL },
11857   { TXC_MXMDHTWO,         NES_READONLY(txc_mxmdhtwo_l_r), NES_NOACCESS, NES_WRITEONLY(txc_mxmdhtwo_w), NULL, NULL, NULL },
11858   { WAIXING_TYPE_A,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_a_w),           NULL, NULL, mmc3_irq },
11859   { WAIXING_TYPE_A_1,     NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_a_w),           NULL, NULL, mmc3_irq },
11860   { WAIXING_TYPE_B,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_a_w),           NULL, NULL, mmc3_irq },
11861   { WAIXING_TYPE_C,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_a_w),           NULL, NULL, mmc3_irq },
11862   { WAIXING_TYPE_D,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_a_w),           NULL, NULL, mmc3_irq },
11863   { WAIXING_TYPE_E,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_a_w),           NULL, NULL, mmc3_irq },
11864   { WAIXING_TYPE_F,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_f_w),           NULL, NULL, mmc3_irq },
11865   { WAIXING_TYPE_G,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_g_w),           NULL, NULL, mmc3_irq },
11866   { WAIXING_TYPE_H,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_h_w),           NULL, NULL, mmc3_irq },
11867   { WAIXING_TYPE_I,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txrom_w),               NULL, NULL, mmc3_irq },   // this is MMC3 + possibly additional WRAM added in 0x5000-0x5fff
11868   { WAIXING_TYPE_J,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txrom_w),               NULL, NULL, mmc3_irq },   // this is MMC3 + possibly additional WRAM added in 0x5000-0x5fff
11869   { WAIXING_SGZ,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_sgz_w),         NULL, NULL, konami_irq },
11870   { WAIXING_SGZLZ,        NES_WRITEONLY(waixing_sgzlz_l_w), NES_NOACCESS, NES_NOACCESS,     NULL, NULL, NULL },
11871   { WAIXING_FFV,          NES_WRITEONLY(waixing_ffv_l_w), NES_NOACCESS, NES_NOACCESS,       NULL, NULL, NULL },
11872   { WAIXING_ZS,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_zs_w),          NULL, NULL, NULL },
11873   { WAIXING_DQ8,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_dq8_w),         NULL, NULL, NULL },
11874   { WAIXING_SECURITY,     NES_WRITEONLY(waixing_sec_l_w), NES_NOACCESS, NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11875   { WAIXING_SH2,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txrom_w),               NULL, NULL, mmc3_irq },   // this is MMC3 + possibly additional WRAM added in 0x5000-0x5fff
11876   { WAIXING_PS2,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(waixing_ps2_w),         NULL, NULL, NULL },
11877   { UNL_8237,             NES_WRITEONLY(unl_8237_l_w), NES_NOACCESS, NES_WRITEONLY(unl_8237_w),      NULL, NULL, mmc3_irq },
11878   { UNL_AX5705,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(unl_ax5705_w),          NULL, NULL, NULL },
11879   { UNL_CC21,             NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(unl_cc21_w),            NULL, NULL, NULL },
11880   { UNL_KOF97,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(unl_kof97_w),           NULL, NULL, mmc3_irq },
11881   { UNL_T230,             NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(unl_t230_w),            NULL, NULL, konami_irq },
11882   { UNL_KOF96,            {FUNC(kof96_l_w), FUNC(kof96_l_r)}, NES_NOACCESS, NES_WRITEONLY(kof96_w),     NULL, NULL, mmc3_irq },
11883   { UNL_MK2,              NES_NOACCESS, NES_WRITEONLY(mk2_m_w), NES_NOACCESS,               NULL, NULL, mmc3_irq },
11884   { UNL_N625092,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(n625092_w),             NULL, NULL, NULL },
11885   { UNL_SC127,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sc127_w),               NULL, NULL, sc127_irq },
11886   { UNL_SMB2J,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(smb2j_w),               NULL, NULL, NULL },
11887   { UNL_SUPERFIGHTER3,    NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(unl_sf3_w),             NULL, NULL, mmc3_irq },
11888   { UNL_XZY,              NES_WRITEONLY(unl_xzy_l_w), NES_NOACCESS, NES_NOACCESS,           NULL, NULL, NULL },
11889   { UNL_RACERMATE,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(unl_racmate_w),         NULL, NULL, NULL },
11890   { UNL_STUDYNGAME,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sng32_w),               NULL, NULL, NULL },
11891   { UNL_603_5052,         {FUNC(unl_6035052_extra_w), FUNC(unl_6035052_extra_r)}, {FUNC(unl_6035052_extra_w), FUNC(unl_6035052_extra_r)}, NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11892   { UNL_EDU2K,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(edu2k_w),               NULL, NULL, NULL },
11893   { UNL_SHJY3,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(shjy3_w),               NULL, NULL, shjy3_irq },
11894   { UNL_H2288,            {FUNC(h2288_l_w), FUNC(h2288_l_r)}, NES_NOACCESS, NES_WRITEONLY(h2288_w),     NULL, NULL, mmc3_irq },
11895   //
11896   { BTL_AISENSHINICOL,    NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(btl_mariobaby_w),       NULL, NULL, NULL },
11897   { BTL_DRAGONNINJA,      NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(btl_dn_w),              NULL, NULL, btl_dn_irq },
11898   { BTL_MARIOBABY,        NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(btl_mariobaby_w),       NULL, NULL, NULL },
11899   { BTL_SMB2A,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(btl_smb2a_w),           NULL, NULL, btl_smb2a_irq },
11900   { BTL_SMB2B,            NES_WRITEONLY(smb2jb_l_w), NES_NOACCESS, NES_NOACCESS,            NULL, NULL, smb2jb_irq },
11901   { BTL_SMB3,             NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(btl_smb3_w),            NULL, NULL, btl_smb3_irq },
11902   { BTL_SUPERBROS11,      NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(btl_smb11_w),           NULL, NULL, mmc3_irq },
11903   { BTL_TOBIDASE,         NES_WRITEONLY(btl_tobi_l_w), NES_NOACCESS, NES_NOACCESS,          NULL, NULL, NULL },
11904   { BTL_PIKACHUY2K,       NES_NOACCESS, {FUNC(btl_pika_y2k_m_w), FUNC(btl_pika_y2k_m_r)}, NES_WRITEONLY(btl_pika_y2k_w),  NULL, NULL, mmc3_irq },
11905   { WHIRLWIND_2706,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(whirl2706_w),           NULL, NULL, NULL },
11906   //
11907   { BMC_190IN1,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_190in1_w),          NULL, NULL, NULL },
11908   { BMC_A65AS,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_a65as_w),           NULL, NULL, NULL },
11909   { BMC_GS2004,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_gs2004_w),          NULL, NULL, NULL },
11910   { BMC_GS2013,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_gs2013_w),          NULL, NULL, NULL },
11911   { BMC_NOVELDIAMOND,     NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(novel1_w),              NULL, NULL, NULL },
11912   { BMC_9999999IN1,       NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(novel2_w),              NULL, NULL, NULL },
11913   { BMC_T262,             NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_t262_w),            NULL, NULL, NULL },
11914   { BMC_WS,               NES_NOACCESS, NES_WRITEONLY(bmc_ws_m_w), NES_NOACCESS,            NULL, NULL, NULL },
11915   { BMC_GKA,              NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_gka_w),             NULL, NULL, NULL },
11916   { BMC_GKB,              NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_gkb_w),             NULL, NULL, NULL },
11917   { BMC_SUPER_700IN1,     NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_super700in1_w),     NULL, NULL, NULL },
11918   { BMC_36IN1,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_36in1_w),           NULL, NULL, NULL },
11919   { BMC_21IN1,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_21in1_w),           NULL, NULL, NULL },
11920   { BMC_150IN1,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_150in1_w),          NULL, NULL, NULL },
11921   { BMC_35IN1,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_35in1_w),           NULL, NULL, NULL },
11922   { BMC_64IN1,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_64in1_w),           NULL, NULL, NULL },
11923   { BMC_SUPERHIK_300IN1,  NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_hik300_w),          NULL, NULL, NULL },
11924   { BMC_SUPERGUN_20IN1,   NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(supergun20in1_w),       NULL, NULL, NULL },
11925   { BMC_72IN1,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_72in1_w),           NULL, NULL, NULL },
11926   { BMC_76IN1,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_76in1_w),           NULL, NULL, NULL },
11927   { BMC_SUPER_42IN1,      NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_76in1_w),           NULL, NULL, NULL },
11928   { BMC_1200IN1,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_1200in1_w),         NULL, NULL, NULL },
11929   { BMC_31IN1,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_31in1_w),           NULL, NULL, NULL },
11930   { BMC_22GAMES,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_22g_w),             NULL, NULL, NULL },
11931   { BMC_20IN1,            NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_20in1_w),           NULL, NULL, NULL },
11932   { BMC_110IN1,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_110in1_w),          NULL, NULL, NULL },
11933   { BMC_64IN1NR,          NES_WRITEONLY(bmc_64in1nr_l_w), NES_NOACCESS, NES_WRITEONLY(bmc_64in1nr_w), NULL, NULL, NULL },
11934   { BMC_S24IN1SC03,       NES_WRITEONLY(bmc_s24in1sc03_l_w), NES_NOACCESS, NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11935   { BMC_HIK8IN1,          NES_NOACCESS, NES_WRITEONLY(bmc_hik8_m_w), NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11936   { BMC_SUPERHIK_4IN1,    NES_NOACCESS, NES_WRITEONLY(bmc_hik4in1_m_w), NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11937   { BMC_SUPERBIG_7IN1,    NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_sbig7_w),           NULL, NULL, mmc3_irq },
11938   { BMC_MARIOPARTY_7IN1,  NES_NOACCESS, NES_WRITEONLY(bmc_mario7in1_m_w), NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11939   { BMC_FAMILY_4646B,     NES_NOACCESS, NES_WRITEONLY(bmc_family4646_m_w), NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11940   { BMC_15IN1,            NES_NOACCESS, NES_WRITEONLY(bmc_15in1_m_w), NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq },
11941   { BMC_BALLGAMES_11IN1,  NES_NOACCESS, NES_WRITEONLY(bmc_ball11_m_w), NES_WRITEONLY(bmc_ball11_w), NULL, NULL, NULL },
11942   { BMC_GOLDENCARD_6IN1,  NES_WRITEONLY(bmc_gc6in1_l_w), NES_NOACCESS, NES_WRITEONLY(bmc_gc6in1_w), NULL, NULL, mmc3_irq },
11943   { BMC_VT5201,           NES_NOACCESS, NES_NOACCESS, {FUNC(bmc_vt5201_w), FUNC(bmc_vt5201_r)},         NULL, NULL, NULL },
11944   { BMC_BENSHENG_BS5,     NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_bs5_w),             NULL, NULL, NULL },
11945   { BMC_810544,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_810544_w),          NULL, NULL, NULL },
11946   { BMC_NTD_03,           NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(bmc_ntd03_w),           NULL, NULL, NULL },
11947   { BMC_G63IN1,           NES_NOACCESS, NES_NOACCESS, {FUNC(bmc_gb63_w), FUNC(bmc_gb63_r)},             NULL, NULL, NULL },
11948   { BMC_FK23C,            NES_WRITEONLY(fk23c_l_w), NES_NOACCESS, NES_WRITEONLY(fk23c_w),   NULL, NULL, mmc3_irq },
11949   { BMC_FK23CA,           NES_WRITEONLY(fk23c_l_w), NES_NOACCESS, NES_WRITEONLY(fk23c_w),   NULL, NULL, mmc3_irq },
11950   { BMC_PJOY84,           NES_NOACCESS, NES_WRITEONLY(pjoy84_m_w), NES_WRITEONLY(txrom_w),  NULL, NULL, mmc3_irq },
11951   //
11952   { FFE_MAPPER6,          NES_WRITEONLY(mapper6_l_w), NES_NOACCESS, NES_WRITEONLY(mapper6_w), NULL, NULL, ffe_irq },
11953   { FFE_MAPPER8,          NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(mapper8_w),             NULL, NULL, NULL },
11954   { FFE_MAPPER17,         NES_WRITEONLY(mapper17_l_w), NES_NOACCESS, NES_NOACCESS,          NULL, NULL, ffe_irq },
11955   // for debug and development
11956   { UNKNOWN_BOARD,        {FUNC(dummy_l_w), FUNC(dummy_l_r)}, {FUNC(dummy_m_w), FUNC(dummy_m_r)}, {FUNC(dummy_w), FUNC(dummy_r)}, NULL, NULL, NULL },
11957   //
11958   { UNSUPPORTED_BOARD,    NES_NOACCESS, NES_NOACCESS, NES_NOACCESS,                         NULL, NULL, NULL },
11959   //
11960};
11961
11962const nes_pcb_intf *nes_pcb_intf_lookup( int pcb_id )
11963{
11964   int i;
11965   for (i = 0; i < ARRAY_LENGTH(nes_intf_list); i++)
11966   {
11967      if (nes_intf_list[i].mmc_pcb == pcb_id)
11968         return &nes_intf_list[i];
11969   }
11970   return NULL;
11971}
11972
11973void pcb_handlers_setup( running_machine &machine )
11974{
11975   nes_state *state = machine.driver_data<nes_state>();
11976   const nes_pcb_intf *intf = nes_pcb_intf_lookup(state->m_pcb_id);
11977   device_t *ppu = machine.device("ppu");
11978
11979   if (intf == NULL)
11980      fatalerror("Missing PCB interface\n");
11981
11982   if (intf)
11983   {
11984      state->m_mmc_write_low = intf->mmc_l.write;
11985      state->m_mmc_write_low_name = intf->mmc_l.write_name;
11986      state->m_mmc_write_mid = intf->mmc_m.write;
11987      state->m_mmc_write_mid_name = intf->mmc_m.write_name;
11988      state->m_mmc_write = intf->mmc_h.write;
11989      state->m_mmc_write_name = intf->mmc_h.write_name;
11990      state->m_mmc_read_low = intf->mmc_l.read;
11991      state->m_mmc_read_low_name = intf->mmc_l.read_name;
11992      state->m_mmc_read_mid = intf->mmc_m.read;   // in progress
11993      state->m_mmc_read_mid_name = intf->mmc_m.read_name;
11994      state->m_mmc_read = intf->mmc_h.read;   // in progress
11995      state->m_mmc_read_name = intf->mmc_h.read_name;
11996      ppu2c0x_set_latch(ppu, intf->mmc_ppu_latch);
11997   }
11998   else
11999   {
12000      logerror("PCB %d is not yet supported, defaulting to no mapper.\n", state->m_pcb_id);
12001      state->m_mmc_write_low = NULL;
12002      state->m_mmc_write_mid = NULL;
12003      state->m_mmc_write = NULL;
12004      state->m_mmc_read_low = NULL;
12005      state->m_mmc_read_mid = NULL;   // in progress
12006      state->m_mmc_read = NULL;   // in progress
12007      ppu2c0x_set_latch(ppu, NULL);
12008   }
12009
12010   state->m_mmc3_prg_cb = prg8_x;
12011   state->m_mmc3_chr_cb = chr1_x;
12012
12013   switch (state->m_pcb_id)
12014   {
12015      case STD_TXSROM:
12016         state->m_mmc3_chr_cb = txsrom_chr_cb;
12017         break;
12018      case GOUDER_37017:
12019         state->m_mmc3_prg_cb = gouder_sf4_prg_cb;
12020         break;
12021      case KASING_BOARD:
12022         state->m_mmc3_prg_cb = kasing_prg_cb;
12023         break;
12024      case REXSOFT_DBZ5:
12025         state->m_mmc3_chr_cb = rex_dbz_chr_cb;
12026         break;
12027      case TXC_TW:
12028         state->m_mmc3_prg_cb = txc_tw_prg_cb;
12029         break;
12030      case WAIXING_TYPE_A:
12031         state->m_mmc3_chr_cb = waixing_a_chr_cb;
12032         break;
12033      case WAIXING_TYPE_A_1:
12034         state->m_mmc3_chr_cb = waixing_a1_chr_cb;
12035         break;
12036      case WAIXING_TYPE_B:
12037         state->m_mmc3_chr_cb = waixing_b_chr_cb;
12038         break;
12039      case WAIXING_TYPE_C:
12040         state->m_mmc3_chr_cb = waixing_c_chr_cb;
12041         break;
12042      case WAIXING_TYPE_D:
12043         state->m_mmc3_chr_cb = waixing_d_chr_cb;
12044         break;
12045      case WAIXING_TYPE_E:
12046         state->m_mmc3_chr_cb = waixing_e_chr_cb;
12047         break;
12048      case WAIXING_TYPE_G:
12049         state->m_mmc3_chr_cb = waixing_g_chr_cb;
12050         break;
12051      case WAIXING_TYPE_H:
12052         state->m_mmc3_chr_cb = waixing_h_chr_cb;
12053         break;
12054      case WAIXING_SECURITY:
12055         state->m_mmc3_prg_cb = waixing_sec_prg_cb;
12056         state->m_mmc3_chr_cb = waixing_sec_chr_cb;
12057         break;
12058      case WAIXING_SH2:
12059         state->m_mmc3_chr_cb = waixing_sh2_chr_cb;
12060         break;
12061      case UNL_8237:
12062         state->m_mmc3_prg_cb = unl_8237_prg_cb;
12063         state->m_mmc3_chr_cb = unl_8237_chr_cb;
12064         break;
12065      case UNL_H2288:
12066         state->m_mmc3_prg_cb = h2288_prg_cb;
12067         break;
12068      case SUPERGAME_BOOGERMAN:
12069         state->m_mmc3_prg_cb = sgame_boog_prg_cb;
12070         state->m_mmc3_chr_cb = sgame_boog_chr_cb;
12071         break;
12072      case UNL_KOF96:
12073         state->m_mmc3_prg_cb = kof96_prg_cb;
12074         state->m_mmc3_chr_cb = kof96_chr_cb;
12075         break;
12076      case KAY_PANDAPRINCE:
12077         state->m_mmc3_prg_cb = kay_pp_prg_cb;
12078         state->m_mmc3_chr_cb = kay_pp_chr_cb;
12079         break;
12080      case BMC_FK23C:
12081         state->m_mmc3_prg_cb = fk23c_prg_cb;
12082         state->m_mmc3_chr_cb = fk23c_chr_cb;
12083         break;
12084      case BMC_S24IN1SC03:
12085         state->m_mmc3_prg_cb = bmc_s24in1sc03_prg_cb;
12086         state->m_mmc3_chr_cb = bmc_s24in1sc03_chr_cb;
12087         break;
12088      case BMC_PJOY84:
12089         state->m_mmc3_prg_cb = pjoy84_prg_cb;
12090         state->m_mmc3_chr_cb = pjoy84_chr_cb;
12091         break;
12092   }
12093}
12094
12095/*************************************************************
12096
12097 pcb_initialize
12098
12099 Initialize all the necessary registers and quantities for
12100 emulation of each board
12101
12102 *************************************************************/
12103
12104/* this is used by many boards (MMC3, MMC6 + most MMC3 pirate clone boards) */
12105static void mmc3_common_initialize( running_machine &machine, int prg_mask, int chr_mask, int IRQ_type )
12106{
12107   nes_state *state = machine.driver_data<nes_state>();
12108
12109   state->m_mmc3_alt_irq = IRQ_type;      // later MMC3 boards seem to use MMC6-type IRQ... more investigations are in progress at NESDev...
12110   state->m_mmc_prg_bank[0] = state->m_mmc_prg_bank[2] = 0xfe;   // prg_bank[2] & prg_bank[3] remain always the same in most MMC3 variants
12111   state->m_mmc_prg_bank[1] = state->m_mmc_prg_bank[3] = 0xff;   // but some pirate clone mappers change them after writing certain registers
12112   state->m_mmc3_latch = 0;
12113   state->m_mmc3_wram_protect = 0x80;
12114   state->m_mmc_prg_base = state->m_mmc_chr_base = 0;
12115   state->m_mmc_prg_mask = prg_mask;
12116   state->m_mmc_chr_mask = chr_mask;
12117   mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
12118   mmc3_set_chr(machine, state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
12119}
12120
12121// WIP code
12122static int pcb_initialize( running_machine &machine, int idx )
12123{
12124   nes_state *state = machine.driver_data<nes_state>();
12125   int err = 0, i;
12126
12127   /* basic PRG config */
12128   prg32(machine, 0);
12129
12130   /* some boards will not use this, but directly CHRROM (resp. CHRRAM) if the board only has VROM (resp. VRAM) */
12131   state->m_mmc_chr_source = state->m_chr_chunks ? CHRROM : CHRRAM;
12132   chr8(machine, 0, state->m_mmc_chr_source);
12133
12134   /* Here, we init a few helpers: 4 prg banks and 16 chr banks - some mappers use them */
12135   for (i = 0; i < 4; i++)
12136      state->m_mmc_prg_bank[i] = 0;
12137   for (i = 0; i < 16; i++)
12138      state->m_mmc_vrom_bank[i] = 0;
12139   for (i = 0; i < 16; i++)
12140      state->m_mmc_extra_bank[i] = 0;
12141
12142   state->m_mmc_latch1 = 0;
12143   state->m_mmc_latch2 = 0;
12144
12145   /* Finally, we init IRQ-related quantities. */
12146   state->m_IRQ_enable = state->m_IRQ_enable_latch = 0;
12147   state->m_IRQ_count = state->m_IRQ_count_latch = 0;
12148   state->m_IRQ_toggle = 0;
12149
12150   switch (idx)
12151   {
12152         /* many boards only needs PRG to point at first 32k and CHR at first 8k */
12153      case STD_NROM:   // mapper 0
12154      case HVC_FAMBASIC:
12155      case GG_NROM:
12156      case UXROM_CC:   // mapper 180
12157      case STD_CNROM:   // mapper 3, 185
12158      case BANDAI_PT554:
12159      case TENGEN_800008:
12160      case STD_BXROM:   // mapper 34
12161      case STD_GXROM:   // mapper 66
12162      case STD_MXROM:
12163      case BANDAI_OEKAKIDS:   // mapper 96
12164      case JALECO_JF11:   // mapper 140
12165      case JALECO_JF13:   // mapper 86
12166      case JALECO_JF19:   // mapper 92
12167      case DIS_74X377:   // mapper 11
12168      case DIS_74X161X138:   // mapper 38
12169      case CALTRON_6IN1:   // mapper 41
12170      case TXC_STRIKEWOLF:   // mapper 36
12171      case UNL_STUDYNGAME:   // mapper 39
12172      case RUMBLESTATION_BOARD:   // mapper 46
12173      case BMC_GKB:   // mapper 58
12174      case RCM_TETRISFAMILY:   // mapper 61
12175      case BMC_SUPER_700IN1:   // mapper 62
12176      case MAGICSERIES_MD:   // mapper 107
12177      case HES_BOARD:   // mapper 113
12178      case HES6IN1_BOARD:   // mapper 113
12179      case SACHEN_SA72008:   // mapper 133
12180      case SACHEN_TCU02:   // mapper 136
12181      case SACHEN_SA72007:   // mapper 145
12182      case SACHEN_TCU01:   // mapper 147
12183      case SACHEN_SA009:   // mapper 160
12184      case SACHEN_SA0037:   // mapper 148
12185      case SACHEN_SA0036:   // mapper 149
12186      case AGCI_50282:   // mapper 144
12187      case KAISER_KS7058:   // mapper 171
12188      case HENGEDIANZI_BOARD:   // mapper 177
12189      case WAIXING_SGZLZ:   // mapper 178
12190      case HENGEDIANZI_XJZB:   // mapper 179
12191      case BMC_21IN1:   // mapper 201
12192      case BMC_9999999IN1:   // mapper 213
12193      case RCM_GS2015:   // mapper 216
12194      case BMC_72IN1:   // mapper 225
12195      case BMC_76IN1:   // mapper 226
12196      case BMC_SUPER_42IN1:   // mapper 226
12197      case ACTENT_ACT52:   // mapper 228
12198      case CNE_SHLZ:   // mapper 240
12199      case TXC_MXMDHTWO:   // mapper 241
12200      case WAIXING_ZS:   // mapper 242
12201      case WAIXING_DQ8:   // mapper 242
12202      case CNE_DECATHLON:   // mapper 244
12203      case UNL_CC21:
12204      case BMC_VT5201:
12205      case BMC_WS:
12206      case UNL_EDU2K:
12207         break;
12208
12209         /* other boards need additional initialization */
12210      case STD_UXROM:   // mapper 2
12211      case STD_UN1ROM:   // mapper 94
12212      case STD_JXROM:      // mapper 69
12213      case SUNSOFT_5B:
12214      case SUNSOFT_FME7:
12215      case NAMCOT_3425:   // mapper 95
12216      case DIS_74X139X74:   // mapper 87
12217      case DIS_74X161X161X32:   // mapper 152 & 70
12218      case BANDAI_LZ93:   // mapper 16, 157
12219      case BANDAI_LZ93EX:   // same + EEPROM
12220      case BANDAI_DATACH:
12221      case BANDAI_FCG:
12222      case IREM_HOLYDIV:   // mapper 78
12223      case IREM_G101:   // mapper 32
12224      case IREM_H3001:   // mapper 65
12225      case JALECO_SS88006:   // mapper 18
12226      case JALECO_JF16:   // mapper 78
12227      case JALECO_JF17:   // mapper 72
12228      case KONAMI_VRC1:   // mapper 75
12229      case KONAMI_VRC2:
12230      case KONAMI_VRC3:   // mapper 73
12231      case KONAMI_VRC4:
12232      case KONAMI_VRC6:
12233      case SUNSOFT_3:   // mapper 67
12234      case TAITO_TC0190FMC:   // mapper 33
12235      case TAITO_TC0190FMCP:   // mapper 48
12236      case TAITO_X1_005:   // mapper 80
12237      case TAITO_X1_005_A:   // mapper 207
12238      case TAITO_X1_017:   // mapper 82
12239      case NTDEC_ASDER:   // mapper 112
12240      case FUTUREMEDIA_BOARD:   // mapper 117
12241      case BTL_DRAGONNINJA:   // mapper 222
12242      case WAIXING_SGZ:   // mapper 252
12243      case UNL_T230:
12244      case BMC_NTD_03:
12245      case KAISER_KS7022:
12246      case UNL_SHJY3:
12247      case KAISER_KS7017:
12248      case KAISER_KS7032:
12249      case KAISER_KS202:
12250         prg16_89ab(machine, 0);
12251         prg16_cdef(machine, state->m_prg_chunks - 1);
12252         break;
12253
12254      case STD_CPROM:   // mapper 13
12255         chr4_0(machine, 0, CHRRAM);
12256         chr4_4(machine, 0, CHRRAM);
12257         break;
12258      case STD_AXROM:   // mapper 7
12259         set_nt_mirroring(machine, PPU_MIRROR_LOW);
12260         break;
12261      case STD_SXROM:   // mapper 1, 155
12262      case STD_SOROM:
12263      case STD_SXROM_A:
12264      case STD_SOROM_A:
12265         state->m_mmc1_latch = 0;
12266         state->m_mmc1_count = 0;
12267         state->m_mmc_reg[0] = 0x0f;
12268         state->m_mmc_reg[1] = state->m_mmc_reg[2] = state->m_mmc_reg[3] = 0;
12269         state->m_mmc1_reg_write_enable = 1;
12270         set_nt_mirroring(machine, PPU_MIRROR_HORZ);
12271         mmc1_set_chr(machine);
12272         mmc1_set_prg(machine);
12273         if (state->m_battery || state->m_wram)
12274            wram_bank(machine, 0, (idx == STD_SOROM) ? NES_WRAM : NES_BATTERY);
12275         break;
12276      case STD_PXROM:   // mapper 9
12277         state->m_mmc_reg[0] = state->m_mmc_reg[2] = 0;
12278         state->m_mmc_reg[1] = state->m_mmc_reg[3] = 0;
12279         state->m_mmc_latch1 = state->m_mmc_latch2 = 0xfe;
12280         prg8_89(machine, 0);
12281         prg8_ab(machine, (state->m_prg_chunks << 1) - 3);
12282         prg8_cd(machine, (state->m_prg_chunks << 1) - 2);
12283         prg8_ef(machine, (state->m_prg_chunks << 1) - 1);
12284         break;
12285      case STD_FXROM: // mapper 10
12286         state->m_mmc_reg[0] = state->m_mmc_reg[2] = 0;
12287         state->m_mmc_reg[1] = state->m_mmc_reg[3] = 0;
12288         state->m_mmc_latch1 = state->m_mmc_latch2 = 0xfe;
12289         prg16_89ab(machine, 0);
12290         prg16_cdef(machine, state->m_prg_chunks - 1);
12291         break;
12292      case STD_TXROM:   // mapper 4
12293      case STD_TVROM:
12294      case STD_TKROM:
12295      case REXSOFT_DBZ5:   // mapper 12
12296      case WAIXING_TYPE_A:   // mapper 74
12297      case WAIXING_TYPE_A_1:
12298      case STD_TXSROM:   // mapper 118
12299      case STD_TQROM:   // mapper 119
12300      case WAIXING_SH2:   // mapper 165
12301      case WAIXING_TYPE_B:   // mapper 191
12302      case WAIXING_TYPE_C:   // mapper 192
12303      case WAIXING_TYPE_D:   // mapper 194
12304      case WAIXING_TYPE_E:   // mapper 195
12305      case WAIXING_TYPE_H:   // mapper 245
12306      case BTL_SUPERBROS11:   // mapper 196
12307      case UNL_H2288:      // mapper 123
12308      case UNL_KOF97:
12309      case UNL_603_5052:
12310      case NITRA_TDA:   // mapper 250
12311         if (state->m_four_screen_vram)   // only TXROM and DXROM have 4-screen mirroring
12312         {
12313            set_nt_page(machine, 0, CART_NTRAM, 0, 1);
12314            set_nt_page(machine, 1, CART_NTRAM, 1, 1);
12315            set_nt_page(machine, 2, CART_NTRAM, 2, 1);
12316            set_nt_page(machine, 3, CART_NTRAM, 3, 1);
12317         }
12318         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12319         break;
12320      case STD_HKROM:   // MMC6 (basically the same as TxROM, but alt IRQ behaviour)
12321         mmc3_common_initialize(machine, 0xff, 0xff, 1);
12322         state->m_mmc6_reg = 0xf0;
12323         state->m_mmc_latch2 = 0;   // this is used differently here compared to MMC3
12324         break;
12325      case PAL_ZZ:   // mapper 37
12326         mmc3_common_initialize(machine, 0x07, 0x7f, 0);
12327         break;
12328      case NES_QJ:   // mapper 47
12329         mmc3_common_initialize(machine, 0x0f, 0x7f, 0);
12330         break;
12331      case STD_EXROM:   // mapper 5
12332         state->m_MMC5_rom_bank_mode = 3;
12333         state->m_MMC5_vrom_bank_mode = 0;
12334         state->m_MMC5_vram_protect = 0;
12335         state->m_mmc5_high_chr = 0;
12336         state->m_mmc5_vram_control = 0;
12337         state->m_mmc5_split_scr = 0;
12338         memset(state->m_MMC5_vrom_bank, 0, ARRAY_LENGTH(state->m_MMC5_vrom_bank));
12339         state->m_mmc5_prg_mode = 3;
12340         state->m_mmc5_last_chr_a = 1;
12341         state->m_mmc5_prg_regs[0] = 0xfc;
12342         state->m_mmc5_prg_regs[1] = 0xfd;
12343         state->m_mmc5_prg_regs[2] = 0xfe;
12344         state->m_mmc5_prg_regs[3] = 0xff;
12345         memset(state->m_mmc5_vrom_regA, ~0, ARRAY_LENGTH(state->m_mmc5_vrom_regA));
12346         memset(state->m_mmc5_vrom_regB, ~0, ARRAY_LENGTH(state->m_mmc5_vrom_regB));
12347         prg16_89ab(machine, state->m_prg_chunks - 2);
12348         prg16_cdef(machine, state->m_prg_chunks - 1);
12349         break;
12350      case STD_NXROM:      // mapper 68
12351      case SUNSOFT_DCS:      // mapper 68
12352         state->m_mmc_reg[0] = 0;
12353         prg16_89ab(machine, 0);
12354         prg16_cdef(machine, state->m_prg_chunks - 1);
12355         break;
12356      case NAMCOT_34X3:   // mapper 88
12357      case STD_DXROM:   // mapper 206
12358      case STD_DRROM:
12359         if (state->m_four_screen_vram)   // only TXROM and DXROM have 4-screen mirroring
12360         {
12361            set_nt_page(machine, 0, CART_NTRAM, 0, 1);
12362            set_nt_page(machine, 1, CART_NTRAM, 1, 1);
12363            set_nt_page(machine, 2, CART_NTRAM, 2, 1);
12364            set_nt_page(machine, 3, CART_NTRAM, 3, 1);
12365         }
12366      case NAMCOT_3453:   // mapper 154
12367         prg16_89ab(machine, state->m_prg_chunks - 2);
12368         prg16_cdef(machine, state->m_prg_chunks - 1);
12369         break;
12370      case NAMCOT_3446:   // mapper 76
12371         prg8_89(machine, 0);
12372         prg8_ab(machine, 1);
12373         prg16_cdef(machine, state->m_prg_chunks - 1);
12374         chr2_0(machine, 0, CHRROM);
12375         chr2_2(machine, 1, CHRROM);
12376         chr2_4(machine, 2, CHRROM);
12377         chr2_6(machine, 3, CHRROM);
12378         break;
12379      case BANDAI_JUMP2:   // mapper 153
12380         for (i = 0; i < 8; i++)
12381            state->m_mmc_reg[i] = 0;
12382         prg16_89ab(machine, 0);
12383         prg16_cdef(machine, state->m_prg_chunks - 1);
12384         fjump2_set_prg(machine);
12385         break;
12386      case BANDAI_KARAOKE:   // mapper 188
12387         prg16_89ab(machine, 0);
12388         prg16_cdef(machine, (state->m_prg_chunks - 1) ^ 0x08);
12389         break;
12390      case IREM_LROG017:   // mapper 77
12391         chr2_2(machine, 0, CHRROM);
12392         chr2_4(machine, 1, CHRROM);
12393         chr2_6(machine, 2, CHRROM);
12394         break;
12395      case IREM_TAM_S1:   // mapper 97
12396         prg16_89ab(machine, state->m_prg_chunks - 1);
12397         prg16_cdef(machine, 0);
12398         break;
12399      case KONAMI_VRC7:   // mapper 85
12400         prg8_89(machine, 0);
12401         prg8_ab(machine, 0);
12402         prg8_cd(machine, 0);
12403         prg8_ef(machine, 0xff);
12404         break;
12405      case NAMCOT_163:   // mapper 19
12406         prg16_89ab(machine, 0);
12407         prg16_cdef(machine, state->m_prg_chunks - 1);
12408         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12409         break;
12410      case SUNSOFT_1:   // mapper 184
12411      case SUNSOFT_2:   // mapper 89 & 93
12412         prg16_89ab(machine, 0);
12413         prg16_cdef(machine, state->m_prg_chunks - 1);
12414         if (!state->m_hard_mirroring)
12415            set_nt_mirroring(machine, PPU_MIRROR_LOW);
12416         break;
12417
12418         // mapper 14
12419      case REXSOFT_SL1632:
12420         state->m_mmc_extra_bank[2] = 0xfe;
12421         state->m_mmc_extra_bank[3] = 0xff;
12422         state->m_mmc_extra_bank[0] = state->m_mmc_extra_bank[1] = state->m_mmc_extra_bank[4] = state->m_mmc_extra_bank[5] = state->m_mmc_extra_bank[6] = 0;
12423         state->m_mmc_extra_bank[7] = state->m_mmc_extra_bank[8] = state->m_mmc_extra_bank[9] = state->m_mmc_extra_bank[0xa] = state->m_mmc_extra_bank[0xb] = 0;
12424         state->m_mmc_reg[0] = state->m_mmc_reg[1] = 0;
12425         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12426         break;
12427         // mapper 15
12428      case WAIXING_PS2:
12429         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12430         break;
12431
12432         // mapper 35
12433      case UNL_SC127:
12434         // mapper 42
12435      case BTL_MARIOBABY:
12436      case BTL_AISENSHINICOL:
12437         prg32(machine, 0xff);
12438         break;
12439
12440         // mapper 40
12441      case BTL_SMB2A:
12442         prg8_67(machine, 0xfe);
12443         prg8_89(machine, 0xfc);
12444         prg8_ab(machine, 0xfd);
12445         prg8_cd(machine, 0xfe);
12446         prg8_ef(machine, 0xff);
12447         break;
12448
12449         // mapper 43
12450      case UNL_SMB2J:
12451         if (state->m_battery)
12452            memset(state->m_battery_ram, 0x2000, 0xff);
12453         else if (state->m_prg_ram)
12454            memset(state->m_wram, 0x2000, 0xff);
12455         break;
12456         // mapper 44
12457      case BMC_SUPERBIG_7IN1:
12458         // mapper 49
12459      case BMC_SUPERHIK_4IN1:
12460         mmc3_common_initialize(machine, 0x0f, 0x7f, 0);
12461         break;
12462         // mapper 45
12463      case BMC_HIK8IN1:
12464         state->m_mmc_reg[0] = state->m_mmc_reg[1] = state->m_mmc_reg[2] = state->m_mmc_reg[3] = 0;
12465         mmc3_common_initialize(machine, 0x3f, 0xff, 0);
12466         break;
12467
12468         // mapper 50
12469      case BTL_SMB2B:
12470         prg8_67(machine, 0x0f);
12471         prg8_89(machine, 0x08);
12472         prg8_ab(machine, 0x09);
12473         prg8_cd(machine, 0);
12474         prg8_ef(machine, 0x0b);
12475         break;
12476         // mapper 51
12477      case BMC_BALLGAMES_11IN1:
12478         state->m_mmc_reg[0] = 0x01;
12479         state->m_mmc_reg[1] = 0x00;
12480         bmc_ball11_set_banks(machine);
12481         break;
12482         // mapper 52
12483      case BMC_MARIOPARTY_7IN1:
12484         state->m_map52_reg_written = 0;
12485         mmc3_common_initialize(machine, 0x1f, 0xff, 0);
12486         break;
12487         // mapper 54
12488      case BMC_NOVELDIAMOND:
12489         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12490         break;
12491         // mapper 57
12492      case BMC_GKA:
12493         prg16_89ab(machine, 0);
12494         prg16_cdef(machine, 0);
12495         break;
12496
12497         // mapper 64
12498      case TENGEN_800032:
12499         // mapper 158
12500      case TENGEN_800037:
12501         prg16_89ab(machine, state->m_prg_chunks - 1);
12502         prg16_cdef(machine, state->m_prg_chunks - 1);
12503         break;
12504         // mapper 71
12505      case CAMERICA_BF9097:
12506         set_nt_mirroring(machine, PPU_MIRROR_HORZ);
12507      case CAMERICA_BF9093:
12508         prg32(machine, 0xff);
12509         break;
12510
12511         // mapper 79 (& 146)
12512      case AVE_NINA06:
12513         set_nt_mirroring(machine, PPU_MIRROR_HORZ);
12514         break;
12515
12516         // mapper 83
12517      case CONY_BOARD:
12518         state->m_mapper83_reg[9] = 0x0f;
12519         prg8_cd(machine, 0x1e);
12520         prg8_ef(machine, 0x1f);
12521         break;
12522
12523         // mapper 91
12524      case UNL_MK2:
12525         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12526         prg16_89ab(machine, state->m_prg_chunks - 1);
12527         prg16_cdef(machine, state->m_prg_chunks - 1);
12528         break;
12529
12530         // mapper 104
12531      case CAMERICA_GOLDENFIVE:
12532         prg16_89ab(machine, 0x00);
12533         prg16_cdef(machine, 0x0f);
12534         break;
12535         // mapper 106
12536      case BTL_SMB3:
12537         prg8_89(machine, (state->m_prg_chunks << 1) - 1);
12538         prg8_ab(machine, 0);
12539         prg8_cd(machine, 0);
12540         prg8_ef(machine, (state->m_prg_chunks << 1) - 1);
12541         break;
12542
12543         // mapper 108
12544      case WHIRLWIND_2706:
12545         prg32(machine, 0xff);
12546         break;
12547
12548         // mapper 114
12549      case SUPERGAME_LIONKING:
12550         state->m_map114_reg = state->m_map114_reg_enabled = 0;
12551         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12552         break;
12553         // mapper 115
12554      case KASING_BOARD:
12555         state->m_mmc_reg[0] = 0;
12556         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12557         break;
12558         // mapper 116
12559      case SOMERI_SL12:
12560         state->m_mmc_prg_base = state->m_mmc_chr_base = 0;
12561         state->m_mmc_prg_mask = 0xff;
12562         state->m_mmc_chr_mask = 0xff;
12563         state->m_mmc_cmd1 = 2; // mode
12564         state->m_mmc3_latch = 0;
12565         state->m_mmc3_wram_protect = 0;
12566         // MMC1 regs
12567         state->m_mmc1_count = 0;
12568         state->m_mmc_reg[0] = 0x0c;
12569         state->m_mmc_reg[1] = 0x00;
12570         state->m_mmc_reg[2] = 0x00;
12571         state->m_mmc_reg[3] = 0x00;
12572         // MMC3 regs
12573         state->m_mmc_prg_bank[0] = 0x3c;
12574         state->m_mmc_prg_bank[1] = 0x3d;
12575         state->m_mmc_prg_bank[2] = 0xfe;
12576         state->m_mmc_prg_bank[3] = 0xff;
12577         state->m_mmc_vrom_bank[0] = 0x00;
12578         state->m_mmc_vrom_bank[1] = 0x01;
12579         state->m_mmc_vrom_bank[2] = 0x04;
12580         state->m_mmc_vrom_bank[3] = 0x05;
12581         state->m_mmc_vrom_bank[4] = 0x06;
12582         state->m_mmc_vrom_bank[5] = 0x07;
12583         // VRC2 regs
12584         state->m_mmc_prg_bank[4] = 0x00;
12585         state->m_mmc_prg_bank[5] = 0x01;
12586         for (i = 0; i < 8; ++i)
12587            state->m_mmc_vrom_bank[6 + i] = i;
12588         someri_mode_update(machine);
12589         break;
12590
12591         // mapper 120
12592      case BTL_TOBIDASE:
12593         prg32(machine, 2);
12594         break;
12595
12596         // mapper 121
12597      case KAY_PANDAPRINCE:
12598         state->m_mmc_reg[5] = state->m_mmc_reg[6] = state->m_mmc_reg[7] = 0;
12599         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12600         break;
12601
12602         // mapper 126
12603      case BMC_PJOY84:
12604         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12605         state->m_mmc_reg[0] = state->m_mmc_reg[1] = state->m_mmc_reg[2] = state->m_mmc_reg[3] = 0;
12606         pjoy84_set_base_mask(machine);
12607         mmc3_set_chr(machine, state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
12608         mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
12609         break;
12610
12611         // mapper 132
12612      case TXC_22211A:
12613         // mapper 172
12614      case TXC_22211B:
12615         // mapper 173
12616      case TXC_22211C:
12617         state->m_txc_reg[0] = state->m_txc_reg[1] = state->m_txc_reg[2] = state->m_txc_reg[3] = 0;
12618         break;
12619
12620         // mapper 134
12621      case BMC_FAMILY_4646B:
12622         mmc3_common_initialize(machine, 0x1f, 0xff, 0);
12623         break;
12624
12625         // mapper 137
12626      case SACHEN_8259D:
12627         chr8(machine, state->m_chr_chunks - 1, CHRROM);
12628         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12629         break;
12630         // mapper 138
12631      case SACHEN_8259B:
12632         // mapper 139
12633      case SACHEN_8259C:
12634         // mapper 141
12635      case SACHEN_8259A:
12636         // mapper 150
12637      case SACHEN_74LS374:
12638         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12639         break;
12640         // mapper 143
12641      case SACHEN_TCA01:
12642         prg16_89ab(machine, 0);
12643         prg16_cdef(machine, 1);
12644         break;
12645
12646         // mapper 156
12647      case OPENCORP_DAOU306:
12648         prg16_89ab(machine, state->m_prg_chunks - 2);
12649         prg16_cdef(machine, state->m_prg_chunks - 1);
12650         set_nt_mirroring(machine, PPU_MIRROR_LOW);
12651         break;
12652         // mapper 163
12653      case NANJING_BOARD:
12654         state->m_mmc_count = 0xff;
12655         state->m_mmc_reg[0] = 0xff;
12656         state->m_mmc_reg[1] = 0;
12657         prg16_89ab(machine, state->m_prg_chunks - 2);
12658         prg16_cdef(machine, state->m_prg_chunks - 1);
12659         break;
12660         // mapper 164
12661      case WAIXING_FFV:
12662         prg16_89ab(machine, 0);
12663         prg16_cdef(machine, 0x1f);
12664         break;
12665         // mapper 166
12666      case SUBOR_TYPE1:
12667         state->m_subor_reg[0] = state->m_subor_reg[1] = state->m_subor_reg[2] = state->m_subor_reg[3] = 0;
12668         prg16_89ab(machine, 0);
12669         prg16_cdef(machine, 0x07);
12670         break;
12671         // mapper 167
12672      case SUBOR_TYPE0:
12673         state->m_subor_reg[0] = state->m_subor_reg[1] = state->m_subor_reg[2] = state->m_subor_reg[3] = 0;
12674         prg16_89ab(machine, 0);
12675         prg16_cdef(machine, 0x20);
12676         break;
12677
12678         // mapper 176
12679      case UNL_XZY:
12680         // mapper 182
12681      case HOSENKAN_BOARD:
12682         prg32(machine, (state->m_prg_chunks - 1) >> 1);
12683         break;
12684
12685      case FUKUTAKE_BOARD:   // mapper 186
12686         prg16_89ab(machine, 0);
12687         prg16_cdef(machine, 0);
12688         break;
12689
12690         // mapper 187
12691      case UNL_KOF96:
12692         state->m_mmc_reg[0] = state->m_mmc_reg[1] = state->m_mmc_reg[2] = state->m_mmc_reg[3] = 0;
12693         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12694         break;
12695         // mapper 189
12696      case TXC_TW:
12697         state->m_mmc_latch1 = 0;
12698         state->m_mmc_latch2 = 0x80;
12699         state->m_mmc_chr_base = 0;
12700         state->m_mmc_chr_mask = 0xff;
12701         mmc3_set_chr(machine, state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
12702         break;
12703         // mapper 193
12704      case NTDEC_FIGHTINGHERO:
12705         prg32(machine, (state->m_prg_chunks - 1) >> 1);
12706         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12707         break;
12708         // mapper 197
12709      case UNL_SUPERFIGHTER3:
12710         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12711         unl_sf3_set_chr(machine, state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
12712         break;
12713         // mapper 198
12714      case WAIXING_TYPE_F:
12715         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12716         state->m_mmc_prg_bank[0] = 0x00;
12717         state->m_mmc_prg_bank[1] = 0x01;
12718         state->m_mmc_prg_bank[2] = 0x4e;
12719         state->m_mmc_prg_bank[3] = 0x4f;
12720         mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
12721         break;
12722         // mapper 199
12723      case WAIXING_TYPE_G:
12724         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12725         state->m_mmc_prg_bank[0] = 0x00;
12726         state->m_mmc_prg_bank[1] = 0x01;
12727         state->m_mmc_prg_bank[2] = 0x3e;
12728         state->m_mmc_prg_bank[3] = 0x3f;
12729         mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
12730         state->m_mmc_vrom_bank[0] = 0x00;
12731         state->m_mmc_vrom_bank[1] = 0x02;
12732         state->m_mmc_vrom_bank[2] = 0x04;
12733         state->m_mmc_vrom_bank[3] = 0x05;
12734         state->m_mmc_vrom_bank[4] = 0x06;
12735         state->m_mmc_vrom_bank[5] = 0x07;
12736         state->m_mmc_vrom_bank[6] = 0x01;
12737         state->m_mmc_vrom_bank[7] = 0x03;
12738         waixing_g_set_chr(machine, state->m_mmc_chr_base, state->m_mmc_chr_mask);
12739         break;
12740
12741         // mapper 200
12742      case BMC_36IN1:
12743         prg16_89ab(machine, state->m_prg_chunks - 1);
12744         prg16_cdef(machine, state->m_prg_chunks - 1);
12745         break;
12746
12747         // mapper 202
12748      case BMC_150IN1:
12749         // mapper 203
12750      case BMC_35IN1:
12751         // mapper 204
12752      case BMC_64IN1:
12753         // mapper 214
12754      case BMC_SUPERGUN_20IN1:
12755         prg16_89ab(machine, 0);
12756         prg16_cdef(machine, 0);
12757         break;
12758         // mapper 205
12759      case BMC_15IN1:
12760         mmc3_common_initialize(machine, 0x1f, 0xff, 0);
12761         state->m_mmc_prg_base = 0x10;   // this board has a diff prg_base
12762         mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
12763         break;
12764
12765         // mapper 208
12766      case GOUDER_37017:
12767         state->m_mmc_reg[0] = state->m_mmc_reg[1] = state->m_mmc_reg[2] = state->m_mmc_reg[3] = state->m_mmc_reg[4] = 0;
12768         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12769         break;
12770         // mapper 212
12771      case BMC_SUPERHIK_300IN1:
12772         chr8(machine, 0xff, CHRROM);
12773         prg32(machine, 0xff);
12774         break;
12775
12776         // mapper 215
12777      case SUPERGAME_BOOGERMAN:
12778         state->m_mmc_reg[0] = 0x00;
12779         state->m_mmc_reg[1] = 0xff;
12780         state->m_mmc_reg[2] = 0x04;
12781         state->m_mmc_reg[3] = 0;
12782         mmc3_common_initialize(machine, 0x1f, 0xff, 0);
12783         sgame_boog_set_prg(machine);
12784         mmc3_set_chr(machine, state->m_mmc_chr_source, state->m_mmc_chr_base, state->m_mmc_chr_mask);
12785         break;
12786
12787         // mapper 217
12788      case BMC_GOLDENCARD_6IN1:
12789         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12790         state->m_mmc_reg[0] = 0x00;
12791         state->m_mmc_reg[1] = 0xff;
12792         state->m_mmc_reg[2] = 0x03;
12793         state->m_mmc_reg[3] = 0;
12794         bmc_gc6in1_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
12795         bmc_gc6in1_set_chr(machine, state->m_mmc_chr_source);
12796         break;
12797         // mapper 221
12798      case UNL_N625092:
12799         prg16_89ab(machine, 0);
12800         prg16_cdef(machine, 0);
12801         break;
12802
12803         // mapper 223?
12804      case WAIXING_TYPE_I:
12805         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12806         state->m_mmc3_wram_protect = 0;
12807         break;
12808
12809         // mapper 224?
12810      case WAIXING_TYPE_J:
12811         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12812         state->m_mmc_prg_bank[0] = 0x01;
12813         state->m_mmc_prg_bank[1] = 0x02;
12814         state->m_mmc_prg_bank[2] = 0x7e;
12815         state->m_mmc_prg_bank[3] = 0x7f;
12816         mmc3_set_prg(machine, state->m_mmc_prg_base, state->m_mmc_prg_mask);
12817         break;
12818
12819         // mapper 227
12820      case BMC_1200IN1:
12821         prg16_89ab(machine, 0);
12822         prg16_cdef(machine, 0);
12823         break;
12824
12825         // mapper 229
12826      case BMC_31IN1:
12827         prg16_89ab(machine, 0);
12828         prg16_cdef(machine, 1);
12829         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12830         break;
12831         // mapper 230
12832      case BMC_22GAMES:
12833         prg16_89ab(machine, 0);
12834         prg16_cdef(machine, 7);
12835         break;
12836         // mapper 231
12837      case BMC_20IN1:
12838         prg16_89ab(machine, 0);
12839         prg16_cdef(machine, state->m_prg_chunks - 1);
12840         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12841         break;
12842         // mapper 232
12843      case CAMERICA_BF9096:
12844         state->m_mmc_latch1 = 0x18;
12845         state->m_mmc_latch2 = 0x00;
12846         bf9096_set_prg(machine);
12847         break;
12848
12849         // mapper 243
12850      case SACHEN_74LS374_A:
12851         state->m_mmc_vrom_bank[0] = 3;
12852         chr8(machine, 3, CHRROM);
12853         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12854         break;
12855
12856         // mapper 246
12857      case CNE_FSB:
12858         prg32(machine, 0xff);
12859         break;
12860         // mapper 249
12861      case WAIXING_SECURITY:
12862         state->m_mmc_reg[0] = 0;
12863         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12864         break;
12865
12866         // mapper 254
12867      case BTL_PIKACHUY2K:
12868         state->m_mmc_reg[0] = 0xff;
12869         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12870         break;
12871
12872         // mapper 255
12873      case BMC_110IN1:
12874         prg16_89ab(machine, 0);
12875         prg16_cdef(machine, 1);
12876         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12877         break;
12878
12879         // UNIF only
12880      case BMC_64IN1NR:
12881         state->m_mmc_reg[0] = 0x80;
12882         state->m_mmc_reg[1] = 0x43;
12883         state->m_mmc_reg[2] = state->m_mmc_reg[3] = 0;
12884         bmc_64in1nr_set_prg(machine);
12885         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12886         break;
12887      case BMC_190IN1:
12888         prg16_89ab(machine, 0);
12889         prg16_cdef(machine, 0);
12890         break;
12891      case BMC_A65AS:
12892         prg16_89ab(machine, 0);
12893         prg16_cdef(machine, 7);
12894         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12895         break;
12896      case BMC_GS2004:
12897      case BMC_GS2013:
12898         prg32(machine, 0xff);
12899         break;
12900      case BMC_S24IN1SC03:
12901         state->m_mmc_reg[0] = 0x24;
12902         state->m_mmc_reg[1] = 0x9f;
12903         state->m_mmc_reg[2] = 0;
12904         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12905         break;
12906      case BMC_T262:
12907         state->m_mmc_latch1 = 0;
12908         state->m_mmc_latch2 = 0;
12909         prg16_89ab(machine, 0);
12910         prg16_cdef(machine, 7);
12911         break;
12912      case DREAMTECH_BOARD:
12913         prg16_89ab(machine, 0);
12914         prg16_cdef(machine, 8);
12915         break;
12916      case UNL_8237:
12917         state->m_mmc_reg[0] = state->m_mmc_reg[1] = state->m_mmc_reg[2] = 0;
12918         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12919         break;
12920      case UNL_AX5705:
12921         state->m_mmc_prg_bank[0] = 0;
12922         state->m_mmc_prg_bank[1] = 1;
12923         prg8_89(machine, state->m_mmc_prg_bank[0]);
12924         prg8_ab(machine, state->m_mmc_prg_bank[1]);
12925         prg8_cd(machine, 0xfe);
12926         prg8_ef(machine, 0xff);
12927         break;
12928      case UNL_RACERMATE:
12929         chr4_0(machine, 0, state->m_mmc_chr_source);
12930         chr4_4(machine, 0, state->m_mmc_chr_source);
12931         prg16_89ab(machine, 0);
12932         prg16_cdef(machine, state->m_prg_chunks - 1);
12933         break;
12934
12935      case BMC_BENSHENG_BS5:
12936         state->m_mmc_prg_bank[0] = 0xff;
12937         state->m_mmc_prg_bank[1] = 0xff;
12938         state->m_mmc_prg_bank[2] = 0xff;
12939         state->m_mmc_prg_bank[3] = 0xff;
12940         bmc_bs5_update_banks(machine);
12941         break;
12942
12943      case BMC_810544:
12944         prg16_89ab(machine, 0);
12945         prg16_cdef(machine, 0);
12946         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12947         break;
12948
12949      case BMC_G63IN1:
12950         bmc_gb63_update(machine);
12951         break;
12952
12953      case BMC_FK23C:
12954         state->m_mmc_reg[0] = 4;
12955         state->m_mmc_reg[1] = 0xff;
12956         state->m_mmc_reg[2] = state->m_mmc_reg[3] = 0;
12957         state->m_mmc_reg[4] = state->m_mmc_reg[5] = state->m_mmc_reg[6] = state->m_mmc_reg[7] = 0xff;
12958         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12959         fk23c_set_prg(machine);
12960         fk23c_set_chr(machine);
12961         break;
12962
12963      case BMC_FK23CA:
12964         state->m_mmc_reg[0] = state->m_mmc_reg[1] = state->m_mmc_reg[2] = state->m_mmc_reg[3] = 0;
12965         state->m_mmc_reg[4] = state->m_mmc_reg[5] = state->m_mmc_reg[6] = state->m_mmc_reg[7] = 0xff;
12966         mmc3_common_initialize(machine, 0xff, 0xff, 0);
12967         fk23c_set_prg(machine);
12968         fk23c_set_chr(machine);
12969         break;
12970
12971
12972      case FFE_MAPPER6:
12973         prg16_89ab(machine, 0);
12974         prg16_cdef(machine, 7);
12975         break;
12976      case FFE_MAPPER8:
12977         prg32(machine, 0);
12978         break;
12979      case FFE_MAPPER17:
12980         prg16_89ab(machine, 0);
12981         prg16_cdef(machine, state->m_prg_chunks - 1);
12982         break;
12983
12984      case UNSUPPORTED_BOARD:
12985      default:
12986         /* Mapper not supported */
12987         err = 2;
12988         break;
12989   }
12990
12991   return err;
12992}
12993
12994/*************************************************************
12995
12996 nes_pcb_reset
12997
12998 Resets the mmc bankswitch areas to their defaults.
12999 It returns a value "err" that indicates if it was
13000 successful. Possible values for err are:
13001
13002 0 = success
13003 1 = no pcb found
13004 2 = pcb not supported
13005
13006 *************************************************************/
13007
13008int nes_pcb_reset( running_machine &machine )
13009{
13010   nes_state *state = machine.driver_data<nes_state>();
13011   int err = 0;
13012   const nes_pcb_intf *intf = nes_pcb_intf_lookup(state->m_pcb_id);
13013
13014   if (intf == NULL)
13015      fatalerror("Missing PCB interface\n");
13016
13017   /* Set the mapper irq callback */
13018   ppu2c0x_set_scanline_callback(state->m_ppu, intf ? intf->mmc_scanline : NULL);
13019   ppu2c0x_set_hblank_callback(state->m_ppu, intf ? intf->mmc_hblank : NULL);
13020
13021   err = pcb_initialize(machine, state->m_pcb_id);
13022
13023   return err;
13024}
src/mess/machine/amigacd.c
r11460r11461
1/***************************************************************************
2
3    Amiga CD-ROM controller emulation
4
5Notes:
6Many thanks to Toni Wilen for all the help and information about the
7DMAC controller.
8
9***************************************************************************/
10
11
12#include "emu.h"
13#include "includes/amiga.h"
14#include "amigacd.h"
15#include "machine/6525tpi.h"
16#include "machine/6526cia.h"
17#include "machine/wd33c93.h"
18#include "imagedev/chd_cd.h"
19#include "matsucd.h"
20
21
22#define VERBOSE_DMAC 0
23
24#define LOG(x) do { if (VERBOSE_DMAC) logerror x; } while (0)
25
26/* constants */
27#define CD_SECTOR_TIME      (1000/((300*1024)/2048))   /* 2X CDROM sector time in msec (300KBps) */
28
29/***************************************************************************
30
31    DMAC
32
33***************************************************************************/
34
35/*
36 * value to go into DAWR
37 */
38#define DAWR_ATZSC      3       /* according to A3000T service-manual */
39
40/*
41 * bits defined for CNTR
42 */
43#define CNTR_TCEN       (1<<7)  /* Terminal Count Enable */
44#define CNTR_PREST      (1<<6)  /* Perp Reset (not implemented :-((( ) */
45#define CNTR_PDMD       (1<<5)  /* Perp Device Mode Select (1=SCSI,0=XT/AT) */
46#define CNTR_INTEN      (1<<4)  /* Interrupt Enable */
47#define CNTR_DDIR       (1<<3)  /* Device Direction. 1==rd host, wr to perp */
48
49/*
50 * bits defined for ISTR
51 */
52#define ISTR_INTX       (1<<8)  /* XT/AT Interrupt pending */
53#define ISTR_INT_F      (1<<7)  /* Interrupt Follow */
54#define ISTR_INTS       (1<<6)  /* SCSI Peripheral Interrupt */
55#define ISTR_E_INT      (1<<5)  /* End-Of-Process Interrupt */
56#define ISTR_INT_P      (1<<4)  /* Interrupt Pending */
57#define ISTR_UE_INT     (1<<3)  /* Under-Run FIFO Error Interrupt */
58#define ISTR_OE_INT     (1<<2)  /* Over-Run FIFO Error Interrupt */
59#define ISTR_FF_FLG     (1<<1)  /* FIFO-Full Flag */
60#define ISTR_FE_FLG     (1<<0)  /* FIFO-Empty Flag */
61
62typedef struct
63{
64   UINT16      istr;      /* Interrupt Status Register (R) */
65   UINT16      cntr;      /* Control Register (RW) */
66   UINT32      wtc;      /* Word Transfer Count Register (RW) */
67   UINT32      acr;      /* Address Count Register (RW) */
68   UINT16      dawr;      /* DACK Width Register (W) */
69   emu_timer *dma_timer;
70} _dmac_data;
71
72static _dmac_data dmac_data;
73
74static void check_interrupts( running_machine &machine )
75{
76   /* if interrupts are disabled, bail */
77   if ( (dmac_data.cntr & CNTR_INTEN) == 0 )
78      return;
79
80   /* if no interrupts are pending, bail */
81   if ( (dmac_data.istr & ISTR_INT_P) == 0 )
82      return;
83
84   /* otherwise, generate the IRQ */
85   amiga_custom_w(machine.device("maincpu")->memory().space(AS_PROGRAM), REG_INTREQ, 0x8000 | INTENA_PORTS, 0xffff);
86}
87
88static TIMER_CALLBACK(dmac_dma_proc)
89{
90   amiga_state *state = machine.driver_data<amiga_state>();
91   while( dmac_data.wtc > 0 )
92   {
93      UINT16   dat16;
94      UINT8   dat8;
95
96      if ( matsucd_get_next_byte( &dat8 ) < 0 )
97         break;
98
99      dat16 = dat8;
100
101      if ( matsucd_get_next_byte( &dat8 ) < 0 )
102         break;
103
104      dat16 <<= 8;
105      dat16 |= dat8;
106
107      (*state->m_chip_ram_w)(state, dmac_data.acr, dat16);
108
109      dmac_data.acr += 2;
110      dmac_data.wtc--;
111   }
112
113   if ( dmac_data.wtc > 0 )
114   {
115      matsucd_read_next_block();
116      dmac_data.dma_timer->adjust(attotime::from_msec( CD_SECTOR_TIME ));
117   }
118   else
119   {
120      dmac_data.istr |= ISTR_INT_P | ISTR_E_INT;
121      check_interrupts( machine );
122   }
123}
124
125static READ16_HANDLER( amiga_dmac_r )
126{
127   offset &= 0xff;
128
129   switch( offset )
130   {
131      case 0x20:
132      {
133         UINT8   v = dmac_data.istr;
134         LOG(( "DMAC: PC=%08x - ISTR Read(%04x)\n", cpu_get_pc(&space->device()), dmac_data.istr ));
135
136         dmac_data.istr &= ~0x0f;
137         return v;
138      }
139      break;
140
141      case 0x21:
142      {
143         LOG(( "DMAC: PC=%08x - CNTR Read(%04x)\n", cpu_get_pc(&space->device()), dmac_data.cntr ));
144         return dmac_data.cntr;
145      }
146      break;
147
148      case 0x40:   /* wtc hi */
149      {
150         LOG(( "DMAC: PC=%08x - WTC HI Read\n", cpu_get_pc(&space->device()) ));
151         return (dmac_data.wtc >> 16);
152      }
153      break;
154
155      case 0x41:   /* wtc lo */
156      {
157         LOG(( "DMAC: PC=%08x - WTC LO Read\n", cpu_get_pc(&space->device()) ));
158         return dmac_data.wtc;
159      }
160      break;
161
162      case 0x42:   /* acr hi */
163      {
164         LOG(( "DMAC: PC=%08x - ACR HI Read\n", cpu_get_pc(&space->device()) ));
165         return (dmac_data.acr >> 16);
166      }
167      break;
168
169      case 0x43:   /* acr lo */
170      {
171         LOG(( "DMAC: PC=%08x - ACR LO Read\n", cpu_get_pc(&space->device()) ));
172         return dmac_data.acr;
173      }
174      break;
175
176      case 0x48:   /* wd33c93 SCSI expansion */
177      case 0x49:
178      {
179         LOG(( "DMAC: PC=%08x - WD33C93 Read(%d)\n", cpu_get_pc(&space->device()), offset & 1 ));
180         return 0x00;   /* Not available without SCSI expansion */
181      }
182      break;
183
184      case 0x50:
185      {
186         LOG(( "DMAC: PC=%08x - CDROM RESP Read\n", cpu_get_pc(&space->device()) ));
187         return matsucd_response_r(space->machine());
188      }
189      break;
190
191      case 0x51:   /* XT IO */
192      case 0x52:
193      case 0x53:
194      {
195         LOG(( "DMAC: PC=%08x - XT IO Read(%d)\n", cpu_get_pc(&space->device()), (offset & 3)-1 ));
196         return 0xff;
197      }
198      break;
199
200      case 0x58:   /* TPI6525 */
201      case 0x59:
202      case 0x5A:
203      case 0x5B:
204      case 0x5C:
205      case 0x5D:
206      case 0x5E:
207      case 0x5F:
208      case 0x60:
209      case 0x61:
210      case 0x62:
211      case 0x63:
212      case 0x64:
213      case 0x65:
214      case 0x66:
215      case 0x67:
216      {
217         device_t *tpi = space->machine().device("tpi6525");
218         LOG(( "DMAC: PC=%08x - TPI6525 Read(%d)\n", cpu_get_pc(&space->device()), (offset - 0x58) ));
219         return tpi6525_r(tpi, offset - 0x58);
220      }
221      break;
222
223      case 0x70:   /* DMA start strobe */
224      {
225         LOG(( "DMAC: PC=%08x - DMA Start Strobe\n", cpu_get_pc(&space->device()) ));
226         dmac_data.dma_timer->adjust(attotime::from_msec( CD_SECTOR_TIME ));
227      }
228      break;
229
230      case 0x71:   /* DMA stop strobe */
231      {
232         LOG(( "DMAC: PC=%08x - DMA Stop Strobe\n", cpu_get_pc(&space->device()) ));
233         dmac_data.dma_timer->reset(  );
234      }
235      break;
236
237      case 0x72:   /* Clear IRQ strobe */
238      {
239         LOG(( "DMAC: PC=%08x - IRQ Clear Strobe\n", cpu_get_pc(&space->device()) ));
240         dmac_data.istr &= ~ISTR_INT_P;
241      }
242      break;
243
244      case 0x74:   /* Flush strobe */
245      {
246         LOG(( "DMAC: PC=%08x - Flush Strobe\n", cpu_get_pc(&space->device()) ));
247         dmac_data.istr |= ISTR_FE_FLG;
248      }
249      break;
250
251      default:
252         logerror( "DMAC-READ: PC=%08x, offset = %02x\n", cpu_get_pc(&space->device()), offset );
253      break;
254   }
255
256   return 0;
257}
258
259static WRITE16_HANDLER( amiga_dmac_w )
260{
261   offset &= 0xff;
262
263   switch( offset )
264   {
265      case 0x21:   /* control write */
266      {
267         LOG(( "DMAC: PC=%08x - CNTR Write(%04x)\n", cpu_get_pc(&space->device()), data ));
268         dmac_data.cntr = data;
269         check_interrupts(space->machine());
270      }
271      break;
272
273      case 0x40:   /* wtc hi */
274      {
275         LOG(( "DMAC: PC=%08x - WTC HI Write - data = %04x\n", cpu_get_pc(&space->device()), data ));
276         dmac_data.wtc &= 0x0000ffff;
277         dmac_data.wtc |= ((UINT32)data) << 16;
278      }
279      break;
280
281      case 0x41:   /* wtc lo */
282      {
283         LOG(( "DMAC: PC=%08x - WTC LO Write - data = %04x\n", cpu_get_pc(&space->device()), data ));
284         dmac_data.wtc &= 0xffff0000;
285         dmac_data.wtc |= data;
286      }
287      break;
288
289      case 0x42:   /* acr hi */
290      {
291         LOG(( "DMAC: PC=%08x - ACR HI Write - data = %04x\n", cpu_get_pc(&space->device()), data ));
292         dmac_data.acr &= 0x0000ffff;
293         dmac_data.acr |= ((UINT32)data) << 16;
294      }
295      break;
296
297      case 0x43:   /* acr lo */
298      {
299         LOG(( "DMAC: PC=%08x - ACR LO Write - data = %04x\n", cpu_get_pc(&space->device()), data ));
300         dmac_data.acr &= 0xffff0000;
301         dmac_data.acr |= data;
302      }
303      break;
304
305      case 0x47:   /* dawr */
306      {
307         LOG(( "DMAC: PC=%08x - DAWR Write - data = %04x\n", cpu_get_pc(&space->device()), data ));
308         dmac_data.dawr = data;
309      }
310      break;
311
312      case 0x48:   /* wd33c93 SCSI expansion */
313      case 0x49:
314      {
315         LOG(( "DMAC: PC=%08x - WD33C93 Write(%d) - data = %04x\n", cpu_get_pc(&space->device()), offset & 1, data ));
316         /* Not available without SCSI expansion */
317      }
318      break;
319
320      case 0x50:
321      {
322         LOG(( "DMAC: PC=%08x - CDROM CMD Write - data = %04x\n", cpu_get_pc(&space->device()), data ));
323         matsucd_command_w(space->machine(), data );
324      }
325      break;
326
327      case 0x58:   /* TPI6525 */
328      case 0x59:
329      case 0x5A:
330      case 0x5B:
331      case 0x5C:
332      case 0x5D:
333      case 0x5E:
334      case 0x5F:
335      case 0x60:
336      case 0x61:
337      case 0x62:
338      case 0x63:
339      case 0x64:
340      case 0x65:
341      case 0x66:
342      case 0x67:
343      {
344         device_t *tpi = space->machine().device("tpi6525");
345         LOG(( "DMAC: PC=%08x - TPI6525 Write(%d) - data = %04x\n", cpu_get_pc(&space->device()), (offset - 0x58), data ));
346         tpi6525_w(tpi, offset - 0x58, data);
347      }
348      break;
349
350      case 0x70:   /* DMA start strobe */
351      {
352         LOG(( "DMAC: PC=%08x - DMA Start Strobe\n", cpu_get_pc(&space->device()) ));
353         dmac_data.dma_timer->adjust(attotime::from_msec( CD_SECTOR_TIME ));
354      }
355      break;
356
357      case 0x71:   /* DMA stop strobe */
358      {
359         LOG(( "DMAC: PC=%08x - DMA Stop Strobe\n", cpu_get_pc(&space->device()) ));
360         dmac_data.dma_timer->reset(  );
361      }
362      break;
363
364      case 0x72:   /* Clear IRQ strobe */
365      {
366         LOG(( "DMAC: PC=%08x - IRQ Clear Strobe\n", cpu_get_pc(&space->device()) ));
367         dmac_data.istr &= ~ISTR_INT_P;
368      }
369      break;
370
371      case 0x74:   /* Flush Strobe */
372      {
373         LOG(( "DMAC: PC=%08x - Flush Strobe\n", cpu_get_pc(&space->device()) ));
374         dmac_data.istr |= ISTR_FE_FLG;
375      }
376      break;
377
378      default:
379         logerror( "DMAC-WRITE: PC=%08x, offset = %02x, data = %04x\n", cpu_get_pc(&space->device()), offset, data );
380      break;
381   }
382}
383
384/***************************************************************************
385
386    Autoconfig
387
388***************************************************************************/
389
390static void   dmac_install(running_machine &machine, offs_t base)
391{
392   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
393   space->install_legacy_read_handler(base, base + 0xFFFF, FUNC(amiga_dmac_r));
394   space->install_legacy_write_handler(base, base + 0xFFFF, FUNC(amiga_dmac_w));
395}
396
397static void   dmac_uninstall(running_machine &machine, offs_t base)
398{
399   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
400   space->unmap_readwrite(base, base + 0xFFFF);
401}
402
403static const amiga_autoconfig_device dmac_device =
404{
405   0,            /* link into free memory list */
406   0,            /* ROM vector offset valid */
407   0,            /* multiple devices on card */
408   1,            /* number of 64k pages */
409   3,            /* product number (DMAC) */
410   0,            /* prefer 8MB address space */
411   0,            /* can be shut up */
412   0x0202,         /* manufacturers number (Commodore) */
413   0,            /* serial number */
414   0,            /* ROM vector offset */
415   NULL,         /* interrupt control read */
416   NULL,         /* interrupt control write */
417   dmac_install,   /* memory installation */
418   dmac_uninstall   /* memory uninstallation */
419};
420
421/***************************************************************************
422
423    TPI6525
424
425***************************************************************************/
426
427READ8_DEVICE_HANDLER( amigacd_tpi6525_portc_r )
428{
429   int   ret = 0;
430
431   if ( (tpi6525_get_ddr_c(device) & 0x04) == 0 ) /* if pin 2 is set to input */
432   {
433      ret |= matsucd_stch_r() ? 0x00 : 0x04;   /* read status change signal */
434   }
435
436   if ( (tpi6525_get_ddr_c(device) & 0x08) == 0 ) /* if pin 3 is set to input */
437      ret |= matsucd_sten_r() ? 0x08 : 0x00;   /* read enable signal */
438
439   return ret;
440}
441
442WRITE8_DEVICE_HANDLER( amigacd_tpi6525_portb_w )
443{
444   if ( tpi6525_get_ddr_b(device) & 0x01 ) /* if pin 0 is set to output */
445      matsucd_cmd_w( data & 1 ); /* write to the /CMD signal */
446
447   if ( tpi6525_get_ddr_b(device) & 0x02 ) /* if pin 1 is set to output */
448      matsucd_enable_w( data & 2 ); /* write to the /ENABLE signal */
449}
450
451static emu_timer *tp6525_delayed_timer;
452
453static TIMER_CALLBACK(tp6525_delayed_irq)
454{
455   amiga_state *state = machine.driver_data<amiga_state>();
456   (void)param;
457
458   if ( (CUSTOM_REG(REG_INTREQ) & INTENA_PORTS) == 0 )
459   {
460      amiga_custom_w(machine.device("maincpu")->memory().space(AS_PROGRAM), REG_INTREQ, 0x8000 | INTENA_PORTS, 0xffff);
461   }
462   else
463   {
464      tp6525_delayed_timer->adjust(attotime::from_msec(1));
465   }
466}
467
468static void amigacd_tpi6525_irq_trampoline(device_t *device, int level)
469{
470   amiga_state *state = device->machine().driver_data<amiga_state>();
471   LOG(( "TPI6525 Interrupt: level = %d\n", level ));
472
473   if ( level )
474   {
475      if ( (CUSTOM_REG(REG_INTREQ) & INTENA_PORTS) == 0 )
476      {
477         amiga_custom_w(device->machine().device("maincpu")->memory().space(AS_PROGRAM), REG_INTREQ, 0x8000 | INTENA_PORTS, 0xffff);
478      }
479      else
480      {
481         /* we *have to* deliver the irq, so if we can't, delay it and try again later */
482         tp6525_delayed_timer->adjust(attotime::from_msec(1));
483      }
484   }
485}
486
487WRITE_LINE_DEVICE_HANDLER( amigacd_tpi6525_irq )
488{
489   amigacd_tpi6525_irq_trampoline(device, state);
490}
491
492static void cdrom_status_enabled( running_machine &machine, int level )
493{
494   device_t *tpi = machine.device("tpi6525");
495
496   /* PC3 on the 6525 */
497   tpi6525_i3_w(tpi, level);
498}
499
500static void cdrom_status_change( running_machine &machine, int level )
501{
502   device_t *tpi = machine.device("tpi6525");
503
504   /* invert */
505   level = level ? 0 : 1;
506
507   /* PC2 on the 6525 */
508   tpi6525_i2_w(tpi, level);
509}
510
511static void cdrom_subcode_ready( running_machine &machine, int level )
512{
513   device_t *tpi = machine.device("tpi6525");
514
515   /* PC1 on the 6525 */
516   tpi6525_i1_w(tpi, level);
517}
518
519MACHINE_START( amigacd )
520{
521   /* initialize the dmac */
522   memset( &dmac_data, 0, sizeof( dmac_data ) );
523
524   dmac_data.dma_timer = machine.scheduler().timer_alloc(FUNC(dmac_dma_proc));
525   tp6525_delayed_timer = machine.scheduler().timer_alloc(FUNC(tp6525_delayed_irq));
526
527   /* set up DMAC with autoconfig */
528   amiga_add_autoconfig( machine, &dmac_device );
529
530   matsucd_init( machine.device("cdrom"), "cdda" );
531}
532
533MACHINE_RESET( amigacd )
534{
535   /* initialize the cdrom */
536   matsucd_set_status_enabled_callback( cdrom_status_enabled );
537   matsucd_set_status_changed_callback( cdrom_status_change );
538   matsucd_set_subcode_ready_callback( cdrom_subcode_ready );
539}
src/mess/machine/nes.c
r11460r11461
1#include "emu.h"
2#include "crsshair.h"
3#include "hash.h"
4#include "cpu/m6502/m6502.h"
5#include "video/ppu2c0x.h"
6#include "includes/nes.h"
7#include "machine/nes_mmc.h"
8#include "imagedev/cartslot.h"
9#include "imagedev/flopdrv.h"
10#include "hashfile.h"
11
12/***************************************************************************
13    CONSTANTS
14***************************************************************************/
15
16/* Set to dump info about the inputs to the errorlog */
17#define LOG_JOY      0
18
19/* Set to generate prg & chr files when the cart is loaded */
20#define SPLIT_PRG   0
21#define SPLIT_CHR   0
22
23/***************************************************************************
24    FUNCTION PROTOTYPES
25***************************************************************************/
26
27static void init_nes_core(running_machine &machine);
28static void nes_machine_stop(running_machine &machine);
29static READ8_HANDLER(nes_fds_r);
30static WRITE8_HANDLER(nes_fds_w);
31static void fds_irq(device_t *device, int scanline, int vblank, int blanked);
32
33/***************************************************************************
34    FUNCTIONS
35***************************************************************************/
36
37static void init_nes_core( running_machine &machine )
38{
39   nes_state *state = machine.driver_data<nes_state>();
40   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
41   static const char *const bank_names[] = { "bank1", "bank2", "bank3", "bank4" };
42   int prg_banks = (state->m_prg_chunks == 1) ? (2 * 2) : (state->m_prg_chunks * 2);
43   int i;
44
45   /* We set these here in case they weren't set in the cart loader */
46   state->m_rom = machine.region("maincpu")->base();
47   state->m_vrom = machine.region("gfx1")->base();
48   state->m_vram = machine.region("gfx2")->base();
49   state->m_ciram = machine.region("gfx3")->base();
50
51   /* Brutal hack put in as a consequence of the new memory system; we really need to fix the NES code */
52   space->install_readwrite_bank(0x0000, 0x07ff, 0, 0x1800, "bank10");
53
54   machine.device("ppu")->memory().space(AS_PROGRAM)->install_legacy_readwrite_handler(0, 0x1fff, FUNC(nes_chr_r), FUNC(nes_chr_w));
55   machine.device("ppu")->memory().space(AS_PROGRAM)->install_legacy_readwrite_handler(0x2000, 0x3eff, FUNC(nes_nt_r), FUNC(nes_nt_w));
56
57   memory_set_bankptr(machine, "bank10", state->m_rom);
58
59   /* If there is Disk Expansion and no cart has been loaded, setup memory accordingly */
60   if (state->m_disk_expansion && state->m_pcb_id == NO_BOARD)
61   {
62      /* If we are loading a disk we have already filled state->m_fds_data and we don't want to overwrite it,
63         if we are loading a cart image identified as mapper 20 (probably wrong mapper...) we need to alloc
64         memory for use in nes_fds_r/nes_fds_w. Same goes for allocation of fds_ram (used for bank2)  */
65      if (state->m_fds_data == NULL)
66      {
67         UINT32 size = machine.region("maincpu")->bytes() - 0x10000;
68         state->m_fds_data = auto_alloc_array_clear(machine, UINT8, size);
69         memcpy(state->m_fds_data, state->m_rom, size);   // copy in fds_data the cart PRG
70      }
71      if (state->m_fds_ram == NULL)
72         state->m_fds_ram = auto_alloc_array(machine, UINT8, 0x8000);
73
74      space->install_legacy_read_handler(0x4030, 0x403f, FUNC(nes_fds_r));
75      space->install_read_bank(0x6000, 0xdfff, "bank2");
76      space->install_read_bank(0xe000, 0xffff, "bank1");
77
78      space->install_legacy_write_handler(0x4020, 0x402f, FUNC(nes_fds_w));
79      space->install_write_bank(0x6000, 0xdfff, "bank2");
80
81      memory_set_bankptr(machine, "bank1", &state->m_rom[0xe000]);
82      memory_set_bankptr(machine, "bank2", state->m_fds_ram);
83      return;
84   }
85
86   /* Set up the mapper callbacks */
87   pcb_handlers_setup(machine);
88
89   /* Set up the memory handlers for the mapper */
90   space->install_read_bank(0x8000, 0x9fff, "bank1");
91   space->install_read_bank(0xa000, 0xbfff, "bank2");
92   space->install_read_bank(0xc000, 0xdfff, "bank3");
93   space->install_read_bank(0xe000, 0xffff, "bank4");
94   space->install_readwrite_bank(0x6000, 0x7fff, "bank5");
95
96   /* configure banks 1-4 */
97   for (i = 0; i < 4; i++)
98   {
99      memory_configure_bank(machine, bank_names[i], 0, prg_banks, machine.region("maincpu")->base() + 0x10000, 0x2000);
100      // some mappers (e.g. MMC5) can map PRG RAM in  0x8000-0xffff as well
101      if (state->m_prg_ram)
102         memory_configure_bank(machine, bank_names[i], prg_banks, state->m_wram_size / 0x2000, state->m_wram, 0x2000);
103      // however, at start we point to PRG ROM
104      memory_set_bank(machine, bank_names[i], i);
105      state->m_prg_bank[i] = i;
106   }
107
108   /* bank 5 configuration is more delicate, since it can have PRG RAM, PRG ROM or SRAM mapped to it */
109   /* we first map PRG ROM banks, then the battery bank (if a battery is present), and finally PRG RAM (state->m_wram) */
110   memory_configure_bank(machine, "bank5", 0, prg_banks, machine.region("maincpu")->base() + 0x10000, 0x2000);
111   state->m_battery_bank5_start = prg_banks;
112   state->m_prgram_bank5_start = prg_banks;
113   state->m_empty_bank5_start = prg_banks;
114
115   /* add battery ram, but only if there's no trainer since they share overlapping memory. */
116   if (state->m_battery && !state->m_trainer)
117   {
118      UINT32 bank_size = (state->m_battery_size > 0x2000) ? 0x2000 : state->m_battery_size;
119      int bank_num = (state->m_battery_size > 0x2000) ? state->m_battery_size / 0x2000 : 1;
120      memory_configure_bank(machine, "bank5", prg_banks, bank_num, state->m_battery_ram, bank_size);
121      state->m_prgram_bank5_start += bank_num;
122      state->m_empty_bank5_start += bank_num;
123   }
124   /* add prg ram. */
125   if (state->m_prg_ram)
126   {
127      memory_configure_bank(machine, "bank5", state->m_prgram_bank5_start, state->m_wram_size / 0x2000, state->m_wram, 0x2000);
128      state->m_empty_bank5_start += state->m_wram_size / 0x2000;
129   }
130
131   memory_configure_bank(machine, "bank5", state->m_empty_bank5_start, 1, state->m_rom + 0x6000, 0x2000);
132
133   /* if we have any additional PRG RAM, point bank5 to its first bank */
134   if (state->m_battery || state->m_prg_ram)
135      state->m_prg_bank[4] = state->m_battery_bank5_start;
136   else
137      state->m_prg_bank[4] = state->m_empty_bank5_start; // or shall we point to "maincpu" region at 0x6000? point is that we should never access this region if no sram or wram is present!
138
139   memory_set_bank(machine, "bank5", state->m_prg_bank[4]);
140
141   if (state->m_four_screen_vram)
142   {
143      state->m_extended_ntram = auto_alloc_array(machine, UINT8, 0x2000);
144      state->save_pointer(NAME(state->m_extended_ntram), 0x2000);
145   }
146
147   // there are still some quirk about writes to bank5... I hope to fix them soon. (mappers 34,45,52,246 have both mid_w and WRAM-->check)
148   if (state->m_mmc_write_mid)
149      space->install_legacy_write_handler(0x6000, 0x7fff, state->m_mmc_write_mid,state->m_mmc_write_mid_name);
150   if (state->m_mmc_write)
151      space->install_legacy_write_handler(0x8000, 0xffff, state->m_mmc_write, state->m_mmc_write_name);
152
153   // In fact, we also allow single pcbs to overwrite the bank read handlers defined above,
154   // because some pcbs (mainly pirate ones) require protection values to be read instead of
155   // the expected ROM banks: these handlers, though, must take care of the ROM access as well
156   if (state->m_mmc_read_mid)
157      space->install_legacy_read_handler(0x6000, 0x7fff, state->m_mmc_read_mid,state->m_mmc_read_mid_name);
158   if (state->m_mmc_read)
159      space->install_legacy_read_handler(0x8000, 0xffff, state->m_mmc_read,state->m_mmc_read_name);
160
161   // install additional handlers
162   if (state->m_pcb_id == BTL_SMB2B || state->m_mapper == 50)
163   {
164      space->install_legacy_write_handler(0x4020, 0x403f, FUNC(smb2jb_extra_w));
165      space->install_legacy_write_handler(0x40a0, 0x40bf, FUNC(smb2jb_extra_w));
166   }
167
168   if (state->m_pcb_id == KAISER_KS7017)
169   {
170      space->install_legacy_read_handler(0x4030, 0x4030, FUNC(ks7017_extra_r));
171      space->install_legacy_write_handler(0x4020, 0x40ff, FUNC(ks7017_extra_w));
172   }
173
174   if (state->m_pcb_id == UNL_603_5052)
175   {
176      space->install_legacy_read_handler(0x4020, 0x40ff, FUNC(unl_6035052_extra_r));
177      space->install_legacy_write_handler(0x4020, 0x40ff, FUNC(unl_6035052_extra_w));
178   }
179
180   if (state->m_pcb_id == WAIXING_SH2)
181      machine.device("ppu")->memory().space(AS_PROGRAM)->install_legacy_read_handler(0, 0x1fff, FUNC(waixing_sh2_chr_r));
182}
183
184// to be probably removed (it does nothing since a long time)
185int nes_ppu_vidaccess( device_t *device, int address, int data )
186{
187   return data;
188}
189
190MACHINE_RESET( nes )
191{
192   nes_state *state = machine.driver_data<nes_state>();
193
194   /* Reset the mapper variables. Will also mark the char-gen ram as dirty */
195   if (state->m_disk_expansion && state->m_pcb_id == NO_BOARD)
196      ppu2c0x_set_hblank_callback(state->m_ppu, fds_irq);
197   else
198      nes_pcb_reset(machine);
199
200   /* Reset the serial input ports */
201   state->m_in_0.shift = 0;
202   state->m_in_1.shift = 0;
203
204   machine.device("maincpu")->reset();
205}
206
207static TIMER_CALLBACK( nes_irq_callback )
208{
209   nes_state *state = machine.driver_data<nes_state>();
210   device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
211   state->m_irq_timer->adjust(attotime::never);
212}
213
214static void nes_banks_restore(nes_state *state)
215{
216   memory_set_bank(state->machine(), "bank1", state->m_prg_bank[0]);
217   memory_set_bank(state->machine(), "bank2", state->m_prg_bank[1]);
218   memory_set_bank(state->machine(), "bank3", state->m_prg_bank[2]);
219   memory_set_bank(state->machine(), "bank4", state->m_prg_bank[3]);
220   memory_set_bank(state->machine(), "bank5", state->m_prg_bank[4]);
221}
222
223static void nes_state_register( running_machine &machine )
224{
225   nes_state *state = machine.driver_data<nes_state>();
226
227   state->save_item(NAME(state->m_prg_bank));
228
229   state->save_item(NAME(state->m_MMC5_floodtile));
230   state->save_item(NAME(state->m_MMC5_floodattr));
231   state->save_item(NAME(state->m_mmc5_vram_control));
232
233   state->save_item(NAME(state->m_nes_vram_sprite));
234   state->save_item(NAME(state->m_last_frame_flip));
235
236   // shared mapper variables
237   state->save_item(NAME(state->m_IRQ_enable));
238   state->save_item(NAME(state->m_IRQ_enable_latch));
239   state->save_item(NAME(state->m_IRQ_count));
240   state->save_item(NAME(state->m_IRQ_count_latch));
241   state->save_item(NAME(state->m_IRQ_toggle));
242   state->save_item(NAME(state->m_IRQ_reset));
243   state->save_item(NAME(state->m_IRQ_status));
244   state->save_item(NAME(state->m_IRQ_mode));
245   state->save_item(NAME(state->m_mult1));
246   state->save_item(NAME(state->m_mult2));
247   state->save_item(NAME(state->m_mmc_chr_source));
248   state->save_item(NAME(state->m_mmc_cmd1));
249   state->save_item(NAME(state->m_mmc_cmd2));
250   state->save_item(NAME(state->m_mmc_count));
251   state->save_item(NAME(state->m_mmc_prg_base));
252   state->save_item(NAME(state->m_mmc_prg_mask));
253   state->save_item(NAME(state->m_mmc_chr_base));
254   state->save_item(NAME(state->m_mmc_chr_mask));
255   state->save_item(NAME(state->m_mmc_prg_bank));
256   state->save_item(NAME(state->m_mmc_vrom_bank));
257   state->save_item(NAME(state->m_mmc_extra_bank));
258
259   state->save_item(NAME(state->m_fds_motor_on));
260   state->save_item(NAME(state->m_fds_door_closed));
261   state->save_item(NAME(state->m_fds_current_side));
262   state->save_item(NAME(state->m_fds_head_position));
263   state->save_item(NAME(state->m_fds_status0));
264   state->save_item(NAME(state->m_fds_read_mode));
265   state->save_item(NAME(state->m_fds_write_reg));
266   state->save_item(NAME(state->m_fds_last_side));
267   state->save_item(NAME(state->m_fds_count));
268
269   state->save_pointer(NAME(state->m_wram), state->m_wram_size);
270   if (state->m_battery)
271      state->save_pointer(NAME(state->m_battery_ram), state->m_battery_size);
272
273   machine.save().register_postload(save_prepost_delegate(FUNC(nes_banks_restore), state));
274}
275
276MACHINE_START( nes )
277{
278   nes_state *state = machine.driver_data<nes_state>();
279
280   init_nes_core(machine);
281   machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(nes_machine_stop),&machine));
282
283   state->m_maincpu = machine.device("maincpu");
284   state->m_ppu = machine.device("ppu");
285   state->m_sound = machine.device("nessound");
286   state->m_cart = machine.device("cart");
287
288   state->m_irq_timer = machine.scheduler().timer_alloc(FUNC(nes_irq_callback));
289   nes_state_register(machine);
290}
291
292static void nes_machine_stop( running_machine &machine )
293{
294   nes_state *state = machine.driver_data<nes_state>();
295   device_image_interface *image = dynamic_cast<device_image_interface *>(state->m_cart);
296   /* Write out the battery file if necessary */
297   if (state->m_battery)
298      image->battery_save(state->m_battery_ram, state->m_battery_size);
299
300   if (state->m_mapper_bram_size)
301      image->battery_save(state->m_mapper_bram, state->m_mapper_bram_size);
302}
303
304
305
306READ8_HANDLER( nes_IN0_r )
307{
308   nes_state *state = space->machine().driver_data<nes_state>();
309   int cfg = input_port_read(space->machine(), "CTRLSEL");
310   int ret;
311
312   if ((cfg & 0x000f) >= 0x07)   // for now we treat the FC keyboard separately from other inputs!
313   {
314      // here we should have the tape input
315      ret = 0;
316   }
317   else
318   {
319      /* Some games expect bit 6 to be set because the last entry on the data bus shows up */
320      /* in the unused upper 3 bits, so typically a read from $4016 leaves 0x40 there. */
321      ret = 0x40;
322
323      ret |= ((state->m_in_0.i0 >> state->m_in_0.shift) & 0x01);
324
325      /* zapper */
326      if ((cfg & 0x000f) == 0x0002)
327      {
328         int x = state->m_in_0.i1;   /* read Zapper x-position */
329         int y = state->m_in_0.i2;   /* read Zapper y-position */
330         UINT32 pix, color_base;
331
332         /* get the pixel at the gun position */
333         pix = ppu2c0x_get_pixel(state->m_ppu, x, y);
334
335         /* get the color base from the ppu */
336         color_base = ppu2c0x_get_colorbase(state->m_ppu);
337
338         /* look at the screen and see if the cursor is over a bright pixel */
339         if ((pix == color_base + 0x20) || (pix == color_base + 0x30) ||
340            (pix == color_base + 0x33) || (pix == color_base + 0x34))
341         {
342            ret &= ~0x08; /* sprite hit */
343         }
344         else
345            ret |= 0x08;  /* no sprite hit */
346
347         /* If button 1 is pressed, indicate the light gun trigger is pressed */
348         ret |= ((state->m_in_0.i0 & 0x01) << 4);
349      }
350
351      if (LOG_JOY)
352         logerror("joy 0 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc(&space->device()), state->m_in_0.shift, state->m_in_0.i0);
353
354      state->m_in_0.shift++;
355   }
356
357   return ret;
358}
359
360// row of the keyboard matrix are read 4-bits at time, and gets returned as bit1->bit4
361static UINT8 nes_read_fc_keyboard_line( running_machine &machine, UINT8 scan, UINT8 mode )
362{
363   static const char *const fc_keyport_names[] = { "FCKEY0", "FCKEY1", "FCKEY2", "FCKEY3", "FCKEY4", "FCKEY5", "FCKEY6", "FCKEY7", "FCKEY8" };
364   return ((input_port_read(machine, fc_keyport_names[scan]) >> (mode * 4)) & 0x0f) << 1;
365}
366
367static UINT8 nes_read_subor_keyboard_line( running_machine &machine, UINT8 scan, UINT8 mode )
368{
369   static const char *const sub_keyport_names[] = { "SUBKEY0", "SUBKEY1", "SUBKEY2", "SUBKEY3", "SUBKEY4",
370      "SUBKEY5", "SUBKEY6", "SUBKEY7", "SUBKEY8", "SUBKEY9", "SUBKEY10", "SUBKEY11", "SUBKEY12" };
371   return ((input_port_read(machine, sub_keyport_names[scan]) >> (mode * 4)) & 0x0f) << 1;
372}
373
374READ8_HANDLER( nes_IN1_r )
375{
376   nes_state *state = space->machine().driver_data<nes_state>();
377   int cfg = input_port_read(space->machine(), "CTRLSEL");
378   int ret;
379
380   if ((cfg & 0x000f) == 0x07)   // for now we treat the FC keyboard separately from other inputs!
381   {
382      if (state->m_fck_scan < 9)
383         ret = ~nes_read_fc_keyboard_line(space->machine(), state->m_fck_scan, state->m_fck_mode) & 0x1e;
384      else
385         ret = 0x1e;
386   }
387   else if ((cfg & 0x000f) == 0x08)   // for now we treat the Subor keyboard separately from other inputs!
388   {
389      if (state->m_fck_scan < 12)
390         ret = ~nes_read_subor_keyboard_line(space->machine(), state->m_fck_scan, state->m_fck_mode) & 0x1e;
391      else
392         ret = 0x1e;
393   }
394   else
395   {
396      /* Some games expect bit 6 to be set because the last entry on the data bus shows up */
397      /* in the unused upper 3 bits, so typically a read from $4017 leaves 0x40 there. */
398      ret = 0x40;
399
400      /* Handle data line 0's serial output */
401      ret |= ((state->m_in_1.i0 >> state->m_in_1.shift) & 0x01);
402
403      /* zapper */
404      if ((cfg & 0x00f0) == 0x0030)
405      {
406         int x = state->m_in_1.i1;   /* read Zapper x-position */
407         int y = state->m_in_1.i2;   /* read Zapper y-position */
408         UINT32 pix, color_base;
409
410         /* get the pixel at the gun position */
411         pix = ppu2c0x_get_pixel(state->m_ppu, x, y);
412
413         /* get the color base from the ppu */
414         color_base = ppu2c0x_get_colorbase(state->m_ppu);
415
416         /* look at the screen and see if the cursor is over a bright pixel */
417         if ((pix == color_base + 0x20) || (pix == color_base + 0x30) ||
418            (pix == color_base + 0x33) || (pix == color_base + 0x34))
419         {
420            ret &= ~0x08; /* sprite hit */
421         }
422         else
423            ret |= 0x08;  /* no sprite hit */
424
425         /* If button 1 is pressed, indicate the light gun trigger is pressed */
426         ret |= ((state->m_in_1.i0 & 0x01) << 4);
427      }
428
429      /* arkanoid dial */
430      else if ((cfg & 0x00f0) == 0x0040)
431      {
432         /* Handle data line 2's serial output */
433         ret |= ((state->m_in_1.i2 >> state->m_in_1.shift) & 0x01) << 3;
434
435         /* Handle data line 3's serial output - bits are reversed */
436         /* NPW 27-Nov-2007 - there is no third subscript! commenting out */
437         /* ret |= ((state->m_in_1[3] >> state->m_in_1.shift) & 0x01) << 4; */
438         /* ret |= ((state->m_in_1[3] << state->m_in_1.shift) & 0x80) >> 3; */
439      }
440
441      if (LOG_JOY)
442         logerror("joy 1 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc(&space->device()), state->m_in_1.shift, state->m_in_1.i0);
443
444      state->m_in_1.shift++;
445   }
446
447   return ret;
448}
449
450
451// FIXME: this is getting messier and messier (no pun intended). inputs reading should be simplified and port_categories cleaned up
452// to also emulate the fact that nothing should be in Port 2 if there is a Crazy Climber pad, etc.
453static void nes_read_input_device( running_machine &machine, int cfg, nes_input *vals, int pad_port, int supports_zapper )
454{
455   nes_state *state = machine.driver_data<nes_state>();
456   static const char *const padnames[] = { "PAD1", "PAD2", "PAD3", "PAD4", "CC_LEFT", "CC_RIGHT" };
457
458   vals->i0 = 0;
459   vals->i1 = 0;
460   vals->i2 = 0;
461
462   switch (cfg & 0x0f)
463   {
464      case 0x01:   /* gamepad */
465         if (pad_port >= 0)
466            vals->i0 = input_port_read(machine, padnames[pad_port]);
467         break;
468
469      case 0x02:   /* zapper 1 */
470         if (supports_zapper)
471         {
472            vals->i0 = input_port_read(machine, "ZAPPER1_T");
473            vals->i1 = input_port_read(machine, "ZAPPER1_X");
474            vals->i2 = input_port_read(machine, "ZAPPER1_Y");
475         }
476         break;
477
478      case 0x03:   /* zapper 2 */
479         if (supports_zapper)
480         {
481            vals->i0 = input_port_read(machine, "ZAPPER2_T");
482            vals->i1 = input_port_read(machine, "ZAPPER2_X");
483            vals->i2 = input_port_read(machine, "ZAPPER2_Y");
484         }
485         break;
486
487      case 0x04:   /* arkanoid paddle */
488         if (pad_port == 1)
489            vals->i0 = (UINT8) ((UINT8) input_port_read(machine, "PADDLE") + (UINT8)0x52) ^ 0xff;
490         break;
491
492      case 0x05:   /* crazy climber controller */
493         if (pad_port == 0)
494         {
495            state->m_in_0.i0 = input_port_read(machine, padnames[4]);
496            state->m_in_1.i0 = input_port_read(machine, padnames[5]);
497         }
498         break;
499   }
500}
501
502
503static TIMER_CALLBACK( lightgun_tick )
504{
505   if ((input_port_read(machine, "CTRLSEL") & 0x000f) == 0x0002)
506   {
507      /* enable lightpen crosshair */
508      crosshair_set_screen(machine, 0, CROSSHAIR_SCREEN_ALL);
509   }
510   else
511   {
512      /* disable lightpen crosshair */
513      crosshair_set_screen(machine, 0, CROSSHAIR_SCREEN_NONE);
514   }
515
516   if ((input_port_read(machine, "CTRLSEL") & 0x00f0) == 0x0030)
517   {
518      /* enable lightpen crosshair */
519      crosshair_set_screen(machine, 1, CROSSHAIR_SCREEN_ALL);
520   }
521   else
522   {
523      /* disable lightpen crosshair */
524      crosshair_set_screen(machine, 1, CROSSHAIR_SCREEN_NONE);
525   }
526}
527
528WRITE8_HANDLER( nes_IN0_w )
529{
530   nes_state *state = space->machine().driver_data<nes_state>();
531   int cfg = input_port_read(space->machine(), "CTRLSEL");
532
533   /* Check if lightgun has been chosen as input: if so, enable crosshair */
534   space->machine().scheduler().timer_set(attotime::zero, FUNC(lightgun_tick));
535
536   if ((cfg & 0x000f) >= 0x07)   // for now we treat the FC keyboard separately from other inputs!
537   {
538      // here we should also have the tape output
539
540      if (BIT(data, 2))   // keyboard active
541      {
542         int lines = ((cfg & 0x000f) == 0x04) ? 9 : 12;
543         UINT8 out = BIT(data, 1);   // scan
544
545         if (state->m_fck_mode && !out && ++state->m_fck_scan > lines)
546            state->m_fck_scan = 0;
547
548         state->m_fck_mode = out;   // access lower or upper 4 bits
549
550         if (BIT(data, 0))   // reset
551            state->m_fck_scan = 0;
552      }
553   }
554   else
555   {
556      if (data & 0x01)
557         return;
558
559      if (LOG_JOY)
560         logerror("joy 0 bits read: %d\n", state->m_in_0.shift);
561
562      /* Toggling bit 0 high then low resets both controllers */
563      state->m_in_0.shift = 0;
564      state->m_in_1.shift = 0;
565
566      /* Read the input devices */
567      if ((cfg & 0x000f) != 0x06)
568      {
569         nes_read_input_device(space->machine(), cfg >>  0, &state->m_in_0, 0,  TRUE);
570         nes_read_input_device(space->machine(), cfg >>  4, &state->m_in_1, 1,  TRUE);
571         nes_read_input_device(space->machine(), cfg >>  8, &state->m_in_2, 2, FALSE);
572         nes_read_input_device(space->machine(), cfg >> 12, &state->m_in_3, 3, FALSE);
573      }
574      else // crazy climber pad
575      {
576         nes_read_input_device(space->machine(), 0, &state->m_in_1, 1,  TRUE);
577         nes_read_input_device(space->machine(), 0, &state->m_in_2, 2, FALSE);
578         nes_read_input_device(space->machine(), 0, &state->m_in_3, 3, FALSE);
579         nes_read_input_device(space->machine(), cfg >>  0, &state->m_in_0, 0,  TRUE);
580      }
581
582      if (cfg & 0x0f00)
583         state->m_in_0.i0 |= (state->m_in_2.i0 << 8) | (0x08 << 16);
584
585      if (cfg & 0xf000)
586         state->m_in_1.i0 |= (state->m_in_3.i0 << 8) | (0x04 << 16);
587   }
588}
589
590
591WRITE8_HANDLER( nes_IN1_w )
592{
593}
594
595struct nes_cart_lines
596{
597   const char *tag;
598   int line;
599};
600
601static const struct nes_cart_lines nes_cart_lines_table[] =
602{
603   { "PRG A0",    0 },
604   { "PRG A1",    1 },
605   { "PRG A2",    2 },
606   { "PRG A3",    3 },
607   { "PRG A4",    4 },
608   { "PRG A5",    5 },
609   { "PRG A6",    6 },
610   { "PRG A7",    7 },
611   { "CHR A10",  10 },
612   { "CHR A11",  11 },
613   { "CHR A12",  12 },
614   { "CHR A13",  13 },
615   { "CHR A14",  14 },
616   { "CHR A15",  15 },
617   { "CHR A16",  16 },
618   { "CHR A17",  17 },
619   { "NC",      127 },
620   { 0 }
621};
622
623static int nes_cart_get_line( const char *feature )
624{
625   const struct nes_cart_lines *nes_line = &nes_cart_lines_table[0];
626
627   if (feature == NULL)
628      return 128;
629
630   while (nes_line->tag)
631   {
632      if (strcmp(nes_line->tag, feature) == 0)
633         break;
634
635      nes_line++;
636   }
637
638   return nes_line->line;
639}
640
641DEVICE_IMAGE_LOAD( nes_cart )
642{
643   nes_state *state = image.device().machine().driver_data<nes_state>();
644   state->m_pcb_id = NO_BOARD;   // initialization
645
646   if (image.software_entry() == NULL)
647   {
648      const char *mapinfo = NULL;
649      int mapint1 = 0, mapint2 = 0, mapint3 = 0, mapint4 = 0, goodcrcinfo = 0;
650      char magic[4], extend[5];
651      int local_options = 0;
652      char m;
653
654      /* Check first 4 bytes of the image to decide if it is UNIF or iNES */
655      /* Unfortunately, many .unf files have been released as .nes, so we cannot rely on extensions only */
656      memset(magic, '\0', sizeof(magic));
657      image.fread(magic, 4);
658
659      if ((magic[0] == 'N') && (magic[1] == 'E') && (magic[2] == 'S'))   /* If header starts with 'NES' it is iNES */
660      {
661         UINT32 prg_size;
662         state->m_ines20 = 0;
663         state->m_battery_size = NES_BATTERY_SIZE; // with iNES we can only support 8K WRAM battery (iNES 2.0 might fix this)
664         state->m_prg_ram = 1;   // always map state->m_wram in bank5 (eventually, this should be enabled only for some mappers)
665
666         // check if the image is recognized by nes.hsi
667         mapinfo = hashfile_extrainfo(image);
668
669         // image_extrainfo() resets the file position back to start.
670         // Let's skip past the magic header once again.
671         image.fseek(4, SEEK_SET);
672
673         image.fread(&state->m_prg_chunks, 1);
674         image.fread(&state->m_chr_chunks, 1);
675         /* Read the first ROM option byte (offset 6) */
676         image.fread(&m, 1);
677
678         /* Interpret the iNES header flags */
679         state->m_mapper = (m & 0xf0) >> 4;
680         local_options = m & 0x0f;
681
682         /* Read the second ROM option byte (offset 7) */
683         image.fread(&m, 1);
684
685         switch (m & 0xc)
686         {
687            case 0x4:
688            case 0xc:
689               // probably the header got corrupted: don't trust upper bits for mapper
690               break;
691
692            case 0x8:   // it's iNES 2.0 format
693               state->m_ines20 = 1;
694            case 0x0:
695            default:
696               state->m_mapper = state->m_mapper | (m & 0xf0);
697               break;
698         }
699
700         if (mapinfo /* && !state->m_ines20 */)
701         {
702            if (4 == sscanf(mapinfo,"%d %d %d %d", &mapint1, &mapint2, &mapint3, &mapint4))
703            {
704               /* image is present in nes.hsi: overwrite the header settings with these */
705               state->m_mapper = mapint1;
706               local_options = mapint2 & 0x0f;
707               state->m_crc_hack = (mapint2 & 0xf0) >> 4;   // this is used to differentiate among variants of the same Mapper (see below)
708               state->m_prg_chunks = mapint3;
709               state->m_chr_chunks = mapint4;
710               logerror("NES.HSI info: %d %d %d %d\n", mapint1, mapint2, mapint3, mapint4);
711//                  mame_printf_error("NES.HSI info: %d %d %d %d\n", mapint1, mapint2, mapint3, mapint4);
712               goodcrcinfo = 1;
713               state->m_ines20 = 0;
714            }
715            else
716            {
717               logerror("NES: [%s], Invalid mapinfo found\n", mapinfo);
718            }
719         }
720         else
721         {
722            logerror("NES: No extrainfo found\n");
723         }
724
725         state->m_hard_mirroring = (local_options & 0x01) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ;
726//          mame_printf_error("%s\n", state->m_hard_mirroring & 0x01 ? "Vertical" : "Horizontal");
727         state->m_battery = local_options & 0x02;
728         state->m_trainer = local_options & 0x04;
729         state->m_four_screen_vram = local_options & 0x08;
730
731         if (state->m_battery)
732            logerror("-- Battery found\n");
733
734         if (state->m_trainer)
735            logerror("-- Trainer found\n");
736
737         if (state->m_four_screen_vram)
738            logerror("-- 4-screen VRAM\n");
739
740         if (state->m_ines20)
741         {
742            logerror("Extended iNES format:\n");
743            image.fread(&extend, 5);
744            state->m_mapper |= (extend[0] & 0x0f) << 8;
745            logerror("-- mapper: %d\n", state->m_mapper);
746            logerror("-- submapper: %d\n", (extend[0] & 0xf0) >> 4);
747            state->m_prg_chunks |= ((extend[1] & 0x0f) << 8);
748            state->m_chr_chunks |= ((extend[1] & 0xf0) << 4);
749            logerror("-- PRG chunks: %d\n", state->m_prg_chunks);
750            logerror("-- CHR chunks: %d\n", state->m_chr_chunks);
751            logerror("-- PRG NVWRAM: %d\n", extend[2] & 0x0f);
752            logerror("-- PRG WRAM: %d\n", (extend[2] & 0xf0) >> 4);
753            logerror("-- CHR NVWRAM: %d\n", extend[3] & 0x0f);
754            logerror("-- CHR WRAM: %d\n", (extend[3] & 0xf0) >> 4);
755            logerror("-- TV System: %d\n", extend[4] & 3);
756         }
757
758         /* Free the regions that were allocated by the ROM loader */
759         image.device().machine().region_free("maincpu");
760         image.device().machine().region_free("gfx1");
761
762         /* Allocate them again with the proper size */
763         prg_size = (state->m_prg_chunks == 1) ? 2 * 0x4000 : state->m_prg_chunks * 0x4000;
764         image.device().machine().region_alloc("maincpu", 0x10000 + prg_size, 1, ENDIANNESS_LITTLE);
765         if (state->m_chr_chunks)
766            image.device().machine().region_alloc("gfx1", state->m_chr_chunks * 0x2000, 1, ENDIANNESS_LITTLE);
767
768         state->m_rom = image.device().machine().region("maincpu")->base();
769         state->m_vrom = image.device().machine().region("gfx1")->base();
770
771         state->m_vram_chunks = image.device().machine().region("gfx2")->bytes() / 0x2000;
772         state->m_vram = image.device().machine().region("gfx2")->base();
773         // FIXME: this should only be allocated if there is actual wram in the cart (i.e. if state->m_prg_ram = 1)!
774         // or if there is a trainer, I think
775         state->m_wram_size = 0x10000;
776         state->m_wram = auto_alloc_array(image.device().machine(), UINT8, state->m_wram_size);
777
778         /* Setup PCB type (needed to add proper handlers later) */
779         state->m_pcb_id = nes_get_mmc_id(image.device().machine(), state->m_mapper);
780
781         // a few mappers correspond to multiple PCBs, so we need a few additional checks
782         switch (state->m_pcb_id)
783         {
784            case STD_CNROM:
785               if (state->m_mapper == 185)
786               {
787                  switch (state->m_crc_hack)
788                  {
789                     case 0x0: // pin26: CE, pin27: CE (B-Wings, Bird Week)
790                        state->m_ce_mask = 0x03;
791                        state->m_ce_state = 0x03;
792                        break;
793                     case 0x4: // pin26: CE, pin27: /CE (Mighty Bomb Jack, Spy Vs. Spy)
794                        state->m_ce_mask = 0x03;
795                        state->m_ce_state = 0x01;
796                        break;
797                     case 0x8: // pin26: /CE, pin27: CE (Sansu 1, 2, 3 Nen)
798                        state->m_ce_mask = 0x03;
799                        state->m_ce_state = 0x02;
800                        break;
801                     case 0xc: // pin26: /CE, pin27: /CE (Seicross v2.0)
802                        state->m_ce_mask = 0x03;
803                        state->m_ce_state = 0x00;
804                        break;
805                  }
806               }
807               break;
808            case KONAMI_VRC2:
809               if (state->m_mapper == 22)
810               {
811                  state->m_vrc_ls_prg_a = 0;
812                  state->m_vrc_ls_prg_b = 1;
813                  state->m_vrc_ls_chr = 1;
814               }
815               if (state->m_mapper == 23 && !state->m_crc_hack)
816               {
817                  state->m_vrc_ls_prg_a = 1;
818                  state->m_vrc_ls_prg_b = 0;
819                  state->m_vrc_ls_chr = 0;
820               }
821               if (state->m_mapper == 23 && state->m_crc_hack)
822               {
823                  // here there are also Akumajou Special, Crisis Force, Parodius da!, Tiny Toons which are VRC-4
824                  state->m_vrc_ls_prg_a = 3;
825                  state->m_vrc_ls_prg_b = 2;
826                  state->m_pcb_id = KONAMI_VRC4; // this allows for konami_irq to be installed at reset
827               }
828               break;
829            case KONAMI_VRC4:
830               if (state->m_mapper == 21)
831               {
832                  // Wai Wai World 2 & Ganbare Goemon Gaiden 2 (the latter with crc_hack)
833                  state->m_vrc_ls_prg_a = state->m_crc_hack ? 7 : 2;
834                  state->m_vrc_ls_prg_b = state->m_crc_hack ? 6 : 1;
835               }
836               if (state->m_mapper == 25)   // here there is also Ganbare Goemon Gaiden which is VRC-2
837               {
838                  state->m_vrc_ls_prg_a = state->m_crc_hack ? 2 : 0;
839                  state->m_vrc_ls_prg_b = state->m_crc_hack ? 3 : 1;
840               }
841               break;
842            case KONAMI_VRC6:
843               if (state->m_mapper == 24)
844               {
845                  state->m_vrc_ls_prg_a = 1;
846                  state->m_vrc_ls_prg_b = 0;
847               }
848               if (state->m_mapper == 26)
849               {
850                  state->m_vrc_ls_prg_a = 0;
851                  state->m_vrc_ls_prg_b = 1;
852               }
853               break;
854            case IREM_G101:
855               if (state->m_crc_hack)
856                  state->m_hard_mirroring = PPU_MIRROR_HIGH;   // Major League has hardwired mirroring
857               break;
858            case DIS_74X161X161X32:
859               if (state->m_mapper == 70)
860                  state->m_hard_mirroring = PPU_MIRROR_VERT;   // only hardwired mirroring makes different mappers 70 & 152
861               break;
862            case SUNSOFT_2:
863               if (state->m_mapper == 93)
864                  state->m_hard_mirroring = PPU_MIRROR_VERT;   // only hardwired mirroring makes different mappers 89 & 93
865               break;
866            case STD_BXROM:
867               if (state->m_crc_hack)
868                  state->m_pcb_id = AVE_NINA01;   // Mapper 34 is used for 2 diff boards
869               break;
870            case BANDAI_LZ93:
871               if (state->m_crc_hack)
872                  state->m_pcb_id = BANDAI_JUMP2;   // Mapper 153 is used for 2 diff boards
873               break;
874            case IREM_HOLYDIV:
875               if (state->m_crc_hack)
876                  state->m_pcb_id = JALECO_JF16;   // Mapper 78 is used for 2 diff boards
877               break;
878            case CAMERICA_BF9093:
879               if (state->m_crc_hack)
880                  state->m_pcb_id = CAMERICA_BF9097;   // Mapper 71 is used for 2 diff boards
881               break;
882            case HES_BOARD:
883               if (state->m_crc_hack)
884                  state->m_pcb_id = HES6IN1_BOARD;   // Mapper 113 is used for 2 diff boards
885               break;
886            case WAIXING_ZS:
887               if (state->m_crc_hack)
888                  state->m_pcb_id = WAIXING_DQ8;   // Mapper 242 is used for 2 diff boards
889               break;
890            //FIXME: we also have to fix Action 52 PRG loading somewhere...
891         }
892
893         /* Allocate internal Mapper RAM for boards which require it */
894         if (state->m_pcb_id == STD_EXROM)
895            state->m_mapper_ram = auto_alloc_array(image.device().machine(), UINT8, 0x400);
896
897         if (state->m_pcb_id == TAITO_X1_005 || state->m_pcb_id == TAITO_X1_005_A)
898            state->m_mapper_bram = auto_alloc_array(image.device().machine(), UINT8, 0x80);
899
900         if (state->m_pcb_id == TAITO_X1_017)
901            state->m_mapper_bram = auto_alloc_array(image.device().machine(), UINT8, 0x1400);
902
903         if (state->m_pcb_id == NAMCOT_163)
904            state->m_mapper_ram = auto_alloc_array(image.device().machine(), UINT8, 0x2000);
905
906         if (state->m_pcb_id == FUKUTAKE_BOARD)
907            state->m_mapper_ram = auto_alloc_array(image.device().machine(), UINT8, 2816);
908
909         /* Position past the header */
910         image.fseek(16, SEEK_SET);
911
912         /* Load the 0x200 byte trainer at 0x7000 if it exists */
913         if (state->m_trainer)
914            image.fread(&state->m_wram[0x1000], 0x200);
915
916         /* Read in the program chunks */
917         image.fread(&state->m_rom[0x10000], 0x4000 * state->m_prg_chunks);
918         if (state->m_prg_chunks == 1)
919            memcpy(&state->m_rom[0x14000], &state->m_rom[0x10000], 0x4000);
920
921#if SPLIT_PRG
922         {
923            FILE *prgout;
924            char outname[255];
925
926            sprintf(outname, "%s.prg", image.filename());
927            prgout = fopen(outname, "wb");
928            if (prgout)
929            {
930               fwrite(&state->m_rom[0x10000], 1, 0x4000 * state->m_prg_chunks, prgout);
931               mame_printf_error("Created PRG chunk\n");
932            }
933
934            fclose(prgout);
935         }
936#endif
937
938         logerror("**\n");
939         logerror("Mapper: %d\n", state->m_mapper);
940         logerror("PRG chunks: %02x, size: %06x\n", state->m_prg_chunks, 0x4000 * state->m_prg_chunks);
941         // mame_printf_error("Mapper: %d\n", state->m_mapper);
942         // mame_printf_error("PRG chunks: %02x, size: %06x\n", state->m_prg_chunks, 0x4000 * state->m_prg_chunks);
943
944         /* Read in any chr chunks */
945         if (state->m_chr_chunks > 0)
946         {
947            image.fread(state->m_vrom, state->m_chr_chunks * 0x2000);
948            if (state->m_mapper == 2)
949               logerror("Warning: VROM has been found in VRAM-based mapper. Either the mapper is set wrong or the ROM image is incorrect.\n");
950         }
951
952#if SPLIT_CHR
953         if (state->m_chr_chunks > 0)
954         {
955            FILE *chrout;
956            char outname[255];
957
958            sprintf(outname, "%s.chr", image.filename());
959            chrout= fopen(outname, "wb");
960            if (chrout)
961            {
962               fwrite(state->m_vrom, 1, 0x2000 * state->m_chr_chunks, chrout);
963               mame_printf_error("Created CHR chunk\n");
964            }
965            fclose(chrout);
966         }
967#endif
968
969         logerror("CHR chunks: %02x, size: %06x\n", state->m_chr_chunks, 0x2000 * state->m_chr_chunks);
970         logerror("**\n");
971         // mame_printf_error("CHR chunks: %02x, size: %06x\n", state->m_chr_chunks, 0x2000 * state->m_chr_chunks);
972         // mame_printf_error("**\n");
973      }
974      else if ((magic[0] == 'U') && (magic[1] == 'N') && (magic[2] == 'I') && (magic[3] == 'F')) /* If header starts with 'UNIF' it is UNIF */
975      {
976         UINT32 unif_ver = 0;
977         char magic2[4];
978         UINT8 buffer[4];
979         UINT32 chunk_length = 0, read_length = 0x20;
980         UINT32 prg_start = 0, chr_start = 0, prg_size;
981         char unif_mapr[32];   // here we should store MAPR chunks
982         UINT32 size = image.length();
983         int mapr_chunk_found = 0;
984         // allocate space to temporarily store PRG & CHR banks
985         UINT8 *temp_prg = auto_alloc_array(image.device().machine(), UINT8, 256 * 0x4000);
986         UINT8 *temp_chr = auto_alloc_array(image.device().machine(), UINT8, 256 * 0x2000);
987         UINT8 temp_byte = 0;
988
989         /* init prg/chr chunks to 0: the exact number of chunks will be determined while reading the file */
990         state->m_prg_chunks = 0;
991         state->m_chr_chunks = 0;
992
993         image.fread(&buffer, 4);
994         unif_ver = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
995         logerror("UNIF file found, version %d\n", unif_ver);
996
997         if (size <= 0x20)
998         {
999            logerror("%s only contains the UNIF header and no data.\n", image.filename());
1000            return IMAGE_INIT_FAIL;
1001         }
1002
1003         do
1004         {
1005            image.fseek(read_length, SEEK_SET);
1006
1007            memset(magic2, '\0', sizeof(magic2));
1008            image.fread(&magic2, 4);
1009
1010            /* We first run through the whole image to find a [MAPR] chunk. This is needed
1011                 because, unfortunately, the MAPR chunk is not always the first chunk (see
1012                 Super 24-in-1). When such a chunk is found, we set mapr_chunk_found=1 and
1013                 we go back to load other chunks! */
1014            if (!mapr_chunk_found)
1015            {
1016               if ((magic2[0] == 'M') && (magic2[1] == 'A') && (magic2[2] == 'P') && (magic2[3] == 'R'))
1017               {
1018                  mapr_chunk_found = 1;
1019                  logerror("[MAPR] chunk found: ");
1020                  image.fread(&buffer, 4);
1021                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1022
1023                  if (chunk_length <= 0x20)
1024                     image.fread(&unif_mapr, chunk_length);
1025
1026                  // find out prg/chr size, battery, wram, etc.
1027                  unif_mapr_setup(image.device().machine(), unif_mapr);
1028
1029                  /* now that we found the MAPR chunk, we can go back to load other chunks */
1030                  image.fseek(0x20, SEEK_SET);
1031                  read_length = 0x20;
1032               }
1033               else
1034               {
1035                  logerror("Skip this chunk. We need a [MAPR] chunk before anything else.\n");
1036                  image.fread(&buffer, 4);
1037                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1038
1039                  read_length += (chunk_length + 8);
1040               }
1041            }
1042            else
1043            {
1044               /* What kind of chunk do we have here? */
1045               if ((magic2[0] == 'M') && (magic2[1] == 'A') && (magic2[2] == 'P') && (magic2[3] == 'R'))
1046               {
1047                  /* The [MAPR] chunk has already been read, so we skip it */
1048                  /* TO DO: it would be nice to check if more than one MAPR chunk is present */
1049                  logerror("[MAPR] chunk found (in the 2nd run). Already loaded.\n");
1050                  image.fread(&buffer, 4);
1051                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1052
1053                  read_length += (chunk_length + 8);
1054               }
1055               else if ((magic2[0] == 'R') && (magic2[1] == 'E') && (magic2[2] == 'A') && (magic2[3] == 'D'))
1056               {
1057                  logerror("[READ] chunk found. No support yet.\n");
1058                  image.fread(&buffer, 4);
1059                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1060
1061                  read_length += (chunk_length + 8);
1062               }
1063               else if ((magic2[0] == 'N') && (magic2[1] == 'A') && (magic2[2] == 'M') && (magic2[3] == 'E'))
1064               {
1065                  logerror("[NAME] chunk found. No support yet.\n");
1066                  image.fread(&buffer, 4);
1067                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1068
1069                  read_length += (chunk_length + 8);
1070               }
1071               else if ((magic2[0] == 'W') && (magic2[1] == 'R') && (magic2[2] == 'T') && (magic2[3] == 'R'))
1072               {
1073                  logerror("[WRTR] chunk found. No support yet.\n");
1074                  image.fread(&buffer, 4);
1075                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1076
1077                  read_length += (chunk_length + 8);
1078               }
1079               else if ((magic2[0] == 'T') && (magic2[1] == 'V') && (magic2[2] == 'C') && (magic2[3] == 'I'))
1080               {
1081                  logerror("[TVCI] chunk found.\n");
1082                  image.fread(&buffer, 4);
1083                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1084
1085                  image.fread(&temp_byte, 1);
1086                  logerror("Television Standard : %s\n", (temp_byte == 0) ? "NTSC" : (temp_byte == 1) ? "PAL" : "Does not matter");
1087
1088                  read_length += (chunk_length + 8);
1089               }
1090               else if ((magic2[0] == 'T') && (magic2[1] == 'V') && (magic2[2] == 'S') && (magic2[3] == 'C')) // is this the same as TVCI??
1091               {
1092                  logerror("[TVSC] chunk found. No support yet.\n");
1093                  image.fread(&buffer, 4);
1094                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1095
1096                  read_length += (chunk_length + 8);
1097               }
1098               else if ((magic2[0] == 'D') && (magic2[1] == 'I') && (magic2[2] == 'N') && (magic2[3] == 'F'))
1099               {
1100                  logerror("[DINF] chunk found. No support yet.\n");
1101                  image.fread(&buffer, 4);
1102                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1103
1104                  read_length += (chunk_length + 8);
1105               }
1106               else if ((magic2[0] == 'C') && (magic2[1] == 'T') && (magic2[2] == 'R') && (magic2[3] == 'L'))
1107               {
1108                  logerror("[CTRL] chunk found. No support yet.\n");
1109                  image.fread(&buffer, 4);
1110                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1111
1112                  read_length += (chunk_length + 8);
1113               }
1114               else if ((magic2[0] == 'B') && (magic2[1] == 'A') && (magic2[2] == 'T') && (magic2[3] == 'R'))
1115               {
1116                  logerror("[BATR] chunk found. No support yet.\n");
1117                  image.fread(&buffer, 4);
1118                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1119
1120                  read_length += (chunk_length + 8);
1121               }
1122               else if ((magic2[0] == 'V') && (magic2[1] == 'R') && (magic2[2] == 'O') && (magic2[3] == 'R'))
1123               {
1124                  logerror("[VROR] chunk found. No support yet.\n");
1125                  image.fread(&buffer, 4);
1126                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1127
1128                  read_length += (chunk_length + 8);
1129               }
1130               else if ((magic2[0] == 'M') && (magic2[1] == 'I') && (magic2[2] == 'R') && (magic2[3] == 'R'))
1131               {
1132                  logerror("[MIRR] chunk found.\n");
1133                  image.fread(&buffer, 4);
1134                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1135
1136                  image.fread(&temp_byte, 1);
1137                  switch (temp_byte)
1138                  {
1139                     case 0:   // Horizontal Mirroring (Hard Wired)
1140                        state->m_hard_mirroring = PPU_MIRROR_HORZ;
1141                        break;
1142                     case 1:   // Vertical Mirroring (Hard Wired)
1143                        state->m_hard_mirroring = PPU_MIRROR_VERT;
1144                        break;
1145                     case 2:   // Mirror All Pages From $2000 (Hard Wired)
1146                        state->m_hard_mirroring = PPU_MIRROR_LOW;
1147                        break;
1148                     case 3:   // Mirror All Pages From $2400 (Hard Wired)
1149                        state->m_hard_mirroring = PPU_MIRROR_HIGH;
1150                        break;
1151                     case 4:   // Four Screens of VRAM (Hard Wired)
1152                        state->m_four_screen_vram = 1;
1153                        break;
1154                     case 5:   // Mirroring Controlled By Mapper Hardware
1155                        logerror("Mirroring handled by the board hardware.\n");
1156                        // default to horizontal at start
1157                        state->m_hard_mirroring = PPU_MIRROR_HORZ;
1158                        break;
1159                     default:
1160                        logerror("Undocumented mirroring value.\n");
1161                        // default to horizontal
1162                        state->m_hard_mirroring = PPU_MIRROR_HORZ;
1163                        break;
1164                  }
1165
1166                  read_length += (chunk_length + 8);
1167               }
1168               else if ((magic2[0] == 'P') && (magic2[1] == 'C') && (magic2[2] == 'K'))
1169               {
1170                  logerror("[PCK%c] chunk found. No support yet.\n", magic2[3]);
1171                  image.fread(&buffer, 4);
1172                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1173
1174                  read_length += (chunk_length + 8);
1175               }
1176               else if ((magic2[0] == 'C') && (magic2[1] == 'C') && (magic2[2] == 'K'))
1177               {
1178                  logerror("[CCK%c] chunk found. No support yet.\n", magic2[3]);
1179                  image.fread(&buffer, 4);
1180                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1181
1182                  read_length += (chunk_length + 8);
1183               }
1184               else if ((magic2[0] == 'P') && (magic2[1] == 'R') && (magic2[2] == 'G'))
1185               {
1186                  logerror("[PRG%c] chunk found. ", magic2[3]);
1187                  image.fread(&buffer, 4);
1188                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1189
1190                  // FIXME: we currently don't support PRG chunks smaller than 16K!
1191                  state->m_prg_chunks += (chunk_length / 0x4000);
1192
1193                  if (chunk_length / 0x4000)
1194                     logerror("It consists of %d 16K-blocks.\n", chunk_length / 0x4000);
1195                  else
1196                     logerror("This chunk is smaller than 16K: the emulation might have issues. Please report this file to the MESS forums.\n");
1197
1198                  /* Read in the program chunks */
1199                  image.fread(&temp_prg[prg_start], chunk_length);
1200
1201                  prg_start += chunk_length;
1202                  read_length += (chunk_length + 8);
1203               }
1204               else if ((magic2[0] == 'C') && (magic2[1] == 'H') && (magic2[2] == 'R'))
1205               {
1206                  logerror("[CHR%c] chunk found. ", magic2[3]);
1207                  image.fread(&buffer, 4);
1208                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
1209
1210                  state->m_chr_chunks += (chunk_length / 0x2000);
1211
1212                  logerror("It consists of %d 8K-blocks.\n", chunk_length / 0x2000);
1213
1214                  /* Read in the vrom chunks */
1215                  image.fread(&temp_chr[chr_start], chunk_length);
1216
1217                  chr_start += chunk_length;
1218                  read_length += (chunk_length + 8);
1219               }
1220               else
1221               {
1222                  logerror("Unsupported UNIF chunk or corrupted header. Please report the problem at MESS Board.\n");
1223                  read_length = size;
1224               }
1225            }
1226         } while (size > read_length);
1227
1228         if (!mapr_chunk_found)
1229         {
1230            auto_free(image.device().machine(), temp_prg);
1231            auto_free(image.device().machine(), temp_chr);
1232            fatalerror("UNIF should have a [MAPR] chunk to work. Check if your image has been corrupted");
1233         }
1234
1235         if (!prg_start)
1236         {
1237            auto_free(image.device().machine(), temp_prg);
1238            auto_free(image.device().machine(), temp_chr);
1239            fatalerror("Unsupported UNIF chunk or corrupted header. Please report the problem at MESS Board.\n");
1240         }
1241
1242         /* Free the regions that were allocated by the ROM loader */
1243         image.device().machine().region_free("maincpu");
1244         image.device().machine().region_free("gfx1");
1245         image.device().machine().region_free("gfx2");
1246
1247         /* Allocate them again, and copy PRG/CHR from temp buffers */
1248         /* Take care of PRG */
1249         prg_size = (state->m_prg_chunks == 1) ? 2 * 0x4000 : state->m_prg_chunks * 0x4000;
1250         image.device().machine().region_alloc("maincpu", 0x10000 + prg_size, 1, ENDIANNESS_LITTLE);
1251         state->m_rom = image.device().machine().region("maincpu")->base();
1252         memcpy(&state->m_rom[0x10000], &temp_prg[0x00000], state->m_prg_chunks * 0x4000);
1253         /* If only a single 16K PRG chunk is present, mirror it! */
1254         if (state->m_prg_chunks == 1)
1255            memcpy(&state->m_rom[0x14000], &state->m_rom[0x10000], 0x4000);
1256
1257         /* Take care of CHR ROM */
1258         if (state->m_chr_chunks)
1259         {
1260            image.device().machine().region_alloc("gfx1", state->m_chr_chunks * 0x2000, 1, ENDIANNESS_LITTLE);
1261            state->m_vrom = image.device().machine().region("gfx1")->base();
1262            memcpy(&state->m_vrom[0x00000], &temp_chr[0x00000], state->m_chr_chunks * 0x2000);
1263         }
1264
1265         /* Take care of CHR RAM */
1266         if (state->m_vram_chunks)
1267         {
1268            image.device().machine().region_alloc("gfx2", state->m_vram_chunks * 0x2000, 1, ENDIANNESS_LITTLE);
1269            state->m_vram = image.device().machine().region("gfx2")->base();
1270         }
1271
1272         // FIXME: this should only be allocated if there is actual wram in the cart (i.e. if state->m_prg_ram = 1)!
1273         state->m_wram_size = 0x10000;
1274         state->m_wram = auto_alloc_array(image.device().machine(), UINT8, state->m_wram_size);
1275
1276#if SPLIT_PRG
1277         {
1278            FILE *prgout;
1279            char outname[255];
1280
1281            sprintf(outname, "%s.prg", image.filename());
1282            prgout = fopen(outname, "wb");
1283            if (prgout)
1284            {
1285               fwrite(&state->m_rom[0x10000], 1, 0x4000 * state->m_prg_chunks, prgout);
1286               mame_printf_error("Created PRG chunk\n");
1287            }
1288
1289            fclose(prgout);
1290         }
1291#endif
1292
1293#if SPLIT_CHR
1294         if (state->m_chr_chunks > 0)
1295         {
1296            FILE *chrout;
1297            char outname[255];
1298
1299            sprintf(outname, "%s.chr", image.filename());
1300            chrout= fopen(outname, "wb");
1301            if (chrout)
1302            {
1303               fwrite(state->m_vrom, 1, 0x2000 * state->m_chr_chunks, chrout);
1304               mame_printf_error("Created CHR chunk\n");
1305            }
1306            fclose(chrout);
1307         }
1308#endif
1309         // free the temporary copy of PRG/CHR
1310         auto_free(image.device().machine(), temp_prg);
1311         auto_free(image.device().machine(), temp_chr);
1312         logerror("UNIF support is only very preliminary.\n");
1313      }
1314      else
1315      {
1316         logerror("%s is NOT a file in either iNES or UNIF format.\n", image.filename());
1317         return IMAGE_INIT_FAIL;
1318      }
1319   }
1320   else
1321   {
1322      UINT32 prg_size = image.get_software_region_length("prg");
1323      UINT32 chr_size = image.get_software_region_length("chr");
1324      UINT32 vram_size = image.get_software_region_length("vram");
1325      vram_size += image.get_software_region_length("vram2");
1326
1327      /* Free the regions that were allocated by the ROM loader */
1328      image.device().machine().region_free("maincpu");
1329      image.device().machine().region_free("gfx1");
1330      image.device().machine().region_free("gfx2");
1331
1332      /* Allocate them again with the proper size */
1333      image.device().machine().region_alloc("maincpu", 0x10000 + prg_size, 1, ENDIANNESS_LITTLE);
1334
1335      // validate the xml fields
1336      if (!prg_size)
1337         fatalerror("No PRG entry for this software! Please check if the xml list got corrupted");
1338      if (prg_size < 0x8000)
1339         fatalerror("PRG entry is too small! Please check if the xml list got corrupted");
1340
1341      if (chr_size)
1342         image.device().machine().region_alloc("gfx1", chr_size, 1, ENDIANNESS_LITTLE);
1343
1344      if (vram_size)
1345         image.device().machine().region_alloc("gfx2", vram_size, 1, ENDIANNESS_LITTLE);
1346
1347      state->m_rom = image.device().machine().region("maincpu")->base();
1348      state->m_vrom = image.device().machine().region("gfx1")->base();
1349      state->m_vram = image.device().machine().region("gfx2")->base();
1350
1351      memcpy(state->m_rom + 0x10000, image.get_software_region("prg"), prg_size);
1352
1353      if (chr_size)
1354         memcpy(state->m_vrom, image.get_software_region("chr"), chr_size);
1355
1356      state->m_prg_chunks = prg_size / 0x4000;
1357      state->m_chr_chunks = chr_size / 0x2000;
1358      state->m_vram_chunks = vram_size / 0x2000;
1359
1360      state->m_pcb_id = nes_get_pcb_id(image.device().machine(), image.get_feature("pcb"));
1361
1362      if (state->m_pcb_id == STD_TVROM || state->m_pcb_id == STD_DRROM || state->m_pcb_id == IREM_LROG017)
1363         state->m_four_screen_vram = 1;
1364      else
1365         state->m_four_screen_vram = 0;
1366
1367      state->m_battery = (image.get_software_region("bwram") != NULL) ? 1 : 0;
1368      state->m_battery_size = image.get_software_region_length("bwram");
1369
1370      if (state->m_pcb_id == BANDAI_LZ93EX)
1371      {
1372         // allocate the 24C01 or 24C02 EEPROM
1373         state->m_battery = 1;
1374         state->m_battery_size += 0x2000;
1375      }
1376
1377      if (state->m_pcb_id == BANDAI_DATACH)
1378      {
1379         // allocate the 24C01 and 24C02 EEPROM
1380         state->m_battery = 1;
1381         state->m_battery_size += 0x4000;
1382      }
1383
1384      state->m_prg_ram = (image.get_software_region("wram") != NULL) ? 1 : 0;
1385      state->m_wram_size = image.get_software_region_length("wram");
1386      state->m_mapper_ram_size = image.get_software_region_length("mapper_ram");
1387      state->m_mapper_bram_size = image.get_software_region_length("mapper_bram");
1388
1389      if (state->m_prg_ram)
1390         state->m_wram = auto_alloc_array(image.device().machine(), UINT8, state->m_wram_size);
1391      if (state->m_mapper_ram_size)
1392         state->m_mapper_ram = auto_alloc_array(image.device().machine(), UINT8, state->m_mapper_ram_size);
1393      if (state->m_mapper_bram_size)
1394         state->m_mapper_bram = auto_alloc_array(image.device().machine(), UINT8, state->m_mapper_bram_size);
1395
1396      /* Check for mirroring */
1397      if (image.get_feature("mirroring") != NULL)
1398      {
1399         const char *mirroring = image.get_feature("mirroring");
1400         if (!strcmp(mirroring, "horizontal"))
1401            state->m_hard_mirroring = PPU_MIRROR_HORZ;
1402         if (!strcmp(mirroring, "vertical"))
1403            state->m_hard_mirroring = PPU_MIRROR_VERT;
1404         if (!strcmp(mirroring, "high"))
1405            state->m_hard_mirroring = PPU_MIRROR_HIGH;
1406         if (!strcmp(mirroring, "low"))
1407            state->m_hard_mirroring = PPU_MIRROR_LOW;
1408      }
1409
1410      state->m_chr_open_bus = 0;
1411      state->m_ce_mask = 0;
1412      state->m_ce_state = 0;
1413      state->m_vrc_ls_prg_a = 0;
1414      state->m_vrc_ls_prg_b = 0;
1415      state->m_vrc_ls_chr = 0;
1416
1417      /* Check for pins in specific boards which require them */
1418      if (state->m_pcb_id == STD_CNROM)
1419      {
1420         if (image.get_feature("chr-pin26") != NULL)
1421         {
1422            state->m_ce_mask |= 0x01;
1423            state->m_ce_state |= !strcmp(image.get_feature("chr-pin26"), "CE") ? 0x01 : 0;
1424         }
1425         if (image.get_feature("chr-pin27") != NULL)
1426         {
1427            state->m_ce_mask |= 0x02;
1428            state->m_ce_state |= !strcmp(image.get_feature("chr-pin27"), "CE") ? 0x02 : 0;
1429         }
1430      }
1431
1432      if (state->m_pcb_id == TAITO_X1_005 && image.get_feature("x1-pin17") != NULL && image.get_feature("x1-pin31") != NULL)
1433      {
1434         if (!strcmp(image.get_feature("x1-pin17"), "CIRAM A10") && !strcmp(image.get_feature("x1-pin31"), "NC"))
1435            state->m_pcb_id = TAITO_X1_005_A;
1436      }
1437
1438      if (state->m_pcb_id == KONAMI_VRC2)
1439      {
1440         state->m_vrc_ls_prg_a = nes_cart_get_line(image.get_feature("vrc2-pin3"));
1441         state->m_vrc_ls_prg_b = nes_cart_get_line(image.get_feature("vrc2-pin4"));
1442         state->m_vrc_ls_chr = (nes_cart_get_line(image.get_feature("vrc2-pin21")) != 10) ? 1 : 0;
1443//          mame_printf_error("VRC-2, pin3: A%d, pin4: A%d, pin21: %s\n", state->m_vrc_ls_prg_a, state->m_vrc_ls_prg_b, state->m_vrc_ls_chr ? "NC" : "A10");
1444      }
1445
1446      if (state->m_pcb_id == KONAMI_VRC4)
1447      {
1448         state->m_vrc_ls_prg_a = nes_cart_get_line(image.get_feature("vrc4-pin3"));
1449         state->m_vrc_ls_prg_b = nes_cart_get_line(image.get_feature("vrc4-pin4"));
1450//          mame_printf_error("VRC-4, pin3: A%d, pin4: A%d\n", state->m_vrc_ls_prg_a, state->m_vrc_ls_prg_b);
1451      }
1452
1453      if (state->m_pcb_id == KONAMI_VRC6)
1454      {
1455         state->m_vrc_ls_prg_a = nes_cart_get_line(image.get_feature("vrc6-pin9"));
1456         state->m_vrc_ls_prg_b = nes_cart_get_line(image.get_feature("vrc6-pin10"));
1457//          mame_printf_error("VRC-6, pin9: A%d, pin10: A%d\n", state->m_vrc_ls_prg_a, state->m_vrc_ls_prg_b);
1458      }
1459
1460      /* Check for other misc board variants */
1461      if (state->m_pcb_id == STD_SOROM)
1462      {
1463         if (image.get_feature("mmc1_type") != NULL && !strcmp(image.get_feature("mmc1_type"), "MMC1A"))
1464            state->m_pcb_id = STD_SOROM_A;   // in MMC1-A PRG RAM is always enabled
1465      }
1466
1467      if (state->m_pcb_id == STD_SXROM)
1468      {
1469         if (image.get_feature("mmc1_type") != NULL && !strcmp(image.get_feature("mmc1_type"), "MMC1A"))
1470            state->m_pcb_id = STD_SXROM_A;   // in MMC1-A PRG RAM is always enabled
1471      }
1472
1473      if (state->m_pcb_id == STD_NXROM || state->m_pcb_id == SUNSOFT_DCS)
1474      {
1475         if (image.get_software_region("minicart") != NULL)   // check for dual minicart
1476         {
1477            state->m_pcb_id = SUNSOFT_DCS;
1478            // we shall load somewhere the minicart, but we still do not support this
1479         }
1480      }
1481
1482#if 0
1483      if (state->m_pcb_id == UNSUPPORTED_BOARD)
1484         mame_printf_error("This board (%s) is currently not supported by MESS\n", image.get_feature("pcb"));
1485      mame_printf_error("PCB Feature: %s\n", image.get_feature("pcb"));
1486      mame_printf_error("PRG chunks: %d\n", state->m_prg_chunks);
1487      mame_printf_error("CHR chunks: %d\n", state->m_chr_chunks);
1488      mame_printf_error("VRAM: Present %s, size: %d\n", state->m_vram_chunks ? "Yes" : "No", vram_size);
1489      mame_printf_error("NVWRAM: Present %s, size: %d\n", state->m_battery ? "Yes" : "No", state->m_battery_size);
1490      mame_printf_error("WRAM:   Present %s, size: %d\n", state->m_prg_ram ? "Yes" : "No", state->m_wram_size);
1491#endif
1492   }
1493
1494   // Attempt to load a battery file for this ROM
1495   // A few boards have internal RAM with a battery (MMC6, Taito X1-005 & X1-017, etc.)
1496   if (state->m_battery || state->m_mapper_bram_size)
1497   {
1498      UINT8 *temp_nvram = auto_alloc_array(image.device().machine(), UINT8, state->m_battery_size + state->m_mapper_bram_size);
1499      image.battery_load(temp_nvram, state->m_battery_size + state->m_mapper_bram_size, 0x00);
1500      if (state->m_battery)
1501      {
1502         state->m_battery_ram = auto_alloc_array(image.device().machine(), UINT8, state->m_battery_size);
1503         memcpy(state->m_battery_ram, temp_nvram, state->m_battery_size);
1504      }
1505      if (state->m_mapper_bram_size)
1506         memcpy(state->m_mapper_bram, temp_nvram + state->m_battery_size, state->m_mapper_bram_size);
1507
1508      auto_free(image.device().machine(), temp_nvram);
1509   }
1510
1511   return IMAGE_INIT_PASS;
1512}
1513
1514
1515
1516void nes_partialhash(hash_collection &dest, const unsigned char *data,
1517   unsigned long length, const char *functions)
1518{
1519   if (length <= 16)
1520      return;
1521   dest.compute(&data[16], length - 16, functions);
1522}
1523
1524/**************************
1525
1526 Disk System emulation
1527
1528**************************/
1529
1530static void fds_irq( device_t *device, int scanline, int vblank, int blanked )
1531{
1532   nes_state *state = device->machine().driver_data<nes_state>();
1533
1534   if (state->m_IRQ_enable_latch)
1535      device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
1536
1537   if (state->m_IRQ_enable)
1538   {
1539      if (state->m_IRQ_count <= 114)
1540      {
1541         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
1542         state->m_IRQ_enable = 0;
1543         state->m_fds_status0 |= 0x01;
1544      }
1545      else
1546         state->m_IRQ_count -= 114;
1547   }
1548}
1549
1550static READ8_HANDLER( nes_fds_r )
1551{
1552   nes_state *state = space->machine().driver_data<nes_state>();
1553   UINT8 ret = 0x00;
1554
1555   switch (offset)
1556   {
1557      case 0x00: /* $4030 - disk status 0 */
1558         ret = state->m_fds_status0;
1559         /* clear the disk IRQ detect flag */
1560         state->m_fds_status0 &= ~0x01;
1561         break;
1562      case 0x01: /* $4031 - data latch */
1563         /* don't read data if disk is unloaded */
1564         if (state->m_fds_data == NULL)
1565            ret = 0;
1566         else if (state->m_fds_current_side)
1567            ret = state->m_fds_data[(state->m_fds_current_side - 1) * 65500 + state->m_fds_head_position++];
1568         else
1569            ret = 0;
1570         break;
1571      case 0x02: /* $4032 - disk status 1 */
1572         /* return "no disk" status if disk is unloaded */
1573         if (state->m_fds_data == NULL)
1574            ret = 1;
1575         else if (state->m_fds_last_side != state->m_fds_current_side)
1576         {
1577            /* If we've switched disks, report "no disk" for a few reads */
1578            ret = 1;
1579            state->m_fds_count++;
1580            if (state->m_fds_count == 50)
1581            {
1582               state->m_fds_last_side = state->m_fds_current_side;
1583               state->m_fds_count = 0;
1584            }
1585         }
1586         else
1587            ret = (state->m_fds_current_side == 0); /* 0 if a disk is inserted */
1588         break;
1589      case 0x03: /* $4033 */
1590         ret = 0x80;
1591         break;
1592      default:
1593         ret = 0x00;
1594         break;
1595   }
1596
1597   return ret;
1598}
1599
1600static WRITE8_HANDLER( nes_fds_w )
1601{
1602   nes_state *state = space->machine().driver_data<nes_state>();
1603
1604   switch (offset)
1605   {
1606      case 0x00:
1607         state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0xff00) | data;
1608         break;
1609      case 0x01:
1610         state->m_IRQ_count_latch = (state->m_IRQ_count_latch & 0x00ff) | (data << 8);
1611         break;
1612      case 0x02:
1613         state->m_IRQ_count = state->m_IRQ_count_latch;
1614         state->m_IRQ_enable = data;
1615         break;
1616      case 0x03:
1617         // d0 = sound io (1 = enable)
1618         // d1 = disk io (1 = enable)
1619         break;
1620      case 0x04:
1621         /* write data out to disk */
1622         break;
1623      case 0x05:
1624         state->m_fds_motor_on = BIT(data, 0);
1625
1626         if (BIT(data, 1))
1627            state->m_fds_head_position = 0;
1628
1629         state->m_fds_read_mode = BIT(data, 2);
1630         set_nt_mirroring(space->machine(), BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1631
1632         if ((!(data & 0x40)) && (state->m_fds_write_reg & 0x40))
1633            state->m_fds_head_position -= 2; // ???
1634
1635         state->m_IRQ_enable_latch = BIT(data, 7);
1636         state->m_fds_write_reg = data;
1637         break;
1638   }
1639}
1640
1641static void nes_load_proc( device_image_interface &image )
1642{
1643   nes_state *state = image.device().machine().driver_data<nes_state>();
1644   int header = 0;
1645   state->m_fds_sides = 0;
1646
1647   if (image.length() % 65500)
1648      header = 0x10;
1649
1650   state->m_fds_sides = (image.length() - header) / 65500;
1651
1652   if (state->m_fds_data == NULL)
1653      state->m_fds_data = (UINT8*)image.image_malloc(state->m_fds_sides * 65500);   // I don't think we can arrive here ever, probably it can be removed...
1654
1655   /* if there is an header, skip it */
1656   image.fseek(header, SEEK_SET);
1657
1658   image.fread(state->m_fds_data, 65500 * state->m_fds_sides);
1659   return;
1660}
1661
1662static void nes_unload_proc( device_image_interface &image )
1663{
1664   nes_state *state = image.device().machine().driver_data<nes_state>();
1665
1666   /* TODO: should write out changes here as well */
1667   state->m_fds_sides =  0;
1668}
1669
1670DRIVER_INIT( famicom )
1671{
1672   nes_state *state = machine.driver_data<nes_state>();
1673   int i;
1674
1675   /* clear some of the variables we don't use */
1676   state->m_trainer = 0;
1677   state->m_battery = 0;
1678   state->m_prg_ram = 0;
1679   state->m_four_screen_vram = 0;
1680   state->m_hard_mirroring = 0;
1681   state->m_prg_chunks = state->m_chr_chunks = 0;
1682
1683   /* initialize the disk system */
1684   state->m_disk_expansion = 1;
1685   state->m_pcb_id = NO_BOARD;
1686
1687   state->m_fds_sides = 0;
1688   state->m_fds_last_side = 0;
1689   state->m_fds_count = 0;
1690   state->m_fds_motor_on = 0;
1691   state->m_fds_door_closed = 0;
1692   state->m_fds_current_side = 1;
1693   state->m_fds_head_position = 0;
1694   state->m_fds_status0 = 0;
1695   state->m_fds_read_mode = state->m_fds_write_reg = 0;
1696
1697   state->m_fds_data = auto_alloc_array_clear(machine, UINT8, 65500 * 2);
1698   state->m_fds_ram = auto_alloc_array_clear(machine, UINT8, 0x8000);
1699   state->save_pointer(NAME(state->m_fds_ram), 0x8000);
1700
1701   // setup CHR accesses to 8k VRAM
1702   state->m_vram = machine.region("gfx2")->base();
1703   for (i = 0; i < 8; i++)
1704   {
1705      state->m_chr_map[i].source = CHRRAM;
1706      state->m_chr_map[i].origin = i * 0x400; // for save state uses!
1707      state->m_chr_map[i].access = &state->m_vram[state->m_chr_map[i].origin];
1708   }
1709
1710   floppy_install_load_proc(floppy_get_device(machine, 0), nes_load_proc);
1711   floppy_install_unload_proc(floppy_get_device(machine, 0), nes_unload_proc);
1712}
src/mess/machine/amigacd.h
r11460r11461
1#ifndef __AMIGACD_H__
2#define __AMIGACD_H__
3
4
5MACHINE_START( amigacd );
6MACHINE_RESET( amigacd );
7
8/* 6525tpi */
9READ8_DEVICE_HANDLER( amigacd_tpi6525_portc_r );
10WRITE8_DEVICE_HANDLER( amigacd_tpi6525_portb_w );
11WRITE_LINE_DEVICE_HANDLER( amigacd_tpi6525_irq );
12
13
14#endif /* __AMIGACD_H__ */
src/mess/machine/nes_unif.c
r11460r11461
1/*****************************************************************************************
2
3    NES MMC Emulation - UNIF boards
4
5    Very preliminary support for UNIF boards
6
7    TODO:
8    - properly support WRAM, etc.
9
10****************************************************************************************/
11
12typedef struct __unif
13{
14   const char *board; /* UNIF board */
15
16   int nvwram;
17   int wram;
18   int chrram;
19   int board_idx;
20} unif;
21
22
23/*************************************************************
24
25    Constants
26
27*************************************************************/
28
29/* CHRRAM sizes */
30enum
31{
32   CHRRAM_0 = 0,
33   CHRRAM_1,
34   CHRRAM_2,
35   CHRRAM_4,
36   CHRRAM_6,
37   CHRRAM_8,
38   CHRRAM_16,
39   CHRRAM_32
40};
41
42/*************************************************************
43
44    unif_list
45
46    Supported UNIF boards and corresponding handlers
47
48*************************************************************/
49
50static const unif unif_list[] =
51{
52/*       UNIF                       NVW  WRAM  CRAM     IDX*/
53   { "DREAMTECH01",                0,    0, CHRRAM_8,  DREAMTECH_BOARD},      //UNIF only!
54   { "NES-ANROM",                  0,    0, CHRRAM_8,  STD_AXROM},
55   { "NES-AOROM",                  0,    0, CHRRAM_8,  STD_AXROM},
56   { "NES-CNROM",                  0,    0, CHRRAM_0,  STD_CNROM},
57   { "NES-NROM",                   0,    0, CHRRAM_0,  STD_NROM},
58   { "NES-NROM-128",               0,    0, CHRRAM_0,  STD_NROM},
59   { "NES-NROM-256",               0,    0, CHRRAM_0,  STD_NROM},
60   { "NES-NTBROM",                 8,    0, CHRRAM_0,  STD_NXROM},
61   { "NES-SLROM",                  0,    0, CHRRAM_0,  STD_SXROM},
62   { "NES-TBROM",                  0,    0, CHRRAM_0,  STD_TXROM},
63   { "NES-TFROM",                  0,    0, CHRRAM_0,  STD_TXROM},
64   { "NES-TKROM",                  8,    0, CHRRAM_0,  STD_TXROM},
65   { "NES-TLROM",                  0,    0, CHRRAM_0,  STD_TXROM},
66   { "NES-UOROM",                  0,    0, CHRRAM_8,  STD_UXROM},
67   { "UNL-22211",                  0,    0, CHRRAM_0,  TXC_22211A},
68   // mapper 172 & 173 are variant of this one... no UNIF?
69   { "UNL-KOF97",                  0,    0, CHRRAM_0,  UNL_KOF97},
70   { "UNL-SA-NROM",                0,    0, CHRRAM_0,  SACHEN_TCA01},
71   { "UNL-VRC7",                   0,    0, CHRRAM_0,  KONAMI_VRC7},
72   { "UNL-T-230",                  0,    0, CHRRAM_8,  UNL_T230},
73   { "UNL-CC-21",                  0,    0, CHRRAM_0,  UNL_CC21},
74   { "UNL-AX5705",                 0,    0, CHRRAM_0,  UNL_AX5705},
75   { "UNL-SMB2J",                  8,    8, CHRRAM_0,  UNL_SMB2J},
76   { "UNL-8237",                   0,    0, CHRRAM_0,  UNL_8237},
77   { "UNL-SL1632",                 0,    0, CHRRAM_0,  REXSOFT_SL1632},
78   { "UNL-SACHEN-74LS374N",        0,    0, CHRRAM_0,  SACHEN_74LS374},
79   // mapper 243 variant exists! how to distinguish?!?  mapper243_l_w, NULL, NULL, NULL, NULL, NULL, NULL (also uses NT_VERT!)
80   { "UNL-TC-U01-1.5M",            0,    0, CHRRAM_0,  SACHEN_TCU01},
81   { "UNL-SACHEN-8259C",           0,    0, CHRRAM_0,  SACHEN_8259C},
82   { "UNL-SA-016-1M",              0,    0, CHRRAM_0,  AVE_NINA06},   // actually this is Mapper 146, but works like 79!
83   { "UNL-SACHEN-8259D",           0,    0, CHRRAM_0,  SACHEN_8259D},
84   { "UNL-SA-72007",               0,    0, CHRRAM_0,  SACHEN_SA72007},
85   { "UNL-SA-72008",               0,    0, CHRRAM_0,  SACHEN_SA72008},
86   { "UNL-SA-0037",                0,    0, CHRRAM_0,  SACHEN_SA0037},
87   { "UNL-SA-0036",                0,    0, CHRRAM_0,  SACHEN_SA0036},
88   { "UNL-SACHEN-8259A",           0,    0, CHRRAM_0,  SACHEN_8259A},
89   { "UNL-SACHEN-8259B",           0,    0, CHRRAM_0,  SACHEN_8259B},
90   { "BMC-190IN1",                 0,    0, CHRRAM_0,  BMC_190IN1},
91   { "BMC-64IN1NOREPEAT",          0,    0, CHRRAM_0,  BMC_64IN1NR},      //UNIF only!
92   { "BMC-A65AS",                  0,    0, CHRRAM_8,  BMC_A65AS},      //UNIF only!
93   { "BMC-GS-2004",                0,    0, CHRRAM_8,  BMC_GS2004},      //UNIF only!
94   { "BMC-GS-2013",                0,    0, CHRRAM_8,  BMC_GS2013},      //UNIF only!
95   { "BMC-NOVELDIAMOND9999999IN1", 0,    0, CHRRAM_0,  BMC_NOVELDIAMOND},
96   { "BMC-SUPER24IN1SC03",         8,    0, CHRRAM_8,  BMC_S24IN1SC03},
97   { "BMC-SUPERHIK8IN1",           8,    0, CHRRAM_0,  BMC_HIK8IN1},
98   { "BMC-T-262",                  0,    0, CHRRAM_8,  BMC_T262},      //UNIF only!
99   { "BMC-WS",                     0,    0, CHRRAM_0,  BMC_WS},      //UNIF only!
100   { "BMC-N625092",                0,    0, CHRRAM_0,  UNL_N625092},
101   // below are boards which are not yet supported, but are used by some UNIF files. they are here as a reminder to what is missing to be added
102   { "UNL-TEK90",                  0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},   // related to JY Company? (i.e. mappers 90, 209, 211?)
103   { "UNL-KS7017",                 0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},
104   { "UNL-KS7032",                 0,    0, CHRRAM_0,  KAISER_KS7032}, //  mapper 142
105   { "UNL-DANCE",                  0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},
106   { "UNL-603-5052",               0,    0, CHRRAM_0,  UNL_603_5052}, // mapper 238?
107   { "UNL-EDU2000",               32,    0, CHRRAM_8,  UNL_EDU2K},
108   { "UNL-H2288",                  0,    0, CHRRAM_0,  UNL_H2288},   // mapper 123
109   { "UNL-SHERO",                  0,    0, CHRRAM_8,  UNSUPPORTED_BOARD /*SACHEN_SHERO*/},
110   { "UNL-TF1201",                 0,    0, CHRRAM_0,  UNSUPPORTED_BOARD /*UNL_TF1201*/},
111   { "UNL-DRIPGAME",               0,    0, CHRRAM_0,  UNSUPPORTED_BOARD}, // [by Quietust - we need more info]}
112   { "UNL-OneBus",                 0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},
113   { "BTL-MARIO1-MALEE2",          0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},   // mapper 55?
114   { "BMC-FK23C",                  0,    0, CHRRAM_0,  BMC_FK23C},
115   { "BMC-FK23CA",                 0,    0, CHRRAM_0,  BMC_FK23CA},
116   { "BMC-GHOSTBUSTERS63IN1",      0,    0, CHRRAM_8,  BMC_G63IN1 },
117   { "BMC-BS-5",                   0,    0, CHRRAM_0,  BMC_BENSHENG_BS5},
118   { "BMC-810544-C-A1",            0,    0, CHRRAM_0,  BMC_810544},
119   { "BMC-411120-C",               0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},
120   { "BMC-8157",                   0,    0, CHRRAM_8,  UNSUPPORTED_BOARD /*BMC_8157*/},
121   { "BMC-42IN1RESETSWITCH",       0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},   // mapper 60?
122   { "BMC-830118C",                0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},
123   { "BMC-D1038",                  0,    0, CHRRAM_0,  BMC_VT5201}, // mapper 60?
124   { "BMC-12-IN-1",                0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},
125   { "BMC-70IN1",                  0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},   // mapper 236?
126   { "BMC-70IN1B",                 0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},   // mapper 236?
127   { "BMC-SUPERVISION16IN1",       0,    0, CHRRAM_0,  UNSUPPORTED_BOARD},   // mapper 53
128   { "BMC-NTD-03",                 0,    0, CHRRAM_0,  BMC_NTD_03}
129};
130
131const unif *nes_unif_lookup( const char *board )
132{
133   int i;
134   for (i = 0; i < ARRAY_LENGTH(unif_list); i++)
135   {
136      if (!mame_stricmp(unif_list[i].board, board))
137         return &unif_list[i];
138   }
139   return NULL;
140}
141
142/*************************************************************
143
144 unif_mapr_setup
145
146 setup the board specific variables (wram, nvwram, pcb_id etc.)
147 for a given board (after reading the MAPR chunk of the UNIF file)
148
149 *************************************************************/
150
151void unif_mapr_setup( running_machine &machine, const char *board )
152{
153   nes_state *state = machine.driver_data<nes_state>();
154   const unif *unif_board = nes_unif_lookup(board);
155
156   logerror("%s\n", board);
157
158   if (unif_board == NULL)
159      fatalerror("Unknown UNIF board %s.", board);
160
161   state->m_pcb_id = unif_board->board_idx;
162   state->m_battery = unif_board->nvwram;   // we should implement battery banks based on the size of this...
163   state->m_battery_size = NES_BATTERY_SIZE; // FIXME: we should allow for smaller battery!
164   state->m_prg_ram = unif_board->wram;   // we should implement WRAM banks based on the size of this...
165
166   if (unif_board->chrram <= CHRRAM_8)
167      state->m_vram_chunks = 1;
168   else if (unif_board->chrram == CHRRAM_16)
169      state->m_vram_chunks = 2;
170   else if (unif_board->chrram == CHRRAM_32)
171      state->m_vram_chunks = 4;
172}
src/mess/machine/msx.c
r11460r11461
1/*
2 * msx.c: MSX emulation
3 *
4 * Copyright (C) 2004 Sean Young
5 *
6 * Todo:
7 *
8 * - fix mouse support
9 * - cassette support doesn't work
10 * - Ensure changing cartridge after boot works
11 * - wd2793, nms8255
12 */
13
14#include "emu.h"
15#include "machine/i8255.h"
16#include "includes/msx_slot.h"
17#include "includes/msx.h"
18#include "machine/rp5c01.h"
19#include "machine/wd17xx.h"
20#include "imagedev/flopdrv.h"
21#include "formats/basicdsk.h"
22#include "video/tms9928a.h"
23#include "cpu/z80/z80.h"
24#include "video/v9938.h"
25#include "machine/ctronics.h"
26#include "imagedev/cassette.h"
27#include "osdepend.h"
28#include "sound/ay8910.h"
29#include "sound/2413intf.h"
30#include "sound/dac.h"
31#include "hashfile.h"
32
33#define VERBOSE 0
34
35static void msx_memory_map_all (running_machine &machine);
36static void msx_memory_map_page (running_machine &machine, int page);
37static void msx_memory_init (running_machine &machine);
38static void msx_memory_set_carts (running_machine &machine);
39static void msx_memory_reset (running_machine &machine);
40
41
42
43static int msx_probe_type (UINT8* pmem, int size)
44{
45   int kon4, kon5, asc8, asc16, i;
46
47   if (size <= 0x10000) return 0;
48
49   if ( (pmem[0x10] == 'Y') && (pmem[0x11] == 'Z') && (size > 0x18000) )
50      return 6;
51
52   kon4 = kon5 = asc8 = asc16 = 0;
53
54   for (i=0;i<size-3;i++)
55   {
56      if (pmem[i] == 0x32 && pmem[i+1] == 0)
57      {
58         switch (pmem[i+2]) {
59         case 0x60:
60         case 0x70:
61            asc16++;
62            asc8++;
63            break;
64         case 0x68:
65         case 0x78:
66            asc8++;
67            asc16--;
68         }
69
70         switch (pmem[i+2]) {
71         case 0x60:
72         case 0x80:
73         case 0xa0:
74            kon4++;
75            break;
76         case 0x50:
77         case 0x70:
78         case 0x90:
79         case 0xb0:
80            kon5++;
81         }
82      }
83   }
84
85   if (MAX (kon4, kon5) > MAX (asc8, asc16) )
86      return (kon5 > kon4) ? 2 : 3;
87   else
88      return (asc8 > asc16) ? 4 : 5;
89}
90
91DEVICE_IMAGE_LOAD (msx_cart)
92{
93   msx_state *state = image.device().machine().driver_data<msx_state>();
94   int size;
95   int size_aligned;
96   UINT8 *mem;
97   int type;
98   const char *extra = NULL;
99   char *sramfile;
100   slot_state *st;
101   int id = -1;
102
103   if (strcmp(image.device().tag(),"cart1")==0) {
104      id = 0;
105   }
106   if (strcmp(image.device().tag(),"cart2")==0) {
107      id = 1;
108   }
109
110   if( id == -1 ) {
111      //logerror ("error: invalid cart tag '%s'\n", image->tag);
112      return IMAGE_INIT_FAIL;
113   }
114
115   size = image.length ();
116   if (size < 0x2000) {
117      logerror ("cart #%d: error: file is smaller than 2kb, too small "
118              "to be true!\n", id);
119      return IMAGE_INIT_FAIL;
120   }
121
122   /* allocate memory and load */
123   size_aligned = 0x2000;
124   while (size_aligned < size) {
125      size_aligned *= 2;
126   }
127   mem = (UINT8*)image.image_malloc(size_aligned);
128   if (!mem) {
129      logerror ("cart #%d: error: failed to allocate memory for cartridge\n",
130                  id);
131      return IMAGE_INIT_FAIL;
132   }
133   if (size < size_aligned) {
134      memset (mem, 0xff, size_aligned);
135   }
136   if (image.fread(mem, size) != size) {
137      logerror ("cart #%d: %s: can't read full %d bytes\n",
138                  id, image.filename (), size);
139      return IMAGE_INIT_FAIL;
140   }
141
142   /* see if msx.crc will tell us more */
143   extra = hashfile_extrainfo(image);
144
145   if (!extra)
146   {
147      logerror("cart #%d: warning: no information in crc file\n", id);
148      type = -1;
149   }
150   else if ((1 != sscanf(extra, "%d", &type) ) ||
151         type < 0 || type > SLOT_LAST_CARTRIDGE_TYPE)
152   {
153      logerror("cart #%d: warning: information in crc file not valid\n", id);
154      type = -1;
155   }
156   else
157   {
158      logerror ("cart #%d: info: cart extra info: '%s' = %s\n", id, extra,
159                  msx_slot_list[type].name);
160   }
161
162   /* if not, attempt autodetection */
163   if (type < 0)
164   {
165      type = msx_probe_type (mem, size);
166
167      if (mem[0] != 'A' || mem[1] != 'B') {
168         logerror("cart #%d: %s: May not be a valid ROM file\n",
169                     id, image.filename ());
170      }
171
172      logerror("cart #%d: Probed cartridge mapper %d/%s\n", id,
173                  type, msx_slot_list[type].name);
174   }
175
176   /* mapper type 0 always needs 64kB */
177   if (!type && size_aligned != 0x10000)
178   {
179      size_aligned = 0x10000;
180      mem = (UINT8*)image.image_realloc(mem, 0x10000);
181      if (!mem) {
182         logerror ("cart #%d: error: cannot allocate memory\n", id);
183         return IMAGE_INIT_FAIL;
184      }
185
186      if (size < 0x10000) {
187         memset (mem + size, 0xff, 0x10000 - size);
188      }
189      if (size > 0x10000) {
190         logerror ("cart #%d: warning: rom truncated to 64kb due to "
191                 "mapperless type (possibly detected)\n", id);
192
193         size = 0x10000;
194      }
195   }
196
197   /* mapper type 0 (ROM) might need moving around a bit */
198   if (!type) {
199      int i, page = 1;
200
201      /* find the correct page */
202      if (mem[0] == 'A' && mem[1] == 'B') {
203         for (i=2; i<=8; i += 2) {
204            if (mem[i] || mem[i+1]) {
205               page = mem[i+1] / 0x40;
206               break;
207            }
208         }
209      }
210
211      if (size <= 0x4000) {
212         if (page == 1 || page == 2) {
213            /* copy to the respective page */
214            memcpy (mem + (page * 0x4000), mem, 0x4000);
215            memset (mem, 0xff, 0x4000);
216         }
217         else {
218            /* memory is repeated 4 times */
219            page = -1;
220            memcpy (mem + 0x4000, mem, 0x4000);
221            memcpy (mem + 0x8000, mem, 0x4000);
222            memcpy (mem + 0xc000, mem, 0x4000);
223         }
224      }
225      else /*if (size <= 0xc000) */ {
226         if (page) {
227            /* shift up 16kB; custom memcpy so overlapping memory
228                   isn't corrupted. ROM starts in page 1 (0x4000) */
229            UINT8 *m;
230
231            page = 1;
232            i = 0xc000; m = mem + 0xffff;
233            while (i--) {
234               *m = *(m - 0x4000); m--;
235            }
236            memset (mem, 0xff, 0x4000);
237         }
238      }
239
240      if (page) {
241         logerror ("cart #%d: info: rom in page %d\n", id, page);
242      }
243      else {
244         logerror ("cart #%d: info: rom duplicted in all pages\n", id);
245      }
246   }
247
248   /* kludge */
249   if (type == 0) {
250      type = SLOT_ROM;
251   }
252
253   /* allocate and set slot_state for this cartridge */
254   st = (slot_state*) image.image_malloc(sizeof (slot_state));
255   if (!st)
256   {
257      logerror ("cart #%d: error: cannot allocate memory for "
258              "cartridge state\n", id);
259      return IMAGE_INIT_FAIL;
260   }
261   memset (st, 0, sizeof (slot_state));
262
263   st->m_type = type;
264   sramfile = (char*)image.image_malloc(strlen (image.filename () + 1));
265
266   if (sramfile) {
267      char *ext;
268
269      strcpy (sramfile, image.basename ());
270      ext = strrchr (sramfile, '.');
271      if (ext) {
272         *ext = 0;
273      }
274      st->m_sramfile = sramfile;
275   }
276
277   if (msx_slot_list[type].init (image.device().machine(), st, 0, mem, size_aligned)) {
278      return IMAGE_INIT_FAIL;
279   }
280   if (msx_slot_list[type].loadsram) {
281      msx_slot_list[type].loadsram (image.device().machine(), st);
282   }
283
284   state->m_cart_state[id] = st;
285   msx_memory_set_carts (image.device().machine());
286
287   return IMAGE_INIT_PASS;
288}
289
290DEVICE_IMAGE_UNLOAD (msx_cart)
291{
292   msx_state *state = image.device().machine().driver_data<msx_state>();
293   int id = -1;
294
295   if (strcmp(image.device().tag(),"cart1")==0) {
296      id = 0;
297   }
298   if (strcmp(image.device().tag(),"cart2")==0) {
299      id = 1;
300   }
301
302   if( id == -1 ) {
303      //logerror ("error: invalid cart tag '%s'\n", image->tag);
304      return;
305   }
306
307   if (msx_slot_list[state->m_cart_state[id]->m_type].savesram)
308   {
309      msx_slot_list[state->m_cart_state[id]->m_type].savesram (image.device().machine(), state->m_cart_state[id]);
310   }
311}
312
313void msx_vdp_interrupt(running_machine &machine, int i)
314{
315   cputag_set_input_line (machine, "maincpu", 0, (i ? HOLD_LINE : CLEAR_LINE));
316}
317
318static void msx_ch_reset_core (running_machine &machine)
319{
320   msx_memory_reset (machine);
321   msx_memory_map_all (machine);
322}
323
324static const TMS9928a_interface tms9928a_interface =
325{
326   TMS99x8A,
327   0x4000,
328   0, 0,
329   msx_vdp_interrupt
330};
331
332MACHINE_START( msx )
333{
334   TMS9928A_configure(&tms9928a_interface);
335   MACHINE_START_CALL( msx2 );
336}
337
338MACHINE_START( msx2 )
339{
340   msx_state *state = machine.driver_data<msx_state>();
341   state->m_port_c_old = 0xff;
342   state->m_dsk_stat = 0x7f;
343}
344
345MACHINE_RESET( msx )
346{
347   TMS9928A_reset ();
348   msx_ch_reset_core (machine);
349}
350
351MACHINE_RESET( msx2 )
352{
353   v9938_reset (0);
354   msx_ch_reset_core (machine);
355}
356
357static WRITE8_DEVICE_HANDLER ( msx_ppi_port_a_w );
358static WRITE8_DEVICE_HANDLER ( msx_ppi_port_c_w );
359static READ8_DEVICE_HANDLER (msx_ppi_port_b_r );
360
361I8255_INTERFACE( msx_ppi8255_interface )
362{
363   DEVCB_NULL,
364   DEVCB_HANDLER(msx_ppi_port_a_w),
365   DEVCB_HANDLER(msx_ppi_port_b_r),
366   DEVCB_NULL,
367   DEVCB_NULL,
368   DEVCB_HANDLER(msx_ppi_port_c_w)
369};
370
371
372static const UINT8 cc_op[0x100] = {
373 4+1,10+1, 7+1, 6+1, 4+1, 4+1, 7+1, 4+1, 4+1,11+1, 7+1, 6+1, 4+1, 4+1, 7+1, 4+1,
374 8+1,10+1, 7+1, 6+1, 4+1, 4+1, 7+1, 4+1,12+1,11+1, 7+1, 6+1, 4+1, 4+1, 7+1, 4+1,
375 7+1,10+1,16+1, 6+1, 4+1, 4+1, 7+1, 4+1, 7+1,11+1,16+1, 6+1, 4+1, 4+1, 7+1, 4+1,
376 7+1,10+1,13+1, 6+1,11+1,11+1,10+1, 4+1, 7+1,11+1,13+1, 6+1, 4+1, 4+1, 7+1, 4+1,
377 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1,
378 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1,
379 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1,
380 7+1, 7+1, 7+1, 7+1, 7+1, 7+1, 4+1, 7+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1,
381 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1,
382 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1,
383 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1,
384 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 7+1, 4+1,
385 5+1,10+1,10+1,10+1,10+1,11+1, 7+1,11+1, 5+1,10+1,10+1, 0+1,10+1,17+1, 7+1,11+1,
386 5+1,10+1,10+1,11+1,10+1,11+1, 7+1,11+1, 5+1, 4+1,10+1,11+1,10+1, 0+1, 7+1,11+1,
387 5+1,10+1,10+1,19+1,10+1,11+1, 7+1,11+1, 5+1, 4+1,10+1, 4+1,10+1, 0+1, 7+1,11+1,
388 5+1,10+1,10+1, 4+1,10+1,11+1, 7+1,11+1, 5+1, 6+1,10+1, 4+1,10+1, 0+1, 7+1,11+1
389};
390
391static const UINT8 cc_cb[0x100] = {
392 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
393 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
394 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
395 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
396 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,12+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,12+2, 8+2,
397 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,12+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,12+2, 8+2,
398 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,12+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,12+2, 8+2,
399 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,12+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,12+2, 8+2,
400 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
401 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
402 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
403 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
404 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
405 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
406 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2,
407 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,15+2, 8+2
408};
409
410static const UINT8 cc_ed[0x100] = {
411 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
412 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
413 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
414 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
41512+2,12+2,15+2,20+2, 8+2,14+2, 8+2, 9+2,12+2,12+2,15+2,20+2, 8+2,14+2, 8+2, 9+2,
41612+2,12+2,15+2,20+2, 8+2,14+2, 8+2, 9+2,12+2,12+2,15+2,20+2, 8+2,14+2, 8+2, 9+2,
41712+2,12+2,15+2,20+2, 8+2,14+2, 8+2,18+2,12+2,12+2,15+2,20+2, 8+2,14+2, 8+2,18+2,
41812+2,12+2,15+2,20+2, 8+2,14+2, 8+2, 8+2,12+2,12+2,15+2,20+2, 8+2,14+2, 8+2, 8+2,
419 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
420 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
42116+2,16+2,16+2,16+2, 8+2, 8+2, 8+2, 8+2,16+2,16+2,16+2,16+2, 8+2, 8+2, 8+2, 8+2,
42216+2,16+2,16+2,16+2, 8+2, 8+2, 8+2, 8+2,16+2,16+2,16+2,16+2, 8+2, 8+2, 8+2, 8+2,
423 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
424 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
425 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2,
426 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2, 8+2
427};
428
429static const UINT8 cc_xy[0x100] = {
430 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2,15+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2,
431 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2,15+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2,
432 4+2,14+2,20+2,10+2, 9+2, 9+2, 9+2, 4+2, 4+2,15+2,20+2,10+2, 9+2, 9+2, 9+2, 4+2,
433 4+2, 4+2, 4+2, 4+2,23+2,23+2,19+2, 4+2, 4+2,15+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2,
434 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2, 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2,
435 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2, 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2,
436 9+2, 9+2, 9+2, 9+2, 9+2, 9+2,19+2, 9+2, 9+2, 9+2, 9+2, 9+2, 9+2, 9+2,19+2, 9+2,
43719+2,19+2,19+2,19+2,19+2,19+2, 4+2,19+2, 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2,
438 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2, 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2,
439 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2, 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2,
440 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2, 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2,
441 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2, 4+2, 4+2, 4+2, 4+2, 9+2, 9+2,19+2, 4+2,
442 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 0+2, 4+2, 4+2, 4+2, 4+2,
443 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2,
444 4+2,14+2, 4+2,23+2, 4+2,15+2, 4+2, 4+2, 4+2, 8+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2,
445 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2,10+2, 4+2, 4+2, 4+2, 4+2, 4+2, 4+2
446};
447
448static const UINT8 cc_xycb[0x100] = {
44923+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
45023+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
45123+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
45223+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
45320+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,
45420+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,
45520+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,
45620+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,20+2,
45723+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
45823+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
45923+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
46023+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
46123+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
46223+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
46323+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,
46423+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2,23+2
465};
466
467/* extra cycles if jr/jp/call taken and 'interrupt latency' on rst 0-7 */
468static const UINT8 cc_ex[0x100] = {
469 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
470 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   /* DJNZ */
471 5, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,   /* JR NZ/JR Z */
472 5, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,   /* JR NC/JR C */
473 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
474 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
475 0, 0, 0, 0, 0, 0, 0+1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
476 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
477 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
478 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
479 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
480 5, 5, 5, 5, 0, 0, 0, 0, 5, 5, 5, 5, 0, 0, 0, 0,   /* LDIR/CPIR/INIR/OTIR LDDR/CPDR/INDR/OTDR */
481 6, 0, 0, 0, 7, 0, 0, 2, 6, 0, 0, 0, 7, 0, 0, 2,
482 6, 0, 0, 0, 7, 0, 0, 2, 6, 0, 0, 0, 7, 0, 0, 2,
483 6, 0, 0, 0, 7, 0, 0, 2, 6, 0, 0, 0, 7, 0, 0, 2,
484 6, 0, 0, 0, 7, 0, 0, 2, 6, 0, 0, 0, 7, 0, 0, 2+1
485};
486
487
488DRIVER_INIT( msx )
489{
490   device_set_input_line_vector (machine.device("maincpu"), 0, 0xff);
491
492   msx_memory_init (machine);
493
494   z80_set_cycle_tables( machine.device("maincpu"), cc_op, cc_cb, cc_ed, cc_xy, cc_xycb, cc_ex );
495}
496
497INTERRUPT_GEN( msx2_interrupt )
498{
499   v9938_set_sprite_limit(0, input_port_read(device->machine(), "DSW") & 0x20);
500   v9938_set_resolution(0, input_port_read(device->machine(), "DSW") & 0x03);
501   v9938_interrupt(device->machine(), 0);
502}
503
504INTERRUPT_GEN( msx_interrupt )
505{
506   msx_state *state = device->machine().driver_data<msx_state>();
507   int i;
508
509   for (i=0; i<2; i++)
510   {
511      state->m_mouse[i] = input_port_read(device->machine(), i ? "MOUSE1" : "MOUSE0");
512      state->m_mouse_stat[i] = -1;
513   }
514
515   TMS9928A_set_spriteslimit (input_port_read(device->machine(), "DSW") & 0x20);
516   TMS9928A_interrupt(device->machine());
517}
518
519/*
520** The I/O funtions
521*/
522
523static device_t *cassette_device_image(running_machine &machine)
524{
525   return machine.device("cassette");
526}
527
528READ8_HANDLER ( msx_psg_port_a_r )
529{
530   msx_state *state = space->machine().driver_data<msx_state>();
531   int data, inp;
532
533   data = (cassette_input(cassette_device_image(space->machine())) > 0.0038 ? 0x80 : 0);
534
535   if ( (state->m_psg_b ^ input_port_read(space->machine(), "DSW") ) & 0x40)
536      {
537      /* game port 2 */
538      inp = input_port_read(space->machine(), "JOY1") & 0x7f;
539#if 0
540      if ( !(inp & 0x80) )
541         {
542#endif
543         /* joystick */
544         return (inp & 0x7f) | data;
545#if 0
546         }
547      else
548         {
549         /* mouse */
550         data |= inp & 0x70;
551         if (state->m_mouse_stat[1] < 0)
552            inp = 0xf;
553         else
554            inp = ~(state->m_mouse[1] >> (4*state->m_mouse_stat[1]) ) & 15;
555
556         return data | inp;
557         }
558#endif
559      }
560   else
561      {
562      /* game port 1 */
563      inp = input_port_read(space->machine(), "JOY0") & 0x7f;
564#if 0
565      if ( !(inp & 0x80) )
566         {
567#endif
568         /* joystick */
569         return (inp & 0x7f) | data;
570#if 0
571         }
572      else
573         {
574         /* mouse */
575         data |= inp & 0x70;
576         if (state->m_mouse_stat[0] < 0)
577            inp = 0xf;
578         else
579            inp = ~(state->m_mouse[0] >> (4*state->m_mouse_stat[0]) ) & 15;
580
581         return data | inp;
582         }
583#endif
584      }
585
586   return 0;
587}
588
589READ8_HANDLER ( msx_psg_port_b_r )
590{
591   msx_state *state = space->machine().driver_data<msx_state>();
592   return state->m_psg_b;
593}
594
595WRITE8_HANDLER ( msx_psg_port_a_w )
596{
597}
598
599WRITE8_HANDLER ( msx_psg_port_b_w )
600{
601   msx_state *state = space->machine().driver_data<msx_state>();
602   /* Arabic or kana mode led */
603   if ( (data ^ state->m_psg_b) & 0x80)
604      set_led_status (space->machine(), 2, !(data & 0x80) );
605
606   if ( (state->m_psg_b ^ data) & 0x10)
607   {
608      if (++state->m_mouse_stat[0] > 3) state->m_mouse_stat[0] = -1;
609   }
610   if ( (state->m_psg_b ^ data) & 0x20)
611   {
612      if (++state->m_mouse_stat[1] > 3) state->m_mouse_stat[1] = -1;
613   }
614
615   state->m_psg_b = data;
616}
617
618WRITE8_DEVICE_HANDLER( msx_printer_strobe_w )
619{
620   centronics_strobe_w(device, BIT(data, 1));
621}
622
623WRITE8_DEVICE_HANDLER( msx_printer_data_w )
624{
625   if (input_port_read(device->machine(), "DSW") & 0x80)
626   {
627      /* SIMPL emulation */
628      dac_signed_data_w(device->machine().device("dac"), data);
629   }
630   else
631   {
632      centronics_data_w(device, 0, data);
633   }
634}
635
636READ8_DEVICE_HANDLER( msx_printer_status_r )
637{
638   UINT8 result = 0xfd;
639
640   if (input_port_read(device->machine(), "DSW") & 0x80)
641      return 0xff;
642
643   result |= centronics_busy_r(device) << 1;
644
645   return result;
646}
647
648WRITE8_HANDLER (msx_fmpac_w)
649{
650   msx_state *state = space->machine().driver_data<msx_state>();
651   if (state->m_opll_active)
652   {
653      device_t *ym = space->machine().device("ym2413");
654
655      if (offset == 1)
656         ym2413_w (ym, 1, data);
657      else
658         ym2413_w (ym, 0, data);
659   }
660}
661
662/*
663** RTC functions
664*/
665
666WRITE8_HANDLER (msx_rtc_latch_w)
667{
668   msx_state *state = space->machine().driver_data<msx_state>();
669   state->m_rtc_latch = data & 15;
670}
671
672WRITE8_HANDLER (msx_rtc_reg_w)
673{
674   msx_state *state = space->machine().driver_data<msx_state>();
675   rp5c01_device *rtc = space->machine().device<rp5c01_device>(TC8521_TAG);
676   rtc->write(*space, state->m_rtc_latch, data);
677}
678
679READ8_HANDLER (msx_rtc_reg_r)
680{
681   msx_state *state = space->machine().driver_data<msx_state>();
682   rp5c01_device *rtc = space->machine().device<rp5c01_device>(TC8521_TAG);
683   return rtc->read(*space, state->m_rtc_latch);
684}
685
686/*
687From: erbo@xs4all.nl (erik de boer)
688
689sony and philips have used (almost) the same design
690and this is the memory layout
691but it is not a msx standard !
692
693WD1793 or wd2793 registers
694
695adress
696
6977FF8H read  status register
698      write command register
6997FF9H  r/w  track register (r/o on NMS 8245 and Sony)
7007FFAH  r/w  sector register (r/o on NMS 8245 and Sony)
7017FFBH  r/w  data register
702
703
704hardware registers
705
706adress
707
7087FFCH r/w  bit 0 side select
7097FFDH r/w  b7>M-on , b6>in-use , b1>ds1 , b0>ds0  (all neg. logic)
7107FFEH         not used
7117FFFH read b7>drq , b6>intrq
712
713set on 7FFDH bit 2 always to 0 (some use it as disk change reset)
714
715*/
716
717static WRITE_LINE_DEVICE_HANDLER( msx_wd179x_intrq_w )
718{
719   msx_state *drvstate = device->machine().driver_data<msx_state>();
720   if (state)
721      drvstate->m_dsk_stat &= ~0x40;
722   else
723      drvstate->m_dsk_stat |= 0x40;
724}
725
726static WRITE_LINE_DEVICE_HANDLER( msx_wd179x_drq_w )
727{
728   msx_state *drvstate = device->machine().driver_data<msx_state>();
729   if (state)
730      drvstate->m_dsk_stat &= ~0x80;
731   else
732      drvstate->m_dsk_stat |= 0x80;
733}
734
735const wd17xx_interface msx_wd17xx_interface =
736{
737   DEVCB_LINE_VCC,
738   DEVCB_LINE(msx_wd179x_intrq_w),
739   DEVCB_LINE(msx_wd179x_drq_w),
740   {FLOPPY_0, FLOPPY_1, NULL, NULL}
741};
742
743FLOPPY_OPTIONS_START(msx)
744   FLOPPY_OPTION(msx, "dsk", "MSX SS", basicdsk_identify_default, basicdsk_construct_default, NULL,
745      HEADS([1])
746      TRACKS([80])
747      SECTORS([9])
748      SECTOR_LENGTH([512])
749      FIRST_SECTOR_ID([1]))
750   FLOPPY_OPTION(msx, "dsk", "MSX DS", basicdsk_identify_default, basicdsk_construct_default, NULL,
751      HEADS([2])
752      TRACKS([80])
753      SECTORS([9])
754      SECTOR_LENGTH([512])
755      FIRST_SECTOR_ID([1]))
756FLOPPY_OPTIONS_END
757
758/*
759** The PPI functions
760*/
761
762static WRITE8_DEVICE_HANDLER ( msx_ppi_port_a_w )
763{
764   msx_state *state = device->machine().driver_data<msx_state>();
765   state->m_primary_slot = data;
766
767   if (VERBOSE)
768      logerror ("write to primary slot select: %02x\n", state->m_primary_slot);
769   msx_memory_map_all (device->machine());
770}
771
772static WRITE8_DEVICE_HANDLER ( msx_ppi_port_c_w )
773{
774   msx_state *state = device->machine().driver_data<msx_state>();
775   
776   state->keylatch = data & 0x0f;
777
778   /* caps lock */
779   if ( (state->m_port_c_old ^ data) & 0x40)
780      set_led_status (device->machine(),1, !(data & 0x40) );
781
782   /* key click */
783   if ( (state->m_port_c_old ^ data) & 0x80)
784      dac_signed_data_w (device->machine().device("dac"), (data & 0x80 ? 0x7f : 0));
785
786   /* cassette motor on/off */
787   if ( (state->m_port_c_old ^ data) & 0x10)
788      cassette_change_state(cassette_device_image(device->machine()),
789                  (data & 0x10) ? CASSETTE_MOTOR_DISABLED :
790                              CASSETTE_MOTOR_ENABLED,
791                  CASSETTE_MASK_MOTOR);
792
793   /* cassette signal write */
794   if ( (state->m_port_c_old ^ data) & 0x20)
795      cassette_output(cassette_device_image(device->machine()), (data & 0x20) ? -1.0 : 1.0);
796
797   state->m_port_c_old = data;
798}
799
800static READ8_DEVICE_HANDLER( msx_ppi_port_b_r )
801{
802   msx_state *state = device->machine().driver_data<msx_state>();
803   UINT8 result = 0xff;
804   int row, data;
805   static const char *const keynames[] = { "KEY0", "KEY1", "KEY2", "KEY3", "KEY4", "KEY5" };
806
807   row = state->keylatch;
808   if (row <= 10)
809   {
810      data = input_port_read(device->machine(), keynames[row / 2]);
811
812      if (row & 1)
813         data >>= 8;
814      result = data & 0xff;
815   }
816   return result;
817}
818
819/************************************************************************
820 *
821 * New memory emulation !!
822 *
823 ***********************************************************************/
824
825static void msx_memory_init (running_machine &machine)
826{
827   msx_state *state = machine.driver_data<msx_state>();
828   int   prim, sec, page, extent, option;
829   int size = 0;
830   const msx_slot_layout *layout= (msx_slot_layout*)NULL;
831   const msx_slot *slot;
832   const msx_driver_struct *driver;
833   slot_state *st;
834   UINT8 *mem = NULL;
835
836   state->m_empty = auto_alloc_array(machine, UINT8, 0x4000);
837   memset (state->m_empty, 0xff, 0x4000);
838
839   for (prim=0; prim<4; prim++) {
840      for (sec=0; sec<4; sec++) {
841         for (page=0; page<4; page++) {
842            state->m_all_state[prim][sec][page]= (slot_state*)NULL;
843         }
844      }
845   }
846
847   for (driver = msx_driver_list; driver->name[0]; driver++) {
848      if (!strcmp (driver->name, machine.system().name)) {
849         layout = driver->layout;
850      }
851   }
852
853   if (!layout) {
854      logerror ("msx_memory_init: error: missing layout definition in "
855              "msx_driver_list\n");
856      return;
857   }
858
859   state->layout = layout;
860
861   for (; layout->entry != MSX_LAYOUT_LAST; layout++) {
862
863      switch (layout->entry) {
864      case MSX_LAYOUT_SLOT_ENTRY:
865         prim = layout->slot_primary;
866         sec = layout->slot_secondary;
867         page = layout->slot_page;
868         extent = layout->page_extent;
869
870         if (layout->slot_secondary) {
871            state->m_slot_expanded[layout->slot_primary]= TRUE;
872         }
873
874         slot = &msx_slot_list[layout->type];
875         if (slot->slot_type != layout->type) {
876            logerror ("internal error: msx_slot_list[%d].type != %d\n",
877                     slot->slot_type, slot->slot_type);
878         }
879
880         size = layout->size;
881         option = layout->option;
882
883         if (VERBOSE)
884         {
885            logerror ("slot %d/%d/%d-%d: type %s, size 0x%x\n",
886               prim, sec, page, page + extent - 1, slot->name, size);
887         }
888
889         st = (slot_state*)NULL;
890         if (layout->type == SLOT_CARTRIDGE1) {
891            st = state->m_cart_state[0];
892            if (!st) {
893               slot = &msx_slot_list[SLOT_SOUNDCARTRIDGE];
894               size = 0x20000;
895            }
896         }
897         if (layout->type == SLOT_CARTRIDGE2) {
898            st = state->m_cart_state[1];
899            if (!st) {
900               /* Check whether the optional FM-PAC rom is present */
901               option = 0x10000;
902               size = 0x10000;
903               mem = machine.region("maincpu")->base() + option;
904               if (machine.region("maincpu")->bytes() >= size + option && mem[0] == 'A' && mem[1] == 'B') {
905                  slot = &msx_slot_list[SLOT_FMPAC];
906               }
907               else {
908                  slot = &msx_slot_list[SLOT_EMPTY];
909               }
910            }
911         }
912
913         if (!st) {
914            switch (slot->mem_type) {
915
916            case MSX_MEM_HANDLER:
917            case MSX_MEM_ROM:
918               mem = machine.region("maincpu")->base() + option;
919               break;
920            case MSX_MEM_RAM:
921               mem = NULL;
922               break;
923            }
924            st = auto_alloc_clear (machine, slot_state);
925            memset (st, 0, sizeof (slot_state));
926
927            if (slot->init (machine, st, layout->slot_page, mem, size)) {
928               continue;
929            }
930         }
931
932         while (extent--) {
933            if (page > 3) {
934               logerror ("internal error: msx_slot_layout wrong, "
935                   "page + extent > 3\n");
936               break;
937            }
938            state->m_all_state[prim][sec][page] = st;
939            page++;
940         }
941         break;
942      case MSX_LAYOUT_KANJI_ENTRY:
943         state->m_kanji_mem = machine.region("maincpu")->base() + layout->option;
944         break;
945      case MSX_LAYOUT_RAMIO_SET_BITS_ENTRY:
946         state->m_ramio_set_bits = (UINT8)layout->option;
947         break;
948      }
949   }
950}
951
952static void msx_memory_reset (running_machine &machine)
953{
954   msx_state *state = machine.driver_data<msx_state>();
955   slot_state *st, *last_st = (slot_state*)NULL;
956   int prim, sec, page;
957
958   state->m_primary_slot = 0;
959
960   for (prim=0; prim<4; prim++) {
961      state->m_secondary_slot[prim] = 0;
962      for (sec=0; sec<4; sec++) {
963         for (page=0; page<4; page++) {
964            st = state->m_all_state[prim][sec][page];
965            if (st && st != last_st) {
966               msx_slot_list[st->m_type].reset (machine, st);
967            }
968            last_st = st;
969         }
970      }
971   }
972}
973
974static void msx_memory_set_carts (running_machine &machine)
975{
976   msx_state *state = machine.driver_data<msx_state>();
977   const msx_slot_layout *layout;
978   int page;
979
980   if (!state->layout) {
981      return;
982   }
983
984   for (layout = state->layout; layout->entry != MSX_LAYOUT_LAST; layout++) {
985
986      if (layout->entry == MSX_LAYOUT_SLOT_ENTRY) {
987
988         switch (layout->type) {
989         case SLOT_CARTRIDGE1:
990            for (page=0; page<4; page++) {
991               state->m_all_state[layout->slot_primary]
992                          [layout->slot_secondary]
993                          [page] = state->m_cart_state[0];
994            }
995            break;
996         case SLOT_CARTRIDGE2:
997            for (page=0; page<4; page++) {
998               state->m_all_state[layout->slot_primary]
999                          [layout->slot_secondary]
1000                          [page] = state->m_cart_state[1];
1001            }
1002            break;
1003         }
1004      }
1005   }
1006}
1007
1008static void msx_memory_map_page (running_machine &machine, int page)
1009{
1010   msx_state *state = machine.driver_data<msx_state>();
1011   int slot_primary;
1012   int slot_secondary;
1013   slot_state *st;
1014   const msx_slot *slot;
1015
1016   slot_primary = (state->m_primary_slot >> (page * 2)) & 3;
1017   slot_secondary = (state->m_secondary_slot[slot_primary] >> (page * 2)) & 3;
1018
1019   st = state->m_all_state[slot_primary][slot_secondary][page];
1020   slot = st ? &msx_slot_list[st->m_type] : &msx_slot_list[SLOT_EMPTY];
1021   state->m_state[page] = st;
1022   state->m_slot[page] = slot;
1023
1024   if (VERBOSE)
1025   {
1026      logerror ("mapping %s in %d/%d/%d\n", slot->name, slot_primary,
1027         slot_secondary, page);
1028   }
1029   slot->map (machine, st, page);
1030}
1031
1032static void msx_memory_map_all (running_machine &machine)
1033{
1034   int i;
1035
1036   for (i=0; i<4; i++) {
1037      msx_memory_map_page (machine, i);
1038   }
1039}
1040
1041WRITE8_HANDLER (msx_page0_w)
1042{
1043   msx_state *state = space->machine().driver_data<msx_state>();
1044   if ( offset == 0 )
1045   {
1046      state->m_superloadrunner_bank = data;
1047      if (state->m_slot[2]->slot_type == SLOT_SUPERLOADRUNNER) {
1048         state->m_slot[2]->map (space->machine(), state->m_state[2], 2);
1049      }
1050   }
1051
1052   switch (state->m_slot[0]->mem_type) {
1053   case MSX_MEM_RAM:
1054      state->m_ram_pages[0][offset] = data;
1055      break;
1056   case MSX_MEM_HANDLER:
1057      state->m_slot[0]->write (space->machine(), state->m_state[0], offset, data);
1058   }
1059}
1060
1061WRITE8_HANDLER (msx_page0_1_w)
1062{
1063   msx_page0_w( space, 0x2000 + offset, data );
1064}
1065
1066WRITE8_HANDLER (msx_page1_w)
1067{
1068   msx_state *state = space->machine().driver_data<msx_state>();
1069   switch (state->m_slot[1]->mem_type) {
1070   case MSX_MEM_RAM:
1071      state->m_ram_pages[1][offset] = data;
1072      break;
1073   case MSX_MEM_HANDLER:
1074      state->m_slot[1]->write (space->machine(), state->m_state[1], 0x4000 + offset, data);
1075   }
1076}
1077
1078WRITE8_HANDLER (msx_page1_1_w)
1079{
1080   msx_page1_w( space, 0x2000 + offset, data );
1081}
1082
1083WRITE8_HANDLER (msx_page1_2_w)
1084{
1085   msx_page1_w( space, 0x3ff8 + offset, data );
1086}
1087
1088WRITE8_HANDLER (msx_page2_w)
1089{
1090   msx_state *state = space->machine().driver_data<msx_state>();
1091   switch (state->m_slot[2]->mem_type) {
1092   case MSX_MEM_RAM:
1093      state->m_ram_pages[2][offset] = data;
1094      break;
1095   case MSX_MEM_HANDLER:
1096      state->m_slot[2]->write (space->machine(), state->m_state[2], 0x8000 + offset, data);
1097   }
1098}
1099
1100WRITE8_HANDLER (msx_page2_1_w)
1101{
1102   msx_page2_w( space, 0x1800 + offset, data );
1103}
1104
1105WRITE8_HANDLER (msx_page2_2_w)
1106{
1107   msx_page2_w( space, 0x2000 + offset, data );
1108}
1109
1110WRITE8_HANDLER (msx_page2_3_w)
1111{
1112   msx_page2_w( space, 0x3800 + offset, data );
1113}
1114
1115WRITE8_HANDLER (msx_page3_w)
1116{
1117   msx_state *state = space->machine().driver_data<msx_state>();
1118   switch (state->m_slot[3]->mem_type) {
1119   case MSX_MEM_RAM:
1120      state->m_ram_pages[3][offset] = data;
1121      break;
1122   case MSX_MEM_HANDLER:
1123      state->m_slot[3]->write (space->machine(), state->m_state[3], 0xc000 + offset, data);
1124   }
1125}
1126
1127WRITE8_HANDLER (msx_page3_1_w)
1128{
1129   msx_page3_w( space, 0x2000 + offset, data );
1130}
1131
1132WRITE8_HANDLER (msx_sec_slot_w)
1133{
1134   msx_state *state = space->machine().driver_data<msx_state>();
1135   int slot = state->m_primary_slot >> 6;
1136   if (state->m_slot_expanded[slot])
1137   {
1138      if (VERBOSE)
1139         logerror ("write to secondary slot %d select: %02x\n", slot, data);
1140
1141      state->m_secondary_slot[slot] = data;
1142      msx_memory_map_all (space->machine());
1143   }
1144   else {
1145      msx_page3_w(space, 0x3fff, data);
1146   }
1147}
1148
1149READ8_HANDLER (msx_sec_slot_r)
1150{
1151   msx_state *state = space->machine().driver_data<msx_state>();
1152   UINT8 result;
1153   int slot = state->m_primary_slot >> 6;
1154
1155   if (state->m_slot_expanded[slot])
1156      result = ~state->m_secondary_slot[slot];
1157   else
1158      result = state->m_top_page[0x1fff];
1159
1160   return result;
1161}
1162
1163WRITE8_HANDLER (msx_ram_mapper_w)
1164{
1165   msx_state *state = space->machine().driver_data<msx_state>();
1166   state->m_ram_mapper[offset] = data;
1167   if (state->m_slot[offset]->slot_type == SLOT_RAM_MM) {
1168      state->m_slot[offset]->map (space->machine(), state->m_state[offset], offset);
1169   }
1170}
1171
1172READ8_HANDLER (msx_ram_mapper_r)
1173{
1174   msx_state *state = space->machine().driver_data<msx_state>();
1175   return state->m_ram_mapper[offset] | state->m_ramio_set_bits;
1176}
1177
1178WRITE8_HANDLER (msx_90in1_w)
1179{
1180   msx_state *state = space->machine().driver_data<msx_state>();
1181   state->m_korean90in1_bank = data;
1182   if (state->m_slot[1]->slot_type == SLOT_KOREAN_90IN1)
1183   {
1184      state->m_slot[1]->map (space->machine(), state->m_state[1], 1);
1185   }
1186   if (state->m_slot[2]->slot_type == SLOT_KOREAN_90IN1)
1187   {
1188      state->m_slot[2]->map (space->machine(), state->m_state[2], 2);
1189   }
1190}
1191
1192READ8_HANDLER (msx_kanji_r)
1193{
1194   msx_state *state = space->machine().driver_data<msx_state>();
1195   UINT8 result = 0xff;
1196
1197   if (offset && state->m_kanji_mem)
1198   {
1199      int latch;
1200      UINT8 ret;
1201
1202      latch = state->m_kanji_latch;
1203      ret = state->m_kanji_mem[latch++];
1204
1205      state->m_kanji_latch &= ~0x1f;
1206      state->m_kanji_latch |= latch & 0x1f;
1207
1208      result = ret;
1209   }
1210   return result;
1211}
1212
1213WRITE8_HANDLER (msx_kanji_w)
1214{
1215   msx_state *state = space->machine().driver_data<msx_state>();
1216   if (offset)
1217   {
1218      state->m_kanji_latch =
1219            (state->m_kanji_latch & 0x007E0) | ((data & 0x3f) << 11);
1220   }
1221   else
1222   {
1223      state->m_kanji_latch =
1224            (state->m_kanji_latch & 0x1f800) | ((data & 0x3f) << 5);
1225   }
1226}
src/mess/machine/nes_mmc.c
r11460r11461
1/*****************************************************************************************
2
3    NES MMC Emulation
4
5
6    MESS source file to handle various Multi-Memory Controllers (aka Mappers) used by NES carts.
7
8    Many information about the mappers below come from the wonderful doc written by Disch.
9    Current info (when used) are based on v0.6.1 of his docs.
10    You can find the latest version of the doc at http://www.romhacking.net/docs/362/
11
12
13    Missing components:
14    * Currently, we are not emulating 4-screen mirroring (only 3 games use it)
15    * We need a better way to implement CPU cycle based IRQ. Currently we update their counter once every scanline
16      but, with this approach, every time 114 clocks have passed and for certain games it is too much!
17    * We need to emulate additional sound hardware in mappers 019, 024, 026, 069, 085 (and possibly other ones)
18    * We need to emulate EEPROM in mapper 016 and 159
19    * Barcode World (mapper 069) and Datach games (mapper 157) need Barcode Reader emulation
20      Notice that for mapper 157, the barcode reader enters in the irq, so glitches may be related to this!
21    * Karaoke Studio (mapper 188) misses input devices
22
23    Known issues on specific mappers:
24
25    * 000 F1 Race requires more precise PPU timing. It currently has plenty of 1-line glitches.
26    * 001 Yoshi flashes in-game. Back to the Future have heavily corrupted graphics (since forever).
27    * 001 SOROM boards do not properly handle the two WRAM/Battery banks
28    * 002, 003, 094, 097, 152 Bus conflict?
29    * 003 Firehouse Rescue has flashing graphics
30    * 004 Mendel Palace has never worked properly
31    * 004 Ninja Gaiden 2 has flashing bg graphics in the second level
32    * 005 has issues (see e.g. Just Breed or Metal Slader Glory), RAM banking needs hardware flags to determine size
33    * 007 Marble Madness has small graphics corruptions
34    * 014 in-game graphics is glitched
35    * 015 Shanghai Tycoon has corrupted graphics
36    * 033 has still some graphics problem (e.g. missing text in Akira)
37    * 034 Impossible Mission II does not show graphics
38    * 038 seems to miss inputs. separate reads?
39    * 042 Ai Senshi Nicol has broken graphics (our Mapper 42 implementation does not handle CHR banks)
40    * 048 Don Doko Don 2 freezes when you reach the first boss
41    * 051 only half of the games work
42    * 064 has many IRQ problems (due to the way we implement CPU based IRQ) - see Skull & Crossbones.
43          Klax has problems as well (even if it uses scanline based IRQ, according to Disch's docs).
44    * 067 some 1-line glitches that cannot be solved without a better implementation for cycle-based IRQs
45    * 071 Fire Hawk is flashing all the times.
46    * 072, 086, 092 lack samples support (maybe others as well)
47    * 073 16 bit IRQ mode is not implemented
48    * 077 Requires 4-screen mirroring. Currently, it is very glitchy
49    * 083 has serious glitches
50    * 088 Quinty has never worked properly
51    * 096 is preliminary (no correct chr switch in connection to PPU)
52    * 104 Not all the games work
53    * 107 Are the scrolling glitches (check status bar) correct? NEStopia behaves similarly
54    * 112 Master Shooter is not working and misses some graphics
55    * 117 In-game glitches
56    * 119 Pin Bot has glitches when the ball is in the upper half of the screen
57    * 133 Qi Wang starts with corrupted graphics (ingame seems better)
58    * 143 are Dancing Block borders (in the intro) correct?
59    * 158 In addition to IRQ problems (same as 64), mirroring was just a guess (wrong?). info needed!
60    * 164 preliminary - no sprites?
61    * 176 has some graphics problem
62    * 178 Fan Kong Jin Ying is not working (but not even in NEStopia)
63    * 180 Crazy Climber controller?
64    * 187, 198, 208, 215 have some PRG banking issues - preliminary!
65    * 188 needs mic input (reads from 0x6000-0x7fff)
66    * 197 Super Fighter 3 has some glitch in-game (maybe mirroring?)
67    * 222 is only preliminar (wrong IRQ, mirroring or CHR banking?)
68    * 225 115-in-1 has glitches in the menu (games seem fine)
69    * 229 is preliminary
70    * 230 not working yet (needs a value to flip at reset)
71    * 232 has graphics glitches
72    * 241 Commandos is not working (but not even in NEStopia)
73    * 242 In Dragon Quest VIII graphics of the main character is not drawn (it seems similar to Shanghai Tycoon [map15]
74          because in place of the missing graphics we get glitches in the left border)
75    * 249 only half of the games work (and Du Bao Ying Hao seems to suffer the same problem as DQ8 and Shanghai Tycoon)
76    * 255 does not really select game (same in NEStopia apparently)
77
78    A few Mappers suffer of hardware conflict: original dumpers have used the same mapper number for more than
79    a kind of boards. In these cases (and only in these cases) we exploit nes.hsi to set up accordingly
80    emulation. Games which requires this hack are the following:
81    * 032 - Major League needs hardwired mirroring (missing windows and glitched field in top view, otherwise)
82    * 034 - Impossible Mission II is not like BxROM games (it writes to 0x7ffd-0x7fff, instead of 0x8000). It is still
83          unplayable though (see above)
84    * 071 - Fire Hawk is different from other Camerica games (no hardwired mirroring). Without crc_hack no helicopter graphics
85    * 078 - Cosmo Carrier needs a different mirroring than Holy Diver
86    * 113 - HES 6-in-1 requires mirroring (check Bookyman playfield), while other games break with this (check AV Soccer)
87    * 153 - Famicom Jump II uses a different board (or the same in a very different way)
88    * 242 - DQ8 has no mirroring (missing graphics is due to other reasons though)
89
90    crc_hacks have been added also to handle a few wiring settings which would require submappers:
91    * CHR protection pins for mapper 185
92    * VRC-2, VRC-4 and VRC-6 line wiring
93
94    Known issues on specific UNIF boards:
95    * BMC-GS2004 is not working
96    * BMC-GS2013 is not working
97    * BMC-WS some games have corrupted graphics (e.g. Galaxian)
98    * UNL-8237 is not working
99    * UNL-KOF97 is not working
100
101    Details to investigate:
102    * 034 writes to 0x8000-0xffff should not be used for NINA-001 and BNROM, only unlicensed BxROM...
103    * 144 we ignore writes to 0x8000 while NEStopia does not. is it a problem?
104    * 240 we do not map writes to 0x4020-0x40ff. is this a problem?
105    * some other emus uses mapper 210 for mapper 019 games without additional sound hardware and mirroring capabilities
106      (in 210 mirroring is hardwired). However, simply initializing mirroring to Vertical in 019 seems to fix all glitches
107      in 210 games, so there seems to be no reason to have this duplicate mapper
108
109    Some mappers copy PRG rom in SRAM region. Below is a list of those which does it (in MESS) to further
110    investigate if we are supporting them in the right way (e.g. do any of the following have conflicts with SRAM?):
111    * 065 (Gimmick! breaks badly without it)
112    * 040, 042, 050
113
114    Remember that the MMC # does not equal the mapper #. In particular, Mapper 4 is
115    in fact MMC3, Mapper 9 is MMC2 and Mapper 10 is MMC4. Makes perfect sense, right?
116
117    TODO:
118    - add more info
119    - add missing mappers
120
121****************************************************************************************/
122
123#include "emu.h"
124#include "cpu/m6502/m6502.h"
125#include "video/ppu2c0x.h"
126#include "includes/nes.h"
127#include "nes_mmc.h"
128#include "sound/nes_apu.h"
129
130#ifdef MAME_DEBUG
131#define VERBOSE 1
132#else
133#define VERBOSE 0
134#endif
135
136#define LOG_MMC(x) do { if (VERBOSE) logerror x; } while (0)
137#define LOG_FDS(x) do { if (VERBOSE) logerror x; } while (0)
138
139static void ffe_irq( device_t *device, int scanline, int vblank, int blanked );
140static WRITE8_HANDLER( mapper6_l_w );
141static WRITE8_HANDLER( mapper6_w );
142static WRITE8_HANDLER( mapper8_w );
143static WRITE8_HANDLER( mapper17_l_w );
144
145/*************************************************************
146
147    Base emulation (see drivers/nes.c):
148    memory 0x0000-0x1fff RAM
149           0x2000-0x3fff PPU
150           0x4000-0x4017 APU
151           0x4018-0x5fff Expansion Area
152           0x6000-0x7fff PRG RAM
153           0x8000-0xffff PRG ROM
154
155    nes_chr_r/w take care of RAM, nes_nt_r/w take care of PPU.
156    for mapper specific emulation, we generically setup the
157    following handlers:
158    - nes_low_mapper_r/w take care of accesses to 0x4100-0x5fff
159      (calling state->m_mmc_write_low/state->m_mmc_read_low)
160    - state->m_mmc_write/read_mid take care of 0x6000-0x7fff
161    - state->m_mmc_write/read take care of access to 0x8000-0xffff
162      (most mappers only writes in this area)
163    some mappers may access 0x4018-0x4100: this must be taken
164    care separately in init_nes_core
165
166*************************************************************/
167
168WRITE8_HANDLER( nes_chr_w )
169{
170   nes_state *state = space->machine().driver_data<nes_state>();
171   int bank = offset >> 10;
172
173   if (state->m_chr_map[bank].source == CHRRAM)
174   {
175      state->m_chr_map[bank].access[offset & 0x3ff] = data;
176   }
177}
178
179READ8_HANDLER( nes_chr_r )
180{
181   nes_state *state = space->machine().driver_data<nes_state>();
182   int bank = offset >> 10;
183
184   // a few CNROM boards contained copy protection schemes through
185   // suitably configured diodes, so that subsequent CHR reads can
186   // give actual VROM content or open bus values.
187   // For most boards, chr_open_bus remains always zero.
188   if (state->m_chr_open_bus)
189      return 0xff;
190
191   return state->m_chr_map[bank].access[offset & 0x3ff];
192}
193
194WRITE8_HANDLER( nes_nt_w )
195{
196   nes_state *state = space->machine().driver_data<nes_state>();
197   int page = ((offset & 0xc00) >> 10);
198
199   if (state->m_nt_page[page].writable == 0)
200      return;
201
202   state->m_nt_page[page].access[offset & 0x3ff] = data;
203}
204
205READ8_HANDLER( nes_nt_r )
206{
207   nes_state *state = space->machine().driver_data<nes_state>();
208   int page = ((offset & 0xc00) >> 10);
209
210   if (state->m_nt_page[page].source == MMC5FILL)
211   {
212      if ((offset & 0x3ff) >= 0x3c0)
213         return state->m_MMC5_floodattr;
214
215      return state->m_MMC5_floodtile;
216   }
217   return state->m_nt_page[page].access[offset & 0x3ff];
218}
219
220WRITE8_HANDLER( nes_low_mapper_w )
221{
222   nes_state *state = space->machine().driver_data<nes_state>();
223
224   if (state->m_mmc_write_low)
225      (*state->m_mmc_write_low)(space, offset, data);
226   else
227      logerror("Unimplemented LOW mapper write, offset: %04x, data: %02x\n", offset + 0x4100, data);
228}
229
230READ8_HANDLER( nes_low_mapper_r )
231{
232   nes_state *state = space->machine().driver_data<nes_state>();
233
234   if (state->m_mmc_read_low)
235      return (*state->m_mmc_read_low)(space, offset);
236   else
237      logerror("Unimplemented LOW mapper read, offset: %04x\n", offset + 0x4100);
238
239   return 0;
240}
241
242/*************************************************************
243
244    Helpers to handle MMC
245
246*************************************************************/
247
248static void wram_bank( running_machine &machine, int bank, int source )
249{
250   nes_state *state = machine.driver_data<nes_state>();
251
252   assert(state->m_battery || state->m_prg_ram);
253   if (source == NES_BATTERY)
254   {
255      bank &= (state->m_battery_size / 0x2000) - 1;
256      state->m_prg_bank[4] = state->m_battery_bank5_start + bank;
257   }
258   else
259   {
260      bank &= (state->m_wram_size / 0x2000) - 1;
261      state->m_prg_bank[4] = state->m_prgram_bank5_start + bank;
262   }
263   memory_set_bank(machine, "bank5", state->m_prg_bank[4]);
264}
265
266INLINE void prg_bank_refresh( running_machine &machine )
267{
268   nes_state *state = machine.driver_data<nes_state>();
269   memory_set_bank(machine, "bank1", state->m_prg_bank[0]);
270   memory_set_bank(machine, "bank2", state->m_prg_bank[1]);
271   memory_set_bank(machine, "bank3", state->m_prg_bank[2]);
272   memory_set_bank(machine, "bank4", state->m_prg_bank[3]);
273}
274
275/* PRG ROM in 8K, 16K or 32K blocks */
276
277static void prg32( running_machine &machine, int bank )
278{
279   nes_state *state = machine.driver_data<nes_state>();
280
281   /* if there is only 16k PRG, return */
282   if (!(state->m_prg_chunks >> 1))
283      return;
284
285   /* assumes that bank references a 32k chunk */
286   bank &= ((state->m_prg_chunks >> 1) - 1);
287
288   state->m_prg_bank[0] = bank * 4 + 0;
289   state->m_prg_bank[1] = bank * 4 + 1;
290   state->m_prg_bank[2] = bank * 4 + 2;
291   state->m_prg_bank[3] = bank * 4 + 3;
292   prg_bank_refresh(machine);
293}
294
295static void prg16_89ab( running_machine &machine, int bank )
296{
297   nes_state *state = machine.driver_data<nes_state>();
298
299   /* assumes that bank references a 16k chunk */
300   bank &= (state->m_prg_chunks - 1);
301
302   state->m_prg_bank[0] = bank * 2 + 0;
303   state->m_prg_bank[1] = bank * 2 + 1;
304   prg_bank_refresh(machine);
305}
306
307static void prg16_cdef( running_machine &machine, int bank )
308{
309   nes_state *state = machine.driver_data<nes_state>();
310
311   /* assumes that bank references a 16k chunk */
312   bank &= (state->m_prg_chunks - 1);
313
314   state->m_prg_bank[2] = bank * 2 + 0;
315   state->m_prg_bank[3] = bank * 2 + 1;
316   prg_bank_refresh(machine);
317}
318
319static void prg8_89( running_machine &machine, int bank )
320{
321   nes_state *state = machine.driver_data<nes_state>();
322
323   /* assumes that bank references an 8k chunk */
324   bank &= ((state->m_prg_chunks << 1) - 1);
325
326   state->m_prg_bank[0] = bank;
327   prg_bank_refresh(machine);
328}
329
330static void prg8_ab( running_machine &machine, int bank )
331{
332   nes_state *state = machine.driver_data<nes_state>();
333
334   /* assumes that bank references an 8k chunk */
335   bank &= ((state->m_prg_chunks << 1) - 1);
336
337   state->m_prg_bank[1] = bank;
338   prg_bank_refresh(machine);
339}
340
341static void prg8_cd( running_machine &machine, int bank )
342{
343   nes_state *state = machine.driver_data<nes_state>();
344
345   /* assumes that bank references an 8k chunk */
346   bank &= ((state->m_prg_chunks << 1) - 1);
347
348   state->m_prg_bank[2] = bank;
349   prg_bank_refresh(machine);
350}
351
352static void prg8_ef( running_machine &machine, int bank )
353{
354   nes_state *state = machine.driver_data<nes_state>();
355
356   /* assumes that bank references an 8k chunk */
357   bank &= ((state->m_prg_chunks << 1) - 1);
358
359   state->m_prg_bank[3] = bank;
360   prg_bank_refresh(machine);
361}
362
363/* We define an additional helper to map PRG-ROM to 0x6000-0x7000 */
364// TODO: are we implementing this correctly in the mappers which uses it? check!
365
366static void prg8_67( running_machine &machine, int bank )
367{
368   nes_state *state = machine.driver_data<nes_state>();
369
370   /* assumes that bank references an 8k chunk */
371   bank &= ((state->m_prg_chunks << 1) - 1);
372
373   state->m_prg_bank[4] = bank;
374   memory_set_bank(machine, "bank5", state->m_prg_bank[4]);
375}
376
377/* We also define an additional helper to map 8k PRG-ROM to one of the banks (passed as parameter) */
378static void prg8_x( running_machine &machine, int start, int bank )
379{
380   nes_state *state = machine.driver_data<nes_state>();
381
382   assert(start < 4);
383
384   /* assumes that bank references an 8k chunk */
385   bank &= ((state->m_prg_chunks << 1) - 1);
386
387   state->m_prg_bank[start] = bank;
388   prg_bank_refresh(machine);
389}
390
391/* CHR ROM in 1K, 2K, 4K or 8K blocks */
392
393// this can be probably removed later, but it is useful while testing xml and unf handling with VRAM & VROM
394INLINE void chr_sanity_check( running_machine &machine, int source )
395{
396   nes_state *state = machine.driver_data<nes_state>();
397
398   if (source == CHRRAM && state->m_vram == NULL)
399      fatalerror("CHRRAM bankswitch with no VRAM");
400
401   if (source == CHRROM && state->m_vrom == NULL)
402      fatalerror("CHRROM bankswitch with no VROM");
403}
404
405static void chr8( running_machine &machine, int bank, int source )
406{
407   nes_state *state = machine.driver_data<nes_state>();
408   int i;
409
410   chr_sanity_check(machine, source);
411
412   if (source == CHRRAM)
413   {
414      bank &= (state->m_vram_chunks - 1);
415      for (i = 0; i < 8; i++)
416      {
417         state->m_chr_map[i].source = source;
418         state->m_chr_map[i].origin = (bank * 0x2000) + (i * 0x400); // for save state uses!
419         state->m_chr_map[i].access = &state->m_vram[state->m_chr_map[i].origin];
420      }
421   }
422   else
423   {
424      bank &= (state->m_chr_chunks - 1);
425      for (i = 0; i < 8; i++)
426      {
427         state->m_chr_map[i].source = source;
428         state->m_chr_map[i].origin = (bank * 0x2000) + (i * 0x400); // for save state uses!
429         state->m_chr_map[i].access = &state->m_vrom[state->m_chr_map[i].origin];
430      }
431   }
432}
433
434static void chr4_x( running_machine &machine, int start, int bank, int source )
435{
436   nes_state *state = machine.driver_data<nes_state>();
437   int i;
438
439   chr_sanity_check(machine, source);
440
441   if (source == CHRRAM)
442   {
443      bank &= ((state->m_vram_chunks << 1) - 1);
444      for (i = 0; i < 4; i++)
445      {
446         state->m_chr_map[i + start].source = source;
447         state->m_chr_map[i + start].origin = (bank * 0x1000) + (i * 0x400); // for save state uses!
448         state->m_chr_map[i + start].access = &state->m_vram[state->m_chr_map[i + start].origin];
449      }
450   }
451   else
452   {
453      bank &= ((state->m_chr_chunks << 1) - 1);
454      for (i = 0; i < 4; i++)
455      {
456         state->m_chr_map[i + start].source = source;
457         state->m_chr_map[i + start].origin = (bank * 0x1000) + (i * 0x400); // for save state uses!
458         state->m_chr_map[i + start].access = &state->m_vrom[state->m_chr_map[i + start].origin];
459      }
460   }
461}
462
463static void chr4_0( running_machine &machine, int bank, int source )
464{
465   chr4_x(machine, 0, bank, source);
466}
467
468static void chr4_4( running_machine &machine, int bank, int source )
469{
470   chr4_x(machine, 4, bank, source);
471}
472
473static void chr2_x( running_machine &machine, int start, int bank, int source )
474{
475   nes_state *state = machine.driver_data<nes_state>();
476   int i;
477
478   chr_sanity_check(machine, source);
479
480   if (source == CHRRAM)
481   {
482      bank &= ((state->m_vram_chunks << 2) - 1);
483      for (i = 0; i < 2; i++)
484      {
485         state->m_chr_map[i + start].source = source;
486         state->m_chr_map[i + start].origin = (bank * 0x800) + (i * 0x400); // for save state uses!
487         state->m_chr_map[i + start].access = &state->m_vram[state->m_chr_map[i + start].origin];
488      }
489   }
490   else
491   {
492      bank &= ((state->m_chr_chunks << 2) - 1);
493      for (i = 0; i < 2; i++)
494      {
495         state->m_chr_map[i + start].source = source;
496         state->m_chr_map[i + start].origin = (bank * 0x800) + (i * 0x400); // for save state uses!
497         state->m_chr_map[i + start].access = &state->m_vrom[state->m_chr_map[i + start].origin];
498      }
499   }
500}
501
502static void chr2_0( running_machine &machine, int bank, int source )
503{
504   chr2_x(machine, 0, bank, source);
505}
506
507static void chr2_2( running_machine &machine, int bank, int source )
508{
509   chr2_x(machine, 2, bank, source);
510}
511
512static void chr2_4( running_machine &machine, int bank, int source )
513{
514   chr2_x(machine, 4, bank, source);
515}
516
517static void chr2_6( running_machine &machine, int bank, int source )
518{
519   chr2_x(machine, 6, bank, source);
520}
521
522static void chr1_x( running_machine &machine, int start, int bank, int source )
523{
524   nes_state *state = machine.driver_data<nes_state>();
525
526   chr_sanity_check(machine, source);
527
528   if (source == CHRRAM)
529   {
530      bank &= ((state->m_vram_chunks << 3) - 1);
531      state->m_chr_map[start].source = source;
532      state->m_chr_map[start].origin = (bank * 0x400); // for save state uses!
533      state->m_chr_map[start].access = &state->m_vram[state->m_chr_map[start].origin];
534   }
535   else
536   {
537      bank &= ((state->m_chr_chunks << 3) - 1);
538      state->m_chr_map[start].source = source;
539      state->m_chr_map[start].origin = (bank * 0x400); // for save state uses!
540      state->m_chr_map[start].access = &state->m_vrom[state->m_chr_map[start].origin];
541   }
542}
543
544static void chr1_0 (running_machine &machine, int bank, int source)
545{
546   chr1_x(machine, 0, bank, source);
547}
548
549static void chr1_1( running_machine &machine, int bank, int source )
550{
551   chr1_x(machine, 1, bank, source);
552}
553
554static void chr1_2( running_machine &machine, int bank, int source )
555{
556   chr1_x(machine, 2, bank, source);
557}
558
559static void chr1_3( running_machine &machine, int bank, int source )
560{
561   chr1_x(machine, 3, bank, source);
562}
563
564static void chr1_4( running_machine &machine, int bank, int source )
565{
566   chr1_x(machine, 4, bank, source);
567}
568
569static void chr1_5( running_machine &machine, int bank, int source )
570{
571   chr1_x(machine, 5, bank, source);
572}
573
574static void chr1_6( running_machine &machine, int bank, int source )
575{
576   chr1_x(machine, 6, bank, source);
577}
578
579static void chr1_7( running_machine &machine, int bank, int source )
580{
581   chr1_x(machine, 7, bank, source);
582}
583
584
585/* NameTable paging and mirroring */
586
587static void set_nt_page( running_machine &machine, int page, int source, int bank, int writable )
588{
589   nes_state *state = machine.driver_data<nes_state>();
590   UINT8* base_ptr;
591
592   switch (source)
593   {
594      case CART_NTRAM:
595         base_ptr = state->m_extended_ntram;
596         break;
597      case MMC5FILL:
598         base_ptr = NULL;
599         break;
600      case ROM:
601         base_ptr = state->m_vrom;
602         break;
603      case EXRAM:
604         base_ptr = state->m_mapper_ram;
605         break;
606      case CIRAM:
607      default:
608         base_ptr = state->m_ciram;
609         break;
610   }
611
612   page &= 3; /* mask down to the 4 logical pages */
613   state->m_nt_page[page].source = source;
614
615   if (base_ptr != NULL)
616   {
617      state->m_nt_page[page].origin = bank * 0x400;
618      state->m_nt_page[page].access = base_ptr + state->m_nt_page[page].origin;
619   }
620
621   state->m_nt_page[page].writable = writable;
622}
623
624void set_nt_mirroring( running_machine &machine, int mirroring )
625{
626   /* setup our videomem handlers based on mirroring */
627   switch (mirroring)
628   {
629      case PPU_MIRROR_VERT:
630         set_nt_page(machine, 0, CIRAM, 0, 1);
631         set_nt_page(machine, 1, CIRAM, 1, 1);
632         set_nt_page(machine, 2, CIRAM, 0, 1);
633         set_nt_page(machine, 3, CIRAM, 1, 1);
634         break;
635
636      case PPU_MIRROR_HORZ:
637         set_nt_page(machine, 0, CIRAM, 0, 1);
638         set_nt_page(machine, 1, CIRAM, 0, 1);
639         set_nt_page(machine, 2, CIRAM, 1, 1);
640         set_nt_page(machine, 3, CIRAM, 1, 1);
641         break;
642
643      case PPU_MIRROR_HIGH:
644         set_nt_page(machine, 0, CIRAM, 1, 1);
645         set_nt_page(machine, 1, CIRAM, 1, 1);
646         set_nt_page(machine, 2, CIRAM, 1, 1);
647         set_nt_page(machine, 3, CIRAM, 1, 1);
648         break;
649
650      case PPU_MIRROR_LOW:
651         set_nt_page(machine, 0, CIRAM, 0, 1);
652         set_nt_page(machine, 1, CIRAM, 0, 1);
653         set_nt_page(machine, 2, CIRAM, 0, 1);
654         set_nt_page(machine, 3, CIRAM, 0, 1);
655         break;
656
657      case PPU_MIRROR_NONE:
658      case PPU_MIRROR_4SCREEN:
659      default:
660         /* external RAM needs to be used somehow. */
661         /* but as a default, we'll arbitrarily set vertical so as not to crash*/
662         /* mappers should use set_nt_page and assign which pages are which */
663
664         logerror("Mapper set 4-screen mirroring without supplying external nametable memory!\n");
665
666         set_nt_page(machine, 0, CIRAM, 0, 1);
667         set_nt_page(machine, 1, CIRAM, 0, 1);
668         set_nt_page(machine, 2, CIRAM, 1, 1);
669         set_nt_page(machine, 3, CIRAM, 1, 1);
670         break;
671   }
672}
673
674/*  Other custom mirroring helpers are defined below: Waixing games use waixing_set_mirror (which swaps
675    MIRROR_HIGH and MIRROR_LOW compared to the above) and Sachen games use sachen_set_mirror (which has
676    a slightly different MIRROR_HIGH, with page 0 set to 0) */
677
678
679/*************************************************************
680
681 Support for xml list
682
683 *************************************************************/
684
685/* Include emulation of NES PCBs for softlist */
686#include "machine/nes_pcb.c"
687
688
689/*************************************************************
690
691    Support for .unf Files
692
693*************************************************************/
694
695/* Include emulation of UNIF Boards for .unf files */
696#include "machine/nes_unif.c"
697
698
699/*************************************************************
700
701 Support for .nes Files
702
703 *************************************************************/
704
705/* Include emulation of iNES Mappers for .nes files */
706#include "machine/nes_ines.c"
707
src/mess/machine/nes_mmc.h
r11460r11461
1#ifndef __MMC_H
2#define __MMC_H
3
4/* Boards */
5enum
6{
7   STD_NROM = 0,
8   STD_AXROM, STD_BXROM, STD_CNROM, STD_CPROM,
9   STD_DXROM, STD_EXROM, STD_FXROM, STD_GXROM,
10   STD_HKROM, STD_JXROM, STD_MXROM, STD_NXROM,
11   STD_PXROM, STD_SXROM, STD_TXROM, STD_TXSROM,
12   STD_TKROM, STD_TQROM, STD_TVROM,
13   STD_UN1ROM, STD_UXROM,
14   HVC_FAMBASIC, NES_QJ, PAL_ZZ, UXROM_CC,
15   STD_DRROM, STD_SXROM_A, STD_SOROM, STD_SOROM_A,
16   /* Discrete components boards (by various manufacturer) */
17   DIS_74X161X138, DIS_74X139X74,
18   DIS_74X377, DIS_74X161X161X32,
19   /* Active Enterprises */
20   ACTENT_ACT52,
21   /* AGCI */
22   AGCI_50282,
23   /* AVE */
24   AVE_NINA01, AVE_NINA06,
25   /* Bandai */
26   BANDAI_JUMP2, BANDAI_PT554,
27   BANDAI_DATACH, BANDAI_KARAOKE, BANDAI_OEKAKIDS,
28   BANDAI_FCG, BANDAI_LZ93, BANDAI_LZ93EX,
29   /* Caltron */
30   CALTRON_6IN1,
31   /* Camerica */
32   CAMERICA_BF9093, CAMERICA_BF9097, CAMERICA_BF9096,
33   CAMERICA_GOLDENFIVE, GG_NROM,
34   /* Dreamtech */
35   DREAMTECH_BOARD,
36   /* Irem */
37   IREM_G101, IREM_H3001, IREM_LROG017,
38   IREM_TAM_S1, IREM_HOLYDIV,
39   /* Jaleco */
40   JALECO_SS88006, JALECO_JF11, JALECO_JF13,
41   JALECO_JF16, JALECO_JF17, JALECO_JF19,
42   /* Konami */
43   KONAMI_VRC1, KONAMI_VRC2, KONAMI_VRC3,
44   KONAMI_VRC4, KONAMI_VRC6, KONAMI_VRC7,
45   /* Namcot */
46   NAMCOT_163, NAMCOT_3453,
47   NAMCOT_3425, NAMCOT_34X3, NAMCOT_3446,
48   /* NTDEC */
49   NTDEC_ASDER, NTDEC_FIGHTINGHERO,
50   /* Rex Soft */
51   REXSOFT_SL1632, REXSOFT_DBZ5,
52   /* Sachen */
53   SACHEN_8259A, SACHEN_8259B, SACHEN_8259C, SACHEN_8259D,
54   SACHEN_SA009, SACHEN_SA0036, SACHEN_SA0037,
55   SACHEN_SA72007, SACHEN_SA72008, SACHEN_TCA01,
56   SACHEN_TCU01, SACHEN_TCU02,
57   SACHEN_74LS374, SACHEN_74LS374_A,
58   /* Sunsoft */
59   SUNSOFT_1, SUNSOFT_2, SUNSOFT_3, SUNSOFT_4,
60   SUNSOFT_DCS, SUNSOFT_5B, SUNSOFT_FME7,
61   /* Taito */
62   TAITO_TC0190FMC, TAITO_TC0190FMCP,
63   TAITO_X1_005, TAITO_X1_005_A, TAITO_X1_017,
64   /* Tengen */
65   TENGEN_800008, TENGEN_800032, TENGEN_800037,
66   /* TXC */
67   TXC_22211A, TXC_22211B, TXC_22211C,
68   TXC_MXMDHTWO, TXC_TW, TXC_STRIKEWOLF,
69   /* Multigame Carts */
70   BMC_64IN1NR, BMC_190IN1, BMC_A65AS, BMC_GS2004, BMC_GS2013,
71   BMC_HIK8IN1, BMC_NOVELDIAMOND, BMC_S24IN1SC03, BMC_T262,
72   BMC_WS, BMC_SUPERBIG_7IN1, BMC_SUPERHIK_4IN1, BMC_BALLGAMES_11IN1,
73   BMC_MARIOPARTY_7IN1, BMC_SUPER_700IN1, BMC_FAMILY_4646B,
74   BMC_36IN1, BMC_21IN1, BMC_150IN1, BMC_35IN1, BMC_64IN1,
75   BMC_15IN1, BMC_SUPERHIK_300IN1, BMC_9999999IN1, BMC_SUPERGUN_20IN1,
76   BMC_GOLDENCARD_6IN1, BMC_72IN1, BMC_SUPER_42IN1, BMC_76IN1,
77   BMC_1200IN1, BMC_31IN1, BMC_22GAMES, BMC_20IN1, BMC_110IN1,
78   BMC_GKA, BMC_GKB, BMC_VT5201, BMC_BENSHENG_BS5, BMC_810544,
79   BMC_NTD_03, BMC_G63IN1, BMC_FK23C, BMC_FK23CA, BMC_PJOY84,
80   /* Unlicensed */
81   UNL_8237, UNL_CC21, UNL_AX5705, UNL_KOF97,
82   UNL_N625092, UNL_SC127, UNL_SMB2J, UNL_T230,
83   UNL_UXROM, UNL_MK2, UNL_XZY, UNL_KOF96,
84   UNL_SUPERFIGHTER3, UNL_RACERMATE, UNL_EDU2K,
85   UNL_SHJY3, UNL_STUDYNGAME, UNL_603_5052, UNL_H2288,
86   /* Bootleg boards */
87   BTL_SMB2A, BTL_MARIOBABY, BTL_AISENSHINICOL, BTL_TOBIDASE,
88   BTL_SMB2B, BTL_SMB3, BTL_SUPERBROS11, BTL_DRAGONNINJA,
89   BTL_PIKACHUY2K,
90   /* Misc: these are needed to convert mappers to boards, I will sort them later */
91   OPENCORP_DAOU306, HES_BOARD, HES6IN1_BOARD, RUMBLESTATION_BOARD,
92   MAGICSERIES_MD, KASING_BOARD, FUTUREMEDIA_BOARD, FUKUTAKE_BOARD, SOMERI_SL12,
93   HENGEDIANZI_BOARD, HENGEDIANZI_XJZB, SUBOR_TYPE0, SUBOR_TYPE1,
94   KAISER_KS7058, KAISER_KS7032, KAISER_KS7022, KAISER_KS7017, KAISER_KS202, CONY_BOARD,
95   CNE_DECATHLON, CNE_FSB, CNE_SHLZ, RCM_GS2015, RCM_TETRISFAMILY,
96   WAIXING_TYPE_A, WAIXING_TYPE_A_1, WAIXING_TYPE_B, WAIXING_TYPE_C, WAIXING_TYPE_D,
97   WAIXING_TYPE_E, WAIXING_TYPE_F, WAIXING_TYPE_G, WAIXING_TYPE_H,
98   WAIXING_TYPE_I, WAIXING_TYPE_J,
99   WAIXING_SGZLZ, WAIXING_SGZ, WAIXING_ZS, WAIXING_SECURITY, WAIXING_SH2,
100   WAIXING_DQ8, WAIXING_FFV, WAIXING_PS2, SUPERGAME_LIONKING, SUPERGAME_BOOGERMAN,
101   KAY_PANDAPRINCE, HOSENKAN_BOARD, NITRA_TDA, GOUDER_37017, NANJING_BOARD,
102   WHIRLWIND_2706,
103   /* FFE boards, for mappers 6, 8, 17 */
104   FFE_MAPPER6, FFE_MAPPER8, FFE_MAPPER17,
105   /* Unsupported (for place-holder boards, with no working emulation) & no-board (at init) */
106   UNSUPPORTED_BOARD, UNKNOWN_BOARD, NO_BOARD
107};
108
109// these are used to setup the proper PCB ID, for each supported type of files
110int nes_get_pcb_id(running_machine &machine, const char *feature);   // for softlist
111void unif_mapr_setup(running_machine &machine, const char *board);   // for UNIF files
112int nes_get_mmc_id(running_machine &machine, int mapper);   // for iNES files
113
114// these are used to setup handlers and callbacks necessary to the emulation (resp. at start and reset)
115void pcb_handlers_setup(running_machine &machine);
116int nes_pcb_reset(running_machine &machine);
117
118
119WRITE8_HANDLER( nes_low_mapper_w );
120READ8_HANDLER( nes_low_mapper_r );
121WRITE8_HANDLER( nes_chr_w );
122READ8_HANDLER( nes_chr_r );
123WRITE8_HANDLER( nes_nt_w );
124READ8_HANDLER( nes_nt_r );
125
126WRITE8_HANDLER( smb2jb_extra_w );
127WRITE8_HANDLER( ks7017_extra_w );
128READ8_HANDLER( ks7017_extra_r );
129WRITE8_HANDLER( unl_6035052_extra_w );
130READ8_HANDLER( unl_6035052_extra_r );
131READ8_HANDLER( waixing_sh2_chr_r );
132
133//TEMPORARY PPU STUFF
134
135/* mirroring types */
136#define PPU_MIRROR_NONE      0
137#define PPU_MIRROR_VERT      1
138#define PPU_MIRROR_HORZ      2
139#define PPU_MIRROR_HIGH      3
140#define PPU_MIRROR_LOW      4
141#define PPU_MIRROR_4SCREEN   5   // Same effect as NONE, but signals that we should never mirror
142
143void set_nt_mirroring(running_machine &machine, int mirroring);
144
145
146#endif
src/mess/machine/nes_ines.c
r11460r11461
1/*****************************************************************************************
2
3    NES MMC Emulation
4
5    Support for iNES Mappers
6
7****************************************************************************************/
8
9typedef struct _nes_mmc  nes_mmc;
10struct _nes_mmc
11{
12   int    iNesMapper; /* iNES Mapper # */
13   int    pcb_id;
14};
15
16/*************************************************************
17
18    Mapper 6
19
20    Known Boards: FFE4 Copier Board
21    Games: Hacked versions of games
22
23    In MESS: Supported? Not sure if we could also have ExRAM or not...
24       However, priority is pretty low for this mapper.
25
26*************************************************************/
27
28/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
29we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
30there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
31static void ffe_irq( device_t *device, int scanline, int vblank, int blanked )
32{
33   nes_state *state = device->machine().driver_data<nes_state>();
34
35   /* 114 is the number of cycles per scanline */
36   /* TODO: change to reflect the actual number of cycles spent */
37   if (state->m_IRQ_enable)
38   {
39      if ((0xffff - state->m_IRQ_count) < 114)
40      {
41         device_set_input_line(state->m_maincpu, M6502_IRQ_LINE, HOLD_LINE);
42         state->m_IRQ_count = 0xffff;
43         state->m_IRQ_enable = 0;
44      }
45      state->m_IRQ_count -= 114;
46   }
47}
48
49static WRITE8_HANDLER( mapper6_l_w )
50{
51   nes_state *state = space->machine().driver_data<nes_state>();
52   LOG_MMC(("mapper6_l_w, offset: %04x, data: %02x\n", offset, data));
53
54   switch (offset)
55   {
56      case 0x1fe:
57         state->m_mmc_latch1 = data & 0x80;
58         set_nt_mirroring(space->machine(), BIT(data, 4) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
59         break;
60      case 0x1ff:
61         set_nt_mirroring(space->machine(), BIT(data, 4) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
62         break;
63
64      case 0x401:
65         state->m_IRQ_enable = data & 0x01;
66         break;
67      case 0x402:
68         state->m_IRQ_count = (state->m_IRQ_count & 0xff00) | data;
69         break;
70      case 0x403:
71         state->m_IRQ_enable = 1;
72         state->m_IRQ_count = (state->m_IRQ_count & 0x00ff) | (data << 8);
73         break;
74   }
75}
76
77static WRITE8_HANDLER( mapper6_w )
78{
79   nes_state *state = space->machine().driver_data<nes_state>();
80   LOG_MMC(("mapper6_w, offset: %04x, data: %02x\n", offset, data));
81
82   if (!state->m_mmc_latch1)   // when in "FFE mode" we are forced to use CHRRAM/EXRAM bank?
83   {
84      prg16_89ab(space->machine(), data >> 2);
85      // chr8(space->machine(), data & 0x03, ???);
86      // due to lack of info on the exact behavior, we simply act as if mmc_latch1=1
87      if (state->m_mmc_chr_source == CHRROM)
88         chr8(space->machine(), data & 0x03, CHRROM);
89   }
90   else if (state->m_mmc_chr_source == CHRROM)         // otherwise, we can use CHRROM (when present)
91      chr8(space->machine(), data, CHRROM);
92}
93
94/*************************************************************
95
96    Mapper 8
97
98    Known Boards: FFE3 Copier Board
99    Games: Hacked versions of games
100
101    In MESS: Supported? (I have no games to test this)
102
103*************************************************************/
104
105static WRITE8_HANDLER( mapper8_w )
106{
107   LOG_MMC(("mapper8_w, offset: %04x, data: %02x\n", offset, data));
108
109   chr8(space->machine(), data & 0x07, CHRROM);
110   prg16_89ab(space->machine(), data >> 3);
111}
112
113/*************************************************************
114
115    Mapper 17
116
117    Known Boards: FFE8 Copier Board
118    Games: Hacked versions of games
119
120    In MESS: Supported?. IRQ support is just a guess (used to
121      use MMC3 IRQ but it was wrong and it never enabled it)
122
123*************************************************************/
124
125static WRITE8_HANDLER( mapper17_l_w )
126{
127   nes_state *state = space->machine().driver_data<nes_state>();
128   LOG_MMC(("mapper17_l_w, offset: %04x, data: %02x\n", offset, data));
129
130   switch (offset)
131   {
132      case 0x1fe:
133         set_nt_mirroring(space->machine(), BIT(data, 4) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
134         break;
135      case 0x1ff:
136         set_nt_mirroring(space->machine(), BIT(data, 4) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
137         break;
138
139      case 0x401:
140         state->m_IRQ_enable = data & 0x01;
141         break;
142      case 0x402:
143         state->m_IRQ_count = (state->m_IRQ_count & 0xff00) | data;
144         break;
145      case 0x403:
146         state->m_IRQ_enable = 1;
147         state->m_IRQ_count = (state->m_IRQ_count & 0x00ff) | (data << 8);
148         break;
149
150      case 0x404:
151         prg8_89(space->machine(), data);
152         break;
153      case 0x405:
154         prg8_ab(space->machine(), data);
155         break;
156      case 0x406:
157         prg8_cd(space->machine(), data);
158         break;
159      case 0x407:
160         prg8_ef(space->machine(), data);
161         break;
162
163      case 0x410:
164      case 0x411:
165      case 0x412:
166      case 0x413:
167      case 0x414:
168      case 0x415:
169      case 0x416:
170      case 0x417:
171         chr1_x(space->machine(), offset & 7, data, CHRROM);
172         break;
173   }
174}
175
176/*************************************************************
177
178    mmc_list
179
180    Supported mappers and corresponding pcb id
181
182*************************************************************/
183
184static const nes_mmc mmc_list[] =
185{
186/*  INES   DESC                          LOW_W, LOW_R, MED_W, HIGH_W, PPU_latch, scanline CB, hblank CB */
187   {  0, STD_NROM },
188   {  1, STD_SXROM },
189   {  2, STD_UXROM },
190   {  3, STD_CNROM },
191   {  4, STD_TXROM },
192   {  5, STD_EXROM },
193   {  6, FFE_MAPPER6 },
194   {  7, STD_AXROM },
195   {  8, FFE_MAPPER8 },
196   {  9, STD_PXROM },
197   { 10, STD_FXROM },
198   { 11, DIS_74X377 },
199   { 12, REXSOFT_DBZ5 },
200   { 13, STD_CPROM },
201   { 14, REXSOFT_SL1632 },
202   { 15, WAIXING_PS2 },
203   { 16, BANDAI_LZ93EX },   // with 24c02
204   { 17, FFE_MAPPER17 },
205   { 18, JALECO_SS88006 },
206   { 19, NAMCOT_163 },
207   { 21, KONAMI_VRC4 },
208   { 22, KONAMI_VRC2 },
209   { 23, KONAMI_VRC2 },
210   { 24, KONAMI_VRC6 },
211   { 25, KONAMI_VRC4 },
212   { 26, KONAMI_VRC6 },
213   // 27 World Hero board - Unsupported
214   // 28 Unused
215   // 29 Unused
216   // 30 Unused
217   // 31 Unused
218   { 32, IREM_G101 },
219   { 33, TAITO_TC0190FMC },
220   { 34, STD_BXROM },
221   { 35, UNL_SC127 },
222   { 36, TXC_STRIKEWOLF },
223   { 37, PAL_ZZ },
224   { 38, DIS_74X161X138 },
225   { 39, UNL_STUDYNGAME },
226   { 40, BTL_SMB2A },
227   { 41, CALTRON_6IN1 },
228   { 42, BTL_MARIOBABY },   // ai senshi nicol?
229   { 43, UNL_SMB2J },
230   { 44, BMC_SUPERBIG_7IN1 },
231   { 45, BMC_HIK8IN1 },
232   { 46, RUMBLESTATION_BOARD },
233   { 47, NES_QJ },
234   { 48, TAITO_TC0190FMCP },
235   { 49, BMC_SUPERHIK_4IN1 },
236   { 50, BTL_SMB2B },
237   { 51, BMC_BALLGAMES_11IN1 },
238   { 52, BMC_MARIOPARTY_7IN1 },
239   // 53 Supervision 16-in-1 - Unsupported
240   { 54, BMC_NOVELDIAMOND },
241   // 55 Genius SMB - No info (nor images) available
242   { 56, KAISER_KS202 },
243   { 57, BMC_GKA },
244   { 58, BMC_GKB },
245   // 59 Unused
246   // 60 4-in-1, 35-in-1 Reset based
247   { 61, RCM_TETRISFAMILY },
248   { 62, BMC_SUPER_700IN1 },
249   // 63 CH001 X-in-1 - No info (nor images) available
250   { 64, TENGEN_800032 },
251   { 65, IREM_H3001 },
252   { 66, STD_GXROM },
253   { 67, SUNSOFT_3 },
254   { 68, STD_NXROM },
255   { 69, STD_JXROM },
256   { 70, DIS_74X161X161X32 },
257   { 71, CAMERICA_BF9093 },
258   { 72, JALECO_JF17 },
259   { 73, KONAMI_VRC3 },
260   { 74, WAIXING_TYPE_A },
261   { 75, KONAMI_VRC1 },
262   { 76, NAMCOT_3446 },
263   { 77, IREM_LROG017 },
264   { 78, IREM_HOLYDIV },
265   { 79, AVE_NINA06 },
266   { 80, TAITO_X1_005 },
267   // 81 Unused
268   { 82, TAITO_X1_017 },
269   { 83, CONY_BOARD },
270   // 84 Pasofami hacked images?
271   { 85, KONAMI_VRC7 },
272   { 86, JALECO_JF13 },
273   { 87, DIS_74X139X74 },
274   { 88, NAMCOT_34X3 },
275   { 89, SUNSOFT_2 },
276   // 90 JY Company Type A (Aladdin, Final Fight 3, Super Mario World, Tekken 2) - Unsupported
277   { 91, UNL_MK2 },
278   { 92, JALECO_JF19 },
279   { 93, SUNSOFT_2 },
280   { 94, STD_UN1ROM },
281   { 95, NAMCOT_3425 },
282   { 96, BANDAI_OEKAKIDS },
283   { 97, IREM_TAM_S1 },
284   // 98 Unused
285   // 99 VS. system - Not going to be implemented (use MAME instead)
286   // 100 images hacked to work with nesticle?
287   // 101 Unused (Urusei Yatsura had been assigned to this mapper, but it's Mapper 87)
288   // 102 Unused
289   // 103 Bootleg cart 2708 (Doki Doki Panic - FDS Conversion) - Unsupported
290   { 104, CAMERICA_GOLDENFIVE },
291   // 105 Nintendo World Championship - Unsupported
292   { 106, BTL_SMB3 },
293   { 107, MAGICSERIES_MD },
294   { 108, WHIRLWIND_2706 },
295   // 109 Unused
296   // 110 Unused
297   // 111 Ninja Ryuukenden Chinese? - Unsupported
298   { 112, NTDEC_ASDER },
299   { 113, HES_BOARD },
300   { 114, SUPERGAME_LIONKING },
301   { 115, KASING_BOARD },
302   { 116, SOMERI_SL12 },
303   { 117, FUTUREMEDIA_BOARD },
304   { 118, STD_TXSROM },
305   { 119, STD_TQROM },
306   { 120, BTL_TOBIDASE },
307   { 121, KAY_PANDAPRINCE },
308   // 122 Unused
309   { 123, UNL_H2288 },
310   // 124 Unused
311   // 125 Unused
312   { 126, BMC_PJOY84 },
313   // 127 Unused
314   // 128 Unused
315   // 129 Unused
316   // 130 Unused
317   // 131 Unused
318   { 132, TXC_22211B },
319   { 133, SACHEN_SA72008 },
320   { 134, BMC_FAMILY_4646B },
321   // 135 Unused
322   { 136, SACHEN_TCU02 },
323   { 137, SACHEN_8259D },
324   { 138, SACHEN_8259B },
325   { 139, SACHEN_8259C },
326   { 140, JALECO_JF11 },
327   { 141, SACHEN_8259A },
328   { 142, KAISER_KS7032},
329   { 143, SACHEN_TCA01 },
330   { 144, AGCI_50282 },
331   { 145, SACHEN_SA72007 },
332   { 146, AVE_NINA06 }, // basically same as Mapper 79 (Nina006)
333   { 147, SACHEN_TCU01 },
334   { 148, SACHEN_SA0037 },
335   { 149, SACHEN_SA0036 },
336   { 150, SACHEN_74LS374 },
337   // 151 VS. system by Konami - Not going to be implemented (use MAME instead)
338   { 152, DIS_74X161X161X32 },
339   { 153, BANDAI_LZ93 },
340   { 154, NAMCOT_3453 },
341   { 155, STD_SXROM_A }, // diff compared to MMC1 concern WRAM
342   { 156, OPENCORP_DAOU306 },
343   { 157, BANDAI_DATACH },   // no Datach Reader -> we fall back to mapper 16
344   { 158, TENGEN_800037 },
345   { 159, BANDAI_LZ93EX },   // with 24c01
346   { 160, SACHEN_SA009 },
347   // 161 Unused
348   // 162 Unused
349   { 163, NANJING_BOARD},
350   { 164, WAIXING_FFV },
351   { 165, WAIXING_SH2 },
352   { 166, SUBOR_TYPE1 },
353   { 167, SUBOR_TYPE0 },
354   { 168, UNL_RACERMATE },
355   // 169 Unused
356   // 170 Fujiya
357   { 171, KAISER_KS7058 },
358   { 172, TXC_22211B },
359   { 173, TXC_22211C },
360   // 174 Unused
361   { 175, KAISER_KS7022},
362   { 176, UNL_XZY },
363   { 177, HENGEDIANZI_BOARD },
364   { 178, WAIXING_SGZLZ },
365   { 179, HENGEDIANZI_XJZB },
366   { 180, UXROM_CC },
367   // 181 Unused
368   { 182, HOSENKAN_BOARD },
369   // 183 FDS bootleg (Shui Guan Pipe) - Unsupported
370   { 184, SUNSOFT_1 },
371   { 185, STD_CNROM },
372   { 186, FUKUTAKE_BOARD },
373   { 187, UNL_KOF96 },
374   { 188, BANDAI_KARAOKE },
375   { 189, TXC_TW },
376   // 190 Unused
377   { 191, WAIXING_TYPE_B },
378   { 192, WAIXING_TYPE_C },
379   { 193, NTDEC_FIGHTINGHERO },
380   { 194, WAIXING_TYPE_D },
381   { 195, WAIXING_TYPE_E },
382   { 196, BTL_SUPERBROS11 },
383   { 197, UNL_SUPERFIGHTER3 },
384   { 198, WAIXING_TYPE_F },
385   { 199, WAIXING_TYPE_G },
386   { 200, BMC_36IN1 },
387   { 201, BMC_21IN1 },
388   { 202, BMC_150IN1 },
389   { 203, BMC_35IN1 },
390   { 204, BMC_64IN1 },
391   { 205, BMC_15IN1 },
392   { 206, STD_DXROM },
393   { 207, TAITO_X1_005_A },
394   { 208, GOUDER_37017 },
395   // 209 JY Company Type B (Power Rangers 3 & 4, Shin Samurai Spirits 2) - Unsupported
396   // 210 Some emu uses this as Mapper 19 without some features
397   // 211 JY Company Type C (Tiny Toon Adventures 6, Donkey Kong Country 4) - Unsupported
398   { 212, BMC_SUPERHIK_300IN1 },
399   { 213, BMC_9999999IN1 },
400   { 214, BMC_SUPERGUN_20IN1 },
401   { 215, SUPERGAME_BOOGERMAN },
402   { 216, RCM_GS2015 },
403   { 217, BMC_GOLDENCARD_6IN1 },
404   // 218 Unused
405   // 219 Bootleg A9746 - Unsupported
406   // 220 Unused
407   { 221, UNL_N625092 },
408   { 222, BTL_DRAGONNINJA },
409   { 223, WAIXING_TYPE_I },   // (according to NEStopia source, it's MMC3 with more WRAM)
410   { 224, WAIXING_TYPE_J },   // (according to NEStopia source, it's MMC3 with more WRAM)
411   { 225, BMC_72IN1 },
412   { 226, BMC_76IN1 },
413   { 227, BMC_1200IN1 },
414   { 228, ACTENT_ACT52 },
415   { 229, BMC_31IN1 },
416   { 230, BMC_22GAMES },
417   { 231, BMC_20IN1 },
418   { 232, CAMERICA_BF9096 },
419   // 233 Super 22 Games - Unsupported
420   // 234 AVE Maxi 15 - Unsupported
421   // 235 Golden Game x-in-1 - Unsupported
422   // 236 Game 800-in-1 - Unsupported
423   // 237 Unused
424   { 238, UNL_603_5052 },
425   // 239 Unused
426   { 240, CNE_SHLZ },
427   { 241, TXC_MXMDHTWO },
428   { 242, WAIXING_ZS },
429   { 243, SACHEN_74LS374_A },
430   { 244, CNE_DECATHLON },
431   { 245, WAIXING_TYPE_H },
432   { 246, CNE_FSB },
433   // 247 Unused
434   // 248 Unused
435   { 249, WAIXING_SECURITY },
436   { 250, NITRA_TDA },
437   // 251 Shen Hua Jian Yun III?? - Unsupported
438   { 252, WAIXING_SGZ },
439   // 253 Super 8-in-1 99 King Fighter?? - Unsupported
440   { 254, BTL_PIKACHUY2K },
441   { 255, BMC_110IN1 },
442};
443
444const nes_mmc *nes_mapper_lookup( int mapper )
445{
446   int i;
447
448   for (i = 0; i < ARRAY_LENGTH(mmc_list); i++)
449   {
450      if (mmc_list[i].iNesMapper == mapper)
451         return &mmc_list[i];
452   }
453
454   return NULL;
455}
456
457int nes_get_mmc_id( running_machine &machine, int mapper )
458{
459   const nes_mmc *mmc = nes_mapper_lookup(mapper);
460
461   if (mmc == NULL)
462      fatalerror("Unimplemented Mapper %d", mapper);
463
464   return mmc->pcb_id;
465}
src/mess/machine/6525tpi.c
r11460r11461
1/***************************************************************************
2    mos tri port interface 6525
3    mos triple interface adapter 6523
4
5    peter.trauner@jk.uni-linz.ac.at
6
7    used in commodore b series
8    used in commodore c1551 floppy disk drive
9***************************************************************************/
10
11/*
12 mos tpi 6525
13 40 pin package
14 3 8 bit ports (pa, pb, pc)
15 8 registers to pc
16 0 port a 0 in low
17 1 port a data direction register 1 output
18 2 port b
19 3 port b ddr
20 4 port c
21  handshaking, interrupt mode
22  0 interrupt 0 input, 1 interrupt enabled
23   interrupt set on falling edge
24  1 interrupt 1 input
25  2 interrupt 2 input
26  3 interrupt 3 input
27  4 interrupt 4 input
28  5 irq output
29  6 ca handshake line (read handshake answer on I3 preferred)
30  7 cb handshake line (write handshake clear on I4 preferred)
31 5 port c ddr
32
33 6 cr configuration register
34  0 mc
35    0 port c normal input output mode like port a and b
36    1 port c used for handshaking and interrupt input
37  1 1 interrupt prioritized
38  2 i3 configure edge
39    1 interrupt set on positive edge
40  3 i4 configure edge
41  5,4 ca handshake
42   00 on read
43      rising edge of i3 sets ca high
44      read a data from computers sets ca low
45   01 pulse output
46      1 microsecond low after read a operation
47   10 manual output low
48   11 manual output high
49  7,6 cb handshake
50   00 handshake on write
51      write b data from computer sets cb 0
52      rising edge of i4 sets cb high
53   01 pulse output
54      1 microsecond low after write b operation
55   10 manual output low
56   11 manual output high
57 7 air active interrupt register
58   0 I0 occurred
59   1 I1 occurred
60   2 I2 occurred
61   3 I3 occurred
62   4 I4 occurred
63   read clears interrupt
64
65 non prioritized interrupts
66  interrupt is set when occurred
67  read clears all interrupts
68
69 prioritized interrupts
70  I4>I3>I2>I1>I0
71  highest interrupt can be found in air register
72  read clears highest interrupt
73*/
74
75#include "emu.h"
76#include "6525tpi.h"
77
78
79/***************************************************************************
80    CONSTANTS
81***************************************************************************/
82
83#define VERBOSE_LEVEL 0
84#define DBG_LOG( MACHINE, N, M, A ) \
85   do { \
86      if(VERBOSE_LEVEL >= N) \
87      { \
88         if( M ) \
89            logerror("%11.6f: %-24s", MACHINE.time().as_double(), (char*) M ); \
90         logerror A; \
91      } \
92   } while (0)
93
94
95#define INTERRUPT_MODE (tpi6525->cr & 1)
96#define PRIORIZED_INTERRUPTS (tpi6525->cr & 2)
97#define INTERRUPT3_RISING_EDGE (tpi6525->cr & 4)
98#define INTERRUPT4_RISING_EDGE (tpi6525->cr & 8)
99#define CA_MANUAL_OUT (tpi6525->cr & 0x20)
100#define CA_MANUAL_LEVEL ((tpi6525->cr & 0x10) ? 1 : 0)
101#define CB_MANUAL_OUT (tpi6525->cr & 0x80)
102#define CB_MANUAL_LEVEL ((tpi6525->cr & 0x40) ? 1 : 0)
103
104
105/***************************************************************************
106    TYPE DEFINITIONS
107***************************************************************************/
108
109typedef struct _tpi6525_state tpi6525_state;
110struct _tpi6525_state
111{
112   devcb_resolved_write_line   out_irq_func;
113   devcb_resolved_read8      in_pa_func;
114   devcb_resolved_write8      out_pa_func;
115   devcb_resolved_read8      in_pb_func;
116   devcb_resolved_write8      out_pb_func;
117   devcb_resolved_read8      in_pc_func;
118   devcb_resolved_write8      out_pc_func;
119   devcb_resolved_write_line   out_ca_func;
120   devcb_resolved_write_line   out_cb_func;
121
122   UINT8 port_a, ddr_a, in_a;
123   UINT8 port_b, ddr_b, in_b;
124   UINT8 port_c, ddr_c, in_c;
125
126   UINT8 ca_level, cb_level, interrupt_level;
127
128   UINT8 cr;
129   UINT8 air;
130
131   UINT8 irq_level[5];
132};
133
134
135/*****************************************************************************
136    INLINE FUNCTIONS
137*****************************************************************************/
138
139INLINE tpi6525_state *get_safe_token(device_t *device)
140{
141   assert(device != NULL);
142   assert(device->type() == TPI6525);
143
144   return (tpi6525_state *)downcast<legacy_device_base *>(device)->token();
145}
146
147
148/*****************************************************************************
149    DEVICE INTERFACE
150*****************************************************************************/
151
152static DEVICE_START( tpi6525 )
153{
154   tpi6525_state *tpi6525 = get_safe_token(device);
155   const tpi6525_interface *intf = (const tpi6525_interface*)device->static_config();
156
157   // resolve callbacks
158   tpi6525->out_irq_func.resolve(intf->out_irq_func, *device);
159   tpi6525->in_pa_func.resolve(intf->in_pa_func, *device);
160   tpi6525->out_pa_func.resolve(intf->out_pa_func, *device);
161   tpi6525->in_pb_func.resolve(intf->in_pb_func, *device);
162   tpi6525->out_pb_func.resolve(intf->out_pb_func, *device);
163   tpi6525->in_pc_func.resolve(intf->in_pc_func, *device);
164   tpi6525->out_pc_func.resolve(intf->out_pc_func, *device);
165   tpi6525->out_ca_func.resolve(intf->out_ca_func, *device);
166   tpi6525->out_cb_func.resolve(intf->out_cb_func, *device);
167
168   /* verify that we have an interface assigned */
169   assert(device->static_config() != NULL);
170
171   /* register for state saving */
172   device->save_item(NAME(tpi6525->port_a));
173   device->save_item(NAME(tpi6525->ddr_a));
174   device->save_item(NAME(tpi6525->in_a));
175   device->save_item(NAME(tpi6525->port_b));
176   device->save_item(NAME(tpi6525->ddr_b));
177   device->save_item(NAME(tpi6525->in_b));
178   device->save_item(NAME(tpi6525->port_c));
179   device->save_item(NAME(tpi6525->ddr_c));
180   device->save_item(NAME(tpi6525->in_c));
181   device->save_item(NAME(tpi6525->ca_level));
182   device->save_item(NAME(tpi6525->cb_level));
183   device->save_item(NAME(tpi6525->interrupt_level));
184   device->save_item(NAME(tpi6525->cr));
185   device->save_item(NAME(tpi6525->air));
186   device->save_item(NAME(tpi6525->irq_level));
187}
188
189
190static DEVICE_RESET( tpi6525 )
191{
192   tpi6525_state *tpi6525 = get_safe_token(device);
193
194   /* setup some initial values */
195   tpi6525->in_a = 0xff;
196   tpi6525->in_b = 0xff;
197   tpi6525->in_c = 0xff;
198}
199
200
201DEVICE_GET_INFO( tpi6525 )
202{
203   switch (state)
204   {
205      /* --- the following bits of info are returned as 64-bit signed integers --- */
206      case DEVINFO_INT_TOKEN_BYTES:         info->i = sizeof(tpi6525_state);      break;
207
208      /* --- the following bits of info are returned as pointers to data or functions --- */
209      case DEVINFO_FCT_START:               info->start = DEVICE_START_NAME( tpi6525 );         break;
210      case DEVINFO_FCT_STOP:               /* Nothing */                              break;
211      case DEVINFO_FCT_RESET:               info->reset = DEVICE_RESET_NAME( tpi6525 );         break;
212
213      /* --- the following bits of info are returned as NULL-terminated strings --- */
214      case DEVINFO_STR_NAME:               strcpy(info->s, "6525 TPI");         break;
215      case DEVINFO_STR_FAMILY:            strcpy(info->s, "6525 TPI");         break;
216      case DEVINFO_STR_VERSION:            strcpy(info->s, "1.0");               break;
217      case DEVINFO_STR_SOURCE_FILE:         strcpy(info->s, __FILE__);            break;
218      case DEVINFO_STR_CREDITS:            strcpy(info->s, "Copyright MESS Team");   break;
219   }
220}
221
222
223/***************************************************************************
224    IMPLEMENTATION
225***************************************************************************/
226
227static void tpi6525_set_interrupt(device_t *device)
228{
229   tpi6525_state *tpi6525 = get_safe_token(device);
230
231   if (!tpi6525->interrupt_level && (tpi6525->air != 0))
232   {
233      tpi6525->interrupt_level = 1;
234
235      DBG_LOG(device->machine(), 3, "tpi6525", ("%s set interrupt\n", device->tag()));
236
237      tpi6525->out_irq_func(tpi6525->interrupt_level);
238   }
239}
240
241
242static void tpi6525_clear_interrupt(device_t *device)
243{
244   tpi6525_state *tpi6525 = get_safe_token(device);
245
246   if (tpi6525->interrupt_level && (tpi6525->air == 0))
247   {
248      tpi6525->interrupt_level = 0;
249
250      DBG_LOG(device->machine(), 3, "tpi6525", ("%s clear interrupt\n", device->tag()));
251
252      tpi6525->out_irq_func(tpi6525->interrupt_level);
253   }
254}
255
256
257WRITE_LINE_DEVICE_HANDLER( tpi6525_i0_w )
258{
259   tpi6525_state *tpi6525 = get_safe_token(device);
260
261   if (INTERRUPT_MODE && (state != tpi6525->irq_level[0]))
262   {
263      tpi6525->irq_level[0] = state;
264
265      if ((state == 0) && !(tpi6525->air & 1) && (tpi6525->ddr_c & 1))
266      {
267         tpi6525->air |= 1;
268         tpi6525_set_interrupt(device);
269      }
270   }
271}
272
273
274WRITE_LINE_DEVICE_HANDLER( tpi6525_i1_w )
275{
276   tpi6525_state *tpi6525 = get_safe_token(device);
277
278   if (INTERRUPT_MODE && (state != tpi6525->irq_level[1]))
279   {
280      tpi6525->irq_level[1] = state;
281
282      if ((state == 0) && !(tpi6525->air & 2) && (tpi6525->ddr_c & 2))
283      {
284         tpi6525->air |= 2;
285         tpi6525_set_interrupt(device);
286      }
287   }
288}
289
290
291WRITE_LINE_DEVICE_HANDLER( tpi6525_i2_w )
292{
293   tpi6525_state *tpi6525 = get_safe_token(device);
294
295   if (INTERRUPT_MODE && (state != tpi6525->irq_level[2]))
296   {
297      tpi6525->irq_level[2] = state;
298
299      if ((state == 0) && !(tpi6525->air & 4) && (tpi6525->ddr_c & 4))
300      {
301         tpi6525->air |= 4;
302         tpi6525_set_interrupt(device);
303      }
304   }
305}
306
307
308WRITE_LINE_DEVICE_HANDLER( tpi6525_i3_w )
309{
310   tpi6525_state *tpi6525 = get_safe_token(device);
311
312   if (INTERRUPT_MODE && (state != tpi6525->irq_level[3]))
313   {
314      tpi6525->irq_level[3] = state;
315
316      if (((INTERRUPT3_RISING_EDGE && (state == 1))
317         || (!INTERRUPT3_RISING_EDGE && (state == 0)))
318         && !(tpi6525->air & 8) && (tpi6525->ddr_c & 8))
319      {
320         tpi6525->air |= 8;
321         tpi6525_set_interrupt(device);
322      }
323   }
324}
325
326
327WRITE_LINE_DEVICE_HANDLER( tpi6525_i4_w )
328{
329   tpi6525_state *tpi6525 = get_safe_token(device);
330
331   if (INTERRUPT_MODE && (state != tpi6525->irq_level[4]) )
332   {
333      tpi6525->irq_level[4] = state;
334
335      if (((INTERRUPT4_RISING_EDGE && (state == 1))
336         ||(!INTERRUPT4_RISING_EDGE&&(state == 0)))
337         && !(tpi6525->air & 0x10) && (tpi6525->ddr_c & 0x10))
338      {
339         tpi6525->air |= 0x10;
340         tpi6525_set_interrupt(device);
341      }
342   }
343}
344
345
346READ8_DEVICE_HANDLER( tpi6525_porta_r )
347{
348   tpi6525_state *tpi6525 = get_safe_token(device);
349   UINT8 data = tpi6525->in_a;
350
351   if (!tpi6525->in_pa_func.isnull())
352      data = tpi6525->in_pa_func(offset);
353
354   data = (data & ~tpi6525->ddr_a) | (tpi6525->ddr_a & tpi6525->port_a);
355
356   return data;
357}
358
359
360WRITE8_DEVICE_HANDLER( tpi6525_porta_w )
361{
362   tpi6525_state *tpi6525 = get_safe_token(device);
363
364   tpi6525->in_a = data;
365}
366
367
368READ8_DEVICE_HANDLER( tpi6525_portb_r )
369{
370   tpi6525_state *tpi6525 = get_safe_token(device);
371   UINT8 data = tpi6525->in_b;
372
373   if (!tpi6525->in_pb_func.isnull())
374      data = tpi6525->in_pb_func(offset);
375
376   data = (data & ~tpi6525->ddr_b) | (tpi6525->ddr_b & tpi6525->port_b);
377
378   return data;
379}
380
381
382WRITE8_DEVICE_HANDLER( tpi6525_portb_w )
383{
384   tpi6525_state *tpi6525 = get_safe_token(device);
385
386   tpi6525->in_b = data;
387}
388
389
390READ8_DEVICE_HANDLER( tpi6525_portc_r )
391{
392   tpi6525_state *tpi6525 = get_safe_token(device);
393   UINT8 data = tpi6525->in_c;
394
395   if (!tpi6525->in_pc_func.isnull())
396      data &= tpi6525->in_pc_func(offset);
397
398   data = (data & ~tpi6525->ddr_c) | (tpi6525->ddr_c & tpi6525->port_c);
399
400   return data;
401}
402
403
404WRITE8_DEVICE_HANDLER( tpi6525_portc_w )
405{
406   tpi6525_state *tpi6525 = get_safe_token(device);
407
408   tpi6525->in_c = data;
409}
410
411
412READ8_DEVICE_HANDLER( tpi6525_r )
413{
414   tpi6525_state *tpi6525 = get_safe_token(device);
415   UINT8 data = 0xff;
416
417   switch (offset & 7)
418   {
419   case 0:
420      data = tpi6525->in_a;
421
422      if (!tpi6525->in_pa_func.isnull())
423         data &= tpi6525->in_pa_func(0);
424
425      data = (data & ~tpi6525->ddr_a) | (tpi6525->ddr_a & tpi6525->port_a);
426
427      break;
428
429   case 1:
430      data = tpi6525->in_b;
431
432      if (!tpi6525->in_pb_func.isnull())
433         data &= tpi6525->in_pb_func(0);
434
435      data = (data & ~tpi6525->ddr_b) | (tpi6525->ddr_b & tpi6525->port_b);
436
437      break;
438
439   case 2:
440      if (INTERRUPT_MODE)
441      {
442         data = 0;
443
444         if (tpi6525->irq_level[0]) data |= 0x01;
445         if (tpi6525->irq_level[1]) data |= 0x02;
446         if (tpi6525->irq_level[2]) data |= 0x04;
447         if (tpi6525->irq_level[3]) data |= 0x08;
448         if (tpi6525->irq_level[4]) data |= 0x10;
449         if (!tpi6525->interrupt_level) data |= 0x20;
450         if (tpi6525->ca_level) data |= 0x40;
451         if (tpi6525->cb_level) data |= 0x80;
452      }
453      else
454      {
455         data = tpi6525->in_c;
456
457         if (!tpi6525->in_pc_func.isnull())
458            data &= tpi6525->in_pc_func(0);
459
460         data = (data & ~tpi6525->ddr_c) | (tpi6525->ddr_c & tpi6525->port_c);
461      }
462
463      DBG_LOG(device->machine(), 2, "tpi6525", ("%s read %.2x %.2x\n", device->tag(), offset, data));
464      break;
465
466   case 3:
467      data = tpi6525->ddr_a;
468      break;
469
470   case 4:
471      data = tpi6525->ddr_b;
472      break;
473
474   case 5:
475      data = tpi6525->ddr_c;
476      break;
477
478   case 6:
479      data = tpi6525->cr;
480      break;
481
482   case 7: /* air */
483      if (PRIORIZED_INTERRUPTS)
484      {
485         if (tpi6525->air & 0x10)
486         {
487            data = 0x10;
488            tpi6525->air &= ~0x10;
489         }
490         else if (tpi6525->air & 8)
491         {
492            data = 8;
493            tpi6525->air &= ~8;
494         }
495         else if (tpi6525->air & 4)
496         {
497            data = 4;
498            tpi6525->air &= ~4;
499         }
500         else if (tpi6525->air & 2)
501         {
502            data = 2;
503            tpi6525->air &= ~2;
504         }
505         else if (tpi6525->air & 1)
506         {
507            data = 1;
508            tpi6525->air &= ~1;
509         }
510      }
511      else
512      {
513         data = tpi6525->air;
514         tpi6525->air = 0;
515      }
516
517      tpi6525_clear_interrupt(device);
518      break;
519
520   }
521
522   DBG_LOG(device->machine(), 3, "tpi6525", ("%s read %.2x %.2x\n", device->tag(), offset, data));
523
524   return data;
525}
526
527
528WRITE8_DEVICE_HANDLER( tpi6525_w )
529{
530   tpi6525_state *tpi6525 = get_safe_token(device);
531
532   DBG_LOG(device->machine(), 2, "tpi6525", ("%s write %.2x %.2x\n", device->tag(), offset, data));
533
534   switch (offset & 7)
535   {
536   case 0:
537      tpi6525->port_a = data;
538      tpi6525->out_pa_func(0, tpi6525->port_a & tpi6525->ddr_a);
539      break;
540
541   case 1:
542      tpi6525->port_b = data;
543      tpi6525->out_pb_func(0, tpi6525->port_b & tpi6525->ddr_b);
544      break;
545
546   case 2:
547      tpi6525->port_c = data;
548
549      if (!INTERRUPT_MODE)
550         tpi6525->out_pc_func(0, tpi6525->port_c & tpi6525->ddr_c);
551      break;
552
553   case 3:
554      tpi6525->ddr_a = data;
555      tpi6525->out_pa_func(0, tpi6525->port_a & tpi6525->ddr_a);
556
557      break;
558
559   case 4:
560      tpi6525->ddr_b = data;
561      tpi6525->out_pb_func(0, tpi6525->port_b & tpi6525->ddr_b);
562      break;
563
564   case 5:
565      tpi6525->ddr_c = data;
566
567      if (!INTERRUPT_MODE)
568         tpi6525->out_pc_func(0, tpi6525->port_c & tpi6525->ddr_c);
569      break;
570
571   case 6:
572      tpi6525->cr = data;
573
574      if (INTERRUPT_MODE)
575      {
576         if (CA_MANUAL_OUT)
577         {
578            if (tpi6525->ca_level != CA_MANUAL_LEVEL)
579            {
580               tpi6525->ca_level = CA_MANUAL_LEVEL;
581               tpi6525->out_ca_func(tpi6525->ca_level);
582            }
583         }
584         if (CB_MANUAL_OUT)
585         {
586            if (tpi6525->cb_level != CB_MANUAL_LEVEL)
587            {
588               tpi6525->cb_level = CB_MANUAL_LEVEL;
589               tpi6525->out_cb_func(tpi6525->cb_level);
590            }
591         }
592      }
593
594      break;
595
596   case 7:
597      /* tpi6525->air = data; */
598      break;
599   }
600}
601
602
603/* this should probably be done better, needed for amigacd.c */
604
605UINT8 tpi6525_get_ddr_a(device_t *device)
606{
607   tpi6525_state *tpi6525 = get_safe_token(device);
608   return tpi6525->ddr_a;
609}
610
611UINT8 tpi6525_get_ddr_b(device_t *device)
612{
613   tpi6525_state *tpi6525 = get_safe_token(device);
614   return tpi6525->ddr_b;
615}
616
617UINT8 tpi6525_get_ddr_c(device_t *device)
618{
619   tpi6525_state *tpi6525 = get_safe_token(device);
620   return tpi6525->ddr_c;
621}
622
623DEFINE_LEGACY_DEVICE(TPI6525, tpi6525);
src/mess/machine/6525tpi.h
r11460r11461
1/*****************************************************************************
2 *
3 * machine/tpi6525.h
4 *
5 * mos tri port interface 6525
6 * mos triple interface adapter 6523
7 *
8 * peter.trauner@jk.uni-linz.ac.at
9 *
10 * used in commodore b series
11 * used in commodore c1551 floppy disk drive
12 *
13 * tia6523 is a tpi6525 without control register!?
14 *
15 * tia6523
16 *   only some lines of port b and c are in the pinout!
17 *
18 * connector to floppy c1551 (delivered with c1551 as c16 expansion)
19 *   port a for data read/write
20 *   port b
21 *   0 status 0
22 *   1 status 1
23 *   port c
24 *   6 dav output edge data on port a available
25 *   7 ack input edge ready for next datum
26 *
27 ****************************************************************************/
28
29#ifndef __TPI6525_H__
30#define __TPI6525_H__
31
32
33/***************************************************************************
34    TYPE DEFINITIONS
35***************************************************************************/
36
37typedef struct _tpi6525_interface tpi6525_interface;
38struct _tpi6525_interface
39{
40   devcb_write_line   out_irq_func;
41
42   devcb_read8         in_pa_func;
43   devcb_write8      out_pa_func;
44
45   devcb_read8         in_pb_func;
46   devcb_write8      out_pb_func;
47
48   devcb_read8         in_pc_func;
49   devcb_write8      out_pc_func;
50
51   devcb_write_line   out_ca_func;
52   devcb_write_line   out_cb_func;
53};
54
55
56/***************************************************************************
57    DEVICE CONFIGURATION MACROS
58***************************************************************************/
59
60DECLARE_LEGACY_DEVICE(TPI6525, tpi6525);
61
62#define MCFG_TPI6525_ADD(_tag, _intrf) \
63   MCFG_DEVICE_ADD(_tag, TPI6525, 0) \
64   MCFG_DEVICE_CONFIG(_intrf)
65
66
67/***************************************************************************
68    FUNCTION PROTOTYPES
69***************************************************************************/
70
71READ8_DEVICE_HANDLER( tpi6525_r );
72WRITE8_DEVICE_HANDLER( tpi6525_w );
73
74READ8_DEVICE_HANDLER( tpi6525_porta_r );
75WRITE8_DEVICE_HANDLER( tpi6525_porta_w );
76
77READ8_DEVICE_HANDLER( tpi6525_portb_r );
78WRITE8_DEVICE_HANDLER( tpi6525_portb_w );
79
80READ8_DEVICE_HANDLER( tpi6525_portc_r );
81WRITE8_DEVICE_HANDLER( tpi6525_portc_w );
82
83WRITE_LINE_DEVICE_HANDLER( tpi6525_i0_w );
84WRITE_LINE_DEVICE_HANDLER( tpi6525_i1_w );
85WRITE_LINE_DEVICE_HANDLER( tpi6525_i2_w );
86WRITE_LINE_DEVICE_HANDLER( tpi6525_i3_w );
87WRITE_LINE_DEVICE_HANDLER( tpi6525_i4_w );
88
89UINT8 tpi6525_get_ddr_a(device_t *device);
90UINT8 tpi6525_get_ddr_b(device_t *device);
91UINT8 tpi6525_get_ddr_c(device_t *device);
92
93
94#endif /* __TPI6525_H__ */
src/mess/machine/snescart.c
r11460r11461
1/***************************************************************************
2
3  snescart.c
4
5  Machine file to handle cart loading in the Nintendo Super NES emulation.
6
7***************************************************************************/
8
9#include "emu.h"
10#include "includes/snes.h"
11#include "imagedev/cartslot.h"
12#include "snescart.h"
13
14#define SNES_CART_DEBUG 0
15
16/****** Strings for Cart Header Logging ******/
17
18#define UNK "Unknown"
19
20/* Some known type of cart */
21static const char *const types[] =
22{
23   "ROM",
24   "ROM, DSP-1",
25   "ROM, DSP-2",
26   "ROM, DSP-3",
27   "ROM, DSP-4",
28   "ROM, Super FX / FX2",
29   "ROM, SA-1",
30   "ROM, S-DD1",
31   "ROM, OBC-1",
32   "ROM, S-RTC",
33   "ROM, Z80GB (Super Game Boy)",
34   "ROM, C4",
35   "ROM, Seta ST-010",
36   "ROM, Seta ST-011",
37   "ROM, Seta ST-018",
38   "ROM, SPC7110",
39   "ROM, SPC7110, RTC",
40   UNK,                     // to add: Satellaview BS-X detection
41};
42
43/* Some known countries */
44static const char *const countries[] =
45{
46/* 0*/   "Japan (NTSC)", "USA & Canada (NTSC)", "Europe, Oceania & Asia (PAL)", "Sweden (PAL)",
47/* 4*/   "Finland (PAL)", "Denmark (PAL)", "France (PAL)", "Holland (PAL)",
48/* 8*/   "Spain (PAL)", "Germany, Austria & Switzerland (PAL)", "Italy (PAL)", "Hong Kong & China (PAL)",
49/* c*/   "Indonesia (PAL)", "South Korea (NTSC)", UNK, UNK,
50};
51
52/* Some known companies (integrations to the list from Snes9x) */
53static const char *const companies[] =
54{
55/* 0*/   "Invalid", "Nintendo", "Ajinomoto", "Imagineer-Zoom", "Chris Gray Enterprises Inc.", "Zamuse", "Falcom", UNK,
56/* 8*/   "Capcom", "HOT-B", "Jaleco", "Coconuts", "Rage Software", "Micronet", "Technos", "Mebio Software",
57/*10*/   "SHOUEi System", "Starfish", "Gremlin Graphics", "Electronic Arts", "NCS / Masaya", "COBRA Team", "Human/Field", "KOEI",
58/*18*/   "Hudson Soft", "Game Village", "Yanoman", UNK, "Tecmo", UNK, "Open System", "Virgin Games",
59/*20*/   "KSS", "Sunsoft", "POW", "Micro World", UNK, UNK, "Enix", "Loriciel/Electro Brain",
60/*28*/   "Kemco", "Seta Co.,Ltd.", "Culture Brain", "Irem Japan", "Pal Soft", "Visit Co.,Ltd.", "INTEC Inc.", "System Sacom Corp.",
61/*30*/   "Viacom New Media", "Carrozzeria", "Dynamic", "Nintendo", "Magifact", "Hect", UNK, UNK,
62/*38*/   "Capcom Europe", "Accolade Europe", UNK, "Arcade Zone", "Empire Software", "Loriciel", "Gremlin Graphics", UNK,
63/*40*/   "Seika Corp.", "UBI Soft", UNK, UNK, "LifeFitness Exertainment", UNK, "System 3", "Spectrum Holobyte",
64/*48*/   UNK, "Irem", UNK, "Raya Systems/Sculptured Software", "Renovation Products", "Malibu Games/Black Pearl", UNK, "U.S. Gold",
65/*50*/   "Absolute Entertainment", "Acclaim", "Activision", "American Sammy", "GameTek", "Hi Tech Expressions", "LJN Toys", UNK,
66/*58*/   UNK, UNK, "Mindscape", "Romstar, Inc.", UNK, "Tradewest", UNK, "American Softworks Corp.",
67/*60*/   "Titus", "Virgin Interactive Entertainment", "Maxis", "Origin/FCI/Pony Canyon", UNK, UNK, UNK, "Ocean",
68/*68*/   UNK, "Electronic Arts", UNK, "Laser Beam", UNK, UNK, "Elite", "Electro Brain",
69/*70*/   "Infogrames", "Interplay", "LucasArts", "Parker Brothers", "Konami", "STORM", UNK, UNK,
70/*78*/   "THQ Software", "Accolade Inc.", "Triffix Entertainment", UNK, "Microprose", UNK, UNK, "Kemco",
71/*80*/   "Misawa", "Teichio", "Namco Ltd.", "Lozc", "Koei", UNK, "Tokuma Shoten Intermedia", "Tsukuda Original",
72/*88*/   "DATAM-Polystar", UNK, UNK, "Bullet-Proof Software", "Vic Tokai", UNK, "Character Soft", "I\'\'Max",
73/*90*/   "Takara", "CHUN Soft", "Video System Co., Ltd.", "BEC", UNK, "Varie", "Yonezawa / S'Pal Corp.", "Kaneco",
74/*98*/   UNK, "Pack in Video", "Nichibutsu", "TECMO", "Imagineer Co.", UNK, UNK, UNK,
75/*a0*/   "Telenet", "Hori", UNK, UNK, "Konami", "K.Amusement Leasing Co.", UNK, "Takara",
76/*a8*/   UNK, "Technos Jap.", "JVC", UNK, "Toei Animation", "Toho", UNK, "Namco Ltd.",
77/*b0*/   "Media Rings Corp.", "ASCII Co. Activison", "Bandai", UNK, "Enix America", UNK, "Halken", UNK,
78/*b8*/   UNK, UNK, "Culture Brain", "Sunsoft", "Toshiba EMI", "Sony Imagesoft", UNK, "Sammy",
79/*c0*/   "Taito", UNK, "Kemco", "Square", "Tokuma Soft", "Data East", "Tonkin House", UNK,
80/*c8*/   "KOEI", UNK, "Konami USA", "NTVIC", UNK, "Meldac", "Pony Canyon", "Sotsu Agency/Sunrise",
81/*d0*/   "Disco/Taito", "Sofel", "Quest Corp.", "Sigma", "Ask Kodansha Co., Ltd.", UNK, "Naxat", UNK,
82/*d8*/   "Capcom Co., Ltd.", "Banpresto", "Tomy", "Acclaim", UNK, "NCS", "Human Entertainment", "Altron",
83/*e0*/   "Jaleco", UNK, "Yutaka", UNK, "T&ESoft", "EPOCH Co.,Ltd.", UNK, "Athena",
84/*e8*/   "Asmik", "Natsume", "King Records", "Atlus", "Sony Music Entertainment", UNK, "IGS", UNK,
85/*f0*/   UNK, "Motown Software", "Left Field Entertainment", "Beam Software", "Tec Magik", UNK, UNK, UNK,
86/*f8*/   UNK, "Cybersoft", UNK, "Psygnosis", UNK, UNK, "Davidson", UNK,
87};
88
89
90/* We use this to convert the company_id in the header to int value to be passed in companies[] */
91static int char_to_int_conv( char id )
92{
93   int value;
94
95   if (id == '1') value = 0x01;
96   else if (id == '2') value = 0x02;
97   else if (id == '3') value = 0x03;
98   else if (id == '4') value = 0x04;
99   else if (id == '5') value = 0x05;
100   else if (id == '6') value = 0x06;
101   else if (id == '7') value = 0x07;
102   else if (id == '8') value = 0x08;
103   else if (id == '9') value = 0x09;
104   else if (id == 'A') value = 0x0a;
105   else if (id == 'B') value = 0x0b;
106   else if (id == 'C') value = 0x0c;
107   else if (id == 'D') value = 0x0d;
108   else if (id == 'E') value = 0x0e;
109   else if (id == 'F') value = 0x0f;
110   else value = 0x00;
111
112   return value;
113}
114
115
116/***************************************************************************
117
118  SRAM handling
119
120***************************************************************************/
121
122/* Loads the battery backed RAM into the appropriate memory area */
123static void snes_load_sram(running_machine &machine)
124{
125   snes_state *state = machine.driver_data<snes_state>();
126   UINT8 ii;
127   UINT8 *battery_ram, *ptr;
128
129   battery_ram = (UINT8*)malloc(state->m_cart[0].sram_max);
130   ptr = battery_ram;
131   device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("cart"));
132   image->battery_load(battery_ram, state->m_cart[0].sram_max, 0xff);
133
134   if (state->m_cart[0].mode == SNES_MODE_20)
135   {
136      UINT32 size = state->m_cart[0].small_sram ? 0x8000 : 0x10000;
137
138      /* There could be some larger image needing banks 0x70 to 0x7f at address 0x8000 for ROM
139         * mirroring. These should be treated separately or data would be overwritten by SRAM */
140      for (ii = 0; ii < 16; ii++)
141      {
142         /* loading */
143         memmove(&snes_ram[0x700000 + (ii * 0x010000)], ptr, size);
144         /* mirroring */
145         memcpy(&snes_ram[0xf00000 + (ii * 0x010000)], &snes_ram[0x700000 + (ii * 0x010000)], size);
146         ptr += size;
147      }
148   }
149   else if (state->m_cart[0].mode == SNES_MODE_21)
150   {
151      for (ii = 0; ii < 16; ii++)
152      {
153         /* loading */
154         memmove(&snes_ram[0x306000 + (ii * 0x010000)], ptr, 0x2000);
155         /* mirroring */
156         memcpy(&snes_ram[0xb06000 + (ii * 0x010000)], &snes_ram[0x306000 + (ii * 0x010000)], 0x2000);
157         ptr += 0x2000;
158      }
159   }
160   else if (state->m_cart[0].mode == SNES_MODE_25)
161   {
162      for (ii = 0; ii < 16; ii++)
163      {
164         memmove(&snes_ram[0xb06000 + (ii * 0x010000)], ptr, 0x2000);
165         ptr += 0x2000;
166      }
167   }
168
169   free(battery_ram);
170}
171
172/* Saves the battery backed RAM from the appropriate memory area */
173static void snes_save_sram(running_machine &machine)
174{
175   snes_state *state = machine.driver_data<snes_state>();
176   UINT8 ii;
177   UINT8 *battery_ram, *ptr;
178
179   battery_ram = (UINT8*)malloc(state->m_cart[0].sram_max);
180   ptr = battery_ram;
181
182   if (state->m_cart[0].mode == SNES_MODE_20)
183   {
184      UINT32 size = state->m_cart[0].small_sram ? 0x8000 : 0x10000;
185
186      for (ii = 0; ii < 16; ii++)
187      {
188         memmove(ptr, &snes_ram[0x700000 + (ii * 0x010000)], size);
189         ptr += size;
190      }
191   }
192   else if (state->m_cart[0].mode == SNES_MODE_21)
193   {
194      for (ii = 0; ii < 16; ii++)
195      {
196         memmove(ptr, &snes_ram[0x306000 + (ii * 0x010000)], 0x2000);
197         ptr += 0x2000;
198      }
199   }
200   else if (state->m_cart[0].mode == SNES_MODE_25)
201   {
202      for (ii = 0; ii < 16; ii++)
203      {
204         memmove(ptr, &snes_ram[0xb06000 + (ii * 0x010000)], 0x2000);
205         ptr += 0x2000;
206      }
207   }
208   device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("cart"));
209   image->battery_save(battery_ram, state->m_cart[0].sram_max);
210
211   free(battery_ram);
212}
213
214static void snes_machine_stop(running_machine &machine)
215{
216   snes_state *state = machine.driver_data<snes_state>();
217
218   /* Save SRAM */
219   if (state->m_cart[0].sram > 0)
220      snes_save_sram(machine);
221}
222
223MACHINE_START( snes_mess )
224{
225   machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(snes_machine_stop),&machine));
226   MACHINE_START_CALL(snes);
227}
228
229
230static void sufami_load_sram(running_machine &machine, const char *cart_tag)
231{
232   UINT8 ii;
233   UINT8 *battery_ram, *ptr;
234   int st_sram_offset = 0;
235
236   battery_ram = (UINT8*)malloc(0x20000);
237   ptr = battery_ram;
238   device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device(cart_tag));
239   image->battery_load(battery_ram, 0x20000, 0);
240
241   if (strcmp(cart_tag, "slot_a") == 0)
242      st_sram_offset = 0x608000;
243
244   if (strcmp(cart_tag, "slot_b") == 0)
245      st_sram_offset = 0x708000;
246
247   /* Cart RAM is at 0x60-0x63:0x8000-0xffff (+0x10 for slot2) */
248   for (ii = 0; ii < 4; ii++)
249   {
250      /* loading */
251      memcpy(&snes_ram[st_sram_offset + (ii * 0x010000)], ptr + (ii * 0x8000), 0x8000);
252      /* mirroring */
253      memcpy(&snes_ram[0x800000 + st_sram_offset + (ii * 0x010000)], &snes_ram[st_sram_offset + (ii * 0x010000)], 0x8000);
254   }
255
256   free(battery_ram);
257}
258
259static void sufami_machine_stop(running_machine &machine)
260{
261   snes_state *state = machine.driver_data<snes_state>();
262   UINT8 ii;
263   UINT8 *battery_ram, *ptr;
264
265   battery_ram = (UINT8*)malloc(0x20000);
266   ptr = battery_ram;
267
268   if (state->m_cart[0].slot_in_use)
269   {
270      for (ii = 0; ii < 4; ii++)
271      {
272         memmove(ptr + ii * 0x8000, &snes_ram[0x608000 + (ii * 0x010000)], 0x8000);
273      }
274      device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("slot_a"));
275      image->battery_save(battery_ram, 0x20000);
276   }
277
278   if (state->m_cart[1].slot_in_use)
279   {
280      for (ii = 0; ii < 4; ii++)
281      {
282         memmove(ptr + ii * 0x8000, &snes_ram[0x708000 + (ii * 0x010000)], 0x8000);
283      }
284      device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("slot_b"));
285      image->battery_save(battery_ram, 0x20000);
286   }
287
288   free(battery_ram);
289}
290
291MACHINE_START( snesst )
292{
293   machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(sufami_machine_stop),&machine));
294   MACHINE_START_CALL(snes);
295}
296
297
298/***************************************************************************
299
300  Cart handling
301
302***************************************************************************/
303
304/* This function assign a 'score' to data immediately after 'offset' to measure how valid they are
305as information block (to decide if the image is HiRom, LoRom, ExLoRom or ExHiRom) */
306/* Code from bsnes, courtesy of byuu - http://byuu.cinnamonpirate.com/ */
307static int snes_validate_infoblock( UINT8 *infoblock, UINT32 offset )
308{
309   int score = 0;
310   UINT16 reset_vector = infoblock[offset + 0x3c] | (infoblock[offset + 0x3d] << 8);
311   UINT16 checksum     = infoblock[offset + 0x1e] | (infoblock[offset + 0x1f] << 8);
312   UINT16 ichecksum    = infoblock[offset + 0x1c] | (infoblock[offset + 0x1d] << 8);
313   UINT8 reset_opcode  = infoblock[(offset & ~0x7fff) | (reset_vector & 0x7fff)];   //first opcode executed upon reset
314   UINT8 mapper        = infoblock[offset + 0x15] & ~0x10;                     //mask off irrelevent FastROM-capable bit
315
316   /* $00:[000-7fff] contains uninitialized RAM and MMIO.
317    reset vector must point to ROM at $00:[8000-ffff] to be considered valid. */
318   if (reset_vector < 0x8000)
319      return 0;
320
321   /* some images duplicate the header in multiple locations, and others have completely
322    invalid header information that cannot be relied upon. The code below will analyze
323    the first opcode executed at the specified reset vector to determine the probability
324    that this is the correct header. Score is assigned accordingly. */
325
326   /* most likely opcodes */
327   if (reset_opcode == 0x78      //sei
328      || reset_opcode == 0x18      //clc (clc; xce)
329      || reset_opcode == 0x38      //sec (sec; xce)
330      || reset_opcode == 0x9c      //stz $nnnn (stz $4200)
331      || reset_opcode == 0x4c      //jmp $nnnn
332      || reset_opcode == 0x5c      //jml $nnnnnn
333   )
334      score += 8;
335
336   /* plausible opcodes */
337   if (reset_opcode == 0xc2      //rep #$nn
338      || reset_opcode == 0xe2      //sep #$nn
339      || reset_opcode == 0xad      //lda $nnnn
340      || reset_opcode == 0xae      //ldx $nnnn
341      || reset_opcode == 0xac      //ldy $nnnn
342      || reset_opcode == 0xaf      //lda $nnnnnn
343      || reset_opcode == 0xa9      //lda #$nn
344      || reset_opcode == 0xa2      //ldx #$nn
345      || reset_opcode == 0xa0      //ldy #$nn
346      || reset_opcode == 0x20      //jsr $nnnn
347      || reset_opcode == 0x22      //jsl $nnnnnn
348   )
349      score += 4;
350
351   /* implausible opcodes */
352   if (reset_opcode == 0x40      //rti
353      || reset_opcode == 0x60      //rts
354      || reset_opcode == 0x6b      //rtl
355      || reset_opcode == 0xcd      //cmp $nnnn
356      || reset_opcode == 0xec      //cpx $nnnn
357      || reset_opcode == 0xcc      //cpy $nnnn
358   )
359      score -= 4;
360
361   /* least likely opcodes */
362   if (reset_opcode == 0x00      //brk #$nn
363      || reset_opcode == 0x02      //cop #$nn
364      || reset_opcode == 0xdb      //stp
365      || reset_opcode == 0x42      //wdm
366      || reset_opcode == 0xff      //sbc $nnnnnn,x
367   )
368      score -= 8;
369
370   /* Sometimes, both the header and reset vector's first opcode will match ...
371    fallback and rely on info validity in these cases to determine more likely header. */
372
373   /* a valid checksum is the biggest indicator of a valid header. */
374   if ((checksum + ichecksum) == 0xffff && (checksum != 0) && (ichecksum != 0))
375      score += 4;
376
377   /* then there are the expected mapper values */
378   if (offset == 0x007fc0 && mapper == 0x20)   // 0x20 is usually LoROM
379      score += 2;
380
381   if (offset == 0x00ffc0 && mapper == 0x21)   // 0x21 is usually HiROM
382      score += 2;
383
384   if (offset == 0x007fc0 && mapper == 0x22)   // 0x22 is usually ExLoROM
385      score += 2;
386
387   if (offset == 0x40ffc0 && mapper == 0x25)   // 0x25 is usually ExHiROM
388      score += 2;
389
390   /* finally, there are valid values in the Company, Region etc. fields */
391   if (infoblock[offset + 0x1a] == 0x33)         // Company field: 0x33 indicates extended header
392      score += 2;
393
394   if (infoblock[offset + 0x16] < 0x08)         // ROM Type field
395      score++;
396
397   if (infoblock[offset + 0x17] < 0x10)         // ROM Size field
398      score++;
399
400   if (infoblock[offset + 0x18] < 0x08)         // SRAM Size field
401      score++;
402
403   if (infoblock[offset + 0x19] < 14)            // Region field
404      score++;
405
406   /* do we still have a positive score? */
407   if (score < 0)
408      score = 0;
409
410   return score;
411}
412
413/* Here we add a couple of cart utilities, to avoid duplicating the code in each DEVICE_IMAGE_LOAD */
414static UINT32 snes_skip_header( device_image_interface &image, UINT32 snes_rom_size )
415{
416   UINT8 header[512];
417   UINT32 offset = 512;
418
419   /* Check for a header (512 bytes) */
420   if (image.software_entry() == NULL)
421      image.fread( header, 512);
422   else
423      memcpy(header, image.get_software_region("rom"), 512);
424
425   if ((header[8] == 0xaa) && (header[9] == 0xbb) && (header[10] == 0x04))
426   {
427      /* Found an SWC identifier */
428      logerror("Found header (SWC) - Skipped\n");
429   }
430   else if ((header[0] | (header[1] << 8)) == (((snes_rom_size - 512) / 1024) / 8))
431   {
432      /* Some headers have the rom size at the start, if this matches with the actual rom size, we probably have a header */
433      logerror("Found header (size) - Skipped\n");
434   }
435   else if ((snes_rom_size % 0x8000) == 512)
436   {
437      /* As a last check we'll see if there's exactly 512 bytes extra to this image. */
438      logerror("Found header (extra) - Skipped\n");
439   }
440   else
441   {
442      /* No header found so go back to the start of the file */
443      logerror("No header found.\n");
444      offset = 0;
445   }
446
447   return offset;
448}
449
450
451/* This determines if a cart is in Mode 20, 21, 22 or 25; sets state->m_cart[0].mode and
452 state->m_cart[0].sram accordingly; and returns the offset of the internal header (needed to
453 detect BSX and ST carts) */
454static UINT32 snes_find_hilo_mode( device_image_interface &image, UINT8 *buffer, UINT32 offset, int cartid )
455{
456   snes_state *state = image.device().machine().driver_data<snes_state>();
457   UINT8 valid_mode20, valid_mode21, valid_mode25;
458   UINT32 retvalue;
459
460   /* Now to determine if this is a lo-ROM, a hi-ROM or an extended lo/hi-ROM */
461   valid_mode20 = snes_validate_infoblock(buffer, 0x007fc0);
462   valid_mode21 = snes_validate_infoblock(buffer, 0x00ffc0);
463   valid_mode25 = snes_validate_infoblock(buffer, 0x40ffc0);
464
465   /* Images larger than 32mbits are likely ExHiRom */
466   if (valid_mode25)
467      valid_mode25 += 4;
468
469   if ((valid_mode20 >= valid_mode21) && (valid_mode20 >= valid_mode25))
470   {
471      if ((buffer[0x007fd5] == 0x32) || ((state->m_cart_size - offset) > 0x401000))
472         state->m_cart[cartid].mode = SNES_MODE_22;   // ExLoRom
473      else
474         state->m_cart[cartid].mode = SNES_MODE_20;   // LoRom
475
476      retvalue = 0x007fc0;
477
478      /* a few games require 512k, however we store twice as much to be sure to cover the various mirrors */
479      state->m_cart[cartid].sram_max = 0x100000;
480   }
481   else if (valid_mode21 >= valid_mode25)
482   {
483      state->m_cart[cartid].mode = SNES_MODE_21;   // HiRom
484      retvalue = 0x00ffc0;
485      state->m_cart[cartid].sram_max = 0x20000;
486   }
487   else
488   {
489      state->m_cart[cartid].mode = SNES_MODE_25;   // ExHiRom
490      retvalue = 0x40ffc0;
491      state->m_cart[cartid].sram_max = 0x20000;
492   }
493
494   logerror( "\t HiROM/LoROM id: %s (LoROM: %d , HiROM: %d, ExHiROM: %d)\n",
495          (state->m_cart[cartid].mode == SNES_MODE_20) ? "LoROM" :
496          (state->m_cart[cartid].mode == SNES_MODE_21) ? "HiROM" :
497          (state->m_cart[cartid].mode == SNES_MODE_22) ? "ExLoROM" :
498          (state->m_cart[cartid].mode == SNES_MODE_25) ? "ExHiROM" : "Other (BSX or ST)",
499          valid_mode20, valid_mode21, valid_mode25);
500
501   return retvalue;
502}
503
504static int snes_find_addon_chip( running_machine &machine )
505{
506   snes_state *state = machine.driver_data<snes_state>();
507   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
508   int supported_type = 1;
509   int dsp_prg_offset = 0;
510
511   /* Info mostly taken from http://snesemu.black-ship.net/misc/-from%20nsrt.edgeemu.com-chipinfo.htm */
512   switch (snes_r_bank1(space, 0x00ffd6))
513   {
514      case 0x00:
515      case 0x01:
516      case 0x02:
517         state->m_has_addon_chip = HAS_NONE;
518         break;
519
520      case 0x03:
521         if (snes_r_bank1(space, 0x00ffd5) == 0x30)
522         {
523            state->m_has_addon_chip = HAS_DSP4;
524            dsp_prg_offset = SNES_DSP4_OFFSET;
525         }
526         else
527         {
528            state->m_has_addon_chip = HAS_DSP1;
529            dsp_prg_offset = SNES_DSP1B_OFFSET;
530         }
531         break;
532
533      case 0x04:
534         state->m_has_addon_chip = HAS_DSP1;
535         dsp_prg_offset = SNES_DSP1B_OFFSET;
536         break;
537
538      case 0x05:
539         if (snes_r_bank1(space, 0x00ffd5) == 0x20)
540         {
541            state->m_has_addon_chip = HAS_DSP2;
542            dsp_prg_offset = SNES_DSP2_OFFSET;
543         }
544         /* DSP-3 is hard to detect. We exploit the fact that the only game has been manufactured by Bandai */
545         else if ((snes_r_bank1(space, 0x00ffd5) == 0x30) && (snes_r_bank1(space, 0x00ffda) == 0xb2))
546         {
547            state->m_has_addon_chip = HAS_DSP3;
548            dsp_prg_offset = SNES_DSP3_OFFSET;
549         }
550         else
551         {
552            state->m_has_addon_chip = HAS_DSP1;
553            dsp_prg_offset = SNES_DSP1B_OFFSET;
554         }
555         break;
556
557      case 0x13:   // Mario Chip 1
558      case 0x14:   // GSU-x
559      case 0x15:   // GSU-x
560      case 0x1a:   // GSU-1 (21 MHz at start)
561         if (snes_r_bank1(space, 0x00ffd5) == 0x20)
562            state->m_has_addon_chip = HAS_SUPERFX;
563         break;
564
565      case 0x25:
566         state->m_has_addon_chip = HAS_OBC1;
567         break;
568
569      case 0x32:   // needed by a Sample game (according to ZSNES)
570      case 0x34:
571      case 0x35:
572         if (snes_r_bank1(space, 0x00ffd5) == 0x23)
573         {
574            state->m_has_addon_chip = HAS_SA1;
575            supported_type = 0;
576            mame_printf_error("This is a SA-1 type game, currently unsupported by the driver\n");
577         }
578         break;
579
580      case 0x43:
581      case 0x45:
582         if (snes_r_bank1(space, 0x00ffd5) == 0x32)
583         {
584            state->m_has_addon_chip = HAS_SDD1;
585         }
586         break;
587
588      case 0x55:
589         if (snes_r_bank1(space, 0x00ffd5) == 0x35)
590         {
591            state->m_has_addon_chip = HAS_RTC;
592         }
593         break;
594
595      case 0xe3:
596         state->m_has_addon_chip = HAS_Z80GB;
597         supported_type = 0;
598         break;
599
600      case 0xf3:
601         state->m_has_addon_chip = HAS_CX4;
602         break;
603
604      case 0xf5:
605         if (snes_r_bank1(space, 0x00ffd5) == 0x30)
606         {
607            state->m_has_addon_chip = HAS_ST018;
608            supported_type = 0;
609         }
610         else if (snes_r_bank1(space, 0x00ffd5) == 0x3a)
611         {
612            state->m_has_addon_chip = HAS_SPC7110;
613         }
614         break;
615
616      case 0xf6:
617         /* These Seta ST-01X chips have both 0x30 at 0x00ffd5,
618             they only differ for the 'size' at 0x00ffd7 */
619         if (snes_r_bank1(space, 0x00ffd7) < 0x0a)
620            state->m_has_addon_chip = HAS_ST011;
621         else
622            state->m_has_addon_chip = HAS_ST010;
623
624         // if we are loading the game in a driver without the ST01X DSP, revert to HAS_NONE to avoid crash
625         if (!state->m_upd96050)
626            state->m_has_addon_chip = HAS_NONE;
627         break;
628
629      case 0xf9:
630         if (snes_r_bank1(space, 0x00ffd5) == 0x3a)
631         {
632            state->m_has_addon_chip = HAS_SPC7110_RTC;
633            supported_type = 0;
634         }
635         break;
636
637      default:
638         state->m_has_addon_chip = HAS_UNK;
639         supported_type = 0;
640         break;
641   }
642
643   if ((state->m_has_addon_chip >= HAS_DSP1) && (state->m_has_addon_chip <= HAS_DSP4))
644   {
645      UINT8 *dspsrc = (UINT8 *)machine.region("addons")->base();
646      UINT32 *dspprg = (UINT32 *)machine.region("dspprg")->base();
647      UINT16 *dspdata = (UINT16 *)machine.region("dspdata")->base();
648
649      // copy DSP program
650      for (int i = 0; i < 0x2000; i+= 4)
651      {
652         *dspprg = dspsrc[dsp_prg_offset+0+i]<<24 | dspsrc[dsp_prg_offset+1+i]<<16 | dspsrc[dsp_prg_offset+2+i]<<8;
653         dspprg++;
654      }
655
656      // copy DSP data
657      for (int i = 0; i < 0x800; i+= 2)
658      {
659         *dspdata++ = dspsrc[dsp_prg_offset+0x2000+i]<<8 | dspsrc[dsp_prg_offset+0x2001+i];
660      }
661   }
662
663   if ((state->m_has_addon_chip == HAS_ST010) || (state->m_has_addon_chip == HAS_ST011))
664   {
665      UINT8 *dspsrc = (UINT8 *)machine.region("addons")->base();
666      UINT32 *dspprg = (UINT32 *)machine.region("dspprg")->base();
667      UINT16 *dspdata = (UINT16 *)machine.region("dspdata")->base();
668
669      // copy DSP program
670      for (int i = 0; i < 0x10000; i+= 4)
671      {
672         *dspprg = dspsrc[0+i]<<24 | dspsrc[1+i]<<16 | dspsrc[2+i]<<8;
673         dspprg++;
674      }
675
676      // copy DSP data
677      for (int i = 0; i < 0x1000; i+= 2)
678      {
679         *dspdata++ = dspsrc[0x10000+i]<<8 | dspsrc[0x10001+i];
680      }
681   }
682
683   return supported_type;
684}
685
686static void snes_cart_log_info( running_machine &machine, int total_blocks, int supported )
687{
688   snes_state *state = machine.driver_data<snes_state>();
689   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
690   char title[21], rom_id[4], company_id[2];
691   int i, company, has_ram = 0, has_sram = 0;
692
693   /* Company */
694   for (i = 0; i < 2; i++)
695      company_id[i] = snes_r_bank1(space, 0x00ffb0 + i);
696   company = (char_to_int_conv(company_id[0]) << 4) + char_to_int_conv(company_id[1]);
697   if (company == 0)
698      company = snes_r_bank1(space, 0x00ffda);
699
700   /* ROM ID */
701   for( i = 0; i < 4; i++ )
702      rom_id[i] = snes_r_bank1(space, 0x00ffb2 + i);
703
704   /* Title */
705   for( i = 0; i < 21; i++ )
706      title[i] = snes_r_bank1(space, 0x00ffc0 + i);
707
708   /* RAM */
709   if (((snes_r_bank1(space, 0x00ffd6) & 0xf) == 1) ||
710      ((snes_r_bank1(space, 0x00ffd6) & 0xf) == 2) ||
711      ((snes_r_bank1(space, 0x00ffd6) & 0xf) == 4) ||
712      ((snes_r_bank1(space, 0x00ffd6) & 0xf) == 5))
713      has_ram = 1;
714
715   /* SRAM */
716   if (((snes_r_bank1(space, 0x00ffd6) & 0xf) == 2) ||
717      ((snes_r_bank1(space, 0x00ffd6) & 0xf) == 5) ||
718      ((snes_r_bank1(space, 0x00ffd6) & 0xf) == 6))
719      has_sram = 1;
720
721   logerror( "ROM DETAILS\n" );
722   logerror( "===========\n\n" );
723   logerror( "\tTotal blocks:  %d (%dmb)\n", total_blocks, total_blocks / (state->m_cart[0].mode & 5 ? 32 : 16) );
724   logerror( "\tROM bank size: %s \n",
725          (state->m_cart[0].mode == SNES_MODE_20) ? "LoROM" :
726          (state->m_cart[0].mode == SNES_MODE_21) ? "HiROM" :
727          (state->m_cart[0].mode == SNES_MODE_22) ? "ExLoROM" :
728          (state->m_cart[0].mode == SNES_MODE_25) ? "ExHiROM" : "Other (BSX or ST)" );
729   logerror( "\tCompany:       %s [%.2s]\n", companies[company], company_id );
730   logerror( "\tROM ID:        %.4s\n\n", rom_id );
731
732   logerror( "HEADER DETAILS\n" );
733   logerror( "==============\n\n" );
734   logerror( "\tName:          %.21s\n", title );
735   logerror( "\tSpeed:         %s [%d]\n", ((snes_r_bank1(space, 0x00ffd5) & 0xf0)) ? "FastROM" : "SlowROM", (snes_r_bank1(space, 0x00ffd5) & 0xf0) >> 4 );
736   logerror( "\tBank size:     %s [%d]\n", (snes_r_bank1(space, 0x00ffd5) & 0xf) ? "HiROM" : "LoROM", snes_r_bank1(space, 0x00ffd5) & 0xf );
737
738   logerror( "\tType:          %s", types[state->m_has_addon_chip]);
739   if (has_ram)
740      logerror( ", RAM");
741   if (has_sram)
742      logerror( ", SRAM");
743   logerror( " [%d]\n", snes_r_bank1(space, 0x00ffd6) );
744
745   logerror( "\tSize:          %d megabits [%d]\n", 1 << (snes_r_bank1(space, 0x00ffd7) - 7), snes_r_bank1(space, 0x00ffd7) );
746   logerror( "\tSRAM:          %d kilobits [%d]\n", state->m_cart[0].sram * 8, snes_ram[0xffd8] );
747   logerror( "\tCountry:       %s [%d]\n", countries[snes_r_bank1(space, 0x00ffd9)], snes_r_bank1(space, 0x00ffd9) );
748   logerror( "\tLicense:       %s [%X]\n", companies[snes_r_bank1(space, 0x00ffda)], snes_r_bank1(space, 0x00ffda) );
749   logerror( "\tVersion:       1.%d\n", snes_r_bank1(space, 0x00ffdb) );
750   logerror( "\tInv Checksum:  %X %X\n", snes_r_bank1(space, 0x00ffdd), snes_r_bank1(space, 0x00ffdc) );
751   logerror( "\tChecksum:      %X %X\n", snes_r_bank1(space, 0x00ffdf), snes_r_bank1(space, 0x00ffde) );
752   logerror( "\tNMI Address:   %2X%2Xh\n", snes_r_bank1(space, 0x00fffb), snes_r_bank1(space, 0x00fffa) );
753   logerror( "\tStart Address: %2X%2Xh\n\n", snes_r_bank1(space, 0x00fffd), snes_r_bank1(space, 0x00fffc) );
754
755   logerror( "\tMode: %d\n", state->m_cart[0].mode);
756
757   if (!supported)
758      logerror("WARNING: This cart type \"%s\" is not supported yet!\n", types[state->m_has_addon_chip]);
759}
760
761static DEVICE_IMAGE_LOAD( snes_cart )
762{
763   int supported_type = 1, i, j;
764   running_machine &machine = image.device().machine();
765   snes_state *state = machine.driver_data<snes_state>();
766   address_space *space = machine.device( "maincpu")->memory().space( AS_PROGRAM );
767   int total_blocks, read_blocks, has_bsx_slot = 0, st_bios = 0;
768   UINT32 offset, int_header_offs;
769   UINT8 *ROM = image.device().machine().region("cart")->base();
770
771   if (image.software_entry() == NULL)
772      state->m_cart_size = image.length();
773   else
774      state->m_cart_size = image.get_software_region_length("rom");
775
776   /* Check for a header (512 bytes), and skip it if found */
777   offset = snes_skip_header(image, state->m_cart_size);
778
779   if (image.software_entry() == NULL)
780   {
781      image.fseek(offset, SEEK_SET);
782      image.fread( ROM, state->m_cart_size - offset);
783   }
784   else
785      memcpy(ROM, image.get_software_region("rom") + offset, state->m_cart_size - offset);
786
787   if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", state->m_cart_size - offset);
788
789   /* First, look if the cart is HiROM or LoROM (and set snes_cart accordingly) */
790   int_header_offs = snes_find_hilo_mode(image, ROM, offset, 0);
791
792   /* Then, detect BS-X carts */
793   // Detect presence of BS-X Flash Cart
794   if ((ROM[int_header_offs + 0x13] == 0x00 || ROM[int_header_offs + 0x13] == 0xff) &&
795         ROM[int_header_offs + 0x14] == 0x00)
796   {
797      UINT8 n15 = ROM[int_header_offs + 0x15];
798      if (n15 == 0x00 || n15 == 0x80 || n15 == 0x84 || n15 == 0x9c || n15 == 0xbc || n15 == 0xfc)
799      {
800         if (ROM[int_header_offs + 0x1a] == 0x33 || ROM[int_header_offs + 0x1a] == 0xff)
801         {
802            // BS-X Flash Cart
803            state->m_cart[0].mode = SNES_MODE_BSX;
804         }
805      }
806   }
807
808   // Detect presence of BS-X flash cartridge connector
809   if ((ROM[int_header_offs - 14] == 'Z') && (ROM[int_header_offs - 11] == 'J'))
810   {
811      UINT8 n13 = ROM[int_header_offs - 13];
812      if ((n13 >= 'A' && n13 <= 'Z') || (n13 >= '0' && n13 <= '9'))
813      {
814         if (ROM[int_header_offs + 0x1a] == 0x33 ||
815            (ROM[int_header_offs - 10] == 0x00 && ROM[int_header_offs - 4] == 0x00))
816         {
817            has_bsx_slot = 1;
818         }
819      }
820   }
821
822   // If there is a BS-X connector, detect if it is the Base Cart or a compatible slotted cart
823   if (has_bsx_slot)
824   {
825      if (!memcmp(ROM + int_header_offs, "Satellaview BS-X     ", 21))
826      {
827         //BS-X Base Cart
828         state->m_cart[0].mode = SNES_MODE_BSX;
829         // handle RAM
830      }
831      else
832      {
833         state->m_cart[0].mode = (int_header_offs ==0x007fc0) ? SNES_MODE_BSLO : SNES_MODE_BSHI;
834         // handle RAM?
835      }
836   }
837
838   /* Then, detect Sufami Turbo carts */
839   if (!memcmp(ROM, "BANDAI SFC-ADX", 14))
840   {
841      state->m_cart[0].mode = SNES_MODE_ST;
842      if (!memcmp(ROM + 16, "SFC-ADX BACKUP", 14))
843         st_bios = 1;
844   }
845
846   if (SNES_CART_DEBUG) mame_printf_error("mode %d\n", state->m_cart[0].mode);
847
848   /* FIXME: Insert crc check here? */
849
850   /* How many blocks of data are available to be loaded? */
851   total_blocks = ((state->m_cart_size - offset) / (state->m_cart[0].mode & 0xa5 ? 0x8000 : 0x10000));
852   read_blocks = 0;
853
854   if (SNES_CART_DEBUG) mame_printf_error("blocks %d\n", total_blocks);
855
856   /* Loading all the data blocks from cart, we only partially cover banks 0x00 to 0x7f. Therefore, we
857     * have to mirror the blocks until we reach the end. E.g. for a 11Mbits image (44 blocks), we proceed
858     * as follows:
859     * 11 Mbits = 8 Mbits (blocks 1->32) + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44).
860     * Hence, we fill memory up to 16 Mbits (banks 0x00 to 0x3f) mirroring as follows
861     * 8 Mbits (blocks 1->32) + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44) + 1 Mbit (blocks 41->44)
862     *   + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44) + 1 Mbit (blocks 41->44)
863     * and we repeat the same blocks in the second half of the banks (banks 0x40 to 0x7f).
864     * This is likely what happens in the real SNES as well, because the unit cannot be aware of the exact
865     * size of data in the cart (procedure confirmed by byuu)
866     */
867   switch (state->m_cart[0].mode)
868   {
869      case SNES_MODE_21:
870      /* HiROM carts load data in banks 0xc0 to 0xff. Each bank is fully mirrored in banks 0x40 to 0x7f
871         * (actually up to 0x7d, because 0x7e and 0x7f are overwritten by WRAM). The top half (address
872         * range 0x8000 - 0xffff) of each bank is also mirrored in banks 0x00 to 0x3f and 0x80 to 0xbf.
873         */
874         /* SPC7110 games needs this different loading routine */
875         if ((ROM[0x00ffd6] == 0xf9 || ROM[0x00ffd6] == 0xf5) && (ROM[0x00ffd5] == 0x3a))
876         {
877            while (read_blocks < 16 && read_blocks < total_blocks)
878            {
879               /* Loading data */
880               memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x10000], 0x10000);
881               /* Mirroring */
882               memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
883               memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
884               read_blocks++;
885            }
886         }
887         else
888         {
889            while (read_blocks < 64 && read_blocks < total_blocks)
890            {
891               /* Loading data */
892               memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x10000], 0x10000);
893               /* Mirroring */
894               memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
895               memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0xc00000 + read_blocks * 0x10000], 0x10000);
896               memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
897               read_blocks++;
898            }
899            /* Filling banks up to 0xff and their mirrors */
900            while (read_blocks % 64)
901            {
902               int j = 0, repeat_blocks;
903               while ((read_blocks % (64 >> j)) && j < 6)
904                  j++;
905               repeat_blocks = read_blocks % (64 >> (j - 1));
906
907               memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &snes_ram[0xc00000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
908               memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
909               memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0x400000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
910               memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[0x800000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
911               read_blocks += repeat_blocks;
912            }
913         }
914         break;
915
916      case SNES_MODE_25:
917      /* Extendend HiROM carts start to load data in banks 0xc0 to 0xff. However, they exceed the
918         * available space in these banks, and continue loading at banks 0x40 to 0x7f. The top half
919         * (address range 0x8000 - 0xffff) of each bank is also mirrored either to banks 0x00 to 0x3f
920         * (for data in banks 0x40 to 0x7f) or to banks 0x80 to 0xbf (for data in banks 0xc0 to 0xff).
921         * Notice that banks 0x7e and 0x7f are overwritten by WRAM, but they could contain data at
922         * address > 0x8000 because the mirrors at 0x3e and 0x3f are not overwritten.
923         */
924         /* Reading the first 64 blocks */
925         while (read_blocks < 64 && read_blocks < total_blocks)
926         {
927            /* Loading data */
928            memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x10000], 0x10000);
929            /* Mirroring */
930            memcpy( &snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
931            read_blocks++;
932         }
933         /* ExHiROMs are supposed to be larger than 32Mbits! */
934         if (read_blocks < 64)
935         {
936            logerror("This image has been identified as ExHiROM, but it's too small!\n");
937            logerror("Please verify if it's corrupted. If it's not please report this as a bug.\n");
938            return IMAGE_INIT_FAIL;
939         }
940         /* Scaling down the counter */
941         read_blocks -= 64;
942         /* Reading the next blocks */
943         while (read_blocks < 64  && read_blocks < (total_blocks - 64))
944         {
945            /* Loading data */
946            memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &ROM[0x400000 + read_blocks * 0x10000], 0x10000);
947            /* Mirroring */
948            memcpy(&snes_ram[0x8000 + read_blocks * 0x10000], &snes_ram[0x408000 + read_blocks * 0x10000], 0x8000);
949            read_blocks++;
950         }
951         /* Filling banks up to 0x7f and their mirrors */
952         while (read_blocks % 64)
953         {
954            int j = 0, repeat_blocks;
955            while ((read_blocks % (64 >> j)) && j < 6)
956               j++;
957            repeat_blocks = read_blocks % (64 >> (j - 1));
958
959            memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0x400000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
960            memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
961            read_blocks += repeat_blocks;
962         }
963         break;
964
965      case SNES_MODE_22:
966      /* "Extendend LoROM" carts have their data loaded in banks 0x00 to 0x3f at address 0x8000.
967         * These are then mirrored in banks 0x40 to 0x7f, both at address 0x0000 and at address
968         * 0x8000, in banks 0x80 to 0xbf at address 0x8000 and in banks 0xc0 to 0xff, both at address
969         * 0x0000 and at address 0x8000. Notice that SDD-1 games (Star Ocean and Street Fighter Zero 2)
970         * use SNES_MODE_22
971         */
972         while (read_blocks < 64 && read_blocks < total_blocks)
973         {
974            /* Loading and mirroring data */
975            memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000);
976            memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000);
977            memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x10000], 0x10000);
978            memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x10000], 0x10000);
979            read_blocks++;
980         }
981         /* Filling banks up to 0x3f and their mirrors */
982         while (read_blocks % 64)
983         {
984            int j = 0, repeat_blocks;
985            while ((read_blocks % (64 >> j)) && j < 6)
986               j++;
987            repeat_blocks = read_blocks % (64 >> (j - 1));
988
989            memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
990            memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[0x800000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
991            memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0x400000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
992            memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &snes_ram[0xc00000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
993            read_blocks += repeat_blocks;
994         }
995         break;
996
997      case SNES_MODE_ST:
998         if (!st_bios)
999         {
1000            mame_printf_error("This is a Sufami Turbo data cart and cannot be loaded for snes/snespal in MESS.\n");
1001            mame_printf_error("Please use snesst driver to load it, instead.\n");
1002            return IMAGE_INIT_FAIL;
1003         }
1004         else
1005         {
1006            // The Base ST cart consists of 8 * 0x8000 block which have to be loaded (and mirrored)
1007            // at 0x00-0x1f:0x8000-0xffff and 0x80-0x9f:0x8000-0xffff
1008            for (i = 0; i < 8; i++)
1009            {
1010               /* Loading data */
1011               memcpy(&snes_ram[0x008000 + i * 0x10000], &ROM[0x000000 + i * 0x8000], 0x8000);
1012               /* Mirroring */
1013               memcpy(&snes_ram[0x808000 + i * 0x10000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000);
1014
1015               /* Additional mirrors (to fill snes_ram up to 0x1fffff) */
1016               for (j = 1; j < 4; j++)
1017               {
1018                  memcpy(&snes_ram[0x008000 + i * 0x10000 + j * 0x80000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000);
1019                  memcpy(&snes_ram[0x808000 + i * 0x10000 + j * 0x80000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000);
1020               }
1021            }
1022         }
1023         break;
1024
1025      case SNES_MODE_BSX:
1026      case SNES_MODE_BSLO:
1027      case SNES_MODE_BSHI:
1028         /* not handled yet */
1029         mame_printf_error("This is a BS-X Satellaview image: MESS does not support these yet, sorry.\n");
1030#if 0
1031         // shall we force incompatibility of flash carts without a base unit?
1032         if (!has_bsx_slot)
1033         {
1034            mame_printf_error("This is a BS-X flash cart and cannot be loaded in snes/snespal.\n");
1035//              mame_printf_error("Please use snesbsx driver to load it, instead.\n");
1036            return IMAGE_INIT_FAIL;
1037         }
1038#endif
1039         break;
1040
1041      default:
1042      case SNES_MODE_20:
1043      /* LoROM carts load data in banks 0x00 to 0x7f at address 0x8000 (actually up to 0x7d, because 0x7e and
1044         * 0x7f are overwritten by WRAM). Each block is also mirrored in banks 0x80 to 0xff (up to 0xff for real)
1045         */
1046         /* SuperFX games needs this different loading routine */
1047         if (((ROM[0x007fd6] >= 0x13 && ROM[0x007fd6] <= 0x15) || ROM[0x007fd6] == 0x1a) && (ROM[0x007fd5] == 0x20))
1048         {
1049            while (read_blocks < 64 && read_blocks < total_blocks)
1050            {
1051               /* Loading data primary: banks 0-3f from 8000-ffff*/
1052               memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000);
1053               /* Mirroring at banks 80-bf from 8000-ffff */
1054               memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0x8000 + (read_blocks * 0x10000)], 0x8000);
1055               /* Mirroring at banks 40-5f and c0-df */
1056               memcpy(&snes_ram[0x400000 + read_blocks * 0x8000], &snes_ram[0x8000 + (read_blocks * 0x10000)], total_blocks * 0x8000);
1057               memcpy(&snes_ram[0xc00000 + read_blocks * 0x8000], &snes_ram[0x8000 + (read_blocks * 0x10000)], total_blocks * 0x8000);
1058
1059               read_blocks++;
1060            }
1061            /* SuperFX games are supposed to contain 64 blocks! */
1062            if (read_blocks < total_blocks)
1063            {
1064               logerror("This image has been identified as a SuperFX game, but it's too large!\n");
1065               logerror("Please verify if it's corrupted. If it's not please report this as a bug.\n");
1066               return IMAGE_INIT_FAIL;
1067            }
1068         }
1069         else
1070         {
1071            while (read_blocks < 128 && read_blocks < total_blocks)
1072            {
1073               /* Loading data */
1074               memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000);
1075               /* Mirroring */
1076               memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0x8000 + (read_blocks * 0x10000)], 0x8000);
1077               read_blocks++;
1078            }
1079            /* Filling banks up to 0x7f and their mirrors */
1080            while (read_blocks % 128)
1081            {
1082               int j = 0, repeat_blocks;
1083               while ((read_blocks % (128 >> j)) && j < 7)
1084                  j++;
1085               repeat_blocks = read_blocks % (128 >> (j - 1));
1086
1087               memcpy( &snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1088               memcpy( &snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1089               read_blocks += repeat_blocks;
1090            }
1091         }
1092         break;
1093   }
1094
1095   /* Detect special chips */
1096   supported_type = snes_find_addon_chip(machine);
1097
1098   /* Find the amount of cart ram (even if we call it sram...) */
1099   if (image.software_entry() == NULL)
1100   {
1101      if ((state->m_has_addon_chip != HAS_SUPERFX))
1102         state->m_cart[0].sram = snes_r_bank1(space, 0x00ffd8);
1103      else
1104         state->m_cart[0].sram = (snes_r_bank1(space, 0x00ffbd) & 0x07);
1105
1106      if (state->m_cart[0].sram > 0)
1107      {
1108         state->m_cart[0].sram = (1024 << state->m_cart[0].sram);
1109         if (state->m_cart[0].sram > state->m_cart[0].sram_max)
1110            state->m_cart[0].sram = state->m_cart[0].sram_max;
1111      }
1112//      printf("size %x\n", state->m_cart[0].sram);
1113   }
1114   else
1115   {
1116      // if we are loading from softlist, take sram from the xml
1117      state->m_cart[0].sram = image.get_software_region("sram") ? image.get_software_region_length("sram") : 0;
1118
1119      if (state->m_cart[0].sram > 0)
1120      {
1121         if (state->m_cart[0].sram > state->m_cart[0].sram_max)
1122            fatalerror("Found more SRAM than max allowed (found: %x, max: %x), check xml file!\n", state->m_cart[0].sram, state->m_cart[0].sram_max);
1123      }
1124      // TODO: Eventually sram handlers should point to the allocated cart:sram region!
1125      // For now, we only use the region as a placeholder to carry size info...
1126//      printf("size %x\n", state->m_cart[0].sram);
1127   }
1128
1129   /* adjust size for very large carts */
1130   if (state->m_cart[0].mode == SNES_MODE_20 && ((state->m_cart_size - offset) > 0x200000 || state->m_cart[0].sram > (32 * 1024)))
1131      state->m_cart[0].small_sram = 1;
1132   else
1133      state->m_cart[0].small_sram = 0;
1134
1135   /* Log snes_cart information */
1136   snes_cart_log_info(machine, total_blocks, supported_type);
1137
1138   /* Load SRAM */
1139   snes_load_sram(machine);
1140
1141   /* All done */
1142   return IMAGE_INIT_PASS;
1143}
1144
1145static DEVICE_IMAGE_LOAD( sufami_cart )
1146{
1147   running_machine &machine = image.device().machine();
1148   snes_state *state = machine.driver_data<snes_state>();
1149   int total_blocks, read_blocks;
1150   int st_bios = 0, slot_id = 0;
1151   UINT32 offset, st_data_offset = 0;
1152   UINT8 *ROM = image.device().machine().region(image.device().tag())->base();
1153
1154   snes_ram = machine.region("maincpu")->base();
1155
1156   if (strcmp(image.device().tag(), "slot_a") == 0)
1157   {
1158      st_data_offset = 0x200000;
1159      slot_id = 0;
1160   }
1161
1162   if (strcmp(image.device().tag(), "slot_b") == 0)
1163   {
1164      st_data_offset = 0x400000;
1165      slot_id = 1;
1166   }
1167
1168   if (image.software_entry() == NULL)
1169      state->m_cart_size = image.length();
1170   else
1171      state->m_cart_size = image.get_software_region_length("rom");
1172
1173   /* Check for a header (512 bytes), and skip it if found */
1174   offset = snes_skip_header(image, state->m_cart_size);
1175
1176   if (image.software_entry() == NULL)
1177   {
1178      image.fseek(offset, SEEK_SET);
1179      image.fread( ROM, state->m_cart_size - offset);
1180   }
1181   else
1182      memcpy(ROM, image.get_software_region("rom") + offset, state->m_cart_size - offset);
1183
1184   if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", state->m_cart_size - offset);
1185
1186   /* Detect Sufami Turbo carts */
1187   if (!memcmp(ROM, "BANDAI SFC-ADX", 14))
1188   {
1189      state->m_cart[slot_id].mode = SNES_MODE_ST;
1190      if (!memcmp(ROM + 16, "SFC-ADX BACKUP", 14))
1191         st_bios = 1;
1192   }
1193   else
1194   {
1195      mame_printf_error("This is not a Sufami Turbo data pack.\n");
1196      mame_printf_error("This image cannot be loaded in snesst (Use snes or snespal drivers, instead).\n");
1197      return IMAGE_INIT_FAIL;
1198   }
1199
1200   if (st_bios == 1)
1201   {
1202      mame_printf_error("This is the Sufami Turbo BIOS and not a Sufami Turbo data pack.\n");
1203      mame_printf_error("This image cannot be loaded in snesst.\n");
1204      return IMAGE_INIT_FAIL;
1205   }
1206
1207   /* FIXME: Insert crc check here? */
1208
1209   /* How many blocks of data are available to be loaded? */
1210   total_blocks = (state->m_cart_size - offset) / 0x8000;
1211   read_blocks = 0;
1212
1213   if (SNES_CART_DEBUG)
1214      mame_printf_error("blocks %d\n", total_blocks);
1215
1216   // actually load the cart
1217   while (read_blocks < 32 && read_blocks < total_blocks)
1218   {
1219      /* Loading data */
1220      // CART (either A or B)
1221      memcpy(&snes_ram[0x008000 + st_data_offset + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000);
1222      /* Mirroring */
1223      memcpy(&snes_ram[0x808000 + st_data_offset + read_blocks * 0x10000], &snes_ram[0x8000 + st_data_offset + (read_blocks * 0x10000)], 0x8000);
1224
1225      read_blocks++;
1226   }
1227
1228   /* Filling banks up to 0x1f and their mirrors */
1229   while (read_blocks % 32)
1230   {
1231      int j = 0, repeat_blocks;
1232      while ((read_blocks % (32 >> j)) && j < 5)
1233         j++;
1234      repeat_blocks = read_blocks % (32 >> (j - 1));
1235
1236      memcpy(&snes_ram[st_data_offset + read_blocks * 0x10000], &snes_ram[st_data_offset + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1237      memcpy(&snes_ram[0x800000 + st_data_offset + read_blocks * 0x10000], &snes_ram[st_data_offset + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1238      read_blocks += repeat_blocks;
1239   }
1240
1241   sufami_load_sram(machine, image.device().tag());
1242
1243   state->m_cart[slot_id].slot_in_use = 1;   // aknowledge the cart in this slot, for saving sram at exit
1244
1245   auto_free(image.device().machine(), ROM);
1246
1247   return IMAGE_INIT_PASS;
1248}
1249
1250static DEVICE_IMAGE_LOAD( bsx_cart )
1251{
1252   running_machine &machine = image.device().machine();
1253   snes_state *state = machine.driver_data<snes_state>();
1254   int total_blocks, read_blocks;
1255   int has_bsx_slot = 0;
1256   UINT32 offset, int_header_offs;
1257   UINT8 *ROM = image.device().machine().region("cart")->base();
1258
1259   if (image.software_entry() == NULL)
1260      state->m_cart_size = image.length();
1261   else
1262      state->m_cart_size = image.get_software_region_length("rom");
1263
1264   /* Check for a header (512 bytes), and skip it if found */
1265   offset = snes_skip_header(image, state->m_cart_size);
1266
1267   if (image.software_entry() == NULL)
1268   {
1269      image.fseek(offset, SEEK_SET);
1270      image.fread( ROM, state->m_cart_size - offset);
1271   }
1272   else
1273      memcpy(ROM, image.get_software_region("rom") + offset, state->m_cart_size - offset);
1274
1275   if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", state->m_cart_size - offset);
1276
1277   /* First, look if the cart is HiROM or LoROM (and set snes_cart accordingly) */
1278   int_header_offs = snes_find_hilo_mode(image, ROM, offset, 0);
1279
1280   // Detect presence of BS-X flash cartridge connector
1281   if ((ROM[int_header_offs - 14] == 'Z') && (ROM[int_header_offs - 11] == 'J'))
1282   {
1283      UINT8 n13 = ROM[int_header_offs - 13];
1284      if ((n13 >= 'A' && n13 <= 'Z') || (n13 >= '0' && n13 <= '9'))
1285      {
1286         if (ROM[int_header_offs + 0x1a] == 0x33 ||
1287            (ROM[int_header_offs - 10] == 0x00 && ROM[int_header_offs - 4] == 0x00))
1288         {
1289            has_bsx_slot = 1;
1290         }
1291      }
1292   }
1293
1294   // If there is a BS-X connector, detect if it is the Base Cart or a compatible slotted cart
1295   if (has_bsx_slot)
1296   {
1297      if (!memcmp(ROM + int_header_offs, "Satellaview BS-X     ", 21))
1298      {
1299         //BS-X Base Cart
1300         state->m_cart[0].mode = SNES_MODE_BSX;
1301         // handle RAM
1302      }
1303      else
1304      {
1305         state->m_cart[0].mode = (int_header_offs ==0x007fc0) ? SNES_MODE_BSLO : SNES_MODE_BSHI;
1306         // handle RAM?
1307      }
1308   }
1309   else
1310   {
1311      mame_printf_error("This is not a BS-X compatible cart.\n");
1312      mame_printf_error("This image cannot be loaded in the first cartslot of snesbsx.\n");
1313      return IMAGE_INIT_FAIL;
1314   }
1315
1316
1317   /* FIXME: Insert crc check here? */
1318
1319   /* How many blocks of data are available to be loaded? */
1320   total_blocks = (state->m_cart_size - offset) / 0x8000;
1321   read_blocks = 0;
1322
1323   if (SNES_CART_DEBUG) mame_printf_error("blocks %d\n", total_blocks);
1324
1325   // actually load the cart
1326   while (read_blocks < 64 && read_blocks < total_blocks)
1327   {
1328      /* Loading data */
1329      memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000);
1330      /* Mirroring */
1331      memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0x8000 + (read_blocks * 0x10000)], 0x8000);
1332
1333      read_blocks++;
1334   }
1335
1336   /* Filling banks up to 0x3f and their mirrors */
1337   while (read_blocks % 64)
1338   {
1339      int j = 0, repeat_blocks;
1340      while ((read_blocks % (64 >> j)) && j < 6)
1341         j++;
1342      repeat_blocks = read_blocks % (64 >> (j - 1));
1343
1344      memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1345      memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1346      read_blocks += repeat_blocks;
1347   }
1348
1349   return IMAGE_INIT_PASS;
1350}
1351
1352static DEVICE_IMAGE_LOAD( bsx2slot_cart )
1353{
1354   running_machine &machine = image.device().machine();
1355   snes_state *state = machine.driver_data<snes_state>();
1356   UINT32 offset, int_header_offs;
1357   UINT8 *ROM = image.device().machine().region("flash")->base();
1358
1359   if (image.software_entry() == NULL)
1360      state->m_cart_size = image.length();
1361   else
1362      state->m_cart_size = image.get_software_region_length("rom");
1363
1364   /* Check for a header (512 bytes), and skip it if found */
1365   offset = snes_skip_header(image, state->m_cart_size);
1366
1367   if (image.software_entry() == NULL)
1368   {
1369      image.fseek(offset, SEEK_SET);
1370      image.fread( ROM, state->m_cart_size - offset);
1371   }
1372   else
1373      memcpy(ROM, image.get_software_region("rom") + offset, state->m_cart_size - offset);
1374
1375   if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", state->m_cart_size - offset);
1376
1377   /* First, look if the cart is HiROM or LoROM (and set snes_cart accordingly) */
1378   int_header_offs = snes_find_hilo_mode(image, ROM, offset, 1);
1379
1380   // Detect presence of BS-X Flash Cart
1381   if ((ROM[int_header_offs + 0x13] == 0x00 || ROM[int_header_offs + 0x13] == 0xff) &&
1382      ROM[int_header_offs + 0x14] == 0x00)
1383   {
1384      UINT8 n15 = ROM[int_header_offs + 0x15];
1385      if (n15 == 0x00 || n15 == 0x80 || n15 == 0x84 || n15 == 0x9c || n15 == 0xbc || n15 == 0xfc)
1386      {
1387         if (ROM[int_header_offs + 0x1a] == 0x33 || ROM[int_header_offs + 0x1a] == 0xff)
1388         {
1389            // BS-X Flash Cart
1390            state->m_cart[1].mode = SNES_MODE_BSX;
1391         }
1392      }
1393   }
1394
1395   if (state->m_cart[1].mode != SNES_MODE_BSX)
1396   {
1397      mame_printf_error("This is not a BS-X flash cart.\n");
1398      mame_printf_error("This image cannot be loaded in the second cartslot of snesbsx.\n");
1399      return IMAGE_INIT_FAIL;
1400   }
1401
1402   // actually load the cart
1403   return IMAGE_INIT_PASS;
1404}
1405
1406MACHINE_CONFIG_FRAGMENT( snes_cartslot )
1407   MCFG_CARTSLOT_ADD("cart")
1408   MCFG_CARTSLOT_EXTENSION_LIST("sfc,smc,fig,swc,bin")
1409   MCFG_CARTSLOT_NOT_MANDATORY
1410   MCFG_CARTSLOT_INTERFACE("snes_cart")
1411   MCFG_CARTSLOT_LOAD(snes_cart)
1412   MCFG_SOFTWARE_LIST_ADD("cart_list","snes")
1413MACHINE_CONFIG_END
1414
1415// This (hackily) emulates a SNES unit with a Sufami Turbo Unit cart inserted:
1416// hence, the user can mount two data cart in the two slots available on the ST Unit
1417MACHINE_CONFIG_FRAGMENT( sufami_cartslot )
1418   MCFG_CARTSLOT_ADD("slot_a")
1419   MCFG_CARTSLOT_EXTENSION_LIST("st,sfc")
1420   MCFG_CARTSLOT_NOT_MANDATORY
1421   MCFG_CARTSLOT_INTERFACE("sufami_cart")
1422   MCFG_CARTSLOT_LOAD(sufami_cart)
1423
1424   MCFG_CARTSLOT_ADD("slot_b")
1425   MCFG_CARTSLOT_EXTENSION_LIST("st,sfc")
1426   MCFG_CARTSLOT_NOT_MANDATORY
1427   MCFG_CARTSLOT_INTERFACE("sufami_cart")
1428   MCFG_CARTSLOT_LOAD(sufami_cart)
1429
1430//  MCFG_SOFTWARE_LIST_ADD("cart_list","snes")
1431MACHINE_CONFIG_END
1432
1433// This (hackily) emulates a SNES unit where you want to load a BS-X compatible cart:
1434// hence, the user can mount a SNES cart in the first slot (either a BS-X BIOS cart, or a
1435// BS-X compatible one, e.g. Same Game), and there is a second slot for the 8M data pack
1436// (in a real SNES this would have been inserted in the smaller slot on the cart itself)
1437MACHINE_CONFIG_FRAGMENT( bsx_cartslot )
1438   MCFG_CARTSLOT_ADD("cart")
1439   MCFG_CARTSLOT_EXTENSION_LIST("sfc,smc,fig,swc,bin")
1440   MCFG_CARTSLOT_NOT_MANDATORY
1441   MCFG_CARTSLOT_INTERFACE("snes_cart")
1442   MCFG_CARTSLOT_LOAD(bsx_cart)
1443
1444   MCFG_CARTSLOT_ADD("slot2")
1445   MCFG_CARTSLOT_EXTENSION_LIST("bs,sfc")
1446   MCFG_CARTSLOT_NOT_MANDATORY
1447   MCFG_CARTSLOT_INTERFACE("bsx_cart")
1448   MCFG_CARTSLOT_LOAD(bsx2slot_cart)
1449
1450//  MCFG_SOFTWARE_LIST_ADD("cart_list","snes")
1451MACHINE_CONFIG_END
1452
1453DRIVER_INIT( snes_mess )
1454{
1455   snes_ram = machine.region("maincpu")->base();
1456   memset(snes_ram, 0, 0x1000000);
1457}
1458
1459DRIVER_INIT( snesst )
1460{
1461   snes_state *state = machine.driver_data<snes_state>();
1462   UINT8 *STBIOS = machine.region("sufami")->base();
1463   int i, j;
1464
1465   state->m_cart[0].slot_in_use = 0;
1466   state->m_cart[1].slot_in_use = 0;
1467
1468   DRIVER_INIT_CALL(snes_mess);
1469
1470   // the Base ST cart consists of 8 * 0x8000 block which have to be loaded (and mirrored)
1471   // at 0x00-0x1f:0x8000-0xffff and 0x80-0x9f:0x8000-0xffff
1472   for (i = 0; i < 8; i++)
1473   {
1474      /* Loading data */
1475      memcpy(&snes_ram[0x008000 + i * 0x10000], &STBIOS[0x000000 + i * 0x8000], 0x8000);
1476      /* Mirroring */
1477      memcpy(&snes_ram[0x808000 + i * 0x10000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000);
1478
1479      /* Additional mirrors (to fill snes_ram up to 0x1fffff) */
1480      for (j = 1; j < 4; j++)
1481      {
1482         memcpy(&snes_ram[0x008000 + i * 0x10000 + j * 0x80000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000);
1483         memcpy(&snes_ram[0x808000 + i * 0x10000 + j * 0x80000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000);
1484      }
1485   }
1486
1487}
src/mess/machine/snescart.h
r11460r11461
1/*
2    snescart.h
3
4*/
5
6#ifndef _SNESCART_H
7#define _SNESCART_H
8
9#include "imagedev/cartslot.h"
10
11MACHINE_START( snes_mess );
12MACHINE_START( snesst );
13
14DRIVER_INIT( snes_mess );
15DRIVER_INIT( snesst );
16
17MACHINE_CONFIG_EXTERN( snes_cartslot );
18MACHINE_CONFIG_EXTERN( sufami_cartslot );
19MACHINE_CONFIG_EXTERN( bsx_cartslot );
20
21#endif /* _SNESCART_H */
22
src/mess/machine/pce.c
r11460r11461
1/************************************************************
2
3PC Engine CD HW notes:
4
5CD Interface Register 0x00 - CDC status
6x--- ---- busy signal
7-x-- ---- request signal
8---x ---- cd signal
9---- x--- i/o signal
10
11CD Interface Register 0x03 - BRAM lock / CD status
12-x-- ---- acknowledge signal
13--x- ---- done signal
14---x ---- bram signal
15---- x--- ADPCM 2
16---- -x-- ADPCM 1
17---- --x- CDDA left/right speaker select
18
19CD Interface Register 0x05 - CD-DA Volume low 8-bit port
20
21CD Interface Register 0x06 - CD-DA Volume high 8-bit port
22
23CD Interface Register 0x07 - BRAM unlock / CD status
24x--- ---- Enables BRAM
25
26CD Interface Register 0x0c - ADPCM status
27x--- ---- ADPCM is reading data
28---- x--- ADPCM playback (0) stopped (1) currently playing
29---- -x-- pending ADPCM data write
30---- ---x ADPCM playback (1) stopped (0) currently playing
31
32CD Interface Register 0x0d - ADPCM address control
33x--- ---- ADPCM reset
34-x-- ---- ADPCM play
35--x- ---- ADPCM repeat
36---x ---- ADPCM set length
37---- x--- ADPCM set read address
38---- --xx ADPCM set write address
39(note: some games reads bit 5 and wants it to be low otherwise they hangs, surely NOT an ADPCM repeat flag read because it doesn't make sense)
40
41CD Interface Register 0x0e - ADPCM playback rate
42
43CD Interface Register 0x0f - ADPCM fade in/out register
44---- xxxx command setting:
450x00 ADPCM/CD-DA Fade-in
460x01 CD-DA fade-in
470x08 CD-DA fade-out (short) ADPCM fade-in
480x09 CD-DA fade-out (long)
490x0a ADPCM fade-out (long)
500x0c CD-DA fade-out (short) ADPCM fade-in
510x0d CD-DA fade-out (short)
520x0e ADPCM fade-out (short)
53
54*************************************************************/
55
56#include "emu.h"
57#include "coreutil.h"
58#include "cpu/h6280/h6280.h"
59#include "includes/pce.h"
60#include "imagedev/chd_cd.h"
61#include "sound/msm5205.h"
62#include "sound/cdda.h"
63#include "hashfile.h"
64
65
66#define PCE_BRAM_SIZE            0x800
67#define PCE_ADPCM_RAM_SIZE         0x10000
68#define PCE_ACARD_RAM_SIZE         0x200000
69#define PCE_CD_COMMAND_BUFFER_SIZE   0x100
70
71#define PCE_CD_IRQ_TRANSFER_READY      0x40
72#define PCE_CD_IRQ_TRANSFER_DONE      0x20
73#define PCE_CD_IRQ_SAMPLE_FULL_PLAY      0x08
74#define PCE_CD_IRQ_SAMPLE_HALF_PLAY      0x04
75
76#define PCE_CD_ADPCM_PLAY_FLAG      0x08
77#define PCE_CD_ADPCM_STOP_FLAG      0x01
78
79#define PCE_CD_DATA_FRAMES_PER_SECOND   75
80
81enum {
82   PCE_CD_CDDA_OFF=0,
83   PCE_CD_CDDA_PLAYING,
84   PCE_CD_CDDA_PAUSED
85};
86
87
88/* CD Unit RAM */
89
90/* MSM5205 ADPCM decoder definition */
91static void pce_cd_msm5205_int(device_t *device);
92const msm5205_interface pce_cd_msm5205_interface = {
93   pce_cd_msm5205_int,   /* interrupt function */
94   MSM5205_S48_4B      /* 1/48 prescaler, 4bit data */
95};
96
97
98/* joystick related data*/
99
100#define JOY_CLOCK   0x01
101#define JOY_RESET   0x02
102
103
104/* prototypes */
105static void pce_cd_init( running_machine &machine );
106static void pce_cd_set_irq_line( running_machine &machine, int num, int state );
107static TIMER_CALLBACK( pce_cd_adpcm_dma_timer_callback );
108static TIMER_CALLBACK( pce_cd_cdda_fadeout_callback );
109static TIMER_CALLBACK( pce_cd_cdda_fadein_callback );
110static TIMER_CALLBACK( pce_cd_adpcm_fadeout_callback );
111static TIMER_CALLBACK( pce_cd_adpcm_fadein_callback );
112
113static WRITE8_HANDLER( pce_sf2_banking_w )
114{
115   memory_set_bankptr( space->machine(), "bank2", space->machine().region("user1")->base() + offset * 0x080000 + 0x080000 );
116   memory_set_bankptr( space->machine(), "bank3", space->machine().region("user1")->base() + offset * 0x080000 + 0x088000 );
117   memory_set_bankptr( space->machine(), "bank4", space->machine().region("user1")->base() + offset * 0x080000 + 0x0D0000 );
118}
119
120static WRITE8_HANDLER( pce_cartridge_ram_w )
121{
122   pce_state *state = space->machine().driver_data<pce_state>();
123   state->m_cartridge_ram[offset] = data;
124}
125
126DEVICE_IMAGE_LOAD(pce_cart)
127{
128   pce_state *state = image.device().machine().driver_data<pce_state>();
129   UINT32 size;
130   int split_rom = 0, offset = 0;
131   const char *extrainfo = NULL;
132   unsigned char *ROM;
133   logerror("*** DEVICE_IMAGE_LOAD(pce_cart) : %s\n", image.filename());
134
135   /* open file to get size */
136   ROM = image.device().machine().region("user1")->base();
137
138   if (image.software_entry() == NULL)
139      size = image.length();
140   else
141      size = image.get_software_region_length("rom");
142
143   /* handle header accordingly */
144   if ((size / 512) & 1)
145   {
146      logerror("*** DEVICE_IMAGE_LOAD(pce_cart) : Header present\n");
147      size -= 512;
148      offset = 512;
149   }
150
151   if (size > PCE_ROM_MAXSIZE)
152      size = PCE_ROM_MAXSIZE;
153
154   if (image.software_entry() == NULL)
155   {
156      image.fseek(offset, SEEK_SET);
157      image.fread( ROM, size);
158      extrainfo = hashfile_extrainfo(image);
159   }
160   else
161      memcpy(ROM, image.get_software_region("rom") + offset, size);
162
163   if (extrainfo)
164   {
165      logerror("extrainfo: %s\n", extrainfo);
166      if (strstr(extrainfo, "ROM_SPLIT"))
167         split_rom = 1;
168   }
169
170   if (ROM[0x1fff] < 0xe0)
171   {
172      int i;
173      UINT8 decrypted[256];
174
175      logerror( "*** DEVICE_IMAGE_LOAD(pce_cart) : ROM image seems encrypted, decrypting...\n" );
176
177      /* Initialize decryption table */
178      for (i = 0; i < 256; i++)
179         decrypted[i] = ((i & 0x01) << 7) | ((i & 0x02) << 5) | ((i & 0x04) << 3) | ((i & 0x08) << 1) | ((i & 0x10) >> 1) | ((i & 0x20 ) >> 3) | ((i & 0x40) >> 5) | ((i & 0x80) >> 7);
180
181      /* Decrypt ROM image */
182      for (i = 0; i < size; i++)
183         ROM[i] = decrypted[ROM[i]];
184   }
185
186   /* check if we're dealing with a split rom image */
187   if (size == 384 * 1024)
188   {
189      split_rom = 1;
190      /* Mirror the upper 128KB part of the image */
191      memcpy(ROM + 0x060000, ROM + 0x040000, 0x020000);   /* Set up 060000 - 07FFFF mirror */
192   }
193
194   /* set up the memory for a split rom image */
195   if (split_rom)
196   {
197      logerror("Split rom detected, setting up memory accordingly\n");
198      /* Set up ROM address space as follows:          */
199      /* 000000 - 03FFFF : ROM data 000000 - 03FFFF    */
200      /* 040000 - 07FFFF : ROM data 000000 - 03FFFF    */
201      /* 080000 - 0BFFFF : ROM data 040000 - 07FFFF    */
202      /* 0C0000 - 0FFFFF : ROM data 040000 - 07FFFF    */
203      memcpy(ROM + 0x080000, ROM + 0x040000, 0x040000);   /* Set up 080000 - 0BFFFF region */
204      memcpy(ROM + 0x0C0000, ROM + 0x040000, 0x040000);   /* Set up 0C0000 - 0FFFFF region */
205      memcpy(ROM + 0x040000, ROM, 0x040000);      /* Set up 040000 - 07FFFF region */
206   }
207   else
208   {
209      /* mirror 256KB rom data */
210      if (size <= 0x040000)
211         memcpy(ROM + 0x040000, ROM, 0x040000);
212
213      /* mirror 512KB rom data */
214      if (size <= 0x080000)
215         memcpy(ROM + 0x080000, ROM, 0x080000);
216   }
217
218   memory_set_bankptr(image.device().machine(), "bank1", ROM);
219   memory_set_bankptr(image.device().machine(), "bank2", ROM + 0x080000);
220   memory_set_bankptr(image.device().machine(), "bank3", ROM + 0x088000);
221   memory_set_bankptr(image.device().machine(), "bank4", ROM + 0x0d0000);
222
223   /* Check for Street fighter 2 */
224   if (size == PCE_ROM_MAXSIZE)
225   {
226      image.device().machine().device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x01ff0, 0x01ff3, FUNC(pce_sf2_banking_w));
227   }
228
229   /* Check for Populous */
230   if (!memcmp(ROM + 0x1F26, "POPULOUS", 8))
231   {
232      state->m_cartridge_ram = auto_alloc_array(image.device().machine(), UINT8, 0x8000);
233      memory_set_bankptr(image.device().machine(), "bank2", state->m_cartridge_ram);
234      image.device().machine().device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x080000, 0x087FFF, FUNC(pce_cartridge_ram_w));
235   }
236
237   /* Check for CD system card */
238   state->m_sys3_card = 0;
239   if (!memcmp(ROM + 0x3FFB6, "PC Engine CD-ROM SYSTEM", 23))
240   {
241      /* Check if 192KB additional system card ram should be used */
242      if(!memcmp(ROM + 0x29D1, "VER. 3.", 7))       { state->m_sys3_card = 1; } // JP version
243      else if(!memcmp(ROM + 0x29C4, "VER. 3.", 7 ))   { state->m_sys3_card = 3; } // US version
244
245      if(state->m_sys3_card)
246      {
247         state->m_cartridge_ram = auto_alloc_array(image.device().machine(), UINT8, 0x30000);
248         memory_set_bankptr(image.device().machine(), "bank4", state->m_cartridge_ram);
249         image.device().machine().device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x0D0000, 0x0FFFFF, FUNC(pce_cartridge_ram_w));
250         image.device().machine().device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_readwrite_handler(0x080000, 0x087FFF, FUNC(pce_cd_acard_wram_r),FUNC(pce_cd_acard_wram_w));
251      }
252   }
253   return 0;
254}
255
256#ifdef MESS
257DRIVER_INIT( pce )
258{
259   pce_state *state = machine.driver_data<pce_state>();
260   state->m_io_port_options = PCE_JOY_SIG | CONST_SIG;
261}
262#endif
263
264DRIVER_INIT( tg16 )
265{
266   pce_state *state = machine.driver_data<pce_state>();
267   state->m_io_port_options = TG_16_JOY_SIG | CONST_SIG;
268}
269
270DRIVER_INIT( sgx )
271{
272   pce_state *state = machine.driver_data<pce_state>();
273   state->m_io_port_options = PCE_JOY_SIG | CONST_SIG;
274}
275
276MACHINE_START( pce )
277{
278   pce_cd_init( machine );
279}
280
281#ifdef MESS
282MACHINE_RESET( pce )
283{
284   pce_state *state = machine.driver_data<pce_state>();
285   pce_cd_t &pce_cd = state->m_cd;
286   int joy_i;
287
288   for (joy_i = 0; joy_i < 5; joy_i++)
289      state->m_joy_6b_packet[joy_i] = 0;
290
291   pce_cd.adpcm_read_buf = 0;
292   pce_cd.adpcm_write_buf = 0;
293
294   // TODO: add CD-DA stop command here
295
296   pce_cd.regs[0x0c] |= PCE_CD_ADPCM_STOP_FLAG;
297   pce_cd.regs[0x0c] &= ~PCE_CD_ADPCM_PLAY_FLAG;
298   //pce_cd.regs[0x03] = (pce_cd.regs[0x03] & ~0x0c) | (PCE_CD_SAMPLE_STOP_PLAY);
299
300   /* Note: Arcade Card BIOS contents are the same as System 3, only internal HW differs.
301       We use a category to select between modes (some games can be run in either S-CD or A-CD modes) */
302   state->m_acard = input_port_read(machine, "A_CARD") & 1;
303}
304
305/* todo: how many input ports does the PCE have? */
306WRITE8_HANDLER ( pce_joystick_w )
307{
308   pce_state *state = space->machine().driver_data<pce_state>();
309   int joy_i;
310   UINT8 joy_type = input_port_read(space->machine(),"JOY_TYPE");
311
312   h6280io_set_buffer(&space->device(), data);
313
314    /* bump counter on a low-to-high transition of bit 1 */
315    if ((!state->m_joystick_data_select) && (data & JOY_CLOCK))
316    {
317        state->m_joystick_port_select = (state->m_joystick_port_select + 1) & 0x07;
318    }
319
320    /* do we want buttons or direction? */
321    state->m_joystick_data_select = data & JOY_CLOCK;
322
323    /* clear counter if bit 2 is set */
324    if (data & JOY_RESET)
325    {
326      state->m_joystick_port_select = 0;
327
328      for (joy_i = 0; joy_i < 5; joy_i++)
329      {
330         if (((joy_type >> (joy_i*2)) & 3) == 2)
331              state->m_joy_6b_packet[joy_i] ^= 1;
332      }
333    }
334}
335
336READ8_HANDLER ( pce_joystick_r )
337{
338   pce_state *state = space->machine().driver_data<pce_state>();
339   static const char *const joyname[4][5] = {
340      { "JOY_P1", "JOY_P2", "JOY_P3", "JOY_P4", "JOY_P5" },
341      { },
342      { "JOY6B_P1", "JOY6B_P2", "JOY6B_P3", "JOY6B_P4", "JOY6B_P5" },
343      { }
344   };
345   UINT8 joy_type = input_port_read(space->machine(), "JOY_TYPE");
346   UINT8 ret, data;
347
348   if (state->m_joystick_port_select <= 4)
349   {
350      switch((joy_type >> (state->m_joystick_port_select*2)) & 3)
351      {
352         case 0: //2-buttons pad
353            data = input_port_read(space->machine(), joyname[0][state->m_joystick_port_select]);
354            break;
355         case 2: //6-buttons pad
356            /*
357                Two packets:
358                1st packet: directions + I, II, Run, Select
359                2nd packet: 6 buttons "header" (high 4 bits active low) + III, IV, V, VI
360                Note that six buttons pad just doesn't work with (almost?) every single 2-button-only games, it's really just an after-thought and it is like this
361                on real HW.
362                */
363            data = input_port_read(space->machine(), joyname[2][state->m_joystick_port_select]) >> (state->m_joy_6b_packet[state->m_joystick_port_select]*8);
364            break;
365         default:
366            data = 0xff;
367            break;
368      }
369   }
370   else
371      data = 0xff;
372
373
374   if (state->m_joystick_data_select)
375      data >>= 4;
376
377   ret = (data & 0x0f) | state->m_io_port_options;
378#ifdef UNIFIED_PCE
379   ret &= ~0x40;
380#endif
381
382   return (ret);
383}
384#endif
385NVRAM_HANDLER( pce )
386{
387   pce_state *state = machine.driver_data<pce_state>();
388   pce_cd_t &pce_cd = state->m_cd;
389   if (read_or_write)
390   {
391      file->write(pce_cd.bram, PCE_BRAM_SIZE);
392   }
393   else
394   {
395      /* load battery backed memory from disk */
396      if (file)
397         file->read(pce_cd.bram, PCE_BRAM_SIZE);
398   }
399}
400
401static void pce_set_cd_bram( running_machine &machine )
402{
403   pce_state *state = machine.driver_data<pce_state>();
404   pce_cd_t &pce_cd = state->m_cd;
405   memory_set_bankptr( machine, "bank10", pce_cd.bram + ( pce_cd.bram_locked ? PCE_BRAM_SIZE : 0 ) );
406}
407
408static void adpcm_stop(running_machine &machine)
409{
410   pce_state *state = machine.driver_data<pce_state>();
411   pce_cd_t &pce_cd = state->m_cd;
412   pce_cd.regs[0x0c] |= PCE_CD_ADPCM_STOP_FLAG;
413   pce_cd.regs[0x0c] &= ~PCE_CD_ADPCM_PLAY_FLAG;
414   //pce_cd.regs[0x03] = (pce_cd.regs[0x03] & ~0x0c) | (PCE_CD_SAMPLE_STOP_PLAY);
415   pce_cd_set_irq_line( machine, PCE_CD_IRQ_SAMPLE_FULL_PLAY, ASSERT_LINE );
416   pce_cd.regs[0x0d] &= ~0x60;
417   pce_cd.msm_idle = 1;
418}
419
420static void adpcm_play(running_machine &machine)
421{
422   pce_state *state = machine.driver_data<pce_state>();
423   pce_cd_t &pce_cd = state->m_cd;
424   pce_cd.regs[0x0c] &= ~PCE_CD_ADPCM_STOP_FLAG;
425   pce_cd.regs[0x0c] |= PCE_CD_ADPCM_PLAY_FLAG;
426   pce_cd_set_irq_line( machine, PCE_CD_IRQ_SAMPLE_FULL_PLAY, CLEAR_LINE );
427   pce_cd.regs[0x03] = (pce_cd.regs[0x03] & ~0x0c);
428   pce_cd.msm_idle = 0;
429}
430
431
432/* Callback for new data from the MSM5205.
433  The PCE cd unit actually divides the clock signal supplied to
434  the MSM5205. Currently we can only use static clocks for the
435  MSM5205.
436 */
437static void pce_cd_msm5205_int(device_t *device)
438{
439   pce_state *state = device->machine().driver_data<pce_state>();
440   pce_cd_t &pce_cd = state->m_cd;
441   UINT8 msm_data;
442
443//  popmessage("%08x %08x %08x %02x %02x",pce_cd.msm_start_addr,pce_cd.msm_end_addr,pce_cd.msm_half_addr,pce_cd.regs[0x0c],pce_cd.regs[0x0d]);
444
445   if ( pce_cd.msm_idle )
446      return;
447
448   /* Supply new ADPCM data */
449   msm_data = (pce_cd.msm_nibble) ? (pce_cd.adpcm_ram[pce_cd.msm_start_addr] & 0x0f) : ((pce_cd.adpcm_ram[pce_cd.msm_start_addr] & 0xf0) >> 4);
450
451   msm5205_data_w(device, msm_data);
452   pce_cd.msm_nibble ^= 1;
453
454   if(pce_cd.msm_nibble == 0)
455   {
456      pce_cd.msm_start_addr++;
457
458      if(pce_cd.msm_start_addr == pce_cd.msm_half_addr)
459      {
460         //pce_cd_set_irq_line( device->machine(), PCE_CD_IRQ_SAMPLE_FULL_PLAY, CLEAR_LINE );
461         //pce_cd_set_irq_line( device->machine(), PCE_CD_IRQ_SAMPLE_HALF_PLAY, ASSERT_LINE );
462      }
463
464      if(pce_cd.msm_start_addr > pce_cd.msm_end_addr)
465      {
466         //pce_cd_set_irq_line( device->machine(), PCE_CD_IRQ_SAMPLE_HALF_PLAY, CLEAR_LINE );
467         //pce_cd_set_irq_line( device->machine(), PCE_CD_IRQ_SAMPLE_FULL_PLAY, CLEAR_LINE );
468         adpcm_stop(device->machine());
469         msm5205_reset_w(device, 1);
470      }
471   }
472}
473
474#define   SCSI_STATUS_OK         0x00
475#define SCSI_CHECK_CONDITION   0x02
476
477static void pce_cd_reply_status_byte( pce_state *state, UINT8 status )
478{
479   pce_cd_t &pce_cd = state->m_cd;
480logerror("Setting CD in reply_status_byte\n");
481   pce_cd.scsi_CD = pce_cd.scsi_IO = pce_cd.scsi_REQ = 1;
482   pce_cd.scsi_MSG = 0;
483   pce_cd.message_after_status = 1;
484   pce_cd.status_sent = pce_cd.message_sent = 0;
485
486   if ( status == SCSI_STATUS_OK )
487   {
488      pce_cd.regs[0x01] = 0x00;
489   }
490   else
491   {
492      pce_cd.regs[0x01] = 0x01;
493   }
494}
495
496/* 0x00 - TEST UNIT READY */
497static void pce_cd_test_unit_ready( running_machine &machine )
498{
499   pce_state *state = machine.driver_data<pce_state>();
500   pce_cd_t &pce_cd = state->m_cd;
501   logerror("test unit ready\n");
502   if ( pce_cd.cd )
503   {
504      logerror( "Sending STATUS_OK status\n" );
505      pce_cd_reply_status_byte( state, SCSI_STATUS_OK );
506   }
507   else
508   {
509      logerror( "Sending CHECK_CONDITION status\n" );
510      pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
511   }
512}
513
514/* 0x08 - READ (6) */
515static void pce_cd_read_6( running_machine &machine )
516{
517   pce_state *state = machine.driver_data<pce_state>();
518   pce_cd_t &pce_cd = state->m_cd;
519   UINT32 frame = ( ( pce_cd.command_buffer[1] & 0x1F ) << 16 ) | ( pce_cd.command_buffer[2] << 8 ) | pce_cd.command_buffer[3];
520   UINT32 frame_count = pce_cd.command_buffer[4];
521
522   /* Check for presence of a CD */
523   if ( ! pce_cd.cd )
524   {
525      pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
526      return;
527   }
528
529   if ( pce_cd.cdda_status != PCE_CD_CDDA_OFF )
530   {
531      pce_cd.cdda_status = PCE_CD_CDDA_OFF;
532      cdda_stop_audio( machine.device( "cdda" ) );
533      pce_cd.end_mark = 0;
534   }
535
536   pce_cd.current_frame = frame;
537   pce_cd.end_frame = frame + frame_count;
538
539   if ( frame_count == 0 )
540   {
541      /* Star Breaker uses this */
542      popmessage("Read Sector frame count == 0, contact MESSdev");
543      pce_cd_reply_status_byte( state, SCSI_STATUS_OK );
544   }
545   else
546   {
547      pce_cd.data_timer->adjust(attotime::from_hz( PCE_CD_DATA_FRAMES_PER_SECOND ), 0, attotime::from_hz( PCE_CD_DATA_FRAMES_PER_SECOND ));
548   }
549}
550
551/* 0xD8 - SET AUDIO PLAYBACK START POSITION (NEC) */
552static void pce_cd_nec_set_audio_start_position( running_machine &machine )
553{
554   pce_state *state = machine.driver_data<pce_state>();
555   pce_cd_t &pce_cd = state->m_cd;
556   UINT32   frame = 0;
557
558   if ( ! pce_cd.cd )
559   {
560      /* Throw some error here */
561      pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
562      return;
563   }
564
565   switch( pce_cd.command_buffer[9] & 0xC0 )
566   {
567   case 0x00:
568      popmessage("CD-DA set start mode 0x00, contact MESSdev");
569      frame = ( pce_cd.command_buffer[3] << 16 ) | ( pce_cd.command_buffer[4] << 8 ) | pce_cd.command_buffer[5];
570      break;
571   case 0x40:
572   {
573      UINT8 m,s,f;
574
575      m = bcd_2_dec( pce_cd.command_buffer[2]);
576      s = bcd_2_dec( pce_cd.command_buffer[3]);
577      f = bcd_2_dec( pce_cd.command_buffer[4]);
578
579      frame = f + 75 * (s + m * 60);
580      if(frame >= 525) // TODO: seven seconds gap? O_o
581         frame -= 525;
582      break;
583   }
584   case 0x80:
585      frame = pce_cd.toc->tracks[ bcd_2_dec( pce_cd.command_buffer[2] ) - 1 ].physframeofs;
586      break;
587   default:
588      popmessage("CD-DA set start mode 0xc0, contact MESSdev");
589      //assert( NULL == pce_cd_nec_set_audio_start_position );
590      break;
591   }
592
593   pce_cd.current_frame = frame;
594
595   if ( pce_cd.cdda_status == PCE_CD_CDDA_PAUSED )
596   {
597      pce_cd.cdda_status = PCE_CD_CDDA_OFF;
598      cdda_stop_audio( machine.device( "cdda" ) );
599      pce_cd.end_frame = pce_cd.last_frame;
600      pce_cd.end_mark = 0;
601   }
602   else
603   {
604      if(pce_cd.command_buffer[1] & 0x03)
605      {
606         pce_cd.cdda_status = PCE_CD_CDDA_PLAYING;
607         pce_cd.end_frame = pce_cd.last_frame; //get the end of the CD
608         cdda_start_audio( machine.device( "cdda" ), pce_cd.current_frame, pce_cd.end_frame - pce_cd.current_frame );
609         pce_cd.cdda_play_mode = (pce_cd.command_buffer[1] & 0x02) ? 2 : 3; // mode 2 sets IRQ at end
610         pce_cd.end_mark =  (pce_cd.command_buffer[1] & 0x02) ? 1 : 0;
611      }
612      else
613      {
614         pce_cd.cdda_status = PCE_CD_CDDA_PLAYING;
615         pce_cd.end_frame = pce_cd.toc->tracks[ cdrom_get_track(pce_cd.cd, pce_cd.current_frame) + 1 ].physframeofs; //get the end of THIS track
616         cdda_start_audio( machine.device( "cdda" ), pce_cd.current_frame, pce_cd.end_frame - pce_cd.current_frame );
617         pce_cd.end_mark = 0;
618         pce_cd.cdda_play_mode = 3;
619      }
620   }
621
622   pce_cd_reply_status_byte( state, SCSI_STATUS_OK );
623   pce_cd_set_irq_line( machine, PCE_CD_IRQ_TRANSFER_DONE, ASSERT_LINE );
624}
625
626/* 0xD9 - SET AUDIO PLAYBACK END POSITION (NEC) */
627static void pce_cd_nec_set_audio_stop_position( running_machine &machine )
628{
629   pce_state *state = machine.driver_data<pce_state>();
630   pce_cd_t &pce_cd = state->m_cd;
631   UINT32  frame = 0;
632
633   if ( ! pce_cd.cd )
634   {
635      /* Throw some error here */
636      pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
637      return;
638   }
639
640   switch( pce_cd.command_buffer[9] & 0xC0 )
641   {
642   case 0x00:
643      popmessage("CD-DA set end mode 0x00, contact MESSdev");
644      frame = ( pce_cd.command_buffer[3] << 16 ) | ( pce_cd.command_buffer[4] << 8 ) | pce_cd.command_buffer[5];
645      break;
646   case 0x40:
647   {
648      UINT8 m,s,f;
649
650      m = bcd_2_dec( pce_cd.command_buffer[2]);
651      s = bcd_2_dec( pce_cd.command_buffer[3]);
652      f = bcd_2_dec( pce_cd.command_buffer[4]);
653
654      frame = f + 75 * (s + m * 60);
655      if(frame >= 525) // TODO: seven seconds gap? O_o
656         frame -= 525;
657      break;
658   }
659   case 0x80:
660      frame = pce_cd.toc->tracks[ bcd_2_dec( pce_cd.command_buffer[2] ) - 1 ].physframeofs;
661      break;
662   default:
663      popmessage("CD-DA set end mode 0xc0, contact MESSdev");
664      //assert( NULL == pce_cd_nec_set_audio_start_position );
665      break;
666   }
667
668   pce_cd.end_frame = frame;
669   pce_cd.cdda_play_mode = pce_cd.command_buffer[1] & 0x03;
670
671   if ( pce_cd.cdda_play_mode )
672   {
673      if ( pce_cd.cdda_status == PCE_CD_CDDA_PAUSED )
674      {
675         cdda_pause_audio( machine.device( "cdda" ), 0 );
676      }
677      else
678      {
679         cdda_start_audio( machine.device( "cdda" ), pce_cd.current_frame, pce_cd.end_frame - pce_cd.current_frame );
680         pce_cd.end_mark = 1;
681      }
682      pce_cd.cdda_status = PCE_CD_CDDA_PLAYING;
683   }
684   else
685   {
686      pce_cd.cdda_status = PCE_CD_CDDA_OFF;
687      cdda_stop_audio( machine.device( "cdda" ) );
688      pce_cd.end_frame = pce_cd.last_frame;
689      pce_cd.end_mark = 0;
690//      assert( NULL == pce_cd_nec_set_audio_stop_position );
691   }
692
693   pce_cd_reply_status_byte( state, SCSI_STATUS_OK );
694   pce_cd_set_irq_line( machine, PCE_CD_IRQ_TRANSFER_DONE, ASSERT_LINE );
695}
696
697/* 0xDA - PAUSE (NEC) */
698static void pce_cd_nec_pause( running_machine &machine )
699{
700   pce_state *state = machine.driver_data<pce_state>();
701   pce_cd_t &pce_cd = state->m_cd;
702
703   /* If no cd mounted throw an error */
704   if ( ! pce_cd.cd )
705   {
706      pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
707      return;
708   }
709
710   /* If there was no cdda playing, throw an error */
711   if ( pce_cd.cdda_status == PCE_CD_CDDA_OFF )
712   {
713      pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
714      return;
715   }
716
717   pce_cd.cdda_status = PCE_CD_CDDA_PAUSED;
718   pce_cd.current_frame = cdda_get_audio_lba( machine.device( "cdda" ) );
719   cdda_pause_audio( machine.device( "cdda" ), 1 );
720   pce_cd_reply_status_byte( state, SCSI_STATUS_OK );
721}
722
723/* 0xDD - READ SUBCHANNEL Q (NEC) */
724static void pce_cd_nec_get_subq( running_machine &machine )
725{
726   pce_state *state = machine.driver_data<pce_state>();
727   pce_cd_t &pce_cd = state->m_cd;
728   /* WP - I do not have access to chds with subchannel information yet, so I'm faking something here */
729   UINT32 msf_abs, msf_rel, track, frame;
730
731   if ( ! pce_cd.cd )
732   {
733      /* Throw some error here */
734      pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
735      return;
736   }
737
738   frame = pce_cd.current_frame;
739
740   switch( pce_cd.cdda_status )
741   {
742   case PCE_CD_CDDA_PAUSED:
743      pce_cd.data_buffer[0] = 2;
744      frame = cdda_get_audio_lba( machine.device( "cdda" ) );
745      break;
746   case PCE_CD_CDDA_PLAYING:
747      pce_cd.data_buffer[0] = 0;
748      frame = cdda_get_audio_lba( machine.device( "cdda" ) );
749      break;
750   default:
751      pce_cd.data_buffer[0] = 3;
752      break;
753   }
754
755   msf_abs = lba_to_msf( frame );
756   track = cdrom_get_track( pce_cd.cd, frame );
757   msf_rel = lba_to_msf( frame - cdrom_get_track_start( pce_cd.cd, track ) );
758
759   pce_cd.data_buffer[1] = 0;
760   pce_cd.data_buffer[2] = dec_2_bcd( track+1 );      /* track */
761   pce_cd.data_buffer[3] = 1;                     /* index */
762   pce_cd.data_buffer[4] = ( msf_rel >> 16 ) & 0xFF;   /* M (relative) */
763   pce_cd.data_buffer[5] = ( msf_rel >> 8 ) & 0xFF;   /* S (relative) */
764   pce_cd.data_buffer[6] = msf_rel & 0xFF;            /* F (relative) */
765   pce_cd.data_buffer[7] = ( msf_abs >> 16 ) & 0xFF;   /* M (absolute) */
766   pce_cd.data_buffer[8] = ( msf_abs >> 8 ) & 0xFF;   /* S (absolute) */
767   pce_cd.data_buffer[9] = msf_abs & 0xFF;            /* F (absolute) */
768   pce_cd.data_buffer_size = 10;
769
770   pce_cd.data_buffer_index = 0;
771   pce_cd.data_transferred = 1;
772   pce_cd.scsi_IO = 1;
773   pce_cd.scsi_CD = 0;
774}
775
776/* 0xDE - GET DIR INFO (NEC) */
777static void pce_cd_nec_get_dir_info( running_machine &machine )
778{
779   pce_state *state = machine.driver_data<pce_state>();
780   pce_cd_t &pce_cd = state->m_cd;
781   UINT32 frame, msf, track = 0;
782   const cdrom_toc   *toc;
783   logerror("nec get dir info\n");
784
785   if ( ! pce_cd.cd )
786   {
787      /* Throw some error here */
788      pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
789   }
790
791   toc = cdrom_get_toc( pce_cd.cd );
792
793   switch( pce_cd.command_buffer[1] )
794   {
795   case 0x00:      /* Get first and last track numbers */
796      pce_cd.data_buffer[0] = dec_2_bcd(1);
797      pce_cd.data_buffer[1] = dec_2_bcd(toc->numtrks);
798      pce_cd.data_buffer_size = 2;
799      break;
800   case 0x01:      /* Get total disk size in MSF format */
801      frame = toc->tracks[toc->numtrks-1].physframeofs;
802      frame += toc->tracks[toc->numtrks-1].frames;
803      msf = lba_to_msf( frame + 150 );
804
805      pce_cd.data_buffer[0] = ( msf >> 16 ) & 0xFF;   /* M */
806      pce_cd.data_buffer[1] = ( msf >> 8 ) & 0xFF;   /* S */
807      pce_cd.data_buffer[2] = msf & 0xFF;            /* F */
808      pce_cd.data_buffer_size = 3;
809      break;
810   case 0x02:      /* Get track information */
811      if ( pce_cd.command_buffer[2] == 0xAA )
812      {
813         frame = toc->tracks[toc->numtrks-1].physframeofs;
814         frame += toc->tracks[toc->numtrks-1].frames;
815         pce_cd.data_buffer[3] = 0x04;   /* correct? */
816      } else
817      {
818         track = MAX( bcd_2_dec( pce_cd.command_buffer[2] ), 1 );
819         frame = toc->tracks[track-1].physframeofs;
820         pce_cd.data_buffer[3] = ( toc->tracks[track-1].trktype == CD_TRACK_AUDIO ) ? 0x00 : 0x04;
821      }
822      logerror("track = %d, frame = %d\n", track, frame );
823      msf = lba_to_msf( frame + 150 );
824      pce_cd.data_buffer[0] = ( msf >> 16 ) & 0xFF;   /* M */
825      pce_cd.data_buffer[1] = ( msf >> 8 ) & 0xFF;   /* S */
826      pce_cd.data_buffer[2] = msf & 0xFF;            /* F */
827      pce_cd.data_buffer_size = 4;
828      break;
829   default:
830//      assert( pce_cd_nec_get_dir_info == NULL );  // Not implemented yet
831      break;
832   }
833
834   pce_cd.data_buffer_index = 0;
835   pce_cd.data_transferred = 1;
836   pce_cd.scsi_IO = 1;
837   pce_cd.scsi_CD = 0;
838}
839
840static void pce_cd_end_of_list( running_machine &machine )
841{
842   pce_state *state = machine.driver_data<pce_state>();
843   pce_cd_reply_status_byte( state, SCSI_CHECK_CONDITION );
844}
845
846static void pce_cd_handle_data_output( running_machine &machine )
847{
848   pce_state *state = machine.driver_data<pce_state>();
849   pce_cd_t &pce_cd = state->m_cd;
850   static const struct {
851      UINT8   command_byte;
852      UINT8   command_size;
853      void   (*command_handler)(running_machine &machine);
854   } pce_cd_commands[] = {
855      { 0x00, 6, pce_cd_test_unit_ready },            /* TEST UNIT READY */
856      { 0x08, 6, pce_cd_read_6 },                     /* READ (6) */
857      { 0xD8,10, pce_cd_nec_set_audio_start_position },   /* NEC SET AUDIO PLAYBACK START POSITION */
858      { 0xD9,10, pce_cd_nec_set_audio_stop_position },   /* NEC SET AUDIO PLAYBACK END POSITION */
859      { 0xDA,10, pce_cd_nec_pause },                  /* NEC PAUSE */
860      { 0xDD,10, pce_cd_nec_get_subq },               /* NEC GET SUBCHANNEL Q */
861      { 0xDE,10, pce_cd_nec_get_dir_info },            /* NEC GET DIR INFO */
862      { 0xFF, 1, pce_cd_end_of_list }                  /* end of list marker */
863   };
864
865   if ( pce_cd.scsi_REQ && pce_cd.scsi_ACK )
866   {
867      /* Command byte received */
868      logerror( "Command byte $%02X received\n", pce_cd.regs[0x01] );
869
870      /* Check for buffer overflow */
871      assert( pce_cd.command_buffer_index < PCE_CD_COMMAND_BUFFER_SIZE );
872
873      pce_cd.command_buffer[pce_cd.command_buffer_index] = pce_cd.regs[0x01];
874      pce_cd.command_buffer_index++;
875      pce_cd.scsi_REQ = 0;
876   }
877
878   if ( ! pce_cd.scsi_REQ && ! pce_cd.scsi_ACK && pce_cd.command_buffer_index )
879   {
880      int i = 0;
881
882      logerror( "Check if command done\n" );
883
884      for( i = 0; pce_cd.command_buffer[0] > pce_cd_commands[i].command_byte; i++ );
885
886      /* Check for unknown commands */
887      if ( pce_cd.command_buffer[0] != pce_cd_commands[i].command_byte )
888      {
889         logerror("Unrecognized command: %02X\n", pce_cd.command_buffer[0] );
890         if(pce_cd.command_buffer[0] == 0x03)
891            popmessage("CD command 0x03 issued (Request Sense), contact MESSdev");
892      }
893      assert( pce_cd.command_buffer[0] == pce_cd_commands[i].command_byte );
894
895      if ( pce_cd.command_buffer_index == pce_cd_commands[i].command_size )
896      {
897         (pce_cd_commands[i].command_handler)( machine );
898         pce_cd.command_buffer_index = 0;
899      }
900      else
901      {
902         pce_cd.scsi_REQ = 1;
903      }
904   }
905}
906
907static void pce_cd_handle_data_input( running_machine &machine )
908{
909   pce_state *state = machine.driver_data<pce_state>();
910   pce_cd_t &pce_cd = state->m_cd;
911   if ( pce_cd.scsi_CD )
912   {
913      /* Command / Status byte */
914      if ( pce_cd.scsi_REQ && pce_cd.scsi_ACK )
915      {
916         logerror( "status sent\n" );
917         pce_cd.scsi_REQ = 0;
918         pce_cd.status_sent = 1;
919      }
920
921      if ( ! pce_cd.scsi_REQ && ! pce_cd.scsi_ACK && pce_cd.status_sent )
922      {
923         pce_cd.status_sent = 0;
924         if ( pce_cd.message_after_status )
925         {
926            logerror( "message after status\n" );
927            pce_cd.message_after_status = 0;
928            pce_cd.scsi_MSG = pce_cd.scsi_REQ = 1;
929            pce_cd.regs[0x01] = 0;
930         }
931      }
932   }
933   else
934   {
935      /* Data */
936      if ( pce_cd.scsi_REQ && pce_cd.scsi_ACK )
937      {
938         pce_cd.scsi_REQ = 0;
939      }
940
941      if ( ! pce_cd.scsi_REQ && ! pce_cd.scsi_ACK )
942      {
943         if ( pce_cd.data_buffer_index == pce_cd.data_buffer_size )
944         {
945            pce_cd_set_irq_line( machine, PCE_CD_IRQ_TRANSFER_READY, CLEAR_LINE );
946            if ( pce_cd.data_transferred )
947            {
948               pce_cd.data_transferred = 0;
949               pce_cd_reply_status_byte( state, SCSI_STATUS_OK );
950               pce_cd_set_irq_line( machine, PCE_CD_IRQ_TRANSFER_DONE, ASSERT_LINE );
951            }
952         }
953         else
954         {
955            logerror("Transfer byte from offset %d\n", pce_cd.data_buffer_index);
956            pce_cd.regs[0x01] = pce_cd.data_buffer[pce_cd.data_buffer_index];
957            pce_cd.data_buffer_index++;
958            pce_cd.scsi_REQ = 1;
959         }
960      }
961   }
962}
963
964static void pce_cd_handle_message_output( pce_state *state )
965{
966   pce_cd_t &pce_cd = state->m_cd;
967   if ( pce_cd.scsi_REQ && pce_cd.scsi_ACK )
968   {
969      pce_cd.scsi_REQ = 0;
970   }
971}
972
973static void pce_cd_handle_message_input( pce_state *state )
974{
975   pce_cd_t &pce_cd = state->m_cd;
976   if ( pce_cd.scsi_REQ && pce_cd.scsi_ACK )
977   {
978      pce_cd.scsi_REQ = 0;
979      pce_cd.message_sent = 1;
980   }
981
982   if ( ! pce_cd.scsi_REQ && ! pce_cd.scsi_ACK && pce_cd.message_sent )
983   {
984      pce_cd.message_sent = 0;
985      pce_cd.scsi_BSY = 0;
986   }
987}
988
989/* Update internal CD statuses */
990static void pce_cd_update( running_machine &machine )
991{
992   pce_state *state = machine.driver_data<pce_state>();
993   pce_cd_t &pce_cd = state->m_cd;
994   /* Check for reset of CD unit */
995   if ( pce_cd.scsi_RST != pce_cd.scsi_last_RST )
996   {
997      if ( pce_cd.scsi_RST )
998      {
999         logerror("Performing CD reset\n");
1000         /* Reset internal data */
1001         pce_cd.scsi_BSY = pce_cd.scsi_SEL = pce_cd.scsi_CD = pce_cd.scsi_IO = 0;
1002         pce_cd.scsi_MSG = pce_cd.scsi_REQ = pce_cd.scsi_ATN = 0;
1003         pce_cd.cd_motor_on = 0;
1004         pce_cd.selected = 0;
1005         pce_cd.cdda_status = PCE_CD_CDDA_OFF;
1006         cdda_stop_audio( machine.device( "cdda" ) );
1007         pce_cd.adpcm_dma_timer->adjust(attotime::never); // stop ADPCM DMA here
1008      }
1009      pce_cd.scsi_last_RST = pce_cd.scsi_RST;
1010   }
1011
1012   /* Check if bus can be freed */
1013   if ( ! pce_cd.scsi_SEL && ! pce_cd.scsi_BSY && pce_cd.selected )
1014   {
1015      logerror( "freeing bus\n" );
1016      pce_cd.selected = 0;
1017      pce_cd.scsi_CD = pce_cd.scsi_MSG = pce_cd.scsi_IO = pce_cd.scsi_REQ = 0;
1018      pce_cd_set_irq_line( machine, PCE_CD_IRQ_TRANSFER_DONE, CLEAR_LINE );
1019   }
1020
1021   /* Select the CD device */
1022   if ( pce_cd.scsi_SEL )
1023   {
1024      if ( ! pce_cd.selected )
1025      {
1026         pce_cd.selected = 1;
1027         logerror("Setting CD in device selection\n");
1028         pce_cd.scsi_BSY = pce_cd.scsi_REQ = pce_cd.scsi_CD = 1;
1029         pce_cd.scsi_MSG = pce_cd.scsi_IO = 0;
1030      }
1031   }
1032
1033   if ( pce_cd.scsi_ATN )
1034   {
1035   }
1036   else
1037   {
1038      /* Check for data and pessage phases */
1039      if ( pce_cd.scsi_BSY )
1040      {
1041         if ( pce_cd.scsi_MSG )
1042         {
1043            /* message phase */
1044            if ( pce_cd.scsi_IO )
1045            {
1046               pce_cd_handle_message_input(state);
1047            }
1048            else
1049            {
1050               pce_cd_handle_message_output(state);
1051            }
1052         }
1053         else
1054         {
1055            /* data phase */
1056            if ( pce_cd.scsi_IO )
1057            {
1058               /* Reading data from target */
1059               pce_cd_handle_data_input( machine );
1060            }
1061            else
1062            {
1063               /* Sending data to target */
1064               pce_cd_handle_data_output( machine );
1065            }
1066         }
1067      }
1068   }
1069
1070   /* FIXME: presumably CD-DA needs an irq interface for this */
1071   if(cdda_audio_ended(machine.device("cdda")) && pce_cd.end_mark == 1)
1072   {
1073      switch(pce_cd.cdda_play_mode & 3)
1074      {
1075         case 1: cdda_start_audio( machine.device( "cdda" ), pce_cd.current_frame, pce_cd.end_frame - pce_cd.current_frame ); pce_cd.end_mark = 1; break; //play with repeat
1076         case 2: pce_cd_set_irq_line( machine, PCE_CD_IRQ_TRANSFER_DONE, ASSERT_LINE ); pce_cd.end_mark = 0; break; //irq when finished
1077         case 3: pce_cd.end_mark = 0; break; //play without repeat
1078      }
1079   }
1080}
1081
1082static void pce_cd_set_irq_line( running_machine &machine, int num, int state )
1083{
1084   pce_state *drvstate = machine.driver_data<pce_state>();
1085   pce_cd_t &pce_cd = drvstate->m_cd;
1086   switch( num )
1087   {
1088   case PCE_CD_IRQ_TRANSFER_DONE:
1089      if ( state == ASSERT_LINE )
1090      {
1091         pce_cd.regs[0x03] |= PCE_CD_IRQ_TRANSFER_DONE;
1092      }
1093      else
1094      {
1095         pce_cd.regs[0x03] &= ~ PCE_CD_IRQ_TRANSFER_DONE;
1096      }
1097      break;
1098   case PCE_CD_IRQ_TRANSFER_READY:
1099      if ( state == ASSERT_LINE )
1100      {
1101         pce_cd.regs[0x03] |= PCE_CD_IRQ_TRANSFER_READY;
1102      }
1103      else
1104      {
1105         pce_cd.regs[0x03] &= ~ PCE_CD_IRQ_TRANSFER_READY;
1106      }
1107      break;
1108   case PCE_CD_IRQ_SAMPLE_FULL_PLAY:
1109      if ( state == ASSERT_LINE )
1110      {
1111         pce_cd.regs[0x03] |= PCE_CD_IRQ_SAMPLE_FULL_PLAY;
1112         //printf("x %02x %02x\n",pce_cd.regs[0x02],pce_cd.regs[0x03]);
1113      }
1114      else
1115      {
1116         pce_cd.regs[0x03] &= ~ PCE_CD_IRQ_SAMPLE_FULL_PLAY;
1117      }
1118      break;
1119   case PCE_CD_IRQ_SAMPLE_HALF_PLAY:
1120      if ( state == ASSERT_LINE )
1121      {
1122         pce_cd.regs[0x03] |= PCE_CD_IRQ_SAMPLE_HALF_PLAY;
1123         //printf("y %02x %02x\n",pce_cd.regs[0x02],pce_cd.regs[0x03]);
1124      }
1125      else
1126      {
1127         pce_cd.regs[0x03] &= ~ PCE_CD_IRQ_SAMPLE_HALF_PLAY;
1128      }
1129      break;
1130   default:
1131      break;
1132   }
1133
1134   if ( pce_cd.regs[0x02] & pce_cd.regs[0x03] & ( PCE_CD_IRQ_TRANSFER_DONE | PCE_CD_IRQ_TRANSFER_READY | PCE_CD_IRQ_SAMPLE_HALF_PLAY | PCE_CD_IRQ_SAMPLE_FULL_PLAY) )
1135   {
1136      cputag_set_input_line(machine, "maincpu", 1, ASSERT_LINE );
1137   }
1138   else
1139   {
1140      cputag_set_input_line(machine, "maincpu", 1, CLEAR_LINE );
1141   }
1142}
1143
1144static TIMER_CALLBACK( pce_cd_data_timer_callback )
1145{
1146   pce_state *state = machine.driver_data<pce_state>();
1147   pce_cd_t &pce_cd = state->m_cd;
1148   if ( pce_cd.data_buffer_index == pce_cd.data_buffer_size )
1149   {
1150      /* Read next data sector */
1151      logerror("read sector %d\n", pce_cd.current_frame );
1152      if ( ! cdrom_read_data( pce_cd.cd, pce_cd.current_frame, pce_cd.data_buffer, CD_TRACK_MODE1 ) )
1153      {
1154         logerror("Mode1 CD read failed for frame #%d\n", pce_cd.current_frame );
1155      }
1156      else
1157      {
1158         logerror("Succesfully read mode1 frame #%d\n", pce_cd.current_frame );
1159      }
1160
1161      pce_cd.data_buffer_index = 0;
1162      pce_cd.data_buffer_size = 2048;
1163      pce_cd.current_frame++;
1164
1165      pce_cd.scsi_IO = 1;
1166      pce_cd.scsi_CD = 0;
1167
1168      if ( pce_cd.current_frame == pce_cd.end_frame )
1169      {
1170         /* We are done, disable the timer */
1171         logerror("Last frame read from CD\n");
1172         pce_cd.data_transferred = 1;
1173         pce_cd.data_timer->adjust(attotime::never);
1174      }
1175      else
1176      {
1177         pce_cd.data_transferred = 0;
1178      }
1179   }
1180}
1181
1182static void pce_cd_init( running_machine &machine )
1183{
1184   pce_state *state = machine.driver_data<pce_state>();
1185   pce_cd_t &pce_cd = state->m_cd;
1186   device_t *device;
1187
1188   /* Initialize pce_cd struct */
1189   memset( &pce_cd, 0, sizeof(pce_cd) );
1190
1191   /* Initialize BRAM */
1192   pce_cd.bram = auto_alloc_array(machine, UINT8, PCE_BRAM_SIZE * 2 );
1193   memset( pce_cd.bram, 0, PCE_BRAM_SIZE );
1194   memset( pce_cd.bram + PCE_BRAM_SIZE, 0xFF, PCE_BRAM_SIZE );
1195   pce_cd.bram_locked = 1;
1196   pce_set_cd_bram(machine);
1197
1198   /* set up adpcm related things */
1199   pce_cd.adpcm_ram = auto_alloc_array(machine, UINT8, PCE_ADPCM_RAM_SIZE );
1200   memset( pce_cd.adpcm_ram, 0, PCE_ADPCM_RAM_SIZE );
1201   pce_cd.adpcm_clock_divider = 1;
1202   msm5205_change_clock_w(machine.device("msm5205"), (PCE_CD_CLOCK / 6) / pce_cd.adpcm_clock_divider);
1203
1204   /* Set up cd command buffer */
1205   pce_cd.command_buffer = auto_alloc_array(machine, UINT8, PCE_CD_COMMAND_BUFFER_SIZE );
1206   memset( pce_cd.command_buffer, 0, PCE_CD_COMMAND_BUFFER_SIZE );
1207   pce_cd.command_buffer_index = 0;
1208
1209   /* Set up Arcade Card RAM buffer */
1210   pce_cd.acard_ram = auto_alloc_array(machine, UINT8, PCE_ACARD_RAM_SIZE );
1211   memset( pce_cd.acard_ram, 0, PCE_ACARD_RAM_SIZE );
1212
1213   pce_cd.data_buffer = auto_alloc_array(machine, UINT8, 8192 );
1214   memset( pce_cd.data_buffer, 0, 8192 );
1215   pce_cd.data_buffer_size = 0;
1216   pce_cd.data_buffer_index = 0;
1217
1218   pce_cd.subcode_buffer = auto_alloc_array(machine, UINT8, 96 );
1219
1220   device = machine.device("cdrom");
1221   if ( device )
1222   {
1223      pce_cd.cd = cd_get_cdrom_file(device);
1224      if ( pce_cd.cd )
1225      {
1226         pce_cd.toc = cdrom_get_toc( pce_cd.cd );
1227         cdda_set_cdrom( machine.device("cdda"), pce_cd.cd );
1228         pce_cd.last_frame = cdrom_get_track_start( pce_cd.cd, cdrom_get_last_track( pce_cd.cd ) - 1 );
1229         pce_cd.last_frame += pce_cd.toc->tracks[ cdrom_get_last_track( pce_cd.cd ) - 1 ].frames;
1230         pce_cd.end_frame = pce_cd.last_frame;
1231      }
1232   }
1233
1234   pce_cd.data_timer = machine.scheduler().timer_alloc(FUNC(pce_cd_data_timer_callback));
1235   pce_cd.data_timer->adjust(attotime::never);
1236   pce_cd.adpcm_dma_timer = machine.scheduler().timer_alloc(FUNC(pce_cd_adpcm_dma_timer_callback));
1237   pce_cd.adpcm_dma_timer->adjust(attotime::never);
1238
1239   pce_cd.cdda_fadeout_timer = machine.scheduler().timer_alloc(FUNC(pce_cd_cdda_fadeout_callback));
1240   pce_cd.cdda_fadeout_timer->adjust(attotime::never);
1241   pce_cd.cdda_fadein_timer = machine.scheduler().timer_alloc(FUNC(pce_cd_cdda_fadein_callback));
1242   pce_cd.cdda_fadein_timer->adjust(attotime::never);
1243
1244   pce_cd.adpcm_fadeout_timer = machine.scheduler().timer_alloc(FUNC(pce_cd_adpcm_fadeout_callback));
1245   pce_cd.adpcm_fadeout_timer->adjust(attotime::never);
1246   pce_cd.adpcm_fadein_timer = machine.scheduler().timer_alloc(FUNC(pce_cd_adpcm_fadein_callback));
1247   pce_cd.adpcm_fadein_timer->adjust(attotime::never);
1248}
1249
1250WRITE8_HANDLER( pce_cd_bram_w )
1251{
1252   pce_state *state = space->machine().driver_data<pce_state>();
1253   pce_cd_t &pce_cd = state->m_cd;
1254   if ( ! pce_cd.bram_locked )
1255   {
1256      pce_cd.bram[ offset ] = data;
1257   }
1258}
1259
1260static void pce_cd_set_adpcm_ram_byte(running_machine &machine, UINT8 val)
1261{
1262   pce_state *state = machine.driver_data<pce_state>();
1263   pce_cd_t &pce_cd = state->m_cd;
1264   if(pce_cd.adpcm_write_buf > 0)
1265   {
1266      pce_cd.adpcm_write_buf--;
1267   }
1268   else
1269   {
1270      pce_cd.adpcm_ram[pce_cd.adpcm_write_ptr] = val;
1271      pce_cd.adpcm_write_ptr = ((pce_cd.adpcm_write_ptr + 1) & 0xffff);
1272      //TODO: length + 1
1273   }
1274}
1275
1276static TIMER_CALLBACK( pce_cd_cdda_fadeout_callback )
1277{
1278   pce_state *state = machine.driver_data<pce_state>();
1279   pce_cd_t &pce_cd = state->m_cd;
1280   pce_cd.cdda_volume-= 0.1;
1281
1282   if(pce_cd.cdda_volume <= 0)
1283   {
1284      pce_cd.cdda_volume = 0.0;
1285      cdda_set_volume(machine.device("cdda"), 0.0);
1286      pce_cd.cdda_fadeout_timer->adjust(attotime::never);
1287   }
1288   else
1289   {
1290      cdda_set_volume(machine.device("cdda"), pce_cd.cdda_volume);
1291      pce_cd.cdda_fadeout_timer->adjust(attotime::from_usec(param), param);
1292   }
1293}
1294
1295static TIMER_CALLBACK( pce_cd_cdda_fadein_callback )
1296{
1297   pce_state *state = machine.driver_data<pce_state>();
1298   pce_cd_t &pce_cd = state->m_cd;
1299   pce_cd.cdda_volume+= 0.1;
1300
1301   if(pce_cd.cdda_volume >= 100.0)
1302   {
1303      pce_cd.cdda_volume = 100.0;
1304      cdda_set_volume(machine.device("cdda"), 100.0);
1305      pce_cd.cdda_fadein_timer->adjust(attotime::never);
1306   }
1307   else
1308   {
1309      cdda_set_volume(machine.device("cdda"), pce_cd.cdda_volume);
1310      pce_cd.cdda_fadein_timer->adjust(attotime::from_usec(param), param);
1311   }
1312}
1313
1314static TIMER_CALLBACK( pce_cd_adpcm_fadeout_callback )
1315{
1316   pce_state *state = machine.driver_data<pce_state>();
1317   pce_cd_t &pce_cd = state->m_cd;
1318   pce_cd.adpcm_volume-= 0.1;
1319
1320   if(pce_cd.adpcm_volume <= 0)
1321   {
1322      pce_cd.adpcm_volume = 0.0;
1323      msm5205_set_volume(machine.device("msm5205"), 0.0);
1324      pce_cd.adpcm_fadeout_timer->adjust(attotime::never);
1325   }
1326   else
1327   {
1328      msm5205_set_volume(machine.device("msm5205"), pce_cd.adpcm_volume);
1329      pce_cd.adpcm_fadeout_timer->adjust(attotime::from_usec(param), param);
1330   }
1331}
1332
1333static TIMER_CALLBACK( pce_cd_adpcm_fadein_callback )
1334{
1335   pce_state *state = machine.driver_data<pce_state>();
1336   pce_cd_t &pce_cd = state->m_cd;
1337   pce_cd.adpcm_volume+= 0.1;
1338
1339   if(pce_cd.adpcm_volume >= 100.0)
1340   {
1341      pce_cd.adpcm_volume = 100.0;
1342      msm5205_set_volume(machine.device("msm5205"), 100.0);
1343      pce_cd.adpcm_fadein_timer->adjust(attotime::never);
1344   }
1345   else
1346   {
1347      msm5205_set_volume(machine.device("msm5205"), pce_cd.adpcm_volume);
1348      pce_cd.adpcm_fadein_timer->adjust(attotime::from_usec(param), param);
1349   }
1350}
1351
1352
1353WRITE8_HANDLER( pce_cd_intf_w )
1354{
1355   pce_state *state = space->machine().driver_data<pce_state>();
1356   pce_cd_t &pce_cd = state->m_cd;
1357   pce_cd_update(space->machine());
1358
1359   if(offset & 0x200 && state->m_sys3_card && state->m_acard) // route Arcade Card handling ports
1360      return pce_cd_acard_w(space,offset,data);
1361
1362   logerror("%04X: write to CD interface offset %02X, data %02X\n", cpu_get_pc(&space->device()), offset, data );
1363
1364   switch( offset & 0xf )
1365   {
1366   case 0x00:   /* CDC status */
1367      /* select device (which bits??) */
1368      pce_cd.scsi_SEL = 1;
1369      pce_cd_update(space->machine());
1370      pce_cd.scsi_SEL = 0;
1371      pce_cd.adpcm_dma_timer->adjust(attotime::never); // stop ADPCM DMA here
1372      /* any write here clears CD transfer irqs */
1373      pce_cd.regs[0x03] &= ~0x70;
1374      cputag_set_input_line(space->machine(), "maincpu", 1, CLEAR_LINE );
1375      break;
1376   case 0x01:   /* CDC command / status / data */
1377      break;
1378   case 0x02:   /* ADPCM / CD control / IRQ enable/disable */
1379            /* bit 6 - transfer ready irq */
1380            /* bit 5 - transfer done irq */
1381            /* bit 4 - ?? irq */
1382            /* bit 3 - ?? irq */
1383            /* bit 2 - ?? irq */
1384      pce_cd.scsi_ACK = data & 0x80;
1385      /* Don't set or reset any irq lines, but just verify the current state */
1386      pce_cd_set_irq_line( space->machine(), 0, 0 );
1387      break;
1388   case 0x03:   /* BRAM lock / CD status / IRQ - Read Only register */
1389      break;
1390   case 0x04:   /* CD reset */
1391      pce_cd.scsi_RST = data & 0x02;
1392      break;
1393   case 0x05:   /* Convert PCM data / PCM data */
1394   case 0x06:   /* PCM data */
1395      break;
1396   case 0x07:   /* BRAM unlock / CD status */
1397      if ( data & 0x80 )
1398      {
1399         pce_cd.bram_locked = 0;
1400         pce_set_cd_bram(space->machine());
1401      }
1402      break;
1403   case 0x08:   /* ADPCM address (LSB) / CD data */
1404      break;
1405   case 0x09:   /* ADPCM address (MSB) */
1406      break;
1407   case 0x0A:   /* ADPCM RAM data port */
1408      pce_cd_set_adpcm_ram_byte(space->machine(), data);
1409      break;
1410   case 0x0B:   /* ADPCM DMA control */
1411      if ( data & 0x03 )
1412      {
1413         /* Start CD to ADPCM transfer */
1414         pce_cd.adpcm_dma_timer->adjust(attotime::from_hz( PCE_CD_DATA_FRAMES_PER_SECOND * 2048 ), 0, attotime::from_hz( PCE_CD_DATA_FRAMES_PER_SECOND * 2048 ) );
1415         pce_cd.regs[0x0c] |= 4;
1416      }
1417      break;
1418   case 0x0C:   /* ADPCM status */
1419      break;
1420   case 0x0D:   /* ADPCM address control */
1421      if ( ( pce_cd.regs[0x0D] & 0x80 ) && ! ( data & 0x80 ) ) // ADPCM reset
1422      {
1423         /* Reset ADPCM hardware */
1424         pce_cd.adpcm_read_ptr = 0;
1425         pce_cd.adpcm_write_ptr = 0;
1426         pce_cd.msm_start_addr = 0;
1427         pce_cd.msm_end_addr = 0;
1428         pce_cd.msm_half_addr = 0;
1429         pce_cd.msm_nibble = 0;
1430         adpcm_stop(space->machine());
1431         msm5205_reset_w( space->machine().device( "msm5205"), 1 );
1432      }
1433
1434      if(data & 0x20)
1435         pce_cd.msm_half_addr = (pce_cd.adpcm_read_ptr + (pce_cd.adpcm_length / ((data & 0x40) ? 2 : 1))) & 0xffff;
1436
1437      if ( ( data & 0x40) && ((pce_cd.regs[0x0D] & 0x40) == 0) ) // ADPCM play
1438      {
1439         pce_cd.msm_start_addr = (pce_cd.adpcm_read_ptr);
1440         pce_cd.msm_end_addr = (pce_cd.adpcm_read_ptr + pce_cd.adpcm_length) & 0xffff;
1441         pce_cd.msm_nibble = 0;
1442         adpcm_play(space->machine());
1443         msm5205_reset_w( space->machine().device( "msm5205"), 0 );
1444
1445         //popmessage("%08x %08x",pce_cd.adpcm_read_ptr,pce_cd.adpcm_length);
1446      }
1447      else if ( (data & 0x40) == 0 )
1448      {
1449         /* used by Buster Bros to cancel an in-flight sample */
1450         adpcm_stop(space->machine());
1451         msm5205_reset_w( space->machine().device( "msm5205"), 1 );
1452      }
1453
1454      if ( data & 0x10 ) //ADPCM set length
1455      {
1456         pce_cd.adpcm_length = ( pce_cd.regs[0x09] << 8 ) | pce_cd.regs[0x08];
1457      }
1458      if ( data & 0x08 ) //ADPCM set read address
1459      {
1460         pce_cd.adpcm_read_ptr = ( pce_cd.regs[0x09] << 8 ) | pce_cd.regs[0x08];
1461         pce_cd.adpcm_read_buf = 2;
1462      }
1463      if ( ( data & 0x02 ) == 0x02 ) //ADPCM set write address
1464      {
1465         pce_cd.adpcm_write_ptr = ( pce_cd.regs[0x09] << 8 ) | pce_cd.regs[0x08];
1466         pce_cd.adpcm_write_buf = data & 1;
1467      }
1468      break;
1469   case 0x0E:   /* ADPCM playback rate */
1470      pce_cd.adpcm_clock_divider = 0x10 - ( data & 0x0F );
1471      msm5205_change_clock_w(space->machine().device("msm5205"), (PCE_CD_CLOCK / 6) / pce_cd.adpcm_clock_divider);
1472      break;
1473   case 0x0F:   /* ADPCM and CD audio fade timer */
1474      /* TODO: timers needs HW tests */
1475      if(pce_cd.regs[0xf] != data)
1476      {
1477         switch(data & 0xf)
1478         {
1479            case 0x00: //CD-DA / ADPCM enable (100 msecs)
1480               pce_cd.cdda_volume = 0.0;
1481               pce_cd.cdda_fadein_timer->adjust(attotime::from_usec(100), 100);
1482               pce_cd.adpcm_volume = 0.0;
1483               pce_cd.adpcm_fadein_timer->adjust(attotime::from_usec(100), 100);
1484               pce_cd.cdda_fadeout_timer->adjust(attotime::never);
1485               pce_cd.adpcm_fadeout_timer->adjust(attotime::never);
1486               break;
1487            case 0x01: //CD-DA enable (100 msecs)
1488               pce_cd.cdda_volume = 0.0;
1489               pce_cd.cdda_fadein_timer->adjust(attotime::from_usec(100), 100);
1490               pce_cd.cdda_fadeout_timer->adjust(attotime::never);
1491               break;
1492            case 0x08: //CD-DA short (1500 msecs) fade out / ADPCM enable
1493               pce_cd.cdda_volume = 100.0;
1494               pce_cd.cdda_fadeout_timer->adjust(attotime::from_usec(1500), 1500);
1495               pce_cd.adpcm_volume = 0.0;
1496               pce_cd.adpcm_fadein_timer->adjust(attotime::from_usec(100), 100);
1497               pce_cd.cdda_fadein_timer->adjust(attotime::never);
1498               pce_cd.adpcm_fadeout_timer->adjust(attotime::never);
1499               break;
1500            case 0x09: //CD-DA long (5000 msecs) fade out
1501               pce_cd.cdda_volume = 100.0;
1502               pce_cd.cdda_fadeout_timer->adjust(attotime::from_usec(5000), 5000);
1503               pce_cd.cdda_fadein_timer->adjust(attotime::never);
1504               break;
1505            case 0x0a: //ADPCM long (5000 msecs) fade out
1506               pce_cd.adpcm_volume = 100.0;
1507               pce_cd.adpcm_fadeout_timer->adjust(attotime::from_usec(5000), 5000);
1508               pce_cd.adpcm_fadein_timer->adjust(attotime::never);
1509               break;
1510            case 0x0c: //CD-DA short (1500 msecs) fade out / ADPCM enable
1511               pce_cd.cdda_volume = 100.0;
1512               pce_cd.cdda_fadeout_timer->adjust(attotime::from_usec(1500), 1500);
1513               pce_cd.adpcm_volume = 0.0;
1514               pce_cd.adpcm_fadein_timer->adjust(attotime::from_usec(100), 100);
1515               pce_cd.cdda_fadein_timer->adjust(attotime::never);
1516               pce_cd.adpcm_fadeout_timer->adjust(attotime::never);
1517               break;
1518            case 0x0d: //CD-DA short (1500 msecs) fade out
1519               pce_cd.cdda_volume = 100.0;
1520               pce_cd.cdda_fadeout_timer->adjust(attotime::from_usec(1500), 1500);
1521               pce_cd.cdda_fadein_timer->adjust(attotime::never);
1522               break;
1523            case 0x0e: //ADPCM short (1500 msecs) fade out
1524               pce_cd.adpcm_volume = 100.0;
1525               pce_cd.adpcm_fadeout_timer->adjust(attotime::from_usec(1500), 1500);
1526               pce_cd.adpcm_fadein_timer->adjust(attotime::never);
1527               break;
1528            default:
1529               popmessage("CD-DA / ADPCM Fade effect mode %02x, contact MESSdev",data & 0x0f);
1530               break;
1531         }
1532      }
1533      break;
1534   default:
1535      return;
1536   }
1537   pce_cd.regs[offset & 0xf] = data;
1538   pce_cd_update(space->machine());
1539}
1540
1541static TIMER_CALLBACK( pce_cd_clear_ack )
1542{
1543   pce_state *state = machine.driver_data<pce_state>();
1544   pce_cd_t &pce_cd = state->m_cd;
1545   pce_cd_update(machine);
1546   pce_cd.scsi_ACK = 0;
1547   pce_cd_update(machine);
1548   if ( pce_cd.scsi_CD )
1549   {
1550      pce_cd.regs[0x0B] &= 0xFE;
1551   }
1552}
1553
1554static UINT8 pce_cd_get_cd_data_byte(running_machine &machine)
1555{
1556   pce_state *state = machine.driver_data<pce_state>();
1557   pce_cd_t &pce_cd = state->m_cd;
1558   UINT8 data = pce_cd.regs[0x01];
1559   if ( pce_cd.scsi_REQ && ! pce_cd.scsi_ACK && ! pce_cd.scsi_CD )
1560   {
1561      if ( pce_cd.scsi_IO )
1562      {
1563         pce_cd.scsi_ACK = 1;
1564         machine.scheduler().timer_set(machine.device<cpu_device>("maincpu")->cycles_to_attotime(15), FUNC(pce_cd_clear_ack));
1565      }
1566   }
1567   return data;
1568}
1569
1570
1571static TIMER_CALLBACK( pce_cd_adpcm_dma_timer_callback )
1572{
1573   pce_state *state = machine.driver_data<pce_state>();
1574   pce_cd_t &pce_cd = state->m_cd;
1575   if ( pce_cd.scsi_REQ && ! pce_cd.scsi_ACK && ! pce_cd.scsi_CD && pce_cd.scsi_IO  )
1576   {
1577      pce_cd.adpcm_ram[pce_cd.adpcm_write_ptr] = pce_cd_get_cd_data_byte(machine);
1578      pce_cd.adpcm_write_ptr = ( pce_cd.adpcm_write_ptr + 1 ) & 0xFFFF;
1579
1580      pce_cd.regs[0x0c] &= ~4;
1581   }
1582}
1583
1584static UINT8 pce_cd_get_adpcm_ram_byte(running_machine &machine)
1585{
1586   pce_state *state = machine.driver_data<pce_state>();
1587   pce_cd_t &pce_cd = state->m_cd;
1588   if(pce_cd.adpcm_read_buf > 0)
1589   {
1590      pce_cd.adpcm_read_buf--;
1591      return 0;
1592   }
1593   else
1594   {
1595      UINT8 res;
1596
1597      res = pce_cd.adpcm_ram[pce_cd.adpcm_read_ptr];
1598      pce_cd.adpcm_read_ptr = ((pce_cd.adpcm_read_ptr + 1) & 0xffff);
1599
1600      return res;
1601   }
1602}
1603
1604READ8_HANDLER( pce_cd_intf_r )
1605{
1606   pce_state *state = space->machine().driver_data<pce_state>();
1607   pce_cd_t &pce_cd = state->m_cd;
1608   UINT8 data = pce_cd.regs[offset & 0x0F];
1609
1610   pce_cd_update(space->machine());
1611
1612   if(offset & 0x200 && state->m_sys3_card && state->m_acard) // route Arcade Card handling ports
1613      return pce_cd_acard_r(space,offset);
1614
1615   logerror("%04X: read from CD interface offset %02X\n", cpu_get_pc(&space->device()), offset );
1616
1617   if((offset & 0xc0) == 0xc0 && state->m_sys3_card) //System 3 Card header handling
1618   {
1619      switch(offset & 0xcf)
1620      {
1621         case 0xc1: return 0xaa;
1622         case 0xc2: return 0x55;
1623         case 0xc3: return 0x00;
1624         case 0xc5: return (state->m_sys3_card & 2) ? 0x55 : 0xaa;
1625         case 0xc6: return (state->m_sys3_card & 2) ? 0xaa : 0x55;
1626         case 0xc7: return 0x03;
1627      }
1628   }
1629
1630   switch( offset & 0xf )
1631   {
1632   case 0x00:   /* CDC status */
1633      data &= 0x07;
1634      data |= pce_cd.scsi_BSY ? 0x80 : 0;
1635      data |= pce_cd.scsi_REQ ? 0x40 : 0;
1636      data |= pce_cd.scsi_MSG ? 0x20 : 0;
1637      data |= pce_cd.scsi_CD  ? 0x10 : 0;
1638      data |= pce_cd.scsi_IO  ? 0x08 : 0;
1639      break;
1640   case 0x01:   /* CDC command / status / data */
1641      break;
1642   case 0x02:   /* ADPCM / CD control */
1643      break;
1644   case 0x03:   /* BRAM lock / CD status */
1645      /* bit 4 set when CD motor is on */
1646      /* bit 2 set when less than half of the ADPCM data is remaining ?? */
1647      pce_cd.bram_locked = 1;
1648      pce_set_cd_bram(space->machine());
1649      data = data & 0x6E;
1650      data |= ( pce_cd.cd_motor_on ? 0x10 : 0 );
1651      pce_cd.regs[0x03] ^= 0x02;         /* TODO: get rid of this hack */
1652      break;
1653   case 0x04:   /* CD reset */
1654      break;
1655   case 0x05:   /* Convert PCM data / PCM data */
1656   case 0x06:   /* PCM data */
1657      break;
1658   case 0x07:   /* BRAM unlock / CD status */
1659      data = ( pce_cd.bram_locked ? ( data & 0x7F ) : ( data | 0x80 ) );
1660      break;
1661   case 0x08:   /* ADPCM address (LSB) / CD data */
1662      data = pce_cd_get_cd_data_byte(space->machine());
1663      break;
1664   case 0x0A:   /* ADPCM RAM data port */
1665      data = pce_cd_get_adpcm_ram_byte(space->machine());
1666      break;
1667   case 0x0B:   /* ADPCM DMA control */
1668      break;
1669   case 0x0C:   /* ADPCM status */
1670      break;
1671   case 0x0D:   /* ADPCM address control */
1672      break;
1673   /* These are read-only registers */
1674   case 0x09:   /* ADPCM address (MSB) */
1675   case 0x0E:   /* ADPCM playback rate */
1676   case 0x0F:   /* ADPCM and CD audio fade timer */
1677      return 0;
1678   default:
1679      data = 0xFF;
1680      break;
1681   }
1682
1683   return data;
1684}
1685
1686
1687/*
1688
1689PC Engine Arcade Card emulation
1690
1691*/
1692
1693READ8_HANDLER( pce_cd_acard_r )
1694{
1695   pce_state *state = space->machine().driver_data<pce_state>();
1696   pce_cd_t &pce_cd = state->m_cd;
1697   UINT8 r_num;
1698
1699   if((offset & 0x2e0) == 0x2e0)
1700   {
1701      switch(offset & 0x2ef)
1702      {
1703         case 0x2e0: return (pce_cd.acard_shift >> 0)  & 0xff;
1704         case 0x2e1: return (pce_cd.acard_shift >> 8)  & 0xff;
1705         case 0x2e2: return (pce_cd.acard_shift >> 16) & 0xff;
1706         case 0x2e3: return (pce_cd.acard_shift >> 24) & 0xff;
1707         case 0x2e4: return (pce_cd.acard_shift_reg);
1708         case 0x2e5: return pce_cd.acard_latch;
1709         case 0x2ee: return 0x10;
1710         case 0x2ef: return 0x51;
1711      }
1712
1713      return 0;
1714   }
1715
1716   r_num = (offset & 0x30) >> 4;
1717
1718   switch(offset & 0x0f)
1719   {
1720      case 0x00:
1721      case 0x01:
1722      {
1723         UINT8 res;
1724         if(pce_cd.acard_ctrl[r_num] & 2)
1725            res = pce_cd.acard_ram[(pce_cd.acard_base_addr[r_num] + pce_cd.acard_addr_offset[r_num]) & 0x1fffff];
1726         else
1727            res = pce_cd.acard_ram[pce_cd.acard_base_addr[r_num] & 0x1fffff];
1728
1729         if(pce_cd.acard_ctrl[r_num] & 0x1)
1730         {
1731            if(pce_cd.acard_ctrl[r_num] & 0x10)
1732            {
1733               pce_cd.acard_base_addr[r_num] += pce_cd.acard_addr_inc[r_num];
1734               pce_cd.acard_base_addr[r_num] &= 0xffffff;
1735            }
1736            else
1737            {
1738               pce_cd.acard_addr_offset[r_num] += pce_cd.acard_addr_inc[r_num];
1739            }
1740         }
1741
1742         return res;
1743      }
1744      case 0x02: return (pce_cd.acard_base_addr[r_num] >> 0) & 0xff;
1745      case 0x03: return (pce_cd.acard_base_addr[r_num] >> 8) & 0xff;
1746      case 0x04: return (pce_cd.acard_base_addr[r_num] >> 16) & 0xff;
1747      case 0x05: return (pce_cd.acard_addr_offset[r_num] >> 0) & 0xff;
1748      case 0x06: return (pce_cd.acard_addr_offset[r_num] >> 8) & 0xff;
1749      case 0x07: return (pce_cd.acard_addr_inc[r_num] >> 0) & 0xff;
1750      case 0x08: return (pce_cd.acard_addr_inc[r_num] >> 8) & 0xff;
1751      case 0x09: return pce_cd.acard_ctrl[r_num];
1752      default:   return 0;
1753   }
1754
1755   return 0;
1756}
1757
1758WRITE8_HANDLER( pce_cd_acard_w )
1759{
1760   pce_state *state = space->machine().driver_data<pce_state>();
1761   pce_cd_t &pce_cd = state->m_cd;
1762   UINT8 w_num;
1763
1764   if((offset & 0x2e0) == 0x2e0)
1765   {
1766      switch(offset & 0x0f)
1767      {
1768         case 0: pce_cd.acard_shift = (data & 0xff) | (pce_cd.acard_shift & 0xffffff00); break;
1769         case 1: pce_cd.acard_shift = (data << 8)   | (pce_cd.acard_shift & 0xffff00ff); break;
1770         case 2: pce_cd.acard_shift = (data << 16)  | (pce_cd.acard_shift & 0xff00ffff); break;
1771         case 3: pce_cd.acard_shift = (data << 24)  | (pce_cd.acard_shift & 0x00ffffff); break;
1772         case 4:
1773            {
1774               pce_cd.acard_shift_reg = data & 0x0f;
1775
1776               if(pce_cd.acard_shift_reg != 0)
1777               {
1778                   pce_cd.acard_shift = (pce_cd.acard_shift_reg < 8) ?
1779                                 (pce_cd.acard_shift << pce_cd.acard_shift_reg)
1780                                 : (pce_cd.acard_shift >> (16 - pce_cd.acard_shift_reg));
1781               }
1782            }
1783            break;
1784         case 5: pce_cd.acard_latch = data; break;
1785      }
1786   }
1787   else
1788   {
1789      w_num = (offset & 0x30) >> 4;
1790
1791      switch(offset & 0x0f)
1792      {
1793         case 0x00:
1794         case 0x01:
1795            if(pce_cd.acard_ctrl[w_num] & 2)
1796               pce_cd.acard_ram[(pce_cd.acard_base_addr[w_num] + pce_cd.acard_addr_offset[w_num]) & 0x1fffff] = data;
1797            else
1798               pce_cd.acard_ram[pce_cd.acard_base_addr[w_num] & 0x1FFFFF] = data;
1799
1800            if(pce_cd.acard_ctrl[w_num] & 0x1)
1801            {
1802               if(pce_cd.acard_ctrl[w_num] & 0x10)
1803               {
1804                  pce_cd.acard_base_addr[w_num] += pce_cd.acard_addr_inc[w_num];
1805                  pce_cd.acard_base_addr[w_num] &= 0xffffff;
1806               }
1807               else
1808               {
1809                  pce_cd.acard_addr_offset[w_num] += pce_cd.acard_addr_inc[w_num];
1810               }
1811            }
1812
1813            break;
1814
1815         case 0x02: pce_cd.acard_base_addr[w_num] = (data & 0xff) | (pce_cd.acard_base_addr[w_num] & 0xffff00);   break;
1816         case 0x03: pce_cd.acard_base_addr[w_num] = (data << 8) | (pce_cd.acard_base_addr[w_num] & 0xff00ff);      break;
1817         case 0x04: pce_cd.acard_base_addr[w_num] = (data << 16) | (pce_cd.acard_base_addr[w_num] & 0x00ffff);   break;
1818         case 0x05: pce_cd.acard_addr_offset[w_num] = (data & 0xff) | (pce_cd.acard_addr_offset[w_num] & 0xff00);   break;
1819         case 0x06:
1820            pce_cd.acard_addr_offset[w_num] = (data << 8) | (pce_cd.acard_addr_offset[w_num] & 0x00ff);
1821
1822            if((pce_cd.acard_ctrl[w_num] & 0x60) == 0x40)
1823            {
1824               pce_cd.acard_base_addr[w_num] += pce_cd.acard_addr_offset[w_num] + ((pce_cd.acard_ctrl[w_num] & 0x08) ? 0xff0000 : 0);
1825               pce_cd.acard_base_addr[w_num] &= 0xffffff;
1826            }
1827            break;
1828         case 0x07: pce_cd.acard_addr_inc[w_num] = (data & 0xff) | (pce_cd.acard_addr_inc[w_num] & 0xff00);      break;
1829         case 0x08: pce_cd.acard_addr_inc[w_num] = (data << 8) | (pce_cd.acard_addr_inc[w_num] & 0x00ff);         break;
1830         case 0x09: pce_cd.acard_ctrl[w_num] = data & 0x7f;                                    break;
1831         case 0x0a:
1832            if((pce_cd.acard_ctrl[w_num] & 0x60) == 0x60)
1833            {
1834               pce_cd.acard_base_addr[w_num] += pce_cd.acard_addr_offset[w_num];
1835               pce_cd.acard_base_addr[w_num] &= 0xffffff;
1836            }
1837            break;
1838      }
1839   }
1840}
1841
1842READ8_HANDLER( pce_cd_acard_wram_r )
1843{
1844   return pce_cd_intf_r(space,0x200 | (offset & 0x6000) >> 9);
1845}
1846
1847WRITE8_HANDLER( pce_cd_acard_wram_w )
1848{
1849   pce_cd_intf_w(space,0x200 | (offset & 0x6000) >> 9,data);
1850}
1851
src/mess/machine/atarifdc.c
r11460r11461
1/***************************************************************************
2
3    Atari 400/800
4
5    Floppy Disk Controller code
6
7    Juergen Buchmueller, June 1998
8
9***************************************************************************/
10
11#include <ctype.h>
12
13#include "emu.h"
14#include "cpu/m6502/m6502.h"
15#include "includes/atari.h"
16#include "ataridev.h"
17#include "sound/pokey.h"
18#include "machine/6821pia.h"
19#include "imagedev/flopdrv.h"
20#include "image.h"
21
22#define VERBOSE_SERIAL   0
23#define VERBOSE_CHKSUM   0
24
25typedef struct _atari_drive atari_drive;
26struct _atari_drive
27{
28   UINT8 *image;      /* malloc'd image */
29   int type;         /* type of image (XFD, ATR, DSK) */
30   int mode;         /* 0 read only, != 0 read/write */
31   int density;      /* 0 SD, 1 MD, 2 DD */
32   int header_skip;   /* number of bytes in format header */
33   int tracks;       /* number of tracks (35,40,77,80) */
34   int heads;         /* number of heads (1,2) */
35   int spt;         /* sectors per track (18,26) */
36   int seclen;       /* sector length (128,256) */
37   int bseclen;      /* boot sector length (sectors 1..3) */
38   int sectors;      /* total sectors, ie. tracks x heads x spt */
39};
40
41typedef struct _atari_fdc_t atari_fdc_t;
42struct _atari_fdc_t
43{
44   int  serout_count;
45   int  serout_offs;
46   UINT8 serout_buff[512];
47   UINT8 serout_chksum;
48   int  serout_delay;
49
50   int  serin_count;
51   int  serin_offs;
52   UINT8 serin_buff[512];
53   UINT8 serin_chksum;
54   int  serin_delay;
55
56   atari_drive drv[4];
57};
58
59/*************************************
60 *
61 *  Disk stuff
62 *
63 *************************************/
64
65#define FORMAT_XFD   0
66#define FORMAT_ATR   1
67#define FORMAT_DSK   2
68
69/*****************************************************************************
70    INLINE FUNCTIONS
71*****************************************************************************/
72INLINE atari_fdc_t *get_safe_token(device_t *device)
73{
74   assert(device != NULL);
75   assert(device->type() == ATARI_FDC);
76
77   return (atari_fdc_t *)downcast<legacy_device_base *>(device)->token();
78}
79
80/*****************************************************************************
81 * This is the structure I used in my own Atari 800 emulator some years ago
82 * Though it's a bit overloaded, I used it as it is the maximum of all
83 * supported formats:
84 * XFD no header at all
85 * ATR 16 bytes header
86 * DSK this struct
87 * It is used to determine the format of a XFD image by it's size only
88 *****************************************************************************/
89
90typedef struct _dsk_format dsk_format;
91struct _dsk_format
92{
93   UINT8 density;
94   UINT8 tracks;
95   UINT8 door;
96   UINT8 sta1;
97   UINT8 spt;
98   UINT8 doublesided;
99   UINT8 highdensity;
100   UINT8 seclen_hi;
101   UINT8 seclen_lo;
102   UINT8 status;
103   UINT8 sta2;
104   UINT8 sta3;
105   UINT8 sta4;
106   UINT8 cr;
107   UINT8 info[65+1];
108};
109
110/* combined with the size the image should have */
111typedef struct _xfd_format xfd_format;
112struct _xfd_format
113{
114   int size;
115   dsk_format dsk;
116};
117
118/* here's a table of known xfd formats */
119static const xfd_format xfd_formats[] =
120{
121   {35 * 18 * 1 * 128,             {0,35,1,0,18,0,0,0,128,255,0,0,0,13,"35 SS/SD"}},
122   {35 * 26 * 1 * 128,             {1,35,1,0,26,0,4,0,128,255,0,0,0,13,"35 SS/MD"}},
123   {(35 * 18 * 1 - 3) * 256 + 3 * 128, {2,35,1,0,18,0,4,1,  0,255,0,0,0,13,"35 SS/DD"}},
124   {40 * 18 * 1 * 128,             {0,40,1,0,18,0,0,0,128,255,0,0,0,13,"40 SS/SD"}},
125   {40 * 26 * 1 * 128,             {1,40,1,0,26,0,4,0,128,255,0,0,0,13,"40 SS/MD"}},
126   {(40 * 18 * 1 - 3) * 256 + 3 * 128, {2,40,1,0,18,0,4,1,  0,255,0,0,0,13,"40 SS/DD"}},
127   {40 * 18 * 2 * 128,             {0,40,1,0,18,1,0,0,128,255,0,0,0,13,"40 DS/SD"}},
128   {40 * 26 * 2 * 128,             {1,40,1,0,26,1,4,0,128,255,0,0,0,13,"40 DS/MD"}},
129   {(40 * 18 * 2 - 3) * 256 + 3 * 128, {2,40,1,0,18,1,4,1,  0,255,0,0,0,13,"40 DS/DD"}},
130   {77 * 18 * 1 * 128,             {0,77,1,0,18,0,0,0,128,255,0,0,0,13,"77 SS/SD"}},
131   {77 * 26 * 1 * 128,             {1,77,1,0,26,0,4,0,128,255,0,0,0,13,"77 SS/MD"}},
132   {(77 * 18 * 1 - 3) * 256 + 3 * 128, {2,77,1,0,18,0,4,1,  0,255,0,0,0,13,"77 SS/DD"}},
133   {77 * 18 * 2 * 128,             {0,77,1,0,18,1,0,0,128,255,0,0,0,13,"77 DS/SD"}},
134   {77 * 26 * 2 * 128,             {1,77,1,0,26,1,4,0,128,255,0,0,0,13,"77 DS/MD"}},
135   {(77 * 18 * 2 - 3) * 256 + 3 * 128, {2,77,1,0,18,1,4,1,  0,255,0,0,0,13,"77 DS/DD"}},
136   {80 * 18 * 2 * 128,             {0,80,1,0,18,1,0,0,128,255,0,0,0,13,"80 DS/SD"}},
137   {80 * 26 * 2 * 128,             {1,80,1,0,26,1,4,0,128,255,0,0,0,13,"80 DS/MD"}},
138   {(80 * 18 * 2 - 3) * 256 + 3 * 128, {2,80,1,0,18,1,4,1,  0,255,0,0,0,13,"80 DS/DD"}},
139   {0, {0,}}
140};
141
142/*****************************************************************************
143 *
144 * Open a floppy image for drive 'drive' if it is not yet openend
145 * and a name was given. Determine the image geometry depending on the
146 * type of image and store the results into the global drv[] structure
147 *
148 *****************************************************************************/
149
150#define MAXSIZE 5760 * 256 + 80
151static void atari_load_proc(device_image_interface &image)
152{
153   atari_fdc_t *fdc = get_safe_token(image.device().owner());
154   int id = floppy_get_drive(image);
155   int size, i;
156   const char *ext;
157
158   fdc->drv[id].image = (UINT8*)image.image_malloc(MAXSIZE);
159   if (!fdc->drv[id].image)
160      return;
161
162   /* tell whether the image is writable */
163   fdc->drv[id].mode = !image.is_readonly();
164   /* set up image if it has been created */
165   if (image.has_been_created())
166   {
167      int sector;
168      char buff[256];
169      memset(buff, 0, sizeof(buff));
170      /* default to 720 sectors */
171      for( sector = 0; sector < 720; sector++ )
172         image.fwrite(buff, 256);
173      image.fseek(0, SEEK_SET);
174   }
175
176   size = image.fread(fdc->drv[id].image, MAXSIZE);
177   if( size <= 0 )
178   {
179      fdc->drv[id].image = NULL;
180      return;
181   }
182   /* re allocate the buffer; we don't want to be too lazy ;) */
183    fdc->drv[id].image = (UINT8*)image.image_realloc(fdc->drv[id].image, size);
184
185   ext = image.filetype();
186    /* no extension: assume XFD format (no header) */
187    if (!ext)
188    {
189        fdc->drv[id].type = FORMAT_XFD;
190        fdc->drv[id].header_skip = 0;
191    }
192    else
193    /* XFD extension */
194    if( toupper(ext[0])=='X' && toupper(ext[1])=='F' && toupper(ext[2])=='D' )
195    {
196        fdc->drv[id].type = FORMAT_XFD;
197        fdc->drv[id].header_skip = 0;
198    }
199    else
200    /* ATR extension */
201    if( toupper(ext[0])=='A' && toupper(ext[1])=='T' && toupper(ext[2])=='R' )
202    {
203        fdc->drv[id].type = FORMAT_ATR;
204        fdc->drv[id].header_skip = 16;
205    }
206    else
207    /* DSK extension */
208    if( toupper(ext[0])=='D' && toupper(ext[1])=='S' && toupper(ext[2])=='K' )
209    {
210        fdc->drv[id].type = FORMAT_DSK;
211        fdc->drv[id].header_skip = sizeof(dsk_format);
212    }
213    else
214    {
215      fdc->drv[id].type = FORMAT_XFD;
216        fdc->drv[id].header_skip = 0;
217    }
218
219   if( fdc->drv[id].type == FORMAT_ATR &&
220      (fdc->drv[id].image[0] != 0x96 || fdc->drv[id].image[1] != 0x02) )
221   {
222      fdc->drv[id].type = FORMAT_XFD;
223      fdc->drv[id].header_skip = 0;
224   }
225
226   switch (fdc->drv[id].type)
227   {
228   /* XFD or unknown format: find a matching size from the table */
229   case FORMAT_XFD:
230      for( i = 0; xfd_formats[i].size; i++ )
231      {
232         if( size == xfd_formats[i].size )
233         {
234            fdc->drv[id].density = xfd_formats[i].dsk.density;
235            fdc->drv[id].tracks = xfd_formats[i].dsk.tracks;
236            fdc->drv[id].spt = xfd_formats[i].dsk.spt;
237            fdc->drv[id].heads = (xfd_formats[i].dsk.doublesided) ? 2 : 1;
238            fdc->drv[id].bseclen = 128;
239            fdc->drv[id].seclen = 256 * xfd_formats[i].dsk.seclen_hi + xfd_formats[i].dsk.seclen_lo;
240            fdc->drv[id].sectors = fdc->drv[id].tracks * fdc->drv[id].heads * fdc->drv[id].spt;
241            break;
242         }
243      }
244      break;
245   /* ATR format: find a size including the 16 bytes header */
246   case FORMAT_ATR:
247      {
248         int s;
249
250         fdc->drv[id].bseclen = 128;
251         /* get sectors from ATR header */
252         s = (size - 16) / 128;
253         /* 3 + odd number of sectors ? */
254         if ( fdc->drv[id].image[4] == 128 || (s % 18) == 0 || (s % 26) == 0 || ((s - 3) % 1) != 0 )
255         {
256            fdc->drv[id].sectors = s;
257            fdc->drv[id].seclen = 128;
258            /* sector size 128 or count not evenly dividable by 26 ? */
259            if( fdc->drv[id].seclen == 128 || (s % 26) != 0 )
260            {
261               /* yup! single density */
262               fdc->drv[id].density = 0;
263               fdc->drv[id].spt = 18;
264               fdc->drv[id].heads = 1;
265               fdc->drv[id].tracks = s / 18;
266               if( s % 18 != 0 )
267                  fdc->drv[id].tracks += 1;
268               if( fdc->drv[id].tracks % 2 == 0 && fdc->drv[id].tracks > 80 )
269               {
270                  fdc->drv[id].heads = 2;
271                  fdc->drv[id].tracks /= 2;
272               }
273            }
274            else
275            {
276               /* yes: medium density */
277               fdc->drv[id].density = 0;
278               fdc->drv[id].spt = 26;
279               fdc->drv[id].heads = 1;
280               fdc->drv[id].tracks = s / 26;
281               if( s % 26 != 0 )
282                  fdc->drv[id].tracks += 1;
283               if( fdc->drv[id].tracks % 2 == 0 && fdc->drv[id].tracks > 80 )
284               {
285                  fdc->drv[id].heads = 2;
286                  fdc->drv[id].tracks /= 2;
287               }
288            }
289         }
290         else
291         {
292            /* it's double density */
293            s = (s - 3) / 2 + 3;
294            fdc->drv[id].sectors = s;
295            fdc->drv[id].density = 2;
296            fdc->drv[id].seclen = 256;
297            fdc->drv[id].spt = 18;
298            fdc->drv[id].heads = 1;
299            fdc->drv[id].tracks = s / 18;
300            if( s % 18 != 0 )
301               fdc->drv[id].tracks += 1;
302            if( fdc->drv[id].tracks % 2 == 0 && fdc->drv[id].tracks > 80 )
303            {
304               fdc->drv[id].heads = 2;
305               fdc->drv[id].tracks /= 2;
306            }
307         }
308      }
309      break;
310   /* DSK format: it's all in the header */
311   case FORMAT_DSK:
312      {
313         dsk_format *dsk = (dsk_format *) fdc->drv[id].image;
314
315         fdc->drv[id].tracks = dsk->tracks;
316         fdc->drv[id].spt = dsk->spt;
317         fdc->drv[id].heads = (dsk->doublesided) ? 2 : 1;
318         fdc->drv[id].seclen = 256 * dsk->seclen_hi + dsk->seclen_lo;
319         fdc->drv[id].bseclen = fdc->drv[id].seclen;
320         fdc->drv[id].sectors = fdc->drv[id].tracks * fdc->drv[id].heads * fdc->drv[id].spt;
321      }
322      break;
323   }
324   logerror("atari opened floppy '%s', %d sectors (%d %s%s) %d bytes/sector\n",
325         image.filename(),
326         fdc->drv[id].sectors,
327         fdc->drv[id].tracks,
328         (fdc->drv[id].heads == 1) ? "SS" : "DS",
329         (fdc->drv[id].density == 0) ? "SD" : (fdc->drv[id].density == 1) ? "MD" : "DD",
330         fdc->drv[id].seclen);
331   return;
332}
333
334
335
336/*****************************************************************************
337 *
338 * This is a description of the data flow between Atari (A) and the
339 * Floppy (F) for the supported commands.
340 *
341 * A->F     DEV  CMD  AUX1 AUX2 CKS
342 *          '1'  'S'  00   00                 get status
343 * F->A     ACK  CPL  04   FF   E0   00   CKS
344 *                     ^    ^
345 *                     |    |
346 *                     |    bit 7 : door closed
347 *                     |
348 *                     bit7  : MD 128 bytes/sector, 26 sectors/track
349 *                     bit5  : DD 256 bytes/sector, 18 sectors/track
350 *                     else  : SD 128 bytes/sector, 18 sectors/track
351 *
352 * A->F     DEV  CMD  AUX1 AUX2 CKS
353 *          '1'  'R'  SECL SECH               read sector
354 * F->A     ACK                               command acknowledge
355 *               ***                          now read the sector
356 * F->A              CPL                      complete: sector read
357 * F->A                  128/256 byte CKS
358 *
359 * A->F     DEV  CMD  AUX1 AUX2 CKS
360 *          '1'  'W'  SECL SECH               write with verify
361 * F->A     ACK                               command acknowledge
362 * A->F          128/256 data CKS
363 * F->A                            CPL        complete: CKS okay
364 *          execute writing the sector
365 * F->A                                 CPL   complete: sector written
366 *
367 * A->F     DEV  CMD  AUX1 AUX2 CKS
368 *          '1'  'P'  SECL SECH               put sector
369 * F->A     ACK                               command acknowledge
370 * A->F          128/256 data CKS
371 * F->A                            CPL        complete: CKS okay
372 *          execute writing the sector
373 * F->A                                 CPL   complete: sector written
374 *
375 * A->F     DEV  CMD  AUX1 AUX2 CKS
376 *           '1' '!'  xx   xx                 single density format
377 * F->A     ACK                               command acknowledge
378 *          execute formatting
379 * F->A               CPL                     complete: format
380 * F->A                    128/256 byte CKS   bad sector table
381 *
382 *
383 * A->F     DEV  CMD  AUX1 AUX2 CKS
384 *          '1'  '"'  xx   xx                 double density format
385 * F->A     ACK                               command acknowledge
386 *          execute formatting
387 * F->A               CPL                     complete: format
388 * F->A                    128/256 byte CKS   bad sector table
389 *
390 *****************************************************************************/
391static void make_chksum(UINT8 * chksum, UINT8 data)
392{
393   UINT8 newone;
394   newone= *chksum + data;
395   if (newone < *chksum)
396      newone++;
397
398   if (VERBOSE_CHKSUM)
399      logerror("atari chksum old $%02x + data $%02x -> new $%02x\n", *chksum, data, newone);
400
401   *chksum = newone;
402}
403
404static void clr_serout(device_t *device,int expect_data)
405{
406   atari_fdc_t *fdc = get_safe_token(device);
407
408   fdc->serout_chksum = 0;
409   fdc->serout_offs = 0;
410   fdc->serout_count = expect_data + 1;
411}
412
413static void add_serout(device_t *device,int expect_data)
414{
415   atari_fdc_t *fdc = get_safe_token(device);
416
417   fdc->serout_chksum = 0;
418   fdc->serout_count = expect_data + 1;
419}
420
421static void clr_serin(device_t *device, int ser_delay)
422{
423   atari_fdc_t *fdc = get_safe_token(device);
424   device_t *pokey = device->machine().device("pokey");
425   fdc->serin_chksum = 0;
426   fdc->serin_offs = 0;
427   fdc->serin_count = 0;
428   pokey_serin_ready(pokey, ser_delay * 40);
429}
430
431static void add_serin(device_t *device,UINT8 data, int with_checksum)
432{
433   atari_fdc_t *fdc = get_safe_token(device);
434   fdc->serin_buff[fdc->serin_count++] = data;
435   if (with_checksum)
436      make_chksum(&fdc->serin_chksum, data);
437}
438
439static void ATTR_PRINTF(2,3) atari_set_frame_message(device_t *device,const char *fmt, ...)
440{
441   va_list arg;
442   va_start(arg, fmt);
443
444   vsprintf(atari_frame_message, fmt, arg);
445   atari_frame_counter = 30; /* FIXME */
446
447   va_end(arg);
448}
449
450static void a800_serial_command(device_t *device)
451{
452   int i, drive, sector, offset;
453   atari_fdc_t *fdc = get_safe_token(device);
454
455   if( !fdc->serout_offs )
456   {
457      if (VERBOSE_SERIAL)
458         logerror("atari serout command offset = 0\n");
459      return;
460   }
461   clr_serin(device, 10);
462
463   if (VERBOSE_SERIAL)
464   {
465      logerror("atari serout command %d: %02X %02X %02X %02X %02X : %02X ",
466         fdc->serout_offs,
467         fdc->serout_buff[0], fdc->serout_buff[1], fdc->serout_buff[2],
468         fdc->serout_buff[3], fdc->serout_buff[4], fdc->serout_chksum);
469   }
470
471   if (fdc->serout_chksum == 0)
472   {
473      if (VERBOSE_SERIAL)
474         logerror("OK\n");
475
476      drive = fdc->serout_buff[0] - '1';   /* drive # */
477      /* sector # */
478      if (drive < 0 || drive > 3)          /* ignore unknown drives */
479      {
480         logerror("atari unsupported drive #%d\n", drive+1);
481         atari_set_frame_message(device, "DRIVE #%d not supported", drive+1);
482         return;
483      }
484
485      /* extract sector number from the command buffer */
486      sector = fdc->serout_buff[2] + 256 * fdc->serout_buff[3];
487
488      switch (fdc->serout_buff[1]) /* command ? */
489      {
490         case 'S':   /* status */
491            atari_set_frame_message(device, "DRIVE #%d STATUS", drive+1);
492
493            if (VERBOSE_SERIAL)
494               logerror("atari status\n");
495
496            add_serin(device,'A',0);
497            add_serin(device,'C',0);
498            if (!fdc->drv[drive].mode) /* read only mode ? */
499            {
500               if (fdc->drv[drive].spt == 26)
501                  add_serin(device,0x80,1);   /* MD: 0x80 */
502               else
503               if (fdc->drv[drive].seclen == 128)
504                  add_serin(device,0x00,1);   /* SD: 0x00 */
505               else
506                  add_serin(device,0x20,1);   /* DD: 0x20 */
507            }
508            else
509            {
510               if (fdc->drv[drive].spt == 26)
511                  add_serin(device,0x84,1);   /* MD: 0x84 */
512               else
513               if (fdc->drv[drive].seclen == 128)
514                  add_serin(device,0x04,1);   /* SD: 0x04 */
515               else
516                  add_serin(device,0x24,1);   /* DD: 0x24 */
517            }
518            if (fdc->drv[drive].image)
519               add_serin(device,0xff,1);   /* door closed: 0xff */
520            else
521               add_serin(device,0x7f,1);   /* door open: 0x7f */
522            add_serin(device,0xe0,1);   /* dunno */
523            add_serin(device,0x00,1);   /* dunno */
524            add_serin(device,fdc->serin_chksum,0);
525            break;
526
527         case 'R':   /* read sector */
528            if (VERBOSE_SERIAL)
529               logerror("atari read sector #%d\n", sector);
530
531            if( sector < 1 || sector > fdc->drv[drive].sectors )
532            {
533               atari_set_frame_message(device, "DRIVE #%d READ SECTOR #%3d - ERR", drive+1, sector);
534
535               if (VERBOSE_SERIAL)
536                  logerror("atari bad sector #\n");
537
538               add_serin(device,'E',0);
539               break;
540            }
541            add_serin(device,'A',0);   /* acknowledge */
542            add_serin(device,'C',0);   /* completed */
543            if (sector < 4)    /* sector 1 .. 3 might be different length */
544            {
545               atari_set_frame_message(device, "DRIVE #%d READ SECTOR #%3d - SD", drive+1, sector);
546               offset = (sector - 1) * fdc->drv[drive].bseclen + fdc->drv[drive].header_skip;
547               for (i = 0; i < 128; i++)
548                  add_serin(device,fdc->drv[drive].image[offset++],1);
549            }
550            else
551            {
552               atari_set_frame_message(device, "DRIVE #%d READ SECTOR #%3d - %cD", drive+1, sector, (fdc->drv[drive].seclen == 128) ? 'S' : 'D');
553                    offset = (sector - 1) * fdc->drv[drive].seclen + fdc->drv[drive].header_skip;
554               for (i = 0; i < fdc->drv[drive].seclen; i++)
555                  add_serin(device,fdc->drv[drive].image[offset++],1);
556            }
557            add_serin(device,fdc->serin_chksum,0);
558            break;
559
560         case 'W':   /* write sector with verify */
561            if (VERBOSE_SERIAL)
562               logerror("atari write sector #%d\n", sector);
563
564            add_serin(device,'A',0);
565            if (sector < 4)    /* sector 1 .. 3 might be different length */
566            {
567               add_serout(device,fdc->drv[drive].bseclen);
568               atari_set_frame_message(device, "DRIVE #%d WRITE SECTOR #%3d - SD", drive+1, sector);
569                }
570            else
571            {
572               add_serout(device,fdc->drv[drive].seclen);
573               atari_set_frame_message(device, "DRIVE #%d WRITE SECTOR #%3d - %cD", drive+1, sector, (fdc->drv[drive].seclen == 128) ? 'S' : 'D');
574                }
575            break;
576
577         case 'P':   /* put sector (no verify) */
578            if (VERBOSE_SERIAL)
579               logerror("atari put sector #%d\n", sector);
580
581            add_serin(device,'A',0);
582            if (sector < 4)    /* sector 1 .. 3 might be different length */
583            {
584               add_serout(device,fdc->drv[drive].bseclen);
585               atari_set_frame_message(device, "DRIVE #%d PUT SECTOR #%3d - SD", drive+1, sector);
586                }
587            else
588            {
589               add_serout(device,fdc->drv[drive].seclen);
590               atari_set_frame_message(device, "DRIVE #%d PUT SECTOR #%3d - %cD", drive+1, sector, (fdc->drv[drive].seclen == 128) ? 'S' : 'D');
591                }
592            break;
593
594         case '!':   /* SD format */
595            if (VERBOSE_SERIAL)
596               logerror("atari format SD drive #%d\n", drive+1);
597
598            atari_set_frame_message(device, "DRIVE #%d FORMAT SD", drive+1);
599                add_serin(device,'A',0);   /* acknowledge */
600            add_serin(device,'C',0);   /* completed */
601            for (i = 0; i < 128; i++)
602               add_serin(device,0,1);
603            add_serin(device,fdc->serin_chksum,0);
604            break;
605
606         case '"':   /* DD format */
607            if (VERBOSE_SERIAL)
608               logerror("atari format DD drive #%d\n", drive+1);
609
610            atari_set_frame_message(device, "DRIVE #%d FORMAT DD", drive+1);
611                add_serin(device,'A',0);   /* acknowledge */
612            add_serin(device,'C',0);   /* completed */
613            for (i = 0; i < 256; i++)
614               add_serin(device,0,1);
615            add_serin(device,fdc->serin_chksum,0);
616            break;
617
618         default:
619            if (VERBOSE_SERIAL)
620               logerror("atari unknown command #%c\n", fdc->serout_buff[1]);
621
622            atari_set_frame_message(device, "DRIVE #%d UNKNOWN CMD '%c'", drive+1, fdc->serout_buff[1]);
623                add_serin(device,'N',0);   /* negative acknowledge */
624      }
625   }
626   else
627   {
628      atari_set_frame_message(device, "serial cmd chksum error");
629      if (VERBOSE_SERIAL)
630         logerror("BAD\n");
631
632      add_serin(device,'E',0);
633   }
634   if (VERBOSE_SERIAL)
635      logerror("atari %d bytes to read\n", fdc->serin_count);
636}
637
638static void a800_serial_write(device_t *device)
639{
640   int i, drive, sector, offset;
641   atari_fdc_t *fdc = get_safe_token(device);
642
643   if (VERBOSE_SERIAL)
644   {
645      logerror("atari serout %d bytes written : %02X ",
646         fdc->serout_offs, fdc->serout_chksum);
647   }
648
649   clr_serin(device, 80);
650   if (fdc->serout_chksum == 0)
651   {
652      if (VERBOSE_SERIAL)
653         logerror("OK\n");
654
655      add_serin(device,'C',0);
656      /* write the sector */
657      drive = fdc->serout_buff[0] - '1';   /* drive # */
658      /* not write protected and image available ? */
659      if (fdc->drv[drive].mode && fdc->drv[drive].image)
660      {
661         /* extract sector number from the command buffer */
662         sector = fdc->serout_buff[2] + 256 * fdc->serout_buff[3];
663         if (sector < 4)    /* sector 1 .. 3 might be different length */
664         {
665            offset = (sector - 1) * fdc->drv[drive].bseclen + fdc->drv[drive].header_skip;
666
667            if (VERBOSE_SERIAL)
668               logerror("atari storing 128 byte sector %d at offset 0x%08X", sector, offset );
669
670            for (i = 0; i < 128; i++)
671               fdc->drv[drive].image[offset++] = fdc->serout_buff[5+i];
672            atari_set_frame_message(device, "DRIVE #%d WROTE SECTOR #%3d - SD", drive+1, sector);
673            }
674         else
675         {
676            offset = (sector - 1) * fdc->drv[drive].seclen + fdc->drv[drive].header_skip;
677
678            if (VERBOSE_SERIAL)
679               logerror("atari storing %d byte sector %d at offset 0x%08X", fdc->drv[drive].seclen, sector, offset );
680
681            for (i = 0; i < fdc->drv[drive].seclen; i++)
682               fdc->drv[drive].image[offset++] = fdc->serout_buff[5+i];
683            atari_set_frame_message(device, "DRIVE #%d WROTE SECTOR #%3d - %cD", drive+1, sector, (fdc->drv[drive].seclen == 128) ? 'S' : 'D');
684            }
685         add_serin(device,'C',0);
686      }
687      else
688      {
689         add_serin(device,'E',0);
690      }
691   }
692   else
693   {
694      if (VERBOSE_SERIAL)
695         logerror("BAD\n");
696
697      add_serin(device,'E',0);
698   }
699}
700
701READ8_DEVICE_HANDLER ( atari_serin_r )
702{
703   int data = 0x00;
704   int ser_delay = 0;
705   atari_fdc_t *fdc = get_safe_token(device);
706
707   if (fdc->serin_count)
708   {
709      device_t *pokey = device->machine().device("pokey");
710
711      data = fdc->serin_buff[fdc->serin_offs];
712      ser_delay = 2 * 40;
713      if (fdc->serin_offs < 3)
714      {
715         ser_delay = 4 * 40;
716         if (fdc->serin_offs < 2)
717            ser_delay = 200 * 40;
718      }
719      fdc->serin_offs++;
720      if (--fdc->serin_count == 0)
721         fdc->serin_offs = 0;
722      else
723         pokey_serin_ready(pokey, ser_delay);
724   }
725
726   if (VERBOSE_SERIAL)
727      logerror("atari serin[$%04x] -> $%02x; delay %d\n", fdc->serin_offs, data, ser_delay);
728
729   return data;
730}
731
732WRITE8_DEVICE_HANDLER ( atari_serout_w )
733{
734   pia6821_device *pia = device->machine().device<pia6821_device>( "pia" );
735   atari_fdc_t *fdc = get_safe_token(device);
736
737   /* ignore serial commands if no floppy image is specified */
738   if( !fdc->drv[0].image )
739      return;
740   if (fdc->serout_count)
741   {
742      /* store data */
743      fdc->serout_buff[fdc->serout_offs] = data;
744
745      if (VERBOSE_SERIAL)
746         logerror("atari serout[$%04x] <- $%02x; count %d\n", fdc->serout_offs, data, fdc->serout_count);
747
748      fdc->serout_offs++;
749      if (--fdc->serout_count == 0)
750      {
751         /* exclusive or written checksum with calculated */
752         fdc->serout_chksum ^= data;
753         /* if the attention line is high, this should be data */
754         if (pia->irq_b_state())
755            a800_serial_write(device);
756      }
757      else
758      {
759         make_chksum(&fdc->serout_chksum, data);
760      }
761   }
762}
763
764WRITE_LINE_DEVICE_HANDLER(atarifdc_pia_cb2_w)
765{
766   atari_fdc_t *fdc = get_safe_token(device);
767   if (!state)
768   {
769      clr_serout(device,4); /* expect 4 command bytes + checksum */
770   }
771   else
772   {
773      fdc->serin_delay = 0;
774      a800_serial_command(device);
775   }
776}
777
778static FLOPPY_IDENTIFY( atari_dsk_identify )
779{
780   *vote = 100;
781   return FLOPPY_ERROR_SUCCESS;
782}
783
784
785static FLOPPY_CONSTRUCT( atari_dsk_construct )
786{
787   return FLOPPY_ERROR_SUCCESS;
788}
789
790FLOPPY_OPTIONS_START( atari_only )
791   FLOPPY_OPTION(
792      atari_dsk,
793      "atr,dsk,xfd",
794      "Atari floppy disk image",
795      atari_dsk_identify,
796      atari_dsk_construct,
797      NULL,
798      NULL
799   )
800FLOPPY_OPTIONS_END0
801
802static const floppy_config atari_floppy_config =
803{
804   DEVCB_NULL,
805   DEVCB_NULL,
806   DEVCB_NULL,
807   DEVCB_NULL,
808   DEVCB_NULL,
809   FLOPPY_STANDARD_5_25_DSHD,
810   FLOPPY_OPTIONS_NAME(atari_only),
811   NULL
812};
813
814static MACHINE_CONFIG_FRAGMENT( atari_fdc )
815   MCFG_FLOPPY_4_DRIVES_ADD(atari_floppy_config)
816MACHINE_CONFIG_END
817
818device_t *atari_floppy_get_device_child(device_t *device,int drive)
819{
820   switch(drive) {
821      case 0 : return device->subdevice(FLOPPY_0);
822      case 1 : return device->subdevice(FLOPPY_1);
823      case 2 : return device->subdevice(FLOPPY_2);
824      case 3 : return device->subdevice(FLOPPY_3);
825   }
826   return NULL;
827}
828
829static DEVICE_START(atari_fdc)
830{
831   int id;
832   for(id=0;id<4;id++)
833   {
834      floppy_install_load_proc(atari_floppy_get_device_child(device, id), atari_load_proc);
835   }
836}
837
838static DEVICE_RESET(atari_fdc)
839{
840}
841
842DEVICE_GET_INFO( atari_fdc )
843{
844   switch (state)
845   {
846      /* --- the following bits of info are returned as 64-bit signed integers --- */
847      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                                    break;
848      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(atari_fdc_t);                        break;
849
850      /* --- the following bits of info are returned as pointers --- */
851      case DEVINFO_PTR_MACHINE_CONFIG:            info->machine_config = MACHINE_CONFIG_NAME(atari_fdc);      break;
852
853      /* --- the following bits of info are returned as pointers to data or functions --- */
854      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(atari_fdc);               break;
855      case DEVINFO_FCT_STOP:                     /* Nothing */                                    break;
856      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(atari_fdc);               break;
857
858      /* --- the following bits of info are returned as NULL-terminated strings --- */
859      case DEVINFO_STR_NAME:                     strcpy(info->s, "Atari FDC");                        break;
860      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "Atari FDC");                        break;
861      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                              break;
862      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);                           break;
863      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright the MESS Team");             break;
864   }
865}
866
867DEFINE_LEGACY_DEVICE(ATARI_FDC, atari_fdc);
src/mess/includes/msx_slot.h
r11460r11461
1/*****************************************************************************
2 *
3 * includes/msx_slot.h
4 *
5 ****************************************************************************/
6
7#ifndef MSX_SLOT_H_
8#define MSX_SLOT_H_
9
10
11enum {
12   MSX_LAYOUT_SLOT_ENTRY,
13   MSX_LAYOUT_KANJI_ENTRY,
14   MSX_LAYOUT_RAMIO_SET_BITS_ENTRY,
15   MSX_LAYOUT_LAST
16};
17
18typedef struct {
19   int entry;
20   int type;
21   int slot_primary, slot_secondary, slot_page, page_extent;
22   int size, option;
23} msx_slot_layout;
24
25#define MSX_LAYOUT_INIT(msx) \
26static const msx_slot_layout msx_slot_layout_##msx[] = {
27
28#define MSX_LAYOUT_SLOT(prim, sec, page, extend, type, size, option) \
29   {                        \
30      MSX_LAYOUT_SLOT_ENTRY,      \
31      SLOT_##type,            \
32      prim,                  \
33      sec,                  \
34      page,                  \
35      extend,                  \
36      size,                  \
37      option                  \
38   },
39
40#define MSX_LAYOUT_KANJI(offset) \
41   {                        \
42      MSX_LAYOUT_KANJI_ENTRY,      \
43      SLOT_EMPTY,               \
44      0,                     \
45      0,                     \
46      0,                     \
47      0,                     \
48      0,                     \
49      offset                  \
50   },
51
52#define MSX_LAYOUT_RAMIO_SET_BITS(offset) \
53   {                        \
54      MSX_LAYOUT_RAMIO_SET_BITS_ENTRY,      \
55      SLOT_EMPTY,               \
56      0,                     \
57      0,                     \
58      0,                     \
59      0,                     \
60      0,                     \
61      offset                  \
62   },
63
64#define MSX_LAYOUT_END \
65   {                        \
66      MSX_LAYOUT_LAST,         \
67      SLOT_END,               \
68      0,                     \
69      0,                     \
70      0,                     \
71      0,                     \
72      0,                     \
73      0                     \
74   }                        \
75};
76
77
78enum msx_slot_type {
79   SLOT_EMPTY = 0,
80   SLOT_MSXDOS2,
81   SLOT_KONAMI_SCC,
82   SLOT_KONAMI,
83   SLOT_ASCII8,
84   SLOT_ASCII16,
85   SLOT_GAMEMASTER2,
86   SLOT_ASCII8_SRAM,
87   SLOT_ASCII16_SRAM,
88   SLOT_RTYPE,
89   SLOT_MAJUTSUSHI,
90   SLOT_FMPAC,
91   SLOT_SUPERLOADRUNNER,
92   SLOT_SYNTHESIZER,
93   SLOT_CROSS_BLAIM,
94   SLOT_DISK_ROM,
95   SLOT_KOREAN_80IN1,
96   SLOT_KOREAN_126IN1,
97   SLOT_KOREAN_90IN1,
98   SLOT_LAST_CARTRIDGE_TYPE = SLOT_KOREAN_90IN1,
99   SLOT_SOUNDCARTRIDGE,
100   SLOT_ROM,
101   SLOT_RAM,
102   SLOT_RAM_MM,
103   SLOT_CARTRIDGE1,
104   SLOT_CARTRIDGE2,
105        SLOT_DISK_ROM2,
106   SLOT_END
107};
108
109enum msx_mem_type {
110   MSX_MEM_ROM,
111   MSX_MEM_RAM,
112   MSX_MEM_HANDLER
113};
114
115typedef struct {
116   int m_type;
117   int m_start_page;
118   int m_bank_mask;
119   int m_banks[4];
120   int m_size;
121   UINT8 *m_mem;
122   const char *m_sramfile;
123   union {
124      struct {
125         UINT8 *mem;
126         int sram_support;
127         int sram_active;
128         int opll_active;
129      } fmpac;
130      struct {
131         int active;
132      } scc;
133      struct {
134         UINT8 *mem;
135         int sram_mask;
136         int empty_mask;
137      } sram;
138      struct {
139         int scc_active;
140         int sccp_active;
141         int ram_mode[4];
142         int banks_saved[4];
143         int mode;
144      } sccp;
145   } m_cart;
146} slot_state;
147
148typedef struct {
149   int slot_type;
150   int mem_type;
151   char name[32];
152   int (*init)(running_machine &machine, slot_state*, int page, UINT8 *mem, int size);
153   void (*reset)(running_machine &machine, slot_state*);
154   void (*map)(running_machine &machine, slot_state*, int page);
155   void (*write)(running_machine &machine, slot_state*, UINT16, UINT8);
156   int (*loadsram)(running_machine &machine, slot_state*);
157   int (*savesram)(running_machine &machine, slot_state*);
158} msx_slot;
159
160extern const msx_slot msx_slot_list[];
161
162#define MSX_SLOT_START \
163const msx_slot msx_slot_list[] = {
164
165#define MSX_SLOT_ROM(type, ent) { \
166   type,                     \
167   MSX_MEM_ROM,               \
168   #type,                     \
169   slot_##ent##_init,            \
170   slot_##ent##_reset,            \
171   slot_##ent##_map,            \
172   NULL,                     \
173   NULL,                     \
174   NULL                     \
175},
176
177#define MSX_SLOT_RAM(type, ent) { \
178   type,                     \
179   MSX_MEM_RAM,               \
180   #type,                     \
181   slot_##ent##_init,            \
182   slot_##ent##_reset,            \
183   slot_##ent##_map,            \
184   NULL,                     \
185   NULL,                     \
186   NULL                     \
187},
188
189#define MSX_SLOT(type, ent) { \
190   type,                     \
191   MSX_MEM_HANDLER,            \
192   #type,                     \
193   slot_##ent##_init,            \
194   slot_##ent##_reset,            \
195   slot_##ent##_map,            \
196   slot_##ent##_write,            \
197   NULL,                     \
198   NULL                     \
199},
200
201#define MSX_SLOT_SRAM(type, ent) { \
202   type,                     \
203   MSX_MEM_HANDLER,            \
204   #type,                     \
205   slot_##ent##_init,            \
206   slot_##ent##_reset,            \
207   slot_##ent##_map,            \
208   slot_##ent##_write,            \
209   slot_##ent##_loadsram,         \
210   slot_##ent##_savesram         \
211},
212
213#define MSX_SLOT_NULL(type) { \
214   type,                     \
215   MSX_MEM_ROM,               \
216   #type,                     \
217   NULL,                     \
218   NULL,                     \
219   NULL,                     \
220   NULL,                     \
221   NULL,                     \
222   NULL                     \
223},
224
225#define MSX_SLOT_END \
226   { SLOT_END, 0, "", NULL, NULL, NULL, NULL, NULL } \
227};
228
229#define MSX_SLOT_INIT(nm)          static int \
230   slot_##nm##_init (running_machine &machine, slot_state *state, int page, UINT8 *mem, int size)
231#define MSX_SLOT_MAP(nm)         \
232   static void slot_##nm##_map (running_machine &machine, slot_state *state, int page)
233#define MSX_SLOT_WRITE(nm)         \
234   static void slot_##nm##_write (running_machine &machine, slot_state *state, UINT16 addr, UINT8 val)
235#define MSX_SLOT_RESET(nm)         \
236   static void slot_##nm##_reset (running_machine &machine, slot_state *state)
237#define MSX_SLOT_LOADSRAM(nm)      \
238   static int slot_##nm##_loadsram (running_machine &machine, slot_state *state)
239#define MSX_SLOT_SAVESRAM(nm)      \
240   static int slot_##nm##_savesram (running_machine &machine, slot_state *state)
241
242typedef struct {
243   char name[9];
244   const msx_slot_layout *layout;
245} msx_driver_struct;
246
247extern const msx_driver_struct msx_driver_list[];
248
249#define MSX_DRIVER_LIST      \
250const msx_driver_struct msx_driver_list[] = {
251#define MSX_DRIVER(foo)      \
252      { #foo, msx_slot_layout_##foo },
253#define MSX_DRIVER_END      \
254      { "", NULL }      \
255};
256
257
258#endif /* MSX_SLOT_H_ */
src/mess/includes/nes.h
r11460r11461
1/*****************************************************************************
2 *
3 * includes/nes.h
4 *
5 * Nintendo Entertainment System (Famicom)
6 *
7 ****************************************************************************/
8
9#ifndef NES_H_
10#define NES_H_
11
12
13/***************************************************************************
14    CONSTANTS
15***************************************************************************/
16
17#define NTSC_CLOCK           N2A03_DEFAULTCLOCK     /* 1.789772 MHz */
18#define PAL_CLOCK              (26601712.0/16)        /* 1.662607 MHz */
19
20#define NES_BATTERY_SIZE 0x2000
21
22
23/***************************************************************************
24    TYPE DEFINITIONS
25***************************************************************************/
26
27struct nes_input
28{
29   UINT32 shift;
30   UINT32 i0, i1, i2;
31};
32
33/*PPU fast banking constants and structures */
34
35#define CHRROM 0
36#define CHRRAM 1
37
38typedef struct
39{
40   int source;   //defines source of base pointer
41   int origin; //defines offset of 0x400 byte segment at base pointer
42   UINT8* access;   //source translated + origin -> valid pointer!
43} chr_bank;
44
45/*PPU nametable fast banking constants and structures */
46
47#define CIRAM 0
48#define ROM 1
49#define EXRAM 2
50#define MMC5FILL 3
51#define CART_NTRAM 4
52
53#define NES_BATTERY 0
54#define NES_WRAM 1
55
56typedef struct
57{
58   int source;      /* defines source of base pointer */
59   int origin;      /* defines offset of 0x400 byte segment at base pointer */
60   int writable;   /* ExRAM, at least, can be write-protected AND used as nametable */
61   UINT8* access;   /* direct access when possible */
62} name_table;
63
64typedef void (*nes_prg_callback)(running_machine &machine, int start, int bank);
65typedef void (*nes_chr_callback)(running_machine &machine, int start, int bank, int source);
66
67class nes_state : public driver_device
68{
69public:
70   nes_state(const machine_config &mconfig, device_type type, const char *tag)
71      : driver_device(mconfig, type, tag) { }
72
73   /* input_related - this part has to be cleaned up (e.g. in_2 and in_3 are not really necessary here...) */
74   nes_input m_in_0, m_in_1, m_in_2, m_in_3;
75   UINT8 m_fck_scan, m_fck_mode;
76
77   int           m_prg_bank[5];
78   chr_bank      m_chr_map[8];  //quick banking structure, because some of this changes multiple times per scanline!
79   name_table    m_nt_page[4];  //quick banking structure for a maximum of 4K of RAM/ROM/ExRAM
80
81   int m_chr_open_bus;
82   int m_prgram_bank5_start, m_battery_bank5_start, m_empty_bank5_start;
83
84   UINT8 m_ce_mask, m_ce_state;
85   UINT8 m_vrc_ls_prg_a, m_vrc_ls_prg_b, m_vrc_ls_chr;
86
87   int m_MMC5_floodtile;
88   int m_MMC5_floodattr;
89   int m_mmc5_vram_control;
90   UINT8 m_mmc5_high_chr;
91   UINT8 m_mmc5_split_scr;
92   UINT8 *m_extended_ntram;
93
94   UINT8 m_mmc5_last_chr_a;
95   UINT16 m_mmc5_vrom_regA[8];
96   UINT16 m_mmc5_vrom_regB[4];
97   UINT8 m_mmc5_prg_regs[4];
98   UINT8 m_mmc5_bank_security;
99   UINT8 m_mmc5_prg_mode;
100   UINT8 m_mmc5_chr_mode;
101   UINT8 m_mmc5_chr_high;
102   UINT8 m_mmc5_split_ctrl;
103   UINT8 m_mmc5_split_yst;
104   UINT8 m_mmc5_split_bank;
105
106   /* video-related */
107   int m_nes_vram_sprite[8]; /* Used only by mmc5 for now */
108   int m_last_frame_flip;
109
110   /* misc */
111   write8_space_func   m_mmc_write_low;
112   const char        *m_mmc_write_low_name;
113   write8_space_func   m_mmc_write_mid;
114   const char        *m_mmc_write_mid_name;
115   write8_space_func   m_mmc_write;
116   const char        *m_mmc_write_name;
117   read8_space_func    m_mmc_read_low;
118   const char        *m_mmc_read_low_name;
119   read8_space_func    m_mmc_read_mid;
120   const char        *m_mmc_read_mid_name;
121   read8_space_func    m_mmc_read;
122   const char        *m_mmc_read_name;
123   emu_timer           *m_irq_timer;
124
125   nes_prg_callback    m_mmc3_prg_cb;   // these are used to simplify a lot emulation of some MMC3 pirate clones
126   nes_chr_callback    m_mmc3_chr_cb;
127
128   /* devices */
129   device_t      *m_maincpu;
130   device_t      *m_ppu;
131   device_t      *m_sound;
132   device_t      *m_cart;
133
134   /* misc region to be allocated at init */
135   // variables which don't change at run-time
136   UINT8      *m_rom;
137   UINT8      *m_vrom;
138   UINT8      *m_vram;
139   UINT8      *m_wram;
140   UINT8      *m_ciram; //PPU nametable RAM - external to PPU!
141   UINT8      *m_battery_ram;
142   UINT8      *m_mapper_ram;
143   UINT8      *m_mapper_bram;
144
145   /***** Mapper-related variables *****/
146
147   // common ones
148   int        m_IRQ_enable, m_IRQ_enable_latch;
149   UINT16     m_IRQ_count, m_IRQ_count_latch;
150   UINT8      m_IRQ_toggle;
151   UINT8      m_IRQ_reset;
152   UINT8      m_IRQ_status;
153   UINT8      m_IRQ_mode;
154   UINT8      m_IRQ_clear;
155   int        m_mult1, m_mult2;
156
157   UINT8 m_mmc_chr_source;         // This is set at init to CHRROM or CHRRAM. a few mappers can swap between
158                           // the two (this is done in the specific handlers).
159
160   UINT8 m_mmc_cmd1, m_mmc_cmd2;      // These represent registers where the mapper writes important values
161   UINT8 m_mmc_count;            // This is used as counter in mappers like 1 and 45
162
163   int m_mmc_prg_base, m_mmc_prg_mask;   // MMC3 based multigame carts select a block of banks by using these (and then act like normal MMC3),
164   int m_mmc_chr_base, m_mmc_chr_mask;   // while MMC3 and clones (mapper 118 & 119) simply set them as 0 and 0xff resp.
165
166   UINT8 m_mmc_prg_bank[6];            // Many mappers writes only some bits of the selected bank (for both PRG and CHR),
167   UINT8 m_mmc_vrom_bank[16];         // hence these are handy to latch bank values.
168
169   UINT16 m_MMC5_vrom_bank[12];         // MMC5 has 10bit wide VROM regs!
170   UINT8 m_mmc_extra_bank[16];         // some MMC3 clone have 2 series of PRG/CHR banks...
171                              // we collect them all here: first 4 elements PRG banks, then 6/8 CHR banks
172
173   UINT8 m_mmc_latch1, m_mmc_latch2;
174   UINT8 m_mmc_reg[16];
175
176   UINT8 m_mmc_dipsetting;
177
178   // misc mapper related variables which should be merged with the above one, where possible
179   int m_mmc1_reg_write_enable;
180   int m_mmc1_latch;
181   int m_mmc1_count;
182
183   int m_mmc3_latch;
184   int m_mmc3_wram_protect;
185   int m_mmc3_alt_irq;
186
187   int m_MMC5_rom_bank_mode;
188   int m_MMC5_vrom_bank_mode;
189   int m_MMC5_vram_protect;
190   int m_MMC5_scanline;
191   int m_vrom_page_a;
192   int m_vrom_page_b;
193   // int vrom_next[4];
194
195   UINT8 m_mmc6_reg;
196
197   // these might be unified in single mmc_reg[] array, together with state->m_mmc_cmd1 & state->m_mmc_cmd2
198   // but be careful that MMC3 clones often use state->m_mmc_cmd1/state->m_mmc_cmd2 (from base MMC3) AND additional regs below!
199   UINT8 m_mapper83_reg[10];
200   UINT8 m_mapper83_low_reg[4];
201   UINT8 m_txc_reg[4];   // used by mappers 132, 172 & 173
202   UINT8 m_subor_reg[4];   // used by mappers 166 & 167
203   UINT8 m_sachen_reg[8];   // used by mappers 137, 138, 139 & 141
204   UINT8 m_map52_reg_written;
205   UINT8 m_map114_reg, m_map114_reg_enabled;
206
207   /***** NES-cart related *****/
208
209   /* load-time cart variables which remain constant */
210   UINT16 m_prg_chunks;      // iNES 2.0 allows for more chunks (a recently dumped multigame cart has 256 chunks of both PRG & CHR!)
211   UINT16 m_chr_chunks;
212   UINT16 m_vram_chunks;
213   UINT8 m_trainer;
214   UINT8 m_battery;         // if there is PRG RAM with battery backup
215   UINT32 m_battery_size;
216   UINT8 m_prg_ram;         // if there is PRG RAM with no backup
217   UINT32 m_wram_size;
218   UINT32 m_mapper_ram_size;
219   UINT32 m_mapper_bram_size;
220
221   /* system variables which don't change at run-time */
222   UINT16 m_mapper;      // for iNES
223   UINT16 m_pcb_id;      // for UNIF & xml
224   UINT8 m_four_screen_vram;
225   UINT8 m_hard_mirroring;
226   UINT8 m_crc_hack;   // this is needed to detect different boards sharing the same Mappers (shame on .nes format)
227   UINT8 m_ines20;
228
229   /***** FDS-floppy related *****/
230
231   int     m_disk_expansion;
232
233   UINT8   m_fds_sides;
234   UINT8   *m_fds_data;   // here, we store a copy of the disk
235   UINT8   *m_fds_ram;   // here, we emulate the RAM adapter
236
237   /* Variables which can change */
238   UINT8   m_fds_motor_on;
239   UINT8   m_fds_door_closed;
240   UINT8   m_fds_current_side;
241   UINT32  m_fds_head_position;
242   UINT8   m_fds_status0;
243   UINT8   m_fds_read_mode;
244   UINT8   m_fds_write_reg;
245
246   /* these are used in the mapper 20 handlers */
247   int     m_fds_last_side;
248   int     m_fds_count;
249};
250
251
252/*----------- defined in machine/nes.c -----------*/
253
254WRITE8_HANDLER ( nes_IN0_w );
255WRITE8_HANDLER ( nes_IN1_w );
256
257/* protos */
258
259DEVICE_IMAGE_LOAD(nes_cart);
260DEVICE_START(nes_disk);
261DEVICE_IMAGE_LOAD(nes_disk);
262DEVICE_IMAGE_UNLOAD(nes_disk);
263
264MACHINE_START( nes );
265MACHINE_RESET( nes );
266
267DRIVER_INIT( famicom );
268
269READ8_HANDLER( nes_IN0_r );
270READ8_HANDLER( nes_IN1_r );
271
272int nes_ppu_vidaccess( device_t *device, int address, int data );
273
274void nes_partialhash(hash_collection &dest, const unsigned char *data, unsigned long length, const char *functions);
275
276/*----------- defined in video/nes.c -----------*/
277
278PALETTE_INIT( nes );
279VIDEO_START( nes );
280SCREEN_UPDATE( nes );
281
282
283#endif /* NES_H_ */
src/mess/includes/msx.h
r11460r11461
1/*****************************************************************************
2 *
3 * includes/msx.h
4 *
5 ****************************************************************************/
6
7#ifndef __MSX_H__
8#define __MSX_H__
9
10#include "machine/wd17xx.h"
11#include "formats/flopimg.h"
12
13#define MSX_MAX_CARTS   (2)
14
15#define TC8521_TAG   "rtc"
16
17class msx_state : public driver_device
18{
19public:
20   msx_state(const machine_config &mconfig, device_type type, const char *tag)
21      : driver_device(mconfig, type, tag) { }
22
23   /* PSG */
24   int m_psg_b;
25   int m_opll_active;
26   /* mouse */
27   UINT16 m_mouse[2];
28   int m_mouse_stat[2];
29   /* rtc */
30   int m_rtc_latch;
31   /* disk */
32   UINT8 m_dsk_stat;
33   /* kanji */
34   UINT8 *m_kanji_mem;
35   int m_kanji_latch;
36   /* memory */
37   const msx_slot_layout *layout;
38   slot_state *m_cart_state[MSX_MAX_CARTS];
39   slot_state *m_state[4];
40   const msx_slot *m_slot[4];
41   UINT8 *m_ram_pages[4];
42   UINT8 *m_empty, m_ram_mapper[4];
43   UINT8 m_ramio_set_bits;
44   slot_state *m_all_state[4][4][4];
45   int m_slot_expanded[4];
46   UINT8 m_primary_slot;
47   UINT8 m_secondary_slot[4];
48   UINT8 m_superloadrunner_bank;
49   UINT8 m_korean90in1_bank;
50   UINT8 *m_top_page;
51   int m_port_c_old;
52   int keylatch;
53};
54
55
56/*----------- defined in machine/msx.c -----------*/
57
58extern const i8255_interface msx_ppi8255_interface;
59extern const wd17xx_interface msx_wd17xx_interface;
60/* start/stop functions */
61extern DRIVER_INIT( msx );
62extern MACHINE_START( msx );
63extern MACHINE_START( msx2 );
64extern MACHINE_RESET( msx );
65extern MACHINE_RESET( msx2 );
66extern INTERRUPT_GEN( msx_interrupt );
67extern INTERRUPT_GEN( msx2_interrupt );
68
69DEVICE_IMAGE_LOAD( msx_cart );
70DEVICE_IMAGE_UNLOAD( msx_cart );
71
72void msx_vdp_interrupt(running_machine &machine, int i);
73
74/* I/O functions */
75READ8_DEVICE_HANDLER( msx_printer_status_r );
76WRITE8_DEVICE_HANDLER( msx_printer_strobe_w );
77WRITE8_DEVICE_HANDLER( msx_printer_data_w );
78
79WRITE8_HANDLER ( msx_psg_port_a_w );
80READ8_HANDLER ( msx_psg_port_a_r );
81WRITE8_HANDLER ( msx_psg_port_b_w );
82READ8_HANDLER ( msx_psg_port_b_r );
83WRITE8_HANDLER ( msx_fmpac_w );
84READ8_HANDLER ( msx_rtc_reg_r );
85WRITE8_HANDLER ( msx_rtc_reg_w );
86WRITE8_HANDLER ( msx_rtc_latch_w );
87WRITE8_HANDLER ( msx_90in1_w );
88
89/* new memory emulation */
90WRITE8_HANDLER (msx_page0_w);
91WRITE8_HANDLER (msx_page0_1_w);
92WRITE8_HANDLER (msx_page1_w);
93WRITE8_HANDLER (msx_page1_1_w);
94WRITE8_HANDLER (msx_page1_2_w);
95WRITE8_HANDLER (msx_page2_w);
96WRITE8_HANDLER (msx_page2_1_w);
97WRITE8_HANDLER (msx_page2_2_w);
98WRITE8_HANDLER (msx_page2_3_w);
99WRITE8_HANDLER (msx_page3_w);
100WRITE8_HANDLER (msx_page3_1_w);
101WRITE8_HANDLER (msx_sec_slot_w);
102 READ8_HANDLER (msx_sec_slot_r);
103WRITE8_HANDLER (msx_ram_mapper_w);
104 READ8_HANDLER (msx_ram_mapper_r);
105 READ8_HANDLER (msx_kanji_r);
106WRITE8_HANDLER (msx_kanji_w);
107
108#endif /* __MSX_H__ */
src/mess/includes/pce.h
r11460r11461
1/*****************************************************************************
2 *
3 * includes/pce.h
4 *
5 * NEC PC Engine/TurboGrafx16
6 *
7 ****************************************************************************/
8
9#ifndef PCE_H_
10#define PCE_H_
11
12#include "cdrom.h"
13#include "sound/msm5205.h"
14
15#define C6280_TAG         "c6280"
16
17#define   MAIN_CLOCK      21477270
18#define PCE_CD_CLOCK   9216000
19
20#define PCE_HEADER_SIZE      512
21
22#define TG_16_JOY_SIG      0x00
23#define PCE_JOY_SIG         0x40
24#define NO_CD_SIG         0x80
25#define CD_SIG            0x00
26/* these might be used to indicate something, but they always seem to return 1 */
27#define CONST_SIG         0x30
28
29/* the largest possible cartridge image (street fighter 2 - 2.5MB) */
30#define PCE_ROM_MAXSIZE      0x280000
31
32typedef struct
33{
34   UINT8   regs[16];
35   UINT8   *bram;
36   UINT8   *adpcm_ram;
37   int      bram_locked;
38   int      adpcm_read_ptr;
39   UINT8   adpcm_read_buf;
40   int      adpcm_write_ptr;
41   UINT8   adpcm_write_buf;
42   int      adpcm_length;
43   int      adpcm_clock_divider;
44   UINT32  msm_start_addr;
45   UINT32   msm_end_addr;
46   UINT32   msm_half_addr;
47   UINT8   msm_nibble;
48   UINT8   msm_idle;
49
50   /* SCSI signals */
51   int      scsi_BSY;   /* Busy. Bus in use */
52   int      scsi_SEL;   /* Select. Initiator has won arbitration and has selected a target */
53   int      scsi_CD;   /* Control/Data. Target is sending control (data) information */
54   int      scsi_IO;   /* Input/Output. Target is sending (receiving) information */
55   int      scsi_MSG;   /* Message. Target is sending or receiving a message */
56   int      scsi_REQ;   /* Request. Target is requesting a data transfer */
57   int      scsi_ACK;   /* Acknowledge. Initiator acknowledges that it is ready for a data transfer */
58   int      scsi_ATN;   /* Attention. Initiator has a message ready for the target */
59   int      scsi_RST;   /* Reset. Initiator forces all targets and any other initiators to do a warm reset */
60   int      scsi_last_RST;   /* To catch setting of RST signal */
61   int      cd_motor_on;
62   int      selected;
63   UINT8   *command_buffer;
64   int      command_buffer_index;
65   int      status_sent;
66   int      message_after_status;
67   int      message_sent;
68   UINT8   *data_buffer;
69   int      data_buffer_size;
70   int      data_buffer_index;
71   int      data_transferred;
72
73   /* Arcade Card specific */
74   UINT8   *acard_ram;
75   UINT8   acard_latch;
76   UINT8   acard_ctrl[4];
77   UINT32   acard_base_addr[4];
78   UINT16   acard_addr_offset[4];
79   UINT16   acard_addr_inc[4];
80   UINT32   acard_shift;
81   UINT8   acard_shift_reg;
82
83   UINT32   current_frame;
84   UINT32   end_frame;
85   UINT32   last_frame;
86   UINT8   cdda_status;
87   UINT8   cdda_play_mode;
88   UINT8   *subcode_buffer;
89   UINT8   end_mark;
90   cdrom_file   *cd;
91   const cdrom_toc*   toc;
92   emu_timer   *data_timer;
93   emu_timer   *adpcm_dma_timer;
94
95   emu_timer   *cdda_fadeout_timer;
96   emu_timer   *cdda_fadein_timer;
97   double   cdda_volume;
98   emu_timer   *adpcm_fadeout_timer;
99   emu_timer   *adpcm_fadein_timer;
100   double   adpcm_volume;
101} pce_cd_t;
102
103
104class pce_state : public driver_device
105{
106public:
107   pce_state(const machine_config &mconfig, device_type type, const char *tag)
108      : driver_device(mconfig, type, tag) { }
109
110   unsigned char *m_user_ram;
111   UINT8 *m_cd_ram;
112   UINT8 m_io_port_options;
113   UINT8 m_sys3_card;
114   UINT8 m_acard;
115   pce_cd_t m_cd;
116   UINT8 *m_cartridge_ram;
117   int m_joystick_port_select;
118   int m_joystick_data_select;
119   UINT8 m_joy_6b_packet[5];
120};
121
122
123/*----------- defined in machine/pce.c -----------*/
124
125DEVICE_IMAGE_LOAD(pce_cart);
126NVRAM_HANDLER( pce );
127WRITE8_HANDLER ( pce_joystick_w );
128 READ8_HANDLER ( pce_joystick_r );
129
130extern const msm5205_interface pce_cd_msm5205_interface;
131WRITE8_HANDLER( pce_cd_bram_w );
132WRITE8_HANDLER( pce_cd_intf_w );
133READ8_HANDLER( pce_cd_intf_r );
134WRITE8_HANDLER( pce_cd_acard_w );
135READ8_HANDLER( pce_cd_acard_r );
136WRITE8_HANDLER( pce_cd_acard_wram_w );
137READ8_HANDLER( pce_cd_acard_wram_r );
138
139DRIVER_INIT( pce );
140DRIVER_INIT( tg16 );
141DRIVER_INIT( sgx );
142MACHINE_START( pce );
143MACHINE_RESET( pce );
144
145
146#endif /* PCE_H_ */
src/mess/video/nes.c
r11460r11461
1/***************************************************************************
2
3  video/nes.c
4
5  Routines to control the unique NES video hardware/PPU.
6
7***************************************************************************/
8
9#include "emu.h"
10#include "video/ppu2c0x.h"
11#include "includes/nes.h"
12#include "machine/nes_mmc.h"
13
14static void nes_vh_reset( running_machine &machine )
15{
16   nes_state *state = machine.driver_data<nes_state>();
17   ppu2c0x_set_vidaccess_callback(machine.device("ppu"), nes_ppu_vidaccess);
18
19   if (state->m_four_screen_vram)
20      set_nt_mirroring(machine, PPU_MIRROR_4SCREEN);
21   else
22   {
23      switch (state->m_hard_mirroring)
24      {
25         case PPU_MIRROR_HORZ:
26         case PPU_MIRROR_VERT:
27         case PPU_MIRROR_HIGH:
28         case PPU_MIRROR_LOW:
29            set_nt_mirroring(machine, state->m_hard_mirroring);
30            break;
31         default:
32            set_nt_mirroring(machine, PPU_MIRROR_NONE);
33            break;
34      }
35   }
36}
37
38VIDEO_START( nes )
39{
40   nes_state *state = machine.driver_data<nes_state>();
41
42   state->m_last_frame_flip =  0;
43
44   machine.add_notifier(MACHINE_NOTIFY_RESET, machine_notify_delegate(FUNC(nes_vh_reset),&machine));
45}
46
47PALETTE_INIT( nes )
48{
49   ppu2c0x_init_palette(machine, 0);
50}
51
52
53/***************************************************************************
54
55  Display refresh
56
57***************************************************************************/
58
59SCREEN_UPDATE( nes )
60{
61   nes_state *state = screen->machine().driver_data<nes_state>();
62
63   /* render the ppu */
64   ppu2c0x_render(state->m_ppu, bitmap, 0, 0, 0, 0);
65
66   /* if this is a disk system game, check for the flip-disk key */
67   if (state->m_disk_expansion && state->m_pcb_id == NO_BOARD)
68   {
69      // latch this input so it doesn't go at warp speed
70      if ((input_port_read(screen->machine(), "FLIPDISK") & 0x01) && (!state->m_last_frame_flip))
71      {
72         state->m_last_frame_flip = 1;
73         state->m_fds_current_side++;
74         if (state->m_fds_current_side > state->m_fds_sides)
75            state->m_fds_current_side = 0;
76
77         if (state->m_fds_current_side == 0)
78            popmessage("No disk inserted.");
79         else
80            popmessage("Disk set to side %d", state->m_fds_current_side);
81      }
82
83      if (!(input_port_read(screen->machine(), "FLIPDISK") & 0x01))
84         state->m_last_frame_flip = 0;
85   }
86   return 0;
87}
src/mess/drivers/a3000.c
r11460r11461
1/***************************************************************************
2
3    Commodore Amiga 3000
4
5    Skeleton driver
6
7***************************************************************************/
8
9#include "emu.h"
10#include "cpu/m68000/m68000.h"
11
12
13class a3000_state : public driver_device
14{
15public:
16   a3000_state(const machine_config &mconfig, device_type type, const char *tag)
17      : driver_device(mconfig, type, tag) { }
18
19};
20
21
22
23/***************************************************************************
24    CONSTANTS
25***************************************************************************/
26
27#define XTAL_U104   XTAL_32MHz
28
29
30/***************************************************************************
31    ADDRESS MAPS
32***************************************************************************/
33
34static ADDRESS_MAP_START( a3000_mem, AS_PROGRAM, 32 )
35   ADDRESS_MAP_UNMAP_HIGH
36   AM_RANGE(0x000000, 0x1fffff) AM_RAMBANK("chipram")
37   AM_RANGE(0xf80000, 0xffffff) AM_ROM AM_REGION("kickstart", 0)
38ADDRESS_MAP_END
39
40
41/***************************************************************************
42    INPUT PORTS
43***************************************************************************/
44
45static INPUT_PORTS_START( a3000 )
46INPUT_PORTS_END
47
48
49/***************************************************************************
50    MACHINE DRIVERS
51***************************************************************************/
52
53static MACHINE_CONFIG_START( a3000, a3000_state )
54   MCFG_CPU_ADD("maincpu", M68030, XTAL_U104 / 2)
55   MCFG_CPU_PROGRAM_MAP(a3000_mem)
56
57   MCFG_SCREEN_ADD("screen", RASTER)
58   MCFG_SCREEN_REFRESH_RATE(60)
59   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
60   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
61   MCFG_SCREEN_SIZE(512*2, 312)
62   MCFG_SCREEN_VISIBLE_AREA((129-8-8)*2, (449+8-1+8)*2, 44-8, 300+8-1)
63MACHINE_CONFIG_END
64
65
66/***************************************************************************
67    ROM DEFINITIONS
68***************************************************************************/
69
70/* Note: I think those ROMs are correct, but they should be verified */
71ROM_START( a3000 )
72   ROM_REGION32_BE(0x80000, "kickstart", 0)
73   ROM_DEFAULT_BIOS("kick14")
74   ROM_SYSTEM_BIOS(0, "kick14", "Kickstart 1.4 (36.16)")
75   /* COPYRIGHT 1990 CAI // ALL RIGHTS RESERVED // ALPHA 5 ROM 0 CS=9713 */
76   ROMX_LOAD("390629-02.u182", 0x00000, 0x40000, CRC(58327536) SHA1(d1713d7f31474a5948e6d488e33686061cf3d1e2), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(1))
77   /* COPYRIGHT 1990 CAI // ALL RIGHTS RESERVED // ALPHA 5 ROM 1 CS=9B21 */
78   ROMX_LOAD("390630-02.u183", 0x00002, 0x40000, CRC(fe2f7fb9) SHA1(c05c9c52d014c66f9019152b3f2a2adc2c678794), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(1))
79   ROM_SYSTEM_BIOS(1, "kick204", "Kickstart 2.04 (37.175)")
80   ROMX_LOAD("390629-03.u182", 0x00000, 0x40000, CRC(a245dbdf) SHA1(83bab8e95d378b55b0c6ae6561385a96f638598f), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(2))
81   ROMX_LOAD("390630-03.u183", 0x00002, 0x40000, CRC(7db1332b) SHA1(48f14b31279da6757848df6feb5318818f8f576c), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(2))
82   ROM_SYSTEM_BIOS(2, "kick31", "Kickstart 3.1 (40.68)")
83   ROMX_LOAD("kick31.u182",    0x00000, 0x40000, CRC(286b9a0d) SHA1(6763a2258ec493f7408cf663110dae9a17803ad1), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(3))
84   ROMX_LOAD("kick31.u183",    0x00002, 0x40000, CRC(0b8cde6a) SHA1(5f02e97b48ebbba87d516a56b0400c6fc3434d8d), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(3))
85ROM_END
86
87
88/***************************************************************************
89    GAME DRIVERS
90***************************************************************************/
91
92/*    YEAR  NAME   PARENT  COMPAT  MACHINE  INPUT  INIT  COMPANY      FULLNAME      FLAGS */
93COMP( 1990, a3000, 0,      0,      a3000,   a3000, 0,    "Commodore Business Machines", "Amiga 3000", GAME_NOT_WORKING | GAME_NO_SOUND )
src/mess/drivers/astrocde.c
r11460r11461
1/****************************************************************************
2
3    Bally Astrocade consumer hardware
4    driver by Nicola Salmoria, Mike Coates, Frank Palazzolo, Aaron Giles,
5    Dirk Best
6
7****************************************************************************/
8
9#include "emu.h"
10#include "cpu/z80/z80.h"
11#include "includes/astrocde.h"
12#include "sound/astrocde.h"
13#include "imagedev/cartslot.h"
14#include "machine/ram.h"
15
16MACHINE_RESET( astrocde );
17void get_ram_expansion_settings(address_space *space, int &ram_expansion_installed, int &write_protect_on, int &expansion_ram_start, int &expansion_ram_end, int &shadow_ram_end);
18
19/*************************************
20 *
21 *  Memory maps
22 *
23 * $0000 to $1FFF:  8K on-board ROM (could be one of three available BIOS dumps)
24 * $2000 to $3FFF:  8K cartridge ROM
25 * $4000 to $4FFF:  4K screen RAM
26 * $5000 to $FFFF:  44K address space not available in standard machine.  With a
27 * sufficiently large RAM expansion, all of this RAM can be added, and accessed
28 * by an extended BASIC program.  Bally and Astrocade BASIC can access from
29 * $5000 to $7FFF if available.
30 *
31 *  RAM Expansions
32 *
33 * Several third party RAM expansions have been made for the Astrocade.  These
34 * allow access to various ranges of the expansion memory ($5000 to $FFFF).
35 * A RAM expansion is required to use extended BASIC programs like Blue RAM BASIC
36 * and VIPERSoft BASIC.  All of the expansions also have a RAM protect switch, which
37 * can be flipped at any time to make the RAM act like ROM.  Extended BASIC
38 * programs need access to the RAM and won't work with RAM protect enabled, but
39 * this can be useful with Bally and Astrocade BASIC.  They also have a range switch
40 * (not implemented).  The default position is 6K, but it can be switched to
41 * 2K.  This means that the expanded memory starting at $6000 will instead be
42 * mapped to the cartridge memory starting at $2000.  So it would be possible to
43 * load a cartridge program from tape into the expansion memory, then flip the range
44 * switch and run it as a cartridge.  This is useful for cartridge development.
45 *
46 * NOTE:  If you have any trouble running cartridges with a RAM expansion installed, hit reset.
47 *
48 * Blue RAM -- available in 4K, 16K, and 32K.  These also use an INS8154 chip,
49 * (not yet implemented) which has an additional $80 bytes of RAM mapped
50 * immediately after the end of the expansion address space.  This memory
51 * can't be write protected.  The INS8154 has I/O features needed for loading
52 * tape programs into Blue RAM BASIC, as well as running the Blue RAM Utility cart.
53 * 4K:  $6000 to $6FFF (can't run VIPERSoft BASIC, because this program needs memory
54 * past this range)
55 * 16K:  $6000 to $9FFF
56 * 32K:  $6000 to $DFFF
57 *
58 * VIPER System 1 -- This is available in 16K only.  It also includes a keyboard (not implemented).
59 * 16K:  $6000 to $9FFF
60 *
61 * Lil' WHITE RAM -- This is available in 32K only.  Attempts to read and write
62 * to memory outside of its address range ($D000 to $FFFF) are mapped to the expansion
63 * memory $5000 to $7FFF.  The current implementation won't allow the shadow RAM area
64 * to be accessed when RAM protect is on, but there is no known software that will
65 * access the upper range of the expansion RAM when RAM protect is enabled.
66 * 32K:  $5000 to $CFFF
67 *
68 * R&L 64K RAM Board -- This is a highly configurable kit.  RAM can be installed in
69 * 2K increments.  So, the entire 44K expansion memory can be filled.  It is also
70 * possible to override the rest of the memory map with RAM (not implemented).
71 * There are 32 switches allowing users to activate and deactivate each 2K block (not implemented).
72 * RAM write protection can be implemented in three ranges through jumpers or by
73 * installing switches.  The ranges are $0000 to $0FFF (first 4K), $0000 to $3FFF (first 16K),
74 * and $0000 to $FFFF (all 64K).  The current implementation is for 44K expansion memory mapped from
75 * $5000 to $FFFF, with only a single write protect covering this entire range.
76 *
77 *************************************/
78
79static ADDRESS_MAP_START( astrocade_mem, AS_PROGRAM, 8 )
80   AM_RANGE(0x0000, 0x0fff) AM_ROM AM_WRITE(astrocade_funcgen_w)
81   AM_RANGE(0x1000, 0x3fff) AM_ROM /* Star Fortress writes in here?? */
82   AM_RANGE(0x4000, 0x4fff) AM_RAM AM_BASE_MEMBER(astrocde_state, m_videoram) /* ASG */
83ADDRESS_MAP_END
84
85
86static ADDRESS_MAP_START( astrocade_io, AS_IO, 8 )
87   AM_RANGE(0x00, 0x1f) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_READWRITE(astrocade_data_chip_register_r, astrocade_data_chip_register_w)
88ADDRESS_MAP_END
89
90static INPUT_CHANGED( set_write_protect )  // run when RAM expansion write protect switch is changed
91{
92   int ram_expansion_installed = 0, write_protect_on = 0, expansion_ram_start = 0, expansion_ram_end = 0, shadow_ram_end = 0;
93   address_space *space = field->port->machine().device("maincpu")->memory().space(AS_PROGRAM);
94   UINT8 *expram = ram_get_ptr(field->port->machine().device("ram_tag"));
95
96   get_ram_expansion_settings(space, ram_expansion_installed, write_protect_on, expansion_ram_start, expansion_ram_end, shadow_ram_end);  // passing by reference
97
98    if (ram_expansion_installed == 1)
99    {
100        if (write_protect_on == 0)  // write protect off, so install memory normally
101        {
102            space->install_ram(expansion_ram_start, expansion_ram_end, expram);
103            if (shadow_ram_end > expansion_ram_end)
104                space->install_ram(expansion_ram_end + 1, shadow_ram_end, expram);
105        }
106        else  // write protect on, so make memory read only
107        {
108            space->nop_write(expansion_ram_start, expansion_ram_end);
109        }
110     }
111}
112
113/*************************************
114 *
115 *  Input ports
116 *
117 *
118 *  The Astrocade has ports for four hand controllers.  Each controller has a
119 *  knob on top that can be simultaneously pushed as an eight-way joystick and
120 *  twisted as a paddle, in addition to a trigger button.  The knob can twist
121 *  through about 270 degrees, registering 256 unique positions.  It does not
122 *  autocenter.  When selecting options on the menu, twisting the knob to the
123 *  right gives lower numbers, and twisting to the left gives larger numbers.
124 *  Paddle games like Clowns have more intuitive behavior -- twisting to the
125 *  right moves the character right.
126 *
127 *  There is a 24-key keypad on the system itself (6 rows, 4 columns).  It is
128 *  labeled for the built-in calculator, but overlays were released for other
129 *  programs, the most popular being the BASIC cartridges, which allowed a
130 *  large number of inputs by making the bottom row shift buttons.  The labels
131 *  below first list the calculator key, then the BASIC keys in the order of no
132 *  shift, GREEN shift, RED shift, BLUE shift, WORDS shift.
133 *
134 *************************************/
135
136static INPUT_PORTS_START( astrocde )
137   PORT_START("P1HANDLE")
138   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP)    PORT_PLAYER(1) PORT_8WAY
139   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN)  PORT_PLAYER(1) PORT_8WAY
140   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT)  PORT_PLAYER(1) PORT_8WAY
141   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT) PORT_PLAYER(1) PORT_8WAY
142   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_BUTTON1)        PORT_PLAYER(1)
143   PORT_BIT(0xe0, IP_ACTIVE_HIGH, IPT_UNUSED)
144
145   PORT_START("P2HANDLE")
146   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP)    PORT_PLAYER(2) PORT_8WAY
147   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN)  PORT_PLAYER(2) PORT_8WAY
148   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT)  PORT_PLAYER(2) PORT_8WAY
149   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT) PORT_PLAYER(2) PORT_8WAY
150   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_BUTTON1)        PORT_PLAYER(2)
151   PORT_BIT(0xe0, IP_ACTIVE_HIGH, IPT_UNUSED)
152
153   PORT_START("P3HANDLE")
154   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP)    PORT_PLAYER(3) PORT_8WAY
155   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN)  PORT_PLAYER(3) PORT_8WAY
156   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT)  PORT_PLAYER(3) PORT_8WAY
157   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT) PORT_PLAYER(3) PORT_8WAY
158   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_BUTTON1)        PORT_PLAYER(3)
159   PORT_BIT(0xe0, IP_ACTIVE_HIGH, IPT_UNUSED)
160
161   PORT_START("P4HANDLE")
162   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP)    PORT_PLAYER(4) PORT_8WAY
163   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN)  PORT_PLAYER(4) PORT_8WAY
164   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT)  PORT_PLAYER(4) PORT_8WAY
165   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT) PORT_PLAYER(4) PORT_8WAY
166   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_BUTTON1)        PORT_PLAYER(4)
167   PORT_BIT(0xe0, IP_ACTIVE_HIGH, IPT_UNUSED)
168
169   PORT_START("KEYPAD0")
170   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("%   \xC3\xB7         [   ]   LIST") PORT_CODE(KEYCODE_O)
171   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("/   x     J   K   L   NEXT") PORT_CODE(KEYCODE_SLASH_PAD)
172   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("x   -     V   W   X   IF") PORT_CODE(KEYCODE_ASTERISK)
173   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("-   +     &   @   *   GOTO") PORT_CODE(KEYCODE_MINUS_PAD)
174   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("+   =     #   %   :   PRINT") PORT_CODE(KEYCODE_PLUS_PAD)
175   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("=   WORDS Shift") PORT_CODE(KEYCODE_ENTER_PAD)
176   PORT_BIT(0xc0, IP_ACTIVE_HIGH, IPT_UNUSED )
177
178   PORT_START("KEYPAD1")
179   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("\xE2\x86\x93   HALT              RUN") PORT_CODE(KEYCODE_PGDN)
180   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("CH  9     G   H   I   STEP") PORT_CODE(KEYCODE_H)
181   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("9   6     S   T   U   RND") PORT_CODE(KEYCODE_9)
182   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("6   3     \xE2\x86\x91   .   \xE2\x86\x93   BOX") PORT_CODE(KEYCODE_6)
183   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("3   ERASE (   ;   )") PORT_CODE(KEYCODE_3)
184   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME(".   BLUE Shift") PORT_CODE(KEYCODE_STOP)
185   PORT_BIT(0xc0, IP_ACTIVE_HIGH, IPT_UNUSED)
186
187   PORT_START("KEYPAD2")
188   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("\xE2\x86\x91   PAUSE     /   \\") PORT_CODE(KEYCODE_PGUP)
189   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("MS  8     D   E   F   TO") PORT_CODE(KEYCODE_S)
190   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("8   5     P   Q   R   RETN") PORT_CODE(KEYCODE_8)
191   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("5   2     \xE2\x86\x90   '   \xE2\x86\x92   LINE") PORT_CODE(KEYCODE_5)
192   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("2   0     <   \"   >   INPUT") PORT_CODE(KEYCODE_2)
193   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("0   RED Shift") PORT_CODE(KEYCODE_0)
194   PORT_BIT(0xc0, IP_ACTIVE_HIGH, IPT_UNUSED)
195
196   PORT_START("KEYPAD3")
197   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("C   GO                +10") PORT_CODE(KEYCODE_C)
198   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("MR  7     A   B   C   FOR") PORT_CODE(KEYCODE_R)
199   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("7   4     M   N   O   GOSB") PORT_CODE(KEYCODE_7)
200   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("4   1     Y   Z   !   CLEAR") PORT_CODE(KEYCODE_4)
201   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("1   SPACE $   ,   ?") PORT_CODE(KEYCODE_1)
202   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("CE  GREEN Shift") PORT_CODE(KEYCODE_E)
203   PORT_BIT(0xc0, IP_ACTIVE_HIGH, IPT_UNUSED)
204
205   PORT_START("P1_KNOB")
206   PORT_BIT(0xff, 0x00, IPT_PADDLE) PORT_INVERT PORT_SENSITIVITY(85) PORT_KEYDELTA(10) PORT_CENTERDELTA(0) PORT_MINMAX(0,255) PORT_CODE_DEC(KEYCODE_Z) PORT_CODE_INC(KEYCODE_X) PORT_PLAYER(1)
207
208   PORT_START("P2_KNOB")
209   PORT_BIT(0xff, 0x00, IPT_PADDLE) PORT_INVERT PORT_SENSITIVITY(85) PORT_KEYDELTA(10) PORT_CENTERDELTA(0) PORT_MINMAX(0,255) PORT_CODE_DEC(KEYCODE_N) PORT_CODE_INC(KEYCODE_M) PORT_PLAYER(2)
210
211   PORT_START("P3_KNOB")
212   PORT_BIT(0xff, 0x00, IPT_PADDLE) PORT_INVERT PORT_SENSITIVITY(85) PORT_KEYDELTA(10) PORT_CENTERDELTA(0) PORT_MINMAX(0,255) PORT_CODE_DEC(KEYCODE_Q) PORT_CODE_INC(KEYCODE_W) PORT_PLAYER(3)
213
214   PORT_START("P4_KNOB")
215   PORT_BIT(0xff, 0x00, IPT_PADDLE) PORT_INVERT PORT_SENSITIVITY(85) PORT_KEYDELTA(10) PORT_CENTERDELTA(0) PORT_MINMAX(0,255) PORT_CODE_DEC(KEYCODE_Y) PORT_CODE_INC(KEYCODE_U) PORT_PLAYER(4)
216
217    PORT_START("CFG")   /* machine config */
218   PORT_DIPNAME( 0x3f, 0x00, "RAM Expansion")
219   PORT_DIPSETTING(   0x00, "No RAM Expansion")
220   PORT_DIPSETTING(   0x01, "16KB Viper System 1 RAM Expansion")
221   PORT_DIPSETTING(   0x02, "32KB Lil' WHITE RAM Expansion")
222   PORT_DIPSETTING(   0x04, "R&L 64K RAM Board (44K installed)")
223   PORT_DIPSETTING(   0x08, "4KB Blue RAM Expansion")
224   PORT_DIPSETTING(   0x10, "16KB Blue RAM Expansion")
225   PORT_DIPSETTING(   0x20, "32KB Blue RAM Expansion")
226
227   PORT_START("PROTECT")  /* Write protect RAM */
228   PORT_DIPNAME( 0x01, 0x00, "Write Protect RAM") PORT_CHANGED(set_write_protect, 0)
229   PORT_DIPSETTING( 0x00, "Write Protect Off")
230   PORT_DIPSETTING( 0x01, "Write Protect On")
231INPUT_PORTS_END
232
233
234/*************************************
235 *
236 *  Machine drivers
237 *
238 *************************************/
239
240static MACHINE_CONFIG_START( astrocde, astrocde_state )
241   /* basic machine hardware */
242   MCFG_CPU_ADD("maincpu", Z80, ASTROCADE_CLOCK/4)        /* 1.789 MHz */
243   MCFG_CPU_PROGRAM_MAP(astrocade_mem)
244   MCFG_CPU_IO_MAP(astrocade_io)
245
246   MCFG_MACHINE_RESET( astrocde )
247
248   /* video hardware */
249   MCFG_SCREEN_ADD("screen", RASTER)
250   MCFG_SCREEN_RAW_PARAMS(ASTROCADE_CLOCK, 455, 0, 352, 262, 0, 240)
251   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
252   MCFG_SCREEN_UPDATE(astrocde)
253
254   MCFG_PALETTE_LENGTH(512)
255   MCFG_PALETTE_INIT(astrocde)
256
257   MCFG_VIDEO_START(astrocde)
258
259   /* sound hardware */
260   MCFG_SPEAKER_STANDARD_MONO("mono")
261   MCFG_SOUND_ADD("astrocade1", ASTROCADE, ASTROCADE_CLOCK/4)
262   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
263
264    /* optional expansion ram (installed in MACHINE_RESET)*/
265   MCFG_RAM_ADD("ram_tag")
266   MCFG_RAM_DEFAULT_SIZE("32k")
267
268   /* cartridge */
269   MCFG_CARTSLOT_ADD("cart")
270   MCFG_CARTSLOT_EXTENSION_LIST("bin")
271   MCFG_CARTSLOT_INTERFACE("astrocde_cart")
272
273   /* Software lists */
274   MCFG_SOFTWARE_LIST_ADD("cart_list","astrocde")
275MACHINE_CONFIG_END
276
277
278/*************************************
279 *
280 *  ROM definitions
281 *
282 *************************************/
283
284ROM_START( astrocde )
285   ROM_REGION( 0x10000, "maincpu", 0 )
286   ROM_LOAD( "astro.bin",  0x0000, 0x2000, CRC(ebc77f3a) SHA1(b902c941997c9d150a560435bf517c6a28137ecc) )
287   ROM_CART_LOAD( "cart", 0x2000, 0x8000, 0 )
288ROM_END
289
290ROM_START( astrocdl )
291   ROM_REGION( 0x10000, "maincpu", 0 )
292   ROM_LOAD( "ballyhlc.bin",  0x0000, 0x2000, CRC(d7c517ba) SHA1(6b2bef5d970e54ed204549f58ba6d197a8bfd3cc) )
293   ROM_CART_LOAD( "cart", 0x2000, 0x8000, 0 )
294ROM_END
295
296ROM_START( astrocdw )
297   ROM_REGION( 0x10000, "maincpu", 0 )
298   ROM_LOAD( "bioswhit.bin",  0x0000, 0x2000, CRC(6eb53e79) SHA1(d84341feec1a0a0e8aa6151b649bc3cf6ef69fbf) )
299   ROM_CART_LOAD( "cart", 0x2000, 0x8000, 0 )
300ROM_END
301
302/*************************************
303 *
304 *  Driver initialization
305 *
306 *************************************/
307
308static DRIVER_INIT( astrocde )
309{
310   astrocde_state *state = machine.driver_data<astrocde_state>();
311   state->m_video_config = AC_SOUND_PRESENT | AC_LIGHTPEN_INTS;
312}
313
314MACHINE_RESET( astrocde )
315{
316    int ram_expansion_installed = 0, write_protect_on = 0, expansion_ram_start = 0, expansion_ram_end = 0, shadow_ram_end = 0;
317    address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
318    UINT8 *expram = ram_get_ptr(machine.device("ram_tag"));
319    space->unmap_readwrite(0x5000, 0xffff);  // unmap any previously installed expansion RAM
320
321    get_ram_expansion_settings(space, ram_expansion_installed, write_protect_on, expansion_ram_start, expansion_ram_end, shadow_ram_end);  // passing by reference
322
323    if (ram_expansion_installed == 1)
324    {
325        if (write_protect_on == 0)  // write protect off, so install memory normally
326        {
327            space->install_ram(expansion_ram_start, expansion_ram_end, expram);
328            if (shadow_ram_end > expansion_ram_end)
329                space->install_ram(expansion_ram_end + 1, shadow_ram_end, expram);
330        }
331        else  // write protect on, so make memory read only
332        {
333            space->nop_write(expansion_ram_start, expansion_ram_end);
334        }
335     }
336}
337
338void get_ram_expansion_settings(address_space *space, int &ram_expansion_installed, int &write_protect_on, int &expansion_ram_start, int &expansion_ram_end, int &shadow_ram_end)
339{
340    if (input_port_read(space->machine(), "PROTECT") == 0x01)
341        write_protect_on = 1;
342    else
343        write_protect_on = 0;
344
345    ram_expansion_installed = 1;
346
347    switch(input_port_read(space->machine(), "CFG"))  // check RAM expansion configuration and set address ranges
348    {
349        case 0x00:  // No RAM Expansion
350             ram_expansion_installed = 0;
351             break;
352        case 0x01:  // 16KB Viper System 1 RAM Expansion
353             expansion_ram_start = 0x6000;
354             expansion_ram_end = 0x9fff;
355             shadow_ram_end = 0;
356             break;
357        case 0x02:  // "32KB Lil' WHITE RAM Expansion
358             expansion_ram_start = 0x5000;
359             expansion_ram_end = 0xcfff;
360             shadow_ram_end = 0xffff;
361             break;
362        case 0x04:  // R&L 64K RAM Board (44KB installed)
363             expansion_ram_start = 0x5000;
364             expansion_ram_end = 0xffff;
365             shadow_ram_end = 0;
366             break;
367        case 0x08:  // 4KB Blue RAM Expansion
368             expansion_ram_start = 0x6000;
369             expansion_ram_end = 0x6fff;
370             shadow_ram_end = 0;
371             break;
372        case 0x10:  // 16KB Blue RAM Expansion
373             expansion_ram_start = 0x6000;
374             expansion_ram_end = 0x9fff;
375             shadow_ram_end = 0;
376             break;
377        case 0x20:  // 32KB Blue RAM Expansion
378             expansion_ram_start = 0x6000;
379             expansion_ram_end = 0xdfff;
380             shadow_ram_end = 0;
381             break;
382        default:
383            break;
384    }
385}
386
387
388/*************************************
389 *
390 *  Driver definitions
391 *
392 *************************************/
393
394/*    YEAR  NAME      PARENT    COMPAT    MACHINE   INPUT     INIT      COMPANY                FULLNAME                     FLAGS */
395CONS( 1978, astrocde, 0,        0,        astrocde, astrocde, astrocde, "Bally Manufacturing", "Bally Professional Arcade", GAME_SUPPORTS_SAVE )
396CONS( 1977, astrocdl, astrocde, 0,        astrocde, astrocde, astrocde, "Bally Manufacturing", "Bally Home Library Computer", GAME_SUPPORTS_SAVE )
397CONS( 1977, astrocdw, astrocde, 0,        astrocde, astrocde, astrocde, "Bally Manufacturing", "Bally Computer System", GAME_SUPPORTS_SAVE )
src/mess/drivers/amiga.c
r11460r11461
1/***************************************************************************
2Commodore Amiga - (c) 1985, Commodore Business Machines Co.
3
4Preliminary driver by:
5
6Ernesto Corvi
7
8Note 1: The 'fast-mem' memory detector in Kickstart 1.2 expects to
9see the custom chips at the end of any present fast memory (mapped
10from $C00000 onwards). I assume this is a bug, given that the routine
11was entirely rewritten for Kickstart 1.3. So the strategy is, for
12any machine that can run Kickstart 1.2 (a500,a1000 and a2000), we
13map a mirror of the custom chips right after any fast-mem we mapped.
14If we didn't map any, then we still put a mirror, but where fast-mem
15would commence ($C00000).
16
17***************************************************************************/
18
19/* Core includes */
20#include "emu.h"
21#include "includes/amiga.h"
22
23/* Components */
24#include "cpu/m68000/m68000.h"
25#include "cpu/m6502/m6502.h"
26#include "machine/6525tpi.h"
27#include "machine/6526cia.h"
28#include "machine/amigafdc.h"
29#include "machine/amigakbd.h"
30#include "machine/amigacd.h"
31#include "machine/amigacrt.h"
32#include "machine/msm6242.h"
33#include "machine/ctronics.h"
34#include "machine/nvram.h"
35#include "sound/cdda.h"
36
37/* Devices */
38#include "imagedev/chd_cd.h"
39#include "imagedev/cartslot.h"
40
41
42static READ8_DEVICE_HANDLER( amiga_cia_0_portA_r );
43static READ8_DEVICE_HANDLER( amiga_cia_0_cdtv_portA_r );
44static WRITE8_DEVICE_HANDLER( amiga_cia_0_portA_w );
45
46/***************************************************************************
47  Battery Backed-Up Clock (MSM6264)
48***************************************************************************/
49
50static READ16_HANDLER( amiga_clock_r )
51{
52   device_t *rtc = space->machine().device("rtc");
53   return msm6242_r(rtc, offset / 2);
54}
55
56
57static WRITE16_HANDLER( amiga_clock_w )
58{
59   device_t *rtc = space->machine().device("rtc");
60   msm6242_w(rtc, offset / 2, data);
61}
62
63
64/***************************************************************************
65    CENTRONICS PORT
66***************************************************************************/
67
68static READ8_DEVICE_HANDLER( amiga_cia_1_porta_r )
69{
70   UINT8 result = 0;
71
72   /* centronics status is stored in PA0 to PA2 */
73   result |= centronics_busy_r(device) << 0;
74   result |= !centronics_pe_r(device) << 1;
75   result |= centronics_vcc_r(device) << 2;
76
77   /* PA3 to PA7 store the serial line status (not emulated) */
78
79   return result;
80}
81
82static const centronics_interface amiga_centronics_config =
83{
84   FALSE,
85   DEVCB_DEVICE_LINE("cia_0", mos6526_flag_w),
86   DEVCB_NULL,
87   DEVCB_NULL
88};
89
90
91/***************************************************************************
92  Address maps
93***************************************************************************/
94
95static ADDRESS_MAP_START(amiga_mem, AS_PROGRAM, 16)
96   ADDRESS_MAP_UNMAP_HIGH
97   AM_RANGE(0x000000, 0x07ffff) AM_MIRROR(0x80000) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(amiga_state, m_chip_ram, m_chip_ram_size)
98   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia_r, amiga_cia_w)
99   AM_RANGE(0xc00000, 0xc7ffff) AM_RAM /* slow-mem */
100   AM_RANGE(0xc80000, 0xcfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w)   /* see Note 1 above */
101   AM_RANGE(0xdf0000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE_MEMBER(amiga_state, m_custom_regs)   /* Custom Chips */
102   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE(amiga_autoconfig_r, amiga_autoconfig_w)
103   AM_RANGE(0xf80000, 0xffffff) AM_ROM AM_REGION("user1", 0)   /* System ROM - mirror */
104ADDRESS_MAP_END
105
106static ADDRESS_MAP_START(keyboard_mem, AS_PROGRAM, 8)
107   AM_RANGE(0x0000, 0x003f) AM_RAM /* internal user ram */
108   AM_RANGE(0x0040, 0x007f) AM_NOP /* unassigned */
109   AM_RANGE(0x0080, 0x0080) AM_NOP /* port a */
110   AM_RANGE(0x0081, 0x0081) AM_NOP /* port b */
111   AM_RANGE(0x0082, 0x0082) AM_NOP /* port c */
112   AM_RANGE(0x0083, 0x0083) AM_NOP /* port d */
113   AM_RANGE(0x0084, 0x0085) AM_NOP /* latch */
114   AM_RANGE(0x0086, 0x0087) AM_NOP /* count */
115   AM_RANGE(0x0088, 0x0088) AM_NOP /* upper latch & transfer latch to counter */
116   AM_RANGE(0x0089, 0x0089) AM_NOP /* clear pa0 pos edge detected */
117   AM_RANGE(0x008a, 0x008a) AM_NOP /* clear pa1 neg edge detected */
118   AM_RANGE(0x008b, 0x008e) AM_NOP /* unassigned */
119   AM_RANGE(0x008f, 0x008f) AM_NOP /* control register */
120   AM_RANGE(0x0090, 0x07ff) AM_NOP /* unassigned */
121   AM_RANGE(0x0800, 0x0fff) AM_ROM AM_REGION("keyboard", 0) /* internal mask rom */
122ADDRESS_MAP_END
123
124
125/*
126 * CDTV memory map (source: http://www.l8r.net/technical/cdtv-technical.html)
127 *
128 * 000000-0FFFFF Chip memory
129 * 100000-1FFFFF Space for extra chip memory (Megachip)
130 * 200000-9FFFFF Space for AutoConfig memory
131 * A00000-BFFFFF CIA chips
132 * C00000-C7FFFF Space for slow-fast memory
133 * C80000-DBFFFF Space
134 * DC0000-DC7FFF Power backed-up real time clock
135 * DC8000-DC87FF Non-volatile RAM
136 * DC8800-DCFFFF Space in non-volatile RAM decoded area
137 * DD0000-DEFFFF Space
138 * DF0000-DFFFFF Custom chips
139 * E00000-E7FFFF Memory card address space for front panel memory card
140 * E80000-E8FFFF AutoConfig configuration space
141 * E90000-E9FFFF First AutoConfig device, used by DMAC
142 * EA0000-EFFFFF Space for other AutoConfig devices
143 * F00000-F3FFFF CDTV ROM
144 * F40000-F7FFFF Space in CDTV ROM decoded area
145 * F80000-FBFFFF Space in Kickstart ROM decoded area (used by Kickstart 2)
146 * FC0000-FFFFFF Kickstart ROM
147 *
148 */
149
150static ADDRESS_MAP_START(cdtv_mem, AS_PROGRAM, 16)
151   AM_RANGE(0x000000, 0x0fffff) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(amiga_state, m_chip_ram, m_chip_ram_size)
152   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia_r, amiga_cia_w)
153   AM_RANGE(0xdc0000, 0xdc003f) AM_READWRITE(amiga_clock_r, amiga_clock_w)
154   AM_RANGE(0xdc8000, 0xdc87ff) AM_RAM AM_SHARE("nvram")
155   AM_RANGE(0xdf0000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE_MEMBER(amiga_state, m_custom_regs)   /* Custom Chips */
156   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE(amiga_autoconfig_r, amiga_autoconfig_w)
157   AM_RANGE(0xf00000, 0xffffff) AM_ROM AM_REGION("user1", 0)   /* CDTV & System ROM */
158ADDRESS_MAP_END
159
160static ADDRESS_MAP_START(cdtv_rcmcu_mem, AS_PROGRAM, 8)
161   AM_RANGE(0x0000, 0x003f) AM_RAM /* internal user ram */
162   AM_RANGE(0x0040, 0x007f) AM_NOP /* unassigned */
163   AM_RANGE(0x0080, 0x0080) AM_NOP /* port a */
164   AM_RANGE(0x0081, 0x0081) AM_NOP /* port b */
165   AM_RANGE(0x0082, 0x0082) AM_NOP /* port c */
166   AM_RANGE(0x0083, 0x0083) AM_NOP /* port d */
167   AM_RANGE(0x0084, 0x0085) AM_NOP /* latch */
168   AM_RANGE(0x0086, 0x0087) AM_NOP /* count */
169   AM_RANGE(0x0088, 0x0088) AM_NOP /* upper latch & transfer latch to counter */
170   AM_RANGE(0x0089, 0x0089) AM_NOP /* clear pa0 pos edge detected */
171   AM_RANGE(0x008a, 0x008a) AM_NOP /* clear pa1 neg edge detected */
172   AM_RANGE(0x008b, 0x008e) AM_NOP /* unassigned */
173   AM_RANGE(0x008f, 0x008f) AM_NOP /* control register */
174   AM_RANGE(0x0090, 0x07ff) AM_NOP /* unassigned */
175   AM_RANGE(0x0800, 0x0fff) AM_ROM AM_REGION("rcmcu", 0) /* internal mask rom */
176ADDRESS_MAP_END
177
178static ADDRESS_MAP_START(a1000_mem, AS_PROGRAM, 16)
179   AM_RANGE(0x000000, 0x03ffff) AM_MIRROR(0xc0000) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(amiga_state, m_chip_ram, m_chip_ram_size)
180   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia_r, amiga_cia_w)
181   AM_RANGE(0xc00000, 0xc3ffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) /* See Note 1 above */
182   AM_RANGE(0xdf0000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE_MEMBER(amiga_state, m_custom_regs)   /* Custom Chips */
183   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE(amiga_autoconfig_r, amiga_autoconfig_w)
184   AM_RANGE(0xf80000, 0xfbffff) AM_ROM AM_REGION("user1", 0)   /* Bootstrap ROM */
185   AM_RANGE(0xfc0000, 0xffffff) AM_RAMBANK("bank2")   /* Writable Control Store RAM */
186ADDRESS_MAP_END
187
188
189/***************************************************************************
190  Inputs
191***************************************************************************/
192
193static INPUT_PORTS_START( amiga_common )
194   PORT_START("input")
195   PORT_CONFNAME( 0x20, 0x00, "Input Port 0 Device")
196   PORT_CONFSETTING( 0x00, "Mouse" )
197   PORT_CONFSETTING( 0x20, DEF_STR(Joystick) )
198   PORT_CONFNAME( 0x10, 0x10, "Input Port 1 Device")
199   PORT_CONFSETTING( 0x00, "Mouse" )
200   PORT_CONFSETTING( 0x10, DEF_STR(Joystick) )
201
202   PORT_START("CIA0PORTA")
203   PORT_BIT( 0x3f, IP_ACTIVE_LOW, IPT_SPECIAL )
204   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
205   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
206
207   PORT_START("JOY0DAT")
208   PORT_BIT( 0x0303, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(amiga_joystick_convert, "P1JOY")
209   PORT_BIT( 0xfcfc, IP_ACTIVE_HIGH, IPT_UNUSED )
210
211   PORT_START("JOY1DAT")
212   PORT_BIT( 0x0303, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(amiga_joystick_convert, "P2JOY")
213   PORT_BIT( 0xfcfc, IP_ACTIVE_HIGH, IPT_UNUSED )
214
215   PORT_START("POTGO")
216   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNUSED )
217   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
218   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_UNUSED )
219   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
220   PORT_BIT( 0xaaff, IP_ACTIVE_HIGH, IPT_UNUSED )
221
222   PORT_START("P1JOY")
223   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
224   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1)
225   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1)
226   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
227
228   PORT_START("P2JOY")
229   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(2)
230   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
231   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2)
232   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
233
234   PORT_START("P0MOUSEX")
235   PORT_BIT( 0xff, 0x00, IPT_MOUSE_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_PLAYER(1)
236
237   PORT_START("P0MOUSEY")
238   PORT_BIT( 0xff, 0x00, IPT_MOUSE_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_PLAYER(1)
239
240   PORT_START("P1MOUSEX")
241   PORT_BIT( 0xff, 0x00, IPT_MOUSE_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_PLAYER(2)
242
243   PORT_START("P1MOUSEY")
244   PORT_BIT( 0xff, 0x00, IPT_MOUSE_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_PLAYER(2)
245
246   PORT_INCLUDE( amiga_us_keyboard )
247
248INPUT_PORTS_END
249
250
251static INPUT_PORTS_START( amiga )
252   PORT_START("hardware")
253   PORT_CONFNAME( 0x08, 0x08, "Battery backed-up RTC")
254   PORT_CONFSETTING( 0x00, "Not Installed" )
255   PORT_CONFSETTING( 0x08, "Installed" )
256
257   PORT_INCLUDE( amiga_common )
258INPUT_PORTS_END
259
260
261/* TODO: Support for the CDTV remote control */
262static INPUT_PORTS_START( cdtv )
263   PORT_INCLUDE( amiga_common )
264INPUT_PORTS_END
265
266/***************************************************************************
267  Machine drivers
268***************************************************************************/
269
270static MACHINE_START( cdtv )
271{
272   MACHINE_START_CALL( amigacd );
273}
274
275
276static MACHINE_RESET( cdtv )
277{
278   MACHINE_RESET_CALL( amiga );
279
280   /* initialize the cdrom controller */
281   MACHINE_RESET_CALL( amigacd );
282}
283
284static const mos6526_interface cia_0_ntsc_intf =
285{
286   60,                                          /* tod_clock */
287   DEVCB_LINE(amiga_cia_0_irq),                     /* irq_func */
288   DEVCB_DEVICE_LINE("centronics", centronics_strobe_w),   /* pc_func */
289   DEVCB_NULL,
290   DEVCB_NULL,
291   DEVCB_HANDLER(amiga_cia_0_portA_r),
292   DEVCB_HANDLER(amiga_cia_0_portA_w),                  /* port A */
293   DEVCB_NULL,
294   DEVCB_DEVICE_HANDLER("centronics", centronics_data_w)   /* port B */
295};
296
297static const mos6526_interface cia_0_pal_intf =
298{
299   50,                                          /* tod_clock */
300   DEVCB_LINE(amiga_cia_0_irq),                     /* irq_func */
301   DEVCB_DEVICE_LINE("centronics", centronics_strobe_w),   /* pc_func */
302   DEVCB_NULL,
303   DEVCB_NULL,
304   DEVCB_HANDLER(amiga_cia_0_portA_r),
305   DEVCB_HANDLER(amiga_cia_0_portA_w),                  /* port A */
306   DEVCB_NULL,
307   DEVCB_DEVICE_HANDLER("centronics", centronics_data_w)   /* port B */
308};
309
310static const mos6526_interface cia_1_intf =
311{
312   0,                                          /* tod_clock */
313   DEVCB_LINE(amiga_cia_1_irq),                     /* irq_func */
314   DEVCB_NULL,                                    /* pc_func */
315   DEVCB_NULL,
316   DEVCB_NULL,
317   DEVCB_DEVICE_HANDLER("centronics", amiga_cia_1_porta_r),
318   DEVCB_NULL,                                    /* port A */
319   DEVCB_NULL,
320   DEVCB_DEVICE_HANDLER("fdc", amiga_fdc_control_w)      /* port B */
321};
322
323static const mos6526_interface cia_0_cdtv_intf =
324{
325   0,                                          /* tod_clock */
326   DEVCB_LINE(amiga_cia_0_irq),                     /* irq_func */
327   DEVCB_DEVICE_LINE("centronics", centronics_strobe_w),   /* pc_func */
328   DEVCB_NULL,
329   DEVCB_NULL,
330   DEVCB_HANDLER(amiga_cia_0_cdtv_portA_r),
331   DEVCB_HANDLER(amiga_cia_0_portA_w),                  /* port A */
332   DEVCB_NULL,
333   DEVCB_DEVICE_HANDLER("centronics", centronics_data_w)   /* port B */
334};
335
336static const mos6526_interface cia_1_cdtv_intf =
337{
338   0,                                          /* tod_clock */
339   DEVCB_LINE(amiga_cia_1_irq),                     /* irq_func */
340   DEVCB_NULL,   /* pc_func */
341   DEVCB_NULL,
342   DEVCB_NULL,
343   DEVCB_DEVICE_HANDLER("centronics", amiga_cia_1_porta_r),
344   DEVCB_NULL,                                    /* port A */
345   DEVCB_NULL,
346   DEVCB_NULL                                    /* port B */
347};
348
349static const tpi6525_interface cdtv_tpi_intf =
350{
351   DEVCB_LINE(amigacd_tpi6525_irq),
352   DEVCB_NULL,
353   DEVCB_NULL,
354   DEVCB_NULL,
355   DEVCB_HANDLER(amigacd_tpi6525_portb_w),
356   DEVCB_HANDLER(amigacd_tpi6525_portc_r),
357   DEVCB_NULL,
358   DEVCB_NULL,
359   DEVCB_NULL
360};
361
362
363static MACHINE_CONFIG_FRAGMENT( amiga_cartslot )
364   MCFG_CARTSLOT_ADD("cart")
365   MCFG_CARTSLOT_EXTENSION_LIST("rom,bin")
366   MCFG_CARTSLOT_NOT_MANDATORY
367MACHINE_CONFIG_END
368
369static MACHINE_CONFIG_START( ntsc, amiga_state )
370   /* basic machine hardware */
371   MCFG_CPU_ADD("maincpu", M68000, AMIGA_68000_NTSC_CLOCK)
372   MCFG_CPU_PROGRAM_MAP(amiga_mem)
373
374   MCFG_CPU_ADD("keyboard", M6502, XTAL_1MHz) /* 1 MHz? */
375   MCFG_CPU_PROGRAM_MAP(keyboard_mem)
376
377   MCFG_SCREEN_ADD("screen", RASTER)
378   MCFG_SCREEN_REFRESH_RATE(59.997)
379   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
380
381   MCFG_MACHINE_RESET( amiga )
382
383    /* video hardware */
384   MCFG_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK)
385   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
386   MCFG_SCREEN_SIZE(228*4, 262)
387   MCFG_SCREEN_VISIBLE_AREA(214, (228*4)-1, 34, 262-1)
388   MCFG_SCREEN_UPDATE(amiga)
389
390   MCFG_PALETTE_LENGTH(4096)
391   MCFG_PALETTE_INIT( amiga )
392
393   MCFG_VIDEO_START(amiga)
394
395   /* devices */
396   MCFG_MSM6242_ADD("rtc")
397   MCFG_CENTRONICS_ADD("centronics", amiga_centronics_config)
398
399   /* sound hardware */
400   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
401
402   MCFG_SOUND_ADD("amiga", AMIGA, 3579545)
403   MCFG_SOUND_ROUTE(0, "lspeaker", 0.50)
404   MCFG_SOUND_ROUTE(1, "rspeaker", 0.50)
405   MCFG_SOUND_ROUTE(2, "rspeaker", 0.50)
406   MCFG_SOUND_ROUTE(3, "lspeaker", 0.50)
407
408   /* cia */
409   MCFG_MOS8520_ADD("cia_0", AMIGA_68000_NTSC_CLOCK / 10, cia_0_ntsc_intf)
410   MCFG_MOS8520_ADD("cia_1", AMIGA_68000_NTSC_CLOCK, cia_1_intf)
411
412   MCFG_AMIGA_FDC_ADD("fdc")
413MACHINE_CONFIG_END
414
415static MACHINE_CONFIG_DERIVED( a1000n, ntsc )
416   MCFG_CPU_MODIFY("maincpu")
417   MCFG_CPU_PROGRAM_MAP(a1000_mem)
418MACHINE_CONFIG_END
419
420static MACHINE_CONFIG_DERIVED( a500n, ntsc )
421   MCFG_FRAGMENT_ADD(amiga_cartslot)
422MACHINE_CONFIG_END
423
424
425static MACHINE_CONFIG_DERIVED( cdtv, ntsc )
426   MCFG_CPU_REPLACE("maincpu", M68000, CDTV_CLOCK_X1 / 4)
427   MCFG_CPU_PROGRAM_MAP(cdtv_mem)
428
429   MCFG_DEVICE_REMOVE("keyboard")
430
431   MCFG_CPU_ADD("rcmcu", M6502, XTAL_1MHz) /* 1 MHz? */
432   MCFG_CPU_PROGRAM_MAP(cdtv_rcmcu_mem)
433   MCFG_DEVICE_DISABLE()
434
435//  MCFG_CPU_ADD("lcd", LC6554, XTAL_4MHz) /* 4 MHz? */
436//  MCFG_CPU_PROGRAM_MAP(cdtv_lcd_mem)
437
438   MCFG_MACHINE_START( cdtv )
439   MCFG_MACHINE_RESET( cdtv )
440
441   MCFG_NVRAM_ADD_0FILL("nvram")
442
443   MCFG_SOUND_ADD( "cdda", CDDA, 0 )
444   MCFG_SOUND_ROUTE( 0, "lspeaker", 1.0 )
445   MCFG_SOUND_ROUTE( 1, "rspeaker", 1.0 )
446
447   /* cdrom */
448   MCFG_CDROM_ADD( "cdrom" )
449   MCFG_CDROM_INTERFACE("cdrom")
450   MCFG_SOFTWARE_LIST_ADD("cd_list", "cdtv")
451
452   MCFG_TPI6525_ADD("tpi6525", cdtv_tpi_intf)
453
454   /* cia */
455   MCFG_DEVICE_REMOVE("cia_0")
456   MCFG_DEVICE_REMOVE("cia_1")
457   MCFG_MOS8520_ADD("cia_0", CDTV_CLOCK_X1 / 40, cia_0_cdtv_intf)
458   MCFG_MOS8520_ADD("cia_1", CDTV_CLOCK_X1 / 4, cia_1_cdtv_intf)
459MACHINE_CONFIG_END
460
461
462static MACHINE_CONFIG_DERIVED( pal, ntsc )
463
464   /* adjust for PAL specs */
465   MCFG_CPU_MODIFY("maincpu")
466   MCFG_CPU_CLOCK( AMIGA_68000_PAL_CLOCK)
467
468   MCFG_SCREEN_MODIFY("screen")
469   MCFG_SCREEN_REFRESH_RATE(50)
470   MCFG_SCREEN_SIZE(228*4, 312)
471   MCFG_SCREEN_VISIBLE_AREA(214, (228*4)-1, 34, 312-1)
472
473   /* cia */
474   MCFG_DEVICE_REMOVE("cia_0")
475   MCFG_MOS8520_ADD("cia_0", AMIGA_68000_PAL_CLOCK / 10, cia_0_pal_intf)
476MACHINE_CONFIG_END
477
478static MACHINE_CONFIG_DERIVED( a500p, pal )
479   MCFG_FRAGMENT_ADD(amiga_cartslot)
480MACHINE_CONFIG_END
481
482static MACHINE_CONFIG_DERIVED( a1000p, pal )
483   MCFG_CPU_MODIFY("maincpu")
484   MCFG_CPU_PROGRAM_MAP(a1000_mem)
485MACHINE_CONFIG_END
486
487/***************************************************************************
488
489  Amiga specific stuff
490
491***************************************************************************/
492
493
494static READ8_DEVICE_HANDLER( amiga_cia_0_portA_r )
495{
496   UINT8 ret = input_port_read(device->machine(), "CIA0PORTA") & 0xc0;   /* Gameport 1 and 0 buttons */
497   ret |= amiga_fdc_status_r(device->machine().device("fdc"));
498   return ret;
499}
500
501
502static READ8_DEVICE_HANDLER( amiga_cia_0_cdtv_portA_r )
503{
504   return input_port_read(device->machine(), "CIA0PORTA") & 0xc0;   /* Gameport 1 and 0 buttons */
505}
506
507
508static WRITE8_DEVICE_HANDLER( amiga_cia_0_portA_w )
509{
510   amiga_state *state = device->machine().driver_data<amiga_state>();
511   /* switch banks as appropriate */
512   memory_set_bank(device->machine(), "bank1", data & 1);
513
514   /* swap the write handlers between ROM and bank 1 based on the bit */
515   if ((data & 1) == 0) {
516      UINT32 mirror_mask = state->m_chip_ram_size;
517
518      while( (mirror_mask<<1) < 0x100000 ) {
519         mirror_mask |= ( mirror_mask << 1 );
520      }
521
522      /* overlay disabled, map RAM on 0x000000 */
523      device->machine().device("maincpu")->memory().space(AS_PROGRAM)->install_write_bank(0x000000, state->m_chip_ram_size - 1, 0, mirror_mask, "bank1");
524
525      /* if there is a cart region, check for cart overlay */
526      if (device->machine().region("user2")->base() != NULL)
527         amiga_cart_check_overlay(device->machine());
528   }
529   else
530      /* overlay enabled, map Amiga system ROM on 0x000000 */
531      device->machine().device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0x000000, state->m_chip_ram_size - 1);
532
533   set_led_status( device->machine(), 0, ( data & 2 ) ? 0 : 1 ); /* bit 2 = Power Led on Amiga */
534   output_set_value("power_led", ( data & 2 ) ? 0 : 1);
535}
536
537static UINT16 amiga_read_joy0dat(running_machine &machine)
538{
539   if ( input_port_read(machine, "input") & 0x20 ) {
540      /* Joystick */
541      return input_port_read_safe(machine, "JOY0DAT", 0xffff);
542   } else {
543      /* Mouse */
544      int input;
545      input  = ( input_port_read(machine, "P0MOUSEX") & 0xff );
546      input |= ( input_port_read(machine, "P0MOUSEY") & 0xff ) << 8;
547      return input;
548   }
549}
550
551static UINT16 amiga_read_joy1dat(running_machine &machine)
552{
553   if ( input_port_read(machine, "input") & 0x10 ) {
554      /* Joystick */
555      return input_port_read_safe(machine, "JOY1DAT", 0xffff);
556   } else {
557      /* Mouse */
558      int input;
559      input  = ( input_port_read(machine, "P1MOUSEX") & 0xff );
560      input |= ( input_port_read(machine, "P1MOUSEY") & 0xff ) << 8;
561      return input;
562   }
563}
564
565static UINT16 amiga_read_dskbytr(running_machine &machine)
566{
567   return amiga_fdc_get_byte(machine.device("fdc"));
568}
569
570static void amiga_write_dsklen(running_machine &machine, UINT16 data)
571{
572   amiga_state *state = machine.driver_data<amiga_state>();
573   if ( data & 0x8000 ) {
574      if ( CUSTOM_REG(REG_DSKLEN) & 0x8000 )
575         amiga_fdc_setup_dma(machine.device("fdc"));
576   }
577}
578
579
580static void amiga_reset(running_machine &machine)
581{
582   if (input_port_read(machine, "hardware") & 0x08)
583   {
584      /* Install RTC */
585      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_readwrite_handler(0xdc0000, 0xdc003f, FUNC(amiga_clock_r), FUNC(amiga_clock_w));
586   }
587   else
588   {
589      /* No RTC support */
590      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_readwrite(0xdc0000, 0xdc003f);
591   }
592}
593
594static DRIVER_INIT( amiga )
595{
596   amiga_state *state = machine.driver_data<amiga_state>();
597   static const amiga_machine_interface amiga_intf =
598   {
599      ANGUS_CHIP_RAM_MASK,
600      amiga_read_joy0dat,   amiga_read_joy1dat,  /* joy0dat_r & joy1dat_r */
601      NULL,                                    /* potgo_w */
602      amiga_read_dskbytr,   amiga_write_dsklen,  /* dskbytr_r & dsklen_w */
603      NULL,                                    /* serdat_w */
604      NULL,                                    /* scanline0_callback */
605      amiga_reset,                             /* reset_callback */
606      amiga_cart_nmi,                          /* nmi_callback */
607      0                                        /* flags */
608   };
609
610   amiga_machine_config(machine, &amiga_intf);
611
612   /* set up memory */
613   memory_configure_bank(machine, "bank1", 0, 1, state->m_chip_ram, 0);
614   memory_configure_bank(machine, "bank1", 1, 1, machine.region("user1")->base(), 0);
615
616   /* initialize cartridge (if present) */
617   amiga_cart_init(machine);
618
619   /* initialize keyboard */
620   amigakbd_init(machine);
621}
622
623#ifdef UNUSED_FUNCTION
624static DRIVER_INIT( amiga_ecs )
625{
626   static const amiga_machine_interface amiga_intf =
627   {
628      ECS_CHIP_RAM_MASK,
629      amiga_cia_0_portA_r, NULL,               /* CIA0 port A & B read */
630      amiga_cia_0_portA_w, NULL,               /* CIA0 port A & B write */
631      NULL, NULL,                              /* CIA1 port A & B read */
632      NULL, amiga_fdc_control_w,               /* CIA1 port A & B write */
633      amiga_read_joy0dat,   amiga_read_joy1dat,  /* joy0dat_r & joy1dat_r */
634      NULL,                                    /* potgo_w */
635      amiga_read_dskbytr,   amiga_write_dsklen,  /* dskbytr_r & dsklen_w */
636      NULL,                                    /* serdat_w */
637      NULL,                                    /* scanline0_callback */
638      amiga_reset,                             /* reset_callback */
639      amiga_cart_nmi,                          /* nmi_callback */
640      0                                        /* flags */
641   };
642
643   amiga_machine_config(machine, &amiga_intf);
644
645   /* set up memory */
646   memory_configure_bank(1, 0, 1, state->m_chip_ram, 0);
647   memory_configure_bank(1, 1, 1, machine.region("user1")->base(), 0);
648
649   /* initialize Action Replay (if present) */
650   amiga_cart_init(machine);
651
652   /* initialize keyboard */
653   amigakbd_init(machine);
654}
655#endif
656
657static DRIVER_INIT( cdtv )
658{
659   amiga_state *state = machine.driver_data<amiga_state>();
660   static const amiga_machine_interface amiga_intf =
661   {
662      ECS_CHIP_RAM_MASK,
663      amiga_read_joy0dat,   amiga_read_joy1dat,  /* joy0dat_r & joy1dat_r */
664      NULL,                                    /* potgo_w */
665      amiga_read_dskbytr,   amiga_write_dsklen,  /* dskbytr_r & dsklen_w */
666      NULL,                                    /* serdat_w */
667      NULL,                                    /* scanline0_callback */
668      NULL,                                    /* reset_callback */
669      NULL,                                    /* nmi_callback */
670      0                                        /* flags */
671   };
672
673   amiga_machine_config(machine, &amiga_intf);
674
675   /* set up memory */
676   memory_configure_bank(machine, "bank1", 0, 1, state->m_chip_ram, 0);
677   memory_configure_bank(machine, "bank1", 1, 1, machine.region("user1")->base(), 0);
678
679   /* initialize keyboard - in cdtv we can use a standard Amiga keyboard*/
680   amigakbd_init(machine);
681}
682
683
684/***************************************************************************
685    ROM DEFINITIONS
686***************************************************************************/
687
688ROM_START( a500n )
689   ROM_REGION16_BE(0x080000, "user1", 0)
690   ROM_DEFAULT_BIOS("kick13")
691   ROM_SYSTEM_BIOS(0, "kick12",  "Kickstart 1.2 (33.180)")
692   ROMX_LOAD("315093-01.u6", 0x000000, 0x040000, CRC(a6ce1636) SHA1(11f9e62cf299f72184835b7b2a70a16333fc0d88), ROM_GROUPWORD | ROM_BIOS(1))
693   ROM_SYSTEM_BIOS(1, "kick13",  "Kickstart 1.3 (34.5)")
694   ROMX_LOAD("315093-02.u6", 0x000000, 0x040000, CRC(c4f0f55f) SHA1(891e9a547772fe0c6c19b610baf8bc4ea7fcb785), ROM_GROUPWORD | ROM_BIOS(2))
695   ROM_COPY("user1", 0x000000, 0x040000, 0x040000)
696   ROM_SYSTEM_BIOS(2, "kick204", "Kickstart 2.04 (37.175)")
697   ROMX_LOAD("390979-01.u6", 0x000000, 0x080000, CRC(c3bdb240) SHA1(c5839f5cb98a7a8947065c3ed2f14f5f42e334a1), ROM_GROUPWORD | ROM_BIOS(3))   /* identical to 363968.01 */
698   ROM_SYSTEM_BIOS(3, "kick31",  "Kickstart 3.1 (40.63)")
699   ROMX_LOAD("kick40063.u6", 0x000000, 0x080000, CRC(fc24ae0d) SHA1(3b7f1493b27e212830f989f26ca76c02049f09ca), ROM_GROUPWORD | ROM_BIOS(4))   /* part number? */
700
701   /* action replay cartridge */
702   ROM_REGION16_BE(0x080000, "user2", ROMREGION_ERASEFF )
703   ROM_CART_LOAD("cart", 0x0000, 0x080000, ROM_NOMIRROR | ROM_OPTIONAL)
704
705   /* keyboard controller, mos 6500/1 mcu */
706   ROM_REGION(0x800, "keyboard", 0)
707   ROM_LOAD("328191-02.ic1", 0x000, 0x800, NO_DUMP)
708ROM_END
709
710#define rom_a500p    rom_a500n
711
712
713ROM_START( a1000n )
714   ROM_REGION16_BE(0x080000, "user1", 0)
715   ROM_LOAD16_BYTE("252179-01.u5n", 0x000000, 0x001000, CRC(42553bc4) SHA1(8855a97f7a44e3f62d1c88d938fee1f4c606af5b))
716   ROM_LOAD16_BYTE("252180-01.u5p", 0x000001, 0x001000, CRC(8e5b9a37) SHA1(d10f1564b99f5ffe108fa042362e877f569de2c3))
717
718   /* keyboard controller, mos 6500/1 mcu */
719   ROM_REGION(0x800, "keyboard", 0)
720   ROM_LOAD("328191-01.bin", 0x000, 0x800, NO_DUMP)
721ROM_END
722
723#define rom_a1000p    rom_a1000n
724
725
726ROM_START( cdtv )
727   ROM_REGION16_BE(0x100000, "user1", 0)
728   ROM_LOAD16_BYTE("391008-01.u34", 0x000000, 0x020000, CRC(791cb14b) SHA1(277a1778924496353ffe56be68063d2a334360e4))
729   ROM_LOAD16_BYTE("391009-01.u35", 0x000001, 0x020000, CRC(accbbc2e) SHA1(41b06d1679c6e6933c3378b7626025f7641ebc5c))
730   ROM_COPY("user1", 0x000000, 0x040000, 0x040000)
731   ROMX_LOAD(      "315093-02.u13", 0x080000, 0x040000, CRC(c4f0f55f) SHA1(891e9a547772fe0c6c19b610baf8bc4ea7fcb785), ROM_GROUPWORD)
732   ROM_COPY("user1", 0x080000, 0x0c0000, 0x040000)
733
734   /* remote control input converter, mos 6500/1 mcu */
735   ROM_REGION(0x800, "rcmcu", 0)
736   ROM_LOAD("252609-02.u75", 0x000, 0x800, NO_DUMP)
737
738   /* lcd controller, sanyo lc6554h */
739   ROM_REGION(0x1000, "lcd", 0)
740   ROM_LOAD("252608-01.u62", 0x000, 0x1000, NO_DUMP)
741ROM_END
742
743/***************************************************************************
744    GAME DRIVERS
745***************************************************************************/
746
747/*    YEAR  NAME    PARENT  COMPAT  MACHINE INPUT   INIT    COMPANY                             FULLNAME                 FLAGS */
748COMP( 1985, a1000n, 0,      0,      a1000n, amiga,  amiga,  "Commodore Business Machines",  "Amiga 1000 (NTSC)",     GAME_IMPERFECT_GRAPHICS )
749COMP( 1985, a1000p, a1000n, 0,      a1000p, amiga,  amiga,  "Commodore Business Machines",  "Amiga 1000 (PAL)",      GAME_IMPERFECT_GRAPHICS )
750COMP( 1987, a500n,  0,      0,      a500n,  amiga,  amiga,  "Commodore Business Machines",  "Amiga 500 (NTSC, OCS)", GAME_IMPERFECT_GRAPHICS )
751COMP( 1987, a500p,  a500n,  0,      a500p,  amiga,  amiga,  "Commodore Business Machines",  "Amiga 500 (PAL, OCS)",  GAME_IMPERFECT_GRAPHICS )
752COMP( 1991, cdtv,   0,      0,      cdtv,   cdtv,   cdtv,   "Commodore Business Machines",  "CDTV (NTSC)",           GAME_IMPERFECT_GRAPHICS )
src/mess/drivers/a7000.c
r11460r11461
1/***************************************************************************
2
3    Acorn Archimedes 7000/7000+
4
5    preliminary driver by Angelo Salese,
6    based on work by Tomasz Slanina and Tom Walker
7
8    ???
9    bp (0382827C) (second trigger)
10    do R13 = SR13
11
12****************************************************************************/
13
14#include "emu.h"
15#include "cpu/arm7/arm7.h"
16#include "cpu/arm7/arm7core.h"
17
18
19class a7000_state : public driver_device
20{
21public:
22   a7000_state(const machine_config &mconfig, device_type type, const char *tag)
23      : driver_device(mconfig, type, tag) { }
24
25   UINT8 m_vidc20_pal_index;
26   UINT16 m_vidc20_horz_reg[0x10];
27   UINT16 m_vidc20_vert_reg[0x10];
28   UINT8 m_vidc20_bpp_mode;
29   emu_timer *m_flyback_timer;
30   UINT16 m_timer_in[2];
31   UINT16 m_timer_out[2];
32   int m_timer_counter[2];
33   emu_timer *m_IOMD_timer[2];
34   UINT8 m_IRQ_status_A;
35   UINT8 m_IRQ_mask_A;
36   UINT8 m_IOMD_IO_ctrl;
37   UINT8 m_IOMD_keyb_ctrl;
38   UINT16 m_io_id;
39   UINT8 m_viddma_status;
40   UINT32 m_viddma_addr_start;
41   UINT32 m_viddma_addr_end;
42   UINT8 m_t0readinc;
43   UINT8 m_t1readinc;
44};
45
46
47/*
48 *
49 * VIDC20 chip emulation
50 *
51 */
52
53
54static const char *const vidc20_regnames[] =
55{
56   "Video Palette",               // 0
57   "Video Palette Address",         // 1
58   "RESERVED",                   // 2
59   "LCD offset",                  // 3
60   "Border Colour",               // 4
61   "Cursor Palette Logical Colour 1",   // 5
62   "Cursor Palette Logical Colour 2",   // 6
63   "Cursor Palette Logical Colour 3",   // 7
64   "Horizontal",                  // 8
65   "Vertical",                     // 9
66   "Stereo Image",                  // A
67   "Sound",                     // B
68   "External",                     // C
69   "Frequency Synthesis",            // D
70   "Control",                     // E
71   "Data Control"                  // F
72};
73
74static const char *const vidc20_horz_regnames[] =
75{
76   "Horizontal Cycle",             // 0x80 HCR
77   "Horizontal Sync Width",         // 0x81 HSWR
78   "Horizontal Border Start",         // 0x82 HBSR
79   "Horizontal Display Start",         // 0x83 HDSR
80   "Horizontal Display End",         // 0x84 HDER
81   "Horizontal Border End",         // 0x85 HBER
82   "Horizontal Cursor Start",         // 0x86 HCSR
83   "Horizontal Interlace",          // 0x87 HIR
84   "Horizontal Counter TEST",         // 0x88
85   "Horizontal <UNDEFINED>",         // 0x89
86   "Horizontal <UNDEFINED>",         // 0x8a
87   "Horizontal <UNDEFINED>",         // 0x8b
88   "Horizontal All TEST",            // 0x8c
89   "Horizontal <UNDEFINED>",         // 0x8d
90   "Horizontal <UNDEFINED>",         // 0x8e
91   "Horizontal <UNDEFINED>"         // 0x8f
92};
93
94#define HCR  0
95#define HSWR 1
96#define HBSR 2
97#define HDSR 3
98#define HDER 4
99#define HBER 5
100#define HCSR 6
101#define HIR  7
102
103static const char *const vidc20_vert_regnames[] =
104{
105   "Vertical Cycle",               // 0x90 VCR
106   "Vertical Sync Width",            // 0x91 VSWR
107   "Vertical Border Start",         // 0x92 VBSR
108   "Vertical Display Start",         // 0x93 VDSR
109   "Vertical Display End",          // 0x94 VDER
110   "Vertical Border End",            // 0x95 VBER
111   "Vertical Cursor Start",         // 0x96 VCSR
112   "Vertical Cursor End",            // 0x97 VCER
113   "Vertical Counter TEST",         // 0x98
114   "Horizontal <UNDEFINED>",         // 0x99
115   "Vertical Counter Increment TEST",   // 0x9a
116   "Horizontal <UNDEFINED>",         // 0x9b
117   "Vertical All TEST",            // 0x9c
118   "Horizontal <UNDEFINED>",         // 0x9d
119   "Horizontal <UNDEFINED>",         // 0x9e
120   "Horizontal <UNDEFINED>"         // 0x9f
121};
122
123#define VCR  0
124#define VSWR 1
125#define VBSR 2
126#define VDSR 3
127#define VDER 4
128#define VBER 5
129#define VCSR 6
130#define VCER 7
131
132static void vidc20_dynamic_screen_change(running_machine &machine)
133{
134   a7000_state *state = machine.driver_data<a7000_state>();
135   /* sanity checks - first pass */
136   /*
137    total cycles + border start/end
138    */
139   if(state->m_vidc20_horz_reg[HCR] && state->m_vidc20_horz_reg[HBSR] && state->m_vidc20_horz_reg[HBER] &&
140      state->m_vidc20_vert_reg[VCR] && state->m_vidc20_vert_reg[VBSR] && state->m_vidc20_vert_reg[VBER])
141   {
142      /* sanity checks - second pass */
143      /*
144        total cycles > border end > border start
145        */
146      if((state->m_vidc20_horz_reg[HCR] > state->m_vidc20_horz_reg[HBER]) &&
147         (state->m_vidc20_horz_reg[HBER] > state->m_vidc20_horz_reg[HBSR]) &&
148         (state->m_vidc20_vert_reg[VCR] > state->m_vidc20_vert_reg[VBER]) &&
149         (state->m_vidc20_vert_reg[VBER] > state->m_vidc20_vert_reg[VBSR]))
150      {
151         /* finally ready to change the resolution */
152         int hblank_period,vblank_period;
153         rectangle visarea = machine.primary_screen->visible_area();
154         hblank_period = (state->m_vidc20_horz_reg[HCR] & 0x3ffc);
155         vblank_period = (state->m_vidc20_vert_reg[VCR] & 0x3fff);
156         /* note that we use the border registers as the visible area */
157         visarea.min_x = (state->m_vidc20_horz_reg[HBSR] & 0x3ffe);
158         visarea.max_x = (state->m_vidc20_horz_reg[HBER] & 0x3ffe)-1;
159         visarea.min_y = (state->m_vidc20_vert_reg[VBSR] & 0x1fff);
160         visarea.max_y = (state->m_vidc20_vert_reg[VBER] & 0x1fff)-1;
161
162         machine.primary_screen->configure(hblank_period, vblank_period, visarea, machine.primary_screen->frame_period().attoseconds );
163         logerror("VIDC20: successfully changed the screen to:\n Display Size = %d x %d\n Border Size %d x %d\n Cycle Period %d x %d\n",
164                    (state->m_vidc20_horz_reg[HDER]-state->m_vidc20_horz_reg[HDSR]),(state->m_vidc20_vert_reg[VDER]-state->m_vidc20_vert_reg[VDSR]),
165                    (state->m_vidc20_horz_reg[HBER]-state->m_vidc20_horz_reg[HBSR]),(state->m_vidc20_vert_reg[VBER]-state->m_vidc20_vert_reg[VBSR]),
166                    hblank_period,vblank_period);
167      }
168   }
169}
170
171static WRITE32_HANDLER( a7000_vidc20_w )
172{
173   a7000_state *state = space->machine().driver_data<a7000_state>();
174   int reg = data >> 28;
175
176   switch(reg)
177   {
178      case 0: // Video Palette
179      {
180         int r,g,b;
181
182         r = (data & 0x0000ff) >> 0;
183         g = (data & 0x00ff00) >> 8;
184         b = (data & 0xff0000) >> 16;
185
186         palette_set_color_rgb(space->machine(),state->m_vidc20_pal_index & 0xff,r,g,b);
187
188         /* auto-increment & wrap-around */
189         state->m_vidc20_pal_index++;
190         state->m_vidc20_pal_index &= 0xff;
191      }
192      break;
193      case 1: // Video Palette Address
194      {
195         // according to RPCEmu, these mustn't be set
196         if (data & 0x0fffff00)
197            return;
198
199         state->m_vidc20_pal_index = data & 0xff;
200      }
201      break;
202
203      case 4: // Border Color
204      {
205         int r,g,b;
206
207         r = (data & 0x0000ff) >> 0;
208         g = (data & 0x00ff00) >> 8;
209         b = (data & 0xff0000) >> 16;
210
211         palette_set_color_rgb(space->machine(),0x100,r,g,b);
212      }
213      break;
214      case 5: // Cursor Palette Logical Colour n
215      case 6:
216      case 7:
217      {
218         int r,g,b;
219         int cursor_index = 0x100 + reg - 4; // 0x101,0x102 and 0x103 (plus 0x100 of above, 2bpp)
220
221         r = (data & 0x0000ff) >> 0;
222         g = (data & 0x00ff00) >> 8;
223         b = (data & 0xff0000) >> 16;
224
225         palette_set_color_rgb(space->machine(),cursor_index,r,g,b);
226      }
227      break;
228      case 8: // Horizontal
229      {
230         int horz_reg;
231
232         horz_reg = (data >> 24) & 0xf;
233         state->m_vidc20_horz_reg[horz_reg] = data & 0x3fff;
234         if(horz_reg == 0 || horz_reg == 2 || horz_reg == 5)
235            vidc20_dynamic_screen_change(space->machine());
236
237         // logerror("VIDC20: %s Register write = %08x (%d)\n",vidc20_horz_regnames[horz_reg],val,val);
238      }
239      break;
240      case 9: // Vertical
241      {
242         int vert_reg;
243
244         vert_reg = (data >> 24) & 0xf;
245         state->m_vidc20_vert_reg[vert_reg] = data & 0x1fff;
246         if(vert_reg == 0 || vert_reg == 2 || vert_reg == 5)
247            vidc20_dynamic_screen_change(space->machine());
248
249         if(vert_reg == 4)
250         {
251            if(state->m_vidc20_vert_reg[VDER] != 0)
252               state->m_flyback_timer->adjust(space->machine().primary_screen->time_until_pos(state->m_vidc20_vert_reg[VDER]));
253            else
254               state->m_flyback_timer->adjust(attotime::never);
255         }
256
257         // logerror("VIDC20: %s Register write = %08x (%d)\n",vidc20_vert_regnames[vert_reg],val,val);
258
259      }
260      break;
261      case 0x0e: // Control
262      {
263         state->m_vidc20_bpp_mode = (data & 0xe0) >> 5;
264      }
265      break;
266      default: logerror("VIDC20: %s Register write = %08x\n",vidc20_regnames[reg],data & 0xfffffff);
267   }
268}
269
270static VIDEO_START( a7000 )
271{
272}
273
274static SCREEN_UPDATE( a7000 )
275{
276   a7000_state *state = screen->machine().driver_data<a7000_state>();
277   int x_size,y_size,x_start,y_start;
278   int x,y,xi;
279   UINT32 count;
280   UINT8 *vram = screen->machine().region("vram")->base();
281
282   bitmap_fill(bitmap, cliprect, screen->machine().pens[0x100]);
283
284   x_size = (state->m_vidc20_horz_reg[HDER]-state->m_vidc20_horz_reg[HDSR]);
285   y_size = (state->m_vidc20_vert_reg[VDER]-state->m_vidc20_vert_reg[VDSR]);
286   x_start = state->m_vidc20_horz_reg[HDSR];
287   y_start = state->m_vidc20_vert_reg[VDSR];
288
289   /* check if display is enabled */
290   if(x_size <= 0 || y_size <= 0)
291      return 0;
292
293//  popmessage("%d",state->m_vidc20_bpp_mode);
294
295   count = 0;
296
297   switch(state->m_vidc20_bpp_mode)
298   {
299      case 0: /* 1 bpp */
300      {
301         for(y=0;y<y_size;y++)
302         {
303            for(x=0;x<x_size;x+=8)
304            {
305               for(xi=0;xi<8;xi++)
306                  *BITMAP_ADDR32(bitmap, y+y_start, x+xi+x_start) = screen->machine().pens[(vram[count]>>(xi))&1];
307
308               count++;
309            }
310         }
311      }
312      break;
313      case 1: /* 2 bpp */
314      {
315         for(y=0;y<y_size;y++)
316         {
317            for(x=0;x<x_size;x+=4)
318            {
319               for(xi=0;xi<4;xi++)
320                  *BITMAP_ADDR32(bitmap, y+y_start, x+xi+x_start) = screen->machine().pens[(vram[count]>>(xi*2))&3];
321
322               count++;
323            }
324         }
325      }
326      break;
327      case 2: /* 4 bpp */
328      {
329         for(y=0;y<y_size;y++)
330         {
331            for(x=0;x<x_size;x+=2)
332            {
333               for(xi=0;xi<2;xi++)
334                  *BITMAP_ADDR32(bitmap, y+y_start, x+xi+x_start) = screen->machine().pens[(vram[count]>>(xi*4))&0xf];
335
336               count++;
337            }
338         }
339      }
340      break;
341      case 3: /* 8 bpp */
342      {
343         for(y=0;y<y_size;y++)
344         {
345            for(x=0;x<x_size;x++)
346            {
347               *BITMAP_ADDR32(bitmap, y+y_start, x+x_start) = screen->machine().pens[(vram[count])&0xff];
348
349               count++;
350            }
351         }
352      }
353      break;
354      case 4: /* 16 bpp */
355      {
356         for(y=0;y<y_size;y++)
357         {
358            for(x=0;x<x_size;x++)
359            {
360               int r,g,b,pen;
361
362               pen = ((vram[count]<<8)|(vram[count+1]))&0xffff;
363               r = (pen & 0x000f);
364               g = (pen & 0x00f0) >> 4;
365               b = (pen & 0x0f00) >> 8;
366               r = (r << 4) | (r & 0xf);
367               g = (g << 4) | (g & 0xf);
368               b = (b << 4) | (b & 0xf);
369
370               *BITMAP_ADDR32(bitmap, y+y_start, x+x_start) =  b | g << 8 | r << 16;
371
372               count+=2;
373            }
374         }
375      }
376      break;
377      case 6: /* 32 bpp */
378      {
379         for(y=0;y<y_size;y++)
380         {
381            for(x=0;x<x_size;x++)
382            {
383               int r,g,b,pen;
384
385               pen = ((vram[count]<<24)|(vram[count+1]<<16)|(vram[count+2]<<8)|(vram[count+3]<<0));
386               r = (pen & 0x0000ff);
387               g = (pen & 0x00ff00) >> 8;
388               b = (pen & 0xff0000) >> 16;
389
390               *BITMAP_ADDR32(bitmap, y+y_start, x+x_start) =  b | g << 8 | r << 16;
391
392               count+=4;
393            }
394         }
395      }
396      break;
397      default:
398         //fatalerror("VIDC20 %08x BPP mode not supported\n",state->m_vidc20_bpp_mode);
399         break;
400   }
401
402    return 0;
403}
404
405/*
406*
407* IOMD / ARM7500 / ARM7500FE chip emulation
408*
409*/
410
411/* TODO: some of these registers are actually ARM7500 specific */
412static const char *const iomd_regnames[] =
413{
414   "I/O Control",                  // 0x000 IOCR
415   "Keyboard Data",               // 0x004 KBDDAT
416   "Keyboard Control",               // 0x008 KBDCR
417   "General Purpose I/O Lines",      // 0x00c IOLINES
418   "IRQA Status",                  // 0x010 IRQSTA
419   "IRQA Request/clear",            // 0x014 IRQRQA
420   "IRQA Mask",                  // 0x018 IRQMSKA
421   "Enter SUSPEND Mode",            // 0x01c SUSMODE
422   "IRQB Status",                  // 0x020 IRQSTB
423   "IRQB Request/clear",            // 0x024 IRQRQB
424   "IRQB Mask",                  // 0x028 IRQMSKB
425   "Enter STOP Mode",               // 0x02c STOPMODE
426   "FIQ Status",                  // 0x030 FIQST
427   "FIQ Request/clear",            // 0x034 FIQRQ
428   "FIQ Mask",                     // 0x038 FIQMSK
429   "Clock divider control",         // 0x03c CLKCTL
430   "Timer 0 Low Bits",               // 0x040 T0LOW
431   "Timer 0 High Bits",            // 0x044 T0HIGH
432   "Timer 0 Go Command",            // 0x048 T0GO
433   "Timer 0 Latch Command",         // 0x04c T0LATCH
434   "Timer 1 Low Bits",               // 0x050 T1LOW
435   "Timer 1 High Bits",            // 0x054 T1HIGH
436   "Timer 1 Go Command",            // 0x058 T1GO
437   "Timer 1 Latch Command",         // 0x05c T1LATCH
438   "IRQC Status",                  // 0x060 IRQSTC
439   "IRQC Request/clear",            // 0x064 IRQRQC
440   "IRQC Mask",                  // 0x068 IRQMSKC
441   "LCD and IIS Control Bits",         // 0x06c VIDIMUX
442   "IRQD Status",                  // 0x070 IRQSTD
443   "IRQD Request/clear",            // 0x074 IRQRQD
444   "IRQD Mask",                  // 0x078 IRQMSKD
445   "<RESERVED>",                  // 0x07c
446   "ROM Control Bank 0",            // 0x080 ROMCR0
447   "ROM Control Bank 1",            // 0x084 ROMCR1
448   "DRAM Control (IOMD)",            // 0x088 DRAMCR
449   "VRAM and Refresh Control",         // 0x08c VREFCR
450   "Flyback Line Size",            // 0x090 FSIZE
451   "Chip ID no. Low Byte",            // 0x094 ID0
452   "Chip ID no. High Byte",         // 0x098 ID1
453   "Chip Version Number",            // 0x09c VERSION
454   "Mouse X Position",               // 0x0a0 MOUSEX
455   "Mouse Y Position",               // 0x0a4 MOUSEY
456   "Mouse Data",                  // 0x0a8 MSEDAT
457   "Mouse Control",               // 0x0ac MSECR
458   "<RESERVED>",                  // 0x0b0
459   "<RESERVED>",                  // 0x0b4
460   "<RESERVED>",                  // 0x0b8
461   "<RESERVED>",                  // 0x0bc
462   "DACK Timing Control",            // 0x0c0 DMATCR
463   "I/O Timing Control",            // 0x0c4 IOTCR
464   "Expansion Card Timing",         // 0x0c8 ECTCR
465   "DMA External Control",            // 0x0cc DMAEXT (IOMD) / ASTCR (ARM7500)
466   "DRAM Width Control",            // 0x0d0 DRAMWID
467   "Force CAS/RAS Lines Low",         // 0x0d4 SELFREF
468   "<RESERVED>",                  // 0x0d8
469   "<RESERVED>",                  // 0x0dc
470   "A to D IRQ Control",            // 0x0e0 ATODICR
471   "A to D IRQ Status",            // 0x0e4 ATODCC
472   "A to D IRQ Converter Control",      // 0x0e8 ATODICR
473   "A to D IRQ Counter 1",            // 0x0ec ATODCNT1
474   "A to D IRQ Counter 2",            // 0x0f0 ATODCNT2
475   "A to D IRQ Counter 3",            // 0x0f4 ATODCNT3
476   "A to D IRQ Counter 4",            // 0x0f8 ATODCNT4
477   "<RESERVED>",                  // 0x0fc
478   "I/O DMA 0 CurA",               // 0x100 IO0CURA
479   "I/O DMA 0 EndA",               // 0x104 IO0ENDA
480   "I/O DMA 0 CurB",               // 0x108 IO0CURB
481   "I/O DMA 0 EndB",               // 0x10c IO0ENDB
482   "I/O DMA 0 Control",            // 0x110 IO0CR
483   "I/O DMA 0 Status",               // 0x114 IO0ST
484   "<RESERVED>",                  // 0x118
485   "<RESERVED>",                  // 0x11c
486   "I/O DMA 1 CurA",               // 0x120 IO1CURA
487   "I/O DMA 1 EndA",               // 0x124 IO1ENDA
488   "I/O DMA 1 CurB",               // 0x128 IO1CURB
489   "I/O DMA 1 EndB",               // 0x12c IO1ENDB
490   "I/O DMA 1 Control",            // 0x130 IO1CR
491   "I/O DMA 1 Status",               // 0x134 IO1ST
492   "<RESERVED>",                  // 0x138
493   "<RESERVED>",                  // 0x13c
494   "I/O DMA 2 CurA",               // 0x140 IO2CURA
495   "I/O DMA 2 EndA",               // 0x144 IO2ENDA
496   "I/O DMA 2 CurB",               // 0x148 IO2CURB
497   "I/O DMA 2 EndB",               // 0x14c IO2ENDB
498   "I/O DMA 2 Control",            // 0x150 IO2CR
499   "I/O DMA 2 Status",               // 0x154 IO2ST
500   "<RESERVED>",                  // 0x158
501   "<RESERVED>",                  // 0x15c
502   "I/O DMA 3 CurA",               // 0x160 IO3CURA
503   "I/O DMA 3 EndA",               // 0x164 IO3ENDA
504   "I/O DMA 3 CurB",               // 0x168 IO3CURB
505   "I/O DMA 3 EndB",               // 0x16c IO3ENDB
506   "I/O DMA 3 Control",            // 0x170 IO3CR
507   "I/O DMA 3 Status",               // 0x174 IO3ST
508   "<RESERVED>",                  // 0x178
509   "<RESERVED>",                  // 0x17c
510   "Sound DMA 0 CurA",               // 0x180 SD0CURA
511   "Sound DMA 0 EndA",               // 0x184 SD0ENDA
512   "Sound DMA 0 CurB",               // 0x188 SD0CURB
513   "Sound DMA 0 EndB",               // 0x18c SD0ENDB
514   "Sound DMA 0 Control",            // 0x190 SD0CR
515   "Sound DMA 0 Status",            // 0x194 SD0ST
516   "<RESERVED>",                  // 0x198
517   "<RESERVED>",                  // 0x19c
518   "Sound DMA 1 CurA",               // 0x1a0 SD1CURA
519   "Sound DMA 1 EndA",               // 0x1a4 SD1ENDA
520   "Sound DMA 1 CurB",               // 0x1a8 SD1CURB
521   "Sound DMA 1 EndB",               // 0x1ac SD1ENDB
522   "Sound DMA 1 Control",            // 0x1b0 SD1CR
523   "Sound DMA 1 Status",            // 0x1b4 SD1ST
524   "<RESERVED>",                  // 0x1b8
525   "<RESERVED>",                  // 0x1bc
526   "Cursor DMA Current",            // 0x1c0 CURSCUR
527   "Cursor DMA Init",               // 0x1c4 CURSINIT
528   "Duplex LCD Current B",            // 0x1c8 VIDCURB
529   "<RESERVED>",                  // 0x1cc
530   "Video DMA Current",            // 0x1d0 VIDCUR
531   "Video DMA End",               // 0x1d4 VIDEND
532   "Video DMA Start",               // 0x1d8 VIDSTART
533   "Video DMA Init",               // 0x1dc VIDINIT
534   "Video DMA Control",            // 0x1e0 VIDCR
535   "<RESERVED>",                  // 0x1e4
536   "Duplex LCD Init B",            // 0x1e8 VIDINITB
537   "<RESERVED>",                  // 0x1ec
538   "DMA IRQ Status",               // 0x1f0 DMAST
539   "DMA IRQ Request",               // 0x1f4 DMARQ
540   "DMA IRQ Mask",                  // 0x1f8 DMAMSK
541   "<RESERVED>"                  // 0x1fc
542};
543
544#define IOMD_IOCR      0x000/4
545#define IOMD_KBDDAT      0x004/4
546#define IOMD_KBDCR      0x008/4
547
548#define IOMD_IRQSTA      0x010/4
549#define IOMD_IRQRQA    0x014/4
550#define IOMD_IRQMSKA   0x018/4
551
552#define IOMD_T0LOW      0x040/4
553#define IOMD_T0HIGH    0x044/4
554#define IOMD_T0GO      0x048/4
555#define IOMD_T0LATCH   0x04c/4
556
557#define IOMD_T1LOW      0x050/4
558#define IOMD_T1HIGH    0x054/4
559#define IOMD_T1GO      0x058/4
560#define IOMD_T1LATCH   0x05c/4
561
562#define IOMD_ID0      0x094/4
563#define IOMD_ID1      0x098/4
564#define IOMD_VERSION   0x09c/4
565
566#define IOMD_VIDCUR      0x1d0/4
567#define IOMD_VIDEND      0x1d4/4
568#define IOMD_VIDSTART   0x1d8/4
569#define IOMD_VIDINIT   0x1dc/4
570#define IOMD_VIDCR      0x1e0/4
571
572
573
574static void fire_iomd_timer(a7000_state *state, int timer)
575{
576   int timer_count = state->m_timer_counter[timer];
577   int val = timer_count / 2; // correct?
578
579   if(val==0)
580      state->m_IOMD_timer[timer]->adjust(attotime::never);
581   else
582      state->m_IOMD_timer[timer]->adjust(attotime::from_usec(val), 0, attotime::from_usec(val));
583}
584
585static TIMER_CALLBACK( IOMD_timer0_callback )
586{
587   a7000_state *state = machine.driver_data<a7000_state>();
588   state->m_IRQ_status_A|=0x20;
589   if(state->m_IRQ_mask_A&0x20)
590   {
591      generic_pulse_irq_line(machine.device("maincpu"), ARM7_IRQ_LINE);
592   }
593}
594
595static TIMER_CALLBACK( IOMD_timer1_callback )
596{
597   a7000_state *state = machine.driver_data<a7000_state>();
598   state->m_IRQ_status_A|=0x40;
599   if(state->m_IRQ_mask_A&0x40)
600   {
601      generic_pulse_irq_line(machine.device("maincpu"), ARM7_IRQ_LINE);
602   }
603}
604
605static TIMER_CALLBACK( flyback_timer_callback )
606{
607   a7000_state *state = machine.driver_data<a7000_state>();
608   state->m_IRQ_status_A|=0x08;
609   if(state->m_IRQ_mask_A&0x08)
610   {
611      generic_pulse_irq_line(machine.device("maincpu"), ARM7_IRQ_LINE);
612   }
613
614   state->m_flyback_timer->adjust(machine.primary_screen->time_until_pos(state->m_vidc20_vert_reg[VDER]));
615}
616
617static void viddma_transfer_start(address_space *space)
618{
619   a7000_state *state = space->machine().driver_data<a7000_state>();
620   UINT32 src = state->m_viddma_addr_start;
621   UINT32 dst = 0;
622   UINT32 size = state->m_viddma_addr_end;
623   UINT32 dma_index;
624   UINT8 *vram = space->machine().region("vram")->base();
625
626   /* TODO: this should actually be a qword transfer */
627   for(dma_index = 0;dma_index < size;dma_index++)
628   {
629      vram[dst] = space->read_byte(src);
630
631      src++;
632      dst++;
633   }
634}
635
636static READ32_HANDLER( a7000_iomd_r )
637{
638   a7000_state *state = space->machine().driver_data<a7000_state>();
639//  if(offset != IOMD_KBDCR)
640//      logerror("IOMD: %s Register (%04x) read\n",iomd_regnames[offset & (0x1ff >> 2)],offset*4);
641
642
643   switch(offset)
644   {
645      case IOMD_IOCR:
646      {
647         UINT8 flyback;
648         int vert_pos;
649
650         vert_pos = space->machine().primary_screen->vpos();
651         flyback = (vert_pos <= state->m_vidc20_vert_reg[VDSR] || vert_pos >= state->m_vidc20_vert_reg[VDER]) ? 0x80 : 0x00;
652
653         return state->m_IOMD_IO_ctrl | 0x34 | flyback;
654      }
655      case IOMD_KBDCR:   return state->m_IOMD_keyb_ctrl | 0x80; //IOMD Keyb status
656
657      /*
658        1--- ---- always high
659        -x-- ---- Timer 1
660        --x- ---- Timer 0
661        ---x ---- Power On Reset
662        ---- x--- Flyback
663        ---- -x-- nINT1
664        ---- --0- always low
665        ---- ---x INT2
666        */
667      case IOMD_IRQSTA:   return (state->m_IRQ_status_A & ~2) | 0x80;
668      case IOMD_IRQRQA:   return (state->m_IRQ_status_A & state->m_IRQ_mask_A) | 0x80;
669      case IOMD_IRQMSKA:   return (state->m_IRQ_mask_A);
670
671      case IOMD_T0LOW:   return state->m_timer_out[0] & 0xff;
672      case IOMD_T0HIGH:   return (state->m_timer_out[0] >> 8) & 0xff;
673
674      case IOMD_T1LOW:   return state->m_timer_out[1] & 0xff;
675      case IOMD_T1HIGH:   return (state->m_timer_out[1] >> 8) & 0xff;
676
677      case IOMD_ID0:      return state->m_io_id & 0xff; // IOMD ID low
678      case IOMD_ID1:      return (state->m_io_id >> 8) & 0xff; // IOMD ID high
679      case IOMD_VERSION:   return 0;
680
681      case IOMD_VIDEND:   return (state->m_viddma_addr_end & 0x00fffff8); //bits 31:24 undefined
682      case IOMD_VIDSTART: return (state->m_viddma_addr_start & 0x1ffffff8); //bits 31, 30, 29 undefined
683      case IOMD_VIDCR:   return (state->m_viddma_status & 0xa0) | 0x50; //bit 6 = DRAM mode, bit 4 = QWORD transfer
684
685      default:   logerror("IOMD: %s Register (%04x) read\n",iomd_regnames[offset & (0x1ff >> 2)],offset*4); break;
686   }
687
688   return 0;
689}
690
691static WRITE32_HANDLER( a7000_iomd_w )
692{
693   a7000_state *state = space->machine().driver_data<a7000_state>();
694//  logerror("IOMD: %s Register (%04x) write = %08x\n",iomd_regnames[offset & (0x1ff >> 2)],offset*4,data);
695
696   switch(offset)
697   {
698      case IOMD_IOCR:      state->m_IOMD_IO_ctrl = data & ~0xf4; break;
699
700      case IOMD_KBDCR:
701         state->m_IOMD_keyb_ctrl = data & ~0xf4;
702         //keyboard_ctrl_write(data & 0x08);
703         break;
704
705      case IOMD_IRQRQA:   state->m_IRQ_status_A &= ~data; break;
706      case IOMD_IRQMSKA:   state->m_IRQ_mask_A = (data & ~2) | 0x80; break;
707
708      case IOMD_T0LOW:   state->m_timer_in[0] = (state->m_timer_in[0] & 0xff00) | (data & 0xff); break;
709      case IOMD_T0HIGH:   state->m_timer_in[0] = (state->m_timer_in[0] & 0x00ff) | ((data & 0xff) << 8); break;
710      case IOMD_T0GO:
711         state->m_timer_counter[0] = state->m_timer_in[0];
712         fire_iomd_timer(state,0);
713         break;
714      case IOMD_T0LATCH:
715         {
716            state->m_t0readinc^=1;
717            state->m_timer_out[0] = state->m_timer_counter[0];
718            if(state->m_t0readinc)
719            {
720               state->m_timer_counter[0]--;
721               if(state->m_timer_counter[0] < 0)
722                  state->m_timer_counter[0]+= state->m_timer_in[0];
723            }
724         }
725         break;
726
727      case IOMD_T1LOW:   state->m_timer_in[1] = (state->m_timer_in[1] & 0xff00) | (data & 0xff); break;
728      case IOMD_T1HIGH:   state->m_timer_in[1] = (state->m_timer_in[1] & 0x00ff) | ((data & 0xff) << 8); break;
729      case IOMD_T1GO:
730         state->m_timer_counter[1] = state->m_timer_in[1];
731         fire_iomd_timer(state,1);
732         break;
733      case IOMD_T1LATCH:
734         {
735            state->m_t1readinc^=1;
736            state->m_timer_out[1] = state->m_timer_counter[1];
737            if(state->m_t1readinc)
738            {
739               state->m_timer_counter[1]--;
740               if(state->m_timer_counter[1] < 0)
741                  state->m_timer_counter[1]+= state->m_timer_in[1];
742            }
743         }
744         break;
745
746      case IOMD_VIDEND:   state->m_viddma_addr_end = data & 0x00fffff8; //bits 31:24 unused
747      case IOMD_VIDSTART: state->m_viddma_addr_start = data & 0x1ffffff8; //bits 31, 30, 29 unused
748      case IOMD_VIDCR:
749         state->m_viddma_status = data & 0xa0; if(data & 0x20) { viddma_transfer_start(space); }
750         break;
751
752
753      default: logerror("IOMD: %s Register (%04x) write = %08x\n",iomd_regnames[offset & (0x1ff >> 2)],offset*4,data);
754   }
755}
756
757static ADDRESS_MAP_START( a7000_mem, AS_PROGRAM, 32)
758   AM_RANGE(0x00000000, 0x003fffff) AM_MIRROR(0x00800000) AM_ROM AM_REGION("user1", 0x0)
759//  AM_RANGE(0x01000000, 0x01ffffff) AM_NOP //expansion ROM
760//  AM_RANGE(0x02000000, 0x02ffffff) AM_RAM //VRAM
761//  I/O 03000000 - 033fffff
762//  AM_RANGE(0x03010000, 0x03011fff) //Super IO
763//  AM_RANGE(0x03012000, 0x03029fff) //FDC
764//  AM_RANGE(0x0302b000, 0x0302bfff) //Network podule
765//  AM_RANGE(0x03040000, 0x0304ffff) //podule space 0,1,2,3
766//  AM_RANGE(0x03070000, 0x0307ffff) //podule space 4,5,6,7
767   AM_RANGE(0x03200000, 0x032001ff) AM_READWRITE(a7000_iomd_r,a7000_iomd_w) //IOMD Registers //mirrored at 0x03000000-0x1ff?
768//  AM_RANGE(0x03310000, 0x03310003) //Mouse Buttons
769
770   AM_RANGE(0x03400000, 0x037fffff) AM_WRITE(a7000_vidc20_w)
771//  AM_RANGE(0x08000000, 0x08ffffff) AM_MIRROR(0x07000000) //EASI space
772   AM_RANGE(0x10000000, 0x13ffffff) AM_RAM //SIMM 0 bank 0
773   AM_RANGE(0x14000000, 0x17ffffff) AM_RAM //SIMM 0 bank 1
774//  AM_RANGE(0x18000000, 0x18ffffff) AM_MIRROR(0x03000000) AM_RAM //SIMM 1 bank 0
775//  AM_RANGE(0x1c000000, 0x1cffffff) AM_MIRROR(0x03000000) AM_RAM //SIMM 1 bank 1
776ADDRESS_MAP_END
777
778
779/* Input ports */
780static INPUT_PORTS_START( a7000 )
781INPUT_PORTS_END
782
783static MACHINE_START(a7000)
784{
785   a7000_state *state = machine.driver_data<a7000_state>();
786   state->m_IOMD_timer[0] = machine.scheduler().timer_alloc(FUNC(IOMD_timer0_callback));
787   state->m_IOMD_timer[1] = machine.scheduler().timer_alloc(FUNC(IOMD_timer1_callback));
788   state->m_flyback_timer = machine.scheduler().timer_alloc(FUNC(flyback_timer_callback));
789
790   state->m_io_id = 0xd4e7;
791}
792
793static MACHINE_RESET(a7000)
794{
795   a7000_state *state = machine.driver_data<a7000_state>();
796   state->m_IOMD_IO_ctrl = 0x0b | 0x34; //bit 0,1 and 3 set high on reset plus 2,4,5 always high
797//  state->m_IRQ_status_A = 0x10; // set POR bit ON
798   state->m_IRQ_mask_A = 0x00;
799
800   state->m_IOMD_keyb_ctrl = 0x00;
801
802   state->m_IOMD_timer[0]->adjust( attotime::never);
803   state->m_IOMD_timer[1]->adjust( attotime::never);
804   state->m_flyback_timer->adjust( attotime::never);
805}
806
807static MACHINE_CONFIG_START( a7000, a7000_state )
808
809   /* Basic machine hardware */
810   MCFG_CPU_ADD( "maincpu", ARM7, XTAL_32MHz )
811   MCFG_CPU_PROGRAM_MAP(a7000_mem)
812
813   MCFG_MACHINE_START( a7000 )
814   MCFG_MACHINE_RESET( a7000 )
815
816   /* video hardware */
817   MCFG_SCREEN_ADD("screen", RASTER)
818   MCFG_SCREEN_REFRESH_RATE(60)
819   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
820   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
821   MCFG_SCREEN_SIZE(1900, 1080) //max available size
822   MCFG_SCREEN_VISIBLE_AREA(0, 1900-1, 0, 1080-1)
823   MCFG_SCREEN_UPDATE(a7000)
824   MCFG_PALETTE_LENGTH(0x200)
825//  MCFG_PALETTE_INIT(black_and_white)
826
827   MCFG_VIDEO_START(a7000)
828MACHINE_CONFIG_END
829
830static MACHINE_CONFIG_DERIVED( a7000p, a7000 )
831
832   MCFG_CPU_MODIFY("maincpu")
833   MCFG_CPU_CLOCK(XTAL_48MHz)
834MACHINE_CONFIG_END
835
836ROM_START(a7000)
837   ROM_REGION( 0x800000, "user1", ROMREGION_ERASEFF )
838   ROM_LOAD( "rom1.bin", 0x000000, 0x100000, CRC(ff0e3d12) SHA1(fa489bebede3d13dc43cddec5b5c9b6829a28914) )
839   ROM_LOAD( "rom2.bin", 0x100000, 0x100000, CRC(4ae4fd8b) SHA1(1b30d5905d5364dfa48bad69257b0ef8190e9bf6) )
840   ROM_LOAD( "rom3.bin", 0x200000, 0x100000, CRC(3108fb2b) SHA1(865b01583f3fb5f4ed5e9201676db327cdeb40b3) )
841   ROM_LOAD( "rom4.bin", 0x300000, 0x100000, CRC(55a51980) SHA1(a7191727edd5babf679ebbdea6585833a1fb34e6) )
842
843   ROM_REGION( 0x800000, "vram", ROMREGION_ERASE00 )
844ROM_END
845
846ROM_START(a7000p)
847   ROM_REGION( 0x800000, "user1", ROMREGION_ERASEFF )
848   ROM_LOAD( "riscos-3.71.rom", 0x000000, 0x400000, CRC(211cf888) SHA1(c5fe0645e48894fb4b245abeefdc9a65d659af59))
849
850   ROM_REGION( 0x800000, "vram", ROMREGION_ERASE00 )
851ROM_END
852
853/***************************************************************************
854
855  Game driver(s)
856
857***************************************************************************/
858
859/*    YEAR  NAME        PARENT  COMPAT  MACHINE     INPUT   INIT    COMPANY FULLNAME        FLAGS */
860COMP( 1995, a7000,      0,      0,      a7000,      a7000,   0,      "Acorn",  "Archimedes A7000",   GAME_NOT_WORKING | GAME_NO_SOUND )
861COMP( 1997, a7000p,     a7000,  0,      a7000p,     a7000,   0,      "Acorn",  "Archimedes A7000+",  GAME_NOT_WORKING | GAME_NO_SOUND )
src/mess/drivers/ng_aes.c
r11460r11461
1/***************************************************************************
2
3    Neo-Geo AES hardware
4
5    Credits (from MAME neogeo.c, since this is just a minor edit of that driver):
6        * This driver was made possible by the research done by
7          Charles MacDonald.  For a detailed description of the Neo-Geo
8          hardware, please visit his page at:
9          http://cgfm2.emuviews.com/temp/mvstech.txt
10        * Presented to you by the Shin Emu Keikaku team.
11        * The following people have all spent probably far
12          too much time on this:
13          AVDB
14          Bryan McPhail
15          Fuzz
16          Ernesto Corvi
17          Andrew Prime
18          Zsolt Vasvari
19
20    MESS cartridge support by R. Belmont based on work by Michael Zapf
21
22    Current status:
23        - Cartridges run.
24
25    ToDo :
26        - Change input code to allow selection of the mahjong panel in PORT_CATEGORY.
27        - Clean up code, to reduce duplication of MAME source
28
29****************************************************************************/
30
31#include "emu.h"
32#include "cpu/m68000/m68000.h"
33#include "includes/neogeo.h"
34#include "machine/pd4990a.h"
35#include "cpu/z80/z80.h"
36#include "sound/2610intf.h"
37#include "devices/aescart.h"
38#include "imagedev/cartslot.h"
39#ifdef MESS
40#include "neogeo.lh"
41#else
42extern const char layout_neogeo[];
43#endif
44
45
46// CD-ROM / DMA control registers
47typedef struct
48{
49   UINT8 area_sel;
50   UINT8 pcm_bank_sel;
51   UINT8 spr_bank_sel;
52   UINT32 addr_source; // target if in fill mode
53   UINT32 addr_target;
54   UINT16 fill_word;
55   UINT32 word_count;
56   UINT16 dma_mode[10];
57} neocd_ctrl_t;
58
59class ng_aes_state : public neogeo_state
60{
61public:
62   ng_aes_state(const machine_config &mconfig, device_type type, const char *tag)
63      : neogeo_state(mconfig, type, tag) { }
64
65   UINT8 *m_memcard_data;
66   neocd_ctrl_t m_neocd_ctrl;
67};
68
69
70
71#define LOG_VIDEO_SYSTEM      (0)
72#define LOG_CPU_COMM         (0)
73#define LOG_MAIN_CPU_BANKING   (1)
74#define LOG_AUDIO_CPU_BANKING   (1)
75
76#define NEOCD_AREA_SPR    0
77#define NEOCD_AREA_PCM    1
78#define NEOCD_AREA_AUDIO  4
79#define NEOCD_AREA_FIX    5
80
81/*************************************
82 *
83 *  Global variables
84 *
85 *************************************/
86
87//static UINT16 *save_ram;
88
89UINT16* neocd_work_ram;
90
91/*************************************
92 *
93 *  Forward declarations
94 *
95 *************************************/
96
97//static void set_output_latch(running_machine &machine, UINT8 data);
98//static void set_output_data(running_machine &machine, UINT8 data);
99
100
101/*************************************
102 *
103 *  Main CPU interrupt generation
104 *
105 *************************************/
106
107#define IRQ2CTRL_ENABLE            (0x10)
108#define IRQ2CTRL_LOAD_RELATIVE      (0x20)
109#define IRQ2CTRL_AUTOLOAD_VBLANK   (0x40)
110#define IRQ2CTRL_AUTOLOAD_REPEAT   (0x80)
111
112
113static void adjust_display_position_interrupt_timer( running_machine &machine )
114{
115   neogeo_state *state = machine.driver_data<neogeo_state>();
116
117   if ((state->m_display_counter + 1) != 0)
118   {
119      attotime period = (attotime::from_hz(NEOGEO_PIXEL_CLOCK) * (state->m_display_counter + 1));
120      if (LOG_VIDEO_SYSTEM) logerror("adjust_display_position_interrupt_timer  current y: %02x  current x: %02x   target y: %x  target x: %x\n", machine.primary_screen->vpos(), machine.primary_screen->hpos(), (state->m_display_counter + 1) / NEOGEO_HTOTAL, (state->m_display_counter + 1) % NEOGEO_HTOTAL);
121
122      state->m_display_position_interrupt_timer->adjust(period);
123   }
124}
125
126#ifdef MESS
127void neogeo_set_display_position_interrupt_control( running_machine &machine, UINT16 data )
128{
129   neogeo_state *state = machine.driver_data<neogeo_state>();
130   state->m_display_position_interrupt_control = data;
131}
132
133
134void neogeo_set_display_counter_msb( address_space *space, UINT16 data )
135{
136   neogeo_state *state = space->machine().driver_data<neogeo_state>();
137
138   state->m_display_counter = (state->m_display_counter & 0x0000ffff) | ((UINT32)data << 16);
139
140   if (LOG_VIDEO_SYSTEM) logerror("PC %06x: set_display_counter %08x\n", cpu_get_pc(&space->device()), state->m_display_counter);
141}
142
143
144void neogeo_set_display_counter_lsb( address_space *space, UINT16 data )
145{
146   neogeo_state *state = space->machine().driver_data<neogeo_state>();
147
148   state->m_display_counter = (state->m_display_counter & 0xffff0000) | data;
149
150   if (LOG_VIDEO_SYSTEM) logerror("PC %06x: set_display_counter %08x\n", cpu_get_pc(&space->device()), state->m_display_counter);
151
152   if (state->m_display_position_interrupt_control & IRQ2CTRL_LOAD_RELATIVE)
153   {
154      if (LOG_VIDEO_SYSTEM) logerror("AUTOLOAD_RELATIVE ");
155      adjust_display_position_interrupt_timer(space->machine());
156   }
157}
158#endif
159
160static void update_interrupts( running_machine &machine )
161{
162   neogeo_state *state = machine.driver_data<neogeo_state>();
163
164   if(strcmp((char*)machine.system().name,"aes") != 0)
165   {  // raster and vblank IRQs are swapped on the NeoCD.
166      cputag_set_input_line(machine, "maincpu", 2, state->m_vblank_interrupt_pending ? ASSERT_LINE : CLEAR_LINE);
167      cputag_set_input_line(machine, "maincpu", 1, state->m_display_position_interrupt_pending ? ASSERT_LINE : CLEAR_LINE);
168      cputag_set_input_line(machine, "maincpu", 3, state->m_irq3_pending ? ASSERT_LINE : CLEAR_LINE);
169   }
170   else
171   {
172      cputag_set_input_line(machine, "maincpu", 1, state->m_vblank_interrupt_pending ? ASSERT_LINE : CLEAR_LINE);
173      cputag_set_input_line(machine, "maincpu", 2, state->m_display_position_interrupt_pending ? ASSERT_LINE : CLEAR_LINE);
174      cputag_set_input_line(machine, "maincpu", 3, state->m_irq3_pending ? ASSERT_LINE : CLEAR_LINE);
175   }
176}
177
178#ifdef MESS
179void neogeo_acknowledge_interrupt( running_machine &machine, UINT16 data )
180{
181   neogeo_state *state = machine.driver_data<neogeo_state>();
182
183   if (data & 0x01)
184      state->m_irq3_pending = 0;
185   if (data & 0x02)
186      state->m_display_position_interrupt_pending = 0;
187   if (data & 0x04)
188      state->m_vblank_interrupt_pending = 0;
189
190   update_interrupts(machine);
191}
192#endif
193
194static TIMER_CALLBACK( display_position_interrupt_callback )
195{
196   neogeo_state *state = machine.driver_data<neogeo_state>();
197
198   if (LOG_VIDEO_SYSTEM) logerror("--- Scanline @ %d,%d\n", machine.primary_screen->vpos(), machine.primary_screen->hpos());
199
200   if (state->m_display_position_interrupt_control & IRQ2CTRL_ENABLE)
201   {
202      if (LOG_VIDEO_SYSTEM) logerror("*** Scanline interrupt (IRQ2) ***  y: %02x  x: %02x\n", machine.primary_screen->vpos(), machine.primary_screen->hpos());
203      state->m_display_position_interrupt_pending = 1;
204
205      update_interrupts(machine);
206   }
207
208   if (state->m_display_position_interrupt_control & IRQ2CTRL_AUTOLOAD_REPEAT)
209   {
210      if (LOG_VIDEO_SYSTEM) logerror("AUTOLOAD_REPEAT ");
211      adjust_display_position_interrupt_timer(machine);
212   }
213}
214
215
216static TIMER_CALLBACK( display_position_vblank_callback )
217{
218   neogeo_state *state = machine.driver_data<neogeo_state>();
219
220   if (state->m_display_position_interrupt_control & IRQ2CTRL_AUTOLOAD_VBLANK)
221   {
222      if (LOG_VIDEO_SYSTEM) logerror("AUTOLOAD_VBLANK ");
223      adjust_display_position_interrupt_timer(machine);
224   }
225
226   /* set timer for next screen */
227   state->m_display_position_vblank_timer->adjust(machine.primary_screen->time_until_pos(NEOGEO_VBSTART, NEOGEO_VBLANK_RELOAD_HPOS));
228}
229
230
231static TIMER_CALLBACK( vblank_interrupt_callback )
232{
233   neogeo_state *state = machine.driver_data<neogeo_state>();
234
235   if (LOG_VIDEO_SYSTEM) logerror("+++ VBLANK @ %d,%d\n", machine.primary_screen->vpos(), machine.primary_screen->hpos());
236
237   /* add a timer tick to the pd4990a */
238   upd4990a_addretrace(state->m_upd4990a);
239
240   state->m_vblank_interrupt_pending = 1;
241
242   update_interrupts(machine);
243
244   /* set timer for next screen */
245   state->m_vblank_interrupt_timer->adjust(machine.primary_screen->time_until_pos(NEOGEO_VBSTART, 0));
246}
247
248
249static void create_interrupt_timers( running_machine &machine )
250{
251   neogeo_state *state = machine.driver_data<neogeo_state>();
252   state->m_display_position_interrupt_timer = machine.scheduler().timer_alloc(FUNC(display_position_interrupt_callback));
253   state->m_display_position_vblank_timer = machine.scheduler().timer_alloc(FUNC(display_position_vblank_callback));
254   state->m_vblank_interrupt_timer = machine.scheduler().timer_alloc(FUNC(vblank_interrupt_callback));
255}
256
257
258static void start_interrupt_timers( running_machine &machine )
259{
260   neogeo_state *state = machine.driver_data<neogeo_state>();
261   state->m_vblank_interrupt_timer->adjust(machine.primary_screen->time_until_pos(NEOGEO_VBSTART, 0));
262   state->m_display_position_vblank_timer->adjust(machine.primary_screen->time_until_pos(NEOGEO_VBSTART, NEOGEO_VBLANK_RELOAD_HPOS));
263}
264
265
266
267/*************************************
268 *
269 *  Audio CPU interrupt generation
270 *
271 *************************************/
272
273static void audio_cpu_irq(device_t *device, int assert)
274{
275   neogeo_state *state = device->machine().driver_data<neogeo_state>();
276   device_set_input_line(state->m_audiocpu, 0, assert ? ASSERT_LINE : CLEAR_LINE);
277}
278
279
280static void audio_cpu_assert_nmi(running_machine &machine)
281{
282   neogeo_state *state = machine.driver_data<neogeo_state>();
283   device_set_input_line(state->m_audiocpu, INPUT_LINE_NMI, ASSERT_LINE);
284}
285
286
287static WRITE8_HANDLER( audio_cpu_clear_nmi_w )
288{
289   neogeo_state *state = space->machine().driver_data<neogeo_state>();
290   device_set_input_line(state->m_audiocpu, INPUT_LINE_NMI, CLEAR_LINE);
291}
292
293
294
295/*************************************
296 *
297 *  Input ports / Controllers
298 *
299 *************************************/
300
301static void select_controller( running_machine &machine, UINT8 data )
302{
303   neogeo_state *state = machine.driver_data<neogeo_state>();
304   state->m_controller_select = data;
305}
306
307
308#if 0
309static CUSTOM_INPUT( multiplexed_controller_r )
310{
311   int port = (FPTR)param;
312
313   static const char *const cntrl[2][2] =
314      {
315         { "IN0-0", "IN0-1" }, { "IN1-0", "IN1-1" }
316      };
317
318   return input_port_read_safe(field->port->machine(), cntrl[port][controller_select & 0x01], 0x00);
319}
320
321
322static CUSTOM_INPUT( mahjong_controller_r )
323{
324   UINT32 ret;
325
326/*
327cpu #0 (PC=00C18B9A): unmapped memory word write to 00380000 = 0012 & 00FF
328cpu #0 (PC=00C18BB6): unmapped memory word write to 00380000 = 001B & 00FF
329cpu #0 (PC=00C18D54): unmapped memory word write to 00380000 = 0024 & 00FF
330cpu #0 (PC=00C18D6C): unmapped memory word write to 00380000 = 0009 & 00FF
331cpu #0 (PC=00C18C40): unmapped memory word write to 00380000 = 0000 & 00FF
332*/
333   switch (controller_select)
334   {
335   default:
336   case 0x00: ret = 0x0000; break; /* nothing? */
337   case 0x09: ret = input_port_read(field->port->machine(), "MAHJONG1"); break;
338   case 0x12: ret = input_port_read(field->port->machine(), "MAHJONG2"); break;
339   case 0x1b: ret = input_port_read(field->port->machine(), "MAHJONG3"); break; /* player 1 normal inputs? */
340   case 0x24: ret = input_port_read(field->port->machine(), "MAHJONG4"); break;
341   }
342
343   return ret;
344}
345
346#endif
347
348static WRITE16_HANDLER( io_control_w )
349{
350   neogeo_state *state = space->machine().driver_data<neogeo_state>();
351   switch (offset)
352   {
353   case 0x00: select_controller(space->machine(), data & 0x00ff); break;
354//  case 0x18: set_output_latch(space->machine(), data & 0x00ff); break;
355//  case 0x20: set_output_data(space->machine(), data & 0x00ff); break;
356   case 0x28: upd4990a_control_16_w(state->m_upd4990a, 0, data, mem_mask); break;
357//  case 0x30: break; // coin counters
358//  case 0x31: break; // coin counters
359//  case 0x32: break; // coin lockout
360//  case 0x33: break; // coui lockout
361
362   default:
363      logerror("PC: %x  Unmapped I/O control write.  Offset: %x  Data: %x\n", cpu_get_pc(&space->device()), offset, data);
364      break;
365   }
366}
367
368
369
370/*************************************
371 *
372 *  Unmapped memory access
373 *
374 *************************************/
375#ifdef MESS
376READ16_HANDLER( neogeo_unmapped_r )
377{
378   neogeo_state *state = space->machine().driver_data<neogeo_state>();
379   UINT16 ret;
380
381   /* unmapped memory returns the last word on the data bus, which is almost always the opcode
382       of the next instruction due to prefetch */
383
384   /* prevent recursion */
385   if (state->m_recurse)
386      ret = 0xffff;
387   else
388   {
389      state->m_recurse = 1;
390      ret = space->read_word(cpu_get_pc(&space->device()));
391      state->m_recurse = 0;
392   }
393
394   return ret;
395}
396#endif
397
398
399
400/*************************************
401 *
402 *  uPD4990A calendar chip
403 *
404 *************************************/
405#if 0
406static void calendar_init(running_machine &machine)
407{
408   /* set the celander IC to 'right now' */
409   system_time systime;
410   system_tm time;
411
412   machine.base_datetime(&systime);
413   time = systime.local_time;
414
415   pd4990a.seconds = ((time.second / 10) << 4) + (time.second % 10);
416   pd4990a.minutes = ((time.minute / 10) << 4) + (time.minute % 10);
417   pd4990a.hours = ((time.hour / 10) <<4 ) + (time.hour % 10);
418   pd4990a.days = ((time.mday / 10) << 4) + (time.mday % 10);
419   pd4990a.month = time.month + 1;
420   pd4990a.year = ((((time.year - 1900) % 100) / 10) << 4) + ((time.year - 1900) % 10);
421   pd4990a.weekday = time.weekday;
422}
423
424
425static void calendar_clock(void)
426{
427//  pd4990a_addretrace();
428}
429#endif
430
431static CUSTOM_INPUT( get_calendar_status )
432{
433   neogeo_state *state = field->port->machine().driver_data<neogeo_state>();
434   return (upd4990a_databit_r(state->m_upd4990a, 0) << 1) | upd4990a_testbit_r(state->m_upd4990a, 0);
435}
436
437
438
439/*************************************
440 *
441 *  NVRAM (Save RAM)
442 *
443 *************************************/
444#if 0
445static NVRAM_HANDLER( neogeo )
446{
447   if (read_or_write)
448      /* save the SRAM settings */
449      mame_fwrite(file, save_ram, 0x2000);
450   else
451   {
452      /* load the SRAM settings */
453      if (file)
454         mame_fread(file, save_ram, 0x2000);
455      else
456         memset(save_ram, 0, 0x10000);
457   }
458}
459
460
461static void set_save_ram_unlock( running_machine &machine, UINT8 data )
462{
463   neogeo_state *state = machine.driver_data<neogeo_state>();
464   state->m_save_ram_unlocked = data;
465}
466
467
468static WRITE16_HANDLER( save_ram_w )
469{
470   neogeo_state *state = space->machine().driver_data<neogeo_state>();
471
472   if (state->m_save_ram_unlocked)
473      COMBINE_DATA(&save_ram[offset]);
474}
475#endif
476
477
478/*************************************
479 *
480 *  Memory card
481 *
482 *************************************/
483
484#define MEMCARD_SIZE   0x0800
485
486static CUSTOM_INPUT( get_memcard_status )
487{
488   /* D0 and D1 are memcard presence indicators, D2 indicates memcard
489       write protect status (we are always write enabled) */
490   if(strcmp((char*)field->port->machine().system().name,"aes") != 0)
491      return 0x00;  // On the Neo Geo CD, the memory card is internal and therefore always present.
492   else
493      return (memcard_present(field->port->machine()) == -1) ? 0x07 : 0x00;
494}
495
496static READ16_HANDLER( memcard_r )
497{
498   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
499   UINT16 ret;
500
501   if (memcard_present(space->machine()) != -1)
502      ret = state->m_memcard_data[offset] | 0xff00;
503   else
504      ret = 0xffff;
505
506   return ret;
507}
508
509
510static WRITE16_HANDLER( memcard_w )
511{
512   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
513   if (ACCESSING_BITS_0_7)
514   {
515      if (memcard_present(space->machine()) != -1)
516         state->m_memcard_data[offset] = data;
517   }
518}
519
520/* The NeoCD has an 8kB internal memory card, instead of memcard slots like the MVS and AES */
521static READ16_HANDLER( neocd_memcard_r )
522{
523   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
524   return state->m_memcard_data[offset] | 0xff00;
525}
526
527
528static WRITE16_HANDLER( neocd_memcard_w )
529{
530   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
531   if (ACCESSING_BITS_0_7)
532   {
533      state->m_memcard_data[offset] = data;
534   }
535}
536
537static MEMCARD_HANDLER( neogeo )
538{
539   ng_aes_state *state = machine.driver_data<ng_aes_state>();
540   switch (action)
541   {
542   case MEMCARD_CREATE:
543      memset(state->m_memcard_data, 0, MEMCARD_SIZE);
544      file.write(state->m_memcard_data, MEMCARD_SIZE);
545      break;
546
547   case MEMCARD_INSERT:
548      file.read(state->m_memcard_data, MEMCARD_SIZE);
549      break;
550
551   case MEMCARD_EJECT:
552      file.write(state->m_memcard_data, MEMCARD_SIZE);
553      break;
554   }
555}
556
557
558
559/*************************************
560 *
561 *  Inter-CPU communications
562 *
563 *************************************/
564
565static WRITE16_HANDLER( audio_command_w )
566{
567   /* accessing the LSB only is not mapped */
568   if (mem_mask != 0x00ff)
569   {
570      soundlatch_w(space, 0, data >> 8);
571
572      audio_cpu_assert_nmi(space->machine());
573
574      /* boost the interleave to let the audio CPU read the command */
575      space->machine().scheduler().boost_interleave(attotime::zero, attotime::from_usec(50));
576
577      if (LOG_CPU_COMM) logerror("MAIN CPU PC %06x: audio_command_w %04x - %04x\n", cpu_get_pc(&space->device()), data, mem_mask);
578   }
579}
580
581
582static READ8_HANDLER( audio_command_r )
583{
584   UINT8 ret = soundlatch_r(space, 0);
585
586   if (LOG_CPU_COMM) logerror(" AUD CPU PC   %04x: audio_command_r %02x\n", cpu_get_pc(&space->device()), ret);
587
588   /* this is a guess */
589   audio_cpu_clear_nmi_w(space, 0, 0);
590
591   return ret;
592}
593
594
595static WRITE8_HANDLER( audio_result_w )
596{
597   neogeo_state *state = space->machine().driver_data<neogeo_state>();
598
599   if (LOG_CPU_COMM && (state->m_audio_result != data)) logerror(" AUD CPU PC   %04x: audio_result_w %02x\n", cpu_get_pc(&space->device()), data);
600
601   state->m_audio_result = data;
602}
603
604
605static CUSTOM_INPUT( get_audio_result )
606{
607   neogeo_state *state = field->port->machine().driver_data<neogeo_state>();
608   UINT32 ret = state->m_audio_result;
609
610//  if (LOG_CPU_COMM) logerror("MAIN CPU PC %06x: audio_result_r %02x\n", cpu_get_pc(field->port->machine().device("maincpu")), ret);
611
612   return ret;
613}
614
615
616
617/*************************************
618 *
619 *  Main CPU banking
620 *
621 *************************************/
622
623static void _set_main_cpu_vector_table_source( running_machine &machine )
624{
625   neogeo_state *state = machine.driver_data<neogeo_state>();
626   memory_set_bank(machine, NEOGEO_BANK_VECTORS, state->m_main_cpu_vector_table_source);
627}
628
629
630static void set_main_cpu_vector_table_source( running_machine &machine, UINT8 data )
631{
632   neogeo_state *state = machine.driver_data<neogeo_state>();
633   state->m_main_cpu_vector_table_source = data;
634
635   _set_main_cpu_vector_table_source(machine);
636}
637
638
639static void _set_main_cpu_bank_address( running_machine &machine )
640{
641   neogeo_state *state = machine.driver_data<neogeo_state>();
642   memory_set_bankptr(machine, NEOGEO_BANK_CARTRIDGE, &machine.region("maincpu")->base()[state->m_main_cpu_bank_address]);
643}
644
645#ifdef MESS
646void neogeo_set_main_cpu_bank_address( address_space *space, UINT32 bank_address )
647{
648   neogeo_state *state = space->machine().driver_data<neogeo_state>();
649
650   if (LOG_MAIN_CPU_BANKING) logerror("MAIN CPU PC %06x: neogeo_set_main_cpu_bank_address %06x\n", cpu_get_pc(&space->device()), bank_address);
651
652   state->m_main_cpu_bank_address = bank_address;
653
654   _set_main_cpu_bank_address(space->machine());
655}
656#endif
657
658static WRITE16_HANDLER( main_cpu_bank_select_w )
659{
660   UINT32 bank_address;
661   UINT32 len = space->machine().region("maincpu")->bytes();
662
663   if ((len <= 0x100000) && (data & 0x07))
664      logerror("PC %06x: warning: bankswitch to %02x but no banks available\n", cpu_get_pc(&space->device()), data);
665   else
666   {
667      bank_address = ((data & 0x07) + 1) * 0x100000;
668
669      if (bank_address >= len)
670      {
671         logerror("PC %06x: warning: bankswitch to empty bank %02x\n", cpu_get_pc(&space->device()), data);
672         bank_address = 0x100000;
673      }
674
675      neogeo_set_main_cpu_bank_address(space, bank_address);
676   }
677}
678
679
680static void main_cpu_banking_init( running_machine &machine )
681{
682   address_space *mainspace = machine.device("maincpu")->memory().space(AS_PROGRAM);
683
684   /* create vector banks */
685   memory_configure_bank(machine, NEOGEO_BANK_VECTORS, 0, 1, machine.region("mainbios")->base(), 0);
686   memory_configure_bank(machine, NEOGEO_BANK_VECTORS, 1, 1, machine.region("maincpu")->base(), 0);
687
688   /* set initial main CPU bank */
689   if (machine.region("maincpu")->bytes() > 0x100000)
690      neogeo_set_main_cpu_bank_address(mainspace, 0x100000);
691   else
692      neogeo_set_main_cpu_bank_address(mainspace, 0x000000);
693}
694
695
696
697/*************************************
698 *
699 *  Audio CPU banking
700 *
701 *************************************/
702
703static void set_audio_cpu_banking( running_machine &machine )
704{
705   neogeo_state *state = machine.driver_data<neogeo_state>();
706   int region;
707
708   for (region = 0; region < 4; region++)
709      memory_set_bank(machine, NEOGEO_BANK_AUDIO_CPU_CART_BANK + region, state->m_audio_cpu_banks[region]);
710}
711
712
713static void audio_cpu_bank_select( address_space *space, int region, UINT8 bank )
714{
715   neogeo_state *state = space->machine().driver_data<neogeo_state>();
716
717   if (LOG_AUDIO_CPU_BANKING) logerror("Audio CPU PC %03x: audio_cpu_bank_select: Region: %d   Bank: %02x\n", cpu_get_pc(&space->device()), region, bank);
718
719   state->m_audio_cpu_banks[region] = bank;
720
721   set_audio_cpu_banking(space->machine());
722}
723
724
725static READ8_HANDLER( audio_cpu_bank_select_f000_f7ff_r )
726{
727   audio_cpu_bank_select(space, 0, offset >> 8);
728
729   return 0;
730}
731
732
733static READ8_HANDLER( audio_cpu_bank_select_e000_efff_r )
734{
735   audio_cpu_bank_select(space, 1, offset >> 8);
736
737   return 0;
738}
739
740
741static READ8_HANDLER( audio_cpu_bank_select_c000_dfff_r )
742{
743   audio_cpu_bank_select(space, 2, offset >> 8);
744
745   return 0;
746}
747
748
749static READ8_HANDLER( audio_cpu_bank_select_8000_bfff_r )
750{
751   audio_cpu_bank_select(space, 3, offset >> 8);
752
753   return 0;
754}
755
756
757static void _set_audio_cpu_rom_source( address_space *space )
758{
759   neogeo_state *state = space->machine().driver_data<neogeo_state>();
760
761/*  if (!machine.region("audiobios")->base())   */
762      state->m_audio_cpu_rom_source = 1;
763
764   memory_set_bank(space->machine(), NEOGEO_BANK_AUDIO_CPU_MAIN_BANK, state->m_audio_cpu_rom_source);
765
766   /* reset CPU if the source changed -- this is a guess */
767   if (state->m_audio_cpu_rom_source != state->m_audio_cpu_rom_source_last)
768   {
769      state->m_audio_cpu_rom_source_last = state->m_audio_cpu_rom_source;
770
771      cputag_set_input_line(space->machine(), "audiocpu", INPUT_LINE_RESET, PULSE_LINE);
772
773      if (LOG_AUDIO_CPU_BANKING) logerror("Audio CPU PC %03x: selectign %s ROM\n", cpu_get_pc(&space->device()), state->m_audio_cpu_rom_source ? "CARTRIDGE" : "BIOS");
774   }
775}
776
777
778static void set_audio_cpu_rom_source( address_space *space, UINT8 data )
779{
780   neogeo_state *state = space->machine().driver_data<neogeo_state>();
781   state->m_audio_cpu_rom_source = data;
782
783   _set_audio_cpu_rom_source(space);
784}
785
786
787static void audio_cpu_banking_init( running_machine &machine )
788{
789   neogeo_state *state = machine.driver_data<neogeo_state>();
790   int region;
791   int bank;
792   UINT8 *rgn;
793   UINT32 address_mask;
794
795   /* audio bios/cartridge selection */
796   if (machine.region("audiobios")->base())
797      memory_configure_bank(machine, NEOGEO_BANK_AUDIO_CPU_MAIN_BANK, 0, 1, machine.region("audiobios")->base(), 0);
798   memory_configure_bank(machine, NEOGEO_BANK_AUDIO_CPU_MAIN_BANK, 1, 1, machine.region("audiocpu")->base(), 0);
799
800   /* audio banking */
801   address_mask = machine.region("audiocpu")->bytes() - 0x10000 - 1;
802
803   rgn = machine.region("audiocpu")->base();
804   for (region = 0; region < 4; region++)
805   {
806      for (bank = 0; bank < 0x100; bank++)
807      {
808         UINT32 bank_address = 0x10000 + (((bank << (11 + region)) & 0x3ffff) & address_mask);
809         memory_configure_bank(machine, NEOGEO_BANK_AUDIO_CPU_CART_BANK + region, bank, 1, &rgn[bank_address], 0);
810      }
811   }
812
813   /* set initial audio banks --
814       how does this really work, or is it even neccessary? */
815   state->m_audio_cpu_banks[0] = 0x1e;
816   state->m_audio_cpu_banks[1] = 0x0e;
817   state->m_audio_cpu_banks[2] = 0x06;
818   state->m_audio_cpu_banks[3] = 0x02;
819
820   set_audio_cpu_banking(machine);
821
822   state->m_audio_cpu_rom_source_last = 0;
823   set_audio_cpu_rom_source(machine.device("maincpu")->memory().space(AS_PROGRAM), 0);
824}
825
826
827
828/*************************************
829 *
830 *  System control register
831 *
832 *************************************/
833
834static WRITE16_HANDLER( system_control_w )
835{
836   if (ACCESSING_BITS_0_7)
837   {
838      UINT8 bit = (offset >> 3) & 0x01;
839
840      switch (offset & 0x07)
841      {
842      default:
843      case 0x00: neogeo_set_screen_dark(space->machine(), bit); break;
844      case 0x01: set_main_cpu_vector_table_source(space->machine(), bit);
845               set_audio_cpu_rom_source(space, bit); /* this is a guess */
846               break;
847      case 0x05: neogeo_set_fixed_layer_source(space->machine(), bit); break;
848//      case 0x06: set_save_ram_unlock(space->machine(), bit); break;
849      case 0x07: neogeo_set_palette_bank(space->machine(), bit); break;
850
851      case 0x02: /* unknown - HC32 middle pin 1 */
852      case 0x03: /* unknown - uPD4990 pin ? */
853      case 0x04: /* unknown - HC32 middle pin 10 */
854         logerror("PC: %x  Unmapped system control write.  Offset: %x  Data: %x\n", cpu_get_pc(&space->device()), offset & 0x07, bit);
855         break;
856      }
857
858      if (LOG_VIDEO_SYSTEM && ((offset & 0x07) != 0x06)) logerror("PC: %x  System control write.  Offset: %x  Data: %x\n", cpu_get_pc(&space->device()), offset & 0x07, bit);
859   }
860}
861
862/*
863 *  CD-ROM / DMA control
864 *
865 *  DMA
866
867    FF0061  Write 0x40 means start DMA transfer
868    FF0064  Source address (in copy mode), Target address (in filll mode)
869    FF0068  Target address (in copy mode)
870    FF006C  Fill word
871    FF0070  Words count
872    FF007E  \
873    ......   | DMA programming words?   NeoGeoCD uses Sanyo Puppet LC8359 chip to
874    FF008E  /                           interface with CD, and do DMA transfers
875
876    Memory access control
877
878    FF011C  DIP SWITCH (Region code)
879    FF0105  Area Selector (5 = FIX, 0 = SPR, 4 = Z80, 1 = PCM)
880    FF01A1  Sprite bank selector
881    FF01A3  PCM bank selector
882    FF0120  Prepare sprite area for transfer
883    FF0122  Prepare PCM area for transfer
884    FF0126  Prepare Z80 area for transfer
885    FF0128  Prepare Fix area for transfer
886    FF0140  Terminate work on Spr Area  (Sprites must be decoded here)
887    FF0142  Terminate work on Pcm Area
888    FF0146  Terminate work on Z80 Area  (Z80 needs to be reset)
889    FF0148  Terminate work on Fix Area
890
891    CD-ROM:
892    0xff0102 == 0xF0 start cd transfer
893    int m=bcd(fast_r8(0x10f6c8));
894    int s=bcd(fast_r8(0x10f6c9));
895    int f=bcd(fast_r8(0x10f6ca));
896    int seccount=fast_r16(0x10f688);
897
898    inisec=((m*60)+s)*75+f;
899    inisec-=150;
900    dstaddr=0x111204; // this must come from somewhere
901
902    the value @ 0x10f688 is decremented each time a sector is read until it's 0.
903
904 *
905 */
906
907static void neocd_do_dma(address_space* space)
908{
909   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
910   // TODO: Proper DMA timing and control
911   int count;
912//  UINT16 word;
913
914   switch(state->m_neocd_ctrl.dma_mode[0])
915   {
916   case 0xffdd:
917      for(count=0;count<state->m_neocd_ctrl.word_count;count++)
918      {
919         //word = space->read_word(state->m_neocd_ctrl.addr_source);
920         space->write_word(state->m_neocd_ctrl.addr_source+(count*2),state->m_neocd_ctrl.fill_word);
921      }
922      logerror("CTRL: DMA word-fill transfer of %i bytes\n",count*2);
923      break;
924   case 0xfef5:
925      for(count=0;count<state->m_neocd_ctrl.word_count;count++)
926      {
927         //word = space->read_word(state->m_neocd_ctrl.addr_source);
928         space->write_word(state->m_neocd_ctrl.addr_source+(count*4),(state->m_neocd_ctrl.addr_source+(count*4)) >> 16);
929         space->write_word(state->m_neocd_ctrl.addr_source+(count*4)+2,(state->m_neocd_ctrl.addr_source+(count*4)) & 0xffff);
930      }
931      logerror("CTRL: DMA mode 2 transfer of %i bytes\n",count*4);
932      break;
933   case 0xcffd:
934      for(count=0;count<state->m_neocd_ctrl.word_count;count++)
935      {
936         //word = space->read_word(state->m_neocd_ctrl.addr_source);
937         space->write_word(state->m_neocd_ctrl.addr_source+(count*8),((state->m_neocd_ctrl.addr_source+(count*8)) >> 24) | 0xff00);
938         space->write_word(state->m_neocd_ctrl.addr_source+(count*8)+2,((state->m_neocd_ctrl.addr_source+(count*8)) >> 16) | 0xff00);
939         space->write_word(state->m_neocd_ctrl.addr_source+(count*8)+4,((state->m_neocd_ctrl.addr_source+(count*8)) >> 8) | 0xff00);
940         space->write_word(state->m_neocd_ctrl.addr_source+(count*8)+6,(state->m_neocd_ctrl.addr_source+(count*8)) | 0xff00);
941      }
942      logerror("CTRL: DMA mode 3 transfer of %i bytes\n",count*8);
943      break;
944   default:
945      logerror("CTRL: Unknown DMA transfer mode %04x\n",state->m_neocd_ctrl.dma_mode[0]);
946   }
947}
948
949static READ16_HANDLER( neocd_control_r )
950{
951   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
952
953   switch(offset)
954   {
955   case 0x64/2: // source address, high word
956      return (state->m_neocd_ctrl.addr_source >> 16) & 0xffff;
957   case 0x66/2: // source address, low word
958      return state->m_neocd_ctrl.addr_source & 0xffff;
959   case 0x68/2: // target address, high word
960      return (state->m_neocd_ctrl.addr_target >> 16) & 0xffff;
961   case 0x6a/2: // target address, low word
962      return state->m_neocd_ctrl.addr_target & 0xffff;
963   case 0x6c/2: // fill word
964      return state->m_neocd_ctrl.fill_word;
965   case 0x70/2: // word count
966      return (state->m_neocd_ctrl.word_count >> 16) & 0xffff;
967   case 0x72/2:
968      return state->m_neocd_ctrl.word_count & 0xffff;
969   case 0x7e/2:  // DMA parameters
970   case 0x80/2:
971   case 0x82/2:
972   case 0x84/2:
973   case 0x86/2:
974   case 0x88/2:
975   case 0x8a/2:
976   case 0x8c/2:
977   case 0x8e/2:
978      return state->m_neocd_ctrl.dma_mode[offset-(0x7e/2)];
979      break;
980   case 0x105/2:
981      return state->m_neocd_ctrl.area_sel;
982   case 0x11c/2:
983      logerror("CTRL: Read region code.\n");
984      return 0x0600;  // we'll just force USA region for now
985   case 0x1a0/2:
986      return state->m_neocd_ctrl.spr_bank_sel;
987      break;
988   case 0x1a2/2:
989      return state->m_neocd_ctrl.pcm_bank_sel;
990      break;
991   default:
992      logerror("CTRL: Read offset %04x\n",offset);
993   }
994
995   return 0;
996}
997
998static WRITE16_HANDLER( neocd_control_w )
999{
1000   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
1001   switch(offset)
1002   {
1003   case 0x60/2: // Start DMA transfer
1004      if((data & 0xff) == 0x40)
1005         neocd_do_dma(space);
1006      break;
1007   case 0x64/2: // source address, high word
1008      state->m_neocd_ctrl.addr_source = (state->m_neocd_ctrl.addr_source & 0x0000ffff) | (data << 16);
1009      logerror("CTRL: Set source address to %08x\n",state->m_neocd_ctrl.addr_source);
1010      break;
1011   case 0x66/2: // source address, low word
1012      state->m_neocd_ctrl.addr_source = (state->m_neocd_ctrl.addr_source & 0xffff0000) | data;
1013      logerror("CTRL: Set source address to %08x\n",state->m_neocd_ctrl.addr_source);
1014      break;
1015   case 0x68/2: // target address, high word
1016      state->m_neocd_ctrl.addr_target = (state->m_neocd_ctrl.addr_target & 0x0000ffff) | (data << 16);
1017      logerror("CTRL: Set target address to %08x\n",state->m_neocd_ctrl.addr_target);
1018      break;
1019   case 0x6a/2: // target address, low word
1020      state->m_neocd_ctrl.addr_target = (state->m_neocd_ctrl.addr_target & 0xffff0000) | data;
1021      logerror("CTRL: Set target address to %08x\n",state->m_neocd_ctrl.addr_target);
1022      break;
1023   case 0x6c/2: // fill word
1024      state->m_neocd_ctrl.fill_word = data;
1025      logerror("CTRL: Set fill word to %04x\n",data);
1026      break;
1027   case 0x70/2: // word count
1028      state->m_neocd_ctrl.word_count = (state->m_neocd_ctrl.word_count & 0x0000ffff) | (data << 16);
1029      logerror("CTRL: Set word count to %i\n",state->m_neocd_ctrl.word_count);
1030      break;
1031   case 0x72/2: // word count (low word)
1032      state->m_neocd_ctrl.word_count = (state->m_neocd_ctrl.word_count & 0xffff0000) | data;
1033      logerror("CTRL: Set word count to %i\n",state->m_neocd_ctrl.word_count);
1034      break;
1035   case 0x7e/2:  // DMA parameters
1036   case 0x80/2:
1037   case 0x82/2:
1038   case 0x84/2:
1039   case 0x86/2:
1040   case 0x88/2:
1041   case 0x8a/2:
1042   case 0x8c/2:
1043   case 0x8e/2:
1044      state->m_neocd_ctrl.dma_mode[offset-(0x7e/2)] = data;
1045      logerror("CTRL: DMA parameter %i set to %04x\n",offset-(0x7e/2),data);
1046      break;
1047   case 0x104/2:
1048      state->m_neocd_ctrl.area_sel = data & 0x00ff;
1049      logerror("CTRL: 0xExxxxx set to area %i\n",data & 0xff);
1050      break;
1051   case 0x140/2:  // end sprite transfer
1052      video_reset_neogeo(space->machine());
1053      break;
1054   case 0x142/2:  // end PCM transfer
1055      break;
1056   case 0x146/2:  // end Z80 transfer
1057      cputag_set_input_line(space->machine(),"audiocpu",INPUT_LINE_RESET,PULSE_LINE);
1058      break;
1059   case 0x148/2:  // end FIX transfer
1060      video_reset_neogeo(space->machine());
1061      break;
1062   case 0x1a0/2:
1063      state->m_neocd_ctrl.spr_bank_sel = data & 0xff;
1064      logerror("CTRL: Sprite area set to bank %i\n",data & 0xff);
1065      break;
1066   case 0x1a2/2:
1067      state->m_neocd_ctrl.pcm_bank_sel = data & 0xff;
1068      logerror("CTRL: PCM area set to bank %i\n",data & 0xff);
1069      break;
1070   default:
1071      logerror("CTRL: Write offset %04x, data %04x\n",offset*2,data);
1072   }
1073}
1074
1075/*
1076 *  Handling NeoCD banked RAM
1077 *  When the Z80 space is banked in to 0xe00000, only the low byte of each word is used
1078 */
1079
1080static READ16_HANDLER(neocd_transfer_r)
1081{
1082   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
1083   UINT16 ret = 0x0000;
1084   UINT8* Z80 = space->machine().region("audiocpu")->base();
1085   UINT8* PCM = space->machine().region("ymsnd")->base();
1086   UINT8* FIX = space->machine().region("fixed")->base();
1087   UINT16* SPR = (UINT16*)space->machine().region("sprites")->base();
1088
1089   switch(state->m_neocd_ctrl.area_sel)
1090   {
1091   case NEOCD_AREA_AUDIO:
1092      ret = Z80[offset & 0xffff] | 0xff00;
1093      break;
1094   case NEOCD_AREA_PCM:
1095      ret = PCM[offset + (0x100000*state->m_neocd_ctrl.pcm_bank_sel)] | 0xff00;
1096      break;
1097   case NEOCD_AREA_SPR:
1098      ret = SPR[offset + (0x80000*state->m_neocd_ctrl.spr_bank_sel)];
1099      break;
1100   case NEOCD_AREA_FIX:
1101      ret = FIX[offset & 0x1ffff] | 0xff00;
1102      break;
1103   }
1104
1105   return ret;
1106}
1107
1108static WRITE16_HANDLER(neocd_transfer_w)
1109{
1110   ng_aes_state *state = space->machine().driver_data<ng_aes_state>();
1111   UINT8* Z80 = space->machine().region("audiocpu")->base();
1112   UINT8* PCM = space->machine().region("ymsnd")->base();
1113   UINT8* FIX = space->machine().region("fixed")->base();
1114   UINT16* SPR = (UINT16*)space->machine().region("sprites")->base();
1115
1116   switch(state->m_neocd_ctrl.area_sel)
1117   {
1118   case NEOCD_AREA_AUDIO:
1119      Z80[offset & 0xffff] = data & 0xff;
1120      break;
1121   case NEOCD_AREA_PCM:
1122      PCM[offset + (0x100000*state->m_neocd_ctrl.pcm_bank_sel)] = data & 0xff;
1123      break;
1124   case NEOCD_AREA_SPR:
1125      COMBINE_DATA(SPR+(offset + (0x80000*state->m_neocd_ctrl.spr_bank_sel)));
1126      break;
1127   case NEOCD_AREA_FIX:
1128      FIX[offset & 0x1ffff] = data & 0xff;
1129      break;
1130   }
1131
1132}
1133
1134/*
1135 * Handling selectable controller types
1136 */
1137
1138static READ16_HANDLER( aes_in0_r )
1139{
1140   neogeo_state *state = space->machine().driver_data<neogeo_state>();
1141   UINT32 ret = 0xffff;
1142   UINT32 ctrl = input_port_read(space->machine(),"CTRLSEL");
1143
1144   switch(ctrl & 0x0f)
1145   {
1146   case 0x00:
1147      ret = 0xffff;
1148      break;
1149   case 0x01:
1150      ret = input_port_read(space->machine(),"IN0");
1151      break;
1152   case 0x02:
1153      switch (state->m_controller_select)
1154      {
1155         case 0x09: ret = input_port_read(space->machine(), "MJ01_P1"); break;
1156         case 0x12: ret = input_port_read(space->machine(), "MJ02_P1"); break;
1157         case 0x1b: ret = input_port_read(space->machine(), "MJ03_P1"); break; /* player 1 normal inputs? */
1158         case 0x24: ret = input_port_read(space->machine(), "MJ04_P1"); break;
1159         default:
1160            ret = input_port_read(space->machine(),"IN0");
1161            break;
1162      }
1163      break;
1164   }
1165
1166   return ret;
1167}
1168
1169static READ16_HANDLER( aes_in1_r )
1170{
1171   neogeo_state *state = space->machine().driver_data<neogeo_state>();
1172   UINT32 ret = 0xffff;
1173   UINT32 ctrl = input_port_read(space->machine(),"CTRLSEL");
1174
1175   switch(ctrl & 0xf0)
1176   {
1177   case 0x00:
1178      ret = 0xffff;
1179      break;
1180   case 0x10:
1181      ret = input_port_read(space->machine(),"IN1");
1182      break;
1183   case 0x20:
1184      switch (state->m_controller_select)
1185      {
1186         case 0x09: ret = input_port_read(space->machine(), "MJ01_P2"); break;
1187         case 0x12: ret = input_port_read(space->machine(), "MJ02_P2"); break;
1188         case 0x1b: ret = input_port_read(space->machine(), "MJ03_P2"); break; /* player 2 normal inputs? */
1189         case 0x24: ret = input_port_read(space->machine(), "MJ04_P2"); break;
1190         default:
1191            ret = input_port_read(space->machine(),"IN1");
1192            break;
1193      }
1194      break;
1195   }
1196
1197   return ret;
1198}
1199
1200
1201static READ16_HANDLER(aes_in2_r)
1202{
1203   UINT32 in2 = input_port_read(space->machine(),"IN2");
1204   UINT32 ret = in2;
1205   UINT32 sel = input_port_read(space->machine(),"CTRLSEL");
1206   neogeo_state *state = space->machine().driver_data<neogeo_state>();
1207
1208   if((sel & 0x02) && (state->m_controller_select == 0x24))
1209      ret ^= 0x0200;
1210
1211   if((sel & 0x20) && (state->m_controller_select == 0x24))
1212      ret ^= 0x0800;
1213
1214   return ret;
1215}
1216
1217
1218/*************************************
1219 *
1220 *  Machine initialization
1221 *
1222 *************************************/
1223
1224static void aes_postload(neogeo_state *state)
1225{
1226   _set_main_cpu_bank_address(state->machine());
1227   _set_main_cpu_vector_table_source(state->machine());
1228   set_audio_cpu_banking(state->machine());
1229   _set_audio_cpu_rom_source(state->machine().device("maincpu")->memory().space(AS_PROGRAM));
1230}
1231
1232static void common_machine_start(running_machine &machine)
1233{
1234   neogeo_state *state = machine.driver_data<neogeo_state>();
1235
1236   /* set the BIOS bank */
1237   memory_set_bankptr(machine, NEOGEO_BANK_BIOS, machine.region("mainbios")->base());
1238
1239   /* set the initial main CPU bank */
1240   main_cpu_banking_init(machine);
1241
1242   /* set the initial audio CPU ROM banks */
1243   audio_cpu_banking_init(machine);
1244
1245   create_interrupt_timers(machine);
1246
1247   /* start with an IRQ3 - but NOT on a reset */
1248   state->m_irq3_pending = 1;
1249
1250   /* get devices */
1251   state->m_maincpu = machine.device("maincpu");
1252   state->m_audiocpu = machine.device("audiocpu");
1253   state->m_upd4990a = machine.device("upd4990a");
1254
1255   /* register state save */
1256   state->save_item(NAME(state->m_display_position_interrupt_control));
1257   state->save_item(NAME(state->m_display_counter));
1258   state->save_item(NAME(state->m_vblank_interrupt_pending));
1259   state->save_item(NAME(state->m_display_position_interrupt_pending));
1260   state->save_item(NAME(state->m_irq3_pending));
1261   state->save_item(NAME(state->m_audio_result));
1262   state->save_item(NAME(state->m_controller_select));
1263   state->save_item(NAME(state->m_main_cpu_bank_address));
1264   state->save_item(NAME(state->m_main_cpu_vector_table_source));
1265   state->save_item(NAME(state->m_audio_cpu_banks));
1266   state->save_item(NAME(state->m_audio_cpu_rom_source));
1267   state->save_item(NAME(state->m_audio_cpu_rom_source_last));
1268   state->save_item(NAME(state->m_save_ram_unlocked));
1269   state->save_item(NAME(state->m_output_data));
1270   state->save_item(NAME(state->m_output_latch));
1271   state->save_item(NAME(state->m_el_value));
1272   state->save_item(NAME(state->m_led1_value));
1273   state->save_item(NAME(state->m_led2_value));
1274   state->save_item(NAME(state->m_recurse));
1275
1276   machine.save().register_postload(save_prepost_delegate(FUNC(aes_postload), state));
1277}
1278
1279static MACHINE_START( neogeo )
1280{
1281   ng_aes_state *state = machine.driver_data<ng_aes_state>();
1282   common_machine_start(machine);
1283
1284   /* initialize the memcard data structure */
1285   state->m_memcard_data = auto_alloc_array_clear(machine, UINT8, MEMCARD_SIZE);
1286   state->save_pointer(NAME(state->m_memcard_data), 0x0800);
1287}
1288
1289static MACHINE_START(neocd)
1290{
1291   ng_aes_state *state = machine.driver_data<ng_aes_state>();
1292   UINT8* ROM = machine.region("mainbios")->base();
1293   UINT8* RAM = machine.region("maincpu")->base();
1294   UINT8* Z80bios = machine.region("audiobios")->base();
1295   UINT8* FIXbios = machine.region("fixedbios")->base();
1296   int x;
1297
1298   common_machine_start(machine);
1299
1300   /* initialize the memcard data structure */
1301   /* NeoCD doesn't have memcard slots, rather, it has a larger internal memory which works the same */
1302   state->m_memcard_data = auto_alloc_array_clear(machine, UINT8, 0x2000);
1303   state->save_pointer(NAME(state->m_memcard_data), 0x2000);
1304
1305   // copy initial 68k vectors into RAM
1306   memcpy(RAM,ROM,0x80);
1307
1308   // copy Z80 code into Z80 space (from 0x20000)
1309   for(x=0;x<0x10000;x+=2)
1310   {
1311      Z80bios[x] = ROM[x+0x20001];
1312      Z80bios[x+1] = ROM[x+0x20000];
1313   }
1314
1315   // copy fixed tiles into FIX space (from 0x70000)
1316   memcpy(FIXbios,ROM+0x70000,0x10000);
1317}
1318
1319//static DEVICE_IMAGE_LOAD(aes_cart)
1320//{
1321//  else
1322//      return IMAGE_INIT_FAIL;
1323
1324//  return IMAGE_INIT_PASS;
1325//}
1326
1327/*************************************
1328 *
1329 *  Machine reset
1330 *
1331 *************************************/
1332
1333static MACHINE_RESET( neogeo )
1334{
1335   neogeo_state *state = machine.driver_data<neogeo_state>();
1336   offs_t offs;
1337   address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
1338
1339   /* reset system control registers */
1340   for (offs = 0; offs < 8; offs++)
1341      system_control_w(space, offs, 0, 0x00ff);
1342
1343   machine.device("maincpu")->reset();
1344
1345   neogeo_reset_rng(machine);
1346
1347   start_interrupt_timers(machine);
1348
1349   /* trigger the IRQ3 that was set by MACHINE_START */
1350   update_interrupts(machine);
1351
1352   state->m_recurse = 0;
1353
1354   /* AES apparently always uses the cartridge's fixed bank mode */
1355   neogeo_set_fixed_layer_source(machine,1);
1356}
1357
1358
1359
1360/*************************************
1361 *
1362 *  Main CPU memory handlers
1363 *
1364 *************************************/
1365
1366static ADDRESS_MAP_START( main_map, AS_PROGRAM, 16 )
1367   AM_RANGE(0x000000, 0x00007f) AM_ROMBANK(NEOGEO_BANK_VECTORS)
1368   AM_RANGE(0x000080, 0x0fffff) AM_ROM
1369   AM_RANGE(0x100000, 0x10ffff) AM_MIRROR(0x0f0000) AM_RAM
1370   /* some games have protection devices in the 0x200000 region, it appears to map to cart space, not surprising, the ROM is read here too */
1371   AM_RANGE(0x200000, 0x2fffff) AM_ROMBANK(NEOGEO_BANK_CARTRIDGE)
1372   AM_RANGE(0x2ffff0, 0x2fffff) AM_WRITE(main_cpu_bank_select_w)
1373   AM_RANGE(0x300000, 0x300001) AM_MIRROR(0x01ff7e) AM_READ(aes_in0_r)
1374   AM_RANGE(0x300080, 0x300081) AM_MIRROR(0x01ff7e) AM_READ_PORT("IN4")
1375   AM_RANGE(0x300000, 0x300001) AM_MIRROR(0x01ffe0) AM_READ(neogeo_unmapped_r) AM_WRITENOP   // AES has no watchdog
1376   AM_RANGE(0x320000, 0x320001) AM_MIRROR(0x01fffe) AM_READ_PORT("IN3") AM_WRITE(audio_command_w)
1377   AM_RANGE(0x340000, 0x340001) AM_MIRROR(0x01fffe) AM_READ(aes_in1_r)
1378   AM_RANGE(0x360000, 0x37ffff) AM_READ(neogeo_unmapped_r)
1379   AM_RANGE(0x380000, 0x380001) AM_MIRROR(0x01fffe) AM_READ(aes_in2_r)
1380   AM_RANGE(0x380000, 0x38007f) AM_MIRROR(0x01ff80) AM_WRITE(io_control_w)
1381   AM_RANGE(0x3a0000, 0x3a001f) AM_MIRROR(0x01ffe0) AM_READWRITE(neogeo_unmapped_r, system_control_w)
1382   AM_RANGE(0x3c0000, 0x3c0007) AM_MIRROR(0x01fff8) AM_READ(neogeo_video_register_r)
1383   AM_RANGE(0x3c0000, 0x3c000f) AM_MIRROR(0x01fff0) AM_WRITE(neogeo_video_register_w)
1384   AM_RANGE(0x3e0000, 0x3fffff) AM_READ(neogeo_unmapped_r)
1385   AM_RANGE(0x400000, 0x401fff) AM_MIRROR(0x3fe000) AM_READWRITE(neogeo_paletteram_r, neogeo_paletteram_w)
1386   AM_RANGE(0x800000, 0x800fff) AM_READWRITE(memcard_r, memcard_w)
1387   AM_RANGE(0xc00000, 0xc1ffff) AM_MIRROR(0x0e0000) AM_ROMBANK(NEOGEO_BANK_BIOS)
1388   AM_RANGE(0xd00000, 0xd0ffff) AM_MIRROR(0x0f0000) AM_READ(neogeo_unmapped_r) //AM_RAM_WRITE(save_ram_w) AM_BASE(&save_ram)
1389   AM_RANGE(0xe00000, 0xffffff) AM_READ(neogeo_unmapped_r)
1390ADDRESS_MAP_END
1391
1392static ADDRESS_MAP_START( neocd_main_map, AS_PROGRAM, 16 )
1393   AM_RANGE(0x000000, 0x00007f) AM_RAMBANK(NEOGEO_BANK_VECTORS)
1394   AM_RANGE(0x000080, 0x0fffff) AM_RAM
1395   AM_RANGE(0x100000, 0x10ffff) AM_MIRROR(0x0f0000) AM_RAM AM_BASE(&neocd_work_ram)
1396   /* some games have protection devices in the 0x200000 region, it appears to map to cart space, not surprising, the ROM is read here too */
1397   AM_RANGE(0x200000, 0x2fffff) AM_ROMBANK(NEOGEO_BANK_CARTRIDGE)
1398   AM_RANGE(0x2ffff0, 0x2fffff) AM_WRITE(main_cpu_bank_select_w)
1399   AM_RANGE(0x300000, 0x300001) AM_MIRROR(0x01ff7e) AM_READ(aes_in0_r)
1400   AM_RANGE(0x300080, 0x300081) AM_MIRROR(0x01ff7e) AM_READ_PORT("IN4")
1401   AM_RANGE(0x300000, 0x300001) AM_MIRROR(0x01ffe0) AM_READ(neogeo_unmapped_r) AM_WRITENOP   // AES has no watchdog
1402   AM_RANGE(0x320000, 0x320001) AM_MIRROR(0x01fffe) AM_READ_PORT("IN3") AM_WRITE(audio_command_w)
1403   AM_RANGE(0x340000, 0x340001) AM_MIRROR(0x01fffe) AM_READ(aes_in1_r)
1404   AM_RANGE(0x360000, 0x37ffff) AM_READ(neogeo_unmapped_r)
1405   AM_RANGE(0x380000, 0x380001) AM_MIRROR(0x01fffe) AM_READ(aes_in2_r)
1406   AM_RANGE(0x380000, 0x38007f) AM_MIRROR(0x01ff80) AM_WRITE(io_control_w)
1407   AM_RANGE(0x3a0000, 0x3a001f) AM_MIRROR(0x01ffe0) AM_READWRITE(neogeo_unmapped_r, system_control_w)
1408   AM_RANGE(0x3c0000, 0x3c0007) AM_MIRROR(0x01fff8) AM_READ(neogeo_video_register_r)
1409   AM_RANGE(0x3c0000, 0x3c000f) AM_MIRROR(0x01fff0) AM_WRITE(neogeo_video_register_w)
1410   AM_RANGE(0x3e0000, 0x3fffff) AM_READ(neogeo_unmapped_r)
1411   AM_RANGE(0x400000, 0x401fff) AM_MIRROR(0x3fe000) AM_READWRITE(neogeo_paletteram_r, neogeo_paletteram_w)
1412   AM_RANGE(0x800000, 0x803fff) AM_READWRITE(neocd_memcard_r, neocd_memcard_w)
1413   AM_RANGE(0xc00000, 0xcfffff) AM_ROMBANK(NEOGEO_BANK_BIOS)
1414   AM_RANGE(0xd00000, 0xd0ffff) AM_MIRROR(0x0f0000) AM_READ(neogeo_unmapped_r) //AM_RAM_WRITE(save_ram_w) AM_BASE(&save_ram)
1415   AM_RANGE(0xe00000, 0xefffff) AM_READWRITE(neocd_transfer_r,neocd_transfer_w)
1416   AM_RANGE(0xf00000, 0xfeffff) AM_READ(neogeo_unmapped_r)
1417   AM_RANGE(0xff0000, 0xff01ff) AM_READWRITE(neocd_control_r, neocd_control_w) // CDROM / DMA
1418   AM_RANGE(0xff0200, 0xffffff) AM_READ(neogeo_unmapped_r)
1419ADDRESS_MAP_END
1420
1421
1422/*************************************
1423 *
1424 *  Audio CPU memory handlers
1425 *
1426 *************************************/
1427
1428static ADDRESS_MAP_START( audio_map, AS_PROGRAM, 8 )
1429   AM_RANGE(0x0000, 0x7fff) AM_ROMBANK(NEOGEO_BANK_AUDIO_CPU_MAIN_BANK)
1430   AM_RANGE(0x8000, 0xbfff) AM_ROMBANK(NEOGEO_BANK_AUDIO_CPU_CART_BANK + 3)
1431   AM_RANGE(0xc000, 0xdfff) AM_ROMBANK(NEOGEO_BANK_AUDIO_CPU_CART_BANK + 2)
1432   AM_RANGE(0xe000, 0xefff) AM_ROMBANK(NEOGEO_BANK_AUDIO_CPU_CART_BANK + 1)
1433   AM_RANGE(0xf000, 0xf7ff) AM_ROMBANK(NEOGEO_BANK_AUDIO_CPU_CART_BANK + 0)
1434   AM_RANGE(0xf800, 0xffff) AM_RAM
1435ADDRESS_MAP_END
1436
1437
1438
1439/*************************************
1440 *
1441 *  Audio CPU port handlers
1442 *
1443 *************************************/
1444
1445static ADDRESS_MAP_START( audio_io_map, AS_IO, 8 )
1446  /*AM_RANGE(0x00, 0x00) AM_MIRROR(0xff00) AM_READWRITE(audio_command_r, audio_cpu_clear_nmi_w);*/  /* may not and NMI clear */
1447   AM_RANGE(0x00, 0x00) AM_MIRROR(0xff00) AM_READ(audio_command_r)
1448   AM_RANGE(0x04, 0x07) AM_MIRROR(0xff00) AM_DEVREADWRITE("ymsnd", ym2610_r, ym2610_w)
1449   AM_RANGE(0x08, 0x08) AM_MIRROR(0xff00) /* write - NMI enable / acknowledge? (the data written doesn't matter) */
1450   AM_RANGE(0x08, 0x08) AM_MIRROR(0xfff0) AM_MASK(0xfff0) AM_READ(audio_cpu_bank_select_f000_f7ff_r)
1451   AM_RANGE(0x09, 0x09) AM_MIRROR(0xfff0) AM_MASK(0xfff0) AM_READ(audio_cpu_bank_select_e000_efff_r)
1452   AM_RANGE(0x0a, 0x0a) AM_MIRROR(0xfff0) AM_MASK(0xfff0) AM_READ(audio_cpu_bank_select_c000_dfff_r)
1453   AM_RANGE(0x0b, 0x0b) AM_MIRROR(0xfff0) AM_MASK(0xfff0) AM_READ(audio_cpu_bank_select_8000_bfff_r)
1454   AM_RANGE(0x0c, 0x0c) AM_MIRROR(0xff00) AM_WRITE(audio_result_w)
1455   AM_RANGE(0x18, 0x18) AM_MIRROR(0xff00) /* write - NMI disable? (the data written doesn't matter) */
1456ADDRESS_MAP_END
1457
1458
1459
1460/*************************************
1461 *
1462 *  Audio interface
1463 *
1464 *************************************/
1465
1466static const ym2610_interface ym2610_config =
1467{
1468   audio_cpu_irq
1469};
1470
1471
1472
1473/*************************************
1474 *
1475 *  Standard Neo-Geo DIPs and
1476 *  input port definition
1477 *
1478 *************************************/
1479
1480#define STANDARD_DIPS                                                      \
1481   PORT_DIPNAME( 0x0001, 0x0001, "Test Switch" ) PORT_DIPLOCATION("SW:1")               \
1482   PORT_DIPSETTING(     0x0001, DEF_STR( Off ) )                                 \
1483   PORT_DIPSETTING(     0x0000, DEF_STR( On ) )                                 \
1484   PORT_DIPNAME( 0x0002, 0x0002, "Coin Chutes?" ) PORT_DIPLOCATION("SW:2")               \
1485   PORT_DIPSETTING(     0x0000, "1?" )                                       \
1486   PORT_DIPSETTING(     0x0002, "2?" )                                       \
1487   PORT_DIPNAME( 0x0004, 0x0004, "Autofire (in some games)" ) PORT_DIPLOCATION("SW:3")      \
1488   PORT_DIPSETTING(     0x0004, DEF_STR( Off ) )                                 \
1489   PORT_DIPSETTING(     0x0000, DEF_STR( On ) )                                 \
1490   PORT_DIPNAME( 0x0018, 0x0018, "COMM Setting (Cabinet No.)" ) PORT_DIPLOCATION("SW:4,5")   \
1491   PORT_DIPSETTING(     0x0018, "1" )                                          \
1492   PORT_DIPSETTING(     0x0008, "2" )                                          \
1493   PORT_DIPSETTING(     0x0010, "3" )                                          \
1494   PORT_DIPSETTING(     0x0000, "4" )                                          \
1495   PORT_DIPNAME( 0x0020, 0x0020, "COMM Setting (Link Enable)" ) PORT_DIPLOCATION("SW:6")   \
1496   PORT_DIPSETTING(     0x0020, DEF_STR( Off ) )                                 \
1497   PORT_DIPSETTING(     0x0000, DEF_STR( On ) )                                 \
1498   PORT_DIPNAME( 0x0040, 0x0040, DEF_STR( Free_Play ) ) PORT_DIPLOCATION("SW:7")         \
1499   PORT_DIPSETTING(     0x0040, DEF_STR( Off ) )                                 \
1500   PORT_DIPSETTING(     0x0000, DEF_STR( On ) )                                 \
1501   PORT_DIPNAME( 0x0080, 0x0080, "Freeze" ) PORT_DIPLOCATION("SW:8")                  \
1502   PORT_DIPSETTING(     0x0080, DEF_STR( Off ) )                                 \
1503   PORT_DIPSETTING(     0x0000, DEF_STR( On ) )
1504
1505#define STANDARD_IN2                                                            \
1506   PORT_START("IN2")                                                            \
1507   PORT_BIT( 0x00ff, IP_ACTIVE_LOW, IPT_UNUSED )                                       \
1508   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_START1 )                           \
1509   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON5) PORT_NAME("1P Select") PORT_CODE(KEYCODE_5) PORT_PLAYER(1)   \
1510   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_START2 )                           \
1511   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON5) PORT_NAME("2P Select") PORT_CODE(KEYCODE_6) PORT_PLAYER(2)   \
1512   PORT_BIT( 0x7000, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(get_memcard_status, NULL)         \
1513   PORT_BIT( 0x8000, IP_ACTIVE_HIGH, IPT_UNKNOWN )  /* Matrimelee expects this bit to be active high when on an AES */
1514
1515#define STANDARD_IN3                                                            \
1516   PORT_START("IN3")                                                            \
1517   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_UNUSED )  /* Coin 1 - AES has no coin slots, it's a console */   \
1518   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_UNUSED )  /* Coin 2 - AES has no coin slots, it's a console */   \
1519   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_UNUSED )  /* Service Coin - not used, AES is a console */   \
1520   PORT_BIT( 0x0008, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* having this ACTIVE_HIGH causes you to start with 2 credits using USA bios roms */   \
1521   PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* having this ACTIVE_HIGH causes you to start with 2 credits using USA bios roms */   \
1522   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_SPECIAL ) /* what is this? */                        \
1523   PORT_BIT( 0x00c0, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(get_calendar_status, NULL)         \
1524   PORT_BIT( 0xff00, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(get_audio_result, NULL)
1525
1526
1527#define STANDARD_IN4                                                         \
1528   PORT_START("IN4")                                                         \
1529   PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_UNKNOWN )                                    \
1530   PORT_BIT( 0x0002, IP_ACTIVE_HIGH, IPT_UNKNOWN )                                    \
1531   PORT_BIT( 0x0004, IP_ACTIVE_HIGH, IPT_UNKNOWN )                                    \
1532   PORT_BIT( 0x0008, IP_ACTIVE_HIGH, IPT_UNKNOWN )                                    \
1533   PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_UNKNOWN )                                    \
1534   PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_UNKNOWN )                                    \
1535   PORT_BIT( 0x0040, IP_ACTIVE_HIGH, IPT_SPECIAL ) /* what is this? - is 0 for 1 or 2 slot MVS (and AES?)*/                     \
1536   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("Enter BIOS") PORT_CODE(KEYCODE_F2)   \
1537   PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNUSED )
1538
1539static INPUT_PORTS_START( controller )
1540   PORT_START("IN0")
1541   PORT_BIT( 0x00ff, IP_ACTIVE_LOW, IPT_UNUSED )
1542   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1) PORT_CATEGORY (1)
1543   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) PORT_CATEGORY (1)
1544   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) PORT_CATEGORY (1)
1545   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) PORT_CATEGORY (1)
1546   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_CATEGORY (1)
1547   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_CATEGORY (1)
1548   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_CATEGORY (1)
1549   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_CATEGORY (1)
1550
1551
1552   PORT_START("IN1")
1553   PORT_BIT( 0x00ff, IP_ACTIVE_LOW, IPT_UNUSED )
1554   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2) PORT_CATEGORY (2)
1555   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) PORT_CATEGORY (2)
1556   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) PORT_CATEGORY (2)
1557   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) PORT_CATEGORY (2)
1558   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_CATEGORY (2)
1559   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_CATEGORY (2)
1560   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_CATEGORY (2)
1561   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) PORT_CATEGORY (2)
1562INPUT_PORTS_END
1563
1564static INPUT_PORTS_START( mjpanel )
1565   PORT_START("MJ01_P1")
1566   PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED )
1567   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_MAHJONG_A ) PORT_PLAYER(1) PORT_CATEGORY (3)
1568   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_B ) PORT_PLAYER(1) PORT_CATEGORY (3)
1569   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_C ) PORT_PLAYER(1) PORT_CATEGORY (3)
1570   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_MAHJONG_D ) PORT_PLAYER(1) PORT_CATEGORY (3)
1571   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_E ) PORT_PLAYER(1) PORT_CATEGORY (3)
1572   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_MAHJONG_F ) PORT_PLAYER(1) PORT_CATEGORY (3)
1573   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_MAHJONG_G ) PORT_PLAYER(1) PORT_CATEGORY (3)
1574   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1575
1576   PORT_START("MJ02_P1")
1577   PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED )
1578   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_MAHJONG_H ) PORT_PLAYER(1) PORT_CATEGORY (3)
1579   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_I ) PORT_PLAYER(1) PORT_CATEGORY (3)
1580   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_J ) PORT_PLAYER(1) PORT_CATEGORY (3)
1581   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_MAHJONG_K ) PORT_PLAYER(1) PORT_CATEGORY (3)
1582   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_L ) PORT_PLAYER(1) PORT_CATEGORY (3)
1583   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_MAHJONG_M ) PORT_PLAYER(1) PORT_CATEGORY (3)
1584   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_MAHJONG_N ) PORT_PLAYER(1) PORT_CATEGORY (3)
1585   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(1) PORT_CATEGORY (3)
1586
1587   PORT_START("MJ03_P1")
1588   PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED )
1589   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1) PORT_CATEGORY (3)
1590   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) PORT_CATEGORY (3)
1591   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) PORT_CATEGORY (3)
1592   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) PORT_CATEGORY (3)
1593   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_CATEGORY (3)
1594   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_CATEGORY (3)
1595   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_CATEGORY (3)
1596   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_CATEGORY (3)
1597
1598   PORT_START("MJ04_P1")
1599   PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED )
1600   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_MAHJONG_PON ) PORT_PLAYER(1) PORT_CATEGORY (3)
1601   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_CHI ) PORT_PLAYER(1) PORT_CATEGORY (3)
1602   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_KAN ) PORT_PLAYER(1) PORT_CATEGORY (3)
1603   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_MAHJONG_RON ) PORT_PLAYER(1) PORT_CATEGORY (3)
1604   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_REACH ) PORT_PLAYER(1) PORT_CATEGORY (3)
1605   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1606   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1607   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1608
1609   PORT_START("MJ01_P2")
1610   PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED )
1611   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_MAHJONG_A ) PORT_PLAYER(2) PORT_CATEGORY (4)
1612   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_B ) PORT_PLAYER(2) PORT_CATEGORY (4)
1613   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_C ) PORT_PLAYER(2) PORT_CATEGORY (4)
1614   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_MAHJONG_D ) PORT_PLAYER(2) PORT_CATEGORY (4)
1615   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_E ) PORT_PLAYER(2) PORT_CATEGORY (4)
1616   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_MAHJONG_F ) PORT_PLAYER(2) PORT_CATEGORY (4)
1617   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_MAHJONG_G ) PORT_PLAYER(2) PORT_CATEGORY (4)
1618   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1619
1620   PORT_START("MJ02_P2")
1621   PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED )
1622   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_MAHJONG_H ) PORT_PLAYER(2) PORT_CATEGORY (4)
1623   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_I ) PORT_PLAYER(2) PORT_CATEGORY (4)
1624   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_J ) PORT_PLAYER(2) PORT_CATEGORY (4)
1625   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_MAHJONG_K ) PORT_PLAYER(2) PORT_CATEGORY (4)
1626   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_L ) PORT_PLAYER(2) PORT_CATEGORY (4)
1627   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_MAHJONG_M ) PORT_PLAYER(2) PORT_CATEGORY (4)
1628   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_MAHJONG_N ) PORT_PLAYER(2) PORT_CATEGORY (4)
1629   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1630
1631   PORT_START("MJ03_P2")
1632   PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED )
1633   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2) PORT_CATEGORY (4)
1634   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) PORT_CATEGORY (4)
1635   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) PORT_CATEGORY (4)
1636   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) PORT_CATEGORY (4)
1637   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_CATEGORY (4)
1638   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_CATEGORY (4)
1639   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_CATEGORY (4)
1640   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) PORT_CATEGORY (4)
1641
1642   PORT_START("MJ04_P2")
1643   PORT_BIT( 0x00ff, IP_ACTIVE_HIGH, IPT_UNUSED )
1644   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_MAHJONG_PON ) PORT_PLAYER(2) PORT_CATEGORY (4)
1645   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_CHI ) PORT_PLAYER(2) PORT_CATEGORY (4)
1646   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_KAN ) PORT_PLAYER(2) PORT_CATEGORY (4)
1647   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_MAHJONG_RON ) PORT_PLAYER(2) PORT_CATEGORY (4)
1648   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_REACH ) PORT_PLAYER(2) PORT_CATEGORY (4)
1649   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1650   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1651   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN )
1652
1653INPUT_PORTS_END
1654
1655static INPUT_PORTS_START( aes )
1656// was there anyting in place of dipswitch in the home console?
1657/*  PORT_START("IN0")
1658    PORT_BIT( 0x00ff, IP_ACTIVE_LOW, IPT_UNUSED )
1659//  PORT_DIPNAME( 0x0001, 0x0001, "Test Switch" ) PORT_DIPLOCATION("SW:1")
1660//  PORT_DIPSETTING(      0x0001, DEF_STR( Off ) )
1661//  PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
1662//  PORT_DIPNAME( 0x0002, 0x0002, "Coin Chutes?" ) PORT_DIPLOCATION("SW:2")
1663//  PORT_DIPSETTING(      0x0000, "1?" )
1664//  PORT_DIPSETTING(      0x0002, "2?" )
1665//  PORT_DIPNAME( 0x0004, 0x0000, "Mahjong Control Panel (or Auto Fire)" ) PORT_DIPLOCATION("SW:3")
1666//  PORT_DIPSETTING(      0x0004, DEF_STR( Off ) )
1667//  PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
1668//  PORT_DIPNAME( 0x0018, 0x0018, "COMM Setting (Cabinet No.)" ) PORT_DIPLOCATION("SW:4,5")
1669//  PORT_DIPSETTING(      0x0018, "1" )
1670//  PORT_DIPSETTING(      0x0008, "2" )
1671//  PORT_DIPSETTING(      0x0010, "3" )
1672//  PORT_DIPSETTING(      0x0000, "4" )
1673//  PORT_DIPNAME( 0x0020, 0x0020, "COMM Setting (Link Enable)" ) PORT_DIPLOCATION("SW:6")
1674//  PORT_DIPSETTING(      0x0020, DEF_STR( Off ) )
1675//  PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
1676//  PORT_DIPNAME( 0x0040, 0x0040, DEF_STR( Free_Play ) ) PORT_DIPLOCATION("SW:7")
1677//  PORT_DIPSETTING(      0x0040, DEF_STR( Off ) )
1678//  PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
1679//  PORT_DIPNAME( 0x0080, 0x0080, "Freeze" ) PORT_DIPLOCATION("SW:8")
1680//  PORT_DIPSETTING(      0x0080, DEF_STR( Off ) )
1681//  PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
1682    PORT_BIT( 0xff00, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(aes_controller_r, NULL) */
1683
1684   PORT_START("CTRLSEL")  /* Select Controller Type */
1685   PORT_CATEGORY_CLASS( 0x0f, 0x01, "P1 Controller")
1686   PORT_CATEGORY_ITEM(  0x00, "Unconnected",         0 )
1687   PORT_CATEGORY_ITEM(  0x01, "NeoGeo Controller",      1 )
1688   PORT_CATEGORY_ITEM(  0x02, "NeoGeo Mahjong Panel",   3 )
1689   PORT_CATEGORY_CLASS( 0xf0, 0x10, "P2 Controller")
1690   PORT_CATEGORY_ITEM(  0x00, "Unconnected",      0 )
1691   PORT_CATEGORY_ITEM(  0x10, "NeoGeo Controller",      2 )
1692   PORT_CATEGORY_ITEM(  0x20, "NeoGeo Mahjong Panel",   4 )
1693
1694   PORT_INCLUDE( controller )
1695
1696   PORT_INCLUDE( mjpanel )
1697
1698// were some of these present in the AES?!?
1699   STANDARD_IN2
1700
1701   STANDARD_IN3
1702
1703   STANDARD_IN4
1704INPUT_PORTS_END
1705
1706
1707
1708/*************************************
1709 *
1710 *  Machine driver
1711 *
1712 *************************************/
1713
1714static MACHINE_CONFIG_START( neogeo, ng_aes_state )
1715
1716   /* basic machine hardware */
1717   MCFG_CPU_ADD("maincpu", M68000, NEOGEO_MAIN_CPU_CLOCK)
1718   MCFG_CPU_PROGRAM_MAP(main_map)
1719
1720   MCFG_CPU_ADD("audiocpu", Z80, NEOGEO_AUDIO_CPU_CLOCK)
1721   MCFG_CPU_PROGRAM_MAP(audio_map)
1722   MCFG_CPU_IO_MAP(audio_io_map)
1723
1724   MCFG_MACHINE_START(neogeo)
1725   MCFG_MACHINE_RESET(neogeo)
1726
1727   /* video hardware */
1728   MCFG_VIDEO_START(neogeo)
1729   MCFG_VIDEO_RESET(neogeo)
1730   MCFG_DEFAULT_LAYOUT(layout_neogeo)
1731
1732   MCFG_SCREEN_ADD("screen", RASTER)
1733   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
1734   MCFG_SCREEN_RAW_PARAMS(NEOGEO_PIXEL_CLOCK, NEOGEO_HTOTAL, NEOGEO_HBEND, NEOGEO_HBSTART, NEOGEO_VTOTAL, NEOGEO_VBEND, NEOGEO_VBSTART)
1735   MCFG_SCREEN_UPDATE(neogeo)
1736
1737   /* audio hardware */
1738   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
1739
1740   MCFG_SOUND_ADD("ymsnd", YM2610, NEOGEO_YM2610_CLOCK)
1741   MCFG_SOUND_CONFIG(ym2610_config)
1742   MCFG_SOUND_ROUTE(0, "lspeaker",  0.60)
1743   MCFG_SOUND_ROUTE(0, "rspeaker", 0.60)
1744   MCFG_SOUND_ROUTE(1, "lspeaker",  1.0)
1745   MCFG_SOUND_ROUTE(2, "rspeaker", 1.0)
1746
1747   /* NEC uPD4990A RTC */
1748   MCFG_UPD4990A_ADD("upd4990a")
1749MACHINE_CONFIG_END
1750
1751static MACHINE_CONFIG_DERIVED( aes, neogeo )
1752
1753   MCFG_MEMCARD_HANDLER(neogeo)
1754
1755   MCFG_AES_CARTRIDGE_ADD("aes_multicart")
1756//  MCFG_CARTSLOT_ADD("cart")
1757//  MCFG_CARTSLOT_MANDATORY
1758
1759//  MCFG_CARTSLOT_LOAD(aes_cart)
1760
1761   MCFG_SOFTWARE_LIST_ADD("cart_list","aes")
1762MACHINE_CONFIG_END
1763
1764static MACHINE_CONFIG_DERIVED( neocd, neogeo )
1765
1766   MCFG_CPU_MODIFY("maincpu")
1767   MCFG_CPU_PROGRAM_MAP(neocd_main_map)
1768
1769   MCFG_MACHINE_START(neocd)
1770MACHINE_CONFIG_END
1771
1772/*************************************
1773 *
1774 *  Driver initalization
1775 *
1776 *************************************/
1777
1778static DRIVER_INIT( neogeo )
1779{
1780}
1781
1782
1783ROM_START( aes )
1784   ROM_REGION16_BE( 0x80000, "mainbios", 0 )
1785   ROM_SYSTEM_BIOS( 0, "jap-aes",   "Japan AES" )
1786   ROMX_LOAD("neo-po.bin",  0x00000, 0x020000, CRC(16d0c132) SHA1(4e4a440cae46f3889d20234aebd7f8d5f522e22c), ROM_GROUPWORD | ROM_REVERSE | ROM_BIOS(1))   /* AES Console (Japan) Bios */
1787   ROM_SYSTEM_BIOS( 1, "asia-aes",   "Asia AES" )
1788   ROMX_LOAD("neo-epo.bin", 0x00000, 0x020000, CRC(d27a71f1) SHA1(1b3b22092f30c4d1b2c15f04d1670eb1e9fbea07), ROM_GROUPWORD | ROM_REVERSE | ROM_BIOS(2))   /* AES Console (Asia?) Bios */
1789//  ROM_SYSTEM_BIOS( 2, "uni-bios_2_3","Universe Bios (Hack, Ver. 2.3)" )
1790//  ROMX_LOAD( "uni-bios_2_3.rom",  0x00000, 0x020000, CRC(27664eb5) SHA1(5b02900a3ccf3df168bdcfc98458136fd2b92ac0), ROM_GROUPWORD | ROM_REVERSE | ROM_BIOS(3) ) /* Universe Bios v2.3 (hack) */
1791
1792   ROM_REGION( 0x200000, "maincpu", ROMREGION_ERASEFF )
1793
1794   ROM_REGION( 0x20000, "audiobios", 0 )
1795   ROM_LOAD( "sm1.sm1", 0x00000, 0x20000, CRC(94416d67) SHA1(42f9d7ddd6c0931fd64226a60dc73602b2819dcf) )
1796
1797   ROM_REGION( 0x90000, "audiocpu", ROMREGION_ERASEFF )
1798
1799   ROM_REGION( 0x20000, "zoomy", 0 )
1800   ROM_LOAD( "000-lo.lo", 0x00000, 0x20000, CRC(5a86cff2) SHA1(5992277debadeb64d1c1c64b0a92d9293eaf7e4a) )
1801
1802   ROM_REGION( 0x20000, "fixedbios", 0 )
1803   ROM_LOAD( "sfix.sfix", 0x000000, 0x20000, CRC(c2ea0cfd) SHA1(fd4a618cdcdbf849374f0a50dd8efe9dbab706c3) )
1804
1805   ROM_REGION( 0x20000, "fixed", ROMREGION_ERASEFF )
1806
1807   ROM_REGION( 0x1000000, "ymsnd", ROMREGION_ERASEFF )
1808
1809   ROM_REGION( 0x1000000, "ymsnd.deltat", ROMREGION_ERASEFF )
1810
1811   ROM_REGION( 0x900000, "sprites", ROMREGION_ERASEFF )
1812ROM_END
1813
1814ROM_START( neocd )
1815   ROM_REGION16_BE( 0x100000, "mainbios", 0 )
1816   ROM_LOAD16_WORD_SWAP( "top-sp1.bin",    0x00000, 0x80000, CRC(19f0ad1a) SHA1(b3e2f8467e9a642c122428d075024a9bd1fe0679) )
1817
1818   ROM_REGION( 0x200000, "maincpu", ROMREGION_ERASEFF )
1819
1820   ROM_REGION( 0x100000, "audiobios", ROMREGION_ERASEFF )
1821
1822   ROM_REGION( 0x10000, "audiocpu", ROMREGION_ERASEFF )
1823
1824   ROM_REGION( 0x20000, "zoomy", 0 )
1825   ROM_LOAD( "000-lo.lo", 0x00000, 0x20000, CRC(5a86cff2) SHA1(5992277debadeb64d1c1c64b0a92d9293eaf7e4a) )
1826
1827   ROM_REGION( 0x20000, "fixedbios", ROMREGION_ERASEFF )
1828
1829   ROM_REGION( 0x20000, "fixed", ROMREGION_ERASEFF )
1830
1831   ROM_REGION( 0x400000, "ymsnd", ROMREGION_ERASEFF )
1832
1833//    NO_DELTAT_REGION
1834
1835   ROM_REGION( 0x400000, "sprites", ROMREGION_ERASEFF )
1836ROM_END
1837
1838ROM_START( neocdz )
1839   ROM_REGION16_BE( 0x100000, "mainbios", 0 )
1840   ROM_LOAD16_WORD_SWAP( "neocd.bin",    0x00000, 0x80000, CRC(df9de490) SHA1(7bb26d1e5d1e930515219cb18bcde5b7b23e2eda) )
1841
1842   ROM_REGION( 0x200000, "maincpu", ROMREGION_ERASEFF )
1843
1844   ROM_REGION( 0x20000, "audiobios", ROMREGION_ERASEFF )
1845
1846   ROM_REGION( 0x10000, "audiocpu", ROMREGION_ERASEFF )
1847
1848   ROM_REGION( 0x20000, "zoomy", 0 )
1849   ROM_LOAD( "000-lo.lo", 0x00000, 0x20000, CRC(5a86cff2) SHA1(5992277debadeb64d1c1c64b0a92d9293eaf7e4a) )
1850
1851   ROM_REGION( 0x20000, "fixedbios", ROMREGION_ERASEFF )
1852
1853   ROM_REGION( 0x20000, "fixed", ROMREGION_ERASEFF )
1854
1855   ROM_REGION( 0x400000, "ymsnd", ROMREGION_ERASEFF )
1856
1857//    NO_DELTAT_REGION
1858
1859   ROM_REGION( 0x400000, "sprites", ROMREGION_ERASEFF )
1860ROM_END
1861
1862/*    YEAR  NAME  PARENT COMPAT MACHINE INPUT  INIT     COMPANY      FULLNAME            FLAGS */
1863CONS( 1990, aes,    0,   0,   aes,      aes,   neogeo,  "SNK", "Neo-Geo AES", 0)
1864CONS( 1994, neocd,  aes, 0,   neocd,    aes,   neogeo,  "SNK", "Neo-Geo CD", GAME_NOT_WORKING )
1865CONS( 1996, neocdz, aes, 0,   neocd,    aes,   neogeo,  "SNK", "Neo-Geo CDZ", GAME_NOT_WORKING )
src/mess/drivers/psx.c
r11460r11461
1/***************************************************************************
2
3  Sony Playstaion
4  ===============
5  Preliminary driver by smf
6  Additional development by pSXAuthor and R. Belmont
7
8***************************************************************************/
9
10#include "emu.h"
11#include "cpu/psx/psx.h"
12#include "imagedev/snapquik.h"
13#include "imagedev/chd_cd.h"
14#include "includes/psx.h"
15#include "sound/spu.h"
16#include "debugger.h"
17#include "zlib.h"
18#include "machine/psxcd.h"
19#include "machine/psxcard.h"
20
21typedef struct
22{
23   UINT8 n_shiftin;
24   UINT8 n_shiftout;
25   int n_bits;
26   int n_state;
27   int n_byte;
28   int b_lastclock;
29   int b_ack;
30} pad_t;
31
32
33class psx1_state : public psx_state
34{
35public:
36   psx1_state(const machine_config &mconfig, device_type type, const char *tag)
37      : psx_state(mconfig, type, tag) { }
38
39   UINT8 *m_exe_buffer;
40   int m_exe_size;
41   pad_t m_pad[ 2 ];
42   int m_cd_param_p;
43   int m_cd_result_p;
44   int m_cd_result_c;
45   int m_cd_result_ready;
46   int m_cd_reset;
47   UINT8 m_cd_stat;
48   UINT8 m_cd_io_status;
49   UINT8 m_cd_param[8];
50   UINT8 m_cd_result[8];
51};
52
53
54#define VERBOSE_LEVEL ( 0 )
55
56INLINE void ATTR_PRINTF(3,4) verboselog( running_machine &machine, int n_level, const char *s_fmt, ... )
57{
58   if( VERBOSE_LEVEL >= n_level )
59   {
60      va_list v;
61      char buf[ 32768 ];
62      va_start( v, s_fmt );
63      vsprintf( buf, s_fmt, v );
64      va_end( v );
65      logerror( "%s: %s", machine.describe_context(), buf );
66   }
67}
68
69
70static void psxexe_conv32( UINT32 *p_uint32 )
71{
72   UINT8 *p_uint8;
73
74   p_uint8 = (UINT8 *)p_uint32;
75
76   *( p_uint32 ) = p_uint8[ 0 ] |
77      ( p_uint8[ 1 ] << 8 ) |
78      ( p_uint8[ 2 ] << 16 ) |
79      ( p_uint8[ 3 ] << 24 );
80}
81
82static int load_psxexe( device_t *cpu, unsigned char *p_n_file, int n_len )
83{
84   psx_state *state = cpu->machine().driver_data<psx_state>();
85   struct PSXEXE_HEADER
86   {
87      UINT8 id[ 8 ];
88      UINT32 text;   /* SCE only */
89      UINT32 data;   /* SCE only */
90      UINT32 pc0;
91      UINT32 gp0;      /* SCE only */
92      UINT32 t_addr;
93      UINT32 t_size;
94      UINT32 d_addr;   /* SCE only */
95      UINT32 d_size;   /* SCE only */
96      UINT32 b_addr;   /* SCE only */
97      UINT32 b_size;   /* SCE only */
98      UINT32 s_addr;
99      UINT32 s_size;
100      UINT32 SavedSP;
101      UINT32 SavedFP;
102      UINT32 SavedGP;
103      UINT32 SavedRA;
104      UINT32 SavedS0;
105      UINT8 dummy[ 0x800 - 76 ];
106   };
107
108   struct PSXEXE_HEADER *psxexe_header = (struct PSXEXE_HEADER *)p_n_file;
109
110   if( n_len >= sizeof( struct PSXEXE_HEADER ) &&
111      memcmp( psxexe_header->id, "PS-X EXE", 8 ) == 0 )
112   {
113      UINT8 *p_ram;
114      UINT8 *p_psxexe;
115      UINT32 n_stack;
116      UINT32 n_ram;
117      UINT32 n_address;
118      UINT32 n_size;
119
120      psxexe_conv32( &psxexe_header->text );
121      psxexe_conv32( &psxexe_header->data );
122      psxexe_conv32( &psxexe_header->pc0 );
123      psxexe_conv32( &psxexe_header->gp0 );
124      psxexe_conv32( &psxexe_header->t_addr );
125      psxexe_conv32( &psxexe_header->t_size );
126      psxexe_conv32( &psxexe_header->d_addr );
127      psxexe_conv32( &psxexe_header->d_size );
128      psxexe_conv32( &psxexe_header->b_addr );
129      psxexe_conv32( &psxexe_header->b_size );
130      psxexe_conv32( &psxexe_header->s_addr );
131      psxexe_conv32( &psxexe_header->s_size );
132      psxexe_conv32( &psxexe_header->SavedSP );
133      psxexe_conv32( &psxexe_header->SavedFP );
134      psxexe_conv32( &psxexe_header->SavedGP );
135      psxexe_conv32( &psxexe_header->SavedRA );
136      psxexe_conv32( &psxexe_header->SavedS0 );
137
138      /* todo: check size.. */
139
140      logerror( "psx_exe_load: pc    %08x\n", psxexe_header->pc0 );
141      logerror( "psx_exe_load: org   %08x\n", psxexe_header->t_addr );
142      logerror( "psx_exe_load: len   %08x\n", psxexe_header->t_size );
143      logerror( "psx_exe_load: sp    %08x\n", psxexe_header->s_addr );
144      logerror( "psx_exe_load: len   %08x\n", psxexe_header->s_size );
145
146      p_ram = (UINT8 *)state->m_p_n_psxram;
147      n_ram = state->m_n_psxramsize;
148
149      p_psxexe = p_n_file + sizeof( struct PSXEXE_HEADER );
150
151      n_address = psxexe_header->t_addr;
152      n_size = psxexe_header->t_size;
153      while( n_size != 0 )
154      {
155         p_ram[ BYTE4_XOR_LE( n_address ) % n_ram ] = *( p_psxexe );
156         n_address++;
157         p_psxexe++;
158         n_size--;
159      }
160
161      cpu_set_reg( cpu, PSXCPU_PC, psxexe_header->pc0 );
162      cpu_set_reg( cpu, PSXCPU_R28, psxexe_header->gp0 );
163      n_stack = psxexe_header->s_addr + psxexe_header->s_size;
164      if( n_stack != 0 )
165      {
166         cpu_set_reg( cpu, PSXCPU_R29, n_stack );
167         cpu_set_reg( cpu, PSXCPU_R30, n_stack );
168      }
169
170      return 1;
171   }
172   return 0;
173}
174
175static void cpe_set_register( device_t *cpu, int n_reg, int n_value )
176{
177   if( n_reg < 0x80 && ( n_reg % 4 ) == 0 )
178   {
179      logerror( "psx_exe_load: r%-2d   %08x\n", n_reg / 4, n_value );
180      cpu_set_reg( cpu, PSXCPU_R0 + ( n_reg / 4 ), n_value );
181   }
182   else if( n_reg == 0x80 )
183   {
184      logerror( "psx_exe_load: lo    %08x\n", n_value );
185      cpu_set_reg( cpu, PSXCPU_LO, n_value );
186   }
187   else if( n_reg == 0x84 )
188   {
189      logerror( "psx_exe_load: hi    %08x\n", n_value );
190      cpu_set_reg( cpu, PSXCPU_HI, n_value );
191   }
192   else if( n_reg == 0x88 )
193   {
194      logerror( "psx_exe_load: sr    %08x\n", n_value );
195      cpu_set_reg( cpu, PSXCPU_CP0R12, n_value );
196   }
197   else if( n_reg == 0x8c )
198   {
199      logerror( "psx_exe_load: cause %08x\n", n_value );
200      cpu_set_reg( cpu, PSXCPU_CP0R13, n_value );
201   }
202   else if( n_reg == 0x90 )
203   {
204      logerror( "psx_exe_load: pc    %08x\n", n_value );
205      cpu_set_reg( cpu, PSXCPU_PC, n_value );
206   }
207   else if( n_reg == 0x94 )
208   {
209      logerror( "psx_exe_load: prid  %08x\n", n_value );
210      cpu_set_reg( cpu, PSXCPU_CP0R15, n_value );
211   }
212   else
213   {
214      logerror( "psx_exe_load: invalid register %04x/%08x\n", n_reg, n_value );
215   }
216}
217
218static int load_cpe( device_t *cpu, unsigned char *p_n_file, int n_len )
219{
220   psx_state *state = cpu->machine().driver_data<psx_state>();
221   if( n_len >= 4 &&
222      memcmp( p_n_file, "CPE\001", 4 ) == 0 )
223   {
224      int n_offset = 4;
225
226      for( ;; )
227      {
228         if( n_offset >= n_len || p_n_file[ n_offset ] > 8 )
229         {
230            break;
231         }
232
233         switch( p_n_file[ n_offset++ ] )
234         {
235         case 0:
236            /* end of file */
237            return 1;
238         case 1:
239            /* read bytes */
240            {
241               int n_address = ( (int)p_n_file[ n_offset + 0 ] << 0 ) |
242                  ( (int)p_n_file[ n_offset + 1 ] << 8 ) |
243                  ( (int)p_n_file[ n_offset + 2 ] << 16 ) |
244                  ( (int)p_n_file[ n_offset + 3 ] << 24 );
245               int n_size = ( (int)p_n_file[ n_offset + 4 ] << 0 ) |
246                  ( (int)p_n_file[ n_offset + 5 ] << 8 ) |
247                  ( (int)p_n_file[ n_offset + 6 ] << 16 ) |
248                  ( (int)p_n_file[ n_offset + 7 ] << 24 );
249
250               UINT8 *p_ram = (UINT8 *)state->m_p_n_psxram;
251               UINT32 n_ram = state->m_n_psxramsize;
252
253               n_offset += 8;
254
255               logerror( "psx_exe_load: org   %08x\n", n_address );
256               logerror( "psx_exe_load: len   %08x\n", n_size );
257
258               while( n_size > 0 )
259               {
260                  p_ram[ BYTE4_XOR_LE( n_address ) % n_ram ] = p_n_file[ n_offset++ ];
261                  n_address++;
262                  n_size--;
263               }
264               break;
265            }
266         case 2:
267            /* run address: not tested */
268            {
269               int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ) |
270                  ( (int)p_n_file[ n_offset + 3 ] << 8 ) |
271                  ( (int)p_n_file[ n_offset + 4 ] << 16 ) |
272                  ( (int)p_n_file[ n_offset + 5 ] << 24 );
273
274               n_offset += 4;
275
276               cpe_set_register( cpu, 0x90, n_value );
277               break;
278            }
279         case 3:
280            /* set reg to longword */
281            {
282               int n_reg = ( (int)p_n_file[ n_offset + 0 ] << 0 ) |
283                  ( (int)p_n_file[ n_offset + 1 ] << 8 );
284               int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ) |
285                  ( (int)p_n_file[ n_offset + 3 ] << 8 ) |
286                  ( (int)p_n_file[ n_offset + 4 ] << 16 ) |
287                  ( (int)p_n_file[ n_offset + 5 ] << 24 );
288
289               n_offset += 6;
290
291               cpe_set_register( cpu, n_reg, n_value );
292               break;
293            }
294         case 4:
295            /* set reg to word: not tested */
296            {
297               int n_reg = ( (int)p_n_file[ n_offset + 0 ] << 0 ) |
298                  ( (int)p_n_file[ n_offset + 1 ] << 8 );
299               int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ) |
300                  ( (int)p_n_file[ n_offset + 3 ] << 8 );
301
302               n_offset += 4;
303
304               cpe_set_register( cpu, n_reg, n_value );
305               break;
306            }
307         case 5:
308            /* set reg to byte: not tested */
309            {
310               int n_reg = ( (int)p_n_file[ n_offset + 0 ] << 0 ) |
311                  ( (int)p_n_file[ n_offset + 1 ] << 8 );
312               int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 );
313
314               n_offset += 3;
315
316               cpe_set_register( cpu, n_reg, n_value );
317               break;
318            }
319         case 6:
320            /* set reg to 3-byte: not tested */
321            {
322               int n_reg = ( (int)p_n_file[ n_offset + 0 ] << 0 ) |
323                  ( (int)p_n_file[ n_offset + 1 ] << 8 );
324               int n_value = ( (int)p_n_file[ n_offset + 2 ] << 0 ) |
325                  ( (int)p_n_file[ n_offset + 3 ] << 8 ) |
326                  ( (int)p_n_file[ n_offset + 4 ] << 16 );
327
328               n_offset += 5;
329
330               cpe_set_register( cpu, n_reg, n_value );
331               break;
332            }
333         case 7:
334            /* workspace: not tested */
335            n_offset += 4;
336            break;
337         case 8:
338            /* unit */
339            {
340               int n_unit = p_n_file[ n_offset + 0 ];
341
342               n_offset++;
343
344               logerror( "psx_exe_load: unit  %08x\n", n_unit );
345            }
346            break;
347         }
348      }
349   }
350   return 0;
351}
352
353static int load_psf( device_t *cpu, unsigned char *p_n_file, int n_len )
354{
355   int n_return;
356   unsigned long n_crc;
357   unsigned long n_compressed;
358   unsigned char *p_n_compressed;
359   unsigned long n_uncompressed;
360   unsigned char *p_n_uncompressed;
361
362   struct PSF_HEADER
363   {
364      unsigned char id[ 4 ];
365      UINT32 reserved_size;
366      UINT32 exe_size;
367      UINT32 exe_crc;
368   };
369
370   struct PSF_HEADER *psf_header = (struct PSF_HEADER *)p_n_file;
371
372   n_return = 0;
373
374   if( n_len >= sizeof( struct PSF_HEADER ) &&
375      memcmp( p_n_file, "PSF", 3 ) == 0 )
376   {
377      psxexe_conv32( &psf_header->reserved_size );
378      psxexe_conv32( &psf_header->exe_size );
379      psxexe_conv32( &psf_header->exe_crc );
380
381      logerror( "psx_exe_load: reserved_size %08x\n", psf_header->reserved_size );
382      logerror( "psx_exe_load: exe_size      %08x\n", psf_header->exe_size );
383      logerror( "psx_exe_load: exe_crc       %08x\n", psf_header->exe_crc );
384
385      n_compressed = psf_header->exe_size;
386      p_n_compressed = p_n_file + sizeof( struct PSF_HEADER ) + psf_header->reserved_size;
387
388      n_crc = crc32( crc32( 0L, Z_NULL, 0 ), p_n_compressed, n_compressed );
389      if( n_crc != psf_header->exe_crc )
390      {
391         logerror( "psx_exe_load: psf invalid crc\n" );
392         return 0;
393      }
394
395      n_uncompressed = 0x200000;
396      p_n_uncompressed = (unsigned char *)malloc( n_uncompressed );
397
398      if( uncompress( p_n_uncompressed, &n_uncompressed, p_n_compressed, n_compressed ) != Z_OK )
399      {
400         logerror( "psx_exe_load: psf uncompress failed\n" );
401      }
402      else if( !load_psxexe( cpu, p_n_uncompressed, n_uncompressed ) )
403      {
404         logerror( "psx_exe_load: psf load failed\n" );
405      }
406      else
407      {
408         n_return = 1;
409      }
410
411      free( p_n_uncompressed );
412   }
413   return n_return;
414}
415
416DIRECT_UPDATE_HANDLER( psx_default )
417{
418   return address;
419}
420
421DIRECT_UPDATE_HANDLER( psx_setopbase )
422{
423   psx1_state *state = machine.driver_data<psx1_state>();
424   if( address == 0x80030000 )
425   {
426      device_t *cpu = machine.device("maincpu");
427
428      machine.device("maincpu")->memory().space(AS_PROGRAM)->set_direct_update_handler(direct_update_delegate(FUNC(psx_default), &machine));
429
430      if( load_psxexe( cpu, state->m_exe_buffer, state->m_exe_size ) ||
431         load_cpe( cpu, state->m_exe_buffer, state->m_exe_size ) ||
432         load_psf( cpu, state->m_exe_buffer, state->m_exe_size ) )
433      {
434/*          DEBUGGER_BREAK; */
435
436         address = cpu_get_reg( cpu, PSXCPU_PC );
437      }
438      else
439      {
440         logerror( "psx_exe_load: invalid exe\n" );
441      }
442
443      state->m_exe_size = 0;
444      free( state->m_exe_buffer );
445   }
446   return address;
447}
448
449static QUICKLOAD_LOAD( psx_exe_load )
450{
451   psx1_state *state = image.device().machine().driver_data<psx1_state>();
452   address_space *space = image.device().machine().device( "maincpu")->memory().space( AS_PROGRAM );
453
454   state->m_exe_size = 0;
455   state->m_exe_buffer = (UINT8*)malloc( quickload_size );
456   if( state->m_exe_buffer == NULL )
457   {
458      logerror( "psx_exe_load: out of memory\n" );
459      return IMAGE_INIT_FAIL;
460   }
461   if( image.fread( state->m_exe_buffer, quickload_size ) != quickload_size )
462   {
463      free( state->m_exe_buffer );
464      return IMAGE_INIT_FAIL;
465   }
466   state->m_exe_size = quickload_size;
467   space->set_direct_update_handler(direct_update_delegate(FUNC(psx_setopbase), &image.device().machine()));
468
469   return IMAGE_INIT_PASS;
470}
471
472/* PAD emulation */
473
474#define PAD_STATE_IDLE ( 0 )
475#define PAD_STATE_LISTEN ( 1 )
476#define PAD_STATE_ACTIVE ( 2 )
477#define PAD_STATE_READ ( 3 )
478#define PAD_STATE_UNLISTEN ( 4 )
479#define PAD_STATE_MEMCARD ( 5 )
480
481#define PAD_TYPE_STANDARD ( 4 )
482#define PAD_BYTES_STANDARD ( 2 )
483
484#define PAD_CMD_START ( 0x01 )
485#define PAD_CMD_READ  ( 0x42 ) /* B */
486
487#define PAD_DATA_OK   ( 0x5a ) /* Z */
488#define PAD_DATA_IDLE ( 0xff )
489
490static TIMER_CALLBACK(psx_pad_ack)
491{
492   psx1_state *state = machine.driver_data<psx1_state>();
493   int n_port = param;
494   pad_t *pad = &state->m_pad[ n_port ];
495
496   if( pad->n_state != PAD_STATE_IDLE )
497   {
498      psx_sio_input( machine, 0, PSX_SIO_IN_DSR, pad->b_ack * PSX_SIO_IN_DSR );
499      if( !pad->b_ack )
500      {
501         pad->b_ack = 1;
502         machine.scheduler().timer_set(attotime::from_usec( 2 ), FUNC(psx_pad_ack) , n_port);
503      }
504   }
505}
506
507static void psx_pad( running_machine &machine, int n_port, int n_data )
508{
509   psx1_state *state = machine.driver_data<psx1_state>();
510   pad_t *pad = &state->m_pad[ n_port ];
511   int b_sel;
512   int b_clock;
513   int b_data;
514   int b_ack;
515   int b_ready;
516   static const char *const portnames[] = { "IN0", "IN1", "IN2", "IN3" };
517   psxcard_device *psxcard = NULL;
518
519   if (n_port == 0)
520   {
521      psxcard = machine.device<psxcard_device>("card1");
522   }
523   else
524   {
525      psxcard = machine.device<psxcard_device>("card2");
526   }
527
528   b_sel = ( n_data & PSX_SIO_OUT_DTR ) / PSX_SIO_OUT_DTR;
529   b_clock = ( n_data & PSX_SIO_OUT_CLOCK ) / PSX_SIO_OUT_CLOCK;
530   b_data = ( n_data & PSX_SIO_OUT_DATA ) / PSX_SIO_OUT_DATA;
531   b_ready = 0;
532   b_ack = 0;
533
534   if( b_sel )
535   {
536      pad->n_state = PAD_STATE_IDLE;
537   }
538
539   switch( pad->n_state )
540   {
541   case PAD_STATE_LISTEN:
542   case PAD_STATE_ACTIVE:
543   case PAD_STATE_READ:
544   case PAD_STATE_MEMCARD:
545      if( pad->b_lastclock && !b_clock )
546      {
547         psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( pad->n_shiftout & 1 ) * PSX_SIO_IN_DATA );
548         pad->n_shiftout >>= 1;
549      }
550      if( !pad->b_lastclock && b_clock )
551      {
552         pad->n_shiftin >>= 1;
553         pad->n_shiftin |= b_data << 7;
554         pad->n_bits++;
555
556         if( pad->n_bits == 8 )
557         {
558            pad->n_bits = 0;
559            b_ready = 1;
560         }
561      }
562      break;
563   }
564
565   pad->b_lastclock = b_clock;
566
567   switch( pad->n_state )
568   {
569   case PAD_STATE_IDLE:
570      if( !b_sel )
571      {
572         pad->n_state = PAD_STATE_LISTEN;
573         pad->n_shiftout = PAD_DATA_IDLE;
574         pad->n_bits = 0;
575      }
576      break;
577   case PAD_STATE_LISTEN:
578      if( b_ready )
579      {
580         if( pad->n_shiftin == PAD_CMD_START )
581         {
582            pad->n_state = PAD_STATE_ACTIVE;
583            pad->n_shiftout = ( PAD_TYPE_STANDARD << 4 ) | ( PAD_BYTES_STANDARD >> 1 );
584            b_ack = 1;
585         }
586         else if( psxcard->transfer(pad->n_shiftin, &pad->n_shiftout) )
587         {
588            pad->n_state = PAD_STATE_MEMCARD;
589            b_ack = 1;
590         }
591         else
592         {
593            pad->n_state = PAD_STATE_UNLISTEN;
594         }
595      }
596      break;
597   case PAD_STATE_MEMCARD:
598      if( b_ready )
599      {
600         if( psxcard->transfer(pad->n_shiftin, &pad->n_shiftout) )
601         {
602            b_ack = 1;
603         }
604         else
605         {
606            b_ack = 0;
607            pad->n_state = PAD_STATE_IDLE;
608         }
609      }
610      break;
611   case PAD_STATE_ACTIVE:
612      if( b_ready )
613      {
614         if( pad->n_shiftin == PAD_CMD_READ )
615         {
616            pad->n_state = PAD_STATE_READ;
617            pad->n_shiftout = PAD_DATA_OK;
618            pad->n_byte = 0;
619            b_ack = 1;
620         }
621         else
622         {
623            pad->n_state = PAD_STATE_UNLISTEN;
624         }
625      }
626      break;
627   case PAD_STATE_READ:
628      if( b_ready )
629      {
630         if( pad->n_byte < PAD_BYTES_STANDARD )
631         {
632            pad->n_shiftout = input_port_read(machine, portnames[pad->n_byte + ( n_port * PAD_BYTES_STANDARD )]);
633            pad->n_byte++;
634            b_ack = 1;
635         }
636         else
637         {
638            pad->n_state = PAD_STATE_LISTEN;
639         }
640      }
641      break;
642   }
643
644   if( b_ack )
645   {
646      pad->b_ack = 0;
647      machine.scheduler().timer_set(attotime::from_usec( 10 ), FUNC(psx_pad_ack), n_port);
648   }
649}
650
651static void psx_sio0( running_machine &machine, int n_data )
652{
653   /* todo: raise data & ack when nothing is driving it low */
654   psx_pad( machine, 0, n_data );
655   psx_pad( machine, 1, n_data ^ PSX_SIO_OUT_DTR );
656}
657
658/* ----------------------------------------------------------------------- */
659
660static void cd_dma_read( running_machine &machine, UINT32 n_address, INT32 n_size )
661{
662   psxcd_device *psxcd = machine.device<psxcd_device>("psxcd");
663   UINT8 *psxram = (UINT8 *)memory_get_shared(machine, "share1");
664
665   psxcd->start_dma(psxram + n_address, n_size*4);
666}
667
668static void cd_dma_write( running_machine &machine, UINT32 n_address, INT32 n_size )
669{
670   printf("cd_dma_write?!: addr %x, size %x\n", n_address, n_size);
671}
672
673static READ8_HANDLER( psx_cd_r )
674{
675   psxcd_device *psxcd = space->machine().device<psxcd_device>(PSXCD_TAG);
676
677   return psxcd->read_byte(offset);
678}
679
680static WRITE8_HANDLER( psx_cd_w )
681{
682   psxcd_device *psxcd = space->machine().device<psxcd_device>(PSXCD_TAG);
683
684   psxcd->write_byte(offset, data);
685}
686
687static ADDRESS_MAP_START( psx_map, AS_PROGRAM, 32 )
688   AM_RANGE(0x00000000, 0x001fffff) AM_RAM   AM_SHARE("share1") /* ram */
689   AM_RANGE(0x1f801800, 0x1f801803) AM_READWRITE8(psx_cd_r, psx_cd_w, 0xffffffff)
690   AM_RANGE(0x1fc00000, 0x1fc7ffff) AM_ROM AM_SHARE("share2") AM_REGION("user1", 0) /* bios */
691   AM_RANGE(0x80000000, 0x801fffff) AM_RAM AM_SHARE("share1") /* ram mirror */
692   AM_RANGE(0x80600000, 0x807fffff) AM_RAM AM_SHARE("share1") /* ram mirror */
693   AM_RANGE(0x9fc00000, 0x9fc7ffff) AM_ROM AM_SHARE("share2") /* bios mirror */
694   AM_RANGE(0xa0000000, 0xa01fffff) AM_RAM AM_SHARE("share1") /* ram mirror */
695   AM_RANGE(0xbfc00000, 0xbfc7ffff) AM_ROM AM_SHARE("share2") /* bios mirror */
696   AM_RANGE(0xfffe0130, 0xfffe0133) AM_WRITENOP
697ADDRESS_MAP_END
698
699
700static MACHINE_RESET( psx )
701{
702   psx_machine_init(machine);
703   psx_sio_install_handler( machine, 0, psx_sio0 );
704
705   psx_dma_install_read_handler(machine, 3, cd_dma_read);
706   psx_dma_install_write_handler(machine, 3, cd_dma_write);
707}
708
709static DRIVER_INIT( psx )
710{
711   psx_driver_init(machine);
712}
713
714static INPUT_PORTS_START( psx )
715   PORT_START("IN0")
716   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT )  PORT_PLAYER(1)
717   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN )  PORT_PLAYER(1)
718   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
719   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP )   PORT_PLAYER(1)
720   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START )  PORT_PLAYER(1)
721   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(1)
722   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(1)
723   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SELECT ) PORT_PLAYER(1)
724
725   PORT_START("IN1")
726   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("P1 Square")
727   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("P1 Cross")
728   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_NAME("P1 Circle")
729   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_NAME("P1 Triangle")
730   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(1) PORT_NAME("P1 R1")
731   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(1) PORT_NAME("P1 L1")
732   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_PLAYER(1) PORT_NAME("P1 R2")
733   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_PLAYER(1) PORT_NAME("P1 L2")
734
735   PORT_START("IN2")
736   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT )  PORT_PLAYER(2)
737   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN )  PORT_PLAYER(2)
738   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
739   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP )   PORT_PLAYER(2)
740   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START )  PORT_PLAYER(2)
741   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(2)
742   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(2)
743   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SELECT ) PORT_PLAYER(2)
744
745   PORT_START("IN3")
746   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_NAME("P2 Square")
747   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_NAME("P2 Cross")
748   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_NAME("P2 Circle")
749   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) PORT_NAME("P2 Triangle")
750   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(2) PORT_NAME("P2 R1")
751   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(2) PORT_NAME("P2 L1")
752   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_PLAYER(2) PORT_NAME("P2 R2")
753   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_PLAYER(2) PORT_NAME("P2 L2")
754INPUT_PORTS_END
755
756static void spu_irq(device_t *device, UINT32 data)
757{
758   if (data)
759   {
760      psx_irq_set(device->machine(), 1<<9);
761   }
762}
763
764static MACHINE_CONFIG_START( psxntsc, psx1_state )
765   /* basic machine hardware */
766   MCFG_CPU_ADD( "maincpu", CXD8530AQ, XTAL_67_7376MHz )
767   MCFG_CPU_PROGRAM_MAP( psx_map)
768   MCFG_CPU_VBLANK_INT("screen", psx_vblank)
769
770   MCFG_SCREEN_ADD("screen", RASTER)
771   MCFG_SCREEN_REFRESH_RATE( 60 )
772   MCFG_SCREEN_VBLANK_TIME(0)
773
774   MCFG_MACHINE_RESET( psx )
775
776   /* video hardware */
777   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
778   MCFG_SCREEN_SIZE( 1024, 512 )
779   MCFG_SCREEN_VISIBLE_AREA( 0, 639, 0, 479 )
780   MCFG_SCREEN_UPDATE( psx )
781
782   MCFG_PALETTE_LENGTH( 65536 )
783
784   MCFG_PALETTE_INIT( psx )
785   MCFG_VIDEO_START( psx_type2 )
786
787   /* sound hardware */
788   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
789   MCFG_SPU_ADD( "spu", XTAL_67_7376MHz/2, &spu_irq )
790   MCFG_SOUND_ROUTE( 0, "lspeaker", 1.00 )
791   MCFG_SOUND_ROUTE( 1, "rspeaker", 1.00 )
792
793   /* quickload */
794   MCFG_QUICKLOAD_ADD("quickload", psx_exe_load, "cpe,exe,psf,psx", 0)
795
796   MCFG_CDROM_ADD("cdrom")
797   MCFG_PSXCD_ADD("cdrom")
798   MCFG_PSXCARD_ADD("card1")
799   MCFG_PSXCARD_ADD("card2")
800MACHINE_CONFIG_END
801
802static MACHINE_CONFIG_START( psxpal, psx1_state )
803   /* basic machine hardware */
804   MCFG_CPU_ADD( "maincpu", CXD8530AQ, XTAL_67_7376MHz )
805   MCFG_CPU_PROGRAM_MAP( psx_map)
806   MCFG_CPU_VBLANK_INT("screen", psx_vblank)
807
808   MCFG_SCREEN_ADD("screen", RASTER)
809   MCFG_SCREEN_REFRESH_RATE( 50 )
810   MCFG_SCREEN_VBLANK_TIME(0)
811
812   MCFG_MACHINE_RESET( psx )
813
814   /* video hardware */
815   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
816   MCFG_SCREEN_SIZE( 1024, 512 )
817   MCFG_SCREEN_VISIBLE_AREA( 0, 639, 0, 511 )
818   MCFG_SCREEN_UPDATE( psx )
819   MCFG_PALETTE_LENGTH( 65536 )
820
821   MCFG_PALETTE_INIT( psx )
822   MCFG_VIDEO_START( psx_type2 )
823
824   /* sound hardware */
825   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
826   MCFG_SPU_ADD( "spu", XTAL_67_7376MHz/2, &spu_irq )
827   MCFG_SOUND_ROUTE( 0, "lspeaker", 1.00 )
828   MCFG_SOUND_ROUTE( 1, "rspeaker", 1.00 )
829
830   /* quickload */
831   MCFG_QUICKLOAD_ADD("quickload", psx_exe_load, "cpe,exe,psf,psx", 0)
832
833   MCFG_CDROM_ADD("cdrom")
834   MCFG_PSXCD_ADD("cdrom")
835   MCFG_PSXCARD_ADD("card1")
836   MCFG_PSXCARD_ADD("card2")
837MACHINE_CONFIG_END
838
839ROM_START( psj )
840   ROM_REGION32_LE( 0x080000, "user1", 0 )
841
842   ROM_SYSTEM_BIOS( 0, "1.0J", "SCPH-1000/DTL-H1000" ) // 22091994
843   ROMX_LOAD( "ps-10j.bin",    0x0000000, 0x080000, CRC(3b601fc8) SHA1(343883a7b555646da8cee54aadd2795b6e7dd070), ROM_BIOS(1) )
844
845   ROM_SYSTEM_BIOS( 1, "1.1J", "SCPH-3000/DTL-H1000H (Version 1.1 01/22/95)" ) // 22091994
846   ROMX_LOAD( "ps-11j.bin",    0x0000000, 0x080000, CRC(3539def6) SHA1(b06f4a861f74270be819aa2a07db8d0563a7cc4e), ROM_BIOS(2) )
847
848   ROM_SYSTEM_BIOS( 2, "2.1J", "SCPH-3500 (Version 2.1 07/17/95 J)" ) // 22091994
849   ROMX_LOAD( "ps-21j.bin",    0x0000000, 0x080000, CRC(bc190209) SHA1(e38466a4ba8005fba7e9e3c7b9efeba7205bee3f), ROM_BIOS(3) )
850
851   ROM_SYSTEM_BIOS( 3, "2.2J", "SCPH-5000/DTL-H1200 (Version 2.2 12/04/95 J)" ) // 04121995
852/*  ROMX_LOAD( "ps-22j.bad",    0x0000000, 0x080000, BAD_DUMP CRC(8c93a399) SHA1(e340db2696274dda5fdc25e434a914db71e8b02b), ROM_BIOS(4) ) */
853   ROMX_LOAD( "ps-22j.bin",    0x0000000, 0x080000, CRC(24fc7e17) SHA1(ffa7f9a7fb19d773a0c3985a541c8e5623d2c30d), ROM_BIOS(4) )
854
855   ROM_SYSTEM_BIOS( 4, "2.2D", "DTL-H1100 (Version 2.2 03/06/96 D)" ) // 04121995
856   ROMX_LOAD( "ps-22d.bin",    0x0000000, 0x080000, CRC(decb22f5) SHA1(73107d468fc7cb1d2c5b18b269715dd889ecef06), ROM_BIOS(5) )
857
858   ROM_SYSTEM_BIOS( 5, "3.0J", "SCPH-5500 (Version 3.0 09/09/96 J)" ) // 04121995
859   ROMX_LOAD( "ps-30j.bin",    0x0000000, 0x080000, CRC(ff3eeb8c) SHA1(b05def971d8ec59f346f2d9ac21fb742e3eb6917), ROM_BIOS(6) )
860
861   ROM_SYSTEM_BIOS( 6, "4.0J", "SCPH-7000/SCPH-9000 (Version 4.0 08/18/97 J)" ) // 29051997
862   ROMX_LOAD( "ps-40j.bin",    0x0000000, 0x080000, CRC(ec541cd0) SHA1(77b10118d21ac7ffa9b35f9c4fd814da240eb3e9), ROM_BIOS(7) )
863
864   ROM_SYSTEM_BIOS( 7, "4.3J", "SCPH-100 (Version 4.3 03/11/00 J)" ) // 04121995
865   ROMX_LOAD( "psone-43j.bin", 0x0000000, 0x080000, CRC(f2af798b) SHA1(339a48f4fcf63e10b5b867b8c93cfd40945faf6c), ROM_BIOS(8) )
866ROM_END
867
868ROM_START( psu )
869   ROM_REGION32_LE( 0x080000, "user1", 0 )
870
871   ROM_SYSTEM_BIOS( 0, "2.0A", "DTL-H1001 (Version 2.0 05/07/95 A)" ) // 22091994
872   ROMX_LOAD( "ps-20a.bin",    0x0000000, 0x080000, CRC(55847d8c) SHA1(649895efd79d14790eabb362e94eb0622093dfb9), ROM_BIOS(1) )
873
874   ROM_SYSTEM_BIOS( 1, "2.1A", "DTL-H1101 (Version 2.1 07/17/95 A)" ) // 22091994
875   ROMX_LOAD( "ps-21a.bin",    0x0000000, 0x080000, CRC(aff00f2f) SHA1(ca7af30b50d9756cbd764640126c454cff658479), ROM_BIOS(2) )
876
877   ROM_SYSTEM_BIOS( 2, "2.2A", "SCPH-1001/DTL-H1201/DTL-H3001 (Version 2.2 12/04/95 A)" ) // 04121995
878   ROMX_LOAD( "ps-22a.bin",    0x0000000, 0x080000, CRC(37157331) SHA1(10155d8d6e6e832d6ea66db9bc098321fb5e8ebf), ROM_BIOS(3) )
879
880   ROM_SYSTEM_BIOS( 3, "3.0A", "SCPH-5501/SCPH-7003 (Version 3.0 11/18/96 A)" ) // 04121995
881   ROMX_LOAD( "ps-30a.bin",    0x0000000, 0x080000, CRC(8d8cb7e4) SHA1(0555c6fae8906f3f09baf5988f00e55f88e9f30b), ROM_BIOS(4) )
882
883   ROM_SYSTEM_BIOS( 4, "4.1A", "SCPH-7001/SCPH-7501/SCPH-7503/SCPH-9001 (Version 4.1 12/16/97 A)" ) // 04121995
884   ROMX_LOAD( "ps-41a.bin",    0x0000000, 0x080000, CRC(502224b6) SHA1(14df4f6c1e367ce097c11deae21566b4fe5647a9), ROM_BIOS(5) )
885
886   ROM_SYSTEM_BIOS( 5, "4.5A", "SCPH-101 (Version 4.5 05/25/00 A)" ) // 04121995
887   ROMX_LOAD( "psone-45a.bin", 0x0000000, 0x080000, CRC(171bdcec) SHA1(dcffe16bd90a723499ad46c641424981338d8378), ROM_BIOS(6) )
888ROM_END
889
890ROM_START( pse )
891   ROM_REGION32_LE( 0x080000, "user1", 0 )
892
893   ROM_SYSTEM_BIOS( 0, "2.0E", "DTL-H1002/SCPH-1002 (Version 2.0 05/10/95 E)" ) // 22091994
894   ROMX_LOAD( "ps-20e.bin",    0x0000000, 0x080000, CRC(9bb87c4b) SHA1(20b98f3d80f11cbf5a7bfd0779b0e63760ecc62c), ROM_BIOS(1) )
895
896   ROM_SYSTEM_BIOS( 1, "2.1E", "SCPH-1002/DTL-H1102 (Version 2.1 07/17/95 E)" ) // 22091994
897   ROMX_LOAD( "ps-21e.bin",    0x0000000, 0x080000, CRC(86c30531) SHA1(76cf6b1b2a7c571a6ad07f2bac0db6cd8f71e2cc), ROM_BIOS(2) )
898
899   ROM_SYSTEM_BIOS( 2, "2.2E", "SCPH-1002/DTL-H1202/DTL-H3002 (Version 2.2 12/04/95 E)" ) // 04121995
900   ROMX_LOAD( "ps-22e.bin",    0x0000000, 0x080000, CRC(1e26792f) SHA1(b6a11579caef3875504fcf3831b8e3922746df2c), ROM_BIOS(3) )
901
902   ROM_SYSTEM_BIOS( 3, "3.0E", "SCPH-5502/SCPH-5552 (Version 3.0 01/06/97 E)" ) // 04121995
903/*  ROMX_LOAD( "ps-30e.bad",    0x0000000, 0x080000, BAD_DUMP CRC(4d9e7c86) SHA1(f8de9325fc36fcfa4b29124d291c9251094f2e54), ROM_BIOS(4) ) */
904   ROMX_LOAD( "ps-30e.bin",    0x0000000, 0x080000, CRC(d786f0b9) SHA1(f6bc2d1f5eb6593de7d089c425ac681d6fffd3f0), ROM_BIOS(4) )
905
906   ROM_SYSTEM_BIOS( 4, "4.1E", "SCPH-7002/SCPH-7502/SCPH-9002 (Version 4.1 12/16/97 E)" ) // 04121995
907   ROMX_LOAD( "ps-41e.bin",    0x0000000, 0x080000, CRC(318178bf) SHA1(8d5de56a79954f29e9006929ba3fed9b6a418c1d), ROM_BIOS(5) )
908
909   ROM_SYSTEM_BIOS( 5, "4.4E", "SCPH-102 (Version 4.4 03/24/00 E)" ) // 04121995
910   ROMX_LOAD( "psone-44e.bin", 0x0000000, 0x080000, CRC(0bad7ea9) SHA1(beb0ac693c0dc26daf5665b3314db81480fa5c7c), ROM_BIOS(6) )
911
912   ROM_SYSTEM_BIOS( 6, "4.5E", "SCPH-102 (Version 4.5 05/25/00 E)" ) // 04121995
913   ROMX_LOAD( "psone-45e.bin", 0x0000000, 0x080000, CRC(76b880e5) SHA1(dbc7339e5d85827c095764fc077b41f78fd2ecae), ROM_BIOS(7) )
914ROM_END
915
916ROM_START( psa )
917   ROM_REGION32_LE( 0x080000, "user1", 0 )
918
919   ROM_SYSTEM_BIOS( 0, "3.0A", "SCPH-5501/SCPH-7003 (Version 3.0 11/18/96 A)" ) // 04121995
920   ROMX_LOAD( "ps-30a.bin",    0x0000000, 0x080000, CRC(8d8cb7e4) SHA1(0555c6fae8906f3f09baf5988f00e55f88e9f30b), ROM_BIOS(1) )
921
922   ROM_SYSTEM_BIOS( 1, "4.1A", "SCPH-7001/SCPH-7501/SCPH-7503/SCPH-9001 (Version 4.1 12/16/97 A)" ) // 04121995
923   ROMX_LOAD( "ps-41a.bin",    0x0000000, 0x080000, CRC(502224b6) SHA1(14df4f6c1e367ce097c11deae21566b4fe5647a9), ROM_BIOS(2) )
924ROM_END
925
926/*
927The version number & release date is stored in ascii text at the end of every bios, except for scph1000.
928There is also a BCD encoded date at offset 0x100, but this is set to 22091994 for versions prior to 2.2
929and 04121995 for all versions from 2.2 ( except Version 4.0J which is 29051997 ).
930
931Consoles not dumped:
932
933DTL-H1001H
934DTL-H3000
935SCPH-5001
936SCPH-5002
937SCPH-5003
938SCPH-5503
939SCPH-7500
940SCPH-9003
941SCPH-103
942
943Holes in version numbers:
944
945Version 2.0 J
946Version 4.1 J
947Version 4.2 J
948Version 4.4 J
949Version 4.5 J
950Version 4.0 A
951Version 4.2 A
952Version 4.3 A
953Version 4.4 A
954Version 4.0 E
955Version 4.2 E
956Version 4.3 E
957
958*/
959
960/*    YEAR  NAME    PARENT  COMPAT  MACHINE     INPUT   INIT    COMPANY                             FULLNAME                            FLAGS */
961CONS( 1994, psj,    0,      0,      psxntsc,    psx,    psx,    "Sony Computer Entertainment Inc", "Sony PlayStation (Japan)",         GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
962CONS( 1995, pse,    psj,    0,      psxpal,     psx,    psx,    "Sony Computer Entertainment Inc", "Sony PlayStation (Europe)",        GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
963CONS( 1995, psu,    psj,    0,      psxntsc,    psx,    psx,    "Sony Computer Entertainment Inc", "Sony PlayStation (USA)",           GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
964CONS( 1995, psa,    psj,    0,      psxntsc,    psx,    psx,    "Sony Computer Entertainment Inc", "Sony PlayStation (Asia-Pacific)",  GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
src/mess/drivers/ami1200.c
r11460r11461
1/*
2    Amiga 1200
3
4    Preliminary MAME driver by Mariusz Wojcieszek
5    CD-ROM controller by Ernesto Corvi
6    Borrowed by incog for MESS
7
8    2009-05 Fabio Priuli:
9    Amiga 1200 support is just sketched (I basically took cd32 and removed Akiko). I connected
10    the floppy drive in the same way as in amiga.c but it seems to be not working, since I
11    tried to load WB3.1 with no success. However, this problem may be due to anything: maybe
12    the floppy code must be connected elsewhere, or the .adf image is broken, or I made some
13    stupid mistake in the CIA interfaces.
14    Later, it could be wise to re-factor this source and merge the non-AGA code with
15    mess/drivers/amiga.c
16*/
17
18#include "emu.h"
19#include "cpu/m68000/m68000.h"
20#include "machine/6526cia.h"
21#include "machine/i2cmem.h"
22#include "machine/amigafdc.h"
23#include "machine/amigakbd.h"
24
25#include "includes/amiga.h"
26#include "includes/cd32.h"
27
28
29
30class ami1200_state : public cd32_state
31{
32public:
33   ami1200_state(const machine_config &mconfig, device_type type, const char *tag)
34      : cd32_state(mconfig, type, tag) { }
35
36   UINT16 potgo_value;
37   int cd32_shifter[2];
38   int oldstate[2];
39};
40
41
42
43#define A1200PAL_XTAL_X1  XTAL_28_37516MHz
44#define A1200PAL_XTAL_X2  XTAL_4_433619MHz
45
46
47
48static void handle_cd32_joystick_cia(ami1200_state *state, UINT8 pra, UINT8 dra);
49
50static WRITE32_HANDLER( aga_overlay_w )
51{
52   if (ACCESSING_BITS_16_23)
53   {
54      data = (data >> 16) & 1;
55
56      /* switch banks as appropriate */
57      memory_set_bank(space->machine(), "bank1", data & 1);
58
59      /* swap the write handlers between ROM and bank 1 based on the bit */
60      if ((data & 1) == 0)
61         /* overlay disabled, map RAM on 0x000000 */
62         space->install_write_bank(0x000000, 0x1fffff, "bank1");
63      else
64         /* overlay enabled, map Amiga system ROM on 0x000000 */
65         space->unmap_write(0x000000, 0x1fffff);
66   }
67}
68
69/*************************************
70 *
71 *  CIA-A port A access:
72 *
73 *  PA7 = game port 1, pin 6 (fire)
74 *  PA6 = game port 0, pin 6 (fire)
75 *  PA5 = /RDY (disk ready)
76 *  PA4 = /TK0 (disk track 00)
77 *  PA3 = /WPRO (disk write protect)
78 *  PA2 = /CHNG (disk change)
79 *  PA1 = /LED (LED, 0=bright / audio filter control)
80 *  PA0 = MUTE
81 *
82 *************************************/
83
84static WRITE8_DEVICE_HANDLER( ami1200_cia_0_porta_w )
85{
86   ami1200_state *state = device->machine().driver_data<ami1200_state>();
87
88   /* bit 2 = Power Led on Amiga */
89   set_led_status(device->machine(), 0, !BIT(data, 1));
90
91   handle_cd32_joystick_cia(state, data, mos6526_r(device, 2));
92}
93
94/*************************************
95 *
96 *  CIA-A port B access:
97 *
98 *  PB7 = parallel data 7
99 *  PB6 = parallel data 6
100 *  PB5 = parallel data 5
101 *  PB4 = parallel data 4
102 *  PB3 = parallel data 3
103 *  PB2 = parallel data 2
104 *  PB1 = parallel data 1
105 *  PB0 = parallel data 0
106 *
107 *************************************/
108
109static READ8_DEVICE_HANDLER( ami1200_cia_0_portb_r )
110{
111   /* parallel port */
112   logerror("%s:CIA0_portb_r\n", device->machine().describe_context());
113   return 0xff;
114}
115
116static WRITE8_DEVICE_HANDLER( ami1200_cia_0_portb_w )
117{
118   /* parallel port */
119   logerror("%s:CIA0_portb_w(%02x)\n", device->machine().describe_context(), data);
120}
121
122static ADDRESS_MAP_START( a1200_map, AS_PROGRAM, 32 )
123   ADDRESS_MAP_UNMAP_HIGH
124   AM_RANGE(0x000000, 0x1fffff) AM_RAMBANK("bank1") AM_BASE_SIZE_MEMBER(cd32_state, m_chip_ram, m_chip_ram_size)
125   AM_RANGE(0xbfa000, 0xbfa003) AM_WRITE(aga_overlay_w)
126   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE16(amiga_cia_r, amiga_cia_w, 0xffffffff)
127   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE16(amiga_custom_r, amiga_custom_w, 0xffffffff) AM_BASE_MEMBER(cd32_state, m_custom_regs)
128   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE16(amiga_autoconfig_r, amiga_autoconfig_w, 0xffffffff)
129   AM_RANGE(0xf80000, 0xffffff) AM_ROM AM_REGION("user1", 0)   /* Kickstart */
130ADDRESS_MAP_END
131
132
133//int cd32_input_port_val = 0;
134//int cd32_input_select = 0;
135
136static void cd32_potgo_w(running_machine &machine, UINT16 data)
137{
138   ami1200_state *state = machine.driver_data<ami1200_state>();
139   int i;
140
141   state->m_potgo_value = state->m_potgo_value & 0x5500;
142   state->m_potgo_value |= data & 0xaa00;
143
144   for (i = 0; i < 8; i += 2)
145   {
146      UINT16 dir = 0x0200 << i;
147      if (data & dir)
148      {
149         UINT16 d = 0x0100 << i;
150         state->m_potgo_value &= ~d;
151         state->m_potgo_value |= data & d;
152      }
153   }
154   for (i = 0; i < 2; i++)
155   {
156      UINT16 p5dir = 0x0200 << (i * 4); /* output enable P5 */
157      UINT16 p5dat = 0x0100 << (i * 4); /* data P5 */
158      if ((state->m_potgo_value & p5dir) && (state->m_potgo_value & p5dat))
159         state->m_cd32_shifter[i] = 8;
160   }
161}
162
163static void handle_cd32_joystick_cia(ami1200_state *state, UINT8 pra, UINT8 dra)
164{
165   int i;
166
167   for (i = 0; i < 2; i++)
168   {
169      UINT8 but = 0x40 << i;
170      UINT16 p5dir = 0x0200 << (i * 4); /* output enable P5 */
171      UINT16 p5dat = 0x0100 << (i * 4); /* data P5 */
172      if (!(state->m_potgo_value & p5dir) || !(state->m_potgo_value & p5dat))
173      {
174         if ((dra & but) && (pra & but) != state->m_oldstate[i])
175         {
176            if (!(pra & but))
177            {
178               state->m_cd32_shifter[i]--;
179               if (state->m_cd32_shifter[i] < 0)
180                  state->m_cd32_shifter[i] = 0;
181            }
182         }
183      }
184      state->m_oldstate[i] = pra & but;
185   }
186}
187
188
189static INPUT_PORTS_START( a1200 )
190   PORT_START("CIA0PORTA")
191   PORT_BIT( 0x3f, IP_ACTIVE_LOW, IPT_SPECIAL )
192   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
193   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
194
195   PORT_START("CIA0PORTB")
196   PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNUSED )
197
198   PORT_START("JOY0DAT")
199   PORT_BIT( 0x0303, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(amiga_joystick_convert, "P1JOY")
200   PORT_BIT( 0xfcfc, IP_ACTIVE_HIGH, IPT_UNUSED )
201
202   PORT_START("JOY1DAT")
203   PORT_BIT( 0x0303, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(amiga_joystick_convert, "P2JOY")
204   PORT_BIT( 0xfcfc, IP_ACTIVE_HIGH, IPT_UNUSED )
205
206   PORT_START("POTGO")
207   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNUSED )
208   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
209   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_UNUSED )
210   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
211   PORT_BIT( 0xaaff, IP_ACTIVE_HIGH, IPT_UNUSED )
212
213   PORT_START("P1JOY")
214   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
215   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1)
216   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1)
217   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
218
219   PORT_START("P2JOY")
220   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(2)
221   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
222   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2)
223   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
224
225   PORT_START("P0MOUSEX")
226   PORT_BIT( 0xff, 0x00, IPT_MOUSE_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_PLAYER(1)
227
228   PORT_START("P0MOUSEY")
229   PORT_BIT( 0xff, 0x00, IPT_MOUSE_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_PLAYER(1)
230
231   PORT_START("P1MOUSEX")
232   PORT_BIT( 0xff, 0x00, IPT_MOUSE_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_PLAYER(2)
233
234   PORT_START("P1MOUSEY")
235   PORT_BIT( 0xff, 0x00, IPT_MOUSE_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(5) PORT_MINMAX(0, 255) PORT_PLAYER(2)
236
237   PORT_INCLUDE( amiga_us_keyboard )
238INPUT_PORTS_END
239
240
241/*************************************
242 *
243 *  Sound definitions
244 *
245 *************************************/
246
247static READ8_DEVICE_HANDLER( a1200_cia_0_portA_r )
248{
249   UINT8 ret = input_port_read(device->machine(), "CIA0PORTA") & 0xc0;   /* Gameport 1 and 0 buttons */
250   ret |= amiga_fdc_status_r(device->machine().device("fdc"));
251   return ret;
252}
253
254
255static const mos6526_interface a1200_cia_0_intf =
256{
257   0,                                       /* tod_clock */
258   DEVCB_LINE(amiga_cia_0_irq),                           /* irq_func */
259   DEVCB_NULL,   /* pc_func */
260   DEVCB_NULL,
261   DEVCB_NULL,
262   DEVCB_HANDLER(a1200_cia_0_portA_r),
263   DEVCB_HANDLER(ami1200_cia_0_porta_w),      /* port A */
264   DEVCB_HANDLER(ami1200_cia_0_portb_r),
265   DEVCB_HANDLER(ami1200_cia_0_portb_w)      /* port B */
266};
267
268static const mos6526_interface a1200_cia_1_intf =
269{
270   0,                                       /* tod_clock */
271   DEVCB_LINE(amiga_cia_1_irq),                           /* irq_func */
272   DEVCB_NULL,   /* pc_func */
273   DEVCB_NULL,
274   DEVCB_NULL,
275   DEVCB_NULL,
276   DEVCB_NULL,                           /* port A */
277   DEVCB_NULL,
278   DEVCB_DEVICE_HANDLER("fdc", amiga_fdc_control_w)         /* port B */
279};
280
281
282static MACHINE_CONFIG_START( a1200n, ami1200_state )
283
284   /* basic machine hardware */
285   MCFG_CPU_ADD("maincpu", M68EC020, AMIGA_68EC020_NTSC_CLOCK) /* 14.3 Mhz */
286   MCFG_CPU_PROGRAM_MAP(a1200_map)
287
288//  MCFG_CPU_ADD("keyboard_mpu", MC68HC05)
289
290   MCFG_MACHINE_RESET(amiga)
291
292   /* video hardware */
293   MCFG_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK)
294
295   MCFG_SCREEN_ADD("screen", RASTER)
296   MCFG_SCREEN_REFRESH_RATE(59.997)
297   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
298   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
299   MCFG_SCREEN_SIZE(512*2, 312)
300   MCFG_SCREEN_VISIBLE_AREA((129-8-8)*2, (449+8-1+8)*2, 44-8, 300+8-1)
301   MCFG_SCREEN_UPDATE(amiga_aga)
302
303   MCFG_VIDEO_START(amiga_aga)
304
305   /* sound hardware */
306   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
307
308   MCFG_SOUND_ADD("amiga", AMIGA, XTAL_28_63636MHz/8)
309   MCFG_SOUND_ROUTE(0, "lspeaker", 0.25)
310   MCFG_SOUND_ROUTE(1, "rspeaker", 0.25)
311   MCFG_SOUND_ROUTE(2, "rspeaker", 0.25)
312   MCFG_SOUND_ROUTE(3, "lspeaker", 0.25)
313
314   /* cia */
315   MCFG_MOS8520_ADD("cia_0", AMIGA_68EC020_NTSC_CLOCK / 10, a1200_cia_0_intf)
316   MCFG_MOS8520_ADD("cia_1", AMIGA_68EC020_NTSC_CLOCK / 10, a1200_cia_1_intf)
317
318   MCFG_AMIGA_FDC_ADD("fdc")
319MACHINE_CONFIG_END
320
321static MACHINE_CONFIG_DERIVED( a1200p, a1200n )
322
323   /* adjust for PAL specs */
324   MCFG_CPU_MODIFY("maincpu")
325   MCFG_CPU_CLOCK(A1200PAL_XTAL_X1/2) /* 14.18758 MHz */
326
327   /* video hardware */
328   MCFG_SCREEN_MODIFY("screen")
329   MCFG_SCREEN_REFRESH_RATE(50)
330
331   /* sound hardware */
332   MCFG_SOUND_MODIFY("amiga")
333   MCFG_SOUND_CLOCK(A1200PAL_XTAL_X1/8) /* 3.546895 MHz */
334
335   /* cia */
336   MCFG_DEVICE_MODIFY("cia_0")
337   MCFG_DEVICE_CLOCK(A1200PAL_XTAL_X1/20)
338   MCFG_DEVICE_MODIFY("cia_1")
339   MCFG_DEVICE_CLOCK(A1200PAL_XTAL_X1/20)
340MACHINE_CONFIG_END
341
342
343/***************************************************************************
344    ROM DEFINITIONS
345***************************************************************************/
346
347ROM_START( a1200n )
348   ROM_REGION32_BE(0x080000, "user1", 0)
349   ROM_DEFAULT_BIOS("kick31")
350   ROM_SYSTEM_BIOS(0, "kick30", "Kickstart 3.0 (39.106)")
351   ROMX_LOAD("391523-01.u6a", 0x000000, 0x040000, CRC(c742a412) SHA1(999eb81c65dfd07a71ee19315d99c7eb858ab186), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(1))
352   ROMX_LOAD("391524-01.u6b", 0x000002, 0x040000, CRC(d55c6ec6) SHA1(3341108d3a402882b5ef9d3b242cbf3c8ab1a3e9), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(1))
353   ROM_SYSTEM_BIOS(1, "kick31", "Kickstart 3.1 (40.068)")
354   ROMX_LOAD("391773-01.u6a", 0x000000, 0x040000, CRC(08dbf275) SHA1(b8800f5f909298109ea69690b1b8523fa22ddb37), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(2))   // ROM_LOAD32_WORD_SWAP!
355   ROMX_LOAD("391774-01.u6b", 0x000002, 0x040000, CRC(16c07bf8) SHA1(90e331be1970b0e53f53a9b0390b51b59b3869c2), ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2) | ROM_BIOS(2))
356
357   // COMMODORE | 391508-01 REV0 | KEYBOARD MPU
358   ROM_REGION(0x1040, "keyboard_rev0", 0)
359   ROM_LOAD("391508-01.u13", 0x0000, 0x1040, NO_DUMP)
360
361   // Amiga Tech REV1 Keyboard MPU
362   ROM_REGION(0x2f40, "keyboard_rev1", 0)
363   ROM_LOAD("391508-02.u13", 0x0000, 0x2f40, NO_DUMP)
364ROM_END
365
366#define rom_a1200p    rom_a1200n
367
368
369/***************************************************************************************************/
370
371// these come directly from amiga.c
372
373static UINT16 a1200_read_dskbytr(running_machine &machine)
374{
375   return amiga_fdc_get_byte(machine.device("fdc"));
376}
377
378static void a1200_write_dsklen(running_machine &machine, UINT16 data)
379{
380   cd32_state *state = machine.driver_data<cd32_state>();
381   if ( data & 0x8000 )
382   {
383      if ( CUSTOM_REG(REG_DSKLEN) & 0x8000 )
384         amiga_fdc_setup_dma(machine.device("fdc"));
385   }
386}
387
388
389static DRIVER_INIT( a1200 )
390{
391   cd32_state *state = machine.driver_data<cd32_state>();
392   static const amiga_machine_interface cd32_intf =
393   {
394      AGA_CHIP_RAM_MASK,
395      NULL, NULL,         /* joy0dat_r & joy1dat_r */
396      cd32_potgo_w,      /* potgo_w */
397      a1200_read_dskbytr, a1200_write_dsklen, /* dskbytr_r & dsklen_w */
398      NULL,            /* serdat_w */
399      NULL,            /* scanline0_callback */
400      NULL,            /* reset_callback */
401      NULL,            /* nmi_callback */
402      FLAGS_AGA_CHIPSET   /* flags */
403   };
404
405   /* configure our Amiga setup */
406   amiga_machine_config(machine, &cd32_intf);
407
408   /* set up memory */
409   memory_configure_bank(machine, "bank1", 0, 1, state->m_chip_ram, 0);
410   memory_configure_bank(machine, "bank1", 1, 1, machine.region("user1")->base(), 0);
411
412   /* initialize keyboard */
413   amigakbd_init(machine);
414}
415
416
417/***************************************************************************************************/
418
419/*    YEAR  NAME     PARENT   COMPAT  MACHINE INPUT   INIT      COMPANY       FULLNAME */
420COMP( 1992, a1200n,  0,       0,      a1200n, a1200,  a1200,  "Commodore Business Machines",  "Amiga 1200 (NTSC)" , GAME_NOT_WORKING )
421COMP( 1992, a1200p,  a1200n,  0,      a1200p, a1200,  a1200,  "Commodore Business Machines",  "Amiga 1200 (PAL)" , GAME_NOT_WORKING  )
src/mess/drivers/atari.c
r11460r11461
1/******************************************************************************
2    Atari 400/800
3
4    MESS Driver
5
6    Juergen Buchmueller, June 1998
7
8    2009-05 FP changes:
9     Factored out MESS specific code from MAME
10     Added skeleton support for other XL/XE machines (VERY preliminary):
11     - a600xl based on maxaflex emulation in MAME
12     - a1200xl sharing a800xl code without BASIC
13     - a65xe, a65xea, a130xe, a800xe, xegs sharing a800xl code (and this is wrong
14      at least for xegs)
15     Added proper dumps and labels, thanks to Freddy Offenga researches (a few
16     are still marked BAD_DUMP while waiting for crc confirmation, since they
17     have been obtained by splitting whole dumps)
18
19     To Do:
20     - Find out why a600xl and a800xl don't work (xe machines should then follow)
21     - Investigate supported RAM sizes and OS versions in different models
22     - Implement differences between various models (currently most of the
23      XL/XE are exactly an a800xl, but this will change as soon as emulation
24      starts to work)
25     - Fix various keyboard differences
26     - Freddy emulation for 800XLF?
27     - Add support for proto boards and expansions (a1400xl, C/PM board, etc.)
28     - Clean up the whole driver + cart + floppy structure
29
30******************************************************************************/
31
32#include "emu.h"
33#include "deprecat.h"
34#include "cpu/m6502/m6502.h"
35#include "includes/atari.h"
36#include "machine/ataridev.h"
37#include "imagedev/cartslot.h"
38#include "sound/pokey.h"
39#include "machine/6821pia.h"
40#include "video/gtia.h"
41#include "sound/dac.h"
42#include "machine/ram.h"
43
44/******************************************************************************
45    Atari 800 memory map (preliminary)
46
47    ***************** read access *******************
48    range     short   description
49    0000-9FFF RAM     main memory
50    A000-BFFF RAM/ROM RAM or (banked) ROM cartridges
51    C000-CFFF ROM     unused or monitor ROM
52
53    ********* GTIA    ********************************
54
55    D000      m0pf    missile 0 playfield collisions
56    D001      m1pf    missile 1 playfield collisions
57    D002      m2pf    missile 2 playfield collisions
58    D003      m3pf    missile 3 playfield collisions
59    D004      p0pf    player 0 playfield collisions
60    D005      p1pf    player 1 playfield collisions
61    D006      p2pf    player 2 playfield collisions
62    D007      p3pf    player 3 playfield collisions
63    D008      m0pl    missile 0 player collisions
64    D009      m1pl    missile 1 player collisions
65    D00A      m2pl    missile 2 player collisions
66    D00B      m3pl    missile 3 player collisions
67    D00C      p0pl    player 0 player collisions
68    D00D      p1pl    player 1 player collisions
69    D00E      p2pl    player 2 player collisions
70    D00F      p3pl    player 3 player collisions
71    D010      but0    button stick 0
72    D011      but1    button stick 1
73    D012      but2    button stick 2
74    D013      but3    button stick 3
75    D014      xff     unused
76    D015      xff     unused
77    D016      xff     unused
78    D017      xff     unused
79    D018      xff     unused
80    D019      xff     unused
81    D01A      xff     unused
82    D01B      xff     unused
83    D01C      xff     unused
84    D01D      xff     unused
85    D01E      xff     unused
86    D01F      cons    console keys
87    D020-D0FF repeated 7 times
88
89    D100-D1FF xff
90
91    ********* POKEY   ********************************
92    D200      pot0    paddle 0
93    D201      pot1    paddle 1
94    D202      pot2    paddle 2
95    D203      pot3    paddle 3
96    D204      pot4    paddle 4
97    D205      pot5    paddle 5
98    D206      pot6    paddle 6
99    D207      pot7    paddle 7
100    D208      potb    all paddles
101    D209      kbcode  keyboard scan code
102    D20A      random  random number generator
103    D20B      xff     unused
104    D20C      xff     unused
105    D20D      serin   serial input
106    D20E      irqst   IRQ status
107    D20F      skstat  sk status
108    D210-D2FF repeated 15 times
109
110    ********* PIO     ********************************
111    D300      porta   read pio port A
112    D301      portb   read pio port B
113    D302      pactl   read pio port A control
114    D303      pbctl   read pio port B control
115    D304-D3FF repeated 63 times
116
117    ********* ANTIC   ********************************
118    D400      xff     unused
119    D401      xff     unused
120    D402      xff     unused
121    D403      xff     unused
122    D404      xff     unused
123    D405      xff     unused
124    D406      xff     unused
125    D407      xff     unused
126    D408      xff     unused
127    D409      xff     unused
128    D40A      xff     unused
129    D40B      vcount  vertical (scanline) counter
130    D40C      penh    light pen horizontal pos
131    D40D      penv    light pen vertical pos
132    D40E      xff     unused
133    D40F      nmist   NMI status
134
135    D500-D7FF xff     unused memory
136
137    D800-DFFF ROM     floating point ROM
138    E000-FFFF ROM     bios ROM
139
140    ***************** write access *******************
141    range     short   description
142    0000-9FFF RAM     main memory
143    A000-BFFF RAM/ROM RAM or (banked) ROM
144    C000-CFFF ROM     unused or monitor ROM
145
146    ********* GTIA    ********************************
147    D000      hposp0  player 0 horz position
148    D001      hposp1  player 1 horz position
149    D002      hposp2  player 2 horz position
150    D003      hposp3  player 3 horz position
151    D004      hposm0  missile 0 horz position
152    D005      hposm1  missile 0 horz position
153    D006      hposm2  missile 0 horz position
154    D007      hposm3  missile 0 horz position
155    D008      sizep0  size player 0
156    D009      sizep1  size player 0
157    D00A      sizep2  size player 0
158    D00B      sizep3  size player 0
159    D00C      sizem   size missiles
160    D00D      grafp0  graphics data for player 0
161    D00E      grafp1  graphics data for player 1
162    D00F      grafp2  graphics data for player 2
163    D010      grafp3  graphics data for player 3
164    D011      grafm   graphics data for missiles
165    D012      colpm0  color for player/missile 0
166    D013      colpm1  color for player/missile 1
167    D014      colpm2  color for player/missile 2
168    D015      colpm3  color for player/missile 3
169    D016      colpf0  color 0 playfield
170    D017      colpf1  color 1 playfield
171    D018      colpf2  color 2 playfield
172    D019      colpf3  color 3 playfield
173    D01A      colbk   background playfield
174    D01B      prior   priority select
175    D01C      vdelay  delay until vertical retrace
176    D01D      gractl  graphics control
177    D01E      hitclr  clear collisions
178    D01F      wcons   write console (speaker)
179    D020-D0FF repeated 7 times
180
181    D100-D1FF xff     unused
182
183    ********* POKEY   ********************************
184    D200      audf1   frequency audio chan #1
185    D201      audc1   control audio chan #1
186    D202      audf2   frequency audio chan #2
187    D203      audc2   control audio chan #2
188    D204      audf3   frequency audio chan #3
189    D205      audc3   control audio chan #3
190    D206      audf4   frequency audio chan #4
191    D207      audc4   control audio chan #4
192    D208      audctl  audio control
193    D209      stimer  start timer
194    D20A      skres   sk reset
195    D20B      potgo   start pot AD conversion
196    D20C      xff     unused
197    D20D      serout  serial output
198    D20E      irqen   IRQ enable
199    D20F      skctl   sk control
200    D210-D2FF repeated 15 times
201
202    ********* PIO     ********************************
203    D300      porta   write pio port A (output or mask)
204    D301      portb   write pio port B (output or mask)
205    D302      pactl   write pio port A control
206    D303      pbctl   write pio port B control
207    D304-D3FF         repeated
208
209    ********* ANTIC   ********************************
210    D400      dmactl  write DMA control
211    D401      chactl  write character control
212    D402      dlistl  write display list lo
213    D403      dlisth  write display list hi
214    D404      hscrol  write horz scroll
215    D405      vscrol  write vert scroll
216    D406      xff     unused
217    D407      pmbash  player/missile base addr hi
218    D408      xff     unused
219    D409      chbash  character generator base addr hi
220    D40A      wsync   wait for hsync
221    D40B      xff     unused
222    D40C      xff     unused
223    D40D      xff     unused
224    D40E      nmien   NMI enable
225    D40F      nmires  NMI reset
226
227    D500-D7FF xff     unused memory
228
229    D800-DFFF ROM     floating point ROM
230    E000-FFFF ROM     BIOS ROM
231******************************************************************************/
232
233/**************************************************************
234 *
235 * Memory maps
236 *
237 **************************************************************/
238
239
240static ADDRESS_MAP_START(a400_mem, AS_PROGRAM, 8)
241   AM_RANGE(0x0000, 0x9fff) AM_NOP   /* RAM installed at runtime */
242   AM_RANGE(0xa000, 0xbfff) AM_RAMBANK("a000")
243   AM_RANGE(0xc000, 0xcfff) AM_ROM
244   AM_RANGE(0xd000, 0xd0ff) AM_READWRITE(atari_gtia_r, atari_gtia_w)
245   AM_RANGE(0xd100, 0xd1ff) AM_NOP
246   AM_RANGE(0xd200, 0xd2ff) AM_DEVREADWRITE("pokey", pokey_r, pokey_w)
247   AM_RANGE(0xd300, 0xd3ff) AM_DEVREADWRITE_MODERN("pia", pia6821_device, read_alt, write_alt)
248   AM_RANGE(0xd400, 0xd4ff) AM_READWRITE(atari_antic_r, atari_antic_w)
249   AM_RANGE(0xd500, 0xd7ff) AM_NOP
250   AM_RANGE(0xd800, 0xffff) AM_ROM
251ADDRESS_MAP_END
252
253
254static ADDRESS_MAP_START(a800_mem, AS_PROGRAM, 8)
255   AM_RANGE(0x0000, 0x7fff) AM_RAMBANK("0000")
256   AM_RANGE(0x8000, 0x9fff) AM_RAMBANK("8000")
257   AM_RANGE(0xa000, 0xbfff) AM_RAMBANK("a000")
258   AM_RANGE(0xc000, 0xcfff) AM_ROM
259   AM_RANGE(0xd000, 0xd0ff) AM_READWRITE(atari_gtia_r, atari_gtia_w)
260   AM_RANGE(0xd100, 0xd1ff) AM_NOP
261   AM_RANGE(0xd200, 0xd2ff) AM_DEVREADWRITE("pokey", pokey_r, pokey_w)
262   AM_RANGE(0xd300, 0xd3ff) AM_DEVREADWRITE_MODERN("pia", pia6821_device, read_alt, write_alt)
263   AM_RANGE(0xd400, 0xd4ff) AM_READWRITE(atari_antic_r, atari_antic_w)
264   AM_RANGE(0xd500, 0xd7ff) AM_NOP
265   AM_RANGE(0xd800, 0xffff) AM_ROM
266ADDRESS_MAP_END
267
268
269static ADDRESS_MAP_START(a600xl_mem, AS_PROGRAM, 8)
270   AM_RANGE(0x0000, 0x3fff) AM_RAM
271   AM_RANGE(0x5000, 0x57ff) AM_ROM AM_REGION("maincpu", 0x5000)   /* self test */
272   AM_RANGE(0xa000, 0xbfff) AM_ROM   /* BASIC */
273   AM_RANGE(0xc000, 0xcfff) AM_ROM /* OS */
274   AM_RANGE(0xd000, 0xd0ff) AM_READWRITE(atari_gtia_r, atari_gtia_w)
275   AM_RANGE(0xd100, 0xd1ff) AM_NOP
276   AM_RANGE(0xd200, 0xd2ff) AM_DEVREADWRITE("pokey", pokey_r, pokey_w)
277   AM_RANGE(0xd300, 0xd3ff) AM_DEVREADWRITE_MODERN("pia", pia6821_device, read_alt, write_alt)
278   AM_RANGE(0xd400, 0xd4ff) AM_READWRITE(atari_antic_r, atari_antic_w)
279   AM_RANGE(0xd500, 0xd7ff) AM_NOP
280   AM_RANGE(0xd800, 0xffff) AM_ROM /* OS */
281ADDRESS_MAP_END
282
283
284static ADDRESS_MAP_START(a800xl_mem, AS_PROGRAM, 8)
285   AM_RANGE(0x0000, 0x4fff) AM_RAM
286   AM_RANGE(0x5000, 0x57ff) AM_RAMBANK("bank2")
287   AM_RANGE(0x5800, 0x9fff) AM_RAM
288   AM_RANGE(0xa000, 0xbfff) AM_RAMBANK("bank1")
289   AM_RANGE(0xc000, 0xcfff) AM_RAMBANK("bank3")
290   AM_RANGE(0xd000, 0xd0ff) AM_READWRITE(atari_gtia_r, atari_gtia_w)
291   AM_RANGE(0xd100, 0xd1ff) AM_NOP
292   AM_RANGE(0xd200, 0xd2ff) AM_DEVREADWRITE("pokey", pokey_r, pokey_w)
293   AM_RANGE(0xd300, 0xd3ff) AM_DEVREADWRITE_MODERN("pia", pia6821_device, read_alt, write_alt)
294   AM_RANGE(0xd400, 0xd4ff) AM_READWRITE(atari_antic_r, atari_antic_w)
295   AM_RANGE(0xd500, 0xd7ff) AM_NOP
296   AM_RANGE(0xd800, 0xffff) AM_RAMBANK("bank4")
297ADDRESS_MAP_END
298
299static ADDRESS_MAP_START(xegs_mem, AS_PROGRAM, 8)
300   AM_RANGE(0x0000, 0x4fff) AM_RAM
301   AM_RANGE(0x5000, 0x57ff) AM_RAMBANK("bank2")
302   AM_RANGE(0x5800, 0x7fff) AM_RAM
303   AM_RANGE(0x8000, 0x9fff) AM_ROMBANK("bank0")
304   AM_RANGE(0xa000, 0xbfff) AM_ROMBANK("bank1")
305   AM_RANGE(0xc000, 0xcfff) AM_RAMBANK("bank3")
306   AM_RANGE(0xd000, 0xd0ff) AM_READWRITE(atari_gtia_r, atari_gtia_w)
307   AM_RANGE(0xd100, 0xd1ff) AM_NOP
308   AM_RANGE(0xd200, 0xd2ff) AM_DEVREADWRITE("pokey", pokey_r, pokey_w)
309   AM_RANGE(0xd300, 0xd3ff) AM_DEVREADWRITE_MODERN("pia", pia6821_device, read_alt, write_alt)
310   AM_RANGE(0xd400, 0xd4ff) AM_READWRITE(atari_antic_r, atari_antic_w)
311   AM_RANGE(0xd500, 0xd7ff) AM_NOP
312   AM_RANGE(0xd800, 0xffff) AM_RAMBANK("bank4")
313ADDRESS_MAP_END
314
315
316static ADDRESS_MAP_START(a5200_mem, AS_PROGRAM, 8)
317   AM_RANGE(0x0000, 0x3fff) AM_RAM
318   AM_RANGE(0x4000, 0xbfff) AM_ROM
319   AM_RANGE(0xc000, 0xc0ff) AM_READWRITE(atari_gtia_r, atari_gtia_w)
320   AM_RANGE(0xd400, 0xd5ff) AM_READWRITE(atari_antic_r, atari_antic_w)
321   AM_RANGE(0xe800, 0xe8ff) AM_DEVREADWRITE("pokey", pokey_r, pokey_w)
322   AM_RANGE(0xf800, 0xffff) AM_ROM
323ADDRESS_MAP_END
324
325
326#ifdef MESS
327int atari_input_disabled(running_machine &machine)
328{
329   return 0;
330}
331#endif
332
333/**************************************************************
334 *
335 * Input ports
336 *
337 **************************************************************/
338
339
340#define JOYSTICK_DELTA         10
341#define JOYSTICK_SENSITIVITY   200
342
343static INPUT_PORTS_START( atari_artifacting )
344   PORT_START("artifacts")
345   PORT_CONFNAME(0x40, 0x00, "Television Artifacts" )
346   PORT_CONFSETTING(0x00, DEF_STR( Off ) )
347   PORT_CONFSETTING(0x40, DEF_STR( On ) )
348INPUT_PORTS_END
349
350
351
352static INPUT_PORTS_START( atari_console )
353   PORT_START("console")
354   PORT_BIT(0x04, 0x04, IPT_KEYBOARD) PORT_NAME("CONS.2: Option") PORT_CODE(KEYCODE_F3)
355   PORT_BIT(0x02, 0x02, IPT_KEYBOARD) PORT_NAME("CONS.1: Select") PORT_CODE(KEYCODE_F2)
356   PORT_BIT(0x01, 0x01, IPT_KEYBOARD) PORT_NAME("CONS.0: Start") PORT_CODE(KEYCODE_F1)
357INPUT_PORTS_END
358
359
360
361static INPUT_PORTS_START( atari_digital_joystick2 )
362   PORT_START("djoy_0_1")   /* IN1 digital joystick #1 + #2 (PIA port A) */
363   PORT_BIT(0x01, 0x01, IPT_JOYSTICK_UP)    PORT_CODE(KEYCODE_8_PAD) PORT_CODE(JOYCODE_Y_UP_SWITCH)    PORT_PLAYER(1)
364   PORT_BIT(0x02, 0x02, IPT_JOYSTICK_DOWN)  PORT_CODE(KEYCODE_2_PAD) PORT_CODE(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(1)
365   PORT_BIT(0x04, 0x04, IPT_JOYSTICK_LEFT)  PORT_CODE(KEYCODE_4_PAD) PORT_CODE(JOYCODE_X_LEFT_SWITCH)  PORT_PLAYER(1)
366   PORT_BIT(0x08, 0x08, IPT_JOYSTICK_RIGHT) PORT_CODE(KEYCODE_6_PAD) PORT_CODE(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(1)
367   PORT_BIT(0x10, 0x10, IPT_JOYSTICK_UP)    PORT_CODE(KEYCODE_8_PAD) PORT_CODE(JOYCODE_Y_UP_SWITCH)    PORT_PLAYER(2)
368   PORT_BIT(0x20, 0x20, IPT_JOYSTICK_DOWN)  PORT_CODE(KEYCODE_2_PAD) PORT_CODE(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(2)
369   PORT_BIT(0x40, 0x40, IPT_JOYSTICK_LEFT)  PORT_CODE(KEYCODE_4_PAD) PORT_CODE(JOYCODE_X_LEFT_SWITCH)  PORT_PLAYER(2)
370   PORT_BIT(0x80, 0x80, IPT_JOYSTICK_RIGHT) PORT_CODE(KEYCODE_6_PAD) PORT_CODE(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(2)
371
372   PORT_START("djoy_2_3")   /* IN2 digital joystick #3 + #4 (PIA port B) */
373   PORT_BIT(0x01, 0x01, IPT_UNUSED)
374   PORT_BIT(0x02, 0x02, IPT_UNUSED)
375   PORT_BIT(0x04, 0x04, IPT_UNUSED)
376   PORT_BIT(0x08, 0x08, IPT_UNUSED)
377   PORT_BIT(0x10, 0x10, IPT_UNUSED)
378   PORT_BIT(0x20, 0x20, IPT_UNUSED)
379   PORT_BIT(0x40, 0x40, IPT_UNUSED)
380   PORT_BIT(0x80, 0x80, IPT_UNUSED)
381
382   PORT_START("djoy_b")   /* IN3 digital joystick buttons (GTIA button bits) */
383   PORT_BIT(0x01, 0x01, IPT_BUTTON1) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_PLAYER(1)
384   PORT_BIT(0x02, 0x02, IPT_BUTTON1) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON2) PORT_PLAYER(2)
385   PORT_BIT(0x04, 0x04, IPT_UNUSED)
386   PORT_BIT(0x08, 0x08, IPT_UNUSED)
387   PORT_BIT(0x10, 0x10, IPT_BUTTON2) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_PLAYER(1)
388   PORT_BIT(0x20, 0x20, IPT_BUTTON2) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON2) PORT_PLAYER(2)
389   PORT_BIT(0x40, 0x40, IPT_UNUSED)
390   PORT_BIT(0x80, 0x80, IPT_UNUSED)
391INPUT_PORTS_END
392
393
394
395static INPUT_PORTS_START( atari_digital_joystick4 )
396   PORT_START("djoy_0_1")   /* digital joystick #1 + #2 (PIA port A) */
397   PORT_BIT(0x01, 0x01, IPT_JOYSTICK_UP)    PORT_CODE(KEYCODE_8_PAD) PORT_CODE(JOYCODE_Y_UP_SWITCH)    PORT_PLAYER(1)
398   PORT_BIT(0x02, 0x02, IPT_JOYSTICK_DOWN)  PORT_CODE(KEYCODE_2_PAD) PORT_CODE(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(1)
399   PORT_BIT(0x04, 0x04, IPT_JOYSTICK_LEFT)  PORT_CODE(KEYCODE_4_PAD) PORT_CODE(JOYCODE_X_LEFT_SWITCH)  PORT_PLAYER(1)
400   PORT_BIT(0x08, 0x08, IPT_JOYSTICK_RIGHT) PORT_CODE(KEYCODE_6_PAD) PORT_CODE(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(1)
401   PORT_BIT(0x10, 0x10, IPT_JOYSTICK_UP)    PORT_CODE(KEYCODE_8_PAD) PORT_CODE(JOYCODE_Y_UP_SWITCH)    PORT_PLAYER(2)
402   PORT_BIT(0x20, 0x20, IPT_JOYSTICK_DOWN)  PORT_CODE(KEYCODE_2_PAD) PORT_CODE(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(2)
403   PORT_BIT(0x40, 0x40, IPT_JOYSTICK_LEFT)  PORT_CODE(KEYCODE_4_PAD) PORT_CODE(JOYCODE_X_LEFT_SWITCH)  PORT_PLAYER(2)
404   PORT_BIT(0x80, 0x80, IPT_JOYSTICK_RIGHT) PORT_CODE(KEYCODE_6_PAD) PORT_CODE(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(2)
405
406   PORT_START("djoy_2_3")   /* digital joystick #3 + #4 (PIA port B) */
407   PORT_BIT(0x01, 0x01, IPT_JOYSTICK_UP)    PORT_CODE(KEYCODE_8_PAD) PORT_CODE(JOYCODE_Y_UP_SWITCH)    PORT_PLAYER(3)
408   PORT_BIT(0x02, 0x02, IPT_JOYSTICK_DOWN)  PORT_CODE(KEYCODE_2_PAD) PORT_CODE(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(3)
409   PORT_BIT(0x04, 0x04, IPT_JOYSTICK_LEFT)  PORT_CODE(KEYCODE_4_PAD) PORT_CODE(JOYCODE_X_LEFT_SWITCH)  PORT_PLAYER(3)
410   PORT_BIT(0x08, 0x08, IPT_JOYSTICK_RIGHT) PORT_CODE(KEYCODE_6_PAD) PORT_CODE(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(3)
411   PORT_BIT(0x10, 0x10, IPT_JOYSTICK_UP)    PORT_CODE(KEYCODE_8_PAD) PORT_CODE(JOYCODE_Y_UP_SWITCH)    PORT_PLAYER(4)
412   PORT_BIT(0x20, 0x20, IPT_JOYSTICK_DOWN)  PORT_CODE(KEYCODE_2_PAD) PORT_CODE(JOYCODE_Y_DOWN_SWITCH)  PORT_PLAYER(4)
413   PORT_BIT(0x40, 0x40, IPT_JOYSTICK_LEFT)  PORT_CODE(KEYCODE_4_PAD) PORT_CODE(JOYCODE_X_LEFT_SWITCH)  PORT_PLAYER(4)
414   PORT_BIT(0x80, 0x80, IPT_JOYSTICK_RIGHT) PORT_CODE(KEYCODE_6_PAD) PORT_CODE(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(4)
415
416   PORT_START("djoy_b")   /* digital joystick buttons (GTIA button bits) */
417   PORT_BIT(0x01, 0x01, IPT_BUTTON1) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_PLAYER(1)
418   PORT_BIT(0x02, 0x02, IPT_BUTTON1) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON2) PORT_PLAYER(2)
419   PORT_BIT(0x04, 0x04, IPT_BUTTON1) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON3) PORT_PLAYER(3)
420   PORT_BIT(0x08, 0x08, IPT_BUTTON1) PORT_CODE(KEYCODE_0_PAD) PORT_CODE(JOYCODE_BUTTON4) PORT_PLAYER(4)
421   PORT_BIT(0x10, 0x10, IPT_BUTTON2) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON1) PORT_PLAYER(1)
422   PORT_BIT(0x20, 0x20, IPT_BUTTON2) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON2) PORT_PLAYER(2)
423   PORT_BIT(0x40, 0x40, IPT_BUTTON2) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON3) PORT_PLAYER(3)
424   PORT_BIT(0x80, 0x80, IPT_BUTTON2) PORT_CODE(KEYCODE_DEL_PAD) PORT_CODE(JOYCODE_BUTTON4) PORT_PLAYER(4)
425INPUT_PORTS_END
426
427
428
429/* 2009-04 FP:
430Small note about natural keyboard support: currently,
431- "Break" is mapped to 'F1'
432- "Clear" is mapped to 'F2'
433- "Atari" is mapped to 'F3'                         */
434
435static INPUT_PORTS_START( atari_keyboard )
436   PORT_START("keyboard_0")
437   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_L) PORT_CHAR('l') PORT_CHAR('L')
438   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_J) PORT_CHAR('j') PORT_CHAR('J')
439   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_COLON) PORT_CHAR(';') PORT_CHAR(':')
440   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Break") PORT_CODE(KEYCODE_BACKSPACE) PORT_CHAR(UCHAR_MAMEKEY(F1))
441   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_UNUSED)
442   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_K) PORT_CHAR('k') PORT_CHAR('K')
443   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR('+') PORT_CHAR('\\')
444   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH) PORT_CHAR('*') PORT_CHAR('^')
445
446   PORT_START("keyboard_1")
447   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_O) PORT_CHAR('o') PORT_CHAR('O')
448   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) // None!
449   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_P) PORT_CHAR('p') PORT_CHAR('P')
450   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_U) PORT_CHAR('u') PORT_CHAR('U')
451   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Return") PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)
452   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_I) PORT_CHAR('i') PORT_CHAR('I')
453   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_OPENBRACE) PORT_CHAR('-') PORT_CHAR('_')
454   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_CLOSEBRACE) PORT_CHAR('=') PORT_CHAR('|')
455
456   PORT_START("keyboard_2")
457   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_V) PORT_CHAR('v') PORT_CHAR('V')
458   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_UNUSED)
459   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_C) PORT_CHAR('c') PORT_CHAR('C')
460   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_UNUSED)
461   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_UNUSED)
462   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_B) PORT_CHAR('b') PORT_CHAR('B')
463   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_X) PORT_CHAR('x') PORT_CHAR('X')
464   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_Z) PORT_CHAR('z') PORT_CHAR('Z')
465
466   PORT_START("keyboard_3")
467   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')
468   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_UNUSED)
469   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')
470   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('&')
471   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Escape") PORT_CODE(KEYCODE_ESC) PORT_CHAR(27)
472   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')
473   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('\"')
474   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')
475
476   PORT_START("keyboard_4")
477   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA) PORT_CHAR(',') PORT_CHAR('[')
478   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_SPACE) PORT_CHAR(' ')
479   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP) PORT_CHAR('.') PORT_CHAR(']')
480   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_N) PORT_CHAR('n') PORT_CHAR('N')
481   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_UNUSED)
482   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_M) PORT_CHAR('m') PORT_CHAR('M')
483   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH) PORT_CHAR('/') PORT_CHAR('?')
484   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Atari") PORT_CODE(KEYCODE_RCONTROL) PORT_CHAR(UCHAR_MAMEKEY(F3))
485
486   PORT_START("keyboard_5")
487   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_R) PORT_CHAR('r') PORT_CHAR('R')
488   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_UNUSED)
489   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_E) PORT_CHAR('e') PORT_CHAR('E')
490   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_Y) PORT_CHAR('y') PORT_CHAR('Y')
491   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_TAB) PORT_CHAR(UCHAR_MAMEKEY(TAB))
492   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_T) PORT_CHAR('t') PORT_CHAR('T')
493   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_W) PORT_CHAR('w') PORT_CHAR('W')
494   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_Q) PORT_CHAR('q') PORT_CHAR('Q')
495
496   PORT_START("keyboard_6")
497   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_9) PORT_CHAR('9') PORT_CHAR('(')
498   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_UNUSED)
499   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_0) PORT_CHAR('0') PORT_CHAR(')')
500   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('\'')
501   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("BackS  Delete") PORT_CODE(KEYCODE_BACKSLASH2) PORT_CHAR(8) PORT_CHAR(UCHAR_MAMEKEY(DEL))
502   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_CHAR('@')
503   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("<  Clear") PORT_CODE(KEYCODE_MINUS) PORT_CHAR('<') PORT_CHAR(UCHAR_MAMEKEY(F2))
504   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME(">  Insert") PORT_CODE(KEYCODE_EQUALS) PORT_CHAR('>') PORT_CHAR(UCHAR_MAMEKEY(INSERT))
505
506   PORT_START("keyboard_7")
507   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_F) PORT_CHAR('f') PORT_CHAR('F')
508   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_H) PORT_CHAR('h') PORT_CHAR('H')
509   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_D) PORT_CHAR('d') PORT_CHAR('D')
510   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_UNUSED)
511   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Caps") PORT_CODE(KEYCODE_CAPSLOCK) PORT_TOGGLE PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
512   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_G) PORT_CHAR('g') PORT_CHAR('G')
513   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_S) PORT_CHAR('s') PORT_CHAR('S')
514   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_A) PORT_CHAR('a') PORT_CHAR('A')
515
516   PORT_START("fake")
517   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Shift") PORT_CODE(KEYCODE_LSHIFT) PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1)
518   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Ctrl") PORT_CODE(KEYCODE_LCONTROL) PORT_CHAR(UCHAR_SHIFT_2)
519INPUT_PORTS_END
520
521
522static INPUT_PORTS_START( atari_analog_paddles )
523   PORT_START("analog_0") /* IN8 analog in #1 */
524   PORT_BIT(0xff, 0x74, IPT_PADDLE) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(1) PORT_REVERSE
525
526   PORT_START("analog_1") /* IN9 analog in #2 */
527   PORT_BIT(0xff, 0x74, IPT_PADDLE) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(2) PORT_REVERSE
528
529   PORT_START("analog_2") /* IN10 analog in #3 */
530   PORT_BIT(0xff, 0x74, IPT_PADDLE) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(3) PORT_REVERSE
531
532   PORT_START("analog_3") /* IN11 analog in #4 */
533   PORT_BIT(0xff, 0x74, IPT_PADDLE) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(4) PORT_REVERSE
534
535   PORT_START("analog_4") /* IN12 analog in #5 */
536   PORT_BIT(0xff, 0x74, IPT_PADDLE) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_REVERSE /* PORT_PLAYER(5) */
537
538   PORT_START("analog_5") /* IN13 analog in #6 */
539   PORT_BIT(0xff, 0x74, IPT_PADDLE) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_REVERSE /* PORT_PLAYER(6) */
540
541   PORT_START("analog_6") /* IN14 analog in #7 */
542   PORT_BIT(0xff, 0x74, IPT_PADDLE) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_REVERSE /* PORT_PLAYER(7) */
543
544   PORT_START("analog_7") /* IN15 analog in #8 */
545   PORT_BIT(0xff, 0x74, IPT_PADDLE) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_REVERSE /* PORT_PLAYER(8) */
546INPUT_PORTS_END
547
548
549
550static INPUT_PORTS_START( a800 )
551   PORT_INCLUDE( atari_artifacting )
552   PORT_INCLUDE( atari_console )
553   PORT_INCLUDE( atari_digital_joystick4 )
554   PORT_INCLUDE( atari_keyboard )
555   PORT_INCLUDE( atari_analog_paddles )
556INPUT_PORTS_END
557
558
559
560static INPUT_PORTS_START( a800xl )
561   PORT_INCLUDE( atari_artifacting )
562   PORT_INCLUDE( atari_console )
563   PORT_INCLUDE( atari_digital_joystick2 )
564   PORT_INCLUDE( atari_keyboard )
565   PORT_INCLUDE( atari_analog_paddles )
566INPUT_PORTS_END
567
568
569
570static INPUT_PORTS_START( a5200 )
571   PORT_INCLUDE( atari_artifacting )
572
573   PORT_START("djoy_b")   /* lower/upper buttons */
574   PORT_BIT(0x01, 0x01, IPT_BUTTON1) PORT_PLAYER(1)
575   PORT_BIT(0x02, 0x02, IPT_BUTTON1) PORT_PLAYER(2)
576   PORT_BIT(0x04, 0x04, IPT_BUTTON1) PORT_PLAYER(3)
577   PORT_BIT(0x08, 0x08, IPT_BUTTON1) PORT_PLAYER(4)
578   PORT_BIT(0x10, 0x10, IPT_BUTTON2) PORT_PLAYER(1)
579   PORT_BIT(0x20, 0x20, IPT_BUTTON2) PORT_PLAYER(2)
580   PORT_BIT(0x40, 0x40, IPT_BUTTON2) PORT_PLAYER(3)
581   PORT_BIT(0x80, 0x80, IPT_BUTTON2) PORT_PLAYER(4)
582
583   PORT_START("keypad_0")
584   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("(Break)") PORT_CODE(KEYCODE_PAUSE)   // is this correct?
585   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[#]") PORT_CODE(KEYCODE_ENTER_PAD)
586   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[0]") PORT_CODE(KEYCODE_0_PAD)
587   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[*]") PORT_CODE(KEYCODE_PLUS_PAD)
588   PORT_BIT(0xf0, IP_ACTIVE_HIGH, IPT_UNUSED)
589
590   PORT_START("keypad_1")
591   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("Reset") PORT_CODE(KEYCODE_F3)
592   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[9]") PORT_CODE(KEYCODE_9_PAD)
593   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[8]") PORT_CODE(KEYCODE_8_PAD)
594   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[7]") PORT_CODE(KEYCODE_7_PAD)
595   PORT_BIT(0xf0, IP_ACTIVE_HIGH, IPT_UNUSED)
596
597   PORT_START("keypad_2")
598   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME(DEF_STR(Pause)) PORT_CODE(KEYCODE_F2)
599   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[6]") PORT_CODE(KEYCODE_6_PAD)
600   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[5]") PORT_CODE(KEYCODE_5_PAD)
601   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[4]") PORT_CODE(KEYCODE_4_PAD)
602   PORT_BIT(0xf0, IP_ACTIVE_HIGH, IPT_UNUSED)
603
604   PORT_START("keypad_3")
605   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_START)    PORT_NAME("Start")
606   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[3]") PORT_CODE(KEYCODE_3_PAD)
607   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[2]") PORT_CODE(KEYCODE_2_PAD)
608   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_NAME("[1]") PORT_CODE(KEYCODE_1_PAD)
609   PORT_BIT(0xf0, IP_ACTIVE_HIGH, IPT_UNUSED)
610
611   PORT_START("analog_0")
612   PORT_BIT(0xff, 0x72, IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(1)
613
614   PORT_START("analog_1")
615   PORT_BIT(0xff, 0x72, IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(1)
616
617   PORT_START("analog_2")
618   PORT_BIT(0xff, 0x72, IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(2)
619
620   PORT_START("analog_3")
621   PORT_BIT(0xff, 0x72, IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(2)
622
623   PORT_START("analog_4")
624   PORT_BIT(0xff, 0x72, IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(3)
625
626   PORT_START("analog_5")
627   PORT_BIT(0xff, 0x72, IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(3)
628
629   PORT_START("analog_6")
630   PORT_BIT(0xff, 0x72, IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(4)
631
632   PORT_START("analog_7")
633   PORT_BIT(0xff, 0x72, IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0x00,0xe4) PORT_PLAYER(4)
634
635INPUT_PORTS_END
636
637
638/**************************************************************
639 *
640 * Palette
641 *
642 **************************************************************/
643
644static const UINT8 atari_palette[256*3] =
645{
646   /* Grey */
647   0x00,0x00,0x00, 0x25,0x25,0x25, 0x34,0x34,0x34, 0x4e,0x4e,0x4e,
648   0x68,0x68,0x68, 0x75,0x75,0x75, 0x8e,0x8e,0x8e, 0xa4,0xa4,0xa4,
649   0xb8,0xb8,0xb8, 0xc5,0xc5,0xc5, 0xd0,0xd0,0xd0, 0xd7,0xd7,0xd7,
650   0xe1,0xe1,0xe1, 0xea,0xea,0xea, 0xf4,0xf4,0xf4, 0xff,0xff,0xff,
651   /* Gold */
652   0x41,0x20,0x00, 0x54,0x28,0x00, 0x76,0x37,0x00, 0x9a,0x50,0x00,
653   0xc3,0x68,0x06, 0xe4,0x7b,0x07, 0xff,0x91,0x1a, 0xff,0xab,0x1d,
654   0xff,0xc5,0x1f, 0xff,0xd0,0x3b, 0xff,0xd8,0x4c, 0xff,0xe6,0x51,
655   0xff,0xf4,0x56, 0xff,0xf9,0x70, 0xff,0xff,0x90, 0xff,0xff,0xaa,
656   /* Orange */
657   0x45,0x19,0x04, 0x72,0x1e,0x11, 0x9f,0x24,0x1e, 0xb3,0x3a,0x20,
658   0xc8,0x51,0x20, 0xe3,0x69,0x20, 0xfc,0x81,0x20, 0xfd,0x8c,0x25,
659   0xfe,0x98,0x2c, 0xff,0xae,0x38, 0xff,0xb9,0x46, 0xff,0xbf,0x51,
660   0xff,0xc6,0x6d, 0xff,0xd5,0x87, 0xff,0xe4,0x98, 0xff,0xe6,0xab,
661   /* Red-Orange */
662   0x5d,0x1f,0x0c, 0x7a,0x24,0x0d, 0x98,0x2c,0x0e, 0xb0,0x2f,0x0f,
663   0xbf,0x36,0x24, 0xd3,0x4e,0x2a, 0xe7,0x62,0x3e, 0xf3,0x6e,0x4a,
664   0xfd,0x78,0x54, 0xff,0x8a,0x6a, 0xff,0x98,0x7c, 0xff,0xa4,0x8b,
665   0xff,0xb3,0x9e, 0xff,0xc2,0xb2, 0xff,0xd0,0xc3, 0xff,0xda,0xd0,
666   /* Pink */
667   0x4a,0x17,0x00, 0x72,0x1f,0x00, 0xa8,0x13,0x00, 0xc8,0x21,0x0a,
668   0xdf,0x25,0x12, 0xec,0x3b,0x24, 0xfa,0x52,0x36, 0xfc,0x61,0x48,
669   0xff,0x70,0x5f, 0xff,0x7e,0x7e, 0xff,0x8f,0x8f, 0xff,0x9d,0x9e,
670   0xff,0xab,0xad, 0xff,0xb9,0xbd, 0xff,0xc7,0xce, 0xff,0xca,0xde,
671   /* Purple */
672   0x49,0x00,0x36, 0x66,0x00,0x4b, 0x80,0x03,0x5f, 0x95,0x0f,0x74,
673   0xaa,0x22,0x88, 0xba,0x3d,0x99, 0xca,0x4d,0xa9, 0xd7,0x5a,0xb6,
674   0xe4,0x67,0xc3, 0xef,0x72,0xce, 0xfb,0x7e,0xda, 0xff,0x8d,0xe1,
675   0xff,0x9d,0xe5, 0xff,0xa5,0xe7, 0xff,0xaf,0xea, 0xff,0xb8,0xec,
676   /* Purple-Blue */
677   0x48,0x03,0x6c, 0x5c,0x04,0x88, 0x65,0x0d,0x90, 0x7b,0x23,0xa7,
678   0x93,0x3b,0xbf, 0x9d,0x45,0xc9, 0xa7,0x4f,0xd3, 0xb2,0x5a,0xde,
679   0xbd,0x65,0xe9, 0xc5,0x6d,0xf1, 0xce,0x76,0xfa, 0xd5,0x83,0xff,
680   0xda,0x90,0xff, 0xde,0x9c,0xff, 0xe2,0xa9,0xff, 0xe6,0xb6,0xff,
681   /* Blue 1 */
682   0x05,0x1e,0x81, 0x06,0x26,0xa5, 0x08,0x2f,0xca, 0x26,0x3d,0xd4,
683   0x44,0x4c,0xde, 0x4f,0x5a,0xec, 0x5a,0x68,0xff, 0x65,0x75,0xff,
684   0x71,0x83,0xff, 0x80,0x91,0xff, 0x90,0xa0,0xff, 0x97,0xa9,0xff,
685   0x9f,0xb2,0xff, 0xaf,0xbe,0xff, 0xc0,0xcb,0xff, 0xcd,0xd3,0xff,
686   /* Blue 2 */
687   0x0b,0x07,0x79, 0x20,0x1c,0x8e, 0x35,0x31,0xa3, 0x46,0x42,0xb4,
688   0x57,0x53,0xc5, 0x61,0x5d,0xcf, 0x6d,0x69,0xdb, 0x7b,0x77,0xe9,
689   0x89,0x85,0xf7, 0x91,0x8d,0xff, 0x9c,0x98,0xff, 0xa7,0xa4,0xff,
690   0xb2,0xaf,0xff, 0xbb,0xb8,0xff, 0xc3,0xc1,0xff, 0xd3,0xd1,0xff,
691   /* Light-Blue */
692   0x1d,0x29,0x5a, 0x1d,0x38,0x76, 0x1d,0x48,0x92, 0x1d,0x5c,0xac,
693   0x1d,0x71,0xc6, 0x32,0x86,0xcf, 0x48,0x9b,0xd9, 0x4e,0xa8,0xec,
694   0x55,0xb6,0xff, 0x69,0xca,0xff, 0x74,0xcb,0xff, 0x82,0xd3,0xff,
695   0x8d,0xda,0xff, 0x9f,0xd4,0xff, 0xb4,0xe2,0xff, 0xc0,0xeb,0xff,
696   /* Turquoise */
697   0x00,0x4b,0x59, 0x00,0x5d,0x6e, 0x00,0x6f,0x84, 0x00,0x84,0x9c,
698   0x00,0x99,0xbf, 0x00,0xab,0xca, 0x00,0xbc,0xde, 0x00,0xd0,0xf5,
699   0x10,0xdc,0xff, 0x3e,0xe1,0xff, 0x64,0xe7,0xff, 0x76,0xea,0xff,
700   0x8b,0xed,0xff, 0x9a,0xef,0xff, 0xb1,0xf3,0xff, 0xc7,0xf6,0xff,
701   /* Green-Blue */
702   0x00,0x48,0x00, 0x00,0x54,0x00, 0x03,0x6b,0x03, 0x0e,0x76,0x0e,
703   0x18,0x80,0x18, 0x27,0x92,0x27, 0x36,0xa4,0x36, 0x4e,0xb9,0x4e,
704   0x51,0xcd,0x51, 0x72,0xda,0x72, 0x7c,0xe4,0x7c, 0x85,0xed,0x85,
705   0x99,0xf2,0x99, 0xb3,0xf7,0xb3, 0xc3,0xf9,0xc3, 0xcd,0xfc,0xcd,
706   /* Green */
707   0x16,0x40,0x00, 0x1c,0x53,0x00, 0x23,0x66,0x00, 0x28,0x78,0x00,
708   0x2e,0x8c,0x00, 0x3a,0x98,0x0c, 0x47,0xa5,0x19, 0x51,0xaf,0x23,
709   0x5c,0xba,0x2e, 0x71,0xcf,0x43, 0x85,0xe3,0x57, 0x8d,0xeb,0x5f,
710   0x97,0xf5,0x69, 0xa0,0xfe,0x72, 0xb1,0xff,0x8a, 0xbc,0xff,0x9a,
711   /* Yellow-Green */
712   0x2c,0x35,0x00, 0x38,0x44,0x00, 0x44,0x52,0x00, 0x49,0x56,0x00,
713   0x60,0x71,0x00, 0x6c,0x7f,0x00, 0x79,0x8d,0x0a, 0x8b,0x9f,0x1c,
714   0x9e,0xb2,0x2f, 0xab,0xbf,0x3c, 0xb8,0xcc,0x49, 0xc2,0xd6,0x53,
715   0xcd,0xe1,0x53, 0xdb,0xef,0x6c, 0xe8,0xfc,0x79, 0xf2,0xff,0xab,
716   /* Orange-Green */
717   0x46,0x3a,0x09, 0x4d,0x3f,0x09, 0x54,0x45,0x09, 0x6c,0x58,0x09,
718   0x90,0x76,0x09, 0xab,0x8b,0x0a, 0xc1,0xa1,0x20, 0xd0,0xb0,0x2f,
719   0xde,0xbe,0x3d, 0xe6,0xc6,0x45, 0xed,0xcd,0x4c, 0xf5,0xd8,0x62,
720   0xfb,0xe2,0x76, 0xfc,0xee,0x98, 0xfd,0xf3,0xa9, 0xfd,0xf3,0xbe,
721   /* Light-Orange */
722   0x40,0x1a,0x02, 0x58,0x1f,0x05, 0x70,0x24,0x08, 0x8d,0x3a,0x13,
723   0xab,0x51,0x1f, 0xb5,0x64,0x27, 0xbf,0x77,0x30, 0xd0,0x85,0x3a,
724   0xe1,0x93,0x44, 0xed,0xa0,0x4e, 0xf9,0xad,0x58, 0xfc,0xb7,0x5c,
725   0xff,0xc1,0x60, 0xff,0xca,0x69, 0xff,0xcf,0x7e, 0xff,0xda,0x96
726};
727
728
729/* Initialise the palette */
730static PALETTE_INIT( mess_atari )
731{
732   int i;
733
734   for ( i = 0; i < sizeof(atari_palette) / 3; i++ )
735   {
736      palette_set_color_rgb(machine, i, atari_palette[i*3], atari_palette[i*3+1], atari_palette[i*3+2]);
737   }
738}
739
740/**************************************************************
741 *
742 * Memory banking
743 *
744 **************************************************************/
745
746static void a800xl_mmu(running_machine &machine, UINT8 new_mmu)
747{
748   UINT8 *base = machine.region("maincpu")->base();
749   UINT8 *base1, *base2, *base3, *base4;
750
751   /* check if memory C000-FFFF changed */
752   if( new_mmu & 0x01 )
753   {
754      logerror("%s MMU BIOS ROM\n", machine.system().name);
755      base3 = base + 0x14000;  /* 8K lo BIOS */
756      base4 = base + 0x15800;  /* 4K FP ROM + 8K hi BIOS */
757      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xc000, 0xcfff, "bank3");
758      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xc000, 0xcfff);
759      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xd800, 0xffff, "bank4");
760      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xd800, 0xffff);
761   }
762   else
763   {
764      logerror("%s MMU BIOS RAM\n", machine.system().name);
765      base3 = base + 0x0c000;  /* 8K RAM */
766      base4 = base + 0x0d800;  /* 4K RAM + 8K RAM */
767      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0xc000, 0xcfff, "bank3");
768      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0xd800, 0xffff, "bank4");
769   }
770   memory_set_bankptr(machine, "bank3", base3);
771   memory_set_bankptr(machine, "bank4", base4);
772
773   /* check if BASIC changed */
774   if( new_mmu & 0x02 )
775   {
776      logerror("%s MMU BASIC RAM\n", machine.system().name);
777      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0xa000, 0xbfff, "bank1");
778      base1 = base + 0x0a000;  /* 8K RAM */
779   }
780   else
781   {
782      logerror("%s MMU BASIC ROM\n", machine.system().name);
783      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xa000, 0xbfff, "bank1");
784      machine.device("maincpu")->memory().space(AS_PROGRAM)->nop_write(0xa000, 0xbfff);
785      base1 = base + 0x10000;  /* 8K BASIC */
786   }
787
788   memory_set_bankptr(machine, "bank1", base1);
789
790   /* check if self-test ROM changed */
791   if( new_mmu & 0x80 )
792   {
793      logerror("%s MMU SELFTEST RAM\n", machine.system().name);
794      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0x5000, 0x57ff, "bank2");
795      base2 = base + 0x05000;  /* 0x0800 bytes */
796   }
797   else
798   {
799      logerror("%s MMU SELFTEST ROM\n", machine.system().name);
800      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x5000, 0x57ff, "bank2");
801      machine.device("maincpu")->memory().space(AS_PROGRAM)->nop_write(0x5000, 0x57ff);
802      base2 = base + 0x15000;  /* 0x0800 bytes */
803   }
804   memory_set_bankptr(machine, "bank2", base2);
805}
806
807/* BASIC was available in a separate cart, so we don't test it */
808static void a1200xl_mmu(running_machine &machine, UINT8 new_mmu)
809{
810   UINT8 *base = machine.region("maincpu")->base();
811   UINT8 *base2, *base3, *base4;
812
813   /* check if memory C000-FFFF changed */
814   if( new_mmu & 0x01 )
815   {
816      logerror("%s MMU BIOS ROM\n", machine.system().name);
817      base3 = base + 0x14000;  /* 8K lo BIOS */
818      base4 = base + 0x15800;  /* 4K FP ROM + 8K hi BIOS */
819      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xc000, 0xcfff, "bank3");
820      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xc000, 0xcfff);
821      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xd800, 0xffff, "bank4");
822      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xd800, 0xffff);
823   }
824   else
825   {
826      logerror("%s MMU BIOS RAM\n", machine.system().name);
827      base3 = base + 0x0c000;  /* 8K RAM */
828      base4 = base + 0x0d800;  /* 4K RAM + 8K RAM */
829      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0xc000, 0xcfff, "bank3");
830      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0xd800, 0xffff, "bank4");
831   }
832   memory_set_bankptr(machine, "bank3", base3);
833   memory_set_bankptr(machine, "bank4", base4);
834
835   /* check if self-test ROM changed */
836   if( new_mmu & 0x80 )
837   {
838      logerror("%s MMU SELFTEST RAM\n", machine.system().name);
839      base2 = base + 0x05000;  /* 0x0800 bytes */
840      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0x5000, 0x57ff, "bank2");
841   }
842   else
843   {
844      logerror("%s MMU SELFTEST ROM\n", machine.system().name);
845      base2 = base + 0x15000;  /* 0x0800 bytes */
846      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x5000, 0x57ff, "bank2");
847      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0x5000, 0x57ff);
848   }
849   memory_set_bankptr(machine, "bank2", base2);
850}
851
852static void xegs_mmu(running_machine &machine, UINT8 new_mmu)
853{
854   UINT8 *base = machine.region("maincpu")->base();
855   UINT8 *base2, *base3, *base4;
856
857   /* check if memory C000-FFFF changed */
858   if( new_mmu & 0x01 )
859   {
860      logerror("%s MMU BIOS ROM\n", machine.system().name);
861      base3 = base + 0x14000;  /* 8K lo BIOS */
862      base4 = base + 0x15800;  /* 4K FP ROM + 8K hi BIOS */
863      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xc000, 0xcfff, "bank3");
864      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xc000, 0xcfff);
865      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0xd800, 0xffff, "bank4");
866      machine.device("maincpu")->memory().space(AS_PROGRAM)->unmap_write(0xd800, 0xffff);
867   }
868   else
869   {
870      logerror("%s MMU BIOS RAM\n", machine.system().name);
871      base3 = base + 0x0c000;  /* 8K RAM */
872      base4 = base + 0x0d800;  /* 4K RAM + 8K RAM */
873      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0xc000, 0xcfff, "bank3");
874      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0xd800, 0xffff, "bank4");
875   }
876   memory_set_bankptr(machine, "bank3", base3);
877   memory_set_bankptr(machine, "bank4", base4);
878
879
880   /* check if self-test ROM changed */
881   if( new_mmu & 0x80 )
882   {
883      logerror("%s MMU SELFTEST RAM\n", machine.system().name);
884      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_readwrite_bank(0x5000, 0x57ff, "bank2");
885      base2 = base + 0x05000;  /* 0x0800 bytes */
886   }
887   else
888   {
889      logerror("%s MMU SELFTEST ROM\n", machine.system().name);
890      machine.device("maincpu")->memory().space(AS_PROGRAM)->install_read_bank(0x5000, 0x57ff, "bank2");
891      machine.device("maincpu")->memory().space(AS_PROGRAM)->nop_write(0x5000, 0x57ff);
892      base2 = base + 0x15000;  /* 0x0800 bytes */
893   }
894   memory_set_bankptr(machine, "bank2", base2);
895}
896
897/**************************************************************
898 *
899 * PIA interface
900 *
901 **************************************************************/
902
903static WRITE8_DEVICE_HANDLER(a1200xl_pia_pb_w) { a1200xl_mmu(device->machine(), data); }
904static WRITE8_DEVICE_HANDLER(a800xl_pia_pb_w)
905{
906   if (downcast<pia6821_device *>(device)->port_b_z_mask() != 0xff)
907      a800xl_mmu(device->machine(), data);
908}
909
910static WRITE8_DEVICE_HANDLER(xegs_pia_pb_w)
911{
912   if (downcast<pia6821_device *>(device)->port_b_z_mask() != 0xff)
913      xegs_mmu(device->machine(), data);
914}
915
916static const pokey_interface atari_pokey_interface =
917{
918   {
919      DEVCB_INPUT_PORT("analog_0"),
920      DEVCB_INPUT_PORT("analog_1"),
921      DEVCB_INPUT_PORT("analog_2"),
922      DEVCB_INPUT_PORT("analog_3"),
923      DEVCB_INPUT_PORT("analog_4"),
924      DEVCB_INPUT_PORT("analog_5"),
925      DEVCB_INPUT_PORT("analog_6"),
926      DEVCB_INPUT_PORT("analog_7")
927   },
928   DEVCB_NULL,
929   DEVCB_DEVICE_HANDLER("fdc", atari_serin_r),
930   DEVCB_DEVICE_HANDLER("fdc", atari_serout_w),
931   atari_interrupt_cb,
932};
933
934
935static const pia6821_interface atari_pia_interface =
936{
937   DEVCB_HANDLER(atari_pia_pa_r),      /* port A in */
938   DEVCB_HANDLER(atari_pia_pb_r),   /* port B in */
939   DEVCB_NULL,      /* line CA1 in */
940   DEVCB_NULL,      /* line CB1 in */
941   DEVCB_NULL,      /* line CA2 in */
942   DEVCB_NULL,      /* line CB2 in */
943   DEVCB_NULL,      /* port A out */
944   DEVCB_NULL,      /* port B out */
945   DEVCB_NULL,      /* line CA2 out */
946   DEVCB_DEVICE_LINE("fdc",atarifdc_pia_cb2_w),      /* port CB2 out */
947   DEVCB_NULL,      /* IRQA */
948   DEVCB_NULL      /* IRQB */
949};
950
951static const pia6821_interface a600xl_pia_interface =
952{
953   DEVCB_HANDLER(atari_pia_pa_r),      /* port A in */
954   DEVCB_HANDLER(atari_pia_pb_r),   /* port B in */
955   DEVCB_NULL,      /* line CA1 in */
956   DEVCB_NULL,      /* line CB1 in */
957   DEVCB_NULL,      /* line CA2 in */
958   DEVCB_NULL,      /* line CB2 in */
959   DEVCB_NULL,      /* port A out */
960   DEVCB_HANDLER(a600xl_pia_pb_w),      /* port B out */
961   DEVCB_NULL,      /* line CA2 out */
962   DEVCB_DEVICE_LINE("fdc",atarifdc_pia_cb2_w),      /* port CB2 out */
963   DEVCB_NULL,      /* IRQA */
964   DEVCB_NULL      /* IRQB */
965};
966
967static const pia6821_interface a1200xl_pia_interface =
968{
969   DEVCB_HANDLER(atari_pia_pa_r),      /* port A in */
970   DEVCB_HANDLER(atari_pia_pb_r),   /* port B in */
971   DEVCB_NULL,      /* line CA1 in */
972   DEVCB_NULL,      /* line CB1 in */
973   DEVCB_NULL,      /* line CA2 in */
974   DEVCB_NULL,      /* line CB2 in */
975   DEVCB_NULL,      /* port A out */
976   DEVCB_HANDLER(a1200xl_pia_pb_w),      /* port B out */
977   DEVCB_NULL,      /* line CA2 out */
978   DEVCB_DEVICE_LINE("fdc",atarifdc_pia_cb2_w),      /* port CB2 out */
979   DEVCB_NULL,      /* IRQA */
980   DEVCB_NULL      /* IRQB */
981};
982
983static const pia6821_interface a800xl_pia_interface =
984{
985   DEVCB_HANDLER(atari_pia_pa_r),      /* port A in */
986   DEVCB_HANDLER(atari_pia_pb_r),   /* port B in */
987   DEVCB_NULL,      /* line CA1 in */
988   DEVCB_NULL,      /* line CB1 in */
989   DEVCB_NULL,      /* line CA2 in */
990   DEVCB_NULL,      /* line CB2 in */
991   DEVCB_NULL,      /* port A out */
992   DEVCB_HANDLER(a800xl_pia_pb_w),      /* port B out */
993   DEVCB_NULL,      /* line CA2 out */
994   DEVCB_DEVICE_LINE("fdc",atarifdc_pia_cb2_w),      /* port CB2 out */
995   DEVCB_NULL,      /* IRQA */
996   DEVCB_NULL      /* IRQB */
997};
998
999static const pia6821_interface xegs_pia_interface =
1000{
1001   DEVCB_HANDLER(atari_pia_pa_r),      /* port A in */
1002   DEVCB_HANDLER(atari_pia_pb_r),   /* port B in */
1003   DEVCB_NULL,      /* line CA1 in */
1004   DEVCB_NULL,      /* line CB1 in */
1005   DEVCB_NULL,      /* line CA2 in */
1006   DEVCB_NULL,      /* line CB2 in */
1007   DEVCB_NULL,      /* port A out */
1008   DEVCB_HANDLER(xegs_pia_pb_w),      /* port B out */
1009   DEVCB_NULL,      /* line CA2 out */
1010   DEVCB_DEVICE_LINE("fdc",atarifdc_pia_cb2_w),      /* port CB2 out */
1011   DEVCB_NULL,      /* IRQA */
1012   DEVCB_NULL      /* IRQB */
1013};
1014
1015// FIXME: should there be anything connected where other system have the fdc?
1016static const pokey_interface a5200_pokey_interface =
1017{
1018   {
1019      DEVCB_INPUT_PORT("analog_0"),
1020      DEVCB_INPUT_PORT("analog_1"),
1021      DEVCB_INPUT_PORT("analog_2"),
1022      DEVCB_INPUT_PORT("analog_3"),
1023      DEVCB_INPUT_PORT("analog_4"),
1024      DEVCB_INPUT_PORT("analog_5"),
1025      DEVCB_INPUT_PORT("analog_6"),
1026      DEVCB_INPUT_PORT("analog_7")
1027   },
1028   DEVCB_NULL,
1029   DEVCB_NULL,   // FIXME: is there anything connected here?
1030   DEVCB_NULL,   // FIXME: is there anything connected here?
1031   atari_interrupt_cb,
1032};
1033
1034static const pia6821_interface a5200_pia_interface =
1035{
1036   DEVCB_HANDLER(atari_pia_pa_r),      /* port A in */
1037   DEVCB_HANDLER(atari_pia_pb_r),   /* port B in */
1038   DEVCB_NULL,      /* line CA1 in */
1039   DEVCB_NULL,      /* line CB1 in */
1040   DEVCB_NULL,      /* line CA2 in */
1041   DEVCB_NULL,      /* line CB2 in */
1042   DEVCB_NULL,      /* port A out */
1043   DEVCB_NULL,      /* port B out */
1044   DEVCB_NULL,      /* line CA2 out */
1045   DEVCB_NULL,      /* port CB2 out */   // FIXME: is there anything connected here
1046   DEVCB_NULL,      /* IRQA */
1047   DEVCB_NULL      /* IRQB */
1048};
1049
1050
1051/**************************************************************
1052 *
1053 * Machine drivers
1054 *
1055 **************************************************************/
1056
1057static MACHINE_CONFIG_FRAGMENT( a400_cartslot )
1058   MCFG_CARTSLOT_ADD("cart1")
1059   MCFG_CARTSLOT_EXTENSION_LIST("rom,bin")
1060   MCFG_CARTSLOT_NOT_MANDATORY
1061   MCFG_CARTSLOT_LOAD(a800_cart)
1062   MCFG_CARTSLOT_UNLOAD(a800_cart)
1063   MCFG_CARTSLOT_INTERFACE("a800_cart")
1064MACHINE_CONFIG_END
1065
1066static MACHINE_CONFIG_FRAGMENT( a800_cartslot )
1067   MCFG_CARTSLOT_ADD("cart1")
1068   MCFG_CARTSLOT_EXTENSION_LIST("rom,bin")
1069   MCFG_CARTSLOT_NOT_MANDATORY
1070   MCFG_CARTSLOT_LOAD(a800_cart)
1071   MCFG_CARTSLOT_UNLOAD(a800_cart)
1072   MCFG_CARTSLOT_INTERFACE("a800_cart")
1073
1074   MCFG_CARTSLOT_ADD("cart2")
1075   MCFG_CARTSLOT_EXTENSION_LIST("rom,bin")
1076   MCFG_CARTSLOT_NOT_MANDATORY
1077   MCFG_CARTSLOT_LOAD(a800_cart_right)
1078   MCFG_CARTSLOT_UNLOAD(a800_cart_right)
1079   MCFG_CARTSLOT_INTERFACE("a800_cart")
1080MACHINE_CONFIG_END
1081
1082static MACHINE_CONFIG_START( atari_common_nodac, driver_device )
1083   /* basic machine hardware */
1084   MCFG_CPU_ADD("maincpu", M6502, FREQ_17_EXACT)
1085
1086   /* video hardware */
1087   MCFG_SCREEN_ADD("screen", RASTER)
1088   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(1))
1089   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
1090   MCFG_SCREEN_VISIBLE_AREA(MIN_X, MAX_X, MIN_Y, MAX_Y)
1091   MCFG_PALETTE_LENGTH(sizeof(atari_palette) / 3)
1092   MCFG_PALETTE_INIT(mess_atari)
1093   MCFG_SCREEN_UPDATE(atari)
1094
1095   MCFG_VIDEO_START(atari)
1096
1097   MCFG_PIA6821_ADD( "pia", atari_pia_interface )
1098
1099   /* sound hardware */
1100   MCFG_SPEAKER_STANDARD_MONO("mono")
1101   MCFG_SOUND_ADD("pokey", POKEY, FREQ_17_EXACT)
1102   MCFG_SOUND_CONFIG(atari_pokey_interface)
1103   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
1104
1105   /* internal ram */
1106   MCFG_RAM_ADD(RAM_TAG)
1107   MCFG_RAM_DEFAULT_SIZE("40K")
1108MACHINE_CONFIG_END
1109
1110
1111static MACHINE_CONFIG_DERIVED( atari_common, atari_common_nodac )
1112   MCFG_SOUND_ADD("dac", DAC, 0)
1113   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
1114
1115   MCFG_ATARI_FDC_ADD("fdc")
1116MACHINE_CONFIG_END
1117
1118
1119static MACHINE_CONFIG_DERIVED( a400, atari_common )
1120
1121   MCFG_CPU_MODIFY( "maincpu" )
1122   MCFG_CPU_PROGRAM_MAP(a400_mem)
1123   MCFG_CPU_VBLANK_INT_HACK(a400_interrupt, TOTAL_LINES_60HZ)
1124
1125   MCFG_MACHINE_START( a400 )
1126
1127   MCFG_SCREEN_MODIFY("screen")
1128   MCFG_SCREEN_REFRESH_RATE(FRAME_RATE_60HZ)
1129   MCFG_SCREEN_SIZE(HWIDTH*8, TOTAL_LINES_60HZ)
1130
1131   MCFG_FRAGMENT_ADD(a400_cartslot)
1132
1133   /* software lists */
1134   MCFG_SOFTWARE_LIST_ADD("cart_list","a800")
1135MACHINE_CONFIG_END
1136
1137
1138static MACHINE_CONFIG_DERIVED( a400pal, atari_common )
1139
1140   MCFG_CPU_MODIFY( "maincpu" )
1141   MCFG_CPU_PROGRAM_MAP(a400_mem)
1142   MCFG_CPU_VBLANK_INT_HACK(a400_interrupt, TOTAL_LINES_50HZ)
1143
1144   MCFG_MACHINE_START( a400 )
1145
1146   MCFG_SCREEN_MODIFY("screen")
1147   MCFG_SCREEN_REFRESH_RATE(FRAME_RATE_50HZ)
1148   MCFG_SCREEN_SIZE(HWIDTH*8, TOTAL_LINES_50HZ)
1149
1150   MCFG_FRAGMENT_ADD(a400_cartslot)
1151
1152   /* software lists */
1153   MCFG_SOFTWARE_LIST_ADD("cart_list","a800")
1154MACHINE_CONFIG_END
1155
1156
1157static MACHINE_CONFIG_DERIVED( a800, atari_common )
1158
1159   MCFG_CPU_MODIFY( "maincpu" )
1160   MCFG_CPU_PROGRAM_MAP(a800_mem)
1161   MCFG_CPU_VBLANK_INT_HACK(a800_interrupt, TOTAL_LINES_60HZ)
1162
1163   MCFG_MACHINE_START( a800 )
1164
1165   MCFG_SCREEN_MODIFY("screen")
1166   MCFG_SCREEN_REFRESH_RATE(FRAME_RATE_60HZ)
1167   MCFG_SCREEN_SIZE(HWIDTH*8, TOTAL_LINES_60HZ)
1168
1169   MCFG_FRAGMENT_ADD(a800_cartslot)
1170
1171   /* software lists */
1172   MCFG_SOFTWARE_LIST_ADD("cart_list","a800")
1173MACHINE_CONFIG_END
1174
1175
1176static MACHINE_CONFIG_DERIVED( a800pal, atari_common )
1177
1178   MCFG_CPU_MODIFY( "maincpu" )
1179   MCFG_CPU_PROGRAM_MAP(a800_mem)
1180   MCFG_CPU_VBLANK_INT_HACK(a800_interrupt, TOTAL_LINES_50HZ)
1181
1182   MCFG_MACHINE_START( a800 )
1183
1184   MCFG_SCREEN_MODIFY("screen")
1185   MCFG_SCREEN_REFRESH_RATE(FRAME_RATE_50HZ)
1186   MCFG_SCREEN_SIZE(HWIDTH*8, TOTAL_LINES_50HZ)
1187
1188   MCFG_FRAGMENT_ADD(a800_cartslot)
1189
1190   /* software lists */
1191   MCFG_SOFTWARE_LIST_ADD("cart_list","a800")
1192MACHINE_CONFIG_END
1193
1194
1195static MACHINE_CONFIG_DERIVED( a600xl, atari_common )
1196
1197   MCFG_CPU_MODIFY( "maincpu" )
1198   MCFG_CPU_PROGRAM_MAP(a600xl_mem)   // FIXME?
1199   MCFG_CPU_VBLANK_INT_HACK(a800xl_interrupt, TOTAL_LINES_60HZ)
1200
1201   MCFG_PIA6821_MODIFY( "pia", a600xl_pia_interface )
1202
1203   MCFG_MACHINE_START( a800xl )   // FIXME?
1204
1205   MCFG_SCREEN_MODIFY("screen")
1206   MCFG_SCREEN_REFRESH_RATE(FRAME_RATE_60HZ)
1207   MCFG_SCREEN_SIZE(HWIDTH*8, TOTAL_LINES_60HZ)
1208
1209   MCFG_FRAGMENT_ADD(a400_cartslot)
1210
1211   /* software lists */
1212   MCFG_SOFTWARE_LIST_ADD("cart_list","a800")
1213
1214   /* internal ram */
1215   MCFG_RAM_MODIFY(RAM_TAG)
1216   MCFG_RAM_DEFAULT_SIZE("16K")
1217MACHINE_CONFIG_END
1218
1219
1220static MACHINE_CONFIG_DERIVED( a800xl, atari_common )
1221
1222   MCFG_CPU_MODIFY( "maincpu" )
1223   MCFG_CPU_PROGRAM_MAP(a800xl_mem)
1224   MCFG_CPU_VBLANK_INT_HACK(a800xl_interrupt, TOTAL_LINES_60HZ)
1225
1226   MCFG_PIA6821_MODIFY( "pia", a800xl_pia_interface )
1227
1228   MCFG_MACHINE_START( a800xl )
1229
1230   MCFG_SCREEN_MODIFY("screen")
1231   MCFG_SCREEN_REFRESH_RATE(FRAME_RATE_60HZ)
1232   MCFG_SCREEN_SIZE(HWIDTH*8, TOTAL_LINES_60HZ)
1233
1234   MCFG_FRAGMENT_ADD(a400_cartslot)
1235
1236   /* software lists */
1237   MCFG_SOFTWARE_LIST_ADD("cart_list","a800")
1238MACHINE_CONFIG_END
1239
1240static MACHINE_CONFIG_DERIVED( a800xlpal, a800xl )
1241
1242   MCFG_CPU_MODIFY( "maincpu" )
1243   MCFG_CPU_CLOCK( 1773000 )
1244   MCFG_CPU_VBLANK_INT_HACK(a800xl_interrupt, TOTAL_LINES_50HZ)
1245   MCFG_SCREEN_MODIFY("screen")
1246   MCFG_SCREEN_REFRESH_RATE(FRAME_RATE_50HZ)
1247   MCFG_SCREEN_SIZE(HWIDTH*8, TOTAL_LINES_50HZ)
1248
1249   MCFG_SOUND_MODIFY("pokey")
1250   MCFG_SOUND_CLOCK(1773000)
1251MACHINE_CONFIG_END
1252
1253static MACHINE_CONFIG_DERIVED( a1200xl, a800xl )
1254
1255   MCFG_PIA6821_MODIFY( "pia", a1200xl_pia_interface )
1256MACHINE_CONFIG_END
1257
1258static MACHINE_CONFIG_DERIVED( xegs, a800xl )
1259
1260   MCFG_CPU_MODIFY( "maincpu" )
1261   MCFG_CPU_PROGRAM_MAP(xegs_mem)
1262
1263   MCFG_MACHINE_START( xegs )
1264
1265   MCFG_PIA6821_MODIFY( "pia", xegs_pia_interface )
1266
1267   MCFG_DEVICE_REMOVE("cart1")
1268   MCFG_DEVICE_REMOVE("cart_list")
1269
1270   MCFG_CARTSLOT_ADD("cart1")
1271   MCFG_CARTSLOT_EXTENSION_LIST("rom,bin")
1272   MCFG_CARTSLOT_NOT_MANDATORY
1273   MCFG_CARTSLOT_LOAD(xegs_cart)
1274   MCFG_CARTSLOT_UNLOAD(xegs_cart)
1275   MCFG_CARTSLOT_INTERFACE("xegs_cart")
1276
1277   /* software lists */
1278   MCFG_SOFTWARE_LIST_ADD("cart_list","xegs")
1279MACHINE_CONFIG_END
1280
1281
1282static MACHINE_CONFIG_DERIVED( a5200, atari_common_nodac )
1283
1284   MCFG_CPU_MODIFY( "maincpu" )
1285   MCFG_CPU_PROGRAM_MAP(a5200_mem)
1286   MCFG_CPU_VBLANK_INT_HACK(a5200_interrupt, TOTAL_LINES_60HZ)
1287
1288   MCFG_DEVICE_REMOVE("pokey")
1289   MCFG_SOUND_ADD("pokey", POKEY, FREQ_17_EXACT)
1290   MCFG_SOUND_CONFIG(a5200_pokey_interface)
1291   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
1292
1293   MCFG_PIA6821_MODIFY( "pia", a5200_pia_interface )
1294
1295   MCFG_MACHINE_START( a5200 )
1296
1297   MCFG_SCREEN_MODIFY( "screen" )
1298   MCFG_SCREEN_REFRESH_RATE(FRAME_RATE_60HZ)
1299   MCFG_SCREEN_SIZE(HWIDTH*8, TOTAL_LINES_60HZ)
1300
1301   MCFG_CARTSLOT_ADD("cart")
1302   MCFG_CARTSLOT_EXTENSION_LIST("rom,bin,a52")
1303   MCFG_CARTSLOT_NOT_MANDATORY
1304   MCFG_CARTSLOT_LOAD(a5200_cart)
1305   MCFG_CARTSLOT_UNLOAD(a5200_cart)
1306   MCFG_CARTSLOT_INTERFACE("a5200_cart")
1307
1308   /* Software lists */
1309   MCFG_SOFTWARE_LIST_ADD("cart_list","a5200")
1310
1311   /* internal ram */
1312   MCFG_RAM_MODIFY(RAM_TAG)
1313   MCFG_RAM_DEFAULT_SIZE("16K")
1314MACHINE_CONFIG_END
1315
1316
1317/**************************************************************
1318 *
1319 * ROM loading
1320 *
1321 **************************************************************/
1322
1323ROM_START(a400)
1324   ROM_REGION(0x14000, "maincpu", 0) /* 64K for the CPU + 2 * 8K for cartridges */
1325   ROM_LOAD( "co12399b.rom", 0xd800, 0x0800, CRC(6a5d766e) SHA1(01a6044f7a81d409c938e7dfde0a1af5832229d2) )
1326   ROM_SYSTEM_BIOS(0, "default", "OS Rev. B")
1327   ROMX_LOAD( "co12499b.rom",  0xe000, 0x1000, BAD_DUMP CRC(d818f3e8) SHA1(bcdec2188f6a6a5bfc1df4e383bd828d34b5c4ac), ROM_BIOS(1) )   // CRC and label waiting for confirmation
1328   ROMX_LOAD( "co14599b.rom",  0xf000, 0x1000, BAD_DUMP CRC(c1690a9b) SHA1(c5248e8565574fd39ae1c3f4f356aa4cac07df95), ROM_BIOS(1) )   // CRC and label waiting for confirmation
1329   ROM_SYSTEM_BIOS(1, "reva", "OS Rev. A")
1330   ROMX_LOAD( "co12499a.rom",  0xe000, 0x1000, BAD_DUMP CRC(29f64e17) SHA1(abf7ec488c6b600f1b7f30bdc7f8a2bf6a727675), ROM_BIOS(2) )   // CRC and label waiting for confirmation
1331   ROMX_LOAD( "co14599a.rom",  0xf000, 0x1000, BAD_DUMP CRC(bc533f0c) SHA1(e217148495fa747fe5488132d8d22533e68c7e58), ROM_BIOS(2) )   // CRC and label waiting for confirmation
1332
1333   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1334ROM_END
1335
1336ROM_START(a400pal)
1337   ROM_REGION(0x14000, "maincpu", 0) /* 64K for the CPU + 2 * 8K for cartridges */
1338   ROM_LOAD( "co12399b.rom", 0xd800, 0x0800, CRC(6a5d766e) SHA1(01a6044f7a81d409c938e7dfde0a1af5832229d2) )
1339   ROM_LOAD( "co15199.rom", 0xe000, 0x1000, BAD_DUMP CRC(8e547f56) SHA1(1bd746ea798b723bfb18495a7facca113183d713) )   // Rev. A - CRC and label waiting for confirmation
1340   ROM_LOAD( "co15299.rom", 0xf000, 0x1000, BAD_DUMP CRC(be55b413) SHA1(d88afae49b08e75943d0258cb580e5d34756414a) )   // Rev. A - CRC and label waiting for confirmation
1341
1342   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1343ROM_END
1344
1345ROM_START(a800)
1346   ROM_REGION(0x14000, "maincpu", 0) /* 64K for the CPU + 2 * 8K for cartridges */
1347   ROM_LOAD( "co12399b.rom", 0xd800, 0x0800, CRC(6a5d766e) SHA1(01a6044f7a81d409c938e7dfde0a1af5832229d2) )
1348   ROM_SYSTEM_BIOS(0, "default", "OS Rev. B")
1349   ROMX_LOAD( "co12499b.rom",  0xe000, 0x1000, BAD_DUMP CRC(d818f3e8) SHA1(bcdec2188f6a6a5bfc1df4e383bd828d34b5c4ac), ROM_BIOS(1) )   // CRC and label waiting for confirmation
1350   ROMX_LOAD( "co14599b.rom",  0xf000, 0x1000, BAD_DUMP CRC(c1690a9b) SHA1(c5248e8565574fd39ae1c3f4f356aa4cac07df95), ROM_BIOS(1) )   // CRC and label waiting for confirmation
1351   ROM_SYSTEM_BIOS(1, "reva", "OS Rev. A")
1352   ROMX_LOAD( "co12499a.rom",  0xe000, 0x1000, BAD_DUMP CRC(29f64e17) SHA1(abf7ec488c6b600f1b7f30bdc7f8a2bf6a727675), ROM_BIOS(2) )   // CRC and label waiting for confirmation
1353   ROMX_LOAD( "co14599a.rom",  0xf000, 0x1000, BAD_DUMP CRC(bc533f0c) SHA1(e217148495fa747fe5488132d8d22533e68c7e58), ROM_BIOS(2) )   // CRC and label waiting for confirmation
1354
1355   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1356
1357   ROM_REGION(0x2000, "rslot", ROMREGION_ERASEFF)
1358ROM_END
1359
1360ROM_START(a800pal)
1361   ROM_REGION(0x14000, "maincpu", 0) /* 64K for the CPU + 2 * 8K for cartridges */
1362   ROM_LOAD( "co12399b.rom", 0xd800, 0x0800, CRC(6a5d766e) SHA1(01a6044f7a81d409c938e7dfde0a1af5832229d2) )
1363   ROM_LOAD( "co15199.rom", 0xe000, 0x1000, BAD_DUMP CRC(8e547f56) SHA1(1bd746ea798b723bfb18495a7facca113183d713) )   // Rev. A - CRC and label waiting for confirmation
1364   ROM_LOAD( "co15299.rom", 0xf000, 0x1000, BAD_DUMP CRC(be55b413) SHA1(d88afae49b08e75943d0258cb580e5d34756414a) )   // Rev. A - CRC and label waiting for confirmation
1365
1366   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1367
1368   ROM_REGION(0x2000, "rslot", ROMREGION_ERASEFF)
1369ROM_END
1370
1371ROM_START(a1200xl)
1372   ROM_REGION(0x18000, "maincpu", 0)
1373   ROM_SYSTEM_BIOS(0, "default", "OS Rev. 11")
1374   ROMX_LOAD( "co60616b.rom", 0x14000, 0x2000, BAD_DUMP CRC(6e29ec8d) SHA1(3f9c06d6b4d261f3d5bf4354e3cff0c17b9347b9), ROM_BIOS(1) )   // CRC and label waiting for confirmation
1375   ROMX_LOAD( "co60617b.rom", 0x16000, 0x2000, BAD_DUMP CRC(d73ce29a) SHA1(64790242d902643fe0c40dd842749f1fe461831b), ROM_BIOS(1) )   // CRC and label waiting for confirmation
1376   ROM_SYSTEM_BIOS(1, "rev10", "OS Rev. 10")
1377   ROMX_LOAD( "co60616a.rom", 0x14000, 0x2000, BAD_DUMP CRC(0391386b) SHA1(7c176657c88b89b8a69bf021fa8e0939efc0dff2), ROM_BIOS(2) )   // CRC and label waiting for confirmation
1378   ROMX_LOAD( "co60617a.rom", 0x16000, 0x2000, BAD_DUMP CRC(b502f1e7) SHA1(6688db57d97fa570aef5c15cef3e5fb2688879c2), ROM_BIOS(2) )   // CRC and label waiting for confirmation
1379
1380   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1381ROM_END
1382
1383ROM_START(a600xl)
1384   ROM_REGION(0x10000, "maincpu", 0)
1385   ROM_LOAD( "co60302a.rom", 0xa000, 0x2000, CRC(f0202fb3) SHA1(7ad88dd99ff4a6ee66f6d162074db6f8bef7a9b6) )   // Rev. B
1386   ROM_LOAD( "co62024.rom",  0xc000, 0x4000, CRC(643bcc98) SHA1(881d030656b40bbe48f15a696b28f22c0b752ab0) )   // Rev. 1
1387
1388   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1389ROM_END
1390
1391ROM_START(a800xl)
1392   ROM_REGION(0x18000, "maincpu", 0)
1393   ROM_FILL( 0, 0x10000, 0x00 )
1394   ROM_LOAD( "co60302a.rom", 0x10000, 0x2000, CRC(f0202fb3) SHA1(7ad88dd99ff4a6ee66f6d162074db6f8bef7a9b6) )   // Rev. B
1395   ROM_LOAD( "co61598b.rom", 0x14000, 0x4000, CRC(1f9cd270) SHA1(ae4f523ba08b6fd59f3cae515a2b2410bbd98f55) )   // Rev. 2
1396
1397   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1398ROM_END
1399
1400#define rom_a800xlp rom_a800xl
1401
1402ROM_START(a65xe)
1403   ROM_REGION(0x18000, "maincpu", 0)
1404   ROM_LOAD( "co24947a.rom", 0x10000, 0x2000, CRC(7d684184) SHA1(3693c9cb9bf3b41bae1150f7a8264992468fc8c0) )   // Rev. C
1405   ROM_LOAD( "co61598b.rom", 0x14000, 0x4000, CRC(1f9cd270) SHA1(ae4f523ba08b6fd59f3cae515a2b2410bbd98f55) )   // Rev. 2
1406
1407   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1408ROM_END
1409
1410ROM_START(a65xea)
1411   ROM_REGION(0x18000, "maincpu", 0)
1412   ROM_LOAD( "basic_ar.rom", 0x10000, 0x2000, CRC(c899f4d6) SHA1(043df191d1fe402e792266a108e147ffcda35130) )   // is this correct? or shall we use Rev. C?
1413//  ROM_LOAD( "c101700.rom",  0x14000, 0x4000, CRC(7f9a76c8) SHA1(57eb6d87850a763f11767f53d4eaede186f831a2) )   // this was from Savetz and has wrong bits!
1414   ROM_LOAD( "c101700.rom",  0x14000, 0x4000, CRC(45f47988) SHA1(a36b8b20f657580f172749bb0625c08706ed824c) )   // Rev. 3B ?
1415
1416   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1417ROM_END
1418
1419ROM_START(a130xe)
1420   ROM_REGION(0x18000, "maincpu", 0)
1421   ROM_LOAD( "co24947a.rom", 0x10000, 0x2000, CRC(7d684184) SHA1(3693c9cb9bf3b41bae1150f7a8264992468fc8c0) )   // Rev. C
1422   ROM_LOAD( "co61598b.rom", 0x14000, 0x4000, CRC(1f9cd270) SHA1(ae4f523ba08b6fd59f3cae515a2b2410bbd98f55) )   // Rev. 2
1423
1424   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1425ROM_END
1426
1427ROM_START(a800xe)
1428   ROM_REGION(0x18000, "maincpu", 0)
1429   ROM_LOAD( "co24947a.rom", 0x10000, 0x2000, CRC(7d684184) SHA1(3693c9cb9bf3b41bae1150f7a8264992468fc8c0) )   // Rev. C
1430   ROM_LOAD( "c300717.rom",  0x14000, 0x4000, CRC(29f133f7) SHA1(f03b9b93000ee84abb9cf8d6367241006f172182) )   // Rev. 3
1431
1432   ROM_REGION(0x10000, "lslot", ROMREGION_ERASEFF)
1433ROM_END
1434
1435ROM_START(xegs)
1436   ROM_REGION(0x1a000, "maincpu", 0)
1437   ROM_LOAD( "c101687.rom", 0x10000, 0x8000, CRC(d50260d1) SHA1(0e0625ab2473f8431640df3ac8af61925760b9b9) )   // Rev. C + Rev. 4 + Missile Command
1438
1439   ROM_REGION(0x20000, "user1", ROMREGION_ERASE00)
1440ROM_END
1441
1442
1443ROM_START(a5200)
1444   ROM_REGION(0x14000, "maincpu", 0) /* 64K for the CPU + 16K for cartridges */
1445   ROM_SYSTEM_BIOS(0, "default", "a5200")
1446   ROMX_LOAD( "5200.rom",  0xf800, 0x0800, CRC(4248d3e3) SHA1(6ad7a1e8c9fad486fbec9498cb48bf5bc3adc530), ROM_BIOS(1) )
1447   ROM_SYSTEM_BIOS(1, "alt", "a5200 (alt)")
1448   ROMX_LOAD( "5200a.rom", 0xf800, 0x0800, CRC(c2ba2613) SHA1(1d2a3f00109d75d2d79fecb565775eb95b7d04d5), ROM_BIOS(2) )
1449ROM_END
1450
1451/**************************************************************
1452 *
1453 * Driver initializations
1454 *
1455 **************************************************************/
1456
1457static DRIVER_INIT( a800xl )
1458{
1459   a800xl_mmu(machine, 0xff);
1460}
1461
1462static DRIVER_INIT( xegs )
1463{
1464   xegs_mmu(machine, 0xff);
1465}
1466
1467static DRIVER_INIT( a600xl )
1468{
1469   UINT8 *rom = machine.region("maincpu")->base();
1470   memcpy( rom + 0x5000, rom + 0xd000, 0x800 );
1471}
1472
1473/**************************************************************
1474 *
1475 * Game driver(s)
1476 *
1477 **************************************************************/
1478
1479/*     YEAR  NAME      PARENT    COMPAT MACHINE     INPUT    INIT      COMPANY    FULLNAME */
1480COMP ( 1979, a400,     0,        0,     a400,       a800,    0,      "Atari",   "Atari 400 (NTSC)", 0)
1481COMP ( 1979, a400pal,  a400,     0,     a400pal,    a800,    0,      "Atari",   "Atari 400 (PAL)",  0)
1482COMP ( 1979, a800,     0,        0,     a800,       a800,    0,      "Atari",   "Atari 800 (NTSC)", 0)
1483COMP ( 1979, a800pal,  a800,     0,     a800pal,    a800,    0,      "Atari",   "Atari 800 (PAL)",  0)
1484COMP ( 1982, a1200xl,  a800,     0,     a1200xl,    a800xl,  a800xl, "Atari",   "Atari 1200XL",     GAME_NOT_WORKING )      // 64k RAM
1485COMP ( 1983, a600xl,   a800xl,   0,     a600xl,     a800xl,  a600xl, "Atari",   "Atari 600XL",      GAME_NOT_WORKING )      // 16k RAM
1486COMP ( 1983, a800xl,   0,       0,     a800xl,     a800xl,  a800xl, "Atari",   "Atari 800XL (NTSC)",GAME_IMPERFECT_GRAPHICS )      // 64k RAM
1487COMP ( 1983, a800xlp,  a800xl,    0,     a800xlpal,  a800xl,  a800xl, "Atari",   "Atari 800XL (PAL)", GAME_IMPERFECT_GRAPHICS )      // 64k RAM
1488COMP ( 1986, a65xe,    a800xl,   0,     a800xl,     a800xl,  a800xl, "Atari",   "Atari 65XE",       GAME_NOT_WORKING )      // 64k RAM
1489COMP ( 1986, a65xea,   a800xl,   0,     a800xl,     a800xl,  a800xl, "Atari",   "Atari 65XE (Arabic)", GAME_NOT_WORKING )
1490COMP ( 1986, a130xe,   a800xl,   0,     a800xl,     a800xl,  a800xl, "Atari",   "Atari 130XE",      GAME_NOT_WORKING )      // 128k RAM
1491COMP ( 1986, a800xe,   a800xl,   0,     a800xl,     a800xl,  a800xl, "Atari",   "Atari 800XE",      GAME_NOT_WORKING )      // 64k RAM
1492COMP ( 1987, xegs,     0,        0,     xegs,       a800xl,  xegs,   "Atari",   "Atari XE Game System", GAME_NOT_WORKING )   // 64k RAM
1493
1494CONS ( 1982, a5200,    0,        0,     a5200,      a5200,   0,      "Atari",   "Atari 5200",       0)
src/mess/drivers/nes.c
r11460r11461
1/***************************************************************************
2
3  nes.c
4
5  Driver file to handle emulation of the Nintendo Entertainment System (Famicom).
6
7  MESS driver by Brad Oliver (bradman@pobox.com), NES sound code by Matt Conte.
8  Based in part on the old xNes code, by Nicolas Hamel, Chuck Mason, Brad Oliver,
9  Richard Bannister and Jeff Mitchell.
10
11***************************************************************************/
12
13#include "emu.h"
14#include "video/ppu2c0x.h"
15#include "machine/nes_mmc.h"
16#include "includes/nes.h"
17#include "cpu/m6502/m6502.h"
18#include "imagedev/cartslot.h"
19#include "sound/nes_apu.h"
20#include "imagedev/flopdrv.h"
21#include "formats/nes_dsk.h"
22
23
24static READ8_DEVICE_HANDLER( psg_4015_r )
25{
26   return nes_psg_r(device, 0x15);
27}
28
29static WRITE8_DEVICE_HANDLER( psg_4015_w )
30{
31   nes_psg_w(device, 0x15, data);
32}
33
34static WRITE8_DEVICE_HANDLER( psg_4017_w )
35{
36   nes_psg_w(device, 0x17, data);
37}
38
39static WRITE8_HANDLER(nes_vh_sprite_dma_w)
40{
41   nes_state *state = space->machine().driver_data<nes_state>();
42   ppu2c0x_spriteram_dma(space, state->m_ppu, data);
43}
44
45static ADDRESS_MAP_START( nes_map, AS_PROGRAM, 8 )
46   AM_RANGE(0x0000, 0x07ff) AM_RAM AM_MIRROR(0x1800)               /* RAM */
47   AM_RANGE(0x2000, 0x3fff) AM_DEVREADWRITE("ppu", ppu2c0x_r, ppu2c0x_w)      /* PPU registers */
48   AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE("nessound", nes_psg_r, nes_psg_w)      /* PSG primary registers */
49   AM_RANGE(0x4014, 0x4014) AM_WRITE(nes_vh_sprite_dma_w)            /* stupid address space hole */
50   AM_RANGE(0x4015, 0x4015) AM_DEVREADWRITE("nessound", psg_4015_r, psg_4015_w)      /* PSG status / first control register */
51   AM_RANGE(0x4016, 0x4016) AM_READWRITE(nes_IN0_r, nes_IN0_w)         /* IN0 - input port 1 */
52   AM_RANGE(0x4017, 0x4017) AM_READ(nes_IN1_r)                     /* IN1 - input port 2 */
53   AM_RANGE(0x4017, 0x4017) AM_DEVWRITE("nessound", psg_4017_w)      /* PSG second control register */
54   AM_RANGE(0x4100, 0x5fff) AM_READWRITE(nes_low_mapper_r, nes_low_mapper_w)   /* Perform unholy acts on the machine */
55ADDRESS_MAP_END
56
57
58static INPUT_PORTS_START( nes_controllers )
59   PORT_START("CTRLSEL")  /* Select Controller Type */
60   PORT_CATEGORY_CLASS( 0x000f, 0x0001, "P1 Controller")
61   PORT_CATEGORY_ITEM(  0x0000, "Unconnected",      0 )
62   PORT_CATEGORY_ITEM(  0x0001, "Gamepad",         1 )
63   PORT_CATEGORY_ITEM(  0x0002, "Zapper",         5 )
64   PORT_CATEGORY_ITEM(  0x0006, "Crazy Climber pad", 10 )
65   PORT_CATEGORY_CLASS( 0x00f0, 0x0010, "P2 Controller")
66   PORT_CATEGORY_ITEM(  0x0000, "Unconnected",      0 )
67   PORT_CATEGORY_ITEM(  0x0010, "Gamepad",         2 )
68   PORT_CATEGORY_ITEM(  0x0030, "Zapper",         6 )
69   PORT_CATEGORY_ITEM(  0x0040, "Arkanoid paddle",   7 )
70//  PORT_CATEGORY_ITEM(  0x0050, "Family Trainer",  11 )
71   PORT_CATEGORY_CLASS( 0x0f00, 0x0000, "P3 Controller")
72   PORT_CATEGORY_ITEM(  0x0000, "Unconnected",      0 )
73   PORT_CATEGORY_ITEM(  0x0100, "Gamepad",         3 )
74   PORT_CATEGORY_CLASS( 0xf000, 0x0000, "P4 Controller")
75   PORT_CATEGORY_ITEM(  0x0000, "Unconnected",      0 )
76   PORT_CATEGORY_ITEM(  0x1000, "Gamepad",         4 )
77
78   PORT_START("PAD1")   /* Joypad 1 */
79   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P1 A") PORT_CATEGORY(1) PORT_PLAYER(1)
80   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P1 B") PORT_CATEGORY(1) PORT_PLAYER(1)
81   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_CATEGORY(1) PORT_PLAYER(1)
82   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_START ) PORT_CATEGORY(1) PORT_PLAYER(1)
83   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_CATEGORY(1) PORT_PLAYER(1)
84   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_CATEGORY(1) PORT_PLAYER(1)
85   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_CATEGORY(1) PORT_PLAYER(1)
86   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_CATEGORY(1) PORT_PLAYER(1)
87
88   PORT_START("PAD2")   /* Joypad 2 */
89   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P2 A") PORT_CATEGORY(2) PORT_PLAYER(2)
90   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P2 B") PORT_CATEGORY(2) PORT_PLAYER(2)
91   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_CATEGORY(2) PORT_PLAYER(2)
92   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_START ) PORT_CATEGORY(2) PORT_PLAYER(2)
93   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_CATEGORY(2) PORT_PLAYER(2)
94   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_CATEGORY(2) PORT_PLAYER(2)
95   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_CATEGORY(2) PORT_PLAYER(2)
96   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_CATEGORY(2) PORT_PLAYER(2)
97
98   PORT_START("PAD3")   /* Joypad 3 */
99   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P3 A") PORT_CATEGORY(3) PORT_PLAYER(3)
100   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P3 B") PORT_CATEGORY(3) PORT_PLAYER(3)
101   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_CATEGORY(3) PORT_PLAYER(3)
102   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_START ) PORT_CATEGORY(3) PORT_PLAYER(3)
103   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_CATEGORY(3) PORT_PLAYER(3)
104   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_CATEGORY(3) PORT_PLAYER(3)
105   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_CATEGORY(3) PORT_PLAYER(3)
106   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_CATEGORY(3) PORT_PLAYER(3)
107
108   PORT_START("PAD4")   /* Joypad 4 */
109   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P4 A") PORT_CATEGORY(4) PORT_PLAYER(4)
110   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P4 B") PORT_CATEGORY(4) PORT_PLAYER(4)
111   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_CATEGORY(4) PORT_PLAYER(4)
112   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_START ) PORT_CATEGORY(4) PORT_PLAYER(4)
113   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_CATEGORY(4) PORT_PLAYER(4)
114   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_CATEGORY(4) PORT_PLAYER(4)
115   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_CATEGORY(4) PORT_PLAYER(4)
116   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_CATEGORY(4) PORT_PLAYER(4)
117
118   PORT_START("ZAPPER1_X")  /* P1 zapper */
119   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(70) PORT_KEYDELTA(30) PORT_MINMAX(0,255)                                          PORT_CATEGORY(5) PORT_PLAYER(1)
120   PORT_START("ZAPPER1_Y")  /* P1 zapper */
121   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(50) PORT_KEYDELTA(30) PORT_MINMAX(0,255)                                          PORT_CATEGORY(5) PORT_PLAYER(1)
122   PORT_START("ZAPPER1_T")  /* P1 zapper trigger */
123   PORT_BIT( 0x03, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("P1 Lightgun Trigger") PORT_CATEGORY(5) PORT_PLAYER(1)
124
125   PORT_START("ZAPPER2_X")  /* P2 zapper */
126   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(70) PORT_KEYDELTA(30) PORT_MINMAX(0,255 )                                          PORT_CATEGORY(6) PORT_PLAYER(2)
127   PORT_START("ZAPPER2_Y")  /* P2 zapper */
128   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(50) PORT_KEYDELTA(30) PORT_MINMAX(0,255 )                                          PORT_CATEGORY(6) PORT_PLAYER(2)
129   PORT_START("ZAPPER2_T")  /* P2 zapper trigger */
130   PORT_BIT( 0x03, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("P2 Lightgun Trigger") PORT_CATEGORY(6) PORT_PLAYER(2)
131
132   PORT_START("PADDLE")  /* Arkanoid paddle */
133   PORT_BIT( 0xff, 0x7f, IPT_PADDLE) PORT_SENSITIVITY(25) PORT_KEYDELTA(3) PORT_MINMAX(0x62,0xf2)                                                   PORT_CATEGORY(7)
134
135   PORT_START("CC_LEFT")
136   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED ) PORT_CATEGORY(10) PORT_PLAYER(1)
137   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNUSED ) PORT_CATEGORY(10) PORT_PLAYER(1)
138   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_CATEGORY(10) PORT_PLAYER(1)
139   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_START ) PORT_CATEGORY(10) PORT_PLAYER(1)
140   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICKLEFT_UP ) PORT_CATEGORY(10) PORT_PLAYER(1)
141   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICKLEFT_DOWN ) PORT_CATEGORY(10) PORT_PLAYER(1)
142   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICKLEFT_LEFT ) PORT_CATEGORY(10) PORT_PLAYER(1)
143   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICKLEFT_RIGHT ) PORT_CATEGORY(10) PORT_PLAYER(1)
144
145   PORT_START("CC_RIGHT")
146   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED ) PORT_CATEGORY(10) PORT_PLAYER(1)
147   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNUSED ) PORT_CATEGORY(10) PORT_PLAYER(1)
148   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED ) PORT_CATEGORY(10) PORT_PLAYER(1)
149   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED ) PORT_CATEGORY(10) PORT_PLAYER(1)
150   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICKRIGHT_UP ) PORT_CATEGORY(10) PORT_PLAYER(1)
151   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICKRIGHT_DOWN ) PORT_CATEGORY(10) PORT_PLAYER(1)
152   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICKRIGHT_LEFT ) PORT_CATEGORY(10) PORT_PLAYER(1)
153   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICKRIGHT_RIGHT ) PORT_CATEGORY(10) PORT_PLAYER(1)
154
155INPUT_PORTS_END
156
157static INPUT_PORTS_START( nes )
158   PORT_INCLUDE( nes_controllers )
159
160   PORT_START("CONFIG")  /* configuration */
161   PORT_CONFNAME( 0x01, 0x00, "Draw Top/Bottom 8 Lines")
162   PORT_CONFSETTING(    0x01, DEF_STR(No) )
163   PORT_CONFSETTING(    0x00, DEF_STR(Yes) )
164   PORT_CONFNAME( 0x02, 0x00, "Enforce 8 Sprites/line")
165   PORT_CONFSETTING(    0x02, DEF_STR(No) )
166   PORT_CONFSETTING(    0x00, DEF_STR(Yes) )
167INPUT_PORTS_END
168
169static INPUT_PORTS_START( famicom )
170   PORT_INCLUDE( nes_controllers )
171
172   PORT_START("FLIPDISK") /* fake keys */
173   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("Change Disk Side")
174INPUT_PORTS_END
175
176static INPUT_PORTS_START( fc_keyboard )
177   PORT_START("FCKEY0")
178   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F8) PORT_CHAR(UCHAR_MAMEKEY(F8))
179   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13)
180   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR('[')
181   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_BACKSLASH)   PORT_CHAR(']')
182   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_NAME("Kana")
183   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_RSHIFT)
184   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_BACKSLASH2)   PORT_CHAR('\\')
185   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_NAME("Stop") PORT_CODE(KEYCODE_BACKSPACE)
186
187   PORT_START("FCKEY1")
188   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F7) PORT_CHAR(UCHAR_MAMEKEY(F7))
189   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_OPENBRACE)   PORT_CHAR('@')
190   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_COLON)   PORT_CHAR(':')
191   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_QUOTE)   PORT_CHAR(';')
192   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CHAR('_')
193   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CHAR('/')
194   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_MINUS)   PORT_CHAR('-')
195   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_EQUALS)   PORT_CHAR('^')
196
197   PORT_START("FCKEY2")
198   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F6) PORT_CHAR(UCHAR_MAMEKEY(F6))
199   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_O)   PORT_CHAR('O')
200   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_L)   PORT_CHAR('L')
201   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_K)   PORT_CHAR('K')
202   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_STOP)   PORT_CHAR('.')
203   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_COMMA)   PORT_CHAR(',')
204   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_P)   PORT_CHAR('P')
205   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_0)   PORT_CHAR('0')
206
207   PORT_START("FCKEY3")
208   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F5) PORT_CHAR(UCHAR_MAMEKEY(F5))
209   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_I)   PORT_CHAR('I')
210   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_U)   PORT_CHAR('U')
211   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_J)   PORT_CHAR('J')
212   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_M)   PORT_CHAR('M')
213   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_N)   PORT_CHAR('N')
214   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_9)   PORT_CHAR('9')
215   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_8)   PORT_CHAR('8')
216
217   PORT_START("FCKEY4")
218   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F4) PORT_CHAR(UCHAR_MAMEKEY(F4))
219   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_Y)   PORT_CHAR('Y')
220   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_G)   PORT_CHAR('G')
221   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_H)   PORT_CHAR('H')
222   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_B)   PORT_CHAR('B')
223   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_V)   PORT_CHAR('V')
224   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_7)   PORT_CHAR('7')
225   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_6)   PORT_CHAR('6')
226
227   PORT_START("FCKEY5")
228   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F3) PORT_CHAR(UCHAR_MAMEKEY(F3))
229   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_T)   PORT_CHAR('T')
230   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_R)   PORT_CHAR('R')
231   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_D)   PORT_CHAR('D')
232   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F)   PORT_CHAR('F')
233   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_C)   PORT_CHAR('C')
234   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_5)   PORT_CHAR('5')
235   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_4)   PORT_CHAR('4')
236
237   PORT_START("FCKEY6")
238   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F2) PORT_CHAR(UCHAR_MAMEKEY(F2))
239   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_W)   PORT_CHAR('W')
240   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_S)   PORT_CHAR('S')
241   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_A)   PORT_CHAR('A')
242   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_X)   PORT_CHAR('X')
243   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_Z)   PORT_CHAR('Z')
244   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_E)   PORT_CHAR('E')
245   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_3)   PORT_CHAR('3')
246
247   PORT_START("FCKEY7")
248   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_F1) PORT_CHAR(UCHAR_MAMEKEY(F1))
249   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_TAB) PORT_CHAR(UCHAR_MAMEKEY(ESC))
250   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_Q)   PORT_CHAR('Q')
251   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_LCONTROL)      PORT_CHAR(UCHAR_SHIFT_2)
252   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_LSHIFT)      PORT_CHAR(UCHAR_SHIFT_1)
253   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_NAME("Grph") PORT_CODE(KEYCODE_LALT)
254   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_1)   PORT_CHAR('1')
255   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_2)   PORT_CHAR('2')
256
257   PORT_START("FCKEY8")
258   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_NAME("Clr")
259   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_UP)   PORT_CHAR(UCHAR_MAMEKEY(UP))
260   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_RIGHT) PORT_CHAR(UCHAR_MAMEKEY(RIGHT))
261   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_LEFT) PORT_CHAR(UCHAR_MAMEKEY(LEFT))
262   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_DOWN) PORT_CHAR(UCHAR_MAMEKEY(DOWN))
263   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_CODE(KEYCODE_SPACE)      PORT_CHAR(' ')
264   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_NAME("Del") PORT_CODE(KEYCODE_DEL)
265   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(8) PORT_NAME("Ins") PORT_CODE(KEYCODE_INSERT)
266
267INPUT_PORTS_END
268
269static INPUT_PORTS_START( subor_keyboard )
270   PORT_START("SUBKEY0")
271   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_4)   PORT_CHAR('4')
272   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_G)   PORT_CHAR('G')
273   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F)   PORT_CHAR('F')
274   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_C)   PORT_CHAR('C')
275   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F2) PORT_CHAR(UCHAR_MAMEKEY(F2))
276   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_E)   PORT_CHAR('E')
277   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_5)   PORT_CHAR('5')
278   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_V)   PORT_CHAR('V')
279
280   PORT_START("SUBKEY1")
281   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_2)   PORT_CHAR('2')
282   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_D)   PORT_CHAR('D')
283   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_S)   PORT_CHAR('S')
284   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_END) PORT_CHAR(UCHAR_MAMEKEY(END))
285   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F1) PORT_CHAR(UCHAR_MAMEKEY(F1))
286   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_W)   PORT_CHAR('W')
287   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_3)   PORT_CHAR('3')
288   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_X)   PORT_CHAR('X')
289
290   PORT_START("SUBKEY2")
291   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_INSERT) PORT_CHAR(UCHAR_MAMEKEY(INSERT))
292   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_BACKSPACE)   PORT_CHAR(8)
293   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_NAME("NEXT")
294   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_RIGHT) PORT_CHAR(UCHAR_MAMEKEY(RIGHT))
295   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F8) PORT_CHAR(UCHAR_MAMEKEY(F8))
296   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_NAME("PRIOR")
297   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_DEL) PORT_CHAR(UCHAR_MAMEKEY(DEL))
298   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_HOME) PORT_CHAR(UCHAR_MAMEKEY(HOME))
299
300   PORT_START("SUBKEY3")
301   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_9)   PORT_CHAR('9')
302   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_I)   PORT_CHAR('I')
303   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_L)   PORT_CHAR('L')
304   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_COMMA)   PORT_CHAR(',')
305   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F5) PORT_CHAR(UCHAR_MAMEKEY(F5))
306   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_O)   PORT_CHAR('O')
307   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_0)   PORT_CHAR('0')
308   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_STOP)   PORT_CHAR('.')
309
310   PORT_START("SUBKEY4")
311   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR(']')
312   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_ENTER)   PORT_CHAR(13)
313   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_UP) PORT_CHAR(UCHAR_MAMEKEY(UP))
314   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_LEFT) PORT_CHAR(UCHAR_MAMEKEY(LEFT))
315   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F7) PORT_CHAR(UCHAR_MAMEKEY(F7))
316   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_OPENBRACE)   PORT_CHAR('[')
317   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_BACKSLASH)   PORT_CHAR('\\')
318   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_DOWN) PORT_CHAR(UCHAR_MAMEKEY(DOWN))
319
320   PORT_START("SUBKEY5")
321   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_Q)   PORT_CHAR('Q')
322   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_CAPSLOCK) PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
323   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_Z)   PORT_CHAR('Z')
324   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_TAB)   PORT_CHAR('\t')
325   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_ESC) PORT_CHAR(UCHAR_MAMEKEY(ESC))
326   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_A)   PORT_CHAR('A')
327   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_1)   PORT_CHAR('1')
328   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_LCONTROL)      PORT_CHAR(UCHAR_SHIFT_2)
329
330   PORT_START("SUBKEY6")
331   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_7)   PORT_CHAR('7')
332   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_Y)   PORT_CHAR('Y')
333   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_K)   PORT_CHAR('K')
334   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_M)   PORT_CHAR('M')
335   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F4) PORT_CHAR(UCHAR_MAMEKEY(F4))
336   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_U)   PORT_CHAR('U')
337   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_8)   PORT_CHAR('8')
338   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_J)   PORT_CHAR('J')
339
340   PORT_START("SUBKEY7")
341   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_MINUS)   PORT_CHAR('-')
342   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_COLON)   PORT_CHAR(':')
343   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_QUOTE)   PORT_CHAR('\'')
344   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_SLASH)   PORT_CHAR('/')
345   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F6) PORT_CHAR(UCHAR_MAMEKEY(F6))
346   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_P)      PORT_CHAR('P')
347   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_EQUALS)   PORT_CHAR('=')
348   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_LSHIFT)   PORT_CHAR(UCHAR_SHIFT_1)
349
350   PORT_START("SUBKEY8")
351   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_T)   PORT_CHAR('T')
352   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_H)   PORT_CHAR('H')
353   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_N)   PORT_CHAR('N')
354   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_SPACE)   PORT_CHAR(' ')
355   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F3) PORT_CHAR(UCHAR_MAMEKEY(F3))
356   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_R)   PORT_CHAR('R')
357   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_6)   PORT_CHAR('6')
358   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_B)   PORT_CHAR('B')
359
360   PORT_START("SUBKEY9")
361   PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNUSED ) PORT_CATEGORY(9)
362
363   PORT_START("SUBKEY10")
364   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_NAME("LMENU")
365   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_4_PAD)   PORT_CHAR(UCHAR_MAMEKEY(4_PAD))
366   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_7_PAD)   PORT_CHAR(UCHAR_MAMEKEY(7_PAD))
367   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F11)      PORT_CHAR(UCHAR_MAMEKEY(F11))
368   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F12)      PORT_CHAR(UCHAR_MAMEKEY(F12))
369   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_1_PAD)   PORT_CHAR(UCHAR_MAMEKEY(1_PAD))
370   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_2_PAD)   PORT_CHAR(UCHAR_MAMEKEY(2_PAD))
371   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_8_PAD)   PORT_CHAR(UCHAR_MAMEKEY(8_PAD))
372
373   PORT_START("SUBKEY11")
374   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_MINUS_PAD)PORT_CHAR(UCHAR_MAMEKEY(MINUS_PAD))
375   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_PLUS_PAD)   PORT_CHAR(UCHAR_MAMEKEY(PLUS_PAD))
376   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_ASTERISK)   PORT_CHAR(UCHAR_MAMEKEY(ASTERISK))
377   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_9_PAD)   PORT_CHAR(UCHAR_MAMEKEY(9_PAD))
378   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F10) PORT_CHAR(UCHAR_MAMEKEY(F10))
379   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_5_PAD)   PORT_CHAR(UCHAR_MAMEKEY(5_PAD))
380   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_SLASH_PAD)PORT_CHAR(UCHAR_MAMEKEY(SLASH_PAD))
381   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_NUMLOCK)   PORT_CHAR(UCHAR_MAMEKEY(NUMLOCK))
382
383   PORT_START("SUBKEY12")
384   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_TILDE)   PORT_CHAR('`')
385   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_6_PAD)   PORT_CHAR(UCHAR_MAMEKEY(6_PAD))
386   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_NAME("PAUSE")
387   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_NAME("SPACE2")
388   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_F9) PORT_CHAR(UCHAR_MAMEKEY(F9))
389   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_3_PAD)   PORT_CHAR(UCHAR_MAMEKEY(3_PAD))
390   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_NAME("Keypad .") PORT_CODE(KEYCODE_DEL_PAD)
391   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CATEGORY(9) PORT_CODE(KEYCODE_0_PAD)   PORT_CHAR(UCHAR_MAMEKEY(0_PAD))
392
393INPUT_PORTS_END
394
395static INPUT_PORTS_START( famikey )
396   PORT_INCLUDE( famicom )
397   PORT_INCLUDE( fc_keyboard )
398   PORT_INCLUDE( subor_keyboard )
399
400   PORT_MODIFY("CTRLSEL")  /* Select Controller Type */
401   PORT_CATEGORY_CLASS( 0x000f, 0x0004, "P1 Controller")
402   PORT_CATEGORY_ITEM(  0x0000, "Unconnected",      0 )
403   PORT_CATEGORY_ITEM(  0x0001, "Gamepad",         1 )
404   PORT_CATEGORY_ITEM(  0x0002, "Zapper",         5 )
405   PORT_CATEGORY_ITEM(  0x0006, "Crazy Climber pad", 10 )
406   PORT_CATEGORY_ITEM(  0x0007, "FC Keyboard",      8 )
407   PORT_CATEGORY_ITEM(  0x0008, "Subor Keyboard",   9 )
408   PORT_CATEGORY_CLASS( 0x00f0, 0x0010, "P2 Controller")
409   PORT_CATEGORY_ITEM(  0x0000, "Unconnected",      0 )
410   PORT_CATEGORY_ITEM(  0x0010, "Gamepad",         2 )
411   PORT_CATEGORY_ITEM(  0x0030, "Zapper",         6 )
412   PORT_CATEGORY_ITEM(  0x0040, "Arkanoid paddle",   7 )
413//  PORT_CATEGORY_ITEM(  0x0050, "Family Trainer",  11 )
414   PORT_CATEGORY_CLASS( 0x0f00, 0x0000, "P3 Controller")
415   PORT_CATEGORY_ITEM(  0x0000, "Unconnected",      0 )
416   PORT_CATEGORY_ITEM(  0x0100, "Gamepad",         3 )
417   PORT_CATEGORY_CLASS( 0xf000, 0x0000, "P4 Controller")
418   PORT_CATEGORY_ITEM(  0x0000, "Unconnected",      0 )
419   PORT_CATEGORY_ITEM(  0x1000, "Gamepad",         4 )
420INPUT_PORTS_END
421
422#ifdef UNUSED_FUNCTION
423/* This layout is not changed at runtime */
424gfx_layout nes_vram_charlayout =
425{
426    8,8,    /* 8*8 characters */
427    512,    /* 512 characters */
428    2,  /* 2 bits per pixel */
429    { 8*8, 0 }, /* the two bitplanes are separated */
430    { 0, 1, 2, 3, 4, 5, 6, 7 },
431    { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
432    16*8    /* every char takes 16 consecutive bytes */
433};
434#endif
435
436static const nes_interface nes_apu_interface =
437{
438   "maincpu"
439};
440
441
442static void ppu_nmi(device_t *device, int *ppu_regs)
443{
444   cputag_set_input_line(device->machine(), "maincpu", INPUT_LINE_NMI, PULSE_LINE);
445}
446
447
448static const ppu2c0x_interface nes_ppu_interface =
449{
450   0,
451   0,
452   PPU_MIRROR_NONE,
453   ppu_nmi
454};
455
456static const floppy_config nes_floppy_config =
457{
458   DEVCB_NULL,
459   DEVCB_NULL,
460   DEVCB_NULL,
461   DEVCB_NULL,
462   DEVCB_NULL,
463   FLOPPY_STANDARD_5_25_DSHD,
464   FLOPPY_OPTIONS_NAME(nes_only),
465   NULL
466};
467
468
469static MACHINE_CONFIG_START( nes, nes_state )
470   /* basic machine hardware */
471   MCFG_CPU_ADD("maincpu", N2A03, NTSC_CLOCK)
472   MCFG_CPU_PROGRAM_MAP(nes_map)
473
474   MCFG_MACHINE_START( nes )
475   MCFG_MACHINE_RESET( nes )
476
477   MCFG_SCREEN_ADD("screen", RASTER)
478   MCFG_SCREEN_REFRESH_RATE(60.098)
479   // This isn't used so much to calulate the vblank duration (the PPU code tracks that manually) but to determine
480   // the number of cycles in each scanline for the PPU scanline timer. Since the PPU has 20 vblank scanlines + 2
481   // non-rendering scanlines, we compensate. This ends up being 2500 cycles for the non-rendering portion, 2273
482   // cycles for the actual vblank period.
483   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC((113.66/(NTSC_CLOCK/1000000)) * (PPU_VBLANK_LAST_SCANLINE_NTSC-PPU_VBLANK_FIRST_SCANLINE+1+2)))
484   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
485   MCFG_SCREEN_SIZE(32*8, 262)
486   MCFG_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 0*8, 30*8-1)
487   MCFG_SCREEN_UPDATE(nes)
488
489   MCFG_PALETTE_INIT(nes)
490   MCFG_VIDEO_START(nes)
491
492   MCFG_PALETTE_LENGTH(4*16*8)
493
494   MCFG_PPU2C02_ADD( "ppu", nes_ppu_interface )
495
496   /* sound hardware */
497   MCFG_SPEAKER_STANDARD_MONO("mono")
498   MCFG_SOUND_ADD("nessound", NES, NTSC_CLOCK)
499   MCFG_SOUND_CONFIG(nes_apu_interface)
500   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90)
501
502   MCFG_CARTSLOT_ADD("cart")
503   MCFG_CARTSLOT_EXTENSION_LIST("nes,unf")
504   MCFG_CARTSLOT_MANDATORY
505   MCFG_CARTSLOT_INTERFACE("nes_cart")
506   MCFG_CARTSLOT_LOAD(nes_cart)
507   MCFG_CARTSLOT_PARTIALHASH(nes_partialhash)
508   MCFG_SOFTWARE_LIST_ADD("cart_list","nes")
509MACHINE_CONFIG_END
510
511static MACHINE_CONFIG_DERIVED( nespal, nes )
512
513   /* basic machine hardware */
514   MCFG_CPU_MODIFY( "maincpu" )
515   MCFG_CPU_CLOCK( PAL_CLOCK )
516
517   MCFG_DEVICE_REMOVE( "ppu" )
518   MCFG_PPU2C07_ADD( "ppu", nes_ppu_interface )
519
520   /* video hardware */
521   MCFG_SCREEN_MODIFY("screen")
522   MCFG_SCREEN_REFRESH_RATE(53.355)
523   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC((106.53/(PAL_CLOCK/1000000)) * (PPU_VBLANK_LAST_SCANLINE_PAL-PPU_VBLANK_FIRST_SCANLINE+1+2)))
524   MCFG_VIDEO_START(nes)
525
526   /* sound hardware */
527   MCFG_SOUND_REPLACE("nessound", NES, PAL_CLOCK)
528   MCFG_SOUND_CONFIG(nes_apu_interface)
529   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90)
530MACHINE_CONFIG_END
531
532static MACHINE_CONFIG_DERIVED( dendy, nes )
533
534   /* basic machine hardware */
535   MCFG_CPU_MODIFY( "maincpu" )
536   MCFG_CPU_CLOCK( 26601712/15 ) /* 26.601712MHz / 15 == 1.77344746666... MHz */
537
538   MCFG_DEVICE_REMOVE( "ppu" )
539   MCFG_PPU2C07_ADD( "ppu", nes_ppu_interface )
540
541   /* video hardware */
542   MCFG_SCREEN_MODIFY("screen")
543   MCFG_SCREEN_REFRESH_RATE(50.00697796827)
544   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC((106.53/(PAL_CLOCK/1000000)) * (PPU_VBLANK_LAST_SCANLINE_PAL-PPU_VBLANK_FIRST_SCANLINE+1+2)))
545   MCFG_VIDEO_START(nes)
546
547   /* sound hardware */
548   MCFG_SOUND_REPLACE("nessound", NES, 26601712/15) /* 26.601712MHz / 15 == 1.77344746666... MHz */
549   MCFG_SOUND_CONFIG(nes_apu_interface)
550   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90)
551MACHINE_CONFIG_END
552
553static MACHINE_CONFIG_DERIVED( famicom, nes )
554
555   MCFG_CARTSLOT_MODIFY("cart")
556   MCFG_CARTSLOT_EXTENSION_LIST("nes,unf")
557   MCFG_CARTSLOT_NOT_MANDATORY
558   MCFG_CARTSLOT_LOAD(nes_cart)
559   MCFG_CARTSLOT_PARTIALHASH(nes_partialhash)
560
561   MCFG_FLOPPY_DRIVE_ADD(FLOPPY_0, nes_floppy_config)
562MACHINE_CONFIG_END
563
564
565/* rom regions are just place-holders: they get removed and re-allocated when a cart is loaded */
566ROM_START( nes )
567   ROM_REGION( 0x10000, "maincpu", ROMREGION_ERASE00 )  /* Main RAM + program banks */
568   ROM_REGION( 0x2000,  "gfx1", ROMREGION_ERASE00 )  /* VROM */
569   ROM_REGION( 0x4000,  "gfx2", ROMREGION_ERASE00 )  /* VRAM */
570   ROM_REGION( 0x800,   "gfx3", ROMREGION_ERASE00 )  /* CI RAM */
571ROM_END
572
573ROM_START( nespal )
574   ROM_REGION( 0x10000, "maincpu", ROMREGION_ERASE00 )  /* Main RAM + program banks */
575   ROM_REGION( 0x2000,  "gfx1", ROMREGION_ERASE00 )  /* VROM */
576   ROM_REGION( 0x4000,  "gfx2", ROMREGION_ERASE00 )  /* VRAM */
577   ROM_REGION( 0x800,   "gfx3", ROMREGION_ERASE00 )  /* CI RAM */
578ROM_END
579
580ROM_START( famicom )
581   ROM_REGION( 0x10000, "maincpu", 0 )  /* Main RAM + program banks */
582   ROM_LOAD_OPTIONAL( "disksys.rom", 0xe000, 0x2000, CRC(5e607dcf) SHA1(57fe1bdee955bb48d357e463ccbf129496930b62) )
583
584   ROM_REGION( 0x2000,  "gfx1", ROMREGION_ERASE00 )  /* VROM */
585   ROM_REGION( 0x4000,  "gfx2", ROMREGION_ERASE00 )  /* VRAM */
586   ROM_REGION( 0x800,   "gfx3", ROMREGION_ERASE00 )  /* CI RAM */
587ROM_END
588
589#define rom_fami_key rom_famicom
590
591ROM_START( famitwin )
592   ROM_REGION( 0x10000, "maincpu", 0 )  /* Main RAM + program banks */
593   ROM_LOAD_OPTIONAL( "disksyst.rom", 0xe000, 0x2000, CRC(4df24a6c) SHA1(e4e41472c454f928e53eb10e0509bf7d1146ecc1) )
594
595   ROM_REGION( 0x2000,  "gfx1", ROMREGION_ERASE00 )  /* VROM */
596   ROM_REGION( 0x4000,  "gfx2", ROMREGION_ERASE00 )  /* VRAM */
597   ROM_REGION( 0x800,   "gfx3", ROMREGION_ERASE00 )  /* CI RAM */
598ROM_END
599
600ROM_START( m82 )
601   ROM_REGION( 0x14000, "maincpu", 0 )  /* Main RAM + program banks */
602   /* Banks to be mapped at 0xe000? More investigations needed... */
603   ROM_LOAD( "m82_v1_0.bin", 0x10000, 0x4000, CRC(7d56840a) SHA1(cbd2d14fa073273ba58367758f40d67fd8a9106d) )
604
605   ROM_REGION( 0x2000,  "gfx1", ROMREGION_ERASE00 )  /* VROM */
606   ROM_REGION( 0x4000,  "gfx2", ROMREGION_ERASE00 )  /* VRAM */
607   ROM_REGION( 0x800,   "gfx3", ROMREGION_ERASE00 )  /* CI RAM */
608ROM_END
609
610// see http://www.disgruntleddesigner.com/chrisc/drpcjr/index.html
611// and http://www.disgruntleddesigner.com/chrisc/drpcjr/DrPCJrMemMap.txt
612ROM_START( drpcjr )
613   ROM_REGION( 0x18000, "maincpu", 0 )  /* Main RAM + program banks */
614   /* 4 banks to be mapped in 0xe000-0xffff (or 8 banks to be mapped in 0xe000-0xefff & 0xf000-0xffff).
615    Banks selected by writing at 0x4180 */
616   ROM_LOAD("drpcjr_bios.bin", 0x10000, 0x8000, CRC(c8fbef89) SHA1(2cb0a817b31400cdf27817d09bae7e69f41b062b) )   // bios vers. 1.0a
617   // Not sure if we should support this: hacked version 1.5a by Chris Covell with bugfixes and GameGenie support
618//  ROM_LOAD("drpcjr_v1_5_gg.bin", 0x10000, 0x8000, CRC(98f2033b) SHA1(93c114da787a19279d1a46667c2f69b49e25d4f1) )
619
620   ROM_REGION( 0x2000,  "gfx1", ROMREGION_ERASE00 )  /* VROM */
621   ROM_REGION( 0x4000,  "gfx2", ROMREGION_ERASE00 )  /* VRAM */
622   ROM_REGION( 0x800,   "gfx3", ROMREGION_ERASE00 )  /* CI RAM */
623ROM_END
624
625ROM_START( dendy )
626   ROM_REGION( 0x10000, "maincpu", ROMREGION_ERASE00 )  /* Main RAM + program banks */
627   ROM_REGION( 0x2000,  "gfx1", ROMREGION_ERASE00 )  /* VROM */
628   ROM_REGION( 0x4000,  "gfx2", ROMREGION_ERASE00 )  /* VRAM */
629   ROM_REGION( 0x800,   "gfx3", ROMREGION_ERASE00 )  /* CI RAM */
630ROM_END
631
632/***************************************************************************
633
634  Game driver(s)
635
636***************************************************************************/
637
638/*     YEAR  NAME      PARENT  COMPAT MACHINE   INPUT    INIT    COMPANY       FULLNAME */
639CONS( 1985, nes,       0,      0,     nes,      nes,     0,       "Nintendo",  "Nintendo Entertainment System / Famicom (NTSC)", GAME_IMPERFECT_GRAPHICS )
640CONS( 1987, nespal,    nes,    0,     nespal,   nes,     0,       "Nintendo",  "Nintendo Entertainment System (PAL)", GAME_IMPERFECT_GRAPHICS )
641CONS( 1983, famicom,   nes,    0,     famicom,  famicom, famicom, "Nintendo",  "Famicom (w/ Disk System add-on)", GAME_IMPERFECT_GRAPHICS )
642CONS( 1983, fami_key,  nes,    0,     famicom,  famikey, famicom, "Nintendo",  "Famicom (w/ Disk System add-on + Keyboard add-on)", GAME_IMPERFECT_GRAPHICS )
643CONS( 1986, famitwin,  nes,    0,     famicom,  famicom, famicom, "Sharp",     "Famicom Twin", GAME_IMPERFECT_GRAPHICS )
644CONS( 198?, m82,       nes,    0,     nes,      nes,     0,       "Nintendo",  "M82 Display Unit", GAME_IMPERFECT_GRAPHICS )
645CONS( 1996, drpcjr,    nes,    0,     famicom,  famicom, famicom, "Bung",      "Doctor PC Jr", GAME_IMPERFECT_GRAPHICS )
646CONS( 1992, dendy,     nes,    0,     dendy,    nes,     0,       "Steepler",  "Dendy Classic", GAME_IMPERFECT_GRAPHICS )
src/mess/drivers/msx.c
r11460r11461
1/*
2** msx.c : driver for MSX
3**
4** Todo:
5** - Add support for other MSX models (de,fr,jp,ru etc.)
6
7This following list is probably incomplete. Corrections are welcome.
8
9Al Alamiah AX-170
10Al Alamiah AX-350
11Al Alamiah AX-370
12Canon V-10
13Canon V-20
14Ciel Expert 3 IDE
15Ciel Expert 3 Turbo
16Daewoo CPC-300
17Daewoo CPC-400
18Daewoo CPC-400S
19Daewoo DPC-100
20Daewoo DPC-180
21Daewoo DPC-200
22Goldstar FC-200
23Gradiente Expert 1.0
24Gradiente Expert 1.1
25Gradiente Expert 1.3
26Gradiente Expert 2.0
27Gradiente Expert DDPlus
28Gradiente Expert Plus
29JVC HC-7GB
30Mitsubishi ML-F80
31Mitsubishi ML-FX1
32National CF-1200
33National CF-2000
34National CF-2700
35National CF-3000
36National CF-3300
37National FS-1300
38National FS-4000
39National FS-4500
40National FS-4600
41National FS-4700
42National FS-5000
43National FS-5500F1
44National FS-5500F2
45Panasonic FS-A1
46Panasonic FS-A1 MK2
47Panasonic FS-A1F
48Panasonic FS-A1FM
49Panasonic FS-A1FX
50Panasonic FS-A1GT
51Panasonic FS-A1ST
52Panasonic FS-A1WSX
53Panasonic FS-A1WX
54Philips NMS-801
55Philips NMS-8220
56Philips NMS-8245
57Philips NMS-8245F
58Philips NMS-8250
59Philips NMS-8255
60Philips NMS-8280
61Philips NMS-8280G
62Philips VG-8000
63Philips VG-8010
64Philips VG-8010F
65Philips VG-8020-00
66Philips VG-8020-20
67Philips VG-8020-40
68Philips VG-8230
69Philips VG-8235
70Philips VG-8235F
71Philips VG-8240
72===============
73
74PCB Layout missing
75
76
77Pioneer PX-7
78============
79
80|---------------------------------------|
81|  CN1     CN2                          |
82|                                       |
83|                                       |
84|  IC33                                 |---------------------------------|
85|                                                      CN3                |
86|   IC32   IC34            IC38  IC40                                     |
87|                                                               IC20      |
88|   IC15   IC18  IC43      IC8   IC35   IC6     |----IC3---|              |
89|                                               |----------|    IC21      |
90|   IC16   IC19  |---IC13---|    IC7    IC10                              |
91|                |----------|                   IC36  IC29      ---       |
92|   IC17   IC14                                     X2          | |       |
93|                |--IC12---|     |----IC1-----|       IC37      |I|       |
94|   IC28   IC11  |---------|     |------------|   X1            |C|       |
95|                                                               |2|       |
96|  |----IC4----| |----IC5----|   IC39  IC9      IC42  IC44      | |       |
97|  |-----------| |-----------|                                  ---       |
98|                                                                         |
99|       IC45   IC31    IC30      IC41                                     |
100|                                                                         |
101|  CN4 CN5  CN6  CN7                                  CN8                 |
102|-------------------------------------------------------------------------|
103
104Notes:
105  X1 - 3.579MHz
106  X2 - 500kHz
107  IC1 - Sharp LH0080A Z80A-CPU-D
108  IC2 - TMS91289NL
109  IC3 - MB111S112  Z10 (500kHz)
110  IC4  - M5L8255AP-5
111  IC5  - YM2149F
112  IC6,IC7,IC8,IC10,IC45 - SN74LS367AN
113  IC9 - SN74LS245N
114  IC11,IC34 - SN74LS139N
115  IC12 - YM2301-23908 / 53 18 85 A (might indicate a version)
116  IC13 - Pioneer PD5031 2364-213 514100 (M5L2764-213)
117  IC14,IC17,IC30,IC31 - SN74LS157N
118  IC15-IC19 - MB81416-12
119  IC20,IC21 - TMS4416-I5NL
120  IC28 - SN74LS153N
121  IC29 - SN74LS02N
122  IC32 - SN74LS374N
123  IC33 - M5218P
124  IC35 - SN74LS74AN
125  IC36 - SN74LS30N
126  IC37-IC39 - SN74LS04N
127  IC40,IC41 - SN74LS05N
128  IC42 - SN74LS08N
129  IC43,IC44 - SN74LS32N
130  CN1 - Printer
131  CN2 - Cassette recorder
132  CN3 - Expansion slot
133  CN4 - Keyboard
134  CN5 - Keyboard
135  CN6 - Controller #1
136  CN7 - Controller #2
137  CN8 - Expansion slot
138
139
140Sanyo MPC-100
141Sanyo PHC-28S
142Sanyo Wavy PHC-23
143Sanyo Wavy PHC-35J
144Sanyo Wavy PHC70FD1
145Sanyo Wavy PHC70FD2
146Sharp Epcom HotBit 1.1
147Sharp Epcom HotBit 1.2
148Sharp Epcom HotBit 1.3b
149Sharp Epcom HotBit 1.3p
150Sharp Epcom HotBit 2.0
151Sony HB-10P
152Sony HB-201
153Sony HB-201P
154Sony HB-501P
155Sony HB-55D
156Sony HB-55P
157Sony HB-75D
158Sony HB-75P
159Sony HB-F1
160Sony HB-F1II
161Sony HB-F1XD
162Sony HB-F1XD MK2
163Sony HB-F1XDJ
164Sony HB-F1XV
165Sony HB-F5
166Sony HB-F500
167Sony HB-F500P
168Sony HB-F700D
169Sony HB-F700F
170Sony HB-F700P
171Sony HB-F700S
172Sony HB-F900
173Sony HB-F9P
174Sony HB-F9S
175Sony HB-G900AP
176Sony HB-G900P
177Sony HB-T7
178Spectravideo SVI-728
179Spectravideo SVI-738
180Talent DPC-200
181Talent DPC-200A
182Talent TPC-310
183==============
184
185PCB Layouts missing
186
187
188Toshiba HX-10
189=============
190
191Code on PCB: MSX TUK
192        |---------------------------|-------------------|-------------|
193        |   CN1  CN2  CN3  CN4               CN5                      |
194        |                        |---------------------------|        |
195        |                        |---------------------------|        |
196        |                                    CN6                      |
197        |                        IC40                                 |
198        |                                                         CN7 |
199        |                      IC38     IC32     IC33     IC37        |
200        |                                                             |
201        |                      Q2       IC31     IC34     IC35        |
202        |    Q1                                                   CN8 |
203        |                                                 IC39        |
204        |   |--IC15------| |--IC2----|   |----IC1-----|               |
205        |   |------------| |---------|   |------------|               |
206        |                                                 IC30        |
207        |                 IC3    IC4                              CN9 |
208        |                               |-----IC15-------|            |
209        |  IC17   IC18    IC7    IC8    |----------------|            |
210        |                                                 IC27        |
211        |  IC19   IC20    IC9    IC10   |----IC25------|              |
212|----|  |                               |--------------|  IC26        |
213| Q  |  |  IC21   IC22    IC11   IC12                                 |
214|    |  |                                                             |
215| S  |  |  IC23   IC24    IC13   IC14    IC29             IC28        |
216|  L |  |                                                             |
217|    |  |                                 CN11   CN10                 |
218|----|  |-------------------------------------------------------------|
219
220Notes:
221  Mainboard components:
222   IC1               - Sharp LH0080A Z80A-CPU-D
223   IC2               - MB83256
224   IC3,IC4,IC27,IC28 - Texas Instruments SN74LS157N
225   IC7-IC14          - HM4864AP
226   IC15              - Toshiba TCX-1007 (64pin custom chip)
227   IC16              - 40pin chip covered with some kind of heatsink(?), probably TMS9929A
228   IC17-IC24         - 4116-3
229   IC25              - AY-3-8910A
230   IC26              - SN74LS09N
231   IC29              - HD74LS145P
232   IC30-IC34         - M74LS367AP
233   IC35              - MB74LS74A
234   IC37              - HD74LS373P
235   IC38              - Toshiba TC74HCU04P
236   IC39              - HD74LS08P
237   IC40              - TA75559P
238   Q1                - 10687.5
239   Q2                - 3579545
240   CN1               - Cassette connecter
241   CN2               - RF connector
242   CN3               - Audio connector
243   CN4               - Video connector
244   CN5               - Expansion connector
245   CN6               - Cartridge connector
246   CN7               - Printer connector
247   CN8               - Joystick 2 connector
248   CN9               - Joystick 1 connector
249   CN10              - Keyboard connector 1
250   CN11              - Keyboard connector 2
251
252  Extra pcb (video related?) components::
253   Q - 4.433619
254   S - 74LS04
255   L - LVA510
256
257
258Toshiba HX-10S
259Toshiba HX-20
260Toshiba HX-23
261Toshiba HX-23F
262Yamaha CX5M
263Yamaha CX5M-128
264Yamaha CX7M
265Yamaha CX7M-128
266Yamaha YIS-303
267Yamaha YIS-503
268Yamaha YIS-503M
269Yamaha YIS-503
270Yashica YC-64
271=============
272
273PCB Layouts missing
274
275
276*/
277
278#include "emu.h"
279#include "cpu/z80/z80.h"
280#include "deprecat.h"
281#include "machine/i8255.h"
282#include "machine/rp5c01.h"
283#include "machine/wd17xx.h"
284#include "video/tms9928a.h"
285#include "video/v9938.h"
286#include "machine/ctronics.h"
287#include "includes/msx_slot.h"
288#include "includes/msx.h"
289#include "imagedev/flopdrv.h"
290#include "imagedev/cartslot.h"
291#include "imagedev/cassette.h"
292#include "formats/fmsx_cas.h"
293#include "formats/msx_dsk.h"
294#include "sound/ay8910.h"
295#include "sound/dac.h"
296#include "sound/wave.h"
297#include "sound/k051649.h"
298#include "sound/2413intf.h"
299
300static ADDRESS_MAP_START (msx_memory_map, AS_PROGRAM, 8)
301   AM_RANGE( 0x0000, 0x1fff) AM_READ_BANK("bank1") AM_WRITE( msx_page0_w )
302   AM_RANGE( 0x2000, 0x3fff) AM_READ_BANK("bank2") AM_WRITE( msx_page0_1_w )
303   AM_RANGE( 0x4000, 0x5fff) AM_READ_BANK("bank3") AM_WRITE( msx_page1_w )
304   AM_RANGE( 0x6000, 0x7ff7) AM_READ_BANK("bank4") AM_WRITE( msx_page1_1_w )
305   AM_RANGE( 0x7ff8, 0x7fff) AM_READ_BANK("bank5") AM_WRITE( msx_page1_2_w )
306   AM_RANGE( 0x8000, 0x97ff) AM_READ_BANK("bank6") AM_WRITE( msx_page2_w )
307   AM_RANGE( 0x9800, 0x9fff) AM_READ_BANK("bank7") AM_WRITE(msx_page2_1_w )
308   AM_RANGE( 0xa000, 0xb7ff) AM_READ_BANK("bank8") AM_WRITE( msx_page2_2_w )
309   AM_RANGE( 0xb800, 0xbfff) AM_READ_BANK("bank9") AM_WRITE( msx_page2_3_w )
310   AM_RANGE( 0xc000, 0xdfff) AM_READ_BANK("bank10") AM_WRITE( msx_page3_w )
311   AM_RANGE( 0xe000, 0xfffe) AM_READ_BANK("bank11") AM_WRITE( msx_page3_1_w )
312   AM_RANGE( 0xffff, 0xffff) AM_READWRITE( msx_sec_slot_r, msx_sec_slot_w )
313ADDRESS_MAP_END
314
315
316static WRITE8_DEVICE_HANDLER( msx_ay8910_w )
317{
318   if ( offset & 1 )
319      ay8910_data_w( device, offset, data );
320   else
321      ay8910_address_w( device, offset, data );
322}
323
324
325static ADDRESS_MAP_START (msx_io_map, AS_IO, 8)
326   ADDRESS_MAP_UNMAP_HIGH
327   ADDRESS_MAP_GLOBAL_MASK(0xff)
328   AM_RANGE( 0x77, 0x77) AM_WRITE( msx_90in1_w )
329   AM_RANGE( 0x7c, 0x7d) AM_WRITE( msx_fmpac_w )
330   AM_RANGE( 0x90, 0x90) AM_DEVREADWRITE("centronics", msx_printer_status_r, msx_printer_strobe_w)
331   AM_RANGE( 0x91, 0x91) AM_DEVWRITE("centronics", msx_printer_data_w)
332   AM_RANGE( 0xa0, 0xa7) AM_DEVREADWRITE("ay8910", ay8910_r, msx_ay8910_w )
333   AM_RANGE( 0xa8, 0xab) AM_DEVREADWRITE_MODERN("ppi8255", i8255_device, read, write)
334   AM_RANGE( 0x98, 0x98) AM_READWRITE( TMS9928A_vram_r, TMS9928A_vram_w )
335   AM_RANGE( 0x99, 0x99) AM_READWRITE( TMS9928A_register_r, TMS9928A_register_w )
336   AM_RANGE( 0xd8, 0xd9) AM_READWRITE( msx_kanji_r, msx_kanji_w )
337ADDRESS_MAP_END
338
339
340static ADDRESS_MAP_START (msx2_io_map, AS_IO, 8)
341   ADDRESS_MAP_UNMAP_HIGH
342   ADDRESS_MAP_GLOBAL_MASK(0xff)
343   AM_RANGE( 0x77, 0x77) AM_WRITE( msx_90in1_w )
344   AM_RANGE( 0x7c, 0x7d) AM_WRITE( msx_fmpac_w )
345   AM_RANGE( 0x90, 0x90) AM_DEVREADWRITE("centronics", msx_printer_status_r, msx_printer_strobe_w)
346   AM_RANGE( 0x91, 0x91) AM_DEVWRITE("centronics", msx_printer_data_w)
347   AM_RANGE( 0xa0, 0xa7) AM_DEVREADWRITE("ay8910", ay8910_r, msx_ay8910_w )
348   AM_RANGE( 0xa8, 0xab) AM_DEVREADWRITE_MODERN("ppi8255", i8255_device, read, write)
349   AM_RANGE( 0x98, 0x98) AM_READWRITE( v9938_0_vram_r, v9938_0_vram_w )
350   AM_RANGE( 0x99, 0x99) AM_READWRITE( v9938_0_status_r, v9938_0_command_w )
351   AM_RANGE( 0x9a, 0x9a) AM_WRITE( v9938_0_palette_w )
352   AM_RANGE( 0x9b, 0x9b) AM_WRITE( v9938_0_register_w )
353   AM_RANGE( 0xb4, 0xb4) AM_WRITE( msx_rtc_latch_w )
354   AM_RANGE( 0xb5, 0xb5) AM_READWRITE( msx_rtc_reg_r, msx_rtc_reg_w )
355   AM_RANGE( 0xd8, 0xd9) AM_READWRITE( msx_kanji_r, msx_kanji_w )
356   AM_RANGE( 0xfc, 0xff) AM_READWRITE( msx_ram_mapper_r, msx_ram_mapper_w )
357ADDRESS_MAP_END
358
359
360static INPUT_PORTS_START( msx_dips )
361   PORT_START("JOY0")
362   PORT_BIT (0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP)
363   PORT_BIT (0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN)
364   PORT_BIT (0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT)
365   PORT_BIT (0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT)
366   PORT_BIT (0x10, IP_ACTIVE_LOW, IPT_BUTTON1)
367   PORT_BIT (0x20, IP_ACTIVE_LOW, IPT_BUTTON2)
368   PORT_BIT (0x40, IP_ACTIVE_LOW, IPT_UNUSED)
369   PORT_DIPNAME( 0x80, 0, "Game port 1")
370   PORT_DIPSETTING(    0x00, DEF_STR( Joystick ))
371   PORT_DIPSETTING(    0x80, "Mouse")
372
373   PORT_START("JOY1")
374   PORT_BIT (0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP)     PORT_PLAYER(2)
375   PORT_BIT (0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN)     PORT_PLAYER(2)
376   PORT_BIT (0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT)     PORT_PLAYER(2)
377   PORT_BIT (0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT)      PORT_PLAYER(2)
378   PORT_BIT (0x10, IP_ACTIVE_LOW, IPT_BUTTON1)     PORT_PLAYER(2)
379   PORT_BIT (0x20, IP_ACTIVE_LOW, IPT_BUTTON2)     PORT_PLAYER(2)
380   PORT_BIT (0x40, IP_ACTIVE_LOW, IPT_UNUSED)
381   PORT_DIPNAME( 0x80, 0, "Game port 2")
382   PORT_DIPSETTING( 0x00, DEF_STR( Joystick ))
383   PORT_DIPSETTING( 0x80, "Mouse")
384
385   PORT_START("DSW")
386   PORT_DIPNAME( 0x40, 0, "Swap game port 1 and 2")
387   PORT_DIPSETTING( 0, DEF_STR( No ) )
388   PORT_DIPSETTING( 0x40, DEF_STR( Yes ) )
389   PORT_DIPNAME( 0x80, 0, "SIMPL")
390   PORT_DIPSETTING( 0x00, DEF_STR ( Off ) )
391   PORT_DIPSETTING( 0x80, DEF_STR ( On ) )
392   PORT_DIPNAME( 0x20, 0x20, "Enforce 4/8 sprites/line")
393   PORT_DIPSETTING( 0, DEF_STR( No ) )
394   PORT_DIPSETTING( 0x20, DEF_STR( Yes ) )
395   PORT_DIPNAME ( 0x03, 0, "Render resolution")
396   PORT_DIPSETTING( 0, DEF_STR( High ))
397   PORT_DIPSETTING( 1, DEF_STR( Low ))
398   PORT_DIPSETTING( 2, "Auto" )
399
400   PORT_START("MOUSE0")
401   PORT_BIT( 0xff00, 0x00, IPT_TRACKBALL_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1)
402   PORT_BIT( 0x00ff, 0x00, IPT_TRACKBALL_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1)
403
404   PORT_START("MOUSE1")
405   PORT_BIT( 0xff00, 0x00, IPT_TRACKBALL_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(2)
406   PORT_BIT( 0x00ff, 0x00, IPT_TRACKBALL_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(2)
407INPUT_PORTS_END
408
409
410/* 2008-05 FP: About keyboards
411
412Even if some later Philips (and maybe others) models started to use a layout similar to current
413PC keyboards, common MSX keyboards have a couple of keys which do not fit usual mapping
414- the key in the 1st row before 'Backspace', 3rd key from '0', here re-mapped to KEYCODE_BACKSLASH2
415- the last key in the 4th row, 4th key from 'M' (not counting Shift), here re-mapped to KEYCODE_TILDE
416
417These keys corresponds to the following symbols
418
419    input_port  | msx   | msxuk | msxjp | msxkr |hotbit |expert |
420    -------------------------------------------------------------
421    BACKSLASH2  |  \ |  |  \ |  |  ? |  | won | |  \ ^  |  { }  |
422    -------------------------------------------------------------
423    TILDE       |  DK*  |  DK*  |  _    |  _    |  < >  |  / ?  |
424
425* DK = "Dead Key"
426Notice that 'expert' input_ports covers both versions 1.0 and 1.1.
427msx2 input_ports have the same symbols as their msx counterparts.
428
429TO DO:
430- check Expert 1.0 layout with the real thing
431- check Korean layout
432- fix natural support in systems using msx inputs but with different mapping
433(these systems could have different uses for keys mapped at the following
434locations: COLON, QUOTE, BACKSLASH, OPENBRACE, CLOSEBRACE, BACKSLASH2, TILDE.
435The corresponding symbols would not work properly in -natural mode).
436
437Additional note about natural keyboard support: currently,
438- "Keypad ," is not mapped
439- "Graph" is mapped to 'F6' (this key could be labeled "L Graph")
440- "Code" is mapped to 'F7' (this key could be labeled "R Graph", "Kana" or "Hangul")
441- "Stop" is mapped to 'F8'
442- "Select" is mapped to 'F9'
443*/
444
445#define KEYB_ROW0   \
446   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_0) PORT_CHAR('0') PORT_CHAR(')')   \
447   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')   \
448   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('@')   \
449   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')   \
450   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')   \
451   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')   \
452   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('^')   \
453   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('&')
454
455#define KEYB_EXPERT11_ROW0    \
456   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_0) PORT_CHAR('0') PORT_CHAR(')')   \
457   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')   \
458   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('"')   \
459   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')   \
460   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')   \
461   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')   \
462   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('^')   \
463   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('&')
464
465#define KEYB_HOTBIT_ROW0    \
466   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_0) PORT_CHAR('0') PORT_CHAR(')')   \
467   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')   \
468   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('@')   \
469   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')   \
470   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')   \
471   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')   \
472   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('"')   \
473   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('&')
474
475#define KEYB_ROW1   \
476   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_8)            PORT_CHAR('8') PORT_CHAR('*')   \
477   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_9)            PORT_CHAR('9') PORT_CHAR('(')   \
478   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS)         PORT_CHAR('-') PORT_CHAR('_')   \
479   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_EQUALS)      PORT_CHAR('=') PORT_CHAR('+')   \
480   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH2)   PORT_CHAR('\\') PORT_CHAR('|')   \
481   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_OPENBRACE)      PORT_CHAR('[') PORT_CHAR('{')   \
482   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR(']') PORT_CHAR('}')   \
483   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COLON)         PORT_CHAR(';') PORT_CHAR(':')
484
485#define KEYB_HOTBIT_ROW1    \
486   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_8)            PORT_CHAR('8') PORT_CHAR('*')   \
487   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_9)            PORT_CHAR('9') PORT_CHAR('(')   \
488   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS)         PORT_CHAR('-') PORT_CHAR('_')   \
489   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_EQUALS)      PORT_CHAR('=') PORT_CHAR('+')   \
490   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH2)   PORT_CHAR('\\') PORT_CHAR('^')   \
491   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_OPENBRACE)      PORT_CHAR('\'') PORT_CHAR('`')   \
492   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR('"') PORT_CHAR('`')   \
493   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COLON)         PORT_CHAR('\xC7') PORT_CHAR('\xE7')
494
495#define KEYB_EXPERT11_ROW1    \
496   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_8)            PORT_CHAR('8') PORT_CHAR('\'')   \
497   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_9)            PORT_CHAR('9') PORT_CHAR('(')   \
498   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS)         PORT_CHAR('-') PORT_CHAR('_')   \
499   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_EQUALS)      PORT_CHAR('=') PORT_CHAR('+')   \
500   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH2)   PORT_CHAR('{') PORT_CHAR('}')   \
501   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_OPENBRACE)      PORT_CHAR('\'') PORT_CHAR('`')   \
502   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR('[') PORT_CHAR(']')   \
503   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE)         PORT_CHAR('~') PORT_CHAR('^')
504
505#define KEYB_ROW2   \
506   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE)      PORT_CHAR('\'') PORT_CHAR('"')   \
507   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH)   PORT_CHAR('`') PORT_CHAR('~')   \
508   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA)      PORT_CHAR(',') PORT_CHAR('<')   \
509   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP)      PORT_CHAR('.') PORT_CHAR('>')   \
510   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH)      PORT_CHAR('/') PORT_CHAR('?')   \
511   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("Dead Key") PORT_CODE(KEYCODE_TILDE)            \
512   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_A)         PORT_CHAR('a') PORT_CHAR('A')   \
513   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_B)         PORT_CHAR('b') PORT_CHAR('B')
514
515#define KEYB_HOTBIT_ROW2    \
516   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE)         PORT_CHAR('~') PORT_CHAR('^')   \
517   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH)      PORT_CHAR('[') PORT_CHAR(']')   \
518   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA)         PORT_CHAR(',') PORT_CHAR(';')   \
519   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP)         PORT_CHAR('.') PORT_CHAR(':')   \
520   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH)         PORT_CHAR('/') PORT_CHAR('?')   \
521   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_TILDE)         PORT_CHAR('<') PORT_CHAR('>')   \
522   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_A)            PORT_CHAR('a') PORT_CHAR('A')   \
523   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_B)            PORT_CHAR('b') PORT_CHAR('B')
524
525#define KEYB_EXPERT10_ROW2    \
526   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE)      PORT_CHAR('\'') PORT_CHAR('"')   \
527   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH)   PORT_CHAR('\xC7') PORT_CHAR('\xE7')   \
528   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA)      PORT_CHAR(',') PORT_CHAR('<')   \
529   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP)      PORT_CHAR('.') PORT_CHAR('>')   \
530   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH)      PORT_CHAR('/') PORT_CHAR('?')   \
531   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("Dead Key") PORT_CODE(KEYCODE_TILDE)            \
532   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_A)         PORT_CHAR('a') PORT_CHAR('A')   \
533   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_B)         PORT_CHAR('b') PORT_CHAR('B')
534
535#define KEYB_EXPERT11_ROW2    \
536   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH)   PORT_CHAR('*') PORT_CHAR('@')   \
537   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COLON)      PORT_CHAR('\xC7') PORT_CHAR('\xE7')   \
538   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA)      PORT_CHAR(',') PORT_CHAR('<')   \
539   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP)      PORT_CHAR('.') PORT_CHAR('>')   \
540   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_TILDE)      PORT_CHAR('/') PORT_CHAR('?')   \
541   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH)      PORT_CHAR(';') PORT_CHAR(':')   \
542   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_A)         PORT_CHAR('a') PORT_CHAR('A')   \
543   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_B)         PORT_CHAR('b') PORT_CHAR('B')
544
545#define KEYB_ROW3   \
546   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_C) PORT_CHAR('c') PORT_CHAR('C')   \
547   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_D) PORT_CHAR('d') PORT_CHAR('D')   \
548   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_E) PORT_CHAR('e') PORT_CHAR('E')   \
549   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_F) PORT_CHAR('f') PORT_CHAR('F')   \
550   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_G) PORT_CHAR('g') PORT_CHAR('G')   \
551   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_H) PORT_CHAR('h') PORT_CHAR('H')   \
552   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_I) PORT_CHAR('i') PORT_CHAR('I')   \
553   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_J) PORT_CHAR('j') PORT_CHAR('J')
554
555#define KEYB_ROW4   \
556   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_K) PORT_CHAR('k') PORT_CHAR('K')   \
557   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_L) PORT_CHAR('l') PORT_CHAR('L')   \
558   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_M) PORT_CHAR('m') PORT_CHAR('M')   \
559   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_N) PORT_CHAR('n') PORT_CHAR('N')   \
560   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_O) PORT_CHAR('o') PORT_CHAR('O')   \
561   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_P) PORT_CHAR('p') PORT_CHAR('P')   \
562   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_Q) PORT_CHAR('q') PORT_CHAR('Q')   \
563   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_R) PORT_CHAR('r') PORT_CHAR('R')
564
565#define KEYB_ROW5   \
566   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_S) PORT_CHAR('s') PORT_CHAR('S')   \
567   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_T) PORT_CHAR('t') PORT_CHAR('T')   \
568   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_U) PORT_CHAR('u') PORT_CHAR('U')   \
569   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_V) PORT_CHAR('v') PORT_CHAR('V')   \
570   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_W) PORT_CHAR('w') PORT_CHAR('W')   \
571   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_X) PORT_CHAR('x') PORT_CHAR('X')   \
572   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_Y) PORT_CHAR('y') PORT_CHAR('Y')   \
573   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_Z) PORT_CHAR('z') PORT_CHAR('Z')
574
575#define KEYB_ROW6   \
576   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LSHIFT)                  PORT_CHAR(UCHAR_SHIFT_1)         \
577   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LCONTROL)                  PORT_CHAR(UCHAR_SHIFT_2)         \
578   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("GRAPH") PORT_CODE(KEYCODE_PGUP)      PORT_CHAR(UCHAR_MAMEKEY(F6))      \
579   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CAPS") PORT_CODE(KEYCODE_CAPSLOCK)   PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))   \
580   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CODE") PORT_CODE(KEYCODE_PGDN)      PORT_CHAR(UCHAR_MAMEKEY(F7))      \
581   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F1  F6") PORT_CODE(KEYCODE_F1)      PORT_CHAR(UCHAR_MAMEKEY(F1))      \
582   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F2  F7") PORT_CODE(KEYCODE_F2)      PORT_CHAR(UCHAR_MAMEKEY(F2))      \
583   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F3  F8") PORT_CODE(KEYCODE_F3)      PORT_CHAR(UCHAR_MAMEKEY(F3))
584
585#define KEYB_EXPERT11_ROW6    \
586   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LSHIFT)                     PORT_CHAR(UCHAR_SHIFT_1)         \
587   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CONTROL") PORT_CODE(KEYCODE_LCONTROL)      PORT_CHAR(UCHAR_SHIFT_2)         \
588   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("L GRA") PORT_CODE(KEYCODE_PGUP)         PORT_CHAR(UCHAR_MAMEKEY(F6))      \
589   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CAPS LOCK") PORT_CODE(KEYCODE_CAPSLOCK)   PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))   \
590   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("R GRA") PORT_CODE(KEYCODE_PGDN)         PORT_CHAR(UCHAR_MAMEKEY(F7))      \
591   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F1  F6") PORT_CODE(KEYCODE_F1)         PORT_CHAR(UCHAR_MAMEKEY(F1))      \
592   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F2  F7") PORT_CODE(KEYCODE_F2)         PORT_CHAR(UCHAR_MAMEKEY(F2))      \
593   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F3  F8") PORT_CODE(KEYCODE_F3)         PORT_CHAR(UCHAR_MAMEKEY(F3))
594
595#define KEYB_ROW7   \
596   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F4  F9") PORT_CODE(KEYCODE_F4)      PORT_CHAR(UCHAR_MAMEKEY(F4))   \
597   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F5  F10") PORT_CODE(KEYCODE_F5)      PORT_CHAR(UCHAR_MAMEKEY(F5))   \
598   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_ESC)                     PORT_CHAR(UCHAR_MAMEKEY(ESC))   \
599   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_TAB)                     PORT_CHAR('\t')               \
600   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("STOP") PORT_CODE(KEYCODE_RCONTROL)   PORT_CHAR(UCHAR_MAMEKEY(F8))   \
601   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSPACE)                  PORT_CHAR(8)               \
602   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("SELECT") PORT_CODE(KEYCODE_END)      PORT_CHAR(UCHAR_MAMEKEY(F9))   \
603   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_ENTER)                     PORT_CHAR(13)
604
605#define KEYB_ROW8   \
606   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SPACE)               PORT_CHAR(' ')               \
607   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_HOME)               PORT_CHAR(UCHAR_MAMEKEY(HOME))   \
608   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_INSERT)            PORT_CHAR(UCHAR_MAMEKEY(INSERT))\
609   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("DEL") PORT_CODE(KEYCODE_DEL)   PORT_CHAR(UCHAR_MAMEKEY(DEL))   \
610   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LEFT)               PORT_CHAR(UCHAR_MAMEKEY(LEFT))   \
611   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_UP)               PORT_CHAR(UCHAR_MAMEKEY(UP))   \
612   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_DOWN)               PORT_CHAR(UCHAR_MAMEKEY(DOWN))   \
613   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_RIGHT)               PORT_CHAR(UCHAR_MAMEKEY(RIGHT))
614
615#define KEYB_ROW9   \
616   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_ASTERISK)   PORT_CHAR(UCHAR_MAMEKEY(ASTERISK))   \
617   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_PLUS_PAD)   PORT_CHAR(UCHAR_MAMEKEY(PLUS_PAD))   \
618   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH_PAD)   PORT_CHAR(UCHAR_MAMEKEY(SLASH_PAD))   \
619   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_0_PAD)      PORT_CHAR(UCHAR_MAMEKEY(0_PAD))      \
620   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_1_PAD)      PORT_CHAR(UCHAR_MAMEKEY(1_PAD))      \
621   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_2_PAD)      PORT_CHAR(UCHAR_MAMEKEY(2_PAD))      \
622   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_3_PAD)      PORT_CHAR(UCHAR_MAMEKEY(3_PAD))      \
623   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_4_PAD)      PORT_CHAR(UCHAR_MAMEKEY(4_PAD))
624
625#define KEYB_ROW10   \
626   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_5_PAD)      PORT_CHAR(UCHAR_MAMEKEY(5_PAD))      \
627   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_6_PAD)      PORT_CHAR(UCHAR_MAMEKEY(6_PAD))      \
628   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_7_PAD)      PORT_CHAR(UCHAR_MAMEKEY(7_PAD))      \
629   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_8_PAD)      PORT_CHAR(UCHAR_MAMEKEY(8_PAD))      \
630   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_9_PAD)      PORT_CHAR(UCHAR_MAMEKEY(9_PAD))      \
631   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS_PAD)   PORT_CHAR(UCHAR_MAMEKEY(MINUS_PAD))   \
632   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("Keypad ,") PORT_CODE(KEYCODE_ENTER_PAD)            \
633   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_DEL_PAD)   PORT_CHAR(UCHAR_MAMEKEY(DEL_PAD))
634
635static INPUT_PORTS_START( msx )
636   PORT_START("KEY0")
637   KEYB_ROW0
638   KEYB_ROW1
639
640   PORT_START("KEY1")
641   KEYB_ROW2
642   KEYB_ROW3
643
644   PORT_START("KEY2")
645   KEYB_ROW4
646   KEYB_ROW5
647
648   PORT_START("KEY3")
649   KEYB_ROW6
650   KEYB_ROW7
651
652   PORT_START("KEY4")
653   KEYB_ROW8
654   PORT_BIT (0xff00, IP_ACTIVE_LOW, IPT_UNUSED)
655
656   PORT_START("KEY5")
657   PORT_BIT (0xffff, IP_ACTIVE_LOW, IPT_UNUSED)
658
659   PORT_INCLUDE( msx_dips )
660INPUT_PORTS_END
661
662static INPUT_PORTS_START( msxuk )
663   PORT_START("KEY0")
664   KEYB_ROW0
665   KEYB_ROW1
666
667   PORT_START("KEY1")
668   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE)         PORT_CHAR('\'') PORT_CHAR('"')
669   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH)      PORT_CHAR('\xA3') PORT_CHAR('~')
670   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA)         PORT_CHAR(',') PORT_CHAR('<')
671   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP)         PORT_CHAR('.') PORT_CHAR('>')
672   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH)         PORT_CHAR('/') PORT_CHAR('?')
673   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("Dead Key") PORT_CODE(KEYCODE_TILDE)
674   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_A)            PORT_CHAR('a') PORT_CHAR('A')
675   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_B)            PORT_CHAR('b') PORT_CHAR('B')
676   KEYB_ROW3
677
678   PORT_START("KEY2")
679   KEYB_ROW4
680   KEYB_ROW5
681
682   PORT_START("KEY3")
683   KEYB_ROW6
684   KEYB_ROW7
685
686   PORT_START("KEY4")
687   KEYB_ROW8
688   PORT_BIT (0xff00, IP_ACTIVE_LOW, IPT_UNUSED)
689
690   PORT_START("KEY5")
691   PORT_BIT (0xffff, IP_ACTIVE_LOW, IPT_UNUSED)
692
693   PORT_INCLUDE( msx_dips )
694INPUT_PORTS_END
695
696#define KEYB_JAP_ROW0   \
697   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_0) PORT_CHAR('0')               \
698   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')   \
699   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('"')   \
700   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')   \
701   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')   \
702   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')   \
703   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('&')   \
704   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('\'')
705
706#define KEYB_JAP_ROW1   \
707   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_8)            PORT_CHAR('8') PORT_CHAR('(')   \
708   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_9)            PORT_CHAR('9') PORT_CHAR(')')   \
709   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS)         PORT_CHAR('-') PORT_CHAR('=')   \
710   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_EQUALS)      PORT_CHAR('^') PORT_CHAR('~')   \
711   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH2)   PORT_CHAR('\xA5') PORT_CHAR('|')\
712   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_OPENBRACE)      PORT_CHAR('@') PORT_CHAR('`')   \
713   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR('[') PORT_CHAR('{')   \
714   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COLON)         PORT_CHAR(';') PORT_CHAR('+')
715
716#define KEYB_KOR_ROW1   \
717   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_8)            PORT_CHAR('8') PORT_CHAR('(')   \
718   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_9)            PORT_CHAR('9') PORT_CHAR(')')   \
719   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS)         PORT_CHAR('-') PORT_CHAR('=')   \
720   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_EQUALS)      PORT_CHAR('^') PORT_CHAR('~')   \
721   PORT_BIT (0x1000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("\xE2\x82\xA9 |") PORT_CODE(KEYCODE_BACKSLASH2) PORT_CHAR(0xffe6) PORT_CHAR('|') \
722   PORT_BIT (0x2000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_OPENBRACE)      PORT_CHAR('@') PORT_CHAR('`')   \
723   PORT_BIT (0x4000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_CLOSEBRACE)   PORT_CHAR('[') PORT_CHAR('{')   \
724   PORT_BIT (0x8000, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COLON)         PORT_CHAR(';') PORT_CHAR('+')
725
726#define KEYB_JAP_ROW2   \
727   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE)      PORT_CHAR(':') PORT_CHAR('*')   \
728   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH)   PORT_CHAR(']') PORT_CHAR('}')   \
729   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA)      PORT_CHAR(',') PORT_CHAR('<')   \
730   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP)      PORT_CHAR('.') PORT_CHAR('>')   \
731   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH)      PORT_CHAR('/') PORT_CHAR('?')   \
732   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("_") PORT_CODE(KEYCODE_TILDE) PORT_CHAR('_')      \
733   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_A)         PORT_CHAR('a') PORT_CHAR('A')   \
734   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_B)         PORT_CHAR('b') PORT_CHAR('B')
735
736static INPUT_PORTS_START( msxjp )
737   PORT_START("KEY0")
738   KEYB_JAP_ROW0
739   KEYB_JAP_ROW1
740
741   PORT_START("KEY1")
742   KEYB_JAP_ROW2
743   KEYB_ROW3
744
745   PORT_START("KEY2")
746   KEYB_ROW4
747   KEYB_ROW5
748
749   PORT_START("KEY3")
750   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LSHIFT)                  PORT_CHAR(UCHAR_SHIFT_1)
751   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LCONTROL)                  PORT_CHAR(UCHAR_SHIFT_2)
752   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("GRAPH") PORT_CODE(KEYCODE_PGUP)      PORT_CHAR(UCHAR_MAMEKEY(F6))
753   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CAPS") PORT_CODE(KEYCODE_CAPSLOCK)   PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
754   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("KANA") PORT_CODE(KEYCODE_PGDN)      PORT_CHAR(UCHAR_MAMEKEY(F7))
755   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F1  F6") PORT_CODE(KEYCODE_F1)      PORT_CHAR(UCHAR_MAMEKEY(F1))
756   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F2  F7") PORT_CODE(KEYCODE_F2)      PORT_CHAR(UCHAR_MAMEKEY(F2))
757   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F3  F8") PORT_CODE(KEYCODE_F3)      PORT_CHAR(UCHAR_MAMEKEY(F3))
758   KEYB_ROW7
759
760   PORT_START("KEY4")
761   KEYB_ROW8
762   PORT_BIT (0xff00, IP_ACTIVE_LOW, IPT_UNUSED)
763
764   PORT_START("KEY5")
765   PORT_BIT (0xffff, IP_ACTIVE_LOW, IPT_UNUSED)
766
767   PORT_INCLUDE( msx_dips )
768INPUT_PORTS_END
769
770static INPUT_PORTS_START( msxkr )
771   PORT_START("KEY0")
772   KEYB_JAP_ROW0
773   KEYB_KOR_ROW1
774
775   PORT_START("KEY1")
776   KEYB_JAP_ROW2
777   KEYB_ROW3
778
779   PORT_START("KEY2")
780   KEYB_ROW4
781   KEYB_ROW5
782
783   PORT_START("KEY3")
784   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LSHIFT)                  PORT_CHAR(UCHAR_SHIFT_1)
785   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LCONTROL)                  PORT_CHAR(UCHAR_SHIFT_2)
786   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("GRAPH") PORT_CODE(KEYCODE_PGUP)      PORT_CHAR(UCHAR_MAMEKEY(F6))
787   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CAPS") PORT_CODE(KEYCODE_CAPSLOCK)   PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
788   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("Hangul") PORT_CODE(KEYCODE_PGDN)      PORT_CHAR(UCHAR_MAMEKEY(F7))
789   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F1  F6") PORT_CODE(KEYCODE_F1)      PORT_CHAR(UCHAR_MAMEKEY(F1))
790   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F2  F7") PORT_CODE(KEYCODE_F2)      PORT_CHAR(UCHAR_MAMEKEY(F2))
791   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F3  F8") PORT_CODE(KEYCODE_F3)      PORT_CHAR(UCHAR_MAMEKEY(F3))
792   KEYB_ROW7
793
794   PORT_START("KEY4")
795   KEYB_ROW8
796   PORT_BIT (0xff00, IP_ACTIVE_LOW, IPT_UNUSED)
797
798   PORT_START("KEY5")
799   PORT_BIT (0xffff, IP_ACTIVE_LOW, IPT_UNUSED)
800
801   PORT_INCLUDE( msx_dips )
802INPUT_PORTS_END
803
804static INPUT_PORTS_START( hotbit )
805   PORT_START("KEY0")
806   KEYB_HOTBIT_ROW0
807   KEYB_HOTBIT_ROW1
808
809   PORT_START("KEY1")
810   KEYB_HOTBIT_ROW2
811   KEYB_ROW3
812
813   PORT_START("KEY2")
814   KEYB_ROW4
815   KEYB_ROW5
816
817   PORT_START("KEY3")
818   KEYB_ROW6
819   KEYB_ROW7
820
821   PORT_START("KEY4")
822   KEYB_ROW8
823   PORT_BIT (0xff00, IP_ACTIVE_LOW, IPT_UNUSED)
824
825   PORT_START("KEY5")
826   PORT_BIT (0xffff, IP_ACTIVE_LOW, IPT_UNUSED)
827
828   PORT_INCLUDE( msx_dips )
829INPUT_PORTS_END
830
831/* 2008-05 FP: I guess these belong to the keypad */
832#define KEYB_EXPERT11_ROW9   \
833   PORT_BIT (0x0100, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_PLUS_PAD)      PORT_CHAR(UCHAR_MAMEKEY(PLUS_PAD))   \
834   PORT_BIT (0x0200, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS_PAD)      PORT_CHAR(UCHAR_MAMEKEY(MINUS_PAD))   \
835   PORT_BIT (0x0400, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_ASTERISK)      PORT_CHAR(UCHAR_MAMEKEY(ASTERISK))   \
836   PORT_BIT (0x0800, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH_PAD)      PORT_CHAR(UCHAR_MAMEKEY(SLASH_PAD))   \
837   PORT_BIT (0xf000, IP_ACTIVE_LOW, IPT_UNUSED)   \
838
839static INPUT_PORTS_START( expert11 )
840   PORT_START("KEY0")
841   KEYB_EXPERT11_ROW0
842   KEYB_EXPERT11_ROW1
843
844   PORT_START("KEY1")
845   KEYB_EXPERT11_ROW2
846   KEYB_ROW3
847
848   PORT_START("KEY2")
849   KEYB_ROW4
850   KEYB_ROW5
851
852   PORT_START("KEY3")
853   KEYB_EXPERT11_ROW6
854   KEYB_ROW7
855
856   PORT_START("KEY4")
857   KEYB_ROW8
858   KEYB_EXPERT11_ROW9
859
860   PORT_START("KEY5")
861   PORT_BIT (0xffff, IP_ACTIVE_LOW, IPT_UNUSED)
862
863   PORT_INCLUDE( msx_dips )
864INPUT_PORTS_END
865
866static INPUT_PORTS_START( expert10 )
867   PORT_START("KEY0")
868   KEYB_ROW0
869   KEYB_ROW1
870
871   PORT_START("KEY1")
872   KEYB_EXPERT10_ROW2
873   KEYB_ROW3
874
875   PORT_START("KEY2")
876   KEYB_ROW4
877   KEYB_ROW5
878
879   PORT_START("KEY3")
880   KEYB_EXPERT11_ROW6
881   KEYB_ROW7
882
883   PORT_START("KEY4")
884   KEYB_ROW8
885   KEYB_EXPERT11_ROW9
886
887   PORT_START("KEY5")
888   PORT_BIT (0xffff, IP_ACTIVE_LOW, IPT_UNUSED)
889
890   PORT_INCLUDE( msx_dips )
891INPUT_PORTS_END
892
893static INPUT_PORTS_START( msx2 )
894   PORT_START("KEY0")
895   KEYB_ROW0
896   KEYB_ROW1
897
898   PORT_START("KEY1")
899   KEYB_ROW2
900   KEYB_ROW3
901
902   PORT_START("KEY2")
903   KEYB_ROW4
904   KEYB_ROW5
905
906   PORT_START("KEY3")
907   KEYB_ROW6
908   KEYB_ROW7
909
910   PORT_START("KEY4")
911   KEYB_ROW8
912   KEYB_ROW9
913
914   PORT_START("KEY5")
915   KEYB_ROW10
916
917   PORT_INCLUDE( msx_dips )
918INPUT_PORTS_END
919
920static INPUT_PORTS_START( msx2jp )
921   PORT_START("KEY0")
922   KEYB_JAP_ROW0
923   KEYB_JAP_ROW1
924
925   PORT_START("KEY1")
926   KEYB_JAP_ROW2
927   KEYB_ROW3
928
929   PORT_START("KEY2")
930   KEYB_ROW4
931   KEYB_ROW5
932
933   PORT_START("KEY3")
934   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LSHIFT)                  PORT_CHAR(UCHAR_SHIFT_1)
935   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LCONTROL)                  PORT_CHAR(UCHAR_SHIFT_2)
936   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("GRAPH") PORT_CODE(KEYCODE_PGUP)      PORT_CHAR(UCHAR_MAMEKEY(F6))
937   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CAPS") PORT_CODE(KEYCODE_CAPSLOCK)   PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
938   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("KANA") PORT_CODE(KEYCODE_PGDN)      PORT_CHAR(UCHAR_MAMEKEY(F7))
939   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F1  F6") PORT_CODE(KEYCODE_F1)      PORT_CHAR(UCHAR_MAMEKEY(F1))
940   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F2  F7") PORT_CODE(KEYCODE_F2)      PORT_CHAR(UCHAR_MAMEKEY(F2))
941   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F3  F8") PORT_CODE(KEYCODE_F3)      PORT_CHAR(UCHAR_MAMEKEY(F3))
942   KEYB_ROW7
943
944   PORT_START("KEY4")
945   KEYB_ROW8
946   KEYB_ROW9
947
948   PORT_START("KEY5")
949   KEYB_ROW10
950
951   PORT_INCLUDE( msx_dips )
952INPUT_PORTS_END
953
954static INPUT_PORTS_START( msx2kr )
955   PORT_START("KEY0")
956   KEYB_JAP_ROW0
957   KEYB_KOR_ROW1
958
959   PORT_START("KEY1")
960   KEYB_JAP_ROW2
961   KEYB_ROW3
962
963   PORT_START("KEY2")
964   KEYB_ROW4
965   KEYB_ROW5
966
967   PORT_START("KEY3")
968   PORT_BIT (0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LSHIFT)                  PORT_CHAR(UCHAR_SHIFT_1)
969   PORT_BIT (0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LCONTROL)                  PORT_CHAR(UCHAR_SHIFT_2)
970   PORT_BIT (0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("GRAPH") PORT_CODE(KEYCODE_PGUP)      PORT_CHAR(UCHAR_MAMEKEY(F6))
971   PORT_BIT (0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CAPS") PORT_CODE(KEYCODE_CAPSLOCK)   PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
972   PORT_BIT (0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("Hangul") PORT_CODE(KEYCODE_PGDN)      PORT_CHAR(UCHAR_MAMEKEY(F7))
973   PORT_BIT (0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F1  F6") PORT_CODE(KEYCODE_F1)      PORT_CHAR(UCHAR_MAMEKEY(F1))
974   PORT_BIT (0x0040, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F2  F7") PORT_CODE(KEYCODE_F2)      PORT_CHAR(UCHAR_MAMEKEY(F2))
975   PORT_BIT (0x0080, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F3  F8") PORT_CODE(KEYCODE_F3)      PORT_CHAR(UCHAR_MAMEKEY(F3))
976   KEYB_ROW7
977
978   PORT_START("KEY4")
979   KEYB_ROW8
980   PORT_BIT (0xff00, IP_ACTIVE_LOW, IPT_UNUSED)
981
982   PORT_START("KEY5")
983   PORT_BIT (0xffff, IP_ACTIVE_LOW, IPT_UNUSED)
984
985   PORT_INCLUDE( msx_dips )
986INPUT_PORTS_END
987
988static const ay8910_interface msx_ay8910_interface =
989{
990   AY8910_LEGACY_OUTPUT,
991   AY8910_DEFAULT_LOADS,
992   DEVCB_MEMORY_HANDLER("maincpu", PROGRAM, msx_psg_port_a_r),
993   DEVCB_MEMORY_HANDLER("maincpu", PROGRAM, msx_psg_port_b_r),
994   DEVCB_MEMORY_HANDLER("maincpu", PROGRAM, msx_psg_port_a_w),
995   DEVCB_MEMORY_HANDLER("maincpu", PROGRAM, msx_psg_port_b_w)
996};
997
998static VIDEO_START( msx2 )
999{
1000   VIDEO_START_CALL(generic_bitmapped);
1001   v9938_init(machine, 0, *machine.primary_screen, machine.generic.tmpbitmap, MODEL_V9938, 0x20000, msx_vdp_interrupt);
1002}
1003
1004#define MSX_XBORDER_PIXELS      15
1005#define MSX_YBORDER_PIXELS      27
1006#define MSX_TOTAL_XRES_PIXELS      256 + (MSX_XBORDER_PIXELS * 2)
1007#define MSX_TOTAL_YRES_PIXELS      192 + (MSX_YBORDER_PIXELS * 2)
1008#define MSX_VISIBLE_XBORDER_PIXELS   8
1009#define MSX_VISIBLE_YBORDER_PIXELS   24
1010
1011static const cassette_config msx_cassette_config =
1012{
1013   fmsx_cassette_formats,
1014   NULL,
1015   (cassette_state)(CASSETTE_PLAY),
1016   NULL
1017};
1018
1019static const floppy_config msx_floppy_config =
1020{
1021   DEVCB_NULL,
1022   DEVCB_NULL,
1023   DEVCB_NULL,
1024   DEVCB_NULL,
1025   DEVCB_NULL,
1026   FLOPPY_STANDARD_5_25_DSHD,
1027   FLOPPY_OPTIONS_NAME(msx),
1028   NULL
1029};
1030
1031static MACHINE_CONFIG_FRAGMENT( msx_cartslot )
1032   MCFG_CARTSLOT_ADD("cart1")
1033   MCFG_CARTSLOT_EXTENSION_LIST("mx1,rom")
1034   MCFG_CARTSLOT_NOT_MANDATORY
1035   MCFG_CARTSLOT_LOAD(msx_cart)
1036   MCFG_CARTSLOT_UNLOAD(msx_cart)
1037
1038   MCFG_CARTSLOT_ADD("cart2")
1039   MCFG_CARTSLOT_EXTENSION_LIST("mx1,rom")
1040   MCFG_CARTSLOT_NOT_MANDATORY
1041   MCFG_CARTSLOT_LOAD(msx_cart)
1042   MCFG_CARTSLOT_UNLOAD(msx_cart)
1043MACHINE_CONFIG_END
1044
1045static MACHINE_CONFIG_START( msx, msx_state )
1046   /* basic machine hardware */
1047   MCFG_CPU_ADD("maincpu", Z80, 3579545)        /* 3.579545 MHz */
1048   MCFG_CPU_PROGRAM_MAP(msx_memory_map)
1049   MCFG_CPU_IO_MAP(msx_io_map)
1050   MCFG_CPU_VBLANK_INT("screen", msx_interrupt)
1051   MCFG_QUANTUM_TIME(attotime::from_hz(60))
1052
1053   MCFG_MACHINE_START( msx )
1054   MCFG_MACHINE_RESET( msx )
1055
1056   MCFG_I8255_ADD( "ppi8255", msx_ppi8255_interface )
1057
1058   /* video hardware */
1059   MCFG_FRAGMENT_ADD(tms9928a)
1060   MCFG_SCREEN_MODIFY("screen")
1061   MCFG_SCREEN_REFRESH_RATE(60)
1062   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
1063   MCFG_SCREEN_SIZE(MSX_TOTAL_XRES_PIXELS, MSX_TOTAL_YRES_PIXELS)
1064   MCFG_SCREEN_VISIBLE_AREA(MSX_XBORDER_PIXELS - MSX_VISIBLE_XBORDER_PIXELS, MSX_TOTAL_XRES_PIXELS - MSX_XBORDER_PIXELS + MSX_VISIBLE_XBORDER_PIXELS - 1, MSX_YBORDER_PIXELS - MSX_VISIBLE_YBORDER_PIXELS, MSX_TOTAL_YRES_PIXELS - MSX_YBORDER_PIXELS + MSX_VISIBLE_YBORDER_PIXELS - 1)
1065
1066   /* sound hardware */
1067   MCFG_SPEAKER_STANDARD_MONO("mono")
1068   MCFG_SOUND_ADD("dac", DAC, 0)
1069   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.10)
1070   MCFG_SOUND_WAVE_ADD("wave", "cassette")
1071   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
1072   MCFG_SOUND_ADD("ay8910", AY8910, 1789773)
1073   MCFG_SOUND_CONFIG(msx_ay8910_interface)
1074   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.10)
1075   MCFG_SOUND_ADD("k051649", K051649, 1789773)
1076   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
1077   MCFG_SOUND_ADD("ym2413", YM2413, 3579545)
1078   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.40)
1079
1080   /* printer */
1081   MCFG_CENTRONICS_ADD("centronics", standard_centronics)
1082
1083   MCFG_CASSETTE_ADD( "cassette", msx_cassette_config )
1084
1085   MCFG_WD179X_ADD("wd179x", msx_wd17xx_interface )
1086
1087   MCFG_FLOPPY_2_DRIVES_ADD(msx_floppy_config)
1088
1089   MCFG_FRAGMENT_ADD(msx_cartslot)
1090MACHINE_CONFIG_END
1091
1092
1093static MACHINE_CONFIG_DERIVED( msx_pal, msx )
1094   MCFG_SCREEN_MODIFY("screen")
1095   MCFG_SCREEN_REFRESH_RATE(50)
1096MACHINE_CONFIG_END
1097
1098#define MSX2_XBORDER_PIXELS      16
1099#define MSX2_YBORDER_PIXELS      28
1100#define MSX2_TOTAL_XRES_PIXELS      256 * 2 + (MSX2_XBORDER_PIXELS * 2)
1101#define MSX2_TOTAL_YRES_PIXELS      212 * 2 + (MSX2_YBORDER_PIXELS * 2)
1102#define MSX2_VISIBLE_XBORDER_PIXELS   8 * 2
1103#define MSX2_VISIBLE_YBORDER_PIXELS   14 * 2
1104
1105static RP5C01_INTERFACE( rtc_intf )
1106{
1107   DEVCB_NULL
1108};
1109
1110static MACHINE_CONFIG_START( msx2, msx_state )
1111   /* basic machine hardware */
1112   MCFG_CPU_ADD("maincpu", Z80, 3579545)        /* 3.579545 MHz */
1113   MCFG_CPU_PROGRAM_MAP(msx_memory_map)
1114   MCFG_CPU_IO_MAP(msx2_io_map)
1115   MCFG_CPU_VBLANK_INT_HACK(msx2_interrupt, 262)
1116   MCFG_QUANTUM_TIME(attotime::from_hz(60))
1117
1118   MCFG_MACHINE_START( msx2 )
1119   MCFG_MACHINE_RESET( msx2 )
1120
1121   MCFG_I8255_ADD( "ppi8255", msx_ppi8255_interface )
1122
1123   /* video hardware */
1124   MCFG_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK)
1125   MCFG_SCREEN_ADD("screen", RASTER)
1126   MCFG_SCREEN_REFRESH_RATE(60)
1127   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
1128   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
1129   MCFG_SCREEN_SIZE(MSX2_TOTAL_XRES_PIXELS, MSX2_TOTAL_YRES_PIXELS)
1130   MCFG_SCREEN_VISIBLE_AREA(MSX2_XBORDER_PIXELS - MSX2_VISIBLE_XBORDER_PIXELS, MSX2_TOTAL_XRES_PIXELS - MSX2_XBORDER_PIXELS + MSX2_VISIBLE_XBORDER_PIXELS - 1, MSX2_YBORDER_PIXELS - MSX2_VISIBLE_YBORDER_PIXELS, MSX2_TOTAL_YRES_PIXELS - MSX2_YBORDER_PIXELS + MSX2_VISIBLE_YBORDER_PIXELS - 1)
1131   MCFG_SCREEN_UPDATE(generic_bitmapped)
1132
1133   MCFG_PALETTE_LENGTH(512)
1134   MCFG_PALETTE_INIT(v9938)
1135
1136   MCFG_VIDEO_START(msx2)
1137
1138   /* sound hardware */
1139   MCFG_SPEAKER_STANDARD_MONO("mono")
1140   MCFG_SOUND_ADD("dac", DAC, 0)
1141   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.10)
1142   MCFG_SOUND_WAVE_ADD("wave", "cassette")
1143   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
1144   MCFG_SOUND_ADD("ay8910", AY8910, 1789773)
1145   MCFG_SOUND_CONFIG(msx_ay8910_interface)
1146   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.10)
1147   MCFG_SOUND_ADD("k051649", K051649, 1789773)
1148   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
1149   MCFG_SOUND_ADD("ym2413", YM2413, 3579545)
1150   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.40)
1151
1152   /* printer */
1153   MCFG_CENTRONICS_ADD("centronics", standard_centronics)
1154
1155   /* cassette */
1156   MCFG_CASSETTE_ADD( "cassette", msx_cassette_config )
1157
1158   /* real time clock */
1159   MCFG_RP5C01_ADD("rtc", XTAL_32_768kHz, rtc_intf)
1160
1161   MCFG_WD179X_ADD("wd179x", msx_wd17xx_interface )
1162
1163   MCFG_FLOPPY_2_DRIVES_ADD(msx_floppy_config)
1164
1165   MCFG_FRAGMENT_ADD(msx_cartslot)
1166MACHINE_CONFIG_END
1167
1168
1169static MACHINE_CONFIG_DERIVED( msx2_pal, msx2 )
1170   MCFG_SCREEN_MODIFY("screen")
1171   MCFG_SCREEN_REFRESH_RATE(50)
1172MACHINE_CONFIG_END
1173
1174
1175/***************************************************************************
1176
1177  Game driver(s)
1178
1179***************************************************************************/
1180
1181/********************************  MSX 1 **********************************/
1182
1183/* MSX */
1184
1185ROM_START (msx)
1186   ROM_REGION (0x8000, "maincpu", 0)
1187   ROM_LOAD ("msx.rom", 0x0000, 0x8000, CRC(8205795e) SHA1(829c00c3114f25b3dae5157c0a238b52a3ac37db))
1188ROM_END
1189
1190MSX_LAYOUT_INIT (msx)
1191   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1192   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1193   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1194   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1195MSX_LAYOUT_END
1196
1197/* MSX - Al Alamiah AX-170 */
1198
1199ROM_START (ax170)
1200   ROM_REGION (0x10000, "maincpu", 0)
1201   ROM_LOAD ("ax170bios.rom", 0x0000, 0x8000, CRC(bd95c436) SHA1(5e094fca95ab8e91873ee372a3f1239b9a48a48d))
1202   ROM_LOAD ("ax170arab.rom", 0x8000, 0x8000, CRC(339cd1aa) SHA1(0287b2ec897b9196788cd9f10c99e1487d7adbbb))
1203ROM_END
1204
1205MSX_LAYOUT_INIT (ax170)
1206   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1207   MSX_LAYOUT_SLOT (1, 0, 1, 2, ROM, 0x8000, 0x8000)
1208   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1209   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1210   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1211MSX_LAYOUT_END
1212
1213/* MSX - Canon V-10 */
1214
1215ROM_START (canonv10)
1216   ROM_REGION (0x8000, "maincpu", 0)
1217   ROM_LOAD ("v10bios.rom", 0x0000, 0x8000, CRC(e9ccd789) SHA1(8963fc041975f31dc2ab1019cfdd4967999de53e))
1218ROM_END
1219
1220MSX_LAYOUT_INIT (canonv10)
1221   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1222   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1223   MSX_LAYOUT_SLOT (2, 0, 3, 1, RAM, 0x4000, 0xC000)   /* 16KB RAM */
1224   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1225MSX_LAYOUT_END
1226
1227/* MSX - Canon V-20 */
1228ROM_START (canonv20)
1229   ROM_REGION (0x8000, "maincpu", 0)
1230   ROM_LOAD ("v20bios.rom", 0x0000, 0x8000, CRC(e9ccd789) SHA1(8963fc041975f31dc2ab1019cfdd4967999de53e))
1231ROM_END
1232
1233MSX_LAYOUT_INIT (canonv20)
1234   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1235   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1236   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1237   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1238MSX_LAYOUT_END
1239
1240/* MSX - Daewoo DPC-100 */
1241
1242ROM_START (dpc100)
1243   ROM_REGION (0xc000, "maincpu", 0)
1244   ROM_LOAD ("100bios.rom", 0x0000, 0x8000, CRC(3ab0cd3b) SHA1(171b587bd5a947a13f3114120b6e7baca3b57d78))
1245   ROM_LOAD ("100han.rom", 0x8000, 0x4000, CRC(97478efb) SHA1(4421fa2504cbce18f7c84b5ea97f04e017007f07))
1246ROM_END
1247
1248MSX_LAYOUT_INIT (dpc100)
1249   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1250   MSX_LAYOUT_SLOT (0, 0, 2, 1, ROM, 0x4000, 0x8000)
1251   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1252   MSX_LAYOUT_SLOT (2, 0, 3, 1, RAM, 0x4000, 0xC000)   /* 16KB RAM */
1253   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1254MSX_LAYOUT_END
1255
1256/* MSX - Daewoo DPC-180 */
1257
1258ROM_START (dpc180)
1259   ROM_REGION (0xc000, "maincpu", 0)
1260   ROM_LOAD ("180bios.rom", 0x0000, 0x8000, CRC(3ab0cd3b) SHA1(171b587bd5a947a13f3114120b6e7baca3b57d78))
1261   ROM_LOAD ("180han.rom", 0x8000, 0x4000, CRC(97478efb) SHA1(4421fa2504cbce18f7c84b5ea97f04e017007f07))
1262ROM_END
1263
1264MSX_LAYOUT_INIT (dpc180)
1265   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1266   MSX_LAYOUT_SLOT (0, 0, 2, 1, ROM, 0x4000, 0x8000)
1267   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1268   MSX_LAYOUT_SLOT (2, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
1269   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1270MSX_LAYOUT_END
1271
1272/* MSX - Daewoo DPC-200 */
1273
1274ROM_START (dpc200)
1275   ROM_REGION (0xc000, "maincpu", 0)
1276   ROM_LOAD ("200bios.rom", 0x0000, 0x8000, CRC(3ab0cd3b) SHA1(171b587bd5a947a13f3114120b6e7baca3b57d78))
1277   ROM_LOAD ("200han.rom", 0x8000, 0x4000, CRC(97478efb) SHA1(4421fa2504cbce18f7c84b5ea97f04e017007f07))
1278ROM_END
1279
1280MSX_LAYOUT_INIT (dpc200)
1281   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1282   MSX_LAYOUT_SLOT (0, 0, 2, 1, ROM, 0x4000, 0x8000)
1283   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1284   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1285   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1286MSX_LAYOUT_END
1287
1288/* MSX - Goldstar FC-200 */
1289
1290ROM_START (gsfc200)
1291   ROM_REGION (0x8000, "maincpu", 0)
1292   ROM_LOAD ("fc200bios.rom.u5a", 0x0000, 0x4000, CRC(61f473fb) SHA1(c425750bbb2ae1d278216b45029d303e37d8df2f))
1293   ROM_LOAD ("fc200bios.rom.u5b", 0x4000, 0x4000, CRC(1a99b1a1) SHA1(e18f72271b64693a2a2bc226e1b9ebd0448e07c0))
1294ROM_END
1295
1296MSX_LAYOUT_INIT (gsfc200)
1297   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1298   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1299   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1300   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1301MSX_LAYOUT_END
1302
1303/* MSX - Gradiente Expert 1.0 */
1304
1305ROM_START (expert10)
1306   ROM_REGION (0x8000, "maincpu",0)
1307   ROM_LOAD ("expbios.rom", 0x0000, 0x8000, CRC(07610d77) SHA1(ef3e010eb57e4476700a3bbff9d2119ab3acdf62))
1308ROM_END
1309
1310MSX_LAYOUT_INIT (expert10)
1311   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1312   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1313   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1314   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1315MSX_LAYOUT_END
1316
1317/* MSX - Gradiente Expert 1.1 */
1318ROM_START (expert11)
1319   ROM_REGION (0xc000, "maincpu",0)
1320   ROM_LOAD ("expbios11.rom", 0x0000, 0x8000, CRC(efb4b972) SHA1(d6720845928ee848cfa88a86accb067397685f02))
1321ROM_END
1322
1323MSX_LAYOUT_INIT (expert11)
1324   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1325   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1326   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1327   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1328MSX_LAYOUT_END
1329
1330/* MSX - Gradiente Expert 1.3 */
1331ROM_START (expert13)
1332   ROM_REGION (0x8000, "maincpu",0)
1333   ROM_LOAD ("expbios13.rom", 0x0000, 0x8000, CRC(5638bc38) SHA1(605f5af3f358c6811f54e0173bad908614a198c0))
1334ROM_END
1335
1336MSX_LAYOUT_INIT (expert13)
1337   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1338   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1339   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
1340   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1341MSX_LAYOUT_END
1342
1343/* MSX - Gradiente Expert DDPlus */
1344ROM_START (expertdp)
1345   ROM_REGION (0xc000, "maincpu",0)
1346   ROM_LOAD ("eddpbios.rom", 0x0000, 0x8000, CRC(efb4b972) SHA1(d6720845928ee848cfa88a86accb067397685f02))
1347   ROM_LOAD ("eddpdisk.rom", 0x8000, 0x4000, CRC(549f1d90) SHA1(f1525de4e0b60a6687156c2a96f8a8b2044b6c56))
1348ROM_END
1349
1350MSX_LAYOUT_INIT (expertdp)
1351   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1352   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1353   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1354   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
1355  MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM2, 0x4000, 0x8000)
1356MSX_LAYOUT_END
1357
1358/* MSX - Gradiente Expert Plus */
1359
1360ROM_START (expertpl)
1361   ROM_REGION (0xc000, "maincpu",0)
1362   ROM_LOAD ("exppbios.rom", 0x0000, 0x8000, CRC(efb4b972) SHA1(d6720845928ee848cfa88a86accb067397685f02))
1363   ROM_LOAD ("exppdemo.rom", 0x8000, 0x4000, CRC(a9bbef64) SHA1(d4cea8c815f3eeabe0c6a1c845f902ec4318bf6b))
1364ROM_END
1365
1366MSX_LAYOUT_INIT (expertpl)
1367   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1368   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1369   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1370   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1371   MSX_LAYOUT_SLOT (3, 3, 2, 1, ROM, 0x4000, 0x8000)
1372MSX_LAYOUT_END
1373
1374/* MSX - JVC HC-7GB */
1375
1376ROM_START (jvchc7gb)
1377   ROM_REGION (0x8000, "maincpu", 0)
1378   ROM_LOAD ("hc7gbbios.rom", 0x0000, 0x8000, CRC(e9ccd789) SHA1(8963fc041975f31dc2ab1019cfdd4967999de53e))
1379ROM_END
1380
1381MSX_LAYOUT_INIT (jvchc7gb)
1382   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1383   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1384   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1385   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1386MSX_LAYOUT_END
1387
1388/* MSX - Mitsubishi ML-F80 */
1389
1390ROM_START (mlf80)
1391   ROM_REGION (0x8000, "maincpu", 0)
1392   ROM_LOAD ("mlf80bios.rom", 0x0000, 0x8000, CRC(e9ccd789) SHA1(8963fc041975f31dc2ab1019cfdd4967999de53e))
1393ROM_END
1394
1395MSX_LAYOUT_INIT (mlf80)
1396   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1397   MSX_LAYOUT_SLOT (1, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1398   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1399   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1400MSX_LAYOUT_END
1401
1402/* MSX - Mitsubishi ML-FX1 */
1403
1404ROM_START (mlfx1)
1405   ROM_REGION (0x8000, "maincpu", 0)
1406   ROM_LOAD ("mlfx1bios.rom", 0x0000, 0x8000, CRC(62867dce) SHA1(0cbe0df4af45e8f531e9c761403ac9e71808f20c))
1407ROM_END
1408
1409MSX_LAYOUT_INIT (mlfx1)
1410   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1411   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1412   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1413   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1414MSX_LAYOUT_END
1415
1416/* MSX - National CF-1200 */
1417
1418ROM_START (cf1200)
1419   ROM_REGION (0x8000, "maincpu", 0)
1420   ROM_LOAD ("1200bios.rom", 0x0000, 0x8000, CRC(5ad03407) SHA1(c7a2c5baee6a9f0e1c6ee7d76944c0ab1886796c))
1421ROM_END
1422
1423MSX_LAYOUT_INIT (cf1200)
1424   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1425   MSX_LAYOUT_SLOT (0, 0, 3, 1, RAM, 0x4000, 0xC000)   /* 16KB RAM */
1426   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1427   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1428MSX_LAYOUT_END
1429
1430/* MSX - National CF-2000 */
1431
1432ROM_START (cf2000)
1433   ROM_REGION (0x8000, "maincpu", 0)
1434   ROM_LOAD ("2000bios.rom", 0x0000, 0x8000, CRC(ee229390) SHA1(302afb5d8be26c758309ca3df611ae69cced2821))
1435ROM_END
1436
1437MSX_LAYOUT_INIT (cf2000)
1438   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1439   MSX_LAYOUT_SLOT (0, 0, 3, 1, RAM, 0x4000, 0xC000)   /* 16KB RAM */
1440   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1441   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1442MSX_LAYOUT_END
1443
1444/* MSX - National CF-2700 */
1445ROM_START (cf2700)
1446   ROM_REGION (0x8000, "maincpu", 0)
1447   ROM_LOAD ("2700bios.rom.ic32", 0x0000, 0x8000, CRC(5ad03407) SHA1(c7a2c5baee6a9f0e1c6ee7d76944c0ab1886796c))
1448ROM_END
1449
1450MSX_LAYOUT_INIT (cf2700)
1451   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1452   MSX_LAYOUT_SLOT (0, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
1453   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1454   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1455MSX_LAYOUT_END
1456
1457/* MSX - National CF-3000 */
1458
1459ROM_START (cf3000)
1460   ROM_REGION (0x8000, "maincpu", 0)
1461   ROM_LOAD ("3000bios.rom", 0x0000, 0x8000, CRC(5ad03407) SHA1(c7a2c5baee6a9f0e1c6ee7d76944c0ab1886796c))
1462ROM_END
1463
1464MSX_LAYOUT_INIT (cf3000)
1465   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1466   MSX_LAYOUT_SLOT (1, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
1467   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1468   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1469MSX_LAYOUT_END
1470
1471/* MSX - National CF-3300 */
1472ROM_START (cf3300)
1473   ROM_REGION (0xc000, "maincpu", 0)
1474   ROM_LOAD ("3300bios.rom", 0x0000, 0x8000, CRC(5ad03407) SHA1(c7a2c5baee6a9f0e1c6ee7d76944c0ab1886796c))
1475   ROM_LOAD ("3300disk.rom", 0x8000, 0x4000, CRC(549f1d90) SHA1(f1525de4e0b60a6687156c2a96f8a8b2044b6c56))
1476ROM_END
1477
1478MSX_LAYOUT_INIT (cf3300)
1479   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1480   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1481   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1482   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
1483  MSX_LAYOUT_SLOT (3, 1, 1, 2, DISK_ROM2, 0x4000, 0x8000)
1484MSX_LAYOUT_END
1485
1486/* MSX - National FS-1300 */
1487
1488ROM_START (fs1300)
1489   ROM_REGION (0x8000, "maincpu", 0)
1490   ROM_LOAD ("1300bios.rom", 0x0000, 0x8000, CRC(5ad03407) SHA1(c7a2c5baee6a9f0e1c6ee7d76944c0ab1886796c))
1491ROM_END
1492
1493MSX_LAYOUT_INIT (fs1300)
1494   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1495   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1496   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1497   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
1498MSX_LAYOUT_END
1499
1500/* MSX - National FS-4000 */
1501ROM_START (fs4000)
1502   ROM_REGION (0x38000 ,"maincpu", 0)
1503   ROM_LOAD ("4000bios.rom", 0x0000, 0x8000, CRC(071135e0) SHA1(df48902f5f12af8867ae1a87f255145f0e5e0774))
1504   ROM_LOAD ("4000word.rom", 0x8000, 0x8000, CRC(950b6c87) SHA1(931d6318774bd495a32ec3dabf8d0edfc9913324))
1505   ROM_LOAD ("4000kdr.rom", 0x10000, 0x8000, CRC(ebaa5a1e) SHA1(77bd67d5d10d459d343e79eafcd8e17eb0f209dd))
1506   ROM_LOAD ("4000kfn.rom", 0x18000, 0x20000, CRC(956dc96d) SHA1(9ed3ab6d893632b9246e91b412cd5db519e7586b))
1507ROM_END
1508
1509MSX_LAYOUT_INIT (fs4000)
1510   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1511   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1512   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1513   MSX_LAYOUT_SLOT (3, 0, 0, 2, ROM, 0x8000, 0x8000)
1514   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x10000)
1515   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1516   MSX_LAYOUT_KANJI (0x18000)
1517MSX_LAYOUT_END
1518
1519/* MSX - Philips NMS-801 */
1520
1521ROM_START (nms801)
1522   ROM_REGION (0x8000, "maincpu", 0)
1523   ROM_LOAD ("801bios.rom", 0x0000, 0x8000, CRC(fa089461) SHA1(21329398c0f350e330b353f45f21aa7ba338fc8d))
1524ROM_END
1525
1526MSX_LAYOUT_INIT (nms801)
1527   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1528   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1529   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1530   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1531MSX_LAYOUT_END
1532
1533/* MSX - Philips VG-8000 */
1534
1535ROM_START (vg8000)
1536   ROM_REGION (0x8000, "maincpu", 0)
1537   ROM_LOAD ("8000bios.rom", 0x0000, 0x8000, CRC(efd970b0) SHA1(42252cf87deeb58181a7bfec7c874190a1351779))
1538ROM_END
1539
1540MSX_LAYOUT_INIT (vg8000)
1541   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1542   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1543   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1544   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x4000, 0xC000)   /* 16KB RAM */
1545MSX_LAYOUT_END
1546
1547/* MSX - Philips VG-8010 */
1548
1549ROM_START (vg8010)
1550   ROM_REGION (0x8000, "maincpu", 0)
1551   ROM_LOAD ("8010bios.rom", 0x0000, 0x8000, CRC(efd970b0) SHA1(42252cf87deeb58181a7bfec7c874190a1351779))
1552ROM_END
1553
1554MSX_LAYOUT_INIT (vg8010)
1555   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1556   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1557   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1558   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x8000, 0x8000)   /* 32KB RAM */
1559MSX_LAYOUT_END
1560
1561/* MSX - Philips VG-8010F */
1562
1563ROM_START (vg8010f)
1564   ROM_REGION (0x8000, "maincpu", 0)
1565   ROM_LOAD ("8010fbios.rom", 0x0000, 0x8000, CRC(df57c9ca) SHA1(898630ad1497dc9a329580c682ee55c4bcb9c30c))
1566ROM_END
1567
1568MSX_LAYOUT_INIT (vg8010f)
1569   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1570   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1571   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1572   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x8000, 0x8000)   /* 32KB RAM */
1573MSX_LAYOUT_END
1574
1575/* MSX - Philips VG-8020-00 */
1576
1577ROM_START (vg802000)
1578   ROM_REGION (0x8000, "maincpu", 0)
1579   ROM_LOAD ("8020-00bios.rom", 0x0000, 0x8000, CRC(8205795e) SHA1(829c00c3114f25b3dae5157c0a238b52a3ac37db))
1580ROM_END
1581
1582MSX_LAYOUT_INIT (vg802000)
1583   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1584   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1585   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1586   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1587MSX_LAYOUT_END
1588
1589/* MSX - Philips VG-8020-20 */
1590
1591ROM_START (vg802020)
1592   ROM_REGION (0x8000, "maincpu", 0)
1593   ROM_LOAD ("8020-20bios.rom", 0x0000, 0x8000, CRC(A317E6B4) SHA1(E998F0C441F4F1800EF44E42CD1659150206CF79))
1594ROM_END
1595
1596MSX_LAYOUT_INIT (vg802020)
1597   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1598   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1599   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1600   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
1601MSX_LAYOUT_END
1602
1603/* MSX - Pioneer PX-7 */
1604
1605ROM_START (piopx7)
1606   ROM_REGION (0xc000, "maincpu", 0)
1607   ROM_LOAD ("ym2301.ic12", 0x0000, 0x8000, CRC(e9ccd789) SHA1(8963fc041975f31dc2ab1019cfdd4967999de53e))
1608   ROM_LOAD ("pd5031.ic13", 0x8000, 0x2000, CRC(91e0df72) SHA1(4f0102cdc27216fd9bcdb9663db728d2ccd8ca6d))
1609   ROM_FILL( 0xa000, 0x2000, 0x6E )
1610ROM_END
1611
1612MSX_LAYOUT_INIT (piopx7)
1613   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1614   MSX_LAYOUT_SLOT (0, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
1615   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1616   MSX_LAYOUT_SLOT (2, 0, 1, 2, ROM, 0x4000, 0x8000)
1617   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1618MSX_LAYOUT_END
1619
1620/* MSX - Sanyo MPC-100 */
1621
1622ROM_START (mpc100)
1623   ROM_REGION (0x8000, "maincpu", 0)
1624   ROM_LOAD ("mpc100bios.rom", 0x0000, 0x8000, CRC(e9ccd789) SHA1(8963fc041975f31dc2ab1019cfdd4967999de53e))
1625ROM_END
1626
1627MSX_LAYOUT_INIT (mpc100)
1628   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1629   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1630   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1631   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1632MSX_LAYOUT_END
1633
1634/* MSX - Sharp Epcom HotBit 1.1 */
1635
1636ROM_START (hotbit11)
1637   ROM_REGION (0x8000, "maincpu",0)
1638   ROM_LOAD ("hotbit11.rom", 0x0000, 0x8000, CRC(b6942694) SHA1(663f8c512d04d213fa616b0db5eefe3774012a4b))
1639ROM_END
1640
1641MSX_LAYOUT_INIT (hotbit11)
1642   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1643   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1644   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1645   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1646MSX_LAYOUT_END
1647
1648/* MSX - Sharp Epcom HotBit 1.2 */
1649
1650ROM_START (hotbit12)
1651   ROM_REGION (0x8000, "maincpu",0)
1652   ROM_LOAD ("hotbit12.rom", 0x0000, 0x8000, CRC(f59a4a0c) SHA1(9425815446d468058705bae545ffa13646744a87))
1653ROM_END
1654
1655MSX_LAYOUT_INIT (hotbit12)
1656   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1657   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1658   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1659   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1660MSX_LAYOUT_END
1661
1662/* MSX - Sharp Epcom HotBit 1.3b */
1663
1664ROM_START (hotbi13b)
1665   ROM_REGION (0x8000, "maincpu",0)
1666   ROM_LOAD ("hotbit13b.rom", 0x0000, 0x8000, CRC(7a19820e) SHA1(e0c2bfb078562d15acabc5831020a2370ea87052))
1667ROM_END
1668
1669MSX_LAYOUT_INIT (hotbi13b)
1670   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1671   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1672   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1673   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
1674MSX_LAYOUT_END
1675
1676/* MSX - Sharp Epcom HotBit 1.3p */
1677
1678ROM_START (hotbi13p)
1679   ROM_REGION (0x8000, "maincpu",0)
1680   ROM_LOAD ("hotbit13p.rom", 0x0000, 0x8000, CRC(150e239c) SHA1(942f9507d206cd8156f15601fe8032fcf0e3875b))
1681ROM_END
1682
1683MSX_LAYOUT_INIT (hotbi13p)
1684   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1685   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1686   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1687   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
1688MSX_LAYOUT_END
1689
1690/* MSX - Sony HB-10P */
1691
1692ROM_START (hb10p)
1693   ROM_REGION (0x10000, "maincpu", 0)
1694   ROM_LOAD ("10pbios.rom", 0x0000, 0x8000, CRC(0f488dd8) SHA1(5e7c8eab238712d1e18b0219c0f4d4dae180420d))
1695ROM_END
1696
1697MSX_LAYOUT_INIT (hb10p)
1698   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1699   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1700   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1701   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1702MSX_LAYOUT_END
1703
1704/* MSX - Sony HB-20P */
1705
1706ROM_START (hb20p)
1707   ROM_REGION (0x10000, "maincpu", 0)
1708   ROM_LOAD ("20pbios.rom", 0x0000, 0x8000, CRC(21af423f) SHA1(365c93d7652c9f727221689bcc348652832a7b7a))
1709ROM_END
1710
1711MSX_LAYOUT_INIT (hb20p)
1712   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1713   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1714   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1715   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1716MSX_LAYOUT_END
1717
1718/* MSX - Sony HB-201 */
1719
1720ROM_START (hb201)
1721   ROM_REGION (0x10000, "maincpu", 0)
1722   ROM_LOAD ("201bios.rom.ic9", 0x0000, 0x8000, CRC(ee229390) SHA1(302afb5d8be26c758309ca3df611ae69cced2821))
1723   ROM_LOAD ("201note.rom.ic8", 0x8000, 0x4000, CRC(74567244) SHA1(0f4f09f1a6ef7535b243afabfb44a3a0eb0498d9))
1724   ROM_FILL( 0xc000, 0x4000, 0xff )
1725ROM_END
1726
1727MSX_LAYOUT_INIT (hb201)
1728   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1729   MSX_LAYOUT_SLOT (0, 0, 2, 2, ROM, 0x8000, 0x8000)
1730   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1731   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1732   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1733MSX_LAYOUT_END
1734
1735/* MSX - Sony HB-201P */
1736
1737ROM_START (hb201p)
1738   ROM_REGION (0xc000, "maincpu", 0)
1739   ROM_LOAD ("201pbios.rom.ic9", 0x0000, 0x8000, CRC(0f488dd8) SHA1(5e7c8eab238712d1e18b0219c0f4d4dae180420d))
1740   ROM_LOAD ("201pnote.rom.ic8", 0x8000, 0x4000, CRC(1ff9b6ec) SHA1(e84d3ec7a595ee36b50e979683c84105c1871857))
1741ROM_END
1742
1743MSX_LAYOUT_INIT (hb201p)
1744   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1745   MSX_LAYOUT_SLOT (0, 0, 2, 1, ROM, 0x4000, 0x8000)
1746   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1747   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1748   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1749MSX_LAYOUT_END
1750
1751/* MSX - Sony HB-501P */
1752
1753ROM_START (hb501p)
1754   ROM_REGION (0x8000, "maincpu", 0)
1755   ROM_LOAD ("501pbios.rom", 0x0000, 0x8000, CRC(0f488dd8) SHA1(5e7c8eab238712d1e18b0219c0f4d4dae180420d))
1756ROM_END
1757
1758MSX_LAYOUT_INIT (hb501p)
1759   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1760   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1761   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1762   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1763MSX_LAYOUT_END
1764
1765/* MSX - Sony HB-55D */
1766
1767ROM_START (hb55d)
1768   ROM_REGION (0xc000, "maincpu", 0)
1769   ROM_LOAD ("55dbios.rom", 0x0000, 0x8000, CRC(7e2b32dd) SHA1(38a645febd0e0fe86d594f27c2d14be995acc730))
1770   ROM_LOAD ("55dnote.rom", 0x8000, 0x4000, CRC(8aae0494) SHA1(97ce59892573cac3c440efff6d74c8a1c29a5ad3))
1771ROM_END
1772
1773MSX_LAYOUT_INIT (hb55d)
1774   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1775   MSX_LAYOUT_SLOT (0, 0, 2, 1, ROM, 0x4000, 0x8000)
1776   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1777   MSX_LAYOUT_SLOT (2, 0, 3, 1, RAM, 0x4000, 0xC000)   /* 16KB RAM */
1778   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1779MSX_LAYOUT_END
1780
1781/* MSX - Sony HB-55P */
1782
1783ROM_START (hb55p)
1784   ROM_REGION (0xc000, "maincpu", 0)
1785   ROM_LOAD ("55pbios.ic42", 0x0000, 0x4000, CRC(24c198be) SHA1(7f8c94cb8913db32a696dec80ffc78e46693f1b7))
1786   ROM_LOAD ("55pbios.ic43", 0x4000, 0x4000, CRC(e516e7e5) SHA1(05fedd4b9bfcf4949020c79d32c4c3f03a54fb62))
1787   ROM_LOAD ("55pnote.ic44", 0x8000, 0x4000, CRC(492b12f8) SHA1(b262aedc71b445303f84efe5e865cbb71fd7d952))
1788ROM_END
1789
1790MSX_LAYOUT_INIT (hb55p)
1791   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1792   MSX_LAYOUT_SLOT (0, 0, 2, 1, ROM, 0x4000, 0x8000)
1793   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1794   MSX_LAYOUT_SLOT (2, 0, 3, 1, RAM, 0x4000, 0xC000)   /* 16KB RAM */
1795   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1796MSX_LAYOUT_END
1797
1798/* MSX - Sony HB-75D */
1799
1800ROM_START (hb75d)
1801   ROM_REGION (0xc000, "maincpu", 0)
1802   ROM_LOAD ("75dbios.rom", 0x0000, 0x8000, CRC(7e2b32dd) SHA1(38a645febd0e0fe86d594f27c2d14be995acc730))
1803   ROM_LOAD ("75dnote.rom", 0x8000, 0x4000, CRC(8aae0494) SHA1(97ce59892573cac3c440efff6d74c8a1c29a5ad3))
1804ROM_END
1805
1806MSX_LAYOUT_INIT (hb75d)
1807   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1808   MSX_LAYOUT_SLOT (0, 0, 2, 1, ROM, 0x4000, 0x8000)
1809   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1810   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1811   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1812MSX_LAYOUT_END
1813
1814/* MSX - Sony HB-75P */
1815
1816ROM_START (hb75p)
1817   ROM_REGION (0xc000, "maincpu", 0)
1818   ROM_LOAD ("75pbios.ic42", 0x0000, 0x4000, CRC(24c198be) SHA1(7f8c94cb8913db32a696dec80ffc78e46693f1b7))
1819   ROM_LOAD ("75pbios.ic43", 0x4000, 0x4000, CRC(e516e7e5) SHA1(05fedd4b9bfcf4949020c79d32c4c3f03a54fb62))
1820   ROM_LOAD ("75pnote.ic44", 0x8000, 0x4000, CRC(492b12f8) SHA1(b262aedc71b445303f84efe5e865cbb71fd7d952))
1821ROM_END
1822
1823MSX_LAYOUT_INIT (hb75p)
1824   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1825   MSX_LAYOUT_SLOT (0, 0, 2, 1, ROM, 0x4000, 0x8000)
1826   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1827   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1828   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1829MSX_LAYOUT_END
1830
1831/* MSX - Spectravideo SVI-728 */
1832
1833ROM_START (svi728)
1834   ROM_REGION (0xc000, "maincpu", 0)
1835   ROM_LOAD ("728bios.rom", 0x0000, 0x8000, CRC(1ce9246c) SHA1(ea6a82cf8c6e65eb30b98755c8577cde8d9186c0))
1836   ROM_LOAD ("707disk.rom", 0x8000, 0x4000, CRC(f9978853) SHA1(6aa856cc56eb98863c9da7a566571605682b5c6b))
1837ROM_END
1838
1839MSX_LAYOUT_INIT (svi728)
1840   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1841   MSX_LAYOUT_SLOT (1, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
1842   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1843   MSX_LAYOUT_SLOT (3, 0, 1, 1, DISK_ROM2, 0x4000, 0x8000)
1844   MSX_LAYOUT_SLOT (3, 1, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1845MSX_LAYOUT_END
1846
1847/* MSX - Spectravideo SVI-738 */
1848
1849ROM_START (svi738)
1850   ROM_REGION (0x10000, "maincpu", 0)
1851   ROM_LOAD ("738bios.rom", 0x0000, 0x8000, CRC(ad007d62) SHA1(c53b3f2c00f31683914f7452f3f4d94ae2929c0d))
1852   ROM_LOAD ("738disk.rom", 0x8000, 0x4000, CRC(acd27a36) SHA1(99a40266bc296cef1d432cb0caa8df1a7e570be4))
1853   ROM_LOAD ("738232c.rom", 0xc000, 0x2000, CRC(3353dcc6) SHA1(4e9384c9d137f0ab65ffc5a78f04cd8c9df6c8b7))
1854   ROM_FILL (0xe000, 0x2000, 0xff)
1855ROM_END
1856
1857MSX_LAYOUT_INIT (svi738)
1858   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1859   MSX_LAYOUT_SLOT (1, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
1860   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1861   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0xc000)
1862   MSX_LAYOUT_SLOT (3, 1, 1, 2, DISK_ROM2, 0x4000, 0x8000)
1863   MSX_LAYOUT_SLOT (3, 2, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1864MSX_LAYOUT_END
1865
1866/* MSX - Spectravideo SVI-738 Swedish */
1867
1868ROM_START (svi738sw)
1869   ROM_REGION (0x10000, "maincpu", 0)
1870   ROM_LOAD ("738sebios.rom", 0x0000, 0x8000, CRC(c8ccdaa0) SHA1(87f4d0fa58cfe9cef818a3185df2735e6da6168c))
1871   ROM_LOAD ("738sedisk.rom", 0x8000, 0x4000, CRC(fb884df4) SHA1(6d3a530ae822ec91f6444c681c9b08b9efadc7e7))
1872   ROM_LOAD ("738se232c.rom", 0xc000, 0x2000, CRC(3353dcc6) SHA1(4e9384c9d137f0ab65ffc5a78f04cd8c9df6c8b7))
1873   ROM_FILL (0xe000, 0x2000, 0xff)
1874ROM_END
1875
1876MSX_LAYOUT_INIT (svi738sw)
1877   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1878   MSX_LAYOUT_SLOT (1, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
1879   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1880   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0xc000)
1881   MSX_LAYOUT_SLOT (3, 1, 1, 2, DISK_ROM2, 0x4000, 0x8000)
1882   MSX_LAYOUT_SLOT (3, 2, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1883MSX_LAYOUT_END
1884
1885
1886/* MSX - Talent DPC-200 */
1887
1888ROM_START (tadpc200)
1889   ROM_REGION (0x8000, "maincpu", 0)
1890   ROM_LOAD ("dpc200bios.rom", 0x0000, 0x8000, CRC(8205795e) SHA1(829c00c3114f25b3dae5157c0a238b52a3ac37db))
1891ROM_END
1892
1893MSX_LAYOUT_INIT (tadpc200)
1894   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1895   MSX_LAYOUT_SLOT (1, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1896   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1897   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1898MSX_LAYOUT_END
1899
1900
1901/* MSX - Talent DPC-200A */
1902
1903ROM_START (tadpc20a)
1904   ROM_REGION (0x8000, "maincpu", 0)
1905   ROM_LOAD ("dpc200abios.rom", 0x0000, 0x8000, CRC(8205795e) SHA1(829c00c3114f25b3dae5157c0a238b52a3ac37db))
1906ROM_END
1907
1908MSX_LAYOUT_INIT (tadpc20a)
1909   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1910   MSX_LAYOUT_SLOT (1, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1911   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1912   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1913MSX_LAYOUT_END
1914
1915/* MSX - Toshiba HX-10 */
1916/* The BIOS on the Toshiba HX-10 is inside a big 64pin Toshiba chip label TCX-1007 */
1917
1918ROM_START (hx10)
1919   ROM_REGION (0x8000, "maincpu",0)
1920   ROM_LOAD ("tcx-1007.ic15", 0x0000, 0x8000, CRC(5486b711) SHA1(4dad9de7c28b452351cc12910849b51bd9a37ab3))
1921ROM_END
1922
1923MSX_LAYOUT_INIT (hx10)
1924   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1925   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1926   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
1927   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1928MSX_LAYOUT_END
1929
1930/* MSX - Toshiba HX-10S */
1931
1932ROM_START (hx10s)
1933   ROM_REGION (0x8000, "maincpu",0)
1934   ROM_LOAD ("hx10sbios.rom", 0x0000, 0x8000, CRC(5486b711) SHA1(4dad9de7c28b452351cc12910849b51bd9a37ab3))
1935ROM_END
1936
1937MSX_LAYOUT_INIT (hx10s)
1938   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1939   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1940   MSX_LAYOUT_SLOT (2, 0, 3, 1, RAM, 0x4000, 0xC000)   /* 16KB RAM */
1941   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1942MSX_LAYOUT_END
1943
1944/* MSX - Toshiba HX-20 */
1945
1946ROM_START (hx20)
1947   ROM_REGION (0x10000, "maincpu",0)
1948   ROM_LOAD ("hx20bios.rom", 0x0000, 0x8000, CRC(8205795e) SHA1(829c00c3114f25b3dae5157c0a238b52a3ac37db))
1949   ROM_LOAD ("hx20word.rom", 0x8000, 0x8000, CRC(39b3e1c0) SHA1(9f7cfa932bd7dfd0d9ecaadc51655fb557c2e125))
1950ROM_END
1951
1952MSX_LAYOUT_INIT (hx20)
1953   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1954   MSX_LAYOUT_SLOT (0, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
1955   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1956   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1957   MSX_LAYOUT_SLOT (3, 0, 2, 0, RAM, 0x8000, 0x0000)   /* 32KB RAM */
1958   MSX_LAYOUT_SLOT (3, 3, 1, 2, ROM, 0x8000, 0x8000)
1959MSX_LAYOUT_END
1960
1961/* MSX - Yamaha CX5M */
1962
1963ROM_START (cx5m)
1964   ROM_REGION (0x10000, "maincpu",0)
1965   ROM_LOAD ("cx5mbios.rom", 0x0000, 0x8000, CRC(e2242b53) SHA1(706dd67036baeec7127e4ccd8c8db8f6ce7d0e4c))
1966   ROM_LOAD ("sfg05m.rom",       0x8000, 0x8000, CRC(6c2545c9) SHA1(bc4b242647116f4886bb92e86421f97b1be51938))
1967ROM_END
1968
1969MSX_LAYOUT_INIT (cx5m)
1970   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1971   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1972   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1973   MSX_LAYOUT_SLOT (3, 0, 0, 2, ROM, 0x8000, 0x8000)
1974   MSX_LAYOUT_SLOT (3, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
1975MSX_LAYOUT_END
1976
1977/* MSX - Yamaha CX5M-128 */
1978
1979ROM_START (cx5m128)
1980   ROM_REGION (0x18000, "maincpu",0)
1981   ROM_LOAD ("cx5m128bios.rom", 0x0000, 0x8000, CRC(507b2caa) SHA1(0dde59e8d98fa524961cd37b0e100dbfb42cf576))
1982   ROM_LOAD ("cx5m128ext.rom",  0x8000, 0x4000, CRC(feada82e) SHA1(48b0c2ff1f1e407cc44394219f7b3878efaa919f))
1983   ROM_LOAD ("sfg05.rom",      0xc000, 0x8000, CRC(2425c279) SHA1(d956167e234f60ad916120437120f86fc8c3c321))
1984   ROM_LOAD ("yrm502.rom",    0x14000,0x4000, CRC(5330fe21) SHA1(7b1798561ee1844a7d6432924fbee9b4fc591c19))
1985ROM_END
1986
1987MSX_LAYOUT_INIT (cx5m128)
1988   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
1989   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
1990   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
1991   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0x8000)
1992   MSX_LAYOUT_SLOT (3, 1, 1, 1, ROM, 0x4000, 0x14000) /* YRM-502 */
1993   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
1994   MSX_LAYOUT_SLOT (3, 3, 0, 2, ROM, 0x8000, 0xc000) /* SFG-05 */
1995MSX_LAYOUT_END
1996
1997/* MSX - Yamaha CX5MII */
1998
1999ROM_START (cx5m2)
2000   ROM_REGION (0x14000, "maincpu",0)
2001   ROM_LOAD ("cx5m2bios.rom", 0x0000, 0x8000, CRC(507b2caa) SHA1(0dde59e8d98fa524961cd37b0e100dbfb42cf576))
2002   ROM_LOAD ("cx5m2ext.rom",  0x8000, 0x4000, CRC(feada82e) SHA1(48b0c2ff1f1e407cc44394219f7b3878efaa919f))
2003   ROM_LOAD ("sfg05.rom",       0xc000, 0x8000, CRC(2425c279) SHA1(d956167e234f60ad916120437120f86fc8c3c321))
2004ROM_END
2005
2006MSX_LAYOUT_INIT (cx5m2)
2007   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2008   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2009   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2010   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0x8000)
2011   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2012   MSX_LAYOUT_SLOT (3, 3, 0, 2, ROM, 0x8000, 0xc000)
2013MSX_LAYOUT_END
2014
2015/* MSX - Yamaha YIS303 */
2016
2017ROM_START (yis303)
2018   ROM_REGION (0x14000, "maincpu",0)
2019   ROM_LOAD ("yis303bios.rom", 0x0000, 0x8000, CRC(e2242b53) SHA1(706dd67036baeec7127e4ccd8c8db8f6ce7d0e4c))
2020   ROM_FILL( 0x8000, 0xc000, 0xff )
2021ROM_END
2022
2023MSX_LAYOUT_INIT (yis303)
2024   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2025   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2026   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2027   MSX_LAYOUT_SLOT (3, 0, 0, 3, ROM, 0xC000, 0x0000)   /* Fill FF */
2028   MSX_LAYOUT_SLOT (3, 0, 3, 1, RAM, 0x4000, 0xC000)   /* 16KB RAM */
2029MSX_LAYOUT_END
2030
2031/* MSX - Yamaha YIS503 */
2032
2033ROM_START (yis503)
2034   ROM_REGION (0x10000, "maincpu",0)
2035   ROM_LOAD ("yis503bios.rom", 0x0000, 0x8000, CRC(e2242b53) SHA1(706dd67036baeec7127e4ccd8c8db8f6ce7d0e4c))
2036   ROM_FILL( 0x8000, 0x8000, 0xff )
2037ROM_END
2038
2039MSX_LAYOUT_INIT (yis503)
2040   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2041   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2042   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2043   MSX_LAYOUT_SLOT (3, 0, 0, 2, ROM, 0xC000, 0x0000)   /* Fill FF */
2044   MSX_LAYOUT_SLOT (3, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
2045MSX_LAYOUT_END
2046
2047/* MSX - Yamaha YIS503II */
2048
2049ROM_START (yis503ii)
2050   ROM_REGION (0x8000, "maincpu",0)
2051   ROM_LOAD ("yis503iibios.rom", 0x0000, 0x8000, CRC(e2242b53) SHA1(706dd67036baeec7127e4ccd8c8db8f6ce7d0e4c))
2052ROM_END
2053
2054MSX_LAYOUT_INIT (yis503ii)
2055   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2056   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2057   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2058   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
2059MSX_LAYOUT_END
2060
2061/* MSX - Yamaha YIS503IIR Russian */
2062
2063ROM_START (y503iir)
2064   ROM_REGION (0xe000, "maincpu",0)
2065   ROM_LOAD ("yis503iirbios.rom",  0x0000, 0x8000, CRC(225a4f9e) SHA1(5173ac403e26c462f904f85c9ef5e7b1e19253e7))
2066   ROM_LOAD ("yis503iirdisk.rom", 0x8000, 0x4000, CRC(9eb7e24d) SHA1(3a481c7b7e4f0406a55952bc5b9f8cf9d699376c))
2067   ROM_LOAD ("yis503iirnet.rom",  0xc000, 0x2000, CRC(0731db3f) SHA1(264fbb2de69fdb03f87dc5413428f6aa19511a7f))
2068ROM_END
2069
2070MSX_LAYOUT_INIT (y503iir)
2071   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2072   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2073   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2074   MSX_LAYOUT_SLOT (3, 1, 1, 2, DISK_ROM2, 0x4000, 0x8000) /* National disk */
2075   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
2076   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x2000, 0xc000)   /* Net */
2077MSX_LAYOUT_END
2078
2079/* MSX - Yamaha YIS503IIR Estonian */
2080
2081ROM_START (y503iir2)
2082   ROM_REGION (0xe000, "maincpu",0)
2083   ROM_LOAD ("yis503ii2bios.rom",  0x0000, 0x8000, CRC(1548cee3) SHA1(42c7fff25b1bd90776ac0aea971241aedce8947d))
2084   ROM_LOAD ("yis503iirdisk.rom", 0x8000, 0x4000, CRC(9eb7e24d) SHA1(3a481c7b7e4f0406a55952bc5b9f8cf9d699376c))
2085   ROM_LOAD ("yis503iirnet.rom",  0xc000, 0x2000, CRC(0731db3f) SHA1(264fbb2de69fdb03f87dc5413428f6aa19511a7f))
2086ROM_END
2087
2088MSX_LAYOUT_INIT (y503iir2)
2089   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2090   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2091   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2092   MSX_LAYOUT_SLOT (3, 1, 1, 2, DISK_ROM2, 0x4000, 0x8000) /* National disk */
2093   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
2094   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x2000, 0xc000)   /* Net */
2095MSX_LAYOUT_END
2096
2097/* MSX - Yamaha YIS503M */
2098
2099ROM_START (yis503m)
2100   ROM_REGION (0x10000, "maincpu",0)
2101   ROM_LOAD ("yis503mbios.rom", 0x0000, 0x8000, CRC(e2242b53) SHA1(706dd67036baeec7127e4ccd8c8db8f6ce7d0e4c))
2102   ROM_LOAD ("sfg05m.rom",       0x8000, 0x8000, CRC(6c2545c9) SHA1(bc4b242647116f4886bb92e86421f97b1be51938))
2103ROM_END
2104
2105MSX_LAYOUT_INIT (yis503m)
2106   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2107   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2108   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2109   MSX_LAYOUT_SLOT (3, 0, 0, 2, ROM, 0x8000, 0x8000)
2110   MSX_LAYOUT_SLOT (3, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
2111MSX_LAYOUT_END
2112
2113/* MSX - Yashica YC-64 */
2114
2115ROM_START (yc64)
2116   ROM_REGION (0x8000, "maincpu",0)
2117   ROM_LOAD ("yc64bios.rom", 0x0000, 0x8000, CRC(e9ccd789) SHA1(8963fc041975f31dc2ab1019cfdd4967999de53e))
2118ROM_END
2119
2120MSX_LAYOUT_INIT (yc64)
2121   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2122   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2123   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2124   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
2125MSX_LAYOUT_END
2126
2127/* MSX - Frael Bruc 100-1 */
2128
2129ROM_START (bruc100)
2130   ROM_REGION (0x8000, "maincpu",0)
2131    ROM_LOAD( "bruc100-1bios.rom", 0x0000, 0x8000, CRC(c7bc4298) SHA1(3abca440cba16ac5e162b602557d30169f77adab))
2132ROM_END
2133
2134MSX_LAYOUT_INIT (bruc100)
2135   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2136   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2137   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2138   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB RAM */
2139MSX_LAYOUT_END
2140
2141
2142/********************************  MSX 2 **********************************/
2143
2144/* MSX2 */
2145
2146ROM_START (msx2)
2147   ROM_REGION (0x20000, "maincpu",0)
2148   ROM_LOAD ("msx2.rom", 0x0000, 0x8000, CRC(f05ed518) SHA1(5e1a4bd6826b29302a1eb88c340477e7cbd0b50a))
2149   ROM_LOAD ("msx2ext.rom", 0x8000, 0x4000, CRC(95db2959) SHA1(e7905d16d2ccd57a013c122dc432106cd59ef52c))
2150   ROM_LOAD_OPTIONAL ("disk.rom", 0xc000, 0x4000, CRC(b7c58fad) SHA1(bc517b4a248c3a1338c5efc937b0128b6a783808))
2151   ROM_LOAD_OPTIONAL ("fmpac.rom", 0x10000, 0x10000, CRC(0e84505d) SHA1(9d789166e3caf28e4742fe933d962e99618c633d))
2152ROM_END
2153
2154MSX_LAYOUT_INIT (msx2)
2155   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2156   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2157   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2158   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2159   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
2160   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2161   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2162MSX_LAYOUT_END
2163
2164/* MSX2 - Al Alamiah AX-350 */
2165
2166ROM_START (ax350)
2167   ROM_REGION (0x44000, "maincpu", 0)
2168   ROM_LOAD ("ax350bios.rom",  0x0000,  0x8000, CRC(ea306155) SHA1(35195ab67c289a0b470883464df66bc6ea5b00d3))
2169   ROM_LOAD ("ax350ext.rom",   0x8000,  0x4000, CRC(7c7540b7) SHA1(ebb76f9061e875365023523607db610f2eda1d26))
2170   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2171   ROM_FILL (0xc000, 0x14000, 0)
2172   ROM_LOAD ("ax350arab.rom", 0x20000,  0x8000, CRC(c0d8fc85) SHA1(2c9600c6e0025fee10d249e97448ecaa37e38c42))
2173   ROM_LOAD ("ax350swp.rom",  0x28000,  0x8000, CRC(076f40fc) SHA1(4b4508131dca6d811694ae6379f41364c477de58))
2174   ROM_LOAD ("ax350paint.rom",0x30000, 0x10000, CRC(18956e3a) SHA1(ace202e87337fbc54fea21e22c0b3af0abe6f4ae))
2175   ROM_LOAD ("ax350disk.rom", 0x40000,  0x4000, CRC(1e7d6512) SHA1(78cd7f847e77fd8cd51a647efb2725ba93f4c471))
2176ROM_END
2177
2178MSX_LAYOUT_INIT (ax350)
2179   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000,  0x0000)  /* Bios */
2180   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000,  0x8000)  /* Ext */
2181   MSX_LAYOUT_SLOT (0, 1, 1, 2, ROM, 0x8000,  0x20000)  /* Arab */
2182   MSX_LAYOUT_SLOT (0, 2, 1, 2, ROM, 0x8000,  0x28000) /* SWP */
2183   MSX_LAYOUT_SLOT (0, 3, 0, 4, ROM, 0x10000, 0x30000)  /* Paint */
2184   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2185   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2186   MSX_LAYOUT_SLOT (3, 1, 1, 2, DISK_ROM2, 0x4000, 0x40000) /* Disk */
2187   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2188   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2189MSX_LAYOUT_END
2190
2191/* MSX2 - Al Alamiah AX-370 */
2192
2193ROM_START (ax370)
2194   ROM_REGION (0x44000, "maincpu", 0)
2195   ROM_LOAD ("ax370bios.rom",  0x0000,  0x8000, CRC(ea306155) SHA1(35195ab67c289a0b470883464df66bc6ea5b00d3))
2196   ROM_LOAD ("ax370ext.rom",   0x8000,  0x4000, CRC(7c7540b7) SHA1(ebb76f9061e875365023523607db610f2eda1d26))
2197   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2198   ROM_FILL (0xc000, 0x14000, 0)
2199   ROM_LOAD ("ax370arab.rom", 0x20000,  0x8000, CRC(c0d8fc85) SHA1(2c9600c6e0025fee10d249e97448ecaa37e38c42))
2200   ROM_LOAD ("ax370swp.rom",  0x28000,  0x8000, CRC(076f40fc) SHA1(4b4508131dca6d811694ae6379f41364c477de58))
2201   ROM_LOAD ("ax370paint.rom",0x30000, 0x10000, CRC(18956e3a) SHA1(ace202e87337fbc54fea21e22c0b3af0abe6f4ae))
2202   ROM_LOAD ("ax370disk.rom", 0x40000,  0x4000, CRC(60f8baba) SHA1(95de8809d2758fc0a743390ea5085b602e59e101))
2203ROM_END
2204
2205MSX_LAYOUT_INIT (ax370)
2206   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000,  0x0000)  /* Bios */
2207   MSX_LAYOUT_SLOT (0, 2, 1, 2, ROM, 0x8000,  0x28000) /* SWP */
2208   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2209   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2210  MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2211   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000,  0x8000)  /* Ext */
2212   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000,  0x20000)  /* Arab */
2213   //MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0x40000) /* TC8566AF Disk controller*/
2214   MSX_LAYOUT_SLOT (3, 3, 0, 4, ROM, 0x10000, 0x30000)  /* Paint */
2215   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2216MSX_LAYOUT_END
2217
2218/* MSX2 - Daewoo CPC-300 */
2219
2220ROM_START (cpc300)
2221   ROM_REGION (0x30000, "maincpu", 0)
2222   ROM_LOAD ("300bios.rom", 0x0000, 0x8000, CRC(53850907) SHA1(affa3c5cd8db79a1450ad8a7f405a425b251653d))
2223   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2224   ROM_FILL (0xc000, 0x14000, 0)
2225   ROM_LOAD ("300ext.rom", 0x20000, 0x8000, CRC(d64da39c) SHA1(fb51c505adfbc174df94289fa894ef969f5357bc))
2226   ROM_LOAD ("300han.rom", 0x28000, 0x8000, CRC(e78cd87f) SHA1(47a9d9a24e4fc6f9467c6e7d61a02d45f5a753ef))
2227ROM_END
2228
2229MSX_LAYOUT_INIT (cpc300)
2230   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2231   MSX_LAYOUT_SLOT (0, 1, 1, 2, ROM, 0x8000, 0x28000)
2232   MSX_LAYOUT_SLOT (0, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2233   MSX_LAYOUT_SLOT (0, 3, 0, 2, ROM, 0x8000, 0x20000)
2234   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2235   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2236   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2237MSX_LAYOUT_END
2238
2239/* MSX2 - Daewoo CPC-300E */
2240
2241ROM_START (cpc300e)
2242   ROM_REGION (0x30000, "maincpu", 0)
2243   ROM_LOAD ("300ebios.rom", 0x0000, 0x8000, CRC(53850907) SHA1(affa3c5cd8db79a1450ad8a7f405a425b251653d))
2244   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2245   ROM_FILL (0xc000, 0x14000, 0)
2246   ROM_LOAD ("300eext.rom", 0x20000, 0x8000, CRC(d64da39c) SHA1(fb51c505adfbc174df94289fa894ef969f5357bc))
2247   ROM_LOAD ("300ehan.rom", 0x28000, 0x4000, CRC(5afea78d) SHA1(f08c91f8c78d681e1f02eaaaaafb87ad81112b60))
2248ROM_END
2249
2250MSX_LAYOUT_INIT (cpc300e)
2251   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2252   MSX_LAYOUT_SLOT (0, 1, 1, 1, ROM, 0x4000, 0x28000)
2253   MSX_LAYOUT_SLOT (0, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2254   MSX_LAYOUT_SLOT (0, 3, 0, 2, ROM, 0x8000, 0x20000)
2255   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2256   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2257   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2258MSX_LAYOUT_END
2259
2260/* MSX2 - Daewoo CPC-400 */
2261ROM_START (cpc400)
2262   ROM_REGION (0x50000, "maincpu", 0)
2263   ROM_LOAD ("400bios.rom", 0x0000, 0x8000, CRC(53850907) SHA1(affa3c5cd8db79a1450ad8a7f405a425b251653d))
2264   ROM_LOAD ("400disk.rom", 0x8000, 0x4000, CRC(5fa517df) SHA1(914f6ccb25d78621186001f2f5e2aaa2d628cd0c))
2265   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2266   ROM_FILL (0xc000, 0x14000, 0)
2267   ROM_LOAD ("400ext.rom", 0x20000, 0x8000, CRC(2ba104a3) SHA1(b6d3649a6647fa9f6bd61efc317485a20901128f))
2268   ROM_LOAD ("400han.rom", 0x28000, 0x8000, CRC(a8ead5e3) SHA1(87936f808423dddfd00629056d6807b4be1dc63e))
2269   ROM_LOAD ("400kfn.rom", 0x30000, 0x20000, CRC(b663c605) SHA1(965f4982790f1817bcbabbb38c8777183b231a55))
2270ROM_END
2271
2272MSX_LAYOUT_INIT (cpc400)
2273   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2274   MSX_LAYOUT_SLOT (0, 1, 1, 2, ROM, 0x8000, 0x28000)
2275   MSX_LAYOUT_SLOT (0, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2276   MSX_LAYOUT_SLOT (0, 3, 0, 2, ROM, 0x8000, 0x20000)
2277   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2278   MSX_LAYOUT_SLOT (2, 0, 1, 2, DISK_ROM2, 0x4000, 0x8000)
2279   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2280   MSX_LAYOUT_KANJI (0x30000)
2281   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2282MSX_LAYOUT_END
2283
2284/* MSX2 - Daewoo CPC-400S */
2285
2286ROM_START (cpc400s)
2287   ROM_REGION (0x50000, "maincpu", 0)
2288   ROM_LOAD ("400sbios.rom", 0x0000, 0x8000, CRC(53850907) SHA1(affa3c5cd8db79a1450ad8a7f405a425b251653d))
2289   ROM_LOAD ("400sdisk.rom", 0x8000, 0x4000, CRC(5fa517df) SHA1(914f6ccb25d78621186001f2f5e2aaa2d628cd0c))
2290   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2291   ROM_FILL (0xc000, 0x14000, 0)
2292   ROM_LOAD ("400sext.rom", 0x20000, 0x8000, CRC(2ba104a3) SHA1(b6d3649a6647fa9f6bd61efc317485a20901128f))
2293   ROM_LOAD ("400shan.rom", 0x28000, 0x8000, CRC(975e7a31) SHA1(6a50295ea35e720ba6f4ba5616c3441128b384ed))
2294   ROM_LOAD ("400skfn.rom", 0x30000, 0x20000, CRC(fa85368c) SHA1(30fff22e3e3d464993707488442721a5e56a9707))
2295ROM_END
2296
2297MSX_LAYOUT_INIT (cpc400s)
2298   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2299   MSX_LAYOUT_SLOT (0, 1, 1, 2, ROM, 0x8000, 0x28000)
2300   MSX_LAYOUT_SLOT (0, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2301   MSX_LAYOUT_SLOT (0, 3, 0, 2, ROM, 0x8000, 0x20000)
2302   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2303   MSX_LAYOUT_SLOT (2, 0, 1, 2, DISK_ROM2, 0x4000, 0x8000)
2304   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2305   MSX_LAYOUT_KANJI (0x30000)
2306   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2307MSX_LAYOUT_END
2308
2309/* MSX2 - Gradiente Expert 2.0 */
2310
2311ROM_START (expert20)
2312   ROM_REGION (0x28000, "maincpu", 0)
2313   ROM_LOAD ("exp20bios.rom", 0x0000, 0x8000, CRC(6BACDCE4) SHA1(9c43106dba3ae2829e9a11dffa9d000ed6d6454c))
2314   ROM_LOAD ("exp20ext.rom",  0x8000, 0x4000, CRC(08CED880) SHA1(4f2a7e0172f0214f025f23845f6e053d0ffd28e8))
2315   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2316   ROM_FILL (0xc000, 0x14000, 0)
2317   ROM_LOAD ("xbasic2.rom", 0x20000, 0x4000, CRC(2825b1a0) SHA1(47370bec7ca1f0615a54eda548b07fbc0c7ef398))
2318   ROM_LOAD ("microsoldisk.rom", 0x24000, 0x4000, CRC(6704ef81) SHA1(a3028515ed829e900cc8deb403e17b09a38bf9b0))
2319ROM_END
2320
2321MSX_LAYOUT_INIT (expert20)
2322   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2323   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2324   MSX_LAYOUT_SLOT (1, 1, 0, 1, ROM, 0x4000, 0x8000) /* EXT */
2325   MSX_LAYOUT_SLOT (1, 1, 1, 1, ROM, 0x4000, 0x20000) /* BASIC */
2326   MSX_LAYOUT_SLOT (1, 3, 1, 1, DISK_ROM, 0x4000, 0x24000) /* Microsol controller */
2327   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2328   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2329   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2330MSX_LAYOUT_END
2331
2332
2333/* MSX2 - National FS-4500 */
2334
2335ROM_START (fs4500)
2336   ROM_REGION (0x94000, "maincpu",0)
2337   ROM_LOAD ("4500bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2338   ROM_LOAD ("4500ext.rom", 0x8000, 0x4000, CRC(4a48779c) SHA1(b8e30d604d319d511cbfbc61e5d8c38fbb9c5a33))
2339   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2340   ROM_FILL (0xc000, 0x14000, 0)
2341   ROM_LOAD ("4500font.rom", 0x20000, 0x4000, CRC(4bd54f95) SHA1(3ce8e35790eb4689b21e14c7ecdd4b63943ee158))
2342   ROM_LOAD ("4500buns.rom", 0x24000, 0x8000, CRC(c9398e11) SHA1(e89ea1e8e583392e2dd9debb8a4b6a162f58ba91))
2343   ROM_LOAD ("4500jush.rom", 0x2c000, 0x8000, CRC(4debfd2d) SHA1(6442c1c5cece64c6dae90cc6ae3675f070d93e06))
2344   ROM_LOAD ("4500wor1.rom", 0x34000, 0xc000, CRC(0c8b5cfb) SHA1(3f047469b62d93904005a0ea29092e892724ce0b))
2345   ROM_LOAD ("4500wor2.rom", 0x40000, 0xc000, CRC(d9909451) SHA1(4c8ea05c09b40c41888fa18db065575a317fda16))
2346   ROM_LOAD ("4500kdr1.rom", 0x4c000, 0x4000, CRC(f8c7f0db) SHA1(df07e89fa0b1c7874f9cdf184c136f964fea4ff4))
2347   ROM_LOAD ("4500kdr2.rom", 0x50000, 0x4000, CRC(69e87c31) SHA1(c63db26660da96af56f8a7d3ea18544b9ae5a37c))
2348   ROM_LOAD ("4500kfn.rom", 0x54000, 0x20000, CRC(956dc96d) SHA1(9ed3ab6d893632b9246e91b412cd5db519e7586b))
2349   ROM_LOAD ("4500budi.rom", 0x74000, 0x20000, CRC(f94590f8) SHA1(1ebb06062428fcdc66808a03761818db2bba3c73))
2350ROM_END
2351
2352MSX_LAYOUT_INIT (fs4500)
2353   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2354   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
2355   MSX_LAYOUT_SLOT (0, 2, 0, 1, ROM, 0x4000, 0x20000)
2356   MSX_LAYOUT_SLOT (0, 3, 1, 2, ROM, 0x8000, 0x2c000)
2357   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2358   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2359   MSX_LAYOUT_SLOT (3, 0, 0, 3, ROM, 0xc000, 0x34000)
2360   MSX_LAYOUT_SLOT (3, 0, 3, 1, ROM, 0x4000, 0x4c000)
2361   MSX_LAYOUT_SLOT (3, 1, 0, 3, ROM, 0xc000, 0x40000)
2362   MSX_LAYOUT_SLOT (3, 1, 3, 1, ROM, 0x4000, 0x50000)
2363   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
2364   MSX_LAYOUT_KANJI (0x54000)
2365/*  MSX_LAYOUT_BUNSETSU (0x74000) */ /* Matsushita Bunsetsu Henkan ROM must be emulated */
2366MSX_LAYOUT_END
2367
2368/* MSX2 - National FS-4600 */
2369
2370ROM_START (fs4600)
2371   ROM_REGION (0x170000, "maincpu",0)
2372   ROM_LOAD ("4600bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2373   ROM_LOAD ("4600ext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2374   ROM_LOAD ("4600disk.rom", 0xc000, 0x4000, CRC(ae4e65b7) SHA1(073feb8bb645d935e099afaf61e6f04f52adee42))
2375   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2376   ROM_FILL (0x10000, 0x10000, 0)
2377   ROM_LOAD ("4600fon1.rom", 0x20000, 0x4000, CRC(7391389b) SHA1(31292b9ca9fe7d1d8833530f44c0a5671bfefe4e))
2378   ROM_LOAD ("4600fon2.rom", 0x24000, 0x4000, CRC(c3a6b445) SHA1(02155fc25c9bd23e1654fe81c74486351e1ecc28))
2379   ROM_LOAD ("4600kdr.rom", 0x28000, 0x8000, CRC(b2db6bf5) SHA1(3a9a942ed888dd641cddf8deada1879c454df3c6))
2380   ROM_LOAD ("4600kfn.rom", 0x30000, 0x20000, CRC(c61ddc5d) SHA1(5e872d5853698731a0ed22fb72dbcdfd59cd19c3))
2381   ROM_LOAD ("4600kf12.rom", 0x50000, 0x20000, CRC(340d1ef7) SHA1(a7a23dc01314e88381eee88b4878b39931ab4818))
2382   ROM_LOAD ("4600firm.rom", 0x70000, 0x100000, CRC(1df57472) SHA1(005794c10a4237de3907ba4a44d436078d3c06c2))
2383ROM_END
2384
2385MSX_LAYOUT_INIT (fs4600)
2386   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2387   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
2388   MSX_LAYOUT_SLOT (0, 2, 0, 1, ROM, 0x4000, 0x20000)
2389   MSX_LAYOUT_SLOT (0, 2, 1, 2, ROM, 0x8000, 0x28000)
2390   MSX_LAYOUT_SLOT (0, 3, 0, 1, ROM, 0x4000, 0x24000)
2391   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2392   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2393   MSX_LAYOUT_SLOT (3, 1, 0, 4, ASCII16, 0x100000, 0x70000) /* National FS-4600 Mapper must be emulated */
2394   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2395   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM2, 0x4000, 0xc000)
2396   MSX_LAYOUT_KANJI (0x30000)
2397/*  MSX_LAYOUT_KANJI_12 (0x50000) */ /* Matsushita 12 dots Kanji ROM must be emulated */
2398   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2399MSX_LAYOUT_END
2400
2401/* MSX2 - National FS-4700 */
2402
2403ROM_START (fs4700)
2404   ROM_REGION (0x94000, "maincpu",0)
2405   ROM_LOAD ("4700bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2406   ROM_LOAD ("4700ext.rom", 0x8000, 0x4000, CRC(4a48779c) SHA1(b8e30d604d319d511cbfbc61e5d8c38fbb9c5a33))
2407   ROM_LOAD ("4700disk.rom", 0xc000, 0x4000, CRC(1e7d6512) SHA1(78cd7f847e77fd8cd51a647efb2725ba93f4c471))
2408   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2409   ROM_FILL (0x10000, 0x10000, 0)
2410   ROM_LOAD ("4700font.rom", 0x20000, 0x4000, CRC(4bd54f95) SHA1(3ce8e35790eb4689b21e14c7ecdd4b63943ee158))
2411   ROM_LOAD ("4700buns.rom", 0x24000, 0x8000, CRC(c9398e11) SHA1(e89ea1e8e583392e2dd9debb8a4b6a162f58ba91))
2412   ROM_LOAD ("4700jush.rom", 0x2c000, 0x8000, CRC(4debfd2d) SHA1(6442c1c5cece64c6dae90cc6ae3675f070d93e06))
2413   ROM_LOAD ("4700wor1.rom", 0x34000, 0xc000, CRC(5f39a727) SHA1(f5af1d2a8bcf247f78847e1a9d995e581df87e8e))
2414   ROM_LOAD ("4700wor2.rom", 0x40000, 0xc000, CRC(d9909451) SHA1(4c8ea05c09b40c41888fa18db065575a317fda16))
2415   ROM_LOAD ("4700kdr1.rom", 0x4c000, 0x4000, CRC(f8c7f0db) SHA1(df07e89fa0b1c7874f9cdf184c136f964fea4ff4))
2416   ROM_LOAD ("4700kdr2.rom", 0x50000, 0x4000, CRC(69e87c31) SHA1(c63db26660da96af56f8a7d3ea18544b9ae5a37c))
2417   ROM_LOAD ("4700kfn.rom", 0x54000, 0x20000, CRC(956dc96d) SHA1(9ed3ab6d893632b9246e91b412cd5db519e7586b))
2418   ROM_LOAD ("4700budi.rom", 0x74000, 0x20000, CRC(f94590f8) SHA1(1ebb06062428fcdc66808a03761818db2bba3c73))
2419ROM_END
2420
2421MSX_LAYOUT_INIT (fs4700)
2422   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2423   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
2424   MSX_LAYOUT_SLOT (0, 2, 0, 1, ROM, 0x4000, 0x20000)
2425   MSX_LAYOUT_SLOT (0, 3, 1, 2, ROM, 0x8000, 0x2c000)
2426   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2427   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2428   MSX_LAYOUT_SLOT (3, 0, 0, 3, ROM, 0xc000, 0x34000)
2429   MSX_LAYOUT_SLOT (3, 0, 3, 1, ROM, 0x4000, 0x4c000)
2430   MSX_LAYOUT_SLOT (3, 1, 0, 3, ROM, 0xc000, 0x40000)
2431   MSX_LAYOUT_SLOT (3, 1, 3, 1, ROM, 0x4000, 0x50000)
2432   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
2433   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM2, 0x4000, 0xc000)
2434   MSX_LAYOUT_KANJI (0x54000)
2435/*  MSX_LAYOUT_BUNSETSU (0x74000) */ /* Matsushita Bunsetsu Henkan ROM must be emulated */
2436MSX_LAYOUT_END
2437
2438/* MSX2 - National FS-5000 */
2439
2440ROM_START (fs5000)
2441   ROM_REGION (0x50000, "maincpu",0)
2442   ROM_LOAD ("5000bios.rom", 0x0000, 0x8000, CRC(a44ea707) SHA1(59967765d6e9328909dee4dac1cbe4cf9d47d315))
2443   ROM_LOAD ("5000ext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2444   ROM_LOAD ("5000disk.rom", 0xc000, 0x4000, CRC(ae4e65b7) SHA1(073feb8bb645d935e099afaf61e6f04f52adee42))
2445   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2446   ROM_FILL (0x10000, 0x10000, 0xff)
2447   ROM_LOAD ("5000rtc.rom", 0x20000, 0x8000, CRC(03351598) SHA1(98bbfa3ab07b7a5cad55d7ddf7cbd9440caa2a86))
2448   ROM_LOAD ("5000kdr.rom", 0x28000, 0x8000, CRC(b2db6bf5) SHA1(3a9a942ed888dd641cddf8deada1879c454df3c6))
2449   ROM_LOAD ("5000kfn.rom", 0x30000, 0x20000, CRC(c61ddc5d) SHA1(5e872d5853698731a0ed22fb72dbcdfd59cd19c3))
2450ROM_END
2451
2452MSX_LAYOUT_INIT (fs5000)
2453   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2454   MSX_LAYOUT_SLOT (0, 1, 0, 4, ROM, 0x10000, 0x10000)
2455   MSX_LAYOUT_SLOT (0, 2, 0, 4, ROM, 0x10000, 0x10000)
2456   MSX_LAYOUT_SLOT (0, 3, 0, 4, ROM, 0x10000, 0x10000)
2457   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2458   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2459   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2460   MSX_LAYOUT_SLOT (3, 0, 1, 2, ROM, 0x8000, 0x28000)
2461   MSX_LAYOUT_SLOT (3, 1, 1, 1, ROM, 0x8000, 0x20000)
2462   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2463   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM2, 0x4000, 0xc000)
2464   MSX_LAYOUT_KANJI (0x30000)
2465   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2466MSX_LAYOUT_END
2467
2468/* MSX2 - National FS-5500F1/F2*/
2469
2470ROM_START (fs5500)
2471   ROM_REGION (0x50000, "maincpu",0)
2472   ROM_LOAD ("5500bios.rom", 0x0000, 0x8000, CRC(5bf38e13) SHA1(44e0dd215b2a9f0770dd76fb49187c05b083eed9))
2473   ROM_LOAD ("5500ext.rom", 0x8000, 0x4000, CRC(3c42c367) SHA1(4be8371f3b03e70ddaca495958345f3c4f8e2d36))
2474   ROM_LOAD ("5500disk.rom", 0xc000, 0x4000, CRC(1e7d6512) SHA1(78cd7f847e77fd8cd51a647efb2725ba93f4c471))
2475   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2476   ROM_FILL (0x10000, 0x10000, 0xff)
2477   ROM_LOAD ("5500imp.rom", 0x20000, 0x8000, CRC(6173a88c) SHA1(b677a861b67e8763a11d5dcf52416b42493ade57))
2478   ROM_LOAD ("5500kdr.rom", 0x28000, 0x8000, CRC(b2db6bf5) SHA1(3a9a942ed888dd641cddf8deada1879c454df3c6))
2479   ROM_LOAD ("5500kfn.rom", 0x30000, 0x20000, CRC(956dc96d) SHA1(9ed3ab6d893632b9246e91b412cd5db519e7586b))
2480ROM_END
2481
2482MSX_LAYOUT_INIT (fs5500)
2483   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2484   MSX_LAYOUT_SLOT (0, 1, 0, 4, ROM, 0x10000, 0x10000)
2485   MSX_LAYOUT_SLOT (0, 2, 0, 4, ROM, 0x10000, 0x10000)
2486   MSX_LAYOUT_SLOT (0, 3, 0, 4, ROM, 0x10000, 0x10000)
2487   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2488   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2489   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2490   MSX_LAYOUT_SLOT (3, 0, 1, 2, ROM, 0x8000, 0x28000)
2491   MSX_LAYOUT_SLOT (3, 1, 1, 1, ROM, 0x8000, 0x20000)
2492   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)   /* 64KB RAM */
2493   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM2, 0x4000, 0xc000)
2494   MSX_LAYOUT_KANJI (0x30000)
2495MSX_LAYOUT_END
2496
2497
2498/* MSX2 - Panasonic FS-A1 */
2499
2500ROM_START (fsa1)
2501   ROM_REGION (0x30000, "maincpu",0)
2502   ROM_LOAD ("a1bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2503   ROM_LOAD ("a1ext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2504   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2505   ROM_FILL (0xc000, 0x14000, 0)
2506   ROM_LOAD ("a1desk1.rom", 0x20000, 0x8000, CRC(99c48147) SHA1(63098f27beac9eca6b39d837d2a552395df33fe1))
2507   ROM_LOAD ("a1desk2.rom", 0x28000, 0x8000, CRC(7f6f4aa1) SHA1(7f5b76605e3d898cc4b5aacf1d7682b82fe84353))
2508ROM_END
2509
2510MSX_LAYOUT_INIT (fsa1)
2511   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2512   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2513   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2514   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64 KB RAM */
2515   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
2516   MSX_LAYOUT_SLOT (3, 2, 1, 2, ROM, 0x8000, 0x20000)
2517   MSX_LAYOUT_SLOT (3, 3, 1, 2, ROM, 0x8000, 0x28000)
2518MSX_LAYOUT_END
2519
2520/* MSX2 - Panasonic FS-A1 (a) */
2521
2522ROM_START (fsa1a)
2523   ROM_REGION (0x30000, "maincpu",0)
2524   ROM_LOAD ("a1bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2525   ROM_LOAD ("a1ext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2526   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2527   ROM_FILL (0xc000, 0x14000, 0)
2528   ROM_LOAD ("a1desk1a.rom", 0x20000, 0x8000, CRC(25b5b170) SHA1(d9307bfdaab1312d25e38af7c0d3a7671a9f716b))
2529   ROM_LOAD ("a1desk2.rom", 0x28000, 0x8000, CRC(7f6f4aa1) SHA1(7f5b76605e3d898cc4b5aacf1d7682b82fe84353))
2530ROM_END
2531
2532MSX_LAYOUT_INIT (fsa1a)
2533   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2534   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2535   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2536   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
2537   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
2538   MSX_LAYOUT_SLOT (3, 2, 1, 2, ROM, 0x8000, 0x20000)
2539   MSX_LAYOUT_SLOT (3, 3, 1, 2, ROM, 0x8000, 0x28000)
2540MSX_LAYOUT_END
2541
2542/* MSX2 - Panasonic FS-A1F */
2543
2544ROM_START (fsa1f)
2545   ROM_REGION (0x50000, "maincpu",0)
2546   ROM_LOAD ("a1fbios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2547   ROM_LOAD ("a1fext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2548   ROM_LOAD ("a1fdisk.rom", 0xc000, 0x4000, CRC(e25cacca) SHA1(607cfca605eaf82e3efa33459d6583efb7ecc13b))
2549   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2550   ROM_FILL (0x10000, 0x10000, 0)
2551   ROM_LOAD ("a1fkdr.rom", 0x20000, 0x8000, CRC(2dbea5ec) SHA1(ea35cc2cad9cfdf56cae224d8ee41579de37f000))
2552   ROM_LOAD ("a1fcock.rom", 0x28000, 0x8000, CRC(5c2948cd) SHA1(4a99f2444f29c2b642efd6f084081d6fd96bfa9b))
2553   ROM_LOAD ("a1fkfn.rom", 0x30000, 0x20000, CRC(c61ddc5d) SHA1(5e872d5853698731a0ed22fb72dbcdfd59cd19c3))
2554ROM_END
2555
2556MSX_LAYOUT_INIT (fsa1f)
2557   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2558   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2559   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2560   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2561   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
2562   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
2563/*  MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000) */ /* FDC Emulation of TC8566AF must be emulated */
2564   MSX_LAYOUT_SLOT (3, 3, 1, 2, ROM, 0x8000, 0x28000)
2565   MSX_LAYOUT_KANJI (0x30000)
2566   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2567MSX_LAYOUT_END
2568
2569/* MSX2 - Panasonic FS-A1FM */
2570
2571ROM_START (fsa1fm)
2572   ROM_REGION (0x180000, "maincpu",0)
2573   ROM_LOAD ("a1fmbios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2574   ROM_LOAD ("a1fmext.rom", 0x8000, 0x4000, CRC(ad295b5d) SHA1(d552319a19814494e3016de4b8f010e8f7b97e02))
2575   ROM_LOAD ("a1fmdisk.rom", 0xc000, 0x4000, CRC(e25cacca) SHA1(607cfca605eaf82e3efa33459d6583efb7ecc13b))
2576   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2577   ROM_FILL (0x10000, 0x10000, 0)
2578   ROM_LOAD ("a1fmkfn.rom", 0x40000, 0x20000, CRC(c61ddc5d) SHA1(5e872d5853698731a0ed22fb72dbcdfd59cd19c3))
2579   ROM_LOAD ("a1fmkf12.rom", 0x60000, 0x20000, CRC(340d1ef7) SHA1(a7a23dc01314e88381eee88b4878b39931ab4818))
2580   ROM_LOAD ("a1fmfirm.rom", 0x80000, 0x100000, CRC(8ce0ece7) SHA1(f89e3d8f3b6855c29d71d3149cc762e0f6918ad5))
2581ROM_END
2582
2583MSX_LAYOUT_INIT (fsa1fm)
2584   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2585   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2586   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2587   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2588   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
2589/*  MSX_LAYOUT_SLOT (3, 1, 1, 2, MODEM_ROM, 0x20000, 0x20000) */ /* Modem Mapper of FS-CM1/A1FM must be emulated */
2590/*  MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000) */ /* FDC Emulation of TC8566AF must be emulated */
2591/*  MSX_LAYOUT_SLOT (3, 3, 0, 4, FSA1FM_ROM, 0x100000, 0x80000) */ /* Panasonic FS-A1FM Mapper must be emulated */
2592   MSX_LAYOUT_KANJI (0x40000)
2593/*  MSX_LAYOUT_KANJI_12 (0x60000) */ /* Matsushita 12 dots Kanji ROM must be emulated */
2594   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2595MSX_LAYOUT_END
2596
2597/* MSX2 - Panasonic FS-A1MK2 */
2598
2599ROM_START (fsa1mk2)
2600   ROM_REGION (0x34000, "maincpu",0)
2601   ROM_LOAD ("a1mkbios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2602   ROM_LOAD ("a1mk2ext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2603   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2604   ROM_FILL (0xc000, 0x14000, 0)
2605   ROM_LOAD ("a1mkcoc1.rom", 0x20000, 0x8000, CRC(0eda3f57) SHA1(2752cd89754c05abdf7c23cba132d38e3ef0f27d))
2606   ROM_LOAD ("a1mkcoc2.rom", 0x28000, 0x4000, CRC(756d7128) SHA1(e194d290ebfa4595ce0349ea2fc15442508485b0))
2607   ROM_LOAD ("a1mkcoc3.rom", 0x2c000, 0x8000, CRC(c1945676) SHA1(a3f4e2e4934074925d775afe30ac72f150ede543))
2608ROM_END
2609
2610MSX_LAYOUT_INIT (fsa1mk2)
2611   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2612   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2613   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2614   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64 KB Mapper RAM */
2615   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
2616   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
2617   MSX_LAYOUT_SLOT (3, 2, 1, 1, ROM, 0x4000, 0x28000)
2618   MSX_LAYOUT_SLOT (3, 3, 1, 2, ROM, 0x8000, 0x2c000)
2619   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2620MSX_LAYOUT_END
2621
2622/* MSX2 - Philips NMS-8220 - 2 possible sets (/00 /16) */
2623
2624ROM_START (nms8220)
2625   ROM_REGION (0x20000, "maincpu", 0)
2626   ROM_LOAD ("8220bios.rom.u14", 0x0000, 0x8000, BAD_DUMP CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
2627   ROM_LOAD ("8220ext.rom.u14", 0x8000, 0x4000, BAD_DUMP CRC(06e4f5e6) SHA1(f5eb0a396097572589f2a6efeed045044e9425e4))
2628   ROM_LOAD ("8220pen.rom.u13", 0xc000, 0x4000, CRC(3d38c53e) SHA1(cb754aed85b3e97a7d3c5894310df7ca18f89f41))
2629   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2630   ROM_FILL (0x10000, 0x10000, 0)
2631ROM_END
2632
2633MSX_LAYOUT_INIT (nms8220)
2634   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2635   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2636   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2637   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2638   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2639   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x4000, 0xc000)
2640   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2641MSX_LAYOUT_END
2642
2643/* MSX2 - Philips NMS-8220 (a) */
2644
2645ROM_START (nms8220a)
2646   ROM_REGION (0x20000, "maincpu", 0)
2647   ROM_LOAD ("8220bios.rom.u14", 0x0000, 0x8000, BAD_DUMP CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
2648   ROM_LOAD ("8220ext.rom.u14", 0x8000, 0x4000, BAD_DUMP CRC(06e4f5e6) SHA1(f5eb0a396097572589f2a6efeed045044e9425e4))
2649   ROM_LOAD ("8220pena.rom.u13", 0xc000, 0x4000, CRC(17817b5a) SHA1(5df95d033ae70b107697b69470126ce1b7ae9eb5))
2650   /* 0x10000 - 0x1ffff reserved for optional fmpac rom from msx2 parent set */
2651   ROM_FILL (0x10000, 0x10000, 0)
2652ROM_END
2653
2654MSX_LAYOUT_INIT (nms8220a)
2655   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2656   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2657   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2658   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2659   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2660   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x4000, 0xc000)
2661   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2662MSX_LAYOUT_END
2663
2664/* MSX2 - Philips NMS-8245 - 2 possible sets (/00 /16) */
2665
2666ROM_START (nms8245)
2667   ROM_REGION (0x40000, "maincpu", 0)
2668   /* 0x10000 - 0x1ffff reserved for optional fmpac rom from msx2 parent set */
2669   ROM_FILL (0x10000, 0x10000, 0)
2670   ROM_LOAD ("nms8245.u7", 0x20000, 0x20000, BAD_DUMP CRC(0c827d5f) SHA1(064e706cb1f12b99b329944ceeedc0efc3b2d9be))
2671ROM_END
2672
2673MSX_LAYOUT_INIT (nms8245)
2674   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x20000)
2675   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2676   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2677   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x28000)
2678   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2679   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0x2c000)
2680   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2681MSX_LAYOUT_END
2682
2683/* MSX2 - Philips NMS-8245F */
2684
2685ROM_START (nms8245f)
2686   ROM_REGION (0x40000, "maincpu", 0)
2687   /* 0x10000 - 0x1ffff reserved for optional fmpac rom from msx2 parent set */
2688   ROM_FILL (0x10000, 0x10000, 0)
2689   ROM_LOAD ("nms8245.u7", 0x20000, 0x20000, BAD_DUMP CRC(0c827d5f) SHA1(064e706cb1f12b99b329944ceeedc0efc3b2d9be))
2690ROM_END
2691
2692MSX_LAYOUT_INIT (nms8245f)
2693   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x30000)
2694   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2695   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2696   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x38000)
2697   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2698   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0x3c000)
2699   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2700MSX_LAYOUT_END
2701
2702/* MSX2 - Philips NMS-8250 */
2703/* Labels taken from an NMS-8250/00 */
2704
2705ROM_START (nms8250)
2706   ROM_REGION (0x20000, "maincpu", 0)
2707   ROM_LOAD ("d23c256eac.ic119", 0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
2708   ROM_LOAD ("d23128ec.ic118", 0x8000, 0x4000, CRC(66237ecf) SHA1(5c1f9c7fb655e43d38e5dd1fcc6b942b2ff68b02))
2709   ROM_LOAD ("jq00014.ic117", 0xc000, 0x04000, CRC(ca3307d3) SHA1(c3efedda7ab947a06d9345f7b8261076fa7ceeef))
2710   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2711   ROM_FILL (0x10000, 0x10000, 0)
2712ROM_END
2713
2714MSX_LAYOUT_INIT (nms8250)
2715   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2716   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2717   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2718   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2719   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2720   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0xc000)
2721   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2722MSX_LAYOUT_END
2723
2724/* MSX2 - Philips NMS-8255 */
2725
2726ROM_START (nms8255)
2727   ROM_REGION (0x20000, "maincpu", 0)
2728   ROM_LOAD ("8255bios.rom.ic119", 0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
2729   ROM_LOAD ("8255ext.rom.ic118", 0x8000, 0x4000, CRC(66237ecf) SHA1(5c1f9c7fb655e43d38e5dd1fcc6b942b2ff68b02))
2730   ROM_LOAD ("8255disk.rom.ic117", 0xc000, 0x04000, CRC(ca3307d3) SHA1(c3efedda7ab947a06d9345f7b8261076fa7ceeef))
2731   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2732   ROM_FILL (0x10000, 0x10000, 0)
2733ROM_END
2734
2735MSX_LAYOUT_INIT (nms8255)
2736   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2737   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2738   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2739   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2740   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2741   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0xc000)
2742   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2743MSX_LAYOUT_END
2744
2745/* MSX2 - Philips NMS-8280 - 2 possible sets (/00 /16) */
2746
2747ROM_START (nms8280)
2748   ROM_REGION (0x20000, "maincpu", 0)
2749   ROM_LOAD ("8280bios.rom.ic119", 0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
2750   ROM_LOAD ("8280ext.rom.ic118", 0x8000, 0x4000, CRC(66237ecf) SHA1(5c1f9c7fb655e43d38e5dd1fcc6b942b2ff68b02))
2751   ROM_LOAD ("8280disk.rom.ic117", 0xc000, 0x04000, CRC(ca3307d3) SHA1(c3efedda7ab947a06d9345f7b8261076fa7ceeef))
2752   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2753   ROM_FILL (0x10000, 0x10000, 0)
2754ROM_END
2755
2756MSX_LAYOUT_INIT (nms8280)
2757   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2758   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2759   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2760   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2761   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2762   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0xc000)
2763   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2764MSX_LAYOUT_END
2765
2766/* MSX2 - Philips NMS-8280G */
2767
2768ROM_START (nms8280g)
2769   ROM_REGION (0x20000, "maincpu", 0)
2770   ROM_LOAD ("8280gbios.rom.ic119", 0x0000, 0x8000, CRC(8fa060e2) SHA1(b17d9bea0eb16a1aa2d0ccbd7c9488da9f57698e))
2771   ROM_LOAD ("8280gext.rom.ic118", 0x8000, 0x4000, CRC(41e36d03) SHA1(4ab7b2030d022f5486abaab22aaeaf8aa23e05f3))
2772   ROM_LOAD ("8280gdisk.rom.ic117", 0xc000, 0x04000, CRC(d0beebb8) SHA1(d1001f93c87ff7fb389e418e33bf7bc81bdbb65f))
2773   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2774   ROM_FILL (0x10000, 0x10000, 0)
2775ROM_END
2776
2777MSX_LAYOUT_INIT (nms8280g)
2778   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2779   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2780   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2781   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2782   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2783   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0xc000)
2784   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2785MSX_LAYOUT_END
2786
2787/* MSX2 - Philips VG-8230 (u11 - exp, u12 - basic, u13 - disk */
2788
2789ROM_START (vg8230)
2790   ROM_REGION (0x20000, "maincpu", 0)
2791   ROM_LOAD ("8230bios.rom.u12", 0x0000, 0x8000, CRC(b31c851d) SHA1(0de3c802057560560a03d7965fcc4cff69f8575c))
2792   ROM_LOAD ("8230ext.rom.u11", 0x8000, 0x4000, CRC(8f84f783) SHA1(3288894e1be6af705871499b23c85732dbc40993))
2793   ROM_LOAD ("8230disk.rom.u13", 0xc000, 0x4000, CRC(77c4e5bc) SHA1(849f93867ff7846b27f84d0be418569faf058ac2))
2794   /* 0x10000 - 0x1ffff reserved for optional fmpac rom from msx2 parent set */
2795   ROM_FILL (0x10000, 0x10000, 0)
2796ROM_END
2797
2798MSX_LAYOUT_INIT (vg8230)
2799   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2800   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2801   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2802   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2803   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2804   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0xc000)
2805   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2806MSX_LAYOUT_END
2807
2808/* MSX2 - Philips VG-8235 3 psosible basic and ext roms (/00 /02 /19) */
2809
2810ROM_START (vg8235)
2811   ROM_REGION (0x20000, "maincpu", 0)
2812   ROM_LOAD ("8235bios.rom.u48", 0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
2813   ROM_LOAD ("8235ext.rom.u49", 0x8000, 0x4000, CRC(66237ecf) SHA1(5c1f9c7fb655e43d38e5dd1fcc6b942b2ff68b02))
2814   ROM_LOAD ("8235disk.rom.u50", 0xc000, 0x4000, CRC(51daeb25) SHA1(8954e59aa79310c7b719ecf0cde1e82fb731dcd1))
2815   /* 0x10000 - 0x1ffff reserved for optional fmpac rom from msx2 parent set */
2816   ROM_FILL (0x10000, 0x10000, 0)
2817ROM_END
2818
2819MSX_LAYOUT_INIT (vg8235)
2820   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2821   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2822   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2823   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2824   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2825   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0xc000)
2826   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2827MSX_LAYOUT_END
2828
2829/* MSX2 - Philips VG-8235F */
2830
2831ROM_START (vg8235f)
2832   ROM_REGION (0x20000, "maincpu", 0)
2833   ROM_LOAD ("8235fbios.rom.u48", 0x0000, 0x8000, CRC(c0577a50) SHA1(3926cdd91fa89657a811463e48cfbdb350676e51))
2834   ROM_LOAD ("8235fext.rom.u49", 0x8000, 0x4000, CRC(e235d5c8) SHA1(792e6b2814ab783d06c7576c1e3ccd6a9bbac34a))
2835   ROM_LOAD ("8235fdisk.rom.u50", 0xc000, 0x4000, CRC(77c4e5bc) SHA1(849f93867ff7846b27f84d0be418569faf058ac2))
2836   /* 0x10000 - 0x1ffff reserved for optional fmpac rom from msx2 parent set */
2837   ROM_FILL (0x10000, 0x10000, 0)
2838ROM_END
2839
2840MSX_LAYOUT_INIT (vg8235f)
2841   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2842   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2843   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2844   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2845   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2846   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0xc000)
2847   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2848MSX_LAYOUT_END
2849
2850/* MSX2 - Philips VG-8240 */
2851
2852ROM_START (vg8240)
2853   ROM_REGION (0x20000, "maincpu", 0)
2854   ROM_LOAD ("8240bios.rom", 0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
2855   ROM_LOAD ("8240ext.rom", 0x8000, 0x4000, CRC(66237ecf) SHA1(5c1f9c7fb655e43d38e5dd1fcc6b942b2ff68b02))
2856   ROM_LOAD ("8240disk.rom", 0xc000, 0x4000, CRC(ca3307d3) SHA1(c3efedda7ab947a06d9345f7b8261076fa7ceeef))
2857   /* 0x10000 - 0x1ffff reserved for optional fmpac rom from msx2 parent set */
2858   ROM_FILL (0x10000, 0x10000, 0)
2859ROM_END
2860
2861MSX_LAYOUT_INIT (vg8240)
2862   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2863   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2864   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2865   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2866   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2867   MSX_LAYOUT_SLOT (3, 3, 1, 2, DISK_ROM, 0x4000, 0xc000)
2868   MSX_LAYOUT_RAMIO_SET_BITS (0xf8)
2869MSX_LAYOUT_END
2870
2871/* MSX2 - Sanyo Wavy PHC-23 */
2872
2873ROM_START (phc23)
2874   ROM_REGION (0x20000, "maincpu",0)
2875   ROM_LOAD ("23bios.rom", 0x0000, 0x8000, CRC(ba81b3dd) SHA1(4ce41fcc1a603411ec4e99556409c442078f0ecf))
2876   ROM_LOAD ("23ext.rom", 0x8000, 0x4000, CRC(90ca25b5) SHA1(fd9fa78bac25aa3c0792425b21d14e364cf7eea4))
2877   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2878   ROM_FILL (0xc000, 0x14000, 0)
2879ROM_END
2880
2881MSX_LAYOUT_INIT (phc23)
2882   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2883   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2884   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2885   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2886   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
2887MSX_LAYOUT_END
2888
2889/* MSX2 - Sharp Epcom HotBit 2.0 */
2890
2891ROM_START (hotbit20)
2892   ROM_REGION (0x28000, "maincpu", 0)
2893   ROM_LOAD ("hb2bios.rom", 0x0000, 0x8000, CRC(0160e8c9) SHA1(d0cfc35f22b150a1cb10decae4841dfe63b78251))
2894   ROM_LOAD ("hb2ext.rom",  0x8000, 0x4000, CRC(08ced880) SHA1(4f2a7e0172f0214f025f23845f6e053d0ffd28e8))
2895   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2896   ROM_FILL (0xc000, 0x14000, 0)
2897   ROM_LOAD ("xbasic2.rom", 0x20000, 0x4000, CRC(2825b1a0) SHA1(47370bec7ca1f0615a54eda548b07fbc0c7ef398))
2898   ROM_LOAD ("microsoldisk.rom", 0x24000, 0x4000, CRC(6704ef81) SHA1(a3028515ed829e900cc8deb403e17b09a38bf9b0))
2899ROM_END
2900
2901MSX_LAYOUT_INIT (hotbit20)
2902   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2903   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2904   MSX_LAYOUT_SLOT (1, 1, 0, 1, ROM, 0x4000, 0x8000) /* EXT */
2905   MSX_LAYOUT_SLOT (1, 1, 1, 1, ROM, 0x4000, 0x20000) /* BASIC */
2906   MSX_LAYOUT_SLOT (1, 3, 1, 1, DISK_ROM, 0x4000, 0x24000) /* Microsol controller */
2907   MSX_LAYOUT_SLOT (2, 0, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
2908   MSX_LAYOUT_SLOT (3, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2909   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2910MSX_LAYOUT_END
2911
2912/* MSX2 - Sony HB-F1 */
2913
2914ROM_START (hbf1)
2915   ROM_REGION (0x34000, "maincpu",0)
2916   ROM_LOAD ("f1bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2917   ROM_LOAD ("f1ext.rom", 0x8000, 0x4000, CRC(4a48779c) SHA1(b8e30d604d319d511cbfbc61e5d8c38fbb9c5a33))
2918   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2919   ROM_FILL (0xc000, 0x14000, 0)
2920   ROM_LOAD ("f1note1.rom", 0x20000, 0x4000, CRC(84810ea8) SHA1(9db72bb78792595a12499c821048504dc96ef848))
2921   ROM_LOAD ("f1note2.rom", 0x24000, 0x8000, CRC(e32e5ee0) SHA1(aa78fc9bcd2343f84cf790310a768ee47f90c841))
2922   ROM_LOAD ("f1note3.rom", 0x2c000, 0x8000, CRC(73eb9329) SHA1(58accf41a90693874b86ce98d8d43c27beb8b6dc))
2923ROM_END
2924
2925MSX_LAYOUT_INIT (hbf1)
2926   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2927   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2928   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2929   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2930   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0x20000)
2931   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x24000)
2932   MSX_LAYOUT_SLOT (3, 2, 1, 2, ROM, 0x8000, 0x2c000)
2933   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM, 0x10000, 0x0000)  /* 64KB RAM */
2934MSX_LAYOUT_END
2935
2936/* MSX2 - Sony HB-F1II */
2937
2938ROM_START (hbf12)
2939   ROM_REGION (0x34000, "maincpu",0)
2940   ROM_LOAD ("f12bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
2941   ROM_LOAD ("f12ext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2942   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2 parent set */
2943   ROM_FILL (0xc000, 0x14000, 0)
2944   ROM_LOAD ("f12note1.rom", 0x20000, 0x4000, CRC(dcacf970) SHA1(30d914cda2180889a40a3328e0a0c1327f4eaa10))
2945   ROM_LOAD ("f12note2.rom", 0x24000, 0x8000, CRC(b0241a61) SHA1(ed2fea5c2a3c2e58d4f69f9d636e08574486a2b1))
2946   ROM_LOAD ("f12note3.rom", 0x2c000, 0x8000, CRC(44a10e6a) SHA1(917d1c079e03c4a44de864f123d03c4e32c8daae))
2947ROM_END
2948
2949MSX_LAYOUT_INIT (hbf12)
2950   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2951   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2952   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2953   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2954   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0x20000)
2955   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x24000)
2956   MSX_LAYOUT_SLOT (3, 2, 1, 2, ROM, 0x8000, 0x2c000)
2957   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2958   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2959MSX_LAYOUT_END
2960
2961/* MSX2 - Sony HB-F1XD */
2962
2963ROM_START (hbf1xd)
2964   ROM_REGION (0x20000, "maincpu",0)
2965   ROM_LOAD ("f1xdbios.rom.ic27", 0x0000, 0x8000, BAD_DUMP CRC(ba81b3dd) SHA1(4ce41fcc1a603411ec4e99556409c442078f0ecf))
2966   ROM_LOAD ("f1xdext.rom.ic27", 0x8000, 0x4000, BAD_DUMP CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2967   ROM_LOAD ("f1xddisk.rom.ic27", 0xc000, 0x4000, BAD_DUMP CRC(54c73ad6) SHA1(12f2cc79b3d09723840bae774be48c0d721ec1c6))
2968   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2969   ROM_FILL (0x10000, 0x10000, 0)
2970ROM_END
2971
2972MSX_LAYOUT_INIT (hbf1xd)
2973   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2974   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2975   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2976   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2977   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
2978   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
2979   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
2980MSX_LAYOUT_END
2981
2982/* MSX2 - Sony HB-F1XDMK2 */
2983
2984ROM_START (hbf1xdm2)
2985   ROM_REGION (0x20000, "maincpu",0)
2986   ROM_LOAD ("f1m2bios.rom.ic27", 0x0000, 0x8000, BAD_DUMP CRC(ba81b3dd) SHA1(4ce41fcc1a603411ec4e99556409c442078f0ecf))
2987   ROM_LOAD ("f1m2ext.rom.ic27", 0x8000, 0x4000, BAD_DUMP CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
2988   ROM_LOAD ("f1m2disk.rom.ic27", 0xc000, 0x4000, BAD_DUMP CRC(54c73ad6) SHA1(12f2cc79b3d09723840bae774be48c0d721ec1c6))
2989   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
2990   ROM_FILL (0x10000, 0x10000, 0)
2991ROM_END
2992
2993MSX_LAYOUT_INIT (hbf1xdm2)
2994   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
2995   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
2996   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
2997   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
2998   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
2999   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3000   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3001MSX_LAYOUT_END
3002
3003/* MSX2 - Sony HB-F500 */
3004
3005ROM_START (hbf500)
3006   ROM_REGION (0x40000, "maincpu", 0)
3007   ROM_LOAD ("f500bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
3008   ROM_LOAD ("f500ext.rom", 0x8000, 0x4000, CRC(4a48779c) SHA1(b8e30d604d319d511cbfbc61e5d8c38fbb9c5a33))
3009   ROM_LOAD ("f500disk.rom", 0xc000, 0x4000, CRC(f7f5b0ea) SHA1(e93b8da1e8dddbb3742292b0e5e58731b90e9313))
3010   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3011   ROM_FILL (0x10000, 0x10000, 0)
3012   ROM_LOAD ("f500kfn.rom", 0x20000, 0x20000, CRC(5a59926e) SHA1(6acaf2eeb57f65f7408235d5e07b7563229de799))
3013ROM_END
3014
3015MSX_LAYOUT_INIT (hbf500)
3016   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3017   MSX_LAYOUT_SLOT (0, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
3018   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
3019   MSX_LAYOUT_SLOT (0, 1, 1, 2, DISK_ROM, 0x4000, 0xc000)
3020   MSX_LAYOUT_SLOT (0, 2, 0, 2, RAM, 0x8000, 0x0000)   /* 32KB RAM */
3021   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3022   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3023   MSX_LAYOUT_KANJI (0x20000)
3024MSX_LAYOUT_END
3025
3026/* MSX2 - Sony HB-F500P */
3027
3028ROM_START (hbf500p)
3029   ROM_REGION (0x20000, "maincpu", 0)
3030   ROM_LOAD ("500pbios.rom.ic41", 0x0000, 0x8000, CRC(b31c851d) SHA1(0de3c802057560560a03d7965fcc4cff69f8575c))
3031   ROM_LOAD ("500pext.ic47", 0x8000, 0x8000, CRC(cdd4824a) SHA1(505031f1e8396a6e0cb11c1540e6e7f6999d1191))
3032   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3033   ROM_FILL (0x10000, 0x10000, 0)
3034ROM_END
3035
3036MSX_LAYOUT_INIT (hbf500p)
3037   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3038   MSX_LAYOUT_SLOT (0, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
3039   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
3040   MSX_LAYOUT_SLOT (0, 1, 1, 2, DISK_ROM, 0x4000, 0xc000)
3041   MSX_LAYOUT_SLOT (0, 2, 0, 2, RAM, 0x8000, 0x0000)   /* 32KB RAM */
3042   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3043   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3044   MSX_LAYOUT_SLOT (3, 0, 0, 4, ROM, 0x10000, 0x10000)
3045MSX_LAYOUT_END
3046
3047/* MSX2 - Sony HB-F700D */
3048
3049ROM_START (hbf700d)
3050   ROM_REGION (0x20000, "maincpu", 0)
3051   ROM_LOAD ("700dbios.rom.ic5", 0x0000, 0x8000, CRC(e975aa79) SHA1(cef16eb95502ba6ab2265fcafcedde470a101541))
3052   ROM_LOAD ("700dext.ic6", 0x8000, 0x8000, CRC(100cf756) SHA1(317722fa36c2ed31c07c5218b43490fd5badf1f8))
3053   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3054   ROM_FILL (0x10000, 0x10000, 0)
3055ROM_END
3056
3057MSX_LAYOUT_INIT (hbf700d)
3058   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3059   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3060   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3061   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3062   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
3063   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM_MM, 0x40000, 0x0000)   /* 256KB Mapper RAM */
3064   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3065MSX_LAYOUT_END
3066
3067/* MSX2 - Sony HB-F700F */
3068
3069ROM_START (hbf700f)
3070   ROM_REGION (0x20000, "maincpu", 0)
3071   ROM_LOAD ("700fbios.ic5", 0x0000, 0x8000, CRC(440dae3c) SHA1(fedd9b682d056ddd1e9b3d281723e12f859b2e69))
3072   ROM_LOAD ("700fext.ic6", 0x8000, 0x8000, CRC(7c8b07b1) SHA1(ecacb20ba0a9bbd25e8c0f128d64dd66f8cd8bee))
3073   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3074   ROM_FILL (0x10000, 0x10000, 0)
3075ROM_END
3076
3077MSX_LAYOUT_INIT (hbf700f)
3078   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3079   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3080   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3081   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3082   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
3083   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM_MM, 0x40000, 0x0000)   /* 256KB Mapper RAM */
3084   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3085MSX_LAYOUT_END
3086
3087/* MSX2 - Sony HB-F700P */
3088
3089ROM_START (hbf700p)
3090   ROM_REGION (0x20000, "maincpu", 0)
3091   ROM_LOAD ("700pbios.rom.ic5", 0x0000, 0x8000, CRC(b31c851d) SHA1(0de3c802057560560a03d7965fcc4cff69f8575c))
3092   ROM_LOAD ("700pext.ic6", 0x8000, 0x8000, CRC(63e1bffc) SHA1(496698a60432490dc1306c8cc1d4a6ded275261a))
3093   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3094   ROM_FILL (0x10000, 0x10000, 0)
3095ROM_END
3096
3097MSX_LAYOUT_INIT (hbf700p)
3098   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3099   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3100   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3101   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3102   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
3103   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM_MM, 0x40000, 0x0000)   /* 256KB Mapper RAM */
3104   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3105MSX_LAYOUT_END
3106
3107/* MSX2 - Sony HB-F700S */
3108
3109ROM_START (hbf700s)
3110   ROM_REGION (0x20000, "maincpu", 0)
3111   ROM_LOAD ("700sbios.rom.ic5", 0x0000, 0x8000, CRC(c2b889a5) SHA1(4811956f878c3e03da46317f787cdc4bebc86f47))
3112   ROM_LOAD ("700sext.ic6", 0x8000, 0x8000, CRC(28d1badf) SHA1(ae3ed88a2d7034178e08f7bdf5409f462bf67fc9))
3113   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3114   ROM_FILL (0x10000, 0x10000, 0)
3115ROM_END
3116
3117MSX_LAYOUT_INIT (hbf700s)
3118   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3119   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3120   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3121   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3122   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
3123   MSX_LAYOUT_SLOT (3, 3, 0, 4, RAM_MM, 0x40000, 0x0000)   /* 256KB Mapper RAM */
3124   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3125MSX_LAYOUT_END
3126
3127/* MSX2 - Sony HB-F900 */
3128ROM_START (hbf900)
3129   ROM_REGION (0x44000, "maincpu", 0)
3130   ROM_LOAD ("f900bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
3131   ROM_LOAD ("f900ext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
3132   ROM_LOAD ("f900disk.rom", 0xc000, 0x4000, CRC(f83d0ea6) SHA1(fc760d1d7b16370abc7eea39955f230b95b37df6))
3133   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3134   ROM_FILL (0x10000, 0x10000, 0)
3135   ROM_LOAD ("f900util.rom", 0x20000, 0x4000, CRC(bc6c7c66) SHA1(558b7383544542cf7333700ff90c3efbf93ba2a3))
3136   ROM_LOAD ("f900kfn.rom", 0x24000, 0x20000, CRC(5a59926e) SHA1(6acaf2eeb57f65f7408235d5e07b7563229de799))
3137ROM_END
3138
3139MSX_LAYOUT_INIT (hbf900)
3140   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3141   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3142   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3143   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3144   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
3145   MSX_LAYOUT_SLOT (3, 1, 0, 4, RAM_MM, 0x40000, 0x0000)   /* 256KB Mapper RAM */
3146   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x4000, 0x10000)
3147   MSX_LAYOUT_KANJI (0x24000)
3148   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3149MSX_LAYOUT_END
3150
3151/* MSX2 - Sony HB-F900 (a) */
3152ROM_START (hbf900a)
3153   ROM_REGION (0x44000, "maincpu", 0)
3154   ROM_LOAD ("f900bios.rom", 0x0000, 0x8000, CRC(9b3e7b97) SHA1(0081ea0d25bc5cd8d70b60ad8cfdc7307812c0fd))
3155   ROM_LOAD ("f900ext.rom", 0x8000, 0x4000, CRC(43e7a7fc) SHA1(0fbd45ef3dd7bb82d4c31f1947884f411f1ca344))
3156   ROM_LOAD ("f900disa.rom", 0xc000, 0x4000, CRC(54c73ad6) SHA1(12f2cc79b3d09723840bae774be48c0d721ec1c6))
3157   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3158   ROM_FILL (0x10000, 0x10000, 0)
3159   ROM_LOAD ("f900util.rom", 0x20000, 0x4000, CRC(bc6c7c66) SHA1(558b7383544542cf7333700ff90c3efbf93ba2a3))
3160   ROM_LOAD ("f900kfn.rom", 0x24000, 0x20000, CRC(5a59926e) SHA1(6acaf2eeb57f65f7408235d5e07b7563229de799))
3161ROM_END
3162
3163MSX_LAYOUT_INIT (hbf900a)
3164   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3165   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3166   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3167   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3168   MSX_LAYOUT_SLOT (3, 0, 1, 2, DISK_ROM, 0x4000, 0xc000)
3169   MSX_LAYOUT_SLOT (3, 1, 0, 4, RAM_MM, 0x40000, 0x0000)   /* 256KB Mapper RAM */
3170   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x4000, 0x10000)
3171   MSX_LAYOUT_KANJI (0x24000)
3172   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3173MSX_LAYOUT_END
3174
3175/* MSX2 - Sony HB-F9P */
3176
3177ROM_START (hbf9p)
3178   ROM_REGION (0x28000, "maincpu", 0)
3179   ROM_LOAD ("f9pbios.rom.ic11", 0x0000, 0x8000, CRC(b31c851d) SHA1(0de3c802057560560a03d7965fcc4cff69f8575c))
3180   ROM_LOAD ("f9pfirm1.ic12", 0x8000, 0x8000, CRC(524f67aa) SHA1(41a186afced50ca6312cb5b6c4adb684faca6232))
3181   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3182   ROM_FILL (0x10000, 0x10000, 0)
3183   ROM_LOAD ("f9pfirm2.rom.ic13", 0x20000, 0x8000, CRC(ea97069f) SHA1(2d1880d1f5a6944fcb1b198b997a3d90ecd1903d))
3184ROM_END
3185
3186MSX_LAYOUT_INIT (hbf9p)
3187   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3188   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3189   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3190   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3191   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0xc000)
3192   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3193   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
3194   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3195MSX_LAYOUT_END
3196
3197/* MSX2 - Sony HB-F9P Russian */
3198
3199/* MSX2 - Sony HB-F9S */
3200ROM_START (hbf9s)
3201   ROM_REGION (0x28000, "maincpu", 0)
3202   ROM_LOAD ("f9sbios.ic11", 0x0000, 0x8000, CRC(c2b889a5) SHA1(4811956f878c3e03da46317f787cdc4bebc86f47))
3203   ROM_LOAD ("f9sfirm1.ic12", 0x8000, 0x8000, CRC(cf39620b) SHA1(1166a93d7185ba024bdf2bfa9a30e1c447fb6db1))
3204   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3205   ROM_FILL (0x10000, 0x10000, 0)
3206   ROM_LOAD ("f9sfirm2.ic13", 0x20000, 0x8000, CRC(ea97069f) SHA1(2d1880d1f5a6944fcb1b198b997a3d90ecd1903d))
3207ROM_END
3208
3209MSX_LAYOUT_INIT (hbf9s)
3210   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3211   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3212   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3213   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3214   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0xc000)
3215   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3216   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
3217   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3218MSX_LAYOUT_END
3219
3220/* MSX2 - Sony HB-G900AP */
3221
3222/* IC109 - 32KB Basic ROM SLOT#00 0000-7FFF */
3223/* IC112 - 16KB Basic ROM SLOT#01 0000-3FFF */
3224/* IC117 - 16KB Disk ROM SLOT#01 4000-7FFF */
3225/* IC123 - 32KB ROM RS232C ROM SLOT#02 4000-7FFF / Video Utility ROM SLOT#03 4000-7FFF */
3226
3227/* MSX2 - Sony HB-G900AP */
3228ROM_START (hbg900ap)
3229   ROM_REGION (0x28000, "maincpu", 0)
3230   ROM_LOAD ("g900bios.rom", 0x0000, 0x8000, CRC(b31c851d) SHA1(0de3c802057560560a03d7965fcc4cff69f8575c))
3231   ROM_LOAD ("g900ext.rom", 0x8000, 0x4000, CRC(8f84f783) SHA1(3288894e1be6af705871499b23c85732dbc40993))
3232   ROM_LOAD ("g900disk.rom", 0xc000, 0x4000, CRC(54c73ad6) SHA1(12f2cc79b3d09723840bae774be48c0d721ec1c6))
3233   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3234   ROM_FILL (0x10000, 0x10000, 0)
3235   ROM_LOAD ("g900232c.rom", 0x20000, 0x4000, CRC(06cf1da6) SHA1(373aa82d0426830880a7344ef98f7309d93814c7))
3236   ROM_LOAD ("g900util.rom", 0x24000, 0x4000, CRC(d0417c20) SHA1(8779b004e7605a3c419825f0373a5d8fa84e1d5b))
3237ROM_END
3238
3239MSX_LAYOUT_INIT (hbg900ap)
3240   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3241   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
3242   MSX_LAYOUT_SLOT (0, 1, 1, 2, DISK_ROM, 0x4000, 0xc000)
3243/*  MSX_LAYOUT_SLOT (0, 2, 1, 1, ROM, 0x4000, 0x20000) */ /* RS232C must be emulated */
3244   MSX_LAYOUT_SLOT (0, 3, 1, 1, ROM, 0x4000, 0x24000)
3245   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3246   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3247   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x80000, 0x0000)   /* 512KB Mapper RAM */
3248   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3249MSX_LAYOUT_END
3250
3251
3252/* MSX2 - Sony HB-G900P - 3x 32KB ROMs */
3253
3254ROM_START (hbg900p)
3255   ROM_REGION (0x28000, "maincpu", 0)
3256   ROM_LOAD ("g900bios.rom", 0x0000, 0x8000, CRC(b31c851d) SHA1(0de3c802057560560a03d7965fcc4cff69f8575c))
3257   ROM_LOAD ("g900ext.rom", 0x8000, 0x4000, CRC(8f84f783) SHA1(3288894e1be6af705871499b23c85732dbc40993))
3258   ROM_LOAD ("g900disk.rom", 0xc000, 0x4000, CRC(54c73ad6) SHA1(12f2cc79b3d09723840bae774be48c0d721ec1c6))
3259   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3260   ROM_FILL (0x10000, 0x10000, 0)
3261   ROM_LOAD ("g900232c.rom", 0x20000, 0x4000, CRC(06cf1da6) SHA1(373aa82d0426830880a7344ef98f7309d93814c7))
3262   ROM_LOAD ("g900util.rom", 0x24000, 0x4000, CRC(d0417c20) SHA1(8779b004e7605a3c419825f0373a5d8fa84e1d5b))
3263ROM_END
3264
3265MSX_LAYOUT_INIT (hbg900p)
3266   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3267   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
3268   MSX_LAYOUT_SLOT (0, 1, 1, 2, DISK_ROM, 0x4000, 0xc000)
3269/*  MSX_LAYOUT_SLOT (0, 2, 1, 1, ROM, 0x4000, 0x20000) */ /* RS232C must be emulated */
3270   MSX_LAYOUT_SLOT (0, 3, 1, 1, ROM, 0x4000, 0x24000)
3271   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3272   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3273   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3274   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3275MSX_LAYOUT_END
3276
3277/* MSX2 - Talent TPC-310 */
3278ROM_START (tpc310)
3279   ROM_REGION (0x2c000, "maincpu", 0)
3280   ROM_LOAD ("tpc310bios.rom",  0x0000, 0x8000, CRC(8cd3e845) SHA1(7bba23669b7abfb6a142f9e1735b847d6e4e8267))
3281   ROM_LOAD ("tpc310ext.rom",   0x8000, 0x4000, CRC(094a9e7a) SHA1(39dfc46260f99b670916b1e55f67a5d4136e6e54))
3282   ROM_LOAD ("dpf550disk.rom",  0xc000, 0x4000, CRC(347b1b44) SHA1(c1d83c559e1e6a6da961eafa55aab105681c634c))
3283   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3284   ROM_FILL (0x10000, 0x10000, 0)
3285   ROM_LOAD ("tpc310turbo.rom",0x20000, 0x4000, CRC(0ea62a4d) SHA1(181bf58da7184e128cd419da3109b93344a543cf))
3286   ROM_LOAD ("tpc310acc.rom",  0x24000, 0x8000, CRC(4fb8fab3) SHA1(cdeb0ed8adecaaadb78d5a5364fd603238591685))
3287ROM_END
3288
3289MSX_LAYOUT_INIT (tpc310)
3290   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3291   MSX_LAYOUT_SLOT (1, 0, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
3292   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3293   MSX_LAYOUT_SLOT (3, 0, 0, 1, ROM, 0x4000, 0x8000)
3294   MSX_LAYOUT_SLOT (3, 0, 1, 1, ROM, 0x4000, 0x20000)
3295   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x24000)
3296   MSX_LAYOUT_SLOT (3, 2, 1, 1, DISK_ROM2, 0x4000, 0xc000)
3297   MSX_LAYOUT_SLOT (3, 3, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3298   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3299MSX_LAYOUT_END
3300
3301/* MSX2 - Toshiba HX-23 */
3302
3303ROM_START (hx23)
3304   ROM_REGION (0x30000, "maincpu", 0)
3305   ROM_LOAD ("hx23bios.rom",  0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
3306   ROM_LOAD ("hx23ext.rom",   0x8000, 0x4000, CRC(06e4f5e6) SHA1(f5eb0a396097572589f2a6efeed045044e9425e4))
3307   /* 0xc000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3308   ROM_FILL (0xc000, 0x14000, 0)
3309   ROM_LOAD ("hx23word.rom", 0x20000, 0x8000, CRC(39b3e1c0) SHA1(9f7cfa932bd7dfd0d9ecaadc51655fb557c2e125))
3310   ROM_FILL (0x28000, 0x8000, 0)
3311ROM_END
3312
3313MSX_LAYOUT_INIT (hx23)
3314   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3315   MSX_LAYOUT_SLOT (0, 0, 2, 2, RAM, 0x8000, 0x8000)   /* 32KB RAM */
3316   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3317   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3318   MSX_LAYOUT_SLOT (3, 0, 0, 2, RAM, 0x8000, 0x0000)   /* 32KB RAM */
3319   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3320   MSX_LAYOUT_SLOT (3, 3, 0, 4, ROM, 0x10000, 0x20000)
3321   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3322MSX_LAYOUT_END
3323
3324/* MSX2 - Toshiba HX-23F */
3325
3326ROM_START (hx23f)
3327   ROM_REGION (0x30000, "maincpu", 0)
3328   ROM_LOAD ("hx23fbios.rom",  0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
3329   ROM_LOAD ("hx23fext.rom",   0x8000, 0x4000, CRC(06e4f5e6) SHA1(f5eb0a396097572589f2a6efeed045044e9425e4))
3330   /* 0xc000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3331   ROM_FILL (0xc000, 0x14000, 0)
3332   ROM_LOAD ("hx23fword.rom", 0x20000, 0x8000, CRC(39b3e1c0) SHA1(9f7cfa932bd7dfd0d9ecaadc51655fb557c2e125))
3333   ROM_FILL (0x28000, 0x8000, 0)
3334ROM_END
3335
3336MSX_LAYOUT_INIT (hx23f)
3337   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3338   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3339   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3340   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
3341   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3342   MSX_LAYOUT_SLOT (3, 3, 0, 4, ROM, 0x10000, 0x20000)
3343   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3344MSX_LAYOUT_END
3345
3346/* MSX2 - Yamaha CX7M */
3347
3348ROM_START (cx7m)
3349   ROM_REGION (0x28000, "maincpu", 0)
3350   ROM_LOAD ("cx7mbios.rom",  0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
3351   ROM_LOAD ("cx7mext.rom",   0x8000, 0x4000, CRC(66237ecf) SHA1(5c1f9c7fb655e43d38e5dd1fcc6b942b2ff68b02))
3352   /* 0xc000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3353   ROM_FILL (0xc000, 0x14000, 0)
3354   ROM_LOAD ("sfg05m.rom", 0x20000, 0x8000, CRC(6c2545c9) SHA1(bc4b242647116f4886bb92e86421f97b1be51938))
3355ROM_END
3356
3357MSX_LAYOUT_INIT (cx7m)
3358   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3359   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
3360   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3361   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3362   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3363   MSX_LAYOUT_SLOT (3, 3, 0, 2, ROM, 0x8000, 0x20000)
3364   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3365MSX_LAYOUT_END
3366
3367/* MSX2 - Yamaha CX7M-128 */
3368
3369ROM_START (cx7m128)
3370   ROM_REGION (0x2c000, "maincpu", 0)
3371   ROM_LOAD ("cx7mbios.rom",  0x0000, 0x8000, CRC(6cdaf3a5) SHA1(6103b39f1e38d1aa2d84b1c3219c44f1abb5436e))
3372   ROM_LOAD ("cx7mext.rom",   0x8000, 0x4000, CRC(66237ecf) SHA1(5c1f9c7fb655e43d38e5dd1fcc6b942b2ff68b02))
3373   /* 0xc000 - 0x1ffff reserved for optional fmpac roms from msx2 parent set */
3374   ROM_FILL (0xc000, 0x14000, 0)
3375   ROM_LOAD ("sfg05m.rom", 0x20000, 0x8000, CRC(6c2545c9) SHA1(bc4b242647116f4886bb92e86421f97b1be51938))
3376   ROM_LOAD ("yrm502.rom", 0x28000, 0x4000, CRC(51f7ddd1) SHA1(2a4b4a4657e3077df8a88f98210b76883d3702b1))
3377ROM_END
3378
3379MSX_LAYOUT_INIT (cx7m128)
3380   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3381   MSX_LAYOUT_SLOT (0, 1, 0, 1, ROM, 0x4000, 0x8000)
3382   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3383   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3384   MSX_LAYOUT_SLOT (3, 1, 1, 1, ROM, 0x4000, 0x28000)
3385   MSX_LAYOUT_SLOT (3, 2, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3386   MSX_LAYOUT_SLOT (3, 3, 0, 2, ROM, 0x8000, 0x20000)
3387   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3388MSX_LAYOUT_END
3389
3390/********************************  MSX 2+ **********************************/
3391
3392/* MSX2+ */
3393
3394ROM_START (msx2p)
3395   ROM_REGION (0x48000, "maincpu",0)
3396   ROM_LOAD ("msx2p.rom", 0x0000, 0x8000, CRC(00870134) SHA1(e2fbd56e42da637609d23ae9df9efd1b4241b18a))
3397   ROM_LOAD ("msx2pext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3398   ROM_LOAD_OPTIONAL ("disk.rom", 0xc000, 0x4000, CRC(b7c58fad) SHA1(bc517b4a248c3a1338c5efc937b0128b6a783808))
3399   ROM_LOAD_OPTIONAL ("fmpac.rom", 0x10000, 0x10000, CRC(0e84505d) SHA1(9d789166e3caf28e4742fe933d962e99618c633d))
3400   ROM_LOAD ("msx2pkdr.rom", 0x20000, 0x8000, CRC(a068cba9) SHA1(1ef3956f7f918873fb9b031339bba45d1e5e5878))
3401   ROM_LOAD ("msx2pkfn.rom", 0x28000, 0x20000, CRC(b244f6cf) SHA1(e0e99cd91e88ce2676445663f832c835d74d6fd4))
3402ROM_END
3403
3404MSX_LAYOUT_INIT (msx2p)
3405   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3406   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3407   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3408   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x20000, 0x0000)   /* 128KB Mapper RAM */
3409   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3410   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3411   MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000)
3412   MSX_LAYOUT_KANJI (0x28000)
3413   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3414MSX_LAYOUT_END
3415
3416/* MSX2+ - Panasonic FS-A1FX */
3417
3418ROM_START (fsa1fx)
3419   ROM_REGION (0x50000, "maincpu",0)
3420   ROM_LOAD ("a1fxbios.rom", 0x0000, 0x8000, CRC(19771608) SHA1(e90f80a61d94c617850c415e12ad70ac41e66bb7))
3421   ROM_LOAD ("a1fxext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3422   ROM_LOAD ("a1fxdisk.rom", 0xc000, 0x4000, CRC(2bda0184) SHA1(2a0d228afde36ac7c5d3c2aac9c7c664dd071a8c))
3423   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2p parent set */
3424   ROM_FILL (0x10000, 0x10000, 0)
3425   ROM_LOAD ("a1fxkdr.rom", 0x20000, 0x8000, CRC(a068cba9) SHA1(1ef3956f7f918873fb9b031339bba45d1e5e5878))
3426   ROM_LOAD ("a1fxcock.rom", 0x28000, 0x8000, CRC(f662e6eb) SHA1(9d67fab55b85f4ac4f5924323a70020eb8589057))
3427   ROM_LOAD ("a1fxkfn.rom", 0x30000, 0x20000, CRC(b244f6cf) SHA1(e0e99cd91e88ce2676445663f832c835d74d6fd4))
3428ROM_END
3429
3430MSX_LAYOUT_INIT (fsa1fx)
3431   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3432   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3433   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3434   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3435   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3436   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3437/*  MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000) */ /* FDC Emulation of TC8566AF must be emulated */
3438   MSX_LAYOUT_SLOT (3, 3, 1, 2, ROM, 0x8000, 0x28000)
3439   MSX_LAYOUT_KANJI (0x30000)
3440   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3441MSX_LAYOUT_END
3442
3443/* MSX2+ - Panasonic FS-A1WSX */
3444
3445ROM_START (fsa1wsx)
3446   ROM_REGION (0x270000, "maincpu",0)
3447   ROM_LOAD ("a1wsbios.rom", 0x0000, 0x8000, CRC(358ec547) SHA1(f4433752d3bf876bfefb363c749d4d2e08a218b6))
3448   ROM_LOAD ("a1wsext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3449   ROM_LOAD ("a1wsdisk.rom", 0xc000, 0x4000, CRC(ac7d92b4) SHA1(b7068e2aab02072852ca249596b7550ac632c4c2))
3450   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2p parent set */
3451   ROM_FILL (0x10000, 0x10000, 0)
3452   ROM_LOAD ("a1wskdr.rom", 0x20000, 0x8000, CRC(b4fc574d) SHA1(dcc3a67732aa01c4f2ee8d1ad886444a4dbafe06))
3453   ROM_LOAD ("a1wsmusp.rom", 0x28000, 0x4000, CRC(456e494e) SHA1(6354ccc5c100b1c558c9395fa8c00784d2e9b0a3))
3454   ROM_FILL (0x2c000, 0x4000, 0)
3455   ROM_LOAD ("a1wskfn.rom", 0x30000, 0x40000, CRC(1f6406fb) SHA1(5aff2d9b6efc723bc395b0f96f0adfa83cc54a49))
3456   ROM_LOAD ("a1wsfirm.rom", 0x70000, 0x200000, CRC(e363595d) SHA1(3330d9b6b76e3c4ccb7cf252496ed15d08b95d3f))
3457ROM_END
3458
3459MSX_LAYOUT_INIT (fsa1wsx)
3460   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3461   MSX_LAYOUT_SLOT (0, 2, 1, 1, ROM, 0x4000, 0x28000)
3462   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3463   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3464   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3465   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3466   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3467/*  MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000) */ /* FDC Emulation of TC8566AF must be emulated */
3468/*  MSX_LAYOUT_SLOT (3, 3, 1, 4, PANASONIC08, 0x200000, 0x70000) */ /* Panasonic 08KB Mapper must be emulated */
3469   MSX_LAYOUT_KANJI (0x30000)
3470   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3471MSX_LAYOUT_END
3472
3473/* MSX2+ - Panasonic FS-A1WX */
3474
3475ROM_START (fsa1wx)
3476   ROM_REGION (0x270000, "maincpu",0)
3477   ROM_LOAD ("a1wxbios.rom", 0x0000, 0x8000, CRC(19771608) SHA1(e90f80a61d94c617850c415e12ad70ac41e66bb7))
3478   ROM_LOAD ("a1wxext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3479   ROM_LOAD ("a1wxdisk.rom", 0xc000, 0x4000, CRC(2bda0184) SHA1(2a0d228afde36ac7c5d3c2aac9c7c664dd071a8c))
3480   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2p parent set */
3481   ROM_FILL (0x10000, 0x10000, 0)
3482   ROM_LOAD ("a1wxkdr.rom", 0x20000, 0x8000, CRC(a068cba9) SHA1(1ef3956f7f918873fb9b031339bba45d1e5e5878))
3483   ROM_LOAD ("a1wxmusp.rom", 0x28000, 0x4000, CRC(456e494e) SHA1(6354ccc5c100b1c558c9395fa8c00784d2e9b0a3))
3484   ROM_FILL (0x2c000, 0x4000, 0)
3485   ROM_LOAD ("a1wxkfn.rom", 0x30000, 0x40000, CRC(1f6406fb) SHA1(5aff2d9b6efc723bc395b0f96f0adfa83cc54a49))
3486   ROM_LOAD ("a1wxfirm.rom", 0x70000, 0x200000, CRC(283f3250) SHA1(d37ab4bd2bfddd8c97476cbe7347ae581a6f2972))
3487ROM_END
3488
3489MSX_LAYOUT_INIT (fsa1wx)
3490   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3491   MSX_LAYOUT_SLOT (0, 2, 1, 1, ROM, 0x4000, 0x28000)
3492   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3493   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3494   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3495   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3496   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3497/*  MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000) */ /* FDC Emulation of TC8566AF must be emulated */
3498/*  MSX_LAYOUT_SLOT (3, 3, 1, 4, PANASONIC08, 0x200000, 0x70000) */ /* Panasonic 08KB Mapper must be emulated */
3499   MSX_LAYOUT_KANJI (0x30000)
3500   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3501MSX_LAYOUT_END
3502
3503/* MSX2+ - Panasonic FS-A1WX (a) */
3504ROM_START (fsa1wxa)
3505   ROM_REGION (0x270000, "maincpu",0)
3506   ROM_LOAD ("a1wxbios.rom", 0x0000, 0x8000, CRC(19771608) SHA1(e90f80a61d94c617850c415e12ad70ac41e66bb7))
3507   ROM_LOAD ("a1wxext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3508   ROM_LOAD ("a1wxdisk.rom", 0xc000, 0x4000, CRC(2bda0184) SHA1(2a0d228afde36ac7c5d3c2aac9c7c664dd071a8c))
3509   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2p parent set */
3510   ROM_FILL (0x10000, 0x10000, 0)
3511   ROM_LOAD ("a1wxkdr.rom", 0x20000, 0x8000, CRC(a068cba9) SHA1(1ef3956f7f918873fb9b031339bba45d1e5e5878))
3512   ROM_LOAD ("a1wxmusp.rom", 0x28000, 0x4000, CRC(456e494e) SHA1(6354ccc5c100b1c558c9395fa8c00784d2e9b0a3))
3513   ROM_FILL (0x2c000, 0x4000, 0)
3514   ROM_LOAD ("a1wxkfn.rom", 0x30000, 0x40000, CRC(1f6406fb) SHA1(5aff2d9b6efc723bc395b0f96f0adfa83cc54a49))
3515   ROM_LOAD ("a1wxfira.rom", 0x70000, 0x200000, CRC(58440a8e) SHA1(8e0d4a77e7d5736e8225c2df4701509363eb230f))
3516ROM_END
3517
3518MSX_LAYOUT_INIT (fsa1wxa)
3519   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3520   MSX_LAYOUT_SLOT (0, 2, 1, 1, ROM, 0x4000, 0x28000)
3521   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3522   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3523   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3524   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3525   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3526/*  MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000) */ /* FDC Emulation of TC8566AF must be emulated */
3527/*  MSX_LAYOUT_SLOT (3, 3, 1, 4, PANASONIC08, 0x200000, 0x70000) */ /* Panasonic 08KB Mapper must be emulated */
3528   MSX_LAYOUT_KANJI (0x30000)
3529   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3530MSX_LAYOUT_END
3531
3532/* MSX2+ - Sanyo Wavy PHC-35J */
3533
3534ROM_START (phc35j)
3535   ROM_REGION (0x48000, "maincpu",0)
3536   ROM_LOAD ("35jbios.rom", 0x0000, 0x8000, CRC(358ec547) SHA1(f4433752d3bf876bfefb363c749d4d2e08a218b6))
3537   ROM_LOAD ("35jext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3538   /* 0x0c000 - 0x1ffff reserved for optional disk and fmpac roms from msx2p parent set */
3539   ROM_FILL (0xc000, 0x14000, 0)
3540   ROM_LOAD ("35jkdr.rom", 0x20000, 0x8000, CRC(b4fc574d) SHA1(dcc3a67732aa01c4f2ee8d1ad886444a4dbafe06))
3541   ROM_LOAD ("35jkfn.rom", 0x28000, 0x20000, CRC(c9651b32) SHA1(84a645becec0a25d3ab7a909cde1b242699a8662))
3542ROM_END
3543
3544MSX_LAYOUT_INIT (phc35j)
3545   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3546   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3547   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3548   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3549   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3550   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3551   MSX_LAYOUT_KANJI (0x28000)
3552   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3553MSX_LAYOUT_END
3554
3555/* MSX2+ - Sanyo Wavy PHC-70FD1 */
3556
3557ROM_START (phc70fd)
3558   ROM_REGION (0x50000, "maincpu",0)
3559   ROM_LOAD ("70fdbios.rom", 0x0000, 0x8000, CRC(19771608) SHA1(e90f80a61d94c617850c415e12ad70ac41e66bb7))
3560   ROM_LOAD ("70fdext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3561   ROM_LOAD ("70fddisk.rom", 0xc000, 0x4000, CRC(db7f1125) SHA1(9efa744be8355675e7bfdd3976bbbfaf85d62e1d))
3562   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2p parent set */
3563   ROM_FILL (0x10000, 0x10000, 0)
3564   ROM_LOAD ("70fdkdr.rom", 0x20000, 0x8000, CRC(a068cba9) SHA1(1ef3956f7f918873fb9b031339bba45d1e5e5878))
3565   ROM_LOAD ("70fdmus.rom", 0x28000, 0x4000, CRC(5c32eb29) SHA1(aad42ba4289b33d8eed225d42cea930b7fc5c228))
3566   ROM_LOAD ("70fdbas.rom", 0x2c000, 0x4000, CRC(da7be246) SHA1(22b3191d865010264001b9d896186a9818478a6b))
3567   ROM_LOAD ("70fdkfn.rom", 0x30000, 0x20000, CRC(c9651b32) SHA1(84a645becec0a25d3ab7a909cde1b242699a8662))
3568ROM_END
3569
3570MSX_LAYOUT_INIT (phc70fd)
3571   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3572   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3573   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3574   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3575   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3576   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3577/*  MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000) */ /* FDC Emulation of TC8566AF must be emulated */
3578   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x4000, 0x28000)
3579   MSX_LAYOUT_SLOT (3, 3, 2, 1, ROM, 0x4000, 0x2c000)
3580   MSX_LAYOUT_KANJI (0x30000)
3581   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3582MSX_LAYOUT_END
3583
3584/* MSX2+ - Sanyo Wavy PHC-70FD2 */
3585ROM_START (phc70fd2)
3586   ROM_REGION (0x70000, "maincpu",0)
3587   ROM_LOAD ("70f2bios.rom", 0x0000, 0x8000, CRC(19771608) SHA1(e90f80a61d94c617850c415e12ad70ac41e66bb7))
3588   ROM_LOAD ("70f2ext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3589   ROM_LOAD ("70f2disk.rom", 0xc000, 0x4000, CRC(db7f1125) SHA1(9efa744be8355675e7bfdd3976bbbfaf85d62e1d))
3590   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2p parent set */
3591   ROM_FILL (0x10000, 0x10000, 0)
3592   ROM_LOAD ("70f2kdr.rom", 0x20000, 0x8000, CRC(a068cba9) SHA1(1ef3956f7f918873fb9b031339bba45d1e5e5878))
3593   ROM_LOAD ("70f2mus.rom", 0x28000, 0x4000, CRC(5c32eb29) SHA1(aad42ba4289b33d8eed225d42cea930b7fc5c228))
3594   ROM_LOAD ("70f2bas.rom", 0x2c000, 0x4000, CRC(da7be246) SHA1(22b3191d865010264001b9d896186a9818478a6b))
3595   ROM_LOAD ("70f2kfn.rom", 0x30000, 0x40000, CRC(9a850db9) SHA1(bcdb4dae303dfe5234f372d70a5e0271d3202c36))
3596ROM_END
3597
3598MSX_LAYOUT_INIT (phc70fd2)
3599   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3600   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3601   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3602   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3603   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3604   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3605/*  MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000) */ /* FDC Emulation of TC8566AF must be emulated */
3606   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x4000, 0x28000)
3607   MSX_LAYOUT_SLOT (3, 3, 2, 1, ROM, 0x4000, 0x2c000)
3608   MSX_LAYOUT_KANJI (0x30000)
3609   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3610MSX_LAYOUT_END
3611
3612/* MSX2+ - Sony HB-F1XDJ */
3613
3614ROM_START (hbf1xdj)
3615   ROM_REGION (0x170000, "maincpu",0)
3616   ROM_LOAD ("f1xjbios.rom", 0x0000, 0x8000, CRC(00870134) SHA1(e2fbd56e42da637609d23ae9df9efd1b4241b18a))
3617   ROM_LOAD ("f1xjext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3618   ROM_LOAD ("f1xjdisk.rom", 0xc000, 0x4000, CRC(a21f5266) SHA1(c1bb307a570ab833e3bfcc4a58a4f4e12dc1df0f))
3619   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2p parent set */
3620   ROM_FILL (0x10000, 0x10000, 0)
3621   ROM_LOAD ("f1xjkdr.rom", 0x20000, 0x8000, CRC(a068cba9) SHA1(1ef3956f7f918873fb9b031339bba45d1e5e5878))
3622   ROM_LOAD ("f1xjmus.rom", 0x28000, 0x4000, CRC(5c32eb29) SHA1(aad42ba4289b33d8eed225d42cea930b7fc5c228))
3623   ROM_FILL (0x2c000, 0x4000, 0)
3624   ROM_LOAD ("f1xjkfn.rom", 0x30000, 0x40000, CRC(7016dfd0) SHA1(218d91eb6df2823c924d3774a9f455492a10aecb))
3625   ROM_LOAD ("f1xjfirm.rom", 0x70000, 0x100000, CRC(77be583f) SHA1(ade0c5ba5574f8114d7079050317099b4519e88f))
3626ROM_END
3627
3628MSX_LAYOUT_INIT (hbf1xdj)
3629   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3630/*  MSX_LAYOUT_SLOT (0, 3, 1, 4, SONY08, 0x100000, 0x70000) */ /* Sony 08KB MSX-JE Mapper must be emulated */
3631   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3632   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3633   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3634   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3635   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3636   MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000)
3637   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x4000, 0x28000)
3638   MSX_LAYOUT_KANJI (0x30000)
3639   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3640MSX_LAYOUT_END
3641
3642/* MSX2+ - Sony HB-F1XV */
3643
3644ROM_START (hbf1xv)
3645   ROM_REGION (0x170000, "maincpu",0)
3646   ROM_LOAD ("f1xvbios.rom", 0x0000, 0x8000, CRC(2c7ed27b) SHA1(174c9254f09d99361ff7607630248ff9d7d8d4d6))
3647   ROM_LOAD ("f1xvext.rom", 0x8000, 0x4000, CRC(b8ba44d3) SHA1(fe0254cbfc11405b79e7c86c7769bd6322b04995))
3648   ROM_LOAD ("f1xvdisk.rom", 0xc000, 0x4000, CRC(04e4e533) SHA1(5a4e7dbbfb759109c7d2a3b38bda9c60bf6ffef5))
3649   /* 0x10000 - 0x1ffff reserved for optional fmpac roms from msx2p parent set */
3650   ROM_FILL (0x10000, 0x10000, 0)
3651   ROM_LOAD ("f1xvkdr.rom", 0x20000, 0x8000, CRC(b4fc574d) SHA1(dcc3a67732aa01c4f2ee8d1ad886444a4dbafe06))
3652   ROM_LOAD ("f1xvmus.rom", 0x28000, 0x4000, CRC(5c32eb29) SHA1(aad42ba4289b33d8eed225d42cea930b7fc5c228))
3653   ROM_FILL (0x2c000, 0x4000, 0)
3654   ROM_LOAD ("f1xvkfn.rom", 0x30000, 0x40000, CRC(7016dfd0) SHA1(218d91eb6df2823c924d3774a9f455492a10aecb))
3655   ROM_LOAD ("f1xvfirm.rom", 0x70000, 0x100000, CRC(77be583f) SHA1(ade0c5ba5574f8114d7079050317099b4519e88f))
3656ROM_END
3657
3658MSX_LAYOUT_INIT (hbf1xv)
3659   MSX_LAYOUT_SLOT (0, 0, 0, 2, ROM, 0x8000, 0x0000)
3660/*  MSX_LAYOUT_SLOT (0, 3, 1, 4, SONY08, 0x100000, 0x70000) */ /* Sony 08KB MSX-JE Mapper must be emulated */
3661   MSX_LAYOUT_SLOT (1, 0, 0, 4, CARTRIDGE1, 0x0000, 0x0000)
3662   MSX_LAYOUT_SLOT (2, 0, 0, 4, CARTRIDGE2, 0x0000, 0x0000)
3663   MSX_LAYOUT_SLOT (3, 0, 0, 4, RAM_MM, 0x10000, 0x0000)   /* 64KB Mapper RAM */
3664   MSX_LAYOUT_SLOT (3, 1, 0, 1, ROM, 0x4000, 0x8000)
3665   MSX_LAYOUT_SLOT (3, 1, 1, 2, ROM, 0x8000, 0x20000)
3666   MSX_LAYOUT_SLOT (3, 2, 1, 2, DISK_ROM, 0x4000, 0xc000)
3667   MSX_LAYOUT_SLOT (3, 3, 1, 1, ROM, 0x4000, 0x28000)
3668   MSX_LAYOUT_KANJI (0x30000)
3669   MSX_LAYOUT_RAMIO_SET_BITS (0x80)
3670MSX_LAYOUT_END
3671
3672MSX_DRIVER_LIST
3673  /* MSX 1 */
3674   MSX_DRIVER (msx)
3675  MSX_DRIVER (ax170)
3676   MSX_DRIVER (canonv10)
3677   MSX_DRIVER (canonv20)
3678   MSX_DRIVER (dpc100)
3679   MSX_DRIVER (dpc180)
3680   MSX_DRIVER (dpc200)
3681   MSX_DRIVER (gsfc200)
3682   MSX_DRIVER (expert10)
3683   MSX_DRIVER (expert11)
3684   MSX_DRIVER (expert13)
3685   MSX_DRIVER (expert20)
3686   MSX_DRIVER (expertdp)
3687   MSX_DRIVER (expertpl)
3688   MSX_DRIVER (jvchc7gb)
3689   MSX_DRIVER (mlf80)
3690   MSX_DRIVER (mlfx1)
3691   MSX_DRIVER (cf1200)
3692   MSX_DRIVER (cf2000)
3693   MSX_DRIVER (cf2700)
3694   MSX_DRIVER (cf3000)
3695   MSX_DRIVER (cf3300)
3696   MSX_DRIVER (fs1300)
3697   MSX_DRIVER (fs4000)
3698   MSX_DRIVER (nms801)
3699   MSX_DRIVER (vg802000)
3700   MSX_DRIVER (vg802020)
3701   MSX_DRIVER (piopx7)
3702   MSX_DRIVER (mpc100)
3703   MSX_DRIVER (hotbit11)
3704   MSX_DRIVER (hotbit12)
3705   MSX_DRIVER (hotbi13b)
3706   MSX_DRIVER (hotbi13p)
3707   MSX_DRIVER (hotbit20)
3708   MSX_DRIVER (hb10p)
3709   MSX_DRIVER (hb20p)
3710   MSX_DRIVER (hb201)
3711   MSX_DRIVER (hb201p)
3712   MSX_DRIVER (hb501p)
3713   MSX_DRIVER (hb55d)
3714   MSX_DRIVER (hb55p)
3715   MSX_DRIVER (hb75d)
3716   MSX_DRIVER (hb75p)
3717   MSX_DRIVER (svi728)
3718   MSX_DRIVER (svi738)
3719   MSX_DRIVER (svi738sw)
3720   MSX_DRIVER (tadpc200)
3721   MSX_DRIVER (tadpc20a)
3722   MSX_DRIVER (hx10)
3723   MSX_DRIVER (hx10s)
3724   MSX_DRIVER (hx20)
3725   MSX_DRIVER (cx5m)
3726   MSX_DRIVER (cx5m128)
3727   MSX_DRIVER (cx5m2)
3728   MSX_DRIVER (yis303)
3729   MSX_DRIVER (yis503)
3730   MSX_DRIVER (yis503ii)
3731   MSX_DRIVER (y503iir)
3732   MSX_DRIVER (y503iir2)
3733   MSX_DRIVER (yis503m)
3734   MSX_DRIVER (yc64)
3735   MSX_DRIVER (bruc100)
3736
3737
3738
3739   MSX_DRIVER (msx2)
3740   MSX_DRIVER (ax350)
3741   MSX_DRIVER (ax370)
3742   MSX_DRIVER (nms8220)
3743   MSX_DRIVER (nms8220a)
3744   MSX_DRIVER (vg8230)
3745   MSX_DRIVER (vg8235)
3746   MSX_DRIVER (vg8235f)
3747   MSX_DRIVER (vg8240)
3748   MSX_DRIVER (nms8245)
3749   MSX_DRIVER (nms8245f)
3750   MSX_DRIVER (nms8250)
3751   MSX_DRIVER (nms8255)
3752   MSX_DRIVER (nms8280)
3753   MSX_DRIVER (nms8280g)
3754   MSX_DRIVER (hbf9p)
3755   MSX_DRIVER (hbf9s)
3756   MSX_DRIVER (hbf500p)
3757   MSX_DRIVER (hbf700d)
3758   MSX_DRIVER (hbf700f)
3759   MSX_DRIVER (hbf700p)
3760   MSX_DRIVER (hbf700s)
3761   MSX_DRIVER (hbg900ap)
3762   MSX_DRIVER (hbg900p)
3763   MSX_DRIVER (fs5500)
3764   MSX_DRIVER (fs4500)
3765   MSX_DRIVER (fs4700)
3766   MSX_DRIVER (fs5000)
3767   MSX_DRIVER (fs4600)
3768   MSX_DRIVER (fsa1)
3769   MSX_DRIVER (fsa1a)
3770   MSX_DRIVER (fsa1mk2)
3771   MSX_DRIVER (fsa1f)
3772   MSX_DRIVER (fsa1fm)
3773   MSX_DRIVER (hbf500)
3774   MSX_DRIVER (hbf900)
3775   MSX_DRIVER (hbf900a)
3776   MSX_DRIVER (hbf1)
3777   MSX_DRIVER (hbf12)
3778   MSX_DRIVER (hbf1xd)
3779   MSX_DRIVER (hbf1xdm2)
3780   MSX_DRIVER (phc23)
3781   MSX_DRIVER (cpc300)
3782   MSX_DRIVER (cpc300e)
3783   MSX_DRIVER (cpc400)
3784   MSX_DRIVER (cpc400s)
3785   MSX_DRIVER (msx2p)
3786   MSX_DRIVER (fsa1fx)
3787   MSX_DRIVER (fsa1wx)
3788   MSX_DRIVER (fsa1wxa)
3789   MSX_DRIVER (fsa1wsx)
3790   MSX_DRIVER (hbf1xdj)
3791   MSX_DRIVER (hbf1xv)
3792   MSX_DRIVER (phc70fd)
3793   MSX_DRIVER (phc70fd2)
3794   MSX_DRIVER (phc35j)
3795
3796   MSX_DRIVER (tpc310)
3797   MSX_DRIVER (hx23)
3798   MSX_DRIVER (hx23f)
3799   MSX_DRIVER (cx7m)
3800   MSX_DRIVER (cx7m128)
3801
3802MSX_DRIVER_END
3803
3804
3805/*    YEAR  NAME      PARENT    COMPAT  MACHINE  INPUT     INIT   COMPANY              FULLNAME */
3806COMP(1983, msx,        0,      0,   msx_pal,  msx,       msx,      "ASCII & Microsoft", "MSX" , 0)
3807
3808COMP(1983, ax170,   msx,   0,   msx_pal,  msx,      msx,     "Al Alamiah", "AX-170" , 0)
3809COMP(1983, canonv10,  msx,   0,   msx_pal,  msx,      msx,     "Canon", "V-10" , 0)
3810COMP(1983, canonv20,  msx,   0,   msx_pal,  msx,      msx,     "Canon", "V-20" , 0)
3811COMP(1984, dpc100,   msx,   0,   msx,     msxkr,    msx,     "Daewoo", "IQ-1000 DPC-100 (Korea)" , 0)
3812COMP(1984, dpc180,   msx,   0,   msx,     msxkr,    msx,     "Daewoo", "IQ-1000 DPC-180 (Korea)" , 0)
3813COMP(1984, dpc200,   msx,   0,   msx,     msxkr,    msx,     "Daewoo", "IQ-1000 DPC-200 (Korea)" , 0)
3814COMP(1983, gsfc200,   msx,   0,   msx_pal,  msx,      msx,     "Goldstar", "FC-200" , 0)
3815COMP(1983, expert10, msx,   0,   msx,     expert10, msx,     "Gradiente", "Expert 1.0 (Brazil)" , 0)
3816COMP(1984, expert11, msx,   0,   msx,     expert11, msx,     "Gradiente", "Expert 1.1 (Brazil)" , 0)
3817COMP(1984, expert13, msx,   0,   msx,     expert11, msx,     "Gradiente", "Expert 1.3 (Brazil)" , 0)
3818COMP(1985, expertdp, msx,   0,   msx,     expert11, msx,     "Gradiente", "Expert DDPlus (Brazil)", 0 )
3819COMP(1984, expertpl, msx,   0,   msx,     expert11, msx,     "Gradiente", "Expert Plus (Brazil)" , 0)
3820COMP(1983, jvchc7gb,  msx,   0,   msx_pal,  msx,      msx,     "JVC", "HC-7GB" , 0)
3821COMP(1983, mlf80,     msx,   0,   msx_pal,  msx,      msx,     "Mitsubishi", "ML-F80" , 0)
3822COMP(1983, mlfx1,     msx,   0,   msx_pal,  msx,      msx,     "Mitsubishi", "ML-FX1" , 0)
3823COMP(1984, cf1200,   msx,   0,  msx,      msxjp,    msx,     "National / Matsushita", "CF-1200 (Japan)" , 0)
3824COMP(1983, cf2000,   msx,   0,  msx,      msxjp,    msx,     "National / Matsushita", "CF-2000 (Japan)" , 0)
3825COMP(1984, cf2700,   msx,   0,  msx,      msxjp,    msx,     "National / Matsushita", "CF-2700 (Japan)" , 0)
3826COMP(1984, cf3000,   msx,   0,  msx,      msxjp,    msx,     "National / Matsushita", "CF-3000 (Japan)" , 0)
3827COMP(1985, cf3300,   msx,   0,  msx,      msxjp,    msx,     "National / Matsushita", "CF-3300 (Japan)", 0 )
3828COMP(1985, fs1300,   msx,   0,  msx,      msxjp,    msx,     "National / Matsushita", "FS-1300 (Japan)" , 0)
3829COMP(1985, fs4000,   msx,   0,  msx,      msxjp,    msx,     "National / Matsushita", "FS-4000 (Japan)" , 0)
3830COMP(1983, nms801,     msx,   0,   msx_pal,  msx,      msx,     "Philips", "NMS-801" , 0)
3831COMP(1984, vg8000,  msx,   0,   msx,     msx,      msx,     "Philips",    "VG-8000" , GAME_NOT_WORKING)
3832COMP(1984, vg8010,  msx,   0,   msx,     msx,      msx,     "Philips",    "VG-8010" , GAME_NOT_WORKING)
3833COMP(1984, vg8010f,  msx,   0,   msx,     msx,      msx,     "Philips",    "VG-8010F" , GAME_NOT_WORKING)
3834COMP(1985, vg802000,  msx,   0,   msx,     msx,      msx,     "Philips",    "VG-8020-00" , 0)
3835COMP(1985, vg802020, msx,   0,   msx,     msx,      msx,     "Philips",    "VG-8020-20" , 0)
3836COMP(1985, piopx7,     msx,   0,   msx_pal,  msx,      msx,     "Pioneer",    "PX-07" , 0)
3837COMP(1985, mpc100,     msx,   0,   msx_pal,  msx,      msx,     "Sanyo",    "MPC-100" , 0)
3838COMP(1985, hotbit11, msx,   0,   msx,     hotbit,   msx,     "Sharp / Epcom",    "HB-8000 Hotbit 1.1" , 0)
3839COMP(1985, hotbit12, msx,   0,   msx,     hotbit,   msx,     "Sharp / Epcom",    "HB-8000 Hotbit 1.2" , 0)
3840COMP(1985, hotbi13b, msx,   0,   msx,     hotbit,   msx,     "Sharp / Epcom",    "HB-8000 Hotbit 1.3b" , 0)
3841COMP(1985, hotbi13p, msx,   0,   msx,     hotbit,   msx,     "Sharp / Epcom",    "HB-8000 Hotbit 1.3p" , 0)
3842COMP(1985, hb10p,    msx,   0,  msx_pal,  msx,     msx,     "Sony", "HB-10P" , 0)
3843COMP(1985, hb20p,    msx,   0,  msx_pal,  msx,     msx,     "Sony", "HB-20P (Spanish)" , 0)
3844COMP(1985, hb201,    msx,   0,  msx,      msxjp,    msx,     "Sony", "HB-201 (Japan)" , 0)
3845COMP(1985, hb201p,   msx,   0,   msx_pal,  msx,      msx,     "Sony", "HB-201P" , 0)
3846COMP(1984, hb501p,   msx,   0,   msx_pal,  msx,      msx,     "Sony", "HB-501P" , 0)
3847COMP(1983, hb55d,    msx,   0,   msx_pal,  msx,      msx,     "Sony", "HB-55D (Germany)" , 0)
3848COMP(1983, hb55p,    msx,   0,   msx_pal,  msx,      msx,     "Sony", "HB-55P" , 0)
3849COMP(1983, hb75d,    msx,   0,   msx_pal,  msx,      msx,     "Sony", "HB-75D (Germany)" , 0)
3850COMP(1983, hb75p,    msx,   0,   msx_pal,  msx,      msx,     "Sony", "HB-75P" , 0)
3851COMP(1985, svi728,   msx,   0,   msx_pal,  msx,      msx,     "Spectravideo", "SVI-728", 0 )
3852COMP(1985, svi738,   msx,   0,   msx_pal,  msx,      msx,     "Spectravideo", "SVI-738", 0 )
3853COMP(1985, svi738sw, msx,   0,   msx_pal,  msx,      msx,     "Spectravideo", "SVI-738 (Swedish)", 0 )
3854COMP(1983, tadpc200,  msx,   0,   msx_pal,  msx,      msx,     "Talent", "DPC-200" , 0)
3855COMP(1983, tadpc20a,  msx,   0,   msx_pal,  msx,      msx,     "Talent", "DPC-200A" , 0)
3856COMP(1984, hx10,     msx,   0,   msx_pal,  msx,      msx,     "Toshiba",    "HX-10" , 0)
3857COMP(1984, hx10s,     msx,   0,   msx_pal,  msx,      msx,     "Toshiba",    "HX-10S" , 0)
3858COMP(1984, hx20,     msx,   0,   msx_pal,  msx,      msx,     "Toshiba",    "HX-20" , 0)
3859COMP(1984, cx5m,     msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "CX5M" , GAME_NOT_WORKING)
3860COMP(1984, cx5m128,  msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "CX5M-128" , GAME_NOT_WORKING)
3861COMP(1984, cx5m2,   msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "CX5MII" , GAME_NOT_WORKING)
3862COMP(1984, yis303,  msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "YIS303" , 0)
3863COMP(1984, yis503,   msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "YIS503" , 0)
3864COMP(1984, yis503ii,msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "YIS503II" , 0)
3865COMP(1986, y503iir, msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "YIS503IIR (Russian)" , 0)
3866COMP(1986, y503iir2, msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "YIS503IIR (Estonian)" , 0)
3867COMP(1984, yis503m, msx,   0,   msx_pal,  msx,      msx,     "Yamaha",    "YIS503M" , GAME_NOT_WORKING)
3868COMP(1984, yc64,   msx,   0,   msx_pal,  msx,      msx,     "Yashica", "YC-64" , 0)
3869COMP(1984, bruc100, msx,   0,   msx_pal,  msx,      msx,     "Frael", "Bruc 100-1" , 0)
3870
3871COMP(1985, msx2,     0,      msx,msx2_pal, msx2,       msx,     "ASCII & Microsoft", "MSX2", 0)
3872COMP(1986, ax350,    msx2,   0,   msx2_pal, msx2,       msx,     "Al Alamiah", "AX-350", 0)
3873COMP(1986, ax370,    msx2,   0,   msx2_pal, msx2,       msx,     "Al Alamiah", "AX-370", 0)
3874COMP(1986, expert20, msx2,   0,   msx2_pal, msx2,    msx,     "Gradiente", "Expert 2.0 (Brazil)" , GAME_NOT_WORKING)
3875COMP(1986, nms8220,  msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "NMS-8220 (12-jun-1986)", 0)
3876COMP(1986, nms8220a, msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "NMS-8220 (13-aug-1986)", 0)
3877COMP(1986, vg8230,   msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "VG-8230", 0)
3878COMP(1986, vg8235,   msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "VG-8235", 0)
3879COMP(1986, vg8235f,  msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "VG-8235F", 0)
3880COMP(1986, vg8240,   msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "VG-8240", 0)
3881COMP(1986, nms8245,  msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "NMS-8245", 0)
3882COMP(1986, nms8245f, msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "NMS-8245F", 0)
3883COMP(1986, nms8250,  msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "NMS-8250", 0)
3884COMP(1986, nms8255,  msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "NMS-8255", 0)
3885COMP(1986, nms8280,  msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "NMS-8280", 0)
3886COMP(1986, nms8280g, msx2,   0,   msx2_pal, msx2,       msx,     "Philips", "NMS-8280G", 0)
3887COMP(1985, hbf9p,    msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-F9P" , 0)
3888COMP(1985, hbf9s,    msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-F9S" , 0)
3889COMP(1985, hbf500p,  msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-F500P", 0)
3890COMP(1985, hbf700d,  msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-F700D (Germany)" , 0)
3891COMP(1985, hbf700f,  msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-F700F" , 0)
3892COMP(1985, hbf700p,  msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-F700P" , 0)
3893COMP(1985, hbf700s,  msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-F700S (Spain)", 0)
3894COMP(1986, hbg900ap, msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-G900AP", 0 )
3895COMP(1986, hbg900p,  msx2,   0,   msx2_pal, msx2,       msx,     "Sony", "HB-G900P", 0 )
3896COMP(1986, hotbit20, msx2,   0,   msx2_pal, msx2,    msx,     "Sharp / Epcom",    "HB-8000 Hotbit 2.0" , GAME_NOT_WORKING)
3897COMP(1986, tpc310,   msx2,   0,  msx2_pal, msx2,     msx,     "Talent", "TPC-310", 0)
3898COMP(1986, hx23,     msx2,   0,  msx2_pal, msx2,     msx,     "Toshiba", "HX-23", 0)
3899COMP(1986, hx23f,    msx2,   0,  msx2_pal, msx2,     msx,     "Toshiba", "HX-23F", 0)
3900COMP(1986, cx7m,     msx2,   0,   msx2_pal,msx2,      msx,     "Yamaha",    "CX7M" , GAME_NOT_WORKING)
3901COMP(1986, cx7m128,  msx2,   0,   msx2_pal,msx2,      msx,     "Yamaha",    "CX7M-128" , GAME_NOT_WORKING)
3902COMP(1985, fs5500,   msx2,   0,  msx2,     msx2jp,   msx,     "National / Matsushita", "FS-5500F1/F2 (Japan)", 0 )
3903COMP(1986, fs4500,   msx2,   0,  msx2,     msx2jp,   msx,     "National / Matsushita", "FS-4500 (Japan)", 0 )
3904COMP(1986, fs4700,   msx2,   0,  msx2,     msx2jp,   msx,     "National / Matsushita", "FS-4700 (Japan)", 0 )
3905COMP(1986, fs5000,   msx2,   0,  msx2,     msx2jp,   msx,     "National / Matsushita", "FS-5000F2 (Japan)", 0 )
3906COMP(1986, fs4600,   msx2,   0,  msx2,     msx2jp,   msx,     "National / Matsushita", "FS-4600 (Japan)", 0 )
3907COMP(1986, fsa1,     msx2,   0,  msx2,     msx2jp,   msx,     "Panasonic / Matsushita", "FS-A1 / 1st released version (Japan)", 0)
3908COMP(1986, fsa1a,    msx2,   0,  msx2,     msx2jp,   msx,     "Panasonic / Matsushita", "FS-A1 / 2nd released version (Japan)", 0)
3909COMP(1987, fsa1mk2,  msx2,   0,  msx2,     msx2jp,   msx,     "Panasonic / Matsushita", "FS-A1MK2 (Japan)", 0)
3910COMP(1987, fsa1f,    msx2,   0,  msx2,     msx2jp,   msx,     "Panasonic / Matsushita", "FS-A1F (Japan)", 0 )
3911COMP(1987, fsa1fm,   msx2,   0,  msx2,     msx2jp,   msx,     "Panasonic / Matsushita", "FS-A1FM (Japan)", 0 )
3912COMP(1986, hbf500,   msx2,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F500 (Japan)", 0)
3913COMP(1986, hbf900,   msx2,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F900 / 1st released version (Japan)", 0)
3914COMP(1986, hbf900a,  msx2,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F900 / 2nd released version (Japan)", 0)
3915COMP(1986, hbf1,     msx2,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F1 (Japan)", GAME_NOT_WORKING )
3916COMP(1987, hbf12,    msx2,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F1II (Japan)", GAME_NOT_WORKING )
3917COMP(1987, hbf1xd,   msx2,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F1XD (Japan)", 0)
3918COMP(1988, hbf1xdm2, msx2,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F1XDMK2 (Japan)", 0)
3919COMP(1988, phc23,    msx2,   0,  msx2,     msx2jp,   msx,     "Sanyo", "WAVY PHC-23 (Japan)", 0)
3920
3921COMP(1986, cpc300,   msx2,   0,   msx2,     msx2kr,   msx,     "Daewoo", "IQ-2000 CPC-300 (Korea)", 0)
3922COMP(1986, cpc300e,  msx2,   0,   msx2,     msx2kr,   msx,     "Daewoo", "IQ-2000 CPC-300E (Korea)", 0)
3923COMP(1986, cpc400,   msx2,   0,   msx2,     msx2kr,   msx,     "Daewoo", "X-II CPC-400 (Korea)", 0 )
3924COMP(1986, cpc400s,  msx2,   0,   msx2,     msx2kr,   msx,     "Daewoo", "X-II CPC-400S (Korea)", 0 )
3925COMP(1988, msx2p,    0,      msx,msx2,     msx2jp,   msx,     "ASCII & Microsoft", "MSX2+", 0)
3926COMP(1988, fsa1fx,   msx2p,   0,  msx2,     msx2jp,   msx,     "Panasonic / Matsushita", "FS-A1FX (Japan)", 0 )
3927COMP(1988, fsa1wx,   msx2p,   0,  msx2,     msx2jp,   msx,     "Panasonic / Matsushita", "FS-A1WX / 1st released version (Japan)", 0 )
3928COMP(1988, fsa1wxa,  msx2p,   0,  msx2,     msx2jp,   msx,    "Panasonic / Matsushita", "FS-A1WX / 2nd released version (Japan)", 0 )
3929COMP(1989, fsa1wsx,  msx2p,   0,  msx2,     msx2jp,   msx,     "Panasonic / Matsushita", "FS-A1WSX (Japan)", 0 )
3930COMP(1988, hbf1xdj,  msx2p,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F1XDJ (Japan)", 0 )
3931COMP(1989, hbf1xv,   msx2p,   0,  msx2,     msx2jp,   msx,     "Sony", "HB-F1XV (Japan)", 0 )
3932COMP(1988, phc70fd,  msx2p,   0,  msx2,     msx2jp,   msx,     "Sanyo", "WAVY PHC-70FD (Japan)", 0 )
3933COMP(1988, phc70fd2, msx2p,   0,  msx2,     msx2jp,   msx,     "Sanyo", "WAVY PHC-70FD2 (Japan)", 0 )
3934COMP(1989, phc35j,   msx2p,   0,  msx2,     msx2jp,   msx,     "Sanyo", "WAVY PHC-35J (Japan)", 0)
3935
src/mess/drivers/n64.c
r11460r11461
1/*
2    Nintendo 64
3
4    Driver by Ville Linde
5    Reformatted to share hardware by R. Belmont
6    Additional work by Ryan Holtz
7    Porting from Mupen64 by Harmony
8*/
9
10#include "emu.h"
11#include "cpu/rsp/rsp.h"
12#include "cpu/mips/mips3.h"
13#include "sound/dmadac.h"
14#include "imagedev/cartslot.h"
15#include "includes/n64.h"
16
17
18static ADDRESS_MAP_START( n64_map, AS_PROGRAM, 32 )
19   AM_RANGE(0x00000000, 0x007fffff) AM_RAM   AM_BASE(&rdram)            // RDRAM
20   AM_RANGE(0x03f00000, 0x03f00027) AM_READWRITE(n64_rdram_reg_r, n64_rdram_reg_w)
21   AM_RANGE(0x04000000, 0x04000fff) AM_RAM AM_SHARE("dmem")               // RSP DMEM
22   AM_RANGE(0x04001000, 0x04001fff) AM_RAM AM_SHARE("imem")               // RSP IMEM
23   AM_RANGE(0x04040000, 0x040fffff) AM_DEVREADWRITE("rsp", n64_sp_reg_r, n64_sp_reg_w)   // RSP
24   AM_RANGE(0x04100000, 0x041fffff) AM_DEVREADWRITE("rsp", n64_dp_reg_r, n64_dp_reg_w)   // RDP
25   AM_RANGE(0x04300000, 0x043fffff) AM_READWRITE(n64_mi_reg_r, n64_mi_reg_w)   // MIPS Interface
26   AM_RANGE(0x04400000, 0x044fffff) AM_READWRITE(n64_vi_reg_r, n64_vi_reg_w)   // Video Interface
27   AM_RANGE(0x04500000, 0x045fffff) AM_READWRITE(n64_ai_reg_r, n64_ai_reg_w)   // Audio Interface
28   AM_RANGE(0x04600000, 0x046fffff) AM_READWRITE(n64_pi_reg_r, n64_pi_reg_w)   // Peripheral Interface
29   AM_RANGE(0x04700000, 0x047fffff) AM_READWRITE(n64_ri_reg_r, n64_ri_reg_w)   // RDRAM Interface
30   AM_RANGE(0x04800000, 0x048fffff) AM_READWRITE(n64_si_reg_r, n64_si_reg_w)   // Serial Interface
31   //AM_RANGE(0x08000000, 0x08007fff) AM_RAM                                   // Cartridge SRAM
32   AM_RANGE(0x10000000, 0x13ffffff) AM_ROM AM_REGION("user2", 0)   // Cartridge
33   AM_RANGE(0x1fc00000, 0x1fc007bf) AM_ROM AM_REGION("user1", 0)   // PIF ROM
34   AM_RANGE(0x1fc007c0, 0x1fc007ff) AM_READWRITE(n64_pif_ram_r, n64_pif_ram_w)
35ADDRESS_MAP_END
36
37static ADDRESS_MAP_START( rsp_map, AS_PROGRAM, 32 )
38   AM_RANGE(0x00000000, 0x00000fff) AM_RAM AM_SHARE("dmem")
39   AM_RANGE(0x00001000, 0x00001fff) AM_RAM AM_SHARE("imem")
40   AM_RANGE(0x04000000, 0x04000fff) AM_RAM AM_BASE(&rsp_dmem) AM_SHARE("dmem")
41   AM_RANGE(0x04001000, 0x04001fff) AM_RAM AM_BASE(&rsp_imem) AM_SHARE("imem")
42ADDRESS_MAP_END
43
44static INPUT_PORTS_START( n64 )
45   PORT_START("P1")
46   PORT_BIT( 0x8000, IP_ACTIVE_HIGH, IPT_BUTTON1 )        PORT_PLAYER(1) PORT_NAME("P1 Button A")
47   PORT_BIT( 0x4000, IP_ACTIVE_HIGH, IPT_BUTTON2 )        PORT_PLAYER(1) PORT_NAME("P1 Button B")
48   PORT_BIT( 0x2000, IP_ACTIVE_HIGH, IPT_BUTTON3 )        PORT_PLAYER(1) PORT_NAME("P1 Button Z")
49   PORT_BIT( 0x1000, IP_ACTIVE_HIGH, IPT_START )          PORT_PLAYER(1) PORT_NAME("P1 Start")
50   PORT_BIT( 0x0800, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP )    PORT_PLAYER(1) PORT_NAME("P1 Joypad \xE2\x86\x91") /* Up */
51   PORT_BIT( 0x0400, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN )  PORT_PLAYER(1) PORT_NAME("P1 Joypad \xE2\x86\x93") /* Down */
52   PORT_BIT( 0x0200, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT )  PORT_PLAYER(1) PORT_NAME("P1 Joypad \xE2\x86\x90") /* Left */
53   PORT_BIT( 0x0100, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) PORT_NAME("P1 Joypad \xE2\x86\x92") /* Right */
54   PORT_BIT( 0x00c0, IP_ACTIVE_HIGH, IPT_UNUSED )
55   PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_BUTTON4 )        PORT_PLAYER(1) PORT_NAME("P1 Button L")
56   PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_BUTTON5 )        PORT_PLAYER(1) PORT_NAME("P1 Button R")
57   PORT_BIT( 0x0008, IP_ACTIVE_HIGH, IPT_BUTTON6 )        PORT_PLAYER(1) PORT_NAME("P1 Button C \xE2\x86\x91") /* Up */
58   PORT_BIT( 0x0004, IP_ACTIVE_HIGH, IPT_BUTTON7 )        PORT_PLAYER(1) PORT_NAME("P1 Button C \xE2\x86\x93") /* Down */
59   PORT_BIT( 0x0002, IP_ACTIVE_HIGH, IPT_BUTTON8 )        PORT_PLAYER(1) PORT_NAME("P1 Button C \xE2\x86\x90") /* Left */
60   PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_BUTTON9 )        PORT_PLAYER(1) PORT_NAME("P1 Button C \xE2\x86\x92") /* Right */
61
62   PORT_START("P1_ANALOG_X")
63   PORT_BIT( 0xff, 0x80, IPT_AD_STICK_X ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(30) PORT_KEYDELTA(30) PORT_PLAYER(1)
64
65   PORT_START("P1_ANALOG_Y")
66   PORT_BIT( 0xff, 0x80, IPT_AD_STICK_Y ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(30) PORT_KEYDELTA(30) PORT_PLAYER(1) PORT_REVERSE
67
68   PORT_START("P2")
69   PORT_BIT( 0x8000, IP_ACTIVE_HIGH, IPT_BUTTON1 )        PORT_PLAYER(2) PORT_NAME("P2 Button A")
70   PORT_BIT( 0x4000, IP_ACTIVE_HIGH, IPT_BUTTON2 )        PORT_PLAYER(2) PORT_NAME("P2 Button B")
71   PORT_BIT( 0x2000, IP_ACTIVE_HIGH, IPT_BUTTON3 )        PORT_PLAYER(2) PORT_NAME("P2 Button Z")
72   PORT_BIT( 0x1000, IP_ACTIVE_HIGH, IPT_START )          PORT_PLAYER(2) PORT_NAME("P2 Start")
73   PORT_BIT( 0x0800, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP )    PORT_PLAYER(2) PORT_NAME("P2 Joypad \xE2\x86\x91") /* Up */
74   PORT_BIT( 0x0400, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN )  PORT_PLAYER(2) PORT_NAME("P2 Joypad \xE2\x86\x93") /* Down */
75   PORT_BIT( 0x0200, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT )  PORT_PLAYER(2) PORT_NAME("P2 Joypad \xE2\x86\x90") /* Left */
76   PORT_BIT( 0x0100, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) PORT_NAME("P2 Joypad \xE2\x86\x92") /* Right */
77   PORT_BIT( 0x00c0, IP_ACTIVE_HIGH, IPT_UNUSED )
78   PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_BUTTON4 )        PORT_PLAYER(2) PORT_NAME("P2 Button L")
79   PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_BUTTON5 )        PORT_PLAYER(2) PORT_NAME("P2 Button R")
80   PORT_BIT( 0x0008, IP_ACTIVE_HIGH, IPT_BUTTON6 )        PORT_PLAYER(2) PORT_NAME("P2 Button C \xE2\x86\x91") /* Up */
81   PORT_BIT( 0x0004, IP_ACTIVE_HIGH, IPT_BUTTON7 )        PORT_PLAYER(2) PORT_NAME("P2 Button C \xE2\x86\x93") /* Down */
82   PORT_BIT( 0x0002, IP_ACTIVE_HIGH, IPT_BUTTON8 )        PORT_PLAYER(2) PORT_NAME("P2 Button C \xE2\x86\x90") /* Left */
83   PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_BUTTON9 )        PORT_PLAYER(2) PORT_NAME("P2 Button C \xE2\x86\x92") /* Right */
84
85   PORT_START("P2_ANALOG_X")
86   PORT_BIT( 0xff, 0x80, IPT_AD_STICK_X ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(30) PORT_KEYDELTA(30) PORT_PLAYER(2)
87
88   PORT_START("P2_ANALOG_Y")
89   PORT_BIT( 0xff, 0x80, IPT_AD_STICK_Y ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(30) PORT_KEYDELTA(30) PORT_PLAYER(2) PORT_REVERSE
90
91INPUT_PORTS_END
92
93/* ?? */
94static const mips3_config config =
95{
96   16384,            /* code cache size */
97   8192,            /* data cache size */
98   62500000         /* system clock */
99};
100
101static INTERRUPT_GEN( n64_vblank )
102{
103   signal_rcp_interrupt(device->machine(), VI_INTERRUPT);
104}
105
106static DEVICE_IMAGE_LOAD(n64_cart)
107{
108   int i, length;
109   UINT8 *cart = image.device().machine().region("user2")->base();
110
111   if (image.software_entry() == NULL)
112   {
113      length = image.fread( cart, 0x4000000);
114   }
115   else
116   {
117      length = image.get_software_region_length("rom");
118      memcpy(cart, image.get_software_region("rom"), length);
119   }
120
121   if (cart[0] == 0x37 && cart[1] == 0x80)
122   {
123      for (i = 0; i < length; i += 4)
124      {
125         UINT8 b1 = cart[i + 0];
126         UINT8 b2 = cart[i + 1];
127         UINT8 b3 = cart[i + 2];
128         UINT8 b4 = cart[i + 3];
129         cart[i + 0] = b3;
130         cart[i + 1] = b4;
131         cart[i + 2] = b1;
132         cart[i + 3] = b2;
133      }
134   }
135   else
136   {
137      for (i = 0; i < length; i += 4)
138      {
139         UINT8 b1 = cart[i + 0];
140         UINT8 b2 = cart[i + 1];
141         UINT8 b3 = cart[i + 2];
142         UINT8 b4 = cart[i + 3];
143         cart[i + 0] = b4;
144         cart[i + 1] = b3;
145         cart[i + 2] = b2;
146         cart[i + 3] = b1;
147      }
148   }
149
150   logerror("cart length = %d\n", length);
151   return IMAGE_INIT_PASS;
152}
153
154static MACHINE_CONFIG_START( n64, _n64_state )
155
156   /* basic machine hardware */
157   MCFG_CPU_ADD("maincpu", VR4300BE, 93750000)
158   MCFG_CPU_CONFIG(config)
159   MCFG_CPU_PROGRAM_MAP(n64_map)
160   MCFG_CPU_VBLANK_INT("screen", n64_vblank)
161
162   MCFG_CPU_ADD("rsp", RSP, 62500000)
163   MCFG_CPU_CONFIG(n64_rsp_config)
164   MCFG_CPU_PROGRAM_MAP(rsp_map)
165
166   MCFG_MACHINE_START( n64 )
167   MCFG_MACHINE_RESET( n64 )
168   MCFG_QUANTUM_TIME(attotime::from_hz(600))
169
170   /* video hardware */
171   MCFG_SCREEN_ADD("screen", RASTER)
172   MCFG_SCREEN_REFRESH_RATE(60)
173   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
174   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
175   MCFG_SCREEN_SIZE(640, 525)
176   MCFG_SCREEN_VISIBLE_AREA(0, 639, 0, 239)
177   MCFG_SCREEN_UPDATE(n64)
178
179   MCFG_PALETTE_LENGTH(0x1000)
180
181   MCFG_VIDEO_START(n64)
182
183   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
184
185   MCFG_SOUND_ADD("dac2", DMADAC, 0)
186   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 1.0)
187   MCFG_SOUND_ADD("dac1", DMADAC, 0)
188   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 1.0)
189
190   /* cartridge */
191   MCFG_CARTSLOT_ADD("cart")
192   MCFG_CARTSLOT_EXTENSION_LIST("v64,z64,rom,n64,bin")
193   MCFG_CARTSLOT_MANDATORY
194   MCFG_CARTSLOT_INTERFACE("n64_cart")
195   MCFG_CARTSLOT_LOAD(n64_cart)
196
197   /* software lists */
198   MCFG_SOFTWARE_LIST_ADD("cart_list","n64")
199MACHINE_CONFIG_END
200
201ROM_START( n64 )
202   ROM_REGION( 0x800000, "maincpu", ROMREGION_ERASEFF )      /* dummy region for R4300 */
203
204   ROM_REGION32_BE( 0x800, "user1", 0 )
205   ROM_LOAD( "pifdata.bin", 0x0000, 0x0800, CRC(5ec82be9) SHA1(9174eadc0f0ea2654c95fd941406ab46b9dc9bdd) )
206
207   ROM_REGION32_BE( 0x4000000, "user2", ROMREGION_ERASEFF)
208
209   ROM_REGION16_BE( 0x80, "normpoint", 0 )
210   ROM_LOAD( "normpnt.rom", 0x00, 0x80, CRC(e7f2a005) SHA1(c27b4a364a24daeee6e99fd286753fd6216362b4) )
211
212   ROM_REGION16_BE( 0x80, "normslope", 0 )
213   ROM_LOAD( "normslp.rom", 0x00, 0x80, CRC(4f2ae525) SHA1(eab43f8cc52c8551d9cff6fced18ef80eaba6f05) )
214ROM_END
215
216CONS(1996, n64,    0,      0,      n64,   n64,   0,   "Nintendo", "Nintendo 64", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
src/mess/drivers/snes.c
r11460r11461
1/***************************************************************************
2
3  snes.c
4
5  Driver file to handle emulation of the Nintendo Super NES.
6
7  R. Belmont
8  Anthony Kruize
9  Angelo Salese
10  Fabio Priuli
11  byuu
12  Based on the original MESS driver by Lee Hammerton (aka Savoury Snax)
13
14  Driver is preliminary right now.
15
16  The memory map included below is setup in a way to make it easier to handle
17  Mode 20 and Mode 21 ROMs.
18
19  Todo (in no particular order):
20    - Fix additional sound bugs
21    - Emulate extra chips - superfx, dsp2, sa-1 etc.
22    - Add horizontal mosaic, hi-res. interlaced etc to video emulation.
23    - Fix support for Mode 7. (In Progress)
24    - Handle interleaved roms (maybe even multi-part roms, but how?)
25    - Add support for running at 3.58 MHz at the appropriate time.
26    - I'm sure there's lots more ...
27
28***************************************************************************/
29
30#include "emu.h"
31#include "audio/snes_snd.h"
32#include "cpu/spc700/spc700.h"
33#include "cpu/superfx/superfx.h"
34#include "cpu/g65816/g65816.h"
35#include "cpu/upd7725/upd7725.h"
36#include "includes/snes.h"
37#include "machine/snescart.h"
38#include "crsshair.h"
39
40#define MAX_SNES_CART_SIZE 0x600000
41
42/*************************************
43 *
44 *  Memory handlers
45 *
46 *************************************/
47
48static READ8_DEVICE_HANDLER( spc_ram_100_r )
49{
50   return spc_ram_r(device, offset + 0x100);
51}
52
53static WRITE8_DEVICE_HANDLER( spc_ram_100_w )
54{
55   spc_ram_w(device, offset + 0x100, data);
56}
57
58/*************************************
59 *
60 *  Address maps
61 *
62 *************************************/
63
64static ADDRESS_MAP_START( snes_map, AS_PROGRAM, 8)
65   AM_RANGE(0x000000, 0x2fffff) AM_READWRITE(snes_r_bank1, snes_w_bank1)   /* I/O and ROM (repeats for each bank) */
66   AM_RANGE(0x300000, 0x3fffff) AM_READWRITE(snes_r_bank2, snes_w_bank2)   /* I/O and ROM (repeats for each bank) */
67   AM_RANGE(0x400000, 0x5fffff) AM_READ(snes_r_bank3)      /* ROM (and reserved in Mode 20) */
68   AM_RANGE(0x600000, 0x6fffff) AM_READWRITE(snes_r_bank4, snes_w_bank4)   /* used by Mode 20 DSP-1 */
69   AM_RANGE(0x700000, 0x7dffff) AM_READWRITE(snes_r_bank5, snes_w_bank5)
70   AM_RANGE(0x7e0000, 0x7fffff) AM_RAM               /* 8KB Low RAM, 24KB High RAM, 96KB Expanded RAM */
71   AM_RANGE(0x800000, 0xbfffff) AM_READWRITE(snes_r_bank6, snes_w_bank6)   /* Mirror and ROM */
72   AM_RANGE(0xc00000, 0xffffff) AM_READWRITE(snes_r_bank7, snes_w_bank7)   /* Mirror and ROM */
73ADDRESS_MAP_END
74
75static ADDRESS_MAP_START( superfx_map, AS_PROGRAM, 8)
76   AM_RANGE(0x000000, 0x3fffff) AM_READWRITE(superfx_r_bank1, superfx_w_bank1)
77   AM_RANGE(0x400000, 0x5fffff) AM_READWRITE(superfx_r_bank2, superfx_w_bank2)
78   AM_RANGE(0x600000, 0x7dffff) AM_READWRITE(superfx_r_bank3, superfx_w_bank3)
79   AM_RANGE(0x800000, 0xbfffff) AM_READWRITE(superfx_r_bank1, superfx_w_bank1)
80   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(superfx_r_bank2, superfx_w_bank2)
81   AM_RANGE(0xe00000, 0xffffff) AM_READWRITE(superfx_r_bank3, superfx_w_bank3)
82ADDRESS_MAP_END
83
84static ADDRESS_MAP_START( spc_map, AS_PROGRAM, 8)
85   AM_RANGE(0x0000, 0x00ef) AM_DEVREADWRITE("spc700", spc_ram_r, spc_ram_w)   /* lower 32k ram */
86   AM_RANGE(0x00f0, 0x00ff) AM_DEVREADWRITE("spc700", spc_io_r, spc_io_w)     /* spc io */
87   AM_RANGE(0x0100, 0xffff) AM_DEVWRITE("spc700", spc_ram_100_w)
88   AM_RANGE(0x0100, 0xffbf) AM_DEVREAD("spc700", spc_ram_100_r)
89   AM_RANGE(0xffc0, 0xffff) AM_DEVREAD("spc700", spc_ipl_r)
90ADDRESS_MAP_END
91
92static ADDRESS_MAP_START( dsp_prg_map, AS_PROGRAM, 32 )
93   AM_RANGE(0x0000, 0x07ff) AM_ROM AM_REGION("dspprg", 0)
94ADDRESS_MAP_END
95
96static ADDRESS_MAP_START( dsp_data_map, AS_DATA, 16 )
97   AM_RANGE(0x0000, 0x03ff) AM_ROM AM_REGION("dspdata", 0)
98ADDRESS_MAP_END
99
100static ADDRESS_MAP_START( setadsp_prg_map, AS_PROGRAM, 32 )
101   AM_RANGE(0x0000, 0x3fff) AM_ROM AM_REGION("dspprg", 0)
102ADDRESS_MAP_END
103
104static ADDRESS_MAP_START( setadsp_data_map, AS_DATA, 16 )
105   AM_RANGE(0x0000, 0x07ff) AM_ROM AM_REGION("dspdata", 0)
106ADDRESS_MAP_END
107
108/*************************************
109 *
110 *  Input ports
111 *
112 *************************************/
113
114static CUSTOM_INPUT( snes_mouse_speed_input )
115{
116   snes_state *state = field->port->machine().driver_data<snes_state>();
117   int port = (FPTR)param;
118
119   if (snes_ram[OLDJOY1] & 0x1)
120   {
121      state->m_mouse[port].speed++;
122      if ((state->m_mouse[port].speed & 0x03) == 0x03)
123         state->m_mouse[port].speed = 0;
124   }
125
126   return state->m_mouse[port].speed;
127}
128
129static CUSTOM_INPUT( snes_superscope_offscreen_input )
130{
131   snes_state *state = field->port->machine().driver_data<snes_state>();
132   int port = (FPTR)param;
133   static const char *const portnames[2][3] =
134         {
135            { "SUPERSCOPE1", "SUPERSCOPE1_X", "SUPERSCOPE1_Y" },
136            { "SUPERSCOPE2", "SUPERSCOPE2_X", "SUPERSCOPE2_Y" },
137         };
138
139   INT16 x = input_port_read(field->port->machine(), portnames[port][1]);
140   INT16 y = input_port_read(field->port->machine(), portnames[port][2]);
141
142   /* these are the theoretical boundaries, but we currently are always onscreen... */
143   if (x < 0 || x >= SNES_SCR_WIDTH || y < 0 || y >= snes_ppu.beam.last_visible_line)
144      state->m_scope[port].offscreen = 1;
145   else
146      state->m_scope[port].offscreen = 0;
147
148   return state->m_scope[port].offscreen;
149}
150
151static TIMER_CALLBACK( lightgun_tick )
152{
153   if ((input_port_read(machine, "CTRLSEL") & 0x0f) == 0x03 || (input_port_read(machine, "CTRLSEL") & 0x0f) == 0x04)
154   {
155      /* enable lightpen crosshair */
156      crosshair_set_screen(machine, 0, CROSSHAIR_SCREEN_ALL);
157   }
158   else
159   {
160      /* disable lightpen crosshair */
161      crosshair_set_screen(machine, 0, CROSSHAIR_SCREEN_NONE);
162   }
163
164   if ((input_port_read(machine, "CTRLSEL") & 0xf0) == 0x30 || (input_port_read(machine, "CTRLSEL") & 0xf0) == 0x40)
165   {
166      /* enable lightpen crosshair */
167      crosshair_set_screen(machine, 1, CROSSHAIR_SCREEN_ALL);
168   }
169   else
170   {
171      /* disable lightpen crosshair */
172      crosshair_set_screen(machine, 1, CROSSHAIR_SCREEN_NONE);
173   }
174}
175
176
177static INPUT_PORTS_START( snes_joypads )
178   PORT_START("SERIAL1_DATA1_L")
179   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("P1 Button A") PORT_PLAYER(1) PORT_CATEGORY(11)
180   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("P1 Button X") PORT_PLAYER(1) PORT_CATEGORY(11)
181   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_NAME("P1 Button L") PORT_PLAYER(1) PORT_CATEGORY(11)
182   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_NAME("P1 Button R") PORT_PLAYER(1) PORT_CATEGORY(11)
183   PORT_START("SERIAL1_DATA1_H")
184   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P1 Button B") PORT_PLAYER(1) PORT_CATEGORY(11)
185   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P1 Button Y") PORT_PLAYER(1) PORT_CATEGORY(11)
186   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_PLAYER(1) PORT_CATEGORY(11)
187   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START1 ) PORT_PLAYER(1) PORT_CATEGORY(11)
188   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(1) PORT_CATEGORY(11)
189   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) PORT_CATEGORY(11)
190   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) PORT_CATEGORY(11)
191   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) PORT_CATEGORY(11)
192
193   PORT_START("SERIAL2_DATA1_L")
194   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("P2 Button A") PORT_PLAYER(2) PORT_CATEGORY(21)
195   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("P2 Button X") PORT_PLAYER(2) PORT_CATEGORY(21)
196   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_NAME("P2 Button L") PORT_PLAYER(2) PORT_CATEGORY(21)
197   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_NAME("P2 Button R") PORT_PLAYER(2) PORT_CATEGORY(21)
198   PORT_START("SERIAL2_DATA1_H")
199   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P2 Button B") PORT_PLAYER(2) PORT_CATEGORY(21)
200   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P2 Button Y") PORT_PLAYER(2) PORT_CATEGORY(21)
201   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SELECT ) PORT_PLAYER(2) PORT_CATEGORY(21)
202   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START2 ) PORT_PLAYER(2) PORT_CATEGORY(21)
203   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(2) PORT_CATEGORY(21)
204   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) PORT_CATEGORY(21)
205   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) PORT_CATEGORY(21)
206   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) PORT_CATEGORY(21)
207
208   PORT_START("SERIAL1_DATA2_L")
209   PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNUSED )
210   PORT_START("SERIAL1_DATA2_H")
211   PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNUSED )
212
213   PORT_START("SERIAL2_DATA2_L")
214   PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNUSED )
215   PORT_START("SERIAL2_DATA2_H")
216   PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNUSED )
217INPUT_PORTS_END
218
219static INPUT_PORTS_START( snes_mouse )
220   PORT_START("MOUSE1")
221   /* bits 0,3 = mouse signature (must be 1) */
222   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
223   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNUSED )
224   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED )
225   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
226   /* bits 4,5 = mouse speed: 0 = slow, 1 = normal, 2 = fast, 3 = unused */
227   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(snes_mouse_speed_input, (void *)0)
228   /* bits 6,7 = mouse buttons */
229   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P1 Mouse Button Left") PORT_PLAYER(1) PORT_CATEGORY(12)
230   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P1 Mouse Button Right") PORT_PLAYER(1) PORT_CATEGORY(12)
231
232   PORT_START("MOUSE1_X")
233   PORT_BIT( 0xff, 0x00, IPT_TRACKBALL_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1) PORT_CATEGORY(12)
234
235   PORT_START("MOUSE1_Y")
236   PORT_BIT( 0xff, 0x00, IPT_TRACKBALL_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1) PORT_CATEGORY(12)
237
238   PORT_START("MOUSE2")
239   /* bits 0,3 = mouse signature (must be 1) */
240   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
241   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNUSED )
242   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED )
243   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
244   /* bits 4,5 = mouse speed: 0 = slow, 1 = normal, 2 = fast, 3 = unused */
245   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(snes_mouse_speed_input, (void *)1)
246   /* bits 6,7 = mouse buttons */
247   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("P2 Mouse Button Left") PORT_PLAYER(2) PORT_CATEGORY(22)
248   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("P2 Mouse Button Right") PORT_PLAYER(2) PORT_CATEGORY(22)
249
250   PORT_START("MOUSE2_X")
251   PORT_BIT( 0xff, 0x00, IPT_TRACKBALL_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(2) PORT_CATEGORY(22)
252
253   PORT_START("MOUSE2_Y")
254   PORT_BIT( 0xff, 0x00, IPT_TRACKBALL_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(2) PORT_CATEGORY(22)
255INPUT_PORTS_END
256
257static INPUT_PORTS_START( snes_superscope )
258   PORT_START("SUPERSCOPE1")
259   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED )   // Noise
260   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(snes_superscope_offscreen_input, (void *)0)
261   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED )
262   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
263   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("Port1 Superscope Pause") PORT_PLAYER(1) PORT_CATEGORY(13)
264   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("Port1 Superscope Turbo") PORT_TOGGLE PORT_PLAYER(1) PORT_CATEGORY(13)
265   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("Port1 Superscope Cursor") PORT_PLAYER(1) PORT_CATEGORY(13)
266   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("Port1 Superscope Fire") PORT_PLAYER(1) PORT_CATEGORY(13)
267
268   PORT_START("SUPERSCOPE1_X")
269   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X ) PORT_NAME("Port1 Superscope X Axis") PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_PLAYER(1) PORT_CATEGORY(13)
270
271   PORT_START("SUPERSCOPE1_Y")
272   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y) PORT_NAME("Port1 Superscope Y Axis") PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_PLAYER(1) PORT_CATEGORY(13)
273
274   PORT_START("SUPERSCOPE2")
275   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED )   // Noise
276   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(snes_superscope_offscreen_input, (void *)1)
277   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED )
278   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
279   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("Port2 Superscope Pause") PORT_PLAYER(2) PORT_CATEGORY(23)
280   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("Port2 Superscope Turbo") PORT_PLAYER(2) PORT_CATEGORY(23)
281   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("Port2 Superscope Cursor") PORT_PLAYER(2) PORT_CATEGORY(23)
282   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("Port2 Superscope Fire") PORT_PLAYER(2) PORT_CATEGORY(23)
283
284   PORT_START("SUPERSCOPE2_X")
285   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X ) PORT_NAME("Port2 Superscope X Axis") PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_PLAYER(2) PORT_CATEGORY(23)
286
287   PORT_START("SUPERSCOPE2_Y")
288   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y) PORT_NAME("Port2 Superscope Y Axis") PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_PLAYER(2) PORT_CATEGORY(23)
289INPUT_PORTS_END
290
291static INPUT_PORTS_START( snes )
292   PORT_START("CTRLSEL")  /* Select Controller Type */
293   PORT_CATEGORY_CLASS( 0x0f, 0x01, "P1 Controller")
294   PORT_CATEGORY_ITEM(  0x00, "Unconnected",      10 )
295   PORT_CATEGORY_ITEM(  0x01, "Gamepad",      11 )
296   PORT_CATEGORY_ITEM(  0x02, "Mouse",         12 )
297   PORT_CATEGORY_ITEM(  0x03, "Superscope",      13 )
298//  PORT_CATEGORY_ITEM(  0x04, "Justfier",      14 )
299//  PORT_CATEGORY_ITEM(  0x05, "Multitap",      15 )
300   PORT_CATEGORY_CLASS( 0xf0, 0x10, "P2 Controller")
301   PORT_CATEGORY_ITEM(  0x00, "Unconnected",      20 )
302   PORT_CATEGORY_ITEM(  0x10, "Gamepad",      21 )
303   PORT_CATEGORY_ITEM(  0x20, "Mouse",         22 )
304   PORT_CATEGORY_ITEM(  0x30, "Superscope",      23 )
305//  PORT_CATEGORY_ITEM(  0x40, "Justfier",      24 )
306//  PORT_CATEGORY_ITEM(  0x50, "Multitap",      25 )
307
308   PORT_INCLUDE(snes_joypads)
309   PORT_INCLUDE(snes_mouse)
310   PORT_INCLUDE(snes_superscope)
311
312   PORT_START("OPTIONS")
313   PORT_CONFNAME( 0x01, 0x00, "Hi-Res pixels blurring (TV effect)")
314   PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
315   PORT_CONFSETTING(    0x01, DEF_STR( On ) )
316
317#if SNES_LAYER_DEBUG
318   PORT_START("DEBUG1")
319   PORT_CONFNAME( 0x03, 0x00, "Select BG1 priority" )
320   PORT_CONFSETTING(    0x00, "All" )
321   PORT_CONFSETTING(    0x01, "BG1B (lower) only" )
322   PORT_CONFSETTING(    0x02, "BG1A (higher) only" )
323   PORT_CONFNAME( 0x0c, 0x00, "Select BG2 priority" )
324   PORT_CONFSETTING(    0x00, "All" )
325   PORT_CONFSETTING(    0x04, "BG2B (lower) only" )
326   PORT_CONFSETTING(    0x08, "BG2A (higher) only" )
327   PORT_CONFNAME( 0x30, 0x00, "Select BG3 priority" )
328   PORT_CONFSETTING(    0x00, "All" )
329   PORT_CONFSETTING(    0x10, "BG3B (lower) only" )
330   PORT_CONFSETTING(    0x20, "BG3A (higher) only" )
331   PORT_CONFNAME( 0xc0, 0x00, "Select BG4 priority" )
332   PORT_CONFSETTING(    0x00, "All" )
333   PORT_CONFSETTING(    0x40, "BG4B (lower) only" )
334   PORT_CONFSETTING(    0x80, "BG4A (higher) only" )
335
336   PORT_START("DEBUG2")
337   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 1") PORT_CODE(KEYCODE_1_PAD) PORT_TOGGLE
338   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 2") PORT_CODE(KEYCODE_2_PAD) PORT_TOGGLE
339   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 3") PORT_CODE(KEYCODE_3_PAD) PORT_TOGGLE
340   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 4") PORT_CODE(KEYCODE_4_PAD) PORT_TOGGLE
341   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Objects") PORT_CODE(KEYCODE_5_PAD) PORT_TOGGLE
342   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Main/Sub") PORT_CODE(KEYCODE_6_PAD) PORT_TOGGLE
343   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Color Math") PORT_CODE(KEYCODE_7_PAD) PORT_TOGGLE
344   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Windows") PORT_CODE(KEYCODE_8_PAD) PORT_TOGGLE
345
346   PORT_START("DEBUG3")
347   PORT_BIT( 0x4, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mosaic") PORT_CODE(KEYCODE_9_PAD) PORT_TOGGLE
348   PORT_CONFNAME( 0x70, 0x00, "Select OAM priority" )
349   PORT_CONFSETTING(    0x00, "All" )
350   PORT_CONFSETTING(    0x10, "OAM0 only" )
351   PORT_CONFSETTING(    0x20, "OAM1 only" )
352   PORT_CONFSETTING(    0x30, "OAM2 only" )
353   PORT_CONFSETTING(    0x40, "OAM3 only" )
354   PORT_CONFNAME( 0x80, 0x00, "Draw sprite in reverse order" )
355   PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
356   PORT_CONFSETTING(    0x80, DEF_STR( On ) )
357
358   PORT_START("DEBUG4")
359   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 0 draw") PORT_TOGGLE
360   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 1 draw") PORT_TOGGLE
361   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 2 draw") PORT_TOGGLE
362   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 3 draw") PORT_TOGGLE
363   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 4 draw") PORT_TOGGLE
364   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 5 draw") PORT_TOGGLE
365   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 6 draw") PORT_TOGGLE
366   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 7 draw") PORT_TOGGLE
367#endif
368INPUT_PORTS_END
369
370
371/*************************************
372 *
373 *  Input callbacks
374 *
375 *************************************/
376
377static void snes_gun_latch( running_machine &machine, INT16 x, INT16 y )
378{
379   /* these are the theoretical boundaries */
380   if (x < 0)
381      x = 0;
382   if (x > (SNES_SCR_WIDTH - 1))
383      x = SNES_SCR_WIDTH - 1;
384
385   if (y < 0)
386      y = 0;
387   if (y > (snes_ppu.beam.last_visible_line - 1))
388      y = snes_ppu.beam.last_visible_line - 1;
389
390   snes_ppu.beam.latch_horz = x;
391   snes_ppu.beam.latch_vert = y;
392   snes_ram[STAT78] |= 0x40;
393}
394
395static void snes_input_read_joy( running_machine &machine, int port )
396{
397   snes_state *state = machine.driver_data<snes_state>();
398   static const char *const portnames[2][4] =
399         {
400            { "SERIAL1_DATA1_L", "SERIAL1_DATA1_H", "SERIAL1_DATA2_L", "SERIAL1_DATA2_H" },
401            { "SERIAL2_DATA1_L", "SERIAL2_DATA1_H", "SERIAL2_DATA2_L", "SERIAL2_DATA2_H" },
402         };
403
404   state->m_data1[port] = input_port_read(machine, portnames[port][0]) | (input_port_read(machine, portnames[port][1]) << 8);
405   state->m_data2[port] = input_port_read(machine, portnames[port][2]) | (input_port_read(machine, portnames[port][3]) << 8);
406
407   // avoid sending signals that could crash games
408   // if left, no right
409   if (state->m_data1[port] & 0x200)
410      state->m_data1[port] &= ~0x100;
411   // if up, no down
412   if (state->m_data1[port] & 0x800)
413      state->m_data1[port] &= ~0x400;
414
415   state->m_joypad[port].buttons = state->m_data1[port];
416}
417
418static void snes_input_read_mouse( running_machine &machine, int port )
419{
420   snes_state *state = machine.driver_data<snes_state>();
421   INT16 var;
422   static const char *const portnames[2][3] =
423         {
424            { "MOUSE1", "MOUSE1_X", "MOUSE1_Y" },
425            { "MOUSE2", "MOUSE2_X", "MOUSE2_Y" },
426         };
427
428   state->m_mouse[port].buttons = input_port_read(machine, portnames[port][0]);
429   state->m_mouse[port].x = input_port_read(machine, portnames[port][1]);
430   state->m_mouse[port].y = input_port_read(machine, portnames[port][2]);
431   var = state->m_mouse[port].x - state->m_mouse[port].oldx;
432
433   if (var < -127)
434   {
435      state->m_mouse[port].deltax = 0xff;
436      state->m_mouse[port].oldx -= 127;
437   }
438   else if (var < 0)
439   {
440      state->m_mouse[port].deltax = 0x80 | (-var);
441      state->m_mouse[port].oldx = state->m_mouse[port].x;
442   }
443   else if (var > 127)
444   {
445      state->m_mouse[port].deltax = 0x7f;
446      state->m_mouse[port].oldx += 127;
447   }
448   else
449   {
450      state->m_mouse[port].deltax = var & 0xff;
451      state->m_mouse[port].oldx = state->m_mouse[port].x;
452   }
453
454   var = state->m_mouse[port].y - state->m_mouse[port].oldy;
455
456   if (var < -127)
457   {
458      state->m_mouse[port].deltay = 0xff;
459      state->m_mouse[port].oldy -= 127;
460   }
461   else if (var < 0)
462   {
463      state->m_mouse[port].deltay = 0x80 | (-var);
464      state->m_mouse[port].oldy = state->m_mouse[port].y;
465   }
466   else if (var > 127)
467   {
468      state->m_mouse[port].deltay = 0x7f;
469      state->m_mouse[port].oldy += 127;
470   }
471   else
472   {
473      state->m_mouse[port].deltay = var & 0xff;
474      state->m_mouse[port].oldy = state->m_mouse[port].y;
475   }
476
477   state->m_data1[port] = state->m_mouse[port].buttons | (0x00 << 8);
478   state->m_data2[port] = 0;
479}
480
481static void snes_input_read_superscope( running_machine &machine, int port )
482{
483   snes_state *state = machine.driver_data<snes_state>();
484   static const char *const portnames[2][3] =
485         {
486            { "SUPERSCOPE1", "SUPERSCOPE1_X", "SUPERSCOPE1_Y" },
487            { "SUPERSCOPE2", "SUPERSCOPE2_X", "SUPERSCOPE2_Y" },
488         };
489   UINT8 input;
490
491   /* first read input bits */
492   state->m_scope[port].x = input_port_read(machine, portnames[port][1]);
493   state->m_scope[port].y = input_port_read(machine, portnames[port][2]);
494   input = input_port_read(machine, portnames[port][0]);
495
496   /* then start elaborating input bits: only keep old turbo value */
497   state->m_scope[port].buttons &= 0x20;
498
499   /* set onscreen/offscreen */
500   state->m_scope[port].buttons |= BIT(input, 1);
501
502   /* turbo is a switch; toggle is edge sensitive */
503   if (BIT(input, 5) && !state->m_scope[port].turbo_lock)
504   {
505      state->m_scope[port].buttons ^= 0x20;
506      state->m_scope[port].turbo_lock = 1;
507   }
508   else if (!BIT(input, 5))
509      state->m_scope[port].turbo_lock = 0;
510
511   /* fire is a button; if turbo is active, trigger is level sensitive; otherwise it is edge sensitive */
512   if (BIT(input, 7) && (BIT(state->m_scope[port].buttons, 5) || !state->m_scope[port].fire_lock))
513   {
514      state->m_scope[port].buttons |= 0x80;
515      state->m_scope[port].fire_lock = 1;
516   }
517   else if (!BIT(input, 7))
518      state->m_scope[port].fire_lock = 0;
519
520   /* cursor is a button; it is always level sensitive */
521   state->m_scope[port].buttons |= BIT(input, 6);
522
523   /* pause is a button; it is always edge sensitive */
524   if (BIT(input, 4) && !state->m_scope[port].pause_lock)
525   {
526      state->m_scope[port].buttons |= 0x10;
527      state->m_scope[port].pause_lock = 1;
528   }
529   else if (!BIT(input, 4))
530      state->m_scope[port].pause_lock = 0;
531
532   /* If we have pressed fire or cursor and we are on-screen and SuperScope is in Port2, then latch video signal.
533    Notice that we only latch Port2 because its IOBit pin is connected to bit7 of the IO Port, while Port1 has
534    IOBit pin connected to bit6 of the IO Port, and the latter is not detected by the H/V Counters. In other
535    words, you can connect SuperScope to Port1, but there is no way SNES could detect its on-screen position */
536   if ((state->m_scope[port].buttons & 0xc0) && !(state->m_scope[port].buttons & 0x02) && port == 1)
537      snes_gun_latch(machine, state->m_scope[port].x, state->m_scope[port].y);
538
539   state->m_data1[port] = 0xff | (state->m_scope[port].buttons << 8);
540   state->m_data2[port] = 0;
541}
542
543static void snes_input_read( running_machine &machine )
544{
545   snes_state *state = machine.driver_data<snes_state>();
546   UINT8 ctrl1 = input_port_read(machine, "CTRLSEL") & 0x0f;
547   UINT8 ctrl2 = (input_port_read(machine, "CTRLSEL") & 0xf0) >> 4;
548
549   /* Check if lightgun has been chosen as input: if so, enable crosshair */
550   machine.scheduler().timer_set(attotime::zero, FUNC(lightgun_tick));
551
552   switch (ctrl1)
553   {
554   case 1:   /* SNES joypad */
555      snes_input_read_joy(machine, 0);
556      break;
557   case 2:   /* SNES Mouse */
558      snes_input_read_mouse(machine, 0);
559      break;
560   case 3:   /* SNES Superscope */
561      snes_input_read_superscope(machine, 0);
562      break;
563   case 0:   /* no controller in port1 */
564   default:
565      state->m_data1[0] = 0;
566      state->m_data2[0] = 0;
567      break;
568   }
569
570   switch (ctrl2)
571   {
572   case 1:   /* SNES joypad */
573      snes_input_read_joy(machine, 1);
574      break;
575   case 2:   /* SNES Mouse */
576      snes_input_read_mouse(machine, 1);
577      break;
578   case 3:   /* SNES Superscope */
579      snes_input_read_superscope(machine, 1);
580      break;
581   case 0:   /* no controller in port2 */
582   default:
583      state->m_data1[1] = 0;
584      state->m_data2[1] = 0;
585      break;
586   }
587
588   // is automatic reading on? if so, copy port data1/data2 to joy1l->joy4h
589   // this actually works like reading the first 16bits from oldjoy1/2 in reverse order
590   if (snes_ram[NMITIMEN] & 1)
591   {
592      state->m_joy1l = (state->m_data1[0] & 0x00ff) >> 0;
593      state->m_joy1h = (state->m_data1[0] & 0xff00) >> 8;
594      state->m_joy2l = (state->m_data1[1] & 0x00ff) >> 0;
595      state->m_joy2h = (state->m_data1[1] & 0xff00) >> 8;
596      state->m_joy3l = (state->m_data2[0] & 0x00ff) >> 0;
597      state->m_joy3h = (state->m_data2[0] & 0xff00) >> 8;
598      state->m_joy4l = (state->m_data2[1] & 0x00ff) >> 0;
599      state->m_joy4h = (state->m_data2[1] & 0xff00) >> 8;
600
601      // make sure read_idx starts returning all 1s because the auto-read reads it :-)
602      state->m_read_idx[0] = 16;
603      state->m_read_idx[1] = 16;
604   }
605
606}
607
608static UINT8 snes_oldjoy1_read( running_machine &machine )
609{
610   snes_state *state = machine.driver_data<snes_state>();
611   UINT8 ctrl1 = input_port_read(machine, "CTRLSEL") & 0x0f;
612   UINT8 res = 0;
613
614   switch (ctrl1)
615   {
616   case 1:   /* SNES joypad */
617      if (state->m_read_idx[0] >= 16)
618         res = 0x01;
619      else
620         res = (state->m_joypad[0].buttons >> (15 - state->m_read_idx[0]++)) & 0x01;
621      break;
622   case 2:   /* SNES Mouse */
623      if (state->m_read_idx[0] >= 32)
624         res = 0x01;
625      else if (state->m_read_idx[0] >= 24)
626         res = (state->m_mouse[0].deltax >> (31 - state->m_read_idx[0]++)) & 0x01;
627      else if (state->m_read_idx[0] >= 16)
628         res = (state->m_mouse[0].deltay >> (23 - state->m_read_idx[0]++)) & 0x01;
629      else if (state->m_read_idx[0] >= 8)
630         res = (state->m_mouse[0].buttons >> (15 - state->m_read_idx[0]++)) & 0x01;
631      else
632         res = 0;
633      break;
634   case 3:   /* SNES Superscope */
635      if (state->m_read_idx[0] >= 8)
636         res = 0x01;
637      else
638         res = (state->m_scope[0].buttons >> (7 - state->m_read_idx[0]++)) & 0x01;
639      break;
640   case 0:   /* no controller in port2 */
641   default:
642      break;
643   }
644
645   return res;
646}
647
648static UINT8 snes_oldjoy2_read( running_machine &machine )
649{
650   snes_state *state = machine.driver_data<snes_state>();
651   UINT8 ctrl2 = (input_port_read(machine, "CTRLSEL") & 0xf0) >> 4;
652   UINT8 res = 0;
653
654   switch (ctrl2)
655   {
656   case 1:   /* SNES joypad */
657      if (state->m_read_idx[1] >= 16)
658         res = 0x01;
659      else
660         res = (state->m_joypad[1].buttons >> (15 - state->m_read_idx[1]++)) & 0x01;
661      break;
662   case 2:   /* SNES Mouse */
663      if (state->m_read_idx[1] >= 32)
664         res = 0x01;
665      else if (state->m_read_idx[1] >= 24)
666         res = (state->m_mouse[1].deltax >> (31 - state->m_read_idx[1]++)) & 0x01;
667      else if (state->m_read_idx[1] >= 16)
668         res = (state->m_mouse[1].deltay >> (23 - state->m_read_idx[1]++)) & 0x01;
669      else if (state->m_read_idx[1] >= 8)
670         res = (state->m_mouse[1].buttons >> (15 - state->m_read_idx[1]++)) & 0x01;
671      else
672         res = 0;
673      break;
674   case 3:   /* SNES Superscope */
675      if (state->m_read_idx[1] >= 8)
676         res = 0x01;
677      else
678         res = (state->m_scope[1].buttons >> (7 - state->m_read_idx[1]++)) & 0x01;
679      break;
680   case 0:   /* no controller in port2 */
681   default:
682      break;
683   }
684
685   return res;
686}
687
688/*************************************
689 *
690 *  Machine driver
691 *
692 *************************************/
693
694static MACHINE_RESET( snes_mess )
695{
696   snes_state *state = machine.driver_data<snes_state>();
697
698   MACHINE_RESET_CALL(snes);
699
700   state->m_io_read = snes_input_read;
701   state->m_oldjoy1_read = snes_oldjoy1_read;
702   state->m_oldjoy2_read = snes_oldjoy2_read;
703}
704
705static MACHINE_CONFIG_START( snes_base, snes_state )
706
707   /* basic machine hardware */
708   MCFG_CPU_ADD("maincpu", _5A22, MCLK_NTSC)   /* 2.68 MHz, also 3.58 MHz */
709   MCFG_CPU_PROGRAM_MAP(snes_map)
710
711   MCFG_CPU_ADD("soundcpu", SPC700, 1024000)   /* 1.024 MHz */
712   MCFG_CPU_PROGRAM_MAP(spc_map)
713
714   //MCFG_QUANTUM_TIME(attotime::from_hz(48000))
715   MCFG_QUANTUM_PERFECT_CPU("maincpu")
716
717   MCFG_MACHINE_START(snes_mess)
718   MCFG_MACHINE_RESET(snes_mess)
719
720   /* video hardware */
721   MCFG_VIDEO_START(snes)
722
723   MCFG_SCREEN_ADD("screen", RASTER)
724   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
725   MCFG_SCREEN_RAW_PARAMS(DOTCLK_NTSC, SNES_HTOTAL, 0, SNES_SCR_WIDTH, SNES_VTOTAL_NTSC, 0, SNES_SCR_HEIGHT_NTSC)
726   MCFG_SCREEN_UPDATE(snes)
727
728   /* sound hardware */
729   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
730   MCFG_SOUND_ADD("spc700", SNES, 0)
731   MCFG_SOUND_ROUTE(0, "lspeaker", 1.00)
732   MCFG_SOUND_ROUTE(1, "rspeaker", 1.00)
733MACHINE_CONFIG_END
734
735static MACHINE_CONFIG_DERIVED( snes, snes_base )
736
737   MCFG_FRAGMENT_ADD(snes_cartslot)
738MACHINE_CONFIG_END
739
740static SUPERFX_CONFIG( snes_superfx_config )
741{
742   DEVCB_LINE(snes_extern_irq_w)   /* IRQ line from cart */
743};
744
745static MACHINE_CONFIG_DERIVED( snessfx, snes )
746
747   MCFG_CPU_ADD("superfx", SUPERFX, 21480000)   /* 21.48MHz */
748   MCFG_CPU_PROGRAM_MAP(superfx_map)
749   MCFG_CPU_CONFIG(snes_superfx_config)
750MACHINE_CONFIG_END
751
752static MACHINE_CONFIG_DERIVED( snesdsp, snes )
753
754   MCFG_CPU_ADD("dsp", UPD7725, 8000000)
755   MCFG_CPU_PROGRAM_MAP(dsp_prg_map)
756   MCFG_CPU_DATA_MAP(dsp_data_map)
757MACHINE_CONFIG_END
758
759static MACHINE_CONFIG_DERIVED( snesst10, snes )
760
761   MCFG_CPU_ADD("setadsp", UPD96050, 10000000)
762   MCFG_CPU_PROGRAM_MAP(setadsp_prg_map)
763   MCFG_CPU_DATA_MAP(setadsp_data_map)
764MACHINE_CONFIG_END
765
766static MACHINE_CONFIG_DERIVED( snesst11, snes )
767
768   MCFG_CPU_ADD("setadsp", UPD96050, 15000000)
769   MCFG_CPU_PROGRAM_MAP(setadsp_prg_map)
770   MCFG_CPU_DATA_MAP(setadsp_data_map)
771MACHINE_CONFIG_END
772
773static MACHINE_CONFIG_DERIVED( snespal, snes )
774   MCFG_CPU_MODIFY( "maincpu" )
775   MCFG_CPU_CLOCK( MCLK_PAL )
776
777   MCFG_SCREEN_MODIFY("screen")
778   MCFG_SCREEN_RAW_PARAMS(DOTCLK_PAL, SNES_HTOTAL, 0, SNES_SCR_WIDTH, SNES_VTOTAL_PAL, 0, SNES_SCR_HEIGHT_PAL)
779MACHINE_CONFIG_END
780
781static MACHINE_CONFIG_DERIVED( snespsfx, snespal )
782
783   MCFG_CPU_ADD("superfx", SUPERFX, 21480000)   /* 21.48MHz */
784   MCFG_CPU_PROGRAM_MAP(superfx_map)
785   MCFG_CPU_CONFIG(snes_superfx_config)
786MACHINE_CONFIG_END
787
788static MACHINE_CONFIG_DERIVED( snespdsp, snespal )
789
790   MCFG_CPU_ADD("dsp", UPD7725, 8000000)
791   MCFG_CPU_PROGRAM_MAP(dsp_prg_map)
792   MCFG_CPU_DATA_MAP(dsp_data_map)
793MACHINE_CONFIG_END
794
795static MACHINE_CONFIG_DERIVED( snesst, snes_base )
796
797   MCFG_MACHINE_START(snesst)
798
799   MCFG_FRAGMENT_ADD(sufami_cartslot)
800MACHINE_CONFIG_END
801
802static MACHINE_CONFIG_DERIVED( snesbsx, snes_base )
803
804   MCFG_FRAGMENT_ADD(bsx_cartslot)
805MACHINE_CONFIG_END
806
807
808/*************************************
809 *
810 *  ROM definition(s)
811 *
812 *************************************/
813
814ROM_START( snes )
815   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
816
817   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
818   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
819
820   ROM_REGION( 0x10000, "addons", ROMREGION_ERASE00 )      /* add-on chip ROMs (DSP, SFX, etc) */
821
822   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
823   ROM_REGION( 0x2000, "dspprg", ROMREGION_ERASEFF)
824   ROM_REGION( 0x800, "dspdata", ROMREGION_ERASEFF)
825ROM_END
826
827ROM_START( snesdsp )
828   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
829
830   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
831   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
832
833   ROM_REGION( 0x10000, "addons", 0 )      /* add-on chip ROMs (DSP, SFX, etc) */
834   ROM_LOAD( "dsp1b.bin", SNES_DSP1B_OFFSET, 0x002800, CRC(453557e0) SHA1(3a218b0e4572a8eba6d0121b17fdac9529609220) )
835   ROM_LOAD( "dsp1.bin",  SNES_DSP1_OFFSET,  0x002800, CRC(2838f9f5) SHA1(0a03ccb1fd2bea91151c745a4d1f217ae784f889) )
836   ROM_LOAD( "dsp2.bin",  SNES_DSP2_OFFSET,  0x002800, CRC(8e9fbd9b) SHA1(06dd9fcb118d18f6bbe234e013cb8780e06d6e63) )
837   ROM_LOAD( "dsp3.bin",  SNES_DSP3_OFFSET,  0x002800, CRC(6b86728a) SHA1(1b133741fad810eb7320c21ecfdd427d25a46da1) )
838   ROM_LOAD( "dsp4.bin",  SNES_DSP4_OFFSET,  0x002800, CRC(ce0c7783) SHA1(76fd25f7dc26c3b3f7868a3aa78c7684068713e5) )
839
840   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
841   ROM_REGION( 0x2000, "dspprg", ROMREGION_ERASEFF)
842   ROM_REGION( 0x800, "dspdata", ROMREGION_ERASEFF)
843ROM_END
844
845ROM_START( snesst10 )
846   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
847
848   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
849   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
850
851   ROM_REGION( 0x11000, "addons", 0 )      /* add-on chip ROMs (DSP, SFX, etc) */
852   ROM_LOAD( "st010.bin",    0x000000, 0x011000, CRC(aa11ee2d) SHA1(cc1984e989cb94e3dcbb5f99e085b5414e18a017) )
853
854   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
855   ROM_REGION( 0x10000, "dspprg", ROMREGION_ERASEFF)
856   ROM_REGION( 0x1000, "dspdata", ROMREGION_ERASEFF)
857ROM_END
858
859ROM_START( snesst11 )
860   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
861
862   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
863   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
864
865   ROM_REGION( 0x11000, "addons", 0 )      /* add-on chip ROMs (DSP, SFX, etc) */
866   ROM_LOAD( "st011.bin",    0x000000, 0x011000, CRC(34d2952c) SHA1(1375b8c1efc8cae4962b57dfe22f6b78e1ddacc8) )
867
868   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
869   ROM_REGION( 0x10000, "dspprg", ROMREGION_ERASEFF)
870   ROM_REGION( 0x1000, "dspdata", ROMREGION_ERASEFF)
871ROM_END
872
873ROM_START( snessfx )
874   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
875
876   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
877   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
878
879   ROM_REGION( 0x10000, "addons", ROMREGION_ERASE00 )      /* add-on chip ROMs (DSP, SFX, etc) */
880
881   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
882   ROM_REGION( 0x2000, "dspprg", ROMREGION_ERASEFF)
883   ROM_REGION( 0x800, "dspdata", ROMREGION_ERASEFF)
884ROM_END
885
886ROM_START( snespal )
887   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
888
889   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
890   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
891
892   ROM_REGION( 0x10000, "addons", ROMREGION_ERASE00 )      /* add-on chip ROMs (DSP, SFX, etc) */
893
894   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
895   ROM_REGION( 0x2000, "dspprg", ROMREGION_ERASEFF)
896   ROM_REGION( 0x800, "dspdata", ROMREGION_ERASEFF)
897ROM_END
898
899ROM_START( snespdsp )
900   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
901
902   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
903   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
904
905   ROM_REGION( 0x10000, "addons", 0 )      /* add-on chip ROMs (DSP, SFX, etc) */
906   ROM_LOAD( "dsp1b.bin", SNES_DSP1B_OFFSET, 0x002800, CRC(453557e0) SHA1(3a218b0e4572a8eba6d0121b17fdac9529609220) )
907   ROM_LOAD( "dsp1.bin",  SNES_DSP1_OFFSET,  0x002800, CRC(2838f9f5) SHA1(0a03ccb1fd2bea91151c745a4d1f217ae784f889) )
908   ROM_LOAD( "dsp2.bin",  SNES_DSP2_OFFSET,  0x002800, CRC(8e9fbd9b) SHA1(06dd9fcb118d18f6bbe234e013cb8780e06d6e63) )
909   ROM_LOAD( "dsp3.bin",  SNES_DSP3_OFFSET,  0x002800, CRC(6b86728a) SHA1(1b133741fad810eb7320c21ecfdd427d25a46da1) )
910   ROM_LOAD( "dsp4.bin",  SNES_DSP4_OFFSET,  0x002800, CRC(ce0c7783) SHA1(76fd25f7dc26c3b3f7868a3aa78c7684068713e5) )
911
912   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
913   ROM_REGION( 0x2000, "dspprg", ROMREGION_ERASEFF)
914   ROM_REGION( 0x800, "dspdata", ROMREGION_ERASEFF)
915ROM_END
916
917ROM_START( snespsfx )
918   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
919
920   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
921   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
922
923   ROM_REGION( 0x10000, "addons", ROMREGION_ERASE00 )      /* add-on chip ROMs (DSP, SFX, etc) */
924
925   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
926   ROM_REGION( 0x2000, "dspprg", ROMREGION_ERASEFF)
927   ROM_REGION( 0x800, "dspdata", ROMREGION_ERASEFF)
928ROM_END
929
930ROM_START( snesst )
931   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
932
933   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
934   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
935
936   ROM_REGION( 0x10000, "addons", ROMREGION_ERASE00 )      /* add-on chip ROMs (DSP, SFX, etc) */
937
938   ROM_REGION( 0x40000, "sufami", 0 )      /* add-on chip ROMs (DSP, SFX, etc) */
939   ROM_LOAD( "shvc-qh-0.bin", 0,   0x40000, CRC(9b4ca911) SHA1(ef86ea192eed03d5c413fdbbfd46043be1d7a127) )
940
941   ROM_REGION( MAX_SNES_CART_SIZE, "slot_a", ROMREGION_ERASE00 )
942   ROM_REGION( MAX_SNES_CART_SIZE, "slot_b", ROMREGION_ERASE00 )
943   ROM_REGION( 0x2000, "dspprg", ROMREGION_ERASEFF)
944   ROM_REGION( 0x800, "dspdata", ROMREGION_ERASEFF)
945ROM_END
946
947ROM_START( snesbsx )
948   ROM_REGION( 0x1000000, "maincpu", ROMREGION_ERASE00 )
949
950   ROM_REGION( 0x100, "user5", 0 )      /* IPL ROM */
951   ROM_LOAD( "spc700.rom", 0, 0x40, CRC(44bb3a40) SHA1(97e352553e94242ae823547cd853eecda55c20f0) )   /* boot rom */
952
953   ROM_REGION( 0x10000, "addons", 0 )      /* add-on chip ROMs (DSP, SFX, etc) */
954   ROM_LOAD( "dsp1b.bin", SNES_DSP1B_OFFSET, 0x002800, CRC(453557e0) SHA1(3a218b0e4572a8eba6d0121b17fdac9529609220) )
955   ROM_LOAD( "dsp1.bin",  SNES_DSP1_OFFSET,  0x002800, CRC(2838f9f5) SHA1(0a03ccb1fd2bea91151c745a4d1f217ae784f889) )
956   ROM_LOAD( "dsp2.bin",  SNES_DSP2_OFFSET,  0x002800, CRC(8e9fbd9b) SHA1(06dd9fcb118d18f6bbe234e013cb8780e06d6e63) )
957   ROM_LOAD( "dsp3.bin",  SNES_DSP3_OFFSET,  0x002800, CRC(6b86728a) SHA1(1b133741fad810eb7320c21ecfdd427d25a46da1) )
958   ROM_LOAD( "dsp4.bin",  SNES_DSP4_OFFSET,  0x002800, CRC(ce0c7783) SHA1(76fd25f7dc26c3b3f7868a3aa78c7684068713e5) )
959
960   ROM_REGION( MAX_SNES_CART_SIZE, "cart", ROMREGION_ERASE00 )
961   ROM_REGION( MAX_SNES_CART_SIZE, "flash", ROMREGION_ERASE00 )
962   ROM_REGION( 0x2000, "dspprg", ROMREGION_ERASEFF)
963   ROM_REGION( 0x800, "dspdata", ROMREGION_ERASEFF)
964ROM_END
965
966
967
968/*************************************
969 *
970 *  Game driver(s)
971 *
972 *************************************/
973
974/*    YEAR  NAME      PARENT  COMPAT  MACHINE   INPUT  INIT          COMPANY     FULLNAME                                      FLAGS */
975CONS( 1989, snes,     0,      0,      snes,     snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System / Super Famicom (NTSC)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
976CONS( 1991, snespal,  snes,   0,      snespal,  snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System (PAL)",  GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
977
978// FIXME: the "hacked" drivers below, currently needed due to limitations in the core device design, should eventually be removed
979
980// These would require CPU to be added/removed depending on the cart which is loaded
981CONS( 1989, snesdsp,  snes,   0,      snesdsp,  snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System / Super Famicom (NTSC, w/DSP-x)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
982CONS( 1991, snespdsp, snes,   0,      snespdsp, snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System (PAL, w/DSP-x)",  GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
983CONS( 1989, snessfx,  snes,   0,      snessfx,  snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System / Super Famicom (NTSC, w/SuperFX)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
984CONS( 1991, snespsfx, snes,   0,      snespsfx, snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System (PAL, w/SuperFX)",  GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
985CONS( 1989, snesst10,  snes,   0,      snesst10,  snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System / Super Famicom (NTSC, w/ST-010)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
986CONS( 1989, snesst11,  snes,   0,      snesst11,  snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System / Super Famicom (NTSC, w/ST-011)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
987//CONS( 1989, snessa1,  snes,   0,      snessa1,  snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System / Super Famicom (NTSC, w/SA-1)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
988//CONS( 1991, snespsa1, snes,   0,      snespsa1, snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System (PAL, w/SA-1)",  GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
989
990// These would require cartslot to be added/removed depending on the cart which is loaded
991CONS( 1989, snesst,   snes,   0,      snesst,  snes,  snesst,       "Nintendo", "Super Nintendo Entertainment System / Super Famicom (NTSC, w/Sufami Turbo)", GAME_NOT_WORKING )
992CONS( 1989, snesbsx,  snes,   0,      snesbsx, snes,  snes_mess,    "Nintendo", "Super Nintendo Entertainment System / Super Famicom (NTSC, w/BS-X Satellaview slotted cart)",  GAME_NOT_WORKING )
src/mess/drivers/a310.c
r11460r11461
1/******************************************************************************
2 *
3 *  Acorn Archimedes 310
4 *
5 *  Skeleton: Juergen Buchmueller <pullmoll@t-online.de>, Jul 2000
6 *  Enhanced: R. Belmont, June 2007
7 *  Angelo Salese, August 2010
8 *
9 *  TODO:
10 *  - try to understand why bios 2 was working at some point and now isn't
11 *  - fix RISC OS / Arthur booting, possible causes:
12 *  \- missing reset page size hook-up
13 *  \- some subtle memory paging fault
14 *  \- missing RAM max size
15 *  \- ARM bug?
16 *
17 *
18=======================================================================================
19 *
20 *      Memory map (from http://b-em.bbcmicro.com/arculator/archdocs.txt)
21 *
22 *  0000000 - 1FFFFFF - logical RAM (32 meg)
23 *  2000000 - 2FFFFFF - physical RAM (supervisor only - max 16MB - requires quad MEMCs)
24 *  3000000 - 33FFFFF - IOC (IO controllers - supervisor only)
25 *  3310000 - FDC - WD1772
26 *  33A0000 - Econet - 6854
27 *  33B0000 - Serial - 6551
28 *  3240000 - 33FFFFF - internal expansion cards
29 *  32D0000 - hard disc controller (not IDE) - HD63463
30 *  3350010 - printer
31 *  3350018 - latch A
32 *  3350040 - latch B
33 *  3270000 - external expansion cards
34 *
35 *  3400000 - 3FFFFFF - ROM (read - 12 meg - Arthur and RiscOS 2 512k, RiscOS 3 2MB)
36 *  3400000 - 37FFFFF - Low ROM  (4 meg, I think this is expansion ROMs)
37 *  3800000 - 3FFFFFF - High ROM (main OS ROM)
38 *
39 *  3400000 - 35FFFFF - VICD10 (write - supervisor only)
40 *  3600000 - 3FFFFFF - MEMC (write - supervisor only)
41 *
42 *****************************************************************************/
43/*
44    DASM of code (bios 2 / RISC OS 2)
45    0x380d4e0: MEMC: control to 0x10c (page size 32 kbytes, DRAM ram refresh only during flyback)
46    0x380d4f0: VIDC: params (screen + sound frequency)
47    0x380d51c: IOC: sets control to 0xff, clear IRQA and FIQ masks, sets IRQB mask to 0x80 (keyboard receive full irq)
48    0x380d530: IOC: sets timer 0 to 0x4e20, go command
49        0x380e0a8: work RAM physical check, max size etc.
50    0x380e1f8: IOC: Disables DRAM ram refresh, sets timer 1 to 0x7ffe, go command, then it tests the latch of this timer, enables DRAM refresh
51        0x380d00c: Set up default logical space
52        0x380d16c: Set up case by case logical space
53
54
55*/
56
57
58#include "emu.h"
59#include "machine/wd17xx.h"
60#include "imagedev/flopdrv.h"
61#include "cpu/arm/arm.h"
62#include "sound/dac.h"
63#include "includes/archimds.h"
64#include "machine/i2cmem.h"
65#include "machine/ram.h"
66
67
68class a310_state : public driver_device
69{
70public:
71   a310_state(const machine_config &mconfig, device_type type, const char *tag)
72      : driver_device(mconfig, type, tag) { }
73
74};
75
76
77static WRITE_LINE_DEVICE_HANDLER( a310_wd177x_intrq_w )
78{
79   if (state)
80      archimedes_request_fiq(device->machine(), ARCHIMEDES_FIQ_FLOPPY);
81   else
82      archimedes_clear_fiq(device->machine(), ARCHIMEDES_FIQ_FLOPPY);
83}
84
85static WRITE_LINE_DEVICE_HANDLER( a310_wd177x_drq_w )
86{
87   if (state)
88      archimedes_request_fiq(device->machine(), ARCHIMEDES_FIQ_FLOPPY_DRQ);
89   else
90      archimedes_clear_fiq(device->machine(), ARCHIMEDES_FIQ_FLOPPY_DRQ);
91}
92
93static READ32_HANDLER( a310_psy_wram_r )
94{
95   return archimedes_memc_physmem[offset];
96}
97
98static WRITE32_HANDLER( a310_psy_wram_w )
99{
100   COMBINE_DATA(&archimedes_memc_physmem[offset]);
101}
102
103
104static DRIVER_INIT(a310)
105{
106   UINT32 ram_size = ram_get_size(machine.device(RAM_TAG));
107
108   archimedes_memc_physmem = auto_alloc_array(machine, UINT32, 0x01000000);
109
110   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_readwrite_handler( 0x02000000, 0x02000000+(ram_size-1), FUNC(a310_psy_wram_r), FUNC(a310_psy_wram_w) );
111
112   archimedes_driver_init(machine);
113}
114
115static MACHINE_START( a310 )
116{
117   archimedes_init(machine);
118
119   // reset the DAC to centerline
120   //dac_signed_data_w(machine.device("dac"), 0x80);
121}
122
123static MACHINE_RESET( a310 )
124{
125   archimedes_reset(machine);
126}
127
128static ADDRESS_MAP_START( a310_mem, AS_PROGRAM, 32 )
129   AM_RANGE(0x00000000, 0x01ffffff) AM_READWRITE(archimedes_memc_logical_r, archimedes_memc_logical_w)
130//  AM_RANGE(0x02000000, 0x02ffffff) AM_RAM AM_BASE(&archimedes_memc_physmem) /* physical RAM - 16 MB for now, should be 512k for the A310 */
131   AM_RANGE(0x03000000, 0x033fffff) AM_READWRITE(archimedes_ioc_r, archimedes_ioc_w)
132   AM_RANGE(0x03400000, 0x035fffff) AM_READWRITE(archimedes_vidc_r, archimedes_vidc_w)
133   AM_RANGE(0x03600000, 0x037fffff) AM_READWRITE(archimedes_memc_r, archimedes_memc_w)
134   AM_RANGE(0x03800000, 0x03ffffff) AM_ROM AM_REGION("maincpu", 0) AM_WRITE(archimedes_memc_page_w)
135ADDRESS_MAP_END
136
137
138static INPUT_PORTS_START( a310 )
139   PORT_START("dip") /* DIP switches */
140   PORT_BIT(0xfd, 0xfd, IPT_UNUSED)
141
142   PORT_START("key0") /* KEY ROW 0 */
143   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("ESC") PORT_CODE(KEYCODE_ESC)
144   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("1  !") PORT_CODE(KEYCODE_1)
145   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("2  \"") PORT_CODE(KEYCODE_2)
146   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("3  #") PORT_CODE(KEYCODE_3)
147   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("4  $") PORT_CODE(KEYCODE_4)
148   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME("5  %") PORT_CODE(KEYCODE_5)
149   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("6  &") PORT_CODE(KEYCODE_6)
150   PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("7  '") PORT_CODE(KEYCODE_7)
151
152   PORT_START("key1") /* KEY ROW 1 */
153   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("8  *") PORT_CODE(KEYCODE_8)
154   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("9  (") PORT_CODE(KEYCODE_9)
155   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("0  )") PORT_CODE(KEYCODE_0)
156   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("-  _") PORT_CODE(KEYCODE_MINUS)
157   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("=  +") PORT_CODE(KEYCODE_EQUALS)
158   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME("`  ~") PORT_CODE(KEYCODE_TILDE)
159   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("BACK SPACE") PORT_CODE(KEYCODE_BACKSPACE)
160   PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("TAB") PORT_CODE(KEYCODE_TAB)
161
162   PORT_START("key2") /* KEY ROW 2 */
163   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("q  Q") PORT_CODE(KEYCODE_Q)
164   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("w  W") PORT_CODE(KEYCODE_W)
165   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("e  E") PORT_CODE(KEYCODE_E)
166   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("r  R") PORT_CODE(KEYCODE_R)
167   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("t  T") PORT_CODE(KEYCODE_T)
168   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME("y  Y") PORT_CODE(KEYCODE_Y)
169   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("u  U") PORT_CODE(KEYCODE_U)
170   PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("i  I") PORT_CODE(KEYCODE_I)
171
172   PORT_START("key3") /* KEY ROW 3 */
173   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("o  O") PORT_CODE(KEYCODE_O)
174   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("p  P") PORT_CODE(KEYCODE_P)
175   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("[  {") PORT_CODE(KEYCODE_OPENBRACE)
176   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("]  }") PORT_CODE(KEYCODE_CLOSEBRACE)
177   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("RETURN") PORT_CODE(KEYCODE_ENTER)
178   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME("DEL") PORT_CODE(KEYCODE_DEL)
179   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("CTRL") PORT_CODE(KEYCODE_LCONTROL)
180   PORT_BIT(0x80, 0x80, IPT_KEYBOARD) PORT_NAME("CAPS LOCK") PORT_CODE(KEYCODE_CAPSLOCK) PORT_TOGGLE
181
182   PORT_START("key4") /* KEY ROW 4 */
183   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("a  A") PORT_CODE(KEYCODE_A)
184   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("s  S") PORT_CODE(KEYCODE_S)
185   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("d  D") PORT_CODE(KEYCODE_D)
186   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("f  F") PORT_CODE(KEYCODE_F)
187   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("g  G") PORT_CODE(KEYCODE_G)
188   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME("h  H") PORT_CODE(KEYCODE_H)
189   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("j  J") PORT_CODE(KEYCODE_J)
190   PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("k  K") PORT_CODE(KEYCODE_K)
191
192   PORT_START("key5") /* KEY ROW 5 */
193   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("l  L") PORT_CODE(KEYCODE_L)
194   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME(";  :") PORT_CODE(KEYCODE_COLON)
195   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("'  \"") PORT_CODE(KEYCODE_QUOTE)
196   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("\\  |") PORT_CODE(KEYCODE_ASTERISK)
197   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("SHIFT (L)") PORT_CODE(KEYCODE_LSHIFT)
198   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME("z  Z") PORT_CODE(KEYCODE_Z)
199   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("x  X") PORT_CODE(KEYCODE_X)
200   PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("c  C") PORT_CODE(KEYCODE_C)
201
202   PORT_START("key6") /* KEY ROW 6 */
203   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("v  V") PORT_CODE(KEYCODE_V)
204   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("b  B") PORT_CODE(KEYCODE_B)
205   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("n  N") PORT_CODE(KEYCODE_N)
206   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("m  M") PORT_CODE(KEYCODE_M)
207   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME(",  <") PORT_CODE(KEYCODE_COMMA)
208   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME(".  >") PORT_CODE(KEYCODE_STOP)
209   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("/  ?") PORT_CODE(KEYCODE_SLASH)
210   PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("SHIFT (R)") PORT_CODE(KEYCODE_RSHIFT)
211
212   PORT_START("key7") /* KEY ROW 7 */
213   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("LINE FEED")
214   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("SPACE") PORT_CODE(KEYCODE_SPACE)
215   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("- (KP)") PORT_CODE(KEYCODE_MINUS_PAD)
216   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME(", (KP)") PORT_CODE(KEYCODE_PLUS_PAD)
217   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("ENTER (KP)") PORT_CODE(KEYCODE_ENTER_PAD)
218   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME(". (KP)") PORT_CODE(KEYCODE_DEL_PAD)
219   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("0 (KP)") PORT_CODE(KEYCODE_0_PAD)
220   PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("1 (KP)") PORT_CODE(KEYCODE_1_PAD)
221
222   PORT_START("key8") /* KEY ROW 8 */
223   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("2 (KP)") PORT_CODE(KEYCODE_2_PAD)
224   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("3 (KP)") PORT_CODE(KEYCODE_3_PAD)
225   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("4 (KP)") PORT_CODE(KEYCODE_4_PAD)
226   PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("5 (KP)") PORT_CODE(KEYCODE_5_PAD)
227   PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("6 (KP)") PORT_CODE(KEYCODE_6_PAD)
228   PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME("7 (KP)") PORT_CODE(KEYCODE_7_PAD)
229   PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("8 (KP)") PORT_CODE(KEYCODE_8_PAD)
230   PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("9 (KP)") PORT_CODE(KEYCODE_9_PAD)
231
232   PORT_START("via1a") /* VIA #1 PORT A */
233   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START) PORT_PLAYER(1)
234   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START) PORT_PLAYER(2)
235   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1                )
236   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON2                )
237   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT) PORT_4WAY
238   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_UP) PORT_4WAY
239   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT) PORT_4WAY
240   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN) PORT_4WAY
241
242   PORT_START("tape")/* tape control */
243   PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("TAPE STOP") PORT_CODE(KEYCODE_F5)
244   PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("TAPE PLAY") PORT_CODE(KEYCODE_F6)
245   PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("TAPE REW") PORT_CODE(KEYCODE_F7)
246   PORT_BIT (0xf8, 0x80, IPT_UNUSED)
247INPUT_PORTS_END
248
249static const wd17xx_interface a310_wd17xx_interface =
250{
251   DEVCB_NULL,
252   DEVCB_LINE(a310_wd177x_intrq_w),
253   DEVCB_LINE(a310_wd177x_drq_w),
254   {FLOPPY_0, FLOPPY_1, FLOPPY_2, FLOPPY_3}
255};
256
257static const i2cmem_interface i2cmem_interface =
258{
259   I2CMEM_SLAVE_ADDRESS, 0, 0x100
260};
261
262static MACHINE_CONFIG_START( a310, a310_state )
263   /* basic machine hardware */
264   MCFG_CPU_ADD("maincpu", ARM, 8000000)        /* 8 MHz */
265   MCFG_CPU_PROGRAM_MAP(a310_mem)
266
267   MCFG_MACHINE_START( a310 )
268   MCFG_MACHINE_RESET( a310 )
269
270   MCFG_I2CMEM_ADD("i2cmem",i2cmem_interface)
271
272   /* video hardware */
273   MCFG_SCREEN_ADD("screen", RASTER)
274   MCFG_SCREEN_REFRESH_RATE(60)
275   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
276   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
277   MCFG_SCREEN_SIZE(1280, 1024) //TODO: default screen size
278   MCFG_SCREEN_VISIBLE_AREA(0*8, 1280 - 1, 0*16, 1024 - 1)
279   MCFG_SCREEN_UPDATE(archimds_vidc)
280
281   MCFG_PALETTE_LENGTH(32768)
282
283   MCFG_VIDEO_START(archimds_vidc)
284
285   MCFG_RAM_ADD(RAM_TAG)
286   MCFG_RAM_DEFAULT_SIZE("2M")
287   MCFG_RAM_EXTRA_OPTIONS("512K, 1M, 4M, 8M, 16M")
288
289   MCFG_WD1772_ADD("wd1772", a310_wd17xx_interface )
290
291   //MCFG_FLOPPY_4_DRIVES_ADD(a310_floppy_config)
292
293   MCFG_SPEAKER_STANDARD_MONO("mono")
294   MCFG_SOUND_ADD("dac0", DAC, 0)
295   MCFG_SOUND_ROUTE(0, "mono", 0.10)
296
297   MCFG_SOUND_ADD("dac1", DAC, 0)
298   MCFG_SOUND_ROUTE(0, "mono", 0.10)
299
300   MCFG_SOUND_ADD("dac2", DAC, 0)
301   MCFG_SOUND_ROUTE(0, "mono", 0.10)
302
303   MCFG_SOUND_ADD("dac3", DAC, 0)
304   MCFG_SOUND_ROUTE(0, "mono", 0.10)
305
306   MCFG_SOUND_ADD("dac4", DAC, 0)
307   MCFG_SOUND_ROUTE(0, "mono", 0.10)
308
309   MCFG_SOUND_ADD("dac5", DAC, 0)
310   MCFG_SOUND_ROUTE(0, "mono", 0.10)
311
312   MCFG_SOUND_ADD("dac6", DAC, 0)
313   MCFG_SOUND_ROUTE(0, "mono", 0.10)
314
315   MCFG_SOUND_ADD("dac7", DAC, 0)
316   MCFG_SOUND_ROUTE(0, "mono", 0.10)
317MACHINE_CONFIG_END
318
319ROM_START(a310)
320   ROM_REGION( 0x800000, "maincpu", 0 )
321   ROM_SYSTEM_BIOS( 0, "311", "RiscOS 3.11 (29 Sep 1992)" )
322   ROMX_LOAD( "ic24.rom", 0x000000, 0x80000, CRC(c1adde84) SHA1(12d060e0401dd0523d44453f947bdc55dd2c3240), ROM_BIOS(1) )
323   ROMX_LOAD( "ic25.rom", 0x080000, 0x80000, CRC(15d89664) SHA1(78f5d0e6f1e8ee603317807f53ff8fe65a3b3518), ROM_BIOS(1) )
324   ROMX_LOAD( "ic26.rom", 0x100000, 0x80000, CRC(a81ceb7c) SHA1(46b870876bc1f68f242726415f0c49fef7be0c72), ROM_BIOS(1) )
325   ROMX_LOAD( "ic27.rom", 0x180000, 0x80000, CRC(707b0c6c) SHA1(345199a33fed23996374b9db8170a52ab63f0380), ROM_BIOS(1) )
326   ROM_SYSTEM_BIOS( 1, "120", "Arthur/RiscOS 1.20 (25 Sep 1987)" )
327   ROMX_LOAD( "arthur.bin",   0x000000, 0x080000, CRC(eb3fda57) SHA1(1181ff9c2c2f3d6d414054ec33b2260404bafc81), ROM_BIOS(2) )
328   ROM_SYSTEM_BIOS( 2, "200", "RiscOS 2.0 (05 Oct 1988)" )
329   ROMX_LOAD( "riscos2.bin",  0x000000, 0x080000, CRC(89c4ad36) SHA1(b82a78830dac386f9b649b6d32a34f9c6910546d), ROM_BIOS(3) )
330
331   ROM_REGION( 0x200000, "vram", ROMREGION_ERASE00 )
332
333   ROM_REGION( 0x100, "i2cmem", ROMREGION_ERASE00 )
334ROM_END
335
336/*    YEAR  NAME  PARENT  COMPAT  MACHINE  INPUT  INIT   COMPANY  FULLNAME */
337COMP( 1988, a310, 0,      0,      a310,    a310,  a310,   "Acorn", "Archimedes 310", GAME_NOT_WORKING)
src/mess/drivers/pce.c
r11460r11461
1/****************************************************************************
2
3 PC-Engine / Turbo Grafx 16 driver
4 by Charles Mac Donald
5 E-Mail: cgfm2@hooked.net
6
7 Thanks to David Shadoff and Brian McPhail for help with the driver.
8
9****************************************************************************/
10
11/**********************************************************************
12          To-Do List:
13- convert h6280-based drivers to internal memory map for the I/O region
14- test sprite collision and overflow interrupts
15- sprite precaching
16- rewrite the base renderer loop
17- Add CD support
18- Add 6 button joystick support
19- Add 263 line mode
20- Sprite DMA should use vdc VRAM functions
21- properly implement the pixel clocks instead of the simple scaling we do now
22
23Banking
24=======
25
26Normally address spacebanks 00-F6 are assigned to regular HuCard ROM space. There
27are a couple of special situations:
28
29Street Fighter II:
30  - address space banks 40-7F switchable by writing to 1FF0-1FF3
31    1FF0 - select rom banks 40-7F
32    1FF1 - select rom banks 80-BF
33    1FF2 - select rom banks C0-FF
34    1FF3 - select rom banks 100-13F
35
36Populous:
37  - address space banks 40-43 contains 32KB RAM
38
39CDRom units:
40  - address space banks 80-87 contains 64KB RAM
41
42Super System Card:
43  - address space banks 68-7F contains 192KB RAM
44
45**********************************************************************/
46
47/**********************************************************************
48                          Known Bugs
49***********************************************************************
50- Benkei Gaiden: hangs after a few Sunsoft logo spins.
51- Busou Keiji Cyber Cross: hangs on attract mode
52- Cadash: After choosing character and name, the game starts and the display 'jiggles' like tracking if off a VCR
53- Fighting Run: has color and sprite issues during gameplay;
54- Hisou Kihei - Xserd: black screen;
55**********************************************************************/
56
57#include "emu.h"
58#include "deprecat.h"
59#include "video/vdc.h"
60#include "cpu/h6280/h6280.h"
61#include "includes/pce.h"
62#include "imagedev/cartslot.h"
63#include "imagedev/chd_cd.h"
64#include "sound/c6280.h"
65#include "sound/cdda.h"
66#include "sound/msm5205.h"
67#include "hash.h"
68
69
70static ADDRESS_MAP_START( pce_mem , AS_PROGRAM, 8)
71   AM_RANGE( 0x000000, 0x07FFFF) AM_ROMBANK("bank1")
72   AM_RANGE( 0x080000, 0x087FFF) AM_ROMBANK("bank2")
73   AM_RANGE( 0x088000, 0x0CFFFF) AM_ROMBANK("bank3")
74   AM_RANGE( 0x0D0000, 0x0FFFFF) AM_ROMBANK("bank4")
75   AM_RANGE( 0x100000, 0x10FFFF) AM_RAM AM_BASE_MEMBER( pce_state, m_cd_ram )
76   AM_RANGE( 0x110000, 0x1EDFFF) AM_NOP
77   AM_RANGE( 0x1EE000, 0x1EE7FF) AM_ROMBANK("bank10") AM_WRITE( pce_cd_bram_w )
78   AM_RANGE( 0x1EE800, 0x1EFFFF) AM_NOP
79   AM_RANGE( 0x1F0000, 0x1F1FFF) AM_RAM AM_MIRROR(0x6000) AM_BASE_MEMBER( pce_state, m_user_ram )
80   AM_RANGE( 0x1FE000, 0x1FE3FF) AM_READWRITE( vdc_0_r, vdc_0_w )
81   AM_RANGE( 0x1FE400, 0x1FE7FF) AM_READWRITE( vce_r, vce_w )
82   AM_RANGE( 0x1FE800, 0x1FEBFF) AM_DEVREADWRITE(C6280_TAG, c6280_r, c6280_w )
83   AM_RANGE( 0x1FEC00, 0x1FEFFF) AM_READWRITE( h6280_timer_r, h6280_timer_w )
84   AM_RANGE( 0x1FF000, 0x1FF3FF) AM_READWRITE( pce_joystick_r, pce_joystick_w )
85   AM_RANGE( 0x1FF400, 0x1FF7FF) AM_READWRITE( h6280_irq_status_r, h6280_irq_status_w )
86   AM_RANGE( 0x1FF800, 0x1FFBFF) AM_READWRITE( pce_cd_intf_r, pce_cd_intf_w )
87ADDRESS_MAP_END
88
89static ADDRESS_MAP_START( pce_io , AS_IO, 8)
90   AM_RANGE( 0x00, 0x03) AM_READWRITE( vdc_0_r, vdc_0_w )
91ADDRESS_MAP_END
92
93static ADDRESS_MAP_START( sgx_mem , AS_PROGRAM, 8)
94   AM_RANGE( 0x000000, 0x07FFFF) AM_ROMBANK("bank1")
95   AM_RANGE( 0x080000, 0x087FFF) AM_ROMBANK("bank2")
96   AM_RANGE( 0x088000, 0x0CFFFF) AM_ROMBANK("bank3")
97   AM_RANGE( 0x0D0000, 0x0FFFFF) AM_ROMBANK("bank4")
98   AM_RANGE( 0x100000, 0x10FFFF) AM_RAM AM_BASE_MEMBER( pce_state, m_cd_ram )
99   AM_RANGE( 0x110000, 0x1EDFFF) AM_NOP
100   AM_RANGE( 0x1EE000, 0x1EE7FF) AM_ROMBANK("bank10") AM_WRITE( pce_cd_bram_w )
101   AM_RANGE( 0x1EE800, 0x1EFFFF) AM_NOP
102   AM_RANGE( 0x1F0000, 0x1F7FFF) AM_RAM AM_BASE_MEMBER( pce_state, m_user_ram )
103   AM_RANGE( 0x1FE000, 0x1FE007) AM_READWRITE( vdc_0_r, vdc_0_w ) AM_MIRROR(0x03E0)
104   AM_RANGE( 0x1FE008, 0x1FE00F) AM_READWRITE( vpc_r, vpc_w ) AM_MIRROR(0x03E0)
105   AM_RANGE( 0x1FE010, 0x1FE017) AM_READWRITE( vdc_1_r, vdc_1_w ) AM_MIRROR(0x03E0)
106   AM_RANGE( 0x1FE400, 0x1FE7FF) AM_READWRITE( vce_r, vce_w )
107   AM_RANGE( 0x1FE800, 0x1FEBFF) AM_DEVREADWRITE(C6280_TAG, c6280_r, c6280_w )
108   AM_RANGE( 0x1FEC00, 0x1FEFFF) AM_READWRITE( h6280_timer_r, h6280_timer_w )
109   AM_RANGE( 0x1FF000, 0x1FF3FF) AM_READWRITE( pce_joystick_r, pce_joystick_w )
110   AM_RANGE( 0x1FF400, 0x1FF7FF) AM_READWRITE( h6280_irq_status_r, h6280_irq_status_w )
111   AM_RANGE( 0x1FF800, 0x1FFBFF) AM_READWRITE( pce_cd_intf_r, pce_cd_intf_w )
112ADDRESS_MAP_END
113
114static ADDRESS_MAP_START( sgx_io , AS_IO, 8)
115   AM_RANGE( 0x00, 0x03) AM_READWRITE( sgx_vdc_r, sgx_vdc_w )
116ADDRESS_MAP_END
117
118/* todo: alternate forms of input (multitap, mouse, etc.) */
119static INPUT_PORTS_START( pce )
120
121   PORT_START("JOY_P1")
122   /* II is left of I on the original pad so we map them in reverse order */
123   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P1 Button I") PORT_PLAYER(1) PORT_CATEGORY(10)
124   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P1 Button II") PORT_PLAYER(1) PORT_CATEGORY(10)
125   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P1 Select") PORT_PLAYER(1) PORT_CATEGORY(10)
126   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P1 Run") PORT_PLAYER(1) PORT_CATEGORY(10)
127   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1) PORT_CATEGORY(10)
128   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) PORT_CATEGORY(10)
129   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) PORT_CATEGORY(10)
130   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) PORT_CATEGORY(10)
131
132   PORT_START("JOY_P2")
133   /* II is left of I on the original pad so we map them in reverse order */
134   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P2 Button I") PORT_PLAYER(2) PORT_CATEGORY(20)
135   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P2 Button II") PORT_PLAYER(2) PORT_CATEGORY(20)
136   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P2 Select") PORT_PLAYER(2) PORT_CATEGORY(20)
137   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P2 Run") PORT_PLAYER(2) PORT_CATEGORY(20)
138   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2) PORT_CATEGORY(20)
139   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) PORT_CATEGORY(20)
140   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) PORT_CATEGORY(20)
141   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) PORT_CATEGORY(20)
142
143   PORT_START("JOY_P3")
144   /* II is left of I on the original pad so we map them in reverse order */
145   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P3 Button I") PORT_PLAYER(3) PORT_CATEGORY(30)
146   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P3 Button II") PORT_PLAYER(3) PORT_CATEGORY(30)
147   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P3 Select") PORT_PLAYER(3) PORT_CATEGORY(30)
148   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P3 Run") PORT_PLAYER(3) PORT_CATEGORY(30)
149   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(3) PORT_CATEGORY(30)
150   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(3) PORT_CATEGORY(30)
151   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(3) PORT_CATEGORY(30)
152   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(3) PORT_CATEGORY(30)
153
154   PORT_START("JOY_P4")
155   /* II is left of I on the original pad so we map them in reverse order */
156   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P4 Button I") PORT_PLAYER(4) PORT_CATEGORY(40)
157   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P4 Button II") PORT_PLAYER(4) PORT_CATEGORY(40)
158   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P4 Select") PORT_PLAYER(4) PORT_CATEGORY(40)
159   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P4 Run") PORT_PLAYER(4) PORT_CATEGORY(40)
160   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(4) PORT_CATEGORY(40)
161   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(4) PORT_CATEGORY(40)
162   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(4) PORT_CATEGORY(40)
163   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(4) PORT_CATEGORY(40)
164
165   PORT_START("JOY_P5")
166   /* II is left of I on the original pad so we map them in reverse order */
167   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P5 Button I") PORT_PLAYER(5) PORT_CATEGORY(50)
168   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P5 Button II") PORT_PLAYER(5) PORT_CATEGORY(50)
169   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P5 Select") PORT_PLAYER(5) PORT_CATEGORY(50)
170   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P5 Run") PORT_PLAYER(5) PORT_CATEGORY(50)
171   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(5) PORT_CATEGORY(50)
172   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(5) PORT_CATEGORY(50)
173   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(5) PORT_CATEGORY(50)
174   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(5) PORT_CATEGORY(50)
175
176   PORT_START("JOY6B_P1")
177   /* II is left of I on the original pad so we map them in reverse order */
178   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P1 Button I") PORT_PLAYER(1) PORT_CATEGORY(11)
179   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P1 Button II") PORT_PLAYER(1) PORT_CATEGORY(11)
180   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P1 Select") PORT_PLAYER(1) PORT_CATEGORY(11)
181   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P1 Run") PORT_PLAYER(1) PORT_CATEGORY(11)
182   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1) PORT_CATEGORY(11)
183   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) PORT_CATEGORY(11)
184   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) PORT_CATEGORY(11)
185   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) PORT_CATEGORY(11)
186   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P1 Button III") PORT_PLAYER(1) PORT_CATEGORY(11)
187   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("P1 Button IV") PORT_PLAYER(1) PORT_CATEGORY(11)
188   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("P1 Button V") PORT_PLAYER(1) PORT_CATEGORY(11)
189   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("P1 Button VI") PORT_PLAYER(1) PORT_CATEGORY(11)
190   PORT_BIT( 0xf000, IP_ACTIVE_HIGH,IPT_UNUSED ) //6-button pad header
191
192   PORT_START("JOY6B_P2")  /* Player 2 controls */
193   /* II is left of I on the original pad so we map them in reverse order */
194   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P2 Button I") PORT_PLAYER(2) PORT_CATEGORY(21)
195   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P2 Button II") PORT_PLAYER(2) PORT_CATEGORY(21)
196   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P2 Select") PORT_PLAYER(2) PORT_CATEGORY(21)
197   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P2 Run") PORT_PLAYER(2) PORT_CATEGORY(21)
198   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2) PORT_CATEGORY(21)
199   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) PORT_CATEGORY(21)
200   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) PORT_CATEGORY(21)
201   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) PORT_CATEGORY(21)
202   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P2 Button III") PORT_PLAYER(2) PORT_CATEGORY(21)
203   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("P2 Button IV") PORT_PLAYER(2) PORT_CATEGORY(21)
204   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("P2 Button V") PORT_PLAYER(2) PORT_CATEGORY(21)
205   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("P2 Button VI") PORT_PLAYER(2) PORT_CATEGORY(21)
206   PORT_BIT( 0xf000, IP_ACTIVE_HIGH,IPT_UNUSED ) //6-button pad header
207
208   PORT_START("JOY6B_P3")  /* Player 3 controls */
209   /* II is left of I on the original pad so we map them in reverse order */
210   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P3 Button I") PORT_PLAYER(3) PORT_CATEGORY(31)
211   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P3 Button II") PORT_PLAYER(3) PORT_CATEGORY(31)
212   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P3 Select") PORT_PLAYER(3) PORT_CATEGORY(31)
213   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P3 Run") PORT_PLAYER(3) PORT_CATEGORY(31)
214   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(3) PORT_CATEGORY(31)
215   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(3) PORT_CATEGORY(31)
216   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(3) PORT_CATEGORY(31)
217   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(3) PORT_CATEGORY(31)
218   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P3 Button III") PORT_PLAYER(3) PORT_CATEGORY(31)
219   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("P3 Button IV") PORT_PLAYER(3) PORT_CATEGORY(31)
220   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("P3 Button V") PORT_PLAYER(3) PORT_CATEGORY(31)
221   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("P3 Button VI") PORT_PLAYER(3) PORT_CATEGORY(31)
222   PORT_BIT( 0xf000, IP_ACTIVE_HIGH,IPT_UNUSED ) //6-button pad header
223
224   PORT_START("JOY6B_P4")  /* Player 4 controls */
225   /* II is left of I on the original pad so we map them in reverse order */
226   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P4 Button I") PORT_PLAYER(4) PORT_CATEGORY(41)
227   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P4 Button II") PORT_PLAYER(4) PORT_CATEGORY(41)
228   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P4 Select") PORT_PLAYER(4) PORT_CATEGORY(41)
229   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P4 Run") PORT_PLAYER(4) PORT_CATEGORY(41)
230   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(4) PORT_CATEGORY(41)
231   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(4) PORT_CATEGORY(41)
232   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(4) PORT_CATEGORY(41)
233   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(4) PORT_CATEGORY(41)
234   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P3 Button III") PORT_PLAYER(4) PORT_CATEGORY(41)
235   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("P3 Button IV") PORT_PLAYER(4) PORT_CATEGORY(41)
236   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("P3 Button V") PORT_PLAYER(4) PORT_CATEGORY(41)
237   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("P3 Button VI") PORT_PLAYER(4) PORT_CATEGORY(41)
238   PORT_BIT( 0xf000, IP_ACTIVE_HIGH,IPT_UNUSED ) //6-button pad header
239
240   PORT_START("JOY6B_P5")  /* Player 5 controls */
241   /* II is left of I on the original pad so we map them in reverse order */
242   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P5 Button I") PORT_PLAYER(5) PORT_CATEGORY(51)
243   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P5 Button II") PORT_PLAYER(5) PORT_CATEGORY(51)
244   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_SELECT  ) PORT_NAME("P5 Select") PORT_PLAYER(5) PORT_CATEGORY(51)
245   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_START   ) PORT_NAME("P5 Run") PORT_PLAYER(5) PORT_CATEGORY(51)
246   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(5) PORT_CATEGORY(51)
247   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(5) PORT_CATEGORY(51)
248   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(5) PORT_CATEGORY(51)
249   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(5) PORT_CATEGORY(51)
250   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P5 Button III") PORT_PLAYER(5) PORT_CATEGORY(51)
251   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("P5 Button IV") PORT_PLAYER(5) PORT_CATEGORY(51)
252   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("P5 Button V") PORT_PLAYER(5) PORT_CATEGORY(51)
253   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("P5 Button VI") PORT_PLAYER(5) PORT_CATEGORY(51)
254   PORT_BIT( 0xf000, IP_ACTIVE_HIGH,IPT_UNUSED ) //6-button pad header
255
256   PORT_START("JOY_TYPE")
257   PORT_CATEGORY_CLASS(0x0003,0x0000,"Joystick Type Player 1")
258   PORT_CATEGORY_ITEM( 0x0000,"2-buttons", 10)
259//  PORT_CATEGORY_ITEM( 0x0001,"3-buttons", xx)
260   PORT_CATEGORY_ITEM( 0x0002,"6-buttons", 11)
261//  PORT_CATEGORY_ITEM( 0x0003,"Mouse",     xx)
262   PORT_CATEGORY_CLASS(0x000c,0x0000,"Joystick Type Player 2")
263   PORT_CATEGORY_ITEM( 0x0000,"2-buttons", 20)
264//  PORT_CATEGORY_ITEM( 0x0004,"3-buttons", xx)
265   PORT_CATEGORY_ITEM( 0x0008,"6-buttons", 21)
266//  PORT_CATEGORY_ITEM( 0x000c,"Mouse",     xx)
267   PORT_CATEGORY_CLASS(0x0030,0x0000,"Joystick Type Player 3")
268   PORT_CATEGORY_ITEM( 0x0000,"2-buttons", 30)
269//  PORT_CATEGORY_ITEM( 0x0010,"3-buttons", xx)
270   PORT_CATEGORY_ITEM( 0x0020,"6-buttons", 31)
271//  PORT_CATEGORY_ITEM( 0x0030,"Mouse",     xx)
272   PORT_CATEGORY_CLASS(0x00c0,0x0000,"Joystick Type Player 4")
273   PORT_CATEGORY_ITEM( 0x0000,"2-buttons", 40)
274//  PORT_CATEGORY_ITEM( 0x0040,"3-buttons", xx)
275   PORT_CATEGORY_ITEM( 0x0080,"6-buttons", 41)
276//  PORT_CATEGORY_ITEM( 0x00c0,"Mouse",     xx)
277   PORT_CATEGORY_CLASS(0x0300,0x0000,"Joystick Type Player 5")
278   PORT_CATEGORY_ITEM( 0x0000,"2-buttons", 50)
279//  PORT_CATEGORY_ITEM( 0x0100,"3-buttons", xx)
280   PORT_CATEGORY_ITEM( 0x0200,"6-buttons", 51)
281//  PORT_CATEGORY_ITEM( 0x0300,"Mouse",     xx)
282
283   PORT_START("A_CARD")
284   PORT_CONFNAME( 0x01, 0x01, "Arcade Card" )
285   PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
286   PORT_CONFSETTING(    0x01, DEF_STR( On ) )
287INPUT_PORTS_END
288
289
290static void pce_partialhash(hash_collection &dest, const unsigned char *data,
291   unsigned long length, const char *functions)
292{
293   if ( ( length <= PCE_HEADER_SIZE ) || ( length & PCE_HEADER_SIZE ) ) {
294         dest.compute(&data[PCE_HEADER_SIZE], length - PCE_HEADER_SIZE, functions);
295   } else {
296      dest.compute(data, length, functions);
297   }
298}
299
300static const c6280_interface c6280_config =
301{
302   "maincpu"
303};
304static MACHINE_CONFIG_FRAGMENT( pce_cdslot )
305   MCFG_CDROM_ADD( "cdrom" )
306   MCFG_CDROM_INTERFACE("pce_cdrom")
307
308   MCFG_SOFTWARE_LIST_ADD("cd_list","pcecd")
309MACHINE_CONFIG_END
310
311static MACHINE_CONFIG_FRAGMENT( pce_cartslot )
312   MCFG_CARTSLOT_ADD("cart")
313   MCFG_CARTSLOT_EXTENSION_LIST("pce,bin")
314   MCFG_CARTSLOT_MANDATORY
315   MCFG_CARTSLOT_INTERFACE("pce_cart")
316   MCFG_CARTSLOT_LOAD(pce_cart)
317   MCFG_CARTSLOT_PARTIALHASH(pce_partialhash)
318   MCFG_SOFTWARE_LIST_ADD("cart_list","pce")
319MACHINE_CONFIG_END
320
321static MACHINE_CONFIG_FRAGMENT( tg16_cartslot )
322   MCFG_CARTSLOT_ADD("cart")
323   MCFG_CARTSLOT_EXTENSION_LIST("pce,bin")
324   MCFG_CARTSLOT_MANDATORY
325   MCFG_CARTSLOT_INTERFACE("tg16_cart")
326   MCFG_CARTSLOT_LOAD(pce_cart)
327   MCFG_CARTSLOT_PARTIALHASH(pce_partialhash)
328   MCFG_SOFTWARE_LIST_ADD("cart_list","tg16")
329MACHINE_CONFIG_END
330
331static MACHINE_CONFIG_FRAGMENT( sgx_cartslot )
332   MCFG_CARTSLOT_ADD("cart")
333   MCFG_CARTSLOT_EXTENSION_LIST("pce,bin")
334   MCFG_CARTSLOT_MANDATORY
335   MCFG_CARTSLOT_INTERFACE("pce_cart")
336   MCFG_CARTSLOT_LOAD(pce_cart)
337   MCFG_CARTSLOT_PARTIALHASH(pce_partialhash)
338   MCFG_SOFTWARE_LIST_ADD("cart_list","sgx")
339MACHINE_CONFIG_END
340
341static MACHINE_CONFIG_START( pce_common, pce_state )
342   /* basic machine hardware */
343   MCFG_CPU_ADD("maincpu", H6280, MAIN_CLOCK/3)
344   MCFG_CPU_PROGRAM_MAP(pce_mem)
345   MCFG_CPU_IO_MAP(pce_io)
346   MCFG_CPU_VBLANK_INT_HACK(pce_interrupt, VDC_LPF)
347   MCFG_QUANTUM_TIME(attotime::from_hz(60))
348
349   MCFG_MACHINE_START( pce )
350   MCFG_MACHINE_RESET( pce )
351
352    /* video hardware */
353   MCFG_SCREEN_ADD("screen", RASTER)
354   MCFG_SCREEN_REFRESH_RATE(60)
355   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
356   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
357   MCFG_SCREEN_RAW_PARAMS(MAIN_CLOCK/2, VDC_WPF, 70, 70 + 512 + 32, VDC_LPF, 14, 14+242)
358   MCFG_SCREEN_UPDATE( pce )
359
360   /* MCFG_GFXDECODE( pce ) */
361   MCFG_PALETTE_LENGTH(1024)
362   MCFG_PALETTE_INIT( vce )
363
364   MCFG_VIDEO_START( pce )
365
366   MCFG_NVRAM_HANDLER( pce )
367   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
368   MCFG_SOUND_ADD(C6280_TAG, C6280, MAIN_CLOCK/6)
369   MCFG_SOUND_CONFIG(c6280_config)
370   MCFG_SOUND_ROUTE( 0, "lspeaker", 1.00 )
371   MCFG_SOUND_ROUTE( 1, "rspeaker", 1.00 )
372
373   MCFG_SOUND_ADD( "msm5205", MSM5205, PCE_CD_CLOCK / 6 )
374   MCFG_SOUND_CONFIG( pce_cd_msm5205_interface )
375   MCFG_SOUND_ROUTE( ALL_OUTPUTS, "lspeaker", 0.50 )
376   MCFG_SOUND_ROUTE( ALL_OUTPUTS, "rspeaker", 0.50 )
377
378   MCFG_SOUND_ADD( "cdda", CDDA, 0 )
379   MCFG_SOUND_ROUTE( 0, "lspeaker", 1.00 )
380   MCFG_SOUND_ROUTE( 1, "rspeaker", 1.00 )
381MACHINE_CONFIG_END
382
383static MACHINE_CONFIG_DERIVED( pce, pce_common )
384   MCFG_FRAGMENT_ADD( pce_cartslot )
385   MCFG_FRAGMENT_ADD( pce_cdslot )
386MACHINE_CONFIG_END
387
388static MACHINE_CONFIG_DERIVED( tg16, pce_common )
389   MCFG_FRAGMENT_ADD( tg16_cartslot )
390   MCFG_FRAGMENT_ADD( pce_cdslot )
391MACHINE_CONFIG_END
392
393static MACHINE_CONFIG_START( sgx, pce_state )
394   /* basic machine hardware */
395   MCFG_CPU_ADD("maincpu", H6280, MAIN_CLOCK/3)
396   MCFG_CPU_PROGRAM_MAP(sgx_mem)
397   MCFG_CPU_IO_MAP(sgx_io)
398   MCFG_CPU_VBLANK_INT_HACK(sgx_interrupt, VDC_LPF)
399   MCFG_QUANTUM_TIME(attotime::from_hz(60))
400
401   MCFG_MACHINE_START( pce )
402   MCFG_MACHINE_RESET( pce )
403
404   /* video hardware */
405   MCFG_SCREEN_ADD("screen", RASTER)
406   MCFG_SCREEN_REFRESH_RATE(60)
407   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
408   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
409   MCFG_SCREEN_RAW_PARAMS(MAIN_CLOCK/2, VDC_WPF, 70, 70 + 512 + 32, VDC_LPF, 14, 14+242)
410   MCFG_SCREEN_UPDATE( pce )
411
412   MCFG_PALETTE_LENGTH(1024)
413   MCFG_PALETTE_INIT( vce )
414
415   MCFG_VIDEO_START( pce )
416
417   MCFG_NVRAM_HANDLER( pce )
418   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
419   MCFG_SOUND_ADD(C6280_TAG, C6280, MAIN_CLOCK/6)
420   MCFG_SOUND_CONFIG(c6280_config)
421   MCFG_SOUND_ROUTE(0, "lspeaker", 1.00)
422   MCFG_SOUND_ROUTE(1, "rspeaker", 1.00)
423
424   MCFG_SOUND_ADD( "msm5205", MSM5205, PCE_CD_CLOCK / 6 )
425   MCFG_SOUND_CONFIG( pce_cd_msm5205_interface )
426   MCFG_SOUND_ROUTE( ALL_OUTPUTS, "lspeaker", 0.00 )
427   MCFG_SOUND_ROUTE( ALL_OUTPUTS, "rspeaker", 0.00 )
428
429   MCFG_SOUND_ADD( "cdda", CDDA, 0 )
430   MCFG_SOUND_ROUTE( 0, "lspeaker", 1.00 )
431   MCFG_SOUND_ROUTE( 1, "rspeaker", 1.00 )
432
433   MCFG_FRAGMENT_ADD( sgx_cartslot )
434   MCFG_FRAGMENT_ADD( pce_cdslot )
435MACHINE_CONFIG_END
436
437/***************************************************************************
438
439  Game driver(s)
440
441***************************************************************************/
442
443ROM_START( pce )
444   ROM_REGION( PCE_ROM_MAXSIZE, "user1", 0 )      /* Cartridge ROM area */
445   ROM_FILL( 0, PCE_ROM_MAXSIZE, 0xFF )
446ROM_END
447
448#define rom_tg16 rom_pce
449#define rom_sgx rom_pce
450
451/*    YEAR  NAME    PARENT  COMPAT  MACHINE INPUT    INIT   COMPANY  FULLNAME */
452CONS( 1987, pce,    0,      0,      pce,    pce,     pce,   "Nippon Electronic Company", "PC Engine", GAME_IMPERFECT_SOUND)
453CONS( 1989, tg16,   pce,    0,      tg16,   pce,     tg16,  "Nippon Electronic Company", "TurboGrafx 16", GAME_IMPERFECT_SOUND)
454CONS( 1989, sgx,    pce,    0,      sgx,    pce,     sgx,   "Nippon Electronic Company", "SuperGrafx", GAME_IMPERFECT_SOUND)
src/mess/mess.mak
r11460r11461
261261DRVLIBS += \
262262   $(MESSOBJ)/acorn.a \
263263   $(MESSOBJ)/act.a \
264   $(MESSOBJ)/amiga.a \
265264   $(MESSOBJ)/amstrad.a \
266265   $(MESSOBJ)/apf.a \
267266   $(MESSOBJ)/apple.a \
268267   $(MESSOBJ)/applied.a \
269268   $(MESSOBJ)/arcadia.a \
270   $(MESSOBJ)/ascii.a \
271269   $(MESSOBJ)/at.a \
272270   $(MESSOBJ)/atari.a \
273271   $(MESSOBJ)/att.a \
274   $(MESSOBJ)/bally.a \
275272   $(MESSOBJ)/bandai.a \
276273   $(MESSOBJ)/be.a \
277274   $(MESSOBJ)/bnpo.a \
r11460r11461
502499   $(MAME_DRIVERS)/dc.o       \
503500   $(MAME_MACHINE)/dccons.o    \
504501   $(MAME_MACHINE)/gdrom.o    \
502   $(MAME_DRIVERS)/a310.o      \
503   $(MAME_DRIVERS)/a7000.o      \
504   $(MAME_MACHINE)/amigafdc.o   \
505   $(MAME_MACHINE)/amigacrt.o   \
506   $(MAME_MACHINE)/amigacd.o   \
507   $(MAME_MACHINE)/amigakbd.o   \
508   $(MAME_DRIVERS)/amiga.o      \
509   $(MAME_DRIVERS)/a3000.o      \
510   $(MAME_DRIVERS)/ami1200.o   \
511   $(MAME_DRIVERS)/msx.o      \
512   $(MAME_MACHINE)/msx_slot.o   \
513   $(MAME_MACHINE)/msx.o      \
514   $(MAME_MACHINE)/ataricrt.o   \
515   $(MAME_MACHINE)/atarifdc.o   \
516   $(MAME_DRIVERS)/atari400.o   \
517   $(MAME_DRIVERS)/astrocdh.o   \
518   $(MAME_MACHINE)/pce.o      \
519   $(MAME_DRIVERS)/pce.o      \
520   $(MAME_MACHINE)/nes_mmc.o   \
521   $(MAME_VIDEO)/nes.o         \
522   $(MAME_MACHINE)/nes.o      \
523   $(MAME_DRIVERS)/nes.o      \
524   $(MAME_MACHINE)/snescart.o   \
525   $(MAME_DRIVERS)/snes.o      \
526   $(MAME_DRIVERS)/n64.o      \
527   $(MAME_MACHINE)/aescart.o   \
528   $(MAME_DRIVERS)/ng_aes.o   \
529   $(MAME_DRIVERS)/psx.o      \
530   $(MAME_MACHINE)/psxcd.o      \
531   $(MAME_MACHINE)/psxcddrv.o   \
532   $(MAME_MACHINE)/psxcard.o   \
505533
506534#-------------------------------------------------
507535# the following files are general components and
r11460r11461
545573   $(MESS_MACHINE)/terminal.o   \
546574   $(MESS_MACHINE)/teleprinter.o   \
547575   $(MESS_MACHINE)/upd7002.o   \
548   $(MESS_MACHINE)/wd17xx.o   \
549576   $(MESS_VIDEO)/crtc6845.o   \
550577   $(MESS_VIDEO)/dl1416.o      \
551578   $(MESS_VIDEO)/hd44780.o      \
r11460r11461
566593#-------------------------------------------------
567594
568595$(MESSOBJ)/acorn.a:            \
569   $(MESS_DRIVERS)/a310.o      \
570596   $(MESS_DRIVERS)/a6809.o      \
571   $(MESS_DRIVERS)/a7000.o      \
572597   $(MESS_DRIVERS)/acrnsys1.o   \
573598   $(MESS_DRIVERS)/atom.o      \
574599   $(MESS_FORMATS)/atom_atm.o   \
r11460r11461
588613   $(MESS_DRIVERS)/apricotf.o   \
589614   $(MESS_DRIVERS)/victor9k.o   \
590615
591$(MESSOBJ)/amiga.a:            \
592   $(MESS_MACHINE)/amigafdc.o   \
593   $(MESS_MACHINE)/amigacrt.o   \
594   $(MESS_MACHINE)/amigacd.o   \
595   $(MESS_MACHINE)/matsucd.o   \
596   $(MESS_MACHINE)/amigakbd.o   \
597   $(MESS_DRIVERS)/amiga.o      \
598   $(MESS_DRIVERS)/a3000.o      \
599   $(MESS_DRIVERS)/ami1200.o   \
600
601616$(MESSOBJ)/amstrad.a:         \
602617   $(MESS_DRIVERS)/amstrad.o   \
603618   $(MESS_MACHINE)/amstrad.o   \
r11460r11461
648663   $(MESS_AUDIO)/arcadia.o      \
649664   $(MESS_VIDEO)/arcadia.o      \
650665
651$(MESSOBJ)/ascii.a:            \
652   $(MESS_DRIVERS)/msx.o      \
653   $(MESS_MACHINE)/msx_slot.o   \
654   $(MESS_MACHINE)/msx.o      \
655
656666$(MESSOBJ)/at.a:            \
657667   $(MESS_MACHINE)/at_keybc.o   \
658668   $(MESS_MACHINE)/ps2.o      \
r11460r11461
661671   $(MESS_DRIVERS)/at.o      \
662672
663673$(MESSOBJ)/atari.a:            \
664   $(MESS_MACHINE)/ataricrt.o   \
665   $(MESS_MACHINE)/atarifdc.o   \
666   $(MESS_DRIVERS)/atari.o      \
667674   $(MESS_MACHINE)/a7800.o      \
668675   $(MESS_DRIVERS)/a7800.o      \
669676   $(MESS_VIDEO)/a7800.o      \
r11460r11461
679686$(MESSOBJ)/att.a:            \
680687   $(MESS_DRIVERS)/unixpc.o   \
681688
682$(MESSOBJ)/bally.a:            \
683   $(MESS_DRIVERS)/astrocde.o   \
684
685689$(MESSOBJ)/bandai.a:         \
686690   $(MESS_DRIVERS)/pippin.o   \
687691   $(MESS_DRIVERS)/rx78.o      \
r11460r11461
758762   $(MESS_MACHINE)/c8280.o      \
759763   $(MESS_MACHINE)/c9060.o      \
760764   $(MESS_DRIVERS)/clcd.o      \
761   $(MESS_MACHINE)/6525tpi.o   \
762765   $(MESS_MACHINE)/cbm.o      \
763766   $(MESS_MACHINE)/cbmipt.o   \
764767   $(MESS_MACHINE)/c64.o      \
r11460r11461
11471150   $(MESS_MACHINE)/z80ne.o     \
11481151
11491152$(MESSOBJ)/nec.a:            \
1150   $(MESS_MACHINE)/pce.o      \
1151   $(MESS_DRIVERS)/pce.o      \
11521153   $(MESS_DRIVERS)/pcfx.o      \
11531154   $(MESS_DRIVERS)/pc6001.o   \
11541155   $(MESS_DRIVERS)/pc8401a.o   \
r11460r11461
11711172   $(MESS_VIDEO)/gb.o         \
11721173   $(MESS_MACHINE)/gb.o      \
11731174   $(MESS_DRIVERS)/gb.o      \
1174   $(MESS_MACHINE)/nes_mmc.o   \
1175   $(MESS_VIDEO)/nes.o         \
1176   $(MESS_MACHINE)/nes.o      \
1177   $(MESS_DRIVERS)/nes.o      \
1178   $(MESS_MACHINE)/snescart.o   \
1179   $(MESS_DRIVERS)/snes.o      \
1180   $(MESS_DRIVERS)/n64.o      \
11811175   $(MESS_MACHINE)/pokemini.o   \
11821176   $(MESS_DRIVERS)/pokemini.o   \
11831177   $(MESS_DRIVERS)/vboy.o      \
r11460r11461
14101404$(MESSOBJ)/snk.a:            \
14111405   $(MESS_DRIVERS)/ngp.o      \
14121406   $(MESS_VIDEO)/k1ge.o      \
1413   $(MESS_DEVICES)/aescart.o   \
1414   $(MESS_DRIVERS)/ng_aes.o   \
14151407
14161408$(MESSOBJ)/sony.a:            \
1417   $(MESS_DRIVERS)/psx.o      \
1418   $(MESS_MACHINE)/psxcd.o      \
1419   $(MESS_MACHINE)/psxcddrv.o   \
1420   $(MESS_MACHINE)/psxcard.o   \
14211409   $(MESS_DRIVERS)/pockstat.o   \
14221410   $(MESS_DRIVERS)/smc777.o   \
14231411
r11460r11461
18061794$(MESS_DRIVERS)/mmd1.o:      $(MESS_LAYOUT)/mmd1.lh \
18071795               $(MESS_LAYOUT)/mmd2.lh
18081796$(MESS_VIDEO)/newbrain.o:   $(MESS_LAYOUT)/newbrain.lh
1809$(MESS_DRIVERS)/ng_aes.o:   $(MESS_LAYOUT)/neogeo.lh
1797$(MAME_DRIVERS)/ng_aes.o:   $(MESS_LAYOUT)/neogeo.lh
18101798$(MESS_DRIVERS)/poly880.o:   $(MESS_LAYOUT)/poly880.lh
18111799$(MESS_DRIVERS)/pc1500.o:   $(MESS_LAYOUT)/pc1500.lh
18121800$(MESS_VIDEO)/pc8401a.o:   $(MESS_LAYOUT)/pc8500.lh

Previous 15994 Revisions Next


© 1998-2018 The MESS Team