clean code

git-svn-id: svn://kolibrios.org@8170 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
IgorA 2020-11-10 12:19:15 +00:00
parent 0920470661
commit 97d7b5c34a
14 changed files with 306 additions and 316 deletions

View File

@ -1,3 +1,3 @@
kos32-bcc -S -v- -R- -6 -a4 -O2 -Og -Oi -Ov -OS -k- -D__MENUET__ -Iinclude life2.cpp kos32-bcc -S -v- -R- -6 -a4 -O2 -Og -Oi -Ov -OS -k- -D__KOLIBRI__ -Iinclude life2.cpp
echo include "me_make.inc" > f_life2.asm echo include "kos_make.inc" > f_life2.asm
t2fasm < life2.asm >> f_life2.asm t2fasm < life2.asm >> f_life2.asm

View File

@ -28,10 +28,10 @@ namespace Kolibri // All kolibri functions, types and data are nested in the (
//_ The stack will be deleted from dynamic memory at the finish of the thread if stack beginning is not zero. //_ The stack will be deleted from dynamic memory at the finish of the thread if stack beginning is not zero.
struct TMutex; // Simple mutex can be locked only once at a time. struct TMutex; // Simple mutex can be locked only once at a time.
#define MENUET_MUTEX_INIT {} // Simple mutex initializer, cat be redefined in a realization of the library #define KOLIBRI_MUTEX_INIT {} // Simple mutex initializer, cat be redefined in a realization of the library
struct TRecMutex; // Recursive mutex can be locked many times by a single thread at a time. struct TRecMutex; // Recursive mutex can be locked many times by a single thread at a time.
#define MENUET_REC_MUTEX_INIT {} // Recursive mutex initializer, cat be redefined in a realization of the library #define KOLIBRI_REC_MUTEX_INIT {} // Recursive mutex initializer, cat be redefined in a realization of the library
// Some functions have two forms: the fast form with (thread_data) parameter and the form without it. // Some functions have two forms: the fast form with (thread_data) parameter and the form without it.
// Note: pass only thread data of current thread as (thread_data) parameter to these functions. // Note: pass only thread data of current thread as (thread_data) parameter to these functions.
@ -146,7 +146,7 @@ void KolibriOnSize(int window_rect[/* 4 */], Kolibri::TThreadData thread_data);
void KolibriOnKeyPress(Kolibri::TThreadData thread_data); // When user press a key. void KolibriOnKeyPress(Kolibri::TThreadData thread_data); // When user press a key.
void KolibriOnMouse(Kolibri::TThreadData thread_data); // When user move a mouse. void KolibriOnMouse(Kolibri::TThreadData thread_data); // When user move a mouse.
#ifdef __MENUET__ #ifdef __KOLIBRI__
namespace Kolibri namespace Kolibri
{ {
@ -156,15 +156,15 @@ namespace Kolibri
{ {
unsigned int mut; unsigned int mut;
}; };
#undef MENUET_MUTEX_INIT #undef KOLIBRI_MUTEX_INIT
#define MENUET_MUTEX_INIT {0x40} // Simple mutex initializer, cat be redefined in a realization of the library #define KOLIBRI_MUTEX_INIT {0x40} // Simple mutex initializer, cat be redefined in a realization of the library
struct TRecMutex // Recursive mutex can be locked many times by a single thread at a time. struct TRecMutex // Recursive mutex can be locked many times by a single thread at a time.
{ {
unsigned int mut, pid; unsigned int mut, pid;
}; };
#undef MENUET_REC_MUTEX_INIT #undef KOLIBRI_REC_MUTEX_INIT
#define MENUET_REC_MUTEX_INIT {0x20,-1} // Recursive mutex initializer, cat be redefined in a realization of the library #define KOLIBRI_REC_MUTEX_INIT {0x20,-1} // Recursive mutex initializer, cat be redefined in a realization of the library
// Global variables. // Global variables.
@ -172,7 +172,7 @@ namespace Kolibri
volatile unsigned int _ThreadScanCount[2] = {0, 0}; volatile unsigned int _ThreadScanCount[2] = {0, 0};
volatile int _ThreadNumber = 1; volatile int _ThreadNumber = 1;
volatile int _ExitProcessNow = 0; volatile int _ExitProcessNow = 0;
TMutex _ThreadMutex = MENUET_MUTEX_INIT; TMutex _ThreadMutex = KOLIBRI_MUTEX_INIT;
unsigned int _ThreadSavedBegProc[4]; unsigned int _ThreadSavedBegProc[4];
// Inline functions. // Inline functions.
@ -478,8 +478,8 @@ namespace Kolibri
int win_type = ((unsigned int)thread_data[KOLIBRI_THREAD_DATA_FLAG] & 0x40000000) ? int win_type = ((unsigned int)thread_data[KOLIBRI_THREAD_DATA_FLAG] & 0x40000000) ?
((TStartData*)thread_data[KOLIBRI_THREAD_DATA_TITLE])->WinData.WindowType : ((TStartData*)thread_data[KOLIBRI_THREAD_DATA_TITLE])->WinData.WindowType :
((unsigned int)thread_data[KOLIBRI_THREAD_DATA_C_WINDOW] >> 24); ((unsigned int)thread_data[KOLIBRI_THREAD_DATA_C_WINDOW] >> 24);
border_size = MENUET_BORDER_SIZE; border_size = KOLIBRI_BORDER_SIZE;
header_size = short(((win_type & 15) == 3) ? _GetSkinHeader() : MENUET_HEADER_SIZE); header_size = short(((win_type & 15) == 3) ? _GetSkinHeader() : KOLIBRI_HEADER_SIZE);
} }
void GetClientSize(unsigned short &width, unsigned short &height, void GetClientSize(unsigned short &width, unsigned short &height,
@ -507,7 +507,7 @@ namespace Kolibri
} }
} }
#else // def __MENUET__ #else // def __KOLIBRI__
namespace Kolibri namespace Kolibri
{ {
@ -518,8 +518,8 @@ namespace Kolibri
TMutex(); TMutex();
~TMutex(); ~TMutex();
}; };
#undef MENUET_MUTEX_INIT #undef KOLIBRI_MUTEX_INIT
#define MENUET_MUTEX_INIT TMutex() #define KOLIBRI_MUTEX_INIT TMutex()
struct TRecMutex struct TRecMutex
{ {
@ -528,11 +528,11 @@ namespace Kolibri
TRecMutex(); TRecMutex();
~TRecMutex(); ~TRecMutex();
}; };
#undef MENUET_REC_MUTEX_INIT #undef KOLIBRI_REC_MUTEX_INIT
#define MENUET_REC_MUTEX_INIT TRecMutex() #define KOLIBRI_REC_MUTEX_INIT TRecMutex()
} }
#endif // else: def __MENUET__ #endif // else: def __KOLIBRI__
#endif // ndef __KOLIBRI_H_INCLUDED_ #endif // ndef __KOLIBRI_H_INCLUDED_

View File

