Skip to content

Commit

Permalink
Restructure the code for better library builds, and improvements to x…
Browse files Browse the repository at this point in the history
…64 builds
  • Loading branch information
Danaozhong committed Dec 15, 2024
1 parent ca57c3b commit f0ff8fb
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 81 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Set the configuration for the assembler
if (${BUILD_32BIT})
if(MSVC)
# Nothing to do - MSVC supports building 32bit using a different cmake invokation
# Nothing to do - MSVC supports building 32bit using a different cmake invocation
else()
# Set this flag for the compiler and linker
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
endif()

# tell the assembler to generate 32 bit files
if (WIN32)
set(CMAKE_ASM_NASM_OBJECT_FORMAT win32)
Expand Down
63 changes: 14 additions & 49 deletions glide3x/h5/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
set (GLIDE_H5_DIR ${CMAKE_SOURCE_DIR}/glide3x/h5)

set (CINIT_DIR ${GLIDE_H5_DIR}/cinit)

set (MINIHWC_DIR ${GLIDE_H5_DIR}/minihwc)
add_subdirectory(incsrc)
add_subdirectory(cinit)
add_subdirectory(minihwc)

set(GLIDE_SOURCES
${GLIDE_H5_DIR}/glide3/src/fifo.c
Expand Down Expand Up @@ -34,7 +34,6 @@ set(GLIDE_SOURCES
)



set(GLIDE_SOURCES ${GLIDE_SOURCES}
# We always use the C routines for drawing triangles, never the asm or 3dnow ones
${GLIDE_H5_DIR}/glide3/src/gxdraw.c
Expand All @@ -47,42 +46,18 @@ if(WIN32)
${GLIDE_H5_DIR}/glide3/src/gsfc.c
${GLIDE_H5_DIR}/glide3/src/winsurf.c
)

set(GLIDE_OUTSIDE_SOURCES ${GLIDE_OUTSIDE_SOURCES}
${MINIHWC_DIR}/hwcio.c
${MINIHWC_DIR}/gdebug.c
${MINIHWC_DIR}/minihwc.c
${MINIHWC_DIR}/win_mode.c
)
if (${BUILD_32BIT})
# This code is anyway only relevant for Win9x, and can be excluded for x64 builds.
set (GLIDE_ASM_SOURCES ${GLIDE_ASM_SOURCES}
${MINIHWC_DIR}/win9x.asm
)
endif()
else()
# Linux build
set(GLIDE_OUTSIDE_SOURCES ${GLIDE_OUTSIDE_SOURCES}
${MINIHWC_DIR}/hwcio.c
${MINIHWC_DIR}/gdebug.c

set(GLIDE_OUTSIDE_SOURCES ${GLIDE_OUTSIDE_SOURCES}
${FXMISC_DIR}/fxos.c
${FXMISC_DIR}/fximg.c
)


if (${USE_DRI})
set(GLIDE_OUTSIDE_SOURCES ${GLIDE_OUTSIDE_SOURCES}
${FXMISC_DIR}/linhwc.c
${FXMISC_DIR}/linutil.c
)
else()
set(GLIDE_OUTSIDE_SOURCES ${GLIDE_OUTSIDE_SOURCES}
${MINIHWC_DIR}/minihwc.c
${MINIHWC_DIR}/lin_mode.c
${MINIHWC_DIR}/gpio.c
${CINIT_DIR}/h3cinit.c
)
endif()
endif()

Expand All @@ -93,18 +68,19 @@ add_library(${CMAKE_PROJECT_NAME} SHARED
${GLIDE_SOURCES}
${GLIDE_OUTSIDE_SOURCES}
${GLIDE_ASM_SOURCES}
)
)

target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
${GLIDE_H5_DIR}/glide3/src
${GLIDE_H5_DIR}/incsrc
${GLIDE_H5_DIR}/init
${GLIDE_H5_DIR}/minihwc
${CINIT_DIR}
)

target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC
pcilib
cinit
h3
minihwc
)

if (${EMBED_TEXUS2})
Expand Down Expand Up @@ -133,12 +109,9 @@ target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC
-DUSE_PACKET_FIFO=1
-DGLIDE_CHECK_CONTEXT

# subsystem
-DH3
-DH4
-DFX_GLIDE_H5_CSIM=1
-DFX_GLIDE_NAPALM=1

