This commit is contained in:
william 2023-09-24 22:02:08 -04:00
parent 69e730141a
commit 31f0c2f937
3 changed files with 105 additions and 24 deletions

BIN
bin/emu

Binary file not shown.

View File

@ -1,26 +1,83 @@
#include "op.h"
#define IS_ALU_OP_CODE_(op, offset) \
case op + offset: \
op_##op(); \
// Reference: https://www.nesdev.org/wiki/CPU_unofficial_opcodes
#define IS_OP_CODE_MODE(op, op_code, addr_mode) \
case op_code: \
op_ ## op(ADDR_MODE_ ## addr_mode); \
break;
#define IS_OP_CODE(op, op_code) \
IS_OP_CODE_MODE(op, op_code, IMPLICIT)
#define IS_ALU_OP_CODE_(op, offset, addr_mode) \
IS_OP_CODE_MODE(op, OP_CODE_ ## op + offset, addr_mode)
#define IS_ALU_OP_CODE(op) \
IS_ALU_OP_CODE_(op, 0x01) \
IS_ALU_OP_CODE_(op, 0x05) \
IS_ALU_OP_CODE_(op, 0x09) \
IS_ALU_OP_CODE_(op, 0x0d) \
IS_ALU_OP_CODE_(op, 0x11) \
IS_ALU_OP_CODE_(op, 0x15) \
IS_ALU_OP_CODE_(op, 0x19) \
IS_ALU_OP_CODE_(op, 0x1d)
IS_ALU_OP_CODE_(op, 0x01, INDEXED_INDIRECT) \
IS_ALU_OP_CODE_(op, 0x05, ZERO_PAGE) \
IS_ALU_OP_CODE_(op, 0x09, IMMEDIATE) \
IS_ALU_OP_CODE_(op, 0x0d, ABSOLUTE) \
IS_ALU_OP_CODE_(op, 0x11, INDIRECT_INDEXED) \
IS_ALU_OP_CODE_(op, 0x15, ZERO_PAGE_INDEXED_X) \
IS_ALU_OP_CODE_(op, 0x19, ABSOLUTE_INDEXED_Y) \
IS_ALU_OP_CODE_(op, 0x1d, ABSOLUTE_INDEXED_X)
#define IS_ALU_OP_CODE_NO_IMMEDIATE(op) \
IS_ALU_OP_CODE_(op, 0x01, INDEXED_INDIRECT) \
IS_ALU_OP_CODE_(op, 0x05, ZERO_PAGE) \
IS_ALU_OP_CODE_(op, 0x0d, ABSOLUTE) \
IS_ALU_OP_CODE_(op, 0x11, INDIRECT_INDEXED) \
IS_ALU_OP_CODE_(op, 0x15, ZERO_PAGE_INDEXED_X) \
IS_ALU_OP_CODE_(op, 0x19, ABSOLUTE_INDEXED_Y) \
IS_ALU_OP_CODE_(op, 0x1d, ABSOLUTE_INDEXED_X)
void op_ORA(addr_mode_t addr_mode) {
}
void op_AND(addr_mode_t addr_mode) {
}
void op_EOR(addr_mode_t addr_mode) {
}
void op_ADC(addr_mode_t addr_mode) {
}
void op_STA(addr_mode_t addr_mode) {
}
void op_LDA(addr_mode_t addr_mode) {
}
void op_CMP(addr_mode_t addr_mode) {
}
void op_SBC(addr_mode_t addr_mode) {
}
void process_op_code(int op) {
switch (op) {
// CTRL
IS_OP_CODE(BRK, 0x00)
IS_OP_CODE_MODE(NOP, 0x04, ZERO_PAGE)
// ALU
IS_ALU_OP_CODE(ORA)
IS_ALU_OP_CODE(AND)
IS_ALU_OP_CODE(EOR)
IS_ALU_OP_CODE(ADC)
IS_ALU_OP_CODE_NO_IMMEDIATE(STA)
IS_ALU_OP_CODE(LDA)
IS_ALU_OP_CODE(CMP)
IS_ALU_OP_CODE(SBC)
}
}
void op_AND() {
}

View File

@ -1,10 +1,34 @@
#ifndef CPU_OP_H
#define CPU_OP_H
// The number associated with each op code is the matching line of the ALU op code.
// Based on the table here: https://www.nesdev.org/wiki/CPU_unofficial_opcodes
enum op_code {
ORA = 0x00,
AND = 0x20,
EOR = 0x40,
ADC = 0x60,
STA = 0x80,
LDA = 0xa0,
CMP = 0xc0,
SBC = 0xe0
OP_CODE_ORA = 0x00,
OP_CODE_AND = 0x20,
OP_CODE_EOR = 0x40,
OP_CODE_ADC = 0x60,
OP_CODE_STA = 0x80,
OP_CODE_LDA = 0xa0,
OP_CODE_CMP = 0xc0,
OP_CODE_SBC = 0xe0
};
typedef enum {
ADDR_MODE_ABSOLUTE, // a
ADDR_MODE_ABSOLUTE_JUMP, // (a)
ADDR_MODE_ABSOLUTE_INDEXED_X, // a,x
ADDR_MODE_ABSOLUTE_INDEXED_Y, // a,y
ADDR_MODE_ACCUMULATOR, // A
ADDR_MODE_IMMEDIATE, // #i
ADDR_MODE_IMPLICIT, // Imp
ADDR_MODE_INDEXED_INDIRECT, // (d,x)
ADDR_MODE_INDIRECT_JUMP, //
ADDR_MODE_INDIRECT_INDEXED, // (d),y
ADDR_MODE_RELATIVE, // label
ADDR_MODE_ZERO_PAGE, // d
ADDR_MODE_ZERO_PAGE_INDEXED_X, // d,x
ADDR_MODE_ZERO_PAGE_INDEXED_Y, // d,y
} addr_mode_t;
#endif