コード例 #1
0
ファイル: BkBtl.cpp プロジェクト: SapphireDensetsu/bkbtl
int main(int argc, char** argv)
{
    const char *inPath = argv[0];
    // Get application directory
    int i, j;
    for (i = 0, j = 0; inPath[i] != '\0'; i++) {
        if ((inPath[i] == '\\') || (inPath[i] == '/'))
            j = i + 1;
    }
    strncpy(g_AppDirectory, inPath, j);
    g_AppDirectory[j] = '\0';

    // Get application INI file path
    const char *inPathDot = strrchr(inPath, '.');
    int c = (inPathDot == NULL) ? strlen(inPath) : inPathDot - inPath;
    strncpy(g_AppIniPath, inPath, c);
    strncpy(g_AppIniPath + c, ".ini", 4);

#if defined(_DINGOO)
    SDL_putenv("DINGOO_IGNORE_OS_EVENTS=1");  //HACK to fix "push long time on X" problem
#endif

    Settings_ParseIniFile(g_AppIniPath);

    // Init SDL video
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
        return 255;  // Unable to initialize SDL

#ifdef _WIN32
    SDL_putenv("SDL_VIDEO_WINDOW_POS=300,200");
    SDL_WM_SetCaption("BKBTL SDL", "BKBTL SDL");
#else
    SDL_ShowCursor(SDL_DISABLE);
#endif

    // Prepare screen surface
    g_Screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BITPERPIXEL, 0);
    if (g_Screen == NULL)
        return 254;  // Unable to set video mode
    g_Keyboard = SDL_CreateRGBSurface(0, KEYBOARD_WIDTH, KEYBOARD_HEIGHT, 32, 0,0,0,0);
    SDL_SetAlpha(g_Keyboard, SDL_SRCALPHA, 180);
    SDL_SetColorKey(g_Keyboard, SDL_SRCCOLORKEY, SDL_MapRGB(g_Keyboard->format, 0,0,0));

    SDL_Delay(1000);
    if (SDL_NumJoysticks())
        g_Joystick = SDL_JoystickOpen(0);

    Fonts_Initialize();

    if (!Emulator_Init())
        return 255;
    if (!Emulator_InitConfiguration(DEFAULT_BK_CONF))
        return 255;

    Main_ClearScreen();
    Main_SetScreenMode(0);

    Emulator_Start();

    Uint32 ticksLast;
    Uint32 ticksLastFps = SDL_GetTicks();
    int frames = 0;
    while (!g_okQuit)
    {
        ticksLast = SDL_GetTicks();  // Time at frame start
        SDL_Event evt;
        while (SDL_PollEvent(&evt))
        {
            if (evt.type == SDL_QUIT)
            {
                g_okQuit = TRUE;
                break;
            }
            else
            {
                if (evt.type == SDL_KEYDOWN || evt.type == SDL_KEYUP ||
                        evt.type == SDL_JOYBUTTONDOWN || evt.type == SDL_JOYBUTTONUP)
                {
                    Main_OnKeyJoyEvent(evt);
                }
            }
        }

        if (g_okEmulatorRunning)
        {
            Emulator_SystemFrame();

            Main_DrawScreen();

            frames++;
        }

        // Delay
        Uint32 ticksNew = SDL_GetTicks();
        Uint32 ticksElapsed = ticksNew - ticksLast;
        g_LastDelay = 0;
        if (ticksElapsed < FRAME_TICKS)
        {
            g_LastDelay = FRAME_TICKS - ticksElapsed;
            SDL_Delay(FRAME_TICKS - ticksElapsed);
        }
        ticksLast = ticksNew;

        if (ticksLast - ticksLastFps > 1000)  //DEBUG: FPS calculation
        {
            g_LastFps = frames;
            frames = 0;
            ticksLastFps += 1000;
        }
    }

    Emulator_Stop();
    Emulator_Done();

    Main_SetScreenMode(-1);

    if (g_Joystick != NULL)
    {
        SDL_JoystickClose(g_Joystick);
    }

    // Free memory
    SDL_FreeSurface(g_Keyboard);
    SDL_FreeSurface(g_Screen);

    Fonts_Finalize();

    SDL_Quit();

    return 0;
}
コード例 #2
0
ファイル: BkBtl.cpp プロジェクト: SapphireDensetsu/bkbtl
// Show directory browser for *.BIN mask
void Main_BrowseAndLoadBin()
{
    // Get file list by mask
    char ** pfilenames = Common_FindFiles(g_AppDirectory, "*.bin");

    int exitBrowser = FALSE;
    int currentItem = 0;
    int redrawScreen = TRUE;
    int menuItemCount = 0;
    const int menuLeft = 12;
    const int menuWidth = 8 * 32;
    const int menuHeight = 11 * 20;

    while (!exitBrowser)
    {
        if (redrawScreen)
        {
            Main_DrawScreen();

            // Draw menu background
            SDL_Rect rc;
            rc.x = menuLeft - 8;
            rc.y = 8 - 4;
            rc.w = 12 + menuWidth;
            rc.h = 8 + menuHeight;
            SDL_FillRect(g_Screen, &rc, SDL_MapRGB(g_Screen->format, 32, 32, 192));
            // Draw selected item background
            rc.x = menuLeft - 4;
            rc.y = 8 - 1 + currentItem * 11;
            rc.w = 4 + menuWidth;
            rc.h = 11 + 2;
            SDL_FillRect(g_Screen, &rc, SDL_MapRGB(g_Screen->format, 192, 32, 32));

            // Draw menu items
            char ** pitem = pfilenames;
            int y = 8;
            menuItemCount = 0;
            while (*pitem != NULL)
            {
                Font_DrawText(menuLeft, y, *pitem);
                pitem++;
                y += 11;
                menuItemCount++;
            }

            SDL_Flip(g_Screen);

            redrawScreen = FALSE;
        }

        SDL_Event evt;
        while (SDL_PollEvent(&evt))
        {
            redrawScreen = TRUE;
            if (evt.type == SDL_QUIT)
            {
                g_okQuit = exitBrowser = TRUE;
                break;
            }
            if (evt.type == SDL_KEYDOWN)
            {
                switch (evt.key.keysym.sym)
                {
                case SDLK_PAUSE:  // POWER UP button on Dingoo
                    g_okQuit = exitBrowser = TRUE;
                    break;
                case SDLK_TAB:  // Left shoulder on Dingoo
                case SDLK_ESCAPE:  // SELECT button on Dingoo
                    exitBrowser = TRUE;
                    break;
                case SDLK_UP:
                    if (currentItem > 0) currentItem--;
                    else currentItem = menuItemCount - 1;
                    break;
                case SDLK_DOWN:
                    if (currentItem < menuItemCount - 1) currentItem++;
                    else currentItem = 0;
                    break;
                case SDLK_LCTRL:  // A button on Dingoo
                case SDLK_SPACE:  // X button on Dingoo
                case SDLK_RETURN:  // START button on Dingoo
                {
                    char * filename = pfilenames[currentItem];
                    Main_LoadBin(filename);
                    // Print "S1000"
                    Emulator_KeyboardEvent(0123, TRUE);
                    Emulator_KeyboardEvent(0123, FALSE);
                    Emulator_KeyboardEvent(061, TRUE);
                    Emulator_KeyboardEvent(061, FALSE);
                    Emulator_KeyboardEvent(060, TRUE);
                    Emulator_KeyboardEvent(060, FALSE);
                    Emulator_KeyboardEvent(060, TRUE);
                    Emulator_KeyboardEvent(060, FALSE);
                    Emulator_KeyboardEvent(060, TRUE);
                    Emulator_KeyboardEvent(060, FALSE);
                    exitBrowser = TRUE;
                }
                break;
                default:
                    break;
                }
            }
        }

        SDL_Delay(50);
    }

    Common_FindFiles_Cleanup(pfilenames);
}
コード例 #3
0
ファイル: BkBtl.cpp プロジェクト: SapphireDensetsu/bkbtl
void Main_Menu()
{
    int exitMenu = FALSE;
    int currentItem = 0;
    int redrawScreen = TRUE;
    const int menuItemCount = sizeof(m_MainMenuItems) / sizeof(MenuItemStruct);
    const int menuLeft = 12;
    const int menuWidth = 8 * 16;
    char progname[50];
    char buffer[32];

    sprintf(progname, "BKBTL SDL version %d.%d  " __DATE__ " ", VERSION_MAJOR, VERSION_MINOR);

    while (!exitMenu)
    {
        if (redrawScreen)
        {
            Main_DrawScreen();

            // Draw menu background
            SDL_Rect rc;
            rc.x = menuLeft - 8;
            rc.y = 8 - 4;
            rc.w = 16 + menuWidth;
            rc.h = 8 + 12 * menuItemCount;
            SDL_FillRect(g_Screen, &rc, SDL_MapRGB(g_Screen->format, 32, 32, 192));
            // Draw selected item background
            rc.x = menuLeft - 4;
            rc.y = 8 - 1 + currentItem * 12;
            rc.w = 8 + menuWidth;
            rc.h = 11 + 2;
            SDL_FillRect(g_Screen, &rc, SDL_MapRGB(g_Screen->format, 192, 32, 32));

            // Draw menu items
            int y = 8;
            for (int i = 0; i < menuItemCount; i++)
            {
                Font_DrawText(menuLeft, y + 12 * i, m_MainMenuItems[i].text);
            }

            // Emulator name and version number
            Font_DrawText(menuLeft, SCREEN_HEIGHT - 12, progname);
            // Last FPS
            sprintf(buffer, "FPS: %d, Delay: %d", g_LastFps, g_LastDelay);
            Font_DrawText(menuLeft, SCREEN_HEIGHT - 24, buffer);

            SDL_Flip(g_Screen);

            redrawScreen = FALSE;
        }

        SDL_Event evt;
        while (SDL_PollEvent(&evt))
        {
            redrawScreen = TRUE;
            if (evt.type == SDL_QUIT)
            {
                g_okQuit = exitMenu = TRUE;
                break;
            }
            if (evt.type == SDL_KEYDOWN || evt.type == SDL_JOYBUTTONDOWN)
            {
                KeyMappingStruct* mapping = FindKeyMapping(1, evt.key.keysym.sym, TRUE);
                if (mapping != NULL)
                {
                    switch (mapping->resultcd)
                    {
                    case ID_EXIT:
                        g_okQuit = exitMenu = TRUE;
                        break;
                    case ID_MENU:
                    case ID_MENU_ESCAPE:
                        exitMenu = TRUE;
                        break;
                    case ID_MENU_UP:
                        if (currentItem > 0) currentItem--;
                        else currentItem = menuItemCount - 1;
                        break;
                    case ID_MENU_DOWN:
                        if (currentItem < menuItemCount - 1) currentItem++;
                        else currentItem = 0;
                        break;
                    case ID_MENU_RIGHT:
                    case ID_MENU_SELECT:
                        if (Main_ExecuteMenuCommand(m_MainMenuItems[currentItem].command, TRUE))
                            exitMenu = TRUE;
                        break;
                    case ID_MENU_LEFT:
                        if (Main_ExecuteMenuCommand(m_MainMenuItems[currentItem].command, FALSE))
                            exitMenu = TRUE;
                        break;
                    default:
                        break;
                    }
                }
            }
        }

        SDL_Delay(50);
    }
}
コード例 #4
0
ファイル: UKNCBTL.cpp プロジェクト: fixelsan/ukncbtl
int main(int argc, char* argv[])
{
    // Get application path
    g_ApplicationExePath.append(argv[0]);

    // Calculate INI file path
    g_ApplicationIniPath = g_ApplicationExePath;
    g_ApplicationIniPath.resize(g_ApplicationIniPath.find_last_of(_T('.')));
    g_ApplicationIniPath.append(_T(".ini"));

    if (! InitInstance())
        return 255;

    Emulator_Start();

    // The main loop
    Uint32 ticksLast;
    Uint32 ticksLastFps = SDL_GetTicks();
    int frames = 0;
    while (!g_okQuit)
    {
        ticksLast = SDL_GetTicks();  // Time at frame start
        SDL_Event evt;
        while (SDL_PollEvent(&evt))
        {
            if (evt.type == SDL_QUIT)
            {
                g_okQuit = TRUE;
                break;
            }
            else
            {
                if (evt.type == SDL_KEYDOWN || evt.type == SDL_KEYUP ||
                        evt.type == SDL_JOYBUTTONDOWN || evt.type == SDL_JOYBUTTONUP)
                {
                    Main_OnKeyJoyEvent(evt);
                }
            }
        }

        if (g_okEmulatorRunning)
        {
            Emulator_SystemFrame();

            Main_DrawScreen();

            frames++;
        }

        // Delay
        Uint32 ticksNew = SDL_GetTicks();
        Uint32 ticksElapsed = ticksNew - ticksLast;
        g_LastDelay = 0;
        if (ticksElapsed < FRAME_TICKS)
        {
            g_LastDelay = FRAME_TICKS - ticksElapsed;
            SDL_Delay(FRAME_TICKS - ticksElapsed);
        }
        ticksLast = ticksNew;

        if (ticksLast - ticksLastFps > 1000)  //DEBUG: FPS calculation
        {
            g_LastFps = frames;
            frames = 0;
            ticksLastFps += 1000;
        }
    }

    Emulator_Stop();

    DoneInstance();

    return 0;
}