Improved debug display.
Bug fixes: POPD and POPP now pull bytes from the stack in proper order.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
// assembly.c
|
||||
// These are functions useful for translating assembly mnemonics to hex and vice-versa for the SplitBit CPU.
|
||||
// Written by Anachronaut
|
||||
// 10/18/2024
|
||||
|
||||
#include "assembly.h"
|
||||
|
||||
typedef struct {
|
||||
uint8_t opcode;
|
||||
const char* mnemonic;
|
||||
} Instruction;
|
||||
|
||||
Instruction instruction_set[] = {
|
||||
// Arithmetic and Logic Operations:
|
||||
{0x00, "ADD"},
|
||||
{0x01, "SUB"},
|
||||
{0x02, "AND"},
|
||||
{0x03, "OR"},
|
||||
{0x04, "NOR"},
|
||||
{0x05, "NAND"},
|
||||
{0x06, "XOR"},
|
||||
{0x07, "NOTA"},
|
||||
{0x08, "NOTB"},
|
||||
// Branch Operations:
|
||||
{0x10, "BRI"},
|
||||
{0x11, "BRQ"},
|
||||
{0x12, "BRA"},
|
||||
{0x13, "BRB"},
|
||||
// Register Operations:
|
||||
{0x20, "RSTA"},
|
||||
{0x21, "RSTB"},
|
||||
{0x22, "INCA"},
|
||||
{0x23, "INCB"},
|
||||
{0x24, "DECA"},
|
||||
{0x25, "DECB"},
|
||||
{0x26, "LDA"},
|
||||
{0x27, "LDB"},
|
||||
{0x28, "INIA"},
|
||||
{0x29, "INIB"},
|
||||
// Stack Operations:
|
||||
{0x30, "PSHQ"},
|
||||
{0x31, "PSHA"},
|
||||
{0x32, "PSHB"},
|
||||
{0x33, "PSHP"},
|
||||
{0x34, "PSHD"},
|
||||
{0x35, "POPA"},
|
||||
{0x36, "POPB"},
|
||||
{0x37, "POPP"},
|
||||
{0x38, "POPD"},
|
||||
// Data Operations:
|
||||
{0x40, "INCD"},
|
||||
{0x41, "DECD"},
|
||||
{0x42, "LDA"},
|
||||
{0x43, "LDB"},
|
||||
{0x44, "STQ"},
|
||||
{0x45, "STA"},
|
||||
{0x46, "STB"},
|
||||
{0x47, "SETD"},
|
||||
// Output Operations:
|
||||
{0xD0, "OUTQ"},
|
||||
{0xD1, "OUTA"},
|
||||
{0xD2, "OUTB"},
|
||||
// Input Operations:
|
||||
{0xE0, "INA"},
|
||||
{0xE1, "INB"},
|
||||
{0xE2, "IND"},
|
||||
// Special Operations:
|
||||
{0xF0, "NOP"},
|
||||
{0xFF, "HALT"}
|
||||
};
|
||||
|
||||
const char* getMnemonic(uint8_t opcode) {
|
||||
int num_instructions = sizeof(instruction_set) / sizeof(Instruction);
|
||||
for (int i = 0; i < num_instructions; i++) {
|
||||
if (instruction_set[i].opcode == opcode) {
|
||||
return instruction_set[i].mnemonic;
|
||||
}
|
||||
}
|
||||
return "---";
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// assembly.c
|
||||
// These are functions useful for translating assembly mnemonics to hex and vice-versa for the SplitBit CPU.
|
||||
// Written by Anachronaut
|
||||
// 10/18/2024
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef ASSEMBLY_H
|
||||
#define ASSEMBLY_H
|
||||
|
||||
const char* getMnemonic(uint8_t opcode);
|
||||
|
||||
#endif // CPU_H
|
||||
+2
-2
@@ -206,18 +206,18 @@ uint8_t executeOperation(uint8_t Instruction, CPURegisters *cpu) {
|
||||
break;
|
||||
case 0x37:
|
||||
// POPP - Pop Data to the Program Counter
|
||||
cpu->StackPointer++;
|
||||
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:
|
||||
// POPD - Pop Data to the Data Pointer
|
||||
cpu->StackPointer++;
|
||||
cpu->DataPointer = (uint16_t)cpu->Data[cpu->StackPointer] << 8;
|
||||
cpu->StackPointer++;
|
||||
cpu->DataPointer |= (uint16_t)cpu->Data[cpu->StackPointer];
|
||||
cpu->StackPointer++;
|
||||
break;
|
||||
//
|
||||
// 4x - Data Operations:
|
||||
|
||||
+3
-2
@@ -7,6 +7,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include "assembly.h"
|
||||
|
||||
void printHelp(const char *programName) {
|
||||
printf("Usage: %s [OPTIONS] <binaryfile>\n", programName);
|
||||
@@ -48,8 +49,8 @@ uint8_t parseOptions(int argc, char *argv[]) {
|
||||
void printRegisters(CPURegisters *cpu, uint8_t *Program, uint8_t *Data) {
|
||||
printf("***** CPU Registers *****\n");
|
||||
printf("A: 0x%02X\tB: 0x%02X\tQ: 0x%02X\tStatus: 0b%08b\n", cpu->A, cpu->B, cpu->Q, cpu->Status);
|
||||
printf("Program Counter: 0x%04X Current Instruction: 0x%02X\n", cpu->ProgramCounter, Program[cpu->ProgramCounter]);
|
||||
printf("Program Counter: 0x%04X Current Instruction: 0x%02X (%s)\n", cpu->ProgramCounter, Program[cpu->ProgramCounter],getMnemonic(Program[cpu->ProgramCounter]));
|
||||
printf(" Data Pointer: 0x%04X Current Data Value: 0x%02X\n", cpu->DataPointer, Data[cpu->DataPointer]);
|
||||
printf(" Stack Pointer: 0x%04X Current Value: 0x%02X\n", cpu->StackPointer, Data[cpu->StackPointer]);
|
||||
printf(" Stack Pointer: 0x%04X Current Value: (0x%02X) (0x%02X)\n", Data[cpu->StackPointer], Data[cpu->StackPointer+1], Data[cpu->StackPointer+2]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user