rewrite KRule to fasm, replace old with it

git-svn-id: svn://kolibrios.org@8756 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Rustem Gimadutdinov (rgimad) 2021-06-01 11:23:13 +00:00
parent fac22c1e73
commit 94803c76d8
16 changed files with 115 additions and 1729 deletions

View File

@ -698,6 +698,7 @@ tup.append_table(extra_files, {
{"kolibrios/develop/TinyBasic/", PROGS .. "/develop/tinybasic/TBuserMan.txt"},
{"kolibrios/utils/teatool", PROGS .. "/other/TEAtool/teatool"},
{"kolibrios/utils/passwordgen", PROGS .. "/other/PasswordGen/passwordgen"},
{"kolibrios/utils/kruler", PROGS .. "/other/kruler/kruler"},
{"kolibrios/media/qr_tool", PROGS .. "/media/qr_tool/qr_tool"},
{"kolibrios/utils/weather", PROGS .. "/other/Weather/weather"},
})

View File

@ -1,131 +0,0 @@
#include "kosSyst.h"
#include "kosfile.h"
CKosFile::CKosFile(char *fileName)
{
//
this->fileInfo.bufferPtr = new Byte[FILE_BUFFER_SIZE];
//
this->filePointer = 0;
this->bufferPointer = 0;
this->validBuffer = false;
//
strcpy( this->fileInfo.fileURL, fileName );
}
CKosFile::~CKosFile(void)
{
//
delete this->fileInfo.bufferPtr;
}
void CKosFile::ValidateBuffer()
{
//
if ( this->validBuffer )
{
//
if ( this->filePointer < this->bufferPointer
|| this->filePointer >= (this->bufferPointer + FILE_BUFFER_SIZE) )
{
//
this->validBuffer = false;
}
}
}
void CKosFile::UpdateBuffer(void)
{
//
if ( ! this->validBuffer )
{
//
this->fileInfo.OffsetLow = this->filePointer / OS_BLOCK_SIZE;
this->fileInfo.OffsetHigh = 0;
//
this->bufferPointer = this->fileInfo.OffsetLow * OS_BLOCK_SIZE;
//
this->fileInfo.dataCount = FILE_BUFFER_BLOCKS;
//
this->fileInfo.rwMode = 0;
//
Dword rr = kos_FileSystemAccess( &(this->fileInfo) );
this->validBuffer = ( rr == 0 );
}
}
int CKosFile::Seek(int seekFrom, int seekStep)
{
//
switch ( seekFrom )
{
//
case SEEK_SET:
//
this->filePointer = seekStep;
break;
//
case SEEK_CUR:
//
this->filePointer += seekStep;
break;
}
//
this->ValidateBuffer();
//
return this->filePointer;
}
int CKosFile::Read(Byte *targetPtr, int readCount)
{
int bufferLeast, result;
//
result = 0;
//
do
{
//
this->UpdateBuffer();
//
if ( ! this->validBuffer ) return result;
//
bufferLeast = FILE_BUFFER_SIZE - (this->filePointer - this->bufferPointer);
//
if ( bufferLeast > readCount ) bufferLeast = readCount;
//
if ( bufferLeast )
{
//
memcpy(
targetPtr,
this->fileInfo.bufferPtr + (this->filePointer - this->bufferPointer),
bufferLeast
);
//
targetPtr += bufferLeast;
readCount -= bufferLeast;
this->filePointer += bufferLeast;
//
result += bufferLeast;
}
//
this->ValidateBuffer();
}
while ( readCount > 0 );
//
return result;
}
int CKosFile::Write(Byte *sourcePtr, int writeCount)
{
return 0;
}

View File

@ -1,26 +0,0 @@
#pragma once
#define SEEK_SET 0
#define SEEK_CUR 1
#define FILE_BUFFER_SIZE 512
#define OS_BLOCK_SIZE 1
#define FILE_BUFFER_BLOCKS (FILE_BUFFER_SIZE / OS_BLOCK_SIZE)
class CKosFile
{
public:
CKosFile(char *fileName);
virtual ~CKosFile(void);
virtual int Read(Byte *targetPtr, int readCount);
virtual int Write(Byte *sourcePtr, int writeCount);
virtual int Seek(int seekFrom, int seekStep);
protected:
int filePointer;
int bufferPointer;
bool validBuffer;
kosFileInfo fileInfo;
virtual void ValidateBuffer(void);
virtual void UpdateBuffer(void);
};

View File

@ -1,28 +0,0 @@
//
struct MemBlock
{
Dword Size;
Dword Addr;
MemBlock *Next;
MemBlock *Previous;
};
#define INITIALQUEUESIZE (32 * 4)
#define FALSE 0
#define TRUE -1
#define MB_FREE 0
#define MB_USER 1
#define SIZE_ALIGN 4
Byte *allocmem( Dword reqsize );
Dword freemem( void *vaddress );

View File

@ -1,5 +0,0 @@
if tup.getconfig("NO_MSVC") ~= "" then return end
HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../.." or tup.getconfig("HELPERDIR")
tup.include(HELPERDIR .. "/use_msvc.lua")
compile_msvc{"*.cpp"}
link_msvc("krule")

View File

@ -1,9 +0,0 @@
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
@cl /c /O2 /nologo /GS- /GR- /fp:fast *.cpp
@link /nologo /manifest:no /entry:crtStartUp /subsystem:native /base:0 /fixed /align:16 /nodefaultlib krule.obj *.obj
@del krule
@pe2kos krule.exe krule
@del krule.exe
@del *.obj
pause

View File

@ -1,835 +0,0 @@
#include "kosSyst.h"
#include <stdarg.h>
#define atexitBufferSize 32
char pureCallMessage[] = "PURE function call!";
char *kosExePath = NULL;
//
void (__cdecl *atExitList[atexitBufferSize])();
int atExitFnNum = 0;
//
int __cdecl atexit( void (__cdecl *func )( void ))
{
//
if ( atExitFnNum < atexitBufferSize )
{
//
atExitList[atExitFnNum++] = func;
return 0;
}
else
{
return 1;
}
}
//
Dword RandomSeed = 1;
//
void rtlSrand( Dword seed )
{
RandomSeed = seed;
}
//
Dword rtlRand( void )
{
//ìàñêà 0x80000776
Dword dwi, i;
for ( i = 0; i < 32; i++ )
{
dwi = RandomSeed & 0x80000776;
__asm{
mov eax, dwi
mov edx, eax
bswap eax
xor eax, edx
xor al, ah
setpo al
movzx eax, al
mov dwi, eax
}
RandomSeed = ( RandomSeed << 1 ) | ( dwi & 1 );
}
return RandomSeed;
}
#if _MSC_VER >= 1400
//
void * __cdecl memcpy( void *dst, const void *src, size_t bytesCount )
{
__asm{
mov edi, dst
mov eax, dst
mov esi, src
mov ecx, bytesCount
rep movsb
}
}
//
void memset( Byte *dst, Byte filler, Dword count )
{
//
__asm{
mov edi, dst
mov al, filler
mov ecx, count
rep stosb
}
}
#endif
//
Dword rtlInterlockedExchange( Dword *target, Dword value )
{
// Dword result;
//
__asm{
mov eax, value
mov ebx, target
xchg eax, [ebx]
// mov result, eax
}
//
// return result;
}
//////////////////////////////////////////////////////////////////////
//
// êîïèðîâàíèå ñòðîêè
//
char * __cdecl strcpy( char *target, const char *source )
{
char *result = target;
while( target[0] = source[0] )
{
target++;
source++;
}
return result;
}
//////////////////////////////////////////////////////////////////////
//
// ðåâåðñèâíûé ïîèñê ñèìâîëà
//
char * __cdecl strrchr( const char * string, int c )
{
char *cPtr;
//
for ( cPtr = (char *)string + strlen( string ); cPtr >= string; cPtr-- )
{
//
if ( *cPtr == c ) return cPtr;
}
//
return NULL;
}
//////////////////////////////////////////////////////////////////////
//
// îïðåäåëåíèå äëèíû ñòðîêè
//
int __cdecl strlen( const char *line )
{
int i;
for( i=0; line[i] != 0; i++ );
return i;
}
//////////////////////////////////////////////////////////////////////
//
// ïåðåâîä øåñòíàäöàòèðè÷íîãî ÷èñëà â ñèìâîë
//
unsigned int num2hex( unsigned int num )
{
if( num < 10 )
return num + '0';
return num - 10 + 'A';
}
//////////////////////////////////////////////////////////////////////
//
// âûâîä ñòðîêè íà ïå÷àòü
//
Dword dectab[] = { 1000000000, 100000000, 10000000, 1000000, 100000,
10000, 1000, 100, 10, 0 };
//
void sprintf( char *Str, char* Format, ... )
{
int i, fmtlinesize, j, k, flag;
Dword head, tail;
char c;
va_list arglist;
//
va_start(arglist, Format);
//
fmtlinesize = strlen( Format );
//
if( fmtlinesize == 0 ) return;
//
for( i = 0, j = 0; i < fmtlinesize; i++ )
{
//
c = Format[i];
//
if( c != '%' )
{
Str[j++] = c;
continue;
}
//
i++;
//
if( i >= fmtlinesize ) break;
//
flag = 0;
//
c = Format[i];
//
switch( c )
{
//
case '%':
Str[j++] = c;
break;
// âûâîä ñòðîêè
case 'S':
Byte* str;
str = va_arg(arglist, Byte*);
for( k = 0; ( c = str[k] ) != 0; k++ )
{
Str[j++] = c;
}
break;
// âûâîä áàéòà
case 'B':
k = va_arg(arglist, int) & 0xFF;
Str[j++] = num2hex( ( k >> 4 ) & 0xF );
Str[j++] = num2hex( k & 0xF );
break;
// âûâîä ñèìâîëà
case 'C':
Str[j++] = va_arg(arglist, int) & 0xFF;
break;
// âûâîä äâîéíîãî ñëîâà â øåñòíàäöàòèðè÷íîì âèäå
case 'X':
Dword val;
val = va_arg(arglist, Dword);
for( k = 7; k >= 0; k-- )
{
//
c = num2hex ( ( val >> (k * 4) ) & 0xF );
//
if( c == '0' )
{
if( flag ) Str[j++] = c;
}
else
{
flag++;
Str[j++] = c;
}
}
//
if( flag == 0 ) Str[j++] = '0';
break;
// âûâîä äâîéíîãî ñëîâà â äåñÿòè÷íîì âèäå
case 'U':
head = va_arg(arglist, Dword);
tail = 0;
for( k = 0; dectab[k] != 0; k++ )
{
tail = head % dectab[k];
head /= dectab[k];
c = head + '0';
if( c == '0' )
{
if( flag ) Str[j++] = c;
}
else
{
flag++;
Str[j++] = c;
}
//
head = tail;
}
//
c = head + '0';
Str[j++] = c;
break;
// âûâîä 64-áèòíîãî ñëîâà â øåñòíàäöàòèðè÷íîì âèäå
case 'Q':
unsigned int low_dword, high_dword;
low_dword = va_arg(arglist, unsigned int);
high_dword = va_arg(arglist, unsigned int);
for( k = 7; k >= 0; k-- )
{
//
c = num2hex ( ( ( high_dword + 1) >> (k * 4) ) & 0xF );
//
if( c == '0' )
{
if( flag ) Str[j++] = c;
}
else
{
flag++;
Str[j++] = c;
}
}
//
for( k=7; k >= 0; k-- )
{
//
c = num2hex ( ( low_dword >> (k * 4) ) & 0xF );
//
if( c == '0' )
{
if( flag ) Str[j++] = c;
}
else
{
flag++;
Str[j++] = c;
}
}
//
if( flag == 0 ) Str[j++] = '0';
//
break;
//
default:
break;
}
}
//
Str[j] = 0;
}
// ôóíêöèÿ -1 çàâåðøåíèÿ ïðîöåññà
void kos_ExitApp()
{
int i;
//
for ( i = atExitFnNum - 1; i >= 0; i-- )
{
//
atExitList[i]();
}
//
__asm{
mov eax, -1
int 0x40
}
}
// ôóíêöèÿ 0
void kos_DefineAndDrawWindow(
Word x, Word y,
Word sizeX, Word sizeY,
Byte mainAreaType,
Dword mainAreaColour,
Byte headerType,
Dword headerColour,
Dword borderColour
)
{
Dword arg1, arg2, arg3, arg4;
//
arg1 = ( x << 16 ) + sizeX;
arg2 = ( y << 16 ) + sizeY;
arg3 = ( mainAreaType << 24 ) | mainAreaColour;
arg4 = ( headerType << 24 ) | headerColour;
//
__asm{
mov eax, 0
mov ebx, arg1
mov ecx, arg2
mov edx, arg3
mov esi, arg4
mov edi, borderColour
int 0x40
}
}
// ôóíêöèÿ 1 ïîñòàâèòü òî÷êó
void kos_PutPixel( Dword x, Dword y, Dword colour )
{
//
__asm{
mov eax, 1
mov ebx, x
mov ecx, y
mov edx, colour
int 0x40
}
}
// ôóíêöèÿ 2 ïîëó÷èòü êîä íàæàòîé êëàâèøè
bool kos_GetKey( Byte &keyCode )
{
Dword result;
//
__asm{
mov eax, 2
int 0x40
mov result, eax
}
//
keyCode = result >> 8;
//
return ( result & 0xFF ) == 0;
}
// ôóíêöèÿ 3 ïîëó÷èòü âðåìÿ
Dword kos_GetSystemClock()
{
// Dword result;
//
__asm{
mov eax, 3
int 0x40
// mov result, eax
}
//
// return result;
}
// ôóíêöèÿ 4
void kos_WriteTextToWindow(
Word x,
Word y,
Byte fontType,
Dword textColour,
char *textPtr,
Dword textLen
)
{
Dword arg1, arg2;
//
arg1 = ( x << 16 ) | y;
arg2 = ( fontType << 24 ) | textColour;
//
__asm{
mov eax, 4
mov ebx, arg1
mov ecx, arg2
mov edx, textPtr
mov esi, textLen
int 0x40
}
}
// ôóíêöèÿ 5 ïàóçà, â ñîòûõ äîëÿõ ñåêóíäû
void kos_Pause( Dword value )
{
//
__asm{
mov eax, 5
mov ebx, value
int 0x40
}
}
// ôóíêöèÿ 7 íàðèñîâàòü èçîáðàæåíèå
void kos_PutImage( RGB * imagePtr, Word sizeX, Word sizeY, Word x, Word y )
{
Dword arg1, arg2;
//
arg1 = ( sizeX << 16 ) | sizeY;
arg2 = ( x << 16 ) | y;
//
__asm{
mov eax, 7
mov ebx, imagePtr
mov ecx, arg1
mov edx, arg2
int 0x40
}
}
// ôóíêöèÿ 8 îïðåäåëèòü êíîïêó
void kos_DefineButton( Word x, Word y, Word sizeX, Word sizeY, Dword buttonID, Dword colour )
{
Dword arg1, arg2;
//
arg1 = ( x << 16 ) | sizeX;
arg2 = ( y << 16 ) | sizeY;
//
__asm{
mov eax, 8
mov ebx, arg1
mov ecx, arg2
mov edx, buttonID
mov esi, colour
int 0x40
}
}
// ôóíêöèÿ 9 - èíôîðìàöèÿ î ïðîöåññå
Dword kos_ProcessInfo( sProcessInfo *targetPtr, Dword processID )
{
// Dword result;
//
__asm{
mov eax, 9
mov ebx, targetPtr
mov ecx, processID
int 0x40
// mov result, eax
}
//
// return result;
}
// ôóíêöèÿ 10
Dword kos_WaitForEvent()
{
// Dword result;
__asm{
mov eax, 10
int 0x40
// mov result, eax
}
// return result;
}
// ôóíêöèÿ 11
Dword kos_CheckForEvent()
{
// Dword result;
__asm{
mov eax, 11
int 0x40
// mov result, eax
}
// return result;
}
// ôóíêöèÿ 12
void kos_WindowRedrawStatus( Dword status )
{
__asm{
mov eax, 12
mov ebx, status
int 0x40
}
}
// ôóíêöèÿ 13 íàðèñîâàòü ïîëîñó
void kos_DrawBar( Word x, Word y, Word sizeX, Word sizeY, Dword colour )
{
Dword arg1, arg2;
//
arg1 = ( x << 16 ) | sizeX;
arg2 = ( y << 16 ) | sizeY;
//
__asm{
mov eax, 13
mov ebx, arg1
mov ecx, arg2
mov edx, colour
int 0x40
}
}
// ôóíêöèÿ 17
bool kos_GetButtonID( Dword &buttonID )
{
Dword result;
//
__asm{
mov eax, 17
int 0x40
mov result, eax
}
//
buttonID = result >> 8;
//
return (result & 0xFF) == 0;
}
// ôóíêöèÿ 23
Dword kos_WaitForEvent( Dword timeOut )
{
// Dword result;
__asm{
mov eax, 23
mov ebx, timeOut
int 0x40
// mov result, eax
}
// return result;
}
// ïîëó÷åíèå èíôîðìàöèè î ñîñòîÿíèè "ìûøè" ôóíêöèÿ 37
void kos_GetMouseState( Dword & buttons, int & cursorX, int & cursorY )
{
Dword mB;
Word curX;
Word curY;
sProcessInfo sPI;
//
__asm{
mov eax, 37
mov ebx, 0
int 0x40
mov curY, ax
shr eax, 16
mov curX, ax
mov eax, 37
mov ebx, 2
int 0x40
mov mB, eax
}
//
kos_ProcessInfo( &sPI );
//
buttons = mB;
cursorX = curX - sPI.processInfo.x_start;
cursorY = curY - sPI.processInfo.y_start;
}
// ôóíêöèÿ 40 óñòàíîâèòü ìàñêó ñîáûòèé
void kos_SetMaskForEvents( Dword mask )
{
//
__asm{
mov eax, 40
mov ebx, mask
int 0x40
}
}
// ôóíêöèÿ 47 âûâåñòè â îêíî ïðèëîæåíèÿ ÷èñëî
void kos_DisplayNumberToWindow(
Dword value,
Dword digitsNum,
Word x,
Word y,
Dword colour,
eNumberBase nBase,
bool valueIsPointer
)
{
Dword arg1, arg2;
//
arg1 = ( valueIsPointer ? 1 : 0 ) |
( ((Byte)nBase) << 8 ) |
( ( digitsNum & 0x1F ) << 16 );
arg2 = ( x << 16 ) | y;
//
__asm{
mov eax, 47
mov ebx, arg1
mov ecx, value
mov edx, arg2
mov esi, colour
int 0x40
}
}
// ôóíêöèÿ 70 äîñòóï ê ôàéëîâîé ñèñòåìå
Dword kos_FileSystemAccess( kosFileInfo *fileInfo )
{
// Dword result;
//
__asm{
mov eax, 70
mov ebx, fileInfo
int 0x40
// mov result, eax
}
//
// return result;
}
// ôóíêöèÿ 63 âûâîä ñèìâîëÿ â îêíî îòëàäêè
void kos_DebugOutChar( char ccc )
{
//
__asm{
mov eax, 63
mov ebx, 1
mov cl, ccc
int 0x40
}
}
// ôóíêöèÿ 66 ðåæèì ïîëó÷åíèÿ äàííûõ îò êëàâèàòóðû
void kos_SetKeyboardDataMode( Dword mode )
{
//
__asm{
mov eax, 66
mov ebx, 1
mov ecx, mode
int 0x40
}
}
// âûâîä ñòðîêè â îêíî îòëàäêè
void rtlDebugOutString( char *str )
{
//
for ( ; str[0] != 0; str++ )
{
kos_DebugOutChar( str[0] );
}
//
kos_DebugOutChar( 13 );
kos_DebugOutChar( 10 );
}
// ôóíêöèÿ 64 èçìåíåíèå êîëè÷åñòâà ïàìÿòè, âûäåëåííîé äëÿ ïðîãðàììû
bool kos_ApplicationMemoryResize( Dword targetSize )
{
Dword result;
//
__asm{
mov eax, 64
mov ebx, 1
mov ecx, targetSize
int 0x40
mov result, eax
}
//
return result == 0;
}
// ôóíêöèÿ 67 èçìåíèòü ïàðàìåòðû îêíà, ïàðàìåòð == -1 íå ìåíÿåòñÿ
void kos_ChangeWindow( Dword x, Dword y, Dword sizeX, Dword sizeY )
{
//
__asm{
mov eax, 67
mov ebx, x
mov ecx, y
mov edx, sizeX
mov esi, sizeY
int 0x40
}
}
// âûçîâ àáñòðàêòíîãî ìåòîäà
int __cdecl _purecall()
{
rtlDebugOutString( pureCallMessage );
kos_ExitApp();
return 0;
}
// âûçîâ ñòàòè÷åñêèõ èíèöèàëèçàòîðîâ
// çàîäíî èíèöèàëèçàöèÿ ãåíåðàòîðà ñëó÷àéíûõ ÷èñåë
//#pragma section(".CRT$XCA",long,read,write)
//#pragma section(".CRT$XCZ",long,read,write)
#pragma data_seg(".CRT$XCA")
#pragma data_seg(".CRT$XCZ")
typedef void (__cdecl *_PVFV)(void);
__declspec(allocate(".CRT$XCA")) _PVFV __xc_a[1] = { NULL };
__declspec(allocate(".CRT$XCZ")) _PVFV __xc_z[1] = { NULL };
//
#pragma comment(linker, "/merge:.CRT=.rdata")
//
void crtStartUp()
{
// âûçûâàåì èíèöèàëèçàòîðû ïî ñïèñêó, NULL'û èãíîðèðóåì
for ( _PVFV *pbegin = __xc_a; pbegin < __xc_z; pbegin++ )
{
//
if ( *pbegin != NULL )
(**pbegin)();
}
// èíèöèàëèçèðóåì ãåíåðàòîð ñëó÷àéíûõ ÷èñåë
rtlSrand( kos_GetSystemClock() );
// ïóòü ê ôàéëó ïðîöåññà
kosExePath = *((char **)0x20);
// âûçîâ ãëàâíîé ôóíêöèè ïðèëîæåíèÿ
kos_Main();
// âûõîä
kos_ExitApp();
}

