Beispiel #1
0
void input_match_keyboard(Input::Controllers *controllers, SDL_Event event) {
	// Match NES buttons to keyboard buttons
	
	nesinput_t input;

	input.nescode = 0x00;
	input.player = 0;
	input.pressed = 0;
	input.turboa = 0;
	input.turbob = 0;

	if (event.type == SDL_KEYDOWN) { input.pressed = 1; }

	for (int i = 0; i < NUMGAMEPADS; i++) {
		if (player[i].u == event.key.keysym.scancode) {
			input.nescode = Input::Controllers::Pad::UP;
			input.player = i;
		}
		else if (player[i].d == event.key.keysym.scancode) {
			input.nescode = Input::Controllers::Pad::DOWN;
			input.player = i;
		}
		else if (player[i].l == event.key.keysym.scancode) {
			input.nescode = Input::Controllers::Pad::LEFT;
			input.player = i;
		}
		else if (player[i].r == event.key.keysym.scancode) {
			input.nescode = Input::Controllers::Pad::RIGHT;
			input.player = i;
		}
		else if (player[i].select == event.key.keysym.scancode) {
			input.nescode = Input::Controllers::Pad::SELECT;
			input.player = i;
		}
		else if (player[i].start == event.key.keysym.scancode) {
			input.nescode = Input::Controllers::Pad::START;
			input.player = i;
		}
		else if (player[i].a == event.key.keysym.scancode) {
			input.nescode = Input::Controllers::Pad::A;
			input.player = i;
		}
		else if (player[i].b == event.key.keysym.scancode) {
			input.nescode = Input::Controllers::Pad::B;
			input.player = i;
		}
		else if (player[i].ta == event.key.keysym.scancode) {
			input.nescode = Input::Controllers::Pad::A;
			input.player = i;
			input.turboa = 1;
		}
		else if (player[i].tb == event.key.keysym.scancode) {
			input.nescode = Input::Controllers::Pad::B;
			input.player = i;
			input.turbob = 1;
		}
	}

	input_inject(controllers, input);
	
	if (event.key.keysym.scancode == SDL_SCANCODE_GRAVE && event.type == SDL_KEYDOWN) { timing_set_altspeed(); }
	if (event.key.keysym.scancode == SDL_SCANCODE_GRAVE && event.type == SDL_KEYUP) { timing_set_default(); }
	
	const Uint8 *keys = SDL_GetKeyboardState(NULL);
	
	// Process non-game events
	if (keys[SDL_SCANCODE_F1]) { nst_flip_disk(); }
	if (keys[SDL_SCANCODE_F2]) { nst_reset(0); }
	//if (keys[SDL_SCANCODE_F3]) {  }
	//if (keys[SDL_SCANCODE_F4]) {  }
	if (keys[SDL_SCANCODE_F5]) { nst_state_quicksave(0); }
	if (keys[SDL_SCANCODE_F6]) { nst_state_quicksave(1); }
	if (keys[SDL_SCANCODE_F7]) { nst_state_quickload(0); }
	if (keys[SDL_SCANCODE_F8]) { nst_state_quickload(1); }
	//if (keys[SDL_SCANCODE_F9]) {  }
	//if (keys[SDL_SCANCODE_F10]) {  }
	//if (keys[SDL_SCANCODE_F11]) {  }
	//if (keys[SDL_SCANCODE_F12]) {  }
	
	// Insert Coins
	controllers->vsSystem.insertCoin = 0;
	if (keys[SDL_SCANCODE_1]) { controllers->vsSystem.insertCoin |= Input::Controllers::VsSystem::COIN_1; }
	if (keys[SDL_SCANCODE_2]) { controllers->vsSystem.insertCoin |= Input::Controllers::VsSystem::COIN_2; }
	
	// Rewinder
	if (keys[SDL_SCANCODE_BACKSPACE]) { nst_set_rewind(0); }
	if (keys[SDL_SCANCODE_BACKSLASH]) { nst_set_rewind(1); }
	
	// Escape exits when not in GUI mode
	if (keys[SDL_SCANCODE_ESCAPE]) {
		if (conf.misc_disable_gui) { nst_schedule_quit(); }
	}
	
	// F toggles fullscreen
	if (keys[SDL_SCANCODE_F]) { video_toggle_fullscreen(); }
	if (keys[SDL_SCANCODE_T]) { video_toggle_filter(); }
	if (keys[SDL_SCANCODE_G]) { video_toggle_scalefactor(); }
}
Beispiel #2
0
void input_match_keyboard(Input::Controllers *controllers, SDL_Event event) {
    // Match NES buttons to keyboard buttons

    nesinput_t input;

    input.nescode = 0x00;
    input.player = 0;
    input.pressed = 0;
    input.turboa = 0;
    input.turbob = 0;

    if (event.type == SDL_KEYDOWN) {
        input.pressed = 1;
    }

    for (int i = 0; i < NUMGAMEPADS; i++) {
        if (player[i].u == event.key.keysym.scancode) {
            input.nescode = Input::Controllers::Pad::UP;
            input.player = i;
        }
        else if (player[i].d == event.key.keysym.scancode) {
            input.nescode = Input::Controllers::Pad::DOWN;
            input.player = i;
        }
        else if (player[i].l == event.key.keysym.scancode) {
            input.nescode = Input::Controllers::Pad::LEFT;
            input.player = i;
        }
        else if (player[i].r == event.key.keysym.scancode) {
            input.nescode = Input::Controllers::Pad::RIGHT;
            input.player = i;
        }
        else if (player[i].select == event.key.keysym.scancode) {
            input.nescode = Input::Controllers::Pad::SELECT;
            input.player = i;
        }
        else if (player[i].start == event.key.keysym.scancode) {
            input.nescode = Input::Controllers::Pad::START;
            input.player = i;
        }
        else if (player[i].a == event.key.keysym.scancode) {
            input.nescode = Input::Controllers::Pad::A;
            input.player = i;
        }
        else if (player[i].b == event.key.keysym.scancode) {
            input.nescode = Input::Controllers::Pad::B;
            input.player = i;
        }
        else if (player[i].ta == event.key.keysym.scancode) {
            input.nescode = Input::Controllers::Pad::A;
            input.player = i;
            input.turboa = 1;
        }
        else if (player[i].tb == event.key.keysym.scancode) {
            input.nescode = Input::Controllers::Pad::B;
            input.player = i;
            input.turbob = 1;
        }
    }

    input_inject(controllers, input);

    if (event.key.keysym.scancode == ui.altspeed && event.type == SDL_KEYDOWN) {
        timing_set_altspeed();
    }
    if (event.key.keysym.scancode == ui.altspeed && event.type == SDL_KEYUP) {
        timing_set_default();
    }

    const Uint8 *keys = SDL_GetKeyboardState(NULL);

    // Insert Coins
    controllers->vsSystem.insertCoin = 0;
    if (keys[ui.insertcoin1]) {
        controllers->vsSystem.insertCoin |= Input::Controllers::VsSystem::COIN_1;
    }
    if (keys[ui.insertcoin2]) {
        controllers->vsSystem.insertCoin |= Input::Controllers::VsSystem::COIN_2;
    }

    // Process non-game events
    if (keys[ui.fdsflip]) {
        nst_flip_disk();
    }
    if (keys[ui.fdsswitch]) {
        nst_switch_disk();
    }
    if (keys[ui.qsave1]) {
        nst_state_quicksave(0);
    }
    if (keys[ui.qsave2]) {
        nst_state_quicksave(1);
    }
    if (keys[ui.qload1]) {
        nst_state_quickload(0);
    }
    if (keys[ui.qload2]) {
        nst_state_quickload(1);
    }

    // Screenshot
    if (keys[ui.screenshot]) {
        video_screenshot(NULL);
    }

    // Reset
    if (keys[ui.reset]) {
        nst_reset(0);
    }

    // Rewinder
    if (keys[ui.rwstart]) {
        nst_set_rewind(0);
    }
    if (keys[ui.rwstop]) {
        nst_set_rewind(1);
    }

    // Video
    if (keys[ui.fullscreen]) {
        video_toggle_fullscreen();
    }
    if (keys[ui.filter]) {
        video_toggle_filter();
    }
    if (keys[ui.scalefactor]) {
        video_toggle_scalefactor();
    }

    // NSF
    if (nst_nsf) {
        Nsf nsf(emulator);

        if (keys[SDL_SCANCODE_UP]) {
            nsf.PlaySong();
            video_clear_buffer();
            video_disp_nsf();
        }
        if (keys[SDL_SCANCODE_DOWN]) {
            //nsf.StopSong();
        }
        if (keys[SDL_SCANCODE_LEFT]) {
            nsf.SelectPrevSong();
            video_clear_buffer();
            video_disp_nsf();
        }
        if (keys[SDL_SCANCODE_RIGHT]) {
            nsf.SelectNextSong();
            video_clear_buffer();
            video_disp_nsf();
        }
    }

    // Escape exits when not in GUI mode
    if (keys[SDL_SCANCODE_ESCAPE]) {
        if (conf.misc_disable_gui) {
            nst_schedule_quit();
        }
    }
}