Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 8128 → Rev 8129

/programs/demos/life2/me_cdlg_win.cpp
File deleted
\ No newline at end of file
/programs/demos/life2/me_cdlg.inc
File deleted
/programs/demos/life2/me_cdlg.h
File deleted
/programs/demos/life2/bmp2h.cpp
1,4 → 1,3
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
/programs/demos/life2/include/menuet.h
File deleted
/programs/demos/life2/include/me_heap.h
File deleted
/programs/demos/life2/include/me_heap.inc
File deleted
/programs/demos/life2/include/me_func.inc
File deleted
/programs/demos/life2/include/me_lib.h
File deleted
/programs/demos/life2/include/me_lib.inc
File deleted
/programs/demos/life2/include/me_start.inc
File deleted
/programs/demos/life2/include/me_file.h
File deleted
/programs/demos/life2/include/kolibri.h
0,0 → 1,537
#ifndef __MENUET_H_INCLUDED_
#define __MENUET_H_INCLUDED_
 
#include <kos_lib.h>
 
// Kolibri interface.
 
namespace Kolibri // All kolibri functions, types and data are nested in the (Kolibri) namespace.
{
const char *DebugPrefix = "User program: ";
char CommandLine[257];
 
struct TWindowData // Data for drawing a window.
{
unsigned short WindowType, HeaderType;
unsigned long WindowColor, HeaderColor, BorderColor, TitleColor;
const char *Title;
};
 
struct TStartData // This structure is used only for MenuetOnStart function.
{
unsigned short Left, Width, Top, Height; // Initial window rectangle.
TWindowData WinData;
};
 
typedef void **TThreadData; // Thread data are the fast identifier of thread, contains user dword in
//_ the zero element and stack beginning (or zero if it is unknown) in the first element.
//_ 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
 
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
 
// 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.
 
void Main(); // Main function is called at program startup.
void* ThreadMain(void *user = 0, void *stack_begin = 0);
// Called at thread startup, (user) is placed in thread data as a user dword,
//_ (stack_begin) is placed in thread data as a stack beginning.
//_ Return new value of stack beginning that can be changed in the thread data.
void GetWindowData(TWindowData &win_data); // Write current window data to (win_data).
void GetWindowData(TWindowData &win_data, TThreadData thread_data);
void SetWindowData(const TWindowData &win_data); // Replace current window data by (win_data).
void SetWindowData(const TWindowData &win_data, TThreadData thread_data);
void CloseWindow(); // Close current window when returning to message loop.
void CloseWindow(TThreadData thread_data);
void Redraw(int frame = 0); // Redraw current window immediately, if (frame) is positive redraw the frame too,
void Redraw(int frame, TThreadData thread_data); //_ if (frame) is negative redraw only invalideted window.
void Invalidate(int frame = 0); // Redraw current window when no message will be is the queue,
void Invalidate(int frame, TThreadData thread_data); //_ if (frame) is positive redraw the frame too,
//_ if (frame) is negative do nothing.
void MoveWindow(const int window_rect[/* 4 */]); // Move and resize current window.
 
void Abort(); // Abnormally terminate a program.
void ExitProcess(); // Exit from the process, don't call any destructors of global varyables
void ExitThread(); // Exit from the current thread
void ExitThread(TThreadData thread_data);
void ReturnMessageLoop(); // Return to the message loop of the thread. Exit from the thread
void ReturnMessageLoop(TThreadData thread_data); //_ if it is called from (MenuetOnStart).
 
void Delay(unsigned int time); // Delay the execution of the program during (time) hundredth seconds.
unsigned int Clock(); // Return the time from starting of the system to this moment in hundredth of seconds.
int GetPackedTime(); // Return the current time of day in binary-decimal format 0x00SSMMHH.
void GetTime(int t[/* 3 */]); // Write the current time to (t): t[0] = second, t[1] = minute, t[2] = hour.
int GetPackedDate(); // Return the current date in binary-decimal format 0x00YYDDMM.
void GetDate(int d[/* 3 */]); // Write the current date to (d): d[0] = day, d[1] = month, d[2] = year.
void GetTimeDate(int t[/* 6 */]); // Write the current time and date to (t): t[0] = second,
//_ t[1] = minute, t[2] = hour, t[3] = day, t[4] = month, t[5] = year.
void ReadCommonColors(unsigned int colors[/* 10 */]); // Writes standart window colors to (colors).
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 = -1);
// Write (pid_for) process information to variables parameters points, return
//_ the number of processes. (pid_for) equal to (-1) means current process.
unsigned int GetPid(); // Return the current thread identifier (pid).
unsigned int GetPid(TThreadData thread_data);
TThreadData GetThreadData(); // Return the thread data of the current thread.
TThreadData GetThreadData(unsigned int pid); // Return the thread data of the thread with the given pid.
 
void* GetPicture(unsigned short &width, unsigned short &height);
void* GetPicture(unsigned short &width, unsigned short &height, TThreadData thread_data);
// Return the picture on the window and write its width and height to (width) and (height).
void SetPicture(void *picture, unsigned short width, unsigned short height);
void SetPicture(void *picture, unsigned short width, unsigned short height, TThreadData thread_data);
// Replace the picture on the window by the given picture with the given width and height.
void GetBorderHeader(unsigned short &border_size, unsigned short &header_size);
void GetBorderHeader(unsigned short &border_size, unsigned short &header_size, TThreadData thread_data);
// Write the border thickness to (border_size) and header height to (header_size).
void GetClientSize(unsigned short &width, unsigned short &height);
void GetClientSize(unsigned short &width, unsigned short &height, TThreadData thread_data);
// Write the client area width and height to (width) and (height) parameters.
void GetClientSize(unsigned short &width, unsigned short &height, int win_width, int win_height);
void GetClientSize(unsigned short &width, unsigned short &height, int win_width, int win_height, TThreadData thread_data);
// Write the client area size of window with the width (win_width)
//_ and height (win_height) to (width) and (height) parameters.
void GetScreenSize(unsigned short &width, unsigned short &height);
// Write the screen width and height to (width) and (height) parameters.
 
void InitMutex(TMutex *mutex); // Initialize the simple mutex.
void InitRecMutex(TRecMutex *mutex); // Initialize the recursive mutex.
bool TryLock(TMutex *mutex); // Try to lock the mutex without waitting, return true if lock.
bool TryLock(TRecMutex *mutex);
bool TryLock(TRecMutex *mutex, TThreadData thread_data);
bool TryLock(TRecMutex *mutex, unsigned int pid);
void Lock(TMutex *mutex); // Lock mutex and wait for it if this necessary.
void Lock(TRecMutex *mutex);
void Lock(TRecMutex *mutex, TThreadData thread_data);
void Lock(TRecMutex *mutex, unsigned int pid);
bool LockTime(TMutex *mutex, int time);
bool LockTime(TRecMutex *mutex, int time); // Lock mutex and wait for it during (time) hundredth seconds.
bool LockTime(TRecMutex *mutex, int time, TThreadData thread_data);
bool LockTime(TRecMutex *mutex, int time, unsigned int pid);
void UnLock(TMutex *mutex); // Unlock mutex
void UnLock(TRecMutex *mutex);
void UnLock(TRecMutex *mutex, TThreadData thread_data);
void UnLock(TRecMutex *mutex, unsigned int pid);
 
void DebugPutChar(char c); // Put the character to the debug board.
void DebugPutString(const char *s); // Put the string to the debug board.
int GetKey(); // Return key pressed by user or -1 if no key was pressed.
int GetMouseButton(); // Return buttons pressed: 0 - no buttons, 1 - left button, 2 - right button, 3 - both buttons.
void GetMousePosition(short &x, short &y, bool absolute = false);
// Write mouse position to (x) and (y): absolute if (absolute) is true and relative the window otherwise.
void GetMousePosPicture(short &x, short &y);
 
int GetThreadNumber(); // Return the number of threads currently executing.
bool WasThreadCreated(); // Return true if there was created at least one thread except the main thred.
unsigned int CreateThread(void *user = 0, unsigned int stack_size = 0, void *stack_end = 0);
// Create a new thread with the user dword (user) and stack pointer (stack_end).
//_ If (stack_end) is zero, create stack in dynamic memory of size (stack_size) or
//_ the same size as the main thread if (stack_size) less that 4096. Set the beginning
//_ of the stack if (stack_end) is zero or (stack_size) is not zero, in this case stack
//_ will be deleted automaticaly from dynamic memory at the finish of the thread.
}
 
// Function, defined outside.
 
bool MenuetOnStart(Kolibri::TStartData &me_start, Kolibri::TThreadData thread_data);
// Window will be created iff return value is true.
bool MenuetOnClose(Kolibri::TThreadData thread_data); // Window will be closed iff return value is true.
int MenuetOnIdle(Kolibri::TThreadData thread_data); // Return the time to wait next message.
void MenuetOnSize(int window_rect[/* 4 */], Kolibri::TThreadData thread_data); // When the window is resized.
void MenuetOnKeyPress(Kolibri::TThreadData thread_data); // When user press a key.
void MenuetOnMouse(Kolibri::TThreadData thread_data); // When user move a mouse.
 
#ifdef __MENUET__
 
