/programs/demos/life2/include/menuet_win.cpp |
---|
File deleted |
/programs/demos/life2/include/kolibri.h |
---|
28,10 → 28,10 |
//_ 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. |
#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. |
#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. |
// Note: pass only thread data of current thread as (thread_data) parameter to these functions. |
146,7 → 146,7 |
void KolibriOnKeyPress(Kolibri::TThreadData thread_data); // When user press a key. |
void KolibriOnMouse(Kolibri::TThreadData thread_data); // When user move a mouse. |
#ifdef __MENUET__ |
#ifdef __KOLIBRI__ |
namespace Kolibri |
{ |
156,15 → 156,15 |
{ |
unsigned int mut; |
}; |
#undef MENUET_MUTEX_INIT |
#define MENUET_MUTEX_INIT {0x40} // Simple mutex initializer, cat be redefined in a realization of the library |
#undef KOLIBRI_MUTEX_INIT |
#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. |
{ |
unsigned int mut, pid; |
}; |
#undef MENUET_REC_MUTEX_INIT |
#define MENUET_REC_MUTEX_INIT {0x20,-1} // Recursive mutex initializer, cat be redefined in a realization of the library |
#undef KOLIBRI_REC_MUTEX_INIT |
#define KOLIBRI_REC_MUTEX_INIT {0x20,-1} // Recursive mutex initializer, cat be redefined in a realization of the library |
// Global variables. |
172,7 → 172,7 |
volatile unsigned int _ThreadScanCount[2] = {0, 0}; |
volatile int _ThreadNumber = 1; |
volatile int _ExitProcessNow = 0; |
TMutex _ThreadMutex = MENUET_MUTEX_INIT; |
TMutex _ThreadMutex = KOLIBRI_MUTEX_INIT; |
unsigned int _ThreadSavedBegProc[4]; |
// Inline functions. |
478,8 → 478,8 |
int win_type = ((unsigned int)thread_data[KOLIBRI_THREAD_DATA_FLAG] & 0x40000000) ? |
((TStartData*)thread_data[KOLIBRI_THREAD_DATA_TITLE])->WinData.WindowType : |
((unsigned int)thread_data[KOLIBRI_THREAD_DATA_C_WINDOW] >> 24); |
border_size = MENUET_BORDER_SIZE; |
header_size = short(((win_type & 15) == 3) ? _GetSkinHeader() : MENUET_HEADER_SIZE); |
border_size = KOLIBRI_BORDER_SIZE; |
header_size = short(((win_type & 15) == 3) ? _GetSkinHeader() : KOLIBRI_HEADER_SIZE); |
} |
void GetClientSize(unsigned short &width, unsigned short &height, |
507,7 → 507,7 |
} |
} |
#else // def __MENUET__ |
#else // def __KOLIBRI__ |
namespace Kolibri |
{ |
518,8 → 518,8 |
TMutex(); |
~TMutex(); |
}; |
#undef MENUET_MUTEX_INIT |
#define MENUET_MUTEX_INIT TMutex() |
#undef KOLIBRI_MUTEX_INIT |
#define KOLIBRI_MUTEX_INIT TMutex() |
struct TRecMutex |
{ |
528,11 → 528,11 |
TRecMutex(); |
~TRecMutex(); |
}; |
#undef MENUET_REC_MUTEX_INIT |
#define MENUET_REC_MUTEX_INIT TRecMutex() |
#undef KOLIBRI_REC_MUTEX_INIT |
#define KOLIBRI_REC_MUTEX_INIT TRecMutex() |
} |
#endif // else: def __MENUET__ |
#endif // else: def __KOLIBRI__ |
#endif // ndef __KOLIBRI_H_INCLUDED_ |
/programs/demos/life2/include/kolibri_win.cpp |
---|
0,0 → 1,920 |
#include <string.h> |
#include <process.h> |
#include <stdio.h> |
#include <math.h> |
#include <assert.h> |
#include <deque.h> |
#include <kolibri.h> |
#include <kos_heap.h> |
#include <kos_file.h> |
using namespace Kolibri; |
using namespace std; |
const char file_prefix[] = ""; |
bool WasThreadCreatedBool = false; |
struct TExceptToMessageLoop |
{ |
TExceptToMessageLoop() {} |
}; |
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; |
deque<unsigned char> *keys; |
unsigned int bmp_data_length; |
unsigned int *bmp_data; |
unsigned int mouse_state; |
}; |
TThreadDataStruct /*__thread*/ ThreadDataStruct; |
int nCmdShow; |
HINSTANCE hInstance; |
const char szWindowClass[] = "Kolibri window"; |
void FinalizeThreadData() |
{ |
if (ThreadDataStruct.keys) |
{ |
delete ThreadDataStruct.keys; |
ThreadDataStruct.keys = 0; |
} |
if (ThreadDataStruct.bmp_data) |
{ |
delete[] ThreadDataStruct.bmp_data; |
ThreadDataStruct.bmp_data = 0; |
} |
} |
unsigned int CalculateNewTime() |
{ |
unsigned int t = GetTickCount(); |
unsigned int dt = (unsigned int)(t - ThreadDataStruct.win_time) / 10U; |
ThreadDataStruct.me_time += dt; |
ThreadDataStruct.win_time += dt * 10; |
return t; |
} |
void DrawPicture(HDC hdc) |
{ |
TRecMutex xm; |
InitRecMutex(&xm); |
Lock(&xm); |
UnLock(&xm); |
int w = ThreadDataStruct.picture_width, h = ThreadDataStruct.picture_height; |
RECT rect; |
if (!ThreadDataStruct.picture || !ThreadDataStruct.hwnd || w <= 0 || h <= 0) return; |
if (GetClientRect(ThreadDataStruct.hwnd, &rect)) |
{ |
rect.right -= rect.left; rect.left = 0; |
rect.bottom -= rect.top; rect.top = 0; |
if (rect.right <= 0 || rect.bottom <= 0) return; |
if (w > rect.right) w = rect.right; |
if (h > rect.bottom) h = rect.bottom; |
} |
if (!ThreadDataStruct.bmp_data || ThreadDataStruct.bmp_data_length < w * h) |
{ |
if (ThreadDataStruct.bmp_data) delete[] ThreadDataStruct.bmp_data; |
ThreadDataStruct.bmp_data_length = w * h; |
ThreadDataStruct.bmp_data = new unsigned int[ThreadDataStruct.bmp_data_length]; |
} |
int i; |
unsigned char *p = (unsigned char*)ThreadDataStruct.picture; |
for (i = 0; i < w * h; i++) |
{ |
ThreadDataStruct.bmp_data[i] = ((unsigned int)p[0]) + |
((unsigned int)p[1] << 8) + ((unsigned int)p[2] << 16); |
p += 3; |
} |
HBITMAP bitmap = CreateBitmap(w, h, 1, 32, ThreadDataStruct.bmp_data); |
if (bitmap) |
{ |
HDC memdc = CreateCompatibleDC(hdc); |
if (memdc) |
{ |
SelectObject(memdc, bitmap); |
BitBlt(hdc, 0, 0, w, h, memdc, 0, 0, SRCCOPY); |
DeleteObject(memdc); |
} |
DeleteObject(bitmap); |
} |
} |
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
{ |
const int timeout = 20; |
unsigned int t; |
PAINTSTRUCT ps; |
HDC hdc; |
if (hWnd == ThreadDataStruct.hwnd && ThreadDataStruct.flag != -1) |
{ |
int window_rect[4]; |
switch (message) |
{ |
case WM_CREATE: |
SetTimer(hWnd, 0, timeout, NULL); |
SendMessage(hWnd, WM_SIZE, SIZE_RESTORED, 0); |
return 0; |
case WM_TIMER: |
t = CalculateNewTime(); |
while (KolibriOnIdle((TThreadData)(&ThreadDataStruct)) == 0 && |
GetTickCount() - t + 2 < timeout); |
return 0; |
case WM_MOUSEMOVE: |
KolibriOnMouse((TThreadData)(&ThreadDataStruct)); |
return 0; |
case WM_LBUTTONDOWN: |
if (!ThreadDataStruct.mouse_state) SetCapture(hWnd); |
ThreadDataStruct.mouse_state |= 1; |
KolibriOnMouse((TThreadData)(&ThreadDataStruct)); |
return 0; |
case WM_LBUTTONUP: |
if (ThreadDataStruct.mouse_state & 1) |
{ |
ThreadDataStruct.mouse_state &= ~1; |
if (!ThreadDataStruct.mouse_state) ReleaseCapture(); |
KolibriOnMouse((TThreadData)(&ThreadDataStruct)); |
} |
return 0; |
case WM_RBUTTONDOWN: |
if (!ThreadDataStruct.mouse_state) SetCapture(hWnd); |
ThreadDataStruct.mouse_state |= 2; |
KolibriOnMouse((TThreadData)(&ThreadDataStruct)); |
return 0; |
case WM_RBUTTONUP: |
if (ThreadDataStruct.mouse_state & 2) |
{ |
ThreadDataStruct.mouse_state &= ~2; |
if (!ThreadDataStruct.mouse_state) ReleaseCapture(); |
KolibriOnMouse((TThreadData)(&ThreadDataStruct)); |
} |
return 0; |
case WM_CAPTURECHANGED: |
if (ThreadDataStruct.mouse_state) |
{ |
ThreadDataStruct.mouse_state = 0; |
KolibriOnMouse((TThreadData)(&ThreadDataStruct)); |
} |
return 0; |
//case WM_SYSKEYDOWN: case WM_KEYDOWN: |
case WM_CHAR: |
ThreadDataStruct.keys->push_back((unsigned char)wParam); |
KolibriOnKeyPress((TThreadData)(&ThreadDataStruct)); |
return 0; |
case WM_SIZE: |
GetProcessInfo(0, 0, 0, 0, window_rect); |
KolibriOnSize(window_rect, (TThreadData)(&ThreadDataStruct)); |
InvalidateRect(hWnd, 0, 0); |
return 0; |
case WM_PAINT: |
hdc = BeginPaint(hWnd, &ps); |
if (ThreadDataStruct.picture) DrawPicture(hdc); |
EndPaint(hWnd, &ps); |
return 0; |
case WM_CLOSE: |
if (KolibriOnClose((TThreadData)(&ThreadDataStruct))) |
{ |
ThreadDataStruct.flag = -1; |
} |
else return 0; |
case WM_DESTROY: |
PostQuitMessage(0); |
return 0; |
} |
} |
return DefWindowProc(hWnd, message, wParam, lParam); |
} |
ATOM MyRegisterClass() |
{ |
HBRUSH background = CreateSolidBrush(RGB(0, 0, 0)); |
WNDCLASSEX wcex; |
wcex.cbSize = sizeof(WNDCLASSEX); |
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; |
wcex.lpfnWndProc = (WNDPROC)WndProc; |
wcex.cbClsExtra = 0; |
wcex.cbWndExtra = 0; |
wcex.hInstance = hInstance; |
wcex.hIcon = 0; |
wcex.hCursor = LoadCursor(NULL, IDC_ARROW); |
wcex.hbrBackground = background; |
wcex.lpszMenuName = NULL; |
wcex.lpszClassName = szWindowClass; |
wcex.hIconSm = 0; |
ATOM ret = RegisterClassEx(&wcex); |
DeleteObject(background); |
return ret; |
} |
HWND InitInstance(int x, int y, int w, int h) |
{ |
HWND hWnd; |
MyRegisterClass(); |
DWORD style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, exstyle = 0; |
hWnd = CreateWindowEx(exstyle, szWindowClass, ThreadDataStruct.win_data->Title, style, |
x, y, w, h, NULL, NULL, hInstance, NULL); |
if (!hWnd) return NULL; |
ShowWindow(hWnd, nCmdShow); |
UpdateWindow(hWnd); |
return hWnd; |
} |
int ThreadMainProc(void *user) |
{ |
ThreadMain(user, 0); |
return 0; |
} |
namespace Kolibri |
{ |
void Main() {ThreadMain();} |
void* ThreadMain(void *user, void *stack_begin) |
{ |
TStartData start_data; |
ThreadDataStruct.user = user; |
ThreadDataStruct.stack_begin = stack_begin; |
ThreadDataStruct.win_data = &start_data.WinData; |
ThreadDataStruct.hwnd = 0; |
ThreadDataStruct.flag = 0; |
ThreadDataStruct.win_time = GetTickCount(); |
ThreadDataStruct.me_time = ThreadDataStruct.win_time / 10; |
ThreadDataStruct.keys = new deque<unsigned char>; |
ThreadDataStruct.bmp_data_length = 0; |
ThreadDataStruct.bmp_data = 0; |
ThreadDataStruct.mouse_state = 0; |
start_data.Left = 50; start_data.Width = 256; |
start_data.Top = 50; start_data.Height = 256; |
start_data.WinData.WindowType = 0x03; |
start_data.WinData.HeaderType = 0x80; |
start_data.WinData.WindowColor = 0xFFFFFF; |
start_data.WinData.HeaderColor = 0x6060FF; |
start_data.WinData.BorderColor = 0x000000; |
start_data.WinData.TitleColor = 0xFFFF40; |
start_data.WinData.Title = 0; |
if (KolibriOnStart(start_data, (TThreadData)(&ThreadDataStruct))) |
{ |
while (ThreadDataStruct.flag < 0) |
{ |
ThreadDataStruct.flag &= ~0x80000000; |
if (KolibriOnClose((TThreadData)(&ThreadDataStruct))) |
{ |
ThreadDataStruct.flag = -1; |
break; |
} |
} |
if (ThreadDataStruct.flag >= 0) |
{ |
assert((ThreadDataStruct.hwnd = InitInstance(start_data.Left, |
start_data.Top, start_data.Width, start_data.Height)) != NULL); |
assert(SendMessage(ThreadDataStruct.hwnd, WM_CREATE, 0, 0) == 0); |
MSG msg; |
HACCEL hAccelTable = 0; |
while (GetMessage(&msg, NULL, 0, 0)) |
{ |
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) |
{ |
TranslateMessage(&msg); |
DispatchMessage(&msg); |
} |
} |
} |
assert(ThreadDataStruct.flag == -1); |
} |
FinalizeThreadData(); |
return ThreadDataStruct.stack_begin; |
} |
void GetWindowData(TWindowData &win_data) |
{ |
win_data = *ThreadDataStruct.win_data; |
} |
void GetWindowData(TWindowData &win_data, TThreadData thread_data) |
{ |
win_data = *((TThreadDataStruct*)thread_data)->win_data; |
} |
void SetWindowData(const TWindowData &win_data) |
{ |
*ThreadDataStruct.win_data = win_data; |
if (ThreadDataStruct.hwnd) |
{ |
SetWindowText(ThreadDataStruct.hwnd, ThreadDataStruct.win_data->Title); |
InvalidateRect(ThreadDataStruct.hwnd, NULL, FALSE); |
} |
} |
void SetWindowData(const TWindowData &win_data, TThreadData thread_data) |
{ |
*((TThreadDataStruct*)thread_data)->win_data = win_data; |
if (((TThreadDataStruct*)thread_data)->hwnd) |
{ |
SetWindowText(((TThreadDataStruct*)thread_data)->hwnd, |
((TThreadDataStruct*)thread_data)->win_data->Title); |
InvalidateRect(((TThreadDataStruct*)thread_data)->hwnd, NULL, FALSE); |
} |
} |
void CloseWindow() |
{ |
if (ThreadDataStruct.hwnd) |
{ |
SendMessage(ThreadDataStruct.hwnd, WM_CLOSE, 0, 0); |
} |
else ThreadDataStruct.flag |= 0x80000000; |
} |
void CloseWindow(TThreadData thread_data) |
{ |
if (((TThreadDataStruct*)thread_data)->hwnd) |
{ |
SendMessage(((TThreadDataStruct*)thread_data)->hwnd, WM_CLOSE, 0, 0); |
} |
else ((TThreadDataStruct*)thread_data)->flag |= 0x80000000; |
} |
void Redraw(int /*frame*/) |
{ |
if (ThreadDataStruct.hwnd) |
{ |
InvalidateRect(ThreadDataStruct.hwnd, NULL, FALSE); |
SendMessage(ThreadDataStruct.hwnd, WM_PAINT, 0, 0); |
} |
} |
void Redraw(int /*frame*/, TThreadData thread_data) |
{ |
if (((TThreadDataStruct*)thread_data)->hwnd) |
{ |
InvalidateRect(((TThreadDataStruct*)thread_data)->hwnd, NULL, FALSE); |
SendMessage(((TThreadDataStruct*)thread_data)->hwnd, WM_PAINT, 0, 0); |
} |
} |
void Invalidate(int /*frame*/) |
{ |
if (ThreadDataStruct.hwnd) |
{ |
InvalidateRect(ThreadDataStruct.hwnd, NULL, FALSE); |
} |
} |
void Invalidate(int /*frame*/, TThreadData thread_data) |
{ |
if (((TThreadDataStruct*)thread_data)->hwnd) |
{ |
InvalidateRect(((TThreadDataStruct*)thread_data)->hwnd, NULL, FALSE); |
} |
} |
void MoveWindow(const int window_rect[/* 4 */]) |
{ |
if (!ThreadDataStruct.hwnd) return; |
RECT rect; |
if (window_rect[0] == -1 || window_rect[1] == -1 || |
window_rect[2] == -1 || window_rect[3] == -1) |
{ |
if (!GetWindowRect(ThreadDataStruct.hwnd, &rect)) return; |
::MoveWindow(ThreadDataStruct.hwnd, |
(window_rect[0] == -1) ? rect.left : window_rect[0], |
(window_rect[1] == -1) ? rect.top : window_rect[1], |
(window_rect[2] == -1) ? (rect.right - rect.left) : window_rect[2], |
(window_rect[3] == -1) ? (rect.bottom - rect.top) : window_rect[3], TRUE); |
} |
else |
{ |
::MoveWindow(ThreadDataStruct.hwnd, window_rect[0], |
window_rect[1], window_rect[2], window_rect[3], TRUE); |
} |
} |
void Abort() |
{ |
if (ThreadDataStruct.hwnd) KillTimer(ThreadDataStruct.hwnd, 0); |
abort(); |
} |
void ExitProcess() {::ExitProcess(0);} |
void ExitThread() {FinalizeThreadData(); ::ExitThread(0);} |
void ExitThread(TThreadData) {FinalizeThreadData(); ::ExitThread(0);} |
void ReturnMessageLoop() |
{ |
TExceptToMessageLoop ex; |
throw(ex); |
} |
void ReturnMessageLoop(TThreadData) |
{ |
TExceptToMessageLoop ex; |
throw(ex); |
} |
void Delay(unsigned int time) {Sleep(time * 10);} |
unsigned int Clock() {CalculateNewTime(); return ThreadDataStruct.me_time;} |
int GetPackedTime() |
{ |
SYSTEMTIME time; |
GetSystemTime(&time); |
int t; |
t = (time.wSecond / 10) * 16 + (time.wSecond % 10); |
t = (time.wMinute / 10) * 16 + (time.wMinute % 10) + (t << 8); |
t = (time.wHour / 10) * 16 + (time.wHour % 10) + (t << 8); |
return t; |
} |
void GetTime(int t[/* 3 */]) |
{ |
SYSTEMTIME time; |
GetSystemTime(&time); |
t[0] = time.wSecond; |
t[1] = time.wMinute; |
t[2] = time.wHour; |
} |
int GetPackedDate() |
{ |
SYSTEMTIME time; |
GetSystemTime(&time); |
int t; |
t = ((time.wYear / 10) % 10) * 16 + (time.wYear % 10); |
t = (time.wDay / 10) * 16 + (time.wDay % 10) + (t << 8); |
t = (time.wMonth / 10) * 16 + (time.wMonth % 10) + (t << 8); |
return t; |
} |
void GetDate(int d[/* 3 */]) |
{ |
SYSTEMTIME time; |
GetSystemTime(&time); |
d[0] = time.wDay; |
d[1] = time.wMonth; |
d[2] = time.wYear; |
} |
void GetTimeDate(int t[/* 6 */]) |
{ |
SYSTEMTIME time; |
GetSystemTime(&time); |
t[0] = time.wSecond; |
t[1] = time.wMinute; |
t[2] = time.wHour; |
t[3] = time.wDay; |
t[4] = time.wMonth; |
t[5] = time.wYear; |
} |
void ReadCommonColors(unsigned int colors[/* 10 */]) |
{ |
int i; |
for (i = 0; i < 10; i++) colors[i] = 0; |
} |
unsigned int GetProcessInfo(unsigned int *use_cpu, char process_name[/* 13 */], unsigned int *use_memory, |
unsigned int *pid, int window_rect[/* 4 */], unsigned int pid_for) |
{ |
if (use_cpu) *use_cpu = 0; |
if (process_name) strcpy(process_name, "noname"); |
if (use_memory) *use_memory = 0; |
if (pid) |
{ |
if ((pid_for | 15) == -1) pid_for = getpid(); |
*pid = pid_for; |
} |
if (window_rect) |
{ |
RECT rect; |
if (ThreadDataStruct.hwnd && GetWindowRect(ThreadDataStruct.hwnd, &rect)) |
{ |
window_rect[0] = rect.left; |
window_rect[1] = rect.top; |
window_rect[2] = rect.right - rect.left; |
window_rect[3] = rect.bottom - rect.top; |
} |
else |
{ |
window_rect[0] = 0; window_rect[1] = 0; |
window_rect[2] = 0; window_rect[3] = 0; |
} |
} |
return 1; |
} |
unsigned int GetPid() {return GetCurrentThreadId();} |
unsigned int GetPid(TThreadData /*thread_data*/) {return GetCurrentThreadId();} |
TThreadData GetThreadData() {return (TThreadData)(&ThreadDataStruct);} |
TThreadData GetThreadData(unsigned int /*pid*/) {return (TThreadData)(&ThreadDataStruct);} |
void* GetPicture(unsigned short &width, unsigned short &height) |
{ |
width = (unsigned short)ThreadDataStruct.picture_width; |
height = (unsigned short)ThreadDataStruct.picture_height; |
return ThreadDataStruct.picture; |
} |
void* GetPicture(unsigned short &width, unsigned short &height, TThreadData thread_data) |
{ |
width = (unsigned short)((TThreadDataStruct*)thread_data)->picture_width; |
height = (unsigned short)((TThreadDataStruct*)thread_data)->picture_height; |
return ((TThreadDataStruct*)thread_data)->picture; |
} |
void SetPicture(void *picture, unsigned short width, unsigned short height) |
{ |
ThreadDataStruct.picture_width = width; |
ThreadDataStruct.picture_height = height; |
ThreadDataStruct.picture = picture; |
if (ThreadDataStruct.hwnd) |
{ |
InvalidateRect(ThreadDataStruct.hwnd, NULL, FALSE); |
} |
} |
void SetPicture(void *picture, unsigned short width, unsigned short height, TThreadData thread_data) |
{ |
((TThreadDataStruct*)thread_data)->picture_width = width; |
((TThreadDataStruct*)thread_data)->picture_height = height; |
((TThreadDataStruct*)thread_data)->picture = picture; |
if (((TThreadDataStruct*)thread_data)->hwnd) |
{ |
InvalidateRect(((TThreadDataStruct*)thread_data)->hwnd, NULL, FALSE); |
} |
} |
void GetBorderHeader(unsigned short &border_size, unsigned short &header_size) |
{ |
border_size = (unsigned short)GetSystemMetrics(SM_CXFRAME); |
header_size = (unsigned short)(GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION)); |
} |
void GetBorderHeader(unsigned short &border_size, unsigned short &header_size, TThreadData /*thread_data*/) |
{ |
border_size = (unsigned short)GetSystemMetrics(SM_CXFRAME); |
header_size = (unsigned short)(GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION)); |
} |
void GetClientSize(unsigned short &width, unsigned short &height) |
{ |
if (!ThreadDataStruct.hwnd) {width = 0; height = 0; return;} |
RECT rect; |
GetClientRect(ThreadDataStruct.hwnd, &rect); |
width = (unsigned short)(rect.right - rect.left); |
height = (unsigned short)(rect.bottom - rect.top); |
} |
void GetClientSize(unsigned short &width, unsigned short &height, TThreadData thread_data) |
{ |
if (!((TThreadDataStruct*)thread_data)->hwnd) {width = 0; height = 0; return;} |
RECT rect; |
GetClientRect(((TThreadDataStruct*)thread_data)->hwnd, &rect); |
width = (unsigned short)(rect.right - rect.left); |
height = (unsigned short)(rect.bottom - rect.top); |
} |
void GetClientSize(unsigned short &width, unsigned short &height, int win_width, int win_height) |
{ |
win_width -= 2*GetSystemMetrics(SM_CXFRAME); |
win_height -= 2*GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION); |
if (win_width < 0) win_width = 0; |
if (win_height < 0) win_height = 0; |
width = (unsigned short)win_width; height = (unsigned short)win_height; |
} |
void GetClientSize(unsigned short &width, unsigned short &height, |
int win_width, int win_height, TThreadData /*thread_data*/) |
{ |
win_width -= 2*GetSystemMetrics(SM_CXFRAME); |
win_height -= 2*GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION); |
if (win_width < 0) win_width = 0; |
if (win_height < 0) win_height = 0; |
width = (unsigned short)win_width; height = (unsigned short)win_height; |
} |
void GetScreenSize(unsigned short &width, unsigned short &height) |
{ |
width = (unsigned short)GetSystemMetrics(SM_CXFULLSCREEN); |
height = (unsigned short)GetSystemMetrics(SM_CYFULLSCREEN); |
} |
TMutex::TMutex() {mut = (unsigned int)CreateMutex(NULL, FALSE, NULL);} |
TMutex::~TMutex() {if (mut) {CloseHandle((HANDLE)mut); mut = 0;}} |
TRecMutex::TRecMutex() {mut = (unsigned int)CreateMutex(NULL, FALSE, NULL);} |
TRecMutex::~TRecMutex() {if (mut) {CloseHandle((HANDLE)mut); mut = 0;}} |
void InitMutex(TMutex *mutex) {if (!mutex->mut) *mutex = TMutex();} |
void InitRecMutex(TRecMutex *mutex) {if (!mutex->mut) *mutex = TRecMutex();} |
bool TryLock(TMutex *mutex) |
{ |
DWORD ret = WaitForSingleObject((HANDLE)mutex->mut, 0); |
return ret == WAIT_OBJECT_0 || ret == WAIT_ABANDONED; |
} |
bool TryLock(TRecMutex *mutex, unsigned int /*pid*/) |
{ |
DWORD ret = WaitForSingleObject((HANDLE)mutex->mut, 0); |
return ret == WAIT_OBJECT_0 || ret == WAIT_ABANDONED; |
} |
bool TryLock(TRecMutex *mutex) |
{ |
DWORD ret = WaitForSingleObject((HANDLE)mutex->mut, 0); |
return ret == WAIT_OBJECT_0 || ret == WAIT_ABANDONED; |
} |
bool TryLock(TRecMutex *mutex, TThreadData /*thread_data*/) |
{ |
DWORD ret = WaitForSingleObject((HANDLE)mutex->mut, 0); |
return ret == WAIT_OBJECT_0 || ret == WAIT_ABANDONED; |
} |
void Lock(TMutex *mutex) |
{ |
WaitForSingleObject((HANDLE)mutex->mut, INFINITE); |
} |
void Lock(TRecMutex *mutex, unsigned int /*pid*/) |
{ |
WaitForSingleObject((HANDLE)mutex->mut, INFINITE); |
} |
void Lock(TRecMutex *mutex) |
{ |
WaitForSingleObject((HANDLE)mutex->mut, INFINITE); |
} |
void Lock(TRecMutex *mutex, TThreadData /*thread_data*/) |
{ |
WaitForSingleObject((HANDLE)mutex->mut, INFINITE); |
} |
bool LockTime(TMutex *mutex, unsigned int time) |
{ |
DWORD ret = WaitForSingleObject((HANDLE)mutex->mut, time * 10); |
return ret == WAIT_OBJECT_0 || ret == WAIT_ABANDONED; |
} |
bool LockTime(TRecMutex *mutex, unsigned int time, unsigned int /*pid*/) |
{ |
DWORD ret = WaitForSingleObject((HANDLE)mutex->mut, time * 10); |
return ret == WAIT_OBJECT_0 || ret == WAIT_ABANDONED; |
} |
bool LockTime(TRecMutex *mutex, unsigned int time) |
{ |
DWORD ret = WaitForSingleObject((HANDLE)mutex->mut, time * 10); |
return ret == WAIT_OBJECT_0 || ret == WAIT_ABANDONED; |
} |
bool LockTime(TRecMutex *mutex, unsigned int time, TThreadData /*thread_data*/) |
{ |
DWORD ret = WaitForSingleObject((HANDLE)mutex->mut, time * 10); |
return ret == WAIT_OBJECT_0 || ret == WAIT_ABANDONED; |
} |
void UnLock(TMutex *mutex) |
{ |
ReleaseMutex((HANDLE)mutex->mut); |
} |
void UnLock(TRecMutex *mutex, unsigned int /*pid*/) |
{ |
ReleaseMutex((HANDLE)mutex->mut); |
} |
void UnLock(TRecMutex *mutex) |
{ |
ReleaseMutex((HANDLE)mutex->mut); |
} |
void UnLock(TRecMutex *mutex, TThreadData /*thread_data*/) |
{ |
ReleaseMutex((HANDLE)mutex->mut); |
} |
void DebugPutChar(char c) |
{ |
DWORD num_written; |
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), &c, 1, &num_written, NULL); |
} |
void DebugPutString(const char *s) |
{ |
DWORD num_written; |
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), s, strlen(s), &num_written, NULL); |
} |
int GetKey() |
{ |
if (ThreadDataStruct.keys->empty()) return -1; |
else |
{ |
unsigned char c = ThreadDataStruct.keys->front(); |
ThreadDataStruct.keys->pop_front(); |
return c; |
} |
} |
int GetMouseButton() |
{ |
return ThreadDataStruct.mouse_state; |
} |
void GetMousePosition(short &x, short &y, bool absolute) |
{ |
POINT point; |
if (!GetCursorPos(&point)) {x = -1; y = -1;} |
else if (absolute) {x = (short)point.x; y = (short)point.y;} |
else |
{ |
RECT rect; |
if (!ThreadDataStruct.hwnd || !GetWindowRect(ThreadDataStruct.hwnd, &rect)) |
{ |
x = -1; y = -1; |
} |
else |
{ |
x = (short)(point.x - rect.left); |
y = (short)(point.y - rect.top); |
} |
} |
} |
void GetMousePosPicture(short &x, short &y) |
{ |
POINT point; |
if (!GetCursorPos(&point)) {x = -1; y = -1;} |
else if (!ThreadDataStruct.hwnd || !ScreenToClient(ThreadDataStruct.hwnd, &point)) |
{ |
x = -1; y = -1; |
} |
else |
{ |
x = (short)point.x; |
y = (short)point.y; |
} |
} |
bool WasThreadCreated() {return WasThreadCreatedBool;} |
unsigned int CreateThread(void *user, unsigned int stack_size, void* /*stack_end*/) |
{ |
unsigned long pid = -1; |
WasThreadCreatedBool = true; |
if (!::CreateThread(NULL, stack_size, (LPTHREAD_START_ROUTINE)ThreadMainProc, user, 0, &pid)) |
{ |
return -1; |
} |
return pid; |
} |
unsigned int StrLen(const char *str) {return ::strlen(str);} |
char *StrCopy(char *dest, const char *src) {return ::strcpy(dest, src);} |
void *MemCopy(void *dest, const void *src, unsigned int n) {return ::memcpy(dest, src, n);} |
void *MemSet(void *s, char c, unsigned int n) {return ::memset(s, c, n);} |
double Floor(double x) {return floor(x);} |
void *Alloc(unsigned int size) {return malloc(size);} |
void *ReAlloc(void *mem, unsigned int size) {return realloc(mem, size);} |
void Free(void *mem) {free(mem);} |
TFileData FileOpen(const char *name, unsigned int /*buffer_length*/) |
{ |
if (!name || !name[0]) return 0; |
TFileData file_data = (TFileData)Alloc(sizeof(unsigned int) + |
strlen(file_prefix) + strlen(name) + 1); |
if (!file_data) return 0; |
file_data->data = 0; |
strcpy((char*)file_data + sizeof(unsigned int), file_prefix); |
strcat((char*)file_data + sizeof(unsigned int), name); |
return file_data; |
} |
int FileClose(TFileData file_data) |
{ |
if (!file_data) return -1; |
if (file_data->data) CloseHandle((HANDLE)file_data->data); |
Free(file_data); |
return 0; |
} |
bool FileEof(TFileData file_data) |
{ |
unsigned int pos; |
if (FileTestRead(file_data) < 0) return false; |
pos = SetFilePointer((HANDLE)file_data->data, 0, NULL, FILE_CURRENT); |
if (pos == -1) return false; |
return pos >= GetFileSize((HANDLE)file_data->data, NULL); |
} |
unsigned int FileGetPosition(TFileData file_data) |
{ |
unsigned int pos; |
if (FileTestRead(file_data) < 0) return 0; |
pos = SetFilePointer((HANDLE)file_data->data, 0, NULL, FILE_CURRENT); |
return (pos == -1) ? 0 : pos; |
} |
void FileSetPosition(TFileData file_data, unsigned int pos) |
{ |
if (FileTestRead(file_data) < 0) return; |
SetFilePointer((HANDLE)file_data->data, pos, NULL, FILE_BEGIN); |
} |
void FileReset(TFileData file_data) |
{ |
if (!file_data || !file_data->data) return; |
FlushFileBuffers((HANDLE)file_data->data); |
} |
unsigned int FileGetLength(TFileData file_data) |
{ |
if (FileTestRead(file_data) < 0) return -1; |
return GetFileSize((HANDLE)file_data->data, NULL); |
} |
int FileTestRead(TFileData file_data) |
{ |
if (!file_data) return -1; |
if (!file_data->data) |
{ |
file_data->data = (unsigned int)CreateFile((char*)file_data + sizeof(unsigned int), |
GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, |
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, 0); |
if (!file_data->data) return -512; |
} |
return 0; |
} |
int FileRead(TFileData file_data, void *mem, int size) |
{ |
if (!file_data || !mem || size <= 0) return -1; |
int res = FileTestRead(file_data); |
if (res < 0) return res; |
if (!ReadFile((HANDLE)file_data->data, mem, size, (unsigned long*)&res, NULL)) |
{ |
return -512; |
} |
return (res >= 0) ? res : (-1); |
} |
} |
bool CheckAllocConsole(LPSTR lpCmdLine) |
{ |
char Console[] = "-console"; |
int ConsoleL = ::strlen(Console); |
char *s; |
for (s = lpCmdLine; *s; s++) |
{ |
if ((s == lpCmdLine || isspace(s[-1])) && memcmp(s, Console, ConsoleL) == 0 && |
(!s[ConsoleL] || isspace(s[ConsoleL]))) |
{ |
AllocConsole(); |
SetConsoleTitle("Debug Console"); |
return true; |
} |
} |
return false; |
} |
int APIENTRY WinMain(HINSTANCE hInstance, |
HINSTANCE /*hPrevInstance*/, |
LPSTR lpCmdLine, |
int nCmdShow) |
{ |
::nCmdShow = nCmdShow; |
::hInstance = hInstance; |
CheckAllocConsole(lpCmdLine); |
Main(); |
//::ExitThread(0); |
return 0; |
} |
/programs/demos/life2/include/kos_file.h |
---|
22,7 → 22,7 |
int FileRead(TFileData file_data, void *mem, int size); |
} |
#ifdef __MENUET__ |
#ifdef __KOLIBRI__ |
namespace Kolibri |
{ |
262,7 → 262,7 |
} |
} |
#else // def __MENUET__ |
#else // def __KOLIBRI__ |
namespace Kolibri |
{ |
272,7 → 272,7 |
}; |
} |
#endif // else: def __MENUET__ |
#endif // else: def __KOLIBRI__ |
#endif // ndef __KOLIBRI_FILE_H_INCLUDED_ |
/programs/demos/life2/include/kos_func.inc |
---|
1,7 → 1,7 |
;const int |
MENUET_BORDER_SIZE = 4; |
KOLIBRI_BORDER_SIZE = 4; |
;const int |
MENUET_HEADER_SIZE = 20; |
KOLIBRI_HEADER_SIZE = 20; |
;const int |
KOLIBRI_THREAD_DATA_USER = 0; // Thread data begin from the user dword |
39,7 → 39,7 |
KOLIBRI_THREAD_DATA_LEN = 16; |
;const int |
MENUET_MUTEX_MAX_TIME_WAIT = 20; |
KOLIBRI_MUTEX_MAX_TIME_WAIT = 20; |
;const int |
KOLIBRI_FILE_BLOCK_SIZE = 512; |
53,9 → 53,9 |
{ |
segment name |
if name eq _init_ | name eq _INIT_ |
Menuet_SegmentInit: |
Kolibri_SegmentInit: |
else if name eq _exit_ | name eq _EXIT_ |
Menuet_SegmentExit: |
Kolibri_SegmentExit: |
end if |
} |
62,14 → 62,14 |
macro endseg name |
{ |
if name eq _init_ | name eq _INIT_ |
Menuet_SegmentInitEnd: |
Kolibri_SegmentInitEnd: |
else if name eq _exit_ | name eq _EXIT_ |
Menuet_SegmentExitEnd: |
Kolibri_SegmentExitEnd: |
end if |
endseg name |
} |
macro Menuet_Put_MovEaxVal_Ret address,val |
macro Kolibri_Put_MovEaxVal_Ret address,val |
{ |
mov byte [address],0xB8 |
mov dword [address+4],0xC089C300 |
79,7 → 79,7 |
proc @Kolibri@Main$qv |
and esp,not 3 |
sub esp,1024 |
mov eax,9 |
mov eax,SF_THREAD_INFO |
mov ebx,esp |
mov ecx,-1 |
int 0x40 |
97,21 → 97,21 |
cld |
mov edi,@Kolibri@_ThreadTable |
mov ecx,256 |
rep stos dword [edi] |
rep stosd |
mov esi,@Kolibri@GetPid$qv |
mov edi,@Kolibri@_ThreadSavedBegProc |
movs dword [edi],[esi] |
movs dword [edi],[esi] |
movsd |
movsd |
mov esi,@Kolibri@GetThreadData$qv |
movs dword [edi],[esi] |
movs dword [edi],[esi] |
Menuet_Put_MovEaxVal_Ret @Kolibri@GetPid$qv,edx |
if defined MenuetHeapInit |
movsd |
movsd |
Kolibri_Put_MovEaxVal_Ret @Kolibri@GetPid$qv,edx |
if defined KolibriHeapInit |
mov ecx,esp |
push ebx |
push ecx |
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 |
mov [esp+4],eax ; the begin of a heap. Return address of the created data. |
mov dword [esp],0 |
123,12 → 123,12 |
call @Kolibri@ThreadMain$qpvt1 |
.ThreadFinish: |
add esp,8 |
if defined MenuetHeapFreeAndThreadFinish |
if defined KolibriHeapFreeAndThreadFinish |
test eax,eax |
jz .ThreadFinish_end |
push dword @Kolibri@_ExitProcessNow |
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. |
.ThreadFinish_end: |
or eax,-1 |
142,16 → 142,16 |
sub esp,KOLIBRI_THREAD_DATA_LEN*4 |
mov [esp],ebx |
mov [esp+4],ebp |
mov eax,40 |
mov eax,SF_SET_EVENTS_MASK |
mov ebx,0x27 |
int 0x40 |
mov ebx,esp |
cmp byte [@Kolibri@_ThreadSavedBegProc],0x90 |
jz .main_else_first_check |
Menuet_Put_MovEaxVal_Ret @Kolibri@GetThreadData$qv,esp |
if defined Menuet_SegmentInit & defined Menuet_SegmentInitEnd |
push Menuet_SegmentInitEnd |
push Menuet_SegmentInit |
Kolibri_Put_MovEaxVal_Ret @Kolibri@GetThreadData$qv,esp |
if defined Kolibri_SegmentInit & defined Kolibri_SegmentInitEnd |
push Kolibri_SegmentInitEnd |
push Kolibri_SegmentInit |
jmp .main_after_first_check |
end if |
.main_else_first_check: |
166,11 → 166,13 |
jmp .main_end |
.main_close_first: |
btr dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],31 |
if defined @@KolibriOnClose$qppv |
push esp |
call @@KolibriOnClose$qppv |
pop ecx |
test al,al |
jnz .main_end |
end if |
.main_test_close_first: |
cmp dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0 |
jl .main_close_first |
181,7 → 183,7 |
.main_paint_msg: |
or dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],3 |
sub esp,1024 |
mov eax,9 |
mov eax,SF_THREAD_INFO |
mov ebx,esp |
mov ecx,-1 |
int 0x40 |
197,6 → 199,7 |
.main_size: |
mov [esp+KOLIBRI_THREAD_DATA_LAST_SX*4],ecx |
mov [esp+KOLIBRI_THREAD_DATA_LAST_SY*4],edx |
if defined @@KolibriOnSize$qpippv |
push edx |
push ecx |
push ebx |
207,6 → 210,7 |
push edx |
call @@KolibriOnSize$qpippv |
add esp,24 |
end if |
test dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],3 |
jz .main_cycle |
.main_paint: |
217,7 → 221,7 |
call @Kolibri@Redraw$qippv |
add esp,8 |
.main_cycle: |
mov eax,11 |
mov eax,SF_CHECK_EVENT |
.main_message: |
cmp dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0 |
jl .main_close |
226,56 → 230,86 |
jnz .main_on_message |
cmp dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0 |
jne .main_paint |
if defined @@KolibriOnIdle$qppv |
push esp |
call @@KolibriOnIdle$qppv |
pop ecx |
else |
or eax,-1 |
end if |
test eax,eax |
jz .main_cycle |
jl .main_wait_message |
mov ebx,eax |
mov eax,23 |
mov eax,SF_WAIT_EVENT_TIMEOUT |
jmp .main_message |
.main_wait_message: |
mov eax,10 |
mov eax,SF_WAIT_EVENT |
jmp .main_message |
if defined @@KolibriOnKeyPress$qppv |
.main_key_press: |
push esp |
call @@KolibriOnKeyPress$qppv |
pop ecx |
jmp .main_cycle |
end if |
if defined @@KolibriOnMouse$qppv |
.main_mouse: |
push esp |
call @@KolibriOnMouse$qppv |
pop ecx |
jmp .main_cycle |
end if |
align 4 |
.main_on_message: |
dec eax |
jz .main_paint_msg |
dec eax |
if defined @@KolibriOnKeyPress$qppv |
jz .main_key_press |
else |
jz .main_cycle |
end if |
cmp eax,4 |
if defined @@KolibriOnMouse$qppv |
jz .main_mouse |
else |
jz .main_cycle |
end if |
dec eax |
jnz .main_cycle |
align 4 |
.main_button: |
mov eax,17 |
mov eax,SF_GET_BUTTON |
int 0x40 |
test al,al |
jnz .main_cycle |
shr eax,8 |
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: |
btr dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],31 |
if defined @@KolibriOnClose$qppv |
push esp |
call @@KolibriOnClose$qppv |
pop ecx |
test al,al |
jz .main_button |
end if |
.main_end: |
mov ebx,esp |
lock dec dword [@Kolibri@_ThreadNumber] |
if defined Menuet_SegmentExit & defined Menuet_SegmentExitEnd |
if defined Kolibri_SegmentExit & defined Kolibri_SegmentExitEnd |
jnz .main_else_last_check |
push Menuet_SegmentExitEnd |
push Menuet_SegmentExit |
push Kolibri_SegmentExitEnd |
push Kolibri_SegmentExit |
jmp .main_after_last_check |
end if |
.main_else_last_check: |
290,12 → 324,12 |
mov ebx,1 |
jmp .main_end_wait |
.main_end_wait_loop: |
mov eax,5 |
mov eax,SF_SLEEP |
int 0x40 |
shl ebx,1 |
cmp ebx,MENUET_MUTEX_MAX_TIME_WAIT |
cmp ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT |
jna .main_end_wait |
mov ebx,MENUET_MUTEX_MAX_TIME_WAIT |
mov ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT |
.main_end_wait: |
cmp dword [@Kolibri@_ExitProcessNow],0 |
jnz @Kolibri@ExitProcess$qv |
346,8 → 380,8 |
and dword [ebp+KOLIBRI_THREAD_DATA_FLAG*4],0xFFFFFFFC |
test dl,2 |
jz .redraw_picture |
mov eax,12 |
mov ebx,1 |
mov eax,SF_REDRAW |
mov ebx,SSF_BEGIN_DRAW |
int 0x40 |
xor eax,eax |
mov ebx,[ebp+KOLIBRI_THREAD_DATA_X*4] |
368,17 → 402,14 |
mov esi,ecx |
dec esi |
jz .window_defined |
mov eax,4 |
mov eax,SF_DRAW_TEXT |
mov ebx,0x00070007 |
mov ecx,[ebp+KOLIBRI_THREAD_DATA_C_TITLE*4] |
int 0x40 |
.window_defined: |
mov eax,12 |
mov ebx,2 |
int 0x40 |
.redraw_picture: |
mov eax,12 |
mov ebx,2 |
mov eax,SF_REDRAW |
mov ebx,SSF_END_DRAW |
int 0x40 |
mov esi,[ebp+KOLIBRI_THREAD_DATA_PICTURE*4] |
test esi,esi |
387,15 → 418,15 |
jecxz .redraw_end_draw |
mov al,byte [ebp+KOLIBRI_THREAD_DATA_C_WINDOW*4+3] |
and al,15 |
mov edx,MENUET_BORDER_SIZE*65536+MENUET_HEADER_SIZE |
mov edx,KOLIBRI_BORDER_SIZE*65536+KOLIBRI_HEADER_SIZE |
cmp al,3 |
jnz .redraw_no_skin |
mov eax,48 |
mov ebx,4 |
mov eax,SF_STYLE_SETTINGS |
mov ebx,SSF_GET_SKIN_HEIGHT |
int 0x40 |
mov dx,ax |
.redraw_no_skin: |
mov eax,7 |
mov eax,SF_PUT_IMAGE |
mov ebx,esi |
int 0x40 |
.redraw_end_draw: |
409,22 → 440,25 |
mov ecx,[eax+4] |
mov edx,[eax+8] |
mov esi,[eax+12] |
mov eax,67 |
mov eax,SF_CHANGE_WINDOW |
int 0x40 |
ret |
endp |
;proc @Kolibri@Abort$qv |
; push dword [@Kolibri@DebugPrefix] |
; call @Kolibri@DebugPutString$qpxc |
; mov dword [esp],Menuet_abort_string |
; call @Kolibri@DebugPutString$qpxc |
; pop ecx |
proc @Kolibri@ExitDebug$qv |
push dword [@Kolibri@DebugPrefix] |
call @Kolibri@DebugPutString$qpxc |
mov dword [esp],Kolibri_debug_string |
call @Kolibri@DebugPutString$qpxc |
pop ecx |
jmp @Kolibri@ExitProcess$qv |
endp |
proc @Kolibri@ExitProcess$qv |
lock bts dword [@Kolibri@_ExitProcessNow],0 |
jc .exit_process_wait |
sub esp,1024 |
mov eax,9 |
mov eax,SF_THREAD_INFO |
mov ebx,esp |
mov ecx,-1 |
int 0x40 |
431,7 → 465,7 |
mov esi,eax |
mov edi,[esp+30] |
.exit_process_loop: |
mov eax,9 |
mov eax,SF_THREAD_INFO |
mov ebx,esp |
mov ecx,esi |
int 0x40 |
443,7 → 477,7 |
inc ebx |
jz .exit_process_continue |
mov ebx,eax |
call Menuet_HashInt |
call Kolibri_HashInt |
movzx eax,al |
mov eax,dword [@Kolibri@_ThreadTable+eax*4] |
jmp .exit_process_test |
454,8 → 488,8 |
jz .exit_process_continue |
cmp ebx,[eax+KOLIBRI_THREAD_DATA_PID*4] |
jnz .exit_process_next |
mov eax,18 |
mov ebx,2 |
mov eax,SF_SYSTEM |
mov ebx,SSF_TERMINATE_THREAD |
mov ecx,esi |
int 0x40 |
.exit_process_continue: |
472,7 → 506,7 |
or eax,-1 |
int 0x40 |
.exit_process_wait: |
mov eax,5 |
mov eax,SF_SLEEP |
mov ebx,1 |
.exit_process_wait_loop: |
cmp dword [@Kolibri@_ExitProcessNow],0 |
479,26 → 513,26 |
jl .exit_process_end |
int 0x40 |
shl ebx,1 |
cmp ebx,MENUET_MUTEX_MAX_TIME_WAIT |
cmp ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT |
jna .exit_process_wait_loop |
mov ebx,MENUET_MUTEX_MAX_TIME_WAIT |
mov ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT |
jmp .exit_process_wait_loop |
endp |
proc @Kolibri@ExitThread$qppv,@Kolibri@ThreadMain$qpvt1 |
mov esp,[esp+4] |
jmp Menuet_main_end |
jmp Kolibri_main_end |
endp |
proc @Kolibri@ReturnMessageLoop$qppv,@Kolibri@ThreadMain$qpvt1 |
mov esp,[esp+4] |
bt dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],30 |
jc Menuet_main_end |
jmp Menuet_main_cycle |
jc Kolibri_main_end |
jmp Kolibri_main_cycle |
endp |
proc @Kolibri@Delay$qui uses ebx |
mov eax,5 |
mov eax,SF_SLEEP |
mov ebx,[esp+8] |
int 0x40 |
ret |
505,20 → 539,32 |
endp |
proc @Kolibri@Clock$qv uses ebx |
mov eax,26 |
mov ebx,9 |
mov eax,SF_SYSTEM_GET |
mov ebx,SSF_TIME_COUNT |
int 0x40 |
ret |
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 |
mov eax,3 |
mov eax,SF_GET_SYS_TIME |
int 0x40 |
ret |
endp |
proc @Kolibri@GetTime$qpi |
mov eax,3 |
mov eax,SF_GET_SYS_TIME |
int 0x40 |
mov edx,[esp+4] |
movzx ecx,al |
544,13 → 590,13 |
endp |
proc @Kolibri@GetPackedDate$qv |
mov eax,29 |
mov eax,SF_GET_SYS_DATE |
int 0x40 |
ret |
endp |
proc @Kolibri@GetDate$qpi |
mov eax,29 |
mov eax,SF_GET_SYS_DATE |
int 0x40 |
mov edx,[esp+4] |
movzx ecx,al |
576,8 → 622,8 |
endp |
proc @Kolibri@ReadCommonColors$qpui uses ebx |
mov eax,48 |
mov ebx,3 |
mov eax,SF_STYLE_SETTINGS |
mov ebx,SSF_GET_COLORS |
mov ecx,[esp+8] |
mov edx,40 |
int 0x40 |
585,7 → 631,7 |
endp |
proc @Kolibri@DrawText$qssipxc uses ebx |
mov eax,4 |
mov eax,SF_DRAW_TEXT |
mov ebx,[esp+8-2] |
mov bx,[esp+12] |
mov ecx,[esp+16] |
595,9 → 641,17 |
ret |
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 |
sub esp,1024 |
mov eax,9 |
mov eax,SF_THREAD_INFO |
mov ebx,esp |
mov ecx,[1024+12+24+esp] |
int 0x40 |
612,9 → 666,9 |
jz .get_proc_info_no_name |
lea esi,[esp+10] |
cld |
movs dword [edi],[esi] |
movs dword [edi],[esi] |
movs dword [edi],[esi] |
movsd |
movsd |
movsd |
mov byte [edi],0 |
xor edi,edi |
.get_proc_info_no_name: |
634,10 → 688,10 |
jz .get_proc_info_no_rect |
lea esi,[esp+34] |
cld |
movs dword [edi],[esi] |
movs dword [edi],[esi] |
movs dword [edi],[esi] |
movs dword [edi],[esi] |
movsd |
movsd |
movsd |
movsd |
xor edi,edi |
.get_proc_info_no_rect: |
add esp,1024 |
646,7 → 700,7 |
proc @Kolibri@GetPid$qv uses ebx |
sub esp,1024 |
mov eax,9 |
mov eax,SF_THREAD_INFO |
mov ebx,esp |
mov ecx,-1 |
int 0x40 |
665,11 → 719,11 |
@Kolibri@_HashWord$qui: |
@Kolibri@_HashDword$qui: |
mov eax,[esp+4] |
Menuet_HashInt: |
mul dword [Menuet_hash_int_val0] |
Kolibri_HashInt: |
mul dword [Kolibri_hash_int_val0] |
xor eax,edx |
bswap eax |
mul dword [Menuet_hash_int_val1] |
mul dword [Kolibri_hash_int_val1] |
shrd eax,edx,14 |
bswap eax |
lea eax,[eax+4*eax] |
677,10 → 731,12 |
ret |
endp |
Menuet_hash_int_val0: |
if defined @Kolibri@_HashByte$qui | defined @Kolibri@_HashWord$qui | defined @Kolibri@_HashDword$qui |
Kolibri_hash_int_val0: |
dd 0xA82F94C5 |
Menuet_hash_int_val1: |
Kolibri_hash_int_val1: |
dd 0x9193780B |
end if |
proc @Kolibri@GetThreadData$qv |
call @Kolibri@GetPid$qv |
692,7 → 748,7 |
proc @Kolibri@GetThreadData$qui |
mov eax,[esp+4] |
call Menuet_HashInt |
call Kolibri_HashInt |
movzx eax,al |
cmp dword [@Kolibri@_ThreadScanCount+4],0 |
jnz .get_thread_data_wait |
713,7 → 769,7 |
ret |
.get_thread_data_wait: |
push eax ebx |
mov eax,5 |
mov eax,SF_SLEEP |
mov ebx,1 |
.get_thread_data_wait_loop: |
int 0x40 |
720,9 → 776,9 |
cmp dword [@Kolibri@_ThreadScanCount+4],0 |
jz .get_thread_data_wait_end |
shl ebx,1 |
cmp ebx,MENUET_MUTEX_MAX_TIME_WAIT |
cmp ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT |
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 |
.get_thread_data_wait_end: |
pop ebx eax |
730,14 → 786,14 |
endp |
proc @Kolibri@_GetSkinHeader$qv uses ebx |
mov eax,48 |
mov ebx,4 |
mov eax,SF_STYLE_SETTINGS |
mov ebx,SSF_GET_SKIN_HEIGHT |
int 0x40 |
ret |
endp |
proc @Kolibri@GetScreenSize$qrust1 |
mov eax,14 |
mov eax,SF_GET_SCREEN_SIZE |
int 0x40 |
mov ecx,[esp+8] |
mov word [ecx],ax |
747,14 → 803,14 |
ret |
endp |
proc Menuet_MutexLockNoWait |
proc Kolibri_MutexLockNoWait |
pop eax |
xor al,al |
ret |
endp |
proc Menuet_MutexLockWait uses ebx |
mov eax,5 |
proc Kolibri_MutexLockWait uses ebx |
mov eax,SF_SLEEP |
xor ebx,ebx |
.lock_wait_cycle: |
int 0x40 |
764,23 → 820,23 |
ret |
endp |
proc Menuet_MutexLockWaitTime |
proc Kolibri_MutexLockWaitTime |
cmp dword [esp+12],0 |
jng .MutexLockWait |
push ebx edx |
mov edx,[esp+20] |
mov eax,26 |
mov ebx,9 |
mov eax,SF_SYSTEM_GET |
mov ebx,SSF_TIME_COUNT |
int 0x40 |
add edx,eax |
.lock_wait_time_cycle: |
mov eax,5 |
mov eax,SF_SLEEP |
xor ebx,ebx |
int 0x40 |
shl byte [ecx],1 |
jnz .lock_wait_time_ret_true |
mov eax,26 |
mov ebx,9 |
mov eax,SF_SYSTEM_GET |
mov ebx,SSF_TIME_COUNT |
int 0x40 |
cmp eax,edx |
js .lock_wait_time_cycle |
793,7 → 849,7 |
ret |
endp |
proc Menuet_MutexLock |
proc Kolibri_MutexLock |
shl byte [ecx],1 |
jnz .lock_first |
call eax |
803,21 → 859,21 |
endp |
proc @Kolibri@TryLock$qp14Kolibri@TMutex |
mov eax,Menuet_MutexLockNoWait |
mov eax,Kolibri_MutexLockNoWait |
mov ecx,[esp+4] |
jmp Menuet_MutexLock |
jmp Kolibri_MutexLock |
endp |
proc @Kolibri@Lock$qp14Kolibri@TMutex |
mov eax,Menuet_MutexLockWait |
mov eax,Kolibri_MutexLockWait |
mov ecx,[esp+4] |
jmp Menuet_MutexLock |
jmp Kolibri_MutexLock |
endp |
proc @Kolibri@LockTime$qp14Kolibri@TMutexi |
mov eax,Menuet_MutexLockWaitTime |
mov eax,Kolibri_MutexLockWaitTime |
mov ecx,[esp+4] |
jmp Menuet_MutexLock |
jmp Kolibri_MutexLock |
endp |
proc @Kolibri@UnLock$qp14Kolibri@TMutex |
828,7 → 884,7 |
.unlock_pause: |
mov byte [ecx],0x40 |
push ebx |
mov eax,5 |
mov eax,SF_SLEEP |
xor ebx,ebx |
int 0x40 |
pop ebx |
835,7 → 891,7 |
ret |
endp |
proc Menuet_MutexLockRec |
proc Kolibri_MutexLockRec |
shl byte [ecx],1 |
jng .lock_first |
cmp dword [ecx+4],edx |
853,31 → 909,31 |
.lock_rec_overflow: |
push dword [@Kolibri@DebugPrefix] |
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 |
pop ecx |
jmp @Kolibri@Abort$qv |
jmp @Kolibri@ExitDebug$qv |
endp |
proc @Kolibri@TryLock$qp16Kolibri@TRecMutexui |
mov eax,Menuet_MutexLockNoWait |
mov eax,Kolibri_MutexLockNoWait |
mov ecx,[esp+4] |
mov edx,[esp+8] |
jmp Menuet_MutexLockRec |
jmp Kolibri_MutexLockRec |
endp |
proc @Kolibri@Lock$qp16Kolibri@TRecMutexui |
mov eax,Menuet_MutexLockWait |
mov eax,Kolibri_MutexLockWait |
mov ecx,[esp+4] |
mov edx,[esp+8] |
jmp Menuet_MutexLockRec |
jmp Kolibri_MutexLockRec |
endp |
proc @Kolibri@LockTime$qp16Kolibri@TRecMutexiui |
mov eax,Menuet_MutexLockWaitTime |
mov eax,Kolibri_MutexLockWaitTime |
mov ecx,[esp+4] |
mov edx,[esp+12] |
jmp Menuet_MutexLockRec |
jmp Kolibri_MutexLockRec |
endp |
proc @Kolibri@UnLock$qp16Kolibri@TRecMutexui |
896,7 → 952,7 |
.unlock_rec_pause: |
mov byte [ecx],0x20 |
push ebx |
mov eax,5 |
mov eax,SF_SLEEP |
xor ebx,ebx |
int 0x40 |
pop ebx |
904,10 → 960,10 |
.unlock_rec_notlocked: |
push dword [@Kolibri@DebugPrefix] |
call @Kolibri@DebugPutString$qpxc |
mov dword [esp],Menuet_unlock_rec_notlocked_string |
mov dword [esp],Kolibri_unlock_rec_notlocked_string |
call @Kolibri@DebugPutString$qpxc |
pop ecx |
jmp @Kolibri@Abort$qv |
jmp @Kolibri@ExitDebug$qv |
endp |
proc @Kolibri@DebugPutChar$qc |
918,8 → 974,8 |
cmp cl,10 |
jz .debug_put_char_enter |
.debug_put_char_after_cmp: |
mov eax,63 |
mov ebx,1 |
mov eax,SF_BOARD |
mov ebx,SSF_DEBUG_WRITE |
int 0x40 |
pop ebx |
.debug_put_char_ret: |
926,15 → 982,14 |
ret |
.debug_put_char_enter: |
mov cl,13 |
mov eax,63 |
mov ebx,1 |
mov eax,SF_BOARD |
mov ebx,SSF_DEBUG_WRITE |
int 0x40 |
mov cl,10 |
jmp .debug_put_char_after_cmp |
endp |
proc @Kolibri@DebugPutString$qpxc |
push esi |
proc @Kolibri@DebugPutString$qpxc uses esi |
push dword 0 |
mov esi,dword [esp+12] |
jmp .debug_put_string_test |
947,12 → 1002,12 |
or al,[esi] |
test al,al |
jnz .debug_put_string_loop |
pop ecx esi |
pop ecx |
ret |
endp |
proc @Kolibri@GetKey$qv |
mov eax,2 |
mov eax,SF_GET_KEY |
int 0x40 |
test al,al |
jnz .get_key_eof |
959,20 → 1014,20 |
movzx eax,ah |
ret |
.get_key_eof: |
mov eax,-1 |
mov eax,SF_TERMINATE_PROCESS |
ret |
endp |
proc @Kolibri@GetMouseButton$qv uses ebx |
mov eax,37 |
mov ebx,2 |
mov eax,SF_MOUSE_GET |
mov ebx,SSF_BUTTON |
int 0x40 |
ret |
endp |
proc @Kolibri@GetMousePosition$qrst1o uses ebx |
mov eax,37 |
xor ebx,ebx |
mov eax,SF_MOUSE_GET |
xor ebx,ebx ;SSF_SCREEN_POSITION |
cmp byte [esp+16],0 |
jnz .get_mouse_pos_absolute |
inc ebx |
998,13 → 1053,13 |
mov ebx,[esp+12] |
test edx,edx |
jnz .create_thread_after_new |
if defined MenuetHeapAlloc |
if defined KolibriHeapAlloc |
cmp ebx,4096 |
jnb .create_thread_alloc |
mov ebx,STACKSIZE |
.create_thread_alloc: |
push ebx |
call MenuetHeapAlloc ; Create new dynamic memory of the given size |
call KolibriHeapAlloc ; Create new dynamic memory of the given size |
pop ecx |
test eax,eax |
jnz .create_thread_mem_created |
1027,8 → 1082,8 |
mov ecx,[esp+8] |
mov dword [edx+8],ebx |
mov dword [edx+4],ecx |
mov dword [edx],Menuet_ThreadFinish |
mov eax,51 |
mov dword [edx],Kolibri_ThreadFinish |
mov eax,SF_CREATE_THREAD |
mov ebx,1 |
mov ecx,@Kolibri@ThreadMain$qpvt1 |
int 0x40 |
1037,11 → 1092,11 |
inc ebx |
jnz .create_thread_end |
lock dec dword [@Kolibri@_ThreadNumber] |
if defined MenuetHeapFree |
if defined KolibriHeapFree |
or ebx,[edx+8] |
jz .create_thread_end |
push ebx |
call MenuetHeapFree ; Delete the given dynamic memory |
call KolibriHeapFree ; Delete the given dynamic memory |
pop ecx |
end if |
.create_thread_end: |
1052,23 → 1107,23 |
cld |
mov esi,@Kolibri@_ThreadSavedBegProc |
mov edi,@Kolibri@GetPid$qv |
movs dword [edi],[esi] |
movs dword [edi],[esi] |
movsd |
movsd |
mov edi,@Kolibri@GetThreadData$qv |
movs dword [edi],[esi] |
movs dword [edi],[esi] |
movsd |
movsd |
mov eax,0x90909090 |
mov edi,@Kolibri@_ThreadSavedBegProc |
stos dword [edi] |
stos dword [edi] |
stos dword [edi] |
stos dword [edi] |
stosd |
stosd |
stosd |
stosd |
pop edi esi |
jmp .create_thread_fill_stack |
endp |
proc @Kolibri@_FileAccess$qpv uses ebx |
mov eax,70 |
mov eax,SF_FILE |
mov ebx,[esp+8] |
int 0x40 |
mov ecx,[esp+8] |
1076,12 → 1131,20 |
ret |
endp |
Menuet_abort_string: |
if defined Kolibri_debug_string |
Kolibri_debug_string: |
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 |
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 |
end if |
include "kos_lib.inc" |
/programs/demos/life2/include/kos_heap.h |
---|
1,5 → 1,5 |
#ifndef __MENUET_HEAP_H_INCLUDED_ |
#define __MENUET_HEAP_H_INCLUDED_ |
#ifndef __KOLIBRI_HEAP_H_INCLUDED_ |
#define __KOLIBRI_HEAP_H_INCLUDED_ |
#include <kolibri.h> |
#include <memheap.h> |
13,7 → 13,7 |
void Free(void *mem); |
} |
#ifdef __MENUET__ |
#ifdef __KOLIBRI__ |
namespace Kolibri |
{ |
20,22 → 20,22 |
// Global variables |
MemoryHeap::TFreeSpace _MenuetFreeSpace; |
MemoryHeap::TMemBlock _MenuetMemBlock; |
TMutex _MemHeapMutex = MENUET_MUTEX_INIT; |
MemoryHeap::TFreeSpace _KolibriFreeSpace; |
MemoryHeap::TMemBlock _KolibriMemBlock; |
TMutex _MemHeapMutex = KOLIBRI_MUTEX_INIT; |
// Functions |
void *_HeapInit(void *begin, void *use_end, void *end) |
{ |
MemoryHeap::InitFreeSpace(_MenuetFreeSpace); |
_MenuetMemBlock = MemoryHeap::CreateBlock(begin, end, _MenuetFreeSpace); |
unsigned int use_beg = (unsigned int)MemoryHeap::BlockBegin(_MenuetMemBlock) + |
MemoryHeap::InitFreeSpace(_KolibriFreeSpace); |
_KolibriMemBlock = MemoryHeap::CreateBlock(begin, end, _KolibriFreeSpace); |
unsigned int use_beg = (unsigned int)MemoryHeap::BlockBegin(_KolibriMemBlock) + |
MemoryHeap::BlockAddSize - MemoryHeap::BlockEndSize; |
unsigned int use_size = (unsigned int)use_end; |
if (use_size <= use_beg) return 0; |
else use_size -= use_beg; |
return MemoryHeap::Alloc(_MenuetFreeSpace, use_size); |
return MemoryHeap::Alloc(_KolibriFreeSpace, use_size); |
} |
bool _SetUseMemory(unsigned int use_mem); |
46,13 → 46,13 |
{ |
if (!size) return 0; |
Lock(&_MemHeapMutex); |
void *res = MemoryHeap::Alloc(_MenuetFreeSpace, size); |
void *res = MemoryHeap::Alloc(_KolibriFreeSpace, size); |
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))) |
{ |
res = MemoryHeap::Alloc(_MenuetFreeSpace, size); |
res = MemoryHeap::Alloc(_KolibriFreeSpace, size); |
} |
} |
UnLock(&_MemHeapMutex); |
62,13 → 62,13 |
void *ReAlloc(void *mem, unsigned int size) |
{ |
Lock(&_MemHeapMutex); |
void *res = MemoryHeap::ReAlloc(_MenuetFreeSpace, mem, size); |
void *res = MemoryHeap::ReAlloc(_KolibriFreeSpace, mem, 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))) |
{ |
res = MemoryHeap::ReAlloc(_MenuetFreeSpace, mem, size); |
res = MemoryHeap::ReAlloc(_KolibriFreeSpace, mem, size); |
} |
} |
UnLock(&_MemHeapMutex); |
78,7 → 78,7 |
void Free(void *mem) |
{ |
Lock(&_MemHeapMutex); |
MemoryHeap::Free(_MenuetFreeSpace, mem); |
MemoryHeap::Free(_KolibriFreeSpace, mem); |
UnLock(&_MemHeapMutex); |
} |
85,6 → 85,6 |
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_ |
/programs/demos/life2/include/kos_heap.inc |
---|
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 |
push ebx |
20,7 → 20,7 |
test eax,eax |
jnz .set_use_memory_nomem |
push ecx |
push dword [@Kolibri@_MenuetMemBlock] |
push dword [@Kolibri@_KolibriMemBlock] |
call @@MemoryHeap@ResizeBlock$q20MemoryHeap@TMemBlockpv |
add esp,8 |
mov al,1 |
58,9 → 58,9 |
mov eax,5 |
int 0x40 |
shl ebx,1 |
cmp ebx,MENUET_MUTEX_MAX_TIME_WAIT |
cmp ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT |
jna .heap_free_tf_wait |
mov ebx,MENUET_MUTEX_MAX_TIME_WAIT |
mov ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT |
.heap_free_tf_wait: |
cmp dword [ecx],0 |
jnz @Kolibri@ExitProcess$qv |
67,7 → 67,7 |
lock bts dword [@Kolibri@_MemHeapMutex],0 |
jc .heap_free_tf_wait_loop |
push dword [esp+4] |
push @Kolibri@_MenuetFreeSpace |
push @Kolibri@_KolibriFreeSpace |
call @@MemoryHeap@Free$qr21MemoryHeap@TFreeSpacepv |
add esp,8 |
mov byte [@Kolibri@_MemHeapMutex],0x40 |
/programs/demos/life2/include/kos_lib.h |
---|
1,5 → 1,5 |
#ifndef __MENUET_LIB_H_INCLUDED_ |
#define __MENUET_LIB_H_INCLUDED_ |
#ifndef __KOLIBRI_LIB_H_INCLUDED_ |
#define __KOLIBRI_LIB_H_INCLUDED_ |
// Kolibri interface. |
13,4 → 13,4 |
double Floor(double x); |
} |
#endif // __MENUET_LIB_H_INCLUDED_ |
#endif // __KOLIBRI_LIB_H_INCLUDED_ |
/programs/demos/life2/include/kos_lib.inc |
---|
84,7 → 84,7 |
mov ax,[esp+10] |
shl ax,1 |
cmp ax,0x8680 |
ja Menuet_floor_end |
ja Kolibri_floor_end |
mov ch,4 |
sub esp,2 |
wait |
100,7 → 100,7 |
mov [esp],dx |
fldcw word [esp] |
add esp,2 |
Menuet_floor_end: |
Kolibri_floor_end: |
ret |
endp |
/programs/demos/life2/include/kos_start.inc |
---|
8,6 → 8,9 |
dd U_END+STACKSIZE |
dd @Kolibri@CommandLine,0 |
include "..\..\..\KOSfuncs.inc" |
include "..\..\proc32.inc" |
ptr equ |
offset equ |
short equ |
39,47 → 42,3 |
macro segment 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: |
} |
/programs/demos/life2/include/write_macro.inc |
---|
7,7 → 7,7 |
pushad |
push straddr |
push strend |
jmp @Menuet@DebugPutString$qpxc |
jmp @Kolibri@DebugPutString$qpxc |
straddr db arg,0 |
strend: |
pop eax |