FreeBASIC  0.91.0
hook_ports.c
Go to the documentation of this file.
1 /* ports I/O hooks, default to system implementations */
2 
3 #include "fb.h"
4 
5 /*:::::*/
6 FBCALL int fb_In( unsigned short port )
7 {
8  int res = -1;
9 
10  FB_LOCK();
11 
12  if( __fb_ctx.hooks.inproc)
13  res = __fb_ctx.hooks.inproc( port );
14  if( res < 0 )
15  res = fb_hIn( port );
16 
17  FB_UNLOCK();
18 
19  return res;
20 }
21 
22 /*:::::*/
23 FBCALL int fb_Out( unsigned short port, unsigned char value )
24 {
25  int res = -1;
26 
27  FB_LOCK();
28 
30  res = __fb_ctx.hooks.outproc( port, value );
31  if( res < 0 )
32  res = fb_hOut( port, value );
33 
34  FB_UNLOCK();
35 
36  return res;
37 }
38 
39 /*:::::*/
40 FBCALL int fb_Wait( unsigned short port, int and, int xor )
41 {
42  int res;
43 
44  do {
45  res = fb_In( port );
46  if( res < 0 )
47  return res;
48  res ^= xor;
49  } while( ( res & and ) == 0 );
50 
51  return FB_RTERROR_OK;
52 }