From b2144f77087bf9f1919c005cb01bd8bf449d4309 Mon Sep 17 00:00:00 2001 From: hap Date: Mon, 10 May 2021 20:49:13 +0200 Subject: m6800: account interrupt cycles for timer counter --- src/devices/cpu/m6800/6800dasm.cpp | 2 +- src/devices/cpu/m6800/6800ops.hxx | 16 ++++----- src/devices/cpu/m6800/m6800.cpp | 67 ++++++++++++++++++++------------------ src/devices/cpu/m6800/m6800.h | 8 ++--- src/devices/cpu/m6800/m6801.cpp | 27 +++++++-------- src/devices/cpu/m6800/m6801.h | 8 ++--- 6 files changed, 64 insertions(+), 64 deletions(-) diff --git a/src/devices/cpu/m6800/6800dasm.cpp b/src/devices/cpu/m6800/6800dasm.cpp index 8ced48044dc..f55c6543790 100644 --- a/src/devices/cpu/m6800/6800dasm.cpp +++ b/src/devices/cpu/m6800/6800dasm.cpp @@ -45,7 +45,7 @@ const char *const m680x_disassembler::op_name_str[] = { /* * This table defines the opcodes: * byte meaning - * 0 token (menmonic) + * 0 token (mnemonic) * 1 addressing mode * 2 invalid opcode for 1:6800/6802/6808, 2:6801/6803, 4:HD63701 */ diff --git a/src/devices/cpu/m6800/6800ops.hxx b/src/devices/cpu/m6800/6800ops.hxx index a498c846df7..f93fad7cb22 100644 --- a/src/devices/cpu/m6800/6800ops.hxx +++ b/src/devices/cpu/m6800/6800ops.hxx @@ -41,7 +41,7 @@ OP_HANDLER( illegl3 ) OP_HANDLER( trap ) { logerror("m6800: illegal opcode: address %04X, op %02X\n",PC-1,(int) M_RDOP_ARG(PC-1)&0xFF); - TAKE_TRAP(); + take_trap(); } /* $00 ILLEGAL */ @@ -80,7 +80,7 @@ OP_HANDLER( tap ) { CC=A; ONE_MORE_INSN(); - CHECK_IRQ_LINES(); /* HJB 990417 */ + check_irq_lines(); } /* $07 TPA inherent ----- */ @@ -132,7 +132,7 @@ OP_HANDLER( cli ) { CLI; ONE_MORE_INSN(); - CHECK_IRQ_LINES(); /* HJB 990417 */ + check_irq_lines(); } /* $0f SEI */ @@ -140,7 +140,7 @@ OP_HANDLER( sei ) { SEI; ONE_MORE_INSN(); - CHECK_IRQ_LINES(); /* HJB 990417 */ + check_irq_lines(); } /* $10 SBA inherent -**** */ @@ -221,7 +221,7 @@ OP_HANDLER( slp ) { /* wait for next IRQ (same as waiting of wai) */ m_wai_state |= M6800_SLP; - EAT_CYCLES(); + eat_cycles(); } /* $1b ABA inherent ***** */ @@ -427,7 +427,7 @@ OP_HANDLER( rti ) PULLBYTE(A); PULLWORD(pX); PULLWORD(pPC); - CHECK_IRQ_LINES(); /* HJB 990417 */ + check_irq_lines(); } /* $3c PSHX inherent ----- */ @@ -459,8 +459,8 @@ OP_HANDLER( wai ) PUSHBYTE(A); PUSHBYTE(B); PUSHBYTE(CC); - CHECK_IRQ_LINES(); - if (m_wai_state & M6800_WAI) EAT_CYCLES(); + check_irq_lines(); + if (m_wai_state & M6800_WAI) eat_cycles(); } /* $3f SWI absolute indirect ----- */ diff --git a/src/devices/cpu/m6800/m6800.cpp b/src/devices/cpu/m6800/m6800.cpp index 7eab9292599..95fa32b07a9 100644 --- a/src/devices/cpu/m6800/m6800.cpp +++ b/src/devices/cpu/m6800/m6800.cpp @@ -1,24 +1,28 @@ // license:BSD-3-Clause // copyright-holders:Aaron Giles -/*** m6800: Portable 6800 class emulator ************************************* +/*** m6800: Portable 6800 class emulator ************************************* - m68xx.c +m68xx.cpp - References: +References: - 6809 Simulator V09, By L.C. Benschop, Eindhoven The Netherlands. + 6809 Simulator V09, By L.C. Benschop, Eindhoven The Netherlands. - m6809: Portable 6809 emulator, DS (6809 code in MAME, derived from - the 6809 Simulator V09) + m6809: Portable 6809 emulator, DS (6809 code in MAME, derived from + the 6809 Simulator V09) - 6809 Microcomputer Programming & Interfacing with Experiments" - by Andrew C. Staugaard, Jr.; Howard W. Sams & Co., Inc. + 6809 Microcomputer Programming & Interfacing with Experiments" + by Andrew C. Staugaard, Jr.; Howard W. Sams & Co., Inc. - System dependencies: uint16_t must be 16 bit unsigned int - uint8_t must be 8 bit unsigned int - uint32_t must be more than 16 bits - arrays up to 65536 bytes must be supported - machine must be twos complement +System dependencies: uint16_t must be 16 bit unsigned int + uint8_t must be 8 bit unsigned int + uint32_t must be more than 16 bits + arrays up to 65536 bytes must be supported + machine must be twos complement + +TODO: +- Verify invalid opcodes for the different CPU types. +- A lot more work and cleanups, especially for the 6801 derivatives. History 991031 ZV @@ -41,10 +45,6 @@ History PAIR union. Registers defined using macros. Split the core into four execution loops for M6802, M6803, M6808 and HD63701. TST, TSTA and TSTB opcodes reset carry flag. -TODO: - Verify invalid opcodes for the different CPU types. - Add proper credits to _info functions. - Integrate m6808_Flags into the registers (multiple m6808 type CPUs?) 990301 HJB Modified the interrupt handling. No more pending interrupt checks. @@ -479,11 +479,13 @@ void m6800_cpu_device::WM16(uint32_t Addr, PAIR *p ) /* IRQ enter */ void m6800_cpu_device::enter_interrupt(const char *message,uint16_t irq_vector) { + int cycles_to_eat = 0; + LOG((message)); if( m_wai_state & (M6800_WAI|M6800_SLP) ) { if( m_wai_state & M6800_WAI ) - m_icount -= 4; + cycles_to_eat = 4; m_wai_state &= ~(M6800_WAI|M6800_SLP); } else @@ -493,16 +495,17 @@ void m6800_cpu_device::enter_interrupt(const char *message,uint16_t irq_vector) PUSHBYTE(A); PUSHBYTE(B); PUSHBYTE(CC); - m_icount -= 12; + cycles_to_eat = 12; } SEI; PCD = RM16( irq_vector ); -} - + if (cycles_to_eat > 0) + increment_counter(cycles_to_eat); +} /* check the IRQ lines for pending interrupts */ -void m6800_cpu_device::CHECK_IRQ_LINES() +void m6800_cpu_device::check_irq_lines() { // TODO: IS3 interrupt @@ -517,7 +520,8 @@ void m6800_cpu_device::CHECK_IRQ_LINES() else { if( m_irq_state[M6800_IRQ_LINE] != CLEAR_LINE ) - { /* standard IRQ */ + { + /* standard IRQ */ if(m_wai_state & M6800_SLP) m_wai_state &= ~M6800_SLP; @@ -538,9 +542,10 @@ void m6800_cpu_device::increment_counter(int amount) m_icount -= amount; } -void m6800_cpu_device::EAT_CYCLES() +void m6800_cpu_device::eat_cycles() { - increment_counter(m_icount); + if (m_icount > 0) + increment_counter(m_icount); } @@ -605,7 +610,7 @@ void m6800_cpu_device::state_string_export(const device_state_entry &entry, std: void m6800_cpu_device::device_reset() { m_cc = 0xc0; - SEI; /* IRQ disabled */ + SEI; /* IRQ disabled */ PCD = RM16( 0xfffe ); m_wai_state = 0; @@ -637,23 +642,21 @@ void m6800_cpu_device::execute_set_input(int irqline, int state) ****************************************************************************/ void m6800_cpu_device::execute_run() { - uint8_t ireg; - - CHECK_IRQ_LINES(); /* HJB 990417 */ + check_irq_lines(); - CLEANUP_COUNTERS(); + cleanup_counters(); do { if( m_wai_state & (M6800_WAI|M6800_SLP) ) { - EAT_CYCLES(); + eat_cycles(); } else { pPPC = pPC; debugger_instruction_hook(PCD); - ireg=M_RDOP(PCD); + uint8_t ireg=M_RDOP(PCD); PC++; (this->*m_insn[ireg])(); increment_counter(m_cycles[ireg]); diff --git a/src/devices/cpu/m6800/m6800.h b/src/devices/cpu/m6800/m6800.h index 1601a62b798..8b8980d1c5c 100644 --- a/src/devices/cpu/m6800/m6800.h +++ b/src/devices/cpu/m6800/m6800.h @@ -103,11 +103,11 @@ protected: void WM16(uint32_t Addr, PAIR *p ); void enter_interrupt(const char *message,uint16_t irq_vector); virtual void m6800_check_irq2() { } - void CHECK_IRQ_LINES(); + void check_irq_lines(); virtual void increment_counter(int amount); - virtual void EAT_CYCLES(); - virtual void CLEANUP_COUNTERS() { } - virtual void TAKE_TRAP() { } + virtual void eat_cycles(); + virtual void cleanup_counters() { } + virtual void take_trap() { } void aba(); void abx(); diff --git a/src/devices/cpu/m6800/m6801.cpp b/src/devices/cpu/m6800/m6801.cpp index fecf48c0cd3..aaf27be8480 100644 --- a/src/devices/cpu/m6800/m6801.cpp +++ b/src/devices/cpu/m6800/m6801.cpp @@ -512,7 +512,7 @@ void m6801_cpu_device::check_timer_event() { TOH++; // next IRQ point #if 0 - CLEANUP_COUNTERS(); + cleanup_counters(); #endif m_tcsr |= TCSR_TOF; m_pending_tcsr |= TCSR_TOF; @@ -572,7 +572,7 @@ void hd6301x_cpu_device::check_timer_event() { TOH++; // next IRQ point #if 0 - CLEANUP_COUNTERS(); + cleanup_counters(); #endif m_tcsr |= TCSR_TOF; m_pending_tcsr |= TCSR_TOF; @@ -632,7 +632,7 @@ void hd6301x_cpu_device::increment_counter(int amount) check_timer_event(); } -void m6801_cpu_device::EAT_CYCLES() +void m6801_cpu_device::eat_cycles() { int cycles_to_eat = std::min(int(m_timer_next - CTD), m_icount); if (cycles_to_eat > 0) @@ -640,7 +640,7 @@ void m6801_cpu_device::EAT_CYCLES() } /* cleanup high-word of counters */ -void m6801_cpu_device::CLEANUP_COUNTERS() +void m6801_cpu_device::cleanup_counters() { OCH -= CTH; TOH -= CTH; @@ -650,10 +650,10 @@ void m6801_cpu_device::CLEANUP_COUNTERS() check_timer_event(); } -void hd6301x_cpu_device::CLEANUP_COUNTERS() +void hd6301x_cpu_device::cleanup_counters() { OC2H -= CTH; - m6801_cpu_device::CLEANUP_COUNTERS(); + m6801_cpu_device::cleanup_counters(); } void m6801_cpu_device::set_rmcr(uint8_t data) @@ -788,7 +788,7 @@ void m6801_cpu_device::serial_transmit() // send stop bit '1' m_tx = 1; - CHECK_IRQ_LINES(); + check_irq_lines(); m_txbits = M6801_SERIAL_START; @@ -876,7 +876,7 @@ void m6801_cpu_device::serial_receive() LOGRX("SCI Receive Overrun Error\n"); - CHECK_IRQ_LINES(); + check_irq_lines(); } else { @@ -890,7 +890,7 @@ void m6801_cpu_device::serial_receive() // set RDRF flag m_trcsr |= M6801_TRCSR_RDRF; - CHECK_IRQ_LINES(); + check_irq_lines(); } } } @@ -908,7 +908,7 @@ void m6801_cpu_device::serial_receive() LOGRX("SCI Receive Framing Error\n"); - CHECK_IRQ_LINES(); + check_irq_lines(); } m_rxbits = M6801_SERIAL_START; @@ -1051,11 +1051,8 @@ void m6801_cpu_device::device_start() save_item(NAME(m_use_ext_serclock)); save_item(NAME(m_latch09)); - save_item(NAME(m_timer_over.d)); - save_item(NAME(m_timer_next)); - save_item(NAME(m_sc1_state)); } @@ -1714,7 +1711,7 @@ void hd6301x_cpu_device::tcsr3_w(uint8_t data) { m_tout3 = false; write_port2(); - } + } else if (tout3_last_enable ? (data & 0x0c) == 0 : (data & 0x0c) != 0) { m_port2_written = true; @@ -1867,7 +1864,7 @@ std::unique_ptr hd6301_cpu_device::create_disassembler() return std::make_unique(6301); } -void hd6301_cpu_device::TAKE_TRAP() +void hd6301_cpu_device::take_trap() { enter_interrupt("take TRAP\n",0xffee); } diff --git a/src/devices/cpu/m6800/m6801.h b/src/devices/cpu/m6800/m6801.h index c88d0f3ba1c..57eb487e853 100644 --- a/src/devices/cpu/m6800/m6801.h +++ b/src/devices/cpu/m6800/m6801.h @@ -162,8 +162,8 @@ protected: virtual void m6800_check_irq2() override; virtual void increment_counter(int amount) override; - virtual void EAT_CYCLES() override; - virtual void CLEANUP_COUNTERS() override; + virtual void eat_cycles() override; + virtual void cleanup_counters() override; virtual void modified_tcsr(); virtual void set_timer_event(); @@ -209,7 +209,7 @@ protected: virtual std::unique_ptr create_disassembler() override; - virtual void TAKE_TRAP() override; + virtual void take_trap() override; }; @@ -296,7 +296,7 @@ protected: virtual void modified_counters() override; virtual void increment_counter(int amount) override; virtual void check_timer_event() override; - virtual void CLEANUP_COUNTERS() override; + virtual void cleanup_counters() override; virtual void set_rmcr(uint8_t data) override; devcb_read8::array<2> m_in_portx_func; -- cgit v1.2.3