View File

@ -1,209 +0,0 @@
typedef unsigned __int32 Dword;
typedef unsigned __int16 Word;
typedef unsigned __int8 Byte;
//typedef unsigned __int32 size_t;
#define NULL 0
#define MAX_PATH 256
#define FO_READ 0
#define FO_WRITE 2
#define EM_WINDOW_REDRAW 1
#define EM_KEY_PRESS 2
#define EM_BUTTON_CLICK 4
#define EM_APP_CLOSE 8
#define EM_DRAW_BACKGROUND 16
#define EM_MOUSE_EVENT 32
#define EM_IPC 64
#define EM_NETWORK 256
#define KM_CHARS 0
#define KM_SCANS 1
#define WRS_BEGIN 1
#define WRS_END 2
#define PROCESS_ID_SELF -1
#define abs(a) (a<0?0-a:a)
extern "C" double acos(double x);
extern "C" double asin(double x);
extern "C" double floor(double x);
extern "C" double round(double x);
#pragma function(acos,asin)
#if _MSC_VER > 1200
#pragma function(floor)
#endif
struct kosFileInfo
{
Dword rwMode;
Dword OffsetLow;
Dword OffsetHigh;
Dword dataCount;
Byte *bufferPtr;
char fileURL[MAX_PATH];
};
struct RGB
{
Byte b;
Byte g;
Byte r;
//
RGB() {};
//
RGB( Dword value )
{
r = (Byte)(value >> 16);
g = (Byte)(value >> 8);
b = (Byte)value;
};
//
bool operator != ( RGB &another )
{
return this->b != another.b || this->g != another.g || this->r != another.r;
};
//
bool operator == ( RGB &another )
{
return this->b == another.b && this->g == another.g && this->r == another.r;
};
};
union sProcessInfo
{
Byte rawData[1024];
struct
{
Dword cpu_usage;
Word window_stack_position;
Word window_stack_value;
Word reserved1;
char process_name[12];
Dword memory_start;
Dword used_memory;
Dword PID;
Dword x_start;
Dword y_start;
Dword x_size;
Dword y_size;
Word slot_state;
} processInfo;
};
//
extern char *kosExePath;
//
void crtStartUp();
//
int __cdecl _purecall();
//
int __cdecl atexit( void (__cdecl *func )( void ));
//
void rtlSrand( Dword seed );
Dword rtlRand( void );
//
char * __cdecl strcpy( char *target, const char *source );
int __cdecl strlen( const char *line );
char * __cdecl strrchr( const char * string, int c );
#if _MSC_VER < 1400
extern "C" void * __cdecl memcpy( void *dst, const void *src, size_t bytesCount );
extern "C" void memset( Byte *dst, Byte filler, Dword count );
#pragma intrinsic(memcpy,memset)
#else
void * __cdecl memcpy( void *dst, const void *src, size_t bytesCount );
void memset( Byte *dst, Byte filler, Dword count );
#endif
void sprintf( char *Str, char* Format, ... );
//
Dword rtlInterlockedExchange( Dword *target, Dword value );
// ôóíêöèÿ -1 çàâåðøåíèÿ ïðîöåññà
void kos_ExitApp();
// ôóíêöèÿ 0
void kos_DefineAndDrawWindow(
Word x, Word y,
Word sizeX, Word sizeY,
Byte mainAreaType, Dword mainAreaColour,
Byte headerType, Dword headerColour,
Dword borderColour
);
// ôóíêöèÿ 1 ïîñòàâèòü òî÷êó
void kos_PutPixel( Dword x, Dword y, Dword colour );
// ôóíêöèÿ 2 ïîëó÷èòü êîä íàæàòîé êëàâèøè
bool kos_GetKey( Byte &keyCode );
// ôóíêöèÿ 3 ïîëó÷èòü âðåìÿ
Dword kos_GetSystemClock();
// ôóíêöèÿ 4
void kos_WriteTextToWindow(
Word x, Word y,
Byte fontType,
Dword textColour,
char *textPtr,
Dword textLen
);
// ôóíêöèÿ 7 íàðèñîâàòü èçîáðàæåíèå
void kos_PutImage( RGB * imagePtr, Word sizeX, Word sizeY, Word x, Word y );
// ôóíêöèÿ 8 îïðåäåëèòü êíîïêó
void kos_DefineButton( Word x, Word y, Word sizeX, Word sizeY, Dword buttonID, Dword colour );
// ôóíêöèÿ 5 ïàóçà, â ñîòûõ äîëÿõ ñåêóíäû
void kos_Pause( Dword value );
// ôóíêöèÿ 9 - èíôîðìàöèÿ î ïðîöåññå
Dword kos_ProcessInfo( sProcessInfo *targetPtr, Dword processID = PROCESS_ID_SELF );
// ôóíêöèÿ 10
Dword kos_WaitForEvent();
// ôóíêöèÿ 11
Dword kos_CheckForEvent();
// ôóíêöèÿ 12
void kos_WindowRedrawStatus( Dword status );
// ôóíêöèÿ 13 íàðèñîâàòü ïîëîñó
void kos_DrawBar( Word x, Word y, Word sizeX, Word sizeY, Dword colour );
// ôóíêöèÿ 17
bool kos_GetButtonID( Dword &buttonID );
// ôóíêöèÿ 23
Dword kos_WaitForEvent( Dword timeOut );
//
enum eNumberBase
{
nbDecimal = 0,
nbHex,
nbBin
};
// ïîëó÷åíèå èíôîðìàöèè î ñîñòîÿíèè "ìûøè" ôóíêöèÿ 37
void kos_GetMouseState( Dword & buttons, int & cursorX, int & cursorY );
// ôóíêöèÿ 40 óñòàíîâèòü ìàñêó ñîáûòèé
void kos_SetMaskForEvents( Dword mask );
// ôóíêöèÿ 47 âûâåñòè â îêíî ïðèëîæåíèÿ ÷èñëî
void kos_DisplayNumberToWindow(
Dword value,
Dword digitsNum,
Word x,
Word y,
Dword colour,
eNumberBase nBase = nbDecimal,
bool valueIsPointer = false
);
// ôóíêöèÿ 58 äîñòóï ê ôàéëîâîé ñèñòåìå
Dword kos_FileSystemAccess( kosFileInfo *fileInfo );
// ôóíêöèÿ 63
void kos_DebugOutChar( char ccc );
//
void rtlDebugOutString( char *str );
// ôóíêöèÿ 64 èçìåíèòü ïàðàìåòðû îêíà, ïàðàìåòð == -1 íå ìåíÿåòñÿ
void kos_ChangeWindow( Dword x, Dword y, Dword sizeX, Dword sizeY );
// ôóíêöèÿ 67 èçìåíåíèå êîëè÷åñòâà ïàìÿòè, âûäåëåííîé äëÿ ïðîãðàììû
bool kos_ApplicationMemoryResize( Dword targetSize );
// ôóíêöèÿ 66 ðåæèì ïîëó÷åíèÿ äàííûõ îò êëàâèàòóðû
void kos_SetKeyboardDataMode( Dword mode );
//
void kos_Main();

