Example #1
0
//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static char dest[1024];
    int i,wmId,wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;
    HMENU hMenu;

    switch (message)
    {
    case WM_COMMAND:
        wmId    = LOWORD(wParam);
        wmEvent = HIWORD(wParam);
        // Parse the menu selections:
        switch (wmId)
        {
        case ID_FILE_OPEN:
            file_open(hWnd);
            break;
        case ID_FILE_LOADPATCH:
            file_open_patch(hWnd);
            break;
        case ID_FILE_UNLOAD:
            emu_event(E_UNLOAD,0);
            break;
        case ID_NES_PAUSE:
            emu_event(E_TOGGLERUNNING,0);
            break;
        case ID_NES_SOFTRESET:
            emu_event(E_SOFTRESET,0);
            break;
        case ID_NES_HARDRESET:
            emu_event(E_HARDRESET,0);
            break;
        case ID_NES_LOADSTATE:
            emu_event(E_LOADSTATE,0);
            break;
        case ID_NES_SAVESTATE:
            emu_event(E_SAVESTATE,0);
            break;
        case ID_MOVIE_LOAD:
            load_movie(hWnd);
            break;
        case ID_MOVIE_SAVE:
            save_movie(hWnd);
            break;
        case ID_MOVIE_PLAY:
            emu_event(E_PLAYMOVIE,0);
            break;
        case ID_MOVIE_RECORD:
            emu_event(E_RECORDMOVIE,0);
            break;
        case ID_MOVIE_STOP:
            emu_event(E_STOPMOVIE,0);
            break;
        case ID_FDS_FLIPDISK:
            emu_event(E_FLIPDISK,0);
            break;
        case ID_VIEW_CONFIGURATION:
            ConfigurationPropertySheet(hWnd);
            break;
        case ID_VIEW_DEBUGGER:
            DialogBox(hInst,(LPCTSTR)IDD_DEBUGGER,hWnd,(DLGPROC)DebuggerDlg);
            break;
        case ID_VIEW_SEARCH:
            DialogBox(hInst,(LPCTSTR)IDD_CHEATSEARCH,hWnd,(DLGPROC)CheatSearchDlg);
            break;
        case ID_VIEW_CONSOLE:
            hMenu = GetMenu(hWnd);
            if(GetWindowLong(hConsole,GWL_USERDATA) == 0) {
                CheckMenuItem(hMenu,ID_VIEW_CONSOLE,MF_CHECKED);
                ShowWindow(hConsole,SW_SHOW);
                SetWindowLong(hConsole,GWL_USERDATA,1);
            }
            else {
                CheckMenuItem(hMenu,ID_VIEW_CONSOLE,MF_UNCHECKED);
                ShowWindow(hConsole,SW_HIDE);
                SetWindowLong(hConsole,GWL_USERDATA,0);
            }
            break;
        case IDM_ABOUT:
            DialogBox(hInst,(LPCTSTR)IDD_ABOUT,hWnd,(DLGPROC)AboutDlg);
            break;
        case ID_HELP_SUPPORTEDMAPPERS:
            DialogBox(hInst,(LPCTSTR)IDD_MAPPERS,hWnd,(DLGPROC)MappersDlg);
            break;
        case IDM_EXIT:
            if(config_get_bool("video.fullscreen") != 0)
                emu_event(E_WINDOWED,0);
            else
                DestroyWindow(hWnd);
            break;
        case ID_VIEW_FULLSCREEN:
            emu_event(E_TOGGLEFULLSCREEN,0);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
        break;
    case WM_ENTERMENULOOP:
        sound_pause();
        for(i=0; nesids[i] != -1; i++) {
            EnableMenuItem(GetMenu(hWnd),nesids[i],nes->cart ? MF_ENABLED : MF_GRAYED);
        }
        break;
    case WM_EXITMENULOOP:
        sound_play();
        break;
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        // TODO: Add any drawing code here...
        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        quit++;
        if(hConsole)
            DestroyWindow(hConsole);
        PostQuitMessage(0);
        break;
    case WM_SIZE:
//		video_resize();
        break;
    case WM_DROPFILES:
        DragQueryFile((HDROP)wParam,0,dest,1024);
        DragFinish((HDROP)wParam);
        loadrom(dest);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
Example #2
0
int main (int argc, char *argv[])
{
    GCContext    gc_context;
    GMainLoop   *mainLoop;
    GKeyFile    *keyFile;
    GThread     *displayThread;
    GThread     *inputControllerThread;
    GThread     *x11EventThread;
    int          i;

    
    GCConfig config = {
        .movie_path          = DEFAULT_MOVIE_PATH,
        .mask_path           = DEFAULT_MASK_PATH,
        .controller_path     = DEFAULT_CONTROLLER_PATH,
        .seconds_per_frame   = DEFAULT_SECONDS_PER_FRAME,
        .easing_factor       = DEFAULT_EASING_FACTOR,
        .frames_per_tick     = 0,
        .diameter_controller = 0,
        .diameter_rim        = 0,
        .ctr                 = 0,
        .fpr                 = 0,
        .number_of_frames    = 0,
        .fullscreen          = TRUE,
        .timeZone            = NULL,
    };

    Movie movie = {
        .planes             = NULL,
        .frame_offset       = 0,
        .fd_movie           = -1,
        .frame              = { .pitches = { FRAME_PITCH, 0, 0 } },
        .fd_mask            = -1,
        .mask               = { .pitches = { MASK_PITCH, 0, 0 } },
        .pre_load_surface   = VDP_INVALID_HANDLE,
        .play_direction     = DIRECTION_FORWARD,
        .ticks              = 0,
        .new_frame          = FALSE,
        .ease_to            = TRUE,
    };

    keyFile = g_key_file_new();
    if (argc > 1 && g_key_file_load_from_file(keyFile, argv[1], G_KEY_FILE_NONE, NULL)) {
        if (g_key_file_has_group(keyFile, "MAIN")) {
            if (g_key_file_has_key(keyFile, "MAIN", "utc_offset", NULL))
                config.timeZone = g_time_zone_new(g_key_file_get_string(keyFile, "MAIN", "utc_offset", NULL));
            if (g_key_file_has_key(keyFile, "MAIN", "ease_to_time", NULL))
                movie.ease_to = g_key_file_get_boolean(keyFile, "MAIN", "ease_to_time", NULL);
        }
 
        if (g_key_file_has_group(keyFile, "MOVIE")) {
           if (g_key_file_has_key(keyFile, "MOVIE", "file", NULL))
              config.movie_path = g_key_file_get_string(keyFile, "MOVIE", "file", NULL);
           if (g_key_file_has_key(keyFile, "MOVIE", "mask", NULL))
              config.mask_path = g_key_file_get_string(keyFile, "MOVIE", "mask", NULL);
           if (g_key_file_has_key(keyFile, "MOVIE", "seconds_per_frame", NULL))
              config.seconds_per_frame = (float)g_key_file_get_double(keyFile, "MOVIE", "seconds_per_frame", NULL);
           if (g_key_file_has_key(keyFile, "MOVIE", "easing_factor", NULL))
              config.easing_factor = (float)g_key_file_get_integer(keyFile, "MOVIE", "easing_factor", NULL);
        }
        
        if (g_key_file_has_group(keyFile, "CONTROLLER")) {
           if (g_key_file_has_key(keyFile, "CONTROLLER", "path", NULL))
              config.controller_path = g_key_file_get_string(keyFile, "CONTROLLER", "path", NULL);

           if (g_key_file_has_key(keyFile, "CONTROLLER", "diameter_controller", NULL))
              config.diameter_controller = (float)g_key_file_get_double(keyFile, "CONTROLLER", "diameter_controller", NULL);
           if (g_key_file_has_key(keyFile, "CONTROLLER", "diameter_rim", NULL))
              config.diameter_rim = (float)g_key_file_get_double(keyFile, "CONTROLLER", "diameter_rim", NULL);
           if (g_key_file_has_key(keyFile, "CONTROLLER", "ctr", NULL))
              config.ctr = (float)g_key_file_get_double(keyFile, "CONTROLLER", "ctr", NULL);
           if (g_key_file_has_key(keyFile, "CONTROLLER", "fpr", NULL))
              config.fpr = (float)g_key_file_get_double(keyFile, "CONTROLLER", "fpr", NULL);
           if (g_key_file_has_key(keyFile, "CONTROLLER", "frames_per_tick", NULL))
              config.frames_per_tick = (float)g_key_file_get_double(keyFile, "CONTROLLER", "frames_per_tick", NULL);
        }

        if (g_key_file_has_group(keyFile, "SCREEN")) {
           if (g_key_file_has_key(keyFile, "SCREEN", "fullscreen", NULL))
              config.fullscreen = g_key_file_get_boolean(keyFile, "SCREEN", "fullscreen", NULL);
        }
        g_key_file_free(keyFile);
    }

    if (!config.timeZone)
        config.timeZone = g_time_zone_new_local();

    if (!config.frames_per_tick && 
        !(config.frames_per_tick = frames_per_tick(config.diameter_controller,
                                                   config.diameter_rim,
                                                   config.ctr,
                                                   config.fpr)))
    {
        g_warning("No valid tick settings, using default frames per tick: %f", DEFAULT_FRAMES_PER_TICK);
        config.frames_per_tick = DEFAULT_FRAMES_PER_TICK;
    }

    config.movie_size = get_file_size(config.movie_path);
    config.number_of_frames = config.movie_size / FRAME_SIZE;
    
    mainLoop = g_main_loop_new(NULL, FALSE);

    gc_context.g_main_loop        = mainLoop;
    gc_context.g_main_context     = g_main_loop_get_context(mainLoop);
    gc_context.window_size.width  = MOVIE_WIDTH;
    gc_context.window_size.height = MOVIE_HEIGHT;
    gc_context.exit               = FALSE;
    gc_context.movie_context      = &movie;
    gc_context.config             = &config;


    g_message("movie file: %s",                           config.movie_path);
    g_message("movie size: %lu",                          config.movie_size);
    g_message("movie frames: %lu",                        config.number_of_frames);
    g_message("movie mask file: %s",                      config.mask_path);
    g_message("frames per minute: %f",                    get_frames_per_minute(&gc_context));
    g_message("frames per day:    %lu",                   get_frames_per_day(&gc_context));
    g_message("frames per tick:   %f",                    config.frames_per_tick);
    g_message("number of days:    %d",                    get_number_of_days(&gc_context));
    g_message("current day:       %d",                    get_current_day(&gc_context));

    if (movie.ease_to) {
        movie.ease_to_frame = get_frame_offset(&gc_context, GO_TO_RAND_DAY, DAY_OFFSET_NOW);
        g_message("ease to frame:    %lu", movie.ease_to_frame);
    }

    x11_init(&gc_context);
    vdpau_init(&gc_context);

    load_movie(&gc_context);
    load_mask(&gc_context);

    g_cond_init(&movie.tick_cond);
    g_mutex_init(&movie.tick_lock);
    g_mutex_init(&movie.frame_lock);

    displayThread = g_thread_new("Display thread", display_thread, (gpointer)&gc_context);
    inputControllerThread = g_thread_new("Input controller thread", input_controller_thread, (gpointer)&gc_context);
    x11EventThread = g_thread_new("X11 Event thread", x11_event_thread, (gpointer)&gc_context);

    g_main_loop_run(mainLoop);

    gc_context.exit = TRUE;
    g_thread_join(displayThread); 
    g_thread_join(inputControllerThread); 
    g_thread_join(x11EventThread); 
    g_cond_clear(&movie.tick_cond);
    g_mutex_clear(&movie.tick_lock);
    g_mutex_clear(&movie.frame_lock);
    g_time_zone_unref(config.timeZone);
}