Skip to content

Commit 674a3c5

Browse files
committed
Standardized VGA Interface
1 parent c792fa6 commit 674a3c5

3 files changed

Lines changed: 55 additions & 28 deletions

File tree

include/vga.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,9 @@ void vga_putc(char ch);
88
void vga_puts(const char* text);
99
void vga_clear(uint8_t color);
1010
void vga_set_color(uint8_t color);
11-
void vga_scroll(int lines);
1211
void vga_set_cursor(uint8_t x, uint8_t y);
13-
void vga_hide_cursor(void);
14-
void vga_print_art(void);
15-
void vga_draw_rect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color);
16-
void terminal_set_font(int use_vector);
17-
void backspace_handler(void);
1812
uint8_t vga_get_x(void);
1913
uint8_t vga_get_y(void);
20-
void update_vga_buffer(void);
2114

2215
#endif
2316

src/ai/ai_model.c

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static void ai_worker_loop(void* arg) {
9595
void ai_scheduler_init(uint32_t n_workers) {
9696
ai_scheduler_running = 1;
9797
ai_worker_count = n_workers;
98+
vga_set_color(0x0A);
9899
diag_log(DIAG_INFO, "AI Neural Scheduler: Initializing workers...");
99100

100101
// In a real implementation, we would spawn kernel threads here
@@ -106,12 +107,6 @@ void ai_scheduler_init(uint32_t n_workers) {
106107

107108
// Moved matmul_worker to after ai_dot_q16_simd
108109

109-
static uint16_t* const vga_buffer = (uint16_t*)0xB8000;
110-
static const uint8_t vga_width = 80;
111-
static const uint8_t vga_height = 25;
112-
static uint8_t vga_x = 0;
113-
static uint8_t vga_y = 0;
114-
static uint8_t vga_color = 0x0A;
115110
static char token_history[10];
116111
static uint32_t token_count = 0;
117112
static uint32_t token_head = 0;
@@ -120,21 +115,7 @@ static q16_16_t ai_temp = 1 << 16;
120115
static uint32_t kv_cache_tokens = 0;
121116

122117
static void vga_put(char ch) {
123-
if (ch == '\n') {
124-
vga_x = 0;
125-
vga_y++;
126-
} else {
127-
uint32_t idx = (uint32_t)vga_y * vga_width + vga_x;
128-
vga_buffer[idx] = (uint16_t)ch | ((uint16_t)vga_color << 8);
129-
vga_x++;
130-
}
131-
if (vga_x >= vga_width) {
132-
vga_x = 0;
133-
vga_y++;
134-
}
135-
if (vga_y >= vga_height) {
136-
vga_y = vga_height - 1;
137-
}
118+
vga_putc(ch);
138119
}
139120

140121
void ai_stream_putc(char ch) {

src/drivers/vga.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,34 @@ static uint16_t* const vga_buffer = (uint16_t*)0xB8000;
77
static const uint8_t vga_width = 80;
88
static const uint8_t vga_height = 25;
99

10+
static uint8_t vga_cursor_x = 0;
11+
static uint8_t vga_cursor_y = 0;
12+
static uint8_t vga_current_color = 0x07;
13+
14+
void vga_set_color(uint8_t color) {
15+
vga_current_color = color;
16+
}
17+
18+
uint8_t vga_get_x(void) {
19+
return vga_cursor_x;
20+
}
21+
22+
uint8_t vga_get_y(void) {
23+
return vga_cursor_y;
24+
}
25+
26+
void vga_set_cursor(uint8_t x, uint8_t y) {
27+
if (x < vga_width) vga_cursor_x = x;
28+
if (y < vga_height) vga_cursor_y = y;
29+
}
30+
1031
void vga_clear(uint8_t color) {
1132
uint16_t blank = (uint16_t)' ' | ((uint16_t)color << 8);
1233
for (uint32_t i = 0; i < (uint32_t)vga_width * vga_height; ++i) {
1334
vga_buffer[i] = blank;
1435
}
36+
vga_cursor_x = 0;
37+
vga_cursor_y = 0;
1538
}
1639

1740
static void vga_put_at(char ch, uint8_t color, uint8_t x, uint8_t y) {
@@ -22,6 +45,36 @@ static void vga_put_at(char ch, uint8_t color, uint8_t x, uint8_t y) {
2245
vga_buffer[idx] = (uint16_t)ch | ((uint16_t)color << 8);
2346
}
2447

48+
void vga_putc(char ch) {
49+
if (ch == '\n') {
50+
vga_cursor_x = 0;
51+
vga_cursor_y++;
52+
} else if (ch == '\r') {
53+
vga_cursor_x = 0;
54+
} else {
55+
vga_put_at(ch, vga_current_color, vga_cursor_x, vga_cursor_y);
56+
vga_cursor_x++;
57+
}
58+
59+
if (vga_cursor_x >= vga_width) {
60+
vga_cursor_x = 0;
61+
vga_cursor_y++;
62+
}
63+
64+
if (vga_cursor_y >= vga_height) {
65+
// Simple scroll: just reset to top or stay at bottom?
66+
// For now, let's just stay at bottom and clear or similar.
67+
// Real scrolling would involve memmove.
68+
vga_cursor_y = vga_height - 1;
69+
}
70+
}
71+
72+
void vga_puts(const char* text) {
73+
for (uint32_t i = 0; text[i] != 0; ++i) {
74+
vga_putc(text[i]);
75+
}
76+
}
77+
2578
static void vga_write_at(const char* text, uint8_t color, uint8_t x, uint8_t y) {
2679
uint8_t col = x;
2780
uint8_t row = y;

0 commit comments

Comments
 (0)