From 66d185712e3eade21b3f97811253c6bffca1c884 Mon Sep 17 00:00:00 2001 From: Duncan Date: Mon, 16 Jun 2014 09:25:42 +0100 Subject: [PATCH 01/17] Fix gfx_clear bug not using zoom level There is a strong possibility that i have implemented all zooming code incorrectly. This will require looking at. --- src/gfx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 74a38d433d..fe142edefc 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -216,8 +216,8 @@ void gfx_clear(rct_drawpixelinfo *dpi, int colour) int y, w, h; char* ptr; - w = dpi->width >> dpi->var_0F; - h = dpi->height >> dpi->var_0F; + w = dpi->width >> dpi->zoom_level; + h = dpi->height >> dpi->zoom_level; ptr = dpi->bits; for (y = 0; y < h; y++) { From f45ec1976ae0945771bc981e5d93e59043621e01 Mon Sep 17 00:00:00 2001 From: Duncan Date: Mon, 16 Jun 2014 12:44:23 +0100 Subject: [PATCH 02/17] Corrected mistake with zoom_level Has not been tested. Still requires looking at x, y initial values i think they might be >> as well. --- src/gfx.c | 70 +++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 7f35f83f55..3c568c6f6b 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -647,7 +647,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; + uint8 zoom_level = dest_dpi->zoom_level; //Requires use of palette? if (image_type & IMAGE_TYPE_USE_PALETTE){ @@ -655,12 +655,12 @@ 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 -= zoom_level){ - uint8* next_source_pointer = source_pointer + source_image->width*zoom_level; - uint8* next_unknown_pointer = unknown_pointer + source_image->width*zoom_level; + for (; height > 0; height -= (1<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++){ + for (int no_pixels = width; no_pixels > 0; no_pixels -= (1< 0; height -= zoom_level){ - uint8* next_source_pointer = source_pointer + source_image->width*zoom_level; + for (; height > 0; height -= (1<width<width + dest_dpi->pitch; - for (int no_pixels = width; no_pixels > 0; no_pixels -= zoom_level, source_pointer+= zoom_level, dest_pointer++){ + for (int no_pixels = width; no_pixels > 0; no_pixels -= (1< 0; height -= zoom_level){ - uint8* next_source_pointer = source_pointer + source_image->width*zoom_level; + for (; height > 0; height -= (1<width<width + dest_dpi->pitch; - for (int no_pixels = width; no_pixels > 0; no_pixels -= zoom_level, source_pointer += zoom_level, dest_pointer++){ + for (int no_pixels = width; no_pixels > 0; no_pixels -= (1<flags & G1_FLAG_BMP)){//Not tested - for (; height > 0; height-=zoom_level){ - uint8* next_source_pointer = source_pointer + source_image->width*zoom_level; + for (; height > 0; height-=(1<width<width + dest_dpi->pitch; - for (int no_pixels = width; no_pixels > 0; no_pixels -= zoom_level, dest_pointer++, source_pointer += zoom_level){ + for (int no_pixels = width; no_pixels > 0; no_pixels -= (1<offset; - 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; + for (; height > 0; height -= (1<width<width<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){ + for (int no_pixels = width; no_pixels > 0; no_pixels -= (1< 0; height -= zoom_level){ - uint8* next_source_pointer = source_pointer + source_image->width*zoom_level; + for (; height > 0; height -= (1<width<width + dest_dpi->pitch; - for (int no_pixels = width; no_pixels > 0; no_pixels -= zoom_level, dest_pointer++, source_pointer += zoom_level){ + for (int no_pixels = width; no_pixels > 0; no_pixels -= (1<zoom_level + 1; + int zoom_level = dpi->zoom_level; uint8* next_source_pointer; uint8* next_dest_pointer = dest_bits_pointer; //For every line in the image - for (int y = source_y_start; y < (height + source_y_start); y += zoom_level){ + for (int y = source_y_start; y < (height + source_y_start); y += (1< 0){ //Since the start is positive //We need to move the drawing surface to the correct position - dest_pointer += x_start / zoom_level; + dest_pointer += x_start >> zoom_level; } else{ //If the start is negative we require to remove part of the image. @@ -838,7 +838,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 -= zoom_level, source_pointer += zoom_level, dest_pointer++){ + for (; no_pixels > 0; no_pixels -= (1< 0; no_pixels -= zoom_level, dest_pointer++){ + for (; no_pixels > 0; no_pixels -= (1< 0; no_pixels -= zoom_level, source_pointer += zoom_level, dest_pointer++){ + for (; no_pixels > 0; no_pixels -= (1<zoom_level + 1; + //Its used super often so we will define it to a seperate variable. + int zoom_level = dpi->zoom_level; //This will be the height of the drawn image - int height = g1_source->height / zoom_level; + 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; //This is the start y coordinate on the source @@ -1038,7 +1038,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<width / zoom_level; + 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 @@ -1070,7 +1070,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<width + dpi->pitch)*dest_start_y + dest_start_x; - height *= zoom_level; - width *= zoom_level; + 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 From 4f77ba0698f44af3e7c47181b070f5ecd16c8af0 Mon Sep 17 00:00:00 2001 From: Duncan Date: Mon, 16 Jun 2014 16:09:29 +0100 Subject: [PATCH 03/17] Added extra zoom code This is some sort of short cut code. I think some of the more common sprites are precomputed for zoomed images. --- src/gfx.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/gfx.c b/src/gfx.c index 3c568c6f6b..72a1a0e6b4 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1003,7 +1003,24 @@ 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]); + + if ( dpi->zoom_level && !(g1_source->flags & (1<<4)) ){ + rct_drawpixelinfo zoomed_dpi = { + .bits = dpi->bits, + .x = dpi->x >> 1, + .y = dpi->y >> 1, + .height = dpi->height>>1, + .width = dpi->width>>1, + .pitch = dpi->pitch, + .zoom_level = dpi->zoomlevel - 1 + }; + gfx_draw_sprite_palette_set(&zoomed_dpi,(image_type << 28) | (image_element - dpi->zoom_level), x >> 1, y >> 1, palette_pointer, unknown_pointer); + return; + } + if ( dpi->zoom_level && !(g1_source->flags & (1<<5)) ){ + return; + } //Zooming code has been integrated into main code. /*if (dpi->zoom_level >= 1){ //These have not been tested //something to do with zooming From f0fb16d1b24e8baf86b8339e7579b2ea91074db7 Mon Sep 17 00:00:00 2001 From: Duncan Date: Tue, 17 Jun 2014 12:15:58 +0100 Subject: [PATCH 04/17] Re-factored part of gfx_fill_rect Removed references to global vars that are not required. Possible bug in line 416 will require looking at. --- src/gfx.c | 54 ++++++++++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 72a1a0e6b4..b77beccde5 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -393,47 +393,33 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot } } else { // 00678B8A 00678E38 - char* esi; - esi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits;; + char* dest_pointer; + dest_pointer = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits;; - int eax, ebp; - eax = colour; - ebp = dpi->width + dpi->pitch - right_; + //The pattern loops every 15 lines this is which + //part the pattern is on. + int pattern_y = (top + dpi->y) % 15; - RCT2_GLOBAL(0x00EDF810, uint32) = ebp; - RCT2_GLOBAL(0x009ABDB2, uint16) = bottom_; - RCT2_GLOBAL(0x00EDF814, uint32) = right_; + //The pattern loops every 15 pixels this is which + //part the pattern is on. + int pattern_x = (right + dpi_->x) % 15; - top_ = (top + dpi->y) & 0xf; - right_ = (right + dpi_->x) &0xf; + uint16* pattern_pointer; + pattern_pointer = (uint16*)RCT2_GLOBAL(0x0097FEFC,uint32)[colour >> 28]; // or possibly uint8)[esi*4] ? - dpi_ = (rct_drawpixelinfo*)esi; + for (int no_lines = bottom_; no_lines > 0; no_lines--) { + char* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch; + uint16 pattern = pattern_pointer[pattern_y]; - 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); + for (int no_pixels = right_; no_pixels >=0; --no_pixels) { + if (!(pattern & (1 << pattern_x))) + *dest_pointer = (char*)(left_ & 0xFF); //left seems odd here - right_++; - right_ = right_ & 0xF; - dpi_++; + pattern_x = (pattern_x + 1) % 15; + dest_pointer++; } - // pop ecx - // pop ebx - top_++; - top_ = top_ &0xf; - dpi_ += RCT2_GLOBAL(0x00EDF810, uint32); + pattern_y = (pattern_y + 1) % 15; + dest_pointer = next_dest_pointer; } return; } From aaaf06e94d117e26aaeddcdb98e51f77a3b4f32c Mon Sep 17 00:00:00 2001 From: Duncan Date: Tue, 17 Jun 2014 12:20:34 +0100 Subject: [PATCH 05/17] Fixed bug in gfx_fill_rect As expected _left was incorrect. --- src/gfx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gfx.c b/src/gfx.c index b77beccde5..71bba51ea9 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -413,7 +413,7 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot for (int no_pixels = right_; no_pixels >=0; --no_pixels) { if (!(pattern & (1 << pattern_x))) - *dest_pointer = (char*)(left_ & 0xFF); //left seems odd here + *dest_pointer = colour & 0xFF; pattern_x = (pattern_x + 1) % 15; dest_pointer++; From 28c2d6430d9996ea4bf294e46c1aa0cf5712845c Mon Sep 17 00:00:00 2001 From: Duncan Date: Tue, 17 Jun 2014 12:39:56 +0100 Subject: [PATCH 06/17] Re-factored part of gfx_fill_rect added zooming Added notes for future work as well. --- src/gfx.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 71bba51ea9..8d7469d9f2 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -426,36 +426,28 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot } else { // 00678B7E 00678C83 - if (dpi->zoom_level < 1) { - // Location in screen buffer? - uint8* pixel = top_ * (dpi->width + dpi->pitch) + left_ + dpi->bits; + // Location in screen buffer? + uint8* dest_pointer = (top_>>dpi->zoom_level) * ((dpi->width>>dpi->zoom_level) + dpi->pitch) + left_>>dpi->zoom_level + 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_; - - // 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; + // Fill the rectangle with the colours from the colour table + for (int i = 0; i < bottom_>>dpi->zoom_level; ++i) { + uint8* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch; + for (int j = 0; j < right_; ++j) { + *dest_pointer = g1_element->offset[*dest_pointer]; + dest_pointer++; } - } else if (dpi->zoom_level > 1) { - // 00678C8A 00678D57 - right_ = right; - } else if (dpi->zoom_level == 1) { - // 00678C88 00678CEE - right = right; + dest_pointer = next_dest_pointer; } - + return; } } else { - // 00678B3A 00678EC9 + // 00678B3A 00678EC9 still to be implemented right_ = right; + return; } } else { // 00678B2E 00678BE5 From 3e6ee0d3b1813abc5a0eb14c9e5f088f96fdfedc Mon Sep 17 00:00:00 2001 From: Duncan Date: Tue, 17 Jun 2014 16:29:07 +0100 Subject: [PATCH 07/17] Re-factor of gfx_fill_rect. Moved cross_hatching code. Renamed some of the variables to make it easier to follow. Possible future change into big switch statement. --- src/gfx.c | 220 +++++++++++++++++++++++------------------------------- 1 file changed, 95 insertions(+), 125 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 8d7469d9f2..1a586ceb4a 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -356,156 +356,126 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot colour |= RCT2_GLOBAL(0x009ABD9C, uint32); - if (!(colour & 0x1000000)) { - if (!(colour & 0x8000000)) { - left_ = left - dpi->x; - if (left_ < 0) - left_ = 0; + if (!(colour & 0x8000000)) { + uint16 cross_pattern = 0; - right_ = right - dpi->x; - right_++; - if (right_ > dpi->width) - right_ = dpi->width; + int start_x = left - dpi->x; + if (start_x < 0){ + start_x = 0; + cross_pattern ^= start_x; + } - right_ -= left_; - - top_ = top - dpi->y; - if (top_ < 0) - top_ = 0; + int end_x = right - dpi->x; + end_x++; + if (end_x > dpi->width) + end_x = dpi->width; - bottom_ = bottom - dpi->y; - bottom_++; + int width = end_x - start_x; - if (bottom_ > dpi->height) - bottom_ = dpi->height; + int start_y = top - dpi->y; + if (start_y < 0){ + start_y = 0; + cross_pattern ^= start_y; + } + int end_y = bottom - dpi->y; + end_y++; - bottom_ -= top_; + if (end_y > dpi->height) + end_y = dpi->height; - 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* dest_pointer; - dest_pointer = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits;; - - //The pattern loops every 15 lines this is which - //part the pattern is on. - int pattern_y = (top + dpi->y) % 15; - - //The pattern loops every 15 pixels this is which - //part the pattern is on. - int pattern_x = (right + dpi_->x) % 15; - - uint16* pattern_pointer; - pattern_pointer = (uint16*)RCT2_GLOBAL(0x0097FEFC,uint32)[colour >> 28]; // or possibly uint8)[esi*4] ? - - for (int no_lines = bottom_; no_lines > 0; no_lines--) { - char* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch; - uint16 pattern = pattern_pointer[pattern_y]; - - for (int no_pixels = right_; no_pixels >=0; --no_pixels) { - if (!(pattern & (1 << pattern_x))) - *dest_pointer = colour & 0xFF; + int height = end_y - start_y; + if (colour&0x1000000){ + // 00678B2E 00678BE5 + //Cross hatching + uint8* dest_pointer = (start_y * (dpi->width + dpi->pitch)) + start_x + dpi->bits; - pattern_x = (pattern_x + 1) % 15; - dest_pointer++; - } - pattern_y = (pattern_y + 1) % 15; - dest_pointer = next_dest_pointer; + uint32 ecx; + for (int i = 0; i < height; ++i) { + uint8* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch; + ecx = cross_pattern; + // Rotate right + ecx = (ecx >> 1) | (ecx << (sizeof(ecx) * CHAR_BIT - 1)); + ecx = (ecx & 0xFFFF0000) | width; + // Fill every other pixel with the colour + for (; (ecx & 0xFFFF) > 0; ecx--) { + ecx = ecx ^ 0x80000000; + if ((int)ecx < 0) { + *dest_pointer = colour & 0xFF; } - return; + dest_pointer++; } + cross_pattern ^= 1; + dest_pointer = next_dest_pointer; + + } + } + if (!(colour & 0x2000000)) { + if (!(colour & 0x4000000)) { + uint8* dest_pointer = start_y * (dpi->width + dpi->pitch) + start_x + dpi->bits; + for (int i = 0; i < height; ++i) { + memset(dest_pointer, (colour & 0xFF), width); + dest_pointer += dpi->width + dpi->pitch; + } + return; } else { - // 00678B7E 00678C83 - // Location in screen buffer? - uint8* dest_pointer = (top_>>dpi->zoom_level) * ((dpi->width>>dpi->zoom_level) + dpi->pitch) + left_>>dpi->zoom_level + dpi->bits; + // 00678B8A 00678E38 + char* dest_pointer; + dest_pointer = start_y * (dpi->width + dpi->pitch) + start_x + 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]); + //The pattern loops every 15 lines this is which + //part the pattern is on. + int pattern_y = (top + dpi->y) % 15; - // Fill the rectangle with the colours from the colour table - for (int i = 0; i < bottom_>>dpi->zoom_level; ++i) { - uint8* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch; - for (int j = 0; j < right_; ++j) { - *dest_pointer = g1_element->offset[*dest_pointer]; + //The pattern loops every 15 pixels this is which + //part the pattern is on. + int pattern_x = (right + dpi_->x) % 15; + + uint16* pattern_pointer; + pattern_pointer = (uint16*)RCT2_GLOBAL(0x0097FEFC,uint32)[colour >> 28]; // or possibly uint8)[esi*4] ? + + for (int no_lines = height; no_lines > 0; no_lines--) { + char* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch; + uint16 pattern = pattern_pointer[pattern_y]; + + for (int no_pixels = width; no_pixels >=0; --no_pixels) { + if (!(pattern & (1 << pattern_x))) + *dest_pointer = colour & 0xFF; + + pattern_x = (pattern_x + 1) % 15; dest_pointer++; } + pattern_y = (pattern_y + 1) % 15; dest_pointer = next_dest_pointer; } return; } + } else { - // 00678B3A 00678EC9 still to be implemented - right_ = right; - return; - } - } else { - // 00678B2E 00678BE5 - // Cross hatching - uint16 pattern = 0; + // 00678B7E 00678C83 + // Location in screen buffer? + uint8* dest_pointer = (start_y>>dpi->zoom_level) * ((dpi->width>>dpi->zoom_level) + dpi->pitch) + start_x>>dpi->zoom_level + dpi->bits; - left_ = left_ - dpi->x; - if (left_ < 0) { - pattern = pattern ^ left_; - left_ = 0; - } + // 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]); - 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; + // Fill the rectangle with the colours from the colour table + for (int i = 0; i < height>>dpi->zoom_level; ++i) { + uint8* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch; + for (int j = 0; j < width; ++j) { + *dest_pointer = g1_element->offset[*dest_pointer]; + dest_pointer++; } - pixel++; + dest_pointer = next_dest_pointer; } - pattern = pattern ^ 1; - pixel += length; - + return; } - } - + } else { + // 00678B3A 00678EC9 still to be implemented + right_ = right; + return; + } // RCT2_CALLPROC_X(0x00678AD4, left, right, top, bottom, 0, dpi, colour); } From 6f528664fee80684c97dc3e05d51de55485d7d7b Mon Sep 17 00:00:00 2001 From: Duncan Date: Tue, 17 Jun 2014 16:47:32 +0100 Subject: [PATCH 08/17] Add Author --- src/gfx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gfx.c b/src/gfx.c index 1a586ceb4a..c922154b7e 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014 Ted John, Peter Hill + * Copyright (c) 2014 Ted John, Peter Hill, Duncan Frost * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. * * This file is part of OpenRCT2. From 4b02a716921717a606e3630f3b79bb597511ec7f Mon Sep 17 00:00:00 2001 From: Duncan Date: Wed, 18 Jun 2014 12:22:15 +0100 Subject: [PATCH 09/17] Changed layout of gfx_fill_rect Now in a more logical state. Ready for being reimplemented as a switch with multiple functions. --- src/gfx.c | 215 +++++++++++++++++++++++++++--------------------------- 1 file changed, 108 insertions(+), 107 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index c922154b7e..c48189f199 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -356,126 +356,127 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot colour |= RCT2_GLOBAL(0x009ABD9C, uint32); - if (!(colour & 0x8000000)) { - uint16 cross_pattern = 0; + uint16 cross_pattern = 0; - int start_x = left - dpi->x; - if (start_x < 0){ - start_x = 0; - cross_pattern ^= start_x; - } + int start_x = left - dpi->x; + if (start_x < 0){ + start_x = 0; + cross_pattern ^= start_x; + } - int end_x = right - dpi->x; - end_x++; - if (end_x > dpi->width) - end_x = dpi->width; + int end_x = right - dpi->x; + end_x++; + if (end_x > dpi->width) + end_x = dpi->width; - int width = end_x - start_x; + int width = end_x - start_x; - int start_y = top - dpi->y; - if (start_y < 0){ - start_y = 0; - cross_pattern ^= start_y; - } - int end_y = bottom - dpi->y; - end_y++; + int start_y = top - dpi->y; + if (start_y < 0){ + start_y = 0; + cross_pattern ^= start_y; + } + int end_y = bottom - dpi->y; + end_y++; - if (end_y > dpi->height) - end_y = dpi->height; + if (end_y > dpi->height) + end_y = dpi->height; - int height = end_y - start_y; - if (colour&0x1000000){ - // 00678B2E 00678BE5 - //Cross hatching - uint8* dest_pointer = (start_y * (dpi->width + dpi->pitch)) + start_x + dpi->bits; - - uint32 ecx; - for (int i = 0; i < height; ++i) { - uint8* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch; - ecx = cross_pattern; - // Rotate right - ecx = (ecx >> 1) | (ecx << (sizeof(ecx) * CHAR_BIT - 1)); - ecx = (ecx & 0xFFFF0000) | width; - // Fill every other pixel with the colour - for (; (ecx & 0xFFFF) > 0; ecx--) { - ecx = ecx ^ 0x80000000; - if ((int)ecx < 0) { - *dest_pointer = colour & 0xFF; - } - dest_pointer++; - } - cross_pattern ^= 1; - dest_pointer = next_dest_pointer; - - } - } - if (!(colour & 0x2000000)) { - if (!(colour & 0x4000000)) { - uint8* dest_pointer = start_y * (dpi->width + dpi->pitch) + start_x + dpi->bits; - - for (int i = 0; i < height; ++i) { - memset(dest_pointer, (colour & 0xFF), width); - dest_pointer += dpi->width + dpi->pitch; - } - return; - } else { - // 00678B8A 00678E38 - char* dest_pointer; - dest_pointer = start_y * (dpi->width + dpi->pitch) + start_x + dpi->bits; - - //The pattern loops every 15 lines this is which - //part the pattern is on. - int pattern_y = (top + dpi->y) % 15; - - //The pattern loops every 15 pixels this is which - //part the pattern is on. - int pattern_x = (right + dpi_->x) % 15; - - uint16* pattern_pointer; - pattern_pointer = (uint16*)RCT2_GLOBAL(0x0097FEFC,uint32)[colour >> 28]; // or possibly uint8)[esi*4] ? - - for (int no_lines = height; no_lines > 0; no_lines--) { - char* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch; - uint16 pattern = pattern_pointer[pattern_y]; - - for (int no_pixels = width; no_pixels >=0; --no_pixels) { - if (!(pattern & (1 << pattern_x))) - *dest_pointer = colour & 0xFF; + int height = end_y - start_y; + if (colour&0x1000000){ + // 00678B2E 00678BE5 + //Cross hatching + uint8* dest_pointer = (start_y * (dpi->width + dpi->pitch)) + start_x + dpi->bits; - pattern_x = (pattern_x + 1) % 15; - dest_pointer++; - } - pattern_y = (pattern_y + 1) % 15; - dest_pointer = next_dest_pointer; + uint32 ecx; + for (int i = 0; i < height; ++i) { + uint8* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch; + ecx = cross_pattern; + // Rotate right + ecx = (ecx >> 1) | (ecx << (sizeof(ecx) * CHAR_BIT - 1)); + ecx = (ecx & 0xFFFF0000) | width; + // Fill every other pixel with the colour + for (; (ecx & 0xFFFF) > 0; ecx--) { + ecx = ecx ^ 0x80000000; + if ((int)ecx < 0) { + *dest_pointer = colour & 0xFF; } - return; + dest_pointer++; } - - } else { - // 00678B7E 00678C83 - // Location in screen buffer? - uint8* dest_pointer = (start_y>>dpi->zoom_level) * ((dpi->width>>dpi->zoom_level) + dpi->pitch) + start_x>>dpi->zoom_level + 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]); - - // Fill the rectangle with the colours from the colour table - for (int i = 0; i < height>>dpi->zoom_level; ++i) { - uint8* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch; - for (int j = 0; j < width; ++j) { - *dest_pointer = g1_element->offset[*dest_pointer]; - dest_pointer++; - } - dest_pointer = next_dest_pointer; - } - return; + cross_pattern ^= 1; + dest_pointer = next_dest_pointer; + } - } else { + return; + } + if (colour & 0x2000000){ + //0x2000000 + // 00678B7E 00678C83 + // Location in screen buffer? + uint8* dest_pointer = (start_y>>dpi->zoom_level) * ((dpi->width>>dpi->zoom_level) + dpi->pitch) + start_x>>dpi->zoom_level + 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]); + + // Fill the rectangle with the colours from the colour table + for (int i = 0; i < height>>dpi->zoom_level; ++i) { + uint8* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch; + for (int j = 0; j < width; ++j) { + *dest_pointer = g1_element->offset[*dest_pointer]; + dest_pointer++; + } + dest_pointer = next_dest_pointer; + } + return; + } + if (colour & 0x4000000){ + //0x4000000 + // 00678B8A 00678E38 + char* dest_pointer; + dest_pointer = start_y * (dpi->width + dpi->pitch) + start_x + dpi->bits; + + //The pattern loops every 15 lines this is which + //part the pattern is on. + int pattern_y = (top + dpi->y) % 15; + + //The pattern loops every 15 pixels this is which + //part the pattern is on. + int pattern_x = (right + dpi_->x) % 15; + + uint16* pattern_pointer; + pattern_pointer = (uint16*)RCT2_GLOBAL(0x0097FEFC,uint32)[colour >> 28]; // or possibly uint8)[esi*4] ? + + for (int no_lines = height; no_lines > 0; no_lines--) { + char* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch; + uint16 pattern = pattern_pointer[pattern_y]; + + for (int no_pixels = width; no_pixels >=0; --no_pixels) { + if (!(pattern & (1 << pattern_x))) + *dest_pointer = colour & 0xFF; + + pattern_x = (pattern_x + 1) % 15; + dest_pointer++; + } + pattern_y = (pattern_y + 1) % 15; + dest_pointer = next_dest_pointer; + } + return; + } + if (colour & 0x8000000){ + //0x8000000 // 00678B3A 00678EC9 still to be implemented + //RCT2_CALLPROC_X(0x00678AD4, left, right, top, bottom, 0, dpi, colour); right_ = right; return; - } + } + //0x0000000 + uint8* dest_pointer = start_y * (dpi->width + dpi->pitch) + start_x + dpi->bits; + + for (int i = 0; i < height; ++i) { + memset(dest_pointer, (colour & 0xFF), width); + dest_pointer += dpi->width + dpi->pitch; + } // RCT2_CALLPROC_X(0x00678AD4, left, right, top, bottom, 0, dpi, colour); } From 31bf6bf4b3494eaf99c7bb601e68c7ecb718d099 Mon Sep 17 00:00:00 2001 From: Duncan Date: Wed, 18 Jun 2014 13:03:37 +0100 Subject: [PATCH 10/17] Re-factor of gfx_transpose_palette Requires testing i feel as though osinterface call might be incorrect. --- src/gfx.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index c48189f199..2afb80f147 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1121,25 +1121,21 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in */ void gfx_transpose_palette(int pal, unsigned char product) { - int eax, ebx, ebp; - uint8* esi, *edi; + rct_g1_element g1 = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[pal]; + int width = g1.width; + int x = g1.x_offset; + uint8* dest_pointer = RCT2_ADDRESS(0x014124680,uint8)[x]; + uint8* source_pointer = g1.offset; - ebx = pal * 16; - esi = (uint8*)(*((int*)(RCT2_ADDRESS_G1_ELEMENTS + ebx))); - ebp = *((short*)(0x009EBD2C + ebx)); - eax = *((short*)(0x009EBD30 + ebx)) * 4; - edi = (uint8*)0x01424680 + eax; - - for (; ebp > 0; ebp--) { - edi[0] = (esi[0] * product) >> 8; - edi[1] = (esi[1] * product) >> 8; - edi[2] = (esi[2] * product) >> 8; - esi += 3; - edi += 4; + for (; width > 0; width--) { + dest_pointer[0] = (source_pointer[0] * product) >> 8; + dest_pointer[1] = (source_pointer[1] * product) >> 8; + dest_pointer[2] = (source_pointer[2] * product) >> 8; + source_pointer += 3; + dest_pointer += 4; } - osinterface_update_palette((char*)0x01424680, 10, 236); + osinterface_update_palette((char*)0x01424680, 10, 236);//Odd would have expected dest_pointer } - /** * Draws i formatted text string centred at i specified position. * rct2: 0x006C1D6C From 759268c1f5c2bfaa74284da01987aa64bc4d56ff Mon Sep 17 00:00:00 2001 From: Duncan Date: Wed, 18 Jun 2014 16:22:45 +0100 Subject: [PATCH 11/17] Started adding final pattern code Has not been tested. Looping code not implemented. --- src/gfx.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/gfx.c b/src/gfx.c index 2afb80f147..abc96a258c 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -467,7 +467,59 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot //0x8000000 // 00678B3A 00678EC9 still to be implemented //RCT2_CALLPROC_X(0x00678AD4, left, right, top, bottom, 0, dpi, colour); - right_ = right; + esi = left - RCT2_GLOBAL(0x1420070,sint16); + RCT2_GLOBAL(0xEDF824,uint32) = esi; + esi = top - RCT2_GLOBAL(0x1420072,sint16); + RCT2_GLOBAL(0xEDF828,uint32) = esi; + left -= dpi->x;//0x4 + if ( left < 0 ){ + RCT2_GLOBAL(0xEDF824,sint32) -= left; + left = 0; + } + right -= dpi->x; + right++; + if ( right > dpi->width ){ + right = dpi->width + } + right -= left; + top -= dpi->y; + if ( top < 0 ){ + RCT2_GLOBAL(0xEDF828,sint32) -= top; + top = 0; + } + bottom -= dpi->y; + bottom++; + if (bottom > dpi->height){ + bottom = dpi->height; + } + bottom -= top; + RCT2_GLOBAL(0xEDF824,sint32) &= 0x3F; + RCT2_GLOBAL(0xEDF828,sint32) &= 0x3F; + esi = dpi->width; + esi += dpi->pitch; + esi *= top; + esi += left; + esi += dpi->bits; + RCT2_GLOBAL(0xEDF82C,sint32) = right; + RCT2_GLOBAL(0xEDF830,sint32) = bottom; + left = dpi->width; + left+= dpi->pitch; + left-= right; + RCT2_GLOBAL(0xEDF834,sint32) = left; + colour &= 0xFF; + colour--; + right = colour; + colour <<= 8; + right |= colour; + RCT2_GLOBAL(0xEDF838,sint32) = right; + //right <<= 4; + int edi = esi; + esi = RCT2_GLOBAL(0xEDF828,sint32); + esi *= 0x40; + left = 0; + esi += RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS,rct_g1_element)[right];//??? + //Not finished + //Start of loop return; } //0x0000000 From b6274a72a0deadae5cf70d3131bc9c47eff320dc Mon Sep 17 00:00:00 2001 From: Duncan Date: Wed, 18 Jun 2014 16:35:26 +0100 Subject: [PATCH 12/17] Added note about possible issue in draw_sprite. --- src/gfx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gfx.c b/src/gfx.c index abc96a258c..7c59552edf 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -922,7 +922,8 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax >>= 19; //push edx/y eax &= 0x1F; - ebp = RCT2_GLOBAL(ebp * 4 + 0x97FCBC, uint32); + ebp = RCT2_GLOBAL(ebp * 4 + 0x97FCBC, uint32); //ebp has not been set to anything before this! ?? + //Possibly another variable input?! eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); ebp <<= 0x4; eax <<= 0x4; From e2d5c9904c05e02b17e17a99895cdd2d30199d3e Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 18 Jun 2014 18:24:52 +0100 Subject: [PATCH 13/17] Fixed compile bugs. Zooming code is broken --- src/gfx.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 7c59552edf..75696cf6c9 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -413,7 +413,7 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot //0x2000000 // 00678B7E 00678C83 // Location in screen buffer? - uint8* dest_pointer = (start_y>>dpi->zoom_level) * ((dpi->width>>dpi->zoom_level) + dpi->pitch) + start_x>>dpi->zoom_level + dpi->bits; + uint8* dest_pointer = dpi->bits + (uint32)((start_y>>(dpi->zoom_level)) * ((dpi->width >> dpi->zoom_level) + dpi->pitch) + (start_x >> dpi->zoom_level)); // Find colour in colour table? uint32 eax = RCT2_ADDRESS(0x0097FCBC, uint32)[(colour & 0xFF)]; @@ -445,7 +445,7 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot int pattern_x = (right + dpi_->x) % 15; uint16* pattern_pointer; - pattern_pointer = (uint16*)RCT2_GLOBAL(0x0097FEFC,uint32)[colour >> 28]; // or possibly uint8)[esi*4] ? + pattern_pointer = (uint16*)(&RCT2_ADDRESS(0x0097FEFC,uint16)[colour >> 28]); // or possibly uint8)[esi*4] ? for (int no_lines = height; no_lines > 0; no_lines--) { char* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch; @@ -467,7 +467,7 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot //0x8000000 // 00678B3A 00678EC9 still to be implemented //RCT2_CALLPROC_X(0x00678AD4, left, right, top, bottom, 0, dpi, colour); - esi = left - RCT2_GLOBAL(0x1420070,sint16); + int esi = left - RCT2_GLOBAL(0x1420070,sint16); RCT2_GLOBAL(0xEDF824,uint32) = esi; esi = top - RCT2_GLOBAL(0x1420072,sint16); RCT2_GLOBAL(0xEDF828,uint32) = esi; @@ -479,7 +479,7 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot right -= dpi->x; right++; if ( right > dpi->width ){ - right = dpi->width + right = dpi->width; } right -= left; top -= dpi->y; @@ -499,7 +499,7 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot esi += dpi->pitch; esi *= top; esi += left; - esi += dpi->bits; + esi += (uint32)dpi->bits; RCT2_GLOBAL(0xEDF82C,sint32) = right; RCT2_GLOBAL(0xEDF830,sint32) = bottom; left = dpi->width; @@ -517,7 +517,7 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot esi = RCT2_GLOBAL(0xEDF828,sint32); esi *= 0x40; left = 0; - esi += RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS,rct_g1_element)[right];//??? + esi += (uint32)(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS,rct_g1_element)[right]).offset;//??? //Not finished //Start of loop return; @@ -657,8 +657,8 @@ void gfx_bmp_sprite_to_buffer(uint8* palette_pointer, uint8* unknown_pointer, ui unknown_pointer += source_pointer - source_image->offset;// RCT2_GLOBAL(0x9E3CE0, uint32); for (; height > 0; height -= (1<width << zoom_level; - uint8* next_unknown_pointer = unknown_pointer + source_image->width << zoom_level; + uint8* next_source_pointer = source_pointer + (uint32)(source_image->width << zoom_level); + uint8* next_unknown_pointer = unknown_pointer + (uint32)(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 -= (1< 0; height -= (1<width<width<width + dest_dpi->pitch; for (int no_pixels = width; no_pixels > 0; no_pixels -= (1< 0; height -= (1<width<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 -= (1<flags & G1_FLAG_BMP)){//Not tested for (; height > 0; height-=(1<width<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 -= (1<offset; for (; height > 0; height -= (1<width<width<width << zoom_level); + uint8* next_unknown_pointer = unknown_pointer + (uint32)(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 -= (1< 0; height -= (1<width<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 -= (1<zoom_level = 0; gfx_draw_sprite_palette_set(dpi, image_id, x, y, palette_pointer, unknown_pointer); + dpi->zoom_level = 0; } /* @@ -1014,7 +1015,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in .height = dpi->height>>1, .width = dpi->width>>1, .pitch = dpi->pitch, - .zoom_level = dpi->zoomlevel - 1 + .zoom_level = dpi->zoom_level - 1 }; gfx_draw_sprite_palette_set(&zoomed_dpi,(image_type << 28) | (image_element - dpi->zoom_level), x >> 1, y >> 1, palette_pointer, unknown_pointer); return; @@ -1177,7 +1178,7 @@ void gfx_transpose_palette(int pal, unsigned char product) rct_g1_element g1 = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[pal]; int width = g1.width; int x = g1.x_offset; - uint8* dest_pointer = RCT2_ADDRESS(0x014124680,uint8)[x]; + uint8* dest_pointer = (uint8*)&(RCT2_ADDRESS(0x014124680,uint8)[x]); uint8* source_pointer = g1.offset; for (; width > 0; width--) { From 9c051a0a227fd18c54b02e81531c65c6fe85753a Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 18 Jun 2014 19:19:27 +0100 Subject: [PATCH 14/17] Fixed zooming code. Its still not working quite right --- src/gfx.c | 36 +++++++++++++++++------------------- src/gfx.h | 2 +- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 75696cf6c9..bab06b4520 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -987,9 +987,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0x9ABDA4, uint8*) = palette; palette_pointer = palette; } - dpi->zoom_level = 0; gfx_draw_sprite_palette_set(dpi, image_id, x, y, palette_pointer, unknown_pointer); - dpi->zoom_level = 0; } /* @@ -1007,37 +1005,37 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in rct_g1_element* g1_source = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[image_element]); - if ( dpi->zoom_level && !(g1_source->flags & (1<<4)) ){ + if ( dpi->zoom_level && (g1_source->flags & (1<<4)) ){ rct_drawpixelinfo zoomed_dpi = { .bits = dpi->bits, .x = dpi->x >> 1, .y = dpi->y >> 1, .height = dpi->height>>1, .width = dpi->width>>1, - .pitch = dpi->pitch, + .pitch = (dpi->width+dpi->pitch)-(dpi->width>>1),//In the actual code this is dpi->pitch but that doesn't seem correct. .zoom_level = dpi->zoom_level - 1 }; - gfx_draw_sprite_palette_set(&zoomed_dpi,(image_type << 28) | (image_element - dpi->zoom_level), x >> 1, y >> 1, palette_pointer, unknown_pointer); + gfx_draw_sprite_palette_set(&zoomed_dpi, (image_type << 28) | (image_element - g1_source->zoomed_offset), x >> 1, y >> 1, palette_pointer, unknown_pointer); return; } - if ( dpi->zoom_level && !(g1_source->flags & (1<<5)) ){ + if ( dpi->zoom_level && (g1_source->flags & (1<<5)) ){ return; } //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); - return; - } - if (dpi->zoom_level == 2){ - RCT2_CALLPROC_X(0x0067DADA, 0, (int)g1_source, x, y, 0, (int)dpi, 0); - return; - } - RCT2_CALLPROC_X(0x0067FAAE, 0, (int)g1_source, x, y, 0, (int)dpi, 0); - return; - }*/ + //if (dpi->zoom_level >= 1){ //These have not been tested + // //something to do with zooming + // if (dpi->zoom_level == 1){ + // RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); + // return; + // } + // if (dpi->zoom_level == 2){ + // RCT2_CALLPROC_X(0x0067DADA, 0, (int)g1_source, x, y, 0, (int)dpi, 0); + // return; + // } + // RCT2_CALLPROC_X(0x0067FAAE, 0, (int)g1_source, x, y, 0, (int)dpi, 0); + // return; + //} //Its used super often so we will define it to a seperate variable. int zoom_level = dpi->zoom_level; diff --git a/src/gfx.h b/src/gfx.h index 6e484b74e7..d2e3eeb433 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -43,7 +43,7 @@ typedef struct { sint16 x_offset; // 0x08 sint16 y_offset; // 0x0A uint16 flags; // 0x0C - sint16 unused; // 0x0E + sint16 zoomed_offset; // 0x0E } rct_g1_element; enum{ From 5de7cac8829ec2e73c4097d75379daef7d0851ec Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Thu, 19 Jun 2014 09:25:50 +0100 Subject: [PATCH 15/17] Fixed pattern bugs in new code --- src/gfx.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index bab06b4520..e04bfc9cc9 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -413,17 +413,17 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot //0x2000000 // 00678B7E 00678C83 // Location in screen buffer? - uint8* dest_pointer = dpi->bits + (uint32)((start_y>>(dpi->zoom_level)) * ((dpi->width >> dpi->zoom_level) + dpi->pitch) + (start_x >> dpi->zoom_level)); + uint8* dest_pointer = dpi->bits + (uint32)((start_y >> (dpi->zoom_level)) * ((dpi->width >> dpi->zoom_level) + dpi->pitch) + (start_x >> dpi->zoom_level)); // 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]); + rct_g1_element g1_element = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[eax]; // Fill the rectangle with the colours from the colour table for (int i = 0; i < height>>dpi->zoom_level; ++i) { - uint8* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch; + uint8* next_dest_pointer = dest_pointer + (dpi->width >> dpi->zoom_level) + dpi->pitch; for (int j = 0; j < width; ++j) { - *dest_pointer = g1_element->offset[*dest_pointer]; + *dest_pointer = g1_element.offset[*dest_pointer]; dest_pointer++; } dest_pointer = next_dest_pointer; @@ -438,27 +438,29 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot //The pattern loops every 15 lines this is which //part the pattern is on. - int pattern_y = (top + dpi->y) % 15; + int pattern_y = (start_y + dpi->y) % 16; //The pattern loops every 15 pixels this is which //part the pattern is on. - int pattern_x = (right + dpi_->x) % 15; + int start_pattern_x = (start_x + dpi_->x) % 16; + int pattern_x = start_pattern_x; uint16* pattern_pointer; - pattern_pointer = (uint16*)(&RCT2_ADDRESS(0x0097FEFC,uint16)[colour >> 28]); // or possibly uint8)[esi*4] ? + pattern_pointer = RCT2_ADDRESS(0x0097FEFC,uint16*)[colour >> 28]; // or possibly uint8)[esi*4] ? for (int no_lines = height; no_lines > 0; no_lines--) { char* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch; uint16 pattern = pattern_pointer[pattern_y]; - for (int no_pixels = width; no_pixels >=0; --no_pixels) { - if (!(pattern & (1 << pattern_x))) + for (int no_pixels = width; no_pixels > 0; --no_pixels) { + if (pattern & (1 << pattern_x)) *dest_pointer = colour & 0xFF; - pattern_x = (pattern_x + 1) % 15; + pattern_x = (pattern_x + 1) % 16; dest_pointer++; } - pattern_y = (pattern_y + 1) % 15; + pattern_x = start_pattern_x; + pattern_y = (pattern_y + 1) % 16; dest_pointer = next_dest_pointer; } return; From f68ab9162dfe7934bf743545ef5aa7a9c10514b9 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Thu, 19 Jun 2014 10:27:35 +0100 Subject: [PATCH 16/17] Added 0x97FCBC table for getting palettes from g1 elements --- src/gfx.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index e04bfc9cc9..6fd0515136 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -69,6 +69,46 @@ uint8 text_palette[0x8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +// Previously 0x97FCBC use it to get the correct palette from g1_elements +uint16 palette_to_g1_offset[] = { + 0x1333, 0x1334, 0x1335, 0x1336, + 0x1337, 0x1338, 0x1339, 0x133A, + 0x133B, 0x133C, 0x133D, 0x133E, + 0x133F, 0x1340, 0x1341, 0x1342, + 0x1343, 0x1344, 0x1345, 0x1346, + 0x1347, 0x1348, 0x1349, 0x134A, + 0x134B, 0x134C, 0x134D, 0x134E, + 0x134F, 0x1350, 0x1351, 0x1352, + 0x1353, 0x0C1C, 0x0C1D, 0x0C1E, + 0x0C1F, 0x0C20, 0x0C22, 0x0C23, + 0x0C24, 0x0C25, 0x0C26, 0x0C21, + 0x1354, 0x1355, 0x1356, 0x1357, + 0x1358, 0x1359, 0x135A, 0x135B, + 0x135C, 0x135D, 0x135E, 0x135F, + 0x1360, 0x1361, 0x1362, 0x1363, + 0x1364, 0x1365, 0x1366, 0x1367, + 0x1368, 0x1369, 0x136A, 0x136B, + 0x136C, 0x136D, 0x136E, 0x136F, + 0x1370, 0x1371, 0x1372, 0x1373, + 0x1374, 0x1375, 0x1376, 0x1377, + 0x1378, 0x1379, 0x137A, 0x137B, + 0x137C, 0x137D, 0x137E, 0x137F, + 0x1380, 0x1381, 0x1382, 0x1383, + 0x1384, 0x1385, 0x1386, 0x1387, + 0x1388, 0x1389, 0x138A, 0x138B, + 0x138C, 0x138D, 0x138E, 0x138F, + 0x1390, 0x1391, 0x1392, 0x1393, + 0x1394, 0x1395, 0x1396, 0x1397, + 0x1398, 0x1399, 0x139A, 0x139B, + 0x139C, 0x139D, 0x139E, 0x139F, + 0x13A0, 0x13A1, 0x13A2, 0x13A3, + 0x13A4, 0x13A5, 0x13A6, 0x13A7, + 0x13A8, 0x13A9, 0x13AA, 0x13AB, + 0x13AC, 0x13AD, 0x13AE, 0x13AF, + 0x13B0, 0x13B1, 0x13B2, 0x13B3, + 0x13B4, 0x13B5, 0x13B6, 0x13B7, +}; + static void gfx_draw_dirty_blocks(int x, int y, int columns, int rows); /** @@ -416,7 +456,7 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot uint8* dest_pointer = dpi->bits + (uint32)((start_y >> (dpi->zoom_level)) * ((dpi->width >> dpi->zoom_level) + dpi->pitch) + (start_x >> dpi->zoom_level)); // Find colour in colour table? - uint32 eax = RCT2_ADDRESS(0x0097FCBC, uint32)[(colour & 0xFF)]; + uint16 eax = palette_to_g1_offset[(colour & 0xFF)]; rct_g1_element g1_element = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[eax]; // Fill the rectangle with the colours from the colour table @@ -910,7 +950,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax >>= 19; eax &= 0x7F; } - eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); + eax = palette_to_g1_offset[eax];// RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); palette_pointer = ((rct_g1_element*)RCT2_ADDRESS_G1_ELEMENTS)[eax].offset; RCT2_GLOBAL(0x9ABDA4, uint32) = (uint32)palette_pointer; @@ -924,9 +964,9 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) eax >>= 19; //push edx/y eax &= 0x1F; - ebp = RCT2_GLOBAL(ebp * 4 + 0x97FCBC, uint32); //ebp has not been set to anything before this! ?? + ebp = palette_to_g1_offset[ebp]; //RCT2_GLOBAL(ebp * 4 + 0x97FCBC, uint32); //ebp has not been set to anything before this! ?? //Possibly another variable input?! - eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); + eax = palette_to_g1_offset[eax]; //RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); ebp <<= 0x4; eax <<= 0x4; ebp = RCT2_GLOBAL(ebp + RCT2_ADDRESS_G1_ELEMENTS, uint32); @@ -952,7 +992,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) RCT2_GLOBAL(0xEDF81C, uint32) |= 0x20000000; image_id |= IMAGE_TYPE_USE_PALETTE; - eax = RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); + eax = palette_to_g1_offset[eax]; //RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); eax <<= 4; eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); edx = *((uint32*)(eax + 0xF3)); @@ -975,13 +1015,13 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y) //Top int top_type = (image_id >> 19) & 0x1f; - uint32 top_offset = RCT2_ADDRESS(0x97FCBC, uint32)[top_type]; + uint32 top_offset = palette_to_g1_offset[top_type]; //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]; + uint32 trouser_offset = palette_to_g1_offset[trouser_type]; //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); @@ -2063,7 +2103,7 @@ void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, in } } - eax = RCT2_ADDRESS(0x097FCBC, uint32)[al * 4]; + eax = palette_to_g1_offset[al]; //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)) { From 76c07fc278fcae393062dc1e84f45e4f199ce128 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Thu, 19 Jun 2014 10:33:14 +0100 Subject: [PATCH 17/17] Added paletts to sprite list. --- src/sprites.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/sprites.h b/src/sprites.h index 83f9e3461b..2ec98fa449 100644 --- a/src/sprites.h +++ b/src/sprites.h @@ -24,6 +24,9 @@ enum { SPR_NONE = -1, + SPR_PALETTE_1_START = 3100, + SPR_PALETTE_1_END = 3110, + SPR_COOL_AND_WET = 3290, SPR_WARM = 3291, SPR_HOT_AND_DRY = 3292, @@ -36,6 +39,9 @@ enum { SPR_CHAR_START = 3861, SPR_CHAR_END = 4757, + SPR_PALETTE_2_START = 4915, + SPR_PALETTE_2_END = 5047, + SPR_RESIZE = 5058, SPR_HEARING_VIEWPORT = 5166,