int main(int argc, char **argv) { if (argc < 2) { PrintUsage(); return 0; } FILE *File = fopen(argv[1], "rb"); if (!File) { printf("Could not open file: %s\n", argv[1]); return -1; } int Flags = 0; if (argc > 2) { if(strncmp(argv[2], "--me", 4) == 0) { Flags |= Z64_FLAG_MIDDLE_ENDIAN; } } z64 Z64; Z64Open(&Z64, Flags, argv[1]); printf("Image name: %.20s\n", Z64.Hdr.ImageName); printf("Manufacturer: %s (%d)\n", Z64GetManufacturerString(Z64.Hdr.ManufacturerID), Z64.Hdr.ManufacturerID); printf("Region: %s (%d)\n", Z64GetCountryString(Z64.Hdr.Country), Z64.Hdr.Country); printf("Boot code:\n"); MIPS_R3000 Dummy; void *RDRAM = linearAlloc(0x400000); MapMemoryRegion(&Dummy, (mmm) {RDRAM, 0x00000000, 0x400000}); memcpy(RDRAM, &Z64.Hdr.BootCode, 1008 * 4); DisassemblerPrintRange(&Dummy, 0, 32, 0); Z64Close(&Z64); return 0; }
int main(int argc, char **argv) { InitPlatform(argc, argv); MIPS_R3000 Cpu; SignalProcessor *SP = new SignalProcessor(); FILE *f = fopen("n64_ipl.bin", "rb"); if (!f) { printf("Could not find n64_ipl.bin\n"); return -1; } fseek(f, 0, SEEK_END); long fsize = ftell(f); fseek(f, 0, SEEK_SET); u8 *BiosBuffer = (u8 *)linearAlloc(0x800); fread(BiosBuffer, fsize, 1, f); fclose(f); memset(BiosBuffer + 0x7C0, 0, 64); u8 *CartBuffer = (u8 *)linearAlloc(0x01000000); z64 Z64Cart; if (!Z64Open(&Z64Cart, Z64_FLAG_MIDDLE_ENDIAN, "cart.v64")) { printf("Couldn't open cart.v64"); return -1; } Z64Read(&Z64Cart, CartBuffer, Z64GetCartSize(&Z64Cart)); Z64Close(&Z64Cart); MapMemoryRegion(&Cpu, (mmm) {linearAlloc(0x400000), 0x00000000, 0x400000, MEM_REGION_RW}); // RDRAM MapMemoryRegion(&Cpu, (mmm) {BiosBuffer, 0x1FC00000, 0x07C0, MEM_REGION_READ}); // PIF ROM MapMemoryRegion(&Cpu, (mmm) {BiosBuffer + 0x7C0, 0x1FC007C0, 64, MEM_REGION_RW}); // PIF RAM MapMemoryRegion(&Cpu, (mmm) {linearAlloc(sizeof(VideoInterface)), 0x04400000, sizeof(VideoInterface), MEM_REGION_RW}); // VI MapMemoryRegion(&Cpu, (mmm) {CartBuffer, 0x10000000, 0x01000000, MEM_REGION_READ}); MapMemoryRegion(&Cpu, (mmm) {SP, 0xA4040000, sizeof(SignalProcessor), MEM_REGION_RW}); MapMemoryRegion(&Cpu, (mmm) {linearAlloc(0x1000), 0xA4000000, 0x1000, MEM_REGION_RW}); // SP_DMEM MapMemoryRegion(&Cpu, (mmm) {linearAlloc(0x1000), 0xA4001000, 0x1000, MEM_REGION_RW}); // SP_IMEM MapMemoryRegion(&Cpu, (mmm) {linearAlloc(sizeof(PeripheralInterface)), 0x4600000, sizeof(PeripheralInterface), MEM_REGION_RW}); WriteMemWordRaw(&Cpu, 0x10000000 + 0x40 + 0x062C, 0); WriteMemWordRaw(&Cpu, 0x10000000 + 0x40 + 0x0638, 0); PIFConfig PIF = {(u8 *)MapVirtualAddress(&Cpu, 0x1FC007C0, MEM_REGION_RW), nullptr, 0}; PIFStartThread(&PIF); VIStartThread(&Cpu, (VideoInterface *)MapVirtualAddress(&Cpu, 0x04400000, MEM_REGION_RW)); PIStartThread(&Cpu, (PeripheralInterface *)MapVirtualAddress(&Cpu, 0x04600000, MEM_REGION_RW)); ResetCpu(&Cpu); bool Step = false; int CyclesToRun = 10000; bool AutoStep = false; u32 IRQ0Steps = 0; if (PlatformHasDebugger()) { CyclesToRun = 1; AutoStep = false; PlatformAttachDebugger(&Cpu); } while (MainLoopPlatform()) { #ifdef _3DS // @TODO this should be moved out to the platform layer until we develop a proper UI and way to exit // u32 KeysDown = hidKeysDown(); // if (KeysDown & KEY_START) // break; #endif if (Step || AutoStep) { Step = false; StepCpu(&Cpu, CyclesToRun); IRQ0Steps += CyclesToRun; // if (IRQ0Steps >= 50000) // { // C0GenerateException(&Cpu, C0_CAUSE_INT, Cpu.pc - 4); // IRQ0Steps = 0; // InterruptMask |= 1; // } } SwapBuffersPlatform(); } PICloseThread(); VICloseThread(); PIFCloseThread(); ExitPlatform(); return 0; }