UbixOS  2.0
video.c
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2002-2018 The UbixOS Project.
3  * All rights reserved.
4  *
5  * This was developed by Christopher W. Olsen for the UbixOS Project.
6  *
7  * Redistribution and use in source and binary forms, with or without modification, are permitted
8  * provided that the following conditions are met:
9  *
10  * 1) Redistributions of source code must retain the above copyright notice, this list of
11  * conditions, the following disclaimer and the list of authors.
12  * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13  * conditions, the following disclaimer and the list of authors in the documentation and/or
14  * other materials provided with the distribution.
15  * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16  * endorse or promote products derived from this software without specific prior written
17  * permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <sys/io.h>
30 #include <sys/video.h>
31 #include <ubixos/spinlock.h>
32 #include <ubixos/tty.h>
33 
34 static unsigned char *videoBuffer = (unsigned char *) 0xB8000;
36 
37 void backSpace() {
38  uInt32 bufferOffset = 0x0;
39  outportByte(0x3d4, 0x0e);
40  bufferOffset = inportByte(0x3d5);
41  bufferOffset <<= 0x8; /* Shift Address Left 8 Bits */
42  outportByte(0x3d4, 0x0f);
43  bufferOffset += inportByte(0x3d5);
44  bufferOffset <<= 0x1; /* Shift Address Left 1 Bits */
45  videoBuffer[bufferOffset--] = 0x20;
46  videoBuffer[bufferOffset--] = printColor;
47  videoBuffer[bufferOffset] = 0x20;
48  bufferOffset >>= 0x1;
49  tty_foreground->tty_x = (bufferOffset & 0xFF);
50  tty_foreground->tty_y = (bufferOffset >> 0x8);
51  outportByte(0x3D4, 0x0f);
53  outportByte(0x3D4, 0x0e);
55  return;
56 }
57 
58 void kprint(char *string) {
59 
60  unsigned int bufferOffset = 0x0, character = 0x0, i = 0x0;
61 
62  /* Short circuit if we're in tty mode */
63  if (NULL != tty_foreground) {
64  tty_print(string, tty_find(0));
65  return;
66  }
67 
68  /* We Need To Get The Y Position */
69  outportByte(0x3D4, 0x0e);
70  bufferOffset = inportByte(0x3D5);
71  bufferOffset <<= 8; /* Shift Address Left 8 Bits */
72  /* Then We Need To Add The X Position */
73  outportByte(0x3D4, 0x0f);
74  bufferOffset += inportByte(0x3D5);
75  bufferOffset <<= 1; /* Shift Address Left 1 Bits */
76 
77  while ((character = *string++)) {
78  switch (character) {
79  case '\n':
80  bufferOffset = (bufferOffset / 160) * 160 + 160;
81  break;
82  default:
83  videoBuffer[bufferOffset++] = character;
84  videoBuffer[bufferOffset++] = printColor;
85  break;
86  } /* switch */
87  /* Check To See If We Are Out Of Bounds */
88  if (bufferOffset >= 160 * 25) {
89  for (i = 0; i < 160 * 24; i++) {
90  videoBuffer[i] = videoBuffer[i + 160];
91  } /* for */
92  for (i = 0; i < 80; i++) {
93  videoBuffer[(160 * 24) + (i * 2)] = 0x20;
94  videoBuffer[(160 * 24) + (i * 2) + 1] = printColor;
95  } /* for */
96  bufferOffset -= 160;
97  } /* if */
98  } /* while */
99  bufferOffset >>= 1; /* Set the new cursor position */
100  outportByte(0x3D4, 0x0f);
101  outportByte(0x3D5, ((bufferOffset & 0x0ff) & 0xFF));
102  outportByte(0x3D4, 0x0e);
103  outportByte(0x3D5, ((bufferOffset >> 8) & 0xFF));
104 
105  return;
106 }
107 
108 /* Clears The Screen */
109 void clearScreen() {
110  short i = 0x0;
111 
112  for (i = 0x0; i < (80 * 25); i++) {
113  videoBuffer[i * 2] = 0x20;
114  videoBuffer[i * 2 + 1] = defaultColor;
115  }
116  outportByte(0x3D4, 0x0f);
117  outportByte(0x3D5, 0);
118  outportByte(0x3D4, 0x0e);
119  outportByte(0x3D5, 0);
120 }
121 
122 /***
123  END
124  ***/
backSpace
void backSpace()
Definition: video.c:37
spinlock.h
printColor
int printColor
Definition: video.c:35
uInt32
unsigned long int uInt32
Definition: objgfx30.h:49
defaultColor
#define defaultColor
Definition: video.h:34
video.h
tty_termNode::tty_x
uint16_t tty_x
Definition: tty.h:40
outportByte
void outportByte(unsigned int, unsigned char)
outputut one byte to specified port
Definition: io.c:72
tty_print
int tty_print(char *, tty_term *)
Definition: tty.c:115
tty_termNode::tty_y
uint16_t tty_y
Definition: tty.h:41
clearScreen
void clearScreen()
Definition: video.c:109
inportByte
unsigned char inportByte(unsigned int)
input one byte from specified port
Definition: io.c:38
tty_find
tty_term * tty_find(uInt16)
Definition: tty.c:167
tty.h
tty_foreground
tty_term * tty_foreground
Definition: tty.c:38
io.h
kprint
void kprint(char *string)
Definition: video.c:58
NULL
#define NULL
Definition: fat_string.h:17