FreeBASIC  0.91.0
rtl-console.bas
Go to the documentation of this file.
1 '' intrinsic runtime lib console functions (LOCATE, COLOR, CLS, INKEY, ...)
2 ''
3 '' chng: oct/2004 written [v1ctor]
4 
5 #include once "fb.bi"
6 #include once "fbint.bi"
7 #include once "ast.bi"
8 #include once "lex.bi"
9 #include once "rtl.bi"
10 
11 #define FB_COLOR_FG_DEFAULT &h00000001
12 #define FB_COLOR_BG_DEFAULT &h00000002
13 
14  dim shared as FB_RTL_PROCDEF funcdata( 0 to ... ) = _
15  { _
16 /' function fb_ConsoleView _
17  ( _
18  byval toprow as long = 0, _
19  byval botrow as long = 0 _
20  ) as long '/ _
21  ( _
22  @FB_RTL_CONSOLEVIEW, NULL, _
23  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
24  NULL, FB_RTL_OPT_NONE, _
25  2, _
26  { _
27  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, 0 ), _
28  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, 0 ) _
29  } _
30  ), _
31 /' function fb_ReadXY _
32  ( _
33  byval x as long, _
34  byval y as long, _
35  byval colorflag as long _
36  ) as ulong '/ _
37  ( _
38  @FB_RTL_CONSOLEREADXY, NULL, _
39  FB_DATATYPE_ULONG, FB_FUNCMODE_FBCALL, _
40  NULL, FB_RTL_OPT_NONE, _
41  3, _
42  { _
43  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, FALSE ), _
44  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, FALSE ), _
45  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, 0 ) _
46  } _
47  ), _
48 /' function fb_Width _
49  ( _
50  byval cols as long = -1, _
51  byval rows as long = -1 _
52  ) as long '/ _
53  ( _
54  @FB_RTL_WIDTH, NULL, _
55  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
56  NULL, FB_RTL_OPT_NONE, _
57  2, _
58  { _
59  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, -1 ), _
60  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, -1 ) _
61  } _
62  ), _
63 /' function fb_WidthDev( byref dev as string, byval width as long = -1 ) as long '/ _
64  ( _
65  @FB_RTL_WIDTHDEV, NULL, _
66  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
67  NULL, FB_RTL_OPT_NONE, _
68  2, _
69  { _
70  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, FALSE ), _
71  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, -1 ) _
72  } _
73  ), _
74 /' function fb_WidthFile( byval fnum as long, byval width as long = -1 ) as long '/ _
75  ( _
76  @FB_RTL_WIDTHFILE, NULL, _
77  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
78  NULL, FB_RTL_OPT_NONE, _
79  2, _
80  { _
81  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, FALSE ), _
82  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, -1 ) _
83  } _
84  ), _
85 /' function locate _
86  ( _
87  byval row as long = 0, _
88  byval col as long = 0, _
89  byval cursor as long = -1, _
90  byval start as long = 0, _
91  byval stop as long = 0 _
92  ) as long '/ _
93  ( _
94  @"locate", @"fb_Locate", _
95  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
96  NULL, FB_RTL_OPT_NONE, _
97  5, _
98  { _
99  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE,0 ), _
100  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE,0 ), _
101  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, -1 ), _
102  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, 0 ), _
103  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, 0 ) _
104  } _
105  ), _
106 /' function pos overload( ) as long '/ _
107  ( _
108  @"pos", @"fb_GetX", _
109  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
110  NULL, FB_RTL_OPT_OVER, _
111  0 _
112  ), _
113 /' function pos overload( byval dummy as long ) as long '/ _
114  ( _
115  @"pos", @"fb_Pos", _
116  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
117  NULL, FB_RTL_OPT_OVER, _
118  1, _
119  { _
120  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, FALSE ) _
121  } _
122  ), _
123 /' function csrlin( ) as long '/ _
124  ( _
125  @"csrlin", @"fb_GetY", _
126  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
127  NULL, FB_RTL_OPT_NONE, _
128  0 _
129  ), _
130 /' sub cls( byval mode as long = &hFFFF0000 ) '/ _
131  ( _
132  @"cls", @"fb_Cls", _
133  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
134  NULL, FB_RTL_OPT_NONE, _
135  1, _
136  { _
137  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, &hFFFF0000 ) _
138  } _
139  ), _
140 /' function fb_Color _
141  ( _
142  byval fc as long, _
143  byval bc as long, _
144  byval flags as long _
145  ) as long '/ _
146  ( _
147  @FB_RTL_COLOR, NULL, _
148  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
149  NULL, FB_RTL_OPT_NONE, _
150  3, _
151  { _
152  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, FALSE ), _
153  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, FALSE ), _
154  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, FALSE ) _
155  } _
156  ), _
157 /' function inkey( ) as string '/ _
158  ( _
159  @"inkey", @"fb_Inkey", _
160  FB_DATATYPE_STRING, FB_FUNCMODE_FBCALL, _
161  @rtlMultinput_cb, FB_RTL_OPT_STRSUFFIX or FB_RTL_OPT_NOQB, _
162  0 _
163  ), _
164 /' function inkey( ) as string '/ _
165  ( _
166  @"inkey", @"fb_InkeyQB", _
167  FB_DATATYPE_STRING, FB_FUNCMODE_FBCALL, _
168  @rtlMultinput_cb, FB_RTL_OPT_STRSUFFIX or FB_RTL_OPT_QBONLY, _
169  0 _
170  ), _
171 /' function getkey( ) as long '/ _
172  ( _
173  @"getkey", @"fb_Getkey", _
174  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
175  @rtlMultinput_cb, FB_RTL_OPT_NOQB, _
176  0 _
177  ), _
178 /' function pcopy( byval src as long = -1, byval dst as long = -1 ) as long '/ _
179  ( _
180  @"pcopy", @"fb_PageCopy", _
181  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
182  NULL, FB_RTL_OPT_NONE, _
183  2, _
184  { _
185  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, -1 ), _
186  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, -1 ) _
187  } _
188  ), _
189 /' function fb_PageSet( byval active as long = -1, byval visible as long = -1 ) as long '/ _
190  ( _
191  @FB_RTL_PAGESET, NULL, _
192  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
193  NULL, FB_RTL_OPT_NONE, _
194  2, _
195  { _
196  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, -1 ), _
197  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, -1 ) _
198  } _
199  ), _
200 /' EOL '/ _
201  ( _
202  NULL _
203  ) _
204  }
205 
206 '':::::
208 
210 
211 end sub
212 
213 '':::::
215 
216  '' procs will be deleted when symbEnd is called
217 
218 end sub
219 
220 '':::::
221 function rtlConsoleView _
222  ( _
223  byval topexpr as ASTNODE ptr, _
224  byval botexpr as ASTNODE ptr _
225  ) as ASTNODE ptr
226 
227  dim as ASTNODE ptr proc = any
228 
229  function = NULL
230 
231  ''
232  proc = astNewCALL( PROCLOOKUP( CONSOLEVIEW ) )
233 
234  '' byval toprow as integer
235  if( astNewARG( proc, topexpr ) = NULL ) then
236  exit function
237  end if
238 
239  '' byval botrow as integer
240  if( astNewARG( proc, botexpr ) = NULL ) then
241  exit function
242  end if
243 
244  function = proc
245 
246 end function
247 
248 '':::::
249 function rtlWidthScreen _
250  ( _
251  byval width_arg as ASTNODE ptr, _
252  byval height_arg as ASTNODE ptr, _
253  byval isfunc as integer _
254  ) as ASTNODE ptr
255 
256  dim as ASTNODE ptr proc = any
257 
258  function = NULL
259 
260  ''
261  proc = astNewCALL( PROCLOOKUP( WIDTH ) )
262 
263  '' byval width_arg as integer
264  if( width_arg = NULL ) then
265  width_arg = astNewCONSTi( -1 )
266  end if
267  if( astNewARG( proc, width_arg ) = NULL ) then
268  exit function
269  end if
270 
271  '' byval height_arg as integer
272  if( height_arg = NULL ) then
273  height_arg = astNewCONSTi( -1 )
274  end if
275  if( astNewARG( proc, height_arg ) = NULL ) then
276  exit function
277  end if
278 
279  if( isfunc = FALSE ) then
280  astAdd( rtlErrorCheck( proc ) )
281  end if
282 
283  function = proc
284 end function
285 
286 '':::::
287 function rtlColor _
288  ( _
289  byval fexpr as ASTNODE ptr, _
290  byval bexpr as ASTNODE ptr, _
291  byval isfunc as integer _
292  ) as ASTNODE ptr
293 
294  dim as ASTNODE ptr proc = any
295  dim as integer flags = any
296 
297  function = NULL
298  flags = 0
299 
300  ''
301  proc = astNewCALL( PROCLOOKUP( COLOR ) )
302 
303  '' byval fore_color as integer
304  if( fexpr = NULL ) then
305  fexpr = astNewCONSTi( 0, FB_DATATYPE_INTEGER )
306  flags or= FB_COLOR_FG_DEFAULT
307  end if
308  if( astNewARG( proc, fexpr ) = NULL ) then
309  exit function
310  end if
311 
312  '' byval back_color as integer
313  if( bexpr = NULL ) then
314  bexpr = astNewCONSTi( 0, FB_DATATYPE_INTEGER )
315  flags or= FB_COLOR_BG_DEFAULT
316  end if
317  if( astNewARG( proc, bexpr ) = NULL ) then
318  exit function
319  end if
320 
321  '' byval flags as integer
322  if( astNewARG( proc, astNewCONSTi( flags ) ) = NULL ) then
323  exit function
324  end if
325 
326  if( isfunc = FALSE ) then
327  astAdd( proc )
328  end if
329 
330  function = proc
331 
332 end function
333 
334 '':::::
335 function rtlPageSet _
336  ( _
337  byval active as ASTNODE ptr, _
338  byval visible as ASTNODE ptr, _
339  byval isfunc as integer _
340  ) as ASTNODE ptr
341 
342  dim as ASTNODE ptr proc = any
343 
344  function = NULL
345 
346  ''
347  proc = astNewCALL( PROCLOOKUP( PAGESET ) )
348 
349  '' byval active as integer = -1
350  if( active = NULL ) then
351  active = astNewCONSTi( -1 )
352  end if
353  if( astNewARG( proc, active ) = NULL ) then
354  exit function
355  end if
356 
357  '' byval visible as integer = -1
358  if( visible = NULL ) then
359  visible = astNewCONSTi( -1 )
360  end if
361  if( astNewARG( proc, visible ) = NULL ) then
362  exit function
363  end if
364 
365  if( isfunc = FALSE ) then
366  astAdd( proc )
367  end if
368 
369  function = proc
370 
371 end function
372 
373 '':::::
374 function rtlConsoleReadXY _
375  ( _
376  byval rowexpr as ASTNODE ptr, _
377  byval columnexpr as ASTNODE ptr, _
378  byval colorflagexpr as ASTNODE ptr _
379  ) as ASTNODE ptr
380 
381  dim as ASTNODE ptr proc = any
382 
383  function = NULL
384 
385  ''
386  proc = astNewCALL( PROCLOOKUP( CONSOLEREADXY ) )
387 
388  '' byval column as integer
389  if( astNewARG( proc, columnexpr ) = NULL ) then
390  exit function
391  end if
392 
393  '' byval row as integer
394  if( astNewARG( proc, rowexpr ) = NULL ) then
395  exit function
396  end if
397 
398  '' byval colorflag as integer
399  if( colorflagexpr = NULL ) then
400  colorflagexpr = astNewCONSTi( 0 )
401  end if
402  if( astNewARG( proc, colorflagexpr ) = NULL ) then
403  exit function
404  end if
405 
406  function = proc
407 
408 end function
409