From 9a2ee072230bd5cb222921d0f34a6416ca69e12f Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Sat, 9 Feb 2019 20:52:52 +0300 Subject: [PATCH] added libsocket and updated watt32, but network still not work --- src/game/Doom2DF.lpr | 5 +- src/game/g_main.pas | 14 +++- src/lib/enet/enet.pp | 14 ++-- src/lib/socket/socket.pas | 135 ++++++++++++++++++++++++++++++ src/lib/watt32/watt32.pp | 37 +++++--- src/wrappers/sdl2/sdl2allegro.inc | 12 +-- 6 files changed, 188 insertions(+), 29 deletions(-) create mode 100644 src/lib/socket/socket.pas diff --git a/src/game/Doom2DF.lpr b/src/game/Doom2DF.lpr index 53020f4..10ec8fc 100644 --- a/src/game/Doom2DF.lpr +++ b/src/game/Doom2DF.lpr @@ -63,9 +63,12 @@ uses ENet in '../wrappers/enet/enet.pas', {$ELSE} ENet in '../lib/enet/enet.pp', - {$IFDEF GO32V2} + {$IFDEF USE_WATT32} Watt32 in '../lib/watt32/watt32.pp', {$ENDIF} + {$IFDEF USE_LIBSOCKET} + Socket in '../lib/socket/socket.pas', + {$ENDIF} {$ENDIF} {$IFDEF USE_SDL2ALLEGRO} Allegro in '../lib/allegro4/allegro.pas', diff --git a/src/game/g_main.pas b/src/game/g_main.pas index 4e38444..627ebb0 100644 --- a/src/game/g_main.pas +++ b/src/game/g_main.pas @@ -38,9 +38,12 @@ implementation uses {$INCLUDE ../nogl/noGLuses.inc} -{$IF DEFINED(GO32V2) AND NOT DEFINED(USE_ENETWRAP)} +{$IFDEF USE_WATT32} Watt32, {$ENDIF} +{$IFDEF USE_LIBSOCKET} + Socket, +{$ENDIF} {$IFDEF ENABLE_HOLMES} g_holmes, fui_wadread, fui_style, fui_gfx_gl, {$ENDIF} @@ -83,13 +86,13 @@ begin TMsgType.Notify ); -{$IF DEFINED(GO32V2) AND NOT DEFINED(USE_ENETWRAP)} +{$IFDEF USE_WATT32} 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 Init: (' + IntToStr(sdlflags) + ') ' + sock_init_err(sdlflags), TMsgType.Notify); e_WriteLog('Wattcp Version: ' + wattcpVersion, TMsgType.Notify); e_WriteLog('Wattcp Capabilities: ' + wattcpCapabilities, TMsgType.Notify); e_WriteLog('Wattcp IP: ' + @@ -100,6 +103,11 @@ begin TMsgType.Notify ); {$ENDIF} +{$IFDEF USE_LIBSOCKET} + sdlflags := __lsck_init; + e_WriteLog('libsocket Init: (' + IntToStr(sdlflags) + ') ' + lsck_strerror(sdlflags), TMsgType.Notify); + e_WriteLog('libsocket Version: ' + __lsck_get_version, TMsgType.Notify); +{$ENDIF} {$IFDEF HEADLESS} conbufDumpToStdOut := true; diff --git a/src/lib/enet/enet.pp b/src/lib/enet/enet.pp index 4aa383d..1a75e2f 100644 --- a/src/lib/enet/enet.pp +++ b/src/lib/enet/enet.pp @@ -79,14 +79,16 @@ unit ENet; interface uses - ctypes, -{$IF DEFINED(WINDOWS)} - WinSock2; -{$ELSEIF DEFINED(GO32V2)} - Watt32; +{$IF DEFINED(USE_WATT32)} + Watt32, +{$ELSEIF DEFINED(USE_LIBSOCKET)} + Socket, +{$ELSEIF DEFINED(WINDOWS)} + WinSock2, {$ELSE} - BaseUnix, Sockets; + BaseUnix, Sockets, {$ENDIF} + ctypes; //////////////////////////////////////////////////////////////////////////////// // types.h diff --git a/src/lib/socket/socket.pas b/src/lib/socket/socket.pas new file mode 100644 index 0000000..1052ad1 --- /dev/null +++ b/src/lib/socket/socket.pas @@ -0,0 +1,135 @@ +// TCP/IP stack for winDOS +// ftp://ftp.delorie.com/pub/djgpp/current/v2tk/ls080b.zip +// ftp://ftp.delorie.com/pub/djgpp/current/v2tk/ls080d.zip +// ftp://ftp.delorie.com/pub/djgpp/current/v2tk/ls080s.zip + +{$MODE OBJFPC} +{$PACKRECORDS C} + +{$MODESWITCH OUT} +{$LONGSTRINGS ON} +{$MACRO ON} + +{$LINKLIB libsocket.a} +{$LINKLIB libc.a} +{$DEFINE LibraryLibSockDecl := cdecl} +{$DEFINE LibraryLibSockImp := cdecl; external} +{$DEFINE LibraryLibSockVar := cvar; external} + +unit socket; + +interface + + uses ctypes; + + (* Start-up & shutdown *) + function __lsck_init: cint; LibraryLibSockImp; + procedure __lsck_uninit; LibraryLibSockImp; + + (* Configuration *) + function __lsck_config_getdir: PChar; LibraryLibSockImp; + function __lsck_config_setdir (newdir: PChar): PChar; LibraryLibSockImp; + function __lsck_config_getfile: PChar; LibraryLibSockImp; + function __lsck_config_setfile (newfile: PChar): PChar; LibraryLibSockImp; + + (* DNS address(es) *) + function __lsck_getdnsaddr: PChar; LibraryLibSockImp; + function __lsck_getdnsaddrs: PPChar; LibraryLibSockImp; + + (* Error fudging *) + //function lsck_strerror (errnum: cint): PChar; LibraryLibSockImp; + function lsck_strerror (errnum: cint): PChar; LibraryLibSockImp name 'strerror'; + + (* File descriptor tests *) + function __fd_is_socket (fd: cint): cint; LibraryLibSockImp; + function __fd_is_valid (fd: cint): cint; LibraryLibSockImp; + + (* Debugging *) + const + LSCK_DEBUG_OFF = 0; + LSCK_DEBUG_NORMAL = 1; + LSCK_DEBUG_VERBOSE = 2; + LSCK_DEBUG_ON = LSCK_DEBUG_NORMAL; + + procedure __lsck_debug_setlevel (level: cint); LibraryLibSockImp; + function __lsck_debug_getlevel: cint; LibraryLibSockImp; + procedure __lsck_debug_enable; LibraryLibSockImp; + procedure __lsck_debug_disable; LibraryLibSockImp; + function __lsck_debug_enabled: cint; LibraryLibSockImp; + + (* lsck/copyrite.h *) + function __lsck_get_version: PChar; LibraryLibSockImp; + function __lsck_get_copyright: PChar; LibraryLibSockImp; + + (* lsck/domname.h *) + function getdomainname (name: PChar; len: csize_t): cint; LibraryLibSockImp; + function setdomainname (const name: PChar; len: csize_t): cint; LibraryLibSockImp; + + (* lsck/hostname.h *) + function gethostname (buf: PChar; size: cint): cint; LibraryLibSockImp; + function sethostname (buf: PChar; size: cint): cint; LibraryLibSockImp; + + (* lsck/if.h *) + {...} + + + + function htonl (_val: culong): culong; LibraryLibSockImp; + function ntohl (_val: culong): culong; LibraryLibSockImp; + function htons (_val: cushort): cushort; LibraryLibSockImp; + function ntohs (_val: cushort): cushort; LibraryLibSockImp; + + + + (* MACRO *) + const + FD_MAXFDSET = 256; (* FD_SETSIZE *) + + type + (* djgpp sys-include -> sys/wtypes.h -> fd_set *) + TFDSet = record + fd_bits: array [0..(FD_MAXFDSET + 7) DIV 8] of cuchar; + end; + + 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 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 (FD_MAXFDSET + 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/lib/watt32/watt32.pp b/src/lib/watt32/watt32.pp index 60eb926..31011ca 100644 --- a/src/lib/watt32/watt32.pp +++ b/src/lib/watt32/watt32.pp @@ -1,3 +1,7 @@ +// TCP/IP stack for DOS +// ftp://ftp.delorie.com/pub/djgpp/current/v2tk/wat3222br6.zip +// ftp://ftp.delorie.com/pub/djgpp/current/v2tk/wat3222sr6.zip + {$MODE OBJFPC} {$PACKRECORDS C} @@ -21,6 +25,9 @@ interface uses ctypes; const + (* socket size have another size on 64-bit systems *) + W32_UNDOC_TCP_SOCKET_SIZE = 4470; + W32_UNDOC_UDP_SOCKET_SIZE = 4470; FD_MAXFDSET = 512; (* FD_SETSIZE *) type @@ -30,37 +37,42 @@ interface end; tcp_Socket = record - undoc: array [0..4469] of cuchar; + undoc: array [0..W32_UNDOC_TCP_SOCKET_SIZE - 1] of cuchar; end; udp_Socket = record - undoc: array [0..1739] of cuchar; + undoc: array [0..W32_UNDOC_UDP_SOCKET_SIZE - 1] of cuchar; end; Psock_type = Pointer; var + wattcpCopyrigh: PChar; LibraryLibWattVar; my_ip_addr: culong; external name '__w32_my_ip_addr'; - function wattcpCopyright: PChar; LibraryLibWattImp; function wattcpVersion: PChar; LibraryLibWattImp; function wattcpCapabilities: PChar; LibraryLibWattImp; + function wattcpBuildCC: PChar; LibraryLibWattImp; + function wattcpBuildCCexe: PChar; LibraryLibWattImp; + function wattcpBuildCflags: PChar; LibraryLibWattImp; + + function sock_init: cint; inline; (* MACRO *) + function watt_sock_init (tcp_Sock_size, udp_Sock_size, time_t_size: csize_t): cint; LibraryLibWattImp; - function watt_sock_init (tcp, udp: csize_t): cint; LibraryLibWattImp; - function sock_init_err: PChar; LibraryLibWattImp; + function sock_init_err (rc: cint): PChar; LibraryLibWattImp name '_w32_sock_init_err'; 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; + procedure init_userSuppliedTimerTick; LibraryLibWattImp name '_w32_init_userSuppliedTimerTick'; + procedure userTimerTick (elapsed_time_msec: culong); LibraryLibWattImp name '_w32_userTimerTick'; + procedure init_timer_isr; LibraryLibWattImp; + procedure exit_timer_isr; LibraryLibWattImp; + function tcp_tick (s: Psock_type): culong; LibraryLibWattImp name '_w32_tcp_tick'; function htons (hostshort: cuint16): cuint16; LibraryLibWattImp; function htonl (hostlong: cuint32): cuint32; LibraryLibWattImp; @@ -68,7 +80,6 @@ interface 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; @@ -76,9 +87,9 @@ interface implementation - function sock_init: cint; + function sock_init: cint; inline; begin - sock_init := watt_sock_init(sizeof(tcp_Socket), sizeof(udp_Socket)) + sock_init := watt_sock_init(sizeof(tcp_Socket), sizeof(udp_Socket), sizeof(cuint)) (* !!! DJGPP *) end; function fpFD_SET (fdno: cint; var nset: TFDSet): cint; diff --git a/src/wrappers/sdl2/sdl2allegro.inc b/src/wrappers/sdl2/sdl2allegro.inc index fedd18b..4ea4320 100644 --- a/src/wrappers/sdl2/sdl2allegro.inc +++ b/src/wrappers/sdl2/sdl2allegro.inc @@ -372,11 +372,11 @@ implementation uses {$IFDEF GO32V2} - {$IFNDEF USE_ENETWRAP} - Watt32, - {$ENDIF} go32, {$ENDIF} + {$IFDEF USE_WATT32} + Watt32, + {$ENDIF} e_Log, g_options, SysUtils, Math, Classes, ctypes; const @@ -881,7 +881,7 @@ implementation procedure AllegroTimerCallback; cdecl; begin inc(ticks); - {$IF DEFINED(GO32V2) AND NOT DEFINED(USE_ENETWRAP)} + {$IFDEF USE_WATT32} userTimerTick(1); {$ENDIF} end; @@ -1195,7 +1195,7 @@ implementation if useVsync then vsync; - {$IF DEFINED(GO32V2) AND NOT DEFINED(USE_ENETWRAP)} + {$IFDEF USE_WATT32} tcp_tick(nil); {$ENDIF} end; @@ -1279,7 +1279,7 @@ implementation Exit end; - {$IF DEFINED(GO32V2) AND NOT DEFINED(USE_ENETWRAP)} + {$IFDEF USE_WATT32} tcp_tick(nil); {$ENDIF} end; -- 2.29.2