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.
This commit is contained in:
OmniBlade 2021-02-16 12:48:29 +01:00
parent 9bbf3028f3
commit efb3484b79
18 changed files with 81 additions and 35 deletions

View File

@ -50,7 +50,7 @@ br_resource_class fw_resourceClasses[25] = {
br_uint_16 nameOrdinals_BRCORE1[185];
br_image Image_BRCORE1 = {
{},
{0},
"BRCORE1",
2,
0,

View File

@ -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);

View File

@ -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]);

View File

@ -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*);

View File

@ -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;

View File

@ -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;

View File

@ -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) {

View File

@ -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);

View File

@ -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;

View File

@ -18,6 +18,9 @@ typedef __iobuf FILE;
typedef long fpos_t;
typedef void * onexit_t();
*/
#ifdef _WIN32
#include <windows.h>
#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;

View File

@ -20,6 +20,33 @@
#include <time.h>
#include <unistd.h>
#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;

View File

@ -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`

View File

@ -4,6 +4,10 @@
#include <stdlib.h>
#include <unistd.h>
#if defined _WIN32 && !defined sleep
#define sleep(x) _sleep(x)
#endif
#define BLUE
#define LOG_TRACE(...) debug_printf("[TRACE] %s", __FUNCTION__, __VA_ARGS__)

View File

@ -3,7 +3,7 @@
#include "br_types.h"
#include "debug.h"
#include <SDL2/SDL.h>
#include <SDL.h>
#define COUNT_OF(array) (sizeof((array)) / sizeof((array)[0]))

View File

@ -1,5 +1,5 @@
#include "dr_types.h"
#include <SDL2/SDL.h>
#include <SDL.h>
#include "keyboard.h"

View File

@ -2,6 +2,7 @@
#include "harness.h"
#ifdef _WIN32
#include <windows.h>
#include <gl/gl.h>
#elif defined __unix__
#define GL_GLEXT_PROTOTYPES 1
@ -10,7 +11,7 @@
#define GL_SILENCE_DEPRECATION
#include <OpenGL/gl3.h>
#endif
#include <SDL2/SDL_opengl.h>
#include <SDL_opengl.h>
tRenderer OpenGLRenderer = {
Harness_GLRenderer_GetWindowFlags,

View File

@ -2,7 +2,7 @@
#define HARNESS_GL_RENDERER
#include "harness.h"
#include <SDL2/SDL.h>
#include <SDL.h>
extern tRenderer OpenGLRenderer;

View File

@ -14,6 +14,11 @@
#ifdef _WIN32
#include <imagehlp.h>
#include <windows.h>
#ifdef _WIN64
#define Esp Rsp
#define Eip Rip
#define Ebp Rbp
#endif
#else
#include <err.h>
#include <execinfo.h>