summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/atapicdr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/machine/atapicdr.cpp')
-rw-r--r--src/devices/machine/atapicdr.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/devices/machine/atapicdr.cpp b/src/devices/machine/atapicdr.cpp
index c13b6ff001e..33cb0cb154e 100644
--- a/src/devices/machine/atapicdr.cpp
+++ b/src/devices/machine/atapicdr.cpp
@@ -30,11 +30,11 @@ atapi_fixed_cdrom_device::atapi_fixed_cdrom_device(const machine_config &mconfig
// device_add_mconfig - add device configuration
//-------------------------------------------------
-MACHINE_CONFIG_START(atapi_cdrom_device::device_add_mconfig)
- MCFG_CDROM_ADD("image")
- MCFG_CDROM_INTERFACE("cdrom")
- MCFG_DEVICE_ADD("cdda", CDDA)
-MACHINE_CONFIG_END
+void atapi_cdrom_device::device_add_mconfig(machine_config &config)
+{
+ CDROM(config, "image").set_interface("cdrom");
+ CDDA(config, "cdda");
+}
void atapi_cdrom_device::device_start()
{
08'>108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
// license:BSD-3-Clause
// copyright-holders:Fabio Priuli
/**********************************************************************

    Nintendo Family Computer - Epoch Barcode Battler

    TODO: this should be actually emulated as a standalone system with
    a few 7segments LEDs, once we get a dump of its BIOS
    At the moment we only emulated the connection with a Famicom

**********************************************************************/

#include "emu.h"
#include "bcbattle.h"

//**************************************************************************
//  DEVICE DEFINITIONS
//**************************************************************************

DEFINE_DEVICE_TYPE(NES_BARCODE_BATTLER, nes_bcbattle_device, "nes_bcbattle", "Epoch Barcode Battler (FC)")


void nes_bcbattle_device::device_add_mconfig(machine_config &config)
{
	BARCODE_READER(config, "battler");
}


//-------------------------------------------------
//  scan_tick - periodic scan kludge
//-------------------------------------------------

// This part is the hacky replacement for the real Barcode unit [shared with SNES implementation]:
// code periodically checks whether a new code has been scanned and it moves it to the
// m_current_barcode array
TIMER_CALLBACK_MEMBER(nes_bcbattle_device::scan_tick)
{
	int old = m_new_code;
	// has something new been scanned?
	if (old < m_reader->get_pending_code())
	{
		if (m_reader->get_byte_length() == 13)
		{
			for (int i = 0; i < 13; i++)
				m_current_barcode[i] = m_reader->read_code() + '0';
		}
		else if (m_reader->get_byte_length() == 8)
		{
			for (int i = 0; i < 5; i++)
				m_current_barcode[i] = 0x20;
			for (int i = 5; i < 13; i++)
				m_current_barcode[i] = m_reader->read_code() + '0';
		}
		// read one more, to reset the internal byte counter
		m_reader->read_code();

		// the string "SUNSOFT" is accepted as well by Barcode World
		m_current_barcode[13] = 'E';
		m_current_barcode[14] = 'P';
		m_current_barcode[15] = 'O';
		m_current_barcode[16] = 'C';
		m_current_barcode[17] = 'H';
		m_current_barcode[18] = 0x0d;
		m_current_barcode[19] = 0x0a;
		m_pending_code = 1;
	}
	m_new_code = m_reader->get_pending_code();
}

//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

//-------------------------------------------------
//  nes_bcbattle_device - constructor
//-------------------------------------------------

nes_bcbattle_device::nes_bcbattle_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: device_t(mconfig, NES_BARCODE_BATTLER, tag, owner, clock)
	, device_nes_control_port_interface(mconfig, *this)
	, m_reader(*this, "battler")
	, m_pending_code(0), m_new_code(0), m_transmitting(0), m_cur_bit(0), m_cur_byte(0), battler_timer(nullptr)
{
}


//-------------------------------------------------
//  device_start
//-------------------------------------------------

void nes_bcbattle_device::device_start()
{
	// lacking emulation of the standalone Barcode Battler, we refresh periodically the input from the reader
	// proper emulation would have the standalone unit acknowledging that a new barcode has been scanned
	// and sending the proper serial bits, instead of our read_current_bit() function!
	battler_timer = timer_alloc(FUNC(nes_bcbattle_device::scan_tick), this);
	battler_timer->adjust(attotime::zero, 0, machine().device<cpu_device>("maincpu")->cycles_to_attotime(1000));

	save_item(NAME(m_current_barcode));
	save_item(NAME(m_new_code));
	save_item(NAME(m_pending_code));
	save_item(NAME(m_transmitting));
	save_item(NAME(m_cur_bit));
	save_item(NAME(m_cur_byte));
}


//-------------------------------------------------
//  device_reset
//-------------------------------------------------

void nes_bcbattle_device::device_reset()
{
	m_pending_code = 0;
	m_new_code = 0;
	m_transmitting = 0;
	m_cur_bit = 0;
	m_cur_byte = 0;
	std::fill(std::begin(m_current_barcode), std::end(m_current_barcode), 0);
}


//-------------------------------------------------
//  read
//-------------------------------------------------

int nes_bcbattle_device::read_current_bit()
{
	if (m_pending_code && !m_transmitting)
	{
		// we start with 1
		m_transmitting = 1;
		m_cur_byte = 0;
		m_cur_bit = 0;
		return 1;
	}

	if (m_transmitting)
	{
		if (m_cur_bit == 0)
		{
			m_cur_bit++;
			return 1;
		}
		if (m_cur_bit < 9)
		{
			int bit = (BIT(m_current_barcode[m_cur_byte], m_cur_bit - 1)) ^ 1;
			m_cur_bit++;
			return bit;
		}
		if (m_cur_bit == 9)
		{
			m_cur_bit = 0;
			//printf("%X ", m_current_barcode[m_cur_byte]);
			m_cur_byte++;
			if (m_cur_byte == 20)
			{
				m_cur_byte = 0;
				m_transmitting = 0;
				m_pending_code = 0;
			}
			return 0;
		}
	}

	return 0;
}

uint8_t nes_bcbattle_device::read_exp(offs_t offset)
{
	uint8_t ret = 0;
	if (offset == 1)    //$4017
	{
		ret |= read_current_bit() << 2;
	}

	return ret;
}