#include #include #include #include #include #include #include "vm.h" #include "logger.h" #include "host.h" #include "hostVmShared.h" #include "BBSClient.h" #if __VITA__ #include #endif int main(int argc, char* argv[]) { //default to full resolution int windowWidth = 0; int windowHeight = 0; std::string downloadLid = ""; int opt; while ((opt = getopt(argc, argv, "w:h:d:")) != -1) { switch (opt) { case 'w': windowWidth = (int)strtol(optarg, NULL, 10); break; case 'h': windowHeight = (int)strtol(optarg, NULL, 10); break; case 'd': downloadLid = optarg; break; } } printf("windowWidth: %d\n", windowWidth); printf("windowHeight: %d\n", windowHeight); Host *host = new Host(windowWidth, windowHeight); PicoRam *memory = new PicoRam(); memory->Reset(); Audio *audio = new Audio(memory); Logger_Initialize(host->logFilePrefix()); Logger_Write("initializing Vm\n"); Vm *vm = new Vm(host, memory, nullptr, nullptr, audio); host->setUpPaletteColors(); host->oneTimeSetup(audio); host->setTargetFps(60); #if LOAD_PACK_INS host->unpackCarts(); #endif Logger_Write("initialized Vm and host\n"); Logger_Write("Setting cart list on vm\n"); vm->SetCartList(host->listcarts()); bool loadCart = false; char* cart; #if __VITA__ char boot_params[1024]; sceAppMgrGetAppParam(boot_params); if (strstr(boot_params,"psgm:play") && strstr(boot_params, "¶m=")) { loadCart = true; cart = strstr(boot_params, "¶m=") + 7; } #else int index; for (index = optind; index < argc; index++) { cart = argv[index]; loadCart = true; } #endif if (!downloadLid.empty()) { std::string filename = "bbs_" + downloadLid + ".p8.png"; printf("[PicoPlay] Downloading cartridge '%s' from Lexaloffle BBS...\n", downloadLid.c_str()); if (BBSClient::DownloadCartByLid(downloadLid, filename, host->getCartDirectory())) { cart = strdup(filename.c_str()); loadCart = true; } else { printf("[PicoPlay] Failed to download cartridge '%s' from BBS.\n", downloadLid.c_str()); } } if (loadCart){ Logger_Write("Loading arg cart \n"); vm->LoadCart(cart, true); } else { Logger_Write("Loading bios cart\n"); vm->LoadBiosCart(); } vm->vm_run(); // Main loop Logger_Write("Starting main loop\n"); vm->GameLoop(); Logger_Write("Turning off vm and exiting logger\n"); vm->CloseCart(); Logger_Write("calling one time cleanup\n"); host->oneTimeCleanup(); Logger_Write("deleting vm\n"); delete vm; Logger_Write("deleting host\n"); delete host; Logger_Write("exiting logger\n"); Logger_Exit(); return 0; }