Previous 15994 Revisions Next

r15584 Thursday 12th July, 2012 at 21:39:43 UTC by Michael Zapf
ti99: gromport redesigned, now offering three slot options "single" (default) / "multi" / "gkracker" determining the set of cartridge slots (cart or cart1/2/3/4). Cartridge insertion may be set to trigger RESET or not. TI consoles now have a dedicated RESET line, connected to the RESET input of the CPU and VDP. [Michael Zapf]
[src/mess/drivers]geneve.c ti99_4p.c ti99_4x.c ti99_8.c
[src/mess/machine/ti99]gromport.c gromport.h ti99defs.h videowrp.h

src/mess/machine/ti99/gromport.c
r15583r15584
1/**********************************************************************
1/***************************************************************************
2    GROM port - the cartridge port of the TI-99/4, TI-99/4A, and
3    TI-99/8 console.
24
3    Gromport: the cartridge port of the TI-99/4, TI-99/4A, and
4    TI-99/8 console. The name refers to the main intended application
5    scenario, that is, to host cartridges with GROMs. (The other port
6    of the console is called I/O port.)
5    The name refers to the main intended application scenario, that is,
6    to host cartridges with GROMs. The second, wider port of the console is
7    called I/O port and connects to the Peripheral Expansion System
8    (see peribox.h).
79
8    Over the years, many different kinds of cartridges appeared; the
9    usual cartridge layout contains GROMs and possibly a ROM circuit
10    for time-critical code (since the GROMs were utterly slow).
10          LEFT
1111
12    Texas Instruments kept control over all software development by
13    reserving GROMs and their programming to them and licensees.
12  RESET*  1||2   GND
13      D7  3||4   CRUCLK
14      D6  5||6   CRUIN
15      D5  7||8   A15/CRUOUT
16      D4  9||10  A13
17      D3 11||12  A12
18      D2 13||14  A11
19      D1 15||16  A10
20      D0 17||18  A9
21     +5V 19||20  A8
22     /GS 21||22  A7
23     A14 23||24  A3
24    DBIN 25||26  A6
25  GRMCLK 27||28  A5
26     -5V 29||30  A4
27   READY 31||32  /WE
28     GND 33||34  /ROMG
29     GND 35||36  GND
1430
15    Interestingly, the OS designers planned for an alternative -
16    cartridges which can be run with EPROMs only - which provided
17    a means for third-party authors to create cartridges without
18    TI license. The last action of TI before their retreat from the
19    home computer market was to disable this alternative.
31         RIGHT
2032
21    Nevertheless, the majority of consoles runs with different kinds of
22    cartridges; most recent developments by third party include
23    multi-bank cartridges with storage space up to 128 KiB.
33    Address bus line ordering, according to TI convention, is A0 (MSB) ... A15 (LSB).
34    A0, A1, and A2 are not delivered to the port but decoded in the console:
2435
25    The implementation as shown here goes beyond the simple port
26    by realizing a "multi-cartridge extender". This is a somewhat
27    mythical device which was never available for the normal
28    customer, but there are reports of the existance of such a device
29    in development labs or demonstrations.
36    /ROMG is asserted for A0/A1/A2 = 011 (addresses 6000 - 7fff)
37    /GS is asserted for A0...A5 = 100110 (addresses 9800 - 9bff)
3038
31    The interesting thing about this is that the OS of the console
32    fully supports this multi-cartridge extender, providing a selection
33    option on the screen to switch between different plugged-in
34    cartridges.
39    This means that a maximum of 8 KiB of direct memory space can be accessed.
40    The /GS line is used to enable GROM circuits on the board (serial ROMs with
41    own address counter, see grom.h).
3542
36    The switching is possible by decoding address lines that are reserved
37    for GROM access. GROMs are accessed via four separate addresses
38    9800, 9802, 9C00, 9C02. The addressing scheme looks like this:
43    When a cartridge is inserted the /RESET line is pulled to ground, which
44    via a R/C component pulls down the /RESET input of the timer circuit for
45    a short time, which in turn resets the CPU. In order to dump cartridges,
46    a common procedure was to tape the /RESET line of the cartridge. However,
47    inserting a cartridge without resetting often caused so much data bus noise
48    that the console usually locked up.
3949
40    1001 1Wxx xxxx xxM0        W = write(1), read(0), M = address(1), data(0)
50    ----------------
4151
42    This leaves 8 bits (256 options) which are not decoded inside the
43    console. As the complete address is routed to the port, some circuit
44    just needs to decode the xxx lines and turn on the respective slot.
52    The TI-99/4A computer was strictly designed for cartridge usage. The basic
53    console had only little directly accessible RAM and offered no ways to
54    write machine language programs; cartridges were intended to add various
55    capabilities, or just for running games.
4556
46    One catch must be considered: Some cartridges contain ROMs which are
47    directly accessed and not via ports. This means that the ROMs must
48    be activated according to the slot that is selected.
57    Beside the seemingly simple handling, Texas Instruments had own intentions
58    behind their cartridge strategy. With only 8 KiB of direct access memory, a
59    major part of the cartridge code had to be stored in GROMs, which had to be
60    licensed from Texas Instruments. Thus they kept firm control over all
61    software development.
4962
50    Another issue: Each GROM contains an own address counter and an ID.
51    According to the ID the GROM only delivers data if the address counter
52    is within the ID area (0 = 0000-1fff, 1=2000-3fff ... 7=e000-ffff).
53    Thus it is essential that all GROMs stay in sync with their address
54    counters. We have to route all address settings to all slots and their
55    GROMs, even when the slot has not been selected before. The selected
56    just shows its effect when data is read. In this case, only the
57    data from the selected slot will be delivered.
63    Over the years, and with the increasingly difficult market situations,
64    TI's policies seem to have changed. This may be the reason that the built-in
65    operating system actually allowed for running ROM-only cartridges until TI
66    clipped out this part in the OS, banning cartridges without GROMs. Consoles
67    with this modification were produced in 1983, TI's last year in the home
68    computer business.
5869
59    This may be considered as a design flaw within the complete cartridge system
60    which eventually led to TI not manufacturing that device for the broad
61    market.
70    Although only 8 KiB were available for direct addressing, clever techniques
71    were invented by third-party manufacturers. The first extension was utilized
72    by TI themselves in the Extended Basic cartridge which offers two banks
73    of ROM contents. Switching between the banks is achieved by writing a value
74    to the ROM space at 6000 or 6002. Later, cartridges with much more memory
75    space were created, up to the Super Space II cartridge with 128 KiB of
76    buffered SRAM.
6277
63    --------
78    ----------------
6479
65    This implementation also contains the GRAMKracker, a popular device
66    with persistent RAM and a cartridge slot. With it, cartridge contents
67    can be read, stored in its RAM, and modified. Moreover, the
68    console GROMs can be loaded into the device and overrun the data
69    delivered by the console GROMs. (Take care when changing something
70    in this emulation - this overrun is emulated by the sequence in which
71    the devices on the datamux are executed.)
80    From the console case layout the GROM port was intended for a single
81    cartridge only. Although never officially released, the operating system
82    of the TI console supported a multi-cartridge extender with software
83    switching. There were also extenders based on hardware switching (like
84    the Navarone Widget).
7285
73    --------
86    This emulation offers both variants as slot options:
7487
75    The second part of this file contains the implementation of the
76    cartridge image format (RPK).
88    -gromport single   : default single cartridge connector
89    -gromport multi    : software-switchable 4-slot cartridge extender
90    -gromport gkracker : GRAM Kracker
7791
78    Michael Zapf, 2012
92    The last option enables another popular device, the GRAM Kracker. This is
93    a device to be plugged into the cartridge slot with five manual switches
94    at the front and an own cartridge slot at its top. It contains buffered
95    SRAM, a built-in ROM, and a GROM simulator which simulates GROM behaviour
96    when accessing the buffered RAM. Its main use is to provide editable
97    storage for the read-only cartridge contents. Cartridges can be plugged
98    into its slot; their contents can be read and written to disk, modified as
99    needed, and loaded into the buffered RAM. Even the console GROMs can be
100    copied into the device; despite running in parallel, the GROM simulator
101    is able to override the console GROMs, thus allowing the user to install
102    a customized OS.
79103
80*********************************************************************/
104    (Emulation detail: Take care when changing something in this emulation -
105    this overrun is emulated by the sequence in which the devices on the datamux
106    are executed.)
81107
108    Michael Zapf, July 2012
109
110***************************************************************************/
82111#include "gromport.h"
83#include "ti99defs.h"
84112
85113#define VERBOSE 1
86114#define LOG logerror
87115
88116#define GROM_AREA 0x9800
89117#define GROM_MASK 0xf800
90#define AUTO -1
91118
92#define CARTGROM_TAG "grom_contents"
93#define CARTROM_TAG "rom_contents"
94#define CARTROM2_TAG "rom2_contents"
95
96119#define GROM3_TAG "grom3"
97120#define GROM4_TAG "grom4"
98121#define GROM5_TAG "grom5"
99122#define GROM6_TAG "grom6"
100123#define GROM7_TAG "grom7"
101124
102enum
125#define CARTGROM_TAG "grom_contents"
126#define CARTROM_TAG "rom_contents"
127#define CARTROM2_TAG "rom2_contents"
128#define GKRACKER_ROM_TAG "gkracker_rom"
129#define GKRACKER_NVRAM_TAG "gkracker_nvram"
130
131gromport_device::gromport_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
132   :   bus8z_device(mconfig, GROMPORT, "Cartridge port", tag, owner, clock),
133      device_slot_interface(mconfig, *this),
134      m_connector(NULL)
103135{
104   PCB_STANDARD=1,
105   PCB_PAGED,
106   PCB_MINIMEM,
107   PCB_SUPER,
108   PCB_MBX,
109   PCB_PAGED379I,
110   PCB_PAGEDCRU,
111   PCB_GKRACKER
112};
136}
113137
114#define GKSWITCH1_TAG "GKSWITCH1"
115#define GKSWITCH2_TAG "GKSWITCH2"
116#define GKSWITCH3_TAG "GKSWITCH3"
117#define GKSWITCH4_TAG "GKSWITCH4"
118#define GKSWITCH5_TAG "GKSWITCH5"
119
120/*******************************************
121    Cartridge PCB types
122*******************************************/
123
124cartridge_pcb_device::cartridge_pcb_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock)
125: bus8z_device(mconfig, type, name, tag, owner, clock)
138/* Only called for addresses 6000-7fff and GROM addresses (see datamux config) */
139READ8Z_MEMBER(gromport_device::readz)
126140{
127   if (VERBOSE>7) LOG("cartridge_pcb_device: common initialization\n");
128   for (int i=0; i < 5; i++) m_grom[i] = 0;
129   m_rom_ptr = 0;
130   m_rom2_ptr = 0;
131   m_ram_ptr = 0;
132   m_grom_size = 0;
133   m_rom_size = 0;
134   m_ram_size = 0;
141   if (m_connector != NULL)
142      m_connector->readz(space, offset, value);
135143}
136144
137void cartridge_pcb_device::device_start(void)
145WRITE8_MEMBER(gromport_device::write)
138146{
147   if (m_connector != NULL)
148      m_connector->write(space, offset, data);
139149}
140150
141cartridge_pcb_standard_device::cartridge_pcb_standard_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
142: cartridge_pcb_device(mconfig, TICARTPCBSTD, "Standard cartridge PCB", tag, owner, clock)
151void gromport_device::crureadz(offs_t offset, UINT8 *value)
143152{
153   if (m_connector != NULL)
154      m_connector->crureadz(offset, value);
144155}
145156
146cartridge_pcb_paged_device::cartridge_pcb_paged_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
147: cartridge_pcb_device(mconfig, TICARTPCBPAG, "Paged cartridge PCB", tag, owner, clock)
157void gromport_device::cruwrite(offs_t offset, UINT8 data)
148158{
159   if (m_connector != NULL)
160      m_connector->cruwrite(offset, data);
149161}
150162
151cartridge_pcb_minimem_device::cartridge_pcb_minimem_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
152: cartridge_pcb_device(mconfig, TICARTPCBMIN, "MiniMemory cartridge PCB", tag, owner, clock)
163WRITE_LINE_MEMBER(gromport_device::ready_line)
153164{
165   m_console_ready(state);
154166}
155167
156cartridge_pcb_superspace_device::cartridge_pcb_superspace_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
157: cartridge_pcb_device(mconfig, TICARTPCBSUP, "SuperSpace II cartridge PCB", tag, owner, clock)
168void gromport_device::device_start()
158169{
159170}
160171
161cartridge_pcb_mbx_device::cartridge_pcb_mbx_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
162: cartridge_pcb_device(mconfig, TICARTPCBMBX, "MBX cartridge PCB", tag, owner, clock)
172void gromport_device::device_reset()
163173{
174   m_reset_on_insert = (ioport("CARTRESET")->read()==0x01);
164175}
165176
166cartridge_pcb_paged379i_device::cartridge_pcb_paged379i_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
167: cartridge_pcb_device(mconfig, TICARTPCBPGI, "Paged379i cartridge PCB", tag, owner, clock)
177/*
178    Shall we reset the console when a cartridge has been inserted?
179    This is triggered by the cartridge by pulling down /RESET via a capacitor.
180    Accordingly, when we put a tape over the /RESET contact we can avoid the
181    reset, which is useful when we want to swap the cartridges while a program
182    is runnning.
183*/
184void gromport_device::cartridge_inserted()
168185{
169   m_rom_page = get_paged379i_bank(15);
186   if (m_reset_on_insert)
187   {
188      m_console_reset(ASSERT_LINE);
189      m_console_reset(CLEAR_LINE);
190   }
170191}
171192
172cartridge_pcb_pagedcru_device::cartridge_pcb_pagedcru_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
173: cartridge_pcb_device(mconfig, TICARTPCBPGC, "PagedCRU cartridge PCB", tag, owner, clock)
193
194void gromport_device::device_config_complete()
174195{
196   const gromport_config *intf = reinterpret_cast<const gromport_config *>(static_config());
197   m_console_ready.resolve(intf->ready, *this);
198   m_console_reset.resolve(intf->reset, *this);
199   m_connector = static_cast<ti99_cartridge_connector_device*>(first_subdevice());
175200}
176201
177cartridge_pcb_gramkracker_device::cartridge_pcb_gramkracker_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
178: cartridge_pcb_device(mconfig, TICARTPCBGRK, "GRAM Kracker cartridge PCB", tag, owner, clock)
202SLOT_INTERFACE_START( gromport )
203   SLOT_INTERFACE("single", GROMPORT_SINGLE)
204   SLOT_INTERFACE("multi", GROMPORT_MULTI)
205   SLOT_INTERFACE("gkracker", GROMPORT_GK)
206SLOT_INTERFACE_END
207
208
209INPUT_PORTS_START(gromport)
210   PORT_START( "CARTRESET" )
211   PORT_CONFNAME( 0x01, 0x01, "RESET on cartridge insert" )
212      PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
213      PORT_CONFSETTING(    0x01, DEF_STR( On ) )
214INPUT_PORTS_END
215
216ioport_constructor gromport_device::device_input_ports() const
179217{
180   m_grom_address = 0;   // for the GROM emulation
181   for (int i=1; i < 6; i++) m_gk_switch[i] = 0;
218   return INPUT_PORTS_NAME(gromport);
182219}
183220
184/*****************************************************************************
185    Common methods.
186******************************************************************************/
221const device_type GROMPORT = &device_creator<gromport_device>;
187222
188/* Read function for this cartridge, CRU. */
189void cartridge_pcb_device::crureadz(offs_t offset, UINT8 *value) {  };
223/***************************************************************************
224    Different versions of cartridge connections
190225
191/* Write function for this cartridge, CRU. */
192void cartridge_pcb_device::cruwrite(offs_t offset, UINT8 value) {  };
226    single: the standard console connector, one cartridge
227    multi:  a multi-cart expander, up to 4 cartridges with software selection
228    gkracker: GRAMKracker, a device with NVRAM which allows the user to copy
229              the contents of the cartridge plugged into its slot into the NVRAM
230              and to modify it.
193231
194READ8Z_MEMBER( cartridge_pcb_device::gromreadz )
232***************************************************************************/
233
234const device_type GROMPORT_SINGLE = &device_creator<single_conn_device>;
235const device_type GROMPORT_MULTI = &device_creator<multi_conn_device>;
236const device_type GROMPORT_GK = &device_creator<gkracker_device>;
237
238ti99_cartridge_connector_device::ti99_cartridge_connector_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock)
239: bus8z_device(mconfig, type, name, tag, owner, clock)
195240{
196   for (int i=0; i < 5; i++)
197   {
198      if (m_grom[i] != NULL)
199      {
200         m_grom[i]->readz(space, offset, value, mem_mask);
201      }
202   }
203241}
204242
205WRITE8_MEMBER( cartridge_pcb_device::gromwrite )
243void ti99_cartridge_connector_device::ready_line(int state)
206244{
207   for (int i=0; i < 5; i++)
208   {
209      if (m_grom[i] != NULL)
210      {
211         m_grom[i]->write(space, offset, data, mem_mask);
212      }
213   }
245   m_gromport->ready_line(state);
214246}
215247
216/*****************************************************************************
217  Cartridge type: Standard
218    Most cartridges are built in this type. Every cartridge may contain
219    GROM between 0 and 40 KiB, and ROM with 8 KiB length, no banking.
220******************************************************************************/
248single_conn_device::single_conn_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
249: ti99_cartridge_connector_device(mconfig, GROMPORT_SINGLE, "Standard cartridge connector", tag, owner, clock)
250{
251   m_shortname = "single";
252}
221253
222/* Read function for the standard cartridge. */
223READ8Z_MEMBER(cartridge_pcb_standard_device::readz)
254READ8Z_MEMBER(single_conn_device::readz)
224255{
225   if ((offset & GROM_MASK)==GROM_AREA)
226      gromreadz(space, offset, value, mem_mask);
227   else
228   {
229      if (m_rom_ptr!=NULL)
230      {
231         // For TI-99/8 we should plan for 16K cartridges. However, none was ever produced.
232         // Well, forget about that.
233         *value = m_rom_ptr[offset & 0x1fff];
234         //      LOG("read cartridge rom space %04x = %02x\n", offset, *value);
235      }
236   }
256   // Pass through
257   m_cartridge->readz(space, offset, value);
237258}
238259
239/* Write function for the standard cartridge. */
240WRITE8_MEMBER(cartridge_pcb_standard_device::write)
260WRITE8_MEMBER(single_conn_device::write)
241261{
242   // LOG("write standard\n");
243   if ((offset & GROM_MASK)==GROM_AREA)
244      gromwrite(space, offset, data, mem_mask);
245   else
246   {
247      if (VERBOSE>5) LOG("cartridge_pcb_device: Cannot write to ROM space at %04x\n", offset);
248   }
262   // Pass through
263   m_cartridge->write(space, offset, data);
249264}
250265
251/*****************************************************************************
252  Cartridge type: Paged (Extended Basic)
253    This cartridge consists of GROM memory and 2 pages of standard ROM.
254    The page is set by writing any value to a location in
255    the address area, where an even word offset sets the page to 0 and an
256    odd word offset sets the page to 1 (e.g. 6000 = bank 0, and
257    6002 = bank 1).
258******************************************************************************/
266void single_conn_device::crureadz(offs_t offset, UINT8 *value)
267{
268   // Pass through
269   m_cartridge->crureadz(offset, value);
270}
259271
260/* Read function for the paged cartridge. */
261READ8Z_MEMBER(cartridge_pcb_paged_device::readz)
272void single_conn_device::cruwrite(offs_t offset, UINT8 data)
262273{
263   if ((offset & GROM_MASK)==GROM_AREA)
264      gromreadz(space, offset, value, mem_mask);
265   else
266   {
267      if (m_rom_page==0)
268      {
269         *value = m_rom_ptr[offset & 0x1fff];
270      }
271      else
272      {
273         *value = m_rom2_ptr[offset & 0x1fff];
274      }
275   }
274   // Pass through
275   m_cartridge->cruwrite(offset, data);
276276}
277277
278/* Write function for the paged cartridge. */
279WRITE8_MEMBER(cartridge_pcb_paged_device::write)
278void single_conn_device::device_reset()
280279{
281   // LOG("write standard\n");
282   if ((offset & GROM_MASK)==GROM_AREA)
283      gromwrite(space, offset, data, mem_mask);
280   m_cartridge->set_slot(0);
281}
284282
285   else
286      m_rom_page = (offset >> 1) & 1;
283static MACHINE_CONFIG_FRAGMENT( single_slot )
284   MCFG_DEVICE_ADD("cartridge", TI99CART, 0)
285MACHINE_CONFIG_END
286
287machine_config_constructor single_conn_device::device_mconfig_additions() const
288{
289   return MACHINE_CONFIG_NAME( single_slot );
287290}
288291
292void single_conn_device::device_config_complete()
293{
294   m_cartridge = static_cast<ti99_cartridge_device*>(first_subdevice());
295   m_gromport = static_cast<gromport_device*>(owner());
296}
289297
290/*****************************************************************************
291  Cartridge type: Mini Memory
292    GROM: 6 KiB (occupies G>6000 to G>7800)
293    ROM: 4 KiB (romfile is actually 8 K long, second half with zeros, 0x6000-0x6fff)
294    persistent RAM: 4 KiB (0x7000-0x7fff)
295******************************************************************************/
298/********************************************************/
296299
297/* Read function for the minimem cartridge. */
298READ8Z_MEMBER(cartridge_pcb_minimem_device::readz)
300/*
301    The multi-cartridge extender
302
303    This is a somewhat mythical device which was never available for the normal
304    customer, but there are reports of the existance of such a device
305    in development labs or demonstrations.
306
307    The interesting thing about this is that the OS of the console
308    fully supports this multi-cartridge extender, providing a selection
309    option on the screen to switch between different plugged-in
310    cartridges.
311
312    The switching is possible by decoding address lines that are reserved
313    for GROM access. GROMs are accessed via four separate addresses
314    9800, 9802, 9C00, 9C02. The addressing scheme looks like this:
315
316    1001 1Wxx xxxx xxM0        W = write(1), read(0), M = address(1), data(0)
317
318    This leaves 8 bits (256 options) which are not decoded inside the
319    console. As the complete address is routed to the port, some circuit
320    just needs to decode the xxx lines and turn on the respective slot.
321
322    One catch must be considered: Some cartridges contain ROMs which are
323    directly accessed and not via ports. This means that the ROMs must
324    be activated according to the slot that is selected.
325
326    Another issue: Each GROM contains an own address counter and an ID.
327    According to the ID the GROM only delivers data if the address counter
328    is within the ID area (0 = 0000-1fff, 1=2000-3fff ... 7=e000-ffff).
329    Thus it is essential that all GROMs stay in sync with their address
330    counters. We have to route all address settings to all slots and their
331    GROMs, even when the slot has not been selected before. The selected
332    just shows its effect when data is read. In this case, only the
333    data from the selected slot will be delivered.
334
335    This may be considered as a design flaw within the complete cartridge system
336    which eventually led to TI not manufacturing that device for the broad
337    market.
338*/
339
340#define AUTO -1
341
342multi_conn_device::multi_conn_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
343   : ti99_cartridge_connector_device(mconfig, GROMPORT_MULTI, "Multi-cartridge extender", tag, owner, clock)
299344{
300   if ((offset & GROM_MASK)==GROM_AREA)
301      gromreadz(space, offset, value, mem_mask);
345   m_shortname = "multi";
346}
302347
348/*
349    Activates a slot in the multi-cartridge extender.
350    Setting the slot is done by accessing the GROM ports using a
351    specific address:
352
353    slot 0:  0x9800 (0x9802, 0x9c00, 0x9c02)   : cartridge1
354    slot 1:  0x9804 (0x9806, 0x9c04, 0x9c06)   : cartridge2
355    ...
356    slot 15: 0x983c (0x983e, 0x9c3c, 0x9c3e)   : cartridge16
357
358    Scheme:
359
360    1001 1Wxx xxxx xxM0 (M=mode; M=0: data, M=1: address; W=write)
361
362    The following addresses are theoretically available, but the
363    built-in OS does not use them; i.e. cartridges will not be
364    included in the selection list, and their features will not be
365    found by lookup, but they could be accessed directly by user
366    programs.
367    slot 16: 0x9840 (0x9842, 0x9c40, 0x9c42)
368    ...
369    slot 255:  0x9bfc (0x9bfe, 0x9ffc, 0x9ffe)
370
371    Setting the GROM base should select one cartridge, but the ROMs in the
372    CPU space must also be switched. As there is no known special mechanism
373    we assume that by switching the GROM base, the ROM is automatically
374    switched.
375
376    Caution: This means that cartridges which do not have at least one
377    GROM cannot be switched with this mechanism.
378
379    We assume that the slot number is already calculated in the caller:
380    slotnumber>=0 && slotnumber<=255
381
382    NOTE: The OS will stop searching when it finds slots 1 and 2 empty.
383    Interestingly, cartridge subroutines are found nevertheless, even when
384    the cartridge is plugged into a higher slot.
385*/
386void multi_conn_device::set_slot(int slotnumber)
387{
388   if (VERBOSE>7)
389      if (m_active_slot != slotnumber) LOG("multi_conn_device: Setting cartslot to %d\n", slotnumber);
390
391   if (m_fixed_slot==AUTO)
392      m_active_slot = slotnumber;
303393   else
304   {
305      if ((offset & 0x1000)==0x0000)
306      {
307         *value = m_rom_ptr[offset & 0x0fff];
308      }
309      else
310      {
311         *value = m_ram_ptr[offset & 0x0fff];
312      }
313   }
394      m_active_slot = m_fixed_slot;
314395}
315396
316/* Write function for the minimem cartridge. */
317WRITE8_MEMBER(cartridge_pcb_minimem_device::write)
397int multi_conn_device::get_active_slot(bool changebase, offs_t offset)
318398{
319   // LOG("write standard\n");
320   if ((offset & GROM_MASK)==GROM_AREA)
321      gromwrite(space, offset, data, mem_mask);
322
323   else
399   int slot;
400   if (changebase)
324401   {
325      if ((offset & 0x1000)==0x0000)
402      if ((offset & GROM_MASK) == GROM_AREA)
326403      {
327         if (VERBOSE>1) LOG("ti99: gromport: Write access to cartridge ROM at address %04x ignored", offset);
404         set_slot((offset>>2) & 0x00ff);
328405      }
329      else
330      {
331         m_ram_ptr[offset & 0x0fff] = data;
332      }
333406   }
407   slot = m_active_slot;
408   return slot;
334409}
335410
336/*****************************************************************************
337  Cartridge type: SuperSpace II
338    SuperSpace cartridge type. SuperSpace is intended as a user-definable
339    blank cartridge containing buffered RAM
340    It has an Editor/Assembler GROM which helps the user to load
341    the user program into the cartridge. If the user program has a suitable
342    header, the console recognizes the cartridge as runnable, and
343    assigns a number in the selection screen.
344    Switching the RAM banks in this cartridge is achieved by setting
345    CRU bits (the system serial interface).
411void multi_conn_device::insert(int index, ti99_cartridge_device* cart)
412{
413   if (VERBOSE>3) LOG("multi_conn_device: insert slot %d\n", index);
414   m_cartridge[index] = cart;
415   m_gromport->cartridge_inserted();
416}
346417
347    GROM: Editor/Assembler GROM
348    ROM: none
349    persistent RAM: 32 KiB (0x6000-0x7fff, 4 banks)
350    Switching the bank is done via CRU write
351******************************************************************************/
418void multi_conn_device::remove(int index)
419{
420   if (VERBOSE>3) LOG("multi_conn_device: remove slot %d\n", index);
421   m_cartridge[index] = NULL;
422}
352423
353/* Read function for the super cartridge. */
354READ8Z_MEMBER(cartridge_pcb_superspace_device::readz)
424READ8Z_MEMBER(multi_conn_device::readz)
355425{
356   if ((offset & GROM_MASK)==GROM_AREA)
357      gromreadz(space, offset, value, mem_mask);
358   else
426   int slot = get_active_slot(true, offset);
427
428   // If we have a GROM access, we need to send the read request to all
429   // attached cartridges so the slot is irrelevant here. Each GROM
430   // contains an internal address counter, and we must make sure they all stay in sync.
431   if ((offset & GROM_MASK) == GROM_AREA)
359432   {
360      if (m_ram_ptr==NULL)
433      for (int i=0; i < NUMBER_OF_CARTRIDGE_SLOTS; i++)
361434      {
362         *value = 0;
435         if (m_cartridge[i] != NULL)
436         {
437            UINT8 newval = *value;
438            m_cartridge[i]->readz(space, offset, &newval, mem_mask);
439            if (i==slot)
440            {
441               *value = newval;
442            }
443         }
363444      }
364      else
445   }
446   else
447   {
448      if (slot < NUMBER_OF_CARTRIDGE_SLOTS && m_cartridge[slot] != NULL)
365449      {
366         offs_t boffset = (m_ram_page << 13) | (offset & 0x1fff);
367         *value = m_ram_ptr[boffset];
450         m_cartridge[slot]->readz(space, offset, value, mem_mask);
368451      }
369452   }
370453}
371454
372/* Write function for the super cartridge. */
373WRITE8_MEMBER(cartridge_pcb_superspace_device::write)
455WRITE8_MEMBER(multi_conn_device::write)
374456{
375   if ((offset & GROM_MASK)==GROM_AREA)
376      gromwrite(space, offset, data, mem_mask);
377   else
457   int slot = get_active_slot(true, offset);
458
459   // Same issue as above (read)
460   // We don't have GRAM cartridges, anyway, so it's just used for setting the address.
461   if ((offset & GROM_MASK) == GROM_AREA)
378462   {
379      if ((offset & 0x1000)==0x0000)
463      for (int i=0; i < NUMBER_OF_CARTRIDGE_SLOTS; i++)
380464      {
381         if (VERBOSE>1) LOG("ti99: gromport: Write access to cartridge ROM at address %04x ignored", offset);
465         if (m_cartridge[i] != NULL)
466         {
467            m_cartridge[i]->write(space, offset, data, mem_mask);
468         }
382469      }
383      else
470   }
471   else
472   {
473      if (slot < NUMBER_OF_CARTRIDGE_SLOTS && m_cartridge[slot] != NULL)
384474      {
385         offs_t boffset = (m_ram_page << 13) | (offset & 0x1fff);
386         m_ram_ptr[boffset] = data;
475         //      LOG("try it on slot %d\n", slot);
476         m_cartridge[slot]->write(space, offset, data, mem_mask);
387477      }
388478   }
389479}
390480
391void cartridge_pcb_superspace_device::crureadz(offs_t offset, UINT8 *value)
481void multi_conn_device::crureadz(offs_t offset, UINT8 *value)
392482{
393   // offset is the bit number. The CRU base address is already divided  by 2.
483   int slot = get_active_slot(false, offset);
484   /* Sanity check. Higher slots are always empty. */
485   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
486      return;
394487
395   // ram_page contains the bank number. We have a maximum of
396   // 4 banks; the Super Space II manual says:
397   //
398   // Banks are selected by writing a bit pattern to CRU address >0800:
399   //
400   // Bank #   Value
401   // 0        >02  = 0000 0010
402   // 1        >08  = 0000 1000
403   // 2        >20  = 0010 0000
404   // 3        >80  = 1000 0000
405   //
406   // With the bank number (0, 1, 2, or 3) in R0:
407   //
408   // BNKSW   LI    R12,>0800   Set CRU address
409   //         LI    R1,2        Load Shift Bit
410   //         SLA   R0,1        Align Bank Number
411   //         JEQ   BNKS1       Skip shift if Bank 0
412   //         SLA   R1,0        Align Shift Bit
413   // BNKS1   LDCR  R1,0        Switch Banks
414   //         SRL   R0,1        Restore Bank Number (optional)
415   //         RT
488   if (m_cartridge[slot] != NULL)
489   {
490      m_cartridge[slot]->crureadz(offset, value);
491   }
492}
416493
417   // Our implementation in MESS always gets 8 bits in one go. Also, the address
418   // is twice the bit number. That is, the offset value is always a multiple
419   // of 0x10.
494void multi_conn_device::cruwrite(offs_t offset, UINT8 data)
495{
496   int slot = get_active_slot(true, offset);
420497
421   if (VERBOSE>2) LOG("ti99: gromport: Superspace: CRU accessed at %04x\n", offset);
422   if ((offset & 0xfff0) != 0x0800)
423      *value = 0;
498   /* Sanity check. Higher slots are always empty. */
499   if (slot >= NUMBER_OF_CARTRIDGE_SLOTS)
500      return;
424501
425   // CRU addresses are only 1 bit wide. Bytes are transferred from LSB
426   // to MSB. That is, 8 bit are eight consecutive addresses. */
427   *value = (m_ram_page == (offset-1)/2);
502   if (m_cartridge[slot] != NULL)
503   {
504      m_cartridge[slot]->cruwrite(offset, data);
505   }
428506}
429507
430void cartridge_pcb_superspace_device::cruwrite(offs_t offset, UINT8 data)
508void multi_conn_device::device_start()
431509{
432   // data is bit
433   // offset is address
434   if (VERBOSE>2) LOG("ti99: gromport: Superspace: CRU accessed at %04x\n", offset);
435
436   if (offset < 16)
510   m_next_free_slot = 0;
511   m_active_slot = 0;
512   for (int i=0; i < NUMBER_OF_CARTRIDGE_SLOTS; i++)
437513   {
438      if (data != 0)
439         m_ram_page = (offset-2)/4;
514      m_cartridge[i] = NULL;
440515   }
516   m_gromport = static_cast<gromport_device*>(owner());
441517}
442518
443/*****************************************************************************
444  Cartridge type: MBX
445    GROM: up to 40 KiB
446    ROM: up to 16 KiB (in up to 2 banks of 8KiB each)
447    RAM: 1022 B (0x6c00-0x6ffd, overrides ROM in that area)
448    ROM mapper: 6ffe
519void multi_conn_device::device_reset(void)
520{
521   m_active_slot = 0;
522   m_fixed_slot = ioport("CARTSLOT")->read() - 1;
523}
449524
450    Note that some MBX cartridges assume the presence of the MBX system
451    (additional console) and will not run without it. The MBX hardware is
452    not emulated yet.
453******************************************************************************/
525static MACHINE_CONFIG_FRAGMENT( multi_slot )
526   MCFG_DEVICE_ADD("cartridge1", TI99CART, 0)
527   MCFG_DEVICE_ADD("cartridge2", TI99CART, 0)
528   MCFG_DEVICE_ADD("cartridge3", TI99CART, 0)
529   MCFG_DEVICE_ADD("cartridge4", TI99CART, 0)
530MACHINE_CONFIG_END
454531
455/* Read function for the mbx cartridge. */
456READ8Z_MEMBER(cartridge_pcb_mbx_device::readz)
532machine_config_constructor multi_conn_device::device_mconfig_additions() const
457533{
458   if ((offset & GROM_MASK)==GROM_AREA)
459      gromreadz(space, offset, value, mem_mask);
460   else
461   {
462      if ((offset & 0x1c00)==0x0c00)
463      {
464         // This is the RAM area which overrides any ROM. There is no
465         // known banking behavior for the RAM, so we must assume that
466         // there is only one bank.
467         if (m_ram_ptr != NULL)
468            *value = m_ram_ptr[offset & 0x03ff];
469      }
470      else
471      {
472         if (m_rom_ptr!=NULL)
473            *value = m_rom_ptr[(offset & 0x1fff) | (m_rom_page<<13)];
474      }
475   }
534   return MACHINE_CONFIG_NAME( multi_slot );
476535}
477536
478/* Write function for the mbx cartridge. */
479WRITE8_MEMBER(cartridge_pcb_mbx_device::write)
537INPUT_PORTS_START(multi_slot)
538   PORT_START( "CARTSLOT" )
539   PORT_DIPNAME( 0x0f, 0x00, "Multi-cartridge slot" )
540      PORT_DIPSETTING(    0x00, "Auto" )
541      PORT_DIPSETTING(    0x01, "Slot 1" )
542      PORT_DIPSETTING(    0x02, "Slot 2" )
543      PORT_DIPSETTING(    0x03, "Slot 3" )
544      PORT_DIPSETTING(    0x04, "Slot 4" )
545INPUT_PORTS_END
546
547ioport_constructor multi_conn_device::device_input_ports() const
480548{
481   if ((offset & GROM_MASK)==GROM_AREA)
482      gromwrite(space, offset, data, mem_mask);
483   else
484   {
485      if (offset == 0x6ffe)
486      {
487         m_rom_page = data & 1;
488         return;
489      }
490
491      if ((offset & 0x1c00)==0x0c00)
492      {
493         if (m_ram_ptr == NULL) return;
494         m_ram_ptr[offset & 0x03ff] = data;
495      }
496   }
549   return INPUT_PORTS_NAME(multi_slot);
497550}
498551
499/*****************************************************************************
500  Cartridge type: paged379i
501    This cartridge consists of one 16 KiB, 32 KiB, 64 KiB, or 128 KiB EEPROM
502    which is organised in 2, 4, 8, or 16 pages of 8 KiB each. The complete
503    memory contents must be stored in one dump file.
504    The pages are selected by writing a value to some memory locations. Due to
505    using the inverted outputs of the LS379 latch, setting the inputs of the
506    latch to all 0 selects the highest bank, while setting to all 1 selects the
507    lowest. There are some cartridges (16 KiB) which are using this scheme, and
508    there are new hardware developments mainly relying on this scheme.
552/**************************************************************************
509553
510    Writing to       selects page (16K/32K/64K/128K)
511    >6000            1 / 3 / 7 / 15
512    >6002            0 / 2 / 6 / 14
513    >6004            1 / 1 / 5 / 13
514    >6006            0 / 0 / 4 / 12
515    >6008            1 / 3 / 3 / 11
516    >600A            0 / 2 / 2 / 10
517    >600C            1 / 1 / 1 / 9
518    >600E            0 / 0 / 0 / 8
519    >6010            1 / 3 / 7 / 7
520    >6012            0 / 2 / 6 / 6
521    >6014            1 / 1 / 5 / 5
522    >6016            0 / 0 / 4 / 4
523    >6018            1 / 3 / 3 / 3
524    >601A            0 / 2 / 2 / 2
525    >601C            1 / 1 / 1 / 1
526    >601E            0 / 0 / 0 / 0
554    The GRAM Kracker was manufactured by Miller's Graphics and designed to
555    fit into the cartridge slot.
527556
528    The paged379i cartrige does not have any GROMs.
529******************************************************************************/
557    It offers one own cartridge slot at the top side and a row of switches
558    at its front. It contains buffered SRAM circuits; the base version has
559    56 KiB, and the extended version has 80 KiB.
530560
531/*
532    Determines which bank to set, depending on the size of the ROM. This is
533    some magic code that actually represents different PCB versions.
534*/
535int cartridge_pcb_paged379i_device::get_paged379i_bank(int rompage)
536{
537   int mask = 0;
538   if (m_rom_size > 16384)
539   {
540      if (m_rom_size > 32768)
541      {
542         if (m_rom_size > 65536)
543            mask = 15;
544         else
545            mask = 7;
546      }
547      else
548         mask = 3;
549   }
550   else
551      mask = 1;
561    The operation of the GRAM Kracker is a bit complex and most likely
562    bound to fail when you have no manual. Accordingly, this emulation is
563    neither simpler nor more difficult to use.
552564
553   return rompage & mask;
554}
565    Concept of operation:
555566
567    Loader: The GRAM Kracker contains a small loader utility
568    which allows you to dump cartridges and to load the contents into the
569    SRAM of the GK. This loader utility is active when the switch 5 is put
570    into "Loader on" state. The activated loader hides the TI BASIC
571    interpreter in the console.
556572
557/* Read function for the paged379i cartridge. */
558READ8Z_MEMBER(cartridge_pcb_paged379i_device::readz)
559{
560   if ((offset & 0xe000)==0x6000)
561      *value = m_rom_ptr[(m_rom_page<<13) | (offset & 0x1fff)];
562}
573    Cartridges: When a cartridge is plugged into the GK the contents may be
574    dumped and saved to disk by the loader. They cannot be directly copied
575    into the GK because the memory locations are hidden by the cartridge.
563576
564/* Write function for the paged379i cartridge. Only used to set the bank. */
565WRITE8_MEMBER(cartridge_pcb_paged379i_device::write)
566{
567   // Bits: 0110 0000 000b bbbx
568   // x = don't care, bbbb = bank
569   if ((offset & 0xffe0)==0x6000)
570   {
571      // Set bank
572      m_rom_page = get_paged379i_bank(15 - ((offset>>1) & 15));
573   }
574}
577    Loading the cartridge into the SRAM: With the cartridge unplugged, dumps
578    can be loaded into the SRAM using the loader. This is one major use case
579    of the GK, that is, to load dumps from disk, and in particular modified
580    dumps. (There is no checksum, so contents may be freely changed.)
575581
576/*****************************************************************************
577  Cartridge type: pagedcru
578    This cartridge consists of one 16 KiB, 32 KiB, or 64 KiB EEPROM which is
579    organised in 2, 4, or 8 pages of 8 KiB each. We assume there is only one
580    dump file of the respective size.
581    The pages are selected by writing a value to the CRU. This scheme is
582    similar to the one used for the SuperSpace cartridge, with the exception
583    that we are using ROM only, and we can have up to 8 pages.
582    Console dump: The GK is also able to dump the console GROMs and also to
583    load them into the SRAM (only in the extended version). Due to a
584    peculiarity of the TI console design it is possible to override the
585    console GROMs with the contents in the cartridge slot.
584586
585    Bank     Value written to CRU>0800
586    0      >0002  = 0000 0000 0000 0010
587    1      >0008  = 0000 0000 0000 1000
588    2      >0020  = 0000 0000 0010 0000
589    3      >0080  = 0000 0000 1000 0000
590    4      >0200  = 0000 0010 0000 0000
591    5      >0800  = 0000 1000 0000 0000
592    6      >2000  = 0010 0000 0000 0000
593    7      >8000  = 1000 0000 0000 0000
587    A standard procedure for use with the GK:
594588
595    No GROMs used in this type.
596******************************************************************************/
589    Save cartridge:
597590
598/* Read function for the pagedcru cartridge. */
599READ8Z_MEMBER(cartridge_pcb_pagedcru_device::readz)
600{
601   if ((offset & 0xe000)==0x6000)
602      *value = m_rom_ptr[(m_rom_page<<13) | (offset & 0x1fff)];
603}
591    - Put switches to [Normal | OpSys | TI BASIC | W/P | Loader On]
592    - Insert a disk image into disk drive 1
593    - Plug in a cartridge
594    - Reset the console (done automatically here)
595    - Visit the option screen, press 1 for GRAM KRACKER
596    - In the GK loader, select 2 for Save Module
597    - Follow the on-screen instructions. Switches are set via the dip switch menu.
598    - Enter a target file name
599    - Saving is complete when the Save operation has been unmarked.
604600
605/* Write function for the pagedcru cartridge. No effect. */
606WRITE8_MEMBER(cartridge_pcb_pagedcru_device::write)
607{
608   return;
609}
601    Load cartridge:
610602
611void cartridge_pcb_pagedcru_device::crureadz(offs_t offset, UINT8 *value)
612{
613   int page = m_rom_page;
614   if ((offset & 0xf800)==0x0800)
615   {
616      int bit = (offset & 0x001e)>>1;
617      if (bit != 0)
618      {
619         page = page-(bit/2);  // 4 page flags per 8 bits
620      }
621      *value = 1 << (page*2+1);
622   }
623}
603    - Put switches to [Normal | OpSys | TI BASIC | W/P | Loader On]
604    - Insert a disk image into disk drive 1
605    - Make sure no cartridge is plugged in
606    - Press 1 for GRAM KRACKER
607    - Press 3 for Init Module space; follow instructions
608    - Press 1 for Load Module; specify file name on disk
609    - Loading is complete when the Load operation has been unmarked.
624610
625void cartridge_pcb_pagedcru_device::cruwrite(offs_t offset, UINT8 data)
626{
627   if ((offset & 0xf800)==0x0800)
628   {
629      int bit = (offset & 0x001e)>>1;
630      if (data != 0 && bit > 0)
631      {
632         m_rom_page = (bit-1)/2;
633      }
634   }
635}
611    Memory organisation:
636612
637/*****************************************************************************
638    Cartridge type: GRAMKracker
613    The console has three GROMs with 6 KiB size and occupying 8 KiB of address
614    space each. These are called GROMs 0, 1, and 2. GROM 0 contains the common
615    routines for the computer operation; GROMs 1 and 2 contain TI BASIC.
639616
640    The GK is a big cartridge that fits into the same slot as any other
641    cartridge but which offers a set of switches, an own cartridge slot,
642    and buffered RAM inside. Also, it has a built-in ROM called "LOADER".
617    Memory locations 6000-7fff are assigned to cartridge ROMs; in some
618    cartridges, a second ROM bank can be used by writing a value to a special
619    ROM access. This way, instead of 8 KiB we often have 16 KiB at these
620    locations.
643621
644    Its primary use is to allow the user to copy cartridge contents into the
645    buffered RAM and to modify it there. That way, ROM cartridges can be
646    customized.
622    Each cartridge can host up to 5 GROMs (called GROM 3, 4, 5, 6, and 7).
623    As in the console, each one occupies 6 KiB in an 8 KiB window.
647624
648    The 80 KiB of the GK are allocated as follows
649    00000 - 01fff: GRAM 0
650    02000 - 03fff: GRAM 1  (alternatively, the loader GROM appears here)
651    04000 - 05fff: GRAM 2
652    06000 - 0ffff: GRAM 3-7 (alternatively, the guest GROMs appear here)
653    10000 - 11fff: RAM 1
654    12000 - 13fff: RAM 2
625    The GRAM Kracker offers
655626
656    The GK emulates GROMs, but without a readable address counter. Thus it
657    relies on the console GROMs being still in place.
658    Also, the GK does not implement a GROM buffer.
627    - a loader in an own GROM 1 (which hides the console GROM 1 when active,
628    so we have no BASIC anymore). The contents of the loader must be found
629    by the emulator in a file named ti99_gkracker.zip.
659630
660    We need to implement a complete second path of handling as it differs
661    from the multi-cart extender. Eventually, the multi-cart extender and
662    the GK should be implemented as separate slot devices.
631    - a complete set of 8 (simulated) GRAMs with full 8 KiB each (done by a
632    simple addressing circuit); the basic version only offered GRAMs 3-7
663633
664    The GK cartridge type is in fact the internal LOADER ROM. In order to use
665    the GK, the cartridge must be plugged into one slot, and the "guest"
666    cartridge of the GK must be plugged into any other slot. Also, the DIP
667    switch of the multi-cart extender must be set to "GRAM Kracker".
668*****************************************************************************/
634    - 16 KiB of RAM memory space for the 6000-7fff area (called "bank 1" and "bank 2")
669635
670enum
671{
672   CART_AUTO = 0,
673   CART_1,
674   CART_2,
675   CART_3,
676   CART_4,
677   CART_GK = 15
678};
636    Notes:
679637
638    - it is mandatory to turn off the loader when loading into GRAM 1, but only
639    after prompted in the on-screen instructions, or the loader will crash
640    - GRAM0 must be properly loaded if switch 2 is set to GRAM0 and the computer is reset
641    - Switch 4 must not be in W/P position (write protect) when loading data
642    into the GK (either other position will do).
643
644
645***************************************************************************/
680646enum
681647{
682648   GK_OFF = 0,
r15583r15584
692658   GK_LDOFF = 1
693659};
694660
695void cartridge_pcb_gramkracker_device::set_gk_guest(cartridge_device* guest)
661#define GKSWITCH1_TAG "GKSWITCH1"
662#define GKSWITCH2_TAG "GKSWITCH2"
663#define GKSWITCH3_TAG "GKSWITCH3"
664#define GKSWITCH4_TAG "GKSWITCH4"
665#define GKSWITCH5_TAG "GKSWITCH5"
666
667gkracker_device::gkracker_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
668   :   ti99_cartridge_connector_device(mconfig, GROMPORT_GK, "GRAMKracker", tag, owner, clock),
669      device_nvram_interface(mconfig, *this)
696670{
697   m_gk_guest = guest;
671   m_shortname = "ti99_gkracker";
698672}
699673
700/*
701    Read function for the GRAMKracker cartridge.
702*/
703READ8Z_MEMBER(cartridge_pcb_gramkracker_device::readz)
674READ8Z_MEMBER(gkracker_device::readz)
704675{
705676   if ((offset & GROM_MASK) == GROM_AREA)
706677   {
707678      // Reads from the GRAM space of the GRAM Kracker.
708      // m_gk_slot is the slot where the GK module is plugged in
709      // m_gk_guest_slot is the slot where the cartridge is plugged in
710679
711680      // The GK does not have a readable address counter, but the console
712681      // GROMs will keep our address counter up to date. That is
r15583r15584
752721         // but only if it has GROMs
753722         bool guest_has_grom = false;
754723
755         if (m_gk_guest != NULL)
724         if (m_cartridge != NULL)
756725         {
757            guest_has_grom = (m_gk_guest->has_grom());
726            guest_has_grom = m_cartridge->has_grom();
758727            // Note that we only have ONE real cartridge and the GK;
759728            // we need not access all slots.
760729            if (guest_has_grom)
761730            {
762               m_gk_guest->readz(space, offset, value, mem_mask);   // read from guest
731               m_cartridge->readz(space, offset, value, mem_mask);   // read from guest
763732            }
764733         }
765734         if (!guest_has_grom && (m_gk_switch[1]==GK_NORMAL))
r15583r15584
774743   }
775744   else
776745   {
777      if (m_gk_guest != NULL)
746      if (m_cartridge != NULL)
778747      {
779748         // Read from the guest cartridge.
780         m_gk_guest->readz(space, offset, value, mem_mask);
749         m_cartridge->readz(space, offset, value, mem_mask);
781750      }
782751      else
783752      {
r15583r15584
788757         // RAM is stored behind the GRAM area
789758         case GK_BANK1:
790759            *value = m_ram_ptr[offset+0x10000 - 0x6000];
791
760            break;
792761         case GK_BANK2:
793762            *value = m_ram_ptr[offset+0x12000 - 0x6000];
763            break;
794764
795765         default:
796766            // Switch in middle position (WP, implies auto-select according to the page flag)
r15583r15584
798768               *value = m_ram_ptr[offset+0x10000 - 0x6000];
799769            else
800770               *value = m_ram_ptr[offset+0x12000 - 0x6000];
771            break;
801772         }
802773      }
803774   }
775   if (VERBOSE>8) LOG("gkracker_device: read %04x -> %02x\n", offset, *value);
804776}
805777
806/*
807    See above.
808*/
809WRITE8_MEMBER(cartridge_pcb_gramkracker_device::write)
778WRITE8_MEMBER(gkracker_device::write)
810779{
811780   // write to the guest cartridge if present
812   if (m_gk_guest != NULL)
781   if (m_cartridge != NULL)
813782   {
814      m_gk_guest->write(space, offset, data, mem_mask);
783      m_cartridge->write(space, offset, data, mem_mask);
815784   }
816785
817786   if ((offset & GROM_MASK) == GROM_AREA)
818787   {
819      // Writes to the GRAM space of the GRAM Kracker.
788      // Write to the GRAM space of the GRAM Kracker.
820789      if ((offset & 0x0002)==0x0002)
821790      {
822791         // Set address
r15583r15584
825794            // Accept low address byte (second write)
826795            m_grom_address = (m_grom_address & 0xff00) | data;
827796            m_waddr_LSB = false;
797            if (VERBOSE>8) LOG("gkracker_device: set grom address %04x\n", m_grom_address);
828798         }
829799         else
830800         {
r15583r15584
836806      else
837807      {
838808         // Write data byte to GRAM area.
809         if (VERBOSE>7) LOG("gkracker_device: gwrite %04x(%04x) <- %02x\n", offset, m_grom_address, data);
839810
840811         // According to manual:
841812         // Writing to GRAM 0: switch 2 set to GRAM 0 + Write protect switch (4) in 1 or 2 position
r15583r15584
859830               m_ram_ptr[m_grom_address] = data;
860831            break;
861832         default:
862            if (m_gk_switch[1]==GK_NORMAL && m_gk_guest != NULL)
833            if (m_gk_switch[1]==GK_NORMAL && m_cartridge == NULL)
863834               m_ram_ptr[m_grom_address] = data;
864835            break;
865836         }
r15583r15584
872843   }
873844   else
874845   {
875      // Write to the RAM space of the GRAM Kracker.
876      if (m_gk_guest == NULL)
846      // Write to the RAM space of the GRAM Kracker
847      // (only if no cartridge is present)
848      if (VERBOSE>7) LOG("gkracker_device: write %04x <- %02x\n", offset, data);
849      if (m_cartridge == NULL)
877850      {
878851         if (m_gk_switch[1] == GK_OFF) return; // just don't do anything
879852         switch (m_gk_switch[4])
r15583r15584
897870   }
898871}
899872
873void gkracker_device::crureadz(offs_t offset, UINT8 *value)
874{
875   if (m_cartridge != NULL) m_cartridge->crureadz(offset, value);
876}
877
878void gkracker_device::cruwrite(offs_t offset, UINT8 data)
879{
880   if (m_cartridge != NULL) m_cartridge->cruwrite(offset, data);
881}
882
883INPUT_CHANGED_MEMBER( gkracker_device::gk_changed )
884{
885   if (VERBOSE>7) LOG("gkracker_device: input changed %d - %d\n", (int)((UINT64)param & 0x07), newval);
886   m_gk_switch[(UINT64)param & 0x07] = newval;
887}
888
889void gkracker_device::insert(int index, ti99_cartridge_device* cart)
890{
891   if (VERBOSE>3) LOG("gkracker_device: insert cartridge\n");
892   m_cartridge = cart;
893   // Switch 1 has a third location for resetting. We do the reset by default
894   // here. It can be turned off in the configuration.
895   m_gromport->cartridge_inserted();
896}
897
898void gkracker_device::remove(int index)
899{
900   if (VERBOSE>3) LOG("gkracker_device: remove cartridge\n");
901   m_cartridge = NULL;
902}
903
904void gkracker_device::gk_install_menu(const char* menutext, int len, int ptr, int next, int start)
905{
906   const int base = 0x0000;
907   m_ram_ptr[base + ptr] = (UINT8)((next >> 8) & 0xff);
908   m_ram_ptr[base + ptr+1] = (UINT8)(next & 0xff);
909   m_ram_ptr[base + ptr+2] = (UINT8)((start >> 8) & 0xff);
910   m_ram_ptr[base + ptr+3] = (UINT8)(start & 0xff);
911
912   m_ram_ptr[base + ptr+4] = (UINT8)(len & 0xff);
913   memcpy(m_ram_ptr + base + ptr+5, menutext, len);
914}
915
900916/*
901    Read cartridge mapper CRU interface (Guest in GRAM Kracker)
917    Define the default for the GRAM Kracker device. The memory is preset with
918    some sample entries which shall indicate that the memory has been tested
919    by the manufacturer.
902920*/
903void cartridge_pcb_gramkracker_device::crureadz(offs_t offset, UINT8 *value)
921void gkracker_device::nvram_default()
904922{
905   if (m_gk_guest != NULL)   m_gk_guest->crureadz(offset, value);
923   if (VERBOSE>3) LOG("gkracker_device: Creating default NVRAM\n");
924   memset(m_ram_ptr, 0, 81920);
925
926   m_ram_ptr[0x6000] = 0xaa;
927   m_ram_ptr[0x6001] = 0x01;
928   m_ram_ptr[0x6002] = 0x01;
929
930   m_ram_ptr[0x6006] = 0x60;
931   m_ram_ptr[0x6007] = 0x20;
932
933   gk_install_menu("GROM 3 OK", 9, 0x60e0, 0, 0x6100);
934   gk_install_menu("GROM 4 OK", 9, 0x60c0, 0x60e0, 0x6100);
935   gk_install_menu("GROM 5 OK", 9, 0x60a0, 0x60c0, 0x6100);
936   gk_install_menu("GROM 6 OK", 9, 0x6080, 0x60a0, 0x6100);
937   gk_install_menu("PROM   OK", 9, 0x6060, 0x6080, 0x6100);
938   gk_install_menu("RAMS   OK", 9, 0x6040, 0x6060, 0x6100);
939   gk_install_menu("OPTION GRAMS OK", 15, 0x6020, 0x6040, 0x6100);
940
941   m_ram_ptr[0x6100] = 0x0b;      // GPL EXIT
906942}
907943
944void gkracker_device::nvram_read(emu_file &file)
945{
946   int readsize = file.read(m_ram_ptr, 81920);
947   if (VERBOSE>3) LOG("gkracker_device: reading NVRAM\n");
948   // If we increased the size, fill the remaining parts with 0
949   if (readsize < 81920)
950   {
951      memset(m_ram_ptr + readsize, 0, 81920-readsize);
952   }
953}
954
955void gkracker_device::nvram_write(emu_file &file)
956{
957   if (VERBOSE>3) LOG("gkracker_device: writing NVRAM\n");
958   file.write(m_ram_ptr, 81920);
959}
960
961void gkracker_device::device_start()
962{
963   m_ram_ptr = memregion(GKRACKER_NVRAM_TAG)->base();
964   m_grom_ptr = memregion(GKRACKER_ROM_TAG)->base();
965   m_cartridge = NULL;
966   m_grom_address = 0;   // for the GROM emulation
967   for (int i=1; i < 6; i++) m_gk_switch[i] = 0;
968   m_gromport = static_cast<gromport_device*>(owner());
969}
970
971void gkracker_device::device_reset()
972{
973   m_gk_switch[1] = ioport(GKSWITCH1_TAG)->read();
974   m_gk_switch[2] = ioport(GKSWITCH2_TAG)->read();
975   m_gk_switch[3] = ioport(GKSWITCH3_TAG)->read();
976   m_gk_switch[4] = ioport(GKSWITCH4_TAG)->read();
977   m_gk_switch[5] = ioport(GKSWITCH5_TAG)->read();
978}
979
980static MACHINE_CONFIG_FRAGMENT( gkracker_slot )
981   MCFG_DEVICE_ADD("cartridge", TI99CART, 0)
982MACHINE_CONFIG_END
983
908984/*
909    Write cartridge mapper CRU interface (Guest in GRAM Kracker)
985    The GRAMKracker ROM
910986*/
911void cartridge_pcb_gramkracker_device::cruwrite(offs_t offset, UINT8 data)
987ROM_START( gkracker_rom )
988   ROM_REGION(0x14000, GKRACKER_NVRAM_TAG, ROMREGION_ERASE00)
989   ROM_REGION(0x2000, GKRACKER_ROM_TAG, 0)
990   ROM_LOAD("gkracker.bin", 0x0000, 0x2000, CRC(86eaaf9f) SHA1(a3bd5257c63e190800921b52dbe3ffa91ad91113))
991ROM_END
992
993const rom_entry *gkracker_device::device_rom_region() const
912994{
913   if (m_gk_guest != NULL) m_gk_guest->cruwrite(offset, data);
995   return ROM_NAME( gkracker_rom );
914996}
915997
916/*****************************************************************************
917    A cartridge. In fact, just the empty cartridge, as the image to be loaded
918    will be included as the PCB.
919*****************************************************************************/
998machine_config_constructor gkracker_device::device_mconfig_additions() const
999{
1000   return MACHINE_CONFIG_NAME( gkracker_slot );
1001}
9201002
1003INPUT_PORTS_START(gkracker)
1004   PORT_START( GKSWITCH1_TAG )
1005   PORT_DIPNAME( 0x01, 0x01, "GK switch 1" ) PORT_CHANGED_MEMBER(DEVICE_SELF, gkracker_device, gk_changed, 1)
1006      PORT_DIPSETTING(    0x00, "GK Off" )
1007      PORT_DIPSETTING(    0x01, DEF_STR( Normal ) )
1008
1009   PORT_START( GKSWITCH2_TAG )
1010   PORT_DIPNAME( 0x01, 0x01, "GK switch 2" ) PORT_CHANGED_MEMBER(DEVICE_SELF, gkracker_device, gk_changed, 2)
1011      PORT_DIPSETTING(    0x00, "GRAM 0" )
1012      PORT_DIPSETTING(    0x01, "Op Sys" )
1013
1014   PORT_START( GKSWITCH3_TAG )
1015   PORT_DIPNAME( 0x01, 0x01, "GK switch 3" ) PORT_CHANGED_MEMBER(DEVICE_SELF, gkracker_device, gk_changed, 3)
1016      PORT_DIPSETTING(    0x00, "GRAM 1-2" )
1017      PORT_DIPSETTING(    0x01, "TI BASIC" )
1018
1019   PORT_START( GKSWITCH4_TAG )
1020   PORT_DIPNAME( 0x03, 0x01, "GK switch 4" ) PORT_CHANGED_MEMBER(DEVICE_SELF, gkracker_device, gk_changed, 4)
1021      PORT_DIPSETTING(    0x00, "Bank 1" )
1022      PORT_DIPSETTING(    0x01, "W/P" )
1023      PORT_DIPSETTING(    0x02, "Bank 2" )
1024
1025   PORT_START( GKSWITCH5_TAG )
1026   PORT_DIPNAME( 0x01, 0x00, "GK switch 5" ) PORT_CHANGED_MEMBER(DEVICE_SELF, gkracker_device, gk_changed, 5)
1027      PORT_DIPSETTING(    0x00, "Loader On" )
1028      PORT_DIPSETTING(    0x01, "Loader Off" )
1029INPUT_PORTS_END
1030
1031ioport_constructor gkracker_device::device_input_ports() const
1032{
1033   return INPUT_PORTS_NAME(gkracker);
1034}
1035
1036/***************************************************************************
1037    Cartridge implementation
1038
1039    Every cartridge is an instance of ti99_cartridge_device, implementing the
1040    device_image_interface. This means it is capable of loading cartridge
1041    data into its memory locations. All memory locations are organised as
1042    regions.
1043
1044    The different cartridge versions are realised by different PCB instances.
1045    All PCBs are subclassed from ti99_cartridge_pcb.
1046
1047***************************************************************************/
1048enum
1049{
1050   PCB_STANDARD=1,
1051   PCB_PAGED,
1052   PCB_MINIMEM,
1053   PCB_SUPER,
1054   PCB_MBX,
1055   PCB_PAGED379I,
1056   PCB_PAGEDCRU
1057};
1058
9211059static const pcb_type pcbdefs[] =
9221060{
9231061   { PCB_STANDARD, "standard" },
r15583r15584
9271065   { PCB_MBX, "mbx" },
9281066   { PCB_PAGED379I, "paged379i" },
9291067   { PCB_PAGEDCRU, "pagedcru" },
930   { PCB_GKRACKER, "gramkracker" },
9311068   { 0, NULL}
9321069};
9331070
r15583r15584
9391076   { 0, NULL}
9401077};
9411078
942cartridge_device::cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
943: bus8z_device(mconfig, TICARTRIDGE, "TI-99 cartridge", tag, owner, clock),
944  device_image_interface(mconfig, *this),
945  m_pcb(NULL)
1079ti99_cartridge_device::ti99_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
1080:   bus8z_device(mconfig, TI99CART, "TI-99 cartridge", tag, owner, clock),
1081   device_image_interface(mconfig, *this),
1082   m_pcb(NULL)
9461083{
9471084   m_shortname = "cartridge";
9481085}
9491086
950void cartridge_device::device_start()
1087void ti99_cartridge_device::prepare_cartridge()
9511088{
952   if (VERBOSE>7) LOG("cartridge_device: device_start\n");
953}
954
955void cartridge_device::device_stop()
956{
957   if (VERBOSE>7) LOG("cartridge_device: device_stop\n");
958}
959
960void cartridge_device::device_reset()
961{
962   if (m_type==PCB_GKRACKER)
963   {
964      cartridge_pcb_gramkracker_device* pcb = static_cast<cartridge_pcb_gramkracker_device*>(m_pcb);
965      pcb->m_gk_switch[1] = owner()->ioport(GKSWITCH1_TAG)->read();
966      pcb->m_gk_switch[2] = owner()->ioport(GKSWITCH2_TAG)->read();
967      pcb->m_gk_switch[3] = owner()->ioport(GKSWITCH3_TAG)->read();
968      pcb->m_gk_switch[4] = owner()->ioport(GKSWITCH4_TAG)->read();
969      pcb->m_gk_switch[5] = owner()->ioport(GKSWITCH5_TAG)->read();
970   }
971}
972
973void cartridge_device::device_config_complete()
974{
975   if (VERBOSE>8) LOG("cartridge_device: device_config_complete\n");
976   update_names();
977   m_softlist = false;
978}
979
980void cartridge_device::prepare_cartridge()
981{
9821089   int rom2_length;
9831090
9841091   UINT8* grom_ptr;
r15583r15584
9961103      grom_ptr = m_softlist? get_software_region("grom_socket") : (UINT8*)m_rpk->get_contents_of_socket("grom_socket");
9971104      memcpy(regg->base(), grom_ptr, m_pcb->m_grom_size);
9981105
999      if (m_type==PCB_GKRACKER)
1000      {
1001         cartridge_pcb_gramkracker_device* pcb = static_cast<cartridge_pcb_gramkracker_device*>(m_pcb);
1002         pcb->m_grom_ptr = grom_ptr;
1003      }
1004
10051106      // Find the GROMs and keep their pointers
1006      m_pcb->m_grom[0] = static_cast<ti99_grom_device*>(subdevice(GROM3_TAG));
1007      if (m_pcb->m_grom_size > 0x2000) m_pcb->m_grom[1] = static_cast<ti99_grom_device*>(subdevice(GROM4_TAG));
1008      if (m_pcb->m_grom_size > 0x4000) m_pcb->m_grom[2] = static_cast<ti99_grom_device*>(subdevice(GROM5_TAG));
1009      if (m_pcb->m_grom_size > 0x6000) m_pcb->m_grom[3] = static_cast<ti99_grom_device*>(subdevice(GROM6_TAG));
1010      if (m_pcb->m_grom_size > 0x8000) m_pcb->m_grom[4] = static_cast<ti99_grom_device*>(subdevice(GROM7_TAG));
1107      m_pcb->set_grom_pointer(0, subdevice(GROM3_TAG));
1108      if (m_pcb->m_grom_size > 0x2000) m_pcb->set_grom_pointer(1, subdevice(GROM4_TAG));
1109      if (m_pcb->m_grom_size > 0x4000) m_pcb->set_grom_pointer(2, subdevice(GROM5_TAG));
1110      if (m_pcb->m_grom_size > 0x6000) m_pcb->set_grom_pointer(3, subdevice(GROM6_TAG));
1111      if (m_pcb->m_grom_size > 0x8000) m_pcb->set_grom_pointer(4, subdevice(GROM7_TAG));
10111112   }
10121113
10131114   m_pcb->m_rom_size = m_softlist? get_software_region_length("rom_socket") : m_rpk->get_resource_length("rom_socket");
10141115   if (m_pcb->m_rom_size > 0)
10151116   {
1117      if (VERBOSE>6) LOG("gromport: rom_socket.size=0x%04x\n", m_pcb->m_rom_size);
10161118      regr = memregion("rom_contents");
10171119      m_pcb->m_rom_ptr = m_softlist? get_software_region("rom_socket") : (UINT8*)m_rpk->get_contents_of_socket("rom_socket");
10181120      memcpy(regr->base(), m_pcb->m_rom_ptr, m_pcb->m_rom_size);
r15583r15584
10391141   }
10401142}
10411143
1042bool cartridge_device::has_grom()
1144/*
1145    Find the index of the cartridge name. We assume the format
1146    <name><number>, i.e. the number is the longest string from the right
1147    which can be interpreted as a number. Subtract 1.
1148*/
1149int ti99_cartridge_device::get_index_from_tagname()
10431150{
1044   assert (m_pcb != NULL);
1045   return (m_pcb->m_grom_size>0);
1046}
1151   const char *mytag = tag();
1152   int maxlen = strlen(mytag);
1153   int i;
10471154
1048void cartridge_device::set_gk_guest(cartridge_device* guest)
1049{
1050   assert (m_pcb != NULL);
1051   assert (m_rpk->get_type()==PCB_GKRACKER);
1155   for (i=maxlen-1; i >=0; i--)
1156      if (mytag[i] < 48 || mytag[i] > 57) break;
10521157
1053   cartridge_pcb_gramkracker_device* pcb = static_cast<cartridge_pcb_gramkracker_device*>(m_pcb);
1054   pcb->set_gk_guest(guest);
1158   if (i==maxlen-1) return 0;
1159   return atoi(mytag+i+1)-1;
10551160}
10561161
1057void cartridge_device::set_switch(int swtch, int val)
1162bool ti99_cartridge_device::has_grom()
10581163{
1059   assert (m_pcb != NULL);
1060   assert (m_rpk->get_type()==PCB_GKRACKER);
1061   cartridge_pcb_gramkracker_device* pcb = static_cast<cartridge_pcb_gramkracker_device*>(m_pcb);
1062   pcb->m_gk_switch[swtch] = val;
1164   return m_pcb->m_grom_size>0;
10631165}
10641166
1065bool cartridge_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry)
1167bool ti99_cartridge_device::call_load()
10661168{
1067   if (VERBOSE>8) LOG("gromport.cartridge_device: swlist = %s, swname = %s\n", swlist, swname);
1068   load_software_part_region(this, swlist, swname, start_entry);
1069   m_softlist = true;
1070   m_rpk = NULL;
1071   return true;
1072}
1073
1074bool cartridge_device::call_load()
1075{
10761169   // File name is in m_basename
10771170   // return true = error
1078   if (VERBOSE>8) LOG("cartridge_device: loading\n");
1171   if (VERBOSE>8) LOG("cartridge_device: loading %s in slot %s\n", m_basename.cstr(), tag());
10791172
1080   astring ntag(tag(), ":PCB");
1081   const char* mytag = ntag.cstr();
1082   gromport_device *gp = static_cast<gromport_device*>(owner());
1083   int slot = get_index_from_tagname();
1084
10851173   if (m_softlist)
10861174   {
1087      LOG("using softlists\n");
1175      if (VERBOSE>7) LOG("using softlists\n");
10881176      int i = 0;
10891177      const char* pcb = get_feature("pcb");
10901178      do
10911179      {
10921180         if (strcmp(pcb, sw_pcbdefs[i].name)==0)
10931181         {
1094            m_type = sw_pcbdefs[i].id;
1182            m_pcbtype = sw_pcbdefs[i].id;
10951183            break;
10961184         }
10971185         i++;
10981186      } while (sw_pcbdefs[i].id != 0);
1099      if (VERBOSE>5) LOG("gromport.cartridge_device: Cartridge type is %s (%d)\n", pcb, m_type);
1187      if (VERBOSE>5) LOG("gromport.cartridge_device: Cartridge type is %s (%d)\n", pcb, m_pcbtype);
11001188   }
11011189   else
11021190   {
r15583r15584
11041192      try
11051193      {
11061194         m_rpk = reader->open(machine().options(), filename(), machine().system().name);
1107         m_type = m_rpk->get_type();
1195         m_pcbtype = m_rpk->get_type();
11081196      }
11091197      catch (rpk_exception& err)
11101198      {
r15583r15584
11151203      }
11161204   }
11171205
1118   switch (m_type)
1206   switch (m_pcbtype)
11191207   {
11201208   case PCB_STANDARD:
11211209      if (VERBOSE>6) LOG("gromport.cartridge_device: standard PCB\n");
1122      m_pcb = static_cast<cartridge_pcb_standard_device*>(&machine().add_dynamic_device(*this, TICARTPCBSTD, mytag, 0));
1210      m_pcb = new ti99_standard_cartridge();
11231211      break;
11241212   case PCB_PAGED:
11251213      if (VERBOSE>6) LOG("gromport.cartridge_device: paged PCB\n");
1126      m_pcb = static_cast<cartridge_pcb_paged_device*>(&machine().add_dynamic_device(*this, TICARTPCBPAG, mytag, 0));
1214      m_pcb = new ti99_paged_cartridge();
11271215      break;
11281216   case PCB_MINIMEM:
11291217      if (VERBOSE>6) LOG("gromport.cartridge_device: minimem PCB\n");
1130      m_pcb = static_cast<cartridge_pcb_minimem_device*>(&machine().add_dynamic_device(*this, TICARTPCBMIN, mytag, 0));
1218      m_pcb = new ti99_minimem_cartridge();
11311219      break;
11321220   case PCB_SUPER:
11331221      if (VERBOSE>6) LOG("gromport.cartridge_device: superspace PCB\n");
1134      m_pcb = static_cast<cartridge_pcb_superspace_device*>(&machine().add_dynamic_device(*this, TICARTPCBSUP, mytag, 0));
1222      m_pcb = new ti99_super_cartridge();
11351223      break;
11361224   case PCB_MBX:
11371225      if (VERBOSE>6) LOG("gromport.cartridge_device: MBX PCB\n");
1138      m_pcb = static_cast<cartridge_pcb_mbx_device*>(&machine().add_dynamic_device(*this, TICARTPCBMBX, mytag, 0));
1226      m_pcb = new ti99_mbx_cartridge();
11391227      break;
11401228   case PCB_PAGED379I:
11411229      if (VERBOSE>6) LOG("gromport.cartridge_device: Paged379i PCB\n");
1142      m_pcb = static_cast<cartridge_pcb_paged379i_device*>(&machine().add_dynamic_device(*this, TICARTPCBPGI, mytag, 0));
1230      m_pcb = new ti99_paged379i_cartridge();
11431231      break;
11441232   case PCB_PAGEDCRU:
11451233      if (VERBOSE>6) LOG("gromport.cartridge_device: PagedCRU PCB\n");
1146      m_pcb = static_cast<cartridge_pcb_pagedcru_device*>(&machine().add_dynamic_device(*this, TICARTPCBPGC, mytag, 0));
1234      m_pcb = new ti99_pagedcru_cartridge();
11471235      break;
1148   case PCB_GKRACKER:
1149      if (VERBOSE>6) LOG("gromport.cartridge_device: GRAMKracker PCB\n");
1150      m_pcb = static_cast<cartridge_pcb_gramkracker_device*>(&machine().add_dynamic_device(*this, TICARTPCBGRK, mytag, 0));
1151      gp->set_gk_slot(slot);
1152      break;
11531236   }
11541237
11551238   prepare_cartridge();
1156   m_pcb->set_machine(machine()); // TODO: Feels like a hack.
1157   gp->change_slot(true, slot);
1158
1159   machine().schedule_hard_reset();  // could be configurable by DIP switch, simulating taping the RESET line
1160
1239   m_slot = get_index_from_tagname();
1240   m_connector->insert(m_slot, this);
11611241   return false;
11621242}
11631243
1164void cartridge_device::call_unload()
1244void ti99_cartridge_device::call_unload()
11651245{
1166   if (VERBOSE>6) LOG("gromport.cartridge_device: unloading from %s\n", tag());
1167
1168   gromport_device *gp = static_cast<gromport_device*>(owner());
1169   int slot = get_index_from_tagname();
1170   if (slot == gp->m_gk_slot)
1171   {
1172      gp->m_gk_slot = -1;      // Remove GRAMKracker slot index
1173      // seems to be no way to change the dip switch except by keyboard
1174   }
1175
1246   if (VERBOSE>7) LOG("ti99_cartridge_device: unload\n");
11761247   if (m_rpk != NULL)
11771248   {
1178      // Transfer RAM contents back into socket structure
1179/*      if (m_pcb->m_ram_size > 0)
1180        {
1181            UINT8* ram_ptr;
1182            ram_ptr = (UINT8*)m_rpk->get_contents_of_socket("ram_socket");
1183            memcpy(ram_ptr, m_pcb->m_ram_ptr, m_pcb->m_ram_size);
1184        } */
11851249      m_rpk->close(); // will write NVRAM contents
11861250      delete m_rpk;
11871251   }
11881252
1189   // TODO: How can we remove the dynamically added device?
1253   delete m_pcb;
11901254   m_pcb = NULL;
1191   gp->change_slot(false, get_index_from_tagname());
1255   m_connector->remove(m_slot);
11921256}
11931257
1194READ8Z_MEMBER(cartridge_device::readz)
1258void ti99_cartridge_device::set_slot(int i)
11951259{
1196   assert(m_pcb != NULL);
1197   m_pcb->readz(space, offset, value, mem_mask);
1260   m_slot = i;
11981261}
11991262
1200WRITE8_MEMBER(cartridge_device::write)
1263bool ti99_cartridge_device::call_softlist_load(char *swlist, char *swname, rom_entry *start_entry)
12011264{
1202   assert(m_pcb != NULL);
1203   m_pcb->write(space, offset, data, mem_mask);
1265   if (VERBOSE>8) LOG("ti99_cartridge_device: swlist = %s, swname = %s\n", swlist, swname);
1266   load_software_part_region(this, swlist, swname, start_entry);
1267   m_softlist = true;
1268   m_rpk = NULL;
1269   return true;
12041270}
12051271
1206void cartridge_device::crureadz(offs_t offset, UINT8 *value)
1272READ8Z_MEMBER(ti99_cartridge_device::readz)
12071273{
1208   assert(m_pcb != NULL);
1209   m_pcb->crureadz(offset, value);
1274   if (m_pcb != NULL) m_pcb->readz(space, offset, value);
12101275}
12111276
1212void cartridge_device::cruwrite(offs_t offset, UINT8 data)
1277WRITE8_MEMBER(ti99_cartridge_device::write)
12131278{
1214   assert(m_pcb != NULL);
1215   m_pcb->cruwrite(offset, data);
1279   if (m_pcb != NULL) m_pcb->write(space, offset, data);
12161280}
12171281
1218/*
1219    Find the index of the cartridge name. We assume the format
1220    <name><number>, i.e. the number is the longest string from the right
1221    which can be interpreted as a number. Subtract 1.
1222*/
1223int cartridge_device::get_index_from_tagname()
1282void ti99_cartridge_device::crureadz(offs_t offset, UINT8 *value)
12241283{
1225   const char *mytag = tag();
1226   int maxlen = strlen(mytag);
1227   int i;
1228   for (i=maxlen-1; i >=0; i--)
1229      if (mytag[i] < 48 || mytag[i] > 57) break;
1284   if (m_pcb != NULL) m_pcb->crureadz(offset, value);
1285}
12301286
1231   return atoi(mytag+i+1)-1;
1287void ti99_cartridge_device::cruwrite(offs_t offset, UINT8 data)
1288{
1289   if (m_pcb != NULL) m_pcb->cruwrite(offset, data);
12321290}
12331291
1292void ti99_cartridge_device::ready_line(int state)
1293{
1294   m_connector->ready_line(state);
1295}
1296
1297void ti99_cartridge_device::device_config_complete()
1298{
1299   update_names();
1300   m_softlist = false;
1301   m_connector = static_cast<ti99_cartridge_connector_device*>(owner());
1302}
1303
12341304static GROM_CONFIG(grom3_config)
12351305{
1236   false, 3, CARTGROM_TAG, 0x0000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(":gromport", gromport_device, ready_line), GROMFREQ
1306   false, 3, CARTGROM_TAG, 0x0000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti99_cartridge_device, ready_line), GROMFREQ
12371307};
12381308static GROM_CONFIG(grom4_config)
12391309{
1240   false, 4, CARTGROM_TAG, 0x2000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(":gromport", gromport_device, ready_line), GROMFREQ
1310   false, 4, CARTGROM_TAG, 0x2000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti99_cartridge_device, ready_line), GROMFREQ
12411311};
12421312static GROM_CONFIG(grom5_config)
12431313{
1244   false, 5, CARTGROM_TAG, 0x4000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(":gromport", gromport_device, ready_line), GROMFREQ
1314   false, 5, CARTGROM_TAG, 0x4000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti99_cartridge_device, ready_line), GROMFREQ
12451315};
12461316static GROM_CONFIG(grom6_config)
12471317{
1248   false, 6, CARTGROM_TAG, 0x6000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(":gromport", gromport_device, ready_line), GROMFREQ
1318   false, 6, CARTGROM_TAG, 0x6000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti99_cartridge_device, ready_line), GROMFREQ
12491319};
12501320static GROM_CONFIG(grom7_config)
12511321{
1252   false, 7, CARTGROM_TAG, 0x8000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(":gromport", gromport_device, ready_line), GROMFREQ
1322   false, 7, CARTGROM_TAG, 0x8000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti99_cartridge_device, ready_line), GROMFREQ
12531323};
12541324
12551325/*
1256    The GROM devices on a cartridge.
1326    5 GROMs that may be contained in a cartridge
12571327*/
1258static MACHINE_CONFIG_FRAGMENT( cartridge_groms )
1328static MACHINE_CONFIG_FRAGMENT( ti99_cartridge )
12591329   MCFG_GROM_ADD( GROM3_TAG, grom3_config )
12601330   MCFG_GROM_ADD( GROM4_TAG, grom4_config )
12611331   MCFG_GROM_ADD( GROM5_TAG, grom5_config )
r15583r15584
12631333   MCFG_GROM_ADD( GROM7_TAG, grom7_config )
12641334MACHINE_CONFIG_END
12651335
1266machine_config_constructor cartridge_device::device_mconfig_additions() const
1336machine_config_constructor ti99_cartridge_device::device_mconfig_additions() const
12671337{
1268   return MACHINE_CONFIG_NAME( cartridge_groms );
1338   return MACHINE_CONFIG_NAME( ti99_cartridge );
12691339}
12701340
12711341/*
1272    Memory area for one cartridge.
1342    Memory area for one cartridge. For most cartridges we only need 8 KiB for
1343    ROM contents, but cartridges of the "paged379i" type have up to 128 KiB
1344    organised as selectable banks, so we must be sure there is enough space.
12731345*/
12741346ROM_START( cartridge_memory )
1275   ROM_REGION(0xa000, CARTGROM_TAG, 0)
1276   ROM_FILL(0x0000, 0xa000, 0x00)
1277   ROM_REGION(0x2000, CARTROM_TAG, 0)
1278   ROM_FILL(0x0000, 0x2000, 0x00)
1279   ROM_REGION(0x2000, CARTROM2_TAG, 0)
1280   ROM_FILL(0x0000, 0x2000, 0x00)
1347   ROM_REGION(0xa000, CARTGROM_TAG, ROMREGION_ERASE00)
1348   ROM_REGION(0x20000, CARTROM_TAG, ROMREGION_ERASE00)
1349   ROM_REGION(0x2000, CARTROM2_TAG, ROMREGION_ERASE00)
12811350ROM_END
12821351
1283const rom_entry *cartridge_device::device_rom_region() const
1352const rom_entry *ti99_cartridge_device::device_rom_region() const
12841353{
12851354   return ROM_NAME( cartridge_memory );
12861355}
12871356
1288void gromport_device::set_gk_slot(int slot)
1357const device_type TI99CART = &device_creator<ti99_cartridge_device>;
1358
1359/***************************************************************************
1360    Cartridge types
1361    Cartridges differ by the circuits on their PCB which hosts the ROMs.
1362    Some cartridges also have RAM, and some allow for switching between
1363    ROMs.
1364
1365    Unlike in the previous implementation we do not model it as a full device.
1366***************************************************************************/
1367
1368ti99_cartridge_pcb::ti99_cartridge_pcb()
12891369{
1290   if (VERBOSE>5) LOG("gromport_device: Setting slot %d as GK slot.\n", slot);
1291   m_gk_slot = slot;
12921370}
12931371
1294void gromport_device::find_gk_guest()
1372READ8Z_MEMBER(ti99_cartridge_pcb::gromreadz)
12951373{
1296   // The first slot which contains a cartridge (not the GK) is the guest of the GK
1297   for (int i=0; i < m_numcart; i++)
1374   for (int i=0; i < 5; i++)
12981375   {
1299      if (i==m_gk_slot) continue;
1300      if (m_cartridge[i]->is_available())
1376      if (m_grom[i] != NULL)
13011377      {
1302         m_cartridge[m_gk_slot]->set_gk_guest(m_cartridge[i]);
1303         if (VERBOSE>5) LOG("gromport_device: Setting slot %d as guest slot.\n", i);
1304         return;
1378         m_grom[i]->readz(space, offset, value, mem_mask);
13051379      }
13061380   }
1307   m_cartridge[m_gk_slot]->set_gk_guest(NULL);
13081381}
13091382
1310/*****************************************************************************
1311    The complete multi-port cartridge system. Hosts up to four cartridges
1312    at this time.
1313*****************************************************************************/
1314
1315gromport_device::gromport_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
1316: bus8z_device(mconfig, GROMPORT, "TI-99 multi-cartridge extender", tag, owner, clock)
1383WRITE8_MEMBER(ti99_cartridge_pcb::gromwrite)
13171384{
1318   m_gk_slot = -1;
1385   for (int i=0; i < 5; i++)
1386   {
1387      if (m_grom[i] != NULL)
1388      {
1389         m_grom[i]->write(space, offset, data, mem_mask);
1390      }
1391   }
13191392}
13201393
1321/*
1322    Activates a slot in the multi-cartridge extender.
1323    Setting the slot is done by accessing the GROM ports using a
1324    specific address:
1325
1326    slot 0:  0x9800 (0x9802, 0x9c00, 0x9c02)   : cartridge1
1327    slot 1:  0x9804 (0x9806, 0x9c04, 0x9c06)   : cartridge2
1328    ...
1329    slot 15: 0x983c (0x983e, 0x9c3c, 0x9c3e)   : cartridge16
1330
1331    Scheme:
1332
1333    1001 1Wxx xxxx xxM0 (M=mode; M=0: data, M=1: address; W=write)
1334
1335    The following addresses are theoretically available, but the
1336    built-in OS does not use them; i.e. cartridges will not be
1337    included in the selection list, and their features will not be
1338    found by lookup, but they could be accessed directly by user
1339    programs.
1340    slot 16: 0x9840 (0x9842, 0x9c40, 0x9c42)
1341    ...
1342    slot 255:  0x9bfc (0x9bfe, 0x9ffc, 0x9ffe)
1343
1344    Setting the GROM base should select one cartridge, but the ROMs in the
1345    CPU space must also be switched. As there is no known special mechanism
1346    we assume that by switching the GROM base, the ROM is automatically
1347    switched.
1348
1349    Caution: This means that cartridges which do not have at least one
1350    GROM cannot be switched with this mechanism.
1351
1352    We assume that the slot number is already calculated in the caller:
1353    slotnumber>=0 && slotnumber<=255
1354
1355    NOTE: The OS will stop searching when it finds slots 1 and 2 empty.
1356    Interestingly, cartridge subroutines are found nevertheless, even when
1357    the cartridge is plugged into a higher slot.
1358*/
1359void gromport_device::set_slot(int slotnumber)
1394READ8Z_MEMBER(ti99_cartridge_pcb::readz)
13601395{
1361   if (VERBOSE>7)
1362      if (m_active_slot != slotnumber) LOG("ti99: gromport: Setting cartslot to %d\n", slotnumber);
1363
1364   if (m_fixed_slot==AUTO)
1365      m_active_slot = slotnumber;
1396   if ((offset & GROM_MASK)==GROM_AREA)
1397      gromreadz(space, offset, value, mem_mask);
13661398   else
1367      m_active_slot = m_fixed_slot;
1399   {
1400      if (m_rom_ptr!=NULL)
1401      {
1402         // For TI-99/8 we should plan for 16K cartridges. However, none was ever produced.
1403         // Well, forget about that.
1404         *value = m_rom_ptr[offset & 0x1fff];
1405         //      LOG("read cartridge rom space %04x = %02x\n", offset, *value);
1406      }
1407   }
13681408}
13691409
1370int gromport_device::get_active_slot(bool changebase, offs_t offset)
1410WRITE8_MEMBER(ti99_cartridge_pcb::write)
13711411{
1372   int slot;
1373   if (changebase)
1412   // LOG("write standard\n");
1413   if ((offset & GROM_MASK)==GROM_AREA)
1414      gromwrite(space, offset, data, mem_mask);
1415   else
13741416   {
1375      if ((offset & GROM_MASK) == GROM_AREA)
1376      {
1377         set_slot((offset>>2) & 0x00ff);
1378      }
1417      if (VERBOSE>5) LOG("cartridge_pcb_device: Cannot write to ROM space at %04x\n", offset);
13791418   }
1380   slot = m_active_slot;
1419}
13811420
1382   // Here we have a design flaw in the operating system of the TI.
1383   // The system iterates through all banks to check for multiple cartridges.
1384   // If we do not have a multi-cart system, each bank shows the same contents
1385   // since there is no decoding of the bank information.
1386   // This brings us into trouble here: If only slot 1 is occupied, slot 2
1387   // would deliver zeros only. This differs from slot 1, so we get a
1388   // meaningless selection option.
1389   //
1390   // If we have only one cartridge in slot 1, we pretend that we have a
1391   // single-slot system. The slot variable is forced to the first slot.
1421void ti99_cartridge_pcb::crureadz(offs_t offset, UINT8 *value)
1422{
1423}
13921424
1393   if (m_fixed_slot==AUTO && m_next_free_slot==1)
1394      slot=0;
1425void ti99_cartridge_pcb::cruwrite(offs_t offset, UINT8 data)
1426{
1427}
13951428
1396   return slot;
1429inline void ti99_cartridge_pcb::set_grom_pointer(int number, device_t *dev)
1430{
1431   m_grom[number] = static_cast<ti99_grom_device*>(dev);
13971432}
13981433
1399void gromport_device::change_slot(bool inserted, int index)
1434/*****************************************************************************
1435  Cartridge type: Paged (Extended Basic)
1436    This cartridge consists of GROM memory and 2 pages of standard ROM.
1437    The page is set by writing any value to a location in
1438    the address area, where an even word offset sets the page to 0 and an
1439    odd word offset sets the page to 1 (e.g. 6000 = bank 0, and
1440    6002 = bank 1).
1441******************************************************************************/
1442
1443READ8Z_MEMBER(ti99_paged_cartridge::readz)
14001444{
1401   if (inserted)
1402   {
1403      if (VERBOSE>6) LOG("gromport_device: Inserted into slot %d\n", index);
1404      if (m_next_free_slot <= index)
1405         m_next_free_slot = index+1;
1406   }
1445   if ((offset & GROM_MASK)==GROM_AREA)
1446      gromreadz(space, offset, value, mem_mask);
14071447   else
14081448   {
1409      if (VERBOSE>6) LOG("gromport_device: Removed from slot %d\n", index);
1410      for (int i=NUMBER_OF_CARTRIDGE_SLOTS-1; i>=0; i--)
1449      if (m_rom_page==0)
14111450      {
1412         if (m_cartridge[i]->is_available())
1413         {
1414            m_next_free_slot = index+1;
1415            break;
1416         }
1451         *value = m_rom_ptr[offset & 0x1fff];
14171452      }
1453      else
1454      {
1455         *value = m_rom2_ptr[offset & 0x1fff];
1456      }
14181457   }
1419   if (VERBOSE>6) LOG("Next free slot: %d\n", m_next_free_slot);
1458}
14201459
1421   if (m_gk_slot != -1) find_gk_guest();
1460WRITE8_MEMBER(ti99_paged_cartridge::write)
1461{
1462   // LOG("write standard\n");
1463   if ((offset & GROM_MASK)==GROM_AREA)
1464      gromwrite(space, offset, data, mem_mask);
1465
1466   else
1467      m_rom_page = (offset >> 1) & 1;
14221468}
14231469
1424/****************************************************
1425    Memory space (ROM, GROM)
1426****************************************************/
1427READ8Z_MEMBER(gromport_device::readz)
1470/*****************************************************************************
1471  Cartridge type: Mini Memory
1472    GROM: 6 KiB (occupies G>6000 to G>7800)
1473    ROM: 4 KiB (romfile is actually 8 K long, second half with zeros, 0x6000-0x6fff)
1474    persistent RAM: 4 KiB (0x7000-0x7fff)
1475******************************************************************************/
1476
1477/* Read function for the minimem cartridge. */
1478READ8Z_MEMBER(ti99_minimem_cartridge::readz)
14281479{
1429   // GRAMKracker support
1430   // We *could* check the DIP switch, but this would only introduce another
1431   // source of confusion when the GRAMKracker is plugged in, but the switch
1432   // is not set.
1433   // The check for the presence of the GK using the index is safer.
1434   if ((m_gk_slot != -1) /*&& (ioport("CARTSLOT")==CART_GK) */)
1435   {
1436      m_cartridge[m_gk_slot]->readz(space, offset, value, mem_mask);
1437      return;
1438   }
1480   if ((offset & GROM_MASK)==GROM_AREA)
1481      gromreadz(space, offset, value, mem_mask);
14391482
1440   int slot = get_active_slot(true, offset);
1441
1442   // If we have a GROM access, we need to send the read request to all
1443   // attached cartridges so the slot is irrelevant here. Each GROM
1444   // contains an internal address counter, and we must make sure they all stay in sync.
1445   if ((offset & GROM_MASK) == GROM_AREA)
1483   else
14461484   {
1447      for (int i=0; i < m_numcart; i++)
1485      if ((offset & 0x1000)==0x0000)
14481486      {
1449         if (m_cartridge[i]->is_available())
1450         {
1451            UINT8 newval = *value;
1452            m_cartridge[i]->readz(space, offset, &newval, mem_mask);
1453            if (i==slot)
1454            {
1455               *value = newval;
1456            }
1457         }
1487         *value = m_rom_ptr[offset & 0x0fff];
14581488      }
1459   }
1460   else
1461   {
1462      if (slot < m_numcart && m_cartridge[slot]->is_available())
1489      else
14631490      {
1464         m_cartridge[slot]->readz(space, offset, value, mem_mask);
1491         *value = m_ram_ptr[offset & 0x0fff];
14651492      }
14661493   }
14671494}
14681495
1469WRITE8_MEMBER(gromport_device::write)
1496/* Write function for the minimem cartridge. */
1497WRITE8_MEMBER(ti99_minimem_cartridge::write)
14701498{
1471   // GRAMKracker support
1472   if ((m_gk_slot != -1) /*&& (ioport("CARTSLOT")==CART_GK)*/)
1473   {
1474      m_cartridge[m_gk_slot]->write(space, offset, data, mem_mask);
1475      return;
1476   }
1499   // LOG("write standard\n");
1500   if ((offset & GROM_MASK)==GROM_AREA)
1501      gromwrite(space, offset, data, mem_mask);
14771502
1478   int slot = get_active_slot(true, offset);
1479
1480   // Same issue as above (read)
1481   // We don't have GRAM cartridges, anyway, so it's just used for setting the address.
1482   if ((offset & GROM_MASK) == GROM_AREA)
1503   else
14831504   {
1484      for (int i=0; i < m_numcart; i++)
1505      if ((offset & 0x1000)==0x0000)
14851506      {
1486         if (m_cartridge[i]->is_available())
1487         {
1488            m_cartridge[i]->write(space, offset, data, mem_mask);
1489         }
1507         if (VERBOSE>1) LOG("ti99: gromport: Write access to cartridge ROM at address %04x ignored", offset);
14901508      }
1509      else
1510      {
1511         m_ram_ptr[offset & 0x0fff] = data;
1512      }
14911513   }
1514}
1515
1516/*****************************************************************************
1517    Cartridge type: SuperSpace II
1518
1519    SuperSpace is intended as a user-definable blank cartridge containing
1520    buffered RAM. It has an Editor/Assembler GROM which helps the user to load
1521    the user program into the cartridge. If the user program has a suitable
1522    header, the console recognizes the cartridge as runnable, and
1523    assigns a number in the selection screen. Switching the RAM banks in this
1524    cartridge is achieved by setting CRU bits (the system serial interface).
1525
1526    GROM:           Editor/Assembler GROM
1527    ROM:            none
1528    persistent RAM: 32 KiB (0x6000-0x7fff, 4 banks)
1529    Banking:        via CRU write
1530******************************************************************************/
1531
1532/* Read function for the super cartridge. */
1533READ8Z_MEMBER(ti99_super_cartridge::readz)
1534{
1535   if ((offset & GROM_MASK)==GROM_AREA)
1536      gromreadz(space, offset, value, mem_mask);
14921537   else
14931538   {
1494      if (slot < m_numcart && m_cartridge[slot]->is_available())
1539      if (m_ram_ptr != NULL)
14951540      {
1496         //      LOG("try it on slot %d\n", slot);
1497         m_cartridge[slot]->write(space, offset, data, mem_mask);
1541         *value = m_ram_ptr[(m_ram_page << 13) | (offset & 0x1fff)];
14981542      }
14991543   }
15001544}
15011545
1502/*
1503    Called from the cartriges.
1504*/
1505WRITE_LINE_MEMBER(gromport_device::ready_line)
1546/* Write function for the super cartridge. */
1547WRITE8_MEMBER(ti99_super_cartridge::write)
15061548{
1507   m_ready(state);
1549   if ((offset & GROM_MASK)==GROM_AREA)
1550      gromwrite(space, offset, data, mem_mask);
1551   else
1552   {
1553      m_ram_ptr[(m_ram_page << 13) | (offset & 0x1fff)] = data;
1554   }
15081555}
15091556
1510/****************************************************
1511    CRU interface
1512****************************************************/
1513void gromport_device::crureadz(offs_t offset, UINT8 *value)
1557void ti99_super_cartridge::crureadz(offs_t offset, UINT8 *value)
15141558{
1515   // GRAMKracker support
1516   if ((m_gk_slot != -1) /* && (ioport("CARTSLOT")==CART_GK)*/)
1517   {
1518      m_cartridge[m_gk_slot]->crureadz(offset, value);
1519      return;
1520   }
1559   // offset is the bit number. The CRU base address is already divided  by 2.
15211560
1522   int slot = get_active_slot(false, offset);
1561   // ram_page contains the bank number. We have a maximum of
1562   // 4 banks; the Super Space II manual says:
1563   //
1564   // Banks are selected by writing a bit pattern to CRU address >0800:
1565   //
1566   // Bank #   Value
1567   // 0        >02  = 0000 0010
1568   // 1        >08  = 0000 1000
1569   // 2        >20  = 0010 0000
1570   // 3        >80  = 1000 0000
1571   //
1572   // With the bank number (0, 1, 2, or 3) in R0:
1573   //
1574   // BNKSW   LI    R12,>0800   Set CRU address
1575   //         LI    R1,2        Load Shift Bit
1576   //         SLA   R0,1        Align Bank Number
1577   //         JEQ   BNKS1       Skip shift if Bank 0
1578   //         SLA   R1,0        Align Shift Bit
1579   // BNKS1   LDCR  R1,0        Switch Banks
1580   //         SRL   R0,1        Restore Bank Number (optional)
1581   //         RT
15231582
1524   /* Sanity check. Higher slots are always empty. */
1525   if (slot >= m_numcart)
1526      return;
1583   // Our implementation in MESS always gets 8 bits in one go. Also, the address
1584   // is twice the bit number. That is, the offset value is always a multiple
1585   // of 0x10.
15271586
1528   if (m_cartridge[slot]->is_available())
1587   if ((offset & 0xfff0) == 0x0800)
15291588   {
1530      m_cartridge[slot]->crureadz(offset, value);
1589      if (VERBOSE>2) LOG("ti99_super_cartridge: CRU accessed at %04x\n", offset);
1590      UINT8 val = 0x02 << (m_ram_page << 1);
1591      *value = (val >> ((offset - 0x0800)>>1)) & 0xff;
15311592   }
15321593}
15331594
1534void gromport_device::cruwrite(offs_t offset, UINT8 data)
1595void ti99_super_cartridge::cruwrite(offs_t offset, UINT8 data)
15351596{
1536   // GRAMKracker support
1537   if ((m_gk_slot != -1) /*&& (ioport("CARTSLOT")==CART_GK)*/)
1597   if ((offset & 0xfff0) == 0x0800)
15381598   {
1539      m_cartridge[m_gk_slot]->cruwrite(offset, data);
1540      return;
1599      if (VERBOSE>2) LOG("ti99_super_cartridge: CRU accessed at %04x\n", offset);
1600      if (data != 0)
1601         m_ram_page = (offset-0x0802)>>2;
15411602   }
1603}
15421604
1543   int slot = get_active_slot(true, offset);
1605/*****************************************************************************
1606  Cartridge type: MBX
1607    GROM: up to 40 KiB
1608    ROM: up to 16 KiB (in up to 2 banks of 8KiB each)
1609    RAM: 1022 B (0x6c00-0x6ffd, overrides ROM in that area)
1610    ROM mapper: 6ffe
15441611
1545   /* Sanity check. Higher slots are always empty. */
1546   if (slot >= m_numcart)
1547      return;
1612    TODO: Some MBX cartridges assume the presence of the MBX system
1613    (special user interface box with speech input/output)
1614    and will not run without it. This MBX hardware is not emulated yet.
1615******************************************************************************/
15481616
1549   if (m_cartridge[slot]->is_available())
1617/* Read function for the mbx cartridge. */
1618READ8Z_MEMBER(ti99_mbx_cartridge::readz)
1619{
1620   if ((offset & GROM_MASK)==GROM_AREA)
1621      gromreadz(space, offset, value, mem_mask);
1622   else
15501623   {
1551      m_cartridge[slot]->cruwrite(offset, data);
1624      if ((offset & 0x1c00)==0x0c00)
1625      {
1626         // This is the RAM area which overrides any ROM. There is no
1627         // known banking behavior for the RAM, so we must assume that
1628         // there is only one bank.
1629         if (m_ram_ptr != NULL)
1630            *value = m_ram_ptr[offset & 0x03ff];
1631      }
1632      else
1633      {
1634         if (m_rom_ptr!=NULL)
1635            *value = m_rom_ptr[(offset & 0x1fff) | (m_rom_page<<13)];
1636      }
15521637   }
15531638}
15541639
1555/****************************************************
1556    Device management
1557****************************************************/
1558void gromport_device::device_start(void)
1640/* Write function for the mbx cartridge. */
1641WRITE8_MEMBER(ti99_mbx_cartridge::write)
15591642{
1560   // Resolve the callback line
1561   const gromport_config *intf = reinterpret_cast<const gromport_config *>(static_config());
1562   m_ready.resolve(intf->ready, *this);
1643   if ((offset & GROM_MASK)==GROM_AREA)
1644      gromwrite(space, offset, data, mem_mask);
1645   else
1646   {
1647      if (offset == 0x6ffe)
1648      {
1649         m_rom_page = data & 1;
1650         return;
1651      }
15631652
1564   // Add the cartridges to the list
1565   device_iterator *iter = new device_iterator(*this, 1);
1653      if ((offset & 0x1c00)==0x0c00)
1654      {
1655         if (m_ram_ptr == NULL) return;
1656         m_ram_ptr[offset & 0x03ff] = data;
1657      }
1658   }
1659}
15661660
1567   int i = 0;
1568   cartridge_device *cart = static_cast<cartridge_device*>(iter->first());
1661/*****************************************************************************
1662  Cartridge type: paged379i
1663    This cartridge consists of one 16 KiB, 32 KiB, 64 KiB, or 128 KiB EEPROM
1664    which is organised in 2, 4, 8, or 16 pages of 8 KiB each. The complete
1665    memory contents must be stored in one dump file.
1666    The pages are selected by writing a value to some memory locations. Due to
1667    using the inverted outputs of the LS379 latch, setting the inputs of the
1668    latch to all 0 selects the highest bank, while setting to all 1 selects the
1669    lowest. There are some cartridges (16 KiB) which are using this scheme, and
1670    there are new hardware developments mainly relying on this scheme.
15691671
1570   // Skip the first node (it's the gromport)
1571   cart = static_cast<cartridge_device*>(iter->next());
1572   while (cart != NULL)
1672    Writing to       selects page (16K/32K/64K/128K)
1673    >6000            1 / 3 / 7 / 15
1674    >6002            0 / 2 / 6 / 14
1675    >6004            1 / 1 / 5 / 13
1676    >6006            0 / 0 / 4 / 12
1677    >6008            1 / 3 / 3 / 11
1678    >600A            0 / 2 / 2 / 10
1679    >600C            1 / 1 / 1 / 9
1680    >600E            0 / 0 / 0 / 8
1681    >6010            1 / 3 / 7 / 7
1682    >6012            0 / 2 / 6 / 6
1683    >6014            1 / 1 / 5 / 5
1684    >6016            0 / 0 / 4 / 4
1685    >6018            1 / 3 / 3 / 3
1686    >601A            0 / 2 / 2 / 2
1687    >601C            1 / 1 / 1 / 1
1688    >601E            0 / 0 / 0 / 0
1689
1690    The paged379i cartrige does not have any GROMs.
1691******************************************************************************/
1692
1693/*
1694    Determines which bank to set, depending on the size of the ROM. This is
1695    some magic code that actually represents different PCB versions.
1696*/
1697int ti99_paged379i_cartridge::get_paged379i_bank(int rompage)
1698{
1699   int mask = 0;
1700   if (m_rom_size > 16384)
15731701   {
1574      m_cartridge[i++] = cart;
1575      // LOG("tag = %s\n", cart->tag());
1576      cart = static_cast<cartridge_device*>(iter->next());
1702      if (m_rom_size > 32768)
1703      {
1704         if (m_rom_size > 65536)
1705            mask = 15;
1706         else
1707            mask = 7;
1708      }
1709      else
1710         mask = 3;
15771711   }
1578   m_numcart = i;
1579   m_next_free_slot = 0;
1580   m_active_slot = 0;
1581}
1712   else
1713      mask = 1;
15821714
1583void gromport_device::device_stop(void)
1584{
1715   return rompage & mask;
15851716}
15861717
1587void gromport_device::device_reset(void)
1718
1719/* Read function for the paged379i cartridge. */
1720READ8Z_MEMBER(ti99_paged379i_cartridge::readz)
15881721{
1589   m_active_slot = 0;
1590   m_fixed_slot = ioport("CARTSLOT")->read() - 1;
1722   if ((offset & 0xe000)==0x6000)
1723      *value = m_rom_ptr[(m_rom_page<<13) | (offset & 0x1fff)];
15911724}
15921725
1593INPUT_CHANGED_MEMBER( gromport_device::gk_changed )
1726/* Write function for the paged379i cartridge. Only used to set the bank. */
1727WRITE8_MEMBER(ti99_paged379i_cartridge::write)
15941728{
1595   if (VERBOSE>7) LOG("gromport: input changed %d - %d\n", (int)((UINT64)param & 0x07), newval);
1596   if (m_gk_slot != -1)
1729   // Bits: 0110 0000 000b bbbx
1730   // x = don't care, bbbb = bank
1731   if ((offset & 0xffe0)==0x6000)
15971732   {
1598      m_cartridge[m_gk_slot]->set_switch((UINT64)param & 0x07, newval); // param is a pointer type
1733      // Set bank
1734      m_rom_page = get_paged379i_bank(15 - ((offset>>1) & 15));
15991735   }
16001736}
16011737
1602INPUT_PORTS_START(gromport_device)
1603   PORT_START( "CARTSLOT" )
1604   PORT_DIPNAME( 0x0f, 0x00, "Multi-cartridge slot" )
1605      PORT_DIPSETTING(    0x00, "Auto" )
1606      PORT_DIPSETTING(    0x01, "Slot 1" )
1607      PORT_DIPSETTING(    0x02, "Slot 2" )
1608      PORT_DIPSETTING(    0x03, "Slot 3" )
1609      PORT_DIPSETTING(    0x04, "Slot 4" )
1610      PORT_DIPSETTING(    0x0f, "GRAM Kracker" )
1738/*****************************************************************************
1739  Cartridge type: pagedcru
1740    This cartridge consists of one 16 KiB, 32 KiB, or 64 KiB EEPROM which is
1741    organised in 2, 4, or 8 pages of 8 KiB each. We assume there is only one
1742    dump file of the respective size.
1743    The pages are selected by writing a value to the CRU. This scheme is
1744    similar to the one used for the SuperSpace cartridge, with the exception
1745    that we are using ROM only, and we can have up to 8 pages.
16111746
1612   PORT_START( GKSWITCH1_TAG )
1613   PORT_DIPNAME( 0x01, 0x01, "GK switch 1" ) PORT_CONDITION( "CARTSLOT", 0x0f, EQUALS, 0x0f ) PORT_CHANGED_MEMBER(DEVICE_SELF, gromport_device, gk_changed, 1)
1614      PORT_DIPSETTING(    0x00, "GK Off" )
1615      PORT_DIPSETTING(    0x01, DEF_STR( Normal ) )
1747    Bank     Value written to CRU>0800
1748    0      >0002  = 0000 0000 0000 0010
1749    1      >0008  = 0000 0000 0000 1000
1750    2      >0020  = 0000 0000 0010 0000
1751    3      >0080  = 0000 0000 1000 0000
1752    4      >0200  = 0000 0010 0000 0000
1753    5      >0800  = 0000 1000 0000 0000
1754    6      >2000  = 0010 0000 0000 0000
1755    7      >8000  = 1000 0000 0000 0000
16161756
1617   PORT_START( GKSWITCH2_TAG )
1618   PORT_DIPNAME( 0x01, 0x01, "GK switch 2" ) PORT_CONDITION( "CARTSLOT", 0x0f, EQUALS, 0x0f ) PORT_CHANGED_MEMBER(DEVICE_SELF, gromport_device, gk_changed, 2)
1619      PORT_DIPSETTING(    0x00, "GRAM 0" )
1620      PORT_DIPSETTING(    0x01, "Op Sys" )
1757    No GROMs used in this type.
1758******************************************************************************/
16211759
1622   PORT_START( GKSWITCH3_TAG )
1623   PORT_DIPNAME( 0x01, 0x01, "GK switch 3" ) PORT_CONDITION( "CARTSLOT", 0x0f, EQUALS, 0x0f ) PORT_CHANGED_MEMBER(DEVICE_SELF, gromport_device, gk_changed, 3)
1624      PORT_DIPSETTING(    0x00, "GRAM 1-2" )
1625      PORT_DIPSETTING(    0x01, "TI BASIC" )
1760/* Read function for the pagedcru cartridge. */
1761READ8Z_MEMBER(ti99_pagedcru_cartridge::readz)
1762{
1763   if ((offset & 0xe000)==0x6000)
1764      *value = m_rom_ptr[(m_rom_page<<13) | (offset & 0x1fff)];
1765}
16261766
1627   PORT_START( GKSWITCH4_TAG )
1628   PORT_DIPNAME( 0x03, 0x01, "GK switch 4" ) PORT_CONDITION( "CARTSLOT", 0x0f, EQUALS, 0x0f ) PORT_CHANGED_MEMBER(DEVICE_SELF, gromport_device, gk_changed, 4)
1629      PORT_DIPSETTING(    0x00, "Bank 1" )
1630      PORT_DIPSETTING(    0x01, "W/P" )
1631      PORT_DIPSETTING(    0x02, "Bank 2" )
1767/* Write function for the pagedcru cartridge. No effect. */
1768WRITE8_MEMBER(ti99_pagedcru_cartridge::write)
1769{
1770   return;
1771}
16321772
1633   PORT_START( GKSWITCH5_TAG )
1634   PORT_DIPNAME( 0x01, 0x00, "GK switch 5" ) PORT_CONDITION( "CARTSLOT", 0x0f, EQUALS, 0x0f ) PORT_CHANGED_MEMBER(DEVICE_SELF, gromport_device, gk_changed, 5)
1635      PORT_DIPSETTING(    0x00, "Loader On" )
1636      PORT_DIPSETTING(    0x01, "Loader Off" )
1637INPUT_PORTS_END
1638
1639static MACHINE_CONFIG_FRAGMENT(gromport_device)
1640   MCFG_DEVICE_ADD("cartridge1", TICARTRIDGE, 0)
1641   MCFG_DEVICE_ADD("cartridge2", TICARTRIDGE, 0)
1642   MCFG_DEVICE_ADD("cartridge3", TICARTRIDGE, 0)
1643   MCFG_DEVICE_ADD("cartridge4", TICARTRIDGE, 0)
1644MACHINE_CONFIG_END
1645
1646machine_config_constructor gromport_device::device_mconfig_additions() const
1773void ti99_pagedcru_cartridge::crureadz(offs_t offset, UINT8 *value)
16471774{
1648   return MACHINE_CONFIG_NAME( gromport_device );
1775   int page = m_rom_page;
1776   if ((offset & 0xf800)==0x0800)
1777   {
1778      int bit = (offset & 0x001e)>>1;
1779      if (bit != 0)
1780      {
1781         page = page-(bit/2);  // 4 page flags per 8 bits
1782      }
1783      *value = 1 << (page*2+1);
1784   }
16491785}
16501786
1651ioport_constructor gromport_device::device_input_ports() const
1787void ti99_pagedcru_cartridge::cruwrite(offs_t offset, UINT8 data)
16521788{
1653   return INPUT_PORTS_NAME(gromport_device);
1789   if ((offset & 0xf800)==0x0800)
1790   {
1791      int bit = (offset & 0x001e)>>1;
1792      if (data != 0 && bit > 0)
1793      {
1794         m_rom_page = (bit-1)/2;
1795      }
1796   }
16541797}
16551798
1656const device_type GROMPORT = &device_creator<gromport_device>;
1657const device_type TICARTRIDGE = &device_creator<cartridge_device>;
1799/****************************************************************************
16581800
1659const device_type TICARTPCBSTD = &device_creator<cartridge_pcb_standard_device>;
1660const device_type TICARTPCBPAG = &device_creator<cartridge_pcb_paged_device>;
1661const device_type TICARTPCBMIN = &device_creator<cartridge_pcb_minimem_device>;
1662const device_type TICARTPCBSUP = &device_creator<cartridge_pcb_superspace_device>;
1663const device_type TICARTPCBMBX = &device_creator<cartridge_pcb_mbx_device>;
1664const device_type TICARTPCBPGI = &device_creator<cartridge_pcb_paged379i_device>;
1665const device_type TICARTPCBPGC = &device_creator<cartridge_pcb_pagedcru_device>;
1666const device_type TICARTPCBGRK = &device_creator<cartridge_pcb_gramkracker_device>;
1801    RPK loader
16671802
1668/*****************************************************************************************************************
1669******************************************************************************************************************
1670RPK format support
1803    RPK format support
16711804
16721805    A RPK file ("rompack") contains a collection of dump files and a layout
16731806    file that defines the kind of circuit board (PCB) used in the cartridge
r15583r15584
17281861
17291862rpk::~rpk()
17301863{
1731   if (VERBOSE>6) LOG("Destroy RPK\n");
1864   if (VERBOSE>6) LOG("rpk: Destroy RPK\n");
17321865}
17331866
17341867/*
r15583r15584
20982231
20992232   return newrpk;
21002233}
2234
src/mess/machine/ti99/gromport.h
r15583r15584
1/*********************************************************************
1/***************************************************************************
2    Gromport of the TI-99 consoles
23
3    gromport.h
4    See grompoprt.c for documentation
4    For details see gromport.c
55
6    Michael Zapf
6    Michael Zapf, July 2012
7***************************************************************************/
78
8    February 2012: Rewritten as class
9#ifndef __GROMPORT__
10#define __GROMPORT__
911
10*********************************************************************/
11
12#ifndef __TI99CART_H__
13#define __TI99CART_H__
14
1512#include "emu.h"
1613#include "ti99defs.h"
1714#include "grom.h"
18#include "image.h"
1915
2016extern const device_type GROMPORT;
21extern const device_type TICARTRIDGE;
22extern const device_type TICARTPCBSTD;
23extern const device_type TICARTPCBPAG;
24extern const device_type TICARTPCBMIN;
25extern const device_type TICARTPCBSUP;
26extern const device_type TICARTPCBMBX;
27extern const device_type TICARTPCBPGI;
28extern const device_type TICARTPCBPGC;
29extern const device_type TICARTPCBGRK;
3017
31/* We set the number of slots to 4, although we may have up to 16. From a
32   logical point of view we could have 256, but the operating system only checks
33   the first 16 banks. */
34#define NUMBER_OF_CARTRIDGE_SLOTS 4
35
3618#define GROMPORT_CONFIG(name) \
3719   const gromport_config(name) =
3820
3921typedef struct _gromport_config
4022{
4123   devcb_write_line   ready;
24   devcb_write_line   reset;
4225} gromport_config;
4326
44class cartridge_pcb_device;
27class ti99_cartridge_connector_device;
28
29class gromport_device : public bus8z_device, public device_slot_interface
30{
31public:
32   gromport_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
33   DECLARE_READ8Z_MEMBER(readz);
34   DECLARE_WRITE8_MEMBER(write);
35   void crureadz(offs_t offset, UINT8 *value);
36   void cruwrite(offs_t offset, UINT8 data);
37   DECLARE_WRITE_LINE_MEMBER(ready_line);
38
39   void   cartridge_inserted();
40
41protected:
42   void device_start();
43   void device_reset();
44   void device_config_complete();
45   ioport_constructor device_input_ports() const;
46
47private:
48   ti99_cartridge_connector_device*   m_connector;
49   bool m_reset_on_insert;
50   devcb_resolved_write_line m_console_reset;
51   devcb_resolved_write_line m_console_ready;
52};
53
54SLOT_INTERFACE_EXTERN(gromport);
55
56#define MCFG_TI99_GROMPORT_ADD( _tag, _conf )   \
57   MCFG_DEVICE_ADD(_tag, GROMPORT, 0) \
58   MCFG_DEVICE_CONFIG(_conf)   \
59   MCFG_DEVICE_SLOT_INTERFACE(gromport, "single", NULL, false)
60
61/****************************************************************************/
62
4563class rpk;
64class ti99_cartridge_pcb;
4665
47/*****************************************************************************
48    The base class of a cartridge
49    Cartridges are implemented as subdevices of the cartridge slot. They
50    are always present as devices, irrespective of the fact that they are
51    plugged in. Plugging in, however, means that there is a PCB and sizes
52    for ROM or RAM.
53*****************************************************************************/
54class cartridge_device : public bus8z_device, public device_image_interface
66class ti99_cartridge_device : public bus8z_device, public device_image_interface
5567{
56   friend class gromport_device;
57   friend class cartridge_pcb_device;
58
5968public:
60   cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
69   ti99_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
6170
6271   DECLARE_READ8Z_MEMBER(readz);
6372   DECLARE_WRITE8_MEMBER(write);
73   void   crureadz(offs_t offset, UINT8 *value);
74   void   cruwrite(offs_t offset, UINT8 data);
75   void   ready_line(int state);
76   bool   is_available() { return m_pcb != NULL; }
77   bool   has_grom();
78   void   set_slot(int i);
6479
65   bool is_available() { return m_pcb != NULL; }
66   bool has_grom();
67   void set_switch(int swtch, int val);   // forwarding to GK
80protected:
81   void device_start() { };
82   void device_config_complete();
83   machine_config_constructor device_mconfig_additions() const;
84   const rom_entry* device_rom_region() const;
6885
69   virtual void crureadz(offs_t offset, UINT8 *value);
70   virtual void cruwrite(offs_t offset, UINT8 data);
71
7286   // Image handling: implementation of methods which are abstract in the parent
7387   bool call_load();
7488   void call_unload();
7589   bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry);
7690
91   void prepare_cartridge();
92
93   // device_image_interface
7794   iodevice_t image_type() const { return IO_CARTSLOT; }
7895   bool is_readable()  const         { return true; }
7996   bool is_writeable() const         { return false; }
r15583r15584
83100   const char *image_interface() const { return "ti99_cart"; }
84101   const char *file_extensions() const { return "rpk"; }
85102   const option_guide *create_option_guide() const { return NULL; }
86   machine_config_constructor device_mconfig_additions() const;
87103
88protected:
89   void device_start(void);
90   void device_stop(void);
91   void device_reset(void);
92   void device_config_complete(void);
93   const rom_entry *device_rom_region() const;
94
95104private:
96   bool has_extension(const char* name);
97   void prepare_cartridge();
98   int get_index_from_tagname();
99   UINT8* get_grom_ptr();
100   void set_gk_guest(cartridge_device *guest);
105   bool   m_softlist;
106   int    m_pcbtype;
107   int    m_slot;
108   int    get_index_from_tagname();
101109
102   int m_type;
110   ti99_cartridge_pcb*               m_pcb;         // inbound
111   ti99_cartridge_connector_device*   m_connector;   // outbound
103112
104   // PCB device associated to this cartridge. If NULL, the slot is empty.
105   cartridge_pcb_device *m_pcb;
106
107113   // RPK which is associated to this cartridge
114   // When we close it, the contents are saved to NVRAM if available
108115   rpk   *m_rpk;
109
110   // If we are using softlists
111   bool m_softlist;
112116};
113117
114/*****************************************************************************
115    The class of a cartridge PCB
116*****************************************************************************/
118extern const device_type TI99CART;
117119
118class cartridge_pcb_device : public bus8z_device
120/****************************************************************************/
121
122class ti99_cartridge_connector_device : public bus8z_device
119123{
120   friend class cartridge_device;
121   friend class gromport_device;
122
123124public:
124   cartridge_pcb_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
125
126125   virtual DECLARE_READ8Z_MEMBER(readz) =0;
127126   virtual DECLARE_WRITE8_MEMBER(write) =0;
127   virtual void crureadz(offs_t offset, UINT8 *value) =0;
128   virtual void cruwrite(offs_t offset, UINT8 data) =0;
129   void ready_line(int state);
128130
129   /* Read function for this cartridge, CRU. */
130   virtual void crureadz(offs_t offset, UINT8 *value);
131   virtual void insert(int index, ti99_cartridge_device* cart) { m_gromport->cartridge_inserted(); };
132   virtual void remove(int index) { };
131133
132   /* Write function for this cartridge, CRU. */
133   virtual void cruwrite(offs_t offset, UINT8 data);
134protected:
135   ti99_cartridge_connector_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
136   gromport_device*   m_gromport;
137};
134138
139/*
140    Single cartridge connector.
141*/
142class single_conn_device : public ti99_cartridge_connector_device
143{
144public:
145   single_conn_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
146
147   DECLARE_READ8Z_MEMBER(readz);
148   DECLARE_WRITE8_MEMBER(write);
149   void crureadz(offs_t offset, UINT8 *value);
150   void cruwrite(offs_t offset, UINT8 data);
151
135152protected:
136   void device_start(void);
137   DECLARE_READ8Z_MEMBER( gromreadz );
138   DECLARE_WRITE8_MEMBER( gromwrite );
139   void set_gk_guest(int slot);
153   void device_start() { };
154   void device_reset();
155   machine_config_constructor device_mconfig_additions() const;
156   void device_config_complete();
140157
141   /* Points to the (max 5) GROM devices. */
142   ti99_grom_device *m_grom[5];
158private:
159   ti99_cartridge_device *m_cartridge;
160};
143161
144   // ROM buffer.
145   UINT8 *m_rom_ptr;
162/*
163    Multi cartridge connector.
164*/
146165
147   // ROM buffer for the second bank of paged cartridges.
148   UINT8 *m_rom2_ptr;
166/* We set the number of slots to 4, although we may have up to 16. From a
167   logical point of view we could have 256, but the operating system only checks
168   the first 16 banks. */
169#define NUMBER_OF_CARTRIDGE_SLOTS 4
149170
150   // RAM buffer. The persistence service is done by the cartridge system.
151   // The RAM space is a consecutive space; all banks are in one buffer.
152   UINT8 *m_ram_ptr;
171class multi_conn_device : public ti99_cartridge_connector_device
172{
173public:
174   multi_conn_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
153175
154   // ROM page.
155   int m_rom_page;
176   DECLARE_READ8Z_MEMBER(readz);
177   DECLARE_WRITE8_MEMBER(write);
178   void crureadz(offs_t offset, UINT8 *value);
179   void cruwrite(offs_t offset, UINT8 data);
156180
157   // RAM page.
158   int m_ram_page;
181   void insert(int index, ti99_cartridge_device* cart);
182   void remove(int index);
159183
160   // GROM buffer size. Depends of the size of the resource loaded into "grom_socket".
161   int m_grom_size;
184protected:
185   void device_start();
186   void device_reset();
187   machine_config_constructor device_mconfig_additions() const;
188   ioport_constructor device_input_ports() const;
162189
163   // ROM buffer size. All banks have equal sizes.
164   int m_rom_size;
190private:
191   int      m_active_slot;
192   int      m_fixed_slot;
193   int      m_next_free_slot;
194   int      m_numcart;
195   ti99_cartridge_device*   m_cartridge[NUMBER_OF_CARTRIDGE_SLOTS];
165196
166   // RAM buffer size. All banks have equal sizes.
167   int m_ram_size;
197   void   set_slot(int slotnumber);
198   int    get_active_slot(bool changebase, offs_t offset);
199   void   change_slot(bool inserted, int index);
168200};
169201
170class cartridge_pcb_standard_device : public cartridge_pcb_device
202/*
203    GRAM Kracker.
204*/
205class gkracker_device : public ti99_cartridge_connector_device, public device_nvram_interface
171206{
172207public:
173   cartridge_pcb_standard_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
208   gkracker_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
209
174210   DECLARE_READ8Z_MEMBER(readz);
175211   DECLARE_WRITE8_MEMBER(write);
212   void crureadz(offs_t offset, UINT8 *value);
213   void cruwrite(offs_t offset, UINT8 data);
214
215   void insert(int index, ti99_cartridge_device* cart);
216   void remove(int index);
217   DECLARE_INPUT_CHANGED_MEMBER( gk_changed );
218
219protected:
220   void device_start();
221   void device_reset();
222
223   machine_config_constructor device_mconfig_additions() const;
224   const rom_entry* device_rom_region() const;
225   ioport_constructor device_input_ports() const;
226
227   // device_nvram_interface
228   void nvram_default();
229   void nvram_read(emu_file &file);
230   void nvram_write(emu_file &file);
231
232private:
233   int    m_gk_switch[6];         // Used to cache the switch settings.
234
235   int      m_ram_page;
236   int      m_grom_address;
237   UINT8*   m_ram_ptr;
238   UINT8*   m_grom_ptr;
239
240   bool   m_waddr_LSB;
241
242   ti99_cartridge_device *m_cartridge;      // guest cartridge
243
244   // Just for proper initialization
245   void gk_install_menu(const char* menutext, int len, int ptr, int next, int start);
176246};
177247
178class cartridge_pcb_paged_device : public cartridge_pcb_device
248extern const device_type GROMPORT_SINGLE;
249extern const device_type GROMPORT_MULTI;
250extern const device_type GROMPORT_GK;
251
252/****************************************************************************/
253
254class ti99_cartridge_pcb
179255{
256   friend class ti99_cartridge_device;
180257public:
181   cartridge_pcb_paged_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
182   DECLARE_READ8Z_MEMBER(readz);
183   DECLARE_WRITE8_MEMBER(write);
258   ti99_cartridge_pcb();
259
260protected:
261   virtual DECLARE_READ8Z_MEMBER(readz);
262   virtual DECLARE_WRITE8_MEMBER(write);
263   virtual void   crureadz(offs_t offset, UINT8 *value);
264   virtual void   cruwrite(offs_t offset, UINT8 data);
265
266   DECLARE_READ8Z_MEMBER(gromreadz);
267   DECLARE_WRITE8_MEMBER(gromwrite);
268   inline void       set_grom_pointer(int number, device_t *dev);
269
270   ti99_grom_device*   m_grom[5];
271   int               m_grom_size;
272   int               m_rom_size;
273   int               m_ram_size;
274
275   UINT8*            m_rom_ptr;
276   UINT8*            m_rom2_ptr;
277   UINT8*            m_ram_ptr;
278
279private:
184280};
185281
186class cartridge_pcb_minimem_device : public cartridge_pcb_device
282/******************** Standard cartridge ******************************/
283
284class ti99_standard_cartridge : public ti99_cartridge_pcb
187285{
188public:
189   cartridge_pcb_minimem_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
190   DECLARE_READ8Z_MEMBER(readz);
191   DECLARE_WRITE8_MEMBER(write);
192286};
193287
194class cartridge_pcb_superspace_device : public cartridge_pcb_device
288/*********** Paged cartridge (like Extended Basic) ********************/
289
290class ti99_paged_cartridge : public ti99_cartridge_pcb
195291{
196292public:
197   cartridge_pcb_superspace_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
198293   DECLARE_READ8Z_MEMBER(readz);
199294   DECLARE_WRITE8_MEMBER(write);
200   void crureadz(offs_t offset, UINT8 *value);
201   void cruwrite(offs_t offset, UINT8 data);
295
296private:
297   int    m_rom_page;
202298};
203299
204class cartridge_pcb_mbx_device : public cartridge_pcb_device
300/********************** Mini Memory ***********************************/
301
302class ti99_minimem_cartridge : public ti99_cartridge_pcb
205303{
206304public:
207   cartridge_pcb_mbx_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
208305   DECLARE_READ8Z_MEMBER(readz);
209306   DECLARE_WRITE8_MEMBER(write);
210307};
211308
212class cartridge_pcb_paged379i_device : public cartridge_pcb_device
309/********************* Super Space II *********************************/
310
311class ti99_super_cartridge : public ti99_cartridge_pcb
213312{
214313public:
215   cartridge_pcb_paged379i_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
216314   DECLARE_READ8Z_MEMBER(readz);
217315   DECLARE_WRITE8_MEMBER(write);
316   void   crureadz(offs_t offset, UINT8 *value);
317   void   cruwrite(offs_t offset, UINT8 data);
318
218319private:
219   int get_paged379i_bank(int rompage);
320   int      m_ram_page;
220321};
221322
222class cartridge_pcb_pagedcru_device : public cartridge_pcb_device
323/************************* MBX  ***************************************/
324
325class ti99_mbx_cartridge : public ti99_cartridge_pcb
223326{
224327public:
225   cartridge_pcb_pagedcru_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
226328   DECLARE_READ8Z_MEMBER(readz);
227329   DECLARE_WRITE8_MEMBER(write);
228   void crureadz(offs_t offset, UINT8 *value);
229   void cruwrite(offs_t offset, UINT8 data);
330private:
331   int    m_rom_page;
230332};
231333
232class cartridge_pcb_gramkracker_device : public cartridge_pcb_device
334/********************** Paged 379i ************************************/
335
336class ti99_paged379i_cartridge : public ti99_cartridge_pcb
233337{
234   friend class cartridge_device;
235
236338public:
237   cartridge_pcb_gramkracker_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
238339   DECLARE_READ8Z_MEMBER(readz);
239340   DECLARE_WRITE8_MEMBER(write);
240   void crureadz(offs_t offset, UINT8 *value);
241   void cruwrite(offs_t offset, UINT8 data);
242
243   void set_gk_guest(cartridge_device *guest);
244   void set_switch(int swtch, int val);
245
246341private:
247   // GROM emulation in GK
248   bool   m_waddr_LSB;
249   UINT16   m_grom_address;
250   UINT8*   m_grom_ptr;
251
252   int    m_gk_switch[6];         // Used to cache the switch settings.
253
254   // GRAMKracker guest slot
255   cartridge_device *m_gk_guest;
342   int    get_paged379i_bank(int rompage);
343   int    m_rom_page;
256344};
257345
258/*****************************************************************************
259    The overall cartridge system
260*****************************************************************************/
346/********************** Paged CRU  ************************************/
261347
262class gromport_device : public bus8z_device
348class ti99_pagedcru_cartridge : public ti99_cartridge_pcb
263349{
264   friend class cartridge_device;
265
266350public:
267   gromport_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
268351   DECLARE_READ8Z_MEMBER(readz);
269352   DECLARE_WRITE8_MEMBER(write);
270   DECLARE_WRITE_LINE_MEMBER(ready_line);
271
272   void crureadz(offs_t offset, UINT8 *value);
273   void cruwrite(offs_t offset, UINT8 value);
274
275   DECLARE_INPUT_CHANGED_MEMBER( gk_changed );
276
277protected:
278   void device_start(void);
279   void device_stop(void);
280   void device_reset(void);
281   machine_config_constructor device_mconfig_additions() const;
282   ioport_constructor device_input_ports() const;
283
353   void   crureadz(offs_t offset, UINT8 *value);
354   void   cruwrite(offs_t offset, UINT8 data);
284355private:
285   void set_slot(int slot);
286   int get_active_slot(bool changebase, offs_t offset);
287   void change_slot(bool inserted, int index);
288   void set_gk_slot(int slot);
289   void find_gk_guest();
290   void crureadz_gk(offs_t offset, UINT8 *value);
291   void cruwrite_gk(offs_t offset, UINT8 value);
356   int    m_rom_page;
357};
292358
293   // Points to all cartridges. This is faster than iterating the list
294   // of subdevices on each memory access.
295   cartridge_device*   m_cartridge[NUMBER_OF_CARTRIDGE_SLOTS];
296359
297   // Number of available cartridge positions
298   int    m_numcart;
299
300   // Determines which slot is currently active. This value is changed when
301   // there are accesses to other GROM base addresses.
302   int    m_active_slot;
303
304   // Used in order to enforce a special slot. This value is retrieved
305   // from the dipswitch setting. A value of -1 means automatic, that is,
306   // the grom base switch is used. Values 0 .. max refer to the
307   // respective slot.
308   int    m_fixed_slot;
309
310   // Holds the highest index of a cartridge being plugged in plus one.
311   // If we only have one cartridge inserted, we don't want to get a
312   // selection option, so we just mirror the memory contents.
313   int    m_next_free_slot;
314
315   /* GK support. */
316   int      m_gk_slot;
317
318   /* Ready line */
319   devcb_resolved_write_line m_ready;
320};
321
322360typedef struct _pcb_type
323361{
324362   int id;
r15583r15584
328366/*************************************************************************
329367    RPK support
330368*************************************************************************/
369class rpk;
331370
332371class rpk_socket
333372{
r15583r15584
359398   rpk_reader(const pcb_type *types)
360399   : m_types(types) { };
361400
362   rpk             *open(emu_options &options, const char *filename, const char *system_name);
401   rpk *open(emu_options &options, const char *filename, const char *system_name);
363402
364403private:
365404   const zip_file_header*   find_file(zip_file *zip, const char *filename, UINT32 crc);
r15583r15584
446485   const char* m_detail;
447486};
448487
449/*************************************************************************
450    Macros
451*************************************************************************/
452
453#define MCFG_TI99_GROMPORT_ADD(_tag, _intf) \
454   MCFG_DEVICE_ADD(_tag, GROMPORT, 0)   \
455   MCFG_DEVICE_CONFIG(_intf)
456
457#endif /* __TI99CART_H__ */
488#endif
src/mess/machine/ti99/videowrp.h
r15583r15584
1919
2020class ti_video_device : public bus8z_device
2121{
22public:
23   virtual void   reset_vdp(int state) =0;
24
2225protected:
2326   address_space   *m_space;
2427   tms9928a_device *m_tms9928a;
r15583r15584
4043   ti_std_video_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
4144   DECLARE_READ8Z_MEMBER(readz);
4245   DECLARE_WRITE8_MEMBER(write);
46
47   void   reset_vdp(int state) { m_tms9928a->reset_line(state); }
4348};
4449
4550/*
r15583r15584
5459   DECLARE_WRITE8_MEMBER(write);
5560   DECLARE_READ16_MEMBER(read16);
5661   DECLARE_WRITE16_MEMBER(write16);
62   void   reset_vdp(int state) { m_v9938->reset_line(state); }
5763
5864protected:
5965   void         device_start(void);
src/mess/machine/ti99/ti99defs.h
r15583r15584
1717#define TIBOARD_TAG    "ti_board"
1818#define DATAMUX_TAG    "datamux_16_8"
1919#define VIDEO_SYSTEM_TAG "video"
20#define V9938_SYSTEM_TAG "video9938"
2120#define SCREEN_TAG      "screen"
2221#define TISOUNDCHIP_TAG "soundchip"
2322#define TISOUND_TAG    "tisound"
src/mess/drivers/ti99_8.c
r15583r15584
232232   // Forwarding interrupts to the CPU or CRU
233233   DECLARE_WRITE_LINE_MEMBER( console_ready );
234234   DECLARE_WRITE_LINE_MEMBER( console_ready_mapper );
235   DECLARE_WRITE_LINE_MEMBER( console_reset );
235236
236237   DECLARE_WRITE_LINE_MEMBER( set_tms9901_INT2 );
237238   DECLARE_WRITE_LINE_MEMBER( extint );
r15583r15584
259260   peribox_device      *m_peribox;
260261   ti998_mapper_device   *m_mapper;
261262   joyport_device*    m_joyport;
263   ti_video_device*   m_video;
262264
263265   int    m_firstjoy;         // First joystick. 14 for TI-99/8
264266
r15583r15584
465467
466468static GROMPORT_CONFIG(console_cartslot)
467469{
468   DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready)
470   DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready),
471   DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_reset)
469472};
470473
471474static PERIBOX_CONFIG( peribox_conf )
r15583r15584
663666
664667WRITE8_MEMBER( ti99_8::tms9901_interrupt )
665668{
666   m_cpu->set_input_line(1, data);
669   m_cpu->set_input_line(INPUT_LINE_99XX_INT1, data);
667670}
668671
669672const tms9901_interface tms9901_wiring_ti99_8 =
r15583r15584
721724}
722725
723726/*
727    The RESET line leading to a reset of the CPU.
728*/
729WRITE_LINE_MEMBER( ti99_8::console_reset )
730{
731   if (machine().phase() != MACHINE_PHASE_INIT)
732   {
733      m_cpu->set_input_line(INPUT_LINE_99XX_RESET, state);
734      m_video->reset_vdp(state);
735   }
736}
737
738/*
724739    Memory access over the mapper also operates
725740    the READY line, and the mapper raises READY depending on the clock pulse.
726741    So we must make sure this does not interfere.
r15583r15584
915930   driver->m_peribox = static_cast<peribox_device*>(machine.device(PERIBOX_TAG));
916931   driver->m_mapper = static_cast<ti998_mapper_device*>(machine.device(MAPPER_TAG));
917932   driver->m_joyport = static_cast<joyport_device*>(machine.device(JOYPORT_TAG));
933   driver->m_video = static_cast<ti_video_device*>(machine.device(VIDEO_SYSTEM_TAG));
918934
919935   driver->m_peribox->senila(CLEAR_LINE);
920936   driver->m_peribox->senilb(CLEAR_LINE);
src/mess/drivers/geneve.c
r15583r15584
539539WRITE8_MEMBER( geneve::tms9901_interrupt )
540540{
541541   /* INTREQ is connected to INT1. */
542   device_execute(m_cpu)->set_input_line(1, data);
542   device_execute(m_cpu)->set_input_line(INPUT_LINE_99XX_INT1, data);
543543}
544544
545545/* tms9901 setup */
r15583r15584
583583{
584584   m_inta = (state!=0)? ASSERT_LINE : CLEAR_LINE;
585585   m_tms9901->set_single_int(1, state);
586   device_execute(m_cpu)->set_input_line(4, state);
586   device_execute(m_cpu)->set_input_line(INPUT_LINE_99XX_INT4, state);
587587}
588588
589589/*
src/mess/drivers/ti99_4p.c
r15583r15584
771771   // offset contains the interrupt level (0-15)
772772   // However, the TI board just ignores that level and hardwires it to 1
773773   // See below (interrupt_level)
774   m_cpu->set_input_line(0, data);
774   m_cpu->set_input_line(INPUT_LINE_99XX_INTREQ, data);
775775}
776776
777777READ8_MEMBER( ti99_4p::interrupt_level )
src/mess/drivers/ti99_4x.c
r15583r15584
7474   // Forwarding interrupts to the CPU or CRU
7575   DECLARE_WRITE_LINE_MEMBER( console_ready );
7676   DECLARE_WRITE_LINE_MEMBER( console_ready_dmux );
77   DECLARE_WRITE_LINE_MEMBER( console_reset );
7778
7879   DECLARE_WRITE_LINE_MEMBER( set_tms9901_INT2 );
7980   DECLARE_WRITE_LINE_MEMBER( set_tms9901_INT12 );
r15583r15584
9495   peribox_device*      m_peribox;
9596   joyport_device*    m_joyport;
9697   ti99_datamux_device* m_datamux;
98   ti_video_device*   m_video;
9799
98100   int      m_ready_line, m_ready_line_dmux;
99101
r15583r15584
319321
320322static GROMPORT_CONFIG(console_cartslot)
321323{
322   DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready)
324   DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready),
325   DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_reset)
323326};
324327
325328static PERIBOX_CONFIG( peribox_conf )
r15583r15584
566569   // offset contains the interrupt level (0-15)
567570   // However, the TI board just ignores that level and hardwires it to 1
568571   // See below (interrupt_level)
569   m_cpu->set_input_line(0, data);
572   m_cpu->set_input_line(INPUT_LINE_99XX_INTREQ, data);
570573}
571574
572575READ8_MEMBER( ti99_4x::interrupt_level )
r15583r15584
641644}
642645
643646/*
647    The RESET line leading to a reset of the CPU.
648*/
649WRITE_LINE_MEMBER( ti99_4x::console_reset )
650{
651   if (machine().phase() != MACHINE_PHASE_INIT)
652   {
653      m_cpu->set_input_line(INPUT_LINE_99XX_RESET, state);
654      m_video->reset_vdp(state);
655   }
656}
657
658/*
644659    The exception of the above rule. Memory access over the datamux also operates
645660    the READY line, and the datamux raises READY depending on the clock pulse.
646661    So we must make sure this does not interfere.
r15583r15584
764779
765780static const dmux_device_list_entry dmux_devices_ev[] =
766781{
767   { V9938_SYSTEM_TAG, 0x8800, 0xfc01, 0x0400, NULL, 0, 0 },
782   { VIDEO_SYSTEM_TAG, 0x8800, 0xfc01, 0x0400, NULL, 0, 0 },
768783   { GROM0_TAG,     0x9800, 0xfc01, 0x0400, "GROMENA", 0x01, 0x00 },
769784   { GROM1_TAG,     0x9800, 0xfc01, 0x0400, "GROMENA", 0x01, 0x00 },
770785   { GROM2_TAG,     0x9800, 0xfc01, 0x0400, "GROMENA", 0x01, 0x00 },
r15583r15584
840855
841856   driver->m_joyport = static_cast<joyport_device*>(machine.device(JOYPORT_TAG));
842857
858   driver->m_video = static_cast<ti_video_device*>(machine.device(VIDEO_SYSTEM_TAG));
859
843860   driver->m_peribox->senila(CLEAR_LINE);
844861   driver->m_peribox->senilb(CLEAR_LINE);
845862   driver->m_firstjoy = 5;
r15583r15584
956973
957974   driver->m_datamux = static_cast<ti99_datamux_device*>(machine.device(DATAMUX_TAG));
958975   driver->m_joyport = static_cast<joyport_device*>(machine.device(JOYPORT_TAG));
976   driver->m_video = static_cast<ti_video_device*>(machine.device(VIDEO_SYSTEM_TAG));
959977   driver->m_firstjoy = 6;
960978
961979   driver->m_peribox->senila(CLEAR_LINE);
r15583r15584
10761094   // interlace mode, but in non-interlace modes only half of the lines are
10771095   // painted. Accordingly, the full set of lines is refreshed at 30 Hz,
10781096   // not 60 Hz. This should be fixed in the v9938 emulation.
1079   MCFG_TI_V9938_ADD(V9938_SYSTEM_TAG, 30, SCREEN_TAG, 2500, 512+32, (212+28)*2, DEVICE_SELF, ti99_4x, set_tms9901_INT2_from_v9938)
1097   MCFG_TI_V9938_ADD(VIDEO_SYSTEM_TAG, 30, SCREEN_TAG, 2500, 512+32, (212+28)*2, DEVICE_SELF, ti99_4x, set_tms9901_INT2_from_v9938)
10801098   MCFG_TIMER_ADD_SCANLINE("scantimer", ti99_4ev_hblank_interrupt, SCREEN_TAG, 0, 1)
10811099
10821100   /* Main board */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team