namespace Kolibri
{
// Structures.
 
struct TMutex // Simple mutex can be locked only once at a time.
{
unsigned int mut;
};
#undef MENUET_MUTEX_INIT
#define MENUET_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
 
// Global variables.
 
volatile TThreadData _ThreadTable[256];
volatile unsigned int _ThreadScanCount[2] = {0, 0};
volatile int _ThreadNumber = 1;
volatile int _ExitProcessNow = 0;
TMutex _ThreadMutex = MENUET_MUTEX_INIT;
unsigned int _ThreadSavedBegProc[4];
 
// Inline functions.
 
inline void GetWindowData(TWindowData &win_data) {GetWindowData(win_data, GetThreadData());}
 
inline void SetWindowData(const TWindowData &win_data) {SetWindowData(win_data, GetThreadData());}
 
inline void CloseWindow() {CloseWindow(GetThreadData());}
 
inline void Redraw(int frame) {Redraw(frame, GetThreadData());}
 
inline void Invalidate(int frame) {Invalidate(frame, GetThreadData());}
 
inline void* GetPicture(unsigned short &width, unsigned short &height)
{
return GetPicture(width, height, GetThreadData());
}
 
inline void SetPicture(void *picture, unsigned short width, unsigned short height)
{
SetPicture(picture, width, height, GetThreadData());
}
 
inline void GetBorderHeader(unsigned short &border_size, unsigned short &header_size)
{
GetBorderHeader(border_size, header_size, GetThreadData());
}
 
inline void GetClientSize(unsigned short &width, unsigned short &height)
{
unsigned int pid;
int rect[4];
GetProcessInfo(0, 0, 0, &pid, rect);
GetClientSize(width, height, rect[2], rect[3], GetThreadData(pid));
}
 
inline void GetClientSize(unsigned short &width, unsigned short &height, TThreadData thread_data)
{
int rect[4];
GetProcessInfo(0, 0, 0, 0, rect);
GetClientSize(width, height, rect[2], rect[3], thread_data);
}
 
inline void GetClientSize(unsigned short &width, unsigned short &height, int win_width, int win_height)
{
GetClientSize(width, height, win_width, win_height, GetThreadData());
}
 
inline void GetTimeDate(int t[/* 6 */]) {GetTime(t); GetDate(t + 3);}
 
inline void InitMutex(TMutex *mutex) {mutex->mut = 0;}
 
inline void InitRecMutex(TRecMutex *mutex) {mutex->mut = 0; mutex->pid = -1;}
 
inline bool TryLock(TRecMutex *mutex) {return TryLock(mutex, GetPid());}
 
inline bool TryLock(TRecMutex *mutex, TThreadData thread_data) {return TryLock(mutex, GetPid(thread_data));}
 
inline void Lock(TRecMutex *mutex) {Lock(mutex, GetPid());}
 
inline void Lock(TRecMutex *mutex, TThreadData thread_data) {Lock(mutex, GetPid(thread_data));}
 
inline bool LockTime(TRecMutex *mutex, int time) {return LockTime(mutex, time, GetPid());}
 
inline bool LockTime(TRecMutex *mutex, int time, TThreadData thread_data)
{return LockTime(mutex, time, GetPid(thread_data));}
 
inline void UnLock(TRecMutex *mutex) {UnLock(mutex, GetPid());}
 
inline void UnLock(TRecMutex *mutex, TThreadData thread_data) {UnLock(mutex, GetPid(thread_data));}
 
inline int GetThreadNumber() {return _ThreadNumber;}
 
// Constants from fasm.
 
#include <kos_func.inc>
 
// Functions.
 
unsigned char _HashByte(unsigned int value);
unsigned short _HashWord(unsigned int value);
unsigned int _HashDword(unsigned int value);
 
void _GetStartData(TStartData &start_data, TThreadData thread_data)
{
start_data.Left = (unsigned short)((unsigned long)thread_data[MENUET_THREAD_DATA_X] >> 16);
start_data.Width = (unsigned short)((unsigned long)thread_data[MENUET_THREAD_DATA_X]);
start_data.Top = (unsigned short)((unsigned long)thread_data[MENUET_THREAD_DATA_Y] >> 16);
start_data.Height = (unsigned short)((unsigned long)thread_data[MENUET_THREAD_DATA_Y]);
GetWindowData(start_data.WinData, thread_data);
}
 
void _SetStartData(const TStartData &start_data, TThreadData thread_data)
{
(unsigned long&)thread_data[MENUET_THREAD_DATA_X] =
((unsigned int)start_data.Left << 16) | start_data.Width;
(unsigned long&)thread_data[MENUET_THREAD_DATA_Y] =
((unsigned int)start_data.Top << 16) | start_data.Height;
SetWindowData(start_data.WinData, thread_data);
}
 
void _ApplyCommonColors(TWindowData &win_data)
{
unsigned int colors[10];
ReadCommonColors(colors);
win_data.WindowColor = colors[5];
win_data.HeaderColor = colors[1];
win_data.BorderColor = colors[0];
win_data.TitleColor = colors[4];
}
 
void _SetValueFunctionPriority(void *beg, int n)
{
int k, i;
unsigned char num[256];
for (i = 0; i < 256; i++) num[i] = 0;
for (k = 0; k < n; k++)
{
i = ((unsigned char*)beg + 6*k)[1];
((unsigned char*)beg + 6*k)[0] = num[i];
if (num[i] != 255) num[i]++;
}
}
 
void _CallFunctionPriority(void *beg, void *end, bool reverse = false)
{
struct _Local
{
static int cmp(void *beg, int i, int j)
{
unsigned char *x = (unsigned char*)beg + 6*i;
unsigned char *y = (unsigned char*)beg + 6*j;
if (*(unsigned short*)x < *(unsigned short*)y) return -1;
if (*(unsigned short*)x > *(unsigned short*)y) return 1;
return 0;
}
 
static void swap(void *beg, int i, int j)
{
unsigned char *x = (unsigned char*)beg + 6*i;
unsigned char *y = (unsigned char*)beg + 6*j;
short s;
int t;
s = *(short*)x; *(short*)x = *(short*)y; *(short*)y = s;
x += 2; y += 2;
t = *(int*)x; *(int*)x = *(int*)y; *(int*)y = t;
}
 
static void call(void *beg, int i)
{
unsigned char *x = (unsigned char*)beg + 6*i;
(*(void(**)())(x+2))();
}
};
 
if (!beg || !end || end <= beg) return;
int i, j, k, m, n;
n = ((unsigned char*)end - (unsigned char*)beg) / 6;
if (n <= 0) return;
_SetValueFunctionPriority(beg, n);
m = n; k = n;
while (m > 1)
{
if (k > 0) k--;
else _Local::swap(beg, 0, --m);
j = k;
for (;;)
{
i = j;
if (2*i + 1 >= m) break;
if (_Local::cmp(beg, 2*i + 1, j) > 0) j = 2*i + 1;
if (2*i + 2 < m && _Local::cmp(beg, 2*i + 2, j) > 0) j = 2*i + 2;
if (i == j) break;
_Local::swap(beg, i, j);
}
}
if (!reverse)
{
for (k = 0; k < n; k++) _Local::call(beg, k);
}
else
{
for (k = n-1; k >= 0; k--) _Local::call(beg, k);
}
}
 
bool _CallStart(TThreadData thread_data, void *init = 0, void *init_end = 0)
{
struct _TThreadDataTemplate
{
unsigned int data[12];
};
static const _TThreadDataTemplate _ThreadDataTemplate =
{{3, 0x00320100, 0x00320100, 0x03FFFFFF, 0x806060FF, 0x00000000, 0x00FFFF40, 0, 0, 0, -1, -1}};
 
unsigned int pid = GetPid();
volatile TThreadData *thread_table_item;
Lock(&_ThreadMutex);
if (_ExitProcessNow) ExitProcess();
thread_table_item = &_ThreadTable[_HashByte(pid)];
thread_data[MENUET_THREAD_DATA_NEXT] = (void*)*thread_table_item;
(unsigned int&)thread_data[MENUET_THREAD_DATA_PID] = pid;
*(_TThreadDataTemplate*)(thread_data + MENUET_THREAD_DATA_FLAG) = _ThreadDataTemplate;
*thread_table_item = thread_data;
UnLock(&_ThreadMutex);
if (_ExitProcessNow) ExitProcess();
_CallFunctionPriority(init, init_end, false);
TStartData start_data;
_GetStartData(start_data, thread_data);
_ApplyCommonColors(start_data.WinData);
(unsigned int&)thread_data[MENUET_THREAD_DATA_FLAG] |= 0x40000000;
thread_data[MENUET_THREAD_DATA_TITLE] = (void*)(&start_data);
if (!MenuetOnStart(start_data, thread_data)) return false;
(unsigned int&)thread_data[MENUET_THREAD_DATA_FLAG] &= ~0x40000000;
_SetStartData(start_data, thread_data);
return true;
}
 
void _RemoveThreadData(TThreadData thread_data, void *exit = 0, void *exit_end = 0)
{
_CallFunctionPriority(exit, exit_end, true);
volatile TThreadData *thread_table_item;
Lock(&_ThreadMutex);
if (_ExitProcessNow) ExitProcess();
thread_table_item = &_ThreadTable[_HashByte(GetPid(thread_data))];
while (*thread_table_item)
{
if (*thread_table_item == thread_data)
{
*thread_table_item = (TThreadData)thread_data[MENUET_THREAD_DATA_NEXT];
break;
}
thread_table_item = (TThreadData*)(*thread_table_item + MENUET_THREAD_DATA_NEXT);
}
UnLock(&_ThreadMutex);
if (_ExitProcessNow) ExitProcess();
}
 
void GetWindowData(TWindowData &win_data, TThreadData thread_data)
{
if ((unsigned int)thread_data[MENUET_THREAD_DATA_FLAG] & 0x40000000)
{
win_data = ((TStartData*)thread_data[MENUET_THREAD_DATA_TITLE])->WinData;
return;
}
win_data.WindowType = (unsigned short)((unsigned int)thread_data[MENUET_THREAD_DATA_C_WINDOW] >> 24);
win_data.HeaderType = (unsigned short)((unsigned int)thread_data[MENUET_THREAD_DATA_C_HEADER] >> 24);
win_data.WindowColor = (unsigned int)thread_data[MENUET_THREAD_DATA_C_WINDOW] & 0xFFFFFF;
win_data.HeaderColor = (unsigned int)thread_data[MENUET_THREAD_DATA_C_HEADER] & 0xFFFFFF;
win_data.BorderColor = (unsigned int)thread_data[MENUET_THREAD_DATA_C_BORDER] & 0xFFFFFF;
win_data.TitleColor = (unsigned int)thread_data[MENUET_THREAD_DATA_C_TITLE] & 0xFFFFFF;
win_data.Title = (char*)thread_data[MENUET_THREAD_DATA_TITLE];
}
 
void SetWindowData(const TWindowData &win_data, TThreadData thread_data)
{
if ((unsigned int)thread_data[MENUET_THREAD_DATA_FLAG] & 0x40000000)
{
((TStartData*)thread_data[MENUET_THREAD_DATA_TITLE])->WinData = win_data;
return;
}
(unsigned int&)thread_data[MENUET_THREAD_DATA_C_WINDOW] =
((unsigned int)win_data.WindowType << 24) | (win_data.WindowColor & 0xFFFFFF);
(unsigned int&)thread_data[MENUET_THREAD_DATA_C_HEADER] =
((unsigned int)win_data.HeaderType << 24) | (win_data.HeaderColor & 0xFFFFFF);
(unsigned int&)thread_data[MENUET_THREAD_DATA_C_BORDER] = win_data.BorderColor & 0xFFFFFF;
(unsigned int&)thread_data[MENUET_THREAD_DATA_C_TITLE] = win_data.TitleColor & 0xFFFFFF;
thread_data[MENUET_THREAD_DATA_TITLE] = (void*)win_data.Title;
Invalidate(1, thread_data);
}
 
void CloseWindow(TThreadData thread_data)
{
(unsigned int&)thread_data[MENUET_THREAD_DATA_FLAG] |= 0x80000000;
}
 
void Invalidate(int frame, TThreadData thread_data)
{
if (frame < 0) return;
(unsigned int&)thread_data[MENUET_THREAD_DATA_FLAG] |= (frame ? 3 : 1);
}
 
void* GetPicture(unsigned short &width, unsigned short &height, TThreadData thread_data)
{
width = (unsigned short)((unsigned int)thread_data[MENUET_THREAD_DATA_SZ_PICT] >> 16);
height = (unsigned short)((unsigned int)thread_data[MENUET_THREAD_DATA_SZ_PICT]);
return (void*)thread_data[MENUET_THREAD_DATA_PICTURE];
}
 
void SetPicture(void *picture, unsigned short width, unsigned short height, TThreadData thread_data)
{
thread_data[MENUET_THREAD_DATA_PICTURE] = (void*)picture;
(unsigned int&)thread_data[MENUET_THREAD_DATA_SZ_PICT] =
(width == 0 || height == 0) ? 0 : (((unsigned int)width << 16) | height);
Invalidate(0, thread_data);
}
 
int _GetSkinHeader();
 
void GetBorderHeader(unsigned short &border_size, unsigned short &header_size, TThreadData thread_data)
{
int win_type = ((unsigned int)thread_data[MENUET_THREAD_DATA_FLAG] & 0x40000000) ?
((TStartData*)thread_data[MENUET_THREAD_DATA_TITLE])->WinData.WindowType :
((unsigned int)thread_data[MENUET_THREAD_DATA_C_WINDOW] >> 24);
border_size = MENUET_BORDER_SIZE;
header_size = short(((win_type & 15) == 3) ? _GetSkinHeader() : MENUET_HEADER_SIZE);
}
 
void GetClientSize(unsigned short &width, unsigned short &height,
int win_width, int win_height, TThreadData thread_data)
{
const int MAX_SIZE = 32767;
unsigned short border_size, header_size;
GetBorderHeader(border_size, header_size, thread_data);
win_width -= 2 * border_size;
win_height -= border_size + header_size;
if (win_width < 0) win_width = 0;
else if (win_width > MAX_SIZE) win_width = MAX_SIZE;
if (win_height < 0) win_height = 0;
else if (win_height > MAX_SIZE) win_height = MAX_SIZE;
width = (unsigned short)win_width;
height = (unsigned short)win_height;
}
 
void GetMousePosPicture(short &x, short &y)
{
unsigned short dx, dy;
GetMousePosition(x, y);
GetBorderHeader(dx, dy);
x -= dx; y -= dy;
}
}
 
