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.5) and /drivers/x86_videomem.c (Article 7.5)


001 /* Copyright (C) 2004  David Decotigny            001 /* Copyright (C) 2004  David Decotigny
002                                                   002 
003    This program is free software; you can redi    003    This program is free software; you can redistribute it and/or
004    modify it under the terms of the GNU Genera    004    modify it under the terms of the GNU General Public License
005    as published by the Free Software Foundatio    005    as published by the Free Software Foundation; either version 2
006    of the License, or (at your option) any lat    006    of the License, or (at your option) any later version.
007                                                   007    
008    This program is distributed in the hope tha    008    This program is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the     009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR    010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU General Public License for more details    011    GNU General Public License for more details.
012                                                   012    
013    You should have received a copy of the GNU     013    You should have received a copy of the GNU General Public License
014    along with this program; if not, write to t    014    along with this program; if not, write to the Free Software
015    Foundation, Inc., 59 Temple Place - Suite 3    015    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
016    USA.                                           016    USA. 
017 */                                                017 */
018 #include <sos/klibc.h>                            018 #include <sos/klibc.h>
019 #include <hwcore/ioports.h>                       019 #include <hwcore/ioports.h>
020                                                   020 
021 #include "x86_videomem.h"                         021 #include "x86_videomem.h"
022                                                   022 
023 /* The text video memory starts at address 0xB    023 /* The text video memory starts at address 0xB8000. Odd bytes are the
024    ASCII value of the character, even bytes ar    024    ASCII value of the character, even bytes are attribute for the
025    preceding character. */                        025    preceding character. */
026 #define VIDEO   0xb8000                           026 #define VIDEO   0xb8000
027                                                   027 
028                                                   028 
029 /* Console screen size */                         029 /* Console screen size */
030 #define LINES   25                                030 #define LINES   25
031 #define COLUMNS 80                                031 #define COLUMNS 80
032                                                   032 
033                                                   033 
034 /** The structure of a character element in th    034 /** The structure of a character element in the video memory. @see
035     http://webster.cs.ucr.edu/AoA DOS edition     035     http://webster.cs.ucr.edu/AoA DOS edition chapter 23 */
036 typedef struct {                                  036 typedef struct {
037   unsigned char character;                        037   unsigned char character;
038   unsigned char attribute;                        038   unsigned char attribute;
039 } __attribute__ ((packed)) x86_video_mem[LINES    039 } __attribute__ ((packed)) x86_video_mem[LINES*COLUMNS];
040                                                   040 
041                                                   041 
042                                                   042 
043 /** The base pointer for the video memory */      043 /** The base pointer for the video memory */
044 static volatile x86_video_mem *video = (volati    044 static volatile x86_video_mem *video = (volatile x86_video_mem*)VIDEO;
045                                                   045 
046 sos_ret_t sos_x86_videomem_setup(void)            046 sos_ret_t sos_x86_videomem_setup(void)
047 {                                                 047 {
048   /*                                              048   /*
049    * Hide cursor. @see Ralf Brown's interrupt     049    * Hide cursor. @see Ralf Brown's interrupt (and port) list
050    * http://www-2.cs.cmu.edu/~ralf/files.html     050    * http://www-2.cs.cmu.edu/~ralf/files.html
051    */                                             051    */
052 #define CRT_REG_INDEX 0x3d4                       052 #define CRT_REG_INDEX 0x3d4
053 #define CRT_REG_DATA  0x3d5                       053 #define CRT_REG_DATA  0x3d5
054                                                   054 
055   /* CRT index port => ask for access to regis    055   /* CRT index port => ask for access to register 0xa ("cursor
056      start") */                                   056      start") */
057   outb(0x0a, CRT_REG_INDEX);                      057   outb(0x0a, CRT_REG_INDEX);
058                                                   058 
059   /* (RBIL Tables 708 & 654) CRT Register 0xa     059   /* (RBIL Tables 708 & 654) CRT Register 0xa => bit 5 = cursor OFF */
060   outb(1 << 5, CRT_REG_DATA);                     060   outb(1 << 5, CRT_REG_DATA);
061                                                   061 
062   return SOS_OK;                                  062   return SOS_OK;
063 }                                                 063 }
064                                                   064 
065                                                   065 
066 sos_ret_t sos_x86_videomem_cls(unsigned char a    066 sos_ret_t sos_x86_videomem_cls(unsigned char attribute)
067 {                                                 067 {
068   /* Clears the screen */                         068   /* Clears the screen */
069   int i;                                          069   int i;
070   for(i = 0 ; i < LINES*COLUMNS ; i++)            070   for(i = 0 ; i < LINES*COLUMNS ; i++)
071     {                                             071     {
072       (*video)[i].character = 0;                  072       (*video)[i].character = 0;
073       (*video)[i].attribute = attribute;          073       (*video)[i].attribute = attribute;
074     }                                             074     }
075                                                   075 
076   return SOS_OK;                                  076   return SOS_OK;  
077 }                                                 077 }
078                                                   078 
079                                                   079 
080 sos_ret_t sos_x86_videomem_putstring(unsigned     080 sos_ret_t sos_x86_videomem_putstring(unsigned char row, unsigned char col,
081                                      unsigned     081                                      unsigned char attribute,
082                                      const cha    082                                      const char *str)
083 {                                                 083 {
084   unsigned video_offs = row*COLUMNS + col;        084   unsigned video_offs = row*COLUMNS + col;
085                                                   085 
086   if (video_offs >= LINES*COLUMNS)                086   if (video_offs >= LINES*COLUMNS)
087     return -SOS_EINVAL;                           087     return -SOS_EINVAL;
088                                                   088   
089   for ( ; str && *str && (video_offs < LINES*C    089   for ( ; str && *str && (video_offs < LINES*COLUMNS) ; str++, video_offs++)
090     {                                             090     {
091       (*video)[video_offs].character = (unsign    091       (*video)[video_offs].character = (unsigned char)*str;
092       (*video)[video_offs].attribute = attribu    092       (*video)[video_offs].attribute = attribute;
093     }                                             093     }
094                                                   094 
095   return SOS_OK;                                  095   return SOS_OK;
096 }                                                 096 }
097                                                   097 
098                                                   098 
099 sos_ret_t sos_x86_videomem_putchar(unsigned ch    099 sos_ret_t sos_x86_videomem_putchar(unsigned char row, unsigned char col,
100                                    unsigned ch    100                                    unsigned char attribute,
101                                    unsigned ch    101                                    unsigned char c)
102 {                                                 102 {
103   unsigned video_offs = row*COLUMNS + col;        103   unsigned video_offs = row*COLUMNS + col;
104                                                   104 
105   if (video_offs >= LINES*COLUMNS)                105   if (video_offs >= LINES*COLUMNS)
106     return -SOS_EINVAL;                           106     return -SOS_EINVAL;
107                                                   107   
108   (*video)[video_offs].character = c;             108   (*video)[video_offs].character = c;
109   (*video)[video_offs].attribute = attribute;     109   (*video)[video_offs].attribute = attribute;
110                                                   110 
111   return SOS_OK;                                  111   return SOS_OK;
112 }                                                 112 }
113                                                   113 
114                                                   114 
115 sos_ret_t sos_x86_videomem_printf(unsigned cha    115 sos_ret_t sos_x86_videomem_printf(unsigned char row, unsigned char col,
116                                   unsigned cha    116                                   unsigned char attribute,
117                                   const char *    117                                   const char *format, /* args */...)
118 {                                                 118 {
119   char buff[256];                                 119   char buff[256];
120   va_list ap;                                     120   va_list ap;
121                                                   121   
122   va_start(ap, format);                           122   va_start(ap, format);
123   vsnprintf(buff, sizeof(buff), format, ap);      123   vsnprintf(buff, sizeof(buff), format, ap);
124   va_end(ap);                                     124   va_end(ap);
125                                                   125   
126   return sos_x86_videomem_putstring(row, col,     126   return sos_x86_videomem_putstring(row, col, attribute, buff);
127 }                                                 127 }
                                                      

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