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


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

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