File: M6507.hxx

package info (click to toggle)
stella 0.7-2
  • links: PTS
  • area: non-free
  • in suites: hamm, slink
  • size: 864 kB
  • ctags: 1,158
  • sloc: cpp: 6,615; ansic: 492; makefile: 224; asm: 31
file content (129 lines) | stat: -rw-r--r-- 3,861 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//============================================================================
//
//    SSSS    tt          lll  lll              
//   SS  SS   tt           ll   ll                
//   SS     tttttt  eeee   ll   ll   aaaa    "An Atari 2600 VCS Emulator"
//    SSSS    tt   ee  ee  ll   ll      aa      
//       SS   tt   eeeeee  ll   ll   aaaaa   Copyright (c) 1995,1996,1997
//   SS  SS   tt   ee      ll   ll  aa  aa         Bradford W. Mott
//    SSSS     ttt  eeeee llll llll  aaaaa    
//
//============================================================================

#ifndef M6507_HXX
#define M6507_HXX

#include <fstream.h>

class M6507;

#include "machine.hxx"
#include "System.hxx"

/**
  This is an abstract base class for classes that emulate the
  6507 microprocessor.  For the most part the 6507 is just like 
  the 6502 except it has an 8K address space.

  @author  Bradford W. Mott
  @version $Id: M6507.hxx,v 1.2 1997/05/17 19:00:06 bwmott Exp $
*/
class M6507
{
  public:
    /// Enumeration of the 6507 addressing modes
    enum AddressingMode 
    {
      Implied, Immediate, Absolute, AbsoluteX, AbsoluteY,
      Zero, ZeroX, ZeroY, Indirect, IndirectX, IndirectY, Invalid 
    };

  public:
    /// Constructor
    M6507(System& system);

    /// Destructor
    virtual ~M6507();

  public:
    /// Reset myself to power-on state
    virtual void reset();

    /**
      Execute instructions until at least the given number of 
      cycles have passed or execution is halted by someone
    */
    virtual void execute(uLong numberOfCycles) = 0;

  public:
    /// Indicate that execution should be stopped
    void halt() { myHaltExecution = true; }

    /// Answer the number of CPU cycles executed since the last reset
    uLong cycles() const { return myCycles; }

    /// Waste the given number of CPU cycles
    void wasteCycles(uLong cycles) { myCycles += cycles; }

  public:
#ifdef DEBUG
    // Output stream used for debugging trace
    ofstream debugStream;
#endif

  protected:
    // Called if an illegal instruction is executed
    void invalidInstruction();

  protected:
    // Answers value of the Processor Status register 
    uByte PS() const;

    // Change the processor flags to correspond to the given value
    void PS(uByte ps);

  protected:
    // Output operator for addressing modes
    friend ostream& operator<<(ostream& out, const AddressingMode& mode);

  protected:
    uByte A;    // Accumulator                 8 bits
    uByte X;    // X index register            8 bits
    uByte Y;    // Y index register            8 bits
    uByte SP;   // Stack Pointer               8 bits
    uByte IR;   // Instruction register        8 bits
    uWord PC;   // Program Counter            16 bits

    bool N;     // N flag for processor status register
    bool V;     // V flag for processor status register
    bool B;     // B flag for processor status register
    bool D;     // D flag for processor status register
    bool I;     // I flag for processor status register
    bool Z;     // Z flag for processor status register
    bool C;     // C flag for processor status register
   
    // Indicates if execution should be halted
    bool myHaltExecution;

    // Reference to the system I belong to 
    System& mySystem;
 
    // Indicates how many cycles I've executed
    uLong myCycles;

  protected:
    // Addressing mode for each of the 256 opcodes
    static AddressingMode ourAddressingModeTable[256];

    // Lookup table used for binary-code-decimal math
    static uByte ourBCDTable[2][256];

    // Table of instruction cycle times.  In some cases additional
    // cycles will be added during the execution of an instruction.
    static uLong ourInstructionCycleTable[256];

    // Table of instruction mnemonics
    static const char* ourInstructionMnemonicTable[256];
};
#endif