diff options
Diffstat (limited to 'src/devices/bus/snes_ctrl/bcbattle.cpp')
-rw-r--r-- | src/devices/bus/snes_ctrl/bcbattle.cpp | 67 |
1 files changed, 30 insertions, 37 deletions
diff --git a/src/devices/bus/snes_ctrl/bcbattle.cpp b/src/devices/bus/snes_ctrl/bcbattle.cpp index 138a4ef4669..c5d78bc04b3 100644 --- a/src/devices/bus/snes_ctrl/bcbattle.cpp +++ b/src/devices/bus/snes_ctrl/bcbattle.cpp @@ -26,47 +26,40 @@ void snes_bcbattle_device::device_add_mconfig(machine_config &config) } -//------------------------------------------------- -// device_timer - handler timer events -//------------------------------------------------- - -// This part is the hacky replacement for the real Barcode unit [shared with NES implementation]: +// This part is a hacky replacement for the real Barcode unit [shared with NES implementation]: // code periodically checks whether a new code has been scanned and it moves it to the // m_current_barcode array -void snes_bcbattle_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) +TIMER_CALLBACK_MEMBER(snes_bcbattle_device::scan_tick) { - if (id == TIMER_BATTLER) + int old = m_new_code; + m_new_code = m_reader->get_pending_code(); + // has something new been scanned? + if (old < m_new_code) { - int old = m_new_code; - m_new_code = m_reader->get_pending_code(); - // has something new been scanned? - if (old < m_new_code) + if (m_reader->get_byte_length() == 13) { - 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; + 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; } } @@ -98,7 +91,7 @@ void snes_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(TIMER_BATTLER); + battler_timer = timer_alloc(FUNC(snes_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)); @@ -121,7 +114,7 @@ void snes_bcbattle_device::device_reset() m_transmitting = 0; m_cur_bit = 0; m_cur_byte = 0; - memset(m_current_barcode, 0, ARRAY_LENGTH(m_current_barcode)); + std::fill(std::begin(m_current_barcode), std::end(m_current_barcode), 0); } |