This commit is contained in:
julianb0 2019-06-20 13:58:27 +02:00
parent d882e0362a
commit e9fa6438a4
No known key found for this signature in database
GPG Key ID: DDF8325C95299A62
3 changed files with 29 additions and 22 deletions

BIN
console_font.ttf Normal file

Binary file not shown.

View File

@ -5,10 +5,17 @@
; Main function
;
main:
mov rcx, 80
mov rdx, 25
.1:
mov rcx, 79
prn.rep '+'
prn 10
prn '!'
dec rdx
test rdx, rdx
j.nz .1
call showoff
hlt
ret

View File

@ -3,8 +3,11 @@
#include <cn/console.h>
#define SCREEN_WIDTH (1280)
#define SCREEN_HEIGHT (720)
#define CONSOLE_WIDTH 80
#define CONSOLE_HEIGHT 25
#define SCREEN_WIDTH (9 * CONSOLE_WIDTH)
#define SCREEN_HEIGHT (16 * CONSOLE_HEIGHT)
SDL_Window *scr_win = NULL;
SDL_Renderer *scr_rend = NULL;
@ -12,9 +15,9 @@ SDL_Renderer *scr_rend = NULL;
TTF_Font *scr_font = NULL;
SDL_Color scr_text_color = { 255, 255, 255, 0 };
char scr_lines[SCREEN_HEIGHT][SCREEN_WIDTH] = { 0 };
SDL_Texture *scr_texts[SCREEN_HEIGHT] = { 0 };
SDL_Rect *scr_rects[SCREEN_HEIGHT] = { 0 };
char scr_lines[CONSOLE_HEIGHT][CONSOLE_WIDTH+1] = { 0 };
SDL_Texture *scr_texts[CONSOLE_HEIGHT] = { 0 };
SDL_Rect *scr_rects[CONSOLE_HEIGHT] = { 0 };
//----------------------------------------------------------------------------//
@ -37,11 +40,8 @@ void console_init(ctx_t *ctx)
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", 20);
("console_font.ttf", 16);
if (scr_font == NULL)
{
@ -50,10 +50,10 @@ void console_init(ctx_t *ctx)
}
size_t y;
for (y = 0; y < SCREEN_HEIGHT; y++)
for (y = 0; y < CONSOLE_HEIGHT; y++)
{
memset(scr_lines[y], ' ', SCREEN_WIDTH - 1);
scr_lines[y][SCREEN_WIDTH - 1] = 0;
memset(scr_lines[y], ' ', CONSOLE_WIDTH);
scr_lines[y][CONSOLE_WIDTH] = 0;
}
}
@ -63,7 +63,7 @@ void console_exit(ctx_t *ctx)
{
size_t y;
for (y = 0; y < SCREEN_HEIGHT; y++)
for (y = 0; y < CONSOLE_HEIGHT; y++)
if (scr_texts[y] != NULL)
{
if (scr_rects[y])
@ -86,9 +86,11 @@ 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 < SCREEN_HEIGHT; y++)
for (y = 0; y < CONSOLE_HEIGHT; y++)
if (scr_texts[y] != NULL)
SDL_RenderCopy(scr_rend, scr_texts[y],
NULL, scr_rects[y]);
@ -102,9 +104,9 @@ void console_putat(ctx_t *ctx, char ch, int x, int y)
{
SDL_Surface *surf;
// trace("putat: %c %d %d\n", ch, x, y);
trace("putat: %c %d %d\n", ch, x, y);
if (y >= SCREEN_HEIGHT || x >= SCREEN_WIDTH)
if (y >= CONSOLE_HEIGHT || x >= CONSOLE_WIDTH)
{
logerr("console_putat: position out of range (%d,%d)", x, y);
return;
@ -136,7 +138,8 @@ void console_putat(ctx_t *ctx, char ch, int x, int y)
if (scr_texts[y] == NULL)
{
logerr("console_putat: couldn't create texture from surface\n");
logerr("console_putat: couldn't create texture from surface: "
"(%d,%d) '%c'\nError: '%s'\n", x, y, ch, SDL_GetError());
SDL_FreeSurface(surf);
die(-1);
}
@ -159,9 +162,6 @@ void console_putat(ctx_t *ctx, char ch, int x, int y)
console_render(ctx);
}
#define CONSOLE_WIDTH 80
#define CONSOLE_HEIGHT 25
int csn_x = 0;
int csn_y = 0;