@ -39,7 +39,7 @@ struct TThreadDataStruct
TThreadDataStruct /*__thread*/ ThreadDataStruct; TThreadDataStruct /*__thread*/ ThreadDataStruct;
int nCmdShow; int nCmdShow;
HINSTANCE hInstance; HINSTANCE hInstance;
const char szWindowClass[] = "Menuet window"; const char szWindowClass[] = "Kolibri window";
void FinalizeThreadData() void FinalizeThreadData()
{ {
@ -127,53 +127,53 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return 0; return 0;
case WM_TIMER: case WM_TIMER:
t = CalculateNewTime(); t = CalculateNewTime();
while (MenuetOnIdle((TThreadData)(&ThreadDataStruct)) == 0 && while (KolibriOnIdle((TThreadData)(&ThreadDataStruct)) == 0 &&
GetTickCount() - t + 2 < timeout); GetTickCount() - t + 2 < timeout);
return 0; return 0;
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
MenuetOnMouse((TThreadData)(&ThreadDataStruct)); KolibriOnMouse((TThreadData)(&ThreadDataStruct));
return 0; return 0;
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
if (!ThreadDataStruct.mouse_state) SetCapture(hWnd); if (!ThreadDataStruct.mouse_state) SetCapture(hWnd);
ThreadDataStruct.mouse_state |= 1; ThreadDataStruct.mouse_state |= 1;
MenuetOnMouse((TThreadData)(&ThreadDataStruct)); KolibriOnMouse((TThreadData)(&ThreadDataStruct));
return 0; return 0;
case WM_LBUTTONUP: case WM_LBUTTONUP:
if (ThreadDataStruct.mouse_state & 1) if (ThreadDataStruct.mouse_state & 1)
{ {
ThreadDataStruct.mouse_state &= ~1; ThreadDataStruct.mouse_state &= ~1;
if (!ThreadDataStruct.mouse_state) ReleaseCapture(); if (!ThreadDataStruct.mouse_state) ReleaseCapture();
MenuetOnMouse((TThreadData)(&ThreadDataStruct)); KolibriOnMouse((TThreadData)(&ThreadDataStruct));
} }
return 0; return 0;
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
if (!ThreadDataStruct.mouse_state) SetCapture(hWnd); if (!ThreadDataStruct.mouse_state) SetCapture(hWnd);
ThreadDataStruct.mouse_state |= 2; ThreadDataStruct.mouse_state |= 2;
MenuetOnMouse((TThreadData)(&ThreadDataStruct)); KolibriOnMouse((TThreadData)(&ThreadDataStruct));
return 0; return 0;
case WM_RBUTTONUP: case WM_RBUTTONUP:
if (ThreadDataStruct.mouse_state & 2) if (ThreadDataStruct.mouse_state & 2)
{ {
ThreadDataStruct.mouse_state &= ~2; ThreadDataStruct.mouse_state &= ~2;
if (!ThreadDataStruct.mouse_state) ReleaseCapture(); if (!ThreadDataStruct.mouse_state) ReleaseCapture();
MenuetOnMouse((TThreadData)(&ThreadDataStruct)); KolibriOnMouse((TThreadData)(&ThreadDataStruct));
} }
return 0; return 0;
case WM_CAPTURECHANGED: case WM_CAPTURECHANGED:
if (ThreadDataStruct.mouse_state) if (ThreadDataStruct.mouse_state)
{ {
ThreadDataStruct.mouse_state = 0; ThreadDataStruct.mouse_state = 0;
MenuetOnMouse((TThreadData)(&ThreadDataStruct)); KolibriOnMouse((TThreadData)(&ThreadDataStruct));
} }
return 0; return 0;
//case WM_SYSKEYDOWN: case WM_KEYDOWN: //case WM_SYSKEYDOWN: case WM_KEYDOWN:
case WM_CHAR: case WM_CHAR:
ThreadDataStruct.keys->push_back((unsigned char)wParam); ThreadDataStruct.keys->push_back((unsigned char)wParam);
MenuetOnKeyPress((TThreadData)(&ThreadDataStruct)); KolibriOnKeyPress((TThreadData)(&ThreadDataStruct));
return 0; return 0;
case WM_SIZE: case WM_SIZE:
GetProcessInfo(0, 0, 0, 0, window_rect); GetProcessInfo(0, 0, 0, 0, window_rect);
MenuetOnSize(window_rect, (TThreadData)(&ThreadDataStruct)); KolibriOnSize(window_rect, (TThreadData)(&ThreadDataStruct));
InvalidateRect(hWnd, 0, 0); InvalidateRect(hWnd, 0, 0);
return 0; return 0;
case WM_PAINT: case WM_PAINT:
@ -182,7 +182,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
EndPaint(hWnd, &ps); EndPaint(hWnd, &ps);
return 0; return 0;
case WM_CLOSE: case WM_CLOSE:
if (MenuetOnClose((TThreadData)(&ThreadDataStruct))) if (KolibriOnClose((TThreadData)(&ThreadDataStruct)))
{ {
ThreadDataStruct.flag = -1; ThreadDataStruct.flag = -1;
} }
@ -262,12 +262,12 @@ namespace Kolibri
start_data.WinData.BorderColor = 0x000000; start_data.WinData.BorderColor = 0x000000;
start_data.WinData.TitleColor = 0xFFFF40; start_data.WinData.TitleColor = 0xFFFF40;
start_data.WinData.Title = 0; start_data.WinData.Title = 0;
if (MenuetOnStart(start_data, (TThreadData)(&ThreadDataStruct))) if (KolibriOnStart(start_data, (TThreadData)(&ThreadDataStruct)))
{ {
while (ThreadDataStruct.flag < 0) while (ThreadDataStruct.flag < 0)
{ {
ThreadDataStruct.flag &= ~0x80000000; ThreadDataStruct.flag &= ~0x80000000;
if (MenuetOnClose((TThreadData)(&ThreadDataStruct))) if (KolibriOnClose((TThreadData)(&ThreadDataStruct)))
{ {
ThreadDataStruct.flag = -1; ThreadDataStruct.flag = -1;
break; break;

View File

@ -22,7 +22,7 @@ namespace Kolibri // All kolibri functions, types and data are nested in the (
int FileRead(TFileData file_data, void *mem, int size); int FileRead(TFileData file_data, void *mem, int size);
} }
#ifdef __MENUET__ #ifdef __KOLIBRI__
namespace Kolibri namespace Kolibri
{ {
@ -262,7 +262,7 @@ namespace Kolibri
} }
} }
#else // def __MENUET__ #else // def __KOLIBRI__
namespace Kolibri namespace Kolibri
{ {
@ -272,7 +272,7 @@ namespace Kolibri
}; };
} }
#endif // else: def __MENUET__ #endif // else: def __KOLIBRI__
#endif // ndef __KOLIBRI_FILE_H_INCLUDED_ #endif // ndef __KOLIBRI_FILE_H_INCLUDED_

View File

@ -1,7 +1,7 @@
;const int ;const int
MENUET_BORDER_SIZE = 4; KOLIBRI_BORDER_SIZE = 4;
;const int ;const int
MENUET_HEADER_SIZE = 20; KOLIBRI_HEADER_SIZE = 20;
;const int ;const int
KOLIBRI_THREAD_DATA_USER = 0; // Thread data begin from the user dword KOLIBRI_THREAD_DATA_USER = 0; // Thread data begin from the user dword
@ -39,7 +39,7 @@ KOLIBRI_THREAD_DATA_LAST_SY = 15;
KOLIBRI_THREAD_DATA_LEN = 16; KOLIBRI_THREAD_DATA_LEN = 16;
;const int ;const int
MENUET_MUTEX_MAX_TIME_WAIT = 20; KOLIBRI_MUTEX_MAX_TIME_WAIT = 20;
;const int ;const int
KOLIBRI_FILE_BLOCK_SIZE = 512; KOLIBRI_FILE_BLOCK_SIZE = 512;
@ -53,23 +53,23 @@ macro segment name
{ {
segment name segment name
if name eq _init_ | name eq _INIT_ if name eq _init_ | name eq _INIT_
Menuet_SegmentInit: Kolibri_SegmentInit:
else if name eq _exit_ | name eq _EXIT_ else if name eq _exit_ | name eq _EXIT_
Menuet_SegmentExit: Kolibri_SegmentExit:
end if end if
} }
macro endseg name macro endseg name
{ {
if name eq _init_ | name eq _INIT_ if name eq _init_ | name eq _INIT_
Menuet_SegmentInitEnd: Kolibri_SegmentInitEnd:
else if name eq _exit_ | name eq _EXIT_ else if name eq _exit_ | name eq _EXIT_
Menuet_SegmentExitEnd: Kolibri_SegmentExitEnd:
end if end if
endseg name endseg name
} }
macro Menuet_Put_MovEaxVal_Ret address,val macro Kolibri_Put_MovEaxVal_Ret address,val
{ {
mov byte [address],0xB8 mov byte [address],0xB8
mov dword [address+4],0xC089C300 mov dword [address+4],0xC089C300
@ -79,7 +79,7 @@ macro Menuet_Put_MovEaxVal_Ret address,val
proc @Kolibri@Main$qv proc @Kolibri@Main$qv
and esp,not 3 and esp,not 3
sub esp,1024 sub esp,1024
mov eax,9 mov eax,SF_THREAD_INFO
mov ebx,esp mov ebx,esp
mov ecx,-1 mov ecx,-1
int 0x40 int 0x40
@ -97,21 +97,21 @@ end if
cld cld
mov edi,@Kolibri@_ThreadTable mov edi,@Kolibri@_ThreadTable
mov ecx,256 mov ecx,256
rep stos dword [edi] rep stosd
mov esi,@Kolibri@GetPid$qv mov esi,@Kolibri@GetPid$qv
mov edi,@Kolibri@_ThreadSavedBegProc mov edi,@Kolibri@_ThreadSavedBegProc
movs dword [edi],[esi] movsd
movs dword [edi],[esi] movsd
mov esi,@Kolibri@GetThreadData$qv mov esi,@Kolibri@GetThreadData$qv
movs dword [edi],[esi] movsd
movs dword [edi],[esi] movsd
Menuet_Put_MovEaxVal_Ret @Kolibri@GetPid$qv,edx Kolibri_Put_MovEaxVal_Ret @Kolibri@GetPid$qv,edx
if defined MenuetHeapInit if defined KolibriHeapInit
mov ecx,esp mov ecx,esp
push ebx push ebx
push ecx push ecx
push U_END push U_END
call MenuetHeapInit ; Initialize a dynamic heap and create new memory in its begin. call KolibriHeapInit ; Initialize a dynamic heap and create new memory in its begin.
pop ecx ; Parameters: begin of a new heap, end of data to create in pop ecx ; Parameters: begin of a new heap, end of data to create in
mov [esp+4],eax ; the begin of a heap. Return address of the created data. mov [esp+4],eax ; the begin of a heap. Return address of the created data.
mov dword [esp],0 mov dword [esp],0
@ -123,12 +123,12 @@ end if
call @Kolibri@ThreadMain$qpvt1 call @Kolibri@ThreadMain$qpvt1
.ThreadFinish: .ThreadFinish:
add esp,8 add esp,8
if defined MenuetHeapFreeAndThreadFinish if defined KolibriHeapFreeAndThreadFinish
test eax,eax test eax,eax
jz .ThreadFinish_end jz .ThreadFinish_end
push dword @Kolibri@_ExitProcessNow push dword @Kolibri@_ExitProcessNow
push eax push eax
call MenuetHeapFreeAndThreadFinish ; Free the given memory and finish the thread, call KolibriHeapFreeAndThreadFinish ; Free the given memory and finish the thread,
end if ; should exit process if second argument points to not zero. end if ; should exit process if second argument points to not zero.
.ThreadFinish_end: .ThreadFinish_end:
or eax,-1 or eax,-1
@ -142,16 +142,16 @@ proc @Kolibri@ThreadMain$qpvt1
sub esp,KOLIBRI_THREAD_DATA_LEN*4 sub esp,KOLIBRI_THREAD_DATA_LEN*4
mov [esp],ebx mov [esp],ebx
mov [esp+4],ebp mov [esp+4],ebp
mov eax,40 mov eax,SF_SET_EVENTS_MASK
mov ebx,0x27 mov ebx,0x27
int 0x40 int 0x40
mov ebx,esp mov ebx,esp
cmp byte [@Kolibri@_ThreadSavedBegProc],0x90 cmp byte [@Kolibri@_ThreadSavedBegProc],0x90
jz .main_else_first_check jz .main_else_first_check
Menuet_Put_MovEaxVal_Ret @Kolibri@GetThreadData$qv,esp Kolibri_Put_MovEaxVal_Ret @Kolibri@GetThreadData$qv,esp
if defined Menuet_SegmentInit & defined Menuet_SegmentInitEnd if defined Kolibri_SegmentInit & defined Kolibri_SegmentInitEnd
push Menuet_SegmentInitEnd push Kolibri_SegmentInitEnd
push Menuet_SegmentInit push Kolibri_SegmentInit
jmp .main_after_first_check jmp .main_after_first_check
end if end if
.main_else_first_check: .main_else_first_check:
@ -166,11 +166,13 @@ end if
jmp .main_end jmp .main_end
.main_close_first: .main_close_first:
btr dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],31 btr dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],31
if defined @@KolibriOnClose$qppv
push esp push esp
call @@KolibriOnClose$qppv call @@KolibriOnClose$qppv
pop ecx pop ecx
test al,al test al,al
jnz .main_end jnz .main_end
end if
.main_test_close_first: .main_test_close_first:
cmp dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0 cmp dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0
jl .main_close_first jl .main_close_first
@ -181,7 +183,7 @@ end if
.main_paint_msg: .main_paint_msg:
or dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],3 or dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],3
sub esp,1024 sub esp,1024
mov eax,9 mov eax,SF_THREAD_INFO
mov ebx,esp mov ebx,esp
mov ecx,-1 mov ecx,-1
int 0x40 int 0x40
@ -197,6 +199,7 @@ end if
.main_size: .main_size:
mov [esp+KOLIBRI_THREAD_DATA_LAST_SX*4],ecx mov [esp+KOLIBRI_THREAD_DATA_LAST_SX*4],ecx
mov [esp+KOLIBRI_THREAD_DATA_LAST_SY*4],edx mov [esp+KOLIBRI_THREAD_DATA_LAST_SY*4],edx
if defined @@KolibriOnSize$qpippv
push edx push edx
push ecx push ecx
push ebx push ebx
@ -207,6 +210,7 @@ end if
push edx push edx
call @@KolibriOnSize$qpippv call @@KolibriOnSize$qpippv
add esp,24 add esp,24
end if
test dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],3 test dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],3
jz .main_cycle jz .main_cycle
.main_paint: .main_paint:
@ -217,7 +221,7 @@ end if
call @Kolibri@Redraw$qippv call @Kolibri@Redraw$qippv
add esp,8 add esp,8
.main_cycle: .main_cycle:
mov eax,11 mov eax,SF_CHECK_EVENT
.main_message: .main_message:
cmp dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0 cmp dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0
jl .main_close jl .main_close
@ -226,56 +230,86 @@ end if
jnz .main_on_message jnz .main_on_message
cmp dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0 cmp dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0
jne .main_paint jne .main_paint
if defined @@KolibriOnIdle$qppv
push esp push esp
call @@KolibriOnIdle$qppv call @@KolibriOnIdle$qppv
pop ecx pop ecx
else
or eax,-1
end if
test eax,eax test eax,eax
jz .main_cycle jz .main_cycle
jl .main_wait_message jl .main_wait_message
mov ebx,eax mov ebx,eax
mov eax,23 mov eax,SF_WAIT_EVENT_TIMEOUT
jmp .main_message jmp .main_message
.main_wait_message: .main_wait_message:
mov eax,10 mov eax,SF_WAIT_EVENT
jmp .main_message jmp .main_message
if defined @@KolibriOnKeyPress$qppv
.main_key_press: .main_key_press:
push esp push esp
call @@KolibriOnKeyPress$qppv call @@KolibriOnKeyPress$qppv
pop ecx pop ecx
jmp .main_cycle jmp .main_cycle
end if
if defined @@KolibriOnMouse$qppv
.main_mouse: .main_mouse:
push esp push esp
call @@KolibriOnMouse$qppv call @@KolibriOnMouse$qppv
pop ecx pop ecx
jmp .main_cycle jmp .main_cycle
end if
align 4
.main_on_message: .main_on_message:
dec eax dec eax
jz .main_paint_msg jz .main_paint_msg
dec eax dec eax
if defined @@KolibriOnKeyPress$qppv
jz .main_key_press jz .main_key_press
else
jz .main_cycle
end if
cmp eax,4 cmp eax,4
if defined @@KolibriOnMouse$qppv
jz .main_mouse jz .main_mouse
else
jz .main_cycle
end if
dec eax dec eax
jnz .main_cycle jnz .main_cycle
align 4
.main_button: .main_button:
mov eax,17 mov eax,SF_GET_BUTTON
int 0x40 int 0x40
test al,al shr eax,8
jnz .main_cycle cmp eax,1
je .main_close
if defined @@KolibriOnButton$qlppv
push esp
push eax
call @@KolibriOnButton$qlppv
add esp,8
end if
jmp .main_cycle
.main_close: .main_close:
btr dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],31 btr dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],31
if defined @@KolibriOnClose$qppv
push esp push esp
call @@KolibriOnClose$qppv call @@KolibriOnClose$qppv
pop ecx pop ecx
test al,al test al,al
jz .main_button jz .main_button
end if
.main_end: .main_end:
mov ebx,esp mov ebx,esp
lock dec dword [@Kolibri@_ThreadNumber] lock dec dword [@Kolibri@_ThreadNumber]
if defined Menuet_SegmentExit & defined Menuet_SegmentExitEnd if defined Kolibri_SegmentExit & defined Kolibri_SegmentExitEnd
jnz .main_else_last_check jnz .main_else_last_check
push Menuet_SegmentExitEnd push Kolibri_SegmentExitEnd
push Menuet_SegmentExit push Kolibri_SegmentExit
jmp .main_after_last_check jmp .main_after_last_check
end if end if
.main_else_last_check: .main_else_last_check:
@ -290,12 +324,12 @@ end if
mov ebx,1 mov ebx,1
jmp .main_end_wait jmp .main_end_wait
.main_end_wait_loop: .main_end_wait_loop:
mov eax,5 mov eax,SF_SLEEP
int 0x40 int 0x40
shl ebx,1 shl ebx,1
cmp ebx,MENUET_MUTEX_MAX_TIME_WAIT cmp ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
jna .main_end_wait jna .main_end_wait
mov ebx,MENUET_MUTEX_MAX_TIME_WAIT mov ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
.main_end_wait: .main_end_wait:
cmp dword [@Kolibri@_ExitProcessNow],0 cmp dword [@Kolibri@_ExitProcessNow],0
jnz @Kolibri@ExitProcess$qv jnz @Kolibri@ExitProcess$qv
@ -346,8 +380,8 @@ proc @Kolibri@Redraw$qippv
and dword [ebp+KOLIBRI_THREAD_DATA_FLAG*4],0xFFFFFFFC and dword [ebp+KOLIBRI_THREAD_DATA_FLAG*4],0xFFFFFFFC
test dl,2 test dl,2
jz .redraw_picture jz .redraw_picture
mov eax,12 mov eax,SF_REDRAW
mov ebx,1 mov ebx,SSF_BEGIN_DRAW
int 0x40 int 0x40
xor eax,eax xor eax,eax
mov ebx,[ebp+KOLIBRI_THREAD_DATA_X*4] mov ebx,[ebp+KOLIBRI_THREAD_DATA_X*4]
@ -368,17 +402,14 @@ proc @Kolibri@Redraw$qippv
mov esi,ecx mov esi,ecx
dec esi dec esi
jz .window_defined jz .window_defined
mov eax,4 mov eax,SF_DRAW_TEXT
mov ebx,0x00070007 mov ebx,0x00070007
mov ecx,[ebp+KOLIBRI_THREAD_DATA_C_TITLE*4] mov ecx,[ebp+KOLIBRI_THREAD_DATA_C_TITLE*4]
int 0x40 int 0x40
.window_defined: .window_defined:
mov eax,12
mov ebx,2
int 0x40
.redraw_picture: .redraw_picture:
mov eax,12 mov eax,SF_REDRAW
mov ebx,2 mov ebx,SSF_END_DRAW
int 0x40 int 0x40
mov esi,[ebp+KOLIBRI_THREAD_DATA_PICTURE*4] mov esi,[ebp+KOLIBRI_THREAD_DATA_PICTURE*4]
test esi,esi test esi,esi
@ -387,15 +418,15 @@ proc @Kolibri@Redraw$qippv
jecxz .redraw_end_draw jecxz .redraw_end_draw
mov al,byte [ebp+KOLIBRI_THREAD_DATA_C_WINDOW*4+3] mov al,byte [ebp+KOLIBRI_THREAD_DATA_C_WINDOW*4+3]
and al,15 and al,15
mov edx,MENUET_BORDER_SIZE*65536+MENUET_HEADER_SIZE mov edx,KOLIBRI_BORDER_SIZE*65536+KOLIBRI_HEADER_SIZE
cmp al,3 cmp al,3
jnz .redraw_no_skin jnz .redraw_no_skin
mov eax,48 mov eax,SF_STYLE_SETTINGS
mov ebx,4 mov ebx,SSF_GET_SKIN_HEIGHT
int 0x40 int 0x40
mov dx,ax mov dx,ax
.redraw_no_skin: .redraw_no_skin:
mov eax,7 mov eax,SF_PUT_IMAGE
mov ebx,esi mov ebx,esi
int 0x40 int 0x40
.redraw_end_draw: .redraw_end_draw:
@ -409,29 +440,32 @@ proc @Kolibri@MoveWindow$qxpxi uses ebx esi
mov ecx,[eax+4] mov ecx,[eax+4]
mov edx,[eax+8] mov edx,[eax+8]
mov esi,[eax+12] mov esi,[eax+12]
mov eax,67 mov eax,SF_CHANGE_WINDOW
int 0x40 int 0x40
ret ret
endp endp
;proc @Kolibri@Abort$qv proc @Kolibri@ExitDebug$qv
; push dword [@Kolibri@DebugPrefix] push dword [@Kolibri@DebugPrefix]
; call @Kolibri@DebugPutString$qpxc call @Kolibri@DebugPutString$qpxc
; mov dword [esp],Menuet_abort_string mov dword [esp],Kolibri_debug_string
; call @Kolibri@DebugPutString$qpxc call @Kolibri@DebugPutString$qpxc
; pop ecx pop ecx
jmp @Kolibri@ExitProcess$qv
endp
proc @Kolibri@ExitProcess$qv proc @Kolibri@ExitProcess$qv
lock bts dword [@Kolibri@_ExitProcessNow],0 lock bts dword [@Kolibri@_ExitProcessNow],0
jc .exit_process_wait jc .exit_process_wait
sub esp,1024 sub esp,1024
mov eax,9 mov eax,SF_THREAD_INFO
mov ebx,esp mov ebx,esp
mov ecx,-1 mov ecx,-1
int 0x40 int 0x40
mov esi,eax mov esi,eax
mov edi,[esp+30] mov edi,[esp+30]
.exit_process_loop: .exit_process_loop:
mov eax,9 mov eax,SF_THREAD_INFO
mov ebx,esp mov ebx,esp
mov ecx,esi mov ecx,esi
int 0x40 int 0x40
@ -443,7 +477,7 @@ proc @Kolibri@ExitProcess$qv
inc ebx inc ebx
jz .exit_process_continue jz .exit_process_continue
mov ebx,eax mov ebx,eax
call Menuet_HashInt call Kolibri_HashInt
movzx eax,al movzx eax,al
mov eax,dword [@Kolibri@_ThreadTable+eax*4] mov eax,dword [@Kolibri@_ThreadTable+eax*4]
jmp .exit_process_test jmp .exit_process_test
@ -454,8 +488,8 @@ proc @Kolibri@ExitProcess$qv
jz .exit_process_continue jz .exit_process_continue
cmp ebx,[eax+KOLIBRI_THREAD_DATA_PID*4] cmp ebx,[eax+KOLIBRI_THREAD_DATA_PID*4]
jnz .exit_process_next jnz .exit_process_next
mov eax,18 mov eax,SF_SYSTEM
mov ebx,2 mov ebx,SSF_TERMINATE_THREAD
mov ecx,esi mov ecx,esi
int 0x40 int 0x40
.exit_process_continue: .exit_process_continue:
@ -472,53 +506,65 @@ end if
or eax,-1 or eax,-1
int 0x40 int 0x40
.exit_process_wait: .exit_process_wait:
mov eax,5 mov eax,SF_SLEEP
mov ebx,1 mov ebx,1
.exit_process_wait_loop: .exit_process_wait_loop:
cmp dword [@Kolibri@_ExitProcessNow],0 cmp dword [@Kolibri@_ExitProcessNow],0
jl .exit_process_end jl .exit_process_end
int 0x40 int 0x40
shl ebx,1 shl ebx,1
cmp ebx,MENUET_MUTEX_MAX_TIME_WAIT cmp ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
jna .exit_process_wait_loop jna .exit_process_wait_loop
mov ebx,MENUET_MUTEX_MAX_TIME_WAIT mov ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
jmp .exit_process_wait_loop jmp .exit_process_wait_loop
endp endp
proc @Kolibri@ExitThread$qppv,@Kolibri@ThreadMain$qpvt1 proc @Kolibri@ExitThread$qppv,@Kolibri@ThreadMain$qpvt1
mov esp,[esp+4] mov esp,[esp+4]
jmp Menuet_main_end jmp Kolibri_main_end
endp endp
proc @Kolibri@ReturnMessageLoop$qppv,@Kolibri@ThreadMain$qpvt1 proc @Kolibri@ReturnMessageLoop$qppv,@Kolibri@ThreadMain$qpvt1
mov esp,[esp+4] mov esp,[esp+4]
bt dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],30 bt dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],30
jc Menuet_main_end jc Kolibri_main_end
jmp Menuet_main_cycle jmp Kolibri_main_cycle
endp endp
proc @Kolibri@Delay$qui uses ebx proc @Kolibri@Delay$qui uses ebx
mov eax,5 mov eax,SF_SLEEP
mov ebx,[esp+8] mov ebx,[esp+8]
int 0x40 int 0x40
ret ret
endp endp
proc @Kolibri@Clock$qv uses ebx proc @Kolibri@Clock$qv uses ebx
mov eax,26 mov eax,SF_SYSTEM_GET
mov ebx,9 mov ebx,SSF_TIME_COUNT
int 0x40 int 0x40
ret ret
endp endp
proc @Kolibri@DrawButton$qllllll uses ebx esi
mov eax,SF_DEFINE_BUTTON
mov ebx,[esp+12-2+8]
mov bx,[esp+20+8]
mov ecx,[esp+16-2+8]
mov cx,[esp+24+8]
mov edx,[esp+4+8]
mov esi,[esp+8+8]
int 0x40
ret
endp
proc @Kolibri@GetPackedTime$qv proc @Kolibri@GetPackedTime$qv
mov eax,3 mov eax,SF_GET_SYS_TIME
int 0x40 int 0x40
ret ret
endp endp
proc @Kolibri@GetTime$qpi proc @Kolibri@GetTime$qpi
mov eax,3 mov eax,SF_GET_SYS_TIME
int 0x40 int 0x40
mov edx,[esp+4] mov edx,[esp+4]
movzx ecx,al movzx ecx,al
@ -544,13 +590,13 @@ proc @Kolibri@GetTime$qpi
endp endp
proc @Kolibri@GetPackedDate$qv proc @Kolibri@GetPackedDate$qv
mov eax,29 mov eax,SF_GET_SYS_DATE
int 0x40 int 0x40
ret ret
endp endp
proc @Kolibri@GetDate$qpi proc @Kolibri@GetDate$qpi
mov eax,29 mov eax,SF_GET_SYS_DATE
int 0x40 int 0x40
mov edx,[esp+4] mov edx,[esp+4]
movzx ecx,al movzx ecx,al
@ -576,8 +622,8 @@ proc @Kolibri@GetDate$qpi
endp endp
proc @Kolibri@ReadCommonColors$qpui uses ebx proc @Kolibri@ReadCommonColors$qpui uses ebx
mov eax,48 mov eax,SF_STYLE_SETTINGS
mov ebx,3 mov ebx,SSF_GET_COLORS
mov ecx,[esp+8] mov ecx,[esp+8]
mov edx,40 mov edx,40
int 0x40 int 0x40
@ -585,7 +631,7 @@ proc @Kolibri@ReadCommonColors$qpui uses ebx
endp endp
proc @Kolibri@DrawText$qssipxc uses ebx proc @Kolibri@DrawText$qssipxc uses ebx
mov eax,4 mov eax,SF_DRAW_TEXT
mov ebx,[esp+8-2] mov ebx,[esp+8-2]
mov bx,[esp+12] mov bx,[esp+12]
mov ecx,[esp+16] mov ecx,[esp+16]
@ -595,9 +641,17 @@ proc @Kolibri@DrawText$qssipxc uses ebx
ret ret
endp endp
proc @Kolibri@SetWindowCaption$qpxc uses ebx
mov eax,SF_SET_CAPTION
mov ebx,2
mov ecx,[esp+8]
int 0x40
ret
endp
proc @Kolibri@GetProcessInfo$qpuipct1t1piui uses ebx esi edi proc @Kolibri@GetProcessInfo$qpuipct1t1piui uses ebx esi edi
sub esp,1024 sub esp,1024
mov eax,9 mov eax,SF_THREAD_INFO
mov ebx,esp mov ebx,esp
mov ecx,[1024+12+24+esp] mov ecx,[1024+12+24+esp]
int 0x40 int 0x40
@ -612,9 +666,9 @@ proc @Kolibri@GetProcessInfo$qpuipct1t1piui uses ebx esi edi
jz .get_proc_info_no_name jz .get_proc_info_no_name
lea esi,[esp+10] lea esi,[esp+10]
cld cld
movs dword [edi],[esi] movsd
movs dword [edi],[esi] movsd
movs dword [edi],[esi] movsd
mov byte [edi],0 mov byte [edi],0
xor edi,edi xor edi,edi
.get_proc_info_no_name: .get_proc_info_no_name:
@ -634,10 +688,10 @@ proc @Kolibri@GetProcessInfo$qpuipct1t1piui uses ebx esi edi
jz .get_proc_info_no_rect jz .get_proc_info_no_rect
lea esi,[esp+34] lea esi,[esp+34]
cld cld
movs dword [edi],[esi] movsd
movs dword [edi],[esi] movsd
movs dword [edi],[esi] movsd
movs dword [edi],[esi] movsd
xor edi,edi xor edi,edi
.get_proc_info_no_rect: .get_proc_info_no_rect:
add esp,1024 add esp,1024
@ -646,7 +700,7 @@ endp
proc @Kolibri@GetPid$qv uses ebx proc @Kolibri@GetPid$qv uses ebx
sub esp,1024 sub esp,1024
mov eax,9 mov eax,SF_THREAD_INFO
mov ebx,esp mov ebx,esp
mov ecx,-1 mov ecx,-1
int 0x40 int 0x40
@ -665,11 +719,11 @@ proc @Kolibri@_HashByte$qui
@Kolibri@_HashWord$qui: @Kolibri@_HashWord$qui:
@Kolibri@_HashDword$qui: @Kolibri@_HashDword$qui:
mov eax,[esp+4] mov eax,[esp+4]
Menuet_HashInt: Kolibri_HashInt:
mul dword [Menuet_hash_int_val0] mul dword [Kolibri_hash_int_val0]
xor eax,edx xor eax,edx
bswap eax bswap eax
mul dword [Menuet_hash_int_val1] mul dword [Kolibri_hash_int_val1]
shrd eax,edx,14 shrd eax,edx,14
bswap eax bswap eax
lea eax,[eax+4*eax] lea eax,[eax+4*eax]
@ -677,10 +731,12 @@ Menuet_HashInt:
ret ret
endp endp
Menuet_hash_int_val0: if defined @Kolibri@_HashByte$qui | defined @Kolibri@_HashWord$qui | defined @Kolibri@_HashDword$qui
Kolibri_hash_int_val0:
dd 0xA82F94C5 dd 0xA82F94C5
Menuet_hash_int_val1: Kolibri_hash_int_val1:
dd 0x9193780B dd 0x9193780B
end if
proc @Kolibri@GetThreadData$qv proc @Kolibri@GetThreadData$qv
call @Kolibri@GetPid$qv call @Kolibri@GetPid$qv
@ -692,7 +748,7 @@ endp
proc @Kolibri@GetThreadData$qui proc @Kolibri@GetThreadData$qui
mov eax,[esp+4] mov eax,[esp+4]
call Menuet_HashInt call Kolibri_HashInt
movzx eax,al movzx eax,al
cmp dword [@Kolibri@_ThreadScanCount+4],0 cmp dword [@Kolibri@_ThreadScanCount+4],0
jnz .get_thread_data_wait jnz .get_thread_data_wait
@ -713,16 +769,16 @@ proc @Kolibri@GetThreadData$qui
ret ret
.get_thread_data_wait: .get_thread_data_wait:
push eax ebx push eax ebx
mov eax,5 mov eax,SF_SLEEP
mov ebx,1 mov ebx,1
.get_thread_data_wait_loop: .get_thread_data_wait_loop:
int 0x40 int 0x40
cmp dword [@Kolibri@_ThreadScanCount+4],0 cmp dword [@Kolibri@_ThreadScanCount+4],0
jz .get_thread_data_wait_end jz .get_thread_data_wait_end
shl ebx,1 shl ebx,1
cmp ebx,MENUET_MUTEX_MAX_TIME_WAIT cmp ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
jna .get_thread_data_wait_loop jna .get_thread_data_wait_loop
mov ebx,MENUET_MUTEX_MAX_TIME_WAIT mov ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
jmp .get_thread_data_wait_loop jmp .get_thread_data_wait_loop
.get_thread_data_wait_end: .get_thread_data_wait_end:
pop ebx eax pop ebx eax
@ -730,14 +786,14 @@ proc @Kolibri@GetThreadData$qui
endp endp
proc @Kolibri@_GetSkinHeader$qv uses ebx proc @Kolibri@_GetSkinHeader$qv uses ebx
mov eax,48 mov eax,SF_STYLE_SETTINGS
mov ebx,4 mov ebx,SSF_GET_SKIN_HEIGHT
int 0x40 int 0x40
ret ret
endp endp
proc @Kolibri@GetScreenSize$qrust1 proc @Kolibri@GetScreenSize$qrust1
mov eax,14 mov eax,SF_GET_SCREEN_SIZE
int 0x40 int 0x40
mov ecx,[esp+8] mov ecx,[esp+8]
mov word [ecx],ax mov word [ecx],ax
@ -747,14 +803,14 @@ proc @Kolibri@GetScreenSize$qrust1
ret ret
endp endp
proc Menuet_MutexLockNoWait proc Kolibri_MutexLockNoWait
pop eax pop eax
xor al,al xor al,al
ret ret
endp endp
proc Menuet_MutexLockWait uses ebx proc Kolibri_MutexLockWait uses ebx
mov eax,5 mov eax,SF_SLEEP
xor ebx,ebx xor ebx,ebx
.lock_wait_cycle: .lock_wait_cycle:
int 0x40 int 0x40
@ -764,23 +820,23 @@ proc Menuet_MutexLockWait uses ebx
ret ret
endp endp
proc Menuet_MutexLockWaitTime proc Kolibri_MutexLockWaitTime
cmp dword [esp+12],0 cmp dword [esp+12],0
jng .MutexLockWait jng .MutexLockWait
push ebx edx push ebx edx
mov edx,[esp+20] mov edx,[esp+20]
mov eax,26 mov eax,SF_SYSTEM_GET
mov ebx,9 mov ebx,SSF_TIME_COUNT
int 0x40 int 0x40
add edx,eax add edx,eax
.lock_wait_time_cycle: .lock_wait_time_cycle:
mov eax,5 mov eax,SF_SLEEP
xor ebx,ebx xor ebx,ebx
int 0x40 int 0x40
shl byte [ecx],1 shl byte [ecx],1
jnz .lock_wait_time_ret_true jnz .lock_wait_time_ret_true
mov eax,26 mov eax,SF_SYSTEM_GET
mov ebx,9 mov ebx,SSF_TIME_COUNT
int 0x40 int 0x40
cmp eax,edx cmp eax,edx
js .lock_wait_time_cycle js .lock_wait_time_cycle
@ -793,7 +849,7 @@ proc Menuet_MutexLockWaitTime
ret ret
endp endp
proc Menuet_MutexLock proc Kolibri_MutexLock
shl byte [ecx],1 shl byte [ecx],1
jnz .lock_first jnz .lock_first
call eax call eax
@ -803,21 +859,21 @@ proc Menuet_MutexLock
endp endp
proc @Kolibri@TryLock$qp14Kolibri@TMutex proc @Kolibri@TryLock$qp14Kolibri@TMutex
mov eax,Menuet_MutexLockNoWait mov eax,Kolibri_MutexLockNoWait
mov ecx,[esp+4] mov ecx,[esp+4]
jmp Menuet_MutexLock jmp Kolibri_MutexLock
endp endp
proc @Kolibri@Lock$qp14Kolibri@TMutex proc @Kolibri@Lock$qp14Kolibri@TMutex
mov eax,Menuet_MutexLockWait mov eax,Kolibri_MutexLockWait
mov ecx,[esp+4] mov ecx,[esp+4]
jmp Menuet_MutexLock jmp Kolibri_MutexLock
endp endp
proc @Kolibri@LockTime$qp14Kolibri@TMutexi proc @Kolibri@LockTime$qp14Kolibri@TMutexi
mov eax,Menuet_MutexLockWaitTime mov eax,Kolibri_MutexLockWaitTime
mov ecx,[esp+4] mov ecx,[esp+4]
jmp Menuet_MutexLock jmp Kolibri_MutexLock
endp endp
proc @Kolibri@UnLock$qp14Kolibri@TMutex proc @Kolibri@UnLock$qp14Kolibri@TMutex
@ -828,14 +884,14 @@ proc @Kolibri@UnLock$qp14Kolibri@TMutex
.unlock_pause: .unlock_pause:
mov byte [ecx],0x40 mov byte [ecx],0x40
push ebx push ebx
mov eax,5 mov eax,SF_SLEEP
xor ebx,ebx xor ebx,ebx
int 0x40 int 0x40
pop ebx pop ebx
ret ret
endp endp
proc Menuet_MutexLockRec proc Kolibri_MutexLockRec
shl byte [ecx],1 shl byte [ecx],1
jng .lock_first jng .lock_first
cmp dword [ecx+4],edx cmp dword [ecx+4],edx
@ -853,31 +909,31 @@ proc Menuet_MutexLockRec
.lock_rec_overflow: .lock_rec_overflow:
push dword [@Kolibri@DebugPrefix] push dword [@Kolibri@DebugPrefix]
call @Kolibri@DebugPutString$qpxc call @Kolibri@DebugPutString$qpxc
mov dword [esp],Menuet_try_lock_rec_overflow_string mov dword [esp],Kolibri_try_lock_rec_overflow_string
call @Kolibri@DebugPutString$qpxc call @Kolibri@DebugPutString$qpxc
pop ecx pop ecx
jmp @Kolibri@Abort$qv jmp @Kolibri@ExitDebug$qv
endp endp
proc @Kolibri@TryLock$qp16Kolibri@TRecMutexui proc @Kolibri@TryLock$qp16Kolibri@TRecMutexui
mov eax,Menuet_MutexLockNoWait mov eax,Kolibri_MutexLockNoWait
mov ecx,[esp+4] mov ecx,[esp+4]
mov edx,[esp+8] mov edx,[esp+8]
jmp Menuet_MutexLockRec jmp Kolibri_MutexLockRec
endp endp
proc @Kolibri@Lock$qp16Kolibri@TRecMutexui proc @Kolibri@Lock$qp16Kolibri@TRecMutexui
mov eax,Menuet_MutexLockWait mov eax,Kolibri_MutexLockWait
mov ecx,[esp+4] mov ecx,[esp+4]
mov edx,[esp+8] mov edx,[esp+8]
jmp Menuet_MutexLockRec jmp Kolibri_MutexLockRec
endp endp
proc @Kolibri@LockTime$qp16Kolibri@TRecMutexiui proc @Kolibri@LockTime$qp16Kolibri@TRecMutexiui
mov eax,Menuet_MutexLockWaitTime mov eax,Kolibri_MutexLockWaitTime
mov ecx,[esp+4] mov ecx,[esp+4]
mov edx,[esp+12] mov edx,[esp+12]
jmp Menuet_MutexLockRec jmp Kolibri_MutexLockRec
endp endp
proc @Kolibri@UnLock$qp16Kolibri@TRecMutexui proc @Kolibri@UnLock$qp16Kolibri@TRecMutexui
@ -896,7 +952,7 @@ proc @Kolibri@UnLock$qp16Kolibri@TRecMutexui
.unlock_rec_pause: .unlock_rec_pause:
mov byte [ecx],0x20 mov byte [ecx],0x20
push ebx push ebx
mov eax,5 mov eax,SF_SLEEP
xor ebx,ebx xor ebx,ebx
int 0x40 int 0x40
pop ebx pop ebx
@ -904,10 +960,10 @@ proc @Kolibri@UnLock$qp16Kolibri@TRecMutexui
.unlock_rec_notlocked: .unlock_rec_notlocked:
push dword [@Kolibri@DebugPrefix] push dword [@Kolibri@DebugPrefix]
call @Kolibri@DebugPutString$qpxc call @Kolibri@DebugPutString$qpxc
mov dword [esp],Menuet_unlock_rec_notlocked_string mov dword [esp],Kolibri_unlock_rec_notlocked_string
call @Kolibri@DebugPutString$qpxc call @Kolibri@DebugPutString$qpxc
pop ecx pop ecx
jmp @Kolibri@Abort$qv jmp @Kolibri@ExitDebug$qv
endp endp
proc @Kolibri@DebugPutChar$qc proc @Kolibri@DebugPutChar$qc
@ -918,23 +974,22 @@ proc @Kolibri@DebugPutChar$qc
cmp cl,10 cmp cl,10
jz .debug_put_char_enter jz .debug_put_char_enter
.debug_put_char_after_cmp: .debug_put_char_after_cmp:
mov eax,63 mov eax,SF_BOARD
mov ebx,1 mov ebx,SSF_DEBUG_WRITE
int 0x40 int 0x40
pop ebx pop ebx
.debug_put_char_ret: .debug_put_char_ret:
ret ret
.debug_put_char_enter: .debug_put_char_enter:
mov cl,13 mov cl,13
mov eax,63 mov eax,SF_BOARD
mov ebx,1 mov ebx,SSF_DEBUG_WRITE
int 0x40 int 0x40
mov cl,10 mov cl,10
jmp .debug_put_char_after_cmp jmp .debug_put_char_after_cmp
endp endp
proc @Kolibri@DebugPutString$qpxc proc @Kolibri@DebugPutString$qpxc uses esi
push esi
push dword 0 push dword 0
mov esi,dword [esp+12] mov esi,dword [esp+12]
jmp .debug_put_string_test jmp .debug_put_string_test
@ -947,32 +1002,32 @@ proc @Kolibri@DebugPutString$qpxc
or al,[esi] or al,[esi]
test al,al test al,al
jnz .debug_put_string_loop jnz .debug_put_string_loop
pop ecx esi pop ecx
ret ret
endp endp
proc @Kolibri@GetKey$qv proc @Kolibri@GetKey$qv
mov eax,2 mov eax,SF_GET_KEY
int 0x40 int 0x40
test al,al test al,al
jnz .get_key_eof jnz .get_key_eof
movzx eax,ah movzx eax,ah
ret ret
.get_key_eof: .get_key_eof:
mov eax,-1 mov eax,SF_TERMINATE_PROCESS
ret ret
endp endp
proc @Kolibri@GetMouseButton$qv uses ebx proc @Kolibri@GetMouseButton$qv uses ebx
mov eax,37 mov eax,SF_MOUSE_GET
mov ebx,2 mov ebx,SSF_BUTTON
int 0x40 int 0x40
ret ret
endp endp
proc @Kolibri@GetMousePosition$qrst1o uses ebx proc @Kolibri@GetMousePosition$qrst1o uses ebx
mov eax,37 mov eax,SF_MOUSE_GET
xor ebx,ebx xor ebx,ebx ;SSF_SCREEN_POSITION
cmp byte [esp+16],0 cmp byte [esp+16],0
jnz .get_mouse_pos_absolute jnz .get_mouse_pos_absolute
inc ebx inc ebx
@ -998,13 +1053,13 @@ proc @Kolibri@CreateThread$qpvuit1
mov ebx,[esp+12] mov ebx,[esp+12]
test edx,edx test edx,edx
jnz .create_thread_after_new jnz .create_thread_after_new
if defined MenuetHeapAlloc if defined KolibriHeapAlloc
cmp ebx,4096 cmp ebx,4096
jnb .create_thread_alloc jnb .create_thread_alloc
mov ebx,STACKSIZE mov ebx,STACKSIZE
.create_thread_alloc: .create_thread_alloc:
push ebx push ebx
call MenuetHeapAlloc ; Create new dynamic memory of the given size call KolibriHeapAlloc ; Create new dynamic memory of the given size
pop ecx pop ecx
test eax,eax test eax,eax
jnz .create_thread_mem_created jnz .create_thread_mem_created
@ -1027,8 +1082,8 @@ end if
mov ecx,[esp+8] mov ecx,[esp+8]
mov dword [edx+8],ebx mov dword [edx+8],ebx
mov dword [edx+4],ecx mov dword [edx+4],ecx
mov dword [edx],Menuet_ThreadFinish mov dword [edx],Kolibri_ThreadFinish
mov eax,51 mov eax,SF_CREATE_THREAD
mov ebx,1 mov ebx,1
mov ecx,@Kolibri@ThreadMain$qpvt1 mov ecx,@Kolibri@ThreadMain$qpvt1
int 0x40 int 0x40
@ -1037,11 +1092,11 @@ end if
inc ebx inc ebx
jnz .create_thread_end jnz .create_thread_end
lock dec dword [@Kolibri@_ThreadNumber] lock dec dword [@Kolibri@_ThreadNumber]
if defined MenuetHeapFree if defined KolibriHeapFree
or ebx,[edx+8] or ebx,[edx+8]
jz .create_thread_end jz .create_thread_end
push ebx push ebx
call MenuetHeapFree ; Delete the given dynamic memory call KolibriHeapFree ; Delete the given dynamic memory
pop ecx pop ecx
end if end if
.create_thread_end: .create_thread_end:
@ -1052,23 +1107,23 @@ end if
cld cld
mov esi,@Kolibri@_ThreadSavedBegProc mov esi,@Kolibri@_ThreadSavedBegProc
mov edi,@Kolibri@GetPid$qv mov edi,@Kolibri@GetPid$qv
movs dword [edi],[esi] movsd
movs dword [edi],[esi] movsd
mov edi,@Kolibri@GetThreadData$qv mov edi,@Kolibri@GetThreadData$qv
movs dword [edi],[esi] movsd
movs dword [edi],[esi] movsd
mov eax,0x90909090 mov eax,0x90909090
mov edi,@Kolibri@_ThreadSavedBegProc mov edi,@Kolibri@_ThreadSavedBegProc
stos dword [edi] stosd
stos dword [edi] stosd
stos dword [edi] stosd
stos dword [edi] stosd
pop edi esi pop edi esi
jmp .create_thread_fill_stack jmp .create_thread_fill_stack
endp endp
proc @Kolibri@_FileAccess$qpv uses ebx proc @Kolibri@_FileAccess$qpv uses ebx
mov eax,70 mov eax,SF_FILE
mov ebx,[esp+8] mov ebx,[esp+8]
int 0x40 int 0x40
mov ecx,[esp+8] mov ecx,[esp+8]
@ -1076,12 +1131,20 @@ proc @Kolibri@_FileAccess$qpv uses ebx
ret ret
endp endp
Menuet_abort_string: if defined Kolibri_debug_string
Kolibri_debug_string:
db 'Abnormal program termination.',10,0 db 'Abnormal program termination.',10,0
Menuet_try_lock_rec_overflow_string: end if
if defined Kolibri_MutexLockRec
Kolibri_try_lock_rec_overflow_string:
db 'Recursive mutex lock count overflow.',10,0 db 'Recursive mutex lock count overflow.',10,0
Menuet_unlock_rec_notlocked_string: end if
if defined @Kolibri@UnLock$qp16Kolibri@TRecMutexui
Kolibri_unlock_rec_notlocked_string:
db 'Recursive mutex unlock error.',10,0 db 'Recursive mutex unlock error.',10,0
end if
include "kos_lib.inc" include "kos_lib.inc"

