Skip to content

Commit 4a593b2

Browse files
committed
drivers: buffer multiple VGA screens
Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
1 parent 80c08fc commit 4a593b2

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

drivers/vga.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@
3030
#define MAX_ROWS VGA_ROWS
3131
#define MAX_COLS (2 * VGA_COLS)
3232

33-
static uint8_t vga_buffer[MAX_ROWS][MAX_COLS];
3433

35-
static inline void write_vga_buffer(void) {
34+
static uint8_t vga_buffer[VGA_SCREENS][MAX_ROWS][MAX_COLS];
35+
36+
static inline void write_vga_buffer(int cur_screen) {
3637
void *vga_memory = paddr_to_virt_kern(VGA_START_ADDR);
3738

38-
memcpy(vga_memory, vga_buffer, sizeof(vga_buffer));
39+
memcpy(vga_memory, vga_buffer[cur_screen], sizeof(vga_buffer[cur_screen]));
3940
}
4041

4142
void vga_write(const char *buf, size_t len, vga_color_t color) {
42-
static int row = 0, col = 0;
43+
static int screen = 0, row = 0, col = 0;
4344

4445
for (unsigned int i = 0; i < len; i++) {
4546
char c = buf[i];
@@ -50,21 +51,19 @@ void vga_write(const char *buf, size_t len, vga_color_t color) {
5051
row++;
5152
}
5253

53-
/* Scroll up one row when hit end of VGA area */
54+
/* Go to the next screen when hit end of VGA area */
5455
if (row == (MAX_ROWS - 1)) {
55-
memmove(vga_buffer[0], vga_buffer[1],
56-
sizeof(vga_buffer) - sizeof(vga_buffer[0]));
57-
memset(vga_buffer[MAX_ROWS - 1], 0x00, MAX_COLS);
58-
col = 0;
59-
row--;
56+
screen = (screen + 1) % VGA_SCREENS;
57+
memset(vga_buffer[screen], 0x00, sizeof(vga_buffer[screen]));
58+
row = col = 0;
6059
}
6160

6261
if (c == '\n')
6362
continue;
6463

65-
vga_buffer[row][col++] = buf[i];
66-
vga_buffer[row][col++] = color;
64+
vga_buffer[screen][row][col++] = buf[i];
65+
vga_buffer[screen][row][col++] = color;
6766
}
6867

69-
write_vga_buffer();
68+
write_vga_buffer(screen);
7069
}

include/drivers/vga.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ typedef enum vga_color vga_color_t;
5353
#define VGA_END_ADDR 0xBFFFF
5454
#define VGA_ROWS 25
5555
#define VGA_COLS 80
56+
#define VGA_SCREENS 10
5657

5758
extern void vga_write(const char *buf, size_t len, vga_color_t color);
5859
#endif /* KTF_DRV_VGA_H */

0 commit comments

Comments
 (0)