-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.h
59 lines (49 loc) · 1.19 KB
/
util.h
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
#ifndef __ia16
// Make VSCode's C analyzer work
#define __far
#endif
//
// Utility types
//
typedef unsigned char byte;
// ia16-gcc likes unsigned integers better sometimes
typedef unsigned int uint;
//
// Convenient access to the low and high bytes of a word (like l/h registers)
//
typedef union {
uint word;
struct
{
byte lo;
byte hi;
};
} uint_lh;
static inline byte HI(uint n) { return n >> 8; }
static inline byte LO(uint n) { return (byte)n; }
//
// Video memory access
//
static char __far *const vidc = (char __far *)0xB8000000;
// Video memory word at `addr`
#define vidw(addr) (*(uint __far *)(vidc + addr))
//
// Replicas of x86 instructions
//
// Store word `value` at `addr`, increment `addr`
#define vid_stosw(addr, value) \
{ \
vidw(addr) = value; \
addr += 2; \
}
#define outb(port, value) \
asm volatile( \
"outb %%al, %0\n" \
: \
: "i"(port), "Ral"((byte)(value)));
// Note: `value` should be a `byte` type variable
#define inb(port, value) \
asm volatile( \
"inb %1, %%al\n" \
: "=Ral"(value) \
: "i"(port));