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

video.c

Go to the documentation of this file.
00001 /*!     \file drivers/video/video.c
00002  *      \brief Low level video controller 6845 driver.
00003  *      \author Andrea Righi <drizzt@inwind.it>
00004  *      \date Last update: 2003-11-08
00005  *      \note Copyright (&copy;) 2003 Andrea Righi
00006  */
00007 
00008 #include <const.h>
00009 #include <stdarg.h>
00010 
00011 #include <arch/i386.h>
00012 #include <arch/mem.h>
00013 #include <arch/paging.h>
00014 
00015 #include <kernel/console.h>
00016 #include <kernel/semaphore.h>
00017 #include <kernel/speaker.h>
00018 #include <kernel/task.h>
00019 
00020 #include <kernel/video.h>
00021 
00022 /** \ingroup Drivers
00023  *  \defgroup VideoDriver Video Controller 6845
00024  *  The low level video controller 6845 driver.
00025  *  @{
00026  */
00027 
00028 //! Video base address port.
00029 word    crt_port;
00030 //! Video width (columns).
00031 byte    crt_width;
00032 //! Video height (rows).
00033 byte    crt_height;
00034 
00035 //! \brief Refresh cursor position for a selected console.
00036 //! \param console The selected console address.
00037 //! \return
00038 //!     \li #TRUE if the current console is the foreground console;
00039 //!     \li #FALSE otherwise.
00040 //! \note
00041 //!     There is no reason to refresh the cursor if the selected
00042 //!     console is not the foreground console. In this case the
00043 //!     function returns a value of #FALSE.
00044 bool move_cur(console_t *console)
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 }
00066 
00067 
00068 //! \brief Clear the screen of the selected console.
00069 //! \param console The selected console address.
00070 void k_clrscr(console_t *console)
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 }
00083 
00084 //! \brief Get the cursor position of the selected console.
00085 //! \param console The selected console address.
00086 //! \return
00087 //!     The cursor position (in characters from the beginning
00088 //!     of the video buffer).
00089 word k_get_cur_pos(console_t *console)
00090 {
00091         return(console->cur_pos);
00092 }
00093 
00094 //! \brief Set the cursor position of the selected console.
00095 //! \param console The selected console address.
00096 //! \param pos
00097 //!     The cursor position (in characters from the beginning
00098 //!     of the video buffer).
00099 //! \return
00100 //!     \li #TRUE on success;
00101 //!     \li #FALSE if the position is over the buffer.
00102 bool k_set_cur_pos(console_t *console, word pos)
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 }
00112 
00113 //! \brief Get the current color of the selected console.
00114 //! \param console The selected console address.
00115 //! \return The current color code (see console.h).
00116 byte k_get_color(console_t *console)
00117 {
00118         return(console->cur_color);
00119 }
00120 
00121 //! \brief Set the current color of the selected console.
00122 //! \param console The selected console address.
00123 //! \param attrib The current color code (see console.h).
00124 void k_set_color(console_t *console, byte attrib)
00125 {
00126         console->cur_color = attrib;
00127 }
00128 
00129 //! \brief Scroll up the screen of the selected console.
00130 //! \param console The selected console address.
00131 void k_scroll_up(console_t *console)
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 }
00152 
00153 //! \brief
00154 //!     Set the (x, y) coordinates as the current position in the
00155 //!     selected console.
00156 //! \param console The selected console address.
00157 //! \param x The column position.
00158 //! \param y The row position.
00159 void k_gotoxy(console_t *console, int x, int y)
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 }
00181 
00182 //! \brief Put a character in the selected console.
00183 //! \param console The selected console address.
00184 //! \param c The ASCII code of the character to print.
00185 void _kputchar(console_t *console, byte 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 }
00224 
00225 //! \brief Get the CRT height (in characters).
00226 //! \return The CRT heitht.
00227 byte k_get_crt_height()
00228 {
00229         return( crt_height );
00230 }
00231 
00232 //! \brief Get the CRT width (in characters).
00233 //! \return The CRT width.
00234 byte k_get_crt_width()
00235 {
00236         return( crt_width );
00237 }
00238 
00239 //! \brief Initialize the video parameters.
00240 void init_video()
00241 {
00242         crt_port=0x3D4;
00243         crt_width=80;
00244         crt_height=25;
00245 }
00246 
00247 /** @} */ // end of VideoDriver

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