PancakeNESEmu
A homebrewed NES Emulator written in C
Loading...
Searching...
No Matches
CPU Struct Reference

This structure will be used to represent the state of the Central Processing Unit (CPU) of our emulator. This Virtual CPU emulates a "MOS Technology 6502". More...

#include <cpu.h>

Collaboration diagram for CPU:
Collaboration graph

Public Attributes

address program_counter
 An address pointing to the next instruction to be executed.
 
data stack_pointer
 A register that holds the 8 lower bytes of the address 0x11??.
 
data cache
 A 8 bit reserved space that I use for some operations.
 
data accumulator
 A 8 bit register used to perform operations.
 
data register_x
 A 8 bit register. Commonly used to hold offset and counters.
 
data register_y
 A 8 bit register. Commonly used to hold offset and counters.
 
data flags
 NVPBDIZC.
 
unsigned char cycle_counter
 The cycle counter. The counter is decremented every step.
 
memory mem
 A direct access to the Emulator Memory.
 

Detailed Description

This structure will be used to represent the state of the Central Processing Unit (CPU) of our emulator. This Virtual CPU emulates a "MOS Technology 6502".

Here's some informations about this CPU:

  • It is a 8-bits register with a 16-bits addressing mode.
  • There is 3 work registers: Accumulator, Register Index X, Register Index Y
  • There is a Register that holds the processor intern flags. Here's its layout:
    • N: Negative. Set if the result of an operation is negative.
    • V: Overflow. Set if an arithmetic operation between two numbers cause and integer overflow (For instance: 64+64=-128).
    • P: Unused on the NES, I'll use it as a "paused" state.
    • B: Break. Set if the BRK instruction is encountered or when an interrupt is raised.
    • D: Decimal. When set, the processor will obey the rule of BCD for add and sub.
    • I: Interrupt Disable. When set, the processor will not respond to any interrupt.
    • Z: Zero. Set if the result of the last operation is zero.
    • C: Carry. Set if the last operation caused an overflow from bit 7 or an underflow from bit 0

Definition at line 27 of file cpu.h.

Member Data Documentation

◆ accumulator

data CPU::accumulator

A 8 bit register used to perform operations.

Definition at line 31 of file cpu.h.

Referenced by init_cpu(), main(), print_cpu_state(), and printw_cpu_state().

◆ cache

data CPU::cache

A 8 bit reserved space that I use for some operations.

Definition at line 30 of file cpu.h.

Referenced by init_cpu().

◆ cycle_counter

unsigned char CPU::cycle_counter

The cycle counter. The counter is decremented every step.

Definition at line 37 of file cpu.h.

Referenced by init_cpu(), and step_cpu().

◆ flags

data CPU::flags

NVPBDIZC.

Definition at line 35 of file cpu.h.

Referenced by init_cpu(), main(), and print_cpu_state().

◆ mem

memory CPU::mem

A direct access to the Emulator Memory.

Definition at line 39 of file cpu.h.

Referenced by execute_instruction(), free_cpu(), get_next_instruction(), init_cpu(), main(), print_stack_state(), start_cpu(), and step_cpu().

◆ program_counter

address CPU::program_counter

An address pointing to the next instruction to be executed.

Definition at line 28 of file cpu.h.

Referenced by execute_instruction(), get_next_instruction(), init_cpu(), print_cpu_state(), printw_cpu_state(), start_cpu(), and step_cpu().

◆ register_x

data CPU::register_x

A 8 bit register. Commonly used to hold offset and counters.

Definition at line 32 of file cpu.h.

Referenced by execute_instruction(), get_next_instruction(), init_cpu(), main(), print_cpu_state(), and printw_cpu_state().

◆ register_y

data CPU::register_y

A 8 bit register. Commonly used to hold offset and counters.

Definition at line 33 of file cpu.h.

Referenced by execute_instruction(), get_next_instruction(), init_cpu(), main(), print_cpu_state(), and printw_cpu_state().

◆ stack_pointer

data CPU::stack_pointer

A register that holds the 8 lower bytes of the address 0x11??.

Definition at line 29 of file cpu.h.

Referenced by init_cpu(), main(), print_cpu_state(), print_stack_state(), and printw_cpu_state().


The documentation for this struct was generated from the following file: