mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
screen
This commit is contained in:
parent
b0bfce1ced
commit
bcb7bd59af
9
Makefile
9
Makefile
@ -21,14 +21,7 @@ clean:
|
||||
|
||||
test: vm/a.out
|
||||
@vm/k.exe vm/a.out vm/a.sym > vm/stdout.txt
|
||||
@rm -f vm/a.out
|
||||
@echo "output:"
|
||||
@echo ">>>>>>>>"
|
||||
@cat -v vm/stdout.txt
|
||||
@echo
|
||||
@echo "<<<<<<<<"
|
||||
@echo
|
||||
|
||||
@rm -f vm/a.out vm/a.sym
|
||||
wc: clean
|
||||
@cat $(shell find -name *.[kch]) $(shell find -name *.py) | wc -l
|
||||
|
||||
|
3
ka/ABI
3
ka/ABI
@ -6,7 +6,8 @@
|
||||
1. STACK
|
||||
|
||||
Stack grows downward. 'rbp' and 'rsp' are both used.
|
||||
There is no red zone. The lowest stack frame is marked by having 'rbp' = 0.
|
||||
The lowest stack frame is marked by having 'rbp' = 0.
|
||||
There is a 128-bytes red zone below 'rsp'.
|
||||
|
||||
A function's assembly code looks like this:
|
||||
label:
|
||||
|
@ -56,8 +56,6 @@ doprnt:
|
||||
j.z .modf_p
|
||||
cmp rax, 'x'
|
||||
j.z .modf_x
|
||||
cmp rax, 'u'
|
||||
j.z .modf_u
|
||||
cmp rax, 'd'
|
||||
j.z .modf_d
|
||||
cmp rax, 'o'
|
||||
@ -101,27 +99,18 @@ doprnt:
|
||||
|
||||
.modf_x:
|
||||
mov ax2, 16
|
||||
mov ax3, 1
|
||||
jmp .print_number
|
||||
|
||||
.modf_u:
|
||||
mov ax2, 10
|
||||
mov ax3, 1
|
||||
jmp .print_number
|
||||
|
||||
.modf_d:
|
||||
mov ax2, 10
|
||||
xor ax3, ax3
|
||||
jmp .print_number
|
||||
|
||||
.modf_o:
|
||||
mov ax2, 8
|
||||
mov ax3, 1
|
||||
jmp .print_number
|
||||
|
||||
.modf_b:
|
||||
mov ax2, 2
|
||||
mov ax3, 1
|
||||
jmp .print_number
|
||||
|
||||
.print_number:
|
||||
@ -129,10 +118,10 @@ doprnt:
|
||||
sub rsp, 80
|
||||
mov rdi, rsp
|
||||
|
||||
; assume modifier already set up ax2 and ax3
|
||||
; assume modifier already set up ax2
|
||||
mov ax0, rsp
|
||||
mov ax1, q[rsi + nx2 * 8]
|
||||
call _itoa
|
||||
call itoa
|
||||
inc nx2
|
||||
|
||||
.print_itoa_buf:
|
||||
|
@ -2,23 +2,9 @@
|
||||
; See the LICENSE file in the project root for more information.
|
||||
|
||||
;
|
||||
; wrappers
|
||||
; void itoa(char *buf, int num, int base)
|
||||
;
|
||||
|
||||
itoa:
|
||||
mov ax3, 0
|
||||
jmp _itoa
|
||||
|
||||
utoa:
|
||||
mov ax3, 1
|
||||
jmp _itoa
|
||||
|
||||
;
|
||||
; void _itoa(char *buf, int num, int base, int unsi)
|
||||
;
|
||||
; Behaves as itoa if unsi == 0, as utoa otherwise
|
||||
;
|
||||
_itoa:
|
||||
mov rax, ax0
|
||||
xor lx0, lx0
|
||||
|
||||
@ -36,9 +22,6 @@ _itoa:
|
||||
|
||||
; deal with base 10 signedness
|
||||
|
||||
test ax3, ax3 ; unsigned mode
|
||||
j.nz .conv
|
||||
|
||||
cmp ax2, 10 ; base 10
|
||||
j.nz .conv
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
; buf and src must NOT overlap
|
||||
;
|
||||
strrev:
|
||||
test b[ax1], b[ax1]
|
||||
cmp b[ax1], 0
|
||||
mov.z b[ax0], 0
|
||||
ret.z
|
||||
|
||||
@ -40,7 +40,7 @@ strrev:
|
||||
; Inverses str
|
||||
;
|
||||
strrev2:
|
||||
test b[ax0], b[ax0]
|
||||
cmp b[ax0], 0
|
||||
ret.z
|
||||
|
||||
mov ax1, ax0
|
||||
|
@ -5,6 +5,9 @@
|
||||
; Main function
|
||||
;
|
||||
main:
|
||||
mov rcx, 80
|
||||
prn.rep '+'
|
||||
prn 10
|
||||
call showoff
|
||||
hlt
|
||||
ret
|
||||
|
179
vm/a.sym
179
vm/a.sym
@ -1,94 +1,91 @@
|
||||
_start 1048576
|
||||
_start.1 1048610
|
||||
itoa 1048626
|
||||
utoa 1048652
|
||||
_itoa 1048678
|
||||
_itoa.conv 1048840
|
||||
_itoa.nondec 1048928
|
||||
_itoa.next 1048942
|
||||
_itoa.fini 1048976
|
||||
_itoa.bad 1049048
|
||||
_itoa.zero 1049086
|
||||
doprnt 1049120
|
||||
doprnt.main_loop 1049250
|
||||
doprnt.print_regular 1049286
|
||||
doprnt.check_modf 1049344
|
||||
doprnt.modf_s 1049640
|
||||
doprnt.print_string 1049678
|
||||
doprnt.modf_c 1049736
|
||||
doprnt.modf_p 1049778
|
||||
doprnt.modf_x 1049830
|
||||
doprnt.modf_u 1049870
|
||||
doprnt.modf_d 1049910
|
||||
doprnt.modf_o 1049944
|
||||
doprnt.modf_b 1049984
|
||||
doprnt.print_number 1050024
|
||||
doprnt.print_itoa_buf 1050084
|
||||
doprnt.modf_percent 1050156
|
||||
doprnt.bad_modifier 1050194
|
||||
doprnt.nullstring 1050258
|
||||
doprnt.epilogue 1050426
|
||||
doprnt.doput 1050512
|
||||
putc 1050568
|
||||
printf 1050586
|
||||
print 1050644
|
||||
print.1 1050658
|
||||
print.2 1050702
|
||||
print_n 1050706
|
||||
print_n.1 1050714
|
||||
strnlen 1050742
|
||||
strlen 1050784
|
||||
strrev 1050810
|
||||
strrev.2 1050878
|
||||
strrev2 1050938
|
||||
strrev2.2 1050992
|
||||
strrev2.3 1051044
|
||||
strcpy 1051048
|
||||
strncpy 1051074
|
||||
strnzcpy 1051098
|
||||
strnzcpy.1 1051136
|
||||
strcmp 1051154
|
||||
strncmp 1051180
|
||||
strchrnul 1051242
|
||||
strchr 1051276
|
||||
RFS.GetMaxIdx 1051336
|
||||
RFS.GetUsage 1051360
|
||||
RFS.GetCurIdx 1051384
|
||||
RFS.GetLeastAvail 1051408
|
||||
RFS.IsFrameActive 1051432
|
||||
RFS.ActivateFrame 1051456
|
||||
RFS.DeactivateFrame 1051480
|
||||
RFS.CopyFrame 1051504
|
||||
RFS.MoveFrame 1051528
|
||||
RFS.SwitchFrame 1051552
|
||||
RFS.LoadArgs 1051576
|
||||
RFS.LoadReg 1051600
|
||||
RFS.StoreReg 1051624
|
||||
IDT.AddHandler 1051648
|
||||
IDT.DelHandler 1051672
|
||||
IDT.QueryHandler 1051696
|
||||
IDT.DoneHandling 1051716
|
||||
MEM.GetMemOff 1051740
|
||||
MEM.GetMemSize 1051764
|
||||
cpudev_test 1051788
|
||||
trap0_test 1052008
|
||||
showoff 1052080
|
||||
printf_test 1052180
|
||||
strchr_test 1052332
|
||||
bswap_test 1052396
|
||||
ramdev_test 1052466
|
||||
movzx_test 1052502
|
||||
itoa_test 1052600
|
||||
devtest 1052764
|
||||
str_test 1052848
|
||||
main 1053184
|
||||
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
|
||||
itoa.conv 1048768
|
||||
itoa.nondec 1048856
|
||||
itoa.next 1048870
|
||||
itoa.fini 1048904
|
||||
itoa.bad 1048976
|
||||
itoa.zero 1049014
|
||||
doprnt 1049048
|
||||
doprnt.main_loop 1049178
|
||||
doprnt.print_regular 1049214
|
||||
doprnt.check_modf 1049272
|
||||
doprnt.modf_s 1049542
|
||||
doprnt.print_string 1049580
|
||||
doprnt.modf_c 1049638
|
||||
doprnt.modf_p 1049680
|
||||
doprnt.modf_x 1049732
|
||||
doprnt.modf_d 1049758
|
||||
doprnt.modf_o 1049784
|
||||
doprnt.modf_b 1049810
|
||||
doprnt.print_number 1049836
|
||||
doprnt.print_itoa_buf 1049896
|
||||
doprnt.modf_percent 1049968
|
||||
doprnt.bad_modifier 1050006
|
||||
doprnt.nullstring 1050070
|
||||
doprnt.epilogue 1050238
|
||||
doprnt.doput 1050324
|
||||
putc 1050380
|
||||
printf 1050398
|
||||
print 1050456
|
||||
print.1 1050470
|
||||
print.2 1050514
|
||||
print_n 1050518
|
||||
print_n.1 1050526
|
||||
strnlen 1050554
|
||||
strlen 1050596
|
||||
strrev 1050622
|
||||
strrev.2 1050696
|
||||
strrev2 1050756
|
||||
strrev2.2 1050816
|
||||
strrev2.3 1050868
|
||||
strcpy 1050872
|
||||
strncpy 1050898
|
||||
strnzcpy 1050922
|
||||
strnzcpy.1 1050960
|
||||
strcmp 1050978
|
||||
strncmp 1051004
|
||||
strchrnul 1051066
|
||||
strchr 1051100
|
||||
RFS.GetMaxIdx 1051160
|
||||
RFS.GetUsage 1051184
|
||||
RFS.GetCurIdx 1051208
|
||||
RFS.GetLeastAvail 1051232
|
||||
RFS.IsFrameActive 1051256
|
||||
RFS.ActivateFrame 1051280
|
||||
RFS.DeactivateFrame 1051304
|
||||
RFS.CopyFrame 1051328
|
||||
RFS.MoveFrame 1051352
|
||||
RFS.SwitchFrame 1051376
|
||||
RFS.LoadArgs 1051400
|
||||
RFS.LoadReg 1051424
|
||||
RFS.StoreReg 1051448
|
||||
IDT.AddHandler 1051472
|
||||
IDT.DelHandler 1051496
|
||||
IDT.QueryHandler 1051520
|
||||
IDT.DoneHandling 1051540
|
||||
MEM.GetMemOff 1051564
|
||||
MEM.GetMemSize 1051588
|
||||
cpudev_test 1051612
|
||||
trap0_test 1051832
|
||||
showoff 1051904
|
||||
printf_test 1052004
|
||||
strchr_test 1052156
|
||||
bswap_test 1052220
|
||||
ramdev_test 1052290
|
||||
movzx_test 1052326
|
||||
itoa_test 1052424
|
||||
devtest 1052588
|
||||
str_test 1052672
|
||||
main 1053008
|
||||
errno 1053072
|
||||
trap0_test.msg 1053080
|
||||
printf_test.fmt 1053103
|
||||
printf_test.str 1053151
|
||||
strchr_test.str 1053159
|
||||
itoa_test.buf 1053175
|
||||
devtest.buf 1053215
|
||||
str_test.msg 1053255
|
||||
str_test.buf1 1053271
|
||||
str_test.buf2 1053311
|
||||
|
@ -12,8 +12,9 @@ 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 };
|
||||
char scr_lines[SCREEN_HEIGHT][SCREEN_WIDTH] = { 0 };
|
||||
SDL_Texture *scr_texts[SCREEN_HEIGHT] = { 0 };
|
||||
SDL_Rect *scr_rects[SCREEN_HEIGHT] = { 0 };
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
@ -40,30 +41,36 @@ void console_init(ctx_t *ctx)
|
||||
// including FreeMono.ttf directly in the project
|
||||
// would force it into GPL...
|
||||
scr_font = TTF_OpenFont
|
||||
("/usr/share/fonts/truetype/freefont/FreeMono.ttf", 15);
|
||||
("/usr/share/fonts/truetype/freefont/FreeMono.ttf", 20);
|
||||
|
||||
if (scr_font == NULL)
|
||||
{
|
||||
logerr("Couldn't open the FreeMono font\n");
|
||||
die(-1);
|
||||
}
|
||||
|
||||
size_t y;
|
||||
for (y = 0; y < SCREEN_HEIGHT; y++)
|
||||
{
|
||||
memset(scr_lines[y], ' ', SCREEN_WIDTH - 1);
|
||||
scr_lines[y][SCREEN_WIDTH - 1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
void console_exit(ctx_t *ctx)
|
||||
{
|
||||
size_t x, y;
|
||||
size_t 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]);
|
||||
if (scr_texts[y] != NULL)
|
||||
{
|
||||
if (scr_rects[y])
|
||||
free(scr_rects[y]);
|
||||
|
||||
SDL_DestroyTexture(scr_texts[x][y]);
|
||||
}
|
||||
SDL_DestroyTexture(scr_texts[y]);
|
||||
}
|
||||
|
||||
if (scr_win)
|
||||
SDL_DestroyWindow(scr_win);
|
||||
@ -76,16 +83,15 @@ void console_exit(ctx_t *ctx)
|
||||
|
||||
void console_render(ctx_t *ctx)
|
||||
{
|
||||
size_t x, y;
|
||||
size_t 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]);
|
||||
if (scr_texts[y] != NULL)
|
||||
SDL_RenderCopy(scr_rend, scr_texts[y],
|
||||
NULL, scr_rects[y]);
|
||||
|
||||
SDL_RenderPresent(scr_rend);
|
||||
}
|
||||
@ -94,40 +100,45 @@ void console_render(ctx_t *ctx)
|
||||
|
||||
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 (y >= SCREEN_HEIGHT || x >= SCREEN_WIDTH)
|
||||
{
|
||||
if (scr_rects[x][y])
|
||||
{
|
||||
free(scr_rects[x][y]);
|
||||
scr_rects[x][y] = NULL;
|
||||
}
|
||||
|
||||
SDL_DestroyTexture(scr_texts[x][y]);
|
||||
logerr("console_putat: position out of range (%d,%d)", x, y);
|
||||
return;
|
||||
}
|
||||
|
||||
scr_texts[x][y] = SDL_CreateTextureFromSurface(scr_rend, surf);
|
||||
scr_rects[x][y] = malloc(sizeof(SDL_Rect));
|
||||
scr_lines[y][x] = ch;
|
||||
|
||||
if (scr_rects[x][y] == NULL)
|
||||
surf = TTF_RenderText_Solid(scr_font, scr_lines[y], scr_text_color);
|
||||
|
||||
if (scr_texts[y])
|
||||
{
|
||||
if (scr_rects[y])
|
||||
{
|
||||
free(scr_rects[y]);
|
||||
scr_rects[y] = NULL;
|
||||
}
|
||||
|
||||
SDL_DestroyTexture(scr_texts[y]);
|
||||
}
|
||||
|
||||
scr_texts[y] = SDL_CreateTextureFromSurface(scr_rend, surf);
|
||||
scr_rects[y] = malloc(sizeof(SDL_Rect));
|
||||
|
||||
if (scr_rects[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;
|
||||
scr_rects[y]->x = 0;
|
||||
scr_rects[y]->y = y * surf->h;
|
||||
scr_rects[y]->w = surf->w;
|
||||
scr_rects[y]->h = surf->h;
|
||||
|
||||
SDL_FreeSurface(surf);
|
||||
|
||||
|
@ -1,11 +1,23 @@
|
||||
// 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 <unistd.h>
|
||||
#include <in/instrs.h>
|
||||
#include <cn/console.h>
|
||||
|
||||
IMPL_START_0(hlt)
|
||||
{
|
||||
while (1) getchar();
|
||||
CHK_SUPERV();
|
||||
SDL_Event evt;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (SDL_WaitEvent(&evt) == 1)
|
||||
{
|
||||
if (evt.type == SDL_QUIT)
|
||||
die(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
IMPL_END;
|
||||
|
||||
|
12
vm/pc/main.c
12
vm/pc/main.c
@ -48,14 +48,26 @@ void sigsegv(int _)
|
||||
sigcommon();
|
||||
}
|
||||
|
||||
//
|
||||
// Main loop
|
||||
//
|
||||
void main_loop(void)
|
||||
{
|
||||
SDL_Event evt;
|
||||
|
||||
//
|
||||
// Start decoding
|
||||
//
|
||||
while (!dying) {
|
||||
// Execute one instruction
|
||||
decode(&main_ctx);
|
||||
|
||||
if (__builtin_expect(SDL_PollEvent(&evt) == 1, 0))
|
||||
{
|
||||
if (evt.type == SDL_QUIT)
|
||||
die(0);
|
||||
}
|
||||
|
||||
if (main_ctx.step)
|
||||
getchar();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user