Add wrappers to graphic syscalls.

This commit is contained in:
Ivan Baravy 2020-02-06 06:19:20 +03:00
parent 750efc930a
commit b23e29d6d1
8 changed files with 393 additions and 143 deletions

1
.gitignore vendored
View File

@ -22,5 +22,6 @@ tags
coverage.*
covpreproc
*.rgba
*.rgb
*.png
*.skn

141
kofu.c
View File

@ -31,6 +31,7 @@
#include <assert.h>
#include <time.h>
#include "kolibri.h"
#include "syscalls.h"
#include "trace.h"
#define PATH_MAX 4096
@ -212,6 +213,129 @@ void kofu_pwd(int argc, const char **argv) {
printf("%s%s%s\n", quote, cur_dir, quote);
}
void kofu_set_pixel(int argc, const char **argv) {
size_t x = strtoul(argv[1], NULL, 0);
size_t y = strtoul(argv[2], NULL, 0);
uint32_t color = strtoul(argv[3], NULL, 16);
int invert = (argc == 5) && !strcmp(argv[4], "-i");
umka_sys_set_pixel(x, y, color, invert);
}
void kofu_write_text(int argc, const char **argv) {
(void)argc;
size_t x = strtoul(argv[1], NULL, 0);
size_t y = strtoul(argv[2], NULL, 0);
uint32_t color = strtoul(argv[3], NULL, 16);
const char *string = argv[4];
int asciiz = strtoul(argv[5], NULL, 0);
int fill_background = strtoul(argv[6], NULL, 0);
int font_and_encoding = strtoul(argv[7], NULL, 0);
int draw_to_buffer = strtoul(argv[8], NULL, 0);
int scale_factor = strtoul(argv[9], NULL, 0);
int length = strtoul(argv[10], NULL, 0);
int background_color_or_buffer = strtoul(argv[11], NULL, 0);
umka_sys_write_text(x, y, color, asciiz, fill_background, font_and_encoding, draw_to_buffer, scale_factor, string, length, background_color_or_buffer);
}
void kofu_display_number(int argc, const char **argv) {
(void)argc;
int is_pointer = strtoul(argv[1], NULL, 0);
int base = strtoul(argv[2], NULL, 0);
if (base == 10) base = 0;
else if (base == 16) base = 1;
else if (base == 2) base = 2;
else base = 0;
size_t digits_to_display = strtoul(argv[3], NULL, 0);
int is_qword = strtoul(argv[4], NULL, 0);
int show_leading_zeros = strtoul(argv[5], NULL, 0);
uintptr_t number_or_pointer = strtoul(argv[6], NULL, 0);
size_t x = strtoul(argv[7], NULL, 0);
size_t y = strtoul(argv[8], NULL, 0);
uint32_t color = strtoul(argv[9], NULL, 16);
int fill_background = strtoul(argv[10], NULL, 0);
int font = strtoul(argv[11], NULL, 0);
int draw_to_buffer = strtoul(argv[12], NULL, 0);
int scale_factor = strtoul(argv[13], NULL, 0);
uintptr_t background_color_or_buffer = strtoul(argv[14], NULL, 16);
umka_sys_display_number(is_pointer, base, digits_to_display, is_qword, show_leading_zeros, number_or_pointer, x, y, color, fill_background, font, draw_to_buffer, scale_factor, background_color_or_buffer);
}
void kofu_button(int argc, const char **argv) {
(void)argc;
size_t x = strtoul(argv[1], NULL, 0);
size_t xsize = strtoul(argv[2], NULL, 0);
size_t y = strtoul(argv[3], NULL, 0);
size_t ysize = strtoul(argv[4], NULL, 0);
uint32_t button_id = strtoul(argv[5], NULL, 0);
uint32_t color = strtoul(argv[6], NULL, 16);
int draw_button = strtoul(argv[7], NULL, 0);
int draw_frame = strtoul(argv[8], NULL, 0);
umka_sys_button(x, xsize, y, ysize, button_id, draw_button, draw_frame, color);
}
void kofu_put_image(int argc, const char **argv) {
(void)argc;
FILE *f = fopen(argv[1], "r");
fseek(f, 0, SEEK_END);
size_t fsize = ftell(f);
rewind(f);
uint8_t *image = (uint8_t*)malloc(fsize);
fread(image, fsize, 1, f);
fclose(f);
size_t xsize = strtoul(argv[2], NULL, 0);
size_t ysize = strtoul(argv[3], NULL, 0);
size_t x = strtoul(argv[4], NULL, 0);
size_t y = strtoul(argv[5], NULL, 0);
umka_sys_put_image(image, xsize, ysize, x, y);
free(image);
}
void kofu_put_image_palette(int argc, const char **argv) {
(void)argc;
FILE *f = fopen(argv[1], "r");
fseek(f, 0, SEEK_END);
size_t fsize = ftell(f);
rewind(f);
uint8_t *image = (uint8_t*)malloc(fsize);
fread(image, fsize, 1, f);
fclose(f);
size_t xsize = strtoul(argv[2], NULL, 0);
size_t ysize = strtoul(argv[3], NULL, 0);
size_t x = strtoul(argv[4], NULL, 0);
size_t y = strtoul(argv[5], NULL, 0);
size_t bpp = strtoul(argv[6], NULL, 0);
void *palette = NULL;
size_t row_offset = strtoul(argv[7], NULL, 0);
umka_sys_put_image_palette(image, xsize, ysize, x, y, bpp, palette, row_offset);
free(image);
}
void kofu_draw_rect(int argc, const char **argv) {
size_t x = strtoul(argv[1], NULL, 0);
size_t xsize = strtoul(argv[2], NULL, 0);
size_t y = strtoul(argv[3], NULL, 0);
size_t ysize = strtoul(argv[4], NULL, 0);
uint32_t color = strtoul(argv[5], NULL, 16);
int gradient = (argc == 7) && !strcmp(argv[6], "-g");
umka_sys_draw_rect(x, xsize, y, ysize, color, gradient);
}
void kofu_draw_line(int argc, const char **argv) {
size_t x = strtoul(argv[1], NULL, 0);
size_t xend = strtoul(argv[2], NULL, 0);
size_t y = strtoul(argv[3], NULL, 0);
size_t yend = strtoul(argv[4], NULL, 0);
uint32_t color = strtoul(argv[5], NULL, 16);
int invert = (argc == 7) && !strcmp(argv[6], "-i");
umka_sys_draw_line(x, xend, y, yend, color, invert);
}
void kofu_draw_window(int argc, const char **argv) {
(void)argc;
(void)argv;
umka_sys_draw_window(0, 300, 0, 200, 0x00000088, 1, 1, 1, 0, 1, 4, "hello");
}
void kofu_scrot(int argc, const char **argv) {
(void)argc;
(void)argv;
@ -247,7 +371,7 @@ void ls_range(f7080s1arg_t *fX0, f70or80_t f70or80) {
if (fX0->size > requested) {
fX0->size = requested;
}
kos_lfn(fX0, &r, f70or80);
umka_sys_lfn(fX0, &r, f70or80);
fX0->offset += fX0->size;
print_f70_status(&r, 1);
f7080s1info_t *dir = fX0->buf;
@ -275,7 +399,7 @@ void ls_all(f7080s1arg_t *fX0, f70or80_t f70or80) {
f7080ret_t r;
size_t bdfe_len = (fX0->encoding == CP866) ? BDFE_LEN_CP866 : BDFE_LEN_UNICODE;
while (true) {
kos_lfn(fX0, &r, f70or80);
umka_sys_lfn(fX0, &r, f70or80);
print_f70_status(&r, 1);
assert((r.status == ERROR_SUCCESS && r.count == fX0->size)
|| (r.status == ERROR_END_OF_FILE && r.count < fX0->size));
@ -349,7 +473,7 @@ void kofu_stat(int argc, const char **argv, f70or80_t f70or80) {
fX0.u.f80.path_encoding = DEFAULT_PATH_ENCODING;
fX0.u.f80.path = argv[1];
}
kos_lfn(&fX0, &r, f70or80);
umka_sys_lfn(&fX0, &r, f70or80);
print_f70_status(&r, 0);
if (r.status != ERROR_SUCCESS)
return;
@ -428,7 +552,7 @@ void kofu_read(int argc, const char **argv, f70or80_t f70or80) {
}
fX0.buf = (uint8_t*)malloc(fX0.count);
kos_lfn(&fX0, &r, f70or80);
umka_sys_lfn(&fX0, &r, f70or80);
print_f70_status(&r, 1);
if (r.status == ERROR_SUCCESS || r.status == ERROR_END_OF_FILE) {
@ -466,6 +590,15 @@ func_table_t funcs[] = {
{ "read80", kofu_read80 },
{ "pwd", kofu_pwd },
{ "cd", kofu_cd },
{ "draw_window", kofu_draw_window },
{ "set_pixel", kofu_set_pixel },
{ "write_text", kofu_write_text },
{ "put_image", kofu_put_image },
{ "button", kofu_button },
{ "draw_rect", kofu_draw_rect },
{ "draw_line", kofu_draw_line },
{ "display_number", kofu_display_number },
{ "put_image_palette", kofu_put_image_palette },
{ "scrot", kofu_scrot },
{ NULL, NULL },
};

View File

@ -32,6 +32,7 @@
#include <unistd.h>
#include <fcntl.h>
#include "kolibri.h"
#include "syscalls.h"
#define DIRENTS_TO_READ 100
@ -65,7 +66,7 @@ static int kofuse_getattr(const char *path, struct stat *stbuf,
bdfe_t file;
f7080s5arg_t fX0 = {.sf = 5, .flags = 0, .buf = &file, .u = {.f80 = {.path_encoding = UTF8, .path = path}}};
f7080ret_t r;
kos_lfn(&fX0, &r, F80);
umka_sys_lfn(&fX0, &r, F80);
bdfe_to_stat(&file, stbuf);
// res = -ENOENT;
@ -82,7 +83,7 @@ static int kofuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
f7080s1info_t *dir = (f7080s1info_t*)malloc(sizeof(f7080s1info_t) + BDFE_LEN_UNICODE * DIRENTS_TO_READ);
f7080s1arg_t fX0 = {.sf = 1, .offset = 0, .encoding = UTF8, .size = DIRENTS_TO_READ, .buf = dir, .u = {.f80 = {.path_encoding = UTF8, .path = path}}};
f7080ret_t r;
kos_lfn(&fX0, &r, F80);
umka_sys_lfn(&fX0, &r, F80);
bdfe_t *bdfe = dir->bdfes;
for (size_t i = 0; i < dir->cnt; i++) {
filler(buf, bdfe->name, NULL, 0, 0);
@ -109,7 +110,7 @@ static int kofuse_read(const char *path, char *buf, size_t size, off_t offset,
f7080s0arg_t fX0 = {.sf = 0, .offset = offset, .count = size, .buf = buf, .u = {.f80 = {.path_encoding = UTF8, .path = path}}};
f7080ret_t r;
kos_lfn(&fX0, &r, F80);
umka_sys_lfn(&fX0, &r, F80);
return size;
}

View File

@ -12,6 +12,7 @@ _free fix free
sys_msg_board equ _sys_msg_board
cli equ nop
iretd equ retd
lang fix en
preboot_blogesc = 0 ; start immediately after bootlog
@ -20,7 +21,9 @@ VESA_1_2_VIDEO = 0 ; enable vesa 1.2 bank switch functions
purge mov,add,sub
purge mov,add,sub
section '.text' executable align 16
section '.text' executable align 32
public i40
coverage_begin:
public coverage_begin
@ -68,6 +71,7 @@ include 'gui/skincode.inc'
restore load_file
include 'gui/draw.inc'
include 'gui/font.inc'
include 'core/syscall.inc'
include 'sha3.asm'
@ -253,82 +257,6 @@ proc kos_init c uses ebx esi edi ebp
mov [skin_data], 0
call load_default_skin
mov eax, 0
mov ebx, (0 SHL 16)+300
mov ecx, (0 SHL 16)+200
mov edx, 0x34000088
mov esi, 0x00008800
mov edi, window_title
call syscall_draw_window
mov eax, 1
mov ebx, 0
mov ecx, 0
mov edx, 0x000000ff
call syscall_setpixel
mov eax, 1
mov ebx, 1
mov ecx, 1
mov edx, 0x00ff0000
call syscall_setpixel
mov eax, 1
mov ebx, 2
mov ecx, 2
mov edx, 0x0000ff00
call syscall_setpixel
mov eax, 38
mov ebx, (10 SHL 16) + 510
mov ecx, (10 SHL 16) + 510
mov edx, 0x00ff0000
call syscall_drawline
mov eax, 13
mov ebx, (60 SHL 16) + 20
mov ecx, (30 SHL 16) + 20
mov edx, 0x0000ff00
call syscall_drawrect
mov eax, 7
mov ebx, chess_image
mov ecx, (8 SHL 16) + 8
mov edx, (5 SHL 16) + 15
call syscall_putimage
mov eax, 65
mov ebx, chess_image
mov ecx, (12 SHL 16) + 12
mov edx, (5 SHL 16) + 30
mov esi, 9
mov edi, 0
mov ebp, 0
call sys_putimage_palette
mov eax, 4
mov ebx, (10 SHL 16) + 70
mov ecx, 0xffff00
mov edx, window_title
mov esi, 5
mov edi, 0
call syscall_writetext
mov eax, 8
mov ebx, (55 SHL 16) + 40
mov ecx, (5 SHL 16) + 20
mov edx, 0x20c0ffee
mov esi, 0x00dddddd
call syscall_button
mov eax, 47
mov ebx, 0x80040000
mov ecx, 1234
mov edx, (5 SHL 16) + 45
mov esi, 0x50ffff00
mov edi, 0x000000ff
call display_number
ret
endp
@ -408,28 +336,6 @@ proc kos_disk_del c uses ebx esi edi ebp, _name
endp
public kos_lfn
proc kos_lfn c uses ebx edx esi edi ebp, _f7080arg, _f7080ret, _f70or80
push ebx
mov ebx, [_f7080arg]
pushad ; file_system_lfn writes here
cmp [_f70or80], 80
jz .f80
.f70:
call file_system_lfn
jmp .done
.f80:
call fileSystemUnicode
.done:
popad
mov ecx, [_f7080ret]
mov [ecx+0], eax ; status
mov [ecx+4], ebx ; count
pop ebx
ret
endp
proc vdisk_close stdcall uses ebx esi edi ebp, _userdata
extrn cio_disk_free
ccall cio_disk_free, [_userdata]
@ -593,6 +499,55 @@ wakeup_osloop:
read_process_memory:
.forced:
ret
sys_getkey:
sys_clock:
delay_hs_unprotected:
undefined_syscall:
sys_cpuusage:
sys_waitforevent:
sys_getevent:
sys_redrawstat:
syscall_getscreensize:
sys_background:
sys_cachetodiskette:
sys_getbutton:
sys_system:
paleholder:
sys_midi:
sys_setup:
sys_settime:
sys_wait_event_timeout:
syscall_cdaudio:
syscall_putarea_backgr:
sys_getsetup:
sys_date:
syscall_getpixel_WinMap:
syscall_getarea:
readmousepos:
sys_getbackground:
set_app_param:
sys_outport:
syscall_reserveportarea:
sys_apm:
syscall_threads:
sys_clipboard:
sound_interface:
sys_pcibios:
sys_IPC:
sys_gs:
pci_api:
sys_resize_app_memory:
sys_process_def:
f68:
sys_debug_services:
sys_sendwindowmsg:
blit_32:
sys_network:
sys_socket:
sys_protocols:
sys_posix:
sys_end:
ret
proc __load_file _filename
push ebx ecx edx esi edi
@ -638,31 +593,9 @@ do_not_touch_winmap db 0
window_minimize db 0
sound_flag db 0
chess_image db \
0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, \
0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, \
0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, \
0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, \
0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, \
0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, \
0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, \
0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, \
0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, \
0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, \
0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, \
0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, \
0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, \
0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, \
0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, \
0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff
fl_moving db 0
rb 3
;section '.bss' writeable align 16
;IncludeUGlobals
;section '.bss' writeable align 16
;IncludeUGlobals
; crap

View File

@ -129,7 +129,7 @@ typedef struct {
uint32_t kos_time_to_epoch(uint32_t *time);
void kos_init(void);
void kos_lfn(void *f7080sXarg, f7080ret_t *r, f70or80_t f70or80);
void i40(void);
void *kos_disk_add(const char *file_name, const char *disk_name);
int kos_disk_del(const char *name);
uint32_t kos_getcwd(char *buf, uint32_t len);

View File

@ -47,8 +47,8 @@ trace_lwp.o: trace_lwp.c trace_lwp.h kolibri.h
cio.o: cio.c
$(CC) $(CFLAGS) $(CFLAGS_32) -c $<
kofu.o: kofu.c kolibri.h trace.h
$(CC) $(CFLAGS) $(CFLAGS_32) -c $< -std=c99 -D_POSIX_C_SOURCE
kofu.o: kofu.c kolibri.h trace.h syscalls.h
$(CC) $(CFLAGS) $(CFLAGS_32) -c $< -std=c99 -D_POSIX_C_SOURCE -masm=intel
kofuse.o: kofuse.c kolibri.h
$(CC) $(CFLAGS) $(CFLAGS_32) `pkg-config fuse3 --cflags` -c $< -std=gnu99

171
syscalls.h Normal file
View File

@ -0,0 +1,171 @@
#ifndef SYSCALLS_H_INCLUDED
#define SYSCALLS_H_INCLUDED
#include <inttypes.h>
#include "kolibri.h"
static inline void umka_sys_draw_window(size_t x, size_t xsize,
size_t y, size_t ysize,
uint32_t color, int has_caption,
int client_relative,
int fill_workarea, int gradient_fill,
int movable, uint32_t style,
const char *caption) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(0),
"b"((x << 16) + xsize),
"c"((y << 16) + ysize),
"d"((gradient_fill << 31) + (!fill_workarea << 30)
+ (client_relative << 29) + (has_caption << 28) + (style << 24)
+ color),
"S"(!movable << 24),
"D"(caption)
: "memory");
}
static inline void umka_sys_set_pixel(size_t x, size_t y, uint32_t color,
int invert) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(1),
"b"(x),
"c"(y),
"d"((invert << 24) + color)
: "memory");
}
static inline void umka_sys_write_text(size_t x, size_t y,
uint32_t color,
int asciiz, int fill_background,
int font_and_encoding,
int draw_to_buffer,
int scale_factor,
const char *string, size_t length,
uintptr_t background_color_or_buffer) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(4),
"b"((x << 16) + y),
"c"((asciiz << 31) + (fill_background << 30)
+ (font_and_encoding << 28) + (draw_to_buffer << 27)
+ (scale_factor << 24) + color),
"d"(string),
"S"(length),
"D"(background_color_or_buffer)
: "memory");
}
static inline void umka_sys_put_image(void *image, size_t xsize, size_t ysize,
size_t x, size_t y) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(7),
"b"(image),
"c"((xsize << 16) + ysize),
"d"((x << 16) + y)
: "memory");
}
static inline void umka_sys_button(size_t x, size_t xsize,
size_t y, size_t ysize,
size_t button_id,
int draw_button, int draw_frame,
uint32_t color) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(8),
"b"((x << 16) + xsize),
"c"((y << 16) + ysize),
"d"((!draw_button << 30) + (!draw_frame << 29) + button_id),
"S"(color)
: "memory");
}
static inline void umka_sys_draw_rect(size_t x, size_t xsize,
size_t y, size_t ysize,
uint32_t color, int gradient) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(13),
"b"((x << 16) + xsize),
"c"((y << 16) + ysize),
"d"((gradient << 31) + color)
: "memory");
}
static inline void umka_sys_draw_line(size_t x, size_t xend,
size_t y, size_t yend,
uint32_t color, int invert) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(38),
"b"((x << 16) + xend),
"c"((y << 16) + yend),
"d"((invert << 24) + color)
: "memory");
}
static inline void umka_sys_display_number(int is_pointer, int base,
int digits_to_display, int is_qword,
int show_leading_zeros,
int number_or_pointer,
size_t x, size_t y,
uint32_t color, int fill_background,
int font, int draw_to_buffer,
int scale_factor,
uintptr_t background_color_or_buffer) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(47),
"b"(is_pointer + (base << 8) + (digits_to_display << 16)
+ (is_qword << 30) + (show_leading_zeros << 31)),
"c"(number_or_pointer),
"d"((x << 16) + y),
"S"(color + (fill_background << 30) + (font << 28)
+ (draw_to_buffer << 27) + (scale_factor << 24)),
"D"(background_color_or_buffer)
: "memory");
}
static inline void umka_sys_put_image_palette(void *image,
size_t xsize, size_t ysize,
size_t x, size_t y,
size_t bpp, void *palette,
size_t row_offset) {
__asm__ __inline__ __volatile__ (
"push ebp;"
"mov ebp, %[row_offset];"
"call i40;"
"pop ebp"
:
: "a"(65),
"b"(image),
"c"((xsize << 16) + ysize),
"d"((x << 16) + y),
"S"(bpp),
"D"(palette),
[row_offset] "rm"(row_offset)
: "memory");
}
static inline void umka_sys_lfn(void *f7080sXarg, f7080ret_t *r,
f70or80_t f70or80) {
__asm__ __inline__ __volatile__ (
"call i40"
: "=a" (r->status),
"=b" (r->count)
: "a"(f70or80),
"b"(f7080sXarg)
: "memory");
}
#endif

View File

@ -1 +1,12 @@
draw_window
set_pixel 0 0 0x0000ff
set_pixel 1 1 0xff0000
set_pixel 2 2 0x00ff00
draw_line 10 510 10 510 0xff0000
draw_rect 60 20 30 20 0x00ff00
put_image chess_image.rgb 8 8 5 15
put_image_palette chess_image.rgb 12 12 5 30 9 0
write_text 10 70 0xffff00 hello 0 0 0 0 0 5 0
button 55 40 5 20 0xc0ffee 0xffffff 1 0
display_number 0 10 4 0 0 1234 5 45 0xffff00 1 1 0 0 0x0000ff
scrot