Cpu.h
上传用户:luhy168
上传日期:2022-01-10
资源大小:240k
文件大小:5k
源码类别:

模拟服务器

开发平台:

Visual C++

  1. //------------------------------------------------------------------------------
  2. // Name: Cpu.h
  3. // Desc: Header file for all the Cpu stuff. Note to self, write better desc!!!
  4. //------------------------------------------------------------------------------
  5. #ifndef __CPU_H__
  6. #define __CPU_H__
  7. /*
  8.   THE REGISTERS INSIDE THE 6502 MICROPROCESSOR
  9.     Almost all calculations are done in the microprocessor. Registers are
  10.   special pieces of memory in the processor which are used to carry out, and
  11.   store information about calculations. The 6502 has the following registers:
  12.   THE ACCUMULATOR
  13.     This is THE most important register in the microprocessor. Various ma-
  14.   chine language instructions allow you to copy the contents of a memory
  15.   location into the accumulator, copy the contents of the accumulator into
  16.   a memory location, modify the contents of the accumulator or some other
  17.   register directly, without affecting any memory. And the accumulator is
  18.   the only register that has instructions for performing math.
  19.   THE X INDEX REGISTER
  20.     This is a very important register. There are instructions for nearly
  21.   all of the transformations you can make to the accumulator. But there are
  22.   other instructions for things that only the X register can do. Various
  23.   machine language instructions allow you to copy the contents of a memory
  24.   location into the X register, copy the contents of the X register into a
  25.   memory location, and modify the contents of the X, or some other register
  26.   directly.
  27.   THE Y INDEX REGISTER
  28.     This is a very important register. There are instructions for nearly
  29.   all of the transformations you can make to the accumulator, and the X
  30.   register. But there are other instructions for things that only the Y
  31.   register can do. Various machine language instructions allow you to copy
  32.   the contents of a memory location into the Y register, copy the contents
  33.   of the Y register into a memory location, and modify the contents of the
  34.   Y, or some other register directly.
  35.   THE STATUS REGISTER
  36.     This register consists of eight "flags" (a flag = something that indi-
  37.   cates whether something has, or has not occurred). Bits of this register
  38.   are altered depending on the result of arithmetic and logical operations.
  39.   These bits are described below:
  40.      Bit No.       7   6   5   4   3   2   1   0
  41.                    S   V       B   D   I   Z   C
  42.    Bit0 - C - Carry flag: this holds the carry out of the most significant
  43.    bit in any arithmetic operation. In subtraction operations however, this
  44.    flag is cleared - set to 0 - if a borrow is required, set to 1 - if no
  45.    borrow is required. The carry flag is also used in shift and rotate
  46.    logical operations.
  47.    Bit1 - Z - Zero flag: this is set to 1 when any arithmetic or logical
  48.    operation produces a zero result, and is set to 0 if the result is
  49.    non-zero.
  50.    Bit 2 - I: this is an interrupt enable/disable flag. If it is set,
  51.    interrupts are disabled. If it is cleared, interrupts are enabled.
  52.    Bit 3 - D: this is the decimal mode status flag. When set, and an Add with
  53.    Carry or Subtract with Carry instruction is executed, the source values are
  54.    treated as valid BCD (Binary Coded Decimal, eg. 0x00-0x99 = 0-99) numbers.
  55.    The result generated is also a BCD number.
  56.    Bit 4 - B: this is set when a software interrupt (BRK instruction) is
  57.    executed.
  58.    Bit 5: not used. Supposed to be logical 1 at all times.
  59.    Bit 6 - V - Overflow flag: when an arithmetic operation produces a result
  60.    too large to be represented in a byte, V is set.
  61.    Bit 7 - S - Sign flag: this is set if the result of an operation is
  62.    negative, cleared if positive.
  63.    The most commonly used flags are C, Z, V, S.
  64.   
  65.   THE PROGRAM COUNTER
  66.     This contains the address of the current machine language instruction
  67.   being executed. Since the operating system is always "RUN"ning in the
  68.   Commodore VIC-20 (or, for that matter, any computer), the program counter
  69.   is always changing. It could only be stopped by halting the microprocessor
  70.   in some way.
  71.   THE STACK POINTER
  72.     This register contains the location of the first empty place on the
  73.   stack. The stack is used for temporary storage by machine language pro-
  74.   grams, and by the computer.
  75. */
  76. // The CPU structure.
  77. typedef struct tagNES6502
  78. {
  79. BYTE  A;              // The Accumulator register on the 6502.
  80. BYTE  X;              // The X Index register on the 6502.
  81. BYTE  Y;              // The Y Index register on the 6502.
  82. BYTE  S;              // The stack pointer on the 6502.
  83. BYTE  F;              // The flags register on the 6502.
  84. WORD  P;              // The program counter on the 6502.
  85. BYTE  Memory[0x8000]; // All the memory on the NES except the PRG-ROM.
  86. BYTE* pbyPRGROMBank1; // Points to the first PRG-ROM bank on the NES cartridge.
  87. BYTE* pbyPRGROMBank2; // Points to the second PRG-ROM bank on the NES cartridge.
  88. BYTE  byCycles;       // Number of cycles left until the end of the scanline.
  89. } NES6502;
  90. // Number of cycles each scanline takes.
  91. #define NUM_CYCLES_PER_SCANLINE 113
  92. // Valid control flags used in RunCPU()
  93. #define RUNCPU_STEP 0x00000001
  94. #define RUNCPU_RUN  0x00000002
  95. // CPU frequency
  96. #define CPU_FREQUENCY 1789772
  97. // External ASM function to run the CPU
  98. extern "C" void RunCPU(DWORD dwFlags);
  99. #endif