Previous 15994 Revisions Next

r8297 Sunday 20th June, 2010 at 13:22:27 UTC by Michael Zapf
Modifications related to getting TI-99/4P going again, plus some
refactoring
[src/mess/drivers]ti99_4p.c ti99_4x.c ti99_8.c
[src/mess/machine]99_hsgpl.c 99_peb.c ti99_4x.c ti99_4x.h

src/mess/machine/99_peb.c
r8296r8297
142142/* index of the currently active card (-1 if none) */
143143static int active_card;
144144
145/* when 1, enable a workaround required by snug sgcpu 99/4p, which mistakenly
146enables 2 cards simultaneously */
147#define ACTIVATE_BIT_EMULATE 1
145/* index of the currently active card, overridden by the mapper */
146static int active_card_tmp;
148147
149#if ACTIVATE_BIT_EMULATE
150/* activate mask: 1 bit set for each card enable CRU bit set */
151static int active_card_mask;
152#endif
148/* Mapper override. */
149static int mapper_override;
153150
154151/* ila: inta status register (not actually used on ti-99/4(a), but nevertheless
155152present) */
r8296r8297
198195   intb_callback = in_intb_callback;
199196
200197   active_card = -1;
201#if ACTIVATE_BIT_EMULATE
202   active_card_mask = 0;
203#endif
198   active_card_tmp = -1;
199
200   mapper_override = FALSE; // for ti99_4p
201
204202   ila = 0;
205203   ilb = 0;
206204}
r8296r8297
394392         reply |= ((unsigned) (*handler)(space, offset << 1)) << 8;
395393      }
396394   }
395//  printf("[%04x:%04x] = %04x\n", (active_card<<8)+0x1000, (offset<<1)+0x4000, reply);
397396
398397   return tmp_buffer = reply;
399398}
r8296r8297
483482
484483   if (active_card != -1)
485484   {
486            handler = expansion_ports[active_card].mem_read;
485      handler = expansion_ports[active_card].mem_read;
487486      if (handler)
488487         reply = (*handler)(space, offset);
489488   }
r8296r8297
597596/*
598597    Read CRU in range >0400->1ffe (>200->fff) (snug sgcpu 99/4p)
599598*/
600 READ8_HANDLER ( ti99_4p_peb_cru_r )
599READ8_HANDLER( ti99_4p_peb_cru_r )
601600{
602601   int port;
603602   cru_read_handler handler;
r8296r8297
614613/*
615614    Write CRU in range >0400->1ffe (>200->fff) (snug sgcpu 99/4p)
616615*/
617WRITE8_HANDLER ( ti99_4p_peb_cru_w )
616WRITE8_HANDLER( ti99_4p_peb_cru_w )
618617{
619618   int port;
620619   cru_write_handler handler;
621620
621   int cru_address = (offset + 0x200)<<1;
622
622623   port = offset >> 7;
623624   handler = ti99_4p_expansion_ports[port].cru_write;
624625
r8296r8297
626627      (*handler)(space->machine, offset & 0x7f, data);
627628
628629   /* expansion card enable? */
629   if ((offset & 0x7f) == 0)
630   if ((cru_address & 0xfe) == 0)
630631   {
631632      if (data & 1)
632633      {
633634         /* enable */
635         if (cru_address == 0x1e00)
636         {
637            // The internal mapper has precedence over the external bus.
638            // It may be turned on although there is another device currently turned on
639            active_card_tmp = active_card;
640            mapper_override = TRUE;
641         }
634642         active_card = port;
635#if ACTIVATE_BIT_EMULATE
636         active_card_mask |= (1 << port);
637#endif
638643      }
639644      else
640645      {
641#if ACTIVATE_BIT_EMULATE
642         active_card_mask &= ~(1 << port);
643#endif
644         if (port == active_card)   /* geez... who cares? */
646         if ((cru_address == 0x1e00) && mapper_override)
645647         {
646            active_card = -1;         /* no port selected */
647#if ACTIVATE_BIT_EMULATE
648            active_card_mask &= ~(1 << port);
649
650            if (active_card_mask)
648            active_card = active_card_tmp;
649            mapper_override = FALSE;
650         }
651         else
652         {
653            if (port == active_card)   /* geez... who cares? */
651654            {
652               int i;
653               logerror("Extension card error, trying to recover\n");
654               for (i = 0; i<28; i++)
655                  if (active_card_mask & (1 << i))
656                     active_card = i;
655               active_card = -1;         /* no port selected */
657656            }
658#endif
659657         }
660658      }
661659   }
r8296r8297
709707         reply = (ilb & 0xff) | (ilb << 8);
710708   }
711709
710//  printf("[%04x:%04x] = %04x\n", (active_card<<8)+0x400, (offset<<1)+0x4000, reply);
712711   return tmp_buffer = reply;
713712}
714713
src/mess/machine/99_hsgpl.c
r8296r8297
235235
236236   if (ti99_hsgpl_get_dirty_flag())
237237   {
238      filerr = mame_fopen(SEARCHPATH_NVRAM, name,
238      filerr = mame_fopen(SEARCHPATH_NVRAM, name,
239239         OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
240240
241241      if (filerr != FILERR_NONE)
r8296r8297
301301      hsgpl.cru_reg |= 1 << offset;
302302   else
303303      hsgpl.cru_reg &= ~ (1 << offset);
304   
304
305305   if (offset == cr_crdena_bit)
306306      ti99_set_hsgpl_crdena(data);
307307}
r8296r8297
342342         reply = (hsgpl.addr + 1) & 0xff00;
343343         hsgpl.raddr_LSB = TRUE;
344344      }
345//      printf("hsgpl grmra: [%04x] = %02x\n", (offset<<1)+0x9800, reply>>8);
345346   }
346347   else
347348   {   /* read GPL data */
r8296r8297
417418         break;
418419      }
419420
421//      printf("hsgpl grmrd: [%04x:%04x] = %02x\n", (offset<<1)+0x9800, hsgpl.addr, reply);
422
420423      reply <<= 8;
421424
422
423425      /* increment address */
424426      hsgpl.addr++;
425427      hsgpl.raddr_LSB = hsgpl.waddr_LSB = FALSE;
426428   }
427
428429   return reply;
429430}
430431
r8296r8297
447448      {
448449         hsgpl.addr = (hsgpl.addr & 0xFF00) | ((data >> 8) & 0xFF);
449450         hsgpl.waddr_LSB = FALSE;
451//          printf("hsgpl grmsa: [%04x:%04x]\n", (offset<<1)+0x9c00, hsgpl.addr);
450452      }
451453      else
452454      {
r8296r8297
583585      reply = 0;
584586      break;
585587   }
586
588//  printf("[%02x:%04x] = %04x\n", hsgpl.cur_bank, 0x6000 + 2*offset, reply);
587589   return reply;
588590}
589591
r8296r8297
606608      return;
607609   }
608610
609   /* MBX: RAM in 0x6c00-0x6ffd (it is unclear whether the MBX RAM area is
610    enabled/disabled by the wriena bit).  I guess RAM is unpaged, but it is
611    not implemented */
611   // MBX: RAM in 0x6c00-0x6ffd (it is unclear whether the MBX RAM area is
612   // enabled/disabled by the wriena bit).  I guess RAM is unpaged, but it is
613   // not implemented
612614   if ((hsgpl.cru_reg & cr_wriena) || ((hsgpl.cru_reg & cr_mbxena) && (offset >= 0x0600) && (offset <= 0x07fe)))
613615   {
614616      switch (port)
r8296r8297
637639      case 13:
638640      case 14:
639641      case 15:
640         /* feeprom is normally written to using GPL ports, and I don't know
641            writing through >6000 page is enabled */
642         // feeprom is normally written to using GPL ports, and I don't know
643         // writing through >6000 page is enabled
642644#if 0
643645         at29c040a_w(feeprom_rom6, 1 + 2*offset + 0x2000*hsgpl.cur_bank + 0x8000*port, data);
644646         at29c040a_w(feeprom_rom6, 2*offset + 0x2000*hsgpl.cur_bank + 0x8000*port, data >> 8);
src/mess/machine/ti99_4x.c
r8296r8297
8888static void ti99_4p_mapper_init(running_machine *machine);
8989static void ti99_myarcxram_init(running_machine *machine);
9090static void ti99_evpc_reset(running_machine *machine);
91static void ti99_evpc_load_novram(running_machine *machine, const char *filename);
92static void ti99_evpc_save_novram(running_machine *machine, const char *filename);
9193
9294/*
9395    pointer to extended RAM area
r8296r8297
242244/* Used to cache the switch settings. */
243245static UINT8 gk_switch[8];
244246
245/* true if 99/4p rom6 is enabled */
246static int ti99_4p_internal_rom6_enable;
247/* pointer to the ROM6 data */
248static UINT16 *ti99_4p_internal_ROM6;
247/* DIP switches of EVPC */
248static UINT8 evpc_switch[4];
249249
250250/* Pointer to the cartridge system for the 99/8 */
251251static running_device *multicart8;
r8296r8297
333333   create_grom_high2k(0x0000, 0x5fff);
334334}
335335
336DRIVER_INIT( ti99_8 )
337{
338   UINT8 *mem = memory_region(machine, "maincpu");
339   ti99_model = model_99_8;
340   has_evpc = FALSE;
341
342   /* set up memory pointers */
343   xRAM_ptr_8 = mem + offset_xram_8;
344   ROM0_ptr_8 = mem + offset_rom0_8;
345   ROM1_ptr_8 = ROM0_ptr_8 + 0x2000;
346   ROM2_ptr_8 = ROM1_ptr_8 + 0x2000;
347   ROM3_ptr_8 = ROM2_ptr_8 + 0x2000;
348   sRAM_ptr_8 = mem + offset_sram_8;
349
350   /* Pull this one up here. */
351   ti99_8_enable_rom_and_ports = 1;
352
353   console_GROMs.data_ptr = memory_region(machine, region_grom);
354   create_grom_high2k(0x0000, 0x5fff);
355
356   multicart8 = devtag_get_device(machine, "ti99_multicart");
357   assert (multicart8 != NULL);
358}
359
360DRIVER_INIT( ti99_4p )
361{
362   ti99_model = model_99_4p;
363   has_evpc = TRUE;
364
365   /* set up memory pointers */
366   xRAM_ptr = (UINT16 *) (memory_region(machine, "maincpu") + offset_xram_4p);
367#if 0
368   console_GROMs.data_ptr = memory_region(machine, region_grom);
369   create_grom_high2k(0x0000, 0x5fff);
370#endif
371}
372
373336static const TMS9928a_interface tms9918_interface =
374337{
375338   TMS99x8,
r8296r8297
406369
407370MACHINE_START( ti99_4a_60hz )
408371{
409    ti99_common_init(machine, &tms9918a_interface);
372   ti99_common_init(machine, &tms9918a_interface);
410373}
411374
412375static const TMS9928a_interface tms9929a_interface =
r8296r8297
424387
425388MACHINE_START( ti99_4ev_60hz)
426389{
427    /* has an own VDP, so skip initing the VDP */
428    ti99_common_init(machine, 0);
390   /* has an own VDP, so skip initing the VDP */
391   ti99_common_init(machine, 0);
429392}
430393
431MACHINE_START( ti99_4p )
432{
433   UINT8* mem = memory_region(machine, "maincpu");
434
435   /* Set up system ROM and scratch pad pointers. Must be set up here */
436   /* so that the system can successfully reset (otherwise the reset  */
437   /* vector would be missing in 0x0000). */
438   memory_set_bankptr(machine, "bank1", mem + offset_rom0_4p);   /* system ROM */
439   memory_set_bankptr(machine, "bank2", mem + offset_sram_4p);   /* scratch pad */
440   memory_set_bankptr(machine, "bank11", mem + offset_dram_4p);   /* extra RAM for debugger */
441
442   ti99_peb_init();
443   ti99_floppy_controllers_init_all(machine);
444   ti99_ide_init(machine);
445   ti99_hsgpl_init(machine);
446   ti99_usbsm_init(machine);
447}
448
449394void ti99_common_init(running_machine *machine, const TMS9928a_interface *gfxparm)
450395{
451396   if (gfxparm != 0)
r8296r8297
478423   console_GROMs.raddr_LSB = FALSE;
479424   console_GROMs.waddr_LSB = FALSE;
480425
481   if (ti99_model == model_99_8)
482   {
483      /* ... */
484      ti99_8_enable_rom_and_ports = 1;      /* ??? maybe there is a pull-up */
485      /* MZ: already setting this in driver init, otherwise machine locks up */
486   }
487   else if (ti99_model == model_99_4p)
488   {
489      UINT8* mem = memory_region(machine, "maincpu");
426   /* set up scratch pad pointer */
427   memory_set_bankptr(machine, "bank1", memory_region(machine, "maincpu") + offset_sram);
490428
491      /* set up system ROM and scratch pad pointers */
492      memory_set_bankptr(machine, "bank1", mem + offset_rom0_4p);   /* system ROM */
493      memory_set_bankptr(machine, "bank2", mem + offset_sram_4p);   /* scratch pad */
494      memory_set_bankptr(machine, "bank11", mem + offset_dram_4p);   /* extra RAM for debugger */
495   }
496   else
497   {
498      /* set up scratch pad pointer */
499      memory_set_bankptr(machine, "bank1", memory_region(machine, "maincpu") + offset_sram);
500   }
501
502429   if (!has_evpc) TMS9928A_reset();
503430   else v9938_reset(0);
504431
r8296r8297
514441   tms9901_set_single_int(devtag_get_device(machine, "tms9901"), 12, 0);
515442
516443   /* read config */
517   if (ti99_model == model_99_8)
518      xRAM_kind = RAM_99_8;
519   else if (ti99_model == model_99_4p)
520      xRAM_kind = RAM_99_4P;
521   else
522      xRAM_kind = input_port_read(machine, "RAM");
444   xRAM_kind = input_port_read(machine, "RAM");
523445
524   if (ti99_model == model_99_8)
525      has_speech = TRUE;
526   else
527      has_speech = input_port_read(machine, "SPEECH");
528
446   has_speech = input_port_read(machine, "SPEECH");
529447   has_ide = input_port_read(machine, "HDCTRL") & HD_IDE;
530448   has_rs232 = input_port_read(machine, "SERIAL") & SERIAL_TI;
449   has_handset = (ti99_model == model_99_4)? (input_port_read(machine, "HCI") & HCI_IR) : FALSE;
450   has_mecmouse = input_port_read(machine, "HCI") & HCI_MECMOUSE;
451   has_hsgpl = input_port_read(machine, "EXTCARD") & (EXT_HSGPL_ON | EXT_HSGPL_FLASH);
452   has_usb_sm = input_port_read(machine, "HDCTRL") & HD_USB;
453   has_pcode = input_port_read(machine, "EXTCARD") & EXT_PCODE;
531454
532   if (ti99_model == model_99_4)
533      has_handset = input_port_read(machine, "HCI") & HCI_IR;
534   else
535      has_handset = FALSE;
536
537   if (ti99_model == model_99_4p)
538      has_hsgpl = TRUE;
539   else
540      has_hsgpl = input_port_read(machine, "EXTCARD") & (EXT_HSGPL_ON | EXT_HSGPL_FLASH);
541
542455   hsgpl_flash_mode = input_port_read(machine, "EXTCARD") & EXT_HSGPL_FLASH;
543456
544   has_usb_sm = input_port_read(machine, "HDCTRL") & HD_USB;
545   has_pcode = input_port_read(machine, "EXTCARD") & EXT_PCODE;
546
547457   /* Get the GK settings once */
548   if (ti99_model != model_99_4p)
549   {
550      gk_switch[1] = input_port_read(machine, "GKSWITCH1");
551      gk_switch[2] = input_port_read(machine, "GKSWITCH2");
552      gk_switch[3] = input_port_read(machine, "GKSWITCH3");
553      gk_switch[4] = input_port_read(machine, "GKSWITCH4");
554      gk_switch[5] = input_port_read(machine, "GKSWITCH5");
555   }
458   gk_switch[1] = input_port_read(machine, "GKSWITCH1");
459   gk_switch[2] = input_port_read(machine, "GKSWITCH2");
460   gk_switch[3] = input_port_read(machine, "GKSWITCH3");
461   gk_switch[4] = input_port_read(machine, "GKSWITCH4");
462   gk_switch[5] = input_port_read(machine, "GKSWITCH5");
556463
557464   // Removes all card handlers
558465   ti99_peb_init();
559466
560467   // set up optional expansion hardware
561   ti99_peb_reset(ti99_model == model_99_4p, tms9901_set_int1, NULL);
468   ti99_peb_reset(FALSE, tms9901_set_int1, NULL);
562469
563   if (ti99_model == model_99_8)
564      ti99_8_internal_dsr_reset(machine);
565
566   if (ti99_model == model_99_4p)
567      ti99_4p_internal_dsr_reset(machine);
568
569470   if (has_speech)
570471   {
571472      static const spchroms_interface speech_intf = { region_speech_rom };
572473
573474      spchroms_config(machine, &speech_intf);
574475
575      if (ti99_model != model_99_8)
576      {
577         memory_install_read16_handler(space, 0x9000, 0x93ff, 0, 0, ti99_rspeech_r);
578         memory_install_write16_handler(space, 0x9400, 0x97ff, 0, 0, ti99_wspeech_w);
579      }
476      memory_install_read16_handler(space, 0x9000, 0x93ff, 0, 0, ti99_rspeech_r);
477      memory_install_write16_handler(space, 0x9400, 0x97ff, 0, 0, ti99_wspeech_w);
580478   }
581479   else
582480   {
583      /* which is never true for TI-99/8 */
584481      memory_install_read16_handler(space, 0x9000, 0x93ff, 0, 0, ti99_nop_8_r);
585482      memory_install_write16_handler(space, 0x9400, 0x97ff, 0, 0, ti99_nop_8_w);
586483   }
587484
588485   switch (xRAM_kind)
589486   {
590   case RAM_NONE:
591   default:
592      memory_install_read16_handler(space, 0x2000, 0x3fff, 0, 0, ti99_nop_8_r);
593      memory_install_write16_handler(space, 0x2000, 0x3fff, 0, 0, ti99_nop_8_w);
594      memory_install_read16_handler(space, 0xa000, 0xffff, 0, 0, ti99_nop_8_r);
595      memory_install_write16_handler(space, 0xa000, 0xffff, 0, 0, ti99_nop_8_w);
596      break;
597487   case RAM_TI32:
598488      ti99_TIxram_init(machine);
599489      break;
600490   case RAM_SUPERAMS1024:
601491      ti99_sAMSxram_init(machine);
602492      break;
603   case RAM_99_4P:
604      ti99_4p_mapper_init(machine);
605      break;
606493   case RAM_FOUNDATION128:
607494   case RAM_FOUNDATION512:
608495   case RAM_MYARC128:
609496   case RAM_MYARC512:
610497      ti99_myarcxram_init(machine);
611498      break;
612   case RAM_99_8:
499   case RAM_NONE:
500   default:
501      memory_install_read16_handler(space, 0x2000, 0x3fff, 0, 0, ti99_nop_8_r);
502      memory_install_write16_handler(space, 0x2000, 0x3fff, 0, 0, ti99_nop_8_w);
503      memory_install_read16_handler(space, 0xa000, 0xffff, 0, 0, ti99_nop_8_r);
504      memory_install_write16_handler(space, 0xa000, 0xffff, 0, 0, ti99_nop_8_w);
613505      break;
614506   }
615507
r8296r8297
634526   }
635527
636528   if (has_ide)
637      ti99_ide_reset(machine, ti99_model == model_99_8);
529      ti99_ide_reset(machine, FALSE);
638530
639531   if (has_hsgpl)
640532      ti99_hsgpl_reset(machine);
r8296r8297
642534      hsgpl_crdena = 0;
643535
644536   if (has_usb_sm)
645      ti99_usbsm_reset(machine, ti99_model == model_99_8);
537      ti99_usbsm_reset(machine, FALSE);
646538
647539   if (has_evpc)
540   {
541      /* Get the EVPC settings once */
542      evpc_switch[0] = input_port_read(machine, "EVPC-SW1");
543      evpc_switch[1] = input_port_read(machine, "EVPC-SW3");
544      evpc_switch[2] = input_port_read(machine, "EVPC-SW4");
545      evpc_switch[3] = input_port_read(machine, "EVPC-SW8");
648546      ti99_evpc_reset(machine);
547   }
649548
650549   if (has_pcode)
651550      ti99_pcode_reset(machine);
r8296r8297
672571
673572NVRAM_HANDLER( ti99 )
674573{
675   const char *filename;
574   // called from generic.c
575   // (running_machine *machine, mame_file *file, int read_or_write)
676576
677   /* We may have different HSGPL settings for 80 column and traditional */
678   /* 40 column display. For convenience, we use two different nvram files. */
679   if (has_evpc)
680      filename = "hsgpl80.nv";
681   else
682      filename = "hsgpl40.nv";
577   astring *hsname = astring_assemble_3(astring_alloc(), machine->gamedrv->name, PATH_SEPARATOR, "hsgpl.nv");
578   astring *evname = astring_assemble_3(astring_alloc(), machine->gamedrv->name, PATH_SEPARATOR, "evpc.nv");
683579
684580   // We always try to read the HSGPL, even when the config switch is
685581   // set to off. Otherwise, when the system is started without HSGPL
r8296r8297
688584   // even when the card has been turned off during runtime.
689585   if (read_or_write==0)
690586   {
691      ti99_hsgpl_load_flashroms(machine, filename);
587      ti99_hsgpl_load_flashroms(machine, astring_c(hsname));
588      if (has_evpc) ti99_evpc_load_novram(machine, astring_c(evname));
692589   }
693590   else
694591   {
695      ti99_hsgpl_save_flashroms(machine, filename);
592      ti99_hsgpl_save_flashroms(machine, astring_c(hsname));
593      if (has_evpc) ti99_evpc_save_novram(machine, astring_c(evname));
696594   }
595
596   astring_free(hsname);
597   astring_free(evname);
697598}
698599
699600INPUT_CHANGED( hsgpl_changed )
r8296r8297
712613}
713614
714615/*
715    video initialization.
716*/
717VIDEO_START( ti99_4ev )
718{
719   VIDEO_START_CALL(generic_bitmapped);
720   v9938_init(machine, 0, machine->primary_screen, machine->generic.tmpbitmap,
721      MODEL_V9938, 0x20000, tms9901_set_int2);   /* v38 with 128 kb of video RAM */
722}
723
724/*
725616    VBL interrupt  (mmm...  actually, it happens when the beam enters the lower
726617    border, so it is not a genuine VBI, but who cares ?)
727618*/
r8296r8297
730621   TMS9928A_interrupt(device->machine);
731622   if (has_handset)
732623      ti99_handset_task(device->machine);
733   has_mecmouse = input_port_read(device->machine, "HCI") & HCI_MECMOUSE;
734624   if (has_mecmouse)
735625      mecmouse_poll(device->machine);
736626}
737627
738INTERRUPT_GEN( ti99_4ev_hblank_interrupt )
739{
740   static int line_count;
741   v9938_interrupt(device->machine, 0);
742   if (++line_count == 262)
743   {
744      line_count = 0;
745      has_mecmouse = input_port_read(device->machine, "HCI") & HCI_MECMOUSE;
746      if (has_mecmouse)
747         mecmouse_poll(device->machine);
748   }
749}
750
751628/*
752629    Backdoor function that is called by hsgpl, so that the machine code knows
753630    whether hsgpl or console GROMs are active
r8296r8297
808685*/
809686WRITE16_HANDLER ( ti99_cart_w )
810687{
811   ti99_multicart_w(cartslots, offset, data, mem_mask);
812   if (hsgpl_crdena && !hsgpl_flash_mode)
813      /* hsgpl is enabled */
814      ti99_hsgpl_rom6_w(space, offset, data, mem_mask);
815}
688   // Writing always means that we access the cartridges (and possibly the HGSPL)
689   // Except when we use the SGCPU.
690   if (ti99_model != model_99_4p)
691      ti99_multicart_w(cartslots, offset, data, mem_mask);
816692
817/*
818    99/4p cartridge space: mapped either to internal ROM6 or to HSGPL.
819*/
820READ16_HANDLER ( ti99_4p_cart_r )
821{
822   if (ti99_4p_internal_rom6_enable)
823      return ti99_4p_internal_ROM6[offset];
824
825   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);
826//  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
827
828693   if (hsgpl_crdena && !hsgpl_flash_mode)
829694      /* hsgpl is enabled */
830      return ti99_hsgpl_rom6_r(space, offset, mem_mask);
831
832   return 0;
833}
834
835WRITE16_HANDLER ( ti99_4p_cart_w )
836{
837   if (ti99_4p_internal_rom6_enable)
838   {
839      ti99_4p_internal_ROM6 = (UINT16 *) (memory_region(space->machine, "maincpu") + (FPTR)((offset & 1) ? offset_rom6b_4p : offset_rom6_4p));
840      return;
841   }
842
843   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);
844//  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
845
846   if (hsgpl_crdena && !hsgpl_flash_mode)
847      /* hsgpl is enabled */
848695      ti99_hsgpl_rom6_w(space, offset, data, mem_mask);
849696}
850697
r8296r8297
926773}
927774
928775/*
929    V38 VDP read
930*/
931READ16_HANDLER ( ti99_rv38_r )
932{
933   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);
934//  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
935
936   if (offset & 1)
937   {   /* read VDP status */
938      return ((int) v9938_0_status_r(space, 0)) << 8;
939   }
940   else
941   {   /* read VDP RAM */
942      return ((int) v9938_0_vram_r(space, 0)) << 8;
943   }
944}
945
946/*
947    V38 vdp write
948*/
949WRITE16_HANDLER ( ti99_wv38_w )
950{
951   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);
952//  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
953
954   switch (offset & 3)
955   {
956   case 0:
957      /* write VDP data */
958      v9938_0_vram_w(space, 0, (data >> 8) & 0xff);
959      break;
960   case 1:
961      /* write VDP address */
962      v9938_0_command_w(space, 0, (data >> 8) & 0xff);
963      break;
964   case 2:
965      /* write VDP palette */
966      v9938_0_palette_w(space, 0, (data >> 8) & 0xff);
967      break;
968   case 3:
969      /* write VDP register */
970      v9938_0_register_w(space, 0, (data >> 8) & 0xff);
971      break;
972   }
973}
974
975/*
976776    TMS0285 speech chip read
977777*/
978778static READ16_HANDLER ( ti99_rspeech_r )
r8296r8297
1151951         console_GROMs.raddr_LSB = TRUE;
1152952      }
1153953      /* GROM address values must be globally unique. */
1154      // FIXME: HSGPL asserts here when switched on during runtime
1155      //     You should not do that, but again the emulation should
1156      //     not assert either
1157954      assert (replycart == reply);
1158955   }
1159956   else
r8296r8297
12331030   }
12341031}
12351032
1236/*
1237    GROM read for TI-99/8
1238    For comments, see the handler for TI-99/4A
1239*/
1240static READ8_HANDLER ( ti99_grom_r8 )
1241{
1242   UINT8 reply, replycart;
1243
1244   cpu_adjust_icount(space->machine->firstcpu,-4);
1245
1246   if (offset & 2)
1247   {
1248      replycart = ti99_cartridge_grom_r(cartslots, offset);
1249      console_GROMs.waddr_LSB = FALSE;
1250
1251      if (console_GROMs.raddr_LSB)
1252      {
1253         reply = console_GROMs.addr & 0x00ff;
1254         console_GROMs.raddr_LSB = FALSE;
1255      }
1256      else
1257      {
1258         reply = (console_GROMs.addr>>8) & 0x00ff;
1259         console_GROMs.raddr_LSB = TRUE;
1260      }
1261      /* GROM address values must be globally unique. */
1262      assert (replycart == reply);
1263   }
1264   else
1265   {
1266      reply = GROM_dataread(space->machine, offset);
1267   }
1268   return reply;
1269}
1270
1271/*
1272    GROM write for TI-99/8
1273    For comments, see the handler for TI-99/4A
1274*/
1275static WRITE8_HANDLER ( ti99_grom_w8 )
1276{
1277   cpu_adjust_icount(space->machine->firstcpu,-4/*20+3*/);      /* from 4 to 23? */
1278
1279   if (offset & 2)
1280   {
1281      ti99_cartridge_grom_w(cartslots, offset, data);
1282      console_GROMs.raddr_LSB = FALSE;
1283      if (console_GROMs.waddr_LSB)
1284      {
1285         console_GROMs.addr = (console_GROMs.addr & 0xFF00) | (data & 0xFF);
1286
1287         GROM_dataread(space->machine, offset&0xfffc);
1288         console_GROMs.waddr_LSB = FALSE;
1289      }
1290      else
1291      {
1292         console_GROMs.addr = ((data<<8) & 0xFF00) | (console_GROMs.addr & 0xFF);
1293         console_GROMs.waddr_LSB = TRUE;
1294      }
1295
1296   }
1297   else
1298   {
1299      GRAM_datawrite(offset, (data>>8)&0xff);
1300      console_GROMs.raddr_LSB = console_GROMs.waddr_LSB = FALSE;
1301   }
1302}
1303
1304
1305/*
1306    GROM read for TI-99/4p
1307*/
1308READ16_HANDLER ( ti99_4p_grom_r )
1309{
1310   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);      /* HSGPL is located on 8-bit bus? */
1311   //  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
1312
1313   return hsgpl_crdena? ti99_hsgpl_gpl_r(space, offset, mem_mask) : 0;
1314}
1315
1316/*
1317    GROM write
1318*/
1319WRITE16_HANDLER ( ti99_4p_grom_w )
1320{
1321   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);      /* HSGPL is located on 8-bit bus? */
1322   //  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
1323
1324   if (hsgpl_crdena)
1325      ti99_hsgpl_gpl_w(space, offset, data, mem_mask);
1326}
1327
1328
1329#if 0
1330#pragma mark -
1331#pragma mark 99/8 MEMORY HANDLERS
1332#endif
1333
1334READ8_HANDLER( ti99_8_r )
1335{
1336   /* Set the page. Page size is 4 KiB; page number are the high 4 bits. */
1337   int page = offset >> 12;
1338   UINT32 mapper_reg;
1339   UINT8 reply = 0;
1340
1341   if (ti99_8_enable_rom_and_ports)
1342   {
1343      /* This is only important for address access 0000-1fff and
1344        8000-9fff. Outside, the mapper mode is used. */
1345      if ((offset >= 0x0000) && (offset < 0x2000))
1346      {
1347         /* ROM */
1348         reply = ROM0_ptr_8[offset & 0x1fff];
1349         return reply;
1350      }
1351      else if ((offset >= 0x8000) && (offset < 0xa000))
1352      {
1353         /* ti99 scratch pad and memory-mapped registers */
1354         /* 0x8000-0x9fff */
1355         switch ((offset - 0x8000) >> 10)
1356         {
1357         case 0:
1358            /* RAM: >8000 - >83ff */
1359            reply = sRAM_ptr_8[offset & 0x1fff];
1360            break;
1361
1362         case 1:
1363            /* >8400 - >840f: sound (cannot read)
1364                >8410 - >87ff: SRAM */
1365            if (offset >= 0x8410)
1366               reply = sRAM_ptr_8[offset & 0x1fff];
1367            break;
1368
1369         case 2:
1370            /* VDP read + mapper status */
1371            if (offset < 0x8810)
1372            {
1373               if (! (offset & 1))
1374               {
1375                  if (offset & 2)
1376                     /* read VDP status >8802 */
1377                  reply = TMS9928A_register_r(space, 0);
1378                  else
1379                     /* read VDP RAM >8800 */
1380                  reply = TMS9928A_vram_r(space, 0);
1381               }
1382            }
1383            else
1384            {
1385               /* Read mapper >8810 */
1386               reply = ti99_8_mapper_status;
1387               ti99_8_mapper_status = 0;
1388            }
1389            break;
1390
1391         case 4:
1392            /* speech read: >9000 */
1393            if (! (offset & 1))
1394            {
1395               cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-16*4);      /* this is just a minimum, it can be more */
1396               reply = tms5220_status_r(devtag_get_device(space->machine, "tms5220"), 0);
1397            }
1398            break;
1399
1400         case 6:
1401            /* GROM read: >9800 */
1402            if (! (offset & 1))
1403               reply = ti99_grom_r8(space, offset);
1404            break;
1405
1406         default:
1407            logerror("unmapped read offs=%d\n", (int) offset);
1408            break;
1409         }
1410         return reply;
1411      }
1412   }
1413
1414   mapper_reg = ti99_8_mapper_regs[page];
1415   offset = (mapper_reg + (offset & 0x0fff)) & 0x00ffffff;
1416
1417   #if 0
1418   /* test read protect */
1419   if (mapper_reg & 0x20000000)
1420      ;
1421
1422   /* test execute protect */
1423   if (mapper_reg & 0x40000000)
1424      ;
1425   #endif
1426
1427   if (offset < 0x010000)
1428   /* Read RAM */
1429   reply = xRAM_ptr_8[offset];
1430
1431   if (offset >= 0xff0000)
1432   {
1433      switch ((offset >> 13) & 7)
1434      {
1435      default:
1436         /* should never happen */
1437      case 0:
1438         /* ff0000 - ff1fff: unassigned? */
1439      case 1:
1440         /* ff2000 - ff3fff: ? */
1441      case 4:
1442         /* ff8000 - ff9fff: internal DSR ROM? (normally enabled with a write to CRU >2700) */
1443      case 7:
1444         /* ffe000 - ffffff: ? */
1445         logerror("unmapped read page=%d offs=%d\n", (int) page, (int) offset);
1446         break;
1447
1448      case 2:
1449         /* ff4000 - ff5fff: DSR space */
1450         reply = ti99_8_peb_r(space, offset & 0x1fff);
1451         break;
1452
1453      case 3:
1454         /* ff6000 - ff7fff: cartridge ROM space */
1455         offset &= 0x1fff;
1456
1457         /* We do not support hsgpl here because it is a 16 bit
1458            system. Just check the cartridges.  */
1459         reply = ti99_multicart8_r(multicart8, offset);
1460         break;
1461
1462      case 5:
1463         /* ffa000 - ffbfff: >2000 ROM (ROM1) */
1464         reply = ROM1_ptr_8[offset & 0x1fff];
1465         break;
1466
1467      case 6:
1468         /* ffc000 - ffdfff: >6000 ROM */
1469         reply = ROM3_ptr_8[offset & 0x1fff];
1470         break;
1471      }
1472   }
1473
1474   return reply;
1475}
1476
1477WRITE8_HANDLER ( ti99_8_w )
1478{
1479   int page = offset >> 12;
1480   UINT32 mapper_reg;
1481
1482   if (ti99_8_enable_rom_and_ports)
1483   {
1484      /* memory mapped ports enabled */
1485      if ((offset >= 0x0000) && (offset < 0x2000))
1486      {
1487         /* ROM? */
1488         return;
1489      }
1490      else if ((offset >= 0x8000) && (offset < 0xa000))
1491      {
1492         /* ti99 scratch pad and memory-mapped registers */
1493         /* 0x8000-0x9fff */
1494         switch ((offset - 0x8000) >> 10)
1495         {
1496         case 0:
1497            /* RAM */
1498            sRAM_ptr_8[offset & 0x1fff] = data;
1499            break;
1500
1501         case 1:
1502            /* sound write + RAM */
1503            if (offset < 0x8410)
1504               sn76496_w(devtag_get_device(space->machine, "sn76496"), offset, data);
1505            else
1506               sRAM_ptr_8[offset & 0x1fff] = data;
1507            break;
1508
1509         case 2:
1510            /* VDP read + mapper control */
1511            if (offset >= 0x8810)
1512            {
1513               int file = (data >> 1) & 3;
1514               int i;
1515
1516               if (data & 1)
1517               {   /* load */
1518                  for (i=0; i<16; i++)
1519                  {
1520                     ti99_8_mapper_regs[i] = (sRAM_ptr_8[(file << 6) + (i << 2)] << 24)
1521                                       | (sRAM_ptr_8[(file << 6) + (i << 2) + 1] << 16)
1522                                       | (sRAM_ptr_8[(file << 6) + (i << 2) + 2] << 8)
1523                                       | sRAM_ptr_8[(file << 6) + (i << 2) + 3];
1524                  }
1525               }
1526               else
1527               {   /* save */
1528                  for (i=0; i<16; i++)
1529                  {
1530                     sRAM_ptr_8[(file << 6) + (i << 2)] = ti99_8_mapper_regs[i] >> 24;
1531                     sRAM_ptr_8[(file << 6) + (i << 2) + 1] = ti99_8_mapper_regs[i] >> 16;
1532                     sRAM_ptr_8[(file << 6) + (i << 2) + 2] = ti99_8_mapper_regs[i] >> 8;
1533                     sRAM_ptr_8[(file << 6) + (i << 2) + 3] = ti99_8_mapper_regs[i];
1534                  }
1535               }
1536            }
1537            break;
1538
1539         case 3:
1540            /* VDP write */
1541            if (! (offset & 1))
1542            {
1543               if (offset & 2)
1544                  /* read VDP status */
1545                  TMS9928A_register_w(space, 0, data);
1546               else
1547                  /* read VDP RAM */
1548                  TMS9928A_vram_w(space, 0, data);
1549            }
1550            break;
1551
1552         case 5:
1553            /* speech write */
1554            if (! (offset & 1))
1555            {
1556               cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-48*4);      /* this is just an approx. minimum, it can be much more */
1557
1558               /* the stupid design of the tms5220 core means that ready is cleared when
1559                    there are 15 bytes in FIFO.  It should be 16.  Of course, if it were the
1560                    case, we would need to store the value on the bus, which would be more
1561                    complex. */
1562               if (! tms5220_readyq_r(devtag_get_device(space->machine, "tms5220")))
1563               {
1564                  attotime time_to_ready = double_to_attotime(tms5220_time_to_ready(devtag_get_device(space->machine, "tms5220")));
1565                  double d = cputag_attotime_to_clocks(space->machine, "maincpu", time_to_ready);
1566                  int cycles_to_ready = ((int) (d + 3)) & ~3;
1567
1568                  logerror("time to ready: %f -> %d\n", attotime_to_double(time_to_ready)
1569                     , (int) cycles_to_ready);
1570
1571                  cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-cycles_to_ready);
1572                  timer_set(space->machine, attotime_zero, NULL, 0, /*speech_kludge_callback*/NULL);
1573               }
1574
1575               tms5220_data_w(devtag_get_device(space->machine, "tms5220"), offset, data);
1576            }
1577            break;
1578
1579         case 7:
1580            /* GPL write */
1581            if (! (offset & 1))
1582               ti99_grom_w8(space, offset, data);
1583            break;
1584
1585         default:
1586            logerror("unmapped write offs=%d data=%d\n", (int) offset, (int) data);
1587            break;
1588         }
1589         return;
1590      }
1591   }
1592
1593   mapper_reg = ti99_8_mapper_regs[page];
1594
1595   /* 4 KiB page size */
1596   offset = (mapper_reg + (offset & 0x0fff)) & 0x00ffffff;
1597
1598#if 0
1599   /* test write protect */
1600   if (mapper_reg & 0x80000000)
1601      ;
1602#endif
1603
1604   if (offset < 0x010000)
1605   {   /* Write RAM */
1606      xRAM_ptr_8[offset] = data;
1607   }
1608   else if (offset >= 0xff0000)
1609   {
1610      switch ((offset >> 13) & 7)
1611      {
1612      default:
1613         /* should never happen */
1614      case 0:
1615         /* unassigned??? */
1616      case 1:
1617         /* ??? */
1618      case 4:
1619         /* internal DSR ROM??? (normally enabled with a write to CRU >2700) */
1620      case 7:
1621         /* ??? */
1622         break;
1623
1624      case 2:
1625         /* DSR space */
1626         ti99_8_peb_w(space, offset & 0x1fff, data);
1627         break;
1628
1629      case 3:
1630         /* cartridge space */
1631         /* We do not support HSGPL for the 99/8 at this time. */
1632         ti99_multicart8_w(multicart8, offset & 0x1fff, data);
1633         break;
1634
1635      case 5:
1636         /* >2000 ROM (ROM1) */
1637         break;
1638
1639      case 6:
1640         /* >6000 ROM */
1641         break;
1642      }
1643   }
1644   else
1645   {
1646      logerror("unmapped write page=%d offs=%d\n", (int) page, (int) offset);
1647   }
1648}
1649
16501033/*===========================================================================*/
16511034#if 0
16521035#pragma mark -
r8296r8297
16981081
16991082   if (handset_buflen == 1)
17001083   {
1701      /* Unless I am missing something, the third and last nybble of the
1702        message is not acknowledged by the DSR in any way, and the first nybble
1703        of next message is not requested for either, so we need to decide on
1704        our own when we can post a new event.  Currently, we wait for 1000us
1705        after the DSR acknowledges the second nybble. */
1084      // Unless I am missing something, the third and last nybble of the
1085      // message is not acknowledged by the DSR in any way, and the first nybble
1086      // of next message is not requested for either, so we need to decide on
1087      // our own when we can post a new event.  Currently, we wait for 1000us
1088      // after the DSR acknowledges the second nybble.
17061089      timer_set(machine, ATTOTIME_IN_USEC(1000), NULL, 0, ti99_handset_ack_callback);
17071090   }
17081091
r8296r8297
17131096
17141097/*
17151098    ti99_handset_set_ack()
1716
17171099    Handler for tms9901 P0 pin (handset data acknowledge)
17181100*/
17191101static WRITE8_DEVICE_HANDLER( ti99_handset_set_ack )
r8296r8297
17471129
17481130/*
17491131    ti99_handset_poll_keyboard()
1750
17511132    Poll the current state of one given handset keypad.
1752
17531133    num: number of the keypad to poll (0-3)
1754
17551134    Returns TRUE if the handset state has changed and a message was posted.
17561135*/
17571136static int ti99_handset_poll_keyboard(running_machine *machine, int num)
r8296r8297
17661145   /* read current key state */
17671146   key_buf = ( input_port_read(machine, keynames[num]) | (input_port_read(machine, keynames[num + 1]) << 16) ) >> (4*num);
17681147
1769   /* If a key was previously pressed, this key was not shift, and this key is
1770    still down, then don't change the current key press. */
1148   // If a key was previously pressed, this key was not shift, and this key is
1149   // still down, then don't change the current key press.
17711150   if (previous_key[num] && (previous_key[num] != 0x24)
17721151      && (key_buf & (1 << (previous_key[num] & 0x1f))))
17731152   {
r8296r8297
17771156      return FALSE;
17781157      else
17791158      {
1780         /* the shift modifier state has changed: we need to update the
1781            keyboard state */
1159         // The shift modifier state has changed: we need to update the
1160         // keyboard state
17821161         if (key_buf & 0x0008)
17831162         {   /* shift has been pressed down */
17841163            previous_key[num] = current_key = previous_key[num] | 0x20;
r8296r8297
18051184            current_key |= 0x20;   /* set shift flag */
18061185
18071186         if (current_key != 0x24)
1808            /* If this is the shift key, any other key we may find will
1809                have higher priority; otherwise, we may exit the loop and keep
1810                the key we have just found. */
1187            // If this is the shift key, any other key we may find will
1188            // have higher priority; otherwise, we may exit the loop and keep
1189            // the key we have just found.
18111190            break;
18121191      }
18131192   }
r8296r8297
18291208    ti99_handset_poll_joystick()
18301209
18311210    Poll the current state of one given handset joystick.
1832
18331211    num: number of the joystick to poll (0-3)
1834
18351212    Returns TRUE if the handset state has changed and a message was posted.
18361213*/
18371214static int ti99_handset_poll_joystick(running_machine *machine, int num)
r8296r8297
18631240      message = 0;
18641241
18651242      /* set sign */
1866      /* note that we set the sign if the joystick position is 0 to work
1867        around a bug in the ti99/4 ROMs */
1243      // note that we set the sign if the joystick position is 0 to work
1244      // around a bug in the ti99/4 ROMs
18681245      if (current_joy_x <= 0)
18691246      {
18701247         message |= 0x040;
r8296r8297
19041281
19051282/*
19061283    ti99_handset_task()
1907
19081284    Manage handsets, posting an event if the state of any handset has changed.
19091285*/
19101286static void ti99_handset_task(running_machine *machine)
r8296r8297
21431519{
21441520   if (intreq)
21451521   {
2146      /* On TI99, TMS9900 IC0-3 lines are not connected to TMS9901,
2147        * but hard-wired to force level 1 interrupts */
1522      // On TI99, TMS9900 IC0-3 lines are not connected to TMS9901,
1523      // but hard-wired to force level 1 interrupts
21481524      cputag_set_input_line_and_vector(device->machine, "maincpu", 0, ASSERT_LINE, 1);   /* interrupt it, baby */
21491525   }
21501526   else
r8296r8297
22761652   else
22771653      KeyCol &= ~ (1 << (offset-2));
22781654
2279        if (has_mecmouse)
2280                mecmouse_select(KeyCol, (ti99_model == model_99_4) ? 5 : 6,
2281               (ti99_model == model_99_4) ? 6 : 7);
1655   if (has_mecmouse)
1656      mecmouse_select(KeyCol, (ti99_model == model_99_4) ? 5 : 6, (ti99_model == model_99_4) ? 6 : 7);
22821657}
22831658
22841659/*
r8296r8297
22911666}
22921667
22931668/*
2294    Read pins INT3*-INT7* of TI99's 9901.
2295
2296    signification:
2297     (bit 1: INT1 status)
2298     (bit 2: INT2 status)
2299     bits 3-4: unused?
2300     bit 5: ???
2301     bit 6-7: keyboard status bits 0 through 1
2302*/
2303static READ8_DEVICE_HANDLER( ti99_8_R9901_0 )
2304{
2305   int answer;
2306   static const char *const keynames[] = {
2307      "KEY0", "KEY1", "KEY2", "KEY3", "KEY4", "KEY5", "KEY6", "KEY7",
2308      "KEY8", "KEY9", "KEY10", "KEY11", "KEY12", "KEY13", "KEY14", "KEY15"
2309   };
2310
2311   if (has_mecmouse && (KeyCol == 15))
2312   {
2313      int buttons = input_port_read(device->machine, "MOUSE0") & 3;
2314
2315      answer = ((mecmouse_read_y ? mecmouse_y_buf : mecmouse_x_buf) << 7) & 0x80;
2316
2317      if (! (buttons & 1))
2318         /* action button */
2319         answer |= 0x40;
2320   }
2321   else
2322   {
2323      answer = (input_port_read(device->machine, keynames[KeyCol]) << 6) & 0xC0;
2324   }
2325
2326   return answer;
2327}
2328
2329/*
23301669    Read pins INT8*-INT15* of TI99's 9901.
23311670
23321671    signification:
r8296r8297
23681707}
23691708
23701709/*
2371    WRITE key column select (P0-P3)
2372*/
2373static WRITE8_DEVICE_HANDLER( ti99_8_KeyC )
2374{
2375   if (data)
2376      KeyCol |= 1 << offset;
2377   else
2378      KeyCol &= ~ (1 << offset);
2379
2380   if (has_mecmouse)
2381      mecmouse_select(KeyCol, 14, 15);
2382}
2383
2384static WRITE8_DEVICE_HANDLER( ti99_8_WCRUS )
2385{
2386   ti99_8_enable_rom_and_ports = data;
2387}
2388
2389static WRITE8_DEVICE_HANDLER( ti99_8_PTGEN )
2390{
2391   /* ... */
2392}
2393
2394/*
23951710    command CS1/CS2 tape unit motor (P6-P7)
23961711*/
23971712static WRITE8_DEVICE_HANDLER( ti99_CS_motor )
r8296r8297
24391754   }
24401755}
24411756
2442
2443
2444/*===========================================================================*/
2445#if 0
2446#pragma mark -
2447#pragma mark 99/8 INTERNAL DSR
2448#endif
2449/*
2450    TI 99/8 internal DSR support.
2451
2452    Includes a few specific signals, and an extra ROM.
2453*/
2454
2455/* prototypes */
2456static void ti99_8_internal_dsr_cru_w(running_machine *machine, int offset, int data);
2457static  READ8_HANDLER(ti99_8_internal_dsr_r);
2458
2459
2460static const ti99_peb_card_handlers_t ti99_8_internal_dsr_handlers =
1757/* tms9901 setup */
1758const tms9901_interface tms9901reset_param_ti99_4x =
24611759{
2462   NULL,
2463   ti99_8_internal_dsr_cru_w,
2464   ti99_8_internal_dsr_r,
2465   NULL
2466};
1760   TMS9901_INT1 | TMS9901_INT2 | TMS9901_INTC,   /* only input pins whose state is always known */
24671761
2468/* pointer to the internal DSR ROM data */
2469static UINT8 *ti99_8_internal_DSR;
1762   {   /* read handlers */
1763      ti99_R9901_0,
1764      ti99_R9901_1,
1765      ti99_R9901_2,
1766      ti99_R9901_3
1767   },
24701768
1769   {   /* write handlers */
1770      ti99_handset_set_ack,
1771      NULL,
1772      ti99_KeyC,
1773      ti99_KeyC,
1774      ti99_KeyC,
1775      ti99_AlphaW,
1776      ti99_CS_motor,
1777      ti99_CS_motor,
1778      ti99_audio_gate,
1779      ti99_CS_output,
1780      NULL,
1781      NULL,
1782      NULL,
1783      NULL,
1784      NULL,
1785      NULL
1786   },
24711787
2472/* set up handlers, and set initial state */
2473static void ti99_8_internal_dsr_reset(running_machine *machine)
2474{
2475   ti99_8_internal_DSR = memory_region(machine, "maincpu") + offset_rom0_8 + 0x4000;
1788   /* interrupt handler */
1789   tms9901_interrupt_callback,
24761790
2477   ti99_peb_set_card_handlers(0x2700, & ti99_8_internal_dsr_handlers);
2478}
2479
2480/* write CRU bit:
2481    bit0: enable/disable internal DSR ROM,
2482    bit1: hard reset */
2483static void ti99_8_internal_dsr_cru_w(running_machine *machine, int offset, int data)
2484{
2485   switch (offset)
2486   {
2487   case 1:
2488      /* hard reset -- not emulated */
2489      break;
2490   }
2491}
2492
2493/* read internal DSR ROM */
2494static  READ8_HANDLER(ti99_8_internal_dsr_r)
2495{
2496   return ti99_8_internal_DSR[offset];
2497}
2498
2499
2500
2501/*===========================================================================*/
2502#if 0
2503#pragma mark -
2504#pragma mark SGCPU INTERNAL DSR
2505#endif
2506/*
2507    SNUG SGCPU (a.k.a. 99/4p) internal DSR support.
2508
2509    Includes a few specific signals, and an extra ROM.
2510*/
2511
2512/* prototypes */
2513static void ti99_4p_internal_dsr_cru_w(running_machine *machine, int offset, int data);
2514static READ16_HANDLER(ti99_4p_internal_dsr_r);
2515
2516
2517static const ti99_peb_16bit_card_handlers_t ti99_4p_internal_dsr_handlers =
2518{
2519   NULL,
2520   ti99_4p_internal_dsr_cru_w,
2521   ti99_4p_internal_dsr_r,
2522   NULL
1791   /* clock rate = 3MHz */
1792   3000000.
25231793};
25241794
2525/* pointer to the internal DSR ROM data */
2526static UINT16 *ti99_4p_internal_DSR;
2527
2528
2529/* set up handlers, and set initial state */
2530static void ti99_4p_internal_dsr_reset(running_machine *machine)
2531{
2532   UINT8* mem = memory_region(machine, "maincpu");
2533
2534   ti99_4p_internal_DSR = (UINT16 *) (mem + offset_rom4_4p);
2535   ti99_4p_internal_ROM6 = (UINT16 *) (mem + offset_rom6_4p);
2536
2537   ti99_peb_set_16bit_card_handlers(0x0f00, & ti99_4p_internal_dsr_handlers);
2538
2539   ti99_4p_internal_rom6_enable = 0;
2540   ti99_4p_peb_set_senila(0);
2541   ti99_4p_peb_set_senilb(0);
2542}
2543
2544/* write CRU bit:
2545    bit0: enable/disable internal DSR ROM,
2546    bit1: enable/disable internal cartridge ROM
2547    bit2: set/clear senila
2548    bit3: set/clear senilb*/
2549static void ti99_4p_internal_dsr_cru_w(running_machine *machine, int offset, int data)
2550{
2551   switch (offset)
2552   {
2553   case 1:
2554      ti99_4p_internal_rom6_enable = data;
2555      break;
2556   case 2:
2557      ti99_4p_peb_set_senila(data);
2558      break;
2559   case 3:
2560      ti99_4p_peb_set_senilb(data);
2561      break;
2562   case 4:
2563      /* 0: 16-bit (fast) memory timings */
2564      /* 1: 8-bit memory timings */
2565      break;
2566   case 5:
2567      /* if 0: "KBENA" mode (enable keyboard?) */
2568      /* if 1: "KBINH" mode (inhibit keyboard?) */
2569      break;
2570   }
2571}
2572
2573/* read internal DSR ROM */
2574static READ16_HANDLER(ti99_4p_internal_dsr_r)
2575{
2576   return ti99_4p_internal_DSR[offset];
2577}
2578
2579
2580
2581#if 0
2582#pragma mark -
2583#pragma mark MEMORY EXPANSION CARDS
2584#endif
25851795/*===========================================================================*/
25861796/*
25871797    TI memory extension support.
r8296r8297
26691879static int sAMS_mapper_on;
26701880static int sAMSlookup[16];
26711881
2672
26731882/* set up super AMS handlers, and set initial state */
26741883static void ti99_sAMSxram_init(running_machine *machine)
26751884{
r8296r8297
27571966      COMBINE_DATA(xRAM_ptr + offset+0x5000);
27581967}
27591968
2760
27611969/*===========================================================================*/
27621970/*
2763    SNUG SGCPU (a.k.a. 99/4p) Super AMS clone support.
2764    Compatible with Super AMS, but uses a 16-bit bus.
2765
2766    Up to 1Mb of SRAM.  Straightforward mapper, works with 4kb chunks.
2767*/
2768
2769/* prototypes */
2770static void ti99_4p_mapper_cru_w(running_machine *machine, int offset, int data);
2771static READ16_HANDLER(ti99_4p_mapper_r);
2772static WRITE16_HANDLER(ti99_4p_mapper_w);
2773
2774
2775static const ti99_peb_16bit_card_handlers_t ti99_4p_mapper_handlers =
2776{
2777   NULL,
2778   ti99_4p_mapper_cru_w,
2779   ti99_4p_mapper_r,
2780   ti99_4p_mapper_w
2781};
2782
2783
2784static int ti99_4p_mapper_on;
2785static int ti99_4p_mapper_lookup[16];
2786
2787
2788/* set up handlers, and set initial state */
2789static void ti99_4p_mapper_init(running_machine *machine)
2790{
2791   int i;
2792   char bank_name[10];
2793   /* Not required at run-time */
2794#if 0
2795   memory_install_read16_handler(space, 0x2000, 0x2fff, SMH_BANK(3));
2796   memory_install_write16_handler(space, 0x2000, 0x2fff, SMH_BANK(3));
2797   memory_install_read16_handler(space, 0x3000, 0x3fff, SMH_BANK(4));
2798   memory_install_write16_handler(space, 0x3000, 0x3fff, SMH_BANK(4));
2799   memory_install_read16_handler(space, 0xa000, 0xafff, SMH_BANK(5));
2800   memory_install_write16_handler(space, 0xa000, 0xafff, SMH_BANK(5));
2801   memory_install_read16_handler(space, 0xb000, 0xbfff, SMH_BANK(6));
2802   memory_install_write16_handler(space, 0xb000, 0xbfff, SMH_BANK(6));
2803   memory_install_read16_handler(space, 0xc000, 0xcfff, SMH_BANK(7));
2804   memory_install_write16_handler(space, 0xc000, 0xcfff, SMH_BANK(7));
2805   memory_install_read16_handler(space, 0xd000, 0xdfff, SMH_BANK(8));
2806   memory_install_write16_handler(space, 0xd000, 0xdfff, SMH_BANK(8));
2807   memory_install_read16_handler(space, 0xe000, 0xefff, SMH_BANK(9));
2808   memory_install_write16_handler(space, 0xe000, 0xefff, SMH_BANK(9));
2809   memory_install_read16_handler(space, 0xf000, 0xffff, SMH_BANK(10));
2810   memory_install_write16_handler(space, 0xf000, 0xffff, SMH_BANK(10));
2811#endif
2812
2813   ti99_peb_set_16bit_card_handlers(0x1e00, & ti99_4p_mapper_handlers);
2814
2815   ti99_4p_mapper_on = 0;
2816
2817   for (i=0; i<16; i++)
2818   {
2819      ti99_4p_mapper_lookup[i] = i << 11;
2820
2821      /* update bank base */
2822      switch (i)
2823      {
2824      case 2:
2825      case 3:
2826         sprintf(bank_name,"bank%d",3+(i-2));
2827         memory_set_bankptr(machine,bank_name, xRAM_ptr + (i<<11));
2828         break;
2829
2830      case 10:
2831      case 11:
2832      case 12:
2833      case 13:
2834      case 14:
2835      case 15:
2836         sprintf(bank_name,"bank%d",5+(i-10));
2837         memory_set_bankptr(machine,bank_name, xRAM_ptr + (i<<11));
2838         break;
2839      }
2840   }
2841}
2842
2843/* write CRU bit:
2844    bit0: enable/disable mapper registers in DSR space,
2845    bit1: enable/disable address mapping */
2846static void ti99_4p_mapper_cru_w(running_machine *machine, int offset, int data)
2847{
2848   int i;
2849   char bank_name[10];
2850
2851   if (offset == 1)
2852   {
2853      if (ti99_4p_mapper_on != data)
2854      {
2855         ti99_4p_mapper_on = data;
2856
2857         for (i=0; i<16; i++)
2858         {
2859            /* update bank base */
2860            switch (i)
2861            {
2862            case 2:
2863            case 3:
2864               sprintf(bank_name,"bank%d",3+(i-2));
2865               memory_set_bankptr(machine,bank_name, xRAM_ptr + (ti99_4p_mapper_on ? (ti99_4p_mapper_lookup[i]) : (i<<11)));
2866               break;
2867
2868            case 10:
2869            case 11:
2870            case 12:
2871            case 13:
2872            case 14:
2873            case 15:
2874               sprintf(bank_name,"bank%d",5+(i-10));
2875               memory_set_bankptr(machine,bank_name, xRAM_ptr + (ti99_4p_mapper_on ? (ti99_4p_mapper_lookup[i]) : (i<<11)));
2876               break;
2877            }
2878         }
2879      }
2880   }
2881
2882}
2883
2884/* read a mapper register */
2885static READ16_HANDLER(ti99_4p_mapper_r)
2886{
2887   return (ti99_4p_mapper_lookup[offset & 0xf] >> 3);
2888}
2889
2890/* write a mapper register */
2891static WRITE16_HANDLER(ti99_4p_mapper_w)
2892{
2893   int page = offset & 0xf;
2894   char bank_name[10];
2895   ti99_4p_mapper_lookup[page] = (data & 0xff00) << 3;
2896
2897   if (ti99_4p_mapper_on)
2898   {
2899      /* update bank base */
2900      switch (page)
2901      {
2902      case 2:
2903      case 3:
2904         sprintf(bank_name,"bank%d",3+(page-2));
2905         memory_set_bankptr(space->machine,bank_name, xRAM_ptr+ti99_4p_mapper_lookup[page]);
2906         break;
2907
2908      case 10:
2909      case 11:
2910      case 12:
2911      case 13:
2912      case 14:
2913      case 15:
2914         sprintf(bank_name,"bank%d",5+(page-10));
2915         memory_set_bankptr(space->machine,bank_name, xRAM_ptr+ti99_4p_mapper_lookup[page]);
2916         break;
2917      }
2918   }
2919}
2920
2921
2922/*===========================================================================*/
2923/*
29241971    myarc-ish memory extension support (foundation, and myarc clones).
29251972
29261973    Up to 512kb of RAM.  Straightforward mapper, works with 32kb chunks.
r8296r8297
29431990   NULL
29441991};
29451992
2946
29471993static int myarc_cur_page_offset;
29481994static int myarc_page_offset_mask;
29491995
2950
29511996/* set up myarc handlers, and set initial state */
29521997static void ti99_myarcxram_init(running_machine *machine)
29531998{
r8296r8297
30222067static READ16_HANDLER ( ti99_myarcxramlow_r )
30232068{
30242069   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);
3025
30262070   return xRAM_ptr[myarc_cur_page_offset + offset];
30272071}
30282072
30292073static WRITE16_HANDLER ( ti99_myarcxramlow_w )
30302074{
30312075   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);
3032
30332076   COMBINE_DATA(xRAM_ptr + myarc_cur_page_offset + offset);
30342077}
30352078
r8296r8297
30372080static READ16_HANDLER ( ti99_myarcxramhigh_r )
30382081{
30392082   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);
3040
30412083   return xRAM_ptr[myarc_cur_page_offset + offset+0x1000];
30422084}
30432085
30442086static WRITE16_HANDLER ( ti99_myarcxramhigh_w )
30452087{
30462088   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);
3047
30482089   COMBINE_DATA(xRAM_ptr + myarc_cur_page_offset + offset+0x1000);
30492090}
30502091
30512092
3052/*===========================================================================*/
3053#if 0
3054#pragma mark -
3055#pragma mark EVPC VIDEO CARD
3056#endif
3057/*
3058    SNUG's EVPC emulation
3059*/
2093/**************************************************************************
2094    EVPC (Enhanced Video Processor Card) from SNUG
2095    based on v9938 (may also be equipped with v9958)
2096    Can be used with TI-99/4A as an add-on card; internal VDP must be removed
30602097
2098    The SGCPU ("TI-99/4P") only runs with EVPC.
2099***************************************************************************/
2100
2101#include "emuopts.h"
2102
30612103/* prototypes */
30622104static int evpc_cru_r(running_machine *machine, int offset);
30632105static void evpc_cru_w(running_machine *machine, int offset, int data);
r8296r8297
30672109/* pointer to the evpc DSR area */
30682110static UINT8 *ti99_evpc_DSR;
30692111
3070/* pointer to the evpc novram area */
3071/*static UINT8 *ti99_evpc_novram;*/
3072
30732112static int RAMEN;
3074
30752113static int evpc_dsr_page;
30762114
2115/*
2116    NOVRAM area
2117*/
2118static UINT8 ti99_evpc_novram[256];
2119
30772120static const ti99_peb_card_handlers_t evpc_handlers =
30782121{
30792122   evpc_cru_r,
r8296r8297
30822125   evpc_mem_w
30832126};
30842127
2128static struct
2129{
2130   UINT8 read_index, write_index, mask;
2131   int read;
2132   int state;
2133   struct { UINT8 red, green, blue; } color[0x100];
2134   //int dirty;
2135} evpc_palette;
30852136
30862137/*
2138    NOVRAM handling
2139*/
2140static void ti99_evpc_load_novram(running_machine *machine, const char *filename)
2141{
2142   file_error filerr;
2143   mame_file *file;
2144
2145   filerr = mame_fopen(SEARCHPATH_NVRAM, filename, OPEN_FLAG_READ, &file);
2146   if (filerr == FILERR_NONE)
2147   {
2148      if (mame_fread(file, ti99_evpc_novram, 256) != 256)
2149         logerror("ti99_4ev: NOVRAM load error\n");
2150      mame_fclose(file);
2151   }
2152}
2153
2154static void ti99_evpc_save_novram(running_machine *machine, const char *filename)
2155{
2156   file_error filerr;
2157   mame_file *file;
2158
2159   filerr = mame_fopen(SEARCHPATH_NVRAM, filename,
2160         OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
2161
2162   if (filerr == FILERR_NONE)
2163   {
2164      if (mame_fwrite(file, ti99_evpc_novram, 256) != 256)
2165         logerror("ti99_4ev: NOVRAM save error\n");
2166      mame_fclose(file);
2167   }
2168}
2169
2170INPUT_CHANGED( evpc_changed )
2171{
2172   evpc_switch[(UINT64)param&0x03] = newval;
2173}
2174
2175INTERRUPT_GEN( ti99_4ev_hblank_interrupt )
2176{
2177//  static int line_count;
2178   v9938_interrupt(device->machine, 0);
2179
2180   // No Mechatronic Mouse with v9938 (has own mouse)
2181/*  if (++line_count == 262)
2182    {
2183        line_count = 0;
2184        if (has_mecmouse)
2185            mecmouse_poll(device->machine);
2186    } */
2187}
2188
2189// still unused
2190TIMER_DEVICE_CALLBACK( ti99_4ev_scanline_interrupt )
2191{
2192   v9938_interrupt(timer->machine, 0);
2193}
2194
2195/*
2196    Video initialization. (also used by SGCPU)
2197*/
2198VIDEO_START( ti99_4ev )
2199{
2200   VIDEO_START_CALL(generic_bitmapped);
2201   v9938_init(machine, 0, machine->primary_screen, machine->generic.tmpbitmap,
2202      MODEL_V9938, 0x20000, tms9901_set_int2);   /* v38 with 128 kb of video RAM */
2203}
2204
2205/*
2206    V38 VDP read
2207*/
2208READ16_HANDLER ( ti99_rv38_r )
2209{
2210   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);
2211//  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
2212
2213   if (offset & 1)
2214   {   /* read VDP status */
2215      return ((int) v9938_0_status_r(space, 0)) << 8;
2216   }
2217   else
2218   {   /* read VDP RAM */
2219      return ((int) v9938_0_vram_r(space, 0)) << 8;
2220   }
2221}
2222
2223/*
2224    V38 vdp write
2225*/
2226WRITE16_HANDLER ( ti99_wv38_w )
2227{
2228   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);
2229//  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
2230
2231   switch (offset & 3)
2232   {
2233   case 0:
2234      /* write VDP data */
2235      v9938_0_vram_w(space, 0, (data >> 8) & 0xff);
2236      break;
2237   case 1:
2238      /* write VDP address */
2239      v9938_0_command_w(space, 0, (data >> 8) & 0xff);
2240      break;
2241   case 2:
2242      /* write VDP palette */
2243      v9938_0_palette_w(space, 0, (data >> 8) & 0xff);
2244      break;
2245   case 3:
2246      /* write VDP register pointer (indirect access) */
2247      v9938_0_register_w(space, 0, (data >> 8) & 0xff);
2248      break;
2249   }
2250}
2251
2252/*
30872253    Reset evpc card, set up handlers
30882254*/
30892255static void ti99_evpc_reset(running_machine *machine)
r8296r8297
30972263}
30982264
30992265/*
3100    Read evpc CRU interface
2266    Read EVPC CRU interface (dip switches)
2267    0: Video timing (PAL/NTSC)
2268    1: -
2269    2: charset
2270    3: RAM shift
2271    4: -
2272    5: -
2273    6: -
2274    7: DIP or NOVRAM
2275    Logic is inverted
31012276*/
31022277static int evpc_cru_r(running_machine *machine, int offset)
31032278{
3104   return 0;   /* dip-switch value */
2279   UINT8 value = 0;
2280
2281   if (offset == 0)
2282      value = ~(evpc_switch[0] | (evpc_switch[1]<<2) | (evpc_switch[2]<<3) | (evpc_switch[3]<<7));
2283
2284   return value;
31052285}
31062286
31072287/*
r8296r8297
31502330   }
31512331}
31522332
3153
3154static struct
3155{
3156   UINT8 read_index, write_index, mask;
3157   int read;
3158   int state;
3159   struct { UINT8 red, green, blue; } color[0x100];
3160   //int dirty;
3161} evpc_palette;
3162
31632333/*
31642334    read a byte in evpc DSR space
31652335*/
r8296r8297
31672337{
31682338   UINT8 reply = 0;
31692339
3170
31712340   if (offset < 0x1f00)
31722341   {
31732342      reply = ti99_evpc_DSR[offset+evpc_dsr_page*0x2000];
r8296r8297
31752344   else if (offset < 0x1ff0)
31762345   {
31772346      if (RAMEN)
3178      {   /* NOVRAM */
3179         reply = 0;
2347      {
2348         reply = ti99_evpc_novram[offset-0x1f00];
31802349      }
31812350      else
31822351      {
r8296r8297
31852354   }
31862355   else
31872356   {   /* PALETTE */
3188      logerror("palette read, offset=%d\n", offset-0x1ff0);
31892357      switch (offset - 0x1ff0)
31902358      {
31912359      case 0:
31922360         /* Palette Read Address Register */
3193         logerror("EVPC palette address read\n");
31942361         reply = evpc_palette.write_index;
31952362         break;
31962363
31972364      case 2:
31982365         /* Palette Read Color Value */
3199         logerror("EVPC palette color read\n");
32002366         if (evpc_palette.read)
32012367         {
32022368            switch (evpc_palette.state)
r8296r8297
32222388
32232389      case 4:
32242390         /* Palette Read Pixel Mask */
3225         logerror("EVPC palette mask read\n");
32262391         reply = evpc_palette.mask;
32272392         break;
32282393      case 6:
32292394         /* Palette Read Address Register for Color Value */
3230         logerror("EVPC palette status read\n");
32312395         if (evpc_palette.read)
32322396            reply = 0;
32332397         else
r8296r8297
32452409static WRITE8_HANDLER(evpc_mem_w)
32462410{
32472411   if ((offset >= 0x1f00) && (offset < 0x1ff0) && RAMEN)
3248   {   /* NOVRAM */
2412   {
2413      // NOVRAM
2414      ti99_evpc_novram[offset-0x1f00] = data;
32492415   }
32502416   else if (offset >= 0x1ff0)
32512417   {   /* PALETTE */
r8296r8297
33042470   }
33052471}
33062472
3307/* tms9901 setup */
3308const tms9901_interface tms9901reset_param_ti99_4x =
2473/**************************************************************************
2474    TI-99/8
2475***************************************************************************/
2476
2477DRIVER_INIT( ti99_8 )
33092478{
3310   TMS9901_INT1 | TMS9901_INT2 | TMS9901_INTC,   /* only input pins whose state is always known */
2479   UINT8 *mem = memory_region(machine, "maincpu");
2480   ti99_model = model_99_8;
2481   has_evpc = FALSE;
33112482
3312   {   /* read handlers */
3313      ti99_R9901_0,
3314      ti99_R9901_1,
3315      ti99_R9901_2,
3316      ti99_R9901_3
3317   },
2483   /* set up memory pointers */
2484   xRAM_ptr_8 = mem + offset_xram_8;
2485   ROM0_ptr_8 = mem + offset_rom0_8;
2486   ROM1_ptr_8 = ROM0_ptr_8 + 0x2000;
2487   ROM2_ptr_8 = ROM1_ptr_8 + 0x2000;
2488   ROM3_ptr_8 = ROM2_ptr_8 + 0x2000;
2489   sRAM_ptr_8 = mem + offset_sram_8;
33182490
3319   {   /* write handlers */
3320      ti99_handset_set_ack,
3321      NULL,
3322      ti99_KeyC,
3323      ti99_KeyC,
3324      ti99_KeyC,
3325      ti99_AlphaW,
3326      ti99_CS_motor,
3327      ti99_CS_motor,
3328      ti99_audio_gate,
3329      ti99_CS_output,
3330      NULL,
3331      NULL,
3332      NULL,
3333      NULL,
3334      NULL,
3335      NULL
3336   },
2491   /* Pull this one up here. */
2492   ti99_8_enable_rom_and_ports = 1;
33372493
3338   /* interrupt handler */
3339   tms9901_interrupt_callback,
2494   console_GROMs.data_ptr = memory_region(machine, region_grom);
2495   create_grom_high2k(0x0000, 0x5fff);
33402496
3341   /* clock rate = 3MHz */
3342   3000000.
2497   multicart8 = devtag_get_device(machine, "ti99_multicart");
2498   assert (multicart8 != NULL);
2499}
2500
2501/*
2502    ti99_init_machine(); called before ti99_load_rom...
2503*/
2504MACHINE_RESET( ti99_8 )
2505{
2506   /*console_GROMs.data_ptr = memory_region(machine, region_grom);*/
2507   console_GROMs.addr = 0;
2508   console_GROMs.buf = 0;
2509   console_GROMs.raddr_LSB = FALSE;
2510   console_GROMs.waddr_LSB = FALSE;
2511
2512   ti99_8_enable_rom_and_ports = 1;      /* ??? maybe there is a pull-up */
2513   /* MZ: already setting this in driver init, otherwise machine locks up */
2514
2515   TMS9928A_reset();
2516
2517   /* clear keyboard interface state (probably overkill, but can't harm) */
2518   KeyCol = 0;
2519   AlphaLockLine = 0;
2520
2521   tms9901_set_single_int(devtag_get_device(machine, "tms9901"), 12, 0);
2522
2523   xRAM_kind = RAM_99_8;
2524   has_speech = TRUE;
2525   has_ide = input_port_read(machine, "HDCTRL") & HD_IDE;
2526   has_rs232 = input_port_read(machine, "SERIAL") & SERIAL_TI;
2527   has_handset = FALSE;
2528
2529   has_mecmouse = input_port_read(machine, "HCI") & HCI_MECMOUSE;
2530
2531   has_hsgpl = input_port_read(machine, "EXTCARD") & (EXT_HSGPL_ON | EXT_HSGPL_FLASH);
2532   hsgpl_flash_mode = input_port_read(machine, "EXTCARD") & EXT_HSGPL_FLASH;
2533
2534   has_usb_sm = input_port_read(machine, "HDCTRL") & HD_USB;
2535   has_pcode = input_port_read(machine, "EXTCARD") & EXT_PCODE;
2536
2537   /* Get the GK settings once */
2538   gk_switch[1] = input_port_read(machine, "GKSWITCH1");
2539   gk_switch[2] = input_port_read(machine, "GKSWITCH2");
2540   gk_switch[3] = input_port_read(machine, "GKSWITCH3");
2541   gk_switch[4] = input_port_read(machine, "GKSWITCH4");
2542   gk_switch[5] = input_port_read(machine, "GKSWITCH5");
2543
2544   // Removes all card handlers
2545   ti99_peb_init();
2546
2547   // set up optional expansion hardware
2548   ti99_peb_reset(FALSE, tms9901_set_int1, NULL);
2549
2550   ti99_8_internal_dsr_reset(machine);
2551
2552   static const spchroms_interface speech_intf = { region_speech_rom };
2553   spchroms_config(machine, &speech_intf);
2554
2555   switch (input_port_read(machine, "DISKCTRL"))
2556   {
2557   case DISK_TIFDC:
2558      ti99_fdc_reset(machine);
2559      break;
2560#if HAS_99CCFDC
2561   case DISK_CC:
2562      ti99_ccfdc_reset(machine);
2563      break;
2564#endif
2565   case DISK_BWG:
2566      ti99_bwg_reset(machine);
2567      break;
2568   case DISK_HFDC:
2569      ti99_hfdc_reset(machine);
2570      break;
2571   case DISK_NONE:
2572      break;
2573   }
2574
2575   if (has_ide)
2576      ti99_ide_reset(machine, TRUE);
2577
2578   if (has_hsgpl)
2579      ti99_hsgpl_reset(machine);
2580   else
2581      hsgpl_crdena = 0;
2582
2583   if (has_usb_sm)
2584      ti99_usbsm_reset(machine, TRUE);
2585
2586   if (has_pcode)
2587      ti99_pcode_reset(machine);
2588
2589   /* initialize mechatronics mouse */
2590   mecmouse_sel = 0;
2591   mecmouse_read_y = 0;
2592   mecmouse_x = 0;
2593   mecmouse_y = 0;
2594}
2595
2596/*
2597    GROM read for TI-99/8
2598    For comments, see the handler for TI-99/4A
2599*/
2600static READ8_HANDLER ( ti99_grom_r8 )
2601{
2602   UINT8 reply, replycart;
2603
2604   cpu_adjust_icount(space->machine->firstcpu,-4);
2605
2606   if (offset & 2)
2607   {
2608      replycart = ti99_cartridge_grom_r(cartslots, offset);
2609      console_GROMs.waddr_LSB = FALSE;
2610
2611      if (console_GROMs.raddr_LSB)
2612      {
2613         reply = console_GROMs.addr & 0x00ff;
2614         console_GROMs.raddr_LSB = FALSE;
2615      }
2616      else
2617      {
2618         reply = (console_GROMs.addr>>8) & 0x00ff;
2619         console_GROMs.raddr_LSB = TRUE;
2620      }
2621      /* GROM address values must be globally unique. */
2622      assert (replycart == reply);
2623   }
2624   else
2625   {
2626      reply = GROM_dataread(space->machine, offset);
2627   }
2628   return reply;
2629}
2630
2631/*
2632    GROM write for TI-99/8
2633    For comments, see the handler for TI-99/4A
2634*/
2635static WRITE8_HANDLER ( ti99_grom_w8 )
2636{
2637   cpu_adjust_icount(space->machine->firstcpu,-4/*20+3*/);      /* from 4 to 23? */
2638
2639   if (offset & 2)
2640   {
2641      ti99_cartridge_grom_w(cartslots, offset, data);
2642      console_GROMs.raddr_LSB = FALSE;
2643      if (console_GROMs.waddr_LSB)
2644      {
2645         console_GROMs.addr = (console_GROMs.addr & 0xFF00) | (data & 0xFF);
2646
2647         GROM_dataread(space->machine, offset&0xfffc);
2648         console_GROMs.waddr_LSB = FALSE;
2649      }
2650      else
2651      {
2652         console_GROMs.addr = ((data<<8) & 0xFF00) | (console_GROMs.addr & 0xFF);
2653         console_GROMs.waddr_LSB = TRUE;
2654      }
2655
2656   }
2657   else
2658   {
2659      GRAM_datawrite(offset, (data>>8)&0xff);
2660      console_GROMs.raddr_LSB = console_GROMs.waddr_LSB = FALSE;
2661   }
2662}
2663
2664READ8_HANDLER( ti99_8_r )
2665{
2666   /* Set the page. Page size is 4 KiB; page number are the high 4 bits. */
2667   int page = offset >> 12;
2668   UINT32 mapper_reg;
2669   UINT8 reply = 0;
2670
2671   if (ti99_8_enable_rom_and_ports)
2672   {
2673      //  This is only important for address access 0000-1fff and
2674      // 8000-9fff. Outside, the mapper mode is used.
2675      if ((offset >= 0x0000) && (offset < 0x2000))
2676      {
2677         /* ROM */
2678         reply = ROM0_ptr_8[offset & 0x1fff];
2679         return reply;
2680      }
2681      else if ((offset >= 0x8000) && (offset < 0xa000))
2682      {
2683         /* ti99 scratch pad and memory-mapped registers */
2684         /* 0x8000-0x9fff */
2685         switch ((offset - 0x8000) >> 10)
2686         {
2687         case 0:
2688            /* RAM: >8000 - >83ff */
2689            reply = sRAM_ptr_8[offset & 0x1fff];
2690            break;
2691
2692         case 1:
2693            // >8400 - >840f: sound (cannot read)
2694            // >8410 - >87ff: SRAM
2695            if (offset >= 0x8410)
2696               reply = sRAM_ptr_8[offset & 0x1fff];
2697            break;
2698
2699         case 2:
2700            /* VDP read + mapper status */
2701            if (offset < 0x8810)
2702            {
2703               if (! (offset & 1))
2704               {
2705                  if (offset & 2)
2706                     /* read VDP status >8802 */
2707                  reply = TMS9928A_register_r(space, 0);
2708                  else
2709                     /* read VDP RAM >8800 */
2710                  reply = TMS9928A_vram_r(space, 0);
2711               }
2712            }
2713            else
2714            {
2715               /* Read mapper >8810 */
2716               reply = ti99_8_mapper_status;
2717               ti99_8_mapper_status = 0;
2718            }
2719            break;
2720
2721         case 4:
2722            /* speech read: >9000 */
2723            if (! (offset & 1))
2724            {
2725               cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-16*4);      /* this is just a minimum, it can be more */
2726               reply = tms5220_status_r(devtag_get_device(space->machine, "tms5220"), 0);
2727            }
2728            break;
2729
2730         case 6:
2731            /* GROM read: >9800 */
2732            if (! (offset & 1))
2733               reply = ti99_grom_r8(space, offset);
2734            break;
2735
2736         default:
2737            logerror("unmapped read offs=%d\n", (int) offset);
2738            break;
2739         }
2740         return reply;
2741      }
2742   }
2743
2744   mapper_reg = ti99_8_mapper_regs[page];
2745   offset = (mapper_reg + (offset & 0x0fff)) & 0x00ffffff;
2746
2747   if (offset < 0x010000)
2748   /* Read RAM */
2749   reply = xRAM_ptr_8[offset];
2750
2751   if (offset >= 0xff0000)
2752   {
2753      switch ((offset >> 13) & 7)
2754      {
2755      default:
2756         /* should never happen */
2757      case 0:
2758         /* ff0000 - ff1fff: unassigned? */
2759      case 1:
2760         /* ff2000 - ff3fff: ? */
2761      case 4:
2762         /* ff8000 - ff9fff: internal DSR ROM? (normally enabled with a write to CRU >2700) */
2763      case 7:
2764         /* ffe000 - ffffff: ? */
2765         logerror("unmapped read page=%d offs=%d\n", (int) page, (int) offset);
2766         break;
2767
2768      case 2:
2769         /* ff4000 - ff5fff: DSR space */
2770         reply = ti99_8_peb_r(space, offset & 0x1fff);
2771         break;
2772
2773      case 3:
2774         /* ff6000 - ff7fff: cartridge ROM space */
2775         offset &= 0x1fff;
2776
2777         // We do not support hsgpl here. Just check the cartridges.
2778         reply = ti99_multicart8_r(multicart8, offset);
2779         break;
2780
2781      case 5:
2782         /* ffa000 - ffbfff: >2000 ROM (ROM1) */
2783         reply = ROM1_ptr_8[offset & 0x1fff];
2784         break;
2785
2786      case 6:
2787         /* ffc000 - ffdfff: >6000 ROM */
2788         reply = ROM3_ptr_8[offset & 0x1fff];
2789         break;
2790      }
2791   }
2792
2793   return reply;
2794}
2795
2796WRITE8_HANDLER ( ti99_8_w )
2797{
2798   int page = offset >> 12;
2799   UINT32 mapper_reg;
2800
2801   if (ti99_8_enable_rom_and_ports)
2802   {
2803      /* memory mapped ports enabled */
2804      if ((offset >= 0x0000) && (offset < 0x2000))
2805      {
2806         /* ROM? */
2807         return;
2808      }
2809      else if ((offset >= 0x8000) && (offset < 0xa000))
2810      {
2811         /* ti99 scratch pad and memory-mapped registers */
2812         /* 0x8000-0x9fff */
2813         switch ((offset - 0x8000) >> 10)
2814         {
2815         case 0:
2816            /* RAM */
2817            sRAM_ptr_8[offset & 0x1fff] = data;
2818            break;
2819
2820         case 1:
2821            /* sound write + RAM */
2822            if (offset < 0x8410)
2823               sn76496_w(devtag_get_device(space->machine, "sn76496"), offset, data);
2824            else
2825               sRAM_ptr_8[offset & 0x1fff] = data;
2826            break;
2827
2828         case 2:
2829            /* VDP read + mapper control */
2830            if (offset >= 0x8810)
2831            {
2832               int file = (data >> 1) & 3;
2833               int i;
2834
2835               if (data & 1)
2836               {   /* load */
2837                  for (i=0; i<16; i++)
2838                  {
2839                     ti99_8_mapper_regs[i] = (sRAM_ptr_8[(file << 6) + (i << 2)] << 24)
2840                                       | (sRAM_ptr_8[(file << 6) + (i << 2) + 1] << 16)
2841                                       | (sRAM_ptr_8[(file << 6) + (i << 2) + 2] << 8)
2842                                       | sRAM_ptr_8[(file << 6) + (i << 2) + 3];
2843                  }
2844               }
2845               else
2846               {   /* save */
2847                  for (i=0; i<16; i++)
2848                  {
2849                     sRAM_ptr_8[(file << 6) + (i << 2)] = ti99_8_mapper_regs[i] >> 24;
2850                     sRAM_ptr_8[(file << 6) + (i << 2) + 1] = ti99_8_mapper_regs[i] >> 16;
2851                     sRAM_ptr_8[(file << 6) + (i << 2) + 2] = ti99_8_mapper_regs[i] >> 8;
2852                     sRAM_ptr_8[(file << 6) + (i << 2) + 3] = ti99_8_mapper_regs[i];
2853                  }
2854               }
2855            }
2856            break;
2857
2858         case 3:
2859            /* VDP write */
2860            if (! (offset & 1))
2861            {
2862               if (offset & 2)
2863                  /* read VDP status */
2864                  TMS9928A_register_w(space, 0, data);
2865               else
2866                  /* read VDP RAM */
2867                  TMS9928A_vram_w(space, 0, data);
2868            }
2869            break;
2870
2871         case 5:
2872            /* speech write */
2873            if (! (offset & 1))
2874            {
2875               cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-48*4);      /* this is just an approx. minimum, it can be much more */
2876
2877               // the stupid design of the tms5220 core means that ready is cleared when
2878               // there are 15 bytes in FIFO.  It should be 16.  Of course, if it were the
2879               // case, we would need to store the value on the bus, which would be more
2880               // complex.
2881               if (! tms5220_readyq_r(devtag_get_device(space->machine, "tms5220")))
2882               {
2883                  attotime time_to_ready = double_to_attotime(tms5220_time_to_ready(devtag_get_device(space->machine, "tms5220")));
2884                  double d = cputag_attotime_to_clocks(space->machine, "maincpu", time_to_ready);
2885                  int cycles_to_ready = ((int) (d + 3)) & ~3;
2886
2887                  logerror("time to ready: %f -> %d\n", attotime_to_double(time_to_ready)
2888                     , (int) cycles_to_ready);
2889
2890                  cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-cycles_to_ready);
2891                  timer_set(space->machine, attotime_zero, NULL, 0, /*speech_kludge_callback*/NULL);
2892               }
2893
2894               tms5220_data_w(devtag_get_device(space->machine, "tms5220"), offset, data);
2895            }
2896            break;
2897
2898         case 7:
2899            /* GPL write */
2900            if (! (offset & 1))
2901               ti99_grom_w8(space, offset, data);
2902            break;
2903
2904         default:
2905            logerror("unmapped write offs=%d data=%d\n", (int) offset, (int) data);
2906            break;
2907         }
2908         return;
2909      }
2910   }
2911
2912   mapper_reg = ti99_8_mapper_regs[page];
2913
2914   /* 4 KiB page size */
2915   offset = (mapper_reg + (offset & 0x0fff)) & 0x00ffffff;
2916
2917#if 0
2918   /* test write protect */
2919   if (mapper_reg & 0x80000000)
2920      ;
2921#endif
2922
2923   if (offset < 0x010000)
2924   {   /* Write RAM */
2925      xRAM_ptr_8[offset] = data;
2926   }
2927   else if (offset >= 0xff0000)
2928   {
2929      switch ((offset >> 13) & 7)
2930      {
2931      default:
2932         /* should never happen */
2933      case 0:
2934         /* unassigned??? */
2935      case 1:
2936         /* ??? */
2937      case 4:
2938         /* internal DSR ROM??? (normally enabled with a write to CRU >2700) */
2939      case 7:
2940         /* ??? */
2941         break;
2942
2943      case 2:
2944         /* DSR space */
2945         ti99_8_peb_w(space, offset & 0x1fff, data);
2946         break;
2947
2948      case 3:
2949         /* cartridge space */
2950         /* We do not support HSGPL for the 99/8 at this time. */
2951         ti99_multicart8_w(multicart8, offset & 0x1fff, data);
2952         break;
2953
2954      case 5:
2955         /* >2000 ROM (ROM1) */
2956         break;
2957
2958      case 6:
2959         /* >6000 ROM */
2960         break;
2961      }
2962   }
2963   else
2964   {
2965      logerror("unmapped write page=%d offs=%d\n", (int) page, (int) offset);
2966   }
2967}
2968
2969/*
2970    WRITE key column select (P0-P3)
2971*/
2972static WRITE8_DEVICE_HANDLER( ti99_8_KeyC )
2973{
2974   if (data)
2975      KeyCol |= 1 << offset;
2976   else
2977      KeyCol &= ~ (1 << offset);
2978
2979   if (has_mecmouse)
2980      mecmouse_select(KeyCol, 14, 15);
2981}
2982
2983static WRITE8_DEVICE_HANDLER( ti99_8_WCRUS )
2984{
2985   ti99_8_enable_rom_and_ports = data;
2986}
2987
2988static WRITE8_DEVICE_HANDLER( ti99_8_PTGEN )
2989{
2990   /* ... */
2991}
2992
2993/*
2994    TI 99/8 internal DSR support.
2995    Includes a few specific signals, and an extra ROM.
2996*/
2997
2998/* prototypes */
2999static void ti99_8_internal_dsr_cru_w(running_machine *machine, int offset, int data);
3000static  READ8_HANDLER(ti99_8_internal_dsr_r);
3001
3002
3003static const ti99_peb_card_handlers_t ti99_8_internal_dsr_handlers =
3004{
3005   NULL,
3006   ti99_8_internal_dsr_cru_w,
3007   ti99_8_internal_dsr_r,
3008   NULL
33433009};
33443010
3011/* pointer to the internal DSR ROM data */
3012static UINT8 *ti99_8_internal_DSR;
3013
3014
3015/* set up handlers, and set initial state */
3016static void ti99_8_internal_dsr_reset(running_machine *machine)
3017{
3018   ti99_8_internal_DSR = memory_region(machine, "maincpu") + offset_rom0_8 + 0x4000;
3019
3020   ti99_peb_set_card_handlers(0x2700, & ti99_8_internal_dsr_handlers);
3021}
3022
3023/* write CRU bit:
3024    bit0: enable/disable internal DSR ROM,
3025    bit1: hard reset */
3026static void ti99_8_internal_dsr_cru_w(running_machine *machine, int offset, int data)
3027{
3028   switch (offset)
3029   {
3030   case 1:
3031      /* hard reset -- not emulated */
3032      break;
3033   }
3034}
3035
3036/* read internal DSR ROM */
3037static  READ8_HANDLER(ti99_8_internal_dsr_r)
3038{
3039   return ti99_8_internal_DSR[offset];
3040}
3041
3042/*
3043    Read pins INT3*-INT7* of TI99's 9901.
3044
3045    signification:
3046     (bit 1: INT1 status)
3047     (bit 2: INT2 status)
3048     bits 3-4: unused?
3049     bit 5: ???
3050     bit 6-7: keyboard status bits 0 through 1
3051*/
3052static READ8_DEVICE_HANDLER( ti99_8_R9901_0 )
3053{
3054   int answer;
3055   static const char *const keynames[] = {
3056      "KEY0", "KEY1", "KEY2", "KEY3", "KEY4", "KEY5", "KEY6", "KEY7",
3057      "KEY8", "KEY9", "KEY10", "KEY11", "KEY12", "KEY13", "KEY14", "KEY15"
3058   };
3059
3060   if (has_mecmouse && (KeyCol == 15))
3061   {
3062      int buttons = input_port_read(device->machine, "MOUSE0") & 3;
3063
3064      answer = ((mecmouse_read_y ? mecmouse_y_buf : mecmouse_x_buf) << 7) & 0x80;
3065
3066      if (! (buttons & 1))
3067         /* action button */
3068         answer |= 0x40;
3069   }
3070   else
3071   {
3072      answer = (input_port_read(device->machine, keynames[KeyCol]) << 6) & 0xC0;
3073   }
3074
3075   return answer;
3076}
3077
33453078const tms9901_interface tms9901reset_param_ti99_8 =
33463079{
33473080   TMS9901_INT1 | TMS9901_INT2 | TMS9901_INTC,   /* only input pins whose state is always known */
r8296r8297
33783111   /* clock rate = 3.58MHz??? 2.68MHz??? */
33793112   /*3579545.*/2684658.75
33803113};
3114
3115
3116/**************************************************************************
3117    SGCPU (aka "TI-99/4P")
3118    Requires EVPC and HSGPL (with content)
3119***************************************************************************/
3120
3121/* True if SGCPU rom6 is enabled */
3122static int ti99_4p_internal_rom6_enable;
3123
3124/* Pointer to the memory area. */
3125static UINT16 *ti99_4p_mem;
3126
3127/* pointer to the internal DSR ROM data */
3128static UINT16 *ti99_4p_internal_DSR;
3129
3130/* Offset to the ROM6 bank. */
3131static offs_t rom6_bank_offset;
3132
3133static void ti99_4p_mapper_cru_w(running_machine *machine, int offset, int data);
3134static READ16_HANDLER(ti99_4p_mapper_r);
3135static WRITE16_HANDLER(ti99_4p_mapper_w);
3136static void ti99_4p_internal_dsr_cru_w(running_machine *machine, int offset, int data);
3137static READ16_HANDLER(ti99_4p_internal_dsr_r);
3138
3139static const ti99_peb_16bit_card_handlers_t ti99_4p_internal_dsr_handlers =
3140{
3141   NULL,
3142   ti99_4p_internal_dsr_cru_w,
3143   ti99_4p_internal_dsr_r,
3144   NULL
3145};
3146
3147static const ti99_peb_16bit_card_handlers_t ti99_4p_mapper_handlers =
3148{
3149   NULL,
3150   ti99_4p_mapper_cru_w,
3151   ti99_4p_mapper_r,
3152   ti99_4p_mapper_w
3153};
3154
3155static int ti99_4p_mapper_on;
3156static int ti99_4p_mapper_lookup[16];
3157
3158DRIVER_INIT( ti99_4p )
3159{
3160   ti99_model = model_99_4p;
3161   has_evpc = TRUE;
3162
3163   /* set up memory pointers */
3164   xRAM_ptr = (UINT16 *) (memory_region(machine, "maincpu") + offset_xram_4p);
3165}
3166
3167MACHINE_START( ti99_4p )
3168{
3169   UINT8* mem = memory_region(machine, "maincpu");
3170
3171   // Set up system ROM pointers. Must be set up here
3172   // so that the system can successfully reset (otherwise the reset
3173   // vector would be missing in 0x0000).
3174   memory_set_bankptr(machine, "bank1", mem + offset_rom0_4p);    // system ROM
3175
3176   ti99_floppy_controllers_init_all(machine);
3177   ti99_ide_init(machine);
3178   ti99_hsgpl_init(machine);
3179   ti99_usbsm_init(machine);
3180}
3181
3182/*
3183    Reset the machine.
3184*/
3185MACHINE_RESET( ti99_4p )
3186{
3187   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
3188
3189   UINT8* mem = memory_region(machine, "maincpu");
3190
3191   /* set up system ROM and scratch pad pointers */
3192   memory_set_bankptr(machine, "bank1", mem + offset_rom0_4p);   /* system ROM */
3193   memory_set_bankptr(machine, "bank2", mem + offset_sram_4p);   /* scratch pad */
3194   memory_set_bankptr(machine, "bank11", mem + offset_dram_4p);   /* extra RAM for debugger */
3195
3196   v9938_reset(0);
3197
3198   /* clear keyboard interface state (probably overkill, but can't harm) */
3199   KeyCol = 0;
3200   AlphaLockLine = 0;
3201
3202   tms9901_set_single_int(devtag_get_device(machine, "tms9901"), 12, 0);
3203
3204   xRAM_kind = RAM_99_4P;
3205   has_speech = input_port_read(machine, "SPEECH");
3206   has_ide = input_port_read(machine, "HDCTRL") & HD_IDE;
3207   has_rs232 = input_port_read(machine, "SERIAL") & SERIAL_TI;
3208
3209   has_handset = FALSE;
3210   has_mecmouse = FALSE;        // mouse is connected to v9938
3211   has_hsgpl = TRUE;
3212   has_usb_sm = input_port_read(machine, "HDCTRL") & HD_USB;
3213   has_pcode = input_port_read(machine, "EXTCARD") & EXT_PCODE;
3214
3215   // Removes all card handlers
3216   ti99_peb_init();
3217
3218   // set up optional expansion hardware
3219   ti99_peb_reset(TRUE, tms9901_set_int1, NULL);
3220
3221   ti99_4p_internal_dsr_reset(machine);
3222   ti99_4p_mapper_init(machine);
3223   ti99_hsgpl_reset(machine);
3224   ti99_evpc_reset(machine);
3225
3226   if (has_speech)
3227   {
3228      static const spchroms_interface speech_intf = { region_speech_rom };
3229      spchroms_config(machine, &speech_intf);
3230      memory_install_read16_handler(space, 0x9000, 0x93ff, 0, 0, ti99_rspeech_r);
3231      memory_install_write16_handler(space, 0x9400, 0x97ff, 0, 0, ti99_wspeech_w);
3232   }
3233   else
3234   {
3235      memory_install_read16_handler(space, 0x9000, 0x93ff, 0, 0, ti99_nop_8_r);
3236      memory_install_write16_handler(space, 0x9400, 0x97ff, 0, 0, ti99_nop_8_w);
3237   }
3238
3239
3240   switch (input_port_read(machine, "DISKCTRL"))
3241   {
3242   case DISK_TIFDC:
3243      ti99_fdc_reset(machine);
3244      break;
3245#if HAS_99CCFDC
3246   case DISK_CC:
3247      ti99_ccfdc_reset(machine);
3248      break;
3249#endif
3250   case DISK_BWG:
3251      ti99_bwg_reset(machine);
3252      break;
3253   case DISK_HFDC:
3254      ti99_hfdc_reset(machine);
3255      break;
3256   case DISK_NONE:
3257      break;
3258   }
3259
3260   if (has_ide)
3261      ti99_ide_reset(machine, FALSE);
3262
3263   if (has_usb_sm)
3264      ti99_usbsm_reset(machine, FALSE);
3265
3266   if (has_pcode)
3267      ti99_pcode_reset(machine);
3268}
3269
3270
3271/*
3272    SNUG SGCPU (a.k.a. 99/4p) Super AMS clone support.
3273    Compatible with Super AMS, but uses a 16-bit bus.
3274
3275    Up to 1Mb of SRAM.  Straightforward mapper, works with 4kb chunks.
3276*/
3277
3278/* set up handlers, and set initial state */
3279static void ti99_4p_mapper_init(running_machine *machine)
3280{
3281   int i;
3282   char bank_name[10];
3283   /* Not required at run-time */
3284   ti99_peb_set_16bit_card_handlers(0x1e00, & ti99_4p_mapper_handlers);
3285
3286   ti99_4p_mapper_on = 0;
3287
3288   for (i=0; i<16; i++)
3289   {
3290      ti99_4p_mapper_lookup[i] = i << 11;
3291
3292      /* update bank base */
3293      switch (i)
3294      {
3295      case 2:
3296      case 3:
3297         sprintf(bank_name,"bank%d",3+(i-2));
3298         memory_set_bankptr(machine,bank_name, xRAM_ptr + (i<<11));
3299         break;
3300
3301      case 10:
3302      case 11:
3303      case 12:
3304      case 13:
3305      case 14:
3306      case 15:
3307         sprintf(bank_name,"bank%d",5+(i-10));
3308         memory_set_bankptr(machine,bank_name, xRAM_ptr + (i<<11));
3309         break;
3310      }
3311   }
3312}
3313
3314/*
3315    Write CRU bit:
3316    bit0: enable/disable mapper registers in DSR space,
3317    bit1: enable/disable address mapping
3318*/
3319static void ti99_4p_mapper_cru_w(running_machine *machine, int offset, int data)
3320{
3321   int i;
3322   char bank_name[10];
3323
3324   if (offset == 1)
3325   {
3326      if (ti99_4p_mapper_on != data)
3327      {
3328         ti99_4p_mapper_on = data;
3329
3330         for (i=0; i<16; i++)
3331         {
3332            /* update bank base */
3333            switch (i)
3334            {
3335            case 2:
3336            case 3:
3337               sprintf(bank_name,"bank%d",3+(i-2));
3338               memory_set_bankptr(machine,bank_name, xRAM_ptr + (ti99_4p_mapper_on ? (ti99_4p_mapper_lookup[i]) : (i<<11)));
3339               break;
3340
3341            case 10:
3342            case 11:
3343            case 12:
3344            case 13:
3345            case 14:
3346            case 15:
3347               sprintf(bank_name,"bank%d",5+(i-10));
3348               memory_set_bankptr(machine,bank_name, xRAM_ptr + (ti99_4p_mapper_on ? (ti99_4p_mapper_lookup[i]) : (i<<11)));
3349               break;
3350            }
3351         }
3352      }
3353   }
3354}
3355
3356/* read a mapper register */
3357static READ16_HANDLER(ti99_4p_mapper_r)
3358{
3359   return (ti99_4p_mapper_lookup[offset & 0xf] >> 3);
3360}
3361
3362/* write a mapper register */
3363static WRITE16_HANDLER(ti99_4p_mapper_w)
3364{
3365   int page = offset & 0xf;
3366   char bank_name[10];
3367   ti99_4p_mapper_lookup[page] = (data & 0xff00) << 3;
3368
3369   if (ti99_4p_mapper_on)
3370   {
3371      /* update bank base */
3372      switch (page)
3373      {
3374      case 2:
3375      case 3:
3376         sprintf(bank_name,"bank%d",3+(page-2));
3377         memory_set_bankptr(space->machine,bank_name, xRAM_ptr+ti99_4p_mapper_lookup[page]);
3378         break;
3379
3380      case 10:
3381      case 11:
3382      case 12:
3383      case 13:
3384      case 14:
3385      case 15:
3386         sprintf(bank_name,"bank%d",5+(page-10));
3387         memory_set_bankptr(space->machine,bank_name, xRAM_ptr+ti99_4p_mapper_lookup[page]);
3388         break;
3389      }
3390   }
3391}
3392
3393/*
3394    Internal DSR support.
3395    Includes a few specific signals, and an extra ROM.
3396*/
3397static void ti99_4p_internal_dsr_reset(running_machine *machine)
3398{
3399   // set up handlers, and set initial state
3400   UINT8* mem = memory_region(machine, "maincpu");
3401
3402   ti99_4p_internal_DSR = (UINT16 *) (mem + offset_rom4_4p);
3403   rom6_bank_offset = offset_rom6_4p;
3404   ti99_4p_mem = (UINT16 *)mem;
3405
3406   ti99_peb_set_16bit_card_handlers(0x0f00, & ti99_4p_internal_dsr_handlers);
3407
3408   ti99_4p_internal_rom6_enable = 0;
3409   ti99_4p_peb_set_senila(0);
3410   ti99_4p_peb_set_senilb(0);
3411}
3412
3413/*
3414    Write CRU bit:
3415    bit0: enable/disable internal DSR ROM,
3416    bit1: enable/disable internal cartridge ROM
3417    bit2: set/clear senila
3418    bit3: set/clear senilb
3419*/
3420static void ti99_4p_internal_dsr_cru_w(running_machine *machine, int offset, int data)
3421{
3422   switch (offset)
3423   {
3424   case 1:
3425      ti99_4p_internal_rom6_enable = data;
3426      break;
3427   case 2:
3428      ti99_4p_peb_set_senila(data);
3429      break;
3430   case 3:
3431      ti99_4p_peb_set_senilb(data);
3432      break;
3433   case 4:
3434      /* 0: 16-bit (fast) memory timings */
3435      /* 1: 8-bit memory timings */
3436      break;
3437   case 5:
3438      /* if 0: "KBENA" mode (enable keyboard?) */
3439      /* if 1: "KBINH" mode (inhibit keyboard?) */
3440      break;
3441   }
3442}
3443
3444/*
3445    Read internal DSR ROM.
3446    Addresses 4000-5fff
3447*/
3448static READ16_HANDLER(ti99_4p_internal_dsr_r)
3449{
3450   return ti99_4p_internal_DSR[offset];
3451}
3452
3453/*
3454    SGCPU cartridge space: mapped either to internal ROM6 or to HSGPL.
3455    Addresses 6000-7fff
3456*/
3457READ16_HANDLER ( ti99_4p_cart_r )
3458{
3459   UINT16 value = 0;
3460   if (ti99_4p_internal_rom6_enable)
3461   {
3462      value = ti99_4p_mem[(rom6_bank_offset>>1) + offset];
3463   }
3464   else
3465   {
3466      cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);
3467      //  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
3468
3469      if (hsgpl_crdena)
3470         /* hsgpl is enabled */
3471         value = ti99_hsgpl_rom6_r(space, offset, mem_mask);
3472   }
3473   return value;
3474}
3475
3476WRITE16_HANDLER ( ti99_4p_cart_w )
3477{
3478   if (ti99_4p_internal_rom6_enable)
3479   {
3480      // Switch ROMs
3481      if (offset & 1)
3482         rom6_bank_offset = offset_rom6b_4p;
3483      else
3484         rom6_bank_offset = offset_rom6_4p;
3485   }
3486   else
3487   {
3488      cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);
3489      //  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
3490
3491      if (hsgpl_crdena)
3492         /* hsgpl is enabled */
3493         ti99_hsgpl_rom6_w(space, offset, data, mem_mask);
3494   }
3495}
3496
3497/*
3498    GROM read for TI-99/4p
3499*/
3500READ16_HANDLER ( ti99_4p_grom_r )
3501{
3502   UINT16 value = 0;
3503   // HSGPL is located on 8-bit bus
3504   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);
3505   //  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
3506
3507   // When crdena is false, we must still be able to query the address
3508   // counter (offset & 1)
3509   if (hsgpl_crdena || (offset & 1))
3510      value = ti99_hsgpl_gpl_r(space, offset, mem_mask);
3511
3512   return value;
3513}
3514
3515/*
3516    GROM write
3517*/
3518WRITE16_HANDLER ( ti99_4p_grom_w )
3519{
3520   // HSGPL is located on 8-bit bus
3521   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);
3522   //  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
3523
3524   if (hsgpl_crdena || (offset & 1))
3525      ti99_hsgpl_gpl_w(space, offset, data, mem_mask);
3526}
3527
src/mess/machine/ti99_4x.h
r8296r8297
2828
2929enum
3030{
31   offset_rom0_4p = 0x4000,
32   offset_rom4_4p = 0xc000,
33   offset_rom6_4p = 0x6000,
34   offset_rom6b_4p= 0xe000,
35   offset_sram_4p = 0x10000,      /* scratch RAM (1kbyte) */
36   offset_dram_4p = 0x10400,      /* extra ram for debugger (768 bytes) */
37   offset_xram_4p = 0x10700,      /* extended RAM (1Mb with super AMS compatible mapper) */
38   region_cpu1_len_4p = 0x110700   /* total len */
31   offset_rom0_4p = 0x4000,        // ROM0: 4000-5fff
32   offset_rom4_4p = 0xc000,        // ROM4: c000-dfff
33   offset_rom6_4p = 0x6000,        // ROM6: 6000-7fff (first bank)
34   offset_rom6b_4p= 0xe000,        // ROM6: e000-ffff (second bank)
35   offset_sram_4p = 0x10000,       // scratch RAM (1 KiB)
36   offset_dram_4p = 0x10400,       // extra ram for debugger (768 bytes)
37   offset_xram_4p = 0x10700,       // extended RAM (1Mb with super AMS compatible mapper)
38   region_cpu1_len_4p = 0x110700   // total len
3939};
4040
4141enum
r8296r8297
8080/* GROM_port_t: descriptor for a port of 8 GROMs. Required by ti99_4x, ti99pcod */
8181struct _GROM_port_t
8282{
83        /* pointer to GROM data */
84        UINT8 *data_ptr;
85        /* current address pointer for the active GROM in port (16 bits) */
86        unsigned int addr;
87        /* GROM data buffer */
88        UINT8 buf;
89        /* internal flip-flops that are set after the first access to the GROM
90        address so that next access is mapped to the LSB, and cleared after each
91        data access */
92        char raddr_LSB, waddr_LSB;
83   // pointer to GROM data
84   UINT8 *data_ptr;
85   // current address pointer for the active GROM in port (16 bits)
86   unsigned int addr;
87   // GROM data buffer
88   UINT8 buf;
89   // internal flip-flops that are set after the first access to the GROM
90   // address so that next access is mapped to the LSB, and cleared after each
91   // data access
92   char raddr_LSB, waddr_LSB;
9393};
9494typedef struct _GROM_port_t GROM_port_t;
9595
r8296r8297
199199MACHINE_START( ti99_4p );
200200
201201MACHINE_RESET( ti99 );
202MACHINE_RESET( ti99_4p );
203MACHINE_RESET( ti99_8 );
202204
203205/* For HSGPL */
204206NVRAM_HANDLER( ti99 );
r8296r8297
207209/* For GRAM Kracker */
208210INPUT_CHANGED( gk_changed );
209211
212/* For EVPC */
213INPUT_CHANGED( evpc_changed );
214
210215VIDEO_START( ti99_4ev );
211216INTERRUPT_GEN( ti99_vblank_interrupt );
212217INTERRUPT_GEN( ti99_4ev_hblank_interrupt );
218TIMER_DEVICE_CALLBACK( ti99_4ev_scanline_interrupt );
213219
214220void ti99_set_hsgpl_crdena(int data);
215221void ti99_common_init(running_machine *machine, const TMS9928a_interface *gfxparm);
src/mess/drivers/ti99_8.c
r8296r8297
568568   MDRV_CPU_VBLANK_INT("screen", ti99_vblank_interrupt)
569569
570570   MDRV_MACHINE_START( ti99_8_60hz )
571   MDRV_MACHINE_RESET( ti99 )
571   MDRV_MACHINE_RESET( ti99_8 )
572572
573573   /* For HSGPL */
574574   MDRV_NVRAM_HANDLER( ti99 )
r8296r8297
624624   MDRV_CPU_VBLANK_INT("screen", ti99_vblank_interrupt)
625625
626626   MDRV_MACHINE_START( ti99_8_50hz )
627   MDRV_MACHINE_RESET( ti99 )
627   MDRV_MACHINE_RESET( ti99_8 )
628628
629629   /* video hardware */
630630   MDRV_IMPORT_FROM(tms9928a)
src/mess/drivers/ti99_4p.c
r8296r8297
3434    If you use memory view in the debugger, it crashes at 6000 and some higher addresses. This is
3535    because the memory map has references to GROM handlers.
3636
37    2010-06-19
38    MZ: Driver fixed
39    Important: The SGCPU card relies on a properly set up HSGPL flash memory
40    card; without, it will immediately lock up. It is impossible to set it up
41    from here (a bootstrap problem; you cannot start without the HSGPL).
42    The best chance is to start a ti99_4ev, activate the
43    HSGPL, and go through the setup process there. Copy the hsgpl.nv into this
44    driver's nvram subdirectory. The contents will be directly usable for the SGCPU.
3745*/
3846
3947#include "emu.h"
r8296r8297
6068#include "devices/ti99_hd.h"
6169#include "machine/idectrl.h"
6270#include "machine/smc92x4.h"
71#include "machine/mm58274c.h"
6372#include "machine/rtc65271.h"
6473#include "formats/ti99_dsk.h"
6574
6675
6776static ADDRESS_MAP_START(memmap, ADDRESS_SPACE_PROGRAM, 16)
68   AM_RANGE(0x0000, 0x1fff) AM_ROMBANK("bank1")                        /*system ROM*/
69   AM_RANGE(0x2000, 0x2fff) AM_RAMBANK("bank3")                        /*lower 8kb of RAM extension: AMS bank 2*/
70   AM_RANGE(0x3000, 0x3fff) AM_RAMBANK("bank4")                        /*lower 8kb of RAM extension: AMS bank 3*/
71   AM_RANGE(0x4000, 0x5fff) AM_READWRITE(ti99_4p_peb_r, ti99_4p_peb_w)   /*DSR ROM space*/
72   AM_RANGE(0x6000, 0x7fff) AM_READWRITE(ti99_4p_cart_r,ti99_4p_cart_w)/*cartridge space (internal or hsgpl)*/
73   AM_RANGE(0x8000, 0x83ff) AM_RAMBANK("bank2")                        /*RAM PAD*/
74   AM_RANGE(0x8400, 0x87ff) AM_READWRITE(ti99_nop_8_r, ti99_wsnd_w)   /*soundchip write*/
75   AM_RANGE(0x8800, 0x8bff) AM_READWRITE(ti99_rv38_r, ti99_nop_8_w)   /*vdp read*/
76   AM_RANGE(0x8C00, 0x8fff) AM_READWRITE(ti99_nop_8_r, ti99_wv38_w)   /*vdp write*/
77   AM_RANGE(0x9000, 0x93ff) AM_READWRITE(ti99_nop_8_r, ti99_nop_8_w)   /*speech read - installed dynamically*/
78   AM_RANGE(0x9400, 0x97ff) AM_READWRITE(ti99_nop_8_r, ti99_nop_8_w)   /*speech write - installed dynamically*/
79   AM_RANGE(0x9800, 0x98ff) AM_READWRITE(ti99_4p_grom_r, ti99_nop_8_w)   /*GPL read*/
80   AM_RANGE(0x9900, 0x9bff) AM_RAMBANK("bank11")                        /*extra RAM for debugger*/
81   AM_RANGE(0x9c00, 0x9fff) AM_READWRITE(ti99_nop_8_r, ti99_4p_grom_w)   /*GPL write*/
82   AM_RANGE(0xa000, 0xafff) AM_RAMBANK("bank5")                        /*upper 24kb of RAM extension: AMS bank 10*/
83   AM_RANGE(0xb000, 0xbfff) AM_RAMBANK("bank6")                        /*upper 24kb of RAM extension: AMS bank 11*/
84   AM_RANGE(0xc000, 0xcfff) AM_RAMBANK("bank7")                        /*upper 24kb of RAM extension: AMS bank 12*/
85   AM_RANGE(0xd000, 0xdfff) AM_RAMBANK("bank8")                        /*upper 24kb of RAM extension: AMS bank 13*/
86   AM_RANGE(0xe000, 0xefff) AM_RAMBANK("bank9")                        /*upper 24kb of RAM extension: AMS bank 14*/
87   AM_RANGE(0xf000, 0xffff) AM_RAMBANK("bank10")                        /*upper 24kb of RAM extension: AMS bank 15*/
77   AM_RANGE(0x0000, 0x1fff) AM_ROMBANK("bank1")                         // system ROM
78   AM_RANGE(0x2000, 0x2fff) AM_RAMBANK("bank3")                         // lower 8kb of RAM extension: AMS bank 2
79   AM_RANGE(0x3000, 0x3fff) AM_RAMBANK("bank4")                         // lower 8kb of RAM extension: AMS bank 3
80   AM_RANGE(0x4000, 0x5fff) AM_READWRITE(ti99_4p_peb_r, ti99_4p_peb_w)    // DSR ROM space
81   AM_RANGE(0x6000, 0x7fff) AM_READWRITE(ti99_4p_cart_r,ti99_4p_cart_w) // cartridge space (internal or hsgpl)
82   AM_RANGE(0x8000, 0x83ff) AM_RAMBANK("bank2")                         // RAM PAD
83   AM_RANGE(0x8400, 0x87ff) AM_READWRITE(ti99_nop_8_r, ti99_wsnd_w)     // soundchip write
84   AM_RANGE(0x8800, 0x8bff) AM_READWRITE(ti99_rv38_r, ti99_nop_8_w)     // vdp read
85   AM_RANGE(0x8C00, 0x8fff) AM_READWRITE(ti99_nop_8_r, ti99_wv38_w)     // vdp write
86   AM_RANGE(0x9000, 0x93ff) AM_READWRITE(ti99_nop_8_r, ti99_nop_8_w)    // speech read - installed dynamically
87   AM_RANGE(0x9400, 0x97ff) AM_READWRITE(ti99_nop_8_r, ti99_nop_8_w)    // speech write - installed dynamically*/
88   AM_RANGE(0x9800, 0x98ff) AM_READWRITE(ti99_4p_grom_r, ti99_nop_8_w)  // GPL read
89   AM_RANGE(0x9900, 0x9bff) AM_RAMBANK("bank11")                        // extra RAM for debugger
90   AM_RANGE(0x9c00, 0x9fff) AM_READWRITE(ti99_nop_8_r, ti99_4p_grom_w)  // GPL write
91   AM_RANGE(0xa000, 0xafff) AM_RAMBANK("bank5")                         // upper 24kb of RAM extension: AMS bank 10
92   AM_RANGE(0xb000, 0xbfff) AM_RAMBANK("bank6")                         // upper 24kb of RAM extension: AMS bank 11
93   AM_RANGE(0xc000, 0xcfff) AM_RAMBANK("bank7")                         // upper 24kb of RAM extension: AMS bank 12
94   AM_RANGE(0xd000, 0xdfff) AM_RAMBANK("bank8")                         // upper 24kb of RAM extension: AMS bank 13
95   AM_RANGE(0xe000, 0xefff) AM_RAMBANK("bank9")                         // upper 24kb of RAM extension: AMS bank 14
96   AM_RANGE(0xf000, 0xffff) AM_RAMBANK("bank10")                        // upper 24kb of RAM extension: AMS bank 15
8897ADDRESS_MAP_END
8998
9099static ADDRESS_MAP_START(cru_map, ADDRESS_SPACE_IO, 8)
r8296r8297
121130   PORT_START( "HDCTRL" )
122131   PORT_CONFNAME( 0x03, 0x00, "HD controller" )
123132      PORT_CONFSETTING(    0x00, DEF_STR( None ) )
124//      PORT_CONFSETTING(    0x01, "Nouspikel IDE Controller" )
133//      PORT_CONFSETTING(    0x01, "Nouspikel IDE Controller" )
125134//      PORT_CONFSETTING(    0x02, "WHTech SCSI Controller" )
126135   PORT_CONFNAME( 0x08, 0x00, "USB-SM card" )
127136      PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
r8296r8297
137146      PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
138147      PORT_CONFSETTING(    0x04, DEF_STR( On ) )
139148
140   PORT_START( "HCI" )
141   PORT_CONFNAME( 0x01, 0x00, "Mouse support" )
142      PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
143      PORT_CONFSETTING(    0x01, "Mechatronics Mouse" )
144
145149   PORT_START( "HFDCDIP" )
146150   PORT_DIPNAME( 0xff, 0x55, "HFDC drive config" ) PORT_CONDITION( "DISKCTRL", 0x07, PORTCOND_EQUALS, 0x03 )
147151      PORT_DIPSETTING( 0x00, "40 track, 16 ms")
r8296r8297
154158      PORT_CONFSETTING( 0x00, "No delay")
155159      PORT_CONFSETTING( 0x01, "Realistic")
156160
161   PORT_START( "EVPC-SW1" )
162   PORT_DIPNAME( 0x01, 0x00, "EVPC video mode" ) PORT_CONDITION( "EVPC-SW8", 0x01, PORTCOND_EQUALS, 0x00 ) PORT_CHANGED( evpc_changed, (void *)0)
163      PORT_DIPSETTING(    0x00, "PAL" )
164      PORT_DIPSETTING(    0x01, "NTSC" )
165
166   PORT_START( "EVPC-SW3" )
167   PORT_DIPNAME( 0x01, 0x00, "EVPC charset" ) PORT_CONDITION( "EVPC-SW8", 0x01, PORTCOND_EQUALS, 0x00 ) PORT_CHANGED( evpc_changed, (void *)1)
168      PORT_DIPSETTING(    0x00, DEF_STR( International ))
169      PORT_DIPSETTING(    0x01, DEF_STR( German ))
170
171   PORT_START( "EVPC-SW4" )
172   PORT_DIPNAME( 0x01, 0x00, "EVPC VDP RAM" ) PORT_CONDITION( "EVPC-SW8", 0x01, PORTCOND_EQUALS, 0x00 ) PORT_CHANGED( evpc_changed, (void *)2)
173      PORT_DIPSETTING(    0x00, "shifted" )
174      PORT_DIPSETTING(    0x01, "not shifted" )
175
176   PORT_START( "EVPC-SW8" )
177   PORT_DIPNAME( 0x01, 0x00, "EVPC Configuration" ) PORT_CHANGED( evpc_changed, (void *)3)
178      PORT_DIPSETTING(    0x00, "DIP" )
179      PORT_DIPSETTING(    0x01, "NOVRAM" )
180
157181   /* 3 ports for mouse */
158182   PORT_START("MOUSEX") /* Mouse - X AXIS */
159183      PORT_BIT( 0xff, 0x00, IPT_TRACKBALL_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1)
r8296r8297
261285#endif
262286};
263287
288/* F4 Character Displayer */
289static const gfx_layout ti99_6_charlayout =
290{
291   8, 6,               /* 8 x 6 characters */
292   64,               /* 64 characters */
293   1,               /* 1 bits per pixel */
294   { 0 },               /* no bitplanes */
295   /* x offsets */
296   { 0, 1, 2, 3, 4, 5, 6, 7 },
297   /* y offsets */
298   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8 },
299   8*6               /* every char takes 6 bytes */
300};
301
302static const gfx_layout ti99_7_charlayout =
303{
304   8, 7,               /* 8 x 7 characters */
305   95,               /* 95 characters */
306   1,               /* 1 bits per pixel */
307   { 0 },               /* no bitplanes */
308   /* x offsets */
309   { 0, 1, 2, 3, 4, 5, 6, 7 },
310   /* y offsets */
311   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8 },
312   8*7               /* every char takes 7 bytes */
313};
314
315static const gfx_layout ti99_8_charlayout =
316{
317   8, 8,               /* 8 x 8 characters */
318   64,               /* 64 characters */
319   1,               /* 1 bits per pixel */
320   { 0 },               /* no bitplanes */
321   /* x offsets */
322   { 0, 1, 2, 3, 4, 5, 6, 7 },
323   /* y offsets */
324   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
325   8*8               /* every char takes 8 bytes */
326};
327
328static const gfx_layout ti99_c_charlayout =
329{
330   8, 8,               /* 8 x 8 characters */
331   1,               /* 1 characters */
332   1,               /* 1 bits per pixel */
333   { 0 },               /* no bitplanes */
334   /* x offsets */
335   { 0, 1, 2, 3, 4, 5, 6, 7 },
336   /* y offsets */
337   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
338   8*8               /* every char takes 8 bytes */
339};
340
341static const gfx_layout ti99_24_charlayout =
342{
343   24, 24,               /* 24 x 24 characters */
344   1,               /* 1 characters */
345   1,               /* 1 bits per pixel */
346   { 0 },               /* no bitplanes */
347   /* x offsets */
348   { 0, 1, 2, 3, 4, 5, 6, 7, 64, 65, 66, 67, 68, 69, 70, 71, 128, 129, 130, 131, 132, 133, 134, 135 },
349   /* y offsets */
350   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8, 24*8, 25*8, 26*8, 27*8, 28*8, 29*8, 30*8, 31*8, 48*8, 49*8, 50*8, 51*8, 52*8, 53*8, 54*8, 55*8 },
351   24*24               /* every char takes 72 bytes */
352};
353
354static GFXDECODE_START( ti99b )
355   GFXDECODE_ENTRY( region_grom, 0x04b4, ti99_8_charlayout, 2, 2 )
356   GFXDECODE_ENTRY( region_grom, 0x06b4, ti99_7_charlayout, 2, 2 )
357   GFXDECODE_ENTRY( region_grom, 0x0950, ti99_24_charlayout, 2, 2 )
358   GFXDECODE_ENTRY( region_grom, 0x0998, ti99_c_charlayout, 2, 2 )
359GFXDECODE_END
360
264361/*
265362    We use a DAC to emulate "audio gate", even though
266363    a) there was no DAC in an actual TI99
r8296r8297
279376   DO_NOT_KEEP_GEOMETRY
280377};
281378
379static const mm58274c_interface floppy_mm58274c_interface =
380{
381   1,   /*  mode 24*/
382   0   /*  first day of week */
383};
384
282385/*
283386    Machine description.
284387*/
r8296r8297
288391   MDRV_CPU_ADD("maincpu", TMS9900, 3000000)
289392   MDRV_CPU_PROGRAM_MAP(memmap)
290393   MDRV_CPU_IO_MAP(cru_map)
291   MDRV_CPU_VBLANK_INT_HACK(ti99_4ev_hblank_interrupt, 263)   /* 262.5 in 60Hz, 312.5 in 50Hz */
292394
395   // MZ: Changed 263 to 262 to avoid blank image on startup
396   // The issue is somehow related to changing VReg 9 to 0 in an unconvenient situation
397   // but I could not identify it more closely. Seems to happen in v9938_interrupt.
398   MDRV_CPU_VBLANK_INT_HACK(ti99_4ev_hblank_interrupt, 262)   /* 262.5 in 60Hz, 312.5 in 50Hz */
399
293400   MDRV_MACHINE_START( ti99_4p )
294   MDRV_MACHINE_RESET( ti99 )
401   MDRV_MACHINE_RESET( ti99_4p )
295402
296403   /* For HSGPL */
297404   MDRV_NVRAM_HANDLER( ti99 )
r8296r8297
304411   MDRV_SCREEN_SIZE(512+32, (212+28)*2)
305412   MDRV_SCREEN_VISIBLE_AREA(0, 512+32 - 1, 0, (212+28)*2 - 1)
306413
414// Didn't work, probably just done wrong by me:
415//  MDRV_TIMER_ADD_SCANLINE("v9938_scanline", ti99_4ev_scanline_interrupt , "screen", 0, 1)
416
307417   MDRV_PALETTE_LENGTH(512)
308418
309419   MDRV_PALETTE_INIT(v9938)
310420   MDRV_VIDEO_START(ti99_4ev)
311421   MDRV_VIDEO_UPDATE(generic_bitmapped)
422   MDRV_GFXDECODE(ti99b)
312423
313424   /* sound hardware */
314425   MDRV_SPEAKER_STANDARD_MONO("mono")
r8296r8297
323434   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
324435
325436   /* devices */
326/*   MDRV_IDE_CONTROLLER_ADD( "ide", ti99_ide_interrupt )
327   MDRV_RTC65271_ADD("ide_rtc", ti99_clk_interrupt_callback) */
437/*  MDRV_IDE_CONTROLLER_ADD( "ide", ti99_ide_interrupt )
438    MDRV_RTC65271_ADD("ide_rtc", ti99_clk_interrupt_callback) */
328439
329440   MDRV_CASSETTE_ADD( "cassette", default_cassette_config )
330441
r8296r8297
332443   MDRV_TMS9901_ADD("tms9901", tms9901reset_param_ti99_4x)
333444
334445   MDRV_WD179X_ADD("wd179x", ti99_wd17xx_interface )
446
447   /* rtc */
448   MDRV_MM58274C_ADD("mm58274c_floppy", floppy_mm58274c_interface)
449
335450   MDRV_SMC92X4_ADD("smc92x4", ti99_smc92x4_interface )
336451
337452   MDRV_FLOPPY_4_DRIVES_ADD(ti99_4p_floppy_config)
r8296r8297
369484ROM_END
370485
371486/*    YEAR  NAME      PARENT   COMPAT   MACHINE      INPUT    INIT      COMPANY     FULLNAME */
372COMP( 1996, ti99_4p,  0,      0,      ti99_4p_60hz, ti99_4p, ti99_4p, "System 99 Users Group",      "SGCPU (a.k.a. 99/4P)" , GAME_NOT_WORKING )
487COMP( 1996, ti99_4p,  0,      0,      ti99_4p_60hz, ti99_4p, ti99_4p, "System 99 Users Group",      "SGCPU (a.k.a. 99/4P)" , 0 )
src/mess/drivers/ti99_4x.c
r8296r8297
300300
301301INPUT_PORTS_END
302302
303/*
304    Input ports for the TI-99/4A with EPVC
305    Same as above, but with some additional dip switches
306*/
307static INPUT_PORTS_START(ti99_4ev)
308   PORT_INCLUDE(ti99_4a)
309   PORT_START( "EVPC-SW1" )
310   PORT_DIPNAME( 0x01, 0x00, "EVPC video mode" ) PORT_CONDITION( "EVPC-SW8", 0x01, PORTCOND_EQUALS, 0x00 ) PORT_CHANGED( evpc_changed, (void *)0)
311      PORT_DIPSETTING(    0x00, "PAL" )
312      PORT_DIPSETTING(    0x01, "NTSC" )
303313
314   PORT_START( "EVPC-SW3" )
315   PORT_DIPNAME( 0x01, 0x00, "EVPC charset" ) PORT_CONDITION( "EVPC-SW8", 0x01, PORTCOND_EQUALS, 0x00 ) PORT_CHANGED( evpc_changed, (void *)1)
316      PORT_DIPSETTING(    0x00, DEF_STR( International ))
317      PORT_DIPSETTING(    0x01, DEF_STR( German ))
318
319   PORT_START( "EVPC-SW4" )
320   PORT_DIPNAME( 0x01, 0x00, "EVPC VDP RAM" ) PORT_CONDITION( "EVPC-SW8", 0x01, PORTCOND_EQUALS, 0x00 ) PORT_CHANGED( evpc_changed, (void *)2)
321      PORT_DIPSETTING(    0x00, "shifted" )
322      PORT_DIPSETTING(    0x01, "not shifted" )
323
324   PORT_START( "EVPC-SW8" )
325   PORT_DIPNAME( 0x01, 0x00, "EVPC Configuration" ) PORT_CHANGED( evpc_changed, (void *)3)
326      PORT_DIPSETTING(    0x00, "DIP" )
327      PORT_DIPSETTING(    0x01, "NOVRAM" )
328
329INPUT_PORTS_END
330
304331#define JOYSTICK_DELTA         10
305332#define JOYSTICK_SENSITIVITY   100
306333
r8296r8297
856883   MDRV_MACHINE_START( ti99_4a_60hz )
857884   MDRV_MACHINE_RESET( ti99 )
858885
859   /* For HSGPL */
886   /* For HSGPL and EVPC */
860887   MDRV_NVRAM_HANDLER( ti99 )
861888
862889   /* video hardware */
r8296r8297
968995   MDRV_CPU_ADD("maincpu", TMS9900, 3000000)
969996   MDRV_CPU_PROGRAM_MAP(memmap_4ev)
970997   MDRV_CPU_IO_MAP(cru_map)
971   MDRV_CPU_VBLANK_INT_HACK(ti99_4ev_hblank_interrupt, 263)   /* 262.5 in 60Hz, 312.5 in 50Hz */
998   MDRV_CPU_VBLANK_INT_HACK(ti99_4ev_hblank_interrupt, 262)   /* 262.5 in 60Hz, 312.5 in 50Hz */
972999
9731000   MDRV_MACHINE_START( ti99_4ev_60hz )
9741001   MDRV_MACHINE_RESET( ti99 )
r8296r8297
9841011   MDRV_SCREEN_SIZE(512+32, (212+28)*2)
9851012   MDRV_SCREEN_VISIBLE_AREA(0, 512+32 - 1, 0, (212+28)*2 - 1)
9861013
1014//  MDRV_TIMER_ADD_SCANLINE("v9938_scanline", ti99_4ev_scanline_interrupt , "screen", 1, 1)
1015
9871016   MDRV_PALETTE_LENGTH(512)
9881017
9891018   MDRV_PALETTE_INIT(v9938)
r8296r8297
11301159COMP( 1980, ti99_4e,  ti99_4,  0,      ti99_4_50hz,  ti99_4,  ti99_4,   "Texas Instruments", "TI99/4 Home Computer (Europe)" , 0)
11311160COMP( 1981, ti99_4a,  0,      0,      ti99_4a_60hz, ti99_4a, ti99_4a,   "Texas Instruments", "TI99/4A Home Computer (US)" , 0)
11321161COMP( 1981, ti99_4ae, ti99_4a, 0,      ti99_4a_50hz, ti99_4a, ti99_4a,   "Texas Instruments", "TI99/4A Home Computer (Europe)" , 0)
1133COMP( 1994, ti99_4ev, ti99_4a, 0,      ti99_4ev_60hz,ti99_4a, ti99_4ev,"Texas Instruments", "TI99/4A Home Computer with EVPC" , 0)
1162COMP( 1994, ti99_4ev, ti99_4a, 0,      ti99_4ev_60hz,ti99_4ev, ti99_4ev,"Texas Instruments", "TI99/4A Home Computer with EVPC" , 0)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team