From ccbaf6953ba60385f0fd86ec5921c81ecd6fe08b Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Fri, 8 Feb 2019 19:26:06 +0300 Subject: [PATCH] Added Watt32 support --- src/game/Doom2DF.lpr | 7 ++ src/game/g_main.pas | 21 ++++++ src/lib/enet/enet.pp | 11 ++- src/lib/watt32/watt32.pp | 118 ++++++++++++++++++++++++++++++ src/wrappers/sdl2/sdl2allegro.inc | 18 ++++- 5 files changed, 171 insertions(+), 4 deletions(-) create mode 100644 src/lib/watt32/watt32.pp diff --git a/src/game/Doom2DF.lpr b/src/game/Doom2DF.lpr index a897aea..53020f4 100644 --- a/src/game/Doom2DF.lpr +++ b/src/game/Doom2DF.lpr @@ -63,6 +63,12 @@ uses ENet in '../wrappers/enet/enet.pas', {$ELSE} ENet in '../lib/enet/enet.pp', + {$IFDEF GO32V2} + Watt32 in '../lib/watt32/watt32.pp', + {$ENDIF} +{$ENDIF} +{$IFDEF USE_SDL2ALLEGRO} + Allegro in '../lib/allegro4/allegro.pas', {$ENDIF} e_graphics in '../engine/e_graphics.pas', e_input in '../engine/e_input.pas', @@ -189,6 +195,7 @@ begin else if ParamStr(f) = '--log' then conbufDumpToStdOut := true else if ParamStr(f) = '--safe-log' then e_SetSafeSlowLog(true); end; + if noct then begin Main() diff --git a/src/game/g_main.pas b/src/game/g_main.pas index c789caf..4e38444 100644 --- a/src/game/g_main.pas +++ b/src/game/g_main.pas @@ -38,6 +38,9 @@ implementation uses {$INCLUDE ../nogl/noGLuses.inc} +{$IF DEFINED(GO32V2) AND NOT DEFINED(USE_ENETWRAP)} + Watt32, +{$ENDIF} {$IFDEF ENABLE_HOLMES} g_holmes, fui_wadread, fui_style, fui_gfx_gl, {$ENDIF} @@ -80,6 +83,24 @@ begin TMsgType.Notify ); +{$IF DEFINED(GO32V2) AND NOT DEFINED(USE_ENETWRAP)} + sdlflags := sock_init; + {$IFDEF USE_SDL2ALLEGRO} + hires_timer(0); + init_userSuppliedTimerTick; + {$ENDIF} + e_WriteLog('Wattcp Init: (' + IntToStr(sdlflags) + ') ' + sock_init_err, TMsgType.Notify); + e_WriteLog('Wattcp Version: ' + wattcpVersion, TMsgType.Notify); + e_WriteLog('Wattcp Capabilities: ' + wattcpCapabilities, TMsgType.Notify); + e_WriteLog('Wattcp IP: ' + + IntToStr(my_ip_addr div 16777216 mod 256) + '.' + + IntToStr(my_ip_addr div 65536 mod 256) + '.' + + IntToStr(my_ip_addr div 256 mod 256) + '.' + + IntToStr(my_ip_addr mod 256), + TMsgType.Notify + ); +{$ENDIF} + {$IFDEF HEADLESS} conbufDumpToStdOut := true; {$ENDIF} diff --git a/src/lib/enet/enet.pp b/src/lib/enet/enet.pp index e50109f..4aa383d 100644 --- a/src/lib/enet/enet.pp +++ b/src/lib/enet/enet.pp @@ -13,7 +13,7 @@ {$Z4} // Force four-byte enums -{$IFDEF MSWINDOWS} +{$IF DEFINED(MSWINDOWS)} {$IFDEF LIBENET_WINDOZE_STATIC} {$LINKLIB libenet.a} {$LINKLIB libwinmm.a} @@ -35,6 +35,11 @@ // external LIBNAME name 'var_name' would've been more correct here // because just external is case insensitive, but fuck it {$ENDIF} +{$ELSEIF DEFINED(GO32V2)} + {$LINKLIB libenet.a} + {$DEFINE libraryLibENetDecl := cdecl} + {$DEFINE libraryLibENetImp := cdecl; external} + {$DEFINE libraryLibENetVar := cvar; external} {$ELSE} {$DEFINE libraryLibENetDecl := cdecl} {$DEFINE libraryLibENetImp := cdecl; external 'enet'} @@ -75,8 +80,10 @@ interface uses ctypes, -{$IFDEF WINDOWS} +{$IF DEFINED(WINDOWS)} WinSock2; +{$ELSEIF DEFINED(GO32V2)} + Watt32; {$ELSE} BaseUnix, Sockets; {$ENDIF} diff --git a/src/lib/watt32/watt32.pp b/src/lib/watt32/watt32.pp new file mode 100644 index 0000000..60eb926 --- /dev/null +++ b/src/lib/watt32/watt32.pp @@ -0,0 +1,118 @@ +{$MODE OBJFPC} +{$PACKRECORDS C} + +{$MODESWITCH OUT} +{$LONGSTRINGS ON} +{$MACRO ON} + +{$IF DEFINED(GO32V2)} + {$LINKLIB libwatt.a} + {$DEFINE LibraryLibWattDecl := cdecl} + {$DEFINE LibraryLibWattImp := cdecl; external} + {$DEFINE LibraryLibWattVar := cvar; external} +{$ELSE} + {$ERROR what?} +{$ENDIF} + +unit watt32; + +interface + + uses ctypes; + + const + FD_MAXFDSET = 512; (* FD_SETSIZE *) + + type + (* Watt32 -> sys/wtypes.h -> fd_set *) + TFDSet = record + fd_bits: array [0..63] of cuchar; + end; + + tcp_Socket = record + undoc: array [0..4469] of cuchar; + end; + + udp_Socket = record + undoc: array [0..1739] of cuchar; + end; + + Psock_type = Pointer; + + var + my_ip_addr: culong; external name '__w32_my_ip_addr'; + + function wattcpCopyright: PChar; LibraryLibWattImp; + function wattcpVersion: PChar; LibraryLibWattImp; + function wattcpCapabilities: PChar; LibraryLibWattImp; + + function watt_sock_init (tcp, udp: csize_t): cint; LibraryLibWattImp; + function sock_init_err: PChar; LibraryLibWattImp; + procedure sock_exit; LibraryLibWattImp; + procedure dbug_init; LibraryLibWattImp; + procedure init_misc; LibraryLibWattImp; + procedure sock_sig_exit (const msg: PChar; sigint: cint); LibraryLibWattImp; + + function hires_timer (on: cint): cint; LibraryLibWattImp name '_w32_hires_timer'; + procedure init_userSuppliedTimerTick; LibraryLibWattImp; + procedure userTimerTick (elapsed_time_msec: culong); LibraryLibWattImp; + procedure init_timer_isr; LibraryLibWattImp name '_w32_init_timer_isr'; + procedure exit_timer_isr; LibraryLibWattImp name '_w32_exit_timer_isr'; + + function tcp_tick (s: Psock_type): culong; LibraryLibWattImp; + + + function htons (hostshort: cuint16): cuint16; LibraryLibWattImp; + function htonl (hostlong: cuint32): cuint32; LibraryLibWattImp; + function ntohs (netshort: cuint16): cuint16; LibraryLibWattImp; + function ntohl (netlong: cuint32): cuint32; LibraryLibWattImp; + + (* MACRO *) + function sock_init: cint; + function fpFD_SET (fdno: cint; var nset: TFDSet): cint; + function fpFD_CLR (fdno:cint; var nset: TFDSet): cint; + function fpFD_ZERO (out nset: TFDSet): cint; + function fpFD_ISSET (fdno: cint;const nset: TFDSet): cint; + +implementation + + function sock_init: cint; + begin + sock_init := watt_sock_init(sizeof(tcp_Socket), sizeof(udp_Socket)) + end; + + function fpFD_SET (fdno: cint; var nset: TFDSet): cint; + begin + if (fdno < 0) or (fdno > FD_MAXFDSET) then + exit(-1); + nset.fd_bits[fdno div 8] := nset.fd_bits[fdno div 8] OR (culong(1) shl (fdno and 7)); + fpFD_SET := 0 + end; + + function fpFD_CLR (fdno: cint; var nset: TFDSet): cint; + begin + if (fdno < 0) or (fdno > FD_MAXFDSET) Then + exit(-1); + nset.fd_bits[fdno div 8] := nset.fd_bits[fdno div 8] AND Cardinal(NOT (culong(1) shl (fdno and 7))); + fpFD_CLR := 0 + end; + + function fpFD_ZERO (out nset: TFDSet): cint; + var i :longint; + begin + for i := 0 to (512 + 7) div 8 DO + nset.fd_bits[i] := 0; + fpFD_ZERO := 0 + end; + + function fpFD_ISSET (fdno: cint; const nset: TFDSet): cint; + begin + if (fdno < 0) or (fdno > FD_MAXFDSET) Then + exit(-1); + if ((nset.fd_bits[fdno div 8]) and (culong(1) shl (fdno and 7))) > 0 then + fpFD_ISSET := 1 + else + fpFD_ISSET := 0 + end; + +end. diff --git a/src/wrappers/sdl2/sdl2allegro.inc b/src/wrappers/sdl2/sdl2allegro.inc index a5de6da..fedd18b 100644 --- a/src/wrappers/sdl2/sdl2allegro.inc +++ b/src/wrappers/sdl2/sdl2allegro.inc @@ -372,6 +372,9 @@ implementation uses {$IFDEF GO32V2} + {$IFNDEF USE_ENETWRAP} + Watt32, + {$ENDIF} go32, {$ENDIF} e_Log, g_options, SysUtils, Math, Classes, ctypes; @@ -877,7 +880,10 @@ implementation procedure AllegroTimerCallback; cdecl; begin - inc(ticks) + inc(ticks); + {$IF DEFINED(GO32V2) AND NOT DEFINED(USE_ENETWRAP)} + userTimerTick(1); + {$ENDIF} end; procedure AllegroTimerCallbackEND; begin end; @@ -1188,6 +1194,10 @@ implementation release_screen; if useVsync then vsync; + + {$IF DEFINED(GO32V2) AND NOT DEFINED(USE_ENETWRAP)} + tcp_tick(nil); + {$ENDIF} end; (********** EVENTS **********) @@ -1267,7 +1277,11 @@ implementation event.key.keysym._mod := 0; (* df not use it? *) result := 1; Exit - end + end; + + {$IF DEFINED(GO32V2) AND NOT DEFINED(USE_ENETWRAP)} + tcp_tick(nil); + {$ENDIF} end; (********** MOUSE **********) -- 2.29.2