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