From d7df4f130521f6005feda56a15f82eb3bf8597dd Mon Sep 17 00:00:00 2001 From: Xander Date: Sun, 2 Jul 2023 15:08:43 +0200 Subject: Using reference --- kernel/writer.dats | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'kernel/writer.dats') diff --git a/kernel/writer.dats b/kernel/writer.dats index 7d0383f..9ea10b8 100644 --- a/kernel/writer.dats +++ b/kernel/writer.dats @@ -4,6 +4,14 @@ 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 @@ -26,32 +34,25 @@ fun color_value(c : color): uint8 = 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 } +fun put_char (c : char, writer: &writer) : void = let + val v = writer.buffer.1 + val pos = writer.position in - () -end + v->[writer.position] := @{ ascii_character = c, color_code = writer.color_code}; -%{^ - #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 + if (pos < N - 1) then + writer.position := succ(pos) +end 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) - } + var writer = @{position = 0, color_code = code_value(Black,Yellow), buffer = (pf_vram | vram)} : writer in - output_char(c,writer); + 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 -- cgit v1.2.3