From f448929f739eca2ef30a9188088d5baf5bf3c252 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Thu, 8 May 2014 20:13:58 +0100 Subject: [PATCH 01/99] First couple lines decoded --- src/gfx.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/gfx.c b/src/gfx.c index 022b35e1a2..1e8dc86f84 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -154,6 +154,33 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) { RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + + int eax = 0, ebx = image_id, ecx = x, edx = y, esi = 0, edi = dpi, ebp = 0; + eax = image_id; + eax >>= 26; + RCT2_GLOBAL(0x00EDF81C, uint32) = ebx; + eax &= 0x7; + eax = RCT2_GLOBAL(0x009E3CE4 + 4 * eax, uint32); + RCT2_GLOBAL(0x009E3CDC, uint32) = eax; + if (!(RCT2_GLOBAL(0x00EDF81C, uint32) & 0xE0000000)){ + if (!(ebx & 0x80000000)) + { + if (!(ebx & 0x20000000)){ + eax = ebx; + RCT2_GLOBAL(0x9E3CDC, uint32) = 0; + eax >>= 13; + eax &= 0x1f; + eax = RCT2_GLOBAL(eax * 4 + 0x91FCBC, uint32); + eax <<= 4; + eax = RCT2_GLOBAL(eax + 0x9EBD28, uint32); + ebp = *((uint32*)eax + 0xF3); + esi = *((uint32*)eax + 0xF7); + RCT2_GLOBAL(0x9ABEFF, uint32) = ebp; + RCT2_GLOBAL(0x9ABF03, uint32) = esi; + ebp = *((uint32*)eax + 0xFB); + }//0x67a361 + }//0x67a445 + }//0x67a46e } /** From 2276c198fdf26533e5514d3d3ba711121e56a4b2 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Thu, 8 May 2014 20:43:10 +0100 Subject: [PATCH 02/99] Removed a pointless call in palette tried to make draw sprite more understandable --- src/gfx.c | 20 +++++++++++--------- src/osinterface.c | 4 ++-- src/osinterface.h | 1 + 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 1e8dc86f84..3c6c2ce010 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -26,6 +26,7 @@ #include "rct2.h" #include "strings.h" #include "window.h" +#include "osinterface.h" // HACK These were originally passed back through registers int gLastDrawStringX; @@ -154,30 +155,32 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) { RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + return; int eax = 0, ebx = image_id, ecx = x, edx = y, esi = 0, edi = dpi, ebp = 0; eax = image_id; eax >>= 26; - RCT2_GLOBAL(0x00EDF81C, uint32) = ebx; + RCT2_GLOBAL(0x00EDF81C, uint32) = image_id & 0xE0000000; eax &= 0x7; eax = RCT2_GLOBAL(0x009E3CE4 + 4 * eax, uint32); RCT2_GLOBAL(0x009E3CDC, uint32) = eax; - if (!(RCT2_GLOBAL(0x00EDF81C, uint32) & 0xE0000000)){ - if (!(ebx & 0x80000000)) + if (!(image_id & 0xE0000000)){ + if (!(image_id & (1<<31))) { - if (!(ebx & 0x20000000)){ - eax = ebx; + if (!(image_id & (1<<29))){ + eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; eax >>= 13; eax &= 0x1f; eax = RCT2_GLOBAL(eax * 4 + 0x91FCBC, uint32); eax <<= 4; - eax = RCT2_GLOBAL(eax + 0x9EBD28, uint32); + eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); ebp = *((uint32*)eax + 0xF3); esi = *((uint32*)eax + 0xF7); RCT2_GLOBAL(0x9ABEFF, uint32) = ebp; RCT2_GLOBAL(0x9ABF03, uint32) = esi; ebp = *((uint32*)eax + 0xFB); + eax = ebx;//0x67a310 }//0x67a361 }//0x67a445 }//0x67a46e @@ -195,7 +198,7 @@ void gfx_transpose_palette(int pal, unsigned char product) uint8* esi, *edi; ebx = pal * 16; - esi = (uint8*)(*((int*)(0x009EBD28 + ebx))); + esi = (uint8*)(*((int*)(RCT2_ADDRESS_G1_ELEMENTS + ebx))); ebp = *((short*)(0x009EBD2C + ebx)); eax = *((short*)(0x009EBD30 + ebx)) * 4; edi = (uint8*)0x01424680 + eax; @@ -207,8 +210,7 @@ void gfx_transpose_palette(int pal, unsigned char product) esi += 3; edi += 4; } - - RCT2_CALLPROC_3(0x00405595, int, int, int, 0x01424680, 10, 236); + osinterface_update_palette((char*)0x01424680, 10, 236); } /** diff --git a/src/osinterface.c b/src/osinterface.c index 3e97491e5b..ad3d2c66aa 100644 --- a/src/osinterface.c +++ b/src/osinterface.c @@ -38,7 +38,7 @@ unsigned int gLastKeyPressed; static void osinterface_create_window(); static void osinterface_close_window(); static void osinterface_resize(int width, int height); -static void osinterface_update_palette(char* colours, int start_index, int num_colours); + static SDL_Window *_window; static SDL_Surface *_surface; @@ -150,7 +150,7 @@ static void osinterface_resize(int width, int height) gfx_invalidate_screen(); } -static void osinterface_update_palette(char* colours, int start_index, int num_colours) +void osinterface_update_palette(char* colours, int start_index, int num_colours) { SDL_Color base[256]; SDL_Surface *surface; diff --git a/src/osinterface.h b/src/osinterface.h index 9ec682fea2..6ddcc3d84e 100644 --- a/src/osinterface.h +++ b/src/osinterface.h @@ -45,6 +45,7 @@ void osinterface_init(); void osinterface_process_messages(); void osinterface_draw(); void osinterface_free(); +void osinterface_update_palette(char* colours, int start_index, int num_colours); int osinterface_open_common_file_dialog(int type, char *title, char *filename, char *filterPattern, char *filterName); From f3e7c6c23c8a49aac4f41176a6ca881bba9f56a5 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 9 May 2014 09:18:49 +0100 Subject: [PATCH 03/99] Added more of draw_sprite still needs work. Function call does not work --- src/gfx.c | 237 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 216 insertions(+), 21 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 3c6c2ce010..bcfce787f5 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -145,6 +145,69 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri RCT2_CALLPROC_X(0x006E6F81, left, right, top, bottom, _si, dpi, colour); } +/* +* rct2: 0x67A934 +*/ +void sub_0x67A934(int eax, int ebp, int ebx, int esi, rct_drawpixelinfo *dpi, int x, int y){ + int ecx = x, edx = y, edi = dpi; + ebp = dpi; + esi = RCT2_GLOBAL(0x9E3D08, uint32); + edi = *((uint32*)dpi); + edx += RCT2_GLOBAL(0x9E3D12, uint16); + eax = RCT2_GLOBAL(0x9E3D0E, uint16); + RCT2_GLOBAL(0xEDF808, uint32) = 0; + RCT2_GLOBAL(0x9ABDAC, uint16) = eax; + if (edx > dpi->y) + { + edx -= dpi->y; + RCT2_GLOBAL(0x9ABDAC, uint16) += edx; + if (RCT2_GLOBAL(0x9ABDAC, uint16) <= 0)return; + RCT2_GLOBAL(0xEDF808, uint16) -= edx; + edx = 0; + } + else{ + edx -= dpi->y; + eax = dpi->width; + ebx = edx; + eax += dpi->pitch; + eax *= edx; + edx = ebx; + edi += eax; + } + edx += RCT2_GLOBAL(0x9ABDAC, uint16); + edx -= dpi->height; + if (edx > 0){ + RCT2_GLOBAL(0x9ABDAC, uint16) -= edx; + if (RCT2_GLOBAL(0x9ABDAC, uint16) <= 0)return; + } + eax = RCT2_GLOBAL(0x9E3D0C, uint16); + RCT2_GLOBAL(0xEDF80C, uint32) = 0; + ecx += RCT2_GLOBAL(0x9E3D10, uint16); + + RCT2_GLOBAL(0x9ABDA8, uint16) = eax; + ecx -= dpi->x; + if (ecx < 0){ + RCT2_GLOBAL(0x9ABDA8, uint16) += ecx; + if (RCT2_GLOBAL(0x9ABDA8, uint16) <= 0)return; + RCT2_GLOBAL(0xEDF80C, uint16) -= ecx; + ecx = 0; + } + else{ + edi += ecx; + } + ecx += RCT2_GLOBAL(0x9ABDA8, uint16); + ecx -= dpi->width; + if (ecx > 0){ + RCT2_GLOBAL(0x9ABDA8, uint16) -= ecx; + if (RCT2_GLOBAL(0x9ABDA8, uint16) <= 0)return; + } + eax = dpi->width; + eax += dpi->pitch; + RCT2_GLOBAL(0x9ABDB0, uint16) = eax; + //ebx esi edi + RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); +} + /** * * rct2: 0x0067A28E @@ -154,8 +217,8 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri */ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) { - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); - return; + //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + //return; int eax = 0, ebx = image_id, ecx = x, edx = y, esi = 0, edi = dpi, ebp = 0; eax = image_id; @@ -164,26 +227,158 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax &= 0x7; eax = RCT2_GLOBAL(0x009E3CE4 + 4 * eax, uint32); RCT2_GLOBAL(0x009E3CDC, uint32) = eax; - if (!(image_id & 0xE0000000)){ - if (!(image_id & (1<<31))) + + if ((image_id & (1 << 31)) && (image_id & (1 << 29))){ + eax = image_id; + RCT2_GLOBAL(0x9E3CDC, uint32) = 0; + eax >>= 19; + eax &= 0x1f; + eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); + eax <<= 4; + eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); + ebp = *((uint32*)eax + 0xF3); + esi = *((uint32*)eax + 0xF7); + RCT2_GLOBAL(0x9ABEFF, uint32) = ebp; + RCT2_GLOBAL(0x9ABF03, uint32) = esi; + ebp = *((uint32*)eax + 0xFB); + eax = ebx;//0x67a310 + + RCT2_GLOBAL(0x9ABF07, uint32) = ebp; + eax >>= 24; + eax &= 0x1f; + eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); + eax <<= 4; + eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); + ebp = *((uint32*)eax + 0xF3); + esi = *((uint32*)eax + 0xF7); + RCT2_GLOBAL(0x9ABED6, uint32) = ebp; + RCT2_GLOBAL(0x9ABEDA, uint32) = esi; + ebp = *((uint32*)eax + 0xFB); + + RCT2_GLOBAL(0x9ABDA4, uint32) = 0x009ABE0C; + RCT2_GLOBAL(0x9ABEDE, uint32) = ebp; + } else if ((image_id & (1 << 31))){ + //0x67a361 + } else if ((image_id & (1 << 30))){ + //0x67a445 + } + //0x67A46E + ebx &= 0x7FFFF; + ebx <<= 4; + ebx += RCT2_ADDRESS_G1_ELEMENTS; + if (dpi->pad_0E >= 1){ + if (dpi->pad_0E == 1){ + //long jump into 0x67bd81 + } + if (dpi->pad_0E >= 3){ + //long jump into 0x67DADA + } + //long jump into 0x67FAAE + return; + } + eax = *((uint32*)ebx + 8); + ebp = *((uint32*)ebx + 12); + RCT2_GLOBAL(0x9E3D08, uint32) = *((uint32*)ebx); + RCT2_GLOBAL(0x9E3D0C, uint32) = *((uint32*)ebx + 4); + RCT2_GLOBAL(0x9E3D10, uint32) = *((uint32*)ebx + 8); + RCT2_GLOBAL(0x9E3D14, uint32) = *((uint32*)ebx + 12); + if (RCT2_GLOBAL(0x9E3D14, uint32) & (1 << 2)){ + sub_0x67A934(eax, ebp, ebx, esi, dpi, x, y); + //long jump into 0x67A934 + return; + } + ebp = dpi; + esi = RCT2_GLOBAL(0x9E3D08, uint32); + RCT2_GLOBAL(0x9E3CE0, uint32) = 0; + edi = *((uint32*)dpi); + edx = edx & 0xFFFF + RCT2_GLOBAL(0x9E3D12, uint16); + eax = eax & 0xFFFF + RCT2_GLOBAL(0x9E3D0E, uint16); + RCT2_GLOBAL(0x9ABDAC, uint16) = eax; + edx -= dpi->y; + if (edx < 0){ + RCT2_GLOBAL(0x9ABDAC, uint16)+= edx; + if (RCT2_GLOBAL(0x9ABDAC, uint16) <= 0){ + //jump 0x67A607 + return; + } + edx = -edx; + eax = RCT2_GLOBAL(0x9E3D0C, uint16); + eax *= edx; + edx = 0; + esi += eax; + RCT2_GLOBAL(0x9E3CE0, uint32) += eax; + } else { + ebx = edx; + eax = dpi->width; + + eax += dpi->pitch; + eax *= edx; + edx = ebx; + edi += eax; + } + edx += RCT2_GLOBAL(0x9ABDAC, uint16); + if (edx > dpi->height){ + edx -= dpi->height; + if (RCT2_GLOBAL(0x9ABDAC, uint32) > edx) { - if (!(image_id & (1<<29))){ - eax = image_id; - RCT2_GLOBAL(0x9E3CDC, uint32) = 0; - eax >>= 13; - eax &= 0x1f; - eax = RCT2_GLOBAL(eax * 4 + 0x91FCBC, uint32); - eax <<= 4; - eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); - ebp = *((uint32*)eax + 0xF3); - esi = *((uint32*)eax + 0xF7); - RCT2_GLOBAL(0x9ABEFF, uint32) = ebp; - RCT2_GLOBAL(0x9ABF03, uint32) = esi; - ebp = *((uint32*)eax + 0xFB); - eax = ebx;//0x67a310 - }//0x67a361 - }//0x67a445 - }//0x67a46e + RCT2_GLOBAL(0x9ABDAC, uint32) -= edx; + return;//jump to 0x67A607 + } + RCT2_GLOBAL(0x9ABDAC, uint32) -= edx; + } + else{ + edx -= dpi->height; + } + eax = RCT2_GLOBAL(0x9E3D0C, uint16); + RCT2_GLOBAL(0x9ABDA8, uint16) = eax; + ebx = dpi->width; + eax = -eax; + eax += ebx; + eax += dpi->pitch; + RCT2_GLOBAL(0x9ABDAE, uint16) = 0; + RCT2_GLOBAL(0x9ABDB0, uint16) = eax; + ecx += RCT2_GLOBAL(0x9E3D10, uint16); + if (ecx > dpi->x){ + ecx -= dpi->x; + if (RCT2_GLOBAL(0x9ABDA8, uint16) > ecx ){//missing jz 0x67a596 + RCT2_GLOBAL(0x9ABDA8, uint16) += ecx; + return; + } + RCT2_GLOBAL(0x9ABDA8, uint16) += ecx; + ecx -= RCT2_GLOBAL(0x9ABDAE, uint16); + esi -= ecx; + RCT2_GLOBAL(0x9E3CE0, uint32) -= ecx; + RCT2_GLOBAL(0x9ABDB0, uint16) -= ecx; + ecx = 0; + } + else{ + ecx -= dpi->x; + } + edi += ecx; + ecx += RCT2_GLOBAL(0x9ABDA8, uint16); + if (ecx > dpi->width){ + ecx -= dpi->width; + if (RCT2_GLOBAL(0x9ABDA8, uint16) > ecx){ + RCT2_GLOBAL(0x9ABDA8, uint16) -= ecx; + return; + } + RCT2_GLOBAL(0x9ABDA8, uint16) -= ecx; + RCT2_GLOBAL(0x9ABDAE, uint16) += ecx; + RCT2_GLOBAL(0x9ABDB0, uint16) += ecx; + } + else{ + ecx -= dpi->width; + } + if (!(RCT2_GLOBAL(0x9E3D14, uint16) & 0x02)){ + eax = RCT2_GLOBAL(0x9ABDAC, uint8); + edx = RCT2_GLOBAL(0x9ABDAE, uint16); + ebp = RCT2_GLOBAL(0x9ABDB0, uint16); + ebx = RCT2_GLOBAL(0xEDF81C, uint32); + RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); + return; + } + //0x67A60A + } /** From 1086c4e5247a376ee8b9f10cad816c2e58f9ac80 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sat, 10 May 2014 07:14:12 +0100 Subject: [PATCH 04/99] added notes to help find bug --- src/gfx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gfx.c b/src/gfx.c index bcfce787f5..de6bd2f664 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -149,6 +149,7 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri * rct2: 0x67A934 */ void sub_0x67A934(int eax, int ebp, int ebx, int esi, rct_drawpixelinfo *dpi, int x, int y){ + //eax = 3000A, ecx = 9C, edx = 152, ebx = A46798, esp = CFCC8, ebp = DC10005, esi = 0, edi = 9DEA74 int ecx = x, edx = y, edi = dpi; ebp = dpi; esi = RCT2_GLOBAL(0x9E3D08, uint32); @@ -205,6 +206,8 @@ void sub_0x67A934(int eax, int ebp, int ebx, int esi, rct_drawpixelinfo *dpi, in eax += dpi->pitch; RCT2_GLOBAL(0x9ABDB0, uint16) = eax; //ebx esi edi + char* FindThis = "FINDTHISSTRING"; + //eax 280,ecx FEFC,edx FFFF,ebx A40003,esp CFCC4,ebp 9DEA74,esi 3E1DF13,edi 322076 RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); } @@ -217,6 +220,7 @@ void sub_0x67A934(int eax, int ebp, int ebx, int esi, rct_drawpixelinfo *dpi, in */ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) { + char* FindMe = "FINDTHISOTHERSTRING"; //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); //return; From 601305a4e3651d84b78620daefe6c87be9ee0dda Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sat, 10 May 2014 10:12:48 +0100 Subject: [PATCH 05/99] Still searching for bug. Must be some external memory not set --- src/gfx.c | 141 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 90 insertions(+), 51 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index de6bd2f664..2199fb6fe1 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -148,67 +148,105 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri /* * rct2: 0x67A934 */ -void sub_0x67A934(int eax, int ebp, int ebx, int esi, rct_drawpixelinfo *dpi, int x, int y){ - //eax = 3000A, ecx = 9C, edx = 152, ebx = A46798, esp = CFCC8, ebp = DC10005, esi = 0, edi = 9DEA74 - int ecx = x, edx = y, edi = dpi; - ebp = dpi; - esi = RCT2_GLOBAL(0x9E3D08, uint32); - edi = *((uint32*)dpi); - edx += RCT2_GLOBAL(0x9E3D12, uint16); - eax = RCT2_GLOBAL(0x9E3D0E, uint16); +void sub_0x67A934(int _eax, int _ebp, int _ebx, int _esi, rct_drawpixelinfo *dpi, int x, int y){ + //_eax = 3000A, _ecx = 9C, _edx = 152, _ebx = A46798, esp = CFCC8, ebp = DC10005, _esi = 0, _edi = 9DEA74 + int _ecx = x, _edx = y, _edi = dpi; + sint16 dx = y, ax = 0, bx = 0, cx = x; + _ebp = dpi; + _esi = RCT2_GLOBAL(0x9E3D08, uint32); + _edi = *((uint32*)dpi);//2A18EC + dx += RCT2_GLOBAL(0x9E3D12, uint16); + ax = RCT2_GLOBAL(0x9E3D0E, uint16); RCT2_GLOBAL(0xEDF808, uint32) = 0; - RCT2_GLOBAL(0x9ABDAC, uint16) = eax; - if (edx > dpi->y) + RCT2_GLOBAL(0x9ABDAC, uint16) = ax; + dx -= dpi->y; + if (dx < 0) { - edx -= dpi->y; - RCT2_GLOBAL(0x9ABDAC, uint16) += edx; + RCT2_GLOBAL(0x9ABDAC, uint16) += dx; if (RCT2_GLOBAL(0x9ABDAC, uint16) <= 0)return; - RCT2_GLOBAL(0xEDF808, uint16) -= edx; - edx = 0; + RCT2_GLOBAL(0xEDF808, uint16) -= dx; + _edx = 0; + dx = 0; } else{ - edx -= dpi->y; - eax = dpi->width; - ebx = edx; - eax += dpi->pitch; - eax *= edx; - edx = ebx; - edi += eax; + ax = dpi->width; + bx = dx; + ax += dpi->pitch; + _edx = dx; + _eax = ax; + _eax *= _edx; + _edx = 0; + ax = _eax; + dx = bx; + _edi += _eax; } - edx += RCT2_GLOBAL(0x9ABDAC, uint16); - edx -= dpi->height; - if (edx > 0){ - RCT2_GLOBAL(0x9ABDAC, uint16) -= edx; + dx += RCT2_GLOBAL(0x9ABDAC, uint16); + dx -= dpi->height; + if (dx > 0){ + RCT2_GLOBAL(0x9ABDAC, uint16) -= dx; if (RCT2_GLOBAL(0x9ABDAC, uint16) <= 0)return; } - eax = RCT2_GLOBAL(0x9E3D0C, uint16); + ax = RCT2_GLOBAL(0x9E3D0C, uint16); RCT2_GLOBAL(0xEDF80C, uint32) = 0; - ecx += RCT2_GLOBAL(0x9E3D10, uint16); + cx += RCT2_GLOBAL(0x9E3D10, uint16); - RCT2_GLOBAL(0x9ABDA8, uint16) = eax; - ecx -= dpi->x; - if (ecx < 0){ - RCT2_GLOBAL(0x9ABDA8, uint16) += ecx; + RCT2_GLOBAL(0x9ABDA8, uint16) = ax; + cx -= dpi->x; + if (cx < 0){ + RCT2_GLOBAL(0x9ABDA8, uint16) += cx; if (RCT2_GLOBAL(0x9ABDA8, uint16) <= 0)return; - RCT2_GLOBAL(0xEDF80C, uint16) -= ecx; - ecx = 0; + RCT2_GLOBAL(0xEDF80C, uint16) -= cx; + _ecx = 0; + cx = 0; } else{ - edi += ecx; + _ecx = cx; + _edi += _ecx; } - ecx += RCT2_GLOBAL(0x9ABDA8, uint16); - ecx -= dpi->width; - if (ecx > 0){ - RCT2_GLOBAL(0x9ABDA8, uint16) -= ecx; + cx += RCT2_GLOBAL(0x9ABDA8, uint16); + cx -= dpi->width; + if (cx > 0){ + RCT2_GLOBAL(0x9ABDA8, uint16) -= cx; if (RCT2_GLOBAL(0x9ABDA8, uint16) <= 0)return; } - eax = dpi->width; - eax += dpi->pitch; - RCT2_GLOBAL(0x9ABDB0, uint16) = eax; - //ebx esi edi + ax = dpi->width; + ax += dpi->pitch; + RCT2_GLOBAL(0x9ABDB0, uint16) = ax; + _eax = (_eax & 0xFFFF0000) + ax; + _ebx = (_ebx & 0xFFFF0000) + bx; + _ecx = (_ecx & 0xFFFF0000) + cx; + _edx = (_edx & 0xFFFF0000) + dx; + + //_ebx _esi _edi char* FindThis = "FINDTHISSTRING"; - //eax 280,ecx FEFC,edx FFFF,ebx A40003,esp CFCC4,ebp 9DEA74,esi 3E1DF13,edi 322076 - RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); + //_eax 280,_ecx FEFC,_edx FFFF,_ebx A40003,esp CFCC4,ebp 9DEA74,_esi 3E1DF13,_edi 322076 + _asm{ + push eax + push ebx + push ecx + push edx + push edi + push esi + push ebp + push 0x67AA18 + push dpi + mov eax, _eax + mov ebx, _ebx + mov ecx, _ecx + mov edx, _edx + mov esi, _esi + mov edi, _edi + mov ebp, _ebp + call [esp+4] + add esp,8 + pop ebp + pop esi + pop edi + pop edx + pop ecx + pop ebx + pop eax + } } /** @@ -229,7 +267,8 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax >>= 26; RCT2_GLOBAL(0x00EDF81C, uint32) = image_id & 0xE0000000; eax &= 0x7; - eax = RCT2_GLOBAL(0x009E3CE4 + 4 * eax, uint32); + + eax = RCT2_GLOBAL(0x009E3CE4 + eax*4, uint32);//3D91F13 3F71F13 * 2 RCT2_GLOBAL(0x009E3CDC, uint32) = eax; if ((image_id & (1 << 31)) && (image_id & (1 << 29))){ @@ -280,12 +319,12 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) //long jump into 0x67FAAE return; } - eax = *((uint32*)ebx + 8); - ebp = *((uint32*)ebx + 12); - RCT2_GLOBAL(0x9E3D08, uint32) = *((uint32*)ebx); - RCT2_GLOBAL(0x9E3D0C, uint32) = *((uint32*)ebx + 4); - RCT2_GLOBAL(0x9E3D10, uint32) = *((uint32*)ebx + 8); - RCT2_GLOBAL(0x9E3D14, uint32) = *((uint32*)ebx + 12); + eax = *((uint32*)ebx + 2); + ebp = *((uint32*)ebx + 3); + RCT2_GLOBAL(0x9E3D08, uint32) = *((uint32*)ebx);//3F8DF13 3D8DF13 + RCT2_GLOBAL(0x9E3D0C, uint32) = *((uint32*)ebx + 1);//4E003A 4E003A + RCT2_GLOBAL(0x9E3D10, uint32) = *((uint32*)ebx + 2);//3000A * 2 + RCT2_GLOBAL(0x9E3D14, uint32) = *((uint32*)ebx + 3);//DC10005 *2 if (RCT2_GLOBAL(0x9E3D14, uint32) & (1 << 2)){ sub_0x67A934(eax, ebp, ebx, esi, dpi, x, y); //long jump into 0x67A934 From 16ed98348a1ee20c7e0728b9e2f158b9ba5cbe90 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sat, 10 May 2014 10:16:23 +0100 Subject: [PATCH 06/99] Found bug due to signness on global var --- src/gfx.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 2199fb6fe1..994536e0a5 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -162,9 +162,9 @@ void sub_0x67A934(int _eax, int _ebp, int _ebx, int _esi, rct_drawpixelinfo *dpi dx -= dpi->y; if (dx < 0) { - RCT2_GLOBAL(0x9ABDAC, uint16) += dx; - if (RCT2_GLOBAL(0x9ABDAC, uint16) <= 0)return; - RCT2_GLOBAL(0xEDF808, uint16) -= dx; + RCT2_GLOBAL(0x9ABDAC, sint16) += dx; + if (RCT2_GLOBAL(0x9ABDAC, sint16) <= 0)return; + RCT2_GLOBAL(0xEDF808, sint16) -= dx; _edx = 0; dx = 0; } @@ -180,22 +180,22 @@ void sub_0x67A934(int _eax, int _ebp, int _ebx, int _esi, rct_drawpixelinfo *dpi dx = bx; _edi += _eax; } - dx += RCT2_GLOBAL(0x9ABDAC, uint16); + dx += RCT2_GLOBAL(0x9ABDAC, sint16); dx -= dpi->height; if (dx > 0){ - RCT2_GLOBAL(0x9ABDAC, uint16) -= dx; - if (RCT2_GLOBAL(0x9ABDAC, uint16) <= 0)return; + RCT2_GLOBAL(0x9ABDAC, sint16) -= dx; + if (RCT2_GLOBAL(0x9ABDAC, sint16) <= 0)return; } ax = RCT2_GLOBAL(0x9E3D0C, uint16); RCT2_GLOBAL(0xEDF80C, uint32) = 0; cx += RCT2_GLOBAL(0x9E3D10, uint16); - RCT2_GLOBAL(0x9ABDA8, uint16) = ax; + RCT2_GLOBAL(0x9ABDA8, sint16) = ax; cx -= dpi->x; if (cx < 0){ - RCT2_GLOBAL(0x9ABDA8, uint16) += cx; - if (RCT2_GLOBAL(0x9ABDA8, uint16) <= 0)return; - RCT2_GLOBAL(0xEDF80C, uint16) -= cx; + RCT2_GLOBAL(0x9ABDA8, sint16) += cx; + if (RCT2_GLOBAL(0x9ABDA8, sint16) <= 0)return; + RCT2_GLOBAL(0xEDF80C, sint16) -= cx; _ecx = 0; cx = 0; } @@ -203,11 +203,11 @@ void sub_0x67A934(int _eax, int _ebp, int _ebx, int _esi, rct_drawpixelinfo *dpi _ecx = cx; _edi += _ecx; } - cx += RCT2_GLOBAL(0x9ABDA8, uint16); + cx += RCT2_GLOBAL(0x9ABDA8, sint16); cx -= dpi->width; if (cx > 0){ - RCT2_GLOBAL(0x9ABDA8, uint16) -= cx; - if (RCT2_GLOBAL(0x9ABDA8, uint16) <= 0)return; + RCT2_GLOBAL(0x9ABDA8, sint16) -= cx; + if (RCT2_GLOBAL(0x9ABDA8, sint16) <= 0)return; } ax = dpi->width; ax += dpi->pitch; From 26f4b35e613d8fb2f211a0165a9b4208088e29a9 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sat, 10 May 2014 12:26:19 +0100 Subject: [PATCH 07/99] Cleaned up code so that it makes more sense. --- src/addresses.h | 18 ++++++ src/gfx.c | 164 +++++++++++++++++++----------------------------- 2 files changed, 81 insertions(+), 101 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 2ec02b5edd..961bb4e1a1 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -277,6 +277,24 @@ static void RCT2_CALLPROC_X(int address, int _eax, int _ebx, int _ecx, int _edx, } } +static void RCT2_CALLPROC_X_EBPSAFE(int address, int _eax, int _ebx, int _ecx, int _edx, int _esi, int _edi, int _ebp) +{ + __asm { + push ebp + push address + mov eax, _eax + mov ebx, _ebx + mov ecx, _ecx + mov edx, _edx + mov esi, _esi + mov edi, _edi + mov ebp, _ebp + call[esp] + add esp, 4 + pop ebp + } +} + static void RCT2_CALLFUNC_X(int address, int *_eax, int *_ebx, int *_ecx, int *_edx, int *_esi, int *_edi, int *_ebp) { __asm { diff --git a/src/gfx.c b/src/gfx.c index 994536e0a5..c114018af6 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -145,108 +145,69 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri RCT2_CALLPROC_X(0x006E6F81, left, right, top, bottom, _si, dpi, colour); } +#define RCT2_Y_RELATED_GLOBAL_1 0x9E3D12 //uint16 +#define RCT2_Y_RELATED_GLOBAL_2 0x9ABDAC //sint16 + /* -* rct2: 0x67A934 +* rct2: 0x67A934 title screen bitmaps on buttons +* This function readies all the global vars for copying the sprite data onto the screen +* I think its only used for bitmaps onto buttons but i am not sure. */ -void sub_0x67A934(int _eax, int _ebp, int _ebx, int _esi, rct_drawpixelinfo *dpi, int x, int y){ +void sub_0x67A934(rct_drawpixelinfo *dpi, int x, int y){ //_eax = 3000A, _ecx = 9C, _edx = 152, _ebx = A46798, esp = CFCC8, ebp = DC10005, _esi = 0, _edi = 9DEA74 - int _ecx = x, _edx = y, _edi = dpi; - sint16 dx = y, ax = 0, bx = 0, cx = x; - _ebp = dpi; - _esi = RCT2_GLOBAL(0x9E3D08, uint32); - _edi = *((uint32*)dpi);//2A18EC - dx += RCT2_GLOBAL(0x9E3D12, uint16); - ax = RCT2_GLOBAL(0x9E3D0E, uint16); + int _edi = dpi, _esi; + sint16 translated_x = x, translated_y = y; + char* bits_pointer; + bits_pointer = dpi->bits; + + translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16); RCT2_GLOBAL(0xEDF808, uint32) = 0; - RCT2_GLOBAL(0x9ABDAC, uint16) = ax; - dx -= dpi->y; - if (dx < 0) + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, uint16) = RCT2_GLOBAL(0x9E3D0E, uint16); + translated_y -= dpi->y; + if (translated_y < 0) { - RCT2_GLOBAL(0x9ABDAC, sint16) += dx; - if (RCT2_GLOBAL(0x9ABDAC, sint16) <= 0)return; - RCT2_GLOBAL(0xEDF808, sint16) -= dx; - _edx = 0; - dx = 0; + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) += translated_y; + if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) <= 0)return; + RCT2_GLOBAL(0xEDF808, sint16) -= translated_y; + translated_y = 0; } else{ - ax = dpi->width; - bx = dx; - ax += dpi->pitch; - _edx = dx; - _eax = ax; - _eax *= _edx; - _edx = 0; - ax = _eax; - dx = bx; - _edi += _eax; + bits_pointer += (dpi->width + dpi->pitch)*translated_y; } - dx += RCT2_GLOBAL(0x9ABDAC, sint16); - dx -= dpi->height; - if (dx > 0){ - RCT2_GLOBAL(0x9ABDAC, sint16) -= dx; - if (RCT2_GLOBAL(0x9ABDAC, sint16) <= 0)return; + + translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16); + translated_y -= dpi->height; + if (translated_y > 0){ + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) -= translated_y; + if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) <= 0)return; } - ax = RCT2_GLOBAL(0x9E3D0C, uint16); + RCT2_GLOBAL(0xEDF80C, uint32) = 0; - cx += RCT2_GLOBAL(0x9E3D10, uint16); + translated_x += RCT2_GLOBAL(0x9E3D10, uint16); - RCT2_GLOBAL(0x9ABDA8, sint16) = ax; - cx -= dpi->x; - if (cx < 0){ - RCT2_GLOBAL(0x9ABDA8, sint16) += cx; + RCT2_GLOBAL(0x9ABDA8, sint16) = RCT2_GLOBAL(0x9E3D0C, uint16); + translated_x -= dpi->x; + if (translated_x < 0){ + RCT2_GLOBAL(0x9ABDA8, sint16) += translated_x; if (RCT2_GLOBAL(0x9ABDA8, sint16) <= 0)return; - RCT2_GLOBAL(0xEDF80C, sint16) -= cx; - _ecx = 0; - cx = 0; + RCT2_GLOBAL(0xEDF80C, sint16) -= translated_x; + translated_x = 0; } else{ - _ecx = cx; - _edi += _ecx; + bits_pointer += translated_x; } - cx += RCT2_GLOBAL(0x9ABDA8, sint16); - cx -= dpi->width; - if (cx > 0){ - RCT2_GLOBAL(0x9ABDA8, sint16) -= cx; + translated_x += RCT2_GLOBAL(0x9ABDA8, sint16); + translated_x -= dpi->width; + if (translated_x > 0){ + RCT2_GLOBAL(0x9ABDA8, sint16) -= translated_x; if (RCT2_GLOBAL(0x9ABDA8, sint16) <= 0)return; } - ax = dpi->width; - ax += dpi->pitch; - RCT2_GLOBAL(0x9ABDB0, uint16) = ax; - _eax = (_eax & 0xFFFF0000) + ax; - _ebx = (_ebx & 0xFFFF0000) + bx; - _ecx = (_ecx & 0xFFFF0000) + cx; - _edx = (_edx & 0xFFFF0000) + dx; - //_ebx _esi _edi - char* FindThis = "FINDTHISSTRING"; - //_eax 280,_ecx FEFC,_edx FFFF,_ebx A40003,esp CFCC4,ebp 9DEA74,_esi 3E1DF13,_edi 322076 - _asm{ - push eax - push ebx - push ecx - push edx - push edi - push esi - push ebp - push 0x67AA18 - push dpi - mov eax, _eax - mov ebx, _ebx - mov ecx, _ecx - mov edx, _edx - mov esi, _esi - mov edi, _edi - mov ebp, _ebp - call [esp+4] - add esp,8 - pop ebp - pop esi - pop edi - pop edx - pop ecx - pop ebx - pop eax - } + RCT2_GLOBAL(0x9ABDB0, uint16) = dpi->width + dpi->pitch; + + // I dont think it uses ecx, edx but just in case + //This is a G1 Loaded sprite address 0x9E3D08 + RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, translated_x, translated_y, RCT2_GLOBAL(0x9E3D08, uint32), bits_pointer, dpi); } /** @@ -258,7 +219,6 @@ void sub_0x67A934(int _eax, int _ebp, int _ebx, int _esi, rct_drawpixelinfo *dpi */ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) { - char* FindMe = "FINDTHISOTHERSTRING"; //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); //return; @@ -284,7 +244,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x9ABEFF, uint32) = ebp; RCT2_GLOBAL(0x9ABF03, uint32) = esi; ebp = *((uint32*)eax + 0xFB); - eax = ebx;//0x67a310 + eax = ebx; RCT2_GLOBAL(0x9ABF07, uint32) = ebp; eax >>= 24; @@ -321,26 +281,26 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } eax = *((uint32*)ebx + 2); ebp = *((uint32*)ebx + 3); - RCT2_GLOBAL(0x9E3D08, uint32) = *((uint32*)ebx);//3F8DF13 3D8DF13 - RCT2_GLOBAL(0x9E3D0C, uint32) = *((uint32*)ebx + 1);//4E003A 4E003A - RCT2_GLOBAL(0x9E3D10, uint32) = *((uint32*)ebx + 2);//3000A * 2 - RCT2_GLOBAL(0x9E3D14, uint32) = *((uint32*)ebx + 3);//DC10005 *2 + RCT2_GLOBAL(0x9E3D08, uint32) = *((uint32*)ebx); + RCT2_GLOBAL(0x9E3D0C, uint32) = *((uint32*)ebx + 1); + RCT2_GLOBAL(0x9E3D10, uint32) = *((uint32*)ebx + 2); //Y related + RCT2_GLOBAL(0x9E3D14, uint32) = *((uint32*)ebx + 3); if (RCT2_GLOBAL(0x9E3D14, uint32) & (1 << 2)){ - sub_0x67A934(eax, ebp, ebx, esi, dpi, x, y); - //long jump into 0x67A934 + //Title screen bitmaps + sub_0x67A934(dpi, x, y); return; } ebp = dpi; esi = RCT2_GLOBAL(0x9E3D08, uint32); RCT2_GLOBAL(0x9E3CE0, uint32) = 0; edi = *((uint32*)dpi); - edx = edx & 0xFFFF + RCT2_GLOBAL(0x9E3D12, uint16); + edx = edx & 0xFFFF + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16); eax = eax & 0xFFFF + RCT2_GLOBAL(0x9E3D0E, uint16); - RCT2_GLOBAL(0x9ABDAC, uint16) = eax; + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) = eax; edx -= dpi->y; if (edx < 0){ - RCT2_GLOBAL(0x9ABDAC, uint16)+= edx; - if (RCT2_GLOBAL(0x9ABDAC, uint16) <= 0){ + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) += edx; + if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) <= 0){ //jump 0x67A607 return; } @@ -359,15 +319,16 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) edx = ebx; edi += eax; } - edx += RCT2_GLOBAL(0x9ABDAC, uint16); + edx += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16); if (edx > dpi->height){ edx -= dpi->height; - if (RCT2_GLOBAL(0x9ABDAC, uint32) > edx) + //RCT2_Y_RELATED_GLOBAL_2 is normaly 16 bit signed??? + if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint32) > edx) { - RCT2_GLOBAL(0x9ABDAC, uint32) -= edx; + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, uint32) -= edx; return;//jump to 0x67A607 } - RCT2_GLOBAL(0x9ABDAC, uint32) -= edx; + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, uint32) -= edx; } else{ edx -= dpi->height; @@ -413,7 +374,8 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ecx -= dpi->width; } if (!(RCT2_GLOBAL(0x9E3D14, uint16) & 0x02)){ - eax = RCT2_GLOBAL(0x9ABDAC, uint8); + //RCT2_Y_RELATED_GLOBAL_2 is normally 16 bit signed??? + eax = RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, uint8); edx = RCT2_GLOBAL(0x9ABDAE, uint16); ebp = RCT2_GLOBAL(0x9ABDB0, uint16); ebx = RCT2_GLOBAL(0xEDF81C, uint32); From 6d97593093f0e8a2ee6f32a5db0506ba8046052e Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 11 May 2014 10:14:38 +0100 Subject: [PATCH 08/99] Bug in main draw_sprite func for now skipping code --- src/gfx.c | 196 +++++++++++++++++++++++++++--------------------------- src/gfx.h | 2 +- 2 files changed, 100 insertions(+), 98 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index c114018af6..8f663827f5 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -147,23 +147,24 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri #define RCT2_Y_RELATED_GLOBAL_1 0x9E3D12 //uint16 #define RCT2_Y_RELATED_GLOBAL_2 0x9ABDAC //sint16 - +#define RCT2_X_RELATED_GLOBAL_1 0x9E3D10 //uint16 +#define RCT2_X_RELATED_GLOBAL_2 0x9ABDA8 //sint16 /* * rct2: 0x67A934 title screen bitmaps on buttons * This function readies all the global vars for copying the sprite data onto the screen * I think its only used for bitmaps onto buttons but i am not sure. */ void sub_0x67A934(rct_drawpixelinfo *dpi, int x, int y){ - //_eax = 3000A, _ecx = 9C, _edx = 152, _ebx = A46798, esp = CFCC8, ebp = DC10005, _esi = 0, _edi = 9DEA74 + int _edi = dpi, _esi; sint16 translated_x = x, translated_y = y; char* bits_pointer; bits_pointer = dpi->bits; - translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16); + translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16) - dpi->y; RCT2_GLOBAL(0xEDF808, uint32) = 0; - RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, uint16) = RCT2_GLOBAL(0x9E3D0E, uint16); - translated_y -= dpi->y; + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) = RCT2_GLOBAL(0x9E3D0E, sint16); + if (translated_y < 0) { RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) += translated_y; @@ -175,38 +176,35 @@ void sub_0x67A934(rct_drawpixelinfo *dpi, int x, int y){ bits_pointer += (dpi->width + dpi->pitch)*translated_y; } - translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16); - translated_y -= dpi->height; + translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) - dpi->height; if (translated_y > 0){ RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) -= translated_y; if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) <= 0)return; } RCT2_GLOBAL(0xEDF80C, uint32) = 0; - translated_x += RCT2_GLOBAL(0x9E3D10, uint16); + translated_x += RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_1, uint16) - dpi->x; - RCT2_GLOBAL(0x9ABDA8, sint16) = RCT2_GLOBAL(0x9E3D0C, uint16); - translated_x -= dpi->x; + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) = RCT2_GLOBAL(0x9E3D0C, sint16); if (translated_x < 0){ - RCT2_GLOBAL(0x9ABDA8, sint16) += translated_x; - if (RCT2_GLOBAL(0x9ABDA8, sint16) <= 0)return; + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) += translated_x; + if (RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) <= 0)return; RCT2_GLOBAL(0xEDF80C, sint16) -= translated_x; translated_x = 0; } else{ bits_pointer += translated_x; } - translated_x += RCT2_GLOBAL(0x9ABDA8, sint16); + translated_x += RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16); translated_x -= dpi->width; if (translated_x > 0){ - RCT2_GLOBAL(0x9ABDA8, sint16) -= translated_x; - if (RCT2_GLOBAL(0x9ABDA8, sint16) <= 0)return; + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) -= translated_x; + if (RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) <= 0)return; } RCT2_GLOBAL(0x9ABDB0, uint16) = dpi->width + dpi->pitch; // I dont think it uses ecx, edx but just in case - //This is a G1 Loaded sprite address 0x9E3D08 RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, translated_x, translated_y, RCT2_GLOBAL(0x9E3D08, uint32), bits_pointer, dpi); } @@ -227,11 +225,11 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax >>= 26; RCT2_GLOBAL(0x00EDF81C, uint32) = image_id & 0xE0000000; eax &= 0x7; - - eax = RCT2_GLOBAL(0x009E3CE4 + eax*4, uint32);//3D91F13 3F71F13 * 2 + eax = RCT2_GLOBAL(0x009E3CE4 + eax*4, uint32); RCT2_GLOBAL(0x009E3CDC, uint32) = eax; if ((image_id & (1 << 31)) && (image_id & (1 << 29))){ + /* eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; eax >>= 19; @@ -259,130 +257,134 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebp = *((uint32*)eax + 0xFB); RCT2_GLOBAL(0x9ABDA4, uint32) = 0x009ABE0C; - RCT2_GLOBAL(0x9ABEDE, uint32) = ebp; + RCT2_GLOBAL(0x9ABEDE, uint32) = ebp;*/ + return; } else if ((image_id & (1 << 31))){ - //0x67a361 + return; + //jump into 0x67a361 } else if ((image_id & (1 << 30))){ - //0x67a445 + return; + //jump into 0x67a445 } - //0x67A46E + ebx &= 0x7FFFF; ebx <<= 4; ebx += RCT2_ADDRESS_G1_ELEMENTS; if (dpi->pad_0E >= 1){ if (dpi->pad_0E == 1){ - //long jump into 0x67bd81 + return; + //jump into 0x67bd81 } if (dpi->pad_0E >= 3){ - //long jump into 0x67DADA + return;//jump into 0x67FAAE } - //long jump into 0x67FAAE + //jump into 0x67DADA return; } eax = *((uint32*)ebx + 2); ebp = *((uint32*)ebx + 3); - RCT2_GLOBAL(0x9E3D08, uint32) = *((uint32*)ebx); + RCT2_GLOBAL(0x9E3D08, uint32) = *((uint32*)ebx); //offset to g1 bits? RCT2_GLOBAL(0x9E3D0C, uint32) = *((uint32*)ebx + 1); - RCT2_GLOBAL(0x9E3D10, uint32) = *((uint32*)ebx + 2); //Y related + RCT2_GLOBAL(0x9E3D10, uint32) = *((uint32*)ebx + 2); //X-Y related unsigned? sets RCT2_X_RELATED_GLOBAL_1 and Y RCT2_GLOBAL(0x9E3D14, uint32) = *((uint32*)ebx + 3); if (RCT2_GLOBAL(0x9E3D14, uint32) & (1 << 2)){ //Title screen bitmaps sub_0x67A934(dpi, x, y); return; } + + + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + return; + //There is a mistake in the code below this point calling the above to skip it. + + //dpi on stack + int translated_x, translated_y; + char* bits_pointer; + ebp = dpi; esi = RCT2_GLOBAL(0x9E3D08, uint32); RCT2_GLOBAL(0x9E3CE0, uint32) = 0; - edi = *((uint32*)dpi); - edx = edx & 0xFFFF + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16); - eax = eax & 0xFFFF + RCT2_GLOBAL(0x9E3D0E, uint16); - RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) = eax; - edx -= dpi->y; - if (edx < 0){ - RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) += edx; + bits_pointer = dpi->bits; + + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) = RCT2_GLOBAL(0x9E3D0E, sint16); + + translated_y = y + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16) - dpi->y; + + + if (translated_y < 0){ + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) += translated_y; if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) <= 0){ - //jump 0x67A607 return; } - edx = -edx; - eax = RCT2_GLOBAL(0x9E3D0C, uint16); - eax *= edx; - edx = 0; - esi += eax; - RCT2_GLOBAL(0x9E3CE0, uint32) += eax; + translated_y = -translated_y; + esi += translated_y * RCT2_GLOBAL(0x9E3D0C, sint16); + RCT2_GLOBAL(0x9E3CE0, sint32) += translated_y * RCT2_GLOBAL(0x9E3D0C, sint16); + translated_y = 0; } else { - ebx = edx; - eax = dpi->width; - - eax += dpi->pitch; - eax *= edx; - edx = ebx; - edi += eax; + eax = (dpi->width + dpi->pitch) * translated_y; + bits_pointer += eax; } - edx += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16); - if (edx > dpi->height){ - edx -= dpi->height; - //RCT2_Y_RELATED_GLOBAL_2 is normaly 16 bit signed??? - if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint32) > edx) + + translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) - dpi->height;; + + if (translated_y > 0){ + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) -= translated_y; + if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) <=0) { - RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, uint32) -= edx; - return;//jump to 0x67A607 + return; } - RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, uint32) -= edx; } - else{ - edx -= dpi->height; - } - eax = RCT2_GLOBAL(0x9E3D0C, uint16); - RCT2_GLOBAL(0x9ABDA8, uint16) = eax; - ebx = dpi->width; - eax = -eax; - eax += ebx; - eax += dpi->pitch; + + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) = RCT2_GLOBAL(0x9E3D0C, sint16); + eax = dpi->width + dpi->pitch - RCT2_GLOBAL(0x9E3D0C, sint16); + RCT2_GLOBAL(0x9ABDAE, uint16) = 0; - RCT2_GLOBAL(0x9ABDB0, uint16) = eax; - ecx += RCT2_GLOBAL(0x9E3D10, uint16); - if (ecx > dpi->x){ - ecx -= dpi->x; - if (RCT2_GLOBAL(0x9ABDA8, uint16) > ecx ){//missing jz 0x67a596 - RCT2_GLOBAL(0x9ABDA8, uint16) += ecx; + RCT2_GLOBAL(0x9ABDB0, sint16) = dpi->width + dpi->pitch - RCT2_GLOBAL(0x9E3D0C, sint16); + translated_x = x + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_1, uint16) - dpi->x; + + if (translated_x < 0){ + + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) += translated_x; + if (RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) <= 0){ return; } - RCT2_GLOBAL(0x9ABDA8, uint16) += ecx; - ecx -= RCT2_GLOBAL(0x9ABDAE, uint16); - esi -= ecx; - RCT2_GLOBAL(0x9E3CE0, uint32) -= ecx; - RCT2_GLOBAL(0x9ABDB0, uint16) -= ecx; - ecx = 0; + + translated_x -= RCT2_GLOBAL(0x9ABDAE, sint16); + esi -= translated_x; + RCT2_GLOBAL(0x9E3CE0, sint32) -= translated_x; + RCT2_GLOBAL(0x9ABDB0, sint16) -= translated_x; + translated_x = 0; } - else{ - ecx -= dpi->x; - } - edi += ecx; - ecx += RCT2_GLOBAL(0x9ABDA8, uint16); - if (ecx > dpi->width){ - ecx -= dpi->width; - if (RCT2_GLOBAL(0x9ABDA8, uint16) > ecx){ - RCT2_GLOBAL(0x9ABDA8, uint16) -= ecx; + + bits_pointer += translated_x; + translated_x += RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) - dpi->width; + + if (translated_x > 0){ + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) -= translated_x; + if (RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) <= 0){ return; } - RCT2_GLOBAL(0x9ABDA8, uint16) -= ecx; - RCT2_GLOBAL(0x9ABDAE, uint16) += ecx; - RCT2_GLOBAL(0x9ABDB0, uint16) += ecx; - } - else{ - ecx -= dpi->width; + RCT2_GLOBAL(0x9ABDAE, sint16) += translated_x; + RCT2_GLOBAL(0x9ABDB0, sint16) += translated_x; } + if (!(RCT2_GLOBAL(0x9E3D14, uint16) & 0x02)){ - //RCT2_Y_RELATED_GLOBAL_2 is normally 16 bit signed??? - eax = RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, uint8); - edx = RCT2_GLOBAL(0x9ABDAE, uint16); - ebp = RCT2_GLOBAL(0x9ABDB0, uint16); + eax = (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) & 0xFF) << 8; + edx = RCT2_GLOBAL(0x9ABDAE, sint16); + ebp = RCT2_GLOBAL(0x9ABDB0, sint16); ebx = RCT2_GLOBAL(0xEDF81C, uint32); - RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); + ecx = 0xFFFF&translated_x; + //ebx, esi, edi, ah used in 0x67a690 + //Calling is wrong + //esi or bits is most likely wrong + RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, bits_pointer, ebp); return; } //0x67A60A + esi -= RCT2_GLOBAL(0x9E3D08, sint32); + return; + } diff --git a/src/gfx.h b/src/gfx.h index 9af771d4f8..de0411b258 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -31,7 +31,7 @@ typedef struct { short width; // 0x08 short height; // 0x0A short pitch; // 0x0C note: this is actually (pitch - width) - char pad_0E; // 0x0E + uint16 pad_0E; // 0x0E char var_0F; // 0x0F } rct_drawpixelinfo; From 81f2bfed359cb87f0eeeec2eda109b21331c9c69 Mon Sep 17 00:00:00 2001 From: ddevrien Date: Sun, 11 May 2014 10:51:05 +0200 Subject: [PATCH 09/99] Implemented checkbox widget draw function --- src/widget.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/widget.c b/src/widget.c index c476beed44..c2d386e705 100644 --- a/src/widget.c +++ b/src/widget.c @@ -37,6 +37,7 @@ static void widget_text_inset(rct_drawpixelinfo *dpi, rct_window *w, int widgetI static void widget_text_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex); static void widget_groupbox_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex); static void widget_caption_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex); +static void widget_checkbox_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex); static void widget_closebox_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex); static void widget_scroll_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex); static void widget_hscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, int l, int t, int r, int b, int colour); @@ -154,6 +155,8 @@ void widget_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex) widget_scroll_draw(dpi, w, widgetIndex); break; case WWT_CHECKBOX: + widget_checkbox_draw(dpi, w, widgetIndex); + break; case WWT_24: break; case WWT_25: @@ -711,6 +714,46 @@ static void widget_closebox_draw(rct_drawpixelinfo *dpi, rct_window *w, int widg gfx_draw_string_centred_clipped(dpi, widget->image, (void*)0x013CE952, colour, l, t, widget->right - widget->left - 2); } +/** +* +* rct2: 0x006EBAD9 +*/ +static void widget_checkbox_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex) +{ + rct_widget* widget; + int l, t, b; + uint8 colour; + + // Get the widget + widget = &w->widgets[widgetIndex]; + + // Resolve the absolute ltb + l = w->x + widget->left; + t = w->y + widget->top; + b = w->y + widget->bottom; + + // Get the colour + colour = w->colours[widget->colour]; + + // checkbox + gfx_fill_rect_inset(dpi, l, t, l + 9, b - 1, colour, 0x60); + + // fill it when checkbox is pressed + if (widget_is_pressed(w, widgetIndex)) { + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224; + gfx_draw_string(dpi, (char*)0x009DED72, colour & 0x7F, l, t); + } + + // draw the text + if (widget->image == -1) + return; + + if (widget_is_disabled(w, widgetIndex)) { + colour |= 0x40; + } + gfx_draw_string_left(dpi, widget->image, (char*)0x013CE952, colour, l + 14, t); +} + /** * * rct2: 0x006EBD96 From 705af9377b19c234c2405f0d4d897647919c716e Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sun, 11 May 2014 13:06:28 +0200 Subject: [PATCH 10/99] Start decompiling gfx_fill_rect Section starting 0x00678C83 complete and works, but needs better comments/names --- src/gfx.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 166 insertions(+), 3 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 8f663827f5..cf534af2f7 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -119,14 +119,177 @@ void gfx_draw_line(rct_drawpixelinfo *dpi, int x1, int y1, int x2, int y2, int c * rct2: 0x00678AD4 * dpi (edi) * left (ax) - * top (cx) + * top (cx) ? * right (bx) - * bottom (dx) + * bottom (dx) ? * colour (ebp) */ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bottom, int colour) { - RCT2_CALLPROC_X(0x00678AD4, left, right, top, bottom, 0, dpi, colour); + + int left_, right_, top_, bottom_; + rct_drawpixelinfo* dpi_; + left_ = left; + right_ = right; + top_ = top; + bottom_ = bottom; + dpi_ = dpi; + + if ((left > right) || (top > bottom) || (dpi->x > right) || (left >= (dpi->x + dpi->width)) || + (bottom < dpi->y) || (top >= (dpi->y + dpi->height))) + return; + + colour |= RCT2_GLOBAL(0x009ABD9C, uint32); + + if (!(colour & 0x1000000)) { + if (!(colour & 0x8000000)) { + left_ = left - dpi->x; + if (left_ < 0) + left_ = 0; + + right_ = right - dpi->x; + right_++; + if (right_ > dpi->width) + right_ = dpi->width; + + right_ -= left_; + + top_ = top - dpi->y; + if (top_ < 0) + top_ = 0; + + bottom_ = bottom - dpi->y; + bottom_++; + + if (bottom_ > dpi->height) + bottom_ = dpi->height; + + bottom_ -= top_; + + if (!(colour & 0x2000000)) { + if (!(colour & 0x4000000)) { + char* edi; + edi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; + + // Take the last byte of colour and repeat it 4 times? + uint32 ax; + ax = colour & 0xffff; + ax = (ax & 0xff) << 8; + ax = ax << 8; + ax = (ax & 0xff00) >> 8; + ax = ax << 8; + ax = (ax & 0xff00) >> 8; + + int length; + length = dpi->width + dpi->pitch - right_; + + for (int dx = bottom_; dx > 0; --dx) { + uint32 ecx; + ecx = right_; + ecx = ecx/2; + if (ecx % 2 != 0) { + *edi = ax & 0xff; + edi++; + } + ecx = ecx/2; + if (ecx % 2 != 0) { + *edi = ax & 0xffff; + edi += 2; + } + memset(edi, ax, ecx); + + edi += length; + + } + return; + + } else { + // 00678B8A 00678E38 + char* esi; + esi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits;; + + int eax, ebp; + eax = colour; + ebp = dpi->width + dpi->pitch - right_; + + RCT2_GLOBAL(0x00EDF810, uint32) = ebp; + RCT2_GLOBAL(0x009ABDB2, uint16) = bottom_; + RCT2_GLOBAL(0x00EDF814, uint32) = right_; + + top_ = (top + dpi_->y) & 0xf; + right_ = (right + dpi_->x) &0xf; + + dpi_ = esi; + + esi = eax >> 0x1C; + esi = RCT2_GLOBAL(0x0097FEFC,uint32)[esi]; // or possibly uint8)[esi*4] ? + + for (; RCT2_GLOBAL(0x009ABDB2, uint16) > 0; RCT2_GLOBAL(0x009ABDB2, uint16)--) { + // push ebx + // push ecx + ebp = *(esi + top_*2); + + // mov bp, [esi+top_*2]; + int ecx; + ecx = RCT2_GLOBAL(0x00EDF814, uint32); + + for (int i = ecx; i >=0; --i) { + if (!(ebp & (1 << right_))) + dpi_->bits = left_ & 0xFF; + + right_++; + right_ = right_ & 0xF; + dpi_++; + } + // pop ecx + // pop ebx + top_++; + top_ = top_ &0xf; + dpi_ += RCT2_GLOBAL(0x00EDF810, uint32); + } + return; + } + + } else { + // 00678B7E 00678C83 + if (dpi_->pad_0E < 1) { + // Location in screen buffer? + uint8* edi = top_ * (dpi_->width + dpi_->pitch) + left_ + dpi_->bits; + + // Find colour in colour table? + uint32 eax = RCT2_ADDRESS(0x0097FCBC, uint32)[(colour & 0xFF)]; + rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[eax]); + + int length = (dpi_->width + dpi_->pitch) - right_; + + // Fill the rectangle with the colours from the colour table + for (int i = 0; i < bottom_; ++i) { + uint8 al; + al = 0; + for (int j = 0; j < right_; ++j) { + al = *edi; + *edi = *((uint8*)(&g1_element->offset[al])); + edi++; + } + edi += length; + } + } else if (dpi_->pad_0E > 1) { + // 00678C8A 00678D57 + } else if (dpi_->pad_0E == 1) { + // 00678C88 00678CEE + + } + + } + } else { + // 00678B3A 00678EC9 + + } + } else { + // 00678B2E 00678BE5 + } + + // RCT2_CALLPROC_X(0x00678AD4, left, right, top, bottom, 0, dpi, colour); } /** From 6f1421117be088eb7571b9044297aca0b10cc50c Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sun, 11 May 2014 15:56:59 +0200 Subject: [PATCH 11/99] Some tidying up. Scrollbars don't work --- src/gfx.c | 56 +++++++++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index cf534af2f7..3354d45c07 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -168,41 +168,34 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot if (!(colour & 0x2000000)) { if (!(colour & 0x4000000)) { - char* edi; + uint8* edi; edi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; - // Take the last byte of colour and repeat it 4 times? - uint32 ax; - ax = colour & 0xffff; - ax = (ax & 0xff) << 8; - ax = ax << 8; - ax = (ax & 0xff00) >> 8; - ax = ax << 8; - ax = (ax & 0xff00) >> 8; + uint8 col = colour & 0xFF; int length; length = dpi->width + dpi->pitch - right_; - for (int dx = bottom_; dx > 0; --dx) { - uint32 ecx; - ecx = right_; - ecx = ecx/2; - if (ecx % 2 != 0) { - *edi = ax & 0xff; - edi++; - } - ecx = ecx/2; - if (ecx % 2 != 0) { - *edi = ax & 0xffff; - edi += 2; - } - memset(edi, ax, ecx); - - edi += length; - - } - return; - + for (int i = 0; i < bottom_; ++i) { + uint32 ecx; + ecx = right_; + ecx = ecx / 2; + if (ecx % 2 != 0) { + *edi = col; + edi++; + } + ecx = ecx / 2; + if (ecx % 2 != 0) { + *edi = col; + edi++; + *edi = col; + edi++; + // *((uint16*)edi) = ax & 0xffff; + // edi += 2; + } + memset(edi, col, ecx*4); + edi += length; + } } else { // 00678B8A 00678E38 char* esi; @@ -264,11 +257,8 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot // Fill the rectangle with the colours from the colour table for (int i = 0; i < bottom_; ++i) { - uint8 al; - al = 0; for (int j = 0; j < right_; ++j) { - al = *edi; - *edi = *((uint8*)(&g1_element->offset[al])); + *edi = *((uint8*)(&g1_element->offset[*edi])); edi++; } edi += length; From ce0df832988354cbf00365f4d702374c22646aa8 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sun, 11 May 2014 17:48:33 +0200 Subject: [PATCH 12/99] Formatting --- src/gfx.c | 243 +++++++++++++++++++++++++++--------------------------- 1 file changed, 122 insertions(+), 121 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 3354d45c07..b5bd3c67ad 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -127,157 +127,158 @@ void gfx_draw_line(rct_drawpixelinfo *dpi, int x1, int y1, int x2, int y2, int c void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bottom, int colour) { - int left_, right_, top_, bottom_; - rct_drawpixelinfo* dpi_; - left_ = left; - right_ = right; - top_ = top; - bottom_ = bottom; - dpi_ = dpi; + int left_, right_, top_, bottom_; + rct_drawpixelinfo* dpi_; + left_ = left; + right_ = right; + top_ = top; + bottom_ = bottom; + dpi_ = dpi; - if ((left > right) || (top > bottom) || (dpi->x > right) || (left >= (dpi->x + dpi->width)) || - (bottom < dpi->y) || (top >= (dpi->y + dpi->height))) - return; + if ((left > right) || (top > bottom) || (dpi->x > right) || (left >= (dpi->x + dpi->width)) || + (bottom < dpi->y) || (top >= (dpi->y + dpi->height))) + return; - colour |= RCT2_GLOBAL(0x009ABD9C, uint32); + colour |= RCT2_GLOBAL(0x009ABD9C, uint32); - if (!(colour & 0x1000000)) { - if (!(colour & 0x8000000)) { - left_ = left - dpi->x; - if (left_ < 0) - left_ = 0; + if (!(colour & 0x1000000)) { + if (!(colour & 0x8000000)) { + left_ = left - dpi->x; + if (left_ < 0) + left_ = 0; - right_ = right - dpi->x; - right_++; - if (right_ > dpi->width) - right_ = dpi->width; + right_ = right - dpi->x; + right_++; + if (right_ > dpi->width) + right_ = dpi->width; - right_ -= left_; + right_ -= left_; - top_ = top - dpi->y; - if (top_ < 0) - top_ = 0; + top_ = top - dpi->y; + if (top_ < 0) + top_ = 0; - bottom_ = bottom - dpi->y; - bottom_++; + bottom_ = bottom - dpi->y; + bottom_++; - if (bottom_ > dpi->height) - bottom_ = dpi->height; + if (bottom_ > dpi->height) + bottom_ = dpi->height; - bottom_ -= top_; + bottom_ -= top_; - if (!(colour & 0x2000000)) { - if (!(colour & 0x4000000)) { - uint8* edi; - edi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; + if (!(colour & 0x2000000)) { + if (!(colour & 0x4000000)) { + uint8* edi; + edi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; - uint8 col = colour & 0xFF; + uint8 col = colour & 0xFF; - int length; - length = dpi->width + dpi->pitch - right_; + int length; + length = dpi->width + dpi->pitch - right_; - for (int i = 0; i < bottom_; ++i) { - uint32 ecx; - ecx = right_; - ecx = ecx / 2; - if (ecx % 2 != 0) { - *edi = col; - edi++; - } - ecx = ecx / 2; - if (ecx % 2 != 0) { - *edi = col; - edi++; - *edi = col; - edi++; - // *((uint16*)edi) = ax & 0xffff; - // edi += 2; - } - memset(edi, col, ecx*4); - edi += length; - } - } else { - // 00678B8A 00678E38 - char* esi; - esi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits;; + for (int i = 0; i < bottom_; ++i) { + uint32 ecx; + ecx = right_; + ecx = ecx / 2; + if (ecx % 2 != 0) { + *edi = col; + edi++; + } + ecx = ecx / 2; + if (ecx % 2 != 0) { + *edi = col; + edi++; + *edi = col; + edi++; + // *((uint16*)edi) = ax & 0xffff; + // edi += 2; + } + memset(edi, col, ecx*4); + edi += length; + } + } else { + // 00678B8A 00678E38 + char* esi; + esi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits;; - int eax, ebp; - eax = colour; - ebp = dpi->width + dpi->pitch - right_; + int eax, ebp; + eax = colour; + ebp = dpi->width + dpi->pitch - right_; - RCT2_GLOBAL(0x00EDF810, uint32) = ebp; - RCT2_GLOBAL(0x009ABDB2, uint16) = bottom_; - RCT2_GLOBAL(0x00EDF814, uint32) = right_; + RCT2_GLOBAL(0x00EDF810, uint32) = ebp; + RCT2_GLOBAL(0x009ABDB2, uint16) = bottom_; + RCT2_GLOBAL(0x00EDF814, uint32) = right_; - top_ = (top + dpi_->y) & 0xf; - right_ = (right + dpi_->x) &0xf; + top_ = (top + dpi_->y) & 0xf; + right_ = (right + dpi_->x) &0xf; - dpi_ = esi; + dpi_ = esi; - esi = eax >> 0x1C; - esi = RCT2_GLOBAL(0x0097FEFC,uint32)[esi]; // or possibly uint8)[esi*4] ? + esi = eax >> 0x1C; + esi = RCT2_GLOBAL(0x0097FEFC,uint32)[esi]; // or possibly uint8)[esi*4] ? - for (; RCT2_GLOBAL(0x009ABDB2, uint16) > 0; RCT2_GLOBAL(0x009ABDB2, uint16)--) { - // push ebx - // push ecx - ebp = *(esi + top_*2); + for (; RCT2_GLOBAL(0x009ABDB2, uint16) > 0; RCT2_GLOBAL(0x009ABDB2, uint16)--) { + // push ebx + // push ecx + ebp = *(esi + top_*2); - // mov bp, [esi+top_*2]; - int ecx; - ecx = RCT2_GLOBAL(0x00EDF814, uint32); + // mov bp, [esi+top_*2]; + int ecx; + ecx = RCT2_GLOBAL(0x00EDF814, uint32); - for (int i = ecx; i >=0; --i) { - if (!(ebp & (1 << right_))) - dpi_->bits = left_ & 0xFF; + for (int i = ecx; i >=0; --i) { + if (!(ebp & (1 << right_))) + dpi_->bits = left_ & 0xFF; - right_++; - right_ = right_ & 0xF; - dpi_++; - } - // pop ecx - // pop ebx - top_++; - top_ = top_ &0xf; - dpi_ += RCT2_GLOBAL(0x00EDF810, uint32); - } - return; - } + right_++; + right_ = right_ & 0xF; + dpi_++; + } + // pop ecx + // pop ebx + top_++; + top_ = top_ &0xf; + dpi_ += RCT2_GLOBAL(0x00EDF810, uint32); + } + return; + } - } else { - // 00678B7E 00678C83 - if (dpi_->pad_0E < 1) { - // Location in screen buffer? - uint8* edi = top_ * (dpi_->width + dpi_->pitch) + left_ + dpi_->bits; + } else { + // 00678B7E 00678C83 + if (dpi_->pad_0E < 1) { + // Location in screen buffer? + uint8* edi = top_ * (dpi_->width + dpi_->pitch) + left_ + dpi_->bits; - // Find colour in colour table? - uint32 eax = RCT2_ADDRESS(0x0097FCBC, uint32)[(colour & 0xFF)]; - rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[eax]); + // Find colour in colour table? + uint32 eax = RCT2_ADDRESS(0x0097FCBC, uint32)[(colour & 0xFF)]; + rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[eax]); - int length = (dpi_->width + dpi_->pitch) - right_; + int length = (dpi_->width + dpi_->pitch) - right_; - // Fill the rectangle with the colours from the colour table - for (int i = 0; i < bottom_; ++i) { - for (int j = 0; j < right_; ++j) { - *edi = *((uint8*)(&g1_element->offset[*edi])); - edi++; - } - edi += length; - } - } else if (dpi_->pad_0E > 1) { - // 00678C8A 00678D57 - } else if (dpi_->pad_0E == 1) { - // 00678C88 00678CEE - - } + // Fill the rectangle with the colours from the colour table + for (int i = 0; i < bottom_; ++i) { + for (int j = 0; j < right_; ++j) { + *edi = *((uint8*)(&g1_element->offset[*edi])); + edi++; + } + edi += length; + } + } else if (dpi_->pad_0E > 1) { + // 00678C8A 00678D57 + right_ = right; + } else if (dpi_->pad_0E == 1) { + // 00678C88 00678CEE + right = right; + } - } - } else { - // 00678B3A 00678EC9 - + } + } else { + // 00678B3A 00678EC9 + right_ = right; } } else { // 00678B2E 00678BE5 - } + } // RCT2_CALLPROC_X(0x00678AD4, left, right, top, bottom, 0, dpi, colour); } From ba6263d2bd46dd8a6885190fa5afbb84adb24635 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sun, 11 May 2014 17:49:13 +0200 Subject: [PATCH 13/99] Cross-hatching branch --- src/gfx.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/gfx.c b/src/gfx.c index b5bd3c67ad..feec6685af 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -278,6 +278,63 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot } } else { // 00678B2E 00678BE5 + // Cross hatching + uint16 si; + si = 0; + + left_ = left_ - dpi->x; + if (left_ < 0) { + si = si ^ left_; + left_ = 0; + } + + right_ = right_ - dpi->x; + right_++; + + if (right_ > dpi->width) + right_ = dpi-> width; + + right_ = right_ - left_; + + top_ = top - dpi->y; + if (top_ < 0) { + si = si ^ top_; + top_ = 0; + } + + bottom_ = bottom - dpi->y; + bottom_++; + + if (bottom_ > dpi->height) + bottom_ = dpi->height; + + bottom_ -= top_; + + uint8* edi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; + + uint8 col = colour & 0xFF; + + int length = dpi->width + dpi->pitch - right_; + + for (int i = 0; i < bottom_; ++i) { + uint32 ecx; + ecx = si; + // Rotate right + ecx = (ecx >> 1) | (ecx << (sizeof(ecx) * CHAR_BIT - 1)); + ecx = (ecx & 0xFFFF0000) | right_; + + while (ecx > 0 && ecx != 0xFFFFFFFF) { + ecx = ecx ^ 0x80000000; + if ((int)ecx < 0) { + *edi = col; + } + edi++; + ecx--; + } + si = si ^ 1; + edi += length; + + } } // RCT2_CALLPROC_X(0x00678AD4, left, right, top, bottom, 0, dpi, colour); From 1e8f80fa5c439a3a0c8f44cf88e59b346007645a Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sun, 11 May 2014 18:41:18 +0200 Subject: [PATCH 14/99] Bug fix - memset doesn't increase pointer --- src/gfx.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index feec6685af..57b91881c9 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -177,24 +177,8 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot length = dpi->width + dpi->pitch - right_; for (int i = 0; i < bottom_; ++i) { - uint32 ecx; - ecx = right_; - ecx = ecx / 2; - if (ecx % 2 != 0) { - *edi = col; - edi++; - } - ecx = ecx / 2; - if (ecx % 2 != 0) { - *edi = col; - edi++; - *edi = col; - edi++; - // *((uint16*)edi) = ax & 0xffff; - // edi += 2; - } - memset(edi, col, ecx*4); - edi += length; + memset(edi, col, right_); + edi += length + right_; } } else { // 00678B8A 00678E38 From 7f4e21f334c467c55a947856c94963e6c7b8109f Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sun, 11 May 2014 21:31:31 +0200 Subject: [PATCH 15/99] Bug fix: cross-hatch loop was wrong Also rename and tidy up a bunch of variables --- src/gfx.c | 57 +++++++++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 57b91881c9..ce6aaac213 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -168,17 +168,13 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot if (!(colour & 0x2000000)) { if (!(colour & 0x4000000)) { - uint8* edi; - edi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; + uint8* pixel = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; - uint8 col = colour & 0xFF; - - int length; - length = dpi->width + dpi->pitch - right_; + int length = dpi->width + dpi->pitch - right_; for (int i = 0; i < bottom_; ++i) { - memset(edi, col, right_); - edi += length + right_; + memset(pixel, (colour & 0xFF), right_); + pixel += length + right_; } } else { // 00678B8A 00678E38 @@ -193,7 +189,7 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot RCT2_GLOBAL(0x009ABDB2, uint16) = bottom_; RCT2_GLOBAL(0x00EDF814, uint32) = right_; - top_ = (top + dpi_->y) & 0xf; + top_ = (top + dpi->y) & 0xf; right_ = (right + dpi_->x) &0xf; dpi_ = esi; @@ -229,28 +225,28 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot } else { // 00678B7E 00678C83 - if (dpi_->pad_0E < 1) { + if (dpi->pad_0E < 1) { // Location in screen buffer? - uint8* edi = top_ * (dpi_->width + dpi_->pitch) + left_ + dpi_->bits; + uint8* pixel = top_ * (dpi->width + dpi->pitch) + left_ + dpi->bits; // Find colour in colour table? uint32 eax = RCT2_ADDRESS(0x0097FCBC, uint32)[(colour & 0xFF)]; rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[eax]); - int length = (dpi_->width + dpi_->pitch) - right_; + int length = (dpi->width + dpi->pitch) - right_; // Fill the rectangle with the colours from the colour table for (int i = 0; i < bottom_; ++i) { for (int j = 0; j < right_; ++j) { - *edi = *((uint8*)(&g1_element->offset[*edi])); - edi++; + *pixel = *((uint8*)(&g1_element->offset[*pixel])); + pixel++; } - edi += length; + pixel += length; } - } else if (dpi_->pad_0E > 1) { + } else if (dpi->pad_0E > 1) { // 00678C8A 00678D57 right_ = right; - } else if (dpi_->pad_0E == 1) { + } else if (dpi->pad_0E == 1) { // 00678C88 00678CEE right = right; } @@ -263,12 +259,11 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot } else { // 00678B2E 00678BE5 // Cross hatching - uint16 si; - si = 0; + uint16 pattern = 0; left_ = left_ - dpi->x; if (left_ < 0) { - si = si ^ left_; + pattern = pattern ^ left_; left_ = 0; } @@ -282,7 +277,7 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot top_ = top - dpi->y; if (top_ < 0) { - si = si ^ top_; + pattern = pattern ^ top_; top_ = 0; } @@ -294,29 +289,25 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot bottom_ -= top_; - uint8* edi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; - - uint8 col = colour & 0xFF; + uint8* pixel = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; int length = dpi->width + dpi->pitch - right_; for (int i = 0; i < bottom_; ++i) { - uint32 ecx; - ecx = si; + uint32 ecx = pattern; // Rotate right ecx = (ecx >> 1) | (ecx << (sizeof(ecx) * CHAR_BIT - 1)); ecx = (ecx & 0xFFFF0000) | right_; - - while (ecx > 0 && ecx != 0xFFFFFFFF) { + // Fill every other pixel with the colour + for (; (ecx & 0xFFFF) > 0; ecx--) { ecx = ecx ^ 0x80000000; if ((int)ecx < 0) { - *edi = col; + *pixel = colour & 0xFF; } - edi++; - ecx--; + pixel++; } - si = si ^ 1; - edi += length; + pattern = pattern ^ 1; + pixel += length; } } From ea83381e4cfe282a991d74830a289fb7ef231e2d Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sun, 11 May 2014 22:19:01 +0200 Subject: [PATCH 16/99] Add author --- src/gfx.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index ce6aaac213..e4c229c955 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014 Ted John + * Copyright (c) 2014 Ted John, Peter Hill * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. * * This file is part of OpenRCT2. @@ -119,9 +119,9 @@ void gfx_draw_line(rct_drawpixelinfo *dpi, int x1, int y1, int x2, int y2, int c * rct2: 0x00678AD4 * dpi (edi) * left (ax) - * top (cx) ? + * top (cx) * right (bx) - * bottom (dx) ? + * bottom (dx) * colour (ebp) */ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bottom, int colour) @@ -293,8 +293,9 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot int length = dpi->width + dpi->pitch - right_; + uint32 ecx; for (int i = 0; i < bottom_; ++i) { - uint32 ecx = pattern; + ecx = pattern; // Rotate right ecx = (ecx >> 1) | (ecx << (sizeof(ecx) * CHAR_BIT - 1)); ecx = (ecx & 0xFFFF0000) | right_; From 756f21b427790787eea7ca997cd67517e8ea3c29 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Mon, 12 May 2014 22:04:07 +0100 Subject: [PATCH 17/99] Trying to understand how the drawing function works --- src/gfx.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/src/gfx.c b/src/gfx.c index 8f663827f5..7e83e998e1 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -149,6 +149,77 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri #define RCT2_Y_RELATED_GLOBAL_2 0x9ABDAC //sint16 #define RCT2_X_RELATED_GLOBAL_1 0x9E3D10 //uint16 #define RCT2_X_RELATED_GLOBAL_2 0x9ABDA8 //sint16 + +void sub_0x67AA18(int* source_bits_pointer, int* dest_bits_pointer, rct_drawpixelinfo *dpi){ + if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x2000000){ + return; //0x67AAB3 + } + + if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x4000000){ + return; //0x67AFD8 + } + + int ebx = RCT2_GLOBAL(0xEDF808, uint32); + ebx = RCT2_GLOBAL(ebx * 2 + source_bits_pointer,uint16); + int ebp = dest_bits_pointer; + ebx += (int)source_bits_pointer; + +StartLoop: + ebx = ebx; + int cx = RCT2_GLOBAL(ebx, uint16); + RCT2_GLOBAL(0x9ABDB4, uint8) = cx & 0xFF; + ebx += 2; + cx &= 0xFF7F; + int esi = ebx; + int edx = (cx & 0xFF00) >> 8; + ebx += cx; + edx -= RCT2_GLOBAL(0xEDF80C, sint32); + int edi = ebp; + if (edx > 0){ + edi += edx; + } + else{ + esi -= edx; + cx += edx & 0xFFFF; + if (cx <= 0){ + goto TestLoop; + //jump to 0x67AA97 + } + edx &= 0xFFFF0000; + } + edx += cx; + edx -= RCT2_GLOBAL(0x9ABDA8, sint16); + if (edx > 0){ + cx -= edx; + if (cx <= 0){ + goto TestLoop; + //jump to 0x67AA97 + } + } + if (cx & 1){ + cx >>= 1; + RCT2_GLOBAL(edi, uint8) = RCT2_GLOBAL(esi, uint8); + } + else cx >>= 1; + + if (cx & 1){ + cx >>= 1; + RCT2_GLOBAL(edi, uint16) = RCT2_GLOBAL(esi, uint16); + } + else cx >>= 1; + + for (int i = cx; i > 0; --i, edi++, esi++){ + RCT2_GLOBAL(edi, uint16) = RCT2_GLOBAL(esi, uint16); + } +TestLoop: + if (!(RCT2_GLOBAL(0x9ABDB4, uint8) & 0x80)) goto StartLoop; + edx = RCT2_GLOBAL(0x9ABDB0, sint16); + ebp += edx; + RCT2_GLOBAL(0x9ABDAC, sint16)--; + if (RCT2_GLOBAL(0x9ABDAC, sint16))goto StartLoop; + +} + /* * rct2: 0x67A934 title screen bitmaps on buttons * This function readies all the global vars for copying the sprite data onto the screen @@ -205,7 +276,10 @@ void sub_0x67A934(rct_drawpixelinfo *dpi, int x, int y){ RCT2_GLOBAL(0x9ABDB0, uint16) = dpi->width + dpi->pitch; // I dont think it uses ecx, edx but just in case - RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, translated_x, translated_y, RCT2_GLOBAL(0x9E3D08, uint32), bits_pointer, dpi); + //esi is the source and bits_pointer is the destination + sub_0x67AA18(RCT2_GLOBAL(0x9E3D08, int*), (int*)bits_pointer, dpi); + + //RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, translated_x, translated_y, RCT2_GLOBAL(0x9E3D08, uint32), bits_pointer, dpi); } /** From 1d754dc390d7516e734f3d06d75929a2a0a8ba49 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 13 May 2014 18:32:57 +0100 Subject: [PATCH 18/99] Still searching for bug --- src/gfx.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 7e83e998e1..24a30287fb 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -277,9 +277,9 @@ void sub_0x67A934(rct_drawpixelinfo *dpi, int x, int y){ // I dont think it uses ecx, edx but just in case //esi is the source and bits_pointer is the destination - sub_0x67AA18(RCT2_GLOBAL(0x9E3D08, int*), (int*)bits_pointer, dpi); + //sub_0x67AA18(RCT2_GLOBAL(0x9E3D08, int*), (int*)bits_pointer, dpi); - //RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, translated_x, translated_y, RCT2_GLOBAL(0x9E3D08, uint32), bits_pointer, dpi); + RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, translated_x, translated_y, RCT2_GLOBAL(0x9E3D08, uint32), bits_pointer, dpi); } /** @@ -303,6 +303,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x009E3CDC, uint32) = eax; if ((image_id & (1 << 31)) && (image_id & (1 << 29))){ + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); /* eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; @@ -334,9 +335,11 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x9ABEDE, uint32) = ebp;*/ return; } else if ((image_id & (1 << 31))){ + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); return; //jump into 0x67a361 } else if ((image_id & (1 << 30))){ + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); return; //jump into 0x67a445 } @@ -368,8 +371,8 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); - return; + //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + //return; //There is a mistake in the code below this point calling the above to skip it. //dpi on stack @@ -444,7 +447,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } if (!(RCT2_GLOBAL(0x9E3D14, uint16) & 0x02)){ - eax = (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) & 0xFF) << 8; + eax = (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, uint8)) << 8; edx = RCT2_GLOBAL(0x9ABDAE, sint16); ebp = RCT2_GLOBAL(0x9ABDB0, sint16); ebx = RCT2_GLOBAL(0xEDF81C, uint32); @@ -452,10 +455,11 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) //ebx, esi, edi, ah used in 0x67a690 //Calling is wrong //esi or bits is most likely wrong - RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, bits_pointer, ebp); + RCT2_CALLPROC_X_EBPSAFE(0x67A690, eax, ebx, ecx, edx, esi, bits_pointer, ebp); return; } //0x67A60A + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); esi -= RCT2_GLOBAL(0x9E3D08, sint32); return; From ba16b197e3f1583ed95cd78729dbb7ef5b23bf5c Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 13 May 2014 19:01:59 +0100 Subject: [PATCH 19/99] Bug found in the first test doh. --- src/gfx.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 24a30287fb..e69e64a763 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -291,18 +291,19 @@ void sub_0x67A934(rct_drawpixelinfo *dpi, int x, int y){ */ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) { - //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); - //return; + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + return; int eax = 0, ebx = image_id, ecx = x, edx = y, esi = 0, edi = dpi, ebp = 0; eax = image_id; eax >>= 26; - RCT2_GLOBAL(0x00EDF81C, uint32) = image_id & 0xE0000000; + RCT2_GLOBAL(0x00EDF81C, uint32) = ebx; eax &= 0x7; eax = RCT2_GLOBAL(0x009E3CE4 + eax*4, uint32); + RCT2_GLOBAL(0x00EDF81C, uint32) &= 0xE0000000; RCT2_GLOBAL(0x009E3CDC, uint32) = eax; - if ((image_id & (1 << 31)) && (image_id & (1 << 29))){ + if (ebx&0xE0000000){ RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); /* eax = image_id; @@ -334,11 +335,11 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x9ABDA4, uint32) = 0x009ABE0C; RCT2_GLOBAL(0x9ABEDE, uint32) = ebp;*/ return; - } else if ((image_id & (1 << 31))){ + } else if (ebx & 0x80000000){ RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); return; //jump into 0x67a361 - } else if ((image_id & (1 << 30))){ + } else if (ebx & 0x20000000){ RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); return; //jump into 0x67a445 @@ -366,12 +367,14 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x9E3D14, uint32) = *((uint32*)ebx + 3); if (RCT2_GLOBAL(0x9E3D14, uint32) & (1 << 2)){ //Title screen bitmaps + //RCT2_CALLPROC_X(0x0067A934, eax, ebx, x, y, 0, dpi, ebp); sub_0x67A934(dpi, x, y); return; } - //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + //RCT2_CALLPROC_X(0x0067A4CA, eax,ebx, x, y, 0, dpi, ebp); + //return; //return; //There is a mistake in the code below this point calling the above to skip it. From 20c7b98c889b037fe3179c903478c4053d6d9029 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 13 May 2014 19:06:15 +0100 Subject: [PATCH 20/99] merge --- src/gfx.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 5e6e4019b5..cb4308a338 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -407,7 +407,6 @@ void sub_0x67A934(rct_drawpixelinfo *dpi, int x, int y){ */ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) { -<<<<<<< HEAD RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); return; @@ -582,11 +581,6 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); esi -= RCT2_GLOBAL(0x9E3D08, sint32); return; - - -======= - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); ->>>>>>> master } /** From 92386e5758d2be781b0adda731eb254b0d2ffa7e Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 13 May 2014 19:12:18 +0100 Subject: [PATCH 21/99] Fix sketchy line bug that i introduced --- src/gfx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gfx.h b/src/gfx.h index de0411b258..162ccd121f 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -31,7 +31,7 @@ typedef struct { short width; // 0x08 short height; // 0x0A short pitch; // 0x0C note: this is actually (pitch - width) - uint16 pad_0E; // 0x0E + uint8 pad_0E; // 0x0E char var_0F; // 0x0F } rct_drawpixelinfo; From 8ecde8f07a8fb3147988e70c298d61e7bb0b6bf3 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 13 May 2014 20:10:49 +0100 Subject: [PATCH 22/99] Moved around logic so it runs correctly --- src/gfx.c | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index cb4308a338..d74ce12556 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -407,20 +407,28 @@ void sub_0x67A934(rct_drawpixelinfo *dpi, int x, int y){ */ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) { - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); - return; + //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + //return; int eax = 0, ebx = image_id, ecx = x, edx = y, esi = 0, edi = dpi, ebp = 0; - eax = image_id; - eax >>= 26; - RCT2_GLOBAL(0x00EDF81C, uint32) = ebx; - eax &= 0x7; - eax = RCT2_GLOBAL(0x009E3CE4 + eax*4, uint32); - RCT2_GLOBAL(0x00EDF81C, uint32) &= 0xE0000000; - RCT2_GLOBAL(0x009E3CDC, uint32) = eax; - if (ebx&0xE0000000){ + RCT2_GLOBAL(0x00EDF81C, uint32) = image_id & 0xE0000000; + eax = (image_id >> 26) & 0x7; + //eax = RCT2_GLOBAL(0x009E3CE4 + eax*4, uint32); + RCT2_GLOBAL(0x009E3CDC, uint32) = RCT2_GLOBAL(0x009E3CE4 + eax * 4, uint32); + + if (((image_id)& 0xE0000000) && !(image_id & (1 << 31))) { RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + // + return;//jump into 0x67a445 + } + else if (((image_id)& 0xE0000000) && !(image_id & (1 << 29))){ + char* find = "FINDMEDUNCAN"; + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + return;//jump into 0x67a361 + } + else if ((image_id)& 0xE0000000){ + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); /* eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; @@ -451,14 +459,6 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x9ABDA4, uint32) = 0x009ABE0C; RCT2_GLOBAL(0x9ABEDE, uint32) = ebp;*/ return; - } else if (ebx & 0x80000000){ - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); - return; - //jump into 0x67a361 - } else if (ebx & 0x20000000){ - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); - return; - //jump into 0x67a445 } ebx &= 0x7FFFF; @@ -488,12 +488,6 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) return; } - - //RCT2_CALLPROC_X(0x0067A4CA, eax,ebx, x, y, 0, dpi, ebp); - //return; - //return; - //There is a mistake in the code below this point calling the above to skip it. - //dpi on stack int translated_x, translated_y; char* bits_pointer; @@ -572,8 +566,6 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebx = RCT2_GLOBAL(0xEDF81C, uint32); ecx = 0xFFFF&translated_x; //ebx, esi, edi, ah used in 0x67a690 - //Calling is wrong - //esi or bits is most likely wrong RCT2_CALLPROC_X_EBPSAFE(0x67A690, eax, ebx, ecx, edx, esi, bits_pointer, ebp); return; } From 2c7118c01b55f6791ef6f91f7fc9f850dabae785 Mon Sep 17 00:00:00 2001 From: Duncan Date: Wed, 14 May 2014 17:01:13 +0100 Subject: [PATCH 23/99] Added guess about G1 dpi. Warning not tested. --- src/gfx.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index d74ce12556..8c0f84ae27 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -341,16 +341,16 @@ TestLoop: * This function readies all the global vars for copying the sprite data onto the screen * I think its only used for bitmaps onto buttons but i am not sure. */ -void sub_0x67A934(rct_drawpixelinfo *dpi, int x, int y){ +void sub_0x67A934(rct_drawpixelinfo *source_dpi, rct_drawpixelinfo *dest_dpi, int x, int y){ - int _edi = dpi, _esi; + int _edi = dest_dpi, _esi; sint16 translated_x = x, translated_y = y; char* bits_pointer; - bits_pointer = dpi->bits; + bits_pointer = dest_dpi->bits; - translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16) - dpi->y; + translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16) - dest_dpi->y; RCT2_GLOBAL(0xEDF808, uint32) = 0; - RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) = RCT2_GLOBAL(0x9E3D0E, sint16); + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) = source_dpi->y;//RCT2_GLOBAL(0x9E3D0E, sint16); if (translated_y < 0) { @@ -360,19 +360,19 @@ void sub_0x67A934(rct_drawpixelinfo *dpi, int x, int y){ translated_y = 0; } else{ - bits_pointer += (dpi->width + dpi->pitch)*translated_y; + bits_pointer += (dest_dpi->width + dest_dpi->pitch)*translated_y; } - translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) - dpi->height; + translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) - dest_dpi->height; if (translated_y > 0){ RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) -= translated_y; if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) <= 0)return; } RCT2_GLOBAL(0xEDF80C, uint32) = 0; - translated_x += RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_1, uint16) - dpi->x; + translated_x += RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_1, uint16) - dest_dpi->x; - RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) = RCT2_GLOBAL(0x9E3D0C, sint16); + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) = source_dpi->x;//RCT2_GLOBAL(0x9E3D0C, sint16); if (translated_x < 0){ RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) += translated_x; if (RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) <= 0)return; @@ -383,19 +383,19 @@ void sub_0x67A934(rct_drawpixelinfo *dpi, int x, int y){ bits_pointer += translated_x; } translated_x += RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16); - translated_x -= dpi->width; + translated_x -= dest_dpi->width; if (translated_x > 0){ RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) -= translated_x; if (RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) <= 0)return; } - RCT2_GLOBAL(0x9ABDB0, uint16) = dpi->width + dpi->pitch; + RCT2_GLOBAL(0x9ABDB0, uint16) = dest_dpi->width + dest_dpi->pitch; // I dont think it uses ecx, edx but just in case //esi is the source and bits_pointer is the destination - //sub_0x67AA18(RCT2_GLOBAL(0x9E3D08, int*), (int*)bits_pointer, dpi); + //sub_0x67AA18(RCT2_GLOBAL(0x9E3D08, int*), (int*)bits_pointer, dest_dpi); - RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, translated_x, translated_y, RCT2_GLOBAL(0x9E3D08, uint32), bits_pointer, dpi); + RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, translated_x, translated_y, RCT2_GLOBAL(0x9E3D08, uint32), bits_pointer, dest_dpi); } /** @@ -477,6 +477,8 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } eax = *((uint32*)ebx + 2); ebp = *((uint32*)ebx + 3); + rct_drawpixelinfo* g1_source_dpi = (rct_drawpixelinfo*)ebx; + //This is a rct2_drawpixelinfo struct RCT2_GLOBAL(0x9E3D08, uint32) = *((uint32*)ebx); //offset to g1 bits? RCT2_GLOBAL(0x9E3D0C, uint32) = *((uint32*)ebx + 1); RCT2_GLOBAL(0x9E3D10, uint32) = *((uint32*)ebx + 2); //X-Y related unsigned? sets RCT2_X_RELATED_GLOBAL_1 and Y @@ -484,7 +486,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) if (RCT2_GLOBAL(0x9E3D14, uint32) & (1 << 2)){ //Title screen bitmaps //RCT2_CALLPROC_X(0x0067A934, eax, ebx, x, y, 0, dpi, ebp); - sub_0x67A934(dpi, x, y); + sub_0x67A934(g1_source_dpi, dpi, x, y); return; } From ff86f7e9e9aea07b0b6791ee8253b09879593f6e Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 14 May 2014 21:58:35 +0100 Subject: [PATCH 24/99] sub0x67a934 turned into almost proper C code --- src/gfx.c | 161 +++++++++++++++++++++++++++++------------------------- 1 file changed, 88 insertions(+), 73 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 8c0f84ae27..62435a8bdb 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -262,9 +262,10 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri } #define RCT2_Y_RELATED_GLOBAL_1 0x9E3D12 //uint16 -#define RCT2_Y_RELATED_GLOBAL_2 0x9ABDAC //sint16 +#define RCT2_Y_END_POINT_GLOBAL 0x9ABDAC //sint16 #define RCT2_X_RELATED_GLOBAL_1 0x9E3D10 //uint16 -#define RCT2_X_RELATED_GLOBAL_2 0x9ABDA8 //sint16 +#define RCT2_X_END_POINT_GLOBAL 0x9ABDA8 //sint16 +#define RCT2_DPI_LINE_LENGTH_GLOBAL 0x9ABDB0 //uint16 width+pitch void sub_0x67AA18(int* source_bits_pointer, int* dest_bits_pointer, rct_drawpixelinfo *dpi){ if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x2000000){ @@ -304,7 +305,7 @@ StartLoop: edx &= 0xFFFF0000; } edx += cx; - edx -= RCT2_GLOBAL(0x9ABDA8, sint16); + edx -= RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16); if (edx > 0){ cx -= edx; if (cx <= 0){ @@ -329,10 +330,10 @@ StartLoop: } TestLoop: if (!(RCT2_GLOBAL(0x9ABDB4, uint8) & 0x80)) goto StartLoop; - edx = RCT2_GLOBAL(0x9ABDB0, sint16); + edx = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16); ebp += edx; - RCT2_GLOBAL(0x9ABDAC, sint16)--; - if (RCT2_GLOBAL(0x9ABDAC, sint16))goto StartLoop; + RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16)--; + if (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16))goto StartLoop; } @@ -341,61 +342,75 @@ TestLoop: * This function readies all the global vars for copying the sprite data onto the screen * I think its only used for bitmaps onto buttons but i am not sure. */ -void sub_0x67A934(rct_drawpixelinfo *source_dpi, rct_drawpixelinfo *dest_dpi, int x, int y){ +void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, int y){ - int _edi = dest_dpi, _esi; - sint16 translated_x = x, translated_y = y; char* bits_pointer; bits_pointer = dest_dpi->bits; - translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16) - dest_dpi->y; RCT2_GLOBAL(0xEDF808, uint32) = 0; - RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) = source_dpi->y;//RCT2_GLOBAL(0x9E3D0E, sint16); - if (translated_y < 0) - { - RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) += translated_y; - if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) <= 0)return; - RCT2_GLOBAL(0xEDF808, sint16) -= translated_y; - translated_y = 0; - } - else{ - bits_pointer += (dest_dpi->width + dest_dpi->pitch)*translated_y; - } - - translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) - dest_dpi->height; - if (translated_y > 0){ - RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) -= translated_y; - if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) <= 0)return; - } - - RCT2_GLOBAL(0xEDF80C, uint32) = 0; - translated_x += RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_1, uint16) - dest_dpi->x; - - RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) = source_dpi->x;//RCT2_GLOBAL(0x9E3D0C, sint16); - if (translated_x < 0){ - RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) += translated_x; - if (RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) <= 0)return; - RCT2_GLOBAL(0xEDF80C, sint16) -= translated_x; - translated_x = 0; - } - else{ - bits_pointer += translated_x; - } - translated_x += RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16); - translated_x -= dest_dpi->width; - if (translated_x > 0){ - RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) -= translated_x; - if (RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) <= 0)return; - } - - RCT2_GLOBAL(0x9ABDB0, uint16) = dest_dpi->width + dest_dpi->pitch; + int start_y, end_y; + start_y = y + source_g1->y_offset - dest_dpi->y; - // I dont think it uses ecx, edx but just in case - //esi is the source and bits_pointer is the destination - //sub_0x67AA18(RCT2_GLOBAL(0x9E3D08, int*), (int*)bits_pointer, dest_dpi); + //If the start position is negative reset to zero + if (start_y < 0){ + //Create the end point within the drawing area + end_y = source_g1->height + start_y; + //If the end point is now <= 0 no need to draw + if (end_y <= 0)return; - RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, translated_x, translated_y, RCT2_GLOBAL(0x9E3D08, uint32), bits_pointer, dest_dpi); + RCT2_GLOBAL(0xEDF808, sint16) -= start_y; + start_y = 0; + } + else{ + end_y = source_g1->height; + //Move the pointer to the correct starting y location + bits_pointer += (dest_dpi->width + dest_dpi->pitch)*start_y; + } + + int height = start_y + end_y; + //If the image is taller than the drawing area + if (height > dest_dpi->height){ + //Make the end within the drawing area + end_y -= height - dest_dpi->height; + //If the end is now <=0 then there is nothing to draw + if (end_y <= 0)return; + } + + RCT2_GLOBAL(0xEDF80C, uint32) = 0; + int start_x, end_x; + start_x = x + source_g1->x_offset - dest_dpi->x; + + //If the start position is negative reset to zero + if (start_x < 0){ + //Create the end point within the drawing area + end_x = source_g1->width + start_x; + //If the end point is now <= 0 no need to draw + if (end_x <= 0)return; + + RCT2_GLOBAL(0xEDF80C, sint16) -= start_x; + start_x = 0; + } + else{ + end_x = source_g1->width; + //Increment the pointer to our start location + bits_pointer += start_x; + } + + int width = start_x + end_x; + //If the image is wider than the drawing area + if (width > dest_dpi->width){ + //Make the end within drawing area + end_x -= width - dest_dpi->width; + //If the end is now <=0 then there is nothing to draw + if (end_x <= 0)return; + } + + RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16) = dest_dpi->width + dest_dpi->pitch; + RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = end_x; + RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = end_y; + //sub_0x67AA18(RCT2_GLOBAL(0x9E3D08, int*), (int*)bits_pointer, dest_dpi); + RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, source_g1->offset, bits_pointer, dest_dpi); } /** @@ -423,7 +438,6 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) return;//jump into 0x67a445 } else if (((image_id)& 0xE0000000) && !(image_id & (1 << 29))){ - char* find = "FINDMEDUNCAN"; RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); return;//jump into 0x67a361 } @@ -477,16 +491,17 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } eax = *((uint32*)ebx + 2); ebp = *((uint32*)ebx + 3); - rct_drawpixelinfo* g1_source_dpi = (rct_drawpixelinfo*)ebx; + rct_g1_element* g1_source = (rct_g1_element*)ebx; //This is a rct2_drawpixelinfo struct RCT2_GLOBAL(0x9E3D08, uint32) = *((uint32*)ebx); //offset to g1 bits? RCT2_GLOBAL(0x9E3D0C, uint32) = *((uint32*)ebx + 1); RCT2_GLOBAL(0x9E3D10, uint32) = *((uint32*)ebx + 2); //X-Y related unsigned? sets RCT2_X_RELATED_GLOBAL_1 and Y RCT2_GLOBAL(0x9E3D14, uint32) = *((uint32*)ebx + 3); + if (RCT2_GLOBAL(0x9E3D14, uint32) & (1 << 2)){ //Title screen bitmaps //RCT2_CALLPROC_X(0x0067A934, eax, ebx, x, y, 0, dpi, ebp); - sub_0x67A934(g1_source_dpi, dpi, x, y); + sub_0x67A934(g1_source, dpi, x, y); return; } @@ -499,14 +514,14 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x9E3CE0, uint32) = 0; bits_pointer = dpi->bits; - RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) = RCT2_GLOBAL(0x9E3D0E, sint16); + RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = RCT2_GLOBAL(0x9E3D0E, sint16); translated_y = y + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16) - dpi->y; if (translated_y < 0){ - RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) += translated_y; - if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) <= 0){ + RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) += translated_y; + if (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) <= 0){ return; } translated_y = -translated_y; @@ -518,53 +533,53 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) bits_pointer += eax; } - translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) - dpi->height;; + translated_y += RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) - dpi->height;; if (translated_y > 0){ - RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) -= translated_y; - if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) <=0) + RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) -= translated_y; + if (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) <= 0) { return; } } - RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) = RCT2_GLOBAL(0x9E3D0C, sint16); + RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = RCT2_GLOBAL(0x9E3D0C, sint16); eax = dpi->width + dpi->pitch - RCT2_GLOBAL(0x9E3D0C, sint16); RCT2_GLOBAL(0x9ABDAE, uint16) = 0; - RCT2_GLOBAL(0x9ABDB0, sint16) = dpi->width + dpi->pitch - RCT2_GLOBAL(0x9E3D0C, sint16); + RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16) = dpi->width + dpi->pitch - RCT2_GLOBAL(0x9E3D0C, sint16); translated_x = x + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_1, uint16) - dpi->x; if (translated_x < 0){ - RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) += translated_x; - if (RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) <= 0){ + RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) += translated_x; + if (RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) <= 0){ return; } translated_x -= RCT2_GLOBAL(0x9ABDAE, sint16); esi -= translated_x; RCT2_GLOBAL(0x9E3CE0, sint32) -= translated_x; - RCT2_GLOBAL(0x9ABDB0, sint16) -= translated_x; + RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16) -= translated_x; translated_x = 0; } bits_pointer += translated_x; - translated_x += RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) - dpi->width; + translated_x += RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) - dpi->width; if (translated_x > 0){ - RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) -= translated_x; - if (RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) <= 0){ + RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) -= translated_x; + if (RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) <= 0){ return; } RCT2_GLOBAL(0x9ABDAE, sint16) += translated_x; - RCT2_GLOBAL(0x9ABDB0, sint16) += translated_x; + RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16) += translated_x; } if (!(RCT2_GLOBAL(0x9E3D14, uint16) & 0x02)){ - eax = (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, uint8)) << 8; + eax = (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, uint8)) << 8; edx = RCT2_GLOBAL(0x9ABDAE, sint16); - ebp = RCT2_GLOBAL(0x9ABDB0, sint16); + ebp = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16); ebx = RCT2_GLOBAL(0xEDF81C, uint32); ecx = 0xFFFF&translated_x; //ebx, esi, edi, ah used in 0x67a690 From 84c7f33ba1c7f87d253ea75b0c4355e5bbb32028 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 14 May 2014 22:07:59 +0100 Subject: [PATCH 25/99] Changed to memset to make code look a bit simpler --- src/gfx.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 62435a8bdb..046fcde8c5 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -138,9 +138,7 @@ void gfx_draw_line_on_buffer(rct_drawpixelinfo *dpi, char colour, int y, int x, bits_pointer = dpi->bits + y*(dpi->pitch + dpi->width) + x; //Draw the line to the specified colour - for (; no_pixels > 0; --no_pixels, ++bits_pointer){ - *((uint8*)bits_pointer) = colour; - } + memset(bits_pointer, colour, no_pixels); } From 7f20fa9338a3f4d24413da88bf98aae027c43de7 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 14 May 2014 22:14:46 +0100 Subject: [PATCH 26/99] Skipping buggy code for now. Will be looked at some time later --- src/gfx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gfx.c b/src/gfx.c index 046fcde8c5..99c35a463e 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -502,7 +502,8 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) sub_0x67A934(g1_source, dpi, x, y); return; } - + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + return; //dpi on stack int translated_x, translated_y; char* bits_pointer; From 12dfd1e6447ba420818ed83e64955f3809f5f3cc Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Thu, 15 May 2014 00:23:50 +0100 Subject: [PATCH 27/99] fix warnings --- src/gfx.c | 357 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 264 insertions(+), 93 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 99c35a463e..941ed5e7f1 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014 Ted John + * Copyright (c) 2014 Ted John, Peter Hill * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. * * This file is part of OpenRCT2. @@ -138,7 +138,9 @@ void gfx_draw_line_on_buffer(rct_drawpixelinfo *dpi, char colour, int y, int x, bits_pointer = dpi->bits + y*(dpi->pitch + dpi->width) + x; //Draw the line to the specified colour - memset(bits_pointer, colour, no_pixels); + for (; no_pixels > 0; --no_pixels, ++bits_pointer){ + *((uint8*)bits_pointer) = colour; + } } @@ -240,7 +242,194 @@ void gfx_draw_line(rct_drawpixelinfo *dpi, int x1, int y1, int x2, int y2, int c */ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bottom, int colour) { - RCT2_CALLPROC_X(0x00678AD4, left, right, top, bottom, 0, (int)dpi, colour); + + int left_, right_, top_, bottom_; + rct_drawpixelinfo* dpi_; + left_ = left; + right_ = right; + top_ = top; + bottom_ = bottom; + dpi_ = dpi; + + if ((left > right) || (top > bottom) || (dpi->x > right) || (left >= (dpi->x + dpi->width)) || + (bottom < dpi->y) || (top >= (dpi->y + dpi->height))) + return; + + colour |= RCT2_GLOBAL(0x009ABD9C, uint32); + + if (!(colour & 0x1000000)) { + if (!(colour & 0x8000000)) { + left_ = left - dpi->x; + if (left_ < 0) + left_ = 0; + + right_ = right - dpi->x; + right_++; + if (right_ > dpi->width) + right_ = dpi->width; + + right_ -= left_; + + top_ = top - dpi->y; + if (top_ < 0) + top_ = 0; + + bottom_ = bottom - dpi->y; + bottom_++; + + if (bottom_ > dpi->height) + bottom_ = dpi->height; + + bottom_ -= top_; + + if (!(colour & 0x2000000)) { + if (!(colour & 0x4000000)) { + uint8* pixel = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; + + int length = dpi->width + dpi->pitch - right_; + + for (int i = 0; i < bottom_; ++i) { + memset(pixel, (colour & 0xFF), right_); + pixel += length + right_; + } + } else { + // 00678B8A 00678E38 + char* esi; + esi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits;; + + int eax, ebp; + eax = colour; + ebp = dpi->width + dpi->pitch - right_; + + RCT2_GLOBAL(0x00EDF810, uint32) = ebp; + RCT2_GLOBAL(0x009ABDB2, uint16) = bottom_; + RCT2_GLOBAL(0x00EDF814, uint32) = right_; + + top_ = (top + dpi->y) & 0xf; + right_ = (right + dpi_->x) &0xf; + + dpi_ = (rct_drawpixelinfo*)esi; + + esi = (char*)(eax >> 0x1C); + esi = (char*)RCT2_GLOBAL(0x0097FEFC,uint32)[esi]; // or possibly uint8)[esi*4] ? + + for (; RCT2_GLOBAL(0x009ABDB2, uint16) > 0; RCT2_GLOBAL(0x009ABDB2, uint16)--) { + // push ebx + // push ecx + ebp = *(esi + top_*2); + + // mov bp, [esi+top_*2]; + int ecx; + ecx = RCT2_GLOBAL(0x00EDF814, uint32); + + for (int i = ecx; i >=0; --i) { + if (!(ebp & (1 << right_))) + dpi_->bits = (char*)(left_ & 0xFF); + + right_++; + right_ = right_ & 0xF; + dpi_++; + } + // pop ecx + // pop ebx + top_++; + top_ = top_ &0xf; + dpi_ += RCT2_GLOBAL(0x00EDF810, uint32); + } + return; + } + + } else { + // 00678B7E 00678C83 + if (dpi->pad_0E < 1) { + // Location in screen buffer? + uint8* pixel = top_ * (dpi->width + dpi->pitch) + left_ + dpi->bits; + + // Find colour in colour table? + uint32 eax = RCT2_ADDRESS(0x0097FCBC, uint32)[(colour & 0xFF)]; + rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[eax]); + + int length = (dpi->width + dpi->pitch) - right_; + + // Fill the rectangle with the colours from the colour table + for (int i = 0; i < bottom_; ++i) { + for (int j = 0; j < right_; ++j) { + *pixel = *((uint8*)(&g1_element->offset[*pixel])); + pixel++; + } + pixel += length; + } + } else if (dpi->pad_0E > 1) { + // 00678C8A 00678D57 + right_ = right; + } else if (dpi->pad_0E == 1) { + // 00678C88 00678CEE + right = right; + } + + } + } else { + // 00678B3A 00678EC9 + right_ = right; + } + } else { + // 00678B2E 00678BE5 + // Cross hatching + uint16 pattern = 0; + + left_ = left_ - dpi->x; + if (left_ < 0) { + pattern = pattern ^ left_; + left_ = 0; + } + + right_ = right_ - dpi->x; + right_++; + + if (right_ > dpi->width) + right_ = dpi-> width; + + right_ = right_ - left_; + + top_ = top - dpi->y; + if (top_ < 0) { + pattern = pattern ^ top_; + top_ = 0; + } + + bottom_ = bottom - dpi->y; + bottom_++; + + if (bottom_ > dpi->height) + bottom_ = dpi->height; + + bottom_ -= top_; + + uint8* pixel = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; + + int length = dpi->width + dpi->pitch - right_; + + uint32 ecx; + for (int i = 0; i < bottom_; ++i) { + ecx = pattern; + // Rotate right + ecx = (ecx >> 1) | (ecx << (sizeof(ecx) * CHAR_BIT - 1)); + ecx = (ecx & 0xFFFF0000) | right_; + // Fill every other pixel with the colour + for (; (ecx & 0xFFFF) > 0; ecx--) { + ecx = ecx ^ 0x80000000; + if ((int)ecx < 0) { + *pixel = colour & 0xFF; + } + pixel++; + } + pattern = pattern ^ 1; + pixel += length; + + } + } + + // RCT2_CALLPROC_X(0x00678AD4, left, right, top, bottom, 0, dpi, colour); } /** @@ -260,10 +449,9 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri } #define RCT2_Y_RELATED_GLOBAL_1 0x9E3D12 //uint16 -#define RCT2_Y_END_POINT_GLOBAL 0x9ABDAC //sint16 +#define RCT2_Y_RELATED_GLOBAL_2 0x9ABDAC //sint16 #define RCT2_X_RELATED_GLOBAL_1 0x9E3D10 //uint16 -#define RCT2_X_END_POINT_GLOBAL 0x9ABDA8 //sint16 -#define RCT2_DPI_LINE_LENGTH_GLOBAL 0x9ABDB0 //uint16 width+pitch +#define RCT2_X_RELATED_GLOBAL_2 0x9ABDA8 //sint16 void sub_0x67AA18(int* source_bits_pointer, int* dest_bits_pointer, rct_drawpixelinfo *dpi){ if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x2000000){ @@ -276,7 +464,7 @@ void sub_0x67AA18(int* source_bits_pointer, int* dest_bits_pointer, rct_drawpixe int ebx = RCT2_GLOBAL(0xEDF808, uint32); ebx = RCT2_GLOBAL(ebx * 2 + source_bits_pointer,uint16); - int ebp = dest_bits_pointer; + int ebp = (int)dest_bits_pointer; ebx += (int)source_bits_pointer; StartLoop: @@ -303,7 +491,7 @@ StartLoop: edx &= 0xFFFF0000; } edx += cx; - edx -= RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16); + edx -= RCT2_GLOBAL(0x9ABDA8, sint16); if (edx > 0){ cx -= edx; if (cx <= 0){ @@ -328,10 +516,10 @@ StartLoop: } TestLoop: if (!(RCT2_GLOBAL(0x9ABDB4, uint8) & 0x80)) goto StartLoop; - edx = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16); + edx = RCT2_GLOBAL(0x9ABDB0, sint16); ebp += edx; - RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16)--; - if (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16))goto StartLoop; + RCT2_GLOBAL(0x9ABDAC, sint16)--; + if (RCT2_GLOBAL(0x9ABDAC, sint16))goto StartLoop; } @@ -340,75 +528,61 @@ TestLoop: * This function readies all the global vars for copying the sprite data onto the screen * I think its only used for bitmaps onto buttons but i am not sure. */ -void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, int y){ +void sub_0x67A934(rct_drawpixelinfo *dpi, int x, int y){ + int _edi = (int)dpi; + sint16 translated_x = x, translated_y = y; char* bits_pointer; - bits_pointer = dest_dpi->bits; + bits_pointer = dpi->bits; + translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16) - dpi->y; RCT2_GLOBAL(0xEDF808, uint32) = 0; + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) = RCT2_GLOBAL(0x9E3D0E, sint16); - int start_y, end_y; - start_y = y + source_g1->y_offset - dest_dpi->y; - - //If the start position is negative reset to zero - if (start_y < 0){ - //Create the end point within the drawing area - end_y = source_g1->height + start_y; - //If the end point is now <= 0 no need to draw - if (end_y <= 0)return; - - RCT2_GLOBAL(0xEDF808, sint16) -= start_y; - start_y = 0; + if (translated_y < 0) + { + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) += translated_y; + if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) <= 0)return; + RCT2_GLOBAL(0xEDF808, sint16) -= translated_y; + translated_y = 0; } else{ - end_y = source_g1->height; - //Move the pointer to the correct starting y location - bits_pointer += (dest_dpi->width + dest_dpi->pitch)*start_y; + bits_pointer += (dpi->width + dpi->pitch)*translated_y; } - int height = start_y + end_y; - //If the image is taller than the drawing area - if (height > dest_dpi->height){ - //Make the end within the drawing area - end_y -= height - dest_dpi->height; - //If the end is now <=0 then there is nothing to draw - if (end_y <= 0)return; + translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) - dpi->height; + if (translated_y > 0){ + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) -= translated_y; + if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) <= 0)return; } - + RCT2_GLOBAL(0xEDF80C, uint32) = 0; - int start_x, end_x; - start_x = x + source_g1->x_offset - dest_dpi->x; - - //If the start position is negative reset to zero - if (start_x < 0){ - //Create the end point within the drawing area - end_x = source_g1->width + start_x; - //If the end point is now <= 0 no need to draw - if (end_x <= 0)return; + translated_x += RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_1, uint16) - dpi->x; - RCT2_GLOBAL(0xEDF80C, sint16) -= start_x; - start_x = 0; + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) = RCT2_GLOBAL(0x9E3D0C, sint16); + if (translated_x < 0){ + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) += translated_x; + if (RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) <= 0)return; + RCT2_GLOBAL(0xEDF80C, sint16) -= translated_x; + translated_x = 0; } else{ - end_x = source_g1->width; - //Increment the pointer to our start location - bits_pointer += start_x; + bits_pointer += translated_x; + } + translated_x += RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16); + translated_x -= dpi->width; + if (translated_x > 0){ + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) -= translated_x; + if (RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) <= 0)return; } - int width = start_x + end_x; - //If the image is wider than the drawing area - if (width > dest_dpi->width){ - //Make the end within drawing area - end_x -= width - dest_dpi->width; - //If the end is now <=0 then there is nothing to draw - if (end_x <= 0)return; - } + RCT2_GLOBAL(0x9ABDB0, uint16) = dpi->width + dpi->pitch; - RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16) = dest_dpi->width + dest_dpi->pitch; - RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = end_x; - RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = end_y; - //sub_0x67AA18(RCT2_GLOBAL(0x9E3D08, int*), (int*)bits_pointer, dest_dpi); - RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, source_g1->offset, bits_pointer, dest_dpi); + // I dont think it uses ecx, edx but just in case + //esi is the source and bits_pointer is the destination + //sub_0x67AA18(RCT2_GLOBAL(0x9E3D08, int*), (int*)bits_pointer, dpi); + + RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, translated_x, translated_y, RCT2_GLOBAL(0x9E3D08, uint32), (int)bits_pointer, (int)dpi); } /** @@ -423,7 +597,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); //return; - int eax = 0, ebx = image_id, ecx = x, edx = y, esi = 0, edi = dpi, ebp = 0; + int eax = 0, ebx = image_id, ecx = x, edx = y, esi = 0, edi = (int)dpi, ebp = 0; RCT2_GLOBAL(0x00EDF81C, uint32) = image_id & 0xE0000000; eax = (image_id >> 26) & 0x7; @@ -431,16 +605,17 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x009E3CDC, uint32) = RCT2_GLOBAL(0x009E3CE4 + eax * 4, uint32); if (((image_id)& 0xE0000000) && !(image_id & (1 << 31))) { - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); // return;//jump into 0x67a445 } else if (((image_id)& 0xE0000000) && !(image_id & (1 << 29))){ - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + char* find = "FINDMEDUNCAN"; + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); return;//jump into 0x67a361 } else if ((image_id)& 0xE0000000){ - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); /* eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; @@ -489,38 +664,34 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } eax = *((uint32*)ebx + 2); ebp = *((uint32*)ebx + 3); - rct_g1_element* g1_source = (rct_g1_element*)ebx; - //This is a rct2_drawpixelinfo struct RCT2_GLOBAL(0x9E3D08, uint32) = *((uint32*)ebx); //offset to g1 bits? RCT2_GLOBAL(0x9E3D0C, uint32) = *((uint32*)ebx + 1); RCT2_GLOBAL(0x9E3D10, uint32) = *((uint32*)ebx + 2); //X-Y related unsigned? sets RCT2_X_RELATED_GLOBAL_1 and Y RCT2_GLOBAL(0x9E3D14, uint32) = *((uint32*)ebx + 3); - if (RCT2_GLOBAL(0x9E3D14, uint32) & (1 << 2)){ //Title screen bitmaps //RCT2_CALLPROC_X(0x0067A934, eax, ebx, x, y, 0, dpi, ebp); - sub_0x67A934(g1_source, dpi, x, y); + sub_0x67A934(dpi, x, y); return; } - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); - return; + //dpi on stack int translated_x, translated_y; char* bits_pointer; - ebp = dpi; + ebp = (int)dpi; esi = RCT2_GLOBAL(0x9E3D08, uint32); RCT2_GLOBAL(0x9E3CE0, uint32) = 0; bits_pointer = dpi->bits; - RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = RCT2_GLOBAL(0x9E3D0E, sint16); + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) = RCT2_GLOBAL(0x9E3D0E, sint16); translated_y = y + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16) - dpi->y; if (translated_y < 0){ - RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) += translated_y; - if (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) <= 0){ + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) += translated_y; + if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) <= 0){ return; } translated_y = -translated_y; @@ -532,61 +703,61 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) bits_pointer += eax; } - translated_y += RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) - dpi->height;; + translated_y += RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) - dpi->height;; if (translated_y > 0){ - RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) -= translated_y; - if (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) <= 0) + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) -= translated_y; + if (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, sint16) <=0) { return; } } - RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = RCT2_GLOBAL(0x9E3D0C, sint16); + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) = RCT2_GLOBAL(0x9E3D0C, sint16); eax = dpi->width + dpi->pitch - RCT2_GLOBAL(0x9E3D0C, sint16); RCT2_GLOBAL(0x9ABDAE, uint16) = 0; - RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16) = dpi->width + dpi->pitch - RCT2_GLOBAL(0x9E3D0C, sint16); + RCT2_GLOBAL(0x9ABDB0, sint16) = dpi->width + dpi->pitch - RCT2_GLOBAL(0x9E3D0C, sint16); translated_x = x + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_1, uint16) - dpi->x; if (translated_x < 0){ - RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) += translated_x; - if (RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) <= 0){ + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) += translated_x; + if (RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) <= 0){ return; } translated_x -= RCT2_GLOBAL(0x9ABDAE, sint16); esi -= translated_x; RCT2_GLOBAL(0x9E3CE0, sint32) -= translated_x; - RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16) -= translated_x; + RCT2_GLOBAL(0x9ABDB0, sint16) -= translated_x; translated_x = 0; } bits_pointer += translated_x; - translated_x += RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) - dpi->width; + translated_x += RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) - dpi->width; if (translated_x > 0){ - RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) -= translated_x; - if (RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) <= 0){ + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) -= translated_x; + if (RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_2, sint16) <= 0){ return; } RCT2_GLOBAL(0x9ABDAE, sint16) += translated_x; - RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16) += translated_x; + RCT2_GLOBAL(0x9ABDB0, sint16) += translated_x; } if (!(RCT2_GLOBAL(0x9E3D14, uint16) & 0x02)){ - eax = (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, uint8)) << 8; + eax = (RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_2, uint8)) << 8; edx = RCT2_GLOBAL(0x9ABDAE, sint16); - ebp = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16); + ebp = RCT2_GLOBAL(0x9ABDB0, sint16); ebx = RCT2_GLOBAL(0xEDF81C, uint32); ecx = 0xFFFF&translated_x; //ebx, esi, edi, ah used in 0x67a690 - RCT2_CALLPROC_X_EBPSAFE(0x67A690, eax, ebx, ecx, edx, esi, bits_pointer, ebp); + RCT2_CALLPROC_X_EBPSAFE(0x67A690, eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp); return; } //0x67A60A - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); esi -= RCT2_GLOBAL(0x9E3D08, sint32); return; } From 1aa3bc0232017fb241808994dcd054be4807e92f Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Thu, 15 May 2014 22:15:29 +0100 Subject: [PATCH 28/99] Started clean up of buffer interaction code.Still a little buggy --- src/gfx.c | 90 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 99c35a463e..11c380dfc7 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -274,22 +274,32 @@ void sub_0x67AA18(int* source_bits_pointer, int* dest_bits_pointer, rct_drawpixe return; //0x67AFD8 } - int ebx = RCT2_GLOBAL(0xEDF808, uint32); - ebx = RCT2_GLOBAL(ebx * 2 + source_bits_pointer,uint16); - int ebp = dest_bits_pointer; - ebx += (int)source_bits_pointer; - + int ebx = RCT2_GLOBAL(0xEDF808, uint32); //G1 y start location + ebx = RCT2_GLOBAL(ebx * 2 + source_bits_pointer, uint16);//? x2?? would have though move to width*ebx + //Possibly more information is stored about each horizontal line + //maybe an x offset with each one? + int ebp = (int)dest_bits_pointer; + ebx += (int)source_bits_pointer; //Move to the correct y location? + int ecx = 0; + int edx = 0; StartLoop: - ebx = ebx; - int cx = RCT2_GLOBAL(ebx, uint16); - RCT2_GLOBAL(0x9ABDB4, uint8) = cx & 0xFF; - ebx += 2; + edx = 0; + int cx = RCT2_GLOBAL(ebx, uint16); //Maybe X start stop offsets + int cl = cx & 0xff; + RCT2_GLOBAL(0x9ABDB4, uint8) = cl; //start offset + + ebx += 2;//skip the extra offset info cx &= 0xFF7F; + cl &= 0x7F; //?? int esi = ebx; - int edx = (cx & 0xFF00) >> 8; - ebx += cx; - edx -= RCT2_GLOBAL(0xEDF80C, sint32); + int dl = (cx & 0xFF00) >> 8; + int ch = 0; + cx = cl; + ebx += cx;//?? + edx = dl; + edx -= RCT2_GLOBAL(0xEDF80C, sint32);//g1 x start location int edi = ebp; + //Looks like checking line is with vision if (edx > 0){ edi += edx; } @@ -302,39 +312,48 @@ StartLoop: } edx &= 0xFFFF0000; } - edx += cx; - edx -= RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16); - if (edx > 0){ - cx -= edx; + int dx = edx&0xFFFF; + dx += cx; + dx -= RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16); + if (dx > 0){ + cx -= dx; if (cx <= 0){ goto TestLoop; //jump to 0x67AA97 } } - if (cx & 1){ - cx >>= 1; + + for (; cx > 0; cx--, edi++, esi++){ RCT2_GLOBAL(edi, uint8) = RCT2_GLOBAL(esi, uint8); } - else cx >>= 1; + + /*if (cx & 1){ + RCT2_GLOBAL(edi, uint8) = RCT2_GLOBAL(esi, uint8); + edi+=1; + esi+=1; + } + cx >>= 1; if (cx & 1){ - cx >>= 1; RCT2_GLOBAL(edi, uint16) = RCT2_GLOBAL(esi, uint16); + edi+=2; + esi+=2; } - else cx >>= 1; + cx >>= 1; - for (int i = cx; i > 0; --i, edi++, esi++){ - RCT2_GLOBAL(edi, uint16) = RCT2_GLOBAL(esi, uint16); - } + for (int i = cx; i > 0; i-=4, edi+=4, esi+=4){ + RCT2_GLOBAL(edi, uint32) = RCT2_GLOBAL(esi, uint32); + }*/ TestLoop: if (!(RCT2_GLOBAL(0x9ABDB4, uint8) & 0x80)) goto StartLoop; - edx = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16); + edx = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16); ebp += edx; RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16)--; if (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16))goto StartLoop; } + /* * rct2: 0x67A934 title screen bitmaps on buttons * This function readies all the global vars for copying the sprite data onto the screen @@ -407,8 +426,9 @@ void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16) = dest_dpi->width + dest_dpi->pitch; RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = end_x; RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = end_y; - //sub_0x67AA18(RCT2_GLOBAL(0x9E3D08, int*), (int*)bits_pointer, dest_dpi); - RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, source_g1->offset, bits_pointer, dest_dpi); + char* find = "FINDMEDUNCAN"; + sub_0x67AA18(RCT2_GLOBAL(0x9E3D08, int*), (int*)bits_pointer, dest_dpi); + //RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, source_g1->offset, bits_pointer, dest_dpi); } /** @@ -423,7 +443,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); //return; - int eax = 0, ebx = image_id, ecx = x, edx = y, esi = 0, edi = dpi, ebp = 0; + int eax = 0, ebx = image_id, ecx = x, edx = y, esi = 0, edi = (int)dpi, ebp = 0; RCT2_GLOBAL(0x00EDF81C, uint32) = image_id & 0xE0000000; eax = (image_id >> 26) & 0x7; @@ -431,16 +451,16 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x009E3CDC, uint32) = RCT2_GLOBAL(0x009E3CE4 + eax * 4, uint32); if (((image_id)& 0xE0000000) && !(image_id & (1 << 31))) { - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); // return;//jump into 0x67a445 } else if (((image_id)& 0xE0000000) && !(image_id & (1 << 29))){ - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); return;//jump into 0x67a361 } else if ((image_id)& 0xE0000000){ - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); /* eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; @@ -502,13 +522,13 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) sub_0x67A934(g1_source, dpi, x, y); return; } - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); return; //dpi on stack int translated_x, translated_y; char* bits_pointer; - ebp = dpi; + ebp = (int)dpi; esi = RCT2_GLOBAL(0x9E3D08, uint32); RCT2_GLOBAL(0x9E3CE0, uint32) = 0; bits_pointer = dpi->bits; @@ -582,11 +602,11 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebx = RCT2_GLOBAL(0xEDF81C, uint32); ecx = 0xFFFF&translated_x; //ebx, esi, edi, ah used in 0x67a690 - RCT2_CALLPROC_X_EBPSAFE(0x67A690, eax, ebx, ecx, edx, esi, bits_pointer, ebp); + RCT2_CALLPROC_X_EBPSAFE(0x67A690, eax, ebx, ecx, edx, esi,(int) bits_pointer, ebp); return; } //0x67A60A - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); esi -= RCT2_GLOBAL(0x9E3D08, sint32); return; } From 088ac32da35b2d763bf76e111fd284f9dc6969c7 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Thu, 15 May 2014 21:29:29 +0200 Subject: [PATCH 29/99] Add gfx_fill_rect Still a little buggy for transparent colours --- src/gfx.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/src/gfx.c b/src/gfx.c index 941ed5e7f1..11b97b6cab 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -445,7 +445,106 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot */ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short right, short bottom, int colour, short _si) { - RCT2_CALLPROC_X(0x006E6F81, left, right, top, bottom, _si, (int)dpi, colour); + int colour_, colour1, colour2, colour3; + uint16 ax, bx, si2; + uint8 cl; + + if ((colour & 0x180)) { + // jnz loc_6E719A + if (!(colour & 0x100)) { + colour = colour & 0x7F; + } else { + colour = RCT2_ADDRESS(0x009DEDF4,uint8)[colour]; + } + + colour = colour & 0x2000000; + + if (_si, 8) { + gfx_fill_rect(dpi, left, top, bottom, right, colour); + return; + } else if (_si & 0x20) { + gfx_fill_rect(dpi, left, top, left, bottom, colour + 1); + gfx_fill_rect(dpi, left, top, right, top, colour + 1); + gfx_fill_rect(dpi, right, top, right, bottom, colour + 2); + gfx_fill_rect(dpi, left, bottom, right, bottom, colour + 2); + + if (!(_si & 0x10)) { + gfx_fill_rect(dpi, left+1, top+1, right-1, bottom-1, colour); + } + } else { + gfx_fill_rect(dpi, left, top, left, bottom, colour + 2); + gfx_fill_rect(dpi, left, top, right, top, colour + 2); + gfx_fill_rect(dpi, right, top, right, bottom, colour + 1); + gfx_fill_rect(dpi, left, bottom, right, bottom, colour + 1); + + if (!(_si & 0x10)) { + gfx_fill_rect(dpi, left+1, top+1, right-1, bottom-1, colour); + } + } + } else { + if (_si & 0x80) { + ax = RCT2_ADDRESS(0x0141FC46, uint8)[colour * 8]; + bx = RCT2_ADDRESS(0x0141FC48, uint8)[colour * 8]; + cl = RCT2_ADDRESS(0x0141FC4A, uint8)[colour * 8]; + } else { + ax = RCT2_ADDRESS(0x0141FC47, uint8)[colour * 8]; + bx = RCT2_ADDRESS(0x0141FC49, uint8)[colour * 8]; + cl = RCT2_ADDRESS(0x0141FC4B, uint8)[colour * 8]; + } + colour_ = ((ax & 0xFF) << 12) | (cl << 8) | bx; + + colour2 = ax & 0xFF; + colour1 = cl; + si2 = (ax & 0xFF00) >> 8; + + if (!(_si & 8)) { + if (!(_si & 0x20)) { + + // Draw outline of box, with top and left in one colour + // and bottom and right in the other + gfx_fill_rect(dpi, left, top, left, bottom - 1, colour1); + gfx_fill_rect(dpi, left + 1, top, right - 1, top, colour1); + gfx_fill_rect(dpi, right, top, right, bottom - 1, colour2); + gfx_fill_rect(dpi, left, bottom, right, bottom, colour2); + + if (!(_si & 0x10)) { + if (_si & 0x04) { + colour3 = RCT2_ADDRESS(0x0141FC49, uint8)[0]; + } else { + colour3 = colour_ & 0xFF; + } + gfx_fill_rect(dpi, left+1, top+1, right-1, bottom-1, colour3); + } + + } else { + // jnz loc_6E70AC + // movzx ebp, [esp+10h+var_10] + // movzx ebp, [esp+10h+var_10] + gfx_fill_rect(dpi, left, top, left, bottom, colour2); + gfx_fill_rect(dpi, left + 1, top, right, top, colour2); + + // movzx ebp, byte ptr [esp+10h+var_E+2] + gfx_fill_rect(dpi, right, top + 1, right, bottom - 1, colour1); + gfx_fill_rect(dpi, left + 1, bottom, right, bottom, colour1); + + if (!(_si & 0x10)) { + if (_si & 0x40) { + colour3 = colour_ & 0x00FF; + } else { + if (_si & 0x04) { + colour3 = RCT2_ADDRESS(0x0141FC49, uint8)[0]; + } else { + colour3 = colour_ & 0xFF; + } + colour3 = colour_ & 0xFF00; + } + gfx_fill_rect(dpi, left+1, top+1, right-1, bottom-1, colour3); + } + } + } else { + gfx_fill_rect(dpi, left, top, right, bottom, colour); + } + } } #define RCT2_Y_RELATED_GLOBAL_1 0x9E3D12 //uint16 From 67980e2f5f8160e96d8360748106e875086f5533 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Thu, 15 May 2014 22:13:27 +0200 Subject: [PATCH 30/99] Fix bug with transparency --- src/gfx.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 11b97b6cab..a91b3c8c30 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -451,17 +451,16 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri if ((colour & 0x180)) { // jnz loc_6E719A - if (!(colour & 0x100)) { + if (colour & 0x100) { colour = colour & 0x7F; } else { colour = RCT2_ADDRESS(0x009DEDF4,uint8)[colour]; } - colour = colour & 0x2000000; + colour = colour | 0x2000000; - if (_si, 8) { + if (_si & 8) { gfx_fill_rect(dpi, left, top, bottom, right, colour); - return; } else if (_si & 0x20) { gfx_fill_rect(dpi, left, top, left, bottom, colour + 1); gfx_fill_rect(dpi, left, top, right, top, colour + 1); From 4fae966855841d90214fdb95ac5cbccfd077122f Mon Sep 17 00:00:00 2001 From: ZedThree Date: Fri, 16 May 2014 19:01:25 +0200 Subject: [PATCH 31/99] Bug fix: pressed buttons not the right colour --- src/gfx.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index a91b3c8c30..fdc4f9318b 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -533,15 +533,14 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri if (_si & 0x04) { colour3 = RCT2_ADDRESS(0x0141FC49, uint8)[0]; } else { - colour3 = colour_ & 0xFF; + colour3 = RCT2_ADDRESS(0x0141FC4A, uint8)[colour * 8]; } - colour3 = colour_ & 0xFF00; } gfx_fill_rect(dpi, left+1, top+1, right-1, bottom-1, colour3); } } } else { - gfx_fill_rect(dpi, left, top, right, bottom, colour); + gfx_fill_rect(dpi, left, top, right, bottom, colour_); } } } From e209e370be26263a06a7fc3cb99309f0fc685025 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Fri, 16 May 2014 19:49:52 +0200 Subject: [PATCH 32/99] Tidy up gfx_fill_rect_inset Give names to flags and different tones --- src/gfx.c | 117 +++++++++++++++++++++++++----------------------------- 1 file changed, 53 insertions(+), 64 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index fdc4f9318b..3dc0eeba5b 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -433,7 +433,8 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot } /** - * + * Draw a rectangle, with optional border or fill + * * rct2: 0x006E6F81 * dpi (edi) * left (ax) @@ -441,106 +442,94 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot * right (bx) * bottom (dx) * colour (ebp) - * _si (si) + * flags (si) */ -void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short right, short bottom, int colour, short _si) +void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short right, short bottom, int colour, short flags) { - int colour_, colour1, colour2, colour3; - uint16 ax, bx, si2; - uint8 cl; + uint8 shadow, fill, hilight; - if ((colour & 0x180)) { - // jnz loc_6E719A + // Flags + int no_border, no_fill, pressed; + + no_border = 8; + no_fill = 0x10; + pressed = 0x20; + + if (colour & 0x180) { if (colour & 0x100) { colour = colour & 0x7F; } else { colour = RCT2_ADDRESS(0x009DEDF4,uint8)[colour]; } - colour = colour | 0x2000000; + colour = colour | 0x2000000; //Transparent - if (_si & 8) { + if (flags & no_border) { gfx_fill_rect(dpi, left, top, bottom, right, colour); - } else if (_si & 0x20) { + } else if (flags & pressed) { + // Draw outline of box gfx_fill_rect(dpi, left, top, left, bottom, colour + 1); gfx_fill_rect(dpi, left, top, right, top, colour + 1); gfx_fill_rect(dpi, right, top, right, bottom, colour + 2); gfx_fill_rect(dpi, left, bottom, right, bottom, colour + 2); - if (!(_si & 0x10)) { + if (!(flags & no_fill)) { gfx_fill_rect(dpi, left+1, top+1, right-1, bottom-1, colour); } } else { + // Draw outline of box gfx_fill_rect(dpi, left, top, left, bottom, colour + 2); gfx_fill_rect(dpi, left, top, right, top, colour + 2); gfx_fill_rect(dpi, right, top, right, bottom, colour + 1); gfx_fill_rect(dpi, left, bottom, right, bottom, colour + 1); - if (!(_si & 0x10)) { + if (!(flags & no_fill)) { gfx_fill_rect(dpi, left+1, top+1, right-1, bottom-1, colour); } } } else { - if (_si & 0x80) { - ax = RCT2_ADDRESS(0x0141FC46, uint8)[colour * 8]; - bx = RCT2_ADDRESS(0x0141FC48, uint8)[colour * 8]; - cl = RCT2_ADDRESS(0x0141FC4A, uint8)[colour * 8]; + if (flags & 0x80) { + shadow = RCT2_ADDRESS(0x0141FC46, uint8)[colour * 8]; + fill = RCT2_ADDRESS(0x0141FC48, uint8)[colour * 8]; + hilight = RCT2_ADDRESS(0x0141FC4A, uint8)[colour * 8]; } else { - ax = RCT2_ADDRESS(0x0141FC47, uint8)[colour * 8]; - bx = RCT2_ADDRESS(0x0141FC49, uint8)[colour * 8]; - cl = RCT2_ADDRESS(0x0141FC4B, uint8)[colour * 8]; + shadow = RCT2_ADDRESS(0x0141FC47, uint8)[colour * 8]; + fill = RCT2_ADDRESS(0x0141FC49, uint8)[colour * 8]; + hilight = RCT2_ADDRESS(0x0141FC4B, uint8)[colour * 8]; } - colour_ = ((ax & 0xFF) << 12) | (cl << 8) | bx; - colour2 = ax & 0xFF; - colour1 = cl; - si2 = (ax & 0xFF00) >> 8; + if (flags & no_border) { + gfx_fill_rect(dpi, left, top, right, bottom, fill); + } else if (flags & pressed) { + // Draw outline of box + gfx_fill_rect(dpi, left, top, left, bottom, shadow); + gfx_fill_rect(dpi, left + 1, top, right, top, shadow); + gfx_fill_rect(dpi, right, top + 1, right, bottom - 1, hilight); + gfx_fill_rect(dpi, left + 1, bottom, right, bottom, hilight); - if (!(_si & 8)) { - if (!(_si & 0x20)) { - - // Draw outline of box, with top and left in one colour - // and bottom and right in the other - gfx_fill_rect(dpi, left, top, left, bottom - 1, colour1); - gfx_fill_rect(dpi, left + 1, top, right - 1, top, colour1); - gfx_fill_rect(dpi, right, top, right, bottom - 1, colour2); - gfx_fill_rect(dpi, left, bottom, right, bottom, colour2); - - if (!(_si & 0x10)) { - if (_si & 0x04) { - colour3 = RCT2_ADDRESS(0x0141FC49, uint8)[0]; + if (!(flags & no_fill)) { + if (!(flags & 0x40)) { + if (flags & 0x04) { + fill = RCT2_ADDRESS(0x0141FC49, uint8)[0]; } else { - colour3 = colour_ & 0xFF; + fill = RCT2_ADDRESS(0x0141FC4A, uint8)[colour * 8]; } - gfx_fill_rect(dpi, left+1, top+1, right-1, bottom-1, colour3); - } - - } else { - // jnz loc_6E70AC - // movzx ebp, [esp+10h+var_10] - // movzx ebp, [esp+10h+var_10] - gfx_fill_rect(dpi, left, top, left, bottom, colour2); - gfx_fill_rect(dpi, left + 1, top, right, top, colour2); - - // movzx ebp, byte ptr [esp+10h+var_E+2] - gfx_fill_rect(dpi, right, top + 1, right, bottom - 1, colour1); - gfx_fill_rect(dpi, left + 1, bottom, right, bottom, colour1); - - if (!(_si & 0x10)) { - if (_si & 0x40) { - colour3 = colour_ & 0x00FF; - } else { - if (_si & 0x04) { - colour3 = RCT2_ADDRESS(0x0141FC49, uint8)[0]; - } else { - colour3 = RCT2_ADDRESS(0x0141FC4A, uint8)[colour * 8]; - } - } - gfx_fill_rect(dpi, left+1, top+1, right-1, bottom-1, colour3); } + gfx_fill_rect(dpi, left+1, top+1, right-1, bottom-1, fill); } } else { - gfx_fill_rect(dpi, left, top, right, bottom, colour_); + // Draw outline of box + gfx_fill_rect(dpi, left, top, left, bottom - 1, hilight); + gfx_fill_rect(dpi, left + 1, top, right - 1, top, hilight); + gfx_fill_rect(dpi, right, top, right, bottom - 1, shadow); + gfx_fill_rect(dpi, left, bottom, right, bottom, shadow); + + if (!(flags & no_fill)) { + if (flags & 0x04) { + fill = RCT2_ADDRESS(0x0141FC49, uint8)[0]; + } + gfx_fill_rect(dpi, left+1, top+1, right-1, bottom-1, fill); + } } } } From 001ccc3945aa8f891d5eee6cc0c77eebe7352a3f Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 16 May 2014 19:06:35 +0100 Subject: [PATCH 33/99] Started cleanup of code introduced a bug at some point --- src/gfx.c | 77 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 13 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 11c380dfc7..a0aa6ebe8d 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -265,7 +265,8 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri #define RCT2_X_END_POINT_GLOBAL 0x9ABDA8 //sint16 #define RCT2_DPI_LINE_LENGTH_GLOBAL 0x9ABDB0 //uint16 width+pitch -void sub_0x67AA18(int* source_bits_pointer, int* dest_bits_pointer, rct_drawpixelinfo *dpi){ +void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpixelinfo *dpi, uint16 g1_y_start, uint16 g1_y_end, uint16 g1_x_start, uint16 g1_x_end){ + //Image_id if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x2000000){ return; //0x67AAB3 } @@ -273,21 +274,60 @@ void sub_0x67AA18(int* source_bits_pointer, int* dest_bits_pointer, rct_drawpixe if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x4000000){ return; //0x67AFD8 } + + uint16 offset_to_first_line = *(uint16*)(RCT2_GLOBAL(0xEDF808, uint32) * 2 + (uint32)source_bits_pointer); + //This will now point to the first line + char* source_pointer = (char*)((uint32)source_bits_pointer + offset_to_first_line); + char* dest_pointer = dest_bits_pointer; + char* next_dest_pointer = dest_pointer; int ebx = RCT2_GLOBAL(0xEDF808, uint32); //G1 y start location - ebx = RCT2_GLOBAL(ebx * 2 + source_bits_pointer, uint16);//? x2?? would have though move to width*ebx + ebx = RCT2_GLOBAL(ebx * 2 + (uint32)source_bits_pointer, uint16);//? x2?? would have though move to width*ebx //Possibly more information is stored about each horizontal line //maybe an x offset with each one? - int ebp = (int)dest_bits_pointer; - ebx += (int)source_bits_pointer; //Move to the correct y location? + int ebp = (uint32)dest_bits_pointer; + ebx += (uint32)source_bits_pointer; //Move to the correct y location? int ecx = 0; int edx = 0; StartLoop: edx = 0; + uint8 gap_size = *source_pointer++; + uint8 no_pixels = *source_pointer++; + uint8 last_data_line = gap_size & 0x80; + //Clear the last data line bit + gap_size &= 0x7f; + //Move this to the end + char* next_source_pointer = source_pointer + gap_size; + + + int x_start = (int)no_pixels - (int)g1_x_start; + + if (x_start > 0){ + dest_pointer += x_start; + } + else{ + source_pointer -= x_start; + no_pixels += x_start; + if (no_pixels <= 0) goto TestLoop; + x_start = 0; + } + + int x_end = x_start + no_pixels - g1_x_end; + + if (x_end > 0){ + no_pixels -= x_end; + if (no_pixels <= 0) goto TestLoop; + } + + for (; no_pixels > 0; no_pixels--, dest_pointer++, source_pointer++){ + *dest_pointer = *source_pointer; + } + goto TestLoop; + int cx = RCT2_GLOBAL(ebx, uint16); //Maybe X start stop offsets int cl = cx & 0xff; RCT2_GLOBAL(0x9ABDB4, uint8) = cl; //start offset - + ebx += 2;//skip the extra offset info cx &= 0xFF7F; cl &= 0x7F; //?? @@ -345,6 +385,14 @@ StartLoop: RCT2_GLOBAL(edi, uint32) = RCT2_GLOBAL(esi, uint32); }*/ TestLoop: + source_pointer = next_source_pointer; + if (!last_data_line)goto StartLoop; + next_dest_pointer += dpi->width + dpi->pitch; + dest_pointer = next_dest_pointer; + g1_y_end--; + if (g1_y_end)goto StartLoop; + return; + if (!(RCT2_GLOBAL(0x9ABDB4, uint8) & 0x80)) goto StartLoop; edx = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16); ebp += edx; @@ -360,11 +408,11 @@ TestLoop: * I think its only used for bitmaps onto buttons but i am not sure. */ void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, int y){ - + uint16 g1_y_start, g1_x_start; char* bits_pointer; - bits_pointer = dest_dpi->bits; - RCT2_GLOBAL(0xEDF808, uint32) = 0; + bits_pointer = dest_dpi->bits; + g1_y_start = 0; int start_y, end_y; start_y = y + source_g1->y_offset - dest_dpi->y; @@ -376,7 +424,7 @@ void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, //If the end point is now <= 0 no need to draw if (end_y <= 0)return; - RCT2_GLOBAL(0xEDF808, sint16) -= start_y; + g1_y_start -= start_y; start_y = 0; } else{ @@ -394,8 +442,9 @@ void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, if (end_y <= 0)return; } - RCT2_GLOBAL(0xEDF80C, uint32) = 0; + int start_x, end_x; + g1_x_start = 0; start_x = x + source_g1->x_offset - dest_dpi->x; //If the start position is negative reset to zero @@ -405,7 +454,7 @@ void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, //If the end point is now <= 0 no need to draw if (end_x <= 0)return; - RCT2_GLOBAL(0xEDF80C, sint16) -= start_x; + g1_x_start -= start_x; start_x = 0; } else{ @@ -426,8 +475,10 @@ void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16) = dest_dpi->width + dest_dpi->pitch; RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = end_x; RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = end_y; - char* find = "FINDMEDUNCAN"; - sub_0x67AA18(RCT2_GLOBAL(0x9E3D08, int*), (int*)bits_pointer, dest_dpi); + RCT2_GLOBAL(0xEDF808, uint16) = g1_y_start; + RCT2_GLOBAL(0xEDF80C, uint16) = g1_x_start; + + sub_0x67AA18(source_g1->offset, bits_pointer, dest_dpi, g1_y_start, end_y, g1_x_start, end_x); //RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, source_g1->offset, bits_pointer, dest_dpi); } From 5eb445857b6fb3f850407bcfe9b026eb04e77c21 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sat, 17 May 2014 17:40:55 +0100 Subject: [PATCH 34/99] Trying to find bug in new version of code --- src/gfx.c | 92 +++++++++++++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 51 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index a0aa6ebe8d..65b818b01e 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -275,11 +275,11 @@ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpi return; //0x67AFD8 } - uint16 offset_to_first_line = *(uint16*)(RCT2_GLOBAL(0xEDF808, uint32) * 2 + (uint32)source_bits_pointer); + uint16 offset_to_first_line = *(uint16*)(g1_y_start*2 + (uint32)source_bits_pointer); //This will now point to the first line char* source_pointer = (char*)((uint32)source_bits_pointer + offset_to_first_line); char* dest_pointer = dest_bits_pointer; - char* next_dest_pointer = dest_pointer; + char* next_dest_pointer = dest_bits_pointer; int ebx = RCT2_GLOBAL(0xEDF808, uint32); //G1 y start location ebx = RCT2_GLOBAL(ebx * 2 + (uint32)source_bits_pointer, uint16);//? x2?? would have though move to width*ebx @@ -291,43 +291,18 @@ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpi int edx = 0; StartLoop: edx = 0; - uint8 gap_size = *source_pointer++; uint8 no_pixels = *source_pointer++; - uint8 last_data_line = gap_size & 0x80; + uint8 gap_size = *source_pointer++; + uint8 last_data_line = no_pixels & 0x80; //Clear the last data line bit - gap_size &= 0x7f; + no_pixels &= 0x7f; //Move this to the end - char* next_source_pointer = source_pointer + gap_size; + char* next_source_pointer = source_pointer + no_pixels; - - int x_start = (int)no_pixels - (int)g1_x_start; - - if (x_start > 0){ - dest_pointer += x_start; - } - else{ - source_pointer -= x_start; - no_pixels += x_start; - if (no_pixels <= 0) goto TestLoop; - x_start = 0; - } - - int x_end = x_start + no_pixels - g1_x_end; - - if (x_end > 0){ - no_pixels -= x_end; - if (no_pixels <= 0) goto TestLoop; - } - - for (; no_pixels > 0; no_pixels--, dest_pointer++, source_pointer++){ - *dest_pointer = *source_pointer; - } - goto TestLoop; - int cx = RCT2_GLOBAL(ebx, uint16); //Maybe X start stop offsets int cl = cx & 0xff; RCT2_GLOBAL(0x9ABDB4, uint8) = cl; //start offset - + ebx += 2;//skip the extra offset info cx &= 0xFF7F; cl &= 0x7F; //?? @@ -339,30 +314,41 @@ StartLoop: edx = dl; edx -= RCT2_GLOBAL(0xEDF80C, sint32);//g1 x start location int edi = ebp; - //Looks like checking line is with vision - if (edx > 0){ + + int x_start = (int)gap_size - (int)g1_x_start; + + if (edx > 0){ //edx x_start edi += edx; + dest_pointer += x_start; } else{ + source_pointer -= x_start; + no_pixels += x_start; + esi -= edx; cx += edx & 0xFFFF; - if (cx <= 0){ - goto TestLoop; - //jump to 0x67AA97 - } + + if (cx <= 0) goto TestLoop;//cx + x_start = 0; edx &= 0xFFFF0000; } + + int x_end = x_start + (int)no_pixels - (int)g1_x_end; int dx = edx&0xFFFF; dx += cx; dx -= RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16); - if (dx > 0){ + + if (dx > 0){ //dx x_end + no_pixels -= x_end; cx -= dx; - if (cx <= 0){ - goto TestLoop; - //jump to 0x67AA97 - } + if (cx <= 0) goto TestLoop;//cx } + for (; no_pixels > 0; no_pixels--, dest_pointer++, source_pointer++){ + *dest_pointer = *source_pointer; + } + goto TestLoop; + for (; cx > 0; cx--, edi++, esi++){ RCT2_GLOBAL(edi, uint8) = RCT2_GLOBAL(esi, uint8); } @@ -386,18 +372,22 @@ StartLoop: }*/ TestLoop: source_pointer = next_source_pointer; - if (!last_data_line)goto StartLoop; - next_dest_pointer += dpi->width + dpi->pitch; + int test = (RCT2_GLOBAL(0x9ABDB4, uint8) & 0x80); + if (!test) goto StartLoop; + //if (!last_data_line)goto StartLoop; + next_dest_pointer += (int)dpi->width + (int)dpi->pitch; dest_pointer = next_dest_pointer; - g1_y_end--; - if (g1_y_end)goto StartLoop; - return; - if (!(RCT2_GLOBAL(0x9ABDB4, uint8) & 0x80)) goto StartLoop; edx = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16); ebp += edx; - RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16)--; - if (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16))goto StartLoop; + + test = --RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16); + g1_y_end--; + if (g1_y_end)goto StartLoop;//test + return; + +// +// if (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16))goto StartLoop; } From 0fa9e6ebb9312ef583c84e7a072f1bc99af20bd7 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 18 May 2014 08:14:47 +0100 Subject: [PATCH 35/99] Finished turning the code into C removed all present bugs. Buffer draw code for basic images is done. --- src/gfx.c | 157 ++++++++++++++++++------------------------------------ 1 file changed, 51 insertions(+), 106 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 65b818b01e..a50288073e 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -277,118 +277,63 @@ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpi uint16 offset_to_first_line = *(uint16*)(g1_y_start*2 + (uint32)source_bits_pointer); //This will now point to the first line - char* source_pointer = (char*)((uint32)source_bits_pointer + offset_to_first_line); - char* dest_pointer = dest_bits_pointer; + char* next_source_pointer = (char*)((uint32)source_bits_pointer + offset_to_first_line); char* next_dest_pointer = dest_bits_pointer; - - int ebx = RCT2_GLOBAL(0xEDF808, uint32); //G1 y start location - ebx = RCT2_GLOBAL(ebx * 2 + (uint32)source_bits_pointer, uint16);//? x2?? would have though move to width*ebx - //Possibly more information is stored about each horizontal line - //maybe an x offset with each one? - int ebp = (uint32)dest_bits_pointer; - ebx += (uint32)source_bits_pointer; //Move to the correct y location? - int ecx = 0; - int edx = 0; -StartLoop: - edx = 0; - uint8 no_pixels = *source_pointer++; - uint8 gap_size = *source_pointer++; - uint8 last_data_line = no_pixels & 0x80; - //Clear the last data line bit - no_pixels &= 0x7f; - //Move this to the end - char* next_source_pointer = source_pointer + no_pixels; - int cx = RCT2_GLOBAL(ebx, uint16); //Maybe X start stop offsets - int cl = cx & 0xff; - RCT2_GLOBAL(0x9ABDB4, uint8) = cl; //start offset + //For every line in the image + for (; g1_y_end; g1_y_end--){ - ebx += 2;//skip the extra offset info - cx &= 0xFF7F; - cl &= 0x7F; //?? - int esi = ebx; - int dl = (cx & 0xFF00) >> 8; - int ch = 0; - cx = cl; - ebx += cx;//?? - edx = dl; - edx -= RCT2_GLOBAL(0xEDF80C, sint32);//g1 x start location - int edi = ebp; + uint8 last_data_line = 0; + //For every data section in the line + while (!last_data_line){ + char* source_pointer = next_source_pointer; + char* dest_pointer = next_dest_pointer; - int x_start = (int)gap_size - (int)g1_x_start; + sint8 no_pixels = *source_pointer++; + uint8 gap_size = *source_pointer++; + //The last bit in no_pixels tells you if you have reached the end of a line + last_data_line = no_pixels & 0x80; + //Clear the last data line bit so we have just the no_pixels + no_pixels &= 0x7f; + //Have our next source pointer point to the next data section + next_source_pointer = source_pointer + (int)no_pixels; - if (edx > 0){ //edx x_start - edi += edx; - dest_pointer += x_start; + //Calculates the start point of the image + int x_start = (int)gap_size - (int)g1_x_start; + + if (x_start > 0){ + //Since the start is positive + //We need to move the drawing surface to the correct position + dest_pointer += x_start; + } + else{ + //If the start is negative we require to remove part of the image. + //This is done by moving the image pointer to the correct position. + source_pointer -= x_start; + //The no_pixels will be reduced in this operation + no_pixels += x_start; + //If there are no pixels there is nothing to draw this line + if (no_pixels <= 0) continue; + //Reset the start position to zero as we have taken into account all moves + x_start = 0; + } + + int x_end = x_start + (int)no_pixels; + //If the end position is further out than the whole image + //end position then we need to shorten the line again + if (x_end > (int)g1_x_end){ + //Shorten the line + no_pixels -= x_end - (int)g1_x_end; + //If there are no pixels there is nothing to draw. + if (no_pixels <= 0) continue; + } + + //Finally after all those checks copy the image onto the drawing surface + memcpy(dest_pointer, source_pointer, no_pixels); + } + //Add a line to the drawing surface pointer + next_dest_pointer += (int)dpi->width + (int)dpi->pitch; } - else{ - source_pointer -= x_start; - no_pixels += x_start; - - esi -= edx; - cx += edx & 0xFFFF; - - if (cx <= 0) goto TestLoop;//cx - x_start = 0; - edx &= 0xFFFF0000; - } - - int x_end = x_start + (int)no_pixels - (int)g1_x_end; - int dx = edx&0xFFFF; - dx += cx; - dx -= RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16); - - if (dx > 0){ //dx x_end - no_pixels -= x_end; - cx -= dx; - if (cx <= 0) goto TestLoop;//cx - } - - for (; no_pixels > 0; no_pixels--, dest_pointer++, source_pointer++){ - *dest_pointer = *source_pointer; - } - goto TestLoop; - - for (; cx > 0; cx--, edi++, esi++){ - RCT2_GLOBAL(edi, uint8) = RCT2_GLOBAL(esi, uint8); - } - - /*if (cx & 1){ - RCT2_GLOBAL(edi, uint8) = RCT2_GLOBAL(esi, uint8); - edi+=1; - esi+=1; - } - cx >>= 1; - - if (cx & 1){ - RCT2_GLOBAL(edi, uint16) = RCT2_GLOBAL(esi, uint16); - edi+=2; - esi+=2; - } - cx >>= 1; - - for (int i = cx; i > 0; i-=4, edi+=4, esi+=4){ - RCT2_GLOBAL(edi, uint32) = RCT2_GLOBAL(esi, uint32); - }*/ -TestLoop: - source_pointer = next_source_pointer; - int test = (RCT2_GLOBAL(0x9ABDB4, uint8) & 0x80); - if (!test) goto StartLoop; - //if (!last_data_line)goto StartLoop; - next_dest_pointer += (int)dpi->width + (int)dpi->pitch; - dest_pointer = next_dest_pointer; - - edx = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16); - ebp += edx; - - test = --RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16); - g1_y_end--; - if (g1_y_end)goto StartLoop;//test - return; - -// -// if (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16))goto StartLoop; - } From 69b9c45a4035751b19052e5641c3a3679c2022e7 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 18 May 2014 09:30:13 +0100 Subject: [PATCH 36/99] Started adding in the rest of draw sprite function added in stub function for 2nd draw to buffer func --- src/gfx.c | 120 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 101 insertions(+), 19 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index a50288073e..ed64965863 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -261,17 +261,36 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri #define RCT2_Y_RELATED_GLOBAL_1 0x9E3D12 //uint16 #define RCT2_Y_END_POINT_GLOBAL 0x9ABDAC //sint16 +#define RCT2_Y_START_POINT_GLOBAL 0xEDF808 //sint16 #define RCT2_X_RELATED_GLOBAL_1 0x9E3D10 //uint16 #define RCT2_X_END_POINT_GLOBAL 0x9ABDA8 //sint16 +#define RCT2_X_START_POINT_GLOBAL 0xEDF80C //sint16 #define RCT2_DPI_LINE_LENGTH_GLOBAL 0x9ABDB0 //uint16 width+pitch +/* +* rct2: 0x67A690 very similar in function to 0x67AA18 readied images are copied onto +* buffers +*/ +void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp){ + RCT2_CALLPROC_X_EBPSAFE(0x67AA18, eax, ebx, ecx, edx, esi, edi, ebp); + return; +} + +/* +* rct2: 0x67AA18 transfers readied images onto buffers +* This function copies the sprite data onto the screen +* I think its only used for bitmaps onto buttons but i am not sure. +* There is still a small bug with this code when it is in the choose park view. +*/ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpixelinfo *dpi, uint16 g1_y_start, uint16 g1_y_end, uint16 g1_x_start, uint16 g1_x_end){ //Image_id if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x2000000){ + RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, (int)source_bits_pointer, (int)dest_bits_pointer, (int)dpi); return; //0x67AAB3 } if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x4000000){ + RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, (int)source_bits_pointer, (int)dest_bits_pointer, (int)dpi); return; //0x67AFD8 } @@ -296,10 +315,10 @@ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpi //Clear the last data line bit so we have just the no_pixels no_pixels &= 0x7f; //Have our next source pointer point to the next data section - next_source_pointer = source_pointer + (int)no_pixels; + next_source_pointer = source_pointer + no_pixels; //Calculates the start point of the image - int x_start = (int)gap_size - (int)g1_x_start; + int x_start = gap_size - g1_x_start; if (x_start > 0){ //Since the start is positive @@ -318,17 +337,17 @@ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpi x_start = 0; } - int x_end = x_start + (int)no_pixels; + int x_end = x_start + no_pixels; //If the end position is further out than the whole image //end position then we need to shorten the line again - if (x_end > (int)g1_x_end){ + if (x_end > g1_x_end){ //Shorten the line - no_pixels -= x_end - (int)g1_x_end; + no_pixels -= x_end - g1_x_end; //If there are no pixels there is nothing to draw. if (no_pixels <= 0) continue; } - //Finally after all those checks copy the image onto the drawing surface + //Finally after all those checks, copy the image onto the drawing surface memcpy(dest_pointer, source_pointer, no_pixels); } //Add a line to the drawing surface pointer @@ -407,11 +426,13 @@ void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, if (end_x <= 0)return; } + //Can be removed when i work out the bug in the second function and we don't need to + //test the old version. RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16) = dest_dpi->width + dest_dpi->pitch; RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = end_x; RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = end_y; - RCT2_GLOBAL(0xEDF808, uint16) = g1_y_start; - RCT2_GLOBAL(0xEDF80C, uint16) = g1_x_start; + RCT2_GLOBAL(RCT2_Y_START_POINT_GLOBAL, uint16) = g1_y_start; + RCT2_GLOBAL(RCT2_X_START_POINT_GLOBAL, uint16) = g1_x_start; sub_0x67AA18(source_g1->offset, bits_pointer, dest_dpi, g1_y_start, end_y, g1_x_start, end_x); //RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, source_g1->offset, bits_pointer, dest_dpi); @@ -437,17 +458,77 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x009E3CDC, uint32) = RCT2_GLOBAL(0x009E3CE4 + eax * 4, uint32); if (((image_id)& 0xE0000000) && !(image_id & (1 << 31))) { - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); + //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); // - return;//jump into 0x67a445 + //return;//jump into 0x67a445 + if ((image_id)& 0x40000000){ + eax = image_id; + eax >>= 13; + eax &= 0xFF; + RCT2_GLOBAL(0x009E3CDC, uint32) = 0; + } + else{ + eax = image_id; + eax >>= 13; + eax &= 0x7F; + } + eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); + eax <<= 4; + eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); + RCT2_GLOBAL(0x9ABDA4, uint32) = eax; + } else if (((image_id)& 0xE0000000) && !(image_id & (1 << 29))){ - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); - return;//jump into 0x67a361 + //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); + //return;//jump into 0x67a361 + + eax = image_id; + RCT2_GLOBAL(0x9E3CDC, uint32) = 0; + eax >>= 13; + //push edx/y + eax &= 0x1F; + ebp = RCT2_GLOBAL(ebp * 4 + 0x97FCBC, uint32); + eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); + ebp <<= 4; + eax <<= 4; + ebp = RCT2_GLOBAL(ebp + RCT2_ADDRESS_G1_ELEMENTS, uint32); + eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); + edx = *((uint32*)eax + 0xF3); + esi = *((uint32*)eax + 0xF7); + RCT2_GLOBAL(0x9ABFFF, uint32) = edx; + RCT2_GLOBAL(0x9AC003, uint32) = esi; + edx = *((uint32*)ebp + 0xF3); + esi = *((uint32*)ebp + 0xF7); + esi = *((uint32*)eax + 0xF7); + + edx = *((uint32*)eax + 0xFB); + esi = *((uint32*)ebp + 0xFB); + + eax = image_id; + RCT2_GLOBAL(0x9AC007, uint32) = edx; + eax >>= 18; + RCT2_GLOBAL(0x9ABF42, uint32) = esi; + eax &= 0x1F; + + //image_id + RCT2_GLOBAL(0xEDF81C, uint32) |= 0x20000000; + + eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); + eax <<= 4; + eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); + edx = *((uint32*)eax + 0xF3); + esi = *((uint32*)eax + 0xF7); + RCT2_GLOBAL(0x9ABFD6, uint32) = edx; + RCT2_GLOBAL(0x9ABFDA, uint32) = esi; + edx = *((uint32*)eax + 0xFB); + RCT2_GLOBAL(0x9ABDA4, uint32) = 0x9ABF0C; + RCT2_GLOBAL(0x9ABFDE, uint32) = edx; + edx = y; + } else if ((image_id)& 0xE0000000){ - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); - /* + //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); + //return; eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; eax >>= 19; @@ -455,6 +536,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); eax <<= 4; eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); + ebp = *((uint32*)eax + 0xF3); esi = *((uint32*)eax + 0xF7); RCT2_GLOBAL(0x9ABEFF, uint32) = ebp; @@ -475,8 +557,8 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebp = *((uint32*)eax + 0xFB); RCT2_GLOBAL(0x9ABDA4, uint32) = 0x009ABE0C; - RCT2_GLOBAL(0x9ABEDE, uint32) = ebp;*/ - return; + RCT2_GLOBAL(0x9ABEDE, uint32) = ebp; + } ebx &= 0x7FFFF; @@ -508,8 +590,8 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) sub_0x67A934(g1_source, dpi, x, y); return; } - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); - return; + //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); + //return; //dpi on stack int translated_x, translated_y; char* bits_pointer; @@ -588,7 +670,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebx = RCT2_GLOBAL(0xEDF81C, uint32); ecx = 0xFFFF&translated_x; //ebx, esi, edi, ah used in 0x67a690 - RCT2_CALLPROC_X_EBPSAFE(0x67A690, eax, ebx, ecx, edx, esi,(int) bits_pointer, ebp); + sub_0x67A690(eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp); return; } //0x67A60A From a4645ec806b1ddeb9614d3f386b5c74e486aab91 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 18 May 2014 19:27:00 +0100 Subject: [PATCH 37/99] Trying to locate bug in drawing ready code. --- src/gfx.c | 92 ++++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index ed64965863..88d9e5cb41 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -434,8 +434,8 @@ void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, RCT2_GLOBAL(RCT2_Y_START_POINT_GLOBAL, uint16) = g1_y_start; RCT2_GLOBAL(RCT2_X_START_POINT_GLOBAL, uint16) = g1_x_start; - sub_0x67AA18(source_g1->offset, bits_pointer, dest_dpi, g1_y_start, end_y, g1_x_start, end_x); - //RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, source_g1->offset, bits_pointer, dest_dpi); + //sub_0x67AA18(source_g1->offset, bits_pointer, dest_dpi, g1_y_start, end_y, g1_x_start, end_x); + RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, (int)source_g1->offset, (int)bits_pointer, (int)dest_dpi); } /** @@ -458,9 +458,9 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x009E3CDC, uint32) = RCT2_GLOBAL(0x009E3CE4 + eax * 4, uint32); if (((image_id)& 0xE0000000) && !(image_id & (1 << 31))) { - //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); // - //return;//jump into 0x67a445 + return;//jump into 0x67a445 if ((image_id)& 0x40000000){ eax = image_id; eax >>= 13; @@ -479,8 +479,8 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } else if (((image_id)& 0xE0000000) && !(image_id & (1 << 29))){ - //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); - //return;//jump into 0x67a361 + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); + return;//jump into 0x67a361 eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; @@ -493,16 +493,16 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax <<= 4; ebp = RCT2_GLOBAL(ebp + RCT2_ADDRESS_G1_ELEMENTS, uint32); eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); - edx = *((uint32*)eax + 0xF3); - esi = *((uint32*)eax + 0xF7); + edx = *((uint32*)(eax + 0xF3)); + esi = *((uint32*)(eax + 0xF7)); RCT2_GLOBAL(0x9ABFFF, uint32) = edx; RCT2_GLOBAL(0x9AC003, uint32) = esi; - edx = *((uint32*)ebp + 0xF3); - esi = *((uint32*)ebp + 0xF7); - esi = *((uint32*)eax + 0xF7); + edx = *((uint32*)(ebp + 0xF3)); + esi = *((uint32*)(ebp + 0xF7)); + esi = *((uint32*)(eax + 0xF7)); - edx = *((uint32*)eax + 0xFB); - esi = *((uint32*)ebp + 0xFB); + edx = *((uint32*)(eax + 0xFB)); + esi = *((uint32*)(ebp + 0xFB)); eax = image_id; RCT2_GLOBAL(0x9AC007, uint32) = edx; @@ -516,19 +516,19 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); eax <<= 4; eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); - edx = *((uint32*)eax + 0xF3); - esi = *((uint32*)eax + 0xF7); + edx = *((uint32*)(eax + 0xF3)); + esi = *((uint32*)(eax + 0xF7)); RCT2_GLOBAL(0x9ABFD6, uint32) = edx; RCT2_GLOBAL(0x9ABFDA, uint32) = esi; - edx = *((uint32*)eax + 0xFB); + edx = *((uint32*)(eax + 0xFB)); RCT2_GLOBAL(0x9ABDA4, uint32) = 0x9ABF0C; RCT2_GLOBAL(0x9ABFDE, uint32) = edx; edx = y; } else if ((image_id)& 0xE0000000){ - //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); - //return; + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); + return; eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; eax >>= 19; @@ -537,11 +537,11 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax <<= 4; eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); - ebp = *((uint32*)eax + 0xF3); - esi = *((uint32*)eax + 0xF7); + ebp = *((uint32*)(eax + 0xF3)); + esi = *((uint32*)(eax + 0xF7)); RCT2_GLOBAL(0x9ABEFF, uint32) = ebp; RCT2_GLOBAL(0x9ABF03, uint32) = esi; - ebp = *((uint32*)eax + 0xFB); + ebp = *((uint32*)(eax + 0xFB)); eax = ebx; RCT2_GLOBAL(0x9ABF07, uint32) = ebp; @@ -550,11 +550,11 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); eax <<= 4; eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); - ebp = *((uint32*)eax + 0xF3); - esi = *((uint32*)eax + 0xF7); + ebp = *((uint32*)(eax + 0xF3)); + esi = *((uint32*)(eax + 0xF7)); RCT2_GLOBAL(0x9ABED6, uint32) = ebp; RCT2_GLOBAL(0x9ABEDA, uint32) = esi; - ebp = *((uint32*)eax + 0xFB); + ebp = *((uint32*)(eax + 0xFB)); RCT2_GLOBAL(0x9ABDA4, uint32) = 0x009ABE0C; RCT2_GLOBAL(0x9ABEDE, uint32) = ebp; @@ -597,13 +597,13 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) char* bits_pointer; ebp = (int)dpi; - esi = RCT2_GLOBAL(0x9E3D08, uint32); + esi = (int)g1_source->offset;//RCT2_GLOBAL(0x9E3D08, uint32); RCT2_GLOBAL(0x9E3CE0, uint32) = 0; bits_pointer = dpi->bits; - RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = RCT2_GLOBAL(0x9E3D0E, sint16); + RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = g1_source->height;// RCT2_GLOBAL(0x9E3D0E, sint16); - translated_y = y + RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16) - dpi->y; + translated_y = y - dpi->y + g1_source->y_offset;//RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16); if (translated_y < 0){ @@ -612,30 +612,27 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) return; } translated_y = -translated_y; - esi += translated_y * RCT2_GLOBAL(0x9E3D0C, sint16); - RCT2_GLOBAL(0x9E3CE0, sint32) += translated_y * RCT2_GLOBAL(0x9E3D0C, sint16); + esi += translated_y * g1_source->width;//RCT2_GLOBAL(0x9E3D0C, sint16); + RCT2_GLOBAL(0x9E3CE0, sint32) += translated_y * g1_source->width;//RCT2_GLOBAL(0x9E3D0C, sint16); translated_y = 0; } else { - eax = (dpi->width + dpi->pitch) * translated_y; - bits_pointer += eax; + //eax = ; + bits_pointer += (dpi->width + dpi->pitch) * translated_y;//eax; } - translated_y += RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) - dpi->height;; + translated_y += RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) - dpi->height; if (translated_y > 0){ RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) -= translated_y; - if (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) <= 0) - { - return; - } + if (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) <= 0)return; } - RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = RCT2_GLOBAL(0x9E3D0C, sint16); - eax = dpi->width + dpi->pitch - RCT2_GLOBAL(0x9E3D0C, sint16); + RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = g1_source->width;// RCT2_GLOBAL(0x9E3D0C, sint16); + eax = dpi->width + dpi->pitch - g1_source->width; //RCT2_GLOBAL(0x9E3D0C, sint16); RCT2_GLOBAL(0x9ABDAE, uint16) = 0; - RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16) = dpi->width + dpi->pitch - RCT2_GLOBAL(0x9E3D0C, sint16); - translated_x = x + RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_1, uint16) - dpi->x; + RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16) = dpi->width + dpi->pitch - g1_source->width;// RCT2_GLOBAL(0x9E3D0C, sint16); + translated_x = x - dpi->x + g1_source->x_offset;//RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_1, uint16); if (translated_x < 0){ @@ -644,7 +641,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) return; } - translated_x -= RCT2_GLOBAL(0x9ABDAE, sint16); + RCT2_GLOBAL(0x9ABDAE, sint16) -= translated_x; esi -= translated_x; RCT2_GLOBAL(0x9E3CE0, sint32) -= translated_x; RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16) -= translated_x; @@ -656,21 +653,20 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) if (translated_x > 0){ RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) -= translated_x; - if (RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) <= 0){ - return; - } + if (RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) <= 0)return; + RCT2_GLOBAL(0x9ABDAE, sint16) += translated_x; RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16) += translated_x; } - if (!(RCT2_GLOBAL(0x9E3D14, uint16) & 0x02)){ - eax = (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, uint8)) << 8; + if (!(g1_source->flags & 0x02)){ + eax = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16) & 0xFF + (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, uint8)) << 8; edx = RCT2_GLOBAL(0x9ABDAE, sint16); ebp = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16); ebx = RCT2_GLOBAL(0xEDF81C, uint32); ecx = 0xFFFF&translated_x; - //ebx, esi, edi, ah used in 0x67a690 - sub_0x67A690(eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp); + //ebx, edx, esi, edi, ah, ebp used in 0x67a690 eax=1966, ecx=ff39, edx=ebx=0, esp = cfca4, ebp = 266, esi =368823e, edi = 16c79b2 + sub_0x67A690(eax, ebx, 0, edx, esi, (int)bits_pointer, ebp); return; } //0x67A60A From 400351a38cd30f636c53763b275c7f05774ecd42 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Mon, 19 May 2014 21:12:00 +0100 Subject: [PATCH 38/99] Finally found bug. It was caused by the wrong offset in the calling sub. --- src/gfx.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 88d9e5cb41..1b6e3fd581 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -272,7 +272,7 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri * buffers */ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp){ - RCT2_CALLPROC_X_EBPSAFE(0x67AA18, eax, ebx, ecx, edx, esi, edi, ebp); + RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); return; } @@ -458,9 +458,9 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x009E3CDC, uint32) = RCT2_GLOBAL(0x009E3CE4 + eax * 4, uint32); if (((image_id)& 0xE0000000) && !(image_id & (1 << 31))) { - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); + //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); // - return;//jump into 0x67a445 + //return;//jump into 0x67a445 if ((image_id)& 0x40000000){ eax = image_id; eax >>= 13; @@ -479,8 +479,8 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } else if (((image_id)& 0xE0000000) && !(image_id & (1 << 29))){ - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); - return;//jump into 0x67a361 + //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); + //return;//jump into 0x67a361 eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; @@ -527,8 +527,8 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } else if ((image_id)& 0xE0000000){ - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); - return; + //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); + //return; eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; eax >>= 19; @@ -605,6 +605,9 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) translated_y = y - dpi->y + g1_source->y_offset;//RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16); + if (image_id == 5200){ + image_id = image_id; + } if (translated_y < 0){ RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) += translated_y; @@ -612,7 +615,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) return; } translated_y = -translated_y; - esi += translated_y * g1_source->width;//RCT2_GLOBAL(0x9E3D0C, sint16); + esi += (uint32)translated_y * g1_source->width;//RCT2_GLOBAL(0x9E3D0C, sint16); RCT2_GLOBAL(0x9E3CE0, sint32) += translated_y * g1_source->width;//RCT2_GLOBAL(0x9E3D0C, sint16); translated_y = 0; } else { @@ -649,24 +652,28 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } bits_pointer += translated_x; - translated_x += RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) - dpi->width; + translated_x += RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16); + + + translated_x -= dpi->width; if (translated_x > 0){ RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) -= translated_x; if (RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) <= 0)return; - RCT2_GLOBAL(0x9ABDAE, sint16) += translated_x; - RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16) += translated_x; + RCT2_GLOBAL(0x9ABDAE, uint16) += translated_x; + RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16) += translated_x; } - + if (!(g1_source->flags & 0x02)){ - eax = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16) & 0xFF + (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, uint8)) << 8; - edx = RCT2_GLOBAL(0x9ABDAE, sint16); - ebp = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16); + eax = RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, uint8); + eax <<= 8; + edx = RCT2_GLOBAL(0x9ABDAE, uint16); + ebp = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16); ebx = RCT2_GLOBAL(0xEDF81C, uint32); ecx = 0xFFFF&translated_x; //ebx, edx, esi, edi, ah, ebp used in 0x67a690 eax=1966, ecx=ff39, edx=ebx=0, esp = cfca4, ebp = 266, esi =368823e, edi = 16c79b2 - sub_0x67A690(eax, ebx, 0, edx, esi, (int)bits_pointer, ebp); + sub_0x67A690(eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp); return; } //0x67A60A From 9270aa6aae3abbc6c1a29fda01bf383e499b7bca Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Mon, 19 May 2014 22:06:01 +0100 Subject: [PATCH 39/99] Fixed tab background bug. --- src/gfx.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 1b6e3fd581..4d044d8665 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -458,18 +458,16 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x009E3CDC, uint32) = RCT2_GLOBAL(0x009E3CE4 + eax * 4, uint32); if (((image_id)& 0xE0000000) && !(image_id & (1 << 31))) { - //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); - // - //return;//jump into 0x67a445 - if ((image_id)& 0x40000000){ + + if (!((image_id)& 0x40000000)){ eax = image_id; - eax >>= 13; + eax >>= 19; eax &= 0xFF; RCT2_GLOBAL(0x009E3CDC, uint32) = 0; } else{ eax = image_id; - eax >>= 13; + eax >>= 19; eax &= 0x7F; } eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); @@ -484,13 +482,13 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; - eax >>= 13; + eax >>= 19; //push edx/y eax &= 0x1F; ebp = RCT2_GLOBAL(ebp * 4 + 0x97FCBC, uint32); eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); - ebp <<= 4; - eax <<= 4; + ebp <<= 0x4; + eax <<= 0x4; ebp = RCT2_GLOBAL(ebp + RCT2_ADDRESS_G1_ELEMENTS, uint32); eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); edx = *((uint32*)(eax + 0xF3)); @@ -506,7 +504,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax = image_id; RCT2_GLOBAL(0x9AC007, uint32) = edx; - eax >>= 18; + eax >>= 24; RCT2_GLOBAL(0x9ABF42, uint32) = esi; eax &= 0x1F; @@ -677,8 +675,16 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) return; } //0x67A60A + + esi -= (uint32)g1_source->offset; + ebp = esi; + eax = g1_source->width*g1_source->height; + esi = g1_source->offset; + edx = eax; + edi = 0x9E3D28; + eax = 0; + RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); - esi -= RCT2_GLOBAL(0x9E3D08, sint32); return; } From 0a8a56d4b003d5934a5c6668dbf872a7f66418e4 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 20 May 2014 18:32:42 +0100 Subject: [PATCH 40/99] Bug in buffer code changing the colour of peep --- src/gfx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 4d044d8665..3244ad472c 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -340,7 +340,7 @@ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpi int x_end = x_start + no_pixels; //If the end position is further out than the whole image //end position then we need to shorten the line again - if (x_end > g1_x_end){ + if (x_end > (int)g1_x_end){ //Shorten the line no_pixels -= x_end - g1_x_end; //If there are no pixels there is nothing to draw. @@ -433,9 +433,9 @@ void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = end_y; RCT2_GLOBAL(RCT2_Y_START_POINT_GLOBAL, uint16) = g1_y_start; RCT2_GLOBAL(RCT2_X_START_POINT_GLOBAL, uint16) = g1_x_start; - - //sub_0x67AA18(source_g1->offset, bits_pointer, dest_dpi, g1_y_start, end_y, g1_x_start, end_x); - RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, (int)source_g1->offset, (int)bits_pointer, (int)dest_dpi); + + sub_0x67AA18(source_g1->offset, bits_pointer, dest_dpi, g1_y_start, end_y, g1_x_start, end_x); + //RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, (int)source_g1->offset, (int)bits_pointer, (int)dest_dpi); } /** From e11e9d78f9ded6e0ccb9c8e524888e9f87a3a7c7 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 21 May 2014 18:21:49 +0100 Subject: [PATCH 41/99] Fixed small bug due to wrong constant. --- src/gfx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 3244ad472c..f702d70ae9 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -284,12 +284,12 @@ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp) */ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpixelinfo *dpi, uint16 g1_y_start, uint16 g1_y_end, uint16 g1_x_start, uint16 g1_x_end){ //Image_id - if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x2000000){ + if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x20000000){ RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, (int)source_bits_pointer, (int)dest_bits_pointer, (int)dpi); return; //0x67AAB3 } - if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x4000000){ + if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x40000000){ RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, (int)source_bits_pointer, (int)dest_bits_pointer, (int)dpi); return; //0x67AFD8 } @@ -679,7 +679,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) esi -= (uint32)g1_source->offset; ebp = esi; eax = g1_source->width*g1_source->height; - esi = g1_source->offset; + esi = (int)g1_source->offset; edx = eax; edi = 0x9E3D28; eax = 0; From e5a9426203161631735c2ffd4b023d1114153f93 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 21 May 2014 18:57:56 +0100 Subject: [PATCH 42/99] Added final part of main code section. --- src/gfx.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/gfx.c b/src/gfx.c index f702d70ae9..d48159409c 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -683,8 +683,47 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) edx = eax; edi = 0x9E3D28; eax = 0; + while (edx>0){ + eax = *((sint8*)esi); + if (eax >= 0){ + esi++; + ecx = eax; + edx -= eax; + memcpy((char*)edi, (char*)esi, ecx); + edi += ecx; + esi += ecx; + continue; + } + ecx = eax; + ebx = edi; + eax &= 0x7; + ecx >>= 3; + eax <<= 8; + ecx = -ecx; + eax = eax & 0xFF00 + *((sint8*)esi); + edx -= ecx; + esi += 2; + ebx -= eax; + eax = esi; + esi = ebx; + ebx = eax; + eax = 0; + memcpy((char*)edi, (char*)esi, ecx); + edi += ecx; + esi += ecx; + esi = ebx; + } + //edi poped off stack + esi = ebp; + esi += 0x9E3D28; + eax = RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, uint8); + eax <<= 8; + edx = RCT2_GLOBAL(0x9ABDAE, uint16); + ebp = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16); + ebx = RCT2_GLOBAL(0xEDF81C, uint32); - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); + sub_0x67A690(eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp); + //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); return; } From 5c927eb418c8e35c01109257d6d863855411d7aa Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Thu, 22 May 2014 17:51:15 +0100 Subject: [PATCH 43/99] Fixed small graphical glitch caused by too small a variable --- src/gfx.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index d48159409c..a1f1b8c700 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -282,7 +282,7 @@ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp) * I think its only used for bitmaps onto buttons but i am not sure. * There is still a small bug with this code when it is in the choose park view. */ -void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpixelinfo *dpi, uint16 g1_y_start, uint16 g1_y_end, uint16 g1_x_start, uint16 g1_x_end){ +void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpixelinfo *dpi, int g1_y_start, int g1_y_end, int g1_x_start, int g1_x_end){ //Image_id if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x20000000){ RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, (int)source_bits_pointer, (int)dest_bits_pointer, (int)dpi); @@ -308,7 +308,7 @@ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpi char* source_pointer = next_source_pointer; char* dest_pointer = next_dest_pointer; - sint8 no_pixels = *source_pointer++; + int no_pixels = *source_pointer++; uint8 gap_size = *source_pointer++; //The last bit in no_pixels tells you if you have reached the end of a line last_data_line = no_pixels & 0x80; @@ -362,7 +362,7 @@ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpi * I think its only used for bitmaps onto buttons but i am not sure. */ void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, int y){ - uint16 g1_y_start, g1_x_start; + int g1_y_start, g1_x_start; char* bits_pointer; bits_pointer = dest_dpi->bits; @@ -426,16 +426,7 @@ void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, if (end_x <= 0)return; } - //Can be removed when i work out the bug in the second function and we don't need to - //test the old version. - RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16) = dest_dpi->width + dest_dpi->pitch; - RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = end_x; - RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = end_y; - RCT2_GLOBAL(RCT2_Y_START_POINT_GLOBAL, uint16) = g1_y_start; - RCT2_GLOBAL(RCT2_X_START_POINT_GLOBAL, uint16) = g1_x_start; - - sub_0x67AA18(source_g1->offset, bits_pointer, dest_dpi, g1_y_start, end_y, g1_x_start, end_x); - //RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, (int)source_g1->offset, (int)bits_pointer, (int)dest_dpi); + sub_0x67AA18((char*)source_g1->offset, bits_pointer, dest_dpi, g1_y_start, end_y, g1_x_start, end_x); } /** From 5a5a5409a241876f3d74450ee3f17a0024a41099 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Thu, 22 May 2014 19:18:50 +0100 Subject: [PATCH 44/99] Started implementing next set of buffer functions. Cleaned up some comments and code paths --- src/gfx.c | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index a1f1b8c700..a41bad8105 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -272,6 +272,31 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri * buffers */ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp){ + if (ebx & 0x20000000){ + //0x67a7f7 + RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); + return; + } + if (ebx & 0x40000000){ + //0x67a786 + RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); + return; + } + + if (!(RCT2_GLOBAL(0x9E3D14, uint16) & 1)){ + //0x67a707 + RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); + return; + } + + int _ebx = RCT2_GLOBAL(0x9ABDA8, uint16); + if (RCT2_GLOBAL(0x9E3CDC, uint32) != 0){ + //0x67A722 + RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); + return; + } + + int _ecx = ebx; RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); return; } @@ -285,11 +310,22 @@ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp) void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpixelinfo *dpi, int g1_y_start, int g1_y_end, int g1_x_start, int g1_x_end){ //Image_id if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x20000000){ + + RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16) = dpi->width + dpi->pitch; + RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = g1_x_end; + RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = g1_y_end; + RCT2_GLOBAL(RCT2_Y_START_POINT_GLOBAL, uint16) = g1_y_start; + RCT2_GLOBAL(RCT2_X_START_POINT_GLOBAL, uint16) = g1_x_start; RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, (int)source_bits_pointer, (int)dest_bits_pointer, (int)dpi); return; //0x67AAB3 } if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x40000000){ + RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16) = dpi->width + dpi->pitch; + RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = g1_x_end; + RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = g1_y_end; + RCT2_GLOBAL(RCT2_Y_START_POINT_GLOBAL, uint16) = g1_y_start; + RCT2_GLOBAL(RCT2_X_START_POINT_GLOBAL, uint16) = g1_x_start; RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, (int)source_bits_pointer, (int)dest_bits_pointer, (int)dpi); return; //0x67AFD8 } @@ -555,13 +591,14 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebx += RCT2_ADDRESS_G1_ELEMENTS; if (dpi->pad_0E >= 1){ if (dpi->pad_0E == 1){ + RCT2_CALLPROC_X(0x0067BD81, eax, ebx, x, y, 0, dpi, ebp); return; - //jump into 0x67bd81 } if (dpi->pad_0E >= 3){ - return;//jump into 0x67FAAE + RCT2_CALLPROC_X(0x0067FAAE, eax, ebx, x, y, 0, dpi, ebp); + return; } - //jump into 0x67DADA + RCT2_CALLPROC_X(0x0067DADA, eax, ebx, x, y, 0, dpi, ebp); return; } eax = *((uint32*)ebx + 2); @@ -575,12 +612,10 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) if (RCT2_GLOBAL(0x9E3D14, uint32) & (1 << 2)){ //Title screen bitmaps - //RCT2_CALLPROC_X(0x0067A934, eax, ebx, x, y, 0, dpi, ebp); sub_0x67A934(g1_source, dpi, x, y); return; } - //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); - //return; + //dpi on stack int translated_x, translated_y; char* bits_pointer; From 8bc3ac03c4392463533e8337b4fffbcb5f6f4314 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 23 May 2014 09:05:21 +0100 Subject: [PATCH 45/99] Added more buffer of the buffer function --- src/gfx.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 8 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index a41bad8105..c56ef9e7fe 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -273,8 +273,67 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri */ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp){ if (ebx & 0x20000000){ - //0x67a7f7 - RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); + int _ecx = eax >> 8; + uint32 _ebx = RCT2_GLOBAL(0x9ABDA4, uint32); + _ecx--; + _ecx <<= 0x10; + + if (RCT2_GLOBAL(0x9E3CDC, uint32)){ + + RCT2_GLOBAL(0x9E3D04, uint32) = ebp; + uint32 _ebp = RCT2_GLOBAL(0x9E3CDC, uint32); + _ebp += RCT2_GLOBAL(0x9E3CE0, uint32); + + for (_ecx >>= 0x10; _ecx >= 0; --_ecx){ + for (int _cx = RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16); _cx > 0; --_cx){ + uint8 al = *((char*)esi); + esi++; + al = *((char*)_ebx + al); + al &= *((char*)_ebp); + if (al){ + *((char*)edi) = al; + } + edi++; + _ebp++; + } + esi += edx; + edi += RCT2_GLOBAL(0x9E3D04, uint32); + _ebp += edx; + } + return; + } + + if ((RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16)) == 4){ + + ebp += 4; + edx += 4; + for (_ecx >>= 0x10; _ecx >= 0; --_ecx){ + for (int i = 0; i < 4; ++i){ + uint8 al = *((char*)esi+i); + al = *((char*)_ebx + al); + if (al){ + *((char*)edi+i) = al; + } + } + edi += ebp; + esi += edx; + } + return; + } + + for (_ecx >>= 0x10; _ecx >= 0; --_ecx){ + for (int _cx = RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16); _cx > 0; --_cx){ + uint8 al = *((char*)esi); + esi++; + al = *((char*)_ebx + al); + if (al){ + *((char*)edi) = al; + } + edi++; + } + esi += edx; + edi += ebp; + } return; } if (ebx & 0x40000000){ @@ -289,15 +348,26 @@ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp) return; } - int _ebx = RCT2_GLOBAL(0x9ABDA8, uint16); + int _ebx = RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16); if (RCT2_GLOBAL(0x9E3CDC, uint32) != 0){ //0x67A722 RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); return; } - int _ecx = ebx; - RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); + for (int ah = eax >> 8; ah > 0; --ah){ + int _ecx = _ebx; + for (; _ecx > 0; --_ecx){ + char al = *((char*)esi); + esi++; + if (al){ + *((char*)edi) = al; + } + edi++; + } + esi += edx; + edi += ebp; + } return; } @@ -591,14 +661,14 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebx += RCT2_ADDRESS_G1_ELEMENTS; if (dpi->pad_0E >= 1){ if (dpi->pad_0E == 1){ - RCT2_CALLPROC_X(0x0067BD81, eax, ebx, x, y, 0, dpi, ebp); + RCT2_CALLPROC_X(0x0067BD81, eax, ebx, x, y, 0,(int) dpi, ebp); return; } if (dpi->pad_0E >= 3){ - RCT2_CALLPROC_X(0x0067FAAE, eax, ebx, x, y, 0, dpi, ebp); + RCT2_CALLPROC_X(0x0067FAAE, eax, ebx, x, y, 0, (int)dpi, ebp); return; } - RCT2_CALLPROC_X(0x0067DADA, eax, ebx, x, y, 0, dpi, ebp); + RCT2_CALLPROC_X(0x0067DADA, eax, ebx, x, y, 0, (int)dpi, ebp); return; } eax = *((uint32*)ebx + 2); From b144147400070df8bdb73ca5bfbe943d1ae0d322 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 23 May 2014 09:45:18 +0100 Subject: [PATCH 46/99] Added last parts to main buffer function --- src/gfx.c | 85 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 21 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index c56ef9e7fe..18c61cca64 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -271,15 +271,17 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri * rct2: 0x67A690 very similar in function to 0x67AA18 readied images are copied onto * buffers */ -void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp){ - if (ebx & 0x20000000){ +void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp, int image_type){ + + //Has a background image? + if (image_type & 0x2){ int _ecx = eax >> 8; uint32 _ebx = RCT2_GLOBAL(0x9ABDA4, uint32); _ecx--; _ecx <<= 0x10; + //Mix with background image and colour adjusted if (RCT2_GLOBAL(0x9E3CDC, uint32)){ - RCT2_GLOBAL(0x9E3D04, uint32) = ebp; uint32 _ebp = RCT2_GLOBAL(0x9E3CDC, uint32); _ebp += RCT2_GLOBAL(0x9E3CE0, uint32); @@ -303,6 +305,7 @@ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp) return; } + //Quicker? if ((RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16)) == 4){ ebp += 4; @@ -321,6 +324,7 @@ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp) return; } + //image colour adjusted? for (_ecx >>= 0x10; _ecx >= 0; --_ecx){ for (int _cx = RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16); _cx > 0; --_cx){ uint8 al = *((char*)esi); @@ -336,28 +340,65 @@ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp) } return; } - if (ebx & 0x40000000){ - //0x67a786 - RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); + + //image_type mix with background? + if (image_type & 0x4){ + int _ebx = RCT2_GLOBAL(0x9ABDA4, uint16); + for (int ah = eax >> 8; ah > 0; --ah){ + + for (int cx = RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16); cx > 0; --ecx){ + uint8 al = *((char*)esi); + esi++; + if (al){ + al = *((char*)edi); + al = *((char*)_ebx + al); + *((char*)edi) = al; + } + edi++; + } + esi += edx; + edi += ebp; + } return; } if (!(RCT2_GLOBAL(0x9E3D14, uint16) & 1)){ - //0x67a707 - RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); + int bx = RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16); + for (int ax = RCT2_GLOBAL(0x9ABDAC, uint16); ax > 0; --ax){ + memcpy((char*)edi, (char*)esi, bx); + edi += bx; + esi += bx; + edi += ebp; + esi += edx; + } return; } int _ebx = RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16); if (RCT2_GLOBAL(0x9E3CDC, uint32) != 0){ - //0x67A722 - RCT2_CALLPROC_X(0x67A690, eax, ebx, ecx, edx, esi, edi, ebp); - return; + RCT2_GLOBAL(0x9E3D04, uint32) = ebp; + uint32 _ebp = RCT2_GLOBAL(0x9E3CDC, uint32); + _ebp += RCT2_GLOBAL(0x9E3CE0, uint32); + + for (int ah = eax >> 8; ah > 0; --ah){ + for (int _ecx = _ebx; _ecx > 0; --_ecx){ + char al = *((char*)esi); + esi++; + al &= *((char*)_ebp); + if (al){ + *((char*)edi) = al; + } + edi++; + _ebp++; + } + esi += edx; + edi += RCT2_GLOBAL(0x9E3D04, uint32); + _ebp += edx; + } } for (int ah = eax >> 8; ah > 0; --ah){ - int _ecx = _ebx; - for (; _ecx > 0; --_ecx){ + for (int _ecx = _ebx; _ecx > 0; --_ecx){ char al = *((char*)esi); esi++; if (al){ @@ -377,9 +418,9 @@ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp) * I think its only used for bitmaps onto buttons but i am not sure. * There is still a small bug with this code when it is in the choose park view. */ -void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpixelinfo *dpi, int g1_y_start, int g1_y_end, int g1_x_start, int g1_x_end){ +void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpixelinfo *dpi, int image_type, int g1_y_start, int g1_y_end, int g1_x_start, int g1_x_end){ //Image_id - if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x20000000){ + if (image_type & 0x2){ RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16) = dpi->width + dpi->pitch; RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = g1_x_end; @@ -390,7 +431,7 @@ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpi return; //0x67AAB3 } - if (RCT2_GLOBAL(0xEDF81C, uint32) & 0x40000000){ + if (image_type & 0x4){ RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16) = dpi->width + dpi->pitch; RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = g1_x_end; RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = g1_y_end; @@ -467,7 +508,7 @@ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpi * This function readies all the global vars for copying the sprite data onto the screen * I think its only used for bitmaps onto buttons but i am not sure. */ -void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, int y){ +void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, int y, int image_type){ int g1_y_start, g1_x_start; char* bits_pointer; @@ -532,7 +573,7 @@ void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, if (end_x <= 0)return; } - sub_0x67AA18((char*)source_g1->offset, bits_pointer, dest_dpi, g1_y_start, end_y, g1_x_start, end_x); + sub_0x67AA18((char*)source_g1->offset, bits_pointer, dest_dpi, image_type, g1_y_start, end_y, g1_x_start, end_x); } /** @@ -548,6 +589,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) //return; int eax = 0, ebx = image_id, ecx = x, edx = y, esi = 0, edi = (int)dpi, ebp = 0; + int image_type = (image_id & 0xE0000000) >> 28; RCT2_GLOBAL(0x00EDF81C, uint32) = image_id & 0xE0000000; eax = (image_id >> 26) & 0x7; @@ -607,6 +649,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) //image_id RCT2_GLOBAL(0xEDF81C, uint32) |= 0x20000000; + image_type |= 0x2; eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); eax <<= 4; @@ -682,7 +725,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) if (RCT2_GLOBAL(0x9E3D14, uint32) & (1 << 2)){ //Title screen bitmaps - sub_0x67A934(g1_source, dpi, x, y); + sub_0x67A934(g1_source, dpi, x, y, image_type); return; } @@ -767,7 +810,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebx = RCT2_GLOBAL(0xEDF81C, uint32); ecx = 0xFFFF&translated_x; //ebx, edx, esi, edi, ah, ebp used in 0x67a690 eax=1966, ecx=ff39, edx=ebx=0, esp = cfca4, ebp = 266, esi =368823e, edi = 16c79b2 - sub_0x67A690(eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp); + sub_0x67A690(eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp, image_type); return; } //0x67A60A @@ -818,7 +861,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebp = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16); ebx = RCT2_GLOBAL(0xEDF81C, uint32); - sub_0x67A690(eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp); + sub_0x67A690(eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp, image_type); //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); return; } From 9f3bdff3c987565fb3d4b57e3c3cfbe2235e87dc Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 23 May 2014 10:22:31 +0100 Subject: [PATCH 47/99] Added alternitive image_types to 2nd buffer function --- src/gfx.c | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 18c61cca64..e9909897f4 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -419,28 +419,6 @@ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp, * There is still a small bug with this code when it is in the choose park view. */ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpixelinfo *dpi, int image_type, int g1_y_start, int g1_y_end, int g1_x_start, int g1_x_end){ - //Image_id - if (image_type & 0x2){ - - RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16) = dpi->width + dpi->pitch; - RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = g1_x_end; - RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = g1_y_end; - RCT2_GLOBAL(RCT2_Y_START_POINT_GLOBAL, uint16) = g1_y_start; - RCT2_GLOBAL(RCT2_X_START_POINT_GLOBAL, uint16) = g1_x_start; - RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, (int)source_bits_pointer, (int)dest_bits_pointer, (int)dpi); - return; //0x67AAB3 - } - - if (image_type & 0x4){ - RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16) = dpi->width + dpi->pitch; - RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = g1_x_end; - RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = g1_y_end; - RCT2_GLOBAL(RCT2_Y_START_POINT_GLOBAL, uint16) = g1_y_start; - RCT2_GLOBAL(RCT2_X_START_POINT_GLOBAL, uint16) = g1_x_start; - RCT2_CALLPROC_X_EBPSAFE(0x67AA18, 0, 0, 0, 0, (int)source_bits_pointer, (int)dest_bits_pointer, (int)dpi); - return; //0x67AFD8 - } - uint16 offset_to_first_line = *(uint16*)(g1_y_start*2 + (uint32)source_bits_pointer); //This will now point to the first line char* next_source_pointer = (char*)((uint32)source_bits_pointer + offset_to_first_line); @@ -495,7 +473,31 @@ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpi } //Finally after all those checks, copy the image onto the drawing surface - memcpy(dest_pointer, source_pointer, no_pixels); + //If the image type is not a basic one we require to mix the pixels + if (image_type & 0x2){ + for (; no_pixels > 0; --no_pixels, source_pointer++, dest_pointer++){ + uint8 al = *source_pointer; + uint8 ah = *dest_pointer; + if (image_type & 0x4)//Mix with background and image + al = *((uint8*)(((al | ((int)ah)<<8) - 0x100) + RCT2_GLOBAL(0x9ABDA4, uint32))); + else //Adjust colours? + al = *((uint8*)(al + RCT2_GLOBAL(0x9ABDA4, uint32))); + *dest_pointer = al; + } + } + else if (image_type & 0x4){ + //Doesnt use source pointer ??? mix with background only? + for (; no_pixels > 0; --no_pixels, source_pointer++, dest_pointer++){ + uint8 al = *dest_pointer; + al = *((uint8*)(al + RCT2_GLOBAL(0x9ABDA4, uint32))); + *dest_pointer = al; + } + } + else + { + memcpy(dest_pointer, source_pointer, no_pixels); + } + } //Add a line to the drawing surface pointer next_dest_pointer += (int)dpi->width + (int)dpi->pitch; From cd3db82343cc85acf647e74a215d8eac4de1536d Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 23 May 2014 10:54:31 +0100 Subject: [PATCH 48/99] Added notes for what has been tested. --- src/gfx.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index e9909897f4..452f5afdfe 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -281,7 +281,7 @@ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp, _ecx <<= 0x10; //Mix with background image and colour adjusted - if (RCT2_GLOBAL(0x9E3CDC, uint32)){ + if (RCT2_GLOBAL(0x9E3CDC, uint32)){ //Not tested RCT2_GLOBAL(0x9E3D04, uint32) = ebp; uint32 _ebp = RCT2_GLOBAL(0x9E3CDC, uint32); _ebp += RCT2_GLOBAL(0x9E3CE0, uint32); @@ -342,7 +342,7 @@ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp, } //image_type mix with background? - if (image_type & 0x4){ + if (image_type & 0x4){//Not tested int _ebx = RCT2_GLOBAL(0x9ABDA4, uint16); for (int ah = eax >> 8; ah > 0; --ah){ @@ -362,7 +362,7 @@ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp, return; } - if (!(RCT2_GLOBAL(0x9E3D14, uint16) & 1)){ + if (!(RCT2_GLOBAL(0x9E3D14, uint16) & 1)){//Not tested int bx = RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16); for (int ax = RCT2_GLOBAL(0x9ABDAC, uint16); ax > 0; --ax){ memcpy((char*)edi, (char*)esi, bx); @@ -375,7 +375,7 @@ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp, } int _ebx = RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16); - if (RCT2_GLOBAL(0x9E3CDC, uint32) != 0){ + if (RCT2_GLOBAL(0x9E3CDC, uint32) != 0){//Not tested RCT2_GLOBAL(0x9E3D04, uint32) = ebp; uint32 _ebp = RCT2_GLOBAL(0x9E3CDC, uint32); _ebp += RCT2_GLOBAL(0x9E3CE0, uint32); @@ -474,19 +474,20 @@ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpi //Finally after all those checks, copy the image onto the drawing surface //If the image type is not a basic one we require to mix the pixels - if (image_type & 0x2){ + if (image_type & 0x2){//In the .exe these are all unraveled loops for (; no_pixels > 0; --no_pixels, source_pointer++, dest_pointer++){ uint8 al = *source_pointer; uint8 ah = *dest_pointer; - if (image_type & 0x4)//Mix with background and image + if (image_type & 0x4)//Mix with background and image Not Tested al = *((uint8*)(((al | ((int)ah)<<8) - 0x100) + RCT2_GLOBAL(0x9ABDA4, uint32))); else //Adjust colours? al = *((uint8*)(al + RCT2_GLOBAL(0x9ABDA4, uint32))); *dest_pointer = al; } } - else if (image_type & 0x4){ + else if (image_type & 0x4){//In the .exe these are all unraveled loops //Doesnt use source pointer ??? mix with background only? + //Not Tested for (; no_pixels > 0; --no_pixels, source_pointer++, dest_pointer++){ uint8 al = *dest_pointer; al = *((uint8*)(al + RCT2_GLOBAL(0x9ABDA4, uint32))); @@ -587,15 +588,13 @@ void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, */ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) { - //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, dpi, 0); - //return; int eax = 0, ebx = image_id, ecx = x, edx = y, esi = 0, edi = (int)dpi, ebp = 0; int image_type = (image_id & 0xE0000000) >> 28; RCT2_GLOBAL(0x00EDF81C, uint32) = image_id & 0xE0000000; eax = (image_id >> 26) & 0x7; - //eax = RCT2_GLOBAL(0x009E3CE4 + eax*4, uint32); + RCT2_GLOBAL(0x009E3CDC, uint32) = RCT2_GLOBAL(0x009E3CE4 + eax * 4, uint32); if (((image_id)& 0xE0000000) && !(image_id & (1 << 31))) { @@ -618,9 +617,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } else if (((image_id)& 0xE0000000) && !(image_id & (1 << 29))){ - //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); - //return;//jump into 0x67a361 - + //Has not been tested eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; eax >>= 19; @@ -667,8 +664,6 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } else if ((image_id)& 0xE0000000){ - //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0,(int) dpi, 0); - //return; eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; eax >>= 19; @@ -704,16 +699,17 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebx &= 0x7FFFF; ebx <<= 4; ebx += RCT2_ADDRESS_G1_ELEMENTS; - if (dpi->pad_0E >= 1){ + if (dpi->pad_0E >= 1){ //These have not been tested + //something to do with zooming if (dpi->pad_0E == 1){ RCT2_CALLPROC_X(0x0067BD81, eax, ebx, x, y, 0,(int) dpi, ebp); return; } - if (dpi->pad_0E >= 3){ - RCT2_CALLPROC_X(0x0067FAAE, eax, ebx, x, y, 0, (int)dpi, ebp); + if (dpi->pad_0E == 2){ + RCT2_CALLPROC_X(0x0067DADA, eax, ebx, x, y, 0, (int)dpi, ebp); return; } - RCT2_CALLPROC_X(0x0067DADA, eax, ebx, x, y, 0, (int)dpi, ebp); + RCT2_CALLPROC_X(0x0067FAAE, eax, ebx, x, y, 0, (int)dpi, ebp); return; } eax = *((uint32*)ebx + 2); From 503826e76294f3d6ec64d156bcfcad8aa19bbb50 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 23 May 2014 12:08:20 +0100 Subject: [PATCH 49/99] Cleaned up comments added enums to make code easier to read --- src/gfx.c | 49 ++++++++++++++++++++++++------------------------- src/gfx.h | 11 +++++++++++ 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index c979021e37..58192ed5bc 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -454,13 +454,14 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri #define RCT2_DPI_LINE_LENGTH_GLOBAL 0x9ABDB0 //uint16 width+pitch /* -* rct2: 0x67A690 very similar in function to 0x67AA18 readied images are copied onto -* buffers +* rct2: 0x67A690 +* copies a sprite onto the buffer. There is no compression used on the sprite +* image. */ -void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp, int image_type){ +void gfx_bmp_sprite_to_buffer(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp, int image_type){ //Has a background image? - if (image_type & 0x2){ + if (image_type & IMAGE_TYPE_USE_PALATE){ int _ecx = eax >> 8; uint32 _ebx = RCT2_GLOBAL(0x9ABDA4, uint32); _ecx--; @@ -528,7 +529,7 @@ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp, } //image_type mix with background? - if (image_type & 0x4){//Not tested + if (image_type & IMAGE_TYPE_MIX_BACKGROUND){//Not tested int _ebx = RCT2_GLOBAL(0x9ABDA4, uint16); for (int ah = eax >> 8; ah > 0; --ah){ @@ -604,7 +605,7 @@ void sub_0x67A690(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp, * I think its only used for bitmaps onto buttons but i am not sure. * There is still a small bug with this code when it is in the choose park view. */ -void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpixelinfo *dpi, int image_type, int g1_y_start, int g1_y_end, int g1_x_start, int g1_x_end){ +void gfx_rle_sprite_to_buffer(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpixelinfo *dpi, int image_type, int g1_y_start, int g1_y_end, int g1_x_start, int g1_x_end){ uint16 offset_to_first_line = *(uint16*)(g1_y_start*2 + (uint32)source_bits_pointer); //This will now point to the first line char* next_source_pointer = (char*)((uint32)source_bits_pointer + offset_to_first_line); @@ -660,18 +661,18 @@ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpi //Finally after all those checks, copy the image onto the drawing surface //If the image type is not a basic one we require to mix the pixels - if (image_type & 0x2){//In the .exe these are all unraveled loops + if (image_type & IMAGE_TYPE_USE_PALATE){//In the .exe these are all unraveled loops for (; no_pixels > 0; --no_pixels, source_pointer++, dest_pointer++){ uint8 al = *source_pointer; uint8 ah = *dest_pointer; - if (image_type & 0x4)//Mix with background and image Not Tested + if (image_type & IMAGE_TYPE_MIX_BACKGROUND)//Mix with background and image Not Tested al = *((uint8*)(((al | ((int)ah)<<8) - 0x100) + RCT2_GLOBAL(0x9ABDA4, uint32))); else //Adjust colours? al = *((uint8*)(al + RCT2_GLOBAL(0x9ABDA4, uint32))); *dest_pointer = al; } } - else if (image_type & 0x4){//In the .exe these are all unraveled loops + else if (image_type & IMAGE_TYPE_MIX_BACKGROUND){//In the .exe these are all unraveled loops //Doesnt use source pointer ??? mix with background only? //Not Tested for (; no_pixels > 0; --no_pixels, source_pointer++, dest_pointer++){ @@ -693,11 +694,11 @@ void sub_0x67AA18(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpi /* -* rct2: 0x67A934 title screen bitmaps on buttons -* This function readies all the global vars for copying the sprite data onto the screen -* I think its only used for bitmaps onto buttons but i am not sure. +* rct2: 0x67A934 +* Draws a run length encoded sprite +* This function readies all the vars for copying the sprite data onto the screen */ -void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, int y, int image_type){ +void gfx_draw_rle_sprite(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, int y, int image_type){ int g1_y_start, g1_x_start; char* bits_pointer; @@ -762,7 +763,7 @@ void sub_0x67A934(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, if (end_x <= 0)return; } - sub_0x67AA18((char*)source_g1->offset, bits_pointer, dest_dpi, image_type, g1_y_start, end_y, g1_x_start, end_x); + gfx_rle_sprite_to_buffer((char*)source_g1->offset, bits_pointer, dest_dpi, image_type, g1_y_start, end_y, g1_x_start, end_x); } /** @@ -783,9 +784,9 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x009E3CDC, uint32) = RCT2_GLOBAL(0x009E3CE4 + eax * 4, uint32); - if (((image_id)& 0xE0000000) && !(image_id & (1 << 31))) { + if (image_type && !(image_type & IMAGE_TYPE_UNKNOWN)) { - if (!((image_id)& 0x40000000)){ + if (!(image_type & (1 << 2))){ eax = image_id; eax >>= 19; eax &= 0xFF; @@ -802,7 +803,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x9ABDA4, uint32) = eax; } - else if (((image_id)& 0xE0000000) && !(image_id & (1 << 29))){ + else if (image_type && !(image_type & IMAGE_TYPE_USE_PALATE)){ //Has not been tested eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; @@ -834,7 +835,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) //image_id RCT2_GLOBAL(0xEDF81C, uint32) |= 0x20000000; - image_type |= 0x2; + image_type |= IMAGE_TYPE_USE_PALATE; eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); eax <<= 4; @@ -849,7 +850,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) edx = y; } - else if ((image_id)& 0xE0000000){ + else if (image_type){ eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; eax >>= 19; @@ -907,9 +908,8 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x9E3D10, uint32) = *((uint32*)ebx + 2); //X-Y related unsigned? sets RCT2_X_RELATED_GLOBAL_1 and Y RCT2_GLOBAL(0x9E3D14, uint32) = *((uint32*)ebx + 3); - if (RCT2_GLOBAL(0x9E3D14, uint32) & (1 << 2)){ - //Title screen bitmaps - sub_0x67A934(g1_source, dpi, x, y, image_type); + if (g1_source->flags & G1_FLAG_RLE_COMPRESSION){ + gfx_draw_rle_sprite(g1_source, dpi, x, y, image_type); return; } @@ -994,7 +994,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebx = RCT2_GLOBAL(0xEDF81C, uint32); ecx = 0xFFFF&translated_x; //ebx, edx, esi, edi, ah, ebp used in 0x67a690 eax=1966, ecx=ff39, edx=ebx=0, esp = cfca4, ebp = 266, esi =368823e, edi = 16c79b2 - sub_0x67A690(eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp, image_type); + gfx_bmp_sprite_to_buffer(eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp, image_type); return; } //0x67A60A @@ -1045,8 +1045,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebp = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16); ebx = RCT2_GLOBAL(0xEDF81C, uint32); - sub_0x67A690(eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp, image_type); - //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); + gfx_bmp_sprite_to_buffer(eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp, image_type); return; } diff --git a/src/gfx.h b/src/gfx.h index 162ccd121f..733c94d68a 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -46,6 +46,17 @@ typedef struct { sint16 unused; // 0x0E } rct_g1_element; +enum{ + G1_FLAG_RLE_COMPRESSION = (1<<2), +}; + +enum{ + IMAGE_TYPE_NO_BACKGROUND = (1<<0), + IMAGE_TYPE_USE_PALATE = (1<<1), + IMAGE_TYPE_MIX_BACKGROUND = (1<<2), + IMAGE_TYPE_UNKNOWN = (1<<3) +}; + extern int gLastDrawStringX; extern int gLastDrawStringY; From 296e014ac0d9d4b9a7d180f0547ba575970ca4c9 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 23 May 2014 13:03:26 +0100 Subject: [PATCH 50/99] Added palette pointer --- src/gfx.c | 40 ++++++++++++++++++++++------------------ src/gfx.h | 2 +- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 58192ed5bc..33c0093892 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -458,12 +458,12 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri * copies a sprite onto the buffer. There is no compression used on the sprite * image. */ -void gfx_bmp_sprite_to_buffer(int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp, int image_type){ +void gfx_bmp_sprite_to_buffer(char* palette_pointer, int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp, int image_type){ //Has a background image? - if (image_type & IMAGE_TYPE_USE_PALATE){ + if (image_type & IMAGE_TYPE_USE_PALETTE){ int _ecx = eax >> 8; - uint32 _ebx = RCT2_GLOBAL(0x9ABDA4, uint32); + uint32 _ebx = (uint32)palette_pointer; _ecx--; _ecx <<= 0x10; @@ -530,7 +530,7 @@ void gfx_bmp_sprite_to_buffer(int eax, int ebx, int ecx, int edx, int esi, int e //image_type mix with background? if (image_type & IMAGE_TYPE_MIX_BACKGROUND){//Not tested - int _ebx = RCT2_GLOBAL(0x9ABDA4, uint16); + int _ebx = (uint32)palette_pointer; for (int ah = eax >> 8; ah > 0; --ah){ for (int cx = RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16); cx > 0; --ecx){ @@ -551,7 +551,7 @@ void gfx_bmp_sprite_to_buffer(int eax, int ebx, int ecx, int edx, int esi, int e if (!(RCT2_GLOBAL(0x9E3D14, uint16) & 1)){//Not tested int bx = RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16); - for (int ax = RCT2_GLOBAL(0x9ABDAC, uint16); ax > 0; --ax){ + for (int ax = RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, uint16); ax > 0; --ax){ memcpy((char*)edi, (char*)esi, bx); edi += bx; esi += bx; @@ -605,7 +605,7 @@ void gfx_bmp_sprite_to_buffer(int eax, int ebx, int ecx, int edx, int esi, int e * I think its only used for bitmaps onto buttons but i am not sure. * There is still a small bug with this code when it is in the choose park view. */ -void gfx_rle_sprite_to_buffer(char* source_bits_pointer, char* dest_bits_pointer, rct_drawpixelinfo *dpi, int image_type, int g1_y_start, int g1_y_end, int g1_x_start, int g1_x_end){ +void gfx_rle_sprite_to_buffer(char* source_bits_pointer, char* dest_bits_pointer, char* palette_pointer, rct_drawpixelinfo *dpi, int image_type, int g1_y_start, int g1_y_end, int g1_x_start, int g1_x_end){ uint16 offset_to_first_line = *(uint16*)(g1_y_start*2 + (uint32)source_bits_pointer); //This will now point to the first line char* next_source_pointer = (char*)((uint32)source_bits_pointer + offset_to_first_line); @@ -661,14 +661,14 @@ void gfx_rle_sprite_to_buffer(char* source_bits_pointer, char* dest_bits_pointer //Finally after all those checks, copy the image onto the drawing surface //If the image type is not a basic one we require to mix the pixels - if (image_type & IMAGE_TYPE_USE_PALATE){//In the .exe these are all unraveled loops + if (image_type & IMAGE_TYPE_USE_PALETTE){//In the .exe these are all unraveled loops for (; no_pixels > 0; --no_pixels, source_pointer++, dest_pointer++){ uint8 al = *source_pointer; uint8 ah = *dest_pointer; if (image_type & IMAGE_TYPE_MIX_BACKGROUND)//Mix with background and image Not Tested - al = *((uint8*)(((al | ((int)ah)<<8) - 0x100) + RCT2_GLOBAL(0x9ABDA4, uint32))); + al = palette_pointer[(al | ((int)ah) << 8) - 0x100]; else //Adjust colours? - al = *((uint8*)(al + RCT2_GLOBAL(0x9ABDA4, uint32))); + al = palette_pointer[al]; *dest_pointer = al; } } @@ -677,7 +677,7 @@ void gfx_rle_sprite_to_buffer(char* source_bits_pointer, char* dest_bits_pointer //Not Tested for (; no_pixels > 0; --no_pixels, source_pointer++, dest_pointer++){ uint8 al = *dest_pointer; - al = *((uint8*)(al + RCT2_GLOBAL(0x9ABDA4, uint32))); + al = palette_pointer[al]; *dest_pointer = al; } } @@ -698,7 +698,7 @@ void gfx_rle_sprite_to_buffer(char* source_bits_pointer, char* dest_bits_pointer * Draws a run length encoded sprite * This function readies all the vars for copying the sprite data onto the screen */ -void gfx_draw_rle_sprite(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, int y, int image_type){ +void gfx_draw_rle_sprite(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, int y, int image_type, char* palette_pointer){ int g1_y_start, g1_x_start; char* bits_pointer; @@ -763,7 +763,7 @@ void gfx_draw_rle_sprite(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, if (end_x <= 0)return; } - gfx_rle_sprite_to_buffer((char*)source_g1->offset, bits_pointer, dest_dpi, image_type, g1_y_start, end_y, g1_x_start, end_x); + gfx_rle_sprite_to_buffer((char*)source_g1->offset, bits_pointer, palette_pointer, dest_dpi, image_type, g1_y_start, end_y, g1_x_start, end_x); } /** @@ -779,6 +779,8 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) int eax = 0, ebx = image_id, ecx = x, edx = y, esi = 0, edi = (int)dpi, ebp = 0; int image_type = (image_id & 0xE0000000) >> 28; + char* palette_pointer = NULL; + RCT2_GLOBAL(0x00EDF81C, uint32) = image_id & 0xE0000000; eax = (image_id >> 26) & 0x7; @@ -801,9 +803,9 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax <<= 4; eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); RCT2_GLOBAL(0x9ABDA4, uint32) = eax; - + palette_pointer = (char*)eax; } - else if (image_type && !(image_type & IMAGE_TYPE_USE_PALATE)){ + else if (image_type && !(image_type & IMAGE_TYPE_USE_PALETTE)){ //Has not been tested eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; @@ -835,7 +837,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) //image_id RCT2_GLOBAL(0xEDF81C, uint32) |= 0x20000000; - image_type |= IMAGE_TYPE_USE_PALATE; + image_type |= IMAGE_TYPE_USE_PALETTE; eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); eax <<= 4; @@ -846,6 +848,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x9ABFDA, uint32) = esi; edx = *((uint32*)(eax + 0xFB)); RCT2_GLOBAL(0x9ABDA4, uint32) = 0x9ABF0C; + palette_pointer = (char*)0x9ABF0C; RCT2_GLOBAL(0x9ABFDE, uint32) = edx; edx = y; @@ -879,6 +882,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebp = *((uint32*)(eax + 0xFB)); RCT2_GLOBAL(0x9ABDA4, uint32) = 0x009ABE0C; + palette_pointer = (char*)0x9ABE0C; RCT2_GLOBAL(0x9ABEDE, uint32) = ebp; } @@ -909,7 +913,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x9E3D14, uint32) = *((uint32*)ebx + 3); if (g1_source->flags & G1_FLAG_RLE_COMPRESSION){ - gfx_draw_rle_sprite(g1_source, dpi, x, y, image_type); + gfx_draw_rle_sprite(g1_source, dpi, x, y, image_type, palette_pointer); return; } @@ -994,7 +998,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebx = RCT2_GLOBAL(0xEDF81C, uint32); ecx = 0xFFFF&translated_x; //ebx, edx, esi, edi, ah, ebp used in 0x67a690 eax=1966, ecx=ff39, edx=ebx=0, esp = cfca4, ebp = 266, esi =368823e, edi = 16c79b2 - gfx_bmp_sprite_to_buffer(eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp, image_type); + gfx_bmp_sprite_to_buffer(palette_pointer,eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp, image_type); return; } //0x67A60A @@ -1045,7 +1049,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebp = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16); ebx = RCT2_GLOBAL(0xEDF81C, uint32); - gfx_bmp_sprite_to_buffer(eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp, image_type); + gfx_bmp_sprite_to_buffer(palette_pointer, eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp, image_type); return; } diff --git a/src/gfx.h b/src/gfx.h index 733c94d68a..51ceee10c8 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -52,7 +52,7 @@ enum{ enum{ IMAGE_TYPE_NO_BACKGROUND = (1<<0), - IMAGE_TYPE_USE_PALATE = (1<<1), + IMAGE_TYPE_USE_PALETTE= (1 << 1), IMAGE_TYPE_MIX_BACKGROUND = (1<<2), IMAGE_TYPE_UNKNOWN = (1<<3) }; From 0b20f94182bfb82361c09fee77b70908dcae8b98 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 23 May 2014 13:57:47 +0100 Subject: [PATCH 51/99] Added more readable variable names --- src/gfx.c | 112 +++++++++++++++++++++++++++--------------------------- src/gfx.h | 2 +- 2 files changed, 56 insertions(+), 58 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 33c0093892..b58b433078 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -458,11 +458,11 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri * copies a sprite onto the buffer. There is no compression used on the sprite * image. */ -void gfx_bmp_sprite_to_buffer(char* palette_pointer, int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp, int image_type){ +void gfx_bmp_sprite_to_buffer(char* palette_pointer, char* source_pointer, char* dest_pointer, int end_y, int end_x, int edx, int ebp, int image_type){ //Has a background image? if (image_type & IMAGE_TYPE_USE_PALETTE){ - int _ecx = eax >> 8; + int _ecx = end_y; uint32 _ebx = (uint32)palette_pointer; _ecx--; _ecx <<= 0x10; @@ -474,56 +474,56 @@ void gfx_bmp_sprite_to_buffer(char* palette_pointer, int eax, int ebx, int ecx, _ebp += RCT2_GLOBAL(0x9E3CE0, uint32); for (_ecx >>= 0x10; _ecx >= 0; --_ecx){ - for (int _cx = RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16); _cx > 0; --_cx){ - uint8 al = *((char*)esi); - esi++; + for (int _cx = end_x; _cx > 0; --_cx){ + uint8 al = *source_pointer; + source_pointer++; al = *((char*)_ebx + al); al &= *((char*)_ebp); if (al){ - *((char*)edi) = al; + *dest_pointer = al; } - edi++; + dest_pointer++; _ebp++; } - esi += edx; - edi += RCT2_GLOBAL(0x9E3D04, uint32); + source_pointer += edx; + dest_pointer += RCT2_GLOBAL(0x9E3D04, uint32); _ebp += edx; } return; } //Quicker? - if ((RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16)) == 4){ + if (end_x == 4){ ebp += 4; edx += 4; for (_ecx >>= 0x10; _ecx >= 0; --_ecx){ for (int i = 0; i < 4; ++i){ - uint8 al = *((char*)esi+i); + uint8 al = *(source_pointer + i); al = *((char*)_ebx + al); if (al){ - *((char*)edi+i) = al; + *(dest_pointer + i) = al; } } - edi += ebp; - esi += edx; + dest_pointer += ebp; + source_pointer += edx; } return; } //image colour adjusted? for (_ecx >>= 0x10; _ecx >= 0; --_ecx){ - for (int _cx = RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16); _cx > 0; --_cx){ - uint8 al = *((char*)esi); - esi++; + for (int _cx = end_x; _cx > 0; --_cx){ + uint8 al = *source_pointer; + source_pointer++; al = *((char*)_ebx + al); if (al){ - *((char*)edi) = al; + *dest_pointer = al; } - edi++; + dest_pointer++; } - esi += edx; - edi += ebp; + source_pointer += edx; + dest_pointer += ebp; } return; } @@ -531,70 +531,70 @@ void gfx_bmp_sprite_to_buffer(char* palette_pointer, int eax, int ebx, int ecx, //image_type mix with background? if (image_type & IMAGE_TYPE_MIX_BACKGROUND){//Not tested int _ebx = (uint32)palette_pointer; - for (int ah = eax >> 8; ah > 0; --ah){ + for (int ah = end_y; ah > 0; --ah){ - for (int cx = RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16); cx > 0; --ecx){ - uint8 al = *((char*)esi); - esi++; + for (int cx = end_x; cx > 0; --cx){ + uint8 al = *source_pointer; + source_pointer++; if (al){ - al = *((char*)edi); + al = *dest_pointer; al = *((char*)_ebx + al); - *((char*)edi) = al; + *dest_pointer = al; } - edi++; + dest_pointer++; } - esi += edx; - edi += ebp; + source_pointer += edx; + dest_pointer += ebp; } return; } if (!(RCT2_GLOBAL(0x9E3D14, uint16) & 1)){//Not tested - int bx = RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16); - for (int ax = RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, uint16); ax > 0; --ax){ - memcpy((char*)edi, (char*)esi, bx); - edi += bx; - esi += bx; - edi += ebp; - esi += edx; + int bx = end_x; + for (int ax = end_y; ax > 0; --ax){ + memcpy(dest_pointer, source_pointer, bx); + dest_pointer += bx; + source_pointer += bx; + dest_pointer += ebp; + source_pointer += edx; } return; } - int _ebx = RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, uint16); + int _ebx = end_x; if (RCT2_GLOBAL(0x9E3CDC, uint32) != 0){//Not tested RCT2_GLOBAL(0x9E3D04, uint32) = ebp; uint32 _ebp = RCT2_GLOBAL(0x9E3CDC, uint32); _ebp += RCT2_GLOBAL(0x9E3CE0, uint32); - for (int ah = eax >> 8; ah > 0; --ah){ + for (int ah = end_y; ah > 0; --ah){ for (int _ecx = _ebx; _ecx > 0; --_ecx){ - char al = *((char*)esi); - esi++; + char al = *source_pointer; + source_pointer++; al &= *((char*)_ebp); if (al){ - *((char*)edi) = al; + *dest_pointer = al; } - edi++; + dest_pointer++; _ebp++; } - esi += edx; - edi += RCT2_GLOBAL(0x9E3D04, uint32); + source_pointer += edx; + dest_pointer += RCT2_GLOBAL(0x9E3D04, uint32); _ebp += edx; } } - for (int ah = eax >> 8; ah > 0; --ah){ + for (int no_lines = end_y; no_lines > 0; --no_lines){ for (int _ecx = _ebx; _ecx > 0; --_ecx){ - char al = *((char*)esi); - esi++; + char al = *source_pointer; + source_pointer++; if (al){ - *((char*)edi) = al; + *dest_pointer = al; } - edi++; + dest_pointer++; } - esi += edx; - edi += ebp; + source_pointer += edx; + dest_pointer += ebp; } return; } @@ -992,13 +992,12 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) if (!(g1_source->flags & 0x02)){ eax = RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, uint8); - eax <<= 8; edx = RCT2_GLOBAL(0x9ABDAE, uint16); ebp = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16); ebx = RCT2_GLOBAL(0xEDF81C, uint32); - ecx = 0xFFFF&translated_x; + //ebx, edx, esi, edi, ah, ebp used in 0x67a690 eax=1966, ecx=ff39, edx=ebx=0, esp = cfca4, ebp = 266, esi =368823e, edi = 16c79b2 - gfx_bmp_sprite_to_buffer(palette_pointer,eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp, image_type); + gfx_bmp_sprite_to_buffer(palette_pointer, (char*)esi, bits_pointer, eax, RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16), edx, ebp, image_type); return; } //0x67A60A @@ -1044,12 +1043,11 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) esi = ebp; esi += 0x9E3D28; eax = RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, uint8); - eax <<= 8; edx = RCT2_GLOBAL(0x9ABDAE, uint16); ebp = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16); ebx = RCT2_GLOBAL(0xEDF81C, uint32); - gfx_bmp_sprite_to_buffer(palette_pointer, eax, ebx, ecx, edx, esi, (int)bits_pointer, ebp, image_type); + gfx_bmp_sprite_to_buffer(palette_pointer, (char*)esi, bits_pointer, eax, RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16), edx, ebp, image_type); return; } diff --git a/src/gfx.h b/src/gfx.h index 51ceee10c8..f748c02fc8 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -51,7 +51,7 @@ enum{ }; enum{ - IMAGE_TYPE_NO_BACKGROUND = (1<<0), + IMAGE_TYPE_NO_BACKGROUND = 0, IMAGE_TYPE_USE_PALETTE= (1 << 1), IMAGE_TYPE_MIX_BACKGROUND = (1<<2), IMAGE_TYPE_UNKNOWN = (1<<3) From 20d136bacfe82e51e4a1d54005d3cc74ebd16097 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sat, 24 May 2014 10:53:34 +0100 Subject: [PATCH 52/99] Started to turn the buffer code into legable C --- src/gfx.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index b58b433078..052b09ca3d 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -462,22 +462,17 @@ void gfx_bmp_sprite_to_buffer(char* palette_pointer, char* source_pointer, char* //Has a background image? if (image_type & IMAGE_TYPE_USE_PALETTE){ - int _ecx = end_y; - uint32 _ebx = (uint32)palette_pointer; - _ecx--; - _ecx <<= 0x10; - //Mix with background image and colour adjusted if (RCT2_GLOBAL(0x9E3CDC, uint32)){ //Not tested RCT2_GLOBAL(0x9E3D04, uint32) = ebp; uint32 _ebp = RCT2_GLOBAL(0x9E3CDC, uint32); _ebp += RCT2_GLOBAL(0x9E3CE0, uint32); - for (_ecx >>= 0x10; _ecx >= 0; --_ecx){ + for (; end_y > 0; --end_y){ for (int _cx = end_x; _cx > 0; --_cx){ uint8 al = *source_pointer; source_pointer++; - al = *((char*)_ebx + al); + al = palette_pointer[al]; al &= *((char*)_ebp); if (al){ *dest_pointer = al; @@ -497,10 +492,10 @@ void gfx_bmp_sprite_to_buffer(char* palette_pointer, char* source_pointer, char* ebp += 4; edx += 4; - for (_ecx >>= 0x10; _ecx >= 0; --_ecx){ + for (; end_y > 0; --end_y){ for (int i = 0; i < 4; ++i){ uint8 al = *(source_pointer + i); - al = *((char*)_ebx + al); + al = palette_pointer[al]; if (al){ *(dest_pointer + i) = al; } @@ -512,11 +507,11 @@ void gfx_bmp_sprite_to_buffer(char* palette_pointer, char* source_pointer, char* } //image colour adjusted? - for (_ecx >>= 0x10; _ecx >= 0; --_ecx){ + for (; end_y > 0; --end_y){ for (int _cx = end_x; _cx > 0; --_cx){ uint8 al = *source_pointer; source_pointer++; - al = *((char*)_ebx + al); + al = palette_pointer[al]; if (al){ *dest_pointer = al; } @@ -788,7 +783,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) if (image_type && !(image_type & IMAGE_TYPE_UNKNOWN)) { - if (!(image_type & (1 << 2))){ + if (!(image_type & IMAGE_TYPE_MIX_BACKGROUND)){ eax = image_id; eax >>= 19; eax &= 0xFF; @@ -996,7 +991,6 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebp = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16); ebx = RCT2_GLOBAL(0xEDF81C, uint32); - //ebx, edx, esi, edi, ah, ebp used in 0x67a690 eax=1966, ecx=ff39, edx=ebx=0, esp = cfca4, ebp = 266, esi =368823e, edi = 16c79b2 gfx_bmp_sprite_to_buffer(palette_pointer, (char*)esi, bits_pointer, eax, RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16), edx, ebp, image_type); return; } From b3ced1eedc9b27bdf8480a22416e8c152178d13a Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sat, 24 May 2014 14:41:33 +0100 Subject: [PATCH 53/99] more C cleanup --- src/gfx.c | 127 +++++++++++++++++++++++++----------------------------- 1 file changed, 59 insertions(+), 68 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 052b09ca3d..459fc31379 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -458,67 +458,65 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri * copies a sprite onto the buffer. There is no compression used on the sprite * image. */ -void gfx_bmp_sprite_to_buffer(char* palette_pointer, char* source_pointer, char* dest_pointer, int end_y, int end_x, int edx, int ebp, int image_type){ +void gfx_bmp_sprite_to_buffer(char* palette_pointer, char* source_pointer, char* dest_pointer, rct_g1_element* source_image, rct_drawpixelinfo *dest_dpi, int height, int width, int image_type){ //Has a background image? if (image_type & IMAGE_TYPE_USE_PALETTE){ //Mix with background image and colour adjusted if (RCT2_GLOBAL(0x9E3CDC, uint32)){ //Not tested - RCT2_GLOBAL(0x9E3D04, uint32) = ebp; + uint32 _ebp = RCT2_GLOBAL(0x9E3CDC, uint32); _ebp += RCT2_GLOBAL(0x9E3CE0, uint32); - for (; end_y > 0; --end_y){ - for (int _cx = end_x; _cx > 0; --_cx){ - uint8 al = *source_pointer; + for (; height > 0; --height){ + for (int no_pixels = width; no_pixels > 0; --no_pixels){ + uint8 pixel = *source_pointer; source_pointer++; - al = palette_pointer[al]; - al &= *((char*)_ebp); - if (al){ - *dest_pointer = al; + pixel = palette_pointer[pixel]; + pixel &= *((char*)_ebp); + if (pixel){ + *dest_pointer = pixel; } dest_pointer++; _ebp++; } - source_pointer += edx; - dest_pointer += RCT2_GLOBAL(0x9E3D04, uint32); - _ebp += edx; + source_pointer += source_image->width - width; + dest_pointer += dest_dpi->width + dest_dpi->pitch - width; + _ebp += source_image->width - width; } return; } //Quicker? - if (end_x == 4){ + if (width == 4){ - ebp += 4; - edx += 4; - for (; end_y > 0; --end_y){ - for (int i = 0; i < 4; ++i){ - uint8 al = *(source_pointer + i); - al = palette_pointer[al]; - if (al){ - *(dest_pointer + i) = al; + for (; height > 0; --height){ + for (int no_pixels = 0; no_pixels < 4; ++no_pixels){ + uint8 pixel = source_pointer[no_pixels]; + pixel = palette_pointer[pixel]; + if (pixel){ + dest_pointer[no_pixels] = pixel; } } - dest_pointer += ebp; - source_pointer += edx; + dest_pointer += dest_dpi->width + dest_dpi->pitch - width + 4; + source_pointer += source_image->width - width + 4; } return; } //image colour adjusted? - for (; end_y > 0; --end_y){ - for (int _cx = end_x; _cx > 0; --_cx){ - uint8 al = *source_pointer; + for (; height > 0; --height){ + for (int no_pixels = width; no_pixels > 0; --no_pixels){ + uint8 pixel = *source_pointer; source_pointer++; - al = palette_pointer[al]; - if (al){ - *dest_pointer = al; + pixel = palette_pointer[pixel]; + if (pixel){ + *dest_pointer = pixel; } dest_pointer++; } - source_pointer += edx; - dest_pointer += ebp; + source_pointer += source_image->width - width; + dest_pointer += dest_dpi->width + dest_dpi->pitch - width; } return; } @@ -526,9 +524,10 @@ void gfx_bmp_sprite_to_buffer(char* palette_pointer, char* source_pointer, char* //image_type mix with background? if (image_type & IMAGE_TYPE_MIX_BACKGROUND){//Not tested int _ebx = (uint32)palette_pointer; - for (int ah = end_y; ah > 0; --ah){ + for (int ah = height; ah > 0; --ah){ - for (int cx = end_x; cx > 0; --cx){ + for (int no_pixels = width; no_pixels > 0; --no_pixels){ + //Check this uint8 al = *source_pointer; source_pointer++; if (al){ @@ -538,58 +537,57 @@ void gfx_bmp_sprite_to_buffer(char* palette_pointer, char* source_pointer, char* } dest_pointer++; } - source_pointer += edx; - dest_pointer += ebp; + source_pointer += source_image->width - width; + dest_pointer += dest_dpi->width + dest_dpi->pitch - width; } return; } if (!(RCT2_GLOBAL(0x9E3D14, uint16) & 1)){//Not tested - int bx = end_x; - for (int ax = end_y; ax > 0; --ax){ + int bx = width; + for (int ax = height; ax > 0; --ax){ memcpy(dest_pointer, source_pointer, bx); dest_pointer += bx; source_pointer += bx; - dest_pointer += ebp; - source_pointer += edx; + dest_pointer += dest_dpi->width + dest_dpi->pitch - width; + source_pointer += source_image->width - width; } return; } - int _ebx = end_x; + int _ebx = width; if (RCT2_GLOBAL(0x9E3CDC, uint32) != 0){//Not tested - RCT2_GLOBAL(0x9E3D04, uint32) = ebp; uint32 _ebp = RCT2_GLOBAL(0x9E3CDC, uint32); _ebp += RCT2_GLOBAL(0x9E3CE0, uint32); - for (int ah = end_y; ah > 0; --ah){ + for (int ah = height; ah > 0; --ah){ for (int _ecx = _ebx; _ecx > 0; --_ecx){ - char al = *source_pointer; + char pixel = *source_pointer; source_pointer++; - al &= *((char*)_ebp); - if (al){ - *dest_pointer = al; + pixel &= *((char*)_ebp); + if (pixel){ + *dest_pointer = pixel; } dest_pointer++; _ebp++; } - source_pointer += edx; - dest_pointer += RCT2_GLOBAL(0x9E3D04, uint32); - _ebp += edx; + source_pointer += source_image->width - width; + dest_pointer += dest_dpi->width + dest_dpi->pitch - width; + _ebp += source_image->width - width; } } - for (int no_lines = end_y; no_lines > 0; --no_lines){ + for (int no_lines = height; no_lines > 0; --no_lines){ for (int _ecx = _ebx; _ecx > 0; --_ecx){ - char al = *source_pointer; + char pixel = *source_pointer; source_pointer++; - if (al){ - *dest_pointer = al; + if (pixel){ + *dest_pointer = pixel; } dest_pointer++; } - source_pointer += edx; - dest_pointer += ebp; + source_pointer += source_image->width - width; + dest_pointer += dest_dpi->width + dest_dpi->pitch - width; } return; } @@ -671,9 +669,9 @@ void gfx_rle_sprite_to_buffer(char* source_bits_pointer, char* dest_bits_pointer //Doesnt use source pointer ??? mix with background only? //Not Tested for (; no_pixels > 0; --no_pixels, source_pointer++, dest_pointer++){ - uint8 al = *dest_pointer; - al = palette_pointer[al]; - *dest_pointer = al; + uint8 pixel = *dest_pointer; + pixel = palette_pointer[pixel]; + *dest_pointer = pixel; } } else @@ -987,11 +985,8 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) if (!(g1_source->flags & 0x02)){ eax = RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, uint8); - edx = RCT2_GLOBAL(0x9ABDAE, uint16); - ebp = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16); - ebx = RCT2_GLOBAL(0xEDF81C, uint32); - - gfx_bmp_sprite_to_buffer(palette_pointer, (char*)esi, bits_pointer, eax, RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16), edx, ebp, image_type); + + gfx_bmp_sprite_to_buffer(palette_pointer, (char*)esi, bits_pointer, g1_source, dpi, eax, RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16), image_type); return; } //0x67A60A @@ -1037,11 +1032,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) esi = ebp; esi += 0x9E3D28; eax = RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, uint8); - edx = RCT2_GLOBAL(0x9ABDAE, uint16); - ebp = RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16); - ebx = RCT2_GLOBAL(0xEDF81C, uint32); - - gfx_bmp_sprite_to_buffer(palette_pointer, (char*)esi, bits_pointer, eax, RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16), edx, ebp, image_type); + gfx_bmp_sprite_to_buffer(palette_pointer, (char*)esi, bits_pointer, g1_source, dpi, eax, RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16), image_type); return; } From 08dcee5d92aae05701cea8f9c2f2fe2b1f39c58c Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sat, 24 May 2014 18:35:33 +0100 Subject: [PATCH 54/99] Translated more into C --- src/gfx.c | 97 ++++++++++++++++++++++++------------------------------- src/gfx.h | 1 + 2 files changed, 43 insertions(+), 55 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 459fc31379..a2de032087 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -459,14 +459,14 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri * image. */ void gfx_bmp_sprite_to_buffer(char* palette_pointer, char* source_pointer, char* dest_pointer, rct_g1_element* source_image, rct_drawpixelinfo *dest_dpi, int height, int width, int image_type){ - - //Has a background image? + //Requires use of palette? if (image_type & IMAGE_TYPE_USE_PALETTE){ - //Mix with background image and colour adjusted - if (RCT2_GLOBAL(0x9E3CDC, uint32)){ //Not tested + + //Mix with another image?? and colour adjusted + if (RCT2_GLOBAL(0x9E3CDC, uint32)){ //Not tested. I can't actually work out when this code runs. uint32 _ebp = RCT2_GLOBAL(0x9E3CDC, uint32); - _ebp += RCT2_GLOBAL(0x9E3CE0, uint32); + _ebp += source_pointer - source_image->offset;// RCT2_GLOBAL(0x9E3CE0, uint32); for (; height > 0; --height){ for (int no_pixels = width; no_pixels > 0; --no_pixels){ @@ -521,19 +521,17 @@ void gfx_bmp_sprite_to_buffer(char* palette_pointer, char* source_pointer, char* return; } - //image_type mix with background? + //Mix with background. It only uses source pointer for + //telling if it needs to be drawn not for colour. if (image_type & IMAGE_TYPE_MIX_BACKGROUND){//Not tested - int _ebx = (uint32)palette_pointer; - for (int ah = height; ah > 0; --ah){ - + for (; height > 0; --height){ for (int no_pixels = width; no_pixels > 0; --no_pixels){ - //Check this - uint8 al = *source_pointer; + uint8 pixel = *source_pointer; source_pointer++; - if (al){ - al = *dest_pointer; - al = *((char*)_ebx + al); - *dest_pointer = al; + if (pixel){ + pixel = *dest_pointer; + pixel = palette_pointer[pixel]; + *dest_pointer = pixel; } dest_pointer++; } @@ -543,26 +541,23 @@ void gfx_bmp_sprite_to_buffer(char* palette_pointer, char* source_pointer, char* return; } - if (!(RCT2_GLOBAL(0x9E3D14, uint16) & 1)){//Not tested - int bx = width; - for (int ax = height; ax > 0; --ax){ - memcpy(dest_pointer, source_pointer, bx); - dest_pointer += bx; - source_pointer += bx; - dest_pointer += dest_dpi->width + dest_dpi->pitch - width; - source_pointer += source_image->width - width; + //Basic bitmap no fancy stuff + if (!(source_image->flags & G1_FLAG_BMP)){//Not tested + for (; height > 0; --height){ + memcpy(dest_pointer, source_pointer, width); + dest_pointer += dest_dpi->width + dest_dpi->pitch; + source_pointer += source_image->width; } return; } - int _ebx = width; - if (RCT2_GLOBAL(0x9E3CDC, uint32) != 0){//Not tested + if (RCT2_GLOBAL(0x9E3CDC, uint32) != 0){//Not tested. I can't actually work out when this code runs. uint32 _ebp = RCT2_GLOBAL(0x9E3CDC, uint32); - _ebp += RCT2_GLOBAL(0x9E3CE0, uint32); + _ebp += source_pointer - source_image->offset;// RCT2_GLOBAL(0x9E3CE0, uint32); - for (int ah = height; ah > 0; --ah){ - for (int _ecx = _ebx; _ecx > 0; --_ecx){ - char pixel = *source_pointer; + for (; height > 0; --height){ + for (int no_pixels = width; no_pixels > 0; --no_pixels){ + uint8 pixel = *source_pointer; source_pointer++; pixel &= *((char*)_ebp); if (pixel){ @@ -577,9 +572,10 @@ void gfx_bmp_sprite_to_buffer(char* palette_pointer, char* source_pointer, char* } } + //Basic bitmap with no draw pixels for (int no_lines = height; no_lines > 0; --no_lines){ - for (int _ecx = _ebx; _ecx > 0; --_ecx){ - char pixel = *source_pointer; + for (int no_pixels = width; no_pixels > 0; --no_pixels){ + uint8 pixel = *source_pointer; source_pointer++; if (pixel){ *dest_pointer = pixel; @@ -918,18 +914,13 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) esi = (int)g1_source->offset;//RCT2_GLOBAL(0x9E3D08, uint32); RCT2_GLOBAL(0x9E3CE0, uint32) = 0; bits_pointer = dpi->bits; - - RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) = g1_source->height;// RCT2_GLOBAL(0x9E3D0E, sint16); + int height = g1_source->height; translated_y = y - dpi->y + g1_source->y_offset;//RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16); - if (image_id == 5200){ - image_id = image_id; - } - if (translated_y < 0){ - RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) += translated_y; - if (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) <= 0){ + height += translated_y; + if (height <= 0){ return; } translated_y = -translated_y; @@ -944,21 +935,20 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) translated_y += RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) - dpi->height; if (translated_y > 0){ - RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) -= translated_y; - if (RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) <= 0)return; + height -= translated_y; + if (height <= 0)return; } - - RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) = g1_source->width;// RCT2_GLOBAL(0x9E3D0C, sint16); + + int width = g1_source->width; eax = dpi->width + dpi->pitch - g1_source->width; //RCT2_GLOBAL(0x9E3D0C, sint16); RCT2_GLOBAL(0x9ABDAE, uint16) = 0; RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16) = dpi->width + dpi->pitch - g1_source->width;// RCT2_GLOBAL(0x9E3D0C, sint16); translated_x = x - dpi->x + g1_source->x_offset;//RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_1, uint16); - + if (translated_x < 0){ - - RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) += translated_x; - if (RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) <= 0){ + width += translated_x; + if (width <= 0){ return; } @@ -970,23 +960,21 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } bits_pointer += translated_x; - translated_x += RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16); + translated_x += width; translated_x -= dpi->width; if (translated_x > 0){ - RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) -= translated_x; - if (RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16) <= 0)return; + width -= translated_x; + if (width <= 0)return; RCT2_GLOBAL(0x9ABDAE, uint16) += translated_x; RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16) += translated_x; } if (!(g1_source->flags & 0x02)){ - eax = RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, uint8); - - gfx_bmp_sprite_to_buffer(palette_pointer, (char*)esi, bits_pointer, g1_source, dpi, eax, RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16), image_type); + gfx_bmp_sprite_to_buffer(palette_pointer, (char*)esi, bits_pointer, g1_source, dpi, height, width, image_type); return; } //0x67A60A @@ -1031,8 +1019,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) //edi poped off stack esi = ebp; esi += 0x9E3D28; - eax = RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, uint8); - gfx_bmp_sprite_to_buffer(palette_pointer, (char*)esi, bits_pointer, g1_source, dpi, eax, RCT2_GLOBAL(RCT2_X_END_POINT_GLOBAL, sint16), image_type); + gfx_bmp_sprite_to_buffer(palette_pointer, (char*)esi, bits_pointer, g1_source, dpi, height, width, image_type); return; } diff --git a/src/gfx.h b/src/gfx.h index f748c02fc8..054fd31a94 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -47,6 +47,7 @@ typedef struct { } rct_g1_element; enum{ + G1_FLAG_BMP = (1 << 0), //No invisible sections G1_FLAG_RLE_COMPRESSION = (1<<2), }; From fdca2fb275ee4b4c4d762c0e73b953094f03d86f Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sat, 24 May 2014 20:18:48 +0100 Subject: [PATCH 55/99] Even more c clean up --- src/gfx.c | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index a2de032087..dafddd9546 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -906,17 +906,16 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) return; } - //dpi on stack int translated_x, translated_y; - char* bits_pointer; + char* dest_pointer; + char* source_pointer; - ebp = (int)dpi; - esi = (int)g1_source->offset;//RCT2_GLOBAL(0x9E3D08, uint32); - RCT2_GLOBAL(0x9E3CE0, uint32) = 0; - bits_pointer = dpi->bits; + source_pointer = g1_source->offset; + + dest_pointer = dpi->bits; int height = g1_source->height; - translated_y = y - dpi->y + g1_source->y_offset;//RCT2_GLOBAL(RCT2_Y_RELATED_GLOBAL_1, uint16); + translated_y = y - dpi->y + g1_source->y_offset; if (translated_y < 0){ height += translated_y; @@ -924,15 +923,14 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) return; } translated_y = -translated_y; - esi += (uint32)translated_y * g1_source->width;//RCT2_GLOBAL(0x9E3D0C, sint16); - RCT2_GLOBAL(0x9E3CE0, sint32) += translated_y * g1_source->width;//RCT2_GLOBAL(0x9E3D0C, sint16); + source_pointer += (uint32)translated_y * g1_source->width; + translated_y = 0; } else { - //eax = ; - bits_pointer += (dpi->width + dpi->pitch) * translated_y;//eax; + dest_pointer += (dpi->width + dpi->pitch) * translated_y; } - translated_y += RCT2_GLOBAL(RCT2_Y_END_POINT_GLOBAL, sint16) - dpi->height; + translated_y += height - dpi->height; if (translated_y > 0){ height -= translated_y; @@ -940,26 +938,19 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } int width = g1_source->width; - eax = dpi->width + dpi->pitch - g1_source->width; //RCT2_GLOBAL(0x9E3D0C, sint16); - RCT2_GLOBAL(0x9ABDAE, uint16) = 0; - RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16) = dpi->width + dpi->pitch - g1_source->width;// RCT2_GLOBAL(0x9E3D0C, sint16); - translated_x = x - dpi->x + g1_source->x_offset;//RCT2_GLOBAL(RCT2_X_RELATED_GLOBAL_1, uint16); + translated_x = x - dpi->x + g1_source->x_offset; if (translated_x < 0){ width += translated_x; if (width <= 0){ return; } - - RCT2_GLOBAL(0x9ABDAE, sint16) -= translated_x; - esi -= translated_x; - RCT2_GLOBAL(0x9E3CE0, sint32) -= translated_x; - RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, sint16) -= translated_x; + source_pointer -= translated_x; translated_x = 0; } - bits_pointer += translated_x; + dest_pointer += translated_x; translated_x += width; @@ -968,19 +959,16 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) if (translated_x > 0){ width -= translated_x; if (width <= 0)return; - - RCT2_GLOBAL(0x9ABDAE, uint16) += translated_x; - RCT2_GLOBAL(RCT2_DPI_LINE_LENGTH_GLOBAL, uint16) += translated_x; } if (!(g1_source->flags & 0x02)){ - gfx_bmp_sprite_to_buffer(palette_pointer, (char*)esi, bits_pointer, g1_source, dpi, height, width, image_type); + gfx_bmp_sprite_to_buffer(palette_pointer, source_pointer, dest_pointer, g1_source, dpi, height, width, image_type); return; } //0x67A60A esi -= (uint32)g1_source->offset; - ebp = esi; + ebp = (int)source_pointer; eax = g1_source->width*g1_source->height; esi = (int)g1_source->offset; edx = eax; @@ -1019,7 +1007,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) //edi poped off stack esi = ebp; esi += 0x9E3D28; - gfx_bmp_sprite_to_buffer(palette_pointer, (char*)esi, bits_pointer, g1_source, dpi, height, width, image_type); + gfx_bmp_sprite_to_buffer(palette_pointer, (char*)esi, dest_pointer, g1_source, dpi, height, width, image_type); return; } From af33568f015c9d43fa29e63949ad8eac881c6700 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 25 May 2014 09:30:54 +0100 Subject: [PATCH 56/99] Cleaned up functions brought two identical ones together --- src/gfx.c | 189 +++++++++++++++--------------------------------------- 1 file changed, 52 insertions(+), 137 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index dafddd9546..f64d9299fa 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -458,7 +458,7 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri * copies a sprite onto the buffer. There is no compression used on the sprite * image. */ -void gfx_bmp_sprite_to_buffer(char* palette_pointer, char* source_pointer, char* dest_pointer, rct_g1_element* source_image, rct_drawpixelinfo *dest_dpi, int height, int width, int image_type){ +void gfx_bmp_sprite_to_buffer(uint8* palette_pointer, uint8* source_pointer, uint8* dest_pointer, rct_g1_element* source_image, rct_drawpixelinfo *dest_dpi, int height, int width, int image_type){ //Requires use of palette? if (image_type & IMAGE_TYPE_USE_PALETTE){ @@ -473,7 +473,7 @@ void gfx_bmp_sprite_to_buffer(char* palette_pointer, char* source_pointer, char* uint8 pixel = *source_pointer; source_pointer++; pixel = palette_pointer[pixel]; - pixel &= *((char*)_ebp); + pixel &= *((uint8*)_ebp); if (pixel){ *dest_pointer = pixel; } @@ -594,22 +594,24 @@ void gfx_bmp_sprite_to_buffer(char* palette_pointer, char* source_pointer, char* * I think its only used for bitmaps onto buttons but i am not sure. * There is still a small bug with this code when it is in the choose park view. */ -void gfx_rle_sprite_to_buffer(char* source_bits_pointer, char* dest_bits_pointer, char* palette_pointer, rct_drawpixelinfo *dpi, int image_type, int g1_y_start, int g1_y_end, int g1_x_start, int g1_x_end){ - uint16 offset_to_first_line = *(uint16*)(g1_y_start*2 + (uint32)source_bits_pointer); +void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_pointer, uint8* palette_pointer, rct_drawpixelinfo *dpi, int image_type, int source_y_start, int height, int source_x_start, int width){ + uint16 offset_to_first_line = ((uint16*)source_bits_pointer)[source_y_start]; //This will now point to the first line - char* next_source_pointer = (char*)((uint32)source_bits_pointer + offset_to_first_line); - char* next_dest_pointer = dest_bits_pointer; + uint8* next_source_pointer = source_bits_pointer + offset_to_first_line; + uint8* next_dest_pointer = dest_bits_pointer; //For every line in the image - for (; g1_y_end; g1_y_end--){ + for (; height; height--){ uint8 last_data_line = 0; //For every data section in the line while (!last_data_line){ - char* source_pointer = next_source_pointer; - char* dest_pointer = next_dest_pointer; + uint8* source_pointer = next_source_pointer; + uint8* dest_pointer = next_dest_pointer; int no_pixels = *source_pointer++; + //gap_size is the number of non drawn pixels you require to + //jump over on your destination uint8 gap_size = *source_pointer++; //The last bit in no_pixels tells you if you have reached the end of a line last_data_line = no_pixels & 0x80; @@ -619,7 +621,7 @@ void gfx_rle_sprite_to_buffer(char* source_bits_pointer, char* dest_bits_pointer next_source_pointer = source_pointer + no_pixels; //Calculates the start point of the image - int x_start = gap_size - g1_x_start; + int x_start = gap_size - source_x_start; if (x_start > 0){ //Since the start is positive @@ -641,9 +643,9 @@ void gfx_rle_sprite_to_buffer(char* source_bits_pointer, char* dest_bits_pointer int x_end = x_start + no_pixels; //If the end position is further out than the whole image //end position then we need to shorten the line again - if (x_end > (int)g1_x_end){ + if (x_end > width){ //Shorten the line - no_pixels -= x_end - g1_x_end; + no_pixels -= x_end - width; //If there are no pixels there is nothing to draw. if (no_pixels <= 0) continue; } @@ -682,79 +684,6 @@ void gfx_rle_sprite_to_buffer(char* source_bits_pointer, char* dest_bits_pointer } -/* -* rct2: 0x67A934 -* Draws a run length encoded sprite -* This function readies all the vars for copying the sprite data onto the screen -*/ -void gfx_draw_rle_sprite(rct_g1_element *source_g1, rct_drawpixelinfo *dest_dpi, int x, int y, int image_type, char* palette_pointer){ - int g1_y_start, g1_x_start; - char* bits_pointer; - - bits_pointer = dest_dpi->bits; - g1_y_start = 0; - - int start_y, end_y; - start_y = y + source_g1->y_offset - dest_dpi->y; - - //If the start position is negative reset to zero - if (start_y < 0){ - //Create the end point within the drawing area - end_y = source_g1->height + start_y; - //If the end point is now <= 0 no need to draw - if (end_y <= 0)return; - - g1_y_start -= start_y; - start_y = 0; - } - else{ - end_y = source_g1->height; - //Move the pointer to the correct starting y location - bits_pointer += (dest_dpi->width + dest_dpi->pitch)*start_y; - } - - int height = start_y + end_y; - //If the image is taller than the drawing area - if (height > dest_dpi->height){ - //Make the end within the drawing area - end_y -= height - dest_dpi->height; - //If the end is now <=0 then there is nothing to draw - if (end_y <= 0)return; - } - - - int start_x, end_x; - g1_x_start = 0; - start_x = x + source_g1->x_offset - dest_dpi->x; - - //If the start position is negative reset to zero - if (start_x < 0){ - //Create the end point within the drawing area - end_x = source_g1->width + start_x; - //If the end point is now <= 0 no need to draw - if (end_x <= 0)return; - - g1_x_start -= start_x; - start_x = 0; - } - else{ - end_x = source_g1->width; - //Increment the pointer to our start location - bits_pointer += start_x; - } - - int width = start_x + end_x; - //If the image is wider than the drawing area - if (width > dest_dpi->width){ - //Make the end within drawing area - end_x -= width - dest_dpi->width; - //If the end is now <=0 then there is nothing to draw - if (end_x <= 0)return; - } - - gfx_rle_sprite_to_buffer((char*)source_g1->offset, bits_pointer, palette_pointer, dest_dpi, image_type, g1_y_start, end_y, g1_x_start, end_x); -} - /** * * rct2: 0x0067A28E @@ -768,7 +697,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) int eax = 0, ebx = image_id, ecx = x, edx = y, esi = 0, edi = (int)dpi, ebp = 0; int image_type = (image_id & 0xE0000000) >> 28; - char* palette_pointer = NULL; + uint8* palette_pointer = NULL; RCT2_GLOBAL(0x00EDF81C, uint32) = image_id & 0xE0000000; eax = (image_id >> 26) & 0x7; @@ -792,7 +721,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax <<= 4; eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); RCT2_GLOBAL(0x9ABDA4, uint32) = eax; - palette_pointer = (char*)eax; + palette_pointer = (uint8*)eax; } else if (image_type && !(image_type & IMAGE_TYPE_USE_PALETTE)){ //Has not been tested @@ -837,7 +766,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x9ABFDA, uint32) = esi; edx = *((uint32*)(eax + 0xFB)); RCT2_GLOBAL(0x9ABDA4, uint32) = 0x9ABF0C; - palette_pointer = (char*)0x9ABF0C; + palette_pointer = (uint8*)0x9ABF0C; RCT2_GLOBAL(0x9ABFDE, uint32) = edx; edx = y; @@ -871,12 +800,15 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebp = *((uint32*)(eax + 0xFB)); RCT2_GLOBAL(0x9ABDA4, uint32) = 0x009ABE0C; - palette_pointer = (char*)0x9ABE0C; + palette_pointer = (uint8*)0x9ABE0C; RCT2_GLOBAL(0x9ABEDE, uint32) = ebp; } ebx &= 0x7FFFF; + + rct_g1_element* g1_source = &((rct_g1_element*)RCT2_ADDRESS_G1_ELEMENTS)[ebx]; + ebx <<= 4; ebx += RCT2_ADDRESS_G1_ELEMENTS; if (dpi->pad_0E >= 1){ //These have not been tested @@ -892,75 +824,58 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_CALLPROC_X(0x0067FAAE, eax, ebx, x, y, 0, (int)dpi, ebp); return; } - eax = *((uint32*)ebx + 2); - ebp = *((uint32*)ebx + 3); - rct_g1_element* g1_source = (rct_g1_element*)ebx; - //This is a rct2_drawpixelinfo struct - RCT2_GLOBAL(0x9E3D08, uint32) = *((uint32*)ebx); //offset to g1 bits? - RCT2_GLOBAL(0x9E3D0C, uint32) = *((uint32*)ebx + 1); - RCT2_GLOBAL(0x9E3D10, uint32) = *((uint32*)ebx + 2); //X-Y related unsigned? sets RCT2_X_RELATED_GLOBAL_1 and Y - RCT2_GLOBAL(0x9E3D14, uint32) = *((uint32*)ebx + 3); - if (g1_source->flags & G1_FLAG_RLE_COMPRESSION){ - gfx_draw_rle_sprite(g1_source, dpi, x, y, image_type, palette_pointer); - return; - } - - int translated_x, translated_y; - char* dest_pointer; - char* source_pointer; - - source_pointer = g1_source->offset; - - dest_pointer = dpi->bits; int height = g1_source->height; + int dest_start_y = y - dpi->y + g1_source->y_offset; + int source_start_y = 0; - translated_y = y - dpi->y + g1_source->y_offset; - - if (translated_y < 0){ - height += translated_y; + if (dest_start_y < 0){ + height += dest_start_y; if (height <= 0){ return; } - translated_y = -translated_y; - source_pointer += (uint32)translated_y * g1_source->width; - - translated_y = 0; - } else { - dest_pointer += (dpi->width + dpi->pitch) * translated_y; + source_start_y -= dest_start_y; + dest_start_y = 0; } - translated_y += height - dpi->height; + int dest_end_y = dest_start_y + height; - if (translated_y > 0){ - height -= translated_y; + if (dest_end_y > dpi->height){ + height -= dest_end_y - dpi->height; if (height <= 0)return; } int width = g1_source->width; - - translated_x = x - dpi->x + g1_source->x_offset; + int source_start_x = 0; + int dest_start_x = x - dpi->x + g1_source->x_offset; - if (translated_x < 0){ - width += translated_x; + if (dest_start_x < 0){ + width += dest_start_x; if (width <= 0){ return; } - source_pointer -= translated_x; - translated_x = 0; + source_start_x -= dest_start_x; + dest_start_x = 0; } - dest_pointer += translated_x; - translated_x += width; - + int end_x = dest_start_x + width; - translated_x -= dpi->width; - - if (translated_x > 0){ - width -= translated_x; + if (end_x > dpi->width){ + width -= end_x - dpi->width; if (width <= 0)return; } - + + uint8* dest_pointer = (uint8*)dpi->bits; + dest_pointer += (dpi->width + dpi->pitch)*dest_start_y + dest_start_x; + + if (g1_source->flags & G1_FLAG_RLE_COMPRESSION){ + gfx_rle_sprite_to_buffer(g1_source->offset, dest_pointer, palette_pointer, dpi, image_type, source_start_y, height, source_start_x, width); + return; + } + + uint8* source_pointer = g1_source->offset; + source_pointer += g1_source->width*source_start_y + source_start_x; + if (!(g1_source->flags & 0x02)){ gfx_bmp_sprite_to_buffer(palette_pointer, source_pointer, dest_pointer, g1_source, dpi, height, width, image_type); return; @@ -1007,7 +922,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) //edi poped off stack esi = ebp; esi += 0x9E3D28; - gfx_bmp_sprite_to_buffer(palette_pointer, (char*)esi, dest_pointer, g1_source, dpi, height, width, image_type); + gfx_bmp_sprite_to_buffer(palette_pointer, (uint8*)esi, dest_pointer, g1_source, dpi, height, width, image_type); return; } From 775ce9e83d2a41213918bef65fa06d18136ac314 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 25 May 2014 09:42:29 +0100 Subject: [PATCH 57/99] Added comments to code --- src/gfx.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index f64d9299fa..7aeda6e007 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -553,7 +553,7 @@ void gfx_bmp_sprite_to_buffer(uint8* palette_pointer, uint8* source_pointer, uin if (RCT2_GLOBAL(0x9E3CDC, uint32) != 0){//Not tested. I can't actually work out when this code runs. uint32 _ebp = RCT2_GLOBAL(0x9E3CDC, uint32); - _ebp += source_pointer - source_image->offset;// RCT2_GLOBAL(0x9E3CE0, uint32); + _ebp += source_pointer - source_image->offset; for (; height > 0; --height){ for (int no_pixels = width; no_pixels > 0; --no_pixels){ @@ -825,55 +825,83 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) return; } + //This will be the height of the drawn image int height = g1_source->height; + //This is the start y coordinate on the destination int dest_start_y = y - dpi->y + g1_source->y_offset; + //This is the start y coordinate on the source int source_start_y = 0; + if (dest_start_y < 0){ + //If the destination y is negative reduce the height of the + //image as we will cut off the bottom height += dest_start_y; + //If the image is no longer visible nothing to draw if (height <= 0){ return; } + //The source image will start a further up the image source_start_y -= dest_start_y; + //The destination start is now reset to 0 dest_start_y = 0; } int dest_end_y = dest_start_y + height; if (dest_end_y > dpi->height){ + //If the destination y is outside of the drawing + //image reduce the height of the image height -= dest_end_y - dpi->height; + //If the image no longer has anything to draw if (height <= 0)return; } + //This will be the width of the drawn image int width = g1_source->width; + //This is the source start x coordinate int source_start_x = 0; + //This is the destination start x coordinate int dest_start_x = x - dpi->x + g1_source->x_offset; if (dest_start_x < 0){ + //If the destination is negative reduce the width + //image will cut off the side width += dest_start_x; + //If there is no image to draw if (width <= 0){ return; } + //The source start will also need to cut off the side source_start_x -= dest_start_x; + //Reset the destination to 0 dest_start_x = 0; } - int end_x = dest_start_x + width; + int dest_end_x = dest_start_x + width; - if (end_x > dpi->width){ - width -= end_x - dpi->width; + if (dest_end_x > dpi->width){ + //If the destination x is outside of the drawing area + //reduce the image width. + width -= dest_end_x - dpi->width; + //If there is no image to draw. if (width <= 0)return; } + uint8* dest_pointer = (uint8*)dpi->bits; + //Move the pointer to the start point of the destination dest_pointer += (dpi->width + dpi->pitch)*dest_start_y + dest_start_x; if (g1_source->flags & G1_FLAG_RLE_COMPRESSION){ + //We have to use a different method to move the source pointer for + //rle encoded sprites so that will be handled within this function gfx_rle_sprite_to_buffer(g1_source->offset, dest_pointer, palette_pointer, dpi, image_type, source_start_y, height, source_start_x, width); return; } uint8* source_pointer = g1_source->offset; + //Move the pointer to the start point of the source source_pointer += g1_source->width*source_start_y + source_start_x; if (!(g1_source->flags & 0x02)){ From 2a77380bcbadbeaca5f425e46d78e94207db943e Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 25 May 2014 11:41:57 +0100 Subject: [PATCH 58/99] Messing about --- src/gfx.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 7aeda6e007..9f430b0cf2 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -696,7 +696,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) int eax = 0, ebx = image_id, ecx = x, edx = y, esi = 0, edi = (int)dpi, ebp = 0; int image_type = (image_id & 0xE0000000) >> 28; - + int image_sub_type = (image_id & 0x1C000000) >> 26; uint8* palette_pointer = NULL; RCT2_GLOBAL(0x00EDF81C, uint32) = image_id & 0xE0000000; @@ -718,10 +718,13 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax &= 0x7F; } eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); + //To be fixed + palette_pointer = ((rct_g1_element**)RCT2_ADDRESS_G1_ELEMENTS)[eax]; eax <<= 4; eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); RCT2_GLOBAL(0x9ABDA4, uint32) = eax; - palette_pointer = (uint8*)eax; + palette_pointer = eax; + assert(eax == palette_pointer); } else if (image_type && !(image_type & IMAGE_TYPE_USE_PALETTE)){ //Has not been tested From b8887876ea3ec2ddcb4fe987a395612e75f69c3b Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Mon, 26 May 2014 22:28:26 +0100 Subject: [PATCH 59/99] Cleaned up more asm code --- src/gfx.c | 78 ++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 44 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 9f430b0cf2..ec8f0532bc 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -718,13 +718,9 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax &= 0x7F; } eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); - //To be fixed - palette_pointer = ((rct_g1_element**)RCT2_ADDRESS_G1_ELEMENTS)[eax]; - eax <<= 4; - eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); - RCT2_GLOBAL(0x9ABDA4, uint32) = eax; - palette_pointer = eax; - assert(eax == palette_pointer); + + palette_pointer = ((rct_g1_element*)RCT2_ADDRESS_G1_ELEMENTS)[eax].offset; + RCT2_GLOBAL(0x9ABDA4, uint32) = palette_pointer; } else if (image_type && !(image_type & IMAGE_TYPE_USE_PALETTE)){ //Has not been tested @@ -782,7 +778,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); eax <<= 4; eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); - + //G1_element bits? ebp = *((uint32*)(eax + 0xF3)); esi = *((uint32*)(eax + 0xF7)); RCT2_GLOBAL(0x9ABEFF, uint32) = ebp; @@ -912,48 +908,42 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) return; } //0x67A60A - - esi -= (uint32)g1_source->offset; - ebp = (int)source_pointer; - eax = g1_source->width*g1_source->height; - esi = (int)g1_source->offset; - edx = eax; - edi = 0x9E3D28; - eax = 0; - while (edx>0){ - eax = *((sint8*)esi); - if (eax >= 0){ - esi++; - ecx = eax; - edx -= eax; - memcpy((char*)edi, (char*)esi, ecx); - edi += ecx; - esi += ecx; + int total_no_pixels = g1_source->width*g1_source->height; + source_pointer = g1_source->offset; + uint8* new_source_pointer_start = malloc(total_no_pixels); + uint8* new_source_pointer = new_source_pointer_start;// 0x9E3D28; + + while (total_no_pixels>0){ + sint8 no_pixels = *source_pointer; + if (no_pixels >= 0){ + source_pointer++; + total_no_pixels -= no_pixels; + memcpy((char*)new_source_pointer, (char*)source_pointer, no_pixels); + new_source_pointer += no_pixels; + source_pointer += no_pixels; continue; } - ecx = eax; - ebx = edi; - eax &= 0x7; - ecx >>= 3; + ecx = no_pixels; + no_pixels &= 0x7; + ecx >>= 3;//SAR eax <<= 8; - ecx = -ecx; - eax = eax & 0xFF00 + *((sint8*)esi); - edx -= ecx; - esi += 2; - ebx -= eax; - eax = esi; - esi = ebx; + ecx = -ecx;//Odd + eax = eax & 0xFF00 + *(source_pointer+1); + total_no_pixels -= ecx; + source_pointer += 2; + ebx = new_source_pointer - eax; + eax = source_pointer; + source_pointer = ebx; ebx = eax; eax = 0; - memcpy((char*)edi, (char*)esi, ecx); - edi += ecx; - esi += ecx; - esi = ebx; + memcpy((char*)new_source_pointer, (char*)source_pointer, ecx); + new_source_pointer += ecx; + source_pointer += ecx; + source_pointer = ebx; } - //edi poped off stack - esi = ebp; - esi += 0x9E3D28; - gfx_bmp_sprite_to_buffer(palette_pointer, (uint8*)esi, dest_pointer, g1_source, dpi, height, width, image_type); + source_pointer = new_source_pointer_start + g1_source->width*source_start_y + source_start_x; + gfx_bmp_sprite_to_buffer(palette_pointer, source_pointer, dest_pointer, g1_source, dpi, height, width, image_type); + free(new_source_pointer_start); return; } From 1aa7e33aae55ed06024e4f987d1a2c0b4a86945e Mon Sep 17 00:00:00 2001 From: Duncan Date: Tue, 27 May 2014 16:35:11 +0100 Subject: [PATCH 60/99] Added notes about splitting gfx_draw_sprite --- src/gfx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gfx.c b/src/gfx.c index ec8f0532bc..c0ae8c3751 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -803,7 +803,8 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x9ABEDE, uint32) = ebp; } - + //Some parts of rct jump into the function here + //will require splitting the function in two. Inputs image_id, palette_pointer,dpi,x,y,0x9e3cdc pointer,image_type(0xEDF81C) ebx &= 0x7FFFF; rct_g1_element* g1_source = &((rct_g1_element*)RCT2_ADDRESS_G1_ELEMENTS)[ebx]; From a3b33c4656ebb2dca0d8d7f2ca379ba55609f26a Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 27 May 2014 22:20:00 +0100 Subject: [PATCH 61/99] Split draw_string in two for draw_sprite and others to jump in. Started decoding top and trousers code. --- src/gfx.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index ec8f0532bc..d536adc688 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -683,7 +683,7 @@ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_point } } - +void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, int y, uint8* palette_pointer, int ebp, int eax); /** * * rct2: 0x0067A28E @@ -698,7 +698,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) int image_type = (image_id & 0xE0000000) >> 28; int image_sub_type = (image_id & 0x1C000000) >> 26; uint8* palette_pointer = NULL; - + uint8 palette[0x100]; RCT2_GLOBAL(0x00EDF81C, uint32) = image_id & 0xE0000000; eax = (image_id >> 26) & 0x7; @@ -777,15 +777,19 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax &= 0x1f; eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); eax <<= 4; + rct_g1_element g1_palette = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element); eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); + memcpy(palette, g1_palette.offset, 0x100); //G1_element bits? ebp = *((uint32*)(eax + 0xF3)); esi = *((uint32*)(eax + 0xF7)); + //*(uint32*)(palette+0xF3) = ebp; + //*(uint32*)(palette+0xF7) = esi; RCT2_GLOBAL(0x9ABEFF, uint32) = ebp; RCT2_GLOBAL(0x9ABF03, uint32) = esi; ebp = *((uint32*)(eax + 0xFB)); eax = ebx; - + //*(uint32*)(palette+0xFB) = ebp; RCT2_GLOBAL(0x9ABF07, uint32) = ebp; eax >>= 24; eax &= 0x1f; @@ -794,33 +798,37 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); ebp = *((uint32*)(eax + 0xF3)); esi = *((uint32*)(eax + 0xF7)); + *(uint32*)(palette+0xCA) = ebp; + *(uint32*)(palette+0xCE) = esi; RCT2_GLOBAL(0x9ABED6, uint32) = ebp; RCT2_GLOBAL(0x9ABEDA, uint32) = esi; ebp = *((uint32*)(eax + 0xFB)); RCT2_GLOBAL(0x9ABDA4, uint32) = 0x009ABE0C; - palette_pointer = (uint8*)0x9ABE0C; + palette_pointer = palette;// (uint8*)0x9ABE0C; + *(uint32*)(palette+0xD2) = ebp; RCT2_GLOBAL(0x9ABEDE, uint32) = ebp; - } + gfx_draw_sprite_palette_set(dpi, image_id, x, y, palette_pointer, ebp, eax); +} - ebx &= 0x7FFFF; +void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, int y, uint8* palette_pointer, int ebp, int eax){ + int image_element = 0x7FFFF&image_id; + int image_type = (image_id & 0xE0000000) >> 28; - rct_g1_element* g1_source = &((rct_g1_element*)RCT2_ADDRESS_G1_ELEMENTS)[ebx]; + rct_g1_element* g1_source = &((rct_g1_element*)RCT2_ADDRESS_G1_ELEMENTS)[image_element]; - ebx <<= 4; - ebx += RCT2_ADDRESS_G1_ELEMENTS; if (dpi->pad_0E >= 1){ //These have not been tested //something to do with zooming if (dpi->pad_0E == 1){ - RCT2_CALLPROC_X(0x0067BD81, eax, ebx, x, y, 0,(int) dpi, ebp); + RCT2_CALLPROC_X(0x0067BD81, eax, (int)g1_source, x, y, 0,(int) dpi, ebp); return; } if (dpi->pad_0E == 2){ - RCT2_CALLPROC_X(0x0067DADA, eax, ebx, x, y, 0, (int)dpi, ebp); + RCT2_CALLPROC_X(0x0067DADA, eax, (int)g1_source, x, y, 0, (int)dpi, ebp); return; } - RCT2_CALLPROC_X(0x0067FAAE, eax, ebx, x, y, 0, (int)dpi, ebp); + RCT2_CALLPROC_X(0x0067FAAE, eax, (int)g1_source, x, y, 0, (int)dpi, ebp); return; } @@ -912,7 +920,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) source_pointer = g1_source->offset; uint8* new_source_pointer_start = malloc(total_no_pixels); uint8* new_source_pointer = new_source_pointer_start;// 0x9E3D28; - + int ebx, ecx; while (total_no_pixels>0){ sint8 no_pixels = *source_pointer; if (no_pixels >= 0){ From 9779128fbaa47eb664e1f34f44add03228655ec8 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 28 May 2014 18:00:28 +0100 Subject: [PATCH 62/99] Added peep_palette rewrote top and trouser code --- src/gfx.c | 79 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 863bccdfb3..db6a65a366 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -43,6 +43,26 @@ int gLastDrawStringY; uint8 _screenDirtyBlocks[5120]; +//Originally 0x9ABE0C, 12 elements from 0xF3 are the peep top colour, 12 elements from 0xCA are peep trouser colour +uint8 peep_palette[0x100] = { + 0x00, 0xF3, 0xF4, 0xF5, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, + 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, + 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, + 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, + 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF +}; + static void gfx_draw_dirty_blocks(int x, int y, int columns, int rows); /** @@ -825,8 +845,9 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } else if (image_type && !(image_type & IMAGE_TYPE_USE_PALETTE)){ //Has not been tested - eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; + + eax = image_id; eax >>= 19; //push edx/y eax &= 0x1F; @@ -855,7 +876,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) //image_id RCT2_GLOBAL(0xEDF81C, uint32) |= 0x20000000; - image_type |= IMAGE_TYPE_USE_PALETTE; + image_id |= IMAGE_TYPE_USE_PALETTE; eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); eax <<= 4; @@ -872,43 +893,27 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } else if (image_type){ - eax = image_id; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; - eax >>= 19; - eax &= 0x1f; - eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); - eax <<= 4; - rct_g1_element g1_palette = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element); - eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); - memcpy(palette, g1_palette.offset, 0x100); - //G1_element bits? - ebp = *((uint32*)(eax + 0xF3)); - esi = *((uint32*)(eax + 0xF7)); - //*(uint32*)(palette+0xF3) = ebp; - //*(uint32*)(palette+0xF7) = esi; - RCT2_GLOBAL(0x9ABEFF, uint32) = ebp; - RCT2_GLOBAL(0x9ABF03, uint32) = esi; - ebp = *((uint32*)(eax + 0xFB)); - eax = ebx; - //*(uint32*)(palette+0xFB) = ebp; - RCT2_GLOBAL(0x9ABF07, uint32) = ebp; - eax >>= 24; - eax &= 0x1f; - eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); - eax <<= 4; - eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); - ebp = *((uint32*)(eax + 0xF3)); - esi = *((uint32*)(eax + 0xF7)); - *(uint32*)(palette+0xCA) = ebp; - *(uint32*)(palette+0xCE) = esi; - RCT2_GLOBAL(0x9ABED6, uint32) = ebp; - RCT2_GLOBAL(0x9ABEDA, uint32) = esi; - ebp = *((uint32*)(eax + 0xFB)); - RCT2_GLOBAL(0x9ABDA4, uint32) = 0x009ABE0C; - palette_pointer = palette;// (uint8*)0x9ABE0C; - *(uint32*)(palette+0xD2) = ebp; - RCT2_GLOBAL(0x9ABEDE, uint32) = ebp; + //Copy the peep palette into a new palette. + //Not really required but its nice to make a copy + memcpy(palette, peep_palette, 0x100); + + //Top + int top_type = (image_id >> 19) & 0x1f; + uint32 top_offset = RCT2_ADDRESS(0x97FCBC, uint32)[top_type]; + rct_g1_element top_palette = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[top_offset]; + memcpy(palette + 0xF3, top_palette.offset + 0xF3, 12); + + //Trousers + int trouser_type = (image_id >> 24) & 0x1f; + uint32 trouser_offset = RCT2_ADDRESS(0x97FCBC, uint32)[trouser_type]; + rct_g1_element trouser_palette = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[trouser_offset]; + memcpy(palette + 0xCA, trouser_palette.offset + 0xF3, 12); + + //For backwards compatibility until the zooming function is done + RCT2_GLOBAL(0x9ABDA4, uint8*) = palette; + palette_pointer = palette; } gfx_draw_sprite_palette_set(dpi, image_id, x, y, palette_pointer, ebp, eax); From 0715a5122ecb165b532307c82682cfbabbecdd63 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 28 May 2014 20:52:32 +0100 Subject: [PATCH 63/99] Added unknown pointer as variable. Will be named when function determined --- src/gfx.c | 60 +++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index db6a65a366..d0ab503cb7 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -579,31 +579,29 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri * copies a sprite onto the buffer. There is no compression used on the sprite * image. */ -void gfx_bmp_sprite_to_buffer(uint8* palette_pointer, uint8* source_pointer, uint8* dest_pointer, rct_g1_element* source_image, rct_drawpixelinfo *dest_dpi, int height, int width, int image_type){ +void gfx_bmp_sprite_to_buffer(uint8* palette_pointer, uint8* unknown_pointer, uint8* source_pointer, uint8* dest_pointer, rct_g1_element* source_image, rct_drawpixelinfo *dest_dpi, int height, int width, int image_type){ //Requires use of palette? if (image_type & IMAGE_TYPE_USE_PALETTE){ //Mix with another image?? and colour adjusted - if (RCT2_GLOBAL(0x9E3CDC, uint32)){ //Not tested. I can't actually work out when this code runs. - - uint32 _ebp = RCT2_GLOBAL(0x9E3CDC, uint32); - _ebp += source_pointer - source_image->offset;// RCT2_GLOBAL(0x9E3CE0, uint32); + if (unknown_pointer!= NULL){ //Not tested. I can't actually work out when this code runs. + unknown_pointer += source_pointer - source_image->offset;// RCT2_GLOBAL(0x9E3CE0, uint32); for (; height > 0; --height){ for (int no_pixels = width; no_pixels > 0; --no_pixels){ uint8 pixel = *source_pointer; source_pointer++; pixel = palette_pointer[pixel]; - pixel &= *((uint8*)_ebp); + pixel &= *unknown_pointer; if (pixel){ *dest_pointer = pixel; } dest_pointer++; - _ebp++; + unknown_pointer++; } source_pointer += source_image->width - width; dest_pointer += dest_dpi->width + dest_dpi->pitch - width; - _ebp += source_image->width - width; + unknown_pointer += source_image->width - width; } return; } @@ -673,23 +671,22 @@ void gfx_bmp_sprite_to_buffer(uint8* palette_pointer, uint8* source_pointer, uin } if (RCT2_GLOBAL(0x9E3CDC, uint32) != 0){//Not tested. I can't actually work out when this code runs. - uint32 _ebp = RCT2_GLOBAL(0x9E3CDC, uint32); - _ebp += source_pointer - source_image->offset; + unknown_pointer += source_pointer - source_image->offset; for (; height > 0; --height){ for (int no_pixels = width; no_pixels > 0; --no_pixels){ uint8 pixel = *source_pointer; source_pointer++; - pixel &= *((char*)_ebp); + pixel &= *unknown_pointer; if (pixel){ *dest_pointer = pixel; } dest_pointer++; - _ebp++; + unknown_pointer++; } source_pointer += source_image->width - width; dest_pointer += dest_dpi->width + dest_dpi->pitch - width; - _ebp += source_image->width - width; + unknown_pointer += source_image->width - width; } } @@ -804,7 +801,7 @@ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_point } } -void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, int y, uint8* palette_pointer, int ebp, int eax); +void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, int y, uint8* palette_pointer, uint8* unknown_pointer); /** * * rct2: 0x0067A28E @@ -823,6 +820,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x00EDF81C, uint32) = image_id & 0xE0000000; eax = (image_id >> 26) & 0x7; + uint8* unknown_pointer = (uint8*)(RCT2_ADDRESS(0x9E3CE4, uint32*)[image_sub_type]); RCT2_GLOBAL(0x009E3CDC, uint32) = RCT2_GLOBAL(0x009E3CE4 + eax * 4, uint32); if (image_type && !(image_type & IMAGE_TYPE_UNKNOWN)) { @@ -831,6 +829,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax = image_id; eax >>= 19; eax &= 0xFF; + unknown_pointer = NULL; RCT2_GLOBAL(0x009E3CDC, uint32) = 0; } else{ @@ -841,11 +840,12 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); palette_pointer = ((rct_g1_element*)RCT2_ADDRESS_G1_ELEMENTS)[eax].offset; - RCT2_GLOBAL(0x9ABDA4, uint32) = palette_pointer; + RCT2_GLOBAL(0x9ABDA4, uint32) = (uint32)palette_pointer; } else if (image_type && !(image_type & IMAGE_TYPE_USE_PALETTE)){ //Has not been tested RCT2_GLOBAL(0x9E3CDC, uint32) = 0; + unknown_pointer = NULL; eax = image_id; eax >>= 19; @@ -894,7 +894,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } else if (image_type){ RCT2_GLOBAL(0x9E3CDC, uint32) = 0; - + unknown_pointer = NULL; //Copy the peep palette into a new palette. //Not really required but its nice to make a copy memcpy(palette, peep_palette, 0x100); @@ -916,10 +916,10 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) palette_pointer = palette; } - gfx_draw_sprite_palette_set(dpi, image_id, x, y, palette_pointer, ebp, eax); + gfx_draw_sprite_palette_set(dpi, image_id, x, y, palette_pointer, unknown_pointer); } -void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, int y, uint8* palette_pointer, int ebp, int eax){ +void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, int y, uint8* palette_pointer, uint8* unknown_pointer){ int image_element = 0x7FFFF&image_id; int image_type = (image_id & 0xE0000000) >> 28; @@ -928,14 +928,14 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in if (dpi->pad_0E >= 1){ //These have not been tested //something to do with zooming if (dpi->pad_0E == 1){ - RCT2_CALLPROC_X(0x0067BD81, eax, (int)g1_source, x, y, 0,(int) dpi, ebp); + RCT2_CALLPROC_X(0x0067BD81, 0, (int)g1_source, x, y, 0,(int) dpi, 0); return; } if (dpi->pad_0E == 2){ - RCT2_CALLPROC_X(0x0067DADA, eax, (int)g1_source, x, y, 0, (int)dpi, ebp); + RCT2_CALLPROC_X(0x0067DADA, 0, (int)g1_source, x, y, 0, (int)dpi, 0); return; } - RCT2_CALLPROC_X(0x0067FAAE, eax, (int)g1_source, x, y, 0, (int)dpi, ebp); + RCT2_CALLPROC_X(0x0067FAAE, 0, (int)g1_source, x, y, 0, (int)dpi, 0); return; } @@ -1019,15 +1019,15 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in source_pointer += g1_source->width*source_start_y + source_start_x; if (!(g1_source->flags & 0x02)){ - gfx_bmp_sprite_to_buffer(palette_pointer, source_pointer, dest_pointer, g1_source, dpi, height, width, image_type); + gfx_bmp_sprite_to_buffer(palette_pointer, unknown_pointer, source_pointer, dest_pointer, g1_source, dpi, height, width, image_type); return; } - //0x67A60A + //0x67A60A Not tested int total_no_pixels = g1_source->width*g1_source->height; source_pointer = g1_source->offset; uint8* new_source_pointer_start = malloc(total_no_pixels); uint8* new_source_pointer = new_source_pointer_start;// 0x9E3D28; - int ebx, ecx; + int ebx, ecx, eax; while (total_no_pixels>0){ sint8 no_pixels = *source_pointer; if (no_pixels >= 0){ @@ -1041,23 +1041,23 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in ecx = no_pixels; no_pixels &= 0x7; ecx >>= 3;//SAR - eax <<= 8; + int eax = ((int)no_pixels)<<8; ecx = -ecx;//Odd eax = eax & 0xFF00 + *(source_pointer+1); total_no_pixels -= ecx; source_pointer += 2; - ebx = new_source_pointer - eax; - eax = source_pointer; - source_pointer = ebx; + ebx = (uint32)new_source_pointer - eax; + eax = (uint32)source_pointer; + source_pointer = (uint8*)ebx; ebx = eax; eax = 0; memcpy((char*)new_source_pointer, (char*)source_pointer, ecx); new_source_pointer += ecx; source_pointer += ecx; - source_pointer = ebx; + source_pointer = (uint8*)ebx; } source_pointer = new_source_pointer_start + g1_source->width*source_start_y + source_start_x; - gfx_bmp_sprite_to_buffer(palette_pointer, source_pointer, dest_pointer, g1_source, dpi, height, width, image_type); + gfx_bmp_sprite_to_buffer(palette_pointer, unknown_pointer, source_pointer, dest_pointer, g1_source, dpi, height, width, image_type); free(new_source_pointer_start); return; } From c006e277005f1da391a3a453978b82d2d65ca3e0 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 28 May 2014 21:15:19 +0100 Subject: [PATCH 64/99] Started adding draw_string --- src/gfx.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/gfx.c b/src/gfx.c index d0ab503cb7..05fd02cfaa 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1434,4 +1434,59 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *format, int colour, int x, in gLastDrawStringX = ecx; gLastDrawStringY = edx; + + RCT2_GLOBAL(0xEDF840, uint16) = ecx; + RCT2_GLOBAL(0xEDF842, uint16) = edx; + RCT2_GLOBAL(0x9E3CDC, uint32) = 0; + + if (eax & 0xFF == 0xFE){ + //jmp 0x682853 + } + + ebx = dpi->x; + ebx += dpi->width; + if (ecx >= ebx){ + return; + //jmp 0x6828DF + } + ebx = ecx; + ebx += 0x280; + if (ebx <= dpi->x){ + return; + } + ebx = dpi->y; + ebx += dpi->height; + if (edx >= ebx){ + return; + } + ebx = edx; + ebx += 0x5A; + if (ebx <= dpi->y){ + return; + } + if (eax & 0xff == 0xff){ + //jmp 0x682853 + } + + RCT2_GLOBAL(0x13CE9A2, uint16) = 0; + if (RCT2_GLOBAL(0x13CE950, sint16) < 0){ + RCT2_GLOBAL(0x13CE9A2, uint16) |= 0x4; + if (RCT2_GLOBAL(0x13CE950, uint16)!=0xFFFF){ + RCT2_GLOBAL(0x13CE9A2, uint16) |= 0x8; + } + RCT2_GLOBAL(0x13CE950, uint16) = 0xE0; + } + if (eax&(1 << 5)){ + RCT2_GLOBAL(0x13CE9A2, uint16) |= 0x2; + } + eax &= ~(1 << 5); + if (!(eax & 0x40)){ + //jmp 0x682aa9 + } + RCT2_GLOBAL(0x13CE9A2, uint16) |= 0x1; + eax &= 0x1F; + + ebp = eax; + //0x6827c9 + } From 33833b413f982795f86ab089e60365e813774a3c Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Thu, 29 May 2014 17:55:52 +0100 Subject: [PATCH 65/99] Added more gfx_draw_string --- src/gfx.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 05fd02cfaa..3250927a68 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1027,7 +1027,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in source_pointer = g1_source->offset; uint8* new_source_pointer_start = malloc(total_no_pixels); uint8* new_source_pointer = new_source_pointer_start;// 0x9E3D28; - int ebx, ecx, eax; + int ebx, ecx; while (total_no_pixels>0){ sint8 no_pixels = *source_pointer; if (no_pixels >= 0){ @@ -1430,7 +1430,7 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *format, int colour, int x, in esi = (int)format; edi = (int)dpi; ebp = 0; - RCT2_CALLFUNC_X(0x00682702, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + //RCT2_CALLFUNC_X(0x00682702, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); gLastDrawStringX = ecx; gLastDrawStringY = edx; @@ -1439,7 +1439,9 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *format, int colour, int x, in RCT2_GLOBAL(0xEDF842, uint16) = edx; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; - if (eax & 0xFF == 0xFE){ + if ((eax & 0xFF) == 0xFE){ + RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); + return; //jmp 0x682853 } @@ -1447,7 +1449,6 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *format, int colour, int x, in ebx += dpi->width; if (ecx >= ebx){ return; - //jmp 0x6828DF } ebx = ecx; ebx += 0x280; @@ -1464,7 +1465,9 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *format, int colour, int x, in if (ebx <= dpi->y){ return; } - if (eax & 0xff == 0xff){ + if ((eax & 0xff) == 0xff){ + RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); + return; //jmp 0x682853 } @@ -1481,12 +1484,51 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *format, int colour, int x, in } eax &= ~(1 << 5); if (!(eax & 0x40)){ + RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); + return; //jmp 0x682aa9 } RCT2_GLOBAL(0x13CE9A2, uint16) |= 0x1; eax &= 0x1F; ebp = eax; - //0x6827c9 + if (!(RCT2_GLOBAL(0x13CE9A2, uint16) & 0x4)){ + eax = RCT2_GLOBAL(0x141FC4A + ebp * 8,uint8); + eax <<= 0x10; + eax |= RCT2_GLOBAL(0x141FC48 + ebp * 8, uint8); + } + else if (!(RCT2_GLOBAL(0x13CE9A2, uint16) & 0x8)){ + eax = RCT2_GLOBAL(0x141FC49 + ebp * 8, uint8); + eax <<= 0x10; + eax |= RCT2_GLOBAL(0x141FC47 + ebp * 8, uint8); + + } + else{ + eax = RCT2_GLOBAL(0x141FC48 + ebp * 8, uint8); + eax <<= 0x10; + eax |= RCT2_GLOBAL(0x141FC46 + ebp * 8, uint8); + } + RCT2_GLOBAL(0x9abe05, uint32) = eax; + RCT2_GLOBAL(0x9abda4, uint32) = 0x9abe04; + eax = 0; + if (0){ + add0x682818: + if (!(RCT2_GLOBAL(0x13CE9A2, uint16) & 0x1)){ + eax &= 0xFF; + ebp = RCT2_GLOBAL(0x9ff048, uint32); + eax = *((uint32*)(eax * 4 + ebp)); + if (!(RCT2_GLOBAL(0x13CE9A2, uint16) & 0x2)){ + eax &= 0xff0000ff; + } + RCT2_GLOBAL(0x9abe05, uint32) = eax; + RCT2_GLOBAL(0x9abda4, uint32) = 0x9abe04; + eax = 0; + } + } + eax = edx; + eax += 0x13; + //0x68285a + RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); + return; } From e69b3540559b09a103c9a6317b04602d64269b81 Mon Sep 17 00:00:00 2001 From: Duncan Date: Fri, 30 May 2014 12:42:39 +0100 Subject: [PATCH 66/99] Added a small bit more to draw_string --- src/gfx.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/gfx.c b/src/gfx.c index 3250927a68..1f520efaa0 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1527,7 +1527,30 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *format, int colour, int x, in } eax = edx; eax += 0x13; - //0x68285a + if ( eax <= dpi->y)){ + //jmp 0x682B63 + RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); + return; + } + eax = dpi->y; + eax += dpi->height; + if (eax <= edx){ + //jmp 0x682B63 + RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); + return; + } + eax = *(*(uint8)esi); + esi++; + if (!eax)return; + if ((uint32)eax < 0x9c){ + if((uint32)eax >= 0x8e){ + //jmp 0x682a2d + RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); + return; + } + } + eax -= 0x20; + //0x68288a RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); return; From 81fe1d3494337a2ee6a1133fb731428f91a231a1 Mon Sep 17 00:00:00 2001 From: Duncan Date: Fri, 30 May 2014 15:33:10 +0100 Subject: [PATCH 67/99] Added more draw_string reaches first draw_sprite_call --- src/gfx.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 1f520efaa0..4c0416c694 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1440,8 +1440,7 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *format, int colour, int x, in RCT2_GLOBAL(0x9E3CDC, uint32) = 0; if ((eax & 0xFF) == 0xFE){ - RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); - return; + goto mov0x682853; //jmp 0x682853 } @@ -1466,8 +1465,7 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *format, int colour, int x, in return; } if ((eax & 0xff) == 0xff){ - RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); - return; + goto mov0x682853; //jmp 0x682853 } @@ -1512,7 +1510,7 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *format, int colour, int x, in RCT2_GLOBAL(0x9abda4, uint32) = 0x9abe04; eax = 0; if (0){ - add0x682818: +add0x682818: if (!(RCT2_GLOBAL(0x13CE9A2, uint16) & 0x1)){ eax &= 0xFF; ebp = RCT2_GLOBAL(0x9ff048, uint32); @@ -1525,6 +1523,7 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *format, int colour, int x, in eax = 0; } } +mov0x682853: eax = edx; eax += 0x13; if ( eax <= dpi->y)){ @@ -1550,6 +1549,33 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *format, int colour, int x, in } } eax -= 0x20; + if (eax<0){ + //jmp 0x6828f5 + RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); + return; + } + ebx = dpi->x; + ebx += dpi->width; + if (ecx>=ebx){ + //jmp 0x682b63 + RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); + return; + } + ebx = ecx; + ebx += 0x1a; + if (ebxx){ + //jmp 0x6828e0 + RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); + return; + } + + ebx = eax; + ebx += RCT2_GLOBAL(0x13CE950,uint16); + eax = *((uint32*)(ebx+0x141E9e8); + ebx += 0xf15; + RCT2_GLOBAL(0xEDF81C,uint32) = 0x20000000; + gfx_draw_sprite_palette_set(dpi,ebx, ecx, edx, RCT2_GLOBAL(0x9ABDA4, uint8*), RCT2_GLOBAL(0x9E3CDC, uint8*)) + //0x68288a RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); return; From ed31f96c332106ba85f47f2914f4e3590bd640bc Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 30 May 2014 17:28:06 +0100 Subject: [PATCH 68/99] Added sprite zoom function. No freeing yet leaks memory like a sive --- src/gfx.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 4c0416c694..c5e64c3222 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -706,6 +706,35 @@ void gfx_bmp_sprite_to_buffer(uint8* palette_pointer, uint8* unknown_pointer, ui return; } +rct_g1_element gfx_sprite_zoom_image(rct_g1_element* source, int zoom_level){ + rct_g1_element dest; + uint8* smaller_image; + dest.offset = NULL; + if (zoom_level == 0)return dest; + if (source->flags&G1_FLAG_RLE_COMPRESSION) return dest; + smaller_image = malloc(source->width*source->height); + dest.offset = smaller_image; + uint8* source_pointer = source->offset; + source_pointer += source->y_offset*source->width + source->x_offset; + + for (int y = 0; y < source->height; y += zoom_level){ + uint8* next_line = source_pointer + source->width*zoom_level; + for (int x = 0; x < source->width; x += zoom_level){ + *smaller_image = *source_pointer; + source_pointer += zoom_level; + smaller_image++; + } + source_pointer = next_line;//source->width*zoom_level; + } + + dest.x_offset = 0; + dest.y_offset = 0; + dest.width = source->width / zoom_level; + dest.height= source->height/ zoom_level; + dest.flags = source->flags; + return dest; + //remember to free the pointer +} /* * rct2: 0x67AA18 transfers readied images onto buffers * This function copies the sprite data onto the screen @@ -924,7 +953,8 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in int image_type = (image_id & 0xE0000000) >> 28; rct_g1_element* g1_source = &((rct_g1_element*)RCT2_ADDRESS_G1_ELEMENTS)[image_element]; - + rct_g1_element zoomed = gfx_sprite_zoom_image(g1_source, dpi->pad_0E); + if (zoomed.offset != NULL)g1_source = &zoomed; if (dpi->pad_0E >= 1){ //These have not been tested //something to do with zooming if (dpi->pad_0E == 1){ @@ -1526,7 +1556,7 @@ add0x682818: mov0x682853: eax = edx; eax += 0x13; - if ( eax <= dpi->y)){ + if ( eax <= dpi->y){ //jmp 0x682B63 RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); return; @@ -1538,7 +1568,7 @@ mov0x682853: RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); return; } - eax = *(*(uint8)esi); + eax = *((uint8*)esi); esi++; if (!eax)return; if ((uint32)eax < 0x9c){ @@ -1571,10 +1601,10 @@ mov0x682853: ebx = eax; ebx += RCT2_GLOBAL(0x13CE950,uint16); - eax = *((uint32*)(ebx+0x141E9e8); + eax = *((uint32*)(ebx+0x141E9e8)); ebx += 0xf15; RCT2_GLOBAL(0xEDF81C,uint32) = 0x20000000; - gfx_draw_sprite_palette_set(dpi,ebx, ecx, edx, RCT2_GLOBAL(0x9ABDA4, uint8*), RCT2_GLOBAL(0x9E3CDC, uint8*)) + gfx_draw_sprite_palette_set(dpi, ebx, ecx, edx, RCT2_GLOBAL(0x9ABDA4, uint8*), RCT2_GLOBAL(0x9E3CDC, uint8*)); //0x68288a RCT2_CALLPROC_X(0x00682702, colour, 0, x, y, (int)format, (int)dpi, 0); From 34a9f94ac170c65a637536918ac35876da743f61 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sat, 17 May 2014 09:34:58 +0200 Subject: [PATCH 69/99] Add gfx_get_string_width() --- src/gfx.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 929998071e..c3f5f09a8d 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1041,18 +1041,70 @@ void gfx_redraw_screen_rect(short left, short top, short right, short bottom) } /** - * + * * rct2: 0x006C2321 * buffer (esi) */ int gfx_get_string_width(char *buffer) { - int eax, ebx, ecx, edx, esi, edi, ebp; + int base; + int width; - esi = (int)buffer; - RCT2_CALLFUNC_X(0x006C2321, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + char curr_char; - return ecx & 0xFFFF; + curr_char = 0; + base = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); + width = 0; + + for (curr_char = *buffer; curr_char > 0; buffer++, curr_char = *buffer) { + + if (curr_char >= 0x20) { + width += RCT2_ADDRESS(0x0141E9E8, uint8)[base + (curr_char-0x20)]; + continue; + } + switch(curr_char) { + case 1: + width = *buffer; + buffer++; + break; + case 2: + case 3: + case 4: + buffer++; + break; + case 7: + base = 0x1C0; + break; + case 8: + base = 0x2A0; + break; + case 9: + base = 0x0E0; + break; + case 0x0A: + base = 0; + break; + case 0x17: + curr_char = *buffer; + curr_char &= 0x7FFFF; + buffer += 4; + curr_char <<= 4; + width = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[curr_char]; + curr_char = 0; + break; + default: + if (curr_char <= 0x10) { + continue; + } + buffer += 2; + if (curr_char <= 0x16) { + continue; + } + buffer += 2; + break; + } + } + return width; } /** From 6e778006a5f17445189d16a6867e570f2c89358c Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sat, 17 May 2014 22:37:37 +0200 Subject: [PATCH 70/99] First pass for gfx_draw_string() --- src/addresses.h | 1 + src/gfx.c | 330 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 331 insertions(+) diff --git a/src/addresses.h b/src/addresses.h index 3a36125e05..912461a9b3 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -249,6 +249,7 @@ #define RCT2_ADDRESS_NEWS_ITEM_LIST 0x013CA754 #define RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE 0x013CE950 +#define RCT2_ADDRESS_CURRENT_FONT_FLAGS 0x013CE9A2 #define RCT2_ADDRESS_TILE_MAP_ELEMENT_POINTERS 0x013CE9A4 #define RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT 0x0141E9AC diff --git a/src/gfx.c b/src/gfx.c index c3f5f09a8d..ced773d864 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1285,4 +1285,334 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *format, int colour, int x, in gLastDrawStringX = ecx; gLastDrawStringY = edx; + + + RCT2_GLOBAL(0x00EDF840, uint16) = x; + RCT2_GLOBAL(0x00EDF842, uint16) = y; + + if (colour & 0xFE) { + // jz loc_682853 + } + + if ((x >= dpi->x + dpi->width) || (x <= dpi->x) || + (y >= dpi->y + dpi->height) || (y <= dpi->y)) { + return; + } + if (colour == 0xFF) { + // jz loc_682853 + } + + uint16* current_font_flags = &RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_FLAGS, uint16); + uint16* current_font_sprite_base = &RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); + + // switch_colour: + *current_font_flags = 0; + if (*current_font_sprite_base < 0) { + *current_font_flags |= 4; + if (*current_font_sprite_base != 0xFFFF) { + *current_font_flags |= 8; + } + *current_font_sprite_base = 0xE0; + } + // loc_6827A5 + if (!(ax & (1 << 5))) { + *current_font_flags |= 2; + } + + // loc_6827B4 + if (!(colour & 0x40)) { + ebp = al; + // jmp short loc_682AC7 + } + + *current_font_flags |= 1; + colour &= 0x1F; + + ebp = colour; + + if (*current_font_flags & 4) { + if (*current_font_flags & 8) { + // loc_682805 + eax = RCT2_ADDRESS(0x0141FC48, uint8)[ebp * 8]; + eax = eax << 10; + eax = eax | RCT2_ADDRESS(0x0141FC46, uint8)[ebp * 8]; + } else { + // loc_6827E7 + eax = RCT2_ADDRESS(0x0141FC49, uint8)[ebp * 8]; + eax = eax << 10; + eax = eax | RCT2_ADDRESS(0x0141FC47, uint8)[ebp * 8]; + } + } else { + eax = RCT2_ADDRESS(0x0141FC4A, uint8)[ebp * 8]; + eax = eax << 10; + eax = eax | RCT2_ADDRESS(0x0141FC48, uint8)[ebp * 8]; + } + // jmp short loc_682842 + + + // ; --------------------------------------------------------------------------- + + + // ; --------------------------------------------------------------------------- + // loc_682842 + RCT2_GLOBAL(0x009ABE05, uint32) = eax; + RCT2_GLOBAL(0x009ABDA4, uint32) = 0x009ABE04; + eax = 0; + + // loc_682853 + if (y + 0x13 <= dpi->y) { + skip_char; + } + if (dpi->y + dpi->height <= y) { + skip_char; + } + + // loc_682875 + al = *format; + format++; + + // skip_cont + if (al == 0) { + return; + } + if (al >= 0x9C) { + // jnb short loc_682888 + } + if (al >= 0x8E) { + // jnb colour_char + } + + // loc_682888 + al -= 0x20; + if (al < 0) { + // jb short loc_6828F5 + } + bx = dpi->x + dpi->width; + if (x >= bx) { + // jge skip_char + } + bx = x + 0x1A; + if (bx < dpi->x) { + // jl short loc_6828E0 + } + ebx = al + *current_font_sprite_base; + cl = cl + (RCT2_ADDRESS(0x0141E9E8, uint32)[ebx] & 0xFF) + // push dword_141E9E8[ebx] + // push ecx + // push edx + // push edi + // push esi + + eax = (int)al; + ebx += 0xF15; + esi = (int)format; + edi = (int)dpi; + + RCT2_GLOBAL(0x00EDF81C, uint32) = 0x20000000; + + RCT2_CALLPROC_X(0x067A46E, eax, ebx, ecx, edx, esi, edi, ebp); + + // pop esi + // pop edi + // pop edx + // pop ecx + // pop eax + + // jmp short loc_682875 + + // loc_6828E0 + ebx = al; + ebx += *current_font_sprite_base; + cl = cl + (RCT2_ADDRESS(0x0141E9E8, uint32)[ebx] & 0xFF); + // jmp short loc_682875 + + // loc_6828F5 + switch (al) { + case 0x0E5: + // jz loc_6829E3 + cx = RCT2_GLOBAL(0x0EDF840, uint16); + dx += 0x0A; + if (*current_font_sprite_base <= 0x0E) { + // jbe loc_682875 + } + dx -= 4; + if (*current_font_sprite_base == 0x1C0) { + // jz loc_682875 + } + dx -= 0xFFF4; + // jmp loc_682875 + case 0x0E6: + // jz loc_6829AD + cx = RCT2_GLOBAL(0x0EDF840, uint16); + dx += 5; + if (*current_font_sprite_base <= 0x0E) { + // jbe loc_682875 + } + dx -= 2; + if (*current_font_sprite_base == 0x1C0) { + // jz loc_682875 + } + dx -= 0xFFFA; + // jmp loc_682875 + case 0x0E1: + // jz loc_682A19 + al = *buffer; + buffer++; + cx = RCT2_GLOBAL(0x0EDF840, uint16); + cx += al; + // jmp loc_682875 + + case 0x0F1: + // jz loc_682A34 + ax = *buffer; + buffer += 2; + cx = RCT2_GLOBAL(0x0EDF840, uint16); + cx += (ax & 0xFF); + dx = RCT2_GLOBAL(0x0EDF842, uint16); + dx += (ax & 0xFF00) >> 8; + // jmp loc_682875 + + + case 0x0E7: + // jz loc_682A57 + *current_font_sprite_base = 0x1C0; + // jmp loc_682875 + + case 0x0E8: + // jz loc_682A65 + *current_font_sprite_base = 0x2A0; + // jmp loc_682875 + + case 0x0E9: + // jz loc_682A81 + *current_font_sprite_base = 0xE0; + // jmp loc_682875 + + case 0x0EA: + // jz loc_682A73 + *current_font_sprite_base = 0; + // jmp loc_682875 + + case 0x0EB: + // jz loc_682A8F + *current_font_flags |= 2; + // jmp loc_682875 + + case 0x0EC: + // jz loc_682A9C + *current_font_flags &= 0x0FFFD; + // jmp loc_682875 + + case 0x0ED: + // jz loc_682AAE + ebp = RCT2_GLOBAL(0x0141F740, uint8); + + // jmp short loc_682AC7 + + case 0x0EE: + // jz loc_682AC0 + ebp = RCT2_GLOBAL(0x0141F741, uint8); + + // jmp short loc_682AC7 + + case 0x0EF: + // jz loc_682AB7 + ebp = RCT2_GLOBAL(0x0141F742, uint8); + + // jmp short loc_682AC7 + + case 0x0E2: + // jz loc_682AF7 + eax = *buffer; + buffer++; + if (*current_font_flags & 1) { + // jnz loc_682853 + } + + // push ebx + // mov eax, ds:dword_97FCBC[eax*4] + // shl eax, 4 + // mov eax, g1_elements[eax] + // mov bl, [eax+0F9h] + // mov bh, 1 + + eax = RCT2_ADDRESS(0x097FCBC, uint32)[eax*4]; + rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[eax]); + // What on earth is going on here? + bx = *(g1_element + 0xF9) + (1 << 8); + + if (!(*current_font_flags & 2)) { + bx = bx & 0xFF; + } + RCT2_GLOBAL(0x09ABE05, uint16) = bx; + bx = *(g1_element + 0xF7); + RCT2_GLOBAL(0x09ABE07, uint16) = bx; + bx = *(g1_element + 0xFA); + RCT2_GLOBAL(0x09ABE09, uint16) = bx; + + // pop ebx + RCT2_GLOBAL(0x09ABDA4, uint32) = RCT2_GLOBAL(0x09ABE04, uint32); + + // jmp loc_682853 + + case 0x0F7: + // jz short loc_68296E + buffer += 4; + if (cx >= dpi->x + dpi->width) { + skip_char; + } + ebx = *(format - 4); + eax = ebx & 0x7FFFF; + rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, rct_g1_element)[eax]); + + gfx_draw_sprite(dpi, ebx, cx, dx); + + cx += g1_element->offset; + // jmp loc_682875 + + } + // jmp loc_682875 + + // colour_char + al -= 0x8E; + if (*current_font_flags == 1) { + // jnz short loc_682853 + } + eax = eax & 0xFF; + // mov ebp, g1_elements+13320h + ebp = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 0x13320, uint32)); + // mov eax, [ebp+eax*4+0] + eax = *(ebp + eax*4); + + if (!(*current_font_flags & 2)) { + eax = eax & 0x0FF0000FF; + } + // jump 6842 + + + // loc_682AC7 + if (*current_font_flags & 1) { + // jnz loc_682853 + } + eax = RCT2_ADDRESS(0x0141FD45, uint8)[ebp * 8]; + if (*current_font_flags & 2) { + eax |= 0x0A0A00; + } + // jmp loc_682842 + + // skip_char + al = *buffer; + buffer++; + if (al < 0x20) { + // jb skip_cont + } + if (al >= 0x9C) { + // jnb short skip_char + } + if (al >= 0x8E) { + // jnb colour_char + } + // jmp short skip_char + + } From 99c7b23452077048aa9c248433530844a0256d6e Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sun, 18 May 2014 16:02:02 +0200 Subject: [PATCH 71/99] Second pass of gfx_draw_string. Still buggy --- src/gfx.c | 683 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 384 insertions(+), 299 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index ced773d864..9a5b968f5e 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1261,358 +1261,443 @@ void gfx_draw_string_left(rct_drawpixelinfo *dpi, int format, void *args, int co gfx_draw_string(dpi, buffer, colour, x, y); } + +void colour_char(int al, uint16* current_font_flags) { + + int eax; + uint32* ebp; + + // colour_char + eax = al & 0xFF; + // mov ebp, g1_elements+13320h + ebp = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 0x13320, uint32); + // mov eax, [ebp+eax*4+0] + eax = ebp[eax*4]; + + if (!(*current_font_flags & 2)) { + eax = eax & 0x0FF0000FF; + } + // Store current colour? + RCT2_GLOBAL(0x009ABE05, uint32) = eax; + RCT2_GLOBAL(0x009ABDA4, uint32) = 0x009ABE04; + +} + + +void sub_682AC7(int ebp, int* eax, uint16* current_font_flags) { + + // loc_682AC7 + *eax = RCT2_ADDRESS(0x0141FD45, uint8)[ebp * 8]; + if (*current_font_flags & 2) { + *eax |= 0x0A0A00; + } + // Store current colour? + RCT2_GLOBAL(0x009ABE05, uint32) = *eax; + RCT2_GLOBAL(0x009ABDA4, uint32) = 0x009ABE04; + *eax = 0; + // jmp loc_682842 + +} + + /** * * rct2: 0x00682702 * dpi (edi) - * format (esi) + * buffer (esi) * colour (al) * x (cx) * y (dx) */ -void gfx_draw_string(rct_drawpixelinfo *dpi, char *format, int colour, int x, int y) +void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, int y) { int eax, ebx, ecx, edx, esi, edi, ebp; - eax = colour; - ebx = 0; - ecx = x; - edx = y; - esi = (int)format; - edi = (int)dpi; - ebp = 0; - RCT2_CALLFUNC_X(0x00682702, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); - - gLastDrawStringX = ecx; - gLastDrawStringY = edx; + // eax = colour; + // ebx = 0; + // ecx = x; + // edx = y; + // esi = (int)buffer; + // edi = (int)dpi; + // ebp = 0; + // RCT2_CALLFUNC_X(0x00682702, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + int max_x = x; + int max_y = y; RCT2_GLOBAL(0x00EDF840, uint16) = x; RCT2_GLOBAL(0x00EDF842, uint16) = y; if (colour & 0xFE) { - // jz loc_682853 + // jz loc_682853 } if ((x >= dpi->x + dpi->width) || (x <= dpi->x) || (y >= dpi->y + dpi->height) || (y <= dpi->y)) { return; } - if (colour == 0xFF) { - // jz loc_682853 - } - uint16* current_font_flags = &RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_FLAGS, uint16); uint16* current_font_sprite_base = &RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); - // switch_colour: - *current_font_flags = 0; - if (*current_font_sprite_base < 0) { - *current_font_flags |= 4; - if (*current_font_sprite_base != 0xFFFF) { - *current_font_flags |= 8; + if (!(colour == 0xFF)) { + + // switch_colour: + *current_font_flags = 0; + if (*current_font_sprite_base < 0) { + *current_font_flags |= 4; + if (*current_font_sprite_base != 0xFFFF) { + *current_font_flags |= 8; + } + *current_font_sprite_base = 0xE0; + } + // loc_6827A5 + if (!(colour & (1 << 5))) { + *current_font_flags |= 2; } - *current_font_sprite_base = 0xE0; - } - // loc_6827A5 - if (!(ax & (1 << 5))) { - *current_font_flags |= 2; - } - // loc_6827B4 - if (!(colour & 0x40)) { - ebp = al; - // jmp short loc_682AC7 - } - - *current_font_flags |= 1; - colour &= 0x1F; - - ebp = colour; - - if (*current_font_flags & 4) { - if (*current_font_flags & 8) { - // loc_682805 - eax = RCT2_ADDRESS(0x0141FC48, uint8)[ebp * 8]; - eax = eax << 10; - eax = eax | RCT2_ADDRESS(0x0141FC46, uint8)[ebp * 8]; + // loc_6827B4 + if (!(colour & 0x40)) { + ebp = colour; + sub_682AC7(ebp, &colour, current_font_flags); + // jmp short loc_682AC7 } else { - // loc_6827E7 - eax = RCT2_ADDRESS(0x0141FC49, uint8)[ebp * 8]; - eax = eax << 10; - eax = eax | RCT2_ADDRESS(0x0141FC47, uint8)[ebp * 8]; + *current_font_flags |= 1; + colour &= 0x1F; + + ebp = colour; + + if (*current_font_flags & 4) { + if (*current_font_flags & 8) { + // loc_682805 + eax = RCT2_ADDRESS(0x0141FC48, uint8)[ebp * 8]; + eax = eax << 10; + eax = eax | RCT2_ADDRESS(0x0141FC46, uint8)[ebp * 8]; + } else { + // loc_6827E7 + eax = RCT2_ADDRESS(0x0141FC49, uint8)[ebp * 8]; + eax = eax << 10; + eax = eax | RCT2_ADDRESS(0x0141FC47, uint8)[ebp * 8]; + } + } else { + eax = RCT2_ADDRESS(0x0141FC4A, uint8)[ebp * 8]; + eax = eax << 10; + eax = eax | RCT2_ADDRESS(0x0141FC48, uint8)[ebp * 8]; + } + // loc_682842 + // Store current colour? ; + RCT2_GLOBAL(0x009ABE05, uint32) = eax; + RCT2_GLOBAL(0x009ABDA4, uint32) = 0x009ABE04; + eax = 0; + } - } else { - eax = RCT2_ADDRESS(0x0141FC4A, uint8)[ebp * 8]; - eax = eax << 10; - eax = eax | RCT2_ADDRESS(0x0141FC48, uint8)[ebp * 8]; - } - // jmp short loc_682842 - - - // ; --------------------------------------------------------------------------- - - - // ; --------------------------------------------------------------------------- - // loc_682842 - RCT2_GLOBAL(0x009ABE05, uint32) = eax; - RCT2_GLOBAL(0x009ABDA4, uint32) = 0x009ABE04; - eax = 0; - - // loc_682853 - if (y + 0x13 <= dpi->y) { - skip_char; - } - if (dpi->y + dpi->height <= y) { - skip_char; + // jmp short loc_682842 + // jz loc_682853 } - // loc_682875 - al = *format; - format++; + int skip_char = 0; - // skip_cont - if (al == 0) { - return; - } - if (al >= 0x9C) { - // jnb short loc_682888 - } - if (al >= 0x8E) { - // jnb colour_char + // loc_682853 + if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { + skip_char = 1; } - // loc_682888 - al -= 0x20; - if (al < 0) { - // jb short loc_6828F5 - } - bx = dpi->x + dpi->width; - if (x >= bx) { - // jge skip_char - } - bx = x + 0x1A; - if (bx < dpi->x) { - // jl short loc_6828E0 - } - ebx = al + *current_font_sprite_base; - cl = cl + (RCT2_ADDRESS(0x0141E9E8, uint32)[ebx] & 0xFF) - // push dword_141E9E8[ebx] - // push ecx - // push edx - // push edi - // push esi + // loc_682875 + // al = *buffer; + // buffer++; - eax = (int)al; - ebx += 0xF15; - esi = (int)format; - edi = (int)dpi; - - RCT2_GLOBAL(0x00EDF81C, uint32) = 0x20000000; + for (uint8 al = *buffer; al > 0; al= *buffer, ++buffer) { + // skip_char + // al = *buffer; + // buffer++; + if (skip_char) { + if (al < 0x20) { + skip_char = 0; + // jb skip_cont + } else if (al >= 0x9C) { + continue; + // jnb short skip_char + } else if (al >= 0x8E) { + al -= 0x8E; + if (*current_font_flags == 1) { + if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { + skip_char = 1; + } else { + skip_char = 0; + } + continue; + // jnz short loc_682853 + } + colour_char(al, current_font_flags); + continue; + // jnb colour_char + } else { + continue; + // jmp short skip_char + } + } - RCT2_CALLPROC_X(0x067A46E, eax, ebx, ecx, edx, esi, edi, ebp); + // skip_cont + if (al >= 0x9C) { + // jnb short loc_682888 + // loc_682888 + al -= 0x20; + if (al < 0) { + // jb short loc_6828F5 + // loc_6828F5 + switch (al) { + case 0x0E5: + // jz loc_6829E3 + max_x = RCT2_GLOBAL(0x0EDF840, uint16); + max_y += 0x0A; + if (*current_font_sprite_base <= 0x0E) { + // jbe loc_682875 + break; + } + max_y -= 4; + if (*current_font_sprite_base == 0x1C0) { + // jz loc_682875 + break; + } + max_y -= 0xFFF4; + // jmp loc_682875 + break; + case 0x0E6: + // jz loc_6829AD + max_x = RCT2_GLOBAL(0x0EDF840, uint16); + max_y += 5; + if (*current_font_sprite_base <= 0x0E) { + // jbe loc_682875 + break; + } + max_y -= 2; + if (*current_font_sprite_base == 0x1C0) { + // jz loc_682875 + break; + } + max_y -= 0xFFFA; + // jmp loc_682875 + break; + case 0x0E1: + // jz loc_682A19 + al = *buffer; + buffer++; + max_x = RCT2_GLOBAL(0x0EDF840, uint16); + max_x += al; + // jmp loc_682875 + break; - // pop esi - // pop edi - // pop edx - // pop ecx - // pop eax - - // jmp short loc_682875 - - // loc_6828E0 - ebx = al; - ebx += *current_font_sprite_base; - cl = cl + (RCT2_ADDRESS(0x0141E9E8, uint32)[ebx] & 0xFF); - // jmp short loc_682875 - - // loc_6828F5 - switch (al) { - case 0x0E5: - // jz loc_6829E3 - cx = RCT2_GLOBAL(0x0EDF840, uint16); - dx += 0x0A; - if (*current_font_sprite_base <= 0x0E) { - // jbe loc_682875 - } - dx -= 4; - if (*current_font_sprite_base == 0x1C0) { - // jz loc_682875 - } - dx -= 0xFFF4; - // jmp loc_682875 - case 0x0E6: - // jz loc_6829AD - cx = RCT2_GLOBAL(0x0EDF840, uint16); - dx += 5; - if (*current_font_sprite_base <= 0x0E) { - // jbe loc_682875 - } - dx -= 2; - if (*current_font_sprite_base == 0x1C0) { - // jz loc_682875 - } - dx -= 0xFFFA; - // jmp loc_682875 - case 0x0E1: - // jz loc_682A19 - al = *buffer; - buffer++; - cx = RCT2_GLOBAL(0x0EDF840, uint16); - cx += al; - // jmp loc_682875 - - case 0x0F1: - // jz loc_682A34 - ax = *buffer; - buffer += 2; - cx = RCT2_GLOBAL(0x0EDF840, uint16); - cx += (ax & 0xFF); - dx = RCT2_GLOBAL(0x0EDF842, uint16); - dx += (ax & 0xFF00) >> 8; - // jmp loc_682875 + case 0x0F1: + // jz loc_682A34 + eax = *((uint16*)buffer); + buffer += 2; + max_x = RCT2_GLOBAL(0x0EDF840, uint16); + max_x += (eax & 0xFF); + max_y = RCT2_GLOBAL(0x0EDF842, uint16); + max_y += (eax & 0xFF00) >> 8; + // jmp loc_682875 + break; - case 0x0E7: - // jz loc_682A57 - *current_font_sprite_base = 0x1C0; - // jmp loc_682875 + case 0x0E7: + // jz loc_682A57 + *current_font_sprite_base = 0x1C0; + // jmp loc_682875 + break; - case 0x0E8: - // jz loc_682A65 - *current_font_sprite_base = 0x2A0; - // jmp loc_682875 + case 0x0E8: + // jz loc_682A65 + *current_font_sprite_base = 0x2A0; + // jmp loc_682875 + break; - case 0x0E9: - // jz loc_682A81 - *current_font_sprite_base = 0xE0; - // jmp loc_682875 + case 0x0E9: + // jz loc_682A81 + *current_font_sprite_base = 0xE0; + // jmp loc_682875 + break; - case 0x0EA: - // jz loc_682A73 - *current_font_sprite_base = 0; - // jmp loc_682875 + case 0x0EA: + // jz loc_682A73 + *current_font_sprite_base = 0; + // jmp loc_682875 + break; - case 0x0EB: - // jz loc_682A8F - *current_font_flags |= 2; - // jmp loc_682875 + case 0x0EB: + // jz loc_682A8F + *current_font_flags |= 2; + // jmp loc_682875 + break; - case 0x0EC: - // jz loc_682A9C - *current_font_flags &= 0x0FFFD; - // jmp loc_682875 + case 0x0EC: + // jz loc_682A9C + *current_font_flags &= 0x0FFFD; + // jmp loc_682875 + break; - case 0x0ED: - // jz loc_682AAE - ebp = RCT2_GLOBAL(0x0141F740, uint8); - - // jmp short loc_682AC7 - - case 0x0EE: - // jz loc_682AC0 - ebp = RCT2_GLOBAL(0x0141F741, uint8); + case 0x0ED: + // jz loc_682AAE + ebp = RCT2_GLOBAL(0x0141F740, uint8); + if (*current_font_flags & 1) { + if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { + skip_char = 1; + } else { + skip_char = 0; + } + continue; + // jnz loc_682853 + } + sub_682AC7(ebp, &al, current_font_flags); + // jmp short loc_682AC7 + break; + case 0x0EE: + // jz loc_682AC0 + ebp = RCT2_GLOBAL(0x0141F741, uint8); + if (*current_font_flags & 1) { + if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { + skip_char = 1; + } else { + skip_char = 0; + } + continue; + // jnz loc_682853 + } + sub_682AC7(ebp, &al, current_font_flags); + // jmp short loc_682AC7 + break; + case 0x0EF: + // jz loc_682AB7 + ebp = RCT2_GLOBAL(0x0141F742, uint8); + if (*current_font_flags & 1) { + if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { + skip_char = 1; + } else { + skip_char = 0; + } + continue; + // jnz loc_682853 + } + sub_682AC7(ebp, &al, current_font_flags); + // jmp short loc_682AC7 + break; + case 0x0E2: + // jz loc_682AF7 + eax = *buffer; + buffer++; + if (*current_font_flags & 1) { + if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { + skip_char = 1; + break; + } + } - // jmp short loc_682AC7 + // push ebx + // mov eax, ds:dword_97FCBC[eax*4] + // shl eax, 4 + // mov eax, g1_elements[eax] + // mov bl, [eax+0F9h] + // mov bh, 1 - case 0x0EF: - // jz loc_682AB7 - ebp = RCT2_GLOBAL(0x0141F742, uint8); + eax = RCT2_ADDRESS(0x097FCBC, uint32)[eax*4]; + uint32* g1_element_poss = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, uint32)[eax*16]); + // What on earth is going on here? + g1_element_poss += 0xF9; + ebx = *g1_element_poss + (1 << 8); - // jmp short loc_682AC7 - - case 0x0E2: - // jz loc_682AF7 - eax = *buffer; - buffer++; - if (*current_font_flags & 1) { - // jnz loc_682853 - } + if (!(*current_font_flags & 2)) { + ebx = ebx & 0xFF; + } + RCT2_GLOBAL(0x09ABE05, uint16) = ebx; + ebx = *(g1_element_poss + 0xF7); + RCT2_GLOBAL(0x09ABE07, uint16) = ebx; + ebx = *(g1_element_poss + 0xFA); + RCT2_GLOBAL(0x09ABE09, uint16) = ebx; + + // pop ebx + RCT2_GLOBAL(0x09ABDA4, uint32) = RCT2_GLOBAL(0x09ABE04, uint32); + if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { + skip_char = 1; + } + break; + // jmp loc_682853 + + case 0x0F7: + // jz short loc_68296E + buffer += 4; + if (max_x >= dpi->x + dpi->width) { + skip_char = 1; + break; + } + ebx = *(buffer - 4); + eax = ebx & 0x7FFFF; + rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, rct_g1_element)[eax]); - // push ebx - // mov eax, ds:dword_97FCBC[eax*4] - // shl eax, 4 - // mov eax, g1_elements[eax] - // mov bl, [eax+0F9h] - // mov bh, 1 + gfx_draw_sprite(dpi, ebx, max_x, max_y); - eax = RCT2_ADDRESS(0x097FCBC, uint32)[eax*4]; - rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[eax]); - // What on earth is going on here? - bx = *(g1_element + 0xF9) + (1 << 8); + max_x = max_x + g1_element->offset; + // jmp loc_682875 + break; + } - if (!(*current_font_flags & 2)) { - bx = bx & 0xFF; - } - RCT2_GLOBAL(0x09ABE05, uint16) = bx; - bx = *(g1_element + 0xF7); - RCT2_GLOBAL(0x09ABE07, uint16) = bx; - bx = *(g1_element + 0xFA); - RCT2_GLOBAL(0x09ABE09, uint16) = bx; + } + if (x >= dpi->x + dpi->width) { + skip_char = 1; + } + if (x + 0x1A < dpi->x) { + // jl short loc_6828E0 + // loc_6828E0 + ebx = al; + ebx += *current_font_sprite_base; + max_x = max_x + (RCT2_ADDRESS(0x0141E9E8, uint8)[ebx] & 0xFF); + continue; + // jmp short loc_682875 + } + ebx = al + *current_font_sprite_base; + max_x = max_x + (RCT2_ADDRESS(0x0141E9E8, uint32)[ebx] & 0xFF); + // push dword_141E9E8[ebx] + // push ecx + // push edx + // push edi + // push esi - // pop ebx - RCT2_GLOBAL(0x09ABDA4, uint32) = RCT2_GLOBAL(0x09ABE04, uint32); - - // jmp loc_682853 - - case 0x0F7: - // jz short loc_68296E - buffer += 4; - if (cx >= dpi->x + dpi->width) { - skip_char; - } - ebx = *(format - 4); - eax = ebx & 0x7FFFF; - rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, rct_g1_element)[eax]); - - gfx_draw_sprite(dpi, ebx, cx, dx); - - cx += g1_element->offset; - // jmp loc_682875 - - } - // jmp loc_682875 - - // colour_char - al -= 0x8E; - if (*current_font_flags == 1) { - // jnz short loc_682853 - } - eax = eax & 0xFF; - // mov ebp, g1_elements+13320h - ebp = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 0x13320, uint32)); - // mov eax, [ebp+eax*4+0] - eax = *(ebp + eax*4); - - if (!(*current_font_flags & 2)) { - eax = eax & 0x0FF0000FF; - } - // jump 6842 - - - // loc_682AC7 - if (*current_font_flags & 1) { - // jnz loc_682853 - } - eax = RCT2_ADDRESS(0x0141FD45, uint8)[ebp * 8]; - if (*current_font_flags & 2) { - eax |= 0x0A0A00; - } - // jmp loc_682842 - - // skip_char - al = *buffer; - buffer++; - if (al < 0x20) { - // jb skip_cont - } - if (al >= 0x9C) { - // jnb short skip_char - } - if (al >= 0x8E) { - // jnb colour_char - } - // jmp short skip_char + eax = (int)al; + ebx += 0xF15; + ecx = max_x; + edx = max_y; + esi = (int)buffer; + edi = (int)dpi; + RCT2_GLOBAL(0x00EDF81C, uint32) = 0x20000000; + RCT2_CALLPROC_X(0x067A46E, eax, ebx, ecx, edx, esi, edi, ebp); + + // pop esi + // pop edi + // pop edx + // pop ecx + // pop eax + + continue; + // jmp short loc_682875 + + } else if (al >= 0x8E) { + al -= 0x8E; + if (*current_font_flags == 1) { + if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { + skip_char = 1; + } else { + skip_char = 0; + } + continue; + // jnz short loc_682853 + } + colour_char(al, current_font_flags); + continue; + // jnb colour_char + } + + } + + gLastDrawStringX = max_x; + gLastDrawStringY = max_y; + } From 702a97b185d5a952c03577f5609daf84d69fc9f0 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sun, 18 May 2014 22:06:08 +0200 Subject: [PATCH 72/99] Fix some bugs, tidy up Still buggy... --- src/gfx.c | 290 ++++++++++++++++++++---------------------------------- 1 file changed, 109 insertions(+), 181 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 9a5b968f5e..35cd38f30f 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1265,14 +1265,9 @@ void gfx_draw_string_left(rct_drawpixelinfo *dpi, int format, void *args, int co void colour_char(int al, uint16* current_font_flags) { int eax; - uint32* ebp; - // colour_char - eax = al & 0xFF; - // mov ebp, g1_elements+13320h - ebp = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 0x13320, uint32); - // mov eax, [ebp+eax*4+0] - eax = ebp[eax*4]; + rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[0x1332]); + eax = g1_element->offset[(al & 0xFF) * 4]; if (!(*current_font_flags & 2)) { eax = eax & 0x0FF0000FF; @@ -1280,7 +1275,6 @@ void colour_char(int al, uint16* current_font_flags) { // Store current colour? RCT2_GLOBAL(0x009ABE05, uint32) = eax; RCT2_GLOBAL(0x009ABDA4, uint32) = 0x009ABE04; - } @@ -1328,72 +1322,69 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in RCT2_GLOBAL(0x00EDF840, uint16) = x; RCT2_GLOBAL(0x00EDF842, uint16) = y; - if (colour & 0xFE) { - // jz loc_682853 - } - - if ((x >= dpi->x + dpi->width) || (x <= dpi->x) || - (y >= dpi->y + dpi->height) || (y <= dpi->y)) { - return; - } uint16* current_font_flags = &RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_FLAGS, uint16); uint16* current_font_sprite_base = &RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); - if (!(colour == 0xFF)) { + if (colour != 0xFE) { - // switch_colour: - *current_font_flags = 0; - if (*current_font_sprite_base < 0) { - *current_font_flags |= 4; - if (*current_font_sprite_base != 0xFFFF) { - *current_font_flags |= 8; - } - *current_font_sprite_base = 0xE0; - } - // loc_6827A5 - if (!(colour & (1 << 5))) { - *current_font_flags |= 2; + if ((x >= dpi->x + dpi->width) || (x <= dpi->x) || + (y >= dpi->y + dpi->height) || (y <= dpi->y)) { + return; } - // loc_6827B4 - if (!(colour & 0x40)) { - ebp = colour; - sub_682AC7(ebp, &colour, current_font_flags); - // jmp short loc_682AC7 - } else { - *current_font_flags |= 1; - colour &= 0x1F; + if (colour != 0xFF) { - ebp = colour; - - if (*current_font_flags & 4) { - if (*current_font_flags & 8) { - // loc_682805 - eax = RCT2_ADDRESS(0x0141FC48, uint8)[ebp * 8]; - eax = eax << 10; - eax = eax | RCT2_ADDRESS(0x0141FC46, uint8)[ebp * 8]; - } else { - // loc_6827E7 - eax = RCT2_ADDRESS(0x0141FC49, uint8)[ebp * 8]; - eax = eax << 10; - eax = eax | RCT2_ADDRESS(0x0141FC47, uint8)[ebp * 8]; + // switch_colour: + *current_font_flags = 0; + if (*current_font_sprite_base < 0) { + *current_font_flags |= 4; + if (*current_font_sprite_base != 0xFFFF) { + *current_font_flags |= 8; } - } else { - eax = RCT2_ADDRESS(0x0141FC4A, uint8)[ebp * 8]; - eax = eax << 10; - eax = eax | RCT2_ADDRESS(0x0141FC48, uint8)[ebp * 8]; + *current_font_sprite_base = 0xE0; + } + // loc_6827A5 + if (!(colour & (1 << 5))) { + *current_font_flags |= 2; } - // loc_682842 - // Store current colour? ; - RCT2_GLOBAL(0x009ABE05, uint32) = eax; - RCT2_GLOBAL(0x009ABDA4, uint32) = 0x009ABE04; - eax = 0; + // loc_6827B4 + if (!(colour & 0x40)) { + ebp = colour; + sub_682AC7(ebp, &colour, current_font_flags); + // jmp short loc_682AC7 + } else { + *current_font_flags |= 1; + colour &= 0x1F; + + ebp = colour; + + if (*current_font_flags & 4) { + if (*current_font_flags & 8) { + // loc_682805 + eax = RCT2_ADDRESS(0x0141FC48, uint8)[ebp * 8]; + eax = eax << 10; + eax = eax | RCT2_ADDRESS(0x0141FC46, uint8)[ebp * 8]; + } else { + // loc_6827E7 + eax = RCT2_ADDRESS(0x0141FC49, uint8)[ebp * 8]; + eax = eax << 10; + eax = eax | RCT2_ADDRESS(0x0141FC47, uint8)[ebp * 8]; + } + } else { + eax = RCT2_ADDRESS(0x0141FC4A, uint8)[ebp * 8]; + eax = eax << 10; + eax = eax | RCT2_ADDRESS(0x0141FC48, uint8)[ebp * 8]; + } + // loc_682842 + // Store current colour? ; + RCT2_GLOBAL(0x009ABE05, uint32) = eax; + RCT2_GLOBAL(0x009ABDA4, uint32) = 0x009ABE04; + eax = 0; + + } } - // jmp short loc_682842 - // jz loc_682853 } - int skip_char = 0; // loc_682853 @@ -1402,20 +1393,15 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in } // loc_682875 - // al = *buffer; - // buffer++; - - for (uint8 al = *buffer; al > 0; al= *buffer, ++buffer) { + for (uint8 al = *buffer; al > 0; ++buffer, al = *buffer) { // skip_char // al = *buffer; // buffer++; if (skip_char) { if (al < 0x20) { skip_char = 0; - // jb skip_cont } else if (al >= 0x9C) { continue; - // jnb short skip_char } else if (al >= 0x8E) { al -= 0x8E; if (*current_font_flags == 1) { @@ -1425,117 +1411,89 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in skip_char = 0; } continue; - // jnz short loc_682853 } colour_char(al, current_font_flags); continue; - // jnb colour_char } else { continue; - // jmp short skip_char } } // skip_cont - if (al >= 0x9C) { - // jnb short loc_682888 + if ((al >= 0x8E) && (al < 0x9C)){ + al -= 0x8E; + if (*current_font_flags == 1) { + if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { + skip_char = 1; + } else { + skip_char = 0; + } + continue; + } + colour_char(al, current_font_flags); + continue; + } else { // loc_682888 - al -= 0x20; - if (al < 0) { - // jb short loc_6828F5 - // loc_6828F5 + if (al < 0x20) { + al -= 0x20; switch (al) { case 0x0E5: - // jz loc_6829E3 max_x = RCT2_GLOBAL(0x0EDF840, uint16); max_y += 0x0A; if (*current_font_sprite_base <= 0x0E) { - // jbe loc_682875 break; } max_y -= 4; if (*current_font_sprite_base == 0x1C0) { - // jz loc_682875 break; } max_y -= 0xFFF4; - // jmp loc_682875 break; case 0x0E6: - // jz loc_6829AD max_x = RCT2_GLOBAL(0x0EDF840, uint16); max_y += 5; if (*current_font_sprite_base <= 0x0E) { - // jbe loc_682875 break; } max_y -= 2; if (*current_font_sprite_base == 0x1C0) { - // jz loc_682875 break; } max_y -= 0xFFFA; - // jmp loc_682875 break; case 0x0E1: - // jz loc_682A19 al = *buffer; buffer++; max_x = RCT2_GLOBAL(0x0EDF840, uint16); max_x += al; - // jmp loc_682875 break; - case 0x0F1: - // jz loc_682A34 eax = *((uint16*)buffer); buffer += 2; max_x = RCT2_GLOBAL(0x0EDF840, uint16); max_x += (eax & 0xFF); max_y = RCT2_GLOBAL(0x0EDF842, uint16); max_y += (eax & 0xFF00) >> 8; - // jmp loc_682875 break; - - case 0x0E7: - // jz loc_682A57 *current_font_sprite_base = 0x1C0; - // jmp loc_682875 break; - case 0x0E8: - // jz loc_682A65 *current_font_sprite_base = 0x2A0; - // jmp loc_682875 break; - case 0x0E9: - // jz loc_682A81 *current_font_sprite_base = 0xE0; - // jmp loc_682875 break; - case 0x0EA: - // jz loc_682A73 *current_font_sprite_base = 0; - // jmp loc_682875 break; - case 0x0EB: - // jz loc_682A8F *current_font_flags |= 2; - // jmp loc_682875 break; - case 0x0EC: - // jz loc_682A9C *current_font_flags &= 0x0FFFD; - // jmp loc_682875 break; - case 0x0ED: - // jz loc_682AAE ebp = RCT2_GLOBAL(0x0141F740, uint8); if (*current_font_flags & 1) { if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { @@ -1543,14 +1501,11 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in } else { skip_char = 0; } - continue; - // jnz loc_682853 + break; } sub_682AC7(ebp, &al, current_font_flags); - // jmp short loc_682AC7 break; case 0x0EE: - // jz loc_682AC0 ebp = RCT2_GLOBAL(0x0141F741, uint8); if (*current_font_flags & 1) { if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { @@ -1558,14 +1513,11 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in } else { skip_char = 0; } - continue; - // jnz loc_682853 + break; } sub_682AC7(ebp, &al, current_font_flags); - // jmp short loc_682AC7 break; case 0x0EF: - // jz loc_682AB7 ebp = RCT2_GLOBAL(0x0141F742, uint8); if (*current_font_flags & 1) { if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { @@ -1573,14 +1525,11 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in } else { skip_char = 0; } - continue; - // jnz loc_682853 + break; } sub_682AC7(ebp, &al, current_font_flags); - // jmp short loc_682AC7 break; case 0x0E2: - // jz loc_682AF7 eax = *buffer; buffer++; if (*current_font_flags & 1) { @@ -1618,10 +1567,7 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in skip_char = 1; } break; - // jmp loc_682853 - case 0x0F7: - // jz short loc_68296E buffer += 4; if (max_x >= dpi->x + dpi->width) { skip_char = 1; @@ -1634,67 +1580,49 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in gfx_draw_sprite(dpi, ebx, max_x, max_y); max_x = max_x + g1_element->offset; - // jmp loc_682875 break; } - } - if (x >= dpi->x + dpi->width) { - skip_char = 1; - } - if (x + 0x1A < dpi->x) { - // jl short loc_6828E0 - // loc_6828E0 - ebx = al; - ebx += *current_font_sprite_base; - max_x = max_x + (RCT2_ADDRESS(0x0141E9E8, uint8)[ebx] & 0xFF); - continue; - // jmp short loc_682875 - } - ebx = al + *current_font_sprite_base; - max_x = max_x + (RCT2_ADDRESS(0x0141E9E8, uint32)[ebx] & 0xFF); - // push dword_141E9E8[ebx] - // push ecx - // push edx - // push edi - // push esi - - eax = (int)al; - ebx += 0xF15; - ecx = max_x; - edx = max_y; - esi = (int)buffer; - edi = (int)dpi; - - RCT2_GLOBAL(0x00EDF81C, uint32) = 0x20000000; - - RCT2_CALLPROC_X(0x067A46E, eax, ebx, ecx, edx, esi, edi, ebp); - - // pop esi - // pop edi - // pop edx - // pop ecx - // pop eax - - continue; - // jmp short loc_682875 - - } else if (al >= 0x8E) { - al -= 0x8E; - if (*current_font_flags == 1) { - if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { + } else { + al -= 0x20; + if (max_x >= dpi->x + dpi->width) { skip_char = 1; - } else { - skip_char = 0; } - continue; - // jnz short loc_682853 - } - colour_char(al, current_font_flags); - continue; - // jnb colour_char - } + if (max_x + 0x1A < dpi->x) { + ebx = al; + ebx += *current_font_sprite_base; + max_x = max_x + (RCT2_ADDRESS(0x0141E9E8, uint8)[ebx] & 0xFF); + continue; + } + ebx = al + *current_font_sprite_base; + max_x = max_x + (RCT2_ADDRESS(0x0141E9E8, uint8)[ebx] & 0xFF); + // push dword_141E9E8[ebx] + // push ecx + // push edx + // push edi + // push esi + eax = (int)al; + ebx += 0xF15; + ecx = max_x; + edx = max_y; + esi = (int)buffer; + edi = (int)dpi; + ebp = 0; + + RCT2_GLOBAL(0x00EDF81C, uint32) = 0x20000000; + + RCT2_CALLPROC_X(0x067A46E, eax, ebx, ecx, edx, esi, edi, ebp); + + // pop esi + // pop edi + // pop edx + // pop ecx + // pop eax + + continue; + } + } } gLastDrawStringX = max_x; From c3ea45062b7a377a28c74c1c28f3aea94c93554f Mon Sep 17 00:00:00 2001 From: ZedThree Date: Thu, 22 May 2014 22:01:37 +0200 Subject: [PATCH 73/99] gfx_draw_string complete. Needs tidying --- src/gfx.c | 55 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 35cd38f30f..297c0564d9 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1278,17 +1278,19 @@ void colour_char(int al, uint16* current_font_flags) { } -void sub_682AC7(int ebp, int* eax, uint16* current_font_flags) { +void sub_682AC7(int ebp, uint16* current_font_flags) { + + int eax; // loc_682AC7 - *eax = RCT2_ADDRESS(0x0141FD45, uint8)[ebp * 8]; + eax = RCT2_ADDRESS(0x0141FD45, uint8)[ebp * 8]; if (*current_font_flags & 2) { - *eax |= 0x0A0A00; + eax |= 0x0A0A00; } - // Store current colour? - RCT2_GLOBAL(0x009ABE05, uint32) = *eax; + //Store current colour? + RCT2_GLOBAL(0x009ABE05, uint32) = eax; RCT2_GLOBAL(0x009ABDA4, uint32) = 0x009ABE04; - *eax = 0; + eax = 0; // jmp loc_682842 } @@ -1325,10 +1327,20 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in uint16* current_font_flags = &RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_FLAGS, uint16); uint16* current_font_sprite_base = &RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); + int skip_char = 0; + if (colour != 0xFE) { - if ((x >= dpi->x + dpi->width) || (x <= dpi->x) || - (y >= dpi->y + dpi->height) || (y <= dpi->y)) { + if (x >= dpi->x + dpi->width) + return; + + if (x + 0x280 <= dpi->x) + return; + + if (y >= dpi->y + dpi->height) + return; + + if (y + 0x5A <= dpi->y) { return; } @@ -1344,14 +1356,25 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in *current_font_sprite_base = 0xE0; } // loc_6827A5 - if (!(colour & (1 << 5))) { + // also reset bit 5 + if (colour & (1 << 5)) { *current_font_flags |= 2; } + colour &= ~(1 << 5); // loc_6827B4 if (!(colour & 0x40)) { ebp = colour; - sub_682AC7(ebp, &colour, current_font_flags); + if (*current_font_flags & 1) { + if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { + skip_char = 1; + } + else { + skip_char = 0; + } + } else { + sub_682AC7(ebp, current_font_flags); + } // jmp short loc_682AC7 } else { *current_font_flags |= 1; @@ -1385,7 +1408,6 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in } } } - int skip_char = 0; // loc_682853 if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { @@ -1503,7 +1525,7 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in } break; } - sub_682AC7(ebp, &al, current_font_flags); + sub_682AC7(ebp, current_font_flags); break; case 0x0EE: ebp = RCT2_GLOBAL(0x0141F741, uint8); @@ -1515,7 +1537,7 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in } break; } - sub_682AC7(ebp, &al, current_font_flags); + sub_682AC7(ebp, current_font_flags); break; case 0x0EF: ebp = RCT2_GLOBAL(0x0141F742, uint8); @@ -1527,7 +1549,7 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in } break; } - sub_682AC7(ebp, &al, current_font_flags); + sub_682AC7(ebp, current_font_flags); break; case 0x0E2: eax = *buffer; @@ -1595,6 +1617,9 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in continue; } ebx = al + *current_font_sprite_base; + + ecx = max_x; + max_x = max_x + (RCT2_ADDRESS(0x0141E9E8, uint8)[ebx] & 0xFF); // push dword_141E9E8[ebx] // push ecx @@ -1604,7 +1629,7 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in eax = (int)al; ebx += 0xF15; - ecx = max_x; + edx = max_y; esi = (int)buffer; edi = (int)dpi; From 67b7ca8d1eeb605c6236543bc83ce7d7f428ae0d Mon Sep 17 00:00:00 2001 From: ZedThree Date: Tue, 27 May 2014 19:16:05 +0200 Subject: [PATCH 74/99] Fix use of g1_elements and tidy comments --- src/gfx.c | 95 ++++++++++++++++--------------------------------------- 1 file changed, 28 insertions(+), 67 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 297c0564d9..916b1eecf4 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1308,25 +1308,21 @@ void sub_682AC7(int ebp, uint16* current_font_flags) { void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, int y) { int eax, ebx, ecx, edx, esi, edi, ebp; + rct_g1_element* g1_element; - // eax = colour; - // ebx = 0; - // ecx = x; - // edx = y; - // esi = (int)buffer; - // edi = (int)dpi; - // ebp = 0; - // RCT2_CALLFUNC_X(0x00682702, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); - + // Maximum length/height of string int max_x = x; int max_y = y; + // Store original x, y RCT2_GLOBAL(0x00EDF840, uint16) = x; RCT2_GLOBAL(0x00EDF842, uint16) = y; + // uint16* current_font_flags = &RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_FLAGS, uint16); uint16* current_font_sprite_base = &RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); + // Flag for skipping non-printing characters int skip_char = 0; if (colour != 0xFE) { @@ -1355,76 +1351,62 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in } *current_font_sprite_base = 0xE0; } - // loc_6827A5 - // also reset bit 5 if (colour & (1 << 5)) { *current_font_flags |= 2; } colour &= ~(1 << 5); - // loc_6827B4 if (!(colour & 0x40)) { ebp = colour; if (*current_font_flags & 1) { if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { skip_char = 1; - } - else { + } else { skip_char = 0; } } else { sub_682AC7(ebp, current_font_flags); } - // jmp short loc_682AC7 } else { *current_font_flags |= 1; colour &= 0x1F; - ebp = colour; - if (*current_font_flags & 4) { if (*current_font_flags & 8) { - // loc_682805 - eax = RCT2_ADDRESS(0x0141FC48, uint8)[ebp * 8]; + eax = RCT2_ADDRESS(0x0141FC48, uint8)[colour * 8]; eax = eax << 10; - eax = eax | RCT2_ADDRESS(0x0141FC46, uint8)[ebp * 8]; + eax = eax | RCT2_ADDRESS(0x0141FC46, uint8)[colour * 8]; } else { - // loc_6827E7 - eax = RCT2_ADDRESS(0x0141FC49, uint8)[ebp * 8]; + eax = RCT2_ADDRESS(0x0141FC49, uint8)[colour * 8]; eax = eax << 10; - eax = eax | RCT2_ADDRESS(0x0141FC47, uint8)[ebp * 8]; + eax = eax | RCT2_ADDRESS(0x0141FC47, uint8)[colour * 8]; } } else { - eax = RCT2_ADDRESS(0x0141FC4A, uint8)[ebp * 8]; + eax = RCT2_ADDRESS(0x0141FC4A, uint8)[colour * 8]; eax = eax << 10; - eax = eax | RCT2_ADDRESS(0x0141FC48, uint8)[ebp * 8]; + eax = eax | RCT2_ADDRESS(0x0141FC48, uint8)[colour * 8]; } - // loc_682842 // Store current colour? ; RCT2_GLOBAL(0x009ABE05, uint32) = eax; RCT2_GLOBAL(0x009ABDA4, uint32) = 0x009ABE04; eax = 0; - } } } - - // loc_682853 + if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { skip_char = 1; } - // loc_682875 for (uint8 al = *buffer; al > 0; ++buffer, al = *buffer) { - // skip_char - // al = *buffer; - // buffer++; + + // Skip to the next printing character if (skip_char) { if (al < 0x20) { + // Control codes skip_char = 0; - } else if (al >= 0x9C) { - continue; - } else if (al >= 0x8E) { + } else if (al >= 0x8E && al < 0x9C) { + // Colour codes al -= 0x8E; if (*current_font_flags == 1) { if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { @@ -1440,9 +1422,9 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in continue; } } - - // skip_cont + if ((al >= 0x8E) && (al < 0x9C)){ + // Colour codes al -= 0x8E; if (*current_font_flags == 1) { if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { @@ -1455,8 +1437,8 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in colour_char(al, current_font_flags); continue; } else { - // loc_682888 if (al < 0x20) { + // Control codes al -= 0x20; switch (al) { case 0x0E5: @@ -1552,7 +1534,7 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in sub_682AC7(ebp, current_font_flags); break; case 0x0E2: - eax = *buffer; + al = *buffer; buffer++; if (*current_font_flags & 1) { if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { @@ -1561,29 +1543,19 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in } } - // push ebx - // mov eax, ds:dword_97FCBC[eax*4] - // shl eax, 4 - // mov eax, g1_elements[eax] - // mov bl, [eax+0F9h] - // mov bh, 1 - - eax = RCT2_ADDRESS(0x097FCBC, uint32)[eax*4]; - uint32* g1_element_poss = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, uint32)[eax*16]); - // What on earth is going on here? - g1_element_poss += 0xF9; - ebx = *g1_element_poss + (1 << 8); + eax = RCT2_ADDRESS(0x097FCBC, uint32)[al*4]; + g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[eax]); + ebx = g1_element->offset[0xF9] + (1 << 8); if (!(*current_font_flags & 2)) { ebx = ebx & 0xFF; } RCT2_GLOBAL(0x09ABE05, uint16) = ebx; - ebx = *(g1_element_poss + 0xF7); + ebx = g1_element->offset[0xF7]; RCT2_GLOBAL(0x09ABE07, uint16) = ebx; - ebx = *(g1_element_poss + 0xFA); + ebx = g1_element->offset[0xFA]; RCT2_GLOBAL(0x09ABE09, uint16) = ebx; - // pop ebx RCT2_GLOBAL(0x09ABDA4, uint32) = RCT2_GLOBAL(0x09ABE04, uint32); if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { skip_char = 1; @@ -1597,7 +1569,7 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in } ebx = *(buffer - 4); eax = ebx & 0x7FFFF; - rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, rct_g1_element)[eax]); + g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, rct_g1_element)[eax]); gfx_draw_sprite(dpi, ebx, max_x, max_y); @@ -1621,11 +1593,6 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in ecx = max_x; max_x = max_x + (RCT2_ADDRESS(0x0141E9E8, uint8)[ebx] & 0xFF); - // push dword_141E9E8[ebx] - // push ecx - // push edx - // push edi - // push esi eax = (int)al; ebx += 0xF15; @@ -1639,12 +1606,6 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in RCT2_CALLPROC_X(0x067A46E, eax, ebx, ecx, edx, esi, edi, ebp); - // pop esi - // pop edi - // pop edx - // pop ecx - // pop eax - continue; } } From 504ce150ea2485cc24c2a3da348ed30b8f6b7cf3 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Tue, 27 May 2014 19:58:31 +0200 Subject: [PATCH 75/99] Fix bug in gfx_get_string_width --- src/gfx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 916b1eecf4..456f788442 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1041,6 +1041,7 @@ void gfx_redraw_screen_rect(short left, short top, short right, short bottom) } /** + * Return the width of the string in buffer * * rct2: 0x006C2321 * buffer (esi) @@ -1050,9 +1051,8 @@ int gfx_get_string_width(char *buffer) int base; int width; - char curr_char; + uint8 curr_char; - curr_char = 0; base = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); width = 0; From 55183d05897368315fcbf71ec6004c4c3bb2f097 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Tue, 27 May 2014 20:00:44 +0200 Subject: [PATCH 76/99] draw_string_centred --- src/gfx.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/gfx.c b/src/gfx.c index 456f788442..5b45d2b781 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -900,7 +900,18 @@ void gfx_transpose_palette(int pal, unsigned char product) */ void gfx_draw_string_centred(rct_drawpixelinfo *dpi, int format, int x, int y, int colour, void *args) { - RCT2_CALLPROC_X(0x006C1D6C, colour, format, x, y, (int)args, (int)dpi, 0); + char* buffer; + buffer = (char*)0x0141ED68; + format_string(buffer, format, args); + + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 0xE0; + + int width = gfx_get_string_width(buffer); + + if (width <= 0xFFF) { + x -= width / 2; + gfx_draw_string(dpi, buffer, colour, x, y); + } } /** From 4fdba86b0168696dbc6511d12d0aafa3145e1adb Mon Sep 17 00:00:00 2001 From: ZedThree Date: Thu, 29 May 2014 15:43:38 +0200 Subject: [PATCH 77/99] Add address for common string format buffer --- src/addresses.h | 2 ++ src/gfx.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 912461a9b3..974a9c7507 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -258,6 +258,8 @@ #define RCT2_ADDRESS_GAME_COMMAND_ERROR_STRING_ID 0x0141E9AE #define RCT2_ADDRESS_CURRENT_ROTATION 0x0141E9E0 +#define RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER 0x0141ED68 + #define RCT2_ADDRESS_WATER_RAISE_COST 0x0141F738 #define RCT2_ADDRESS_WATER_LOWER_COST 0x0141F73C diff --git a/src/gfx.c b/src/gfx.c index 5b45d2b781..c19b433554 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1188,7 +1188,7 @@ void gfx_draw_string_right(rct_drawpixelinfo* dpi, int format, void* args, int c char* buffer; short text_width; - buffer = (char*)0x0141ED68; + buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); format_string(buffer, format, args); // Measure text width @@ -1267,7 +1267,7 @@ void gfx_draw_string_left(rct_drawpixelinfo *dpi, int format, void *args, int co { char* buffer; - buffer = (char*)0x0141ED68; + buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); format_string(buffer, format, args); gfx_draw_string(dpi, buffer, colour, x, y); } From 130796052f66d7a68e1675f56f0cffd1860dcb7d Mon Sep 17 00:00:00 2001 From: ZedThree Date: Thu, 29 May 2014 15:44:33 +0200 Subject: [PATCH 78/99] More string functions --- src/gfx.c | 55 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index c19b433554..e1c3c1bcc9 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -901,15 +901,19 @@ void gfx_transpose_palette(int pal, unsigned char product) void gfx_draw_string_centred(rct_drawpixelinfo *dpi, int format, int x, int y, int colour, void *args) { char* buffer; - buffer = (char*)0x0141ED68; + short text_width; + + buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); format_string(buffer, format, args); RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 0xE0; - int width = gfx_get_string_width(buffer); + // Measure text width + text_width = gfx_get_string_width(buffer); - if (width <= 0xFFF) { - x -= width / 2; + // Draw the text centred + if (text_width <= 0xFFF) { + x -= text_width / 2; gfx_draw_string(dpi, buffer, colour, x, y); } } @@ -1132,15 +1136,19 @@ int gfx_get_string_width(char *buffer) */ void gfx_draw_string_left_clipped(rct_drawpixelinfo* dpi, int format, void* args, int colour, int x, int y, int width) { - RCT2_CALLPROC_X(0x006C1B83, colour, format, x, y, (int)args, (int)dpi, width); + // RCT2_CALLPROC_X(0x006C1B83, colour, format, x, y, (int)args, (int)dpi, width); - //char* buffer; + char* buffer; - //buffer = (char*)0x0141ED68; - //format_string(buffer, format, args); - //rctmem->current_font_sprite_base = 224; - //clip_text(buffer, width); - //gfx_draw_string(dpi, buffer, colour, x, y); + buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); + format_string(buffer, format, args); + + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 0xE0; + + // Clip text + RCT2_CALLPROC_X(0x006C2460, 0, 0, 0, 0, (int)buffer, width, 0); + + gfx_draw_string(dpi, buffer, colour, x, y); } /** @@ -1157,19 +1165,24 @@ void gfx_draw_string_left_clipped(rct_drawpixelinfo* dpi, int format, void* args */ void gfx_draw_string_centred_clipped(rct_drawpixelinfo *dpi, int format, void *args, int colour, int x, int y, int width) { - RCT2_CALLPROC_X(0x006C1BBA, colour, format, x, y, (int)args, (int)dpi, width); + char* buffer; + short text_width; - //char* buffer; - //short text_width; + buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); + format_string(buffer, format, args); - //buffer = (char*)0x0141ED68; - //format_string(buffer, format, args); - //rctmem->current_font_sprite_base = 224; - //text_width = clip_text(buffer, width); + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 0xE0; - //// Draw the text centred - //x -= (text_width - 1) / 2; - //gfx_draw_string(dpi, buffer, colour, x, y); + // Clip text + RCT2_CALLPROC_X(0x006C2460, 0, 0, 0, 0, (int)buffer, width, 0); + // // Measure text width + // text_width = gfx_get_string_width(buffer); + + // Draw the text centred + if (text_width <= 0xFFF) { + x -= text_width / 2; + gfx_draw_string(dpi, buffer, colour, x, y); + } } From b5d11159b38d9e1153ea39b5270fd2d231ade9a1 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Thu, 29 May 2014 15:44:47 +0200 Subject: [PATCH 79/99] Start of clip_text --- src/gfx.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/src/gfx.c b/src/gfx.c index e1c3c1bcc9..d35357875b 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1122,6 +1122,116 @@ int gfx_get_string_width(char *buffer) return width; } +/** + * Clip the text in buffer to width and return the new width of the clipped string + * + * rct2: 0x006C2460 + * buffer (esi) + * width (edi) + */ +int gfx_clip_string(char *buffer, int width) +{ + uint16 base; + + if (width < 6) { + *buffer = 0; + return 0; + } + + base = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); + edx = rct2_address(0x141E9F6, uint32)[base]; + + edx = &(edx + edx*2); + // lea edx, [edx+edx*2] + dx = -(edx & 0xFFFF); + dx += width; + eax = 0; + cx = 0; + max_x = 0; + ebp = buffer; + + + // loc_6C2485: ; CODE XREF: clip_text+42j + for (uint32 al = *buffer; al > 0; buffer++, al = *buffer) { + + if (al < 0x20) { + switch(curr_char) { + case 1: + width = *buffer; + buffer++; + continue; + case 2: + case 3: + case 4: + buffer++; + continue; + case 7: + base = 0x1C0; + // jmp short loc_6C2523 + break; + case 8: + base = 0x2A0; + // jmp short loc_6C2523 + break; + case 9: + base = 0x0E0; + // jmp short loc_6C2523 + break; + case 0x0A: + base = 0; + // jmp short loc_6C2523 + break; + case 0x17: + curr_char = *buffer; + curr_char &= 0x7FFFF; + buffer += 4; + curr_char <<= 4; + width = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[curr_char]; + curr_char = 0; + break; + default: + if (curr_char <= 0x10) { + continue; + } + buffer += 2; + if (curr_char <= 0x16) { + continue; + } + buffer += 2; + break; + } + + + // loc_6C2523: ; CODE XREF: clip_text+AEj + // ; clip_text+B5j ... + // movzx edx, byte_141E9F6[ebx] + // lea edx, [edx+edx*2] + // neg dx + // add dx, di + // jmp loc_6C2485 + + } else { + + max_x = max_x + (RCT2_ADDRESS(0x0141E9E8, uint8)[ebx] & 0xFF); + + // loc_6C249A: ; CODE XREF: clip_text+AAj + if (max_x > width) { + rct2_global(ebp + 0, uint32) = 0x2E2E2E; + max_x = width; + // pop esi + return; + } + if (max_x > dx) { + continue; + // ja short loc_6C2485 + } + ebp = buffer; + continue; + } + } +} + + /** * Draws i formatted text string left aligned at i specified position but clips * the text with an elipsis if the text width exceeds the specified width. From 9fecf42e518e665aaa4289c3e25832be4d01f158 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Thu, 29 May 2014 15:52:42 +0200 Subject: [PATCH 80/99] Tidy up loop on pointer --- src/gfx.c | 241 ++++++++++++++++++++++++++---------------------------- 1 file changed, 118 insertions(+), 123 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index d35357875b..7c14ab2ec6 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1066,26 +1066,24 @@ int gfx_get_string_width(char *buffer) int base; int width; - uint8 curr_char; - base = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); width = 0; - for (curr_char = *buffer; curr_char > 0; buffer++, curr_char = *buffer) { + for (uint8* curr_char = buffer; *curr_char > 0; curr_char++) { - if (curr_char >= 0x20) { - width += RCT2_ADDRESS(0x0141E9E8, uint8)[base + (curr_char-0x20)]; + if (*curr_char >= 0x20) { + width += RCT2_ADDRESS(0x0141E9E8, uint8)[base + (*curr_char-0x20)]; continue; } - switch(curr_char) { + switch(*curr_char) { case 1: - width = *buffer; - buffer++; + width = *curr_char; + curr_char++; break; case 2: case 3: case 4: - buffer++; + curr_char++; break; case 7: base = 0x1C0; @@ -1100,22 +1098,19 @@ int gfx_get_string_width(char *buffer) base = 0; break; case 0x17: - curr_char = *buffer; - curr_char &= 0x7FFFF; - buffer += 4; - curr_char <<= 4; - width = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[curr_char]; - curr_char = 0; + width = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[(*curr_char & 0x7FFFF) << 4]; + curr_char += 4; + *curr_char = 0; break; default: - if (curr_char <= 0x10) { + if (*curr_char <= 0x10) { continue; } - buffer += 2; - if (curr_char <= 0x16) { + curr_char += 2; + if (*curr_char <= 0x16) { continue; } - buffer += 2; + curr_char += 2; break; } } @@ -1129,107 +1124,107 @@ int gfx_get_string_width(char *buffer) * buffer (esi) * width (edi) */ -int gfx_clip_string(char *buffer, int width) -{ - uint16 base; +// int gfx_clip_string(char *buffer, int width) +// { +// uint16 base; - if (width < 6) { - *buffer = 0; - return 0; - } +// if (width < 6) { +// *buffer = 0; +// return 0; +// } - base = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); - edx = rct2_address(0x141E9F6, uint32)[base]; +// base = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); +// edx = rct2_address(0x141E9F6, uint32)[base]; - edx = &(edx + edx*2); - // lea edx, [edx+edx*2] - dx = -(edx & 0xFFFF); - dx += width; - eax = 0; - cx = 0; - max_x = 0; - ebp = buffer; +// edx = &(edx + edx*2); +// // lea edx, [edx+edx*2] +// dx = -(edx & 0xFFFF); +// dx += width; +// eax = 0; +// cx = 0; +// max_x = 0; +// ebp = buffer; - // loc_6C2485: ; CODE XREF: clip_text+42j - for (uint32 al = *buffer; al > 0; buffer++, al = *buffer) { +// // loc_6C2485: ; CODE XREF: clip_text+42j +// for (uint32 al = *buffer; al > 0; buffer++, al = *buffer) { - if (al < 0x20) { - switch(curr_char) { - case 1: - width = *buffer; - buffer++; - continue; - case 2: - case 3: - case 4: - buffer++; - continue; - case 7: - base = 0x1C0; - // jmp short loc_6C2523 - break; - case 8: - base = 0x2A0; - // jmp short loc_6C2523 - break; - case 9: - base = 0x0E0; - // jmp short loc_6C2523 - break; - case 0x0A: - base = 0; - // jmp short loc_6C2523 - break; - case 0x17: - curr_char = *buffer; - curr_char &= 0x7FFFF; - buffer += 4; - curr_char <<= 4; - width = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[curr_char]; - curr_char = 0; - break; - default: - if (curr_char <= 0x10) { - continue; - } - buffer += 2; - if (curr_char <= 0x16) { - continue; - } - buffer += 2; - break; - } +// if (al < 0x20) { +// switch(curr_char) { +// case 1: +// width = *buffer; +// buffer++; +// continue; +// case 2: +// case 3: +// case 4: +// buffer++; +// continue; +// case 7: +// base = 0x1C0; +// // jmp short loc_6C2523 +// break; +// case 8: +// base = 0x2A0; +// // jmp short loc_6C2523 +// break; +// case 9: +// base = 0x0E0; +// // jmp short loc_6C2523 +// break; +// case 0x0A: +// base = 0; +// // jmp short loc_6C2523 +// break; +// case 0x17: +// curr_char = *buffer; +// curr_char &= 0x7FFFF; +// buffer += 4; +// curr_char <<= 4; +// width = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[curr_char]; +// curr_char = 0; +// break; +// default: +// if (curr_char <= 0x10) { +// continue; +// } +// buffer += 2; +// if (curr_char <= 0x16) { +// continue; +// } +// buffer += 2; +// break; +// } - // loc_6C2523: ; CODE XREF: clip_text+AEj - // ; clip_text+B5j ... - // movzx edx, byte_141E9F6[ebx] - // lea edx, [edx+edx*2] - // neg dx - // add dx, di - // jmp loc_6C2485 +// // loc_6C2523: ; CODE XREF: clip_text+AEj +// // ; clip_text+B5j ... +// // movzx edx, byte_141E9F6[ebx] +// // lea edx, [edx+edx*2] +// // neg dx +// // add dx, di +// // jmp loc_6C2485 - } else { +// } else { - max_x = max_x + (RCT2_ADDRESS(0x0141E9E8, uint8)[ebx] & 0xFF); +// max_x = max_x + (RCT2_ADDRESS(0x0141E9E8, uint8)[ebx] & 0xFF); - // loc_6C249A: ; CODE XREF: clip_text+AAj - if (max_x > width) { - rct2_global(ebp + 0, uint32) = 0x2E2E2E; - max_x = width; - // pop esi - return; - } - if (max_x > dx) { - continue; - // ja short loc_6C2485 - } - ebp = buffer; - continue; - } - } -} +// // loc_6C249A: ; CODE XREF: clip_text+AAj +// if (max_x > width) { +// rct2_global(ebp + 0, uint32) = 0x2E2E2E; +// max_x = width; +// // pop esi +// return; +// } +// if (max_x > dx) { +// continue; +// // ja short loc_6C2485 +// } +// ebp = buffer; +// continue; +// } +// } +// } /** @@ -1275,24 +1270,24 @@ void gfx_draw_string_left_clipped(rct_drawpixelinfo* dpi, int format, void* args */ void gfx_draw_string_centred_clipped(rct_drawpixelinfo *dpi, int format, void *args, int colour, int x, int y, int width) { - char* buffer; - short text_width; + // char* buffer; + // short text_width; - buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); - format_string(buffer, format, args); + // buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); + // format_string(buffer, format, args); - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 0xE0; + // RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 0xE0; - // Clip text - RCT2_CALLPROC_X(0x006C2460, 0, 0, 0, 0, (int)buffer, width, 0); - // // Measure text width - // text_width = gfx_get_string_width(buffer); + // // Clip text + // RCT2_CALLPROC_X(0x006C2460, 0, 0, 0, 0, (int)buffer, width, 0); + // // // Measure text width + // // text_width = gfx_get_string_width(buffer); - // Draw the text centred - if (text_width <= 0xFFF) { - x -= text_width / 2; - gfx_draw_string(dpi, buffer, colour, x, y); - } + // // Draw the text centred + // if (text_width <= 0xFFF) { + // x -= text_width / 2; + // gfx_draw_string(dpi, buffer, colour, x, y); + // } } From 9c9ece2d7bd7310917ad21a1f02fbbf8e0abfd15 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Thu, 29 May 2014 21:21:01 +0200 Subject: [PATCH 81/99] clip text mostly working --- src/gfx.c | 188 +++++++++++++++++++++++------------------------------- 1 file changed, 80 insertions(+), 108 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 7c14ab2ec6..c9b2e5ab1e 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1124,107 +1124,81 @@ int gfx_get_string_width(char *buffer) * buffer (esi) * width (edi) */ -// int gfx_clip_string(char *buffer, int width) -// { -// uint16 base; +int gfx_clip_string(char *buffer, int width) +{ + uint16 base; + int edx, ebp; + int max_x; -// if (width < 6) { -// *buffer = 0; -// return 0; -// } + if (width < 6) { + *buffer = 0; + return 0; + } -// base = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); -// edx = rct2_address(0x141E9F6, uint32)[base]; + base = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); + edx = width - (3 * RCT2_ADDRESS(0x141E9F6, uint32)[base]); -// edx = &(edx + edx*2); -// // lea edx, [edx+edx*2] -// dx = -(edx & 0xFFFF); -// dx += width; -// eax = 0; -// cx = 0; -// max_x = 0; -// ebp = buffer; + max_x = 0; + ebp = buffer; + for (uint8* curr_char = buffer; *curr_char > 0; curr_char++) { + if (*curr_char < 0x20) { + switch(*curr_char) { + case 1: + width = *curr_char; + curr_char++; + continue; + case 2: + case 3: + case 4: + curr_char++; + continue; + case 7: + base = 0x1C0; + break; + case 8: + base = 0x2A0; + break; + case 9: + base = 0x0E0; + break; + case 0x0A: + base = 0; + break; + case 0x17: + max_x = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[(*curr_char & 0x7FFFF) << 4]; + curr_char += 4; + *curr_char = 0; + continue; + default: + if (*curr_char <= 0x10) { + continue; + } + curr_char += 2; + if (*curr_char <= 0x16) { + continue; + } + curr_char += 2; + continue; + } -// // loc_6C2485: ; CODE XREF: clip_text+42j -// for (uint32 al = *buffer; al > 0; buffer++, al = *buffer) { + edx = RCT2_ADDRESS(0x141E9F6, uint32)[base]; + edx = width - (3 * RCT2_ADDRESS(0x141E9F6, uint32)[base]); + } -// if (al < 0x20) { -// switch(curr_char) { -// case 1: -// width = *buffer; -// buffer++; -// continue; -// case 2: -// case 3: -// case 4: -// buffer++; -// continue; -// case 7: -// base = 0x1C0; -// // jmp short loc_6C2523 -// break; -// case 8: -// base = 0x2A0; -// // jmp short loc_6C2523 -// break; -// case 9: -// base = 0x0E0; -// // jmp short loc_6C2523 -// break; -// case 0x0A: -// base = 0; -// // jmp short loc_6C2523 -// break; -// case 0x17: -// curr_char = *buffer; -// curr_char &= 0x7FFFF; -// buffer += 4; -// curr_char <<= 4; -// width = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[curr_char]; -// curr_char = 0; -// break; -// default: -// if (curr_char <= 0x10) { -// continue; -// } -// buffer += 2; -// if (curr_char <= 0x16) { -// continue; -// } -// buffer += 2; -// break; -// } + max_x += (RCT2_ADDRESS(0x0141E9E8, uint8)[base] & 0xFF); - -// // loc_6C2523: ; CODE XREF: clip_text+AEj -// // ; clip_text+B5j ... -// // movzx edx, byte_141E9F6[ebx] -// // lea edx, [edx+edx*2] -// // neg dx -// // add dx, di -// // jmp loc_6C2485 - -// } else { - -// max_x = max_x + (RCT2_ADDRESS(0x0141E9E8, uint8)[ebx] & 0xFF); - -// // loc_6C249A: ; CODE XREF: clip_text+AAj -// if (max_x > width) { -// rct2_global(ebp + 0, uint32) = 0x2E2E2E; -// max_x = width; -// // pop esi -// return; -// } -// if (max_x > dx) { -// continue; -// // ja short loc_6C2485 -// } -// ebp = buffer; -// continue; -// } -// } -// } + if (max_x > width) { + RCT2_GLOBAL(ebp + 0, uint32) = 0x2E2E2E; + max_x = width; + return; + } + if (max_x <= edx) { + ebp = curr_char; + } + } + return max_x; +} /** @@ -1270,24 +1244,22 @@ void gfx_draw_string_left_clipped(rct_drawpixelinfo* dpi, int format, void* args */ void gfx_draw_string_centred_clipped(rct_drawpixelinfo *dpi, int format, void *args, int colour, int x, int y, int width) { - // char* buffer; - // short text_width; + char* buffer; + short text_width; - // buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); - // format_string(buffer, format, args); + buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); + format_string(buffer, format, args); - // RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 0xE0; + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 0xE0; - // // Clip text - // RCT2_CALLPROC_X(0x006C2460, 0, 0, 0, 0, (int)buffer, width, 0); - // // // Measure text width - // // text_width = gfx_get_string_width(buffer); + // Clip text + text_width = gfx_clip_string(buffer, width); - // // Draw the text centred - // if (text_width <= 0xFFF) { - // x -= text_width / 2; - // gfx_draw_string(dpi, buffer, colour, x, y); - // } + // Draw the text centred + if (text_width <= 0xFFF) { + x -= (text_width - 1) / 2; + gfx_draw_string(dpi, buffer, colour, x, y); + } } From 1dc794b038c2c6c1c5f445cbc05e82f1a6594912 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Thu, 29 May 2014 23:30:05 +0200 Subject: [PATCH 82/99] Finish clip string --- src/gfx.c | 60 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index c9b2e5ab1e..a546ac8231 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1118,30 +1118,35 @@ int gfx_get_string_width(char *buffer) } /** - * Clip the text in buffer to width and return the new width of the clipped string + * Clip the text in buffer to width, add ellipsis and return the new width of the clipped string * * rct2: 0x006C2460 * buffer (esi) * width (edi) */ -int gfx_clip_string(char *buffer, int width) +int gfx_clip_string(char* buffer, int width) { - uint16 base; - int edx, ebp; - int max_x; + // Location of font sprites + uint16 current_font_sprite_base; + // Width the string has to fit into + int max_width; + // Character to change to ellipsis + char* last_char; + // Width of the string, including ellipsis + int clipped_width; if (width < 6) { *buffer = 0; return 0; } - base = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); - edx = width - (3 * RCT2_ADDRESS(0x141E9F6, uint32)[base]); + current_font_sprite_base = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); + max_width = width - (3 * RCT2_ADDRESS(0x141E9F6, uint8)[current_font_sprite_base]); - max_x = 0; - ebp = buffer; + clipped_width = 0; + last_char = buffer; - for (uint8* curr_char = buffer; *curr_char > 0; curr_char++) { + for (char* curr_char = buffer; *curr_char > 0; curr_char++) { if (*curr_char < 0x20) { switch(*curr_char) { case 1: @@ -1154,19 +1159,19 @@ int gfx_clip_string(char *buffer, int width) curr_char++; continue; case 7: - base = 0x1C0; + current_font_sprite_base = 0x1C0; break; case 8: - base = 0x2A0; + current_font_sprite_base = 0x2A0; break; case 9: - base = 0x0E0; + current_font_sprite_base = 0x0E0; break; case 0x0A: - base = 0; + current_font_sprite_base = 0; break; case 0x17: - max_x = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[(*curr_char & 0x7FFFF) << 4]; + clipped_width = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[(*curr_char & 0x7FFFF) << 4]; curr_char += 4; *curr_char = 0; continue; @@ -1181,26 +1186,23 @@ int gfx_clip_string(char *buffer, int width) curr_char += 2; continue; } - - edx = RCT2_ADDRESS(0x141E9F6, uint32)[base]; - edx = width - (3 * RCT2_ADDRESS(0x141E9F6, uint32)[base]); + max_width = width - (3 * RCT2_ADDRESS(0x141E9F6, uint8)[current_font_sprite_base]); } - max_x += (RCT2_ADDRESS(0x0141E9E8, uint8)[base] & 0xFF); + clipped_width += RCT2_ADDRESS(0x0141E9E8, uint8)[current_font_sprite_base + (*curr_char-0x20)]; - if (max_x > width) { - RCT2_GLOBAL(ebp + 0, uint32) = 0x2E2E2E; - max_x = width; - return; + if (clipped_width >= width) { + RCT2_GLOBAL(last_char, uint32) = 0x2E2E2E; + clipped_width = width; + return clipped_width; } - if (max_x <= edx) { - ebp = curr_char; + if (clipped_width <= max_width) { + last_char = curr_char; } } - return max_x; + return clipped_width; } - /** * Draws i formatted text string left aligned at i specified position but clips * the text with an elipsis if the text width exceeds the specified width. @@ -1224,8 +1226,8 @@ void gfx_draw_string_left_clipped(rct_drawpixelinfo* dpi, int format, void* args RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 0xE0; - // Clip text - RCT2_CALLPROC_X(0x006C2460, 0, 0, 0, 0, (int)buffer, width, 0); + // Clip text - return value is not needed + gfx_clip_string(buffer, width); gfx_draw_string(dpi, buffer, colour, x, y); } From 5b41528e2e726445cadeb4de407a2be74c5967bb Mon Sep 17 00:00:00 2001 From: ZedThree Date: Thu, 29 May 2014 23:30:20 +0200 Subject: [PATCH 83/99] Rename variables in get_width to align with clip_string --- src/gfx.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index a546ac8231..ce3c8cdac8 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1061,18 +1061,20 @@ void gfx_redraw_screen_rect(short left, short top, short right, short bottom) * rct2: 0x006C2321 * buffer (esi) */ -int gfx_get_string_width(char *buffer) +int gfx_get_string_width(char* buffer) { - int base; + // Current font sprites + uint16 current_font_sprite_base; + // Width of string int width; - base = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); + current_font_sprite_base = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); width = 0; - for (uint8* curr_char = buffer; *curr_char > 0; curr_char++) { + for (char* curr_char = buffer; *curr_char > 0; curr_char++) { if (*curr_char >= 0x20) { - width += RCT2_ADDRESS(0x0141E9E8, uint8)[base + (*curr_char-0x20)]; + width += RCT2_ADDRESS(0x0141E9E8, uint8)[current_font_sprite_base + (*curr_char-0x20)]; continue; } switch(*curr_char) { @@ -1086,16 +1088,16 @@ int gfx_get_string_width(char *buffer) curr_char++; break; case 7: - base = 0x1C0; + current_font_sprite_base = 0x1C0; break; case 8: - base = 0x2A0; + current_font_sprite_base = 0x2A0; break; case 9: - base = 0x0E0; + current_font_sprite_base = 0x0E0; break; case 0x0A: - base = 0; + current_font_sprite_base = 0; break; case 0x17: width = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[(*curr_char & 0x7FFFF) << 4]; From 583fbaa2a4357419632109cf9b37e38881b60454 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Fri, 30 May 2014 14:10:27 +0200 Subject: [PATCH 84/99] Fix some pointer issues --- src/gfx.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index ce3c8cdac8..c2ec96794f 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1064,17 +1064,17 @@ void gfx_redraw_screen_rect(short left, short top, short right, short bottom) int gfx_get_string_width(char* buffer) { // Current font sprites - uint16 current_font_sprite_base; + uint16* current_font_sprite_base; // Width of string int width; - current_font_sprite_base = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); + current_font_sprite_base = RCT2_ADDRESS(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); width = 0; - for (char* curr_char = buffer; *curr_char > 0; curr_char++) { + for (char* curr_char = buffer; *curr_char != NULL; curr_char++) { if (*curr_char >= 0x20) { - width += RCT2_ADDRESS(0x0141E9E8, uint8)[current_font_sprite_base + (*curr_char-0x20)]; + width += RCT2_ADDRESS(0x0141E9E8, uint8)[*current_font_sprite_base + (*curr_char-0x20)]; continue; } switch(*curr_char) { @@ -1088,16 +1088,16 @@ int gfx_get_string_width(char* buffer) curr_char++; break; case 7: - current_font_sprite_base = 0x1C0; + *current_font_sprite_base = 0x1C0; break; case 8: - current_font_sprite_base = 0x2A0; + *current_font_sprite_base = 0x2A0; break; case 9: - current_font_sprite_base = 0x0E0; + *current_font_sprite_base = 0x0E0; break; case 0x0A: - current_font_sprite_base = 0; + *current_font_sprite_base = 0; break; case 0x17: width = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[(*curr_char & 0x7FFFF) << 4]; @@ -1129,7 +1129,7 @@ int gfx_get_string_width(char* buffer) int gfx_clip_string(char* buffer, int width) { // Location of font sprites - uint16 current_font_sprite_base; + uint16* current_font_sprite_base; // Width the string has to fit into int max_width; // Character to change to ellipsis @@ -1142,13 +1142,13 @@ int gfx_clip_string(char* buffer, int width) return 0; } - current_font_sprite_base = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); - max_width = width - (3 * RCT2_ADDRESS(0x141E9F6, uint8)[current_font_sprite_base]); + current_font_sprite_base = RCT2_ADDRESS(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); + max_width = width - (3 * RCT2_ADDRESS(0x141E9F6, uint8)[*current_font_sprite_base]); clipped_width = 0; last_char = buffer; - for (char* curr_char = buffer; *curr_char > 0; curr_char++) { + for (char* curr_char = buffer; *curr_char != NULL; curr_char++) { if (*curr_char < 0x20) { switch(*curr_char) { case 1: @@ -1161,16 +1161,16 @@ int gfx_clip_string(char* buffer, int width) curr_char++; continue; case 7: - current_font_sprite_base = 0x1C0; + *current_font_sprite_base = 0x1C0; break; case 8: - current_font_sprite_base = 0x2A0; + *current_font_sprite_base = 0x2A0; break; case 9: - current_font_sprite_base = 0x0E0; + *current_font_sprite_base = 0x0E0; break; case 0x0A: - current_font_sprite_base = 0; + *current_font_sprite_base = 0; break; case 0x17: clipped_width = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[(*curr_char & 0x7FFFF) << 4]; @@ -1188,10 +1188,10 @@ int gfx_clip_string(char* buffer, int width) curr_char += 2; continue; } - max_width = width - (3 * RCT2_ADDRESS(0x141E9F6, uint8)[current_font_sprite_base]); + max_width = width - (3 * RCT2_ADDRESS(0x141E9F6, uint8)[*current_font_sprite_base]); } - clipped_width += RCT2_ADDRESS(0x0141E9E8, uint8)[current_font_sprite_base + (*curr_char-0x20)]; + clipped_width += RCT2_ADDRESS(0x0141E9E8, uint8)[*current_font_sprite_base + (*curr_char-0x20)]; if (clipped_width >= width) { RCT2_GLOBAL(last_char, uint32) = 0x2E2E2E; @@ -1424,8 +1424,8 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in RCT2_GLOBAL(0x00EDF842, uint16) = y; // - uint16* current_font_flags = &RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_FLAGS, uint16); - uint16* current_font_sprite_base = &RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); + uint16* current_font_flags = RCT2_ADDRESS(RCT2_ADDRESS_CURRENT_FONT_FLAGS, uint16); + uint16* current_font_sprite_base = RCT2_ADDRESS(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); // Flag for skipping non-printing characters int skip_char = 0; From a06f6ade8b42bbe491c84c9d5f5e7a53b62692b5 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sat, 31 May 2014 16:39:40 +0200 Subject: [PATCH 85/99] String functions for wrapped text --- src/gfx.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 124 insertions(+), 16 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index c2ec96794f..2a80c2e1f5 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1307,15 +1307,62 @@ void gfx_draw_string_right(rct_drawpixelinfo* dpi, int format, void* args, int c int gfx_draw_string_centred_wrapped(rct_drawpixelinfo *dpi, void *args, int x, int y, int width, int format, int colour) { int eax, ebx, ecx, edx, esi, edi, ebp; + // Location of font sprites + uint16* current_font_sprite_base; + // Location of font flags + uint16 current_font_flags; - eax = colour; - ebx = format; - ecx = x; - edx = y; - esi = (int)args; - edi = (int)dpi; - ebp = width; - RCT2_CALLFUNC_X(0x006C1E53, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + current_font_sprite_base = RCT2_ADDRESS(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); + *current_font_sprite_base = 0xE0; + + char* buffer = RCT2_ADDRESS(0x009C383D, char); + + gfx_draw_string(dpi, buffer, colour, dpi->x, dpi->y); + + buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); + + format_string(buffer, format, args); + + *current_font_sprite_base = 0xE0; + + esi = buffer; + edi = width; + RCT2_CALLFUNC_X(0x006C21E2, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + ecx &= 0xFFFF; + edi &= 0xFFFF; + + RCT2_GLOBAL(0x00F43938, uint16) = 0x0A; + + if (ebx > 0xE0) { + RCT2_GLOBAL(0x00F43938, uint16) = 6; + if (ebx != 0x1C0) { + RCT2_GLOBAL(0x00F43938, uint16) = 0x12; + } + } + + if (*buffer == 0x0B) { + RCT2_GLOBAL(0x00F43938, uint16) = RCT2_GLOBAL(0x00F43938, uint16) + 1; + } + + ebx = (RCT2_GLOBAL(0x00F43938, uint16) / 2) * edi; + edx = y - ebx; + + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_FLAGS, uint16) = 0; + + buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); + + do { + int new_width = gfx_get_string_width(buffer); + new_width /= 2; + gfx_draw_string(dpi, buffer, 0xFE, x - new_width, edx); + + buffer += strlen(buffer) + 1; + + edx += RCT2_GLOBAL(0x00F43938, uint16); + eax = (RCT2_GLOBAL(0x00F43938, uint16) / 2) * edi; + ebx -= eax; + + } while (ebx > 0); return (sint16)(edx & 0xFFFF) - y; } @@ -1334,17 +1381,78 @@ int gfx_draw_string_centred_wrapped(rct_drawpixelinfo *dpi, void *args, int x, i int gfx_draw_string_left_wrapped(rct_drawpixelinfo *dpi, void *args, int x, int y, int width, int format, int colour) { int eax, ebx, ecx, edx, esi, edi, ebp; + + // eax = colour; + // ebx = format; + // ecx = x; + // edx = y; + // esi = (int)args; + // edi = (int)dpi; + // ebp = width; + // RCT2_CALLFUNC_X(0x006C2105, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + // return (sint16)(edx & 0xFFFF) - y; - eax = colour; - ebx = format; - ecx = x; - edx = y; - esi = (int)args; - edi = (int)dpi; - ebp = width; - RCT2_CALLFUNC_X(0x006C2105, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + // Location of font sprites + uint16* current_font_sprite_base; + // Location of font flags + uint16 current_font_flags; + + current_font_sprite_base = RCT2_ADDRESS(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); + *current_font_sprite_base = 0xE0; + + char* buffer = RCT2_ADDRESS(0x009C383D, char); + + gfx_draw_string(dpi, buffer, colour, dpi->x, dpi->y); + + buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); + + format_string(buffer, format, args); + + buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); + + *current_font_sprite_base = 0xE0; + + // Add line breaks? Adds \0 rather than \n + // not working for strings with colour code? + esi = buffer; + edi = width; + RCT2_CALLFUNC_X(0x006C21E2, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + ecx &= 0xFFFF; + edi &= 0xFFFF; + + // Font height? + RCT2_GLOBAL(0x00F43938, uint16) = 0x0A; + + if (ebx > 0xE0) { + RCT2_GLOBAL(0x00F43938, uint16) = 6; + if (ebx != 0x1C0) { + RCT2_GLOBAL(0x00F43938, uint16) = 0x12; + } + } + + // Number of lines? + ebx = (RCT2_GLOBAL(0x00F43938, uint16) / 2) * edi; + + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_FLAGS, uint16) = 0; + + buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); + esi = buffer; + + edx = y; + + do { + gfx_draw_string(dpi, buffer, 0xFE, x, edx); + + buffer += strlen(buffer) + 1; + + edx += RCT2_GLOBAL(0x00F43938, uint16); + eax = (RCT2_GLOBAL(0x00F43938, uint16) / 2); + ebx -= eax; + + } while (ebx >= 0); return (sint16)(edx & 0xFFFF) - y; + } /** From 8b1c76b1b608fed23139629fa4a164153edd2ea2 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sat, 31 May 2014 16:43:39 +0200 Subject: [PATCH 86/99] Replace pad_0E with zoom_level --- src/gfx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 2a80c2e1f5..8bdd35d596 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -354,7 +354,7 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot } else { // 00678B7E 00678C83 - if (dpi->pad_0E < 1) { + if (dpi->zoom_level < 1) { // Location in screen buffer? uint8* pixel = top_ * (dpi->width + dpi->pitch) + left_ + dpi->bits; @@ -372,10 +372,10 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot } pixel += length; } - } else if (dpi->pad_0E > 1) { + } else if (dpi->zoom_level > 1) { // 00678C8A 00678D57 right_ = right; - } else if (dpi->pad_0E == 1) { + } else if (dpi->zoom_level == 1) { // 00678C88 00678CEE right = right; } @@ -750,12 +750,12 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) ebx &= 0x7FFFF; ebx <<= 4; ebx += RCT2_ADDRESS_G1_ELEMENTS; - if (dpi->pad_0E >= 1){ - if (dpi->pad_0E == 1){ + if (dpi->zoom_level >= 1){ + if (dpi->zoom_level == 1){ return; //jump into 0x67bd81 } - if (dpi->pad_0E >= 3){ + if (dpi->zoom_level >= 3){ return;//jump into 0x67FAAE } //jump into 0x67DADA From f1c8981e7982027b65b09d5d84c9db06ca7924d5 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 1 Jun 2014 09:25:53 +0100 Subject: [PATCH 87/99] Switched to draw_sprite in draw_string function. Added freeing of zoomed image --- src/gfx.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gfx.c b/src/gfx.c index 62bc70faf0..6d91090cb7 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -948,6 +948,9 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) gfx_draw_sprite_palette_set(dpi, image_id, x, y, palette_pointer, unknown_pointer); } +/* +* 0x67A46E +*/ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, int y, uint8* palette_pointer, uint8* unknown_pointer){ int image_element = 0x7FFFF&image_id; int image_type = (image_id & 0xE0000000) >> 28; @@ -1050,6 +1053,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in if (!(g1_source->flags & 0x02)){ gfx_bmp_sprite_to_buffer(palette_pointer, unknown_pointer, source_pointer, dest_pointer, g1_source, dpi, height, width, image_type); + if (zoomed.offset)free(zoomed.offset); return; } //0x67A60A Not tested @@ -2048,7 +2052,8 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in RCT2_GLOBAL(0x00EDF81C, uint32) = 0x20000000; - RCT2_CALLPROC_X(0x067A46E, eax, ebx, ecx, edx, esi, edi, ebp); + gfx_draw_sprite_palette_set(dpi, 0x20000000 | ebx, ecx, edx, RCT2_GLOBAL(0x9ABDA4, uint8*), NULL); + //RCT2_CALLPROC_X(0x067A46E, eax, ebx, ecx, edx, esi, edi, ebp); continue; } From 1629b3fce79cdc410923e49f254a69c1f1923851 Mon Sep 17 00:00:00 2001 From: Duncan Date: Mon, 2 Jun 2014 16:55:02 +0100 Subject: [PATCH 88/99] Fixed possible small palette bug. Added notes on what is happening in draw_string. --- src/gfx.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 6d91090cb7..76865b1ae1 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -63,6 +63,11 @@ uint8 peep_palette[0x100] = { 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF }; +//Originally 0x9ABE04 +uint8 text_palette[0x8] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + static void gfx_draw_dirty_blocks(int x, int y, int columns, int rows); /** @@ -1720,7 +1725,7 @@ void colour_char(int al, uint16* current_font_flags) { if (!(*current_font_flags & 2)) { eax = eax & 0x0FF0000FF; } - // Store current colour? + // Adjust text palette. Store current colour? RCT2_GLOBAL(0x009ABE05, uint32) = eax; RCT2_GLOBAL(0x009ABDA4, uint32) = 0x009ABE04; } @@ -1735,7 +1740,7 @@ void sub_682AC7(int ebp, uint16* current_font_flags) { if (*current_font_flags & 2) { eax |= 0x0A0A00; } - //Store current colour? + //Adjust text palette. Store current colour? RCT2_GLOBAL(0x009ABE05, uint32) = eax; RCT2_GLOBAL(0x009ABDA4, uint32) = 0x009ABE04; eax = 0; @@ -1834,7 +1839,7 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in eax = eax << 10; eax = eax | RCT2_ADDRESS(0x0141FC48, uint8)[colour * 8]; } - // Store current colour? ; + // Adjust text palette. Store current colour? ; RCT2_GLOBAL(0x009ABE05, uint32) = eax; RCT2_GLOBAL(0x009ABDA4, uint32) = 0x009ABE04; eax = 0; @@ -1998,13 +2003,14 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in if (!(*current_font_flags & 2)) { ebx = ebx & 0xFF; } + //Adjust the text palette RCT2_GLOBAL(0x09ABE05, uint16) = ebx; ebx = g1_element->offset[0xF7]; RCT2_GLOBAL(0x09ABE07, uint16) = ebx; ebx = g1_element->offset[0xFA]; RCT2_GLOBAL(0x09ABE09, uint16) = ebx; - - RCT2_GLOBAL(0x09ABDA4, uint32) = RCT2_GLOBAL(0x09ABE04, uint32); + //Set the palette pointer + RCT2_GLOBAL(0x09ABDA4, uint32) = 0x09ABE04; if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { skip_char = 1; } From 49432dd96f7efedf42fa43987034595b0f01cee6 Mon Sep 17 00:00:00 2001 From: Duncan Date: Tue, 3 Jun 2014 12:57:58 +0100 Subject: [PATCH 89/99] Added a few notes to draw_string. --- src/gfx.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 76865b1ae1..441a201120 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1894,8 +1894,8 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in // Control codes al -= 0x20; switch (al) { - case 0x0E5: - max_x = RCT2_GLOBAL(0x0EDF840, uint16); + case 0x0E5://Start New Line at set y lower + max_x = x;//RCT2_GLOBAL(0x0EDF840, uint16); max_y += 0x0A; if (*current_font_sprite_base <= 0x0E) { break; @@ -1906,8 +1906,8 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in } max_y -= 0xFFF4; break; - case 0x0E6: - max_x = RCT2_GLOBAL(0x0EDF840, uint16); + case 0x0E6://Start New Line at set y lower + max_x = x;//RCT2_GLOBAL(0x0EDF840, uint16); max_y += 5; if (*current_font_sprite_base <= 0x0E) { break; @@ -1916,20 +1916,20 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in if (*current_font_sprite_base == 0x1C0) { break; } - max_y -= 0xFFFA; + max_y -= 0xFFFA;//This does not look correct probably should be an add break; - case 0x0E1: + case 0x0E1://Start New Line at start+buffer x, same y. (Overwrite?) al = *buffer; buffer++; - max_x = RCT2_GLOBAL(0x0EDF840, uint16); + max_x = x;//RCT2_GLOBAL(0x0EDF840, uint16); max_x += al; break; - case 0x0F1: + case 0x0F1: //Start new line at specified x,y eax = *((uint16*)buffer); buffer += 2; - max_x = RCT2_GLOBAL(0x0EDF840, uint16); + max_x = x;//RCT2_GLOBAL(0x0EDF840, uint16); max_x += (eax & 0xFF); - max_y = RCT2_GLOBAL(0x0EDF842, uint16); + max_y = y;//RCT2_GLOBAL(0x0EDF842, uint16); max_y += (eax & 0xFF00) >> 8; break; case 0x0E7: @@ -2023,11 +2023,11 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in } ebx = *(buffer - 4); eax = ebx & 0x7FFFF; - g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, rct_g1_element)[eax]); + g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[eax]); gfx_draw_sprite(dpi, ebx, max_x, max_y); - max_x = max_x + g1_element->offset; + max_x = max_x + g1_element->width; break; } From 8b233c2f794b8513db76d37e949e57887c391aba Mon Sep 17 00:00:00 2001 From: Duncan Date: Wed, 4 Jun 2014 12:30:53 +0100 Subject: [PATCH 90/99] More gfx_draw_string notes. --- src/gfx.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 441a201120..850f5fffff 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1307,13 +1307,15 @@ int gfx_get_string_width(char* buffer) uint16* current_font_sprite_base; // Width of string int width; - + rct_g1_element* g1_element; + current_font_sprite_base = RCT2_ADDRESS(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); width = 0; for (char* curr_char = buffer; *curr_char != NULL; curr_char++) { if (*curr_char >= 0x20) { + //Maybe global not address?? width += RCT2_ADDRESS(0x0141E9E8, uint8)[*current_font_sprite_base + (*curr_char-0x20)]; continue; } @@ -1340,7 +1342,8 @@ int gfx_get_string_width(char* buffer) *current_font_sprite_base = 0; break; case 0x17: - width = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[(*curr_char & 0x7FFFF) << 4]; + g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[*curr_char&0x7FFFF]); + width = g1_element.width; //RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[(*curr_char & 0x7FFFF) << 4]; curr_char += 4; *curr_char = 0; break; From 55e8fe74ffd1e84d645e5e988e758764b3e69097 Mon Sep 17 00:00:00 2001 From: Duncan Date: Wed, 4 Jun 2014 17:04:33 +0100 Subject: [PATCH 91/99] more small changes --- src/gfx.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 850f5fffff..ac7639a1a3 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1343,9 +1343,8 @@ int gfx_get_string_width(char* buffer) break; case 0x17: g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[*curr_char&0x7FFFF]); - width = g1_element.width; //RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[(*curr_char & 0x7FFFF) << 4]; + width += g1_element.width; //RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[(*curr_char & 0x7FFFF) << 4]; curr_char += 4; - *curr_char = 0; break; default: if (*curr_char <= 0x10) { @@ -1416,9 +1415,8 @@ int gfx_clip_string(char* buffer, int width) *current_font_sprite_base = 0; break; case 0x17: - clipped_width = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[(*curr_char & 0x7FFFF) << 4]; + clipped_width += RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[(*curr_char & 0x7FFFF) << 4]; curr_char += 4; - *curr_char = 0; continue; default: if (*curr_char <= 0x10) { From c333e9f0429171a85b7a71146edd2ed647784d0c Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 4 Jun 2014 19:47:46 +0100 Subject: [PATCH 92/99] Fix small dereference mistake --- src/gfx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gfx.c b/src/gfx.c index ac7639a1a3..85ac18c4be 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1343,7 +1343,7 @@ int gfx_get_string_width(char* buffer) break; case 0x17: g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[*curr_char&0x7FFFF]); - width += g1_element.width; //RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[(*curr_char & 0x7FFFF) << 4]; + width += g1_element->width; //RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS + 4, uint16)[(*curr_char & 0x7FFFF) << 4]; curr_char += 4; break; default: From f6a3c2dd04d4e1a722e923403d6139b2406af40f Mon Sep 17 00:00:00 2001 From: Duncan Date: Thu, 5 Jun 2014 16:49:30 +0100 Subject: [PATCH 93/99] Fix small palette issue. --- src/gfx.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 85ac18c4be..d3ec14b9b7 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -2006,10 +2006,12 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in } //Adjust the text palette RCT2_GLOBAL(0x09ABE05, uint16) = ebx; - ebx = g1_element->offset[0xF7]; - RCT2_GLOBAL(0x09ABE07, uint16) = ebx; - ebx = g1_element->offset[0xFA]; - RCT2_GLOBAL(0x09ABE09, uint16) = ebx; + memcpy((uint8*)0x09ABE07,&(g1_element->offset[0xF7]),2); + //ebx = g1_element->offset[0xF7]; + //RCT2_GLOBAL(0x09ABE07, uint16) = ebx; + memcpy((uint8*)0x09ABE09,&(g1_element->offset[0xFA]),2); + //ebx = g1_element->offset[0xFA]; + //RCT2_GLOBAL(0x09ABE09, uint16) = ebx; //Set the palette pointer RCT2_GLOBAL(0x09ABDA4, uint32) = 0x09ABE04; if ((y + 0x13 <= dpi->y) || (dpi->y + dpi->height <= y)) { From c158d98e5c9316ecab71decc3d2cd3b43f416b17 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 6 Jun 2014 09:54:30 +0100 Subject: [PATCH 94/99] Fixed graphical text glitch. Due to not copying whole dword --- src/gfx.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/gfx.c b/src/gfx.c index d3ec14b9b7..04ad5a64d1 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1721,7 +1721,7 @@ void colour_char(int al, uint16* current_font_flags) { int eax; rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[0x1332]); - eax = g1_element->offset[(al & 0xFF) * 4]; + eax = ((uint32*)g1_element->offset)[al & 0xFF]; if (!(*current_font_flags & 2)) { eax = eax & 0x0FF0000FF; @@ -1761,6 +1761,20 @@ void sub_682AC7(int ebp, uint16* current_font_flags) { */ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, int y) { + //int eax, ebx, ecx, edx, esi, edi, ebp; + //char* find = "FINDMEDRAWSTRING"; + //eax = colour; + //ebx = 0; + //ecx = x; + //edx = y; + //esi = (int)buffer; + //edi = (int)dpi; + //ebp = 0; + //RCT2_CALLFUNC_X(0x00682702, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + + //gLastDrawStringX = ecx; + //gLastDrawStringY = edx; + int eax, ebx, ecx, edx, esi, edi, ebp; rct_g1_element* g1_element; From 9f01c5d6bf5b01ead73c0d6323b7eac594450420 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 6 Jun 2014 10:18:39 +0100 Subject: [PATCH 95/99] Fixed small positioning bug in draw_string due to incorrect signness. --- src/gfx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 04ad5a64d1..39688966ba 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1312,7 +1312,7 @@ int gfx_get_string_width(char* buffer) current_font_sprite_base = RCT2_ADDRESS(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); width = 0; - for (char* curr_char = buffer; *curr_char != NULL; curr_char++) { + for (uint8* curr_char = buffer; *curr_char != NULL; curr_char++) { if (*curr_char >= 0x20) { //Maybe global not address?? @@ -1390,7 +1390,7 @@ int gfx_clip_string(char* buffer, int width) clipped_width = 0; last_char = buffer; - for (char* curr_char = buffer; *curr_char != NULL; curr_char++) { + for (uint8* curr_char = buffer; *curr_char != NULL; curr_char++) { if (*curr_char < 0x20) { switch(*curr_char) { case 1: @@ -1774,7 +1774,7 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in //gLastDrawStringX = ecx; //gLastDrawStringY = edx; - + // int eax, ebx, ecx, edx, esi, edi, ebp; rct_g1_element* g1_element; From 490fe70db85061b26da9d065416545903c1a5c05 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sat, 7 Jun 2014 21:34:24 +0100 Subject: [PATCH 96/99] Trying different zoom technique --- src/gfx.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 39688966ba..ed6fca1458 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -747,13 +747,15 @@ rct_g1_element gfx_sprite_zoom_image(rct_g1_element* source, int zoom_level){ * There is still a small bug with this code when it is in the choose park view. */ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_pointer, uint8* palette_pointer, rct_drawpixelinfo *dpi, int image_type, int source_y_start, int height, int source_x_start, int width){ - uint16 offset_to_first_line = ((uint16*)source_bits_pointer)[source_y_start]; + int zoom_level = dpi->zoom_level + 1; + + uint16 offset_to_first_line = ((uint16*)source_bits_pointer)[source_y_start*zoom_level]; //This will now point to the first line uint8* next_source_pointer = source_bits_pointer + offset_to_first_line; uint8* next_dest_pointer = dest_bits_pointer; //For every line in the image - for (; height; height--){ + for (; height; height-=zoom_level){ uint8 last_data_line = 0; //For every data section in the line @@ -773,7 +775,7 @@ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_point next_source_pointer = source_pointer + no_pixels; //Calculates the start point of the image - int x_start = gap_size - source_x_start; + int x_start = gap_size - source_x_start*zoom_level; if (x_start > 0){ //Since the start is positive @@ -786,7 +788,7 @@ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_point source_pointer -= x_start; //The no_pixels will be reduced in this operation no_pixels += x_start; - //If there are no pixels there is nothing to draw this line + //If there are no pixels there is nothing to draw this data section if (no_pixels <= 0) continue; //Reset the start position to zero as we have taken into account all moves x_start = 0; @@ -795,9 +797,9 @@ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_point int x_end = x_start + no_pixels; //If the end position is further out than the whole image //end position then we need to shorten the line again - if (x_end > width){ + if (x_end > width/zoom_level){ //Shorten the line - no_pixels -= x_end - width; + no_pixels -= x_end - width/zoom_level; //If there are no pixels there is nothing to draw. if (no_pixels <= 0) continue; } @@ -805,7 +807,7 @@ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_point //Finally after all those checks, copy the image onto the drawing surface //If the image type is not a basic one we require to mix the pixels if (image_type & IMAGE_TYPE_USE_PALETTE){//In the .exe these are all unraveled loops - for (; no_pixels > 0; --no_pixels, source_pointer++, dest_pointer++){ + for (; no_pixels > 0; no_pixels-=zoom_level, source_pointer+=zoom_level, dest_pointer++){ uint8 al = *source_pointer; uint8 ah = *dest_pointer; if (image_type & IMAGE_TYPE_MIX_BACKGROUND)//Mix with background and image Not Tested @@ -818,7 +820,7 @@ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_point else if (image_type & IMAGE_TYPE_MIX_BACKGROUND){//In the .exe these are all unraveled loops //Doesnt use source pointer ??? mix with background only? //Not Tested - for (; no_pixels > 0; --no_pixels, source_pointer++, dest_pointer++){ + for (; no_pixels > 0; no_pixels-=zoom_level, source_pointer+=zoom_level, dest_pointer++){ uint8 pixel = *dest_pointer; pixel = palette_pointer[pixel]; *dest_pointer = pixel; @@ -826,7 +828,9 @@ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_point } else { - memcpy(dest_pointer, source_pointer, no_pixels); + for (; no_pixels > 0; no_pixels -= zoom_level, source_pointer += zoom_level, dest_pointer++){ + *dest_pointer = *source_pointer; + } } } @@ -959,10 +963,12 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, int y, uint8* palette_pointer, uint8* unknown_pointer){ int image_element = 0x7FFFF&image_id; int image_type = (image_id & 0xE0000000) >> 28; - - rct_g1_element* g1_source = &((rct_g1_element*)RCT2_ADDRESS_G1_ELEMENTS)[image_element]; - rct_g1_element zoomed = gfx_sprite_zoom_image(g1_source, dpi->zoom_level); - if (zoomed.offset != NULL)g1_source = &zoomed; + dpi->zoom_level = 1; + //We add on one so that divides will create the correct number of pixels + int zoom_level = dpi->zoom_level + 1; + rct_g1_element* g1_source = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[image_element]); + //rct_g1_element zoomed = gfx_sprite_zoom_image(g1_source, dpi->zoom_level); + //if (zoomed.offset != NULL)g1_source = &zoomed; if (dpi->zoom_level >= 1){ //These have not been tested //something to do with zooming if (dpi->zoom_level == 1){ @@ -978,9 +984,9 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in } //This will be the height of the drawn image - int height = g1_source->height; + int height = g1_source->height / zoom_level; //This is the start y coordinate on the destination - int dest_start_y = y - dpi->y + g1_source->y_offset; + int dest_start_y = y - dpi->y + g1_source->y_offset / zoom_level; //This is the start y coordinate on the source int source_start_y = 0; @@ -994,7 +1000,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in return; } //The source image will start a further up the image - source_start_y -= dest_start_y; + source_start_y -= dest_start_y*zoom_level; //The destination start is now reset to 0 dest_start_y = 0; } @@ -1010,11 +1016,11 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in } //This will be the width of the drawn image - int width = g1_source->width; + int width = g1_source->width / zoom_level; //This is the source start x coordinate int source_start_x = 0; //This is the destination start x coordinate - int dest_start_x = x - dpi->x + g1_source->x_offset; + int dest_start_x = x - dpi->x + g1_source->x_offset / zoom_level; if (dest_start_x < 0){ //If the destination is negative reduce the width @@ -1025,7 +1031,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in return; } //The source start will also need to cut off the side - source_start_x -= dest_start_x; + source_start_x -= dest_start_x*zoom_level; //Reset the destination to 0 dest_start_x = 0; } @@ -1048,7 +1054,9 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in if (g1_source->flags & G1_FLAG_RLE_COMPRESSION){ //We have to use a different method to move the source pointer for //rle encoded sprites so that will be handled within this function + dpi->zoom_level = 1; gfx_rle_sprite_to_buffer(g1_source->offset, dest_pointer, palette_pointer, dpi, image_type, source_start_y, height, source_start_x, width); + dpi->zoom_level = 0; return; } @@ -1058,7 +1066,6 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in if (!(g1_source->flags & 0x02)){ gfx_bmp_sprite_to_buffer(palette_pointer, unknown_pointer, source_pointer, dest_pointer, g1_source, dpi, height, width, image_type); - if (zoomed.offset)free(zoomed.offset); return; } //0x67A60A Not tested From 940754af8124642c93a6a127828f9a33b36598e2 Mon Sep 17 00:00:00 2001 From: Duncan Date: Sun, 8 Jun 2014 22:00:23 +0100 Subject: [PATCH 97/99] trying to fix zooming problems. --- src/gfx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index ed6fca1458..b081a8e861 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -749,7 +749,7 @@ rct_g1_element gfx_sprite_zoom_image(rct_g1_element* source, int zoom_level){ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_pointer, uint8* palette_pointer, rct_drawpixelinfo *dpi, int image_type, int source_y_start, int height, int source_x_start, int width){ int zoom_level = dpi->zoom_level + 1; - uint16 offset_to_first_line = ((uint16*)source_bits_pointer)[source_y_start*zoom_level]; + uint16 offset_to_first_line = ((uint16*)source_bits_pointer)[source_y_start]; //This will now point to the first line uint8* next_source_pointer = source_bits_pointer + offset_to_first_line; uint8* next_dest_pointer = dest_bits_pointer; @@ -775,7 +775,7 @@ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_point next_source_pointer = source_pointer + no_pixels; //Calculates the start point of the image - int x_start = gap_size - source_x_start*zoom_level; + int x_start = gap_size / zoom_level - source_x_start*zoom_level; if (x_start > 0){ //Since the start is positive From 2b9d7af156add687ad2f697daa00f0b87ad36da0 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Mon, 9 Jun 2014 23:10:54 +0100 Subject: [PATCH 98/99] Messing with zooming code currently breaks. --- src/gfx.c | 177 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 92 insertions(+), 85 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index ed6fca1458..d6f89a2627 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -749,91 +749,97 @@ rct_g1_element gfx_sprite_zoom_image(rct_g1_element* source, int zoom_level){ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_pointer, uint8* palette_pointer, rct_drawpixelinfo *dpi, int image_type, int source_y_start, int height, int source_x_start, int width){ int zoom_level = dpi->zoom_level + 1; - uint16 offset_to_first_line = ((uint16*)source_bits_pointer)[source_y_start*zoom_level]; + uint16 offset_to_first_line = ((uint16*)source_bits_pointer)[source_y_start]; //This will now point to the first line uint8* next_source_pointer = source_bits_pointer + offset_to_first_line; uint8* next_dest_pointer = dest_bits_pointer; + uint8 zoom_skip = 0; //For every line in the image - for (; height; height-=zoom_level){ + for (; height; height--){ + do{ + uint8 last_data_line = 0; + //For every data section in the line + while (!last_data_line){ + uint8* source_pointer = next_source_pointer; + uint8* dest_pointer = next_dest_pointer; - uint8 last_data_line = 0; - //For every data section in the line - while (!last_data_line){ - uint8* source_pointer = next_source_pointer; - uint8* dest_pointer = next_dest_pointer; + int no_pixels = *source_pointer++; + //gap_size is the number of non drawn pixels you require to + //jump over on your destination + uint8 gap_size = *source_pointer++; + //The last bit in no_pixels tells you if you have reached the end of a line + last_data_line = no_pixels & 0x80; + //Clear the last data line bit so we have just the no_pixels + no_pixels &= 0x7f; + //Have our next source pointer point to the next data section + next_source_pointer = source_pointer + no_pixels; - int no_pixels = *source_pointer++; - //gap_size is the number of non drawn pixels you require to - //jump over on your destination - uint8 gap_size = *source_pointer++; - //The last bit in no_pixels tells you if you have reached the end of a line - last_data_line = no_pixels & 0x80; - //Clear the last data line bit so we have just the no_pixels - no_pixels &= 0x7f; - //Have our next source pointer point to the next data section - next_source_pointer = source_pointer + no_pixels; + if (last_data_line && zoom_skip){ + zoom_skip--; + continue; + } + if (last_data_line) zoom_skip = dpi->zoom_level; + //Calculates the start point of the image + int x_start = gap_size - source_x_start; - //Calculates the start point of the image - int x_start = gap_size - source_x_start*zoom_level; + if (x_start > 0){ + //Since the start is positive + //We need to move the drawing surface to the correct position + dest_pointer += x_start; + } + else{ + //If the start is negative we require to remove part of the image. + //This is done by moving the image pointer to the correct position. + source_pointer -= x_start; + //The no_pixels will be reduced in this operation + no_pixels += x_start; + //If there are no pixels there is nothing to draw this data section + if (no_pixels <= 0) continue; + //Reset the start position to zero as we have taken into account all moves + x_start = 0; + } - if (x_start > 0){ - //Since the start is positive - //We need to move the drawing surface to the correct position - dest_pointer += x_start; - } - else{ - //If the start is negative we require to remove part of the image. - //This is done by moving the image pointer to the correct position. - source_pointer -= x_start; - //The no_pixels will be reduced in this operation - no_pixels += x_start; - //If there are no pixels there is nothing to draw this data section - if (no_pixels <= 0) continue; - //Reset the start position to zero as we have taken into account all moves - x_start = 0; - } + int x_end = x_start + no_pixels; + //If the end position is further out than the whole image + //end position then we need to shorten the line again + if (x_end > width){ + //Shorten the line + no_pixels -= x_end - width; + //If there are no pixels there is nothing to draw. + if (no_pixels <= 0) continue; + } - int x_end = x_start + no_pixels; - //If the end position is further out than the whole image - //end position then we need to shorten the line again - if (x_end > width/zoom_level){ - //Shorten the line - no_pixels -= x_end - width/zoom_level; - //If there are no pixels there is nothing to draw. - if (no_pixels <= 0) continue; - } - - //Finally after all those checks, copy the image onto the drawing surface - //If the image type is not a basic one we require to mix the pixels - if (image_type & IMAGE_TYPE_USE_PALETTE){//In the .exe these are all unraveled loops - for (; no_pixels > 0; no_pixels-=zoom_level, source_pointer+=zoom_level, dest_pointer++){ - uint8 al = *source_pointer; - uint8 ah = *dest_pointer; - if (image_type & IMAGE_TYPE_MIX_BACKGROUND)//Mix with background and image Not Tested - al = palette_pointer[(al | ((int)ah) << 8) - 0x100]; - else //Adjust colours? - al = palette_pointer[al]; - *dest_pointer = al; + //Finally after all those checks, copy the image onto the drawing surface + //If the image type is not a basic one we require to mix the pixels + if (image_type & IMAGE_TYPE_USE_PALETTE){//In the .exe these are all unraveled loops + for (; no_pixels > 0; no_pixels--, source_pointer++, dest_pointer++){ + uint8 al = *source_pointer; + uint8 ah = *dest_pointer; + if (image_type & IMAGE_TYPE_MIX_BACKGROUND)//Mix with background and image Not Tested + al = palette_pointer[(al | ((int)ah) << 8) - 0x100]; + else //Adjust colours? + al = palette_pointer[al]; + *dest_pointer = al; + } + } + else if (image_type & IMAGE_TYPE_MIX_BACKGROUND){//In the .exe these are all unraveled loops + //Doesnt use source pointer ??? mix with background only? + //Not Tested + for (; no_pixels > 0; no_pixels--, source_pointer++, dest_pointer++){ + uint8 pixel = *dest_pointer; + pixel = palette_pointer[pixel]; + *dest_pointer = pixel; + } + } + else + { + for (; no_pixels > 0; no_pixels--, source_pointer++, dest_pointer++){ + *dest_pointer = *source_pointer; + } } } - else if (image_type & IMAGE_TYPE_MIX_BACKGROUND){//In the .exe these are all unraveled loops - //Doesnt use source pointer ??? mix with background only? - //Not Tested - for (; no_pixels > 0; no_pixels-=zoom_level, source_pointer+=zoom_level, dest_pointer++){ - uint8 pixel = *dest_pointer; - pixel = palette_pointer[pixel]; - *dest_pointer = pixel; - } - } - else - { - for (; no_pixels > 0; no_pixels -= zoom_level, source_pointer += zoom_level, dest_pointer++){ - *dest_pointer = *source_pointer; - } - } - - } + } while (zoom_skip); //Add a line to the drawing surface pointer next_dest_pointer += (int)dpi->width + (int)dpi->pitch; } @@ -955,6 +961,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } gfx_draw_sprite_palette_set(dpi, image_id, x, y, palette_pointer, unknown_pointer); + dpi->zoom_level = 0; } /* @@ -963,9 +970,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, int y, uint8* palette_pointer, uint8* unknown_pointer){ int image_element = 0x7FFFF&image_id; int image_type = (image_id & 0xE0000000) >> 28; - dpi->zoom_level = 1; - //We add on one so that divides will create the correct number of pixels - int zoom_level = dpi->zoom_level + 1; + rct_g1_element* g1_source = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[image_element]); //rct_g1_element zoomed = gfx_sprite_zoom_image(g1_source, dpi->zoom_level); //if (zoomed.offset != NULL)g1_source = &zoomed; @@ -982,11 +987,14 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in RCT2_CALLPROC_X(0x0067FAAE, 0, (int)g1_source, x, y, 0, (int)dpi, 0); return; } - + //Zoom level testing code. + dpi->zoom_level = 1; + //We add on one so that divides will create the correct number of pixels + int zoom_level = dpi->zoom_level + 1; //This will be the height of the drawn image int height = g1_source->height / zoom_level; //This is the start y coordinate on the destination - int dest_start_y = y - dpi->y + g1_source->y_offset / zoom_level; + int dest_start_y = y - dpi->y + g1_source->y_offset; //This is the start y coordinate on the source int source_start_y = 0; @@ -1000,7 +1008,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in return; } //The source image will start a further up the image - source_start_y -= dest_start_y*zoom_level; + source_start_y -= dest_start_y; //The destination start is now reset to 0 dest_start_y = 0; } @@ -1020,7 +1028,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in //This is the source start x coordinate int source_start_x = 0; //This is the destination start x coordinate - int dest_start_x = x - dpi->x + g1_source->x_offset / zoom_level; + int dest_start_x = x - dpi->x + g1_source->x_offset; if (dest_start_x < 0){ //If the destination is negative reduce the width @@ -1031,7 +1039,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in return; } //The source start will also need to cut off the side - source_start_x -= dest_start_x*zoom_level; + source_start_x -= dest_start_x; //Reset the destination to 0 dest_start_x = 0; } @@ -1054,18 +1062,15 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in if (g1_source->flags & G1_FLAG_RLE_COMPRESSION){ //We have to use a different method to move the source pointer for //rle encoded sprites so that will be handled within this function - dpi->zoom_level = 1; gfx_rle_sprite_to_buffer(g1_source->offset, dest_pointer, palette_pointer, dpi, image_type, source_start_y, height, source_start_x, width); - dpi->zoom_level = 0; return; } - uint8* source_pointer = g1_source->offset; //Move the pointer to the start point of the source source_pointer += g1_source->width*source_start_y + source_start_x; if (!(g1_source->flags & 0x02)){ - gfx_bmp_sprite_to_buffer(palette_pointer, unknown_pointer, source_pointer, dest_pointer, g1_source, dpi, height, width, image_type); + //gfx_bmp_sprite_to_buffer(palette_pointer, unknown_pointer, source_pointer, dest_pointer, g1_source, dpi, height, width, image_type); return; } //0x67A60A Not tested @@ -2083,6 +2088,8 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in RCT2_GLOBAL(0x00EDF81C, uint32) = 0x20000000; gfx_draw_sprite_palette_set(dpi, 0x20000000 | ebx, ecx, edx, RCT2_GLOBAL(0x9ABDA4, uint8*), NULL); + //Part of zoom testing code remove when done. + dpi->zoom_level = 0; //RCT2_CALLPROC_X(0x067A46E, eax, ebx, ecx, edx, esi, edi, ebp); continue; From b073c8eaef45aff97d8b12e942494075d2ade666 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 10 Jun 2014 22:20:44 +0100 Subject: [PATCH 99/99] Finished last part of zooming code. Appears to work good. --- src/gfx.c | 321 ++++++++++++++++++++++++------------------------------ 1 file changed, 143 insertions(+), 178 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index d6f89a2627..78ddbfb8a0 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -585,6 +585,7 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri * image. */ void gfx_bmp_sprite_to_buffer(uint8* palette_pointer, uint8* unknown_pointer, uint8* source_pointer, uint8* dest_pointer, rct_g1_element* source_image, rct_drawpixelinfo *dest_dpi, int height, int width, int image_type){ + uint8 zoom_level = dest_dpi->zoom_level + 1; //Requires use of palette? if (image_type & IMAGE_TYPE_USE_PALETTE){ @@ -592,55 +593,40 @@ void gfx_bmp_sprite_to_buffer(uint8* palette_pointer, uint8* unknown_pointer, ui if (unknown_pointer!= NULL){ //Not tested. I can't actually work out when this code runs. unknown_pointer += source_pointer - source_image->offset;// RCT2_GLOBAL(0x9E3CE0, uint32); - for (; height > 0; --height){ - for (int no_pixels = width; no_pixels > 0; --no_pixels){ + for (; height > 0; height -= zoom_level){ + uint8* next_source_pointer = source_pointer + source_image->width*zoom_level; + uint8* next_unknown_pointer = unknown_pointer + source_image->width*zoom_level; + uint8* next_dest_pointer = dest_pointer + dest_dpi->width + dest_dpi->pitch; + + for (int no_pixels = width; no_pixels > 0; no_pixels -= zoom_level, source_pointer+=zoom_level, unknown_pointer+=zoom_level, dest_pointer++){ uint8 pixel = *source_pointer; - source_pointer++; pixel = palette_pointer[pixel]; pixel &= *unknown_pointer; if (pixel){ *dest_pointer = pixel; } - dest_pointer++; - unknown_pointer++; } - source_pointer += source_image->width - width; - dest_pointer += dest_dpi->width + dest_dpi->pitch - width; - unknown_pointer += source_image->width - width; - } - return; - } - - //Quicker? - if (width == 4){ - - for (; height > 0; --height){ - for (int no_pixels = 0; no_pixels < 4; ++no_pixels){ - uint8 pixel = source_pointer[no_pixels]; - pixel = palette_pointer[pixel]; - if (pixel){ - dest_pointer[no_pixels] = pixel; - } - } - dest_pointer += dest_dpi->width + dest_dpi->pitch - width + 4; - source_pointer += source_image->width - width + 4; + source_pointer = next_source_pointer; + dest_pointer = next_dest_pointer; + unknown_pointer = next_unknown_pointer; } return; } //image colour adjusted? - for (; height > 0; --height){ - for (int no_pixels = width; no_pixels > 0; --no_pixels){ + for (; height > 0; height -= zoom_level){ + uint8* next_source_pointer = source_pointer + source_image->width*zoom_level; + uint8* next_dest_pointer = dest_pointer + dest_dpi->width + dest_dpi->pitch; + for (int no_pixels = width; no_pixels > 0; no_pixels -= zoom_level, source_pointer+= zoom_level, dest_pointer++){ uint8 pixel = *source_pointer; - source_pointer++; pixel = palette_pointer[pixel]; if (pixel){ *dest_pointer = pixel; } - dest_pointer++; } - source_pointer += source_image->width - width; - dest_pointer += dest_dpi->width + dest_dpi->pitch - width; + + source_pointer = next_source_pointer; + dest_pointer = next_dest_pointer; } return; } @@ -648,29 +634,37 @@ void gfx_bmp_sprite_to_buffer(uint8* palette_pointer, uint8* unknown_pointer, ui //Mix with background. It only uses source pointer for //telling if it needs to be drawn not for colour. if (image_type & IMAGE_TYPE_MIX_BACKGROUND){//Not tested - for (; height > 0; --height){ - for (int no_pixels = width; no_pixels > 0; --no_pixels){ + for (; height > 0; height -= zoom_level){ + uint8* next_source_pointer = source_pointer + source_image->width*zoom_level; + uint8* next_dest_pointer = dest_pointer + dest_dpi->width + dest_dpi->pitch; + + for (int no_pixels = width; no_pixels > 0; no_pixels -= zoom_level, source_pointer += zoom_level, dest_pointer++){ uint8 pixel = *source_pointer; - source_pointer++; if (pixel){ pixel = *dest_pointer; pixel = palette_pointer[pixel]; *dest_pointer = pixel; } - dest_pointer++; } - source_pointer += source_image->width - width; - dest_pointer += dest_dpi->width + dest_dpi->pitch - width; + + source_pointer = next_source_pointer; + dest_pointer = next_dest_pointer; } return; } //Basic bitmap no fancy stuff if (!(source_image->flags & G1_FLAG_BMP)){//Not tested - for (; height > 0; --height){ - memcpy(dest_pointer, source_pointer, width); - dest_pointer += dest_dpi->width + dest_dpi->pitch; - source_pointer += source_image->width; + for (; height > 0; height-=zoom_level){ + uint8* next_source_pointer = source_pointer + source_image->width*zoom_level; + uint8* next_dest_pointer = dest_pointer + dest_dpi->width + dest_dpi->pitch; + + for (int no_pixels = width; no_pixels > 0; no_pixels -= zoom_level, dest_pointer++, source_pointer += zoom_level){ + *dest_pointer = *source_pointer; + } + + dest_pointer = next_dest_pointer; + source_pointer = next_source_pointer; } return; } @@ -678,68 +672,42 @@ void gfx_bmp_sprite_to_buffer(uint8* palette_pointer, uint8* unknown_pointer, ui if (RCT2_GLOBAL(0x9E3CDC, uint32) != 0){//Not tested. I can't actually work out when this code runs. unknown_pointer += source_pointer - source_image->offset; - for (; height > 0; --height){ - for (int no_pixels = width; no_pixels > 0; --no_pixels){ + for (; height > 0; height -= zoom_level){ + uint8* next_source_pointer = source_pointer + source_image->width*zoom_level; + uint8* next_unknown_pointer = unknown_pointer + source_image->width*zoom_level; + uint8* next_dest_pointer = dest_pointer + dest_dpi->width + dest_dpi->pitch; + + for (int no_pixels = width; no_pixels > 0; no_pixels -= zoom_level, dest_pointer++, source_pointer += zoom_level, unknown_pointer += zoom_level){ uint8 pixel = *source_pointer; - source_pointer++; pixel &= *unknown_pointer; if (pixel){ *dest_pointer = pixel; } - dest_pointer++; - unknown_pointer++; } - source_pointer += source_image->width - width; - dest_pointer += dest_dpi->width + dest_dpi->pitch - width; - unknown_pointer += source_image->width - width; + dest_pointer = next_dest_pointer; + source_pointer = next_source_pointer; + unknown_pointer = next_unknown_pointer; } } //Basic bitmap with no draw pixels - for (int no_lines = height; no_lines > 0; --no_lines){ - for (int no_pixels = width; no_pixels > 0; --no_pixels){ + for (; height > 0; height -= zoom_level){ + uint8* next_source_pointer = source_pointer + source_image->width*zoom_level; + uint8* next_dest_pointer = dest_pointer + dest_dpi->width + dest_dpi->pitch; + + for (int no_pixels = width; no_pixels > 0; no_pixels -= zoom_level, dest_pointer++, source_pointer += zoom_level){ uint8 pixel = *source_pointer; - source_pointer++; if (pixel){ *dest_pointer = pixel; } - dest_pointer++; } - source_pointer += source_image->width - width; - dest_pointer += dest_dpi->width + dest_dpi->pitch - width; + dest_pointer = next_dest_pointer; + source_pointer = next_source_pointer; } return; } -rct_g1_element gfx_sprite_zoom_image(rct_g1_element* source, int zoom_level){ - rct_g1_element dest; - uint8* smaller_image; - dest.offset = NULL; - if (zoom_level == 0)return dest; - if (source->flags&G1_FLAG_RLE_COMPRESSION) return dest; - smaller_image = malloc(source->width*source->height); - dest.offset = smaller_image; - uint8* source_pointer = source->offset; - source_pointer += source->y_offset*source->width + source->x_offset; - for (int y = 0; y < source->height; y += zoom_level){ - uint8* next_line = source_pointer + source->width*zoom_level; - for (int x = 0; x < source->width; x += zoom_level){ - *smaller_image = *source_pointer; - source_pointer += zoom_level; - smaller_image++; - } - source_pointer = next_line;//source->width*zoom_level; - } - - dest.x_offset = 0; - dest.y_offset = 0; - dest.width = source->width / zoom_level; - dest.height= source->height/ zoom_level; - dest.flags = source->flags; - return dest; - //remember to free the pointer -} /* * rct2: 0x67AA18 transfers readied images onto buffers * This function copies the sprite data onto the screen @@ -749,102 +717,100 @@ rct_g1_element gfx_sprite_zoom_image(rct_g1_element* source, int zoom_level){ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_pointer, uint8* palette_pointer, rct_drawpixelinfo *dpi, int image_type, int source_y_start, int height, int source_x_start, int width){ int zoom_level = dpi->zoom_level + 1; - uint16 offset_to_first_line = ((uint16*)source_bits_pointer)[source_y_start]; - //This will now point to the first line - uint8* next_source_pointer = source_bits_pointer + offset_to_first_line; + uint8* next_source_pointer; uint8* next_dest_pointer = dest_bits_pointer; - - uint8 zoom_skip = 0; + //For every line in the image - for (; height; height--){ - do{ - uint8 last_data_line = 0; - //For every data section in the line - while (!last_data_line){ - uint8* source_pointer = next_source_pointer; - uint8* dest_pointer = next_dest_pointer; + for (int y = source_y_start; y < (height + source_y_start); y += zoom_level){ - int no_pixels = *source_pointer++; - //gap_size is the number of non drawn pixels you require to - //jump over on your destination - uint8 gap_size = *source_pointer++; - //The last bit in no_pixels tells you if you have reached the end of a line - last_data_line = no_pixels & 0x80; - //Clear the last data line bit so we have just the no_pixels - no_pixels &= 0x7f; - //Have our next source pointer point to the next data section - next_source_pointer = source_pointer + no_pixels; + //The first part of the source pointer is a list of offsets to different lines + //This will move the pointer to the correct source line. + next_source_pointer = source_bits_pointer + ((uint16*)source_bits_pointer)[y]; - if (last_data_line && zoom_skip){ - zoom_skip--; - continue; - } - if (last_data_line) zoom_skip = dpi->zoom_level; - //Calculates the start point of the image - int x_start = gap_size - source_x_start; + uint8 last_data_line = 0; - if (x_start > 0){ - //Since the start is positive - //We need to move the drawing surface to the correct position - dest_pointer += x_start; - } - else{ - //If the start is negative we require to remove part of the image. - //This is done by moving the image pointer to the correct position. - source_pointer -= x_start; - //The no_pixels will be reduced in this operation - no_pixels += x_start; - //If there are no pixels there is nothing to draw this data section - if (no_pixels <= 0) continue; - //Reset the start position to zero as we have taken into account all moves - x_start = 0; - } + //For every data section in the line + while (!last_data_line){ + uint8* source_pointer = next_source_pointer; + uint8* dest_pointer = next_dest_pointer; - int x_end = x_start + no_pixels; - //If the end position is further out than the whole image - //end position then we need to shorten the line again - if (x_end > width){ - //Shorten the line - no_pixels -= x_end - width; - //If there are no pixels there is nothing to draw. - if (no_pixels <= 0) continue; - } + int no_pixels = *source_pointer++; + //gap_size is the number of non drawn pixels you require to + //jump over on your destination + uint8 gap_size = *source_pointer++; + //The last bit in no_pixels tells you if you have reached the end of a line + last_data_line = no_pixels & 0x80; + //Clear the last data line bit so we have just the no_pixels + no_pixels &= 0x7f; + //Have our next source pointer point to the next data section + next_source_pointer = source_pointer + no_pixels; - //Finally after all those checks, copy the image onto the drawing surface - //If the image type is not a basic one we require to mix the pixels - if (image_type & IMAGE_TYPE_USE_PALETTE){//In the .exe these are all unraveled loops - for (; no_pixels > 0; no_pixels--, source_pointer++, dest_pointer++){ - uint8 al = *source_pointer; - uint8 ah = *dest_pointer; - if (image_type & IMAGE_TYPE_MIX_BACKGROUND)//Mix with background and image Not Tested - al = palette_pointer[(al | ((int)ah) << 8) - 0x100]; - else //Adjust colours? - al = palette_pointer[al]; - *dest_pointer = al; - } - } - else if (image_type & IMAGE_TYPE_MIX_BACKGROUND){//In the .exe these are all unraveled loops - //Doesnt use source pointer ??? mix with background only? - //Not Tested - for (; no_pixels > 0; no_pixels--, source_pointer++, dest_pointer++){ - uint8 pixel = *dest_pointer; - pixel = palette_pointer[pixel]; - *dest_pointer = pixel; - } - } - else - { - for (; no_pixels > 0; no_pixels--, source_pointer++, dest_pointer++){ - *dest_pointer = *source_pointer; - } + //Calculates the start point of the image + int x_start = gap_size - source_x_start; + + if (x_start > 0){ + //Since the start is positive + //We need to move the drawing surface to the correct position + dest_pointer += x_start / zoom_level; + } + else{ + //If the start is negative we require to remove part of the image. + //This is done by moving the image pointer to the correct position. + source_pointer -= x_start; + //The no_pixels will be reduced in this operation + no_pixels += x_start; + //If there are no pixels there is nothing to draw this data section + if (no_pixels <= 0) continue; + //Reset the start position to zero as we have taken into account all moves + x_start = 0; + } + + int x_end = x_start + no_pixels; + //If the end position is further out than the whole image + //end position then we need to shorten the line again + if (x_end > width){ + //Shorten the line + no_pixels -= x_end - width; + //If there are no pixels there is nothing to draw. + if (no_pixels <= 0) continue; + } + + //Finally after all those checks, copy the image onto the drawing surface + //If the image type is not a basic one we require to mix the pixels + if (image_type & IMAGE_TYPE_USE_PALETTE){//In the .exe these are all unraveled loops + for (; no_pixels > 0; no_pixels -= zoom_level, source_pointer += zoom_level, dest_pointer++){ + uint8 al = *source_pointer; + uint8 ah = *dest_pointer; + if (image_type & IMAGE_TYPE_MIX_BACKGROUND)//Mix with background and image Not Tested + al = palette_pointer[(al | ((int)ah) << 8) - 0x100]; + else //Adjust colours? + al = palette_pointer[al]; + *dest_pointer = al; } } - } while (zoom_skip); + else if (image_type & IMAGE_TYPE_MIX_BACKGROUND){//In the .exe these are all unraveled loops + //Doesnt use source pointer ??? mix with background only? + //Not Tested + for (; no_pixels > 0; no_pixels -= zoom_level, dest_pointer++){ + uint8 pixel = *dest_pointer; + pixel = palette_pointer[pixel]; + *dest_pointer = pixel; + } + } + else + { + for (; no_pixels > 0; no_pixels -= zoom_level, source_pointer += zoom_level, dest_pointer++){ + *dest_pointer = *source_pointer; + } + } + } + //Add a line to the drawing surface pointer next_dest_pointer += (int)dpi->width + (int)dpi->pitch; } } + void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, int y, uint8* palette_pointer, uint8* unknown_pointer); /** * @@ -961,7 +927,6 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) } gfx_draw_sprite_palette_set(dpi, image_id, x, y, palette_pointer, unknown_pointer); - dpi->zoom_level = 0; } /* @@ -972,9 +937,9 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in int image_type = (image_id & 0xE0000000) >> 28; rct_g1_element* g1_source = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[image_element]); - //rct_g1_element zoomed = gfx_sprite_zoom_image(g1_source, dpi->zoom_level); - //if (zoomed.offset != NULL)g1_source = &zoomed; - if (dpi->zoom_level >= 1){ //These have not been tested + + //Zooming code has been integrated into main code. + /*if (dpi->zoom_level >= 1){ //These have not been tested //something to do with zooming if (dpi->zoom_level == 1){ RCT2_CALLPROC_X(0x0067BD81, 0, (int)g1_source, x, y, 0,(int) dpi, 0); @@ -986,9 +951,8 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in } RCT2_CALLPROC_X(0x0067FAAE, 0, (int)g1_source, x, y, 0, (int)dpi, 0); return; - } - //Zoom level testing code. - dpi->zoom_level = 1; + }*/ + //We add on one so that divides will create the correct number of pixels int zoom_level = dpi->zoom_level + 1; //This will be the height of the drawn image @@ -1008,10 +972,11 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in return; } //The source image will start a further up the image - source_start_y -= dest_start_y; + source_start_y -= dest_start_y*zoom_level; //The destination start is now reset to 0 dest_start_y = 0; } + int dest_end_y = dest_start_y + height; @@ -1039,7 +1004,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in return; } //The source start will also need to cut off the side - source_start_x -= dest_start_x; + source_start_x -= dest_start_x*zoom_level; //Reset the destination to 0 dest_start_x = 0; } @@ -1059,6 +1024,9 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in //Move the pointer to the start point of the destination dest_pointer += (dpi->width + dpi->pitch)*dest_start_y + dest_start_x; + height *= zoom_level; + width *= zoom_level; + if (g1_source->flags & G1_FLAG_RLE_COMPRESSION){ //We have to use a different method to move the source pointer for //rle encoded sprites so that will be handled within this function @@ -1070,7 +1038,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in source_pointer += g1_source->width*source_start_y + source_start_x; if (!(g1_source->flags & 0x02)){ - //gfx_bmp_sprite_to_buffer(palette_pointer, unknown_pointer, source_pointer, dest_pointer, g1_source, dpi, height, width, image_type); + gfx_bmp_sprite_to_buffer(palette_pointer, unknown_pointer, source_pointer, dest_pointer, g1_source, dpi, height, width, image_type); return; } //0x67A60A Not tested @@ -2088,9 +2056,6 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in RCT2_GLOBAL(0x00EDF81C, uint32) = 0x20000000; gfx_draw_sprite_palette_set(dpi, 0x20000000 | ebx, ecx, edx, RCT2_GLOBAL(0x9ABDA4, uint8*), NULL); - //Part of zoom testing code remove when done. - dpi->zoom_level = 0; - //RCT2_CALLPROC_X(0x067A46E, eax, ebx, ecx, edx, esi, edi, ebp); continue; }