-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio.c
More file actions
106 lines (95 loc) · 1.58 KB
/
io.c
File metadata and controls
106 lines (95 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* io.c -
*/
#include <io.h>
#include <types.h>
/**************/
/** Screen ***/
/**************/
Byte x, y=19;
Byte color = 0x02;
/* Read a byte from 'port' */
Byte inb (unsigned short port)
{
Byte v;
__asm__ __volatile__ ("inb %w1,%0":"=a" (v):"Nd" (port));
return v;
}
void move_line()
{
x = 0;
if (y < 24)
{
y=y+1;
}
else
{
Word *screen = (Word *)0xb8000;
for (int i = 0; i < 24; ++i)
{
for (int j = 0; j < 80; ++j)
{
screen[i*NUM_COLUMNS + j] = screen[(i + 1)*NUM_COLUMNS + j];
}
}
for (int i = 0; i < 80; ++i)
{
screen[24*NUM_COLUMNS + i] = 0x0000;
}
}
}
void printc(char c)
{
__asm__ __volatile__ ( "movb %0, %%al; outb $0xe9" ::"a"(c)); /* Magic BOCHS debug: writes 'c' to port 0xe9 */
if (c=='\n')
{
move_line();
}
else
{
Word ch = (Word) (c & 0x00FF) | (color << 8);
Word *screen = (Word *)0xb8000;
screen[(y * NUM_COLUMNS + x)] = ch;
if (++x >= NUM_COLUMNS)
move_line();
{
}
}
}
/*
void printc_color(char c, char color)
{
__asm__ __volatile__ ( "movb %0, %%al; outb $0xe9" ::"a"(c)); /* Magic BOCHS debug: writes 'c' to port 0xe9
if (c=='\n')
{
move_line();
}
else
{
Word col = color << 8;
Word ch = (Word) (c & 0x00FF) | col;
Word *screen = (Word *)0xb8000;
screen[(y * NUM_COLUMNS + x)] = ch;
if (++x >= NUM_COLUMNS)
{
move_line();
}
}
}*/
void printc_xy(Byte mx, Byte my, char c)
{
Byte cx, cy;
cx=x;
cy=y;
x=mx;
y=my;
printc(c);
x=cx;
y=cy;
}
void printk(char *string)
{
int i;
for (i = 0; string[i]; i++)
printc(string[i]);
}