Previous 15994 Revisions Next

r9499 Monday 1st November, 2010 at 16:08:55 UTC by Michael Zapf
srccleaned files, removed some debug printfs
[src/mess/machine/ti99]bwg.c bwg.h crubus.c crubus.h datamux.c datamux.h evpc.c evpc.h genboard.c genboard.h grom.c grom.h gromport.c gromport.h handset.c handset.h hfdc.c hfdc.h hsgpl.c hsgpl.h mapper8.c mapper8.h mecmouse.c myarcmem.c p_code.c p_code.h peribox.c peribox.h samsmem.c sgcpu.c sgcpu.h spchsyn.c speech8.c speech8.h ti32kmem.c ti_fdc.c ti_fdc.h ti_rs232.c tiboard.c tiboard.h tn_ide.c tn_usbsm.c videowrp.c videowrp.h

src/mess/machine/ti99/crubus.c
r9498r9499
11/*
2   TI-99 CRU Bus       
2    TI-99 CRU Bus
33*/
44
55#include "emu.h"
r9498r9499
1010typedef struct _crubus_dev
1111{
1212   /* The device. */
13   running_device       *device;
13   running_device      *device;
1414
1515   /* Read access. */
1616   cru_read_function   cru_read;
r9498r9499
1919   cru_write_function   cru_write;
2020
2121   /* Address bits involved. The CRU makes use of the address bus. */
22   UINT16         address_mask;
22   UINT16         address_mask;
2323
2424   /* Value of the address bits which are involved for selecting for read. */
2525   UINT16         select;
r9498r9499
4444{
4545   crubus_state *crubus = get_safe_token(device);
4646   int index = crubus->devindex++;
47//   logerror("register cru device %lx\n", (long unsigned int)crudev);
47//  logerror("register cru device %lx\n", (long unsigned int)crudev);
4848   if (index < MAXCRU)
4949   {
5050      if (crubus->component[index].device == NULL)
r9498r9499
6666{
6767   crubus_state *crubus = get_safe_token(device);
6868   UINT8 reply = 0;
69   
69
7070   for (int i=0; i < MAXCRU; i++)
7171   {
7272      crubus_dev *crudev = &crubus->component[i];
r9498r9499
7676         {
7777            if (((offset<<4) & crudev->address_mask)==crudev->select)
7878            {
79               // CRU read is implemented as an 8-bit read access.
79               // CRU read is implemented as an 8-bit read access.
8080               // We shift the address for the sake of readability
8181               // Each read access returns 8 consecutive CRU bits
8282               // Shift 4 = addr*8*2
r9498r9499
8585         }
8686      }
8787   }
88//   printf("cru read %04x = %02x\n", offset<<4, reply);   
88//  printf("cru read %04x = %02x\n", offset<<4, reply);
8989
9090   return reply;
9191}
r9498r9499
9494{
9595   crubus_state *crubus = get_safe_token(device);
9696
97//   printf("cru write %04x = %02x\n", offset<<1, data);   
97//  printf("cru write %04x = %02x\n", offset<<1, data);
9898   for (int i=0; i < MAXCRU; i++)
9999   {
100100      crubus_dev *crudev = &crubus->component[i];
r9498r9499
104104         {
105105            if (((offset<<1) & crudev->address_mask)==crudev->select)
106106            {
107               // CRU write is implemented as a 1-bit access
107               // CRU write is implemented as a 1-bit access
108108               crudev->cru_write(crudev->device, offset<<1, data);
109109            }
110110         }
r9498r9499
122122   int done=FALSE;
123123   cruconf_device *cons = (cruconf_device*)device->baseconfig().static_config();
124124   crubus_state *crubus = get_safe_token(device);
125   
125
126126   logerror("start CRU bus\n");
127   
127
128128   crubus->devindex = 0;
129129
130130   while (!done)
src/mess/machine/ti99/grom.c
r9498r9499
22
33    GROM emulation (aka TMC0430)
44
5    This is a preliminary implementation since it does not yet contain
6    internal timing; instead, it directly accesses the processor to
5    This is a preliminary implementation since it does not yet contain
6    internal timing; instead, it directly accesses the processor to
77    simulate wait states
88    When this will have become available, the file will be moved to the
99    general circuit collection (emu/machine)
10   
11          +----+--+----+
12      AD7 |1    G    16| Vss             
10
11          +----+--+----+
12      AD7 |1    G    16| Vss
1313      AD6 |2    R    15| GR
1414      AD5 |3    O    14| Vdd
15      AD4 |4    M    13| GRC
15      AD4 |4    M    13| GRC
1616      AD3 |5         12| M
1717      AD2 |6         11| MO
1818      AD1 |7         10| GS*
19      AD0 |8          9| Vcc
19      AD0 |8          9| Vcc
2020          +------------+
2121
2222    GR  = GROM Ready. Should be connected to processor's READY/HOLD*.
r9498r9499
2424    M   = Direction. 1=read, 0=write
2525    MO  = Mode. 1=address counter access, 0=data access
2626    GS* = GROM select. 0=select, 1=deselect
27   
28    Every GROM has an internal ID which represents the high-order three
27
28    Every GROM has an internal ID which represents the high-order three
2929    address bits. The address counter can be set to any value from 0
3030    to 0xffff; the GROM will only react if selected and if the current
3131    address counter's high-order bits match the ID of the chip.
32    Example: When the ID is 6, the GROM will react when the address
32    Example: When the ID is 6, the GROM will react when the address
3333    counter contains a value from 0xc000 to 0xdfff.
34   
34
3535    Writable GROMs are called GRAMs. Although the TI-99 systems reserve a
36    port in the memory space, no one has ever seen a GRAM circuit in the wild.
37    However, third-party products like HSGPL or GRAM Kracker simulate GRAMs
38    using conventional RAM with some addressing circuitry, usually in a custom
36    port in the memory space, no one has ever seen a GRAM circuit in the wild.
37    However, third-party products like HSGPL or GRAM Kracker simulate GRAMs
38    using conventional RAM with some addressing circuitry, usually in a custom
3939    chip.
40   
40
4141    CHECK: Reading the address increases the counter only once. The first access
4242    returns the MSB, the second (and all following accesses) return the LSB.
43   
43
4444    Michael Zapf, August 2010
45   
45
4646***************************************************************************/
4747
4848#include "emu.h"
r9498r9499
5959
6060   /* GROM data buffer. */
6161   UINT8 buffer;
62   
62
6363   /* Internal flip-flop. Used when retrieving the address counter. */
6464   UINT8 raddr_LSB;
6565
6666   /* Internal flip-flops. Used when writing the address counter.*/
6767   UINT8 waddr_LSB;
68   
68
6969   /* ID of this GROM. */
7070   UINT8 ident;
71   
71
7272   /* Pointer to the memory region contained in this GROM. */
7373   UINT8 *memptr;
74   
74
7575   /* GROM size. May be 0x1800 or 0x2000. */
76   // If the GROM has only 6 KiB, the remaining 2 KiB are filled with a
76   // If the GROM has only 6 KiB, the remaining 2 KiB are filled with a
7777   // specific byte pattern which is created by a logical OR of lower
7878   // regions
7979   int extended;
8080
81   /* Determines whether this is a GRAM. */   
81   /* Determines whether this is a GRAM. */
8282   int writable;
8383
84   /* Determines whether there is a rollover at the end of the address space. */   
84   /* Determines whether there is a rollover at the end of the address space. */
8585   int rollover;
86   
86
8787   /* Ready callback. This line is usually connected to the READY pin of the CPU. */
8888   devcb_resolved_write_line gromready;
8989};
r9498r9499
104104}
105105
106106/*
107   Indicates whether this chip will react on the next read/write data
108   access. We do not have a tri-state handling on the read handlers, so this
109   serves to avoid the read access.
107    Indicates whether this chip will react on the next read/write data
108    access. We do not have a tri-state handling on the read handlers, so this
109    serves to avoid the read access.
110110*/
111int is_selected(running_device *chip)
111int is_selected(running_device *chip)
112112{
113113   ti99grom_state *grom = get_safe_token(chip);
114114   return (((grom->address >> 13)&0x07)==grom->ident);
115115}
116116
117117/*
118   Reading from the chip. Represents an access with M=1, GS*=0. The MO bit is
119   defined by the offset (0 or 1). This is the enhanced read function with
120   Z state.
118    Reading from the chip. Represents an access with M=1, GS*=0. The MO bit is
119    defined by the offset (0 or 1). This is the enhanced read function with
120    Z state.
121121*/
122122READ8Z_DEVICE_HANDLER( ti99grom_rz )
123123{
124124   ti99grom_state *grom = get_safe_token(device);
125     
125
126126   if (offset & 2)
127127   {
128      if (((grom->address >> 13)&0x07)!=grom->ident)
128      if (((grom->address >> 13)&0x07)!=grom->ident)
129129         return;
130130
131131      /* When reading, reset the hi/lo flag byte for writing. */
r9498r9499
149149   }
150150   else
151151   {
152      if (((grom->address >> 13)&0x07)==grom->ident)
152      if (((grom->address >> 13)&0x07)==grom->ident)
153153      {
154154         /* GROMs are buffered. Data is retrieved from a buffer, */
155155         /* while the buffer is replaced with the next cell content. */
156156         *value = grom->buffer;
157         
157
158158         /* Get next value, put it in buffer. Note that the GROM */
159159         /* wraps at 8K boundaries. */
160160         UINT16 addr = grom->address-(grom->ident<<13);
161         
161
162162         if (!grom->extended && ((grom->address&0x1fff)>=0x1800))
163163            grom->buffer = grom->memptr[addr-0x1000] | grom->memptr[addr-0x0800];
164164         else
r9498r9499
176176}
177177
178178/*
179   Reading from the chip. Represents an access with M=1, GS*=0. The MO bit is
180   defined by the offset (0 or 1).
179    Reading from the chip. Represents an access with M=1, GS*=0. The MO bit is
180    defined by the offset (0 or 1).
181181*/
182182READ8_DEVICE_HANDLER( ti99grom_r )
183183{
184184   UINT8 reply = 0;
185   ti99grom_rz(device, offset, &reply);
185   ti99grom_rz(device, offset, &reply);
186186   return reply;
187187}
188188
189189
190190/*
191   Writing to the chip. Represents an access with M=0, GS*=0. The MO bit is
192   defined by the offset (0 or 1).
191    Writing to the chip. Represents an access with M=0, GS*=0. The MO bit is
192    defined by the offset (0 or 1).
193193*/
194194WRITE8_DEVICE_HANDLER( ti99grom_w )
195195{
r9498r9499
209209         /* Accept low byte (2nd write) */
210210         grom->address = (grom->address & 0xFF00) | data;
211211         /* Setting the address causes a new prefetch */
212         if (is_selected(device))
212         if (is_selected(device))
213213         {
214214            grom->buffer = grom->memptr[grom->address-(grom->ident<<13)];
215         }     
215         }
216216         grom->waddr_LSB = FALSE;
217217      }
218218      else
r9498r9499
235235            write_addr = ((grom->address + 0x1fff) & 0x1FFF) | (grom->address & 0xE000);
236236         else
237237            write_addr = (grom->address - 1) & 0xFFFF;
238         
238
239239         // UINT16 addr = grom->address-(grom->ident<<13);
240240         if (grom->extended || ((grom->address&0x1fff)<0x1800))
241241            grom->memptr[write_addr-(grom->ident<<13)] = data;
242      }     
242      }
243243      grom->raddr_LSB = grom->waddr_LSB = FALSE;
244244   }
245245
r9498r9499
260260
261261   grom->writable = gromconf->writeable;
262262   grom->ident = gromconf->ident;
263   
263
264264   grom->extended = (gromconf->size==0x1800)? TRUE : FALSE;
265265
266266   grom->rollover = gromconf->rollover;
r9498r9499
280280   const ti99grom_config* gromconf = (const ti99grom_config*)get_config(device);
281281   ti99grom_state *grom = get_safe_token(device);
282282   grom->address = 0;
283   grom->raddr_LSB = FALSE;
283   grom->raddr_LSB = FALSE;
284284   grom->waddr_LSB = FALSE;
285285   grom->buffer = 0;
286286
r9498r9499
291291      grom->memptr = memory_region(device->machine, gromconf->region);
292292
293293   //  TODO: Check whether this may be 0 for console GROMs.
294   //   assert (grom->memptr!=NULL);
294   //  assert (grom->memptr!=NULL);
295295
296296   grom->memptr += gromconf->offset;
297297
src/mess/machine/ti99/crubus.h
r9498r9499
11#ifndef __CRUBUS__
22#define __CRUBUS__
33/*
4   TI-99 CRU Bus   
5   header file for crubus   
4    TI-99 CRU Bus
5    header file for crubus
66*/
77
88typedef void (*cru_read_function)(device_t *device, offs_t offset, UINT8 *value);
r9498r9499
1010
1111typedef struct _cruconf_device
1212{
13   const char             *name;
13   const char            *name;
1414   UINT16               address_mask;
1515   UINT16               select_pattern;
16   cru_read_function       read;
17   cru_write_function       write;
16   cru_read_function      read;
17   cru_write_function      write;
1818} cruconf_device;
1919
2020READ8_DEVICE_HANDLER( ti99_crubus_r );
r9498r9499
2626#define MDRV_CRUBUS_ADD(_tag, _devices)         \
2727   MDRV_DEVICE_ADD(_tag, CRUBUS, 0) \
2828   MDRV_DEVICE_CONFIG( _devices )
29   
29
3030#endif
src/mess/machine/ti99/grom.h
r9498r9499
8181{
8282   int                  writeable;
8383   int                ident;
84   const char             *region;
84   const char            *region;
8585   UINT8               *(*get_memory)(running_device *device);
8686   offs_t               offset;
8787   int                size;
r9498r9499
107107   MDRV_DEVICE_CONFIG_DATA32(ti99grom_config, offset, _offset) \
108108   MDRV_DEVICE_CONFIG_DATA32(ti99grom_config, size, _size) \
109109   MDRV_DEVICE_CONFIG_DATA32(ti99grom_config, rollover, FALSE) \
110   MDRV_DEVICE_CONFIG_DATAPTR(ti99grom_config, ready, _ready)
110   MDRV_DEVICE_CONFIG_DATAPTR(ti99grom_config, ready, _ready)
111111
112112#define MDRV_GROM_ADD_P(_tag, _id, _memptr, _offset, _size, _ready)   \
113113   MDRV_DEVICE_ADD(_tag, GROM, 0)   \
r9498r9499
118118   MDRV_DEVICE_CONFIG_DATA32(ti99grom_config, offset, _offset) \
119119   MDRV_DEVICE_CONFIG_DATA32(ti99grom_config, size, _size) \
120120   MDRV_DEVICE_CONFIG_DATA32(ti99grom_config, rollover, FALSE) \
121   MDRV_DEVICE_CONFIG_DATAPTR(ti99grom_config, ready, _ready)
122   
121   MDRV_DEVICE_CONFIG_DATAPTR(ti99grom_config, ready, _ready)
122
123123#define MDRV_GRAM_ADD(_tag, _id, _region, _offset, _size, _rollover, _ready)      \
124124   MDRV_DEVICE_ADD(_tag, GROM, 0)                        \
125125   MDRV_DEVICE_CONFIG_DATA32(ti99grom_config, writeable, TRUE)   \
r9498r9499
128128   MDRV_DEVICE_CONFIG_DATA32(ti99grom_config, offset, _offset)    \
129129   MDRV_DEVICE_CONFIG_DATA32(ti99grom_config, size, _size)   \
130130   MDRV_DEVICE_CONFIG_DATA32(ti99grom_config, rollover, _rollover) \
131   MDRV_DEVICE_CONFIG_DATAPTR(ti99grom_config, ready, _ready)
131   MDRV_DEVICE_CONFIG_DATAPTR(ti99grom_config, ready, _ready)
132132
133133
src/mess/machine/ti99/gromport.c
r9498r9499
5353
5454   // GROM buffer size.
5555   int grom_size;
56   
56
5757   // ROM buffer size. All banks have equal sizes.
5858   int rom_size;
59   
59
6060   // RAM buffer size. All banks have equal sizes.
6161   int ram_size;
6262
63   // GROM buffer.
63   // GROM buffer.
6464   UINT8 *grom_ptr;
6565
66   // ROM buffer.
66   // ROM buffer.
6767   UINT8 *rom_ptr;
6868
6969   // ROM buffer for the second bank of paged cartridges.
r9498r9499
7272   // RAM buffer. The persistence service is done by the cartridge system.
7373   // The RAM space is a consecutive space; all banks are in one buffer.
7474   UINT8 *ram_ptr;
75   
75
7676   /* GK support. */
77   UINT16   grom_address;   
77   UINT16   grom_address;
7878   int      waddr_LSB;
7979};
8080typedef struct _cartridge_t cartridge_t;
r9498r9499
109109   // If we only have one cartridge inserted, we don't want to get a
110110   // selection option, so we just mirror the memory contents.
111111   int    next_free_slot;
112   
112
113113   /* GK support. */
114114   int      gk_slot;
115115   int      gk_guest_slot;
116   
116
117117   /* Legacy support. */
118118   // Counts the number of slots which currently contain legacy format
119119   // cartridge images.
r9498r9499
122122   // Counts the number of slots which currently contain new format
123123   // cartridge images.
124124   int multi_slots;
125   
125
126126   /* Used to cache the switch settings. */
127127   UINT8 gk_switch[8];
128128
129129   /* Ready line */
130130   devcb_resolved_write_line ready;
131   
131
132132} ti99_multicart_state;
133133
134134#define AUTO -1
r9498r9499
156156
157157   /* Function to disassemble this cartridge. */
158158   assmfct   *disassemble;
159   
159
160160   /* Points to the (max 5) GROM devices. */
161161   running_device *grom[5];
162162};
r9498r9499
189189}
190190
191191/*
192   The console writes the values in this array to cache them.
192    The console writes the values in this array to cache them.
193193*/
194194void set_gk_switches(running_device *cartsys, int number, int value)
195195{
r9498r9499
274274   ti99_multicart_state *cartslots = get_safe_token(cartsys);
275275   running_device *pcb = cartslot->subdevice("pcb");
276276   ti99_pcb_t *pcb_def;
277   
277
278278   void *socketcont;
279279   int reslength;
280//   int i;
280//  int i;
281281
282282   int slotnumber = get_index_from_tagname(cartslot)-1;
283283   assert(slotnumber>=0 && slotnumber<NUMBER_OF_CARTRIDGE_SLOTS);
r9498r9499
296296   if (socketcont != NULL)
297297   {
298298      cartridge->grom_ptr = (UINT8 *)socketcont;
299//      printf("grom_socket = %lx\n", cartridge->grom_ptr);
299//      printf("grom_socket = %lx\n", cartridge->grom_ptr);
300300      cartridge->grom_size = reslength;
301301   }
302302
r9498r9499
306306   {
307307      cartridge->rom_ptr = (UINT8 *)socketcont;
308308      cartridge->rom_size = reslength;
309//      printf("set rom ptr = %lx, romlength = %04x, data = %02x %02x\n", cartridge->rom_ptr, cartridge->rom_size, cartridge->rom_ptr[0], cartridge->rom_ptr[1]);
309//      printf("set rom ptr = %lx, romlength = %04x, data = %02x %02x\n", cartridge->rom_ptr, cartridge->rom_size, cartridge->rom_ptr[0], cartridge->rom_ptr[1]);
310310   }
311311
312312   socketcont = cartslot_get_socket(cartslot, "rom2_socket");
r9498r9499
332332   if (cartridge->grom_size > 0x4000) pcb_def->grom[2] = pcb->subdevice("grom_5");
333333   if (cartridge->grom_size > 0x6000) pcb_def->grom[3] = pcb->subdevice("grom_6");
334334   if (cartridge->grom_size > 0x8000) pcb_def->grom[4] = pcb->subdevice("grom_7");
335   
335
336336   return cartridge;
337337}
338338
r9498r9499
389389   if (cartridge->rom_ptr!=NULL)
390390   {
391391      // For TI-99/8 we should plan for 16K cartridges. However, none was produced. Well, just ignore this thought,
392      *value = (cartridge->rom_ptr)[offset & 0x1fff]; 
393//      printf("read cartridge rom space (length %04x) %04x = %02x\n", cartridge->rom_size, offset, *value);
392      *value = (cartridge->rom_ptr)[offset & 0x1fff];
393//      printf("read cartridge rom space (length %04x) %04x = %02x\n", cartridge->rom_size, offset, *value);
394394   }
395395}
396396
r9498r9499
420420{
421421   int slotnumber;
422422   int i;
423//   cartridge_t *cart;
423//  cartridge_t *cart;
424424   running_device *cartsys = image->owner();
425425   ti99_multicart_state *cartslots = get_safe_token(cartsys);
426426
r9498r9499
654654   // BNKS1   LDCR  R1,0        Switch Banks
655655   //         SRL   R0,1        Restore Bank Number (optional)
656656   //         RT
657   printf("Superspace: CRU accessed at %04x\n", offset);
657   logerror("Superspace: CRU accessed at %04x\n", offset);
658658   if ((offset & 1) == 0 || offset > 7)
659659      *value = 0;
660660
r9498r9499
669669   cartridge_t *cartridge = pcb->cartridge;
670670   // data is bit
671671   // offset is address
672   printf("Superspace: CRU accessed at %04x\n", offset);
672   logerror("Superspace: CRU accessed at %04x\n", offset);
673673   if (offset < 8)
674674   {
675675      if (data != 0)
r9498r9499
853853}
854854
855855/*
856   Determines which bank to set, depending on the size of the ROM. This is
857   some magic code that actually represents different PCB versions.
856    Determines which bank to set, depending on the size of the ROM. This is
857    some magic code that actually represents different PCB versions.
858858*/
859859static void set_paged379i_bank(cartridge_t *cartridge, int rompage)
860860{
r9498r9499
982982      if (bit != 0)
983983      {
984984         page = page-(bit/2);  // 4 page flags per 8 bits
985      }     
985      }
986986      *value = 1 << (page*2+1);
987987   }
988988}
r9498r9499
10961096******************************************************************************/
10971097
10981098/*
1099   Get the pointer to the GROM data from the cartridge. Called by the GROM.
1099    Get the pointer to the GROM data from the cartridge. Called by the GROM.
11001100*/
11011101static UINT8 *get_grom_ptr(running_device *device)
11021102{
r9498r9499
11231123      case DEVINFO_INT_INLINE_CONFIG_BYTES:
11241124         info->i = 0;
11251125         break;
1126         
1127      case DEVINFO_PTR_MACHINE_CONFIG:     
1126
1127      case DEVINFO_PTR_MACHINE_CONFIG:
11281128         info->machine_config = MACHINE_CONFIG_NAME(ti99_cart_common);
11291129         break;
11301130
r9498r9499
11911191         strcpy(info->s, "TI99 empty cartridge");
11921192         break;
11931193
1194      // Don't create GROMs
1195      case DEVINFO_PTR_MACHINE_CONFIG:     
1194      // Don't create GROMs
1195      case DEVINFO_PTR_MACHINE_CONFIG:
11961196         break;
1197         
1197
11981198      default:
11991199         DEVICE_GET_INFO_CALL(ti99_cart_common);
12001200         break;
r9498r9499
12151215         break;
12161216
12171217      case TI99CART_FCT_ASSM:
1218         info->f = (genf *) assemble_paged;
1218         info->f = (genf *) assemble_paged;
12191219         break;
12201220
12211221      case TI99CARTINFO_FCT_6000_R:
r9498r9499
12531253      case TI99CARTINFO_FCT_6000_W:
12541254         info->f = (genf *) write_cart_minimem;
12551255         break;
1256         
1256
12571257      case DEVINFO_STR_NAME:
12581258         strcpy(info->s, "TI99 MiniMemory cartridge pcb");
12591259         break;
r9498r9499
12881288         info->f = (genf *) write_cart_cru;
12891289         break;
12901290
1291      // Don't create GROMs
1292      case DEVINFO_PTR_MACHINE_CONFIG:     
1291      // Don't create GROMs
1292      case DEVINFO_PTR_MACHINE_CONFIG:
12931293         break;
12941294
12951295      case DEVINFO_STR_NAME:
r9498r9499
14461446static DEVICE_IMAGE_LOAD( ti99_cartridge )
14471447{
14481448   running_device *pcbdev = cartslot_get_pcb(&image.device());
1449//   running_device *cartsys = image.device().owner();
1450//   ti99_multicart_state *cartslots = get_safe_token(cartsys);
1449//  running_device *cartsys = image.device().owner();
1450//  ti99_multicart_state *cartslots = get_safe_token(cartsys);
14511451
14521452   int result;
14531453
r9498r9499
14861486static DEVICE_IMAGE_UNLOAD( ti99_cartridge )
14871487{
14881488   running_device *pcbdev;
1489//   ti99_multicart_state *cartslots = (ti99_multicart_state *)downcast<legacy_device_base *>(image.device().owner())->token();
1489//  ti99_multicart_state *cartslots = (ti99_multicart_state *)downcast<legacy_device_base *>(image.device().owner())->token();
14901490
14911491   if (downcast<legacy_device_base *>(&image.device())->token() == NULL)
14921492   {
r9498r9499
15531553      cartslots->cartridge[i].pcb = NULL;
15541554      clear_slot(device, i);
15551555   }
1556   
1556
15571557   devcb_write_line ready = DEVCB_LINE(cartconf->ready);
15581558
15591559   devcb_resolve_write_line(&cartslots->ready, &ready, device);
1560   
1560
15611561   // The cartslot system is initialized now. The cartridges themselves
15621562   // need to check whether their parts are available.
15631563}
r9498r9499
15951595      ti99_cart_gk_rz(device, offset, value);
15961596      return;
15971597   }
1598   
1598
15991599   /* Sanity check. Higher slots are always empty. */
16001600   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
16011601      return;
r9498r9499
16081608
16091609   if (!slot_is_empty(device, slot))
16101610   {
1611//      printf("try it on slot %d\n", slot);
1611//      printf("try it on slot %d\n", slot);
16121612      ti99_pcb_t *pcbdef = (ti99_pcb_t *)downcast<legacy_device_base *>(cart->pcb)->token();
16131613      (*pcbdef->read)(cart->pcb, offset, value);
16141614   }
r9498r9499
16601660   slot = cartslots->active_slot;
16611661
16621662   // The selection mechanism of the console checks the different GROM address
1663   // bases, and when it finds different data, it concludes that there is
1664   // indeed a multi-cartridge facility. Empty   slots return 0 at all
1663   // bases, and when it finds different data, it concludes that there is
1664   // indeed a multi-cartridge facility. Empty slots return 0 at all
16651665   // addresses.
1666   // Unfortunately, TI's cartridge selection mechanism has an undesirable
1666   // Unfortunately, TI's cartridge selection mechanism has an undesirable
16671667   // side-effect which we work around in this implementation.
16681668   // When we have only one cartridge we would like to get only the option to
16691669   // select this cartridge and not an option to switch to the next one (which
1670   // would immediately cycle back to cartridge 1). However, the console
1670   // would immediately cycle back to cartridge 1). However, the console
16711671   // routines always show the switch option when any two slots have different
16721672   // content, and this is the case with only one cartridge (slot 2 will then
16731673   // be filled with zeros).
r9498r9499
17201720   // 1001 1wbb bbbb bbr0
17211721
17221722   cartridge_slot_set(device, (UINT8)((offset>>2) & 0x00ff));
1723   
1723
17241724   // Handle the GRAM Kracker
1725   // BTW, the GK does not have a readable address counter, but the console
1725   // BTW, the GK does not have a readable address counter, but the console
17261726   // GROMs will keep our addess counter up to date. That is
17271727   // exactly what happens in the real machine.
17281728   if ((cartslots->gk_slot != -1) && (input_port_read(device->machine, "CARTSLOT")==CART_GK))
r9498r9499
17321732   }
17331733
17341734   slot = cartslots->active_slot;
1735   
1735
17361736   // This fixes a minor issue: The selection mechanism of the console
17371737   // concludes that there are multiple cartridges plugged in when it
17381738   // checks the different GROM bases and finds different data. Empty
r9498r9499
17451745   // In that case we trick the OS to believe that the addressed
17461746   // cartridge appears at all locations which causes it to assume a
17471747   // standard single cartslot.
1748   
1748
17491749   if (cartslots->fixed_slot==AUTO && cartslots->next_free_slot==1)
17501750      slot=0;
1751   
1751
17521752   if (slot < NUMBER_OF_CARTRIDGE_SLOTS)
17531753   {
17541754      // Select the cartridge which the multicart system is currently pointing at
r9498r9499
17851785      ti99_cart_cru_gk_rz(device, offset, value);
17861786      return;
17871787   }
1788   
1788
17891789   /* Sanity check. Higher slots are always empty. */
17901790   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
17911791      return;
r9498r9499
18201820      ti99_cart_cru_gk_w(device, offset, data);
18211821      return;
18221822   }
1823   
1823
18241824   /* Sanity check. Higher slots are always empty. */
18251825   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
18261826      return;
r9498r9499
18481848   06000 - 0ffff: GRAM 3-7 (alternatively, the guest GROMs appear here)
18491849   10000 - 11fff: RAM 1
18501850   12000 - 13fff: RAM 2
1851   
1851
18521852   The GK emulates GROMs, but without a readable address counter. Thus it
18531853   relies on the console GROMs being still in place (compare with the HSGPL).
18541854   Also, the GK does not implement a GROM buffer.
r9498r9499
18741874      if (get_gk_switch(cartsys, 2)==GK_GRAM0)
18751875         *value = (gromkrackerbox->ram_ptr)[gromkrackerbox->grom_address];
18761876   }
1877   
1877
18781878   if ((gromkrackerbox->grom_address & 0xe000) == 0x2000)
18791879   {
18801880      // If the loader is turned on, return loader contents.
r9498r9499
18991899         *value = (gromkrackerbox->ram_ptr)[gromkrackerbox->grom_address];
19001900   }
19011901
1902   if (((gromkrackerbox->grom_address & 0xe000) == 0x6000) ||
1902   if (((gromkrackerbox->grom_address & 0xe000) == 0x6000) ||
19031903      ((gromkrackerbox->grom_address & 0x8000) == 0x8000))
19041904   {
19051905      // Cartridge space
19061906      // When a cartridge is installed, it overrides the GK contents
1907      // but only if it has GROMs     
1907      // but only if it has GROMs
19081908      int cartwithgrom = FALSE;
19091909      gkguestcart = &cartslots->cartridge[cartslots->gk_guest_slot];
19101910
r9498r9499
19231923      }
19241924      if (!cartwithgrom && get_gk_switch(cartsys, 1)==GK_NORMAL)
19251925      {
1926         *value = (gromkrackerbox->ram_ptr)[gromkrackerbox->grom_address];         
1926         *value = (gromkrackerbox->ram_ptr)[gromkrackerbox->grom_address];
19271927      }
19281928   }
19291929
r9498r9499
19491949
19501950   if ((offset & 0x0002)==0x0002)
19511951   {
1952      // Set address     
1952      // Set address
19531953      if (gromkrackerbox->waddr_LSB)
19541954      {
19551955         /* Accept low byte (2nd write) */
r9498r9499
19721972            || (((gromkrackerbox->grom_address & 0xe000)==0x2000) && get_gk_switch(cartsys, 3)==GK_GRAM12 && (get_gk_switch(cartsys, 5)==GK_LDOFF))
19731973            || (((gromkrackerbox->grom_address & 0xe000)==0x4000) && get_gk_switch(cartsys, 3)==GK_GRAM12)
19741974            || (((gromkrackerbox->grom_address & 0xe000)==0x6000) && get_gk_switch(cartsys, 1)==GK_NORMAL && (cartslots->gk_guest_slot==-1))
1975            || (((gromkrackerbox->grom_address & 0x8000)==0x8000) && get_gk_switch(cartsys, 1)==GK_NORMAL && (cartslots->gk_guest_slot==-1)))
1975            || (((gromkrackerbox->grom_address & 0x8000)==0x8000) && get_gk_switch(cartsys, 1)==GK_NORMAL && (cartslots->gk_guest_slot==-1)))
19761976         {
19771977            (gromkrackerbox->ram_ptr)[gromkrackerbox->grom_address] = data;
19781978         }
19791979      }
19801980      // The GK GROM emulation does not wrap at 8K boundaries.
19811981      gromkrackerbox->grom_address = (gromkrackerbox->grom_address+1) & 0xffff;
1982     
1982
19831983      /* Reset the write address flipflop. */
19841984      gromkrackerbox->waddr_LSB = FALSE;
19851985   }
src/mess/machine/ti99/hsgpl.c
r9498r9499
11/*
22    SNUG HSGPL card emulation.
33    Raphael Nabet, 2003.
4   
4
55    Rewritten as device
66    Michael Zapf, October 2010
77*/
r9498r9499
8181    Note: Writing only works for areas set up as RAM.  To write to the
8282        FEEPROMs, you must used the algorithm specified by their respective
8383        manufacturer.
84       
84
8585    FIXME: Crashes when a cartridge is plugged in
8686*/
8787
8888#define CRU_BASE 0x1B00
8989
9090#define RAMSIZE       0x020000
91#define GRAMSIZE       0x020000
91#define GRAMSIZE      0x020000
9292#define FEEPROM_SIZE   0x80000
93#define FLROMSIZE    4*(FEEPROM_SIZE+2) + 1
93#define FLROMSIZE   4*(FEEPROM_SIZE+2) + 1
9494
9595#define NVVERSION 0
9696
r9498r9499
102102   UINT8   *ram6;
103103   UINT8   *gram;
104104   UINT8   *flashrom;
105   
105
106106   int    current_grom_port;
107   
107
108108   int      dsr_enabled;
109109   int      gram_enabled;
110110   int      bank_enabled;
r9498r9499
115115   int      led_on;
116116   int      mbx_enabled;
117117   int      ram_enabled;
118   
118
119119   int      flash_mode;
120   
120
121121   int      current_bank;
122   
122
123123   /* GROM emulation */
124124   int      raddr_LSB, waddr_LSB;
125125   int      grom_address;
126   
126
127127} hsgpl_state;
128128
129129INLINE hsgpl_state *get_safe_token(running_device *device)
r9498r9499
210210
211211   //activecpu_adjust_icount(-4);
212212
213   // 1001 10bb bbbb bba0
213   // 1001 10bb bbbb bba0
214214   port = card->current_grom_port = (offset & 0x3fc) >> 2;
215215
216216   if (offset & 2)
r9498r9499
237237         {
238238            *value = card->gram[card->grom_address + 0x10000*port];
239239         }
240         else
240         else
241241         {
242242            if (port < 8)
243243            {
r9498r9499
252252               {
253253                  *value = at29c040a_r(card->gromb, card->grom_address + 0x10000*(port-8));
254254               }
255               else
255               else
256256               {
257257                  if (port < 24)
258258                  {
r9498r9499
265265                        /* The HSGPL manual says 32-47, but this is incorrect */
266266                        *value = at29c040a_r(card->rom6, card->grom_address + 0x10000*(port-24));
267267                     }
268                     else
268                     else
269269                     {
270270                        if (port==32 || port==33)
271271                        {
r9498r9499
289289         }
290290      }
291291      // The address auto-increment should be done even when the card is
292      // offline     
292      // offline
293293      card->grom_address++;
294294      card->raddr_LSB = card->waddr_LSB = FALSE;
295295   }
r9498r9499
305305
306306   //activecpu_adjust_icount(-4);
307307
308   // 1001 11bb bbbb bba0
308   // 1001 11bb bbbb bba0
309309   port = card->current_grom_port = (offset & 0x3fc) >> 2;
310310
311311   if (offset & 2)
r9498r9499
325325      }
326326   }
327327   else
328   {   
328   {
329329      if (card->card_enabled)
330330      {
331331         /* write GPL data */
r9498r9499
347347                  {
348348                     at29c040a_w(card->gromb, card->grom_address + 0x10000*(port-8), data);
349349                  }
350                  else
350                  else
351351                  {
352352                     if (port < 24)
353353                     {
r9498r9499
360360                           /* The HSGPL manual says 32-47, but this is incorrect */
361361                           at29c040a_w(card->rom6, card->grom_address + 0x10000*(port-24), data);
362362                        }
363                        else
363                        else
364364                        {
365365                           if (port==32 || port==33)
366366                           {
r9498r9499
397397   if (card->dsr_enabled)
398398   {
399399      *value = at29c040a_r(card->dsr, (offset-0x4000) + 0x2000 * card->dsr_page);
400//      logerror("hsgpl: read dsr %04x[%02x] -> %02x\n", offset, card->dsr_page, *value);
400//      logerror("hsgpl: read dsr %04x[%02x] -> %02x\n", offset, card->dsr_page, *value);
401401   }
402402}
403   
403
404404static READ8Z_DEVICE_HANDLER ( hsgpl_cartspace_rz )
405405{
406406   hsgpl_state *card = get_safe_token(device);
407407
408408   if (!card->card_enabled || card->flash_mode)
409409   {
410//      logerror("hsgpl cart read ignored (enable=%02x)\n", card->card_enabled);       
410//      logerror("hsgpl cart read ignored (enable=%02x)\n", card->card_enabled);
411411      return;
412412   }
413413
r9498r9499
416416   if ((port < 2) && (card->ram_enabled))
417417   {
418418      *value = card->ram6[(offset-0x6000) + 0x2000*card->current_bank + 0x8000*port];
419//      logerror("hsgpl cart ram read %04x -> %02x\n", offset, *value);
419//      logerror("hsgpl cart ram read %04x -> %02x\n", offset, *value);
420420      return;
421421   }
422422
423423   if (port < 16)
424424   {
425425      *value = at29c040a_r(card->rom6, (offset-0x6000) + 0x2000*card->current_bank + 0x8000*port);
426//      logerror("hsgpl cart read %04x -> %02x\n", offset, *value);
426//      logerror("hsgpl cart read %04x -> %02x\n", offset, *value);
427427   }
428428   else
429429   {
r9498r9499
441441static WRITE8_DEVICE_HANDLER ( hsgpl_cartspace_w )
442442{
443443   hsgpl_state *card = get_safe_token(device);
444   
444
445445   if (!card->card_enabled || card->flash_mode)
446446   {
447      logerror("hsgpl cart write ignored: card_enabled=%02x\n", card->card_enabled);       
447      logerror("hsgpl cart write ignored: card_enabled=%02x\n", card->card_enabled);
448448      return;
449449   }
450   
450
451451   int port = card->current_grom_port;
452//   logerror("hsgpl cart write %04x -> %02x\n", offset, data);       
452//  logerror("hsgpl cart write %04x -> %02x\n", offset, data);
453453
454   if (card->bank_enabled)
454   if (card->bank_enabled)
455455   {
456456      card->current_bank = (offset>>1) & 3;
457//      logerror("hsgpl cart select bank %02x\n", card->current_bank);       
457//      logerror("hsgpl cart select bank %02x\n", card->current_bank);
458458      return;      /* right??? */
459459   }
460460
r9498r9499
481481         // feeprom is normally written to using GPL ports, and I don't know
482482         // writing through >6000 page is enabled
483483/*
484         at29c040a_w(feeprom_rom6, 1 + 2*offset + 0x2000*hsgpl.cur_bank + 0x8000*port, data);
485         at29c040a_w(feeprom_rom6, 2*offset + 0x2000*hsgpl.cur_bank + 0x8000*port, data >> 8);
484            at29c040a_w(feeprom_rom6, 1 + 2*offset + 0x2000*hsgpl.cur_bank + 0x8000*port, data);
485            at29c040a_w(feeprom_rom6, 2*offset + 0x2000*hsgpl.cur_bank + 0x8000*port, data >> 8);
486486*/
487487         }
488488         else
r9498r9499
505505*/
506506static READ8Z_DEVICE_HANDLER ( data_rz )
507507{
508   if ((offset & 0xe000)==0x4000)
508   if ((offset & 0xe000)==0x4000)
509509   {
510510      hsgpl_dsrspace_rz(device, offset, value);
511511   }
512   
513   if ((offset & 0xe000)==0x6000)
512
513   if ((offset & 0xe000)==0x6000)
514514   {
515515      hsgpl_cartspace_rz(device, offset, value);
516516   }
517   
518   // 1001 1wbb bbbb bba0
517
518   // 1001 1wbb bbbb bba0
519519   if ((offset & 0xfc01)==0x9800)
520520   {
521521      hsgpl_grom_rz(device, offset, value);
r9498r9499
527527*/
528528static WRITE8_DEVICE_HANDLER ( data_w )
529529{
530   if ((offset & 0xe000)==0x6000)
530   if ((offset & 0xe000)==0x6000)
531531   {
532532      hsgpl_cartspace_w(device, offset, data);
533533   }
534   
535   // 1001 1wbb bbbb bba0
534
535   // 1001 1wbb bbbb bba0
536536   if ((offset & 0xfc01)==0x9c00)
537537   {
538538      hsgpl_grom_w(device, offset, data);
539539   }
540540}
541541
542static ti99_peb_card hsgpl_card =
542static ti99_peb_card hsgpl_card =
543543{
544544   data_rz,
545545   data_w,
546546   NULL,
547   cru_w,   
548   NULL, NULL,   NULL, NULL   
547   cru_w,
548   NULL, NULL,   NULL, NULL
549549};
550550
551551static DEVICE_START( hsgpl )
r9498r9499
566566   hsgpl_state *card = get_safe_token(device);
567567   logerror("hsgpl: stop\n");
568568   free(card->flashrom);
569   if (card->ram6)
569   if (card->ram6)
570570   {
571571      free(card->ram6);
572572      free(card->gram);
r9498r9499
577577{
578578   logerror("hsgpl: reset\n");
579579   hsgpl_state *card = get_safe_token(device);
580   
580
581581   /* If the card is selected in the menu, register the card */
582582   if (input_port_read(device->machine, "EXTCARD") & (EXT_HSGPL_ON | EXT_HSGPL_FLASH))
583583   {
584      running_device *peb = device->owner();   
584      running_device *peb = device->owner();
585585      int success = mount_card(peb, device, &hsgpl_card, get_pebcard_config(device)->slot);
586      if (!success)
586      if (!success)
587587      {
588588         logerror("hsgpl: Failed to mount.\n");
589589         return;
r9498r9499
609609      card->flash_mode = (input_port_read(device->machine, "EXTCARD") & EXT_HSGPL_FLASH);
610610      if (card->flash_mode) logerror("hsgpl: flash mode\n");
611611      else logerror("hsgpl: full mode\n");
612     
613      if (card->ram6==NULL)
612
613      if (card->ram6==NULL)
614614      {
615615         card->ram6 = (UINT8*)malloc(RAMSIZE);
616616         card->gram = (UINT8*)malloc(GRAMSIZE);
r9498r9499
629629   if (read_or_write==0)
630630   {
631631      logerror("hsgpl: device nvram load %s\n", astring_c(hsname));
632     
632
633633      filerr = mame_fopen(SEARCHPATH_NVRAM, astring_c(hsname), OPEN_FLAG_READ, &nvfile);
634634      if (filerr != FILERR_NONE)
635635      {
636         logerror("hsgpl: Could not restore NVRAM\n");
636         logerror("hsgpl: Could not restore NVRAM\n");
637637         return;
638638      }
639639
r9498r9499
643643         mame_fclose(nvfile);
644644         return;
645645      }
646         
646
647647      if (card->flashrom[0] != NVVERSION)
648648      {
649649         logerror("hsgpl: Wrong NVRAM image version: %d\n", card->flashrom[0]);
r9498r9499
656656   {
657657      logerror("hsgpl: device nvram save %s\n", astring_c(hsname));
658658      // Check dirty flags
659      if (at29c040a_is_dirty(card->dsr) ||
659      if (at29c040a_is_dirty(card->dsr) ||
660660         at29c040a_is_dirty(card->rom6) ||
661661         at29c040a_is_dirty(card->groma) ||
662662         at29c040a_is_dirty(card->gromb))
663663      {
664664         card->flashrom[0] = NVVERSION;
665665         filerr = mame_fopen(SEARCHPATH_NVRAM, astring_c(hsname), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &nvfile);
666         
666
667667         if (filerr != FILERR_NONE)
668668         {
669            logerror("hsgpl: Could not save NVRAM\n");
669            logerror("hsgpl: Could not save NVRAM\n");
670670         }
671671         else
672672         {
r9498r9499
686686}
687687
688688/*
689   Get the pointer to the memory data from the HSGPL card. Called by the FEEPROM.
689    Get the pointer to the memory data from the HSGPL card. Called by the FEEPROM.
690690*/
691691static UINT8 *get_mem_ptr(running_device *device)
692692{
src/mess/machine/ti99/gromport.h
r9498r9499
1515typedef struct _ti99_multicart_config
1616{
1717   write_line_device_func   ready;
18   
18
1919} ti99_multicart_config;
2020
2121typedef struct _gromport_callback
r9498r9499
4141
4242#define MDRV_TI99_GROMPORT_ADD(_tag, _ready) \
4343   MDRV_DEVICE_ADD(_tag, TI99_MULTICART, 0) \
44   MDRV_DEVICE_CONFIG_DATAPTR(ti99_multicart_config, ready, _ready)
44   MDRV_DEVICE_CONFIG_DATAPTR(ti99_multicart_config, ready, _ready)
4545
4646#endif /* __TI99CART_H__ */
src/mess/machine/ti99/genboard.c
r9498r9499
11/***************************************************************************
2   Geneve 9640 system board
3     
4   Michael Zapf, October 2010
2    Geneve 9640 system board
3
4    Michael Zapf, October 2010
55***************************************************************************/
66
77#include "emu.h"
r9498r9499
2626   /* Mouse support */
2727   int      last_mx;
2828   int      last_my;
29   
29
3030   /* Joystick support */
3131   int    joySel;
3232
3333   /* Keyboard support */
34   UINT8    keyQueue[KEYQUEUESIZE];
34   UINT8   keyQueue[KEYQUEUESIZE];
3535   int    keyQueueHead;
3636   int    keyQueueLen;
3737   int    keyInBuf;
3838   int    keyReset;
39   UINT32    keyStateSave[4];
39   UINT32   keyStateSave[4];
4040   int    keyNumLockState;
4141   int    keyCtrlState;
4242   int    keyAltState;
r9498r9499
4545   int    keyFakeUnshiftState;
4646   int    keyAutoRepeatKey;
4747   int    keyAutoRepeatTimer;
48   
48
4949   /* Mode flags */
5050   int      palvideo;         // bit 5 +
5151   int      capslock;         // bit 7 +
5252   int      keyboard_clock;      // bit 8 +
5353   int      keep_keybuf;      // bit 9 keyclear -
54   int      zero_wait;         // bit 15
55   
54   int      zero_wait;         // bit 15
55
5656   /* GROM simulation */
5757   int      grom_address;
5858   int      gromraddr_LSB;
5959   int      gromwaddr_LSB;
60   
60
6161   /* Memory */
6262   UINT8   *sram;
6363   UINT8   *dram;
6464   UINT8   *eprom;
65   
65
6666   /* Mapper */
6767   int    geneve_mode;          // +
6868   int      direct_mode;          // mapmode -
r9498r9499
7171   int      cartridge6_writable;    // protect -
7272   int      cartridge7_writable;    // protect -
7373   int      map[8];
74   
74
7575   int      line_count;
76   
76
7777   /* Devices */
78   running_device    *cpu;
79   running_device    *video;
78   running_device   *cpu;
79   running_device   *video;
8080   running_device  *tms9901;
81   running_device    *clock;
82   running_device    *peribox;
83   running_device    *sound;
81   running_device   *clock;
82   running_device   *peribox;
83   running_device   *sound;
8484
8585} genboard_state;
8686
r9498r9499
9191   0x1d,   /* right control */
9292   0x38,   /* alt gr */
9393   /* extra codes are 0x5b for Left Windows, 0x5c for Right Windows, 0x5d
94   for Menu, 0x5e for power, 0x5f for sleep, 0x63 for wake, but I doubt
95   any Geneve program would take advantage of these. */
96   
94    for Menu, 0x5e for power, 0x5f for sleep, 0x63 for wake, but I doubt
95    any Geneve program would take advantage of these. */
96
9797   /* extended key that is equivalent to a non-extended key
98   with shift off */
98    with shift off */
9999   0x35,   /* pad slash */
100   
100
101101   /* extended keys that are equivalent to non-extended keys
102   with numlock off */
102    with numlock off */
103103   0x47,   /* home */
104104   0x48,   /* up */
105105   0x49,   /* page up */
r9498r9499
144144}
145145
146146/****************************************************************************
147   GROM simulation. The Geneve board simulated GROM circuits within its gate
148   array.
147    GROM simulation. The Geneve board simulated GROM circuits within its gate
148    array.
149149*****************************************************************************/
150150
151151/*
152   Simulates GROM. The real Geneve does not use GROMs but simulates them
153   within the gate array. Unlike with real GROMs, no address wrapping occurs,
154   and the complete 64K space is available.
152    Simulates GROM. The real Geneve does not use GROMs but simulates them
153    within the gate array. Unlike with real GROMs, no address wrapping occurs,
154    and the complete 64K space is available.
155155*/
156156static READ8_DEVICE_HANDLER( read_grom )
157157{
r9498r9499
159159   UINT8 reply;
160160   if (offset & 0x0002)
161161   {
162      // GROM address handling   
162      // GROM address handling
163163      board->gromwaddr_LSB = FALSE;
164     
164
165165      if (board->gromraddr_LSB)
166166      {
167167         reply = board->grom_address & 0xff;
r9498r9499
186186}
187187
188188/*
189   Simulates GROM. The real Geneve does not use GROMs but simulates them
190   within the gate array.
189    Simulates GROM. The real Geneve does not use GROMs but simulates them
190    within the gate array.
191191*/
192192static WRITE8_DEVICE_HANDLER( write_grom )
193193{
r9498r9499
206206      {
207207         board->grom_address = (board->grom_address & 0x00ff) | ((UINT16)data<<8);
208208         board->gromwaddr_LSB = TRUE;
209      }         
209      }
210210   }
211211   else
212212   {   // write GPL data
r9498r9499
218218}
219219
220220/****************************************************************************
221   Mapper
221    Mapper
222222*****************************************************************************/
223223
224224READ8_DEVICE_HANDLER( geneve_r )
r9498r9499
227227   UINT8 value = 0;
228228   int page;
229229
230   // Premature access. The CPU reads the start vector before RESET.
230   // Premature access. The CPU reads the start vector before RESET.
231231   if (board->peribox==NULL) return 0;
232   
232
233233   if (!board->zero_wait)
234234      cpu_adjust_icount(board->cpu, -4);
235235
236236   UINT32   physaddr;
237   
237
238238   if (board->geneve_mode)
239239   {
240240      // TODO: shortcut offset & 0xffc0 = 0xf100
r9498r9499
302302         // ++++ ++-- ---- ---+
303303         // 1001 0000 0000 0000
304304         // 0x17000 represents the proper AMA/B/C setting; will be masked away currently
305         ti99_peb_data_rz(board->peribox, offset | 0x17000, &value);
305         ti99_peb_data_rz(board->peribox, offset | 0x17000, &value);
306306         return value;
307307      }
308308      if ((offset & 0xfc01)==0x9800)
r9498r9499
314314         return value;
315315      }
316316   }
317   
318   page = (offset & 0xe000) >> 13;
319317
318   page = (offset & 0xe000) >> 13;
319
320320   if (board->direct_mode)
321321   {
322322      physaddr = 0x1e0000; // points to boot eprom
r9498r9499
338338         physaddr = (board->map[page] << 13);
339339      }
340340   }
341   
342   physaddr |= (offset & 0x1fff);
343   
341
342   physaddr |= (offset & 0x1fff);
343
344344   if ((physaddr & 0x180000)==0x000000)
345345   {
346346      // DRAM. One wait state.
r9498r9499
351351   if ((physaddr & 0x180000)==0x080000)
352352   {
353353      // Memex in PEB
354      // 0 1aaa xxxx xxxx xxxx xxxx 
355      ti99_peb_data_rz(board->peribox, physaddr, &value);
354      // 0 1aaa xxxx xxxx xxxx xxxx
355      ti99_peb_data_rz(board->peribox, physaddr, &value);
356356      return value;
357357   }
358358   if ((physaddr & 0x180000)==0x100000)
359359   {
360      // 1 0aaa xxxx xxxx xxxx xxxx p-box address block
360      // 1 0aaa xxxx xxxx xxxx xxxx p-box address block
361361      // Cards in PEB (aaa = AMC, AMB, AMA)
362      ti99_peb_data_rz(board->peribox, physaddr, &value);
362      ti99_peb_data_rz(board->peribox, physaddr, &value);
363363      return value;
364364   }
365365   if ((physaddr & 0x1f0000)==0x1d0000)
r9498r9499
374374      // mirrored for f0, f2, f4, ...; f1, f3, f5, ...
375375      value = board->eprom[physaddr & 0x003fff];
376376      return value;
377   }   
377   }
378378
379   return 0;   
379   return 0;
380380}
381381/*
382382Geneve mode:
r9498r9499
3903908008 / ffff: key_r
3913918010 / fff0: clock_r
3923928800 / fffd: v9938_r
3939000 / ffc0: speech_r
3939000 / ffc0: speech_r
3943949800 / ffc0: grom_r
395395
396396*/
r9498r9499
402402   int page;
403403
404404   if (board->peribox==NULL) return;
405     
405
406406   if (!board->zero_wait)
407407      cpu_adjust_icount(board->cpu, -4);
408   
408
409409   if (board->geneve_mode)
410410   {
411411      if ((offset & 0xfff1)==0xf100)
r9498r9499
474474         // speech
475475         // ++++ ++-- ---- ---+
476476         // 1001 0100 0000 0000
477         ti99_peb_data_w(board->peribox, offset | 0x17000, data);
477         ti99_peb_data_w(board->peribox, offset | 0x17000, data);
478478         return;
479479      }
480480      if ((offset & 0xfc01)==0x9c00)
r9498r9499
521521         physaddr = (board->map[page] << 13);
522522   }
523523
524   physaddr |= offset & 0x1fff;
525   
524   physaddr |= offset & 0x1fff;
525
526526   if ((physaddr & 0x180000)==0x000000)
527527   {
528528      // DRAM write. One wait state.
r9498r9499
533533   if ((physaddr & 0x180000)==0x080000)
534534   {
535535      // Memex in PEB
536      ti99_peb_data_w(board->peribox, physaddr, data);
536      ti99_peb_data_w(board->peribox, physaddr, data);
537537      return;
538538   }
539539   if ((physaddr & 0x180000)==0x100000)
540540   {
541541      // Classic cards in PEB
542      ti99_peb_data_w(board->peribox, physaddr, data);
542      ti99_peb_data_w(board->peribox, physaddr, data);
543543      return;
544   }     
544   }
545545   if ((physaddr & 0x1f0000)==0x1d0000)
546546   {
547547      // SRAM write
r9498r9499
5775771 010. .... .... .... .... p-box AMA=1 AMB=0 (128 KiB)
5785781 0110 .... .... .... .... p-box AMA=1 AMB=1 AMC=0 (64 KiB)
579579
5801 0111 00.. .... .... .... p-box address block 0xxx, 2xxx
5801 0111 00.. .... .... .... p-box address block 0xxx, 2xxx
5815811 0111 010. .... .... .... p-box address block 4xxx (DSR)
5825821 0111 011. .... .... .... p-box address block 6xxx
5831 0111 100. .... .... .... p-box address block 8xxx
5831 0111 100. .... .... .... p-box address block 8xxx
5845841 0111 101. .... .... .... p-box address block axxx
5855851 0111 11.. .... .... .... p-box address block cxxx, exxx
586586
r9498r9499
592592*/
593593
594594/****************************************************************************
595   CRU handling
595    CRU handling
596596*****************************************************************************/
597597
598598#define CRU_CONTROL_BASE 0x1ee0
r9498r9499
604604   int addroff = (offset + 0x0800) << 1;
605605   int rising_edge = FALSE;
606606   int falling_edge = FALSE;
607     
607
608608   if ((addroff & 0x1fe0) == CRU_CONTROL_BASE)
609609   {
610610      int bit = (addroff & 0x0001e)>>1;
r9498r9499
620620         rising_edge = (!board->keyboard_clock && data);
621621         board->keyboard_clock = data;
622622         if (rising_edge)
623            read_key_if_possible(board);           
623            read_key_if_possible(board);
624624         break;
625625      case 9:
626626         rising_edge = (!board->keep_keybuf && data);
r9498r9499
642642               tms9901_set_single_int(board->tms9901, 8, 0);
643643               board->keyInBuf = 0;
644644            }
645         }           
645         }
646646         break;
647647      case 10:
648648         board->geneve_mode = data;
r9498r9499
678678   genboard_state *board = get_safe_token(device);
679679   int addroff = (offset + 0x0100) << 4;
680680
681   // TMS9995-internal CRU locations (1ee0-1efe) are handled within the 99xxcore
681   // TMS9995-internal CRU locations (1ee0-1efe) are handled within the 99xxcore
682682   // implementation (read_single_cru), so we don't arrive here
683683   ti99_peb_cru_rz(board->peribox, addroff, &value);
684684   return value;
685685}
686686
687687/****************************************************************************
688   Keyboard support
688    Keyboard support
689689*****************************************************************************/
690690
691691UINT8 get_recent_key(running_device *device)
r9498r9499
756756
757757               // Release Fake Shift/Unshift if another key is pressed
758758               // We do so if a key is released, though it is actually
759               // required only if it is a modifier key
759               // required only if it is a modifier key
760760               /*if (pressed)*/
761761               //{
762762               if (board->keyFakeShiftState)
r9498r9499
923923}
924924
925925/****************************************************************************
926   Mouse support
926    Mouse support
927927****************************************************************************/
928928
929929static void poll_mouse(running_device *device)
r9498r9499
963963}
964964
965965/****************************************************************************
966   TMS9901 and attached devices handling
966    TMS9901 and attached devices handling
967967****************************************************************************/
968968
969969/*
r9498r9499
11081108   },
11091109
11101110   {   /* write handlers */
1111      W9901_PE_bus_reset,           
1112      W9901_VDP_reset,           
1113      W9901_joySel,             
1114      NULL,                   
1115      NULL,                   
1116      NULL,                   
1117      W9901_keyboardReset,         
1118      W9901_ext_mem_wait_states,       
1119      NULL,                   
1120      W9901_VDP_wait_states,         
1121      NULL,                   
1122      NULL,                   
1123      NULL,                   
1124      NULL,                   
1125      NULL,                   
1126      NULL                 
1111      W9901_PE_bus_reset,
1112      W9901_VDP_reset,
1113      W9901_joySel,
1114      NULL,
1115      NULL,
1116      NULL,
1117      W9901_keyboardReset,
1118      W9901_ext_mem_wait_states,
1119      NULL,
1120      W9901_VDP_wait_states,
1121      NULL,
1122      NULL,
1123      NULL,
1124      NULL,
1125      NULL,
1126      NULL
11271127   },
11281128
11291129   /* interrupt handler */
r9498r9499
11771177static MACHINE_CONFIG_FRAGMENT( genboard )
11781178   MDRV_MM58274C_ADD("mm58274c", geneve_mm58274c_interface)
11791179MACHINE_CONFIG_END
1180   
1180
11811181static DEVICE_START( genboard )
11821182{
11831183   logerror("Starting Geneve board\n");
r9498r9499
11871187   board->peribox = device->siblingdevice("peribox");
11881188   board->cpu = device->siblingdevice("maincpu");
11891189   board->sound = device->siblingdevice("soundgen");
1190   
1190
11911191   board->clock = device->subdevice("mm58274c");
11921192
11931193   board->sram = (UINT8*)malloc(SRAM_SIZE);
r9498r9499
11991199   assert(board->eprom);
12001200   board->geneve_mode = 0;
12011201   board->direct_mode = 1;
1202   
1202
12031203   memset(board->sram, 0x00, SRAM_SIZE);
12041204   memset(board->dram, 0x00, DRAM_SIZE);
12051205}
r9498r9499
12311231   board->last_mx = 0;
12321232   board->last_my = 0;
12331233   board->line_count = 0;
1234   
1234
12351235   board->palvideo = 0;
12361236   board->capslock = 0;
12371237   board->keyboard_clock = 0;
12381238   board->keep_keybuf = 0;
1239   board->zero_wait = 1;
1240   
1239   board->zero_wait = 1;
1240
12411241   board->geneve_mode = 0;
12421242   board->direct_mode = 1;
12431243   board->cartridge_size_8K = 0;
r9498r9499
12451245   board->cartridge6_writable = 0;
12461246   board->cartridge7_writable = 0;
12471247   for (int i=0; i < 8; i++) board->map[i] = 0;
1248   
1248
12491249   if (input_port_read(device->machine, "BOOTROM")==0)
12501250   {
12511251      board->eprom = memory_region(device->machine, "maincpu") + offset_altrom_geneve;
src/mess/machine/ti99/sgcpu.c
r9498r9499
11/***************************************************************************
2   
3   SGCPU board
4   including decoder/mapper
5   
6   This component implements the address decoder and mapper logic from the
7   SGCPU expansion card (inofficially called TI-99/4P).
8     
9   Michael Zapf, October 2010
10   
11   TODO: Check for wait states
2
3    SGCPU board
4    including decoder/mapper
5
6    This component implements the address decoder and mapper logic from the
7    SGCPU expansion card (inofficially called TI-99/4P).
8
9    Michael Zapf, October 2010
10
11    TODO: Check for wait states
1212***************************************************************************/
1313
1414#include "emu.h"
r9498r9499
3434
3535   /* AMS RAM (1 Mib) */
3636   UINT16 *ram;
37   
37
3838   /* Scratch pad ram (1 KiB) */
3939   UINT16 *scratchpad;
40   
40
4141   /* True if SGCPU DSR is enabled */
4242   int internal_dsr;
4343
r9498r9499
5656   UINT8   lowbyte;
5757   UINT8   highbyte;
5858   UINT8   latch;
59     
59
6060   /* Mapper registers */
6161   UINT8 mapper[16];
62   
62
6363   running_device *cpu;
6464   running_device *soundchip;
6565   running_device *video;
6666   running_device *cassette;
6767   running_device *peribox;
68   
68
6969   int keyCol;
7070   int alphaLockLine;
71   
71
7272} sgcpu_state;
7373
7474
r9498r9499
8888#define SAMS_CRU_BASE 0x1e00
8989
9090/*
91   CRU write (there is no read here)
91    CRU write (there is no read here)
9292*/
9393WRITE8_DEVICE_HANDLER( sgcpu_cru_w )
9494{
9595   sgcpu_state *sgcpu = get_safe_token(device);
9696   int addroff = (offset + 0x0400)<<1;
9797
98   if ((addroff & 0xff00)==MAP_CRU_BASE)
98   if ((addroff & 0xff00)==MAP_CRU_BASE)
9999   {
100100      if ((addroff & 0x000e)==0) sgcpu->internal_dsr = data;
101101      if ((addroff & 0x000e)==2) sgcpu->internal_rom6 = data;
102      if ((addroff & 0x000e)==4)
102      if ((addroff & 0x000e)==4)
103103      {
104104         ti99_peb_senila(sgcpu->peribox, data);
105105      }
106      if ((addroff & 0x000e)==6)
106      if ((addroff & 0x000e)==6)
107107      {
108108         ti99_peb_senilb(sgcpu->peribox, data);
109109      }
110110      // TODO: more CRU bits? 8=Fast timing / a=KBENA
111111      return;
112112   }
113   if ((addroff & 0xff00)==SAMS_CRU_BASE)
113   if ((addroff & 0xff00)==SAMS_CRU_BASE)
114114   {
115115      if ((addroff & 0x000e)==0) sgcpu->access_mapper = data;
116116      if ((addroff & 0x000e)==2) sgcpu->map_mode = data;
r9498r9499
133133
134134/*
135135    Memory read. The SAMS card has two address areas: The memory is at locations
136   0x2000-0x3fff and 0xa000-0xffff, and the mapper area is at 0x4000-0x401e
137   (only even addresses).
136    0x2000-0x3fff and 0xa000-0xffff, and the mapper area is at 0x4000-0x401e
137    (only even addresses).
138138*/
139139static READ16_DEVICE_HANDLER( sgcpu_samsmem_r )
140140{
141   sgcpu_state *sgcpu = get_safe_token(device);
141   sgcpu_state *sgcpu = get_safe_token(device);
142142   UINT32 address = 0;
143143   int addroff = offset << 1;
144144
r9498r9499
146146   if (sgcpu->map_mode)
147147      address = (sgcpu->mapper[(addroff>>12) & 0x000f] << 12) + (addroff & 0x0fff);
148148   else // transparent mode
149      address = addroff;
150   
151   return sgcpu->ram[address>>1];       
149      address = addroff;
150
151   return sgcpu->ram[address>>1];
152152}
153153
154154/*
155   Memory write
155    Memory write
156156*/
157157static WRITE16_DEVICE_HANDLER( sgcpu_samsmem_w )
158158{
159   sgcpu_state *sgcpu = get_safe_token(device);
159   sgcpu_state *sgcpu = get_safe_token(device);
160160   UINT32 address = 0;
161161   int addroff = offset << 1;
162   
162
163163   // select memory expansion
164164   if (sgcpu->map_mode)
165165      address = (sgcpu->mapper[(addroff>>12) & 0x000f] << 12) + (addroff & 0x0fff);
166166   else // transparent mode
167      address = addroff;
168   
169   COMBINE_DATA(&sgcpu->ram[address>>1]);
167      address = addroff;
168
169   COMBINE_DATA(&sgcpu->ram[address>>1]);
170170}
171171
172172/***************************************************************************
r9498r9499
182182
183183   ti99_peb_data_rz(sgcpu->peribox, addroff+1, &sgcpu->latch);
184184   sgcpu->lowbyte = sgcpu->latch;
185     
185
186186   // Takes three cycles
187187   cpu_adjust_icount(sgcpu->cpu, -3);
188188
189189   ti99_peb_data_rz(sgcpu->peribox, addroff, &hbyte);
190190   sgcpu->highbyte = hbyte;
191   
191
192192   // Takes three cycles
193193   cpu_adjust_icount(sgcpu->cpu, -3);
194194
195195   // use the latch and the currently read byte and put it on the 16bit bus
196//   printf("read  address = %04x, value = %04x, memmask = %4x\n", addroff,  (hbyte<<8) | sgcpu->latch, mem_mask);
196//  printf("read  address = %04x, value = %04x, memmask = %4x\n", addroff,  (hbyte<<8) | sgcpu->latch, mem_mask);
197197   return (hbyte<<8) | sgcpu->latch ;
198198}
199199
r9498r9499
204204static WRITE16_DEVICE_HANDLER( sgcpu_datamux_w )
205205{
206206   sgcpu_state *sgcpu = get_safe_token(device);
207   UINT16 addroff = (offset << 1);         
208//   printf("write address = %04x, value = %04x, memmask = %4x\n", addroff, data, mem_mask);
209   
207   UINT16 addroff = (offset << 1);
208//  printf("write address = %04x, value = %04x, memmask = %4x\n", addroff, data, mem_mask);
209
210210   // read more about the datamux in datamux.c
211   
211
212212   // byte-only transfer, high byte
213213   // we use the previously read low byte to complete
214214   if (mem_mask == 0xff00)
215215      data = data | sgcpu->lowbyte;
216   
217   // byte-only transfer, low byte   
218   // we use the previously read high byte to complete   
216
217   // byte-only transfer, low byte
218   // we use the previously read high byte to complete
219219   if (mem_mask == 0x00ff)
220220      data = data | (sgcpu->highbyte << 8);
221221
r9498r9499
224224
225225   // Takes three cycles
226226   cpu_adjust_icount(sgcpu->cpu,-3);
227   
227
228228   // Write to the PEB
229229   ti99_peb_data_w(sgcpu->peribox, addroff, (data>>8) & 0xff);
230   
230
231231   // Takes three cycles
232232   cpu_adjust_icount(sgcpu->cpu,-3);
233233}
r9498r9499
237237*/
238238READ16_DEVICE_HANDLER( sgcpu_r )
239239{
240   sgcpu_state *sgcpu = get_safe_token(device);
240   sgcpu_state *sgcpu = get_safe_token(device);
241241   if (sgcpu->cpu == NULL) return 0;
242242
243243   int addroff = offset << 1;
244244   UINT16 zone = addroff & 0xe000;
245245   UINT16 value = 0;
246   
246
247247   if (zone==0x0000)
248248   {
249249      // ROM0
r9498r9499
255255      value = sgcpu_samsmem_r(device, offset, mem_mask);
256256      return value;
257257   }
258   
258
259259   if (zone==0x4000)
260260   {
261261      if (sgcpu->internal_dsr)
262262      {
263         value = sgcpu->dsr[(addroff & 0x1fff)>>1];     
263         value = sgcpu->dsr[(addroff & 0x1fff)>>1];
264264         return value;
265265      }
266266      else
r9498r9499
272272         }
273273      }
274274   }
275   
275
276276   if (zone==0x6000 && sgcpu->internal_rom6)
277277   {
278278      if (sgcpu->rom6_bank==0)
r9498r9499
301301      // Video: 8800, 8802
302302      if ((addroff & 0xfffd)==0x8800)
303303      {
304         value = ti_v9938_r16(sgcpu->video, offset, mem_mask);
304         value = ti_v9938_r16(sgcpu->video, offset, mem_mask);
305305         return value;
306306      }
307307   }
308   
308
309309   // If we are here, check the peribox via the datamux
310310   // catch-all for unmapped zones
311311   value = sgcpu_datamux_r(device, offset, mem_mask);
r9498r9499
317317*/
318318WRITE16_DEVICE_HANDLER( sgcpu_w )
319319{
320   sgcpu_state *sgcpu = get_safe_token(device);
320   sgcpu_state *sgcpu = get_safe_token(device);
321321   if (sgcpu->cpu == NULL) return;
322322
323//   cpu_adjust_icount(sgcpu->cpu, -4);
324   
323//  cpu_adjust_icount(sgcpu->cpu, -4);
324
325325   int addroff = offset << 1;
326326   UINT16 zone = addroff & 0xe000;
327   
327
328328   if (zone==0x0000)
329329   {
330330      // ROM0
r9498r9499
337337      sgcpu_samsmem_w(device, offset, data, mem_mask);
338338      return;
339339   }
340   
340
341341   if (zone==0x4000)
342342   {
343343      if (sgcpu->internal_dsr)
r9498r9499
383383         return;
384384      }
385385   }
386   
386
387387   // If we are here, check the peribox via the datamux
388388   // catch-all for unmapped zones
389389   sgcpu_datamux_w(device, offset, data, mem_mask);
390390}
391391
392392/***************************************************************************
393   Control lines
393    Control lines
394394****************************************************************************/
395395/*
396   Handles the EXTINT line. This one is directly connected to the 9901.
396    Handles the EXTINT line. This one is directly connected to the 9901.
397397*/
398398WRITE_LINE_DEVICE_HANDLER( card_extint )
399399{
r9498r9499
419419}
420420
421421/***************************************************************************
422   Keyboard/tape control
422    Keyboard/tape control
423423****************************************************************************/
424424static const char *keynames[] = { "KEY0", "KEY1", "KEY2", "KEY3" };
425425
r9498r9499
456456   int answer;
457457
458458   answer = ((input_port_read(device->machine, keynames[sgcpu->keyCol >> 1]) >> ((sgcpu->keyCol & 1) * 8)) << 3) & 0xF8;
459   
459
460460   if (sgcpu->alphaLockLine == FALSE)
461461      answer &= ~(input_port_read(device->machine, "ALPHA") << 3);
462   
462
463463   return answer;
464464}
465465
r9498r9499
602602
603603static DEVICE_START( sgcpu )
604604{
605//   // printf("Starting mapper\n");
605//  // printf("Starting mapper\n");
606606   sgcpu_state *sgcpu = get_safe_token(device);
607607   sgcpu->cpu = device->machine->device("maincpu");
608608   sgcpu->peribox = device->machine->device("peribox");
609609   sgcpu->soundchip = device->machine->device("soundgen");
610610   sgcpu->video = device->machine->device("video");
611611   sgcpu->cassette = device->machine->device("cassette");
612   
612
613613   assert(sgcpu->cpu && sgcpu->peribox && sgcpu->soundchip && sgcpu->video && sgcpu->cassette);
614   
614
615615   sgcpu->ram = (UINT16*)malloc(0x080000);
616616   sgcpu->scratchpad = (UINT16*)malloc(0x0400);
617   
617
618618   UINT16 *rom = (UINT16*)memory_region(device->machine, "maincpu");
619619   sgcpu->rom0  = rom + 0x2000;
620   sgcpu->dsr   = rom + 0x6000;   
621   sgcpu->rom6a = rom + 0x3000;   
622   sgcpu->rom6b = rom + 0x7000;   
620   sgcpu->dsr   = rom + 0x6000;
621   sgcpu->rom6a = rom + 0x3000;
622   sgcpu->rom6b = rom + 0x7000;
623623}
624624
625625static DEVICE_STOP( sgcpu )
src/mess/machine/ti99/hsgpl.h
r9498r9499
11/*
22    SNUG HSGPL card emulation.
33    Raphael Nabet, 2003.
4   
4
55    Rewritten as device
66    Michael Zapf, 2010
77*/
src/mess/machine/ti99/genboard.h
r9498r9499
1919WRITE_LINE_DEVICE_HANDLER( board_ready );
2020
2121#define MDRV_GENEVE_BOARD_ADD(_tag )         \
22   MDRV_DEVICE_ADD(_tag, GENBOARD, 0)
23   
22   MDRV_DEVICE_ADD(_tag, GENBOARD, 0)
23
2424#endif
src/mess/machine/ti99/sgcpu.h
r9498r9499
1919DECLARE_LEGACY_DEVICE( SGCPU, sgcpu );
2020
2121#define MDRV_SGCPUB_ADD(_tag )         \
22   MDRV_DEVICE_ADD(_tag, SGCPU, 0)
22   MDRV_DEVICE_ADD(_tag, SGCPU, 0)
2323
2424extern const tms9901_interface tms9901_wiring_ti99_4p;
25   
25
2626#endif
src/mess/machine/ti99/ti_fdc.c
r9498r9499
11/*
2   TI Standard Floppy Disk Controller
3   September 2010
4   
5   Michael Zapf
2    TI Standard Floppy Disk Controller
3    September 2010
4
5    Michael Zapf
66*/
77#include "emu.h"
88#include "peribox.h"
r9498r9499
2424{
2525   /* Holds the status of the DRQ and IRQ lines. */
2626   int               DRQ_IRQ_status;
27   
27
2828   /* When TRUE, card is accessible. Indicated by a LED. */
2929   int               selected;
3030
r9498r9499
3636
3737   /* When TRUE the CPU is halted while DRQ/IRQ are true. */
3838   int               hold;
39   
39
4040   /* Indicates which drive has been selected. Values are 0, 1, 2, and 4. */
4141   // 000 = no drive
4242   // 001 = drive 1
r9498r9499
4848   int               SIDSEL;
4949
5050   /* count 4.23s from rising edge of motor_on */
51   emu_timer          *motor_on_timer;
52   
51   emu_timer         *motor_on_timer;
52
5353   /* Link to the FDC1771 controller on the board. */
54   running_device       *controller;
54   running_device      *controller;
5555
5656   /* DSR ROM */
5757   UINT8            *rom;
5858
5959   /* Callback lines to the main system. */
6060   ti99_peb_connect   lines;
61   
61
6262} ti99_fdc_state;
6363
6464/* Those defines are required because the WD17xx DEVICE_START implementation
r9498r9499
8181
8282    Emulation is faulty because the CPU is actually stopped in the midst of
8383    instruction, at the end of the memory access
84   
85   TODO: This has to be replaced by the proper READY handling that is already
86   prepared here. (Requires READY handling by the CPU.)
84
85    TODO: This has to be replaced by the proper READY handling that is already
86    prepared here. (Requires READY handling by the CPU.)
8787*/
8888static void fdc_handle_hold(running_device *device)
8989{
90   ti99_fdc_state *card = get_safe_token(device);
90   ti99_fdc_state *card = get_safe_token(device);
9191   line_state state;
92   
92
9393   if (card->hold && (!card->DRQ_IRQ_status) && card->DVENA)
9494      state = ASSERT_LINE;
9595   else
9696      state = CLEAR_LINE;
97   
98   // TODO: use READY
97
98   // TODO: use READY
9999   cputag_set_input_line(device->machine, "maincpu", INPUT_LINE_HALT, state);
100100}
101101
r9498r9499
123123/*************************************************************************/
124124
125125/*
126    The CRU read handler.
126    The CRU read handler.
127127    bit 0: HLD pin
128128    bit 1-3: drive n active
129129    bit 4: 0: motor strobe on
r9498r9499
133133*/
134134static READ8Z_DEVICE_HANDLER( cru_r )
135135{
136   ti99_fdc_state *card = get_safe_token(device);
136   ti99_fdc_state *card = get_safe_token(device);
137137
138138   if ((offset & 0xff00)==CRU_BASE)
139139   {
r9498r9499
144144         // deliver bits 0-7
145145         // TODO: HLD pin
146146         // The DVENA state is returned inverted
147         if (card->DVENA) reply |= ((card->DSEL)<<1);
147         if (card->DVENA) reply |= ((card->DSEL)<<1);
148148         else reply |= 0x10;
149149         reply |= 0x40;
150150         if (card->SIDSEL) reply |= 0x80;
151151      }
152152      *value = reply;
153      printf("fdc read cru %04x = %02x\n", offset, reply);
154153   }
155154}
156155
157156static WRITE8_DEVICE_HANDLER( cru_w )
158157{
159   ti99_fdc_state *card = get_safe_token(device);
158   ti99_fdc_state *card = get_safe_token(device);
160159   int drive, drivebit;
161160
162161   if ((offset & 0xff00)==CRU_BASE)
163162   {
164      printf("fdc write cru %04x = %02x\n", offset, data);
165
166163      int bit = (offset >> 1) & 0x07;
167164      switch (bit)
168165      {
r9498r9499
180177         }
181178         card->strobe_motor = data;
182179         break;
183         
180
184181      case 2:
185182         /* Set disk ready/hold (bit 2) */
186183         // 0: ignore IRQ and DRQ
187         // 1: TMS9900 is stopped until IRQ or DRQ are set
188         // OR the motor stops rotating - rotates for 4.23s after write
189         // to CRU bit 1
190         // This is not emulated and could cause the TI99 to lock up
184         // 1: TMS9900 is stopped until IRQ or DRQ are set
185         // OR the motor stops rotating - rotates for 4.23s after write
186         // to CRU bit 1
187         // This is not emulated and could cause the TI99 to lock up
191188         card->hold = data;
192189         fdc_handle_hold(device);
193190         break;
r9498r9499
202199         /* Select drive X (bits 4-6) */
203200         drive = bit-4;               /* drive # (0-2) */
204201         drivebit = 1<<drive;
205         
202
206203         if (data)
207204         {
208205            if (!(card->DSEL & drivebit))         /* select drive */
209206            {
210207               if (card->DSEL != 0)
211                  logerror("ti_fdc: Multiple drives selected, %02x\n", card->DSEL); 
208                  logerror("ti_fdc: Multiple drives selected, %02x\n", card->DSEL);
212209               card->DSEL |= drivebit;
213210               wd17xx_set_drive(card->controller, drive);
214211               /*wd17xx_set_side(DSKside);*/
r9498r9499
217214         else
218215            card->DSEL &= ~drivebit;
219216         break;
220         
217
221218      case 7:
222219         /* Select side of disk (bit 7) */
223220         card->SIDSEL = data;
224221         wd17xx_set_side(card->controller, data);
225222         break;
226      }   
223      }
227224   }
228225}
229226
r9498r9499
232229*/
233230static READ8Z_DEVICE_HANDLER( data_r )
234231{
235   ti99_fdc_state *card = get_safe_token(device);
232   ti99_fdc_state *card = get_safe_token(device);
236233
237234   if (card->selected)
238235   {
239      if ((offset & 0xe000)==0x4000)
236      if ((offset & 0xe000)==0x4000)
240237      {
241238         // only use the even addresses from 1ff0 to 1ff6.
242239         // Note that data is inverted.
r9498r9499
249246            reply = card->rom[offset & 0x1fff];
250247
251248         *value = reply;
252         printf("fdc read %04x = %02x, %c\n", offset, *value, (char)*value);
253249      }
254250   }
255251}
r9498r9499
259255*/
260256static WRITE8_DEVICE_HANDLER( data_w )
261257{
262   ti99_fdc_state *card = get_safe_token(device);
258   ti99_fdc_state *card = get_safe_token(device);
263259   if (card->selected)
264260   {
265      if ((offset & 0xe000)==0x4000)
261      if ((offset & 0xe000)==0x4000)
266262      {
267         printf("fdc write %04x = %02x\n", offset, data);
268263         // only use the even addresses from 1ff8 to 1ffe.
269264         // Note that data is inverted.
270265         // 0101 1111 1111 1xx0
r9498r9499
280275static WRITE_LINE_DEVICE_HANDLER( ti_fdc_intrq_w )
281276{
282277   running_device *carddev = device->owner();
283   ti99_fdc_state *card = get_safe_token(carddev);
278   ti99_fdc_state *card = get_safe_token(carddev);
284279
285280   if (state)
286281   {
r9498r9499
300295static WRITE_LINE_DEVICE_HANDLER( ti_fdc_drq_w )
301296{
302297   running_device *carddev = device->owner();
303   ti99_fdc_state *card = get_safe_token(carddev);
298   ti99_fdc_state *card = get_safe_token(carddev);
304299
305300   if (state)
306301      card->DRQ_IRQ_status |= fdc_DRQ;
r9498r9499
316311static TIMER_CALLBACK(motor_on_timer_callback)
317312{
318313   running_device *device = (running_device *)ptr;
319   ti99_fdc_state *card = get_safe_token(device);
314   ti99_fdc_state *card = get_safe_token(device);
320315   card->DVENA = 0;
321316   fdc_handle_hold(device);
322317}
r9498r9499
329324   { PFLOPPY_0, PFLOPPY_1, PFLOPPY_2, NULL }
330325};
331326
332static ti99_peb_card fdc_card =
327static ti99_peb_card fdc_card =
333328{
334329   data_r,
335330   data_w,
336331   cru_r,
337332   cru_w,
338   
339   NULL, NULL,   NULL, NULL   
333
334   NULL, NULL,   NULL, NULL
340335};
341336
342337static DEVICE_START( ti99_fdc )
343338{
344339   ti99_fdc_state *card = (ti99_fdc_state*)downcast<legacy_device_base *>(device)->token();
345   
340
346341   /* Resolve the callbacks to the PEB */
347342   peb_callback_if *topeb = (peb_callback_if *)device->baseconfig().static_config();
348343   devcb_resolve_write_line(&card->lines.ready, &topeb->ready, device);
r9498r9499
350345   card->motor_on_timer = timer_alloc(device->machine, motor_on_timer_callback, (void *)device);
351346
352347   astring *region = new astring();
353   astring_assemble_3(region, device->tag(), ":", fdc_region);   
348   astring_assemble_3(region, device->tag(), ":", fdc_region);
354349   card->rom = memory_region(device->machine, astring_c(region));
355350   card->controller = device->subdevice("fd1771");
356351}
r9498r9499
367362   /* If the card is selected in the menu, register the card */
368363   if (input_port_read(device->machine, "DISKCTRL") == DISK_TIFDC)
369364   {
370      running_device *peb = device->owner();   
365      running_device *peb = device->owner();
371366      int success = mount_card(peb, device, &fdc_card, get_pebcard_config(device)->slot);
372367      if (!success) return;
373368
src/mess/machine/ti99/p_code.c
r9498r9499
6969    present called "pcode_r0.bin" (4 KiB), "pcode_r1.bin" (8KiB),
7070    "pcode_g0.bin" (64 KiB). The switch is turned off by default. Check the
7171    switch position if the Master Title Screen does not appear as expected.
72   
73   September 2010: Rewritten as device
72
73    September 2010: Rewritten as device
7474*/
7575#include "emu.h"
7676#include "peribox.h"
r9498r9499
9090   int selected;
9191
9292   int bank_select; // 0 or 1
93   
94   // Pointer to the pcode ROM data. We have three sections of the ROM code:
93
94   // Pointer to the pcode ROM data. We have three sections of the ROM code:
9595   // 4K from one chip, 2 banks with 4K each from the second chip.
9696   UINT8 *rom0;
9797   UINT8 *rom1;
9898   UINT8 *rom2;
9999   UINT8 *grom;
100     
100
101101   running_device *gromdev[8];
102102
103103   ti99_peb_connect      lines;
104   
104
105105} ti99_pcoden_state;
106106
107107INLINE ti99_pcoden_state *get_safe_token(running_device *device)
r9498r9499
123123*/
124124static WRITE8_DEVICE_HANDLER( cru_w )
125125{
126   ti99_pcoden_state *card = get_safe_token(device);
126   ti99_pcoden_state *card = get_safe_token(device);
127127
128128   if ((offset & 0xff00)==PCODE_CRU_BASE)
129129   {
130130      int addr = offset & 0x00ff;
131     
131
132132      if (addr==0)
133133         card->selected = data;
134     
134
135135      if (addr==0x80) // Bit 4 is on address line 8
136136         card->bank_select = data;
137137   }
r9498r9499
142142*/
143143static READ8Z_DEVICE_HANDLER( data_r )
144144{
145   ti99_pcoden_state *card = get_safe_token(device);
145   ti99_pcoden_state *card = get_safe_token(device);
146146
147147   if (card->selected)
148148   {
149      if ((offset & 0xe000)==0x4000)
149      if ((offset & 0xe000)==0x4000)
150150      {
151151         if ((offset & 0xfffd)==GROMBASE)
152152         {
153153            for (int i=0; i < 8; i++)
154               ti99grom_rz(card->gromdev[i], offset, value);
154               ti99grom_rz(card->gromdev[i], offset, value);
155155            return;
156156         }
157         
157
158158         if (offset < 0x5000)
159159         {
160160            /* Accesses ROM 4732 (4K) */
r9498r9499
181181      if ((offset & 0xfffd)==(GROMBASE|0x0400))
182182      {
183183         for (int i=0; i < 8; i++)
184            ti99grom_w(card->gromdev[i], offset, data);
184            ti99grom_w(card->gromdev[i], offset, data);
185185      }
186186   }
187187}
188188
189static ti99_peb_card pcode_ncard =
189static ti99_peb_card pcode_ncard =
190190{
191191   data_r,
192192   data_w,
193193   NULL,
194194   cru_w,
195   
196   NULL, NULL,   NULL, NULL   
195
196   NULL, NULL,   NULL, NULL
197197};
198198
199199static DEVICE_START( ti99_pcoden )
200200{
201201   ti99_pcoden_state *pcode = (ti99_pcoden_state*)downcast<legacy_device_base *>(device)->token();
202   
202
203203   /* Resolve the callbacks to the PEB */
204204   peb_callback_if *topeb = (peb_callback_if *)device->baseconfig().static_config();
205205   devcb_resolve_write_line(&pcode->lines.ready, &topeb->ready, device);
r9498r9499
218218   /* If the card is selected in the menu, register the card */
219219   if (input_port_read(device->machine, "EXTCARD") & EXT_PCODE)
220220   {
221      running_device *peb = device->owner();   
221      running_device *peb = device->owner();
222222      int success = mount_card(peb, device, &pcode_ncard, get_pebcard_config(device)->slot);
223223      if (!success) return;
224     
224
225225      astring *region = new astring();
226      astring_assemble_3(region, device->tag(), ":", pcode_region);   
227     
226      astring_assemble_3(region, device->tag(), ":", pcode_region);
227
228228      pcode->rom0 = memory_region(device->machine, astring_c(region));
229229      pcode->rom1 = pcode->rom0 + 0x1000;
230230      pcode->rom2 = pcode->rom0 + 0x2000;
231231      pcode->grom = pcode->rom0 + 0x3000;
232      pcode->bank_select = 0;   
232      pcode->bank_select = 0;
233233      pcode->selected = 0;
234   
234
235235      astring *gromname = new astring();
236236      for (int i=0; i < 8; i++)
237237      {
r9498r9499
250250}
251251
252252/*
253   Get the pointer to the GROM data from the P-Code card. Called by the GROM.
253    Get the pointer to the GROM data from the P-Code card. Called by the GROM.
254254*/
255255static UINT8 *get_grom_ptr(running_device *device)
256256{
src/mess/machine/ti99/tn_usbsm.c
r9498r9499
2020    either that the LSByte of a word is accessed first or that the MSByte of a word
2121    is accessed first.  The former is true with ti-99/4(a), the latter with the
2222    tms9995 CPU used by Geneve and ti-99/8.
23   
23
2424    TODO:
2525    * Test SmartMedia support
2626    * Implement USB controller and assorted USB devices
r9498r9499
4040
4141#define CRU_BASE 0x1600
4242
43typedef ti99_pebcard_config tn_usbsm_config;
43typedef ti99_pebcard_config tn_usbsm_config;
4444
4545typedef struct _tn_usbsm_state
4646{
r9498r9499
5353   int      tms9995_mode;
5454
5555   UINT8   input_latch;
56   
56
5757   UINT8   output_latch;
5858   UINT16   *ram;
59   
59
6060   /* Callback lines to the main system. */
6161   ti99_peb_connect   lines;
62   
62
6363} tn_usbsm_state;
6464
6565enum
r9498r9499
8282static UINT16 usbsm_mem_16_r(running_device *device, offs_t offset)
8383{
8484   UINT16 reply = 0;
85   tn_usbsm_state *card = get_safe_token(device);
85   tn_usbsm_state *card = get_safe_token(device);
8686
8787   if (offset < 0x2800)
8888   {   /* 0x4000-0x4fff range */
r9498r9499
115115*/
116116static void usbsm_mem_16_w(running_device *device, offs_t offset, UINT16 data)
117117{
118   tn_usbsm_state *card = get_safe_token(device);
118   tn_usbsm_state *card = get_safe_token(device);
119119
120120   if (offset < 0x2800)
121121   {   /* 0x4000-0x4fff range */
r9498r9499
160160*/
161161static READ8Z_DEVICE_HANDLER( cru_rz )
162162{
163   tn_usbsm_state *card = get_safe_token(device);
163   tn_usbsm_state *card = get_safe_token(device);
164164
165165   if ((offset & 0xff00)==CRU_BASE)
166166   {
167167      UINT8 reply = 0;
168168      running_device *smartmedia = card->smartmedia;
169169      offset &= 3;
170     
170
171171      if (offset == 0)
172172      {
173173         // bit
r9498r9499
176176         // 2   >1x04   1: USB Host controller suspended.
177177         // 3   >1x06   1: USB Device controller suspended.
178178         // 4   >1x08   0: Strata FEEPROM is busy.
179         //             1: Strata FEEPROM is ready.
179         //             1: Strata FEEPROM is ready.
180180         // 5   >1x0A   0: SmartMedia card is busy.
181         //             1: SmartMedia card absent or ready.
181         //             1: SmartMedia card absent or ready.
182182         // 6   >1x0C   0: No SmartMedia card present.
183         //             1: A card is in the connector.
183         //             1: A card is in the connector.
184184         // 7   >1x0E   0: SmartMedia card is protected.
185         //             1: Card absent or not protected.
186         
185         //             1: Card absent or not protected.
186
187187         reply = 0x33;
188188         if (!smartmedia_present(smartmedia))
189189            reply |= 0xc0;
r9498r9499
195195}
196196
197197/*
198   CRU write
198    CRU write
199199*/
200200static WRITE8_DEVICE_HANDLER( cru_w )
201201{
202   tn_usbsm_state *card = get_safe_token(device);
202   tn_usbsm_state *card = get_safe_token(device);
203203
204204   if ((offset & 0xff00)==CRU_BASE)
205205   {
r9498r9499
210210      case 0:
211211         card->selected = data;
212212         break;
213         
213
214214      case 1:         /* enable I/O registers */
215215      case 2:         /* enable interrupts */
216216      case 3:         /* enable SmartMedia card */
r9498r9499
236236         else
237237            card->feeprom_page &= ~ (1 << (bit-5));
238238         break;
239         
239
240240      case 16:      /* SRAM page */
241241      case 17:
242242      case 18:
r9498r9499
259259*/
260260static READ8Z_DEVICE_HANDLER( data_rz )
261261{
262   tn_usbsm_state *card = get_safe_token(device);
262   tn_usbsm_state *card = get_safe_token(device);
263263
264   if (((offset & 0xe000)==0x4000) && card->selected)
264   if (((offset & 0xe000)==0x4000) && card->selected)
265265   {
266266      if (card->tms9995_mode ? (!(offset & 1)) : (offset & 1))
267267      {   /* first read triggers 16-bit read cycle */
268268         card->input_latch = usbsm_mem_16_r(device, offset >> 1);
269269      }
270     
270
271271      /* return latched input */
272272      *value = (offset & 1) ? card->input_latch : (card->input_latch >> 8);
273273   }
274274}
275275
276276/*
277   Memory write. The controller is 16 bit, so we need to demultiplex again.
277    Memory write. The controller is 16 bit, so we need to demultiplex again.
278278*/
279279static WRITE8_DEVICE_HANDLER( data_w )
280280{
281   tn_usbsm_state *card = get_safe_token(device);
281   tn_usbsm_state *card = get_safe_token(device);
282282
283   if (((offset & 0xe000)==0x4000) && card->selected)
283   if (((offset & 0xe000)==0x4000) && card->selected)
284284   {
285285      /* latch write */
286286      if (offset & 1)
287287         card->output_latch = (card->output_latch & 0xff00) | data;
288288      else
289289         card->output_latch = (card->output_latch & 0x00ff) | (data << 8);
290     
290
291291      if ((card->tms9995_mode)? (offset & 1) : (!(offset & 1)))
292292      {   /* second write triggers 16-bit write cycle */
293293         usbsm_mem_16_w(device, offset >> 1, card->output_latch);
294      }     
294      }
295295   }
296296}
297297
298298/**************************************************************************/
299299
300static ti99_peb_card tn_usbsm_card =
300static ti99_peb_card tn_usbsm_card =
301301{
302302   data_rz, data_w,            // memory access read/write
303303   cru_rz, cru_w,               // CRU access
304   NULL, NULL,                  // SENILA/B access
304   NULL, NULL,                  // SENILA/B access
305305   NULL, NULL                  // 16 bit access (none here)
306306};
307307
r9498r9499
322322   tn_usbsm_state *card = (tn_usbsm_state*)downcast<legacy_device_base *>(device)->token();
323323   /* Register the card */
324324   running_device *peb = device->owner();
325   
325
326326   if (input_port_read(device->machine, "HDCTRL") & HD_USB)
327327   {
328328      int success = mount_card(peb, device, &tn_usbsm_card, get_pebcard_config(device)->slot);
329329      if (!success) return;
330     
330
331331      card->feeprom_page = 0;
332332      card->sram_page = 0;
333333      card->cru_register = 0;
src/mess/machine/ti99/ti32kmem.c
r9498r9499
55#include "peribox.h"
66#include "ti32kmem.h"
77
8typedef ti99_pebcard_config ti99_mem32k_config;
8typedef ti99_pebcard_config ti99_mem32k_config;
99
1010typedef struct _ti99_mem32k_state
1111{
1212   UINT8 *memory;
13   
13
1414} ti99_mem32k_state;
1515
1616INLINE ti99_mem32k_state *get_safe_token(running_device *device)
r9498r9499
2424*/
2525static READ8Z_DEVICE_HANDLER( mem32k_rz )
2626{
27   ti99_mem32k_state *card = get_safe_token(device);
27   ti99_mem32k_state *card = get_safe_token(device);
2828
2929   if (((offset & 0xe000)==0x2000) || ((offset & 0xe000)==0xa000) || ((offset & 0xc000)==0xc000))
3030   {
r9498r9499
3636}
3737
3838/*
39   Memory write
39    Memory write
4040*/
4141static WRITE8_DEVICE_HANDLER( mem32k_w )
4242{
43   ti99_mem32k_state *card = get_safe_token(device);
43   ti99_mem32k_state *card = get_safe_token(device);
4444
4545   if (((offset & 0xe000)==0x2000) || ((offset & 0xe000)==0xa000) || ((offset & 0xc000)==0xc000))
4646   {
r9498r9499
5353
5454/**************************************************************************/
5555
56static ti99_peb_card ti32k_card =
56static ti99_peb_card ti32k_card =
5757{
5858   mem32k_rz, mem32k_w,         // memory access read/write
5959   NULL, NULL,                  // CRU access (none here)
r9498r9499
7878   ti99_mem32k_state *card = (ti99_mem32k_state*)downcast<legacy_device_base *>(device)->token();
7979   /* Register the card */
8080   running_device *peb = device->owner();
81   
81
8282   if (input_port_read(device->machine, "RAM")==RAM_TI32_EXT)
8383   {
8484      int success = mount_card(peb, device, &ti32k_card, get_pebcard_config(device)->slot);
src/mess/machine/ti99/ti_fdc.h
r9498r9499
11/*
2    TI-99 Standard Floppy Disk Controller Card
3   Based on WD1771
4   Single Density, Double-sided
2    TI-99 Standard Floppy Disk Controller Card
3    Based on WD1771
4    Single Density, Double-sided
55    Michael Zapf, September 2010
66*/
77
src/mess/machine/ti99/evpc.c
r9498r9499
11/*
2   SNUG Enhanced Video Processor Card (evpc)
2    SNUG Enhanced Video Processor Card (evpc)
33    based on v9938 (may also be equipped with v9958)
44    Can be used with TI-99/4A as an add-on card; internal VDP must be removed
55
66    The SGCPU ("TI-99/4P") only runs with EVPC.
7   Michael Zapf   
8   Rewritten as device
9   October 2010
7    Michael Zapf
8    Rewritten as device
9    October 2010
1010*/
1111#include "emu.h"
1212#include "peribox.h"
r9498r9499
2121
2222typedef struct _evpc_palette
2323{
24   UINT8       read_index, write_index, mask;
24   UINT8      read_index, write_index, mask;
2525   int       read;
2626   int       state;
2727   struct { UINT8 red, green, blue; } color[0x100];
r9498r9499
3131typedef struct _ti99_evpc_state
3232{
3333   int                selected;
34   UINT8                *dsrrom;
34   UINT8               *dsrrom;
3535   int                RAMEN;
3636   int                dsr_page;
37   UINT8                *novram;   /* NOVRAM area */
37   UINT8               *novram;   /* NOVRAM area */
3838   evpc_palette         palette;
3939   ti99_peb_connect      lines;
40   
40
4141} ti99_evpc_state;
4242
4343INLINE ti99_evpc_state *get_safe_token(running_device *device)
r9498r9499
9595*/
9696static WRITE8_DEVICE_HANDLER( cru_w )
9797{
98   ti99_evpc_state *card = get_safe_token(device);
98   ti99_evpc_state *card = get_safe_token(device);
9999
100100   if ((offset & 0xff00)==EVPC_CRU_BASE)
101101   {
r9498r9499
105105      case 0:
106106         card->selected = data;
107107         break;
108         
108
109109      case 1:
110110         if (data)
111111            card->dsr_page |= 1;
112112         else
113113            card->dsr_page &= ~1;
114114         break;
115         
115
116116      case 2:
117117         break;
118         
118
119119      case 3:
120120         card->RAMEN = data;
121121         break;
122         
122
123123      case 4:
124124         if (data)
125125            card->dsr_page |= 4;
126126         else
127127            card->dsr_page &= ~4;
128128         break;
129         
129
130130      case 5:
131131         if (data)
132132            card->dsr_page |= 2;
133133         else
134134            card->dsr_page &= ~2;
135135         break;
136         
136
137137      case 6:
138138         break;
139         
139
140140      case 7:
141141         break;
142142      }
r9498r9499
151151*/
152152static READ8Z_DEVICE_HANDLER( data_rz )
153153{
154   ti99_evpc_state *card = get_safe_token(device);
154   ti99_evpc_state *card = get_safe_token(device);
155155
156156   if (card->selected)
157157   {
158      if (card->dsrrom==NULL)
158      if (card->dsrrom==NULL)
159159      {
160160         logerror("evpc: no dsrrom\n");
161161         return;
162162      }
163         
163
164164      if ((offset & 0xe000)==0x4000)
165165      {
166166         if ((offset & 0x1ff0)==0x1ff0)
r9498r9499
172172               /* Palette Read Address Register */
173173               *value = card->palette.write_index;
174174               break;
175               
175
176176            case 2:
177177               /* Palette Read Color Value */
178178               if (card->palette.read)
r9498r9499
197197                  }
198198               }
199199               break;
200               
200
201201            case 4:
202202               /* Palette Read Pixel Mask */
203203               *value = card->palette.mask;
r9498r9499
260260               card->palette.state = 0;
261261               card->palette.read = 0;
262262               break;
263               
263
264264            case 10:
265265               /* Palette Write Color Value */
266266               logerror("EVPC palette color write\n");
r9498r9499
287287                  //evpc_palette.dirty = 1;
288288               }
289289               break;
290               
290
291291            case 12:
292292               /* Palette Write Pixel Mask */
293293               logerror("EVPC palette mask write\n");
294294               card->palette.mask = data;
295295               break;
296               
296
297297            case 14:
298298               /* Palette Write Address Register for Color Value */
299299               logerror("EVPC palette address write (for read access)\n");
r9498r9499
318318   }
319319}
320320
321static ti99_peb_card evpc_card =
321static ti99_peb_card evpc_card =
322322{
323323   data_rz,
324324   data_w,
325325   cru_rz,
326326   cru_w,
327   
328   NULL, NULL,   NULL, NULL   
327
328   NULL, NULL,   NULL, NULL
329329};
330330
331331static DEVICE_START( ti99_evpc )
332332{
333   ti99_evpc_state *card = get_safe_token(device);
333   ti99_evpc_state *card = get_safe_token(device);
334334   card->novram = (UINT8*)malloc(256); // need that already now for NVRAM handling
335   
335
336336   /* Resolve the callbacks to the PEB */
337337   peb_callback_if *topeb = (peb_callback_if *)device->baseconfig().static_config();
338338   devcb_resolve_write_line(&card->lines.ready, &topeb->ready, device);
r9498r9499
341341static DEVICE_STOP( ti99_evpc )
342342{
343343   logerror("ti99_evpc: stop\n");
344   ti99_evpc_state *card = get_safe_token(device);
344   ti99_evpc_state *card = get_safe_token(device);
345345   free(card->novram);
346346}
347347
348348static DEVICE_RESET( ti99_evpc )
349349{
350350   logerror("ti99_evpc: reset\n");
351   ti99_evpc_state *card = get_safe_token(device);
351   ti99_evpc_state *card = get_safe_token(device);
352352   astring *region = new astring();
353353
354354   /* If the card is selected in the menu, register the card */
355   running_device *peb = device->owner();   
355   running_device *peb = device->owner();
356356   int success = mount_card(peb, device, &evpc_card, get_pebcard_config(device)->slot);
357   if (!success)
357   if (!success)
358358   {
359359      logerror("evpc: Could not mount card.\n");
360360      return;
361361   }
362362   card->RAMEN = 0;
363363   card->dsr_page = 0;
364   
365   astring_assemble_3(region, device->tag(), ":", evpc_region);   
366   
364
365   astring_assemble_3(region, device->tag(), ":", evpc_region);
366
367367   card->dsrrom = memory_region(device->machine, astring_c(region));
368368}
369369
r9498r9499
378378   if (read_or_write==0)
379379   {
380380      logerror("evpc: device nvram load %s\n", astring_c(hsname));
381     
381
382382      filerr = mame_fopen(SEARCHPATH_NVRAM, astring_c(hsname), OPEN_FLAG_READ, &nvfile);
383383      if (filerr == FILERR_NONE)
384384      {
r9498r9499
391391   {
392392      logerror("evpc: device nvram save %s\n", astring_c(hsname));
393393      filerr = mame_fopen(SEARCHPATH_NVRAM, astring_c(hsname), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &nvfile);
394     
394
395395      if (filerr == FILERR_NONE)
396396      {
397397         if (mame_fwrite(nvfile, card->novram, 256) != 256)
src/mess/machine/ti99/p_code.h
r9498r9499
11/*
22    TI-99 P-Code Card emulation.
33    Michael Zapf, July 2009
4   
5   Revised July 2010
4
5    Revised July 2010
66*/
77
88#ifndef __PCODEN__
src/mess/machine/ti99/videowrp.c
r9498r9499
11/*
22    TI-99/4(A) and /8 Video subsystem
3   This device actually wraps the naked video chip implementation
3    This device actually wraps the naked video chip implementation
44
55    EVPC (Enhanced Video Processor Card) from SNUG
66    based on v9938 (may also be equipped with v9958)
r9498r9499
1616
1717typedef struct _ti99_video_state
1818{
19   address_space    *space;
19   address_space   *space;
2020   running_device   *cpu;
2121   int            chip;
2222} ti99_video_state;
r9498r9499
4242*/
4343READ16_DEVICE_HANDLER( ti_tms991x_r16 )
4444{
45   ti99_video_state *video = get_safe_token(device);
46//   cpu_adjust_icount(video->cpu, -4);
45   ti99_video_state *video = get_safe_token(device);
46//  cpu_adjust_icount(video->cpu, -4);
4747
4848   if (offset & 1)
4949   {   /* read VDP status */
r9498r9499
6060*/
6161READ8Z_DEVICE_HANDLER( ti8_tms991x_rz )
6262{
63   ti99_video_state *video = get_safe_token(device);
64//   cpu_adjust_icount(video->cpu, -4);
63   ti99_video_state *video = get_safe_token(device);
64//  cpu_adjust_icount(video->cpu, -4);
6565
6666   if (offset & 2)
6767   {   /* read VDP status */
r9498r9499
7474}
7575
7676/*
77   Memory read (EVPC)
77    Memory read (EVPC)
7878*/
7979READ16_DEVICE_HANDLER( ti_v9938_r16 )
8080{
81   ti99_video_state *video = get_safe_token(device);
82//   cpu_adjust_icount(video->cpu, -4);
81   ti99_video_state *video = get_safe_token(device);
82//  cpu_adjust_icount(video->cpu, -4);
8383
8484   if (offset & 1)
8585   {   /* read VDP status */
r9498r9499
9292}
9393
9494/*
95   Memory write
95    Memory write
9696*/
9797WRITE16_DEVICE_HANDLER( ti_tms991x_w16 )
9898{
99   ti99_video_state *video = get_safe_token(device);
100//   cpu_adjust_icount(video->cpu, -4);
99   ti99_video_state *video = get_safe_token(device);
100//  cpu_adjust_icount(video->cpu, -4);
101101
102102   if (offset & 1)
103103   {   /* write VDP address */
r9498r9499
110110}
111111
112112/*
113   Memory write (TI-99/8)
113    Memory write (TI-99/8)
114114*/
115115WRITE8_DEVICE_HANDLER( ti8_tms991x_w )
116116{
117   ti99_video_state *video = get_safe_token(device);
118//   cpu_adjust_icount(video->cpu, -4);
117   ti99_video_state *video = get_safe_token(device);
118//  cpu_adjust_icount(video->cpu, -4);
119119
120120   if (offset & 2)
121121   {   /* write VDP address */
r9498r9499
128128}
129129
130130/*
131   Memory write (EVPC)
131    Memory write (EVPC)
132132*/
133133WRITE16_DEVICE_HANDLER ( ti_v9938_w16 )
134134{
135   ti99_video_state *video = get_safe_token(device);
136//   cpu_adjust_icount(video->cpu, -4);
135   ti99_video_state *video = get_safe_token(device);
136//  cpu_adjust_icount(video->cpu, -4);
137137
138138   switch (offset & 3)
139139   {
r9498r9499
157157}
158158
159159/*
160   Video write (Geneve)
160    Video write (Geneve)
161161*/
162162WRITE8_DEVICE_HANDLER ( gen_v9938_w )
163163{
164   ti99_video_state *video = get_safe_token(device);
165//   cpu_adjust_icount(video->cpu, -4);
164   ti99_video_state *video = get_safe_token(device);
165//  cpu_adjust_icount(video->cpu, -4);
166166
167167   switch (offset & 6)
168168   {
r9498r9499
186186}
187187
188188/*
189    Video read (Geneve).
189    Video read (Geneve).
190190*/
191191READ8Z_DEVICE_HANDLER( gen_v9938_rz )
192192{
193   ti99_video_state *video = get_safe_token(device);
194//   cpu_adjust_icount(video->cpu, -4);
195     
193   ti99_video_state *video = get_safe_token(device);
194//  cpu_adjust_icount(video->cpu, -4);
195
196196   if (offset & 2)
197197   {   /* read VDP status */
198198      *value = v9938_0_status_r(video->space, 0);
r9498r9499
205205
206206READ16_DEVICE_HANDLER ( ti_video_rnop )
207207{
208   ti99_video_state *video = get_safe_token(device);
208   ti99_video_state *video = get_safe_token(device);
209209   cpu_adjust_icount(video->cpu, -4);
210210   return 0;
211211}
212212
213213WRITE16_DEVICE_HANDLER ( ti_video_wnop )
214214{
215   ti99_video_state *video = get_safe_token(device);
215   ti99_video_state *video = get_safe_token(device);
216216   cpu_adjust_icount(video->cpu, -4);
217217}
218218/**************************************************************************/
r9498r9499
220220
221221void video_update_mouse( running_device *device, int delta_x, int delta_y, int buttons)
222222{
223   ti99_video_state *video = get_safe_token(device);
223   ti99_video_state *video = get_safe_token(device);
224224   // TODO: V9938 to be devicified
225225   if (video->chip==TI_V9938)
226226      v9938_update_mouse_state(0, delta_x, delta_y, buttons & 3);
r9498r9499
231231
232232static DEVICE_START( ti99_video )
233233{
234   ti99_video_state *video = get_safe_token(device);
234   ti99_video_state *video = get_safe_token(device);
235235   const ti99_video_config* conf = (const ti99_video_config*)get_config(device);
236   
236
237237   video->cpu = device->machine->device("maincpu");
238238   video->space = cputag_get_address_space(device->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
239239
r9498r9499
246246      running_machine *machine = device->machine;
247247      VIDEO_START_CALL(generic_bitmapped);
248248      v9938_init(machine, 0, *machine->primary_screen, machine->generic.tmpbitmap,
249         MODEL_V9938, 0x20000, conf->callback);   /* v38 with 128 kb of video RAM */     
249         MODEL_V9938, 0x20000, conf->callback);   /* v38 with 128 kb of video RAM */
250250   }
251251}
252252
src/mess/machine/ti99/speech8.c
r9498r9499
11/*
22    TI-99/8 Speech synthesizer subsystem
3   
4   The TI-99/8 contains a speech synthesizer inside the console, so we cannot
5   reuse the spchsyn implementation of the P-Box speech synthesizer.
6   
3
4    The TI-99/8 contains a speech synthesizer inside the console, so we cannot
5    reuse the spchsyn implementation of the P-Box speech synthesizer.
6
77    Note that this subsystem also contains the speech roms.
88*/
99#include "emu.h"
r9498r9499
1616
1717typedef struct _ti99_speech8_state
1818{
19   running_device          *vsp;
20   UINT8                *speechrom_data;      /* pointer to speech ROM data */
19   running_device         *vsp;
20   UINT8               *speechrom_data;      /* pointer to speech ROM data */
2121   int                load_pointer;         /* which 4-bit nibble will be affected by load address */
2222   int                ROM_bits_count;            /* current bit position in ROM */
23   UINT32                speechROMaddr;            /* 18 bit pointer in ROM */
23   UINT32               speechROMaddr;            /* 18 bit pointer in ROM */
2424   UINT32               speechROMlen;         /* length of data pointed by speechrom_data, from 0 to 2^18 */
25   
25
2626} ti99_speech8_state;
2727
2828INLINE ti99_speech8_state *get_safe_token(running_device *device)
r9498r9499
3939static int ti99_spchroms_read(running_device *vspdev, int count)
4040{
4141   running_device *device = vspdev->owner();
42   ti99_speech8_state *spsys = get_safe_token(device);
42   ti99_speech8_state *spsys = get_safe_token(device);
4343
4444   int val;
4545
r9498r9499
8282static void ti99_spchroms_load_address(running_device *vspdev, int data)
8383{
8484   running_device *device = vspdev->owner();
85   ti99_speech8_state *spsys = get_safe_token(device);
85   ti99_speech8_state *spsys = get_safe_token(device);
8686   // tms5220 data sheet says that if we load only one 4-bit nibble, it won't work.
8787   // This code does not care about this.
8888   spsys->speechROMaddr = ((spsys->speechROMaddr & ~(0xf << spsys->load_pointer))
r9498r9499
9797static void ti99_spchroms_read_and_branch(running_device *vspdev)
9898{
9999   running_device *device = vspdev->owner();
100   ti99_speech8_state *spsys = get_safe_token(device);
100   ti99_speech8_state *spsys = get_safe_token(device);
101101   // tms5220 data sheet says that if more than one speech ROM (tms6100) is present,
102102   // there is a bus contention.  This code does not care about this. */
103103   if (spsys->speechROMaddr < spsys->speechROMlen-1)
r9498r9499
120120*/
121121READ8Z_DEVICE_HANDLER( ti998spch_rz )
122122{
123   ti99_speech8_state *spsys = get_safe_token(device);
124   
125   if ((offset & 0xfc01)==0x9000)       
123   ti99_speech8_state *spsys = get_safe_token(device);
124
125   if ((offset & 0xfc01)==0x9000)
126126   {
127      cpu_adjust_icount(device->machine->device("maincpu"),-(18+3));      /* this is just a minimum, it can be more */     
127      cpu_adjust_icount(device->machine->device("maincpu"),-(18+3));      /* this is just a minimum, it can be more */
128128      *value = tms5220_status_r(spsys->vsp, offset) & 0xff;
129129   }
130130}
131131
132132/*
133   Memory write
133    Memory write
134134*/
135135WRITE8_DEVICE_HANDLER( ti998spch_w )
136136{
137   ti99_speech8_state *spsys = get_safe_token(device);
137   ti99_speech8_state *spsys = get_safe_token(device);
138138
139   if ((offset & 0xfc01)==0x9400)
139   if ((offset & 0xfc01)==0x9400)
140140   {
141141      cpu_adjust_icount(device->machine->device("maincpu"),-(54+3));      /* this is just an approx. minimum, it can be much more */
142     
142
143143      /* RN: the stupid design of the tms5220 core means that ready is cleared */
144144      /* when there are 15 bytes in FIFO.  It should be 16.  Of course, if */
145145      /* it were the case, we would need to store the value on the bus, */
r9498r9499
149149         attotime time_to_ready = double_to_attotime(tms5220_time_to_ready(spsys->vsp));
150150         int cycles_to_ready = device->machine->device<cpu_device>("maincpu")->attotime_to_cycles(time_to_ready);
151151         logerror("time to ready: %f -> %d\n", attotime_to_double(time_to_ready), (int) cycles_to_ready);
152         
152
153153         cpu_adjust_icount(device->machine->device("maincpu"),-cycles_to_ready);
154154         timer_set(device->machine, attotime_zero, NULL, 0, NULL);
155      }     
155      }
156156      tms5220_data_w(spsys->vsp, offset, data);
157157   }
158158}
r9498r9499
175175   ti99_speech8_state *spsys = (ti99_speech8_state*)downcast<legacy_device_base *>(device)->token();
176176
177177   astring *region = new astring();
178   astring_assemble_3(region, device->tag(), ":", speech8_region);   
179   
178   astring_assemble_3(region, device->tag(), ":", speech8_region);
179
180180   spsys->speechrom_data = memory_region(device->machine, astring_c(region));
181181   spsys->speechROMlen = memory_region_length(device->machine, astring_c(region));
182182   spsys->speechROMaddr = 0;
r9498r9499
186186
187187static WRITE_LINE_DEVICE_HANDLER( speech8_ready )
188188{
189//   ti99_speech8_state *spsys = (ti99_speech8_state*)downcast<legacy_device_base *>(device->owner())->token();
189//  ti99_speech8_state *spsys = (ti99_speech8_state*)downcast<legacy_device_base *>(device->owner())->token();
190190   logerror("speech8: READY called by VSP\n");
191191}
192192
src/mess/machine/ti99/tn_ide.c
r9498r9499
1818
1919    Rewritten as device
2020    Michael Zapf, September 2010
21   
22    FIXME: idecont assumes that there is only one drive that is called
21
22    FIXME: idecont assumes that there is only one drive that is called
2323    "harddisk" at the root level
2424*/
2525#include "emu.h"
r9498r9499
3232
3333#define CRU_BASE 0x1000
3434
35typedef ti99_pebcard_config tn_ide_config;
35typedef ti99_pebcard_config tn_ide_config;
3636
3737enum
3838{   /* 0xff for 2 mbytes, 0x3f for 512kbytes, 0x03 for 32 kbytes */
r9498r9499
6262   int    sram_enable_dip;
6363   int    cru_register;
6464   int      cur_page;
65   
65
6666   int      tms9995_mode;
67   
68   UINT8    input_latch;
69   UINT8    output_latch;
70   
67
68   UINT8   input_latch;
69   UINT8   output_latch;
70
7171   UINT8   *ram;
72   
72
7373   /* Callback lines to the main system. */
7474   ti99_peb_connect   lines;
75   
75
7676} tn_ide_state;
7777
7878INLINE tn_ide_state *get_safe_token(running_device *device)
r9498r9499
8787*/
8888static READ8Z_DEVICE_HANDLER( cru_rz )
8989{
90   tn_ide_state *card = get_safe_token(device);
90   tn_ide_state *card = get_safe_token(device);
9191   UINT8 reply = 0;
9292   if ((offset & 0xff00)==CRU_BASE)
9393   {
9494      int bit = (offset >> 4) & 7;
95     
95
9696      if (bit==0)
9797      {
9898         reply = card->cru_register & 0x30;
r9498r9499
109109}
110110
111111/*
112   CRU write
112    CRU write
113113*/
114114static WRITE8_DEVICE_HANDLER( cru_w )
115115{
116   tn_ide_state *card = get_safe_token(device);
116   tn_ide_state *card = get_safe_token(device);
117117
118118   if ((offset & 0xff00)==CRU_BASE)
119119   {
r9498r9499
122122      {
123123      case 0:         /* turn card on: handled by core */
124124         card->selected = data;
125         
125
126126      case 1:         /* enable SRAM or registers in 0x4000-0x40ff */
127127         card->sram_enable = data;
128128         break;
129         
129
130130      case 2:         /* enable SRAM page switching */
131131      case 3:         /* force SRAM page 0 */
132132      case 4:         /* enable SRAM in 0x6000-0x7000 ("RAMBO" mode) */
r9498r9499
137137            card->cru_register |= 1 << bit;
138138         else
139139            card->cru_register &= ~(1 << bit);
140         
140
141141         if (bit == 6)
142142            devcb_call_write_line(&card->lines.inta, (card->cru_register & cru_reg_int_en) && card->ide_irq);
143         
143
144144         if ((bit == 6) || (bit == 7))
145145            if ((card->cru_register & cru_reg_int_en) && !(card->cru_register & cru_reg_reset))
146146               card->ide->reset();
r9498r9499
154154*/
155155static READ8Z_DEVICE_HANDLER( data_rz )
156156{
157   tn_ide_state *card = get_safe_token(device);
157   tn_ide_state *card = get_safe_token(device);
158158   UINT8 reply = 0;
159159
160   if (((offset & 0xe000)==0x4000) && card->selected)
160   if (((offset & 0xe000)==0x4000) && card->selected)
161161   {
162162      int addr = offset & 0x1fff;
163   
163
164164      if ((addr <= 0xff) && (card->sram_enable == card->sram_enable_dip))
165165      {   /* registers */
166166         switch ((addr >> 5) & 0x3)
r9498r9499
186186            {   /* first read triggers 16-bit read cycle */
187187               card->input_latch = (! (addr & 0x10)) ? ide_bus_r(card->ide, 0, (addr >> 1) & 0x7) : 0;
188188            }
189           
189
190190            /* return latched input */
191191            /*reply = (addr & 1) ? input_latch : (input_latch >> 8);*/
192192            /* return latched input - bytes are swapped in 2004 IDE card */
r9498r9499
197197            {   /* first read triggers 16-bit read cycle */
198198               card->input_latch = (! (addr & 0x10)) ? ide_bus_r(card->ide, 1, (addr >> 1) & 0x7) : 0;
199199            }
200           
200
201201            /* return latched input */
202202            /*reply = (addr & 1) ? input_latch : (input_latch >> 8);*/
203203            /* return latched input - bytes are swapped in 2004 IDE card */
r9498r9499
217217}
218218
219219/*
220   Memory write. The controller is 16 bit, so we need to demultiplex again.
220    Memory write. The controller is 16 bit, so we need to demultiplex again.
221221*/
222222static WRITE8_DEVICE_HANDLER( data_w )
223223{
224   tn_ide_state *card = get_safe_token(device);
224   tn_ide_state *card = get_safe_token(device);
225225
226   if (((offset & 0xe000)==0x4000) && card->selected)
226   if (((offset & 0xe000)==0x4000) && card->selected)
227227   {
228228      if (card->cru_register & cru_reg_page_switching)
229229      {
230230         card->cur_page = (offset >> 1) & page_mask;
231231      }
232     
232
233233      int addr = offset & 0x1fff;
234     
234
235235      if ((addr <= 0xff) && (card->sram_enable == card->sram_enable_dip))
236236      {   /* registers */
237237         switch ((addr >> 5) & 0x3)
r9498r9499
253253               rtc65271_rtc_w(card->rtc, 0, data);
254254            break;
255255         case 2:      /* IDE registers set 1 (CS1Fx) */
256/*   
257            if (addr & 1)
258               card->output_latch = (card->output_latch & 0xff00) | data;
259            else
260               card->output_latch = (card->output_latch & 0x00ff) | (data << 8);
256/*
257                if (addr & 1)
258                    card->output_latch = (card->output_latch & 0xff00) | data;
259                else
260                    card->output_latch = (card->output_latch & 0x00ff) | (data << 8);
261261*/
262262            /* latch write - bytes are swapped in 2004 IDE card */
263263            if (addr & 1)
264264               card->output_latch = (card->output_latch & 0x00ff) | (data << 8);
265265            else
266266               card->output_latch = (card->output_latch & 0xff00) | data;
267           
267
268268            if (card->tms9995_mode ? (addr & 1) : (!(addr & 1)))
269269            {   /* second write triggers 16-bit write cycle */
270270               ide_bus_w(card->ide, 0, (addr >> 1) & 0x7, card->output_latch);
r9498r9499
272272            break;
273273         case 3:      /* IDE registers set 2 (CS3Fx) */
274274/*
275            if (addr & 1)
276               card->output_latch = (card->output_latch & 0xff00) | data;
277            else
278               card->output_latch = (card->output_latch & 0x00ff) | (data << 8);
275                if (addr & 1)
276                    card->output_latch = (card->output_latch & 0xff00) | data;
277                else
278                    card->output_latch = (card->output_latch & 0x00ff) | (data << 8);
279279*/
280280            /* latch write - bytes are swapped in 2004 IDE card */
281281            if (addr & 1)
282282               card->output_latch = (card->output_latch & 0x00ff) | (data << 8);
283283            else
284284               card->output_latch = (card->output_latch & 0xff00) | data;
285           
285
286286            if (card->tms9995_mode ? (addr & 1) : (!(addr & 1)))
287287            {   /* second write triggers 16-bit write cycle */
288288               ide_bus_w(card->ide, 1, (addr >> 1) & 0x7, card->output_latch);
r9498r9499
305305
306306/**************************************************************************/
307307
308static ti99_peb_card tn_ide_card =
308static ti99_peb_card tn_ide_card =
309309{
310310   data_rz, data_w,            // memory access read/write
311311   cru_rz, cru_w,               // CRU access
312   NULL, NULL,                  // SENILA/B access
312   NULL, NULL,                  // SENILA/B access
313313   NULL, NULL                  // 16 bit access (none here)
314314};
315315
r9498r9499
342342   tn_ide_state *card = get_safe_token(device);
343343   card->rtc = device->subdevice("ide_rtc");
344344   card->ide = device->subdevice("ide");
345   
345
346346   peb_callback_if *topeb = (peb_callback_if *)device->baseconfig().static_config();
347347   devcb_resolve_write_line(&card->lines.inta, &topeb->inta, device);
348348
r9498r9499
358358{
359359   tn_ide_state *card = get_safe_token(device);
360360   running_device *peb = device->owner();
361   
361
362362   if (input_port_read(device->machine, "HDCTRL") & HD_IDE)
363363   {
364364      int success = mount_card(peb, device, &tn_ide_card, get_pebcard_config(device)->slot);
365365      if (!success) return;
366     
366
367367      card->cur_page = 0;
368368      card->sram_enable = 0;
369369      card->cru_register = 0;
src/mess/machine/ti99/evpc.h
r9498r9499
11/*
2    SNUG Enhanced Video Processor Card (evpc)
2    SNUG Enhanced Video Processor Card (evpc)
33
4   Michael Zapf   
5   Rewritten as device
6   October 2010
4    Michael Zapf
5    Rewritten as device
6    October 2010
77*/
88/* device interface */
99#ifndef __EVPC__
src/mess/machine/ti99/samsmem.c
r9498r9499
11/*
22    TI-99 SuperAMS Memory Expansion Card. Uses a 74LS612 memory mapper.
3   
4   TODO: Test this device with some emulated program!
3
4    TODO: Test this device with some emulated program!
55*/
66#include "emu.h"
77#include "peribox.h"
88#include "samsmem.h"
99
10typedef ti99_pebcard_config ti99_samsmem_config;
10typedef ti99_pebcard_config ti99_samsmem_config;
1111
1212typedef struct _ti99_samsmem_state
1313{
14   UINT8    mapper[16];
15   int    map_mode;   
14   UINT8   mapper[16];
15   int    map_mode;
1616   int      access_mapper;
17   UINT8    *memory;
18   
17   UINT8   *memory;
18
1919} ti99_samsmem_state;
2020
2121INLINE ti99_samsmem_state *get_safe_token(running_device *device)
r9498r9499
2727#define SAMS_CRU_BASE 0x1e00
2828
2929/*
30   CRU write (there is no read here)
30    CRU write (there is no read here)
3131*/
3232static WRITE8_DEVICE_HANDLER( samsmem_cru_w )
3333{
34   ti99_samsmem_state *card = get_safe_token(device);
35   if ((offset & 0xff00)==SAMS_CRU_BASE)
34   ti99_samsmem_state *card = get_safe_token(device);
35   if ((offset & 0xff00)==SAMS_CRU_BASE)
3636   {
3737      if ((offset & 0x000e)==0) card->access_mapper = data;
3838      if ((offset & 0x000e)==2) card->map_mode = data;
r9498r9499
4141
4242/*
4343    Memory read. The SAMS card has two address areas: The memory is at locations
44   0x2000-0x3fff and 0xa000-0xffff, and the mapper area is at 0x4000-0x401e
45   (only even addresses).
44    0x2000-0x3fff and 0xa000-0xffff, and the mapper area is at 0x4000-0x401e
45    (only even addresses).
4646*/
4747static READ8Z_DEVICE_HANDLER( samsmem_rz )
4848{
49   ti99_samsmem_state *card = get_safe_token(device);
49   ti99_samsmem_state *card = get_safe_token(device);
5050   UINT32 address = 0;
5151
5252   if (card->access_mapper && ((offset & 0xe000)==0x4000))
r9498r9499
5454      // select the mapper circuit
5555      *value = card->mapper[(offset>>1)&0x000f];
5656   }
57     
57
5858   if (((offset & 0xe000)==0x2000) || ((offset & 0xe000)==0xa000) || ((offset & 0xc000)==0xc000))
5959   {
6060      // select memory expansion
6161      if (card->map_mode)
6262         address = (card->mapper[offset>>12] << 12) + (offset & 0x0fff);
6363      else // transparent mode
64         address = offset;
65      *value = card->memory[address];       
66   }   
64         address = offset;
65      *value = card->memory[address];
66   }
6767}
6868
6969/*
70   Memory write
70    Memory write
7171*/
7272static WRITE8_DEVICE_HANDLER( samsmem_w )
7373{
74   ti99_samsmem_state *card = get_safe_token(device);
74   ti99_samsmem_state *card = get_safe_token(device);
7575   UINT32 address = 0;
7676
7777   if (card->access_mapper && ((offset & 0xe000)==0x4000))
r9498r9499
8585      if (card->map_mode)
8686         address = (card->mapper[offset>>12] << 12) + (offset & 0x0fff);
8787      else // transparent mode
88         address = offset;
89      card->memory[address] = data;
90   }   
88         address = offset;
89      card->memory[address] = data;
90   }
9191}
9292
9393/**************************************************************************/
9494
95static ti99_peb_card samsmem_card =
95static ti99_peb_card samsmem_card =
9696{
9797   samsmem_rz, samsmem_w,         // memory access read/write
9898   NULL, samsmem_cru_w,         // CRU access (no read here)
r9498r9499
117117   ti99_samsmem_state *card = (ti99_samsmem_state*)downcast<legacy_device_base *>(device)->token();
118118   /* Register the card */
119119   running_device *peb = device->owner();
120   
120
121121   if (input_port_read(device->machine, "RAM")==RAM_SUPERAMS1024)
122122   {
123123      int success = mount_card(peb, device, &samsmem_card, get_pebcard_config(device)->slot);
src/mess/machine/ti99/datamux.c
r9498r9499
11/***************************************************************************
2   
3   TI-99/4(A) databus multiplexer circuit
4   
5   The DMUX is used to convert the 16-bit databus of the TMS9900 into
6   an 8-bit databus. The processor writes a 16 bit word which is split
7   by this circuit into two bytes that are sent serially over the 8-bit bus.
8   In the opposite direction, one 16-bit read request from the CPU is
9   translated into two 8-bit read requests (odd address / even address) from
10   this datamux. Its 8-bit latch (LS373) holds the first byte, while the
11   datamux puts the CPU on hold, gets the second byte, and routes that second
12   byte to the D0-D7 lines, while the latch now puts the first byte on D8-D15.
13   Since we get two memory accesses each time, there are twice as many
14   wait states than for a direct 16-bit access (order LSB, MSB).
15   
16   In addition, since the TMS 9900 also supports byte operations, every write
17   operation is automatically preceded by a read operation, so this adds even
18   more delays.
192
20   Within the TI-99/4(A) console, only the internal ROM and the small internal
21   RAM ("scratch pad RAM") are directly connected to the 16-bit bus. All other
22   devices (video, audio, speech, GROM, and the complete P-Box system are
23   connected to the datamux.
24   
25   The TMS9995 which is used in the Geneve has an internal multiplex, and
26   the byte order is reversed: MSB, LSB
27   
28   ROM = 4K * 16 bit (8 KiB) system ROM (kind of BIOS, plus the GPL interpreter)
29   RAM = 128 * 16 bit (256 byte) system RAM ("scratch pad")
3    TI-99/4(A) databus multiplexer circuit
304
31   Many users (me too) used to solder a 16K * 16 bit (32 KiB) SRAM circuit into
32   the console, before the datamux, decoded to 0x2000-0x3fff and 0xa000-0xffff.
33   (This expansion was also called 0-waitstate, since it could be accessed
34   with the full databus width, and the datamux did not create waitstates.)   
35   
36   +---+                                                   +-------+
37   |   |===##========##== D0-D7 ==========##===============|TMS9918| Video
38   |   |   ||        ||                   ||               +-------+ 
39   | T |   +-----+  +-----+      LS245  +----+   
40   | M |   | ROM |  | RAM |             +----+
41   | S |   +-----+  +-----+               || |                     :
42   |   |---||-||-----||-||----------------||-|---------------------:
43   | 9 |   ||        ||    A0 - A14       || |                A0   : Sound
44   | 9 |---||--------||-------------------||-|----------+    -A15  : GROM
45   | 0 |   ||        ||      LS373  +-+   || | +----A15-+----------: Cartridges
46   | 0 |   ||        ||   ##========|<|===## | |                   : Speech
47   |   |   ||        ||   ||  +-+   +-+   || | |                   : Expansion
48   |   |===## D8-D15 ##===##==|>|=====|===##=|=|=========== D0-D7 =: cards
49   +---+                      +-+     |      | |                   : 
50     ^                     LS244|     |      | |                     
51     |                          |     +--+---+-++                   
52     |                       +--------| DMUX |                   
53     +--- READY -------------------------+------+
5    The DMUX is used to convert the 16-bit databus of the TMS9900 into
6    an 8-bit databus. The processor writes a 16 bit word which is split
7    by this circuit into two bytes that are sent serially over the 8-bit bus.
8    In the opposite direction, one 16-bit read request from the CPU is
9    translated into two 8-bit read requests (odd address / even address) from
10    this datamux. Its 8-bit latch (LS373) holds the first byte, while the
11    datamux puts the CPU on hold, gets the second byte, and routes that second
12    byte to the D0-D7 lines, while the latch now puts the first byte on D8-D15.
13    Since we get two memory accesses each time, there are twice as many
14    wait states than for a direct 16-bit access (order LSB, MSB).
5415
55        Databus width
56       :------------- 16 bit ---------------|---------- 8 bit -----:
57   
58   A0=MSB; A15=LSB
59   D0=MSB; D15=LSB
60   
61   We integrate the 16 bit memory expansion in this datamux component
62   (pretending that the memory expansion was soldered on top of the datamux)
16    In addition, since the TMS 9900 also supports byte operations, every write
17    operation is automatically preceded by a read operation, so this adds even
18    more delays.
19
20    Within the TI-99/4(A) console, only the internal ROM and the small internal
21    RAM ("scratch pad RAM") are directly connected to the 16-bit bus. All other
22    devices (video, audio, speech, GROM, and the complete P-Box system are
23    connected to the datamux.
24
25    The TMS9995 which is used in the Geneve has an internal multiplex, and
26    the byte order is reversed: MSB, LSB
27
28    ROM = 4K * 16 bit (8 KiB) system ROM (kind of BIOS, plus the GPL interpreter)
29    RAM = 128 * 16 bit (256 byte) system RAM ("scratch pad")
30
31    Many users (me too) used to solder a 16K * 16 bit (32 KiB) SRAM circuit into
32    the console, before the datamux, decoded to 0x2000-0x3fff and 0xa000-0xffff.
33    (This expansion was also called 0-waitstate, since it could be accessed
34    with the full databus width, and the datamux did not create waitstates.)
35
36    +---+                                                   +-------+
37    |   |===##========##== D0-D7 ==========##===============|TMS9918| Video
38    |   |   ||        ||                   ||               +-------+
39    | T |   +-----+  +-----+      LS245  +----+
40    | M |   | ROM |  | RAM |             +----+
41    | S |   +-----+  +-----+               || |                     :
42    |   |---||-||-----||-||----------------||-|---------------------:
43    | 9 |   ||        ||    A0 - A14       || |                A0   : Sound
44    | 9 |---||--------||-------------------||-|----------+    -A15  : GROM
45    | 0 |   ||        ||      LS373  +-+   || | +----A15-+----------: Cartridges
46    | 0 |   ||        ||   ##========|<|===## | |                   : Speech
47    |   |   ||        ||   ||  +-+   +-+   || | |                   : Expansion
48    |   |===## D8-D15 ##===##==|>|=====|===##=|=|=========== D0-D7 =: cards
49    +---+                      +-+     |      | |                   :
50      ^                     LS244|     |      | |
51      |                          |     +--+---+-++
52      |                          +--------| DMUX |
53      +--- READY -------------------------+------+
54
55         Databus width
56        :------------- 16 bit ---------------|---------- 8 bit -----:
57
58    A0=MSB; A15=LSB
59    D0=MSB; D15=LSB
60
61    We integrate the 16 bit memory expansion in this datamux component
62    (pretending that the memory expansion was soldered on top of the datamux)
6363***************************************************************************/
6464
6565#include "emu.h"
r9498r9499
7171typedef struct _attached_device
7272{
7373   /* The device. */
74   running_device    *device;
75   
74   running_device   *device;
75
7676   /* Address bits involved */
77   UINT16         address_mask;
77   UINT16         address_mask;
7878
7979   /* Value of the address bits which are involved for selecting for read. */
8080   UINT16         select;
8181
8282   /* Value of the address bits which are involved for selecting for write. */
8383   UINT16         write_select;
84   
84
8585   /* Read access. */
8686   databus_read_function read_byte;
87   
87
8888   /* Write access. */
8989   databus_write_function write_byte;
9090
9191   /* Setting which determined if this device is mounted or not. */
9292   const char   *setting;
93   
93
9494   /* Bits which must be set in the setting. */
9595   UINT8      set;
96   
96
9797   /* Bits which must not be set in the setting. */
9898   UINT8      unset;
9999} attached_device;
r9498r9499
102102{
103103   /* All devices that are attached to the 8-bit bus. */
104104   attached_device component[MAXDEV];
105   
105
106106   /* Latch which stores the first byte */
107107   UINT8 latch;
108   
108
109109   // Intermediate storage which holds the low byte of the previous read cycle.
110   // In reality, the TMS9900 adds the low byte to the 16 bit memory word
110   // In reality, the TMS9900 adds the low byte to the 16 bit memory word
111111   // from the previous read-before-write cycle, but this is not yet handled
112112   // by the TMS9900 emulation. TODO: rewrite TMS9900
113113   UINT8 lowbyte;
114114   UINT8 highbyte;
115   
115
116116   /* Memory expansion (internal, 16 bit). */
117117   UINT16 *ram16b;
118   
118
119119   /* Use the memory expansion? */
120120   int use32k;
121   
121
122122   /* Management function */
123123   int devindex;
124124} datamux_state;
r9498r9499
134134static void dmux_mount_device(running_device *dmuxdev, running_device *busdevice, UINT16 address_mask, UINT16 address_bits, UINT16 write_sel, databus_read_function read, databus_write_function write)
135135{
136136   datamux_state *dmux = get_safe_token(dmuxdev);
137   int index = dmux->devindex++;
137   int index = dmux->devindex++;
138138   if (index < MAXDEV)
139139   {
140140      if (dmux->component[index].device == NULL)
r9498r9499
144144         dmux->component[index].select = address_bits;
145145         dmux->component[index].write_select = write_sel;
146146         dmux->component[index].read_byte = read;
147         dmux->component[index].write_byte = write;   
147         dmux->component[index].write_byte = write;
148148         // printf("registering the device at position %d\n", index);
149149      }
150150   }
r9498r9499
153153      logerror("ti99_dmux: Tried to mount too many devices to the DMUX. (Just a bug.)\n");
154154   }
155155}
156/*
157static void dmux_unmount_device(running_device *dmuxdev, running_device *busdevice)
158{
159   datamux_state *dmux = get_safe_token(dmuxdev);
160   for (int index = 0; index < MAXDEV; index++)
161   {
162      if (dmux->component[index].device == busdevice)
163      {
164         dmux->component[index].device = NULL;
165         return;
166      }     
167   }
168   printf("Failed to uninstall device from dmux\n");
169}
170*/
156
171157/***************************************************************************
172158    DEVICE ACCESSOR FUNCTIONS
173159***************************************************************************/
174160
175161/*
176    Read access. We are using two loops because the delay between both
162    Read access. We are using two loops because the delay between both
177163    accesses must not occur within the loop. So we have one access on the bus,
178164    a delay, and then the second access (each one with possibly many attached
179165    devices)
r9498r9499
186172
187173   // Looks ugly, but this is close to the real thing. If the 16bit
188174   // memory expansion is installed in the console, and the access hits its
189   // space, just respond to the memory access and don't bother the
175   // space, just respond to the memory access and don't bother the
190176   // datamux in any way. In particular, do not make the datamux insert wait
191177   // states.
192178   if (dmux->use32k)
r9498r9499
197183
198184      if (base != 0)
199185      {
200         UINT16 reply = dmux->ram16b[offset-base];
186         UINT16 reply = dmux->ram16b[offset-base];
201187         // Store the prefetch
202         dmux->lowbyte = reply & 0x00ff;
203         dmux->highbyte = (reply & 0xff00)>>8;
204         return reply;
188         dmux->lowbyte = reply & 0x00ff;
189         dmux->highbyte = (reply & 0xff00)>>8;
190         return reply;
205191      }
206192   }
207     
193
208194   for (int i=0; i < MAXDEV; i++)
209195   {
210196      attached_device *adev = &dmux->component[i];
r9498r9499
222208         // hope we don't have two devices answering...
223209         // consider something like a logical OR and maybe some artificial smoke
224210      }
225   }   
226   
211   }
212
227213   // Takes three cycles
228214   cpu_adjust_icount(device->machine->device("maincpu"),-3);
229215
r9498r9499
241227            }
242228         }
243229      }
244   }   
230   }
245231
246232   // Takes three cycles
247233   cpu_adjust_icount(device->machine->device("maincpu"),-3);
r9498r9499
256242WRITE16_DEVICE_HANDLER( ti99_dmux_w )
257243{
258244   datamux_state *dmux = get_safe_token(device);
259   UINT16 addr = (offset << 1);         
260   
261   // The handling of byte writing is done in MESS using mem_mask.
245   UINT16 addr = (offset << 1);
246
247   // The handling of byte writing is done in MESS using mem_mask.
262248   // If the mem_mask is ff00, the CPU is about to write the high byte. This
263   // is not the true story, since the real CPU never writes half a word.
264   // In reality, the TMS9900 performs a read-before-write, stores the word
249   // is not the true story, since the real CPU never writes half a word.
250   // In reality, the TMS9900 performs a read-before-write, stores the word
265251   // internally, and replaces the high or low byte when it is about to write
266   // a byte to an even or odd address, respectively. Then it writes the
252   // a byte to an even or odd address, respectively. Then it writes the
267253   // complete new word.
268254   // Example: Memory locations 0x6000 contains the word 0x1234 (BE). If we
269255   // write a 0x56 to 0x6000, the CPU first reads 0x6000, stores the 0x1234,
r9498r9499
271257
272258   // Until the TMS9900 emulation is corrected in this way, we are using
273259   // the DMUX in place of the internal buffer.
274   
275//   printf("write addr=%04x memmask=%04x value=%04x\n", addr, mem_mask, data);
260
261//  printf("write addr=%04x memmask=%04x value=%04x\n", addr, mem_mask, data);
276262   if (mem_mask == 0xff00)
277263      data = data | dmux->lowbyte;
278   
264
279265   if (mem_mask == 0x00ff)
280266      data = data | (dmux->highbyte << 8);
281267
r9498r9499
293279         return;
294280      }
295281   }
296   
282
297283   for (int i=0; i < MAXDEV; i++)
298284   {
299285      attached_device *adev = &dmux->component[i];
r9498r9499
327313            }
328314         }
329315      }
330   }   
316   }
331317
332318   // Takes three cycles
333319   cpu_adjust_icount(device->machine->device("maincpu"),-3);
r9498r9499
362348
363349   for (int index = 0; index < MAXDEV; index++)
364350   {
365      dmux->component[index].device = NULL;     
351      dmux->component[index].device = NULL;
366352   }
367353
368354   if (dmux->ram16b==NULL) dmux->ram16b = (UINT16*)malloc(32768);
r9498r9499
374360         running_device *dev = device->machine->device(cons[i].name);
375361         if (dev!=NULL)
376362         {
377            UINT32 set = 0;
363            UINT32 set = 0;
378364            if (cons[i].setting!=NULL)
379365               set = input_port_read(device->machine, cons[i].setting);
380           
366
381367            if (((set & cons[i].set)==cons[i].set)&&((set & cons[i].unset)==0))
382368            {
383369               dmux_mount_device(device, dev, cons[i].address_mask, cons[i].select_pattern, cons[i].write_select, cons[i].read, cons[i].write);
src/mess/machine/ti99/videowrp.h
r9498r9499
11/*
22    TI-99/4(A) and /8 Video subsystem
3   This device actually wraps the naked video chip implementation
3    This device actually wraps the naked video chip implementation
44    Michael Zapf, October 2010
55*/
66
r9498r9499
1919{
2020   TMS9928a_interface         *tmsparam;
2121   int                     chip;
22   void                   (*callback)(running_machine *, int);
23   
22   void                  (*callback)(running_machine *, int);
23
2424} ti99_video_config;
2525
2626READ16_DEVICE_HANDLER( ti_tms991x_r16 );
r9498r9499
4646   MDRV_SCREEN_MODIFY(_screen)                              \
4747   MDRV_SCREEN_REFRESH_RATE(_rate)                           \
4848   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(_blank))
49   
49
5050#define MDRV_TI_V9938_ADD(_tag, _rate, _screen, _blank, _x, _y, _int)      \
5151   MDRV_DEVICE_ADD(_tag, TIVIDEO, 0)                        \
5252   MDRV_DEVICE_CONFIG_DATAPTR(ti99_video_config, tmsparam, NULL)   \
r9498r9499
6161   MDRV_PALETTE_LENGTH(512)   \
6262   MDRV_PALETTE_INIT(v9938)   \
6363   MDRV_VIDEO_UPDATE(generic_bitmapped)
64   
64
6565#endif /* __TIVIDEO__ */
6666
src/mess/machine/ti99/speech8.h
r9498r9499
1414DECLARE_LEGACY_DEVICE( TISPEECH8, ti99_speech8 );
1515
1616#define MDRV_TISPEECH_ADD(_tag)      \
17   MDRV_DEVICE_ADD(_tag, TISPEECH8, 0)   
17   MDRV_DEVICE_ADD(_tag, TISPEECH8, 0)
1818#endif
src/mess/machine/ti99/hfdc.c
r9498r9499
11/*
2   Myarc Hard and Floppy Disk Controller
3   Michael Zapf
2    Myarc Hard and Floppy Disk Controller
3    Michael Zapf
44*/
55#include "emu.h"
66#include "peribox.h"
r9498r9499
1919#define HFDC_MAX_FLOPPY 4
2020#define HFDC_MAX_HARD 4
2121
22#define TAPE_ADDR    0x0fc0
23#define HDC_R_ADDR    0x0fd0
24#define HDC_W_ADDR    0x0fd2
25#define CLK_ADDR    0x0fe0
26#define RAM_ADDR    0x1000
22#define TAPE_ADDR   0x0fc0
23#define HDC_R_ADDR   0x0fd0
24#define HDC_W_ADDR   0x0fd2
25#define CLK_ADDR   0x0fe0
26#define RAM_ADDR   0x1000
2727
2828typedef ti99_pebcard_config ti99_hfdc_config;
2929
r9498r9499
3737
3838   /* Clock divider bit 0. Unused in this emulation. */
3939   int             CD0;
40   
40
4141   /* Clock divider bit 1. Unused in this emulation. */
4242   int               CD1;
43   
43
4444   /* count 4.23s from rising edge of motor_on */
45   emu_timer          *motor_on_timer;
46   
45   emu_timer         *motor_on_timer;
46
4747   /* Link to the HDC9234 controller on the board. */
48   running_device       *controller;
48   running_device      *controller;
4949
5050   /* Link to the clock chip on the board. */
51   running_device       *clock;
52     
51   running_device      *clock;
52
5353   /* Determines whether we have access to the CRU bits. */
5454   int             cru_select;
55   
55
5656   /* IRQ state */
5757   int             irq;
58   
58
5959   /* DMA in Progress state */
6060   int             dip;
61     
61
6262   /* Output 1 latch */
63   UINT8             output1_latch;
63   UINT8            output1_latch;
6464
6565   /* Output 2 latch */
66   UINT8             output2_latch;
67   
66   UINT8            output2_latch;
67
6868   /* Connected floppy drives. */
69   running_device       *floppy_unit[HFDC_MAX_FLOPPY];
70   
69   running_device      *floppy_unit[HFDC_MAX_FLOPPY];
70
7171   /* Connected harddisk drives. */
72   running_device       *harddisk_unit[HFDC_MAX_HARD];
72   running_device      *harddisk_unit[HFDC_MAX_HARD];
7373
7474   /* DMA address latch */
75   UINT32             dma_address;
76   
75   UINT32            dma_address;
76
7777   /* DSR ROM */
7878   UINT8            *rom;
79   
79
8080   /* ROM banks. */
8181   int             rom_offset;
8282
8383   /* HFDC RAM */
84   UINT8             *ram;
85   
86   /* RAM banks */   
84   UINT8            *ram;
85
86   /* RAM banks */
8787   int             ram_offset[4];
88   
88
8989   /* Callback lines to the main system. */
9090   ti99_peb_connect   lines;
91   
91
9292} ti99_hfdc_state;
9393
9494INLINE ti99_hfdc_state *get_safe_token(running_device *device)
r9498r9499
129129    xx04          DMA in progress
130130
131131    Note that the cru line settings on the board do not match the
132    description in the manual. 02 and 04 swap their positions (checked with
132    description in the manual. 02 and 04 swap their positions (checked with
133133    board and schematics). Similarly, the dip switches
134134    for the drive configurations are not correctly enumerated in the manual.
135135
r9498r9499
150150*/
151151static READ8Z_DEVICE_HANDLER( cru_r )
152152{
153   ti99_hfdc_state *card = get_safe_token(device);
153   ti99_hfdc_state *card = get_safe_token(device);
154154   UINT8 reply;
155   
155
156156   if ((offset & 0xff00)==CRU_BASE)
157157   {
158158      if ((offset & 0x00ff)==0)  /* CRU bits 0-7 */
r9498r9499
161161         if (card->cru_select)
162162         {
163163            /* DIP switches.  Logic levels are inverted (on->0, off->1).  CRU
164            bit order is the reverse of DIP-switch order, too (dip 1 -> bit 7,
165            dip 8 -> bit 0).
166           
167            MZ: 00 should not be used since there is a bug in the
168            DSR of the HFDC which causes problems with SD disks
169            (controller tries DD and then fails to fall back to SD) */           
164                bit order is the reverse of DIP-switch order, too (dip 1 -> bit 7,
165                dip 8 -> bit 0).
166
167                MZ: 00 should not be used since there is a bug in the
168                DSR of the HFDC which causes problems with SD disks
169                (controller tries DD and then fails to fall back to SD) */
170170            reply = ~(input_port_read(device->machine, "HFDCDIP"));
171171         }
172172         else
173173         {
174174            reply = 0;
175           
176            if (card->irq)          reply |= 0x01;
175
176            if (card->irq)         reply |= 0x01;
177177            if (card->dip)         reply |= 0x02;
178178            if (card->strobe_motor)   reply |= 0x04;
179179         }
r9498r9499
194194    04                  Floppy Motor on / CD0           HIGH
195195    06                  ROM page select 0 / CD1
196196    08                  ROM page select 1 / CRU input select
197    12/4/6/8/A          RAM page select at 0x5400
197    12/4/6/8/A          RAM page select at 0x5400
198198    1C/E/0/2/4          RAM page select at 0x5800
199199    26/8/A/C/E          RAM page select at 0x5C00
200200
201201    RAM bank select: bank 0..31; 12 = LSB (accordingly for other two areas)
202202    ROM bank select: bank 0..3; 06 = MSB, 07 = LSB
203    Bit number = (CRU_rel_address - base_address)/2
203    Bit number = (CRU_rel_address - base_address)/2
204204    CD0 and CD1 are Clock Divider selections for the Floppy Data Separator (FDC9216)
205205*/
206206static WRITE8_DEVICE_HANDLER( cru_w )
207207{
208   ti99_hfdc_state *card = get_safe_token(device);
208   ti99_hfdc_state *card = get_safe_token(device);
209209
210210   if ((offset & 0xff00)==CRU_BASE)
211211   {
r9498r9499
254254         break;
255255
256256      default:
257          logerror("ti99/HFDC: Attempt to set undefined CRU bit %d\n", bit);
257          logerror("ti99/HFDC: Attempt to set undefined CRU bit %d\n", bit);
258258      }
259259   }
260260}
r9498r9499
277277
278278static READ8Z_DEVICE_HANDLER( data_r )
279279{
280   ti99_hfdc_state *card = get_safe_token(device);
280   ti99_hfdc_state *card = get_safe_token(device);
281281
282282   if (card->selected && (offset & 0xe000)==0x4000)
283283   {
r9498r9499
292292               logerror("ti99/HFDC: Tape support not available (access to address %04x)\n", offset);
293293               return;
294294            }
295           
295
296296            // HDC9234: 4fd0..4fdf / read: 4fd0,4 (mirror 8,c)
297297            // read: 0100 1111 1101 xx00
298298            if ((offset & 0x1ff3)==HDC_R_ADDR)
r9498r9499
300300               *value = smc92x4_r(card->controller, (offset>>2)&1);
301301               return;
302302            }
303           
303
304304            if ((offset & 0x1fe1)==CLK_ADDR)
305305            {
306306               *value = mm58274c_r(card->clock, (offset & 0x001e) >> 1);
r9498r9499
314314            return;
315315         }
316316      }
317     
317
318318      // RAM: 0101 xxxx xxxx xxxx
319319      if ((offset & 0x1000)==RAM_ADDR)
320320      {
r9498r9499
333333*/
334334static WRITE8_DEVICE_HANDLER( data_w )
335335{
336   ti99_hfdc_state *card = get_safe_token(device);
336   ti99_hfdc_state *card = get_safe_token(device);
337337   if (card->selected && (offset & 0xe000)==0x4000)
338   {     
338   {
339339      // Tape: 4fc0...4fcf
340340      if ((offset & 0x1ff0)==TAPE_ADDR)
341341      {
342342         logerror("ti99/HFDC: Tape support not available (access to address %04x)\n", offset);
343343         return;
344344      }
345     
345
346346      // HDC9234: 4fd0..4fdf / write: 4fd2,6 (mirror a,e)
347347      // write: 0100 1111 1101 xx10
348348      if ((offset & 0x1ff3)==HDC_W_ADDR)
r9498r9499
350350         smc92x4_w(card->controller, (offset>>2)&1, data);
351351         return;
352352      }
353     
353
354354      if ((offset & 0x1fe1)==CLK_ADDR)
355355      {
356356         mm58274c_w(card->clock, (offset & 0x001e) >> 1, data);
357357         return;
358358      }
359     
359
360360      // RAM: 0101 xxxx xxxx xxxx
361361      if ((offset & 0x1000)==RAM_ADDR)
362362      {
r9498r9499
375375*/
376376static WRITE_LINE_DEVICE_HANDLER( intrq_w )
377377{
378   // Note that the callback functions deliver the calling device, which is
378   // Note that the callback functions deliver the calling device, which is
379379   // the controller in this case.
380   ti99_hfdc_state *card = get_safe_token(device->owner());
380   ti99_hfdc_state *card = get_safe_token(device->owner());
381381   card->irq = state;
382382
383383   /* Set INTA */
r9498r9499
396396*/
397397static WRITE_LINE_DEVICE_HANDLER( dip_w )
398398{
399   ti99_hfdc_state *card = get_safe_token(device->owner());
399   ti99_hfdc_state *card = get_safe_token(device->owner());
400400   card->dip = state;
401401}
402402
403403// device ok
404404static WRITE8_DEVICE_HANDLER( auxbus_out )
405405{
406   ti99_hfdc_state *card = get_safe_token(device->owner());
406   ti99_hfdc_state *card = get_safe_token(device->owner());
407407   switch (offset)
408408   {
409409   case INPUT_STATUS:
410410      logerror("ti99/HFDC: Invalid operation: S0=S1=0, but tried to write (expected: read drive status)\n");
411411      break;
412     
412
413413   case OUTPUT_DMA_ADDR:
414414      /* Value is dma address byte. Shift previous contents to the left. */
415415      card->dma_address = ((card->dma_address << 8) + (data&0xff))&0xffffff;
r9498r9499
469469}
470470
471471/*
472   Select the HFDC hard disk unit
473   This function implements the selection logic on the PCB (outside the
474   controller chip)
475   The HDC9234 allows up to four drives to be selected by the select lines.
476   This is not enough for controlling four floppy drives and three hard
477   drives, so the user programmable outputs are used to select the floppy
478   drives. This selection happens completely outside of the controller,
479   so we must implement it here.
472    Select the HFDC hard disk unit
473    This function implements the selection logic on the PCB (outside the
474    controller chip)
475    The HDC9234 allows up to four drives to be selected by the select lines.
476    This is not enough for controlling four floppy drives and three hard
477    drives, so the user programmable outputs are used to select the floppy
478    drives. This selection happens completely outside of the controller,
479    so we must implement it here.
480480*/
481481
482482static running_device *current_harddisk(running_device *controller)
r9498r9499
496496
497497static READ_LINE_DEVICE_HANDLER( auxbus_in )
498498{
499   ti99_hfdc_state *card = get_safe_token(device->owner());
499   ti99_hfdc_state *card = get_safe_token(device->owner());
500500   running_device *drive;
501501   UINT8 reply = 0;
502502
r9498r9499
528528      UINT8 state;
529529      drive = current_harddisk(device);
530530      state = ti99_mfm_harddisk_status(drive);
531      if (state & MFMHD_TRACK00)       reply |= DS_TRK00;
531      if (state & MFMHD_TRACK00)      reply |= DS_TRK00;
532532      if (state & MFMHD_SEEKCOMP)      reply |= DS_SKCOM;
533533      if (state & MFMHD_WRFAULT)      reply |= DS_WRFAULT;
534534      if (state & MFMHD_INDEX)      reply |= DS_INDEX;
r9498r9499
543543*/
544544static UINT8 hfdc_dma_read_callback(running_device *device)
545545{
546   ti99_hfdc_state *card = get_safe_token(device->owner());
546   ti99_hfdc_state *card = get_safe_token(device->owner());
547547   UINT8 value = card->ram[card->dma_address & 0x7fff];
548548   card->dma_address++;
549549   return value;
r9498r9499
554554*/
555555static void hfdc_dma_write_callback(running_device *device, UINT8 data)
556556{
557   ti99_hfdc_state *card = get_safe_token(device->owner());
557   ti99_hfdc_state *card = get_safe_token(device->owner());
558558   card->ram[card->dma_address & 0x7fff] = data;
559559   card->dma_address++;
560560}
r9498r9499
633633   hfdc_harddisk_write_track
634634};
635635
636static ti99_peb_card hfdc_card =
636static ti99_peb_card hfdc_card =
637637{
638638   data_r,
639639   data_w,
640640   cru_r,
641641   cru_w,
642   
643   NULL, NULL,   NULL, NULL   
642
643   NULL, NULL,   NULL, NULL
644644};
645645
646646static DEVICE_START( ti99_hfdc )
647647{
648648   ti99_hfdc_state *card = (ti99_hfdc_state*)downcast<legacy_device_base *>(device)->token();
649   
649
650650   /* Resolve the callbacks to the PEB */
651651   peb_callback_if *topeb = (peb_callback_if *)device->baseconfig().static_config();
652652   devcb_resolve_write_line(&card->lines.inta, &topeb->inta, device);
653653   // The HFDC does not use READY; it has on-board RAM for DMA
654   
654
655655   card->motor_on_timer = timer_alloc(device->machine, motor_on_timer_callback, (void *)device);
656656   card->ram = NULL;
657657   card->ram_offset[0] = 0x2000; // static bank
658658   card->controller = device->subdevice("smc92x4");
659659   card->clock = device->subdevice("mm58274c");
660660   astring *region = new astring();
661   astring_assemble_3(region, device->tag(), ":", hfdc_region);   
661   astring_assemble_3(region, device->tag(), ":", hfdc_region);
662662   card->rom = memory_region(device->machine, astring_c(region));
663663}
664664
r9498r9499
677677   /* If the card is selected in the menu, register the card */
678678   if (input_port_read(device->machine, "DISKCTRL") == DISK_HFDC)
679679   {
680      running_device *peb = device->owner();   
680      running_device *peb = device->owner();
681681      int success = mount_card(peb, device, &hfdc_card, get_pebcard_config(device)->slot);
682682      if (!success) return;
683           
683
684684      // Allocate 32 KiB for on-board buffer memory
685      if (card->ram==NULL)
685      if (card->ram==NULL)
686686      {
687687         card->ram = (UINT8*)malloc(32768);
688//         memset(card->ram, 0, 32768);
688//          memset(card->ram, 0, 32768);
689689      }
690     
690
691691      if (input_port_read(device->machine, "HFDCDIP")&0x55)
692692         ti99_set_80_track_drives(TRUE);
693693      else
694694         ti99_set_80_track_drives(FALSE);
695     
695
696696      smc92x4_set_timing(card->controller, input_port_read(device->machine, "DRVSPD"));
697     
697
698698      // Connect floppy drives to controller. Note that *this* is the
699699      // controller, not the controller chip. The pcb contains a select
700700      // logic.
r9498r9499
702702      for (i = 0; i < 4; i++)
703703      {
704704         card->floppy_unit[i] = device->siblingdevice(flopname[i]);
705         
705
706706         if (card->floppy_unit[i]!=NULL)
707707         {
708708            floppy_drive_set_controller(card->floppy_unit[i], device);
r9498r9499
714714            logerror("hfdc: Image %s is null\n", flopname[i]);
715715         }
716716      }
717     
717
718718      /* In the HFDC ROM, WDSx selects drive x; drive 0 is not used */
719719      for (i = 1; i < 4; i++)
720720      {
src/mess/machine/ti99/ti_rs232.c
r9498r9499
11/*
22    TI-99 RS232 and Parallel interface card
3   Currently this emulation does not interact with the serial interface
4   on the host computer. Planned for a later release.
5   As most serial applications require a feedback from the receiver's side
6   the serial interface implementation will usually *not* work.
7   
8   TI99 RS232 card ('rs232')
9   TMS9902 ('rs232:tms9902_0')
10   TMS9902 ('rs232:tms9902_1')
11   TI99 RS232 attached serial device ('rs232:serdev0')
12   TI99 RS232 attached serial device ('rs232:serdev1')
13   TI99 PIO attached parallel device ('rs232:piodev')
14   
3    Currently this emulation does not interact with the serial interface
4    on the host computer. Planned for a later release.
5    As most serial applications require a feedback from the receiver's side
6    the serial interface implementation will usually *not* work.
7
8    TI99 RS232 card ('rs232')
9    TMS9902 ('rs232:tms9902_0')
10    TMS9902 ('rs232:tms9902_1')
11    TI99 RS232 attached serial device ('rs232:serdev0')
12    TI99 RS232 attached serial device ('rs232:serdev1')
13    TI99 PIO attached parallel device ('rs232:piodev')
14
1515*/
1616#include "emu.h"
1717#include "peribox.h"
r9498r9499
2727// Second card: Change CRU base to 0x1500
2828// #define CRU_BASE 0x1500
2929
30typedef ti99_pebcard_config ti_rs232_config;
30typedef ti99_pebcard_config ti_rs232_config;
3131
3232typedef struct _ti_rs232_state
3333{
3434   running_device *uart0, *uart1, *serdev0, *serdev1, *piodev;
3535
3636   int    selected;
37   
37
3838   // PIO flags
3939   int pio_direction;      // a.k.a. PIOOC pio in output mode if 0
4040   int pio_handshakeout;
r9498r9499
5050   int pio_readable;
5151   int pio_writable;
5252   int pio_write;         // 1 if image is to be written to
53     
54   UINT8    *rom;
55   
53
54   UINT8   *rom;
55
5656   /* Keeps the state of the SENILA line. */
5757   UINT8   senila;
58   
58
5959   /* Keeps the value put on the bus when SENILA becomes active. */
60   UINT8    ila;
61   
60   UINT8   ila;
61
6262   /* Callback lines to the main system. */
6363   ti99_peb_connect   lines;
64   
64
6565} ti_rs232_state;
6666
6767INLINE ti_rs232_state *get_safe_token(running_device *device)
r9498r9499
110110   {
111111      tms9902 = image.device().siblingdevice("tms9902_0");
112112   }
113   else if (devnumber==1)
113   else if (devnumber==1)
114114   {
115115      tms9902 = image.device().siblingdevice("tms9902_1");
116116   }
r9498r9499
119119      logerror("ti99/rs232: Could not find device tag number\n");
120120      return IMAGE_INIT_FAIL;
121121   }
122   
122
123123   if (image)
124124   {
125125      tms9902_set_cts(tms9902, 1);
r9498r9499
140140static DEVICE_IMAGE_LOAD( ti99_piodev )
141141{
142142   running_device *carddev = image.device().owner();
143   ti_rs232_state *card = get_safe_token(carddev);
143   ti_rs232_state *card = get_safe_token(carddev);
144144
145145   /* tell whether the image is writable */
146146   card->pio_readable = !image.has_been_created();
r9498r9499
161161static DEVICE_IMAGE_UNLOAD( ti99_piodev )
162162{
163163   running_device *carddev = image.device().owner();
164   ti_rs232_state *card = get_safe_token(carddev);
164   ti_rs232_state *card = get_safe_token(carddev);
165165
166166   card->pio_writable = 0;
167167   card->pio_handshakein = 1;   /* receiver not ready */
r9498r9499
175175*/
176176static READ8Z_DEVICE_HANDLER( cru_rz )
177177{
178   ti_rs232_state *card = get_safe_token(device);
178   ti_rs232_state *card = get_safe_token(device);
179179
180180   if ((offset & 0xff00)==CRU_BASE)
181181   {
r9498r9499
195195         if (card->cts2)
196196            reply |= 0x40;
197197         if (card->led)
198            reply |= 0x80;         
198            reply |= 0x80;
199199         *value = reply;
200200         return;
201201      }
r9498r9499
213213}
214214
215215/*
216   CRU write
216    CRU write
217217*/
218218static WRITE8_DEVICE_HANDLER( cru_w )
219219{
220   ti_rs232_state *card = get_safe_token(device);
220   ti_rs232_state *card = get_safe_token(device);
221221
222222   if ((offset & 0xff00)==CRU_BASE)
223223   {
r9498r9499
239239      case 0:
240240         card->selected = data;
241241         break;
242         
242
243243      case 1:
244244         card->pio_direction = data;
245245         break;
246         
246
247247      case 2:
248248         if (data != card->pio_handshakeout)
249249         {
r9498r9499
284284            }
285285         }
286286         break;
287         
287
288288      case 3:
289289         card->pio_spareout = data;
290290         break;
291         
291
292292      case 4:
293293         card->flag0 = data;
294294         break;
295         
295
296296      case 5:
297297         card->cts1 = data;
298298         break;
299         
299
300300      case 6:
301301         card->cts2 = data;
302302         break;
303         
303
304304      case 7:
305305         card->led = data;
306306         break;
r9498r9499
314314*/
315315static READ8Z_DEVICE_HANDLER( data_rz )
316316{
317   ti_rs232_state *card = get_safe_token(device);
317   ti_rs232_state *card = get_safe_token(device);
318318
319319   if (card->senila)
320320   {
r9498r9499
328328      // lines are there.
329329      card->ila = 0;
330330   }
331   if (((offset & 0xe000)==0x4000) && card->selected)
331   if (((offset & 0xe000)==0x4000) && card->selected)
332332   {
333333      if ((offset & 0x1000)==0x0000)
334334      {
r9498r9499
342342}
343343
344344/*
345   Memory write
345    Memory write
346346*/
347347static WRITE8_DEVICE_HANDLER( data_w )
348348{
349   ti_rs232_state *card = get_safe_token(device);
349   ti_rs232_state *card = get_safe_token(device);
350350
351   if (((offset & 0xe000)==0x4000) && card->selected)
351   if (((offset & 0xe000)==0x4000) && card->selected)
352352   {
353353      if ((offset & 0x1001)==0x1000)
354354      {
r9498r9499
365365static TMS9902_INT_CALLBACK( int_callback_0 )
366366{
367367   running_device *carddev = device->owner();
368   ti_rs232_state *card = get_safe_token(carddev);
369   if (INT)
370      card->ila |= SENILA_0_BIT;
368   ti_rs232_state *card = get_safe_token(carddev);
369   if (INT)
370      card->ila |= SENILA_0_BIT;
371371   else
372      card->ila &= ~SENILA_0_BIT;
373     
372      card->ila &= ~SENILA_0_BIT;
373
374374   devcb_call_write_line(&card->lines.inta, INT);
375375}
376376
377377static TMS9902_INT_CALLBACK( int_callback_1 )
378378{
379379   running_device *carddev = device->owner();
380   ti_rs232_state *card = get_safe_token(carddev);
381   if (INT)
382      card->ila |= SENILA_1_BIT;
380   ti_rs232_state *card = get_safe_token(carddev);
381   if (INT)
382      card->ila |= SENILA_1_BIT;
383383   else
384      card->ila &= ~SENILA_1_BIT;
385   
384      card->ila &= ~SENILA_1_BIT;
385
386386   devcb_call_write_line(&card->lines.inta, INT);
387387}
388388
r9498r9499
434434};
435435
436436
437static ti99_peb_card tirs232_card =
437static ti99_peb_card tirs232_card =
438438{
439439   data_rz, data_w,            // memory access read/write
440440   cru_rz, cru_w,               // CRU access
441   senila, NULL,               // SENILA/B access
441   senila, NULL,               // SENILA/B access
442442   NULL, NULL                  // 16 bit access (none here)
443443};
444444
445445/*
446   Defines the serial serdev.
446    Defines the serial serdev.
447447*/
448448DEVICE_GET_INFO( ti99_rs232_serdev )
449449{
r9498r9499
456456      case DEVINFO_INT_IMAGE_CREATABLE:          info->i = 1;                                               break;
457457
458458      case DEVINFO_FCT_START:                      info->start = DEVICE_START_NAME( ti99_rs232_serdev );              break;
459//      case DEVINFO_FCT_RESET:                  info->reset = DEVICE_RESET_NAME( ti99_rs232_serdev );         break;
459//      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME( ti99_rs232_serdev );           break;
460460      case DEVINFO_FCT_IMAGE_LOAD:              info->f = (genf *) DEVICE_IMAGE_LOAD_NAME( ti99_rs232_serdev );    break;
461461      case DEVINFO_STR_NAME:                      strcpy( info->s, "TI99 RS232 attached serial device");                            break;
462462      case DEVINFO_STR_FAMILY:                    strcpy(info->s, "Peripheral expansion");                            break;
r9498r9499
468468}
469469
470470/*
471   Defines the PIO (parallel IO) serdev
471    Defines the PIO (parallel IO) serdev
472472*/
473473DEVICE_GET_INFO( ti99_piodev )
474474{
r9498r9499
503503   peb_callback_if *topeb = (peb_callback_if *)device->baseconfig().static_config();
504504
505505   astring *region = new astring();
506   astring_assemble_3(region, device->tag(), ":", ser_region);   
506   astring_assemble_3(region, device->tag(), ":", ser_region);
507507   card->rom = memory_region(device->machine, astring_c(region));
508508   devcb_resolve_write_line(&card->lines.inta, &topeb->inta, device);
509509   // READY and INTB are not used
r9498r9499
523523   ti_rs232_state *card = (ti_rs232_state*)downcast<legacy_device_base *>(device)->token();
524524   /* Register the card */
525525   running_device *peb = device->owner();
526   
526
527527   if (input_port_read(device->machine, "SERIAL")==SERIAL_TI)
528528   {
529529      int success = mount_card(peb, device, &tirs232_card, get_pebcard_config(device)->slot);
r9498r9499
545545   MDRV_TMS9902_ADD("tms9902_1", tms9902_params_1)
546546   MDRV_DEVICE_ADD("serdev0", TI99_RS232, 0)
547547   MDRV_DEVICE_ADD("serdev1", TI99_RS232, 0)
548   MDRV_DEVICE_ADD("piodev", TI99_PIO, 0)   
548   MDRV_DEVICE_ADD("piodev", TI99_PIO, 0)
549549MACHINE_CONFIG_END
550550
551551ROM_START( ti_rs232 )
src/mess/machine/ti99/peribox.c
r9498r9499
2424    June 2010: Reimplemented using device structure (MZ) (obsoletes 99_peb.c)
2525
2626Slots:
27   
27
2828          REAR
2929     +8V  1||2   +8V
3030     GND  3||4   READY
r9498r9499
3535   HOLD* 13||14  IAQHDA
3636 SENILA* 15||16  SENILB*
3737  INTA*  17||18  INTB*
38     D7  19||20  GND 
38     D7  19||20  GND
3939     D5  21||22  D6
4040     D3  23||24  D4
4141     D1  25||26  D2
r9498r9499
4444    A12  31||32  A13
4545    A10  33||34  A11
4646     A8  35||36  A9
47     A6  37||38  A7   
47     A6  37||38  A7
4848     A4  39||40  A5
4949     A2  41||42  A3
5050     A0  43||44  A1
51    AMB  45||46  AMA
51    AMB  45||46  AMA
5252    GND  47||48  AMC
5353    GND  49||50  CLKOUT*
5454CRUCLK*  51||52  DBIN
r9498r9499
6060
6161        < from box to console
6262        > from console into box
63
63
6464READYA  <    System ready (goes to READY, 10K pull-up to +5V) A low level puts the cpu on hold.
65RESET*  >    System reset (active low)
66SCLK    nc   System clock (not connected in interface card)
67LCP*    nc   CPU indicator 1=TI99 0=2nd generation (not connected in interface card)
65RESET*  >    System reset (active low)
66SCLK    nc   System clock (not connected in interface card)
67LCP*    nc   CPU indicator 1=TI99 0=2nd generation (not connected in interface card)
6868BOOTPG* nc   ?
69AUDIO   <    Input audio (to AUDIOIN in console)
70RDBENA* <    Active low: enable flex cable data bus drivers (1K pull-up)
71PCBEN   H    PCB enable for burn-in (always High)
72HOLD*   H    Active low CPU hold request (always High)
73IAQHDA  nc   IAQ [or] HOLDA (logical or)
74SENILA* H(>) Interrupt level A sense enable (always High)
75SENILB* H(>) Interrupt level B sense enable (always High)
76INTA*   <    Interrupt level A (active low, goes to EXTINT*)
77INTB*   nc   Interrupt level B (not used)
78LOAD*   nc   Unmaskable interrupt (not carried by interface cable/card)
79D0-D7   <>   Data bus (D0 most significant)
69AUDIO   <    Input audio (to AUDIOIN in console)
70RDBENA* <    Active low: enable flex cable data bus drivers (1K pull-up)
71PCBEN   H    PCB enable for burn-in (always High)
72HOLD*   H    Active low CPU hold request (always High)
73IAQHDA  nc   IAQ [or] HOLDA (logical or)
74SENILA* H(>) Interrupt level A sense enable (always High)
75SENILB* H(>) Interrupt level B sense enable (always High)
76INTA*   <    Interrupt level A (active low, goes to EXTINT*)
77INTB*   nc   Interrupt level B (not used)
78LOAD*   nc   Unmaskable interrupt (not carried by interface cable/card)
79D0-D7   <>   Data bus (D0 most significant)
8080A0-A15  >    Address bus (A0 most sig; A15 also used as CRUOUT)
8181AMA/B/C H    Extra address bits (always high for TI-99/4x)
8282CLKOUT* >    Inverted PHI3 clock, from TIM9904 clock generator
r9498r9499
8484DBIN    >    Active high = read memory. Drives the data bus buffers.
8585WE*     >    Write Enable pulse (derived from TMS9900 WE* pin)
8686CRUIN   <    CRU input bit to TMS9900
87MEMEN*  >    Memory access enable (active low)
87MEMEN*  >    Memory access enable (active low)
8888
8989
9090The obscure SENILx lines:
9191
92With SENILA* going low, a value shall be put on the data bus,
93representing the interrupt status bits. It can also be used to determine
94the source of the interrupt: The RS232 card (in its standard configuration)
95uses the data bus bits 0 and 1 for its two UARTs, while in the second
96configuration, it uses bits 4 and 5. Still note that the TI-99/4x does not make
92With SENILA* going low, a value shall be put on the data bus,
93representing the interrupt status bits. It can also be used to determine
94the source of the interrupt: The RS232 card (in its standard configuration)
95uses the data bus bits 0 and 1 for its two UARTs, while in the second
96configuration, it uses bits 4 and 5. Still note that the TI-99/4x does not make
9797use of SENILA*.
9898
9999SENILB* / INTB* was planned to be used with disk controllers. The PHP1240 disk
100100controller puts the value of INTB* on D0 when SENILB* gets active (low) which
101reflects the INTRQ output pin of the WD1771. This signal is not used, however.
101reflects the INTRQ output pin of the WD1771. This signal is not used, however.
102102Instead, the disk controller combines DRQ and IRQ and makes use of a READY/HOLD
103103control of the CPU.
104104
105Obviously, SENILA* and SENILB* should never be active at the same time, and
106neither should any memory access to a card be active at the same time, for in
105Obviously, SENILA* and SENILB* should never be active at the same time, and
106neither should any memory access to a card be active at the same time, for in
107107both cases, data bus lines may be set to different levels simultaneously. One
108possible application case is to turn off all cards in the box, lower SENILA*,
108possible application case is to turn off all cards in the box, lower SENILA*,
109109and then do a read access in the memory area of any card in the P-Box (e.g.
1101100x4000-0x5fff). Another possiblity is that the currently active card simply
111111does not respond to a certain memory access, and in this case the status bits
r9498r9499
113113
114114Also note that the SENILx lines access all cards in parallel, meaning that there
115115must be an agreement which cards may use which bits on the data bus. The lines
116do not depend on the card being active at that time.
116do not depend on the card being active at that time.
117117*/
118118
119119#include "emu.h"
r9498r9499
150150
151151typedef struct _ti99_peb_slot
152152{
153   running_device       *card;
154   ti99_peb_card       *intf;
153   running_device      *card;
154   ti99_peb_card      *intf;
155155} ti99_peb_slot;
156156
157157typedef struct _ti99_peb_state
r9498r9499
165165   UINT32               ready_state;
166166
167167   int                  highest;
168   
168
169169   // Callback to the main system
170170   ti99_peb_connect      lines;
171   
171
172172} ti99_peb_state;
173173
174174INLINE ti99_peb_state *get_safe_token(running_device *device)
r9498r9499
227227}
228228
229229/*
230   Declares the callbacks above that are called from the cards. This instance
231   is passed to the cards with MDRV_PBOXCARD_ADD and must be handled as a
232   static_config.
230    Declares the callbacks above that are called from the cards. This instance
231    is passed to the cards with MDRV_PBOXCARD_ADD and must be handled as a
232    static_config.
233233*/
234const peb_callback_if peb_callback =
235{
236   DEVCB_LINE( inta ),
237   DEVCB_LINE( intb ),
238   DEVCB_LINE( ready )
234const peb_callback_if peb_callback =
235{
236   DEVCB_LINE( inta ),
237   DEVCB_LINE( intb ),
238   DEVCB_LINE( ready )
239239};
240240
241241/*
242   Mount the PEB card. Although possible, this is not done by the box itself;
243   instead, the card must call this function on the box. The advantage is
244   that we can assign the same slot to different cards which are selected
245   by dip switches. Only the card which is selected will register itself; the
246   other cards are stillborn.
247   Returns TRUE when the card could be mounted.
242    Mount the PEB card. Although possible, this is not done by the box itself;
243    instead, the card must call this function on the box. The advantage is
244    that we can assign the same slot to different cards which are selected
245    by dip switches. Only the card which is selected will register itself; the
246    other cards are stillborn.
247    Returns TRUE when the card could be mounted.
248248*/
249249int mount_card(running_device *device, running_device *cardptr, ti99_peb_card *cardintf, int slotindex)
250250{
r9498r9499
265265      }
266266   }
267267   else
268      logerror("ti99_peb: Invalid slot number %d\n", slotindex);
268      logerror("ti99_peb: Invalid slot number %d\n", slotindex);
269269   return FALSE;
270270}
271271
r9498r9499
324324}
325325
326326/*
327   For SGCPU
327    For SGCPU
328328*/
329329READ16Z_DEVICE_HANDLER( ti99_peb_data16_rz )
330330{
r9498r9499
338338}
339339
340340/*
341   For SGCPU
341    For SGCPU
342342*/
343343WRITE16_DEVICE_HANDLER( ti99_peb_data16_w )
344344{
r9498r9499
352352}
353353
354354/*
355   SENILx
356   TODO: Check whether device is the correct pointer (seems to be wrong here,
357   the device is usually the caller)
355    SENILx
356    TODO: Check whether device is the correct pointer (seems to be wrong here,
357    the device is usually the caller)
358358*/
359359WRITE_LINE_DEVICE_HANDLER( ti99_peb_senila )
360360{
r9498r9499
389389
390390   for (int slotindex=0; slotindex < MAXSLOTS; slotindex++)
391391      unmount_card(device, slotindex);
392   
392
393393   /* Resolve the callbacks to the console */
394394   devcb_write_line inta = DEVCB_LINE(pebconf->inta);
395395   devcb_write_line intb = DEVCB_LINE(pebconf->intb);
r9498r9499
409409{
410410   ti99_peb_state *peb = get_safe_token(device);
411411   logerror("ti99_peb: reset\n");
412   peb->inta_state = 0;   
413   peb->intb_state = 0;   
412   peb->inta_state = 0;
413   peb->intb_state = 0;
414414   peb->ready_state = 0;
415415   peb->highest = 0;
416416   for (int i=0; i < MAXSLOTS; i++) unmount_card(device, i);
r9498r9499
422422   MDRV_DEVICE_CONFIG( peb_callback )
423423
424424/*
425   We're emulating a "super box" with more than 8 slots. The original
426   box had 8 slots, but that's a bit too limiting.
427   This may become organized differently in future versions; for now
428   we'll go this way.
429   
430   Slot 0 is the "Flex cable interface" / SGCPU / Geneve
431   We assign the same slot number for some cards that cannot be used
432   in parallel anyway. The config switch will determine which one to use.
433   Future works:   
434   // WHTech SCSI controller
435   // MDRV_PBOXCARD_ADD("SCSI", 4, scsi_intf)
425    We're emulating a "super box" with more than 8 slots. The original
426    box had 8 slots, but that's a bit too limiting.
427    This may become organized differently in future versions; for now
428    we'll go this way.
436429
437   // Horizon Ramdisk
438   // MDRV_PBOXCARD_ADD("HRD", 10, ramdisk_intf)
439*/
430    Slot 0 is the "Flex cable interface" / SGCPU / Geneve
431    We assign the same slot number for some cards that cannot be used
432    in parallel anyway. The config switch will determine which one to use.
433    Future works:
434    // WHTech SCSI controller
435    // MDRV_PBOXCARD_ADD("SCSI", 4, scsi_intf)
440436
437    // Horizon Ramdisk
438    // MDRV_PBOXCARD_ADD("HRD", 10, ramdisk_intf)
439*/
440
441441static MACHINE_CONFIG_FRAGMENT( ti99_peb )
442   MDRV_PBOXCARD_ADD( "mem_ti32k",    TI32KMEM, 1 )
443   MDRV_PBOXCARD_ADD( "mem_sams1m",    SAMSMEM,  1 )
444   MDRV_PBOXCARD_ADD( "mem_myarc512",    MYARCMEM, 1 ) 
445   MDRV_PBOXCARD_ADD( "speech",       TISPEECH, 2 ) 
446   MDRV_PBOXCARD_ADD( "usbsmart",       USBSMART, 3 )
447   MDRV_PBOXCARD_ADD( "ide",          TNIDE,      4 )
448   MDRV_PBOXCARD_ADD( "hsgpl",       HSGPL,    5 )
449   MDRV_PBOXCARD_ADD( "rs232_card",    TIRS232,  7 )
450   MDRV_PBOXCARD_ADD( "ti_fdc",       TIFDC,      8 )
451   MDRV_PBOXCARD_ADD( "hfdc",          HFDC,      8 )
452   MDRV_PBOXCARD_ADD( "bwg",          BWG,      8 )
453   
442   MDRV_PBOXCARD_ADD( "mem_ti32k",    TI32KMEM, 1 )
443   MDRV_PBOXCARD_ADD( "mem_sams1m",   SAMSMEM,  1 )
444   MDRV_PBOXCARD_ADD( "mem_myarc512",   MYARCMEM, 1 )
445   MDRV_PBOXCARD_ADD( "speech",      TISPEECH, 2 )
446   MDRV_PBOXCARD_ADD( "usbsmart",      USBSMART, 3 )
447   MDRV_PBOXCARD_ADD( "ide",         TNIDE,     4 )
448   MDRV_PBOXCARD_ADD( "hsgpl",       HSGPL,    5 )
449   MDRV_PBOXCARD_ADD( "rs232_card",   TIRS232,  7 )
450   MDRV_PBOXCARD_ADD( "ti_fdc",      TIFDC,     8 )
451   MDRV_PBOXCARD_ADD( "hfdc",         HFDC,     8 )
452   MDRV_PBOXCARD_ADD( "bwg",         BWG,     8 )
453
454454   MDRV_FLOPPY_4_DRIVES_ADD(ti99_4_floppy_config)
455455   MDRV_MFMHD_3_DRIVES_ADD()
456456MACHINE_CONFIG_END
457457
458458static MACHINE_CONFIG_FRAGMENT( ti994a_peb )
459   MDRV_PBOXCARD_ADD( "mem_ti32k",    TI32KMEM, 1 )
460   MDRV_PBOXCARD_ADD( "mem_sams1m",    SAMSMEM,  1 )
461   MDRV_PBOXCARD_ADD( "mem_myarc512",    MYARCMEM, 1 ) 
462   MDRV_PBOXCARD_ADD( "speech",       TISPEECH, 2 ) 
463   MDRV_PBOXCARD_ADD( "usbsmart",       USBSMART, 3 )
464   MDRV_PBOXCARD_ADD( "ide",          TNIDE,      4 )
465   MDRV_PBOXCARD_ADD( "hsgpl",       HSGPL,    5 )
466   MDRV_PBOXCARD_ADD( "p_code_card",    PCODEN,   6 )
467   MDRV_PBOXCARD_ADD( "rs232_card",    TIRS232,  7 )
468   MDRV_PBOXCARD_ADD( "ti_fdc",       TIFDC,      8 )
469   MDRV_PBOXCARD_ADD( "hfdc",          HFDC,      8 )
470   MDRV_PBOXCARD_ADD( "bwg",          BWG,      8 )
471   
459   MDRV_PBOXCARD_ADD( "mem_ti32k",    TI32KMEM, 1 )
460   MDRV_PBOXCARD_ADD( "mem_sams1m",   SAMSMEM,  1 )
461   MDRV_PBOXCARD_ADD( "mem_myarc512",   MYARCMEM, 1 )
462   MDRV_PBOXCARD_ADD( "speech",      TISPEECH, 2 )
463   MDRV_PBOXCARD_ADD( "usbsmart",      USBSMART, 3 )
464   MDRV_PBOXCARD_ADD( "ide",         TNIDE,     4 )
465   MDRV_PBOXCARD_ADD( "hsgpl",       HSGPL,    5 )
466   MDRV_PBOXCARD_ADD( "p_code_card",   PCODEN,   6 )
467   MDRV_PBOXCARD_ADD( "rs232_card",   TIRS232,  7 )
468   MDRV_PBOXCARD_ADD( "ti_fdc",      TIFDC,     8 )
469   MDRV_PBOXCARD_ADD( "hfdc",         HFDC,     8 )
470   MDRV_PBOXCARD_ADD( "bwg",         BWG,     8 )
471
472472   MDRV_FLOPPY_4_DRIVES_ADD(ti99_4_floppy_config)
473473   MDRV_MFMHD_3_DRIVES_ADD()
474474MACHINE_CONFIG_END
475475
476476static MACHINE_CONFIG_FRAGMENT( ti99ev_peb )
477   MDRV_PBOXCARD_ADD( "mem_ti32k",    TI32KMEM, 1 )
478   MDRV_PBOXCARD_ADD( "mem_sams1m",    SAMSMEM,  1 )
479   MDRV_PBOXCARD_ADD( "mem_myarc512",    MYARCMEM, 1 ) 
480   MDRV_PBOXCARD_ADD( "speech",       TISPEECH, 2 ) 
481   MDRV_PBOXCARD_ADD( "usbsmart",       USBSMART, 3 )
482   MDRV_PBOXCARD_ADD( "ide",          TNIDE,      4 )
483   MDRV_PBOXCARD_ADD( "hsgpl",       HSGPL,    5 )
484   MDRV_PBOXCARD_ADD( "p_code_card",    PCODEN,   6 )
485   MDRV_PBOXCARD_ADD( "rs232_card",    TIRS232,  7 )
486   MDRV_PBOXCARD_ADD( "ti_fdc",       TIFDC,      8 )
487   MDRV_PBOXCARD_ADD( "hfdc",          HFDC,      8 )
488   MDRV_PBOXCARD_ADD( "bwg",          BWG,      8 )
489   MDRV_PBOXCARD_ADD( "evpc",          EVPC,     9 )
490   
477   MDRV_PBOXCARD_ADD( "mem_ti32k",    TI32KMEM, 1 )
478   MDRV_PBOXCARD_ADD( "mem_sams1m",   SAMSMEM,  1 )
479   MDRV_PBOXCARD_ADD( "mem_myarc512",   MYARCMEM, 1 )
480   MDRV_PBOXCARD_ADD( "speech",      TISPEECH, 2 )
481   MDRV_PBOXCARD_ADD( "usbsmart",      USBSMART, 3 )
482   MDRV_PBOXCARD_ADD( "ide",         TNIDE,     4 )
483   MDRV_PBOXCARD_ADD( "hsgpl",       HSGPL,    5 )
484   MDRV_PBOXCARD_ADD( "p_code_card",   PCODEN,   6 )
485   MDRV_PBOXCARD_ADD( "rs232_card",   TIRS232,  7 )
486   MDRV_PBOXCARD_ADD( "ti_fdc",      TIFDC,     8 )
487   MDRV_PBOXCARD_ADD( "hfdc",         HFDC,     8 )
488   MDRV_PBOXCARD_ADD( "bwg",         BWG,     8 )
489   MDRV_PBOXCARD_ADD( "evpc",         EVPC,     9 )
490
491491   MDRV_FLOPPY_4_DRIVES_ADD(ti99_4_floppy_config)
492492   MDRV_MFMHD_3_DRIVES_ADD()
493493MACHINE_CONFIG_END
494494
495495
496496static MACHINE_CONFIG_FRAGMENT( ti998_peb )
497   MDRV_PBOXCARD_ADD( "usbsmart",       USBSMART, 1 )
498   MDRV_PBOXCARD_ADD( "ide",          TNIDE,      2 )
499   MDRV_PBOXCARD_ADD( "rs232_card",    TIRS232,  3 )
500   MDRV_PBOXCARD_ADD( "ti_fdc",       TIFDC,      8 )
501   MDRV_PBOXCARD_ADD( "hfdc",          HFDC,      8 )
502   MDRV_PBOXCARD_ADD( "bwg",          BWG,      8 )
503   
497   MDRV_PBOXCARD_ADD( "usbsmart",      USBSMART, 1 )
498   MDRV_PBOXCARD_ADD( "ide",         TNIDE,     2 )
499   MDRV_PBOXCARD_ADD( "rs232_card",   TIRS232,  3 )
500   MDRV_PBOXCARD_ADD( "ti_fdc",      TIFDC,     8 )
501   MDRV_PBOXCARD_ADD( "hfdc",         HFDC,     8 )
502   MDRV_PBOXCARD_ADD( "bwg",         BWG,     8 )
503
504504   MDRV_FLOPPY_4_DRIVES_ADD(ti99_4_floppy_config)
505505   MDRV_MFMHD_3_DRIVES_ADD()
506506MACHINE_CONFIG_END
507507
508508static MACHINE_CONFIG_FRAGMENT( ti99sg_peb )
509   MDRV_PBOXCARD_ADD( "speech",       TISPEECH, 1 ) 
510   MDRV_PBOXCARD_ADD( "usbsmart",       USBSMART, 2 )
511   MDRV_PBOXCARD_ADD( "ide",          TNIDE,      3 )
512   MDRV_PBOXCARD_ADD( "hsgpl",       HSGPL,    4 )
513   MDRV_PBOXCARD_ADD( "rs232_card",    TIRS232,  6 )
514   MDRV_PBOXCARD_ADD( "ti_fdc",       TIFDC,      7 )
515   MDRV_PBOXCARD_ADD( "hfdc",          HFDC,      7 )
516   MDRV_PBOXCARD_ADD( "bwg",          BWG,      7 )
517   MDRV_PBOXCARD_ADD( "evpc",          EVPC,     8 )
518     
509   MDRV_PBOXCARD_ADD( "speech",      TISPEECH, 1 )
510   MDRV_PBOXCARD_ADD( "usbsmart",      USBSMART, 2 )
511   MDRV_PBOXCARD_ADD( "ide",         TNIDE,     3 )
512   MDRV_PBOXCARD_ADD( "hsgpl",       HSGPL,    4 )
513   MDRV_PBOXCARD_ADD( "rs232_card",   TIRS232,  6 )
514   MDRV_PBOXCARD_ADD( "ti_fdc",      TIFDC,     7 )
515   MDRV_PBOXCARD_ADD( "hfdc",         HFDC,     7 )
516   MDRV_PBOXCARD_ADD( "bwg",         BWG,     7 )
517   MDRV_PBOXCARD_ADD( "evpc",         EVPC,     8 )
518
519519   MDRV_FLOPPY_4_DRIVES_ADD(ti99_4_floppy_config)
520520   MDRV_MFMHD_3_DRIVES_ADD()
521521MACHINE_CONFIG_END
522522
523523static MACHINE_CONFIG_FRAGMENT( geneve_peb )
524   MDRV_PBOXCARD_ADD( "speech",       TISPEECH, 1 ) 
525   MDRV_PBOXCARD_ADD( "usbsmart",       USBSMART, 2 )
526   MDRV_PBOXCARD_ADD( "ide",          TNIDE,      3 )
527   MDRV_PBOXCARD_ADD( "rs232_card",    TIRS232,  6 )
528   MDRV_PBOXCARD_ADD( "ti_fdc",       TIFDC,      7 )
529   MDRV_PBOXCARD_ADD( "hfdc",          HFDC,      7 )
530   MDRV_PBOXCARD_ADD( "bwg",          BWG,      7 )
531     
524   MDRV_PBOXCARD_ADD( "speech",      TISPEECH, 1 )
525   MDRV_PBOXCARD_ADD( "usbsmart",      USBSMART, 2 )
526   MDRV_PBOXCARD_ADD( "ide",         TNIDE,     3 )
527   MDRV_PBOXCARD_ADD( "rs232_card",   TIRS232,  6 )
528   MDRV_PBOXCARD_ADD( "ti_fdc",      TIFDC,     7 )
529   MDRV_PBOXCARD_ADD( "hfdc",         HFDC,     7 )
530   MDRV_PBOXCARD_ADD( "bwg",         BWG,     7 )
531
532532   MDRV_FLOPPY_4_DRIVES_ADD(ti99_4_floppy_config)
533533   MDRV_MFMHD_3_DRIVES_ADD()
534534MACHINE_CONFIG_END
src/mess/machine/ti99/datamux.h
r9498r9499
1212
1313typedef struct _bus_device
1414{
15   const char             *name;
15   const char            *name;
1616   UINT16               address_mask;
1717   UINT16               select_pattern;
1818   UINT16               write_select;
19   databus_read_function    read;
20   databus_write_function    write;
21   const char             *setting;
19   databus_read_function   read;
20   databus_write_function   write;
21   const char            *setting;
2222   UINT8               set;
2323   UINT8               unset;
2424} bus_device;
src/mess/machine/ti99/hfdc.h
r9498r9499
11/*
22    Myarc Hard and Floppy Disk Controller
3   Based on SMC9234
4   High Density, Double-sided
3    Based on SMC9234
4    High Density, Double-sided
55    Michael Zapf, September 2010
66*/
77
src/mess/machine/ti99/myarcmem.c
r9498r9499
11/*
22    TI-99 Myarc memory expansion
3   
4   Note that the DSR part is still missing
5   TODO: Test this device with some emulated program!
3
4    Note that the DSR part is still missing
5    TODO: Test this device with some emulated program!
66*/
77#include "emu.h"
88#include "peribox.h"
99#include "myarcmem.h"
1010
11typedef ti99_pebcard_config ti99_myarcmem_config;
11typedef ti99_pebcard_config ti99_myarcmem_config;
1212
1313typedef struct _ti99_myarcmem_state
1414{
15   int    bank;   
16   UINT8    *memory;
17   
15   int    bank;
16   UINT8   *memory;
17
1818} ti99_myarcmem_state;
1919
2020INLINE ti99_myarcmem_state *get_safe_token(running_device *device)
r9498r9499
2727#define MYARCMEM_CRU_BASE2 0x1900
2828
2929/*
30   CRU write (is there a read?)
30    CRU write (is there a read?)
3131*/
3232static WRITE8_DEVICE_HANDLER( myarcmem_cru_w )
3333{
34   ti99_myarcmem_state *card = get_safe_token(device);
34   ti99_myarcmem_state *card = get_safe_token(device);
3535   if (((offset & 0xff00)==MYARCMEM_CRU_BASE1)||((offset & 0xff00)==MYARCMEM_CRU_BASE2))
3636   {
37      if ((offset & 0x001e)==0)
37      if ((offset & 0x001e)==0)
3838      {
39         logerror("Activate Myarc memory expansion DSR ROM. Not available.\n");   
39         logerror("Activate Myarc memory expansion DSR ROM. Not available.\n");
4040      }
4141      else
4242      {
r9498r9499
4949         {
5050            card->bank |= mask;
5151         }
52      }     
52      }
5353   }
5454}
5555
r9498r9499
5858*/
5959static READ8Z_DEVICE_HANDLER( myarcmem_rz )
6060{
61   ti99_myarcmem_state *card = get_safe_token(device);
61   ti99_myarcmem_state *card = get_safe_token(device);
6262   if (((offset & 0xe000)==0x2000) || ((offset & 0xe000)==0xa000) || ((offset & 0xc000)==0xc000))
6363   {
6464      if (offset < 0xa000)
r9498r9499
6969}
7070
7171/*
72   Memory write
72    Memory write
7373*/
7474static WRITE8_DEVICE_HANDLER( myarcmem_w )
7575{
76   ti99_myarcmem_state *card = get_safe_token(device);
76   ti99_myarcmem_state *card = get_safe_token(device);
7777   if (((offset & 0xe000)==0x2000) || ((offset & 0xe000)==0xa000) || ((offset & 0xc000)==0xc000))
7878   {
7979      if (offset < 0xa000)
r9498r9499
8585
8686/**************************************************************************/
8787
88static ti99_peb_card myarcmem_card =
88static ti99_peb_card myarcmem_card =
8989{
9090   myarcmem_rz, myarcmem_w,         // memory access read/write
9191   NULL, myarcmem_cru_w,         // CRU access (no read here)
r9498r9499
110110   ti99_myarcmem_state *card = (ti99_myarcmem_state*)downcast<legacy_device_base *>(device)->token();
111111   /* Register the card */
112112   running_device *peb = device->owner();
113   
113
114114   if (input_port_read(device->machine, "RAM")==RAM_MYARC512)
115115   {
116116      int success = mount_card(peb, device, &myarcmem_card, get_pebcard_config(device)->slot);
117117      if (!success) return;
118     
118
119119      if (card->memory==NULL)
120120      {
121121         // Allocate 512 KiB
src/mess/machine/ti99/mapper8.c
r9498r9499
11/***************************************************************************
2   
3   TI-99/8 Address decoder and mapper
4   
5   This component implements the address decoder and mapper logic from the
6   TI-99/8 console.
7   
8   The TI-99/8 defines a "logical address map" with 64 KiB (according to the
9   16 address bits) and a "physical address map" with 16 MiB (according to the
10   24 address bits of the mapper). Note that the mapper only uses 16 outgoing
11   address lines and multiplexes the address bytes.   
12   
13   Note: The TI-99/8's internal codename was "Armadillo"
14   
15   Initial setting of mapper (as defined in the power-up routine, TI-99/4A mode)
16   
17   0   00ff0000 -> Unmapped; logical address 0000...0fff = ROM0
18   1   00ff0000 -> Unmapped; logical address 1000...1fff = ROM0
19   2   00000800 -> DRAM; 2000 = 000800, 2fff = 0017ff
20   3   00001800 -> DRAM; 3000 = 001800, 3fff = 0027ff
21   4   00ff4000 -> DSR space (internal / ioport)
22   5   00ff5000 -> DSR space (internal / ioport)
23   6   00ff6000 -> Cartridge space (6000..6fff)
24   7   00ff7000 -> Cartridge space (7000..7fff)
25   8   00ff0000 -> Unmapped; device ports (VDP) and SRAM
26   9   00ff0000 -> Unmapped; device ports (Speech, GROM)
27   A   00002800 -> DRAM; a000 = 002800, afff = 0037ff
28   B   00003800 -> DRAM; b000 = 003800, bfff = 0047ff
29   C   00004800 -> DRAM; c000 = 004800, cfff = 0057ff
30   D   00005800 -> DRAM; d000 = 005800, dfff = 0067ff
31   E   00006800 -> DRAM; e000 = 006800, efff = 0077ff
32   F   00007800 -> DRAM; f000 = 007800, ffff = 0087ff
332
34   Informations taken from
35   [1] ARMADILLO PRODUCT SPECIFICATIONS
36   [2] TI-99/8 Graphics Programming Language interpreter
37   
38   Michael Zapf, October 2010
39   
3    TI-99/8 Address decoder and mapper
4
5    This component implements the address decoder and mapper logic from the
6    TI-99/8 console.
7
8    The TI-99/8 defines a "logical address map" with 64 KiB (according to the
9    16 address bits) and a "physical address map" with 16 MiB (according to the
10    24 address bits of the mapper). Note that the mapper only uses 16 outgoing
11    address lines and multiplexes the address bytes.
12
13    Note: The TI-99/8's internal codename was "Armadillo"
14
15    Initial setting of mapper (as defined in the power-up routine, TI-99/4A mode)
16
17    0   00ff0000 -> Unmapped; logical address 0000...0fff = ROM0
18    1   00ff0000 -> Unmapped; logical address 1000...1fff = ROM0
19    2   00000800 -> DRAM; 2000 = 000800, 2fff = 0017ff
20    3   00001800 -> DRAM; 3000 = 001800, 3fff = 0027ff
21    4   00ff4000 -> DSR space (internal / ioport)
22    5   00ff5000 -> DSR space (internal / ioport)
23    6   00ff6000 -> Cartridge space (6000..6fff)
24    7   00ff7000 -> Cartridge space (7000..7fff)
25    8   00ff0000 -> Unmapped; device ports (VDP) and SRAM
26    9   00ff0000 -> Unmapped; device ports (Speech, GROM)
27    A   00002800 -> DRAM; a000 = 002800, afff = 0037ff
28    B   00003800 -> DRAM; b000 = 003800, bfff = 0047ff
29    C   00004800 -> DRAM; c000 = 004800, cfff = 0057ff
30    D   00005800 -> DRAM; d000 = 005800, dfff = 0067ff
31    E   00006800 -> DRAM; e000 = 006800, efff = 0077ff
32    F   00007800 -> DRAM; f000 = 007800, ffff = 0087ff
33
34    Informations taken from
35    [1] ARMADILLO PRODUCT SPECIFICATIONS
36    [2] TI-99/8 Graphics Programming Language interpreter
37
38    Michael Zapf, October 2010
39
4040***************************************************************************/
4141
4242#include "emu.h"
r9498r9499
6262typedef struct _log_addressed_device
6363{
6464   /* The device. */
65   running_device    *device;
66   
65   running_device   *device;
66
6767   /* Mode. */
6868   int            mode;
6969
7070   /* Stop. If true, stop the address decoder here and do not look for parallel devices. */
7171   int            stop;
72   
72
7373   /* Address bits involved */
74   UINT16         address_mask;
74   UINT16         address_mask;
7575
7676   /* Value of the address bits which are involved for selecting for read. */
7777   UINT16         select;
7878
7979   /* Value of the address bits which are involved for selecting for write. */
8080   UINT16         write_select;
81   
81
8282   /* Read access. */
8383   mapper_read_function read_byte;
84   
84
8585   /* Write access. */
8686   mapper_write_function write_byte;
8787
r9498r9499
9090typedef struct _phys_addressed_device
9191{
9292   /* The device. */
93   running_device    *device;
94   
93   running_device   *device;
94
9595   /* Stop. If true, stop the address decoder here and do not look for parallel devices. */
9696   int            stop;
9797
9898   /* Address bits involved */
99   UINT32         address_mask;
99   UINT32         address_mask;
100100
101101   /* Value of the address bits which are involved for selecting for read. */
102   UINT32         select;   
102   UINT32         select;
103103
104104   /* Read access. */
105105   mapper_read_function read_byte;
106   
106
107107   /* Write access. */
108108   mapper_write_function write_byte;
109   
109
110110} phys_addressed_device;
111111
112112typedef struct _mapper8_state
113113{
114114   /* All devices that are attached to the 16-bit address bus. */
115115   log_addressed_device logcomp[MAXLOGDEV];
116   
116
117117   /* All devices that are attached to the 24-bit mapped address bus. */
118118   phys_addressed_device physcomp[MAXPHYSDEV];
119119
120120   /* The I/O port. */
121121   running_device   *ioport;
122   
122
123123   /* Select bit for the internal DSR. */
124124   int   dsr_selected;
125   
125
126126   /* 99/4A compatibility mode. Name is taken from the spec. If 1, 99/4A compatibility is active. */
127127   int   CRUS;
128   
128
129129   /* P-Code mode. Name is taken from the spec. If 0, P-Code libraries are available. */
130   // May be read as "Pascal and Text-to-speech GROM libraries ENable"
130   // May be read as "Pascal and Text-to-speech GROM libraries ENable"
131131   // Note: this is negative logic. GROMs are present only for PTGEN=0
132132   int PTGEN;
133   
133
134134   /* Address mapper registers. Each offset is selected by the first 4 bits
135      of the logical address. */
135       of the logical address. */
136136   UINT32   pas_offset[16];
137   
137
138138   /* SRAM area of the system. Directly connected to the address decoder. */
139139   UINT8   *sram;
140   
140
141141   /* DRAM area of the system. Connected to the mapped address bus. */
142142   UINT8   *dram;
143143
144144   /* ROM area of the system. Directly connected to the address decoder. */
145145   UINT8   *rom;
146   
146
147147   /* Points to the next free slot in the list. */
148148   int logindex, physindex;
149   
149
150150} mapper8_state;
151151
152152
r9498r9499
160160static void mapper_mount_logical_device(running_device *mapperdev, running_device *busdevice, int mode, int stop, UINT16 address_mask, UINT16 address_bits, UINT16 write_sel, mapper_read_function read, mapper_write_function write)
161161{
162162   mapper8_state *mapper = get_safe_token(mapperdev);
163   int index = mapper->logindex++;
163   int index = mapper->logindex++;
164164   if (index < MAXLOGDEV)
165165   {
166166      if (mapper->logcomp[index].device == NULL)
r9498r9499
168168         mapper->logcomp[index].device = busdevice;
169169         mapper->logcomp[index].mode = mode;
170170         mapper->logcomp[index].stop = stop;
171         
171
172172         mapper->logcomp[index].address_mask = address_mask;
173173         mapper->logcomp[index].select = address_bits;
174174         mapper->logcomp[index].write_select = write_sel;
175175         mapper->logcomp[index].read_byte = read;
176         mapper->logcomp[index].write_byte = write;   
176         mapper->logcomp[index].write_byte = write;
177177         // printf("registering the device at logical position %d, device %lx\n", index, busdevice);
178178      }
179179   }
r9498r9499
186186static void mapper_mount_physical_device(running_device *mapperdev, running_device *busdevice, int stop, UINT32 address_mask, UINT32 address_bits, mapper_read_function read, mapper_write_function write)
187187{
188188   mapper8_state *mapper = get_safe_token(mapperdev);
189   int index = mapper->physindex++;
189   int index = mapper->physindex++;
190190   if (index < MAXPHYSDEV)
191191   {
192192      if (mapper->physcomp[index].device == NULL)
r9498r9499
196196         mapper->physcomp[index].address_mask = address_mask;
197197         mapper->physcomp[index].select = address_bits;
198198         mapper->physcomp[index].read_byte = read;
199         mapper->physcomp[index].write_byte = write;   
199         mapper->physcomp[index].write_byte = write;
200200         // printf("registering the device at physical position %d, device %lx\n", index, busdevice);
201201      }
202202   }
r9498r9499
214214{
215215   mapper8_state *mapper = get_safe_token(device);
216216   int found = FALSE;
217   // printf("ti99_8: read access %04x ... ", offset);
218   // Look for components responding to the logical address   
217   // printf("ti99_8: read access %04x ... ", offset);
218   // Look for components responding to the logical address
219219   for (int i=0; i < MAXLOGDEV; i++)
220220   {
221221      log_addressed_device *adev = &mapper->logcomp[i];
r9498r9499
223223      {
224224         // Check for the mode
225225         if (adev->mode == mapper->CRUS || (mapper->CRUS==0 && adev->mode==1 && mapper->PTGEN==FALSE))
226         {         
226         {
227227            if ((offset & adev->address_mask)==adev->select)
228228            {
229229               if (adev->device == MAP8_SRAM)
r9498r9499
242242                     found = TRUE;
243243                  }
244244                  else
245                  {               
245                  {
246246                     // device
247247                     if (adev->read_byte != NULL)
248248                     {
r9498r9499
265265   mapper8_state *mapper = get_safe_token(device);
266266   int found = FALSE;
267267
268   // printf("ti99_8: write access %04x ... ", offset);
268   // printf("ti99_8: write access %04x ... ", offset);
269269   for (int i=0; i < MAXLOGDEV; i++)
270270   {
271271      log_addressed_device *adev = &mapper->logcomp[i];
r9498r9499
273273      {
274274         // Check for the mode
275275         if (adev->mode == mapper->CRUS ||  (mapper->CRUS==0 && adev->mode==1 && mapper->PTGEN==FALSE))
276         {         
276         {
277277            if ((offset & adev->address_mask)==(adev->select | adev->write_select))
278278            {
279279               if (adev->device == MAP8_SRAM)
r9498r9499
290290                     found = TRUE;
291291                  }
292292                  else
293                  {                     
293                  {
294294                     if (adev->write_byte != NULL)
295295                     {
296296                        // printf("device ");
r9498r9499
318318
319319   if (mapper->sram==NULL)  // not initialized yet
320320      return 0;
321   
321
322322   found = check_logically_addressed_r(device, offset, &value);
323323
324324   if (!found)
r9498r9499
328328      // This means the logical address is transformed by the mapper.
329329      UINT32   pas_address = mapper->pas_offset[(offset & 0xf000)>>12] + (offset & 0xfff);
330330      // printf("%08x ", pas_address);
331     
331
332332      // So now let's do the same as above with physical addresses
333333      for (int i=0; i < MAXPHYSDEV; i++)
334334      {
r9498r9499
362362                        // printf("rom1a");
363363                     }
364364                     else
365                     {                     
365                     {
366366                        if (adev->device == MAP8_INTS)
367367                        {
368368                           // Interrupt sense
r9498r9499
387387         }
388388         if (found && adev->stop) break;
389389      }
390         
390
391391      if (!found)
392392      {
393         // Still not found? Then we route the physical address to the I/O port
393         // Still not found? Then we route the physical address to the I/O port
394394         // which has the peribox attached
395395         // printf("not mapped ... ioport");
396396         if (mapper->ioport!=NULL)
397397            ti99_peb_data_rz(mapper->ioport, pas_address, &value);
398398         // printf("ti99_8: io read %04x = %02x\n", offset, value);
399      }     
399      }
400400   }
401401   // printf(" %02x\n", value);
402402
403   return value;   
403   return value;
404404}
405405
406406/*
r9498r9499
412412   int found = FALSE;
413413   if (mapper->sram==NULL)
414414      return;
415//   // printf("ti99_8: write %04x = %02x\n", offset, data);
416   
417   // Look for components responding to the logical address   
415//  // printf("ti99_8: write %04x = %02x\n", offset, data);
416
417   // Look for components responding to the logical address
418418   found = check_logically_addressed_w(device, offset, data);
419   
419
420420   if (!found)
421421   {
422422      // printf(" not logical ...");
r9498r9499
446446                     found = TRUE;
447447                  }
448448                  else
449                  {                     
449                  {
450450                     if (adev->device == MAP8_INTS)
451451                     {
452452                        // Interrupt sense
r9498r9499
469469         }
470470         if (found && adev->stop) break;
471471      }
472         
472
473473      if (!found)
474474      {
475         // Still not found? Then we route the physical address to the I/O port
475         // Still not found? Then we route the physical address to the I/O port
476476         // which has the peribox attached
477477         // printf("not mapped ... ioport");
478478         if (mapper->ioport!=NULL)
r9498r9499
484484}
485485
486486/*
487   Reconfigure mapper. Writing to this address copies the values in the
488   SRAM into the mapper and vice versa.
489   Format:
490   0000 bbbl; bbb=bank, l=load
487    Reconfigure mapper. Writing to this address copies the values in the
488    SRAM into the mapper and vice versa.
489    Format:
490    0000 bbbl; bbb=bank, l=load
491491*/
492492WRITE8_DEVICE_HANDLER( ti99_mapreg_w )
493493{
494494   mapper8_state *mapper = get_safe_token(device);
495   
495
496496   if ((data & 0xf0)==0)
497497   {
498498      int bankindx = (data & 0x0e)>>1;
r9498r9499
503503         for (int i=0; i < 16; i++)
504504         {
505505            int ptr = (bankindx << 6);
506            mapper->pas_offset[i] =
506            mapper->pas_offset[i] =
507507               (mapper->sram[i*4 + ptr] << 24)
508508               + (mapper->sram[i*4 + ptr+1] << 16)
509509               + (mapper->sram[i*4 + ptr+2] << 8)
510510               + (mapper->sram[i*4 + ptr+3]);
511//            // printf(" values (%04x) %02x %02x %02x %02x, ", i*4+ptr, mapper->sram[i*4 + ptr], mapper->sram[i*4 + ptr+1], mapper->sram[i*4 + ptr+2], mapper->sram[i*4 + ptr+3]);
511//              // printf(" values (%04x) %02x %02x %02x %02x, ", i*4+ptr, mapper->sram[i*4 + ptr], mapper->sram[i*4 + ptr+1], mapper->sram[i*4 + ptr+2], mapper->sram[i*4 + ptr+3]);
512512         }
513513      }
514514      else
r9498r9499
530530/************************************************************************/
531531
532532/*
533   Internal DSR
533    Internal DSR
534534*/
535535READ8Z_DEVICE_HANDLER( ti998dsr_rz )
536536{
r9498r9499
544544   {
545545      if (mapper->ioport!=NULL)
546546         ti99_peb_data_rz(mapper->ioport, 0x4000 + (offset & 0x1fff), value);
547//      printf("ti99_8: io1 read %04x = %02x\n", offset, *value);
547//      printf("ti99_8: io1 read %04x = %02x\n", offset, *value);
548548   }
549549}
550550
551551
552552/*
553   CRU handling. We handle the internal device at CRU address 0x2700 via
554   this mapper component.
553    CRU handling. We handle the internal device at CRU address 0x2700 via
554    this mapper component.
555555*/
556556WRITE8_DEVICE_HANDLER( mapper8c_w )
557557{
r9498r9499
589589
590590static DEVICE_START( mapper8 )
591591{
592//   // printf("Starting mapper\n");
592//  // printf("Starting mapper\n");
593593   mapper8_state *mapper = get_safe_token(device);
594594   mapper->sram = (UINT8*)malloc(SRAM_SIZE);
595595   mapper->dram = (UINT8*)malloc(DRAM_SIZE);
r9498r9499
597597
598598   int i = 0;
599599   int done=FALSE;
600   
600
601601   for (int index = 0; index < MAXLOGDEV; index++)
602602   {
603      mapper->logcomp[index].device = NULL;     
603      mapper->logcomp[index].device = NULL;
604604   }
605605
606606   for (int index = 0; index < MAXPHYSDEV; index++)
607607   {
608      mapper->physcomp[index].device = NULL;     
608      mapper->physcomp[index].device = NULL;
609609   }
610610
611611   // Need to connect the callbacks
612612   mapper->ioport = device->siblingdevice("peribox");
613613   assert(mapper->ioport != NULL);
614   
614
615615   mapper8_dev_config *cons = (mapper8_dev_config*)device->baseconfig().static_config();
616616
617617   mapper->logindex = 0;
618618   mapper->physindex = 0;
619   
619
620620   const char *list[6] = { SRAMNAME, ROM0NAME, ROM1NAME, ROM1ANAME, DRAMNAME, INTSNAME };
621621   while (!done)
622622   {
r9498r9499
633633         }
634634         if (dev==NULL)
635635            dev = device->machine->device(cons[i].name);
636         
636
637637         if (dev!=NULL)
638638         {
639639            if (cons[i].mode != 3)
640640            {
641               mapper_mount_logical_device(device, (running_device*)dev, cons[i].mode, cons[i].stop, (UINT16)cons[i].address_mask, (UINT16)cons[i].select_pattern, (UINT16)cons[i].write_select, cons[i].read, cons[i].write);               
641               mapper_mount_logical_device(device, (running_device*)dev, cons[i].mode, cons[i].stop, (UINT16)cons[i].address_mask, (UINT16)cons[i].select_pattern, (UINT16)cons[i].write_select, cons[i].read, cons[i].write);
642642            }
643643            else
644644            {
645               mapper_mount_physical_device(device, (running_device*)dev, cons[i].stop, cons[i].address_mask, cons[i].select_pattern, cons[i].read, cons[i].write);               
645               mapper_mount_physical_device(device, (running_device*)dev, cons[i].stop, cons[i].address_mask, cons[i].select_pattern, cons[i].read, cons[i].write);
646646            }
647647         }
648648         else
r9498r9499
650650         i++;
651651      }
652652   }
653   
653
654654   mapper->dsr_selected = FALSE;
655655   mapper->CRUS = TRUE;
656656   mapper->PTGEN = TRUE;
r9498r9499
659659static DEVICE_STOP( mapper8 )
660660{
661661   // printf("Stopping mapper\n");
662   mapper8_state *mapper = get_safe_token(device);   
662   mapper8_state *mapper = get_safe_token(device);
663663   free(mapper->sram);
664664   free(mapper->dram);
665665}
src/mess/machine/ti99/peribox.h
r9498r9499
2323} ti99_peb_config;
2424
2525/*
26   Callback interface. The callback functions are in the console and are
27   accessed from the PEB.
26    Callback interface. The callback functions are in the console and are
27    accessed from the PEB.
2828*/
2929
3030#define MAXSLOTS 16
3131
3232/*
33   This interface is used by the PEB to communicate with the expansion cards.
34   It actually forwards the accesses from the main system.
33    This interface is used by the PEB to communicate with the expansion cards.
34    It actually forwards the accesses from the main system.
3535*/
3636typedef struct _ti99_peb_card_interface
3737{
38   void          (*card_read_data)(running_device *card, offs_t offset, UINT8 *value);
38   void         (*card_read_data)(running_device *card, offs_t offset, UINT8 *value);
3939   void         (*card_write_data)(running_device *card, offs_t offset, UINT8 value);
4040
41   void          (*card_read_cru)(running_device *card, offs_t offset, UINT8 *value);
41   void         (*card_read_cru)(running_device *card, offs_t offset, UINT8 *value);
4242   void         (*card_write_cru)(running_device *card, offs_t offset, UINT8 value);
4343
4444   void         (*senila)(running_device *card, int value);
45   void          (*senilb)(running_device *card, int value);
45   void         (*senilb)(running_device *card, int value);
4646
4747   /* For SGCPU only ("expansion bus") */
4848   void         (*card_read_data16)(running_device *card, offs_t offset, UINT16 *value);
49   void         (*card_write_data16)(running_device *card, offs_t offset, UINT16 value);   
50   
49   void         (*card_write_data16)(running_device *card, offs_t offset, UINT16 value);
50
5151} ti99_peb_card;
5252
5353/*
54   Called from the expansion cards. These are the callbacks from the cards to
55   the PEB (which forwards them to the main system).
56*/   
54    Called from the expansion cards. These are the callbacks from the cards to
55    the PEB (which forwards them to the main system).
56*/
5757typedef struct _peb_callback_if
5858{
59   devcb_write_line    inta;
60   devcb_write_line    intb;
61   devcb_write_line    ready;
62   
59   devcb_write_line   inta;
60   devcb_write_line   intb;
61   devcb_write_line   ready;
62
6363} peb_callback_if;
6464
6565/*
66   Used to call back the main system. Also imported by the cards.
67   This structure holds the resolved callbacks within the PEB and the cards.
66    Used to call back the main system. Also imported by the cards.
67    This structure holds the resolved callbacks within the PEB and the cards.
6868*/
6969typedef struct _peb_connect
7070{
r9498r9499
7575} ti99_peb_connect;
7676
7777/*
78   Accessor functions from the console. Note that we make use of the enhanced
79   read handler.
78    Accessor functions from the console. Note that we make use of the enhanced
79    read handler.
8080*/
8181READ8Z_DEVICE_HANDLER( ti99_peb_data_rz );
8282WRITE8_DEVICE_HANDLER( ti99_peb_data_w );
r9498r9499
8989
9090
9191/*
92   For SGCPU only. Actually the SGCPU uses an external cable to add the
93   8 data lines that are not included in the PEB
92    For SGCPU only. Actually the SGCPU uses an external cable to add the
93    8 data lines that are not included in the PEB
9494*/
9595READ16Z_DEVICE_HANDLER( ti99_peb_data16_rz );
9696WRITE16_DEVICE_HANDLER( ti99_peb_data16_w );
9797
9898/*
99   Value passed to the cards
99    Value passed to the cards
100100*/
101101typedef struct _ti99_pebcard_config
102102{
r9498r9499
110110}
111111
112112/*
113   Management functions
113    Management functions
114114*/
115115int mount_card(running_device *device, running_device *cardptr, ti99_peb_card *card, int slotindex);
116116void unmount_card(running_device *device, int slotindex);
r9498r9499
128128   MDRV_DEVICE_ADD(_tag, PBOX4, 0)                     \
129129   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, inta, _inta)      \
130130   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, intb, _intb)      \
131   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, ready, _ready)   
131   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, ready, _ready)
132132
133133#define MDRV_PBOX4A_ADD(_tag, _inta, _intb, _ready)         \
134134   MDRV_DEVICE_ADD(_tag, PBOX4A, 0)                     \
135135   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, inta, _inta)      \
136136   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, intb, _intb)      \
137   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, ready, _ready)   
137   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, ready, _ready)
138138
139139#define MDRV_PBOXEV_ADD(_tag, _inta, _intb, _ready)         \
140140   MDRV_DEVICE_ADD(_tag, PBOXEV, 0)                     \
141141   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, inta, _inta)      \
142142   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, intb, _intb)      \
143   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, ready, _ready)   
144   
143   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, ready, _ready)
144
145145#define MDRV_PBOX8_ADD(_tag, _inta, _intb, _ready)         \
146146   MDRV_DEVICE_ADD(_tag, PBOX8, 0)                     \
147147   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, inta, _inta)      \
148148   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, intb, _intb)      \
149   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, ready, _ready)   
149   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, ready, _ready)
150150
151151#define MDRV_PBOXSG_ADD(_tag, _inta, _intb, _ready)         \
152152   MDRV_DEVICE_ADD(_tag, PBOXSG, 0)                     \
153153   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, inta, _inta)      \
154154   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, intb, _intb)      \
155   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, ready, _ready)   
155   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, ready, _ready)
156156
157157#define MDRV_PBOXGEN_ADD(_tag, _inta, _intb, _ready)         \
158158   MDRV_DEVICE_ADD(_tag, PBOXGEN, 0)                     \
159159   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, inta, _inta)      \
160160   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, intb, _intb)      \
161   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, ready, _ready)   
162   
161   MDRV_DEVICE_CONFIG_DATAPTR(ti99_peb_config, ready, _ready)
162
163163#endif /* __PBOX__ */
src/mess/machine/ti99/mecmouse.c
r9498r9499
11/*
22    TI-99 Mechatronic mouse with adapter
33    Michael Zapf, October 2010
4   
4
55    The Mechatronic mouse is connected to the joystick port and occupies
66    both joystick select lines and the switch lines. From these five
77    lines, left/right/down are used for the motion (i.e. 3 motion steps
r9498r9499
4040    mecmouse_x_buf is the current step count reported to CRU
4141
4242    Michael Zapf, 2008-01-22
43   
43
4444    2010-10-22 Rewriten as device
4545*/
4646
r9498r9499
5757   int y_buf;
5858   int last_mx;
5959   int last_my;
60   
60
6161} ti99_mecmouse_state;
6262
6363INLINE ti99_mecmouse_state *get_safe_token(running_device *device)
r9498r9499
170170   if ((buttons & 2)==0)
171171      /* home button */
172172      answer |= 0x80;
173   return answer;
173   return answer;
174174}
175175
176176/*
177   Variation for TI-99/8
177    Variation for TI-99/8
178178*/
179179int mecmouse_get_values8(running_device *device, int mode)
180180{
r9498r9499
195195      if ((buttons & 2)==0)
196196         /* home button */
197197         answer |= 0x04;
198   }     
199   return answer;
198   }
199   return answer;
200200}
201201
202202/**************************************************************************/
src/mess/machine/ti99/bwg.c
r9498r9499
11/*
2    SNUG BwG Disk Controller
2    SNUG BwG Disk Controller
33    Based on WD1773
44    Double Density, Double-sided
55
r9498r9499
1414        <http://home.t-online.de/home/harald.glaab/snug/bwg.pdf>
1515
1616    Michael Zapf, September 2010
17   
18   FIXME: IO error 50, CALLs ok
17
18    FIXME: IO error 50, CALLs ok
1919*/
2020
2121#include "emu.h"
r9498r9499
3939{
4040   /* Holds the status of the DRQ and IRQ lines. */
4141   int               DRQ_IRQ_status;
42   
42
4343   /* When TRUE, card is accessible. Indicated by a LED. */
4444   int               selected;
4545
r9498r9499
5151
5252   /* When TRUE the CPU is halted while DRQ/IRQ are true. */
5353   int               hold;
54   
54
5555   /* Indicates which drive has been selected. Values are 0, 1, 2, and 4. */
5656   // 000 = no drive
5757   // 001 = drive 1
r9498r9499
6464
6565   /* ROM and RAM offset. */
6666   int               rom_offset, ram_offset;
67   
67
6868   /* Indicates whether the clock is mapped into the address space. */
6969   int               rtc_enabled;
70   
70
7171   /* count 4.23s from rising edge of motor_on */
72   emu_timer          *motor_on_timer;
73   
72   emu_timer         *motor_on_timer;
73
7474   /* Link to the FDC1771 controller on the board. */
75   running_device       *controller;
75   running_device      *controller;
7676
7777   /* Link to the real-time clock on the board. */
78   running_device       *clock;
78   running_device      *clock;
7979
8080   /* DSR ROM */
8181   UINT8            *rom;
r9498r9499
8585
8686   /* DIP swiches */
8787   UINT8            dip1, dip2, dip34;
88   
88
8989   /* Callback lines to the main system. */
9090   ti99_peb_connect   lines;
91   
91
9292} ti99_bwg_state;
9393
9494INLINE ti99_bwg_state *get_safe_token(running_device *device)
r9498r9499
102102
103103    Emulation is faulty because the CPU is actually stopped in the midst of
104104    instruction, at the end of the memory access
105   
106   TODO: This has to be replaced by the proper READY handling that is already
107   prepared here. (Requires READY handling by the CPU.)
105
106    TODO: This has to be replaced by the proper READY handling that is already
107    prepared here. (Requires READY handling by the CPU.)
108108*/
109109static void bwg_handle_hold(running_device *device)
110110{
111   ti99_bwg_state *card = get_safe_token(device);
111   ti99_bwg_state *card = get_safe_token(device);
112112   line_state state;
113   
113
114114   if (card->hold && (!card->DRQ_IRQ_status) && card->DVENA)
115115      state = ASSERT_LINE;
116116   else
117117      state = CLEAR_LINE;
118   
119   // TODO: use READY
118
119   // TODO: use READY
120120   cputag_set_input_line(device->machine, "maincpu", INPUT_LINE_HALT, state);
121121}
122122
r9498r9499
160160static WRITE_LINE_DEVICE_HANDLER( ti_bwg_intrq_w )
161161{
162162   running_device *carddev = device->owner();
163   ti99_bwg_state *card = get_safe_token(carddev);
163   ti99_bwg_state *card = get_safe_token(carddev);
164164
165165   if (state)
166166   {
r9498r9499
180180static WRITE_LINE_DEVICE_HANDLER( ti_bwg_drq_w )
181181{
182182   running_device *carddev = device->owner();
183   ti99_bwg_state *card = get_safe_token(carddev);
183   ti99_bwg_state *card = get_safe_token(carddev);
184184
185185   if (state)
186186      card->DRQ_IRQ_status |= bwg_DRQ;
r9498r9499
196196static TIMER_CALLBACK(motor_on_timer_callback)
197197{
198198   running_device *device = (running_device *)ptr;
199   ti99_bwg_state *card = get_safe_token(device);
199   ti99_bwg_state *card = get_safe_token(device);
200200   card->DVENA = 0;
201201   bwg_handle_hold(device);
202202}
r9498r9499
214214/*
215215    CRU read handler. *=inverted.
216216    bit 0: DSK4 connected*
217   bit 1: DSK1 connected*
218   bit 2: DSK2 connected*
219   bit 3: DSK3 connected*
220   bit 4: Dip 1
221   bit 5: Dip 2
222   bit 6: Dip 3
223   bit 7: Dip 4
217    bit 1: DSK1 connected*
218    bit 2: DSK2 connected*
219    bit 3: DSK3 connected*
220    bit 4: Dip 1
221    bit 5: Dip 2
222    bit 6: Dip 3
223    bit 7: Dip 4
224224*/
225225static READ8Z_DEVICE_HANDLER( cru_r )
226226{
227   ti99_bwg_state *card = get_safe_token(device);
227   ti99_bwg_state *card = get_safe_token(device);
228228   UINT8 reply = 0;
229   
229
230230   if ((offset & 0xff00)==CRU_BASE)
231231   {
232232      if ((offset & 0x00ff)==0)
r9498r9499
235235         // If we want to do that properly, we need to check the actually
236236         // available drives (not the images!). But why should we connect less?
237237         reply = 0x00;
238         
238
239239         // DIP switches. Note that a closed switch means 0
240240         // xx01 1111   11 = nur dsk1; 10 = 1+2, 01=1/2/3, 00=1-4
241241         if (card->dip1) reply |= 0x10;
r9498r9499
250250
251251static WRITE8_DEVICE_HANDLER( cru_w )
252252{
253   ti99_bwg_state *card = get_safe_token(device);
253   ti99_bwg_state *card = get_safe_token(device);
254254   int drive, drivebit;
255255
256256   if ((offset & 0xff00)==CRU_BASE)
r9498r9499
277277      case 2:
278278         /* Set disk ready/hold (bit 2) */
279279         // 0: ignore IRQ and DRQ
280         // 1: TMS9900 is stopped until IRQ or DRQ are set
281         // OR the motor stops rotating - rotates for 4.23s after write
282         // to CRU bit 1
283         // This is not emulated and could cause the TI99 to lock up
280         // 1: TMS9900 is stopped until IRQ or DRQ are set
281         // OR the motor stops rotating - rotates for 4.23s after write
282         // to CRU bit 1
283         // This is not emulated and could cause the TI99 to lock up
284284         card->hold = data;
285285         bwg_handle_hold(device);
286286         break;
r9498r9499
293293         /* Select drive 3 (DSK4) (bit 8) */
294294         drive = (bit == 8) ? 3 : (bit - 4);      /* drive # (0-3) */
295295         drivebit = 1<<drive;
296         
296
297297         if (data)
298298         {
299299            if (!(card->DSEL & drivebit))         /* select drive */
300300            {
301301               if (card->DSEL != 0)
302                  logerror("ti99/BwG: Multiple drives selected, %02x\n", card->DSEL); 
302                  logerror("ti99/BwG: Multiple drives selected, %02x\n", card->DSEL);
303303               card->DSEL |= drivebit;
304304               wd17xx_set_drive(card->controller, drive);
305305            }
r9498r9499
307307         else
308308            card->DSEL &= ~drivebit;
309309         break;
310                 
310
311311      case 7:
312312         /* Select side of disk (bit 7) */
313313         card->SIDE = data;
r9498r9499
334334         else
335335            card->ram_offset = 0x0000;
336336         break;
337         
337
338338      case 14:
339339         /* Override FDC with RTC (active high) */
340340         card->rtc_enabled = data;
341341         break;
342         
342
343343      case 15:
344344         /* EPROM A14 */
345345         if (data)
r9498r9499
347347         else
348348            card->rom_offset &= ~0x4000;
349349         break;
350         
350
351351      case 3:
352352      case 9:
353353      case 12:
r9498r9499
359359
360360/*
361361    Read a byte
362   4000 - 5bff: ROM (4 banks)
363   
364   rtc disabled:
365   5c00 - 5fef: RAM
366   5ff0 - 5fff: Controller (f0 = status, f2 = track, f4 = sector, f6 = data)
362    4000 - 5bff: ROM (4 banks)
367363
368   rtc enabled:
369   5c00 - 5fdf: RAM
370   5fe0 - 5fff: Clock (even addr)
364    rtc disabled:
365    5c00 - 5fef: RAM
366    5ff0 - 5fff: Controller (f0 = status, f2 = track, f4 = sector, f6 = data)
367
368    rtc enabled:
369    5c00 - 5fdf: RAM
370    5fe0 - 5fff: Clock (even addr)
371371*/
372372
373373static READ8Z_DEVICE_HANDLER( data_r )
374374{
375   ti99_bwg_state *card = get_safe_token(device);
375   ti99_bwg_state *card = get_safe_token(device);
376376
377377   if (card->selected)
378378   {
379      if ((offset & 0xe000)==0x4000)
379      if ((offset & 0xe000)==0x4000)
380380      {
381381         // 010x xxxx xxxx xxxx
382382         if ((offset & 0x1c00)==0x1c00)
r9498r9499
398398            {
399399               if ((offset & 0x03f9)==0x03f0)
400400               {
401                  // .... ..11 1111 0xx0
401                  // .... ..11 1111 0xx0
402402                  // Note that the value is inverted again on the board,
403403                  // so we can drop the inversion
404404                  *value = wd17xx_r(card->controller, (offset >> 1)&0x03);
r9498r9499
419419
420420/*
421421    Write a byte
422   4000 - 5bff: ROM, ignore write (4 banks)
423   
424   rtc disabled:
425   5c00 - 5fef: RAM
426   5ff0 - 5fff: Controller (f8 = command, fa = track, fc = sector, fe = data)
422    4000 - 5bff: ROM, ignore write (4 banks)
427423
428   rtc enabled:
429   5c00 - 5fdf: RAM
430   5fe0 - 5fff: Clock (even addr)   
424    rtc disabled:
425    5c00 - 5fef: RAM
426    5ff0 - 5fff: Controller (f8 = command, fa = track, fc = sector, fe = data)
427
428    rtc enabled:
429    5c00 - 5fdf: RAM
430    5fe0 - 5fff: Clock (even addr)
431431*/
432432static WRITE8_DEVICE_HANDLER( data_w )
433433{
434   ti99_bwg_state *card = get_safe_token(device);
434   ti99_bwg_state *card = get_safe_token(device);
435435
436436   if (card->selected)
437437   {
438      if ((offset & 0xe000)==0x4000)
438      if ((offset & 0xe000)==0x4000)
439439      {
440440         // 010x xxxx xxxx xxxx
441441         if ((offset & 0x1c00)==0x1c00)
r9498r9499
445445            {
446446               if ((offset & 0x03e1)==0x03e0)
447447               {
448                  // .... ..11 111x xxx0
448                  // .... ..11 111x xxx0
449449                  mm58274c_w(card->clock, (offset & 0x001e) >> 1, data);
450450               }
451451               else
r9498r9499
457457            {
458458               if ((offset & 0x03f9)==0x03f8)
459459               {
460                  // .... ..11 1111 1xx0
460                  // .... ..11 1111 1xx0
461461                  // Note that the value is inverted again on the board,
462462                  // so we can drop the inversion
463463                  wd17xx_w(card->controller, (offset >> 1)&0x03, data);
r9498r9499
475475static DEVICE_START( ti99_bwg )
476476{
477477   ti99_bwg_state *card = (ti99_bwg_state*)downcast<legacy_device_base *>(device)->token();
478   
478
479479   /* Resolve the callbacks to the PEB */
480480   peb_callback_if *topeb = (peb_callback_if *)device->baseconfig().static_config();
481481   devcb_resolve_write_line(&card->lines.ready, &topeb->ready, device);
r9498r9499
484484   card->controller = device->subdevice("wd1773");
485485   card->clock = device->subdevice("mm58274c");
486486   astring *region = new astring();
487   astring_assemble_3(region, device->tag(), ":", bwg_region);     
487   astring_assemble_3(region, device->tag(), ":", bwg_region);
488488   card->rom = memory_region(device->machine, astring_c(region));
489489   card->ram = NULL;
490490}
r9498r9499
496496   if (card->ram) free(card->ram);
497497}
498498
499static ti99_peb_card bwg_card =
499static ti99_peb_card bwg_card =
500500{
501501   data_r,
502502   data_w,
503503   cru_r,
504   cru_w,   
505   NULL, NULL,   NULL, NULL   
504   cru_w,
505   NULL, NULL,   NULL, NULL
506506};
507507
508508static DEVICE_RESET( ti99_bwg )
r9498r9499
512512   /* If the card is selected in the menu, register the card */
513513   if (input_port_read(device->machine, "DISKCTRL") == DISK_BWG)
514514   {
515      running_device *peb = device->owner();   
515      running_device *peb = device->owner();
516516      int success = mount_card(peb, device, &bwg_card, get_pebcard_config(device)->slot);
517517      if (!success) return;
518           
518
519519      // Allocate 2 KiB for on-board buffer memory (6116 chip)
520      if (card->ram==NULL)
520      if (card->ram==NULL)
521521      {
522522         card->ram = (UINT8*)malloc(2048);
523523         memset(card->ram, 0, 2048);
524524      }
525     
525
526526      card->dip1 = input_port_read(device->machine, "BWGDIP1");
527527      card->dip2 = input_port_read(device->machine, "BWGDIP2");
528528      card->dip34 = input_port_read(device->machine, "BWGDIP34");
r9498r9499
531531      card->SIDE = 0;
532532      card->DVENA = 0;
533533      card->strobe_motor = 0;
534           
534
535535      ti99_set_80_track_drives(FALSE);
536536
537537      floppy_type_t flop = FLOPPY_STANDARD_5_25_DSDD_40;
r9498r9499
541541      card->ram_offset = 0;
542542      card->rom_offset = 0;
543543      card->rtc_enabled = 0;
544     
545      wd17xx_dden_w(card->controller, CLEAR_LINE);   // Correct?   
544
545      wd17xx_dden_w(card->controller, CLEAR_LINE);   // Correct?
546546   }
547547}
548548
src/mess/machine/ti99/mapper8.h
r9498r9499
66
77typedef struct _mapper8_dev_config
88{
9   const char             *name;
9   const char            *name;
1010   int                  mode;
1111   int                  stop;
1212   UINT32               address_mask;
1313   UINT32               select_pattern;
1414   UINT32               write_select;
15   mapper_read_function    read;
16   mapper_write_function    write;
15   mapper_read_function   read;
16   mapper_write_function   write;
1717} mapper8_dev_config;
1818
1919#define SRAMNAME "SRAM"
src/mess/machine/ti99/bwg.h
r9498r9499
11/*
2    SNUG BwG Disk Controller
3   Based on WD1770
4   Double Density, Double-sided
2    SNUG BwG Disk Controller
3    Based on WD1770
4    Double Density, Double-sided
55    Michael Zapf, September 2010
66*/
77
src/mess/machine/ti99/tiboard.c
r9498r9499
11/***************************************************************************
2   TI-99/4(A) and TI-99/8 main board
3     
4   Michael Zapf, October 2010
5   TODO: Find out whether device can be determined more easily in CRU functions
2    TI-99/4(A) and TI-99/8 main board
3
4    Michael Zapf, October 2010
5    TODO: Find out whether device can be determined more easily in CRU functions
66***************************************************************************/
77
88#include "emu.h"
r9498r9499
1818{
1919   /* Mode: Which console do we have? */
2020   int            mode;
21   
21
2222   /* Keyboard support */
2323   int            keyCol;
2424   int            alphaLockLine;
25   
25
2626   /* Devices */
27   running_device    *cpu;
28   running_device    *video;
27   running_device   *cpu;
28   running_device   *video;
2929   running_device  *tms9901;
30   running_device    *peribox;
31   running_device    *sound;
30   running_device   *peribox;
31   running_device   *sound;
3232
33   running_device    *handset;
34   running_device    *mecmouse;
35   running_device    *gromport;
33   running_device   *handset;
34   running_device   *mecmouse;
35   running_device   *gromport;
3636
3737} tiboard_state;
3838
r9498r9499
5757}
5858
5959/****************************************************************************
60   TMS9901 and attached devices handling
60    TMS9901 and attached devices handling
6161****************************************************************************/
6262/*
6363    VBL interrupt  (mmm...  actually, it happens when the beam enters the lower
r9498r9499
6868   running_device *dev = device->machine->device("ti_board");
6969   tiboard_state *board = get_safe_token(dev);
7070
71   TMS9928A_interrupt(device->machine);   
71   TMS9928A_interrupt(device->machine);
7272
73   if (board->handset != NULL)
73   if (board->handset != NULL)
7474      ti99_handset_task(board->handset);
75   if (board->mecmouse != NULL)
75   if (board->mecmouse != NULL)
7676      mecmouse_poll(board->mecmouse);
7777}
7878
r9498r9499
210210      answer = mecmouse_get_values(board->mecmouse);
211211   else
212212      answer = ((input_port_read(device->machine, keynames[board->keyCol >> 1]) >> ((board->keyCol & 1) * 8)) << 3) & 0xF8;
213   
213
214214   if (board->alphaLockLine == FALSE)
215215      answer &= ~(input_port_read(device->machine, "ALPHA") << 3);
216   
216
217217   return answer;
218218}
219219
r9498r9499
241241   }
242242
243243   /* we don't take CS2 into account, as CS2 is a write-only unit */
244   //   if (cassette_input(device->machine->device("cassette1")) > 0)
245   //      answer |= 8;
244   //  if (cassette_input(device->machine->device("cassette1")) > 0)
245   //      answer |= 8;
246246
247247   return answer;
248248}
r9498r9499
257257   running_device *dev = device->machine->device("ti_board");
258258   tiboard_state *board = get_safe_token(dev);
259259
260   if (board->handset != NULL)
260   if (board->handset != NULL)
261261      if (ti99_handset_get_clock(board->handset)) return 2;
262262   return 0;
263263}
r9498r9499
308308   tiboard_state *board = get_safe_token(dev);
309309
310310   int index=5;
311   
311
312312   if (board->mode==TI994A)
313313      index=6;
314   
314
315315   if (data)
316316      board->keyCol |= 1 << (offset-2);
317317   else
r9498r9499
600600};
601601
602602/*
603   Handles the EXTINT line. This one is directly connected to the 9901.
603    Handles the EXTINT line. This one is directly connected to the 9901.
604604*/
605605WRITE_LINE_DEVICE_HANDLER( console_extint )
606606{
r9498r9499
620620/***************************************************************************
621621    DEVICE LIFECYCLE FUNCTIONS
622622***************************************************************************/
623   
623
624624static DEVICE_START( tiboard )
625625{
626626   tiboard_state *board = get_safe_token(device);
r9498r9499
639639   tiboard_state *board = get_safe_token(device);
640640   const tiboard_config* conf = (const tiboard_config*)get_config(device);
641641   board->mode = conf->mode;
642   
642
643643   /* clear keyboard interface state (probably overkill, but can't harm) */
644644   board->keyCol = 0;
645645   board->alphaLockLine = 0;
r9498r9499
650650   {
651651      /* reset handset */
652652      tms9901_set_single_int(board->tms9901, 12, 0);
653     
653
654654      if (input_port_read(device->machine, "HCI") & HCI_IR)
655655         board->handset = device->siblingdevice("handset");
656656   }
657657
658658   if (input_port_read(device->machine, "HCI") & HCI_MECMOUSE)
659659      board->mecmouse = device->siblingdevice("mecmouse");
660   
660
661661   if (board->mode != TI998)
662662   {
663      set_gk_switches(board->gromport, 1, input_port_read(device->machine, "GKSWITCH1")); 
664      set_gk_switches(board->gromport, 2, input_port_read(device->machine, "GKSWITCH2")); 
665      set_gk_switches(board->gromport, 3, input_port_read(device->machine, "GKSWITCH3")); 
666      set_gk_switches(board->gromport, 4, input_port_read(device->machine, "GKSWITCH4")); 
663      set_gk_switches(board->gromport, 1, input_port_read(device->machine, "GKSWITCH1"));
664      set_gk_switches(board->gromport, 2, input_port_read(device->machine, "GKSWITCH2"));
665      set_gk_switches(board->gromport, 3, input_port_read(device->machine, "GKSWITCH3"));
666      set_gk_switches(board->gromport, 4, input_port_read(device->machine, "GKSWITCH4"));
667667      set_gk_switches(board->gromport, 5, input_port_read(device->machine, "GKSWITCH5"));
668   }   
668   }
669669}
670670
671671static const char DEVTEMPLATE_SOURCE[] = __FILE__;
src/mess/machine/ti99/handset.c
r9498r9499
1616    joysticks), according to which was currently active.
1717
1818    Originally written by R. Nabet
19   
20    Michael Zapf   
19
20    Michael Zapf
2121    2010-10-24 Rewriten as device
2222*/
2323
r9498r9499
3333   int       buflen;
3434   int       clock;
3535   int       ack;
36   UINT8       previous_joy[MAX_HANDSETS];
37   UINT8       previous_key[MAX_HANDSETS];
36   UINT8      previous_joy[MAX_HANDSETS];
37   UINT8      previous_key[MAX_HANDSETS];
3838
3939   emu_timer      *timer;
40   running_device    *console9901;
40   running_device   *console9901;
4141
4242} ti99_handset_state;
4343
r9498r9499
7979int ti99_handset_get_clock(running_device *device)
8080{
8181   ti99_handset_state *handset = get_safe_token(device);
82   return handset->clock;   
82   return handset->clock;
8383}
8484
8585int ti99_handset_get_int(running_device *device)
8686{
8787   ti99_handset_state *handset = get_safe_token(device);
88   return handset->buflen==3;   
88   return handset->buflen==3;
8989}
9090
9191/*
r9498r9499
104104   handset->clock = !handset->clock;
105105   handset->buf >>= 4;
106106   handset->buflen--;
107   
107
108108   tms9901_set_single_int(handset->console9901, 12, 0);
109109
110110   if (handset->buflen == 1)
r9498r9499
154154   handset->clock = 1;
155155   handset->buf = ~message;
156156   handset->buflen = 3;
157   
157
158158   tms9901_set_single_int(handset->console9901, 12, 1);
159159}
160160
r9498r9499
310310{
311311   int i;
312312   ti99_handset_state *handset = get_safe_token(device);
313   
313
314314   if (handset->buflen == 0)
315   {   
315   {
316316      /* poll every handset */
317317      for (i=0; i < MAX_HANDSETS; i++)
318318         if (ti99_handset_poll_joystick(device, i)) return;
src/mess/machine/ti99/spchsyn.c
r9498r9499
11/*
22    TI-99 Speech synthesizer
3   
3
44    We emulate the Speech Synthesizer plugged onto a P-Box adapter. The original
5    Speech Synthesizer device was provided as a box to be plugged into the
5    Speech Synthesizer device was provided as a box to be plugged into the
66    right side of the console. In order to be used with Geneve and SGCPU, the
77    speech synthesizer must be moved into the Peripheral Box.
8   
9    The Speech Synthesizer used for the TI was the TMS5200, aka TMC0285, a
8
9    The Speech Synthesizer used for the TI was the TMS5200, aka TMC0285, a
1010    predecessor of the TMS5220 which was used in other commercial products.
11   
11
1212    Note that this adapter also contains the speech roms.
1313*/
1414#include "emu.h"
r9498r9499
2020#define TMS5220_ADDRESS_MASK 0x3FFFFUL   /* 18-bit mask for tms5220 address */
2121#define speech_region "speech_region"
2222
23typedef ti99_pebcard_config ti99_speech_config;
23typedef ti99_pebcard_config ti99_speech_config;
2424
2525typedef struct _ti99_speech_state
2626{
27   running_device          *vsp;
28   UINT8                *speechrom_data;      /* pointer to speech ROM data */
27   running_device         *vsp;
28   UINT8               *speechrom_data;      /* pointer to speech ROM data */
2929   int                load_pointer;         /* which 4-bit nibble will be affected by load address */
3030   int                ROM_bits_count;            /* current bit position in ROM */
31   UINT32                speechROMaddr;            /* 18 bit pointer in ROM */
31   UINT32               speechROMaddr;            /* 18 bit pointer in ROM */
3232   UINT32               speechROMlen;         /* length of data pointed by speechrom_data, from 0 to 2^18 */
3333   ti99_peb_connect      lines;
34   
34
3535} ti99_speech_state;
3636
3737INLINE ti99_speech_state *get_safe_token(running_device *device)
r9498r9499
4848static int ti99_spchroms_read(running_device *vspdev, int count)
4949{
5050   running_device *device = vspdev->owner();
51   ti99_speech_state *adapter = get_safe_token(device);
51   ti99_speech_state *adapter = get_safe_token(device);
5252
5353   int val;
5454
r9498r9499
9191static void ti99_spchroms_load_address(running_device *vspdev, int data)
9292{
9393   running_device *device = vspdev->owner();
94   ti99_speech_state *adapter = get_safe_token(device);
94   ti99_speech_state *adapter = get_safe_token(device);
9595   // tms5220 data sheet says that if we load only one 4-bit nibble, it won't work.
9696   // This code does not care about this.
9797   adapter->speechROMaddr = ((adapter->speechROMaddr & ~(0xf << adapter->load_pointer))
r9498r9499
106106static void ti99_spchroms_read_and_branch(running_device *vspdev)
107107{
108108   running_device *device = vspdev->owner();
109   ti99_speech_state *adapter = get_safe_token(device);
109   ti99_speech_state *adapter = get_safe_token(device);
110110   // tms5220 data sheet says that if more than one speech ROM (tms6100) is present,
111111   // there is a bus contention.  This code does not care about this. */
112112   if (adapter->speechROMaddr < adapter->speechROMlen-1)
r9498r9499
129129*/
130130static READ8Z_DEVICE_HANDLER( speech_rz )
131131{
132   ti99_speech_state *adapter = get_safe_token(device);
133   
134   if ((offset & 0xfc01)==0x9000)       
132   ti99_speech_state *adapter = get_safe_token(device);
133
134   if ((offset & 0xfc01)==0x9000)
135135   {
136      cpu_adjust_icount(device->machine->device("maincpu"),-(18+3));      /* this is just a minimum, it can be more */     
136      cpu_adjust_icount(device->machine->device("maincpu"),-(18+3));      /* this is just a minimum, it can be more */
137137      *value = tms5220_status_r(adapter->vsp, offset) & 0xff;
138138   }
139139}
140140
141141/*
142   Memory write
142    Memory write
143143*/
144144static WRITE8_DEVICE_HANDLER( speech_w )
145145{
146   ti99_speech_state *adapter = get_safe_token(device);
146   ti99_speech_state *adapter = get_safe_token(device);
147147
148   if ((offset & 0xfc01)==0x9400)
148   if ((offset & 0xfc01)==0x9400)
149149   {
150150      cpu_adjust_icount(device->machine->device("maincpu"),-(54+3));      /* this is just an approx. minimum, it can be much more */
151     
151
152152      /* RN: the stupid design of the tms5220 core means that ready is cleared */
153153      /* when there are 15 bytes in FIFO.  It should be 16.  Of course, if */
154154      /* it were the case, we would need to store the value on the bus, */
r9498r9499
158158         attotime time_to_ready = double_to_attotime(tms5220_time_to_ready(adapter->vsp));
159159         int cycles_to_ready = device->machine->device<cpu_device>("maincpu")->attotime_to_cycles(time_to_ready);
160160         logerror("time to ready: %f -> %d\n", attotime_to_double(time_to_ready), (int) cycles_to_ready);
161         
161
162162         cpu_adjust_icount(device->machine->device("maincpu"),-cycles_to_ready);
163163         timer_set(device->machine, attotime_zero, NULL, 0, NULL);
164      }     
164      }
165165      tms5220_data_w(adapter->vsp, offset, data);
166166   }
167167}
168168
169169/**************************************************************************/
170170
171static ti99_peb_card speech_adapter_card =
171static ti99_peb_card speech_adapter_card =
172172{
173173   speech_rz, speech_w,         // memory access read/write
174174   NULL, NULL,                  // CRU access (none here)
r9498r9499
194194   ti99_speech_state *adapter = (ti99_speech_state*)downcast<legacy_device_base *>(device)->token();
195195   /* Register the adapter */
196196   running_device *peb = device->owner();
197   
197
198198   if (input_port_read(device->machine, "SPEECH"))
199199   {
200200      int success = mount_card(peb, device, &speech_adapter_card, get_pebcard_config(device)->slot);
201      if (!success)
201      if (!success)
202202      {
203203         logerror("speech: Could not mount the speech synthesizer\n");
204204         return;
205205      }
206     
206
207207      astring *region = new astring();
208      astring_assemble_3(region, device->tag(), ":", speech_region);   
209     
208      astring_assemble_3(region, device->tag(), ":", speech_region);
209
210210      adapter->speechrom_data = memory_region(device->machine, astring_c(region));
211211      adapter->speechROMlen = memory_region_length(device->machine, astring_c(region));
212212      adapter->speechROMaddr = 0;
src/mess/machine/ti99/tiboard.h
r9498r9499
3939   MDRV_DEVICE_CONFIG_DATA32( tiboard_config, mode, TI994A)
4040
4141#define MDRV_TI998_BOARD_ADD(_tag )         \
42   MDRV_DEVICE_ADD(_tag, TIBOARD, 0)    \
42   MDRV_DEVICE_ADD(_tag, TIBOARD, 0)   \
4343   MDRV_DEVICE_CONFIG_DATA32( tiboard_config, mode, TI998)
4444
4545#endif
src/mess/machine/ti99/handset.h
r9498r9499
88
99typedef struct _ti99_handset_config
1010{
11   const char             *sysintf;
11   const char            *sysintf;
1212} ti99_handset_config;
1313
1414

Previous 15994 Revisions Next


© 1998-2018 The MESS Team