Skip to content
Permalink
Browse files

WIP: compile for DOS (32bit) with Watcom C

  • Loading branch information...
miniupnp committed Jan 3, 2018
1 parent 1da332c commit 820f982e107a5caab039cfc2cb335ab28c9dbb73
Showing with 135 additions and 8 deletions.
  1. +4 −0 .gitattributes
  2. +64 −0 Makefile.wc
  3. +9 −0 src/file.c
  4. +4 −0 src/os/endian.h
  5. +4 −0 src/os/readdir.c
  6. +14 −8 src/timer.c
  7. +31 −0 src/video/video_dos.c
  8. +5 −0 wccbuild.bat
@@ -26,3 +26,7 @@ configure eol=lf
config.lib eol=lf
Makefile* eol=lf
*.sh eol=lf

# DOS
Makefile.wc eol=crlf
*.bat eol=crlf
@@ -0,0 +1,64 @@
# /mf : Flat memory model
# /5r : pentium register calling convention
# /s : remove stack overflow checks
# /ox : optimize
# /wx : warnings maximums
# /q : quiet
coptions = /5r /s /ox /wx /q /bt=DOS4G /dDOS /i=..\include
link_options =

objs = animation.obj config.obj cutscene.obj explosion.obj file.obj gfx.obj house.obj ini.obj inifile.obj load.obj map.obj object.obj opendune.obj rev.obj save.obj scenario.obj sprites.obj string.obj structure.obj team.obj tile.obj timer.obj tools.obj unit.obj wsa.obj
audio_objs = driver.obj dsp_none.obj midi_none.obj mt32mpu.obj sound.obj crashlog_none.obj
misc_objs = format40.obj format80.obj input.obj mouse.obj
gui_objs = editbox.obj font.obj gui.obj mentat.obj security.obj viewport.obj widget.obj widget_click.obj widget_draw.obj
os_objs = video_dos.obj endian.obj error.obj readdir.obj
# readdir.obj
pool_src = $(p)house.c $(p)structure.c $(p)team.c $(p)unit.c
save_src = $(p)house.c $(p)info.c $(p)map.c $(p)object.c $(p)scenario.c $(p)structure.c $(p)team.c $(p)unit.c
script_src = $(p)structure.c $(p)team.c $(p)unit.c
table_src = $(p)animation.c $(p)explosion.c $(p)sound.c $(p)widget.c
p = p
pool_objs = $+ $(pool_src:.c=.obj) $-
p = sl
save_objs = $+ $(save_src:.c=.obj) $- saveload.obj scriptengine.obj
p = s
script_objs = $+ $(script_src:.c=.obj) $- general.obj script.obj
p = t
table_objs = $+ $(table_src:.c=.obj) $- actioninfo.obj houseanimation.obj houseinfo.obj landscapeinfo.obj movementtype.obj selectiontype.obj structureinfo.obj teamaction.obj tilediff.obj unitinfo.obj widgetinfo.obj windowdesc.obj
p =

all_objs = $(objs) $(audio_objs) $(misc_objs) $(gui_objs) $(os_objs) $(pool_objs) $(save_objs) $(script_objs) $(table_objs)


all: precopy ..\bin\opendune.exe

precopy: .symbolic
CD ..\src\pool
FOR %F IN ($(pool_src)) DO COPY /Y %F p%F
CD ..\saveload
FOR %F IN ($(save_src)) DO COPY /Y %F sl%F
CD ..\script
FOR %F IN ($(script_src)) DO COPY /Y %F s%F
CD ..\table
FOR %F IN ($(table_src)) DO COPY /Y %F t%F
CD ..\..\objs

.c: ..\src\;..\src\audio\;..\src\crashlog\;..\src\codec\;..\src\gui\;..\src\input\;..\src\os\;..\src\pool\;..\src\saveload\;..\src\script\;..\src\table\;..\src\video\

# $< : prerequesites
# $[* : without file extension