#else // def __MENUET__
 
namespace Kolibri
{
struct TMutex
{
unsigned int mut;
 
TMutex();
~TMutex();
};
#undef MENUET_MUTEX_INIT
#define MENUET_MUTEX_INIT TMutex()
 
struct TRecMutex
{
unsigned int mut;
 
TRecMutex();
~TRecMutex();
};
#undef MENUET_REC_MUTEX_INIT
#define MENUET_REC_MUTEX_INIT TRecMutex()
}
 
#endif // else: def __MENUET__
 
#endif // ndef __MENUET_H_INCLUDED_
 
/programs/demos/life2/include/kos_file.h
0,0 → 1,278
#ifndef __MENUET_FILE_H_INCLUDED_
#define __MENUET_FILE_H_INCLUDED_
 
#include <kolibri.h>
#include <kos_heap.h>
 
// Kolibri file interface.
 
namespace Kolibri // All kolibri functions, types and data are nested in the (Kolibri) namespace.
{
struct _FileDataStruct;
typedef _FileDataStruct *TFileData;
 
TFileData FileOpen(const char *name, unsigned int buffer_length = 1024);
int FileClose(TFileData file_data);
bool FileEof(TFileData file_data);
unsigned int FileGetPosition(TFileData file_data);
void FileSetPosition(TFileData file_data, unsigned int pos);
void FileReset(TFileData file_data);
unsigned int FileGetLength(TFileData file_data);
int FileTestRead(TFileData file_data);
int FileRead(TFileData file_data, void *mem, int size);
}
 
#ifdef __MENUET__
 
namespace Kolibri
{
// Define the file data structure.
 
struct _FileDataStruct
{
unsigned int length;
unsigned int position;
unsigned int *buffer;
unsigned int access_param[5];
 
enum {PosName = (unsigned int)(((_FileDataStruct*)0)->access_param + 5)};
};
 
// Inline functions.
 
inline bool FileEof(TFileData file_data)
{
return file_data && file_data->position >= file_data->length;
}
 
inline unsigned int FileGetPosition(TFileData file_data)
{
return file_data ? file_data->position : 0;
}
 
inline void FileReset(TFileData file_data)
{
if (!file_data) return;
file_data->length = -1;
file_data->position = 0;
if (file_data->buffer) file_data->buffer[1] = 0;
}
 
// Functions.
 
int _FileAccess(void *file_access_param);
 
TFileData FileOpen(const char *name, unsigned int buffer_length)
{
if (!name || !name[0]) return 0;
unsigned int name_len = StrLen(name) + 1;
unsigned int data_len = (_FileDataStruct::PosName + name_len + 3) & ~3;
buffer_length = (buffer_length / MENUET_FILE_BLOCK_SIZE) * MENUET_FILE_BLOCK_SIZE;
if (buffer_length) data_len += buffer_length + 2*sizeof(unsigned int);
TFileData file = (TFileData)Alloc(_FileDataStruct::PosName + data_len);
if (!file) return 0;
file->length = -1;
file->position = 0;
if (buffer_length)
{
file->buffer = (unsigned int*)((char*)file + data_len) - 2;
file->buffer[0] = buffer_length;
file->buffer[1] = 0;
}
MemCopy(file->access_param + 5, name, name_len);
unsigned int attr[40/4];
file->access_param[0] = 5;
file->access_param[1] = 0;
file->access_param[2] = 0;
file->access_param[3] = 0;
file->access_param[4] = (int)attr;
_FileAccess(file->access_param);
file->length = attr[32/4];
return file;
}
 
int FileClose(TFileData file_data)
{
if (!file_data) return -1;
Free(file_data);
return 0;
}
 
void FileSetPosition(TFileData file_data, unsigned int pos)
{
if (!file_data) return;
if (file_data->buffer && file_data->buffer[1])
{
if (pos >= file_data->position && pos < file_data->position + file_data->buffer[1])
{
file_data->buffer[1] -= pos - file_data->position;
}
else file_data->buffer[1] = 0;
}
file_data->position = pos;
}
 
int _FileReadBuffer(TFileData file_data, void *mem, int size, void *temp_mem = 0)
{
unsigned int *buffer;
if (!file_data || !mem || size <= 0) return -1;
if (file_data->buffer) buffer = file_data->buffer;
else if (temp_mem)
{
buffer = (unsigned int*)((char*)temp_mem + MENUET_FILE_BLOCK_SIZE);
}
else return 0;
if (!buffer[1]) return 0;
if (file_data->position >= file_data->length)
{
buffer[1] = 0;
return 0;
}
unsigned int buf_size = file_data->length - file_data->position;
if (buf_size > buffer[1]) buf_size = buffer[1];
if ((unsigned int)size >= buf_size) size = buf_size;
MemCopy(mem, (char*)buffer - buffer[1], size);
file_data->position += size;
if ((unsigned int)size >= buf_size) buffer[1] = 0;
else buffer[1] -= size;
return size;
}
 
int _FileReadSystem(TFileData file_data, void *mem, int size)
{
int res;
unsigned int len0, len1;
size /= MENUET_FILE_BLOCK_SIZE;
if (!file_data || !mem || size <= 0) return -1;
file_data->access_param[0] = 0;
file_data->access_param[1] = (file_data->position / MENUET_FILE_BLOCK_SIZE) * MENUET_FILE_BLOCK_SIZE;
file_data->access_param[2] = 0;
file_data->access_param[3] = size * MENUET_FILE_BLOCK_SIZE;
file_data->access_param[4] = (unsigned int)mem;
res = _FileAccess(file_data->access_param);
if (res != 0 && res != 6) return (res & 255) - 1024;
if (file_data->length <= file_data->position) return 0;
len0 = file_data->length - file_data->position;
len1 = size * MENUET_FILE_BLOCK_SIZE - (file_data->position % MENUET_FILE_BLOCK_SIZE);
return (len0 <= len1) ? len0 : len1;
}
 
int _FileBufferSystem(TFileData file_data, void *&temp_mem)
{
int res;
unsigned int *buffer;
if (!file_data) return -1;
if (file_data->buffer) buffer = file_data->buffer;
else
{
if (!temp_mem)
{
temp_mem = Alloc(MENUET_FILE_BLOCK_SIZE + 2*sizeof(unsigned int));
if (!temp_mem) return -10;
}
buffer = (unsigned int*)((char*)temp_mem + MENUET_FILE_BLOCK_SIZE);
buffer[0] = MENUET_FILE_BLOCK_SIZE;
}
buffer[1] = buffer[0];
res = _FileReadSystem(file_data, (char*)buffer - buffer[1], buffer[1]);
if (res < 0) buffer[1] = 0;
else buffer[1] -= file_data->position % MENUET_FILE_BLOCK_SIZE;
return res;
}
 
int FileTestRead(TFileData file_data)
{
int res;
void *temp_mem = 0;
if (!file_data) return -1;
if (file_data->buffer && file_data->buffer[1]) return 0;
res = _FileBufferSystem(file_data, temp_mem);
if (temp_mem) Free(temp_mem);
return (res < 0) ? res : 0;
}
 
int FileRead(TFileData file_data, void *mem, int size)
{
int tlen, res, read_len;
void *temp_mem = 0;
res = _FileReadBuffer(file_data, mem, size);
if (res < 0 || res >= size) return res;
read_len = res;
mem = (char*)mem + res;
size -= res;
tlen = file_data->position % MENUET_FILE_BLOCK_SIZE;
if (tlen)
{
res = _FileBufferSystem(file_data, temp_mem);
if (res < 0)
{
if (temp_mem) Free(temp_mem);
return read_len ? read_len : res;
}
res = _FileReadBuffer(file_data, mem, size);
read_len += res;
if (res >= size || file_data->length <= file_data->position ||
file_data->length - file_data->position <= res)
{
if (temp_mem) Free(temp_mem);
return read_len;
}
mem = (char*)mem + res;
size -= res;
}
if (size >= (file_data->buffer ? file_data->buffer[0] : MENUET_FILE_BLOCK_SIZE))
{
res = _FileReadSystem(file_data, mem, size);
if (res < 0)
{
if (temp_mem) Free(temp_mem);
return read_len ? read_len : res;
}
file_data->position += res;
read_len += res;
if (res < (size / MENUET_FILE_BLOCK_SIZE) * MENUET_FILE_BLOCK_SIZE)
{
if (temp_mem) Free(temp_mem);
return read_len;
}
mem = (char*)mem + res;
size -= res;
}
if (size)
{
res = _FileBufferSystem(file_data, temp_mem);
if (res < 0)
{
if (temp_mem) Free(temp_mem);
return read_len ? read_len : res;
}
read_len += _FileReadBuffer(file_data, mem, size, temp_mem);
}
if (temp_mem) Free(temp_mem);
return read_len;
}
// Inline functions.
 
inline unsigned int FileGetLength(TFileData file_data)
{
if (!file_data) return -1;
if (file_data->length == -1) FileTestRead(file_data);
return file_data->length;
}
}
 