View File

@ -1,5 +1,5 @@
#ifndef __MENUET_HEAP_H_INCLUDED_ #ifndef __KOLIBRI_HEAP_H_INCLUDED_
#define __MENUET_HEAP_H_INCLUDED_ #define __KOLIBRI_HEAP_H_INCLUDED_
#include <kolibri.h> #include <kolibri.h>
#include <memheap.h> #include <memheap.h>
@ -13,29 +13,29 @@ namespace Kolibri // All kolibri functions, types and data are nested in the (
void Free(void *mem); void Free(void *mem);
} }
#ifdef __MENUET__ #ifdef __KOLIBRI__
namespace Kolibri namespace Kolibri
{ {
// Global variables // Global variables
MemoryHeap::TFreeSpace _MenuetFreeSpace; MemoryHeap::TFreeSpace _KolibriFreeSpace;
MemoryHeap::TMemBlock _MenuetMemBlock; MemoryHeap::TMemBlock _KolibriMemBlock;
TMutex _MemHeapMutex = MENUET_MUTEX_INIT; TMutex _MemHeapMutex = KOLIBRI_MUTEX_INIT;
// Functions // Functions
void *_HeapInit(void *begin, void *use_end, void *end) void *_HeapInit(void *begin, void *use_end, void *end)
{ {
MemoryHeap::InitFreeSpace(_MenuetFreeSpace); MemoryHeap::InitFreeSpace(_KolibriFreeSpace);
_MenuetMemBlock = MemoryHeap::CreateBlock(begin, end, _MenuetFreeSpace); _KolibriMemBlock = MemoryHeap::CreateBlock(begin, end, _KolibriFreeSpace);
unsigned int use_beg = (unsigned int)MemoryHeap::BlockBegin(_MenuetMemBlock) + unsigned int use_beg = (unsigned int)MemoryHeap::BlockBegin(_KolibriMemBlock) +
MemoryHeap::BlockAddSize - MemoryHeap::BlockEndSize; MemoryHeap::BlockAddSize - MemoryHeap::BlockEndSize;
unsigned int use_size = (unsigned int)use_end; unsigned int use_size = (unsigned int)use_end;
if (use_size <= use_beg) return 0; if (use_size <= use_beg) return 0;
else use_size -= use_beg; else use_size -= use_beg;
return MemoryHeap::Alloc(_MenuetFreeSpace, use_size); return MemoryHeap::Alloc(_KolibriFreeSpace, use_size);
} }
bool _SetUseMemory(unsigned int use_mem); bool _SetUseMemory(unsigned int use_mem);
@ -46,13 +46,13 @@ namespace Kolibri
{ {
if (!size) return 0; if (!size) return 0;
Lock(&_MemHeapMutex); Lock(&_MemHeapMutex);
void *res = MemoryHeap::Alloc(_MenuetFreeSpace, size); void *res = MemoryHeap::Alloc(_KolibriFreeSpace, size);
if (!res) if (!res)
{ {
unsigned use_mem = (unsigned int)MemoryHeap::BlockEndFor(_MenuetMemBlock, size); unsigned use_mem = (unsigned int)MemoryHeap::BlockEndFor(_KolibriMemBlock, size);
if (_SetUseMemory(_RecalculateUseMemory(use_mem))) if (_SetUseMemory(_RecalculateUseMemory(use_mem)))
{ {
res = MemoryHeap::Alloc(_MenuetFreeSpace, size); res = MemoryHeap::Alloc(_KolibriFreeSpace, size);
} }
} }
UnLock(&_MemHeapMutex); UnLock(&_MemHeapMutex);
@ -62,13 +62,13 @@ namespace Kolibri
void *ReAlloc(void *mem, unsigned int size) void *ReAlloc(void *mem, unsigned int size)
{ {
Lock(&_MemHeapMutex); Lock(&_MemHeapMutex);
void *res = MemoryHeap::ReAlloc(_MenuetFreeSpace, mem, size); void *res = MemoryHeap::ReAlloc(_KolibriFreeSpace, mem, size);
if (!res && size) if (!res && size)
{ {
unsigned use_mem = (unsigned int)MemoryHeap::BlockEndFor(_MenuetMemBlock, size); unsigned use_mem = (unsigned int)MemoryHeap::BlockEndFor(_KolibriMemBlock, size);
if (_SetUseMemory(_RecalculateUseMemory(use_mem))) if (_SetUseMemory(_RecalculateUseMemory(use_mem)))
{ {
res = MemoryHeap::ReAlloc(_MenuetFreeSpace, mem, size); res = MemoryHeap::ReAlloc(_KolibriFreeSpace, mem, size);
} }
} }
UnLock(&_MemHeapMutex); UnLock(&_MemHeapMutex);
@ -78,13 +78,13 @@ namespace Kolibri
void Free(void *mem) void Free(void *mem)
{ {
Lock(&_MemHeapMutex); Lock(&_MemHeapMutex);
MemoryHeap::Free(_MenuetFreeSpace, mem); MemoryHeap::Free(_KolibriFreeSpace, mem);
UnLock(&_MemHeapMutex); UnLock(&_MemHeapMutex);
} }
void _FreeAndThreadFinish(void *mem, int *exit_proc_now); void _FreeAndThreadFinish(void *mem, int *exit_proc_now);
} }
#endif // def __MENUET__ #endif // def __KOLIBRI__
#endif // ndef __MENUET_HEAP_H_INCLUDED_ #endif // ndef __KOLIBRI_HEAP_H_INCLUDED_

View File

@ -1,14 +1,14 @@
;/*** ;/***
MenuetHeapInit = @@Kolibri@_HeapInit$qpvt1t1 KolibriHeapInit = @@Kolibri@_HeapInit$qpvt1t1
MenuetHeapAlloc = @@Kolibri@Alloc$qui KolibriHeapAlloc = @@Kolibri@Alloc$qui
MenuetHeapReAlloc = @@Kolibri@ReAlloc$qpvui KolibriHeapReAlloc = @@Kolibri@ReAlloc$qpvui
MenuetHeapFree = @@Kolibri@Free$qpv KolibriHeapFree = @@Kolibri@Free$qpv
MenuetHeapFreeAndThreadFinish = @Kolibri@_FreeAndThreadFinish$qpvpi KolibriHeapFreeAndThreadFinish = @Kolibri@_FreeAndThreadFinish$qpvpi
proc @Kolibri@_SetUseMemory$qui proc @Kolibri@_SetUseMemory$qui
push ebx push ebx
@ -20,7 +20,7 @@ proc @Kolibri@_SetUseMemory$qui
test eax,eax test eax,eax
jnz .set_use_memory_nomem jnz .set_use_memory_nomem
push ecx push ecx
push dword [@Kolibri@_MenuetMemBlock] push dword [@Kolibri@_KolibriMemBlock]
call @@MemoryHeap@ResizeBlock$q20MemoryHeap@TMemBlockpv call @@MemoryHeap@ResizeBlock$q20MemoryHeap@TMemBlockpv
add esp,8 add esp,8
mov al,1 mov al,1
@ -58,16 +58,16 @@ proc @Kolibri@_FreeAndThreadFinish$qpvpi
mov eax,5 mov eax,5
int 0x40 int 0x40
shl ebx,1 shl ebx,1
cmp ebx,MENUET_MUTEX_MAX_TIME_WAIT cmp ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
jna .heap_free_tf_wait jna .heap_free_tf_wait
mov ebx,MENUET_MUTEX_MAX_TIME_WAIT mov ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
.heap_free_tf_wait: .heap_free_tf_wait:
cmp dword [ecx],0 cmp dword [ecx],0
jnz @Kolibri@ExitProcess$qv jnz @Kolibri@ExitProcess$qv
lock bts dword [@Kolibri@_MemHeapMutex],0 lock bts dword [@Kolibri@_MemHeapMutex],0
jc .heap_free_tf_wait_loop jc .heap_free_tf_wait_loop
push dword [esp+4] push dword [esp+4]
push @Kolibri@_MenuetFreeSpace push @Kolibri@_KolibriFreeSpace
call @@MemoryHeap@Free$qr21MemoryHeap@TFreeSpacepv call @@MemoryHeap@Free$qr21MemoryHeap@TFreeSpacepv
add esp,8 add esp,8
mov byte [@Kolibri@_MemHeapMutex],0x40 mov byte [@Kolibri@_MemHeapMutex],0x40

View File

@ -1,5 +1,5 @@
#ifndef __MENUET_LIB_H_INCLUDED_ #ifndef __KOLIBRI_LIB_H_INCLUDED_
#define __MENUET_LIB_H_INCLUDED_ #define __KOLIBRI_LIB_H_INCLUDED_
// Kolibri interface. // Kolibri interface.
@ -13,4 +13,4 @@ namespace Kolibri // All kolibri functions, types and data are nested in the (
double Floor(double x); double Floor(double x);
} }
#endif // __MENUET_LIB_H_INCLUDED_ #endif // __KOLIBRI_LIB_H_INCLUDED_

View File

@ -84,7 +84,7 @@ proc @Kolibri@Floor$qd
mov ax,[esp+10] mov ax,[esp+10]
shl ax,1 shl ax,1
cmp ax,0x8680 cmp ax,0x8680
ja Menuet_floor_end ja Kolibri_floor_end
mov ch,4 mov ch,4
sub esp,2 sub esp,2
wait wait
@ -100,7 +100,7 @@ proc @Kolibri@Floor$qd
mov [esp],dx mov [esp],dx
fldcw word [esp] fldcw word [esp]
add esp,2 add esp,2
Menuet_floor_end: Kolibri_floor_end:
ret ret
endp endp

View File

@ -8,6 +8,9 @@ org 0
dd U_END+STACKSIZE dd U_END+STACKSIZE
dd @Kolibri@CommandLine,0 dd @Kolibri@CommandLine,0
include "..\..\..\KOSfuncs.inc"
include "..\..\proc32.inc"
ptr equ ptr equ
offset equ offset equ
short equ short equ
@ -39,47 +42,3 @@ macro movsw a,b
macro segment name {} macro segment name {}
macro endseg name {} macro endseg name {}
macro usedef [link]
{
common
if ~link eq
virtual at 0
forward
dd link
common
end virtual
end if
}
macro define_f x,[link]
{
common
if x eq
else if used x
x:
usedef link
}
macro enddef [link]
{
common
usedef link
end if
}
macro newdef x,[link]
{
common
end if
if x eq
else if used x
x:
usedef link
}
macro nextdef x
{
x:
}

View File

@ -7,7 +7,7 @@ macro writestr [arg]
pushad pushad
push straddr push straddr
push strend push strend
jmp @Menuet@DebugPutString$qpxc jmp @Kolibri@DebugPutString$qpxc
straddr db arg,0 straddr db arg,0
strend: strend:
pop eax pop eax

View File

@ -1,5 +1,5 @@
#ifndef __MENUET_FILE_OPEN_H_INCLUDED_ #ifndef __KOLIBRI_FILE_OPEN_H_INCLUDED_
#define __MENUET_FILE_OPEN_H_INCLUDED_ #define __KOLIBRI_FILE_OPEN_H_INCLUDED_
#include <kolibri.h> #include <kolibri.h>
@ -8,7 +8,7 @@
namespace Kolibri // All kolibri functions, types and data are nested in the (Kolibri) namespace. namespace Kolibri // All kolibri functions, types and data are nested in the (Kolibri) namespace.
{ {
struct TOpenFileStruct; // Data for a file open dialog. struct TOpenFileStruct; // Data for a file open dialog.
#define MENUET_OPEN_FILE_INIT {} // Initializer of the file open struct, cat be redefined in a realization of the library #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 OpenFileInit(TOpenFileStruct &ofs);
void OpenFileDelete(TOpenFileStruct &ofs); void OpenFileDelete(TOpenFileStruct &ofs);
@ -19,7 +19,7 @@ namespace Kolibri // All kolibri functions, types and data are nested in the (
bool OpenFileSetName(TOpenFileStruct &ofs, char *name); bool OpenFileSetName(TOpenFileStruct &ofs, char *name);
} }
#ifdef __MENUET__ #ifdef __KOLIBRI__
namespace Kolibri namespace Kolibri
{ {
@ -30,8 +30,8 @@ namespace Kolibri
int state; int state;
char *name; char *name;
}; };
#undef MENUET_OPEN_FILE_INIT #undef KOLIBRI_OPEN_FILE_INIT
#define MENUET_OPEN_FILE_INIT {0,0} #define KOLIBRI_OPEN_FILE_INIT {0,0}
// Inline functions. // Inline functions.
@ -79,7 +79,7 @@ namespace Kolibri
} }
} }
#else // else: def __MENUET__ #else // else: def __KOLIBRI__
namespace Kolibri namespace Kolibri
{ {
@ -90,11 +90,11 @@ namespace Kolibri
TOpenFileStruct(); TOpenFileStruct();
~TOpenFileStruct(); ~TOpenFileStruct();
}; };
#undef MENUET_OPEN_FILE_INIT #undef KOLIBRI_OPEN_FILE_INIT
#define MENUET_OPEN_FILE_INIT TOpenFileStruct() #define KOLIBRI_OPEN_FILE_INIT TOpenFileStruct()
} }
#endif // __MENUET__ #endif // __KOLIBRI__
#endif // __MENUET_FILE_OPEN_H_INCLUDED_ #endif // __KOLIBRI_FILE_OPEN_H_INCLUDED_

View File

@ -1,11 +1,10 @@
;//NAME// life2.cpp ;//NAME// life2.cpp
;//COMPILER// bcc32 -S -v- -R- -6 -a4 -O2 -Og -Oi -Ov -OS -k- -D__MENUET__ -Iinclude ;//COMPILER// bcc32 -S -v- -R- -6 -a4 -O2 -Og -Oi -Ov -OS -k- -D__KOLIBRI__ -Iinclude
;//UTIL_PATH// . ;//UTIL_PATH// .
STACKSIZE equ 102400 STACKSIZE equ 102400
HEAPSIZE equ 102400 HEAPSIZE equ 102400
include "..\..\proc32.inc"
include "include\kos_start.inc" include "include\kos_start.inc"
include "include\kos_func.inc" include "include\kos_func.inc"
include "include\kos_heap.inc" include "include\kos_heap.inc"

View File

@ -107,11 +107,11 @@ AxisParam xpar = {0, 0, 0};
AxisParam ypar = {0, 0, 0}; AxisParam ypar = {0, 0, 0};
MouseParam mpar = {0, 0, 0, 0, 0, MouseParam::HitNull}; MouseParam mpar = {0, 0, 0, 0, 0, MouseParam::HitNull};
MenuParam menu; MenuParam menu;
TOpenFileStruct open_file_str = MENUET_OPEN_FILE_INIT; TOpenFileStruct open_file_str = KOLIBRI_OPEN_FILE_INIT;
TimeGeneration timegen[TimeGenLength]; TimeGeneration timegen[TimeGenLength];
int timegenpos = 0; int timegenpos = 0;
#ifdef __MENUET__ #ifdef __KOLIBRI__
inline int abs(int i) {return (i >= 0) ? i : (-i);} inline int abs(int i) {return (i >= 0) ? i : (-i);}
@ -1950,34 +1950,3 @@ void KolibriOnMouse(TThreadData th)
} }
mpar.button = m; mpar.button = m;
} }
#ifndef __MENUET__
#include <windows.h>
void __stdcall (*DllOneGeneration)(int w, int h, void *dest, const void *src, int flag) = 0;
void DllInit()
{
HINSTANCE hLib = LoadLibrary("LifeGen.dll");
if (!hLib)
{
DebugPutString("Can't load the library.\n");
Kolibri::Abort();
}
DllOneGeneration = (void(__stdcall*)(int, int, void*, const void*, int))GetProcAddress(hLib, "OneGeneration");
if (!DllOneGeneration)
{
DebugPutString("Can't get a library function.\n");
Kolibri::Abort();
}
}
void __stdcall OneGeneration(int w, int h, void *dest, const void *src, int flag)
{
if (!DllOneGeneration) DllInit();
DllOneGeneration(w, h, dest, src, flag);
}
#endif