summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/mc6854.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/machine/mc6854.cpp')
-rw-r--r--src/devices/machine/mc6854.cpp115
1 files changed, 56 insertions, 59 deletions
diff --git a/src/devices/machine/mc6854.cpp b/src/devices/machine/mc6854.cpp
index 1164b35308e..c5789cd0e39 100644
--- a/src/devices/machine/mc6854.cpp
+++ b/src/devices/machine/mc6854.cpp
@@ -34,12 +34,13 @@
#include "emu.h"
#include "mc6854.h"
+//#define VERBOSE 1
+#include "logmacro.h"
-/******************* parameters ******************/
+/******************* parameters ******************/
-#define VERBOSE 0
#define FLAG 0x7e
@@ -47,12 +48,10 @@
#define BIT_LENGTH attotime::from_hz( 500000 )
-
-/******************* utility function and macros ********************/
-
+constexpr unsigned mc6854_device::MAX_FRAME_LENGTH;
-#define LOG(x) do { if (VERBOSE) logerror x; } while (0)
+/******************* utility function and macros ********************/
@@ -165,10 +164,10 @@ static const int word_length[4] = { 5, 6, 7, 8 };
-const device_type MC6854 = device_creator<mc6854_device>;
+DEFINE_DEVICE_TYPE(MC6854, mc6854_device, "mc6854", "Motorola MC6854 ADLC")
mc6854_device::mc6854_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
- : device_t(mconfig, MC6854, "MC6854 ADLC", tag, owner, clock, "mc6854", __FILE__),
+ : device_t(mconfig, MC6854, tag, owner, clock),
m_out_irq_cb(*this),
m_out_txd_cb(*this),
m_out_rts_cb(*this),
@@ -191,7 +190,7 @@ mc6854_device::mc6854_device(const machine_config &mconfig, const char *tag, dev
m_flen(0),
m_fpos(0)
{
- for (int i = 0; i < MC6854_FIFO_SIZE; i++)
+ for (int i = 0; i < FIFO_SIZE; i++)
{
m_tfifo[i] = 0;
m_rfifo[i] = 0;
@@ -244,7 +243,7 @@ void mc6854_device::device_start()
void mc6854_device::device_reset()
{
- LOG (( "mc6854 reset\n" ));
+ LOG( "mc6854 reset\n" );
m_cr1 = 0xc0; /* reset condition */
m_cr2 = 0;
m_cr3 = 0;
@@ -309,7 +308,7 @@ void mc6854_device::send_bits( uint32_t data, int len, int zi )
-/* CPU push -> tfifo[0] -> ... -> tfifo[MC6854_FIFO_SIZE-1] -> pop */
+/* CPU push -> tfifo[0] -> ... -> tfifo[FIFO_SIZE-1] -> pop */
void mc6854_device::tfifo_push( uint8_t data )
{
int i;
@@ -318,7 +317,7 @@ void mc6854_device::tfifo_push( uint8_t data )
return;
/* push towards the rightmost free entry */
- for ( i = MC6854_FIFO_SIZE - 1; i >= 0; i-- )
+ for ( i = FIFO_SIZE - 1; i >= 0; i-- )
{
if ( ! ( m_tfifo[ i ] & 0x100 ) )
break;
@@ -332,7 +331,7 @@ void mc6854_device::tfifo_push( uint8_t data )
/* start frame, if needed */
if ( ! m_tstate )
{
- LOG(( "%f mc6854_tfifo_push: start frame\n", machine().time().as_double() ));
+ LOG( "%f mc6854_tfifo_push: start frame\n", machine().time().as_double() );
m_tstate = 2;
send_bits( FLAG, 8, 0 );
}
@@ -345,7 +344,7 @@ void mc6854_device::tfifo_terminate( )
{
/* mark most recently pushed byte as the last one of the frame */
int i;
- for ( i = 0; i < MC6854_FIFO_SIZE; i++ )
+ for ( i = 0; i < FIFO_SIZE; i++ )
{
if ( m_tfifo[ i ] & 0x100 )
{
@@ -360,13 +359,13 @@ void mc6854_device::tfifo_terminate( )
/* call-back to refill the bit-stream from the FIFO */
TIMER_CALLBACK_MEMBER(mc6854_device::tfifo_cb)
{
- int i, data = m_tfifo[ MC6854_FIFO_SIZE - 1 ];
+ int i, data = m_tfifo[ FIFO_SIZE - 1 ];
if ( ! m_tstate )
return;
/* shift FIFO to the right */
- for ( i = MC6854_FIFO_SIZE - 1; i > 0; i-- )
+ for ( i = FIFO_SIZE - 1; i > 0; i-- )
m_tfifo[ i ] = m_tfifo[ i - 1 ];
m_tfifo[ 0 ] = 0;
@@ -381,7 +380,7 @@ TIMER_CALLBACK_MEMBER(mc6854_device::tfifo_cb)
case 2: /* 8-bit address field */
if ( ( data & 1 ) || ( ! AEX ) )
m_tstate = 3;
- LOG(( "%f mc6854_tfifo_cb: address field $%02X\n", machine().time().as_double(), data & 0xff ));
+ LOG( "%f mc6854_tfifo_cb: address field $%02X\n", machine().time().as_double(), data & 0xff );
break;
case 3: /* 8-bit control field */
@@ -391,7 +390,7 @@ TIMER_CALLBACK_MEMBER(mc6854_device::tfifo_cb)
m_tstate = 5;
else
m_tstate = 6;
- LOG(( "%f mc6854_tfifo_cb: control field $%02X\n", machine().time().as_double(), data & 0xff ));
+ LOG( "%f mc6854_tfifo_cb: control field $%02X\n", machine().time().as_double(), data & 0xff );
break;
case 4: /* 8-bit extended control field (optional) */
@@ -399,22 +398,22 @@ TIMER_CALLBACK_MEMBER(mc6854_device::tfifo_cb)
m_tstate = 5;
else
m_tstate = 6;
- LOG(( "%f mc6854_tfifo_cb: control field $%02X\n", machine().time().as_double(), data & 0xff ));
+ LOG( "%f mc6854_tfifo_cb: control field $%02X\n", machine().time().as_double(), data & 0xff );
break;
case 5: /* 8-bit logical control (optional) */
if ( ! ( data & 0x80 ) )
m_tstate = 6;
- LOG(( "%f mc6854_tfifo_cb: logical control field $%02X\n", machine().time().as_double(), data & 0xff ));
+ LOG( "%f mc6854_tfifo_cb: logical control field $%02X\n", machine().time().as_double(), data & 0xff );
break;
case 6: /* variable-length data */
blen = TWL;
- LOG(( "%f mc6854_tfifo_cb: data field $%02X, %i bits\n", machine().time().as_double(), data & 0xff, blen ));
+ LOG( "%f mc6854_tfifo_cb: data field $%02X, %i bits\n", machine().time().as_double(), data & 0xff, blen );
break;
default:
- LOG(( "%f mc6854_tfifo_cb: state=%i\n", machine().time().as_double(), m_tstate));
+ LOG( "%f mc6854_tfifo_cb: state=%i\n", machine().time().as_double(), m_tstate);
}
if ( m_flen < MAX_FRAME_LENGTH )
@@ -439,14 +438,14 @@ TIMER_CALLBACK_MEMBER(mc6854_device::tfifo_cb)
{
int len = m_flen;
- LOG(( "%f mc6854_tfifo_cb: end frame\n", machine().time().as_double() ));
+ LOG( "%f mc6854_tfifo_cb: end frame\n", machine().time().as_double() );
send_bits( 0xdeadbeef, 16, 1 ); /* send check-sum: TODO */
send_bits( FLAG, 8, 0 ); /* send closing flag */
- if ( m_tfifo[ MC6854_FIFO_SIZE - 1 ] & 0x100 )
+ if ( m_tfifo[ FIFO_SIZE - 1 ] & 0x100 )
{
/* re-open frame asap */
- LOG(( "%f mc6854_tfifo_cb: start frame\n", machine().time().as_double() ));
+ LOG( "%f mc6854_tfifo_cb: start frame\n", machine().time().as_double() );
if ( TWOINTER )
send_bits( FLAG, 8, 0 );
}
@@ -490,7 +489,7 @@ void mc6854_device::rfifo_push( uint8_t d )
m_rstate = 3;
else
m_rstate = 2;
- LOG(( "%f mc6854_rfifo_push: address field $%02X\n", machine().time().as_double(), data ));
+ LOG( "%f mc6854_rfifo_push: address field $%02X\n", machine().time().as_double(), data );
data |= 0x400; /* address marker */
break;
@@ -501,7 +500,7 @@ void mc6854_device::rfifo_push( uint8_t d )
m_rstate = 5;
else
m_rstate = 6;
- LOG(( "%f mc6854_rfifo_push: control field $%02X\n", machine().time().as_double(), data ));
+ LOG( "%f mc6854_rfifo_push: control field $%02X\n", machine().time().as_double(), data );
break;
case 4: /* 8-bit extended control field (optional) */
@@ -509,33 +508,33 @@ void mc6854_device::rfifo_push( uint8_t d )
m_rstate = 5;
else
m_rstate = 6;
- LOG(( "%f mc6854_rfifo_push: control field $%02X\n", machine().time().as_double(), data ));
+ LOG( "%f mc6854_rfifo_push: control field $%02X\n", machine().time().as_double(), data );
break;
case 5: /* 8-bit logical control (optional) */
if ( ! ( data & 0x80 ) )
m_rstate = 6;
- LOG(( "%f mc6854_rfifo_push: logical control field $%02X\n", machine().time().as_double(), data ));
+ LOG( "%f mc6854_rfifo_push: logical control field $%02X\n", machine().time().as_double(), data );
break;
case 6: /* variable-length data */
blen = RWL;
data >>= 8 - blen;
- LOG(( "%f mc6854_rfifo_push: data field $%02X, %i bits\n", machine().time().as_double(), data, blen ));
+ LOG( "%f mc6854_rfifo_push: data field $%02X, %i bits\n", machine().time().as_double(), data, blen );
break;
}
/* no further FIFO fill until FV is cleared! */
if ( m_sr2 & FV )
{
- LOG(( "%f mc6854_rfifo_push: field not pushed\n", machine().time().as_double() ));
+ LOG( "%f mc6854_rfifo_push: field not pushed\n", machine().time().as_double() );
return;
}
data |= 0x100; /* entry full marker */
/* push towards the rightmost free entry */
- for ( i = MC6854_FIFO_SIZE - 1; i >= 0; i-- )
+ for ( i = FIFO_SIZE - 1; i >= 0; i-- )
{
if ( ! ( m_rfifo[ i ] & 0x100 ) )
break;
@@ -560,7 +559,7 @@ void mc6854_device::rfifo_terminate( )
{
/* mark most recently pushed byte as the last one of the frame */
int i;
- for ( i = 0; i < MC6854_FIFO_SIZE; i++ )
+ for ( i = 0; i < FIFO_SIZE; i++ )
{
if ( m_rfifo[ i ] & 0x100 )
{
@@ -579,14 +578,14 @@ void mc6854_device::rfifo_terminate( )
/* CPU pops the FIFO */
uint8_t mc6854_device::rfifo_pop( )
{
- int i, data = m_rfifo[ MC6854_FIFO_SIZE - 1 ];
+ int i, data = m_rfifo[ FIFO_SIZE - 1 ];
/* shift FIFO to the right */
- for ( i = MC6854_FIFO_SIZE - 1; i > 0; i -- )
+ for ( i = FIFO_SIZE - 1; i > 0; i -- )
m_rfifo[ i ] = m_rfifo[ i - 1 ];
m_rfifo[ 0 ] = 0;
- if ( m_rfifo[ MC6854_FIFO_SIZE - 1 ] & 0x200 )
+ if ( m_rfifo[ FIFO_SIZE - 1 ] & 0x200 )
{
/* last byte in frame */
m_sr2 |= FV; /* TODO: check CRC & set ERR instead of FV if error*/
@@ -625,7 +624,7 @@ WRITE_LINE_MEMBER( mc6854_device::set_rx )
{
/* only in-frame abort */
m_sr2 |= RABT;
- LOG(( "%f mc6854_receive_bit: abort\n", machine().time().as_double() ));
+ LOG( "%f mc6854_receive_bit: abort\n", machine().time().as_double() );
}
}
else
@@ -655,7 +654,7 @@ WRITE_LINE_MEMBER( mc6854_device::set_rx )
if ( m_rsize >= fieldlen + 24 ) /* last field */
rfifo_push( m_rreg );
rfifo_terminate( );
- LOG(( "%f mc6854_receive_bit: end of frame\n", machine().time().as_double() ));
+ LOG( "%f mc6854_receive_bit: end of frame\n", machine().time().as_double() );
}
m_rones = 0;
m_rstate = 1;
@@ -751,13 +750,13 @@ void mc6854_device::update_sr2( )
{
/* update RDA */
m_sr2 |= RDA2;
- if ( ! (m_rfifo[ MC6854_FIFO_SIZE - 1 ] & 0x100) )
+ if ( ! (m_rfifo[ FIFO_SIZE - 1 ] & 0x100) )
m_sr2 &= ~RDA2;
- else if ( TWOBYTES && ! (m_tfifo[ MC6854_FIFO_SIZE - 2 ] & 0x100) )
+ else if ( TWOBYTES && ! (m_tfifo[ FIFO_SIZE - 2 ] & 0x100) )
m_sr2 &= ~RDA2;
/* update AP */
- if ( m_rfifo[ MC6854_FIFO_SIZE - 1 ] & 0x400 )
+ if ( m_rfifo[ FIFO_SIZE - 1 ] & 0x400 )
m_sr2 |= AP;
else
m_sr2 &= ~AP;
@@ -816,30 +815,30 @@ READ8_MEMBER( mc6854_device::read )
{
case 0: /* status register 1 */
update_sr1( );
- LOG(( "%f %s mc6854_r: get SR1=$%02X (rda=%i,s2rq=%i,fd=%i,cts=%i,tu=%i,tdra=%i,irq=%i)\n",
+ LOG( "%f %s mc6854_r: get SR1=$%02X (rda=%i,s2rq=%i,fd=%i,cts=%i,tu=%i,tdra=%i,irq=%i)\n",
space.machine().time().as_double(), machine().describe_context(), m_sr1,
( m_sr1 & RDA) ? 1 : 0, ( m_sr1 & S2RQ) ? 1 : 0,
( m_sr1 & FD ) ? 1 : 0, ( m_sr1 & CTS ) ? 1 : 0,
( m_sr1 & TU ) ? 1 : 0, ( m_sr1 & TDRA) ? 1 : 0,
- ( m_sr1 & IRQ) ? 1 : 0 ));
+ ( m_sr1 & IRQ) ? 1 : 0 );
return m_sr1;
case 1: /* status register 2 */
update_sr2( );
- LOG(( "%f %s mc6854_r: get SR2=$%02X (ap=%i,fv=%i,ridle=%i,rabt=%i,err=%i,dcd=%i,ovrn=%i,rda2=%i)\n",
+ LOG( "%f %s mc6854_r: get SR2=$%02X (ap=%i,fv=%i,ridle=%i,rabt=%i,err=%i,dcd=%i,ovrn=%i,rda2=%i)\n",
space.machine().time().as_double(), machine().describe_context(), m_sr2,
( m_sr2 & AP ) ? 1 : 0, ( m_sr2 & FV ) ? 1 : 0,
( m_sr2 & RIDLE) ? 1 : 0, ( m_sr2 & RABT) ? 1 : 0,
( m_sr2 & ERR ) ? 1 : 0, ( m_sr2 & DCD ) ? 1 : 0,
- ( m_sr2 & OVRN ) ? 1 : 0, ( m_sr2 & RDA2) ? 1 : 0 ));
+ ( m_sr2 & OVRN ) ? 1 : 0, ( m_sr2 & RDA2) ? 1 : 0 );
return m_sr2;
case 2: /* receiver data register */
case 3:
{
uint8_t data = rfifo_pop( );
- LOG(( "%f %s mc6854_r: get data $%02X\n",
- space.machine().time().as_double(), machine().describe_context(), data ));
+ LOG( "%f %s mc6854_r: get data $%02X\n",
+ space.machine().time().as_double(), machine().describe_context(), data );
return data;
}
@@ -857,13 +856,12 @@ WRITE8_MEMBER( mc6854_device::write )
{
case 0: /* control register 1 */
m_cr1 = data;
- LOG(( "%f %s mc6854_w: set CR1=$%02X (ac=%i,irq=%c%c,%sreset=%c%c)\n",
+ LOG( "%f %s mc6854_w: set CR1=$%02X (ac=%i,irq=%c%c,%sreset=%c%c)\n",
space.machine().time().as_double(), machine().describe_context(), m_cr1,
AC ? 1 : 0,
RIE ? 'r' : '-', TIE ? 't' : '-',
DISCONTINUE ? "discontinue," : "",
- RRESET ? 'r' : '-', TRESET ? 't' : '-'
- ));
+ RRESET ? 'r' : '-', TRESET ? 't' : '-' );
if ( m_cr1 & 0xc )
logerror( "%s mc6854 DMA not handled (CR1=$%02X)\n",
machine().describe_context(), m_cr1 );
@@ -894,12 +892,11 @@ WRITE8_MEMBER( mc6854_device::write )
{
/* control register 3 */
m_cr3 = data;
- LOG(( "%f %s mc6854_w: set CR3=$%02X (lcf=%i,aex=%i,idl=%i,fdse=%i,loop=%i,tst=%i,dtr=%i)\n",
+ LOG( "%f %s mc6854_w: set CR3=$%02X (lcf=%i,aex=%i,idl=%i,fdse=%i,loop=%i,tst=%i,dtr=%i)\n",
space.machine().time().as_double(), machine().describe_context(), m_cr3,
LCF ? (CEX ? 16 : 8) : 0, AEX ? 1 : 0,
IDL0 ? 0 : 1, FDSE ? 1 : 0, LOOP ? 1 : 0,
- TST ? 1 : 0, DTR ? 1 : 0
- ));
+ TST ? 1 : 0, DTR ? 1 : 0 );
if ( LOOP )
logerror( "%s mc6854 loop mode not handled (CR3=$%02X)\n", machine().describe_context(), m_cr3 );
if ( TST )
@@ -912,12 +909,12 @@ WRITE8_MEMBER( mc6854_device::write )
{
/* control register 2 */
m_cr2 = data;
- LOG(( "%f %s mc6854_w: set CR2=$%02X (pse=%i,bytes=%i,fmidle=%i,%s,tlast=%i,clr=%c%c,rts=%i)\n",
+ LOG( "%f %s mc6854_w: set CR2=$%02X (pse=%i,bytes=%i,fmidle=%i,%s,tlast=%i,clr=%c%c,rts=%i)\n",
space.machine().time().as_double(), machine().describe_context(), m_cr2,
PSE ? 1 : 0, TWOBYTES ? 2 : 1, FMIDLE ? 1 : 0,
FCTDRA ? "fc" : "tdra", TLAST ? 1 : 0,
data & 0x20 ? 'r' : '-', data & 0x40 ? 't' : '-',
- RTS ? 1 : 0 ));
+ RTS ? 1 : 0 );
if ( PSE )
logerror( "%s mc6854 status prioritization not handled (CR2=$%02X)\n", machine().describe_context(), m_cr2 );
if ( TLAST )
@@ -943,7 +940,7 @@ WRITE8_MEMBER( mc6854_device::write )
break;
case 2: /* transmitter data: continue data */
- LOG(( "%f %smc6854_w: push data=$%02X\n", space.machine().time().as_double(), machine().describe_context(), data ));
+ LOG( "%f %smc6854_w: push data=$%02X\n", space.machine().time().as_double(), machine().describe_context(), data );
tfifo_push( data );
break;
@@ -952,11 +949,11 @@ WRITE8_MEMBER( mc6854_device::write )
{
/* control register 4 */
m_cr4 = data;
- LOG(( "%f %s mc6854_w: set CR4=$%02X (interframe=%i,tlen=%i,rlen=%i,%s%s)\n", space.machine().time().as_double(), machine().describe_context(), m_cr4,
+ LOG( "%f %s mc6854_w: set CR4=$%02X (interframe=%i,tlen=%i,rlen=%i,%s%s)\n", space.machine().time().as_double(), machine().describe_context(), m_cr4,
TWOINTER ? 2 : 1,
TWL, RWL,
ABT ? ( ABTEX ? "abort-ext," : "abort,") : "",
- NRZ ? "nrz" : "nrzi" ));
+ NRZ ? "nrz" : "nrzi" );
if ( ABT )
{
m_tstate = 0;
@@ -967,7 +964,7 @@ WRITE8_MEMBER( mc6854_device::write )
else
{
/* transmitter data: last data */
- LOG(( "%f %s mc6854_w: push last-data=$%02X\n", space.machine().time().as_double(), machine().describe_context(), data ));
+ LOG( "%f %s mc6854_w: push last-data=$%02X\n", space.machine().time().as_double(), machine().describe_context(), data );
tfifo_push( data );
tfifo_terminate( );
}