#else // def __MENUET__
 
namespace Kolibri
{
struct _FileDataStruct
{
unsigned int data;
};
}
 
#endif // else: def __MENUET__
 
#endif // ndef __MENUET_FILE_H_INCLUDED_
 
/programs/demos/life2/include/kos_func.inc
0,0 → 1,1078
;const int
MENUET_BORDER_SIZE = 4;
;const int
MENUET_HEADER_SIZE = 20;
 
;const int
MENUET_THREAD_DATA_USER = 0; // Thread data begin from the user dword
;const int
MENUET_THREAD_DATA_ST_BEGIN = 1; // Stack beginning follows after the user dword
;const int
MENUET_THREAD_DATA_NEXT = 2;
;const int
MENUET_THREAD_DATA_PID = 3;
;const int
MENUET_THREAD_DATA_FLAG = 4;
;const int
MENUET_THREAD_DATA_X = 5;
;const int
MENUET_THREAD_DATA_Y = 6;
;const int
MENUET_THREAD_DATA_C_WINDOW = 7;
;const int
MENUET_THREAD_DATA_C_HEADER = 8;
;const int
MENUET_THREAD_DATA_C_BORDER = 9;
;const int
MENUET_THREAD_DATA_C_TITLE = 10;
;const int
MENUET_THREAD_DATA_TITLE = 11;
;const int
MENUET_THREAD_DATA_PICTURE = 12;
;const int
MENUET_THREAD_DATA_SZ_PICT = 13;
;const int
MENUET_THREAD_DATA_LAST_SX = 14;
;const int
MENUET_THREAD_DATA_LAST_SY = 15;
;const int
MENUET_THREAD_DATA_LEN = 16;
 
;const int
MENUET_MUTEX_MAX_TIME_WAIT = 20;
 
;const int
MENUET_FILE_BLOCK_SIZE = 512;
 
;const int
MENUET_FILE_MEMORY_OS_NEED = 4096;
 
