Feature: Basic GUI that displays hex information, register information, instruction information.

This commit is contained in:
0x221E
2026-02-06 19:20:42 +01:00
parent caadd2f706
commit 88721ee0da
29 changed files with 8476 additions and 91 deletions

View File

@@ -8,7 +8,7 @@
#include <array>
#include <cassert>
CPU::CPU(std::shared_ptr<Bus> bus) : m_Bus(bus), m_IsHalted(false), m_Context({m_Instruction, m_InstructionPointer, m_Flags, m_Registers, m_Bus, m_IsHalted}) {
CPU::CPU(std::shared_ptr<Bus>& bus) : m_Bus(bus), m_IsHalted(false), m_Context({m_Instruction, m_InstructionPointer, m_Flags, m_Registers, m_Bus, m_IsHalted}) {
m_InstructionPointer = 0x00008000;
for(int i = 0; i < 8; i++)
@@ -44,6 +44,28 @@ void CPU::Dump() {
std::cout << std::endl;
}
void CPU::Reset() {
for(uint8_t i = 0; i < 8; i++)
{
m_Registers[i] = 0;
m_SegmentRegisters[i] = 0;
}
m_InstructionPointer = 0x8000;
m_Flags = 0;
std::cout << "[CPU] State Flushed!" << std::endl;
m_IsHalted = false;
m_Instruction.m_Opcode = (Opcode)0;
m_Instruction.m_Operand1 = 0;
m_Instruction.m_Operand2 = 0;
std::memset(m_Instruction.m_Displacement, 0, 4);
m_Instruction.optional.m_ModRM = (x86::ModRM){ .m_State = x86::ModRMState::INVALID, .m_Reg = 0, .m_Rm = 0 };
}
CPUStatus CPU::GetStatus() {
return (CPUStatus){.m_Registers = m_Registers, .m_IP = m_InstructionPointer, .m_Instruction = m_Instruction};
}
void CPU::FetchDecode() {
uint8_t opcode_raw = m_Bus->AccessX<uint8_t>(m_InstructionPointer);
Opcode opcode = static_cast<Opcode>(opcode_raw);
@@ -83,7 +105,6 @@ void CPU::Execute() {
if(exec_table[opcode_value])
{
exec_table[opcode_value](m_Context);
Dump();
return;
}
throw std::runtime_error("Opcode not found!");
@@ -98,11 +119,16 @@ void CPU::FetchModRMFields() {
break;
case x86::ModRMState::DISP32:
case x86::ModRMState::LR_DISP32:
m_Instruction.m_Operand1 = m_Bus->AccessX<uint32_t>(m_InstructionPointer + m_Instruction.m_Length);
{
uint32_t disp = m_Bus->AccessX<uint32_t>(m_InstructionPointer + m_Instruction.m_Length);
std::memcpy(&m_Instruction.m_Displacement, &disp, 4);
m_Instruction.m_DisplacementSize = 4;
m_Instruction.m_Length += 4;
break;
}
case x86::ModRMState::LR_DISP8:
m_Instruction.m_Operand1 = m_Bus->AccessX<uint8_t>(m_InstructionPointer + m_Instruction.m_Length);
m_Instruction.m_Displacement[0] = m_Bus->AccessX<uint8_t>(m_InstructionPointer + m_Instruction.m_Length);
m_Instruction.m_DisplacementSize = 1;
m_Instruction.m_Length += 1;
break;
default: