From 57a2bc02febdc58055792cc7c415c08e8d65026f Mon Sep 17 00:00:00 2001 From: Jackson Davis Date: Fri, 29 Aug 2014 08:45:10 +0100 Subject: [PATCH] Add structs/addresses for mouse buffer functions --- src/addresses.h | 3 ++- src/input.c | 27 +++++++++++++-------------- src/osinterface.c | 39 ++++++++++++++++++--------------------- src/osinterface.h | 6 ++++++ 4 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 80ef4cbe20..589dc5e69e 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -169,7 +169,8 @@ #define RCT2_ADDRESS_DSOUND_DEVICES_COUNTER 0x009E2BAC #define RCT2_ADDRESS_CMDLINE 0x009E2D98 - +#define RCT2_ADDRESS_MOUSE_READ_INDEX 0x009E2DE8 +#define RCT2_ADDRESS_MOUSE_WRITE_INDEX 0x009E2DE4 #define RCT2_ADDRESS_LAND_RAISE_COST 0x009E2E1C #define RCT2_ADDRESS_LAND_LOWER_COST 0x009E2E20 #define RCT2_ADDRESS_SELECTED_TERRAIN_EDGE 0x009E2E24 diff --git a/src/input.c b/src/input.c index 55cf373728..85e1102131 100644 --- a/src/input.c +++ b/src/input.c @@ -43,7 +43,7 @@ static void input_mouseover_widget_flatbutton_invalidate(); void process_mouse_over(int x, int y); void sub_6ED801(int x, int y); void invalidate_scroll(); -static void* sub_407074(); +static openrct2_mouse_data* get_mouse_input(); #pragma region Scroll bar input @@ -1558,7 +1558,7 @@ void game_handle_input() */ static void game_get_next_input(int *x, int *y, int *state) { - void* eax = sub_407074(); //RCT2_CALLFUNC_X(0x00407074, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + openrct2_mouse_data* eax = get_mouse_input(); if (eax == NULL) { *x = gCursorState.x; *y = gCursorState.y; @@ -1566,9 +1566,9 @@ static void game_get_next_input(int *x, int *y, int *state) return; } - *x = RCT2_GLOBAL(eax + 0, sint32); - *y = RCT2_GLOBAL(eax + 4, sint32); - *state = RCT2_GLOBAL(eax + 8, sint32); + *x = eax->x; + *y = eax->y; + *state = eax->state; //int eax, ebx, ecx, edx, esi, edi, ebp; //RCT2_CALLFUNC_X(0x006E83C7, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); @@ -1764,16 +1764,15 @@ void invalidate_scroll() window_invalidate_by_id(RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, uint8), RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, uint16)); } -static void* sub_407074() +/** + * rct2: 0x00407074 + */ +static openrct2_mouse_data* get_mouse_input() { - int ecx = RCT2_GLOBAL(0x009E2DE8, uint32); - if (ecx != RCT2_GLOBAL(0x009E2DE4, uint32)) { - int eax = ecx + ecx*2; - ecx++; - ecx &= 0x3F; - eax = 0x1424340 + eax*4; - RCT2_GLOBAL(0x009E2DE8, uint32) = ecx; - return (void*)eax; + int read_index = RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_READ_INDEX, uint32); + if (read_index != RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_WRITE_INDEX, uint32)) { + RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_READ_INDEX, uint32) = (read_index + 1) & 0x3F; + return &mouse_buffer[read_index]; } else { return NULL; } diff --git a/src/osinterface.c b/src/osinterface.c index 9213603e7d..73a7b25e6b 100644 --- a/src/osinterface.c +++ b/src/osinterface.c @@ -40,11 +40,12 @@ openrct2_cursor gCursorState; const unsigned char *gKeysState; unsigned char *gKeysPressed; unsigned int gLastKeyPressed; +openrct2_mouse_data* mouse_buffer = (openrct2_mouse_data*)0x1424340; static void osinterface_create_window(); static void osinterface_close_window(); static void osinterface_resize(int width, int height); -static void sub_406C96(int actionType); +static void store_mouse_input(int state); static SDL_Window *_window; static SDL_Surface *_surface; @@ -350,7 +351,7 @@ void osinterface_process_messages() RCT2_GLOBAL(0x0142431C, int) = e.button.y; switch (e.button.button) { case SDL_BUTTON_LEFT: - sub_406C96(1); //RCT2_CALLPROC_1(0x00406C96, int, 1); + store_mouse_input(1); gCursorState.left = CURSOR_PRESSED; gCursorState.old = 1; break; @@ -358,7 +359,7 @@ void osinterface_process_messages() gCursorState.middle = CURSOR_PRESSED; break; case SDL_BUTTON_RIGHT: - sub_406C96(3); //RCT2_CALLPROC_1(0x00406C96, int, 3); + store_mouse_input(3); gCursorState.right = CURSOR_PRESSED; gCursorState.old = 2; break; @@ -369,7 +370,7 @@ void osinterface_process_messages() RCT2_GLOBAL(0x0142431C, int) = e.button.y; switch (e.button.button) { case SDL_BUTTON_LEFT: - sub_406C96(2); //RCT2_CALLPROC_1(0x00406C96, int, 2); + store_mouse_input(2); gCursorState.left = CURSOR_RELEASED; gCursorState.old = 3; break; @@ -377,7 +378,7 @@ void osinterface_process_messages() gCursorState.middle = CURSOR_RELEASED; break; case SDL_BUTTON_RIGHT: - sub_406C96(4); //RCT2_CALLPROC_1(0x00406C96, int, 4); + store_mouse_input(4); gCursorState.right = CURSOR_RELEASED; gCursorState.old = 4; break; @@ -599,22 +600,18 @@ char osinterface_get_path_separator() return '\\'; } -void sub_406C96(int actionType) +/** + * rct2: 0x00406C96 + */ +static void store_mouse_input(int state) { - int eax = RCT2_GLOBAL(0x009E2DE4, uint32); - int ecx = eax + 1; - ecx &= 0x3F; //Array of 64 point structs, loop around buffer? - if (ecx != RCT2_GLOBAL(0x009E2DE8, uint32)) { - int edx = RCT2_GLOBAL(0x01424318, uint32); // X - //eax is a struct index here. Mutliplied by then and then 4 for the struct with 3 4 byte fields - //Struct is {int x, int y, int actionType} - eax = eax + eax*2; - eax = 0x01424340 + eax * 4; //get base of struct, address is base of array - *((uint32*)eax) = edx; - edx = RCT2_GLOBAL(0x0142431C, uint32); // Y - *((uint32*)eax + 1) = edx; - edx = actionType; - *((uint32*)eax + 2) = edx; - RCT2_GLOBAL(0x009E2DE4, uint32) = ecx; + int write_index = RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_WRITE_INDEX, uint32); + int next_write_index = (write_index + 1) & 0x3F; //64 length buffer + + if (next_write_index != RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_READ_INDEX, uint32)) { + mouse_buffer[write_index].x = RCT2_GLOBAL(0x01424318, uint32); + mouse_buffer[write_index].y = RCT2_GLOBAL(0x0142431C, uint32); + mouse_buffer[write_index].state = state; + RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_WRITE_INDEX, uint32) = next_write_index; } } diff --git a/src/osinterface.h b/src/osinterface.h index 6d2cade7aa..75fc3b19f1 100644 --- a/src/osinterface.h +++ b/src/osinterface.h @@ -66,6 +66,12 @@ typedef struct { int old; } openrct2_cursor; +typedef struct { + int x, y; + int state; //0 = ? 1 = LeftDown 2 = LeftUp 3 = RightDown 4 = RightUp +} openrct2_mouse_data; + +extern openrct2_mouse_data* mouse_buffer; extern openrct2_cursor gCursorState; extern const unsigned char *gKeysState; extern unsigned char *gKeysPressed;