DEADSOFTWARE

Added Watt32 support
[d2df-sdl.git] / src / lib / watt32 / watt32.pp
1 {$MODE OBJFPC}
2 {$PACKRECORDS C}
4 {$MODESWITCH OUT}
5 {$LONGSTRINGS ON}
6 {$MACRO ON}
8 {$IF DEFINED(GO32V2)}
9 {$LINKLIB libwatt.a}
10 {$DEFINE LibraryLibWattDecl := cdecl}
11 {$DEFINE LibraryLibWattImp := cdecl; external}
12 {$DEFINE LibraryLibWattVar := cvar; external}
13 {$ELSE}
14 {$ERROR what?}
15 {$ENDIF}
17 unit watt32;
19 interface
21 uses ctypes;
23 const
24 FD_MAXFDSET = 512; (* FD_SETSIZE *)
26 type
27 (* Watt32 -> sys/wtypes.h -> fd_set *)
28 TFDSet = record
29 fd_bits: array [0..63] of cuchar;
30 end;
32 tcp_Socket = record
33 undoc: array [0..4469] of cuchar;
34 end;
36 udp_Socket = record
37 undoc: array [0..1739] of cuchar;
38 end;
40 Psock_type = Pointer;
42 var
43 my_ip_addr: culong; external name '__w32_my_ip_addr';
45 function wattcpCopyright: PChar; LibraryLibWattImp;
46 function wattcpVersion: PChar; LibraryLibWattImp;
47 function wattcpCapabilities: PChar; LibraryLibWattImp;
49 function watt_sock_init (tcp, udp: csize_t): cint; LibraryLibWattImp;
50 function sock_init_err: PChar; LibraryLibWattImp;
51 procedure sock_exit; LibraryLibWattImp;
52 procedure dbug_init; LibraryLibWattImp;
53 procedure init_misc; LibraryLibWattImp;
54 procedure sock_sig_exit (const msg: PChar; sigint: cint); LibraryLibWattImp;
56 function hires_timer (on: cint): cint; LibraryLibWattImp name '_w32_hires_timer';
57 procedure init_userSuppliedTimerTick; LibraryLibWattImp;
58 procedure userTimerTick (elapsed_time_msec: culong); LibraryLibWattImp;
59 procedure init_timer_isr; LibraryLibWattImp name '_w32_init_timer_isr';
60 procedure exit_timer_isr; LibraryLibWattImp name '_w32_exit_timer_isr';
62 function tcp_tick (s: Psock_type): culong; LibraryLibWattImp;
65 function htons (hostshort: cuint16): cuint16; LibraryLibWattImp;
66 function htonl (hostlong: cuint32): cuint32; LibraryLibWattImp;
67 function ntohs (netshort: cuint16): cuint16; LibraryLibWattImp;
68 function ntohl (netlong: cuint32): cuint32; LibraryLibWattImp;
70 (* MACRO *)
71 function sock_init: cint;
72 function fpFD_SET (fdno: cint; var nset: TFDSet): cint;
73 function fpFD_CLR (fdno:cint; var nset: TFDSet): cint;
74 function fpFD_ZERO (out nset: TFDSet): cint;
75 function fpFD_ISSET (fdno: cint;const nset: TFDSet): cint;
77 implementation
79 function sock_init: cint;
80 begin
81 sock_init := watt_sock_init(sizeof(tcp_Socket), sizeof(udp_Socket))
82 end;
84 function fpFD_SET (fdno: cint; var nset: TFDSet): cint;
85 begin
86 if (fdno < 0) or (fdno > FD_MAXFDSET) then
87 exit(-1);
88 nset.fd_bits[fdno div 8] := nset.fd_bits[fdno div 8] OR (culong(1) shl (fdno and 7));
89 fpFD_SET := 0
90 end;
92 function fpFD_CLR (fdno: cint; var nset: TFDSet): cint;
93 begin
94 if (fdno < 0) or (fdno > FD_MAXFDSET) Then
95 exit(-1);
96 nset.fd_bits[fdno div 8] := nset.fd_bits[fdno div 8] AND Cardinal(NOT (culong(1) shl (fdno and 7)));
97 fpFD_CLR := 0
98 end;
100 function fpFD_ZERO (out nset: TFDSet): cint;
101 var i :longint;
102 begin
103 for i := 0 to (512 + 7) div 8 DO
104 nset.fd_bits[i] := 0;
105 fpFD_ZERO := 0
106 end;
108 function fpFD_ISSET (fdno: cint; const nset: TFDSet): cint;
109 begin
110 if (fdno < 0) or (fdno > FD_MAXFDSET) Then
111 exit(-1);
112 if ((nset.fd_bits[fdno div 8]) and (culong(1) shl (fdno and 7))) > 0 then
113 fpFD_ISSET := 1
114 else
115 fpFD_ISSET := 0
116 end;
118 end.