Basic controller input
This commit is contained in:
@ -187,7 +187,7 @@ void ppu_mode_hblank() {
|
|||||||
u32 fps = frame_count;
|
u32 fps = frame_count;
|
||||||
start_timer = end;
|
start_timer = end;
|
||||||
frame_count = 0;
|
frame_count = 0;
|
||||||
printf("FPS: %ld\n", fps);
|
//printf("FPS: %ld\n", fps);
|
||||||
if(cart_need_save()){
|
if(cart_need_save()){
|
||||||
cart_battery_save();
|
cart_battery_save();
|
||||||
}
|
}
|
||||||
|
63
lib/ui.c
63
lib/ui.c
@ -36,11 +36,14 @@ static int screenHeight;
|
|||||||
void ui_init(){
|
void ui_init(){
|
||||||
screenWidth = XRES*scale;
|
screenWidth = XRES*scale;
|
||||||
screenHeight = YRES*scale;
|
screenHeight = YRES*scale;
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
|
||||||
printf("SDL INIT\n");
|
printf("SDL INIT\n");
|
||||||
TTF_Init();
|
TTF_Init();
|
||||||
printf("TTF INIT\n");
|
printf("TTF INIT\n");
|
||||||
|
|
||||||
|
SDL_JoystickEventState(SDL_ENABLE);
|
||||||
|
SDL_JoystickOpen(0);
|
||||||
|
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
strcpy(buffer, emu_get_context()->app_path);
|
strcpy(buffer, emu_get_context()->app_path);
|
||||||
*strrchr(buffer, '\\') = 0;
|
*strrchr(buffer, '\\') = 0;
|
||||||
@ -400,6 +403,48 @@ void ui_on_key(bool down, u32 key_code) {
|
|||||||
gamepad_int_update();
|
gamepad_int_update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ui_on_joy_button(u8 button, bool down) {
|
||||||
|
switch(button){
|
||||||
|
case 0: gamepad_get_state()->b = down; break;
|
||||||
|
case 1: gamepad_get_state()->a = down; break;
|
||||||
|
case 7: gamepad_get_state()->start = down; break;
|
||||||
|
case 6: gamepad_get_state()->select = down; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_on_joy_hat(u8 hat, u8 value) {
|
||||||
|
if(hat == 0){
|
||||||
|
gamepad_get_state()->up = value & SDL_HAT_UP;
|
||||||
|
gamepad_get_state()->down = value & SDL_HAT_DOWN;
|
||||||
|
gamepad_get_state()->left = value & SDL_HAT_LEFT;
|
||||||
|
gamepad_get_state()->right = value & SDL_HAT_RIGHT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DEADZONE 10000
|
||||||
|
|
||||||
|
void ui_on_Joy_axis(u8 axis, int16_t value) {
|
||||||
|
if(axis == 1) {
|
||||||
|
gamepad_get_state()->up = false;
|
||||||
|
gamepad_get_state()->down = false;
|
||||||
|
if(value < -DEADZONE) {
|
||||||
|
gamepad_get_state()->up = true;
|
||||||
|
}
|
||||||
|
if(value > DEADZONE) {
|
||||||
|
gamepad_get_state()->down = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(axis == 0) {
|
||||||
|
gamepad_get_state()->left = false;
|
||||||
|
gamepad_get_state()->right = false;
|
||||||
|
if(value < -DEADZONE) {
|
||||||
|
gamepad_get_state()->left = true;
|
||||||
|
}
|
||||||
|
if(value > DEADZONE) {
|
||||||
|
gamepad_get_state()->right = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ui_handle_events(){
|
void ui_handle_events(){
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
@ -422,6 +467,22 @@ void ui_handle_events(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(e.type == SDL_JOYBUTTONDOWN) {
|
||||||
|
ui_on_joy_button(e.jbutton.button, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(e.type == SDL_JOYBUTTONUP) {
|
||||||
|
ui_on_joy_button(e.jbutton.button, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(e.type == SDL_JOYHATMOTION) {
|
||||||
|
ui_on_joy_hat(e.jhat.hat, e.jhat.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(e.type == SDL_JOYAXISMOTION) {
|
||||||
|
ui_on_Joy_axis(e.jaxis.axis, e.jaxis.value);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user