Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

Video Controller 6845
[Device Drivers]


Functions

bool move_cur (console_t *console)
 Refresh cursor position for a selected console.
Parameters:
console  The selected console address.
Returns:
  • TRUE if the current console is the foreground console;
  • FALSE otherwise.
Note:
There is no reason to refresh the cursor if the selected console is not the foreground console. In this case the function returns a value of FALSE.


void k_clrscr (console_t *console)
 Clear the screen of the selected console.
Parameters:
console  The selected console address.


word k_get_cur_pos (console_t *console)
 Get the cursor position of the selected console.
Parameters:
console  The selected console address.
Returns:
The cursor position (in characters from the beginning of the video buffer).


bool k_set_cur_pos (console_t *console, word pos)
 Set the cursor position of the selected console.
Parameters:
console  The selected console address.
pos  The cursor position (in characters from the beginning of the video buffer).
Returns:
  • TRUE on success;
  • FALSE if the position is over the buffer.


byte k_get_color (console_t *console)
 Get the current color of the selected console.
Parameters:
console  The selected console address.
Returns:
The current color code (see console.h).


void k_set_color (console_t *console, byte attrib)
 Set the current color of the selected console.
Parameters:
console  The selected console address.
attrib  The current color code (see console.h).


void k_scroll_up (console_t *console)
 Scroll up the screen of the selected console.
Parameters:
console  The selected console address.


void k_gotoxy (console_t *console, int x, int y)
 Set the (x, y) coordinates as the current position in the selected console.
Parameters:
console  The selected console address.
x  The column position.
y  The row position.


void _kputchar (console_t *console, byte c)
 Put a character in the selected console.
Parameters:
console  The selected console address.
c  The ASCII code of the character to print.


byte k_get_crt_height ()
 Get the CRT height (in characters).
Returns:
The CRT heitht.


byte k_get_crt_width ()
 Get the CRT width (in characters).
Returns:
The CRT width.


void init_video ()
 Initialize the video parameters.


Variables

word crt_port
 Video base address port.

byte crt_width
 Video width (columns).

byte crt_height
 Video height (rows).


Detailed Description

The low level video controller 6845 driver.

Function Documentation

void _kputchar console_t   console,
byte    c
 

Put a character in the selected console.

Parameters:
console  The selected console address.
c  The ASCII code of the character to print.

Definition at line 185 of file video.c.

00186 {
00187         switch (c)
00188         {
00189                 case '\n':
00190                         (console->cur_pos)+=crt_width;
00191                         (console->cur_pos)-=(console->cur_pos)%crt_width;
00192                         break;
00193                 case '\r':
00194                         (console->cur_pos)-=(console->cur_pos)%crt_width;
00195                         break;
00196                 case '\b':
00197                         if ((console->cur_pos) > 0)
00198                         {
00199                                 (console->vid_buffer)[--(console->cur_pos)] =
00200                                         ((console->cur_color) <<8 ) | ' ';
00201                         }
00202                         break;
00203                 case '\t':
00204                         (console->cur_pos)+=8;
00205                         break;
00206                 case '\a': // CTRL+G => system beep! //
00207                         beep();
00208                         return;
00209                         break;
00210 
00211                 default:
00212                 {
00213                         (console->vid_buffer)[console->cur_pos] = ((console->cur_color) << 8) | c;
00214                         (console->cur_pos)++;
00215                 }
00216         }
00217 
00218         // Check if cursor is at the bottom of the screen               //
00219         if ( console->cur_pos >= (crt_width * crt_height) )
00220                 k_scroll_up(console);
00221 
00222         move_cur(console);
00223 }

void init_video  
 

Initialize the video parameters.

Definition at line 240 of file video.c.

00241 {
00242         crt_port=0x3D4;
00243         crt_width=80;
00244         crt_height=25;
00245 }

void k_clrscr console_t   console
 

Clear the screen of the selected console.

Parameters:
console  The selected console address.

Definition at line 70 of file video.c.

00071 {
00072         dword IF = GET_IF();
00073 
00074         disable();
00075 
00076         memsetw((void *)(console->vid_buffer), BLANK, crt_width*crt_height);
00077         console->cur_pos=0;
00078 
00079         SET_IF(IF);
00080 
00081         move_cur(console);
00082 }

byte k_get_color console_t   console
 

Get the current color of the selected console.

Parameters:
console  The selected console address.
Returns:
The current color code (see console.h).

Definition at line 116 of file video.c.

00117 {
00118         return(console->cur_color);
00119 }

byte k_get_crt_height  
 

