summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--io.c29
-rw-r--r--io.h10
-rw-r--r--m68k_core_x86.c1
-rwxr-xr-xrender_sdl.c45
4 files changed, 79 insertions, 6 deletions
diff --git a/io.c b/io.c
index 2002854..0e562a1 100644
--- a/io.c
+++ b/io.c
@@ -26,6 +26,7 @@ const char * device_type_names[] = {
"3-button gamepad",
"6-button gamepad",
"Mega Mouse",
+ "Saturn Keyboard",
"Menacer",
"Justifier",
"Sega multi-tap",
@@ -107,6 +108,7 @@ typedef struct {
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_binding_down(keybinding * binding)
}
}
-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 @@ void handle_keydown(int keycode)
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_binding_up(keybinding * binding)
}
}
-void handle_keyup(int keycode)
+void handle_keyup(int keycode, char scancode)
{
int bucket = keycode >> 15 & 0xFFFF;
if (!bindings[bucket]) {
@@ -397,6 +413,7 @@ void handle_keyup(int keycode)
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 @@ void map_all_bindings(io_port *ports)
}
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 --git a/io.h b/io.h
index e020dc7..1fb1564 100644
--- a/io.h
+++ b/io.h
@@ -13,6 +13,7 @@ enum {
IO_GAMEPAD3,
IO_GAMEPAD6,
IO_MOUSE,
+ IO_SATURN_KEYBOARD,
IO_MENACER,
IO_JUSTIFIER,
IO_SEGA_MULTI,
@@ -45,6 +46,11 @@ typedef struct {
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 setup_io_devices(tern_node * config, rom_info *rom, genesis_context * gen);
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 --git a/m68k_core_x86.c b/m68k_core_x86.c
index 26a8dbb..c07760b 100644
--- a/m68k_core_x86.c
+++ b/m68k_core_x86.c
@@ -949,6 +949,7 @@ void translate_m68k_movep(m68k_options * opts, m68kinst * inst)
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 --git a/render_sdl.c b/render_sdl.c
index 12369dc..7347af3 100755
--- a/render_sdl.c
+++ b/render_sdl.c
@@ -554,14 +554,55 @@ int lowest_unused_joystick_index()
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);