aboutsummaryrefslogtreecommitdiff
path: root/kernel/writer.dats
diff options
context:
space:
mode:
authorXander <xander@icth.xyz>2023-06-30 21:25:18 +0200
committerXander <xander@icth.xyz>2023-06-30 21:27:18 +0200
commite9b14562b46f230e7208ea3dad8d836f73e8f100 (patch)
tree3cfa4355c7e48e295e4b362e6266936a20b2274b /kernel/writer.dats
parent3f846ecba11a66d7679a68c187d4f6e3560af5e6 (diff)
downloadats-os-e9b14562b46f230e7208ea3dad8d836f73e8f100.tar.xz
ats-os-e9b14562b46f230e7208ea3dad8d836f73e8f100.zip
Modulating print
Diffstat (limited to 'kernel/writer.dats')
-rw-r--r--kernel/writer.dats57
1 files changed, 57 insertions, 0 deletions
diff --git a/kernel/writer.dats b/kernel/writer.dats
new file mode 100644
index 0000000..7d0383f
--- /dev/null
+++ b/kernel/writer.dats
@@ -0,0 +1,57 @@
+#include "share/atspre_staload.hats"
+
+staload "kernel/writer.sats"
+
+extern castfn i2u8 {n: nat} (i: int n): uint8 n
+
+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 output_char(c : char, writer : !writer) : void = let
+ val p = writer.buffer.1
+ val () = p->[writer.column_position] := @{ ascii_character = c , color_code = writer.color_code }
+in
+ ()
+end
+
+%{^
+ #define get_vram() ((void *) 0xB8000 + 1988)
+%}
+
+extern fun get_vram():<> [l: addr] (@[screenChar][N] @ l | ptr l) = "mac#"
+
+extern prfun eat_writer (pf: writer): void
+
+extern castfn uint8_of {n: nat} (i: int n): uint8 n
+
+implement print_char(c : char) : void = let
+ val (pf_vram | vram) = get_vram()
+ val writer = @{
+ column_position = i2sz 0,
+ color_code = code_value(Yellow,Black),
+ buffer = (pf_vram | vram)
+ }
+in
+ output_char(c,writer);
+ let prval () = eat_writer writer in () end
+end
+