Simple Operating System
io.h
Go to the documentation of this file.
1 
6 #ifndef IO_H
7 #define IO_H
8 
9 #include "types.h"
10 
14 typedef union Key {
15  struct {
16  Byte character: 8;
17  Byte scancode: 7;
18  Byte available: 1;
19  };
20 } Key;
21 
22 #pragma GCC diagnostic push
23 #pragma GCC diagnostic ignored "-Wreturn-type"
24 #pragma GCC diagnostic ignored "-Wunused-parameter"
25 
31 void putc(Byte character) {
32  asm("xor ax, ax\n"
33  "mov al, [ebp+8]\n"
34  "int 0x20");
35 }
36 
42 void puts(const int string) {
43  asm("mov bx,[ebp+8]\n"
44  "int 0x20"::"a"(0x100));
45 }
46 
52 void puti(int num) {
53  asm("cmp dx, 0\n"
54  "jge L%=\n"
55  "mov ax, '-'\n"
56  "int 0x20\n"
57  "neg dx\n"
58  "L%=:\n"
59  "mov bx, dx\n"
60  "mov ah, 2\n"
61  "int 0x20\n"::"d"(num));
62 }
63 
72 void printf(const int str, ...) {
73  asm("lea bx, [ebp+8]\n"//BX = EBP + 8
74  "int 0x20"::"a"(0x0300));
75  return;
76 }
77 
83 Key getc(void) {
84  Key key;
85  asm("int 0x16"
86  :"=a"(key)
87  :"a" (0x0));
88  return key;
89 }
90 
96 Key getKeyBuff(void) {
97  Key key;
98  asm("int 0x16\n"
99  "mov bx, 0\n"
100  "jz .end\n"
101  "mov bx, 1\n"
102  ".end:"
103  :"=a"(key), "=b"(key.available)
104  :"a" (0x0100));
105  return key;
106 }
107 
108 #pragma GCC diagnostic pop
109 #endif
Key getKeyBuff(void)
Get key from buffer.
Definition: io.h:96
void puti(int num)
Put int.
Definition: io.h:52
Key getc(void)
Wait for key in buffer, get it and clear buffer.
Definition: io.h:83
union Key Key
Key information, got from buffer.
void printf(const int str,...)
C-like printf function.
Definition: io.h:72
void puts(const int string)
Put string.
Definition: io.h:42
void putc(Byte character)
Put character.
Definition: io.h:31
useful macros, definitions, enums etc.
Key information, got from buffer.
Definition: io.h:14