;/***
 
macro segment name
{
segment name
if name eq _init_ | name eq _INIT_
Menuet_SegmentInit:
else if name eq _exit_ | name eq _EXIT_
Menuet_SegmentExit:
end if
}
 
macro endseg name
{
if name eq _init_ | name eq _INIT_
Menuet_SegmentInitEnd:
else if name eq _exit_ | name eq _EXIT_
Menuet_SegmentExitEnd:
end if
endseg name
}
 
macro Menuet_Put_MovEaxVal_Ret address,val
{
mov byte [address],0xB8
mov dword [address+4],0xC089C300
mov dword [address+1],val
}
 
proc @Kolibri@Main$qv
and esp,not 3
sub esp,1024
mov eax,9
mov ebx,esp
mov ecx,-1
int 0x40
mov ebx,[esp+26]
mov edx,[esp+30]
lea eax,[ebx-0x20]
add esp,1024
cmp esp,eax
cmova esp,eax
and esp,not 3
if defined @Kolibri@CommandLine
mov byte [@Kolibri@CommandLine+256], 0
end if
xor eax,eax
cld
mov edi,@Kolibri@_ThreadTable
mov ecx,256
rep stos dword [edi]
mov esi,@Kolibri@GetPid$qv
mov edi,@Kolibri@_ThreadSavedBegProc
movs dword [edi],[esi]
movs dword [edi],[esi]
mov esi,@Kolibri@GetThreadData$qv
movs dword [edi],[esi]
movs dword [edi],[esi]
Menuet_Put_MovEaxVal_Ret @Kolibri@GetPid$qv,edx
if defined MenuetHeapInit
mov ecx,esp
push ebx
push ecx
push U_END
call MenuetHeapInit ; 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
else
xor eax,eax
push eax
push eax
end if
call @Kolibri@ThreadMain$qpvt1
.ThreadFinish:
add esp,8
if defined MenuetHeapFreeAndThreadFinish
test eax,eax
jz .ThreadFinish_end
push dword @Kolibri@_ExitProcessNow
push eax
call MenuetHeapFreeAndThreadFinish ; 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
int 0x40
endp
 
proc @Kolibri@ThreadMain$qpvt1
xchg ebx,[esp+4]
xchg ebp,[esp+8]
push esi edi
sub esp,MENUET_THREAD_DATA_LEN*4
mov [esp],ebx
mov [esp+4],ebp
mov eax,40
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
jmp .main_after_first_check
end if
.main_else_first_check:
xor eax,eax
push eax eax
.main_after_first_check:
push ebx
call @@Kolibri@_CallStart$qppvpvt2
add esp,12
test al,al
jnz .main_test_close_first
jmp .main_end
.main_close_first:
btr dword [esp+MENUET_THREAD_DATA_FLAG*4],31
push esp
call @@MenuetOnClose$qppv
pop ecx
test al,al
jnz .main_end
.main_test_close_first:
cmp dword [esp+MENUET_THREAD_DATA_FLAG*4],0
jl .main_close_first
push esp
push dword 1
call @Kolibri@Redraw$qippv
add esp,8
.main_paint_msg:
or dword [esp+MENUET_THREAD_DATA_FLAG*4],3
sub esp,1024
mov eax,9
mov ebx,esp
mov ecx,-1
int 0x40
mov eax,[esp+34]
mov ebx,[esp+38]
mov ecx,[esp+42]
mov edx,[esp+46]
add esp,1024
cmp ecx,[esp+MENUET_THREAD_DATA_LAST_SX*4]
jnz .main_size
cmp edx,[esp+MENUET_THREAD_DATA_LAST_SY*4]
jz .main_paint
.main_size:
mov [esp+MENUET_THREAD_DATA_LAST_SX*4],ecx
mov [esp+MENUET_THREAD_DATA_LAST_SY*4],edx
push edx
push ecx
push ebx
push eax
lea ecx,[esp+16]
mov edx,esp
push ecx
push edx
call @@MenuetOnSize$qpippv
add esp,24
test dword [esp+MENUET_THREAD_DATA_FLAG*4],3
jz .main_cycle
.main_paint:
cmp dword [esp+MENUET_THREAD_DATA_FLAG*4],0
jl .main_close
push esp
push dword 0
call @Kolibri@Redraw$qippv
add esp,8
.main_cycle:
mov eax,11
.main_message:
cmp dword [esp+MENUET_THREAD_DATA_FLAG*4],0
jl .main_close
int 0x40
test eax,eax
jnz .main_on_message
cmp dword [esp+MENUET_THREAD_DATA_FLAG*4],0
jne .main_paint
push esp
call @@MenuetOnIdle$qppv
pop ecx
test eax,eax
jz .main_cycle
jl .main_wait_message
mov ebx,eax
mov eax,23
jmp .main_message
.main_wait_message:
mov eax,10
jmp .main_message
.main_key_press:
push esp
call @@MenuetOnKeyPress$qppv
pop ecx
jmp .main_cycle
.main_mouse:
push esp
call @@MenuetOnMouse$qppv
pop ecx
jmp .main_cycle
.main_on_message:
dec eax
jz .main_paint_msg
dec eax
jz .main_key_press
cmp eax,4
jz .main_mouse
dec eax
jnz .main_cycle
.main_button:
mov eax,17
int 0x40
test al,al
jnz .main_cycle
.main_close:
btr dword [esp+MENUET_THREAD_DATA_FLAG*4],31
push esp
call @@MenuetOnClose$qppv
pop ecx
test al,al
jz .main_button
.main_end:
mov ebx,esp
lock dec dword [@Kolibri@_ThreadNumber]
if defined Menuet_SegmentExit & defined Menuet_SegmentExitEnd
jnz .main_else_last_check
push Menuet_SegmentExitEnd
push Menuet_SegmentExit
jmp .main_after_last_check
end if
.main_else_last_check:
xor eax,eax
push eax
push eax
.main_after_last_check:
push ebx
call @@Kolibri@_RemoveThreadData$qppvpvt2
add esp,12
lock inc dword [@Kolibri@_ThreadScanCount+4]
mov ebx,1
jmp .main_end_wait
.main_end_wait_loop:
mov eax,5
int 0x40
shl ebx,1
cmp ebx,MENUET_MUTEX_MAX_TIME_WAIT
jna .main_end_wait
mov ebx,MENUET_MUTEX_MAX_TIME_WAIT
.main_end_wait:
cmp dword [@Kolibri@_ExitProcessNow],0
jnz @Kolibri@ExitProcess$qv
cmp dword [@Kolibri@_ThreadScanCount],0
jnz .main_end_wait_loop
lock dec dword [@Kolibri@_ThreadScanCount+4]
mov ebp,[esp+4]
mov ebx,[esp]
add esp,MENUET_THREAD_DATA_LEN*4
mov eax,ebp
pop edi esi
xchg ebp,[esp+8]
xchg ebx,[esp+4]
ret
endp
 
macro call func
{
if func eq __chkstk
sub esp,eax
else
call func
end if
}
 
proc @Kolibri@Redraw$qippv
push ebp
mov ebp,[esp+12]
mov edx,[ebp+MENUET_THREAD_DATA_FLAG*4]
cmp dword [esp+8],0
jl .redraw_only_inv
jz .redraw_no_frame
or dl,2
.redraw_no_frame:
bt edx,30
jnc .redraw_begin
or dl,1
mov [ebp+MENUET_THREAD_DATA_FLAG*4],edx
jmp .redraw_end
.redraw_only_inv:
test dl,3
jnz .redraw_no_frame
.redraw_end:
pop ebp
ret
.redraw_begin:
push ebx esi edi
and dword [ebp+MENUET_THREAD_DATA_FLAG*4],0xFFFFFFFC
test dl,2
jz .redraw_picture
mov eax,12
mov ebx,1
int 0x40
xor eax,eax
mov ebx,[ebp+MENUET_THREAD_DATA_X*4]
mov ecx,[ebp+MENUET_THREAD_DATA_Y*4]
mov edx,[ebp+MENUET_THREAD_DATA_C_WINDOW*4]
mov esi,[ebp+MENUET_THREAD_DATA_C_HEADER*4]
mov edi,[ebp+MENUET_THREAD_DATA_C_BORDER*4]
int 0x40
mov edx,[ebp+MENUET_THREAD_DATA_TITLE*4]
test edx,edx
jz .window_defined
mov edi,edx
mov ecx,0xFFFFFFFF
xor al,al
cld
repnz scas byte [edi]
not ecx
mov esi,ecx
dec esi
jz .window_defined
mov eax,4
mov ebx,0x00070007
mov ecx,[ebp+MENUET_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
int 0x40
mov esi,[ebp+MENUET_THREAD_DATA_PICTURE*4]
test esi,esi
jz .redraw_end_draw
mov ecx,[ebp+MENUET_THREAD_DATA_SZ_PICT*4]
jecxz .redraw_end_draw
mov al,byte [ebp+MENUET_THREAD_DATA_C_WINDOW*4+3]
and al,15
mov edx,MENUET_BORDER_SIZE*65536+MENUET_HEADER_SIZE
cmp al,3
jnz .redraw_no_skin
mov eax,48
mov ebx,4
int 0x40
mov dx,ax
.redraw_no_skin:
mov eax,7
mov ebx,esi
int 0x40
.redraw_end_draw:
pop edi esi ebx ebp
ret
endp
 
proc @Kolibri@MoveWindow$qxpxi uses ebx esi
mov eax,[esp+12]
mov ebx,[eax]
mov ecx,[eax+4]
mov edx,[eax+8]
mov esi,[eax+12]
mov eax,67
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@ExitProcess$qv
lock bts dword [@Kolibri@_ExitProcessNow],0
jc .exit_process_wait
sub esp,1024
mov eax,9
mov ebx,esp
mov ecx,-1
int 0x40
mov esi,eax
mov edi,[esp+30]
.exit_process_loop:
mov eax,9
mov ebx,esp
mov ecx,esi
int 0x40
mov eax,[esp+30]
cmp eax,edi
jz .exit_process_continue
mov ebx,eax
or bl,15
inc ebx
jz .exit_process_continue
mov ebx,eax
call Menuet_HashInt
movzx eax,al
mov eax,dword [@Kolibri@_ThreadTable+eax*4]
jmp .exit_process_test
.exit_process_next:
mov eax,dword [eax+MENUET_THREAD_DATA_NEXT*4]
.exit_process_test:
test eax,eax
jz .exit_process_continue
cmp ebx,[eax+MENUET_THREAD_DATA_PID*4]
jnz .exit_process_next
mov eax,18
mov ebx,2
mov ecx,esi
int 0x40
.exit_process_continue:
dec esi
jnl .exit_process_loop
add esp,1024
mov dword [@Kolibri@_ExitProcessNow],-1
if defined EMULATOR
int3
call 0x76543210
end if
.exit_process_end:
mov dword [@Kolibri@_ThreadMutex],0
or eax,-1
int 0x40
.exit_process_wait:
mov eax,5
mov ebx,1
.exit_process_wait_loop:
cmp dword [@Kolibri@_ExitProcessNow],0
jl .exit_process_end
int 0x40
shl ebx,1
cmp ebx,MENUET_MUTEX_MAX_TIME_WAIT
jna .exit_process_wait_loop
mov ebx,MENUET_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
endp
 
proc @Kolibri@ReturnMessageLoop$qppv,@Kolibri@ThreadMain$qpvt1
mov esp,[esp+4]
bt dword [esp+MENUET_THREAD_DATA_FLAG*4],30
jc Menuet_main_end
jmp Menuet_main_cycle
endp
 
proc @Kolibri@Delay$qui uses ebx
mov eax,5
mov ebx,[esp+8]
int 0x40
ret
endp
 
proc @Kolibri@Clock$qv uses ebx
mov eax,26
mov ebx,9
int 0x40
ret
endp
 
proc @Kolibri@GetPackedTime$qv
mov eax,3
int 0x40
ret
endp
 
proc @Kolibri@GetTime$qpi
mov eax,3
int 0x40
mov edx,[esp+4]
movzx ecx,al
shr ecx,4
and al,0x0F
imul ecx,10
add cl,al
mov dword [edx+8],ecx
mov cl,ah
shr ecx,4
and ah,0x0F
imul ecx,10
add cl,ah
mov dword [edx+4],ecx
bswap eax
mov cl,ah
shr ecx,4
and ah,0x0F
imul ecx,10
add cl,ah
mov dword [edx],ecx
ret
endp
 
proc @Kolibri@GetPackedDate$qv
mov eax,29
int 0x40
ret
endp
 
proc @Kolibri@GetDate$qpi
mov eax,29
int 0x40
mov edx,[esp+4]
movzx ecx,al
shr ecx,4
and al,0x0F
imul ecx,10
add cl,al
mov dword [edx+4],ecx
mov cl,ah
shr ecx,4
and ah,0x0F
imul ecx,10
add cl,ah
mov dword [edx],ecx
bswap eax
mov cl,ah
shr ecx,4
and ah,0x0F
imul ecx,10
add cl,ah
mov dword [edx+8],ecx
ret
endp
 
proc @Kolibri@ReadCommonColors$qpui uses ebx
mov eax,48
mov ebx,3
mov ecx,[esp+8]
mov edx,40
int 0x40
ret
endp
 
proc @Kolibri@GetProcessInfo$qpuipct1t1piui uses ebx esi edi
sub esp,1024
mov eax,9
mov ebx,esp
mov ecx,[1024+12+24+esp]
int 0x40
xor edi,edi
or edi,[1024+12+4+esp]
jz .get_proc_info_no_usecpu
mov ecx,[esp]
mov [edi],ecx
xor edi,edi
.get_proc_info_no_usecpu:
or edi,[1024+12+8+esp]
jz .get_proc_info_no_name
lea esi,[esp+10]
cld
movs dword [edi],[esi]
movs dword [edi],[esi]
movs dword [edi],[esi]
mov byte [edi],0
xor edi,edi
.get_proc_info_no_name:
or edi,[1024+12+12+esp]
jz .get_proc_info_no_mem
mov ecx,[esp+26]
mov [edi],ecx
xor edi,edi
.get_proc_info_no_mem:
or edi,[1024+12+16+esp]
jz .get_proc_info_no_pid
mov ecx,[esp+30]
mov [edi],ecx
xor edi,edi
.get_proc_info_no_pid:
or edi,[1024+12+20+esp]
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]
xor edi,edi
.get_proc_info_no_rect:
add esp,1024
ret
endp
 
proc @Kolibri@GetPid$qv uses ebx
sub esp,1024
mov eax,9
mov ebx,esp
mov ecx,-1
int 0x40
mov eax,[esp+30]
add esp,1024
ret
endp
 
proc @Kolibri@GetPid$qppv
mov ecx,[esp+4]
mov eax,[ecx+MENUET_THREAD_DATA_PID*4]
ret
endp
 
proc @Kolibri@_HashByte$qui
@Kolibri@_HashWord$qui:
@Kolibri@_HashDword$qui:
mov eax,[esp+4]
Menuet_HashInt:
mul dword [Menuet_hash_int_val0]
xor eax,edx
bswap eax
mul dword [Menuet_hash_int_val1]
shrd eax,edx,14
bswap eax
lea eax,[eax+4*eax]
ror eax,9
ret
endp
 
Menuet_hash_int_val0:
dd 0xA82F94C5
Menuet_hash_int_val1:
dd 0x9193780B
 
proc @Kolibri@GetThreadData$qv
call @Kolibri@GetPid$qv
push eax
call @Kolibri@GetThreadData$qui
pop ecx
ret
endp
 
proc @Kolibri@GetThreadData$qui
mov eax,[esp+4]
call Menuet_HashInt
movzx eax,al
cmp dword [@Kolibri@_ThreadScanCount+4],0
jnz .get_thread_data_wait
.get_thread_data_nowait:
lock inc dword [@Kolibri@_ThreadScanCount]
mov eax,dword [@Kolibri@_ThreadTable+eax*4]
mov ecx,[esp+4]
jmp .get_thread_data_test
.get_thread_data_loop:
mov eax,dword [eax+MENUET_THREAD_DATA_NEXT*4]
.get_thread_data_test:
test eax,eax
jz .get_thread_data_end
cmp ecx,[eax+MENUET_THREAD_DATA_PID*4]
jnz .get_thread_data_loop
.get_thread_data_end:
lock dec dword [@Kolibri@_ThreadScanCount]
ret
.get_thread_data_wait:
push eax ebx
mov eax,5
mov ebx,1
.get_thread_data_wait_loop:
int 0x40
cmp dword [@Kolibri@_ThreadScanCount+4],0
jz .get_thread_data_wait_end
shl ebx,1
cmp ebx,MENUET_MUTEX_MAX_TIME_WAIT
jna .get_thread_data_wait_loop
mov ebx,MENUET_MUTEX_MAX_TIME_WAIT
jmp .get_thread_data_wait_loop
.get_thread_data_wait_end:
pop ebx eax
jmp .get_thread_data_nowait
endp
 
proc @Kolibri@_GetSkinHeader$qv uses ebx
mov eax,48
mov ebx,4
int 0x40
ret
endp
 
proc @Kolibri@GetScreenSize$qrust1
mov eax,14
int 0x40
mov ecx,[esp+8]
mov word [ecx],ax
mov ecx,[esp+4]
shr eax,16
mov word [ecx],ax
ret
endp
 
proc Menuet_MutexLockNoWait
pop eax
xor al,al
ret
endp
 
proc Menuet_MutexLockWait uses ebx
mov eax,5
xor ebx,ebx
.lock_wait_cycle:
int 0x40
shl byte [ecx],1
jz .lock_wait_cycle
mov al,1
ret
endp
 
proc Menuet_MutexLockWaitTime
cmp dword [esp+12],0
jng .MutexLockWait
push ebx edx
mov edx,[esp+20]
mov eax,26
mov ebx,9
int 0x40
add edx,eax
.lock_wait_time_cycle:
mov eax,5
xor ebx,ebx
int 0x40
shl byte [ecx],1
jnz .lock_wait_time_ret_true
mov eax,26
mov ebx,9
int 0x40
cmp eax,edx
js .lock_wait_time_cycle
pop edx ebx eax
xor al,al
ret
.lock_wait_time_ret_true:
pop edx ebx
mov al,1
ret
endp
 
proc Menuet_MutexLock
shl byte [ecx],1
jnz .lock_first
call eax
.lock_first:
mov al,1
ret
endp
 
proc @Kolibri@TryLock$qp14Kolibri@TMutex
mov eax,Menuet_MutexLockNoWait
mov ecx,[esp+4]
jmp Menuet_MutexLock
endp
 
proc @Kolibri@Lock$qp14Kolibri@TMutex
mov eax,Menuet_MutexLockWait
mov ecx,[esp+4]
jmp Menuet_MutexLock
endp
 
proc @Kolibri@LockTime$qp14Kolibri@TMutexi
mov eax,Menuet_MutexLockWaitTime
mov ecx,[esp+4]
jmp Menuet_MutexLock
endp
 
proc @Kolibri@UnLock$qp14Kolibri@TMutex
mov ecx,[esp+4]
shr byte [ecx],1
jz .unlock_pause
ret
.unlock_pause:
mov byte [ecx],0x40
push ebx
mov eax,5
xor ebx,ebx
int 0x40
pop ebx
ret
endp
 
proc Menuet_MutexLockRec
shl byte [ecx],1
jng .lock_first
cmp dword [ecx+4],edx
jz .lock_rec_self
call eax
.lock_rec_first:
mov al,1
mov dword [ecx+4],edx
ret
.lock_rec_self:
mov al,1
add dword [ecx],0x100
jc .lock_rec_overflow
ret
.lock_rec_overflow:
push dword [@Kolibri@DebugPrefix]
call @Kolibri@DebugPutString$qpxc
mov dword [esp],Menuet_try_lock_rec_overflow_string
call @Kolibri@DebugPutString$qpxc
pop ecx
jmp @Kolibri@Abort$qv
endp
 
proc @Kolibri@TryLock$qp16Kolibri@TRecMutexui
mov eax,Menuet_MutexLockNoWait
mov ecx,[esp+4]
mov edx,[esp+8]
jmp Menuet_MutexLockRec
endp
 
proc @Kolibri@Lock$qp16Kolibri@TRecMutexui
mov eax,Menuet_MutexLockWait
mov ecx,[esp+4]
mov edx,[esp+8]
jmp Menuet_MutexLockRec
endp
 
proc @Kolibri@LockTime$qp16Kolibri@TRecMutexiui
mov eax,Menuet_MutexLockWaitTime
mov ecx,[esp+4]
mov edx,[esp+12]
jmp Menuet_MutexLockRec
endp
 
proc @Kolibri@UnLock$qp16Kolibri@TRecMutexui
mov ecx,[esp+4]
mov edx,[esp+8]
cmp dword [ecx+4],edx
jnz .unlock_rec_notlocked
sub dword [ecx],0x100
jnc .unlock_rec_end
add dword [ecx],0x100
shl byte [ecx],1
shr byte [ecx],2
jng .unlock_rec_pause
.unlock_rec_end:
ret
.unlock_rec_pause:
mov byte [ecx],0x20
push ebx
mov eax,5
xor ebx,ebx
int 0x40
pop ebx
ret
.unlock_rec_notlocked:
push dword [@Kolibri@DebugPrefix]
call @Kolibri@DebugPutString$qpxc
mov dword [esp],Menuet_unlock_rec_notlocked_string
call @Kolibri@DebugPutString$qpxc
pop ecx
jmp @Kolibri@Abort$qv
endp
 
proc @Kolibri@DebugPutChar$qc
mov cl,byte [esp+4]
cmp cl,13
jz .debug_put_char_ret
push ebx
cmp cl,10
jz .debug_put_char_enter
.debug_put_char_after_cmp:
mov eax,63
mov ebx,1
int 0x40
pop ebx
.debug_put_char_ret:
ret
.debug_put_char_enter:
mov cl,13
mov eax,63
mov ebx,1
int 0x40
mov cl,10
jmp .debug_put_char_after_cmp
endp
 
proc @Kolibri@DebugPutString$qpxc
push esi
push dword 0
mov esi,dword [esp+12]
jmp .debug_put_string_test
.debug_put_string_loop:
mov dword [esp],eax
call @Kolibri@DebugPutChar$qc
inc esi
.debug_put_string_test:
xor eax,eax
or al,[esi]
test al,al
jnz .debug_put_string_loop
pop ecx esi
ret
endp
 
proc @Kolibri@GetKey$qv
mov eax,2
int 0x40
test al,al
jnz .get_key_eof
movzx eax,ah
ret
.get_key_eof:
mov eax,-1
ret
endp
 
proc @Kolibri@GetMouseButton$qv uses ebx
mov eax,37
mov ebx,2
int 0x40
ret
endp
 
proc @Kolibri@GetMousePosition$qrst1o uses ebx
mov eax,37
xor ebx,ebx
cmp byte [esp+16],0
jnz .get_mouse_pos_absolute
inc ebx
.get_mouse_pos_absolute:
int 0x40
mov ecx,[esp+12]
mov word [ecx],ax
mov ecx,[esp+8]
shr eax,16
mov word [ecx],ax
ret
endp
 
proc @Kolibri@WasThreadCreated$qv
cmp byte [@Kolibri@_ThreadSavedBegProc],0x90
setz al
ret
endp
 
proc @Kolibri@CreateThread$qpvuit1
push ebx
mov edx,[esp+16]
mov ebx,[esp+12]
test edx,edx
jnz .create_thread_after_new
if defined MenuetHeapAlloc
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
pop ecx
test eax,eax
jnz .create_thread_mem_created
end if
or eax,-1
jmp .create_thread_end
.create_thread_mem_created:
lea edx,[eax+ebx]
.create_thread_after_new:
neg ebx
jz .create_thread_test_first
add ebx,edx
.create_thread_test_first:
cmp byte [@Kolibri@_ThreadSavedBegProc],0x90
jnz .create_thread_init
.create_thread_fill_stack:
lock inc dword [@Kolibri@_ThreadNumber]
and edx,not 3
sub edx,12
mov ecx,[esp+8]
mov dword [edx+8],ebx
mov dword [edx+4],ecx
mov dword [edx],Menuet_ThreadFinish
mov eax,51
mov ebx,1
mov ecx,@Kolibri@ThreadMain$qpvt1
int 0x40
mov ebx,eax
or bl,15
inc ebx
jnz .create_thread_end
lock dec dword [@Kolibri@_ThreadNumber]
if defined MenuetHeapFree
or ebx,[edx+8]
jz .create_thread_end
push ebx
call MenuetHeapFree ; Delete the given dynamic memory
pop ecx
end if
.create_thread_end:
pop ebx
ret
.create_thread_init:
push esi edi
cld
mov esi,@Kolibri@_ThreadSavedBegProc
mov edi,@Kolibri@GetPid$qv
movs dword [edi],[esi]
movs dword [edi],[esi]
mov edi,@Kolibri@GetThreadData$qv
movs dword [edi],[esi]
movs dword [edi],[esi]
mov eax,0x90909090
mov edi,@Kolibri@_ThreadSavedBegProc
stos dword [edi]
stos dword [edi]
stos dword [edi]
stos dword [edi]
pop edi esi
jmp .create_thread_fill_stack
endp
 
proc @Kolibri@_FileAccess$qpv uses ebx
mov eax,70
mov ebx,[esp+8]
int 0x40
mov ecx,[esp+8]
mov [ecx],ebx
ret
endp
 
Menuet_abort_string:
db 'Abnormal program termination.',10,0
Menuet_try_lock_rec_overflow_string:
db 'Recursive mutex lock count overflow.',10,0
Menuet_unlock_rec_notlocked_string:
db 'Recursive mutex unlock error.',10,0
 
include "kos_lib.inc"
 
;/**/
 
