summaryrefslogtreecommitdiff
path: root/src/user/app/vterm/draw.c
blob: 44d3ffe451607ccaa189c2f79ff0c31972e17c25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "vterm.h"
#include <camellia/syscalls.h>
#include <string.h>

struct framebuf fb;
handle_t fb_fd;
struct rect dirty;


void dirty_mark(uint32_t x, uint32_t y) {
	if (dirty.x1 > x) dirty.x1 = x;
	if (dirty.x2 < x) dirty.x2 = x;
	if (dirty.y1 > y) dirty.y1 = y;
	if (dirty.y2 < y) dirty.y2 = y;
}

void flush(void) {
	size_t low, high;
	if (~dirty.x1 == 0) return;

	// still not optimal, copies 80 characters instead of 1
	low  = fb.pitch * ( dirty.y1    * font.h) + 4 * ( dirty.x1    * font.w);
	high = fb.pitch * ((dirty.y2+1) * font.h) + 4 * ((dirty.x2+1) * font.w) + 3;

	if (~dirty.y2 == 0) high = fb.len;
	if (high > fb.len)  high = fb.len;

	while (low < high)
		low += _syscall_write(fb_fd, fb.b + low, high - low, low, 0);

	dirty.x1 = ~0; dirty.y1 = ~0;
	dirty.x2 =  0; dirty.y2 =  0;
}

void scroll(void) {
	// TODO memmove. this is UD
	size_t row_len = fb.pitch * font.h;
	memcpy(fb.b, fb.b + row_len, fb.len - row_len);
	memset(fb.b + fb.len - row_len, 0, row_len);
	cursor.y--;

	dirty.x1 =  0; dirty.y1 =  0;
	dirty.x2 = ~0; dirty.y2 = ~0;
}