Previous 199869 Revisions Next

r21078 Thursday 14th February, 2013 at 21:04:38 UTC by Wilbert Pol
(MESS) atari400.c: Reduce tagmap lookups (nw)
[src/mess/drivers]atari400.c

trunk/src/mess/drivers/atari400.c
r21077r21078
254254      , m_maincpu(*this, "maincpu")
255255      , m_ram(*this, RAM_TAG)
256256      , m_pia(*this, "pia")
257      , m_region_maincpu(*this, "maincpu")
258      , m_region_lslot(*this, "lslot")
259      , m_region_rslot(*this, "rslot")
260      , m_region_user1(*this, "user1")
261      , m_a000(*this, "a000")
262      , m_b000(*this, "b000")
263      , m_0000(*this, "0000")
264      , m_8000(*this, "8000")
265      , m_9000(*this, "9000")
266      , m_bank0(*this, "bank0")
267      , m_bank1(*this, "bank1")
268      , m_bank2(*this, "bank2")
269      , m_bank3(*this, "bank3")
270      , m_bank4(*this, "bank4")
257271      , m_a800_cart_loaded(0)
258272      , m_atari(0)
259273      , m_a800_cart_type(A800_UNKNOWN)
r21077r21078
301315   required_device<cpu_device> m_maincpu;
302316   required_device<ram_device> m_ram;
303317   required_device<pia6821_device> m_pia;
318   required_memory_region m_region_maincpu;
319   optional_memory_region m_region_lslot;
320   optional_memory_region m_region_rslot;
321   optional_memory_region m_region_user1;
322   optional_memory_bank m_a000;
323   optional_memory_bank m_b000;
324   optional_memory_bank m_0000;
325   optional_memory_bank m_8000;
326   optional_memory_bank m_9000;
327   optional_memory_bank m_bank0;
328   optional_memory_bank m_bank1;
329   optional_memory_bank m_bank2;
330   optional_memory_bank m_bank3;
331   optional_memory_bank m_bank4;
304332
305333   int m_a800_cart_loaded;
306334   int m_atari;
r21077r21078
824852
825853void a400_state::a800xl_mmu(UINT8 new_mmu)
826854{
827   UINT8 *base = memregion("maincpu")->base();
855   UINT8 *base = m_region_maincpu->base();
828856   UINT8 *base1, *base2, *base3, *base4;
829857
830858   /* check if memory C000-FFFF changed */
r21077r21078
846874      m_maincpu->space(AS_PROGRAM).install_readwrite_bank(0xc000, 0xcfff, "bank3");
847875      m_maincpu->space(AS_PROGRAM).install_readwrite_bank(0xd800, 0xffff, "bank4");
848876   }
849   membank("bank3")->set_base(base3);
850   membank("bank4")->set_base(base4);
877   m_bank3->set_base(base3);
878   m_bank4->set_base(base4);
851879
852880   /* check if BASIC changed */
853881   if( new_mmu & 0x02 )
r21077r21078
864892      base1 = base + 0x10000;  /* 8K BASIC */
865893   }
866894
867   membank("bank1")->set_base(base1);
895   m_bank1->set_base(base1);
868896
869897   /* check if self-test ROM changed */
870898   if( new_mmu & 0x80 )
r21077r21078
880908      m_maincpu->space(AS_PROGRAM).nop_write(0x5000, 0x57ff);
881909      base2 = base + 0x15000;  /* 0x0800 bytes */
882910   }
883   membank("bank2")->set_base(base2);
911   m_bank2->set_base(base2);
884912}
885913
886914/* BASIC was available in a separate cart, so we don't test it */
887915void a400_state::a1200xl_mmu(UINT8 new_mmu)
888916{
889   UINT8 *base = memregion("maincpu")->base();
917   UINT8 *base = m_region_maincpu->base();
890918   UINT8 *base2, *base3, *base4;
891919
892920   /* check if memory C000-FFFF changed */
r21077r21078
908936      m_maincpu->space(AS_PROGRAM).install_readwrite_bank(0xc000, 0xcfff, "bank3");
909937      m_maincpu->space(AS_PROGRAM).install_readwrite_bank(0xd800, 0xffff, "bank4");
910938   }
911   membank("bank3")->set_base(base3);
912   membank("bank4")->set_base(base4);
939   m_bank3->set_base(base3);
940   m_bank4->set_base(base4);
913941
914942   /* check if self-test ROM changed */
915943   if( new_mmu & 0x80 )
r21077r21078
925953      m_maincpu->space(AS_PROGRAM).install_read_bank(0x5000, 0x57ff, "bank2");
926954      m_maincpu->space(AS_PROGRAM).unmap_write(0x5000, 0x57ff);
927955   }
928   membank("bank2")->set_base(base2);
956   m_bank2->set_base(base2);
929957}
930958
931959void a400_state::xegs_mmu(UINT8 new_mmu)
932960{
933   UINT8 *base = memregion("maincpu")->base();
961   UINT8 *base = m_region_maincpu->base();
934962   UINT8 *base2, *base3, *base4;
935963
936964   /* check if memory C000-FFFF changed */
r21077r21078
952980      m_maincpu->space(AS_PROGRAM).install_readwrite_bank(0xc000, 0xcfff, "bank3");
953981      m_maincpu->space(AS_PROGRAM).install_readwrite_bank(0xd800, 0xffff, "bank4");
954982   }
955   membank("bank3")->set_base(base3);
956   membank("bank4")->set_base(base4);
983   m_bank3->set_base(base3);
984   m_bank4->set_base(base4);
957985
958986
959987   /* check if self-test ROM changed */
r21077r21078
970998      m_maincpu->space(AS_PROGRAM).nop_write(0x5000, 0x57ff);
971999      base2 = base + 0x15000;  /* 0x0800 bytes */
9721000   }
973   membank("bank2")->set_base(base2);
1001   m_bank2->set_base(base2);
9741002}
9751003
9761004
r21077r21078
9811009   // take care of 0x0000-0x7fff: RAM or NOP
9821010   ram_top = MIN(m_ram->size(), 0x8000) - 1;
9831011   m_maincpu->space(AS_PROGRAM).install_readwrite_bank(0x0000, ram_top, "0000");
984   membank("0000")->set_base(m_ram->pointer());
1012   if ( m_0000 == NULL )
1013   {
1014      m_0000.findit();
1015   }
1016   m_0000->set_base(m_ram->pointer());
9851017
9861018   // take care of 0x8000-0x9fff: A800 -> either right slot or RAM or NOP, others -> RAM or NOP
9871019   // is there anything in the right slot?
9881020   if (cart_mounted & RIGHT_CARTSLOT_MOUNTED)
9891021   {
9901022      m_maincpu->space(AS_PROGRAM).install_read_bank(0x8000, 0x9fff, "8000");
991      membank("8000")->set_base(memregion("rslot")->base());
1023      if ( m_8000 == NULL )
1024      {
1025         m_8000.findit();
1026      }
1027      m_8000->set_base(m_region_rslot->base());
9921028      m_maincpu->space(AS_PROGRAM).unmap_write(0x8000, 0x9fff);
9931029   }
9941030   else if (m_a800_cart_type != BBSB)
r21077r21078
9971033      if (ram_top > 0x8000)
9981034      {
9991035         m_maincpu->space(AS_PROGRAM).install_readwrite_bank(0x8000, ram_top, "8000");
1000         membank("8000")->set_base(m_ram->pointer() + 0x8000);
1036         if ( m_8000 == NULL )
1037         {
1038            m_8000.findit();
1039         }
1040         m_8000->set_base(m_ram->pointer() + 0x8000);
10011041      }
10021042   }
10031043
r21077r21078
10101050         if (m_a800_cart_type == A800_16K)
10111051         {
10121052            m_maincpu->space(AS_PROGRAM).install_read_bank(0x8000, 0x9fff, "8000");
1013            membank("8000")->set_base(memregion("lslot")->base());
1053            if ( m_8000 == NULL )
1054            {
1055               m_8000.findit();
1056            }
1057            m_8000->set_base(m_region_lslot->base());
10141058            m_maincpu->space(AS_PROGRAM).unmap_write(0x8000, 0x9fff);
10151059
1016            memcpy(memregion("maincpu")->base() + 0x10000, memregion("lslot")->base() + 0x2000, 0x2000);
1060            memcpy(m_region_maincpu->base() + 0x10000, m_region_lslot->base() + 0x2000, 0x2000);
10171061         }
10181062         else if (m_a800_cart_type == A800_8K)
1019            memcpy(memregion("maincpu")->base() + 0x10000, memregion("lslot")->base(), 0x2000);
1063            memcpy(m_region_maincpu->base() + 0x10000, m_region_lslot->base(), 0x2000);
10201064         else
10211065            fatalerror("This type of cart is not supported yet in this driver. Please use a400 or a800.\n");
10221066      }
10231067      else if (m_a800_cart_type == A800_16K)
10241068      {
1025         membank("8000")->set_base(memregion("lslot")->base());
1026         membank("a000")->set_base(memregion("lslot")->base() + 0x2000);
1069         m_8000->set_base(m_region_lslot->base());
1070         m_a000->set_base(m_region_lslot->base() + 0x2000);
10271071         m_maincpu->space(AS_PROGRAM).unmap_write(0x8000, 0xbfff);
10281072      }
10291073      else if (m_a800_cart_type == BBSB)
10301074      {
10311075         // this requires separate banking in 0x8000 & 0x9000!
10321076         m_maincpu->space(AS_PROGRAM).install_read_bank(0x8000, 0x8fff, "8000");
1077         if ( m_8000 == NULL )
1078         {
1079            m_8000.findit();
1080         }
10331081         m_maincpu->space(AS_PROGRAM).install_read_bank(0x9000, 0x9fff, "9000");
1034         membank("8000")->set_base(memregion("lslot")->base() + 0x0000);
1035         membank("9000")->set_base(memregion("lslot")->base() + 0x4000);
1036         membank("a000")->set_base(memregion("lslot")->base() + 0x8000);
1082         if ( m_9000 == NULL )
1083         {
1084            m_9000.findit();
1085         }
1086         m_8000->set_base(m_region_lslot->base() + 0x0000);
1087         m_9000->set_base(m_region_lslot->base() + 0x4000);
1088         m_a000->set_base(m_region_lslot->base() + 0x8000);
10371089         m_maincpu->space(AS_PROGRAM).unmap_write(0xa000, 0xbfff);
10381090      }
10391091      else if (m_a800_cart_type == OSS_034M)
10401092      {
10411093         // this requires separate banking in 0xa000 & 0xb000!
10421094         m_maincpu->space(AS_PROGRAM).install_read_bank(0xa000, 0xafff, "a000");
1095         if ( m_a000 == NULL )
1096         {
1097            m_a000.findit();
1098         }
10431099         m_maincpu->space(AS_PROGRAM).install_read_bank(0xb000, 0xbfff, "b000");
1044         membank("b000")->set_base(memregion("lslot")->base() + 0x3000);
1100         if ( m_b000 == NULL )
1101         {
1102            m_b000.findit();
1103         }
1104         m_b000->set_base(m_region_lslot->base() + 0x3000);
10451105         m_maincpu->space(AS_PROGRAM).unmap_write(0xa000, 0xbfff);
10461106      }
10471107      else if (m_a800_cart_type == OSS_M091)
10481108      {
10491109         // this requires separate banking in 0xa000 & 0xb000!
10501110         m_maincpu->space(AS_PROGRAM).install_read_bank(0xa000, 0xafff, "a000");
1111         if ( m_a000 == NULL )
1112         {
1113            m_a000.findit();
1114         }
10511115         m_maincpu->space(AS_PROGRAM).install_read_bank(0xb000, 0xbfff, "b000");
1052         membank("b000")->set_base(memregion("lslot")->base());
1116         if ( m_b000 == NULL )
1117         {
1118            m_b000.findit();
1119         }
1120         m_b000->set_base(m_region_lslot->base());
10531121         m_maincpu->space(AS_PROGRAM).unmap_write(0xa000, 0xbfff);
10541122      }
10551123      else if (m_a800_cart_type == XEGS_32K)
10561124      {
1057         membank("8000")->set_base(memregion("lslot")->base());
1058         membank("a000")->set_base(memregion("lslot")->base() + 0x6000);
1125         m_8000->set_base(m_region_lslot->base());
1126         m_a000->set_base(m_region_lslot->base() + 0x6000);
10591127         m_maincpu->space(AS_PROGRAM).unmap_write(0x8000, 0xbfff);
10601128      }
10611129      else
10621130      {
1063         membank("a000")->set_base(memregion("lslot")->base());
1131         m_a000->set_base(m_region_lslot->base());
10641132         m_maincpu->space(AS_PROGRAM).unmap_write(0xa000, 0xbfff);
10651133      }
10661134   }
r21077r21078
11301198{
11311199   //  printf("written %x\n", data);
11321200   int bank = data & 0x03;
1133   membank("8000")->set_base(memregion("lslot")->base() + bank * 0x2000);
1201   m_8000->set_base(m_region_lslot->base() + bank * 0x2000);
11341202}
11351203
11361204
r21077r21078
11391207//  printf("write to %x\n", offset);
11401208
11411209   if (offset < 8)
1142      membank("a000")->set_base(memregion("lslot")->base() + offset * 0x2000);
1210      m_a000->set_base(m_region_lslot->base() + offset * 0x2000);
11431211   else
1144      membank("a000")->set_base(memregion("maincpu")->base());
1212      m_a000->set_base(m_region_maincpu->base());
11451213   // FIXME: writes to 0x8-0xf should disable the cart
11461214}
11471215
r21077r21078
11521220//  printf("write to %x\n", offset);
11531221
11541222   if (offset < 8)
1155      membank("a000")->set_base(memregion("lslot")->base() + (7 - offset) * 0x2000);
1223      m_a000->set_base(m_region_lslot->base() + (7 - offset) * 0x2000);
11561224   else
1157      membank("a000")->set_base(memregion("maincpu")->base());
1225      m_a000->set_base(m_region_maincpu->base());
11581226   // FIXME: writes to 0x8-0xf should disable the cart
11591227}
11601228
r21077r21078
11631231{
11641232//  printf("write to %x\n", 0x8000 + offset);
11651233   if (offset >= 0xff6 && offset <= 0xff9)
1166      membank("8000")->set_base(memregion("lslot")->base() + 0x0000 + (offset - 0xff6) * 0x1000);
1234      m_8000->set_base(m_region_lslot->base() + 0x0000 + (offset - 0xff6) * 0x1000);
11671235}
11681236
11691237
r21077r21078
11711239{
11721240//  printf("write to %x\n", 0x9000 + offset);
11731241   if (offset >= 0xff6 && offset <= 0xff9)
1174      membank("9000")->set_base(memregion("lslot")->base() + 0x4000 + (offset - 0xff6) * 0x1000);
1242      m_9000->set_base(m_region_lslot->base() + 0x4000 + (offset - 0xff6) * 0x1000);
11751243}
11761244
11771245
r21077r21078
11811249   {
11821250      case 0:
11831251      case 1:
1184         membank("a000")->set_base(memregion("lslot")->base());
1185         membank("b000")->set_base(memregion("lslot")->base() + 0x3000);
1252         m_a000->set_base(m_region_lslot->base());
1253         m_b000->set_base(m_region_lslot->base() + 0x3000);
11861254         break;
11871255      case 2:
11881256      case 6:
11891257         // docs says this should put 0xff in the 0xa000 bank -> let's point to the end of the cart
1190         membank("a000")->set_base(memregion("lslot")->base() + 0x4000);
1191         membank("b000")->set_base(memregion("lslot")->base() + 0x3000);
1258         m_a000->set_base(m_region_lslot->base() + 0x4000);
1259         m_b000->set_base(m_region_lslot->base() + 0x3000);
11921260         break;
11931261      case 3:
11941262      case 7:
1195         membank("a000")->set_base(memregion("lslot")->base() + 0x1000);
1196         membank("b000")->set_base(memregion("lslot")->base() + 0x3000);
1263         m_a000->set_base(m_region_lslot->base() + 0x1000);
1264         m_b000->set_base(m_region_lslot->base() + 0x3000);
11971265         break;
11981266      case 4:
11991267      case 5:
1200         membank("a000")->set_base(memregion("lslot")->base() + 0x2000);
1201         membank("b000")->set_base(memregion("lslot")->base() + 0x3000);
1268         m_a000->set_base(m_region_lslot->base() + 0x2000);
1269         m_b000->set_base(m_region_lslot->base() + 0x3000);
12021270         break;
12031271      default:
1204         membank("a000")->set_base(memregion("maincpu")->base() + 0xa000);
1205         membank("b000")->set_base(memregion("maincpu")->base() + 0xb000);
1272         m_a000->set_base(m_region_maincpu->base() + 0xa000);
1273         m_b000->set_base(m_region_maincpu->base() + 0xb000);
12061274         break;
12071275   }
12081276}
r21077r21078
12131281   switch (offset & 0x09)
12141282   {
12151283      case 0:
1216         membank("a000")->set_base(memregion("lslot")->base() + 0x1000);
1217         membank("b000")->set_base(memregion("lslot")->base());
1284         m_a000->set_base(m_region_lslot->base() + 0x1000);
1285         m_b000->set_base(m_region_lslot->base());
12181286         break;
12191287      case 1:
1220         membank("a000")->set_base(memregion("lslot")->base() + 0x3000);
1221         membank("b000")->set_base(memregion("lslot")->base());
1288         m_a000->set_base(m_region_lslot->base() + 0x3000);
1289         m_b000->set_base(m_region_lslot->base());
12221290         break;
12231291      case 8:
1224         membank("a000")->set_base(memregion("maincpu")->base() + 0xa000);
1225         membank("b000")->set_base(memregion("maincpu")->base() + 0xb000);
1292         m_a000->set_base(m_region_maincpu->base() + 0xa000);
1293         m_b000->set_base(m_region_maincpu->base() + 0xb000);
12261294         break;
12271295      case 9:
1228         membank("a000")->set_base(memregion("lslot")->base() + 0x2000);
1229         membank("b000")->set_base(memregion("lslot")->base());
1296         m_a000->set_base(m_region_lslot->base() + 0x2000);
1297         m_b000->set_base(m_region_lslot->base());
12301298         break;
12311299   }
12321300}
r21077r21078
12341302
12351303WRITE8_MEMBER( a400_state::xegs_bankswitch )
12361304{
1237   UINT8 *cart = memregion("user1")->base();
1305   UINT8 *cart = m_region_user1->base();
12381306   data &= m_xegs_banks - 1;
1239   membank("bank0")->set_base(cart + data * 0x2000);
1307   m_bank0->set_base(cart + data * 0x2000);
12401308}
12411309
12421310MACHINE_START_MEMBER( a400_state, xegs )
12431311{
12441312   address_space &space = m_maincpu->space(AS_PROGRAM);
1245   UINT8 *cart = memregion("user1")->base();
1246   UINT8 *cpu  = memregion("maincpu")->base();
1313   UINT8 *cart = m_region_user1->base();
1314   UINT8 *cpu  = m_region_maincpu->base();
12471315
12481316   atari_machine_start(machine());
12491317   space.install_write_handler(0xd500, 0xd5ff, write8_delegate(FUNC(a400_state::xegs_bankswitch),this));
12501318
12511319   if (m_xegs_cart)
12521320   {
1253      membank("bank0")->set_base(cart);
1254      membank("bank1")->set_base(cart + (m_xegs_banks - 1) * 0x2000);
1321      m_bank0->set_base(cart);
1322      m_bank1->set_base(cart + (m_xegs_banks - 1) * 0x2000);
12551323   }
12561324   else
12571325   {
12581326      // point to built-in Missile Command (this does not work well, though... FIXME!!)
1259      membank("bank0")->set_base(cpu + 0x10000);
1260      membank("bank1")->set_base(cpu + 0x10000);
1327      m_bank0->set_base(cpu + 0x10000);
1328      m_bank1->set_base(cpu + 0x10000);
12611329   }
12621330}
12631331
r21077r21078
14411509         size -= 0x10;
14421510         start = 0x10;
14431511      }
1444      image.fread(memregion("lslot")->base(), size - start);
1512      image.fread(m_region_lslot->base(), size - start);
14451513   }
14461514   else
14471515   {
14481516      size = image.get_software_region_length("rom");
1449      memcpy(memregion("lslot")->base(), image.get_software_region("rom"), size);
1517      memcpy(m_region_lslot->base(), image.get_software_region("rom"), size);
14501518   }
14511519
14521520   m_a800_cart_loaded |= (size > 0x0000) ? 1 : 0;
r21077r21078
14741542         size -= 0x10;
14751543         start = 0x10;
14761544      }
1477      image.fread(memregion("rslot")->base(), size - start);
1545      image.fread(m_region_rslot->base(), size - start);
14781546   }
14791547   else
14801548   {
14811549      size = image.get_software_region_length("rom");
1482      memcpy(memregion("rslot")->base(), image.get_software_region("rom"), size);
1550      memcpy(m_region_rslot->base(), image.get_software_region("rom"), size);
14831551   }
14841552
14851553   m_a800_cart_loaded |= (size > 0x0000) ? 2 : 0;
r21077r21078
15071575
15081576DEVICE_IMAGE_LOAD_MEMBER( a400_state, a5200_cart )
15091577{
1510   UINT8 *mem = memregion("maincpu")->base();
1578   UINT8 *mem = m_region_maincpu->base();
15111579   UINT32 size;
15121580   bool A13_mirr = FALSE;
15131581
r21077r21078
15481616
15491617DEVICE_IMAGE_UNLOAD_MEMBER( a400_state, a5200_cart )
15501618{
1551   UINT8 *mem = memregion("maincpu")->base();
1619   UINT8 *mem = m_region_maincpu->base();
15521620   /* zap the cartridge memory (again) */
15531621   memset(&mem[0x4000], 0x00, 0x8000);
15541622}
r21077r21078
15571625DEVICE_IMAGE_LOAD_MEMBER( a400_state, xegs_cart )
15581626{
15591627   UINT32 size;
1560   UINT8 *ptr = memregion("user1")->base();
1628   UINT8 *ptr = m_region_user1->base();
15611629
15621630   if (image.software_entry() == NULL)
15631631   {
r21077r21078
21902258
21912259DRIVER_INIT_MEMBER(a400_state,a600xl)
21922260{
2193   UINT8 *rom = memregion("maincpu")->base();
2261   UINT8 *rom = m_region_maincpu->base();
21942262   memcpy( rom + 0x5000, rom + 0xd000, 0x800 );
21952263}
21962264

Previous 199869 Revisions Next


© 1997-2024 The MAME Team