1 |
2 |
idiolatrie |
/******************************************************************************
|
2 |
|
|
* Standard Input/Output *
|
3 |
|
|
******************************************************************************
|
4 |
|
|
* Copyright (C)2011 Mathias H�rtnagl <mathias.hoertnagl@gmail.com> *
|
5 |
|
|
* *
|
6 |
|
|
* This program is free software: you can redistribute it and/or modify *
|
7 |
|
|
* it under the terms of the GNU General Public License as published by *
|
8 |
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
9 |
|
|
* (at your option) any later version. *
|
10 |
|
|
* *
|
11 |
|
|
* This program is distributed in the hope that it will be useful, *
|
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
14 |
|
|
* GNU General Public License for more details. *
|
15 |
|
|
* *
|
16 |
|
|
* You should have received a copy of the GNU General Public License *
|
17 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
18 |
|
|
******************************************************************************/
|
19 |
|
|
#include "stddef.h"
|
20 |
|
|
|
21 |
|
|
#ifndef _STDIO_H
|
22 |
|
|
#define _STDIO_H
|
23 |
|
|
|
24 |
|
|
/******************************************************************************
|
25 |
|
|
* VGA *
|
26 |
|
|
******************************************************************************/
|
27 |
|
|
/* Pointer to VGA display memory. */
|
28 |
|
|
#define VGA_MEMORY ( (volatile ushort *) 0xffff0000 )
|
29 |
|
|
|
30 |
|
|
/* Maximum values of the display's horizontal and vertical coordinates. */
|
31 |
|
|
#define VGA_H 100
|
32 |
|
|
#define VGA_V 37
|
33 |
|
|
|
34 |
|
|
/* Calculates the position of the cursor from its x and y coordinates that is
|
35 |
|
|
actually 10*y + x, substituting a multiplication with left shifts and
|
36 |
|
|
additions. */
|
37 |
|
|
#define VGA_POS(x,y) ( (y << 6) + (y << 5) + (y << 2) + x )
|
38 |
|
|
|
39 |
|
|
/* Set up character information of type 0fff0bbb cccccccc where f and b are the
|
40 |
|
|
3-bit foreground and background colors respectively. c denotes the 8-bit
|
41 |
|
|
character.
|
42 |
|
|
NOTE: Does not check for 3 bit color and 8 bit character limits. */
|
43 |
|
|
#define VGA_CHR(f,b,c) ( (f << 12) | (b << 8) | c )
|
44 |
|
|
|
45 |
|
|
/* Available colors on an 8 color VGA display. */
|
46 |
|
|
#define BLACK ((uchar) 0)
|
47 |
|
|
#define BLUE ((uchar) 1)
|
48 |
|
|
#define GREEN ((uchar) 2)
|
49 |
|
|
#define CYAN ((uchar) 3)
|
50 |
|
|
#define RED ((uchar) 4)
|
51 |
|
|
#define MAGENTA ((uchar) 5)
|
52 |
|
|
#define YELLOW ((uchar) 6)
|
53 |
|
|
#define WHITE ((uchar) 7)
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
/******************************************************************************
|
57 |
|
|
* Keyboard *
|
58 |
|
|
******************************************************************************/
|
59 |
|
|
/* Pointer to Keyboard character memory. */
|
60 |
|
|
#define KEYB_MEMORY ((volatile uint *) 0xffff3000)
|
61 |
|
|
|
62 |
|
|
/* Input buffer size */
|
63 |
|
|
#define INBUF_SIZE 128
|
64 |
|
|
|
65 |
|
|
/* Funtional key flags. */
|
66 |
|
|
#define KEYB_SHIFT ((uchar) 0x80)
|
67 |
|
|
#define KEYB_CTRL ((uchar) 0x40)
|
68 |
|
|
#define KEYB_ALT ((uchar) 0x20)
|
69 |
|
|
#define KEYB_ALTGR ((uchar) 0x10)
|
70 |
|
|
|
71 |
|
|
/* Special keys. */
|
72 |
|
|
#define KEY_ENTER ((uchar) 0x0d)
|
73 |
|
|
#define KEY_BACKSP ((uchar) 0x08)
|
74 |
|
|
#define KEY_TAB ((uchar) 0x09)
|
75 |
|
|
#define KEY_ESC ((uchar) 0x1b)
|
76 |
|
|
#define KEY_DEL ((uchar) 0x7f)
|
77 |
|
|
#define KEY_SCROLL ((uchar) 0x80)
|
78 |
|
|
#define KEY_ARROWU ((uchar) 0xf0)
|
79 |
|
|
#define KEY_ARROWL ((uchar) 0xf1)
|
80 |
|
|
#define KEY_ARROWD ((uchar) 0xf2)
|
81 |
|
|
#define KEY_ARROWR ((uchar) 0xf3)
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
/******************************************************************************
|
85 |
|
|
* Type Definitions *
|
86 |
|
|
******************************************************************************/
|
87 |
|
|
/* Color information structure. */
|
88 |
|
|
typedef struct _color {
|
89 |
|
|
uchar fg;
|
90 |
|
|
uchar bg;
|
91 |
|
|
} color;
|
92 |
|
|
|
93 |
|
|
/* Cursor position structure. */
|
94 |
|
|
typedef struct _cursor {
|
95 |
|
|
uchar x;
|
96 |
|
|
uchar y;
|
97 |
|
|
} cursor;
|
98 |
|
|
|
99 |
|
|
/* Key */
|
100 |
|
|
typedef struct _key {
|
101 |
|
|
uchar flags;
|
102 |
|
|
uchar chr;
|
103 |
|
|
} key;
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
/******************************************************************************
|
107 |
|
|
* Output Functions *
|
108 |
|
|
******************************************************************************/
|
109 |
|
|
/* Set text and background colors. */
|
110 |
|
|
extern void setcolor(uchar fg, uchar bg);
|
111 |
|
|
|
112 |
|
|
/* Set cursor at position x,y. */
|
113 |
|
|
extern void gotoxy(uchar x, uchar y);
|
114 |
|
|
|
115 |
|
|
/* Clears the entire display and resets the cursor. */
|
116 |
|
|
extern void cls();
|
117 |
|
|
|
118 |
|
|
/* Scrolls down one line and clears the lowest line. The vertical cursor jumps
|
119 |
|
|
one line up, if not already on line one. If the cursor is on the first line
|
120 |
|
|
the horizontal cursor is reset to zero. */
|
121 |
|
|
extern void scroll();
|
122 |
|
|
|
123 |
|
|
/* Outputs a single character onto the screen. */
|
124 |
|
|
extern void putc(const uchar chr);
|
125 |
|
|
|
126 |
|
|
/* Print a string without it's trailing '\0' onto the screen. */
|
127 |
|
|
extern void puts(const uchar *str);
|
128 |
|
|
|
129 |
|
|
/* Formatted string printig. The following parameters are available:
|
130 |
|
|
+----+--------------------------------------------------+
|
131 |
|
|
| %s | print a string |
|
132 |
|
|
| %c | print a single character |
|
133 |
|
|
| %x | print a hexadecimal representation of an integer |
|
134 |
|
|
| %b | print a binary representation of an intger |
|
135 |
|
|
| %% | print a '%' |
|
136 |
|
|
+----+--------------------------------------------------+
|
137 |
|
|
+----+----------------+
|
138 |
|
|
| \n | line break |
|
139 |
|
|
| \r | carrage return |
|
140 |
|
|
| \t | tab space |
|
141 |
|
|
| \b | back space |
|
142 |
|
|
| \\ | print a '\' |
|
143 |
|
|
+----+----------------+
|
144 |
|
|
|
145 |
|
|
Despite the standard printf implementation, you can manipulate the background
|
146 |
|
|
and text colors:
|
147 |
|
|
+----+---------+----+---------+----+---------+----+---------+
|
148 |
|
|
| $k | black | $b | blue | $g | green | $c | cyan |
|
149 |
|
|
| $r | red | $m | magenta | $y | yellow | $w | white |
|
150 |
|
|
+----+---------+----+---------+----+---------+----+---------+
|
151 |
|
|
$$ - print a '$'
|
152 |
|
|
|
153 |
|
|
The background colors can be specified the same way with a '#' as a format
|
154 |
|
|
indicator. Besides the format string, the function takes only one value
|
155 |
|
|
argunment. */
|
156 |
|
|
extern void printf(const uchar *format, void *arg);
|
157 |
|
|
|
158 |
|
|
#define printf0(f) printf(f, NULL);
|
159 |
|
|
|
160 |
|
|
/******************************************************************************
|
161 |
|
|
* Input Functions *
|
162 |
|
|
******************************************************************************/
|
163 |
|
|
/* Polls for a singe character. The keyboard controller only sends make codes
|
164 |
|
|
and postpones the read ack until a key is pressed. */
|
165 |
|
|
extern key* getc();
|
166 |
|
|
|
167 |
|
|
/* Returns a string of at most INBUF_SIZE characters (without '\0'). The user
|
168 |
|
|
can confirm the input with the enter button. */
|
169 |
|
|
extern uchar* gets();
|
170 |
|
|
|
171 |
|
|
#endif
|