From 9872097bbc1aed0422de2fff31f6d7de4d154ee3 Mon Sep 17 00:00:00 2001 From: AJR Date: Thu, 16 Apr 2020 15:30:24 -0400 Subject: [PATCH] z8000: Clean up reset sequence (don't read program space at device_reset time) (nw) polepos: Make ROM region tags explicit (nw) --- src/devices/cpu/z8000/z8000.cpp | 60 +++++++++++++++--------------- src/devices/cpu/z8000/z8000.h | 11 +++--- src/devices/cpu/z8000/z8000ops.hxx | 2 +- src/mame/drivers/m20.cpp | 1 - src/mame/drivers/polepos.cpp | 7 ++-- 5 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/devices/cpu/z8000/z8000.cpp b/src/devices/cpu/z8000/z8000.cpp index 3f8570abaff..11129231c37 100644 --- a/src/devices/cpu/z8000/z8000.cpp +++ b/src/devices/cpu/z8000/z8000.cpp @@ -41,7 +41,7 @@ z8002_device::z8002_device(const machine_config &mconfig, device_type type, cons , m_stack_config("stack", ENDIANNESS_BIG, 16, addrbits, 0) , m_sio_config("special I/O", ENDIANNESS_BIG, iobits, 16, 0) , m_mo_out(*this) - , m_ppc(0), m_pc(0), m_psapseg(0), m_psapoff(0), m_fcw(0), m_refresh(0), m_nspseg(0), m_nspoff(0), m_irq_req(0), m_irq_vec(0), m_op_valid(0), m_nmi_state(0), m_mi(0), m_program(nullptr), m_data(nullptr), m_cache(nullptr), m_io(nullptr), m_icount(0) + , m_ppc(0), m_pc(0), m_psapseg(0), m_psapoff(0), m_fcw(0), m_refresh(0), m_nspseg(0), m_nspoff(0), m_irq_req(0), m_irq_vec(0), m_op_valid(0), m_nmi_state(0), m_mi(0), m_halt(false), m_program(nullptr), m_data(nullptr), m_cache(nullptr), m_io(nullptr), m_icount(0) , m_vector_mult(vecmult) { } @@ -364,7 +364,8 @@ void z8002_device::set_irq(int type) return; } /* set interrupt request flag, reset HALT flag */ - m_irq_req = type & ~Z8000_HALT; + m_irq_req = type; + m_halt = false; } void z8002_device::PUSH_PC() @@ -388,6 +389,16 @@ uint32_t z8001_device::GET_PC(uint32_t VEC) return segmented_addr(RDMEM_L(*m_program, VEC + 4)); } +uint32_t z8002_device::get_reset_pc() +{ + return RDMEM_W(*m_program, 4); +} + +uint32_t z8001_device::get_reset_pc() +{ + return segmented_addr(RDMEM_L(*m_program, 4)); +} + uint16_t z8002_device::GET_FCW(uint32_t VEC) { return RDMEM_W(*m_program, VEC); @@ -423,18 +434,13 @@ void z8002_device::Interrupt() { uint16_t fcw = m_fcw; - if (m_irq_req & Z8000_NVI) + if (m_irq_req & Z8000_RESET) { - int type = standard_irq_callback(NVI_LINE); - set_irq(type | Z8000_NVI); + m_irq_req &= ~(Z8000_RESET | Z8000_NMI); + CHANGE_FCW(RDMEM_W(*m_program, 2)); /* get reset m_fcw */ + m_pc = get_reset_pc(); /* get reset m_pc */ } - - if (m_irq_req & Z8000_VI) - { - int type = standard_irq_callback(VI_LINE); - set_irq(type | Z8000_VI); - } - + else /* trap ? */ if (m_irq_req & Z8000_EPU) { @@ -499,6 +505,9 @@ void z8002_device::Interrupt() else if ((m_irq_req & Z8000_NVI) && (m_fcw & F_NVIE)) { + int type = standard_irq_callback(NVI_LINE); + set_irq(type | Z8000_NVI); + CHANGE_FCW(fcw | F_S_N | F_SEG_Z8001());/* switch to segmented (on Z8001) system mode */ PUSH_PC(); PUSHW(SP, fcw); /* save current m_fcw */ @@ -511,6 +520,9 @@ void z8002_device::Interrupt() else if ((m_irq_req & Z8000_VI) && (m_fcw & F_VIE)) { + int type = standard_irq_callback(VI_LINE); + set_irq(type | Z8000_VI); + CHANGE_FCW(fcw | F_S_N | F_SEG_Z8001());/* switch to segmented (on Z8001) system mode */ PUSH_PC(); PUSHW(SP, fcw); /* save current m_fcw */ @@ -631,8 +643,8 @@ void z8002_device::register_save_state() save_item(NAME(m_nmi_state)); save_item(NAME(m_irq_state)); save_item(NAME(m_mi)); + save_item(NAME(m_halt)); save_item(NAME(m_icount)); - save_item(NAME(m_vector_mult)); } void z8002_device::init_spaces() @@ -693,25 +705,11 @@ void z8002_device::device_start() m_mi = CLEAR_LINE; } -void z8001_device::device_reset() -{ - m_fcw = RDMEM_W(*m_program, 2); /* get reset m_fcw */ - if(m_fcw & F_SEG) - { - m_pc = ((RDMEM_W(*m_program, 4) & 0x0700) << 8) | (RDMEM_W(*m_program, 6) & 0xffff); /* get reset m_pc */ - } - else - { - m_pc = RDMEM_W(*m_program, 4); /* get reset m_pc */ - } - m_ppc = m_pc; -} - void z8002_device::device_reset() { - m_fcw = RDMEM_W(*m_program, 2); /* get reset m_fcw */ - m_pc = RDMEM_W(*m_program, 4); /* get reset m_pc */ - m_ppc = m_pc; + m_irq_req |= Z8000_RESET; + m_refresh &= 0x7fff; + m_halt = false; } z8002_device::~z8002_device() @@ -729,7 +727,7 @@ void z8002_device::execute_run() m_ppc = m_pc; debugger_instruction_hook(m_pc); - if (m_irq_req & Z8000_HALT) + if (m_halt) { m_icount = 0; } diff --git a/src/devices/cpu/z8000/z8000.h b/src/devices/cpu/z8000/z8000.h index 3073e246a84..0cdd59c6dcf 100644 --- a/src/devices/cpu/z8000/z8000.h +++ b/src/devices/cpu/z8000/z8000.h @@ -30,7 +30,7 @@ protected: static constexpr uint16_t Z8000_NVI = 0x0800; /* non vectored interrupt */ static constexpr uint16_t Z8000_VI = 0x0400; /* vectored interrupt (LSB is vector) */ static constexpr uint16_t Z8000_SYSCALL = 0x0200; /* system call (lsb is vector) */ - static constexpr uint16_t Z8000_HALT = 0x0100; /* halted flag */ + static constexpr uint16_t Z8000_RESET = 0x0100; /* reset flag */ public: enum @@ -111,6 +111,7 @@ protected: int m_nmi_state; /* NMI line state */ int m_irq_state[2]; /* IRQ line states (NVI, VI) */ int m_mi; + bool m_halt; address_space *m_program; address_space *m_data; address_space *m_stack; @@ -119,7 +120,7 @@ protected: address_space *m_io; address_space *m_sio; int m_icount; - int m_vector_mult; + const int m_vector_mult; void clear_internal_state(); void register_debug_state(); @@ -231,6 +232,7 @@ protected: inline uint32_t SRLL(uint32_t dest, uint8_t count); inline void Interrupt(); virtual uint32_t GET_PC(uint32_t VEC); + virtual uint32_t get_reset_pc(); virtual uint16_t GET_FCW(uint32_t VEC); virtual uint32_t F_SEG_Z8001(); virtual uint32_t PSA_ADDR(); @@ -674,9 +676,7 @@ public: z8001_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); protected: - // device-level overrides - virtual void device_reset() override; - + // z8002_device overrides virtual bool get_segmented_mode() const override; virtual uint32_t adjust_addr_for_nonseg_mode(uint32_t addr) override; virtual uint16_t RDPORT_W(int mode, uint16_t addr) override; @@ -684,6 +684,7 @@ protected: virtual void PUSH_PC() override; virtual void CHANGE_FCW(uint16_t fcw) override; virtual uint32_t GET_PC(uint32_t VEC) override; + virtual uint32_t get_reset_pc() override; virtual uint16_t GET_FCW(uint32_t VEC) override; virtual uint32_t F_SEG_Z8001() override; virtual uint32_t PSA_ADDR() override; diff --git a/src/devices/cpu/z8000/z8000ops.hxx b/src/devices/cpu/z8000/z8000ops.hxx index 2ffb6edc26b..4d3457510c5 100644 --- a/src/devices/cpu/z8000/z8000ops.hxx +++ b/src/devices/cpu/z8000/z8000ops.hxx @@ -4674,7 +4674,7 @@ void z8002_device::Z79_ssN0_0000_addr() void z8002_device::Z7A_0000_0000() { CHECK_PRIVILEGED_INSTR(); - m_irq_req |= Z8000_HALT; + m_halt = true; if (m_icount > 0) m_icount = 0; } diff --git a/src/mame/drivers/m20.cpp b/src/mame/drivers/m20.cpp index 719bc740117..2484e88eab5 100644 --- a/src/mame/drivers/m20.cpp +++ b/src/mame/drivers/m20.cpp @@ -768,7 +768,6 @@ void m20_state::machine_reset() m_fd1797->reset(); memcpy(RAM, ROM, 8); // we need only the reset vector - m_maincpu->reset(); // FIXME: rewrite Z8000 core to not read the vector at this time m_kbdi8251->write_cts(0); if (m_apb) m_apb->halt(); diff --git a/src/mame/drivers/polepos.cpp b/src/mame/drivers/polepos.cpp index b0ad4e5396d..ff2ad8b4741 100644 --- a/src/mame/drivers/polepos.cpp +++ b/src/mame/drivers/polepos.cpp @@ -419,7 +419,7 @@ void polepos_state::machine_reset() void polepos_state::z80_map(address_map &map) { - map(0x0000, 0x2fff).rom(); + map(0x0000, 0x2fff).rom().region("maincpu", 0); map(0x3000, 0x37ff).mirror(0x0800).ram().share("nvram"); /* Battery Backup */ map(0x4000, 0x47ff).rw(FUNC(polepos_state::sprite_r), FUNC(polepos_state::sprite_w)); /* Motion Object */ map(0x4800, 0x4bff).rw(FUNC(polepos_state::road_r), FUNC(polepos_state::road_w)); /* Road Memory */ @@ -448,7 +448,6 @@ void polepos_state::z80_io(address_map &map) /* the same memory map is used by both Z8002 CPUs; all RAM areas are shared */ void polepos_state::z8002_map(address_map &map) { - map(0x0000, 0x7fff).rom(); map(0x8000, 0x8fff).ram().share(m_sprite16_memory); /* Motion Object */ map(0x9000, 0x97ff).ram().share(m_road16_memory); /* Road Memory */ map(0x9800, 0x9fff).ram().w(FUNC(polepos_state::alpha16_w)).share(m_alpha16_memory); /* Alphanumeric (char ram) */ @@ -460,12 +459,14 @@ void polepos_state::z8002_map(address_map &map) void polepos_state::z8002_map_1(address_map &map) { z8002_map(map); + map(0x0000, 0x7fff).rom().region("sub", 0); map(0x6000, 0x6001).mirror(0x0ffe).w(FUNC(polepos_state::z8002_nvi_enable_w)); /* NVI enable - *NOT* shared by the two CPUs */ } void polepos_state::z8002_map_2(address_map &map) { z8002_map(map); + map(0x0000, 0x7fff).rom().region("sub2", 0); map(0x6000, 0x6001).mirror(0x0ffe).w(FUNC(polepos_state::z8002_nvi_enable_w)); /* NVI enable - *NOT* shared by the two CPUs */ } @@ -969,7 +970,7 @@ void polepos_state::topracern_io(address_map &map) void polepos_state::sound_z80_bootleg_map(address_map &map) { - map(0x0000, 0x1fff).rom(); + map(0x0000, 0x1fff).rom().region("soundz80bl", 0); map(0x2700, 0x27ff).ram(); map(0x4000, 0x4000).r(m_soundlatch, FUNC(generic_latch_8_device::read)); map(0x6000, 0x6000).r(m_soundlatch, FUNC(generic_latch_8_device::acknowledge_r));