14 Commits

Author SHA1 Message Date
b2e4b02806 libshell: update shell_ping()
All checks were successful
Build system / Check kernel codestyle (pull_request) Successful in 23s
Build system / Build (pull_request) Successful in 19m18s
make it faster
2026-03-08 18:40:07 +05:00
18f50b5786 libc.obj: return _ksys_exit to exit 2026-03-08 18:36:42 +05:00
84fb020568 libc.obj & libshell: formatting fix & update comments & add checks that shell really initialized 2026-03-07 15:00:04 +05:00
6956ce8b8c libc.obj: add shell console output 2026-03-07 13:58:11 +05:00
Igor Shutrov
668fd4deeb ftpd: add ip to first message
All checks were successful
Build system / Check kernel codestyle (pull_request) Successful in 21s
Build system / Build (pull_request) Successful in 16m30s
2026-02-17 22:08:04 +05:00
dd9a7b92d8 libc.obj: Fixed build skip with TCC build enabled
All checks were successful
Build system / Check kernel codestyle (pull_request) Successful in 1m19s
Build system / Build (pull_request) Successful in 16m42s
Signed-off-by: Max Logaev <maxlogaev@proton.me>
2026-01-28 17:22:54 +03:00
Igor Shutrov
1173ca7b26 Cedit: Improve search panel (#313)
Улучшения для Cedit в Панели поиска:
- Добавлен поиск следующего фрагмента текста по нажатию Enter
- Добавлен обратный переход по полям ввода в Панели поиска по Shift-Tab

Co-authored-by: Igor Shutrov <igor@shutrov.ru>
Reviewed-on: #313
Reviewed-by: Burer <burer@noreply.localhost>
Co-authored-by: Igor Shutrov <kolibridev@inbox.ru>
Co-committed-by: Igor Shutrov <kolibridev@inbox.ru>
2026-01-18 16:28:46 +00:00
ccd0c183ec mtdbg: Backtrace implemented (#315)
Added support for backtrace/stacktrace output.
This is useful for high-level languages ​​like C and Oberon07.
If a debug file is provided, searches for the nearest debug symbol.

Reviewed-on: #315
Reviewed-by: Mikhail Frolov <mixa.frolov2003@gmail.com>
Reviewed-by: Burer <burer@noreply.localhost>
2026-01-18 13:08:02 +00:00
f065cc6e69 mtdbg: Fixed magic cmd flags
Signed-off-by: Max Logaev <maxlogaev@proton.me>
2026-01-11 13:35:58 +00:00
f1b99bad84 libc.obj: Added missing strpbrk() to EXPORTS (#310)
Reviewed-on: #310
Reviewed-by: Max Logaev <maxlogaev@proton.me>
Co-authored-by: Егор <velikiydolbayeb@gmail.com>
Co-committed-by: Егор <velikiydolbayeb@gmail.com>
2026-01-10 23:27:51 +00:00
igorsh
c580d4ac5b ftpd: Add XPWD and XCWD commands (#309)
Добавлены команды XPWD и XCWD, дублирующие PWD и CWD

Co-authored-by: Igor Shutrov <igor@shutrov.ru>
Co-authored-by: Burer <burer@kolibrios.org>
Reviewed-on: #309
Reviewed-by: Burer <burer@noreply.localhost>
Co-authored-by: igorsh <kolibridev@inbox.ru>
Co-committed-by: igorsh <kolibridev@inbox.ru>
2026-01-08 17:03:23 +00:00
Igor Shutrov
17c33521c3 ftpd: Fix typo 2026-01-07 19:41:28 +00:00
Igor Shutrov
f6395c9501 ftpd: Fix typo 2026-01-07 19:41:28 +00:00
Igor Shutrov
000288ce8b ftpd: Fix RETR for small and empty files
All checks were successful
Build system / Check kernel codestyle (pull_request) Successful in 1m5s
Build system / Build (pull_request) Successful in 15m59s
2026-01-06 18:20:39 +00:00
37 changed files with 622 additions and 986 deletions

View File

@@ -401,9 +401,8 @@ tup.append_table(img_files, {
{"@MENU", VAR_PROGS .. "/system/menu/trunk/menu"},
{"@NOTIFY", VAR_PROGS .. "/system/notify3/notify"},
{"@OPEN", VAR_PROGS .. "/system/open/open"},
{"@RESHARE", VAR_PROGS .. "/system/reshare/reshare"},
{"@SS", VAR_PROGS .. "/system/scrsaver/scrsaver"},
{"@TASKBAR", VAR_PROGS .. "/system/taskbar/trunk/TASKBAR"},
{"@SS", VAR_PROGS .. "/system/scrsaver/scrsaver"},
{"@VOLUME", VAR_PROGS .. "/media/volume/volume"},
{"HACONFIG", VAR_PROGS .. "/other/ha/HACONFIG"},
{"ACLOCK", VAR_PROGS .. "/demos/aclock/aclock"},
@@ -662,6 +661,7 @@ end -- tup.getconfig('NO_JWASM') ~= 'full'
-- Programs that require C-- to compile.
if tup.getconfig('NO_CMM') ~= 'full' then
tup.append_table(img_files, {
{"@RESHARE", VAR_PROGS .. "/cmm/misc/reshare.com"},
{"APP_PLUS", VAR_PROGS .. "/cmm/app_plus/app_plus.com"},
{"EASYSHOT", VAR_PROGS .. "/cmm/misc/easyshot.com"},
{"MOUSECFG", VAR_PROGS .. "/cmm/mousecfg/mousecfg.com"},
@@ -722,6 +722,7 @@ tup.append_table(img_files, {
{"SHELL", VAR_PROGS .. "/system/shell/shell"},
{"GAMES/DINO", VAR_PROGS .. "/games/dino/dino"},
{"GAMES/FLPYBIRD", VAR_PROGS .. "/games/flpybird/flpybird"},
{"LIB/LIBC.OBJ", VAR_PROGS .. "/develop/ktcc/trunk/libc.obj/source/libc.obj"},
})
tup.append_table(extra_files, {
{"kolibrios/utils/thashview", VAR_PROGS .. "/other/TinyHashView/thashview"},
@@ -745,7 +746,6 @@ if tup.getconfig('NO_GCC') ~= 'full' then
tup.append_table(img_files, {
{"GAMES/REVERSI", VAR_PROGS .. "/games/reversi/reversi"},
{"LIB/BASE64.OBJ", VAR_PROGS .. "/develop/libraries/base64/base64.obj"},
{"LIB/LIBC.OBJ", VAR_PROGS .. "/develop/ktcc/trunk/libc.obj/source/libc.obj"},
{"LIB/ICONV.OBJ", VAR_PROGS .. "/develop/libraries/iconv/iconv.obj"},
-- {"LIB/MTAR.OBJ", VAR_PROGS .. "/develop/libraries/microtar/mtar.obj"},
})

View File

@@ -47,3 +47,9 @@
перемещение по тексту:
(ctrl+)Home, (ctrl+)End, (ctrl+)PageUp, (ctrl+)PageDown
ctrl+Left, ctrl+Right
перемещение в панели поиска:
Tab к следующему полю ввода
Shift-Tab к предыдущему полю ввода
Enter поиск следующего вхождения

View File

@@ -28,7 +28,7 @@ IMPORT
RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar;
CONST
HEADER = "CEdit (30-apr-2025)";
HEADER = "CEdit (11-jan-2026)";
ShellFilter = "";
EditFilter = "sh|inc|txt|asm|ob07|c|cpp|h|pas|pp|lua|ini|json";
@@ -1750,7 +1750,15 @@ BEGIN
ELSE
IF EditBox_Focus(FindEdit) THEN
IF keyCode = 15 THEN (* Tab *)
SetFocus(ReplaceEdit, TRUE)
IF shift THEN
SetFocus(GotoEdit, TRUE)
ELSE
SetFocus(ReplaceEdit, TRUE)
END
ELSIF keyCode = 28 THEN (* Enter *)
IF searchOpened & (searchText # "") THEN
notFound := ~T.findNext(text, BKW.value)
END
ELSE
EB.key(FindEdit, key);
EditBox_Get(FindEdit, new_searchText);
@@ -1761,14 +1769,26 @@ BEGIN
END
ELSIF EditBox_Focus(ReplaceEdit) THEN
IF keyCode = 15 THEN (* Tab *)
SetFocus(GotoEdit, TRUE)
IF shift THEN
SetFocus(FindEdit, TRUE)
ELSE
SetFocus(GotoEdit, TRUE)
END
ELSIF keyCode = 28 THEN (* Enter *)
IF searchOpened & (searchText # "") THEN
notFound := ~T.findNext(text, BKW.value)
END
ELSE
EB.key(ReplaceEdit, key);
EditBox_Get(ReplaceEdit, replaceText)
END
ELSIF EditBox_Focus(GotoEdit) THEN
IF keyCode = 15 THEN (* Tab *)
SetFocus(FindEdit, TRUE)
IF shift THEN
SetFocus(ReplaceEdit, TRUE)
ELSE
SetFocus(FindEdit, TRUE)
END
ELSE
IF (key DIV 256) MOD 256 = 13 THEN
goto

View File

@@ -1,6 +1,8 @@
CC = kos32-tcc
AR = ar
CFLAGS = -c -I../../libc.obj/include
CFLAGS = -c -I$(LIBC_INCLUDE)
LIBC_INCLUDE = ../../libc.obj/include
LIB = libshell.a
@@ -14,7 +16,8 @@ OBJS = \
shell_init.o \
shell_gets.o \
shell_printf.o \
shell_putc.o
shell_putc.o \
shell_write_string.o
$(LIB): $(OBJS)
$(AR) -crs $@ $(OBJS)
@@ -23,4 +26,16 @@ $(LIB): $(OBJS)
$(CC) $(CFLAGS) -o $@ $<
clean:
rm -rf $(OBJS) $(LIB)
rm -rf $(OBJS) $(LIB)
shell_cls.o: shell_cls.c $(LIBC_INCLUDE)/shell_api.h $(LIBC_INCLUDE)/sys/ksys.h
shell_get_pid.o: shell_get_pid.c $(LIBC_INCLUDE)/shell_api.h $(LIBC_INCLUDE)/string.h
shell_getc.o: shell_getc.c $(LIBC_INCLUDE)/shell_api.h
shell_gets.o: shell_gets.c $(LIBC_INCLUDE)/shell_api.h $(LIBC_INCLUDE)/string.h
shell_init.o: shell_init.c $(LIBC_INCLUDE)/shell_api.h $(LIBC_INCLUDE)/sys/ksys.h $(LIBC_INCLUDE)/string.h $(LIBC_INCLUDE)/stdio.h $(LIBC_INCLUDE)/stdlib.h
shell_ping.o: shell_ping.c $(LIBC_INCLUDE)/shell_api.h $(LIBC_INCLUDE)/sys/ksys.h
shell_printf.o: shell_printf.c $(LIBC_INCLUDE)/shell_api.h $(LIBC_INCLUDE)/stdio.h
shell_putc.o: shell_putc.c $(LIBC_INCLUDE)/shell_api.h
shell_puts.o: shell_puts.c $(LIBC_INCLUDE)/shell_api.h $(LIBC_INCLUDE)/string.h
shell_write_string.o: shell_write_string.c $(LIBC_INCLUDE)/shell_api.h $(LIBC_INCLUDE)/string.h

View File

@@ -3,6 +3,9 @@
void shell_cls()
{
__shell_init();
*__shell_shm = SHELL_CLS;
if(__shell_is_init == __SHELL_INIT_OK)
{
*__shell_shm = SHELL_CLS;
__SHELL_WAIT();
}
}

View File

@@ -3,7 +3,7 @@
void shell_exit()
{
if(__shell_is_init){
if (__shell_is_init == __SHELL_INIT_OK) {
*__shell_shm = SHELL_EXIT;
__SHELL_WAIT();
_ksys_shm_close(__shell_shm_name);

View File

@@ -4,9 +4,14 @@
unsigned shell_get_pid()
{
unsigned pid;
__shell_init();
*__shell_shm = SHELL_PID;
__SHELL_WAIT();
memcpy(&pid, __shell_shm+1, sizeof(unsigned));
if (__shell_is_init == __SHELL_INIT_OK)
{
*__shell_shm = SHELL_PID;
__SHELL_WAIT();
memcpy(&pid, __shell_shm + 1, sizeof(unsigned));
}
return pid;
}

View File

@@ -1,9 +1,16 @@
#include "shell_api.h"
#include <shell_api.h>
char shell_getc()
{
__shell_init();
*__shell_shm = SHELL_GETC;
__SHELL_WAIT();
return *(__shell_shm+1);
if (__shell_is_init == __SHELL_INIT_OK) {
*__shell_shm = SHELL_GETC;
__SHELL_WAIT();
return *(__shell_shm + 1);
}
else {
return 0;
}
}

View File

@@ -4,7 +4,11 @@
void shell_gets(char *str, int n)
{
__shell_init();
*__shell_shm = SHELL_GETS;
if (__shell_is_init == __SHELL_INIT_OK) {
*__shell_shm = SHELL_GETS;
__SHELL_WAIT();
strncpy(str, __shell_shm+1, n);
}
}

View File

@@ -5,40 +5,57 @@
#include <shell_api.h>
char app_name[13];
char __shell_shm_name[32];
char*__shell_shm=NULL;
int __shell_is_init=0;
char __shell_shm_name[32];
char *__shell_shm = NULL;
enum __SHELL_INIT_STATE __shell_is_init = __SHELL_NOT_LOADED;
int __shell_shm_init()
{
__shell_is_init=1;
ksys_thread_t *proc_info = (ksys_thread_t*)malloc(sizeof(ksys_thread_t));
if(proc_info == NULL){
return -1;
}
__shell_is_init = __SHELL_LOADING;
ksys_thread_t proc_info;
unsigned PID;
_ksys_thread_info(proc_info, -1);
PID = proc_info->pid;
strncpy(app_name, proc_info->name, 12);
free(proc_info);
_ksys_thread_info(&proc_info, -1);
PID = proc_info.pid;
strncpy(app_name, (&proc_info)->name, 12);
itoa(PID, __shell_shm_name);
strcat(__shell_shm_name, "-SHELL");
return _ksys_shm_open(__shell_shm_name, KSYS_SHM_OPEN_ALWAYS | KSYS_SHM_WRITE, SHELL_SHM_MAX, &__shell_shm);
return _ksys_shm_open(__shell_shm_name, KSYS_SHM_OPEN_ALWAYS | KSYS_SHM_WRITE, SHELL_SHM_MAX, &__shell_shm);
}
void __shell_init()
{
if(!__shell_is_init){
if(__shell_shm_init()){
debug_printf("%s: shell problems detected!\n", app_name);
_ksys_exit();
switch (__shell_is_init) {
case __SHELL_NOT_LOADED:
if (__shell_shm_init()) {
debug_printf("%s: shell problems detected!\n", app_name);
goto __shell_init_err;
}
if(!shell_ping()){
debug_printf("%s: no shell found!\n", app_name);
_ksys_exit();
if (!shell_ping()) {
goto __shell_init_err;
}
__shell_is_init = __SHELL_INIT_OK; // The shell is being pinged, so it's working.
break;
case __SHELL_LOADING:
while (__shell_is_init == __SHELL_LOADING) {
_ksys_thread_yield();
}
case __SHELL_INIT_OK:
if (!shell_ping()) {
goto __shell_init_err;
}
break;
default:
break;
}
return;
__shell_init_err:
__shell_is_init = __SHELL_INIT_FAILED;
shell_exit();
return;
}

View File

@@ -1,13 +1,24 @@
#include <shell_api.h>
#include <sys/ksys.h>
#include <sys/ksys.h>
#define SHELL_PING_TIMEOUT 10 // 0.1 sec
#define SHELL_PING_MIN_DELAY 1
int shell_ping()
{
__shell_init();
*__shell_shm = SHELL_PING;
_ksys_delay(10);
if(*__shell_shm==SHELL_OK){
return 1;
_ksys_thread_yield(); // hope shell is fast enough
size_t i = 0;
while (*__shell_shm != SHELL_OK){
if (i > (SHELL_PING_TIMEOUT / SHELL_PING_MIN_DELAY)) {
return 0;
}
i++;
_ksys_delay(SHELL_PING_MIN_DELAY);
}
return 0;
}
return 1;
}

View File

@@ -1,12 +1,12 @@
#include <shell_api.h>
#include <stdio.h>
void shell_printf(const char *format,...)
void shell_printf(const char *format, ...)
{
va_list ap;
va_start (ap, format);
*__shell_shm=SHELL_PUTS;
vsnprintf(__shell_shm+1, SHELL_SHM_MAX, format, ap);
va_start(ap, format);
vsnprintf(__shell_shm + 1, SHELL_SHM_MAX, format, ap);
*__shell_shm = SHELL_PUTS;
va_end(ap);
__SHELL_WAIT();
}

View File

@@ -3,7 +3,11 @@
void shell_putc(char c)
{
__shell_init();
*__shell_shm = SHELL_PUTC;
*(__shell_shm+1) = c;
__SHELL_WAIT();
if (__shell_is_init == __SHELL_INIT_OK)
{
*(__shell_shm + 1) = c;
*__shell_shm = SHELL_PUTC;
__SHELL_WAIT();
}
}

View File

@@ -3,8 +3,5 @@
void shell_puts(const char *str)
{
__shell_init();
*__shell_shm = SHELL_PUTS;
strcpy(__shell_shm+1, str);
__SHELL_WAIT();
shell_write_string(str, strlen(str));
}

View File

@@ -0,0 +1,22 @@
#include <shell_api.h>
#include <string.h>
void shell_write_string(const char *s, size_t len)
{
__shell_init();
if (__shell_is_init == __SHELL_INIT_OK)
{
if (len > SHELL_SHM_MAX - 1)
{
shell_write_string(s, SHELL_SHM_MAX - 1); // Outputs as much as it can.
shell_write_string(s + (SHELL_SHM_MAX - 1), len - (SHELL_SHM_MAX - 1)); // Outputs the rest.
}
else
{
memset(__shell_shm, 0, SHELL_SHM_MAX); // without int shell show \t, \n, lose chars and other trash
memcpy(__shell_shm + 1, s, len);
*__shell_shm = SHELL_PUTS;
__SHELL_WAIT();
}
}
}

View File

@@ -0,0 +1,8 @@
.vscode/*
.tup/*
*.o
*.kex
*.obj
*.a
*.tmp

View File

@@ -3,6 +3,12 @@
#include <sys/ksys.h>
#ifdef _BUILD_LIBC
#define __EXTERN
#else
#define __EXTERN extern
#endif
#define SHELL_OK 0
#define SHELL_EXIT 1
#define SHELL_PUTC 2
@@ -15,25 +21,35 @@
#define SHELL_SHM_MAX 1024 * 16
extern char __shell_shm_name[32];
extern char* __shell_shm;
extern int __shell_is_init;
extern void __shell_init();
enum __SHELL_INIT_STATE {
__SHELL_NOT_LOADED = 0, // not try init shell before
__SHELL_LOADING = 1, // in progress
__SHELL_INIT_OK = 2, // ok
__SHELL_INIT_FAILED = 3 // fail init shell
};
#define __SHELL_WAIT() \
while (*__shell_shm) \
_ksys_delay(5)
__EXTERN char __shell_shm_name[32];
__EXTERN char* __shell_shm;
__EXTERN enum __SHELL_INIT_STATE __shell_is_init;
__EXTERN void __shell_init();
extern int shell_ping();
extern unsigned shell_get_pid();
extern void shell_exit();
#define __SHELL_WAIT() \
while (*__shell_shm) { \
_ksys_thread_yield(); \
}
extern char shell_getc();
extern void shell_gets(char* str, int n);
__EXTERN int shell_ping();
__EXTERN unsigned shell_get_pid();
__EXTERN void shell_exit();
extern void shell_putc(char c);
extern void shell_puts(const char* str);
extern void shell_printf(const char* format, ...);
__EXTERN char shell_getc();
__EXTERN void shell_gets(char* str, int n);
extern void shell_cls();
__EXTERN void shell_putc(char c);
__EXTERN void shell_puts(const char* str);
__EXTERN void shell_printf(const char* format, ...);
__EXTERN void shell_write_string(const char* s, size_t len);
__EXTERN void shell_cls();
#endif

View File

@@ -13,6 +13,7 @@
#include "sys/seekdir.c"
#include "sys/socket.c"
#include "sys/telldir.c"
#include "sys/conio.c"
#include "stdio/clearerr.c"
#include "stdio/conio.c"
@@ -120,6 +121,18 @@
#include "misc/basename.c"
#include "misc/dirname.c"
#include "../../lib/libshell/shell_cls.c"
#include "../../lib/libshell/shell_exit.c"
#include "../../lib/libshell/shell_get_pid.c"
#include "../../lib/libshell/shell_getc.c"
#include "../../lib/libshell/shell_gets.c"
#include "../../lib/libshell/shell_init.c"
#include "../../lib/libshell/shell_ping.c"
#include "../../lib/libshell/shell_printf.c"
#include "../../lib/libshell/shell_putc.c"
#include "../../lib/libshell/shell_puts.c"
#include "../../lib/libshell/shell_write_string.c"
ksys_dll_t EXPORTS[] = {
{ "clearerr", &clearerr },
{ "debug_printf", &debug_printf },
@@ -204,6 +217,7 @@ ksys_dll_t EXPORTS[] = {
{ "strstr", &strstr },
{ "strtok", &strtok },
{ "strxfrm", &strxfrm },
{ "strpbrk", &strpbrk },
{ "__errno", &__errno },
{ "closedir", &closedir },
{ "opendir", &opendir },

View File

@@ -73,3 +73,5 @@ int con_init(void)
return con_init_opt(-1, -1, -1, -1, __con_caption);
}

View File

@@ -1,6 +1,6 @@
#include <stdio.h>
#include <errno.h>
#include "conio.h"
#include "../sys/_conio.h"
#include "sys/ksys.h"
size_t fread(void *restrict ptr, size_t size, size_t nmemb, FILE *restrict stream) {
@@ -19,8 +19,7 @@ size_t fread(void *restrict ptr, size_t size, size_t nmemb, FILE *restrict strea
}
if(stream==stdin){
con_init();
con_gets((char*)ptr, bytes_count+1);
console_gets((char*)ptr, bytes_count+1);
return nmemb;
}

View File

@@ -1,45 +1,46 @@
#include <stdio.h>
#include "conio.h"
#include "../sys/_conio.h"
#include <sys/ksys.h>
#include <errno.h>
#include <shell_api.h>
size_t fwrite(const void *restrict ptr, size_t size, size_t nmemb, FILE *restrict stream) {
unsigned bytes_written = 0;
unsigned bytes_count = size * nmemb;
if(!stream){
errno = EBADF;
return 0;
}
if(size<=0 || nmemb<=0){
errno = EINVAL;
stream->error=errno;
return 0;
}
if(stream==stdout){
con_init();
con_write_string((char*)ptr, bytes_count);
return nmemb;
}
if(stream==stderr){
for (size_t i = 0; i < bytes_count; i++) {
char c = *(char*)(ptr+i);
_ksys_debug_putc(c);
}
return nmemb;
}
if(stream->mode != _FILEMODE_R){
unsigned status = _ksys_file_write_file(stream->name, stream->position, bytes_count, ptr, &bytes_written);
if (status != KSYS_FS_ERR_SUCCESS) {
errno = EIO;
stream->error = errno;
return 0;
}
stream->position+=bytes_written;
}
return bytes_written/size;
size_t fwrite(const void* restrict ptr, size_t size, size_t nmemb, FILE* restrict stream)
{
unsigned bytes_written = 0;
unsigned bytes_count = size * nmemb;
if (!stream) {
errno = EBADF;
return 0;
}
if (size <= 0 || nmemb <= 0) {
errno = EINVAL;
stream->error = errno;
return 0;
}
if (stream == stdout) {
console_write((char*)ptr, size);
return nmemb;
}
if (stream == stderr) {
for (size_t i = 0; i < bytes_count; i++) {
char c = *(char*)(ptr + i);
_ksys_debug_putc(c);
}
return nmemb;
}
if (stream->mode != _FILEMODE_R) {
unsigned status = _ksys_file_write_file(stream->name, stream->position, bytes_count, ptr, &bytes_written);
if (status != KSYS_FS_ERR_SUCCESS) {
errno = EIO;
stream->error = errno;
return 0;
}
stream->position += bytes_written;
}
return bytes_written / size;
}

View File

@@ -1,10 +1,10 @@
#include <stdio.h>
#include <conio.h>
#include "../sys/_conio.h"
int getchar(void) {
con_init();
char c = 0;
con_gets(&c, 2);
console_gets(&c, 2);
if (c == 0) {
c = EOF;
}

View File

@@ -4,17 +4,16 @@
#include <errno.h>
#include <limits.h>
char *gets(char* str)
char* gets(char* str)
{
con_init();
if(con_gets(str, STDIO_MAX_MEM)==NULL){
if (console_gets(str, STDIO_MAX_MEM) == NULL) {
errno = EIO;
return NULL;
}
int str_len = strlen(str);
if(str[str_len-1]=='\n'){
str[str_len-1]='\0';
if (str[str_len - 1] == '\n') {
str[str_len - 1] = '\0';
}
return str;
}

View File

@@ -4,11 +4,13 @@
#include <stdio.h>
#include <stdlib.h>
//#include "format_print.h"
// #include "format_print.h"
int printf(const char *format, ...)
int printf(const char* format, ...)
{
va_list arg;
va_start(arg, format);
return vprintf(format, arg);
va_list arg;
va_start(arg, format);
int ret = vprintf(format, arg);
va_end(arg);
return ret;
}

View File

@@ -2,13 +2,12 @@
#include <stdio.h>
#include <string.h>
#include "conio.h"
#include "sys/ksys.h"
#include "../sys/_conio.h"
#include <sys/ksys.h>
int puts(const char *str)
{
con_init();
con_write_asciiz(str);
con_write_asciiz("\n");
return strlen(str);
}
size_t len = strlen(str);
console_write(str, len);
return len;
}

View File

@@ -4,7 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "conio.h"
#include "../sys/_conio.h"
#include <sys/ksys.h>
#include <errno.h>
#include <limits.h>
@@ -22,9 +22,9 @@ int vprintf(const char* format, va_list arg)
errno = ENOMEM;
return errno;
}
con_init();
len = vsnprintf(s, STDIO_MAX_MEM, format, arg);
con_write_string(s, len);
console_write(s, len);
free(s);
return (len);
}

View File

@@ -1,12 +1,10 @@
/* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */
#include <conio.h>
#include <sys/ksys.h>
#include "../sys/_conio.h"
void exit(int status)
{
if (__con_is_load) {
con_exit(status);
}
console_exit();
_ksys_exit();
}

View File

@@ -0,0 +1,10 @@
#ifndef __LIBC_SYS_CONIO_H_
#define __LIBC_SYS_CONIO_H
char* console_gets(char* buff, size_t len);
void console_write(const char* ptr, size_t len);
void console_exit();
#endif // __LIBC_SYS_CONIO_H

View File

@@ -0,0 +1,42 @@
#include <shell_api.h>
#include <conio.h>
#include "_conio.h"
char* console_gets(char* buff, size_t len)
{
char* ret = buff;
if (__shell_is_init < __SHELL_INIT_FAILED) {
shell_gets(buff, len);
}
if (__shell_is_init == __SHELL_INIT_FAILED) {
con_init();
ret = con_gets(buff, len);
}
return ret;
}
void console_write(const char* ptr, size_t len)
{
if (__shell_is_init < __SHELL_INIT_FAILED) {
shell_write_string(ptr, len);
}
if (__shell_is_init == __SHELL_INIT_FAILED) {
con_init();
con_write_string((char*)ptr, len);
}
}
void console_exit()
{
if (__shell_is_init < __SHELL_INIT_FAILED) {
shell_exit();
}
if (__shell_is_init == __SHELL_INIT_FAILED) {
if (__con_is_load) {
con_exit(0);
}
}
}

View File

@@ -122,7 +122,13 @@ struc fpcvt
.sizeof:
}
;-----------------------------------------------------------------------------
; Command flags
CMD_WITHOUT_PARAM = 1b ; command may be called without parameters
CMD_WITH_PARAM = 10b ; command may be called with parameters
CMD_WITHOUT_LOADED_APP = 100b ; command may be called without loaded program
CMD_WITH_LOADED_APP = 1000b ; command may be called with loaded program
;-----------------------------------------------------------------------------
; Entry point
@@ -449,63 +455,56 @@ z1:
mov esi, commands
call find_cmd
mov eax, aUnknownCommand
jc .x11
; check command requirements
; flags field:
; &1: command may be called without parameters
; &2: command may be called with parameters
; &4: command may be called without loaded program
; &8: command may be called with loaded program
jc .cmd_procg
mov eax, [esi+8]
mov ecx, [curarg]
cmp byte [ecx], 0
jz .noargs
test byte [esi+16], 2
jz .x11
test byte [esi+16], CMD_WITH_PARAM
jz .cmd_procg
jmp @f
.noargs:
test byte [esi+16], 1
jz .x11
test byte [esi+16], CMD_WITHOUT_PARAM
jz .cmd_procg
@@:
cmp [debuggee_pid], 0
jz .nodebuggee
mov eax, aAlreadyLoaded
test byte [esi+16], 8
jz .x11
jmp .x9
test byte [esi+16], CMD_WITH_LOADED_APP
jz .cmd_procg
jmp .run_cmd
.nodebuggee:
mov eax, need_debuggee
test byte [esi+16], 4
jnz .x9
test byte [esi+16], CMD_WITHOUT_LOADED_APP
jnz .run_cmd
.x11:
.cmd_procg:
xchg esi, eax
call put_message
; store cmdline for repeating
.x10:
.cmd_procg_no_put_msg:
mov esi, cmdline
mov ecx, [cmdline_len]
@@:
cmp ecx, 0
jle .we
jle .wait_event
mov al, [esi + ecx]
mov [cmdline_prev + ecx], al
dec ecx
jmp @b
.we:
.wait_event:
mov [cmdline_len], 0
jmp waitevent
.x9:
.run_cmd:
call dword [esi+4]
jmp .x10
jmp .cmd_procg_no_put_msg
;-----------------------------------------------------------------------------
; Cmdline handling

View File

@@ -2,7 +2,10 @@
COLOR_THEME fix MOVIEOS
format binary as ""
include '../../macros.inc'
include '../../KOSfuncs.inc'
use32
db 'MENUET01'
dd 1
@@ -1145,6 +1148,105 @@ OnDump:
.ret:
ret
;-----------------------------------------------------------------------------
; Print Backtrace
struct STACK_FRAME
prev_frame rd 1
ret_addr rd 1
ends
OnBacktrace:
push ebp
; Set max depth counter
xor eax, eax
dec eax
mov esi, [curarg]
cmp byte [esi], 0
jz .save_depth
call get_hex_number
mov esi, aParseError
jc .exit
; If depth 0
test eax, eax
jz .done
.save_depth:
mov [bt_depth], eax
; Get start frame addres
mov ebp, [_ebp]
test ebp, ebp
jz .done
mov edi, stack_frame_dump
.next:
mcall SF_DEBUG, SSF_READ_MEMORY, [debuggee_pid], sizeof.STACK_FRAME, ebp
cmp eax, -1
mov esi, read_mem_err
jz .exit
; The address of the previous frame must be less than the current one
mov eax, [edi + STACK_FRAME.prev_frame]
test eax, eax
jz .done
; Save stack_frame_dump
push edi
; Save previous frame
push ebp
; Save return address
mov eax, [edi + STACK_FRAME.ret_addr]
push eax
; Print frame address and return address
push eax ; pop in put_message_nodraw
push ebp ; pop in put_message_nodraw
mov esi, aBacktraceFmt
call put_message_nodraw
; Restore return address
pop eax
; Find symbol by return address
call find_near_symbol
test esi, esi
jnz .print_sym
mov esi, aBacktraceSymStub
.print_sym:
call put_message_nodraw
mov esi, newline
call put_message_nodraw
; Restore previous frame
pop ebp
; Restore stack_frame_dump
pop edi
; The address of the previous frame must be greater than the current one.
cmp [edi + STACK_FRAME.prev_frame], ebp
jna .done
; Set previous frame
mov ebp, [edi + STACK_FRAME.prev_frame]
dec [bt_depth]
jnz .next
.done:
mov esi, newline
.exit:
call put_message
pop ebp
ret
;-----------------------------------------------------------------------------
; Dissassemble block of executable event
@@ -1864,7 +1966,7 @@ include 'disasm.inc'
caption_str db 'Kolibri Debugger',0
begin_str db 'Kolibri Debugger, version 0.35',10
begin_str db 'Kolibri Debugger, version 0.36',10
db 'Hint: type "help" for help, "quit" to quit'
newline db 10,0
prompt db '> ',0
@@ -1880,66 +1982,88 @@ help_groups:
;-----------------------------------------------------------------------------
; Commands format definitions
; TODO: make it with macros
; flags field:
; &1: command may be called without parameters
; &2: command may be called with parameters
; &4: command may be called without loaded program
; &8: command may be called with loaded program
commands:
dd _aH, OnHelp, HelpSyntax, HelpHelp
db 0Fh
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITHOUT_LOADED_APP or CMD_WITH_LOADED_APP
dd aHelp, OnHelp, HelpSyntax, HelpHelp
db 0Fh
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITHOUT_LOADED_APP or CMD_WITH_LOADED_APP
dd aQuit, OnQuit, QuitSyntax, QuitHelp
db 0Dh
db CMD_WITHOUT_PARAM or CMD_WITHOUT_LOADED_APP or CMD_WITH_LOADED_APP
dd aLoad, OnLoad, LoadSyntax, LoadHelp
db 6
db CMD_WITH_PARAM or CMD_WITHOUT_LOADED_APP
dd aReload, OnReload, ReloadSyntax, ReloadHelp
db 0Dh
db CMD_WITHOUT_PARAM or CMD_WITHOUT_LOADED_APP or CMD_WITH_LOADED_APP
dd aTerminate, OnTerminate, TerminateSyntax, TerminateHelp
db 9
db CMD_WITHOUT_PARAM or CMD_WITH_LOADED_APP
dd aDetach, OnDetach, DetachSyntax, DetachHelp
db 9
db CMD_WITHOUT_PARAM or CMD_WITH_LOADED_APP
dd aSuspend, OnSuspend, SuspendSyntax, SuspendHelp
db 9
db CMD_WITHOUT_PARAM or CMD_WITH_LOADED_APP
dd aResume, OnResume, ResumeSyntax, ResumeHelp
db 0Bh
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aStep, OnStepMultiple, StepSyntax, StepHelp
db 0Bh
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aProceed, OnProceedMultiple, ProceedSyntax, ProceedHelp
db 0Bh
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aCalc, OnCalc, CalcSyntax, CalcHelp
db 0Eh
db CMD_WITH_PARAM or CMD_WITHOUT_LOADED_APP or CMD_WITH_LOADED_APP
dd aDump, OnDump, DumpSyntax, DumpHelp
db 0Bh
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBacktrace, OnBacktrace, BacktraceSyntax, BacktraceHelp
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aUnassemble, OnUnassemble, UnassembleSyntax, UnassembleHelp
db 0Bh
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBp, OnBp, BpSyntax, BpHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBpm, OnBpmb, BpmSyntax, BpmHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBpmb, OnBpmb, BpmSyntax, BpmHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBpmw, OnBpmw, BpmSyntax, BpmHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBpmd, OnBpmd, BpmSyntax, BpmHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBl, OnBl, BlSyntax, BlHelp
db 0Bh
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBc, OnBc, BcSyntax, BcHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBd, OnBd, BdSyntax, BdHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aBe, OnBe, BeSyntax, BeHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aReg, OnReg, RSyntax, RHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd aUnpack, OnUnpack, UnpackSyntax, UnpackHelp
db 9
db CMD_WITHOUT_PARAM or CMD_WITH_LOADED_APP
dd aLoadSymbols, OnLoadSymbols, LoadSymbolsSyntax, LoadSymbolsHelp
db 0Ah
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
dd 0
;-----------------------------------------------------------------------------
@@ -1980,7 +2104,8 @@ help_data_msg db 'List of data commands:',10
db 'd [<expression>] - dump data at given address',10
db 'u [<expression>] - unassemble instructions at given address',10
db 'r <register> <expression> or',10
db 'r <register>=<expression> - set register value',10,0
db 'r <register>=<expression> - set register value',10
db 'bt [<number>] - display backtrace / stacktrace',10,0
; Breakpoints commands group
@@ -2038,6 +2163,11 @@ DumpHelp db 'Dump data of debugged program',10
DumpSyntax db 'Usage: d <expression> - dump data at specified address',10
db ' or: d - continue current dump',10,0
aBacktrace db 3,'bt',0
BacktraceHelp db 'Display backtrace / stacktrace',10
BacktraceSyntax db 'Usage: bt <number> - display backtrace with depth',10
db ' or: bt display all backtrace',10,0
aCalc db 2,'?',0
CalcHelp db 'Calculate value of expression',10
CalcSyntax db 'Usage: ? <expression>',10,0
@@ -2102,6 +2232,11 @@ LoadSymbolsSyntax db 'Usage: load-symbols <symbols-file-name>',10,0
aUnknownCommand db 'Unknown command',10,0
;-----------------------------------------------------------------------------
; Info messages
aBacktraceSymStub db '??',0
aBacktraceFmt db '[0x%8X] 0x%8X in ',0
;-----------------------------------------------------------------------------
; Error messages
@@ -2474,11 +2609,13 @@ disasm_cur_pos dd ?
disasm_cur_str dd ?
disasm_string rb 256
thread_info process_information
stack_frame_dump rb sizeof.STACK_FRAME
bt_depth rd 1
;-----------------------------------------------------------------------------
; Coordinates and sizes for GUI
thread_info process_information
data_x_size_dd dd ?, ?
messages_x_size_dd dd ?, ?
registers_x_pos_dd dd ?, ?

View File

@@ -4,6 +4,11 @@
include 'sort.inc'
struct DEBUG_SYMBOL
addr rd 1
string rd 0
ends
; compare proc for sorter
compare:
cmpsd
@@ -459,4 +464,69 @@ find_symbol_name:
@@:
pop esi
ret
ret
;-----------------------------------------------------------------------------
;
; Find the nearest symol using binary search
;
; in: eax - target addres
; out: esi - symbol name
; destroys: ebx, ecx, edx, edi, ebp
;
find_near_symbol:
mov edi, [symbols]
xor esi, esi ; Result
mov ecx, esi ; Left
mov edx, [num_symbols] ; Right
dec edx
js .end
; If the first address is already greater than the target
mov ebp, [edi + ecx * sizeof.DEBUG_SYMBOL]
cmp [ebp + DEBUG_SYMBOL.addr], eax
ja .end
; If the last address is less than or equal to the target
mov ebp, [edi + edx * sizeof.DEBUG_SYMBOL]
cmp [ebp + DEBUG_SYMBOL.addr], eax
jbe .found
.loop:
cmp ecx, edx
ja .end
; Calc middle:
mov ebx, edx ; Middle
sub ebx, ecx ; (right - left)
shr ebx, 1 ; / 2
add ebx, ecx ; + left
; Equal
mov ebp, [edi + ebx * sizeof.DEBUG_SYMBOL]
cmp [ebp + DEBUG_SYMBOL.addr], eax
jz .found
jb .update_left
; Update right
mov edx, ebx
dec edx
jmp .loop
.update_left:
; Save potential result
mov esi, ebp
add esi, DEBUG_SYMBOL.string
; Update left
mov ecx, ebx
inc ecx
jmp .loop
.found:
mov esi, ebp
add esi, DEBUG_SYMBOL.string
.end:
ret

View File

@@ -84,6 +84,7 @@ commands: ; all commands must be in uppercase
; dd 'APPE', login_first, login_first, login_first, cmd_APPE
dd 'CDUP', login_first, login_first, login_first, cmdCDUP
dd 'CWD', login_first, login_first, login_first, cmdCWD
dd 'XCWD', login_first, login_first, login_first, cmdCWD
dd 'DELE', login_first, login_first, login_first, cmdDELE
; dd 'HELP', login_first, login_first, login_first, cmd_HELP
dd 'LIST', login_first, login_first, login_first, cmdLIST
@@ -96,6 +97,7 @@ commands: ; all commands must be in uppercase
dd 'PASV', login_first, login_first, login_first, cmdPASV
dd 'PORT', login_first, login_first, login_first, cmdPORT
dd 'PWD', login_first, login_first, login_first, cmdPWD
dd 'XPWD', login_first, login_first, login_first, cmdPWD
dd 'QUIT', cmdQUIT, cmdQUIT, cmdQUIT, cmdQUIT
; dd 'REIN', login_first, login_first, login_first, cmd_REIN
; dd 'REST', login_first, login_first, login_first, cmd_REST
@@ -342,7 +344,7 @@ align 4
cmdABOR:
or [ebp + thread_data.permissions], ABORT
sendFTP "250 Command succesul"
sendFTP "250 Command successful"
ret
;------------------------------------------------
@@ -383,7 +385,7 @@ cmdCDUP:
invoke con_write_asciiz, eax
invoke con_write_asciiz, str_newline
sendFTP "250 Command succesul"
sendFTP "250 Command successful"
ret
;------------------------------------------------
@@ -448,7 +450,7 @@ cmdCWD:
invoke con_write_asciiz, eax
invoke con_write_asciiz, str_newline
sendFTP "250 Command succesful"
sendFTP "250 Command successful"
ret
.err:
@@ -510,7 +512,7 @@ cmdDELE:
test eax, eax
jnz .err
sendFTP "250 Command succesful"
sendFTP "250 Command successful"
ret
.err:
sendFTP "550 No such file"
@@ -998,7 +1000,9 @@ cmdRETR:
cmp eax, -1
je .cannot_open ; FIXME: this is not the correct error
push eax
invoke con_write_asciiz, str2
pop eax
push eax ebx
mov esi, eax

View File

@@ -135,7 +135,7 @@ start:
mov [sockaddr1.port], ax
xchg al, ah
invoke con_printf, str1, eax
invoke con_printf, str1, ini_buf, eax
add esp, 8
; open listening socket
@@ -341,7 +341,7 @@ thread_exit:
; initialized data
title db 'FTP daemon', 0
str1 db 'Starting FTP daemon on port %u.', 0
str1 db 'Starting FTP daemon on %s:%u', 0
str2 db '.', 0
str2b db ' OK!',10,0
str3 db 'Listen error',10,0

View File

@@ -1,4 +0,0 @@
if tup.getconfig("NO_FASM") ~= "" then return end
HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../.." or tup.getconfig("HELPERDIR")
tup.include(HELPERDIR .. "/use_fasm.lua")
tup.rule("reshare.asm", FASM .. " -dlang=" .. tup.getconfig("LANG") .. " %f %o" .. tup.getconfig("KPACK_CMD"), "%B")

View File

@@ -1,72 +0,0 @@
; SPDX-License-Identifier: GPL-2.0-only
;
; Reshare - Shared Resources Daemon
;
; Copyright (C) 2024-2026 KolibriOS Team
; Copyright (C) 2024-2026 KolibriOS-NG Team
; ====================================================================
CBOX_WIDTH = 13
CBOX_HEIGHT = 13
CBOX_PIXELS = CBOX_WIDTH * CBOX_HEIGHT
CBOX_IMG_SIZE = CBOX_PIXELS * 3 ; 24-bpp BGR, tight rows
; ====================================================================
; Palette entry: 4 bytes BGR0 (padded for dword-indexed lookup)
macro BGRA c
{
db (c) and 0xFF, (c shr 8) and 0xFF, (c shr 16) and 0xFF, 0
}
P00 = 0x04D4FC ; 0xRRGGBB
P01 = 0x04C8FC
P02 = 0x04DCFC
P03 = 0x04B4FC
P04 = 0x04BCFC
P05 = 0x04A9FC
P06 = 0x0498F9
P07 = 0xD2F2FC
P08 = 0x04A5FA
P09 = 0xFFFFFF
P10 = 0xF6FDFD
P11 = 0xAFF9FC
P12 = 0x95E0F7
P13 = 0x0464BC
P14 = 0x2CDCFC
P15 = 0x049FFA
cbox_palette:
BGRA P00
BGRA P01
BGRA P02
BGRA P03
BGRA P04
BGRA P05
BGRA P06
BGRA P07
BGRA P08
BGRA P09
BGRA P10
BGRA P11
BGRA P12
BGRA P13
BGRA P14
BGRA P15
; 4-bit palette indices, one byte per pixel (upper nibble unused values 0..15)
cbox_indexed:
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ; row 1
db 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 ; row 2
db 2, 1, 1, 1, 1, 4, 4, 4, 3, 5, 5, 3, 3 ; row 3
db 0, 1, 1, 1, 4, 4, 3, 3, 6, 7, 7, 8, 3 ; row 4
db 0, 3, 5, 5, 3, 3, 3, 6, 9,10,11, 6, 3 ; row 5
db 0, 5, 7, 7, 6, 3, 6, 9,10,12,13, 6, 5 ; row 6
db 0, 6,10, 9,14, 6, 9,10,12,13, 6,15, 5 ; row 7
db 0, 6,12,10, 9, 9,10,12,13, 6,15, 5, 5 ; row 8
db 0, 6,13,12,10,10,12,13, 6,15, 5, 5, 5 ; row 9
db 1, 8, 6,13,12,12,13, 6,15, 5, 5, 5,15 ; row 10
db 1, 5,15, 6,13,13, 6,15, 5, 5, 5,15,15 ; row 11
db 1, 5, 5,15, 6, 6,15, 5, 5, 5,15,15, 6 ; row 12
db 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 ; row 13

View File

@@ -1,699 +0,0 @@
; SPDX-License-Identifier: GPL-2.0-only
;
; Reshare - Shared Resources Daemon
;
; Copyright (C) 2024-2026 KolibriOS Team
; Copyright (C) 2024-2026 KolibriOS-NG Team
; ====================================================================
use32
org 0
; ====================================================================
db "MENUET01"
dd 1
dd START
dd I_END
dd MEM
dd STACKTOP
dd 0
dd 0
; ====================================================================
include "../../macros.inc"
include "../../KOSfuncs.inc"
include "../../encoding.inc"
include "../../proc32.inc"
include "../../dll.inc"
include "../../debug-fdo.inc"
include "../../develop/libraries/libs-dev/libimg/libimg.inc"
include "checkbox.inc"
; ====================================================================
LIBS:
library img, "libimg.obj"
import img, img.destroy, "img_destroy", \
img.from_file, "img_from_file"
; ====================================================================
START:
mcall SF_SYS_MISC, SSF_HEAP_INIT
mcall SF_KEYBOARD, SSF_SET_INPUT_MODE, 1
; check if this is second instance of app. if so - run gui, else - run daemon
mcall SF_SYS_MISC, SSF_MEM_OPEN, meta_name, 0, SHM_READ
test eax, eax
jz MODE_DAEMON
mcall SF_SYS_MISC, SSF_MEM_CLOSE, meta_name
jmp MODE_GUI
.exit:
mcall SF_TERMINATE_PROCESS
; ====================================================================
MODE_GUI:
.event_loop:
mcall SF_WAIT_EVENT
cmp eax, EV_REDRAW
je .event_redraw
cmp eax, EV_KEY
je .event_key
cmp eax, EV_BUTTON
je .event_button
jmp .event_loop
.event_redraw:
mcall SF_REDRAW, SSF_BEGIN_DRAW
mcall SF_STYLE_SETTINGS, SSF_GET_COLORS, sc, sizeof.system_colors
mcall , SSF_GET_SKIN_HEIGHT
add eax, WIN.H
mov esi, eax
mcall SF_GET_SCREEN_SIZE
movzx ecx, ax
shr eax, 16
sub eax, WIN.W
shr eax, 1
shl eax, 16
add eax, WIN.W
mov ebx, eax
sub ecx, esi
shr ecx, 1
shl ecx, 16
add ecx, esi
mov edx, [sc.work]
add edx, WIN_STYLE
mcall SF_CREATE_WINDOW, , , , , title
; visual dividers
mcall SF_DRAW_RECT, <PAD, GRID.W>, <BTN.Y + BTN.H + PAD, 1>, [sc.work_graph]
mcall , , <GRID.Y + GRID.H, 1>,
; info row
mov ecx, FONT_TYPE shl 24
add ecx, [sc.work_text]
mcall SF_DRAW_TEXT, <PAD, GRID.Y + GRID.H + PAD - 1>, , lb_info
; tabs labels
mov esi, tab_label_strs
xor edi, edi
.tab_label_loop:
mov ebx, edi
imul ebx, TAB_STEP
push ebx
add ebx, PAD * 2
shl ebx, 16
add ebx, BTN.Y
mov edx, [esi]
mcall SF_DRAW_TEXT
add ebx, 1 shl 16 ; bold: x+1, same string
mcall SF_DRAW_TEXT
pop ebx
add ebx, PAD * 11
shl ebx, 16
add ebx, BTN.Y
mov edx, [esi + 4]
mcall SF_DRAW_TEXT
add esi, 8
inc edi
cmp edi, TAB_COUNT
jb .tab_label_loop
; tabs buttons
mov ecx, BTN.Y shl 16 + BTN.H
mov esi, ACTIVE_ICONS32
xor edi, edi
.btn_loop:
mov ebx, edi
imul ebx, TAB_STEP
add ebx, PAD
shl ebx, 16
add ebx, BTN.W
lea edx, [esi + BTN_BASE + BTN_HIDE]
mcall SF_DEFINE_BUTTON
add esi, esi ; 1→2→4→8 (next ACTIVE bit)
inc edi
cmp edi, TAB_COUNT
jb .btn_loop
; tabs content
call draw_tabs
mcall SF_REDRAW, SSF_END_DRAW
jmp .event_loop
.event_key:
mcall SF_GET_KEY
cmp ah, KEY_TAB
jne .event_loop
shl [active_tab], 1 ; * 2
cmp [active_tab], ACTIVE_CHECKBOX
jbe .tab_draw
mov [active_tab], 1
.tab_draw:
call draw_tabs
jmp .event_loop
.event_button:
mcall SF_GET_BUTTON
cmp ah, 1
je .event_exit
movzx eax, ah
sub eax, BTN_BASE
mov [active_tab], eax
call draw_tabs
jmp .event_loop
.event_exit:
mcall SF_TERMINATE_PROCESS
; ====================================================================
draw_tabs:
; draw tab underlines; active tab gets highlight color
xor edi, edi
mov esi, 1 ; current tab bit (ACTIVE_ICONS32=1, then 2, 4, 8)
.loop:
mov edx, [sc.work_dark]
test [active_tab], esi
jz .color_ok
mov edx, [sc.work_button]
.color_ok:
mov eax, edi
imul eax, TAB_STEP
add eax, PAD
mpack ebx, eax, BTN.W
mpack ecx, PAD + BTN.H + 2, 2
mcall SF_DRAW_RECT, ebx, ecx, edx
inc edi
add esi, esi ; shift to next tab bit (1→2→4→8)
cmp edi, TAB_COUNT
jb .loop
; draw current tab content
mcall SF_DRAW_RECT, <GRID.X, GRID.W>, <GRID.Y, GRID.H>, [sc.work]
mov eax, [active_tab]
bsf eax, eax ; 0=i32, 1=i18, 2=i18w, 3=cbox
cmp eax, 3
je .cbox
lea esi, [tab_icon_args + eax * 8]
stdcall draw_tab_icons, [esi], [esi + 4]
ret
.cbox:
stdcall draw_tab_cbox
ret
proc draw_tab_icons stdcall, _shm_name, _meta_off
mcall SF_SYS_MISC, SSF_MEM_OPEN, meta_name, 0, SHM_READ
test eax, eax
jz .done
add eax, [_meta_off]
mov ecx, [eax] ; icon_c
mov edx, [eax + 4] ; icon_w (always next field: _meta_off + 4)
test ecx, ecx
jz .close_meta
test edx, edx
jz .close_meta
push ecx
push edx
mcall SF_SYS_MISC, SSF_MEM_OPEN, [_shm_name], 0, SHM_READ
pop edx
pop ecx
test eax, eax
jz .close_meta
stdcall draw_tab_icons_grid, eax, ecx, edx
mcall SF_SYS_MISC, SSF_MEM_CLOSE, [_shm_name]
.close_meta:
mcall SF_SYS_MISC, SSF_MEM_CLOSE, meta_name
.done:
ret
endp
proc draw_tab_icons_grid stdcall uses ebx esi edi, _icon_img, _icon_c, _icon_w
locals
x dd 0
x_off dd 0
y dd 0
icon_size dd 0
endl
; icon_bytes = icon_w * icon_w * 4
mov eax, [_icon_w]
imul eax, eax
shl eax, 2
mov [icon_size], eax
; x_off = (CELL.W - icon_w) / 2
mov eax, CELL.W
sub eax, [_icon_w]
shr eax, 1
mov [x_off], eax
; y_step = CELL.H
mov edi, CELL.H
xor ecx, ecx
.for_icons:
cmp ecx, [_icon_c]
jae .end_for_icons
push ecx
; SF_PUT_IMAGE_EXT _icon_img+icon_size*index, <_icon_w, _icon_w>, <x+x_off, y+GRID_Y>, 32, 0, 0
mov ebx, [icon_size]
imul ebx, ecx
add ebx, [_icon_img]
mov ecx, [_icon_w]
shl ecx, 16
add ecx, [_icon_w]
mov edx, [x]
add edx, [x_off]
shl edx, 16
add edx, [y]
add edx, GRID.Y
push edi
push ebp
mcall SF_PUT_IMAGE_EXT, , , , 32, 0, 0
pop ebp
pop edi
; draw number with no leading zeros, centered in CELL.W
mov edx, [x]
add edx, GAP
shl edx, 16
add edx, [y]
add edx, [_icon_w]
add edx, GRID.Y + 2
mov esi, DRAWNUM_NOZERO
add esi, [sc.work_graph]
pop ecx
mcall SF_DRAW_NUMBER, DRAWNUM_DEC3, , , ,
inc ecx
add [x], CELL.W
cmp [x], WIN.W - CELL.W
jle .for_icons
mov [x], 0
add [y], edi
jmp .for_icons
.end_for_icons:
ret
endp
proc draw_tab_cbox stdcall
mcall SF_SYS_MISC, SSF_MEM_OPEN, lb_tab_cbox, 0, SHM_READ
test eax, eax
jz .done
mov ebx, eax
mcall SF_PUT_IMAGE, , \
<CBOX_WIDTH, CBOX_HEIGHT>, \
<(WIN.W - CBOX_WIDTH)/2, (WIN.H - CBOX_HEIGHT)/2>
mcall SF_SYS_MISC, SSF_MEM_CLOSE, lb_tab_cbox
.done:
ret
endp
; ====================================================================
MODE_DAEMON:
stdcall dll.Load, LIBS
; load shared resources from files
DEBUGF DBG_INFO, "I: @reshare: loading resources...\n"
stdcall load_icons, icons32_path, icons32_image, size32
stdcall load_icons, icons18_path, icons18_image, size18
; publish meta
mcall SF_SYS_MISC, SSF_MEM_OPEN, meta_name, META_SIZE, SHM_CREATE + SHM_WRITE
test eax, eax
jz .meta_done
mov edi, eax
xor ebx, ebx
xor ecx, ecx
mov eax, [icons32_image]
test eax, eax
jz .i32_set
mov ebx, [eax + Image.Width]
mov eax, [eax + Image.Height]
test ebx, ebx
jz .i32_set
xor edx, edx
div ebx
mov ecx, eax
.i32_set:
mov [edi + META_I32_W], ebx
mov [edi + META_I32_C], ecx
xor ebx, ebx
xor ecx, ecx
mov eax, [icons18_image]
test eax, eax
jz .i18_set
mov ebx, [eax + Image.Width]
mov eax, [eax + Image.Height]
test ebx, ebx
jz .i18_set
xor edx, edx
div ebx
mov ecx, eax
.i18_set:
mov [edi + META_I18_W], ebx
mov [edi + META_I18_C], ecx
mov [edi + META_I18W_W], ebx
mov [edi + META_I18W_C], ecx
mov dword [edi + META_CBOX_W], CBOX_WIDTH
mov dword [edi + META_CBOX_H], CBOX_HEIGHT
mov dword [edi + META_CBOX_SIZE], CBOX_IMG_SIZE
.meta_done:
DEBUGF DBG_INFO, "I: @reshare: starting in daemon mode\n"
mcall SF_SYS_MISC, SSF_MEM_OPEN, lb_tab_cbox, CBOX_IMG_SIZE, SHM_CREATE + SHM_WRITE
test eax, eax
jz .skip_cbox
mov edi, eax
mov esi, cbox_indexed
mov ecx, CBOX_PIXELS
cld
.cbox_expand:
movzx ebx, byte [esi]
inc esi
mov eax, [cbox_palette + ebx * 4]
stosb ; B
shr eax, 8
stosb ; G
shr eax, 8
stosb ; R
dec ecx
jnz .cbox_expand
.skip_cbox:
cmp [icons32_image], 0
jz .skip_i32
stdcall copy_image_to_shm, lb_tab_i32, size32, icons32_image
test eax, eax
jz .skip_i32
invoke img.destroy, [icons32_image]
.skip_i32:
cmp [icons18_image], 0
jz .skip_i18
stdcall copy_image_to_shm, lb_tab_i18, size18, icons18_image
test eax, eax
jz .skip_i18
mov [shared_i18], eax
mcall SF_SYS_MISC, SSF_MEM_OPEN, lb_tab_i18w, [size18], SHM_CREATE + SHM_WRITE
test eax, eax
jz .skip_i18
mov [shared_i18w], eax
invoke img.destroy, [icons18_image]
mov dword [icons18_image], 0
.skip_i18:
mcall SF_SET_EVENTS_MASK, EVM_BACKGROUND
.event_loop:
push [sc.work]
mcall SF_STYLE_SETTINGS, SSF_GET_COLORS, sc, sizeof.system_colors
pop eax
cmp eax, [sc.work]
je .wait_event
cmp [shared_i18], 0
jz .wait_event
cmp [shared_i18w], 0
jz .wait_event
mov esi, [shared_i18]
mov edi, [shared_i18w]
mov ecx, [size18]
shr ecx, 2 ; / 4 to get size in dwords
cld
rep movsd
stdcall replace_2cols, [shared_i18w], [size18], 0xFFFFFFFF, [sc.work], 0xFFCACBD6, [sc.work_dark]
.wait_event:
mcall SF_WAIT_EVENT
cmp eax, EV_BACKGROUND
je .event_loop
jmp .wait_event
proc load_icons stdcall uses ebx ecx, _path, _img_ptr, _size_ptr
invoke img.from_file, [_path]
test eax, eax
jz .fail
mov ebx, [_img_ptr]
mov [ebx], eax
mov ebx, [eax + Image.Width]
mov ecx, [eax + Image.Height]
imul ecx, ebx
shl ecx, 2
mov ebx, [_size_ptr]
mov [ebx], ecx
ret
.fail:
DEBUGF DBG_ERR, "E: @reshare: error loading icons from %s\n", [_path]
ret
endp
proc copy_image_to_shm stdcall uses ebx ecx edx esi edi, _shm_name, _size_ptr, _image_ptr
mov edx, [_size_ptr]
mov edx, [edx]
mcall SF_SYS_MISC, SSF_MEM_OPEN, [_shm_name], edx, SHM_CREATE + SHM_WRITE
test eax, eax
jz .done
mov ebx, [_image_ptr]
mov ebx, [ebx]
mov esi, [ebx + Image.Data]
mov edi, eax
mov ecx, [_size_ptr]
mov ecx, [ecx]
shr ecx, 2
cld
rep movsd
.done:
ret
endp
proc replace_2cols stdcall uses edi, _imgsrc, _imgsize, _col_old1, _col_new1, _col_old2, _col_new2
mov edx, [_imgsize]
add edx, [_imgsrc]
mov edi, [_imgsrc]
.loop:
cmp edi, edx
jae .done
mov eax, [edi]
cmp eax, [_col_old1]
jne .check2
mov eax, [_col_new1]
mov [edi], eax
jmp .next
.check2:
cmp eax, [_col_old2]
jne .next
mov eax, [_col_new2]
mov [edi], eax
.next:
add edi, 4
jmp .loop
.done:
ret
endp
; ====================================================================
BORD = 5
PAD = 8
GAP = 12
GRID_COLS = 16
GRID_ROWS = 9
GRID_Y = BTN.Y + BTN.H + PAD * 2 + 1
TAB_STEP = BTN.W + PAD * 2
WIN RECT 0, 0, GRID.W + PAD * 2 + BORD * 2, GRID.H + GRID_Y + 1 + PAD + 10 + GAP
BTN RECT 0, PAD + 4, CELL.W * 4 - PAD * 2 , 22
CELL RECT 0, 0, 32 + PAD * 2 , 32 + 4 + 10 + PAD
GRID RECT PAD, GRID_Y, CELL.W * GRID_COLS - PAD * 2, CELL.H * GRID_ROWS
FONT_TYPE = 0x90
WIN_STYLE = 0x34000000 ; skinned window, draws itself
BTN_HIDE = 0x60000000
BTN_BASE = 10 ; first user-defined button ID
DRAWNUM_DEC3 = 0x00030000 ; SF_DRAW_NUMBER: decimal, 3 digits
DRAWNUM_NOZERO = 0x10000000 ; SF_DRAW_NUMBER: no leading zeros
KEY_TAB = 15 ; Tab key scan code
; ====================================================================
if lang eq ru_RU
title cp866 "@RESHARE - Служба общих ресурсов", 0
lb_info cp866 "Имя каждой вкладки соответствует имени области памяти, доступной через сисфункцию 68.22.", 0
else if lang eq es_ES
title db "@RESHARE - Servicio de recursos compartidos", 0
lb_info db "Cada nombre de pestana corresponde al nombre de memoria accesible mediante sysfunc 68.22.", 0
else
title cp850 "@RESHARE - Shared resources service", 0
lb_info cp850 "Each tab name corresponds to shared memory page name that can be accessed via sysfunc 68.22.", 0
endf
lb_tab_i32 db "ICONS32", 0
lb_tab_i18 db "ICONS18", 0
lb_tab_i18w db "ICONS18W", 0
lb_tab_cbox db "CHECKBOX", 0
lb_tab_i32_res db "32x32x32bpp", 0
lb_tab_i18_res db "18x18x32bpp", 0
lb_tab_cbox_res db "13x13x24bpp", 0
; ====================================================================
DBG_ALL = 0 ; all messages
DBG_INFO = 1 ; info and errors
DBG_ERR = 2 ; only errors
__DEBUG__ = 1
__DEBUG_LEVEL__ = DBG_ERR
SHM_READ = 0x00
SHM_WRITE = 0x01
SHM_CREATE = 0x08
ACTIVE_ICONS32 = 1
ACTIVE_ICONS18 = 2
ACTIVE_ICONS18W = 4
ACTIVE_CHECKBOX = 8
TAB_COUNT = 4
META_I32_C = 0
META_I32_W = 4
META_I18_C = 8
META_I18_W = 12
META_I18W_C = 16
META_I18W_W = 20
META_CBOX_W = 24
META_CBOX_H = 28
META_CBOX_SIZE = 32
META_SIZE = 36
; ====================================================================
meta_name db "RESHARE_META", 0
icons32_path db "/SYS/ICONS32.PNG", 0
icons18_path db "/SYS/ICONS16.PNG", 0
; pointers to Image structures
icons32_image dd 0
icons18_image dd 0
; sizes of icons image data in bytes
size32 dd 0
size18 dd 0
; currenly selected i18w section
shared_i18 dd 0
shared_i18w dd 0
active_tab dd ACTIVE_ICONS32
tab_icon_args:
dd lb_tab_i32, META_I32_C ; META_I32_W = META_I32_C + 4
dd lb_tab_i18, META_I18_C ; META_I18_W = META_I18_C + 4
dd lb_tab_i18w, META_I18W_C ; META_I18W_W = META_I18W_C + 4
tab_label_strs:
dd lb_tab_i32, lb_tab_i32_res
dd lb_tab_i18, lb_tab_i18_res
dd lb_tab_i18w, lb_tab_i18_res
dd lb_tab_cbox, lb_tab_cbox_res
sc system_colors
include_debug_strings
; ====================================================================
I_END:
rb 4096
align 16
STACKTOP:
MEM: