Simple Operating System
conio.h
Go to the documentation of this file.
1 
7 #ifndef CONIO_H
8 #define CONIO_H
9 
10 #include "types.h"
11 
15 typedef enum {TextMode = 2, TextColorMode = 16, ColorMode = 19} Mode;
16 
20 typedef struct Cursor {
21  Byte x, y;
23 
27 typedef union Attributes {
28  struct {
29  Byte foreground: 4;
30  Byte background: 3;
31  Byte blink: 1;
32  };
33  Byte attributes;
35 
41 void setVideoMode(Mode mode) {
42  asm("int 0x10"
43  :
44  :"a"(0x0000|mode));
45 }
46 
47 void setColorPalette(Byte color) {
48  asm("int 0x10"
49  ::"a"(0x0b00), "b"(color));
50 }
51 
59  Cursor cursor;
60  asm("int 0x10"
61  : "=d"(cursor)
62  : "a"(0x0300), "b"(0x0));
63  return cursor;
64 }
65 
71 void setCursorPosition(Cursor cursor) {
72  asm("int 0x10"
73  :: "a"(0x0200), "b"(0x0), "d"(cursor));
74 }
75 
80 void cls(void) {
81  asm("int 0x10\n\
82  cls_l%=:\n\
83  mov ax,0\n\
84  int 0x20\n\
85  loop cls_l%=\n\
86  mov ax,0x0200\n\
87  int 0x10"
88  :
89  : "a" (0x0200),
90  "b" (0x0),
91  "c" (0xffff),
92  "d" (0x0));
93 }
94 
102 void cputc(char c, Color color, Byte times) {
103  asm("int 0x10"::"a"(0x0900|c), "b"(0x0000|color), "c"(times));
104  //move cursor by 1
105  asm("int 0x10"
106  :: "a" (0x0300), "b" (0x0));
107  asm("add dl, al\n\
108  int 0x10"
109  :: "a"(0x0200|times));
110 }
111 
118 void cputs(int str, Color color) {
119  char* ptr = (char *)str;
120  while(*ptr != 0) {
121  asm("int 0x10"::"a"(0x0900|*ptr), "b"(0x0000|color), "c"(1));
122  //move cursor by 1
123  asm("int 0x10\n\
124  mov ah,02\n\
125  inc dl\n\
126  int 0x10"
127  :: "a" (0x0300), "b" (0x0));
128  ptr++;
129  }
130 }
131 
132 #endif //CONIO_H
union Attributes Attributes
Attributes of character on screen.
void cputs(int str, Color color)
Color put string.
Definition: conio.h:118
struct Cursor Cursor
Position of cursor.
Mode
Video modes, can be changed with void setVideoMode(Mode mode);.
Definition: conio.h:15
void cputc(char c, Color color, Byte times)
Color put character.
Definition: conio.h:102
void setCursorPosition(Cursor cursor)
Set position of cursor.
Definition: conio.h:71
void setVideoMode(Mode mode)
Set the video mode of screen.
Definition: conio.h:41
Cursor getCursorPosition(void)
Get position of Cursor.
Definition: conio.h:58
void cls(void)
Clear screen.
Definition: conio.h:80
Position of cursor.
Definition: conio.h:20
useful macros, definitions, enums etc.
Attributes of character on screen.
Definition: conio.h:27
Byte foreground
Definition: conio.h:29
Byte background
Definition: conio.h:30
Byte blink
Definition: conio.h:31
Byte attributes
Definition: conio.h:33