From 63d7007905047e5f488e179a56d861dfaa17aa90 Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Mon, 1 Oct 2018 21:19:44 +0800 Subject: data_struct -> graph_struct --- csrc/data_struct.c | 47 ----------------------------------------------- csrc/data_struct.h | 16 ---------------- csrc/drawing.c | 18 +++++++++--------- csrc/game_init.c | 13 +++++++------ csrc/graph_struct.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ csrc/graph_struct.h | 19 +++++++++++++++++++ csrc/media_init.c | 8 ++++---- csrc/tools_ui.c | 9 +++++---- 8 files changed, 90 insertions(+), 86 deletions(-) delete mode 100644 csrc/data_struct.c delete mode 100644 csrc/data_struct.h create mode 100644 csrc/graph_struct.c create mode 100644 csrc/graph_struct.h diff --git a/csrc/data_struct.c b/csrc/data_struct.c deleted file mode 100644 index afef28e..0000000 --- a/csrc/data_struct.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2018 Iru Cai - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -#include -#include -#include "data_struct.h" - -static inline void mem_copy_words(void *dst, void *src, size_t n) -{ - memcpy(dst, src, n*2); -} - -struct st * allocate_some_struct(int a1, int a2, int a3, int a4) -{ - struct st * newst = (struct st *)malloc(a1 * a2 * 2 + 12); - newst->f0 = a1; - newst->f2 = a2; - newst->f4 = a3; - newst->f6 = a4; - newst->f8 = newst->data; -} - -/* this function looks buggy and can crash the game */ - -struct st * fcn_00451a97(struct st *a1, struct st *a2, int a3, int a4, int a5, int a6) -{ - if (a2 == NULL) { - a2 = malloc(a5 * a6 * 2 + 12); - } - - a2->f0 = a5; /* number of words(16b) per block? */ - a2->f2 = a6; /* number of blocks? */ - a2->f4 = a2->f6 = 0; - a2->f8 = a2->data; - - int16_t *ebx = &a1->f8[a1->f0 * a4 + a3]; - int16_t *esi = a2->f8; - - for (int i = 0; i < a6; i++) { - mem_copy_words(esi, ebx, a5); /* copy a5 words(16b) from ebx to esi */ - esi = &esi[a5]; - ebx = &ebx[a1->f0]; - } - return a2; -} diff --git a/csrc/data_struct.h b/csrc/data_struct.h deleted file mode 100644 index 9481834..0000000 --- a/csrc/data_struct.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) 2018 Iru Cai - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -struct st -{ - int16_t f0; - int16_t f2; - int16_t f4; - int16_t f6; - int16_t * f8; - int16_t data[0]; -}; - -struct st * allocate_some_struct(int a1, int a2, int a3, int a4); diff --git a/csrc/drawing.c b/csrc/drawing.c index 430c27c..fc5bd8f 100644 --- a/csrc/drawing.c +++ b/csrc/drawing.c @@ -5,11 +5,11 @@ #include #include "player_info.h" -#include "data_struct.h" +#include "graph_struct.h" -struct st st_46caec; +struct graph_st st_46caec; -void fcn_00455b3a(int a1, int a2, uint16_t *a3, struct st *a4, int a5, int a6) +void fcn_00455b3a(int a1, int a2, uint16_t *a3, struct graph_st *a4, int a5, int a6) { int ret = 1; a5 -= (int16_t)a4->f4; @@ -62,7 +62,7 @@ void fcn_00455b3a(int a1, int a2, uint16_t *a3, struct st *a4, int a5, int a6) return ret; } -int fcn_455c52(uint32_t a0, uint32_t a1, uint16_t *a2, struct st * a3, int a4, int a5, int a6) +int fcn_455c52(uint32_t a0, uint32_t a1, uint16_t *a2, struct graph_st * a3, int a4, int a5, int a6) { a4 -= (int16_t)a3->f4; a5 -= (int16_t)a3->f6; @@ -163,12 +163,12 @@ int fcn_455c52(uint32_t a0, uint32_t a1, uint16_t *a2, struct st * a3, int a4, i return 0; } -void fcn_4562a5(struct st * a0, struct st * a1, int a2, int a3) +void fcn_4562a5(struct graph_st * a0, struct graph_st * a1, int a2, int a3) { fcn_455c52((uint16_t)a0->f0, (uint16_t)a0->f2, a0->f8, a1, a2, a3, 0); } -void fcn_456418(uint16_t *a0, struct st *a1, int a2, int a3) +void fcn_456418(uint16_t *a0, struct graph_st *a1, int a2, int a3) { fcn_455c52(640, 480, a0, a1, a2, a3, 0); } @@ -304,7 +304,7 @@ void player_say(int p, int t, const char *s) create_some_font(0x10, 0x101010, 0, 2, 1); IDirectDrawSurface_Lock(pddrawsf2, NULL, &sfdesc1, 1, 0); st_46caec.f8 = sfdesc1.lpSurface; - struct st * edi = fcn_00451a97(&st_46caec, NULL, 0, 40, 440, 220); + struct graph_st * edi = crop_graph(&st_46caec, NULL, 0, 40, 440, 220); fcn_456418(sfdesc1.lpSurface, dw_48bad8+0x54, 220, 130); ecx = dword [p * 0x34 + 0x498eb0]; edx = t + 1; @@ -390,7 +390,7 @@ void move_animation(int obj, int x1, int y1, int x2, int y2, int T) r0.left = -1000; IDirectDrawSurface_Lock(pddrawsf2, NULL, &sfdesc1, 1, 0); st_46caec.f8 = sfdesc1.lpSurface; - struct st * st0 = fcn_00451a97(&st_46caec, NULL, 0, 40, 440, 440); /* st0 @ sp+0x4c */ + struct graph_st * st0 = crop_graph(&st_46caec, NULL, 0, 40, 440, 440); /* st0 @ sp+0x4c */ IDirectDrawSurface_Unlock(pddrawsf2, NULL); while (dist != 0) { @@ -442,7 +442,7 @@ void move_animation(int obj, int x1, int y1, int x2, int y2, int T) free(st0); } -void fcn_4563f5(uint16_t *a0, struct st *a1, int a2, int a3) +void fcn_4563f5(uint16_t *a0, struct graph_st *a1, int a2, int a3) { fcn_00455b3a(640, 480, a0, a1, a2, a3); } diff --git a/csrc/game_init.c b/csrc/game_init.c index 5c09c05..1c06347 100644 --- a/csrc/game_init.c +++ b/csrc/game_init.c @@ -6,6 +6,7 @@ #include "player_info.h" #include "window_util.h" #include "stock.h" +#include "graph_struct.h" int mkf_jump; // 0x48a3b0 @@ -47,8 +48,8 @@ int init_new_game(int a0) mkf_jump = load_mkf("JUMP.MKF"); read_mkf(mkf_jump, game_stage * 4 + game_map, dw_48a358, NULL); fcn_004552b7(dw_48a354, dw_48a358, 0x96000, -16); /* @ bit_functions.c */ - dw_48a3a4 = allocate_some_struct(440, 155, 0, 0); - dw_48a3a0 = allocate_some_struct(192, 461, 0, 0); + dw_48a3a4 = allocate_graph_st(440, 155, 0, 0); + dw_48a3a0 = allocate_graph_st(192, 461, 0, 0); dw_48a3b8 = read_mkf(dw_48a3b0, 8, NULL, NULL); dw_48a3c0 = read_mkf(mkf_data, 2, NULL, NULL); dw_48a3ac = ebp = 0; @@ -100,7 +101,7 @@ int init_new_game(int a0) eax = edx * 3; edx = eax * 4; eax = dw_48a3b8 + 12 + edx; - dw_48a390 = fcn_00451a97(eax, 0, 0x8a, 15, 41, 133); /* function in data_struct.c */ + dw_48a390 = crop_graph(eax, 0, 0x8a, 15, 41, 133); edx = game_stage; /* sign ext */ eax = edx * 20; @@ -108,7 +109,7 @@ int init_new_game(int a0) eax = edx * 12; edx = dw_48a3b8 + 12; eax += edx; - dw_48a398 = fcn_00451a97(eax, 0, 11, 166, 79, 39); + dw_48a398 = crop_graph(eax, 0, 11, 166, 79, 39); edx = game_stage; /* sign ext */ eax = edx * 20; @@ -116,7 +117,7 @@ int init_new_game(int a0) eax = edx * 12; edx = dw_48a3b8 + 12; eax += edx; - dw_48a394 = fcn_00451a97(eax, 0, 99, 166, 79, 39); + dw_48a394 = crop_graph(eax, 0, 99, 166, 79, 39); edx = game_stage; /* sign ext */ eax = edx * 20; @@ -124,7 +125,7 @@ int init_new_game(int a0) eax = edx * 3; edx = eax * 4; eax = dw_48a3b8 + 12 + edx; - dw_48a39c = fcn_00451a97(eax, 0, 157, 216, 23, 24); + dw_48a39c = crop_graph(eax, 0, 157, 216, 23, 24); sub.WINMM.dll_mciSendStringA_9cf(0x8001); /* TODO: 0x4549cf */ diff --git a/csrc/graph_struct.c b/csrc/graph_struct.c new file mode 100644 index 0000000..52aa207 --- /dev/null +++ b/csrc/graph_struct.c @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2018 Iru Cai + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include +#include +#include "graph_struct.h" + +static inline void mem_copy_words(void *dst, void *src, size_t n) +{ + memcpy(dst, src, n*2); +} + +struct graph_st * allocate_graph_st(int w, int h, int x, int y) +{ + struct graph_st * newst = (struct graph_st *)malloc(w * h * 2 + sizeof(graph_st)); + newst->width = w; + newst->height = h; + newst->x = x; + newst->y = y; + newst->gdata = newst->data; + return newst; +} + +/* crop graph a1 starting at (x, y) as laft-top coordinate, + * and get graph a2 with size w*h. + * + * this function looks buggy and can crash the game */ + +struct graph_st * crop_graph(struct graph_st *a1, struct graph_st *a2, int x, int y, int w, int h) +{ + if (a2 == NULL) { + a2 = allocate_graph_st(w, h, 0, 0); + } + + int16_t *src = &a1->gdata[a1->width * y + x]; + int16_t *dst = a2->gdata; + + for (int i = 0; i < h; i++) { + mem_copy_words(esi, ebx, w); + dst = dst + w; + src = src + a1->width; + } + return a2; +} diff --git a/csrc/graph_struct.h b/csrc/graph_struct.h new file mode 100644 index 0000000..4859508 --- /dev/null +++ b/csrc/graph_struct.h @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2018 Iru Cai + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include + +struct graph_st +{ + int16_t width; + int16_t height; + int16_t x; + int16_t y; + int16_t * gdata; + int16_t data[0]; +}; + +struct graph_st * allocate_graph_st(int w, int h, int x, int y); +struct graph_st * crop_graph(struct graph_st *a1, struct graph_st *a2, int x, int y, int w, int h); diff --git a/csrc/media_init.c b/csrc/media_init.c index 627dbc0..efc5b83 100644 --- a/csrc/media_init.c +++ b/csrc/media_init.c @@ -4,7 +4,7 @@ */ #include "global.h" -#include "data_struct.h" +#include "graph_struct.h" #include "player_info.h" #include "sound_struct.h" #include "window_util.h" @@ -36,11 +36,11 @@ int32_t dw_48a164, dw_48a168; MMRESULT gTimerEvent; // 0x48a16c uint16_t modded_key; // 0x46cb07 -struct st st_46cb14 = {640, 480, 0, 0, NULL}; // 0x46cb14, 12 bytes +struct graph_st st_46cb14 = {640, 480, 0, 0, NULL}; // 0x46cb14, 12 bytes uint8_t speed_tab[3] = {6, 4, 2}; // 0x64cb20 uint32_t dw_46cb23 = 0; -void fcn_00456280(struct st *s, int a1, int a2, int a3) +void fcn_00456280(struct graph_st *s, int a1, int a2, int a3) { fcn_00455b3a((uint32_t)s->f0, (uint32_t)s->f2, s->f8, a1, a2, a3); } @@ -614,7 +614,7 @@ void init_data_and_timer() /* edx = 0 */ dw_46cb10 = read_mkf(mkf_data, 0, NULL, NULL); - dw_48a0e8 = allocate_some_struct(32, 32, 0, 0); + dw_48a0e8 = allocate_graph_st(32, 32, 0, 0); b_48a179 = b_48a17a = b_48a178 = 0; dw_48a168 = -1; ShowCursor(0); diff --git a/csrc/tools_ui.c b/csrc/tools_ui.c index a8eb903..534f43c 100644 --- a/csrc/tools_ui.c +++ b/csrc/tools_ui.c @@ -11,8 +11,9 @@ const char str_cross_sym[] = "\xa1\xd1%d"; // x%d char tab_48c548[16]; int selected_tool; // 0x48c560 uint8_t tool_amount[60]; // 0x49915c 4*15 +struct graph_st * dw_48c558; -void fcn_447c6e(struct st *a1, struct st *a2, int player) +void fcn_447c6e(struct graph_st *a1, struct graph_st *a2, int player) { char str[40]; @@ -20,9 +21,9 @@ void fcn_447c6e(struct st *a1, struct st *a2, int player) create_some_font(20, 0xffffff, 0x101010, 3, 0); if (a1 == NULL) { - a1 = (struct st*)((void*)(a2) + 24); + a1 = (struct graph_st*)((void*)(a2) + 24); } else { - fcn_00456280(a1, (struct st*)((void*)(a2) + 24), 0, 0); + fcn_00456280(a1, (struct graph_st*)((void*)(a2) + 24), 0, 0); } int j = 0; @@ -142,7 +143,7 @@ void tools_ui() } IDirectDrawSurface_Lock(pddrawsf2, 0, &sfdesc1, 1, 0); st_46caec.f8 = sfdesc1.lpSurface; - /* struct st* */ dw_48c558 = fcn_00451a97(&st_46caec, NULL, 0, 40, 440, 440); + dw_48c558 = crop_graph(&st_46caec, NULL, 0, 40, 440, 440); IDirectDrawSurface_Unlock(pddrawsf2, NULL); do { -- cgit v1.2.3