Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 1804 → Rev 1805

/programs/games/xonix/trunk/MCSMEMM.H
0,0 → 1,28
//
 
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 );
 
 
 
/programs/games/xonix/trunk/Release/pe2kos.exe
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/programs/games/xonix/trunk/Release
Property changes:
Added: tsvn:logminsize
+5
\ No newline at end of property
/programs/games/xonix/trunk/fatest.sln
0,0 → 1,19
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fatest", "fatest.vcproj", "{9A6F70FC-7AC8-4C42-9B67-FD65BE79F79A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9A6F70FC-7AC8-4C42-9B67-FD65BE79F79A}.Debug|Win32.ActiveCfg = Debug|Win32
{9A6F70FC-7AC8-4C42-9B67-FD65BE79F79A}.Debug|Win32.Build.0 = Debug|Win32
{9A6F70FC-7AC8-4C42-9B67-FD65BE79F79A}.Release|Win32.ActiveCfg = Release|Win32
{9A6F70FC-7AC8-4C42-9B67-FD65BE79F79A}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
/programs/games/xonix/trunk/fatest.vcproj
0,0 → 1,246
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="fatest"
ProjectGUID="{9A6F70FC-7AC8-4C42-9B67-FD65BE79F79A}"
RootNamespace="fatest"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="1"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="false"
FavorSizeOrSpeed="2"
WholeProgramOptimization="true"
PreprocessorDefinitions="NDEBUG;_CONSOLE"
ExceptionHandling="0"
StructMemberAlignment="1"
BufferSecurityCheck="false"
DisableLanguageExtensions="false"
RuntimeTypeInfo="false"
UsePrecompiledHeader="0"
AssemblerOutput="2"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="0"
CallingConvention="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
IgnoreImportLibrary="true"
AdditionalOptions="/ALIGN:32"
OutputFile="$(OutDir)/xonix.exe"
LinkIncremental="1"
GenerateManifest="false"
IgnoreAllDefaultLibraries="true"
GenerateDebugInformation="false"
SubSystem="1"
OptimizeReferences="0"
EnableCOMDATFolding="0"
EntryPointSymbol="crtStartUp"
BaseAddress="0x0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
EmbedManifest="false"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\kosSyst.cpp"
>
</File>
<File
RelativePath=".\main.cpp"
>
</File>
<File
RelativePath=".\mcsmemm.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\kosSyst.h"
>
</File>
<File
RelativePath=".\lang.h"
>
</File>
<File
RelativePath=".\mcarray.h"
>
</File>
<File
RelativePath=".\MCSMEMM.H"
>
</File>
<File
RelativePath=".\resource.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
/programs/games/xonix/trunk/kosSyst.cpp
0,0 → 1,829
#include "kosSyst.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;
}
 
//
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
}
}
 
