Skip to content

Instantly share code, notes, and snippets.

@Bijman
Created August 25, 2025 18:38
Show Gist options
  • Select an option

  • Save Bijman/d898108c1b3d60627cb6845aae4a694c to your computer and use it in GitHub Desktop.

Select an option

Save Bijman/d898108c1b3d60627cb6845aae4a694c to your computer and use it in GitHub Desktop.
diff --git a/Code/CMakeLists.txt b/Code/CMakeLists.txt
index a0764a7..2c8ec32 100644
--- a/Code/CMakeLists.txt
+++ b/Code/CMakeLists.txt
@@ -90,14 +90,16 @@ include_directories(
)
target_link_libraries(${PROJECT_NAME} PRIVATE
- ${SDL2_LIBRARIES}
+ SDL2::SDL2main
SDL2_mixer::SDL2_mixer
+ ${SDL2_LIBRARIES}
m
+ winmm
)
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<C_COMPILER_ID:GNU,Clang>:
- -DLINUX
+ -D__WIN32__
-DHAVE_SDL
-DHAVE_SDL_MIXER
-fPIE
diff --git a/Code/byteptr.h b/Code/byteptr.h
index 38eba78..c507bb6 100644
--- a/Code/byteptr.h
+++ b/Code/byteptr.h
@@ -16,25 +16,29 @@
/// \file
/// \brief Macros to read/write from/to a char*, used for packet creation and such
#ifdef WIN32
-#define WRITEBYTE(p,b) *((byte *)p)++ = b
-#define WRITECHAR(p,b) *((char *)p)++ = b
-#define WRITESHORT(p,b) *((short *)p)++ = b
-#define WRITEUSHORT(p,b) *((USHORT *)p)++ = b
-#define WRITELONG(p,b) *((long *)p)++ = b
-#define WRITEULONG(p,b) *((ULONG *)p)++ = b
-#define WRITEFIXED(p,b) *((fixed_t*)p)++ = b
-#define WRITESTRING(p,b) { int tmp_i=0; do { WRITECHAR(p,b[tmp_i]); } while(b[tmp_i++]); }
-#define WRITESTRINGN(p,b,n) { int tmp_i=0; do { WRITECHAR(p,b[tmp_i]); if(!b[tmp_i]) break;tmp_i++; } while(tmp_i<n); }
+#define WRITEBYTE(p,b) do { byte* _p = (byte*)(p); *_p = (byte)(b); (p) = (void*)(_p + 1); } while (0)
+#define WRITECHAR(p,b) do { char* _p = (char*)(p); *_p = (char)(b); (p) = (void*)(_p + 1); } while (0)
+#define WRITESHORT(p,b) do { short* _p = (short*)(p); *_p = (short)(b); (p) = (void*)(_p + 1); } while (0)
+#define WRITEUSHORT(p,b) do { USHORT* _p = (USHORT*)(p); *_p = (USHORT)(b); (p) = (void*)(_p + 1); } while (0)
+#define WRITELONG(p,b) do { long* _p = (long*)(p); *_p = (long)(b); (p) = (void*)(_p + 1); } while (0)
+#define WRITEULONG(p,b) do { ULONG* _p = (ULONG*)(p); *_p = (ULONG)(b); (p) = (void*)(_p + 1); } while (0)
+#define WRITEFIXED(p,b) do { fixed_t* _p = (fixed_t*)(p); *_p = (fixed_t)(b); (p) = (void*)(_p + 1); } while (0)
-#define READBYTE(p) *((byte *)p)++
-#define READCHAR(p) *((char *)p)++
-#define READSHORT(p) *((short *)p)++
-#define READUSHORT(p) *((USHORT *)p)++
-#define READLONG(p) *((long *)p)++
-#define READULONG(p) *((ULONG *)p)++
-#define READFIXED(p) *((fixed_t*)p)++
-#define READSTRING(p,s) { int tmp_i=0; do { s[tmp_i]=READBYTE(p); } while(s[tmp_i++]); }
-#define SKIPSTRING(p) while(READBYTE(p))
+#define WRITESTRING(p,b) { int _i = 0; do { WRITECHAR(p, b[_i]); } while (b[_i++]); }
+#define WRITESTRINGN(p,b,n) { int _i = 0; do { WRITECHAR(p, b[_i]); if (!b[_i]) break; _i++; } while (_i < (n)); }
+
+#define READBYTE(p) (*({ byte* _p = (byte*)(p); (p) = (void*)(_p + 1); _p; }))
+#define READCHAR(p) (*({ char* _p = (char*)(p); (p) = (void*)(_p + 1); _p; }))
+#define READSHORT(p) (*({ short* _p = (short*)(p); (p) = (void*)(_p + 1); _p; }))
+#define READUSHORT(p) (*({ USHORT* _p = (USHORT*)(p); (p) = (void*)(_p + 1); _p; }))
+#define READLONG(p) (*({ long* _p = (long*)(p); (p) = (void*)(_p + 1); _p; }))
+#define READULONG(p) (*({ ULONG* _p = (ULONG*)(p); (p) = (void*)(_p + 1); _p; }))
+#define READFIXED(p) (*({ fixed_t* _p = (fixed_t*)(p); (p) = (void*)(_p + 1); _p; }))
+
+#define READSTRING(p,s) { int _i = 0; do { s[_i] = READBYTE(p); } while (s[_i++] != 0); }
+#define SKIPSTRING(p) while (READBYTE(p))
+
+#define READMEM(p,s,n) do { memcpy((s), (p), (n)); (p) = (void*)((byte*)(p) + (n)); } while (0)
#else
#ifndef __BIG_ENDIAN__
//
@@ -191,4 +195,4 @@ static inline double readouble(void * ptr)
#define SKIPSTRING(p) while(READBYTE(p))
#define READMEM(p,s,n) memcpy(s, p, n);p+=n
#endif //__BIG_ENDIAN__
-#endif
\ No newline at end of file
+#endif
diff --git a/Code/console.c b/Code/console.c
index c8bf762..86d38ea 100644
--- a/Code/console.c
+++ b/Code/console.c
@@ -19,7 +19,7 @@
#include "doomstat.h"
#ifdef __WIN32__
-#include "win32/win_main.h"
+#include "WIN32/WIN_MAIN.H"
void I_LoadingScreen ( LPCSTR msg );
#endif
diff --git a/Code/d_main.c b/Code/d_main.c
index 272b860..ccd8cc7 100644
--- a/Code/d_main.c
+++ b/Code/d_main.c
@@ -5,6 +5,7 @@
// parse command line parameters, configure game parameters (turbo),
// and call the startup functions.
+#include <dirent.h>
#ifndef __WIN32__
#include <dirent.h> // for dirent, readdir
#include <unistd.h> // for access
diff --git a/Code/d_main.h b/Code/d_main.h
index 3acb194..828a467 100644
--- a/Code/d_main.h
+++ b/Code/d_main.h
@@ -1,14 +1,9 @@
// d_main.h : game startup, and main loop code, system specific
-
+#include <sys/types.h>
#ifndef __D_MAIN__
#define __D_MAIN__
-#ifdef _WIN32
-typedef unsigned int mode_t;
-#endif
-
-
#include "d_event.h"
#include "w_wad.h" // for MAX_WADFILES
diff --git a/Code/sdl2/i_main.c b/Code/sdl2/i_main.c
index d91f3fa..053b189 100644
--- a/Code/sdl2/i_main.c
+++ b/Code/sdl2/i_main.c
@@ -7,11 +7,7 @@ int mb_used = 32;
SDL_RWops* logstream;
-#ifndef FORCESDLMAIN
-int main(int argc, char **argv)
-#else
int SDL_main(int argc, char** argv)
-#endif
{
myargc = argc;
myargv = argv; /// \todo pull out path to exe from this string
@@ -45,4 +41,4 @@ void I_FPrintf(char* lpFmt, ...)
va_end(arglist);
SDL_RWwrite(logstream, &str, sizeof(char), strlen(str));
-}
\ No newline at end of file
+}
diff --git a/Code/w_wad.c b/Code/w_wad.c
index 9382840..12c215e 100644
--- a/Code/w_wad.c
+++ b/Code/w_wad.c
@@ -3,7 +3,7 @@
// added for linux 19990220 by Kin
#ifdef LINUX
#define O_BINARY 0
-#include <linux/limits.h>
+#include <limits.h>
#include <dirent.h>
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment