Skip to content

Commit

Permalink
Implements win95sys.c (#301)
Browse files Browse the repository at this point in the history
* refactor to use win95sys instead of dossys

* added underscore to avoid conflict with windows functions
  • Loading branch information
dethrace-labs committed Apr 18, 2023
1 parent d4fb640 commit ef9e4d6
Show file tree
Hide file tree
Showing 52 changed files with 2,996 additions and 1,585 deletions.
27 changes: 6 additions & 21 deletions docs/PORTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
Assuming an operating system called _foo_, follow the steps to add support for it.

1. Add a new file `os/foo.h` and implement the required functions defined in [os.h](https://github.com/dethrace-labs/dethrace/blob/main/src/harness/include/harness/os.h):
- `OS_GetTime`
- `OS_Sleep`
- `OS_Basename`
- `OS_GetFirstFileInDirectory`
- `OS_GetNextFileInDirectory`
- `OS_IsDebuggerPresent`
- `OS_InstallSignalHandler`
- `OS_fopen`
- `OS_ConsoleReadPassword`

2. Update `src/harness/CMakeLists.h` and add a new conditional section for "os/foo.h", based on existing conditions for Windows, MacOS etc.

Expand All @@ -28,24 +24,13 @@ target_sources(harness PRIVATE

## IO Platform (windowing / input / rendering)

An `IOPlatform` in _dethrace_ implements windowing and input handling, and points to a _renderer_.
A `Platform` in _dethrace_ implements windowing, rendering and input handling.

The default IO platform is `SDL_OpenGL`, which uses SDL for windowing and input, and OpenGL for rendering. See [io_platforms/sdl_gl.c](https://github.com/dethrace-labs/dethrace/blob/main/src/harness/io_platforms/sdl_gl.c).
The default platform is `SDL_OpenGL`, which uses SDL for windowing and input, and OpenGL for rendering. See [platforms/sdl_opengl.c](https://github.com/dethrace-labs/dethrace/blob/main/src/harness/platforms/sdl_opengl.c).

To add a new `IOPlatform`:
To add a new `Platform`:

1. Create `io_platforms/my_platform.c` file and implement the required functions defined in [io_platforms/io_platform.h](https://github.com/dethrace-labs/dethrace/blob/main/src/harness/io_platforms/io_platform.h):
- `IOPlatform_Init`
- `IOPlatform_CreateWindow`
- `IOPlatform_PollEvents`
- `IOPlatform_SwapWindow`
- `IOPlatform_GetKeyMap`
- `IOPlatform_IsKeyDown`
- `IOPlatform_GetMousePosition`
- `IOPlatform_GetMouseButtons`
- `IOPlatform_Shutdown`

`IOPlatform_CreateWindow` returns a `tRenderer*`, which must implement the interface defined in [renderers/renderer.h](https://github.com/dethrace-labs/dethrace/blob/main/src/harness/renderers/renderer.h). See [renderers/gl](https://github.com/dethrace-labs/dethrace/tree/main/src/harness/renderers/gl) for an example.
1. Create `platforms/my_platform.c` file and add a `Harness_Platform_Init` function. Hook up all the function pointers using the `sdl_opengl` [implementation](https://github.com/dethrace-labs/dethrace/blob/main/src/harness/platforms/sdl_opengl.h) as a guide.

2. Add a new conditional section in `src/harness/CMakeLists.txt` for your new platform

Expand Down
4 changes: 2 additions & 2 deletions src/BRSRC13/CORE/FW/devsetup.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ void BrDevEndOld() {

// IDA: void __cdecl BrDevPaletteSetOld(br_pixelmap *pm)
void BrDevPaletteSetOld(br_pixelmap* pm) {
Harness_Hook_BrDevPaletteSetOld(pm);
NOT_IMPLEMENTED();
}

// IDA: void __cdecl BrDevPaletteSetEntryOld(int i, br_colour colour)
void BrDevPaletteSetEntryOld(int i, br_colour colour) {
Harness_Hook_BrDevPaletteSetEntryOld(i, colour);
NOT_IMPLEMENTED();
}

// IDA: br_error __cdecl BrRendererFacilityFind(br_renderer_facility **prf, br_device_pixelmap *destination, br_token scalar_type)
Expand Down
8 changes: 6 additions & 2 deletions src/BRSRC13/CORE/V1DB/prepmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ void BrMapUpdate(br_pixelmap* map, br_uint_16 flags) {
void BrBufferUpdate(br_pixelmap* pm, br_token use, br_uint_16 flags) {
br_token_value tv[3];

Harness_Hook_BrBufferUpdate(pm, use, flags);

// renderer->dispatch->bufferStoredNew ...

// Added by dethrace
if (use != BRT_COLOUR_MAP_O && use != BRT_UNKNOWN) {
LOG_PANIC("use %d", use);
}
gHarness_platform.Renderer_BufferTexture(pm);
}

// IDA: void __usercall BrBufferClear(br_pixelmap *pm@<EAX>)
Expand Down
5 changes: 3 additions & 2 deletions src/BRSRC13/CORE/V1DB/prepmatl.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ void BrMaterialUpdate(br_material* mat, br_uint_16 flags) {
br_token t;
br_int_32 c;

//TODO: ?
// TODO: ?

Harness_Hook_BrMaterialUpdate(mat, flags);
// Added by dethrace
gHarness_platform.Renderer_BufferMaterial(mat);
}

// IDA: void __usercall BrMaterialClear(br_material *mat@<EAX>)
Expand Down
3 changes: 2 additions & 1 deletion src/BRSRC13/CORE/V1DB/prepmesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,8 @@ void BrModelUpdate(br_model* model, br_uint_16 flags) {
model->stored = NULL;
}

Harness_Hook_BrModelUpdate(model);
// Added by dethrace
gHarness_platform.Renderer_BufferModel(model);
}

// IDA: void __usercall BrModelClear(br_model *model@<EAX>)
Expand Down
20 changes: 11 additions & 9 deletions src/BRSRC13/CORE/V1DB/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ void BrDbSceneRenderBegin(br_actor* world, br_actor* camera) {
// this is not complete
STUB_ONCE();

/*
* Collect transforms from camera to root
*
* Make a stack of cumulative transforms for each level between
* the camera and the root - this is so that model->view
* transforms can use the shortest route, rather than via the root
*/
/*
* Collect transforms from camera to root
*
* Make a stack of cumulative transforms for each level between
* the camera and the root - this is so that model->view
* transforms can use the shortest route, rather than via the root
*/
for (i = 0; i < BR_ASIZE(v1db.camera_path); i++) {
v1db.camera_path[i].a = NULL;
}
Expand Down Expand Up @@ -323,7 +323,7 @@ void BrZbSceneRenderBegin(br_actor* world, br_actor* camera, br_pixelmap* colour
// LOG_TRACE("(%p, %p, %p, %p)", world, camera, colour_buffer, depth_buffer);

BrDbSceneRenderBegin(world, camera);
Harness_Hook_BrZbSceneRenderBegin(world, camera, colour_buffer, depth_buffer);
gHarness_platform.Renderer_BeginScene(camera, colour_buffer, depth_buffer);
}

// IDA: void __cdecl BrZbSceneRenderAdd(br_actor *tree)
Expand All @@ -335,7 +335,9 @@ void BrZbSceneRenderAdd(br_actor* tree) {
// IDA: void __cdecl BrZbSceneRenderEnd()
void BrZbSceneRenderEnd() {
// LOG_TRACE("()");
Harness_Hook_BrZbSceneRenderEnd();

gHarness_platform.Renderer_FlushBuffers();
gHarness_platform.Renderer_EndScene();
}

// IDA: void __cdecl BrZbSceneRender(br_actor *world, br_actor *camera, br_pixelmap *colour_buffer, br_pixelmap *depth_buffer)
Expand Down
5 changes: 4 additions & 1 deletion src/DETHRACE/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ target_include_directories(dethrace_obj
target_link_libraries(dethrace_obj PUBLIC SDL2::SDL2 smacker harness brender s3)



if (CMAKE_C_COMPILER_ID MATCHES "MSVC")
target_compile_definitions(dethrace_obj PRIVATE -D_CRT_SECURE_NO_WARNINGS)
target_compile_options(dethrace_obj PRIVATE
Expand Down Expand Up @@ -158,6 +157,10 @@ target_sources(dethrace_obj PRIVATE
pd/net.h
pc-dos/dossys.c
pd/sys.h
pc-win95/win95sys.c
pc-win95/dinput.h
pc-win95/ssdx.c
pc-win95/ssdx.h
)

# Create our main game binary.
Expand Down
15 changes: 10 additions & 5 deletions src/DETHRACE/common/cutscene.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "globvrpb.h"
#include "graphics.h"
#include "harness/config.h"
#include "harness/hooks.h"
#include "harness/os.h"
#include "harness/trace.h"
#include "input.h"
Expand Down Expand Up @@ -72,7 +73,7 @@ void PlaySmackerFile(char* pSmack_name) {
unsigned long w, h, f;
unsigned char r, g, b;
double usf;
struct timespec ts;
tU32 last_frame_time;

if (!gSound_override && !gCut_scene_override) {
StopMusic();
Expand Down Expand Up @@ -126,12 +127,16 @@ void PlaySmackerFile(char* pSmack_name) {
}
}
PDScreenBufferSwap(0);

if (AnyKeyDown() || EitherMouseButtonDown()) {
last_frame_time = PDGetTotalTime();

do {
fuck_off = AnyKeyDown() || EitherMouseButtonDown();
// added by dethrace to avoid 100% cpu
gHarness_platform.Sleep(1);
} while (!fuck_off && PDGetTotalTime() - last_frame_time < delay_ms);
if (fuck_off) {
break;
}
// wait until its time for the next frame
OS_Sleep(delay_ms);
} while (smk_next(s) == SMK_MORE);

smk_close(s);
Expand Down
6 changes: 3 additions & 3 deletions src/DETHRACE/common/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#define _ERRORS_H_

#include "brender/br_types.h"
#include "harness/compiler.h"
#include "dr_types.h"
#include "harness/compiler.h"

extern char* gError_messages[126];
extern int gError_code;
extern char* gPalette_copy__errors; // suffix added to avoid duplicate symbol
extern char* gPalette_copy__errors; // suffix added to avoid duplicate symbol
extern int gPixel_buffer_size__errors; // suffix added to avoid duplicate symbol
extern int gMouse_was_started__errors; // suffix added to avoid duplicate symbol
extern char* gPixels_copy__errors; // suffix added to avoid duplicate symbol
extern char* gPixels_copy__errors; // suffix added to avoid duplicate symbol

HARNESS_NORETURN void FatalError(int pStr_index, ...);

Expand Down
16 changes: 8 additions & 8 deletions src/DETHRACE/common/flicplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1136,12 +1136,12 @@ void DoBlack(tFlic_descriptor* pFlic_info, tU32 chunk_length) {
the_row_bytes = pFlic_info->the_pixelmap->row_bytes;
the_width = pFlic_info->width;
for (i = 0; i < pFlic_info->height; i++) {
line_pixel_ptr = (tU32*)pixel_ptr;
for (j = 0; j < the_width / sizeof(tU32); j++) {
*line_pixel_ptr = 0;
line_pixel_ptr++;
}
pixel_ptr += the_row_bytes;
line_pixel_ptr = (tU32*)pixel_ptr;
for (j = 0; j < the_width / sizeof(tU32); j++) {
*line_pixel_ptr = 0;
line_pixel_ptr++;
}
pixel_ptr += the_row_bytes;
}
}

Expand Down Expand Up @@ -1268,7 +1268,7 @@ void DoUncompressedTrans(tFlic_descriptor* pFlic_info, tU32 chunk_length) {
for (i = 0; i < pFlic_info->height; i++) {
line_pixel_ptr = pixel_ptr;
for (j = 0; j < the_width; j++) {
#if defined (DETHRACE_FIX_BUGS)
#if defined(DETHRACE_FIX_BUGS)
the_byte = MemReadU8(&pFlic_info->data);
#else
the_byte = MemReadU32(&pFlic_info->data);
Expand Down Expand Up @@ -1465,13 +1465,13 @@ int PlayFlic(int pIndex, tU32 pSize, tS8* pData_ptr, br_pixelmap* pDest_pixelmap
gSound_time = 0;
}
if (frame_period >= the_flic.frame_period) {
last_frame = new_time;
finished_playing = PlayNextFlicFrame(&the_flic);
DoPerFrame();
if (!gDark_mode) {
EnsurePaletteUp();
}
ServiceGame();
last_frame = new_time;
}
}
ServiceGame();
Expand Down
10 changes: 5 additions & 5 deletions src/DETHRACE/common/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ void ScreenLarger() {
// IDA: void __usercall DRSetPaletteEntries(br_pixelmap *pPalette@<EAX>, int pFirst_colour@<EDX>, int pCount@<EBX>)
void DRSetPaletteEntries(br_pixelmap* pPalette, int pFirst_colour, int pCount) {
LOG_TRACE("(%p, %d, %d)", pPalette, pFirst_colour, pCount);
if (!pFirst_colour) {
if (pFirst_colour == 0) {
((br_int_32*)pPalette->pixels)[0] = 0;
}
memcpy(gCurrent_palette_pixels + 4 * pFirst_colour, (char*)pPalette->pixels + 4 * pFirst_colour, 4 * pCount);
Expand Down Expand Up @@ -1671,15 +1671,15 @@ void RenderAFrame(int pDepth_mask_on) {
RenderLollipops();

// dethrace: must flush gpu buffer before rendering depth effect into framebuffer
Harness_Hook_FlushRenderer();
gHarness_platform.Renderer_FlushBuffers();
DepthEffectSky(gRender_screen, gDepth_buffer, gCamera, &gCamera_to_world);
DepthEffect(gRender_screen, gDepth_buffer, gCamera, &gCamera_to_world);
if (!gAusterity_mode) {
ProcessTrack(gUniverse_actor, &gProgram_state.track_spec, gCamera, &gCamera_to_world, 1);
}
RenderSplashes();
// dethrace: must flush gpu buffer before rendering smoke into framebuffer
Harness_Hook_FlushRenderer();
gHarness_platform.Renderer_FlushBuffers();
RenderSmoke(gRender_screen, gDepth_buffer, gCamera, &gCamera_to_world, gFrame_period);
RenderSparks(gRender_screen, gDepth_buffer, gCamera, &gCamera_to_world, gFrame_period);
RenderProximityRays(gRender_screen, gDepth_buffer, gCamera, &gCamera_to_world, gFrame_period);
Expand Down Expand Up @@ -2574,10 +2574,10 @@ int DoMouseCursor() {
period = 1000;
}
while (period <= 20) {
// Sleep 1 ms to avoid 100% CPU usage
OS_Sleep(1);
this_call_time = PDGetTotalTime();
period = this_call_time - last_call_time;
// added by dethrace to avoid 100% CPU usage
gHarness_platform.Sleep(1);
}
GetMousePosition(&x_coord, &y_coord);
mouse_moved = x_coord != gMouse_last_x_coord || y_coord != gMouse_last_y_coord;
Expand Down
1 change: 1 addition & 0 deletions src/DETHRACE/common/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ void InitialiseApplication(int pArgc, char** pArgv) {
FatalError(kFatalError_UnsupportedScreenDepth);
}
CalcGrafDataIndex();
PDInitScreen();
InitializeBRenderEnvironment();
InitDRFonts();
InitBRFonts();
Expand Down
5 changes: 5 additions & 0 deletions src/DETHRACE/common/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ br_vector3 gCamera_velocity;

// IDA: void __cdecl UsePathFileToDetermineIfFullInstallation()
void UsePathFileToDetermineIfFullInstallation() {
// changed by dethrace for compatibility
// char line1[80];
// char line2[80];
// char line3[80];
// char path_file[80];
char line1[MAX_PATH_LENGTH];
char line2[MAX_PATH_LENGTH];
char line3[MAX_PATH_LENGTH];
Expand Down
2 changes: 1 addition & 1 deletion src/DETHRACE/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ enum {
#define FONT_LITPLAQ1 19
#define FONT_DRKPLAQ1 20

#define MAX_PATH_LENGTH 256
#define MAX_PATH_LENGTH 1024

#define ROLLING_LETTER_LOOP_RANDOM 96
#define PLAYER_NAME_MAX_LENGTH 13
Expand Down
Loading

0 comments on commit ef9e4d6

Please sign in to comment.