/** * Initialises the emulator * * @param emu Reference to the emulator structure */ void emulator_init(emulator_t* emu) { cpu_init(&emu->cpu, emu); vfp_init(&emu->vfp, emu); memory_init(&emu->memory, emu); gpio_init(&emu->gpio, emu); mbox_init(&emu->mbox, emu); fb_init(&emu->fb, emu); pr_init(&emu->pr, emu); nes_init(&emu->nes, emu); emu->terminated = 0; emu->system_timer_base = emulator_get_time() * 1000; emu->last_refresh = 0; }
//try to load a rom into the nes int nes_load(rom_t *r) { //init the nes nes_init(); //if this is a unif rom if(r->mapper == -1) { mapper_unif_t *mapper; if((mapper = mapper_init_unif(r->board)) == 0) { log_message("unif board '%s' not supported\n",r->board); return(1); } nes->mapper = (mapper_ines_t*)mapper; nes->rom = r; nes->rom->prgbankmask = rom_createmask(mapper->info.prg); nes->rom->chrbankmask = rom_createmask(mapper->info.chr); nes->rom->vrambankmask = rom_createmask(mapper->info.vram); nes->rom->srambankmask = rom_createmask(mapper->info.sram); if(mapper->info.vram) nes_setvramsize(mapper->info.vram / 8); if(mapper->info.sram) nes_setsramsize(mapper->info.sram / 4); log_message("unif mapper '%s' loaded\n",r->board); } else if(r->mapper == 20) { //disk should never be loaded if the bios is not found nes->mapper = (config.fdsbios ? &mapper_hle_fds : &mapper_fds); printf("%s mapper loaded\n",config.fdsbios ? "hle fds" : "fds"); } else { if((nes->mapper = mapper_init_ines(r->mapper)) == 0) { log_message("ines mapper %d not supported\n",r->mapper); return(1); } log_message("ines mapper %d loaded\n",r->mapper); } nes->rom = r; ppu_setmirroring(nes->rom->mirroring); return(0); }
// 函数实现 int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPreInst, LPSTR lpCmdLine, int nCmdShow) { WNDCLASS wc = {0}; MSG msg = {0}; HWND hwnd = NULL; RECT rect = {0}; char file[MAX_PATH] = {0}; int w, h, x, y; NES nes; // 注册窗口 wc.lpfnWndProc = WndProc; wc.hInstance = hCurInst; wc.hIcon = LoadIcon (NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.lpszClassName = APP_CLASS_NAME; wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); if (!RegisterClass(&wc)) return FALSE; // 创建窗口 hwnd = CreateWindow( APP_CLASS_NAME, APP_WND_TITLE, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, NES_WIDTH, NES_HEIGHT, NULL, NULL, hCurInst, NULL); if (!hwnd) return FALSE; if (!ShowOpenFileDialog(hwnd, file)) { nCmdShow = SW_HIDE; PostQuitMessage(0); } GetClientRect(hwnd, &rect); w = NES_WIDTH + (NES_WIDTH - rect.right ); h = NES_HEIGHT + (NES_HEIGHT - rect.bottom); x = (SCREEN_WIDTH - w) / 2; y = (SCREEN_HEIGHT - h) / 2; x = x > 0 ? x : 0; y = y > 0 ? y : 0; // 显示窗口 MoveWindow(hwnd, x, y, w, h, FALSE); ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); // init nes SetWindowLong(hwnd, GWL_USERDATA, (LONG)&nes); nes_init (&nes, file, (DWORD)hwnd); nes_setrun(&nes, 1); // 进入消息循环 while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage (&msg); } // free nes nes_free(&nes); return TRUE; }