]>
git.dujemihanovic.xyz Git - nameless-os.git/blob - kernel/arch/x86/tty/tty.c
9 volatile char *video_memory
= (char *) 0xB8000; /* VGA VRAM starts at 0xB8000 */
11 static int cursor_x
= 0; /* keep track of where cursor is */
12 static int cursor_y
= 0;
14 char *hex_chars
= "0123456789ABCDEF";
15 char kgets_buffer
[100];
17 void screen_clear(void)
20 for ( y
= 0; y
< VGA_HEIGHT
; y
++ ) {
21 for ( x
= 0; x
< VGA_WIDTH
; x
++ ) {
22 video_memory
[(y
* VGA_WIDTH
+ x
) * 2 + 1] = VGA_COLOR_LIGHT_GRAY
;
23 video_memory
[(y
* VGA_WIDTH
+ x
) * 2] = ' ';
34 for ( y
= 1; y
< VGA_HEIGHT
; y
++ ) {
35 for ( x
= 0; x
< VGA_WIDTH
; x
++ ) {
36 video_memory
[((y
- 1) * VGA_WIDTH
+ x
) * 2] = video_memory
[(y
* VGA_WIDTH
+ x
) * 2];
39 for ( x
= 0; x
< VGA_WIDTH
; x
++ ) {
40 video_memory
[((VGA_HEIGHT
- 1) * VGA_WIDTH
+ x
) * 2] = ' ';
42 cursor_y
= VGA_HEIGHT
- 1;
45 void kprint(const char *string
, uint8_t color
)
48 uint8_t vga_misc_output
;
52 while ( next_char
!= 0 ) {
53 if ( next_char
== '\n') { cursor_x
= 0; cursor_y
++; }
54 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
; }
55 if ( cursor_x
>= VGA_WIDTH
) { cursor_x
= 0; cursor_y
++; }
56 if ( cursor_y
>= VGA_HEIGHT
) { scroll_up(); }
57 next_char
= *++string
;
60 vga_misc_output
= inb(0x3CC);
61 if (vga_misc_output
& 0x1 == 0) {
68 outb(crtc_port
+ 1, (cursor_y
* VGA_WIDTH
+ cursor_x
) >> 8);
70 outb(crtc_port
+ 1, (cursor_y
* VGA_WIDTH
+ cursor_x
) & 0xFF);
73 void kprintc(const char character
, uint8_t color
)
75 uint8_t vga_misc_output
;
78 if ( character
== '\n') { cursor_x
= 0; cursor_y
++; }
79 if (character
== 0x7f) {
83 cursor_x
= VGA_WIDTH
- 1;
87 video_memory
[(cursor_y
* VGA_WIDTH
+ cursor_x
) * 2] = ' ';
89 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
; }
90 if ( cursor_x
>= VGA_WIDTH
) { cursor_x
= 0; cursor_y
++; }
91 if ( cursor_y
>= VGA_HEIGHT
) { scroll_up(); }
93 vga_misc_output
= inb(0x3CC);
94 if (vga_misc_output
& 0x1 == 0) {
100 outb(crtc_port
, 0xE);
101 outb(crtc_port
+ 1, (cursor_y
* VGA_WIDTH
+ cursor_x
) >> 8);
102 outb(crtc_port
, 0xF);
103 outb(crtc_port
+ 1, (cursor_y
* VGA_WIDTH
+ cursor_x
) & 0xFF);
107 void kprintb(uint8_t byte
)
111 kprint("0x", VGA_COLOR_LIGHT_GRAY
);
112 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
114 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
117 void kprintw(uint16_t word
)
121 kprint("0x", VGA_COLOR_LIGHT_GRAY
);
122 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
123 temp
= (word
>> 8) & 0xF;
124 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
125 temp
= (word
>> 4) & 0xF;
126 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
128 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
131 void kprintd(uint32_t dword
)
135 kprint("0x", VGA_COLOR_LIGHT_GRAY
);
136 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
137 temp
= (dword
>> 24) & 0xF;
138 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
139 temp
= (dword
>> 20) & 0xF;
140 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
141 temp
= (dword
>> 16) & 0xF;
142 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
143 temp
= (dword
>> 12) & 0xF;
144 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
145 temp
= (dword
>> 8) & 0xF;
146 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
147 temp
= (dword
>> 4) & 0xF;
148 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
150 kprintc(hex_chars
[temp
], VGA_COLOR_LIGHT_GRAY
);
155 for (int i
=0; i
<100; i
++) {
156 kgets_buffer
[i
] = '\0';
161 char temp
= ps2_get_keystroke();
162 if (temp
== '\n') break;
166 kgets_buffer
[i
] = '\0';
171 kgets_buffer
[i
] = temp
;