summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/tms9901.cpp
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2017-05-07 23:18:47 +1000
committer Vas Crabb <vas@vastheman.com>2017-05-14 21:44:11 +1000
commit0f0d39ef81562c75e79176dd3bebb1e491ca39d5 (patch)
tree201cee7fdf55ee800f83859a92efd2cfe66cf2b3 /src/devices/machine/tms9901.cpp
parente6c4be2b4d71c7a6c95be0bae111eb416ff0f9e7 (diff)
Move static data out of devices into the device types. This is a significant change, so please pay attention.
The core changes are: * Short name, full name and source file are no longer members of device_t, they are part of the device type * MACHINE_COFIG_START no longer needs a driver class * MACHINE_CONFIG_DERIVED_CLASS is no longer necessary * Specify the state class you want in the GAME/COMP/CONS line * The compiler will work out the base class where the driver init member is declared * There is one static device type object per driver rather than one per machine configuration Use DECLARE_DEVICE_TYPE or DECLARE_DEVICE_TYPE_NS to declare device type. * DECLARE_DEVICE_TYPE forward-declares teh device type and class, and declares extern object finders. * DECLARE_DEVICE_TYPE_NS is for devices classes in namespaces - it doesn't forward-declare the device type. Use DEFINE_DEVICE_TYPE or DEFINE_DEVICE_TYPE_NS to define device types. * These macros declare storage for the static data, and instantiate the device type and device finder templates. The rest of the changes are mostly just moving stuff out of headers that shouldn't be there, renaming stuff for consistency, and scoping stuff down where appropriate. Things I've actually messed with substantially: * More descriptive names for a lot of devices * Untangled the fantasy sound from the driver state, which necessitates breaking up sound/flip writes * Changed DECO BSMT2000 ready callback into a device delegate * Untangled Microprose 3D noise from driver state * Used object finders for CoCo multipak, KC85 D002, and Irem sound subdevices * Started to get TI-99 stuff out of the TI-990 directory and arrange bus devices properly * Started to break out common parts of Samsung ARM SoC devices * Turned some of FM, SID, SCSP DSP, EPIC12 and Voodoo cores into something resmbling C++ * Tried to make Z180 table allocation/setup a bit safer * Converted generic keyboard/terminal to not use WRITE8 - space/offset aren't relevant * Dynamically allocate generic terminal buffer so derived devices (e.g. teleprinter) can specify size * Imporved encapsulation of Z80DART channels * Refactored the SPC7110 bit table generator loop to make it more readable * Added wrappers for SNES PPU operations so members can be made protected * Factored out some boilerplate for YM chips with PSG * toaplan2 gfx * stic/intv resolution * Video System video * Out Run/Y-board sprite alignment * GIC video hookup * Amstrad CPC ROM box members * IQ151 ROM cart region * MSX cart IRQ callback resolution time * SMS passthrough control devices starting subslots I've smoke-tested several drivers, but I've probably missed something. Things I've missed will likely blow up spectacularly with failure to bind errors and the like. Let me know if there's more subtle breakage (could have happened in FM or Voodoo). And can everyone please, please try to keep stuff clean. In particular, please stop polluting the global namespace. Keep things out of headers that don't need to be there, and use things that can be scoped down rather than macros. It feels like an uphill battle trying to get this stuff under control while more of it's added.
Diffstat (limited to 'src/devices/machine/tms9901.cpp')
-rw-r--r--src/devices/machine/tms9901.cpp275
1 files changed, 98 insertions, 177 deletions
diff --git a/src/devices/machine/tms9901.cpp b/src/devices/machine/tms9901.cpp
index c27d790d375..b0d557b3abf 100644
--- a/src/devices/machine/tms9901.cpp
+++ b/src/devices/machine/tms9901.cpp
@@ -119,40 +119,31 @@ TODO: Tests on a real machine
*****************************************************************************/
-#include <math.h>
#include "emu.h"
-
#include "tms9901.h"
-/*
- Debugging flags.
-*/
-#define TRACE_PINS 0
-#define TRACE_CLOCK 0
-#define TRACE_MODE 0
+#include <math.h>
+
+#define LOG_GENERAL (1U << 0)
+#define LOG_PINS (1U << 1)
+#define LOG_CLOCK (1U << 2)
+#define LOG_MODE (1U << 3)
+
+//#define VERBOSE (LOG_PINS | LOG_CLOCK | LOG_MODE)
+#include "logmacro.h"
+
+#define LOGPINS(...) LOGMASKED(LOG_PINS, __VA_ARGS__)
+#define LOGCLOCK(...) LOGMASKED(LOG_CLOCK, __VA_ARGS__)
+#define LOGMODE(...) LOGMASKED(LOG_MODE, __VA_ARGS__)
+
/*
Constructor
*/
tms9901_device::tms9901_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
-: device_t(mconfig, TMS9901, "TMS9901 Programmable System Interface", tag, owner, clock, "tms9901", __FILE__),
+: device_t(mconfig, TMS9901, tag, owner, clock),
m_read_block(*this),
- m_write_p0(*this),
- m_write_p1(*this),
- m_write_p2(*this),
- m_write_p3(*this),
- m_write_p4(*this),
- m_write_p5(*this),
- m_write_p6(*this),
- m_write_p7(*this),
- m_write_p8(*this),
- m_write_p9(*this),
- m_write_p10(*this),
- m_write_p11(*this),
- m_write_p12(*this),
- m_write_p13(*this),
- m_write_p14(*this),
- m_write_p15(*this),
+ m_write_p{{*this},{*this},{*this},{*this},{*this},{*this},{*this},{*this},{*this},{*this},{*this},{*this},{*this},{*this},{*this},{*this}},
m_interrupt(*this)
{
}
@@ -160,7 +151,7 @@ tms9901_device::tms9901_device(const machine_config &mconfig, const char *tag, d
/*
should be called after any change to int_state or enabled_ints.
*/
-void tms9901_device::field_interrupts(void)
+void tms9901_device::field_interrupts()
{
int current_ints;
@@ -171,13 +162,13 @@ void tms9901_device::field_interrupts(void)
// if timer is enabled, INT3 pin is overridden by timer
if (m_timer_int_pending)
{
- if (TRACE_CLOCK) logerror("%s: timer fires\n", tag());
- current_ints |= TMS9901_INT3;
+ LOGCLOCK("timer fires\n");
+ current_ints |= INT3;
}
else
{
- if (TRACE_CLOCK) logerror("%s: timer clear\n", tag());
- current_ints &= ~TMS9901_INT3;
+ LOGCLOCK("timer clear\n");
+ current_ints &= ~INT3;
}
}
@@ -241,7 +232,7 @@ void tms9901_device::set_single_int(int pin_number, int state)
/*
load the content of m_clock_register into the decrementer
*/
-void tms9901_device::timer_reload(void)
+void tms9901_device::timer_reload()
{
if (m_clock_register != 0)
{ /* reset clock interval */
@@ -292,7 +283,7 @@ READ8_MEMBER( tms9901_device::read )
// INTx levels that have been signaled via the set_single_int method.
// This may mean that those levels must be latched by the callee.
if (!m_read_block.isnull())
- answer |= m_read_block(TMS9901_CB_INT7);
+ answer |= m_read_block(CB_INT7);
// Remove the bits that are set as outputs (can only be INT7*)
answer &= ~m_pio_direction_mirror;
@@ -300,7 +291,7 @@ READ8_MEMBER( tms9901_device::read )
// Set those bits here
answer |= (m_pio_output_mirror & m_pio_direction_mirror) & 0xFF;
}
- if (TRACE_PINS) logerror("%s: input on lines INT7..CB = %02x\n", tag(), answer);
+ LOGPINS("input on lines INT7..CB = %02x\n", answer);
break;
case 1:
if (m_clock_mode)
@@ -314,13 +305,13 @@ READ8_MEMBER( tms9901_device::read )
{
// See above concerning the INT levels.
if (!m_read_block.isnull())
- answer |= m_read_block(TMS9901_INT8_INT15);
+ answer |= m_read_block(INT8_INT15);
// Remove the bits that are set as outputs (can be any line)
answer &= ~(m_pio_direction_mirror >> 8);
answer |= (m_pio_output_mirror & m_pio_direction_mirror) >> 8;
}
- if (TRACE_PINS) logerror("%s: input on lines INT15..int8_t = %02x\n", tag(), answer);
+ LOGPINS("input on lines INT15..int8_t = %02x\n", answer);
break;
case 2:
/* exit timer mode */
@@ -328,26 +319,26 @@ READ8_MEMBER( tms9901_device::read )
// m_clock_mode = false;
if (!m_read_block.isnull())
- answer = m_read_block(TMS9901_P0_P7);
+ answer = m_read_block(P0_P7);
else
answer = 0;
answer &= ~m_pio_direction;
answer |= (m_pio_output & m_pio_direction) & 0xFF;
- if (TRACE_PINS) logerror("%s: input on lines P7..P0 = %02x\n", tag(), answer);
+ LOGPINS("input on lines P7..P0 = %02x\n", answer);
break;
case 3:
// MZ: see above
// m_clock_mode = false;
if (!m_read_block.isnull())
- answer = m_read_block(TMS9901_P8_P15);
+ answer = m_read_block(P8_P15);
else
answer = 0;
answer &= ~(m_pio_direction >> 8);
answer |= (m_pio_output & m_pio_direction) >> 8;
- if (TRACE_PINS) logerror("%s: input on lines P15..P8 = %02x\n", tag(), answer);
+ LOGPINS("input on lines P15..P8 = %02x\n", answer);
break;
}
@@ -376,7 +367,7 @@ WRITE8_MEMBER ( tms9901_device::write )
if (offset >= 0x10)
{
int pin = offset & 0x0F;
- if (TRACE_PINS) logerror("%s: output on P%d = %d\n", tag(), pin, data);
+ LOGPINS("output on P%d = %d\n", pin, data);
int bit = (1 << pin);
@@ -408,74 +399,21 @@ WRITE8_MEMBER ( tms9901_device::write )
m_pio_output_mirror &= ~mirror_bit;
}
- switch (offset)
- {
- case 0x10:
- if (!m_write_p0.isnull()) m_write_p0(data);
- break;
- case 0x11:
- if (!m_write_p1.isnull()) m_write_p1(data);
- break;
- case 0x12:
- if (!m_write_p2.isnull()) m_write_p2(data);
- break;
- case 0x13:
- if (!m_write_p3.isnull()) m_write_p3(data);
- break;
- case 0x14:
- if (!m_write_p4.isnull()) m_write_p4(data);
- break;
- case 0x15:
- if (!m_write_p5.isnull()) m_write_p5(data);
- break;
- case 0x16:
- if (!m_write_p6.isnull()) m_write_p6(data);
- break;
- case 0x17:
- if (!m_write_p7.isnull()) m_write_p7(data);
- break;
- case 0x18:
- if (!m_write_p8.isnull()) m_write_p8(data);
- break;
- case 0x19:
- if (!m_write_p9.isnull()) m_write_p9(data);
- break;
- case 0x1A:
- if (!m_write_p10.isnull()) m_write_p10(data);
- break;
- case 0x1B:
- if (!m_write_p11.isnull()) m_write_p11(data);
- break;
- case 0x1C:
- if (!m_write_p12.isnull()) m_write_p12(data);
- break;
- case 0x1D:
- if (!m_write_p13.isnull()) m_write_p13(data);
- break;
- case 0x1E:
- if (!m_write_p14.isnull()) m_write_p14(data);
- break;
- case 0x1F:
- if (!m_write_p15.isnull()) m_write_p15(data);
- break;
-
- }
- return;
+ m_write_p[offset - 0x10](data);
}
-
- if (offset == 0)
+ else if (offset == 0)
{
// Write to control bit (CB)
if (data == 0)
{
// Switch to interrupt mode; quit clock mode
m_clock_mode = false;
- if (TRACE_MODE) logerror("%s: int mode\n", tag());
+ LOGMODE("int mode\n");
}
else
{
m_clock_mode = true;
- if (TRACE_MODE) logerror("%s: clock mode\n", tag());
+ LOGMODE("clock mode\n");
// we are switching to clock mode: latch the current value of
// the decrementer register
if (m_clock_register != 0)
@@ -484,73 +422,70 @@ WRITE8_MEMBER ( tms9901_device::write )
m_clock_read_register = 0; /* timer inactive... */
}
}
- else
+ else if (offset == 0x0f)
{
- if (offset == 0x0f)
- {
- if (m_clock_mode)
- { /* in clock mode this is the soft reset bit */
- if (!data)
- { // TMS9901 soft reset (RST2*)
- // Spec: "Writing a 0 to bit 15 while in the clock mode executes a soft reset on the I/O pins.
- // [...] RST2* will program all ports to the input mode"
- m_pio_direction = 0;
- m_pio_direction_mirror = 0;
-
- // "RST1* (power-up reset) will reset all mask bits low."
- // Spec is not clear on whether the mask bits are also reset by RST2*
- // TODO: Check on a real machine. (I'd guess from the text they are not touched)
- m_enabled_ints = 0;
- if (TRACE_MODE) logerror("%s: Soft reset (RST2*)\n", tag());
- }
- }
- else
- { /* modify interrupt enable mask */
- if (data)
- m_enabled_ints |= 0x4000; /* set bit */
- else
- m_enabled_ints &= ~0x4000; /* unset bit */
-
- if (TRACE_PINS) logerror("%s: interrupts = %04x\n", tag(), m_enabled_ints);
- field_interrupts(); /* changed interrupt state */
+ if (m_clock_mode)
+ { /* in clock mode this is the soft reset bit */
+ if (!data)
+ { // TMS9901 soft reset (RST2*)
+ // Spec: "Writing a 0 to bit 15 while in the clock mode executes a soft reset on the I/O pins.
+ // [...] RST2* will program all ports to the input mode"
+ m_pio_direction = 0;
+ m_pio_direction_mirror = 0;
+
+ // "RST1* (power-up reset) will reset all mask bits low."
+ // Spec is not clear on whether the mask bits are also reset by RST2*
+ // TODO: Check on a real machine. (I'd guess from the text they are not touched)
+ m_enabled_ints = 0;
+ LOGMODE("Soft reset (RST2*)\n");
}
}
else
- {
- // write one bit to 9901 (bits 1-14)
- //
- // m_clock_mode==false ? Disable/Enable an interrupt
- // : Bit in clock interval
- //
- // offset is the index of the modified bit of register (-> interrupt number -1)
- if (m_clock_mode)
- { /* modify clock interval */
- int bit = 1 << ((offset & 0x0F) - 1); /* corresponding mask */
-
- if (data)
- m_clock_register |= bit; /* set bit */
- else
- m_clock_register &= ~bit; /* clear bit */
-
- /* reset clock timer (page 8) */
- if (TRACE_CLOCK) logerror("%s: clock register = %04x\n", tag(), m_clock_register);
- timer_reload();
- }
+ { /* modify interrupt enable mask */
+ if (data)
+ m_enabled_ints |= 0x4000; /* set bit */
+ else
+ m_enabled_ints &= ~0x4000; /* unset bit */
+
+ LOGMODE("interrupts = %04x\n", m_enabled_ints);
+ field_interrupts(); /* changed interrupt state */
+ }
+ }
+ else
+ {
+ // write one bit to 9901 (bits 1-14)
+ //
+ // m_clock_mode==false ? Disable/Enable an interrupt
+ // : Bit in clock interval
+ //
+ // offset is the index of the modified bit of register (-> interrupt number -1)
+ if (m_clock_mode)
+ { /* modify clock interval */
+ int bit = 1 << ((offset & 0x0F) - 1); /* corresponding mask */
+
+ if (data)
+ m_clock_register |= bit; /* set bit */
else
- { /* modify interrupt enable mask */
- int bit = 1 << (offset & 0x0F); /* corresponding mask */
+ m_clock_register &= ~bit; /* clear bit */
- if (data)
- m_enabled_ints |= bit; /* set bit */
- else
- m_enabled_ints &= ~bit; /* unset bit */
+ /* reset clock timer (page 8) */
+ LOGCLOCK("clock register = %04x\n", m_clock_register);
+ timer_reload();
+ }
+ else
+ { /* modify interrupt enable mask */
+ int bit = 1 << (offset & 0x0F); /* corresponding mask */
- if (offset == 3)
- m_timer_int_pending = false; /* SBO 3 clears pending timer interrupt (??) */
+ if (data)
+ m_enabled_ints |= bit; /* set bit */
+ else
+ m_enabled_ints &= ~bit; /* unset bit */
- if (TRACE_MODE) logerror("%s: enabled interrupts = %04x\n", tag(), m_enabled_ints);
- field_interrupts(); /* changed interrupt state */
- }
+ if (offset == 3)
+ m_timer_int_pending = false; /* SBO 3 clears pending timer interrupt (??) */
+
+ LOGMODE("enabled interrupts = %04x\n");
+ field_interrupts(); /* changed interrupt state */
}
}
}
@@ -566,7 +501,7 @@ void tms9901_device::device_timer(emu_timer &timer, device_timer_id id, int para
if (id==DECREMENTER) // we have only that one
{
m_decrementer_value--;
- if (TRACE_CLOCK) logerror("%s: decrementer = %d\n", tag(), m_decrementer_value);
+ LOGCLOCK("decrementer = %d\n", m_decrementer_value);
if (m_decrementer_value<=0)
{
m_timer_int_pending = true; // decrementer interrupt requested
@@ -580,7 +515,7 @@ void tms9901_device::device_timer(emu_timer &timer, device_timer_id id, int para
device_stop - device-specific stop
-------------------------------------------------*/
-void tms9901_device::device_stop(void)
+void tms9901_device::device_stop()
{
}
@@ -588,7 +523,7 @@ void tms9901_device::device_stop(void)
device_reset - device-specific reset
-------------------------------------------------*/
-void tms9901_device::device_reset(void)
+void tms9901_device::device_reset()
{
do_reset();
}
@@ -628,29 +563,15 @@ void tms9901_device::do_reset()
device_start - device-specific startup
-------------------------------------------------*/
-void tms9901_device::device_start(void)
+void tms9901_device::device_start()
{
m_decrementer = timer_alloc(DECREMENTER);
m_decrementer->adjust(attotime::from_hz(clock() / 64.), 0, attotime::from_hz(clock() / 64.));
m_decrementer->enable(false);
m_read_block.resolve();
- m_write_p0.resolve();
- m_write_p1.resolve();
- m_write_p2.resolve();
- m_write_p3.resolve();
- m_write_p4.resolve();
- m_write_p5.resolve();
- m_write_p6.resolve();
- m_write_p7.resolve();
- m_write_p8.resolve();
- m_write_p9.resolve();
- m_write_p10.resolve();
- m_write_p11.resolve();
- m_write_p12.resolve();
- m_write_p13.resolve();
- m_write_p14.resolve();
- m_write_p15.resolve();
+ for (auto &cb : m_write_p)
+ cb.resolve_safe();
m_interrupt.resolve();
m_clock_register = 0;
@@ -670,4 +591,4 @@ void tms9901_device::device_start(void)
save_item(NAME(m_clock_read_register));
}
-const device_type TMS9901 = device_creator<tms9901_device>;
+DEFINE_DEVICE_TYPE(TMS9901, tms9901_device, "tms9901", "TMS9901 Programmable System Interface")