# HG changeset patch # User Michael Pavone # Date 1462895957 25200 # Node ID 7267bc1ab54708ac4919920a7d0db10d6e355d16 # Parent 01a91df5b87cb92fc1881834200c2254c0851fbc Fix bug in 68K movep.l when the destination is a register mapped to a host register diff -r 01a91df5b87c -r 7267bc1ab547 io.c --- a/io.c Fri May 06 19:19:42 2016 -0700 +++ b/io.c Tue May 10 08:59:17 2016 -0700 @@ -26,6 +26,7 @@ "3-button gamepad", "6-button gamepad", "Mega Mouse", + "Saturn Keyboard", "Menacer", "Justifier", "Sega multi-tap", @@ -107,6 +108,7 @@ static keybinding * bindings[0x10000]; static joystick joysticks[MAX_JOYSTICKS]; static mousebinding mice[MAX_MICE]; +static io_port *keyboard_port; const uint8_t dpadbits[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT}; void bind_key(int keycode, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value) @@ -254,7 +256,20 @@ } } -void handle_keydown(int keycode) +void store_key_event(uint16_t code) +{ + if (keyboard_port) { + keyboard_port->device.keyboard.write_pos = (keyboard_port->device.keyboard.write_pos + 1) & 7; + if (keyboard_port->device.keyboard.write_pos == keyboard_port->device.keyboard.read_pos) { + //we've wrapped around to the read position, drop this event + keyboard_port->device.keyboard.write_pos = (keyboard_port->device.keyboard.write_pos - 1) & 7; + return; + } + keyboard_port->device.keyboard.events[keyboard_port->device.keyboard.write_pos] = code; + } +} + +void handle_keydown(int keycode, char scancode) { int bucket = keycode >> 15 & 0xFFFF; if (!bindings[bucket]) { @@ -263,6 +278,7 @@ int idx = keycode & 0x7FFF; keybinding * binding = bindings[bucket] + idx; handle_binding_down(binding); + store_key_event(scancode); } void handle_joydown(int joystick, int button) @@ -388,7 +404,7 @@ } } -void handle_keyup(int keycode) +void handle_keyup(int keycode, char scancode) { int bucket = keycode >> 15 & 0xFFFF; if (!bindings[bucket]) { @@ -397,6 +413,7 @@ int idx = keycode & 0x7FFF; keybinding * binding = bindings[bucket] + idx; handle_binding_up(binding); + store_key_event(0x100 | scancode); } void handle_joyup(int joystick, int button) @@ -1060,6 +1077,14 @@ } map_bindings(ports, mice[mouse].buttons, MAX_MOUSE_BUTTONS); } + keyboard_port = NULL; + for (int i = 0; i < 3; i++) + { + if (ports[i].device_type == IO_SATURN_KEYBOARD) { + keyboard_port = ports + i; + break; + } + } //not really related to the intention of this function, but the best place to do this currently if (speeds[0] != 100) { set_speed_percent(genesis, speeds[0]); diff -r 01a91df5b87c -r 7267bc1ab547 io.h --- a/io.h Fri May 06 19:19:42 2016 -0700 +++ b/io.h Tue May 10 08:59:17 2016 -0700 @@ -13,6 +13,7 @@ IO_GAMEPAD3, IO_GAMEPAD6, IO_MOUSE, + IO_SATURN_KEYBOARD, IO_MENACER, IO_JUSTIFIER, IO_SEGA_MULTI, @@ -45,6 +46,11 @@ uint8_t tr_counter; uint8_t mouse_num; } mouse; + struct { + uint16_t events[8]; + uint8_t read_pos; + uint8_t write_pos; + } keyboard; } device; uint8_t output; uint8_t control; @@ -76,8 +82,8 @@ void io_adjust_cycles(io_port * pad, uint32_t current_cycle, uint32_t deduction); void io_data_write(io_port * pad, uint8_t value, uint32_t current_cycle); uint8_t io_data_read(io_port * pad, uint32_t current_cycle); -void handle_keydown(int keycode); -void handle_keyup(int keycode); +void handle_keydown(int keycode, char scancode); +void handle_keyup(int keycode, char scancode); void handle_joydown(int joystick, int button); void handle_joyup(int joystick, int button); void handle_joy_dpad(int joystick, int dpad, uint8_t state); diff -r 01a91df5b87c -r 7267bc1ab547 m68k_core_x86.c --- a/m68k_core_x86.c Fri May 06 19:19:42 2016 -0700 +++ b/m68k_core_x86.c Tue May 10 08:59:17 2016 -0700 @@ -949,6 +949,7 @@ add_ir(code, 2, opts->gen.scratch1, SZ_D); push_r(code, opts->gen.scratch1); call(code, opts->read_8); + movzx_rr(code, opts->gen.scratch1, opts->gen.scratch1, SZ_B, SZ_W); shl_ir(code, 16, opts->gen.scratch1, SZ_D); or_rr(code, opts->gen.scratch1, reg, SZ_D); } else { diff -r 01a91df5b87c -r 7267bc1ab547 render_sdl.c --- a/render_sdl.c Fri May 06 19:19:42 2016 -0700 +++ b/render_sdl.c Tue May 10 08:59:17 2016 -0700 @@ -554,14 +554,55 @@ return -1; } +uint8_t scancode_map[SDL_NUM_SCANCODES] = { + [SDL_SCANCODE_A] = 0x1C, + [SDL_SCANCODE_B] = 0x32, + [SDL_SCANCODE_C] = 0x21, + [SDL_SCANCODE_D] = 0x23, + [SDL_SCANCODE_E] = 0x24, + [SDL_SCANCODE_F] = 0x28, + [SDL_SCANCODE_G] = 0x34, + [SDL_SCANCODE_H] = 0x33, + [SDL_SCANCODE_I] = 0x43, + [SDL_SCANCODE_J] = 0x3B, + [SDL_SCANCODE_K] = 0x42, + [SDL_SCANCODE_L] = 0x4B, + [SDL_SCANCODE_M] = 0x3A, + [SDL_SCANCODE_N] = 0x31, + [SDL_SCANCODE_O] = 0x44, + [SDL_SCANCODE_P] = 0x4D, + [SDL_SCANCODE_Q] = 0x15, + [SDL_SCANCODE_R] = 0x2D, + [SDL_SCANCODE_S] = 0x1B, + [SDL_SCANCODE_T] = 0x2C, + [SDL_SCANCODE_U] = 0x3C, + [SDL_SCANCODE_V] = 0x2A, + [SDL_SCANCODE_W] = 0x1D, + [SDL_SCANCODE_X] = 0x22, + [SDL_SCANCODE_Y] = 0x35, + [SDL_SCANCODE_Z] = 0x1A, + [SDL_SCANCODE_1] = 0x16, + [SDL_SCANCODE_2] = 0x1E, + [SDL_SCANCODE_3] = 0x26, + [SDL_SCANCODE_4] = 0x25, + [SDL_SCANCODE_5] = 0x2E, + [SDL_SCANCODE_6] = 0x36, + [SDL_SCANCODE_7] = 0x3D, + [SDL_SCANCODE_8] = 0x3E, + [SDL_SCANCODE_9] = 0x46, + [SDL_SCANCODE_0] = 0x45, + [SDL_SCANCODE_RETURN] = 0x5A, + [SDL_SCANCODE_SPACE] = 0x29 +}; + int32_t handle_event(SDL_Event *event) { switch (event->type) { case SDL_KEYDOWN: - handle_keydown(event->key.keysym.sym); + handle_keydown(event->key.keysym.sym, scancode_map[event->key.keysym.scancode]); break; case SDL_KEYUP: - handle_keyup(event->key.keysym.sym); + handle_keyup(event->key.keysym.sym, scancode_map[event->key.keysym.scancode]); break; case SDL_JOYBUTTONDOWN: handle_joydown(find_joystick_index(event->jbutton.which), event->jbutton.button);