61 lines
1.7 KiB
C
61 lines
1.7 KiB
C
#pragma once
|
|
#pragma warning (disable : 6011 6387 28182)
|
|
|
|
typedef struct memory_t memory_t;
|
|
typedef struct cpu_t cpu_t;
|
|
typedef struct display_t display_t;
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
#include "memory.h"
|
|
#include "display.h"
|
|
#include "utils.h"
|
|
#include "instructions/instructions.h"
|
|
|
|
// Initialization
|
|
#define PC_PROGRAM_START 0x00300200 // Execution starting address
|
|
#define PR_INIT_VALUE 0xffeeeeee // Random value used to check for app return
|
|
#define SR_INIT_VALUE 0x700000f0 // Status Register initialization value (from doc)
|
|
|
|
#define SYSCALL_ADDRESS 0x80010070 // The calling convention to access the system calls, is to jump to 0x80010070 with the syscall number in r0
|
|
|
|
// Status Register bits
|
|
#define SR_BIT_T 0
|
|
|
|
// CPU
|
|
struct cpu_t {
|
|
// General registers R0 - R15
|
|
int32_t r[16];
|
|
|
|
// Control registers
|
|
uint32_t gbr; // Global base register
|
|
uint32_t sr; // Status register (0: T Bit)
|
|
|
|
// System registers
|
|
uint32_t pc; // Program counter
|
|
uint32_t pr; // Procedure register
|
|
uint32_t mach; // Multiply-accumulate high
|
|
uint32_t macl; // Multiply-accumulate low
|
|
|
|
// To sort
|
|
uint32_t vbr; // Vector base register
|
|
uint32_t ssr; // Saved status register
|
|
uint32_t sgr; // Saved general register
|
|
uint32_t spc; // Saved program counter
|
|
uint32_t dbr; // Debug base register
|
|
|
|
// Custom variables
|
|
uint8_t isExecutionFinished; // Set to true when PR == PC_PROGRAM_START
|
|
|
|
// Debug
|
|
uint32_t instruction_count;
|
|
uint8_t* asciiTexture;
|
|
|
|
// External Components
|
|
memory_t* mem; // Memory
|
|
display_t* disp; // Display
|
|
};
|
|
|
|
void run_next_instruction(cpu_t* cpu); |