int main(int argc, char *argv[]) { Uint flags = AG_VIDEO_RESIZABLE; int c, i, fps = -1; char *s; if (AG_InitCore("agar-bench", 0) == -1) { fprintf(stderr, "%s\n", AG_GetError()); return (1); } while ((c = getopt(argc, argv, "?vegt:r:T:")) != -1) { extern char *optarg; switch (c) { case 'v': exit(0); case 'g': flags |= AG_VIDEO_OPENGL; break; case 't': AG_TextParseFontSpec(optarg); break; case 'T': AG_SetString(agConfig, "font-path", optarg); break; case 'r': fps = atoi(optarg); break; case '?': default: printf("%s [-vfFgG] [-w width] [-h height] [-r fps]" " [-t font,size,flags] [-T font-path]\n", agProgName); exit(0); } } if (AG_InitVideo(640, 480, 32, flags) == -1) { fprintf(stderr, "%s\n", AG_GetError()); return (-1); } AG_BindGlobalKey(AG_KEY_ESCAPE, AG_KEYMOD_ANY, AG_Quit); AG_BindGlobalKey(AG_KEY_F8, AG_KEYMOD_ANY, AG_ViewCapture); AG_SetRefreshRate(fps); MainWindow(); AG_EventLoop(); AG_Destroy(); return (0); fail: AG_Destroy(); return (1); }
void MainLoop(int argc, char *argv[]) { int c; char *drivers = NULL; char *optArg; char strbuf[2048]; char homedir[2048]; const SDL_VideoInfo *inf; BOOL flag; SDL_Surface *s; // mtrace(); if(AG_GetVariable(agConfig, "font.size", NULL) == NULL) { AG_SetInt(agConfig, "font.size", UI_PT); } while ((c = AG_Getopt(argc, argv, "?fWd:w:h:T:t:c:T:F:S:o:O:l:s:i:", &optArg, NULL)) != -1) { switch (c) { case 'd': drivers = optArg; break; case 'f': /* Force full screen */ AG_SetBool(agConfig, "view.full-screen", 1); break; case 'W': /* Force Window */ AG_SetBool(agConfig, "view.full-screen", 0); break; case 'T': /* Set an alternate font directory */ AG_SetString(agConfig, "font-path", optArg); break; case 'F': /* Set an alternate font face */ AG_SetString(agConfig, "font.face", optArg); break; case 'S': /* Set an alternate font face */ AG_SetInt(agConfig, "font.size", atoi(optArg)); break; case 'o': /* Set an alternate font face */ AG_SetString(agConfig, "osdfont.face", optArg); break; case 'O': /* Set an alternate font face */ AG_SetInt(agConfig, "osdfont.size", atoi(optArg)); break; case 'l': /* Set an alternate font face */ AG_SetString(agConfig, "load-path", optArg); break; case 's': /* Set an alternate font face */ AG_SetString(agConfig, "save-path", optArg); break; case 'i': /* Set an alternate font face */ AG_SetString(agConfig, "save-path", optArg); AG_SetString(agConfig, "load-path", optArg); break; case 't': /* Change the default font */ AG_TextParseFontSpec(optArg); break; case '?': default: printf("%s [-v] [-f|-W] [-d driver] [-r fps] [-t fontspec] " "[-w width] [-h height] " "[-F font.face] [-S font.size]" "[-o osd-font.face] [-O osd-font.size]" "[-s SavePath] [-l LoadPath] " "[-T font-path]\n\n" "Usage:\n" "-f : FullScreen\n-W:Window Mode\n", agProgName); exit(0); } } if(SDL_getenv("HOME") != NULL) { strcpy(homedir, SDL_getenv("HOME")); } else { strcpy(homedir, "."); } XM7_DebugLog(XM7_LOG_DEBUG, "HOME = %s", homedir); #ifdef _WINDOWS AG_PrtString(agConfig, "font-path", "%s:%s/xm7:%s:.", homedir, homedir, FONTPATH); #else flag = FALSE; if(AG_GetString(agConfig, "font-path", strbuf, 2047) != NULL) { if((strlen(strbuf) <= 0) || (strncmp(strbuf, "_agFontVera", 11) == 0)){ flag = TRUE; } } else { flag = TRUE; } if(flag) AG_PrtString(agConfig, "font-path", "%s/.fonts:%s:%s/.xm7:%s:.", homedir, homedir, homedir, FONTPATH); flag = FALSE; XM7_DebugLog(XM7_LOG_DEBUG, "font-path = %s", strbuf); #endif /* _WINDOWS */ flag = FALSE; if(AG_GetString(agConfig, "font.face", strbuf, 511) != NULL) { if((strlen(strbuf) <= 0) || (strncmp(strbuf, "_agFontVera", 11) == 0)){ flag = TRUE; } } else { flag = TRUE; } if(flag) AG_SetString(agConfig, "font.face", UI_FONT); flag = FALSE; XM7_DebugLog(XM7_LOG_DEBUG, "font.face = %s", strbuf); stopreq_flag = FALSE; run_flag = TRUE; // Debug #ifdef _XM7_FB_DEBUG // Force FB. drivers = "sdlfb:width=1280:height=880:depth=32"; #endif /* * Agar のメインループに入る */ if(drivers == NULL) { #ifdef USE_OPENGL if(AG_InitGraphics(NULL) == -1){ fprintf(stderr, "%s\n", AG_GetError()); return; } #else if(AG_InitGraphics("cocoa,sdlfb") == -1){ fprintf(stderr, "%s\n", AG_GetError()); return; } #endif } else { if (AG_InitGraphics(drivers) == -1) { fprintf(stderr, "%s\n", AG_GetError()); return; } } OnCreate((AG_Widget *)NULL); // AG_AtExitFunc(OnDestroy); XM7_DebugLog(XM7_LOG_DEBUG, "Widget creation OK."); XM7_DebugLog(XM7_LOG_INFO, "Emulate version:%d", fm7_ver); SDL_InitSubSystem(SDL_INIT_AUDIO | SDL_INIT_JOYSTICK); XM7_DebugLog(XM7_LOG_DEBUG, "Audio and JOYSTICK subsystem was initialised."); InitInstance(); XM7_DebugLog(XM7_LOG_DEBUG, "InitInstance() OK."); if(agDriverSw && AG_UsingSDL(NULL)) { SDL_Init(SDL_INIT_VIDEO); XM7_DebugLog(XM7_LOG_INFO, "Start Single WM with SDL."); switch(fm7_ver) { case 1: // FM7/77 if(!(LoadGlobalIconPng(NULL, "tamori.png"))) { LoadGlobalIconPng(NULL, "xm7.png"); } break; case 2: // FM77AV if(!(LoadGlobalIconPng(NULL, "fujitsu.png"))) { LoadGlobalIconPng(NULL, "xm7.png"); } break; case 3: // FM77AV20/40/EX/SX if(!(LoadGlobalIconPng(NULL, "fujitsu2.png"))) { LoadGlobalIconPng(NULL, "xm7.png"); } break; default: LoadGlobalIconPng(NULL, "xm7.png"); break; } } else { // WM function is managed by SDL, load and set icon for WM. SDL_Init(SDL_INIT_VIDEO); XM7_DebugLog(XM7_LOG_INFO, "Start multi window mode."); } stopreq_flag = FALSE; run_flag = TRUE; AG_DrawInitsub(); inf = SDL_GetVideoInfo(); if(inf != NULL) { RootVideoWidth = inf->current_w; RootVideoHeight = inf->current_h; } else { RootVideoWidth = 640; RootVideoHeight = 400; } newResize = FALSE; nDrawTick1D = XM7_timeGetTime(); nDrawTick1E = nDrawTick1D; ResizeWindow_Agar2(nDrawWidth, nDrawHeight); XM7_DebugLog(XM7_LOG_DEBUG, "Screen is %d x %d.", nDrawWidth, nDrawHeight); switch(nErrorCode) { case 0: break; case 1: ErrorPopup(gettext("Error init VM.\nPlease check ROMS and system-memory.\n")); break; case 2: ErrorPopup(gettext("Error init Emulator.\nPlease check window system, display and more.\n")); break; default: ErrorPopup(gettext("Unknown error on setup.\nPlease email to author.")); break; } #if 0 mtrace(); #endif if(DrawArea != NULL) { AG_RedrawOnTick(DrawArea, 1000 / nDrawFPS); XM7_DebugLog(XM7_LOG_INFO, "Direct draw mode."); } else if(GLDrawArea != NULL) { AG_RedrawOnTick(GLDrawArea, 1000 / nDrawFPS); XM7_DebugLog(XM7_LOG_INFO, "OpenGL mode."); } bEventRunFlag == TRUE; AGDrawTaskEvent(TRUE); // muntrace(); XM7_DebugLog(XM7_LOG_INFO, "All End."); }