diff --git a/src/libretro.cpp b/src/libretro.cpp index 86a95085..d1e419d8 100644 --- a/src/libretro.cpp +++ b/src/libretro.cpp @@ -152,93 +152,34 @@ void retro_reset(void) static void update_input(void) { - int dir_x = 0; - int dir_y = 0; + uint16_t keys = 0; + keys |= (!!input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A)) << 0; + keys |= (!!input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B)) << 1; + keys |= (!!input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT)) << 2; + keys |= (!!input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START)) << 3; + keys |= (!!input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT)) << 4; + keys |= (!!input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT)) << 5; + keys |= (!!input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP)) << 6; + keys |= (!!input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN)) << 7; + keys |= (!!input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R)) << 8; + keys |= (!!input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L)) << 9; + keys |= (!!input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X)) << 10; + keys |= (!!input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y)) << 11; - input_poll_cb(); - if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP)) - dir_y--; - if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN)) - dir_y++; - if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT)) - dir_x--; - if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT)) - dir_x++; + for (uint8_t i = 0; i < 12; i++) { + bool key = !!((keys >> i) & 1); + uint8_t nds_key = i > 9 ? i + 6 : i; - if (input_state_cb(0, RETRO_DEVICE_KEYBOARD, 0, RETROK_RETURN)) - log_cb(RETRO_LOG_INFO, "Return key is pressed!\n"); - - if (input_state_cb(0, RETRO_DEVICE_KEYBOARD, 0, RETROK_x)) - log_cb(RETRO_LOG_INFO, "x key is pressed!\n"); - - int16_t mouse_x = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X); - int16_t mouse_y = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y); - bool mouse_l = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT); - bool mouse_r = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT); - bool mouse_down = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELDOWN); - bool mouse_up = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_WHEELUP); - bool mouse_middle = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_MIDDLE); - if (mouse_x) - log_cb(RETRO_LOG_INFO, "Mouse X: %d\n", mouse_x); - if (mouse_y) - log_cb(RETRO_LOG_INFO, "Mouse Y: %d\n", mouse_y); - if (mouse_l) - log_cb(RETRO_LOG_INFO, "Mouse L pressed.\n"); - if (mouse_r) - log_cb(RETRO_LOG_INFO, "Mouse R pressed.\n"); - if (mouse_down) - log_cb(RETRO_LOG_INFO, "Mouse wheeldown pressed.\n"); - if (mouse_up) - log_cb(RETRO_LOG_INFO, "Mouse wheelup pressed.\n"); - if (mouse_middle) - log_cb(RETRO_LOG_INFO, "Mouse middle pressed.\n"); - - mouse_rel_x += mouse_x; - mouse_rel_y += mouse_y; - if (mouse_rel_x >= 310) - mouse_rel_x = 309; - else if (mouse_rel_x < 10) - mouse_rel_x = 10; - if (mouse_rel_y >= 230) - mouse_rel_y = 229; - else if (mouse_rel_y < 10) - mouse_rel_y = 10; - - bool pointer_pressed = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_PRESSED); - int16_t pointer_x = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X); - int16_t pointer_y = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y); - if (pointer_pressed) - log_cb(RETRO_LOG_INFO, "Pointer: (%6d, %6d).\n", pointer_x, pointer_y); - - dir_x += input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 5000; - dir_y += input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / 5000; - dir_x += input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 5000; - dir_y += input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 5000; - - x_coord = (x_coord + dir_x) & 31; - y_coord = (y_coord + dir_y) & 31; - - if (rumble.set_rumble_state) - { - static bool old_start; - static bool old_select; - uint16_t strength_strong = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2) ? 0x4000 : 0xffff; - uint16_t strength_weak = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2) ? 0x4000 : 0xffff; - bool start = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START); - bool select = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT); - if (old_start != start) - log_cb(RETRO_LOG_INFO, "Strong rumble: %s.\n", start ? "ON": "OFF"); - rumble.set_rumble_state(0, RETRO_RUMBLE_STRONG, start * strength_strong); - - if (old_select != select) - log_cb(RETRO_LOG_INFO, "Weak rumble: %s.\n", select ? "ON": "OFF"); - rumble.set_rumble_state(0, RETRO_RUMBLE_WEAK, select * strength_weak); - - old_start = start; - old_select = select; + + if (key) { + NDS::PressKey(nds_key); + } else { + NDS::ReleaseKey(nds_key); + } } } + static void check_variables(void) { @@ -265,6 +206,10 @@ void retro_run(void) update_input(); NDS::RunFrame(); memcpy(frame_buf, GPU::Framebuffer, 256 * 384 * 4); + for (int i = 0; i < 256*192*2; i++) + { + frame_buf[i] = ntohl(frame_buf[i]); + } video_cb(frame_buf, 256, 384, 0); if (!use_audio_cb)