Skip to content

Commit b41dd55

Browse files
committed
Added display buffer per application
1 parent aaab409 commit b41dd55

File tree

7 files changed

+59
-23
lines changed

7 files changed

+59
-23
lines changed

src/drivers/display/text_mode.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ void io_low_scroll_screen(char count, unsigned char color,
1313
int x1, int y1,
1414
int x2, int y2);
1515

16-
void io_low_put_char(char c, unsigned char color);
16+
void io_low_put_char(char c, unsigned char color);
17+
18+
void io_low_flush();

src/drivers/display/text_mode_bios.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,9 @@ void io_low_scroll_screen(char count, unsigned char color,
5252
}
5353

5454
void io_low_put_char(char c, unsigned char color) {
55-
_low_put_chars(c, 1, color);
55+
_low_put_chars(c, 1, color);
56+
}
57+
58+
void io_low_flush() {
59+
// Not implemented, as it's not required.
5660
}

src/drivers/display/text_mode_vga.asm

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
global _low_put_char
44
global _low_vga_copy_step
5+
global _low_flush
56

67
[SECTION .text]
78
_low_put_char:
@@ -47,4 +48,23 @@ global _low_vga_copy_step
4748
pop ds
4849
mov esp, ebp
4950
pop ebp
51+
ret
52+
53+
_low_flush:
54+
push ebp
55+
mov ebp, esp
56+
push es
57+
mov eax, 0x20
58+
mov es, eax ; Absolute memory address
59+
60+
mov esi,[ebp + 0x8] ; (buffer)
61+
mov cx, [ebp + 0xc] ; (count)
62+
mov edi, 0xb8000
63+
64+
cld
65+
rep movsw
66+
67+
pop es
68+
mov esp, ebp
69+
pop ebp
5070
ret

src/drivers/display/text_mode_vga.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ extern void _low_put_char(char c, unsigned char color, unsigned int xy);
44

55
extern void _low_vga_copy_step(unsigned int xy1, unsigned int xy2, unsigned int count);
66

7+
extern _low_flush(unsigned short *buffer, int count);
8+
79
static int location_xy = 0;
810

911
int IO_CURRENT_X = 0;
1012
int IO_CURRENT_Y = 0;
13+
unsigned short buffer[TEXT_WINDOW_HEIGHT*TEXT_WINDOW_WIDTH] = {0};
1114

1215
int get_display_text_x() {
1316
return IO_CURRENT_X;
@@ -38,40 +41,40 @@ void io_low_scroll_screen(char count, unsigned char color,
3841
int x2, int y2) {
3942
if (count == 0) {
4043
for (int r = y1; r <= y2; ++r) {
41-
int index = r*TEXT_WINDOW_WIDTH;
42-
for (int c = x1; c <= x2; ++c, index++) {
43-
_low_put_char(' ', color, index);
44+
int d_index = r*TEXT_WINDOW_WIDTH+x1;
45+
for (int c = x1; c <= x2; ++c) {
46+
buffer[d_index++]=(color<<8)|' ';
4447
}
4548
}
4649
} else if (count > 0) {
4750
// Not yet tested.
4851
int width = x2-x1+1;
49-
for (int r1=y1,r2 = y1+count; r2 <= y2; r1++,r2++) {
50-
_low_vga_copy_step(
51-
r2*TEXT_WINDOW_WIDTH + x1,
52-
r1*TEXT_WINDOW_WIDTH + x1,
53-
width
54-
);
55-
io_low_scroll_screen(0,color,
56-
x1, y2-count,
57-
x2, y2);
52+
for (int r_dest=y1,r_src = y1+count; r_src <= y2; r_src++,r_dest++) {
53+
int s_index = r_src*TEXT_WINDOW_WIDTH+x1;
54+
int d_index = r_dest*TEXT_WINDOW_WIDTH+x1;
55+
for (int j = x1; j <= x2; ++j) {
56+
buffer[d_index++]=buffer[s_index++];
57+
}
5858
}
5959
} else {
6060
// Not yet tested.
6161
int width = x2-x1+1;
62-
for (int r1=y2,r2 = y2+count; r2 >= y1; r1--,r2--) {
63-
_low_vga_copy_step(
64-
r2*TEXT_WINDOW_WIDTH + x1,
65-
r1*TEXT_WINDOW_WIDTH + x1,
66-
width
67-
);
68-
io_low_scroll_screen(0,color,
69-
x1, y1,
70-
x2, y1+count);
62+
for (int r_dest=y2,r_src = y2+count; r_src >= y1; r_src--,r_dest--) {
63+
int s_index = r_src*TEXT_WINDOW_WIDTH+x1;
64+
int d_index = r_dest*TEXT_WINDOW_WIDTH+x1;
65+
for (int j = x1; j <= x2; ++j) {
66+
buffer[d_index++]=buffer[s_index++];
67+
}
7168
}
7269
}
70+
io_low_flush();
7371
}
7472

7573
void io_low_put_char(char c, unsigned char color) {
7674
_low_put_char(c,color, location_xy);
75+
buffer[location_xy]=(color<<8)|c;
76+
}
77+
78+
void io_low_flush() {
79+
_low_flush(buffer, sizeof(buffer)/2);
7780
}

src/kernel/process.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include <lib/utils/logging.h>
3+
#include <lib/utils/output.h>
34

45
#include "memmgr/tables/gdt.c"
56

@@ -81,5 +82,6 @@ int process_exec(int sector_index, int sector_count) {
8182
*(int*)relative_address);
8283
int exit_code = call_main(0, 0);
8384
process_free_id(id);
85+
io_low_flush();
8486
return exit_code;
8587
}

src/lib/utils/output.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include <lib/utils/output.h>
44
#include <drivers/display/text_mode.h>
55

6+
void flush_screen() {
7+
io_low_flush();
8+
}
9+
610
void move_x(unsigned char x) {
711
set_display_text_x(x);
812
}

src/lib/utils/output.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern "C" {
77
#include <lib/utils/color.h>
88
#include <drivers/display/text_mode.h>
99

10+
void flush_screen();
1011
void move_x(unsigned char x);
1112
void move_y(unsigned char y);
1213
void move_xy(unsigned char x, unsigned char y);

0 commit comments

Comments
 (0)