01-25-2023, 09:55 AM
Hahaha, tried a smaller task. Genius, std::map in the interpreter...:
> could you try to write just the MIPS CPU interpreter necessary?
Creating a CPU interpreter for the PSP's MIPS processor would also be a complex task, but less ambitious than creating a full PSP emulator. Here is an example of what a basic MIPS interpreter written in C++ might look like.
#include <iostream>
#include <map>
typedef void (*Instruction)(); // Function pointer type for instructions
std::map<unsigned int, Instruction> instructions; // Map of instruction opcodes to functions
unsigned int pc = 0x00000000; // Program counter
unsigned int reg[32]; // General-purpose registers
void add() {
// Decode instruction
unsigned int rd = (instructions[pc] >> 11) & 0x1F;
unsigned int rs = (instructions[pc] >> 21) & 0x1F;
unsigned int rt = (instructions[pc] >> 16) & 0x1F;
// Execute instruction
reg[rd] = reg[rs] + reg[rt];
// Update program counter
pc += 4;
}
void sub() {
// Decode instruction
unsigned int rd = (instructions[pc] >> 11) & 0x1F;
unsigned int rs = (instructions[pc] >> 21) & 0x1F;
unsigned int rt = (instructions[pc] >> 16) & 0x1F;
// Execute instruction
reg[rd] = reg[rs] - reg[rt];
// Update program counter
pc += 4;
}
int main() {
// I stopped it here
> could you try to write just the MIPS CPU interpreter necessary?
Creating a CPU interpreter for the PSP's MIPS processor would also be a complex task, but less ambitious than creating a full PSP emulator. Here is an example of what a basic MIPS interpreter written in C++ might look like.
#include <iostream>
#include <map>
typedef void (*Instruction)(); // Function pointer type for instructions
std::map<unsigned int, Instruction> instructions; // Map of instruction opcodes to functions
unsigned int pc = 0x00000000; // Program counter
unsigned int reg[32]; // General-purpose registers
void add() {
// Decode instruction
unsigned int rd = (instructions[pc] >> 11) & 0x1F;
unsigned int rs = (instructions[pc] >> 21) & 0x1F;
unsigned int rt = (instructions[pc] >> 16) & 0x1F;
// Execute instruction
reg[rd] = reg[rs] + reg[rt];
// Update program counter
pc += 4;
}
void sub() {
// Decode instruction
unsigned int rd = (instructions[pc] >> 11) & 0x1F;
unsigned int rs = (instructions[pc] >> 21) & 0x1F;
unsigned int rt = (instructions[pc] >> 16) & 0x1F;
// Execute instruction
reg[rd] = reg[rs] - reg[rt];
// Update program counter
pc += 4;
}
int main() {
// I stopped it here

