2014-04-02 22:50:16 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* Copyright (c) 2014 Ted John
|
|
|
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
|
|
|
*
|
|
|
|
* This file is part of OpenRCT2.
|
|
|
|
*
|
|
|
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2014-04-04 20:59:32 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <windows.h>
|
2014-04-02 22:50:16 +02:00
|
|
|
#include "addresses.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "rct2.h"
|
|
|
|
|
2014-04-04 20:59:32 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x00678998
|
|
|
|
*/
|
|
|
|
void gfx_load_g1()
|
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
DWORD bytesRead;
|
|
|
|
DWORD header[2];
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int g1BufferSize;
|
|
|
|
void* g1Buffer;
|
|
|
|
|
|
|
|
rct_g1_element *g1Elements = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element);
|
|
|
|
|
|
|
|
hFile = CreateFile(get_file_path(PATH_ID_G1), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
|
|
|
|
FILE_FLAG_RANDOM_ACCESS | FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (hFile != INVALID_HANDLE_VALUE) {
|
|
|
|
ReadFile(hFile, header, 8, &bytesRead, NULL);
|
|
|
|
if (bytesRead == 8) {
|
|
|
|
g1BufferSize = header[1];
|
|
|
|
g1Buffer = rct2_malloc(g1BufferSize);
|
|
|
|
ReadFile(hFile, g1Elements, 29294 * sizeof(rct_g1_element), &bytesRead, NULL);
|
|
|
|
ReadFile(hFile, g1Buffer, g1BufferSize, &bytesRead, NULL);
|
|
|
|
CloseHandle(hFile);
|
|
|
|
|
|
|
|
for (i = 0; i < 29294; i++)
|
|
|
|
g1Elements[i].offset += (int)g1Buffer;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// exit with error
|
|
|
|
fprintf(stderr, "Unable to load g1.dat");
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
2014-04-02 22:50:16 +02:00
|
|
|
/**
|
2014-04-03 04:08:06 +02:00
|
|
|
* Clears the screen with the specified colour.
|
|
|
|
* rct2: 0x00678A9F
|
|
|
|
*/
|
2014-04-02 22:50:16 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
ptr = dpi->bits;
|
|
|
|
for (y = 0; y < h; y++) {
|
|
|
|
memset(ptr, colour, w);
|
|
|
|
ptr += w + dpi->pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-03 04:08:06 +02:00
|
|
|
*
|
|
|
|
* rct2: 0x00678AD4
|
|
|
|
* left (ax)
|
|
|
|
* top (cx)
|
|
|
|
* right (bx)
|
|
|
|
* bottom (dx)
|
|
|
|
* colour (ebp)
|
|
|
|
*/
|
2014-04-02 22:50:16 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-03 04:08:06 +02:00
|
|
|
*
|
|
|
|
* rct2: 0x0067A28E
|
|
|
|
* image_id (ebx)
|
|
|
|
* x (cx)
|
|
|
|
* y (dx)
|
|
|
|
*/
|
2014-04-02 22:50:16 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-03 04:08:06 +02:00
|
|
|
*
|
|
|
|
* rct2: 0x00683854
|
|
|
|
* a1 (ebx)
|
|
|
|
* product (cl)
|
|
|
|
*/
|
2014-04-02 22:50:16 +02:00
|
|
|
void gfx_transpose_palette(int pal, unsigned char product)
|
|
|
|
{
|
|
|
|
int eax, ebx, ebp;
|
|
|
|
uint8* esi, *edi;
|
|
|
|
|
|
|
|
ebx = pal * 16;
|
|
|
|
esi = (uint8*)(*((int*)(0x009EBD28 + 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT2_CALLPROC_3(0x00405595, int, int, int, 0x01424680, 10, 236);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-03 04:08:06 +02:00
|
|
|
* Draws i formatted text string centred at i specified position.
|
|
|
|
* rct2: 0x006C1D6C
|
|
|
|
* dpi (edi)
|
|
|
|
* format (bx)
|
|
|
|
* x (cx)
|
|
|
|
* y (dx)
|
|
|
|
* colour (al)
|
|
|
|
* args (esi)
|
|
|
|
*/
|
2014-04-02 22:50:16 +02:00
|
|
|
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, args, dpi, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-03 04:08:06 +02:00
|
|
|
*
|
|
|
|
* rct2: 0x006ED7E5
|
|
|
|
*/
|
2014-04-02 22:50:16 +02:00
|
|
|
void gfx_invalidate_screen()
|
|
|
|
{
|
|
|
|
RCT2_CALLPROC_EBPSAFE(0x006ED7E5);
|
|
|
|
}
|