/programs/demos/life2/include/kos_heap.h
0,0 → 1,90
#ifndef __MENUET_HEAP_H_INCLUDED_
#define __MENUET_HEAP_H_INCLUDED_
 
#include <kolibri.h>
#include <memheap.h>
 
// Kolibri memory heap interface.
 
namespace Kolibri // All kolibri functions, types and data are nested in the (Kolibri) namespace.
{
void *Alloc(unsigned int size);
void *ReAlloc(void *mem, unsigned int size);
void Free(void *mem);
}
 
#ifdef __MENUET__
 
namespace Kolibri
{
 
// Global variables
 
MemoryHeap::TFreeSpace _MenuetFreeSpace;
MemoryHeap::TMemBlock _MenuetMemBlock;
TMutex _MemHeapMutex = MENUET_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::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);
}
 
bool _SetUseMemory(unsigned int use_mem);
 
int _RecalculateUseMemory(unsigned int use_mem);
 
void *Alloc(unsigned int size)
{
if (!size) return 0;
Lock(&_MemHeapMutex);
void *res = MemoryHeap::Alloc(_MenuetFreeSpace, size);
if (!res)
{
unsigned use_mem = (unsigned int)MemoryHeap::BlockEndFor(_MenuetMemBlock, size);
if (_SetUseMemory(_RecalculateUseMemory(use_mem)))
{
res = MemoryHeap::Alloc(_MenuetFreeSpace, size);
}
}
UnLock(&_MemHeapMutex);
return res;
}
 
void *ReAlloc(void *mem, unsigned int size)
{
Lock(&_MemHeapMutex);
void *res = MemoryHeap::ReAlloc(_MenuetFreeSpace, mem, size);
if (!res && size)
{
unsigned use_mem = (unsigned int)MemoryHeap::BlockEndFor(_MenuetMemBlock, size);
if (_SetUseMemory(_RecalculateUseMemory(use_mem)))
{
res = MemoryHeap::ReAlloc(_MenuetFreeSpace, mem, size);
}
}
UnLock(&_MemHeapMutex);
return res;
}
 
void Free(void *mem)
{
Lock(&_MemHeapMutex);
MemoryHeap::Free(_MenuetFreeSpace, mem);
UnLock(&_MemHeapMutex);
}
 
void _FreeAndThreadFinish(void *mem, int *exit_proc_now);
}
 
