From 40437b955bb7fccb3ec6480982cad5b79670b6bd Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Mon, 3 Sep 2018 15:52:36 +0800 Subject: move fcn_004552b7 to bit_functions.c and complete it --- csrc/bit_functions.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++ csrc/game_init.c | 17 +------------ 2 files changed, 72 insertions(+), 16 deletions(-) create mode 100644 csrc/bit_functions.c diff --git a/csrc/bit_functions.c b/csrc/bit_functions.c new file mode 100644 index 0000000..b0be170 --- /dev/null +++ b/csrc/bit_functions.c @@ -0,0 +1,71 @@ +#include +#include + +typedef void (*bit_f)(uint16_t*, uint16_t*, uint8_t*, size_t); +extern uint32_t pixel_fmt; + +void fcn_455337(uint16_t *edi, uint16_t *esi, uint8_t *ebx, size_t ecx) +{ + do { + uint16_t ax = *esi; + esi++; + + uint8_t dl = ebx[ax & 0x1f]; + uint8_t dh = ebx[(ax >> 5) & 0x1f]; + uint8_t al = ebx[(ax >> 10) & 0x1f]; + ax = ((uint16_t)(al & 0x3f) << 10) | ((uint16_t)(dh & 0x1f) << 5) | (dl & 0x1f); + + *edi = ax; + edi++; + } while (--ecx); +} + +void fcn_45536c(uint16_t *edi, uint16_t *esi, uint8_t *ebx, size_t ecx) +{ + do { + uint32_t ax = *esi; + esi++; + + uint8_t dl = ebx[ax & 0x1f]; + uint8_t dh = ebx[(ax >> 6) & 0x1f]; + uint16_t dx = ((uint16_t)dh << 8) | dl; + uint8_t al = ebx[(ax >> 11) & 0x1f]; + ax = ((uint16_t)(al & 0x1f) << 11) | (((dx >> 7) & 0x3f) << 5) | (dx & 0x1f); + + *edi = ax; + edi++; + } while (--ecx); +} + +void fcn_4553a1(uint16_t *edi, uint16_t *esi, uint8_t *ebx, size_t ecx) +{ + ebx = (uint8_t*)(((long)ebx) >> 1); + do { + uint16_t ax = *esi; + esi++; + + uint8_t dl = ebx[ax & 0xf]; + uint8_t dh = ebx[(ax >> 4) & 0xf]; + uint8_t al = ebx[(ax >> 8) & 0xf]; + ax = ((uint16_t)(dh & 0xf) << 12) | ((uint16_t)al << 4) | (dl & 0xf); + + *edi = ax; + edi++; + } while (--ecx); +} + +const bit_f ftable_485958[] = { + fcn_455337, fcn_45536c, fcn_45536c, fcn_4553a1 +}; +const uint32_t ftable_485968[] = { + 0x00455442U, 0x00455480U, 0x00455480U, 0x004554beU +}; +const uint32_t ftable_485978[] = { + 0x004555ebU, 0x00455628U, 0x0045566eU, 0x004556abU +}; + +void fcn_004552b7(void * dst, void * src, size_t a3, int a4) +{ + ftable_485958[pixel_fmt](dst, src, (uint8_t*)(0x485d68 + (a4 << 5)), a3 >> 1); +} + diff --git a/csrc/game_init.c b/csrc/game_init.c index d2cdcfe..ea2c16f 100644 --- a/csrc/game_init.c +++ b/csrc/game_init.c @@ -8,21 +8,6 @@ int winning_condition[6] = { 0, 100, 50, 10, 5, 3 }; // 0x46cc00 int game_initial_fund; // 0x49908c int traffic_initial; // 0x46cb44 -const uint32_t ftable_485958[] = { - 0x00455337U, 0x0045536cU, 0x0045536cU, 0x004553a1U, 0x00455442U, - 0x00455480U, 0x00455480U, 0x004554beU, 0x004555ebU, 0x00455628U, - 0x0045566eU, 0x004556abU -}; /* TODO: analyze these functions */ - -void fcn_004552b7(void * a1, void * a2, int a3, int a4) -{ - edi = a1; - esi = a2; - ecx = a3 >> 1; - ebx = 0x485d68 + (a4 << 5); - ftable_485958[dw_47637c](); /* function using esi, edi, ebx, ecx registers */ -} - void fcn_00445a4d(int a1, int a2) { int t = a1 * 15; @@ -48,7 +33,7 @@ int init_new_game(int a0) dw_48a358 = malloc(0x96000); mkf_jump = load_mkf("JUMP.MKF"); read_mkf(mkf_jump, w_4991b6*4+w_4991b8 /* sign ext */, dw_48a358, NULL); - fcn_004552b7(dw_48a354, dw_48a358, 0x96000, -16); + 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_48a3b8 = read_mkf(dw_48a3b0, 8, NULL, NULL); -- cgit v1.2.3