More graphic and window functions and wrappers.

This commit is contained in:
Ivan Baravy 2020-02-07 05:26:27 +03:00
parent 0d5b1b5433
commit 4cf0d46fe6
4 changed files with 251 additions and 44 deletions

133
kofu.c
View File

@ -260,6 +260,20 @@ void kofu_display_number(int argc, const char **argv) {
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_get_font_smoothing(int argc, const char **argv) {
(void)argc;
(void)argv;
const char *names[] = {"off", "anti-aliasing", "subpixel"};
int type = umka_sys_get_smoothing();
printf("font smoothing: %i - %s\n", type, names[type]);
}
void kofu_set_font_smoothing(int argc, const char **argv) {
(void)argc;
int type = strtol(argv[1], NULL, 0);
umka_sys_set_smoothing(type);
}
void kofu_button(int argc, const char **argv) {
(void)argc;
size_t x = strtoul(argv[1], NULL, 0);
@ -330,17 +344,76 @@ void kofu_draw_line(int argc, const char **argv) {
umka_sys_draw_line(x, xend, y, yend, color, invert);
}
void kofu_set_window_caption(int argc, const char **argv) {
(void)argc;
const char *caption = argv[1];
int encoding = strtoul(argv[2], NULL, 0);
umka_sys_set_window_caption(caption, encoding);
}
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");
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 has_caption = strtoul(argv[6], NULL, 0);
int client_relative = strtoul(argv[7], NULL, 0);
int fill_workarea = strtoul(argv[8], NULL, 0);
int gradient_fill = strtoul(argv[9], NULL, 0);
int movable = strtoul(argv[10], NULL, 0);
int style = strtoul(argv[11], NULL, 0);
const char *caption = argv[12];
umka_sys_draw_window(x, xsize, y, ysize, color, has_caption, client_relative, fill_workarea, gradient_fill, movable, style, caption);
}
void kofu_window_redraw(int argc, const char **argv) {
(void)argc;
int begin_end = strtoul(argv[1], NULL, 0);
umka_sys_window_redraw(begin_end);
}
void kofu_move_window(int argc, const char **argv) {
(void)argc;
size_t x = strtoul(argv[1], NULL, 0);
size_t y = strtoul(argv[2], NULL, 0);
ssize_t xsize = strtol(argv[3], NULL, 0);
ssize_t ysize = strtol(argv[4], NULL, 0);
umka_sys_move_window(x, y, xsize, ysize);
}
void kofu_blit_bitmap(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 dstx = strtoul(argv[2], NULL, 0);
size_t dsty = strtoul(argv[3], NULL, 0);
size_t dstxsize = strtoul(argv[4], NULL, 0);
size_t dstysize = strtoul(argv[5], NULL, 0);
size_t srcx = strtoul(argv[6], NULL, 0);
size_t srcy = strtoul(argv[7], NULL, 0);
size_t srcxsize = strtoul(argv[8], NULL, 0);
size_t srcysize = strtoul(argv[9], NULL, 0);
int operation = strtoul(argv[10], NULL, 0);
int background = strtoul(argv[11], NULL, 0);
int transparent = strtoul(argv[12], NULL, 0);
int client_relative = strtoul(argv[13], NULL, 0);
int row_length = strtoul(argv[14], NULL, 0);
uint32_t params[] = {dstx, dsty, dstxsize, dstysize, srcx, srcy, srcxsize, srcysize, (uintptr_t)image, row_length};
umka_sys_blit_bitmap(operation, background, transparent, client_relative, params);
free(image);
}
void kofu_scrot(int argc, const char **argv) {
(void)argc;
(void)argv;
// printf("%"PRIx32 " %"PRIx32 "\n", kos_lfb_base[0], kos_lfb_base[1]);
FILE *img = fopen("umka.rgba", "w");
FILE *img = fopen(argv[1], "w");
// const char *header = "P6\n1024 768\n255\n";
// fwrite(header, strlen(header), 1, img);
uint32_t *lfb = kos_lfb_base;
@ -580,28 +653,34 @@ typedef struct {
} func_table_t;
func_table_t funcs[] = {
{ "disk_add", kofu_disk_add },
{ "disk_del", kofu_disk_del },
{ "ls70", kofu_ls70 },
{ "ls80", kofu_ls80 },
{ "stat70", kofu_stat70 },
{ "stat80", kofu_stat80 },
{ "read70", kofu_read70 },
{ "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 },
};
{ "disk_add", kofu_disk_add },
{ "disk_del", kofu_disk_del },
{ "ls70", kofu_ls70 },
{ "ls80", kofu_ls80 },
{ "stat70", kofu_stat70 },
{ "stat80", kofu_stat80 },
{ "read70", kofu_read70 },
{ "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 },
{ "window_redraw", kofu_window_redraw },
{ "draw_rect", kofu_draw_rect },
{ "draw_line", kofu_draw_line },
{ "display_number", kofu_display_number },
{ "get_font_smoothing", kofu_get_font_smoothing },
{ "set_font_smoothing", kofu_set_font_smoothing },
{ "put_image_palette", kofu_put_image_palette },
{ "move_window", kofu_move_window },
{ "set_window_caption", kofu_set_window_caption },
{ "blit_bitmap", kofu_blit_bitmap },
{ "scrot", kofu_scrot },
{ NULL, NULL },
};
void usage() {
printf("usage: kofu [test_file.t]\n");

View File

@ -57,11 +57,12 @@ include 'blkdev/disk.inc'
include 'blkdev/disk_cache.inc'
include 'fs/fs_lfn.inc'
include 'crc.inc'
; video
include 'core/dll.inc'
include 'core/syscall.inc'
include 'video/framebuffer.inc'
include 'video/vesa20.inc'
include 'video/vga.inc'
include 'video/blitter.inc'
include 'video/cursors.inc'
include 'unpacker.inc'
include 'gui/window.inc'
@ -71,7 +72,9 @@ include 'gui/skincode.inc'
restore load_file
include 'gui/draw.inc'
include 'gui/font.inc'
include 'core/syscall.inc'
include 'gui/event.inc'
include 'gui/mouse.inc'
include 'hid/keyboard.inc'
include 'sha3.asm'
@ -174,6 +177,11 @@ endp
public kos_init
proc kos_init c uses ebx esi edi ebp
mov edi, endofcode
mov ecx, uglobals_size
xor eax, eax
rep stosb
MEMORY_BYTES = 128 SHL 20
DISPLAY_WIDTH = 400
DISPLAY_HEIGHT = 300
@ -241,8 +249,6 @@ proc kos_init c uses ebx esi edi ebp
ret
endp
window_title db 'hello',0
public kos_disk_add
proc kos_disk_add c uses ebx esi edi ebp, _file_name, _disk_name
extrn cio_disk_init
@ -452,11 +458,52 @@ align 4
.ret:
ret
proc my_putpixel
DEBUGF 1,"hello from my putpixel!\n"
pid_to_slot:
;Input:
; eax - pid of process
;Output:
; eax - slot of process or 0 if process don't exists
;Search process by PID.
push ebx
push ecx
mov ebx, [TASK_COUNT]
shl ebx, 5
mov ecx, 2*32
.loop:
;ecx=offset of current process info entry
;ebx=maximum permitted offset
cmp byte [CURRENT_TASK+ecx+0xa], 9
jz .endloop ;skip empty slots
cmp [CURRENT_TASK+ecx+0x4], eax;check PID
jz .pid_found
.endloop:
add ecx, 32
cmp ecx, ebx
jle .loop
pop ecx
pop ebx
xor eax, eax
ret
.pid_found:
shr ecx, 5
mov eax, ecx ;convert offset to index of slot
pop ecx
pop ebx
ret
proc disable_irq _irq
ret
endp
proc enable_irq _irq
ret
endp
kb_write_wait_ack:
sys_msg_board_str:
protect_from_terminate:
unprotect_from_terminate:
@ -485,8 +532,6 @@ sys_clock:
delay_hs_unprotected:
undefined_syscall:
sys_cpuusage:
sys_waitforevent:
sys_getevent:
sys_redrawstat:
syscall_getscreensize:
sys_background:
@ -497,7 +542,6 @@ paleholder:
sys_midi:
sys_setup:
sys_settime:
sys_wait_event_timeout:
syscall_cdaudio:
syscall_putarea_backgr:
sys_getsetup:
@ -521,8 +565,6 @@ sys_resize_app_memory:
sys_process_def:
f68:
sys_debug_services:
sys_sendwindowmsg:
blit_32:
sys_network:
sys_socket:
sys_protocols:
@ -565,7 +607,6 @@ disk_name db 'hd0',0
skin file 'skin.skn'
skin_size = $ - skin
include 'hid/mousedrv.inc'
include 'gui/mousepointer.inc'
screen_workarea RECT
display_width_standard dd 0
@ -573,9 +614,9 @@ display_height_standard dd 0
do_not_touch_winmap db 0
window_minimize db 0
sound_flag db 0
fl_moving db 0
rb 3
timer_ticks dd 0
;hotkey_buffer rd 120*2 ; buffer for 120 hotkeys
PID_lock_input dd 0x0
;section '.bss' writeable align 16
;IncludeUGlobals

View File

@ -87,6 +87,15 @@ static inline void umka_sys_button(size_t x, size_t xsize,
: "memory");
}
static inline void umka_sys_window_redraw(int begin_end) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(12),
"b"(begin_end)
: "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) {
@ -136,6 +145,27 @@ static inline void umka_sys_display_number(int is_pointer, int base,
: "memory");
}
static inline int umka_sys_get_smoothing() {
int type;
__asm__ __inline__ __volatile__ (
"call i40"
: "=a" (type)
: "a"(48),
"b"(9)
: "memory");
return type;
}
static inline void umka_sys_set_smoothing(int type) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(48),
"b"(10),
"c"(type)
: "memory");
}
static inline void umka_sys_put_image_palette(void *image,
size_t xsize, size_t ysize,
size_t x, size_t y,
@ -157,6 +187,19 @@ static inline void umka_sys_put_image_palette(void *image,
: "memory");
}
static inline void umka_sys_move_window(size_t x, size_t y,
ssize_t xsize, ssize_t ysize) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(67),
"b"(x),
"c"(y),
"d"(xsize),
"S"(ysize)
: "memory");
}
static inline void umka_sys_lfn(void *f7080sXarg, f7080ret_t *r,
f70or80_t f70or80) {
__asm__ __inline__ __volatile__ (
@ -168,4 +211,29 @@ static inline void umka_sys_lfn(void *f7080sXarg, f7080ret_t *r,
: "memory");
}
static inline void umka_sys_set_window_caption(const char *caption,
int encoding) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(71),
"b"(encoding ? 2 : 1),
"c"(caption),
"d"(encoding)
: "memory");
}
static inline void umka_sys_blit_bitmap(int operation, int background,
int transparent, int client_relative,
void *params) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(73),
"b"((client_relative << 29) + (transparent << 5) + (background << 4)
+ operation),
"c"(params)
: "memory");
}
#endif

View File

@ -1,4 +1,5 @@
draw_window
window_redraw 1
draw_window 0 300 0 200 0x000088 1 1 1 0 1 4 hello
set_pixel 0 0 0x0000ff
set_pixel 1 1 0xff0000
set_pixel 2 2 0x00ff00
@ -9,4 +10,22 @@ 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
blit_bitmap chess_image.rgba 20 35 8 8 0 0 8 8 0 0 0 1 32
window_redraw 2
set_window_caption hi_there 0
move_window 220 35 150 200
get_font_smoothing
set_font_smoothing 0
get_font_smoothing
window_redraw 1
draw_window 0 300 0 200 0x000088 1 1 1 0 1 4 hello
set_pixel 0 0 0x0000ff
set_pixel 1 1 0xff0000
set_pixel 2 2 0x00ff00
window_redraw 2
set_window_caption hi_2there 0
scrot umka.rgba