# Do not use the ASM routines, but the C triangle setup routines instead, even when building x86
-DGLIDE_USE_C_TRISETUP

# other
-DGLIDE_PLUG
-DGLIDE_SPLASH
Expand All @@ -156,30 +129,22 @@ if (${BUILD_32BIT})
-DGL_X86
)
else()
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC
-DGLIDE_BUILD_64BIT
# Do not use the ASM routines, but the C triangle setup routines instead
-DGLIDE_USE_C_TRISETUP
)

#target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC
# -DGLIDE_BUILD_64BIT
#)
endif()


if(WIN32)
# Windows-only defines
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC
-D__WIN32__
-DFX_DLL_ENABLE
-DHWC_ACCESS_DDRAW=1
-DHWC_EXT_INIT=1
-DGLIDE_ALT_TAB=1

-DBETA=1
-DHWC_MINIVDD_HACK=1
-DWIN40COMPAT=1
-DWINXP_ALT_TAB_FIX=1
-DWINXP_SAFER_ALT_TAB_FIX=1
-DNEED_MSGFILE_ASSIGN
)

# Windows build uses DirectDraw to detect possible screen resolutions and prepare
Expand Down
9 changes: 9 additions & 0 deletions glide3x/h5/cinit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
add_library(cinit
h3cinit.c
)
target_include_directories(cinit PUBLIC .)
target_link_libraries(cinit PUBLIC
fxmisc
h3
)

3 changes: 2 additions & 1 deletion glide3x/h5/cinit/h3cinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@
*/

#include <h3cinit.h>
#include <h3.h>
#include <h3regs.h>
#include <h3defs.h>

#include "h3cinitdd.h"

Expand Down
18 changes: 15 additions & 3 deletions glide3x/h5/glide3/src/fxglide.h
Original file line number Diff line number Diff line change
Expand Up @@ -2151,7 +2151,7 @@ extern struct _GlideRoot_s GR_CDECL _GlideRoot;
extern GrGCFuncs _curGCFuncs;
#endif

#if defined( _MSC_VER)
#if defined( _MSC_VER) && !defined(_WIN64)
/* Turn off the no return value warning for the function definition.
*
* NB: The function returns a value so that we can use it in places
Expand All @@ -2168,6 +2168,8 @@ extern GrGCFuncs _curGCFuncs;
}
# define P6FENCE _grP6Fence()
# pragma warning(default : 4035)
#elif defined( _MSC_VER) && defined(_WIN64)
#define P6FENCE _mm_sfence()
#elif defined(macintosh) && defined(__POWERPC__) && defined(__MWERKS__)
# define P6FENCE __sync()
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
Expand Down Expand Up @@ -2314,6 +2316,10 @@ _trisetup_noclip_valid(const void *va, const void *vb, const void *vc );
#define TRISETUP_ARGB(__cullMode) TRISETUP_NORGB(__cullMode)

#if defined(_MSC_VER)
#if defined(_WIN64)
#define TRISETUP \
(*gc->triSetupProc)
#else /* defined(_WIN64) */
#if defined(GLIDE_DEBUG) || GLIDE_USE_C_TRISETUP
/* MSVC6 Debug does funny stuff, so push our parms inline */
#define TRISETUP(_a, _b, _c) \
Expand All @@ -2332,6 +2338,7 @@ _trisetup_noclip_valid(const void *va, const void *vb, const void *vc );
__asm { mov edx, gc }; \
((FxI32 (*)(const void *va, const void *vb, const void *vc, GrGC *gc))*gc->triSetupProc)(_a, _b, _c, gc)
#endif
#endif

#elif defined(__POWERPC__)
#define TRISETUP(_a, _b, _c) \
Expand Down Expand Up @@ -2762,7 +2769,12 @@ static __inline unsigned long getThreadValueFast (void)
}

#else /* __GNUC__ */

#ifdef _WIN64
inline unsigned long
getThreadValueFast() {
return (unsigned long)TlsGetValue(_GlideRoot.tlsIndex);
}
#else // below is for 32 bit systems
#pragma warning (4:4035) /* No return value */
__inline unsigned long
getThreadValueFast() {
Expand All @@ -2772,7 +2784,7 @@ getThreadValueFast() {
__asm mov eax, DWORD PTR [eax]
}
}

#endif /* _WIN64 */
#endif /* __GNUC__ */
#endif