#endif // def __MENUET__
 
#endif // ndef __MENUET_HEAP_H_INCLUDED_
/programs/demos/life2/include/kos_heap.inc
0,0 → 1,97
;/***
 
MenuetHeapInit = @@Kolibri@_HeapInit$qpvt1t1
 
MenuetHeapAlloc = @@Kolibri@Alloc$qui
 
MenuetHeapReAlloc = @@Kolibri@ReAlloc$qpvui
 
MenuetHeapFree = @@Kolibri@Free$qpv
 
MenuetHeapFreeAndThreadFinish = @Kolibri@_FreeAndThreadFinish$qpvpi
 
proc @Kolibri@_SetUseMemory$qui
push ebx
mov eax,64
mov ebx,1
mov ecx,[esp+8]
int 0x40
pop ebx
test eax,eax
jnz .set_use_memory_nomem
push ecx
push dword [@Kolibri@_MenuetMemBlock]
call @@MemoryHeap@ResizeBlock$q20MemoryHeap@TMemBlockpv
add esp,8
mov al,1
ret
.set_use_memory_nomem:
xor al,al
ret
endp
 
proc @Kolibri@_RecalculateUseMemory$qui
mov eax,dword [esp+4]
mov ecx,(U_END + 3) and not 3
cmp eax,ecx
jna .recalculate_use_memory_min
push ebx
sub eax,ecx
mov ebx,6
mul ebx
dec ebx
div ebx
add eax,((U_END + 3) and not 3) + 3
and eax,not 3
pop ebx
ret
.recalculate_use_memory_min:
mov eax,ecx
ret
endp
 
proc @Kolibri@_FreeAndThreadFinish$qpvpi
mov ebx,1
mov ecx,[esp+8]
jmp .heap_free_tf_wait
.heap_free_tf_wait_loop:
mov eax,5
int 0x40
shl ebx,1
cmp ebx,MENUET_MUTEX_MAX_TIME_WAIT
jna .heap_free_tf_wait
mov ebx,MENUET_MUTEX_MAX_TIME_WAIT
.heap_free_tf_wait:
cmp dword [ecx],0
jnz @Kolibri@ExitProcess$qv
lock bts dword [@Kolibri@_MemHeapMutex],0
jc .heap_free_tf_wait_loop
push dword [esp+4]
push @Kolibri@_MenuetFreeSpace
call @@MemoryHeap@Free$qr21MemoryHeap@TFreeSpacepv
add esp,8
mov byte [@Kolibri@_MemHeapMutex],0x40
or eax,-1
int 0x40
endp
 
macro call func
{
if func eq @MemoryHeap@_FirstNotZeroBit$qui
bsf eax,[esp]
else if func eq @MemoryHeap@_CopyMemItemArray$quiuiui
xchg edi,[esp]
xchg esi,[esp+4]
mov ecx,[esp+8]
cld
sub ecx,esi
shr ecx,2
rep movs dword [edi],[esi]
xchg edi,[esp]
xchg esi,[esp+4]
else
call func
end if
}
 
;/**/
/programs/demos/life2/include/kos_lib.h
0,0 → 1,16
#ifndef __MENUET_LIB_H_INCLUDED_
#define __MENUET_LIB_H_INCLUDED_
 
// Kolibri interface.
 
namespace Kolibri // All kolibri functions, types and data are nested in the (Kolibri) namespace.
{
unsigned int StrLen(const char *str);
char *StrCopy(char *dest, const char *src);
void *MemCopy(void *dest, const void *src, unsigned int n);
void *MemSet(void *s, char c, unsigned int n);
 
double Floor(double x);
}
 
#endif // __MENUET_LIB_H_INCLUDED_
/programs/demos/life2/include/kos_lib.inc
0,0 → 1,106
proc @Kolibri@StrLen$qpxc uses edi
cld
mov edi,[esp+8]
mov ecx,-1
xor al,al
repnz scas byte [edi]
not ecx
lea eax,[ecx-1]
ret
endp
 
proc @Kolibri@StrCopy$qpcpxc uses esi edi
cld
mov edi,[esp+16]
mov ecx,-1
mov esi,edi
xor al,al
repnz scas byte [edi]
not ecx
mov edi,[esp+12]
mov edx,ecx
mov eax,edi
shr ecx,2
rep movs dword [edi],[esi]
mov ecx,edx
and ecx,3
rep movs byte [edi],[esi]
ret
endp
 
proc @Kolibri@MemCopy$qpvpxvui uses esi edi
cld
mov edi,[esp+12]
mov eax,edi
mov ecx,[esp+20]
mov esi,[esp+16]
mov edx,ecx
shr ecx,2
rep movs dword [edi],[esi]
mov ecx,edx
and ecx,3
rep movs byte [edi],[esi]
ret
endp
 
proc @Kolibri@MemSet$qpvcui uses edi
cld
mov edi,[esp+8]
mov al,[esp+12]
mov ah,al
mov dx,ax
shl eax,16
mov ax,dx
mov ecx,[esp+16]
mov edx,ecx
shr ecx,2
rep stos dword [edi]
mov ecx,edx
and ecx,3
rep stos byte [edi]
mov eax,[esp+4]
ret
endp
 
proc __ftol
sub esp,12
wait
fstcw word [esp+8]
wait
mov al,[esp+9]
or byte [esp+9],0x0c
fldcw word [esp+8]
fistp qword [esp]
mov [esp+9],al
fldcw word [esp+8]
mov eax,[esp]
mov edx,[esp+4]
add esp,12
ret
endp
 
proc @Kolibri@Floor$qd
fld qword [esp+4]
mov ax,[esp+10]
shl ax,1
cmp ax,0x8680
ja Menuet_floor_end
mov ch,4
sub esp,2
wait
fstcw word [esp]
mov ax,0xf3ff
wait
mov dx,[esp]
and ax,dx
or ah,ch
mov [esp],ax
fldcw word [esp]
frndint
mov [esp],dx
fldcw word [esp]
add esp,2
Menuet_floor_end:
ret
endp
 
/programs/demos/life2/include/kos_start.inc
0,0 → 1,85
use32
org 0
db 'MENUET01'
dd 1
dd @Kolibri@Main$qv
dd I_END
dd U_END+STACKSIZE+HEAPSIZE
dd U_END+STACKSIZE
dd @Kolibri@CommandLine,0
 
ptr equ
offset equ
short equ
tbyte equ tword
 
PTR equ
OFFSET equ
SHORT equ
TBYTE equ TWORD
 
macro movsb a,b
{
if a eq & b eq
movsb
else
movsx a,b
end if
}
macro movsw a,b
{
if a eq & b eq
movsw
else
movsx a,b
end if
}
 
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 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/menuet_win.cpp
1,4 → 1,3
#include <windows.h>
#include <string.h>
#include <process.h>
#include <stdio.h>
6,11 → 5,11
#include <assert.h>
#include <deque.h>
 
#include <menuet.h>
#include <me_heap.h>
#include <me_file.h>
#include <kolibri.h>
#include <kos_heap.h>
#include <kos_file.h>
 
using namespace Menuet;
using namespace Kolibri;
using namespace std;
 
const char file_prefix[] = "";
236,7 → 235,7
return 0;
}
 
