Bug fixes

Added stack collision detection.
Added SETD instruction.
This commit is contained in:
Anachronaut
2024-10-17 18:40:54 -04:00
committed by GitHub
parent d84e0397f7
commit 158cbf443d
3 changed files with 21 additions and 6 deletions
+14 -1
View File
@@ -5,7 +5,6 @@
#include "cpu.h"
#include "io.h"
#include <stdio.h>
void initializeCPU(CPURegisters *cpu, uint8_t *programMemory, uint8_t *dataMemory) {
cpu->A = 0;
@@ -247,6 +246,15 @@ uint8_t executeOperation(uint8_t Instruction, CPURegisters *cpu) {
// STB - Store B into Data.
cpu->Data[cpu->DataPointer] = cpu->B;
break;
case 0x47:
// SETD - Set the Data Pointer.
cpu->ProgramCounter++;
uint16_t Address;
Address = (uint16_t)cpu->Program[cpu->ProgramCounter] << 8; // Cast the 8 bits to a 16 bit value and shift them to the high byte.
cpu->ProgramCounter++;
Address |= (uint16_t)cpu->Program[cpu->ProgramCounter];
cpu-> DataPointer = Address;
break;
//
// Dx - Output Operations:
//
@@ -301,5 +309,10 @@ uint8_t executeOperation(uint8_t Instruction, CPURegisters *cpu) {
// Unknown Instruction.
return 1;
}
if (cpu->DataPointer >= cpu->StackPointer) {
// A Stack Collision was detected.
cpu->Status |= 0x82; // Set Stack Collision Flag and Halt . (Bits 7 and 1 of the Status Register);
return 2;
}
return 0;
}