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 "flags.h"
#include "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;
private:
struct ProcessorCycle
{
void (MOS6510::*func)();
bool nosteal;
ProcessorCycle () :
func(0),
nosteal(false) {}
};
private:
EventContext &eventContext;
int cycleCount;
int interruptCycle;
bool irqAssertedOnPin;
bool nmiFlag;
bool rstFlag;
bool rdy;
Flags flags;
// 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];
private:
EventCallback<MOS6510> m_nosteal;
EventCallback<MOS6510> m_steal;
void eventWithoutSteals();
void eventWithSteals();
void Initialise();
// 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();
protected:
MOS6510(EventContext *context);
~MOS6510() {}
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
void reset();
static const char *credits() { 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::cpuWrite
virtual void cpuWrite(uint_least16_t addr, uint8_t data)=0
Flags
Definition: flags.h:31
MOS6510::triggerIRQ
void triggerIRQ()
Definition: mos6510.cpp:199
MOS6510::MOS6510
MOS6510(EventContext *context)
Definition: mos6510.cpp:1475
EventCallback< MOS6510 >
MOS6510::triggerNMI
void triggerNMI()
Definition: mos6510.cpp:185
MOS6510
Definition: mos6510.h:47
EventContext
Definition: event.h:107
MOS6510::clearIRQ
void clearIRQ()
Definition: mos6510.cpp:213
MOS6510::reset
void reset()
Definition: mos6510.cpp:2167
MOS6510::triggerRST
void triggerRST()
Definition: mos6510.cpp:171
MOS6510::SR_INTERRUPT
static const int SR_INTERRUPT
Status register interrupt bit.
Definition: mos6510.h:67
MOS6510::setRDY
void setRDY(bool newRDY)
Definition: mos6510.cpp:116
MOS6510::cpuRead
virtual uint8_t cpuRead(uint_least16_t addr)=0