Expand Down
7 changes: 7 additions & 0 deletions glide3x/h5/incsrc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_library(h3 INTERFACE)
target_include_directories(h3 INTERFACE .)
target_link_libraries(h3 INTERFACE
fxmisc
pcilib
)

58 changes: 58 additions & 0 deletions glide3x/h5/minihwc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
if(WIN32)
set(MINIHWC_OS_SPECIFIC_SOURCES
win_mode.c
)
else ()
set(MINIHWC_OS_SPECIFIC_SOURCES
lin_mode.c
linhwc.c
gpio.c
)
endif()

if (${BUILD_32BIT})
# This code is anyway only relevant for Win9x, and can be excluded for x64 builds.
set (MINHWC_ASM_SOURCES ${MINHWC_ASM_SOURCES}
win9x.asm
)
endif()

add_library(minihwc
${MINHWC_ASM_SOURCES}
${MINIHWC_OS_SPECIFIC_SOURCES}
hwcio.c
gdebug.c
minihwc.c
)

if (${BUILD_32BIT})
# 32 bit compilation
target_compile_definitions(minihwc PUBLIC
-DGL_X86
)
endif()

if(WIN32)
# Windows-only defines
target_compile_definitions(minihwc PUBLIC
-D__WIN32__
-DHWC_ACCESS_DDRAW=1
-DHWC_EXT_INIT=1
-DHWC_MINIVDD_HACK=1
)
endif()


target_compile_definitions(minihwc PUBLIC
# subsystem
-DH3
-DH4
-DFX_GLIDE_H5_CSIM=1
-DFX_GLIDE_NAPALM=1

)


target_include_directories(minihwc PUBLIC .)

target_link_libraries(minihwc PUBLIC fxmisc h3 glide_common)
24 changes: 7 additions & 17 deletions glide3x/h5/minihwc/gdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,15 @@ char *hwcGetenv (const char *a);


/*
* For linux, we cannot statically initialize gdbg_msgfile
* to stderr. In linux, stderr is not constant. The same
* would be true of stdout for that matter. So, we initialize
* gdbg_msgfile to NULL and then initialize it to stderr
* below. There are two dfns here, one for the static dfn
* and one for the dynamic dfn. For linux they are different.
* For Windows they are the same.
* We cannot statically initialize gdbg_msgfile
* to stderr. In linux, stderr is not constant. The same
* would be true of stdout for that matter. So, we initialize
* gdbg_msgfile to NULL and then initialize it to stderr/stdout
* below.
*/
#if defined(__linux__) || defined(__FreeBSD__)
#define INITIAL_STATIC_GDBG_MSGFILE NULL
#define INITIAL_GDBG_MSGFILE stderr
#else
#ifdef NEED_MSGFILE_ASSIGN
#define INITIAL_STATIC_GDBG_MSGFILE NULL
#else
#define INITIAL_STATIC_GDBG_MSGFILE stdout
#endif
#define INITIAL_GDBG_MSGFILE stdout
#endif

Expand Down Expand Up @@ -119,11 +111,11 @@ extern int __cdecl klvfprintf(FILE *stream,
va_list arg ) ;
#endif

static FILE *gdbg_msgfile; // GDBG info/error file
static FILE *gdbg_msgfile = NULL; // GDBG info/error file

#else /* #ifdef KERNEL */

static FILE *gdbg_msgfile = INITIAL_STATIC_GDBG_MSGFILE; // GDBG info/error file
static FILE* gdbg_msgfile = NULL; // GDBG info/error file


//----------------------------------------------------------------------
Expand Down Expand Up @@ -187,9 +179,7 @@ void gdbg_init_gdbg_msgfile(void)
static int done=0; // only execute once
if (done)return;
done = 1;
#ifdef NEED_MSGFILE_ASSIGN
gdbg_msgfile = INITIAL_GDBG_MSGFILE;
#endif
}

FX_EXPORT void FX_CSTYLE
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions glide3x/h5/minihwc/lin_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ static XDGAMode *vidModes = 0;
#include <minihwc.h>
#include <hwcio.h>
#include "h3cinit.h"
#include "glide.h"
#include "fxglide.h"
#include "glidesys.h"


#define CFG_FILE "/etc/conf.3dfx/voodoo3"
Expand Down
Loading

0 comments on commit f0ff8fb

Please sign in to comment.