62 lines
1.5 KiB
C++
62 lines
1.5 KiB
C++
#include "../include/instruction.h"
|
|
|
|
Instruction::Instruction(unsigned short opcode) : opcode(opcode) {
|
|
|
|
}
|
|
|
|
/**
|
|
* Gets the NNN Chip8 value, also known as the addr.
|
|
* This is a 12-bit value, the lowest 12 bits of the instruction.
|
|
* @return
|
|
*/
|
|
unsigned short Instruction::nnn() const {
|
|
return this->opcode & 0x0FFF;
|
|
}
|
|
|
|
/**
|
|
* Gets the N Chip8 value, also known as the nibble.
|
|
* This is a 4-bit value, the lowest 4 bits of the instruction.
|
|
* @return
|
|
*/
|
|
unsigned char Instruction::n() const {
|
|
return this->opcode & 0x000F;
|
|
}
|
|
|
|
/**
|
|
* Gets the KK Chip8 value, also known as byte (or NN by Wikipedia).
|
|
* The naming is inconsistent, as Wikipedia has it as NN
|
|
* and http://devernay.free.fr/hacks/chip8/C8TECH10.HTM has it as KK (with byte as alternative name).
|
|
* This is a 8-bit value, the lowest 8 bits of the instruction.
|
|
* @return
|
|
*/
|
|
unsigned short Instruction::kk() const {
|
|
return this->opcode & 0x00FF;
|
|
}
|
|
|
|
/**
|
|
* Gets the X Chip8 value.
|
|
* This is a 4-bit value, the lower 4 bits of the high byte of the instruction.
|
|
* The high byte is the second nibble.
|
|
* Example:
|
|
*
|
|
* 0101 1010 1100 0011
|
|
* Here, the 1010 is the X value.
|
|
* @return
|
|
*/
|
|
unsigned char Instruction::x() const {
|
|
return (this->opcode & 0x0F00) >> 8;
|
|
}
|
|
|
|
/**
|
|
* Gets the Y Chip8 value.
|
|
* This is a 4-bit value, the upper 4 bits of the low byte of the instruction.
|
|
* The low byte is the second nibble.
|
|
* Example:
|
|
*
|
|
* 0101 1010 1100 0011
|
|
* Here, the 1100 is the Y value.
|
|
* @return
|
|
*/
|
|
unsigned char Instruction::y() const {
|
|
return (this->opcode & 0x00F0) >> 4;
|
|
} |