Wednesday, December 30, 2009

The prototype functions, structures, variables, and constants

[DOS | TC2/BC3]
The prototype functions, structures, variables, and constants that are used for handling console in Turbo C 2.1 or Borland C 3.1 are stored in the header-file conio.h

Structure:
text_info struct (
unsigned char winleft;
unsigned char wintop;
unsigned char winright;
unsigned char winbottom;
unsigned char attribute;
unsigned char normattr;
unsigned char currmode;
unsigned char screenheight;
unsigned char screenwidth;
unsigned char curx;
unsigned char cury;
);

Text mode:
-1 Or LASTMODE
0 or BW40
1 or C40
2 or BW80
3 or C80
7 or MONO
64 or C4350 ---> BC3



Color:
0 or BLACK
1 or Blue,
2 or GREEN,
3 or cyan,
4 or RED,
5 or MAGENTA,
6 or BROWN,
7 or LIGHTGRAY,
8 or DARKGRAY,
9 or LIGHTBLUE,
10 or lightgreen,
11 or LIGHTCYAN,
12 or LIGHTRED,
13 or LIGHTMAGENTA,
14 or YELLOW,
15 or WHITE


Blinking:
BLINK 128 or
Cursor mode:
0 or _NOCURSOR
1 or _SOLIDCURSOR
2 or _NORMALCURSOR



Variables:
int directvideo;
int _wscroll; ---> BC3

Complete, the contents of the following conio.h
Code:

/ * Conio.h

Direct MSDOS console input / output.
Copyright (c) 1987, 1992 by Borland International
All Rights Reserved.
* /

# if! defined (__CONIO_H)
# define __CONIO_H
# if! defined (___DEFS_H)
# include <_defs.h>
# endif
# if! defined (_Windows)
# define _NOCURSOR 0
# define _SOLIDCURSOR 1
# define _NORMALCURSOR 2

text_info struct (
unsigned char winleft;
unsigned char wintop;
unsigned char winright;
unsigned char winbottom;
unsigned char attribute;
unsigned char normattr;
unsigned char currmode;
unsigned char screenheight;
unsigned char screenwidth;
unsigned char curx;
unsigned char cury;
);

text_modes enum (LASTMODE =- 1, BW40 = 0, C40, BW80, C80, MONO = 7, C4350 = 64);

# if! defined (__COLORS)
# define __COLORS

enum COLORS (
BLACK, / * dark colors * /
BLUE,
GREEN,
Cyan,
RED,
MAGENTA,
BROWN,
LIGHTGRAY,
DARKGRAY, / * light colors * /
LIGHTBLUE,
Lightgreen,
LIGHTCYAN,
LIGHTRED,
LIGHTMAGENTA,
YELLOW,
WHITE
);
# endif



# define BLINK 128 / * blink bits * /
extern int _Cdecl directvideo;
extern int _Cdecl _wscroll;
# endif / *! _Windows * /
# ifdef __cplusplus
extern "C" (
# endif



_Cdecl clreol void (void);
_Cdecl void clrscr (void);
_Cdecl void gotoxy (int __x, int __y);
_Cdecl int wherex (void);
int _Cdecl wherey (void);
_Cdecl int getch (void);
int _Cdecl getche (void);
int _Cdecl kbhit (void);
int _Cdecl putch (int __c);


# ifndef _PORT_DEFS
unsigned char _Cdecl inportb (__portid unsigned);
_Cdecl unsigned inport (unsigned __portid);
IVI _Cdecl int (__portid unsigned);
unsigned _Cdecl inpw (__portid unsigned);
_Cdecl void outportb (unsigned __portid, __value unsigned char);
_Cdecl void outport (unsigned __portid, __value unsigned);
_Cdecl int outp (unsigned __portid, __value int);
unsigned _Cdecl outpw (__portid unsigned, unsigned __value);

# endif / *! _PORT_DEFS * /
# if! defined (_Windows)
_Cdecl delline void (void);
int _Cdecl gettext (__left int, int __top,
__right int, int __bottom,
__destin void *);
void _Cdecl gettextinfo (struct text_info * __r);
_Cdecl highvideo void (void);
_Cdecl insline void (void);
_Cdecl lowvideo void (void);
int _Cdecl movetext (__left int, int __top,
__right int, int __bottom,
__destleft int, int __desttop);
_Cdecl normvideo void (void);
int _Cdecl puttext (__left int, int __top,
__right int, int __bottom,
__source void *);
void _Cdecl textattr (__newattr int);
void _Cdecl textbackground (__newcolor int);
_Cdecl void textcolor (int __newcolor);
_Cdecl void textmode (int __newmode);
_Cdecl void window (__left int, int __top, __right int, int __bottom);
void _Cdecl _setcursortype (__cur_t int);
_Cdecl cgets char * (char * __str);
_Cdecl int cprintf (const char * __format, ...);
int _Cdecl cputs (const char * __str);
int _Cdecl cscanf (const char * __format, ...);
char * _Cdecl getpass (const char * __prompt);
int _Cdecl ungetch (__ch int);


# endif / *! _Windows * /
# ifndef _PORT_DEFS
# define _PORT_DEFS

/ * These are in-line functions. These prototypes just clean up
some syntax checks and code generation.
* /

unsigned char _Cdecl __inportb__ (__portid unsigned);
unsigned _Cdecl __inportw__ (__portid unsigned);
unsigned char _Cdecl __outportb__ (__portid unsigned, unsigned char __value);
unsigned _Cdecl __outportw__ (__portid unsigned, unsigned __value);


# define inportb (__portid) __inportb__ (__portid)
# define outportb (__portid, __value) ((void) __outportb__ (__portid, __value))
# define inport (__portid) __inportw__ (__portid)
# define outport (__portid, __value) ((void) __outportw__ (__portid, __value))


/ * MSC-compatible macros for port I / O * /
# define INP (__portid) __inportb__ (__portid)
# define outp (__portid, __value) __outportb__ (__portid, (unsigned char) __value)
# define inpw (__portid) __inportw__ (__portid)
# define outpw (__portid, __value) __outportw__ (__portid, __value)

# endif / * _PORT_DEFS * /
# ifdef __cplusplus
)
# endif

