Files
ircolib/main.cpp
T
2026-05-15 09:45:26 +02:00

87 lines
2.7 KiB
C++

#include <cflags.hpp>
#include <ircolib/mem_access.hpp>
#include <loaders/elf.hpp>
#include <loaders/dol.hpp>
#include <ircolib/log.hpp>
#include <mem.hpp>
#include <broadway.hpp>
#include <SDL3/SDL.h>
#include <filesystem>
namespace fs = std::filesystem;
int main(int argc, char **argv) {
weee::core::mem mem;
weee::core::broadway broadway;
std::string binName;
cflags::cflags flags;
flags.add_string_callback(
'\0', "elf",
[&](const std::string &v) {
binName = fs::path(v).filename().string();
if (!weee::core::load_elf(v, mem, broadway))
ircolib::panic("Could not load '{}'", v);
},
"ELF binary to load");
flags.add_string_callback(
'\0', "dol",
[&](const std::string &v) {
binName = fs::path(v).filename().string();
if (!weee::core::load_dol(v, mem, broadway))
ircolib::panic("Could not load '{}'", v);
},
"DOL binary to load");
if (argc < 3) {
flags.print_usage("./weee <binary type flag> <binary path>",
"Available options:", "https://git.irco.sh/weeemu/weee");
return -1;
}
if (!flags.parse(argc, argv))
return -2;
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *window = SDL_CreateWindow("weee", 800, 600, SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_RESIZABLE);
SDL_Renderer *renderer = SDL_CreateRenderer(window, nullptr);
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB24, SDL_TEXTUREACCESS_STREAMING, 640, 240);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_SetRenderLogicalPresentation(renderer, 640, 480, SDL_LOGICAL_PRESENTATION_LETTERBOX);
std::vector<ircolib::u8> rgbTexture;
rgbTexture.resize(640 * 240 * 3);
bool open = true;
while (open) {
ircolib::u64 start = SDL_GetTicks();
broadway.run(mem);
SDL_SetWindowTitle(window,
std::format("weee - {} - {:.2f} fps | {} ms", binName,
1000.f / ((float)SDL_GetTicks() - start), SDL_GetTicks() - start)
.c_str());
SDL_Event e;
while (SDL_PollEvent(&e)) {
if (e.type == SDL_EVENT_QUIT)
open = false;
}
SDL_ConvertPixels(640, 240, SDL_PIXELFORMAT_UYVY, &mem.mem1[0x104000], 640 * 4, SDL_PIXELFORMAT_BGR24,
rgbTexture.data(), 640 * 3);
SDL_RenderClear(renderer);
SDL_UpdateTexture(texture, nullptr, rgbTexture.data(), 640 * 3);
SDL_RenderTexture(renderer, texture, nullptr, nullptr);
SDL_RenderPresent(renderer);
}
SDL_DestroyTexture(texture);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}