View File

@ -1,55 +0,0 @@
#include "kosSyst.h"
#include "kosFile.h"
#include "stdafx.h"
#include <stdio.h>
const char header[] = "Kolibri Rule";
void draw_window(void)
{
int a=5;
int b=10;
// start redraw
kos_WindowRedrawStatus(1);
// define&draw window
kos_DefineAndDrawWindow(10,40,360,68,
0x33,0xFEF977,0,0,(Dword)header);
while (a<355)
{
kos_DrawBar(a,0,1,30,0x000000);
a=a+10;
}
while (b<350)
{
kos_DrawBar(b,0,1,20,0x000000);
b=b+10;
}
// end redraw
kos_WindowRedrawStatus(2);
}
void kos_Main()
{
draw_window();
for (;;)
{
switch (kos_WaitForEvent())
{
case 1:
draw_window();
break;
case 2:
// key pressed, read it and ignore
Byte keyCode;
kos_GetKey(keyCode);
break;
case 3:
// button pressed; we have only one button, close
kos_ExitApp();
}
}
}

View File

@ -1,83 +0,0 @@
#include <math.h>
#include "kosSyst.h"
extern "C" int _fltused = 0;
double acos(double x)
{
__asm {
fld qword ptr [esp+4]
fld1
fadd st, st(1)
fld1
fsub st, st(2)
fmulp st(1), st
fsqrt
fxch st(1)
fpatan
}
}
double asin(double x)
{
__asm {
fld qword ptr [esp+4]
fld1
fadd st, st(1)
fld1
fsub st, st(2)
fmulp st(1), st
fsqrt
fpatan
ret
}
}
#if _MSC_VER <= 1200
extern "C" double _ftol(double x)
{
__asm {
fld qword ptr [esp+4]
push 1F3Fh
fstcw word ptr [esp+2]
fldcw word ptr [esp]
frndint
fldcw word ptr [esp+2]
add esp, 4
}
}
#endif
double ceil(double x)
{
__asm {
fld qword ptr [esp+4]
push 1B3Fh
fstcw word ptr [esp+2]
fldcw word ptr [esp]
frndint
fldcw word ptr [esp+2]
add esp, 4
}
}
double floor(double x)
{
__asm {
fld qword ptr [esp+4]
push 173Fh
fstcw word ptr [esp+2]
fldcw word ptr [esp]
frndint
fldcw word ptr [esp+2]
add esp, 4
}
}
double round(double x)
{
__asm {
fld qword ptr [esp+4]
push 133Fh
fstcw word ptr [esp+2]
fldcw word ptr [esp]
frndint
fldcw word ptr [esp+2]
add esp, 4
}
}

