diff options
author | Xander <xander@icth.xyz> | 2023-06-30 21:25:18 +0200 |
---|---|---|
committer | Xander <xander@icth.xyz> | 2023-06-30 21:27:18 +0200 |
commit | e9b14562b46f230e7208ea3dad8d836f73e8f100 (patch) | |
tree | 3cfa4355c7e48e295e4b362e6266936a20b2274b /kernel | |
parent | 3f846ecba11a66d7679a68c187d4f6e3560af5e6 (diff) | |
download | ats-os-e9b14562b46f230e7208ea3dad8d836f73e8f100.tar.xz ats-os-e9b14562b46f230e7208ea3dad8d836f73e8f100.zip |
Modulating print
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/main.dats | 30 | ||||
-rw-r--r-- | kernel/writer.dats | 57 | ||||
-rw-r--r-- | kernel/writer.sats | 27 |
3 files changed, 87 insertions, 27 deletions
diff --git a/kernel/main.dats b/kernel/main.dats index e7a68f5..bbec179 100644 --- a/kernel/main.dats +++ b/kernel/main.dats @@ -1,16 +1,7 @@ #include "share/atspre_staload.hats" -%{^ - #define get_vram(_) ((void *) 0xB8000 + 1988) -%} - -typedef cell = @{ ch = char, attrib = uint8 } - -extern fun get_vram {n: nat} (n : size_t n):<> [l: agz] (@[cell][n] @ l | ptr l) = "mac#" - -extern prfun eat_vram {l: agz} {n: int} (pf: @[cell][n] @ l): void - -extern castfn uint8_of {n: nat} (i: int n): uint8 n +staload "kernel/writer.sats" +dynload "kernel/writer.dats" fn string_length {n:nat} (str: string (n)) : size_t (n) = let fun loop {i:nat | i <= n} .<n-i>. (str: string n, i: size_t i): size_t (n) = @@ -19,19 +10,4 @@ in loop (str, i2sz(0)) end -implement main0 () = let - val hello = "Hello world!" - val length = string_length hello - val color_byte = 0x1f - val (pf_vram | vram) = get_vram(length) - fun loop {l : agz} {n,i: nat | i <= n} .<n-i>. (pf: !(@[cell][n] @ l) | n : size_t n, i : int i, p : ptr l, str: string (n)) : void = - if n > i then ( - p->[i] := @{ ch = str[i], attrib = uint8_of color_byte }; - loop(pf | n,i+1,p,str)) - else () - -in - loop(pf_vram | length, 0, vram, hello); - let prval () = eat_vram pf_vram in () end -end - +implement main0 () = print_char('X') 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 + diff --git a/kernel/writer.sats b/kernel/writer.sats new file mode 100644 index 0000000..c9b8814 --- /dev/null +++ b/kernel/writer.sats @@ -0,0 +1,27 @@ +#define N 80 * 25 + +datatype color = + | Black + | Blue + | Green + | Cyan + | Red + | Magenta + | Brown + | LightGray + | DarkGray + | LightBlue + | LightGreen + | LightCyan + | LightRed + | Pink + | Yellow + | White + + +typedef screenChar = @{ ascii_character = char, color_code = uint8} + +vtypedef tptr (a: t@ype, l:addr) = (a @ l | ptr l) +vtypedef writer = [l: addr] [n:nat | n < N] @{ column_position = size_t n, color_code = uint8 , buffer = tptr(@[screenChar][N],l)} + +fun print_char(c : char) : void |