-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole.pas
91 lines (77 loc) · 1.67 KB
/
console.pas
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
{
This file is part of Jacqueline: an experimental i386 bootable application
Copyright (C) 2020 Dani Rodríguez <dani@danirod.es>
console.pas - manager for the standard VGA text mode framebuffer
}
unit console;
interface
type
AnsiColor = (
Black := #0,
Blue := #1,
Green := #2,
Cyan := #3,
Red := #4,
Magenta := #5,
Brown := #6,
Gray := #7,
DarkGray := #8,
LightBlue := #9,
LightGreen := #10,
LightCyan := #11,
LightRed := #12,
LightMagenta := #13,
Yellow := #14,
White := #15
);
procedure consoleClearDisplay();
procedure consolePutChar(c: char);
procedure consolePutString(s: pchar);
procedure consoleSetAttributes(foreground, background: AnsiColor);
implementation
const
FRAMEBUFFER_COLS = 80;
FRAMEBUFFER_ROWS = 25;
FRAMEBUFFER_ADDRESS = $b8000;
var
cursorX: integer = 0;
cursorY: integer = 0;
cursorColor: byte = $07;
framebuffer: pchar = pchar(FRAMEBUFFER_ADDRESS);
procedure consoleClearDisplay();
var
i: integer;
begin
cursorX := 0;
cursorY := 0;
for i := 0 to FRAMEBUFFER_COLS * FRAMEBUFFER_ROWS * 2 do begin
framebuffer[i] := #0;
end;
end;
procedure consoleSetAttributes(foreground, background: AnsiColor);
begin
cursorColor := (byte(background) and $f << 4) or (byte(foreground) and $f);
end;
procedure consolePutString(s: pchar);
var
i: integer = 0;
begin
while s[i] <> #0 do begin
consolePutChar(s[i]);
i := i + 1;
end
end;
procedure consolePutChar(c: char);
var
index: integer;
begin
index := (FRAMEBUFFER_COLS * cursorY + cursorX) * 2;
framebuffer[index] := c;
framebuffer[index + 1] := char(cursorColor);
cursorX := cursorX + 1;
if cursorX >= 80 then begin
cursorX := 0;
cursorY := cursorY + 1;
end
end;
end.