video.c

Go to the documentation of this file.
00001 /*****************************************************************************************
00002  Copyright (c) 2002-2005 The UbixOS Project
00003  All rights reserved.
00004 
00005  Redistribution and use in source and binary forms, with or without modification, are
00006  permitted provided that the following conditions are met:
00007 
00008  Redistributions of source code must retain the above copyright notice, this list of
00009  conditions, the following disclaimer and the list of authors.  Redistributions in binary
00010  form must reproduce the above copyright notice, this list of conditions, the following
00011  disclaimer and the list of authors in the documentation and/or other materials provided
00012  with the distribution. Neither the name of the UbixOS Project nor the names of its
00013  contributors may be used to endorse or promote products derived from this software
00014  without specific prior written permission.
00015 
00016  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
00017  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00018  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
00019  THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00020  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00021  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00022  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
00023  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00024  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 
00026  $Id: video_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
00027 
00028 *****************************************************************************************/
00029 
00030 #include <sys/io.h>
00031 #include <sys/video.h>
00032 #include <ubixos/types.h>
00033 #include <ubixos/spinlock.h>
00034 #include <ubixos/tty.h>
00035 
00036 static unsigned char  *videoBuffer = (char *)0xB8000;
00037 int                    printColor = defaultColor;
00038 
00039 
00040 void backSpace() {
00041   uInt32 bufferOffset = 0x0;
00042   outportByte(0x3d4, 0x0e);
00043   bufferOffset = inportByte(0x3d5);
00044   bufferOffset <<= 0x8; /* Shift Address Left 8 Bits */
00045   outportByte(0x3d4, 0x0f);
00046   bufferOffset += inportByte(0x3d5);
00047   bufferOffset <<= 0x1; /* Shift Address Left 1 Bits */
00048   videoBuffer[bufferOffset--] = 0x20;
00049   videoBuffer[bufferOffset--] = printColor;
00050   videoBuffer[bufferOffset]   = 0x20;
00051   bufferOffset >>= 0x1;
00052   tty_foreground->tty_x = (bufferOffset &  0xFF);
00053   tty_foreground->tty_y = (bufferOffset >> 0x8);
00054   outportByte(0x3D4, 0x0f);
00055   outportByte(0x3D5, tty_foreground->tty_x);
00056   outportByte(0x3D4, 0x0e);
00057   outportByte(0x3D5, tty_foreground->tty_y);
00058   return;
00059   }
00060 
00061 void 
00062 kprint(char *string)
00063 {
00064 
00065   unsigned int    bufferOffset = 0x0, character = 0x0, i = 0x0;
00066 
00067   /* Short circuit if we're in tty mode */
00068   if (NULL != tty_foreground)
00069   {
00070       tty_print(string,tty_find(0));
00071       return;
00072   }
00073 
00074   /* We Need To Get The Y Position */
00075   outportByte(0x3D4, 0x0e);
00076   bufferOffset = inportByte(0x3D5);
00077   bufferOffset <<= 8;           /* Shift Address Left 8 Bits */
00078   /* Then We Need To Add The X Position */
00079   outportByte(0x3D4, 0x0f);
00080   bufferOffset += inportByte(0x3D5);
00081   bufferOffset <<= 1;           /* Shift Address Left 1 Bits */
00082 
00083   while ((character = *string++)) {
00084     switch (character) {
00085     case '\n':
00086       bufferOffset = (bufferOffset / 160) * 160 + 160;
00087       break;
00088     default:
00089       videoBuffer[bufferOffset++] = character;
00090       videoBuffer[bufferOffset++] = printColor;
00091       break;
00092     }                           /* switch */
00093     /* Check To See If We Are Out Of Bounds */
00094     if (bufferOffset >= 160 * 25) {
00095       for (i = 0; i < 160 * 24; i++) {
00096         videoBuffer[i] = videoBuffer[i + 160];
00097       }                         /* for */
00098       for (i = 0; i < 80; i++) {
00099         videoBuffer[(160 * 24) + (i * 2)] = 0x20;
00100         videoBuffer[(160 * 24) + (i * 2) + 1] = printColor;
00101       }                         /* for */
00102       bufferOffset -= 160;
00103     }                           /* if */
00104   }                             /* while */
00105   bufferOffset >>= 1;           /* Set the new cursor position  */
00106   outportByte(0x3D4, 0x0f);
00107   outportByte(0x3D5, ((bufferOffset & 0x0ff) & 0xFF));
00108   outportByte(0x3D4, 0x0e);
00109   outportByte(0x3D5, ((bufferOffset >> 8) & 0xFF));
00110 
00111   return;
00112 }
00113 
00114 /* Clears The Screen */
00115 void clearScreen() {
00116   short i = 0x0;
00117 
00118   for (i = 0x0; i < (80 * 25); i++) {
00119     videoBuffer[i * 2] = 0x20;
00120     videoBuffer[i * 2 + 1] = defaultColor;
00121     }
00122   outportByte(0x3D4, 0x0f);
00123   outportByte(0x3D5, 0);
00124   outportByte(0x3D4, 0x0e);
00125   outportByte(0x3D5, 0);
00126   }
00127 
00128 /***
00129  END
00130  ***/

Generated on Fri Dec 15 11:18:55 2006 for UbixOS V2 by  doxygen 1.4.7