Operating System
utilities.h
Go to the documentation of this file.
1 
5 #ifndef __UTILITIES_H_
6 #define __UTILITIES_H_
7 
8 #include <stdint.h>
9 #include "ctype.h"
10 void clear_screen();
12 int add(int, int);
13 int kbhit();
19 // blocked function to read hit kb.
20 int readkb();
26 static inline void set_cursor(uint8_t row, uint8_t col) {
27  uint16_t _DX_ = col | (row << 8);
28  __asm__ volatile(
29  "pushw %%bx\n"
30  "pushw %%ax\n"
31  "movb $0x02, %%ah\n"
32  "movw $0, %%bx\n"
33  "int $0x10\n"
34  "popw %%ax\n"
35  "popw %%bx\n"
36  : /* no output */
37  : "d"(_DX_)
38  : "cc", "memory"
39  );
40 }
45 static inline uint16_t get_cursor(){
46  uint16_t cursor_pos;
47  __asm__ volatile(
48  "pushw %%ax\n"
49  "pushw %%bx\n"
50  "movb $0x03, %%ah\n"
51  "movb $0, %%bh\n"
52  "int $0x10\n"
53  "popw %%bx\n"
54  "popw %%ax\n"
55  : "=d"(cursor_pos)
56  : /* no input */
57  : "cc", "cx"
58  );
59  return cursor_pos;
60 }
68 static inline void __screen_scroll(
69  uint16_t row_col_lu, // for DX
70  uint16_t row_col_rd, // for CX
71  uint8_t lines, // for AL
72  uint16_t direction
73  ){
74  uint8_t funCode;
75  if (direction == 0) {
76  funCode = 0x06;
77  } else {
78  funCode = 0x07;
79  }
80  __asm__ volatile(
81  "pushw %%bx\n"
82  "movb %[funCode], %%ah\n"
83  "movb $0x07, %%bh\n"
84  "int $0x10\n"
85  "popw %%bx\n"
86  : /*no output*/
87  : "a"(lines), "c"(row_col_lu), "d"(row_col_rd), [funCode]"rm"(funCode)
88  : "cc", "memory", "bx"
89  );
90 }
91 static inline void scroll_up_one_line() {
92  __screen_scroll((2 << 8) + 1, (23 << 8) + 78, 1, 0);
93 }
94 #endif
static void __screen_scroll(uint16_t row_col_lu, uint16_t row_col_rd, uint8_t lines, uint16_t direction)
Definition: utilities.h:68
void clear_screen()
light-weight ctype.h
int16_t row
Definition: kbhit.c:11
__asm__(".globl _start\)
static void scroll_up_one_line()
Definition: utilities.h:91
int kbhit()
void hello_hybrid_programming()
testcase
static uint16_t get_cursor()
Definition: utilities.h:45
int direction
Definition: timeout.c:13
static void set_cursor(uint8_t row, uint8_t col)
Definition: utilities.h:26
int add(int, int)
int readkb()