/programs/demos/life2/include/l_proc_lib.h |
---|
File deleted |
\ No newline at end of file |
/programs/demos/life2/include/load_lib.h |
---|
File deleted |
\ No newline at end of file |
/programs/demos/life2/include/kos_func.inc |
---|
84,6 → 84,9 |
cmp esp,eax |
cmova esp,eax |
and esp,not 3 |
if defined @Kolibri@CommandLine |
mov byte [@Kolibri@CommandLine+256], 0 |
end if |
xor eax,eax |
cld |
mov edi,@Kolibri@_ThreadTable |
386,9 → 389,8 |
dec esi |
jz .window_defined |
mov eax,SF_DRAW_TEXT |
mov ebx,0x00070005 |
mov ebx,0x00070007 |
mov ecx,[ebp+KOLIBRI_THREAD_DATA_C_TITLE*4] |
or ecx,1 shl 28 ;make big font |
int 0x40 |
.window_defined: |
.redraw_picture: |
/programs/demos/life2/include/kolibri.h |
---|
8,7 → 8,7 |
namespace Kolibri // All kolibri functions, types and data are nested in the (Kolibri) namespace. |
{ |
const char *DebugPrefix = "User program: "; |
char CommandLine[2048]; |
char CommandLine[257]; |
struct TWindowData // Data for drawing a window. |
{ |
510,6 → 510,31 |
} |
} |
#else // def __KOLIBRI__ |
namespace Kolibri |
{ |
struct TMutex |
{ |
unsigned int mut; |
TMutex(); |
~TMutex(); |
}; |
#undef KOLIBRI_MUTEX_INIT |
#define KOLIBRI_MUTEX_INIT TMutex() |
struct TRecMutex |
{ |
unsigned int mut; |
TRecMutex(); |
~TRecMutex(); |
}; |
#undef KOLIBRI_REC_MUTEX_INIT |
#define KOLIBRI_REC_MUTEX_INIT TRecMutex() |
} |
#endif // else: def __KOLIBRI__ |
#endif // ndef __KOLIBRI_H_INCLUDED_ |
/programs/demos/life2/include/kos_start.inc |
---|
4,24 → 4,12 |
dd 1 |
dd @Kolibri@Main$qv |
dd I_END |
dd U_END+STACKSIZE ;+HEAPSIZE |
dd U_END+STACKSIZE+HEAPSIZE |
dd U_END+STACKSIZE |
if defined @Kolibri@CommandLine |
dd @Kolibri@CommandLine |
else |
dd 0 |
end if |
if defined @Kolibri@CurrentDirectoryPath |
dd @Kolibri@CurrentDirectoryPath |
else |
dd 0 |
end if |
dd @Kolibri@CommandLine,0 |
include "..\..\KOSfuncs.inc" |
include "..\..\proc32.inc" |
include "..\..\macros.inc" |
include "..\..\dll.inc" |
include "..\..\load_lib.mac" |
ptr equ |
offset equ |
/programs/demos/life2/kos_cdlg.inc |
---|
0,0 → 1,167 |
proc @Kolibri@OpenFileDialog$qr23Kolibri@TOpenFileStruct uses ebx esi edi ebp |
call @Kolibri@GetThreadData$qv |
mov ebp,eax |
mov ebx,[esp+20] |
cmp dword [ebx+4],0 |
jnz .open_file_dlg_str |
mov esi,7 |
jmp .open_file_dlg_alloc |
.open_file_dlg_str: |
cld |
mov edi,[ebx+4] |
mov ecx,-1 |
xor al,al |
repnz scas byte [edi] |
not ecx |
mov esi,ecx |
.open_file_dlg_alloc: |
push esi |
call @Kolibri@Alloc$qul |
pop ecx |
test eax,eax |
jz .open_file_dlg_ret |
mov ecx,esi |
dec ecx |
push esi |
push ecx |
push eax |
mov dword [ebx],-1 |
cmp dword [ebx+4],0 |
jnz .open_file_dlg_copy |
mov dword [eax],0x2F64722F |
mov word [eax+4],0x2F31 |
jmp .open_file_dlg_redraw |
.open_file_dlg_copy: |
cld |
mov ecx,esi |
mov esi,[ebx+4] |
mov edi,eax |
rep movs byte [edi],[esi] |
.open_file_dlg_redraw: |
mov eax,12 |
mov ebx,1 |
int 0x40 |
xor eax,eax |
mov ebx,[ebp+KOLIBRI_THREAD_DATA_X*4] |
mov ecx,[ebp+KOLIBRI_THREAD_DATA_Y*4] |
mov edx,[ebp+KOLIBRI_THREAD_DATA_C_WINDOW*4] |
mov esi,[ebp+KOLIBRI_THREAD_DATA_C_HEADER*4] |
mov edi,[ebp+KOLIBRI_THREAD_DATA_C_BORDER*4] |
int 0x40 |
mov eax,4 |
mov ebx,0x00070007 |
mov ecx,[ebp+KOLIBRI_THREAD_DATA_C_TITLE*4] |
mov edx,Kolibri_open_file_dlg_name |
mov esi,Kolibri_open_file_dlg_name_end - Kolibri_open_file_dlg_name |
int 0x40 |
mov eax,4 |
mov ebx,0x000C001E |
xor ecx,ecx |
mov edx,[esp] |
mov esi,[esp+4] |
int 0x40 |
mov eax,12 |
mov ebx,2 |
int 0x40 |
.open_file_dlg_loop: |
mov eax,10 |
int 0x40 |
dec eax |
jz .open_file_dlg_redraw |
dec eax |
jz .open_file_dlg_key |
dec eax |
jz .open_file_dlg_end |
jmp .open_file_dlg_loop |
.open_file_dlg_key: |
xor edi,edi |
.open_file_dlg_key_loop: |
mov eax,2 |
int 0x40 |
test al,al |
jnz .open_file_dlg_key_end |
cmp ah,27 |
jz .open_file_dlg_end |
cmp ah,13 |
jz .open_file_dlg_apply |
cmp ah,8 |
jz .open_file_dlg_key_bsp |
cmp ah,32 |
jna .open_file_dlg_key_loop |
mov ebx,[esp+4] |
cmp ebx,[esp+8] |
jb .open_file_dlg_key_any |
lea esi,[ebx+2*ebx] |
shr esi,1 |
inc esi |
push eax |
push esi |
push dword [esp+8] |
call @Kolibri@ReAlloc$qpvul |
add esp,8 |
mov ecx,eax |
pop eax |
test ecx,ecx |
jz .open_file_dlg_key |
mov [esp+8],esi |
mov [esp],ecx |
.open_file_dlg_key_any: |
mov esi,ebx |
add esi,[esp] |
mov byte [esi],ah |
inc ebx |
mov edi,1 |
mov [esp+4],ebx |
jmp .open_file_dlg_key_loop |
.open_file_dlg_key_bsp: |
mov eax,[esp+4] |
test eax,eax |
jz .open_file_dlg_key_loop |
dec eax |
mov edi,1 |
mov [esp+4],eax |
jmp .open_file_dlg_key_loop |
.open_file_dlg_key_end: |
test edi,edi |
jnz .open_file_dlg_redraw |
jmp .open_file_dlg_loop |
.open_file_dlg_apply: |
mov eax,[esp+4] |
inc eax |
mov [esp+8],eax |
push eax |
push dword [esp+4] |
call @Kolibri@ReAlloc$qpvul |
add esp,8 |
test eax,eax |
jz .open_file_dlg_end |
mov eax,[esp] |
mov esi,eax |
add eax,[esp+4] |
mov byte [eax],0 |
add esp,12 |
mov ebx,[esp+20] |
mov dword [ebx],2 |
push dword [ebx+4] |
call @Kolibri@Free$qpv |
pop ecx |
mov [ebx+4],esi |
jmp .open_file_dlg_invalidate |
.open_file_dlg_end: |
call @Kolibri@Free$qpv |
add esp,12 |
mov ebx,[esp+20] |
mov dword [ebx],1 |
.open_file_dlg_invalidate: |
push ebp |
push dword 1 |
call @@Kolibri@Invalidate$qippv |
add esp,8 |
.open_file_dlg_ret: |
ret |
endp |
Kolibri_open_file_dlg_name: |
db 'Open file' |
Kolibri_open_file_dlg_name_end: |
/programs/demos/life2/life2.cpp |
---|
1,37 → 1,43 |
#include <kolibri.h> |
#include <kos_heap.h> |
#include <kos_file.h> |
#include <load_lib.h> |
#include <l_proc_lib.h> |
#include "lifegen.h" |
#include "life_bmp.h" |
#include "kos_cdlg.h" |
using namespace Kolibri; |
char library_path[2048]; |
/*** |
#define StrLen LibbStrLen |
#define StrCopy LibbStrCopy |
#define MemCopy LibbMemCopy |
#define MemSet LibbMemSet |
#define Floor LibbFloor |
OpenDialog_data ofd; |
unsigned char procinfo[1024]; |
char plugin_path[4096], filename_area[256]; |
od_filter filter1 = { 8, "LIF\0\0" }; |
unsigned int (*StrLen)(const char *str) = 0; |
char *(*StrCopy)(char *dest, const char *src) = 0; |
void *(*MemCopy)(void *dest, const void *src, unsigned int n) = 0; |
void *(*MemSet)(void *s, char c, unsigned int n) = 0; |
double (*Floor)(double x) = 0; |
namespace Kolibri{ |
char CurrentDirectoryPath[2048]; |
} |
void __stdcall DrawWindow() |
void LibbInit() |
{ |
asm{ |
push ebx |
mcall SF_REDRAW,SSF_BEGIN_DRAW |
HINSTANCE hLib = LoadLibrary("Libb.dll"); |
if (!hLib) |
{ |
DebugPutString("Can't load the library.\n"); |
Kolibri::Abort(); |
} |
//KolibriOnPaint(); |
asm{ |
mcall SF_REDRAW,SSF_END_DRAW |
pop ebx |
StrLen = (unsigned int(*)(const char *str))GetProcAddress(hLib, "StrLen"); |
StrCopy = (char *(*)(char *dest, const char *src))GetProcAddress(hLib, "StrCopy"); |
MemCopy = (void *(*)(void *dest, const void *src, unsigned int n))GetProcAddress(hLib, "MemCopy"); |
MemSet = (void *(*)(void *s, char c, unsigned int n))GetProcAddress(hLib, "MemSet"); |
Floor = (double (*)(double x))GetProcAddress(hLib, "Floor"); |
} |
} |
#pragma startup LibbInit |
/**/ |
void __stdcall OneGeneration(int w, int h, void *dest, const void *src, int flag); |
struct GenerateParam |
101,7 → 107,7 |
AxisParam ypar = {0, 0, 0}; |
MouseParam mpar = {0, 0, 0, 0, 0, MouseParam::HitNull}; |
MenuParam menu; |
bool open_file_str = false; |
TOpenFileStruct open_file_str = KOLIBRI_OPEN_FILE_INIT; |
TimeGeneration timegen[TimeGenLength]; |
int timegenpos = 0; |
1350,9 → 1356,11 |
void MenuOpenDialogEnd(TThreadData th) |
{ |
if(!ofd.openfile_path[0] || !open_file_str) return; |
open_file_str = false; |
char *name = ofd.openfile_path; |
int state = OpenFileGetState(open_file_str); |
if (state <= 0) return; |
OpenFileSetState(open_file_str, 0); |
if (state != 2) return; |
char *name = OpenFileGetName(open_file_str); |
if (!name) return; |
FileInfoBlock* file = FileOpen(name); |
if (!file) return; |
1459,9 → 1467,8 |
MenuClearClick(th); |
break; |
case MenuIOpen: |
ofd.type = 0; // 0 - open |
OpenDialog_Start(&ofd); |
if(ofd.status==1) open_file_str = true; |
if (OpenFileGetState(open_file_str) < 0) break; |
OpenFileDialog(open_file_str); |
break; |
case MenuIAbout: |
MenuAboutClick(th); |
1699,26 → 1706,11 |
me_start.Width = 500; me_start.Height = 400; |
InitGenerate(); |
InitMenuButton(); |
if(LoadLibrary("proc_lib.obj", library_path, "/sys/lib/proc_lib.obj", &import_proc_lib)) |
if (CommandLine[0]) |
{ |
ofd.procinfo = procinfo; |
ofd.com_area_name = "FFFFFFFF_open_dialog"; |
ofd.com_area = 0; |
ofd.opendir_path = plugin_path; |
ofd.dir_default_path = "/rd/1"; |
ofd.start_path = "/rd/1/File managers/opendial"; |
ofd.draw_window = DrawWindow; |
ofd.status = 0; |
ofd.openfile_path = CommandLine; |
ofd.filename_area = filename_area; |
ofd.filter_area = &filter1; |
ofd.x_size = 420; |
ofd.x_start = 10; |
ofd.y_size = 320; |
ofd.y_start = 10; |
OpenDialog_Init(&ofd); |
} else return false; |
if (CommandLine[0]) open_file_str = true; |
open_file_str.state = 2; |
OpenFileSetName(open_file_str, CommandLine); |
} |
return true; |
} |
1733,7 → 1725,7 |
{ |
static const unsigned int WAIT_TIME = 2, GEN_TIME = 1; |
int res = -1; |
if (open_file_str) |
if (OpenFileGetState(open_file_str) > 0) |
{ |
MenuOpenDialogEnd(th); |
res = 0; |
1834,9 → 1826,8 |
break; |
case 'o': |
case 'O': |
ofd.type = 0; // 0 - open |
OpenDialog_Start(&ofd); |
if(ofd.status==1) open_file_str=true; |
if (OpenFileGetState(open_file_str) < 0) break; |
OpenFileDialog(open_file_str); |
break; |
case 'a': |
case 'A': |
/programs/demos/life2/kos_cdlg.h |
---|
0,0 → 1,100 |
#ifndef __KOLIBRI_FILE_OPEN_H_INCLUDED_ |
#define __KOLIBRI_FILE_OPEN_H_INCLUDED_ |
#include <kolibri.h> |
// Kolibri interface. |
namespace Kolibri // All kolibri functions, types and data are nested in the (Kolibri) namespace. |
{ |
struct TOpenFileStruct; // Data for a file open dialog. |
#define KOLIBRI_OPEN_FILE_INIT {} // Initializer of the file open struct, cat be redefined in a realization of the library |
void OpenFileInit(TOpenFileStruct &ofs); |
void OpenFileDelete(TOpenFileStruct &ofs); |
bool OpenFileDialog(TOpenFileStruct &ofs); |
int OpenFileGetState(const TOpenFileStruct &ofs); |
bool OpenFileSetState(TOpenFileStruct &ofs, int state); |
char *OpenFileGetName(const TOpenFileStruct &ofs); |
bool OpenFileSetName(TOpenFileStruct &ofs, char *name); |
} |
#ifdef __KOLIBRI__ |
namespace Kolibri |
{ |
// Structures. |
struct TOpenFileStruct |
{ |
int state; |
char *name; |
}; |
#undef KOLIBRI_OPEN_FILE_INIT |
#define KOLIBRI_OPEN_FILE_INIT {0,0} |
// Inline functions. |
inline void OpenFileInit(TOpenFileStruct &ofs) |
{ |
ofs.state = 0; |
ofs.name = 0; |
} |
inline void OpenFileDelete(TOpenFileStruct &ofs) |
{ |
if (ofs.name) {Free(ofs.name); ofs.name = 0;} |
} |
inline int OpenFileGetState(const TOpenFileStruct &ofs) |
{ |
return ofs.state; |
} |
inline char *OpenFileGetName(const TOpenFileStruct &ofs) |
{ |
return ofs.name; |
} |
// Functions. |
bool OpenFileSetState(TOpenFileStruct &ofs, int state) |
{ |
if (!ofs.state) return !state; |
if (ofs.state == state) return true; |
if (state < 0) return false; |
ofs.state = state; |
return true; |
} |
bool OpenFileSetName(TOpenFileStruct &ofs, char *name) |
{ |
if (!ofs.name && !name) return true; |
if (ofs.name) Free(ofs.name); |
if (!name) {ofs.name = 0; return true;} |
ofs.name = (char*)Alloc(StrLen(name) + 1); |
if (!ofs.name) return false; |
StrCopy(ofs.name, name); |
return true; |
} |
} |
#else // else: def __KOLIBRI__ |
namespace Kolibri |
{ |
struct TOpenFileStruct |
{ |
unsigned int data; |
TOpenFileStruct(); |
~TOpenFileStruct(); |
}; |
#undef KOLIBRI_OPEN_FILE_INIT |
#define KOLIBRI_OPEN_FILE_INIT TOpenFileStruct() |
} |
#endif // __KOLIBRI__ |
#endif // __KOLIBRI_FILE_OPEN_H_INCLUDED_ |
/programs/demos/life2/kos_make.inc |
---|
2,11 → 2,12 |
;//COMPILER// bcc32 -S -v- -R- -6 -a4 -O2 -Og -Oi -Ov -OS -k- -D__KOLIBRI__ -Iinclude |
;//UTIL_PATH// . |
STACKSIZE equ 8196 |
HEAPSIZE equ 0 |
STACKSIZE equ 102400 |
HEAPSIZE equ 102400 |
include "include\kos_start.inc" |
include "include\kos_func.inc" |
include "include\kos_heap.inc" |
include "kos_cdlg.inc" |
include "mmxlife.inc" |
;include "sse2life.inc" |
/programs/demos/life2/kos_cdlg_win.cpp |
---|
0,0 → 1,115 |
#include <commdlg.h> |
#include <kolibri.h> |
#include <kos_heap.h> |
#include "kos_cdlg.h" |
using namespace Kolibri; |
extern HINSTANCE hInstance; |
struct TThreadDataStruct |
{ |
void *user; |
void *stack_begin; |
TWindowData *win_data; |
HWND hwnd; |
int flag; |
unsigned int win_time, me_time; |
void *picture; |
unsigned int picture_width, picture_height; |
void *keys; |
unsigned int bmp_data_length; |
unsigned int *bmp_data; |
unsigned int mouse_state; |
}; |
struct TOpenFileData |
{ |
int state; |
char name[1]; |
}; |
namespace Kolibri |
{ |
TOpenFileStruct::TOpenFileStruct() : data(0) {} |
TOpenFileStruct::~TOpenFileStruct() |
{ |
if (data) {delete[] (char*)data; data = 0;} |
} |
void OpenFileInit(TOpenFileStruct &ofs) {ofs.data = 0;} |
void OpenFileDelete(TOpenFileStruct &ofs) |
{ |
if (ofs.data) {delete[] (char*)ofs.data; ofs.data = 0;} |
} |
bool OpenFileDialog(TOpenFileStruct &ofs) |
{ |
char CustomFilter[300], *name; |
int size; |
CustomFilter[0] = 0; CustomFilter[1] = 0; |
if (!OpenFileSetState(ofs, 0)) return false; |
OPENFILENAME ofn = {sizeof(OPENFILENAME), ((TThreadDataStruct*)GetThreadData())->hwnd, |
hInstance, "All files (*.*)\0*.*\0", |
CustomFilter, sizeof(CustomFilter)-1, 1, NULL, 0, NULL, 0, NULL, NULL, |
OFN_HIDEREADONLY | OFN_EXPLORER, 0, 0, "", 0, NULL, 0}; |
size = 0; |
if (ofs.data) size = strlen(((TOpenFileData*)ofs.data)->name) + 1; |
if (size < 10000) size = 10000; |
name = new char[size + 1]; |
if (!name) return false; |
if (ofs.data) strcpy(name, ((TOpenFileData*)ofs.data)->name); |
else name[0] = 0; |
ofn.lpstrFile = &name[0]; ofn.nMaxFile = size; |
size = GetOpenFileName(&ofn) == TRUE; |
if (OpenFileSetName(ofs, name)) |
{ |
((TOpenFileData*)ofs.data)->state = (size ? 2 : 1); |
} |
else size = 0; |
delete[] name; |
return (bool)size; |
} |
int OpenFileGetState(const TOpenFileStruct &ofs) |
{ |
return ofs.data ? ((TOpenFileData*)ofs.data)->state : 0; |
} |
bool OpenFileSetState(TOpenFileStruct &ofs, int state) |
{ |
if (!ofs.data || !((TOpenFileData*)ofs.data)->state) return !state; |
if (((TOpenFileData*)ofs.data)->state == state) return true; |
if (state < 0) return false; |
((TOpenFileData*)ofs.data)->state = state; |
return true; |
} |
char *OpenFileGetName(const TOpenFileStruct &ofs) |
{ |
if (!ofs.data) return 0; |
else return ((TOpenFileData*)ofs.data)->name; |
} |
bool OpenFileSetName(TOpenFileStruct &ofs, char *name) |
{ |
if (!ofs.data && !name) return true; |
int size = (unsigned int)(((TOpenFileData*)0)->name) + 1; |
int state = 0; |
if (name) size += strlen(name); |
if (ofs.data) |
{ |
state = ((TOpenFileData*)ofs.data)->state; |
delete[] (char*)ofs.data; |
} |
ofs.data = (unsigned int)(new char[size]); |
if (!ofs.data) return false; |
((TOpenFileData*)ofs.data)->state = state; |
if (name) strcpy(((TOpenFileData*)ofs.data)->name, name); |
else ((TOpenFileData*)ofs.data)->name[0] = 0; |
return true; |
} |
} |