home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 June
/
SIMTEL_0692.cdr
/
msdos
/
ddjmag
/
ddj8707.arc
/
HOLUB.LST
< prev
next >
Wrap
File List
|
1987-07-28
|
44KB
|
1,158 lines
Listing 1 -- vbios.c
1| #include <stdio.h>
2| #include <dos.h> /* (Microsoft file) includes for int86() */
3|
4| /* VBIOS.C: Various cursor and i/o routine using
5| * the bios interrupts (see below for greater detail):
6| *----------------------------------------------------------
7| * Copyright (C) 1987 Allen I. Holub. All rights reserved.
8| *----------------------------------------------------------
9| * Externally accessable routines:
10| *
11| * int vb_getpage () Get active video page #
12| * void vb_putchar (c) write a single character
13| * void vb_getchar (c) get a key from the bios.
14| * void vb_puts (s, move) write a string
15| * void vb_replace (c) write char w/o moving cursor
16| * int vb_inchar (attrib) Get character & attribute
17| *
18| * void vb_setcur (posn) Set cur pos as int on cur page
19| * int vb_getcur () Get cur pos as int from cur page
20| * void vb_ctoyx (y,x) Set cursor position to (y,x)
21| * void vb_getyx (&y, &x) Get cursor position
22| *
23| * int vb_iscolor() color monitor installed
24| * void vb_cursize (top,bot) Set cursor size
25| * void vb_blockcur() make a block cursor
26| * void vb_normalcur() revert to a normal cursor
27| *
28| * void vb_scroll(l,r,t,b,a) Scroll region
29| */
30|
31| /*--------------------------------------------------------*/
32|
33| extern int int86( int, union REGS *, union REGS *);
34|
35| /*--------------------------------------------------------*/
36|
37| #define VIDEO_INT 0x10 /* Video interrupt */
38| #define KB_INT 0x16 /* Keyboard interrupt */
39|
40| #define CUR_SIZE 0x1 /* Set cursor size */
41| #define SET_POSN 0x2 /* Modify cursor posn */
42| #define READ_POSN 0x3 /* Read current cursor posn */
43| #define WRITE 0x9 /* Write character */
44| #define WRITE_TTY 0xe /* Write char & move cursor */
45| #define GET_VMODE 0xf /* Get video mode & disp pg */
46|
47| /*--------------------------------------------------------*/
48|
49| static union REGS Regs; /* Used to talk to DOS */
50| static int Attribute; /* Current attribute */
51|
52| /*--------------------------------------------------------*/
53|
54| void vb_scroll( x_left, x_right, y_top, y_bottom, amt )
55| {
56| /* Scroll the indicated region on the screen.
57| * If amt is negative, scroll down.
58| */
59|
60| if( amt < 0 )
61| {
62| Regs.h.ah = 7 ;
63| Regs.h.al = -amt ;
64| }
65| else
66| {
67| Regs.h.ah = 6 ;
68| Regs.h.al = amt ;
69| }
70|
71| Regs.h.bh = 0x07 ;
72| Regs.h.cl = x_left ;
73| Regs.h.ch = y_top ;
74| Regs.h.dl = x_right ;
75| Regs.h.dh = y_bottom ;
76| int86(0x10, &Regs, &Regs);
77| }
78|
79| /*--------------------------------------------------------*/
80|
81| int vb_inchar( attrib )
82| int *attrib;
83| {
84| /* Return the character at the current cursor
85| * position and, if attrib is non-NULL, put the
86| * attribute there. Note that vb_getpage() will mess
87| * up the fields in the Regs structure so it must
88| * be called first.
89| */
90|
91| Regs.h.bh = vb_getpage() ;
92| Regs.h.ah = 8 ;
93|
94| int86( VIDEO_INT, &Regs, &Regs );
95|
96| if( attrib )
97| *attrib = Regs.h.ah & 0xff ;
98|
99| return( Regs.h.al & 0xff );
100| }
101|
102| /*--------------------------------------------------------*/
103|
104| int vb_getpage()
105| {
106| /* Returns the currently active display page number
107| */
108|
109| Regs.h.ah = GET_VMODE;
110| int86( VIDEO_INT, &Regs, &Regs );
111|
112| return (int) Regs.h.bh ;
113| }
114|
115| /*--------------------------------------------------------*/
116|
117| void vb_cursize( top_line, bot_line )
118| {
119| /* Scan lines are numberd 0 at the top and 7 at the
120| * bottom on the color card. On the monochrome card
121| * they're 0-12. If top & bot are reversed you'll
122| * get a 2 part cursor. Top_line determines the
123| * position of the top scan line of the cursor,
124| * bot_line is the bottom. A normal cursor can be
125| * created with vb_cursize(6,7). Cursize(0,7) will
126| * fill the entire area occupied by a character.
127| * Cursize(0,1) will put a line over the character
128| * rather than under it.
129| */
130|
131| Regs.h.ch = top_line ;
132| Regs.h.cl = bot_line ;
133| Regs.h.ah = CUR_SIZE ;
134| int86( VIDEO_INT, &Regs, &Regs );
135| }
136|
137| /*--------------------------------------------------------*/
138|
139| int vb_iscolor() /* Returns true if a color card is active */
140| {
141| Regs.h.ah = GET_VMODE ;
142| int86( VIDEO_INT, &Regs, &Regs );
143| return( Regs.h.al != 7 );
144| }
145|
146| void vb_blockcur() /* Make the cursor a block curser */
147| {
148| vb_cursize( 0, vb_iscolor() ? 7 : 12 );
149| }
150|
151| void vb_normalcur() /* Make it an underline cursor */
152| {
153| if( vb_iscolor() )
154| vb_cursize( 6, 7 );
155| else
156| vb_cursize( 11, 12 );
157| }
158|
159| /*--------------------------------------------------------*/
160|
161| void vb_setcur( posn )
162| int posn;
163| {
164| /* Modify current cursor position. The top byte of
165| * "posn" value holds the row (y), the bottom byte,
166| * the column (x). The top-left corner of the screen
167| * is (0,0). Pagenum is the video page number. Note
168| * that vb_getpage() will mess up the fields in the
169| * Regs structure so it must be called first.
170| */
171|
172| Regs.h.bh = vb_getpage() ;
173| Regs.x.dx = posn ;
174| Regs.h.ah = SET_POSN ;
175| int86( VIDEO_INT, &Regs, &Regs );
176| }
177|
178| int vb_getcur()
179| {
180| /* Get current cursor position. The top byte of the
181| * return value holds the row, the bottom by the
182| * column. Pagenum is the video page number. Note
183| * that vb_getpage() will mess up the fields in the
184| * Regs structure so it must be called first.
185| */
186|
187| Regs.h.bh = vb_getpage() ;
188| Regs.h.ah = READ_POSN ;
189| int86( VIDEO_INT, &Regs, &Regs );
190| return( Regs.x.dx );
191| }
192|
193| /*----------------------------------------------------------
194| * vb_cotyx() and vb_getyx also get the cursor position.
195| * They use x and y values, however.
196| */
197|
198| void vb_ctoyx ( y, x )
199| {
200| vb_setcur( (y << 8) | (x & 0xff) );
201| }
202|
203| void vb_getyx( yp, xp )
204| int *yp, *xp;
205| {
206| register int posn;
207|
208| posn = vb_getcur();
209| *xp = posn & 0xff ;
210| *yp = (posn >> 8) & 0xff ;
211| }
212|
213| /*--------------------------------------------------------*/
214|
215| vb_replace(c)
216| {
217| /* Overwrite the character at the current cursor
218| * position without moving the cursor.
219| */
220|
221| Regs.h.ah = 10 ;
222| Regs.h.al = c; /* write c */
223| Regs.h.bl = 0x07; /* Normal characters */
224| Regs.h.bh = 0; /* Display page 0 */
225| Regs.x.cx = 1; /* # of times to write */
226|
227| int86( VIDEO_INT, &Regs, &Regs );
228| }
229|
230| /*--------------------------------------------------------*/
231|
232| vb_putchar( c )
233| {
234| /* Write a character to the screen in TTY mode.
235| * Only normal printing characters, BS, BEL, CR and
236| * LF are recognized. The cursor is automatically
237| * advanced and lines will wrap.
238| */
239|
240| Regs.h.bl = 0x07;
241| Regs.h.al = c;
242| Regs.h.ah = WRITE_TTY ;
243| int86( VIDEO_INT, &Regs, &Regs );
244| }
245|
246| /*--------------------------------------------------------*/
247|
248| vb_puts( str, move_cur )
249| register char *str;
250| {
251| /* Write a string to the screen in TTY mode. If
252| * move_cur is true the cursor is left at the end
253| * of string. If not the cursor will be restored to
254| * its original position (before the write).
255| */
256|
257| register int posn;
258|
259| if( !move_cur )
260| posn = vb_getcur();
261|
262| while( *str )
263| vb_putchar( *str++ );
264|
265| if( !move_cur )
266| vb_setcur( posn );
267| }
268|
269| /*--------------------------------------------------------*/
270|
271| int vb_getchar()
272| {
273| /* Get a character with a direct video bios call.
274| * This routine can be used to complement stderr as
275| * it can be used to get characters from the keyboard,
276| * even when input redirected. The typed character
277| * is returned in the low byte of the returned
278| * integer, the high byte holds the auxillary byte
279| * used to mark ALT keys and such. See the Technical
280| * Reference for more info.
281| */
282|
283| Regs.h.ah = 0 ;
284| int86( KB_INT, &Regs, &Regs );
285| return( (int)Regs.x.ax );
286| }
287|
288| /*--------------------------------------------------------*/
289| #ifdef MAIN
290|
291| main()
292| {
293| vb_replace( 'X' );
294| vb_putchar('\n');
295| vb_putchar('\r');
296| }
297|
298| #endif