Previous 15994 Revisions Next

r8276 Monday 14th June, 2010 at 23:30:12 UTC by Michael Zapf
Provides GRAM Kracker emulation
[src/mess/devices]ti99cart.c
[src/mess/drivers]ti99_4x.c ti99_8.c
[src/mess/machine]ti99_4x.c ti99_4x.h

src/mess/devices/ti99cart.c
r8275r8276
2323#define TI99_CARTRIDGE_PCB_MBX      DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_mbx)
2424#define TI99_CARTRIDGE_PCB_PAGED379I   DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_paged379i)
2525#define TI99_CARTRIDGE_PCB_PAGEDCRU   DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_pagedcru)
26#define TI99_CARTRIDGE_PCB_GRAMKRACKER   DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_gramkracker)
2627
2728/* Generic TI99 cartridge structure. */
2829struct _cartridge_t
2930{
30   /* PCB device associated to this cartridge. If NULL, the slot is empty. */
31   // PCB device associated to this cartridge. If NULL, the slot is empty.
3132   running_device *pcb;
3233
33   /* GROM buffer size. */
34   // GROM buffer size.
3435   int grom_size;
35   
36   /* ROM page. */
36
37   // ROM page.
3738   int rom_page;
38   /* RAM page. */
39
40   // RAM page.
3941   int ram_page;
40   
41   /* ROM buffer size. All banks have equal sizes. */
42
43   // ROM buffer size. All banks have equal sizes.
4244   int rom_size;
43   /* RAM buffer size. All banks have equal sizes. */
45   // RAM buffer size. All banks have equal sizes.
4446   int ram_size;
45   
46   /* pointer to GROM data. */
47
48   // pointer to GROM data.
4749   UINT8 *grom_ptr;
48   
49   /* GROM buffered data output. */
50   /*        UINT8 grom_buffer; */ /* Now handled by the multicart system. */
51   
52   /* ROM buffer. We are using this for both 16 bit (99/4a) and 8 bit
53   (99/8) access. */
50
51   // ROM buffer. We are using this for both 16 bit (99/4a) and 8 bit
52   // (99/8) access.
5453   void *rom_ptr;
55   
56   /* ROM buffer for the second bank of paged cartridges. Other cartridges
57   usually store their ROM in one large file. */
54
55   // ROM buffer for the second bank of paged cartridges. Other cartridges
56   // usually store their ROM in one large file.
5857   void *rom2_ptr;
59   
60   /* RAM buffer. The persistence service is done by the cartridge system.
61   The RAM space is a consecutive space; all banks are in one buffer. */
58
59   // RAM buffer. The persistence service is done by the cartridge system.
60   // The RAM space is a consecutive space; all banks are in one buffer.
6261   void *ram_ptr;
6362};
6463typedef struct _cartridge_t cartridge_t;
r8275r8276
8685
8786struct _ti99_multicart_state
8887{
89   /* Reserves space for all cartridges. This is also used in the legacy
90    cartridge system, but only for slot 0. */
88   // Reserves space for all cartridges. This is also used in the legacy
89   // cartridge system, but only for slot 0.
9190   cartridge_t cartridge[NUMBER_OF_CARTRIDGE_SLOTS];
9291
93   /* Determines which slot is currently active. This value is changed when there
94    are accesses to other GROM base addresses. */
92   // Determines which slot is currently active. This value is changed when
93   // there are accesses to other GROM base addresses.
9594   int active_slot;
9695
97   /* Used in order to enforce a special slot. This value is retrieved
98    from the dipswitch setting. A value of -1 means automatic, that is,
99    the grom base switch is used. Values 0 .. max refer to the
100    respective slot. */
96   // Used in order to enforce a special slot. This value is retrieved
97   // from the dipswitch setting. A value of -1 means automatic, that is,
98   // the grom base switch is used. Values 0 .. max refer to the
99   // respective slot.
101100   int fixed_slot;
102101
103   /* Holds the highest index of a cartridge being plugged in plus one.
104    If we only have one cartridge inserted, we don't want to get a
105    selection option, so we just mirror the memory contents. */
102   // Contains the slot number of the GRAM Kracker
103   int gk_slot;
104
105   // Contains the slot number of the GK guest (which is the cartridge
106   // plugged into the GK)
107   int gk_guest_slot;
108
109   // Holds the highest index of a cartridge being plugged in plus one.
110   // If we only have one cartridge inserted, we don't want to get a
111   // selection option, so we just mirror the memory contents.
106112   int next_free_slot;
107113
108   /* Counts the number of slots which currently contain legacy format
109    cartridge images. */
114   // Counts the number of slots which currently contain legacy format
115   // cartridge images.
110116   int legacy_slots;
111117
112   /* Counts the number of slots which currently contain new format
113    cartridge images. */
118   // Counts the number of slots which currently contain new format
119   // cartridge images.
114120   int multi_slots;
115121
116   /* Legacy mode. Stores the slot number where the cartridge part is mounted.
117    Index is from slotc_type_t. */
122   // Legacy mode. Stores the slot number where the cartridge part is
123   // mounted. Index is from slotc_type_t.
118124   int legacy_slotnumber[5];
119125
120   /* current address pointer for the active GROM in port (16 bits) */
126   // Current address pointer for the active GROM in port (16 bits)
121127   UINT16 grom_address;
122   /* GROM data buffer */
128
129   // GROM data buffer
123130   UINT8 grom_buffer;
124131
125   /* internal flip-flops that are set after the first access to the GROM
126    address so that next access is mapped to the LSB, and cleared after each
127    data access */
132   // Hack for GRAM Kracker. Flag to remember whether we switched the
133   // loader area. (The GK utility assumes that it is not important whether
134   // the GROM address is set before or after the loader bank has been
135   // manually switched, but this will fail here.)
136   int loader_on;
137
138   // Internal flip-flops that are set after the first access to the GROM
139   // address so that next access is mapped to the LSB, and cleared after
140   // each data access
128141   char raddr_LSB, waddr_LSB;
129142};
130143typedef struct _ti99_multicart_state ti99_multicart_state;
r8275r8276
146159static void unload_legacy(running_device *image);
147160static int load_legacy(running_device *image);
148161
162static int cartridge_gram_kracker_readg(running_device *cartsys);
163static void cartridge_gram_kracker_writeg(running_device *cartsys, UINT8 data);
164
149165/* Access to the pcb. Contained in the token of the pcb instance. */
150166struct _ti99_pcb_t
151167{
r8275r8276
257273   cart->rom2_ptr = NULL;
258274   cart->ram_ptr = NULL;
259275   cart->grom_ptr = NULL;
276
277   if (slotnumber==cartslots->gk_guest_slot)
278      cartslots->gk_guest_slot = -1;
260279}
261280
262281static void grom_write_address(ti99_multicart_state *cartslots, UINT8 data)
r8275r8276
286305{
287306   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
288307
289   /* Set the cart slot. Note that the port must be adjusted for 16-bit
290       systems, i.e. it should be shifted left by 1.
291        // 1001 1wbb bbbb bbr0
292    */
308   // Set the cart slot. Note that the port must be adjusted for 16-bit
309   // systems, i.e. it should be shifted left by 1.
310   // 1001 1wbb bbbb bbr0
311
293312   cartridge_slot_set(device, (offset>>2) & 0x00ff);
294313
295314   if (offset & 0x0002)
296315      grom_write_address(cartslots, data);
297316   else
317   {
298318      cartslots->raddr_LSB = cartslots->waddr_LSB = FALSE;
299      /* TODO: write to GRAM */
319
320      // Handle the GRAM Kracker
321      if ((cartslots->gk_slot != -1) && (input_port_read(device->machine, "CARTSLOT")==CART_GK))
322         cartridge_gram_kracker_writeg(device,data);
323   }
300324}
301325
302326/*
r8275r8276
306330static UINT8 grom_read_address(ti99_multicart_state *cartslots)
307331{
308332   UINT8 reply;
309   /* When reading, reset the hi/lo flag byte for writing.
310    TODO: Verify this with a real machine. */
333   // When reading, reset the hi/lo flag byte for writing.
334   // TODO: Verify this with a real machine.
311335   cartslots->waddr_LSB = FALSE;
312336
313   /* Address reading is done in two steps; first, the high byte
314    is transferred, then the low byte. */
337   // Address reading is done in two steps; first, the high byte
338   // is transferred, then the low byte.
315339   if (cartslots->raddr_LSB)
316340   {
317341      /* second pass */
r8275r8276
348372   cartridge_t *cartridge;
349373   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
350374
351   /* Set the cart slot. Note that the port must be adjusted for 16-bit
352       systems, i.e. it should be shifted left by 1.
353        1001 1wbb bbbb bbr0
354    */
375   // Set the cart slot. Note that the port must be adjusted for 16-bit
376   // systems, i.e. it should be shifted left by 1.
377   // 1001 1wbb bbbb bbr0
378
355379   cartridge_slot_set(device, (offset>>2) & 0x00ff);
356380
357381   if (offset & 0x0002)
358382      return grom_read_address(cartslots);
359383
384   // Handle the GRAM Kracker
385   if ((cartslots->gk_slot != -1) && (input_port_read(device->machine, "CARTSLOT")==CART_GK))
386      return cartridge_gram_kracker_readg(device);
387
360388   /* Handle the legacy mode. */
361389   if (in_legacy_mode(device))
362390      return cartridge_grom_read_legacy(device);
363391
364392   slot = cartslots->active_slot;
365   /*
366        This fixes a minor issue: The selection mechanism of the console
367        concludes that there are multiple cartridges plugged in when it
368        checks the different GROM bases and finds different data. Empty
369        slots should return 0 at all addresses, but when we have only
370        one cartridge, this entails that the second cartridge is
371        different (all zeros), and so we get a meaningless selection
372        option between cartridge 1 and 1 and 1 ...
373393
374        So if next_free_slot==1, we have one cartridge in slot 0.
375        In that case we trick the OS to believe that the addressed
376        cartridge appears at all locations which causes it to assume a
377        standard single cartslot.
378    */
394   // This fixes a minor issue: The selection mechanism of the console
395   // concludes that there are multiple cartridges plugged in when it
396   // checks the different GROM bases and finds different data. Empty
397   // slots should return 0 at all addresses, but when we have only
398   // one cartridge, this entails that the second cartridge is
399   // different (all zeros), and so we get a meaningless selection
400   // option between cartridge 1 and 1 and 1 ...
401   //
402   // So if next_free_slot==1, we have one cartridge in slot 0.
403   // In that case we trick the OS to believe that the addressed
404   // cartridge appears at all locations which causes it to assume a
405   // standard single cartslot.
406
379407   if (cartslots->fixed_slot==AUTO && cartslots->next_free_slot==1)
380408      slot=0;
381409
r8275r8276
386414      cartridge = &cartslots->cartridge[slot];
387415      if ((cartridge->grom_size>0) && (cartridge->pcb!=NULL))
388416      {
389         /* This is the reason why we need the image size: Read
390            access beyond the image size must be detected. */
417         // This is the reason why we need the image size: Read
418         // access beyond the image size must be detected. */
391419         /* TODO: replace this using a bitmap of the available GROMs */
392420         if ((cartslots->grom_address < 0x6000) || (cartslots->grom_address > (cartridge->grom_size+0x6000)))
393421            value = 0;
r8275r8276
411439   /* so 0x5fff + 1 = 0x4000. */
412440   /* The address must be increased even if there is no cartridge slot */
413441   cartslots->grom_address = ((cartslots->grom_address + 1) & 0x1FFF) | (cartslots->grom_address & 0xE000);
414   
442
415443   /* Reset the read and write address flipflops. */
416444   cartslots->raddr_LSB = cartslots->waddr_LSB = FALSE;
417445
r8275r8276
458486   }
459487   cartridge = &cartslots->cartridge[slotnumber];
460488
461   /* Get the socket which is retrieved by the multicart instance in
462    the state of the cartslot instance. */
489   // Get the socket which is retrieved by the multicart instance in
490   // the state of the cartslot instance.
463491   socketcont = cartslot_get_socket(cartslot, "grom_socket");
464492   reslength = cartslot_get_resource_length(cartslot, "grom_socket");
465493   if (socketcont != NULL)
r8275r8276
512540            cont16b[i] = BIG_ENDIANIZE_INT16(cont16b[i]);
513541      }
514542   }
543
544   // If the GRAM Kracker is plugged in, this cartridge may become the
545   // guest
546   if (cartslots->gk_slot != -1)
547   {
548      for (i=0; i < NUMBER_OF_CARTRIDGE_SLOTS; i++)
549      {
550         if (!slot_is_empty(cartsys, i) && (i != cartslots->gk_slot))
551         {
552            cartslots->gk_guest_slot = i;
553            break;
554         }
555      }
556   }
515557   return cartridge;
516558}
517559
r8275r8276
543585static DEVICE_START(ti99_pcb_none)
544586{
545587   /* device is ti99_cartslot:cartridge:pcb */
546//  printf("DEVICE_START(ti99_pcb_none), tag of device=%s\n", device->tag());
547588   set_pointers(device, get_index_from_tagname(device->owner)-1);
548589}
549590
r8275r8276
556597static DEVICE_START(ti99_pcb_std)
557598{
558599   /* device is ti99_cartslot:cartridge:pcb */
559//  printf("DEVICE_START(ti99_pcb_std), tag of device=%s\n", device->tag());
560600   set_pointers(device, get_index_from_tagname(device->owner)-1);
561601}
562602
r8275r8276
573613
574614   if (cartridge->rom_ptr==NULL)
575615   {
576//      printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot);
577//      printf("Cartridge address = %lx\n", (long)pcb->cartridge);
578616      value = 0;
579617   }
580618   else
581619   {
582620      value = ((UINT16 *)cartridge->rom_ptr)[offset];
583//      printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value);
584621   }
585//  printf("accessed cartridge rom[%02x:%04x] = %04x\n", 0, 0x6000+offset*2, value);
586622   return value;
587623}
588624
589625static WRITE16_DEVICE_HANDLER( write_cart_std )
590626{
591   logerror("Write access to cartridge ROM at address %04x ignored", 0x6000 + 2*offset);
627   logerror("Write access to cartridge ROM at address %04x ignored\n", 0x6000 + 2*offset);
592628}
593629
594630/*
r8275r8276
625661*/
626662static int assemble_std(running_device *image)
627663{
628//  cartridge_t *cart;
629//  printf("assemble_std, %s\n", image->tag);
630   /*cart = */assemble_common(image);
631
664   assemble_common(image);
632665   return INIT_PASS;
633666}
634667
r8275r8276
648681   ti99_multicart_state *cartslots = (ti99_multicart_state *)cartsys->token;
649682
650683   slotnumber = get_index_from_tagname(image)-1;
651//  printf("Disassemble cartridge %d\n", slotnumber);
652684
653685   /* Search the highest remaining cartridge. */
654686   cartslots->next_free_slot = 0;
r8275r8276
659691         if (!slot_is_empty(cartsys, i))
660692         {
661693            cartslots->next_free_slot = i+1;
662//              printf("Setting new next_free_slot to %d\n", cartslots->next_free_slot);
663694            break;
664695         }
665696      }
r8275r8276
690721static DEVICE_START(ti99_pcb_paged)
691722{
692723   /* device is ti99_cartslot:cartridge:pcb */
693//  printf("DEVICE_START(ti99_pcb_paged), tag of device=%s\n", device->tag());
694724   set_pointers(device, get_index_from_tagname(device->owner)-1);
695725}
696726
r8275r8276
713743
714744   if (rombank==NULL)
715745   {
716//      printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot);
717//      printf("Cartridge address = %lx\n", (long)pcb->cartridge);
718746      /* TODO: Check for consistency with the GROM memory handling. */
719747      value = 0;
720748   }
721749   else
722750   {
723751      value = rombank[offset];
724//      printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value);
725752   }
726//  printf("accessed cartridge rom[%02x:%04x] = %04x\n", rompage, 0x6000+offset*2, value);
727753   return value;
728754}
729755
r8275r8276
738764   ti99_pcb_t *pcb = (ti99_pcb_t *)device->token;
739765   cartridge_t *cartridge = pcb->cartridge;
740766   cartridge->rom_page = offset & 1;
741//  printf("setting rompage to %d\n", cartridge->rom_page);
742767}
743768
744769/*
r8275r8276
781806{
782807   ti99_pcb_t *pcb = (ti99_pcb_t *)device->token;
783808   cartridge_t *cartridge = pcb->cartridge;
784//  printf("offset = %04x\n", offset);
785809   cartridge->rom_page = (offset>>1) & 1;
786810}
787811
r8275r8276
792816{
793817   cartridge_t *cart;
794818
795//  printf("assemble_paged, %s\n", image->tag);
796819   cart = assemble_common(image);
797820   if (cart->rom_ptr==NULL)
798821   {
r8275r8276
817840
818841static DEVICE_START(ti99_pcb_minimem)
819842{
820//  printf("TI99 pcb minimem start\n");
821843   set_pointers(device, get_index_from_tagname(device->owner)-1);
822844}
823845
r8275r8276
832854   {
833855      if (cartridge->rom_ptr==NULL)
834856      {
835         //      printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot);
836         //      printf("Cartridge address = %lx\n", (long)pcb->cartridge);
837857         value = 0;
838858      }
839859      else
840860      {
841861         value = ((UINT16 *)cartridge->rom_ptr)[offset];
842         //      printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value);
843862      }
844      //  printf("accessed cartridge rom[%02x:%04x] = %04x\n", rompage, 0x6000+offset*2, value);
845863   }
846864   else
847865   {
848866      if (cartridge->ram_ptr==NULL)
849867      {
850         //      printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot);
851         //      printf("Cartridge address = %lx\n", (long)pcb->cartridge);
852868         value = 0;
853869      }
854870      else
855871      {
856872         value = ((UINT16 *)cartridge->ram_ptr)[offset-0x800];
857         //      printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value);
858873      }
859      //  printf("accessed cartridge rom[%02x:%04x] = %04x\n", rompage, 0x6000+offset*2, value);
860874   }
861875   return value;
862876}
r8275r8276
879893      if (cartridge->ram_ptr==NULL)
880894      {
881895         logerror("No cartridge RAM at address %04x", 0x6000 + 2*offset);
882
883         //      printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot);
884         //      printf("Cartridge address = %lx\n", (long)pcb->cartridge);
885896         /* TODO: Check for consistency with the GROM memory handling. */
886897      }
887898      else
r8275r8276
945956      if (cartridge->ram_ptr==NULL)
946957      {
947958         logerror("No cartridge RAM at address %04x", 0x6000 + offset);
948
949         //      printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot);
950         //      printf("Cartridge address = %lx\n", (long)pcb->cartridge);
951959         /* TODO: Check for consistency with the GROM memory handling. */
952960      }
953961      else
r8275r8276
962970{
963971   cartridge_t *cart;
964972
965//  printf("assemble_minimem, %s\n", image->tag);
966973   cart = assemble_common(image);
967974   if (cart->grom_size==0)
968975   {
969976      logerror("Missing GROM for Mini Memory");
970      return INIT_FAIL;
977      // should not fail here because there may be variations of
978      // cartridges which do not use all parts
979//      return INIT_FAIL;
971980   }
972981   if (cart->rom_size==0)
973982   {
974983      logerror("Missing ROM for Mini Memory");
975      return INIT_FAIL;
984//      return INIT_FAIL;
976985   }
977986   if (cart->ram_size==0)
978987   {
979988      logerror("Missing RAM for Mini Memory");
980      return INIT_FAIL;
989//      return INIT_FAIL;
981990   }
982991
983992   return INIT_PASS;
r8275r8276
10031012
10041013static DEVICE_START(ti99_pcb_super)
10051014{
1006//  printf("TI99 pcb super start\n");
10071015   set_pointers(device, get_index_from_tagname(device->owner)-1);
10081016}
10091017
r8275r8276
10151023{
10161024   ti99_pcb_t *pcb = (ti99_pcb_t *)device->token;
10171025   cartridge_t *cartridge = pcb->cartridge;
1018   /* offset is the bit number. The CRU base address is already divided
1019           by 2. */
1020        int reply = 0;
1026   // offset is the bit number. The CRU base address is already divided  by 2.
1027   int reply = 0;
10211028
1022   /* ram_page contains the bank number. We have a maximum of
1023    4 banks; the Super Space II manual says:
1029   // ram_page contains the bank number. We have a maximum of
1030   // 4 banks; the Super Space II manual says:
1031   //
1032   // Banks are selected by writing a bit pattern to CRU address >0800:
1033   //
1034   // Bank #   Value
1035   // 0        >02  = 0000 0010
1036   // 1        >08  = 0000 1000
1037   // 2        >20  = 0010 0000
1038   // 3        >80  = 1000 0000
1039   //
1040   // With the bank number (0, 1, 2, or 3) in R0:
1041   //
1042   // BNKSW   LI    R12,>0800   Set CRU address
1043   //         LI    R1,2        Load Shift Bit
1044   //         SLA   R0,1        Align Bank Number
1045   //         JEQ   BNKS1       Skip shift if Bank 0
1046   //         SLA   R1,0        Align Shift Bit
1047   // BNKS1   LDCR  R1,0        Switch Banks
1048   //         SRL   R0,1        Restore Bank Number (optional)
1049   //         RT
10241050
1025    Banks are selected by writing a bit pattern to CRU address >0800:
1026
1027    Bank #   Value
1028    0        >02  = 0000 0010
1029    1        >08  = 0000 1000
1030    2        >20  = 0010 0000
1031    3        >80  = 1000 0000
1032
1033    With the bank number (0, 1, 2, or 3) in R0:
1034
1035    BNKSW   LI    R12,>0800   Set CRU address
1036        LI    R1,2        Load Shift Bit
1037        SLA   R0,1        Align Bank Number
1038        JEQ   BNKS1       Skip shift if Bank 0
1039        SLA   R1,0        Align Shift Bit
1040    BNKS1   LDCR  R1,0        Switch Banks
1041        SRL   R0,1        Restore Bank Number (optional)
1042        RT
1043    */
10441051   if ((offset & 1) == 0 || offset > 7)
10451052      reply = 0;
10461053
1047   /* CRU addresses are only 1 bit wide. Bytes are transferred from LSB
1048    to MSB. That is, 8 bit are eight consecutive addresses. */
1054   // CRU addresses are only 1 bit wide. Bytes are transferred from LSB
1055   // to MSB. That is, 8 bit are eight consecutive addresses. */
10491056   reply = (cartridge->ram_page == (offset-1)/2);
10501057
10511058   return reply;
r8275r8276
10571064   cartridge_t *cartridge = pcb->cartridge;
10581065   // data is bit
10591066   // offset is address
1060        if (offset < 8)
1067   if (offset < 8)
10611068   {
10621069      if (data != 0)
10631070         cartridge->ram_page = (offset-1)/2;
r8275r8276
10781085
10791086   if (cartridge->ram_ptr==NULL)
10801087   {
1081      //      printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot);
1082      //      printf("Cartridge address = %lx\n", (long)pcb->cartridge);
10831088      value = 0;
10841089   }
10851090   else
10861091   {
10871092      boffset = cartridge->ram_page * 0x1000 + offset;
10881093      value = ((UINT16 *)cartridge->ram_ptr)[boffset];
1089      //      printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value);
10901094   }
1091   //  printf("accessed cartridge ram[%02x:%04x] = %04x\n", cartridge->ram_page, 0x6000+offset*2, value);
10921095   return value;
10931096}
10941097
r8275r8276
11061109   if (cartridge->ram_ptr==NULL)
11071110   {
11081111      logerror("No cartridge RAM at address %04x", 0x6000 + 2*offset);
1109
1110      //      printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot);
1111      //      printf("Cartridge address = %lx\n", (long)pcb->cartridge);
11121112   }
11131113   else
11141114   {
r8275r8276
11321132
11331133   if (cartridge->ram_ptr==NULL)
11341134   {
1135      //      printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot);
1136      //      printf("Cartridge address = %lx\n", (long)pcb->cartridge);
11371135      value = 0;
11381136   }
11391137   else
11401138   {
11411139      boffset = cartridge->ram_page * 0x2000 + offset;
11421140      value = ((UINT8 *)cartridge->ram_ptr)[boffset];
1143      //      printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value);
11441141   }
1145   //  printf("accessed cartridge ram[%02x:%04x] = %04x\n", cartridge->ram_page, 0x6000+offset*2, value);
11461142   return value;
11471143}
11481144
r8275r8276
11591155   if (cartridge->ram_ptr==NULL)
11601156   {
11611157      logerror("No cartridge RAM at address %04x", 0x6000 + offset);
1162
1163      //      printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot);
1164      //      printf("Cartridge address = %lx\n", (long)pcb->cartridge);
11651158   }
11661159   else
11671160   {
r8275r8276
11741167static int assemble_super(running_device *image)
11751168{
11761169   cartridge_t *cart;
1177//  printf("assemble_super, %s\n", image->tag);
11781170
11791171   cart = assemble_common(image);
11801172   if (cart->ram_size==0)
r8275r8276
11911183    ROM: up to 16 KiB (in up to 2 banks of 8KiB each)
11921184    RAM: 1022 B (0x6c00-0x6ffd, overrides ROM in that area)
11931185    ROM mapper: 6ffe
1186
1187    Note that some MBX cartridges assume the presence of the MBX system
1188    (additional console) and will not run without it. The MBX hardware is
1189    not emulated yet.
11941190******************************************************************************/
11951191
11961192static DEVICE_START(ti99_pcb_mbx)
11971193{
1198//  printf("TI99 pcb mbx start\n");
11991194   set_pointers(device, get_index_from_tagname(device->owner)-1);
12001195}
12011196
r8275r8276
12081203
12091204   if ((offset >= 0x0600) && (offset <= 0x07fe))
12101205   {
1211      /* This is the RAM area which overrides any ROM. There is no
1212           known banking behavior for the RAM, so we must assume that
1213           there is only one bank. */
1206      // This is the RAM area which overrides any ROM. There is no
1207      // known banking behavior for the RAM, so we must assume that
1208      // there is only one bank.
12141209      if (cartridge->ram_ptr != NULL)
12151210         value = ((UINT16 *)cartridge->ram_ptr)[offset - 0x0600];
12161211   }
r8275r8276
12581253
12591254   if ((offset >= 0x0c00) && (offset <= 0x0ffd))
12601255   {
1261      /* This is the RAM area which overrides any ROM. There is no
1262           known banking behavior for the RAM, so we must assume that
1263           there is only one bank. */
1256      // This is the RAM area which overrides any ROM. There is no
1257      // known banking behavior for the RAM, so we must assume that
1258      // there is only one bank.
12641259      if (cartridge->ram_ptr != NULL)
12651260         value = ((UINT8 *)cartridge->ram_ptr)[offset - 0x0c00];
12661261   }
r8275r8276
12971292
12981293static int assemble_mbx(running_device *image)
12991294{
1300//  cartridge_t *cart;
1301
1302//  printf("assemble_mbx, %s\n", image->tag);
1303   /*cart = */assemble_common(image);
1295   assemble_common(image);
13041296   return INIT_PASS;
13051297}
13061298
13071299/*****************************************************************************
13081300  Cartridge type: paged379i
1309    This cartridge consists of one 16 KiB, 32 KiB, 64 KiB, or 128 KiB EEPROM
1310    which is organised in 2, 4, 8, or 16 pages of 8 KiB each. The complete
1301    This cartridge consists of one 16 KiB, 32 KiB, 64 KiB, or 128 KiB EEPROM
1302    which is organised in 2, 4, 8, or 16 pages of 8 KiB each. The complete
13111303    memory contents must be stored in one dump file.
13121304    The pages are selected by writing a value to some memory locations. Due to
13131305    using the inverted outputs of the LS379 latch, setting the inputs of the
r8275r8276
13381330static DEVICE_START(ti99_pcb_paged379i)
13391331{
13401332   /* device is ti99_cartslot:cartridge:pcb */
1341//  printf("DEVICE_START(ti99_pcb_paged379i), tag of device=%s\n", device->tag());
13421333   set_pointers(device, get_index_from_tagname(device->owner)-1);
13431334}
13441335
r8275r8276
13561347
13571348   if (cartridge->rom_ptr==NULL)
13581349   {
1359      //      printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot);
1360      //      printf("Cartridge address = %lx\n", (long)pcb->cartridge);
13611350      value = 0;
13621351   }
13631352   else
r8275r8276
13661355      // 16bit access -> multiply by 0x1000
13671356      boffset = cartridge->rom_page * 0x1000 + offset;
13681357      value = ((UINT16 *)cartridge->rom_ptr)[boffset];
1369      //      printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value);
13701358   }
1371//    printf("accessed cartridge rom[%02x:%04x] = %04x\n", cartridge->rom_page, 0x6000+offset*2, value);
13721359   return value;
13731360}
13741361
r8275r8276
13911378      mask = 1;
13921379
13931380   cartridge->rom_page = rompage & mask;
1394//  printf("setting rompage to %d\n", cartridge->rom_page);
13951381}
13961382
13971383/*
r8275r8276
14061392{
14071393   ti99_pcb_t *pcb = (ti99_pcb_t *)device->token;
14081394   cartridge_t *cartridge = pcb->cartridge;
1409/*
1410    Bits: 011x xxxx xxxb bbbx
1411    x = don't care, bbbb = bank
1412    16bit access -> drop rightmost bit
1413*/
1395
1396   // Bits: 011x xxxx xxxb bbbx
1397   // x = don't care, bbbb = bank
1398   // 16bit access -> drop rightmost bit
14141399   set_paged379i_bank(cartridge, 15 - (offset & 15));
14151400}
14161401
r8275r8276
14281413
14291414   if (cartridge->rom_ptr==NULL)
14301415   {
1431      //      printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot);
1432      //      printf("Cartridge address = %lx\n", (long)pcb->cartridge);
14331416      value = 0;
14341417   }
14351418   else
r8275r8276
14381421      // 8bit access -> multiply by 0x2000
14391422      boffset = cartridge->rom_page * 0x2000 + offset;
14401423      value = ((UINT8 *)cartridge->rom_ptr)[boffset];
1441      //      printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value);
14421424   }
1443   //  printf("accessed cartridge rom[%02x:%04x] = %04x\n", cartridge->rom_page, 0x6000+offset*2, value);
14441425   return value;
14451426
14461427}
r8275r8276
14521433{
14531434   ti99_pcb_t *pcb = (ti99_pcb_t *)device->token;
14541435   cartridge_t *cartridge = pcb->cartridge;
1455/*
1456    Bits: 011x xxxx xxxb bbbx
1457    x = don't care, bbbb = bank
1458*/
1436
1437   // Bits: 011x xxxx xxxb bbbx
1438   // x = don't care, bbbb = bank
14591439   set_paged379i_bank(cartridge, 15 - ((offset>>1) & 15));
14601440}
14611441
r8275r8276
14661446{
14671447   cartridge_t *cart;
14681448
1469//  printf("assemble_paged379i, %s\n", image->tag);
14701449   cart = assemble_common(image);
14711450   if (cart->rom_ptr==NULL)
14721451   {
r8275r8276
14861465    similar to the one used for the SuperSpace cartridge, with the exception
14871466    that we are using ROM only, and we can have up to 8 pages.
14881467
1489      Bank     Value written to CRU>0800
1468    Bank     Value written to CRU>0800
14901469    0      >0002  = 0000 0000 0000 0010
14911470    1      >0008  = 0000 0000 0000 1000
14921471    2      >0020  = 0000 0000 0010 0000
r8275r8276
15011480static DEVICE_START(ti99_pcb_pagedcru)
15021481{
15031482   /* device is ti99_cartslot:cartridge:pcb */
1504//  printf("DEVICE_START(ti99_pcb_pagedcru), tag of device=%s\n", device->tag());
15051483   set_pointers(device, get_index_from_tagname(device->owner)-1);
15061484}
15071485
r8275r8276
15191497
15201498   if (cartridge->rom_ptr==NULL)
15211499   {
1522      //      printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot);
1523      //      printf("Cartridge address = %lx\n", (long)pcb->cartridge);
15241500      value = 0;
15251501   }
15261502   else
r8275r8276
15291505      // 16bit access -> multiply by 0x1000
15301506      boffset = cartridge->rom_page * 0x1000 + offset;
15311507      value = ((UINT16 *)cartridge->rom_ptr)[boffset];
1532      //      printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value);
15331508   }
1534//    printf("accessed cartridge rom[%02x:%04x] = %04x\n", cartridge->rom_page, 0x6000+offset*2, value);
15351509   return value;
15361510}
15371511
r8275r8276
15581532
15591533   if (cartridge->rom_ptr==NULL)
15601534   {
1561      //      printf("No cartridge ROM in rompage=%d of bank %d\n", rompage, cartslots->active_slot);
1562      //      printf("Cartridge address = %lx\n", (long)pcb->cartridge);
15631535      value = 0;
15641536   }
15651537   else
r8275r8276
15681540      // 8bit access -> multiply by 0x2000
15691541      boffset = cartridge->rom_page * 0x2000 + offset;
15701542      value = ((UINT8 *)cartridge->rom_ptr)[boffset];
1571      //      printf("stdcart/read: %4x = %4x\n", 0x6000 + 2*offset, value);
15721543   }
1573   //  printf("accessed cartridge rom[%02x:%04x] = %04x\n", cartridge->rom_page, 0x6000+offset*2, value);
15741544   return value;
1575
15761545}
15771546
15781547/*
r8275r8276
15941563{
15951564   ti99_pcb_t *pcb = (ti99_pcb_t *)device->token;
15961565   cartridge_t *cartridge = pcb->cartridge;
1597        int reply = 0;
1566   int reply = 0;
15981567
15991568   if ((offset & 1) == 0 || offset > 15)
16001569      reply = 0;
r8275r8276
16101579   cartridge_t *cartridge = pcb->cartridge;
16111580   // data is bit
16121581   // offset is address
1613   /* Note that CRU >0F00 also gets in here ... should check
1614    whether it is intended to go somewhere else */
1615        if (offset < 16)
1582
1583   //Note that CRU >0F00 also gets in here ... should check
1584   // whether it is intended to go somewhere else
1585   if (offset < 16)
16161586   {
16171587      if (data != 0)
16181588      {
16191589         cartridge->rom_page = (offset-1)/2;
1620         // printf("Setting bit %4x of CRU base >0800\n", offset);
16211590      }
16221591   }
1623//  printf("setting rompage to %d\n", cartridge->rom_page);
16241592}
16251593
16261594/*
r8275r8276
16301598{
16311599   cartridge_t *cart;
16321600
1633//  printf("assemble_pagedcru, %s\n", image->tag);
16341601   cart = assemble_common(image);
16351602   if (cart->rom_ptr==NULL)
16361603   {
r8275r8276
16421609}
16431610
16441611/*****************************************************************************
1612  Cartridge type: gramkracker
1613******************************************************************************/
1614
1615static DEVICE_START(ti99_pcb_gramkracker)
1616{
1617   /* device is ti99_cartslot:cartridge:pcb */
1618//  printf("DEVICE_START(ti99_pcb_pagedcru), tag of device=%s\n", device->tag());
1619   set_pointers(device, get_index_from_tagname(device->owner)-1);
1620}
1621
1622/*
1623    The GRAM Kracker contains one GROM and several buffered RAM chips
1624*/
1625static int assemble_gramkracker(running_device *image)
1626{
1627   cartridge_t *cart;
1628   int id,i;
1629
1630   running_device *cartsys = image->owner;
1631   ti99_multicart_state *cartslots = (ti99_multicart_state *)cartsys->token;
1632
1633   cart = assemble_common(image);
1634
1635   if (cart->grom_ptr==NULL)
1636   {
1637      logerror("Missing loader GROM for GRAM Kracker system");
1638      return INIT_FAIL;
1639   }
1640
1641   if (cart->ram_size < 81920)
1642   {
1643      logerror("Missing or insufficient RAM for GRAM Kracker system");
1644      return INIT_FAIL;
1645   }
1646
1647   // Caution: We are using the ram_socket for both grom and direct access.
1648   // So we get the GROM (first 64 KiB) contents swapped. Need to undo.
1649   if (!ti99_is_99_8())
1650   {
1651      /* Undo the bigendianization for the GROM area. */
1652      UINT16 *cont16b = (UINT16 *)cart->ram_ptr;
1653      for (i = 0; i < 32768; i++)
1654         cont16b[i] = BIG_ENDIANIZE_INT16(cont16b[i]);
1655   }
1656
1657   // Get slot number
1658   id = get_index_from_tagname(image);
1659   cartslots->gk_slot = id-1;
1660   cartslots->gk_guest_slot = -1;
1661   // The first cartridge that is still plugged in is the "guest" of the
1662   // GRAM Kracker
1663   for (i=0; i < NUMBER_OF_CARTRIDGE_SLOTS; i++)
1664   {
1665      if (!slot_is_empty(cartsys, i) && (i != cartslots->gk_slot))
1666      {
1667         cartslots->gk_guest_slot = i;
1668         break;
1669      }
1670   }
1671   return INIT_PASS;
1672}
1673
1674/*
1675    Unplugs the GRAM Kracker. The "guest" is still plugged in, but will be
1676    treated as normal.
1677*/
1678static int disassemble_gramkracker(running_device *cartslot)
1679{
1680   running_device *cartsys = cartslot->owner;
1681   ti99_multicart_state *cartslots = (ti99_multicart_state *)cartsys->token;
1682   int i;
1683
1684   int slotnumber = get_index_from_tagname(cartslot)-1;
1685   assert(slotnumber>=0 && slotnumber<NUMBER_OF_CARTRIDGE_SLOTS);
1686   cartridge_t *cart = &cartslots->cartridge[slotnumber];
1687
1688   // We'll undo the undo of the bigendianization for saving (only for
1689   // the GROM part)
1690   if (!ti99_is_99_8())
1691   {
1692      /* Undo the bigendianization for the GROM area. */
1693      UINT16 *cont16b = (UINT16 *)cart->ram_ptr;
1694      for (i = 0; i < 32768; i++)
1695         cont16b[i] = BIG_ENDIANIZE_INT16(cont16b[i]);
1696   }
1697
1698   cartslots->gk_slot = -1;
1699   cartslots->gk_guest_slot = -1;
1700
1701   return disassemble_std(cartslot);
1702}
1703
1704
1705/*****************************************************************************
16451706  Device metadata
16461707******************************************************************************/
16471708
r8275r8276
19682029   }
19692030}
19702031
2032static DEVICE_GET_INFO(ti99_cartridge_pcb_gramkracker)
2033{
2034   switch(state)
2035   {
2036      case DEVINFO_FCT_START:
2037         info->start = DEVICE_START_NAME(ti99_pcb_gramkracker);
2038         break;
2039
2040      case TI99CART_FCT_ASSM:
2041         info->f = (genf *) assemble_gramkracker;
2042         break;
2043
2044      case TI99CART_FCT_DISASSM:
2045         info->f = (genf *) disassemble_gramkracker;
2046         break;
2047
2048      case DEVINFO_STR_NAME:
2049         strcpy(info->s, "TI99 GRAM Kracker system");
2050         break;
2051
2052      default:
2053         DEVICE_GET_INFO_CALL(ti99_cart_common);
2054         break;
2055   }
2056}
2057
2058
19712059/*****************************************************************************
19722060  The cartridge handling of the multi-cartridge system.
19732061  Every cartridge contains a PCB device. The memory handlers delegate the calls
r8275r8276
20102098         cartslot_t *cart = (cartslot_t *)image->token;
20112099
20122100         /* try opening this as a multicart */
2013         /* This line requires that cartslot_t be included in cartslot.h,
2014            otherwise one cannot make use of multicart handling within such a
2015            custom LOAD function. */
2101         // This line requires that cartslot_t be included in cartslot.h,
2102         // otherwise one cannot make use of multicart handling within such a
2103         // custom LOAD function.
20162104         multicart_open_error me = multicart_open(image_filename(image), image->machine->gamedrv->name, MULTICART_FLAGS_LOAD_RESOURCES, &cart->mc);
20172105
2018         /* Now that we have loaded the image files, let the PCB put them all
2019            together. This means we put the images in a structure which allows
2020            for a quick access by the memory handlers. Every PCB defines an
2021            own assembly method. */
2106         // Now that we have loaded the image files, let the PCB put them all
2107         // together. This means we put the images in a structure which allows
2108         // for a quick access by the memory handlers. Every PCB defines an
2109         // own assembly method.
20222110         if (me == MCERR_NONE)
20232111            result = pcb->assemble(image);
20242112         else
20252113            fatalerror("Error loading multicart: %s", multicart_error_text(me));
20262114
2027         /* This is for legacy support. If we have no multicart left
2028            but there are still legacy dumps, we switch to legacy mode. */
2115         // This is for legacy support. If we have no multicart left
2116         // but there are still legacy dumps, we switch to legacy mode.
20292117         if (result != INIT_FAIL)
20302118            cartslots->multi_slots++;
20312119      }
r8275r8276
20482136
20492137   if (image->token == NULL)
20502138   {
2051      /* This means something went wrong during the pcb
2052        identification (e.g. one of the cartridge files was not
2053        found). We do not need to (and cannot) unload the cartridge. */
2139      // This means something went wrong during the pcb
2140      // identification (e.g. one of the cartridge files was not
2141      // found). We do not need to (and cannot) unload the cartridge.
20542142      return;
20552143   }
20562144   pcbdev = cartslot_get_pcb(image);
r8275r8276
20602148      ti99_pcb_t *pcb = (ti99_pcb_t *)pcbdev->token;
20612149      cartslot_t *cart = (cartslot_t *)image->token;
20622150
2063      //  printf("unload\n");
20642151      if (cart->mc != NULL)
20652152      {
20662153         /* Remove pointers and de-big-endianize RAM contents. */
20672154         pcb->disassemble(image);
20682155
2069         /* Close the multicart; all RAM resources will be
2070            written to disk */
2156         // Close the multicart; all RAM resources will be
2157         // written to disk
20712158         multicart_close(cart->mc);
20722159         cart->mc = NULL;
20732160
r8275r8276
21222209
21232210   if (cartridge->grom_size>0)
21242211   {
2125      /* This is the reason why we need the image size: Read
2126        access beyond the image size must be detected. */
2212      // This is the reason why we need the image size: Read
2213      // access beyond the image size must be detected.
21272214      if ((cartslots->grom_address < 0x6000) || (cartslots->grom_address > (cartridge->grom_size+0x6000)))
21282215         return 0;
21292216
r8275r8276
21312218      /* read ahead */
21322219      cartslots->grom_buffer = cartridge->grom_ptr[cartslots->grom_address-0x6000];
21332220      //  printf("GROM address = %04x, reply = %02x\n", console_GROMs.addr, reply>>8);
2134      /* The program counter wraps at each GROM chip size (8K),
2135        so 0x5fff + 1 = 0x4000. */
2221      // The program counter wraps at each GROM chip size (8K),
2222      // so 0x5fff + 1 = 0x4000.
21362223      cartslots->grom_address = ((cartslots->grom_address + 1) & 0x1FFF) | (cartslots->grom_address & 0xE000);
21372224
21382225      /* Reset the read and write address flipflops. */
r8275r8276
21522239   int slotmbx, slotmini, slotebr2, slotrom;
21532240   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
21542241
2155#if 0
2156   if (hsgpl_crdena)
2157      return ti99_hsgpl_rom6_r(space, offset, mem_mask);
2158#endif
2159
21602242   slotmbx = cartslots->legacy_slotnumber[SLOTC_MBX];
21612243
21622244   if ((slotmbx != -1) && (offset >= 0x0600) && (offset <= 0x07fe))
r8275r8276
21882270      else
21892271         return (((UINT16 *)cartslots->cartridge[slotrom].rom_ptr)[offset]);
21902272   }
2191   /* SuperSpace, paged379i, and pagedcru are not supported in
2192    legacy mode. */
2273
2274   /* SuperSpace, paged379i, and pagedcru are not supported in legacy mode. */
21932275}
21942276
21952277static WRITE16_DEVICE_HANDLER( ti99_cart_w_legacy )
r8275r8276
21972279   int slotmbx, slotmini, slotebr2, slotrom;
21982280   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
21992281
2200#if 0
2201   if (hsgpl_crdena)
2202   {
2203      ti99_hsgpl_rom6_w(space, offset, data, mem_mask);
2204      return;
2205   }
2206#endif
22072282   slotmbx = cartslots->legacy_slotnumber[SLOTC_MBX];
22082283   slotrom = cartslots->legacy_slotnumber[SLOTC_CROM];
22092284   slotebr2 = cartslots->legacy_slotnumber[SLOTC_DROM];
r8275r8276
22512326   int slotmbx, slotmini, slotebr2, slotrom;
22522327   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
22532328
2254#if 0
2255   if (hsgpl_crdena)
2256      return ti99_hsgpl_rom6_r(space, offset, mem_mask);
2257#endif
2258
22592329   slotmbx = cartslots->legacy_slotnumber[SLOTC_MBX];
22602330
22612331   if ((slotmbx != -1) && (offset >= 0x0c00) && (offset <= 0x0ffd))
r8275r8276
22872357      else
22882358         return (((UINT8 *)cartslots->cartridge[slotrom].rom_ptr)[offset]);
22892359   }
2290   /* Super Space, paged379i, and pagedcru are not supported in
2291    legacy mode. */
2360   /* Super Space, paged379i, and pagedcru are not supported in legacy mode. */
22922361}
22932362
22942363/*
r8275r8276
22992368   int slotmbx, slotmini, slotebr2, slotrom;
23002369   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
23012370
2302#if 0
2303   if (hsgpl_crdena)
2304   {
2305      ti99_hsgpl_rom6_w(space, offset, data, mem_mask);
2306      return;
2307   }
2308#endif
23092371   slotmbx = cartslots->legacy_slotnumber[SLOTC_MBX];
23102372   slotrom = cartslots->legacy_slotnumber[SLOTC_CROM];
23112373   slotebr2 = cartslots->legacy_slotnumber[SLOTC_DROM];
r8275r8276
23542416   /* Some comments originally in machine/ti99_4x.c */
23552417
23562418   /* We identify file types according to their extension */
2357   /* Note that if we do not recognize the extension, we revert to the
2358    slot location <-> type scheme. */
2419   // Note that if we do not recognize the extension, we revert to the
2420   // slot location <-> type scheme.
23592421   int id = 0;
23602422   int i;
23612423   int filesize;
r8275r8276
23772439
23782440   type = SLOTC_EMPTY;
23792441
2380   /* There is a circuitry in TI99/4(a) that resets the console when a
2381    cartridge is inserted or removed.  We emulate this instead of resetting
2382    the emulator (which is the default in MESS). */
2383#if 0
2384   cpu_set_input_line(machine->firstcpu, INPUT_LINE_RESET, PULSE_LINE);
2385   tms9901_reset(0);
2386   if (! has_evpc)
2387      TMS9928A_reset();
2388   if (has_evpc)
2389      v9938_reset(0);
2390#endif
2391
23922442   ch = strrchr(name, '.');
23932443   ch2 = (ch-1 >= name) ? ch-1 : "";
23942444
r8275r8276
24332483
24342484   savembx = FALSE;
24352485
2436   /* We will use the already allocated buffers in the memory regions,
2437       and the pointers in the cartridge structure will point to them. */
2486   // We will use the already allocated buffers in the memory regions,
2487   // and the pointers in the cartridge structure will point to them.
24382488   switch (type)
24392489   {
24402490      case SLOTC_EMPTY:
r8275r8276
24512501         maxrom = 0x2000;
24522502         if (cartslots->legacy_slotnumber[SLOTC_MINIMEM] != -1)
24532503         {
2454            /* This means the NVRAM has already been loaded.
2455                So we just load 4K of ROM to avoid overwriting
2456                the NVRAM. */
2504            // This means the NVRAM has already been loaded.
2505            // So we just load 4K of ROM to avoid
2506            // overwriting the NVRAM.
24572507            maxrom = 0x1000;
24582508         }
24592509
24602510         if (cartslots->legacy_slotnumber[SLOTC_MBX] != -1)
24612511         {
2462            /* This means the NVRAM has already been loaded.
2463                We need to temporarily save the RAM contents and
2464                write them back because the RAM overrides the
2465                ROM in an intermediate area. */
2512            // This means the NVRAM has already been loaded.
2513            // We need to temporarily save the RAM contents
2514            // and write them back because the RAM overrides
2515            // the ROM in an intermediate area.
24662516            savembx = TRUE;
24672517         }
24682518
r8275r8276
25042554         break;
25052555
25062556      case SLOTC_MINIMEM:
2507         /* Load the NVRAM. Need to BIG_ENDIANIZE it.
2508            MiniMemory has only one cartridge page. */
2557         // Load the NVRAM. Need to BIG_ENDIANIZE it.
2558         // MiniMemory has only one cartridge page.
25092559         if (ti99_is_99_8())
25102560         {
25112561            // printf("** is 99/8\n");
r8275r8276
26032653         }
26042654         else
26052655         {
2606            /* We BIG_ENDIANIZE before saving. This is
2607                consistent with the cartridge save format. */
2656            // We BIG_ENDIANIZE before saving. This is
2657            // consistent with the cartridge save format.
26082658            UINT16 *ramcont = (UINT16 *)cartslots->cartridge[slot].ram_ptr;
26092659            for (i = 0; i < 0x0800; i++)
26102660               ramcont[i] = BIG_ENDIANIZE_INT16(ramcont[i]);
r8275r8276
26212671         }
26222672         else
26232673         {
2624            /* We BIG_ENDIANIZE before saving. This is
2625                consistent with the cartridge save format. */
2674            // We BIG_ENDIANIZE before saving. This is
2675            // consistent with the cartridge save format.
26262676            UINT16 *ramcont = (UINT16 *)cartslots->cartridge[slot].ram_ptr;
26272677            for (i = 0; i < 0x0200; i++)
26282678               ramcont[i] = BIG_ENDIANIZE_INT16(ramcont[i]);
r8275r8276
26592709  Actually, the name of the device should be changed (however, the device name
26602710  length is limited)
26612711******************************************************************************/
2712
2713/* GRAM Kracker support */
2714static WRITE16_DEVICE_HANDLER( ti99_cart_w_gk );
2715static READ16_DEVICE_HANDLER( ti99_cart_r_gk );
2716static WRITE16_DEVICE_HANDLER( ti99_cart_w_gk );
2717static READ8_DEVICE_HANDLER( ti99_cart_crur_gk );
2718static WRITE8_DEVICE_HANDLER( ti99_cart_cruw_gk );
2719static READ8_DEVICE_HANDLER( ti99_cart_r_gk8 );
2720static WRITE8_DEVICE_HANDLER( ti99_cart_w_gk8 );
2721
26622722/*
26632723    Instantiation of a multicart system for the TI family.
26642724*/
r8275r8276
26872747   cartslots->legacy_slots = 0;
26882748   cartslots->multi_slots = 0;
26892749
2690   /* The cartslot system is initialized now. The cartridges themselves
2691       need to check whether their parts are available. */
2750   cartslots->gk_slot = -1;
2751   cartslots->gk_guest_slot = -1;
2752
2753   // The cartslot system is initialized now. The cartridges themselves
2754   // need to check whether their parts are available.
26922755}
26932756
26942757static DEVICE_STOP(ti99_multicart)
r8275r8276
26982761
26992762static DEVICE_RESET(ti99_multicart)
27002763{
2701   /* Consider to propagate RESET to cartridges.
2702    However, schematics do not reveal any pin for resetting a cartridge;
2703    the reset line is an input used when plugging in a cartridge. */
2764   // Consider to propagate RESET to cartridges.
2765   // However, schematics do not reveal any pin for resetting a cartridge;
2766   // the reset line is an input used when plugging in a cartridge.
27042767
2705   /* Allows to manually lock the cartslot system to a specific slot.
2706       We take slot numbers from 0 (automatic mode) to the maximum. */
2707
27082768   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
27092769   int slotnumber = input_port_read(device->machine, "CARTSLOT");
27102770   assert(slotnumber>=0 && slotnumber<=255);
27112771   cartslots->fixed_slot = slotnumber-1; /* auto = -1 */
27122772   cartslots->grom_address = 0x0000;
27132773   cartslots->grom_buffer = 0x00;
2774   cartslots->loader_on = FALSE;
27142775   cartslots->raddr_LSB = cartslots->waddr_LSB = FALSE;
27152776}
27162777
27172778/*
27182779    Accesses the ROM regions of the cartridge for reading.
2719    This is the area from 0x6000 to 0x7fff. Each cartridge is reponsible
2780    This is the area from 0x6000 to 0x7fff. Each cartridge is responsible
27202781    for all kinds of magic which is done inside this area, like swapping
27212782    banks or doing other control actions. These activities beyond simple
27222783    reading are cartridge-specific. Each kind of cartridge requires a
r8275r8276
27302791   int slot = cartslots->active_slot;
27312792   cartridge_t *cart;
27322793
2794   /* Idle the CPU */
2795   cpu_adjust_icount(devtag_get_device(device->machine, "maincpu"),-4);
2796   // Alternatively:
2797   // cpu_spinuntil_time(device->machine->firstcpu, ATTOTIME_IN_USEC(6));
2798
2799   // Handle GRAM Kracker
2800   // We could also consider to use a flag, but input_port_read uses
2801   // a hashtable, so this should not be too slow
2802   if ((cartslots->gk_slot != -1) && (input_port_read(device->machine, "CARTSLOT")==CART_GK))
2803      return ti99_cart_r_gk(device, offset, mem_mask);
2804
27332805   /* Sanity check. Higher slots are always empty. */
27342806   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
27352807      return 0;
27362808
2737   /* Same as above (GROM read): If there is only one cartridge there
2738    is no use of trying other banks. There is one issue with the
2739    selection mechanism: When the console probes the GROM banks and
2740    we have a ROM-only cartridge plugged in, it checks bank 0 and bank 1,
2741    finds no GROM, and then fails to dummy-check bank 0 again which would
2742    have set our cartridge expander to slot 0. But in slot 1 there is no
2743    ROM cartridge, so nothing shows up in the selection list. We work
2744    around this with the following line. */
2809   // Same as above (GROM read): If there is only one cartridge there
2810   // is no use of trying other banks. There is one issue with the
2811   // selection mechanism: When the console probes the GROM banks and
2812   // we have a ROM-only cartridge plugged in, it checks bank 0 and bank 1,
2813   // finds no GROM, and then fails to dummy-check bank 0 again which would
2814   // have set our cartridge expander to slot 0. But in slot 1 there is no
2815   // ROM cartridge, so nothing shows up in the selection list. We work
2816   // around this with the following line.
27452817   if (cartslots->fixed_slot==AUTO && cartslots->next_free_slot==1)
27462818      slot=0;
27472819
27482820   cart = &cartslots->cartridge[slot];
27492821
2750   /* Idle the CPU */
2751        cpu_adjust_icount(devtag_get_device(device->machine, "maincpu"),-4);
2752
2753   // Alternatively:
2754   // cpu_spinuntil_time(device->machine->firstcpu, ATTOTIME_IN_USEC(6));
2755
2756   //  printf("rpk = %d, bin = %d\n", cartslots->multi_slots,cartslots->legacy_slots);
2757
27582822   /* Handle legacy mode. */
27592823   if (in_legacy_mode(device))
27602824   {
r8275r8276
27772841
27782842/*
27792843    Accesses the ROM regions of the cartridge for writing.
2780    This is the area from 0x6000 to 0x7fff. Each cartridge is reponsible
2844    This is the area from 0x6000 to 0x7fff. Each cartridge is responsible
27812845    for all kinds of magic which is done inside this area. Specifically,
27822846    writing is often used to swap banks for subsequent reads. The actual
27832847    effect of writing (beyond setting values in a RAM chip) are
r8275r8276
27912855   int slot = cartslots->active_slot;
27922856   cartridge_t *cart;
27932857
2858   /* Idle the CPU */
2859   cpu_adjust_icount(devtag_get_device(device->machine, "maincpu"),-4);
2860//  cpu_spinuntil_time(device->machine->firstcpu, ATTOTIME_IN_USEC(6));
2861
2862   // Handle GRAM Kracker
2863   if ((cartslots->gk_slot != -1) && (input_port_read(device->machine, "CARTSLOT")==CART_GK))
2864      ti99_cart_w_gk(device, offset, data, mem_mask);
2865
27942866   /* Sanity check. Higher slots are always empty. */
27952867   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
27962868      return;
r8275r8276
28012873
28022874   cart = &cartslots->cartridge[slot];
28032875
2804   /* Idle the CPU */
2805        cpu_adjust_icount(devtag_get_device(device->machine, "maincpu"),-4);
2806//  cpu_spinuntil_time(device->machine->firstcpu, ATTOTIME_IN_USEC(6));
2807
28082876   /* Handle legacy mode. */
28092877   if (in_legacy_mode(device))
28102878   {
r8275r8276
28242892/*
28252893    CRU interface to cartridges, used only by SuperSpace and Pagedcru
28262894    style cartridges.
2827        The SuperSpace has a CRU-based memory mapper. It is accessed via the
2828        cartridge slot on CRU base >0800.
2895    The SuperSpace has a CRU-based memory mapper. It is accessed via the
2896    cartridge slot on CRU base >0800.
28292897*/
28302898READ8_DEVICE_HANDLER( ti99_multicart_cru_r )
28312899{
r8275r8276
28382906   if (in_legacy_mode(device))
28392907      return 0;
28402908
2909   // Handle GRAM Kracker
2910   if ((cartslots->gk_slot != -1) && (input_port_read(device->machine, "CARTSLOT")==CART_GK))
2911      return ti99_cart_crur_gk(device, offset);
2912
28412913   /* Sanity check. Higher slots are always empty. */
28422914   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
28432915      return 0;
r8275r8276
28582930}
28592931
28602932/*
2861        Write cartridge mapper CRU interface (SuperSpace, Pagedcru)
2933    Write cartridge mapper CRU interface (SuperSpace, Pagedcru)
28622934*/
28632935WRITE8_DEVICE_HANDLER( ti99_multicart_cru_w )
28642936{
r8275r8276
28712943   if (in_legacy_mode(device))
28722944      return;
28732945
2946   // Handle GRAM Kracker
2947   if ((cartslots->gk_slot != -1) && (input_port_read(device->machine, "CARTSLOT")==CART_GK))
2948      ti99_cart_cruw_gk(device, offset, data);
2949
28742950   /* Sanity check. Higher slots are always empty. */
28752951   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
28762952      return;
r8275r8276
28962972READ8_DEVICE_HANDLER(ti99_multicart8_r)
28972973{
28982974   ti99_multicart_state *cartslots = (ti99_multicart_state *) device->token;
2975   int slot = cartslots->active_slot;
28992976   cartridge_t *cart;
29002977
2901   int slot = cartslots->active_slot;
2978   /* Idle the CPU. TODO: Check whether this is correct for this machine. */
2979   cpu_adjust_icount(devtag_get_device(device->machine, "maincpu"),-4);
29022980
2981   // Handle GRAM Kracker
2982   if ((cartslots->gk_slot != -1) && (input_port_read(device->machine, "CARTSLOT")==CART_GK))
2983      return ti99_cart_r_gk8(device, offset);
2984
29032985   /* Sanity check. Higher slots are always empty. */
29042986   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
29052987      return 0;
r8275r8276
29102992
29112993   cart = &cartslots->cartridge[slot];
29122994
2913   /* Idle the CPU. TODO: Check whether this is correct for this machine. */
2914        cpu_adjust_icount(devtag_get_device(device->machine, "maincpu"),-4);
2915
29162995   /* Handle legacy mode. */
29172996   if (in_legacy_mode(device))
29182997   {
r8275r8276
29363015{
29373016   ti99_multicart_state *cartslots = (ti99_multicart_state *) device->token;
29383017   cartridge_t *cart;
2939
29403018   int slot = cartslots->active_slot;
29413019
3020   /* Idle the CPU. TODO: Check whether this is correct for this machine. */
3021   cpu_adjust_icount(devtag_get_device(device->machine, "maincpu"),-4);
3022
3023   // Handle GRAM Kracker
3024   if ((cartslots->gk_slot != -1) && (input_port_read(device->machine, "CARTSLOT")==CART_GK))
3025      ti99_cart_w_gk8(device, offset, data);
3026
29423027   /* Sanity check. Higher slots are always empty. */
29433028   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
29443029      return;
r8275r8276
29493034
29503035   cart = &cartslots->cartridge[slot];
29513036
2952   /* Idle the CPU. TODO: Check whether this is correct for this machine. */
2953        cpu_adjust_icount(devtag_get_device(device->machine, "maincpu"),-4);
2954
29553037   /* Handle legacy mode. */
29563038   if (in_legacy_mode(device))
29573039   {
r8275r8276
29663048      }
29673049   }
29683050}
3051
3052/*****************************************************************************
3053   GramKracker support
3054   The 80 KiB of the GK are allocated as follows
3055   00000 - 01fff: GRAM 0
3056   02000 - 03fff: GRAM 1  (alternatively, the loader GROM appears here)
3057   04000 - 05fff: GRAM 2
3058   06000 - 0ffff: GRAM 3-7 (alternatively, the guest GROMs appear here)
3059   10000 - 11fff: RAM 1
3060   12000 - 13fff: RAM 2
3061******************************************************************************/
3062/*
3063    Reads from the GRAM space of the GRAM Kracker.
3064*/
3065static int cartridge_gram_kracker_readg(running_device *cartsys)
3066{
3067   // gk_slot is the slot where the GK module is plugged in
3068   // gk_guest_slot is the slot where the cartridge is plugged in
3069   UINT8 value;
3070   cartridge_t *gkcartridge, *gkguestcart;
3071   ti99_multicart_state *cartslots = (ti99_multicart_state *)cartsys->token;
3072
3073   // This is only called when there is really a GK module
3074   gkcartridge = &cartslots->cartridge[cartslots->gk_slot];
3075
3076   // Buffered value
3077   value = (UINT8)cartslots->grom_buffer;
3078
3079   if (cartslots->grom_address >= 0x6000)
3080   {
3081      // When a cartridge is installed, it overrides the GK contents
3082      // but only if it has GROMs
3083      // So we first get the values and then have them replaced if applicable
3084      if (get_gk_switch(1)==GK_NORMAL)
3085      {
3086         // Read ahead
3087         cartslots->grom_buffer = ((UINT8 *)gkcartridge->ram_ptr)[cartslots->grom_address];
3088      }
3089      else
3090      {
3091         // GK is turned off
3092         cartslots->grom_buffer = 0;
3093      }
3094      if (cartslots->gk_guest_slot != -1)
3095      {
3096         gkguestcart = &cartslots->cartridge[cartslots->gk_guest_slot];
3097         // So if the cartridge has GROM, have it overwrite the value
3098         // if it is in its range
3099         if ((gkguestcart->grom_ptr != NULL)
3100            && (cartslots->grom_address < (0x6000 + gkguestcart->grom_size)))
3101            cartslots->grom_buffer = gkguestcart->grom_ptr[cartslots->grom_address-0x6000];
3102      }
3103   }
3104   else
3105   {
3106      if ((cartslots->grom_address >= 0x2000) && (cartslots->grom_address < 0x4000))
3107      {
3108         // Loader area
3109         if (get_gk_switch(5)==GK_LDOFF)
3110         {
3111            // Loader off
3112            cartslots->loader_on = FALSE;
3113            cartslots->grom_buffer = ((UINT8 *)gkcartridge->ram_ptr)[cartslots->grom_address];
3114         }
3115         else
3116         {
3117            // Loader on
3118            if (!cartslots->loader_on)
3119            {
3120               // Hack for GRAM Kracker: The device tells the user to
3121               // turn on the loader, but it sets the GROM address before!
3122               // So we have read the value from the earlier setting.
3123               value = gkcartridge->grom_ptr[cartslots->grom_address-0x2001];
3124               cartslots->loader_on = TRUE;
3125            }
3126            cartslots->grom_buffer = gkcartridge->grom_ptr[cartslots->grom_address-0x2000];
3127         }
3128      }
3129      else
3130      {
3131         // GRAM 0 or GRAM 2. Note that we deliver a value, but the console may
3132         // ignore it according to the switch setting.
3133         cartslots->grom_buffer = ((UINT8 *)gkcartridge->ram_ptr)[cartslots->grom_address];
3134      }
3135   }
3136
3137   // The program counter wraps at each GROM chip size (8K),
3138   // so 0x5fff + 1 = 0x4000.
3139   // The address must be increased even if there is no cartridge slot
3140   cartslots->grom_address = ((cartslots->grom_address + 1) & 0x1FFF) | (cartslots->grom_address & 0xE000);
3141
3142   /* Reset the read and write address flipflops. */
3143   cartslots->raddr_LSB = cartslots->waddr_LSB = FALSE;
3144
3145   return value;
3146}
3147
3148/*
3149    Writes to the GRAM space of the GRAM Kracker.
3150*/
3151static void cartridge_gram_kracker_writeg(running_device *cartsys, UINT8 data)
3152{
3153   // gk_slot is the slot where the GK module is plugged in
3154   // gk_guest_slot is the slot where the cartridge is plugged in
3155   cartridge_t *gkcartridge;
3156   ti99_multicart_state *cartslots = (ti99_multicart_state *)cartsys->token;
3157
3158   // This is only called when there is really a GK module
3159   gkcartridge = &cartslots->cartridge[cartslots->gk_slot];
3160
3161   // We need to rewind by 1 because the read address has already advanced.
3162   UINT16 write_addr = ((cartslots->grom_address + 0x1fff) & 0x1FFF) | (cartslots->grom_address & 0xE000);
3163
3164   if (get_gk_switch(4)!=GK_WP)
3165   {
3166      // Write protection off
3167      if (((cartslots->grom_address < 0x2000)
3168            && (get_gk_switch(2)==GK_GRAM0))
3169         || ((cartslots->grom_address >= 0x2000) && (cartslots->grom_address < 0x4000)
3170            && (get_gk_switch(3)==GK_GRAM12)
3171            && (get_gk_switch(5)==GK_LDOFF))
3172         || ((cartslots->grom_address >= 0x4000) && (cartslots->grom_address < 0x6000)
3173            && (get_gk_switch(3)==GK_GRAM12))
3174         || ((cartslots->grom_address >= 0x6000) && (cartslots->gk_guest_slot==-1)
3175            && (get_gk_switch(1)==GK_NORMAL)))
3176      {
3177         ((UINT8 *)gkcartridge->ram_ptr)[write_addr] = data;
3178      }
3179      // There is no GRAM in cartridges
3180
3181   }
3182   cartslots->grom_address = ((cartslots->grom_address + 1) & 0x1FFF) | (cartslots->grom_address & 0xE000);
3183
3184   /* Reset the read and write address flipflops. */
3185   cartslots->raddr_LSB = cartslots->waddr_LSB = FALSE;
3186}
3187
3188/*
3189    Reads from the RAM space of the GRAM Kracker.
3190*/
3191static READ16_DEVICE_HANDLER( ti99_cart_r_gk )
3192{
3193   // gk_slot is the slot where the GK module is plugged in
3194   // gk_guest_slot is the slot where the cartridge is plugged in
3195   cartridge_t *gkcartridge, *gkguestcart;
3196   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
3197
3198   gkcartridge = &cartslots->cartridge[cartslots->gk_slot];
3199
3200   if (cartslots->gk_guest_slot != -1)
3201   {
3202      gkguestcart = &cartslots->cartridge[cartslots->gk_guest_slot];
3203      // Legacy mode is not supported with the GK
3204      if (in_legacy_mode(device))
3205      {
3206         return 0;
3207      }
3208      //      printf("accessing cartridge in slot %d\n", slot);
3209      ti99_pcb_t *pcbdef = (ti99_pcb_t *)gkguestcart->pcb->token;
3210      //      printf("address=%lx, offset=%lx\n", pcbdef, offset);
3211      return (*pcbdef->read)(gkguestcart->pcb, offset, mem_mask);
3212   }
3213   else
3214   {
3215      if (get_gk_switch(1)==GK_OFF)
3216         return 0;
3217
3218      if (get_gk_switch(4)==GK_BANK1)
3219         return ((UINT16 *)gkcartridge->ram_ptr)[offset+0x8000];
3220      else
3221      {
3222         if (get_gk_switch(4)==GK_BANK2)
3223            return ((UINT16 *)gkcartridge->ram_ptr)[offset+0x9000];
3224         else
3225         {
3226            // Write protection on
3227            if (gkcartridge->ram_page==0)
3228            {
3229               return ((UINT16 *)gkcartridge->ram_ptr)[offset+0x8000];
3230            }
3231            else
3232            {
3233               return ((UINT16 *)gkcartridge->ram_ptr)[offset+0x9000];
3234            }
3235         }
3236      }
3237   }
3238}
3239
3240/*
3241    Writes to the RAM space of the GRAM Kracker.
3242*/
3243static WRITE16_DEVICE_HANDLER( ti99_cart_w_gk )
3244{
3245   // gk_slot is the slot where the GK module is plugged in
3246   // gk_guest_slot is the slot where the cartridge is plugged in
3247   cartridge_t *gkcartridge, *gkguestcart;
3248   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
3249
3250   gkcartridge = &cartslots->cartridge[cartslots->gk_slot];
3251
3252   if (cartslots->gk_guest_slot != -1)
3253   {
3254      gkguestcart = &cartslots->cartridge[cartslots->gk_guest_slot];
3255      // Legacy mode is not supported with the GK
3256      if (in_legacy_mode(device))
3257      {
3258         return;
3259      }
3260
3261      ti99_pcb_t *pcbdef = (ti99_pcb_t *)gkguestcart->pcb->token;
3262         (*pcbdef->write)(gkguestcart->pcb, offset, data, mem_mask);
3263   }
3264   else
3265   {
3266      if (get_gk_switch(1)==GK_OFF)
3267         return;
3268
3269      if (get_gk_switch(4)==GK_BANK1)
3270      {
3271         UINT16 *pos = ((UINT16 *)gkcartridge->ram_ptr) + offset + 0x8000;
3272         COMBINE_DATA(pos);
3273      }
3274      else
3275      {
3276         if (get_gk_switch(4)==GK_BANK2)
3277         {
3278            UINT16 *pos = ((UINT16 *)gkcartridge->ram_ptr) + offset + 0x9000;
3279            COMBINE_DATA(pos);
3280         }
3281         else
3282         {
3283            // Write protection on
3284            // This is handled like in Extended Basic
3285            gkcartridge->ram_page = offset & 1;
3286         }
3287      }
3288   }
3289}
3290
3291/*
3292    Read cartridge mapper CRU interface (Guest in GRAM Kracker)
3293*/
3294static READ8_DEVICE_HANDLER( ti99_cart_crur_gk )
3295{
3296   ti99_multicart_state *cartslots = (ti99_multicart_state *) device->token;
3297   cartridge_t *gkguestcart;
3298
3299   if (cartslots->gk_guest_slot != -1)
3300   {
3301      gkguestcart = &cartslots->cartridge[cartslots->gk_guest_slot];
3302      ti99_pcb_t *pcbdef = (ti99_pcb_t *)gkguestcart->pcb->token;
3303      if (pcbdef->cruread != NULL)
3304         return (*pcbdef->cruread)(gkguestcart->pcb, offset);
3305   }
3306   return 0;
3307}
3308
3309/*
3310    Write cartridge mapper CRU interface (Guest in GRAM Kracker)
3311*/
3312static WRITE8_DEVICE_HANDLER( ti99_cart_cruw_gk )
3313{
3314   ti99_multicart_state *cartslots = (ti99_multicart_state *) device->token;
3315   cartridge_t *gkguestcart;
3316
3317   if (cartslots->gk_guest_slot != -1)
3318   {
3319      gkguestcart = &cartslots->cartridge[cartslots->gk_guest_slot];
3320      ti99_pcb_t *pcbdef = (ti99_pcb_t *)gkguestcart->pcb->token;
3321      if (pcbdef->cruwrite != NULL)
3322         (*pcbdef->cruwrite)(gkguestcart->pcb, offset, data);
3323   }
3324}
3325
3326/*
3327    TI-99/8 support
3328*/
3329static READ8_DEVICE_HANDLER( ti99_cart_r_gk8 )
3330{
3331   // gk_slot is the slot where the GK module is plugged in
3332   // gk_guest_slot is the slot where the cartridge is plugged in
3333   cartridge_t *gkcartridge, *gkguestcart;
3334   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
3335
3336   gkcartridge = &cartslots->cartridge[cartslots->gk_slot];
3337
3338   if (cartslots->gk_guest_slot != -1)
3339   {
3340      gkguestcart = &cartslots->cartridge[cartslots->gk_guest_slot];
3341      // Legacy mode is not supported with the GK
3342      if (in_legacy_mode(device))
3343      {
3344         return 0;
3345      }
3346      //      printf("accessing cartridge in slot %d\n", slot);
3347      ti99_pcb_t *pcbdef = (ti99_pcb_t *)gkguestcart->pcb->token;
3348      //      printf("address=%lx, offset=%lx\n", pcbdef, offset);
3349      return (*pcbdef->read8)(gkguestcart->pcb, offset);
3350   }
3351   else
3352   {
3353      if (get_gk_switch(1)==GK_OFF)
3354         return 0;
3355
3356      if (get_gk_switch(4)==GK_BANK1)
3357         return ((UINT8 *)gkcartridge->ram_ptr)[offset+0x10000];
3358      else
3359      {
3360         if (get_gk_switch(4)==GK_BANK2)
3361            return ((UINT8 *)gkcartridge->ram_ptr)[offset+0x12000];
3362         else
3363         {
3364            // Write protection on
3365            if (gkcartridge->ram_page==0)
3366               return ((UINT8 *)gkcartridge->ram_ptr)[offset+0x10000];
3367            else
3368               return ((UINT8 *)gkcartridge->ram_ptr)[offset+0x12000];
3369         }
3370      }
3371   }
3372}
3373
3374static WRITE8_DEVICE_HANDLER( ti99_cart_w_gk8 )
3375{
3376   // gk_slot is the slot where the GK module is plugged in
3377   // gk_guest_slot is the slot where the cartridge is plugged in
3378   cartridge_t *gkcartridge, *gkguestcart;
3379   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
3380
3381   gkcartridge = &cartslots->cartridge[cartslots->gk_slot];
3382
3383   if (cartslots->gk_guest_slot != -1)
3384   {
3385      gkguestcart = &cartslots->cartridge[cartslots->gk_guest_slot];
3386      // Legacy mode is not supported with the GK
3387      if (in_legacy_mode(device))
3388      {
3389         return;
3390      }
3391
3392      ti99_pcb_t *pcbdef = (ti99_pcb_t *)gkguestcart->pcb->token;
3393         (*pcbdef->write8)(gkguestcart->pcb, offset, data);
3394   }
3395   else
3396   {
3397      if (get_gk_switch(1)==GK_OFF)
3398         return;
3399
3400      if (get_gk_switch(4)==GK_BANK1)
3401         ((UINT8 *)gkcartridge->ram_ptr)[offset+0x10000] = data;
3402      else
3403      {
3404         if (get_gk_switch(4)==GK_BANK2)
3405            ((UINT8 *)gkcartridge->ram_ptr)[offset+0x12000] = data;
3406         else
3407         {
3408            // Write protection on
3409            // This is handled like in Extended Basic
3410            gkcartridge->ram_page = (offset>>1) & 1;
3411         }
3412      }
3413   }
3414}
3415
3416/*****************************************************************************/
29693417#define TI99_CARTRIDGE_SLOT(p)  MDRV_CARTSLOT_ADD(p) \
2970        MDRV_CARTSLOT_EXTENSION_LIST("rpk,bin") \
2971        MDRV_CARTSLOT_PCBTYPE(0, "none", TI99_CARTRIDGE_PCB_NONE) \
2972        MDRV_CARTSLOT_PCBTYPE(1, "standard", TI99_CARTRIDGE_PCB_STD) \
2973        MDRV_CARTSLOT_PCBTYPE(2, "paged", TI99_CARTRIDGE_PCB_PAGED) \
2974        MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM) \
2975        MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER) \
2976        MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX) \
2977        MDRV_CARTSLOT_PCBTYPE(6, "paged379i", TI99_CARTRIDGE_PCB_PAGED379I) \
2978        MDRV_CARTSLOT_PCBTYPE(7, "pagedcru", TI99_CARTRIDGE_PCB_PAGEDCRU) \
2979        MDRV_CARTSLOT_START(ti99_cartridge) \
2980        MDRV_CARTSLOT_LOAD(ti99_cartridge) \
2981        MDRV_CARTSLOT_UNLOAD(ti99_cartridge)
3418   MDRV_CARTSLOT_EXTENSION_LIST("rpk,bin") \
3419   MDRV_CARTSLOT_PCBTYPE(0, "none", TI99_CARTRIDGE_PCB_NONE) \
3420   MDRV_CARTSLOT_PCBTYPE(1, "standard", TI99_CARTRIDGE_PCB_STD) \
3421   MDRV_CARTSLOT_PCBTYPE(2, "paged", TI99_CARTRIDGE_PCB_PAGED) \
3422   MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM) \
3423   MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER) \
3424   MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX) \
3425   MDRV_CARTSLOT_PCBTYPE(6, "paged379i", TI99_CARTRIDGE_PCB_PAGED379I) \
3426   MDRV_CARTSLOT_PCBTYPE(7, "pagedcru", TI99_CARTRIDGE_PCB_PAGEDCRU) \
3427   MDRV_CARTSLOT_PCBTYPE(8, "gramkracker", TI99_CARTRIDGE_PCB_GRAMKRACKER) \
3428   MDRV_CARTSLOT_START(ti99_cartridge) \
3429   MDRV_CARTSLOT_LOAD(ti99_cartridge) \
3430   MDRV_CARTSLOT_UNLOAD(ti99_cartridge)
29823431
29833432static MACHINE_DRIVER_START(ti99_multicart)
2984        TI99_CARTRIDGE_SLOT("cartridge1")
2985        TI99_CARTRIDGE_SLOT("cartridge2")
2986        TI99_CARTRIDGE_SLOT("cartridge3")
2987        TI99_CARTRIDGE_SLOT("cartridge4")
3433   TI99_CARTRIDGE_SLOT("cartridge1")
3434   TI99_CARTRIDGE_SLOT("cartridge2")
3435   TI99_CARTRIDGE_SLOT("cartridge3")
3436   TI99_CARTRIDGE_SLOT("cartridge4")
29883437MACHINE_DRIVER_END
29893438
29903439static const char DEVTEMPLATE_SOURCE[] = __FILE__;
src/mess/machine/ti99_4x.c
r8275r8276
239239set) */
240240static char hsgpl_crdena;
241241
242/* Used to cache the switch settings. */
243static UINT8 gk_switch[8];
244
242245/* true if 99/4p rom6 is enabled */
243246static int ti99_4p_internal_rom6_enable;
244247/* pointer to the ROM6 data */
r8275r8276
428431MACHINE_START( ti99_4p )
429432{
430433   UINT8* mem = memory_region(machine, "maincpu");
431   
434
432435   /* Set up system ROM and scratch pad pointers. Must be set up here */
433436   /* so that the system can successfully reset (otherwise the reset  */
434437   /* vector would be missing in 0x0000). */
r8275r8276
539542   has_usb_sm = input_port_read(machine, "HDCTRL") & HD_USB;
540543   has_pcode = input_port_read(machine, "EXTCARD") & EXT_PCODE;
541544
545   /* Get the GK settings once */
546   gk_switch[1] = input_port_read(machine, "GKSWITCH1");
547   gk_switch[2] = input_port_read(machine, "GKSWITCH2");
548   gk_switch[3] = input_port_read(machine, "GKSWITCH3");
549   gk_switch[4] = input_port_read(machine, "GKSWITCH4");
550   gk_switch[5] = input_port_read(machine, "GKSWITCH5");
551
542552   /* set up optional expansion hardware */
543553   ti99_peb_reset(ti99_model == model_99_4p, tms9901_set_int1, NULL);
544554
r8275r8276
655665NVRAM_HANDLER( ti99 )
656666{
657667   const char *filename;
658   
668
659669   /* We may have different HSGPL settings for 80 column and traditional */
660670   /* 40 column display. For convenience, we use two different nvram files. */
661671   if (has_evpc)
662672      filename = "hsgpl80.nv";
663673   else
664674      filename = "hsgpl40.nv";
665   
675
666676   if ((ti99_model == model_99_4p) || (input_port_read(machine, "EXTCARD") & (EXT_HSGPL_ON | EXT_HSGPL_FLASH)))
667677   {
668678      if (read_or_write==0)
r8275r8276
681691   hsgpl_flash_mode = newval & EXT_HSGPL_FLASH;
682692}
683693
694INPUT_CHANGED( gk_changed )
695{
696   gk_switch[(long)param&0x07] = newval;
697}
698
699UINT8 get_gk_switch(int index)
700{
701   return gk_switch[index];
702}
703
684704/*
685705    video initialization.
686706*/
687707VIDEO_START( ti99_4ev )
688708{
689709   VIDEO_START_CALL(generic_bitmapped);
690   v9938_init(machine, 0, machine->primary_screen, machine->generic.tmpbitmap,
710   v9938_init(machine, 0, machine->primary_screen, machine->generic.tmpbitmap,
691711      MODEL_V9938, 0x20000, tms9901_set_int2);   /* v38 with 128 kb of video RAM */
692712}
693713
r8275r8276
9951015   tms5220_data_w(devtag_get_device(space->machine, "tmc0285"), offset, (data >> 8) & 0xff);
9961016}
9971017
998static UINT8 GROM_dataread(offs_t offset)
1018static UINT8 GROM_dataread(running_machine *machine, offs_t offset)
9991019{
10001020   UINT8 reply = 0, replycart;
1001   int override_console = FALSE; /* for future extension */
1021   int override_console = FALSE;
10021022
1023   // Operation of GRAMKracker
1024   if (input_port_read(machine, "CARTSLOT")==CART_GK)
1025   {
1026      if (((console_GROMs.addr < 0x2000) && (gk_switch[2]==GK_GRAM0))
1027         || ((console_GROMs.addr >= 0x2000) && (console_GROMs.addr < 0x4000) &&
1028            ((gk_switch[3]==GK_GRAM12) || (gk_switch[5]==GK_LDON)))
1029         || ((console_GROMs.addr >= 0x4000) && (console_GROMs.addr < 0x6000) &&
1030            (gk_switch[3]==GK_GRAM12)))
1031      {
1032         override_console = TRUE;
1033      }
1034   }
1035
10031036   if (console_GROMs.addr < 0x6000)
10041037   {
10051038      /* GROMs are buffered. Data is retrieved from a buffer, */
r8275r8276
10111044      console_GROMs.buf = console_GROMs.data_ptr[console_GROMs.addr];
10121045   }
10131046
1014   /* The address pointer in the cartridge system is updated by this */
1015   /* call. We pretend to do a data read, so we mask away the address */
1016   /* bit in the offset. */
1017   replycart = ti99_cartridge_grom_r(cartslots, offset&0xfffc);
1047   // The address pointer in the cartridge system is updated by this call.
1048   replycart = ti99_cartridge_grom_r(cartslots, offset);
10181049
10191050   if (console_GROMs.addr >= 0x6000 || override_console)
10201051   {
r8275r8276
10331064   return reply;
10341065}
10351066
1067static void GRAM_datawrite(offs_t offset, UINT8 data)
1068{
1069   // The console does not contain RAM at these locations.
1070   // Writing has only effect when there is a GRAM Kracker
1071   ti99_cartridge_grom_w(cartslots, offset, data);
1072
1073   /* Each GROM chip has its own counter, so we update all of them even */
1074   /* when we do not access them. */
1075   /* The program counter wraps at each GROM chip size (8K), */
1076   /* so 0x5fff + 1 = 0x4000. */
1077   console_GROMs.addr = ((console_GROMs.addr + 1) & 0x1FFF) | (console_GROMs.addr & 0xE000);
1078
1079   /* Reset the read and write address flipflops. */
1080   console_GROMs.raddr_LSB = console_GROMs.waddr_LSB = FALSE;
1081}
1082
1083
10361084/*
10371085    GPL read
10381086*/
r8275r8276
10931141         console_GROMs.raddr_LSB = TRUE;
10941142      }
10951143      /* GROM address values must be globally unique. */
1144      // FIXME: Parsec in slot 2 asserts here (bug in Parsec, but
1145      //     should never bring the emulation into trouble)
1146      //     last actions were invalid reads from 99fa
1147      // FIXME: HSGPL asserts here when switched on during runtime
1148      //     You should not do that, but again the emulation should
1149      //     not assert either
10961150      assert (replycart == reply);
10971151   }
10981152   else
r8275r8276
11001154      /* Read GROM data */
11011155      /* Note that we shift the GROM port address to accomodate for */
11021156      /* 8-bit and 16-bit systems. */
1103      reply = ((UINT16)GROM_dataread(offset<<1)) << 8;
1157      reply = ((UINT16)GROM_dataread(space->machine, offset<<1)) << 8;
11041158   }
11051159
11061160   if (hsgpl_crdena)
r8275r8276
11461200         console_GROMs.addr = (console_GROMs.addr & 0xFF00) | ((data >> 8) & 0xFF);
11471201         /* Setting the address causes a new read, putting the */
11481202         /* value into the buffer. We don't need the value here. */
1149         GROM_dataread(offset<<1);
1203         GROM_dataread(space->machine, (offset<<1)&0xfffc);
11501204         console_GROMs.waddr_LSB = FALSE;
11511205      }
11521206      else
r8275r8276
11581212   }
11591213   else
11601214   {
1161      /* write GROM data */
1162      /* the console GROMs are always affected */
1163      /* BTW, console GROMs are never GRAMs, therefore there is no */
1164      /* need to actually write anything, so we just read ahead */
1165      /* TODO: There could be cartridges with GRAM, so this must be */
1166      /* fixed.         */
1167      GROM_dataread(offset<<1);
1215      /* write GRAM data */
1216      GRAM_datawrite(offset<<1, (data>>8)&0xff);
11681217      console_GROMs.raddr_LSB = console_GROMs.waddr_LSB = FALSE;
11691218   }
11701219
r8275r8276
12061255      assert (replycart == reply);
12071256   }
12081257   else
1209      reply = GROM_dataread(offset);
1258      reply = GROM_dataread(space->machine, offset);
12101259
12111260   return reply;
12121261}
r8275r8276
12271276      {
12281277         console_GROMs.addr = (console_GROMs.addr & 0xFF00) | (data & 0xFF);
12291278
1230         GROM_dataread(offset);
1279         GROM_dataread(space->machine, offset);
12311280         console_GROMs.waddr_LSB = FALSE;
12321281      }
12331282      else
r8275r8276
12391288   }
12401289   else
12411290   {
1242      GROM_dataread(offset);
1291      GRAM_datawrite(offset, (data>>8)&0xff);
12431292      console_GROMs.raddr_LSB = console_GROMs.waddr_LSB = FALSE;
12441293   }
12451294}
src/mess/machine/ti99_4x.h
r8275r8276
9393};
9494typedef struct _GROM_port_t GROM_port_t;
9595
96
97#if 0
98/* defines for input port "CFG" */
99enum
100{
101   config_xRAM_bit      = 0,
102   config_xRAM_mask   = 0x7,   /* 3 bits */
103   config_speech_bit   = 3,
104   config_speech_mask   = 0x1,
105   config_fdc_bit      = 4,
106   config_fdc_mask      = 0x103,/* 3 bits (4, 5 and 12) */
107   config_rs232_bit   = 6,
108   config_rs232_mask   = 0x1,
109   /* next option only makes sense for ti99/4 */
110   config_handsets_bit   = 7,
111   config_handsets_mask= 0x1,
112   config_ide_bit      = 8,
113   config_ide_mask      = 0x1,
114   config_hsgpl_bit   = 9,
115   config_hsgpl_mask   = 0x1,
116   config_mecmouse_bit   = 10,
117   config_mecmouse_mask   = 0x1,
118   config_usbsm_bit   = 11,
119   config_usbsm_mask   = 0x1,
120   config_boot_bit      = 13,
121   config_boot_mask   = 0x1,
122   config_cartslot_bit   = 14,
123   config_cartslot_mask   = 0xf, /* need four bits: covers all current and possibly future cartslots, and one auto mode */
124   config_pcode_bit   = 18,
125   config_pcode_mask   = 0x1
126};
127#endif
128
12996/*
13097    Configuration values
13198*/
r8275r8276
187154   CART_2,
188155   CART_3,
189156   CART_4,
190   CART_GK
157   CART_GK = 15
191158};
192159
160enum
161{
162   GK_OFF = 0,
163   GK_NORMAL = 1,
164   GK_GRAM0 = 0,
165   GK_OPSYS = 1,
166   GK_GRAM12 = 0,
167   GK_TIBASIC = 1,
168   GK_BANK1 = 0,
169   GK_WP = 1,
170   GK_BANK2 = 2,
171   GK_LDON = 0,
172   GK_LDOFF = 1
173};
193174
175
194176/* Cartridge types */
195177enum
196178{
r8275r8276
222204NVRAM_HANDLER( ti99 );
223205INPUT_CHANGED( hsgpl_changed );
224206
207/* For GRAM Kracker */
208INPUT_CHANGED( gk_changed );
209
225210VIDEO_START( ti99_4ev );
226211INTERRUPT_GEN( ti99_vblank_interrupt );
227212INTERRUPT_GEN( ti99_4ev_hblank_interrupt );
r8275r8276
230215void ti99_common_init(running_machine *machine, const TMS9928a_interface *gfxparm);
231216int ti99_is_99_8(void);
232217
218UINT8 get_gk_switch(int index);
219
233220READ16_HANDLER( ti99_nop_8_r );
234221WRITE16_HANDLER( ti99_nop_8_w );
235222
src/mess/drivers/ti99_8.c
r8275r8276
231231   PORT_START( "HDCTRL" )
232232   PORT_CONFNAME( 0x03, 0x00, "HD controller" )
233233      PORT_CONFSETTING(    0x00, DEF_STR( None ) )
234//      PORT_CONFSETTING(    0x01, "Nouspikel IDE Controller" )
234//      PORT_CONFSETTING(    0x01, "Nouspikel IDE Controller" )
235235//      PORT_CONFSETTING(    0x02, "WHTech SCSI Controller" )
236236   PORT_CONFNAME( 0x08, 0x00, "USB-SM card" )
237237      PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
r8275r8276
242242      PORT_CONFSETTING(    0x00, DEF_STR( None ) )
243243      PORT_CONFSETTING(    0x01, "TI RS-232 card" )
244244
245   /* Flash setting is used to flash an empty HSGPL DSR ROM */
245   /* Flash setting is used to flash an empty HSGPL DSR ROM */
246246   PORT_START( "EXTCARD" )
247247   PORT_CONFNAME( 0x03, 0x00, "HSGPL extension" ) PORT_CHANGED( hsgpl_changed, NULL)
248248      PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
r8275r8276
258258      PORT_CONFSETTING(    0x01, "Mechatronics Mouse" )
259259
260260   PORT_START( "CARTSLOT" )
261   PORT_DIPNAME( 0x07, 0x00, "Cartridge slot" )
261   PORT_DIPNAME( 0x0f, 0x00, "Cartridge slot" )
262262      PORT_DIPSETTING(    0x00, "Auto" )
263263      PORT_DIPSETTING(    0x01, "Slot 1" )
264264      PORT_DIPSETTING(    0x02, "Slot 2" )
265265      PORT_DIPSETTING(    0x03, "Slot 3" )
266266      PORT_DIPSETTING(    0x04, "Slot 4" )
267//      PORT_CONFSETTING(    0x05, "GRAM Kracker" )
267      PORT_DIPSETTING(    0x0f, "GRAM Kracker" )
268268
269   /* GRAM Kracker Support */
270   PORT_START( "GKSWITCH1" )
271   PORT_DIPNAME( 0x01, 0x01, "GK switch 1" ) PORT_CONDITION( "CARTSLOT", 0x0f, PORTCOND_EQUALS, 0x0f )  PORT_CHANGED( gk_changed, (void *)1)
272      PORT_DIPSETTING(    0x00, "GK Off" )
273      PORT_DIPSETTING(    0x01, DEF_STR( Normal ) )
274
275   PORT_START( "GKSWITCH2" )
276   PORT_DIPNAME( 0x01, 0x01, "GK switch 2" ) PORT_CONDITION( "CARTSLOT", 0x0f, PORTCOND_EQUALS, 0x0f )  PORT_CHANGED( gk_changed, (void *)2)
277      PORT_DIPSETTING(    0x00, "GRAM 0" )
278      PORT_DIPSETTING(    0x01, "Op Sys" )
279
280   PORT_START( "GKSWITCH3" )
281   PORT_DIPNAME( 0x01, 0x01, "GK switch 3" ) PORT_CONDITION( "CARTSLOT", 0x0f, PORTCOND_EQUALS, 0x0f )  PORT_CHANGED( gk_changed, (void *)3)
282      PORT_DIPSETTING(    0x00, "GRAM 1-2" )
283      PORT_DIPSETTING(    0x01, "TI BASIC" )
284
285   PORT_START( "GKSWITCH4" )
286   PORT_DIPNAME( 0x03, 0x01, "GK switch 4" ) PORT_CONDITION( "CARTSLOT", 0x0f, PORTCOND_EQUALS, 0x0f )  PORT_CHANGED( gk_changed, (void *)4)
287      PORT_DIPSETTING(    0x00, "Bank 1" )
288      PORT_DIPSETTING(    0x01, "W/P" )
289      PORT_DIPSETTING(    0x02, "Bank 2" )
290
291   PORT_START( "GKSWITCH5" )
292   PORT_DIPNAME( 0x01, 0x00, "GK switch 5" ) PORT_CONDITION( "CARTSLOT", 0x0f, PORTCOND_EQUALS, 0x0f )  PORT_CHANGED( gk_changed, (void *)5)
293      PORT_DIPSETTING(    0x00, "Loader On" )
294      PORT_DIPSETTING(    0x01, "Loader Off" )
295
269296   PORT_START( "HFDCDIP" )
297   PORT_DIPNAME( 0xff, 0x55, "HFDC drive config" ) PORT_CONDITION( "DISKCTRL", 0x07, PORTCOND_EQUALS, 0x03 )
298      PORT_DIPSETTING( 0x00, "40 track, 16 ms")
299      PORT_DIPSETTING( 0xaa, "40 track, 8 ms")
300      PORT_DIPSETTING( 0x55, "80 track, 2 ms")
301      PORT_DIPSETTING( 0xff, "80 track HD, 2 ms")
302
303   PORT_START( "HFDCDIP" )
270304   PORT_DIPNAME( 0x03, 0x02, "HFDC drive config" ) PORT_CONDITION( "DISKCTRL", 0x07, PORTCOND_EQUALS, 0x03 )
271305      PORT_DIPSETTING( 0x00, "40 track, 16 ms")
272306      PORT_DIPSETTING( 0x01, "40 track, 8 ms")
r8275r8276
564598   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
565599
566600   /* devices */
567/*   MDRV_IDE_CONTROLLER_ADD( "ide", ti99_ide_interrupt )
568   MDRV_RTC65271_ADD("ide_rtc", ti99_clk_interrupt_callback) */
601   // MDRV_IDE_CONTROLLER_ADD( "ide", ti99_ide_interrupt
602   // MDRV_RTC65271_ADD("ide_rtc", ti99_clk_interrupt_callback)
569603
570604   MDRV_CASSETTE_ADD( "cassette", default_cassette_config )
571605
r8275r8276
617651   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.20)
618652
619653   /* devices */
620/*   MDRV_IDE_CONTROLLER_ADD( "ide", ti99_ide_interrupt )
621   MDRV_IDE_HARDDISK_ADD( "ide_harddisk" )
622   MDRV_RTC65271_ADD("ide_rtc", ti99_clk_interrupt_callback)  */
654   // MDRV_IDE_CONTROLLER_ADD( "ide", ti99_ide_interrupt )
655   // MDRV_IDE_HARDDISK_ADD( "ide_harddisk" )
656   // MDRV_RTC65271_ADD("ide_rtc", ti99_clk_interrupt_callback)
623657
624658   MDRV_CASSETTE_ADD( "cassette", default_cassette_config )
625659
src/mess/drivers/ti99_4x.c
r8275r8276
5656   AM_RANGE(0x2000, 0x3fff) AM_READWRITE(ti99_nop_8_r, ti99_nop_8_w)   /*lower 8kb of RAM extension - installed dynamically*/
5757   AM_RANGE(0x4000, 0x5fff) AM_READWRITE(ti99_4x_peb_r, ti99_4x_peb_w)   /*DSR ROM space*/
5858   AM_RANGE(0x6000, 0x7fff) AM_READWRITE(ti99_cart_r, ti99_cart_w)     /*cartridge memory*/
59//   AM_RANGE(0x6000, 0x7fff) AM_DEVREADWRITE("ti99_multicart", ti99_multicart_r, ti99_multicart_w)
59//  AM_RANGE(0x6000, 0x7fff) AM_DEVREADWRITE("ti99_multicart", ti99_multicart_r, ti99_multicart_w)
6060   AM_RANGE(0x8000, 0x80ff) AM_MIRROR(0x0300) AM_RAMBANK("bank1")         /*RAM PAD, mirrored 4 times*/
6161   AM_RANGE(0x8400, 0x87ff) AM_READWRITE(ti99_nop_8_r, ti99_wsnd_w)   /*soundchip write*/
6262   AM_RANGE(0x8800, 0x8bff) AM_READWRITE(ti99_rvdp_r, ti99_nop_8_w)   /*vdp read*/
r8275r8276
7474   AM_RANGE(0x2000, 0x3fff) AM_READWRITE(ti99_nop_8_r, ti99_nop_8_w)   /*lower 8kb of RAM extension - installed dynamically*/
7575   AM_RANGE(0x4000, 0x5fff) AM_READWRITE(ti99_4x_peb_r, ti99_4x_peb_w)   /*DSR ROM space*/
7676   AM_RANGE(0x6000, 0x7fff) AM_READWRITE(ti99_cart_r, ti99_cart_w)     /*cartridge memory*/
77//   AM_RANGE(0x6000, 0x7fff) AM_DEVREADWRITE("ti99_multicart", ti99_multicart_r, ti99_multicart_w)
77//  AM_RANGE(0x6000, 0x7fff) AM_DEVREADWRITE("ti99_multicart", ti99_multicart_r, ti99_multicart_w)
7878   AM_RANGE(0x8000, 0x80ff) AM_MIRROR(0x0300) AM_RAMBANK("bank1")         /*RAM PAD, mirrored 4 times*/
7979   AM_RANGE(0x8400, 0x87ff) AM_READWRITE(ti99_nop_8_r, ti99_wsnd_w)   /*soundchip write*/
8080   AM_RANGE(0x8800, 0x8bff) AM_READWRITE(ti99_rv38_r, ti99_nop_8_w)   /*vdp read*/
r8275r8276
133133   PORT_START( "HDCTRL" )
134134   PORT_CONFNAME( 0x03, 0x00, "HD controller" )
135135      PORT_CONFSETTING(    0x00, DEF_STR( None ) )
136//      PORT_CONFSETTING(    0x01, "Nouspikel IDE Controller" )
136//      PORT_CONFSETTING(    0x01, "Nouspikel IDE Controller" )
137137//      PORT_CONFSETTING(    0x02, "WHTech SCSI Controller" )
138138   PORT_CONFNAME( 0x04, 0x00, "USB-SM card" )
139139      PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
r8275r8276
144144      PORT_CONFSETTING(    0x00, DEF_STR( None ) )
145145      PORT_CONFSETTING(    0x01, "TI RS-232 card" )
146146
147   /* Flash setting is used to flash an empty HSGPL DSR ROM */
147   /* Flash setting is used to flash an empty HSGPL DSR ROM */
148148   PORT_START( "EXTCARD" )
149149   PORT_CONFNAME( 0x03, 0x00, "HSGPL extension" ) PORT_CHANGED( hsgpl_changed, NULL)
150150      PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
r8275r8276
160160      PORT_CONFSETTING(    0x01, "Mechatronics Mouse" )
161161
162162   PORT_START( "CARTSLOT" )
163   PORT_DIPNAME( 0x07, 0x00, "Cartridge slot" )
163   PORT_DIPNAME( 0x0f, 0x00, "Cartridge slot" )
164164      PORT_DIPSETTING(    0x00, "Auto" )
165165      PORT_DIPSETTING(    0x01, "Slot 1" )
166166      PORT_DIPSETTING(    0x02, "Slot 2" )
167167      PORT_DIPSETTING(    0x03, "Slot 3" )
168168      PORT_DIPSETTING(    0x04, "Slot 4" )
169//      PORT_DIPSETTING(    0x05, "GRAM Kracker" )
169      PORT_DIPSETTING(    0x0f, "GRAM Kracker" )
170170
171   /* GRAM Kracker Support */
172   PORT_START( "GKSWITCH1" )
173   PORT_DIPNAME( 0x01, 0x01, "GK switch 1" ) PORT_CONDITION( "CARTSLOT", 0x0f, PORTCOND_EQUALS, 0x0f )  PORT_CHANGED( gk_changed, (void *)1)
174      PORT_DIPSETTING(    0x00, "GK Off" )
175      PORT_DIPSETTING(    0x01, DEF_STR( Normal ) )
176
177   PORT_START( "GKSWITCH2" )
178   PORT_DIPNAME( 0x01, 0x01, "GK switch 2" ) PORT_CONDITION( "CARTSLOT", 0x0f, PORTCOND_EQUALS, 0x0f )  PORT_CHANGED( gk_changed, (void *)2)
179      PORT_DIPSETTING(    0x00, "GRAM 0" )
180      PORT_DIPSETTING(    0x01, "Op Sys" )
181
182   PORT_START( "GKSWITCH3" )
183   PORT_DIPNAME( 0x01, 0x01, "GK switch 3" ) PORT_CONDITION( "CARTSLOT", 0x0f, PORTCOND_EQUALS, 0x0f )  PORT_CHANGED( gk_changed, (void *)3)
184      PORT_DIPSETTING(    0x00, "GRAM 1-2" )
185      PORT_DIPSETTING(    0x01, "TI BASIC" )
186
187   PORT_START( "GKSWITCH4" )
188   PORT_DIPNAME( 0x03, 0x01, "GK switch 4" ) PORT_CONDITION( "CARTSLOT", 0x0f, PORTCOND_EQUALS, 0x0f )  PORT_CHANGED( gk_changed, (void *)4)
189      PORT_DIPSETTING(    0x00, "Bank 1" )
190      PORT_DIPSETTING(    0x01, "W/P" )
191      PORT_DIPSETTING(    0x02, "Bank 2" )
192
193   PORT_START( "GKSWITCH5" )
194   PORT_DIPNAME( 0x01, 0x00, "GK switch 5" ) PORT_CONDITION( "CARTSLOT", 0x0f, PORTCOND_EQUALS, 0x0f )  PORT_CHANGED( gk_changed, (void *)5)
195      PORT_DIPSETTING(    0x00, "Loader On" )
196      PORT_DIPSETTING(    0x01, "Loader Off" )
197
171198   PORT_START( "HFDCDIP" )
172199   PORT_DIPNAME( 0xff, 0x55, "HFDC drive config" ) PORT_CONDITION( "DISKCTRL", 0x07, PORTCOND_EQUALS, 0x03 )
173200      PORT_DIPSETTING( 0x00, "40 track, 16 ms")
r8275r8276
306333   PORT_START( "HDCTRL" )
307334   PORT_CONFNAME( 0x03, 0x00, "HD controller" )
308335      PORT_CONFSETTING(    0x00, DEF_STR( None ) )
309//      PORT_CONFSETTING(    0x01, "Nouspikel IDE Controller" )
336//      PORT_CONFSETTING(    0x01, "Nouspikel IDE Controller" )
310337//      PORT_CONFSETTING(    0x02, "WHTech SCSI Controller" )
311338   PORT_CONFNAME( 0x08, 0x00, "USB-SM card" )
312339      PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
r8275r8276
335362      PORT_CONFSETTING(    0x04, DEF_STR( On ) )
336363
337364   PORT_START( "CARTSLOT" )
338   PORT_DIPNAME( 0x07, 0x00, "Cartridge slot" )
365   PORT_DIPNAME( 0x0f, 0x00, "Cartridge slot" )
339366      PORT_DIPSETTING(    0x00, "Auto" )
340367      PORT_DIPSETTING(    0x01, "Slot 1" )
341368      PORT_DIPSETTING(    0x02, "Slot 2" )
342369      PORT_DIPSETTING(    0x03, "Slot 3" )
343370      PORT_DIPSETTING(    0x04, "Slot 4" )
344//      PORT_DIPSETTING(    0x05, "GRAM Kracker" )
371      PORT_DIPSETTING(    0x0f, "GRAM Kracker" )
345372
373   /* GRAM Kracker Support */
374   PORT_START( "GKSWITCH1" )
375   PORT_DIPNAME( 0x01, 0x01, "GK switch 1" ) PORT_CONDITION( "CARTSLOT", 0x0f, PORTCOND_EQUALS, 0x0f ) PORT_CHANGED( gk_changed, (void *)1)
376      PORT_DIPSETTING(    0x00, "GK Off" )
377      PORT_DIPSETTING(    0x01, DEF_STR( Normal ) )
378
379   PORT_START( "GKSWITCH2" )
380   PORT_DIPNAME( 0x01, 0x01, "GK switch 2" ) PORT_CONDITION( "CARTSLOT", 0x0f, PORTCOND_EQUALS, 0x0f ) PORT_CHANGED( gk_changed, (void *)2)
381      PORT_DIPSETTING(    0x00, "GRAM 0" )
382      PORT_DIPSETTING(    0x01, "Op Sys" )
383
384   PORT_START( "GKSWITCH3" )
385   PORT_DIPNAME( 0x01, 0x01, "GK switch 3" ) PORT_CONDITION( "CARTSLOT", 0x0f, PORTCOND_EQUALS, 0x0f ) PORT_CHANGED( gk_changed, (void *)3)
386      PORT_DIPSETTING(    0x00, "GRAM 1-2" )
387      PORT_DIPSETTING(    0x01, "TI BASIC" )
388
389   PORT_START( "GKSWITCH4" )
390   PORT_DIPNAME( 0x03, 0x01, "GK switch 4" ) PORT_CONDITION( "CARTSLOT", 0x0f, PORTCOND_EQUALS, 0x0f ) PORT_CHANGED( gk_changed, (void *)4)
391      PORT_DIPSETTING(    0x00, "Bank 1" )
392      PORT_DIPSETTING(    0x01, "W/P" )
393      PORT_DIPSETTING(    0x02, "Bank 2" )
394
395   PORT_START( "GKSWITCH5" )
396   PORT_DIPNAME( 0x01, 0x00, "GK switch 5" ) PORT_CONDITION( "CARTSLOT", 0x0f, PORTCOND_EQUALS, 0x0f ) PORT_CHANGED( gk_changed, (void *)5)
397      PORT_DIPSETTING(    0x00, "Loader On" )
398      PORT_DIPSETTING(    0x01, "Loader Off" )
399
346400   PORT_START( "HFDCDIP" )
347401   PORT_DIPNAME( 0xff, 0x55, "HFDC drive config" ) PORT_CONDITION( "DISKCTRL", 0x07, PORTCOND_EQUALS, 0x03 )
348402      PORT_DIPSETTING( 0x00, "40 track, 16 ms")
r8275r8276
688742
689743   /* For HSGPL */
690744   MDRV_NVRAM_HANDLER( ti99 )
691   
745
692746   /* video hardware */
693747   MDRV_IMPORT_FROM(tms9928a)
694748   MDRV_SCREEN_MODIFY("screen")
r8275r8276
709763   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
710764
711765   /* devices */
712/*   MDRV_IDE_CONTROLLER_ADD( "ide", ti99_ide_interrupt )
713   MDRV_RTC65271_ADD("ide_rtc", ti99_clk_interrupt_callback)   */
766   // MDRV_IDE_CONTROLLER_ADD( "ide", ti99_ide_interrupt )
767   // MDRV_RTC65271_ADD("ide_rtc", ti99_clk_interrupt_callback)
714768
715769   MDRV_CASSETTE_ADD( "cassette1", default_cassette_config )
716770   MDRV_CASSETTE_ADD( "cassette2", default_cassette_config )
r8275r8276
747801
748802   /* For HSGPL */
749803   MDRV_NVRAM_HANDLER( ti99 )
750   
804
751805   /* video hardware */
752806   MDRV_IMPORT_FROM(tms9928a)
753807   MDRV_SCREEN_MODIFY("screen")
r8275r8276
766820   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.20)
767821
768822   /* devices */
769/*   MDRV_IDE_CONTROLLER_ADD( "ide", ti99_ide_interrupt )
770   MDRV_RTC65271_ADD("ide_rtc", ti99_clk_interrupt_callback)  */
823   // MDRV_IDE_CONTROLLER_ADD( "ide", ti99_ide_interrupt
824   // MDRV_RTC65271_ADD("ide_rtc", ti99_clk_interrupt_callback)
771825
772826   MDRV_CASSETTE_ADD( "cassette1", default_cassette_config )
773827   MDRV_CASSETTE_ADD( "cassette2", default_cassette_config )
r8275r8276
804858
805859   /* For HSGPL */
806860   MDRV_NVRAM_HANDLER( ti99 )
807   
861
808862   /* video hardware */
809863   MDRV_IMPORT_FROM(tms9928a)
810864   MDRV_SCREEN_MODIFY("screen")
r8275r8276
823877   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.20)
824878
825879   /* devices */
826/*   MDRV_IDE_CONTROLLER_ADD( "ide", ti99_ide_interrupt )
827   MDRV_RTC65271_ADD("ide_rtc", ti99_clk_interrupt_callback) */
880   // MDRV_IDE_CONTROLLER_ADD( "ide", ti99_ide_interrupt )
881   // MDRV_RTC65271_ADD("ide_rtc", ti99_clk_interrupt_callback)
828882
829883   MDRV_CASSETTE_ADD( "cassette1", default_cassette_config )
830884   MDRV_CASSETTE_ADD( "cassette2", default_cassette_config )
r8275r8276
863917
864918   /* For HSGPL */
865919   MDRV_NVRAM_HANDLER( ti99 )
866   
920
867921   /* video hardware */
868922   MDRV_IMPORT_FROM(tms9928a)
869923   MDRV_SCREEN_MODIFY("screen")
r8275r8276
882936   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.20)
883937
884938   /* devices */
885/*   MDRV_IDE_CONTROLLER_ADD( "ide", ti99_ide_interrupt )
886   MDRV_RTC65271_ADD("ide_rtc", ti99_clk_interrupt_callback) */
939   // MDRV_IDE_CONTROLLER_ADD( "ide", ti99_ide_interrupt )
940   // MDRV_RTC65271_ADD("ide_rtc", ti99_clk_interrupt_callback) */
887941
888942   MDRV_CASSETTE_ADD( "cassette1", default_cassette_config )
889943   MDRV_CASSETTE_ADD( "cassette2", default_cassette_config )
r8275r8276
921975
922976   /* For HSGPL */
923977   MDRV_NVRAM_HANDLER( ti99 )
924   
978
925979   /* video hardware */
926980   MDRV_SCREEN_ADD("screen", RASTER)
927981   MDRV_SCREEN_REFRESH_RATE(60)   /* or 50Hz */
r8275r8276
9481002   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.20)
9491003
9501004   /* devices */
951/*   MDRV_IDE_CONTROLLER_ADD( "ide", ti99_ide_interrupt )   
952   MDRV_RTC65271_ADD("ide_rtc", ti99_clk_interrupt_callback)  */
1005   // MDRV_IDE_CONTROLLER_ADD( "ide", ti99_ide_interrupt )
1006   // MDRV_RTC65271_ADD("ide_rtc", ti99_clk_interrupt_callback)  */
9531007
9541008   MDRV_CASSETTE_ADD( "cassette1", default_cassette_config )
9551009   MDRV_CASSETTE_ADD( "cassette2", default_cassette_config )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team