/programs/games/rforces/trunk/KosFile.h |
---|
0,0 → 1,26 |
#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); |
}; |
/programs/games/rforces/trunk/cmp.bat |
---|
0,0 → 1,4 |
"C:\Program Files\Microsoft Visual Studio 8\VC\bin\cl" /c /O2 /nologo /GS- /GR- /fp:fast rforces.cpp kosFile.cpp kosSyst.cpp mcsmemm.cpp |
"C:\Program Files\Microsoft Visual Studio 8\VC\bin\link" /nologo /manifest:no /entry:crtStartUp /subsystem:native /base:0 /fixed /align:16 /nodefaultlib rforces.obj kosFile.obj kosSyst.obj mcsmemm.obj |
pe2kos rforces.exe rforces |
pause |
/programs/games/rforces/trunk/forces_1.1.cpp |
---|
0,0 → 1,402 |
/* Rocket Forces |
* Filename: rforces.cpp |
* Version 0.1 |
* Copyright (c) Serial 2007 |
*/ |
#include <stdlib.h> |
#include "kosSyst.h" |
#include "kosFile.h" |
#include "mymath.h" |
#include "properties.h" |
#include "objects.h" |
#include "rforces.h" |
const char header[] = GAME_NAME; |
cCursor *cursor; |
cGun *gun = new cGun; |
cCross **crosses = new cCross*[R_COUNT]; |
cRocket **rockets = new cRocket*[R_COUNT]; |
cBomb **bombs = new cBomb*[B_COUNT]; |
cExplode **explodes = new cExplode*[R_COUNT + B_COUNT]; |
cBuilding *house = new cBuilding(); |
Dword *cur_handle; |
int score = 0, health = 100; |
struct MouseState |
{ |
int x, y, lbclick; |
Dword buttons; |
} ms; |
void kos_Main() |
{ |
Dword frame_start, frame_end; |
OnStart(); |
Menu(); |
for (;;) |
{ |
frame_start = kos_GetTime(); |
switch (kos_CheckForEvent()) |
{ |
case 1: |
DrawWindow(); |
break; |
case 2: // key pressed, read it and ignore |
Byte keyCode; |
kos_GetKey(keyCode); |
if (keyCode == 27) |
{ |
OnExit(); |
} |
break; |
case 3: // button pressed; we have only one button, close |
OnExit(); |
break; |
case 6: // ñîáûòèå îò ìûøè (íàæàòèå íà êíîïêó ìûøè èëè ïåðåìåùåíèå; ñáðàñûâàåòñÿ ïðè ïðî÷òåíèè) |
OnMouseMove(); |
if (ms.lbclick == 1) |
{ |
OnLMBClick(); |
} |
break; |
default: |
OnMouseMove(); |
break; |
} |
DrawBombs(); |
DrawRocketsAndCrosses(); |
DrawExplodes(); |
frame_end = kos_GetTime(); |
if (frame_end - frame_start < FRAME_TIME) |
{ |
kos_Pause(FRAME_TIME - (frame_end - frame_start)); |
} |
if (health <= 0) |
{ |
OnExit(); |
} |
} |
} |
void DrawWindow() |
{ |
kos_WindowRedrawStatus(1); |
kos_DefineAndDrawWindow(10, 40, WINDOW_WIDTH + 8, WINDOW_HEIGHT + 25, 0x33, BG_COLOR, 0, 0, (Dword)header); |
kos_WindowRedrawStatus(2); |
kos_WindowRedrawStatus(1); /// DEL!!!!11 |
OnMouseMove(); |
// Draw buildings |
for (int i = 20; i < 5 * 50; i += 50) |
{ |
house->Draw(i, 467, H_COLOR); |
} |
for (int i = 8 * 50; i < 13 * 50; i += 50) |
{ |
house->Draw(i, 467, H_COLOR); |
} |
} |
void DrawBombs() |
{ |
for (int i = 0; i < B_COUNT; i++) |
{ |
if (bombs[i]->IsEnabled() == 0) |
{ |
int rnd; |
rnd = rtlRand() % B_POSSIBILITY; |
if (rnd == 1) |
{ |
rnd = 10 + rtlRand() % 620; |
bombs[i]->Enable(rnd, 0, 4, 9, rnd + 2, 0); |
} |
} |
else |
{ |
if (bombs[i]->cy > gun->cy + 5) |
{ |
health -= 5; |
if (explodes[R_COUNT + i]->IsEnabled() == 1) |
{ |
explodes[R_COUNT + i]->Disable(BG_COLOR); |
} |
explodes[R_COUNT + i]->Enable(bombs[i]->cx, bombs[i]->cy); |
bombs[i]->Disable(BG_COLOR); |
} |
else |
{ |
bombs[i]->cy += B_SPEED; |
bombs[i]->DrawAngle(bombs[i]->cx, 639, B_COLOR); |
} |
} |
} |
} |
void DrawRocketsAndCrosses() |
{ |
double a; |
for (int i = 0; i < R_COUNT; i++) |
{ |
if (crosses[i]->IsEnabled() == 1) |
{ |
if (sqrt(((long int) (crosses[i]->x - rockets[i]->cx) * (crosses[i]->x - rockets[i]->cx)) + ((long int) (crosses[i]->y - rockets[i]->cy) * (crosses[i]->y - rockets[i]->cy))) < 5) |
{ |
if (explodes[i]->IsEnabled() == 1) |
{ |
explodes[i]->Disable(BG_COLOR); |
} |
explodes[i]->Enable(crosses[i]->x, crosses[i]->y); |
crosses[i]->Disable(BG_COLOR); |
rockets[i]->Disable(BG_COLOR); |
} |
else |
{ |
crosses[i]->Draw(CROSS_COLOR); |
if (rockets[i]->cx - crosses[i]->x == 0) |
{ |
a = M_PI / 2; |
} |
else |
{ |
a = atan((double)(rockets[i]->cy - crosses[i]->y) / (double)(rockets[i]->cx - crosses[i]->x)); |
if (rockets[i]->cx - crosses[i]->x < 0) a += M_PI; |
} |
rockets[i]->cx = round_int(rockets[i]->cx - R_SPEED * cos(a)); |
rockets[i]->cy = round_int(rockets[i]->cy - R_SPEED * sin(a)); |
rockets[i]->DrawAngle(crosses[i]->x, crosses[i]->y, R_COLOR); |
} |
} |
} |
} |
void DrawExplodes() |
{ |
for (int i = 0; i < R_COUNT + B_COUNT; i++) |
{ |
if (explodes[i]->IsEnabled() == 1) |
{ |
explodes[i]->DrawNext(EXP_COLOR); |
for (int j = 0; j < B_COUNT; j++) |
{ |
if ( bombs[j]->IsEnabled() == 1 && |
bombs[j]->cx > explodes[i]->cx - explodes[i]->step - 1 && bombs[j]->cx < explodes[i]->cx + explodes[i]->step + 1 && |
bombs[j]->cy + 5 > explodes[i]->cy - explodes[i]->step - 1 && bombs[j]->cy + 5 < explodes[i]->cy + explodes[i]->step + 1 |
) |
{ |
score += B_COUNT + 2; |
if (explodes[R_COUNT + j]->IsEnabled() == 1) |
{ |
explodes[R_COUNT + j]->Disable(BG_COLOR); |
} |
explodes[R_COUNT + j]->Enable(bombs[j]->cx, bombs[j]->cy); |
bombs[j]->Disable(BG_COLOR); |
} |
} |
} |
} |
} |
void OnMouseMove() |
{ |
Dword old_buttons = ms.buttons; |
kos_GetMouseWindowXY(ms.x, ms.y); |
kos_GetMouseButtonsState(ms.buttons); |
if ((old_buttons & 0x00000001) == 0 && (ms.buttons & 0x00000001) == 1) |
{ |
ms.lbclick = 1; |
} |
else |
{ |
ms.lbclick = 0; |
} |
kos_WriteTextToWindow(8, 10, 0, TEXT_COLOR, "Population: %", 16); |
kos_DisplayNumberToWindowBg(health, 3, 79, 10, TEXT_COLOR, BG_COLOR, nbDecimal, false); |
kos_WriteTextToWindow(8, 22, 0, TEXT_COLOR, "Score:", 6); |
kos_DisplayNumberToWindowBg(score, 4, 49, 22, TEXT_COLOR, BG_COLOR, nbDecimal, false); |
if (ms.x >= 0 && ms.x < WINDOW_WIDTH && ms.y >= 0 && ms.y < WINDOW_HEIGHT) |
{ |
gun->DrawAngle(ms.x, ms.y, G_COLOR); |
} |
if (HARDWARE_CURSOR == 0) |
{ |
cursor->Draw(ms.x, ms.y, CUR_COLOR); |
} |
/*if (DEBUG == 1) |
{ |
kos_DisplayNumberToWindowBg(ms.x, 3, WINDOW_WIDTH - 30, 10, TEXT_COLOR, BG_COLOR, nbDecimal, false); |
kos_DisplayNumberToWindowBg(ms.y, 3, WINDOW_WIDTH - 30, 22, TEXT_COLOR, BG_COLOR, nbDecimal, false); |
kos_DisplayNumberToWindowBg(ms.buttons, 1, WINDOW_WIDTH - 30, 34, TEXT_COLOR, BG_COLOR, nbDecimal, false); |
}*/ |
} |
void OnLMBClick() |
{ |
if (ms.y < gun->cy - 10) |
{ |
double a; |
int j = -1; |
for (int i = 0; i < R_COUNT; i++) |
{ |
if (crosses[i]->IsEnabled() == 0) |
{ |
if (j >= -1) j = i; |
} |
else if (ms.x > crosses[i]->x - 10 && ms.x < crosses[i]->x + 10 && ms.y > crosses[i]->y - 10 && ms.y < crosses[i]->y + 10) |
{ |
j = -2; |
break; |
} |
} |
if (j >= 0) |
{ |
if (score > 0) score -= 1; |
crosses[j]->Enable(ms.x, ms.y); |
if (gun->cx - ms.x == 0) |
{ |
a = M_PI/2; |
} |
else |
{ |
a = atan((double)gun->cy - ms.y / (double) gun->cx - ms.x); |
if (gun->cx - ms.x < 0) a += M_PI; |
} |
rockets[j]->Enable(round_int(gun->cx - 15 * cos(a)) - 2, round_int(gun->cy - 15 * sin(a)) - 5, 3, 6, round_int(gun->cx - 15 * cos(a)), round_int(gun->cy - 15 * sin(a))); |
} |
} |
} |
void OnRMBClick() |
{ |
} |
void ChangeCursor() |
{ |
Dword *cur = new Dword[1024]; |
for (int i = 0; i < 1024; i++) |
{ |
cur[i] = 0x00000000; |
} |
if (HARDWARE_CURSOR == 1) |
{ |
Dword cur_color = 0xFF000000 | CUR_COLOR; |
cur[0 * 32 + 5] = cur_color; |
cur[1 * 32 + 5] = cur_color; |
cur[2 * 32 + 5] = cur_color; |
cur[2 * 32 + 3] = cur_color; |
cur[2 * 32 + 4] = cur_color; |
cur[2 * 32 + 6] = cur_color; |
cur[3 * 32 + 2] = cur_color; |
cur[4 * 32 + 2] = cur_color; |
cur[5 * 32 + 2] = cur_color; |
cur[5 * 32 + 1] = cur_color; |
cur[5 * 32 + 0] = cur_color; |
cur[5 * 32 + 5] = cur_color; |
cur[8 * 32 + 4] = cur_color; |
cur[8 * 32 + 5] = cur_color; |
cur[8 * 32 + 6] = cur_color; |
cur[8 * 32 + 7] = cur_color; |
cur[9 * 32 + 5] = cur_color; |
cur[10 * 32 + 5] = cur_color; |
cur[7 * 32 + 8] = cur_color; |
cur[6 * 32 + 8] = cur_color; |
cur[5 * 32 + 8] = cur_color; |
cur[5 * 32 + 9] = cur_color; |
cur[5 * 32 + 10] = cur_color; |
} |
cur_handle = kos_LoadMouseCursor(cur, 0x05050002); |
delete[] cur; |
kos_SetMouseCursor(cur_handle); |
} |
void Menu() |
{ |
NewGame(); |
} |
void NewGame() |
{ |
gun->DrawAngle((WINDOW_WIDTH / 2) - 5, WINDOW_HEIGHT - 20, G_COLOR); |
} |
void OnStart() |
{ |
if (HARDWARE_CURSOR == 0) |
{ |
cursor = new cCursor(); |
} |
ChangeCursor(); |
gun->Enable((WINDOW_WIDTH / 2) - 10, WINDOW_HEIGHT - 30, 10, 20, (WINDOW_WIDTH / 2) - 5, WINDOW_HEIGHT - 20); |
for (int i = 0; i < R_COUNT; i++) |
{ |
crosses[i] = new cCross(); |
rockets[i] = new cRocket(); |
} |
for (int i = 0; i < B_COUNT; i++) |
{ |
bombs[i] = new cBomb(); |
} |
for (int i = 0; i < R_COUNT + B_COUNT; i++) |
{ |
explodes[i] = new cExplode(); |
} |
rtlSrand(kos_GetTime()); |
DrawWindow(); |
kos_SetMaskForEvents(39); |
} |
void OnExit() |
{ |
kos_WriteTextToWindow(WINDOW_WIDTH / 2 - 35, WINDOW_HEIGHT / 2 - 10, 0, TEXT_COLOR, "Game Over", 9); |
//while(kos_WaitForEvent() != 2); |
kos_Pause(200); |
/*kos_DeleteMouseCursor(cur_handle); |
for (int i = 0; i < R_COUNT; i++) |
{ |
delete crosses[i]; |
delete rockets[i]; |
} |
for (int i = 0; i < B_COUNT; i++) |
{ |
delete bombs[i]; |
} |
for (int i = 0; i < R_COUNT + B_COUNT; i++) |
{ |
delete explodes[i]; |
} |
delete[] crosses; |
delete[] rockets; |
delete[] bombs; |
delete[] explodes; |
delete gun; |
delete house; |
if (HARDWARE_CURSOR == 0) |
{ |
delete cursor; |
}*/ |
kos_ExitApp(); |
} |
/programs/games/rforces/trunk/kosFile.cpp |
---|
0,0 → 1,131 |
#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; |
} |
/programs/games/rforces/trunk/kosSyst.cpp |
---|
0,0 → 1,970 |
#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; |
} |
// |
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 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; |
} |
// ôóíêöèÿ 26.9 ïîëó÷èòü çíà÷åíèå ñ÷¸ò÷èêà âðåìåíè |
Dword kos_GetTime() |
{ |
__asm{ |
mov eax, 26 |
mov ebx, 9 |
int 0x40 |
} |
} |
// ôóíêöèÿ 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; |
} |
// ôóíêöèÿ 37.1 ïîëó÷åíèå êîîðäèíàò "ìûøè" îòíîñèòåëüíî îêíà |
void kos_GetMouseWindowXY( int & cursorX, int & cursorY ) |
{ |
Word curX; |
Word curY; |
__asm{ |
mov eax, 37 |
mov ebx, 1 |
int 0x40 |
mov ebx, eax |
shr eax, 16 |
and ebx, 0xffff |
mov curX, ax |
mov curY, bx |
} |
cursorX = curX; |
cursorY = curY; |
} |
// ôóíêöèÿ 37.2 ïîëó÷åíèå èíôîðìàöèè î íàæàòûõ êíîïêè "ìûøè" |
void kos_GetMouseButtonsState( Dword & buttons ) |
{ |
Dword mB; |
__asm{ |
mov eax, 37 |
mov ebx, 2 |
int 0x40 |
mov mB, eax |
} |
buttons = mB; |
} |
// ôóíêöèÿ 37.4 çàãðóçêà êóðñîðà "ìûøè" |
Dword * kos_LoadMouseCursor( Dword * cursor, Dword loadstate ) |
{ |
//Dword handle; |
__asm{ |
mov eax, 37 |
mov ebx, 4 |
mov edx, loadstate |
mov ecx, cursor |
int 0x40 |
//mov handle, eax |
} |
//return handle; |
} |
// ôóíêöèÿ 37.5 óñòàíîâêà êóðñîðà "ìûøè" |
Dword * kos_SetMouseCursor( Dword * handle ) |
{ |
//Dword handle; |
__asm{ |
mov eax, 37 |
mov ebx, 5 |
mov ecx, handle |
int 0x40 |
//mov handle, eax |
} |
//return handle; |
} |
// ôóíêöèÿ 37.6 óäàëåíèå êóðñîðà "ìûøè" |
void kos_DeleteMouseCursor( Dword * handle ) |
{ |
__asm{ |
mov eax, 37 |
mov ebx, 6 |
mov ecx, handle |
int 0x40 |
} |
} |
// ôóíêöèÿ 38 íàðèñîâàòü ïîëîñó |
void kos_DrawLine( Word x1, Word y1, Word x2, Word y2, Dword colour ) |
{ |
Dword arg1, arg2; |
// |
arg1 = ( x1 << 16 ) | x2; |
arg2 = ( y1 << 16 ) | y2; |
// |
__asm{ |
mov eax, 38 |
mov ebx, arg1 |
mov ecx, arg2 |
mov edx, colour |
int 0x40 |
} |
} |
// ôóíêöèÿ 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 |
} |
} |
// ôóíêöèÿ 47 âûâåñòè â îêíî ïðèëîæåíèÿ ÷èñëî c ôîíîì |
void kos_DisplayNumberToWindowBg( |
Dword value, |
Dword digitsNum, |
Word x, |
Word y, |
Dword colour, |
Dword bgcolour, |
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 |
or esi, 0x40000000 |
mov edi, bgcolour |
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(); |
} |
/programs/games/rforces/trunk/kosSyst.h |
---|
0,0 → 1,220 |
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; |
}; |
// |
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 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 ); |
// ôóíêöèÿ 26.9 ïîëó÷èòü çíà÷åíèå ñ÷¸ò÷èêà âðåìåíè |
Dword kos_GetTime(); |
// |
enum eNumberBase |
{ |
nbDecimal = 0, |
nbHex, |
nbBin |
}; |
// ôóíêöèÿ 37 ïîëó÷åíèå èíôîðìàöèè î ñîñòîÿíèè "ìûøè" |
void kos_GetMouseState( Dword & buttons, int & cursorX, int & cursorY ); |
// ôóíêöèÿ 37.1 ïîëó÷åíèå êîîðäèíàò "ìûøè" îòíîñèòåëüíî îêíà |
void kos_GetMouseWindowXY( int & cursorX, int & cursorY ); |
// ôóíêöèÿ 37.2 ïîëó÷åíèå èíôîðìàöèè î íàæàòûõ êíîïêè "ìûøè" |
void kos_GetMouseButtonsState( Dword & buttons ); |
// ôóíêöèÿ 37.4 çàãðóçêà êóðñîðà "ìûøè" |
Dword * kos_LoadMouseCursor( Dword * cursor, Dword loadstate ); |
// ôóíêöèÿ 37.5 óñòàíîâêà êóðñîðà "ìûøè" |
Dword * kos_SetMouseCursor( Dword * handle ); |
// ôóíêöèÿ 37.6 óäàëåíèå êóðñîðà "ìûøè" |
void kos_DeleteMouseCursor( Dword * handle ); |
// ôóíêöèÿ 38 íàðèñîâàòü ïîëîñó |
void kos_DrawLine( Word x1, Word y1, Word x2, Word y2, Dword colour ); |
// ôóíêöèÿ 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 |
); |
// ôóíêöèÿ 47 âûâåñòè â îêíî ïðèëîæåíèÿ ÷èñëî c ôîíîì |
void kos_DisplayNumberToWindowBg( |
Dword value, |
Dword digitsNum, |
Word x, |
Word y, |
Dword colour, |
Dword bgcolour, |
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/rforces/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/rforces/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/rforces/trunk/mymath.h |
---|
0,0 → 1,95 |
/* Rocket Forces |
* Filename: mymath.h |
* Version 0.1 |
* Copyright (c) Serial 2007 |
*/ |
extern "C" int _fltused = 0; |
#define M_PI 3.14159265358979323846 |
inline double sin(double x) |
{ |
__asm fld x |
__asm fsin |
} |
inline double cos(double x) |
{ |
__asm fld x |
__asm fcos |
} |
inline double sqrt(double x) |
{ |
__asm fld x |
__asm fsqrt |
} |
inline double acos(double x) |
{ |
__asm fld x |
__asm fld st(0) |
__asm fmul st,st(1) |
__asm fld1 |
__asm fsubrp st(1),st(0) |
__asm fsqrt |
__asm fxch st(1) |
__asm fpatan |
} |
inline double atan(double x) |
{ |
double res = acos(1 / sqrt(1 + x * x)); |
if (x < 0) |
{ |
res *= -1; |
} |
return res; |
} |
inline int round_int(double x) |
{ |
int i; |
static const float round_to_nearest = 0.5f; |
__asm |
{ |
fld x |
fadd st, st(0) |
fadd round_to_nearest |
fistp i |
sar i, 1 |
} |
return i; |
} |
inline int floor_int(double x) |
{ |
int i; |
static const float round_toward_m_i = -0.5f; |
__asm |
{ |
fld x |
fadd st, st (0) |
fadd round_toward_m_i |
fistp i |
sar i, 1 |
} |
return i; |
} |
inline int ceil_int(double x) |
{ |
int i; |
static const float round_toward_p_i = -0.5f; |
__asm |
{ |
fld x |
fadd st, st (0) |
fsubr round_toward_p_i |
fistp i |
sar i, 1 |
} |
return (-i); |
} |
/programs/games/rforces/trunk/objects.h |
---|
0,0 → 1,466 |
/* Rocket Forces |
* Filename: objects.h |
* Version 0.1 |
* Copyright (c) Serial 2007 |
*/ |
void ppx(int x, int y, int color); |
void pline(int x1, int y1, int x2, int y2, int color); |
void draw4(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int color); |
class cBuilding |
{ |
public: |
void Draw(int x, int y, int color) |
{ |
draw4(x, y, x+10, y-5, x+20, y, x, y, color); |
draw4(x, y, x+20, y, x+20, y+11, x, y+11, color); |
draw4(x+3, y+3, x+8, y+3, x+8, y+8, x+3, y+8, color); |
draw4(x+15, y+3, x+20, y+3, x+20, y+11, x+15, y+11, color); |
} |
}; |
class cCursor |
{ |
public: |
cCursor() |
{ |
cx = -1; |
cy = -1; |
} |
void Delete(int color) |
{ |
ppx(cx, cy, color); |
ppx(cx-3, cy, color); |
ppx(cx-4, cy, color); |
ppx(cx-5, cy, color); |
ppx(cx, cy-3, color); |
ppx(cx, cy-4, color); |
ppx(cx, cy-5, color); |
ppx(cx-1, cy-3, color); |
ppx(cx-2, cy-3, color); |
ppx(cx-3, cy-3, color); |
ppx(cx-3, cy-2, color); |
ppx(cx-3, cy-1, color); |
ppx(cx+1, cy-3, color); |
ppx(cx+3, cy, color); |
ppx(cx+4, cy, color); |
ppx(cx+5, cy, color); |
ppx(cx, cy+3, color); |
ppx(cx, cy+4, color); |
ppx(cx, cy+5, color); |
ppx(cx+1, cy+3, color); |
ppx(cx+2, cy+3, color); |
ppx(cx+3, cy+3, color); |
ppx(cx+3, cy+2, color); |
ppx(cx+3, cy+1, color); |
ppx(cx+1, cy-3, color); |
ppx(cx-1, cy+3, color); |
} |
void Draw(int x, int y, int color) |
{ |
if (cx!=x || cy!=y) |
{ |
Delete(BG_COLOR); |
cx = x; |
cy = y; |
ppx(cx, cy, color); |
ppx(cx-3, cy, color); |
ppx(cx-4, cy, color); |
ppx(cx-5, cy, color); |
ppx(cx, cy-3, color); |
ppx(cx, cy-4, color); |
ppx(cx, cy-5, color); |
ppx(cx-1, cy-3, color); |
ppx(cx-2, cy-3, color); |
//ppx(cx-3, cy-3, color); |
ppx(cx-3, cy-2, color); |
ppx(cx-3, cy-1, color); |
ppx(cx+1, cy-3, color); |
ppx(cx+3, cy, color); |
ppx(cx+4, cy, color); |
ppx(cx+5, cy, color); |
ppx(cx, cy+3, color); |
ppx(cx, cy+4, color); |
ppx(cx, cy+5, color); |
ppx(cx+1, cy+3, color); |
ppx(cx+2, cy+3, color); |
//ppx(cx+3, cy+3, color); |
ppx(cx+3, cy+2, color); |
ppx(cx+3, cy+1, color); |
ppx(cx+1, cy-3, color); |
ppx(cx-1, cy+3, color); |
} |
} |
private: |
int cx, cy; |
}; |
class cExplode |
{ |
public: |
cExplode() |
{ |
cx = -1; |
cy = -1; |
} |
void Enable(int cx, int cy) |
{ |
step = 1; |
cExplode::cx = cx; |
cExplode::cy = cy; |
} |
int IsEnabled(void) |
{ |
if (cx==-1 && cy==-1) |
{ |
return 0; |
} |
else |
{ |
return 1; |
} |
} |
void Draw(int r, int color) |
{ |
int d=3-2*r, x=-1, y=r; |
while (x++<y) |
{ |
ppx(cx+x, cy+y, color); |
ppx(cx+x, cy-y, color); |
ppx(cx-x, cy+y, color); |
ppx(cx-x, cy-y, color); |
ppx(cx+y, cy+x, color); |
ppx(cx+y, cy-x, color); |
ppx(cx-y, cy+x, color); |
ppx(cx-y, cy-x, color); |
if (d<0) |
{ |
d += 4*x+6; |
} |
else |
{ |
d += 4*(x-y)+10; |
y--; |
} |
} |
} |
void DrawNext(int color) |
{ |
if (step>=EXP_RAD) |
{ |
Disable(BG_COLOR); |
} |
else |
{ |
Draw(step, BG_COLOR); |
Draw(++step, color); |
} |
} |
void Disable(int color) |
{ |
Draw(step, color); |
cx = -1; |
cy = -1; |
} |
int cx, cy; |
int step; |
}; |
class cRocket |
{ |
public: |
cRocket() |
{ |
cx = -1; |
cy = -1; |
} |
void Enable(int x, int y, int width, int height, int cx, int cy) |
{ |
coord[0][0] = x; |
coord[0][1] = y; |
coord[1][0] = x+width; |
coord[1][1] = y; |
coord[2][0] = x+width; |
coord[2][1] = y+height; |
coord[3][0] = x; |
coord[3][1] = y+height; |
cRocket::cx = cx; |
cRocket::cy = cy; |
for (int j=0; j<4; j++) |
{ |
dist[j] = sqrt((double)((coord[j][0]-cx)*(coord[j][0]-cx)+(coord[j][1]-cy)*(coord[j][1]-cy))); |
fi[j] = acos((coord[j][0]-cx)/dist[j]); |
if (coord[j][1]<cy) fi[j]*=-1; |
fire[j][0] = -1; |
fire[j][1] = -1; |
} |
} |
int IsEnabled(void) |
{ |
if (cx==-1 && cy==-1) |
{ |
return 0; |
} |
else |
{ |
return 1; |
} |
} |
void Draw(int color) |
{ |
draw4(coord[0][0], coord[0][1], coord[1][0], coord[1][1], coord[2][0], coord[2][1], coord[3][0], coord[3][1], color); |
if (fire[3][0]!=-1 || fire[3][1]!=-1) |
{ |
ppx(fire[3][0], fire[3][1], BG_COLOR); |
} |
} |
void DrawAngle(int mx, int my, int color) |
{ |
// Delete old rectangle |
Draw(BG_COLOR); |
// Draw new rectangle |
double a; |
long int dx = (long int) (cx-mx)*(cx-mx); |
long int dy = (long int) (cy-my)*(cy-my); |
if (cx!=mx || cy!=my) |
{ |
a = -M_PI/2+acos((cx-mx)/sqrt((double)(dx+dy))); |
for (int j=0; j<4; j++) |
{ |
coord[j][0] = round_int((double)(cx+dist[j]*cos(a+fi[j]))); |
coord[j][1] = round_int((double)(cy+dist[j]*sin(a+fi[j]))); |
} |
} |
draw4(coord[0][0], coord[0][1], coord[1][0], coord[1][1], coord[2][0], coord[2][1], coord[3][0], coord[3][1], color); |
for (int i=3; i>0; i--) |
{ |
fire[i][0] = fire[i-1][0]; |
fire[i][1] = fire[i-1][1]; |
} |
fire[0][0] = cx; |
fire[0][1] = cy; |
for (int i=1; i<4; i++) |
{ |
if (fire[i][0]!=-1 || fire[i][1]!=-1) ppx(fire[i][0], fire[i][1], SMOKE_COLOR); |
} |
} |
void Disable(int color) |
{ |
for (int i=0; i<4; i++) |
{ |
ppx(fire[i][0], fire[i][1], color); |
fire[i][0] = 0; |
fire[i][1] = 0; |
} |
Draw(color); |
cx = -1; |
cy = -1; |
} |
int cx, cy; |
protected: |
int coord[4][2]; |
double dist[4]; |
double fi[4]; |
int fire[4][2]; |
}; |
class cBomb: public cRocket |
{ |
public: |
void Draw(int color) |
{ |
draw4(coord[0][0], coord[0][1], coord[1][0], coord[1][1], coord[2][0], coord[2][1], coord[3][0], coord[3][1], color); |
ppx(cx-1, coord[2][1]+1, color); |
ppx(cx, coord[2][1]+1, color); |
ppx(cx+1, coord[2][1]+1, color); |
for (int i=1; i<4; i++) |
{ |
if (fire[i][0]!=-1 || fire[i][1]!=-1) |
{ |
if (i==1) |
{ |
ppx(fire[i][0]-1, fire[i][1], BG_COLOR); |
ppx(fire[i][0]+1, fire[i][1], BG_COLOR); |
} |
else |
{ |
ppx(fire[i][0], fire[i][1], BG_COLOR); |
} |
} |
} |
} |
void DrawAngle(int mx, int my, int color) |
{ |
// Delete old rectangle |
Draw(BG_COLOR); |
// Draw new rectangle |
for (int j=0; j<4; j++) |
{ |
coord[j][1] += B_SPEED; |
} |
draw4(coord[0][0], coord[0][1], coord[1][0], coord[1][1], coord[2][0], coord[2][1], coord[3][0], coord[3][1], color); |
ppx(cx-1, coord[2][1]+1, color); |
ppx(cx, coord[2][1]+1, color); |
ppx(cx+1, coord[2][1]+1, color); |
for (int i=3; i>0; i--) |
{ |
fire[i][0] = fire[i-1][0]; |
fire[i][1] = fire[i-1][1]; |
} |
fire[0][0] = cx; |
fire[0][1] = cy; |
for (int i=1; i<4; i++) |
{ |
if (fire[i][0]!=-1 || fire[i][1]!=-1) |
{ |
if (i==1) |
{ |
ppx(fire[i][0]-1, fire[i][1], SMOKE_COLOR); |
ppx(fire[i][0]+1, fire[i][1], SMOKE_COLOR); |
} |
else |
{ |
ppx(fire[i][0], fire[i][1], SMOKE_COLOR); |
} |
} |
} |
} |
void Disable(int color) |
{ |
for (int i=0; i<4; i++) |
{ |
ppx(fire[i][0], fire[i][1], color); |
fire[i][0] = 0; |
fire[i][1] = 0; |
} |
Draw(color); |
cx = -1; |
cy = -1; |
} |
}; |
class cGun: public cRocket |
{ |
public: |
void Enable(int x, int y, int width, int height, int cx, int cy) |
{ |
old_mx = -1; |
old_my = -1; |
coord[0][0] = x; |
coord[0][1] = y; |
coord[1][0] = x+width; |
coord[1][1] = y; |
coord[2][0] = x+width; |
coord[2][1] = y+height; |
coord[3][0] = x; |
coord[3][1] = y+height; |
cRocket::cx = cx; |
cRocket::cy = cy; |
for (int j=0; j<4; j++) |
{ |
dist[j] = sqrt((double)((coord[j][0]-cx)*(coord[j][0]-cx)+(coord[j][1]-cy)*(coord[j][1]-cy))); |
fi[j] = acos((coord[j][0]-cx)/dist[j]); |
if (coord[j][1]<cy) fi[j]*=-1; |
} |
} |
void DrawAngle(int mx, int my, int color) |
{ |
if (old_mx!=mx || old_my!=my) |
{ |
// Delete old rectangle |
old_mx = mx; |
old_my = my; |
Draw(BG_COLOR); |
// Draw new rectangle |
double a; |
long int dx = (long int)(cx-mx)*(cx-mx); |
long int dy = (long int)(cy-my)*(cy-my); |
if (my<=cy && (cx!=mx || cy!=my)) |
{ |
a = -M_PI/2+acos((cx-mx)/sqrt((double)(dx+dy))); |
for (int j=0; j<4; j++) |
{ |
coord[j][0] = round_int((double)(cx+dist[j]*cos(a+fi[j]))); |
coord[j][1] = round_int((double)(cy+dist[j]*sin(a+fi[j]))); |
} |
} |
draw4(coord[0][0], coord[0][1], coord[1][0], coord[1][1], coord[2][0], coord[2][1], coord[3][0], coord[3][1], color); |
draw4(cx-14, cy+2, cx+14, cy+2, cx+14, cy+18, cx-14, cy+18, color); |
} |
} |
protected: |
int old_mx, old_my; |
}; |
class cCross |
{ |
public: |
cCross() |
{ |
x = -1; |
y = -1; |
} |
void Enable(int x, int y) |
{ |
cCross::x = x; |
cCross::y = y; |
size = 2; |
} |
int IsEnabled(void) |
{ |
if (x == -1 && y == -1) |
{ |
return 0; |
} |
else |
{ |
return 1; |
} |
} |
void Draw(int color) |
{ |
pline(x-size, y, x+size, y, color); |
pline(x, y-size, x, y+size, color); |
ppx(x, y, BG_COLOR); |
} |
void Disable(int color) |
{ |
pline(x-size, y, x+size, y, color); |
pline(x, y-size, x, y+size, color); |
x = -1; |
y = -1; |
} |
int x, y; |
protected: |
int size; |
}; |
void ppx(int x, int y, int color) |
{ |
if (x >= 0 && x < WINDOW_WIDTH && y >= 0 && y < WINDOW_HEIGHT) kos_PutPixel(x, y, color); |
} |
void pline(int x1, int y1, int x2, int y2, int color) |
{ |
kos_DrawLine(x1, y1, x2, y2, color); |
} |
void draw4(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int color) |
{ |
pline(x1, y1, x2, y2, color); |
pline(x2, y2, x3, y3, color); |
pline(x3, y3, x4, y4, color); |
pline(x4, y4, x1, y1, color); |
} |
/programs/games/rforces/trunk/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/rforces/trunk/properties.h |
---|
0,0 → 1,46 |
/* Rocket Forces |
* Filename: properties.h |
* Version 0.1 |
* Copyright (c) Serial 2007 |
*/ |
// Color defines |
#define BLACK 0x00000000 |
#define BLUE 0x000000FF |
#define GREEN 0x0000FF00 |
#define RED 0x00FF0000 |
#define LIGHTGRAY 0x00C0C0C0 |
#define DARKGRAY 0x00808080 |
#define YELLOW 0x00FFFF00 |
#define WHITE 0x00FFFFFF |
// Visual properties |
#define GAME_NAME "Rocket Forces v0.1 (F2 - new game, Esc - exit) " |
#define BG_COLOR BLACK |
#define TEXT_COLOR WHITE |
#define CUR_COLOR GREEN |
#define CROSS_COLOR RED |
#define G_COLOR WHITE |
#define R_COLOR GREEN |
#define B_COLOR BLUE |
#define EXP_COLOR YELLOW |
#define H_COLOR LIGHTGRAY |
#define SMOKE_COLOR LIGHTGRAY |
// Game properties |
// R == Rocket |
// B == Bomb |
// EXP == Explode |
int R_COUNT = 6; |
int R_SPEED = 9; |
int B_COUNT = 5; |
int B_SPEED = 4; |
int B_POSSIBILITY = 200; |
int EXP_RAD = 12; |
int FRAME_TIME = 5; |
int HARDWARE_CURSOR = 0; |
int DEBUG = 0; |
#define WINDOW_WIDTH 640 |
#define WINDOW_HEIGHT 480 |
/programs/games/rforces/trunk/rforces.cpp |
---|
0,0 → 1,379 |
/* Rocket Forces |
* Filename: rforces.cpp |
* Version 0.1.1 |
* Copyright (c) Serial 2007 |
*/ |
#include <stdlib.h> |
#include "kosSyst.h" |
#include "kosFile.h" |
#include "mymath.h" |
#include "properties.h" |
#include "objects.h" |
#include "rforces.h" |
const char header[] = GAME_NAME; |
cCursor *cursor; |
cGun *gun = new cGun; |
cCross **crosses = new cCross*[R_COUNT]; |
cRocket **rockets = new cRocket*[R_COUNT]; |
cBomb **bombs = new cBomb*[B_COUNT]; |
cExplode **explodes = new cExplode*[R_COUNT + B_COUNT]; |
cBuilding *house = new cBuilding(); |
Dword *cur_handle; |
int score, health; |
struct MouseState |
{ |
int x, y, lbclick; |
Dword buttons; |
} ms; |
void kos_Main() |
{ |
Dword frame_start, frame_end; |
OnStart(); |
Menu(); |
for (;;) |
{ |
frame_start = kos_GetTime(); |
switch (kos_CheckForEvent()) |
{ |
case 1: |
DrawWindow(); |
break; |
case 2: // key pressed, read it and ignore |
Byte keyCode; |
kos_GetKey(keyCode); |
if (keyCode == 27) |
{ |
OnExit(); |
} |
if (keyCode == 51) |
{ |
OnStart(); |
} |
break; |
case 3: // button pressed; we have only one button, close |
OnExit(); |
break; |
case 6: // ñîáûòèå îò ìûøè (íàæàòèå íà êíîïêó ìûøè èëè ïåðåìåùåíèå; ñáðàñûâàåòñÿ ïðè ïðî÷òåíèè) |
OnMouseMove(); |
if (ms.lbclick == 1) |
{ |
OnLMBClick(); |
} |
break; |
default: |
OnMouseMove(); |
break; |
} |
DrawBombs(); |
DrawRocketsAndCrosses(); |
DrawExplodes(); |
frame_end = kos_GetTime(); |
if (frame_end - frame_start < FRAME_TIME) |
{ |
kos_Pause(FRAME_TIME - (frame_end - frame_start)); |
} |
if (health <= 0) |
{ |
OnExit(); |
} |
} |
} |
void DrawWindow() |
{ |
kos_WindowRedrawStatus(1); |
kos_DefineAndDrawWindow(10, 40, WINDOW_WIDTH + 8, WINDOW_HEIGHT + 25, 0x33, BG_COLOR, 0, 0, (Dword)header); |
kos_WindowRedrawStatus(2); |
OnMouseMove(); |
// Draw buildings |
for (int i = 20; i < 5 * 50; i += 50) |
{ |
house->Draw(i, 467, H_COLOR); |
} |
for (int i = 8 * 50; i < 13 * 50; i += 50) |
{ |
house->Draw(i, 467, H_COLOR); |
} |
} |
void DrawBombs() |
{ |
for (int i = 0; i < B_COUNT; i++) |
{ |
if (bombs[i]->IsEnabled() == 0) |
{ |
int rnd; |
rnd = rtlRand() % B_POSSIBILITY; |
if (rnd == 1) |
{ |
rnd = 10 + rtlRand() % 620; |
bombs[i]->Enable(rnd, 0, 4, 9, rnd + 2, 0); |
} |
} |
else |
{ |
if (bombs[i]->cy > gun->cy + 5) |
{ |
health -= 5; |
if (explodes[R_COUNT + i]->IsEnabled() == 1) |
{ |
explodes[R_COUNT + i]->Disable(BG_COLOR); |
} |
explodes[R_COUNT + i]->Enable(bombs[i]->cx, bombs[i]->cy); |
bombs[i]->Disable(BG_COLOR); |
} |
else |
{ |
bombs[i]->cy += B_SPEED; |
bombs[i]->DrawAngle(bombs[i]->cx, 639, B_COLOR); |
} |
} |
} |
} |
void DrawRocketsAndCrosses() |
{ |
double a; |
for (int i = 0; i < R_COUNT; i++) |
{ |
if (crosses[i]->IsEnabled() == 1) |
{ |
if (sqrt(((long int) (crosses[i]->x - rockets[i]->cx) * (crosses[i]->x - rockets[i]->cx)) + ((long int) (crosses[i]->y - rockets[i]->cy) * (crosses[i]->y - rockets[i]->cy))) < 5) |
{ |
if (explodes[i]->IsEnabled() == 1) |
{ |
explodes[i]->Disable(BG_COLOR); |
} |
explodes[i]->Enable(crosses[i]->x, crosses[i]->y); |
crosses[i]->Disable(BG_COLOR); |
rockets[i]->Disable(BG_COLOR); |
} |
else |
{ |
crosses[i]->Draw(CROSS_COLOR); |
if (rockets[i]->cx - crosses[i]->x == 0) |
{ |
a = M_PI / 2; |
} |
else |
{ |
a = atan((double)(rockets[i]->cy - crosses[i]->y) / (double)(rockets[i]->cx - crosses[i]->x)); |
if (rockets[i]->cx - crosses[i]->x < 0) a += M_PI; |
} |
rockets[i]->cx = round_int(rockets[i]->cx - R_SPEED * cos(a)); |
rockets[i]->cy = round_int(rockets[i]->cy - R_SPEED * sin(a)); |
rockets[i]->DrawAngle(crosses[i]->x, crosses[i]->y, R_COLOR); |
} |
} |
} |
} |
void DrawExplodes() |
{ |
for (int i = 0; i < R_COUNT + B_COUNT; i++) |
{ |
if (explodes[i]->IsEnabled() == 1) |
{ |
explodes[i]->DrawNext(EXP_COLOR); |
for (int j = 0; j < B_COUNT; j++) |
{ |
if ( bombs[j]->IsEnabled() == 1 && |
bombs[j]->cx > explodes[i]->cx - explodes[i]->step - 1 && bombs[j]->cx < explodes[i]->cx + explodes[i]->step + 1 && |
bombs[j]->cy + 5 > explodes[i]->cy - explodes[i]->step - 1 && bombs[j]->cy + 5 < explodes[i]->cy + explodes[i]->step + 1 |
) |
{ |
score += B_COUNT + 2; |
if (explodes[R_COUNT + j]->IsEnabled() == 1) |
{ |
explodes[R_COUNT + j]->Disable(BG_COLOR); |
} |
explodes[R_COUNT + j]->Enable(bombs[j]->cx, bombs[j]->cy); |
bombs[j]->Disable(BG_COLOR); |
} |
} |
} |
} |
} |
void OnMouseMove() |
{ |
Dword old_buttons = ms.buttons; |
kos_GetMouseWindowXY(ms.x, ms.y); |
kos_GetMouseButtonsState(ms.buttons); |
if ((old_buttons & 0x00000001) == 0 && (ms.buttons & 0x00000001) == 1) |
{ |
ms.lbclick = 1; |
} |
else |
{ |
ms.lbclick = 0; |
} |
kos_WriteTextToWindow(8, 10, 0, TEXT_COLOR, "Population: %", 16); |
kos_DisplayNumberToWindowBg(health, 3, 79, 10, TEXT_COLOR, BG_COLOR, nbDecimal, false); |
kos_WriteTextToWindow(8, 22, 0, TEXT_COLOR, "Score:", 6); |
kos_DisplayNumberToWindowBg(score, 4, 49, 22, TEXT_COLOR, BG_COLOR, nbDecimal, false); |
if (ms.x >= 0 && ms.x < WINDOW_WIDTH && ms.y >= 0 && ms.y < WINDOW_HEIGHT) |
{ |
gun->DrawAngle(ms.x, ms.y, G_COLOR); |
} |
if (HARDWARE_CURSOR == 0) |
{ |
cursor->Draw(ms.x, ms.y, CUR_COLOR); |
} |
/*if (DEBUG == 1) |
{ |
kos_DisplayNumberToWindowBg(ms.x, 3, WINDOW_WIDTH - 30, 10, TEXT_COLOR, BG_COLOR, nbDecimal, false); |
kos_DisplayNumberToWindowBg(ms.y, 3, WINDOW_WIDTH - 30, 22, TEXT_COLOR, BG_COLOR, nbDecimal, false); |
kos_DisplayNumberToWindowBg(ms.buttons, 1, WINDOW_WIDTH - 30, 34, TEXT_COLOR, BG_COLOR, nbDecimal, false); |
}*/ |
} |
void OnLMBClick() |
{ |
if (ms.y < gun->cy - 10) |
{ |
double a; |
int j = -1; |
for (int i = 0; i < R_COUNT; i++) |
{ |
if (crosses[i]->IsEnabled() == 0) |
{ |
if (j >= -1) j = i; |
} |
else if (ms.x > crosses[i]->x - 10 && ms.x < crosses[i]->x + 10 && ms.y > crosses[i]->y - 10 && ms.y < crosses[i]->y + 10) |
{ |
j = -2; |
break; |
} |
} |
if (j >= 0) |
{ |
if (score > 0) score -= 1; |
crosses[j]->Enable(ms.x, ms.y); |
if (gun->cx - ms.x == 0) |
{ |
a = M_PI/2; |
} |
else |
{ |
a = atan((double)gun->cy - ms.y / (double) gun->cx - ms.x); |
if (gun->cx - ms.x < 0) a += M_PI; |
} |
rockets[j]->Enable(round_int(gun->cx - 15 * cos(a)) - 2, round_int(gun->cy - 15 * sin(a)) - 5, 3, 6, round_int(gun->cx - 15 * cos(a)), round_int(gun->cy - 15 * sin(a))); |
} |
} |
} |
void OnRMBClick() |
{ |
} |
void ChangeCursor() |
{ |
Dword *cur = new Dword[1024]; |
for (int i = 0; i < 1024; i++) |
{ |
cur[i] = 0x00000000; |
} |
if (HARDWARE_CURSOR == 1) |
{ |
Dword cur_color = 0xFF000000 | CUR_COLOR; |
cur[0 * 32 + 5] = cur_color; |
cur[1 * 32 + 5] = cur_color; |
cur[2 * 32 + 5] = cur_color; |
cur[2 * 32 + 3] = cur_color; |
cur[2 * 32 + 4] = cur_color; |
cur[2 * 32 + 6] = cur_color; |
cur[3 * 32 + 2] = cur_color; |
cur[4 * 32 + 2] = cur_color; |
cur[5 * 32 + 2] = cur_color; |
cur[5 * 32 + 1] = cur_color; |
cur[5 * 32 + 0] = cur_color; |
cur[5 * 32 + 5] = cur_color; |
cur[8 * 32 + 4] = cur_color; |
cur[8 * 32 + 5] = cur_color; |
cur[8 * 32 + 6] = cur_color; |
cur[8 * 32 + 7] = cur_color; |
cur[9 * 32 + 5] = cur_color; |
cur[10 * 32 + 5] = cur_color; |
cur[7 * 32 + 8] = cur_color; |
cur[6 * 32 + 8] = cur_color; |
cur[5 * 32 + 8] = cur_color; |
cur[5 * 32 + 9] = cur_color; |
cur[5 * 32 + 10] = cur_color; |
} |
cur_handle = kos_LoadMouseCursor(cur, 0x05050002); |
delete[] cur; |
kos_SetMouseCursor(cur_handle); |
} |
void Menu() |
{ |
NewGame(); |
} |
void NewGame() |
{ |
gun->DrawAngle((WINDOW_WIDTH / 2) - 5, WINDOW_HEIGHT - 20, G_COLOR); |
} |
void OnStart() |
{ |
if (HARDWARE_CURSOR == 0) |
{ |
cursor = new cCursor(); |
} |
ChangeCursor(); |
gun->Enable((WINDOW_WIDTH / 2) - 10, WINDOW_HEIGHT - 30, 10, 20, (WINDOW_WIDTH / 2) - 5, WINDOW_HEIGHT - 20); |
for (int i = 0; i < R_COUNT; i++) |
{ |
crosses[i] = new cCross(); |
rockets[i] = new cRocket(); |
} |
for (int i = 0; i < B_COUNT; i++) |
{ |
bombs[i] = new cBomb(); |
} |
for (int i = 0; i < R_COUNT + B_COUNT; i++) |
{ |
explodes[i] = new cExplode(); |
} |
health = 100; |
score = 0; |
rtlSrand(kos_GetTime()); |
DrawWindow(); |
kos_SetMaskForEvents(39); |
} |
void OnExit() |
{ |
kos_WriteTextToWindow(WINDOW_WIDTH / 2 - 35, WINDOW_HEIGHT / 2 - 10, 0, TEXT_COLOR, "Game Over", 9); |
kos_Pause(200); |
kos_ExitApp(); |
} |
/programs/games/rforces/trunk/rforces.h |
---|
0,0 → 1,19 |
/* Rocket Forces |
* Filename: rforces.h |
* Version 0.1 |
* Copyright (c) Serial 2007 |
*/ |
void DrawWindow(); |
void DrawBombs(); |
void DrawRocketsAndCrosses(); |
void DrawExplodes(); |
void OnMouseMove(); |
void OnLMBClick(); |
void OnRMBClick(); |
void ChangeCursor(); |
void Menu(); |
void NewGame(); |
void OnStart(); |
void OnExit(); |
/programs/games/rforces/trunk |
---|
Property changes: |
Added: tsvn:logminsize |
+5 |
\ No newline at end of property |
/programs/games/rforces/. |
---|
Property changes: |
Added: tsvn:logminsize |
+5 |
\ No newline at end of property |