diff options
author | Xander <xander@icth.xyz> | 2023-07-02 15:08:43 +0200 |
---|---|---|
committer | Xander <xander@icth.xyz> | 2023-07-02 15:08:43 +0200 |
commit | d7df4f130521f6005feda56a15f82eb3bf8597dd (patch) | |
tree | 5781e727a31df75fda53f0f56a104df6cfc01ff6 /kernel/writer.dats | |
parent | e9b14562b46f230e7208ea3dad8d836f73e8f100 (diff) | |
download | ats-os-d7df4f130521f6005feda56a15f82eb3bf8597dd.tar.xz ats-os-d7df4f130521f6005feda56a15f82eb3bf8597dd.zip |
Using reference
Diffstat (limited to 'kernel/writer.dats')
-rw-r--r-- | kernel/writer.dats | 41 |
1 files changed, 21 insertions, 20 deletions
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 |