Previous 15994 Revisions Next

r7614 Sunday 21st March, 2010 at 11:49:57 UTC by Nathan Woods
[TI99] Cleanups. [Michael Zapf]
[docs]messnew.txt
[src/mess/devices]ti99cart.c ti99cart.h
[src/mess/machine]99_dsk.c ti99_4x.c ti99_4x.h ti99pcod.c

src/mess/devices/ti99cart.c
r7613r7614
1515
1616typedef int assmfct(running_device *);
1717
18#define TI99_CARTRIDGE_PCB_NONE      DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_none)
19#define TI99_CARTRIDGE_PCB_STD      DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_std)
20#define TI99_CARTRIDGE_PCB_PAGED   DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_paged)
21#define TI99_CARTRIDGE_PCB_MINIMEM   DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_minimem)
22#define TI99_CARTRIDGE_PCB_SUPER   DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_super)
23#define TI99_CARTRIDGE_PCB_MBX      DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_mbx)
24#define TI99_CARTRIDGE_PCB_PAGED379I   DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_paged379i)
25#define TI99_CARTRIDGE_PCB_PAGEDCRU   DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_pagedcru)
26
27/* Generic TI99 cartridge structure. */
28struct _cartridge_t
29{
30   /* PCB device associated to this cartridge. If NULL, the slot is empty. */
31   running_device *pcb;
32   
33        /* GROM buffer size. */
34        int grom_size;
35       
36        /* ROM page. */
37        int rom_page;
38        /* RAM page. */
39        int ram_page;
40       
41        /* ROM buffer size. All banks have equal sizes. */
42        int rom_size;
43        /* RAM buffer size. All banks have equal sizes. */
44        int ram_size;
45       
46        /* pointer to GROM data. */
47        UINT8 *grom_ptr;
48       
49        /* GROM buffered data output. */
50        /*        UINT8 grom_buffer; */ /* Now handled by the multicart system. */
51       
52        /* ROM buffer. We are using this for both 16 bit (99/4a) and 8 bit
53        (99/8) access. */
54        void *rom_ptr;
55       
56        /* ROM buffer for the second bank of paged cartridges. Other cartridges
57        usually store their ROM in one large file. */
58        void *rom2_ptr;
59       
60        /* RAM buffer. The persistence service is done by the cartridge system.
61        The RAM space is a consecutive space; all banks are in one buffer. */
62        void *ram_ptr;
63};
64typedef struct _cartridge_t cartridge_t;
65
1866enum
1967{
2068   TI99CARTINFO_FCT_6000_R = DEVINFO_FCT_DEVICE_SPECIFIC,      /* read16_device_handler */
r7613r7614
3684   LEG_CART_MBX
3785} legacy_cart_t;
3886
39struct _ti99_multicart_t
87struct _ti99_multicart_state
4088{
4189   /* Reserves space for all cartridges. This is also used in the legacy
42    cartridge system, but only for slot 0. */
90   cartridge system, but only for slot 0. */
4391   cartridge_t cartridge[NUMBER_OF_CARTRIDGE_SLOTS];
44
92   
4593   /* Determines which slot is currently active. This value is changed when there
46    are accesses to other GROM base addresses. */
94   are accesses to other GROM base addresses. */
4795   int active_slot;
48
96   
4997   /* Used in order to enforce a special slot. This value is retrieved
50       from the dipswitch setting. A value of -1 means automatic, that is,
51       the grom base switch is used. Values 0 .. max refer to the
52       respective slot. */
98   from the dipswitch setting. A value of -1 means automatic, that is,
99   the grom base switch is used. Values 0 .. max refer to the
100   respective slot. */
53101   int fixed_slot;
54
102   
55103   /* Holds the highest index of a cartridge being plugged in plus one.
56       If we only have one cartridge inserted, we don't want to get a
57       selection option, so we just mirror the memory contents. */
104   If we only have one cartridge inserted, we don't want to get a
105   selection option, so we just mirror the memory contents. */
58106   int next_free_slot;
59
107   
60108   /* Counts the number of slots which currently contain legacy format
61       cartridge images. */
109   cartridge images. */
62110   int legacy_slots;
63
111   
64112   /* Counts the number of slots which currently contain new format
65       cartridge images. */
113   cartridge images. */
66114   int multi_slots;
67
115   
68116   /* Legacy mode. Stores the slot number where the cartridge part is mounted.
69       Index is from slotc_type_t. */
117   Index is from slotc_type_t. */
70118   int legacy_slotnumber[5];
119   
120   /* current address pointer for the active GROM in port (16 bits) */
121   UINT16 grom_address;
122   /* GROM data buffer */
123   UINT8 grom_buffer;
124
125   /* internal flip-flops that are set after the first access to the GROM
126   address so that next access is mapped to the LSB, and cleared after each
127   data access */
128   char raddr_LSB, waddr_LSB;
71129};
72typedef struct _ti99_multicart_t ti99_multicart_t;
130typedef struct _ti99_multicart_state ti99_multicart_state;
73131
74132#define AUTO -1
75133
r7613r7614
84142} slotc_type_t;
85143
86144/* Function declaration; the function itself is in the later part of this file. */
87static UINT8 cartridge_grom_read_legacy(running_device *cartsys, int cart_offset);
145static UINT8 cartridge_grom_read_legacy(running_device *cartsys);
88146static void unload_legacy(running_device *image);
89147static int load_legacy(running_device *image);
90148
r7613r7614
122180
123181static int in_legacy_mode(running_device *device)
124182{
125   ti99_multicart_t *cartslots = (ti99_multicart_t *)device->token;
183   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
126184   if ((cartslots->legacy_slots>0) &&  (cartslots->multi_slots==0))
127185      return TRUE;
128186   return FALSE;
r7613r7614
164222    Interestingly, cartridge subroutines are found nevertheless, even when
165223    the cartridge is plugged into a higher slot.
166224*/
167void ti99_cartridge_slot_set(running_device *cartsys, int slotnumber)
225static void cartridge_slot_set(running_device *cartsys, int slotnumber)
168226{
169   ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token;
227   ti99_multicart_state *cartslots = (ti99_multicart_state *)cartsys->token;
170228   assert(slotnumber>=0 && slotnumber<=255);
171229//  if (cartslots->active_slot != slotnumber) printf("Setting cartslot to %d\n", slotnumber);
172230   if (cartslots->fixed_slot==AUTO)
r7613r7614
175233      cartslots->active_slot = cartslots->fixed_slot;
176234}
177235
178/*
179    Allows to manually lock the cartslot system to a specific slot.
180    Called from the machine driver, taking the dipswitch setting.
181    We take slot numbers from 0 (automatic mode) to the maximum.
182*/
183void ti99_lock_cartridge_slot(running_device *cartsys, int slotnumber)
184{
185   ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token;
186   assert(slotnumber>=0 && slotnumber<=255);
187   cartslots->fixed_slot = slotnumber-1; /* auto = -1 */
188}
189
190236static int slot_is_empty(running_device *cartsys, int slotnumber)
191237{
192238   cartridge_t *cart;
193   ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token;
239   ti99_multicart_state *cartslots = (ti99_multicart_state *)cartsys->token;
194240
195241   cart = &cartslots->cartridge[slotnumber];
196242
r7613r7614
202248static void clear_slot(running_device *cartsys, int slotnumber)
203249{
204250   cartridge_t *cart;
205   ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token;
251   ti99_multicart_state *cartslots = (ti99_multicart_state *)cartsys->token;
206252
207253   cart = &cartslots->cartridge[slotnumber];
208254
r7613r7614
213259   cart->grom_ptr = NULL;
214260}
215261
262static void grom_write_address(ti99_multicart_state *cartslots, UINT8 data)
263{
264   /* We are writing; the read states will automatically fall back to default. */
265   cartslots->raddr_LSB = FALSE;
266
267   /* Fore more comments, see machine/ti99_4x.c */
268   if (cartslots->waddr_LSB)
269   {
270      /* Accept low byte (2nd write) */
271      cartslots->grom_address = (cartslots->grom_address & 0xff00) | (data & 0x00ff);
272      cartslots->waddr_LSB = FALSE;
273   }
274   else
275   {
276      /* Accept high byte (1st write) */
277      cartslots->grom_address = ((data<<8) & 0xff00) | (cartslots->grom_address & 0x00ff);
278      cartslots->waddr_LSB = TRUE;
279   }
280}
281
216282/*
217    GROM access. Accesses the GROMs in the cartridge. GROM memory is
218    accessed serially via a set of ports. The GRMWA port (bank 0: 0x9c02)
219    takes two consecutive byte writes which represent the high and low byte
220    of the memory address in the GROM space. Once set, bytes can be read
221    by repeated read accesses on the GRMRD port (bank 0: 0x9800). The
222    address pointer advances on each read. The pointer wraps at the end
223    of each GROM chip memory space, i.e. every 8KiB.
224    This function takes the current GROM address minus 0x6000 which is the
225    lowest address for cartridge GROMs. Lower addresses access GROMs in the
226    console only, which appear in all banks.
227    Note that the GROM access mechanism is identical for all cartridge
228    types.
283   Set the address pointer value or write to GRAM (if available).
229284*/
230UINT8 ti99_cartridge_grom_read(running_device *device, int cart_offset)
285WRITE8_DEVICE_HANDLER(ti99_cartridge_grom_w)
231286{
287   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
288
289   /* Set the cart slot. Note that the port must be adjusted for 16-bit
290      systems, i.e. it should be shifted left by 1.
291      // 1001 1wbb bbbb bbr0
292   */
293   cartridge_slot_set(device, (offset>>2) & 0x00ff);   
294   
295   if (offset & 0x0002)
296      grom_write_address(cartslots, data);
297   else
298      cartslots->raddr_LSB = cartslots->waddr_LSB = FALSE;
299      /* TODO: write to GRAM */   
300}
301
302/*
303   Deliver the local address pointer value. Note that this must be
304   in sync with the console.
305*/
306static UINT8 grom_read_address(ti99_multicart_state *cartslots)
307{
308   UINT8 reply;
309   /* When reading, reset the hi/lo flag byte for writing.
310   TODO: Verify this with a real machine. */
311   cartslots->waddr_LSB = FALSE;
312   
313   /* Address reading is done in two steps; first, the high byte
314   is transferred, then the low byte. */
315   if (cartslots->raddr_LSB)
316   {
317      /* second pass */
318      reply = cartslots->grom_address & 0x00ff;
319      cartslots->raddr_LSB = FALSE;
320   }
321   else
322   {
323      /* first pass */
324      reply = (cartslots->grom_address>>8) & 0x00ff;
325      cartslots->raddr_LSB = TRUE;
326   }
327   return reply;
328}
329
330/*
331   GROM access. Accesses the GROMs in the cartridge. GROM memory is
332   accessed serially via a set of ports. The GRMWA port (bank 0: 0x9c02)
333   takes two consecutive byte writes which represent the high and low byte
334   of the memory address in the GROM space. Once set, bytes can be read
335   by repeated read accesses on the GRMRD port (bank 0: 0x9800). The
336   address pointer advances on each read. The pointer wraps at the end
337   of each GROM chip memory space, i.e. every 8KiB.
338   This function takes the current GROM address minus 0x6000 which is the
339   lowest address for cartridge GROMs. Lower addresses access GROMs in the
340   console only, which appear in all banks.
341   Note that the GROM access mechanism is identical for all cartridge
342   types.
343*/
344READ8_DEVICE_HANDLER(ti99_cartridge_grom_r)
345{
232346   UINT8 value;
233347   int slot;
234348   cartridge_t *cartridge;
235   ti99_multicart_t *cartslots = (ti99_multicart_t *)device->token;
349   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
236350
351   /* Set the cart slot. Note that the port must be adjusted for 16-bit
352      systems, i.e. it should be shifted left by 1.
353      1001 1wbb bbbb bbr0
354   */
355   cartridge_slot_set(device, (offset>>2) & 0x00ff);   
356   
357   if (offset & 0x0002)
358      return grom_read_address(cartslots);
359
237360   /* Handle the legacy mode. */
238361   if (in_legacy_mode(device))
239      return cartridge_grom_read_legacy(device, cart_offset);
362      return cartridge_grom_read_legacy(device);
240363
241364   slot = cartslots->active_slot;
242365   /*
243        This fixes a minor issue: The selection mechanism of the console
244        concludes that there are multiple cartridges plugged in when it
245        checks the different GROM bases and finds different data. Empty
246        slots should return 0 at all addresses, but when we have only
247        one cartridge, this entails that the second cartridge is
248        different (all zeros), and so we get a meaningless selection
249        option between cartridge 1 and 1 and 1 ...
250
251        So if next_free_slot==1, we have one cartridge in slot 0.
252        In that case we trick the OS to believe that the addressed
253        cartridge appears at all locations which causes it to assume a
254        standard single cartslot.
255    */
366      This fixes a minor issue: The selection mechanism of the console
367      concludes that there are multiple cartridges plugged in when it
368      checks the different GROM bases and finds different data. Empty
369      slots should return 0 at all addresses, but when we have only
370      one cartridge, this entails that the second cartridge is
371      different (all zeros), and so we get a meaningless selection
372      option between cartridge 1 and 1 and 1 ...
373     
374      So if next_free_slot==1, we have one cartridge in slot 0.
375      In that case we trick the OS to believe that the addressed
376      cartridge appears at all locations which causes it to assume a
377      standard single cartslot.
378   */
256379   if (cartslots->fixed_slot==AUTO && cartslots->next_free_slot==1)
257380      slot=0;
258381
r7613r7614
261384   else
262385   {
263386      cartridge = &cartslots->cartridge[slot];
264
265387      if ((cartridge->grom_size>0) && (cartridge->pcb!=NULL))
266388      {
267389         /* This is the reason why we need the image size: Read
268               access beyond the image size must be detected. */
269         if (cart_offset > cartridge->grom_size)
270            return 0;
271
272         value = (UINT8)cartridge->grom_buffer;
273         /* read ahead */
274         cartridge->grom_buffer = cartridge->grom_ptr[cart_offset];
390         access beyond the image size must be detected. */
391         /* TODO: replace this using a bitmap of the available GROMs */
392         if ((cartslots->grom_address < 0x6000) || (cartslots->grom_address > (cartridge->grom_size+0x6000)))
393            value = 0;
394         else
395         {
396            /* Buffered GROM access. We use a (virtual) common buffer to avoid implementing this for each cartridge. */
397            value = (UINT8)cartslots->grom_buffer;
398            /* read ahead */
399            cartslots->grom_buffer = cartridge->grom_ptr[cartslots->grom_address-0x6000];
400         }
275401      }
276402      else
277403      {
278404         /* We assume that empty sockets return 0 */
279405         value = 0;
280         logerror("Empty socket at address G(%d)>%04x\n", slot, 0x6000 + cart_offset);
406         //printf("Empty socket at address G(%d)>%04x\n", slot, cartslots->grom_address);
281407      }
408      //         printf("GROM address (cart) = %04x, reply = %02x\n", cartslots->grom_address, value);
409      /* The program counter wraps at each GROM chip size (8K),
410      so 0x5fff + 1 = 0x4000. */
411      cartslots->grom_address = ((cartslots->grom_address + 1) & 0x1FFF) | (cartslots->grom_address & 0xE000);
412     
413      /* Reset the read and write address flipflops. */
414      cartslots->raddr_LSB = cartslots->waddr_LSB = FALSE;
282415   }
283//  printf("grom access(port = %x, address = %04x) = %02x\n", slot,  0x6000 + cart_offset*2, value);
284416   return value;
285417}
286418
287419/*
288    Find the index of the cartridge name. We assume the format
289    <name><number>, i.e. the number is the longest string from the right
290    which can be interpreted as a number.
420   Find the index of the cartridge name. We assume the format
421   <name><number>, i.e. the number is the longest string from the right
422   which can be interpreted as a number.
291423*/
292424static int get_index_from_tagname(running_device *image)
293425{
r7613r7614
301433}
302434
303435/*
304    Common routine to assemble cartridges from resources.
436   Common routine to assemble cartridges from resources.
305437*/
306438static cartridge_t *assemble_common(running_device *cartslot)
307439{
308440   /* Pointer to the cartridge structure. */
309441   cartridge_t *cartridge;
310442   running_device *cartsys = cartslot->owner;
311   ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token;
312
443   ti99_multicart_state *cartslots = (ti99_multicart_state *)cartsys->token;
444   
313445   void *socketcont;
314446   int reslength;
315447   int i;
316
448   
317449   int slotnumber = get_index_from_tagname(cartslot)-1;
318450   assert(slotnumber>=0 && slotnumber<NUMBER_OF_CARTRIDGE_SLOTS);
319
451   
320452   /* There is a cartridge in this slot, check the maximum slot number. */
321453   if (cartslots->next_free_slot <= slotnumber)
322454   {
323455      cartslots->next_free_slot = slotnumber+1;
324456   }
325457   cartridge = &cartslots->cartridge[slotnumber];
326
458   
327459   /* Get the socket which is retrieved by the multicart instance in
328       the state of the cartslot instance. */
460   the state of the cartslot instance. */
329461   socketcont = cartslot_get_socket(cartslot, "grom_socket");
330462   reslength = cartslot_get_resource_length(cartslot, "grom_socket");
331463   if (socketcont != NULL)
r7613r7614
333465      cartridge->grom_ptr = (UINT8 *)socketcont;
334466      cartridge->grom_size = reslength;
335467   }
336
468   
337469   socketcont = cartslot_get_socket(cartslot, "rom_socket");
338470   reslength = cartslot_get_resource_length(cartslot, "rom_socket");
339471   if (socketcont != NULL)
r7613r7614
348480            cont16b[i] = BIG_ENDIANIZE_INT16(cont16b[i]);
349481      }
350482   }
351
483   
352484   socketcont = cartslot_get_socket(cartslot, "rom2_socket");
353485//  reslength = cartslot_get_resource_length(cartslot, "rom2_socket");  /* cannot differ from rom_socket */
354486   if (socketcont != NULL)
r7613r7614
384516static void set_pointers(running_device *pcb, int index)
385517{
386518   running_device *cartsys = pcb->owner->owner;
387   ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token;
519   ti99_multicart_state *cartslots = (ti99_multicart_state *)cartsys->token;
388520   ti99_pcb_t *pcb_def = (ti99_pcb_t *)pcb->token;
389521
390522   pcb_def->read = (read16_device_func) pcb->get_config_fct(TI99CARTINFO_FCT_6000_R);
r7613r7614
511643   int i;
512644   cartridge_t *cart;
513645   running_device *cartsys = image->owner;
514   ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token;
646   ti99_multicart_state *cartslots = (ti99_multicart_state *)cartsys->token;
515647
516648   slotnumber = get_index_from_tagname(image)-1;
517649//  printf("Disassemble cartridge %d\n", slotnumber);
r7613r7614
18661998{
18671999   running_device *pcbdev = cartslot_get_pcb(image);
18682000   running_device *cartsys = image->owner;
1869   ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token;
2001   ti99_multicart_state *cartslots = (ti99_multicart_state *)cartsys->token;
18702002
18712003   int result;
18722004
r7613r7614
18812013         /* If we are here, we have a multicart. */
18822014         ti99_pcb_t *pcb = (ti99_pcb_t *)pcbdev->token;
18832015         cartslot_t *cart = (cartslot_t *)image->token;
1884
2016         
18852017         /* try opening this as a multicart */
18862018         /* This line requires that cartslot_t be included in cartslot.h,
1887            otherwise one cannot make use of multicart handling within such a
1888            custom LOAD function. */
2019         otherwise one cannot make use of multicart handling within such a
2020         custom LOAD function. */
18892021         multicart_open_error me = multicart_open(image_filename(image), image->machine->gamedrv->name, MULTICART_FLAGS_LOAD_RESOURCES, &cart->mc);
1890
2022         
18912023         /* Now that we have loaded the image files, let the PCB put them all
1892            together. This means we put the images in a structure which allows
1893            for a quick access by the memory handlers. Every PCB defines an
1894            own assembly method. */
2024         together. This means we put the images in a structure which allows
2025         for a quick access by the memory handlers. Every PCB defines an
2026         own assembly method. */
18952027         if (me == MCERR_NONE)
18962028            result = pcb->assemble(image);
18972029         else
18982030            fatalerror("Error loading multicart: %s\n", multicart_error_text(me));
1899
2031         
19002032         /* This is for legacy support. If we have no multicart left
1901            but there are still legacy dumps, we switch to legacy mode. */
2033         but there are still legacy dumps, we switch to legacy mode. */
19022034         if (result != INIT_FAIL)
19032035            cartslots->multi_slots++;
19042036      }
r7613r7614
19172049static DEVICE_IMAGE_UNLOAD( ti99_cartridge )
19182050{
19192051   running_device *pcbdev;
1920   ti99_multicart_t *cartslots = (ti99_multicart_t *)image->owner->token;
2052   ti99_multicart_state *cartslots = (ti99_multicart_state *)image->owner->token;
19212053
19222054   if (image->token == NULL)
19232055   {
r7613r7614
19772109  - Both modes may change on plugging and unplugging.
19782110******************************************************************************/
19792111
1980static UINT8 cartridge_grom_read_legacy(running_device *cartsys, int cart_offset)
2112static UINT8 cartridge_grom_read_legacy(running_device *cartsys)
19812113{
19822114   int slot;
19832115   cartridge_t *cartridge;
1984   ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token;
2116   ti99_multicart_state *cartslots = (ti99_multicart_state *)cartsys->token;
19852117
19862118   UINT8 value;
19872119
r7613r7614
19962128   if (cartridge->grom_size>0)
19972129   {
19982130      /* This is the reason why we need the image size: Read
1999        access beyond the image size must be detected. */
2000      if (cart_offset > cartridge->grom_size)
2131      access beyond the image size must be detected. */
2132      if ((cartslots->grom_address < 0x6000) || (cartslots->grom_address > (cartridge->grom_size+0x6000)))
20012133         return 0;
2002
2003      value = (UINT8)cartridge->grom_buffer;
2134     
2135      value =  (UINT8)cartslots->grom_buffer;
20042136      /* read ahead */
2005      cartridge->grom_buffer = cartridge->grom_ptr[cart_offset];
2137      cartslots->grom_buffer = cartridge->grom_ptr[cartslots->grom_address-0x6000];
2138      //  printf("GROM address = %04x, reply = %02x\n", console_GROMs.addr, reply>>8);
2139      /* The program counter wraps at each GROM chip size (8K),
2140      so 0x5fff + 1 = 0x4000. */
2141      cartslots->grom_address = ((cartslots->grom_address + 1) & 0x1FFF) | (cartslots->grom_address & 0xE000);
2142     
2143      /* Reset the read and write address flipflops. */
2144      cartslots->raddr_LSB = cartslots->waddr_LSB = FALSE;
20062145   }
20072146   else
20082147   {
20092148      /* We assume that empty sockets return 0 */
20102149      value = 0;
2011      logerror("Empty socket at address G(%d)>%04x\n", slot, 0x6000 + cart_offset);
2150      logerror("Empty socket at address G(%d)>%04x\n", slot, cartslots->grom_address);
20122151   }
2013
2014   //  printf("grom access(port = %x, address = %04x) = %02x\n", slot,  0x6000 + cart_offset*2, value);
20152152   return value;
20162153}
20172154
20182155static READ16_DEVICE_HANDLER( ti99_cart_r_legacy )
20192156{
20202157   int slotmbx, slotmini, slotebr2, slotrom;
2021   ti99_multicart_t *cartslots = (ti99_multicart_t *)device->token;
2158   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
20222159
20232160#if 0
20242161   if (hsgpl_crdena)
r7613r7614
20632200static WRITE16_DEVICE_HANDLER( ti99_cart_w_legacy )
20642201{
20652202   int slotmbx, slotmini, slotebr2, slotrom;
2066   ti99_multicart_t *cartslots = (ti99_multicart_t *)device->token;
2203   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
20672204
20682205#if 0
20692206   if (hsgpl_crdena)
r7613r7614
21172254static READ8_DEVICE_HANDLER( ti99_cart_r_legacy8 )
21182255{
21192256   int slotmbx, slotmini, slotebr2, slotrom;
2120   ti99_multicart_t *cartslots = (ti99_multicart_t *)device->token;
2257   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
21212258
21222259#if 0
21232260   if (hsgpl_crdena)
r7613r7614
21652302static WRITE8_DEVICE_HANDLER( ti99_cart_w_legacy8 )
21662303{
21672304   int slotmbx, slotmini, slotebr2, slotrom;
2168   ti99_multicart_t *cartslots = (ti99_multicart_t *)device->token;
2305   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
21692306
21702307#if 0
21712308   if (hsgpl_crdena)
r7613r7614
22172354static int load_legacy(running_device *image)
22182355{
22192356   running_device *cartsys = image->owner;
2220   ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token;
2357   ti99_multicart_state *cartslots = (ti99_multicart_state *)cartsys->token;
22212358
22222359   /* Some comments originally in machine/ti99_4x.c */
22232360
r7613r7614
24372574   int i;
24382575   running_device *cartsys = image->owner;
24392576
2440   ti99_multicart_t *cartslots = (ti99_multicart_t *)cartsys->token;
2577   ti99_multicart_state *cartslots = (ti99_multicart_state *)cartsys->token;
24412578
24422579   slotc_type_t type = SLOTC_EMPTY;
24432580   int slot = get_index_from_tagname(image)-1;
r7613r7614
25342671{
25352672   int i;
25362673//  printf("DEVICE_START(ti99_multicart)\n");
2537   ti99_multicart_t *cartslots = (ti99_multicart_t *)device->token;
2674   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
25382675
25392676   cartslots->active_slot = 0;
25402677   cartslots->next_free_slot = 0;
r7613r7614
25672704static DEVICE_RESET(ti99_multicart)
25682705{
25692706   /* Consider to propagate RESET to cartridges.
2570       However, schematics do not reveal any pin for resetting a cartridge;
2571       the reset line is an input used when plugging in a cartridge. */
2572//    printf("DEVICE_RESET(ti99_multicart)\n");
2707   However, schematics do not reveal any pin for resetting a cartridge;
2708   the reset line is an input used when plugging in a cartridge. */
2709
2710   /* Allows to manually lock the cartslot system to a specific slot.
2711      We take slot numbers from 0 (automatic mode) to the maximum. */
2712   
2713   ti99_multicart_state *cartslots = (ti99_multicart_state *)device->token;
2714   int slotnumber = (input_port_read(device->machine, "CFG") >> config_cartslot_bit) & config_cartslot_mask;
2715   assert(slotnumber>=0 && slotnumber<=255);
2716   cartslots->fixed_slot = slotnumber-1; /* auto = -1 */
2717   cartslots->grom_address = 0x0000;
2718   cartslots->grom_buffer = 0x00;
2719   cartslots->raddr_LSB = cartslots->waddr_LSB = FALSE;
25732720}
25742721
25752722/*
r7613r7614
25842731*/
25852732READ16_DEVICE_HANDLER( ti99_multicart_r )
25862733{
2587   ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token;
2734   ti99_multicart_state *cartslots = (ti99_multicart_state *) device->token;
25882735   int slot = cartslots->active_slot;
25892736   cartridge_t *cart;
2590
2737   
25912738   /* Sanity check. Higher slots are always empty. */
25922739   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
25932740      return 0;
2594
2741   
25952742   /* Same as above (GROM read): If there is only one cartridge there
2596       is no use of trying other banks. There is one issue with the
2597       selection mechanism: When the console probes the GROM banks and
2598       we have a ROM-only cartridge plugged in, it checks bank 0 and bank 1,
2599       finds no GROM, and then fails to dummy-check bank 0 again which would
2600       have set our cartridge expander to slot 0. But in slot 1 there is no
2601       ROM cartridge, so nothing shows up in the selection list. We work
2602       around this with the following line. */
2743   is no use of trying other banks. There is one issue with the
2744   selection mechanism: When the console probes the GROM banks and
2745   we have a ROM-only cartridge plugged in, it checks bank 0 and bank 1,
2746   finds no GROM, and then fails to dummy-check bank 0 again which would
2747   have set our cartridge expander to slot 0. But in slot 1 there is no
2748   ROM cartridge, so nothing shows up in the selection list. We work
2749   around this with the following line. */
26032750   if (cartslots->fixed_slot==AUTO && cartslots->next_free_slot==1)
26042751      slot=0;
2605
2752   
26062753   cart = &cartslots->cartridge[slot];
2607
2754   
26082755   /* Idle the CPU */
26092756        cpu_adjust_icount(devtag_get_device(device->machine, "maincpu"),-4);
2610
2757       
26112758   // Alternatively:
26122759   // cpu_spinuntil_time(device->machine->firstcpu, ATTOTIME_IN_USEC(6));
2613
2614//  printf("rpk = %d, bin = %d\n", cartslots->multi_slots,cartslots->legacy_slots);
2615
2760   
2761   //  printf("rpk = %d, bin = %d\n", cartslots->multi_slots,cartslots->legacy_slots);
2762   
26162763   /* Handle legacy mode. */
26172764   if (in_legacy_mode(device))
26182765   {
26192766      return ti99_cart_r_legacy(device, offset, mem_mask);
26202767   }
2621
2768   
26222769   if (!slot_is_empty(device, slot))
26232770   {
2624//      printf("accessing cartridge in slot %d\n", slot);
2771      //      printf("accessing cartridge in slot %d\n", slot);
26252772      ti99_pcb_t *pcbdef = (ti99_pcb_t *)cart->pcb->token;
2626//      printf("address=%lx, offset=%lx\n", pcbdef, offset);
2773      //      printf("address=%lx, offset=%lx\n", pcbdef, offset);
26272774      return (*pcbdef->read)(cart->pcb, offset, mem_mask);
26282775   }
26292776   else
26302777   {
2631//      printf("No cartridge in slot %d\n", slot);
2778      //      printf("No cartridge in slot %d\n", slot);
26322779      return 0;
26332780   }
26342781}
26352782
26362783/*
2637    Accesses the ROM regions of the cartridge for writing.
2638    This is the area from 0x6000 to 0x7fff. Each cartridge is reponsible
2639    for all kinds of magic which is done inside this area. Specifically,
2640    writing is often used to swap banks for subsequent reads. The actual
2641    effect of writing (beyond setting values in a RAM chip) are
2642    cartridge-specific and must be handled within the cartridge pcb.
2643    The currently set GROM bank determines which cartridge is actually
2644    accessed, also for ROM reads.
2784   Accesses the ROM regions of the cartridge for writing.
2785   This is the area from 0x6000 to 0x7fff. Each cartridge is reponsible
2786   for all kinds of magic which is done inside this area. Specifically,
2787   writing is often used to swap banks for subsequent reads. The actual
2788   effect of writing (beyond setting values in a RAM chip) are
2789   cartridge-specific and must be handled within the cartridge pcb.
2790   The currently set GROM bank determines which cartridge is actually
2791   accessed, also for ROM reads.
26452792*/
26462793WRITE16_DEVICE_HANDLER( ti99_multicart_w )
26472794{
2648   ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token;
2795   ti99_multicart_state *cartslots = (ti99_multicart_state *) device->token;
26492796   int slot = cartslots->active_slot;
26502797   cartridge_t *cart;
26512798
r7613r7614
26872834*/
26882835READ8_DEVICE_HANDLER( ti99_multicart_cru_r )
26892836{
2690   ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token;
2837   ti99_multicart_state *cartslots = (ti99_multicart_state *) device->token;
26912838   cartridge_t *cart;
26922839
26932840   int slot = cartslots->active_slot;
r7613r7614
27202867*/
27212868WRITE8_DEVICE_HANDLER( ti99_multicart_cru_w )
27222869{
2723   ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token;
2870   ti99_multicart_state *cartslots = (ti99_multicart_state *) device->token;
27242871   cartridge_t *cart;
27252872
27262873   int slot = cartslots->active_slot;
r7613r7614
27532900*/
27542901READ8_DEVICE_HANDLER(ti99_multicart8_r)
27552902{
2756   ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token;
2903   ti99_multicart_state *cartslots = (ti99_multicart_state *) device->token;
27572904   cartridge_t *cart;
27582905
27592906   int slot = cartslots->active_slot;
r7613r7614
27922939
27932940WRITE8_DEVICE_HANDLER(ti99_multicart8_w)
27942941{
2795   ti99_multicart_t *cartslots = (ti99_multicart_t *) device->token;
2942   ti99_multicart_state *cartslots = (ti99_multicart_state *) device->token;
27962943   cartridge_t *cart;
27972944
27982945   int slot = cartslots->active_slot;
r7613r7614
28242971      }
28252972   }
28262973}
2974#define TI99_CARTRIDGE_SLOT(p)  MDRV_CARTSLOT_ADD(p) \
2975        MDRV_CARTSLOT_EXTENSION_LIST("rpk,bin") \
2976        MDRV_CARTSLOT_PCBTYPE(0, "none", TI99_CARTRIDGE_PCB_NONE) \
2977        MDRV_CARTSLOT_PCBTYPE(1, "standard", TI99_CARTRIDGE_PCB_STD) \
2978        MDRV_CARTSLOT_PCBTYPE(2, "paged", TI99_CARTRIDGE_PCB_PAGED) \
2979        MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM) \
2980        MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER) \
2981        MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX) \
2982        MDRV_CARTSLOT_PCBTYPE(6, "paged379i", TI99_CARTRIDGE_PCB_PAGED379I) \
2983        MDRV_CARTSLOT_PCBTYPE(7, "pagedcru", TI99_CARTRIDGE_PCB_PAGEDCRU) \
2984        MDRV_CARTSLOT_START(ti99_cartridge) \
2985        MDRV_CARTSLOT_LOAD(ti99_cartridge) \
2986        MDRV_CARTSLOT_UNLOAD(ti99_cartridge)
28272987
28282988static MACHINE_DRIVER_START(ti99_multicart)
2829   MDRV_CARTSLOT_ADD("cartridge1")
2830   MDRV_CARTSLOT_EXTENSION_LIST("rpk,bin")
2831   MDRV_CARTSLOT_PCBTYPE(0, "none", TI99_CARTRIDGE_PCB_NONE)
2832   MDRV_CARTSLOT_PCBTYPE(1, "standard", TI99_CARTRIDGE_PCB_STD)
2833   MDRV_CARTSLOT_PCBTYPE(2, "paged", TI99_CARTRIDGE_PCB_PAGED)
2834   MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM)
2835   MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER)
2836   MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX)
2837   MDRV_CARTSLOT_PCBTYPE(6, "paged379i", TI99_CARTRIDGE_PCB_PAGED379I)
2838   MDRV_CARTSLOT_PCBTYPE(7, "pagedcru", TI99_CARTRIDGE_PCB_PAGEDCRU)
2839
2840   MDRV_CARTSLOT_START(ti99_cartridge)
2841   MDRV_CARTSLOT_LOAD(ti99_cartridge)
2842   MDRV_CARTSLOT_UNLOAD(ti99_cartridge)
2843
2844   MDRV_CARTSLOT_ADD("cartridge2")
2845   MDRV_CARTSLOT_EXTENSION_LIST("rpk,bin")
2846   MDRV_CARTSLOT_PCBTYPE(0, "none", TI99_CARTRIDGE_PCB_NONE)
2847   MDRV_CARTSLOT_PCBTYPE(1, "standard", TI99_CARTRIDGE_PCB_STD)
2848   MDRV_CARTSLOT_PCBTYPE(2, "paged", TI99_CARTRIDGE_PCB_PAGED)
2849   MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM)
2850   MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER)
2851   MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX)
2852   MDRV_CARTSLOT_PCBTYPE(6, "paged379i", TI99_CARTRIDGE_PCB_PAGED379I)
2853   MDRV_CARTSLOT_PCBTYPE(7, "pagedcru", TI99_CARTRIDGE_PCB_PAGEDCRU)
2854
2855   MDRV_CARTSLOT_START(ti99_cartridge)
2856   MDRV_CARTSLOT_LOAD(ti99_cartridge)
2857   MDRV_CARTSLOT_UNLOAD(ti99_cartridge)
2858
2859   MDRV_CARTSLOT_ADD("cartridge3")
2860   MDRV_CARTSLOT_EXTENSION_LIST("rpk,bin")
2861   MDRV_CARTSLOT_PCBTYPE(0, "none", TI99_CARTRIDGE_PCB_NONE)
2862   MDRV_CARTSLOT_PCBTYPE(1, "standard", TI99_CARTRIDGE_PCB_STD)
2863   MDRV_CARTSLOT_PCBTYPE(2, "paged", TI99_CARTRIDGE_PCB_PAGED)
2864   MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM)
2865   MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER)
2866   MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX)
2867   MDRV_CARTSLOT_PCBTYPE(6, "paged379i", TI99_CARTRIDGE_PCB_PAGED379I)
2868   MDRV_CARTSLOT_PCBTYPE(7, "pagedcru", TI99_CARTRIDGE_PCB_PAGEDCRU)
2869
2870   MDRV_CARTSLOT_START(ti99_cartridge)
2871   MDRV_CARTSLOT_LOAD(ti99_cartridge)
2872   MDRV_CARTSLOT_UNLOAD(ti99_cartridge)
2873
2874   MDRV_CARTSLOT_ADD("cartridge4")
2875   MDRV_CARTSLOT_EXTENSION_LIST("rpk,bin")
2876   MDRV_CARTSLOT_PCBTYPE(0, "none", TI99_CARTRIDGE_PCB_NONE)
2877   MDRV_CARTSLOT_PCBTYPE(1, "standard", TI99_CARTRIDGE_PCB_STD)
2878   MDRV_CARTSLOT_PCBTYPE(2, "paged", TI99_CARTRIDGE_PCB_PAGED)
2879   MDRV_CARTSLOT_PCBTYPE(3, "minimem", TI99_CARTRIDGE_PCB_MINIMEM)
2880   MDRV_CARTSLOT_PCBTYPE(4, "super", TI99_CARTRIDGE_PCB_SUPER)
2881   MDRV_CARTSLOT_PCBTYPE(5, "mbx", TI99_CARTRIDGE_PCB_MBX)
2882   MDRV_CARTSLOT_PCBTYPE(6, "paged379i", TI99_CARTRIDGE_PCB_PAGED379I)
2883   MDRV_CARTSLOT_PCBTYPE(7, "pagedcru", TI99_CARTRIDGE_PCB_PAGEDCRU)
2884
2885   MDRV_CARTSLOT_START(ti99_cartridge)
2886   MDRV_CARTSLOT_LOAD(ti99_cartridge)
2887   MDRV_CARTSLOT_UNLOAD(ti99_cartridge)
2989        TI99_CARTRIDGE_SLOT("cartridge1")
2990        TI99_CARTRIDGE_SLOT("cartridge2")
2991        TI99_CARTRIDGE_SLOT("cartridge3")
2992        TI99_CARTRIDGE_SLOT("cartridge4")
28882993MACHINE_DRIVER_END
28892994
2995static const char DEVTEMPLATE_SOURCE[] = __FILE__;
28902996
2891DEVICE_GET_INFO(ti99_multicart)
2892{
2893   switch (state)
2894   {
2895      /* --- the following bits of info are returned as pointers to data --- */
2896      case DEVINFO_PTR_MACHINE_CONFIG:
2897         info->machine_config = MACHINE_DRIVER_NAME(ti99_multicart); break;
2997#define DEVTEMPLATE_ID(p,s)             p##ti99_multicart##s
2998#define DEVTEMPLATE_FEATURES            DT_HAS_START | DT_HAS_STOP | DT_HAS_RESET | DT_HAS_MACHINE_CONFIG
2999#define DEVTEMPLATE_NAME                "TI99 Multi-Cartridge Extender"
3000#define DEVTEMPLATE_FAMILY              "Multi-cartridge system"
3001#include "devtempl.h"
28983002
2899      /* --- the following bits of info are returned as NULL-terminated strings --- */
2900      case DEVINFO_STR_NAME:
2901         strcpy(info->s, "TI99 Multi-Cartridge Extender");
2902         break;
2903
2904      case DEVINFO_INT_TOKEN_BYTES: /* private storage, automatically allocated */
2905         info->i = sizeof(ti99_multicart_t);
2906         break;
2907      case DEVINFO_INT_CLASS:
2908         info->i = DEVICE_CLASS_PERIPHERAL;
2909         break;
2910
2911      case DEVINFO_STR_FAMILY:
2912         strcpy(info->s, "Multi-cartridge system");
2913         break;
2914      case DEVINFO_STR_VERSION:
2915         strcpy(info->s, "1.0");
2916         break;
2917      case DEVINFO_STR_SOURCE_FILE:
2918         strcpy(info->s, __FILE__);
2919         break;
2920      /* --- the following bits of info are returned as pointers to functions --- */
2921      case DEVINFO_FCT_START:
2922         info->start = DEVICE_START_NAME(ti99_multicart);
2923         break;
2924      case DEVINFO_FCT_STOP:
2925         info->stop = DEVICE_STOP_NAME(ti99_multicart);
2926         break;
2927      case DEVINFO_FCT_RESET:
2928         info->reset = DEVICE_RESET_NAME(ti99_multicart);
2929         break;
2930   }
2931}
2932
src/mess/devices/ti99cart.h
r7613r7614
99#ifndef __TI99CART_H__
1010#define __TI99CART_H__
1111
12#include "image.h"
12#define TI99_MULTICART   DEVICE_GET_INFO_NAME(ti99_multicart)
1313
14#define TI99_MULTICART         DEVICE_GET_INFO_NAME(ti99_multicart)
15
16#define TI99_CARTRIDGE_PCB_NONE      DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_none)
17#define TI99_CARTRIDGE_PCB_STD      DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_std)
18#define TI99_CARTRIDGE_PCB_PAGED   DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_paged)
19#define TI99_CARTRIDGE_PCB_MINIMEM   DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_minimem)
20#define TI99_CARTRIDGE_PCB_SUPER   DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_super)
21#define TI99_CARTRIDGE_PCB_MBX      DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_mbx)
22#define TI99_CARTRIDGE_PCB_PAGED379I   DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_paged379i)
23#define TI99_CARTRIDGE_PCB_PAGEDCRU   DEVICE_GET_INFO_NAME(ti99_cartridge_pcb_pagedcru)
24
2514/* We set the number of slots to 8, although we may have up to 16. From a
2615   logical point of view we could have 256, but the operating system only checks
2716   the first 16 banks. */
2817#define NUMBER_OF_CARTRIDGE_SLOTS 8
2918
30/* GROM_port_t: descriptor for a port of 8 GROMs */
31struct _GROM_port_t
32{
33   /* pointer to GROM data */
34   UINT8 *data_ptr;
35   /* current address pointer for the active GROM in port (16 bits) */
36   unsigned int addr;
37   /* GROM data buffer */
38   UINT8 buf;
39   /* internal flip-flops that are set after the first access to the GROM
40    address so that next access is mapped to the LSB, and cleared after each
41    data access */
42   char raddr_LSB, waddr_LSB;
43};
44typedef struct _GROM_port_t GROM_port_t;
19READ8_DEVICE_HANDLER(ti99_cartridge_grom_r);
20WRITE8_DEVICE_HANDLER(ti99_cartridge_grom_w);
4521
46/* Generic TI99 cartridge structure. */
47struct _cartridge_t
48{
49   /* PCB device associated to this cartridge. If NULL, the slot is empty. */
50   running_device *pcb;
51
52        /* GROM buffer size. */
53        int grom_size;
54
55        /* ROM page. */
56        int rom_page;
57        /* RAM page. */
58        int ram_page;
59
60        /* ROM buffer size. All banks have equal sizes. */
61        int rom_size;
62        /* RAM buffer size. All banks have equal sizes. */
63        int ram_size;
64
65        /* pointer to GROM data. */
66        UINT8 *grom_ptr;
67
68        /* GROM buffered data output. */
69        UINT8 grom_buffer;
70
71        /* ROM buffer. We are using this for both 16 bit (99/4a) and 8 bit
72       (99/8) access. */
73        void *rom_ptr;
74
75        /* ROM buffer for the second bank of paged cartridges. Other cartridges
76       usually store their ROM in one large file. */
77        void *rom2_ptr;
78
79        /* RAM buffer. The persistence service is done by the cartridge system.
80       The RAM space is a consecutive space; all banks are in one buffer. */
81        void *ram_ptr;
82};
83typedef struct _cartridge_t cartridge_t;
84
85/* Functions to be called from the console. */
86void   ti99_cartridge_slot_set(running_device *cartsys, int slotnumber);
87void   ti99_lock_cartridge_slot(running_device *cartsys, int slotnumber);
88UINT8  ti99_cartridge_grom_read(running_device *cartsys, int offset);
89
9022DEVICE_GET_INFO(ti99_multicart);
9123
9224READ16_DEVICE_HANDLER(ti99_multicart_r);
src/mess/machine/99_dsk.c
r7613r7614
351351static  READ8_HANDLER(fdc_mem_r)
352352{
353353   running_device *fdc = devtag_get_device(space->machine, "wd179x");
354
355   switch (offset)
356   {
357   case 0x1FF0:               /* Status register */
358      return (wd17xx_status_r(fdc, offset) ^ 0xFF);
359   case 0x1FF2:               /* Track register */
360      return wd17xx_track_r(fdc, offset) ^ 0xFF;
361   case 0x1FF4:               /* Sector register */
362      return wd17xx_sector_r(fdc, offset) ^ 0xFF;
363   case 0x1FF6:               /* Data register */
364      return wd17xx_data_r(fdc, offset) ^ 0xFF;
365   default:                  /* DSR ROM */
354   
355   /* only use the even addresses from 1ff0 to 1ff6.
356      Note that data is inverted. */
357   if (offset >= 0x1ff0 && (offset & 0x09)==0)
358      return wd17xx_r(fdc, (offset >> 1)&0x03) ^ 0xff;
359   else
366360      return ti99_disk_DSR[offset];
367   }
368361}
369362
370363/*
r7613r7614
374367{
375368   running_device *fdc = devtag_get_device(space->machine, "wd179x");
376369
377   data ^= 0xFF;   /* inverted data bus */
378
379   switch (offset)
380   {
381   case 0x1FF8:               /* Command register */
382      wd17xx_command_w(fdc, offset, data);
383      break;
384   case 0x1FFA:               /* Track register */
385      wd17xx_track_w(fdc, offset, data);
386      break;
387   case 0x1FFC:               /* Sector register */
388      wd17xx_sector_w(fdc, offset, data);
389      break;
390   case 0x1FFE:               /* Data register */
391      wd17xx_data_w(fdc, offset, data);
392      break;
393   }
370   /* only use the even addresses from 1ff8 to 1ffe.
371      Note that data is inverted. */
372   if (offset >= 0x1ff0 && (offset & 0x09)==0x08)
373      wd17xx_w(fdc, (offset >> 1)&0x03, data ^ 0xff);
394374}
395375
396376
src/mess/machine/ti99pcod.c
r7613r7614
7272*/
7373#include "emu.h"
7474#include "99_peb.h"
75#include "devices/ti99cart.h"
7675#include "ti99_4x.h"
7776#include "ti99pcod.h"
7877
r7613r7614
117116{
118117   UINT8 reply;
119118   /* GROMs are buffered. Data is retrieved from a buffer,
120    while the buffer is replaced with the next cell
121    content. */
119   while the buffer is replaced with the next cell
120   content. */
122121   reply = pcode_GROMs.buf;
123
122   
124123   /* Get next value, put it in buffer. Note that the
125    GROM wraps at 8K boundaries. */
124   GROM wraps at 8K boundaries. */
126125   pcode_GROMs.buf = pcode_GROMs.data_ptr[pcode_GROMs.addr];
127
126   
128127   /* The program counter wraps at each GROM chip size (8K),
129       so 0x5fff + 1 = 0x4000. */
128   so 0x5fff + 1 = 0x4000. */
130129   pcode_GROMs.addr = ((pcode_GROMs.addr + 1) & 0x1FFF) | (pcode_GROMs.addr & 0xE000);
131
130   
132131   /* Reset the read and write address flipflops. */
133132   pcode_GROMs.raddr_LSB = pcode_GROMs.waddr_LSB = FALSE;
134
133   
135134   return reply;
136135}
137136
r7613r7614
265264      /* Check if we access the GROM port */
266265      switch (offset)
267266      {
268      /* GROMs only answer at even addresses. The odd addresses are
269        undefined, so we can as well just ignore these cases. */
267         /* GROMs only answer at even addresses. The odd addresses are
268         undefined, so we can as well just ignore these cases. */
270269      case 0x1bfc:
271270      case 0x1bfe:
272271         reply = ti99_pcode_grom_r(space, offset);
r7613r7614
278277         break;
279278      default:
280279         /* Accesses ROM 4764 (2*4K)
281               We have two banks here which are activated according
282               to the setting of CRU bit 4
283            */
280         We have two banks here which are activated according
281         to the setting of CRU bit 4
282         */
284283         reply = (bank_select==0)? ti99_pcode_rom1[offset-0x1000] : ti99_pcode_rom2[offset-0x1000];
285284      }
286285   }
src/mess/machine/ti99_4x.c
r7613r7614
425425{
426426   if (gfxparm != 0)
427427      TMS9928A_configure(gfxparm);
428
428   
429429        /* Initialize all. Actually, at this point, we don't know
430           how the switches are set. Later we use the configuration switches to
431           determine which one to use. */
430        how the switches are set. Later we use the configuration switches to
431        determine which one to use. */
432432   ti99_peb_init();
433433   ti99_floppy_controllers_init_all(machine);
434434   ti99_ide_init(machine);
435435   ti99_hsgpl_init(machine);
436436   ti99_usbsm_init(machine);
437
437   
438438   /* Find the cartslot device and cache it. This is a string search,
439       and we don't want to repeat it on each memory access. */
439   and we don't want to repeat it on each memory access. */
440440   cartslots = devtag_get_device(machine, "ti99_multicart");
441441   assert(cartslots != NULL);
442442}
r7613r7614
542542      memory_install_read16_handler(space, 0x9000, 0x93ff, 0, 0, ti99_nop_8_r);
543543      memory_install_write16_handler(space, 0x9400, 0x97ff, 0, 0, ti99_nop_8_w);
544544   }
545   /* Check whether we have locked the cartslot. This uses GROM, which the 4p doesn't have. */
546   if (ti99_model != model_99_4p)
547      ti99_lock_cartridge_slot(cartslots, (input_port_read(machine, "CFG") >> config_cartslot_bit) & config_cartslot_mask);
548545
549546   switch (xRAM_kind)
550547   {
r7613r7614
885882   if (! tms5220_readyq_r())
886883   {
887884      /* Weirdly enough, we are always seeing some problems even though
888        everything is working fine. */
885      everything is working fine. */
889886      attotime time_to_ready = double_to_attotime(tms5220_time_to_ready());
890887      logerror("ti99/4a speech says aaargh!\n");
891888      logerror("(time to ready: %f -> %d)\n", time_to_ready, (int) ceil(3000000*time_to_ready));
r7613r7614
900897static WRITE16_HANDLER ( ti99_wspeech_w )
901898{
902899   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-(54+3));      /* this is just an approx. minimum, it can be much more */
903
904#if 1
900   
901   #if 1
905902   /* the stupid design of the tms5220 core means that ready is cleared when
906    there are 15 bytes in FIFO.  It should be 16.  Of course, if it were the
907    case, we would need to store the value on the bus, which would be more
908    complex. */
903   there are 15 bytes in FIFO.  It should be 16.  Of course, if it were the
904   case, we would need to store the value on the bus, which would be more
905   complex. */
909906   if (! tms5220_readyq_r(devtag_get_device(space->machine, "tms5220")))
910907   {
911908      attotime time_to_ready = double_to_attotime(tms5220_time_to_ready(devtag_get_device(space->machine, "tms5220")));
912909      int cycles_to_ready = cputag_attotime_to_clocks(space->machine, "maincpu", time_to_ready);
913
910     
914911      logerror("time to ready: %f -> %d\n", attotime_to_double(time_to_ready), (int) cycles_to_ready);
915
912     
916913      cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-cycles_to_ready);
917914      timer_set(space->machine, attotime_zero, NULL, 0, /*speech_kludge_callback*/NULL);
918915   }
919#endif
920
916   #endif
917   
921918   tms5220_data_w(devtag_get_device(space->machine, "tms5220"), offset, (data >> 8) & 0xff);
922919}
923920
924static UINT8 GROM_dataread(void)
921static UINT8 GROM_dataread(offs_t offset)
925922{
926   UINT8 reply;
927   if (console_GROMs.addr >= 0x6000)
923   UINT8 reply = 0, replycart;
924   int override_console = FALSE; /* for future extension */
925   
926   if (console_GROMs.addr < 0x6000)
928927   {
929      /* Pass the (one and only) program counter for GROMs. The
930           buffer is set and used in the cartridge chip. */
931      reply = ti99_cartridge_grom_read(cartslots, console_GROMs.addr-0x6000);
932   }
933   else
934   {
935928      /* GROMs are buffered. Data is retrieved from a buffer,
936        while the buffer is replaced with the next cell
937        content. */
929      while the buffer is replaced with the next cell
930      content. */
938931      reply = console_GROMs.buf;
939
932     
940933      /* Get next value, put it in buffer. Note that the
941        GROM wraps at 8K boundaries. */
934      GROM wraps at 8K boundaries. */
942935      console_GROMs.buf = console_GROMs.data_ptr[console_GROMs.addr];
936//      printf("GROM address (cons) = %04x, offset = %04x, reply = %02x\n", console_GROMs.addr, offset, reply);
943937   }
944938
945//  printf("GROM address = %04x, reply = %02x\n", console_GROMs.addr, reply>>8);
939   /* The address pointer in the cartridge system is updated by this call.
940      We pretend to do a data read, so we mask away the address bit in the
941      offset. */
942   replycart = ti99_cartridge_grom_r(cartslots, offset&0xfffc);
943   
944   if (console_GROMs.addr >= 0x6000 || override_console)
945   {
946      reply = replycart;
947   }
948
949   /* Each GROM chip has its own counter, so we update all of them even
950   when we do not access them. */
946951   /* The program counter wraps at each GROM chip size (8K),
947       so 0x5fff + 1 = 0x4000. */
952   so 0x5fff + 1 = 0x4000. */
948953   console_GROMs.addr = ((console_GROMs.addr + 1) & 0x1FFF) | (console_GROMs.addr & 0xE000);
949
954   
950955   /* Reset the read and write address flipflops. */
951956   console_GROMs.raddr_LSB = console_GROMs.waddr_LSB = FALSE;
952
957   
953958   return reply;
954959}
955960
r7613r7614
958963*/
959964READ16_HANDLER ( ti99_grom_r )
960965{
961   UINT16 reply;
962
966   UINT16 reply, replycart;
967   
963968   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4 /*20+3*/);      /* from 4 to 23? */
964//  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
965
969   //  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
970   
966971   /* This implementation features a multislot cartridge system which
967       is based on multiple GROM base addresses. The standard base
968       is >9800 (slot 0). When we access the port >9804, we switch to
969       slot 1, >9808 is slot 2, ... >983C is slot 15. Although theoretically
970       we could address up to 256 banks, the TI operating system does not
971       check more than 16 banks.
972       Cartridges may also contain ROMs which need to be banked
973       simultaneously. We use the cartridge slot number to swap the ROM at
974       >6000, or RAM if available. I don't know whether this is the way
975       Texas Instruments envisaged it in the OS, but it is the only
976       plausible way to allow for GROM+ROM cartridges.
977       Note that some cartridges may have programming flaws which only
978       appear when the cartridge is used in a higher-numbered slot.
979       Parsec is one example which only runs in slot 0 as the
980       programmers hard-coded an access to GROM port 0. Note: This *may*
981       be worked around if we make sure that switching only occurs
982       when the address is set, not when data is read or written. But
983       it's not clear whether this has unwanted side effects.
984    */
985
986   /* Activates a slot in the multi-cartridge extender. */
987   ti99_cartridge_slot_set(cartslots, (offset & 0x01fe)/2);
988
972   is based on multiple GROM base addresses. The standard base
973   is >9800 (slot 0). When we access the port >9804, we switch to
974   slot 1, >9808 is slot 2, ... >983C is slot 15. Although theoretically
975   we could address up to 256 banks, the TI operating system does not
976   check more than 16 banks.
977   Cartridges may also contain ROMs which need to be banked
978   simultaneously. We use the cartridge slot number to swap the ROM at
979   >6000, or RAM if available. I don't know whether this is the way
980   Texas Instruments envisaged it in the OS, but it is the only
981   plausible way to allow for GROM+ROM cartridges.
982   Note that some cartridges may have programming flaws which only
983   appear when the cartridge is used in a higher-numbered slot.
984   Parsec is one example which only runs in slot 0 as the
985   programmers hard-coded an access to GROM port 0. Note: This *may*
986   be worked around if we make sure that switching only occurs
987   when the address is set, not when data is read or written. But
988   it's not clear whether this has unwanted side effects.
989   */
990         
989991   if (offset & 1)
990992   {   /* Read GROM address
991           We only have one GROM program counter for the console GROMs
992           and all cartridge GROMs in all banks(!). Hardware
993           implementations must take this into account as well. Thus,
994           we use a structure here in the console, rather than separate
995           counters in each GROM chip. */
993      We only have one GROM program counter for the console GROMs
994      and all cartridge GROMs in all banks(!). Hardware
995      implementations must take this into account as well. Thus,
996      we use a structure here in the console, rather than separate
997      counters in each GROM chip. */
996998
999      /* We call the cartridge system here, but we ignore the
1000         value. This is done to sync the flags. */
1001      replycart = ti99_cartridge_grom_r(cartslots, (offset<<1))<<8;
1002     
9971003      /* When reading, reset the hi/lo flag byte for writing.
998           TODO: Verify this with a real machine. */
1004      TODO: Verify this with a real machine. */
9991005      console_GROMs.waddr_LSB = FALSE;
1000
1006     
10011007      /* Address reading is done in two steps; first, the high byte
1002           is transferred, then the low byte. */
1008      is transferred, then the low byte. */
10031009      if (console_GROMs.raddr_LSB)
10041010      {
10051011         /* second pass */
r7613r7614
10121018         reply = console_GROMs.addr & 0xff00;
10131019         console_GROMs.raddr_LSB = TRUE;
10141020      }
1021      /* GROM address values must be globally unique. */
1022      assert (replycart == reply);
10151023   }
10161024   else
10171025   {
10181026      /* Read GROM data */
1019      reply = ((UINT16)GROM_dataread()) << 8;
1027      /* Note that we shift the GROM port address to accomodate for
1028         8-bit and 16-bit systems. */
1029      reply = ((UINT16)GROM_dataread(offset<<1)) << 8;
10201030   }
1021
1031   
10221032   if (hsgpl_crdena)
10231033      /* hsgpl buffers are stronger than console GROM buffers */
10241034      reply = ti99_hsgpl_gpl_r(space, offset, mem_mask);
1025
1035   
10261036   return reply;
10271037}
10281038
10291039/*
1030    GPL write
1040   GPL write
10311041*/
10321042WRITE16_HANDLER ( ti99_grom_w )
10331043{
10341044   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4/*20+3*/);      /* from 4 to 23? */
1035//  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
1045   //  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
1046     
1047   if (offset & 1)
1048   {
1049      ti99_cartridge_grom_w(cartslots, (offset<<1), (data>>8)&0xff);
10361050
1037   /* Activates a slot in the multi-cartridge extender. */
1038   ti99_cartridge_slot_set(cartslots, (offset & 0x01fe)/2);
1039
1040   // 1001 1wbb bbbb bbr0
1041
1042   if (offset & 1)
1043   {   /* write GROM address */
1051      /* write GROM address */
10441052      /* see comments above */
10451053      console_GROMs.raddr_LSB = FALSE;
1046
1054         
10471055      /* Implements the internal flipflop.
1048           The Editor/Assembler manuals says that the current address
1049           plus one is returned. This effect is properly emulated
1050           as we are using a read-ahead buffer.
1051        */
1056      The Editor/Assembler manuals says that the current address
1057      plus one is returned. This effect is properly emulated
1058      as we are using a read-ahead buffer.
1059      */
10521060      if (console_GROMs.waddr_LSB)
10531061      {
10541062         /* Accept low byte (2nd write) */
10551063         console_GROMs.addr = (console_GROMs.addr & 0xFF00) | ((data >> 8) & 0xFF);
1056
1064         
10571065         /* Setting the address causes a new read, putting the
1058               value into the buffer. We don't need the value here. */
1059         GROM_dataread();
1066         value into the buffer. We don't need the value here. */
1067         GROM_dataread(offset<<1);
10601068         console_GROMs.waddr_LSB = FALSE;
10611069      }
10621070      else
r7613r7614
10651073         console_GROMs.addr = (data & 0xFF00) | (console_GROMs.addr & 0xFF);
10661074         console_GROMs.waddr_LSB = TRUE;
10671075      }
1068
10691076   }
10701077   else
10711078   {
10721079      /* write GROM data */
10731080      /* the console GROMs are always affected */
10741081      /* BTW, console GROMs are never GRAMs, therefore there is no
1075           need to actually write anything, so we just read ahead
1076           TODO: There could be cartridges with GRAM, so this must be
1077           fixed.
1078        */
1079      GROM_dataread();
1082      need to actually write anything, so we just read ahead
1083      TODO: There could be cartridges with GRAM, so this must be
1084      fixed.
1085      */
1086      GROM_dataread(offset<<1);
10801087      console_GROMs.raddr_LSB = console_GROMs.waddr_LSB = FALSE;
10811088   }
1082
1089   
10831090   if (hsgpl_crdena)
10841091      ti99_hsgpl_gpl_w(space, offset, data, mem_mask);
10851092}
r7613r7614
10901097*/
10911098static READ8_HANDLER ( ti99_grom_r8 )
10921099{
1093   UINT8 reply;
1100   UINT8 reply, replycart;
10941101
10951102   cpu_adjust_icount(space->machine->firstcpu,-4);
10961103
1097   /* Activates a slot in the multi-cartridge extender. */
1098   // 1001 1wbb bbbb bbr0
1099   ti99_cartridge_slot_set(cartslots, (offset & 0x03fc)/4);
1100
11011104   if (offset & 2)
11021105   {
1106      replycart = ti99_cartridge_grom_r(cartslots, offset);
11031107      console_GROMs.waddr_LSB = FALSE;
11041108
11051109      if (console_GROMs.raddr_LSB)
r7613r7614
11121116         reply = (console_GROMs.addr>>8) & 0x00ff;
11131117         console_GROMs.raddr_LSB = TRUE;
11141118      }
1119      /* GROM address values must be globally unique. */
1120      assert (replycart == reply);
11151121   }
11161122   else
1117      reply = GROM_dataread();
1123      reply = GROM_dataread(offset);
11181124
11191125   return reply;
11201126}
r7613r7614
11271133{
11281134   cpu_adjust_icount(space->machine->firstcpu,-4/*20+3*/);      /* from 4 to 23? */
11291135
1130   /* Activates a slot in the multi-cartridge extender. */
1131   ti99_cartridge_slot_set(cartslots, (offset & 0x03fc)/4);
1132
11331136   if (offset & 2)
11341137   {
1138      ti99_cartridge_grom_w(cartslots, offset, data);
11351139      console_GROMs.raddr_LSB = FALSE;
11361140      if (console_GROMs.waddr_LSB)
11371141      {
11381142         console_GROMs.addr = (console_GROMs.addr & 0xFF00) | (data & 0xFF);
11391143
1140         GROM_dataread();
1144         GROM_dataread(offset);
11411145         console_GROMs.waddr_LSB = FALSE;
11421146      }
11431147      else
r7613r7614
11491153   }
11501154   else
11511155   {
1152      GROM_dataread();
1156      GROM_dataread(offset);
11531157      console_GROMs.raddr_LSB = console_GROMs.waddr_LSB = FALSE;
11541158   }
11551159}
r7613r7614
11611165READ16_HANDLER ( ti99_4p_grom_r )
11621166{
11631167   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);      /* HSGPL is located on 8-bit bus? */
1164//  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
1165
1168   //  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
1169   
11661170   return /*hsgpl_crdena ?*/ ti99_hsgpl_gpl_r(space, offset, mem_mask) /*: 0*/;
11671171}
11681172
r7613r7614
11721176WRITE16_HANDLER ( ti99_4p_grom_w )
11731177{
11741178   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);      /* HSGPL is located on 8-bit bus? */
1175//  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
1176
1179   //  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
1180   
11771181   /*if (hsgpl_crdena)*/
1178      ti99_hsgpl_gpl_w(space, offset, data, mem_mask);
1182   ti99_hsgpl_gpl_w(space, offset, data, mem_mask);
11791183}
11801184
11811185
r7613r7614
11901194   int page = offset >> 12;
11911195   UINT32 mapper_reg;
11921196   UINT8 reply = 0;
1193
1197   
11941198   if (ti99_8_enable_rom_and_ports)
11951199   {
11961200      /* This is only important for address access 0000-1fff and
1197           8000-9fff. Outside, the mapper mode is used. */
1201      8000-9fff. Outside, the mapper mode is used. */
11981202      if ((offset >= 0x0000) && (offset < 0x2000))
11991203      {
12001204         /* ROM */
r7613r7614
12111215            /* RAM: >8000 - >83ff */
12121216            reply = sRAM_ptr_8[offset & 0x1fff];
12131217            break;
1214
1218           
12151219         case 1:
12161220            /* >8400 - >840f: sound (cannot read)
1217                   >8410 - >87ff: SRAM */
1221            >8410 - >87ff: SRAM */
12181222            if (offset >= 0x8410)
12191223               reply = sRAM_ptr_8[offset & 0x1fff];
12201224            break;
1221
1225           
12221226         case 2:
12231227            /* VDP read + mapper status */
12241228            if (offset < 0x8810)
r7613r7614
12271231               {
12281232                  if (offset & 2)
12291233                     /* read VDP status >8802 */
1230                     reply = TMS9928A_register_r(space, 0);
1234                  reply = TMS9928A_register_r(space, 0);
12311235                  else
12321236                     /* read VDP RAM >8800 */
1233                     reply = TMS9928A_vram_r(space, 0);
1237                  reply = TMS9928A_vram_r(space, 0);
12341238               }
12351239            }
12361240            else
r7613r7614
12401244               ti99_8_mapper_status = 0;
12411245            }
12421246            break;
1243
1247           
12441248         case 4:
12451249            /* speech read: >9000 */
12461250            if (! (offset & 1))
r7613r7614
12491253               reply = tms5220_status_r(devtag_get_device(space->machine, "tms5220"), 0);
12501254            }
12511255            break;
1252
1256           
12531257         case 6:
12541258            /* GROM read: >9800 */
12551259            if (! (offset & 1))
12561260               reply = ti99_grom_r8(space, offset);
12571261            break;
1258
1262           
12591263         default:
12601264            logerror("unmapped read offs=%d\n", (int) offset);
12611265            break;
r7613r7614
12631267         return reply;
12641268      }
12651269   }
1266
1270   
12671271   mapper_reg = ti99_8_mapper_regs[page];
12681272   offset = (mapper_reg + (offset & 0x0fff)) & 0x00ffffff;
1269
1270#if 0
1273   
1274   #if 0
12711275   /* test read protect */
12721276   if (mapper_reg & 0x20000000)
12731277      ;
1274
1278   
12751279   /* test execute protect */
12761280   if (mapper_reg & 0x40000000)
12771281      ;
1278#endif
1279
1282   #endif
1283   
12801284   if (offset < 0x010000)
1281      /* Read RAM */
1282      reply = xRAM_ptr_8[offset];
1283
1285   /* Read RAM */
1286   reply = xRAM_ptr_8[offset];
1287   
12841288   if (offset >= 0xff0000)
12851289   {
12861290      switch ((offset >> 13) & 7)
r7613r7614
12971301         /* ffe000 - ffffff: ? */
12981302         logerror("unmapped read page=%d offs=%d\n", (int) page, (int) offset);
12991303         break;
1300
1304         
13011305      case 2:
13021306         /* ff4000 - ff5fff: DSR space */
13031307         reply = ti99_8_peb_r(space, offset & 0x1fff);
13041308         break;
1305
1309         
13061310      case 3:
13071311         /* ff6000 - ff7fff: cartridge ROM space */
13081312         offset &= 0x1fff;
1309
1313         
13101314         /* We do not support hsgpl here because it is a 16 bit
1311               system. Just check the cartridges.  */
1315         system. Just check the cartridges.  */
13121316         reply = ti99_multicart8_r(multicart8, offset);
13131317         break;
1314
1318         
13151319      case 5:
13161320         /* ffa000 - ffbfff: >2000 ROM (ROM1) */
13171321         reply = ROM1_ptr_8[offset & 0x1fff];
13181322         break;
1319
1323         
13201324      case 6:
13211325         /* ffc000 - ffdfff: >6000 ROM */
13221326         reply = ROM3_ptr_8[offset & 0x1fff];
13231327         break;
13241328      }
13251329   }
1326
1330   
13271331   return reply;
13281332}
13291333
r7613r7614
14071411            if (! (offset & 1))
14081412            {
14091413               cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-48*4);      /* this is just an approx. minimum, it can be much more */
1410
1414               
14111415               /* the stupid design of the tms5220 core means that ready is cleared when
1412                    there are 15 bytes in FIFO.  It should be 16.  Of course, if it were the
1413                    case, we would need to store the value on the bus, which would be more
1414                    complex. */
1416               there are 15 bytes in FIFO.  It should be 16.  Of course, if it were the
1417               case, we would need to store the value on the bus, which would be more
1418               complex. */
14151419               if (! tms5220_readyq_r(devtag_get_device(space->machine, "tms5220")))
14161420               {
14171421                  attotime time_to_ready = double_to_attotime(tms5220_time_to_ready(devtag_get_device(space->machine, "tms5220")));
14181422                  double d = cputag_attotime_to_clocks(space->machine, "maincpu", time_to_ready);
14191423                  int cycles_to_ready = ((int) (d + 3)) & ~3;
1420
1424                 
14211425                  logerror("time to ready: %f -> %d\n", attotime_to_double(time_to_ready)
14221426                     , (int) cycles_to_ready);
1423
1427                 
14241428                  cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-cycles_to_ready);
14251429                  timer_set(space->machine, attotime_zero, NULL, 0, /*speech_kludge_callback*/NULL);
14261430               }
1427
1431               
14281432               tms5220_data_w(devtag_get_device(space->machine, "tms5220"), offset, data);
14291433            }
14301434            break;
1431
1435           
14321436         case 7:
14331437            /* GPL write */
14341438            if (! (offset & 1))
14351439               ti99_grom_w8(space, offset, data);
14361440            break;
1437
1441           
14381442         default:
14391443            logerror("unmapped write offs=%d data=%d\n", (int) offset, (int) data);
14401444            break;
r7613r7614
15521556   if (handset_buflen == 1)
15531557   {
15541558      /* Unless I am missing something, the third and last nybble of the
1555        message is not acknowledged by the DSR in any way, and the first nybble
1556        of next message is not requested for either, so we need to decide on
1557        our own when we can post a new event.  Currently, we wait for 1000us
1558        after the DSR acknowledges the second nybble. */
1559      message is not acknowledged by the DSR in any way, and the first nybble
1560      of next message is not requested for either, so we need to decide on
1561      our own when we can post a new event.  Currently, we wait for 1000us
1562      after the DSR acknowledges the second nybble. */
15591563      timer_set(machine, ATTOTIME_IN_USEC(1000), NULL, 0, ti99_handset_ack_callback);
15601564   }
15611565
r7613r7614
16181622
16191623   /* read current key state */
16201624   key_buf = ( input_port_read(machine, keynames[num]) | (input_port_read(machine, keynames[num + 1]) << 16) ) >> (4*num);
1621
1625   
16221626   /* If a key was previously pressed, this key was not shift, and this key is
1623    still down, then don't change the current key press. */
1627   still down, then don't change the current key press. */
16241628   if (previous_key[num] && (previous_key[num] != 0x24)
1625         && (key_buf & (1 << (previous_key[num] & 0x1f))))
1629      && (key_buf & (1 << (previous_key[num] & 0x1f))))
16261630   {
16271631      /* check the shift modifier state */
16281632      if (((previous_key[num] & 0x20) != 0) == ((key_buf & 0x0008) != 0))
16291633         /* the shift modifier state has not changed */
1630         return FALSE;
1634      return FALSE;
16311635      else
16321636      {
16331637         /* the shift modifier state has changed: we need to update the
1634            keyboard state */
1638         keyboard state */
16351639         if (key_buf & 0x0008)
16361640         {   /* shift has been pressed down */
16371641            previous_key[num] = current_key = previous_key[num] | 0x20;
r7613r7614
16421646         }
16431647         /* post message */
16441648         ti99_handset_post_message(machine, (((unsigned) current_key) << 4) | (num << 1));
1645
1649         
16461650         return TRUE;
16471651      }
1648
1652     
16491653   }
1650
1654   
16511655   current_key = 0;   /* default value if no key is down */
16521656   for (i=0; i<20; i++)
16531657   {
r7613r7614
16591663
16601664         if (current_key != 0x24)
16611665            /* If this is the shift key, any other key we may find will
1662                have higher priority; otherwise, we may exit the loop and keep
1663                the key we have just found. */
1666            have higher priority; otherwise, we may exit the loop and keep
1667            the key we have just found. */
16641668            break;
16651669      }
16661670   }
1667
1671   
16681672   if (current_key != previous_key[num])
16691673   {
16701674      previous_key[num] = current_key;
r7613r7614
17171721
17181722      /* set sign */
17191723      /* note that we set the sign if the joystick position is 0 to work
1720        around a bug in the ti99/4 ROMs */
1724      around a bug in the ti99/4 ROMs */
17211725      if (current_joy_x <= 0)
17221726      {
17231727         message |= 0x040;
r7613r7614
17961800static void mecmouse_select(int selnow, int stick1, int stick2)
17971801{
17981802   /* The Mechatronic mouse is connected to the joystick port and occupies
1799       both joystick select lines and the switch lines. From these five
1800       lines, left/right/down are used for the motion (i.e. 3 motion steps
1801       for positive and four for negative motion and one for rest),
1802       the fire line is used for the secondary mouse button, and the up
1803       line is used for the primary button.
1804       The mouse motion is delivered by the same lines for both directions;
1805       this requires swapping the axes. According to the source code of
1806       the accompanying mouse driver, the readout of the current axis is
1807       done by selecting joystick 1, then joystick 2. The axis swapping is
1808       achieved by selecting stick 1 again. When selecting stick 2, the
1809       second axis is seen on the input lines.
1810       Interrupting this sequence will lead to swapped axes. This is
1811       prevented by resetting the toggle when the mouse is deselected
1812       (neither 1 nor 2 are selected).
1803   both joystick select lines and the switch lines. From these five
1804   lines, left/right/down are used for the motion (i.e. 3 motion steps
1805   for positive and four for negative motion and one for rest),
1806   the fire line is used for the secondary mouse button, and the up
1807   line is used for the primary button.
1808   The mouse motion is delivered by the same lines for both directions;
1809   this requires swapping the axes. According to the source code of
1810   the accompanying mouse driver, the readout of the current axis is
1811   done by selecting joystick 1, then joystick 2. The axis swapping is
1812   achieved by selecting stick 1 again. When selecting stick 2, the
1813   second axis is seen on the input lines.
1814   Interrupting this sequence will lead to swapped axes. This is
1815   prevented by resetting the toggle when the mouse is deselected
1816   (neither 1 nor 2 are selected).
1817   
1818   The joystick lines are selected as follows:
1819   TI-99/4:  Stick 1: P4=1, P3=0, P2=1 (5)
1820   Stick 2: P4=1, P3=1, P2=0 (6)
1821   
1822   TI-99/4A: Stick 1: P4=1, P3=1, P2=0 (6)
1823   Stick 2: P4=1, P3=1, P2=1 (7)
1824   
1825   TI-99/8:  Stick 1: P3=1, P2=1, P1=1, P0=0 (14)
1826   Stick 2: P3=1, P2=1, P1=1, P0=1 (15)
1827   
1828   Geneve: n/a, has own mouse handling via v9938
1829   
1830   As we can only deliver at max 3 steps positive and 4 steps negative,
1831   we split the delta so that subsequent queries add up to the actual
1832   delta. That is, one delta of +10 yields a 3+3+3+1.
1833   
1834   mecmouse_x holds the current delta to be counted down for x
1835   (y accordingly)
1836   
1837   mecmouse_x_buf is the current step count reported to CRU
1838   
1839   Michael Zapf, 2008-01-22
1840   */
18131841
1814       The joystick lines are selected as follows:
1815       TI-99/4:  Stick 1: P4=1, P3=0, P2=1 (5)
1816                 Stick 2: P4=1, P3=1, P2=0 (6)
1817
1818       TI-99/4A: Stick 1: P4=1, P3=1, P2=0 (6)
1819                 Stick 2: P4=1, P3=1, P2=1 (7)
1820
1821       TI-99/8:  Stick 1: P3=1, P2=1, P1=1, P0=0 (14)
1822                 Stick 2: P3=1, P2=1, P1=1, P0=1 (15)
1823
1824       Geneve: n/a, has own mouse handling via v9938
1825
1826       As we can only deliver at max 3 steps positive and 4 steps negative,
1827       we split the delta so that subsequent queries add up to the actual
1828       delta. That is, one delta of +10 yields a 3+3+3+1.
1829
1830       mecmouse_x holds the current delta to be counted down for x
1831       (y accordingly)
1832
1833       mecmouse_x_buf is the current step count reported to CRU
1834
1835       Michael Zapf, 2008-01-22
1836    */
1837
18381842   if (selnow==stick2) {
18391843      if (mecmouse_sel==stick1) {
18401844         if (! mecmouse_read_y)
r7613r7614
19972001   if (intreq)
19982002   {
19992003      /* On TI99, TMS9900 IC0-3 lines are not connected to TMS9901,
2000         * but hard-wired to force level 1 interrupts */
2004      * but hard-wired to force level 1 interrupts */
20012005      cputag_set_input_line_and_vector(device->machine, "maincpu", 0, ASSERT_LINE, 1);   /* interrupt it, baby */
20022006   }
20032007   else
r7613r7614
25462550}
25472551
25482552/* write CRU bit:
2549    bit0: enable/disable mapper registers in DSR space,
2550    bit1: enable/disable address mapping */
2553   bit0: enable/disable mapper registers in DSR space,
2554   bit1: enable/disable address mapping */
25512555static void sAMS_cru_w(running_machine *machine, int offset, int data)
25522556{
25532557   if (offset == 1)
r7613r7614
25702574static READ16_HANDLER ( ti99_sAMSxramlow_r )
25712575{
25722576   cpu_adjust_icount(devtag_get_device(space->machine, "maincpu"),-4);
2573//  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
2574
2577   //  cpu_spinuntil_time(space->machine->firstcpu, ATTOTIME_IN_USEC(6));
2578   
25752579   if (sAMS_mapper_on)
25762580      return xRAM_ptr[(offset&0x7ff)+sAMSlookup[(0x1000+offset)>>11]];
25772581   else
r7613r7614
26482652   /* Not required at run-time */
26492653#if 0
26502654   memory_install_read16_handler(space, 0x2000, 0x2fff, SMH_BANK(3));
2651    memory_install_write16_handler(space, 0x2000, 0x2fff, SMH_BANK(3));
2652    memory_install_read16_handler(space, 0x3000, 0x3fff, SMH_BANK(4));
2653    memory_install_write16_handler(space, 0x3000, 0x3fff, SMH_BANK(4));
2654    memory_install_read16_handler(space, 0xa000, 0xafff, SMH_BANK(5));
2655    memory_install_write16_handler(space, 0xa000, 0xafff, SMH_BANK(5));
2656    memory_install_read16_handler(space, 0xb000, 0xbfff, SMH_BANK(6));
2657    memory_install_write16_handler(space, 0xb000, 0xbfff, SMH_BANK(6));
2658    memory_install_read16_handler(space, 0xc000, 0xcfff, SMH_BANK(7));
2659    memory_install_write16_handler(space, 0xc000, 0xcfff, SMH_BANK(7));
2660    memory_install_read16_handler(space, 0xd000, 0xdfff, SMH_BANK(8));
2661    memory_install_write16_handler(space, 0xd000, 0xdfff, SMH_BANK(8));
2662    memory_install_read16_handler(space, 0xe000, 0xefff, SMH_BANK(9));
2663    memory_install_write16_handler(space, 0xe000, 0xefff, SMH_BANK(9));
2664    memory_install_read16_handler(space, 0xf000, 0xffff, SMH_BANK(10));
2665    memory_install_write16_handler(space, 0xf000, 0xffff, SMH_BANK(10));
2655   memory_install_write16_handler(space, 0x2000, 0x2fff, SMH_BANK(3));
2656   memory_install_read16_handler(space, 0x3000, 0x3fff, SMH_BANK(4));
2657   memory_install_write16_handler(space, 0x3000, 0x3fff, SMH_BANK(4));
2658   memory_install_read16_handler(space, 0xa000, 0xafff, SMH_BANK(5));
2659   memory_install_write16_handler(space, 0xa000, 0xafff, SMH_BANK(5));
2660   memory_install_read16_handler(space, 0xb000, 0xbfff, SMH_BANK(6));
2661   memory_install_write16_handler(space, 0xb000, 0xbfff, SMH_BANK(6));
2662   memory_install_read16_handler(space, 0xc000, 0xcfff, SMH_BANK(7));
2663   memory_install_write16_handler(space, 0xc000, 0xcfff, SMH_BANK(7));
2664   memory_install_read16_handler(space, 0xd000, 0xdfff, SMH_BANK(8));
2665   memory_install_write16_handler(space, 0xd000, 0xdfff, SMH_BANK(8));
2666   memory_install_read16_handler(space, 0xe000, 0xefff, SMH_BANK(9));
2667   memory_install_write16_handler(space, 0xe000, 0xefff, SMH_BANK(9));
2668   memory_install_read16_handler(space, 0xf000, 0xffff, SMH_BANK(10));
2669   memory_install_write16_handler(space, 0xf000, 0xffff, SMH_BANK(10));
26662670#endif
26672671
26682672   ti99_peb_set_16bit_card_handlers(0x1e00, & ti99_4p_mapper_handlers);
src/mess/machine/ti99_4x.h
r7613r7614
107107#endif
108108} fdc_kind_t;
109109
110/* GROM_port_t: descriptor for a port of 8 GROMs. Required by ti99_4x, ti99pcod */
111struct _GROM_port_t
112{
113        /* pointer to GROM data */
114        UINT8 *data_ptr;
115        /* current address pointer for the active GROM in port (16 bits) */
116        unsigned int addr;
117        /* GROM data buffer */
118        UINT8 buf;
119        /* internal flip-flops that are set after the first access to the GROM
120        address so that next access is mapped to the LSB, and cleared after each
121        data access */
122        char raddr_LSB, waddr_LSB;
123};
124typedef struct _GROM_port_t GROM_port_t;
125
126
110127/* defines for input port "CFG" */
111128enum
112129{
docs/messnew.txt
r7613r7614
1919- Scientific Atlanta PowerVu pv9234 STB
2020- Dream Multimedia Dreambox 7000/5620/500
2121
22
23
2224System Driver Changes:
2325----------------------
2426
r7613r7614
2830
2931- [TANDY2K] Implemented DMA mux register. [Curt Coder]
3032
33- [TI99] Cleanups.  [Michael Zapf]
34
3135- [VICTOR9K] Connected MC6852 device. [Curt Coder]
3236
3337

Previous 15994 Revisions Next


© 1998-2018 The MESS Team