.c.obj:
wcc386 $(coptions) $[*

..\bin\opendune.exe: opendune.exe
copy $< $@

opendune.exe: $(all_objs)
%write opendune.lnk NAME $@
%write opendune.lnk SYSTEM DOS4G
%write opendune.lnk OPTION MAP
#%write opendune.lnk FILE {$<}
FOR %F IN ($<) DO %write opendune.lnk FILE %F
%write opendune.lnk LIBRARY clib3r.lib
wlink $(link_options) @opendune.lnk
@@ -7,6 +7,10 @@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#ifdef __WATCOMC__
#include <dos.h>
#include <direct.h>
#endif /* __WATCOMC__ */
#include "multichar.h"
#include "types.h"
#include "os/endian.h"
@@ -473,7 +477,12 @@ static bool File_MakeDirectory(char *dir)
*s = '\0';

if (stat(dir, &st) < 0) {
#ifdef __WATCOMC__
success = (_mkdir(dir) == 0);
#else
success = (mkdir(dir, S_IRWXU) == 0);
#endif

} else {
success = S_ISDIR(st.st_mode);
}
@@ -22,6 +22,10 @@
#if !defined(__BIG_ENDIAN)
#define __BIG_ENDIAN BIG_ENDIAN
#endif
#elif defined(__WATCOMC__)
#define __LITTLE_ENDIAN 1234
#define __BIG_ENDIAN 4321
#define __BYTE_ORDER __LITTLE_ENDIAN
#else
#include <endian.h>
#endif /* _WIN32 */
@@ -3,7 +3,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __WATCOMC__
#include <direct.h>
#else
#include <dirent.h>
#endif
#include <sys/stat.h>
#include <sys/types.h>
#include "types.h"
@@ -1,7 +1,7 @@
/** @file src/timer.c Timer routines. */

#include <stdlib.h>
#if !defined(_MSC_VER) && !defined(TOS)
#if !defined(_MSC_VER) && !defined(TOS) && !defined(__WATCOMC__)
#include <sys/time.h>
#endif /* _MSC_VER */
#if defined(_WIN32)
@@ -14,6 +14,8 @@
#include <mint/osbind.h>
#include <mint/ostruct.h>
#include <mint/sysvars.h>
#elif defined(__WATCOMC__)
#include <time.h>
#else
/* Linux / Mac OS X / etc. */
#if !defined(__USE_POSIX)
@@ -50,7 +52,7 @@ typedef struct TimerNode {
static HANDLE s_timerMainThread = NULL;
static HANDLE s_timerThread = NULL;
static int s_timerTime;
#elif !defined(TOS)
#elif !defined(TOS) && !defined(DOS)
static struct itimerval s_timerTime;
#endif /* _WIN32 */

@@ -72,6 +74,8 @@ uint32 Timer_GetTime(void)
#elif defined(TOS)
/* use the 200 HZ system timer which has a 5ms granularity */
return get_sysvar(_hz_200) * 5;
#elif defined(__WATCOMC__)
return clock() * 1000 / CLOCKS_PER_SEC;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
@@ -127,7 +131,7 @@ static void Timer_InterruptRun(int arg)
timerLock = false;
}

#if defined(TOS)
#if defined(TOS) || defined(DOS)
void SleepAndProcessBackgroundTasks(void)
{
Timer_InterruptRun(0);
@@ -191,7 +195,7 @@ void CALLBACK Timer_InterruptWindows(LPVOID arg, BOOLEAN TimerOrWaitFired) {
}
#endif /* _WIN32 */

#if !defined(TOS)
#if !defined(TOS) && !defined(DOS)

/**
* Suspend the timer interrupt handling.
@@ -237,6 +241,8 @@ void Timer_Init(void)
#if 0
Xbtimer(0/* Timer A */, 1/* divider = 4 */, s_timerSpeed * 6144 / 10000, Timer_Handler);
#endif
#elif defined(DOS)
/* */
#else
s_timerTime.it_value.tv_sec = 0;
s_timerTime.it_value.tv_usec = s_timerSpeed;
@@ -252,19 +258,19 @@ void Timer_Init(void)
sigaction(SIGALRM, &timerSignal, NULL);
}
#endif /* _WIN32 */
#if !defined(TOS)
#if !defined(TOS) && !defined(DOS)
Timer_InterruptResume();
#endif /* !defined(TOS) */
#endif /* !defined(TOS) && !defined(DOS) */
}

/**
* Uninitialize the timer.
*/
void Timer_Uninit(void)
{
#if !defined(TOS)
#if !defined(TOS) && !defined(DOS)
Timer_InterruptSuspend();
#endif /* !defined(TOS) */
#endif /* !defined(TOS) && !defined(DOS) */
#if defined(_WIN32)
CloseHandle(s_timerMainThread);
#endif /* _WIN32 */
@@ -1,8 +1,15 @@
/** @file src/video/video_dos.c IBM PC VGA video driver */

#if defined(__DJGPP__)
#include <dpmi.h>
#include <pc.h>
#include <sys/nearptr.h>
#endif /* __DJGPP__ */
#if defined(__WATCOMC__)
#include <i86.h>
#include <conio.h>
#define outportb outp
#endif /* __WATCOMC__ */

#include "types.h"
#include "video.h"
@@ -21,29 +28,49 @@ static bool s_mouse_right_btn = true;

bool Video_Init(int screen_magnification, VideoScaleFilter filter)
{
#if defined(__DJGPP__)
__dpmi_regs r;
#elif defined(__WATCOMC__)
union REGS r;
#endif /* __WATCOMC__ */
(void)screen_magnification;
(void)filter;

#if defined(__DJGPP__)
/* enable access to 1st MB of memory */
if (__djgpp_nearptr_enable() == 0) {
Error("__djgpp_nearptr_enable() failed, cannot access VGA memory.\n");
return false;
}
#endif /* __DJGPP__ */

g_consoleActive = false;
#if defined(__DJGPP__)
r.x.ax = 0x13; /* MCGA 13h mode */
__dpmi_int(0x10, &r);
#elif defined(__WATCOMC__)
r.w.ax = 0x13;
int386(0x10, &r, &r);
#endif
return true;
}

void Video_Uninit(void)
{
#if defined(__DJGPP__)
__dpmi_regs r;
#elif defined(__WATCOMC__)
union REGS r;
#endif /* __WATCOMC__ */

#if defined(__DJGPP__)
__djgpp_nearptr_disable();
r.x.ax = 0x03; /* text mode */
__dpmi_int(0x10, &r);
#elif defined(__WATCOMC__)
r.w.ax = 0x03;
int386(0x10, &r, &r);
#endif
g_consoleActive = true;
return;
}
@@ -93,5 +120,9 @@ void * Video_GetFrameBuffer(uint16 size)
(void)size;

/* VGA frame buffer */
#if defined(__DJGPP__)
return (void *)(0x000a0000 + __djgpp_conventional_base);
#else
return (void *)(0x000a0000);
#endif
}
@@ -0,0 +1,5 @@
@REM Build OpenDUNE for DOS using WATCOM C
@MKDIR OBJS
@COPY Makefile.wc OBJS\MAKEFILE
@CD OBJS
@WMAKE

0 comments on commit 820f982

Please sign in to comment.
You can’t perform that action at this time.