From efb3484b799879fdaaadfce0e29ceb717df59585 Mon Sep 17 00:00:00 2001 From: OmniBlade Date: Tue, 16 Feb 2021 12:48:29 +0100 Subject: [PATCH] Applies some fixes for an MSVC build. Casts for arithmetic on void*. Includes SDL.h directly with no folder (Documentation suggests this is best practice anyhow) Provides a win32 clock_gettime implementation suitable for how it is used. Removes braces from struct typedefs to keep msvc happy. Other misc changes. OpenGL implementation needs work on MSVC and does not build correctly yet. --- src/BRSRC13/CORE/FW/fwsetup.c | 2 +- src/BRSRC13/CORE/FW/resource.c | 4 ++-- src/BRSRC13/CORE/V1DB/regsupt.c | 7 +++++-- src/BRSRC13/br_types.h | 18 ++++++------------ src/DETHRACE/common/flicplay.c | 4 +++- src/DETHRACE/common/graphics.c | 10 +++++----- src/DETHRACE/common/input.c | 2 +- src/DETHRACE/common/intrface.c | 4 +++- src/DETHRACE/common/loading.c | 2 +- src/DETHRACE/dr_types.h | 14 +++++++++++--- src/DETHRACE/pc-dos/dossys.c | 29 ++++++++++++++++++++++++++++- src/DETHRACE/watcom_functions.c | 2 +- src/harness/debug.h | 4 ++++ src/harness/harness.h | 2 +- src/harness/input/keyboard.c | 2 +- src/harness/renderers/gl_renderer.c | 3 ++- src/harness/renderers/gl_renderer.h | 2 +- src/harness/stack_trace_handler.h | 5 +++++ 18 files changed, 81 insertions(+), 35 deletions(-) diff --git a/src/BRSRC13/CORE/FW/fwsetup.c b/src/BRSRC13/CORE/FW/fwsetup.c index c86cf00c..f576ca6d 100644 --- a/src/BRSRC13/CORE/FW/fwsetup.c +++ b/src/BRSRC13/CORE/FW/fwsetup.c @@ -50,7 +50,7 @@ br_resource_class fw_resourceClasses[25] = { br_uint_16 nameOrdinals_BRCORE1[185]; br_image Image_BRCORE1 = { - {}, + {0}, "BRCORE1", 2, 0, diff --git a/src/BRSRC13/CORE/FW/resource.c b/src/BRSRC13/CORE/FW/resource.c index ee91653d..6120224b 100644 --- a/src/BRSRC13/CORE/FW/resource.c +++ b/src/BRSRC13/CORE/FW/resource.c @@ -108,7 +108,7 @@ void BrResInternalFree(resource_header* res, br_boolean callback) { void BrResFree(void* vres) { LOG_TRACE10("(%p)", vres); - vres = vres - sizeof(resource_header); + vres = (char*)vres - sizeof(resource_header); if (((resource_header*)vres)->magic_num != 0xDEADBEEF) { LOG_PANIC("Bad resource header at %p", vres); } @@ -118,7 +118,7 @@ void BrResFree(void* vres) { void BrResAssert(void* vres) { LOG_TRACE("(%p)", vres); - vres = vres - sizeof(resource_header); + vres = (char*)vres - sizeof(resource_header); if (((resource_header*)vres)->magic_num != 0xDEADBEEF) { LOG_PANIC("Bad resource header at %p. Was %X", vres, ((resource_header*)vres)->magic_num); diff --git a/src/BRSRC13/CORE/V1DB/regsupt.c b/src/BRSRC13/CORE/V1DB/regsupt.c index 91fcc82d..da453450 100644 --- a/src/BRSRC13/CORE/V1DB/regsupt.c +++ b/src/BRSRC13/CORE/V1DB/regsupt.c @@ -74,6 +74,7 @@ br_uint_32 BrModelEnum(char* pattern, br_model_enum_cbfn* callback, void* arg) { br_material* BrMaterialAdd(br_material* material) { BrRegistryAdd(&v1db.reg_materials, material); BrMaterialUpdate(material, BR_MATU_ALL); + return material; } // IDA: br_material* __cdecl BrMaterialRemove(br_material *material) @@ -99,8 +100,9 @@ br_material_find_cbfn* BrMaterialFindHook(br_material_find_cbfn* hook) { // IDA: br_uint_32 __cdecl BrMaterialAddMany(br_material **items, int n) br_uint_32 BrMaterialAddMany(br_material** items, int n) { int i; - int r = 0; + int r; + r = 0; for (i = 0; i < n; i++) { BrRegistryAdd(&v1db.reg_materials, items[i]); BrMaterialUpdate(items[i], BR_MATU_ALL); @@ -169,6 +171,7 @@ br_uint_32 BrMapAddMany(br_pixelmap** items, int n) { int i; int r; + r = 0; for (i = 0; i < n; i++) { BrRegistryAdd(&v1db.reg_textures, items[i]); BrMapUpdate(items[i], 4095); @@ -233,7 +236,7 @@ br_table_find_cbfn* BrTableFindHook(br_table_find_cbfn* hook) { // IDA: br_uint_32 __cdecl BrTableAddMany(br_pixelmap **items, int n) br_uint_32 BrTableAddMany(br_pixelmap** items, int n) { int i; - int r; + int r = 0; for (i = 0; i < n; i++) { BrRegistryAdd(&v1db.reg_tables, items[i]); diff --git a/src/BRSRC13/br_types.h b/src/BRSRC13/br_types.h index d8203409..3ffe1141 100644 --- a/src/BRSRC13/br_types.h +++ b/src/BRSRC13/br_types.h @@ -1030,8 +1030,7 @@ typedef struct br_font { } br_font; #pragma pack(pop) -typedef struct br_object { -} br_object; +typedef struct br_object br_object; typedef struct br_token_value br_token_value; typedef struct br_value_tag { @@ -1155,8 +1154,7 @@ typedef struct br_outfcty_desc { br_boolean fullscreen; } br_outfcty_desc; -typedef struct br_renderer_facility { -} br_renderer_facility; +typedef struct br_renderer_facility br_renderer_facility; typedef struct br_device_pixelmap_dispatch br_device_pixelmap_dispatch; typedef struct br_device_pixelmap { // size: 0x44 @@ -1183,11 +1181,9 @@ typedef struct br_device_pixelmap { // size: 0x44 void* pm_stored; // @0x40 } br_device_pixelmap; -typedef struct br_primitive_library { -} br_primitive_library; +typedef struct br_primitive_library br_primitive_library; -typedef struct br_geometry { -} br_geometry; +typedef struct br_geometry br_geometry; typedef struct br_renderer_dispatch br_renderer_dispatch; @@ -1885,8 +1881,7 @@ typedef struct br_buffer_stored_dispatch { br_error (*_update)(br_buffer_stored*, br_device_pixelmap*, br_token_value*); } br_buffer_stored_dispatch; -typedef struct brp_vertex { -} brp_vertex; +typedef struct brp_vertex brp_vertex; typedef struct br_renderer_dispatch { void (*__reserved0)(br_object*); @@ -2251,8 +2246,7 @@ typedef struct br_primitive_state { br_primitive_state_dispatch* dispatch; } br_primitive_state; -typedef struct brp_block { -} brp_block; +typedef struct brp_block brp_block; typedef struct br_primitive_state_dispatch { void (*__reserved0)(br_object*); diff --git a/src/DETHRACE/common/flicplay.c b/src/DETHRACE/common/flicplay.c index a7e97e56..5ae60f9d 100644 --- a/src/DETHRACE/common/flicplay.c +++ b/src/DETHRACE/common/flicplay.c @@ -644,7 +644,7 @@ int StartFlic(char* pFile_name, int pIndex, tFlic_descriptor_ptr pFlic_info, tU3 } pFlic_info->the_index = pIndex; if (pDest_pixelmap) { - pFlic_info->first_pixel = pDest_pixelmap->pixels + pDest_pixelmap->row_bytes * pFlic_info->y_offset + pFlic_info->x_offset; + pFlic_info->first_pixel = (char*)pDest_pixelmap->pixels + pDest_pixelmap->row_bytes * pFlic_info->y_offset + pFlic_info->x_offset; } //LOG_DEBUG("first pixel %p %p", pFlic_info->first_pixel, pDest_pixelmap->pixels); pFlic_info->the_pixelmap = pDest_pixelmap; @@ -1156,6 +1156,8 @@ int PlayFlic(int pIndex, tU32 pSize, tS8* pData_ptr, br_pixelmap* pDest_pixelmap LOG_WARN("startflic returned error"); return -1; } + + last_frame = 0; while ((!pInterruptable || !AnyKeyDown()) && !finished_playing) { new_time = PDGetTotalTime(); frame_period = new_time - last_frame; diff --git a/src/DETHRACE/common/graphics.c b/src/DETHRACE/common/graphics.c index bb085aaa..370ed02f 100644 --- a/src/DETHRACE/common/graphics.c +++ b/src/DETHRACE/common/graphics.c @@ -420,7 +420,7 @@ void DRSetPaletteEntries(br_pixelmap* pPalette, int pFirst_colour, int pCount) { if (!pFirst_colour) { ((br_int_32*)pPalette->pixels)[0] = 0; } - memcpy(gCurrent_palette_pixels + 4 * pFirst_colour, pPalette->pixels + 4 * pFirst_colour, 4 * pCount); + memcpy(gCurrent_palette_pixels + 4 * pFirst_colour, (char*)pPalette->pixels + 4 * pFirst_colour, 4 * pCount); if (!gFaded_palette) { PDSetPaletteEntries(pPalette, pFirst_colour, pCount); } @@ -1029,8 +1029,8 @@ void DRPixelmapRectangleOnscreenCopy(br_pixelmap* pDest, br_int_16 pDest_x, br_i source_row_wrap = pSource->row_bytes - pWidth; dest_row_wrap = pDest->row_bytes - pWidth; - dest_ptr = pDest->pixels + (pDest->row_bytes * pDest_y + pDest_x); - source_ptr = pSource->pixels + (pSource->row_bytes * pSource_y + pSource_x); + dest_ptr = (char*)pDest->pixels + (pDest->row_bytes * pDest_y + pDest_x); + source_ptr = (char*)pSource->pixels + (pSource->row_bytes * pSource_y + pSource_x); for (y_count = 0; y_count < pHeight; y_count++) { for (x_count = 0; x_count < pWidth; x_count++) { @@ -1086,8 +1086,8 @@ void DRPixelmapRectangleVScaledCopy(br_pixelmap* pDest, br_int_16 pDest_x, br_in source_row_wrap = pSource->row_bytes - pWidth; dest_row_wrap = pDest->row_bytes - pWidth; - dest_ptr = pDest->pixels + (pDest->row_bytes * pDest_y + pDest_x); - source_ptr = pSource->pixels + (pSource->row_bytes * pSource_y + pSource_x); + dest_ptr = (char*)pDest->pixels + (pDest->row_bytes * pDest_y + pDest_x); + source_ptr = (char*)pSource->pixels + (pSource->row_bytes * pSource_y + pSource_x); source_y = 0; source_y_delta = (pSource->height << 16) / pHeight - 0x10000; diff --git a/src/DETHRACE/common/input.c b/src/DETHRACE/common/input.c index d169581b..4b76db95 100644 --- a/src/DETHRACE/common/input.c +++ b/src/DETHRACE/common/input.c @@ -461,7 +461,7 @@ void RollLettersIn() { if (which_letter < let->number_of_letters && which_letter >= 0 && letter_offset >= 0 && letter_offset < font_height) { // LOG_DEBUG("chars %d, %d, %d, %d", let->letters[0], let->letters[1], let->letters[2], let->letters[3]); - source_ptr = gFonts[FONT_TYPEABLE].images->pixels + (font_height * (let->letters[which_letter] - 32) + letter_offset) * the_row_bytes; + source_ptr = (char*)gFonts[FONT_TYPEABLE].images->pixels + (font_height * (let->letters[which_letter] - 32) + letter_offset) * the_row_bytes; for (k = 0; k < font_width; k++) { the_byte = *source_ptr; if (the_byte) { diff --git a/src/DETHRACE/common/intrface.c b/src/DETHRACE/common/intrface.c index 6e61f812..ac07bd8d 100644 --- a/src/DETHRACE/common/intrface.c +++ b/src/DETHRACE/common/intrface.c @@ -213,6 +213,7 @@ int DoInterfaceScreen(tInterface_spec* pSpec, int pOptions, int pCurrent_choice) pSpec->start_proc2(); } + copy_areas = NULL; if (pSpec->number_of_recopy_areas) { copy_areas = BrMemAllocate(sizeof(void*) * pSpec->number_of_recopy_areas, kMem_intf_copy_areas); for (i = 0; i < pSpec->number_of_recopy_areas; i++) { @@ -232,8 +233,9 @@ int DoInterfaceScreen(tInterface_spec* pSpec, int pOptions, int pCurrent_choice) pSpec->recopy_areas[i].bottom[gGraf_data_index] - pSpec->recopy_areas[i].top[gGraf_data_index]); } - timed_out = -1; + timed_out = -1; /* Not sure this is right, timed_out looks like its used as a bool? */ last_choice = gCurrent_choice; + last_press = -1; do { if (last_choice != gCurrent_choice) { ChangeSelection(pSpec, &last_choice, &gCurrent_choice, gCurrent_mode, 1); diff --git a/src/DETHRACE/common/loading.c b/src/DETHRACE/common/loading.c index be49f5ae..379a296c 100644 --- a/src/DETHRACE/common/loading.c +++ b/src/DETHRACE/common/loading.c @@ -745,7 +745,7 @@ tS8* ConvertPixToStripMap(br_pixelmap* pThe_br_map) { current_strip_pointer = temp_strip_image; for (i = 0; i < pThe_br_map->height; i++) { - next_byte = pThe_br_map->pixels + i * pThe_br_map->row_bytes; //points to start of this line + next_byte = (char*)pThe_br_map->pixels + i * pThe_br_map->row_bytes; //points to start of this line new_line_length = 2; // leave space at the start of the line to store number of chunks and first chunk length j = 0; counter = 0; diff --git a/src/DETHRACE/dr_types.h b/src/DETHRACE/dr_types.h index de6720b0..9dbb886f 100644 --- a/src/DETHRACE/dr_types.h +++ b/src/DETHRACE/dr_types.h @@ -18,6 +18,9 @@ typedef __iobuf FILE; typedef long fpos_t; typedef void * onexit_t(); */ +#ifdef _WIN32 +#include +#else typedef short SHORT; typedef unsigned short USHORT; typedef int INT; @@ -25,8 +28,6 @@ typedef int BOOL; typedef unsigned int UINT; typedef unsigned char BYTE; typedef unsigned short WORD; -typedef unsigned int W32; -typedef unsigned short W16; typedef long LONG; typedef unsigned long DWORD; typedef BYTE* PBYTE; @@ -38,7 +39,6 @@ typedef void* PVOID; typedef BYTE* LPBYTE; typedef BYTE* LPSTR; typedef WORD* LPWORD; -typedef W32* LPW32; typedef LONG* LPLONG; typedef void* LPVOID; typedef BYTE* HPBYTE; @@ -46,6 +46,10 @@ typedef BYTE* HPSTR; typedef LONG* HPLONG; typedef void* HPVOID; typedef unsigned int HANDLE; +#endif +typedef unsigned int W32; +typedef unsigned short W16; +typedef W32* LPW32; typedef struct _tagRMI_REGS _RMI_REGS; typedef struct _tagBREGS _HMI_BREGS; typedef struct _tagWREGS _HMI_WREGS; @@ -3046,11 +3050,13 @@ typedef struct SmackSumTag { unsigned long HighestExtraUsed; } SmackSum; +#ifndef _WIN32 typedef struct _heapinfo { void* _pentry; size_t _size; int _useflag; } _HEAPINFO; +#endif typedef enum tSpec_vol_depth_effect { eSpec_dep_acid = 0, @@ -4262,12 +4268,14 @@ typedef struct find_t { char name[13]; } find_t; +#ifndef _WIN32 typedef struct _diskfree_t { unsigned short total_clusters; unsigned short avail_clusters; unsigned short sectors_per_cluster; unsigned short bytes_per_sector; } _diskfree_t; +#endif typedef struct tPD_net_game_info { _IPX_LOCAL_TARGET addr_ipx; diff --git a/src/DETHRACE/pc-dos/dossys.c b/src/DETHRACE/pc-dos/dossys.c index 6dc953d9..ce622a20 100644 --- a/src/DETHRACE/pc-dos/dossys.c +++ b/src/DETHRACE/pc-dos/dossys.c @@ -20,6 +20,33 @@ #include #include +#ifdef _WIN32 +#define NS_PER_SEC (1000ULL * 1000ULL * 1000ULL) +#define CLOCK_MONOTONIC 1 + +int clock_gettime(int dummy, struct timespec* tv) { + static LARGE_INTEGER ticksPerSec; + LARGE_INTEGER ticks; + double seconds; + + if (!ticksPerSec.QuadPart) { + QueryPerformanceFrequency(&ticksPerSec); + if (!ticksPerSec.QuadPart) { + errno = ENOTSUP; + return -1; + } + } + + QueryPerformanceCounter(&ticks); + + seconds = (double)ticks.QuadPart / (double)ticksPerSec.QuadPart; + tv->tv_sec = (time_t)seconds; + tv->tv_nsec = (long)((ULONGLONG)(seconds * NS_PER_SEC) % NS_PER_SEC); + + return 0; +} +#endif + int gASCII_table[128]; tU32 gKeyboard_bits[8]; int gASCII_shift_table[128]; @@ -497,7 +524,7 @@ void PDSetPalette(br_pixelmap* pThe_palette) { void PDSetPaletteEntries(br_pixelmap* pPalette, int pFirst_colour, int pCount) { int i; tU8* p; - p = pPalette->pixels + 4 * pFirst_colour; + p = (char*)pPalette->pixels + 4 * pFirst_colour; for (i = pFirst_colour; i < pFirst_colour + pCount; i++) { BrDevPaletteSetEntryOld(i, (p[2] << 16) | (p[1] << 8) | *p); p += 4; diff --git a/src/DETHRACE/watcom_functions.c b/src/DETHRACE/watcom_functions.c index edefb153..b8f75887 100644 --- a/src/DETHRACE/watcom_functions.c +++ b/src/DETHRACE/watcom_functions.c @@ -16,7 +16,7 @@ void splitpath(char* path, char* drive, char* dir, char* fname, char* ext) { #if defined(_WIN32) || defined(_WIN64) - _splitpath(path, drive, dr, fname, ext); + _splitpath(path, drive, dir, fname, ext); #else // shortcut - we only ever call this method asking for 'fname' // 9 is hardcoded to match `basename` defined in `Usage` diff --git a/src/harness/debug.h b/src/harness/debug.h index 6c45fd51..1e3da8e0 100644 --- a/src/harness/debug.h +++ b/src/harness/debug.h @@ -4,6 +4,10 @@ #include #include +#if defined _WIN32 && !defined sleep + #define sleep(x) _sleep(x) +#endif + #define BLUE #define LOG_TRACE(...) debug_printf("[TRACE] %s", __FUNCTION__, __VA_ARGS__) diff --git a/src/harness/harness.h b/src/harness/harness.h index 63652e75..41f670df 100644 --- a/src/harness/harness.h +++ b/src/harness/harness.h @@ -3,7 +3,7 @@ #include "br_types.h" #include "debug.h" -#include +#include #define COUNT_OF(array) (sizeof((array)) / sizeof((array)[0])) diff --git a/src/harness/input/keyboard.c b/src/harness/input/keyboard.c index d1a82314..b7960e77 100644 --- a/src/harness/input/keyboard.c +++ b/src/harness/input/keyboard.c @@ -1,5 +1,5 @@ #include "dr_types.h" -#include +#include #include "keyboard.h" diff --git a/src/harness/renderers/gl_renderer.c b/src/harness/renderers/gl_renderer.c index d1d75a76..8c8de7cb 100644 --- a/src/harness/renderers/gl_renderer.c +++ b/src/harness/renderers/gl_renderer.c @@ -2,6 +2,7 @@ #include "harness.h" #ifdef _WIN32 +#include #include #elif defined __unix__ #define GL_GLEXT_PROTOTYPES 1 @@ -10,7 +11,7 @@ #define GL_SILENCE_DEPRECATION #include #endif -#include +#include tRenderer OpenGLRenderer = { Harness_GLRenderer_GetWindowFlags, diff --git a/src/harness/renderers/gl_renderer.h b/src/harness/renderers/gl_renderer.h index 028a286b..2388f0c2 100644 --- a/src/harness/renderers/gl_renderer.h +++ b/src/harness/renderers/gl_renderer.h @@ -2,7 +2,7 @@ #define HARNESS_GL_RENDERER #include "harness.h" -#include +#include extern tRenderer OpenGLRenderer; diff --git a/src/harness/stack_trace_handler.h b/src/harness/stack_trace_handler.h index f30eb18f..2fc4c070 100644 --- a/src/harness/stack_trace_handler.h +++ b/src/harness/stack_trace_handler.h @@ -14,6 +14,11 @@ #ifdef _WIN32 #include #include +#ifdef _WIN64 +#define Esp Rsp +#define Eip Rip +#define Ebp Rbp +#endif #else #include #include