Implemented 0x2NNN
							parent
							
								
									fce922f6c6
								
							
						
					
					
						commit
						3aacfdf537
					
				| 
						 | 
					@ -68,9 +68,17 @@ public:
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    [[nodiscard]] unsigned short popFromStack();
 | 
					    [[nodiscard]] unsigned short popFromStack();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void pushToStack(unsigned short value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Sets the program counter (PC) to the given value
 | 
					     * Sets the program counter (PC) to the given value
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    void setProgramCounter(unsigned short value);
 | 
					    void setProgramCounter(unsigned short value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Gets the program counter (PC)
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    [[nodiscard]] unsigned short getProgramCounter() const;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
#endif //CHIP8_CHIP8_H
 | 
					#endif //CHIP8_CHIP8_H
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,6 +29,11 @@ private:
 | 
				
			||||||
     * Handles Chip8 instruction 0x1000
 | 
					     * Handles Chip8 instruction 0x1000
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    static void handle1000(Chip8&, Instruction);
 | 
					    static void handle1000(Chip8&, Instruction);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Handles Chip8 instruction 0x2000
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    static void handle2000(Chip8&, Instruction);
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    InstructionHandler();
 | 
					    InstructionHandler();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -54,6 +54,14 @@ unsigned short Chip8::popFromStack() {
 | 
				
			||||||
    return value;
 | 
					    return value;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Chip8::pushToStack(unsigned short value) {
 | 
				
			||||||
 | 
					    this->stack.push(value);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Chip8::setProgramCounter(unsigned short value) {
 | 
					void Chip8::setProgramCounter(unsigned short value) {
 | 
				
			||||||
    this->pc = value;
 | 
					    this->pc = value;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsigned short Chip8::getProgramCounter() const {
 | 
				
			||||||
 | 
					    return this->pc;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,3 +56,15 @@ void InstructionHandler::handle1000(Chip8& chip8, Instruction instruction) {
 | 
				
			||||||
    chip8.setProgramCounter(instruction.nnn());
 | 
					    chip8.setProgramCounter(instruction.nnn());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Handles the 0x2NNN Chip8 instruction which is used to call a subroutine at NNN.
 | 
				
			||||||
 | 
					 * This will increments the stack pointer and puts PC on top of the stack.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param chip8 The Chip8 instance
 | 
				
			||||||
 | 
					 * @param instruction The Instruction instance
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void InstructionHandler::handle2000(Chip8& chip8, Instruction instruction) {
 | 
				
			||||||
 | 
					    chip8.pushToStack(chip8.getProgramCounter());
 | 
				
			||||||
 | 
					    chip8.setProgramCounter(instruction.nnn());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue