Previous 15994 Revisions Next

r15424 Thursday 7th June, 2012 at 20:28:49 UTC by Michael Zapf
New TMS9900 and TMS9995 implementation with proper control line handling
and wait state generation. Previous implementation has been renamed and
drivers point to the old implementation until they are adapted to the
new one. [Michael Zapf]
[src/emu/cpu]cpu.mak
[src/emu/cpu/tms9900]99xxcore.h ti990_10.c ti990_10l.c* tms9900.c tms9900.h tms9900l.c* tms9900l.h* tms9980a.c tms9980al.c* tms9995.c tms9995.h* tms9995l.c*
[src/mame/drivers]cosmic.c jpmmps.c jpms80.c jubilee.c jvh.c looping.c nsm.c nsmpoker.c pachifev.c supertnk.c tmspoker.c
[src/mess]mess.mak
[src/mess/drivers]cortex.c geneve.c ti990_10.c ti990_4.c ti99_2.c ti99_4p.c ti99_4x.c ti99_8.c tm990189.c tutor.c
[src/mess/machine/ti99]bwg.c datamux.c datamux.h genboard.c genboard.h grom.c grom.h gromport.c mapper8.c mapper8.h p_code.c peribox.c spchsyn.c speech8.c speech8.h ti99defs.h ti_fdc.c videowrp.c videowrp.h

src/mame/drivers/nsmpoker.c
r15423r15424
6060#define MASTER_CLOCK   XTAL_22_1184MHz
6161
6262#include "emu.h"
63#include "cpu/tms9900/tms9900.h"
63#include "cpu/tms9900/tms9900l.h"
6464#include "sound/ay8910.h"
6565
6666
r15423r15424
394394static MACHINE_CONFIG_START( nsmpoker, nsmpoker_state )
395395
396396   /* basic machine hardware */
397   MCFG_CPU_ADD("maincpu", TMS9995, MASTER_CLOCK/2)   /* guess */
397   MCFG_CPU_ADD("maincpu", TMS9995L, MASTER_CLOCK/2)   /* guess */
398398   MCFG_CPU_PROGRAM_MAP(nsmpoker_map)
399399   MCFG_CPU_IO_MAP(nsmpoker_portmap)
400400   MCFG_CPU_VBLANK_INT("screen", nsmpoker_interrupt)
src/mame/drivers/cosmic.c
r15423r15424
2929
3030
3131#include "emu.h"
32#include "cpu/tms9900/tms9900.h"
32#include "cpu/tms9900/tms9900l.h"
3333#include "cpu/z80/z80.h"
3434#include "sound/samples.h"
3535#include "sound/dac.h"
r15423r15424
10691069static MACHINE_CONFIG_START( cosmicg, cosmic_state )
10701070
10711071   /* basic machine hardware */
1072   MCFG_CPU_ADD("maincpu", TMS9980, COSMICG_MASTER_CLOCK/8)
1072   MCFG_CPU_ADD("maincpu", TMS9980L, COSMICG_MASTER_CLOCK/8)
10731073         /* 9.828 MHz Crystal */
10741074         /* R Nabet : huh ? This would imply the crystal frequency is somehow divided by 2 before being
10751075            fed to the tms9904 or tms9980.  Also, I have never heard of a tms9900/9980 operating under
src/mame/drivers/jvh.c
r15423r15424
11
22#include "emu.h"
3#include "cpu/tms9900/tms9900.h"
3#include "cpu/tms9900/tms9900l.h"
44
55class jvh_state : public driver_device
66{
r15423r15424
3838
3939static MACHINE_CONFIG_START( jvh, jvh_state )
4040   /* basic machine hardware */
41   MCFG_CPU_ADD("maincpu", TMS9980, 1000000)
41   MCFG_CPU_ADD("maincpu", TMS9980L, 1000000)
4242   MCFG_CPU_PROGRAM_MAP(jvh_map)
4343MACHINE_CONFIG_END
4444
src/mame/drivers/looping.c
r15423r15424
5353*/
5454
5555#include "emu.h"
56#include "cpu/tms9900/tms9900.h"
56#include "cpu/tms9900/tms9900l.h"
5757#include "sound/ay8910.h"
5858#include "sound/dac.h"
5959#include "sound/tms5220.h"
r15423r15424
637637static MACHINE_CONFIG_START( looping, looping_state )
638638
639639   /* basic machine hardware */
640   MCFG_CPU_ADD("maincpu", TMS9995, MAIN_CPU_CLOCK)
640   MCFG_CPU_ADD("maincpu", TMS9995L, MAIN_CPU_CLOCK)
641641   MCFG_CPU_PROGRAM_MAP(looping_map)
642642   MCFG_CPU_IO_MAP(looping_io_map)
643643   MCFG_CPU_VBLANK_INT("screen", looping_interrupt)
644644
645   MCFG_CPU_ADD("audiocpu", TMS9980, SOUND_CLOCK/4)
645   MCFG_CPU_ADD("audiocpu", TMS9980L, SOUND_CLOCK/4)
646646   MCFG_CPU_PROGRAM_MAP(looping_sound_map)
647647   MCFG_CPU_IO_MAP(looping_sound_io_map)
648648
src/mame/drivers/supertnk.c
r15423r15424
9696
9797
9898#include "emu.h"
99#include "cpu/tms9900/tms9900.h"
99#include "cpu/tms9900/tms9900l.h"
100100#include "sound/ay8910.h"
101101
102102
r15423r15424
425425static MACHINE_CONFIG_START( supertnk, supertnk_state )
426426
427427   /* basic machine hardware */
428   MCFG_CPU_ADD("maincpu", TMS9980, 2598750) /* ? to which frequency is the 20.79 Mhz crystal mapped down? */
428   MCFG_CPU_ADD("maincpu", TMS9980L, 2598750) /* ? to which frequency is the 20.79 Mhz crystal mapped down? */
429429   MCFG_CPU_PROGRAM_MAP(supertnk_map)
430430   MCFG_CPU_IO_MAP(supertnk_io_map)
431431   MCFG_CPU_VBLANK_INT("screen", supertnk_interrupt)
src/mame/drivers/nsm.c
r15423r15424
11
22#include "emu.h"
3#include "cpu/tms9900/tms9900.h"
3#include "cpu/tms9900/tms9900l.h"
44
55class nsm_state : public driver_device
66{
r15423r15424
3737
3838static MACHINE_CONFIG_START( nsm, nsm_state )
3939   /* basic machine hardware */
40   MCFG_CPU_ADD("maincpu", TMS9995, 11052000)
40   MCFG_CPU_ADD("maincpu", TMS9995L, 11052000)
4141   MCFG_CPU_PROGRAM_MAP(nsm_map)
4242MACHINE_CONFIG_END
4343
src/mame/drivers/pachifev.c
r15423r15424
7878***********************************************************************************************************/
7979
8080#include "emu.h"
81#include "cpu/tms9900/tms9900.h"
81#include "cpu/tms9900/tms9900l.h"
8282#include "video/tms9928a.h"
8383#include "sound/msm5205.h"
8484#include "sound/sn76496.h"
r15423r15424
357357static MACHINE_CONFIG_START( pachifev, pachifev_state )
358358
359359    /* basic machine hardware */
360    MCFG_CPU_ADD("maincpu", TMS9995, XTAL_12MHz)
360    MCFG_CPU_ADD("maincpu", TMS9995L, XTAL_12MHz)
361361    MCFG_CPU_CONFIG(pachifev_processor_config)
362362    MCFG_CPU_PROGRAM_MAP(pachifev_map)
363363    MCFG_CPU_IO_MAP(pachifev_cru)
src/mame/drivers/jubilee.c
r15423r15424
8686#define MASTER_CLOCK   XTAL_8MHz   /* guess */
8787
8888#include "emu.h"
89#include "cpu/tms9900/tms9900.h"
89#include "cpu/tms9900/tms9900l.h"
9090#include "video/mc6845.h"
9191
9292
r15423r15424
413413static MACHINE_CONFIG_START( jubileep, jubilee_state )
414414
415415   /* basic machine hardware */
416   MCFG_CPU_ADD("maincpu", TMS9980, MASTER_CLOCK/2)   /* guess */
416   MCFG_CPU_ADD("maincpu", TMS9980L, MASTER_CLOCK/2)   /* guess */
417417   MCFG_CPU_PROGRAM_MAP(jubileep_map)
418418   MCFG_CPU_IO_MAP(jubileep_cru_map)
419419   MCFG_CPU_VBLANK_INT("screen", jubileep_interrupt)
src/mame/drivers/jpmmps.c
r15423r15424
2323
2424
2525#include "emu.h"
26#include "cpu/tms9900/tms9900.h"
26#include "cpu/tms9900/tms9900l.h"
2727#include "sound/sn76496.h"
2828#include "machine/i8255.h"
2929
r15423r15424
108108static MACHINE_CONFIG_START( jpmmps, jpmmps_state )
109109
110110   /* basic machine hardware */
111   MCFG_CPU_ADD("maincpu", TMS9995, MAIN_CLOCK)
111   MCFG_CPU_ADD("maincpu", TMS9995L, MAIN_CLOCK)
112112   MCFG_CPU_PROGRAM_MAP(jpmmps_map)
113113   MCFG_CPU_IO_MAP(jpmmps_io_map)
114114
src/mame/drivers/tmspoker.c
r15423r15424
209209#define MASTER_CLOCK   XTAL_6MHz   /* confirmed */
210210
211211#include "emu.h"
212#include "cpu/tms9900/tms9900.h"
212#include "cpu/tms9900/tms9900l.h"
213213#include "video/mc6845.h"
214214#include "sound/sn76477.h"
215215
r15423r15424
561561static MACHINE_CONFIG_START( tmspoker, tmspoker_state )
562562
563563   /* basic machine hardware */
564   MCFG_CPU_ADD("maincpu", TMS9980, MASTER_CLOCK/4)   /* guess */
564   MCFG_CPU_ADD("maincpu", TMS9980L, MASTER_CLOCK/4)   /* guess */
565565   MCFG_CPU_PROGRAM_MAP(tmspoker_map)
566566   MCFG_CPU_IO_MAP(tmspoker_cru_map)
567567   MCFG_CPU_VBLANK_INT("screen", tmspoker_interrupt)
src/mame/drivers/jpms80.c
r15423r15424
1818
1919
2020#include "emu.h"
21#include "cpu/tms9900/tms9900.h"
21#include "cpu/tms9900/tms9900l.h"
2222#include "sound/ay8910.h"
2323
2424class jpms80_state : public driver_device
r15423r15424
6666
6767static MACHINE_CONFIG_START( jpms80, jpms80_state )
6868   /* basic machine hardware */
69   MCFG_CPU_ADD("maincpu", TMS9995, MAIN_CLOCK)
69   MCFG_CPU_ADD("maincpu", TMS9995L, MAIN_CLOCK)
7070   MCFG_CPU_PROGRAM_MAP(jpms80_map)
7171   MCFG_CPU_IO_MAP(jpms80_io_map)
7272
r15423r15424
8888
8989
9090static MACHINE_CONFIG_START( jpms_older_e00, jpms80_state )
91   MCFG_CPU_ADD("maincpu", TMS9995, MAIN_CLOCK)
91   MCFG_CPU_ADD("maincpu", TMS9995L, MAIN_CLOCK)
9292   MCFG_CPU_PROGRAM_MAP(jpms_older_e00_map)
9393   MCFG_CPU_IO_MAP(jpms_older_e00_io)
9494MACHINE_CONFIG_END
r15423r15424
103103
104104
105105static MACHINE_CONFIG_START( jpms_older_c00, jpms80_state )
106   MCFG_CPU_ADD("maincpu", TMS9995, MAIN_CLOCK)
106   MCFG_CPU_ADD("maincpu", TMS9995L, MAIN_CLOCK)
107107   MCFG_CPU_PROGRAM_MAP(jpms_older_c00_map)
108108   MCFG_CPU_IO_MAP(jpms_older_c00_io)
109109MACHINE_CONFIG_END
src/emu/cpu/cpu.mak
r15423r15424
16071607ifneq ($(filter TMS9900,$(CPUS)),)
16081608OBJDIRS += $(CPUOBJ)/tms9900
16091609CPUOBJS += $(CPUOBJ)/tms9900/tms9900.o
1610CPUOBJS += $(CPUOBJ)/tms9900/tms9980a.o
1610CPUOBJS += $(CPUOBJ)/tms9900/tms9900l.o
1611CPUOBJS += $(CPUOBJ)/tms9900/tms9980al.o
16111612CPUOBJS += $(CPUOBJ)/tms9900/tms9995.o
1612CPUOBJS += $(CPUOBJ)/tms9900/ti990_10.o
1613CPUOBJS += $(CPUOBJ)/tms9900/tms9995l.o
1614CPUOBJS += $(CPUOBJ)/tms9900/ti990_10l.o
16131615DASMOBJS += $(CPUOBJ)/tms9900/9900dasm.o
16141616endif
16151617
16161618$(CPUOBJ)/tms9900/tms9900.o:   $(CPUSRC)/tms9900/tms9900.c \
1617                        $(CPUSRC)/tms9900/tms9900.h \
1619                        $(CPUSRC)/tms9900/tms9900.h
1620
1621$(CPUOBJ)/tms9900/tms9900l.o:   $(CPUSRC)/tms9900/tms9900l.c \
1622                        $(CPUSRC)/tms9900/tms9900l.h \
16181623                        $(CPUSRC)/tms9900/99xxcore.h \
16191624                        $(CPUSRC)/tms9900/99xxstat.h
16201625
1621$(CPUOBJ)/tms9900/tms9980a.o:   $(CPUSRC)/tms9900/tms9980a.c \
1622                        $(CPUSRC)/tms9900/tms9900.h \
1626$(CPUOBJ)/tms9900/tms9980al.o:   $(CPUSRC)/tms9900/tms9980al.c \
1627                        $(CPUSRC)/tms9900/tms9900l.h \
16231628                        $(CPUSRC)/tms9900/99xxcore.h \
16241629                        $(CPUSRC)/tms9900/99xxstat.h
16251630
16261631$(CPUOBJ)/tms9900/tms9995.o:   $(CPUSRC)/tms9900/tms9995.c \
1627                        $(CPUSRC)/tms9900/tms9900.h \
1632                        $(CPUSRC)/tms9900/tms9900.h
1633
1634$(CPUOBJ)/tms9900/tms9995l.o:   $(CPUSRC)/tms9900/tms9995l.c \
1635                        $(CPUSRC)/tms9900/tms9900l.h \
16281636                        $(CPUSRC)/tms9900/99xxcore.h \
16291637                        $(CPUSRC)/tms9900/99xxstat.h
16301638
1631$(CPUOBJ)/tms9900/ti990_10.o:   $(CPUSRC)/tms9900/ti990_10.c \
1632                        $(CPUSRC)/tms9900/tms9900.h \
1639$(CPUOBJ)/tms9900/ti990_10l.o:   $(CPUSRC)/tms9900/ti990_10l.c \
1640                        $(CPUSRC)/tms9900/tms9900l.h \
16331641                        $(CPUSRC)/tms9900/99xxcore.h \
16341642                        $(CPUSRC)/tms9900/99xxstat.h
16351643
src/emu/cpu/tms9900/ti990_10.c
r15423r15424
11/*
2    Generate the tms9900 emulator
2    This file will contain the re-implementation of the ti990_10. The
3    previous implementation can be found as ti990_10l.
34*/
4
5#include "emu.h"
6#include "debugger.h"
7#include "tms9900.h"
8
9#define TMS99XX_MODEL TI990_10_ID
10
11#include "99xxcore.h"
12
13DEFINE_LEGACY_CPU_DEVICE(TI990_10, ti990_10);
src/emu/cpu/tms9900/tms9980a.c
r15423r15424
11/*
2    generate the tms9980a/tms9981 emulator
2    This file will contain the re-implementation of the tms9980a. The
3    previous implementation can be found as tms9980al.
34*/
4
5#include "emu.h"
6#include "debugger.h"
7#include "tms9900.h"
8
9#define TMS99XX_MODEL TMS9980_ID
10
11#include "99xxcore.h"
12
13DEFINE_LEGACY_CPU_DEVICE(TMS9980, tms9980a);
src/emu/cpu/tms9900/99xxcore.h
r15423r15424
8585
8686*/
8787
88#include "tms9900.h"
88#include "tms9900l.h"
8989
9090
9191#if (TMS99XX_MODEL == TI990_10_ID)
9292
9393   #define TMS99XX_PREFIX ti990_10
94   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( ti990_10 )
95   #define TMS99XX_device_get_name "TI990/10"
94   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( ti990_10l )
95   #define TMS99XX_device_get_name "TI990/10L"
9696
9797#elif (TMS99XX_MODEL == TMS9900_ID)
9898
9999   #define TMS99XX_PREFIX tms9900
100   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms9900 )
101   #define TMS99XX_device_get_name "TMS9900"
100   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms9900l )
101   #define TMS99XX_device_get_name "TMS9900L"
102102
103103#elif (TMS99XX_MODEL == TMS9940_ID)
104104
105105   #define TMS99XX_PREFIX tms9940
106   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms9940 )
107   #define TMS99XX_device_get_name "TMS9940"
106   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms9940l )
107   #define TMS99XX_device_get_name "TMS9940L"
108108
109109   #error "tms9940 is not yet supported"
110110
111111#elif (TMS99XX_MODEL == TMS9980_ID)
112112
113113   #define TMS99XX_PREFIX tms9980a
114   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms9980a )
115   #define TMS99XX_device_get_name "TMS9980A/TMS9981"
114   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms9980al )
115   #define TMS99XX_device_get_name "TMS9980AL/TMS9981L"
116116
117117#elif (TMS99XX_MODEL == TMS9985_ID)
118118
119119   #define TMS99XX_PREFIX tms9985
120   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms9985 )
121   #define TMS99XX_device_get_name "TMS9985"
120   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms9985l )
121   #define TMS99XX_device_get_name "TMS9985L"
122122
123123   #error "tms9985 is not yet supported"
124124
125125#elif (TMS99XX_MODEL == TMS9989_ID)
126126
127127   #define TMS99XX_PREFIX tms9989
128   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms9989 )
129   #define TMS99XX_device_get_name "TMS9989"
128   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms9989l )
129   #define TMS99XX_device_get_name "TMS9989L"
130130
131131   #error "tms9989 is not yet supported"
132132
133133#elif (TMS99XX_MODEL == TMS9995_ID)
134134
135135   #define TMS99XX_PREFIX tms9995
136   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms9995 )
137   #define TMS99XX_device_get_name "TMS9995"
136   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms9995l )
137   #define TMS99XX_device_get_name "TMS9995L"
138138
139139#elif (TMS99XX_MODEL == TMS99000_ID)
140140
141141   #define TMS99XX_PREFIX tms99000
142   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms99000 )
143   #define TMS99XX_device_get_name "TMS99000"
142   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms99000l )
143   #define TMS99XX_device_get_name "TMS99000L"
144144
145145   #error "tms99000 is not yet supported"
146146
147147#elif (TMS99XX_MODEL == TMS99105A_ID)
148148
149149   #define TMS99XX_PREFIX tms99105a
150   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms99105a )
151   #define TMS99XX_device_get_name "TMS99105A"
150   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms99105al )
151   #define TMS99XX_device_get_name "TMS99105AL"
152152
153153   #error "tms99105a is not yet supported"
154154
155155#elif (TMS99XX_MODEL == TMS99110A_ID)
156156
157157   #define TMS99XX_PREFIX tms99110a
158   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms99110a )
159   #define TMS99XX_device_get_name "TMS99110A"
158   #define TMS99XX_GET_INFO CPU_GET_INFO_NAME( tms99110al )
159   #define TMS99XX_device_get_name "TMS99110AL"
160160
161161   #error "tms99110a is not yet supported"
162162
r15423r15424
14851485         }
14861486         else
14871487         {
1488            logerror("tms9900.c : the interrupt_pending flag was set incorrectly\n");
1488            logerror("tms9900l.c : the interrupt_pending flag was set incorrectly\n");
14891489            cpustate->interrupt_pending = 0;
14901490         }
14911491      }
r15423r15424
47694769
47704770      /* --- the following bits of info are returned as NULL-terminated strings --- */
47714771      case DEVINFO_STR_NAME:                     strcpy(info->s, TMS99XX_device_get_name);      break;
4772      case DEVINFO_STR_FAMILY:               strcpy(info->s, "Texas Instruments 9900"); break;
4772      case DEVINFO_STR_FAMILY:               strcpy(info->s, "Texas Instruments 9900L"); break;
47734773      case DEVINFO_STR_VERSION:               strcpy(info->s, "2.0");               break;
47744774      case DEVINFO_STR_SOURCE_FILE:                  strcpy(info->s, __FILE__);            break;
47754775      case DEVINFO_STR_CREDITS:               strcpy(info->s, "C TMS9900 emulator by Edward Swartz, initially converted for Mame by M.Coates, updated by R. Nabet"); break;
src/emu/cpu/tms9900/tms9995l.c
r0r15424
1/*
2    generate the tms9995 emulator
3*/
4 
5#include "emu.h"
6#include "debugger.h"
7#include "tms9900l.h"
8 
9#define TMS99XX_MODEL TMS9995_ID
10 
11#include "99xxcore.h"
12 
13DEFINE_LEGACY_CPU_DEVICE(TMS9995L, tms9995l);
src/emu/cpu/tms9900/tms9900l.c
r0r15424
1/*
2    This is the previous implementation of the TMS9900 using the common
3    core implementation in 99xxcore. The new cycle-precise implementation
4    can be found in tms9900.c
5*/
6 
7#include "emu.h"
8#include "debugger.h"
9#include "tms9900l.h"
10 
11#define TMS99XX_MODEL TMS9900_ID
12 
13#include "99xxcore.h"
14 
15DEFINE_LEGACY_CPU_DEVICE(TMS9900L, tms9900l);
src/emu/cpu/tms9900/tms9995.c
r15423r15424
11/*
2    generate the tms9995 emulator
2    Texas Instruments TMS9995
3
4                    +----------------+
5              XTAL1 | 1     \/     40| A15,CRUOUT
6        XTAL2,CLKIN | 2            39| A14
7             CLKOUT | 3            38| A13
8                 D7 | 4            37| A12
9                 D6 | 5            36| A11
10                 D5 | 6            35| A10
11                 D4 | 7            34| A9
12                 D3 | 8            33| A8
13                 D2 | 9            32| A7
14               V_CC |10            31| V_SS
15                 D1 |11            30| A6
16                 D0 |12            29| A5
17              CRUIN |13            28| A4
18          /INT4,/EC |14            27| A3
19              /INT1 |15            26| A2
20          IAQ,HOLDA |16            25| A1
21              /DBIN |17            24| A0
22              /HOLD |18            23| READY
23        /WE,/CRUCLK |19            22| /RESET
24             /MEMEN |20            21| /NMI
25                    +----------------+
26
27      XTAL1    in   Crystal input pin for internal oscillator
28      XTAL2    in   Crystal input pin for internal oscillator, or
29      CLKIN    in   Input pin for external oscillator
30     CLKOUT   out   Clock output signal (1:4 of the input signal frequency)
31      CRUIN    in   CRU input data
32      /INT4    in   Interrupt level 4 input
33        /EC    in   Event counter
34      /INT1    in   Interrupt level 1 input
35        IAQ   out   Instruction acquisition
36      HOLDA   out   Hold acknowledge
37        /WE   out   Data available for memory write
38    /CRUCLK   out   Communication register unit clock output
39     /MEMEN   out   Address bus contains memory address
40       /NMI    in   Non-maskable interrupt (/LOAD on TMS9900)
41     /RESET    in   Reset interrupt
42      READY    in   Memory/External CRU device ready for access
43     CRUOUT   out   Communication register unit data output
44
45       V_CC   +5V   supply
46       V_SS    0V   Ground reference
47
48     A0-A15   out   Address bus
49      D0-D7 in/out  Data bus
50
51     Note that Texas Instruments' bit numberings define bit 0 as the
52     most significant bit (different to most other systems). Also, the
53     system uses big-endian memory organisation: Storing the word 0x1234 at
54     address 0x0000 means that the byte 0x12 is stored at 0x0000 and byte 0x34
55     is stored at 0x0001.
56
57     The TMS9995 is a 16 bit microprocessor like the TMS9900, operating on
58     16-bit words and using 16-bit opcodes. Memory transfer of 16-bit words
59     is achieved by a transfer of the most significant byte, followed by
60     the least significant byte.
61
62     The 8-bit databus width allows the processor to exchange single bytes with
63     the external memory.
64
65     See tms9900.c for some more details on the cycle-precise implementation.
66
67     This implementation also features all control lines and the instruction
68     prefetch mechanism. Prefetching is explicitly triggered within the
69     microprograms. The TMS9995 specification does not reveal the exact
70     operations during the microprogram execution, so we have to look at the
71     required cycle numbers to guess what is happening.
72
73     Auto wait state:
74
75     In order to enable automatic wait state creation, the READY line must be
76     cleared on reset time. A good position to do this is MACHINE_RESET in
77     the driver.
78
79
80     References (see comments below)
81     ----------
82     [1] Texas Instruments 9900 Microprocessor series: TMS9995 16-bit Microcomputer
83
84     TODO:
85        - Fine-tune cycles
86        - State save
87        - Test HOLD
88
89     Michael Zapf, June 2012
390*/
491
5#include "emu.h"
6#include "debugger.h"
7#include "tms9900.h"
92#include "tms9995.h"
893
9#define TMS99XX_MODEL TMS9995_ID
94/* tms9995 ST register bits. */
95enum
96{
97   ST_LH = 0x8000,      // Logical higher (unsigned comparison)
98   ST_AGT = 0x4000,   // Arithmetical greater than (signed comparison)
99   ST_EQ = 0x2000,      // Equal
100   ST_C = 0x1000,      // Carry
101   ST_OV = 0x0800,      // Overflow (when using signed operations)
102   ST_OP = 0x0400,      // Odd parity (used with byte operations)
103   ST_X = 0x0200,      // XOP
104   ST_OE = 0x0020,      // Overflow interrupt enabled
105   ST_IM = 0x000f      // Interrupt mask
106};
10107
11#include "99xxcore.h"
108enum
109{
110   PENDING_NMI = 1,
111   PENDING_MID = 2,
112   PENDING_LEVEL1 = 4,
113   PENDING_OVERFLOW = 8,
114   PENDING_DECR = 16,
115   PENDING_LEVEL4 = 32
116};
12117
13DEFINE_LEGACY_CPU_DEVICE(TMS9995, tms9995);
118#define LOG logerror
119#define VERBOSE 1
120
121/****************************************************************************
122    Constructor
123****************************************************************************/
124
125tms9995_device::tms9995_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
126   : cpu_device(mconfig, TMS9995, "TMS9995", tag, owner, clock),
127     m_program_config("program", ENDIANNESS_BIG, 8, 16),
128     m_io_config("cru", ENDIANNESS_BIG, 8, 16),
129     m_prgspace(NULL),
130     m_cru(NULL)
131{
132}
133
134enum
135{
136   TMS9995_PC=0, TMS9995_WP, TMS9995_STATUS, TMS9995_IR,
137   TMS9995_R0, TMS9995_R1, TMS9995_R2, TMS9995_R3,
138   TMS9995_R4, TMS9995_R5, TMS9995_R6, TMS9995_R7,
139   TMS9995_R8, TMS9995_R9, TMS9995_R10, TMS9995_R11,
140   TMS9995_R12, TMS9995_R13, TMS9995_R14, TMS9995_R15
141};
142
143void tms9995_device::device_start()
144{
145   const tms9995_config *conf = reinterpret_cast<const tms9995_config *>(static_config());
146
147   assert (conf != NULL);
148
149   // TODO: Restore save state suport
150
151   m_prgspace = space(AS_PROGRAM);                  // dimemory.h
152   m_cru = space(AS_IO);
153
154   // Resolve our external connections
155   m_external_operation.resolve(conf->external_callback, *this);
156   m_iaq_line.resolve(conf->iaq_line, *this);
157   m_clock_out_line.resolve(conf->clock_out, *this);
158   m_wait_line.resolve(conf->wait_line, *this);
159   m_holda_line.resolve(conf->holda_line, *this);
160
161   m_mp9537 = (conf->mode==NO_INTERNAL_RAM);
162   m_check_overflow = (conf->overflow==OVERFLOW_INT);
163
164   if (VERBOSE>0) LOG("tms9995: Configured with%s internal memory and%s overflow interrupt\n", m_mp9537? " no" : "", m_check_overflow? "" : " no");
165
166   // set our instruction counter
167   m_icountptr = &m_icount;
168
169   // Clear the interrupt flags
170   m_int_pending = 0;
171
172   m_mid_flag = false;
173   m_nmi_active = false;
174   m_int_overflow = false;
175   m_int_decrementer = false;
176
177   m_idle_state = false;
178
179   // add the states for the debugger
180   for (int i=0; i < 20; i++)
181   {
182      // callimport = need to use the state_import method to write to the state variable
183      // callexport = need to use the state_export method to read the state variable
184      state_add(i, s_statename[i], m_state_any).callimport().callexport().formatstr("%04X");
185   }
186   state_add(STATE_GENPC, "curpc", PC_debug).formatstr("%4s").noshow();
187   state_add(STATE_GENFLAGS, "status", m_state_any).callimport().callexport().formatstr("%16s").noshow();
188
189   // Set up the lookup table for command decoding
190   build_command_lookup_table();
191}
192
193void tms9995_device::device_stop()
194{
195   int k = 0;
196   if (VERBOSE>8) LOG("tms9995: Deleting lookup tables\n");
197   while (m_lotables[k]!=NULL) delete[] m_lotables[k++];
198}
199
200/*
201    TMS9995 hard reset
202    The device reset is just the emulator's trigger for the reset procedure
203    which is invoked via the main loop.
204
205    This also allows us to check the READY line at reset time, which is used
206    to enable automatic wait state creation.
207*/
208void tms9995_device::device_reset()
209{
210   m_reset = true;      // for the main loop
211}
212
213const char* tms9995_device::s_statename[20] =
214{
215   "PC ", "WP ", "ST ", "IR ",
216   "R0 ", "R1 ", "R2 ", "R3 ",
217   "R4 ", "R5 ", "R6 ", "R7 ",
218   "R8 ", "R9 ", "R10", "R11",
219   "R12", "R13", "R14", "R15"
220};
221
222/*
223    Write the contents of a register by external input (debugger)
224    Note: this is untested any may fail because of the prefetch feature of the CPU.
225    In particular it may be required to adjust the PC.
226*/
227void tms9995_device::state_import(const device_state_entry &entry)
228{
229   int index = entry.index();
230   switch (entry.index())
231   {
232      case STATE_GENFLAGS:
233         // no action here; we do not allow import, as the flags are all
234         // bits of the STATUS register
235         break;
236      case TMS9995_PC:
237         PC = (UINT16)m_state_any;
238         break;
239      case TMS9995_WP:
240         WP = (UINT16)m_state_any;
241         break;
242      case TMS9995_STATUS:
243         ST = (UINT16)m_state_any;
244         break;
245      case TMS9995_IR:
246         m_instruction->IR = (UINT16)m_state_any;
247         break;
248      default:
249         // Workspace registers
250         if (index <= TMS9995_R15)
251            write_workspace_register_debug(index-TMS9995_R0, (UINT16)m_state_any);
252         break;
253   }
254}
255
256/*
257    Reads the contents of a register for display in the debugger.
258*/
259void tms9995_device::state_export(const device_state_entry &entry)
260{
261   int index = entry.index();
262   switch (entry.index())
263   {
264      case STATE_GENFLAGS:
265         m_state_any = ST;
266         break;
267      case TMS9995_PC:
268         m_state_any = PC_debug;
269         break;
270      case TMS9995_WP:
271         m_state_any = WP;
272         break;
273      case TMS9995_STATUS:
274         m_state_any = ST;
275         break;
276      case TMS9995_IR:
277         m_state_any = m_instruction->IR;
278         break;
279      default:
280         // Workspace registers
281         if (index <= TMS9995_R15)
282            m_state_any = read_workspace_register_debug(index-TMS9995_R0);
283         break;
284   }
285}
286
287/*
288    state_string_export - export state as a string for the debugger
289*/
290void tms9995_device::state_string_export(const device_state_entry &entry, astring &string)
291{
292   static const char *statestr = "LAECOPX-----IIII";
293   char *flags = string.stringbuffer(16);
294   UINT16 val = 0x8000;
295   if (entry.index()==STATE_GENFLAGS)
296   {
297      for (int i=0; i < 16; i++)
298      {
299         flags[i] = ((val & ST)!=0)? statestr[i] : '.';
300         val = (val >> 1) & 0x7fff;
301      }
302   }
303}
304
305UINT16 tms9995_device::read_workspace_register_debug(int reg)
306{
307   int temp = m_icount;
308   UINT16 value = m_prgspace->read_word((WP+(reg<<1)) & 0xfffe);
309   m_icount = temp;
310   return value;
311}
312
313void tms9995_device::write_workspace_register_debug(int reg, UINT16 data)
314{
315   int temp = m_icount;
316   m_prgspace->write_word((WP+(reg<<1)) & 0xfffe, data);
317   m_icount = temp;
318}
319
320const address_space_config *tms9995_device::memory_space_config(address_spacenum spacenum) const
321{
322   switch (spacenum)
323   {
324   case AS_PROGRAM:
325      return &m_program_config;
326
327   case AS_IO:
328      return &m_io_config;
329
330   default:
331      return NULL;
332   }
333}
334
335/**************************************************************************
336    Microprograms for the CPU instructions
337
338    The actions which are specific to the respective instruction are
339    invoked by repeated calls of ALU_xxx; each call increases a state
340    variable so that on the next call, the next part can be processed.
341    This saves us a lot of additional functions.
342**************************************************************************/
343
344/*
345    Define the indices for the micro-operation table. This is done for the sake
346    of a simpler microprogram definition as an UINT8[].
347*/
348enum
349{
350   PREFETCH,
351   PREFETCH_NO_INT,
352   MEMORY_READ,
353   MEMORY_WRITE,
354   WORD_READ,
355   WORD_WRITE,
356   OPERAND_ADDR,
357   INCREG,
358   INDX,
359   SET_IMM,
360   RETADDR,
361   RETADDR1,
362   CRU_INPUT,
363   CRU_OUTPUT,
364   ABORT,
365   END,
366
367   ALU_NOP,
368   ALU_ADD_S_SXC,
369   ALU_B,
370   ALU_BLWP,
371   ALU_C,
372   ALU_CI,
373   ALU_CLR_SETO,
374   ALU_DIV,
375   ALU_DIVS,
376   ALU_EXTERNAL,
377   ALU_F3,
378   ALU_IMM_ARITHM,
379   ALU_JUMP,
380   ALU_LDCR,
381   ALU_LI,
382   ALU_LIMIWP,
383   ALU_LSTWP,
384   ALU_MOV,
385   ALU_MPY,
386   ALU_RTWP,
387   ALU_SBO_SBZ,
388   ALU_SHIFT,
389   ALU_SINGLE_ARITHM,
390   ALU_STCR,
391   ALU_STSTWP,
392   ALU_TB,
393   ALU_X,
394   ALU_XOP,
395   ALU_INT
396};
397
398#define MICROPROGRAM(_MP) \
399   static const UINT8 _MP[] =
400
401MICROPROGRAM(operand_address_derivation)
402{
403   RETADDR, 0, 0, 0,                     // Register direct                  0
404   WORD_READ, RETADDR, 0, 0,               // Register indirect                1 (1)
405   WORD_READ, RETADDR, 0, 0,               // Symbolic                         1 (1)
406   WORD_READ, INCREG, WORD_WRITE, RETADDR1,   // Reg indirect auto-increment      3 (1) (1)
407   WORD_READ, INDX, WORD_READ, RETADDR         // Indexed                          3 (1) (1)
408};
409
410MICROPROGRAM(add_s_sxc_mp)
411{
412   OPERAND_ADDR,         // x
413   MEMORY_READ,         // 1 (1)
414   OPERAND_ADDR,         // y
415   MEMORY_READ,         // 1 (1)
416   ALU_ADD_S_SXC,         // 0
417   PREFETCH,            // 1 (1)
418   MEMORY_WRITE,         // 1 (1)
419   END
420};
421
422MICROPROGRAM(b_mp)
423{
424   OPERAND_ADDR,
425   ALU_NOP,            // Don't read, just use the address
426   ALU_B,
427   PREFETCH,
428   ALU_NOP,            // Don't save the return address
429   END
430};
431
432MICROPROGRAM(bl_mp)
433{
434   OPERAND_ADDR,
435   ALU_NOP,            // Don't read, just use the address
436   ALU_B,               // Re-use the alu operation from B
437   PREFETCH,
438   ALU_NOP,
439   MEMORY_WRITE,         // Write R11
440   ALU_NOP,
441   END
442};
443
444MICROPROGRAM(blwp_mp)
445{
446   OPERAND_ADDR,         // Determine source address
447   MEMORY_READ,
448   ALU_BLWP,            // Got new WP, save it; increase address, save
449   MEMORY_WRITE,         // save old ST to new R15
450   ALU_BLWP,
451   MEMORY_WRITE,         // save old PC to new R14
452   ALU_BLWP,
453   MEMORY_WRITE,         // save old WP to new R13
454   ALU_BLWP,            // retrieve address
455   MEMORY_READ,         // Read new PC
456   ALU_BLWP,            // Set new PC
457   PREFETCH,
458   ALU_NOP,
459   END
460};
461
462MICROPROGRAM(c_mp)
463{
464   OPERAND_ADDR,         // x
465   MEMORY_READ,         // 1 (1)
466   OPERAND_ADDR,         // y
467   MEMORY_READ,         // 1 (1)
468   ALU_C,               // 0
469   PREFETCH,            // 1 (1)
470   ALU_NOP,            // 1
471   END
472};
473
474MICROPROGRAM(ci_mp)
475{
476   MEMORY_READ,         // 1 (reg)
477   SET_IMM,            // 0
478   MEMORY_READ,         // 1 (imm)
479   ALU_CI,               // (1) set status
480   PREFETCH,            // 1
481   ALU_NOP,            // 1
482   END
483};
484
485MICROPROGRAM(coc_czc_mp)
486{
487   OPERAND_ADDR,
488   MEMORY_READ,
489   ALU_F3,
490   MEMORY_READ,
491   ALU_F3,
492   PREFETCH,
493   ALU_NOP,
494   END
495};
496
497MICROPROGRAM(clr_seto_mp)
498{
499   OPERAND_ADDR,
500   ALU_NOP,
501   ALU_CLR_SETO,         // (1)
502   PREFETCH,            // 1
503   MEMORY_WRITE,         // 1
504   END
505};
506
507MICROPROGRAM(divide_mp)
508{
509   OPERAND_ADDR,         // Address of divisor S in Q=W1W2/S
510   MEMORY_READ,         // Get S
511   ALU_DIV,
512   MEMORY_READ,         // Get W1
513   ALU_DIV,            // Check for overflow; skip next instruction if not
514   ABORT,
515   MEMORY_READ,         // Get W2
516   ALU_DIV,            // Calculate quotient
517   MEMORY_WRITE,         // Write quotient to &W1
518   ALU_DIV,
519   PREFETCH,
520   MEMORY_WRITE,         // Write remainder to &W2
521   END
522};
523
524MICROPROGRAM(divide_signed_mp)
525{
526   OPERAND_ADDR,         // Address of divisor S in Q=W1W2/S
527   MEMORY_READ,         // Get S
528   ALU_DIV,
529   MEMORY_READ,         // Get W1
530   ALU_DIV,            //
531   MEMORY_READ,         // Get W2
532   ALU_DIV,            // Check for overflow, skip next instruction if not
533   ABORT,
534   ALU_DIV,            // Calculate quotient
535   MEMORY_WRITE,         // Write quotient to &W1
536   ALU_DIV,
537   PREFETCH,
538   MEMORY_WRITE,         // Write remainder to &W2
539   END
540};
541
542MICROPROGRAM(external_mp)
543{
544   ALU_NOP,
545   ALU_NOP,
546   ALU_NOP,
547   ALU_NOP,
548   ALU_NOP,
549   ALU_EXTERNAL,
550   PREFETCH,
551   ALU_NOP,
552   END
553};
554
555MICROPROGRAM(imm_arithm_mp)
556{
557   MEMORY_READ,
558   SET_IMM,            // 0
559   MEMORY_READ,         // 1 (1)
560   ALU_IMM_ARITHM,         // 0
561   PREFETCH,            // 1 (1)
562   MEMORY_WRITE,
563   END
564};
565
566MICROPROGRAM(jump_mp)
567{
568   ALU_JUMP,
569   PREFETCH,
570   ALU_NOP,
571   END
572};
573
574MICROPROGRAM(ldcr_mp)
575{
576   ALU_LDCR,
577   OPERAND_ADDR,
578   MEMORY_READ,         // Get source data
579   ALU_LDCR,            // Save it, point to R12
580   WORD_READ,            // Get R12
581   ALU_LDCR,            // Prepare CRU operation
582   CRU_OUTPUT,
583   ALU_NOP,
584   PREFETCH,
585   ALU_NOP,
586   END
587};
588
589MICROPROGRAM(li_mp)
590{
591   SET_IMM,            // 0
592   MEMORY_READ,         // 1 (1)
593   ALU_LI,               // 0
594   PREFETCH,            // 1 (1)
595   MEMORY_WRITE,
596   END
597};
598
599MICROPROGRAM(limi_lwpi_mp)
600{
601   SET_IMM,            // 0
602   MEMORY_READ,         // 1 (1)
603   ALU_NOP,            // 1
604   ALU_LIMIWP,            // (1)
605   PREFETCH,            // 1
606   ALU_NOP,            // 1
607   END
608};
609
610MICROPROGRAM(lst_lwp_mp)
611{
612   MEMORY_READ,
613   ALU_NOP,
614   ALU_LSTWP,
615   PREFETCH,
616   ALU_NOP,
617   END
618};
619
620MICROPROGRAM(mov_mp)
621{
622   OPERAND_ADDR,         // 0
623   MEMORY_READ,         // 1 (1)
624   OPERAND_ADDR,         // 0
625   ALU_MOV,            // 1
626   PREFETCH,
627   MEMORY_WRITE,         // 1 (1)
628   END
629};
630
631MICROPROGRAM(multiply_mp)
632{
633   OPERAND_ADDR,
634   MEMORY_READ,
635   ALU_MPY,
636   MEMORY_READ,
637   ALU_MPY,
638   MEMORY_WRITE,
639   ALU_MPY,
640   PREFETCH,
641   MEMORY_WRITE,
642   END
643};
644
645MICROPROGRAM(rtwp_mp)
646{
647   ALU_RTWP,
648   MEMORY_READ,
649   ALU_RTWP,
650   MEMORY_READ,
651   ALU_RTWP,
652   MEMORY_READ,
653   ALU_RTWP,
654   PREFETCH,
655   ALU_NOP,
656   END
657};
658
659MICROPROGRAM(sbo_sbz_mp)
660{
661   ALU_SBO_SBZ,         // Set address = &R12
662   WORD_READ,            // Read R12
663   ALU_SBO_SBZ,         // Add offset
664   CRU_OUTPUT,            // output via CRU
665   ALU_NOP,
666   PREFETCH,
667   ALU_NOP,
668   END
669};
670
671MICROPROGRAM(shift_mp)
672{
673   MEMORY_READ,
674   ALU_SHIFT,            // skip next operation if count != 0
675   MEMORY_READ,         // if count=0 we must read R0
676   ALU_SHIFT,            // do the shift
677   PREFETCH,
678   MEMORY_WRITE,
679   END
680};
681
682MICROPROGRAM(single_arithm_mp)
683{
684   OPERAND_ADDR,
685   MEMORY_READ,         // This one is not done for CLR/SETO
686   ALU_SINGLE_ARITHM,
687   PREFETCH,
688   MEMORY_WRITE,
689   END
690};
691
692MICROPROGRAM(stcr_mp)
693{
694   ALU_STCR,            // Check for byte operation
695   OPERAND_ADDR,         // Source operand
696   ALU_STCR,            // Save, set R12
697   WORD_READ,            // Read R12
698   ALU_STCR,
699   CRU_INPUT,
700   ALU_STCR,
701   PREFETCH,
702   MEMORY_WRITE,
703   END
704};
705
706MICROPROGRAM(stst_stwp_mp)
707{
708   ALU_STSTWP,
709   ALU_NOP,
710   PREFETCH,
711   MEMORY_WRITE,
712   END
713};
714
715MICROPROGRAM(tb_mp)
716{
717   ALU_TB,
718   WORD_READ,
719   ALU_TB,
720   CRU_INPUT,
721   ALU_TB,
722   PREFETCH,
723   ALU_NOP,
724   END
725};
726
727MICROPROGRAM(x_mp)
728{
729   OPERAND_ADDR,
730   MEMORY_READ,
731   ALU_X,
732   END                  // should not be reached
733};
734
735MICROPROGRAM(xop_mp)
736{
737   OPERAND_ADDR,         // Determine source address
738   ALU_XOP,            // Save it; determine XOP number
739   MEMORY_READ,         // Read new WP
740   ALU_XOP,            //
741   MEMORY_WRITE,         // save source address to new R11
742   ALU_XOP,
743   MEMORY_WRITE,         // save old ST to new R15
744   ALU_XOP,
745   MEMORY_WRITE,         // save old PC to new R14
746   ALU_XOP,
747   MEMORY_WRITE,         // save old WP to new R13
748   ALU_XOP,
749   MEMORY_READ,         // Read new PC
750   ALU_XOP,            // set new PC, set X flag
751   PREFETCH,
752   ALU_NOP,
753   END
754};
755
756MICROPROGRAM(xor_mp)
757{
758   OPERAND_ADDR,
759   MEMORY_READ,
760   ALU_F3,
761   MEMORY_READ,
762   ALU_F3,
763   PREFETCH,
764   MEMORY_WRITE,
765   END
766};
767
768MICROPROGRAM(int_mp)
769{
770   ALU_INT,            // 1
771   MEMORY_READ,         // 1 (1)
772   ALU_INT,            // 2
773   MEMORY_WRITE,         // 1 (1)
774   ALU_INT,            // 1
775   MEMORY_WRITE,         // 1 (1)
776   ALU_INT,            // 1
777   MEMORY_WRITE,         // 1 (1)
778   ALU_INT,            // 1
779   MEMORY_READ,         // 1 (1)
780   ALU_INT,            // 0
781   PREFETCH_NO_INT,      // 1 (1)  (prefetch happens in parallel to the previous operation)
782   ALU_NOP,            // 1 (+decode in parallel; actually performed right after prefetch)
783   ALU_NOP,            // 1
784   END
785};
786
787const tms9995_device::ophandler tms9995_device::s_microoperation[] =
788{
789   &tms9995_device::int_prefetch_and_decode,
790   &tms9995_device::prefetch_and_decode,
791   &tms9995_device::mem_read,
792   &tms9995_device::mem_write,
793   &tms9995_device::word_read,
794   &tms9995_device::word_write,
795   &tms9995_device::operand_address_subprogram,
796   &tms9995_device::increment_register,
797   &tms9995_device::indexed_addressing,
798   &tms9995_device::set_immediate,
799   &tms9995_device::return_with_address,
800   &tms9995_device::return_with_address_copy,
801   &tms9995_device::cru_input_operation,
802   &tms9995_device::cru_output_operation,
803   &tms9995_device::abort_operation,
804   &tms9995_device::command_completed,
805
806   &tms9995_device::alu_nop,
807   &tms9995_device::alu_add_s_sxc,
808   &tms9995_device::alu_b,
809   &tms9995_device::alu_blwp,
810   &tms9995_device::alu_c,
811   &tms9995_device::alu_ci,
812   &tms9995_device::alu_clr_seto,
813   &tms9995_device::alu_divide,
814   &tms9995_device::alu_divide_signed,
815   &tms9995_device::alu_external,
816   &tms9995_device::alu_f3,
817   &tms9995_device::alu_imm_arithm,
818   &tms9995_device::alu_jump,
819   &tms9995_device::alu_ldcr,
820   &tms9995_device::alu_li,
821   &tms9995_device::alu_limi_lwpi,
822   &tms9995_device::alu_lst_lwp,
823   &tms9995_device::alu_mov,
824   &tms9995_device::alu_multiply,
825   &tms9995_device::alu_rtwp,
826   &tms9995_device::alu_sbo_sbz,
827   &tms9995_device::alu_shift,
828   &tms9995_device::alu_single_arithm,
829   &tms9995_device::alu_stcr,
830   &tms9995_device::alu_stst_stwp,
831   &tms9995_device::alu_tb,
832   &tms9995_device::alu_x,
833   &tms9995_device::alu_xop,
834   &tms9995_device::alu_int
835};
836
837/*****************************************************************************
838    CPU instructions
839*****************************************************************************/
840
841/*
842    Available instructions
843    MID is not a real instruction but stands for an invalid operation which
844    triggers a "macro instruction detect" interrupt. Neither is INTR which
845    indicates an interrupt handling in progress.
846*/
847enum
848{
849   MID=0, A, AB, ABS, AI, ANDI, B, BL, BLWP, C,
850   CB, CI, CKOF, CKON, CLR, COC, CZC, DEC, DECT, DIV,
851   DIVS, IDLE, INC, INCT, INV, JEQ, JGT, JH, JHE, JL,
852   JLE, JLT, JMP, JNC, JNE, JNO, JOC, JOP, LDCR, LI,
853   LIMI, LREX, LST, LWP, LWPI, MOV, MOVB, MPY, MPYS, NEG,
854   ORI, RSET, RTWP, S, SB, SBO, SBZ, SETO, SLA, SOC,
855   SOCB, SRA, SRC, SRL, STCR, STST, STWP, SWPB, SZC, SZCB,
856   TB, X, XOP, XOR, INTR
857};
858
859static const char opname[][5] =
860{   "MID ", "A   ", "AB  ", "ABS ", "AI  ", "ANDI", "B   ", "BL  ", "BLWP", "C   ",
861   "CB  ", "CI  ",   "CKOF", "CKON", "CLR ", "COC ", "CZC ", "DEC ", "DECT", "DIV ",
862   "DIVS", "IDLE", "INC ", "INCT", "INV ", "JEQ ", "JGT ", "JH  ", "JHE ", "JL  ",
863   "JLE ", "JLT ", "JMP ", "JNC ", "JNE ", "JNO ", "JOC ", "JOP ", "LDCR", "LI  ",
864   "LIMI", "LREX", "LST ", "LWP ", "LWPI", "MOV ", "MOVB", "MPY ", "MPYS", "NEG ",
865   "ORI ", "RSET",   "RTWP", "S   ", "SB  ", "SBO ", "SBZ ", "SETO", "SLA ", "SOC ",
866   "SOCB", "SRA ", "SRC ", "SRL ",   "STCR", "STST", "STWP", "SWPB", "SZC ", "SZCB",
867   "TB  ", "X   ", "XOP ", "XOR ", "*int"
868};
869
870/*
871    Formats:
872
873          0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
874    ----+------------------------------------------------+
875    1   | Opcode | B | Td |  RegNr     | Ts |    RegNr   |
876        +--------+---+----+------------+----+------------+
877    2   |  Opcode               |      Displacement      |
878        +-----------------------+------------------------+
879    3   |  Opcode         |  RegNr     | Ts |    RegNr   |
880        +-----------------+------------+----+------------+
881    4   |  Opcode         |  Count     | Ts |    RegNr   |
882        +-----------------+------------+----+------------+
883    5   |  Opcode               |  Count    |    RegNr   |
884        +-----------------------+-----------+------------+
885    6   |  Opcode                      | Ts |    RegNr   |
886        +------------------------------+----+------------+
887    7   |  Opcode                         |0| 0| 0| 0| 0 |
888        +---------------------------------+-+--+--+--+---+
889    8   |  Opcode                         |0|    RegNr   |
890        +---------------------------------+-+------------+
891    9   |  Opcode         |   Reg/Nr   | Ts |    RegNr   |
892        +-----------------+------------+----+------------+
893    10  |  Opcode                      | Ts |    RegNr   |   (DIVS, MPYS)
894        +------------------------------+----+------------+
895    11  |  Opcode                           |    RegNr   |   (LST, LWP)
896        +-----------------------------------+------------+
897*/
898
899/*
900    Defines the number of bits from the left which are significant for the
901    command in the respective format.
902*/
903static const int format_mask_len[] =
904{
905   0, 4, 8, 6, 6, 8, 10, 16, 12, 6, 10, 12
906};
907
908const tms9995_device::tms_instruction tms9995_device::s_command[] =
909{
910   // Base opcode list
911   // Opcode, ID, format, microprg
912   { 0x0080, LST, 11, lst_lwp_mp },
913   { 0x0090, LWP, 11, lst_lwp_mp },
914   { 0x0180, DIVS, 10, divide_signed_mp },
915   { 0x01C0, MPYS, 10, multiply_mp },
916   { 0x0200, LI, 8, li_mp },
917   { 0x0220, AI, 8, imm_arithm_mp },
918   { 0x0240, ANDI, 8, imm_arithm_mp },
919   { 0x0260, ORI, 8, imm_arithm_mp },
920   { 0x0280, CI, 8, ci_mp },
921   { 0x02a0, STWP, 8, stst_stwp_mp },
922   { 0x02c0, STST, 8, stst_stwp_mp },
923   { 0x02e0, LWPI, 8, limi_lwpi_mp },
924   { 0x0300, LIMI, 8, limi_lwpi_mp },
925   { 0x0340, IDLE, 7, external_mp },
926   { 0x0360, RSET, 7, external_mp },
927   { 0x0380, RTWP, 7, rtwp_mp },
928   { 0x03a0, CKON, 7, external_mp },
929   { 0x03c0, CKOF, 7, external_mp },
930   { 0x03e0, LREX, 7, external_mp },
931   { 0x0400, BLWP, 6, blwp_mp },
932   { 0x0440, B, 6, b_mp },
933   { 0x0480, X, 6, x_mp },
934   { 0x04c0, CLR, 6, clr_seto_mp },
935   { 0x0500, NEG, 6, single_arithm_mp },
936   { 0x0540, INV, 6, single_arithm_mp },
937   { 0x0580, INC, 6, single_arithm_mp },
938   { 0x05c0, INCT, 6, single_arithm_mp },
939   { 0x0600, DEC, 6, single_arithm_mp },
940   { 0x0640, DECT, 6, single_arithm_mp },
941   { 0x0680, BL, 6, bl_mp },
942   { 0x06c0, SWPB, 6, single_arithm_mp },
943   { 0x0700, SETO, 6, clr_seto_mp },
944   { 0x0740, ABS, 6, single_arithm_mp },
945   { 0x0800, SRA, 5, shift_mp },
946   { 0x0900, SRL, 5, shift_mp },
947   { 0x0a00, SLA, 5, shift_mp },
948   { 0x0b00, SRC, 5, shift_mp },
949   { 0x1000, JMP, 2, jump_mp },
950   { 0x1100, JLT, 2, jump_mp },
951   { 0x1200, JLE, 2, jump_mp },
952   { 0x1300, JEQ, 2, jump_mp },
953   { 0x1400, JHE, 2, jump_mp },
954   { 0x1500, JGT, 2, jump_mp },
955   { 0x1600, JNE, 2, jump_mp },
956   { 0x1700, JNC, 2, jump_mp },
957   { 0x1800, JOC, 2, jump_mp },
958   { 0x1900, JNO, 2, jump_mp },
959   { 0x1a00, JL, 2, jump_mp },
960   { 0x1b00, JH, 2, jump_mp },
961   { 0x1c00, JOP, 2, jump_mp },
962   { 0x1d00, SBO, 2, sbo_sbz_mp },
963   { 0x1e00, SBZ, 2, sbo_sbz_mp },
964   { 0x1f00, TB, 2, tb_mp },
965   { 0x2000, COC, 3, coc_czc_mp },
966   { 0x2400, CZC, 3, coc_czc_mp },
967   { 0x2800, XOR, 3, xor_mp },
968   { 0x2c00, XOP, 3, xop_mp },
969   { 0x3000, LDCR, 4, ldcr_mp },
970   { 0x3400, STCR, 4, stcr_mp },
971   { 0x3800, MPY, 9, multiply_mp },
972   { 0x3c00, DIV, 9, divide_mp },
973   { 0x4000, SZC, 1, add_s_sxc_mp },
974   { 0x5000, SZCB, 1, add_s_sxc_mp },
975   { 0x6000, S, 1, add_s_sxc_mp },
976   { 0x7000, SB, 1, add_s_sxc_mp },
977   { 0x8000, C, 1, c_mp },
978   { 0x9000, CB, 1, c_mp },
979   { 0xa000, A, 1, add_s_sxc_mp },
980   { 0xb000, AB, 1, add_s_sxc_mp },
981   { 0xc000, MOV, 1, mov_mp },
982   { 0xd000, MOVB, 1, mov_mp },
983   { 0xe000, SOC, 1, add_s_sxc_mp },
984   { 0xf000, SOCB, 1, add_s_sxc_mp }
985};
986
987/*
988    Create a B-tree for looking up the commands. Each node can carry up to
989    16 entries, indexed by 4 consecutive bits in the opcode.
990
991    See tms9900.c for a detailed description.
992*/
993void tms9995_device::build_command_lookup_table()
994{
995   int i = 0;
996   int cmdindex = 0;
997   int bitcount;
998   const tms_instruction *inst;
999   UINT16 opcode;
1000   int k = 0;
1001
1002   m_command_lookup_table = new lookup_entry[16];
1003   // We use lotables as a list of allocated tables - to be able to delete them
1004   // at the end.
1005   m_lotables[k++] = m_command_lookup_table;
1006
1007   lookup_entry* table = m_command_lookup_table;
1008   for (int j=0; j < 16; j++)
1009   {
1010      table[j].entry = NULL;
1011      table[j].next_digit = NULL;
1012   }
1013
1014   do
1015   {
1016      inst = &s_command[i];
1017      table = m_command_lookup_table;
1018      if (VERBOSE>8) LOG("tms9995: === opcode=%04x, len=%d\n", inst->opcode, format_mask_len[inst->format]);
1019      bitcount = 4;
1020      opcode = inst->opcode;
1021      cmdindex = (opcode>>12) & 0x000f;
1022
1023      while (bitcount < format_mask_len[inst->format])
1024      {
1025         // Descend
1026         if (table[cmdindex].next_digit == NULL)
1027         {
1028            if (VERBOSE>8) LOG("tms9995: create new table at bitcount=%d for index=%d\n", bitcount, cmdindex);
1029            table[cmdindex].next_digit = new lookup_entry[16];
1030            m_lotables[k++] = table[cmdindex].next_digit;
1031            for (int j=0; j < 16; j++)
1032            {
1033               table[cmdindex].next_digit[j].next_digit = NULL;
1034               table[cmdindex].next_digit[j].entry = NULL;
1035            }
1036         }
1037         else
1038         {
1039            if (VERBOSE>8) LOG("tms9995: found a table at bitcount=%d\n", bitcount);
1040         }
1041
1042         table = table[cmdindex].next_digit;
1043
1044         bitcount = bitcount+4;
1045         opcode <<= 4;
1046         cmdindex = (opcode>>12) & 0x000f;
1047         if (VERBOSE>8) LOG("tms9995: next index=%x\n", cmdindex);
1048      }
1049
1050      if (VERBOSE>8) LOG("tms9995: bitcount=%d\n", bitcount);
1051      // We are at the target level
1052      // Need to fill in the same entry for all values in the bitcount
1053      // (if a command needs 10 bits we have to copy it four
1054      // times for all combinations with 12 bits)
1055      for (int j=0; j < (1<<(bitcount-format_mask_len[inst->format])); j++)
1056      {
1057         if (VERBOSE>8) LOG("tms9995: opcode=%04x at position %d\n", inst->opcode, cmdindex+j);
1058         table[cmdindex+j].entry = inst;
1059      }
1060
1061      i++;
1062   } while (inst->opcode != 0xf000);
1063
1064   m_lotables[k++] = NULL;
1065   if (VERBOSE>8) LOG("tms9995: Allocated %d tables\n", k);
1066}
1067
1068/*
1069    Main execution loop
1070
1071    For each invocation of execute_run, a number of loop iterations has been
1072    calculated before (m_icount). Each loop iteration is one clock cycle.
1073    The loop must be executed for the number of times that corresponds to the
1074    time until the next timer event.
1075*/
1076void tms9995_device::execute_run()
1077{
1078   if (m_reset) service_interrupt();
1079
1080   if (VERBOSE>5) LOG("tms9995: calling execute_run for %d cycles\n", m_icount);
1081   do
1082   {
1083      // Normal operation
1084      if (m_check_ready && m_ready_state == false)
1085      {
1086         // We are in a wait state
1087         set_wait_state(true);
1088         if (VERBOSE>2) LOG("tms9995: wait state\n");
1089         // The clock output should be used to change the state of an outer
1090         // device which operates the READY line
1091         pulse_clock(1);
1092      }
1093      else
1094      {
1095         if (m_check_hold && m_hold_state)
1096         {
1097            set_hold_state(true);
1098            if (VERBOSE>6) LOG("tms9995: hold state\n");
1099            pulse_clock(1);
1100         }
1101         else
1102         {
1103            set_wait_state(false);
1104            set_hold_state(false);
1105
1106            m_check_ready = false;
1107
1108            if (VERBOSE>8) LOG("tms9995: main loop, operation %s, MPC = %d\n", opname[m_instruction->command], MPC);
1109            (this->*s_microoperation[m_instruction->program[MPC]])();
1110
1111            // For multi-pass operations where the MPC should not advance
1112            // or when we have put in a new microprogram
1113            m_pass--;
1114            if (m_pass<=0)
1115            {
1116               m_pass = 1;
1117               MPC++;
1118            }
1119         }
1120      }
1121   } while (m_icount>0);
1122   if (VERBOSE>5) LOG("tms9995: cycles expired; will return soon.\n");
1123}
1124
1125/**************************************************************************/
1126
1127/*
1128    Interrupt input
1129    output
1130        m_nmi_state
1131        m_irq_level
1132        flag[2], flag[4]
1133*/
1134void tms9995_device::execute_set_input(int irqline, int state)
1135{
1136   if (irqline == INPUT_LINE_NMI)
1137   {
1138      m_nmi_active = (state==ASSERT_LINE);
1139      if (VERBOSE>3) LOG("tms9995: NMI interrupt line state=%d\n", state);
1140   }
1141   else
1142   {
1143      if (irqline == 1)
1144      {
1145         m_int1_active = m_flag[2] = (state==ASSERT_LINE);
1146         if (VERBOSE>3) LOG("tms9995: Line INT1 state=%d\n", state);
1147      }
1148      else
1149      {
1150         if (irqline == 4)
1151         {
1152            if (VERBOSE>3) LOG("tms9995: Line INT4/EC state=%d\n", state);
1153            if (m_flag[0]==false)
1154            {
1155               if (VERBOSE>7) LOG("tms9995: set as interrupt\n");
1156               m_int4_active = m_flag[4] = (state==ASSERT_LINE);
1157            }
1158            else
1159            {
1160               if (VERBOSE>7) LOG("tms9995: set as event count\n");
1161               trigger_decrementer();
1162            }
1163         }
1164         else
1165         {
1166            if (VERBOSE>0) LOG("tms9995: Accessed invalid interrupt line %d\n", irqline);
1167         }
1168      }
1169   }
1170}
1171
1172/*
1173    Issue a pulse on the clock line.
1174*/
1175inline void tms9995_device::pulse_clock(int count)
1176{
1177   for (int i=0; i < count; i++)
1178   {
1179      m_clock_out_line(ASSERT_LINE);
1180      m_clock_out_line(CLEAR_LINE);
1181      m_icount--;                     // This is the only location where we count down the cycles.
1182      if (VERBOSE>7) LOG("tms9995: pulse_clock\n");
1183      if (m_flag[0] == false && m_flag[1] == true) trigger_decrementer();
1184   }
1185}
1186
1187/*
1188    Enter the hold state.
1189*/
1190void tms9995_device::set_hold(int state)
1191{
1192   m_hold_state = (state==ASSERT_LINE);
1193   if (VERBOSE>7) LOG("tms9995: set HOLD = %d\n", state);
1194   if (!m_hold_state)
1195   {
1196      m_holda_line(CLEAR_LINE);
1197   }
1198}
1199
1200/*
1201    Signal READY to the CPU. When cleared, the CPU enters wait states.
1202*/
1203void tms9995_device::set_ready(int state)
1204{
1205   if (VERBOSE>5) LOG("tms9995: set READY = %d\n", state);
1206   m_ready_state = (state==ASSERT_LINE);
1207}
1208
1209void tms9995_device::abort_operation()
1210{
1211   command_completed();
1212}
1213
1214/*
1215    Enter or leave the wait state. We only operate the WAIT line when there is a change.
1216*/
1217inline void tms9995_device::set_wait_state(bool state)
1218{
1219   if (m_wait_state != state) m_wait_line(state? ASSERT_LINE : CLEAR_LINE);
1220   m_wait_state = state;
1221}
1222
1223/*
1224    Enter or leave the hold state. We only operate the HOLDA line when there is a change.
1225*/
1226inline void tms9995_device::set_hold_state(bool state)
1227{
1228   if (m_hold_state != state) m_holda_line(state? ASSERT_LINE : CLEAR_LINE);
1229   m_hold_state = state;
1230}
1231
1232/*
1233    Decode the instruction. This is done in parallel to other operations
1234    so we just do it together with the prefetch.
1235*/
1236void tms9995_device::decode(UINT16 inst)
1237{
1238   int index = 0;
1239   lookup_entry* table = m_command_lookup_table;
1240   UINT16 opcode = inst;
1241   bool complete = false;
1242   const tms_instruction *decoded;
1243
1244   int dindex = (m_instindex==0)? 1:0;
1245
1246   m_mid_flag = false;
1247
1248   while (!complete)
1249   {
1250      index = (opcode >> 12) & 0x000f;
1251      if (VERBOSE>8) LOG("tms9995: Check next hex digit of instruction %x\n", index);
1252      if (table[index].next_digit != NULL)
1253      {
1254         table = table[index].next_digit;
1255         opcode = opcode << 4;
1256      }
1257      else complete = true;
1258   }
1259   decoded = table[index].entry;
1260   if (decoded == NULL)
1261   {
1262      // not found
1263      if (VERBOSE>0) LOG("tms9995: Unknown opcode %04x, will trigger MID\n", inst);
1264      m_decoded[dindex].IR = 0;
1265      m_decoded[dindex].command = MID;
1266   }
1267   else
1268   {
1269      m_decoded[dindex].IR = inst;
1270      m_decoded[dindex].command = decoded->id;
1271      m_decoded[dindex].program = decoded->prog;
1272      m_decoded[dindex].byteop = ((decoded->format == 1) && ((inst & 0x1000)!=0));
1273      m_decoded[dindex].state = 0;
1274      if (VERBOSE>7) LOG("tms9995: Command decoded as id %d, %s, base opcode %04x\n", decoded->id, opname[decoded->id], decoded->opcode);
1275      m_pass = 1;
1276   }
1277}
1278
1279/*
1280    Fetch the next instruction and check pending interrupts before.
1281    Getting an instruction is a normal memory access (plus an asserted IAQ line),
1282    so this is subject to wait state handling. We have to allow for a two-pass
1283    handling.
1284*/
1285void tms9995_device::int_prefetch_and_decode()
1286{
1287   bool check_idle = false;
1288   bool check_int = (m_instruction->command != XOP && m_instruction->command != BLWP);
1289   int intmask = ST & 0x000f;
1290
1291   if (m_lowbyte)
1292   {
1293      prefetch_and_decode();
1294      return;
1295   }
1296
1297   // Check interrupt lines
1298   if (m_nmi_active)
1299   {
1300      if (VERBOSE>7) LOG("tms9995: Checking interrupts ... NMI active\n");
1301      m_int_pending |= PENDING_NMI;
1302      m_idle_state = false;
1303      PC = (PC + 2) & 0xfffe;      // we have not prefetched the next instruction
1304   }
1305   else
1306   {
1307      m_int_pending = 0;
1308
1309      if (m_int1_active && intmask >= 1 && check_int) m_int_pending |= PENDING_LEVEL1;
1310      if (m_int_overflow && intmask >= 2 && check_int) m_int_pending |= PENDING_OVERFLOW;
1311      if (m_int_decrementer && intmask >= 3 && check_int) m_int_pending |= PENDING_DECR;
1312      if (m_int4_active && intmask >= 4 && check_int) m_int_pending |= PENDING_LEVEL4;
1313
1314      if (m_int_pending!=0)
1315      {
1316         if (m_idle_state)
1317         {
1318            m_idle_state = false;
1319            if (VERBOSE>7) LOG("tms9995: Interrupt occured, terminate IDLE state\n");
1320         }
1321         PC = PC + 2;      // PC must be advanced (see flow chart), but no prefetch
1322         if (VERBOSE>7) LOG("tms9995: Interrupts pending; no prefetch; advance PC to %04x\n", PC);
1323      }
1324      else
1325      {
1326         if (VERBOSE>7) LOG("tms9995: Checking interrupts ... none pending\n");
1327         // No pending interrupts
1328         if (check_idle && m_idle_state)
1329         {
1330            if (VERBOSE>7) LOG("tms9995: IDLE state\n");
1331            // We are IDLE, stay in the loop and do not advance the PC
1332            m_pass = 2;
1333            pulse_clock(1);
1334         }
1335         else
1336         {
1337            prefetch_and_decode();
1338         }
1339      }
1340   }
1341}
1342
1343/*
1344    The actual prefetch operation, but without the interrupt check. This one is
1345    needed when we complete the interrupt handling and need to get the next
1346    instruction. According to the flow chart in [1], the prefetch after the
1347    interrupt handling ignores other pending interrupts.
1348*/
1349void tms9995_device::prefetch_and_decode()
1350{
1351   if (m_lowbyte)
1352   {
1353      // Second pass for getting the instruction
1354      if (VERBOSE>6) LOG("tms9995: Prefetch memory access (second pass)\n");
1355      word_read();
1356      decode(m_current_value);         // This is for free; in reality it is in parallel with the next memory operation
1357      m_address = m_address_copy;      // restore m_address
1358      m_current_value = m_value_copy;   // restore m_current_value
1359      PC = (PC + 2) & 0xfffe;      // advance PC
1360      m_iaq_line(CLEAR_LINE);
1361      if (VERBOSE>5) LOG("tms9995: ++++ Prefetch done ++++\n");
1362      m_lowbyte = false;
1363   }
1364   else
1365   {
1366      // Fetch next instruction
1367      // Save these values; they have been computed during the current instruction execution
1368      m_address_copy = m_address;
1369      m_value_copy = m_current_value;
1370
1371      m_iaq_line(ASSERT_LINE);
1372
1373      m_address = PC;
1374
1375      if (VERBOSE>5) LOG("tms9995: **** Prefetching new instruction at %04x ****\n", PC);
1376
1377      m_lowbyte = false;   // for mem_read
1378      word_read();         // this is where the clock pulses occur
1379
1380      if (!m_lowbyte)
1381      {
1382         // Only if we got the word in one pass
1383         decode(m_current_value);   // This is for free; in reality it is in parallel with the next memory operation
1384
1385         m_address = m_address_copy;         // restore m_address
1386         m_current_value = m_value_copy;      // restore m_current_value
1387         PC = (PC + 2) & 0xfffe;      // advance PC
1388
1389         m_iaq_line(CLEAR_LINE);
1390      }
1391   }
1392}
1393
1394/*
1395    Used by the normal command completion as well as by the X operation. We
1396    assume that we have a fully decoded operation which was previously
1397    prefetched.
1398*/
1399void tms9995_device::next_command()
1400{
1401   int next = (m_instindex==0)? 1:0;
1402
1403   if (m_decoded[next].command == MID)
1404   {
1405      m_mid_flag = true;
1406      service_interrupt();
1407   }
1408   else
1409   {
1410      m_instindex = next;
1411      m_instruction = &m_decoded[m_instindex];
1412      m_get_destination = false;
1413      // This is a preset for opcodes which do not need an opcode address derivation
1414      m_address = WP + ((m_instruction->IR & 0x000f)<<1);
1415      MPC = -1;
1416      if (VERBOSE>3) LOG("tms9995: ===== Next operation %04x (%s) at %04x =====\n", m_instruction->IR, opname[m_instruction->command], PC-2);
1417      PC_debug = PC - 2;
1418      debugger_instruction_hook(*this, PC_debug);
1419      m_first_cycle = m_icount;
1420   }
1421}
1422
1423/*
1424    End of command execution
1425*/
1426void tms9995_device::command_completed()
1427{
1428   // Pseudo state at the end of the current instruction cycle sequence
1429   if (VERBOSE>4)
1430   {
1431      LOG("tms9995: +++++ Instruction %04x (%s) completed +++++\n", m_instruction->IR, opname[m_instruction->command]);
1432      int cycles =  m_first_cycle - m_icount;
1433      // Avoid nonsense values due to expired and resumed main loop
1434      if (cycles > 0 && cycles < 10000) LOG("tms9995: Consumed %d cycles\n", cycles);
1435   }
1436
1437   if (m_int_pending != 0)
1438   {
1439      service_interrupt();
1440   }
1441   else
1442   {
1443      if ((ST & ST_OE)!=0 && (ST & ST_OV)!=0 && (ST & 0x000f)>2)
1444      {
1445         service_interrupt();
1446      }
1447      else
1448      {
1449         next_command();
1450      }
1451   }
1452}
1453
1454/*
1455    Handle pending interrupts.
1456*/
1457void tms9995_device::service_interrupt()
1458{
1459   int vectorpos = 0;
1460
1461   if (m_reset)
1462   {
1463      vectorpos = 0;
1464      m_intmask = 0;   // clear interrupt mask
1465
1466      m_nmi_state = false;
1467      m_hold_state = false;
1468      m_wait_state = false;
1469      m_lowbyte = false;
1470
1471      m_pass = 0;
1472      m_instindex = 0;
1473      m_instruction = &m_decoded[m_instindex];
1474
1475      // The auto-wait state generation is turned on when the READY line is cleared
1476      // on RESET.
1477      m_auto_wait_state = !m_ready_state;
1478      if (VERBOSE>0) LOG("tms9995: RESET; automatic wait state creation is %s\n", m_auto_wait_state? "enabled":"disabled");
1479      m_ready_state = true;
1480   }
1481   else
1482   {
1483      if (m_mid_flag)
1484      {
1485         vectorpos = 0x0008;
1486         m_intmask = 0x0001;
1487         PC = (PC + 2) & 0xfffe;
1488         if (VERBOSE>7) LOG("tms9995: ***** MID pending\n");
1489      }
1490      else
1491      {
1492         if ((m_int_pending & PENDING_NMI)!=0)
1493         {
1494            vectorpos = 0xfffc;
1495            m_int_pending &= ~PENDING_NMI;
1496            m_intmask = 0;
1497            if (VERBOSE>7) LOG("tms9995: ***** NMI pending\n");
1498         }
1499         else
1500         {
1501            if ((m_int_pending & PENDING_LEVEL1)!=0)
1502            {
1503               vectorpos = 0x0004;
1504               m_int_pending &= ~PENDING_LEVEL1;
1505               m_flag[2] = false;
1506               m_intmask = 0;
1507               if (VERBOSE>7) LOG("tms9995: ***** INT1 pending\n");
1508            }
1509            else
1510            {
1511               if ((m_int_pending & PENDING_OVERFLOW)!=0)
1512               {
1513                  vectorpos = 0x0008;
1514                  m_int_pending &= ~PENDING_OVERFLOW;
1515                  m_intmask = 0x0001;
1516                  if (VERBOSE>7) LOG("tms9995: ***** OVERFL pending\n");
1517               }
1518               else
1519               {
1520                  if ((m_int_pending & PENDING_DECR)!=0)
1521                  {
1522                     vectorpos = 0x000c;
1523                     m_intmask = 0x0002;
1524                     m_int_pending &= ~PENDING_DECR;
1525                     m_flag[3] = false;
1526                     if (VERBOSE>7) LOG("tms9995: ***** DECR pending\n");
1527                  }
1528                  else
1529                  {
1530                     vectorpos = 0x0010;
1531                     m_intmask = 0x0003;
1532                     m_int_pending &= ~PENDING_LEVEL4;
1533                     m_flag[4] = false;
1534                     if (VERBOSE>7) LOG("tms9995: ***** INT4 pending\n");
1535                  }
1536               }
1537            }
1538         }
1539      }
1540   }
1541
1542   if (VERBOSE>6) LOG("tms9995: ********* triggered an interrupt with vector %04x/%04x\n", vectorpos, vectorpos+2);
1543
1544   // The microinstructions will do the context switch
1545   m_address = vectorpos;
1546   m_instruction->program = int_mp;
1547   m_instruction->state = 0;
1548   m_instruction->byteop = false;
1549   m_instruction->command = INTR;
1550   m_pass = m_reset? 1 : 2;
1551
1552   if (m_reset)
1553   {
1554      m_instruction->IR = 0x0000;
1555      m_reset = false;
1556   }
1557   MPC = 0;
1558   m_first_cycle = m_icount;
1559   m_check_ready = false;      // set to default
1560}
1561
1562/*
1563    Read memory. This method expects as input m_address, and delivers the value
1564    in m_current_value. For a single byte read, the byte is put into the high byte.
1565    This method uses the m_pass variable to achieve a two-pass handling for
1566    getting the complete word (high byte, low byte).
1567
1568    input:
1569        m_address
1570        m_lowbyte
1571    output:
1572        m_current_value
1573
1574    m_address is unchanged
1575
1576    Make sure that m_lowbyte is false on the first call.
1577*/
1578void tms9995_device::mem_read()
1579{
1580   // First determine whether the memory is inside the CPU
1581   // On-chip memory is F000 ... F0F9, F0FC-FFF9 = off-chip, FFFA/B = Decrementer
1582   // FFFC-FFFF = NMI vector (on-chip)
1583   // There is a variant of the TMS9995 with no on-chip RAM which was used
1584   // for the TI-99/8 (9537).
1585
1586   if ((m_address & 0xfffe)==0xfffa && !m_mp9537)
1587   {
1588      if (VERBOSE>5) LOG("tms9995: read decrementer\n");
1589      // Decrementer mapped into the address space
1590      m_current_value = m_decrementer_value;
1591      if (m_instruction->byteop)
1592      {
1593         if ((m_address & 1)!=1) m_current_value <<= 8;
1594         m_current_value &= 0xff00;
1595      }
1596      pulse_clock(1);
1597      return;
1598   }
1599
1600   bool onchip = (((m_address & 0xff00)==0xf000 && (m_address < 0xf0fc)) || ((m_address & 0xfffc)==0xfffc)) && !m_mp9537;
1601
1602   if (onchip)
1603   {
1604      if (VERBOSE>5) LOG("tms9995: read onchip memory (single pass, address %04x)\n", m_address);
1605
1606      // Ignore the READY state
1607      m_check_ready = false;
1608      // We put fffc-ffff back into the f000-f0ff area
1609      m_current_value = m_onchip_memory[m_address & 0x00ff]<<8;
1610      if (m_word_access || !m_instruction->byteop)
1611      {
1612         // We have a word operation; add the low byte right here (just 1 cycle)
1613         m_current_value |= (m_onchip_memory[(m_address & 0x00ff)+1] & 0xff);
1614      }
1615   }
1616   else
1617   {
1618      // This is a off-chip access
1619      m_check_ready = true;
1620      if (m_lowbyte)
1621      {
1622         // This is always the odd address
1623         // With the OR we can ensure that we do not skip to an even address
1624         // when we try to read a word from an odd address
1625         m_current_value |= m_prgspace->read_byte(m_address | 0x0001);
1626         m_lowbyte = false;
1627         if (VERBOSE>3) LOG("tms9995: read external memory, second pass (address %04x, complete word = %04x)\n", m_address | 1, m_current_value);
1628         m_check_hold = true;
1629      }
1630      else
1631      {
1632         UINT16 address = m_address;
1633         if (m_word_access || !m_instruction->byteop)
1634         {
1635            // We have to come here a second time; do not advance the MPC
1636            // if the address value is even
1637            m_lowbyte = true;
1638            m_pass = 2;
1639            address &= 0xfffe;
1640            m_check_hold = false;
1641         }
1642         m_current_value = m_prgspace->read_byte(address) << 8;
1643         if (VERBOSE>3)
1644         {
1645            if (m_pass==2) LOG("tms9995: read external memory, first pass (address %04x, value %02x)\n", address, (m_current_value>>8)&0xff);
1646            else LOG("tms9995: read external memory (single pass), address %04x, value=%04x)\n", address, m_current_value);
1647         }
1648      }
1649      if (m_auto_wait_state)
1650      {
1651         if (VERBOSE>7) LOG("tms9995: Next pulse is auto wait\n");
1652         pulse_clock(1);
1653      }
1654   }
1655   pulse_clock(1);
1656}
1657
1658/*
1659    Read a word. This is independent of the byte flag of the instruction.
1660    We need this variant especially when we have to retrieve a register value
1661    in indexed addressing within a byte-oriented operation.
1662*/
1663inline void tms9995_device::word_read()
1664{
1665   m_word_access = true;
1666   mem_read();
1667   m_word_access = false;
1668}
1669
1670/*
1671    Write memory. This method expects as input m_address and m_current_value.
1672    For a single byte write, the byte to be written is expected to be in the
1673    high byte of m_current_value.
1674    This method uses the m_pass variable to achieve a two-pass handling for
1675    writing the complete word (high byte, low byte).
1676
1677    input:
1678        m_address
1679        m_lowbyte
1680        m_current_value
1681
1682    output:
1683        -
1684    m_address is unchanged
1685
1686    Make sure that m_lowbyte is false on the first call.
1687*/
1688void tms9995_device::mem_write()
1689{
1690   if ((m_address & 0xfffe)==0xfffa && !m_mp9537)
1691   {
1692      if (VERBOSE>5) LOG("tms9995: setting decrementer\n");
1693
1694      if (m_instruction->byteop)
1695      {
1696         // According to [1], section 2.3.1.2.2:
1697         // "The decrementer should always be accessed as a full word. [...]
1698         // Writing a single byte to either of the bytes of the decrementer
1699         // will result in the data byte being written into the byte specifically addressed
1700         // and random bits being written into the other byte of the decrementer."
1701
1702         // So we just don't care about the low byte.
1703         if (m_address == 0xfffb) m_current_value >>= 8;
1704
1705         // dito: "This also loads the Decrementing Register with the same count."
1706         m_starting_count_storage_register = m_decrementer_value = m_current_value;
1707      }
1708      else
1709      {
1710         m_starting_count_storage_register = m_decrementer_value = m_current_value;
1711      }
1712      pulse_clock(1);
1713      return;
1714   }
1715
1716   bool onchip = (((m_address & 0xff00)==0xf000 && (m_address < 0xf0fc)) || ((m_address & 0xfffc)==0xfffc)) && !m_mp9537;
1717
1718   if (onchip)
1719   {
1720      if (VERBOSE>3) LOG("tms9995: write to onchip memory (single pass, address %04x, value=%04x)\n", m_address, m_current_value);
1721      m_check_ready = false;
1722      m_onchip_memory[m_address & 0x00ff] = (m_current_value >> 8) & 0xff;
1723      if (m_word_access || !m_instruction->byteop)
1724      {
1725         m_onchip_memory[(m_address & 0x00ff)+1] = m_current_value & 0xff;
1726      }
1727   }
1728   else
1729   {
1730      m_check_ready = true;
1731
1732      if (m_lowbyte)
1733      {
1734         // see above in mem_read
1735         m_prgspace->write_byte(m_address | 0x0001, m_current_value & 0xff);
1736         m_lowbyte = false;
1737         if (VERBOSE>3) LOG("tms9995: write second pass (address %04x, value %02x)\n", m_address | 0x0001, m_current_value & 0xff);
1738         m_check_hold = true;
1739      }
1740      else
1741      {
1742         UINT16 address = m_address;
1743         if (m_word_access || !m_instruction->byteop)
1744         {
1745            // We have to come here a second time; do not advance the MPC
1746            // if the address value is even
1747            m_lowbyte = true;
1748            m_pass = 2;
1749            address &= 0xfffe;
1750            m_check_hold = false;
1751         }
1752         if (VERBOSE>3)
1753         {
1754            if (m_pass==2) LOG("tms9995: write external memory, first pass (address %04x, value %02x)\n", address, (m_current_value>>8)&0xff);
1755            else LOG("tms9995: write external memory (single pass), address %04x, value=%02x\n", address, (m_current_value>>8)&0xff);
1756         }
1757         m_prgspace->write_byte(address, (m_current_value >> 8)& 0xff);
1758      }
1759
1760      if (m_auto_wait_state)
1761      {
1762         if (VERBOSE>7) LOG("tms9995: Next pulse is auto wait\n");
1763         pulse_clock(1);
1764      }
1765   }
1766   pulse_clock(1);
1767}
1768
1769/*
1770    Write a word. This is independent of the byte flag of the instruction.
1771*/
1772inline void tms9995_device::word_write()
1773{
1774   m_word_access = true;
1775   mem_write();
1776   m_word_access = false;
1777}
1778
1779/*
1780    Returns from the operand address derivation.
1781*/
1782void tms9995_device::return_with_address()
1783{
1784   // Return from operand address derivation
1785   // The result should be in m_address
1786   m_instruction->program = m_caller;
1787   MPC = m_caller_MPC; // will be increased on return
1788   m_address = m_current_value + m_address_add;
1789   if (VERBOSE>7) LOG("tms9995: +++ return from operand address derivation +++\n");
1790   // no clock pulse
1791}
1792
1793/*
1794    Returns from the operand address derivation, but using the saved address.
1795    This is required when we use the auto-increment feature.
1796*/
1797void tms9995_device::return_with_address_copy()
1798{
1799   // Return from operand address derivation
1800   m_instruction->program = m_caller;
1801   MPC = m_caller_MPC; // will be increased on return
1802   m_address = m_address_saved;
1803   if (VERBOSE>7) LOG("tms9995: +++ return from operand address derivation (auto inc) +++\n");
1804   // no clock pulse
1805}
1806
1807/*
1808    CRU support code
1809    See common explanations in tms9900.c
1810
1811    The TMS9995 CRU address space is larger than the CRU space of the TMS9900:
1812    0000-fffe (even addresses) instead of 0000-1ffe. Unlike the TMS9900, the
1813    9995 uses the data bus lines D0-D2 to indicate external operations.
1814
1815    Internal CRU locations (read/write)
1816    -----------------------------------
1817    1EE0 Flag 0     Decrementer as event counter
1818    1EE2 Flag 1     Decrementer enable
1819    1EE4 Flag 2     Level 1 interrupt present (read only, also set when interrupt mask disallows interrupts)
1820    1EE6 Flag 3     Level 3 interrupt present (see above)
1821    1EE8 Flag 4     Level 4 interrupt present (see above)
1822    ...
1823    1EFE Flag 15
1824    1FDA MID flag (only indication, does not trigger when set)
1825
1826    The TMS9995 allows for wait states during external CRU access. Therefore
1827    we read one block of 8 bits in one go (as given by the MESS architecture)
1828    but we do iterations for each bit, checking every time for the READY line
1829    in the main loop.
1830
1831        (write)
1832        m_cru_output
1833        m_cru_address
1834        m_cru_value
1835        m_count
1836
1837*/
1838
1839#define CRUREADMASK 0x0fff
1840#define CRUWRITEMASK 0x7fff
1841
1842void tms9995_device::cru_output_operation()
1843{
1844   if (VERBOSE>5) LOG("tms9995: CRU output operation, address %04x, value %d\n", m_cru_address, m_cru_value & 0x01);
1845
1846   if (m_cru_address == 0x1fda)
1847   {
1848      // [1], section 2.3.3.2.2: "setting the MID to one with a CRU instruction
1849      // will not cause the MID interrupt to be requested."
1850      m_check_ready = false;
1851      m_mid_flag = (m_cru_value & 0x01);
1852   }
1853   else
1854   {
1855      if ((m_cru_address & 0xffe0) == 0x1ee0)
1856      {
1857         m_check_ready = false;
1858         // FLAG2, FLAG3, and FLAG4 are read-only
1859         if ((m_cru_address != 0x1ee4) && (m_cru_address != 0x1ee6) && (m_cru_address != 0x1ee8))
1860            m_flag[(m_cru_address>>1)&0x000f] = (m_cru_value & 0x01);
1861      }
1862      else
1863      {
1864         // External access
1865         m_check_ready = true;
1866      }
1867   }
1868
1869   // All CRU write operations are visible to the outside world, even when we
1870   // have internal access. This makes it possible to assign special
1871   // functions to the internal flag bits which are realized outside
1872   // of the CPU. However, no wait states are generated for internal
1873   // accesses. ([1], section 2.3.3.2)
1874
1875   m_cru->write_byte((m_cru_address >> 1)& CRUWRITEMASK, (m_cru_value & 0x01));
1876   m_cru_value >>= 1;
1877   m_cru_address = (m_cru_address + 2) & 0xfffe;
1878   m_count--;
1879
1880   // Repeat this operation
1881   m_pass = (m_count > 0)? 2 : 1;
1882   pulse_clock(2);
1883}
1884
1885/*
1886    Input: (read)
1887        m_cru_multi_first
1888        m_cru_address
1889    Output:
1890        m_cru_value (right-shifted; i.e. first bit is LSB of the 16 bit word,
1891        also for byte operations)
1892*/
1893
1894void tms9995_device::cru_input_operation()
1895{
1896   UINT16 crubit;
1897   UINT8 crubyte;
1898
1899   // Reading is different, since MESS uses 8 bit transfers
1900   // We read 8 bits in one go, then iterate another min(n-1,7) times to allow
1901   // for wait states.
1902
1903   // read_byte for CRU delivers the first bit on the rightmost position
1904
1905   int offset = (m_cru_address>>1) & 0x07;
1906
1907   if (m_cru_first_read || m_cru_bits_left == 0)
1908   {
1909      // Read next 8 bits
1910      // 00000000 0rrrrrrr r
1911      //                   v
1912      // ........ ........ X....... ........
1913      //
1914      crubyte = m_cru->read_byte((m_cru_address >> 4)& CRUREADMASK);
1915      if (VERBOSE>8) LOG("tms9995: Need to get next 8 bits (addresses %04x-%04x): %02x\n", (m_cru_address&0xfff0)+14, m_cru_address&0xfff0, crubyte);
1916      m_cru_read = crubyte << 15;
1917      m_cru_bits_left = 8;
1918
1919      if (m_cru_first_read)
1920      {
1921         m_cru_read >>= offset;
1922         m_cru_bits_left -= offset;
1923         m_parity = 0;
1924         m_cru_value = 0;
1925         m_cru_first_read = false;
1926         m_pass = m_count;
1927      }
1928      if (VERBOSE>8) LOG("tms9995: adjusted value for shift: %06x\n", m_cru_read);
1929   }
1930
1931   crubit = (m_cru_read & 0x8000);
1932   m_cru_value = (m_cru_value >> 1) & 0x7fff;
1933
1934   // During internal reading, the CRUIN line will be ignored. We emulate this
1935   // by overwriting the bit which we got from outside. Also, READY is ignored.
1936   if (m_cru_address == 0x1fda)
1937   {
1938      crubit = m_mid_flag? 0x8000 : 0x0000;
1939      m_check_ready = false;
1940   }
1941   else
1942   {
1943      if ((m_cru_address & 0xffe0)==0x1ee0)
1944      {
1945         crubit = (m_flag[(m_cru_address>>1)&0x000f]==true)? 0x8000 : 0x0000;
1946         m_check_ready = false;
1947      }
1948      else
1949      {
1950         m_check_ready = true;
1951      }
1952   }
1953
1954   if (VERBOSE>5) LOG("tms9995: CRU input operation, address %04x, value %d\n", m_cru_address, (crubit & 0x8000)>>15);
1955
1956   m_cru_value |= crubit;
1957   if (crubit!=0) m_parity++;
1958
1959   m_cru_address = (m_cru_address + 2) & 0xfffe;
1960   m_cru_bits_left--;
1961
1962   if (m_pass > 1)
1963   {
1964      m_cru_read >>= 1;
1965   }
1966   else
1967   {
1968      // This is the final shift. For both byte and word length transfers,
1969      // the first bit is always m_cru_value & 0x0001.
1970      m_cru_value >>= (16 - m_count);
1971   }
1972   pulse_clock(2);
1973}
1974
1975/*
1976    Decrementer.
1977*/
1978void tms9995_device::trigger_decrementer()
1979{
1980   if (m_starting_count_storage_register>0) // null will turn off the decrementer
1981   {
1982      m_decrementer_value--;
1983      if (m_decrementer_value==0)
1984      {
1985         if (VERBOSE>5) LOG("tms9995: decrementer reached 0\n");
1986         m_decrementer_value = m_starting_count_storage_register;
1987         if (m_flag[1]==true)
1988         {
1989            m_flag[3] = true;
1990            m_int_decrementer = true;
1991         }
1992      }
1993   }
1994}
1995
1996/*
1997    This is a switch to a subprogram. In terms of cycles
1998    it does not take any time; execution continues with the first instruction
1999    of the subprogram.
2000
2001    input:
2002        m_get_destination
2003        m_instruction
2004        WP
2005        m_current_value
2006        m_address
2007    output:
2008        m_source_value  = m_current_value before invocation
2009        m_current_value = m_address
2010        m_address_add   = 0
2011        m_lowbyte       = false
2012        m_get_destination = true
2013        m_regnumber     = register number
2014        m_address       = address of register
2015    */
2016void tms9995_device::operand_address_subprogram()
2017{
2018   UINT16 ircopy = m_instruction->IR;
2019   if (m_get_destination) ircopy = ircopy >> 6;
2020
2021   // Save the return program and position
2022   m_caller = m_instruction->program;
2023   m_caller_MPC = MPC;
2024
2025   m_instruction->program = (UINT8*)operand_address_derivation;
2026   MPC = (ircopy & 0x0030) >> 2;
2027   m_regnumber = (ircopy & 0x000f);
2028   m_address = (WP + (m_regnumber<<1)) & 0xffff;
2029
2030   m_source_value = m_current_value;   // will be overwritten when reading the destination
2031   m_current_value = m_address;      // needed for first case
2032
2033   if (MPC==8)   // Symbolic
2034   {
2035      if (m_regnumber != 0)
2036      {
2037         if (VERBOSE>8) LOG("tms9995: indexed addressing\n");
2038         MPC = 16; // indexed
2039      }
2040      else
2041      {
2042         if (VERBOSE>8) LOG("tms9995: symbolic addressing\n");
2043         m_address = PC;
2044         PC = (PC + 2) & 0xfffe;
2045      }
2046   }
2047
2048   m_get_destination = true;
2049   m_lowbyte = false;
2050   m_address_add = 0;
2051   MPC--;      // will be increased in the mail loop
2052   if (VERBOSE>8) LOG("tms9995: *** Operand address derivation; address=%04x; index=%d\n", m_address, MPC+1);
2053}
2054
2055/*
2056    Used for register auto-increment. We have to save the address read from the
2057    register content so that we can return it at the end.
2058*/
2059void tms9995_device::increment_register()
2060{
2061   m_address_saved = m_current_value;   // need a special return so we do not lose the value
2062   m_current_value += m_instruction->byteop? 1 : 2;
2063   m_address = (WP + (m_regnumber<<1)) & 0xffff;
2064   m_lowbyte = false;
2065   pulse_clock(1);
2066}
2067
2068/*
2069    Used for indexed addressing. We store the contents of the index register
2070    in m_address_add which is set to 0 by default. Then we set the address
2071    pointer to the PC location and advance it.
2072*/
2073void tms9995_device::indexed_addressing()
2074{
2075   m_address_add = m_current_value;
2076   m_address = PC;
2077   PC = (PC + 2) & 0xfffe;
2078   m_lowbyte = false;
2079   pulse_clock(1);
2080}
2081
2082void tms9995_device::set_immediate()
2083{
2084   // Need to determine the register address
2085   m_address_saved = WP + ((m_instruction->IR & 0x000f)<<1);
2086   m_address = PC;
2087   m_source_value = m_current_value;      // needed for AI, ANDI, ORI
2088   PC = (PC + 2) & 0xfffe;
2089   m_lowbyte = false;
2090}
2091
2092/**************************************************************************
2093    Status bit operations
2094**************************************************************************/
2095
2096inline void tms9995_device::set_status_bit(int bit, bool state)
2097{
2098   if (state) ST |= bit;
2099   else ST &= ~bit;
2100   m_int_overflow = (m_check_overflow && bit == ST_OV  && ((ST & ST_OE)!=0) && state == true);
2101}
2102
2103void tms9995_device::set_status_parity(UINT8 value)
2104{
2105   int count = 0;
2106   for (int i=0; i < 8; i++)
2107   {
2108      if ((value & 0x80)!=0) count++;
2109      value <<= 1;
2110   }
2111   set_status_bit(ST_OP, (count & 1)!=0);
2112}
2113
2114inline void tms9995_device::compare_and_set_lae(UINT16 value1, UINT16 value2)
2115{
2116   set_status_bit(ST_EQ, value1 == value2);
2117   set_status_bit(ST_LH, value1 > value2);
2118   set_status_bit(ST_AGT, (INT16)value1 > (INT16)value2);
2119}
2120
2121/**************************************************************************
2122    ALU operations. The activities as implemented here are performed
2123    during the internal operations of the CPU, according to the current
2124    instruction.
2125
2126    Some ALU operations are followed by the prefetch operation. In fact,
2127    this prefetch happens in parallel to the ALU operation. In these
2128    situations we do not pulse the clock here but leave this to the prefetch
2129    operation.
2130**************************************************************************/
2131
2132void tms9995_device::alu_nop()
2133{
2134   // Do nothing (or nothing that is externally visible)
2135   pulse_clock(1);
2136   return;
2137}
2138
2139void tms9995_device::alu_add_s_sxc()
2140{
2141   // We have the source operand value in m_source_value and the destination
2142   // value in m_current_value
2143   // The destination address is still in m_address
2144   // Prefetch will not change m_current_value and m_address
2145
2146   UINT32 dest_new = 0;
2147
2148   switch (m_instruction->command)
2149   {
2150   case A:
2151   case AB:
2152      // When adding, a carry occurs when we exceed the 0xffff value.
2153      dest_new = m_current_value + m_source_value;
2154      set_status_bit(ST_C, (dest_new & 0x10000) != 0);
2155
2156      // If the result has a sign bit that is different from both arguments, we have an overflow
2157      // (i.e. getting a negative value from two positive values and vice versa)
2158      set_status_bit(ST_OV, ((dest_new ^ m_current_value) & (dest_new ^ m_source_value) & 0x8000)!=0);
2159      break;
2160   case S:
2161   case SB:
2162      dest_new = m_current_value + ((~m_source_value) & 0xffff) + 1;
2163      // Subtraction means adding the 2s complement, so the carry bit
2164      // is set whenever adding the 2s complement exceeds ffff
2165      // In fact the CPU adds the one's complement, then adds a one. This
2166      // explains why subtracting 0 sets the carry bit.
2167      set_status_bit(ST_C, (dest_new & 0x10000) != 0);
2168
2169      // If the arguments have different sign bits and the result has a
2170      // sign bit different from the destination value, we have an overflow
2171      // e.g. value1 = 0x7fff, value2 = 0xffff; value1-value2 = 0x8000
2172      // or   value1 = 0x8000, value2 = 0x0001; value1-value2 = 0x7fff
2173      // value1 is the destination value
2174      set_status_bit(ST_OV, (m_current_value ^ m_source_value) & (m_current_value ^ dest_new) & 0x8000);
2175      break;
2176   case SOC:
2177   case SOCB:
2178      dest_new = m_current_value | m_source_value;
2179      break;
2180
2181   case SZC:
2182   case SZCB:
2183      dest_new = m_current_value & ~m_source_value;
2184      break;
2185   }
2186
2187   m_current_value = (UINT16)(dest_new & 0xffff);
2188
2189   compare_and_set_lae((UINT16)(dest_new & 0xffff),0);
2190   if (m_instruction->byteop)
2191   {
2192      set_status_parity((UINT8)(dest_new>>8));
2193   }
2194   if (VERBOSE>7) LOG("tms9995: ST = %04x (val=%04x)\n", ST, m_current_value);
2195   // No clock pulse (will be done by prefetch)
2196}
2197
2198/*
2199    Branch / Branch and link. We put the source address into the PC after
2200    copying the PC into m_current_value. The address is R11. The B instruction
2201    will just ignore these settings, but BL will use them.
2202*/
2203void tms9995_device::alu_b()
2204{
2205   m_current_value = PC;
2206   PC = m_address;
2207   m_address = WP + 22;
2208}
2209
2210/*
2211    Branch and load workspace pointer. This is a branch to a subprogram with
2212    context switch.
2213*/
2214void tms9995_device::alu_blwp()
2215{
2216   int n = 1;
2217   switch (m_instruction->state)
2218   {
2219   case 0:
2220      // new WP in m_current_value
2221      m_value_copy = WP;
2222      WP = m_current_value;
2223      m_address_saved = m_address + 2;
2224      m_address = WP + 30;
2225      m_current_value = ST;
2226      break;
2227   case 1:
2228      m_current_value = PC;
2229      m_address = m_address - 2;
2230      break;
2231   case 2:
2232      m_current_value = m_value_copy;      // old WP
2233      m_address = m_address - 2;
2234      break;
2235   case 3:
2236      m_address = m_address_saved;
2237      break;
2238   case 4:
2239      PC = m_current_value;
2240      n = 0;
2241      if (VERBOSE>5) LOG("tms9995: Context switch complete; WP=%04x, PC=%04x, ST=%04x\n", WP, PC, ST);
2242      break;
2243   }
2244   m_instruction->state++;
2245   pulse_clock(n);
2246}
2247
2248/*
2249    Compare is similar to add, s, soc, szc, but we do not write a result.
2250*/
2251void tms9995_device::alu_c()
2252{
2253   // We have the source operand value in m_source_value and the destination
2254   // value in m_current_value
2255   // The destination address is still in m_address
2256   // Prefetch will not change m_current_value and m_address
2257   compare_and_set_lae(m_source_value, m_current_value);
2258   if (VERBOSE>7) LOG("tms9995: ST = %04x (val1=%04x, val2=%04x)\n", ST, m_source_value, m_current_value);
2259}
2260
2261/*
2262    Compare with immediate value.
2263*/
2264void tms9995_device::alu_ci()
2265{
2266   // We have the register value in m_source_value, the register address in m_address_saved
2267   // and the immediate value in m_current_value
2268   compare_and_set_lae(m_source_value, m_current_value);
2269   if (VERBOSE>7) LOG("tms9995: ST = %04x (val1=%04x, val2=%04x)\n", ST, m_source_value, m_current_value);
2270}
2271
2272void tms9995_device::alu_clr_seto()
2273{
2274   if (VERBOSE>7) LOG("tms9995: clr/seto: Setting values for address %04x\n", m_address);
2275   switch (m_instruction->command)
2276   {
2277   case CLR:
2278      m_current_value = 0;
2279      break;
2280   case SETO:
2281      m_current_value = 0xffff;
2282      break;
2283   }
2284   // No clock pulse, as next instruction is prefetch
2285}
2286
2287/*
2288    Unsigned division.
2289*/
2290void tms9995_device::alu_divide()
2291{
2292   int n=1;
2293   UINT32 uval32;
2294
2295   bool overflow = true;
2296   UINT16 value1;
2297
2298   switch (m_instruction->state)
2299   {
2300   case 0:
2301      m_source_value = m_current_value;
2302      // Set address of register
2303      m_address = WP + ((m_instruction->IR >> 5) & 0x001e);
2304      m_address_copy = m_address;
2305      break;
2306   case 1:
2307      // Value of register is in m_current_value
2308      // We have an overflow when the quotient cannot be stored in 16 bits
2309      // This is the case when the dividend / divisor >= 0x10000,
2310      // or equivalently, dividend / 0x10000 >= divisor
2311
2312      // Check overflow for unsigned DIV
2313      if (m_current_value < m_source_value)   // also if source=0
2314      {
2315         MPC++;   // skip the abort
2316         overflow = false;
2317      }
2318      set_status_bit(ST_OV, overflow);
2319      m_value_copy = m_current_value;         // Save the high word
2320      m_address = m_address + 2;
2321      break;
2322   case 2:
2323      // W2 is in m_current_value
2324      uval32 = (m_value_copy << 16) | m_current_value;
2325      // Calculate
2326      // The number of ALU cycles depends on the number of steps in
2327      // the division algorithm. The number of cycles is between 1 and 16
2328      // As in TMS9900, this is a guess; it depends on the actual algorithm
2329      // used in the chip.
2330
2331      m_current_value = uval32 / m_source_value;
2332      m_value_copy = uval32 % m_source_value;
2333      m_address = m_address_copy;
2334
2335      value1 = m_value_copy & 0xffff;
2336      while (value1 != 0)
2337      {
2338         value1 = (value1 >> 1) & 0xffff;
2339         n++;
2340      }
2341
2342      break;
2343   case 3:
2344      // now write the remainder
2345      m_current_value = m_value_copy;
2346      m_address = m_address + 2;
2347      break;
2348   }
2349   m_instruction->state++;
2350   pulse_clock(n);
2351}
2352
2353/*
2354    Signed Division
2355    We cannot handle this by the same ALU operation because we can NOT decide
2356    whether there is an overflow before we have retrieved the whole 32 bit
2357    word. Also, the overflow detection is pretty complicated for signed
2358    division when done before the actual calculation.
2359*/
2360void tms9995_device::alu_divide_signed()
2361{
2362   int n=1;
2363   bool overflow = true;
2364   UINT16 w1, w2, d;
2365   INT32 w;
2366
2367   switch (m_instruction->state)
2368   {
2369   case 0:
2370      // Got the source value (divisor)
2371      m_source_value = m_current_value;
2372      m_address = WP;  // DIVS always uses R0,R1
2373      break;
2374   case 1:
2375      // Value of register is in m_current_value
2376      m_value_copy = m_current_value;
2377      m_address += 2;
2378      break;
2379   case 2:
2380      // Now we have the dividend low word in m_current_value,
2381      // the dividend high word in m_value_copy, and
2382      // the divisor in m_source_value.
2383
2384      w1 = m_value_copy;
2385      w2 = m_current_value;
2386      d = m_source_value;
2387
2388      // Now check for overflow
2389      // Seems a bit complex, and don't ask me how they did it in the chip.
2390      // The basic idea is that the division of a 32-bit number by a 16-bit
2391      // number must result in a 16-bit quotient and a remainder, AND the
2392      // quotient must have positive sign when the signs of the dividend and
2393      // the divisor are equal. When any of these conditions are not met, an
2394      // overflow is indicated.
2395
2396      // Unlike with the unsigned division we cannot tell whether we will
2397      // run into an overflow before we have the complete dividend value.
2398      // It might be easier to just try and divide, but the real machine
2399      // requires much less cycles when there is an overflow, so it seems as
2400      // if this is tested before the algorithm starts.
2401
2402      if ((w1 & 0x8000)==0)      // positive dividend
2403      {
2404         if ((d & 0x8000)==0)   // positive divisor
2405         {
2406            if ((d & 1)==0)      // even divisor
2407            {
2408               if (w1 < d/2) overflow = false;
2409            }
2410            else            // odd divisor
2411            {
2412               if ((w1 < (d-1)/2) || (w1 == (d-1)/2 && w2 < 0x8000)) overflow = false;
2413            }
2414         }
2415         else               // negative divisor
2416         {
2417            d = -d;
2418            if ((d & 1)==0)      // even divisor
2419            {
2420               if ((w1 < d/2) || (w1 == d/2 && w2 < d)) overflow = false;
2421            }
2422            else            // odd divisor
2423            {
2424               if ((w1 < (d+1)/2) || (w1 == (d+1)/2 && w2 < 0x8000+d)) overflow = false;
2425            }
2426         }
2427      }
2428      else                  // negative dividend
2429      {
2430         w1 = -w1;
2431         if ((d & 0x8000)==0)   // positive divisor
2432         {
2433            if ((d & 1)==0)      // even divisor
2434            {
2435               if ((w1 < d/2+1) || (w1 == d/2+1 && w2 > (-d))) overflow = false;
2436            }
2437            else            // odd divisor
2438            {
2439               if ((w1 < (d+1)/2) || (w1 == (d+1)/2 && w2 > 0x8000-d)) overflow = false;
2440            }
2441         }
2442         else               // negative divisor
2443         {
2444            d = -d;
2445            if ((d & 1)==0)      // even divisor
2446            {
2447               if ((w1 < d/2) || (w1 == d/2 && w2 > 0)) overflow = false;
2448            }
2449            else            // odd divisor
2450            {
2451               if ((w1 < (d+1)/2) || (w1 == (d+1)/2 && w2 > 0x8000)) overflow = false;
2452            }
2453         }
2454      }
2455      set_status_bit(ST_OV, overflow);
2456      if (!overflow) MPC++;      // Skip the next microinstruction when there is no overflow
2457      break;
2458   case 3:
2459      // We are here because there was no overflow
2460      w = (m_value_copy << 16) |   m_current_value;
2461      // Do the calculation
2462      m_current_value =  (UINT16)(w / (INT16)m_source_value);
2463      m_value_copy = (UINT16)(w % (INT16)m_source_value);
2464      m_address = WP;
2465
2466      // As we have not implemented the real division algorithm we must
2467      // simulate the number of steps required for calculating the result.
2468      // This is just a guess.
2469      d = m_value_copy;
2470      while (d != 0)
2471      {
2472         d = (d >> 1) & 0xffff;
2473         n++;
2474      }
2475      // go write the quotient into R0
2476      break;
2477   case 4:
2478      // Now write the remainder
2479      m_current_value = m_value_copy;
2480      m_address += 2;
2481      n = 0;
2482      break;
2483   }
2484   m_instruction->state++;
2485   pulse_clock(n);
2486}
2487
2488/*
2489    External operations.
2490*/
2491void tms9995_device::alu_external()
2492{
2493   // Call some possibly attached external device
2494   // A specific bit pattern is put on the data bus, and the CRUOUT line is
2495   // pulsed. In our case we use a special callback function since we cannot
2496   // emulate this behavior in this implementation.
2497
2498   // Opcodes         D012 value
2499   // -----------------vvv------
2500   // IDLE = 0000 0011 0100 0000
2501   // RSET = 0000 0011 0110 0000
2502   // CKON = 0000 0011 1010 0000
2503   // CKOF = 0000 0011 1100 0000
2504   // LREX = 0000 0011 1110 0000
2505
2506   // Only IDLE has a visible effect on the CPU without external support: the
2507   // CPU will stop execution until an interrupt occurs. CKON, CKOF, LREX have
2508   // no effect without external support. Neither has RSET, it does *not*
2509   // cause a reset of the CPU or of the remaining computer system.
2510   // It only clears the interrupt mask and outputs the
2511   // external code on the data bus. A special line decoder could then trigger
2512   // a reset from outside.
2513
2514   if (m_instruction->command == IDLE)
2515      m_idle_state = true;
2516
2517   if (m_instruction->command == RSET)
2518   {
2519      ST &= 0xfff0;
2520      if (VERBOSE>3) LOG("tms9995: New ST = %04x\n", ST);
2521   }
2522
2523   m_external_operation((m_instruction->IR >> 5) & 0x07, 1);
2524}
2525
2526/*
2527    Logical compare and XOR
2528*/
2529void tms9995_device::alu_f3()
2530{
2531   switch (m_instruction->state)
2532   {
2533   case 0:
2534      // We have the contents of the source in m_current_value and its address
2535      // in m_address
2536      m_source_value = m_current_value;
2537      // Get register address
2538      m_address = WP + ((m_instruction->IR >> 5) & 0x001e);
2539      break;
2540   case 1:
2541      // Register contents -> m_current_value
2542      // Source contents -> m_source_value
2543      if (m_instruction->command == COC)
2544      {
2545         set_status_bit(ST_EQ, (m_current_value & m_source_value) == m_source_value);
2546      }
2547      else
2548      {
2549         if (m_instruction->command == CZC)
2550         {
2551            set_status_bit(ST_EQ, (~m_current_value & m_source_value) == m_source_value);
2552         }
2553         else
2554         {
2555            // XOR
2556            // The workspace register address is still in m_address
2557            m_current_value = (m_current_value ^ m_source_value);
2558            compare_and_set_lae(m_current_value, 0);
2559         }
2560      }
2561      if (VERBOSE>7) LOG("tms9995: ST = %04x\n", ST);
2562      break;
2563   }
2564   pulse_clock(1);
2565   m_instruction->state++;
2566}
2567
2568/*
2569    Handles AI, ANDI, ORI.
2570*/
2571void tms9995_device::alu_imm_arithm()
2572{
2573   UINT32 dest_new = 0;
2574
2575   // We have the register value in m_source_value, the register address in m_address_saved
2576   // and the immediate value in m_current_value
2577   switch (m_instruction->command)
2578   {
2579   case AI:
2580      dest_new = m_current_value + m_source_value;
2581      set_status_bit(ST_C, (dest_new & 0x10000) != 0);
2582
2583      // If the result has a sign bit that is different from both arguments, we have an overflow
2584      // (i.e. getting a negative value from two positive values and vice versa)
2585      set_status_bit(ST_OV, ((dest_new ^ m_current_value) & (dest_new ^ m_source_value) & 0x8000)!=0);
2586      break;
2587   case ANDI:
2588      dest_new = m_current_value & m_source_value;
2589      break;
2590   case ORI:
2591      dest_new = m_current_value | m_source_value;
2592      break;
2593   }
2594
2595   m_current_value = (UINT16)(dest_new & 0xffff);
2596   compare_and_set_lae(m_current_value, 0);
2597   m_address = m_address_saved;
2598   if (VERBOSE>7) LOG("tms9995: ST = %04x (val=%04x)\n", ST, m_current_value);
2599}
2600
2601/*
2602    Handles all jump instructions.
2603*/
2604void tms9995_device::alu_jump()
2605{
2606   bool cond = false;
2607   INT8 displacement = (m_instruction->IR & 0xff);
2608
2609   switch (m_instruction->command)
2610   {
2611   case JMP:
2612      cond = true;
2613      break;
2614   case JLT:   // LAECOP == x00xxx
2615      cond = ((ST & (ST_AGT | ST_EQ))==0);
2616      break;
2617   case JLE:   // LAECOP == 0xxxxx
2618      cond = ((ST & ST_LH)==0);
2619      break;
2620   case JEQ:   // LAECOP == xx1xxx
2621      cond = ((ST & ST_EQ)!=0);
2622      break;
2623   case JHE:   // LAECOP == 1x0xxx, 0x1xxx
2624      cond = ((ST & (ST_LH | ST_EQ)) != 0);
2625      break;
2626   case JGT:   // LAECOP == x1xxxx
2627      cond = ((ST & ST_AGT)!=0);
2628      break;
2629   case JNE:   // LAECOP == xx0xxx
2630      cond = ((ST & ST_EQ)==0);
2631      break;
2632   case JNC:   // LAECOP == xxx0xx
2633      cond = ((ST & ST_C)==0);
2634      break;
2635   case JOC:   // LAECOP == xxx1xx
2636      cond = ((ST & ST_C)!=0);
2637      break;
2638   case JNO:   // LAECOP == xxxx0x
2639      cond = ((ST & ST_OV)==0);
2640      break;
2641   case JL:   // LAECOP == 0x0xxx
2642      cond = ((ST & (ST_LH | ST_EQ)) == 0);
2643      break;
2644   case JH:   // LAECOP == 1xxxxx
2645      cond = ((ST & ST_LH)!=0);
2646      break;
2647   case JOP:   // LAECOP == xxxxx1
2648      cond = ((ST & ST_OP)!=0);
2649      break;
2650   }
2651
2652   if (!cond)
2653   {
2654      if (VERBOSE>7) LOG("tms9995: Jump condition false\n");
2655   }
2656   else
2657   {
2658      if (VERBOSE>7) LOG("tms9995: Jump condition true\n");
2659      PC = PC + (displacement<<1);
2660   }
2661   pulse_clock(1);
2662}
2663
2664/*
2665    Implements LDCR.
2666*/
2667void tms9995_device::alu_ldcr()
2668{
2669   switch (m_instruction->state)
2670   {
2671   case 0:
2672      m_count = (m_instruction->IR >> 6) & 0x000f;
2673      if (m_count==0) m_count = 16;
2674      m_instruction->byteop = (m_count<9);
2675      break;
2676   case 1:
2677      // We have read the byte or word into m_current_value.
2678      compare_and_set_lae(m_current_value, 0);
2679      if (VERBOSE>7) LOG("tms9995: ST = %04x (val=%04x)\n", ST, m_current_value);
2680      if (m_instruction->byteop)
2681      {
2682         m_current_value = (m_current_value>>8) & 0xff;
2683         set_status_parity((UINT8)m_current_value);
2684      }
2685      m_cru_value = m_current_value;
2686      m_address = WP + 24;
2687      break;
2688   case 2:
2689      // Prepare CRU operation
2690      m_cru_address = m_current_value;
2691      break;
2692   }
2693   m_instruction->state++;
2694   pulse_clock(1);
2695}
2696
2697/*
2698    Implements LI. Almost everything has been done in the microprogram;
2699    this part is reached with m_address_saved = register address,
2700    and m_current_value = *m_address;
2701*/
2702void tms9995_device::alu_li()
2703{
2704   // Retrieve the address of the register
2705   // The immediate value is still in m_current_value
2706   m_address = m_address_saved;
2707   compare_and_set_lae(m_current_value, 0);
2708   if (VERBOSE>7) LOG("tms9995: ST = %04x (val=%04x)\n", ST, m_current_value);
2709}
2710
2711void tms9995_device::alu_limi_lwpi()
2712{
2713   // The immediate value is in m_current_value
2714   if (m_instruction->command == LIMI)
2715   {
2716      ST = (ST & 0xfff0) | (m_current_value & 0x000f);
2717      if (VERBOSE>7) LOG("tms9995: ST = %04x\n", ST);
2718      pulse_clock(1);      // needs one more than LWPI
2719   }
2720   else
2721   {
2722      WP = m_current_value;
2723      if (VERBOSE>7) LOG("tms9995: new WP = %04x\n", WP);
2724   }
2725}
2726
2727/*
2728    Load status and load workspace pointer. This is a TMS9995-specific
2729    operation.
2730*/
2731void tms9995_device::alu_lst_lwp()
2732{
2733   if (m_instruction->command==LST)
2734   {
2735      ST = m_current_value;
2736      if (VERBOSE>7) LOG("tms9995: new ST = %04x\n", ST);
2737      pulse_clock(1);
2738   }
2739   else
2740   {
2741      WP = m_current_value;
2742      if (VERBOSE>7) LOG("tms9995: new WP = %04x\n", WP);
2743   }
2744}
2745
2746/*
2747    The MOV operation on the TMS9995 is definitely more efficient than in the
2748    TMS9900. As we have only 8 data bus lines we can read or write bytes
2749    with only one cycle. The TMS9900 always has to read the memory word first
2750    in order to write back a complete word, also when doing byte operations.
2751*/
2752void tms9995_device::alu_mov()
2753{
2754   m_current_value = m_source_value;
2755   compare_and_set_lae(m_current_value, 0);
2756   if (VERBOSE>7) LOG("tms9995: ST = %04x (val=%04x)\n", ST, m_current_value);
2757   // No clock pulse, as next instruction is prefetch
2758}
2759
2760/*
2761    Unsigned and signed multiplication
2762*/
2763void tms9995_device::alu_multiply()
2764{
2765   int n = 0;
2766   UINT32 result = 0;
2767   INT32 results = 0;
2768
2769   if (m_instruction->command==MPY)
2770   {
2771      switch (m_instruction->state)
2772      {
2773      case 0:
2774         // m_current_value <- multiplier (source)
2775         m_source_value = m_current_value;
2776         // m_address is the second multiplier (in a register)
2777         m_address = ((m_instruction->IR >> 5) & 0x001e) + WP;
2778         n = 1;
2779         break;
2780      case 1:
2781         // m_current_value <- register content
2782         result = (m_source_value & 0x0000ffff) * (m_current_value & 0x0000ffff);
2783         m_current_value = (result >> 16) & 0xffff;
2784         m_value_copy = result & 0xffff;
2785         // m_address is still the register
2786         n = 16;
2787         break;
2788      case 2:
2789         m_address += 2;
2790         m_current_value = m_value_copy;
2791         // now write the lower 16 bit.
2792         // If the register was R15, do not use R0 but continue writing after
2793         // R15's address
2794         break;
2795      }
2796   }
2797   else
2798   {
2799      switch (m_instruction->state)
2800      {
2801      case 0:
2802         // m_current_value <- multiplier (source)
2803         m_source_value = m_current_value;
2804         // m_address is the second multiplier (in R0)
2805         m_address = WP;
2806         n = 1;
2807         break;
2808      case 1:
2809         // m_current_value <- register content
2810         results = ((INT16)m_source_value) * ((INT16)m_current_value);
2811         m_current_value = (results >> 16) & 0xffff;
2812         m_value_copy = results & 0xffff;
2813         // m_address is still the register
2814         n = 16;
2815         break;
2816      case 2:
2817         m_address += 2;
2818         m_current_value = m_value_copy;
2819         // now write the lower 16 bit.
2820         break;
2821      }
2822   }
2823   m_instruction->state++;
2824   pulse_clock(n);
2825}
2826
2827void tms9995_device::alu_rtwp()
2828{
2829   int n = 0;
2830   switch (m_instruction->state)
2831   {
2832   case 0:
2833      m_address = WP + 30;      // R15
2834      break;
2835   case 1:
2836      ST = m_current_value;
2837      m_address -= 2;            // R14
2838      break;
2839   case 2:
2840      PC = m_current_value;
2841      m_address -= 2;            // R13
2842      break;
2843   case 3:
2844      WP = m_current_value;
2845      n = 1;
2846      break;
2847   }
2848   m_instruction->state++;
2849   pulse_clock(n);
2850}
2851
2852void tms9995_device::alu_sbo_sbz()
2853{
2854   INT8 displacement;
2855
2856   if (m_instruction->state==0)
2857   {
2858      m_address = WP + 24;
2859   }
2860   else
2861   {
2862      m_cru_value = (m_instruction->command==SBO)? 1 : 0;
2863      displacement = (INT8)(m_instruction->IR & 0xff);
2864      m_cru_address = m_current_value + (displacement<<1);
2865      m_count = 1;
2866   }
2867   m_instruction->state++;
2868   pulse_clock(1);
2869}
2870
2871/*
2872    Perform the shift operation
2873*/
2874void tms9995_device::alu_shift()
2875{
2876   bool carry = false;
2877   bool overflow = false;
2878   UINT16 sign = 0;
2879   UINT32 value;
2880   int count;
2881
2882   switch (m_instruction->state)
2883   {
2884   case 0:
2885      // we have the value of the register in m_current_value
2886      // Save it (we may have to read R0)
2887      m_value_copy = m_current_value;
2888      m_address_saved = m_address;
2889      m_address = WP;
2890      // store this in m_current_value where the R0 value will be put
2891      m_current_value = (m_instruction->IR >> 4)& 0x000f;
2892      if (m_current_value != 0)
2893      {
2894         // skip the next read operation
2895         MPC++;
2896         pulse_clock(1);
2897      }
2898      else
2899      {
2900         if (VERBOSE>8) LOG("tms9995: Shift operation gets count from R0\n");
2901      }
2902      break;
2903
2904   case 1:
2905      count = m_current_value & 0x000f; // from the instruction or from R0
2906      if (count==0) count = 16;
2907
2908      value = m_value_copy;
2909
2910      // we are re-implementing the shift operations because we have to pulse
2911      // the clock at each single shift anyway.
2912      // Also, it is easier to implement the status bit setting.
2913      // Note that count is never 0
2914      if (m_instruction->command == SRA) sign = value & 0x8000;
2915
2916      for (int i=0; i < count; i++)
2917      {
2918         switch (m_instruction->command)
2919         {
2920         case SRL:
2921         case SRA:
2922            carry = ((value & 1)!=0);
2923            value = (value >> 1) | sign;
2924            break;
2925         case SLA:
2926            carry = ((value & 0x8000)!=0);
2927            value <<= 1;
2928            if (carry != ((value&0x8000)!=0)) overflow = true;
2929            break;
2930         case SRC:
2931            carry = ((value & 1)!=0);
2932            value = (value>>1) | (carry? 0x8000 : 0x0000);
2933            break;
2934         }
2935         pulse_clock(1);
2936      }
2937
2938      m_current_value = value & 0xffff;
2939      set_status_bit(ST_C, carry);
2940      set_status_bit(ST_OV, overflow);
2941      compare_and_set_lae(m_current_value, 0);
2942      m_address = m_address_saved;      // Register address
2943      if (VERBOSE>7) LOG("tms9995: ST = %04x (val=%04x)\n", ST, m_current_value);
2944      break;
2945   }
2946   m_instruction->state++;
2947   pulse_clock(1);
2948}
2949
2950/*
2951    Handles ABS, DEC, DECT, INC, INCT, NEG, INV
2952*/
2953void tms9995_device::alu_single_arithm()
2954{
2955   UINT32 dest_new = 0;
2956   UINT32 src_val = m_current_value & 0x0000ffff;
2957   UINT16 sign = 0;
2958   bool check_ov = true;
2959
2960   switch (m_instruction->command)
2961   {
2962   case ABS:
2963      // LAECO (from original word!)
2964      // O if >8000
2965      // C is always reset
2966      set_status_bit(ST_OV, m_current_value == 0x8000);
2967      compare_and_set_lae(m_current_value, 0);
2968
2969      if ((m_current_value & 0x8000)!=0)
2970      {
2971         dest_new = ((~src_val) & 0x0000ffff) + 1;
2972      }
2973      else
2974      {
2975         dest_new = src_val;
2976      }
2977      m_current_value = dest_new & 0xffff;
2978      return;
2979   case DEC:
2980      // LAECO
2981      // Carry for result value != 0xffff
2982      // Overflow for result value == 0x7fff
2983      dest_new = src_val + 0xffff;
2984      sign = 0x8000;
2985      break;
2986   case DECT:
2987      // Carry for result value != 0xffff / 0xfffe
2988      // Overflow for result value = 0x7fff / 0x7ffe
2989      dest_new = src_val + 0xfffe;
2990      sign = 0x8000;
2991      break;
2992   case INC:
2993      // LAECO
2994      // Overflow for result value = 0x8000
2995      // Carry for result value = 0x0000
2996      dest_new = src_val + 1;
2997      break;
2998   case INCT:
2999      // LAECO
3000      // Overflow for result value = 0x8000 / 0x8001
3001      // Carry for result value = 0x0000 / 0x0001
3002      dest_new = src_val + 2;
3003      break;
3004   case INV:
3005      // LAE
3006      dest_new = ~src_val & 0xffff;
3007      check_ov = false;
3008      break;
3009   case NEG:
3010      // LAECO
3011      // Overflow occurs for value=0x8000
3012      // Carry occurs for value=0
3013      dest_new = ((~src_val) & 0x0000ffff) + 1;
3014      check_ov = false;
3015      set_status_bit(ST_OV, src_val == 0x8000);
3016      break;
3017   case SWPB:
3018      m_current_value = ((m_current_value << 8) | (m_current_value >> 8)) & 0xffff;
3019      // I don't know what they are doing right now, but we lose a lot of cycles
3020      // according to the spec (which can indeed be proved on a real system)
3021
3022      // Maybe this command is used as a forced wait between accesses to the
3023      // video system. Usually we have two byte writes to set an address in
3024      // the VDP, with a SWPB in between. Most software for the TI-99/4A using
3025      // the TMS9900 will run into trouble when executed on the TI-99/8 with
3026      // the much faster TMS9995. So the SWPB may be used to as an intentional
3027      // slowdown.
3028
3029      // No status bits affected
3030      pulse_clock(10);
3031      return;
3032   }
3033
3034   if (check_ov) set_status_bit(ST_OV, ((src_val & 0x8000)!=sign) && ((dest_new & 0x8000)==sign));
3035   set_status_bit(ST_C, (dest_new & 0x10000) != 0);
3036   m_current_value = dest_new & 0xffff;
3037   compare_and_set_lae(m_current_value, 0);
3038
3039   if (VERBOSE>7) LOG("tms9995: ST = %04x (val=%04x)\n", ST, m_current_value);
3040   // No clock pulse, as next instruction is prefetch
3041}
3042
3043/*
3044    Store CRU.
3045*/
3046void tms9995_device::alu_stcr()
3047{
3048   int n = 1;
3049   switch (m_instruction->state)
3050   {
3051   case 0:
3052      m_count = (m_instruction->IR >> 6) & 0x000f;
3053      if (m_count == 0) m_count = 16;
3054      m_instruction->byteop = (m_count < 9);
3055      break;
3056   case 1:
3057      m_address_saved = m_address;
3058      m_address = WP + 24;
3059      break;
3060   case 2:
3061      m_cru_address = m_current_value;
3062      m_cru_first_read = true;
3063      break;
3064   case 3:
3065      // I don't know what is happening here, but it takes quite some time.
3066      // May be shift operations.
3067      m_current_value = m_cru_value;
3068      m_address = m_address_saved;
3069      compare_and_set_lae(m_current_value, 0);
3070      n = 13;
3071      if (m_instruction->byteop)
3072      {
3073         set_status_parity((UINT8)m_current_value);
3074         m_current_value <<= 8;
3075      }
3076      else n += 8;
3077      if (VERBOSE>7) LOG("tms9995: ST = %04x (val=%04x)\n", ST, m_current_value);
3078      break;
3079   }
3080   m_instruction->state++;
3081   pulse_clock(n);
3082}
3083
3084
3085/*
3086    Store status and store workspace pointer. We need to determine the
3087    address of the register here.
3088*/
3089void tms9995_device::alu_stst_stwp()
3090{
3091   m_address = WP + ((m_instruction->IR & 0x000f)<<1);
3092   m_current_value = (m_instruction->command==STST)? ST : WP;
3093}
3094
3095/*
3096    Test CRU bit.
3097*/
3098void tms9995_device::alu_tb()
3099{
3100   INT8 displacement;
3101
3102   switch (m_instruction->state)
3103   {
3104   case 0:
3105      m_address = WP + 24;
3106      pulse_clock(1);
3107      break;
3108   case 1:
3109      displacement = (INT8)(m_instruction->IR & 0xff);
3110      m_cru_address = m_current_value + (displacement<<1);
3111      m_cru_first_read = true;
3112      m_count = 1;
3113      pulse_clock(1);
3114      break;
3115   case 2:
3116      set_status_bit(ST_EQ, m_cru_value!=0);
3117      if (VERBOSE>7) LOG("tms9995: ST = %04x\n", ST);
3118      break;
3119   }
3120   m_instruction->state++;
3121}
3122
3123/*
3124    Execute. This operation is substituted after reading the word at the
3125    given address.
3126*/
3127void tms9995_device::alu_x()
3128{
3129   // We have the word in m_current_value. This word must now be decoded
3130   // as if it has been acquired by the normal procedure.
3131   decode(m_current_value);
3132   pulse_clock(1);
3133
3134   // Switch to the prefetched and decoded instruction
3135   next_command();
3136}
3137
3138/*
3139    XOP operation.
3140*/
3141void tms9995_device::alu_xop()
3142{
3143   int n = 1;
3144   switch (m_instruction->state)
3145   {
3146   case 0:
3147      // we have the source address in m_address
3148      m_address_saved = m_address;
3149      // Format is xxxx xxnn nnxx xxxx
3150      m_address = 0x0040 + ((m_instruction->IR & 0x03c0)>>4);
3151      break;
3152   case 1:
3153      // m_current_value is new WP
3154      m_value_copy = WP;   // store this for later
3155      WP = m_current_value;
3156      m_address = WP + 0x0016; // Address of new R11
3157      m_current_value = m_address_saved;
3158      break;
3159   case 2:
3160      m_address = WP + 0x001e;
3161      m_current_value = ST;
3162      break;
3163   case 3:
3164      m_address = WP + 0x001c;
3165      m_current_value = PC;
3166      break;
3167   case 4:
3168      m_address = WP + 0x001a;
3169      m_current_value = m_value_copy;
3170      break;
3171   case 5:
3172      m_address = 0x0042 + ((m_instruction->IR & 0x03c0)>>4);
3173      break;
3174   case 6:
3175      PC = m_current_value;
3176      set_status_bit(ST_X, true);
3177      n = 0;
3178      break;
3179   }
3180   m_instruction->state++;
3181   pulse_clock(n);
3182}
3183
3184/*
3185    Handle an interrupt. The behavior as implemented here follows
3186    exactly the flowchart in [1]
3187*/
3188void tms9995_device::alu_int()
3189{
3190   int pulse = 1;
3191
3192   switch (m_instruction->state)
3193   {
3194   case 0:
3195      PC = (PC - 2) & 0xfffe;
3196      m_address_saved = m_address;
3197      if (VERBOSE>7) LOG("tms9995: interrupt service (0): Prepare to read vector\n");
3198      break;
3199   case 1:
3200      pulse = 2;               // two cycles (with the one at the end)
3201      m_source_value = WP;      // old WP
3202      WP = m_current_value;      // new WP
3203      m_current_value = ST;
3204      m_address = (WP + 30)&0xfffe;
3205      if (VERBOSE>7) LOG("tms9995: interrupt service (1): Read new WP = %04x, save ST to %04x\n", WP, m_address);
3206      break;
3207   case 2:
3208      m_address = (WP + 28)&0xfffe;
3209      m_current_value = PC;
3210      if (VERBOSE>7) LOG("tms9995: interrupt service (2): Save PC to %04x\n", m_address);
3211      break;
3212   case 3:
3213      m_address = (WP + 26)&0xfffe;
3214      m_current_value = m_source_value;   // old WP
3215      if (VERBOSE>7) LOG("tms9995: interrupt service (3): Save WP to %04x\n", m_address);
3216      break;
3217   case 4:
3218      m_address = (m_address_saved + 2) & 0xfffe;
3219      if (VERBOSE>7) LOG("tms9995: interrupt service (4): Read PC from %04x\n", m_address);
3220      break;
3221   case 5:
3222      PC = m_current_value;
3223      ST = (ST & 0xfe00) | m_intmask;
3224      if (VERBOSE>5) LOG("tms9995: interrupt service (5): Context switch complete; WP=%04x, PC=%04x, ST=%04x\n", WP, PC, ST);
3225
3226      if (((m_int_pending & PENDING_MID)!=0) && m_nmi_active)
3227      {
3228         if (VERBOSE>5) LOG("tms9995: interrupt service (5): NMI active after context switch\n");
3229         m_int_pending &= ~PENDING_MID;
3230         m_address = 0xfffc;
3231         m_intmask = 0;
3232         MPC = 0;   // redo the interrupt service for the NMI
3233      }
3234      else
3235      {
3236         if (m_reset)
3237         {
3238            if (VERBOSE>5) LOG("tms9995: interrupt service (5): RESET completed\n");
3239            // We came from the RESET interrupt
3240            m_reset = false;
3241            ST &= 0x01ff;
3242            m_mid_flag = false;
3243            // FLAG0 and FLAG1 are also set to zero after RESET ([1], sect. 2.3.1.2.2)
3244            for (int i=0; i < 5; i++) m_flag[i] = false;
3245            m_check_hold = true;
3246         }
3247      }
3248      pulse = 0;
3249      break;
3250
3251      // If next instruction is MID opcode we will detect this in command_completed
3252   }
3253   m_instruction->state++;
3254   pulse_clock(pulse);
3255}
3256
3257/**************************************************************************/
3258UINT32 tms9995_device::execute_min_cycles() const
3259{
3260   return 2;
3261}
3262
3263UINT32 tms9995_device::execute_max_cycles() const
3264{
3265   return 44;
3266}
3267
3268UINT32 tms9995_device::execute_input_lines() const
3269{
3270   return 2;
3271}
3272
3273UINT32 tms9995_device::disasm_min_opcode_bytes() const
3274{
3275   return 2;
3276}
3277
3278UINT32 tms9995_device::disasm_max_opcode_bytes() const
3279{
3280   return 6;
3281}
3282
3283offs_t tms9995_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options)
3284{
3285   return Dasm9900(buffer, pc, TMS9995_ID, oprom, opram);
3286}
3287
3288
3289const device_type TMS9995 = &device_creator<tms9995_device>;
src/emu/cpu/tms9900/tms9900.c
r15423r15424
11/*
2    Generate the tms9900 emulator
2    Texas Instruments TMS9900
3
4                    +--------------------+
5               V_BB | 1  o             64| /HOLD
6               V_CC | 2                63| /MEMEN
7               WAIT | 3                62| READY
8              /LOAD | 4                61| /WE
9              HOLDA | 5                60| CRUCLK
10             /RESET | 6                59| V_CC
11                IAQ | 7                58| -
12               PHI1 | 8                57| -
13               PHI2 | 9                56| D15   -+  LSB
14     LSB  +-    A14 |10                55| D14    |
15          |     A13 |11                54| D13    |
16          |     A12 |12                53| D12    |
17          |     A11 |13                52| D11    |
18  Address |     A10 |14   +--------+   51| D10    | Data
19    bus   |      A9 |15   |        |   50| D9     | bus
20   32K *  |      A8 |16   |        |   49| D8     | 16 bit
21   16bit  |      A7 |17   |        |   48| D7     |
22          |      A6 |18   |        |   47| D6     |
23          |      A5 |19   +--------+   46| D5     |
24          |      A4 |20                45| D4     |
25          |      A3 |21                44| D3     |
26          |      A2 |22                43| D2     |
27          |      A1 |23                42| D1     |
28     MSB  +-     A0 |24                41| D0    -+  MSB
29               PHI4 |25                40| V_SS
30               V_SS |26                39| -
31               V_DD |27                38| -
32               PHI3 |28                37| -
33               DBIN |29                36| IC0   -+ MSB
34             CRUOUT |30                35| IC1    | Interrupt
35              CRUIN |31                34| IC2    | level
36            /INTREQ |32                33| IC3   -+ LSB
37                    +--------------------+
38
39       WAIT   out   Processor in wait state
40      /LOAD    in   Non-maskable interrupt
41      HOLDA   out   Hold acknowledge
42     /RESET    in   Reset
43        IAQ   out   Instruction acquisition
44     PHI1-4    in   Clock phase inputs
45       DBIN   out   Data bus in input mode
46     CRUOUT   out   Communication register unit data output
47      CRUIN    in   Communication register unit data input
48    /INTREQ    in   Interrupt request
49     CRUCLK   out   Communication register unit clock output
50        /WE   out   Data available for memory write
51      READY    in   Memory ready for access
52     /MEMEN   out   Address bus contains memory address
53      /HOLD    in   External device acquires address and data bus lines
54
55      V_BB     -5V  supply
56      V_CC     +5V  supply (pins 2 and 59 connected in parallel)
57      V_DD    +12V  supply
58      V_SS      0V  Ground reference (pins 26 and 40 connected in parallel)
59
60      A0-A14  out   Address bus (32768 words of 16 bit width)
61      D0-A15  i/o   Data bus
62     IC0-IC3   in   Interrupt level (0-15)
63
64     Note that Texas Instruments' bit numberings define bit 0 as the
65     most significant bit (different to most other systems). Also, the
66     system uses big-endian memory organisation: Storing the word 0x1234 at
67     address 0x0000 means that the byte 0x12 is stored at 0x0000 and byte 0x34
68     is stored at 0x0001.
69
70     The processor also knows byte-oriented operations (like add byte (AB),
71     move byte (MOVB)). This makes it necessary for the CPU to read the word
72     from the target memory location first, change the respective byte, and
73     write it back.
74
75     See the TI-99/4A driver for an application of the TMS9900 processor
76     within an 8-bit data bus board layout (using a data bus multiplexer).
77
78     Subcycle handling
79
80     In this implementation we try to emulate the internal operations as
81     precisely as possible, following the technical specifications. We need
82     not try to be clock-precise with every tick; it suffices to perform
83     the proper number of operations within a given time span.
84
85     For each command the CPU executes a microprogram which requires some
86     amount of cycles to complete. During this time the external clock continues
87     to issue pulses which can be used to control wait state creation. As we
88     do not emulate external clocks this implementation offers an extra output
89     "clock_out" (which, however, is available for the TMS9995) which pulses
90     at a rate of 3 MHz. External devices (e.g. memory controllers) may count
91     the pulses and pull down the READY line (with set_ready) as needed.
92
93     Another possibility for creating wait states is to pull down the line
94     for some time set by a timer. This is done, for example, by circuits like
95     GROMs or speech synthesis processors (TMS52xx).
96
97    TODO:
98    - Fine-tune cycles
99    - State save
100    - HOLD state should be tested; I don't have test cases yet
101
102    Michael Zapf, June 2012
3103*/
4104
5#include "emu.h"
6#include "debugger.h"
7105#include "tms9900.h"
8106
9#define TMS99XX_MODEL TMS9900_ID
107/* tms9900 ST register bits. */
108enum
109{
110   ST_LH = 0x8000,      // Logical higher (unsigned comparison)
111   ST_AGT = 0x4000,   // Arithmetical greater than (signed comparison)
112   ST_EQ = 0x2000,      // Equal
113   ST_C = 0x1000,      // Carry
114   ST_OV = 0x0800,      // Overflow (when using signed operations)
115   ST_OP = 0x0400,      // Odd parity (used with byte operations)
116   ST_X = 0x0200,      // XOP
117   ST_IM = 0x000f      // Interrupt mask
118};
10119
11#include "99xxcore.h"
120enum
121{
122   LOAD_INT = -1,
123   RESET_INT = -2
124};
12125
13DEFINE_LEGACY_CPU_DEVICE(TMS9900, tms9900);
126#define LOG logerror
127#define VERBOSE 1
128
129/****************************************************************************
130    Constructor
131****************************************************************************/
132
133tms9900_device::tms9900_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
134   : cpu_device(mconfig, TMS9900, "TMS9900", tag, owner, clock),
135     m_program_config("program", ENDIANNESS_BIG, 16, 16),
136     m_io_config("cru", ENDIANNESS_BIG, 8, 16),
137     m_prgspace(NULL),
138     m_cru(NULL)
139{
140}
141
142enum
143{
144   TMS9900_PC=0, TMS9900_WP, TMS9900_STATUS, TMS9900_IR,
145   TMS9900_R0, TMS9900_R1, TMS9900_R2, TMS9900_R3,
146   TMS9900_R4, TMS9900_R5, TMS9900_R6, TMS9900_R7,
147   TMS9900_R8, TMS9900_R9, TMS9900_R10, TMS9900_R11,
148   TMS9900_R12, TMS9900_R13, TMS9900_R14, TMS9900_R15
149};
150
151void tms9900_device::device_start()
152{
153   const tms9900_config *conf = reinterpret_cast<const tms9900_config *>(static_config());
154
155   assert (conf != NULL);
156
157   // TODO: Restore state save feature
158
159   m_prgspace = space(AS_PROGRAM);                  // dimemory.h
160   m_cru = space(AS_IO);
161
162   // Resolve our external connections
163   m_external_operation.resolve(conf->external_callback, *this);
164   m_get_ic0123.resolve(conf->irq_level, *this);
165   m_iaq_line.resolve(conf->instruction_acquisition, *this);
166   m_clock_out_line.resolve(conf->clock_out, *this);
167   m_wait_line.resolve(conf->wait_line, *this);
168   m_holda_line.resolve(conf->holda_line, *this);
169
170   // set our instruction counter
171   m_icountptr = &m_icount;
172
173   // add the states for the debugger
174   for (int i=0; i < 20; i++)
175   {
176      // callimport = need to use the state_import method to write to the state variable
177      // callexport = need to use the state_export method to read the state variable
178      state_add(i, s_statename[i], m_state_any).callimport().callexport().formatstr("%04X");
179   }
180   state_add(STATE_GENPC, "curpc", PC).formatstr("%4s").noshow();
181   state_add(STATE_GENFLAGS, "status", m_state_any).callimport().callexport().formatstr("%16s").noshow();
182
183   build_command_lookup_table();
184}
185
186void tms9900_device::device_stop()
187{
188   int k = 0;
189   if (VERBOSE>8) LOG("tms9900: Deleting lookup tables\n");
190   while (m_lotables[k]!=NULL) delete[] m_lotables[k++];
191}
192
193/*
194    TMS9900 hard reset
195    The device reset is just the emulator's trigger for the reset procedure
196    which is invoked via the main loop.
197*/
198void tms9900_device::device_reset()
199{
200   m_reset = true;
201}
202
203const char* tms9900_device::s_statename[20] =
204{
205   "PC ", "WP ", "ST ", "IR ",
206   "R0 ", "R1 ", "R2 ", "R3 ",
207   "R4 ", "R5 ", "R6 ", "R7 ",
208   "R8 ", "R9 ", "R10", "R11",
209   "R12", "R13", "R14", "R15"
210};
211
212/*
213    Write the contents of a register by external input (debugger)
214*/
215void tms9900_device::state_import(const device_state_entry &entry)
216{
217   int index = entry.index();
218   switch (entry.index())
219   {
220      case STATE_GENFLAGS:
221         // no action here; we do not allow import, as the flags are all
222         // bits of the STATUS register
223         break;
224      case TMS9900_PC:
225         PC = (UINT16)m_state_any;
226         break;
227      case TMS9900_WP:
228         WP = (UINT16)m_state_any;
229         break;
230      case TMS9900_STATUS:
231         ST = (UINT16)m_state_any;
232         break;
233      case TMS9900_IR:
234         IR = (UINT16)m_state_any;
235         break;
236      default:
237         // Workspace registers
238         if (index <= TMS9900_R15)
239            write_workspace_register_debug(index-TMS9900_R0, (UINT16)m_state_any);
240         break;
241   }
242}
243
244/*
245    Reads the contents of a register for display in the debugger.
246*/
247void tms9900_device::state_export(const device_state_entry &entry)
248{
249   int index = entry.index();
250   switch (entry.index())
251   {
252      case STATE_GENFLAGS:
253         m_state_any = ST;
254         break;
255      case TMS9900_PC:
256         m_state_any = PC;
257         break;
258      case TMS9900_WP:
259         m_state_any = WP;
260         break;
261      case TMS9900_STATUS:
262         m_state_any = ST;
263         break;
264      case TMS9900_IR:
265         m_state_any = IR;
266         break;
267      default:
268         // Workspace registers
269         if (index <= TMS9900_R15)
270            m_state_any = read_workspace_register_debug(index-TMS9900_R0);
271         break;
272   }
273}
274
275/*
276    state_string_export - export state as a string for the debugger
277*/
278void tms9900_device::state_string_export(const device_state_entry &entry, astring &string)
279{
280   static const char *statestr = "LAECOPX-----IIII";
281   char *flags = string.stringbuffer(16);
282   UINT16 val = 0x8000;
283   if (entry.index()==STATE_GENFLAGS)
284   {
285      for (int i=0; i < 16; i++)
286      {
287         flags[i] = ((val & ST)!=0)? statestr[i] : '.';
288         val = (val >> 1) & 0x7fff;
289      }
290   }
291}
292
293/**************************************************************************/
294
295UINT16 tms9900_device::read_workspace_register_debug(int reg)
296{
297   int temp = m_icount;
298   UINT16 value = m_prgspace->read_word((WP+(reg<<1)) & 0xfffe);
299   m_icount = temp;
300   return value;
301}
302
303void tms9900_device::write_workspace_register_debug(int reg, UINT16 data)
304{
305   int temp = m_icount;
306   m_prgspace->write_word((WP+(reg<<1)) & 0xfffe, data);
307   m_icount = temp;
308}
309
310const address_space_config *tms9900_device::memory_space_config(address_spacenum spacenum) const
311{
312   switch (spacenum)
313   {
314   case AS_PROGRAM:
315      return &m_program_config;
316
317   case AS_IO:
318      return &m_io_config;
319
320   default:
321      return NULL;
322   }
323}
324
325/**************************************************************************
326    Microprograms for the CPU instructions
327
328    The actions which are specific to the respective instruction are
329    invoked by repeated calls of ALU_xxx; each call increases a state
330    variable so that on the next call, the next part can be processed.
331    This saves us a lot of additional functions.
332**************************************************************************/
333
334/*
335    Define the indices for the micro-operation table. This is done for the sake
336    of a simpler microprogram definition as an UINT8[].
337*/
338enum
339{
340   IAQ = 0,
341   MEMORY_READ,
342   MEMORY_WRITE,
343   REG_READ,
344   REG_WRITE,
345   CRU,            // 5
346   DATA_DERIVE,
347   RET,
348   END,
349   ALU_NOP,
350   ALU_CLR,         // 10
351   ALU_SETADDR,
352   ALU_ADDONE,
353   ALU_SETADDR_ADDONE,
354   ALU_PCADDR_ADVANCE,
355   ALU_SOURCE,         // 15
356   ALU_ADDREG,
357   ALU_IMM,
358   ALU_REG,
359   ALU_F1,
360   ALU_COMP,         // 20
361   ALU_F3,
362   ALU_MPY,
363   ALU_DIV,
364   ALU_XOP,
365   ALU_CLR_SWPB,      // 25
366   ALU_ABS,
367   ALU_X,
368   ALU_B,
369   ALU_BL,
370   ALU_BLWP,         // 30
371   ALU_LDCR,
372   ALU_STCR,
373   ALU_SBZ_SBO,
374   ALU_TB,
375   ALU_JMP,         // 35
376   ALU_SHIFT,
377   ALU_AI_ORI,
378   ALU_CI,
379   ALU_LI,
380   ALU_LWPI,         // 40
381   ALU_LIMI,
382   ALU_STWP_STST,
383   ALU_EXT,
384   ALU_RTWP,
385   ALU_INT            // 45
386};
387
388
389#define MICROPROGRAM(_MP) \
390   static const UINT8 _MP[] =
391
392/*
393    This is a kind of subroutine with 6 variants. Might be done in countless
394    better ways, but will suffice for now. Each variant has at most 8 steps
395    RET will return to the caller.
396    The padding simplifies the calculation of the start address: We just
397    take the Ts field as an index. In the last two cases we add an offset of 8
398    if we have an indexed (resp. a byte) operation.
399*/
400MICROPROGRAM(data_derivation)
401{
402   REG_READ, RET, 0, 0, 0, 0, 0, 0,                                    // Rx           (00)
403   0, 0, 0, 0, 0, 0, 0, 0,
404   REG_READ, ALU_SETADDR, MEMORY_READ, RET, 0, 0, 0, 0,                     // *Rx          (01)
405   0, 0, 0, 0, 0, 0, 0, 0,
406   ALU_CLR, ALU_PCADDR_ADVANCE, MEMORY_READ, ALU_ADDREG, MEMORY_READ, RET, 0, 0,   // @sym         (10)
407   REG_READ, ALU_PCADDR_ADVANCE, MEMORY_READ, ALU_ADDREG, MEMORY_READ, RET, 0, 0,   // @sym(Rx)     (10)
408   REG_READ, ALU_SETADDR_ADDONE, ALU_ADDONE, REG_WRITE, MEMORY_READ, RET, 0, 0,   // *Rx+ (word)  (11)
409   REG_READ, ALU_SETADDR_ADDONE, REG_WRITE, MEMORY_READ, RET, 0, 0, 0            // *Rx+ (byte)  (11)
410};
411
412MICROPROGRAM(f1_mp)
413{
414   ALU_NOP,
415   DATA_DERIVE,
416   ALU_SOURCE,         // Store the word
417   DATA_DERIVE,
418   ALU_F1,
419   MEMORY_WRITE,
420   END
421};
422
423MICROPROGRAM(comp_mp)
424{
425   ALU_NOP,
426   DATA_DERIVE,
427   ALU_SOURCE,
428   DATA_DERIVE,
429   ALU_COMP,
430   ALU_NOP,      // Compare operations do not write back any data
431   END
432};
433
434MICROPROGRAM(f3_mp)
435{
436   ALU_NOP,
437   DATA_DERIVE,
438   ALU_F3,
439   REG_READ,      // We have to distinguish this from the C/CB microprogram above
440   ALU_F3,
441   ALU_NOP,      // Compare operations do not write back any data
442   END
443};
444
445MICROPROGRAM(xor_mp)
446{
447   ALU_NOP,
448   DATA_DERIVE,
449   ALU_F3,
450   REG_READ,
451   ALU_F3,
452   MEMORY_WRITE,   // XOR again must write back data
453   END
454};
455
456MICROPROGRAM(mult_mp)
457{
458   ALU_NOP,
459   DATA_DERIVE,
460   ALU_MPY,      // Save the value; put register number in m_regnumber
461   REG_READ,
462   ALU_MPY,      // 18 cycles for multiplication
463   REG_WRITE,      // Write the high word
464   ALU_MPY,      // Get low word, increase m_address
465   MEMORY_WRITE,
466   END
467};
468
469MICROPROGRAM(div_mp)
470{
471   ALU_NOP,
472   DATA_DERIVE,   // Get divisor
473   ALU_DIV,      // 0 Store divisor and get register number
474   REG_READ,      // Read register
475   ALU_DIV,      // 1 Check overflow, increase address (or abort here)
476   MEMORY_READ,   // Read subsequent word (if reg=15 this is behind the workspace)
477   ALU_DIV,      // 2 Calculate quotient (takes variable amount of cycles; at least 32 machine cycles), set register number
478   REG_WRITE,      // Write quotient into register
479   ALU_DIV,      // 3 Get remainder
480   MEMORY_WRITE,   // Write remainder
481   END
482};
483
484MICROPROGRAM(xop_mp)
485{
486   ALU_NOP,
487   DATA_DERIVE,   // Get argument
488   ALU_XOP,      // 0 Save the address of the source operand, set address = 0x0040 + xopNr*4
489   MEMORY_READ,   // Read the new WP
490   ALU_XOP,      // 1 Save old WP, set new WP, get the source operand address
491   REG_WRITE,      // Write the address of the source operand into the new R11
492   ALU_XOP,      // 2
493   REG_WRITE,      // Write the ST into the new R15
494   ALU_XOP,      // 3
495   REG_WRITE,      // Write the PC into the new R14
496   ALU_XOP,      // 4
497   REG_WRITE,      // Write the WP into the new R13
498   ALU_XOP,      // 5 Set the X bit in the ST
499   MEMORY_READ,   // Read the new PC
500   ALU_XOP,      // 6 Set the new PC
501   ALU_NOP,
502   END
503};
504
505MICROPROGRAM(clr_swpb_mp)
506{
507   ALU_NOP,
508   DATA_DERIVE,
509   ALU_CLR_SWPB,
510   MEMORY_WRITE,
511   END
512};
513
514MICROPROGRAM(abs_mp)
515{
516   ALU_NOP,
517   DATA_DERIVE,
518   ALU_ABS,      // two cycles
519   MEMORY_WRITE,   // skipped when ABS is not performed
520   ALU_NOP,
521   END
522};
523
524MICROPROGRAM(x_mp)
525{
526   ALU_NOP,
527   DATA_DERIVE,
528   ALU_X,
529   END
530};
531
532MICROPROGRAM(b_mp)      // Branch
533{
534   ALU_NOP,
535   DATA_DERIVE,
536   ALU_B,
537   END
538};
539
540MICROPROGRAM(bl_mp)      // Branch and Link
541{
542   ALU_NOP,
543   DATA_DERIVE,
544   ALU_BL,            // two cycles
545   REG_WRITE,
546   END
547};
548
549MICROPROGRAM(blwp_mp)      // Branch and Load WP
550{
551   ALU_NOP,
552   DATA_DERIVE,         // Get argument
553   ALU_BLWP,            // 0 Save old WP, set new WP, save position
554   REG_WRITE,            // write ST to R15
555   ALU_BLWP,            // 1
556   REG_WRITE,            // write PC to R14
557   ALU_BLWP,            // 2
558   REG_WRITE,            // write WP to R13
559   ALU_BLWP,            // 3 Get saved position
560   MEMORY_READ,         // Read new PC
561   ALU_BLWP,            // 4 Set new PC
562   END
563};
564
565MICROPROGRAM(ldcr_mp)
566{
567   ALU_NOP,
568   DATA_DERIVE,
569   ALU_SOURCE,
570   ALU_NOP,
571   ALU_LDCR,
572   REG_READ,
573   ALU_LDCR,
574   CRU,
575   ALU_NOP,
576   END
577};
578
579MICROPROGRAM(stcr_mp)
580{
581   ALU_NOP,
582   DATA_DERIVE,
583   ALU_SOURCE,         // Store address and value
584   ALU_STCR,         // 0 Set register_number = 12
585   REG_READ,
586   ALU_STCR,         // 1 Prepare CRU access
587   CRU,
588   ALU_STCR,         // 2 Create result; Cycles = 5 + (8-#C-1) or + (16-#C)
589   MEMORY_WRITE,
590   END
591};
592
593MICROPROGRAM(sbz_sbo_mp)
594{
595   ALU_SBZ_SBO,
596   REG_READ,
597   ALU_SBZ_SBO,
598   CRU,
599   END
600};
601
602MICROPROGRAM(tb_mp)
603{
604   ALU_TB,
605   REG_READ,
606   ALU_TB,
607   CRU,
608   ALU_TB,
609   END
610};
611
612MICROPROGRAM(jmp_mp)
613{
614   ALU_NOP,
615   ALU_NOP,
616   ALU_JMP,
617   ALU_JMP,
618   END
619};
620
621MICROPROGRAM(shift_mp)
622{
623   ALU_SHIFT,
624   REG_READ,
625   ALU_SHIFT,
626   REG_READ,
627   ALU_SHIFT,
628   REG_WRITE,
629   END
630};
631
632MICROPROGRAM(ai_ori_mp)
633{
634   ALU_REG,
635   REG_READ,
636   ALU_IMM,
637   MEMORY_READ,
638   ALU_AI_ORI,
639   REG_WRITE,
640   END
641};
642
643MICROPROGRAM(ci_mp)
644{
645   ALU_REG,
646   REG_READ,
647   ALU_IMM,
648   MEMORY_READ,
649   ALU_CI,
650   ALU_NOP,
651   END
652};
653
654MICROPROGRAM(li_mp)
655{
656   ALU_IMM,
657   MEMORY_READ,
658   ALU_LI,            // sets status bits
659   ALU_REG,         // set register number
660   REG_WRITE,
661   END
662};
663
664MICROPROGRAM(lwpi_mp)
665{
666   ALU_IMM,
667   MEMORY_READ,
668   ALU_NOP,
669   ALU_LWPI,            // sets WP
670   END
671};
672
673MICROPROGRAM(limi_mp)
674{
675   ALU_IMM,
676   MEMORY_READ,
677   ALU_NOP,
678   ALU_LIMI,            // sets interrupt mask in ST
679   ALU_NOP,
680   ALU_NOP,
681   END
682};
683
684MICROPROGRAM(stwp_stst_mp)
685{
686   ALU_STWP_STST,
687   ALU_REG,
688   REG_WRITE,
689   END
690};
691
692MICROPROGRAM(external_mp)
693{
694   ALU_EXT,
695   END
696};
697
698MICROPROGRAM(rtwp_mp)      // Problem: This makes RTWP use 8 instead of 7 machine cycles.
699{
700   ALU_RTWP,
701   REG_READ,
702   ALU_RTWP,
703   REG_READ,
704   ALU_RTWP,
705   REG_READ,
706   ALU_RTWP,
707   END
708};
709
710MICROPROGRAM(int_mp)
711{
712   ALU_NOP,
713   ALU_INT,            // 0 Set address = 0
714   MEMORY_READ,
715   ALU_INT,            // 1 Save old WP, set new WP, save position
716   REG_WRITE,            // write ST to R15
717   ALU_INT,            // 2
718   REG_WRITE,            // write PC to R14
719   ALU_INT,            // 3
720   REG_WRITE,            // write WP to R13
721   ALU_INT,            // 4 Get saved position
722   MEMORY_READ,         // Read new PC
723   ALU_INT,            // 5 Set new PC
724   END
725};
726
727const tms9900_device::ophandler tms9900_device::s_microoperation[] =
728{
729   &tms9900_device::acquire_instruction,
730   &tms9900_device::mem_read,
731   &tms9900_device::mem_write,
732   &tms9900_device::register_read,
733   &tms9900_device::register_write,
734   &tms9900_device::cru_operation,
735   &tms9900_device::data_derivation_subprogram,
736   &tms9900_device::return_from_subprogram,
737   &tms9900_device::command_completed,
738
739   &tms9900_device::alu_nop,
740   &tms9900_device::alu_clear,
741   &tms9900_device::alu_setaddr,
742   &tms9900_device::alu_addone,
743   &tms9900_device::alu_setaddr_addone,
744   &tms9900_device::alu_pcaddr_advance,
745   &tms9900_device::alu_source,
746   &tms9900_device::alu_add_register,
747   &tms9900_device::alu_imm,
748   &tms9900_device::alu_reg,
749
750   &tms9900_device::alu_f1,
751   &tms9900_device::alu_comp,
752   &tms9900_device::alu_f3,
753   &tms9900_device::alu_multiply,
754   &tms9900_device::alu_divide,
755   &tms9900_device::alu_xop,
756   &tms9900_device::alu_clr_swpb,
757   &tms9900_device::alu_abs,
758   &tms9900_device::alu_x,
759   &tms9900_device::alu_b,
760   &tms9900_device::alu_bl,
761   &tms9900_device::alu_blwp,
762   &tms9900_device::alu_ldcr,
763   &tms9900_device::alu_stcr,
764   &tms9900_device::alu_sbz_sbo,
765   &tms9900_device::alu_tb,
766   &tms9900_device::alu_jmp,
767   &tms9900_device::alu_shift,
768   &tms9900_device::alu_ai_ori,
769   &tms9900_device::alu_ci,
770   &tms9900_device::alu_li,
771   &tms9900_device::alu_lwpi,
772   &tms9900_device::alu_limi,
773   &tms9900_device::alu_stwp_stst,
774   &tms9900_device::alu_external,
775   &tms9900_device::alu_rtwp,
776   &tms9900_device::alu_int
777};
778
779/*****************************************************************************
780    CPU instructions
781*****************************************************************************/
782
783/*
784    Available instructions
785*/
786enum
787{
788   ILL=0, A, AB, ABS, AI, ANDI, B, BL, BLWP, C,
789   CB, CI, CKOF, CKON, CLR, COC, CZC, DEC, DECT, DIV,
790   IDLE, INC, INCT, INV, JEQ, JGT, JH, JHE, JL, JLE,
791   JLT, JMP, JNC, JNE, JNO, JOC, JOP, LDCR, LI, LIMI,
792   LREX, LWPI, MOV, MOVB, MPY, NEG, ORI, RSET, RTWP, S,
793   SB, SBO, SBZ, SETO, SLA, SOC, SOCB, SRA, SRC, SRL,
794   STCR, STST, STWP, SWPB, SZC, SZCB, TB, X, XOP, XOR
795};
796
797static const char opname[][5] =
798{   "ILL ", "A   ", "AB  ", "ABS ", "AI  ", "ANDI", "B   ", "BL  ", "BLWP", "C   ",
799   "CI  ", "CB  ", "CKOF", "CKON", "CLR ", "COC ", "CZC ", "DEC ", "DECT", "DIV ",
800   "IDLE", "INC ", "INCT", "INV ", "JEQ ", "JGT ", "JH  ", "JHE ", "JL  ", "JLE ",
801   "JLT ", "JMP ", "JNC ", "JNE ", "JNO ", "JOC ", "JOP ", "LDCR", "LI  ", "LIMI",
802   "LREX", "LWPI", "MOV ", "MOVB", "MPY ", "NEG ", "ORI ", "RSET",   "RTWP", "S   ",
803   "SB  ", "SBO ", "SBZ ", "SETO", "SLA ", "SOC ", "SOCB", "SRA ", "SRC ", "SRL ",
804   "STCR", "STST", "STWP", "SWPB", "SZC ", "SZCB", "TB  ", "X   ", "XOP ", "XOR "
805};
806
807/*
808    Formats:
809
810          0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
811    ----+------------------------------------------------+
812    1   | Opcode | B | Td |  RegNr     | Ts |    RegNr   |
813        +--------+---+----+------------+----+------------+
814    2   |  Opcode               |      Displacement      |
815        +-----------------------+------------------------+
816    3   |  Opcode         |  RegNr     | Ts |    RegNr   |
817        +-----------------+------------+----+------------+
818    4   |  Opcode         |  Count     | Ts |    RegNr   |
819        +-----------------+------------+----+------------+
820    5   |  Opcode               |  Count    |    RegNr   |
821        +-----------------------+-----------+------------+
822    6   |  Opcode                      | Ts |    RegNr   |
823        +------------------------------+----+------------+
824    7   |  Opcode                         |0| 0| 0| 0| 0 |
825        +---------------------------------+-+--+--+--+---+
826    8   |  Opcode                         |0|    RegNr   |
827        +---------------------------------+-+------------+
828    9   |  Opcode         |   Reg/Nr   | Ts |    RegNr   |
829        +-----------------+------------+----+------------+
830*/
831
832/*
833    Defines the number of bits from the left which are significant for the
834    command in the respective format.
835*/
836static const int format_mask_len[] =
837{
838   0, 4, 8, 6, 6, 8, 10, 16, 12, 6
839};
840
841const tms9900_device::tms_instruction tms9900_device::s_command[] =
842{
843   // Opcode, ID, format, microprg
844   { 0x0200, LI, 8, li_mp },
845   { 0x0220, AI, 8, ai_ori_mp },
846   { 0x0240, ANDI, 8, ai_ori_mp },
847   { 0x0260, ORI, 8, ai_ori_mp },
848   { 0x0280, CI, 8, ci_mp },
849   { 0x02a0, STWP, 8, stwp_stst_mp },
850   { 0x02c0, STST, 8, stwp_stst_mp },
851   { 0x02e0, LWPI, 8, lwpi_mp },
852   { 0x0300, LIMI, 8, limi_mp },
853   { 0x0340, IDLE, 7, external_mp },
854   { 0x0360, RSET, 7, external_mp },
855   { 0x0380, RTWP, 7, rtwp_mp },
856   { 0x03a0, CKON, 7, external_mp },
857   { 0x03c0, CKOF, 7, external_mp },
858   { 0x03e0, LREX, 7, external_mp },
859   { 0x0400, BLWP, 6, blwp_mp },
860   { 0x0440, B, 6, b_mp },
861   { 0x0480, X, 6, x_mp },
862   { 0x04c0, CLR, 6, clr_swpb_mp },
863   { 0x0500, NEG, 6, clr_swpb_mp },
864   { 0x0540, INV, 6, clr_swpb_mp },
865   { 0x0580, INC, 6, clr_swpb_mp },
866   { 0x05c0, INCT, 6, clr_swpb_mp },
867   { 0x0600, DEC, 6, clr_swpb_mp },
868   { 0x0640, DECT, 6, clr_swpb_mp },
869   { 0x0680, BL, 6, bl_mp },
870   { 0x06c0, SWPB, 6, clr_swpb_mp },
871   { 0x0700, SETO, 6, clr_swpb_mp },
872   { 0x0740, ABS, 6, abs_mp },
873   { 0x0800, SRA, 5, shift_mp },
874   { 0x0900, SRL, 5, shift_mp },
875   { 0x0a00, SLA, 5, shift_mp },
876   { 0x0b00, SRC, 5, shift_mp },
877   { 0x1000, JMP, 2, jmp_mp },
878   { 0x1100, JLT, 2, jmp_mp },
879   { 0x1200, JLE, 2, jmp_mp },
880   { 0x1300, JEQ, 2, jmp_mp },
881   { 0x1400, JHE, 2, jmp_mp },
882   { 0x1500, JGT, 2, jmp_mp },
883   { 0x1600, JNE, 2, jmp_mp },
884   { 0x1700, JNC, 2, jmp_mp },
885   { 0x1800, JOC, 2, jmp_mp },
886   { 0x1900, JNO, 2, jmp_mp },
887   { 0x1a00, JL, 2, jmp_mp },
888   { 0x1b00, JH, 2, jmp_mp },
889   { 0x1c00, JOP, 2, jmp_mp },
890   { 0x1d00, SBO, 2, sbz_sbo_mp },
891   { 0x1e00, SBZ, 2, sbz_sbo_mp },
892   { 0x1f00, TB, 2, tb_mp },
893   { 0x2000, COC, 3, f3_mp },
894   { 0x2400, CZC, 3, f3_mp },
895   { 0x2800, XOR, 3, xor_mp },
896   { 0x2c00, XOP, 3, xop_mp },
897   { 0x3000, LDCR, 4, ldcr_mp },
898   { 0x3400, STCR, 4, stcr_mp },
899   { 0x3800, MPY, 9, mult_mp },
900   { 0x3c00, DIV, 9, div_mp },
901   { 0x4000, SZC, 1, f1_mp },
902   { 0x5000, SZCB, 1, f1_mp },
903   { 0x6000, S, 1, f1_mp },
904   { 0x7000, SB, 1, f1_mp },
905   { 0x8000, C, 1, comp_mp },
906   { 0x9000, CB, 1, comp_mp },
907   { 0xa000, A, 1, f1_mp },
908   { 0xb000, AB, 1, f1_mp },
909   { 0xc000, MOV, 1, f1_mp },
910   { 0xd000, MOVB, 1, f1_mp },
911   { 0xe000, SOC, 1, f1_mp },
912   { 0xf000, SOCB, 1, f1_mp }
913};
914
915/*
916    Create a B-tree for looking up the commands. Each node can carry up to
917    16 entries, indexed by 4 consecutive bits in the opcode.
918
919    Works as follows:
920
921    Opcode = 0201 (Load immediate value into register 1)
922    Opcode = 0284 (Compare immediate value with register 4)
923
924    Table: [ Table0, table1, table2, ... tableF ]
925               |
926       +-------+
927       v
928    table0: [ table00, table01, table02, ... table0f ]
929                                  |
930        +-------------------------+
931        v
932    table02: [ table020, table021, ... table028, ... table02f ]
933                   |         |             |
934                   v         v             v
935                 Entry      NULL          Entry
936                for LI                   for CI
937
938    For each level in the tree, four more bits are compared. The search
939    terminates when the number of compared bits is equal or higher than
940    the number of significant bits of the format of this opcode. The entry
941    points to the respective line in s_command.
942
943    This way we can decode all format 1 commands by a single pass (including the
944    most frequent command MOV), and almost all commands by less than four passes.
945
946    The disadvantage is that we have to build these tables from the opcode
947    list at runtime, and many positions are empty. But we do not need more
948    than 20 tables for the TMS command set.
949*/
950void tms9900_device::build_command_lookup_table()
951{
952   int i = 0;
953   int cmdindex = 0;
954   int bitcount;
955   const tms_instruction *inst;
956   UINT16 opcode;
957   int k = 0;
958
959   m_command_lookup_table = new lookup_entry[16];
960   // We use lotables as a list of allocated tables - to be able to delete them
961   // at the end.
962   m_lotables[k++] = m_command_lookup_table;
963
964   lookup_entry* table = m_command_lookup_table;
965   for (int j=0; j < 16; j++)
966   {
967      table[j].entry = NULL;
968      table[j].next_digit = NULL;
969   }
970
971   do
972   {
973      inst = &s_command[i];
974      table = m_command_lookup_table;
975      if (VERBOSE>8) LOG("tms9900: === opcode=%04x, len=%d\n", inst->opcode, format_mask_len[inst->format]);
976      bitcount = 4;
977      opcode = inst->opcode;
978      cmdindex = (opcode>>12) & 0x000f;
979
980      while (bitcount < format_mask_len[inst->format])
981      {
982         // Descend
983         if (table[cmdindex].next_digit == NULL)
984         {
985            if (VERBOSE>8) LOG("tms9900: create new table at bitcount=%d for index=%d\n", bitcount, cmdindex);
986            table[cmdindex].next_digit = new lookup_entry[16];
987            m_lotables[k++] = table[cmdindex].next_digit;
988            for (int j=0; j < 16; j++)
989            {
990               table[cmdindex].next_digit[j].next_digit = NULL;
991               table[cmdindex].next_digit[j].entry = NULL;
992            }
993         }
994         else
995         {
996            if (VERBOSE>8) LOG("tms9900: found a table at bitcount=%d\n", bitcount);
997         }
998
999         table = table[cmdindex].next_digit;
1000
1001         bitcount = bitcount+4;
1002         opcode <<= 4;
1003         cmdindex = (opcode>>12) & 0x000f;
1004         if (VERBOSE>8) LOG("tms9900: next index=%x\n", cmdindex);
1005      }
1006
1007      if (VERBOSE>8) LOG("tms9900: bitcount=%d\n", bitcount);
1008      // We are at the target level
1009      // Need to fill in the same entry for all values in the bitcount
1010      // (if a command needs 10 bits we have to copy it four
1011      // times for all combinations with 12 bits)
1012      for (int j=0; j < (1<<(bitcount-format_mask_len[inst->format])); j++)
1013      {
1014         if (VERBOSE>8) LOG("tms9900: opcode=%04x at position %d\n", inst->opcode, cmdindex+j);
1015         table[cmdindex+j].entry = inst;
1016      }
1017
1018      i++;
1019   } while (inst->opcode != 0xf000);
1020
1021   m_lotables[k++] = NULL;
1022   if (VERBOSE>8) LOG("tms9900: Allocated %d tables\n", k);
1023}
1024
1025/*
1026    Main execution loop
1027
1028    For each invocation of execute_run, a number of loop iterations has been
1029    calculated before (m_icount). Each loop iteration is one clock cycle.
1030    The loop must be executed for the number of times that corresponds to the
1031    time until the next timer event.
1032
1033    In this implementation, each loop iteration also causes the clock line to
1034    pulse once. External devices may use this pulse to decrement counters
1035    which control the READY line.
1036
1037    Machine cycles to clock input:
1038
1039      +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+
1040      | | | | | | | | | | | | | | | | | |  clock (1 of 4 phases)
1041    +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +
1042    |-------|-------|-------|-------|----  cycles (2 clock pulses each)
1043
1044    Wait states only have effect for memory operations. They are processed as
1045    follows:
1046
1047    1) The CPU sets the address bus for reading. If READY is low, the CPU
1048    waits for the next clock tick repeatedly until READY is high again.
1049    When this is the case, the data bus is sampled on the next clock tick
1050    and the read operation is complete.
1051
1052    As we do not have a split-phase read operation in this emulation
1053    we actually read the data bus instantly but wait for the READY line to
1054    be high again.
1055
1056    2) The CPU sets the address bus for writing. In the same moment, the data
1057    bus is loaded with the word to be written. On the next clock tick,
1058    the CPU checks the READY line and waits until it is high. When READY
1059    is high at a clock tick, the operation is complete on the next clock tick.
1060*/
1061void tms9900_device::execute_run()
1062{
1063   if (m_reset) service_interrupt();
1064
1065   if (VERBOSE>6) LOG("tms9900: calling execute_run for %d cycles\n", m_icount);
1066   do
1067   {
1068      // Only when last instruction has completed
1069      if (m_program == NULL)
1070      {
1071         if (m_load_state)
1072         {
1073            if (VERBOSE>4) LOG("tms9900: load interrupt\n");
1074            service_interrupt();
1075         }
1076         else
1077         {
1078            // Interrupts are serviced when
1079            // - an interrupt condition is signaled over INTREQ and
1080            // - the level indicated by IC0-IC3 is lower than the interrupt mask value and
1081            // - the previous instruction is not an XOP or BLWP
1082            if (m_irq_state && (m_irq_level <= (ST & 0x000f)) && (m_command != XOP && m_command != BLWP))
1083               service_interrupt();
1084         }
1085      }
1086
1087      if (m_program == NULL && m_idle_state)
1088      {
1089         if (VERBOSE>5) LOG("tms9900: idle state\n");
1090         pulse_clock(1);
1091      }
1092      else
1093      {
1094         // Handle HOLD
1095         // A HOLD request is signalled through the input line HOLD.
1096         // The hold state will be entered with the next non-memory access cycle.
1097         if (m_hold_state &&
1098            (m_program==NULL ||
1099            (m_program[MPC] != IAQ &&
1100            m_program[MPC] != MEMORY_READ && m_program[MPC] != MEMORY_WRITE &&
1101            m_program[MPC] != REG_READ && m_program[MPC] != REG_WRITE)))
1102         {
1103            if (VERBOSE>5) LOG("tms9900: hold state\n");
1104            if (!m_hold_acknowledged) acknowledge_hold();
1105            pulse_clock(1);
1106         }
1107         else
1108         {
1109            // Normal operation
1110            if (m_check_ready && m_ready_state == false)
1111            {
1112               // We are in a wait state
1113               set_wait_state(true);
1114               if (VERBOSE>5) LOG("tms9900: wait state\n");
1115               // The clock output should be used to change the state of an outer
1116               // device which operates the READY line
1117               pulse_clock(1);
1118            }
1119            else
1120            {
1121               set_wait_state(false);
1122               m_check_ready = false;
1123
1124               if (m_program==NULL) m_op = IAQ;
1125               else
1126               {
1127                  m_op = m_program[MPC];
1128                  m_iaq_line(CLEAR_LINE);
1129               }
1130               if (VERBOSE>8) LOG("tms9900: MPC = %d, m_op = %d\n", MPC, m_op);
1131               // Call the operation of the microprogram
1132               (this->*s_microoperation[m_op])();
1133               MPC++;
1134            }
1135         }
1136      }
1137   } while (m_icount>0);
1138   if (VERBOSE>6) LOG("tms9900: cycles expired; will return soon.\n");
1139}
1140
1141/**************************************************************************/
1142
1143/*
1144    Interrupt input
1145*/
1146void tms9900_device::execute_set_input(int irqline, int state)
1147{
1148   if (irqline == INPUT_LINE_NMI)
1149   {
1150      m_load_state = (state==ASSERT_LINE);
1151      m_irq_level = -1;
1152   }
1153   else
1154   {
1155      m_irq_state = (state==ASSERT_LINE);
1156      if (state==ASSERT_LINE)
1157      {
1158         m_irq_level = m_get_ic0123(0);
1159         if (VERBOSE>6) LOG("tms9900: interrupt line %d = %d, level=%d, ST=%04x\n", irqline, state, m_irq_level, ST);
1160      }
1161      else
1162      {
1163         if (VERBOSE>6) LOG("tms9900: cleared interrupt line %d\n", irqline);
1164      }
1165   }
1166}
1167
1168void tms9900_device::service_interrupt()
1169{
1170   m_program = int_mp;
1171   MPC = 0;
1172   m_idle_state = false;
1173   m_first_cycle = m_icount;
1174   m_state = 0;
1175   if (m_reset)
1176   {
1177      m_ready_state = true;
1178      m_load_state = false;
1179      m_hold_state = false;
1180      m_hold_acknowledged = false;
1181      m_wait_state = false;
1182      IR = 0;
1183      ST = 0;
1184
1185      m_reset = false;
1186      m_irq_level = RESET_INT;
1187   }
1188   if (VERBOSE>6) LOG("tms9900: ********* triggered an interrupt on level %d\n", m_irq_level);
1189}
1190
1191/*
1192    Issue a pulse on the clock line.
1193*/
1194inline void tms9900_device::pulse_clock(int count)
1195{
1196   for (int i=0; i < count; i++)
1197   {
1198      m_clock_out_line(ASSERT_LINE);
1199      m_clock_out_line(CLEAR_LINE);
1200      m_icount--;                     // This is the only location where we count down the cycles.
1201      if (VERBOSE>7) LOG("tms9900: pulse_clock\n");
1202   }
1203}
1204
1205/*
1206    Enter the hold state.
1207*/
1208void tms9900_device::set_hold(int state)
1209{
1210   m_hold_state = (state==ASSERT_LINE);
1211   if (!m_hold_state)
1212   {
1213      m_hold_acknowledged = false;
1214      m_holda_line(CLEAR_LINE);
1215   }
1216}
1217
1218/*
1219    Acknowledge the HOLD request.
1220*/
1221inline void tms9900_device::acknowledge_hold()
1222{
1223   m_hold_acknowledged = true;
1224   m_holda_line(ASSERT_LINE);
1225}
1226
1227/*
1228    Signal READY to the CPU. When cleared, the CPU enters wait states.
1229*/
1230void tms9900_device::set_ready(int state)
1231{
1232   m_ready_state = (state==ASSERT_LINE);
1233}
1234
1235void tms9900_device::abort_operation()
1236{
1237   command_completed();
1238}
1239
1240/*
1241    Enter or leave the wait state. We only operate the WAIT line when there is a change.
1242*/
1243inline void tms9900_device::set_wait_state(bool state)
1244{
1245   if (m_wait_state != state) m_wait_line(state? ASSERT_LINE : CLEAR_LINE);
1246   m_wait_state = state;
1247}
1248
1249/*
1250    Memory read:
1251    1) Pulse clock (done above)
1252    2) Set address (we also get the value right here)
1253    3) Pulse clock
1254    4) If READY=L (WAIT=H, GOTO 3) else (WAIT=L, STOP)
1255
1256    Clock cycles: 2 + W, W = number of wait states
1257*/
1258UINT16 tms9900_device::pulse_and_read_memory(UINT16 address)
1259{
1260   UINT16 value;
1261   value = m_prgspace->read_word(address & 0xfffe);
1262   pulse_clock(2);
1263   m_check_ready = true;
1264   return value;
1265}
1266
1267/*
1268    Memory write:
1269    1) Pulse clock
1270    2) Set address and write (as in the real system)
1271    3) Pulse clock
1272    4) If READY=L (WAIT=H, GOTO 3) else (WAIT=L, STOP)
1273
1274    Clock cycles: 2 + W, W = number of wait states
1275*/
1276void tms9900_device::pulse_and_write_memory(UINT16 address, UINT16 data)
1277{
1278   m_prgspace->write_word(address & 0xfffe, data);
1279   pulse_clock(2);
1280   m_check_ready = true;
1281}
1282
1283
1284/*
1285    Acquire the next word as an instruction. The program counter advances by
1286    one word.
1287*/
1288void tms9900_device::decode(UINT16 inst)
1289{
1290   int index = 0;
1291   lookup_entry* table = m_command_lookup_table;
1292   UINT16 opcode = inst;
1293   bool complete = false;
1294   const tms_instruction *decoded;
1295
1296   m_state = 0;
1297   IR = inst;
1298   m_get_destination = false;
1299
1300   while (!complete)
1301   {
1302      index = (opcode >> 12) & 0x000f;
1303      if (VERBOSE>8) LOG("tms9900: Check next hex digit of instruction %x\n", index);
1304      if (table[index].next_digit != NULL)
1305      {
1306         table = table[index].next_digit;
1307         opcode = opcode << 4;
1308      }
1309      else complete = true;
1310   }
1311   decoded = table[index].entry;
1312   if (decoded == NULL)
1313   {
1314      // not found
1315      if (VERBOSE>0) LOG("tms9900: Illegal opcode %04x\n", inst);
1316      IR = 0;
1317      // This will cause another instruction acquisition in the next machine cycle
1318      // with an asserted IAQ line (can be used to detect this illegal opcode detection).
1319      m_program = NULL;
1320   }
1321   else
1322   {
1323      m_program = decoded->prog;
1324      MPC = -1;
1325      m_command = decoded->id;
1326      if (VERBOSE>7) LOG("tms9900: Command decoded as id %d, %s, base opcode %04x\n", m_command, opname[m_command], decoded->opcode);
1327   }
1328}
1329
1330inline bool tms9900_device::byte_operation()
1331{
1332   return (IR & 0x1000)!=0;
1333}
1334
1335void tms9900_device::acquire_instruction()
1336{
1337   m_iaq_line(ASSERT_LINE);
1338   m_address = PC;
1339   m_first_cycle = m_icount;
1340   mem_read();
1341   decode(m_current_value);
1342   if (VERBOSE>3) LOG("tms9900: ===== Next operation %04x (%s) at %04x =====\n", IR, opname[m_command], PC);
1343   debugger_instruction_hook(*this, PC);
1344   PC = (PC + 2) & 0xfffe;
1345   // IAQ will be cleared in the main loop
1346}
1347
1348void tms9900_device::mem_read()
1349{
1350   m_current_value = pulse_and_read_memory(m_address);
1351   if (VERBOSE>7) LOG("tms9900: memory read %04x -> %04x\n", m_address, m_current_value);
1352}
1353
1354void tms9900_device::mem_write()
1355{
1356   pulse_and_write_memory(m_address, m_current_value);
1357   if (VERBOSE>7) LOG("tms9900: memory write %04x <- %04x\n", m_address, m_current_value);
1358}
1359
1360void tms9900_device::register_read()
1361{
1362   // Need to set m_address for F1/F3 (we don't know what the data_derive did)
1363   m_address = WP + (m_regnumber<<1);
1364   m_register_contents = m_current_value = pulse_and_read_memory(m_address);
1365   if (VERBOSE>7) LOG("tms9900: register %d read (mem %04x) -> %04x\n", m_regnumber, m_address, m_current_value);
1366}
1367
1368void tms9900_device::register_write()
1369{
1370   pulse_and_write_memory(WP + (m_regnumber<<1), m_current_value);
1371   if (VERBOSE>7) LOG("tms9900: register %d write (mem %04x) <- %04x\n", m_regnumber, WP + (m_regnumber<<1), m_current_value);
1372}
1373
1374/*
1375    CRU support code
1376
1377    The CRU bus is a 1-bit-wide I/O bus.  The CPU can read or write bits at random address.
1378    Special instructions are dedicated to reading and writing one or several consecutive bits.
1379
1380    The CRU uses the same address bus as the normal memory access. For writing,
1381    the CRUCLK line is pulsed, but not for reading where CRUCLK stays cleared.
1382    This means that each normal memory access also causes read accesses on the
1383    CRU side. The /MEMEN line may be used to distinguish the kinds of accesses
1384    as it stays cleared during CRU operations.
1385
1386    We do not emulate this here as it seems there are no real applications of
1387    this side effect. Real designs must ensure that CRU read operations are
1388    idempotent (i.e. they must not change the state of the queried device).
1389
1390    Read returns the number of consecutive CRU bits, with increasing CRU address
1391    from the least significant to the most significant bit; right-aligned
1392
1393    There seems to be no handling of wait states during CRU operations on the
1394    TMS9900. The TMS9995, in contrast, respects wait states during the transmission
1395    of each single bit.
1396
1397    Usage of this method:
1398       CRU write: First bit is at rightmost position of m_value.
1399*/
1400
1401
1402#define CRUREADMASK 0x01ff
1403#define CRUWRITEMASK 0x0fff
1404
1405void tms9900_device::cru_operation()
1406{
1407   int value, value1;
1408   int offset, location;
1409
1410   if (m_cru_output)
1411   {
1412      location = (m_cru_address >> 1)& CRUWRITEMASK;
1413      value = m_value;
1414
1415      // Write m_count bits from cru_address
1416      for (int i=0; i < m_count; i++)
1417      {
1418         m_cru->write_byte(location, (value & 0x01));
1419         value >>= 1;
1420         location = (location + 1) & CRUWRITEMASK;
1421         pulse_clock(2);
1422      }
1423   }
1424   else
1425   {
1426      location = (m_cru_address >> 4)  & CRUREADMASK;
1427      offset   = (m_cru_address>>1) & 0x07;
1428
1429      // Read 8 bits (containing the desired bits)
1430      value = m_cru->read_byte(location);
1431
1432      if ((offset + m_count) > 8)   // spans two 8 bit cluster
1433      {
1434         // Read next 8 bits
1435         location = (location + 1) & CRUREADMASK;
1436         value1 = m_cru->read_byte(location);
1437         value |= (value1 << 8);
1438
1439         if ((offset + m_count) > 16)   // spans three 8 bit cluster
1440         {
1441            // Read next 8 bits
1442            location = (location + 1) & CRUREADMASK;
1443            value1 = m_cru->read_byte(location);
1444            value |= (value1 << 16);
1445         }
1446      }
1447
1448      // On each machine cycle (2 clocks) only one CRU bit is transmitted
1449      pulse_clock(m_count<<1);
1450
1451      // Shift back the bits so that the first bit is at the rightmost place
1452      m_value = (value >> offset);
1453
1454      // Mask out what we want
1455      m_value &= (0x0000ffff >> (16-m_count));
1456   }
1457}
1458
1459void tms9900_device::return_from_subprogram()
1460{
1461   // Return from data derivation
1462   // The result should be in m_current_value
1463   // and the address in m_address
1464   m_program = m_caller;
1465   MPC = m_caller_MPC; // will be increased on return
1466}
1467
1468void tms9900_device::command_completed()
1469{
1470   // Pseudo state at the end of the current instruction cycle sequence
1471   if (VERBOSE>7)
1472   {
1473      int cycles =  m_first_cycle - m_icount;
1474      // Avoid nonsense values due to expired and resumed main loop
1475      if (cycles > 0 && cycles < 10000) LOG("tms9900: Instruction %04x (%s) consumed %d cycles\n", IR, opname[m_command], cycles);
1476   }
1477   m_program = NULL;
1478}
1479
1480/*
1481    This is a switch to a subprogram; there is only one, the data
1482    derivation. In terms of cycles, it does not take any time; execution
1483    continues with the first instruction of the subprogram.
1484*/
1485void tms9900_device::data_derivation_subprogram()
1486{
1487   UINT16 ircopy = IR;
1488
1489   // Save the return program and position
1490   m_caller = m_program;
1491   m_caller_MPC = MPC;
1492
1493   // Source or destination argument?
1494   if (m_get_destination) ircopy >>= 6;
1495
1496   m_regnumber = ircopy & 0x000f;
1497
1498   m_program = (UINT8*)data_derivation;
1499   MPC = ircopy & 0x0030;
1500
1501   if (((MPC == 0x0020) && (m_regnumber != 0))         // indexed
1502      || ((MPC == 0x0030) && ((IR & 0x1000)!=0)))      // byte flag
1503   {
1504      MPC += 8;   // the second option
1505   }
1506   m_get_destination = true;   // when we call this the second time before END it's the destination
1507   MPC--;  // will be increased on return
1508}
1509
1510
1511/**************************************************************************
1512    Status bit operations
1513**************************************************************************/
1514
1515inline void tms9900_device::set_status_bit(int bit, bool state)
1516{
1517   if (state) ST |= bit;
1518   else ST &= ~bit;
1519}
1520
1521void tms9900_device::set_status_parity(UINT8 value)
1522{
1523   int count = 0;
1524   for (int i=0; i < 8; i++)
1525   {
1526      if ((value & 0x80)!=0) count++;
1527      value <<= 1;
1528   }
1529   set_status_bit(ST_OP, (count & 1)!=0);
1530}
1531
1532inline void tms9900_device::compare_and_set_lae(UINT16 value1, UINT16 value2)
1533{
1534   set_status_bit(ST_EQ, value1 == value2);
1535   set_status_bit(ST_LH, value1 > value2);
1536   set_status_bit(ST_AGT, (INT16)value1 > (INT16)value2);
1537   if (VERBOSE>7) LOG("tms9900: ST = %04x (val1=%04x, val2=%04x)\n", ST, value1, value2);
1538}
1539
1540/**************************************************************************
1541    ALU operations
1542**************************************************************************/
1543
1544void tms9900_device::alu_nop()
1545{
1546   // Do nothing (or nothing that is externally visible)
1547   pulse_clock(2);
1548   return;
1549}
1550
1551void tms9900_device::alu_source()
1552{
1553   // Copy the current value into the source data register
1554   m_source_even = ((m_address & 1)==0);
1555   m_source_value = m_current_value;
1556   m_source_address = m_address;
1557   pulse_clock(2);
1558}
1559
1560void tms9900_device::alu_clear()
1561{
1562   // Clears the register contents
1563   m_register_contents = 0;
1564   pulse_clock(2);
1565}
1566
1567void tms9900_device::alu_setaddr()
1568{
1569   // Load the current value into the address register
1570   m_address = m_current_value;
1571   pulse_clock(2);
1572}
1573
1574void tms9900_device::alu_addone()
1575{
1576   m_current_value++;
1577   pulse_clock(2);
1578}
1579
1580void tms9900_device::alu_setaddr_addone()
1581{
1582   // Set the address register and increase the recent value
1583   m_address = m_current_value;
1584   m_current_value++;
1585   pulse_clock(2);
1586}
1587
1588void tms9900_device::alu_pcaddr_advance()
1589{
1590   // Set PC as new read address, increase by 2
1591   m_address = PC;
1592   PC = (PC+2)&0xfffe;
1593   pulse_clock(2);
1594}
1595
1596void tms9900_device::alu_add_register()
1597{
1598   // Add the register contents to the current value and set as address
1599   m_address = m_current_value + m_register_contents;
1600   pulse_clock(2);
1601}
1602
1603void tms9900_device::alu_imm()
1604{
1605   if (VERBOSE>7) LOG("tms9900: Immediate operand, reading from position %04x\n", PC);
1606   m_address = PC;
1607   PC = (PC + 2) & 0xfffe;
1608   pulse_clock(2);
1609}
1610
1611void tms9900_device::alu_reg()
1612{
1613   m_regnumber = IR & 0x000f;
1614   pulse_clock(2);
1615}
1616
1617void tms9900_device::alu_f1()
1618{
1619   UINT32 dest_new = 0;
1620
1621   // Save the destination value
1622   UINT16 prev_dest_value = m_current_value;
1623
1624   m_destination_even = ((m_address & 1)==0);   // this is the destination address; the source address has already been saved
1625   bool byteop = byte_operation();
1626
1627   if (byteop)
1628   {
1629      if (!m_destination_even) m_current_value <<= 8;
1630      if (!m_source_even) m_source_value <<= 8;
1631      // We have to strip away the low byte, or byte operations may fail
1632      // e.g. 0x10ff + 0x0101 = 0x1200
1633      // or   0x2000 - 0x0101 = 0x1eff
1634      m_source_value &= 0xff00;
1635      m_current_value &= 0xff00;
1636   }
1637
1638   switch (m_command)
1639   {
1640      case A:
1641      case AB:
1642         // Add the contents of the source data to the destination data
1643         // May exceed 0xffff (for carry check)
1644         dest_new = m_current_value + m_source_value;
1645
1646         // 1000 + e000 = f000 (L)
1647         // c000 + c000 = 8000 (LC)
1648         // 7000 + 4000 = b000 (LO)
1649         // 2000 + f000 = 1000 (LAC)
1650         // c000 + b000 = 7000 (LACO)
1651         // 2000 + e000 = 0000 (EC)
1652         // 8000 + 8000 = 0000 (ECO)
1653
1654         // When adding, a carry occurs when we exceed the 0xffff value.
1655         set_status_bit(ST_C, (dest_new & 0x10000) != 0);
1656         // If the result has a sign bit that is different from both arguments, we have an overflow
1657         // (i.e. getting a negative value from two positive values and vice versa)
1658         set_status_bit(ST_OV, ((dest_new ^ m_current_value) & (dest_new ^ m_source_value) & 0x8000)!=0);
1659         break;
1660
1661      case S:
1662      case SB:
1663         // Subtract the contents of the source data from the destination data
1664         dest_new = m_current_value + ((~m_source_value) & 0xffff) + 1;
1665         // LAECO(P)
1666         // 8000 - 8000 = 0000 (EC)
1667         // 2000 - 8000 = a000 (LO)
1668         // 8000 - 2000 = 6000 (LACO)
1669         // 2000 - 1000 = 1000 (LAC)
1670         // 1000 - 2000 = f000 (L)
1671         // 1000 - 1000 = 0000 (EC)
1672         // 1000 - f000 = 2000 (LA)
1673         // f000 - 2000 = d000 (LC)
1674
1675         // Subtraction means adding the 2s complement, so the carry bit
1676         // is set whenever adding the 2s complement exceeds ffff
1677         // In fact the CPU adds the one's complement, then adds a one. This
1678         // explains why subtracting 0 sets the carry bit.
1679         set_status_bit(ST_C, (dest_new & 0x10000) != 0);
1680
1681         // If the arguments have different sign bits and the result has a
1682         // sign bit different from the destination value, we have an overflow
1683         // e.g. value1 = 0x7fff, value2 = 0xffff; value1-value2 = 0x8000
1684         // or   value1 = 0x8000, value2 = 0x0001; value1-value2 = 0x7fff
1685         // value1 is the destination value
1686         set_status_bit(ST_OV, (m_current_value ^ m_source_value) & (m_current_value ^ dest_new) & 0x8000);
1687         break;
1688
1689      case SOC:
1690      case SOCB:
1691         // OR the contents of the source data on the destination data
1692         dest_new = m_current_value | m_source_value;
1693         break;
1694
1695      case SZC:
1696      case SZCB:
1697         // AND the one's complement of the contents of the source data on the destination data
1698         dest_new = m_current_value & ~m_source_value;
1699         break;
1700
1701      case MOV:
1702      case MOVB:
1703         // Copy the source data to the destination data
1704         dest_new = m_source_value;
1705         break;
1706   }
1707
1708   if (byteop)
1709   {
1710      set_status_parity((UINT8)(dest_new>>8));
1711
1712      // destnew is the new value to be written (high byte); needs to be
1713      // merged with the existing word
1714      if (m_destination_even)
1715         m_current_value = (prev_dest_value & 0x00ff) | (dest_new & 0xff00);
1716      else
1717         m_current_value = (prev_dest_value & 0xff00) | ((dest_new >> 8) & 0x00ff);
1718      compare_and_set_lae((UINT16)(dest_new & 0xff00), 0);
1719   }
1720   else
1721   {
1722      m_current_value = (UINT16)(dest_new & 0xffff);
1723      compare_and_set_lae((UINT16)(dest_new & 0xffff), 0);
1724   }
1725
1726   pulse_clock(2);
1727}
1728
1729void tms9900_device::alu_comp()
1730{
1731   m_destination_even = ((m_address & 1)==0);   // this is the destination address; the source address has already been saved
1732   if (byte_operation())
1733   {
1734      if (!m_destination_even) m_current_value <<= 8;
1735      if (!m_source_even) m_source_value <<= 8;
1736      set_status_parity((UINT8)(m_source_value>>8));
1737      compare_and_set_lae(m_source_value & 0xff00, m_current_value & 0xff00);
1738   }
1739   else
1740      compare_and_set_lae(m_source_value, m_current_value);
1741
1742   pulse_clock(2);
1743}
1744
1745void tms9900_device::alu_f3()
1746{
1747   if (m_state==0)
1748   {
1749      m_regnumber = (IR >> 6) & 0x000f;
1750      m_source_value = m_current_value;
1751   }
1752   else
1753   {
1754      if (VERBOSE>7) LOG("tms9900: coc/czc/xor %04x with %04x\n", m_source_value, m_register_contents);
1755      switch (m_command)
1756      {
1757      case COC:
1758         set_status_bit(ST_EQ, (m_register_contents & m_source_value) == m_source_value);
1759         break;
1760      case CZC:
1761         set_status_bit(ST_EQ, (~m_register_contents & m_source_value) == m_source_value);
1762         break;
1763      case XOR:
1764         m_current_value = (m_register_contents ^ m_source_value);
1765         compare_and_set_lae(m_current_value, 0);
1766         break;
1767      }
1768   }
1769   if (VERBOSE>7) LOG("tms9900: ST = %04x (log comp)\n", ST);
1770
1771   m_state++;
1772   pulse_clock(2);
1773}
1774
1775void tms9900_device::alu_multiply()
1776{
1777   switch (m_state)
1778   {
1779   case 0: // After data derivation
1780      m_source_value = m_current_value;
1781      m_regnumber = (IR >> 6)&0x000f;
1782      break;
1783   case 1: // After reading the register (multiplier)
1784      if (VERBOSE>7) LOG("tms9900: Multiply %04x by %04x\n", m_register_contents, m_source_value);
1785      m_value = m_register_contents * m_source_value;
1786      m_current_value = (m_value >> 16) & 0xffff;
1787      m_value = m_value & 0xffff;                  // Save low word in m_value
1788      pulse_clock(34);                        // add 36 clock cycles (18 machine cycles); last one in main loop
1789      break;
1790   case 2: // After writing the high word to the destination register
1791      m_current_value = m_value;                  // Prepare to save low word
1792      m_address = (m_address + 2) & 0xffff;
1793      break;
1794   }
1795   pulse_clock(2);
1796   m_state++;
1797}
1798
1799void tms9900_device::alu_divide()
1800{
1801   // Format is DIV Divisor,REG(dividend)
1802   UINT32 value1;
1803
1804   switch (m_state)
1805   {
1806   case 0:
1807      m_source_value = m_current_value;      // store divisor
1808      m_regnumber = (IR >> 6) & 0x000f;
1809      break;
1810   case 1:
1811      // We have an overflow when the quotient cannot be stored in 16 bits
1812      // This is the case when the dividend / divisor >= 0x10000,
1813      // or equivalently, dividend / 0x10000 >= divisor
1814      if (m_register_contents >= m_source_value)
1815      {
1816         ST |= ST_OV;
1817         if (VERBOSE>7) LOG("tms9900: Aborting division because the dividend %08x is too big for the divisor %04x\n", (m_register_contents<<16), m_source_value);
1818         abort_operation();  // behaves as if the end of the operation sequence has been reached
1819      }
1820      else
1821      {
1822         ST &= ~ST_OV;
1823         // m_address is the address of the high word of the dividend (from the previous register read)
1824         m_address = (m_address + 2) & 0xffff;
1825      }
1826      break;
1827   case 2:
1828      // Create full word and perform division
1829      value1 = (m_register_contents << 16) | m_current_value;
1830      if (VERBOSE>7) LOG("tms9900: Dividing %08x by %04x\n", value1, m_source_value);
1831      m_current_value = (value1 / m_source_value) & 0xffff;
1832      m_value = (value1 % m_source_value) & 0xffff;
1833      if (VERBOSE>7) LOG("tms9900: Quotient %04x, remainder %04x\n", m_current_value, m_value);
1834
1835      // The number of ALU cycles depends on the number of steps in
1836      // the division algorithm. The number of cycles is between 32 and
1837      // 48 (*2 for clock cycles)
1838      // As I don't have a description of the actual algorithm, I'll use
1839      // the following heuristic: We use 32 ALU cycles in general, then
1840      // we need as many cycles as it takes to
1841      // shift away the dividend. Thus, bigger dividends need more cycles.
1842      pulse_clock(62);   // one pulse is at the start, one at the end
1843      value1 = m_register_contents & 0xffff;
1844      while (value1 != 0)
1845      {
1846         value1 = (value1 >> 1) & 0xffff;
1847         pulse_clock(2);
1848      }
1849      // We still have m_regnumber; this is where m_current_value will go to
1850      break;
1851   case 3:
1852      // Prepare to write the remainder; we have the address from above
1853      // (m_address), did not change
1854      m_current_value = m_value;
1855      if (VERBOSE>7) LOG("tms9900: ST = %04x (div)\n", ST);
1856      break;
1857   }
1858   pulse_clock(2);
1859   m_state++;
1860}
1861
1862void tms9900_device::alu_xop()
1863{
1864   switch (m_state)
1865   {
1866   case 0:
1867      // We have the effective address of the source operand in m_address
1868      m_source_address = m_address;
1869      // Now we take the XOP number from the instruction register
1870      // and calculate the vector location
1871      // [0010 11xx xx tt SSSS]  shift 6 right, then *4 => shift 4 right
1872      m_address = 0x0040 + ((IR >> 4) & 0x003c);
1873      break;
1874   case 1:
1875      m_value = WP;                     // save the old WP
1876      WP = m_current_value;               // the new WP has been read in the previous microoperation
1877      m_current_value = m_source_address;      // we saved the address of the source operand; retrieve it
1878      m_regnumber = 11;                  // Next register is R11
1879      break;
1880   case 2:
1881      m_current_value = ST;
1882      m_regnumber = 15;
1883      break;
1884   case 3:
1885      m_current_value = PC;
1886      m_regnumber = 14;
1887      break;
1888   case 4:
1889      m_current_value = WP;
1890      m_regnumber = 13;
1891      break;
1892   case 5:
1893      m_address =  0x0042 + ((IR >> 4) & 0x003c);      // location of new PC
1894      ST |= ST_X;
1895      break;
1896   case 6:
1897      PC = m_current_value;
1898      break;
1899   }
1900   pulse_clock(2);
1901   m_state++;
1902}
1903
1904void tms9900_device::alu_clr_swpb()
1905{
1906   UINT32 dest_new = 0;
1907   UINT32 src_val = m_current_value & 0x0000ffff;
1908   UINT16 sign = 0;
1909
1910   bool setstatus = true;
1911   bool check_ov = true;
1912
1913   switch (m_command)
1914   {
1915   case CLR:
1916      // no status bits
1917      m_current_value = 0x0000;
1918      setstatus = false;
1919      break;
1920   case SETO:
1921      // no status bits
1922      m_current_value = 0xffff;
1923      setstatus = false;
1924      break;
1925   case INV:
1926      // LAE
1927      dest_new = ~src_val & 0xffff;
1928      check_ov = false;
1929      break;
1930   case NEG:
1931      // LAEO
1932      // Overflow occurs for value=0x8000
1933      dest_new = ((~src_val) & 0x0000ffff) + 1;
1934      check_ov = false;
1935      set_status_bit(ST_OV, src_val == 0x8000);
1936      break;
1937   case INC:
1938      // LAECO
1939      // Overflow for result value = 0x8000
1940      // Carry for result value = 0x0000
1941      dest_new = src_val + 1;
1942      break;
1943   case INCT:
1944      // LAECO
1945      // Overflow for result value = 0x8000 / 0x8001
1946      // Carry for result value = 0x0000 / 0x0001
1947      dest_new = src_val + 2;
1948      break;
1949   case DEC:
1950      // LAECO
1951      // Carry for result value != 0xffff
1952      // Overflow for result value == 0x7fff
1953      dest_new = src_val + 0xffff;
1954      sign = 0x8000;
1955      break;
1956   case DECT:
1957      // Carry for result value != 0xffff / 0xfffe
1958      // Overflow for result value = 0x7fff / 0x7ffe
1959      dest_new = src_val + 0xfffe;
1960      sign = 0x8000;
1961      break;
1962   case SWPB:
1963      m_current_value = ((m_current_value << 8) | (m_current_value >> 8)) & 0xffff;
1964      setstatus = false;
1965      break;
1966   }
1967
1968   if (setstatus)
1969   {
1970      if (check_ov) set_status_bit(ST_OV, ((src_val & 0x8000)!=sign) && ((dest_new & 0x8000)==sign));
1971      set_status_bit(ST_C, (dest_new & 0x10000) != 0);
1972      m_current_value = dest_new & 0xffff;
1973      compare_and_set_lae(m_current_value, 0);
1974   }
1975
1976   pulse_clock(2);
1977   // No states here
1978}
1979
1980void tms9900_device::alu_abs()
1981{
1982   // LAECO (from original word!)
1983   // O if >8000
1984   // C is alwas reset
1985   set_status_bit(ST_OV, m_current_value == 0x8000);
1986   set_status_bit(ST_C, false);
1987   compare_and_set_lae(m_current_value, 0);
1988
1989   if ((m_current_value & 0x8000)!=0)
1990   {
1991      m_current_value = (-m_current_value) & 0xffff;
1992      pulse_clock(2);      // If ABS is performed it takes one machine cycle more
1993   }
1994   else
1995   {
1996      MPC++; // skips over the next micro operation (MEMORY_WRITE)
1997   }
1998   pulse_clock(2);
1999}
2000
2001void tms9900_device::alu_x()
2002{
2003   if (VERBOSE>7) LOG("tms9900: Substituting current command by %04x\n", m_current_value);
2004   decode(m_current_value);
2005   pulse_clock(2);
2006}
2007
2008/*
2009    Also used by other microprograms
2010*/
2011void tms9900_device::alu_b()
2012{
2013   // no status bits
2014   // Although we got the contents of the source data, we do not use them
2015   // but directly branch there. That is, we are only interested in the
2016   // address of the source data.
2017   // If we have a B *R5 and R5 contains the value 0xa000, the CPU actually
2018   // retrieves the value at 0xa000, but in fact it will load the PC
2019   // with the address 0xa000
2020   PC = m_address;
2021   if (VERBOSE>7) LOG("tms9900: Set new PC = %04x\n", PC);
2022   pulse_clock(2);
2023}
2024
2025void tms9900_device::alu_bl()
2026{
2027   // no status bits
2028   // We have just retrieved the target address; save it in another location
2029   m_source_value = m_current_value;
2030   m_current_value = PC;
2031   m_regnumber = 11;
2032   pulse_clock(4);
2033   PC = m_address;   // See B command: Forget about the value from the target location
2034   if (VERBOSE>7) LOG("tms9900: Set new PC = %04x\n", PC);
2035}
2036
2037void tms9900_device::alu_blwp()
2038{
2039   switch (m_state)
2040   {
2041   case 0:
2042      m_source_address = m_address;               // Save the location of the WP
2043      m_value = WP;
2044      WP = m_current_value;                     // set new WP (*m_destination)
2045      m_current_value = ST;                     // get status register
2046      m_regnumber = 15;
2047      break;
2048   case 1:
2049      m_current_value = PC;                     // get program counter
2050      m_regnumber = 14;
2051      break;
2052   case 2:
2053      m_current_value = m_value;               // retrieve the old WP
2054      m_regnumber = 13;
2055      break;
2056   case 3:
2057      m_address = (m_source_address + 2)&0xffff;   // point to PC component of branch vector
2058      break;
2059   case 4:
2060      PC = m_current_value;
2061      break;
2062   }
2063   pulse_clock(2);
2064   m_state++;
2065}
2066
2067void tms9900_device::alu_ldcr()
2068{
2069   UINT16 value;
2070
2071   // Spec: "If the source operand address is odd, the address is truncated
2072   //        to an even address prior to data transfer."
2073   // (Editor/Assembler, page 151)
2074   // This refers to transfers with more than 8 bits. In this case, for
2075   // LDCR the first bit is taken from the least significant bit of the
2076   // source word. If the address is odd (e.g. 0x1001), it is
2077   // treated as 0x1000, that is, truncated to an even address.
2078   // For transfers with 1-8 bits, the first bit is the least significant
2079   // bit of the source byte (any address).
2080
2081   if (m_state == 0)
2082   {
2083      m_regnumber = 12;
2084   }
2085   else
2086   {
2087      value = m_source_value;   // copied by ALU_SOURCE
2088      m_count = (IR >> 6) & 0x000f;
2089      if (m_count == 0) m_count = 16;
2090      if (m_count <= 8)
2091      {
2092         if (m_source_even) value>>=8;
2093         set_status_parity((UINT8)(value & 0xff));
2094         compare_and_set_lae(value<<8, 0);
2095      }
2096      else
2097      {
2098         compare_and_set_lae(value, 0);
2099      }
2100      m_cru_output = true;
2101      m_cru_address = m_register_contents;
2102      m_value = value;
2103      if (VERBOSE>6) LOG("tms9900: Load CRU address %04x (%d bits), value = %04x\n", m_cru_address, m_count, m_value);
2104   }
2105   m_state++;
2106   pulse_clock(2);
2107}
2108
2109void tms9900_device::alu_stcr()
2110{
2111   UINT16 value;
2112
2113   // For STCR transfers with more than 8 bits, the first CRU bit is
2114   // always put into the least significant bit of the destination word.
2115   // If the address is odd (e.g. 0x1001), it is treated as 0x1000, that is,
2116   // truncated to an even boundary.
2117   // For transfers with 1-8 bits, the destination address is handled as
2118   // in MOVB operations, i.e. the other byte of the word is kept unchanged.
2119
2120   switch (m_state)
2121   {
2122   case 0: // After getting the destination operand and saving the address/value
2123      m_regnumber = 12;
2124      break;
2125   case 1: // After getting R12
2126      m_cru_output = false;
2127      m_cru_address = m_register_contents;
2128      m_count = (IR >> 6) & 0x000f;
2129      if (m_count == 0) m_count = 16;
2130      break;
2131   case 2: // After the cru operation; value starts at LSB of m_value
2132      value = m_value & 0xffff;
2133      if (m_count < 9)
2134      {
2135         if (VERBOSE>6) LOG("tms9900: Store CRU at %04x (%d bits) in %04x, result = %02x\n", m_cru_address, m_count, m_source_address, value);
2136         set_status_parity((UINT8)(value & 0xff));
2137         compare_and_set_lae(value<<8, 0);
2138         if (m_source_even)
2139            m_current_value = (m_source_value & 0x00ff) | (value<<8);
2140         else
2141            m_current_value = (m_source_value & 0xff00) | (value & 0xff);
2142
2143         pulse_clock(2*(5 + (8-m_count)));
2144      }
2145      else
2146      {
2147         if (VERBOSE>6) LOG("tms9900: Store CRU at %04x (%d bits) in %04x, result = %04x\n", m_cru_address, m_count, m_source_address, value);
2148         m_current_value = value;
2149         compare_and_set_lae(value, 0);
2150         pulse_clock(2*(5 + (16-m_count)));
2151      }
2152      m_address = m_source_address;
2153      break;
2154   }
2155
2156   m_state++;
2157   pulse_clock(2);
2158}
2159
2160void tms9900_device::alu_sbz_sbo()
2161{
2162   INT8 displacement;
2163   if (m_state==0)
2164   {
2165      m_regnumber = 12;
2166   }
2167   else
2168   {
2169      m_cru_output = true;
2170      displacement = (IR & 0xff);
2171      m_cru_address = m_register_contents + (displacement<<1);
2172      m_count = 1;
2173      m_value = (m_command == SBO)? 1 : 0;
2174      pulse_clock(2);
2175   }
2176   m_state++;
2177   pulse_clock(2);
2178}
2179
2180void tms9900_device::alu_tb()
2181{
2182   INT8 displacement;
2183   switch (m_state)
2184   {
2185   case 0:
2186      m_regnumber = 12;
2187      break;
2188   case 1:
2189      m_cru_output = false;
2190      displacement = (IR & 0xff);
2191      m_cru_address = m_register_contents + (displacement<<1);
2192      m_count = 1;
2193      break;
2194   case 2:
2195      set_status_bit(ST_EQ, m_value!=0);
2196      if (VERBOSE>7) LOG("tms9900: ST = %04x\n", ST);
2197      break;
2198   }
2199   m_state++;
2200   pulse_clock(2);
2201}
2202
2203void tms9900_device::alu_jmp()
2204{
2205   INT8 displacement;
2206   bool cond = false;
2207
2208   if (m_state==0)
2209   {
2210      switch (m_command)
2211      {
2212      case JMP:
2213         cond = true;
2214         break;
2215      case JLT:   // LAECOP == x00xxx
2216         cond = ((ST & (ST_AGT | ST_EQ))==0);
2217         break;
2218      case JLE:   // LAECOP == 0xxxxx
2219         cond = ((ST & ST_LH)==0);
2220         break;
2221      case JEQ:   // LAECOP == xx1xxx
2222         cond = ((ST & ST_EQ)!=0);
2223         break;
2224      case JHE:   // LAECOP == 1x0xxx, 0x1xxx
2225         cond = ((ST & (ST_LH | ST_EQ)) != 0);
2226         break;
2227      case JGT:   // LAECOP == x1xxxx
2228         cond = ((ST & ST_AGT)!=0);
2229         break;
2230      case JNE:   // LAECOP == xx0xxx
2231         cond = ((ST & ST_EQ)==0);
2232         break;
2233      case JNC:   // LAECOP == xxx0xx
2234         cond = ((ST & ST_C)==0);
2235         break;
2236      case JOC:   // LAECOP == xxx1xx
2237         cond = ((ST & ST_C)!=0);
2238         break;
2239      case JNO:   // LAECOP == xxxx0x
2240         cond = ((ST & ST_OV)==0);
2241         break;
2242      case JL:   // LAECOP == 0x0xxx
2243         cond = ((ST & (ST_LH | ST_EQ)) == 0);
2244         break;
2245      case JH:   // LAECOP == 1xxxxx
2246         cond = ((ST & ST_LH)!=0);
2247         break;
2248      case JOP:   // LAECOP == xxxxx1
2249         cond = ((ST & ST_OP)!=0);
2250         break;
2251      }
2252      pulse_clock(2);
2253      if (!cond)
2254      {
2255         if (VERBOSE>7) LOG("tms9900: Jump condition false\n");
2256         MPC+=1;   // skip next ALU call
2257      }
2258      else
2259         if (VERBOSE>7) LOG("tms9900: Jump condition true\n");
2260   }
2261   else
2262   {
2263      displacement = (IR & 0xff);
2264      PC = PC + (displacement<<1);
2265      pulse_clock(2);
2266   }
2267   m_state++;
2268}
2269
2270void tms9900_device::alu_shift()
2271{
2272   bool carry = false;
2273   bool overflow = false;
2274   UINT16 sign = 0;
2275   UINT32 value;
2276
2277   switch (m_state)
2278   {
2279   case 0:
2280      m_regnumber = (IR & 0x000f);
2281      break;
2282   case 1:
2283      m_source_value = m_current_value;         // save it
2284      m_count = (IR >> 4) & 0x000f;
2285      if (m_count != 0) MPC++;
2286      else m_regnumber = 0;
2287      break;
2288   case 2:
2289      value = m_source_value & 0xffff;
2290
2291      if (m_count==0) m_count = m_register_contents & 0x000f;
2292      if (m_count==0) m_count = 16;
2293
2294      // we are re-implementing the shift operations because we have to pulse
2295      // the clock at each single shift anyway.
2296      // Also, it is easier to implement the status bit setting.
2297      // Note that count is never 0
2298      if (m_command == SRA) sign = value & 0x8000;
2299
2300      for (int i=0; i < m_count; i++)
2301      {
2302         switch (m_command)
2303         {
2304         case SRL:
2305         case SRA:
2306            carry = ((value & 1)!=0);
2307            value = (value >> 1) | sign;
2308            break;
2309         case SLA:
2310            carry = ((value & 0x8000)!=0);
2311            value <<= 1;
2312            if (carry != ((value&0x8000)!=0)) overflow = true;
2313            break;
2314         case SRC:
2315            carry = ((value & 1)!=0);
2316            value = (value>>1) | (carry? 0x8000 : 0x0000);
2317            break;
2318         }
2319         pulse_clock(2);
2320      }
2321
2322      m_current_value = value & 0xffff;
2323      set_status_bit(ST_C, carry);
2324      set_status_bit(ST_OV, overflow);
2325      compare_and_set_lae(m_current_value, 0);
2326
2327      m_regnumber = (IR & 0x000f);
2328      break;
2329   }
2330   m_state++;
2331   pulse_clock(2);
2332}
2333
2334void tms9900_device::alu_ai_ori()
2335{
2336   UINT32 dest_new = 0;
2337   switch (m_command)
2338   {
2339   case AI:
2340      dest_new = m_current_value + m_register_contents;
2341      // See status bit handling for Add
2342      set_status_bit(ST_C, (dest_new & 0x10000) != 0);
2343      set_status_bit(ST_OV, ((dest_new ^ m_current_value) & (dest_new ^ m_register_contents) & 0x8000)!=0);
2344      break;
2345   case ANDI:
2346      dest_new = m_current_value & m_register_contents;
2347      break;
2348   case ORI:
2349      dest_new = m_current_value | m_register_contents;
2350      break;
2351   }
2352   m_current_value = dest_new & 0xffff;
2353   compare_and_set_lae(m_current_value, 0);
2354   pulse_clock(2);
2355}
2356
2357void tms9900_device::alu_ci()
2358{
2359   compare_and_set_lae(m_register_contents, m_current_value);
2360   pulse_clock(2);
2361}
2362
2363void tms9900_device::alu_li()
2364{
2365   compare_and_set_lae(m_current_value, 0);
2366   pulse_clock(2);
2367}
2368
2369void tms9900_device::alu_lwpi()
2370{
2371   WP = m_current_value;
2372   pulse_clock(2);
2373}
2374
2375void tms9900_device::alu_limi()
2376{
2377   ST = (ST & 0xfff0) | (m_current_value & 0x000f);
2378   if (VERBOSE>7) LOG("tms9900: ST = %04x\n", ST);
2379   pulse_clock(2);
2380}
2381
2382void tms9900_device::alu_stwp_stst()
2383{
2384   if (m_command==STST) m_current_value = ST;
2385   else m_current_value = WP;
2386   pulse_clock(2);
2387}
2388
2389void tms9900_device::alu_external()
2390{
2391   pulse_clock(10);
2392
2393   // Call some possibly attached external device
2394   // We pass the bit pattern of the address bus to the external function
2395
2396   // IDLE = 0000 0011 0100 0000
2397   // RSET = 0000 0011 0110 0000
2398   // CKON = 0000 0011 1010 0000
2399   // CKOF = 0000 0011 1100 0000
2400   // LREX = 0000 0011 1110 0000
2401   //                  ---
2402   if (m_command == IDLE)
2403      m_idle_state = true;
2404
2405   m_external_operation((IR >> 5) & 0x07, 1);
2406}
2407
2408void tms9900_device::alu_rtwp()
2409{
2410   switch (m_state)
2411   {
2412   case 0:
2413      m_regnumber = 15;
2414      break;
2415   case 1:
2416      ST = m_register_contents;
2417      m_regnumber = 14;
2418      break;
2419   case 2:
2420      PC = m_register_contents;
2421      m_regnumber = 13;
2422      break;
2423   case 3:
2424      WP = m_register_contents;
2425      break;
2426   }
2427   m_state++;
2428   pulse_clock(2);
2429}
2430
2431
2432void tms9900_device::alu_int()
2433{
2434   if (VERBOSE>7) LOG("tms9900: INT state %d; irq_level %d\n", m_state, m_irq_level);
2435   switch (m_state)
2436   {
2437   case 0:
2438      if (m_irq_level == RESET_INT)
2439      {
2440         m_address = 0;
2441         pulse_clock(2);
2442      }
2443      else
2444      {
2445         if (m_irq_level == LOAD_INT) m_address = 0xfffc;
2446         else
2447         {
2448            m_address = (m_irq_level << 2);
2449         }
2450      }
2451      break;
2452   case 1:
2453      m_value = WP;            // old WP
2454      WP = m_current_value;      // new WP
2455      m_current_value = ST;
2456      m_regnumber = 15;
2457      break;
2458   case 2:
2459      m_current_value = PC;
2460      m_regnumber = 14;
2461      break;
2462   case 3:
2463      m_current_value = m_value;   // old WP
2464      m_regnumber = 13;
2465      break;
2466   case 4:
2467      m_address = (m_address + 2) & 0xfffe;
2468      if (VERBOSE>7) LOG("tms9900: read from %04x\n", m_address);
2469      break;
2470   case 5:
2471      PC = m_current_value;
2472      if (m_irq_level > 0 )
2473      {
2474         ST = (ST & 0xfff0) | (m_irq_level - 1);
2475      }
2476      break;
2477   }
2478   m_state++;
2479   pulse_clock(2);
2480}
2481
2482/**************************************************************************/
2483UINT32 tms9900_device::execute_min_cycles() const
2484{
2485   return 2;
2486}
2487
2488// TODO: Compute this value, just a wild guess for the average
2489UINT32 tms9900_device::execute_max_cycles() const
2490{
2491   return 10;
2492}
2493
2494UINT32 tms9900_device::execute_input_lines() const
2495{
2496   return 1;
2497}
2498
2499// clocks to cycles, cycles to clocks = id
2500// execute_default_irq_vector = 0
2501// execute_burn = nop
2502
2503// device_disasm_interface overrides
2504UINT32 tms9900_device::disasm_min_opcode_bytes() const
2505{
2506   return 2;
2507}
2508
2509UINT32 tms9900_device::disasm_max_opcode_bytes() const
2510{
2511   return 6;
2512}
2513
2514offs_t tms9900_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options)
2515{
2516   return Dasm9900(buffer, pc, TMS9900_ID, oprom, opram);
2517}
2518
2519
2520const device_type TMS9900 = &device_creator<tms9900_device>;
src/emu/cpu/tms9900/tms9900l.h
r0r15424
1/*
2  tms9900.h
3 
4  C Header file for TMS9900 core
5*/
6 
7#pragma once
8 
9#ifndef __TMS9900_H__
10#define __TMS9900_H__
11 
12 
13/*#define TI990_9_ID    0*//* early implementation, used in a few real-world applications, 1974 */
14                          /* very similar to mapper-less 990/10 and tms9900, but the Load process */
15                          /* is different */
16                          /* ("ti990/9" is likely to be a nickname) */
17#define TI990_10_ID      1 /* original multi-chip implementation for minicomputer systems, 1975 */
18/*#define TI990_12_ID       2*//* multi-chip implementation, faster than 990/10. huge instruction set */
19                          /* (144 instructions, with up to 16 additional custom instructions simulteanously) */
20                          /* 1979 (or before) */
21#define TMS9900_ID      3 /* mono-chip implementation, 1976 */
22#define TMS9940_ID      4 /* microcontroller with 2kb ROM, 128b RAM, decrementer, CRU bus, 1979 */
23#define TMS9980_ID      5 /* 8-bit variant of tms9900.  Two distinct chips actually : tms9980a, */
24                          /* and tms9981 with an extra clock and simplified power supply */
25#define TMS9985_ID      6 /* 9940 with 8kb ROM, 256b RAM, and a 8-bit external bus, c. 1978 (never released) */
26#define TMS9989_ID      7 /* improved 9980, used in bombs, missiles, and other *nice* hardware */
27/*#define SBP68689_ID     8*//* improved 9989, built as an ASIC as 9989 was running scarce */
28#define TMS9995_ID      9 /* tms9985-like, with many improvements (but no ROM) */
29#define TMS99000_ID     10/* improved mono-chip implementation, meant to replace 990/10, 1981 */
30                          /* This chip is available in several variants (tms99105, tms99110...), */
31                          /* which are similar but emulate additional instructions thanks */
32                          /* to the so-called macrostore feature. */
33#define TMS99105A_ID   11
34#define TMS99110A_ID   12
35 
36 
37/* NPW 25-May-2002 - Added these to get it to compile under windows */
38#define TI9940_ID      TMS9940_ID
39#define TI9985_ID      TMS9985_ID
40 
41 
42enum
43{
44   TMS9900_PC=1, TMS9900_WP, TMS9900_STATUS, TMS9900_IR,
45   TMS9900_R0, TMS9900_R1, TMS9900_R2, TMS9900_R3,
46   TMS9900_R4, TMS9900_R5, TMS9900_R6, TMS9900_R7,
47   TMS9900_R8, TMS9900_R9, TMS9900_R10, TMS9900_R11,
48   TMS9900_R12, TMS9900_R13, TMS9900_R14, TMS9900_R15
49};
50 
51typedef void (*ti99xx_idle_func)(device_t *device, int state);
52typedef void (*ti99xx_rset_func)(device_t *device);
53typedef void (*ti99xx_lrex_func)(device_t *device);
54typedef void (*ti99xx_ckon_ckof_func)(device_t *device, int state);
55typedef void (*ti99xx_error_interrupt_func)(device_t *device, int state);
56 
57 
58DECLARE_LEGACY_CPU_DEVICE(TI990_10L, ti990_10l);
59 
60/*
61    structure with the parameters ti990_10_reset wants.
62*/
63 
64typedef struct ti990_10reset_param
65{
66   ti99xx_idle_func   idle_callback;
67   ti99xx_rset_func   rset_callback;
68   ti99xx_lrex_func   lrex_callback;
69   ti99xx_ckon_ckof_func   ckon_ckof_callback;
70   ti99xx_error_interrupt_func   error_interrupt_callback;
71} ti990_10reset_param;
72 
73/* accessor for the internal ROM */
74extern READ16_HANDLER(ti990_10_internal_r);
75 
76/* CRU accessor for the mapper registers (R12 base 0x1fa0) */
77extern READ8_HANDLER(ti990_10_mapper_cru_r);
78extern WRITE8_HANDLER(ti990_10_mapper_cru_w);
79/* CRU accessor for the error interrupt register (R12 base 0x1fc0) */
80extern READ8_HANDLER(ti990_10_eir_cru_r);
81extern WRITE8_HANDLER(ti990_10_eir_cru_w);
82 
83 
84 
85DECLARE_LEGACY_CPU_DEVICE(TMS9900L, tms9900l);
86 
87/*
88    structure with optional parameters for tms9900_reset.
89*/
90typedef struct tms9900reset_param
91{
92   ti99xx_idle_func   idle_callback;
93} tms9900reset_param;
94 
95 
96 
97//DECLARE_LEGACY_CPU_DEVICE(TMS9940, tms9940);
98 
99/*
100    structure with optional parameters for tms9940_reset.
101*/
102typedef struct tms9940reset_param
103{
104   ti99xx_idle_func   idle_callback;
105} tms9940reset_param;
106 
107 
108 
109DECLARE_LEGACY_CPU_DEVICE(TMS9980L, tms9980al);
110 
111/*
112    structure with optional parameters for tms9980a_reset.
113*/
114typedef struct tms9980areset_param
115{
116   ti99xx_idle_func   idle_callback;
117} tms9980areset_param;
118 
119 
120 
121//DECLARE_LEGACY_CPU_DEVICE(TMS9985, tms9985);
122 
123/*//
124    structure with optional parameters for tms9985_reset.
125*/
126typedef struct tms9985reset_param
127{
128   ti99xx_idle_func   idle_callback;
129} tms9985reset_param;
130 
131 
132 
133//DECLARE_LEGACY_CPU_DEVICE(TMS9989, tms9989);
134 
135/*
136    structure with optional parameters for tms9989_reset.
137*/
138typedef struct tms9989reset_param
139{
140   ti99xx_idle_func   idle_callback;
141} tms9989reset_param;
142 
143 
144 
145DECLARE_LEGACY_CPU_DEVICE(TMS9995L, tms9995l);
146 
147/*
148  structure with the parameters tms9995_reset wants.
149*/
150typedef struct tms9995reset_param
151{
152   /* auto_wait_state : a non-zero value makes tms9995 generate a wait state automatically on each
153       memory access */
154   int auto_wait_state;
155 
156   ti99xx_idle_func   idle_callback;
157 
158   /* on the tms9995-mp9537, internal RAM and decrementer register are
159        disabled.  This chip is used by the ti99/8 so that internal RAM does
160        not prevent the mapper from working correctly. */
161   int is_mp9537;
162} tms9995reset_param;
163 
164/* accessor for the first 252 bytes of internal RAM */
165extern READ8_HANDLER(tms9995_internal1_r);
166extern WRITE8_HANDLER(tms9995_internal1_w);
167/* accessors for the last 4 bytes of internal RAM */
168extern READ8_HANDLER(tms9995_internal2_r);
169extern WRITE8_HANDLER(tms9995_internal2_w);
170 
171 
172 
173//DECLARE_LEGACY_CPU_DEVICE(TMS99000, tms99000);
174 
175/*
176    structure with optional parameters for tms99000_reset.
177*/
178typedef struct tms99000reset_param
179{
180   ti99xx_idle_func   idle_callback;
181} tms99000reset_param;
182 
183 
184 
185//DECLARE_LEGACY_CPU_DEVICE(TMS99105A, tms99105a);
186 
187/*
188    structure with optional parameters for tms99105a_reset.
189*/
190typedef struct tms99105areset_param
191{
192   ti99xx_idle_func   idle_callback;
193} tms99105areset_param;
194 
195 
196 
197//DECLARE_LEGACY_CPU_DEVICE(TMS99110A, tms99110a);
198 
199/*
200    structure with optional parameters for tms99110a_reset.
201*/
202typedef struct tms99110areset_param
203{
204   ti99xx_idle_func   idle_callback;
205} tms99110areset_param;
206 
207 
208unsigned Dasm9900 (char *buffer, unsigned pc, int model_id, const UINT8 *oprom, const UINT8 *opram);
209 
210#endif /* __TMS9900_H__ */
src/emu/cpu/tms9900/tms9995.h
r0r15424
1/*
2  tms9995.h
3 
4  See tms9995.c for documentation
5  Also see tms9900.h for types of TMS9xxx processors.
6*/
7 
8#ifndef __TMS9995_H__
9#define __TMS9995_H__
10 
11#include "emu.h"
12#include "debugger.h"
13 
14enum
15{
16   TI990_10_ID = 1,
17   TMS9900_ID = 3,
18   TMS9940_ID = 4,
19   TMS9980_ID = 5,
20   TMS9985_ID = 6,
21   TMS9989_ID = 7,
22   TMS9995_ID = 9,
23   TMS99000_ID = 10,
24   TMS99105A_ID = 11,
25   TMS99110A_ID = 12
26};
27 
28#define MCFG_TMS9995_ADD(_tag, _device, _clock, _prgmap, _iomap, _config)      \
29   MCFG_DEVICE_ADD(_tag, _device, _clock / 4.0)      \
30   MCFG_DEVICE_PROGRAM_MAP(_prgmap)         \
31   MCFG_DEVICE_IO_MAP(_iomap)               \
32   MCFG_DEVICE_CONFIG(_config)
33 
34enum
35{
36   IDLE_OP = 2,
37   RSET_OP = 3,
38   CKOF_OP = 5,
39   CKON_OP = 6,
40   LREX_OP = 7
41};
42 
43/*
44    Configuration for the TMS9995. The connections are provided by the
45    main board which contains the processor.
46*/
47typedef struct _tms9995_config
48{
49   devcb_write8      external_callback;
50   devcb_write_line   iaq_line;
51   devcb_write_line   clock_out;
52   devcb_write_line   wait_line;
53   devcb_write_line   holda_line;
54   int               mode;
55   int               overflow;
56} tms9995_config;
57 
58#define TMS9995_CONFIG(name) \
59   const tms9995_config(name) =
60 
61enum
62{
63   NO_INTERNAL_RAM = 0,
64   INTERNAL_RAM,
65   NO_OVERFLOW_INT = 0,
66   OVERFLOW_INT
67};
68 
69class tms9995_device : public cpu_device
70{
71public:
72   tms9995_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
73 
74   // READY input line. When asserted (high), the memory is ready for data exchange.
75   // We chose to use a direct method instead of a delegate to keep performance
76   // footprint low; this method may be called very frequently.
77   void set_ready(int state);
78 
79   // HOLD input line. When asserted (low), the CPU is requested to release the
80   // data and address bus and enter the HOLD state. The entrance of this state
81   // is acknowledged by the HOLDA output line.
82   void set_hold(int state);
83 
84protected:
85   // device-level overrides
86   virtual void      device_start();
87   virtual void      device_stop();
88   virtual void      device_reset();
89 
90   // device_execute_interface overrides
91   virtual UINT32      execute_min_cycles() const;
92   virtual UINT32      execute_max_cycles() const;
93   virtual UINT32      execute_input_lines() const;
94   virtual void      execute_set_input(int irqline, int state);
95   virtual void      execute_run();
96 
97   // device_disasm_interface overrides
98   virtual UINT32      disasm_min_opcode_bytes() const;
99   virtual UINT32      disasm_max_opcode_bytes() const;
100   virtual offs_t      disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options);
101 
102   const address_space_config* memory_space_config(address_spacenum spacenum) const;
103 
104private:
105   // State / debug management
106   UINT16   m_state_any;
107   static const char* s_statename[];
108   void   state_import(const device_state_entry &entry);
109   void   state_export(const device_state_entry &entry);
110   void   state_string_export(const device_state_entry &entry, astring &string);
111   UINT16   read_workspace_register_debug(int reg);
112   void   write_workspace_register_debug(int reg, UINT16 data);
113 
114   // TMS9995 hardware registers
115   UINT16   WP;    // Workspace pointer
116   UINT16   PC;    // Program counter
117   UINT16   ST;    // Status register
118 
119   // The TMS9995 has a prefetch feature which causes a wrong display of the PC.
120   // We use this additional member for the debugger only.
121   UINT16   PC_debug;
122 
123   // 256 bytes of onchip memory
124   UINT8   m_onchip_memory[256];
125 
126   const address_space_config      m_program_config;
127   const address_space_config      m_io_config;
128   address_space*               m_prgspace;
129   address_space*               m_cru;
130 
131   // Variant of the TMS9995 without internal RAM and decrementer
132   bool   m_mp9537;
133 
134   // Processor states
135   bool   m_idle_state;
136   bool   m_nmi_state;
137   bool   m_irq_state;
138   bool   m_ready_state;
139   bool   m_wait_state;
140   bool   m_hold_state;
141 
142   // Auto-wait state generation
143   bool   m_auto_wait_state;
144 
145   // Cycle counter
146   int    m_icount;
147 
148   // The next memory access will address the low byte
149   bool   m_lowbyte;
150 
151   // Check the READY line?
152   bool   m_check_ready;
153 
154   // Check the HOLD line
155   bool   m_check_hold;
156 
157   // For multi-pass operations. For instance, memory word accesses are
158   // executed as two consecutive byte accesses. CRU accesses are repeated
159   // single-bit accesses.
160   int      m_pass;
161 
162   // For parity operations
163   int      m_parity;
164 
165   // For Format 1 instruction; determines whether the next operand address
166   // derivation is for the source or address operand
167   bool   m_get_destination;
168 
169   // Used for situations when a command is byte-oriented, but the memory access
170   // must be word-oriented. Example: MOVB *R1,R0; we must read the full word
171   // from R1 to get the address.
172   bool   m_word_access;
173 
174   // Interrupt handling
175   bool   m_nmi_active;
176   bool   m_int1_active;
177   bool   m_int4_active;
178   bool   m_int_decrementer;
179   bool   m_int_overflow;
180 
181   bool   m_reset;
182   bool   m_mid_flag;
183 
184   // Flag field
185   int      m_int_pending;
186 
187   // The TMS9995 is capable of raising an internal interrupt on
188   // arithmetic overflow, depending on the status register Overflow Enable bit.
189   // However, the specs also say that this feature is non-functional in the
190   // currently available chip. Thus we have an option to turn it off so that
191   // software will not change its behavior on overflows.
192   bool   m_check_overflow;
193 
194   // Service pending interrupts
195   void   service_interrupt();
196 
197   // Issue clock pulses. The TMS9995 uses one (output) clock cycle per machine cycle.
198   inline void pulse_clock(int count);
199 
200   // Signal the wait state via the external line
201   inline void set_wait_state(bool state);
202 
203   // Signal the wait state via the external line
204   inline void set_hold_state(bool state);
205 
206   // Only used for the DIV(S) operations. It seems sufficient to let the
207   // command terminate at this point, so this method just calls command_terminated.
208   void   abort_operation(void);
209 
210   // Decode the given 16-bit value which has been retrieved by a prefetch or
211   // during an X operation.
212   void   decode(UINT16 inst);
213 
214   // Store the interrupt mask part of the ST. This is used when processing
215   // an interrupt, passing the new mask from the service_interrupt part to
216   // the program part.
217   int      m_intmask;
218 
219   // Stored address
220   UINT16   m_address;
221 
222   // Stores the recently read word or the word to be written
223   UINT16   m_current_value;
224 
225   // Stores the value of the source operand in multi-operand instructions
226   UINT16   m_source_value;
227 
228   // During indexed addressing, this value is added to get the final address value.
229   UINT16   m_address_add;
230 
231   // During indirect/auto-increment addressing, this copy of the address must
232   // be preserved while writing the new value to the register.
233   UINT16   m_address_saved;
234 
235   // Another copy of the address
236   UINT16   m_address_copy;
237 
238   // Copy of the value
239   UINT16   m_value_copy;
240 
241   // Stores the recent register number. Only used to pass the register
242   // number during the operand address derivation.
243   int      m_regnumber;
244 
245   // Stores the number of bits or shift operations
246   int      m_count;
247 
248   // ============== Decrementer =======================
249   void trigger_decrementer();
250 
251   // Start value
252   UINT16   m_starting_count_storage_register;
253 
254   // Current decrementer value.
255   UINT16   m_decrementer_value;
256 
257   // ============== CRU support ======================
258 
259   UINT16   m_cru_address;
260   UINT16   m_cru_value;
261   bool   m_cru_first_read;
262   int      m_cru_bits_left;
263   UINT32   m_cru_read;
264 
265   // CPU-internal CRU flags
266   bool   m_flag[16];
267 
268   // ============== Prefetch support =====================
269 
270   typedef struct _decoded_instruction
271   {
272      UINT16         IR;
273      UINT16        command;
274      const UINT8*   program;
275      bool         byteop;
276      int            state;
277   } decoded_instruction;
278 
279   int      m_instindex;
280 
281   // We implement the prefetch mechanism by two separate datasets for
282   // the decoded commands. When the previous command has completed, the
283   // pointer is just switched to the other one.
284   tms9995_device::decoded_instruction    m_decoded[2];
285   tms9995_device::decoded_instruction*   m_instruction;
286 
287   // ================ Microprogram support ========================
288 
289   // Set up lookup table
290   void build_command_lookup_table();
291 
292   // Sequence of micro-operations
293   typedef const UINT8* microprogram;
294 
295   // Method pointer
296   typedef void (tms9995_device::*ophandler)(void);
297 
298   // Opcode list entry
299   typedef struct _tms_instruction
300   {
301      UINT16            opcode;
302      int               id;
303      int               format;
304      microprogram      prog;      // Microprogram
305   } tms_instruction;
306 
307   // Lookup table entry
308   typedef struct _lookup_entry
309   {
310      struct _lookup_entry *next_digit;
311      const tms_instruction *entry;
312   } lookup_entry;
313 
314   // Pointer to the lookup table; the entry point for searching the command
315   lookup_entry*   m_command_lookup_table;
316 
317   // List of allocated tables (used for easy clean-up on exit)
318   lookup_entry*   m_lotables[32];
319 
320   // List of pointers for micro-operations
321   static const tms9995_device::ophandler s_microoperation[];
322 
323   static const tms9995_device::tms_instruction s_command[];
324 
325   // Micro-operation program counter (as opposed to the program counter PC)
326   int    MPC;
327 
328   // Calling microprogram (used when data derivation is called)
329   const UINT8*   m_caller;
330   int          m_caller_MPC;
331 
332   // Table of microprograms
333   static const microprogram mp_table[];
334 
335   // Used to display the number of consumed cycles in the log.
336   int      m_first_cycle;
337 
338   // Status register update
339   inline void set_status_bit(int bit, bool state);
340   inline void compare_and_set_lae(UINT16 value1, UINT16 value2);
341   void set_status_parity(UINT8 value);
342 
343   // Micro-operation declarations
344   void int_prefetch_and_decode();
345   void prefetch_and_decode();
346   void mem_read();
347   void mem_write();
348   inline void word_read();
349   inline void word_write();
350   void operand_address_subprogram();
351   void increment_register();
352   void indexed_addressing();
353   void set_immediate();
354   void return_with_address();
355   void return_with_address_copy();
356   void cru_input_operation();
357   void cru_output_operation();
358   void command_completed();
359   void next_command();
360 
361   // ALU operations for specific commands
362   void alu_nop();
363   void alu_add_s_sxc();
364   void alu_b();
365   void alu_blwp();
366   void alu_c();
367   void alu_ci();
368   void alu_clr_seto();
369   void alu_divide();
370   void alu_divide_signed();
371   void alu_external();
372   void alu_f3();
373   void alu_imm_arithm();
374   void alu_jump();
375   void alu_ldcr();
376   void alu_li();
377   void alu_limi_lwpi();
378   void alu_lst_lwp();
379   void alu_mov();
380   void alu_multiply();
381   void alu_multiply_signed();
382   void alu_rtwp();
383   void alu_sbo_sbz();
384   void alu_shift();
385   void alu_single_arithm();
386   void alu_stcr();
387   void alu_stst_stwp();
388   void alu_tb();
389   void alu_x();
390   void alu_xop();
391   void alu_int();
392 
393   // ================ Connections ====================
394 
395   // Trigger external operation. This is achieved by putting a special value in
396   // the most significant three bits of the data bus and pulsing the CRUCLK line.
397   // Accordingly, we have
398   //
399   // D0 D1 D2
400   // 0  0  0   normal CRU access
401   // 0  1  0   IDLE
402   // 0  1  1   RSET
403   // 1  0  1   CKON
404   // 1  1  0   CKOF
405   // 1  1  1   LREX
406   //
407   // We could realize this via the CRU access as well, but the data bus access
408   // is not that simple to emulate. For the sake of homogenity between the
409   // chip emulations we use a dedicated callback.
410   devcb_resolved_write8   m_external_operation;
411 
412   // Signal to the outside world that we are now getting an instruction (IAQ).
413   // In the real hardware this line is shared with the HOLDA line, and the
414   // /MEMEN line is used to decide which signal we have on the line. We do not
415   // emulate the /MEMEN line, so we have to use two separate lines.
416   devcb_resolved_write_line   m_iaq_line;
417 
418   // Clock output.
419   devcb_resolved_write_line   m_clock_out_line;
420 
421   // Wait output. When asserted (high), the CPU is in a wait state.
422   devcb_resolved_write_line   m_wait_line;
423 
424   // Asserted when the CPU is in a HOLD state
425   devcb_resolved_write_line   m_holda_line;
426};
427 
428unsigned Dasm9900(char *buffer, unsigned pc, int model_id, const UINT8 *oprom, const UINT8 *opram);
429 
430// device type definition
431extern const device_type TMS9995;
432 
433#endif /* __TMS9995_H__ */
src/emu/cpu/tms9900/ti990_10l.c
r0r15424
1/*
2    Generate the tms9900 emulator
3*/
4 
5#include "emu.h"
6#include "debugger.h"
7#include "tms9900l.h"
8 
9#define TMS99XX_MODEL TI990_10_ID
10 
11#include "99xxcore.h"
12 
13DEFINE_LEGACY_CPU_DEVICE(TI990_10L, ti990_10l);
src/emu/cpu/tms9900/tms9900.h
r15423r15424
11/*
2  tms9900.h
2    TMS9900 processor
3    This is a re-implementation of the TMS9900 featuring a cycle-precise
4    behaviour.
35
4  C Header file for TMS9900 core
5*/
6    See tms9900.c for documentation
67
7#pragma once
8    Types of TMS99xx processors:
9    TI990/9    Early implementation, used in a few real-world applications, 1974
10               very similar to mapper-less 990/10 and tms9900, but the Load
11               process is different
812
9#ifndef __TMS9900_H__
10#define __TMS9900_H__
13    TI990/10   Original multi-chip implementation for minicomputer systems, 1975
1114
15    TI990/12   Multi-chip implementation, faster than 990/10. Huge instruction set
1216
13/*#define TI990_9_ID    0*//* early implementation, used in a few real-world applications, 1974 */
14                          /* very similar to mapper-less 990/10 and tms9900, but the Load process */
15                          /* is different */
16                          /* ("ti990/9" is likely to be a nickname) */
17#define TI990_10_ID      1 /* original multi-chip implementation for minicomputer systems, 1975 */
18/*#define TI990_12_ID       2*//* multi-chip implementation, faster than 990/10. huge instruction set */
19                          /* (144 instructions, with up to 16 additional custom instructions simulteanously) */
20                          /* 1979 (or before) */
21#define TMS9900_ID      3 /* mono-chip implementation, 1976 */
22#define TMS9940_ID      4 /* microcontroller with 2kb ROM, 128b RAM, decrementer, CRU bus, 1979 */
23#define TMS9980_ID      5 /* 8-bit variant of tms9900.  Two distinct chips actually : tms9980a, */
24                          /* and tms9981 with an extra clock and simplified power supply */
25#define TMS9985_ID      6 /* 9940 with 8kb ROM, 256b RAM, and a 8-bit external bus, c. 1978 (never released) */
26#define TMS9989_ID      7 /* improved 9980, used in bombs, missiles, and other *nice* hardware */
27/*#define SBP68689_ID     8*//* improved 9989, built as an ASIC as 9989 was running scarce */
28#define TMS9995_ID      9 /* tms9985-like, with many improvements (but no ROM) */
29#define TMS99000_ID     10/* improved mono-chip implementation, meant to replace 990/10, 1981 */
30                          /* This chip is available in several variants (tms99105, tms99110...), */
31                          /* which are similar but emulate additional instructions thanks */
32                          /* to the so-called macrostore feature. */
33#define TMS99105A_ID   11
34#define TMS99110A_ID   12
17    TMS9900    Mono-chip implementation, 1976. Used in the TI-99/4(A) computer.
3518
19    TMS9940    Microcontroller with 2kb ROM, 128b RAM, decrementer, CRU bus, 1979
3620
37/* NPW 25-May-2002 - Added these to get it to compile under windows */
38#define TI9940_ID      TMS9940_ID
39#define TI9985_ID      TMS9985_ID
21    TMS9980    8-bit variant of tms9900.  Two distinct chips actually : tms9980a
22               and tms9981 with an extra clock and simplified power supply
4023
24    TMS9985    9940 with 8kb ROM, 256b RAM, and a 8-bit external bus, c. 1978 (never released)
4125
26    TMS9989    Improved 9980, used in military hardware.
27
28    SBP68689   Improved 9989, built as an ASIC as 9989 was running scarce
29
30    TMS9995    TMS9985-like, with many improvements (but no ROM). Used in the
31               TI-99/8 prototype and the Geneve computer.
32
33    TMS99000   Improved mono-chip implementation, meant to replace 990/10, 1981
34    TMS99105   This chip is available in several variants which are similar
35    TMS99110   but emulate additional instructions, thanks to the so-called
36               macrostore feature.
37
38    In this implementation we only consider TMS9900, 9980, and 9995. The
39    remaining types are implemented on an own code base as they introduce
40    significant changes (e.g. privileged mode, address mapper). For now we
41    leave the implementation of the rest up to 99xxcore.h.
42*/
43
44#ifndef __TMS9900_H__
45#define __TMS9900_H__
46
47#include "emu.h"
48#include "debugger.h"
49
4250enum
4351{
44   TMS9900_PC=1, TMS9900_WP, TMS9900_STATUS, TMS9900_IR,
45   TMS9900_R0, TMS9900_R1, TMS9900_R2, TMS9900_R3,
46   TMS9900_R4, TMS9900_R5, TMS9900_R6, TMS9900_R7,
47   TMS9900_R8, TMS9900_R9, TMS9900_R10, TMS9900_R11,
48   TMS9900_R12, TMS9900_R13, TMS9900_R14, TMS9900_R15
52   TI990_10_ID = 1,
53   TMS9900_ID = 3,
54   TMS9940_ID = 4,
55   TMS9980_ID = 5,
56   TMS9985_ID = 6,
57   TMS9989_ID = 7,
58   TMS9995_ID = 9,
59   TMS99000_ID = 10,
60   TMS99105A_ID = 11,
61   TMS99110A_ID = 12
4962};
5063
51typedef void (*ti99xx_idle_func)(device_t *device, int state);
52typedef void (*ti99xx_rset_func)(device_t *device);
53typedef void (*ti99xx_lrex_func)(device_t *device);
54typedef void (*ti99xx_ckon_ckof_func)(device_t *device, int state);
55typedef void (*ti99xx_error_interrupt_func)(device_t *device, int state);
64#define MCFG_TMS9900_ADD(_tag, _device, _clock, _prgmap, _iomap, _config)      \
65   MCFG_DEVICE_ADD(_tag, _device, _clock)      \
66   MCFG_DEVICE_PROGRAM_MAP(_prgmap)         \
67   MCFG_DEVICE_IO_MAP(_iomap)               \
68   MCFG_DEVICE_CONFIG(_config)
5669
70enum
71{
72   IDLE_OP = 2,
73   RSET_OP = 3,
74   CKOF_OP = 5,
75   CKON_OP = 6,
76   LREX_OP = 7
77};
5778
58DECLARE_LEGACY_CPU_DEVICE(TI990_10, ti990_10);
79typedef struct _tms9900_config
80{
81   devcb_write8      external_callback;
82   devcb_read8         irq_level;
83   devcb_write_line   instruction_acquisition;
84   devcb_write_line   clock_out;
85   devcb_write_line   wait_line;
86   devcb_write_line   holda_line;
87} tms9900_config;
5988
60/*
61    structure with the parameters ti990_10_reset wants.
62*/
89#define TMS9900_CONFIG(name) \
90   const tms9900_config(name) =
6391
64typedef struct ti990_10reset_param
92class tms9900_device : public cpu_device
6593{
66   ti99xx_idle_func   idle_callback;
67   ti99xx_rset_func   rset_callback;
68   ti99xx_lrex_func   lrex_callback;
69   ti99xx_ckon_ckof_func   ckon_ckof_callback;
70   ti99xx_error_interrupt_func   error_interrupt_callback;
71} ti990_10reset_param;
94public:
95   tms9900_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
7296
73/* accessor for the internal ROM */
74extern READ16_HANDLER(ti990_10_internal_r);
97   // READY input line. When asserted (high), the memory is ready for data exchange.
98   void set_ready(int state);
7599
76/* CRU accessor for the mapper registers (R12 base 0x1fa0) */
77extern READ8_HANDLER(ti990_10_mapper_cru_r);
78extern WRITE8_HANDLER(ti990_10_mapper_cru_w);
79/* CRU accessor for the error interrupt register (R12 base 0x1fc0) */
80extern READ8_HANDLER(ti990_10_eir_cru_r);
81extern WRITE8_HANDLER(ti990_10_eir_cru_w);
100   // HOLD input line. When asserted (low), the CPU is requested to release the
101   // data and address bus and enter the HOLD state. The entrance of this state
102   // is acknowledged by the HOLDA output line.
103   void set_hold(int state);
82104
105protected:
106   // device-level overrides
107   virtual void      device_start();
108   virtual void      device_stop();
109   virtual void      device_reset();
83110
111   // device_execute_interface overrides
112   virtual UINT32      execute_min_cycles() const;
113   virtual UINT32      execute_max_cycles() const;
114   virtual UINT32      execute_input_lines() const;
115   virtual void      execute_set_input(int irqline, int state);
116   virtual void      execute_run();
84117
85DECLARE_LEGACY_CPU_DEVICE(TMS9900, tms9900);
118   // device_disasm_interface overrides
119   virtual UINT32      disasm_min_opcode_bytes() const;
120   virtual UINT32      disasm_max_opcode_bytes() const;
121   virtual offs_t      disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options);
86122
87/*
88    structure with optional parameters for tms9900_reset.
89*/
90typedef struct tms9900reset_param
91{
92   ti99xx_idle_func   idle_callback;
93} tms9900reset_param;
123   const address_space_config* memory_space_config(address_spacenum spacenum) const;
94124
125private:
126   // TMS9900 hardware registers
127   UINT16   WP;    // Workspace pointer
128   UINT16   PC;    // Program counter
129   UINT16   ST;    // Status register
95130
131   // Internal register
132   UINT16   IR;      // Instruction register
96133
97//DECLARE_LEGACY_CPU_DEVICE(TMS9940, tms9940);
134   // Decoded command
135   UINT16   m_command;
98136
99/*
100    structure with optional parameters for tms9940_reset.
101*/
102typedef struct tms9940reset_param
103{
104   ti99xx_idle_func   idle_callback;
105} tms9940reset_param;
137   // Indicates if this is a byte-oriented command
138   inline bool    byte_operation();
106139
140   const address_space_config      m_program_config;
141   const address_space_config      m_io_config;
142   address_space*               m_prgspace;
143   address_space*               m_cru;
107144
145   // Processor states
146   bool   m_idle_state;
147   bool   m_load_state;
148   bool   m_irq_state;
149   bool   m_ready_state;
150   bool   m_wait_state;
151   bool   m_hold_state;
108152
109DECLARE_LEGACY_CPU_DEVICE(TMS9980, tms9980a);
153   bool   m_reset;
110154
111/*
112    structure with optional parameters for tms9980a_reset.
113*/
114typedef struct tms9980areset_param
115{
116   ti99xx_idle_func   idle_callback;
117} tms9980areset_param;
155   int    m_irq_level;   // Interrupt level as acquired from input lines IC0-IC3
156   int    m_icount;      // Cycle counter
118157
158   // State / debug management
159   UINT16   m_state_any;
160   static const char* s_statename[];
161   void   state_import(const device_state_entry &entry);
162   void   state_export(const device_state_entry &entry);
163   void   state_string_export(const device_state_entry &entry, astring &string);
164   UINT16   read_workspace_register_debug(int reg);
165   void   write_workspace_register_debug(int reg, UINT16 data);
119166
167   // Interrupt handling
168   void service_interrupt();
120169
121//DECLARE_LEGACY_CPU_DEVICE(TMS9985, tms9985);
170   // ================ Microprogram support ========================
122171
123/*//
124    structure with optional parameters for tms9985_reset.
125*/
126typedef struct tms9985reset_param
127{
128   ti99xx_idle_func   idle_callback;
129} tms9985reset_param;
172   // Set up lookup table
173   void build_command_lookup_table();
130174
175   // Sequence of micro-operations
176   typedef const UINT8* microprogram;
131177
178   // Method pointer
179   typedef void (tms9900_device::*ophandler)(void);
132180
133//DECLARE_LEGACY_CPU_DEVICE(TMS9989, tms9989);
181   // Opcode list entry
182   typedef struct _tms_instruction
183   {
184      UINT16            opcode;
185      int               id;
186      int               format;
187      microprogram      prog;      // Microprogram
188   } tms_instruction;
134189
135/*
136    structure with optional parameters for tms9989_reset.
137*/
138typedef struct tms9989reset_param
139{
140   ti99xx_idle_func   idle_callback;
141} tms9989reset_param;
190   // Lookup table entry
191   typedef struct _lookup_entry
192   {
193      struct _lookup_entry *next_digit;
194      const tms_instruction *entry;
195   } lookup_entry;
142196
197   // Pointer to the lookup table
198   lookup_entry*   m_command_lookup_table;
143199
200   // List of allocated tables (used for easy clean-up on exit)
201   lookup_entry*   m_lotables[32];
144202
145DECLARE_LEGACY_CPU_DEVICE(TMS9995, tms9995);
203   // List of pointers for micro-operations
204   static const tms9900_device::ophandler s_microoperation[];
146205
147/*
148  structure with the parameters tms9995_reset wants.
149*/
150typedef struct tms9995reset_param
151{
152   /* auto_wait_state : a non-zero value makes tms9995 generate a wait state automatically on each
153       memory access */
154   int auto_wait_state;
206   // Opcode table
207   static const tms9900_device::tms_instruction s_command[];
155208
156   ti99xx_idle_func   idle_callback;
209   // Micro-operation declarations
210   void   acquire_instruction(void);
211   void   mem_read(void);
212   void   mem_write(void);
213   void   register_read(void);
214   void   register_write(void);
215   void   cru_operation(void);
216   void   data_derivation_subprogram(void);
217   void   return_from_subprogram(void);
218   void   command_completed(void);
157219
158   /* on the tms9995-mp9537, internal RAM and decrementer register are
159        disabled.  This chip is used by the ti99/8 so that internal RAM does
160        not prevent the mapper from working correctly. */
161   int is_mp9537;
162} tms9995reset_param;
220   void   alu_nop(void);
221   void   alu_clear(void);
222   void   alu_source(void);
223   void   alu_setaddr(void);
224   void   alu_addone(void);
225   void   alu_setaddr_addone(void);
226   void   alu_pcaddr_advance(void);
227   void   alu_add_register(void);
163228
164/* accessor for the first 252 bytes of internal RAM */
165extern READ8_HANDLER(tms9995_internal1_r);
166extern WRITE8_HANDLER(tms9995_internal1_w);
167/* accessors for the last 4 bytes of internal RAM */
168extern READ8_HANDLER(tms9995_internal2_r);
169extern WRITE8_HANDLER(tms9995_internal2_w);
229   void   alu_imm(void);
230   void   alu_reg(void);
170231
232   void   alu_f1(void);
233   void   alu_comp(void);
234   void   alu_f3(void);
235   void   alu_multiply(void);
236   void   alu_divide(void);
237   void   alu_xop(void);
238   void   alu_clr_swpb(void);
239   void   alu_abs(void);
240   void   alu_x(void);
241   void   alu_b(void);
242   void   alu_bl(void);
243   void   alu_blwp(void);
244   void   alu_ldcr(void);
245   void   alu_stcr(void);
246   void   alu_sbz_sbo(void);
247   void   alu_tb(void);
248   void   alu_jmp(void);
249   void   alu_shift(void);
250   void   alu_ai_ori(void);
251   void   alu_ci(void);
252   void   alu_li(void);
253   void   alu_lwpi(void);
254   void   alu_limi(void);
255   void   alu_stwp_stst(void);
256   void   alu_external(void);
257   void   alu_rtwp(void);
258   void   alu_int(void);
171259
260   void   abort_operation(void);
261   UINT16   pulse_and_read_memory(UINT16 address);
262   void   pulse_and_write_memory(UINT16 address, UINT16 data);
263   void   decode(UINT16 inst);
172264
173//DECLARE_LEGACY_CPU_DEVICE(TMS99000, tms99000);
265   // Micro-operation
266   UINT8   m_op;
174267
175/*
176    structure with optional parameters for tms99000_reset.
177*/
178typedef struct tms99000reset_param
179{
180   ti99xx_idle_func   idle_callback;
181} tms99000reset_param;
268   // Micro-operation program counter (as opposed to the program counter PC)
269   int    MPC;
182270
271   // Current microprogram
272   const UINT8*   m_program;
183273
274   // Calling microprogram (used when data derivation is called)
275   const UINT8*   m_caller;
276   int          m_caller_MPC;
184277
185//DECLARE_LEGACY_CPU_DEVICE(TMS99105A, tms99105a);
278   // State of the micro-operation. Needed for repeated ALU calls.
279   int    m_state;
186280
187/*
188    structure with optional parameters for tms99105a_reset.
189*/
190typedef struct tms99105areset_param
191{
192   ti99xx_idle_func   idle_callback;
193} tms99105areset_param;
281   // Check the READY line?
282   bool   m_check_ready;
194283
284   // Has HOLD been acknowledged yet?
285   bool   m_hold_acknowledged;
195286
287   // Issue clock pulses. Note that each machine cycle has two clock cycles.
288   inline void pulse_clock(int count);
196289
197//DECLARE_LEGACY_CPU_DEVICE(TMS99110A, tms99110a);
290   // Signal the wait state via the external line
291   inline void set_wait_state(bool state);
198292
199/*
200    structure with optional parameters for tms99110a_reset.
201*/
202typedef struct tms99110areset_param
203{
204   ti99xx_idle_func   idle_callback;
205} tms99110areset_param;
293   // Used to acknowledge HOLD and enter the HOLD state
294   inline void acknowledge_hold();
206295
296   // Stored address
297   UINT16   m_address;
207298
208unsigned Dasm9900 (char *buffer, unsigned pc, int model_id, const UINT8 *oprom, const UINT8 *opram);
299   // Stores the recently read word or the word to be written
300   UINT16   m_current_value;
209301
302   // Was the source operand a byte from an even address?
303   bool m_source_even;
304
305   // Was the destination operand a byte from an even address?
306   bool m_destination_even;
307
308   // Intermediate storage for the source operand
309   UINT16 m_source_address;
310   UINT16 m_source_value;
311
312   // Stores the recently read register contents
313   UINT16   m_register_contents;
314
315   // Stores the register number for the next register access
316   int    m_regnumber;
317
318   // CRU support: Indicates whether the CRU shall be configured to output mode
319   bool   m_cru_output;
320
321   // CRU support: Stores the CRU address
322   UINT16   m_cru_address;
323
324   // CRU support: Stores the number of bits to be transferred
325   int      m_count;
326
327   // Another internal register, storing intermediate values
328   // Using 32 bits to support MPY
329   UINT32   m_value;
330
331   // For two-argument commands. Indicates whether this is the second operand.
332   bool   m_get_destination;
333
334   // Status register update
335   inline void set_status_bit(int bit, bool state);
336   inline void compare_and_set_lae(UINT16 value1, UINT16 value2);
337   void set_status_parity(UINT8 value);
338
339   // Used to display the number of consumed cycles in the log.
340   int      m_first_cycle;
341
342   /************************************************************************/
343
344   // Trigger external operation. This is achieved by putting a special value in
345   // the most significant three bits of the address bus (TMS9995: data bus) and
346   // pulsing the CRUCLK line.
347   // Accordingly, we have
348   //
349   // A0 A1 A2 A3 A4 A5 ... A12 A13 A14 A15
350   // 0  0  0  x  x  x      x   x   x   -     normal CRU access
351   // 0  1  0  x  x  x      x   x   x   -     IDLE
352   // 0  1  1  x  x  x      x   x   x   -     RSET
353   // 1  0  1  x  x  x      x   x   x   -     CKON
354   // 1  1  0  x  x  x      x   x   x   -     CKOF
355   // 1  1  1  x  x  x      x   x   x   -     LREX
356   //
357   // so the TMS9900 can only use CRU addresses 0 - 1ffe for CRU operations.
358   // By moving these three bits to the data bus, the TMS9995 can allow for the
359   // full range 0000-fffe for its CRU operations.
360   //
361   // We could realize this via the CRU access as well, but the data bus access
362   // is not that simple to emulate. For the sake of homogenity between the
363   // chip emulations we use a dedicated callback.
364   devcb_resolved_write8   m_external_operation;
365
366   // Get the value of the interrupt level lines
367   devcb_resolved_read8   m_get_ic0123;
368
369   // Signal to the outside world that we are now getting an instruction
370   devcb_resolved_write_line   m_iaq_line;
371
372   // Clock output. This is not a pin of the TMS9900 because the TMS9900
373   // needs an external clock, and usually one of those external lines is
374   // used for this purpose.
375   devcb_resolved_write_line   m_clock_out_line;
376
377   // Wait output. When asserted (high), the CPU is in a wait state.
378   devcb_resolved_write_line   m_wait_line;
379
380   // HOLD Acknowledge line. When asserted (high), the CPU is in HOLD state.
381   devcb_resolved_write_line   m_holda_line;
382};
383
384unsigned Dasm9900(char *buffer, unsigned pc, int model_id, const UINT8 *oprom, const UINT8 *opram);
385
386// device type definition
387extern const device_type TMS9900;
388
210389#endif /* __TMS9900_H__ */
src/emu/cpu/tms9900/tms9980al.c
r0r15424
1/*
2    generate the tms9980a/tms9981 emulator
3*/
4 
5#include "emu.h"
6#include "debugger.h"
7#include "tms9900l.h"
8 
9#define TMS99XX_MODEL TMS9980_ID
10 
11#include "99xxcore.h"
12 
13DEFINE_LEGACY_CPU_DEVICE(TMS9980L, tms9980al);
src/mess/machine/ti99/grom.c
r15423r15424
22
33    GROM emulation (aka TMC0430)
44
5    This is a preliminary implementation since it does not yet contain
6    internal timing; instead, it directly accesses the processor to
7    simulate wait states
8    When this will have become available, the file will be moved to the
9    general circuit collection (emu/machine)
10
115          +----+--+----+
126      AD7 |1    G    16| Vss
137      AD6 |2    R    15| GR
r15423r15424
2519    MO  = Mode. 1=address counter access, 0=data access
2620    GS* = GROM select. 0=select, 1=deselect
2721
28
2922    GROMs are slow ROM devices, which are
3023    interfaced via a 8-bit data bus, and include an internal address pointer
3124    which is incremented after each read.  This implies that accesses are
3225    faster when reading consecutive bytes, although the address pointer can be
3326    read and written at any time.
3427
35    They are generally used to store programs in GPL (Graphic Programming
36    Language: a proprietary, interpreted language - the interpreter takes most
37    of a TI99/4(a) CPU ROMs).  They can used to store large pieces of data,
38    too.
28    GROMs are generally used to store programs written in GPL (Graphic Programming
29    Language): a proprietary, interpreted language. The GPL interpreter takes
30    most space of the TI-99/4A system ROMs.
3931
40    Both TI-99/4 and TI-99/4a include three GROMs, with some start-up code,
32    Both TI-99/4 and TI-99/4A include three GROMs, with some start-up code,
4133    system routines and TI-Basic.  TI99/4 includes an additional Equation
4234    Editor.  According to the preliminary schematics found on ftp.whtech.com,
4335    TI-99/8 includes the three standard GROMs and 16 GROMs for the UCSD
r15423r15424
4537    support any, although it should be relatively easy to create an expansion
4638    card with the GPL interpreter and a /4a cartridge port.
4739
48The simple way:
40    Communication with GROM is done by writing and reading data over the
41    AD0-AD7 lines. Within the TI-99 systems, the address bus is decoded for
42    the M, GS*, and MO lines: Writing a byte to address 9c02 asserts the GS* and
43    MO line, and clears the M line, which means the transmitted byte is put into
44    the internal address register. Two bytes must be written to set up the
45    complete address.
4946
50    Each GROM is logically 8kb long.
47    It was obviously planned to offer GRAM circuits as well, since the
48    programming manuals refer to writing to a special address, clearing the MO
49    line. Although the TI-99 systems reserve a port in the memory space, no one
50    has ever seen a GRAM circuit in the wild. However, third-party products like
51    HSGPL or GRAM Kracker simulate GRAMs using conventional RAM with some
52    addressing circuitry, usually in a custom  chip.
5153
52    Communication with GROM is done with 4 memory-mapped locations.  You can read or write
53    a 16-bit address pointer, and read data from GROMs.  One register allows to write data, too,
54    which would support some GRAMs, but AFAIK TI never built such GRAMs (although docs from TI
55    do refer to this possibility).
54    Each GROM is logically 8 KiB long. Original TI-built GROM are 6 KiB long;
55    the extra 2kb can be read, and follow the following formula:
5656
57    Since address are 16-bit long, you can have up to 8 GROMs.  So, a cartridge may
58    include up to 5 GROMs.  (Actually, there is a way more GROMs can be used - see below...)
59
60    The address pointer is incremented after each GROM operation, but it will always remain
61    within the bounds of the currently selected GROM (e.g. after 0x3fff comes 0x2000).
62
63Some details:
64
65    Original TI-built GROM are 6kb long, but take 8kb in address space.  The extra 2kb can be
66    read, and follow the following formula:
6757        GROM[0x1800+offset] = GROM[0x0800+offset] | GROM[0x1000+offset];
68    (sounds like address decoding is incomplete - we are lucky we don't burn any silicon when
69    doing so...)
7058
71    Needless to say, some hackers simulated 8kb GRAMs and GROMs with normal RAM/PROM chips and
72    glue logic.
59    (sounds like address decoding is incomplete - we are lucky we don't burn
60    any silicon when doing so... Needless to say, some hackers simulated 8kb
61    GRAMs and GROMs with normal RAM/PROM chips and glue logic.)
7362
74GROM ports:
63    The address pointer is incremented after each GROM operation, but it will
64    always remain within the bounds of the currently selected GROM (e.g. after
65    0x3fff comes 0x2000).
7566
76    When accessing the GROMs registers, 8 address bits (cpu_addr & 0x03FC) may
77    be used as a port number, which permits the use of up to 256 independent
78    GROM ports, with 64kb of address space in each.  TI99/4(a) ROMs can take
79    advantage of the first 16 ports: it will look for GPL programs in every
80    GROM of the 16 first ports.  Additionally, while the other 240 ports cannot
81    contain standard GROMs with GPL code, they may still contain custom GROMs
82    with data.
67    Since address are 16-bit long, you can have up to 8 GROMs.  Accordingly,
68    a cartridge may include up to 5 GROMs.
8369
84    Note, however, that the TI99/4(a) console does not decode the page number, so console GROMs
85    occupy the first 24kb of EVERY port, and cartridge GROMs occupy the next 40kb of EVERY port
86    (with the exception of one demonstration from TI that implements several distinct ports).
87    (Note that the TI99/8 console does have the required decoder.)  Fortunately, GROM drivers
88    have a relatively high impedance, and therefore extension cards can use TTL drivers to impose
89    another value on the data bus with no risk of burning the console GROMs.  This hack permits
90    the addition of additionnal GROMs in other ports, with the only side effect that whenever
91    the address pointer in port N is altered, the address pointer of console GROMs in port 0
92    is altered, too.  Overriding the system GROMs with custom code is possible, too (some hackers
93    have done so), but I would not recommended it, as connecting such a device to a TI99/8 might
94    burn some drivers.
95
96    The p-code card (-> UCSD Pascal system) contains 8 GROMs, all in port 16.  This port is not
97    in the range recognized by the TI ROMs (0-15), and therefore it is used by the p-code DSR ROMs
98    as custom data.  Additionally, some hackers used the extra ports to implement "GRAM" devices.
99
10070    Every GROM has an internal ID which represents the high-order three
10171    address bits. The address counter can be set to any value from 0
102    to 0xffff; the GROM will only react if selected and if the current
72    to 0xffff; the GROM will only react when selected and when the current
10373    address counter's high-order bits match the ID of the chip.
10474    Example: When the ID is 6, the GROM will react when the address
10575    counter contains a value from 0xc000 to 0xdfff.
10676
107    Writable GROMs are called GRAMs. Although the TI-99 systems reserve a
108    port in the memory space, no one has ever seen a GRAM circuit in the wild.
109    However, third-party products like HSGPL or GRAM Kracker simulate GRAMs
110    using conventional RAM with some addressing circuitry, usually in a custom
111    chip.
112
11377    CHECK: Reading the address increases the counter only once. The first access
11478    returns the MSB, the second (and all following accesses) return the LSB.
11579
r15423r15424
182146            m_buffer = m_memptr[addr];
183147      }
184148      // Note that all GROMs update their address counter.
185      if (m_rollover)
186         m_address = ((m_address + 1) & 0x1FFF) | (m_address & 0xE000);
187      else
188         m_address = (m_address + 1)&0xFFFF;
149      m_address = (m_address + 1)&0xFFFF;
189150
190151      // Reset the read and write address flipflops.
191152      m_raddr_LSB = m_waddr_LSB = false;
153
154      // Maybe the timer is also required for address reading/setting, but
155      // we don't have such technical details on GROMs.
156      clear_ready();
192157   }
193158}
194159
r15423r15424
235200         UINT16 write_addr;
236201         // We need to rewind by 1 because the read address has already advanced.
237202         // However, do not change the address counter!
238         if (m_rollover)
239            write_addr = ((m_address + 0x1fff) & 0x1FFF) | (m_address & 0xE000);
240         else
241            write_addr = (m_address - 1) & 0xFFFF;
203         write_addr = (m_address - 1) & 0xFFFF;
242204
243205         // UINT16 addr = m_address-(m_ident<<13);
244206         if (m_size > 0x1800 || ((m_address&0x1fff)<0x1800))
245207            m_memptr[write_addr-(m_ident<<13)] = data;
246208      }
247209      m_raddr_LSB = m_waddr_LSB = false;
210      clear_ready();
248211   }
249212
250   if (m_rollover)
251      m_address = ((m_address + 1) & 0x1FFF) | (m_address & 0xE000);
252   else
253      m_address = (m_address + 1) & 0xFFFF;
213   m_address = (m_address + 1) & 0xFFFF;
254214}
255215
216/*
217    Timing. We assume that each data read results in READY going down for
218    one cycle at the given frequency.
219*/
220void ti99_grom_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
221{
222   m_gromready(ASSERT_LINE);
223}
224
225void ti99_grom_device::clear_ready()
226{
227   m_gromready(CLEAR_LINE);
228   m_timer->adjust(attotime::from_hz(m_clockrate));
229}
230
256231/***************************************************************************
257232    DEVICE FUNCTIONS
258233***************************************************************************/
259234
260235void ti99_grom_device::device_start(void)
261236{
262   m_gromready.resolve(m_ready, *this);
263   // Test
264   // m_gromready(ASSERT_LINE);
265}
266
267void ti99_grom_device::device_config_complete(void)
268{
269237   const ti99grom_config *conf = reinterpret_cast<const ti99grom_config *>(static_config());
270238
271   if ( conf != NULL )
272   {
273      *static_cast<ti99grom_config *>(this) = *conf;
274   }
239   m_memptr = owner()->memregion(conf->regionname)->base();
240   assert (m_memptr!=NULL);
241   m_memptr += conf->offset_reg;
242
243   m_size = conf->size;
244   m_clockrate = conf->clockrate;
245   m_writable = conf->writable;
246   m_ident = conf->ident;
247   m_gromready.resolve(conf->ready, *this);
248
249   m_timer = timer_alloc(0);
275250}
276251
277252void ti99_grom_device::device_reset(void)
r15423r15424
280255   m_raddr_LSB = false;
281256   m_waddr_LSB = false;
282257   m_buffer = 0;
283
284   m_memptr = owner()->memregion(m_regionname)->base();
285   assert (m_memptr!=NULL);
286
287   m_memptr += m_offset_reg;
288258}
289259
290260const device_type GROM = &device_creator<ti99_grom_device>;
src/mess/machine/ti99/grom.h
r15423r15424
1515
1616typedef struct _ti99grom_config
1717{
18   bool            m_writable;
19   int             m_ident;
20   const char         *m_regionname;
21   offs_t            m_offset_reg;
22   // If the GROM has only 6 KiB, the remaining 2 KiB are filled with a
23   // specific byte pattern which is created by a logical OR of lower
24   // regions
25   int               m_size;
26   bool            m_rollover;   // some GRAM simulations do not implement rollover
27   devcb_write_line   m_ready;
18   bool            writable;
19   int             ident;
20   const char         *regionname;
21   offs_t            offset_reg;
22   int               size;
23   devcb_write_line   ready;
24   int               clockrate;
2825} ti99grom_config;
2926
3027#define GROM_CONFIG(name) \
r15423r15424
4441   DECLARE_WRITE8_MEMBER(write);
4542
4643private:
44   // Is this a GRAM (never seen actually, but obviously planned)
45   bool      m_writable;
46
47   // Identification of this GROM (0-7)
48   int       m_ident;
49
50   // If the GROM has only 6 KiB, the remaining 2 KiB are filled with a
51   // specific byte pattern which is created by a logical OR of lower
52   // regions
53   int         m_size;
54
55   // Ready callback. This line is usually connected to the READY pin of the CPU.
56   devcb_resolved_write_line   m_gromready;
57
58   // Frequency of the incoming GROM clock. In most application cases the
59   // GROM gets its clock from the video display processor (TMS9918)
60   int      m_clockrate;
61
4762   /* Address pointer. */
4863   // This value is always expected to be in the range 0x0000 - 0xffff, even
4964   // when this GROM is not addressed.
r15423r15424
6176   /* Pointer to the memory region contained in this GROM. */
6277   UINT8 *m_memptr;
6378
64   /* Ready callback. This line is usually connected to the READY pin of the CPU. */
65   devcb_resolved_write_line m_gromready;
79   // Timer for READY line operation
80   emu_timer *m_timer;
6681
6782   /* Indicates whether this device will react on the next read/write data access. */
68   int is_selected()
83   inline int is_selected()
6984   {
7085      return (((m_address >> 13)&0x07)==m_ident);
7186   }
7287
88   // Calling this method causes the READY line to be cleared, which puts the
89   // CPU into wait state mode. A timer is set to raise READY again.
90   void clear_ready();
91
7392   void device_start(void);
7493   void device_reset(void);
75   void device_config_complete(void);
94   void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
7695};
7796
7897
src/mess/machine/ti99/gromport.c
r15423r15424
12331233
12341234static GROM_CONFIG(grom3_config)
12351235{
1236   false, 3, CARTGROM_TAG, 0x0000, 0x1800, false, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, gromport_device, ready_line)
1236   false, 3, CARTGROM_TAG, 0x0000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(":gromport", gromport_device, ready_line), GROMFREQ
12371237};
12381238static GROM_CONFIG(grom4_config)
12391239{
1240   false, 4, CARTGROM_TAG, 0x2000, 0x1800, false, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, gromport_device, ready_line)
1240   false, 4, CARTGROM_TAG, 0x2000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(":gromport", gromport_device, ready_line), GROMFREQ
12411241};
12421242static GROM_CONFIG(grom5_config)
12431243{
1244   false, 5, CARTGROM_TAG, 0x4000, 0x1800, false, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, gromport_device, ready_line)
1244   false, 5, CARTGROM_TAG, 0x4000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(":gromport", gromport_device, ready_line), GROMFREQ
12451245};
12461246static GROM_CONFIG(grom6_config)
12471247{
1248   false, 6, CARTGROM_TAG, 0x6000, 0x1800, false, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, gromport_device, ready_line)
1248   false, 6, CARTGROM_TAG, 0x6000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(":gromport", gromport_device, ready_line), GROMFREQ
12491249};
12501250static GROM_CONFIG(grom7_config)
12511251{
1252   false, 7, CARTGROM_TAG, 0x8000, 0x1800, false, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, gromport_device, ready_line)
1252   false, 7, CARTGROM_TAG, 0x8000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(":gromport", gromport_device, ready_line), GROMFREQ
12531253};
12541254
12551255/*
src/mess/machine/ti99/genboard.c
r15423r15424
143143#include "genboard.h"
144144#include "machine/mm58274c.h"
145145
146#define CYCLE 333      // 333 ns for CLKOUT
147#define VIDEOWAIT 1      // timer ID
148
149146#define VERBOSE 1
150147#define LOG logerror
151148
r15423r15424
155152   m_eprom = NULL;
156153}
157154
158/*
159    Callback for VDP waitstate. Not really needed, just for completeness.
160*/
161void geneve_mapper_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
162{
163   // Just remove that flag again.
164   m_video_waiting = false;
165}
166
167155INPUT_CHANGED_MEMBER( geneve_mapper_device::gm_changed )
168156{
169157   int number = (int)((UINT64)param&0x03);
r15423r15424
172160   if (number==1)
173161   {
174162      // Turbo switch. May be changed at any time.
175      if (VERBOSE>0) LOG("geneve / genmod: Setting turbo flag to %d\n", value);
163      if (VERBOSE>0) LOG("genboard: Setting turbo flag to %d\n", value);
176164      m_turbo = (value!=0);
177165   }
178166   else
179167   {
180168      // TIMode switch. Causes reset when changed.
181      if (VERBOSE>0) LOG("geneve / genmod: Setting timode flag to %d\n", value);
169      if (VERBOSE>0) LOG("genboard: Setting timode flag to %d\n", value);
182170      m_timode = (value!=0);
183171      machine().schedule_hard_reset();
184172   }
r15423r15424
275263
276264*/
277265
278void geneve_mapper_device::start_video_wait(int ws)
279{
280   m_video_waittimer->adjust(attotime::from_nsec(CYCLE * ws));
281   m_video_waiting = true;
282}
283
284266void geneve_mapper_device::do_wait(int min)
285267{
286   long ws;
287
268   min = min + 1;
288269   // Extra waitstates?
289   if (m_extra_waitstates && min < 2) min = 2;
290
291   if (m_video_waiting) {
292      attotime left = m_video_waittimer->remaining();
293      ws = (left.as_attoseconds()/ATTOSECONDS_PER_NANOSECOND) / CYCLE;
270   if (m_extra_waitstates && min < 4) min = 3;
271   m_waitcount = min;
272   if (m_waitcount > 0)
273   {
274      if (VERBOSE>8) LOG("genboard: Pulling down READY line for %d cycles\n", m_waitcount);
275      m_ready(CLEAR_LINE);
294276   }
295   else ws = 0;
296
297   // Now wait for the remaining time or for at least the min time
298   device_adjust_icount(m_cpu, -4 * ((ws < min)? min : ws));
299277}
300278
301279/************************************************************************
r15423r15424
330308         // Initialize wait state timer
331309         // Create 16 wait states (2 more than expected, experimenting)
332310         if (m_video_waitstates)
333            start_video_wait(16);
311            do_wait(16);
334312
335313         m_video->readz(space, offset, &value, mem_mask);
314         if (VERBOSE>7) LOG("genboard: Read video %04x -> %02x\n", offset, value);
336315         return value;
337316      }
338317      if ((offset & 0xfff8)==0xf110)
r15423r15424
343322         // Add appropriate number of waitstates
344323         // 1 WS is added at least
345324         do_wait(1);
325         if (VERBOSE>7) LOG("genboard: read mapper %04x -> %02x\n", offset, value);
346326         return value;
347327      }
348328      if ((offset & 0xfff8) == 0xf118)
r15423r15424
350330         // key
351331         value = m_keyboard->get_recent_key();
352332         do_wait(1);
333         if (VERBOSE>7) LOG("genboard: Read keyboard -> %02x\n", value);
353334         return value;
354335      }
355336      if ((offset & 0xfff0)==0xf130)
r15423r15424
359340         // upper nibble is 0xf (probably because of the location at 0xf130?)
360341         value = mm58274c_r(m_clock, offset & 0x000f) | 0xf0;
361342         do_wait(1);
343         if (VERBOSE>7) LOG("genboard: Read clock %04x -> %02x\n", offset, value);
362344         return value;
363345      }
364346   }
r15423r15424
369351         // mapper
370352         value = m_map[offset & 0x0007];
371353         do_wait(1);
354         if (VERBOSE>7) LOG("genboard: Read mapper %04x -> %02x\n", offset, value);
372355         return value;
373356      }
374357      if ((offset & 0xfff8)== 0x8008)
r15423r15424
376359         // key
377360         value = m_keyboard->get_recent_key();
378361         do_wait(1);
362         if (VERBOSE>7) LOG("genboard: Read keyboard -> %02x\n", value);
379363         return value;
380364      }
381365      if ((offset & 0xfff0)==0x8010)
r15423r15424
392376         value |= ((offset & 0x000f)==0x000f)? 0x20 : 0x10;
393377
394378         do_wait(1);
379         if (VERBOSE>7) LOG("genboard: Read clock %04x -> %02x\n", offset, value);
395380         return value;
396381      }
397382      if ((offset & 0xfc01)==0x8800)
r15423r15424
399384         // video
400385         // ++++ ++-- ---- ---+
401386         // 1000 1000 0000 00x0
402         //  device_adjust_icount(m_cpu, -4);
403387
404388         // 1 WS is always added; any pending video waitstates are canceled
405389         m_video_waiting = false;
r15423r15424
408392         // Initialize waitstate timer
409393         // Create 14 waitstates (+2, see above)
410394         if (m_video_waitstates)
411            start_video_wait(16);
395            do_wait(16);
412396
413397         m_video->readz(space, offset, &value, mem_mask);
398         if (VERBOSE>7) LOG("genboard: Read video %04x -> %02x\n", offset, value);
414399         return value;
415400      }
416401      if ((offset & 0xfc01)==0x9000)
r15423r15424
422407         m_peribox->readz(space, offset | ((m_genmod)? 0x170000 : 0x070000), &value, mem_mask);
423408
424409         do_wait(1);
410         if (VERBOSE>7) LOG("genboard: Read speech -> %02x\n", value);
425411         return value;
426412      }
427413      if ((offset & 0xfc01)==0x9800)
r15423r15424
432418         value = read_grom(space, offset, mem_mask);
433419
434420         do_wait(1);
421         if (VERBOSE>7) LOG("genboard: Read GROM %04x -> %02x\n", offset, value);
435422         return value;
436423      }
437424   }
r15423r15424
451438         // value 0x36 = 0 0110 110x xxxx xxxx xxxx (page 1)
452439         // value 0x37 = 0 0110 111x xxxx xxxx xxxx (page 2)
453440         // Only use this if there are 2*8 KiB cartridge ROM
441         if (VERBOSE>7) LOG("genboard: Cartridge area\n");
454442         if (m_cartridge_size==0x4000 && m_cartridge_secondpage) physaddr = 0x06e000;
455443         else physaddr = 0x06c000;
456444      }
r15423r15424
468456      if ((physaddr & 0x180000)==0x000000)
469457      {
470458         // DRAM. One wait state.
471         // device_adjust_icount(m_cpu, -4);
472459         do_wait(1);
473460
474461         value = m_dram[physaddr & 0x07ffff];
475462//          printf("dram read physaddr = %06x logaddr = %04x value = %02x\n", physaddr, offset, value);
463         if (VERBOSE>7) LOG("genboard: Read DRAM %04x (%06x) -> %02x\n", offset, physaddr, value);
476464         return value;
477465      }
478466
479467      if ((physaddr & 0x180000)==0x080000)
480468      {
481469         // On-board memory expansion for standard Geneve (never used)
482         // device_adjust_icount(m_cpu, -4);
483470         do_wait(1);
471         if (VERBOSE>7) LOG("genboard: Read unmapped area %06x\n", physaddr);
484472         return 0;
485473      }
486474
r15423r15424
489477         // 1 111. ..xx xxxx xxxx xxxx on-board eprom (16K)
490478         // mirrored for f0, f2, f4, ...; f1, f3, f5, ...
491479         value = m_eprom[physaddr & 0x003fff];
492         if (VERBOSE>8) LOG("eprom read physaddr = %06x logaddr = %04x value = %02x\n", physaddr, offset, value);
493         do_wait(1);
480         do_wait(0);
481         if (VERBOSE>7) LOG("genboard: Read EPROM %04x (%06x) -> %02x\n", offset, physaddr, value);
494482         return value;
495483      }
496484
r15423r15424
503491         // Return in any case
504492//          printf("sram read physaddr = %06x logaddr = %04x value = %02x\n", physaddr, offset, value);
505493         do_wait(0);
494         if (VERBOSE>7) LOG("genboard: Read SRAM %04x (%06x) -> %02x\n", offset, physaddr, value);
506495         return value;
507496      }
508497
r15423r15424
514503
515504      physaddr = (physaddr & 0x0007ffff);  // 19 bit address (with AMA..AMC)
516505      m_peribox->readz(space, physaddr, &value, mem_mask);
506      if (VERBOSE>7) LOG("genboard: Read P-Box %04x (%06x) -> %02x\n", offset, physaddr, value);
517507      return value;
518508   }
519509   else
r15423r15424
579569         // video
580570         // ++++ ++++ ++++ ---+
581571         // 1111 0001 0000 .cc0
582         // device_adjust_icount(m_cpu, -4);
583
584572         m_video->write(space, offset, data, mem_mask);
585573
586574         // 1 WS is always added; any pending video waitstates are canceled
r15423r15424
590578         // Initialize waitstate timer
591579         // Create 14 waitstates (+3, experimenting)
592580         if (m_video_waitstates)
593            start_video_wait(17);
581            do_wait(17);
594582
583         if (VERBOSE>7) LOG("genboard: Write video %04x <- %02x\n", offset, data);
595584         return;
596585      }
597586      if ((offset & 0xfff8)==0xf110)
r15423r15424
599588         // mapper
600589         m_map[offset & 0x0007] = data;
601590         do_wait(1);
591         if (VERBOSE>7) LOG("genboard: Write mapper %04x <- %02x\n", offset, data);
602592         return;
603593      }
604594      if ((offset & 0xfff1)==0xf120)
r15423r15424
610600         // Add 24 waitstates. This is an average value, as the
611601         // waitstate generation seems to depend on an external timer of
612602         // the sound chip
613         device_adjust_icount(m_cpu, -4 * 24);
603         m_waitcount = 24;
604         m_ready(CLEAR_LINE);
605         if (VERBOSE>7) LOG("genboard: Write sound <- %02x\n", data);
614606         return;
615607      }
616608      if ((offset & 0xfff0)==0xf130)
r15423r15424
619611         // ++++ ++++ ++++ ----
620612         mm58274c_w(m_clock, offset & 0x00f, data);
621613         do_wait(1);
614         if (VERBOSE>7) LOG("genboard: Write clock %04x <- %02x\n", offset, data);
622615         return;
623616      }
624617   }
r15423r15424
630623         // mapper
631624         m_map[offset & 0x0007] = data;
632625         do_wait(1);
626         if (VERBOSE>7) LOG("genboard: Write mapper %04x <- %02x\n", offset, data);
633627         return;
634628      }
635629      // No key write at 8008
r15423r15424
638632         // clock
639633         mm58274c_w(m_clock, offset & 0x00f, data);
640634         do_wait(1);
635         if (VERBOSE>7) LOG("genboard: Write clock %04x <- %02x\n", offset, data);
641636         return;
642637      }
643638      if ((offset & 0xfc01)==0x8400)
r15423r15424
650645         // Add 24 waitstates. This is an approximation, as the
651646         // waitstate generation seems to depend on an external timer of
652647         // the sound chip
653         device_adjust_icount(m_cpu, -4 * 24);
648         m_waitcount = 24;
649         m_ready(CLEAR_LINE);
650         if (VERBOSE>7) LOG("genboard: Write sound <- %02x\n", data);
654651         return;
655652      }
656653      if ((offset & 0xfc01)==0x8c00)
r15423r15424
658655         // video
659656         // ++++ ++-- ---- ---+
660657         // 1000 1100 0000 00c0
661         // device_adjust_icount(m_cpu, -4);
662658         // Initialize waitstate timer
663659         m_video->write(space, offset, data, mem_mask);
664660
r15423r15424
669665         // Initialize waitstate timer
670666         // Create 14 waitstates (+3)
671667         if (m_video_waitstates)
672            start_video_wait(17);
668            do_wait(17);
673669
670         if (VERBOSE>7) LOG("genboard: Write video %04x <- %02x\n", offset, data);
674671         return;
675672      }
676673      if ((offset & 0xfc01)==0x9400)
r15423r15424
681678         // We need to add the address prefix bits
682679         m_peribox->write(space, offset | ((m_genmod)? 0x170000 : 0x070000), data, mem_mask);
683680         do_wait(1);
681         if (VERBOSE>7) LOG("genboard: Write speech <- %02x\n", data);
684682         return;
685683      }
686684      if ((offset & 0xfc01)==0x9c00)
r15423r15424
690688         // 1001 1100 0000 00c0
691689         write_grom(space, offset, data, mem_mask);
692690         do_wait(1);
691         if (VERBOSE>7) LOG("genboard: Write GROM %04x <- %02x\n", offset, data);
693692         return;
694693      }
695694   }
r15423r15424
709708            // writing to 0x6002 selects page 2
710709            m_cartridge_secondpage = ((offset & 0x0002)!=0);
711710            do_wait(1);
711            if (VERBOSE>7) LOG("genboard: Set cartridge page %02x\n", m_cartridge_secondpage);
712
712713            return;
713714         }
714715         else
r15423r15424
740741         // DRAM write. One wait state. (only for normal Geneve)
741742         m_dram[physaddr & 0x07ffff] = data;
742743         do_wait(1);
744         if (VERBOSE>7) LOG("genboard: Write DRAM %04x (%06x) <- %02x\n", offset, physaddr, data);
743745         return;
744746      }
745747
r15423r15424
747749      {
748750         // On-board memory expansion for standard Geneve (never used)
749751         do_wait(1);
752         if (VERBOSE>7) LOG("genboard: Write unmapped area %06x\n", physaddr);
750753         return;
751754      }
752755
r15423r15424
755758         // 1 111. ..xx xxxx xxxx xxxx on-board eprom (16K)
756759         // mirrored for f0, f2, f4, ...; f1, f3, f5, ...
757760         // Ignore EPROM write
758         do_wait(1);
761         do_wait(0);
762         if (VERBOSE>7) LOG("genboard: Write EPROM %04x (%06x) <- %02x, ignored\n", offset, physaddr, data);
759763         return;
760764      }
761765
r15423r15424
765769         {
766770            m_sram[physaddr & ~m_sram_mask] = data;
767771         }
772         if (VERBOSE>7) LOG("genboard: Write SRAM %04x (%06x) <- %02x\n", offset, physaddr, data);
768773         do_wait(0);
769774         // Return in any case
770775         return;
r15423r15424
774779
775780      // only AMA, AMB, AMC are used; AMD and AME are not used
776781      physaddr = (physaddr & 0x0007ffff);  // 19 bit address
782      if (VERBOSE>7) LOG("genboard: Write P-Box %04x (%06x) <- %02x\n", offset, physaddr, data);
777783      m_peribox->write(space, physaddr, data, mem_mask);
778784      do_wait(1);
779785   }
r15423r15424
803809   }
804810}
805811
812/*
813    The mapper is connected to the clock line in order to operate
814    the wait state counter.
815*/
816void geneve_mapper_device::clock_in(int clock)
817{
818   if (clock==ASSERT_LINE && m_waitcount!=0)
819   {
820      m_waitcount--;
821      if (m_waitcount==0) m_ready(ASSERT_LINE);
822   }
823}
824
825/***    DEVICE LIFECYCLE FUNCTIONS      ***/
826
806827void geneve_mapper_device::device_start()
807828{
808   if (VERBOSE>0) LOG("geneve: Starting Geneve mapper\n");
829   const geneve_mapper_config *conf = reinterpret_cast<const geneve_mapper_config *>(static_config());
830
831   if (VERBOSE>0) LOG("genboard: Starting Geneve mapper\n");
809832   // Get pointers
810833   m_peribox = machine().device<bus8z_device>(PERIBOX_TAG);
811834   m_keyboard = machine().device<geneve_keyboard_device>(GKEYBOARD_TAG);
812835   m_video = machine().device<bus8z_device>(VIDEO_SYSTEM_TAG);
813836   m_sound = machine().device<bus8z_device>(TISOUND_TAG);
814837   m_clock = machine().device(GCLOCK_TAG);
815   m_cpu = machine().device("maincpu");
816838
839   m_ready.resolve(conf->ready, *this);
840
817841   // This is a preliminary setting; the initial context switch occurs before
818842   // device_reset. Luckily, the reset vector at >0000/>0002 is the same for
819843   // all variants of the boot eprom.
820   m_eprom = machine().root_device().memregion("maincpu")->base();
844//  m_eprom = machine().root_device().memregion("maincpu")->base();
821845
822846   m_sram = machine().root_device().memregion(SRAM_TAG)->base();
823847   m_dram = machine().root_device().memregion(DRAM_TAG)->base();
r15423r15424
825849   m_geneve_mode = false;
826850   m_direct_mode = true;
827851
828   // Used for generating the VDP waitstates. These are created in the
829   // Gate Array on the board and only affect external memory accesses.
830   // Therefore we cannot use the usual adjust_icount
831   m_video_waittimer = timer_alloc(VIDEOWAIT);
852   m_waitcount = 0;
832853}
833854
834855void geneve_mapper_device::device_reset()
835856{
836   if (VERBOSE>0) LOG("geneve: Resetting mapper\n");
857   if (VERBOSE>1) LOG("genboard: Resetting mapper\n");
837858
838859   m_extra_waitstates = false;
839860   m_video_waitstates = true;
r15423r15424
856877      switch (machine().root_device().ioport("BOOTROM")->read())
857878      {
858879      case GENEVE_098:
859         if (VERBOSE>0) LOG("geneve: Using 0.98 boot eprom\n");
880         if (VERBOSE>0) LOG("genboard: Using 0.98 boot eprom\n");
860881         m_eprom = machine().root_device().memregion("maincpu")->base() + 0x4000;
861882         break;
862883      case GENEVE_100:
863         if (VERBOSE>0) LOG("geneve: Using 1.00 boot eprom\n");
884         if (VERBOSE>0) LOG("genboard: Using 1.00 boot eprom\n");
864885         m_eprom = machine().root_device().memregion("maincpu")->base();
865886         break;
866887      }
867888   }
868889   else
869890   {
870      if (VERBOSE>0) LOG("geneve: Using GenMod modification\n");
891      if (VERBOSE>0) LOG("genboard: Using GenMod modification\n");
871892      m_eprom = machine().root_device().memregion("maincpu")->base() + 0x8000;
872893      if (m_eprom[0] != 0xf0)
873894      {
r15423r15424
947968   m_key_queue[(m_key_queue_head + m_key_queue_length) % KEYQUEUESIZE] = keycode;
948969   m_key_queue_length++;
949970
950   if (VERBOSE>5) LOG("geneve: posting keycode %02x\n", keycode);
971   if (VERBOSE>5) LOG("genboard: posting keycode %02x\n", keycode);
951972}
952973
953974void geneve_keyboard_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
r15423r15424
962983   int i, j;
963984   int keycode;
964985   int pressed;
965   if (VERBOSE>8) LOG("geneve: poll keyboard\n");
986   if (VERBOSE>7) LOG("genboard: poll keyboard\n");
966987   if (m_key_reset) return;
967988
968989   /* Poll keyboard */
r15423r15424
11681189   // buffer clear is disabled, and key queue is not empty. */
11691190   if ((!m_key_reset) && (m_keyboard_clock) && (m_keep_keybuf) && (m_key_queue_length != 0))
11701191   {
1171      if (VERBOSE>6) LOG("geneve: signalling key available\n");
1192      if (VERBOSE>6) LOG("genboard: signalling key available\n");
11721193      m_interrupt(ASSERT_LINE);
11731194      m_key_in_buffer = true;
11741195   }
r15423r15424
11781199{
11791200   bool rising_edge = (!m_keyboard_clock && (state==ASSERT_LINE));
11801201   m_keyboard_clock = (state==ASSERT_LINE);
1181   if (VERBOSE>5) LOG("geneve: keyboard clock_control state=%d\n", m_keyboard_clock);
1202   if (VERBOSE>5) LOG("genboard: keyboard clock_control state=%d\n", m_keyboard_clock);
11821203   if (rising_edge)
11831204      signal_when_key_available();
11841205}
r15423r15424
12351256
12361257void geneve_keyboard_device::device_start()
12371258{
1238   if (VERBOSE>2) LOG("geneve: Keyboard started\n");
1259   if (VERBOSE>2) LOG("genboard: Keyboard started\n");
12391260   m_timer = timer_alloc(0);
12401261}
12411262
src/mess/machine/ti99/genboard.h
r15423r15424
110110
111111/*****************************************************************************/
112112
113typedef struct _geneve_mapper_config
114{
115   devcb_write_line   ready;
116} geneve_mapper_config;
117
113118class geneve_mapper_device : public device_t
114119{
115120public:
116121   geneve_mapper_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
117   void set_geneve_mode(bool geneve) { m_geneve_mode = geneve; }
118   void set_direct_mode(bool direct) { m_direct_mode = direct; }
119   void set_cartridge_size(int size) { m_cartridge_size = size; }
120   void set_cartridge_writable(int base, bool write)
122   inline void set_geneve_mode(bool geneve) { m_geneve_mode = geneve; }
123   inline void set_direct_mode(bool direct) { m_direct_mode = direct; }
124   inline void set_cartridge_size(int size) { m_cartridge_size = size; }
125   inline void set_cartridge_writable(int base, bool write)
121126   {
122127      if (base==0x6000)  m_cartridge6_writable = write;
123128      else  m_cartridge7_writable = write;
124129   }
125   void set_video_waitstates(bool wait) { m_video_waitstates = wait; }
126   void set_extra_waitstates(bool wait) { m_extra_waitstates = wait; }
127   void start_video_wait(int ws);
130   inline void set_video_waitstates(bool wait) { m_video_waitstates = wait; }
131   inline void set_extra_waitstates(bool wait) { m_extra_waitstates = wait; }
132
128133   void do_wait(int min);
129134
130135   DECLARE_READ8_MEMBER( readm );
r15423r15424
132137
133138   DECLARE_INPUT_CHANGED_MEMBER( gm_changed );
134139
140   void clock_in(int state);
141
135142protected:
136143   void   device_start();
137144   void   device_reset();
r15423r15424
143150   int      m_grom_address;
144151   DECLARE_READ8_MEMBER( read_grom );
145152   DECLARE_WRITE8_MEMBER( write_grom );
146   void   device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
147153
148154   // wait states
149   emu_timer   *m_video_waittimer;
150155   bool      m_video_waiting;
151156   bool      m_video_waitstates;
152157   bool      m_extra_waitstates;
r15423r15424
168173   int      m_sram_mask;
169174   int      m_sram_val;
170175
176   // Ready line to the CPU
177   devcb_resolved_write_line m_ready;
178
179   // Counter for the wait states.
180   int   m_waitcount;
181
171182   // Devices
172   device_t*      m_clock;
173   device_t*      m_cpu;
183   device_t*            m_clock;
174184   geneve_keyboard_device*   m_keyboard;
175   bus8z_device*   m_video;
176   bus8z_device*   m_peribox;
177   bus8z_device*   m_sound;
178   UINT8*         m_eprom;
179   UINT8*         m_sram;
180   UINT8*         m_dram;
185   bus8z_device*         m_video;
186   bus8z_device*         m_peribox;
187   bus8z_device*         m_sound;
188   UINT8*               m_eprom;
189   UINT8*               m_sram;
190   UINT8*               m_dram;
181191};
182192
183#define MCFG_GENEVE_MAPPER_ADD(_tag )   \
184   MCFG_DEVICE_ADD(_tag, GENEVE_MAPPER, 0)
193#define GENEVE_MAPPER_CONFIG(name) \
194   const geneve_mapper_config(name) =
195
196#define MCFG_GENEVE_MAPPER_ADD(_tag, _conf )   \
197   MCFG_DEVICE_ADD(_tag, GENEVE_MAPPER, 0)   \
198   MCFG_DEVICE_CONFIG( _conf )
199
185200#endif
src/mess/machine/ti99/ti_fdc.c
r15423r15424
212212   else
213213      state = CLEAR_LINE;
214214
215   // TODO: use READY
216   cputag_set_input_line(machine(), "maincpu", INPUT_LINE_HALT, state);
215   m_slot->set_ready((state==CLEAR_LINE)? ASSERT_LINE : CLEAR_LINE);
216//  cputag_set_input_line(machine(), "maincpu", INPUT_LINE_HALT, state);
217217}
218218
219219/*
src/mess/machine/ti99/p_code.c
r15423r15424
206206
207207static GROM_CONFIG(pgrom0_config)
208208{
209   false, 0, PCODE_GROM_TAG, 0x0000, 0x1800, false, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti_pcode_card_device, ready_line)
209   false, 0, PCODE_GROM_TAG, 0x0000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti_pcode_card_device, ready_line), GROMFREQ
210210};
211211static GROM_CONFIG(pgrom1_config)
212212{
213   false, 1, PCODE_GROM_TAG, 0x2000, 0x1800, false, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti_pcode_card_device, ready_line)
213   false, 1, PCODE_GROM_TAG, 0x2000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti_pcode_card_device, ready_line), GROMFREQ
214214};
215215static GROM_CONFIG(pgrom2_config)
216216{
217   false, 2, PCODE_GROM_TAG, 0x4000, 0x1800, false, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti_pcode_card_device, ready_line)
217   false, 2, PCODE_GROM_TAG, 0x4000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti_pcode_card_device, ready_line), GROMFREQ
218218};
219219static GROM_CONFIG(pgrom3_config)
220220{
221   false, 3, PCODE_GROM_TAG, 0x6000, 0x1800, false, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti_pcode_card_device, ready_line)
221   false, 3, PCODE_GROM_TAG, 0x6000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti_pcode_card_device, ready_line), GROMFREQ
222222};
223223static GROM_CONFIG(pgrom4_config)
224224{
225   false, 4, PCODE_GROM_TAG, 0x8000, 0x1800, false, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti_pcode_card_device, ready_line)
225   false, 4, PCODE_GROM_TAG, 0x8000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti_pcode_card_device, ready_line), GROMFREQ
226226};
227227static GROM_CONFIG(pgrom5_config)
228228{
229   false, 5, PCODE_GROM_TAG, 0xa000, 0x1800, false, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti_pcode_card_device, ready_line)
229   false, 5, PCODE_GROM_TAG, 0xa000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti_pcode_card_device, ready_line), GROMFREQ
230230};
231231static GROM_CONFIG(pgrom6_config)
232232{
233   false, 6, PCODE_GROM_TAG, 0xc000, 0x1800, false, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti_pcode_card_device, ready_line)
233   false, 6, PCODE_GROM_TAG, 0xc000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti_pcode_card_device, ready_line), GROMFREQ
234234};
235235static GROM_CONFIG(pgrom7_config)
236236{
237   false, 7, PCODE_GROM_TAG, 0xe000, 0x1800, false, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti_pcode_card_device, ready_line)
237   false, 7, PCODE_GROM_TAG, 0xe000, 0x1800, DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, ti_pcode_card_device, ready_line), GROMFREQ
238238};
239239
240240void ti_pcode_card_device::device_start()
src/mess/machine/ti99/videowrp.c
r15423r15424
3131}
3232
3333ti_std_video_device::ti_std_video_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
34   : ti_video_device(mconfig, TI994AVIDEO, "Video subsystem", tag, owner, clock)
34   : ti_video_device(mconfig, TI99VIDEO, "Video subsystem", tag, owner, clock)
3535{
3636}
3737
38ti_std8_video_device::ti_std8_video_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
39   : ti_video_device(mconfig, TI998VIDEO, "Video subsystem", tag, owner, clock)
40{
41}
42
4338ti_exp_video_device::ti_exp_video_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
4439   : ti_video_device(mconfig, V9938VIDEO, "Video subsystem", tag, owner, clock)
4540{
r15423r15424
4742
4843/*****************************************************************************/
4944/*
50    Illegal accesses; just take a wait state. Used by TI-99/4A standard or with EVPC
45    Memory access (TI-99/4A and TI-99/8)
5146*/
52
53READ16_MEMBER( ti_video_device::noread )
47READ8Z_MEMBER( ti_std_video_device::readz )
5448{
55   device_adjust_icount(m_cpu, -4);
56   return 0;
57}
58
59WRITE16_MEMBER( ti_video_device::nowrite )
60{
61   device_adjust_icount(m_cpu, -4);
62}
63
64/*****************************************************************************/
65
66// TODO: device_adjust_icount(video->cpu, -4);
67
68/*
69    Memory access (TI-99/4(A))
70*/
71READ16_MEMBER( ti_std_video_device::read16 )
72{
73   if (offset & 1)
74   {   /* read VDP status */
75      return ((int) m_tms9928a->register_read(*(this->m_space), 0)) << 8;
76   }
77   else
78   {   /* read VDP RAM */
79      return ((int) m_tms9928a->vram_read(*(this->m_space), 0)) << 8;
80   }
81}
82
83WRITE16_MEMBER( ti_std_video_device::write16 )
84{
85   if (offset & 1)
86   {   /* write VDP address */
87      m_tms9928a->register_write(*(this->m_space), 0, (data >> 8) & 0xff);
88   }
89   else
90   {   /* write VDP data */
91      m_tms9928a->vram_write(*(this->m_space), 0, (data >> 8) & 0xff);
92   }
93}
94
95/******************************************************************************/
96
97/*
98    Memory access (TI-99/8)
99    Makes use of the Z memory handler.
100*/
101READ8Z_MEMBER( ti_std8_video_device::readz )
102{
10349   if (offset & 2)
10450   {       /* read VDP status */
10551      *value = m_tms9928a->register_read(*(this->m_space), 0);
r15423r15424
11056   }
11157}
11258
113WRITE8_MEMBER( ti_std8_video_device::write )
59WRITE8_MEMBER( ti_std_video_device::write )
11460{
11561   if (offset & 2)
11662   {   /* write VDP address */
r15423r15424
217163
218164void ti_video_device::device_start(void)
219165{
220   m_cpu = machine().device("maincpu");
221   m_space = m_cpu->memory().space(AS_PROGRAM);
222166   m_tms9928a = static_cast<tms9928a_device*>(machine().device(TMS9928A_TAG));
223167}
224168
225169void ti_exp_video_device::device_start(void)
226170{
227   m_cpu = machine().device("maincpu");
228   m_space = m_cpu->memory().space(AS_PROGRAM);
229171   m_v9938 = static_cast<v9938_device*>(machine().device(V9938_TAG));
230172}
231173
r15423r15424
235177
236178/**************************************************************************/
237179
180// TODO: Should propagate READY to the system. However, READY is implemented
181// to be read instead of pushing the level.
182
238183ti_sound_system_device::ti_sound_system_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
239184: bus8z_device(mconfig, TISOUND, "TI sound chip wrapper", tag, owner, clock)
240185{
r15423r15424
252197
253198/**************************************************************************/
254199
255const device_type TI994AVIDEO = &device_creator<ti_std_video_device>;
256const device_type TI998VIDEO = &device_creator<ti_std8_video_device>;
200const device_type TI99VIDEO = &device_creator<ti_std_video_device>;
257201const device_type V9938VIDEO = &device_creator<ti_exp_video_device>;
258202const device_type TISOUND = &device_creator<ti_sound_system_device>;
src/mess/machine/ti99/speech8.c
r15423r15424
168168
169169WRITE_LINE_MEMBER( ti998_spsyn_device::speech8_ready )
170170{
171   //ti99_speech8_state *spsys = get_safe_token(device->owner());
172   if (VERBOSE>4) LOG("speech8: READY called by VSP; no forwarding implemented yet\n");
171   // TODO: Fix polarity in TMS5220
172   m_ready((state==0)? ASSERT_LINE : CLEAR_LINE);
173173}
174174
175175void ti998_spsyn_device::device_start()
176176{
177}
178
179void ti998_spsyn_device::device_config_complete()
180{
177   const speech8_config *conf = reinterpret_cast<const speech8_config *>(static_config());
178   m_ready.resolve(conf->ready, *this);
181179   m_vsp = subdevice(SPEECHSYN_TAG);
182180}
183181
src/mess/machine/ti99/datamux.c
r15423r15424
44
55    The DMUX is used to convert the 16-bit databus of the TMS9900 into
66    an 8-bit databus. The processor writes a 16 bit word which is split
7    by this circuit into two bytes that are sent serially over the 8-bit bus.
7    by this circuit into two bytes that are sent subsequently over the 8-bit bus.
88    In the opposite direction, one 16-bit read request from the CPU is
99    translated into two 8-bit read requests (odd address / even address) from
10    this datamux. Its 8-bit latch (LS373) holds the first byte, while the
11    datamux puts the CPU on hold, gets the second byte, and routes that second
12    byte to the D0-D7 lines, while the latch now puts the first byte on D8-D15.
13    Since we get two memory accesses each time, there are twice as many
14    wait states than for a direct 16-bit access (order LSB, MSB).
10    this datamux. Its 8-bit latch (LS373) holds the first (odd address) byte,
11    while the datamux puts the CPU on hold, gets the second byte,
12    and routes that second byte to the D0-D7 lines, while the latch now puts
13    the first byte on D8-D15. Since we get two memory accesses each time,
14    there are twice as many wait states than for a direct 16-bit access
15    (order LSB, MSB).
1516
16    In addition, since the TMS 9900 also supports byte operations, every write
17    operation is automatically preceded by a read operation, so this adds even
17    In addition, since the TMS 9900 also supports byte operations, all write
18    operations are automatically preceded by a read operation, so this adds even
1819    more delays.
1920
2021    Within the TI-99/4(A) console, only the internal ROM and the small internal
r15423r15424
7677{
7778}
7879
80#define VERBOSE 0
7981#define LOG logerror
8082
8183/***************************************************************************
r15423r15424
8789    accesses must not occur within the loop. So we have one access on the bus,
8890    a delay, and then the second access (each one with possibly many attached
8991    devices)
92
93    TODO: Check two-pass operation
9094*/
9195READ16_MEMBER( ti99_datamux_device::read )
9296{
9397   UINT8 hbyte = 0;
9498   UINT16 addr = (offset << 1);
9599
100   assert (mem_mask == 0xffff);
101
96102   // Looks ugly, but this is close to the real thing. If the 16bit
97103   // memory expansion is installed in the console, and the access hits its
98104   // space, just respond to the memory access and don't bother the
r15423r15424
107113      if (base != 0)
108114      {
109115         UINT16 reply = m_ram16b[offset-base];
110         // Store the prefetch
111         m_lowbyte = reply & 0x00ff;
112         m_highbyte = (reply & 0xff00)>>8;
113116         return reply;
114117      }
115118   }
r15423r15424
124127         // Cast to the bus8z_device (see ti99defs.h)
125128         bus8z_device *devz = static_cast<bus8z_device *>(dev->m_device);
126129         devz->readz(*m_space, addr+1, &m_latch);
127         m_lowbyte = m_latch;
128130      }
129131      // hope we don't have two devices answering...
130132      // consider something like a logical OR and maybe some artificial smoke
131133      dev = dev->m_next;
132134   }
133135
134   // Takes three cycles
135   device_adjust_icount(m_cpu,-3);
136136   dev = m_devices.first();
137137
138138   // Reading the even address now (addr)
r15423r15424
144144         {
145145            bus8z_device *devz = static_cast<bus8z_device *>(dev->m_device);
146146            devz->readz(*m_space, addr, &hbyte);
147            m_highbyte = hbyte;
148147         }
149148      }
150149      dev = dev->m_next;
151150   }
152151
153   // Takes three cycles
154   device_adjust_icount(m_cpu,-3);
152   // Insert four wait states and let CPU enter wait state
153   // The counter in the real console is implemented by a shift register
154   // that is triggered on a memory access
155   m_waitcount = 6;
156   m_ready(CLEAR_LINE);
155157
156158   // use the latch and the currently read byte and put it on the 16bit bus
157159   return (hbyte<<8) | m_latch ;
r15423r15424
164166{
165167   UINT16 addr = (offset << 1);
166168
167   // The handling of byte writing is done in MESS using mem_mask.
168   // If the mem_mask is ff00, the CPU is about to write the high byte. This
169   // is not the true story, since the real CPU never writes half a word.
170   // In reality, the TMS9900 performs a read-before-write, stores the word
171   // internally, and replaces the high or low byte when it is about to write
172   // a byte to an even or odd address, respectively. Then it writes the
173   // complete new word.
174   // Example: Memory locations 0x6000 contains the word 0x1234 (BE). If we
175   // write a 0x56 to 0x6000, the CPU first reads 0x6000, stores the 0x1234,
176   // replaces the first byte with 0x56, and then writes 0x5634 to 0x6000.
169   // Although MESS allows for using mem_mask to address parts of the
170   // data bus, this is not used in the TMS implementation. In fact, all
171   // accesses are true 16-bit accesses. We check for mem_mask always
172   // being ffff.
177173
178   // Until the TMS9900 emulation is corrected in this way, we are using
179   // the DMUX in place of the internal buffer.
174//  printf("write addr=%04x, value=%04x\n", addr, data);
180175
181//  LOG("write addr=%04x memmask=%04x value=%04x\n", addr, mem_mask, data);
182   if (mem_mask == 0xff00)
183      data = data | m_lowbyte;
176   assert (mem_mask == 0xffff);
184177
185   if (mem_mask == 0x00ff)
186      data = data | (m_highbyte << 8);
187
188178   // Handle the internal 32K expansion
189179   if (m_use32k)
190180   {
r15423r15424
211201      dev = dev->m_next;
212202   }
213203
214   // Takes three cycles
215   device_adjust_icount(m_cpu,-3);
216204   dev = m_devices.first();
217205
218206   while (dev != NULL)
r15423r15424
226214      dev = dev->m_next;
227215   }
228216
229   // Takes three cycles
230   device_adjust_icount(m_cpu,-3);
217   // Insert four wait states and let CPU enter wait state
218   m_waitcount = 6;
219   m_ready(CLEAR_LINE);
231220}
232221
233/* CRU space is not involved in the dmux. */
222/*
223    The datamux is connected to the clock line in order to operate
224    the wait state counter.
225*/
226void ti99_datamux_device::clock_in(int clock)
227{
228   if (clock==ASSERT_LINE && m_waitcount!=0)
229   {
230      m_waitcount--;
231      if (m_waitcount==0) m_ready(ASSERT_LINE);
232   }
233}
234234
235235/***************************************************************************
236236    DEVICE LIFECYCLE FUNCTIONS
r15423r15424
248248
249249void ti99_datamux_device::device_reset(void)
250250{
251   const dmux_device_list_entry *list = reinterpret_cast<const dmux_device_list_entry *>(static_config());
251   const datamux_config *conf = reinterpret_cast<const datamux_config *>(static_config());
252252
253   const dmux_device_list_entry *list = conf->devlist;
254   m_ready.resolve(conf->ready, *this);
255
253256   m_cpu = machine().device("maincpu");
254257   m_space = m_cpu->memory().space(AS_PROGRAM);
255258
r15423r15424
288291               {
289292                  attached_device *ad = new attached_device(dev, list[i]);
290293                  m_devices.append(*ad);
291                  LOG("ti99_datamux: Device %s mounted at index %d.\n", list[i].name, i);
294                  if (VERBOSE>8) LOG("datamux: Device %s mounted at index %d.\n", list[i].name, i);
292295               }
293296               else
294297               {
295                  LOG("ti99_datamux: Device %s not found.\n", list[i].name);
298                  if (VERBOSE>8) LOG("datamux: Device %s not found.\n", list[i].name);
296299               }
297300            }
298301            else
299302            {
300               LOG("ti99_datamux: Device %s not mounted due to configuration setting %s.\n", list[i].name, list[i].setting);
303               if (VERBOSE>8) LOG("datamux: Device %s not mounted due to configuration setting %s.\n", list[i].name, list[i].setting);
301304            }
302305         }
303306      }
304307   }
305   LOG("Datamux device count = %d\n", m_devices.count());
308   if (VERBOSE>8) LOG("datamux: Device count = %d\n", m_devices.count());
309   m_ready(ASSERT_LINE);
306310}
307311
308312INPUT_PORTS_START( datamux )
src/mess/machine/ti99/videowrp.h
r15423r15424
1818
1919class ti_video_device : public bus8z_device
2020{
21public:
22   DECLARE_READ16_MEMBER(noread);
23   DECLARE_WRITE16_MEMBER(nowrite);
24
2521protected:
2622   address_space   *m_space;
27   device_t      *m_cpu;
2823   tms9928a_device *m_tms9928a;
2924
3025   /* Constructor */
r15423r15424
3631};
3732
3833/*
39    Connected to the high 8 bits of the 16 bit data bus of the TI-99/4A, D0-D7
34    Used in the TI-99/4A and TI-99/8
4035*/
4136class ti_std_video_device : public ti_video_device
4237{
4338public:
4439   ti_std_video_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
45   DECLARE_READ16_MEMBER(read16);
46   DECLARE_WRITE16_MEMBER(write16);
47};
48
49/*
50    Connected to the multiplexed 8 bit data bus of the TI-99/8
51*/
52class ti_std8_video_device : public ti_video_device
53{
54public:
55   ti_std8_video_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
5640   DECLARE_READ8Z_MEMBER(readz);
5741   DECLARE_WRITE8_MEMBER(write);
5842};
r15423r15424
9882/****************************************************************************/
9983
10084#define MCFG_TI_TMS991x_ADD_NTSC(_tag, _chip, _tmsparam)   \
101   MCFG_DEVICE_ADD(_tag, TI994AVIDEO, 0)                              \
85   MCFG_DEVICE_ADD(_tag, TI99VIDEO, 0)                              \
10286   MCFG_TMS9928A_ADD( TMS9928A_TAG, _chip, _tmsparam )                \
10387   MCFG_TMS9928A_SCREEN_ADD_NTSC( SCREEN_TAG )                      \
10488   MCFG_SCREEN_UPDATE_DEVICE( TMS9928A_TAG, tms9928a_device, screen_update )
10589
10690#define MCFG_TI_TMS991x_ADD_PAL(_tag, _chip, _tmsparam)      \
107   MCFG_DEVICE_ADD(_tag, TI994AVIDEO, 0)                              \
91   MCFG_DEVICE_ADD(_tag, TI99VIDEO, 0)                              \
10892   MCFG_TMS9928A_ADD( TMS9928A_TAG, _chip, _tmsparam )                  \
10993   MCFG_TMS9928A_SCREEN_ADD_PAL( SCREEN_TAG )                        \
11094   MCFG_SCREEN_UPDATE_DEVICE( TMS9928A_TAG, tms9928a_device, screen_update )
11195
11296#define MCFG_TI998_ADD_NTSC(_tag, _chip, _tmsparam)   \
113   MCFG_DEVICE_ADD(_tag, TI998VIDEO, 0)                              \
97   MCFG_DEVICE_ADD(_tag, TI99VIDEO, 0)                              \
11498   MCFG_TMS9928A_ADD( TMS9928A_TAG, _chip, _tmsparam )                \
11599   MCFG_TMS9928A_SCREEN_ADD_NTSC( SCREEN_TAG )                      \
116100   MCFG_SCREEN_UPDATE_DEVICE( TMS9928A_TAG, tms9928a_device, screen_update )
117101
118102#define MCFG_TI998_ADD_PAL(_tag, _chip, _tmsparam)      \
119   MCFG_DEVICE_ADD(_tag, TI998VIDEO, 0)                              \
103   MCFG_DEVICE_ADD(_tag, TI99VIDEO, 0)                              \
120104   MCFG_TMS9928A_ADD( TMS9928A_TAG, _chip, _tmsparam )                  \
121105   MCFG_TMS9928A_SCREEN_ADD_PAL( SCREEN_TAG )                        \
122106   MCFG_SCREEN_UPDATE_DEVICE( TMS9928A_TAG, tms9928a_device, screen_update )
r15423r15424
137121#define MCFG_TI_SOUND_ADD(_tag)         \
138122   MCFG_DEVICE_ADD(_tag, TISOUND, 0)
139123
140extern const device_type TI994AVIDEO;
141extern const device_type TI998VIDEO;
124extern const device_type TI99VIDEO;
142125extern const device_type V9938VIDEO;
143126extern const device_type TISOUND;
144127
src/mess/machine/ti99/speech8.h
r15423r15424
1818
1919extern const device_type TI99_SPEECH8;
2020
21#define SPEECH8_CONFIG(name) \
22   const speech8_config(name) =
23
24typedef struct _speech8_config
25{
26   devcb_write_line ready;
27} speech8_config;
28
29
2130class ti998_spsyn_device : public bus8z_device
2231{
2332public:
r15423r15424
4453   void         device_reset(void);
4554   const rom_entry *device_rom_region() const;
4655   machine_config_constructor device_mconfig_additions() const;
47   void         device_config_complete();
4856
4957private:
5058   device_t      *m_vsp;
59
60   // Ready line to the CPU
61   devcb_resolved_write_line m_ready;
5162};
5263
53#define MCFG_TISPEECH8_ADD(_tag)      \
54   MCFG_DEVICE_ADD(_tag, TI99_SPEECH8, 0)
64#define MCFG_TISPEECH8_ADD(_tag, _conf)      \
65   MCFG_DEVICE_ADD(_tag, TI99_SPEECH8, 0)  \
66   MCFG_DEVICE_CONFIG(_conf)
67
5568#endif
src/mess/machine/ti99/ti99defs.h
r15423r15424
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"
2021#define TMS9928A_TAG   "tms9928a"
2122#define V9938_TAG      "v9938"
2223#define SCREEN_TAG      "screen"
r15423r15424
3031#define MECMOUSE_TAG   "mecmouse"
3132#define HANDSET_TAG      "handset"
3233
34#define GROMFREQ 10700000.0/24
35
3336// TI-99/8
3437#define SRAM_TAG      "sram8"
3538#define DRAM_TAG      "dram8"
src/mess/machine/ti99/peribox.c
r15423r15424
324324   m_console_intb((m_intb_flag != 0)? ASSERT_LINE : CLEAR_LINE);
325325}
326326
327/*
328    When any device pulls down READY, READY goes down.
329*/
327330void peribox_device::ready_join(int slot, int state)
328331{
329   if (VERBOSE>7) LOG("Peribox propagating READY from slot %d to console: %d\n", slot, state);
330   if (state==ASSERT_LINE)
332   if (VERBOSE>7) LOG("peribox: Incoming READY=%d from slot %d\n", state, slot);
333   // We store the inverse state
334   if (state==CLEAR_LINE)
331335      m_ready_flag |= (1 << slot);
332336   else
333337      m_ready_flag &= ~(1 << slot);
334338
335   m_console_ready((m_ready_flag != 0)? ASSERT_LINE : CLEAR_LINE);
339   m_console_ready((m_ready_flag != 0)? CLEAR_LINE : ASSERT_LINE);
336340}
337341
338342void peribox_device::set_slot_loaded(int slot, peribox_slot_device* slotdev)
src/mess/machine/ti99/datamux.h
r15423r15424
3434   UINT8               unset;            // bits that must be reset for this switch so that this device is present
3535} dmux_device_list_entry;
3636
37#define DMUX_CONFIG(name) \
38   const datamux_config(name) =
39
40typedef struct _datamux_config
41{
42   devcb_write_line            ready;
43   const dmux_device_list_entry   *devlist;
44} datamux_config;
45
3746/*
3847    Device list of this datamux.
3948*/
r15423r15424
6271   DECLARE_READ16_MEMBER( read );
6372   DECLARE_WRITE16_MEMBER( write );
6473
74   void clock_in(int state);
75
6576protected:
6677   /* Constructor */
6778   virtual void device_start(void);
r15423r15424
7081   ioport_constructor device_input_ports() const;
7182
7283private:
84   // Ready line to the CPU
85   devcb_resolved_write_line m_ready;
86
7387   /* All devices that are attached to the 8-bit bus. */
7488   simple_list<attached_device> m_devices;
7589
76   /* Latch which stores the first byte */
90   /* Latch which stores the first (odd) byte */
7791   UINT8 m_latch;
7892
79   // Intermediate storage which holds the low byte of the previous read cycle.
80   // In reality, the TMS9900 adds the low byte to the 16 bit memory word
81   // from the previous read-before-write cycle, but this is not yet handled
82   // by the TMS9900 emulation. TODO: rewrite TMS9900
83   UINT8 m_lowbyte;
84   UINT8 m_highbyte;
93   /* Counter for the wait states. */
94   int   m_waitcount;
8595
8696   /* Memory expansion (internal, 16 bit). */
8797   UINT16 *m_ram16b;
src/mess/machine/ti99/mapper8.c
r15423r15424
4242
4343#include "mapper8.h"
4444
45#define VERBOSE 1
45#define VERBOSE
4646#define LOG logerror
4747
4848// Pseudo devices which are not implemented by a proper device. We use these
r15423r15424
121121{
122122   UINT8 value = 0;
123123   bool found = false;
124
124   if (VERBOSE>5) LOG("mapper8: read from %04x\n", offset);
125125   found = search_logically_addressed_r(space, offset, &value, mem_mask);
126   m_waitcount = 2;
126127
127128   if (!found)
128129   {
r15423r15424
133134
134135      // So now let's do the same as above with physical addresses
135136      search_physically_addressed_r(space, pas_address, &value, mem_mask);
137
138      // The PAS area requires one more wait state, as the address bus
139      // is multiplexed
140      m_waitcount = 3;
136141   }
142
143   // Insert wait states and let CPU enter wait state
144   m_ready(CLEAR_LINE);
145
137146   return value;
138147}
139148
r15423r15424
143152
144153   // Look for components responding to the logical address
145154   found = search_logically_addressed_w(space, offset, data, mem_mask);
155   m_waitcount = 2;
146156
147157   if (!found)
148158   {
r15423r15424
153163
154164      // So now let's do the same as above with physical addresses
155165      search_physically_addressed_w(space, pas_address, data, mem_mask);
166
167      // The PAS area requires one more wait state, as the address bus
168      // is multiplexed
169      m_waitcount = 3;
156170   }
171
172   // Insert wait states and let CPU enter wait state
173   m_ready(CLEAR_LINE);
157174}
158175
159176/***************************************************************************
r15423r15424
256273   if (VERBOSE>8) LOG("mapper8: offset=%04x; CRUS=%d, PTGEN=%d\n", offset, m_CRUS? 1:0, m_PTGE? 0:1);
257274   while (dev != NULL)
258275   {
276      if (VERBOSE>5) LOG("mapper8: checking node=%s\n", dev->m_config->name);
259277      // Check the mode
260278      if (((dev->m_config->mode == NATIVE) && (m_CRUS==false))
261279         || ((dev->m_config->mode == TI99EM) && (m_CRUS==true))
r15423r15424
430448   }
431449}
432450
451/*
452    The mapper is connected to the clock line in order to operate
453    the wait state counter.
454*/
455void ti998_mapper_device::clock_in(int clock)
456{
457   if (clock==ASSERT_LINE && m_waitcount!=0)
458   {
459      m_waitcount--;
460      if (m_waitcount==0) m_ready(ASSERT_LINE);
461   }
462}
463
464
433465/***************************************************************************
434466    DEVICE LIFECYCLE FUNCTIONS
435467***************************************************************************/
r15423r15424
446478{
447479   if (VERBOSE>5) LOG("ti99_8: Starting mapper\n");
448480
449   const mapper8_list_entry *entry = reinterpret_cast<const mapper8_list_entry *>(static_config());
481   const mapper8_config *conf = reinterpret_cast<const mapper8_config *>(static_config());
482
483   const mapper8_list_entry *entry = conf->devlist;
484   m_ready.resolve(conf->ready, *this);
485
450486   m_sram = machine().root_device().memregion(SRAM_TAG)->base();
451487   m_dram = machine().root_device().memregion(DRAM_TAG)->base();
452488   m_rom  = machine().root_device().memregion("maincpu")->base();
r15423r15424
527563
528564   // Clean mapper
529565   for (int i=0; i < 16; i++) m_pas_offset[i] = 0;
566
567   m_ready(ASSERT_LINE);
530568}
531569
532570const device_type MAPPER8 = &device_creator<ti998_mapper_device>;
src/mess/machine/ti99/bwg.c
r15423r15424
7878   else
7979      state = CLEAR_LINE;
8080
81   // TODO: use READY
82   cputag_set_input_line(machine(), "maincpu", INPUT_LINE_HALT, state);
81   m_slot->set_ready((state==CLEAR_LINE)? ASSERT_LINE : CLEAR_LINE);
82//  cputag_set_input_line(machine(), "maincpu", INPUT_LINE_HALT, state);
8383}
8484
8585/*
src/mess/machine/ti99/mapper8.h
r15423r15424
4646   UINT32      write_select;      // Additional bits set when doing write accesses to this device
4747} mapper8_list_entry;
4848
49#define MAPPER8_CONFIG(name) \
50   const mapper8_config(name) =
51
52typedef struct _mapper8_config
53{
54   devcb_write_line            ready;
55   const mapper8_list_entry      *devlist;
56} mapper8_config;
57
4958/*
5059    Device list of the mapper.
5160*/
r15423r15424
101110   void CRUS_set(bool state);
102111   void PTGE_set(bool state);
103112
113   void clock_in(int state);
114
104115protected:
105116   void device_start(void);
106117   void device_reset(void);
r15423r15424
112123   void search_physically_addressed_w(address_space& space, offs_t offset, UINT8 data, UINT8 mem_mask );
113124   void mapwrite(int offset, UINT8 data);
114125
126   // Ready line to the CPU
127   devcb_resolved_write_line m_ready;
128
115129   // All devices that are attached to the 16-bit address bus.
116130   simple_list<log_addressed_device> m_logcomp;
117131
r15423r15424
130144   // We use PTGE as the inverse signal.
131145   bool   m_PTGE;
132146
147   // Counter for the wait states.
148   int   m_waitcount;
149
133150   // Address mapper registers. Each offset is selected by the first 4 bits
134151   // of the logical address.
135152   UINT32   m_pas_offset[16];
src/mess/machine/ti99/spchsyn.c
r15423r15424
175175
176176WRITE_LINE_MEMBER( ti_speech_synthesizer_device::speech_ready )
177177{
178   m_slot->set_ready(state);
178   // TODO: Fix this in TMS5220
179   m_slot->set_ready((state==0)? ASSERT_LINE : CLEAR_LINE);
179180}
180181
181182void ti_speech_synthesizer_device::device_start()
src/mess/drivers/ti99_8.c
r15423r15424
167167  a problem of the prototypical XB II which we cannot solve. It seems as if only
168168  hexbus devices are properly supported, but we currently do not have an
169169  emulation for those. Thus you can currently only use cassette to load and
170  save programs. You MUST turn off the floppy controller support in the
171  configuration before you enter XB II. Other cartridges (like Editor/Assembler)
170  save programs. You MUST not plug in any floppy controller when you intend to
171  start XB II. Other cartridges (like Editor/Assembler)
172172  seem to be not affected by this problem and can make use of the floppy
173173  controllers.
174174    Technical detail: The designers of XB II seem to have decided to put PABs
r15423r15424
185185  cartridge is presented. You have to manually select the cartridges with the
186186  dip switch.
187187
188- Emulation speed may still be incorrect.
189
190188- SAVE and OLD MINIMEM do not work properly in XB II. It seems as if the
191189  mapper shadows the NVRAM of the cartridge. You will lose the contents when
192190  you turn off the machine.
193191
194192    Raphael Nabet, 2003.
195    Michael Zapf
196193
197194    February 2012: Rewritten as class
195    Michael Zapf
198196
199197*****************************************************************************/
200198
201199
202200#include "emu.h"
203#include "cpu/tms9900/tms9900.h"
201#include "cpu/tms9900/tms9995.h"
202
204203#include "sound/sn76496.h"
205204#include "sound/wave.h"
206205#include "machine/tms9901.h"
r15423r15424
215214#include "machine/ti99/gromport.h"
216215#include "machine/ti99/mecmouse.h"
217216
218#define VERBOSE 1
217#define VERBOSE
219218#define LOG logerror
220219
221220class ti99_8 : public driver_device
r15423r15424
228227   DECLARE_READ8_MEMBER(cruread);
229228   DECLARE_WRITE8_MEMBER(cruwrite);
230229
230   DECLARE_WRITE8_MEMBER(external_operation);
231
231232   // Forwarding interrupts to the CPU or CRU
232233   DECLARE_WRITE_LINE_MEMBER( console_ready );
234   DECLARE_WRITE_LINE_MEMBER( console_ready_mapper );
235
233236   DECLARE_WRITE_LINE_MEMBER( set_tms9901_INT2 );
234237   DECLARE_WRITE_LINE_MEMBER( extint );
235238   DECLARE_WRITE_LINE_MEMBER( notconnected );
r15423r15424
247250   DECLARE_WRITE_LINE_MEMBER(cassette_motor);
248251   DECLARE_WRITE8_MEMBER(tms9901_interrupt);
249252
253   DECLARE_WRITE_LINE_MEMBER( clock_out );
254
250255   // Some values to keep
251   device_t         *m_cpu;
256   tms9995_device      *m_cpu;
252257   tms9901_device      *m_tms9901;
253258   gromport_device      *m_gromport;
254259   peribox_device      *m_peribox;
255260   mecmouse_device    *m_mecmouse;
256261   ti998_mapper_device   *m_mapper;
257262
263   int      m_ready_line, m_ready_line1;
264
258265private:
259266   /* Keyboard support */
260267   void         set_key(int number, int data);
r15423r15424
276283    The TMS9901 is fully decoded according to the specification, so we only
277284    have 32 bits for it; the rest goes to the CRU bus
278285    (decoded by the "Vaquerro" chip, signal NNOICS*)
279    TODO: Check whether the CRU address space goes up to 7fff (15 bit)
280286*/
281287
282288static ADDRESS_MAP_START(crumap, AS_IO, 8, ti99_8)
r15423r15424
423429
424430static GROM_CONFIG(grom0_config)
425431{
426   false, 0, region_grom, 0x0000, 0x1800, false, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready)
432   false, 0, region_grom, 0x0000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ
427433};
428434
429435static GROM_CONFIG(grom1_config)
430436{
431   false, 1, region_grom, 0x2000, 0x1800, false, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready)
437   false, 1, region_grom, 0x2000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ
432438};
433439
434440static GROM_CONFIG(grom2_config)
435441{
436   false, 2, region_grom, 0x4000, 0x1800, false, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready)
442   false, 2, region_grom, 0x4000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ
437443};
438444
445/****************************************************
446    PASCAL groms, 3 libraries @ 8 GROMs
447    Do some macro tricks to keep writing effort low
448*****************************************************/
449
450#define pascal0_region "pascal0_region"
451#define pascal12_region "pascal12_region"
452
453#define MCFG_GROM_LIBRARY_ADD(_tag, _config)   \
454   MCFG_DEVICE_ADD(#_tag "0", GROM, 0)   \
455   MCFG_DEVICE_CONFIG(_config##0) \
456   MCFG_DEVICE_ADD(#_tag "1", GROM, 0)   \
457   MCFG_DEVICE_CONFIG(_config##1) \
458   MCFG_DEVICE_ADD(#_tag "2", GROM, 0)   \
459   MCFG_DEVICE_CONFIG(_config##2) \
460   MCFG_DEVICE_ADD(#_tag "3", GROM, 0)   \
461   MCFG_DEVICE_CONFIG(_config##3) \
462   MCFG_DEVICE_ADD(#_tag "4", GROM, 0)   \
463   MCFG_DEVICE_CONFIG(_config##4) \
464   MCFG_DEVICE_ADD(#_tag "5", GROM, 0)   \
465   MCFG_DEVICE_CONFIG(_config##5) \
466   MCFG_DEVICE_ADD(#_tag "6", GROM, 0)   \
467   MCFG_DEVICE_CONFIG(_config##6) \
468   MCFG_DEVICE_ADD(#_tag "7", GROM, 0)   \
469   MCFG_DEVICE_CONFIG(_config##7)
470
471#define GROM_LIBRARY_CONFIG(_conf, _region) \
472static GROM_CONFIG(_conf##0) \
473{   false, 0, _region, 0x0000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ }; \
474static GROM_CONFIG(_conf##1) \
475{   false, 1, _region, 0x2000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ }; \
476static GROM_CONFIG(_conf##2) \
477{   false, 2, _region, 0x4000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ }; \
478static GROM_CONFIG(_conf##3) \
479{   false, 3, _region, 0x6000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ }; \
480static GROM_CONFIG(_conf##4) \
481{   false, 4, _region, 0x8000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ }; \
482static GROM_CONFIG(_conf##5) \
483{   false, 5, _region, 0xa000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ }; \
484static GROM_CONFIG(_conf##6) \
485{   false, 6, _region, 0xc000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ }; \
486static GROM_CONFIG(_conf##7) \
487{   false, 7, _region, 0xe000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ };
488
489GROM_LIBRARY_CONFIG(pascal0, pascal0_region)
490GROM_LIBRARY_CONFIG(pascal1, pascal12_region)
491GROM_LIBRARY_CONFIG(pascal2, pascal12_region)
492
439493static GROMPORT_CONFIG(console_cartslot)
440494{
441495   DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready)
r15423r15424
623677
624678WRITE8_MEMBER( ti99_8::tms9901_interrupt )
625679{
626   // offset contains the interrupt level (0-15)
627   if (data==ASSERT_LINE)
628   {
629      // The TMS9901 should normally be connected with the CPU by 5 wires:
630      // INTREQ* and IC0-IC3. The last four lines deliver the interrupt level.
631      // On the TI-99 systems these IC lines are not used; the input lines
632      // at the CPU are hardwired to level 1.
633      if (VERBOSE>8) LOG("mapper8: tms9901 asserts interrupt\n");
634      device_execute(m_cpu)->set_input_line_and_vector(0, ASSERT_LINE, 1);
635   }
636   else
637   {
638      if (VERBOSE>8) LOG("mapper8: tms9901 clears interrupt\n");
639      device_execute(m_cpu)->set_input_line(0, CLEAR_LINE);
640   }
680   m_cpu->set_input_line(1, data);
641681}
642682
643683const tms9901_interface tms9901_wiring_ti99_8 =
r15423r15424
688728
689729WRITE_LINE_MEMBER( ti99_8::console_ready )
690730{
691   if (VERBOSE>6) LOG("ti99_8: READY line set ... not yet connected, level=%02x\n", state);
731   if (VERBOSE>6) LOG("ti99_8: READY level=%02x\n", state);
732   m_ready_line = state;
733
734   m_cpu->set_ready((m_ready_line == ASSERT_LINE && m_ready_line1 == ASSERT_LINE)? ASSERT_LINE : CLEAR_LINE);
692735}
693736
737/*
738    Memory access over the mapper also operates
739    the READY line, and the mapper raises READY depending on the clock pulse.
740    So we must make sure this does not interfere.
741*/
742WRITE_LINE_MEMBER( ti99_8::console_ready_mapper )
743{
744   if (VERBOSE>6) LOG("ti99_8: READY level (mapper) = %02x\n", state);
745   m_ready_line1 = state;
746   m_cpu->set_ready((m_ready_line == ASSERT_LINE && m_ready_line1 == ASSERT_LINE)? ASSERT_LINE : CLEAR_LINE);
747}
748
694749WRITE_LINE_MEMBER( ti99_8::extint )
695750{
696751   if (VERBOSE>6) LOG("ti99_8: EXTINT level = %02x\n", state);
r15423r15424
710765   DEVCB_DRIVER_LINE_MEMBER(ti99_8, set_tms9901_INT2)
711766};
712767
768WRITE8_MEMBER( ti99_8::external_operation )
769{
770   static const char* extop[8] = { "inv1", "inv2", "IDLE", "RSET", "inv3", "CKON", "CKOF", "LREX" };
771   if (VERBOSE>1) LOG("External operation %s not implemented on TI-99 board\n", extop[offset]);
772}
773
774/*
775    Clock line from the CPU. Used to control wait state generation.
776*/
777WRITE_LINE_MEMBER( ti99_8::clock_out )
778{
779   m_mapper->clock_in(state);
780}
781
713782/*****************************************************************************/
714783
715static const struct tms9995reset_param ti99_8_processor_config =
784/*
785    MP9537 mask: This variant of the TMS9995 does not contain on-chip RAM
786    Also, the overflow interrupt is disabled; in the available documentation
787    this feature is said to be disabled and is announced for a later version.
788*/
789static TMS9995_CONFIG( ti99_8_processor_config )
716790{
717   1,   /* enable automatic wait state generation */
718      /* (in January 83 99/8 schematics sheet 9: the delay logic */
719      /* seems to keep READY low for one cycle when RESET* is */
720      /* asserted, but the timings are completely wrong this way) */
721   0,   /* no IDLE callback */
722   1   /* MP9537 mask */
791   DEVCB_DRIVER_MEMBER(ti99_8, external_operation),
792   DEVCB_NULL,      // Instruction acquisition
793   DEVCB_DRIVER_LINE_MEMBER(ti99_8, clock_out),
794   DEVCB_NULL,      // wait
795   DEVCB_NULL,      // HOLDA
796   NO_INTERNAL_RAM,
797   NO_OVERFLOW_INT
723798};
724799
725800/*
r15423r15424
741816
742817    Access to the mapper registers is done directly in the mapper, not via
743818    this list.
819
820    NOTE: The available system software contradicts the specification
821    concerning the Pascal ports. While the specs define f840 as "Text-to-speech
822    library" and f850 and f860 as two libraries for Pascal, the operating
823    system defines f840 as Pascal lib 0, f880 as Pascal lib 1, and f8c0 as
824    Pascal lib 2.
825
826    TODO: This should (must) be improved in terms of performance. Every single
827    memory access goes through the mapper. Either we use an ordered search list,
828    or we order the entries according to their frequency.
829    (I did this right now, putting the Pascal GROMs at the end.)
830    We should think about a set entry where devices with the same address
831    are collected as one single entry (think about the Pascal lib with 24 GROMs,
832    every eight of them on the same address).
744833*/
745static const mapper8_list_entry mapper_devices[] =
746{
747   // TI-99/8 mode
748   { SRAMNAME,         NATIVE, STOP, 0xf000, 0xf800, 0x0000   },   // f000-f7ff
749   { TISOUND_TAG,     NATIVE, STOP, 0xf800, 0xfff0, 0x0000   },   // f800-f80f
750   { VIDEO_SYSTEM_TAG,   NATIVE, STOP, 0xf810, 0xfffd, 0x0000   },   // f810,2 (unlike 99/4A, no different read/write ports)
751   { SPEECH_TAG,      NATIVE, STOP, 0xf820, 0xfff0, 0x0000   },   // f820-f82f
752834
753   { GROM0_TAG,       NATIVE, CONT, 0xf830, 0xfff1, 0x0000   },   // f830-f83e (4 banks), no different read/write ports
754   { GROM1_TAG,      NATIVE, CONT, 0xf830, 0xfff1, 0x0000   },
755   { GROM2_TAG,      NATIVE, CONT, 0xf830, 0xfff1, 0x0000   },
756   { GROMPORT_TAG,    NATIVE, CONT, 0xf830, 0xfff1, 0x0000   },
835#define PASCAL_GROM_LIB(_tag, _addr) \
836   { _tag "0",     PATGEN, CONT, _addr, 0xfff1, 0x0000    },   \
837   { _tag "1",     PATGEN, CONT, _addr, 0xfff1, 0x0000    },   \
838   { _tag "2",     PATGEN, CONT, _addr, 0xfff1, 0x0000    },   \
839   { _tag "3",     PATGEN, CONT, _addr, 0xfff1, 0x0000    },   \
840   { _tag "4",     PATGEN, CONT, _addr, 0xfff1, 0x0000    },   \
841   { _tag "5",     PATGEN, CONT, _addr, 0xfff1, 0x0000    },   \
842   { _tag "6",     PATGEN, CONT, _addr, 0xfff1, 0x0000    },   \
843   { _tag "7",     PATGEN, CONT, _addr, 0xfff1, 0x0000    }
757844
758//  { GROMTTS0_TAG,     PATGEN, CONT, 0xf840, 0xfff1, 0x0000    },  // up to 6 GROMs; no good dumps known
759//  { GROMPC10_TAG,     PATGEN, CONT, 0xf850, 0xfff1, 0x0000    },  // up to 6 GROMs; no good dumps known
760//  { GROMPC20_TAG,     PATGEN, CONT, 0xf860, 0xfff1, 0x0000    },  // up to 6 GROMs; no good dumps known
761   { MAPPER_TAG,      NATIVE, STOP, 0xf870, 0xfff0, 0x0000   },
762845
846static const mapper8_list_entry mapper_devices[] =
847{
763848   // TI-99/4A mode (CRUS=1)
764849   // GROMs: According to the spec, the 99/8 supports up to 4 GROM libraries
765850   // (99/4A supports 256 libraries)
766851   // at 9800, 9804, 9808, 980c. Address counter access is at 9802,6,a,e. Write access +0400.
767852   { ROM0NAME,         TI99EM, STOP, 0x0000, 0xe000, 0x0000   },   // 0000-1fff
768853
769   { GROM0_TAG,       TI99EM, CONT, 0x9800, 0xfff1, 0x0400   },   // 9800,2,4,...e/9c00,2,4,...e
770   { GROM1_TAG,       TI99EM, CONT, 0x9800, 0xfff1, 0x0400   },   // dto.
771   { GROM2_TAG,       TI99EM, CONT, 0x9800, 0xfff1, 0x0400   },   // dto. (GROMs are connected in parallel,
772   { GROMPORT_TAG,    TI99EM, CONT, 0x9800, 0xfff1, 0x0400   },   // dto.  use internal address counter and id)
773
774854   { TISOUND_TAG,     TI99EM, STOP, 0x8400, 0xfff0, 0x0000   },   // 8400-840f
775855   { VIDEO_SYSTEM_TAG,   TI99EM, STOP, 0x8800, 0xfffd, 0x0400   },   // 8800,8802 / 8c00,8c02
776856   { SPEECH_TAG,      TI99EM, STOP, 0x9000, 0xfff0, 0x0400   },   // 9000-900f / 9400-940f
777857   { SRAMNAME,         TI99EM, STOP, 0x8000, 0xf800, 0x0000   },   // 8000-87ff; must follow the sound generator
778858   { MAPPER_TAG,      TI99EM, STOP, 0x8810, 0xfff0, 0x0000   },
779859
860   { GROM0_TAG,       TI99EM, CONT, 0x9800, 0xfff1, 0x0400   },   // 9800,2,4,...e/9c00,2,4,...e
861   { GROM1_TAG,       TI99EM, CONT, 0x9800, 0xfff1, 0x0400   },   // dto.
862   { GROM2_TAG,       TI99EM, CONT, 0x9800, 0xfff1, 0x0400   },   // dto. (GROMs are connected in parallel,
863   { GROMPORT_TAG,    TI99EM, CONT, 0x9800, 0xfff1, 0x0400   },   // dto.  use internal address counter and id)
864
865   // TI-99/8 mode
866   { SRAMNAME,         NATIVE, STOP, 0xf000, 0xf800, 0x0000   },   // f000-f7ff
867   { TISOUND_TAG,     NATIVE, STOP, 0xf800, 0xfff0, 0x0000   },   // f800-f80f
868   { VIDEO_SYSTEM_TAG,   NATIVE, STOP, 0xf810, 0xfffd, 0x0000   },   // f810,2 (unlike 99/4A, no different read/write ports)
869   { SPEECH_TAG,      NATIVE, STOP, 0xf820, 0xfff0, 0x0000   },   // f820-f82f
870   { MAPPER_TAG,      NATIVE, STOP, 0xf870, 0xfff0, 0x0000   },
871
872   { GROM0_TAG,       NATIVE, CONT, 0xf830, 0xfff1, 0x0000   },   // f830-f83e (4 banks), no different read/write ports
873   { GROM1_TAG,      NATIVE, CONT, 0xf830, 0xfff1, 0x0000   },
874   { GROM2_TAG,      NATIVE, CONT, 0xf830, 0xfff1, 0x0000   },
875   { GROMPORT_TAG,    NATIVE, CONT, 0xf830, 0xfff1, 0x0000   },
876
877   PASCAL_GROM_LIB("pascal0_grom", 0xf840),
878   PASCAL_GROM_LIB("pascal1_grom", 0xf880),      // lib1 and 2 are zeroed. We don't have good dumps for them yet.
879   PASCAL_GROM_LIB("pascal2_grom", 0xf8c0),      // Anyway, we keep them in order to check whether/when they are accessed.
880
780881   // Physical (need to pack this in here as well to keep config simple)
882   // but these lines will be put into a separate list
781883   { DRAMNAME,       PHYSIC, STOP, 0x000000, 0xff0000, 0x000000   },   // 000000-00ffff 64 KiB DRAM
782884   { MAPPER_TAG,      PHYSIC, CONT, 0xff4000, 0xffe000, 0x000000   },   // ff4000-ff5fff Internal DSR
783885   { GROMPORT_TAG,      PHYSIC, STOP, 0xff6000, 0xffe000, 0x000000   },   // ff6000-ff7fff Cartridge ROM space
r15423r15424
790892   { NULL, 0, 0, 0, 0, 0  }
791893};
792894
895static MAPPER8_CONFIG( mapper_conf )
896{
897   DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready_mapper),   // READY
898   mapper_devices
899};
900
901static SPEECH8_CONFIG( speech_config )
902{
903   DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready),   // READY
904};
905
793906MACHINE_START( ti99_8 )
794907{
795908   ti99_8 *driver = machine.driver_data<ti99_8>();
796   driver->m_cpu = machine.device("maincpu");
909   driver->m_cpu = static_cast<tms9995_device*>(machine.device("maincpu"));
797910   driver->m_tms9901 = static_cast<tms9901_device*>(machine.device(TMS9901_TAG));
798911   driver->m_gromport = static_cast<gromport_device*>(machine.device(GROMPORT_TAG));
799912   driver->m_peribox = static_cast<peribox_device*>(machine.device(PERIBOX_TAG));
r15423r15424
810923      driver->m_mecmouse = static_cast<mecmouse_device*>(machine.device(MECMOUSE_TAG));
811924   else
812925      driver->m_mecmouse = NULL;
926
927   // Pulling down the line on RESET configures the CPU to insert one wait
928   // state on external memory accesses
929
930   // RN: enable automatic wait state generation
931   // in January 83 99/8 schematics sheet 9: the delay logic
932   // seems to keep READY low for one cycle when RESET* is
933   // asserted, but the timings are completely wrong this way
934
935   driver->m_cpu->set_ready(CLEAR_LINE);
936
937   // But we assert the line here so that the system starts running
938   driver->m_ready_line = driver->m_ready_line1 = ASSERT_LINE;
813939}
814940
815941static MACHINE_CONFIG_START( ti99_8_60hz, ti99_8 )
816942   /* basic machine hardware */
817943   /* TMS9995-MP9537 CPU @ 10.7 MHz */
818   MCFG_CPU_ADD("maincpu", TMS9995, 10738635)
819   MCFG_CPU_CONFIG(ti99_8_processor_config)
820   MCFG_CPU_PROGRAM_MAP(memmap)
821   MCFG_CPU_IO_MAP(crumap)
944   MCFG_TMS9995_ADD("maincpu", TMS9995, 10738635, memmap, crumap, ti99_8_processor_config)
945
822946   MCFG_MACHINE_START( ti99_8 )
823947   MCFG_MACHINE_RESET( ti99_8 )
824948
r15423r15424
827951
828952   /* Main board */
829953   MCFG_TMS9901_ADD( TMS9901_TAG, tms9901_wiring_ti99_8, 2684658.75 )
830   MCFG_MAPPER8_ADD( MAPPER_TAG, mapper_devices )
954   MCFG_MAPPER8_ADD( MAPPER_TAG, mapper_conf )
831955   MCFG_TI99_GROMPORT_ADD( GROMPORT_TAG, console_cartslot )
832956
833957   /* Peripheral expansion box */
r15423r15424
849973   MCFG_GROM_ADD( GROM1_TAG, grom1_config )
850974   MCFG_GROM_ADD( GROM2_TAG, grom2_config )
851975
976   /* Pascal GROM libraries. */
977   MCFG_GROM_LIBRARY_ADD(pascal0_grom, pascal0)
978   MCFG_GROM_LIBRARY_ADD(pascal1_grom, pascal1)
979   MCFG_GROM_LIBRARY_ADD(pascal2_grom, pascal2)
980
852981   /* Devices */
853   MCFG_TISPEECH8_ADD(SPEECH_TAG)
982   MCFG_TISPEECH8_ADD(SPEECH_TAG, speech_config)
854983
855984   /* Optional user controller */
856985   MCFG_MECMOUSE_ADD( MECMOUSE_TAG, 60 )
r15423r15424
860989static MACHINE_CONFIG_START( ti99_8_50hz, ti99_8 )
861990   /* basic machine hardware */
862991   /* TMS9995-MP9537 CPU @ 10.7 MHz */
863   MCFG_CPU_ADD("maincpu", TMS9995, 10738635)
864   MCFG_CPU_CONFIG(ti99_8_processor_config)
865   MCFG_CPU_PROGRAM_MAP(memmap)
866   MCFG_CPU_IO_MAP(crumap)
992   MCFG_TMS9995_ADD("maincpu", TMS9995, 10738635, memmap, crumap, ti99_8_processor_config)
867993   MCFG_MACHINE_START( ti99_8 )
868994   MCFG_MACHINE_RESET( ti99_8 )
869995
r15423r15424
872998
873999   /* Main board */
8741000   MCFG_TMS9901_ADD( TMS9901_TAG, tms9901_wiring_ti99_8, 2684658.75 )
875   MCFG_MAPPER8_ADD( MAPPER_TAG, mapper_devices )
1001   MCFG_MAPPER8_ADD( MAPPER_TAG, mapper_conf )
8761002   MCFG_TI99_GROMPORT_ADD( GROMPORT_TAG, console_cartslot )
8771003
8781004   /* Peripheral expansion box */
r15423r15424
8941020   MCFG_GROM_ADD( GROM1_TAG, grom1_config )
8951021   MCFG_GROM_ADD( GROM2_TAG, grom2_config )
8961022
1023   /* Pascal GROMs libraries. */
1024   MCFG_GROM_LIBRARY_ADD(pascal0_grom, pascal0)
1025   MCFG_GROM_LIBRARY_ADD(pascal1_grom, pascal1)
1026   MCFG_GROM_LIBRARY_ADD(pascal2_grom, pascal2)
1027
8971028   /* Devices */
898   MCFG_TISPEECH8_ADD(SPEECH_TAG)
1029   MCFG_TISPEECH8_ADD(SPEECH_TAG, speech_config)
8991030
9001031   /* Optional user controller */
9011032   MCFG_MECMOUSE_ADD( MECMOUSE_TAG, 50 )
r15423r15424
9131044   ROM_REGION(0x10000, region_grom, 0)
9141045   ROM_LOAD("998grom.bin", 0x0000, 0x6000, CRC(c63806bc) SHA1(cbfa8b04b4aefbbd9a713c54267ad4dd179c13a3))   /* system GROMs */
9151046
1047   /* Pascal GROMs. Sadly, P-System fails to start. */
1048   ROM_REGION(0x10000, pascal0_region, 0)
1049   ROM_LOAD_OPTIONAL("998pascal.bin", 0x0000, 0x10000, CRC(1389589e) SHA1(42942b99ed355a2c091cc480b15f5329156e6b03))
1050
1051   // Still need good dumps; so far, stay with 0
1052   ROM_REGION(0x10000, pascal12_region, 0)
1053   ROM_FILL(0x0000, 0x10000, 0x00)
1054
9161055   /* Built-in RAM */
9171056   ROM_REGION(SRAM_SIZE, SRAM_TAG, 0)
9181057   ROM_FILL(0x0000, SRAM_SIZE, 0x00)
src/mess/drivers/tm990189.c
r15423r15424
5858******************************************************************************************/
5959
6060#include "emu.h"
61#include "cpu/tms9900/tms9900.h"
61#include "cpu/tms9900/tms9900l.h"
6262#include "machine/tms9901.h"
6363#include "machine/tms9902.h"
6464#include "video/tms9928a.h"
r15423r15424
824824
825825static MACHINE_CONFIG_START( tm990_189, tm990189_state )
826826   /* basic machine hardware */
827   MCFG_CPU_ADD("maincpu", TMS9980, 2000000)   /* TMS9980 CPU @ 2.0 MHz */
827   MCFG_CPU_ADD("maincpu", TMS9980L, 2000000)   /* TMS9980 CPU @ 2.0 MHz */
828828   MCFG_CPU_CONFIG(reset_params)
829829   MCFG_CPU_PROGRAM_MAP(tm990_189_memmap)
830830   MCFG_CPU_IO_MAP(tm990_189_cru_map)
r15423r15424
853853
854854static MACHINE_CONFIG_START( tm990_189_v, tm990189_state )
855855   /* basic machine hardware */
856   MCFG_CPU_ADD("maincpu", TMS9980, 2000000)   /* TMS9980 CPU @ 2.0 MHz */
856   MCFG_CPU_ADD("maincpu", TMS9980L, 2000000)   /* TMS9980 CPU @ 2.0 MHz */
857857   MCFG_CPU_CONFIG(reset_params)
858858   MCFG_CPU_PROGRAM_MAP(tm990_189_v_memmap)
859859   MCFG_CPU_IO_MAP(tm990_189_cru_map)
src/mess/drivers/ti990_10.c
r15423r15424
6969
7070#include "emu.h"
7171
72#include "cpu/tms9900/tms9900.h"
72#include "cpu/tms9900/tms9900l.h"
7373#include "sound/beep.h"
7474#include "machine/ti990.h"
7575#include "machine/990_hd.h"
r15423r15424
208208static MACHINE_CONFIG_START( ti990_10, ti990_10_state )
209209   /* basic machine hardware */
210210   /* TI990/10 CPU @ 4.0(???) MHz */
211   MCFG_CPU_ADD("maincpu", TI990_10, 4000000)
211   MCFG_CPU_ADD("maincpu", TI990_10L, 4000000)
212212   MCFG_CPU_CONFIG(reset_params)
213213   MCFG_CPU_PROGRAM_MAP(ti990_10_memmap)
214214   MCFG_CPU_IO_MAP(ti990_10_io)
src/mess/drivers/ti99_2.c
r15423r15424
7979
8080#include "emu.h"
8181#include "machine/tms9901.h"
82#include "cpu/tms9900/tms9900.h"
82#include "cpu/tms9900/tms9900l.h"
8383
8484
8585class ti99_2_state : public driver_device
r15423r15424
375375
376376static MACHINE_CONFIG_START( ti99_2, ti99_2_state )
377377   /* basic machine hardware */
378   MCFG_CPU_ADD("maincpu", TMS9995, 10700000)
378   MCFG_CPU_ADD("maincpu", TMS9995L, 10700000)
379379   MCFG_CPU_CONFIG(ti99_2_processor_config)
380380   MCFG_CPU_PROGRAM_MAP(ti99_2_memmap)
381381   MCFG_CPU_IO_MAP(ti99_2_io)
src/mess/drivers/tutor.c
r15423r15424
168168
169169
170170#include "emu.h"
171#include "cpu/tms9900/tms9900.h"
171#include "cpu/tms9900/tms9900l.h"
172172#include "sound/wave.h"
173173#include "video/tms9928a.h"
174174#include "imagedev/cartslot.h"
r15423r15424
743743static MACHINE_CONFIG_START( tutor, tutor_state )
744744   /* basic machine hardware */
745745   /* TMS9995 CPU @ 10.7 MHz */
746   MCFG_CPU_ADD("maincpu", TMS9995, 10700000)
746   MCFG_CPU_ADD("maincpu", TMS9995L, 10700000)
747747   MCFG_CPU_CONFIG(tutor_processor_config)
748748   MCFG_CPU_PROGRAM_MAP(tutor_memmap)
749749   MCFG_CPU_IO_MAP(tutor_io)
src/mess/drivers/ti990_4.c
r15423r15424
3636#define VIDEO_911 0
3737
3838#include "emu.h"
39#include "cpu/tms9900/tms9900.h"
39#include "cpu/tms9900/tms9900l.h"
4040#include "machine/ti990.h"
4141#if VIDEO_911
4242#include "video/911_vdt.h"
r15423r15424
242242static MACHINE_CONFIG_START( ti990_4, ti990_4_state )
243243   /* basic machine hardware */
244244   /* TMS9900 CPU @ 3.0(???) MHz */
245   MCFG_CPU_ADD("maincpu", TMS9900, 3000000)
245   MCFG_CPU_ADD("maincpu", TMS9900L, 3000000)
246246   MCFG_CPU_PROGRAM_MAP(ti990_4_memmap)
247247   MCFG_CPU_IO_MAP(ti990_4_cru_map)
248248   MCFG_CPU_PERIODIC_INT(ti990_4_line_interrupt, 120/*or TIME_IN_HZ(100) in Europe*/)
src/mess/drivers/geneve.c
r15423r15424
202202
203203
204204#include "emu.h"
205#include "cpu/tms9900/tms9900.h"
205#include "cpu/tms9900/tms9995.h"
206206#include "machine/tms9901.h"
207207#include "machine/mm58274c.h"
208208#include "sound/sn76496.h"
r15423r15424
234234   DECLARE_WRITE_LINE_MEMBER(joystick_select);
235235   DECLARE_WRITE_LINE_MEMBER(extbus_wait_states);
236236   DECLARE_WRITE_LINE_MEMBER(video_wait_states);
237
238   DECLARE_WRITE_LINE_MEMBER(clock_out);
239   DECLARE_WRITE8_MEMBER(external_operation);
240
237241   DECLARE_WRITE8_MEMBER(tms9901_interrupt);
238242
239243   WRITE_LINE_MEMBER( keyboard_interrupt );
r15423r15424
243247   tms9901_device*         m_tms9901;
244248   geneve_mapper_device*   m_mapper;
245249   peribox_device*         m_peribox;
246   device_t*            m_cpu;
250   tms9995_device*         m_cpu;
247251
248252   WRITE_LINE_MEMBER( inta );
249253   WRITE_LINE_MEMBER( intb );
250   WRITE_LINE_MEMBER( ready );
254   WRITE_LINE_MEMBER( ext_ready );
255   WRITE_LINE_MEMBER( mapper_ready );
251256
252257   void   set_tms9901_INT2_from_v9938(v99x8_device &vdp, int state);
253258
r15423r15424
256261   line_state   m_int2;
257262   line_state   m_keyint;
258263   line_state   m_video_wait; // reflects the line to the mapper for CRU query
264
265   int   m_ready_line, m_ready_line1;
266
259267private:
260268   int      m_joystick_select;
261269   // Some values to keep. Rest is on the geneve_mapper.
262270};
263271
264
265272/*
266273    Memory map
267274*/
r15423r15424
356363      {
357364      case 5:
358365         // No one really cares...
366         if (VERBOSE>8) LOG("geneve: Set PAL flag = %02x\n", data);
359367         // m_palvideo = (data!=0);
360368         break;
361369      case 7:
362370         // m_capslock = (data!=0);
371         if (VERBOSE>8) LOG("geneve: Set capslock flag = %02x\n", data);
363372         break;
364373      case 8:
374         if (VERBOSE>8) LOG("geneve: Set keyboard clock flag = %02x\n", data);
365375         m_keyboard->clock_control((data!=0)? ASSERT_LINE : CLEAR_LINE);
366376         break;
367377      case 9:
378         if (VERBOSE>8) LOG("geneve: Set keyboard scan flag = %02x\n", data);
368379         m_keyboard->send_scancodes((data!=0)? ASSERT_LINE : CLEAR_LINE);
369380         break;
370381      case 10:
382         if (VERBOSE>8) LOG("geneve: Geneve mode = %02x\n", data);
371383         m_mapper->set_geneve_mode(data!=0);
372384         break;
373385      case 11:
386         if (VERBOSE>8) LOG("geneve: Direct mode = %02x\n", data);
374387         m_mapper->set_direct_mode(data!=0);
375388         break;
376389      case 12:
390         if (VERBOSE>8) LOG("geneve: Cartridge size 8K = %02x\n", data);
377391         m_mapper->set_cartridge_size((data!=0)? 0x2000 : 0x4000);
378392         break;
379393      case 13:
394         if (VERBOSE>8) LOG("geneve: Cartridge writable 6000 = %02x\n", data);
380395         m_mapper->set_cartridge_writable(0x6000, (data!=0));
381396         break;
382397      case 14:
398         if (VERBOSE>8) LOG("geneve: Cartridge writable 7000 = %02x\n", data);
383399         m_mapper->set_cartridge_writable(0x7000, (data!=0));
384400         break;
385401      case 15:
402         if (VERBOSE>8) LOG("geneve: Extra wait states = %02x\n", data==0);
386403         m_mapper->set_extra_waitstates(data==0);  // let's use the inverse semantics
387404         break;
388405      default:
r15423r15424
410427      return value;
411428   }
412429
413   // TMS9995-internal CRU locations (1ee0-1efe) are handled within the 99xxcore
414   // implementation (read_single_cru), so we don't arrive here
430   // TMS9995-internal CRU locations (1ee0-1efe) are handled within the processor
431   // so we just don't arrive here
415432
416433   // Propagate the CRU access to external devices
417434   m_peribox->crureadz(addroff, &value);
r15423r15424
535552/*
536553    Called by the 9901 core whenever the state of INTREQ and IC0-3 changes.
537554    As with the TI-99/4A, the interrupt level is delivered as the offset,
538    but again it is ignored.
555    but again it is ignored. Anyway, the TMS9995 has only two external inputs
556    (INT1 and INT4).
539557*/
540558WRITE8_MEMBER( geneve::tms9901_interrupt )
541559{
542   /* INTREQ is connected to INT1 (IC0-3 are not connected) */
543   device_execute(m_cpu)->set_input_line(0, data);
560   /* INTREQ is connected to INT1. */
561   device_execute(m_cpu)->set_input_line(1, data);
544562}
545563
546564/* tms9901 setup */
r15423r15424
584602{
585603   m_inta = (state!=0)? ASSERT_LINE : CLEAR_LINE;
586604   m_tms9901->set_single_int(1, state);
587   device_execute(m_cpu)->set_input_line(1, state);
605   device_execute(m_cpu)->set_input_line(4, state);
588606}
589607
590608/*
r15423r15424
596614   m_tms9901->set_single_int(12, state);
597615}
598616
599WRITE_LINE_MEMBER( geneve::ready )
617WRITE_LINE_MEMBER( geneve::ext_ready )
600618{
601   if (VERBOSE>0) LOG("geneve: READY line set ... not yet connected, level=%02x\n", state);
619   if (VERBOSE>6) LOG("ti99_8: READY level (ext) =%02x\n", state);
620   m_ready_line = state;
621   m_cpu->set_ready((m_ready_line == ASSERT_LINE && m_ready_line1 == ASSERT_LINE)? ASSERT_LINE : CLEAR_LINE);
602622}
603623
624WRITE_LINE_MEMBER( geneve::mapper_ready )
625{
626   if (VERBOSE>6) LOG("geneve: READY level (mapper) = %02x\n", state);
627   m_ready_line1 = state;
628   m_cpu->set_ready((m_ready_line == ASSERT_LINE && m_ready_line1 == ASSERT_LINE)? ASSERT_LINE : CLEAR_LINE);
629}
630
604631/*
605632    set the state of int2 (called by the v9938 core)
606633*/
r15423r15424
641668   }
642669}
643670
644static const struct tms9995reset_param geneve_processor_config =
671WRITE8_MEMBER( geneve::external_operation )
645672{
646   0,   /* disable automatic wait state generation */
647   0,   /* no IDLE callback */
648   0   /* no MP9537 mask */
673   static const char* extop[8] = { "inv1", "inv2", "IDLE", "RSET", "inv3", "CKON", "CKOF", "LREX" };
674   if (VERBOSE>1) LOG("External operation %s not implemented on Geneve board\n", extop[offset]);
675}
676
677/*
678    Clock line from the CPU. Used to control wait state generation.
679*/
680WRITE_LINE_MEMBER( geneve::clock_out )
681{
682   m_mapper->clock_in(state);
683}
684
685static TMS9995_CONFIG( geneve_processor_config )
686{
687   DEVCB_DRIVER_MEMBER(geneve, external_operation),
688   DEVCB_NULL,         // Instruction acquisition
689   DEVCB_DRIVER_LINE_MEMBER(geneve, clock_out),
690   DEVCB_NULL,         // wait
691   DEVCB_NULL,         // HOLDA
692   INTERNAL_RAM,      // use internal RAM
693   NO_OVERFLOW_INT      // The generally available versions of TMS9995 have a deactivated overflow interrupt
649694};
650695
651696static const mm58274c_interface geneve_mm58274c_interface =
r15423r15424
663708{
664709   DEVCB_DRIVER_LINE_MEMBER(geneve, inta),         // INTA
665710   DEVCB_DRIVER_LINE_MEMBER(geneve, intb),         // INTB
666   DEVCB_DRIVER_LINE_MEMBER(geneve, ready),      // READY
711   DEVCB_DRIVER_LINE_MEMBER(geneve, ext_ready),   // READY
667712   0x00000                                 // Address bus prefix (Mapper will produce prefixes)
668713};
669714
715static GENEVE_MAPPER_CONFIG( mapper_conf )
716{
717   DEVCB_DRIVER_LINE_MEMBER(geneve, mapper_ready)   // READY
718};
719
670720static DRIVER_INIT( geneve )
671721{
672722}
r15423r15424
679729   driver->m_keyboard = static_cast<geneve_keyboard_device*>(machine.device(GKEYBOARD_TAG));
680730   driver->m_peribox = static_cast<peribox_device*>(machine.device(PERIBOX_TAG));
681731   driver->m_mouse =  static_cast<geneve_mouse_device*>(machine.device(GMOUSE_TAG));
682   driver->m_cpu = machine.device("maincpu");
732   driver->m_cpu = static_cast<tms9995_device*>(machine.device("maincpu"));
683733}
684734
685735/*
r15423r15424
693743   driver->m_int2 = CLEAR_LINE;   // flag reflecting the INT2 line
694744   driver->m_keyint = CLEAR_LINE;
695745
746   // No automatic wait state (auto wait state is enabled with READY=CLEAR at RESET)
747   driver->m_cpu->set_ready(ASSERT_LINE);
748
749   driver->m_ready_line = driver->m_ready_line1 = ASSERT_LINE;
750
696751   driver->m_peribox->set_genmod(machine.root_device().ioport("MODE")->read()==GENMOD);
697752}
698753
699754static MACHINE_CONFIG_START( geneve_60hz, geneve )
700755   /* basic machine hardware */
701756   /* TMS9995 CPU @ 12.0 MHz */
702   MCFG_CPU_ADD("maincpu", TMS9995, 12000000)
703   MCFG_CPU_CONFIG(geneve_processor_config)
704   MCFG_CPU_PROGRAM_MAP(memmap)
705   MCFG_CPU_IO_MAP(crumap)
757   MCFG_TMS9995_ADD("maincpu", TMS9995, 12000000, memmap, crumap, geneve_processor_config)
706758
707759   MCFG_MACHINE_START( geneve )
708760   MCFG_MACHINE_RESET( geneve )
709761
710762   /* video hardware */
711   /* FIXME: (MZ) Lowered the screen rate to 30 Hz. This is a quick hack to
712    restore normal video speed for V9938-based systems until the V9938 implementation
713    is properly fixed. */
763   // Although we should have a 60 Hz screen rate, we have to set it to 30 here.
764   // The reason is that that the number of screen lines is counted twice for the
765   // interlace mode, but in non-interlace modes only half of the lines are
766   // painted. Accordingly, the full set of lines is refreshed at 30 Hz,
767   // not 60 Hz. This should be fixed in the v9938 emulation.
714768   MCFG_TI_V9938_ADD(VIDEO_SYSTEM_TAG, 30, SCREEN_TAG, 2500, 512+32, (212+28)*2, DEVICE_SELF, geneve, set_tms9901_INT2_from_v9938)
715769   MCFG_TIMER_ADD_SCANLINE("scantimer", geneve_hblank_interrupt, SCREEN_TAG, 0, 1) /* 262.5 in 60Hz, 312.5 in 50Hz */
716770
717771   /* Main board components */
718772   MCFG_TMS9901_ADD(TMS9901_TAG, tms9901_wiring_geneve, 3000000)
719   MCFG_GENEVE_MAPPER_ADD( GMAPPER_TAG )
773   MCFG_GENEVE_MAPPER_ADD(GMAPPER_TAG, mapper_conf)
720774   MCFG_MM58274C_ADD(GCLOCK_TAG, geneve_mm58274c_interface)
721775
722776   /* Peripheral expansion box (Geneve composition) */
src/mess/drivers/ti99_4p.c
r15423r15424
6767   DECLARE_WRITE_LINE_MEMBER( console_ready );
6868   DECLARE_WRITE_LINE_MEMBER( extint );
6969   DECLARE_WRITE_LINE_MEMBER( notconnected );
70
70   DECLARE_READ8_MEMBER( interrupt_level );
7171   DECLARE_READ16_MEMBER( memread );
7272   DECLARE_WRITE16_MEMBER( memwrite );
7373
7474   DECLARE_READ16_MEMBER( samsmem_read );
7575   DECLARE_WRITE16_MEMBER( samsmem_write );
7676
77   DECLARE_WRITE8_MEMBER(external_operation);
78   DECLARE_WRITE_LINE_MEMBER( clock_out );
79
80   void   clock_in(int clock);
81
7782   // CRU (Communication Register Unit) handling
7883   DECLARE_READ8_MEMBER( cruread );
7984   DECLARE_WRITE8_MEMBER( cruwrite );
r15423r15424
9095
9196   void set_tms9901_INT2_from_v9938(v99x8_device &vdp, int state);
9297
93   device_t*            m_cpu;
98   tms9900_device*         m_cpu;
99   tms9901_device*         m_tms9901;
94100   ti_sound_system_device*   m_sound;
95101   ti_exp_video_device*   m_video;
96102   cassette_image_device*   m_cassette;
97103   peribox_device*         m_peribox;
98   tms9901_device*         m_tms9901;
99104
100105   // Pointer to ROM0
101106   UINT16 *m_rom0;
r15423r15424
115120   // Scratch pad ram (1 KiB)
116121   UINT16 *m_scratchpad;
117122
123   // READY line
124   bool m_ready_line, m_ready_line1;
125
118126private:
119127   DECLARE_READ16_MEMBER( datamux_read );
120128   DECLARE_WRITE16_MEMBER( datamux_write );
121129   void   set_key(int number, int data);
130
122131   int      m_keyboard_column;
123132   int      m_alphalock_line;
124133
r15423r15424
131140   // Offset to the ROM6 bank.
132141   int m_rom6_bank;
133142
143   // Wait states
144   int m_waitcount;
145
134146   // TRUE when mapper is active
135147   bool m_map_mode;
136148
r15423r15424
411423    one device, the peripheral box, so it is much simpler.
412424***************************************************************************/
413425
426/*
427    The datamux is connected to the clock line in order to operate
428    the wait state counter.
429*/
430void ti99_4p::clock_in(int clock)
431{
432   if (clock==ASSERT_LINE && m_waitcount!=0)
433   {
434      m_waitcount--;
435      if (m_waitcount==0) console_ready(ASSERT_LINE);
436   }
437}
438
439
414440READ16_MEMBER( ti99_4p::datamux_read )
415441{
416442   UINT8 hbyte = 0;
r15423r15424
419445   m_peribox->readz(space, addroff+1, &m_latch, mem_mask);
420446   m_lowbyte = m_latch;
421447
422   // Takes three cycles
423   device_adjust_icount(m_cpu, -3);
424
425448   m_peribox->readz(space, addroff, &hbyte, mem_mask);
426449   m_highbyte = hbyte;
427450
428   // Takes three cycles
429   device_adjust_icount(m_cpu, -3);
430
431451   // use the latch and the currently read byte and put it on the 16bit bus
432452//  printf("read  address = %04x, value = %04x, memmask = %4x\n", addroff,  (hbyte<<8) | sgcpu->latch, mem_mask);
453
454   // Insert four wait states and let CPU enter wait state
455   m_waitcount = 6;
456   console_ready(CLEAR_LINE);
457
433458   return (hbyte<<8) | m_latch ;
434459}
435460
r15423r15424
457482   // Write to the PEB
458483   m_peribox->write(space, addroff+1, data & 0xff);
459484
460   // Takes three cycles
461   device_adjust_icount(m_cpu,-3);
462
463485   // Write to the PEB
464486   m_peribox->write(space, addroff, (data>>8) & 0xff);
465487
466   // Takes three cycles
467   device_adjust_icount(m_cpu,-3);
488   // Insert four wait states and let CPU enter wait state
489   m_waitcount = 6;
490   console_ready(CLEAR_LINE);
468491}
469492
470493/***************************************************************************
r15423r15424
655678   m_cassette->output((state!=0)? +1 : -1);
656679}
657680
658WRITE8_MEMBER( ti99_4p::tms9901_interrupt )
659{
660   // offset contains the interrupt level (0-15)
661   if (data==ASSERT_LINE)
662   {
663      // The TMS9901 should normally be connected with the CPU by 5 wires:
664      // INTREQ* and IC0-IC3. The last four lines deliver the interrupt level.
665      // On the TI-99 systems these IC lines are not used; the input lines
666      // at the CPU are hardwired to level 1.
667      device_execute(m_cpu)->set_input_line_and_vector(0, ASSERT_LINE, 1);
668   }
669   else
670   {
671      device_execute(m_cpu)->set_input_line(0, CLEAR_LINE);
672   }
673}
674
675681/* TMS9901 setup. The callback functions pass a reference to the TMS9901 as device. */
676const tms9901_interface tms9901_wiring_ti99_4p =
682const tms9901_interface tms9901_wiring_sgcpu =
677683{
678684   TMS9901_INT1 | TMS9901_INT2 | TMS9901_INTC,   /* only input pins whose state is always known */
679685
r15423r15424
707713    Control lines
708714****************************************************************************/
709715
716/*
717    We may have lots of devices pulling down this line; so we should use a AND
718    gate to do it right. On the other hand, when READY is down, there is just
719    no chance to make another device pull down the same line; the CPU just
720    won't access any other device in this time.
721*/
710722WRITE_LINE_MEMBER( ti99_4p::console_ready )
711723{
712   if (VERBOSE>6) LOG("READY line set ... not yet connected, level=%02x\n", state);
724   if (VERBOSE>6) LOG("ti99_4p: READY level = %02x\n", state);
725   m_ready_line = state;
726
727   m_cpu->set_ready((m_ready_line == ASSERT_LINE && m_ready_line1 == ASSERT_LINE)? ASSERT_LINE : CLEAR_LINE);
713728}
714729
715730WRITE_LINE_MEMBER( ti99_4p::extint )
716731{
717   if (VERBOSE>6) LOG("EXTINT level = %02x\n", state);
732   if (VERBOSE>6) LOG("ti99_4p: EXTINT level = %02x\n", state);
718733   if (m_tms9901 != NULL)
719734      m_tms9901->set_single_int(1, state);
720735}
721736
722737WRITE_LINE_MEMBER( ti99_4p::notconnected )
723738{
724   if (VERBOSE>6) LOG("Setting a not connected line ... ignored\n");
739   if (VERBOSE>6) LOG("ti99_4p: Setting a not connected line ... ignored\n");
725740}
726741
742/*
743    Clock line from the CPU. Used to control wait state generation.
744*/
745WRITE_LINE_MEMBER( ti99_4p::clock_out )
746{
747   clock_in(state);
748}
749
750WRITE8_MEMBER( ti99_4p::tms9901_interrupt )
751{
752   // offset contains the interrupt level (0-15)
753   // However, the TI board just ignores that level and hardwires it to 1
754   // See below (interrupt_level)
755   m_cpu->set_input_line(0, data);
756}
757
758READ8_MEMBER( ti99_4p::interrupt_level )
759{
760   // On the TI-99 systems these IC lines are not used; the input lines
761   // at the CPU are hardwired to level 1.
762   return 1;
763}
764
765WRITE8_MEMBER( ti99_4p::external_operation )
766{
767   static const char* extop[8] = { "inv1", "inv2", "IDLE", "RSET", "inv3", "CKON", "CKOF", "LREX" };
768   if (VERBOSE>1) LOG("External operation %s not implemented on the SGCPU board\n", extop[offset]);
769}
770
727771/*****************************************************************************/
728772
729773static PERIBOX_CONFIG( peribox_conf )
r15423r15424
734778   0x70000                                    // Address bus prefix (AMA/AMB/AMC)
735779};
736780
737DRIVER_INIT( ti99_4p )
781static TMS9900_CONFIG( sgcpu_cpuconf )
738782{
739}
783   DEVCB_DRIVER_MEMBER(ti99_4p, external_operation),
784   DEVCB_DRIVER_MEMBER(ti99_4p, interrupt_level),
785   DEVCB_NULL,      // Instruction acquisition
786   DEVCB_DRIVER_LINE_MEMBER(ti99_4p, clock_out),
787   DEVCB_NULL,      // wait
788   DEVCB_NULL      // Hold acknowledge
789};
740790
741791MACHINE_START( ti99_4p )
742792{
743793   ti99_4p *driver = machine.driver_data<ti99_4p>();
744794
745   driver->m_cpu = machine.device("maincpu");
795   driver->m_cpu = static_cast<tms9900_device*>(machine.device("maincpu"));
746796   driver->m_peribox = static_cast<peribox_device*>(machine.device(PERIBOX_TAG));
747797   driver->m_sound = static_cast<ti_sound_system_device*>(machine.device(TISOUND_TAG));
748798   driver->m_video = static_cast<ti_exp_video_device*>(machine.device(VIDEO_SYSTEM_TAG));
r15423r15424
755805   driver->m_peribox->senila(CLEAR_LINE);
756806   driver->m_peribox->senilb(CLEAR_LINE);
757807
808   driver->m_ready_line = driver->m_ready_line1 = ASSERT_LINE;
809
758810   UINT16 *rom = (UINT16*)(*machine.root_device().memregion("maincpu"));
759811   driver->m_rom0  = rom + 0x2000;
760812   driver->m_dsr   = rom + 0x6000;
r15423r15424
779831   driver->m_tms9901->set_single_int(12, 0);
780832}
781833
782TIMER_DEVICE_CALLBACK( ti99_4p_hblank_interrupt )
834TIMER_DEVICE_CALLBACK( sgcpu_hblank_interrupt )
783835{
784836   timer.machine().device<v9938_device>(V9938_TAG)->interrupt();
785837}
r15423r15424
790842static MACHINE_CONFIG_START( ti99_4p_60hz, ti99_4p )
791843   /* basic machine hardware */
792844   /* TMS9900 CPU @ 3.0 MHz */
793   MCFG_CPU_ADD("maincpu", TMS9900, 3000000)
794   MCFG_CPU_PROGRAM_MAP(memmap)
795   MCFG_CPU_IO_MAP(cru_map)
845   MCFG_TMS9900_ADD("maincpu", TMS9900, 3000000, memmap, cru_map, sgcpu_cpuconf)
796846   MCFG_MACHINE_START( ti99_4p )
797847
798848   /* video hardware */
799   /* FIXME: (MZ) Lowered the screen rate to 30 Hz. This is a quick hack to
800    restore normal video speed for V9938-based systems until the V9938 implementation
801    is properly fixed. */
849   // Although we should have a 60 Hz screen rate, we have to set it to 30 here.
850   // The reason is that that the number of screen lines is counted twice for the
851   // interlace mode, but in non-interlace modes only half of the lines are
852   // painted. Accordingly, the full set of lines is refreshed at 30 Hz,
853   // not 60 Hz. This should be fixed in the v9938 emulation.
802854   MCFG_TI_V9938_ADD(VIDEO_SYSTEM_TAG, 30, SCREEN_TAG, 2500, 512+32, (212+28)*2, DEVICE_SELF, ti99_4p, set_tms9901_INT2_from_v9938)
803   MCFG_TIMER_ADD_SCANLINE("scantimer", ti99_4p_hblank_interrupt, SCREEN_TAG, 0, 1)
855   MCFG_TIMER_ADD_SCANLINE("scantimer", sgcpu_hblank_interrupt, SCREEN_TAG, 0, 1)
804856
805857   /* tms9901 */
806   MCFG_TMS9901_ADD(TMS9901_TAG, tms9901_wiring_ti99_4p, 3000000)
858   MCFG_TMS9901_ADD(TMS9901_TAG, tms9901_wiring_sgcpu, 3000000)
807859
808860   /* Peripheral expansion box (SGCPU composition) */
809861   MCFG_PERIBOX_SG_ADD( PERIBOX_TAG, peribox_conf )
r15423r15424
834886ROM_END
835887
836888/*    YEAR  NAME      PARENT   COMPAT   MACHINE      INPUT    INIT      COMPANY     FULLNAME */
837COMP( 1996, ti99_4p,  0,      0,      ti99_4p_60hz, ti99_4p, ti99_4p, "System 99 Users Group",      "SGCPU (a.k.a. 99/4P)" , 0 )
889COMP( 1996, ti99_4p,  0,      0,      ti99_4p_60hz, ti99_4p, 0, "System 99 Users Group",      "SGCPU (a.k.a. 99/4P)" , 0 )
src/mess/drivers/cortex.c
r15423r15424
1919****************************************************************************/
2020
2121#include "emu.h"
22#include "cpu/tms9900/tms9900.h"
22#include "cpu/tms9900/tms9900l.h"
2323
2424class cortex_state : public driver_device
2525{
r15423r15424
6868static MACHINE_CONFIG_START( cortex, cortex_state )
6969   /* basic machine hardware */
7070   /* TMS9995 CPU @ 12.0 MHz */
71   MCFG_CPU_ADD("maincpu", TMS9995, 12000000)
71   MCFG_CPU_ADD("maincpu", TMS9995L, 12000000)
7272   MCFG_CPU_CONFIG(cortex_processor_config)
7373   MCFG_CPU_PROGRAM_MAP(cortex_mem)
7474   MCFG_CPU_IO_MAP(cortex_io)
src/mess/drivers/ti99_4x.c
r15423r15424
5656#include "machine/ti99/peribox.h"
5757
5858#define LOG logerror
59#define VERBOSE 1
59#define VERBOSE
6060
6161/*
6262    The console.
r15423r15424
7070   // CRU (Communication Register Unit) handling
7171   DECLARE_READ8_MEMBER(cruread);
7272   DECLARE_WRITE8_MEMBER(cruwrite);
73   DECLARE_WRITE8_MEMBER(external_operation);
7374
7475   // Forwarding interrupts to the CPU or CRU
7576   DECLARE_WRITE_LINE_MEMBER( console_ready );
77   DECLARE_WRITE_LINE_MEMBER( console_ready_dmux );
78
7679   DECLARE_WRITE_LINE_MEMBER( set_tms9901_INT2 );
7780   DECLARE_WRITE_LINE_MEMBER( set_tms9901_INT12 );
7881   void set_tms9901_INT2_from_v9938(v99x8_device &vdp, int state);
7982   DECLARE_WRITE_LINE_MEMBER( extint );
8083   DECLARE_WRITE_LINE_MEMBER( notconnected );
8184
85   DECLARE_READ8_MEMBER( interrupt_level );
86   DECLARE_READ_LINE_MEMBER( ready_connect );
87   DECLARE_WRITE_LINE_MEMBER( clock_out );
88
8289   // Some values to keep
8390   int               m_mode;
84   device_t         *m_cpu;
85   tms9901_device      *m_tms9901;
86   gromport_device      *m_gromport;
87   peribox_device      *m_peribox;
88   mecmouse_device    *m_mecmouse;
89   ti99_handset_device *m_handset;
91   tms9900_device*      m_cpu;
92   tms9901_device*      m_tms9901;
93   gromport_device*   m_gromport;
94   peribox_device*      m_peribox;
95   mecmouse_device*   m_mecmouse;
96   ti99_handset_device* m_handset;
97   ti99_datamux_device* m_datamux;
9098
99   int      m_ready_line, m_ready_line1;
100
91101   // Connections with the system interface TMS9901
92102   DECLARE_READ8_MEMBER(read_by_9901);
93103   DECLARE_WRITE_LINE_MEMBER(keyC0);
r15423r15424
102112   DECLARE_WRITE_LINE_MEMBER(alphaW);
103113
104114private:
105   void            set_key(int number, int data);
106   int               m_keyboard_column;
107   int               m_alphalock_line;
115   void   set_key(int number, int data);
116   int      m_keyboard_column;
117   int      m_alphalock_line;
108118};
109119
110120/*
111    Memory map
121    Memory map.
122    Most of the work is done in the datamux (see datamux.c). We only keep ROM
123    and the small 256 byte PAD RAM here because they are directly connected
124    to the 16bit bus, and the wait state logic is not active during their
125    accesses.
112126*/
113127static ADDRESS_MAP_START(memmap, AS_PROGRAM, 16, ti99_4x)
114128   ADDRESS_MAP_GLOBAL_MASK(0xffff)
115   AM_RANGE(0x0000, 0x1fff) AM_ROM                              /*system ROM*/
116   AM_RANGE(0x8000, 0x80ff) AM_MIRROR(0x0300) AM_RAM         /*RAM PAD, mirrored 4 times*/
117   AM_RANGE(0x8800, 0x8bff) AM_DEVREADWRITE(VIDEO_SYSTEM_TAG, ti_std_video_device, read16, nowrite)   /*vdp read*/
118   AM_RANGE(0x8C00, 0x8fff) AM_DEVREADWRITE(VIDEO_SYSTEM_TAG, ti_std_video_device, noread, write16)   /*vdp write*/
129   AM_RANGE(0x0000, 0x1fff) AM_ROM
130   AM_RANGE(0x8000, 0x80ff) AM_MIRROR(0x0300) AM_RAM
119131   AM_RANGE(0x0000, 0xffff) AM_DEVREADWRITE(DATAMUX_TAG, ti99_datamux_device, read, write)
120132ADDRESS_MAP_END
121133
122static ADDRESS_MAP_START(memmap_4ev, AS_PROGRAM, 16, ti99_4x)
123   ADDRESS_MAP_GLOBAL_MASK(0xffff)
124   AM_RANGE(0x0000, 0x1fff) AM_ROM                              /*system ROM*/
125   AM_RANGE(0x8000, 0x80ff) AM_MIRROR(0x0300) AM_RAM         /*RAM PAD, mirrored 4 times*/
126   AM_RANGE(0x8800, 0x8bff) AM_DEVREADWRITE(VIDEO_SYSTEM_TAG, ti_exp_video_device, read16, nowrite)   /*vdp read*/
127   AM_RANGE(0x8C00, 0x8fff) AM_DEVREADWRITE(VIDEO_SYSTEM_TAG, ti_exp_video_device, noread, write16)   /*vdp write*/
128   AM_RANGE(0x0000, 0xffff) AM_DEVREADWRITE(DATAMUX_TAG, ti99_datamux_device, read, write)
129ADDRESS_MAP_END
130
131134/*
132135    CRU map
133136    TMS9900 CRU address space is 12 bits wide, attached to A3-A14, A0-A2 must
r15423r15424
334337
335338static GROM_CONFIG(grom0_config)
336339{
337   false, 0, region_grom, 0x0000, 0x1800, false, DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready)
340   false, 0, region_grom, 0x0000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready), GROMFREQ
338341};
339342
340343static GROM_CONFIG(grom1_config)
341344{
342   false, 1, region_grom, 0x2000, 0x1800, false, DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready)
345   false, 1, region_grom, 0x2000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready), GROMFREQ
343346};
344347
345348static GROM_CONFIG(grom2_config)
346349{
347   false, 2, region_grom, 0x4000, 0x1800, false, DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready)
350   false, 2, region_grom, 0x4000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready), GROMFREQ
348351};
349352
350353static GROMPORT_CONFIG(console_cartslot)
r15423r15424
376379
377380WRITE8_MEMBER( ti99_4x::cruwrite )
378381{
379//  if (VERBOSE>6) LOG("write access to CRU address %04x\n", offset << 1);
382   if (VERBOSE>6) LOG("write access to CRU address %04x\n", offset << 1);
380383   m_gromport->cruwrite(offset<<1, data);
381384   m_peribox->cruwrite(offset<<1, data);
382385}
383386
387WRITE8_MEMBER( ti99_4x::external_operation )
388{
389   static const char* extop[8] = { "inv1", "inv2", "IDLE", "RSET", "inv3", "CKON", "CKOF", "LREX" };
390   if (VERBOSE>1) LOG("External operation %s not implemented on TI-99 board\n", extop[offset]);
391}
392
384393/***************************************************************************
385394    TI99/4x-specific tms9901 I/O handlers
386395
r15423r15424
412421READ8_MEMBER( ti99_4x::read_by_9901 )
413422{
414423   int answer=0;
415
416424   switch (offset & 0x03)
417425   {
418426   case TMS9901_CB_INT7:
r15423r15424
591599WRITE8_MEMBER( ti99_4x::tms9901_interrupt )
592600{
593601   // offset contains the interrupt level (0-15)
594   if (data==ASSERT_LINE)
595   {
596      // The TMS9901 should normally be connected with the CPU by 5 wires:
597      // INTREQ* and IC0-IC3. The last four lines deliver the interrupt level.
598      // On the TI-99 systems these IC lines are not used; the input lines
599      // at the CPU are hardwired to level 1.
600      device_execute(m_cpu)->set_input_line_and_vector(0, ASSERT_LINE, 1);
601   }
602   else
603   {
604      device_execute(m_cpu)->set_input_line(0, CLEAR_LINE);
605   }
602   // However, the TI board just ignores that level and hardwires it to 1
603   // See below (interrupt_level)
604   m_cpu->set_input_line(0, data);
606605}
607606
607READ8_MEMBER( ti99_4x::interrupt_level )
608{
609   // On the TI-99 systems these IC lines are not used; the input lines
610   // at the CPU are hardwired to level 1.
611   return 1;
612}
613
614/*
615    Clock line from the CPU. Used to control wait state generation.
616*/
617WRITE_LINE_MEMBER( ti99_4x::clock_out )
618{
619   m_datamux->clock_in(state);
620}
621
608622/*****************************************************************************/
609623
610624/*
r15423r15424
633647    Links to external devices
634648***********************************************************/
635649
636
650/*
651    We may have lots of devices pulling down this line; so we should use a AND
652    gate to do it right. On the other hand, when READY is down, there is just
653    no chance to make another device pull down the same line; the CPU just
654    won't access any other device in this time.
655*/
637656WRITE_LINE_MEMBER( ti99_4x::console_ready )
638657{
639   if (VERBOSE>6) LOG("READY line set ... not yet connected, level=%02x\n", state);
658   if (VERBOSE>6) LOG("ti99_4x: READY level = %02x\n", state);
659   m_ready_line = state;
660
661   m_cpu->set_ready((m_ready_line == ASSERT_LINE && m_ready_line1 == ASSERT_LINE)? ASSERT_LINE : CLEAR_LINE);
640662}
641663
664/*
665    The exception of the above rule. Memory access over the datamux also operates
666    the READY line, and the datamux raises READY depending on the clock pulse.
667    So we must make sure this does not interfere.
668*/
669WRITE_LINE_MEMBER( ti99_4x::console_ready_dmux )
670{
671   if (VERBOSE>6) LOG("ti99_4x: READY dmux level = %02x\n", state);
672   m_ready_line1 = state;
673   m_cpu->set_ready((m_ready_line == ASSERT_LINE && m_ready_line1 == ASSERT_LINE)? ASSERT_LINE : CLEAR_LINE);
674}
675
642676WRITE_LINE_MEMBER( ti99_4x::extint )
643677{
644   if (VERBOSE>6) LOG("EXTINT level = %02x\n", state);
678   if (VERBOSE>6) LOG("ti99_4x: EXTINT level = %02x\n", state);
645679   if (m_tms9901 != NULL)
646680      m_tms9901->set_single_int(1, state);
647681}
648682
649683WRITE_LINE_MEMBER( ti99_4x::notconnected )
650684{
651   if (VERBOSE>6) LOG("Setting a not connected line ... ignored\n");
685   if (VERBOSE>6) LOG("ti99_4x: Setting a not connected line ... ignored\n");
652686}
653687
654688/*****************************************************************************/
r15423r15424
737771*/
738772static const dmux_device_list_entry dmux_devices[] =
739773{
774   { VIDEO_SYSTEM_TAG, 0x8800, 0xfc01, 0x0400, NULL, 0, 0 },
740775   { GROM0_TAG,     0x9800, 0xfc01, 0x0400, "GROMENA", 0x01, 0x00 },
741776   { GROM1_TAG,     0x9800, 0xfc01, 0x0400, "GROMENA", 0x01, 0x00 },
742777   { GROM2_TAG,     0x9800, 0xfc01, 0x0400, "GROMENA", 0x01, 0x00 },
r15423r15424
747782   { NULL, 0, 0, 0, NULL, 0, 0  }
748783};
749784
785static const dmux_device_list_entry dmux_devices_ev[] =
786{
787   { V9938_SYSTEM_TAG, 0x8800, 0xfc01, 0x0400, NULL, 0, 0 },
788   { GROM0_TAG,     0x9800, 0xfc01, 0x0400, "GROMENA", 0x01, 0x00 },
789   { GROM1_TAG,     0x9800, 0xfc01, 0x0400, "GROMENA", 0x01, 0x00 },
790   { GROM2_TAG,     0x9800, 0xfc01, 0x0400, "GROMENA", 0x01, 0x00 },
791   { TISOUND_TAG,   0x8400, 0xfc01, 0x0000, NULL, 0, 0 },
792   { GROMPORT_TAG,  0x9800, 0xfc01, 0x0400, NULL, 0, 0 },
793   { GROMPORT_TAG,  0x6000, 0xe000, 0x0000, NULL, 0, 0 },
794   { PERIBOX_TAG,   0x0000, 0x0000, 0x0000, NULL, 0, 0 },  // Peribox needs all addresses
795   { NULL, 0, 0, 0, NULL, 0, 0  }
796};
797
798static DMUX_CONFIG( datamux_conf )
799{
800   DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready_dmux),   // READY
801   dmux_devices
802};
803
804static DMUX_CONFIG( datamux_conf_ev )
805{
806   DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready_dmux),   // READY
807   dmux_devices_ev
808};
809
810static TMS9900_CONFIG( ti99_cpuconf )
811{
812   DEVCB_DRIVER_MEMBER(ti99_4x, external_operation),
813   DEVCB_DRIVER_MEMBER(ti99_4x, interrupt_level),
814   DEVCB_NULL,      // Instruction acquisition
815   DEVCB_DRIVER_LINE_MEMBER(ti99_4x, clock_out),
816   DEVCB_NULL,      // wait
817   DEVCB_NULL      // Hold acknowledge
818};
819
750820/******************************************************************************
751821    Machine definitions
752822******************************************************************************/
r15423r15424
756826   ti99_4x *driver = machine.driver_data<ti99_4x>();
757827   driver->m_mode = TI994;
758828
759   driver->m_cpu = machine.device("maincpu");
829   driver->m_cpu = static_cast<tms9900_device*>(machine.device("maincpu"));
760830   driver->m_tms9901 = static_cast<tms9901_device*>(machine.device(TMS9901_TAG));
761831
762832   driver->m_gromport = static_cast<gromport_device*>(machine.device(GROMPORT_TAG));
763833
764834   driver->m_peribox = static_cast<peribox_device*>(machine.device(PERIBOX_TAG));
835   driver->m_datamux = static_cast<ti99_datamux_device*>(machine.device(DATAMUX_TAG));
765836
766837   driver->m_peribox->senila(CLEAR_LINE);
767838   driver->m_peribox->senilb(CLEAR_LINE);
839
840   driver->m_ready_line = driver->m_ready_line1 = ASSERT_LINE;
768841}
769842
770843MACHINE_RESET( ti99_4 )
r15423r15424
785858    TI-99/4 - the predecessor of the more popular TI-99/4A
786859*/
787860static MACHINE_CONFIG_START( ti99_4_60hz, ti99_4x )
788   MCFG_CPU_ADD("maincpu", TMS9900, 3000000)
789   MCFG_CPU_PROGRAM_MAP(memmap)
790   MCFG_CPU_IO_MAP(cru_map)
861   /* CPU */
862   MCFG_TMS9900_ADD("maincpu", TMS9900, 3000000, memmap, cru_map, ti99_cpuconf)
863
791864   MCFG_MACHINE_START( ti99_4 )
792865   MCFG_MACHINE_RESET( ti99_4 )
793866
r15423r15424
795868
796869   /* Main board */
797870   MCFG_TMS9901_ADD(TMS9901_TAG, tms9901_wiring_ti99_4, 3000000)
798   MCFG_DMUX_ADD( DATAMUX_TAG, dmux_devices )
871   MCFG_DMUX_ADD( DATAMUX_TAG, datamux_conf )
799872   MCFG_TI99_GROMPORT_ADD( GROMPORT_TAG, console_cartslot )
800873
801874   /* Software list */
r15423r15424
830903MACHINE_CONFIG_END
831904
832905static MACHINE_CONFIG_START( ti99_4_50hz, ti99_4x )
833   MCFG_CPU_ADD("maincpu", TMS9900, 3000000)
834   MCFG_CPU_PROGRAM_MAP(memmap)
835   MCFG_CPU_IO_MAP(cru_map)
906   /* CPU */
907   MCFG_TMS9900_ADD("maincpu", TMS9900, 3000000, memmap, cru_map, ti99_cpuconf)
908
836909   MCFG_MACHINE_START( ti99_4 )
837910   MCFG_MACHINE_RESET( ti99_4 )
838911
r15423r15424
841914
842915   /* main board */
843916   MCFG_TMS9901_ADD(TMS9901_TAG, tms9901_wiring_ti99_4, 3000000)
844   MCFG_DMUX_ADD( DATAMUX_TAG, dmux_devices )
917   MCFG_DMUX_ADD( DATAMUX_TAG, datamux_conf )
845918   MCFG_TI99_GROMPORT_ADD( GROMPORT_TAG, console_cartslot )
846919
847920   /* Software list */
r15423r15424
882955   ti99_4x *driver = machine.driver_data<ti99_4x>();
883956   driver->m_mode = TI994A;
884957
885   driver->m_cpu = machine.device("maincpu");
958   driver->m_cpu = static_cast<tms9900_device*>(machine.device("maincpu"));
886959   driver->m_tms9901 = static_cast<tms9901_device*>(machine.device(TMS9901_TAG));
887960
888961   driver->m_mecmouse = static_cast<mecmouse_device*>(machine.device(MECMOUSE_TAG));
889962   driver->m_gromport = static_cast<gromport_device*>(machine.device(GROMPORT_TAG));
890963   driver->m_peribox = static_cast<peribox_device*>(machine.device(PERIBOX_TAG));
891964
965   driver->m_datamux = static_cast<ti99_datamux_device*>(machine.device(DATAMUX_TAG));
966
892967   driver->m_peribox->senila(CLEAR_LINE);
893968   driver->m_peribox->senilb(CLEAR_LINE);
969   driver->m_ready_line = driver->m_ready_line1 = ASSERT_LINE;
894970}
895971
896972MACHINE_RESET( ti99_4a )
r15423r15424
903979}
904980
905981static MACHINE_CONFIG_START( ti99_4a_60hz, ti99_4x )
906   MCFG_CPU_ADD("maincpu", TMS9900, 3000000)
907   MCFG_CPU_PROGRAM_MAP(memmap)
908   MCFG_CPU_IO_MAP(cru_map)
982   /* CPU */
983   MCFG_TMS9900_ADD("maincpu", TMS9900, 3000000, memmap, cru_map, ti99_cpuconf)
984
909985   MCFG_MACHINE_START( ti99_4a )
910986   MCFG_MACHINE_RESET( ti99_4a )
911987
r15423r15424
914990
915991   /* Main board */
916992   MCFG_TMS9901_ADD(TMS9901_TAG, tms9901_wiring_ti99_4a, 3000000)
917   MCFG_DMUX_ADD( DATAMUX_TAG, dmux_devices )
993   MCFG_DMUX_ADD( DATAMUX_TAG, datamux_conf )
918994   MCFG_TI99_GROMPORT_ADD( GROMPORT_TAG, console_cartslot )
919995
920996   /* Software list */
r15423r15424
9461022MACHINE_CONFIG_END
9471023
9481024static MACHINE_CONFIG_START( ti99_4a_50hz, ti99_4x )
949   MCFG_CPU_ADD("maincpu", TMS9900, 3000000)
950   MCFG_CPU_PROGRAM_MAP(memmap)
951   MCFG_CPU_IO_MAP(cru_map)
1025   /* CPU */
1026   MCFG_TMS9900_ADD("maincpu", TMS9900, 3000000, memmap, cru_map, ti99_cpuconf)
1027
9521028   MCFG_MACHINE_START( ti99_4a )
9531029   MCFG_MACHINE_RESET( ti99_4a )
9541030
r15423r15424
9571033
9581034   /* Main board */
9591035   MCFG_TMS9901_ADD(TMS9901_TAG, tms9901_wiring_ti99_4a, 3000000)
960   MCFG_DMUX_ADD( DATAMUX_TAG, dmux_devices )
1036   MCFG_DMUX_ADD( DATAMUX_TAG, datamux_conf )
9611037   MCFG_TI99_GROMPORT_ADD( GROMPORT_TAG, console_cartslot )
9621038
9631039   /* Software list */
r15423r15424
9991075    replacing the console video processor.
10001076*/
10011077static MACHINE_CONFIG_START( ti99_4ev_60hz, ti99_4x )
1002   MCFG_CPU_ADD("maincpu", TMS9900, 3000000)
1003   MCFG_CPU_PROGRAM_MAP(memmap_4ev)
1004   MCFG_CPU_IO_MAP(cru_map)
1078   /* CPU */
1079   MCFG_TMS9900_ADD("maincpu", TMS9900, 3000000, memmap, cru_map, ti99_cpuconf)
1080
10051081   MCFG_MACHINE_START( ti99_4a )
10061082
1007   /* Video hardware */
1008   // FIXME: (MZ) Lowered the screen rate to 30 Hz. This is a quick hack to
1009   // restore normal video speed for V9938-based systems until the V9938 implementation
1010   // is properly fixed.
1011   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)
1083   /* video hardware */
1084   // Although we should have a 60 Hz screen rate, we have to set it to 30 here.
1085   // The reason is that that the number of screen lines is counted twice for the
1086   // interlace mode, but in non-interlace modes only half of the lines are
1087   // painted. Accordingly, the full set of lines is refreshed at 30 Hz,
1088   // not 60 Hz. This should be fixed in the v9938 emulation.
1089   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)
10121090   MCFG_TIMER_ADD_SCANLINE("scantimer", ti99_4ev_hblank_interrupt, SCREEN_TAG, 0, 1)
10131091
10141092   /* Main board */
10151093   MCFG_TMS9901_ADD(TMS9901_TAG, tms9901_wiring_ti99_4a, 3000000)
1016   MCFG_DMUX_ADD( DATAMUX_TAG, dmux_devices )
1094   MCFG_DMUX_ADD( DATAMUX_TAG, datamux_conf_ev )
10171095   MCFG_TI99_GROMPORT_ADD( GROMPORT_TAG, console_cartslot )
10181096
10191097   /* Software list */
src/mess/mess.mak
r15423r15424
3737CPUS += S2650
3838CPUS += TMS340X0
3939CPUS += TMS9900
40CPUS += TMS9995
41CPUS += TMS9900L
42CPUS += TMS9995L
4043CPUS += Z8000
4144#CPUS += Z8001
4245CPUS += TMS32010

Previous 15994 Revisions Next


© 1998-2018 The MESS Team