2017-12-02 19:05:53 +00:00
|
|
|
/*
|
|
|
|
* mos6502.enums.h
|
|
|
|
* Enums and other symbols for use with the mos 6502
|
|
|
|
*
|
|
|
|
* We have separated the definitions of address mode types, instruction
|
|
|
|
* types, etc. into their own file so that we can include it in our main
|
|
|
|
* source file, as well as from our unit test suite, without necessarily
|
|
|
|
* adding them to the global namespace throughout the application.
|
|
|
|
*/
|
|
|
|
|
2017-12-07 03:25:47 +00:00
|
|
|
#ifndef _MOS6502_ENUMS_H_
|
|
|
|
#define _MOS6502_ENUMS_H_
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This defines all of the flags that are possible within the status (P)
|
|
|
|
* register. Note that there is intentionally _no_ definition for the
|
|
|
|
* 6th bit.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
enum status_flags {
|
2018-01-05 20:18:39 +00:00
|
|
|
MOS_CARRY = 1,
|
|
|
|
MOS_ZERO = 2,
|
|
|
|
MOS_INTERRUPT = 4,
|
|
|
|
MOS_DECIMAL = 8,
|
|
|
|
MOS_BREAK = 16,
|
|
|
|
MOS_OVERFLOW = 64,
|
|
|
|
MOS_NEGATIVE = 128,
|
2017-12-02 19:05:53 +00:00
|
|
|
};
|
|
|
|
|
2018-01-21 03:01:26 +00:00
|
|
|
#define MOS_NVZ (MOS_NEGATIVE | MOS_OVERFLOW | MOS_ZERO)
|
|
|
|
#define MOS_NVZC (MOS_NEGATIVE | MOS_OVERFLOW | MOS_ZERO | MOS_CARRY)
|
|
|
|
#define MOS_NZ (MOS_NEGATIVE | MOS_ZERO)
|
|
|
|
#define MOS_NZC (MOS_NEGATIVE | MOS_ZERO | MOS_CARRY)
|
|
|
|
#define MOS_ZC (MOS_ZERO | MOS_CARRY)
|
|
|
|
|
2018-01-22 03:33:12 +00:00
|
|
|
#define MOS_STATUS_DEFAULT (MOS_NEGATIVE | MOS_OVERFLOW | \
|
|
|
|
MOS_INTERRUPT | MOS_ZERO | MOS_CARRY)
|
|
|
|
|
2017-12-07 03:25:47 +00:00
|
|
|
/*
|
|
|
|
* Here we define the various address modes that are possible. These do
|
|
|
|
* not map to any significant numbers that are documented for the 6502
|
|
|
|
* processor; the position of these symbols don't really matter, and are
|
|
|
|
* generally (except for `NOA`, no address mode) in alphabetical order.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
enum addr_mode {
|
|
|
|
NOA, // no address mode
|
|
|
|
ACC, // accumulator
|
|
|
|
ABS, // absolute
|
|
|
|
ABX, // absolute x-index
|
|
|
|
ABY, // absolute y-index
|
2018-02-22 20:07:05 +00:00
|
|
|
BY2, // Consume 2 bytes (for NP2)
|
|
|
|
BY3, // Consume 3 bytes (for NP3)
|
2017-12-02 19:05:53 +00:00
|
|
|
IMM, // immediate
|
|
|
|
IMP, // implied
|
|
|
|
IND, // indirect
|
|
|
|
IDX, // x-index indirect
|
|
|
|
IDY, // indirect y-index
|
|
|
|
REL, // relative
|
|
|
|
ZPG, // zero page
|
|
|
|
ZPX, // zero page x-index
|
|
|
|
ZPY, // zero page y-index
|
|
|
|
};
|
|
|
|
|
2017-12-07 03:25:47 +00:00
|
|
|
/*
|
|
|
|
* These define the various instructions as enum symbols; again, like
|
|
|
|
* for address modes, the values of these enums are not actually
|
|
|
|
* significant to the 6502 processor, and are only useful to we, the
|
|
|
|
* programmers.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
enum instruction {
|
|
|
|
ADC, // ADd with Carry
|
|
|
|
AND, // bitwise AND
|
|
|
|
ASL, // Arithmetic Shift Left
|
2018-01-21 18:48:34 +00:00
|
|
|
BAD, // bad instruction
|
2017-12-02 19:05:53 +00:00
|
|
|
BCC, // Branch on Carry Clear
|
|
|
|
BCS, // Branch on Carry Set
|
|
|
|
BEQ, // Branch on EQual to zero
|
|
|
|
BIT, // BIT test
|
2018-02-22 03:01:46 +00:00
|
|
|
BIM, // BIt test (imMediate mode) (* not a real instruction in the processor; just used by us)
|
2017-12-02 19:05:53 +00:00
|
|
|
BMI, // Branch on MInus
|
|
|
|
BNE, // Branch on Not Equal to zero
|
|
|
|
BPL, // Branch on PLus
|
2018-02-22 03:57:21 +00:00
|
|
|
BRA, // BRanch Always
|
2017-12-02 19:05:53 +00:00
|
|
|
BRK, // BReaK (interrupt)
|
|
|
|
BVC, // Branch on oVerflow Clear
|
|
|
|
BVS, // Branch on oVerflow Set
|
|
|
|
CLC, // CLear Carry
|
|
|
|
CLD, // CLear Decimal
|
|
|
|
CLI, // CLear Interrupt disable
|
|
|
|
CLV, // CLear oVerflow
|
|
|
|
CMP, // CoMPare
|
|
|
|
CPX, // ComPare with X register
|
|
|
|
CPY, // ComPare with Y register
|
|
|
|
DEC, // DECrement
|
|
|
|
DEX, // DEcrement X
|
|
|
|
DEY, // DEcrement Y
|
|
|
|
EOR, // Exclusive OR
|
|
|
|
INC, // INCrement
|
|
|
|
INX, // INcrement X
|
|
|
|
INY, // INcrement Y
|
|
|
|
JMP, // JuMP
|
|
|
|
JSR, // Jump to SubRoutine
|
|
|
|
LDA, // LoaD Accumulator
|
|
|
|
LDX, // LoaD X
|
|
|
|
LDY, // LoaD Y
|
|
|
|
LSR, // Logical Shift Right
|
|
|
|
NOP, // NO oPeration
|
2018-02-22 20:07:05 +00:00
|
|
|
NP2, // No oPeration (2 bytes consumed)
|
|
|
|
NP3, // No oPeration (3 bytes consumed)
|
2017-12-02 19:05:53 +00:00
|
|
|
ORA, // OR with Accumulator
|
|
|
|
PHA, // PusH Accumulator
|
|
|
|
PHP, // PusH Predicate register
|
2018-02-22 05:32:57 +00:00
|
|
|
PHX, // PusH X register
|
|
|
|
PHY, // PusH Y register
|
2017-12-02 19:05:53 +00:00
|
|
|
PLA, // PulL Accumulator
|
|
|
|
PLP, // PulL Predicate register
|
2018-02-22 05:32:57 +00:00
|
|
|
PLX, // PulL X register
|
|
|
|
PLY, // PulL Y register
|
2017-12-02 19:05:53 +00:00
|
|
|
ROL, // ROtate Left
|
|
|
|
ROR, // ROtate Right
|
|
|
|
RTI, // ReTurn from Interrupt
|
|
|
|
RTS, // ReTurn from Subroutine
|
|
|
|
SBC, // SuBtract with Carry
|
|
|
|
SEC, // SEt Carry
|
|
|
|
SED, // SEt Decimal
|
|
|
|
SEI, // SEt Interrupt disable
|
|
|
|
STA, // STore Accumulator
|
|
|
|
STX, // STore X
|
|
|
|
STY, // STore Y
|
2018-02-22 06:02:57 +00:00
|
|
|
STZ, // STore Zero
|
2017-12-02 19:05:53 +00:00
|
|
|
TAX, // Transfer Accumulator to X
|
|
|
|
TAY, // Transfer Accumulator to Y
|
2018-02-22 06:39:33 +00:00
|
|
|
TRB, // Test and Reset Bits
|
2018-02-22 19:39:48 +00:00
|
|
|
TSB, // Test and Set Bits
|
2017-12-02 19:05:53 +00:00
|
|
|
TSX, // Transfer Stack register to X
|
|
|
|
TXA, // Transfer X to Accumulator
|
|
|
|
TXS, // Transfer X to Stack register
|
|
|
|
TYA, // Transfer Y to Accumulator
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|