SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

Diff markup

Differences between /drivers/x86_videomem.c (Article 6) and /drivers/x86_videomem.c (Article 9)


001 /* Copyright (C) 2004  David Decotigny            001 /* Copyright (C) 2004  David Decotigny
002    Copyright (C) 1999  Free Software Foundatio << 
003                                                   002 
004    This program is free software; you can redi    003    This program is free software; you can redistribute it and/or
005    modify it under the terms of the GNU Genera    004    modify it under the terms of the GNU General Public License
006    as published by the Free Software Foundatio    005    as published by the Free Software Foundation; either version 2
007    of the License, or (at your option) any lat    006    of the License, or (at your option) any later version.
008                                                !! 007 
009    This program is distributed in the hope tha    008    This program is distributed in the hope that it will be useful,
010    but WITHOUT ANY WARRANTY; without even the     009    but WITHOUT ANY WARRANTY; without even the implied warranty of
011    MERCHANTABILITY or FITNESS FOR A PARTICULAR    010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012    GNU General Public License for more details    011    GNU General Public License for more details.
013                                                !! 012 
014    You should have received a copy of the GNU     013    You should have received a copy of the GNU General Public License
015    along with this program; if not, write to t    014    along with this program; if not, write to the Free Software
016    Foundation, Inc., 59 Temple Place - Suite 3    015    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
017    USA.                                        !! 016    USA.
018 */                                                017 */
019 #include <sos/klibc.h>                            018 #include <sos/klibc.h>
020 #include <hwcore/ioports.h>                       019 #include <hwcore/ioports.h>
021                                                   020 
022 #include "x86_videomem.h"                         021 #include "x86_videomem.h"
023                                                   022 
024 /* The text video memory starts at address 0xB    023 /* The text video memory starts at address 0xB8000. Odd bytes are the
025    ASCII value of the character, even bytes ar    024    ASCII value of the character, even bytes are attribute for the
026    preceding character. */                        025    preceding character. */
027 #define VIDEO   0xb8000                           026 #define VIDEO   0xb8000
028                                                   027 
029                                                   028 
030 /* Console screen size */                         029 /* Console screen size */
031 #define LINES   25                                030 #define LINES   25
032 #define COLUMNS 80                                031 #define COLUMNS 80
033                                                   032 
                                                   >> 033 /*
                                                   >> 034  * VGA ports and commands.
                                                   >> 035  * 
                                                   >> 036  * @see Ralf Brown's interrupt (and port) list   
                                                   >> 037  * http://www-2.cs.cmu.edu/~ralf/files.html      
                                                   >> 038  */
                                                   >> 039 
                                                   >> 040 /* VGA ports */
                                                   >> 041 #define VGA_COMMAND_PORT 0x3D4
                                                   >> 042 #define VGA_DATA_PORT    0x3D5
                                                   >> 043 
                                                   >> 044 /* VGA commands */
                                                   >> 045 #define VGA_SET_CURSOR_START 0xA
                                                   >> 046 #define VGA_SET_CURSOR_END   0xB
                                                   >> 047 #define VGA_SET_CURSOR_HIGH  0xE
                                                   >> 048 #define VGA_SET_CURSOR_LOW   0xF
