DEADSOFTWARE

added libsocket and updated watt32, but network still not work
[d2df-sdl.git] / src / lib / watt32 / watt32.pp
1 // TCP/IP stack for DOS
2 // ftp://ftp.delorie.com/pub/djgpp/current/v2tk/wat3222br6.zip
3 // ftp://ftp.delorie.com/pub/djgpp/current/v2tk/wat3222sr6.zip
5 {$MODE OBJFPC}
6 {$PACKRECORDS C}
8 {$MODESWITCH OUT}
9 {$LONGSTRINGS ON}
10 {$MACRO ON}
12 {$IF DEFINED(GO32V2)}
13 {$LINKLIB libwatt.a}
14 {$DEFINE LibraryLibWattDecl := cdecl}
15 {$DEFINE LibraryLibWattImp := cdecl; external}
16 {$DEFINE LibraryLibWattVar := cvar; external}
17 {$ELSE}
18 {$ERROR what?}
19 {$ENDIF}
21 unit watt32;
23 interface
25 uses ctypes;
27 const
28 (* socket size have another size on 64-bit systems *)
29 W32_UNDOC_TCP_SOCKET_SIZE = 4470;
30 W32_UNDOC_UDP_SOCKET_SIZE = 4470;
31 FD_MAXFDSET = 512; (* FD_SETSIZE *)
33 type
34 (* Watt32 -> sys/wtypes.h -> fd_set *)
35 TFDSet = record
36 fd_bits: array [0..63] of cuchar;
37 end;
39 tcp_Socket = record
40 undoc: array [0..W32_UNDOC_TCP_SOCKET_SIZE - 1] of cuchar;
41 end;
43 udp_Socket = record
44 undoc: array [0..W32_UNDOC_UDP_SOCKET_SIZE - 1] of cuchar;
45 end;
47 Psock_type = Pointer;
49 var
50 wattcpCopyrigh: PChar; LibraryLibWattVar;
51 my_ip_addr: culong; external name '__w32_my_ip_addr';
53 function wattcpVersion: PChar; LibraryLibWattImp;
54 function wattcpCapabilities: PChar; LibraryLibWattImp;
55 function wattcpBuildCC: PChar; LibraryLibWattImp;
56 function wattcpBuildCCexe: PChar; LibraryLibWattImp;
57 function wattcpBuildCflags: PChar; LibraryLibWattImp;
59 function sock_init: cint; inline; (* MACRO *)
60 function watt_sock_init (tcp_Sock_size, udp_Sock_size, time_t_size: csize_t): cint; LibraryLibWattImp;
62 function sock_init_err (rc: cint): PChar; LibraryLibWattImp name '_w32_sock_init_err';
63 procedure sock_exit; LibraryLibWattImp;
64 procedure dbug_init; LibraryLibWattImp;
65 procedure init_misc; LibraryLibWattImp;
66 procedure sock_sig_exit (const msg: PChar; sigint: cint); LibraryLibWattImp;
68 function hires_timer (on: cint): cint; LibraryLibWattImp name '_w32_hires_timer';
70 procedure init_userSuppliedTimerTick; LibraryLibWattImp name '_w32_init_userSuppliedTimerTick';
71 procedure userTimerTick (elapsed_time_msec: culong); LibraryLibWattImp name '_w32_userTimerTick';
72 procedure init_timer_isr; LibraryLibWattImp;
73 procedure exit_timer_isr; LibraryLibWattImp;
75 function tcp_tick (s: Psock_type): culong; LibraryLibWattImp name '_w32_tcp_tick';
77 function htons (hostshort: cuint16): cuint16; LibraryLibWattImp;
78 function htonl (hostlong: cuint32): cuint32; LibraryLibWattImp;
79 function ntohs (netshort: cuint16): cuint16; LibraryLibWattImp;
80 function ntohl (netlong: cuint32): cuint32; LibraryLibWattImp;
82 (* MACRO *)
83 function fpFD_SET (fdno: cint; var nset: TFDSet): cint;
84 function fpFD_CLR (fdno:cint; var nset: TFDSet): cint;
85 function fpFD_ZERO (out nset: TFDSet): cint;
86 function fpFD_ISSET (fdno: cint;const nset: TFDSet): cint;
88 implementation
90 function sock_init: cint; inline;
91 begin
92 sock_init := watt_sock_init(sizeof(tcp_Socket), sizeof(udp_Socket), sizeof(cuint)) (* !!! DJGPP *)
93 end;
95 function fpFD_SET (fdno: cint; var nset: TFDSet): cint;
96 begin
97 if (fdno < 0) or (fdno > FD_MAXFDSET) then
98 exit(-1);
99 nset.fd_bits[fdno div 8] := nset.fd_bits[fdno div 8] OR (culong(1) shl (fdno and 7));
100 fpFD_SET := 0
101 end;
103 function fpFD_CLR (fdno: cint; var nset: TFDSet): cint;
104 begin
105 if (fdno < 0) or (fdno > FD_MAXFDSET) Then
106 exit(-1);
107 nset.fd_bits[fdno div 8] := nset.fd_bits[fdno div 8] AND Cardinal(NOT (culong(1) shl (fdno and 7)));
108 fpFD_CLR := 0
109 end;
111 function fpFD_ZERO (out nset: TFDSet): cint;
112 var i :longint;
113 begin
114 for i := 0 to (512 + 7) div 8 DO
115 nset.fd_bits[i] := 0;
116 fpFD_ZERO := 0
117 end;
119 function fpFD_ISSET (fdno: cint; const nset: TFDSet): cint;
120 begin
121 if (fdno < 0) or (fdno > FD_MAXFDSET) Then
122 exit(-1);
123 if ((nset.fd_bits[fdno div 8]) and (culong(1) shl (fdno and 7))) > 0 then
124 fpFD_ISSET := 1
125 else
126 fpFD_ISSET := 0
127 end;
129 end.