//
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 sprintk( char *Str, PRINTK *arg )
{
int i, fmtlinesize, j, ac, k, flag;
Dword head, tail;
char c;
//
ac = 0;
 
//
fmtlinesize = strlen( arg->fmtline );
//
if( fmtlinesize == 0 ) return;
//
for( i = 0, j = 0; i < fmtlinesize; i++ )
{
//
c = arg->fmtline[i];
//
if( c != '%' )
{
Str[j++] = c;
continue;
}
//
i++;
//
if( i >= fmtlinesize ) break;
 
//
flag = 0;
//
c = arg->fmtline[i];
//
switch( c )
{
//
case '%':
Str[j++] = c;
break;
// âûâîä ñòðîêè
case 'S':
for( k = 0; ( c = ((Byte *)arg->args[ac])[k] ) != 0; k++ )
{
Str[j++] = c;
}
ac++;
break;
// âûâîä áàéòà
case 'B':
k = (int)(arg->args[ac]) & 0xFF;
Str[j++] = num2hex( ( k >> 4 ) & 0xF );
Str[j++] = num2hex( k & 0xF );
ac++;
break;
// âûâîä ñèìâîëà
case 'C':
Str[j++] = (int)(arg->args[ac]) & 0xFF;
ac++;
break;
// âûâîä äâîéíîãî ñëîâà â øåñòíàäöàòèðè÷íîì âèäå
case 'X':
for( k = 7; k >= 0; k-- )
{
//
c = num2hex ( ( (Dword)(arg->args[ac]) >> (k * 4) ) & 0xF );
//
if( c == '0' )
{
if( flag ) Str[j++] = c;
}
else
{
flag++;
Str[j++] = c;
}
}
//
if( flag == 0 ) Str[j++] = '0';
ac++;
break;
// âûâîä äâîéíîãî ñëîâà â äåñÿòè÷íîì âèäå
case 'U':
head = (Dword)(arg->args[ac]);
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;
ac++;
break;
// âûâîä 64-áèòíîãî ñëîâà â øåñòíàäöàòèðè÷íîì âèäå
case 'Q':
for( k = 7; k >= 0; k-- )
{
//
c = num2hex ( ( *((unsigned int *)(arg->args[ac]) + 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 ( ( *((unsigned int *)(arg->args[ac])) >> (k * 4) ) & 0xF );
//
if( c == '0' )
{
if( flag ) Str[j++] = c;
}
else
{
flag++;
Str[j++] = c;
}
}
//
if( flag == 0 ) Str[j++] = '0';
//
ac++;
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)
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();
}
 
 
/programs/games/xonix/trunk/kosSyst.h
0,0 → 1,201
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)
 
 
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 = value >> 16;
g = value >> 8;
b = 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;
};
 
struct PRINTK
{
char *fmtline;
Dword args[11];
};
 
//
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 );
//
void * __cdecl memcpy( void *dst, const void *src, size_t bytesCount );
//
void memset( Byte *dst, Byte filler, Dword count );
//
void sprintk( char *Str, PRINTK *arg );
//
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();
/programs/games/xonix/trunk/lang.h
0,0 → 1,3
#define RUS 1
#define ENG 2
#define LANG RUS
/programs/games/xonix/trunk/logo.bmp
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/programs/games/xonix/trunk/main.cpp
0,0 → 1,2500
#include "kosSyst.h"
#include "mcarray.h"
#include "lang.h"
 
 
// áèòìàï ïóñòîãî ìåñòà
RGB bmEmpty[] = {
0x201010, 0x101020, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010,
0x101010, 0x102010, 0x201010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010,
0x101010, 0x101010, 0x101020, 0x102010, 0x101010, 0x101010, 0x101010, 0x101010,
0x101010, 0x101010, 0x101010, 0x201010, 0x101020, 0x101010, 0x101010, 0x101010,
0x101010, 0x101010, 0x101010, 0x101010, 0x102010, 0x201010, 0x101010, 0x101010,
0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101020, 0x102010, 0x101010,
0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x201010, 0x101020,
0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x102010
};
 
 
// áèòìàï èãðîêà
RGB bmHero[] = {
0x2020E0, 0x2020E0, 0x2020E0, 0x2020E0, 0x2020E0, 0x2020E0, 0x2020E0, 0x2020C0,
0x2020E0, 0x2020E0, 0x2020E0, 0x2020E0, 0x2020E0, 0x2020E0, 0x2020C0, 0x2020A0,
0x2020E0, 0x2020E0, 0x2020C0, 0x2020C0, 0x2020C0, 0x2020C0, 0x2020A0, 0x2020A0,
0x2020E0, 0x2020E0, 0x2020C0, 0x2020C0, 0x2020C0, 0x2020C0, 0x2020A0, 0x2020A0,
0x2020E0, 0x2020E0, 0x2020C0, 0x2020C0, 0x2020C0, 0x2020C0, 0x2020A0, 0x2020A0,
0x2020E0, 0x2020E0, 0x2020C0, 0x2020C0, 0x2020C0, 0x2020C0, 0x2020A0, 0x2020A0,
0x2020E0, 0x2020C0, 0x2020A0, 0x2020A0, 0x2020A0, 0x2020A0, 0x2020A0, 0x2020A0,
0x2020C0, 0x2020A0, 0x2020A0, 0x2020A0, 0x2020A0, 0x2020A0, 0x2020A0, 0x2020A0
};
 
 
// áèòìàï èãðîêà
RGB bmSuperHero[] = {
0x5720D0, 0x5720D0, 0x5720D0, 0x5720D0, 0x5720D0, 0x5720D0, 0x5720D0, 0x5720B0,
0x5720D0, 0x5720D0, 0x5720D0, 0x5720D0, 0x5720D0, 0x5720D0, 0x5720B0, 0x572090,
0x5720D0, 0x5720D0, 0x5720B0, 0x5720B0, 0x5720B0, 0x5720B0, 0x572090, 0x572090,
0x5720D0, 0x5720D0, 0x5720B0, 0x5720B0, 0x5720B0, 0x5720B0, 0x572090, 0x572090,
0x5720D0, 0x5720D0, 0x5720B0, 0x5720B0, 0x5720B0, 0x5720B0, 0x572090, 0x572090,
0x5720D0, 0x5720D0, 0x5720B0, 0x5720B0, 0x5720B0, 0x5720B0, 0x572090, 0x572090,
0x5720D0, 0x5720B0, 0x572090, 0x572090, 0x572090, 0x572090, 0x572090, 0x572090,
0x5720B0, 0x572090, 0x572090, 0x572090, 0x572090, 0x572090, 0x572090, 0x572090
};
 
 
// áèòìàï ãàäà, áåãàþùåãî ïî çàïîëíåííîé ìåñòíîñòè
RGB bmEnemy1[] = {
0xE02020, 0xE02020, 0xE02020, 0xE02020, 0xE02020, 0xE02020, 0xE02020, 0xC02020,
0xE02020, 0xE02020, 0xE02020, 0xE02020, 0xE02020, 0xE02020, 0xC02020, 0xA02020,
0xE02020, 0xE02020, 0xC02020, 0xC02020, 0xC02020, 0xC02020, 0xA02020, 0xA02020,
0xE02020, 0xE02020, 0xC02020, 0xC02020, 0xC02020, 0xC02020, 0xA02020, 0xA02020,
0xE02020, 0xE02020, 0xC02020, 0xC02020, 0xC02020, 0xC02020, 0xA02020, 0xA02020,
0xE02020, 0xE02020, 0xC02020, 0xC02020, 0xC02020, 0xC02020, 0xA02020, 0xA02020,
0xE02020, 0xC02020, 0xA02020, 0xA02020, 0xA02020, 0xA02020, 0xA02020, 0xA02020,
0xC02020, 0xA02020, 0xA02020, 0xA02020, 0xA02020, 0xA02020, 0xA02020, 0xA02020
};
 
 
// áèòìàï ãàäà, áåãàþùåãî ïî ïóñòîìó ìåñòó
RGB bmEnemy2[] = {
0xE08020, 0xE08020, 0xE08020, 0xE08020, 0xE08020, 0xE08020, 0xE08020, 0xC08020,
0xE08020, 0xE08020, 0xE08020, 0xE08020, 0xE08020, 0xE08020, 0xC08020, 0xA08020,
0xE08020, 0xE08020, 0xC08020, 0xC08020, 0xC08020, 0xC08020, 0xA08020, 0xA08020,
0xE08020, 0xE08020, 0xC08020, 0xC08020, 0xC08020, 0xC08020, 0xA08020, 0xA08020,
0xE08020, 0xE08020, 0xC08020, 0xC08020, 0xC08020, 0xC08020, 0xA08020, 0xA08020,
0xE08020, 0xE08020, 0xC08020, 0xC08020, 0xC08020, 0xC08020, 0xA08020, 0xA08020,
0xE08020, 0xC08020, 0xA08020, 0xA08020, 0xA08020, 0xA08020, 0xA08020, 0xA08020,
0xC08020, 0xA08020, 0xA08020, 0xA08020, 0xA08020, 0xA08020, 0xA08020, 0xA08020
};
 
 
// áèòìàï çàïîëíåíèÿ
RGB bmWall[] = {
0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xCCCCCC,
0xFFFFFF, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xAAAAAA,
0xFFFFFF, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xAAAAAA,
0xFFFFFF, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xAAAAAA,
0xFFFFFF, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xAAAAAA,
0xFFFFFF, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xAAAAAA,
0xFFFFFF, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xCCCCCC, 0xAAAAAA,
0xCCCCCC, 0xAAAAAA, 0xAAAAAA, 0xAAAAAA, 0xAAAAAA, 0xAAAAAA, 0xAAAAAA, 0xAAAAAA
};
 
 
// ñëåä èãðîêà
RGB bmTrack[] = {
0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010,
0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010,
0x101010, 0x101010, 0x101010, 0x1010F0, 0x1010F0, 0x101010, 0x101010, 0x101010,
0x101010, 0x101010, 0x1010F0, 0x1010F0, 0x1010F0, 0x1010F0, 0x101010, 0x101010,
0x101010, 0x101010, 0x1010F0, 0x1010F0, 0x1010F0, 0x1010F0, 0x101010, 0x101010,
0x101010, 0x101010, 0x101010, 0x1010F0, 0x1010F0, 0x101010, 0x101010, 0x101010,
0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010,
0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010
};
 
 
// ñëåä èãðîêà
RGB bmSuperTrack[] = {
0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010,
0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010,
0x101010, 0x101010, 0x101010, 0x5310D0, 0x5310D0, 0x101010, 0x101010, 0x101010,
0x101010, 0x101010, 0x5310D0, 0x5310D0, 0x5310D0, 0x5310D0, 0x101010, 0x101010,
0x101010, 0x101010, 0x5310D0, 0x5310D0, 0x5310D0, 0x5310D0, 0x101010, 0x101010,
0x101010, 0x101010, 0x101010, 0x5310D0, 0x5310D0, 0x101010, 0x101010, 0x101010,
0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010,
0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010, 0x101010
};
 
 
// çàïîëíåíèå ýêðàíà äëÿ ñìåíû óðîâíÿ
RGB bmFlip[] = {
0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0,
0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010,
0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0,
0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010,
0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0,
0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010,
0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0,
0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010, 0xF0F0F0, 0x101010
};
 
 
// áîíóñ íåóÿçâèìîñòè
RGB bmBonus1[] = {
0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xCCCCCC,
0xFFFFFF, 0xCCCCCC, 0xCCCCCC, 0x44AC44, 0x44AC44, 0xCCCCCC, 0xCCCCCC, 0xAAAAAA,
0xFFFFFF, 0xCCCCCC, 0x44AC44, 0x44AC44, 0x44AC44, 0x44AC44, 0xCCCCCC, 0xAAAAAA,
0xFFFFFF, 0x44AC44, 0x44AC44, 0x0C8C0C, 0x0C8C0C, 0x44AC44, 0x44AC44, 0xAAAAAA,
0xFFFFFF, 0x44AC44, 0x44AC44, 0x0C8C0C, 0x0C8C0C, 0x44AC44, 0x44AC44, 0xAAAAAA,
0xFFFFFF, 0xCCCCCC, 0x44AC44, 0x44AC44, 0x44AC44, 0x44AC44, 0xCCCCCC, 0xAAAAAA,
0xFFFFFF, 0xCCCCCC, 0xCCCCCC, 0x44AC44, 0x44AC44, 0xCCCCCC, 0xCCCCCC, 0xAAAAAA,
0xCCCCCC, 0xAAAAAA, 0xAAAAAA, 0xAAAAAA, 0xAAAAAA, 0xAAAAAA, 0xAAAAAA, 0xAAAAAA
};
 
 
// áîíóñ æèçíè
RGB bmBonus2[] = {
0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xCCCCCC,
0xFFFFFF, 0xCCCCCC, 0xD41414, 0xCCCCCC, 0xCCCCCC, 0xD41414, 0xCCCCCC, 0xAAAAAA,
0xFFFFFF, 0xD41414, 0xD41414, 0xD41414, 0xD41414, 0xD41414, 0xD41414, 0xAAAAAA,
0xFFFFFF, 0xD41414, 0xD41414, 0xD41414, 0xD41414, 0xD41414, 0xD41414, 0xAAAAAA,
0xFFFFFF, 0xD41414, 0xD41414, 0xD41414, 0xD41414, 0xD41414, 0xD41414, 0xAAAAAA,
0xFFFFFF, 0xCCCCCC, 0xD41414, 0xD41414, 0xD41414, 0xD41414, 0xCCCCCC, 0xAAAAAA,
0xFFFFFF, 0xCCCCCC, 0xCCCCCC, 0xD41414, 0xD41414, 0xCCCCCC, 0xCCCCCC, 0xAAAAAA,
0xCCCCCC, 0xAAAAAA, 0xAAAAAA, 0xAAAAAA, 0xAAAAAA, 0xAAAAAA, 0xAAAAAA, 0xAAAAAA
};
 
 
//
RGB bmPMButton[] = {
0xCCCCCC, 0xCCCCCC, 0x000000, 0x000000, 0xCCCCCC, 0xCCCCCC,
0xCCCCCC, 0xCCCCCC, 0x000000, 0x000000, 0xCCCCCC, 0xCCCCCC,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0xCCCCCC, 0xCCCCCC, 0x000000, 0x000000, 0xCCCCCC, 0xCCCCCC,
0xCCCCCC, 0xCCCCCC, 0x000000, 0x000000, 0xCCCCCC, 0xCCCCCC,
};
 
 
//
void DrawAppWindow();
//
void DrawTop10Window();
//
void initWorldMap();
//
void drawWorldMap();
//
void clearWorldMap();
//
void drawWorldMapForFlip();
//
void drawWndTitleGo();
//
void ApplyMapDiffs( bool drawTitle = true );
//
int GetCompletePercents();
 
 
#define EAT_ENEMY_BONUS 100
 
#define BEFORE_START_LEVEL 100
#define BONUS1_LIFETIME 250
#define BONUS1_IND_HSIZE 6
 
#define MIN_LOOP_DELAY 1
#define MAX_LOOP_DELAY 20
#define DEFAULT_LOOP_DELAY 12
 
#define blockSize 8
 
#define ENTRY_WND_SIZE_X 400
#define ENTRY_WND_SIZE_Y 144
 
#define TOP10_WND_SIZE_X 176
#define TOP10_WND_SIZE_Y 144
 
#define MAX_X_SIZE 96
#define MIN_X_SIZE 48
#define MAX_Y_SIZE 56
#define MIN_Y_SIZE 28
 
#define flipMapSize ((mapSizeX * mapSizeY) / 4)
#define wndXOffet 1
#define wndYOffset 22
#define freeSpaceCount ((mapSizeX - 4) * (mapSizeY - 4))
//
#define gmEmpty 0
#define gmHero 1
#define gmEnemy1 2
#define gmEnemy2 3
#define gmWall 4
#define gmTrack 5
#define gmFlip 6
#define gmBonus1 7
#define gmBonus2 8
#define gmSuperHero 9
#define gmSuperTrack 10
#define gmProbe 11
 
#define appStateEntry 0
#define appStateGo 1
#define appStateHideMap 2
#define appStateShowMap 3
#define appStatePause 4
#define appStateAfterDeath 5
#define appStateTop10 6
 
#define spacePerEnemy 30
 
 
#define BT_SIZE_X_PLUS 2
#define BT_SIZE_X_MINUS 3
#define BT_LOOP_PLUS 4
#define BT_LOOP_MINUS 5
#define BT_SIZE_Y_PLUS 6
#define BT_SIZE_Y_MINUS 7
 
#define TOP_TBL_SIZE 10
 
 
//
struct hiScoreHero
{
char name[12];
Dword score;
//
hiScoreHero()
{
//
this->ClearName();
this->score = 0;
};
//
void ClearName()
{
memset( (Byte *)(this->name), '.', sizeof(this->name) );
};
};
 
//
char top10FilePath[MAX_PATH];
hiScoreHero heroTbl[TOP_TBL_SIZE];
 
//
struct hiScoreFile
{
Byte block[512];
kosFileInfo fi;
//
hiScoreFile()
{
int i;
 
//
this->fi.offsetLow = this->fi.offsetHigh = 0;
this->fi.dataCount = 0;
this->fi.bufferPtr = this->block;
this->fi.rwMode = 0;
memcpy( this->fi.fileURL, top10FilePath, sizeof( top10FilePath ) );
//
for ( i = 0; i < ( sizeof( this->block ) / sizeof( Dword ) ); i++ )
{
//
((Dword *)(this->block))[i] = rtlRand();
}
};
//
virtual ~hiScoreFile()
{}
//
bool LoadFromDisk()
{
bool result;
int i;
Dword j, k;
Byte *bPtr;
 
//
this->fi.rwMode = FO_READ;
this->fi.dataCount = 512;
result = kos_FileSystemAccess( &(this->fi) ) == 0;
//
if ( result )
{
// äåêîäèðóåì
rtlSrand( ((Dword *)(this->block))[(sizeof(this->block) / sizeof(Dword)) - 1] );
//
for ( i = 0; i < (sizeof( heroTbl ) * 5); i++ )
{
// íå òðîãàåì ïîñëåäíèé Dword
j = rtlRand() % (sizeof(this->block) - 7);
k = ( rtlRand() % 31 ) + 1;
//
bPtr = this->block + j;
//
__asm{
mov edx, bPtr
mov ecx, k
mov eax, [edx]
bswap eax
ror eax, cl
mov [edx], eax
}
}
//
rtlSrand( kos_GetSystemClock() );
}
//
return result;
};
//
bool SaveToDisk()
{
int i;
Dword *rndList;
Byte *bPtr;
Dword k, keyLock;
 
//
rndList = new Dword[(sizeof( heroTbl ) * 5) * 2];
//
keyLock = rtlRand();
//
for ( i = 0; i < (sizeof( heroTbl ) * 5); i++ )
{
//
rndList[i * 2] = rtlRand() % (sizeof(this->block) - 7);
rndList[(i * 2) + 1] = ( rtlRand() % 31 ) + 1;
}
//
for ( i = (sizeof( heroTbl ) * 5) - 1; i >= 0; i-- )
{
//
bPtr = this->block + rndList[i * 2];
k = rndList[(i * 2) + 1];
//
__asm{
mov edx, bPtr
mov ecx, k
mov eax, [edx]
rol eax, cl
bswap eax
mov [edx], eax
}
}
//
delete rndList;
//
((Dword *)(this->block))[(sizeof(this->block) / sizeof(Dword)) - 1] = keyLock;
//
this->fi.rwMode = FO_WRITE;
this->fi.dataCount = 512;
return kos_FileSystemAccess( &( this->fi) ) == 0;
};
};
 
///
hiScoreFile *top10Heroes = NULL;
 
 
// çàãîëîâîê ãëàâíîãî îêíà
char MainWindowTitle[] = "XONIX (C) MMVI by Rabid Rabbit";
#if LANG == RUS
char goWndTitle[] = "“஢¥­ì %U, § ¢¥à襭® %U%%, ¦¨§­¥©: %U, áçñâ: %U";
char menuStr1[] = "1.  ç âì ¨£àã";
char menuStr2[] = "2. ‚ë室";
char menuStr3[] = "“¯à ¢«¥­¨¥: ‘’…‹Šˆ - ­ ¯à ¢«¥­¨¥ ¤¢¨¦¥­¨ï.";
char menuStr4[] = "SPACE - ¯ ã§ , ESC - ¢ë室 ¢ ¬¥­î.";
char thatsAllStr[] = "ˆ£à  ®ª®­ç¥­ .";
char worldSizeStr[] = " §¬¥à ¯®«ï %U x %U í«¥¬¥­â®¢.";
char mainLoopDelayStr[] = "‘ª®à®áâì %U";
char top10str1[] = "ENTER - ¨¬ï Ok.";
char top10str2[] = "ESC - ¢ë室 ¢ ¬¥­î";
#else
char goWndTitle[] = "Level %U, completed %U%%, lives: %U, scores: %U";
char menuStr1[] = "1. Start game";
char menuStr2[] = "2. Exit";
char menuStr3[] = "Control: ARROWS - direction of movement.";
char menuStr4[] = "SPACE - pause, ESC - leave to menu.";
char thatsAllStr[] = "Game finished.";
char worldSizeStr[] = "Field size %U x %U cells.";
char mainLoopDelayStr[] = "Speed %U";
char top10str1[] = "Enter - name Ok.";
char top10str2[] = "ESC - leave to menu";
#endif
//
Byte beep1[] = { 0x90, 0x33, 0 };
//
Byte *heroPtr = NULL;
int heroDX = 0, heroDY = 0, lastMoveDirection = 0;
//
Byte * worldMap = NULL;
//
int wndSizeX = ENTRY_WND_SIZE_X;
int wndSizeY = ENTRY_WND_SIZE_Y;
int mapSizeX = 64;
int mapSizeY = 32;
int loopDelay = DEFAULT_LOOP_DELAY;
int currentLevel = 1;
int appState = appStateEntry;
int levelFillEdge = 0;
int levelFillCount = 0;
int lifeCount = 0;
int flipMapCount = 0;
bool noBonus = false;
bool goToNextLevel = false;
bool bonus1Set = false;
bool bonus2Set = false;
int bonus1Count = 0;
int currentHero = gmHero;
int currentTrack = gmTrack;
Dword scoreCount = 0;
int enterName = -1;
int enterCharNdx = 0;
//
MCArray<Byte*> fillList;
 
//
struct flipMapEl
{
Word x, y;
};
 
//
flipMapEl *flipMapPtr = NULL;
 
 
//
RGB *mapColours[] = {
bmEmpty,
bmHero,
bmEnemy1,
bmEnemy2,
bmWall,
bmTrack,
bmFlip,
bmBonus1,
bmBonus2,
bmSuperHero,
bmSuperTrack,
NULL
};
 
 
//
struct sMapDiff
{
Byte *elPtr;
Byte mapEl;
//
sMapDiff() {};
//
sMapDiff( Byte *sElPtr, Byte sMapEl )
{
this->elPtr = sElPtr;
this->mapEl = sMapEl;
};
};
 
 
//
class CMapDiff : public MCArray<sMapDiff>
{
public:
virtual int Add( const sMapDiff &element )
{
element.elPtr[0] = element.mapEl;
return MCArray<sMapDiff>::Add( element );
}
};
 
 
//
CMapDiff mapDiffList;
MCArray<Byte*> sTrackList;
 
 
//
class CGenericEnemy
{
public:
//
Byte *ePtr;
int dx, dy;
//
virtual bool Move(void) = 0;
};
 
class CWallEnemy : public CGenericEnemy
{
public:
virtual bool Move(void);
};
 
class CSpaceEnemy : public CGenericEnemy
{
public:
virtual bool Move(void);
};
 
 
 
//
bool CWallEnemy::Move()
{
int ddx;
Byte *nextPtr;
Byte mapEl, dirMap;
bool result, border;
 
//
result = false;
border = false;
//
ddx = ( this->ePtr - worldMap ) % mapSizeX;
//
if ( ddx == 0 && this->dx < 0 )
{
border = true;
this->dx = 0 - this->dx;
}
//
if ( ddx == (mapSizeX - 1) && this->dx > 0 )
{
border = true;
this->dx = 0 - this->dx;
}
//
ddx = ( this->ePtr - worldMap ) / mapSizeX;
//
if ( ddx == 0 && this->dy < 0 )
{
border = true;
this->dy = 0 - this->dy;
}
//
if ( ddx == (mapSizeY - 1) && this->dy > 0 )
{
border = true;
this->dy = 0 - this->dy;
}
// ïîëó÷èì êîîðäèíàòû ìåñòà, â êîòîðîå ïîïàäàåò îáúåêò
nextPtr = this->ePtr + ( this->dx + this->dy );
// ïîëó÷èì ýëåìåíò ñ êàðòû
mapEl = nextPtr[0];
//
// â çàâèñèìîñòè îò ýëåìåíòà
switch ( mapEl )
{
// íàïîðîëèñü íà èãðîêà
case gmHero:
if ( sTrackList.GetCount() <= 0 )
{
result = true;
break;
}
 
// ïóñòîå ìåñòî, ñëåä èãðîêà èëè ãàäû íà ïîëå - íàäî îòñêàêèâàòü
case gmSuperHero:
case gmSuperTrack:
case gmTrack:
case gmEnemy2:
case gmEmpty:
//
dirMap = 0;
// -dx +dy
mapEl = this->ePtr[this->dy - this->dx];
if ( mapEl == gmEmpty
|| mapEl == gmTrack
|| mapEl == gmEnemy2
|| mapEl == gmSuperHero
|| mapEl == gmSuperTrack
) dirMap |= 1;
// +dy
mapEl = this->ePtr[this->dy];
if ( mapEl == gmEmpty
|| mapEl == gmTrack
|| mapEl == gmEnemy2
|| mapEl == gmSuperHero
|| mapEl == gmSuperTrack
) dirMap |= 2;
// +dx
mapEl = this->ePtr[this->dx];
if ( mapEl == gmEmpty
|| mapEl == gmTrack
|| mapEl == gmEnemy2
|| mapEl == gmSuperHero
|| mapEl == gmSuperTrack
) dirMap |= 4;
// +dx -dy
mapEl = this->ePtr[this->dx - this->dy];
if ( mapEl == gmEmpty
|| mapEl == gmTrack
|| mapEl == gmEnemy2
|| mapEl == gmSuperHero
|| mapEl == gmSuperTrack
) dirMap |= 8;
//
switch ( dirMap )
{
case 2:
case 3:
this->dy = 0 - this->dy;
break;
 
case 4:
case 12:
this->dx = 0 - this->dx;
break;
 
default:
this->dx = 0 - this->dx;
this->dy = 0 - this->dy;
break;
}
//
nextPtr = this->ePtr + ( this->dx + this->dy );
// ïîëó÷èì ýëåìåíò ñ êàðòû
mapEl = nextPtr[0];
//
switch ( mapEl )
{
//
case gmHero:
if ( sTrackList.GetCount() <= 0 )
{
result = true;
}
 
//
case gmSuperHero:
case gmSuperTrack:
case gmTrack:
case gmEmpty:
case gmEnemy2:
break;
 
//
default:
// ñòèðàåì îáúåêò
mapDiffList.Add( sMapDiff( this->ePtr, gmWall ) );
// ïåðåìåñòèì îáúåêò
this->ePtr = nextPtr;
// ðèñóåì îáúåêò ïî íîâûì êîîðäèíàòàì
mapDiffList.Add( sMapDiff( this->ePtr, gmEnemy1 ) );
break;
}
//
break;
 
// ëåòèì
default:
// ñòèðàåì îáúåêò
mapDiffList.Add( sMapDiff( this->ePtr, gmWall ) );
// ïåðåìåñòèì îáúåêò
this->ePtr = nextPtr;
// ðèñóåì îáúåêò ïî íîâûì êîîðäèíàòàì
mapDiffList.Add( sMapDiff( this->ePtr, gmEnemy1 ) );
//
break;
 
}
//
return result;
}
 
//
bool CSpaceEnemy::Move()
{
Byte *nextPtr;
Byte mapEl, dirMap;
bool result, heroTrack;
 
//
result = false;
//
heroTrack = ( sTrackList.GetCount() > 0 );
// ïîëó÷èì êîîðäèíàòû ìåñòà, â êîòîðîå ïîïàäàåò îáúåêò
nextPtr = this->ePtr + ( this->dx + this->dy );
// ïîëó÷èì ýëåìåíò ñ êàðòû
mapEl = nextPtr[0];
// â çàâèñèìîñòè îò ýëåìåíòà
switch ( mapEl )
{
// íàïîðîëèñü íà èãðîêà èëè åãî ñëåä
case gmTrack:
result = true;
break;
 
//
case gmHero:
if ( heroTrack )
{
result = true;
break;
}
 
// íàäî îòñêàêèâàòü
case gmSuperHero:
case gmSuperTrack:
case gmBonus1:
case gmBonus2:
case gmEnemy1:
case gmWall:
//
dirMap = 0;
// -dx +dy
mapEl = this->ePtr[this->dy - this->dx];
if ( mapEl == gmWall ||
mapEl == gmEnemy1 ||
mapEl == gmBonus1 ||
mapEl == gmBonus2 ||
mapEl == gmSuperHero ||
mapEl == gmSuperTrack ||
( mapEl == gmHero && !heroTrack )
) dirMap |= 1;
// +dy
mapEl = this->ePtr[this->dy];
if ( mapEl == gmWall ||
mapEl == gmEnemy1 ||
mapEl == gmBonus1 ||
mapEl == gmBonus2 ||
mapEl == gmSuperHero ||
mapEl == gmSuperTrack ||
( mapEl == gmHero && !heroTrack )
) dirMap |= 2;
// +dx
mapEl = this->ePtr[this->dx];
if ( mapEl == gmWall ||
mapEl == gmEnemy1 ||
mapEl == gmBonus1 ||
mapEl == gmBonus2 ||
mapEl == gmSuperHero ||
mapEl == gmSuperTrack ||
( mapEl == gmHero && !heroTrack )
) dirMap |= 4;
// +dx -dy
mapEl = this->ePtr[this->dx - this->dy];
if ( mapEl == gmWall ||
mapEl == gmEnemy1 ||
mapEl == gmBonus1 ||
mapEl == gmBonus2 ||
mapEl == gmSuperHero ||
mapEl == gmSuperTrack ||
( mapEl == gmHero && !heroTrack )
) dirMap |= 8;
//
switch ( dirMap )
{
case 2:
case 3:
this->dy = 0 - this->dy;
break;
 
case 4:
case 12:
this->dx = 0 - this->dx;
break;
 
default:
this->dx = 0 - this->dx;
this->dy = 0 - this->dy;
break;
}
//
nextPtr = this->ePtr + ( this->dx + this->dy );
// ïîëó÷èì ýëåìåíò ñ êàðòû
mapEl = nextPtr[0];
//
switch ( mapEl )
{
//
case gmTrack:
result = true;
break;
 
//
case gmHero:
if ( heroTrack )
{
result = true;
break;
}
 
//
case gmSuperHero:
case gmSuperTrack:
case gmBonus1:
case gmBonus2:
case gmWall:
case gmEnemy1:
break;
 
//
default:
// ñòèðàåì îáúåêò
mapDiffList.Add( sMapDiff( this->ePtr, gmEmpty ) );
// ïåðåìåñòèì îáúåêò
this->ePtr = nextPtr;
// ðèñóåì îáúåêò ïî íîâûì êîîðäèíàòàì
mapDiffList.Add( sMapDiff( this->ePtr, gmEnemy2 ) );
break;
}
//
break;
 
// ëåòèì
default:
// ñòèðàåì îáúåêò
mapDiffList.Add( sMapDiff( this->ePtr, gmEmpty ) );
// ïåðåìåñòèì îáúåêò
this->ePtr = nextPtr;
// ðèñóåì îáúåêò ïî íîâûì êîîðäèíàòàì
mapDiffList.Add( sMapDiff( this->ePtr, gmEnemy2 ) );
//
break;
 
}
//
 
//
return result;
}
 
 
//
MCArray<CGenericEnemy *> mapEnemies;
 
 
//
void xonixFree(void)
{
clearWorldMap();
if ( flipMapPtr != NULL )
{
delete flipMapPtr;
flipMapPtr = NULL;
}
}
 
 
//
void checkAndSetBonus2()
{
Dword i;
 
//
if ( (!bonus2Set)
&& rtlRand() < 0x40000000
&& lifeCount < 3
&& GetCompletePercents() > 50 )
{
//
bonus2Set = true;
//
for ( i = rtlRand() % (mapSizeX * mapSizeY); worldMap[i] != gmWall; i = rtlRand() % (mapSizeX * mapSizeY) );
//
mapDiffList.Add( sMapDiff( worldMap + i, gmBonus2 ) );
}
}
 
 
//
void ChangeHero()
{
if ( bonus1Count < 1 )
{
currentHero = gmHero;
currentTrack = gmTrack;
}
else
{
currentHero = gmSuperHero;
currentTrack = gmSuperTrack;
}
}
 
 
//
void checkAndSetBonus1()
{
Dword i;
 
//
if ( (!bonus1Set)
&& rtlRand() > 0x80000000
&& lifeCount < 2
&& GetCompletePercents() > 75 )
{
//
bonus1Set = true;
//
for ( i = rtlRand() % (mapSizeX * mapSizeY); worldMap[i] != gmWall; i = rtlRand() % (mapSizeX * mapSizeY) );
//
mapDiffList.Add( sMapDiff( worldMap + i, gmBonus1 ) );
}
}
 
 
//
void CreateFlipMap(void)
{
Word i, j;
int ndx, ndx2, k;
flipMapEl el;
static int lastMapSizeX = 0, lastMapSizeY = 0;
 
//
if ( lastMapSizeX != mapSizeX || lastMapSizeY != mapSizeY )
{
//
lastMapSizeX = mapSizeX;
lastMapSizeY = mapSizeY;
//
if ( flipMapPtr != NULL )
{
delete flipMapPtr;
flipMapPtr = NULL;
}
}
//
if ( flipMapPtr == NULL )
{
flipMapPtr = new flipMapEl[flipMapSize];
//
ndx = 0;
//
for ( i = 0; i < mapSizeY; i += 2 )
{
for ( j = 0; j < mapSizeX; j += 2 )
{
//
flipMapPtr[ndx].x = j;
flipMapPtr[ndx].y = i;
//
ndx++;
}
}
}
//
for ( k = 0; k < flipMapSize; k++ )
{
//
ndx = rtlRand() % flipMapSize;
ndx2 = rtlRand() % flipMapSize;
//
el = flipMapPtr[ndx];
flipMapPtr[ndx] = flipMapPtr[ndx2];
flipMapPtr[ndx2] = el;
}
}
 
 
//
bool ProcessEndTrack()
{
int i, j, k, m;
bool noFill;
Byte *mPtr, *findPtr;
 
//
j = sTrackList.GetCount();
//
scoreCount += j;
//
for ( i = 0; i < j; i++ )
{
//
mapDiffList.Add( sMapDiff( sTrackList[i], gmWall ) );
}
//
levelFillCount -= j;
//
sTrackList.Clear();
//
heroPtr += heroDX + heroDY;
mapDiffList.Add( sMapDiff( heroPtr, currentHero ) );
//
heroDX = 0;
heroDY = 0;
lastMoveDirection = 0;
// çàëèâêà
mPtr = worldMap;
//
for ( i = 0; i < mapSizeY; i++ )
{
for ( j = 0; j < mapSizeX; j++ )
{
//
if ( mPtr[0] == gmEmpty )
{
//
fillList.Clear();
//
noFill = false;
//
fillList.Add( mPtr );
//
mPtr[0] = gmProbe;
//
for ( k = 0; k < fillList.GetCount(); k++ )
{
// ñïðàâà
findPtr = fillList[k] + 1;
//
switch ( findPtr[0] )
{
case gmEmpty:
fillList.Add( findPtr );
findPtr[0] = gmProbe;
break;
case gmEnemy2:
noFill = true;
break;
default:
break;
}
// ñëåâà
findPtr = fillList[k] - 1;
//
switch ( findPtr[0] )
{
case gmEmpty:
fillList.Add( findPtr );
findPtr[0] = gmProbe;
break;
case gmEnemy2:
noFill = true;
break;
default:
break;
}
// ñâåðõó
findPtr = fillList[k] - mapSizeX;
//
switch ( findPtr[0] )
{
case gmEmpty:
fillList.Add( findPtr );
findPtr[0] = gmProbe;
break;
case gmEnemy2:
noFill = true;
break;
default:
break;
}
// ñíèçó
findPtr = fillList[k] + mapSizeX;
//
switch ( findPtr[0] )
{
case gmEmpty:
fillList.Add( findPtr );
findPtr[0] = gmProbe;
break;
case gmEnemy2:
noFill = true;
break;
default:
break;
}
}
//
if ( noFill )
{
//
fillList.Clear();
}
else
{
//
m = fillList.GetCount();
//
scoreCount += m;
//
for ( k = 0; k < m; k++ )
{
//
mapDiffList.Add( sMapDiff( fillList[k], gmWall ) );
}
//
levelFillCount -= m;
}
}
else
{
mPtr++;
}
}
}
//
mPtr = worldMap;
//
for ( i = 0; i < mapSizeY; i++ )
{
for ( j = 0; j < mapSizeX; j++ )
{
//
if ( mPtr[0] == gmProbe ) mPtr[0] = gmEmpty;
//
mPtr++;
}
}
//
checkAndSetBonus1();
checkAndSetBonus2();
//
ApplyMapDiffs();
//
return levelFillCount <= levelFillEdge;
}
 
 
//
void EatEnemy( Byte *enemyPos )
{
bool Eat = true;
int i, j;
 
//
while ( Eat )
{
//
Eat = false;
//
j = mapEnemies.GetCount();
//
for ( i = 0; i < j; i++ )
{
//
if ( mapEnemies[i]->ePtr == enemyPos )
{
//
delete mapEnemies[i];
//
mapEnemies.RemoveAt( i );
//
Eat = true;
//
scoreCount += EAT_ENEMY_BONUS;
//
break;
}
}
}
}
 
 
//
bool MoveHero()
{
int ddx;
Byte *nextPtr;
Byte mapEl;
bool result;
 
//
if ( heroDX == 0 && heroDY == 0 ) return false;
//
result = false;
//
nextPtr = heroPtr + ( heroDX + heroDY );
//
ddx = ( ( heroPtr - worldMap ) % mapSizeX ) - ( ( nextPtr - worldMap ) % mapSizeX );
//
if ( ddx < -1 || ddx > 1 || nextPtr < worldMap || nextPtr >= ( worldMap + ( mapSizeX * mapSizeY ) ) )
{
heroDX = 0;
heroDY = 0;
return false;
}
 
 
//
mapEl = nextPtr[0];
//
if ( sTrackList.GetCount() > 0 )
{
//
switch ( mapEl )
{
//
case gmEmpty:
sTrackList.Add( nextPtr );
break;
//
case gmBonus1:
bonus1Count = BONUS1_LIFETIME;
ChangeHero();
goToNextLevel = ProcessEndTrack();
return false;
break;
//
case gmBonus2:
lifeCount++;
goToNextLevel = ProcessEndTrack();
return false;
break;
//
case gmWall:
goToNextLevel = ProcessEndTrack();
return false;
break;
//
case gmEnemy1:
if ( bonus1Count > 0 )
{
//
EatEnemy( nextPtr );
//
goToNextLevel = ProcessEndTrack();
//
return false;
break;
}
else
{
//
return true;
}
break;
//
case gmEnemy2:
if ( bonus1Count > 0 )
{
//
EatEnemy( nextPtr );
sTrackList.Add( nextPtr );
break;
}
else
{
//
return true;
}
break;
//
default:
return true;
break;
}
}
else
{
//
switch ( mapEl )
{
//
case gmEmpty:
sTrackList.Add( nextPtr );
break;
//
case gmBonus1:
bonus1Count = BONUS1_LIFETIME;
break;
//
case gmBonus2:
lifeCount++;
break;
//
case gmWall:
break;
//
case gmEnemy1:
if ( bonus1Count > 0 )
{
EatEnemy( nextPtr );
}
else
{
result = true;
}
break;
//
case gmEnemy2:
if ( bonus1Count > 0 )
{
EatEnemy( nextPtr );
sTrackList.Add( nextPtr );
}
else
{
result = true;
}
break;
//
default:
result = true;
break;
}
}
 
//
mapDiffList.Add( sMapDiff( heroPtr, sTrackList.GetCount() <= 1 ? gmWall : currentTrack ) );
heroPtr = nextPtr;
mapDiffList.Add( sMapDiff( heroPtr, currentHero ) );
 
return result;
}
 
 
//
bool MoveEnemies()
{
bool result;
int i, j, ir;
 
//
result = false;
ir = 0;
//
j = mapEnemies.GetCount();
//
for ( i = 0; i < j; i++ )
{
ir += ( mapEnemies[i]->Move() ? 1 : 0 );
}
//
result = ( ir != 0 );
//
return result;
}
 
 
//
void ApplyMapDiffs( bool drawTitle )
{
int i, j;
 
//
kos_WindowRedrawStatus( 1 );
//
if ( drawTitle ) drawWndTitleGo();
//
j = mapDiffList.GetCount();
//
for ( i = 0; i < j; i++ )
{
////
//kos_DrawBar(
// wndXOffet + ( ( ( mapDiffList[i].elPtr - worldMap ) % mapSizeX ) * blockSize ),
// wndYOffset + ( ( ( mapDiffList[i].elPtr - worldMap ) / mapSizeX ) * blockSize ),
// blockSize, blockSize,
// mapColours[mapDiffList[i].mapEl]
//);
//
kos_PutImage(
mapColours[mapDiffList[i].mapEl],
blockSize,
blockSize,
wndXOffet + ( ( ( mapDiffList[i].elPtr - worldMap ) % mapSizeX ) * blockSize ),
wndYOffset + ( ( ( mapDiffList[i].elPtr - worldMap ) / mapSizeX ) * blockSize )
);
}
//
kos_WindowRedrawStatus( 2 );
//
mapDiffList.Clear();
}
 
 
//
void DeadHeroProcess()
{
int i, j;
Byte *mPtr = beep1;
 
// beep
__asm{
mov eax, 55
mov ebx, eax
mov esi, mPtr
push eax
int 0x40
pop eax
}
//
j = sTrackList.GetCount();
//
for ( i = 0; i < j; i++ )
{
//
mapDiffList.Add( sMapDiff( sTrackList[i], gmEmpty ) );
}
//
mapDiffList.Add( sMapDiff( heroPtr, sTrackList.GetCount() > 0 ? gmEmpty : gmWall ) );
//
sTrackList.Clear();
//
heroPtr = worldMap;
//
while ( heroPtr[0] != gmWall ) heroPtr++;
//
mapDiffList.Add( sMapDiff( heroPtr, gmHero ) );
//
noBonus = true;
//
lifeCount--;
//
heroDX = 0;
heroDY = 0;
lastMoveDirection = 0;
}
 
 
//
bool CheckForNextLevel()
{
//
if ( goToNextLevel )
{
//
CreateFlipMap();
goToNextLevel = false;
currentLevel++;
appState = appStateHideMap;
flipMapCount = 0;
return true;
}
 
//
return false;
}
 
 
//
void SetGameVars()
{
//
currentLevel = 1;
lifeCount = 3;
noBonus = true;
bonus1Set = false;
bonus2Set = false;
bonus1Count = 0;
goToNextLevel = false;
currentHero = gmHero;
currentTrack = gmTrack;
scoreCount = 0;
enterName = -1;
//
wndSizeX = ((mapSizeX*blockSize)+2);
wndSizeY = ((mapSizeY*blockSize)+23);
//
kos_ChangeWindow( -1, -1, wndSizeX, wndSizeY );
}
 
//
void SetEntryVars()
{
//
wndSizeX = ENTRY_WND_SIZE_X;
wndSizeY = ENTRY_WND_SIZE_Y;
//
kos_ChangeWindow( -1, -1, wndSizeX, wndSizeY );
kos_SetKeyboardDataMode( KM_SCANS );
}
 
 
//
void ReleaseTop10()
{
//
if ( top10Heroes != NULL )
{
//
memcpy( top10Heroes->block, heroTbl, sizeof(heroTbl) );
//
top10Heroes->SaveToDisk();
//
delete top10Heroes;
}
}
 
 
//
void PrepareTop10()
{
//
top10Heroes = new hiScoreFile;
//
atexit( ReleaseTop10 );
//
if ( top10Heroes->LoadFromDisk() )
{
//
memcpy( heroTbl, top10Heroes->block, sizeof(heroTbl) );
}
}
 
 
//
void SetUpTop10()
{
int i, j;
Byte keyCode;
 
//
while ( kos_CheckForEvent() == 2 ) kos_GetKey( keyCode );
//
kos_SetKeyboardDataMode( KM_CHARS );
//
kos_ChangeWindow( -1, -1, TOP10_WND_SIZE_X, TOP10_WND_SIZE_Y );
//
for ( i = 0; i < TOP_TBL_SIZE; i++ )
{
//
if ( heroTbl[i].score < scoreCount )
{
//
for ( j = TOP_TBL_SIZE - 1; j > i; j-- )
{
//
heroTbl[j] = heroTbl[j-1];
}
//
heroTbl[i].ClearName();
heroTbl[i].score = scoreCount;
//
enterName = i;
enterCharNdx = 0;
//
break;
}
}
}
 
 
//
// òî÷êà âõîäà è ôóíêöèÿ îáðàáîòêè ñîîáùåíèé
//
void kos_Main()
{
Dword buttonID;
Byte keyCode;
Byte *bPtr;
bool workOn = true;
char *cPtr;
 
// îòäåëÿåì èìÿ ìîäóëÿ îò ïóòè
cPtr = strrchr( kosExePath, '/' );
// ïðîâåðêà ;)
if ( cPtr == NULL )
{
//
rtlDebugOutString( "Invalid path to executable." );
//
return;
}
//
cPtr[1] = 0;
//
strcpy( top10FilePath, kosExePath );
//
strcpy( top10FilePath + ((cPtr - kosExePath) + 1), "xonix.t10" );
 
// âûïîëíåíèå ôóíêöèé èíèöèàëèçàöèè
kos_SetKeyboardDataMode( KM_SCANS );
//
PrepareTop10();
 
//
while( workOn )
{
switch ( appState )
{
//
case appStateEntry:
switch ( kos_WaitForEvent() )
{
// ïåðåðèñîâêà îêíà
case 1:
DrawAppWindow();
break;
 
//
case 2:
kos_GetKey( keyCode );
switch ( keyCode )
{
//
case 2:
//
appState = appStateGo;
SetGameVars();
initWorldMap();
DrawAppWindow();
break;
 
//
case 3:
xonixFree();
workOn = false;
break;
}
break;
//
case 3:
//
if ( ! kos_GetButtonID( buttonID ) ) break;
//
switch ( buttonID )
{
//
case BT_SIZE_X_PLUS:
mapSizeX += 2;
if ( mapSizeX > MAX_X_SIZE ) mapSizeX = MAX_X_SIZE;
break;
//
case BT_SIZE_X_MINUS:
mapSizeX -= 2;
if ( mapSizeX < MIN_X_SIZE ) mapSizeX = MIN_X_SIZE;
break;
//
case BT_SIZE_Y_PLUS:
mapSizeY += 2;
if ( mapSizeY > MAX_Y_SIZE ) mapSizeY = MAX_Y_SIZE;
break;
//
case BT_SIZE_Y_MINUS:
mapSizeY -= 2;
if ( mapSizeY < MIN_Y_SIZE ) mapSizeY = MIN_Y_SIZE;
break;
//
case BT_LOOP_MINUS:
loopDelay++;;
if ( loopDelay > MAX_LOOP_DELAY ) loopDelay = MAX_LOOP_DELAY;
break;
//
case BT_LOOP_PLUS:
loopDelay--;;
if ( loopDelay < MIN_LOOP_DELAY ) loopDelay = MIN_LOOP_DELAY;
break;
//
default:
break;
}
DrawAppWindow();
break;
//
default:
break;
}
break;
//
case appStateGo:
//
kos_Pause( loopDelay );
//
if ( bonus1Count > 0 ) bonus1Count--;
//
ChangeHero();
//
switch( kos_WaitForEvent( 1 ) )
{
//
case 0:
if ( MoveHero() )
{
//
DeadHeroProcess();
}
else
{
//
if ( CheckForNextLevel() )
{
break;
}
}
if ( MoveEnemies() )
{
// ñîæðàëè èãðîêà
DeadHeroProcess();
}
ApplyMapDiffs();
break;
//
case 1:
DrawAppWindow();
break;
 
//
case 2:
do kos_GetKey( keyCode ); while ( keyCode & 0x80 );
switch ( keyCode )
{
//
case 0x1:
SetEntryVars();
appState = appStateEntry;
clearWorldMap();
DrawAppWindow();
continue;
 
//
case 0x39:
appState = appStatePause;
break;
 
//
case 0x48:
heroDX = 0;
if ( lastMoveDirection == 0x50 )
{
heroDY = 0;
lastMoveDirection = 0;
}
else
{
heroDY = -mapSizeX;
lastMoveDirection = 0x48;
}
break;
 
//
case 0x50:
heroDX = 0;
if ( lastMoveDirection == 0x48 )
{
heroDY = 0;
lastMoveDirection = 0;
}
else
{
heroDY = mapSizeX;
lastMoveDirection = 0x50;
}
break;
 
//
case 0x4B:
heroDY = 0;
if ( lastMoveDirection == 0x4D )
{
heroDX = 0;
lastMoveDirection = 0;
}
else
{
heroDX = -1;
lastMoveDirection = 0x4B;
}
break;
 
//
case 0x4D:
heroDY = 0;
if ( lastMoveDirection == 0x4B )
{
heroDX = 0;
lastMoveDirection = 0;
}
else
{
heroDX = 1;
lastMoveDirection = 0x4D;
}
break;
}
//
if ( MoveHero() )
{
//
DeadHeroProcess();
}
else
{
//
if ( CheckForNextLevel() )
{
break;
}
}
if ( MoveEnemies() )
{
// ñîæðàëè èãðîêà
DeadHeroProcess();
}
ApplyMapDiffs();
break;
 
//
default:
//
if ( MoveHero() )
{
//
DeadHeroProcess();
}
if ( MoveEnemies() )
{
// ñîæðàëè èãðîêà
DeadHeroProcess();
}
ApplyMapDiffs();
break;
}
//
if ( lifeCount <= 0 )
{
appState = appStateAfterDeath;
DrawAppWindow();
}
//
break;
 
//
case appStateAfterDeath:
switch ( kos_WaitForEvent() )
{
//
case 1:
DrawAppWindow();
break;
//
case 2:
do kos_GetKey( keyCode ); while ( keyCode & 0x80 );
if ( keyCode != 0 )
{
//
appState = appStateTop10;
SetUpTop10();
DrawAppWindow();
}
break;
//
case 3:
if ( kos_GetButtonID( buttonID ) )
{
//
if ( buttonID == 1 )
{
//
appState = appStateTop10;
SetUpTop10();
DrawAppWindow();
}
}
//
default:
break;
}
break;
 
//
case appStateTop10:
switch ( kos_WaitForEvent() )
{
//
case 1:
DrawAppWindow();
break;
//
case 2:
//
kos_GetKey( keyCode );
//
if ( enterName < 0 )
{
//
if ( keyCode == 0x1b )
{
//
SetEntryVars();
clearWorldMap();
appState = appStateEntry;
DrawAppWindow();
}
}
else
{
//
switch ( keyCode )
{
//
case 13:
//
enterName = -1;
break;
//
case 8:
//
if ( enterCharNdx > 0 )
{
//
heroTbl[enterName].name[--enterCharNdx] = '.';
}
break;
//
default:
if ( keyCode >= 0x20 )
{
//
heroTbl[enterName].name[enterCharNdx++] = keyCode;
//
if ( enterCharNdx >= sizeof(heroTbl[0].name) )
{
//
enterName = -1;
}
}
break;
}
//
DrawAppWindow();
}
//
break;
//
default:
break;
}
break;
 
//
case appStatePause:
switch ( kos_WaitForEvent() )
{
case 1:
DrawAppWindow();
break;
 
case 2:
do kos_GetKey( keyCode ); while ( keyCode & 0x80 );
if ( keyCode != 0 )
{
//
appState = appStateGo;
}
break;
 
default:
break;
}
break;
 
//
case appStateHideMap:
//
switch ( kos_WaitForEvent( 1 ) )
{
case 1:
DrawAppWindow();
break;
case 2:
while ( kos_GetKey( keyCode ) );
break;
default:
bPtr = worldMap + (flipMapPtr[flipMapCount].x + (flipMapPtr[flipMapCount].y * mapSizeX));
mapDiffList.Add( sMapDiff( bPtr, gmFlip ) );
mapDiffList.Add( sMapDiff( bPtr + 1, gmFlip ) );
mapDiffList.Add( sMapDiff( bPtr + mapSizeX, gmFlip ) );
mapDiffList.Add( sMapDiff( bPtr + (mapSizeX + 1), gmFlip ) );
ApplyMapDiffs( false );
break;
}
//
flipMapCount++;
//
if ( flipMapCount >= flipMapSize )
{
flipMapCount = 0;
appState = appStateShowMap;
DrawAppWindow();
}
break;
//
case appStateShowMap:
//
switch ( kos_WaitForEvent( 1 ) )
{
case 1:
DrawAppWindow();
break;
default:
break;
}
//
flipMapCount++;
//
if ( flipMapCount >= BEFORE_START_LEVEL )
{
clearWorldMap();
flipMapCount = 0;
initWorldMap();
appState = appStateGo;
DrawAppWindow();
}
//
break;
}
}
}
 
 
//
void DrawEntryScreen()
{
PRINTK pr;
char line[64];
 
//
kos_DefineAndDrawWindow(
100, 100,
wndSizeX, wndSizeY,
0, 0,
0, 0x2040A0,
0x2040A0
);
//
kos_WriteTextToWindow(
4, 4,
0x10, 0x42D2E2,
MainWindowTitle,
sizeof( MainWindowTitle ) - 1
);
//
kos_WriteTextToWindow(
8, 32,
0x10, 0x12FF12,
menuStr1,
sizeof( menuStr1 ) - 1
);
//
kos_WriteTextToWindow(
8, 48,
0x10, 0x12FF12,
menuStr2,
sizeof( menuStr2 ) - 1
);
//
kos_WriteTextToWindow(
8, 80,
0x10, 0xD0FF12,
menuStr3,
sizeof( menuStr3 ) - 1
);
//
kos_WriteTextToWindow(
8, 96,
0x10, 0xD0FF12,
menuStr4,
sizeof( menuStr4 ) - 1
);
// ðàçìåð ïîëÿ
pr.fmtline = worldSizeStr;
pr.args[0] = mapSizeX;
pr.args[1] = mapSizeY;
sprintk( line, &pr );
//
kos_WriteTextToWindow(
8, 112,
0x10, 0x12C0D0,
line,
strlen( line )
);
// êíîïêè X
kos_DefineButton(
ENTRY_WND_SIZE_X - 58, 112,
12, 12,
BT_SIZE_X_MINUS,
0xCCCCCC
);
//
kos_PutImage( bmPMButton + 12, 6, 2, ENTRY_WND_SIZE_X - 58 + 3, 117 );
//
kos_DefineButton(
ENTRY_WND_SIZE_X - 45, 112,
12, 12,
BT_SIZE_X_PLUS,
0xCCCCCC
);
//
kos_PutImage( bmPMButton, 6, 6, ENTRY_WND_SIZE_X - 45 + 3, 115 );
// êíîïêè Y
kos_DefineButton(
ENTRY_WND_SIZE_X - 29, 112,
12, 12,
BT_SIZE_Y_MINUS,
0xCCCCCC
);
//
kos_PutImage( bmPMButton + 12, 6, 2, ENTRY_WND_SIZE_X - 29 + 3, 117 );
//
kos_DefineButton(
ENTRY_WND_SIZE_X - 16, 112,
12, 12,
BT_SIZE_Y_PLUS,
0xCCCCCC
);
//
kos_PutImage( bmPMButton, 6, 6, ENTRY_WND_SIZE_X - 16 + 3, 115 );
//
//çàäåðæêà â öèêëå âûáîðêè ñîîáùåíèé
pr.fmtline = mainLoopDelayStr;
pr.args[0] = MAX_LOOP_DELAY + MIN_LOOP_DELAY - loopDelay;
sprintk( line, &pr );
//
kos_WriteTextToWindow(
8, 128,
0x10, 0x12C0D0,
line,
strlen( line )
);
//
kos_DefineButton(
ENTRY_WND_SIZE_X - 29, 128,
12, 12,
BT_LOOP_MINUS,
0xCCCCCC
);
//
kos_PutImage( bmPMButton + 12, 6, 2, ENTRY_WND_SIZE_X - 29 + 3, 133 );
//
kos_DefineButton(
ENTRY_WND_SIZE_X - 16, 128,
12, 12,
BT_LOOP_PLUS,
0xCCCCCC
);
//
kos_PutImage( bmPMButton, 6, 6, ENTRY_WND_SIZE_X - 16 + 3, 131 );
}
 
 
//
void DrawAppWindow()
{
//
kos_WindowRedrawStatus( 1 );
 
switch ( appState )
{
//
case appStateTop10:
DrawTop10Window();
break;
//
case appStateEntry:
//
DrawEntryScreen();
break;
//
case appStateGo:
case appStateShowMap:
case appStatePause:
drawWorldMap();
break;
//
case appStateAfterDeath:
//
drawWorldMap();
//
kos_DefineButton(
( wndSizeX / 2 ) - 64,
( wndSizeY / 2 ) - 16,
128, 32,
1,
0x136793
);
//
kos_WriteTextToWindow(
( wndSizeX / 2 ) - ( sizeof( thatsAllStr ) * 4 ),
( wndSizeY / 2 ) - 4,
0x10, 0xFFFFFF,
thatsAllStr,
sizeof ( thatsAllStr ) - 1
);
 
//
break;
//
case appStateHideMap:
drawWorldMapForFlip();
break;
}
//
kos_WindowRedrawStatus( 2 );
}
 
 
//
void initWorldMap()
{
int i, j, m, allocSize;
CWallEnemy *we;
CSpaceEnemy *se;
 
//
allocSize = mapSizeX * mapSizeY;
worldMap = new Byte[allocSize];
//
__asm{
mov edi, worldMap
mov ecx, allocSize
mov al, gmEmpty
rep stosb
}
 
 
//
levelFillEdge = ( ( currentLevel + 1 ) * spacePerEnemy ) + currentLevel;
levelFillCount = freeSpaceCount;
//
if ( ! noBonus )
{
lifeCount++;
}
//
noBonus = false;
bonus1Set = false;
bonus2Set = false;
bonus1Count = 0;
goToNextLevel = false;
currentHero = gmHero;
currentTrack = gmTrack;
 
//
for ( i = 0; i < mapSizeX; i++ )
{
//
worldMap[i] = gmWall;
worldMap[mapSizeX + i] = gmWall;
//
worldMap[((mapSizeY-2)*mapSizeX) + i] = gmWall;
worldMap[((mapSizeY-1)*mapSizeX) + i] = gmWall;
}
//
for ( i = 2; i < (mapSizeY-2); i++ )
{
//
worldMap[(i*mapSizeX)] = gmWall;
worldMap[(i*mapSizeX) + 1] = gmWall;
worldMap[(i*mapSizeX) + mapSizeX - 2] = gmWall;
worldMap[(i*mapSizeX) + mapSizeX - 1] = gmWall;
}
//
heroPtr = worldMap + ( mapSizeX / 2 );
heroPtr[0] = gmHero;
heroDX = 0;
heroDY = 0;
//
for ( i = 0; i < currentLevel; i++ )
{
//
for (
j = ( rtlRand() % (mapSizeX * (mapSizeY - 2)) ) + (mapSizeX * 2);
worldMap[j] != gmWall;
j = rtlRand() % (mapSizeX * mapSizeY)
);
//
we = new CWallEnemy();
//
we->ePtr = worldMap + j;
we->dx = rtlRand() & 1 ? 1 : -1;
we->dy = rtlRand() & 1 ? mapSizeX : -mapSizeX;
//
mapEnemies.Add( we );
//
worldMap[j] = gmEnemy1;
}
//
m = currentLevel + 1;
//
for ( i = 0; i < m; i++ )
{
//
for (
j = rtlRand() % (mapSizeX * mapSizeY);
worldMap[j] != gmEmpty;
j = rtlRand() % (mapSizeX * mapSizeY)
);
//
se = new CSpaceEnemy();
//
se->ePtr = worldMap + j;
se->dx = rtlRand() & 1 ? 1 : -1;
se->dy = rtlRand() & 1 ? mapSizeX : -mapSizeX;
//
mapEnemies.Add( se );
//
worldMap[j] = gmEnemy2;
}
}
 
 
//
void drawWorldMap()
{
//
kos_DefineAndDrawWindow(
100, 100,
wndSizeX, wndSizeY,
0, 0,
0, 0x2040A0,
0x2040A0
);
//
drawWndTitleGo();
//
drawWorldMapForFlip();
}
 
 
//
int GetCompletePercents()
{
int n1, n2;
 
//
n1 = freeSpaceCount - levelFillCount;
n2 = freeSpaceCount - levelFillEdge;
//
return ( n1 >= n2 ) ? 100 : ( n1 * 100 ) / n2;
}
 
 
//
void drawWndTitleGo()
{
PRINTK pr;
char line[64];
 
//
kos_DrawBar(
1, 1,
wndSizeX - 2, 18,
0x2040A0
);
 
//
pr.fmtline = goWndTitle;
pr.args[0] = currentLevel;
pr.args[1] = GetCompletePercents();
pr.args[2] = lifeCount;
pr.args[3] = scoreCount;
sprintk( line, &pr );
//
kos_WriteTextToWindow(
4, 4,
0x10, 0x42D2E2,
line,
strlen( line )
);
//
if ( bonus1Count > 0 )
{
//
kos_DrawBar(
2, 22 - BONUS1_IND_HSIZE - 1,
wndSizeX - 4, BONUS1_IND_HSIZE,
0x2040A0
);
//
kos_DrawBar(
2, 22 - BONUS1_IND_HSIZE - 1,
( bonus1Count * ( wndSizeX - 4 ) ) / BONUS1_LIFETIME, BONUS1_IND_HSIZE,
0x5720B0
);
}
}
 
//
void drawWorldMapForFlip()
{
int i, j;
Byte *mPtr = worldMap;
 
//
for ( i = 0; i < mapSizeY; i++ )
{
//
for ( j = 0; j < mapSizeX; j++ )
{
////
//kos_DrawBar(
// wndXOffet + ( j * blockSize ),
// wndYOffset + ( i * blockSize ),
// blockSize, blockSize,
// mapColours[*mPtr]
//);
//
kos_PutImage(
mapColours[*mPtr],
blockSize,
blockSize,
wndXOffet + ( j * blockSize ),
wndYOffset + ( i * blockSize )
);
//
mPtr++;
}
}
}
 
 
//
void clearWorldMap()
{
int i, j;
 
//
sTrackList.Clear();
fillList.Clear();
mapDiffList.Clear();
//
j = mapEnemies.GetCount();
//
for ( i = 0; i < j; i++ )
{
//
delete mapEnemies[i];
}
//
mapEnemies.Clear();
//
if ( worldMap != NULL )
{
delete worldMap;
worldMap = NULL;
}
}
 
 
//
char Top10WndTitle[] = "Top 10";
 
//
void DrawTop10Window()
{
int i;
 
//
kos_DefineAndDrawWindow(
100, 100,
TOP10_WND_SIZE_X, TOP10_WND_SIZE_Y,
0, 0,
0, 0x2040A0,
0x2040A0
);
//
kos_WriteTextToWindow(
4, 4,
0x0, 0x42D2E2,
Top10WndTitle,
sizeof( Top10WndTitle ) - 1
);
//
for ( i = 0; i < TOP_TBL_SIZE; i++ )
{
//
kos_WriteTextToWindow(
6, wndYOffset + 2 + (i * 10),
0x0, enterName != i ? 0xFFFFFF : 0x00FF00,
heroTbl[i].name,
sizeof( heroTbl[0].name )
);
//
kos_DisplayNumberToWindow(
heroTbl[i].score,
8,
112, wndYOffset + 2 + (i * 10),
0xFFFF55,
nbDecimal,
false
);
}
//
kos_WriteTextToWindow(
6, wndYOffset + 6 + (i * 10),
0x10, 0x1060D0,
enterName >= 0 ? top10str1 : top10str2,
enterName >= 0 ? sizeof(top10str1) - 1 : sizeof(top10str2) - 1
);
}
 
 
/programs/games/xonix/trunk/mcarray.h
0,0 → 1,167
#define AR_CHUNK_SIZE 64
 
//
template<class TYPE>
class MCArray
{
protected:
TYPE * _dataPtr;
int _elementsCount;
int _capacity;
 
public:
MCArray();
~MCArray();
virtual int Add( const TYPE &element );
TYPE & GetAt( int Ndx );
TYPE & operator [] ( int Ndx );
int Find( int startNdx, TYPE & element );
int RemoveAt( int Ndx );
void Clear(void);
int GetCount(void);
};
 
//
 
 
//
template<class TYPE>
MCArray<TYPE>::MCArray()
{
// óñòàíàâëèâàåì ïåðåìåííûå
this->_dataPtr = NULL;
this->_capacity = 0;
this->_elementsCount = 0;
}
 
 
//
template<class TYPE>
MCArray<TYPE>::~MCArray()
{
//
this->_capacity = 0;
this->_elementsCount = 0;
//
if ( this->_dataPtr != NULL )
{
delete this->_dataPtr;
}
}
 
 
//
template<class TYPE>
int MCArray<TYPE>::Add( const TYPE &element )
{
TYPE * dPtr;
 
// åñòü ëè ìåñòî?
if ( this->_elementsCount >= this->_capacity )
{
// çàíèìàåì åù¸ ïàìÿòè
dPtr = new TYPE [this->_capacity + AR_CHUNK_SIZE];
// ïðîâåðêà
if ( dPtr == NULL )
{
//
return -1;
}
 
if ( this->_capacity > 0 )
{
// ñêîïèðóåì ñóùåñòâóþùèå äàííûå íà íîâîå ìåñòî
memcpy( dPtr, this->_dataPtr, sizeof(TYPE) * this->_capacity );
// óäàëèì ñòàðóþ êîïèþ äàííûõ
delete this->_dataPtr;
}
// ñêîððåêòèðóåì ðàçìåð
this->_capacity += AR_CHUNK_SIZE;
// ñêîððåêòèðóåì óêàçàòåëü íà äàííûå
this->_dataPtr = dPtr;
}
 
// êîïèðóåì ýëåìåíò â ìàññèâ
memcpy( this->_dataPtr + this->_elementsCount, &element, sizeof(TYPE) );
 
// óâåëè÷èâàåì ñ÷¸ò÷èê ýëåìåíòîâ
return ++this->_elementsCount;
}
 
 
//
template<class TYPE>
TYPE & MCArray<TYPE>::GetAt( int Ndx )
{
//assert( Ndx >= 0 && Ndx < this->_elementsCount );
return this->_dataPtr[Ndx];
}
 
 
//
template<class TYPE>
TYPE & MCArray<TYPE>::operator [] ( int Ndx )
{
return this->GetAt( Ndx );
}
 
 
//
template<class TYPE>
int MCArray<TYPE>::Find( int startNdx, TYPE & element )
{
int i;
 
if ( startNdx < 0 || startNdx >= this->_elementsCount )
{
return -1;
}
 
for ( i = startNdx; i < this->_elementsCount; i++ )
{
if ( element == this->_dataPtr[i] )
{
return i;
}
}
 
return -1;
}
 
 
//
template<class TYPE>
int MCArray<TYPE>::RemoveAt( int Ndx )
{
int mn;
 
if ( Ndx < 0 || Ndx >= this->_elementsCount )
{
return 0;
}
 
mn = this->_elementsCount - Ndx;
 
if ( mn != 1 )
{
memcpy( this->_dataPtr + Ndx, this->_dataPtr + Ndx + 1, sizeof(TYPE) * ( mn - 1 ) );
}
 
this->_elementsCount--;
return 1;
}
 
 
//
template<class TYPE>
void MCArray<TYPE>::Clear()
{
this->_elementsCount = 0;
}
 
//
template<class TYPE>
int MCArray<TYPE>::GetCount()
{
return this->_elementsCount;
}
/programs/games/xonix/trunk/mcsmemm.cpp
0,0 → 1,329
// 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;
}
 
/programs/games/xonix/trunk/resource.h
0,0 → 1,15
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by fatest.rc
//
 
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
/programs/games/xonix/trunk
Property changes:
Added: tsvn:logminsize
+5
\ No newline at end of property
/programs/games/xonix/.
Property changes:
Added: tsvn:logminsize
+5
\ No newline at end of property