mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-07-20 14:01:44 +12:00
Update opengl.hpp, start with ELFs
This commit is contained in:
parent
1a8d563041
commit
51689af51f
8 changed files with 469 additions and 392 deletions
|
@ -9,7 +9,7 @@ CPU::CPU(Memory& mem) : mem(mem) {
|
|||
// Write some code to memory.
|
||||
env.MemoryWrite16(0, 0x0088); // lsls r0, r1, #2
|
||||
env.MemoryWrite16(2, 0x3045); // adds r0, #69
|
||||
env.MemoryWrite16(4, 0xdf45); // swi #69
|
||||
env.MemoryWrite16(4, 0x3845); // subs r0, #69
|
||||
env.MemoryWrite16(6, 0xE7FE); // b +#0 (infinite loop)
|
||||
|
||||
// Setup registers.
|
||||
|
|
24
src/core/elf.cpp
Normal file
24
src/core/elf.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include "memory.hpp"
|
||||
#include "elfio/elfio.hpp"
|
||||
|
||||
using namespace ELFIO;
|
||||
|
||||
std::optional<u32> Memory::loadELF(std::filesystem::path& path) {
|
||||
elfio reader;
|
||||
if (!reader.load(path.string())) {
|
||||
printf("Woops failed to load ELF\n");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto seg_num = reader.segments.size();
|
||||
printf("Number of segments: %d\n", seg_num);
|
||||
for (int i = 0; i < seg_num; ++i) {
|
||||
const auto pseg = reader.segments[i];
|
||||
std::cout << " [" << i << "] 0x" << std::hex << pseg->get_flags()
|
||||
<< "\t0x" << pseg->get_virtual_address() << "\t0x"
|
||||
<< pseg->get_file_size() << "\t0x" << pseg->get_memory_size()
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
return static_cast<u32>(reader.get_entry());
|
||||
}
|
|
@ -34,4 +34,12 @@ void Emulator::runFrame() {
|
|||
for (u32 i = 0; i < freq; i += 2) {
|
||||
step();
|
||||
}
|
||||
}
|
||||
|
||||
bool Emulator::loadELF(std::filesystem::path& path) {
|
||||
std::optional<u32> entrypoint = memory.loadELF(path);
|
||||
if (!entrypoint.has_value())
|
||||
return false;
|
||||
|
||||
Helpers::panic("Entrypoint: %08X\n", entrypoint.value());
|
||||
}
|
|
@ -7,5 +7,9 @@ int main (int argc, char *argv[]) {
|
|||
Helpers::panic("Failed to initialize OpenGL");
|
||||
}
|
||||
|
||||
auto elfPath = std::filesystem::current_path() / (argc > 1 ? argv[1] : "simple_tri.elf");
|
||||
if (emu.loadELF(elfPath)) {
|
||||
Helpers::panic("Failed to load ELF file: %s", elfPath.c_str());
|
||||
}
|
||||
emu.run();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue