From 60450253cdfac9c098d76f01efff34d4ee1dfae4 Mon Sep 17 00:00:00 2001 From: Anachronaut <75824887+RealBusinessAccount@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:23:03 -0400 Subject: [PATCH] Assorted bug fixes. Added INIA and INIB instructions. --- Source/cpu.c | 16 ++++++++++------ Source/emulator.c | 1 + SplitBit Programming Manual.md | 4 ++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Source/cpu.c b/Source/cpu.c index 6148321..29c5c43 100644 --- a/Source/cpu.c +++ b/Source/cpu.c @@ -150,12 +150,14 @@ uint8_t executeOperation(uint8_t Instruction, CPURegisters *cpu) { cpu->B = cpu->Data[cpu->DataPointer]; break; case 0x28: - // INCD - Add 1 to the Data Pointer. - cpu->DataPointer++; + // INIA - Initialize A Immediately from Program Memory. + cpu->ProgramCounter++; + cpu->A = cpu->Data[cpu->ProgramCounter]; break; case 0x29: - // DECD - Subtract 1 from the Data Pointer. - cpu->DataPointer--; + // INIB - Initialize A Immediately from Program Memory. + cpu->ProgramCounter++; + cpu->B = cpu->Data[cpu->ProgramCounter]; break; // // 3x - Stack Operations: @@ -193,19 +195,21 @@ uint8_t executeOperation(uint8_t Instruction, CPURegisters *cpu) { break; case 0x35: // POPA - Pop Data to A. - cpu->A = cpu->Data[cpu->StackPointer]; cpu->StackPointer++; + cpu->A = cpu->Data[cpu->StackPointer]; + break; case 0x36: // POPB - Pop Data to B. - cpu->B = cpu->Data[cpu->StackPointer]; cpu->StackPointer++; + cpu->B = cpu->Data[cpu->StackPointer]; break; case 0x37: // POPP - Pop Data to the Program Counter cpu->ProgramCounter = (uint16_t)cpu->Data[cpu->StackPointer] << 8; cpu->StackPointer++; cpu->ProgramCounter = cpu->ProgramCounter | (uint16_t)cpu->Data[cpu->StackPointer]; + cpu->ProgramCounter += 3; // Because it needs to skip over the subsequent branch instruction on return. cpu->StackPointer++; break; case 0x38: diff --git a/Source/emulator.c b/Source/emulator.c index 11e2a84..1216be6 100644 --- a/Source/emulator.c +++ b/Source/emulator.c @@ -57,6 +57,7 @@ int main (int argc, char *argv[]) { if (debugEnable) { getchar(); printRegisters(&cpu, Program, Data); + printf("Cycle: %u\n", cycleCount); } } printf("Execution halted after %u cycles.\n", cycleCount); diff --git a/SplitBit Programming Manual.md b/SplitBit Programming Manual.md index bdd6433..5380821 100644 --- a/SplitBit Programming Manual.md +++ b/SplitBit Programming Manual.md @@ -46,6 +46,10 @@ Hex Code | Mnemonic | Description | 23 | INCB | Adds 1 to B. | | 24 | DECA | Subtracts 1 from A. | | 25 | DECB | Subtracts 1 from B. | +| 26 | LDA | Loads Data to A via the Data Pointer. | +| 27 | LDB | Loads Data to B via the Data Pointer. +| 28 | INIA | Loads the next byte of Program Memory to A. | +| 29 | INIB | Loads the next byte of Program Memory to B. | ### Stack Operations: 9 Instructions Hex Code | Mnemonic | Description