mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
...
This commit is contained in:
parent
6f8a5d1f76
commit
b0bfce1ced
@ -54,6 +54,6 @@ clean:
|
||||
@rm -f $(OBJDIR)/*/*.d
|
||||
|
||||
k.exe: in/instrs.lst $(obj)
|
||||
@gcc -O2 -lSDL2 -Wall $(obj) -o k.exe
|
||||
@gcc -O2 -lSDL2 -lSDL2_ttf -Wall $(obj) -o k.exe
|
||||
@echo ${CL2}[$@] ${CL}made successfully.${CL3}
|
||||
|
||||
|
20
vm/a.sym
20
vm/a.sym
@ -82,13 +82,13 @@ itoa_test 1052600
|
||||
devtest 1052764
|
||||
str_test 1052848
|
||||
main 1053184
|
||||
errno 1053192
|
||||
trap0_test.msg 1053200
|
||||
printf_test.fmt 1053223
|
||||
printf_test.str 1053271
|
||||
strchr_test.str 1053279
|
||||
itoa_test.buf 1053295
|
||||
devtest.buf 1053335
|
||||
str_test.msg 1053375
|
||||
str_test.buf1 1053391
|
||||
str_test.buf2 1053431
|
||||
errno 1053208
|
||||
trap0_test.msg 1053216
|
||||
printf_test.fmt 1053239
|
||||
printf_test.str 1053287
|
||||
strchr_test.str 1053295
|
||||
itoa_test.buf 1053311
|
||||
devtest.buf 1053351
|
||||
str_test.msg 1053391
|
||||
str_test.buf1 1053407
|
||||
str_test.buf2 1053447
|
||||
|
160
vm/cn/console.c
160
vm/cn/console.c
@ -3,14 +3,166 @@
|
||||
|
||||
#include <cn/console.h>
|
||||
|
||||
#define SCREEN_WIDTH (1280)
|
||||
#define SCREEN_HEIGHT (720)
|
||||
|
||||
SDL_Window *scr_win = NULL;
|
||||
SDL_Renderer *scr_rend = NULL;
|
||||
|
||||
TTF_Font *scr_font = NULL;
|
||||
SDL_Color scr_text_color = { 255, 255, 255, 0 };
|
||||
|
||||
SDL_Rect *scr_rects[SCREEN_WIDTH][SCREEN_HEIGHT] = { 0 };
|
||||
SDL_Texture *scr_texts[SCREEN_WIDTH][SCREEN_HEIGHT] = { 0 };
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
void console_init(ctx_t *ctx)
|
||||
{
|
||||
/*
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0)
|
||||
{
|
||||
log("Couldn't initialize SDL: %s", SDL_GetError());
|
||||
logerr("Couldn't initialize SDL: %s", SDL_GetError());
|
||||
die(-1);
|
||||
}
|
||||
|
||||
SDL_Window *win = SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL_WINDOW_SHOWN);*/
|
||||
SDL_CreateWindowAndRenderer(SCREEN_WIDTH, SCREEN_HEIGHT, 0,
|
||||
&scr_win, &scr_rend);
|
||||
|
||||
if (scr_win == NULL || scr_rend == NULL)
|
||||
{
|
||||
logerr("Couldn't create SDL screen window/renderer: %s", SDL_GetError());
|
||||
die(-1);
|
||||
}
|
||||
|
||||
TTF_Init();
|
||||
|
||||
// XXX I have to find a solution about this...
|
||||
// including FreeMono.ttf directly in the project
|
||||
// would force it into GPL...
|
||||
scr_font = TTF_OpenFont
|
||||
("/usr/share/fonts/truetype/freefont/FreeMono.ttf", 15);
|
||||
|
||||
if (scr_font == NULL)
|
||||
{
|
||||
logerr("Couldn't open the FreeMono font\n");
|
||||
die(-1);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
void console_exit(ctx_t *ctx)
|
||||
{
|
||||
size_t x, y;
|
||||
|
||||
for (y = 0; y < SCREEN_HEIGHT; y++)
|
||||
for (x = 0; x < SCREEN_WIDTH; x++)
|
||||
if (scr_texts[x][y] != NULL)
|
||||
{
|
||||
if (scr_rects[x][y])
|
||||
free(scr_rects[x][y]);
|
||||
|
||||
SDL_DestroyTexture(scr_texts[x][y]);
|
||||
}
|
||||
|
||||
if (scr_win)
|
||||
SDL_DestroyWindow(scr_win);
|
||||
|
||||
TTF_Quit();
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
void console_render(ctx_t *ctx)
|
||||
{
|
||||
size_t x, y;
|
||||
|
||||
SDL_SetRenderDrawColor(scr_rend, 20, 20, 20, 0);
|
||||
SDL_RenderClear(scr_rend);
|
||||
|
||||
for (y = 0; y < SCREEN_HEIGHT; y++)
|
||||
for (x = 0; x < SCREEN_WIDTH; x++)
|
||||
if (scr_texts[x][y] != NULL)
|
||||
SDL_RenderCopy(scr_rend, scr_texts[x][y],
|
||||
NULL, scr_rects[x][y]);
|
||||
|
||||
SDL_RenderPresent(scr_rend);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
void console_putat(ctx_t *ctx, char ch, int x, int y)
|
||||
{
|
||||
char str[2] = { ch, 0 };
|
||||
SDL_Surface *surf;
|
||||
|
||||
// trace("putat: %c %d %d\n", ch, x, y);
|
||||
|
||||
// todo: to be made line-by-line
|
||||
|
||||
surf = TTF_RenderText_Solid(scr_font, str, scr_text_color);
|
||||
|
||||
if (scr_texts[x][y])
|
||||
{
|
||||
if (scr_rects[x][y])
|
||||
{
|
||||
free(scr_rects[x][y]);
|
||||
scr_rects[x][y] = NULL;
|
||||
}
|
||||
|
||||
SDL_DestroyTexture(scr_texts[x][y]);
|
||||
}
|
||||
|
||||
scr_texts[x][y] = SDL_CreateTextureFromSurface(scr_rend, surf);
|
||||
scr_rects[x][y] = malloc(sizeof(SDL_Rect));
|
||||
|
||||
if (scr_rects[x][y] == NULL)
|
||||
{
|
||||
logerr("console_putat: not enough memory\n");
|
||||
SDL_FreeSurface(surf);
|
||||
die(-1);
|
||||
}
|
||||
|
||||
scr_rects[x][y]->x = x * surf->w;
|
||||
scr_rects[x][y]->y = y * surf->h;
|
||||
scr_rects[x][y]->w = surf->w;
|
||||
scr_rects[x][y]->h = surf->h;
|
||||
|
||||
SDL_FreeSurface(surf);
|
||||
|
||||
console_render(ctx);
|
||||
}
|
||||
|
||||
#define CONSOLE_WIDTH 80
|
||||
#define CONSOLE_HEIGHT 25
|
||||
|
||||
int csn_x = 0;
|
||||
int csn_y = 0;
|
||||
|
||||
void console_putc(ctx_t *ctx, char ch)
|
||||
{
|
||||
if (ch < ' ' && ch != '\n')
|
||||
ch = 127;
|
||||
|
||||
if (ch == '\n')
|
||||
csn_x = CONSOLE_WIDTH;
|
||||
|
||||
else
|
||||
{
|
||||
console_putat(ctx, ch, csn_x, csn_y);
|
||||
csn_x++;
|
||||
}
|
||||
|
||||
if (csn_x == CONSOLE_WIDTH)
|
||||
{
|
||||
csn_x = 0;
|
||||
csn_y++;
|
||||
}
|
||||
|
||||
if (csn_y == CONSOLE_HEIGHT)
|
||||
csn_y = 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
|
@ -2,9 +2,13 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
#include <pc/arch.h>
|
||||
|
||||
//#include <SDL2/SDL.h>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
|
||||
void console_init(ctx_t *ctx);
|
||||
void console_exit(ctx_t *ctx);
|
||||
|
||||
void console_render(ctx_t *ctx);
|
||||
void console_putat(ctx_t *ctx, char ch, int x, int y);
|
||||
void console_putc(ctx_t *ctx, char ch);
|
||||
|
||||
|
@ -473,6 +473,8 @@ trap rim
|
||||
#
|
||||
iret
|
||||
|
||||
hlt
|
||||
|
||||
#---------------------------------------------------------------------------#
|
||||
# Misc. instructions #
|
||||
#---------------------------------------------------------------------------#
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include <in/instrs.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <cn/console.h>
|
||||
|
||||
#define _NEED_ARCH_I
|
||||
#include <in/arch_i.h>
|
||||
|
||||
@ -50,10 +52,10 @@ IMPL_OUT;
|
||||
|
||||
IMPL_START_1(prn)
|
||||
{
|
||||
if (p1->mlen > 4) {
|
||||
if (p1->mlen > 1) {
|
||||
trace("prn warning: large access size\n");
|
||||
}
|
||||
putchar((int)v1);
|
||||
console_putc(ctx, (char)v1);
|
||||
}
|
||||
IMPL_END;
|
||||
|
||||
|
@ -3,9 +3,11 @@
|
||||
|
||||
#include <in/instrs.h>
|
||||
|
||||
//
|
||||
// Supervisor only instructions
|
||||
//
|
||||
IMPL_START_0(hlt)
|
||||
{
|
||||
while (1) getchar();
|
||||
}
|
||||
IMPL_END;
|
||||
|
||||
IMPL_START_0(cli)
|
||||
{
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include <limits.h>
|
||||
|
||||
#undef dev_t
|
||||
#define packed __attribute__ ((__packed__))
|
||||
#define static_assert _Static_assert
|
||||
#define alignof _Alignof
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
#include <pc/dev.h>
|
||||
#include <cn/console.h>
|
||||
|
||||
void die(int code)
|
||||
{
|
||||
@ -12,6 +13,8 @@ void die(int code)
|
||||
if (main_ctx.mp)
|
||||
free(main_ctx.mp);
|
||||
|
||||
console_exit(&main_ctx);
|
||||
|
||||
//
|
||||
// Shut down devices
|
||||
//
|
||||
|
@ -34,7 +34,7 @@ ctx_t main_ctx;
|
||||
|
||||
void sigcommon(void)
|
||||
{
|
||||
die(-13);
|
||||
_except(&main_ctx, 1023, "SIGNAL'ed");
|
||||
}
|
||||
|
||||
void sigint(int _)
|
||||
@ -53,12 +53,14 @@ void main_loop(void)
|
||||
//
|
||||
// Start decoding
|
||||
//
|
||||
while (1) {
|
||||
while (!dying) {
|
||||
decode(&main_ctx);
|
||||
|
||||
if (main_ctx.step)
|
||||
getchar();
|
||||
}
|
||||
|
||||
die(0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
Loading…
Reference in New Issue
Block a user