From 948737432882f4333168be4411b1caf115d3f4b6 Mon Sep 17 00:00:00 2001 From: julianb0 Date: Thu, 20 Jun 2019 18:13:06 +0200 Subject: [PATCH] dev --- ka/dos.k | 2 +- ka/inc/screen.k | 6 ++++++ ka/main.k | 18 ------------------ ka/tests.k | 19 +++++++++++++++++++ vm/{in => dv}/DEVCTL | 0 vm/dv/DEVICES | 12 ++++++++++++ vm/dv/clockdev.c | 31 +++++++++++++++++++++++++++++++ vm/dv/keybdev.c | 31 +++++++++++++++++++++++++++++++ vm/pc/console.c | 11 +++++++---- vm/pc/dev.c | 4 +++- vm/pc/dev.h | 2 +- 11 files changed, 111 insertions(+), 25 deletions(-) create mode 100644 ka/inc/screen.k rename vm/{in => dv}/DEVCTL (100%) create mode 100644 vm/dv/DEVICES create mode 100644 vm/dv/clockdev.c create mode 100644 vm/dv/keybdev.c diff --git a/ka/dos.k b/ka/dos.k index 238d156..d3f6bf8 100644 --- a/ka/dos.k +++ b/ka/dos.k @@ -11,7 +11,7 @@ _start: call main .1: - stop + hlt jmp .1 ; diff --git a/ka/inc/screen.k b/ka/inc/screen.k new file mode 100644 index 0000000..a35d291 --- /dev/null +++ b/ka/inc/screen.k @@ -0,0 +1,6 @@ +; The OS/K Team licenses this file to you under the MIT license. +; See the LICENSE file in the project root for more information. + +SCR_TEXTMODE_WIDTH := 80 +SCR_TEXTMODE_HEIGHT := 25 + diff --git a/ka/main.k b/ka/main.k index 06a3c8e..702b3fa 100644 --- a/ka/main.k +++ b/ka/main.k @@ -5,23 +5,5 @@ ; Main function ; main: - mov rdx, 25 -.1: - mov rcx, 79 - prn.rep '+' - prn '!' - dec rdx - test rdx, rdx - j.nz .1 - - mov rcx, 80 - prn.rep '&' - - mov rcx, 80 - prn.rep '%' - - call showoff - - hlt ret diff --git a/ka/tests.k b/ka/tests.k index d188ad4..e64d6f5 100644 --- a/ka/tests.k +++ b/ka/tests.k @@ -1,6 +1,25 @@ ; The OS/K Team licenses this file to you under the MIT license. ; See the LICENSE file in the project root for more information. +putc_scroll_test: + mov rdx, 25 +.1: + mov rcx, 79 + prn.rep '+' + prn '!' + dec rdx + test rdx, rdx + j.nz .1 + + mov rcx, 80 + prn.rep '&' + + mov rcx, 80 + prn.rep '%' + + call showoff + ret + cpudev_test: call RFS.GetLeastAvail mov rbx, rax diff --git a/vm/in/DEVCTL b/vm/dv/DEVCTL similarity index 100% rename from vm/in/DEVCTL rename to vm/dv/DEVCTL diff --git a/vm/dv/DEVICES b/vm/dv/DEVICES new file mode 100644 index 0000000..0a26156 --- /dev/null +++ b/vm/dv/DEVICES @@ -0,0 +1,12 @@ +# The OS/K Team licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +The following device numbers are reserved and always correspond +to the same device: + + # desc + 0 CPU device + 1 memory device + 2 clock device + 3 keyboard device + 4 screen device diff --git a/vm/dv/clockdev.c b/vm/dv/clockdev.c new file mode 100644 index 0000000..6c3d7af --- /dev/null +++ b/vm/dv/clockdev.c @@ -0,0 +1,31 @@ +// The OS/K Team licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include + +//----------------------------------------------------------------------------// + +long clockdev_poweron(ctx_t *ctx, dev_t *dev) +{ + dev->state = DEVGOOD; + + return 0; +} + +//----------------------------------------------------------------------------// + +dev_t clockdev = +{ + .type = "clock", + .name = "clock device", + .modl = "", + .vend = "The OS/K Team", + + .major = KARCH_MAJOR, + .minor = KARCH_MINOR, + .revis = KARCH_REVIS, + + .fpwon = clockdev_poweron, +}; + + diff --git a/vm/dv/keybdev.c b/vm/dv/keybdev.c new file mode 100644 index 0000000..8ccde02 --- /dev/null +++ b/vm/dv/keybdev.c @@ -0,0 +1,31 @@ +// The OS/K Team licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include + +//----------------------------------------------------------------------------// + +long keybdev_poweron(ctx_t *ctx, dev_t *dev) +{ + dev->state = DEVGOOD; + + return 0; +} + +//----------------------------------------------------------------------------// + +dev_t keybdev = +{ + .type = "keyboard", + .name = "keyboard device", + .modl = "", + .vend = "The OS/K Team", + + .major = KARCH_MAJOR, + .minor = KARCH_MINOR, + .revis = KARCH_REVIS, + + .fpwon = keybdev_poweron, +}; + + diff --git a/vm/pc/console.c b/vm/pc/console.c index ade6f79..4d08ce8 100644 --- a/vm/pc/console.c +++ b/vm/pc/console.c @@ -32,6 +32,8 @@ void console_init(ctx_t *ctx) SDL_CreateWindowAndRenderer(SCREEN_WIDTH, SCREEN_HEIGHT, 0, &scr_win, &scr_rend); + SDL_SetRenderDrawColor(scr_rend, 20, 20, 20, 0); + if (scr_win == NULL || scr_rend == NULL) { logerr("Couldn't create SDL screen window/renderer: %s", SDL_GetError()); @@ -55,6 +57,9 @@ void console_init(ctx_t *ctx) memset(scr_lines[y], ' ', CONSOLE_WIDTH); scr_lines[y][CONSOLE_WIDTH] = 0; } + + SDL_RenderClear(scr_rend); + SDL_RenderPresent(scr_rend); } //----------------------------------------------------------------------------// @@ -85,9 +90,6 @@ void console_render(ctx_t *ctx) { size_t y; - SDL_SetRenderDrawColor(scr_rend, 20, 20, 20, 0); - //SDL_RenderSetScale(scr_rend, 0.2f, 0.2f); - SDL_RenderClear(scr_rend); for (y = 0; y < CONSOLE_HEIGHT; y++) @@ -118,7 +120,8 @@ void console_putat(ctx_t *ctx, char ch, int x, int y) if (!surf) { - logerr("console_putat: couldn't render TTF font\n"); + logerr("console_putat: couldn't render TTF font: " + "(%d,%d) '%c'\nError: '%s'\n", x, y, ch, SDL_GetError()); die(-1); } diff --git a/vm/pc/dev.c b/vm/pc/dev.c index 105fccd..405288b 100644 --- a/vm/pc/dev.c +++ b/vm/pc/dev.c @@ -9,12 +9,14 @@ // Add new builtin devices here // -extern dev_t cpudev, memdev; +extern dev_t cpudev, memdev, clockdev, keybdev, screendev; static dev_t *arch_d[] = { &cpudev, &memdev, + &clockdev, + &keybdev, NULL, }; diff --git a/vm/pc/dev.h b/vm/pc/dev.h index 90767f0..366ca5e 100644 --- a/vm/pc/dev.h +++ b/vm/pc/dev.h @@ -4,7 +4,7 @@ #include #define DEVLEN 32 -#define DEVSLOTS 256 +#define DEVSLOTS 4096 typedef long (*devfn_t)(ctx_t *, dev_t *);