diff options
author | Xander <xander@icth.xyz> | 2023-07-03 15:13:48 +0200 |
---|---|---|
committer | Xander <xander@icth.xyz> | 2023-07-03 15:13:48 +0200 |
commit | 4c7934102bea39f002f637ebf12863bf99dd99a7 (patch) | |
tree | a22a95de15008a14f4b35c293e32daec695e29a3 | |
parent | 52b6f5d7e03f6918d56f80fab2deaa807d08764a (diff) | |
download | ats-os-4c7934102bea39f002f637ebf12863bf99dd99a7.tar.xz ats-os-4c7934102bea39f002f637ebf12863bf99dd99a7.zip |
Implemented newline
-rw-r--r-- | kernel/main.dats | 5 | ||||
-rw-r--r-- | kernel/writer.dats | 22 | ||||
-rw-r--r-- | kernel/writer.sats | 4 |
3 files changed, 21 insertions, 10 deletions
diff --git a/kernel/main.dats b/kernel/main.dats index bf20c37..dfbaa49 100644 --- a/kernel/main.dats +++ b/kernel/main.dats @@ -3,4 +3,7 @@ staload "kernel/writer.sats" dynload "kernel/writer.dats" -implement main0 () = put_string(" Hello world") +implement main0 () = ( + put_string(" Hello world\n"); + put_string("GOEIENDSG\n"); + put_string("GOEIENDSG")) diff --git a/kernel/writer.dats b/kernel/writer.dats index 0d67129..cd6f5d7 100644 --- a/kernel/writer.dats +++ b/kernel/writer.dats @@ -51,14 +51,23 @@ staload WRITER = { end } + fun put_char (c : char, writer: &writer) : void = let val buf = get_buffer() val pos = writer.position in - buf.1->[writer.position] := @{ ascii_character = c, color_code = writer.color_code}; - - if (pos < N - 1) then - writer.position := succ(pos); + if (c = '\n') then + let + val new_pos = (pos / BUFFER_WIDTH + 1) * BUFFER_WIDTH + in + if (new_pos < N) then + writer.position := new_pos + end + else ( + buf.1->[writer.position] := @{ ascii_character = c, color_code = writer.color_code}; + + if (pos < N - 1) then + writer.position := succ(pos)); let prval() = eat_buffer buf in () end end @@ -69,8 +78,5 @@ implement put_string (str : string) : void = let implement string_foreach$fwork<writer> (c,env) = put_char(c,env) val _ = string_foreach_env<writer> (g1ofg0(str),!p_val) prval() = fpf(pf) -in -end - - +in end diff --git a/kernel/writer.sats b/kernel/writer.sats index e6baef5..3ccfd7b 100644 --- a/kernel/writer.sats +++ b/kernel/writer.sats @@ -1,4 +1,6 @@ -#define N 80 * 25 +#define BUFFER_HEIGHT 23 +#define BUFFER_WIDTH 80 +#define N BUFFER_HEIGHT * BUFFER_WIDTH datatype color = | Black |