]>
git.dujemihanovic.xyz Git - nameless-os.git/blob - kernel/arch/x86/tty/tty.c
8 volatile char *video_memory
= (char *) 0xB8000; /* VGA VRAM starts at 0xB8000 */
10 static int cursor_x
= 0; /* keep track of where cursor is */
11 static int cursor_y
= 0;
13 char *hex_chars
= "0123456789ABCDEF";
15 void screen_clear(void)
18 for ( y
= 0; y
< VGA_HEIGHT
; y
++ ) {
19 for ( x
= 0; x
< VGA_WIDTH
; x
++ ) {
20 video_memory
[(y
* VGA_WIDTH
+ x
) * 2 + 1] = VGA_COLOR_LIGHT_GRAY
;
21 video_memory
[(y
* VGA_WIDTH
+ x
) * 2] = ' ';
32 for ( y
= 1; y
< VGA_HEIGHT
; y
++ ) {
33 for ( x
= 0; x
< VGA_WIDTH
; x
++ ) {
34 video_memory
[((y
- 1) * VGA_WIDTH
+ x
) * 2] = video_memory
[(y
* VGA_WIDTH
+ x
) * 2];
37 for ( x
= 0; x
< VGA_WIDTH
; x
++ ) {
38 video_memory
[((VGA_HEIGHT
- 1) * VGA_WIDTH
+ x
) * 2] = ' ';
40 cursor_y
= VGA_HEIGHT
- 1;
43 void kprint(const char *string
, uint8_t color
)
46 uint8_t vga_misc_output
;
50 while ( next_char
!= 0 ) {
51 if ( next_char
== '\n') { cursor_x
= 0; cursor_y
++; }
52 else { video_memory
[(cursor_y
* VGA_WIDTH
+ cursor_x
) * 2] = next_char
; video_memory
[((cursor_y
* VGA_WIDTH
+ cursor_x
++) * 2)+ 1] = color
!= 0 ? color
: VGA_COLOR_LIGHT_GRAY
; }
53 if ( cursor_x
>= VGA_WIDTH
) { cursor_x
= 0; cursor_y
++; }
54 if ( cursor_y
>= VGA_HEIGHT
) { scroll_up(); }
55 next_char
= *++string
;
58 vga_misc_output
= inb(0x3CC);
59 if (vga_misc_output
& 0x1 == 0) {
66 outb(crtc_port
+ 1, (cursor_y
* VGA_WIDTH
+ cursor_x
) >> 8);
68 outb(crtc_port
+ 1, (cursor_y
* VGA_WIDTH
+ cursor_x
) & 0xFF);
71 void kprintc(const char character
, uint8_t color
)
73 uint8_t vga_misc_output
;
76 if ( character
== '\n') { cursor_x
= 0; cursor_y
++; }
77 else { video_memory
[(cursor_y
* VGA_WIDTH
+ cursor_x
) * 2] = character
; video_memory
[((cursor_y
* VGA_WIDTH
+ cursor_x
++) * 2)+ 1] = color
!= 0 ? color
: VGA_COLOR_LIGHT_GRAY
; }
78 if ( cursor_x
>= VGA_WIDTH
) { cursor_x
= 0; cursor_y
++; }
79 if ( cursor_y
>= VGA_HEIGHT
) { scroll_up(); }
81 vga_misc_output
= inb(0x3CC);
82 if (vga_misc_output
& 0x1 == 0) {
89 outb(crtc_port
+ 1, (cursor_y
* VGA_WIDTH
+ cursor_x
) >> 8);
91 outb(crtc_port
+ 1, (cursor_y
* VGA_WIDTH
+ cursor_x
) & 0xFF);
95 void kprintb(uint8_t byte
)
99 kprint("0x", VGA_COLOR_LIGHT_GRAY
);
100 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
102 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
105 void kprintw(uint16_t word
)
109 kprint("0x", VGA_COLOR_LIGHT_GRAY
);
110 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
111 temp
= (word
>> 8) & 0xF;
112 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
113 temp
= (word
>> 4) & 0xF;
114 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
116 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
119 void kprintd(uint32_t dword
)
123 kprint("0x", VGA_COLOR_LIGHT_GRAY
);
124 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
125 temp
= (dword
>> 24) & 0xF;
126 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
127 temp
= (dword
>> 20) & 0xF;
128 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
129 temp
= (dword
>> 16) & 0xF;
130 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
131 temp
= (dword
>> 12) & 0xF;
132 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
133 temp
= (dword
>> 8) & 0xF;
134 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
135 temp
= (dword
>> 4) & 0xF;
136 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
138 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
141 int kprintdec(uint32_t num
)
145 /* TODO: make an actual memset function to use instead of this */
146 for (int i
=0; i
<11; i
++) {
150 /* put the numbers in the buffer */
151 for (int i
=9; i
>0 && num
>0; i
--) {
152 uint8_t currdigit
= num
%10;
153 buffer
[i
] = currdigit
+'0';
157 /* shift the array as much as needed */
158 while (*buffer
== '\0') {
160 for (int i
=0; i
<9; i
++) {
161 buffer
[i
] = buffer
[i
+1];
165 /* zero out any leftovers */
167 for (int i
=digits
; i
<10; i
++) {