namespace Menuet
namespace Kolibri
{
void Main() {ThreadMain();}
 
/programs/demos/life2/kos_cdlg.h
0,0 → 1,100
#ifndef __MENUET_FILE_OPEN_H_INCLUDED_
#define __MENUET_FILE_OPEN_H_INCLUDED_
 
#include <kolibri.h>
 
// Kolibri interface.
 
namespace Kolibri // All kolibri functions, types and data are nested in the (Kolibri) namespace.
{
struct TOpenFileStruct; // Data for a file open dialog.
#define MENUET_OPEN_FILE_INIT {} // Initializer of the file open struct, cat be redefined in a realization of the library
 
void OpenFileInit(TOpenFileStruct &ofs);
void OpenFileDelete(TOpenFileStruct &ofs);
bool OpenFileDialog(TOpenFileStruct &ofs);
int OpenFileGetState(const TOpenFileStruct &ofs);
bool OpenFileSetState(TOpenFileStruct &ofs, int state);
char *OpenFileGetName(const TOpenFileStruct &ofs);
bool OpenFileSetName(TOpenFileStruct &ofs, char *name);
}
 
#ifdef __MENUET__
 
namespace Kolibri
{
// Structures.
 
struct TOpenFileStruct
{
int state;
char *name;
};
#undef MENUET_OPEN_FILE_INIT
#define MENUET_OPEN_FILE_INIT {0,0}
 
// Inline functions.
 
inline void OpenFileInit(TOpenFileStruct &ofs)
{
ofs.state = 0;
ofs.name = 0;
}
 
inline void OpenFileDelete(TOpenFileStruct &ofs)
{
if (ofs.name) {Free(ofs.name); ofs.name = 0;}
}
 
inline int OpenFileGetState(const TOpenFileStruct &ofs)
{
return ofs.state;
}
 
inline char *OpenFileGetName(const TOpenFileStruct &ofs)
{
return ofs.name;
}
 
// Functions.
 
bool OpenFileSetState(TOpenFileStruct &ofs, int state)
{
if (!ofs.state) return !state;
if (ofs.state == state) return true;
if (state < 0) return false;
ofs.state = state;
return true;
}
 
bool OpenFileSetName(TOpenFileStruct &ofs, char *name)
{
if (!ofs.name && !name) return true;
if (ofs.name) Free(ofs.name);
if (!name) {ofs.name = 0; return true;}
ofs.name = (char*)Alloc(StrLen(name) + 1);
if (!ofs.name) return false;
StrCopy(ofs.name, name);
return true;
}
}
 
#else // else: def __MENUET__
 
namespace Kolibri
{
struct TOpenFileStruct
{
unsigned int data;
 
TOpenFileStruct();
~TOpenFileStruct();
};
#undef MENUET_OPEN_FILE_INIT
#define MENUET_OPEN_FILE_INIT TOpenFileStruct()
}
 
#endif // __MENUET__
 
#endif // __MENUET_FILE_OPEN_H_INCLUDED_
 
/programs/demos/life2/kos_cdlg.inc
0,0 → 1,167
proc @Kolibri@OpenFileDialog$qr23Kolibri@TOpenFileStruct uses ebx esi edi ebp
call @Kolibri@GetThreadData$qv
mov ebp,eax
mov ebx,[esp+20]
cmp dword [ebx+4],0
jnz .open_file_dlg_str
mov esi,7
jmp .open_file_dlg_alloc
.open_file_dlg_str:
cld
mov edi,[ebx+4]
mov ecx,-1
xor al,al
repnz scas byte [edi]
not ecx
mov esi,ecx
.open_file_dlg_alloc:
push esi
call @@Kolibri@Alloc$qui
pop ecx
test eax,eax
jz .open_file_dlg_ret
mov ecx,esi
dec ecx
push esi
push ecx
push eax
mov dword [ebx],-1
cmp dword [ebx+4],0
jnz .open_file_dlg_copy
mov dword [eax],0x2F64722F
mov word [eax+4],0x2F31
jmp .open_file_dlg_redraw
.open_file_dlg_copy:
cld
mov ecx,esi
mov esi,[ebx+4]
mov edi,eax
rep movs byte [edi],[esi]
.open_file_dlg_redraw:
mov eax,12
mov ebx,1
int 0x40
xor eax,eax
mov ebx,[ebp+MENUET_THREAD_DATA_X*4]
mov ecx,[ebp+MENUET_THREAD_DATA_Y*4]
mov edx,[ebp+MENUET_THREAD_DATA_C_WINDOW*4]
mov esi,[ebp+MENUET_THREAD_DATA_C_HEADER*4]
mov edi,[ebp+MENUET_THREAD_DATA_C_BORDER*4]
int 0x40
mov eax,4
mov ebx,0x00070007
mov ecx,[ebp+MENUET_THREAD_DATA_C_TITLE*4]
mov edx,Kolibri_open_file_dlg_name
mov esi,Kolibri_open_file_dlg_name_end - Kolibri_open_file_dlg_name
int 0x40
mov eax,4
mov ebx,0x000C001E
xor ecx,ecx
mov edx,[esp]
mov esi,[esp+4]
int 0x40
mov eax,12
mov ebx,2
int 0x40
.open_file_dlg_loop:
mov eax,10
int 0x40
dec eax
jz .open_file_dlg_redraw
dec eax
jz .open_file_dlg_key
dec eax
jz .open_file_dlg_end
jmp .open_file_dlg_loop
.open_file_dlg_key:
xor edi,edi
.open_file_dlg_key_loop:
mov eax,2
int 0x40
test al,al
jnz .open_file_dlg_key_end
cmp ah,27
jz .open_file_dlg_end
cmp ah,13
jz .open_file_dlg_apply
cmp ah,8
jz .open_file_dlg_key_bsp
cmp ah,32
jna .open_file_dlg_key_loop
mov ebx,[esp+4]
cmp ebx,[esp+8]
jb .open_file_dlg_key_any
lea esi,[ebx+2*ebx]
shr esi,1
inc esi
push eax
push esi
push dword [esp+8]
call @@Kolibri@ReAlloc$qpvui
add esp,8
mov ecx,eax
pop eax
test ecx,ecx
jz .open_file_dlg_key
mov [esp+8],esi
mov [esp],ecx
.open_file_dlg_key_any:
mov esi,ebx
add esi,[esp]
mov byte [esi],ah
inc ebx
mov edi,1
mov [esp+4],ebx
jmp .open_file_dlg_key_loop
.open_file_dlg_key_bsp:
mov eax,[esp+4]
test eax,eax
jz .open_file_dlg_key_loop
dec eax
mov edi,1
mov [esp+4],eax
jmp .open_file_dlg_key_loop
.open_file_dlg_key_end:
test edi,edi
jnz .open_file_dlg_redraw
jmp .open_file_dlg_loop
.open_file_dlg_apply:
mov eax,[esp+4]
inc eax
mov [esp+8],eax
push eax
push dword [esp+4]
call @@Kolibri@ReAlloc$qpvui
add esp,8
test eax,eax
jz .open_file_dlg_end
mov eax,[esp]
mov esi,eax
add eax,[esp+4]
mov byte [eax],0
add esp,12
mov ebx,[esp+20]
mov dword [ebx],2
push dword [ebx+4]
call @@Kolibri@Free$qpv
pop ecx
mov [ebx+4],esi
jmp .open_file_dlg_invalidate
.open_file_dlg_end:
call @@Kolibri@Free$qpv
add esp,12
mov ebx,[esp+20]
mov dword [ebx],1
.open_file_dlg_invalidate:
push ebp
push dword 1
call @@Kolibri@Invalidate$qippv
add esp,8
.open_file_dlg_ret:
ret
endp
 
Kolibri_open_file_dlg_name:
db 'Open file'
Kolibri_open_file_dlg_name_end:
 
/programs/demos/life2/kos_cdlg_win.cpp
0,0 → 1,115
#include <commdlg.h>
 
#include <kolibri.h>
#include <kos_heap.h>
#include "kos_cdlg.h"
 
using namespace Kolibri;
 
extern HINSTANCE hInstance;
 
struct TThreadDataStruct
{
void *user;
void *stack_begin;
TWindowData *win_data;
HWND hwnd;
int flag;
unsigned int win_time, me_time;
void *picture;
unsigned int picture_width, picture_height;
void *keys;
unsigned int bmp_data_length;
unsigned int *bmp_data;
unsigned int mouse_state;
};
 
struct TOpenFileData
{
int state;
char name[1];
};
 
namespace Kolibri
{
TOpenFileStruct::TOpenFileStruct() : data(0) {}
 
TOpenFileStruct::~TOpenFileStruct()
{
if (data) {delete[] (char*)data; data = 0;}
}
 
void OpenFileInit(TOpenFileStruct &ofs) {ofs.data = 0;}
 
void OpenFileDelete(TOpenFileStruct &ofs)
{
if (ofs.data) {delete[] (char*)ofs.data; ofs.data = 0;}
}
 
bool OpenFileDialog(TOpenFileStruct &ofs)
{
char CustomFilter[300], *name;
int size;
CustomFilter[0] = 0; CustomFilter[1] = 0;
if (!OpenFileSetState(ofs, 0)) return false;
OPENFILENAME ofn = {sizeof(OPENFILENAME), ((TThreadDataStruct*)GetThreadData())->hwnd,
hInstance, "All files (*.*)\0*.*\0",
CustomFilter, sizeof(CustomFilter)-1, 1, NULL, 0, NULL, 0, NULL, NULL,
OFN_HIDEREADONLY | OFN_EXPLORER, 0, 0, "", 0, NULL, 0};
size = 0;
if (ofs.data) size = strlen(((TOpenFileData*)ofs.data)->name) + 1;
if (size < 10000) size = 10000;
name = new char[size + 1];
if (!name) return false;
if (ofs.data) strcpy(name, ((TOpenFileData*)ofs.data)->name);
else name[0] = 0;
ofn.lpstrFile = &name[0]; ofn.nMaxFile = size;
size = GetOpenFileName(&ofn) == TRUE;
if (OpenFileSetName(ofs, name))
{
((TOpenFileData*)ofs.data)->state = (size ? 2 : 1);
}
else size = 0;
delete[] name;
return (bool)size;
}
 
int OpenFileGetState(const TOpenFileStruct &ofs)
{
return ofs.data ? ((TOpenFileData*)ofs.data)->state : 0;
}
 
bool OpenFileSetState(TOpenFileStruct &ofs, int state)
{
if (!ofs.data || !((TOpenFileData*)ofs.data)->state) return !state;
if (((TOpenFileData*)ofs.data)->state == state) return true;
if (state < 0) return false;
((TOpenFileData*)ofs.data)->state = state;
return true;
}
 
char *OpenFileGetName(const TOpenFileStruct &ofs)
{
if (!ofs.data) return 0;
else return ((TOpenFileData*)ofs.data)->name;
}
 
bool OpenFileSetName(TOpenFileStruct &ofs, char *name)
{
if (!ofs.data && !name) return true;
int size = (unsigned int)(((TOpenFileData*)0)->name) + 1;
int state = 0;
if (name) size += strlen(name);
if (ofs.data)
{
state = ((TOpenFileData*)ofs.data)->state;
delete[] (char*)ofs.data;
}
ofs.data = (unsigned int)(new char[size]);
if (!ofs.data) return false;
((TOpenFileData*)ofs.data)->state = state;
if (name) strcpy(((TOpenFileData*)ofs.data)->name, name);
else ((TOpenFileData*)ofs.data)->name[0] = 0;
return true;
}
}
/programs/demos/life2/life2.cpp
1,11 → 1,11
#include <menuet.h>
#include <me_heap.h>
#include <me_file.h>
#include <kolibri.h>
#include <kos_heap.h>
#include <kos_file.h>
#include "lifegen.h"
#include "life_bmp.h"
#include "me_cdlg.h"
#include "kos_cdlg.h"
 
using namespace Menuet;
using namespace Kolibri;
 
/***
#define StrLen LibbStrLen
20,7 → 20,6
void *(*MemSet)(void *s, char c, unsigned int n) = 0;
double (*Floor)(double x) = 0;
 
#include <windows.h>
void LibbInit()
{
HINSTANCE hLib = LoadLibrary("Libb.dll");
27,7 → 26,7
if (!hLib)
{
DebugPutString("Can't load the library.\n");
Menuet::Abort();
Kolibri::Abort();
}
StrLen = (unsigned int(*)(const char *str))GetProcAddress(hLib, "StrLen");
StrCopy = (char *(*)(char *dest, const char *src))GetProcAddress(hLib, "StrCopy");
1789,7 → 1788,7
return res;
}
 
void MenuetOnSize(int window_rect[], Menuet::TThreadData th)
void MenuetOnSize(int window_rect[], Kolibri::TThreadData th)
{
unsigned short w, h;
GetClientSize(w, h, window_rect[2], window_rect[3], th);
1964,13 → 1963,13
if (!hLib)
{
DebugPutString("Can't load the library.\n");
Menuet::Abort();
Kolibri::Abort();
}
DllOneGeneration = (void(__stdcall*)(int, int, void*, const void*, int))GetProcAddress(hLib, "OneGeneration");
if (!DllOneGeneration)
{
DebugPutString("Can't get a library function.\n");
Menuet::Abort();
Kolibri::Abort();
}
}
 
/programs/demos/life2/me_make.inc
5,9 → 5,10
STACKSIZE equ 102400
HEAPSIZE equ 102400
 
include "include\me_start.inc"
include "include\me_func.inc"
include "include\me_heap.inc"
include "me_cdlg.inc"
include "..\..\proc32.inc"
include "include\kos_start.inc"
include "include\kos_func.inc"
include "include\kos_heap.inc"
include "kos_cdlg.inc"
include "mmxlife.inc"
;include "sse2life.inc"