Get the CRT height (in characters).

Returns:
The CRT heitht.

Definition at line 227 of file video.c.

00228 {
00229         return( crt_height );
00230 }

byte k_get_crt_width  
 

Get the CRT width (in characters).

Returns:
The CRT width.

Definition at line 234 of file video.c.

00235 {
00236         return( crt_width );
00237 }

word k_get_cur_pos console_t   console
 

Get the cursor position of the selected console.

Parameters:
console  The selected console address.
Returns:
The cursor position (in characters from the beginning of the video buffer).

Definition at line 89 of file video.c.

00090 {
00091         return(console->cur_pos);
00092 }

void k_gotoxy console_t   console,
int    x,
int    y
 

Set the (x, y) coordinates as the current position in the selected console.

Parameters:
console  The selected console address.
x  The column position.
y  The row position.

Definition at line 159 of file video.c.

00160 {
00161         dword IF = GET_IF();
00162 
00163         // Round x, y to CRT bounds                                     //
00164         if (x != -1)
00165                 x = x % crt_width;
00166         else
00167                 x = console->cur_pos % crt_width;
00168 
00169         if (y != -1)
00170                 y = y % crt_height;
00171         else
00172                 y = console->cur_pos / crt_width;
00173 
00174         disable();
00175         console->cur_pos = y*crt_width + x;
00176 
00177         SET_IF(IF);
00178 
00179         move_cur(console);
00180 }

void k_scroll_up console_t   console
 

Scroll up the screen of the selected console.

Parameters:
console  The selected console address.

Definition at line 131 of file video.c.

00132 {
00133         dword IF = GET_IF();
00134 
00135         disable();
00136 
00137         // Scroll up                                                    //
00138         memcpy( (void *)(console->vid_buffer),
00139                 ((void *)(console->vid_buffer))+crt_width*2,
00140                 crt_width*(crt_height-1)*2 );
00141 
00142         // Blank the bottom line of the screen                          //
00143         memsetw((void *)( ((void *)(console->vid_buffer)) + crt_width*(crt_height-1)*2),
00144                  BLANK, crt_width);
00145 
00146         (console->cur_pos)-=crt_width;
00147 
00148         SET_IF(IF);
00149 
00150         move_cur(console);
00151 }

void k_set_color console_t   console,
byte    attrib
 

Set the current color of the selected console.

Parameters:
console  The selected console address.
attrib  The current color code (see console.h).

Definition at line 124 of file video.c.

00125 {
00126         console->cur_color = attrib;
00127 }

bool k_set_cur_pos console_t   console,
word    pos
 

Set the cursor position of the selected console.

Parameters:
console  The selected console address.
pos  The cursor position (in characters from the beginning of the video buffer).
Returns:
  • TRUE on success;
  • FALSE if the position is over the buffer.

Definition at line 102 of file video.c.

00103 {
00104         if ( pos < (crt_width*crt_height) )
00105         {
00106                 console->cur_pos = pos;
00107                 move_cur(console);
00108                 return(TRUE);
00109         }
00110         return(FALSE);
00111 }

bool move_cur console_t   console
 

Refresh cursor position for a selected console.

Parameters:
console  The selected console address.
Returns:
  • TRUE if the current console is the foreground console;
  • FALSE otherwise.
Note:
There is no reason to refresh the cursor if the selected console is not the foreground console. In this case the function returns a value of FALSE.

Definition at line 44 of file video.c.

00045 {
00046         dword IF = GET_IF();
00047 
00048         disable();
00049 
00050         // Move the cursor only in the current console                  //
00051         if ( (console == get_console_addr(0)) )
00052         {
00053                 // Refresh video cursor position with cur_pos value.    //
00054                 // Registers 14-15 tell the 6845 where to put the       //
00055                 // cursor.                                              //
00056                 outportb(crt_port + 0, 14);
00057                 outportb(crt_port + 1, (console->cur_pos) >> 8);
00058                 outportb(crt_port + 0, 15);
00059                 outportb(crt_port + 1, (console->cur_pos));
00060                 SET_IF(IF);
00061                 return(TRUE);
00062         }
00063         SET_IF(IF);
00064         return(FALSE);
00065 }


Variable Documentation

byte crt_height
 

Video height (rows).

Definition at line 33 of file video.c.

word crt_port
 

Video base address port.

Definition at line 29 of file video.c.

byte crt_width
 

Video width (columns).

Definition at line 31 of file video.c.


Generated on Fri Feb 20 15:32:23 2004 for Minirighi by doxygen1.2.18