View File

@ -1,329 +0,0 @@
// memman.cpp : Defines the entry point for the console application.
//
#include "kosSyst.h"
#include "mcsmemm.h"
void * __cdecl operator new ( size_t count, size_t element_size )
{
return allocmem( (Dword)(count * element_size) );
}
void * __cdecl operator new [] ( size_t amount )
{
return allocmem( (Dword)amount );
}
void * __cdecl operator new ( size_t amount )
{
return allocmem( (Dword)amount );
}
void __cdecl operator delete ( void *pointer )
{
if ( pointer != NULL ) freemem( pointer );
}
void __cdecl operator delete [] ( void *pointer )
{
if ( pointer != NULL ) freemem( pointer );
}
//
Dword mmMutex = FALSE;
MemBlock *rootfree = NULL;
MemBlock *rootuser = NULL;
bool mmInitialized = false;
Byte *mmHeapTop = NULL;
//
Byte * AllocMemFromSystem( Dword reqSize )
{
Byte *result;
sProcessInfo pInfo;
//
if ( mmInitialized )
{
result = mmHeapTop;
}
else
{
//
kos_ProcessInfo( &pInfo );
//
result = (Byte *)(pInfo.processInfo.used_memory + 1);
//
mmInitialized = true;
}
//
if ( ! kos_ApplicationMemoryResize( ((Dword)result) + reqSize ) )
{
result = NULL;
}
//
mmHeapTop = result + reqSize;
//
return result;
}
//
Byte *allocmem( Dword reqsize )
{
MemBlock *BlockForCheck;
MemBlock *LastKnownGood;
Dword tail;
Byte *address;
//ïîäðîâíÿåì ðàçìåð
if( ( tail = reqsize % SIZE_ALIGN ) != 0 )
{
reqsize += SIZE_ALIGN - tail;
}
LastKnownGood = NULL;
// æä¸ì îñâîáîæäåíèÿ ìüþòåêñà
while ( rtlInterlockedExchange( &mmMutex, TRUE ) )
{
//
kos_Pause( 1 );
}
//èùåì ïîäõîäÿùèé ñâîáîäíûé áëîê
if( rootfree != NULL )
{
for ( BlockForCheck = rootfree; ; BlockForCheck = BlockForCheck->Next )
{
if ( BlockForCheck->Size >= reqsize )
{
//íàøëè
if ( LastKnownGood != NULL )
{
if ( LastKnownGood->Size >= BlockForCheck->Size )
LastKnownGood = BlockForCheck;
}
else
LastKnownGood = BlockForCheck;
if ( LastKnownGood->Size == reqsize )
break;
}
if ( BlockForCheck->Next == NULL )
break;
}
}
if ( LastKnownGood != NULL )
{
//ïðîâåðèì íàéäåííûé áëîê íà âîçìîæíîñòü äåëåíèÿ
tail = LastKnownGood->Size - reqsize;
if ( tail >= ( sizeof(MemBlock) + SIZE_ALIGN ) )
{
//áóäåì ðàçáèâàòü
BlockForCheck = (MemBlock *)( ( (Byte *)LastKnownGood ) + tail );
BlockForCheck->Size = reqsize;
//âñòàâèì çàíÿòûé áëîê â íà÷àëî ñïèñêà çàíàòûõ áëîêîâ
if( rootuser != NULL )
{
BlockForCheck->Next = rootuser;
rootuser->Previous = BlockForCheck;
BlockForCheck->Previous = NULL;
rootuser = BlockForCheck;
}
else
{
rootuser = BlockForCheck;
BlockForCheck->Next = NULL;
BlockForCheck->Previous = NULL;
}
//èçìåíèì ðàçìåð îñòàâøåéñÿ ÷àñòè
LastKnownGood->Size = tail - sizeof(MemBlock);
address = ( (Byte *)BlockForCheck ) + sizeof(MemBlock);
// îòïóñòèì ìüþòåêñ
rtlInterlockedExchange( &mmMutex, FALSE );
return address;
}
else
{
//ïåðåìåñòè áëîê èç î÷åðåäè ñâîáîäíûõ â íà÷àëî î÷åðåäè çàíÿòûõ
//ñíà÷àëà âûêèíåì åãî èç î÷åðåäè ñâîáîäíûõ
if ( LastKnownGood->Previous != NULL )
{
LastKnownGood->Previous->Next = LastKnownGood->Next;
}
else
{
//áëîê ñòîèò â íà÷àëå î÷åðåäè
rootfree = LastKnownGood->Next;
}
if( LastKnownGood->Next != NULL )
{
LastKnownGood->Next->Previous = LastKnownGood->Previous;
}
//òåïåðü âñòàâèì åãî â î÷åðåäü çàíÿòûõ
if( rootuser != NULL )
{
LastKnownGood->Next = rootuser;
rootuser->Previous = LastKnownGood;
LastKnownGood->Previous = NULL;
rootuser = LastKnownGood;
}
else
{
rootuser = LastKnownGood;
LastKnownGood->Next = NULL;
LastKnownGood->Previous = NULL;
}
//
address = ( (Byte *)LastKnownGood ) + sizeof(MemBlock);
// îòïóñòèì ìüþòåêñ
rtlInterlockedExchange( &mmMutex, FALSE );
return address;
}
}
else
{
//íàäî ïîëó÷èòü åù¸ êóñî÷åê ïàìÿòè
LastKnownGood = (MemBlock *)AllocMemFromSystem( reqsize + sizeof(MemBlock) );
//
if( LastKnownGood != NULL )
{
LastKnownGood->Size = reqsize;
//òåïåðü âñòàâèì åãî â î÷åðåäü çàíÿòûõ
if( rootuser != NULL )
{
LastKnownGood->Next = rootuser;
rootuser->Previous = LastKnownGood;
LastKnownGood->Previous = NULL;
rootuser = LastKnownGood;
}
else
{
rootuser = LastKnownGood;
LastKnownGood->Next = NULL;
LastKnownGood->Previous = NULL;
}
address = ( (Byte *)LastKnownGood ) + sizeof(MemBlock);
// îòïóñòèì ìüþòåêñ
rtlInterlockedExchange( &mmMutex, FALSE );
return address;
}
}
// îòïóñòèì ìüþòåêñ
rtlInterlockedExchange( &mmMutex, FALSE );
//
rtlDebugOutString( "allocmem failed." );
kos_ExitApp();
//
return NULL;
}
//
Dword freemem( void *vaddress )
{
Dword result;
Byte *checknext, *address = (Byte *)vaddress;
// æä¸ì îñâîáîæäåíèÿ ìüþòåêñà
while ( rtlInterlockedExchange( &mmMutex, TRUE ) )
{
//
kos_Pause( 1 );
}
MemBlock *released = (MemBlock *)( address - sizeof(MemBlock) );
result = released->Size;
//óáèðàåì áëîê èç ñïèñêà çàíÿòûõ
if ( released->Previous != NULL )
{
released->Previous->Next = released->Next;
}
else
{
rootuser = released->Next;
}
if ( released->Next != NULL )
{
released->Next->Previous = released->Previous;
}
//çàêèíåì òåïåðü ýòîò áëîê â ñïèñîê ñâîáîäíûõ
released->Next = rootfree;
released->Previous = NULL;
rootfree = released;
if ( released->Next != NULL )
{
released->Next->Previous = released;
}
//òåïåðü ïîèùåì ñìåæíûå ñâîáîäíûå áëîêè
checknext = (Byte *)(rootfree) + ( rootfree->Size + sizeof(MemBlock) );
//
for ( released = rootfree->Next; released != NULL; released = released->Next )
{
if ( checknext == (Byte *)released )
{
//ñîáèðàåì áëîêè âìåñòå
//ñíà÷àëà âûêèíåì èç î÷åðåäè ñâîáîäíûõ
released->Previous->Next = released->Next;
if( released->Next != NULL )
{
released->Next->Previous = released->Previous;
}
//òåïåðü óâåëè÷èì ðàçìåð êîðíåâîãî áëîêà
rootfree->Size += released->Size + sizeof(MemBlock);
break;
}
}
//åñëè íàäî, ïîèùåì áëîêè ïåðåä òåêùèì.
checknext = (Byte *)(rootfree);
//
if ( released == NULL )
{
for ( released = rootfree->Next; released != NULL; released = released->Next )
{
if ( checknext == (Byte *)released + ( released->Size + sizeof(MemBlock) ) )
{
//ñîáèðàåì áëîêè âìåñòå
//óâåëè÷èì ðàçìåð áëîêà
released->Size += rootfree->Size + sizeof(MemBlock);
//òåïåðü âûêèíåì èç î÷åðåäè ñâîáîäíûõ
released->Previous->Next = released->Next;
if ( released->Next != NULL )
{
released->Next->Previous = released->Previous;
}
//è çàêèíåì åãî â íà÷àëî î÷åðåäè âìåñòî ïðèñîåäèí¸ííîãî áëîêà èç êîðíÿ ñïèñêà
if ( rootfree->Next != NULL )
{
rootfree->Next->Previous = released;
}
released->Next = rootfree->Next;
released->Previous = NULL;
rootfree = released;
break;
}
}
}
// îòïóñòèì ìüþòåêñ
rtlInterlockedExchange( &mmMutex, FALSE );
return result;
}

