From 7c46c30c8073eb0941e89180cd4c3305cf98cca0 Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Fri, 7 Jul 2017 06:51:38 -0400 Subject: [CoCo] Minor refactoring; better usage of accessors for maincpu, maincpu address space and PIA devices (nw) --- src/mame/includes/coco.h | 1 + src/mame/machine/coco.cpp | 45 +++++++++++++++++++++------------------------ 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/mame/includes/coco.h b/src/mame/includes/coco.h index d262650445d..db443136174 100644 --- a/src/mame/includes/coco.h +++ b/src/mame/includes/coco.h @@ -153,6 +153,7 @@ protected: // accessors cpu_device &maincpu() { return *m_maincpu; } + address_space &cpu_address_space() { return maincpu().space(); } pia6821_device &pia_0() { return *m_pia_0; } pia6821_device &pia_1() { return *m_pia_1; } cococart_slot_device &cococart() { return *m_cococart; } diff --git a/src/mame/machine/coco.cpp b/src/mame/machine/coco.cpp index 7abc1647df6..6de238dadbc 100644 --- a/src/mame/machine/coco.cpp +++ b/src/mame/machine/coco.cpp @@ -268,25 +268,22 @@ uint8_t coco_state::floating_bus_read() // prevent stack overflows m_in_floating_bus_read = true; - // set up the ability to read address spaces - address_space &program = m_maincpu->space(AS_PROGRAM); - // get the previous and current PC uint16_t prev_pc = m_maincpu->pcbase(); uint16_t pc = m_maincpu->pc(); // get the byte; and skip over header bytes - uint8_t byte = program.read_byte(prev_pc); + uint8_t byte = cpu_address_space().read_byte(prev_pc); if ((byte == 0x10) || (byte == 0x11)) - byte = program.read_byte(++prev_pc); + byte = cpu_address_space().read_byte(++prev_pc); // check to see if the opcode specifies the indexed addressing mode, and the secondary byte // specifies no-offset bool is_nooffset_indexed = (((byte & 0xF0) == 0x60) || ((byte & 0xF0) == 0xA0) || ((byte & 0xF0) == 0xE0)) - && ((program.read_byte(prev_pc + 1) & 0xBF) == 0x84); + && ((cpu_address_space().read_byte(prev_pc + 1) & 0xBF) == 0x84); // finally read the byte - result = program.read_byte(is_nooffset_indexed ? pc : 0xFFFF); + result = cpu_address_space().read_byte(is_nooffset_indexed ? pc : 0xFFFF); // we're done reading m_in_floating_bus_read = false; @@ -338,7 +335,7 @@ void coco_state::floating_space_write(offs_t offset, uint8_t data) READ8_MEMBER( coco_state::ff00_read ) { - return m_pia_0->read(space, offset, mem_mask); + return pia_0().read(space, offset, mem_mask); } @@ -349,7 +346,7 @@ READ8_MEMBER( coco_state::ff00_read ) WRITE8_MEMBER( coco_state::ff00_write ) { - m_pia_0->write(space, offset, data, mem_mask); + pia_0().write(space, offset, data, mem_mask); } @@ -448,7 +445,7 @@ WRITE_LINE_MEMBER( coco_state::pia0_irq_b ) READ8_MEMBER( coco_state::ff20_read ) { - return m_pia_1->read(space, offset, mem_mask); + return pia_1().read(space, offset, mem_mask); } @@ -460,7 +457,7 @@ READ8_MEMBER( coco_state::ff20_read ) WRITE8_MEMBER( coco_state::ff20_write ) { /* write to the PIA */ - m_pia_1->write(space, offset, data, mem_mask); + pia_1().write(space, offset, data, mem_mask); /* we have to do this to do something that approximates the cartridge Q line behavior */ m_cococart->twiddle_q_lines(); @@ -501,7 +498,7 @@ READ8_MEMBER( coco_state::pia1_pb_r ) // to access 32K of ram, and also allows the cocoe driver to access // the full 64K, as this uses Color Basic 1.2, which can configure 64K rams bool memory_sense = (ram_size >= 0x4000 && ram_size <= 0x7FFF) - || (ram_size >= 0x8000 && (m_pia_0->b_output() & 0x40)); + || (ram_size >= 0x8000 && (pia_0().b_output() & 0x40)); // serial in (PB0) bool serial_in = (m_rs232 != nullptr) && (m_rs232->rxd_r() ? true : false); @@ -608,7 +605,7 @@ WRITE_LINE_MEMBER( coco_state::pia1_firq_b ) bool coco_state::irq_get_line(void) { - return m_pia_0->irq_a_state() || m_pia_0->irq_b_state(); + return pia_0().irq_a_state() || pia_0().irq_b_state(); } @@ -622,7 +619,7 @@ void coco_state::recalculate_irq(void) bool line = irq_get_line(); if (LOG_INTERRUPTS) logerror("recalculate_irq(): line=%d\n", line ? 1 : 0); - m_maincpu->set_input_line(M6809_IRQ_LINE, line ? ASSERT_LINE : CLEAR_LINE); + maincpu().set_input_line(M6809_IRQ_LINE, line ? ASSERT_LINE : CLEAR_LINE); } @@ -634,7 +631,7 @@ void coco_state::recalculate_irq(void) bool coco_state::firq_get_line(void) { - return m_pia_1->irq_a_state() || m_pia_1->irq_b_state(); + return pia_1().irq_a_state() || pia_1().irq_b_state(); } @@ -648,7 +645,7 @@ void coco_state::recalculate_firq(void) bool line = firq_get_line(); if (LOG_INTERRUPTS) logerror("recalculate_firq(): line=%d\n", line ? 1 : 0); - m_maincpu->set_input_line(M6809_FIRQ_LINE, line ? ASSERT_LINE : CLEAR_LINE); + maincpu().set_input_line(M6809_FIRQ_LINE, line ? ASSERT_LINE : CLEAR_LINE); } @@ -700,7 +697,7 @@ void coco_state::update_sound(void) uint8_t cart_sound = (bCartSoundEnable ? 0x20 : 0); /* determine the value to send to the DAC (this is used by the Joystick read as well as audio out) */ - m_dac_output = (m_pia_1->a_output() & 0xFC) >> 2; + m_dac_output = (pia_1().a_output() & 0xFC) >> 2; uint8_t dac_sound = (status == SOUNDMUX_ENABLE ? m_dac_output : 0); /* The CoCo uses the main 6-bit DAC for both audio output and joystick axis position measurement. @@ -875,8 +872,8 @@ void coco_state::poll_joystick(bool *joyin, uint8_t *buttons) void coco_state::poll_keyboard(void) { - uint8_t pia0_pb = m_pia_0->b_output(); - uint8_t pia0_pb_z = m_pia_0->port_b_z_mask(); + uint8_t pia0_pb = pia_0().b_output(); + uint8_t pia0_pb_z = pia_0().port_b_z_mask(); uint8_t pia0_pa = 0x7F; uint8_t pia0_pa_z = 0x7F; @@ -923,7 +920,7 @@ void coco_state::poll_keyboard(void) void coco_state::update_keyboard_input(uint8_t value, uint8_t z) { - m_pia_0->set_a_input(value, z); + pia_0().set_a_input(value, z); } @@ -1075,7 +1072,7 @@ void coco_state::poll_hires_joystick(void) break; case HIRES_RIGHT_COCOMAX3: - newvalue = (m_pia_0->a_output() & 0x04); + newvalue = (pia_0().a_output() & 0x04); joystick_index = 0; is_cocomax3 = true; break; @@ -1087,7 +1084,7 @@ void coco_state::poll_hires_joystick(void) break; case HIRES_LEFT_COCOMAX3: - newvalue = (m_pia_0->a_output() & 0x08); + newvalue = (pia_0().a_output() & 0x08); joystick_index = 1; is_cocomax3 = true; break; @@ -1111,7 +1108,7 @@ void coco_state::poll_hires_joystick(void) double value = m_joystick.input(joystick_index, axis) / 255.0; value *= is_cocomax3 ? 2500.0 : 4160.0; value += is_cocomax3 ? 400.0 : 592.0; - attotime duration = m_maincpu->clocks_to_attotime((uint64_t) value) * 8; + attotime duration = maincpu().clocks_to_attotime((uint64_t) value) * 8; m_hiresjoy_transition_timer[axis]->adjust(duration); } else if (!m_hiresjoy_ca && newvalue) @@ -1230,7 +1227,7 @@ WRITE8_MEMBER( coco_state::ff40_write ) void coco_state::cart_w(bool state) { - m_pia_1->cb1_w(state); + pia_1().cb1_w(state); } -- cgit v1.2.3