Previous 15994 Revisions Next

r9706 Friday 3rd December, 2010 at 02:07:10 UTC by Nathan Woods
More Atari Ace conversions. [Atari Ace]
[src/mess]mess.mak
[src/mess/drivers]amstrad.c msx.c
[src/mess/formats]msx_dsk.c*
[src/mess/includes]msx.h
[src/mess/machine]msx.c msx_slot.c

src/mess/machine/msx_slot.c
r9705r9706
3030
3131static void msx_cpu_setbank (running_machine *machine, int page, UINT8 *mem)
3232{
33   msx_state *state = machine->driver_data<msx_state>();
3334   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
3435   switch (page)
3536   {
r9705r9706
6263      break;
6364   case 8:
6465      memory_set_bankptr (machine,"bank11", mem);
65      msx1.top_page = mem;
66      state->top_page = mem;
6667      break;
6768   }
6869}
r9705r9706
8182
8283MSX_SLOT_MAP(empty)
8384{
84   msx_cpu_setbank (machine, page * 2 + 1, msx1.empty);
85   msx_cpu_setbank (machine, page * 2 + 2, msx1.empty);
85   msx_state *drvstate = machine->driver_data<msx_state>();
86   msx_cpu_setbank (machine, page * 2 + 1, drvstate->empty);
87   msx_cpu_setbank (machine, page * 2 + 2, drvstate->empty);
8688}
8789
8890MSX_SLOT_INIT(rom)
r9705r9706
121123
122124MSX_SLOT_MAP(ram)
123125{
126   msx_state *drvstate = machine->driver_data<msx_state>();
124127   UINT8 *mem = state->mem + (page - state->start_page) * 0x4000;
125128
126   msx1.ram_pages[page] = mem;
129   drvstate->ram_pages[page] = mem;
127130   msx_cpu_setbank (machine, page * 2 + 1, mem);
128131   msx_cpu_setbank (machine, page * 2 + 2, mem + 0x2000);
129132}
r9705r9706
179182
180183MSX_SLOT_RESET(rammm)
181184{
185   msx_state *drvstate = machine->driver_data<msx_state>();
182186   int i;
183187
184188   for (i=0; i<4; i++)
185189   {
186      msx1.ram_mapper[i] = 3 - i;
190      drvstate->ram_mapper[i] = 3 - i;
187191   }
188192}
189193
190194MSX_SLOT_MAP(rammm)
191195{
196   msx_state *drvstate = machine->driver_data<msx_state>();
192197   UINT8 *mem = state->mem +
193         0x4000 * (msx1.ram_mapper[page] & state->bank_mask);
198         0x4000 * (drvstate->ram_mapper[page] & state->bank_mask);
194199
195   msx1.ram_pages[page] = mem;
200   drvstate->ram_pages[page] = mem;
196201   msx_cpu_setbank (machine, page * 2 + 1, mem);
197202   msx_cpu_setbank (machine, page * 2 + 2, mem + 0x2000);
198203}
r9705r9706
218223
219224MSX_SLOT_MAP(msxdos2)
220225{
226   msx_state *drvstate = machine->driver_data<msx_state>();
221227   if (page != 1)
222228   {
223      msx_cpu_setbank (machine, page * 2 + 1, msx1.empty);
224      msx_cpu_setbank (machine, page * 2 + 2, msx1.empty);
229      msx_cpu_setbank (machine, page * 2 + 1, drvstate->empty);
230      msx_cpu_setbank (machine, page * 2 + 2, drvstate->empty);
225231   }
226232   else
227233   {
r9705r9706
294300
295301MSX_SLOT_WRITE(konami)
296302{
303   msx_state *drvstate = machine->driver_data<msx_state>();
297304   switch (addr)
298305   {
299306   case 0x6000:
300307      state->banks[1] = val & state->bank_mask;
301308      slot_konami_map (machine, state, 1);
302      if (msx1.state[0] == state)
309      if (drvstate->state[0] == state)
303310      {
304311         slot_konami_map (machine, state, 0);
305312      }
r9705r9706
307314   case 0x8000:
308315      state->banks[2] = val & state->bank_mask;
309316      slot_konami_map (machine, state, 2);
310      if (msx1.state[3] == state)
317      if (drvstate->state[3] == state)
311318      {
312319         slot_konami_map (machine, state, 3);
313320      }
r9705r9706
315322   case 0xa000:
316323      state->banks[3] = val & state->bank_mask;
317324      slot_konami_map (machine, state, 2);
318      if (msx1.state[3] == state)
325      if (drvstate->state[3] == state)
319326      {
320327         slot_konami_map (machine, state, 3);
321328      }
r9705r9706
402409
403410MSX_SLOT_WRITE(konami_scc)
404411{
412   msx_state *drvstate = machine->driver_data<msx_state>();
405413   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
406414   if (addr >= 0x5000 && addr < 0x5800)
407415   {
408416      state->banks[0] = val & state->bank_mask;
409417      slot_konami_scc_map (machine, state, 1);
410      if (msx1.state[3] == state)
418      if (drvstate->state[3] == state)
411419      {
412420         slot_konami_scc_map (machine, state, 3);
413421      }
r9705r9706
416424   {
417425      state->banks[1] = val & state->bank_mask;
418426      slot_konami_scc_map (machine, state, 1);
419      if (msx1.state[3] == state)
427      if (drvstate->state[3] == state)
420428      {
421429         slot_konami_scc_map (machine, state, 3);
422430      }
r9705r9706
426434      state->banks[2] = val & state->bank_mask;
427435      state->cart.scc.active = ((val & 0x3f) == 0x3f);
428436      slot_konami_scc_map (machine, state, 2);
429      if (msx1.state[0] == state)
437      if (drvstate->state[0] == state)
430438      {
431439         slot_konami_scc_map (machine, state, 0);
432440      }
r9705r9706
467475   {
468476      state->banks[3] = val & state->bank_mask;
469477      slot_konami_scc_map (machine, state, 2);
470      if (msx1.state[0] == state)
478      if (drvstate->state[0] == state)
471479      {
472480         slot_konami_scc_map (machine, state, 0);
473481      }
r9705r9706
507515
508516MSX_SLOT_MAP(ascii8)
509517{
518   msx_state *drvstate = machine->driver_data<msx_state>();
510519   switch (page)
511520   {
512521   case 0:
513      msx_cpu_setbank (machine, 1, msx1.empty);
514      msx_cpu_setbank (machine, 2, msx1.empty);
522      msx_cpu_setbank (machine, 1, drvstate->empty);
523      msx_cpu_setbank (machine, 2, drvstate->empty);
515524      break;
516525   case 1:
517526      msx_cpu_setbank (machine, 3, state->mem + state->banks[0] * 0x2000);
r9705r9706
522531      msx_cpu_setbank (machine, 6, state->mem + state->banks[3] * 0x2000);
523532      break;
524533   case 3:
525      msx_cpu_setbank (machine, 7, msx1.empty);
526      msx_cpu_setbank (machine, 8, msx1.empty);
534      msx_cpu_setbank (machine, 7, drvstate->empty);
535      msx_cpu_setbank (machine, 8, drvstate->empty);
527536   }
528537}
529538
530539MSX_SLOT_WRITE(ascii8)
531540{
541   msx_state *drvstate = machine->driver_data<msx_state>();
532542   int bank;
533543
534544   if (addr >= 0x6000 && addr < 0x8000)
r9705r9706
540550      {
541551         slot_ascii8_map (machine, state, 1);
542552      }
543      else if (msx1.state[2] == state)
553      else if (drvstate->state[2] == state)
544554      {
545555         slot_ascii8_map (machine, state, 2);
546556      }
r9705r9706
580590
581591MSX_SLOT_MAP(ascii16)
582592{
593   msx_state *drvstate = machine->driver_data<msx_state>();
583594   UINT8 *mem;
584595
585596   switch (page)
586597   {
587598   case 0:
588      msx_cpu_setbank (machine, 1, msx1.empty);
589      msx_cpu_setbank (machine, 2, msx1.empty);
599      msx_cpu_setbank (machine, 1, drvstate->empty);
600      msx_cpu_setbank (machine, 2, drvstate->empty);
590601      break;
591602   case 1:
592603      mem = state->mem + state->banks[0] * 0x4000;
r9705r9706
599610      msx_cpu_setbank (machine, 6, mem + 0x2000);
600611      break;
601612   case 3:
602      msx_cpu_setbank (machine, 7, msx1.empty);
603      msx_cpu_setbank (machine, 8, msx1.empty);
613      msx_cpu_setbank (machine, 7, drvstate->empty);
614      msx_cpu_setbank (machine, 8, drvstate->empty);
604615   }
605616}
606617
607618MSX_SLOT_WRITE(ascii16)
608619{
620   msx_state *drvstate = machine->driver_data<msx_state>();
609621   if (addr >= 0x6000 && addr < 0x6800)
610622   {
611623      state->banks[0] = val & state->bank_mask;
r9705r9706
614626   else if (addr >= 0x7000 && addr < 0x7800)
615627   {
616628      state->banks[1] = val & state->bank_mask;
617      if (msx1.state[2] == state)
629      if (drvstate->state[2] == state)
618630      {
619631         slot_ascii16_map (machine, state, 2);
620632      }
r9705r9706
661673   for (i=0; i<4; i++) state->banks[i] = i;
662674}
663675
664static UINT8 *ascii8_sram_bank_select (slot_state *state, int bankno)
676static UINT8 *ascii8_sram_bank_select (msx_state *drvstate, slot_state *state, int bankno)
665677{
666678   int bank = state->banks[bankno];
667679
668680   if (bank & state->cart.sram.empty_mask)
669681   {
670      return msx1.empty;
682      return drvstate->empty;
671683   }
672684   else if (bank & state->cart.sram.sram_mask)
673685   {
r9705r9706
681693
682694MSX_SLOT_MAP(ascii8_sram)
683695{
696   msx_state *drvstate = machine->driver_data<msx_state>();
684697   switch (page)
685698   {
686699   case 0:
687      msx_cpu_setbank (machine, 1, msx1.empty);
688      msx_cpu_setbank (machine, 2, msx1.empty);
700      msx_cpu_setbank (machine, 1, drvstate->empty);
701      msx_cpu_setbank (machine, 2, drvstate->empty);
689702      break;
690703   case 1:
691      msx_cpu_setbank (machine, 3, ascii8_sram_bank_select (state, 0));
692      msx_cpu_setbank (machine, 4, ascii8_sram_bank_select (state, 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));
693706      break;
694707   case 2:
695      msx_cpu_setbank (machine, 5, ascii8_sram_bank_select (state, 2));
696      msx_cpu_setbank (machine, 6, ascii8_sram_bank_select (state, 3));
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));
697710      break;
698711   case 3:
699      msx_cpu_setbank (machine, 7, msx1.empty);
700      msx_cpu_setbank (machine, 8, msx1.empty);
712      msx_cpu_setbank (machine, 7, drvstate->empty);
713      msx_cpu_setbank (machine, 8, drvstate->empty);
701714   }
702715}
703716
704717MSX_SLOT_WRITE(ascii8_sram)
705718{
719   msx_state *drvstate = machine->driver_data<msx_state>();
706720   int bank;
707721
708722   if (addr >= 0x6000 && addr < 0x8000)
r9705r9706
714728      {
715729         slot_ascii8_sram_map (machine, state, 1);
716730      }
717      else if (msx1.state[2] == state)
731      else if (drvstate->state[2] == state)
718732      {
719733         slot_ascii8_sram_map (machine, state, 2);
720734      }
r9705r9706
827841   for (i=0; i<2; i++) state->banks[i] = i;
828842}
829843
830static UINT8 *ascii16_sram_bank_select (slot_state *state, int bankno)
844static UINT8 *ascii16_sram_bank_select (msx_state *drvstate, slot_state *state, int bankno)
831845{
832846   int bank = state->banks[bankno];
833847
834848   if (bank & state->cart.sram.empty_mask)
835849   {
836      return msx1.empty;
850      return drvstate->empty;
837851   }
838852   else if (bank & state->cart.sram.sram_mask)
839853   {
r9705r9706
847861
848862MSX_SLOT_MAP(ascii16_sram)
849863{
864   msx_state *drvstate = machine->driver_data<msx_state>();
850865   UINT8 *mem;
851866
852867   switch (page)
853868   {
854869   case 0:
855      msx_cpu_setbank (machine, 1, msx1.empty);
856      msx_cpu_setbank (machine, 2, msx1.empty);
870      msx_cpu_setbank (machine, 1, drvstate->empty);
871      msx_cpu_setbank (machine, 2, drvstate->empty);
857872      break;
858873   case 1:
859      mem = ascii16_sram_bank_select (state, 0);
874      mem = ascii16_sram_bank_select (drvstate, state, 0);
860875      msx_cpu_setbank (machine, 3, mem);
861876      msx_cpu_setbank (machine, 4, mem + 0x2000);
862877      break;
863878   case 2:
864      mem = ascii16_sram_bank_select (state, 1);
879      mem = ascii16_sram_bank_select (drvstate, state, 1);
865880      msx_cpu_setbank (machine, 5, mem);
866881      msx_cpu_setbank (machine, 6, mem + 0x2000);
867882      break;
868883   case 3:
869      msx_cpu_setbank (machine, 7, msx1.empty);
870      msx_cpu_setbank (machine, 8, msx1.empty);
884      msx_cpu_setbank (machine, 7, drvstate->empty);
885      msx_cpu_setbank (machine, 8, drvstate->empty);
871886   }
872887}
873888
874889MSX_SLOT_WRITE(ascii16_sram)
875890{
891   msx_state *drvstate = machine->driver_data<msx_state>();
876892   if (addr >= 0x6000 && addr < 0x6800)
877893   {
878894      state->banks[0] = val;
r9705r9706
881897   else if (addr >= 0x7000 && addr < 0x7800)
882898   {
883899      state->banks[1] = val;
884      if (msx1.state[2] == state)
900      if (drvstate->state[2] == state)
885901      {
886902         slot_ascii16_sram_map (machine, state, 2);
887903      }
r9705r9706
9941010
9951011MSX_SLOT_MAP(rtype)
9961012{
1013   msx_state *drvstate = machine->driver_data<msx_state>();
9971014   UINT8 *mem;
9981015
9991016   switch (page)
10001017   {
10011018   case 0:
1002      msx_cpu_setbank (machine, 1, msx1.empty);
1003      msx_cpu_setbank (machine, 2, msx1.empty);
1019      msx_cpu_setbank (machine, 1, drvstate->empty);
1020      msx_cpu_setbank (machine, 2, drvstate->empty);
10041021      break;
10051022   case 1:
10061023      mem = state->mem + 15 * 0x4000;
r9705r9706
10131030      msx_cpu_setbank (machine, 6, mem + 0x2000);
10141031      break;
10151032   case 3:
1016      msx_cpu_setbank (machine, 7, msx1.empty);
1017      msx_cpu_setbank (machine, 8, msx1.empty);
1033      msx_cpu_setbank (machine, 7, drvstate->empty);
1034      msx_cpu_setbank (machine, 8, drvstate->empty);
10181035   }
10191036}
10201037
10211038MSX_SLOT_WRITE(rtype)
10221039{
1040   msx_state *drvstate = machine->driver_data<msx_state>();
10231041   if (addr >= 0x7000 && addr < 0x8000)
10241042   {
10251043      int data ;
r9705r9706
10331051         data = val & 0x0f;
10341052      }
10351053      state->banks[0] = data;
1036      if (msx1.state[2] == state)
1054      if (drvstate->state[2] == state)
10371055      {
10381056         slot_rtype_map (machine, state, 2);
10391057      }
r9705r9706
11181136
11191137MSX_SLOT_WRITE(gmaster2)
11201138{
1139   msx_state *drvstate = machine->driver_data<msx_state>();
11211140   if (addr >= 0x6000 && addr < 0x7000)
11221141   {
11231142      if (val & 0x10)
r9705r9706
11301149      }
11311150      state->banks[1] = val;
11321151      slot_gmaster2_map (machine, state, 1);
1133      if (msx1.state[0] == state)
1152      if (drvstate->state[0] == state)
11341153      {
11351154         slot_gmaster2_map (machine, state, 0);
11361155      }
r9705r9706
11471166      }
11481167      state->banks[2] = val;
11491168      slot_gmaster2_map (machine, state, 2);
1150      if (msx1.state[3] == state)
1169      if (drvstate->state[3] == state)
11511170      {
11521171         slot_gmaster2_map (machine, state, 3);
11531172      }
r9705r9706
11641183      }
11651184      state->banks[3] = val;
11661185      slot_gmaster2_map (machine, state, 2);
1167      if (msx1.state[3] == state)
1186      if (drvstate->state[3] == state)
11681187      {
11691188         slot_gmaster2_map (machine, state, 3);
11701189      }
r9705r9706
12581277
12591278static READ8_HANDLER (msx_diskrom_page1_r)
12601279{
1280   msx_state *state = space->machine->driver_data<msx_state>();
12611281   running_device *fdc = space->machine->device("wd179x");
12621282   switch (offset)
12631283   {
r9705r9706
12651285   case 1: return wd17xx_track_r (fdc, 0);
12661286   case 2: return wd17xx_sector_r (fdc, 0);
12671287   case 3: return wd17xx_data_r (fdc, 0);
1268   case 7: return msx1.dsk_stat;
1288   case 7: return state->dsk_stat;
12691289   default:
1270      return msx1.state[1]->mem[offset + 0x3ff8];
1290      return state->state[1]->mem[offset + 0x3ff8];
12711291   }
12721292}
12731293
12741294static READ8_HANDLER (msx_diskrom_page2_r)
12751295{
1296   msx_state *state = space->machine->driver_data<msx_state>();
12761297   running_device *fdc = space->machine->device("wd179x");
12771298   if (offset >= 0x7f8)
12781299   {
r9705r9706
12871308      case 0x7fb:
12881309         return wd17xx_data_r (fdc, 0);
12891310      case 0x7ff:
1290         return msx1.dsk_stat;
1311         return state->dsk_stat;
12911312      default:
1292         return msx1.state[2]->mem[offset + 0x3800];
1313         return state->state[2]->mem[offset + 0x3800];
12931314      }
12941315   }
12951316   else
r9705r9706
13001321
13011322MSX_SLOT_MAP(diskrom)
13021323{
1324   msx_state *drvstate = machine->driver_data<msx_state>();
13031325   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
13041326   switch (page)
13051327   {
13061328   case 0:
1307      msx_cpu_setbank (machine, 1, msx1.empty);
1308      msx_cpu_setbank (machine, 2, msx1.empty);
1329      msx_cpu_setbank (machine, 1, drvstate->empty);
1330      msx_cpu_setbank (machine, 2, drvstate->empty);
13091331      break;
13101332   case 1:
13111333      msx_cpu_setbank (machine, 3, state->mem);
r9705r9706
13131335      memory_install_read8_handler(space, 0x7ff8, 0x7fff, 0, 0, msx_diskrom_page1_r);
13141336      break;
13151337   case 2:
1316      msx_cpu_setbank (machine, 5, msx1.empty);
1317      msx_cpu_setbank (machine, 6, msx1.empty);
1338      msx_cpu_setbank (machine, 5, drvstate->empty);
1339      msx_cpu_setbank (machine, 6, drvstate->empty);
13181340      memory_install_read8_handler(space, 0xb800, 0xbfff, 0, 0, msx_diskrom_page2_r);
13191341      break;
13201342   case 3:
1321      msx_cpu_setbank (machine, 7, msx1.empty);
1322      msx_cpu_setbank (machine, 8, msx1.empty);
1343      msx_cpu_setbank (machine, 7, drvstate->empty);
1344      msx_cpu_setbank (machine, 8, drvstate->empty);
13231345      break;
13241346   }
13251347}
r9705r9706
13831405
13841406static READ8_HANDLER (msx_diskrom2_page1_r)
13851407{
1408   msx_state *state = space->machine->driver_data<msx_state>();
13861409   running_device *fdc = space->machine->device("wd179x");
13871410   switch (offset)
13881411   {
r9705r9706
13901413   case 1: return wd17xx_track_r(fdc, 0);
13911414   case 2: return wd17xx_sector_r(fdc, 0);
13921415   case 3: return wd17xx_data_r(fdc, 0);
1393   case 4: return msx1.dsk_stat;
1416   case 4: return state->dsk_stat;
13941417   default:
1395      return msx1.state[1]->mem[offset + 0x3ff8];
1418      return state->state[1]->mem[offset + 0x3ff8];
13961419   }
13971420}
13981421
13991422static  READ8_HANDLER (msx_diskrom2_page2_r)
14001423{
1424   msx_state *state = space->machine->driver_data<msx_state>();
14011425   running_device *fdc = space->machine->device("wd179x");
14021426   if (offset >= 0x7b8)
14031427   {
r9705r9706
14121436      case 0x7bb:
14131437         return wd17xx_data_r (fdc, 0);
14141438      case 0x7bc:
1415         return msx1.dsk_stat;
1439         return state->dsk_stat;
14161440      default:
1417         return msx1.state[2]->mem[offset + 0x3800];
1441         return state->state[2]->mem[offset + 0x3800];
14181442      }
14191443   }
14201444   else
r9705r9706
14251449
14261450MSX_SLOT_MAP(diskrom2)
14271451{
1452   msx_state *drvstate = machine->driver_data<msx_state>();
14281453   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
14291454   switch (page)
14301455   {
14311456   case 0:
1432      msx_cpu_setbank (machine, 1, msx1.empty);
1433      msx_cpu_setbank (machine, 2, msx1.empty);
1457      msx_cpu_setbank (machine, 1, drvstate->empty);
1458      msx_cpu_setbank (machine, 2, drvstate->empty);
14341459      break;
14351460   case 1:
14361461      msx_cpu_setbank (machine, 3, state->mem);
r9705r9706
14381463      memory_install_read8_handler(space, 0x7fb8, 0x7fbc, 0, 0, msx_diskrom2_page1_r);
14391464      break;
14401465   case 2:
1441      msx_cpu_setbank (machine, 5, msx1.empty);
1442      msx_cpu_setbank (machine, 6, msx1.empty);
1466      msx_cpu_setbank (machine, 5, drvstate->empty);
1467      msx_cpu_setbank (machine, 6, drvstate->empty);
14431468      memory_install_read8_handler(space, 0xb800, 0xbfbc, 0, 0, msx_diskrom2_page2_r);
14441469      break;
14451470   case 3:
1446      msx_cpu_setbank (machine, 7, msx1.empty);
1447      msx_cpu_setbank (machine, 8, msx1.empty);
1471      msx_cpu_setbank (machine, 7, drvstate->empty);
1472      msx_cpu_setbank (machine, 8, drvstate->empty);
14481473   }
14491474}
14501475
r9705r9706
15031528
15041529MSX_SLOT_MAP(synthesizer)
15051530{
1531   msx_state *drvstate = machine->driver_data<msx_state>();
15061532   switch (page)
15071533   {
15081534   case 0:
1509      msx_cpu_setbank (machine, 1, msx1.empty);
1510      msx_cpu_setbank (machine, 2, msx1.empty);
1535      msx_cpu_setbank (machine, 1, drvstate->empty);
1536      msx_cpu_setbank (machine, 2, drvstate->empty);
15111537      break;
15121538   case 1:
15131539      msx_cpu_setbank (machine, 3, state->mem);
r9705r9706
15181544      msx_cpu_setbank (machine, 6, state->mem + 0x6000);
15191545      break;
15201546   case 3:
1521      msx_cpu_setbank (machine, 7, msx1.empty);
1522      msx_cpu_setbank (machine, 8, msx1.empty);
1547      msx_cpu_setbank (machine, 7, drvstate->empty);
1548      msx_cpu_setbank (machine, 8, drvstate->empty);
15231549   }
15241550}
15251551
r9705r9706
15811607
15821608MSX_SLOT_WRITE(majutsushi)
15831609{
1610   msx_state *drvstate = machine->driver_data<msx_state>();
15841611   if (addr >= 0x5000 && addr < 0x6000)
15851612   {
15861613      dac_data_w (machine->device("dac"), val);
r9705r9706
15891616   {
15901617      state->banks[1] = val & 0x0f;
15911618      slot_majutsushi_map (machine, state, 1);
1592      if (msx1.state[0] == state)
1619      if (drvstate->state[0] == state)
15931620      {
15941621         slot_konami_map (machine, state, 0);
15951622      }
r9705r9706
15981625   {
15991626      state->banks[addr < 0xa000 ? 2 : 3] = val & 0x0f;
16001627      slot_majutsushi_map (machine, state, 2);
1601      if (msx1.state[3] == state)
1628      if (drvstate->state[3] == state)
16021629      {
16031630         slot_konami_map (machine, state, 3);
16041631      }
r9705r9706
16511678
16521679MSX_SLOT_RESET(fmpac)
16531680{
1681   msx_state *drvstate = machine->driver_data<msx_state>();
16541682   int i;
16551683
16561684   state->banks[0] = 0;
16571685   state->cart.fmpac.sram_active = 0;
16581686   state->cart.fmpac.opll_active = 0;
1659   msx1.opll_active = 0;
1687   drvstate->opll_active = 0;
16601688   for (i=0; i<=state->bank_mask; i++)
16611689   {
16621690      state->mem[0x3ff6 + i * 0x4000] = 0;
r9705r9706
16741702
16751703MSX_SLOT_MAP(fmpac)
16761704{
1705   msx_state *drvstate = machine->driver_data<msx_state>();
16771706   if (page == 1)
16781707   {
16791708      if (state->cart.fmpac.sram_active)
r9705r9706
16891718   }
16901719   else
16911720   {
1692      msx_cpu_setbank (machine, page * 2 + 1, msx1.empty);
1693      msx_cpu_setbank (machine, page * 2 + 2, msx1.empty);
1721      msx_cpu_setbank (machine, page * 2 + 1, drvstate->empty);
1722      msx_cpu_setbank (machine, page * 2 + 2, drvstate->empty);
16941723   }
16951724}
16961725
16971726MSX_SLOT_WRITE(fmpac)
16981727{
1728   msx_state *drvstate = machine->driver_data<msx_state>();
16991729   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
17001730   int i, data;
17011731
r9705r9706
17331763      }
17341764      state->cart.fmpac.mem[0x3ff6] = data;
17351765      state->cart.fmpac.opll_active = val & 1;
1736      if ((msx1.opll_active ^ val) & 1)
1766      if ((drvstate->opll_active ^ val) & 1)
17371767      {
17381768         logerror ("FM-PAC: OPLL %sactivated\n", val & 1 ? "" : "de");
17391769      }
1740      msx1.opll_active = val & 1;
1770      drvstate->opll_active = val & 1;
17411771      break;
17421772   case 0x7ff7:
17431773      state->banks[0] = val & state->bank_mask;
r9705r9706
18431873
18441874MSX_SLOT_RESET(superloadrunner)
18451875{
1846   msx1.superloadrunner_bank = 0;
1876   msx_state *drvstate = machine->driver_data<msx_state>();
1877   drvstate->superloadrunner_bank = 0;
18471878}
18481879
18491880MSX_SLOT_MAP(superloadrunner)
18501881{
1882   msx_state *drvstate = machine->driver_data<msx_state>();
18511883   if (page == 2)
18521884   {
18531885      UINT8 *mem = state->mem +
1854            (msx1.superloadrunner_bank & state->bank_mask) * 0x4000;
1886            (drvstate->superloadrunner_bank & state->bank_mask) * 0x4000;
18551887
18561888      msx_cpu_setbank (machine, 5, mem);
18571889      msx_cpu_setbank (machine, 6, mem + 0x2000);
18581890   }
18591891   else
18601892   {
1861      msx_cpu_setbank (machine, page * 2 + 1, msx1.empty);
1862      msx_cpu_setbank (machine, page * 2 + 2, msx1.empty);
1893      msx_cpu_setbank (machine, page * 2 + 1, drvstate->empty);
1894      msx_cpu_setbank (machine, page * 2 + 2, drvstate->empty);
18631895   }
18641896}
18651897
r9705r9706
18841916
18851917MSX_SLOT_MAP(crossblaim)
18861918{
1919   msx_state *drvstate = machine->driver_data<msx_state>();
18871920   UINT8 *mem;
18881921
18891922   /* This might look odd, but it's what happens on the real cartridge */
r9705r9706
18981931      }
18991932      else
19001933      {
1901         msx_cpu_setbank (machine, 1, msx1.empty);
1902         msx_cpu_setbank (machine, 2, msx1.empty);
1934         msx_cpu_setbank (machine, 1, drvstate->empty);
1935         msx_cpu_setbank (machine, 2, drvstate->empty);
19031936      }
19041937      break;
19051938   case 1:
r9705r9706
19191952      }
19201953      else
19211954      {
1922         msx_cpu_setbank (machine, 7, msx1.empty);
1923         msx_cpu_setbank (machine, 8, msx1.empty);
1955         msx_cpu_setbank (machine, 7, drvstate->empty);
1956         msx_cpu_setbank (machine, 8, drvstate->empty);
19241957      }
19251958   }
19261959}
19271960
19281961MSX_SLOT_WRITE(crossblaim)
19291962{
1963   msx_state *drvstate = machine->driver_data<msx_state>();
19301964   UINT8 block = val & 3;
19311965
19321966   if (!block) block = 1;
19331967   state->banks[0] = block;
19341968
1935   if (msx1.state[0] == state)
1969   if (drvstate->state[0] == state)
19361970   {
19371971      slot_crossblaim_map (machine, state, 0);
19381972   }
1939   if (msx1.state[2] == state)
1973   if (drvstate->state[2] == state)
19401974   {
19411975      slot_crossblaim_map (machine, state, 2);
19421976   }
1943   if (msx1.state[3] == state)
1977   if (drvstate->state[3] == state)
19441978   {
19451979      slot_crossblaim_map (machine, state, 3);
19461980   }
r9705r9706
19812015
19822016MSX_SLOT_MAP(korean80in1)
19832017{
2018   msx_state *drvstate = machine->driver_data<msx_state>();
19842019   switch (page)
19852020   {
19862021   case 0:
1987      msx_cpu_setbank (machine, 1, msx1.empty);
1988      msx_cpu_setbank (machine, 2, msx1.empty);
2022      msx_cpu_setbank (machine, 1, drvstate->empty);
2023      msx_cpu_setbank (machine, 2, drvstate->empty);
19892024      break;
19902025   case 1:
19912026      msx_cpu_setbank (machine, 3, state->mem + state->banks[0] * 0x2000);
r9705r9706
19962031      msx_cpu_setbank (machine, 6, state->mem + state->banks[3] * 0x2000);
19972032      break;
19982033   case 3:
1999      msx_cpu_setbank (machine, 7, msx1.empty);
2000      msx_cpu_setbank (machine, 8, msx1.empty);
2034      msx_cpu_setbank (machine, 7, drvstate->empty);
2035      msx_cpu_setbank (machine, 8, drvstate->empty);
20012036   }
20022037}
20032038
20042039MSX_SLOT_WRITE(korean80in1)
20052040{
2041   msx_state *drvstate = machine->driver_data<msx_state>();
20062042   int bank;
20072043
20082044   if (addr >= 0x4000 && addr < 0x4004)
r9705r9706
20142050      {
20152051         slot_korean80in1_map (machine, state, 1);
20162052      }
2017      else if (msx1.state[2] == state)
2053      else if (drvstate->state[2] == state)
20182054      {
20192055         slot_korean80in1_map (machine, state, 2);
20202056      }
r9705r9706
20462082
20472083MSX_SLOT_RESET(korean90in1)
20482084{
2049   msx1.korean90in1_bank = 0;
2085   msx_state *drvstate = machine->driver_data<msx_state>();
2086   drvstate->korean90in1_bank = 0;
20502087}
20512088
20522089MSX_SLOT_MAP(korean90in1)
20532090{
2091   msx_state *drvstate = machine->driver_data<msx_state>();
20542092   UINT8 *mem;
2055   UINT8 mask = (msx1.korean90in1_bank & 0xc0) == 0x80 ? 0x3e : 0x3f;
2093   UINT8 mask = (drvstate->korean90in1_bank & 0xc0) == 0x80 ? 0x3e : 0x3f;
20562094   mem = state->mem +
2057      ((msx1.korean90in1_bank & mask) & state->bank_mask) * 0x4000;
2095      ((drvstate->korean90in1_bank & mask) & state->bank_mask) * 0x4000;
20582096
20592097   switch (page)
20602098   {
20612099   case 0:
2062      msx_cpu_setbank (machine, 1, msx1.empty);
2063      msx_cpu_setbank (machine, 2, msx1.empty);
2100      msx_cpu_setbank (machine, 1, drvstate->empty);
2101      msx_cpu_setbank (machine, 2, drvstate->empty);
20642102      break;
20652103   case 1:
20662104      msx_cpu_setbank (machine, 3, mem);
20672105      msx_cpu_setbank (machine, 4, mem + 0x2000);
20682106      break;
20692107   case 2:
2070      switch (msx1.korean90in1_bank & 0xc0)
2108      switch (drvstate->korean90in1_bank & 0xc0)
20712109      {
20722110      case 0x80: /* 32 kb mode */
20732111         mem += 0x4000;
r9705r9706
20822120      }
20832121      break;
20842122   case 3:
2085      msx_cpu_setbank (machine, 7, msx1.empty);
2086      msx_cpu_setbank (machine, 8, msx1.empty);
2123      msx_cpu_setbank (machine, 7, drvstate->empty);
2124      msx_cpu_setbank (machine, 8, drvstate->empty);
20872125   }
20882126}
20892127
r9705r9706
21202158
21212159MSX_SLOT_MAP(korean126in1)
21222160{
2161   msx_state *drvstate = machine->driver_data<msx_state>();
21232162   UINT8 *mem;
21242163
21252164   switch (page)
21262165   {
21272166   case 0:
2128      msx_cpu_setbank (machine, 1, msx1.empty);
2129      msx_cpu_setbank (machine, 2, msx1.empty);
2167      msx_cpu_setbank (machine, 1, drvstate->empty);
2168      msx_cpu_setbank (machine, 2, drvstate->empty);
21302169      break;
21312170   case 1:
21322171      mem = state->mem + state->banks[0] * 0x4000;
r9705r9706
21392178      msx_cpu_setbank (machine, 6, mem + 0x2000);
21402179      break;
21412180   case 3:
2142      msx_cpu_setbank (machine, 7, msx1.empty);
2143      msx_cpu_setbank (machine, 8, msx1.empty);
2181      msx_cpu_setbank (machine, 7, drvstate->empty);
2182      msx_cpu_setbank (machine, 8, drvstate->empty);
21442183   }
21452184}
21462185
21472186MSX_SLOT_WRITE(korean126in1)
21482187{
2188   msx_state *drvstate = machine->driver_data<msx_state>();
21492189   if (addr >= 0x4000 && addr < 0x4002)
21502190   {
21512191      int bank = addr & 1;
r9705r9706
21542194      {
21552195         slot_korean126in1_map (machine, state, 1);
21562196      }
2157      else if (msx1.state[2] == state)
2197      else if (drvstate->state[2] == state)
21582198      {
21592199         slot_korean126in1_map (machine, state, 2);
21602200      }
r9705r9706
21932233
21942234static  READ8_HANDLER (soundcartridge_scc)
21952235{
2236   msx_state *state = space->machine->driver_data<msx_state>();
21962237   int reg;
21972238
21982239
21992240   if (offset >= 0x7e0)
22002241   {
2201      return msx1.state[2]->mem[
2202            msx1.state[2]->banks[2] * 0x2000 + 0x1800 + offset];
2242      return state->state[2]->mem[
2243            state->state[2]->banks[2] * 0x2000 + 0x1800 + offset];
22032244   }
22042245
22052246   reg = offset & 0xff;
r9705r9706
22292270
22302271static  READ8_HANDLER (soundcartridge_sccp)
22312272{
2273   msx_state *state = space->machine->driver_data<msx_state>();
22322274   int reg;
22332275
22342276   if (offset >= 0x7e0)
22352277   {
2236      return msx1.state[2]->mem[
2237            msx1.state[2]->banks[3] * 0x2000 + 0x1800 + offset];
2278      return state->state[2]->mem[
2279            state->state[2]->banks[3] * 0x2000 + 0x1800 + offset];
22382280   }
22392281
22402282   reg = offset & 0xff;
r9705r9706
22892331
22902332MSX_SLOT_WRITE(soundcartridge)
22912333{
2334   msx_state *drvstate = machine->driver_data<msx_state>();
22922335   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
22932336   int i;
22942337
r9705r9706
23072350         state->banks[0] = val & state->bank_mask;
23082351         state->cart.sccp.banks_saved[0] = val;
23092352         slot_soundcartridge_map (machine, state, 1);
2310         if (msx1.state[3] == state)
2353         if (drvstate->state[3] == state)
23112354         {
23122355            slot_soundcartridge_map (machine, state, 3);
23132356         }
r9705r9706
23232366      {
23242367         state->banks[1] = val & state->bank_mask;
23252368         state->cart.sccp.banks_saved[1] = val;
2326         if (msx1.state[3] == state)
2369         if (drvstate->state[3] == state)
23272370         {
23282371            slot_soundcartridge_map (machine, state, 3);
23292372         }
r9705r9706
23442387               (((val & 0x3f) == 0x3f) && !(state->cart.sccp.mode & 0x20));
23452388
23462389         slot_soundcartridge_map (machine, state, 2);
2347         if (msx1.state[0] == state)
2390         if (drvstate->state[0] == state)
23482391         {
23492392            slot_soundcartridge_map (machine, state, 0);
23502393         }
r9705r9706
23962439         state->cart.sccp.sccp_active =
23972440               (val & 0x80) && (state->cart.sccp.mode & 0x20);
23982441         slot_soundcartridge_map (machine, state, 2);
2399         if (msx1.state[0] == state)
2442         if (drvstate->state[0] == state)
24002443         {
24012444            slot_soundcartridge_map (machine, state, 0);
24022445         }
src/mess/machine/msx.c
r9705r9706
3131
3232#define VERBOSE 0
3333
34MSX msx1;
35static slot_state *cart_state[MSX_MAX_CARTS];
34static void msx_memory_map_all (running_machine *machine);
35static void msx_memory_map_page (running_machine *machine, int page);
36static void msx_memory_init (running_machine *machine);
37static void msx_memory_set_carts (running_machine *machine);
38static void msx_memory_reset (running_machine *machine);
3639
40
41
3742static int msx_probe_type (UINT8* pmem, int size)
3843{
3944   int kon4, kon5, asc8, asc16, i;
r9705r9706
8489
8590DEVICE_IMAGE_LOAD (msx_cart)
8691{
92   msx_state *state = image.device().machine->driver_data<msx_state>();
8793   int size;
8894   int size_aligned;
8995   UINT8 *mem;
9096   int type;
9197   const char *extra = NULL;
9298   char *sramfile;
93   slot_state *state;
99   slot_state *st;
94100   int id = -1;
95101
96102   if (strcmp(image.device().tag(),"cart1")==0) {
r9705r9706
245251   }
246252
247253   /* allocate and set slot_state for this cartridge */
248   state = (slot_state*) image.image_malloc(sizeof (slot_state));
249   if (!state)
254   st = (slot_state*) image.image_malloc(sizeof (slot_state));
255   if (!st)
250256   {
251257      logerror ("cart #%d: error: cannot allocate memory for "
252258              "cartridge state\n", id);
253259      return IMAGE_INIT_FAIL;
254260   }
255   memset (state, 0, sizeof (slot_state));
261   memset (st, 0, sizeof (slot_state));
256262
257   state->type = type;
263   st->type = type;
258264   sramfile = (char*)image.image_malloc(strlen (image.filename () + 1));
259265
260266   if (sramfile) {
r9705r9706
265271      if (ext) {
266272         *ext = 0;
267273      }
268      state->sramfile = sramfile;
274      st->sramfile = sramfile;
269275   }
270276
271   if (msx_slot_list[type].init (image.device().machine, state, 0, mem, size_aligned)) {
277   if (msx_slot_list[type].init (image.device().machine, st, 0, mem, size_aligned)) {
272278      return IMAGE_INIT_FAIL;
273279   }
274280   if (msx_slot_list[type].loadsram) {
275      msx_slot_list[type].loadsram (state);
281      msx_slot_list[type].loadsram (st);
276282   }
277283
278   msx1.cart_state[id] = cart_state[id] = state;
279   msx_memory_set_carts ();
284   state->cart_state[id] = st;
285   msx_memory_set_carts (image.device().machine);
280286
281287   return IMAGE_INIT_PASS;
282288}
283289
284290DEVICE_IMAGE_UNLOAD (msx_cart)
285291{
292   msx_state *state = image.device().machine->driver_data<msx_state>();
286293   int id = -1;
287294
288295   if (strcmp(image.device().tag(),"cart1")==0) {
r9705r9706
297304      return;
298305   }
299306
300   if (msx_slot_list[msx1.cart_state[id]->type].savesram)
307   if (msx_slot_list[state->cart_state[id]->type].savesram)
301308   {
302      msx_slot_list[msx1.cart_state[id]->type].savesram (msx1.cart_state[id]);
309      msx_slot_list[state->cart_state[id]->type].savesram (state->cart_state[id]);
303310   }
304311}
305312
r9705r9706
331338
332339MACHINE_START( msx2 )
333340{
334   msx1.dsk_stat = 0x7f;
341   msx_state *state = machine->driver_data<msx_state>();
342   state->dsk_stat = 0x7f;
335343}
336344
337345MACHINE_RESET( msx )
r9705r9706
479487
480488DRIVER_INIT( msx )
481489{
482   int i;
483
484   memset (&msx1, 0, sizeof (MSX));
485   /* LOAD_DEVICE is called before DRIVER_INIT */
486   for (i=0; i<MSX_MAX_CARTS; i++)
487   {
488      msx1.cart_state[i] = cart_state[i];
489   }
490
491490   cpu_set_input_line_vector (machine->device("maincpu"), 0, 0xff);
492491
493492   msx_memory_init (machine);
r9705r9706
504503
505504INTERRUPT_GEN( msx_interrupt )
506505{
506   msx_state *state = device->machine->driver_data<msx_state>();
507507   int i;
508508
509509   for (i=0; i<2; i++)
510510   {
511      msx1.mouse[i] = input_port_read(device->machine, i ? "MOUSE1" : "MOUSE0");
512      msx1.mouse_stat[i] = -1;
511      state->mouse[i] = input_port_read(device->machine, i ? "MOUSE1" : "MOUSE0");
512      state->mouse_stat[i] = -1;
513513   }
514514
515515   TMS9928A_set_spriteslimit (input_port_read(device->machine, "DSW") & 0x20);
r9705r9706
527527
528528READ8_HANDLER ( msx_psg_port_a_r )
529529{
530   msx_state *state = space->machine->driver_data<msx_state>();
530531   int data, inp;
531532
532533   data = (cassette_input(cassette_device_image(space->machine)) > 0.0038 ? 0x80 : 0);
533534
534   if ( (msx1.psg_b ^ input_port_read(space->machine, "DSW") ) & 0x40)
535   if ( (state->psg_b ^ input_port_read(space->machine, "DSW") ) & 0x40)
535536      {
536537      /* game port 2 */
537538      inp = input_port_read(space->machine, "JOY1") & 0x7f;
r9705r9706
547548         {
548549         /* mouse */
549550         data |= inp & 0x70;
550         if (msx1.mouse_stat[1] < 0)
551         if (state->mouse_stat[1] < 0)
551552            inp = 0xf;
552553         else
553            inp = ~(msx1.mouse[1] >> (4*msx1.mouse_stat[1]) ) & 15;
554            inp = ~(state->mouse[1] >> (4*state->mouse_stat[1]) ) & 15;
554555
555556         return data | inp;
556557         }
r9705r9706
572573         {
573574         /* mouse */
574575         data |= inp & 0x70;
575         if (msx1.mouse_stat[0] < 0)
576         if (state->mouse_stat[0] < 0)
576577            inp = 0xf;
577578         else
578            inp = ~(msx1.mouse[0] >> (4*msx1.mouse_stat[0]) ) & 15;
579            inp = ~(state->mouse[0] >> (4*state->mouse_stat[0]) ) & 15;
579580
580581         return data | inp;
581582         }
r9705r9706
587588
588589READ8_HANDLER ( msx_psg_port_b_r )
589590{
590   return msx1.psg_b;
591   msx_state *state = space->machine->driver_data<msx_state>();
592   return state->psg_b;
591593}
592594
593595WRITE8_HANDLER ( msx_psg_port_a_w )
r9705r9706
596598
597599WRITE8_HANDLER ( msx_psg_port_b_w )
598600{
601   msx_state *state = space->machine->driver_data<msx_state>();
599602   /* Arabic or kana mode led */
600   if ( (data ^ msx1.psg_b) & 0x80)
603   if ( (data ^ state->psg_b) & 0x80)
601604      set_led_status (space->machine, 2, !(data & 0x80) );
602605
603   if ( (msx1.psg_b ^ data) & 0x10)
606   if ( (state->psg_b ^ data) & 0x10)
604607   {
605      if (++msx1.mouse_stat[0] > 3) msx1.mouse_stat[0] = -1;
608      if (++state->mouse_stat[0] > 3) state->mouse_stat[0] = -1;
606609   }
607   if ( (msx1.psg_b ^ data) & 0x20)
610   if ( (state->psg_b ^ data) & 0x20)
608611   {
609      if (++msx1.mouse_stat[1] > 3) msx1.mouse_stat[1] = -1;
612      if (++state->mouse_stat[1] > 3) state->mouse_stat[1] = -1;
610613   }
611614
612   msx1.psg_b = data;
615   state->psg_b = data;
613616}
614617
615618WRITE8_DEVICE_HANDLER( msx_printer_strobe_w )
r9705r9706
644647
645648WRITE8_HANDLER (msx_fmpac_w)
646649{
647   if (msx1.opll_active)
650   msx_state *state = space->machine->driver_data<msx_state>();
651   if (state->opll_active)
648652   {
649653      running_device *ym = space->machine->device("ym2413");
650654
r9705r9706
661665
662666WRITE8_HANDLER (msx_rtc_latch_w)
663667{
664   msx1.rtc_latch = data & 15;
668   msx_state *state = space->machine->driver_data<msx_state>();
669   state->rtc_latch = data & 15;
665670}
666671
667672WRITE8_HANDLER (msx_rtc_reg_w)
668673{
674   msx_state *state = space->machine->driver_data<msx_state>();
669675   running_device *rtc = space->machine->device("rtc");
670   tc8521_w(rtc, msx1.rtc_latch, data);
676   tc8521_w(rtc, state->rtc_latch, data);
671677}
672678
673679READ8_HANDLER (msx_rtc_reg_r)
674680{
681   msx_state *state = space->machine->driver_data<msx_state>();
675682   running_device *rtc = space->machine->device("rtc");
676   return tc8521_r(rtc, msx1.rtc_latch);
683   return tc8521_r(rtc, state->rtc_latch);
677684}
678685
679686NVRAM_HANDLER( msx2 )
r9705r9706
721728
722729static WRITE_LINE_DEVICE_HANDLER( msx_wd179x_intrq_w )
723730{
731   msx_state *drvstate = device->machine->driver_data<msx_state>();
724732   if (state)
725      msx1.dsk_stat &= ~0x40;
733      drvstate->dsk_stat &= ~0x40;
726734   else
727      msx1.dsk_stat |= 0x40;
735      drvstate->dsk_stat |= 0x40;
728736}
729737
730738static WRITE_LINE_DEVICE_HANDLER( msx_wd179x_drq_w )
731739{
740   msx_state *drvstate = device->machine->driver_data<msx_state>();
732741   if (state)
733      msx1.dsk_stat &= ~0x80;
742      drvstate->dsk_stat &= ~0x80;
734743   else
735      msx1.dsk_stat |= 0x80;
744      drvstate->dsk_stat |= 0x80;
736745}
737746
738747const wd17xx_interface msx_wd17xx_interface =
r9705r9706
764773
765774static WRITE8_DEVICE_HANDLER ( msx_ppi_port_a_w )
766775{
767   msx1.primary_slot = data;
776   msx_state *state = device->machine->driver_data<msx_state>();
777   state->primary_slot = data;
768778
769779   if (VERBOSE)
770      logerror ("write to primary slot select: %02x\n", msx1.primary_slot);
780      logerror ("write to primary slot select: %02x\n", state->primary_slot);
771781   msx_memory_map_all (device->machine);
772782}
773783
r9705r9706
821831 *
822832 ***********************************************************************/
823833
824void msx_memory_init (running_machine *machine)
834static void msx_memory_init (running_machine *machine)
825835{
836   msx_state *state = machine->driver_data<msx_state>();
826837   int   prim, sec, page, extent, option;
827838   int size = 0;
828839   const msx_slot_layout *layout= (msx_slot_layout*)NULL;
r9705r9706
831842   slot_state *st;
832843   UINT8 *mem = NULL;
833844
834   msx1.empty = auto_alloc_array(machine, UINT8, 0x4000);
835   memset (msx1.empty, 0xff, 0x4000);
845   state->empty = auto_alloc_array(machine, UINT8, 0x4000);
846   memset (state->empty, 0xff, 0x4000);
836847
837848   for (prim=0; prim<4; prim++) {
838849      for (sec=0; sec<4; sec++) {
839850         for (page=0; page<4; page++) {
840            msx1.all_state[prim][sec][page]= (slot_state*)NULL;
851            state->all_state[prim][sec][page]= (slot_state*)NULL;
841852         }
842853      }
843854   }
r9705r9706
854865      return;
855866   }
856867
857   msx1.layout = layout;
868   state->layout = layout;
858869
859870   for (; layout->entry != MSX_LAYOUT_LAST; layout++) {
860871
r9705r9706
866877         extent = layout->page_extent;
867878
868879         if (layout->slot_secondary) {
869            msx1.slot_expanded[layout->slot_primary]= TRUE;
880            state->slot_expanded[layout->slot_primary]= TRUE;
870881         }
871882
872883         slot = &msx_slot_list[layout->type];
r9705r9706
886897
887898         st = (slot_state*)NULL;
888899         if (layout->type == SLOT_CARTRIDGE1) {
889            st = msx1.cart_state[0];
900            st = state->cart_state[0];
890901            if (!st) {
891902               slot = &msx_slot_list[SLOT_SOUNDCARTRIDGE];
892903               size = 0x20000;
893904            }
894905         }
895906         if (layout->type == SLOT_CARTRIDGE2) {
896            st = msx1.cart_state[1];
907            st = state->cart_state[1];
897908            if (!st) {
898909               /* Check whether the optional FM-PAC rom is present */
899910               option = 0x10000;
r9705r9706
933944                   "page + extent > 3\n");
934945               break;
935946            }
936            msx1.all_state[prim][sec][page] = st;
947            state->all_state[prim][sec][page] = st;
937948            page++;
938949         }
939950         break;
940951      case MSX_LAYOUT_KANJI_ENTRY:
941         msx1.kanji_mem = memory_region(machine, "maincpu") + layout->option;
952         state->kanji_mem = memory_region(machine, "maincpu") + layout->option;
942953         break;
943954      case MSX_LAYOUT_RAMIO_SET_BITS_ENTRY:
944         msx1.ramio_set_bits = (UINT8)layout->option;
955         state->ramio_set_bits = (UINT8)layout->option;
945956         break;
946957      }
947958   }
948959}
949960
950void msx_memory_reset (running_machine *machine)
961static void msx_memory_reset (running_machine *machine)
951962{
952   slot_state *state, *last_state= (slot_state*)NULL;
963   msx_state *state = machine->driver_data<msx_state>();
964   slot_state *st, *last_st = (slot_state*)NULL;
953965   int prim, sec, page;
954966
955   msx1.primary_slot = 0;
967   state->primary_slot = 0;
956968
957969   for (prim=0; prim<4; prim++) {
958      msx1.secondary_slot[prim] = 0;
970      state->secondary_slot[prim] = 0;
959971      for (sec=0; sec<4; sec++) {
960972         for (page=0; page<4; page++) {
961            state = msx1.all_state[prim][sec][page];
962            if (state && state != last_state) {
963               msx_slot_list[state->type].reset (machine, state);
973            st = state->all_state[prim][sec][page];
974            if (st && st != last_st) {
975               msx_slot_list[st->type].reset (machine, st);
964976            }
965            last_state = state;
977            last_st = st;
966978         }
967979      }
968980   }
969981}
970982
971void msx_memory_set_carts (void)
983static void msx_memory_set_carts (running_machine *machine)
972984{
985   msx_state *state = machine->driver_data<msx_state>();
973986   const msx_slot_layout *layout;
974987   int page;
975988
976   if (!msx1.layout) {
989   if (!state->layout) {
977990      return;
978991   }
979992
980   for (layout = msx1.layout; layout->entry != MSX_LAYOUT_LAST; layout++) {
993   for (layout = state->layout; layout->entry != MSX_LAYOUT_LAST; layout++) {
981994
982995      if (layout->entry == MSX_LAYOUT_SLOT_ENTRY) {
983996
984997         switch (layout->type) {
985998         case SLOT_CARTRIDGE1:
986999            for (page=0; page<4; page++) {
987               msx1.all_state[layout->slot_primary]
1000               state->all_state[layout->slot_primary]
9881001                          [layout->slot_secondary]
989                          [page] = msx1.cart_state[0];
1002                          [page] = state->cart_state[0];
9901003            }
9911004            break;
9921005         case SLOT_CARTRIDGE2:
9931006            for (page=0; page<4; page++) {
994               msx1.all_state[layout->slot_primary]
1007               state->all_state[layout->slot_primary]
9951008                          [layout->slot_secondary]
996                          [page] = msx1.cart_state[1];
1009                          [page] = state->cart_state[1];
9971010            }
9981011            break;
9991012         }
r9705r9706
10011014   }
10021015}
10031016
1004void msx_memory_map_page (running_machine *machine, int page)
1017static void msx_memory_map_page (running_machine *machine, int page)
10051018{
1019   msx_state *state = machine->driver_data<msx_state>();
10061020   int slot_primary;
10071021   int slot_secondary;
1008   slot_state *state;
1022   slot_state *st;
10091023   const msx_slot *slot;
10101024
1011   slot_primary = (msx1.primary_slot >> (page * 2)) & 3;
1012   slot_secondary = (msx1.secondary_slot[slot_primary] >> (page * 2)) & 3;
1025   slot_primary = (state->primary_slot >> (page * 2)) & 3;
1026   slot_secondary = (state->secondary_slot[slot_primary] >> (page * 2)) & 3;
10131027
1014   state = msx1.all_state[slot_primary][slot_secondary][page];
1015   slot = state ? &msx_slot_list[state->type] : &msx_slot_list[SLOT_EMPTY];
1016   msx1.state[page] = state;
1017   msx1.slot[page] = slot;
1028   st = state->all_state[slot_primary][slot_secondary][page];
1029   slot = st ? &msx_slot_list[st->type] : &msx_slot_list[SLOT_EMPTY];
1030   state->state[page] = st;
1031   state->slot[page] = slot;
10181032
10191033   if (VERBOSE)
10201034   {
10211035      logerror ("mapping %s in %d/%d/%d\n", slot->name, slot_primary,
10221036         slot_secondary, page);
10231037   }
1024   slot->map (machine, state, page);
1038   slot->map (machine, st, page);
10251039}
10261040
1027void msx_memory_map_all (running_machine *machine)
1041static void msx_memory_map_all (running_machine *machine)
10281042{
10291043   int i;
10301044
r9705r9706
10351049
10361050WRITE8_HANDLER (msx_page0_w)
10371051{
1052   msx_state *state = space->machine->driver_data<msx_state>();
10381053   if ( offset == 0 )
10391054   {
1040      msx1.superloadrunner_bank = data;
1041      if (msx1.slot[2]->slot_type == SLOT_SUPERLOADRUNNER) {
1042         msx1.slot[2]->map (space->machine, msx1.state[2], 2);
1055      state->superloadrunner_bank = data;
1056      if (state->slot[2]->slot_type == SLOT_SUPERLOADRUNNER) {
1057         state->slot[2]->map (space->machine, state->state[2], 2);
10431058      }
10441059   }
10451060
1046   switch (msx1.slot[0]->mem_type) {
1061   switch (state->slot[0]->mem_type) {
10471062   case MSX_MEM_RAM:
1048      msx1.ram_pages[0][offset] = data;
1063      state->ram_pages[0][offset] = data;
10491064      break;
10501065   case MSX_MEM_HANDLER:
1051      msx1.slot[0]->write (space->machine, msx1.state[0], offset, data);
1066      state->slot[0]->write (space->machine, state->state[0], offset, data);
10521067   }
10531068}
10541069
r9705r9706
10591074
10601075WRITE8_HANDLER (msx_page1_w)
10611076{
1062   switch (msx1.slot[1]->mem_type) {
1077   msx_state *state = space->machine->driver_data<msx_state>();
1078   switch (state->slot[1]->mem_type) {
10631079   case MSX_MEM_RAM:
1064      msx1.ram_pages[1][offset] = data;
1080      state->ram_pages[1][offset] = data;
10651081      break;
10661082   case MSX_MEM_HANDLER:
1067      msx1.slot[1]->write (space->machine, msx1.state[1], 0x4000 + offset, data);
1083      state->slot[1]->write (space->machine, state->state[1], 0x4000 + offset, data);
10681084   }
10691085}
10701086
r9705r9706
10801096
10811097WRITE8_HANDLER (msx_page2_w)
10821098{
1083   switch (msx1.slot[2]->mem_type) {
1099   msx_state *state = space->machine->driver_data<msx_state>();
1100   switch (state->slot[2]->mem_type) {
10841101   case MSX_MEM_RAM:
1085      msx1.ram_pages[2][offset] = data;
1102      state->ram_pages[2][offset] = data;
10861103      break;
10871104   case MSX_MEM_HANDLER:
1088      msx1.slot[2]->write (space->machine, msx1.state[2], 0x8000 + offset, data);
1105      state->slot[2]->write (space->machine, state->state[2], 0x8000 + offset, data);
10891106   }
10901107}
10911108
r9705r9706
11061123
11071124WRITE8_HANDLER (msx_page3_w)
11081125{
1109   switch (msx1.slot[3]->mem_type) {
1126   msx_state *state = space->machine->driver_data<msx_state>();
1127   switch (state->slot[3]->mem_type) {
11101128   case MSX_MEM_RAM:
1111      msx1.ram_pages[3][offset] = data;
1129      state->ram_pages[3][offset] = data;
11121130      break;
11131131   case MSX_MEM_HANDLER:
1114      msx1.slot[3]->write (space->machine, msx1.state[3], 0xc000 + offset, data);
1132      state->slot[3]->write (space->machine, state->state[3], 0xc000 + offset, data);
11151133   }
11161134}
11171135
r9705r9706
11221140
11231141WRITE8_HANDLER (msx_sec_slot_w)
11241142{
1125   int slot = msx1.primary_slot >> 6;
1126   if (msx1.slot_expanded[slot])
1143   msx_state *state = space->machine->driver_data<msx_state>();
1144   int slot = state->primary_slot >> 6;
1145   if (state->slot_expanded[slot])
11271146   {
11281147      if (VERBOSE)
11291148         logerror ("write to secondary slot %d select: %02x\n", slot, data);
11301149
1131      msx1.secondary_slot[slot] = data;
1150      state->secondary_slot[slot] = data;
11321151      msx_memory_map_all (space->machine);
11331152   }
11341153   else {
r9705r9706
11381157
11391158READ8_HANDLER (msx_sec_slot_r)
11401159{
1160   msx_state *state = space->machine->driver_data<msx_state>();
11411161   UINT8 result;
1142   int slot = msx1.primary_slot >> 6;
1162   int slot = state->primary_slot >> 6;
11431163
1144   if (msx1.slot_expanded[slot])
1145      result = ~msx1.secondary_slot[slot];
1164   if (state->slot_expanded[slot])
1165      result = ~state->secondary_slot[slot];
11461166   else
1147      result = msx1.top_page[0x1fff];
1167      result = state->top_page[0x1fff];
11481168
11491169   return result;
11501170}
11511171
11521172WRITE8_HANDLER (msx_ram_mapper_w)
11531173{
1154   msx1.ram_mapper[offset] = data;
1155   if (msx1.slot[offset]->slot_type == SLOT_RAM_MM) {
1156      msx1.slot[offset]->map (space->machine, msx1.state[offset], offset);
1174   msx_state *state = space->machine->driver_data<msx_state>();
1175   state->ram_mapper[offset] = data;
1176   if (state->slot[offset]->slot_type == SLOT_RAM_MM) {
1177      state->slot[offset]->map (space->machine, state->state[offset], offset);
11571178   }
11581179}
11591180
11601181READ8_HANDLER (msx_ram_mapper_r)
11611182{
1162   return msx1.ram_mapper[offset] | msx1.ramio_set_bits;
1183   msx_state *state = space->machine->driver_data<msx_state>();
1184   return state->ram_mapper[offset] | state->ramio_set_bits;
11631185}
11641186
11651187WRITE8_HANDLER (msx_90in1_w)
11661188{
1167   msx1.korean90in1_bank = data;
1168   if (msx1.slot[1]->slot_type == SLOT_KOREAN_90IN1)
1189   msx_state *state = space->machine->driver_data<msx_state>();
1190   state->korean90in1_bank = data;
1191   if (state->slot[1]->slot_type == SLOT_KOREAN_90IN1)
11691192   {
1170      msx1.slot[1]->map (space->machine, msx1.state[1], 1);
1193      state->slot[1]->map (space->machine, state->state[1], 1);
11711194   }
1172   if (msx1.slot[2]->slot_type == SLOT_KOREAN_90IN1)
1195   if (state->slot[2]->slot_type == SLOT_KOREAN_90IN1)
11731196   {
1174      msx1.slot[2]->map (space->machine, msx1.state[2], 2);
1197      state->slot[2]->map (space->machine, state->state[2], 2);
11751198   }
11761199}
11771200
11781201READ8_HANDLER (msx_kanji_r)
11791202{
1203   msx_state *state = space->machine->driver_data<msx_state>();
11801204   UINT8 result = 0xff;
11811205
1182   if (offset && msx1.kanji_mem)
1206   if (offset && state->kanji_mem)
11831207   {
11841208      int latch;
11851209      UINT8 ret;
11861210
1187      latch = msx1.kanji_latch;
1188      ret = msx1.kanji_mem[latch++];
1211      latch = state->kanji_latch;
1212      ret = state->kanji_mem[latch++];
11891213
1190      msx1.kanji_latch &= ~0x1f;
1191      msx1.kanji_latch |= latch & 0x1f;
1214      state->kanji_latch &= ~0x1f;
1215      state->kanji_latch |= latch & 0x1f;
11921216
11931217      result = ret;
11941218   }
r9705r9706
11971221
11981222WRITE8_HANDLER (msx_kanji_w)
11991223{
1224   msx_state *state = space->machine->driver_data<msx_state>();
12001225   if (offset)
12011226   {
1202      msx1.kanji_latch =
1203            (msx1.kanji_latch & 0x007E0) | ((data & 0x3f) << 11);
1227      state->kanji_latch =
1228            (state->kanji_latch & 0x007E0) | ((data & 0x3f) << 11);
12041229   }
12051230   else
12061231   {
1207      msx1.kanji_latch =
1208            (msx1.kanji_latch & 0x1f800) | ((data & 0x3f) << 5);
1232      state->kanji_latch =
1233            (state->kanji_latch & 0x1f800) | ((data & 0x3f) << 5);
12091234   }
12101235}
src/mess/includes/msx.h
r9705r9706
1212
1313#define MSX_MAX_CARTS   (2)
1414
15typedef struct {
15class msx_state : public driver_device
16{
17public:
18   msx_state(running_machine &machine, const driver_device_config_base &config)
19      : driver_device(machine, config) { }
20
1621   /* PSG */
1722   int psg_b;
1823   int opll_active;
r9705r9706
4146   UINT8 superloadrunner_bank;
4247   UINT8 korean90in1_bank;
4348   UINT8 *top_page;
44} MSX;
49};
4550
4651
4752/*----------- defined in machine/msx.c -----------*/
4853
49extern MSX msx1;
5054extern const i8255a_interface msx_ppi8255_interface;
5155extern const wd17xx_interface msx_wd17xx_interface;
5256/* start/stop functions */
r9705r9706
7983WRITE8_HANDLER ( msx_rtc_latch_w );
8084WRITE8_HANDLER ( msx_90in1_w );
8185
82/* disk functions */
83FLOPPY_OPTIONS_EXTERN(msx);
84
8586/* new memory emulation */
8687WRITE8_HANDLER (msx_page0_w);
8788WRITE8_HANDLER (msx_page0_1_w);
r9705r9706
101102 READ8_HANDLER (msx_kanji_r);
102103WRITE8_HANDLER (msx_kanji_w);
103104
104void msx_memory_map_all (running_machine *machine);
105void msx_memory_map_page (running_machine *machine, int page);
106void msx_memory_init (running_machine *machine);
107void msx_memory_set_carts (void);
108void msx_memory_reset (running_machine *machine);
109
110
111105#endif /* __MSX_H__ */
src/mess/formats/msx_dsk.c
r0r9706
1/*********************************************************************
2
3    formats/msx_dsk.c
4
5    MSX disk images
6
7*********************************************************************/
8
9#include "msx_dsk.h"
10#include "formats/basicdsk.h"
11
12FLOPPY_OPTIONS_START(msx)
13   FLOPPY_OPTION(msx, "dsk", "MSX SS", basicdsk_identify_default, basicdsk_construct_default,
14      HEADS([1])
15      TRACKS([80])
16      SECTORS([9])
17      SECTOR_LENGTH([512])
18      FIRST_SECTOR_ID([1]))
19   FLOPPY_OPTION(msx, "dsk", "MSX DS", basicdsk_identify_default, basicdsk_construct_default,
20      HEADS([2])
21      TRACKS([80])
22      SECTORS([9])
23      SECTOR_LENGTH([512])
24      FIRST_SECTOR_ID([1]))
25FLOPPY_OPTIONS_END
src/mess/mess.mak
r9705r9706
524524   $(MESS_FORMATS)/ap_dsk35.o   \
525525   $(MESS_FORMATS)/hect_tap.o   \
526526   $(MESS_FORMATS)/ti99_dsk.o   \
527   $(MESS_FORMATS)/msx_dsk.o   \
527528
528529
529530
src/mess/drivers/amstrad.c
r9705r9706
100100/* Devices */
101101#include "devices/flopdrv.h"
102102#include "formats/basicdsk.h"
103#include "includes/msx_slot.h"
104#include "includes/msx.h"  /* MSX floppy device load */
103#include "formats/msx_dsk.h"
105104#include "devices/snapquik.h"
106105#include "devices/cartslot.h"
107106#include "devices/cassette.h"
src/mess/drivers/msx.c
r9705r9706
290290#include "devices/cartslot.h"
291291#include "devices/cassette.h"
292292#include "formats/fmsx_cas.h"
293#include "formats/msx_dsk.h"
293294#include "sound/ay8910.h"
294295#include "sound/dac.h"
295296#include "sound/wave.h"
r9705r9706
10411042   MDRV_CARTSLOT_UNLOAD(msx_cart)
10421043MACHINE_CONFIG_END
10431044
1044static MACHINE_CONFIG_START( msx, driver_device )
1045static MACHINE_CONFIG_START( msx, msx_state )
10451046   /* basic machine hardware */
10461047   MDRV_CPU_ADD("maincpu", Z80, 3579545)        /* 3.579545 MHz */
10471048   MDRV_CPU_PROGRAM_MAP(msx_memory_map)
r9705r9706
11011102#define MSX2_VISIBLE_XBORDER_PIXELS   8 * 2
11021103#define MSX2_VISIBLE_YBORDER_PIXELS   14 * 2
11031104
1104static MACHINE_CONFIG_START( msx2, driver_device )
1105static MACHINE_CONFIG_START( msx2, msx_state )
11051106   /* basic machine hardware */
11061107   MDRV_CPU_ADD("maincpu", Z80, 3579545)        /* 3.579545 MHz */
11071108   MDRV_CPU_PROGRAM_MAP(msx_memory_map)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team