View File

@ -1,8 +0,0 @@
// stdafx.cpp : source file that includes just the standard includes
// FixedPoint.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

View File

@ -1,11 +0,0 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// TODO: reference additional headers your program requires here

View File

@ -0,0 +1,4 @@
if tup.getconfig("NO_FASM") ~= "" then return end
tup.rule("kruler.asm", "fasm %f %o " .. tup.getconfig("KPACK_CMD"), "kruler")

1
programs/other/kruler/build.sh Executable file
View File

@ -0,0 +1 @@
fasm kruler.asm kruler

View File

@ -0,0 +1,109 @@
; KRuler - a screen ruler
; rgimad 2021
; author of idea - ConLenov
; header:
use32
org 0
db 'MENUET01' ; magic
dd 1 ; header version
dd START ; entry point
dd I_END ; program size
dd MEM ; memory size
dd STACKTOP ; stack top addr
dd 0 ; buf for args
dd 0 ; reversed
WND_START_X = 10
WND_START_Y = 40
WND_WIDTH = 360
WND_HEIGHT = 68
include "../../macros.inc"
START:
; event loop:
event_loop:
mcall 10 ; wait for event
cmp eax, 1 ; redraw event
je on_redraw
cmp eax,3 ; btn
je on_button
jmp event_loop
on_button:
mcall 17 ; 17 - get key code
cmp ah, 1 ; if key with code 1 is not pressed then continue
jne event_loop
mcall -1 ; else exit
; define and draw window
on_redraw:
mcall 12, 1 ; begin redraw
; mcall 48, 3, sc,sizeof.system_colors
mov edx, 0xFEF977 ; background color
or edx, 0x34000000 ; window type
mcall 0, <WND_START_X, WND_WIDTH>, <WND_START_Y, WND_HEIGHT>, , , wnd_title
mov esi, 5
.while1:
cmp esi, 355
jae .while1_end
mov eax, 38
mov ebx, esi
shl ebx, 16
add ebx, esi
xor ecx, ecx
shl ecx, 16
add ecx, 30 ; stripe height
xor edx, edx
int 0x40
add esi, 10
jmp .while1
.while1_end:
mov esi, 10
.while2:
cmp esi, 350
jae .while2_end
mov eax, 38
mov ebx, esi
shl ebx, 16
add ebx, esi
xor ecx, ecx
shl ecx, 16
add ecx, 20 ; stripe height
xor edx, edx
int 0x40
add esi, 10
jmp .while2
.while2_end:
mcall 12, 2 ; end draw
jmp event_loop
; data:
sc system_colors
wnd_title db 'KRuler v0.0.1',0
; labels:
I_END:
rb 4096 ; for stack
align 16
STACKTOP: ; stack top label, stack grows downwards
MEM: ; end