GrafX2 2.9.3227
The ultimate 256-color painting program
|
#include <emulation/CPU/6502.h>
Macros | |
#define | CPU_6502_API Z_API_EXPORT |
#define | READ_8(address) object->read (object->context, (zuint16)(address)) |
#define | WRITE_8(address, value) object->write(object->context, (zuint16)(address), (zuint8)(value)) |
#define | READ_16(address) read_16bit (object, (zuint16)(address)) |
#define | READ_POINTER(pointer_name) READ_16(Z_6502_ADDRESS_##pointer_name##_POINTER) |
#define | PC object->state.Z_6502_STATE_MEMBER_PC |
#define | S object->state.Z_6502_STATE_MEMBER_S |
#define | P object->state.Z_6502_STATE_MEMBER_P |
#define | A object->state.Z_6502_STATE_MEMBER_A |
#define | X object->state.Z_6502_STATE_MEMBER_X |
#define | Y object->state.Z_6502_STATE_MEMBER_Y |
#define | NMI object->state.Z_6502_STATE_MEMBER_NMI |
#define | IRQ object->state.Z_6502_STATE_MEMBER_IRQ |
#define | CYCLES object->cycles |
#define | OPCODE object->opcode |
#define | EA object->ea |
#define | EA_CYCLES object->ea_cycles |
#define | NP 128 |
#define | VP 64 |
#define | BP 16 |
#define | DP 8 |
#define | IP 4 |
#define | ZP 2 |
#define | CP 1 |
#define | NZP (NP | ZP) |
#define | NZCP (NP | ZP | CP) |
#define | ZP_ZERO(value) (!(value) << 1) |
#define | SET_P_NZ(value) P = (P & ~NZP) | ((value) ? ((value) & NP) : ZP) |
#define | PUSH_8(value) WRITE_8(Z_6502_ADDRESS_STACK + S--, value); |
#define | POP_8 READ_8 (Z_6502_ADDRESS_STACK + ++S) |
#define | PUSH_16(value) push_16bit(object, value) |
#define | POP_16 pop_16bit(object) |
#define | READ_BYTE_OPERAND READ_8 ((PC += 2) - 1) |
#define | READ_WORD_OPERAND READ_16((PC += 3) - 2) |
#define | ZERO_PAGE_ADDRESS READ_BYTE_OPERAND |
#define | ZERO_PAGE_X_ADDRESS (zuint8)(READ_BYTE_OPERAND + X) |
#define | ZERO_PAGE_Y_ADDRESS (zuint8)(READ_BYTE_OPERAND + Y) |
#define | ABSOLUTE_ADDRESS READ_WORD_OPERAND |
#define | ABSOLUTE_X_ADDRESS READ_WORD_OPERAND + X |
#define | ABSOLUTE_Y_ADDRESS READ_WORD_OPERAND + Y |
#define | INDIRECT_X_ADDRESS READ_16((zuint8)(READ_BYTE_OPERAND + X)) |
#define | INDIRECT_Y_ADDRESS READ_16(READ_BYTE_OPERAND) + Y |
#define | EA_READER(name) static zuint8 read_##name (M6502 *object) |
#define | EA_WRITER(name) static void write_##name(M6502 *object, zuint8 value) |
#define | EA_INDEX (OPCODE & 28) >> 2 |
#define | READ_J read_j_table [EA_INDEX](object) |
#define | READ_G read_g_table [EA_INDEX](object) |
#define | READ_H read_h_table [EA_INDEX](object) |
#define | READ_Q read_q_table [EA_INDEX](object) |
#define | WRITE_K(value) write_k_table[EA_INDEX](object, value) |
#define | WRITE_H(value) write_h_table[EA_INDEX](object, value) |
#define | WRITE_Q(value) write_q_table[EA_INDEX](object, value) |
#define | WRITE_G(value) if (EA_CYCLES == 2) A = value; else WRITE_8(EA, value); |
#define | INSTRUCTION(name) static zuint8 name(M6502 *object) |
#define | COMPARE(register, ea_table) |
#define | BRANCH(flag_mask, condition_logic) |
#define | BRANCH_IF_CLEAR(flag_mask) BRANCH(flag_mask, !) |
#define | BRANCH_IF_SET( flag_mask) BRANCH(flag_mask, Z_EMPTY) |
#define | INC_DEC(operation) |
Typedefs | |
typedef zuint8(* | Instruction) (M6502 *object) |
typedef zuint8(* | ReadEA) (M6502 *object) |
typedef void(* | WriteEA) (M6502 *object, zuint8 value) |
Functions | |
static Z_INLINE zuint16 | read_16bit (M6502 *object, zuint16 address) |
static Z_INLINE void | push_16bit (M6502 *object, zuint16 value) |
static Z_INLINE zuint16 | pop_16bit (M6502 *object) |
EA_READER (accumulator) | |
EA_READER (immediate) | |
EA_READER (zero_page) | |
EA_READER (zero_page_x) | |
EA_READER (zero_page_y) | |
EA_READER (absolute) | |
EA_READER (indirect_x) | |
EA_READER (g_zero_page) | |
EA_READER (g_zero_page_x) | |
EA_READER (g_absolute) | |
EA_READER (g_absolute_x) | |
EA_READER (penalized_absolute_x) | |
EA_READER (penalized_absolute_y) | |
EA_READER (penalized_indirect_y) | |
EA_WRITER (zero_page) | |
EA_WRITER (zero_page_x) | |
EA_WRITER (zero_page_y) | |
EA_WRITER (absolute) | |
EA_WRITER (absolute_x) | |
EA_WRITER (absolute_y) | |
EA_WRITER (indirect_x) | |
EA_WRITER (indirect_y) | |
INSTRUCTION (lda_J) | |
INSTRUCTION (ldx_H) | |
INSTRUCTION (ldy_Q) | |
INSTRUCTION (sta_K) | |
INSTRUCTION (stx_H) | |
INSTRUCTION (sty_Q) | |
INSTRUCTION (tax) | |
INSTRUCTION (tay) | |
INSTRUCTION (txa) | |
INSTRUCTION (tya) | |
INSTRUCTION (tsx) | |
INSTRUCTION (txs) | |
INSTRUCTION (pha) | |
INSTRUCTION (php) | |
INSTRUCTION (pla) | |
INSTRUCTION (plp) | |
INSTRUCTION (and_J) | |
INSTRUCTION (eor_J) | |
INSTRUCTION (ora_J) | |
INSTRUCTION (bit_Q) | |
INSTRUCTION (cmp_J) | |
INSTRUCTION (cpx_Q) | |
INSTRUCTION (cpy_Q) | |
INSTRUCTION (adc_J) | |
INSTRUCTION (sbc_J) | |
INSTRUCTION (inc_G) | |
INSTRUCTION (inx) | |
INSTRUCTION (iny) | |
INSTRUCTION (dec_G) | |
INSTRUCTION (dex) | |
INSTRUCTION (dey) | |
INSTRUCTION (asl_G) | |
INSTRUCTION (lsr_G) | |
INSTRUCTION (rol_G) | |
INSTRUCTION (ror_G) | |
INSTRUCTION (jmp_WORD) | |
INSTRUCTION (jmp_vWORD) | |
INSTRUCTION (jsr_WORD) | |
INSTRUCTION (rts) | |
INSTRUCTION (bcc_OFFSET) | |
INSTRUCTION (bcs_OFFSET) | |
INSTRUCTION (beq_OFFSET) | |
INSTRUCTION (bmi_OFFSET) | |
INSTRUCTION (bne_OFFSET) | |
INSTRUCTION (bpl_OFFSET) | |
INSTRUCTION (bvc_OFFSET) | |
INSTRUCTION (bvs_OFFSET) | |
INSTRUCTION (clc) | |
INSTRUCTION (cld) | |
INSTRUCTION (cli) | |
INSTRUCTION (clv) | |
INSTRUCTION (sec) | |
INSTRUCTION (sed) | |
INSTRUCTION (sei) | |
INSTRUCTION (nop) | |
INSTRUCTION (rti) | |
INSTRUCTION (brk) | |
INSTRUCTION (illegal) | |
CPU_6502_API void | m6502_power (M6502 *object, zboolean state) |
Changes the CPU power status. More... | |
CPU_6502_API void | m6502_reset (M6502 *object) |
Resets the CPU. More... | |
CPU_6502_API zusize | m6502_run (M6502 *object, zusize cycles) |
Runs the CPU for a given number of cycles . More... | |
CPU_6502_API void | m6502_nmi (M6502 *object) |
Performs a non-maskable interrupt (NMI). More... | |
CPU_6502_API void | m6502_irq (M6502 *object, zboolean state) |
Changes the state of the maskable interrupt (IRQ). More... | |
Variables | |
static ReadEA const | read_j_table [8] |
static WriteEA const | write_k_table [8] |
static ReadEA const | read_g_table [8] |
static ReadEA const | read_h_table [8] |
static WriteEA const | write_h_table [8] |
static ReadEA const | read_q_table [8] |
static WriteEA const | write_q_table [6] |
static Instruction const | instruction_table [256] |
#define CPU_6502_API Z_API_EXPORT |
#define READ_8 | ( | address | ) | object->read (object->context, (zuint16)(address)) |
#define WRITE_8 | ( | address, | |
value | |||
) | object->write(object->context, (zuint16)(address), (zuint8)(value)) |
#define READ_16 | ( | address | ) | read_16bit (object, (zuint16)(address)) |
#define READ_POINTER | ( | pointer_name | ) | READ_16(Z_6502_ADDRESS_##pointer_name##_POINTER) |
#define PC object->state.Z_6502_STATE_MEMBER_PC |
#define S object->state.Z_6502_STATE_MEMBER_S |
#define P object->state.Z_6502_STATE_MEMBER_P |
#define A object->state.Z_6502_STATE_MEMBER_A |
#define X object->state.Z_6502_STATE_MEMBER_X |
#define Y object->state.Z_6502_STATE_MEMBER_Y |
#define NMI object->state.Z_6502_STATE_MEMBER_NMI |
#define IRQ object->state.Z_6502_STATE_MEMBER_IRQ |
#define CYCLES object->cycles |
#define OPCODE object->opcode |
#define EA object->ea |
#define EA_CYCLES object->ea_cycles |
#define NP 128 |
#define VP 64 |
#define BP 16 |
#define DP 8 |
#define IP 4 |
#define ZP 2 |
#define CP 1 |
#define ZP_ZERO | ( | value | ) | (!(value) << 1) |
#define PUSH_8 | ( | value | ) | WRITE_8(Z_6502_ADDRESS_STACK + S--, value); |
#define POP_8 READ_8 (Z_6502_ADDRESS_STACK + ++S) |
#define PUSH_16 | ( | value | ) | push_16bit(object, value) |
#define POP_16 pop_16bit(object) |
#define ZERO_PAGE_ADDRESS READ_BYTE_OPERAND |
#define ZERO_PAGE_X_ADDRESS (zuint8)(READ_BYTE_OPERAND + X) |
#define ZERO_PAGE_Y_ADDRESS (zuint8)(READ_BYTE_OPERAND + Y) |
#define ABSOLUTE_ADDRESS READ_WORD_OPERAND |
#define ABSOLUTE_X_ADDRESS READ_WORD_OPERAND + X |
#define ABSOLUTE_Y_ADDRESS READ_WORD_OPERAND + Y |
#define INDIRECT_X_ADDRESS READ_16((zuint8)(READ_BYTE_OPERAND + X)) |
#define INDIRECT_Y_ADDRESS READ_16(READ_BYTE_OPERAND) + Y |
#define EA_INDEX (OPCODE & 28) >> 2 |
#define READ_J read_j_table [EA_INDEX](object) |
#define READ_G read_g_table [EA_INDEX](object) |
#define READ_H read_h_table [EA_INDEX](object) |
#define READ_Q read_q_table [EA_INDEX](object) |
#define WRITE_K | ( | value | ) | write_k_table[EA_INDEX](object, value) |
#define WRITE_H | ( | value | ) | write_h_table[EA_INDEX](object, value) |
#define WRITE_Q | ( | value | ) | write_q_table[EA_INDEX](object, value) |
#define COMPARE | ( | register, | |
ea_table | |||
) |
#define BRANCH | ( | flag_mask, | |
condition_logic | |||
) |
#define BRANCH_IF_CLEAR | ( | flag_mask | ) | BRANCH(flag_mask, !) |
#define INC_DEC | ( | operation | ) |
References S, WRITE_8, and Z_6502_ADDRESS_STACK.
References READ_8, S, and Z_6502_ADDRESS_STACK.
EA_READER | ( | immediate | ) |
References EA_CYCLES, and READ_BYTE_OPERAND.
EA_READER | ( | zero_page | ) |
References EA_CYCLES, READ_8, and ZERO_PAGE_ADDRESS.
EA_READER | ( | zero_page_x | ) |
References EA_CYCLES, READ_8, and ZERO_PAGE_X_ADDRESS.
EA_READER | ( | zero_page_y | ) |
References EA_CYCLES, READ_8, and ZERO_PAGE_Y_ADDRESS.
EA_READER | ( | absolute | ) |
References ABSOLUTE_ADDRESS, EA_CYCLES, and READ_8.
EA_READER | ( | indirect_x | ) |
References EA_CYCLES, INDIRECT_X_ADDRESS, and READ_8.
EA_READER | ( | g_zero_page | ) |
References EA, EA_CYCLES, READ_8, and ZERO_PAGE_ADDRESS.
EA_READER | ( | g_zero_page_x | ) |
References EA, EA_CYCLES, READ_8, and ZERO_PAGE_X_ADDRESS.
EA_READER | ( | g_absolute | ) |
References ABSOLUTE_ADDRESS, EA, EA_CYCLES, and READ_8.
EA_READER | ( | g_absolute_x | ) |
References ABSOLUTE_X_ADDRESS, EA, EA_CYCLES, and READ_8.
EA_READER | ( | penalized_absolute_x | ) |
References EA_CYCLES, READ_8, READ_WORD_OPERAND, and X.
EA_READER | ( | penalized_absolute_y | ) |
References EA_CYCLES, READ_8, READ_WORD_OPERAND, and Y.
EA_READER | ( | penalized_indirect_y | ) |
References EA_CYCLES, READ_16, READ_8, READ_BYTE_OPERAND, and Y.
EA_WRITER | ( | zero_page | ) |
References EA_CYCLES, WRITE_8, and ZERO_PAGE_ADDRESS.
EA_WRITER | ( | zero_page_x | ) |
References EA_CYCLES, WRITE_8, and ZERO_PAGE_X_ADDRESS.
EA_WRITER | ( | zero_page_y | ) |
References EA_CYCLES, WRITE_8, and ZERO_PAGE_Y_ADDRESS.
EA_WRITER | ( | absolute | ) |
References ABSOLUTE_ADDRESS, EA_CYCLES, and WRITE_8.
EA_WRITER | ( | absolute_x | ) |
References ABSOLUTE_X_ADDRESS, EA_CYCLES, and WRITE_8.
EA_WRITER | ( | absolute_y | ) |
References ABSOLUTE_Y_ADDRESS, EA_CYCLES, and WRITE_8.
EA_WRITER | ( | indirect_x | ) |
References EA_CYCLES, INDIRECT_X_ADDRESS, and WRITE_8.
EA_WRITER | ( | indirect_y | ) |
References EA_CYCLES, INDIRECT_Y_ADDRESS, and WRITE_8.
INSTRUCTION | ( | inc_G | ) |
References INC_DEC.
INSTRUCTION | ( | dec_G | ) |
References INC_DEC.
INSTRUCTION | ( | bcc_OFFSET | ) |
References BRANCH_IF_CLEAR, and CP.
INSTRUCTION | ( | bcs_OFFSET | ) |
References BRANCH_IF_SET, and CP.
INSTRUCTION | ( | beq_OFFSET | ) |
References BRANCH_IF_SET, and ZP.
INSTRUCTION | ( | bmi_OFFSET | ) |
References BRANCH_IF_SET, and NP.
INSTRUCTION | ( | bne_OFFSET | ) |
References BRANCH_IF_CLEAR, and ZP.
INSTRUCTION | ( | bpl_OFFSET | ) |
References BRANCH_IF_CLEAR, and NP.
INSTRUCTION | ( | bvc_OFFSET | ) |
References BRANCH_IF_CLEAR, and VP.
INSTRUCTION | ( | bvs_OFFSET | ) |
References BRANCH_IF_SET, and VP.
INSTRUCTION | ( | nop | ) |
References PC.
INSTRUCTION | ( | illegal | ) |
CPU_6502_API void m6502_power | ( | M6502 * | object, |
zboolean | state | ||
) |
Changes the CPU power status.
object | A pointer to a 6502 emulator instance. |
state | TRUE = power ON; FALSE = power OFF. |
References A, FALSE, IRQ, NMI, P, PC, S, X, Y, Z_6502_VALUE_AFTER_POWER_ON_A, Z_6502_VALUE_AFTER_POWER_ON_P, Z_6502_VALUE_AFTER_POWER_ON_PC, Z_6502_VALUE_AFTER_POWER_ON_S, Z_6502_VALUE_AFTER_POWER_ON_X, and Z_6502_VALUE_AFTER_POWER_ON_Y.
Referenced by C64_LoadPrg().
CPU_6502_API void m6502_reset | ( | M6502 * | object | ) |
Resets the CPU.
This is equivalent to a pulse on the RESET line of a real 6502.
object | A pointer to a 6502 emulator instance. |
References FALSE, IRQ, NMI, P, PC, READ_POINTER, S, Z_6502_VALUE_AFTER_POWER_ON_P, and Z_6502_VALUE_AFTER_POWER_ON_S.
CPU_6502_API zusize m6502_run | ( | M6502 * | object, |
zusize | cycles | ||
) |
Runs the CPU for a given number of cycles
.
object | A pointer to a 6502 emulator instance. |
cycles | The number of cycles to be executed. |
cycles
specfified. References CYCLES, FALSE, instruction_table, IP, IRQ, NMI, OPCODE, P, PC, PUSH_16, PUSH_8, READ_8, and READ_POINTER.
Referenced by C64_LoadPrg().
CPU_6502_API void m6502_nmi | ( | M6502 * | object | ) |
CPU_6502_API void m6502_irq | ( | M6502 * | object, |
zboolean | state | ||
) |
Changes the state of the maskable interrupt (IRQ).
This is equivalent to a change on the IRQ line of a real 6502.
object | A pointer to a 6502 emulator instance. |
state | TRUE = line high; FALSE = line low. |
References IRQ.
Referenced by C64_LoadPrg(), and C64_mem_write().
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Referenced by m6502_run().