FreeBASIC  0.91.0
dev_scrn_read.c
Go to the documentation of this file.
1 /* file device */
2 
3 #include "fb.h"
4 
5 int fb_DevScrnRead( FB_FILE *handle, void* value, size_t *pLength )
6 {
7  size_t length, copy_length;
8  DEV_SCRN_INFO *info;
9  char *pachBuffer = (char*) value;
10 
11  FB_LOCK();
12 
13  DBG_ASSERT(pLength!=NULL);
14  length = *pLength;
15 
16  info = (DEV_SCRN_INFO*) FB_HANDLE_DEREF(handle)->opaque;
17 
18  while( length > 0 ) {
19  copy_length = (length > info->length) ? info->length : length;
20  if (copy_length==0) {
21 
22  while( fb_KeyHit( ) == 0 )
23  fb_Delay( 25 ); /* release time slice */
24 
25  fb_DevScrnFillInput( info );
26  if( info->length != 0 )
27  continue;
28 
29  break;
30  }
31  memcpy(pachBuffer, info->buffer, copy_length);
32  info->length -= copy_length;
33  if (info->length!=0) {
34  memmove(info->buffer,
35  info->buffer + copy_length,
36  info->length);
37  }
38  length -= copy_length;
39  pachBuffer += copy_length;
40  }
41 
42  FB_UNLOCK();
43 
44  if (length!=0)
45  memset(pachBuffer, 0, length);
46 
47  *pLength -= length;
48 
49  return fb_ErrorSetNum( FB_RTERROR_OK );
50 }
51 
52 static int hReadFromStdin( FB_FILE *handle, void* dst, size_t *pLength )
53 {
54  return fb_DevFileRead( NULL, dst, pLength );
55 }
56 
57 void fb_DevScrnInit_Read( void )
58 {
60 
61  if( FB_HANDLE_SCREEN->hooks->pfnRead == NULL )
62  {
63  FB_HANDLE_SCREEN->hooks->pfnRead =
65  }
66 }