# endif / * __CONIO_H * /
Source code these functions in the \ crtl \ clib. If you intend to change these functions please select the function in question, change it according to your needs, re-compilation in a particular memory model, and come to the library memory model.

Text_info structure used by the TC / BC can be retrieved by using gettextinfo function.

TC / BC save mode, attributes, and attribute the origin of the text and attribute fields currmode, and normattr.
Attributes consist of text and the text color wana-base (background) the text.
Textcolor function is used to set the text color, textbackground function is used to set the text color-base, while the function is used to set textattr both.
Internal format is a text attribute "kbbbcccc". Leftmost bit (k) is the blinking code, the middle 3 bits (bbb) is the basic color, and 4 last bits (ccc) is the color of the text.

TC / BC set-top left coordinates of the screen as the column 1 row 1 and right-bottom coordinates as row 40/80 column text mode depending on 25/43/50 that is used. But internally it stored in the field winleft, wintop, winright, and winbottom be 0, 0, 39/79, and 24/42/49.

Likewise with the coordinates of the cursor, visually it refers to the coordinates of 1.1 while internally it refers to the coordinates of 0.0 and stored in the field curx and cury.

Information about the height and width of the screen are stored in screenheight and screenwidth.
Textmode functions are used to change the display mode according to the desired text. Prototype of this function are:

void textmode (int newmode);

where newmode are:
-1 Or LASTMODE
0 or BW40
1 or C40
2 or BW80
3 or C80
7 or MONO
64 or C4350 ---> BC3

Example:
Code:

# include
# include
int mode;
int main ()
(
while (1)
(Clrscr ();
printf ( "Mode Text: \ n"
"-1: LASTMODE \ n"
"0: BW40 \ n"
"1: C40 \ n"
"2: BW80 \ n"
"3: C80 \ n"
"7: MONO \ n"
"64: C4350 ---> BC3 \ n"
"99: Finished \ n"
"Select:");
scanf ( "% d", & mode);
switch (mode)
(Case -1:
case 0:
case 1:
case 2:
case 3:
case 7:
case 64:
textmode (mode);
break;
case 99:
return 1;
)
)
)

Attributes consist of text and the text color wana-base (background) the text.
Textcolor function is used to set the text color, textbackground function is used to set the text color-base, while the function is used to set textattr both.

Internal format is a text attribute "kbbbcccc". Leftmost bit (k) is the blinking code, the middle 3 bits (bbb) is the basic color, and 4 last bits (ccc) is the color of the text.

Example:
Code:
# include
int mode;
int main ()
(
clrscr ();
textcolor (YELLOW);
textbackground (BLUE)
cprintf ( "Text is printed in color, based YELLOW BLUE \ r \ n");
textattr (0x2F);
/ *
2 = GREEN
F = WHITE
* /
cprintf ( "Text is printed in color, based WHITE GREEN \ r \ n");
return 1;
)

Putch function is used to store / write one character, a particular coded, to the console. Example:

putch (65);
It can also be written into
putch ( 'A');
The function getch () and getche () is used to retrieve / read a character from the keyboard. This function will return the character code is taken, for example, 65 for the letter 'A'. Getch function will only retrieve / read a character just as getche function will write the character into the console to read it. So, the command
getche ();
same
ch = getch ();
putch (ch);

Getch and getche function will return the value 0 if the character is given a character of the expansion, for example, you press the F1 key. To get the character code is the expansion or getche getch function must be called back. Consider the following example footage.
Code:
...
ch = getch ();
if (ch)
cprintf ( "you press the character codes% d", ch);
else
(Ch = getch ();
cprintf ( "you press the character of the expansion coded% d", ch);
)
...

To simplify the use of these functions, I create a new function named getch as follows.
Code:

# include
int getch (void)
(
int ch;
ch = getch ();
if (! ch)
256 + ch = getch ();
return ch;
)

No comments:

Post a Comment

 
THANK YOU FOR VISITING