From 52b6f5d7e03f6918d56f80fab2deaa807d08764a Mon Sep 17 00:00:00 2001 From: Xander Date: Mon, 3 Jul 2023 14:48:38 +0200 Subject: Now using static writer --- kernel/main.dats | 2 +- kernel/writer.dats | 98 ++++++++++++++++++++++++++++++++---------------------- kernel/writer.sats | 9 +++-- 3 files changed, 65 insertions(+), 44 deletions(-) diff --git a/kernel/main.dats b/kernel/main.dats index 9bff703..bf20c37 100644 --- a/kernel/main.dats +++ b/kernel/main.dats @@ -3,4 +3,4 @@ staload "kernel/writer.sats" dynload "kernel/writer.dats" -implement main0 () = print_char('X') +implement main0 () = put_string(" Hello world") diff --git a/kernel/writer.dats b/kernel/writer.dats index 9ea10b8..0d67129 100644 --- a/kernel/writer.dats +++ b/kernel/writer.dats @@ -2,57 +2,75 @@ staload "kernel/writer.sats" -extern castfn i2u8 {n: nat} (i: int n): uint8 n +%{^ + #define get_buffer() ((void *) 0xB8000) +%} -extern fun get_vram():<> [l: agz] (@[screenChar][N] @ l | ptr l) = "mac#" +extern fun get_buffer():<> buffer = "mac#" +extern prfun eat_buffer (pf: buffer): void -extern prfun eat_writer (pf: writer): void +staload WRITER = { + staload "kernel/writer.sats" + extern fun getref (): [l:addr] vtakeoutptr (writer) -%{^ - #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) + + local -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) + var _val: writer = @{position = 0, color_code = code_value(White,Black)} : writer + val p_val = addr@(_val) + + in + + implement getref () = let + extern praxi __assert{l:addr} (ptr: ptr (l)): vtakeout0 (writer@l) + prval (pf, fpf) = __assert (p_val) + in + (pf, fpf | p_val) + end + end +} fun put_char (c : char, writer: &writer) : void = let - val v = writer.buffer.1 + val buf = get_buffer() val pos = writer.position in - v->[writer.position] := @{ ascii_character = c, color_code = writer.color_code}; + buf.1->[writer.position] := @{ ascii_character = c, color_code = writer.color_code}; + + if (pos < N - 1) then + writer.position := succ(pos); - if (pos < N - 1) then - writer.position := succ(pos) + let prval() = eat_buffer buf in () end 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 + +implement put_string (str : string) : void = let + val (pf, fpf | p_val) = $WRITER.getref() + implement string_foreach$fwork (c,env) = put_char(c,env) + val _ = string_foreach_env (g1ofg0(str),!p_val) + prval() = fpf(pf) 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 + + diff --git a/kernel/writer.sats b/kernel/writer.sats index 43881b1..e6baef5 100644 --- a/kernel/writer.sats +++ b/kernel/writer.sats @@ -1,4 +1,4 @@ -#define N 2000 +#define N 80 * 25 datatype color = | Black @@ -21,6 +21,9 @@ datatype color = typedef screenChar = @{ ascii_character = char, color_code = uint8} -vtypedef writer = [l : agz] @{position = [a:int | a >= 0 && a < N] int (a), color_code = uint8 , buffer = (@[screenChar][N] @ l | ptr l)} +vtypedef buffer = [l : agz] (@[screenChar][N] @ l | ptr l) +typedef writer = @{position = [a:int | a >= 0 && a < N] int (a), color_code = uint8} -fun print_char(c : char) : void +castfn i2u8 {n: nat} (i: int n): uint8 n + +fun put_string (str : string) : void -- cgit v1.2.3