034                                                   049 
035 /** The structure of a character element in th    050 /** The structure of a character element in the video memory. @see
036     http://webster.cs.ucr.edu/AoA DOS edition     051     http://webster.cs.ucr.edu/AoA DOS edition chapter 23 */
037 typedef struct {                                  052 typedef struct {
038   unsigned char character;                        053   unsigned char character;
039   unsigned char attribute;                        054   unsigned char attribute;
040 } __attribute__ ((packed)) x86_video_mem[LINES    055 } __attribute__ ((packed)) x86_video_mem[LINES*COLUMNS];
041                                                   056 
042                                                   057 
043                                                   058 
044 /** The base pointer for the video memory */      059 /** The base pointer for the video memory */
045 static volatile x86_video_mem *video = (volati    060 static volatile x86_video_mem *video = (volatile x86_video_mem*)VIDEO;
046                                                   061 
047 sos_ret_t sos_x86_videomem_setup(void)            062 sos_ret_t sos_x86_videomem_setup(void)
048 {                                                 063 {
049   /*                                           << 
050    * Hide cursor. @see Ralf Brown's interrupt  << 
051    * http://www-2.cs.cmu.edu/~ralf/files.html  << 
052    */                                          << 
053 #define CRT_REG_INDEX 0x3d4                    << 
054 #define CRT_REG_DATA  0x3d5                    << 
055                                                << 
056   /* CRT index port => ask for access to regis    064   /* CRT index port => ask for access to register 0xa ("cursor
057      start") */                                   065      start") */
058   outb(0x0a, CRT_REG_INDEX);                   !! 066   outb(0x0a, VGA_COMMAND_PORT);
059                                                   067 
060   /* (RBIL Tables 708 & 654) CRT Register 0xa     068   /* (RBIL Tables 708 & 654) CRT Register 0xa => bit 5 = cursor OFF */
061   outb(1 << 5, CRT_REG_DATA);                  !! 069   outb(1 << 5, VGA_DATA_PORT);
062                                                   070 
063   return SOS_OK;                                  071   return SOS_OK;
064 }                                                 072 }
065                                                   073 
066                                                   074 
067 sos_ret_t sos_x86_videomem_cls(unsigned char a    075 sos_ret_t sos_x86_videomem_cls(unsigned char attribute)
068 {                                                 076 {
069   /* Clears the screen */                         077   /* Clears the screen */
070   int i;                                          078   int i;
071   for(i = 0 ; i < LINES*COLUMNS ; i++)            079   for(i = 0 ; i < LINES*COLUMNS ; i++)
072     {                                             080     {
073       (*video)[i].character = 0;                  081       (*video)[i].character = 0;
074       (*video)[i].attribute = attribute;          082       (*video)[i].attribute = attribute;
075     }                                             083     }
076                                                   084 
077   return SOS_OK;                               !! 085   return SOS_OK;
078 }                                                 086 }
079                                                   087 
080                                                   088 
081 sos_ret_t sos_x86_videomem_putstring(unsigned     089 sos_ret_t sos_x86_videomem_putstring(unsigned char row, unsigned char col,
082                                      unsigned     090                                      unsigned char attribute,
083                                      const cha    091                                      const char *str)
084 {                                                 092 {
085   unsigned video_offs = row*COLUMNS + col;        093   unsigned video_offs = row*COLUMNS + col;
086                                                   094 
087   if (video_offs >= LINES*COLUMNS)                095   if (video_offs >= LINES*COLUMNS)
088     return -SOS_EINVAL;                           096     return -SOS_EINVAL;
089                                                !! 097 
090   for ( ; str && *str && (video_offs < LINES*C    098   for ( ; str && *str && (video_offs < LINES*COLUMNS) ; str++, video_offs++)
091     {                                             099     {
092       (*video)[video_offs].character = (unsign    100       (*video)[video_offs].character = (unsigned char)*str;
093       (*video)[video_offs].attribute = attribu    101       (*video)[video_offs].attribute = attribute;
094     }                                             102     }
095                                                   103 
096   return SOS_OK;                                  104   return SOS_OK;
097 }                                                 105 }
098                                                   106 
099                                                   107 
100 sos_ret_t sos_x86_videomem_putchar(unsigned ch    108 sos_ret_t sos_x86_videomem_putchar(unsigned char row, unsigned char col,
101                                    unsigned ch    109                                    unsigned char attribute,
102                                    unsigned ch    110                                    unsigned char c)
103 {                                                 111 {
104   unsigned video_offs = row*COLUMNS + col;        112   unsigned video_offs = row*COLUMNS + col;
105                                                   113 
106   if (video_offs >= LINES*COLUMNS)                114   if (video_offs >= LINES*COLUMNS)
107     return -SOS_EINVAL;                           115     return -SOS_EINVAL;
108                                                !! 116 
109   (*video)[video_offs].character = c;             117   (*video)[video_offs].character = c;
110   (*video)[video_offs].attribute = attribute;     118   (*video)[video_offs].attribute = attribute;
111                                                   119 
112   return SOS_OK;                                  120   return SOS_OK;
113 }                                                 121 }
114                                                   122 
115                                                   123 
116 sos_ret_t sos_x86_videomem_printf(unsigned cha    124 sos_ret_t sos_x86_videomem_printf(unsigned char row, unsigned char col,
117                                   unsigned cha    125                                   unsigned char attribute,
118                                   const char *    126                                   const char *format, /* args */...)
119 {                                                 127 {
120   char buff[256];                                 128   char buff[256];
121   va_list ap;                                     129   va_list ap;
122                                                !! 130 
123   va_start(ap, format);                           131   va_start(ap, format);
124   vsnprintf(buff, sizeof(buff), format, ap);      132   vsnprintf(buff, sizeof(buff), format, ap);
125   va_end(ap);                                     133   va_end(ap);
126                                                !! 134 
127   return sos_x86_videomem_putstring(row, col,     135   return sos_x86_videomem_putstring(row, col, attribute, buff);
                                                   >> 136 }
                                                   >> 137 
                                                   >> 138 
                                                   >> 139 /*
                                                   >> 140  * Console that supports scrolling, based on the low-level code
                                                   >> 141  * above. This console only takes part of the screen, starting at row
                                                   >> 142  * CONSOLE_ROW_START. The rows before that one are free for use by the
                                                   >> 143  * kernel debugging messages.
                                                   >> 144  */
                                                   >> 145 
                                                   >> 146 /* Current row in the high-level console. Must be signed, because of
                                                   >> 147    computations inside sos_screen_putchar() */
                                                   >> 148 static int row;
                                                   >> 149 
                                                   >> 150 /* Current column in the high-level console. Must be signed, because
                                                   >> 151    of computations inside sos_screen_putchar() */
                                                   >> 152 static int col;
                                                   >> 153 
                                                   >> 154 /* The limit between the low-level console, accessible to the kernel,
                                                   >> 155    and the high-level console, accessible to the user applications
                                                   >> 156    through the sos_screen_putchar() function. */
                                                   >> 157 #define CONSOLE_ROW_START 12
                                                   >> 158 
                                                   >> 159 static void sos_screen_set_cursor (unsigned int row, unsigned int col)
                                                   >> 160 {
                                                   >> 161   unsigned int pos;
                                                   >> 162 
                                                   >> 163   pos = (row * COLUMNS + col);
                                                   >> 164 
                                                   >> 165   outb(VGA_SET_CURSOR_HIGH, VGA_COMMAND_PORT);
                                                   >> 166   outb( (pos >> 8), VGA_DATA_PORT);
                                                   >> 167   outb(VGA_SET_CURSOR_LOW, VGA_COMMAND_PORT);
                                                   >> 168   outb( (pos & 0xFF), VGA_DATA_PORT);
                                                   >> 169 }
                                                   >> 170 
                                                   >> 171 sos_ret_t sos_screen_putchar (char c)
                                                   >> 172 {
                                                   >> 173   if (c == '\r')
                                                   >> 174     {
                                                   >> 175       /* Go to first row */
                                                   >> 176       col = 0;
                                                   >> 177     }
                                                   >> 178 
                                                   >> 179   /* New line */
                                                   >> 180   else if (c == '\n')
                                                   >> 181     {
                                                   >> 182       /* Go to next line */
                                                   >> 183       col = 0;
                                                   >> 184       row ++;
                                                   >> 185     }
                                                   >> 186 
                                                   >> 187   /* Remove the last character */
                                                   >> 188   else if (c == '\b')
                                                   >> 189     {
                                                   >> 190       /* Next character should be displayed instead of the current
                                                   >> 191          one */
                                                   >> 192       col --;
                                                   >> 193 
                                                   >> 194       /* Handle the case where we're at the beginning of a line */
                                                   >> 195       if (col < 0)
                                                   >> 196         {
                                                   >> 197           row --;
                                                   >> 198           col = COLUMNS-1;
                                                   >> 199 
                                                   >> 200           if (row < CONSOLE_ROW_START)
                                                   >> 201             {
                                                   >> 202               row = CONSOLE_ROW_START;
                                                   >> 203               col = 0;
                                                   >> 204             }
                                                   >> 205         }
                                                   >> 206 
                                                   >> 207       /* Replace the current character with a space */
                                                   >> 208       sos_x86_videomem_putchar
                                                   >> 209         (row, col, SOS_X86_VIDEO_FG_BLUE | SOS_X86_VIDEO_BG_LTGRAY, ' ');
                                                   >> 210     }
                                                   >> 211   else if (c != 0)
                                                   >> 212     {
                                                   >> 213       sos_x86_videomem_putchar
                                                   >> 214         (row, col, SOS_X86_VIDEO_FG_BLUE | SOS_X86_VIDEO_BG_LTGRAY, c);
                                                   >> 215       col++;
                                                   >> 216       if (col == COLUMNS)
                                                   >> 217         {
                                                   >> 218           col = 0;
                                                   >> 219           row++;
                                                   >> 220         }
                                                   >> 221     }
                                                   >> 222 
                                                   >> 223   /* Need to scroll ? */
                                                   >> 224   if (row == LINES)
                                                   >> 225     {
                                                   >> 226       int i;
                                                   >> 227 
                                                   >> 228       /* Copy each line in the previous line */
                                                   >> 229       for (i = CONSOLE_ROW_START; i < LINES; i++)
                                                   >> 230         memcpy ((char*) video + i * COLUMNS * 2,
                                                   >> 231                 (char*) video + ((i + 1) * COLUMNS * 2),
                                                   >> 232                 COLUMNS * 2);
                                                   >> 233 
                                                   >> 234       /* Reset the last line of the console */
                                                   >> 235       for (i = 0; i < COLUMNS; i++)
                                                   >> 236         sos_x86_videomem_putchar
                                                   >> 237           (LINES-1, i, SOS_X86_VIDEO_FG_BLUE | SOS_X86_VIDEO_BG_LTGRAY, ' ');
                                                   >> 238 
                                                   >> 239       row--;
                                                   >> 240     }
                                                   >> 241 
                                                   >> 242   sos_screen_set_cursor (row, col);
                                                   >> 243 
                                                   >> 244   return SOS_OK;
                                                   >> 245 }
                                                   >> 246 
                                                   >> 247 sos_ret_t sos_screen_init (void)
                                                   >> 248 {
                                                   >> 249   int i, j;
                                                   >> 250 
                                                   >> 251   row = CONSOLE_ROW_START;
                                                   >> 252   col = 0;
                                                   >> 253 
                                                   >> 254   /* Set the first scan line for the cursor, and the blinking
                                                   >> 255      mode. First scan line is 11, so that we have a visible
                                                   >> 256      cursor. */
                                                   >> 257   outb(VGA_SET_CURSOR_START, VGA_COMMAND_PORT);
                                                   >> 258   outb(((0x2 << 5) | 14), VGA_DATA_PORT);
                                                   >> 259 
                                                   >> 260   for (i = CONSOLE_ROW_START; i < LINES; i++)
                                                   >> 261     {
                                                   >> 262       for (j = 0; j < COLUMNS; j++)
                                                   >> 263         sos_x86_videomem_putchar
                                                   >> 264           (i, j, SOS_X86_VIDEO_FG_BLUE | SOS_X86_VIDEO_BG_LTGRAY, ' ');
                                                   >> 265     }
                                                   >> 266 
                                                   >> 267   sos_screen_set_cursor (row, col);
                                                   >> 268 
                                                   >> 269   return SOS_OK;
128 }                                                 270 }
                                                      

source navigation ] diff markup ] identifier search ] general search ]