mos6510.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 2011-2013 Leandro Nini <drfiemost@users.sourceforge.net>
* Copyright 2007-2010 Antti Lankila
* Copyright 2000 Simon White
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef MOS6510_H
#define MOS6510_H
#include <stdint.h>
#include <cstdio>
#include "sidplayfp/EventScheduler.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
class EventContext;
class MOS6510
{
friend class MOS6510Debug;
private:
static const char *credit;
private:
static const int MAX = 65536;
static const uint8_t SP_PAGE = 0x01;
public:
static const int SR_INTERRUPT = 2;
protected:
struct ProcessorCycle
{
void (MOS6510::*func)();
bool nosteal;
ProcessorCycle () :
func(0),
nosteal(false) {}
};
protected:
EventContext &eventContext;
int cycleCount;
int interruptCycle;
bool irqAssertedOnPin;
bool nmiFlag;
bool rstFlag;
bool rdy;
bool flagN;
bool flagC;
bool flagD;
bool flagZ;
bool flagV;
bool flagI;
bool flagB;
/* Data regarding current instruction */
uint_least16_t Register_ProgramCounter;
uint_least16_t Cycle_EffectiveAddress;
uint_least16_t Cycle_HighByteWrongEffectiveAddress;
uint_least16_t Cycle_Pointer;
uint8_t Cycle_Data;
uint8_t Register_StackPointer;
uint8_t Register_Accumulator;
uint8_t Register_X;
uint8_t Register_Y;
#ifdef DEBUG
/* Debug info */
uint_least16_t instrStartPC;
uint_least16_t instrOperand;
FILE *m_fdbg;
bool dodump;
#endif
struct ProcessorCycle instrTable[0x101 << 3];
protected:
MOS6510(EventContext *context);
~MOS6510() {}
EventCallback<MOS6510> m_nosteal;
EventCallback<MOS6510> m_steal;
void eventWithoutSteals();
void eventWithSteals();
void Initialise();
// Flag utility functions
inline void setFlagsNZ(uint8_t value);
inline uint8_t getStatusRegister();
inline void setStatusRegister(uint8_t sr);
// Declare Interrupt Routines
inline void IRQLoRequest();
inline void IRQHiRequest();
inline void interruptsAndNextOpcode();
inline void calculateInterruptTriggerCycle();
// Declare Instruction Routines
inline void fetchNextOpcode();
inline void throwAwayFetch();
inline void throwAwayRead();
inline void FetchDataByte();
inline void FetchLowAddr();
inline void FetchLowAddrX();
inline void FetchLowAddrY();
inline void FetchHighAddr();
inline void FetchHighAddrX();
inline void FetchHighAddrX2();
inline void FetchHighAddrY();
inline void FetchHighAddrY2();
inline void FetchLowEffAddr();
inline void FetchHighEffAddr();
inline void FetchHighEffAddrY();
inline void FetchHighEffAddrY2();
inline void FetchLowPointer();
inline void FetchLowPointerX();
inline void FetchHighPointer();
inline void FetchEffAddrDataByte ();
inline void PutEffAddrDataByte();
inline void PushLowPC();
inline void PushHighPC();
inline void PushSR();
inline void PopLowPC();
inline void PopHighPC();
inline void PopSR();
inline void brkPushLowPC();
inline void WasteCycle();
// Delcare Instruction Operation Routines
inline void adc_instr();
inline void alr_instr();
inline void anc_instr();
inline void and_instr();
inline void ane_instr();
inline void arr_instr();
inline void asl_instr();
inline void asla_instr();
inline void aso_instr();
inline void axa_instr();
inline void axs_instr();
inline void bcc_instr();
inline void bcs_instr();
inline void beq_instr();
inline void bit_instr();
inline void bmi_instr();
inline void bne_instr();
inline void branch_instr(bool condition);
inline void bpl_instr();
inline void brk_instr();
inline void bvc_instr();
inline void bvs_instr();
inline void clc_instr();
inline void cld_instr();
inline void cli_instr();
inline void clv_instr();
inline void cmp_instr();
inline void cpx_instr();
inline void cpy_instr();
inline void dcm_instr();
inline void dec_instr();
inline void dex_instr();
inline void dey_instr();
inline void eor_instr();
inline void inc_instr();
inline void ins_instr();
inline void inx_instr();
inline void iny_instr();
inline void jmp_instr();
inline void las_instr();
inline void lax_instr();
inline void lda_instr();
inline void ldx_instr();
inline void ldy_instr();
inline void lse_instr();
inline void lsr_instr();
inline void lsra_instr();
inline void oal_instr();
inline void ora_instr();
inline void pha_instr();
inline void pla_instr();
inline void plp_instr();
inline void rla_instr();
inline void rol_instr();
inline void rola_instr();
inline void ror_instr();
inline void rora_instr();
inline void rra_instr();
inline void rti_instr();
inline void rts_instr();
inline void sbx_instr();
inline void say_instr();
inline void sbc_instr();
inline void sec_instr();
inline void sed_instr();
inline void sei_instr();
inline void shs_instr();
inline void sta_instr();
inline void stx_instr();
inline void sty_instr();
inline void tax_instr();
inline void tay_instr();
inline void tsx_instr();
inline void txa_instr();
inline void txs_instr();
inline void tya_instr();
inline void xas_instr();
void illegal_instr();
// Declare Arithmetic Operations
inline void doADC();
inline void doSBC();
inline void doJSR();
public:
virtual uint8_t cpuRead(uint_least16_t addr) =0;
virtual void cpuWrite(uint_least16_t addr, uint8_t data) =0;
#ifdef PC64_TESTSUITE
virtual void loadFile (const char *file) =0;
#endif
virtual void reset();
const char *credits() const { return credit; }
void debug(bool enable, FILE *out);
void setRDY(bool newRDY);
// Non-standard functions
void triggerRST();
void triggerNMI();
void triggerIRQ();
void clearIRQ();
};
#endif // MOS6510_H
MOS6510::PushLowPC
void PushLowPC()
Definition: mos6510.cpp:619
MOS6510::MOS6510
MOS6510(EventContext *context)
Definition: mos6510.cpp:1522
MOS6510::setRDY
void setRDY(bool newRDY)
Definition: mos6510.cpp:156
MOS6510::reset
virtual void reset()
Definition: mos6510.cpp:2215
MOS6510::FetchHighAddrY2
void FetchHighAddrY2()
Definition: mos6510.cpp:484
MOS6510::FetchLowAddrX
void FetchLowAddrX()
Definition: mos6510.cpp:401
MOS6510::SR_INTERRUPT
static const int SR_INTERRUPT
Definition: mos6510.h:65
MOS6510::say_instr
void say_instr()
Definition: mos6510.cpp:867
MOS6510::calculateInterruptTriggerCycle
void calculateInterruptTriggerCycle()
Definition: mos6510.cpp:310
MOS6510::axa_instr
void axa_instr()
Definition: mos6510.cpp:832
MOS6510::FetchLowEffAddr
void FetchLowEffAddr()
Definition: mos6510.cpp:551
MOS6510::cpuWrite
virtual void cpuWrite(uint_least16_t addr, uint8_t data)=0
MOS6510::ProcessorCycle
Definition: mos6510.h:68
MOS6510::nmiFlag
bool nmiFlag
Definition: mos6510.h:91
MOS6510::setFlagsNZ
void setFlagsNZ(uint8_t value)
Definition: mos6510.cpp:98
MOS6510::cycleCount
int cycleCount
Definition: mos6510.h:82
MOS6510::doSBC
void doSBC()
Definition: mos6510.cpp:923
MOS6510::FetchHighEffAddrY2
void FetchHighEffAddrY2()
Definition: mos6510.cpp:588
MOS6510::FetchHighEffAddrY
void FetchHighEffAddrY()
Definition: mos6510.cpp:579
MOS6510::throwAwayRead
void throwAwayRead()
Definition: mos6510.cpp:343
MOS6510::FetchLowAddrY
void FetchLowAddrY()
Definition: mos6510.cpp:415
EventContext
Definition: event.h:101
MOS6510::ins_instr
void ins_instr()
Definition: mos6510.cpp:1432
MOS6510::doADC
void doADC()
Definition: mos6510.cpp:889
MOS6510::FetchLowAddr
void FetchLowAddr()
Definition: mos6510.cpp:383
MOS6510::eventWithSteals
void eventWithSteals()
Definition: mos6510.cpp:74
MOS6510::FetchHighAddrY
void FetchHighAddrY()
Definition: mos6510.cpp:476
MOS6510
Definition: mos6510.h:46
MOS6510::las_instr
void las_instr()
Definition: mos6510.cpp:1444
EventCallback< MOS6510 >
MOS6510::rdy
bool rdy
Definition: mos6510.h:97
MOS6510::PushHighPC
void PushHighPC()
Definition: mos6510.cpp:629
MOS6510::FetchHighPointer
void FetchHighPointer()
Definition: mos6510.cpp:531
MOS6510::FetchLowPointerX
void FetchLowPointerX()
Definition: mos6510.cpp:518
MOS6510::instrTable
struct ProcessorCycle instrTable[0x101<< 3]
Definition: mos6510.h:130
MOS6510::cpuRead
virtual uint8_t cpuRead(uint_least16_t addr)=0
MOS6510::FetchLowPointer
void FetchLowPointer()
Definition: mos6510.cpp:500
MOS6510::PopSR
void PopSR()
Definition: mos6510.cpp:186
MOS6510::Initialise
void Initialise()
Definition: mos6510.cpp:2185
MOS6510::lse_instr
void lse_instr()
Definition: mos6510.cpp:1467
MOS6510::PutEffAddrDataByte
void PutEffAddrDataByte()
Definition: mos6510.cpp:611
MOS6510::aso_instr
void aso_instr()
Definition: mos6510.cpp:1407
MOS6510::m_nosteal
EventCallback< MOS6510 > m_nosteal
Definition: mos6510.h:137
MOS6510::anc_instr
void anc_instr()
Definition: mos6510.cpp:1364
MOS6510::eventWithoutSteals
void eventWithoutSteals()
Definition: mos6510.cpp:66
MOS6510::triggerNMI
void triggerNMI()
Definition: mos6510.cpp:225
MOS6510::irqAssertedOnPin
bool irqAssertedOnPin
Definition: mos6510.h:88
MOS6510::PushSR
void PushSR()
Definition: mos6510.cpp:176
MOS6510::PopHighPC
void PopHighPC()
Definition: mos6510.cpp:649
MOS6510::triggerIRQ
void triggerIRQ()
Definition: mos6510.cpp:239
MOS6510::rla_instr
void rla_instr()
Definition: mos6510.cpp:1490
MOS6510::PopLowPC
void PopLowPC()
Definition: mos6510.cpp:639
MOS6510::FetchHighAddrX
void FetchHighAddrX()
Definition: mos6510.cpp:451
MOS6510::alr_instr
void alr_instr()
Definition: mos6510.cpp:1350
MOS6510::clearIRQ
void clearIRQ()
Definition: mos6510.cpp:253
MOS6510::interruptCycle
int interruptCycle
Definition: mos6510.h:85
MOS6510::dcm_instr
void dcm_instr()
Definition: mos6510.cpp:1419
MOS6510::xas_instr
void xas_instr()
Definition: mos6510.cpp:879
MOS6510::rra_instr
void rra_instr()
Definition: mos6510.cpp:1504
MOS6510::FetchHighEffAddr
void FetchHighEffAddr()
Definition: mos6510.cpp:565
MOS6510::FetchDataByte
void FetchDataByte()
Definition: mos6510.cpp:357
MOS6510::FetchHighAddr
void FetchHighAddr()
Definition: mos6510.cpp:431
MOS6510::throwAwayFetch
void throwAwayFetch()
Definition: mos6510.cpp:335
MOS6510::eventContext
EventContext & eventContext
Definition: mos6510.h:79
MOS6510::m_steal
EventCallback< MOS6510 > m_steal
Definition: mos6510.h:140
MOS6510::triggerRST
void triggerRST()
Definition: mos6510.cpp:211
MOS6510::axs_instr
void axs_instr()
Definition: mos6510.cpp:845
MOS6510::oal_instr
void oal_instr()
Definition: mos6510.cpp:1480
MOS6510::FetchHighAddrX2
void FetchHighAddrX2()
Definition: mos6510.cpp:459
MOS6510::arr_instr
void arr_instr()
Definition: mos6510.cpp:1375
MOS6510::rstFlag
bool rstFlag
Definition: mos6510.h:94
MOS6510::lax_instr
void lax_instr()
Definition: mos6510.cpp:1457