blob: 9ea10b82b01274ea814447ea740515f0f573201c (
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#include "share/atspre_staload.hats"
staload "kernel/writer.sats"
extern castfn i2u8 {n: nat} (i: int n): uint8 n
extern fun get_vram():<> [l: agz] (@[screenChar][N] @ l | ptr l) = "mac#"
extern prfun eat_writer (pf: writer): void
%{^
#define get_vram() ((void *) 0xB8000 + 1988)
%}
fun color_value(c : color): uint8 =
case+ c of
| Black() => i2u8 0
| Blue() => i2u8 1
| Green() => i2u8 2
| Cyan() => i2u8 3
| Red() => i2u8 4
| Magenta() => i2u8 5
| Brown() => i2u8 6
| LightGray() => i2u8 7
| DarkGray() => i2u8 8
| LightBlue() => i2u8 9
| LightGreen() => i2u8 10
| LightCyan() => i2u8 11
| LightRed() => i2u8 12
| Pink() => i2u8 13
| Yellow() => i2u8 14
| White() => i2u8 15
fun code_value(foreground: color, background:color): uint8 =
(color_value(background) << 4) lor color_value(foreground)
fun put_char (c : char, writer: &writer) : void = let
val v = writer.buffer.1
val pos = writer.position
in
v->[writer.position] := @{ ascii_character = c, color_code = writer.color_code};
if (pos < N - 1) then
writer.position := succ(pos)
end
implement print_char(c : char) : void = let
val (pf_vram | vram) = get_vram()
var writer = @{position = 0, color_code = code_value(Black,Yellow), buffer = (pf_vram | vram)} : writer
in
put_char(c,writer);
put_char(c,writer);
put_char(c,writer);
put_char(c,writer);
put_char(c,writer);
let prval () = eat_writer writer in () end
end
|