FreeBASIC  0.91.0
io_locate.c
Go to the documentation of this file.
1 /* console LOCATE statement */
2 
3 #include "../fb.h"
4 #include "fb_private_console.h"
5 #include <go32.h>
6 #include <dpmi.h>
7 #include <sys/farptr.h>
8 
9 /* Raw DOS console cursor positioning function, faster than console LOCATE */
10 unsigned short fb_hSetCursorPos( int col, int row )
11 {
12  unsigned long addr = 0x450 + __fb_con.active * sizeof( short );
13 
14  if( row >= 0 ) {
15  unsigned short old = _farpeekw( _dos_ds, addr );
16  _farpokew( _dos_ds, addr, (row << 8) | col );
17  return old;
18  } else {
19  _farpokew( _dos_ds, addr, col );
20  return 0;
21  }
22 }
23 
24 int fb_ConsoleLocate_BIOS( int row, int col, int cursor )
25 {
26  __dpmi_regs regs;
27  int x, y;
28  int shape_visible;
29  unsigned short usShapePos, usShapeSize;
30 
31  usShapePos = _farpeekw( _dos_ds, 0x450 + __fb_con.active * sizeof( short ) );
32  usShapeSize = _farpeekw( _dos_ds, 0x460 );
33  shape_visible = (usShapeSize & 0xC000)==0x0000;
34 
35  if( col >= 0 )
36  x = col;
37  else
38  x = usShapePos & 0xFF;
39 
40  if( row >= 0 )
41  y = row;
42  else
43  y = (usShapePos >> 8) & 0xFF;
44 
45  /* !!!FIXME!!! is this really needed? */
46  regs.x.ax = 0x0200;
47  regs.x.bx = __fb_con.active;
48  regs.h.dh = (unsigned char) y;
49  regs.h.dl = (unsigned char) x;
50  __dpmi_int(0x10, &regs);
51 
52  _farpokew( _dos_ds, 0x450 + __fb_con.active * sizeof( short ), (y << 8) | x );
53 
54  if( cursor >= 0)
55  {
56  int shape_start, shape_end;
57 
58  shape_start = (usShapeSize >> 8) & 0x1F;
59  shape_end = usShapeSize & 0x1F;
60  shape_visible = cursor!=0;
61 
62  regs.x.ax = 0x0100;
63  regs.h.ch = (unsigned char) (shape_start + (shape_visible ? 0x00 : 0x20));
64  regs.h.cl = (unsigned char) shape_end;
65  __dpmi_int(0x10, &regs);
66  }
67 
68  return ( (x & 0xFF) | ((y & 0xFF) << 8) | (shape_visible ? 0x10000 : 0) );
69 }
70 
71 int fb_ConsoleLocate( int row, int col, int cursor )
72 {
73  int result = fb_ConsoleLocate_BIOS( row-1, col-1, cursor );
75  return result + 0x0101;
76 }