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 8)


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 
034                                                   033 
035 /** The structure of a character element in th    034 /** The structure of a character element in the video memory. @see
036     http://webster.cs.ucr.edu/AoA DOS edition     035     http://webster.cs.ucr.edu/AoA DOS edition chapter 23 */
037 typedef struct {                                  036 typedef struct {
038   unsigned char character;                        037   unsigned char character;
039   unsigned char attribute;                        038   unsigned char attribute;
040 } __attribute__ ((packed)) x86_video_mem[LINES    039 } __attribute__ ((packed)) x86_video_mem[LINES*COLUMNS];
041                                                   040 
042                                                   041 
043                                                   042 
044 /** The base pointer for the video memory */      043 /** The base pointer for the video memory */
045 static volatile x86_video_mem *video = (volati    044 static volatile x86_video_mem *video = (volatile x86_video_mem*)VIDEO;
046                                                   045 
047 sos_ret_t sos_x86_videomem_setup(void)            046 sos_ret_t sos_x86_videomem_setup(void)
048 {                                                 047 {
049   /*                                              048   /*
050    * Hide cursor. @see Ralf Brown's interrupt     049    * Hide cursor. @see Ralf Brown's interrupt (and port) list
051    * http://www-2.cs.cmu.edu/~ralf/files.html     050    * http://www-2.cs.cmu.edu/~ralf/files.html
052    */                                             051    */
053 #define CRT_REG_INDEX 0x3d4                       052 #define CRT_REG_INDEX 0x3d4
054 #define CRT_REG_DATA  0x3d5                       053 #define CRT_REG_DATA  0x3d5
055                                                   054 
056   /* CRT index port => ask for access to regis    055   /* CRT index port => ask for access to register 0xa ("cursor
057      start") */                                   056      start") */
058   outb(0x0a, CRT_REG_INDEX);                      057   outb(0x0a, CRT_REG_INDEX);
059                                                   058 
060   /* (RBIL Tables 708 & 654) CRT Register 0xa     059   /* (RBIL Tables 708 & 654) CRT Register 0xa => bit 5 = cursor OFF */
061   outb(1 << 5, CRT_REG_DATA);                     060   outb(1 << 5, CRT_REG_DATA);
062                                                   061 
063   return SOS_OK;                                  062   return SOS_OK;
064 }                                                 063 }
065                                                   064 
066                                                   065 
067 sos_ret_t sos_x86_videomem_cls(unsigned char a    066 sos_ret_t sos_x86_videomem_cls(unsigned char attribute)
068 {                                                 067 {
069   /* Clears the screen */                         068   /* Clears the screen */
070   int i;                                          069   int i;
071   for(i = 0 ; i < LINES*COLUMNS ; i++)            070   for(i = 0 ; i < LINES*COLUMNS ; i++)
072     {                                             071     {
073       (*video)[i].character = 0;                  072       (*video)[i].character = 0;
074       (*video)[i].attribute = attribute;          073       (*video)[i].attribute = attribute;
075     }                                             074     }
076                                                   075 
077   return SOS_OK;                                  076   return SOS_OK;  
078 }                                                 077 }
079                                                   078 
080                                                   079 
081 sos_ret_t sos_x86_videomem_putstring(unsigned     080 sos_ret_t sos_x86_videomem_putstring(unsigned char row, unsigned char col,
082                                      unsigned     081                                      unsigned char attribute,
083                                      const cha    082                                      const char *str)
084 {                                                 083 {
085   unsigned video_offs = row*COLUMNS + col;        084   unsigned video_offs = row*COLUMNS + col;
086                                                   085 
087   if (video_offs >= LINES*COLUMNS)                086   if (video_offs >= LINES*COLUMNS)
088     return -SOS_EINVAL;                           087     return -SOS_EINVAL;
089                                                   088   
090   for ( ; str && *str && (video_offs < LINES*C    089   for ( ; str && *str && (video_offs < LINES*COLUMNS) ; str++, video_offs++)
091     {                                             090     {
092       (*video)[video_offs].character = (unsign    091       (*video)[video_offs].character = (unsigned char)*str;
093       (*video)[video_offs].attribute = attribu    092       (*video)[video_offs].attribute = attribute;
094     }                                             093     }
095                                                   094 
096   return SOS_OK;                                  095   return SOS_OK;
097 }                                                 096 }
098                                                   097 
099                                                   098 
100 sos_ret_t sos_x86_videomem_putchar(unsigned ch    099 sos_ret_t sos_x86_videomem_putchar(unsigned char row, unsigned char col,
101                                    unsigned ch    100                                    unsigned char attribute,
102                                    unsigned ch    101                                    unsigned char c)
103 {                                                 102 {
104   unsigned video_offs = row*COLUMNS + col;        103   unsigned video_offs = row*COLUMNS + col;
105                                                   104 
106   if (video_offs >= LINES*COLUMNS)                105   if (video_offs >= LINES*COLUMNS)
107     return -SOS_EINVAL;                           106     return -SOS_EINVAL;
108                                                   107   
109   (*video)[video_offs].character = c;             108   (*video)[video_offs].character = c;
110   (*video)[video_offs].attribute = attribute;     109   (*video)[video_offs].attribute = attribute;
111                                                   110 
112   return SOS_OK;                                  111   return SOS_OK;
113 }                                                 112 }
114                                                   113 
115                                                   114 
116 sos_ret_t sos_x86_videomem_printf(unsigned cha    115 sos_ret_t sos_x86_videomem_printf(unsigned char row, unsigned char col,
117                                   unsigned cha    116                                   unsigned char attribute,
118                                   const char *    117                                   const char *format, /* args */...)
119 {                                                 118 {
120   char buff[256];                                 119   char buff[256];
121   va_list ap;                                     120   va_list ap;
122                                                   121   
123   va_start(ap, format);                           122   va_start(ap, format);
124   vsnprintf(buff, sizeof(buff), format, ap);      123   vsnprintf(buff, sizeof(buff), format, ap);
125   va_end(ap);                                     124   va_end(ap);
126                                                   125   
127   return sos_x86_videomem_putstring(row, col,     126   return sos_x86_videomem_putstring(row, col, attribute, buff);
128 }                                                 127 }
                                                      

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