// Menu loop void menuloop() { SDL_Event event; // Stop sound SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); enablesound(0); // Update EEPROM PokeMini_SaveFromCommandLines(0); // Menu's loop while (emurunning && (UI_Status == UI_STATUS_MENU)) { // Slowdown to approx. 60fps SDL_Delay(16); // Process UI UIMenu_Process(); // Screen rendering SDL_FillRect(screen, NULL, 0); if (SDL_LockSurface(screen) == 0) { // Render the menu or the game screen UIMenu_Display_16((uint16_t *)screen->pixels + ScOffP, PixPitch); // Unlock surface SDL_UnlockSurface(screen); SDL_Flip(screen); } // Handle events while (SDL_PollEvent(&event)) handleevents(&event); } // Apply configs PokeMini_ApplyChanges(); if (UI_Status == UI_STATUS_EXIT) emurunning = 0; else enablesound(CommandLine.sound); SDL_EnableKeyRepeat(0, 0); }
void playanm(short anim_num) { unsigned char *animbuf, *palptr; int i, j, k, length = 0, numframes = 0; int32 handle = -1; unsigned char ANIMvesapal[4*256]; unsigned char tempbuf[256]; unsigned char *palook_bak = palookup[0]; UserInput uinfo = { FALSE, FALSE, dir_None }; ANIMnum = anim_num; KB_FlushKeyboardQueue(); KB_ClearKeysDown(); DSPRINTF(ds,"PlayAnm"); MONO_PRINT(ds); DSPRINTF(ds,"PlayAnm"); MONO_PRINT(ds); animbuf = LoadAnm(anim_num); if (!animbuf) return; DSPRINTF(ds,"PlayAnm - Palette Stuff"); MONO_PRINT(ds); for (i = 0; i < 256; i++) tempbuf[i] = i; palookup[0] = tempbuf; ANIM_LoadAnim(animbuf); ANIMnumframes = ANIM_NumFrames(); numframes = ANIMnumframes; palptr = ANIM_GetPalette(); for (i = 0; i < 768; i++) ANIMvesapal[i] = palptr[i]>>2; tilesizx[ANIM_TILE(ANIMnum)] = 200; tilesizy[ANIM_TILE(ANIMnum)] = 320; clearview(0); setbrightness(gs.Brightness,ANIMvesapal,2); if (ANIMnum == 1) { // draw the first frame waloff[ANIM_TILE(ANIMnum)] = (intptr_t)ANIM_DrawFrame(1); invalidatetile(ANIM_TILE(ANIMnum), 0, 1<<4); rotatesprite(0 << 16, 0 << 16, 65536L, 512, ANIM_TILE(ANIMnum), 0, 0, 2 + 4 + 8 + 16 + 64, 0, 0, xdim - 1, ydim - 1); } SoundState = 0; //ototalclock = totalclock + 120*2; ototalclock = totalclock; for (i = 1; i < numframes; i++) { while (totalclock < ototalclock) { handleevents(); CONTROL_GetUserInput(&uinfo); CONTROL_ClearUserInput(&uinfo); switch (ANIMnum) { case ANIM_INTRO: if (KB_KeyWaiting() || uinfo.button0 || uinfo.button1 || quitevent) goto ENDOFANIMLOOP; break; case ANIM_SERP: if (KEY_PRESSED(KEYSC_ESC) || uinfo.button1 || quitevent) goto ENDOFANIMLOOP; break; } getpackets(); } switch (ANIMnum) { case ANIM_INTRO: AnimShareIntro(i,numframes); break; case ANIM_SERP: AnimSerp(i,numframes); break; case ANIM_SUMO: AnimSumo(i,numframes); break; case ANIM_ZILLA: AnimZilla(i,numframes); break; } waloff[ANIM_TILE(ANIMnum)] = (intptr_t)ANIM_DrawFrame(i); invalidatetile(ANIM_TILE(ANIMnum), 0, 1<<4); rotatesprite(0 << 16, 0 << 16, 65536L, 512, ANIM_TILE(ANIMnum), 0, 0, 2 + 4 + 8 + 16 + 64, 0, 0, xdim - 1, ydim - 1); nextpage(); } // pause on final frame while (totalclock < ototalclock) { handleevents(); getpackets(); } ENDOFANIMLOOP: clearview(0); nextpage(); palookup[0] = palook_bak; setbrightness(gs.Brightness, (unsigned char*)palette_data, 2); KB_FlushKeyboardQueue(); KB_ClearKeysDown(); ANIM_FreeAnim(); walock[ANIM_TILE(ANIMnum)] = 1; }
// Main function int main(int argc, char **argv) { SDL_Joystick *joy; SDL_Event event; // Process arguments printf("%s\n\n", AppName); PokeMini_InitDirs(argv[0], NULL); CommandLineInit(); CommandLineConfFile("pokemini.cfg", NULL, NULL); if (!CommandLineArgs(argc, argv, NULL)) { PrintHelpUsage(stdout); return 1; } JoystickSetup("WIZ", 0, 0, WIZ_KeysNames, 16, WIZ_KeysMapping); // Initialize SDL if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } joy = SDL_JoystickOpen(0); atexit(SDL_Quit); // Clean up on exit // Set video spec and check if is supported if (!PokeMini_SetVideo((TPokeMini_VideoSpec *)&PokeMini_Video3x3, 16, CommandLine.lcdfilter, CommandLine.lcdmode)) { fprintf(stderr, "Couldn't set video spec\n"); exit(1); } UIMenu_SetDisplay(288, 192, PokeMini_BGR16, (uint8_t *)PokeMini_BG3, (uint16_t *)PokeMini_BG3_PalBGR16, (uint32_t *)PokeMini_BG3_PalBGR32); // Initialize the display screen = SDL_SetVideoMode(320, 240, 16, SDL_SWSURFACE); // SDL_HWSURFACE | SDL_DOUBLEBUF if (screen == NULL) { fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError()); exit(1); } PixPitch = screen->pitch / 2; ScOffP = (24 * PixPitch) + 16; // Initialize the sound SDL_AudioSpec audfmt; audfmt.freq = 44100; audfmt.format = AUDIO_U8; audfmt.channels = 1; audfmt.samples = SOUNDBUFFER; audfmt.callback = emulatorsound; audfmt.userdata = NULL; // Open the audio device if (SDL_OpenAudio(&audfmt, NULL) < 0) { fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); fprintf(stderr, "Audio will be disabled\n"); AudioEnabled = 0; } else { AudioEnabled = 1; } // Disable key repeat and hide cursor SDL_EnableKeyRepeat(0, 0); SDL_ShowCursor(SDL_DISABLE); // Initialize the emulator printf("Starting emulator...\n"); if (!PokeMini_Create(0, PMSOUNDBUFF)) { fprintf(stderr, "Error while initializing emulator.\n"); } // Setup palette and LCD mode PokeMini_VideoPalette_Init(PokeMini_BGR16, 1); PokeMini_VideoPalette_Index(CommandLine.palette, CommandLine.custompal, CommandLine.lcdcontrast, CommandLine.lcdbright); PokeMini_ApplyChanges(); // Load stuff PokeMini_UseDefaultCallbacks(); if (!PokeMini_LoadFromCommandLines("Using FreeBIOS", "EEPROM data will be discarded!")) { UI_Status = UI_STATUS_MENU; } // Enable sound & init UI printf("Starting emulator...\n"); UIMenu_Init(); enablesound(CommandLine.sound); // Emulator's loop unsigned long time, NewTickSync = 0; while (emurunning) { // Emulate and syncronize if (RequireSoundSync) { PokeMini_EmulateFrame(); // Sleep a little in the hope to free a few samples while (MinxAudio_SyncWithAudio()) SDL_Delay(1); } else { time = SDL_GetTicks(); PokeMini_EmulateFrame(); do { SDL_Delay(1); // This lower CPU usage time = SDL_GetTicks(); } while (time < NewTickSync); NewTickSync = time + 13; // Aprox 72 times per sec } // Screen rendering SDL_FillRect(screen, NULL, 0); if (SDL_LockSurface(screen) == 0) { // Render the menu or the game screen if (PokeMini_Rumbling) { PokeMini_VideoBlit((uint16_t *)screen->pixels + ScOffP + PokeMini_GenRumbleOffset(PixPitch), PixPitch); } else { PokeMini_VideoBlit((uint16_t *)screen->pixels + ScOffP, PixPitch); } LCDDirty = 0; // Unlock surface SDL_UnlockSurface(screen); SDL_Flip(screen); } // Handle events while (SDL_PollEvent(&event)) handleevents(&event); // Menu if (UI_Status == UI_STATUS_MENU) menuloop(); } // Disable sound & free UI enablesound(0); UIMenu_Destroy(); // Save Stuff PokeMini_SaveFromCommandLines(1); // Close joystick if (joy) SDL_JoystickClose(joy); // Terminate... printf("Shutdown emulator...\n"); PokeMini_VideoPalette_Free(); PokeMini_Destroy(); return 0; }
int main(int argc, char **argv) { struct myargs args = {NULL}; struct RDArgs *rda; if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0))) { if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0))) { if ((DOSBase = (struct DosLibrary *) OpenLibrary("dos.library",0))) { rda = ReadArgs("LEFT/K/N,TOP/K/N,WIDTH/N,HEIGHT/N,DEPTH/K/N,MODEID/K,OVERSCAN/K/N,SCROLL/K/N,DRAG/K/N,LIKEWB/K/N", (IPTR *)&args, NULL); if (rda) { struct Screen *screen; struct Window *w1; ULONG oserr = 0; struct TagItem tags[] = { {SA_Width, 640 }, {SA_Height, 480 }, {SA_Depth, 4 }, {TAG_IGNORE, 0 }, {TAG_IGNORE, 0 }, {TAG_IGNORE, 0 }, {TAG_IGNORE, 0 }, {TAG_IGNORE, 0 }, {TAG_IGNORE, 0 }, {TAG_IGNORE, 0 }, {SA_Title, (IPTR)"Screen opening and movement test"}, {SA_ErrorCode, (IPTR)&oserr }, {TAG_DONE, 0 } }; if (args.width) tags[0].ti_Data = *args.width; if (args.height) tags[1].ti_Data = *args.height; if (args.depth) tags[2].ti_Data = *args.depth; printf("Opening screen, size: %lux%lu, depth: %lu\n", tags[0].ti_Data, tags[1].ti_Data, tags[3].ti_Data); if (args.mode) { tags[3].ti_Tag = SA_DisplayID; tags[3].ti_Data = strtoul(args.mode, NULL, 16); printf("ModeID: 0x%08lX\n", tags[3].ti_Data); } if (args.scroll) { tags[4].ti_Tag = SA_AutoScroll; tags[4].ti_Data = *args.scroll; printf("SA_AutoScroll: %ld\n", tags[4].ti_Data); } if (args.drag) { tags[5].ti_Tag = SA_Draggable; tags[5].ti_Data = *args.drag; printf("SA_Draggable: %ld\n", tags[5].ti_Data); } if (args.likewb) { tags[6].ti_Tag = SA_LikeWorkbench; tags[6].ti_Data = *args.likewb; printf("SA_LikeWorkbench: %ld\n", tags[6].ti_Data); } if (args.oscan) { tags[7].ti_Tag = SA_Overscan; tags[7].ti_Data = *args.oscan; printf("SA_Overscan: %ld\n", tags[7].ti_Data); } if (args.left) { tags[8].ti_Tag = SA_Left; tags[8].ti_Data = *args.left; printf("SA_Left: %ld\n", tags[8].ti_Data); } if (args.top) { tags[9].ti_Tag = SA_Top; tags[9].ti_Data = *args.top; printf("SA_Top: %ld\n", tags[9].ti_Data); } screen = OpenScreenTagList(NULL, tags); if (screen) { w1 = openwindow(screen, "Screen data", W1_LEFT, W1_TOP, W1_WIDTH, W1_HEIGHT); if (w1) { WORD x = w1->BorderLeft; WORD y = w1->BorderTop; struct BitMap *bitmap = screen->RastPort.BitMap; y = drawtext(w1, x, y, "Requested size: %lux%lu", tags[0].ti_Data, tags[1].ti_Data); y = drawtext(w1, x, y, "Requested depth: %lu", tags[2].ti_Data); if (args.mode) y = drawtext(w1, x, y, "Requested ModeID: 0x%08lX", tags[3].ti_Data); y = drawtext(w1, x, y, "Actual size: %ux%u", screen->Width, screen->Height); y = drawtext(w1, x, y, "Actual ModeID: 0x%08X", screen->ViewPort.ColorMap->VPModeID); y = drawtext(w1, x, y, "Flags: 0x%04lX", screen->Flags); y = drawtext(w1, x, y, "BitMap size: %ux%u", GetBitMapAttr(bitmap, BMA_WIDTH), GetBitMapAttr(bitmap, BMA_HEIGHT)); y = drawtext(w1, x, y, "BitMap depth: %u", GetBitMapAttr(bitmap, BMA_DEPTH)); handleevents(w1, screen, x, y); CloseWindow(w1); } CloseScreen(screen); } else printf("Failed to open screen, error: %d\n", (int)oserr); FreeArgs(rda); } else printf("Error parsing arguments\n"); CloseLibrary((struct Library *)DOSBase); } CloseLibrary((struct Library *)GfxBase); } CloseLibrary((struct Library *) IntuitionBase); } return 0; } /* main */