IBNOS
console.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Michael Müller
3  * Copyright (c) 2014, Sebastian Lackner
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  */
27 
28 #ifndef _H_CONSOLE_
29 #define _H_CONSOLE_
30 
31 #include <stddef.h>
32 #include <stdint.h>
33 #include <stdbool.h>
34 
44 {
49  COLOR_RED = 4,
61 };
62 
67 {
72 };
73 
78 #define MAKE_COLOR(foreground, background) (((foreground) & 15) | (background) << 4)
79 
83 #define MAKE_RAW_CHAR(color, chr) ((((uint32_t)(chr)) & 0xFF) | (((uint32_t)(color)) & 0xFF) << 8)
84 
90 #define RAW_CHAR_COLOR(raw) (((raw) >> 8) & 0xFF)
91 
95 #define RAW_CHAR_CHR(raw) ((raw) & 0xFF)
96 
100 #define BG_COLOR(color) ((color >> 4) & 15)
101 
105 #define FG_COLOR(color) (color & 15)
106 
110 #define CONSOLE_WIDTH(size) (size & 0xFFFF)
111 
115 #define CONSOLE_HEIGHT(size) ((size >> 16) & 0xFFFF)
116 
120 #define CONSOLE_POSX(pos) (pos & 0xFFFF)
121 
125 #define CONSOLE_POSY(pos) ((pos >> 16) & 0xFFFF)
126 
127 #ifdef __KERNEL__
128 
129  #include <hardware/context.h>
130 
131  void consoleInit();
132  void consoleClear();
133 
134  void consoleSetColor(uint8_t color);
135  uint8_t consoleGetColor();
136  uint8_t consoleGetColorForeground();
137  uint8_t consoleGetColorBackground();
138 
139  void consolePutChar(char chr);
140  void consoleEchoChar(char chr);
141  void consolePutCharRaw(uint16_t chr);
142  void consoleWriteString(const char *str);
143  void consoleWriteStringLen(const char *str, size_t len);
144  void consoleWriteRawLen(const uint16_t *data, size_t count);
145  void consoleWriteStringMax(const char *str, size_t len);
146  void consoleWriteHex32(uint32_t value);
147  void consoleWriteInt32(uint32_t value);
148  void consoleWriteHex16(uint16_t value);
149 
150  bool consoleSetCursorPos(uint8_t x, uint8_t y);
151  uint32_t consoleGetCursorPos();
152  uint32_t consoleGetCursorPosX();
153  uint32_t consoleGetCursorPosY();
154 
155  void consoleScrollUp();
156 
157  uint32_t consoleGetSize();
158  uint8_t consoleGetHeight();
159  uint8_t consoleGetWidth();
160 
161  void consoleShowHardwareCursor(bool changed);
162  void consoleSetHardwareCursor(uint8_t x, uint8_t y);
163  uint32_t consoleGetHardwareCursor();
164 
165  void consoleSetFont();
166  void consoleSetFlags(uint32_t newFlags);
167  uint32_t consoleGetFlags();
168 
169  void consoleSystemFailure(const char **lines, uint32_t numArgs, uint32_t *args, struct taskContext *context);
170 
171 #endif
172 
175 #endif /* _H_CONSOLE_ */
void consoleScrollUp()
Scroll the console up one line.
Definition: console.c:417
void consoleWriteStringMax(const char *str, size_t len)
Write a nullterminated string or a maximum of len characters.
Definition: console.c:287
uint32_t consoleGetCursorPosY()
Get Y position of the text cursor.
Definition: console.c:406
void consoleWriteRawLen(const uint16_t *data, size_t count)
Write raw data with a fixed size to the console.
Definition: console.c:269
uint32_t consoleGetSize()
Returns the packed size of the console.
Definition: console.c:454
uint8_t consoleGetColorForeground()
Get current foreground color.
Definition: console.c:134
VGA_COLOR
Definition: console.h:43
void consoleShowHardwareCursor(bool changed)
Show / hide blinking hardware cursor.
Definition: console.c:464
void consoleWriteInt32(uint32_t value)
Write a 32 bit integer as decimal value on the console.
Definition: console.c:325
uint32_t consoleGetHardwareCursor()
Get packed position of the hardware cursor.
Definition: console.c:513
void consoleSetFont()
Load a custom font supporting latin1 characters.
Definition: console.c:526
uint8_t consoleGetWidth()
Returns the width (text cols) of the console.
Definition: console.c:443
void consoleInit()
Initializes the console.
Definition: console.c:79
uint32_t consoleGetCursorPosX()
Get X position of the text cursor.
Definition: console.c:397
void consoleSetColor(uint8_t color)
Set the text and background color of the console.
Definition: console.c:113
uint8_t consoleGetHeight()
Returns the height (text rows) of the console.
Definition: console.c:434
uint8_t consoleGetColorBackground()
Get current background color.
Definition: console.c:143
void consolePutCharRaw(uint16_t chr)
Write a raw character and color on the console.
Definition: console.c:208
void consoleWriteHex32(uint32_t value)
Write a 32 bit integer as hex value on the console.
Definition: console.c:303
void consoleClear()
Clear the screen contents.
Definition: console.c:90
uint8_t consoleGetColor()
Get current color.
Definition: console.c:124
void consoleSetHardwareCursor(uint8_t x, uint8_t y)
Set the position of the hardware cursor.
Definition: console.c:498
void consoleSystemFailure(const char **lines, uint32_t numArgs, uint32_t *args, struct taskContext *context)
Print a system failure message and halts the system.
Definition: console.c:589
void consoleWriteHex16(uint16_t value)
Write a 16 bit integer as hex value on the console.
Definition: console.c:348
CONSOLE_FLAGS
Definition: console.h:66
void consoleWriteString(const char *str)
Write a C string to the console.
Definition: console.c:240
uint32_t consoleGetCursorPos()
Get packed position of the text cursor.
Definition: console.c:388
void consoleWriteStringLen(const char *str, size_t len)
Write a string with a fixed size to the console.
Definition: console.c:254
bool consoleSetCursorPos(uint8_t x, uint8_t y)
Set the position of the text cursor.
Definition: console.c:371
void consoleSetFlags(uint32_t newFlags)
Set console flags.
Definition: console.c:554
void consoleEchoChar(char chr)
Echo keyboard input on the console.
Definition: console.c:193
uint32_t value
Definition: paging.h:55
void consolePutChar(char chr)
Write a character on the console.
Definition: console.c:156
uint32_t consoleGetFlags()
Get console flags.
Definition: console.c:564