-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.c
65 lines (55 loc) · 989 Bytes
/
io.c
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
/*
* io.c -
*/
#include <io.h>
#include <types.h>
/**************/
/** Screen ***/
/**************/
#define NUM_COLUMNS 80
#define NUM_ROWS 25
Byte x, y=19;
/* Read a byte from 'port' */
Byte inb (unsigned short port)
{
Byte v;
__asm__ __volatile__ ("inb %w1,%0":"=a" (v):"Nd" (port));
return v;
}
void printc(char c)
{
__asm__ __volatile__ ( "movb %0, %%al; outb $0xe9" ::"a"(c));
if (c=='\n')
{
x = 0;
y=(y+1)%NUM_ROWS;
}
else
{
Word ch = (Word) (c & 0x00FF) | 0x0200;
DWord screen = 0xb8000 + (y * NUM_COLUMNS + x) * 2;
if (++x >= NUM_COLUMNS)
{
x = 0;
y=(y+1)%NUM_ROWS;
}
asm("movw %0, (%1)" : : "g"(ch), "g"(screen));
}
}
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]);
}