uploaded graph

git-svn-id: svn://kolibrios.org@1005 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
barsuk 2009-01-28 15:13:38 +00:00
parent c526abcf3e
commit 9166e950b4
21 changed files with 3781 additions and 0 deletions

View File

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

View File

@ -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);
};

View File

@ -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 );

View File

@ -0,0 +1,389 @@
#include "func.h"
int SysColor = 0;
char debuf[50] = "";
// ïî÷åìó-òî íå áûëî â ñòàíäàðòíîé áèáëèîòåêå
void kos_DrawLine( Word x1, Word y1, Word x2, Word y2, Dword colour, Dword invert )
{
Dword arg1, arg2, arg3;
//
arg1 = ( x1 << 16 ) | x2;
arg2 = ( y1 << 16 ) | y2;
arg3 = (invert)?0x01000000:colour;
//
__asm{
mov eax, 38
mov ebx, arg1
mov ecx, arg2
mov edx, arg3
int 0x40
}
}
// ïîõèùåíî èç áèáëèîòåêè ê C--
void DrawRegion(Dword x,Dword y,Dword width,Dword height,Dword color1)
{
kos_DrawBar(x,y,width,1,color1); //ïîëîñà ãîð ñâåðõó
kos_DrawBar(x,y+height,width,1,color1); //ïîëîñà ãîð ñíèçó
kos_DrawBar(x,y,1,height,color1); //ïîëîñà âåðò ñëåâà
kos_DrawBar(x+width,y,1,height+1,color1); //ïîëîñà âåðò ñïðàâà
}
// äà, ýòî áàÿí
int atoi(const char* string)
{
int res=0;
int sign=0;
const char* ptr;
for (ptr=string; *ptr && *ptr<=' ';ptr++);
if (*ptr=='-') {sign=1;++ptr;}
while (*ptr >= '0' && *ptr <= '9')
{
res = res*10 + *ptr++ - '0';
}
if (sign) res = -res;
return res;
}
/*int abs(int n)
{
return (n<0)?-n:n;
}*/
double fabs(double x)
{
__asm fld x
__asm fabs
}
#define M_PI 3.14159265358979323846
double cos(double x)
{
__asm fld x
__asm fcos
}
double sin(double x)
{
__asm fld x
__asm fsin
}
int di(double x)
{
int a;
__asm fld x
__asm fistp a
return a;
}
double id(int x)
{
double a;
__asm fild x
__asm fstp a
return a;
}
bool isalpha(char c)
{
return (c==' ' || c=='\n' || c=='\t' || c=='\r');
}
// ýòà ôóíêöèÿ - âåëîñèïåä. íî ïðîùå áûëî íàïèñàòü ÷åì íàéòè.
double convert(char *s, int *len)
{
int i;
double sign,res, tail, div;
res = 0.0;
i=0;
while (s[i] && isalpha(s[i])) i++;
if (len) *len=i;
if (s[i] == '\0')
return ERROR_END;
sign=1.0;
if (s[i] == '-')
{
sign=-1.0;
i++;
}
while (s[i] && s[i] >= '0' && s[i] <= '9')
{
res *= 10.0;
res += id(s[i] - '0');
i++;
}
if (len) *len=i;
if (!s[i] || isalpha(s[i]))
return sign*res;
if (s[i] != '.' && s[i] != ',')
return ERROR;
i++;
if (len) *len=i;
if (!s[i])
return sign*res;
div = 1.0;
tail = 0.0;
while (s[i] && s[i] >= '0' && s[i] <= '9')
{
tail *= 10.0;
tail += id(s[i] - '0');
div *= 10.0;
i++;
}
res += tail/div;
if (len) *len=i;
return sign*res;
}
#define PREC 2
double double_tab[]={1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15};
// ýòî sprintf, óìåþùèé ôîðìàòèðîâàòü _òîëüêî_ âåùåñòâåííûå ÷èñëà (double) %f
void format( char *Str, int len, char* Format, ... )
{
int i, fmtlinesize, j, k, flag;
char c;
va_list arglist;
//
va_start(arglist, Format);
//
fmtlinesize = strlen( Format );
//
if( fmtlinesize == 0 ) return;
for (i = 0; i < len; i++)
Str[i] = 0;
//
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;
// auaia aauanoaaiiiai ?enea
case 'f':
// ii?aaaeeou ?enei oeo? ai oi?ee
double val, w;
int p;
val = va_arg(arglist, double);
if (val < 0.0)
{
Str[j++] = '-';
val = -val;
}
for (k = 0; k < 15; k++)
if (val < double_tab[k])
break;
if (val < 1.0)
{
Str[j++] = '0';
}
for (p = 1; p < k + 1; p++)
{
Str[j++] = '0' + di(val / double_tab[k - p] - 0.499) % 10;
}
Str[j++] = '.';
w = 0.1;
for (p = 0; p < 2; p++)
{
val-=floor(val);
Str[j++] = '0' + di(val / w - 0.499) % 10;
w /= 10.0;
}
//
default:
break;
}
}
//
Str[j] = 0;
}
void *memcpy(void *dst, const void *src, unsigned size)
{
while (size--)
*((char*)dst+size) = *((char*)src+size);
return dst;
}
int strcmp(const char *s1, const char *s2)
{
int i;
if (s1 == NULL)
if (s2 == NULL)
return 0;
else
return 1;
else
if (s2 == NULL)
return 1;
for (i = 0;;i++)
{
if (s1[i] == '\0')
if (s2[i] == '\0')
return 0;
else
return 1;
else
if (s2[i] == '\0')
return 1;
else
{
if (s1[i] != s2[i])
return 1;
}
}
return 0;
}
kol_struct_import* kol_cofflib_load(char *name)
{
//asm ("int $0x40"::"a"(68), "b"(19), "c"(name));
__asm
{
mov eax, 68
mov ebx, 19
mov ecx, name
int 0x40
}
}
void* kol_cofflib_procload (kol_struct_import *imp, char *name)
{
int i;
for (i=0;;i++)
if ( NULL == ((imp+i) -> name))
break;
else
if ( 0 == strcmp(name, (imp+i)->name) )
return (imp+i)->data;
return NULL;
}
unsigned kol_cofflib_procnum (kol_struct_import *imp)
{
unsigned i, n;
for (i=n=0;;i++)
if ( NULL == ((imp+i) -> name))
break;
else
n++;
return n;
}
void kol_cofflib_procname (kol_struct_import *imp, char *name, unsigned n)
{
unsigned i;
*name = 0;
for (i=0;;i++)
if ( NULL == ((imp+i) -> name))
break;
else
if ( i == n )
{
strcpy(name, ((imp+i)->name));
break;
}
}
/*
end of system part
*/
// ïîñêîëüêó ÿ ïîðòèðîâàë ñ äðåâíåãî äîñà...
void line( int x1, int y1, int x2, int y2)
{
kos_DrawLine(x1,y1,x2,y2,SysColor,0);
}
void outtextxy( int x, int y, char *s, int len)
{
kos_WriteTextToWindow(x,y,0,SysColor,s,len);
}
double textwidth( char *s, int len)
{
int i;
for (i = 0; i < len; i++)
if (s[i] == 0)
break;
return id(i * 6);
}
double textheight( char *s, int len)
{
return 8.0;
}
void setcolor( DWORD color)
{
SysColor = color;
}
void rectangle( int x1, int y1, int x2, int y2)
{
kos_DrawBar(x1,y1,x2-x1,y2-y1,SysColor);
}

View File

@ -0,0 +1,95 @@
#pragma once
#include "kosSyst.h"
#include "kosFile.h"
#include "MCSMEMM.H"
#include <stdarg.h>
#define ERROR 8888888888.9
#define ERROR_END 8888888888.7
#define PREC 2
typedef int HDC;
typedef int DWORD;
extern int SysColor;
extern char debuf[50];
typedef double (*function_t)(double);
typedef struct
{
double x, y;
} TCoord;
void kos_DrawLine( Word x1, Word y1, Word x2, Word y2, Dword colour, Dword invert);
void DrawRegion(Dword x,Dword y,Dword width,Dword height,Dword color1);
int atoi(const char* string);
double fabs(double x);
double cos(double x);
double sin(double x);
int di(double x);
double id(int x);
bool isalpha(char c);
double convert(char *s, int *len=NULL);
void format( char *Str, int len, char* Format, ... );
void line( int x1, int y1, int x2, int y2);
void outtextxy( int x, int y, char *s, int len);
void settextstyle( int a1, int a2, int a3);
double textwidth( char *s, int len);
double textheight( char *s, int len);
void setcolor( DWORD color);
void unsetcolor(HDC hdc);
void rectangle( int x1, int y1, int x2, int y2);
typedef struct
{
unsigned p00 ;
unsigned p04 ;
unsigned p08 ;
unsigned p12 ;
unsigned p16 ;
char p20 ;
char *p21 ;
} kol_struct70 ;
typedef struct
{
unsigned p00 ;
char p04 ;
char p05[3] ;
unsigned p08 ;
unsigned p12 ;
unsigned p16 ;
unsigned p20 ;
unsigned p24 ;
unsigned p28 ;
unsigned p32[2] ;
unsigned p40 ;
} kol_struct_BDVK ;
typedef struct
{
char *name ;
void *data ;
} kol_struct_import ;
kol_struct_import* kol_cofflib_load(char *name);
void* kol_cofflib_procload (kol_struct_import *imp, char *name);
unsigned kol_cofflib_procnum (kol_struct_import *imp);
void kol_cofflib_procname (kol_struct_import *imp, char *name, unsigned n);
int strcmp(const char* string1, const char* string2);

View File

@ -0,0 +1,682 @@
#include "func.h"
#include "parser.h"
#include "kolibri.h"
#include "use_library.h"
const char header[] = "Graph";
const char empty_text[] = "No function loaded. Type file name and press Enter. ";
const char er_file_not_found[] = "Cannot open file. ";
const char str_filename[]="Filename:";
const char str_editfile[]="Edit";
// íà÷àëüíûå ðàçìåðû
#define WND_W 400
#define WND_H 300
#define LIGHTGREEN 0xff0000
#define WHITE 0xffffff
#define BLACK 0x0
#define LIGHTBLUE 0x0000ff
#define LIGHTRED 0xff0000
// font colors
#define BIGFONTCOLOR BLACK
#define SMALLFONTCOLOR BLACK
#define THREE 3.0
// minimum space: 3 pixels
#define BIG_HEIGHT 4.0
#define SMALL_HEIGHT 2.0
#define TEXT_X 15.0
// numeric format for output
#define FORMAT "%f"
// format for two coords
#define FORMAT_COORD "(%f,%f)"
// special value to text if enough space
#define FORMAT_TEST "0.00"
#define DELTA_BIG 1.0
#define DELTA_SMALL 0.1
double *points;
Dword point_count = 0;
double x1,y1,x2,y2;
char *funct = NULL;
char edit_path[256];
//Dword editbox_y = WND_H - 16, editbox_w = WND_W - 70;
edit_box mybox = {0,9*8-5,WND_H - 16-32,0xffffff,0x6a9480,0,0x808080,0,99,(dword)&edit_path,0};
char *full_head;
char *HugeBuf = NULL;
//char fuck[64] = "$this is a fucking marker$";
// ïàðàìåòðû êîìàíäíîé ñòðîêè
char params[1024] = "_FIND_ME_";
/*
fucking piece of shit
*/
// constructor of TCoord
TCoord coord(double x, double y)
{
TCoord r;
r.x = x;
r.y = y;
return r;
}
// move and scale mathematical coords to fit screen coords
TCoord mat2Graf(TCoord c, TCoord scrMin, TCoord scrMax, TCoord mMin, TCoord mMax)
{
TCoord r;
if (c.x > mMax.x)
c.x = mMax.x;
if (c.x < mMin.x)
c.x = mMin.x;
if (c.y > mMax.y)
c.y = mMax.y;
if (c.y < mMin.y)
c.y = mMin.y;
r.x = (scrMax.x - scrMin.x) / (mMax.x - mMin.x) * (c.x - mMin.x) + scrMin.x;
r.y = (scrMax.y - scrMin.y) / (mMax.y - mMin.y) * (mMax.y - c.y) + scrMin.y;
return r;
}
// double-îáåðòêè
void line_d( double x1, double y1, double x2, double y2)
{
line(di(x1), di(y1), di(x2), di(y2));
}
void outtextxy_d( double x, double y, char * text, int len)
{
outtextxy(di(x), di(y), text, len);
}
// huge function to draw all the stuff except the function itself
void drawAxis( TCoord scrMin, TCoord scrMax, TCoord mMin, TCoord mMax)
{
TCoord cZero={0.0,0.0},
gMin, gMax, gZero, step;
TCoord from, to;
double i=0.0;
int j;
double xmin, xmin2, ymin, ymin2;
char buf[30]="";
// scr means Screen(bounding rect)
// m means Mathematical
// g means Graphic(real screen position)
//rtlDebugOutString("draw axis called\n");
//format(debuf, 30, "test: %f,%f,%f,%f\n", 123.45, 1.0, -0.9, 12.57);
//rtlDebugOutString(debuf);
gMin = mat2Graf(mMin, scrMin, scrMax, mMin, mMax);
gMax = mat2Graf(mMax, scrMin, scrMax, mMin, mMax);
gZero = mat2Graf(cZero, scrMin, scrMax, mMin, mMax);
// clear
// setcolor(WHITE);
//rectangle(di(gMin.x), di(gMin.y), di(gMax.x), di(gMax.y));
// ftopku
setcolor(BLACK);
// osy X
line_d(gMin.x, gZero.y ,gMax.x, gZero.y);
// osy Y
line_d(gZero.x, gMin.y, gZero.x, gMax.y);
// bounding rect
line_d(gMin.x, gMin.y, gMax.x, gMin.y);
line_d(gMin.x, gMax.y, gMax.x, gMax.y);
line_d(gMin.x, gMin.y, gMin.x, gMax.y);
line_d(gMax.x, gMin.y, gMax.x, gMax.y);
// coords of the rect : lower left
format(buf, 30, FORMAT_COORD, x1, y1);
//rtlDebugOutString(buf);
outtextxy_d(gMin.x, gMin.y + textheight(buf, 20), buf, 20);
// upper left
format(buf, 30, FORMAT_COORD, x1, y2);
outtextxy_d(gMin.x, gMax.y - textheight(buf, 20), buf, 20);
// lower right
format(buf, 30, FORMAT_COORD, x2, y1);
outtextxy_d(gMax.x - textwidth(buf, 20), gMin.y + textheight(buf, 20), buf, 20);
// upper right
format(buf, 30, FORMAT_COORD, x2, y2);
outtextxy_d(gMax.x - textwidth(buf, 20), gMax.y - textheight(buf, 20), buf, 20);
//rtlDebugOutString("some lines painted\n");
step.x = (mMax.x - mMin.x) / (scrMax.x - scrMin.x);
step.y = (mMax.y - mMin.y) / (scrMax.y - scrMin.y);
// round values
xmin = id(di((mMin.x / DELTA_BIG) * DELTA_BIG));
ymin = id(di((mMin.y / DELTA_BIG) * DELTA_BIG));
// (0,0)
if ((x1 * x2 <= 0.0) && (y1 * y2 <= 0.0))
{
from.x=0.0;
from.y=0.0;
from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
setcolor(BLACK);
format(buf, 30, FORMAT, 0.0);
outtextxy_d(from.x - textwidth(buf, 20), from.y + textheight(buf, 20), buf, 20);
}
// big marks on X
//settextstyle(0, 0, 1);
if (DELTA_BIG / step.x > THREE)
{
for (i = xmin; i <= mMax.x; i += DELTA_BIG)
{
if (i != 0.0)
{
from.x = i;
to.x = from.x;
from.y = -BIG_HEIGHT * step.y;
to.y = BIG_HEIGHT * step.y;
from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
to = mat2Graf(to, scrMin, scrMax, mMin, mMax);
setcolor(BLACK);
line_d(from.x, from.y, to.x, to.y);
// write number
format(buf, 30, FORMAT, i);
// if it fits in the GAP, then write it
if (from.y > scrMin.y && (DELTA_BIG > (textwidth(buf, 20) + 1.0) * step.x))
{
setcolor(BIGFONTCOLOR);
outtextxy_d(from.x - textwidth(buf, 20) / 2.0, to.y - textheight(buf, 20), buf, 20);
}
}
}
}
//rtlDebugOutString("big marks x painted\n");
// big marks on Y
if (DELTA_BIG / step.y > THREE)
{
for (i = ymin; i <= mMax.y; i += DELTA_BIG)
{
if (i != 0.0)
{
from.y = i;
to.y = from.y;
from.x = -BIG_HEIGHT * step.x;
to.x = BIG_HEIGHT * step.x;
from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
to = mat2Graf(to, scrMin, scrMax, mMin, mMax);
setcolor(BLACK);
line_d(from.x, from.y, to.x, to.y);
format(buf, 30, FORMAT, i);
if (from.x > scrMin.x && (DELTA_BIG > textheight(buf, 20) * step.y))
{
setcolor(BIGFONTCOLOR);
outtextxy_d(from.x + TEXT_X, to.y - textheight(buf, 20) / 2.0, buf, 20);
}
}
}
}
xmin2 = id(di(mMin.x / DELTA_SMALL)) * DELTA_SMALL;
ymin2 = id(di(mMin.y / DELTA_SMALL)) * DELTA_SMALL;
if (DELTA_SMALL / step.x > THREE)
{
j = di((( - xmin + xmin2 ) / DELTA_SMALL));
for (i = xmin2; i <= mMax.x; i += DELTA_SMALL, j++)
{
if (j % 10 == 0)
{
// we need to skip every tenth mark, to avoid overwriting big marks
j = 0;
continue;
}
from.x = i;
to.x = from.x;
from.y = -SMALL_HEIGHT * step.y;
to.y = SMALL_HEIGHT * step.y;
from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
to = mat2Graf(to, scrMin, scrMax, mMin, mMax);
setcolor(BLACK);
line_d(from.x, from.y, to.x, to.y);
format(buf, 30, FORMAT, i);
if (from.y > scrMin.y && (DELTA_SMALL > textwidth(buf, 20) * step.x))
{
setcolor(SMALLFONTCOLOR);
outtextxy_d(from.x - textwidth(buf, 20) / 2.0, to.y - textheight(buf, 20), buf, 20);
}
}
}
// finally small marks on Y
if (DELTA_SMALL / step.y > THREE)
{
//rtlDebugOutString("really small marks y painted\n");
j = di((( - ymin + ymin2) / DELTA_SMALL));
for (i = ymin2; i <= mMax.y; i += DELTA_SMALL, j++)
{
if (j % 10 == 0)
{
// we need to skip every tenth, to avoid overwriting
j = 0;
continue;
}
from.y = i;
to.y = from.y;
from.x = -SMALL_HEIGHT * step.x;
to.x = SMALL_HEIGHT * step.x;
from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
to = mat2Graf(to, scrMin, scrMax, mMin, mMax);
setcolor(BLACK);
line_d(from.x, from.y, to.x, to.y);
format(buf, 30, FORMAT, i);
if (from.x > scrMin.x && (DELTA_SMALL > textheight(buf, 20) * step.y))
{
setcolor(SMALLFONTCOLOR);
outtextxy_d(from.x + TEXT_X, from.y - textheight(buf, 20) / 2.0, buf, 20);
}
}
}
}
/*
ends fucking piece of shit
*/
void drawFunction( function_t fi, TCoord scrMin, TCoord scrMax,
TCoord mMin, TCoord mMax, DWORD color)
{
double x;
double y;
int firstPoint = 1;
TCoord p, p0 = {0.0, 0.0}, step;
drawAxis(scrMin, scrMax, mMin, mMax);
setcolor(color);
step.x = (mMax.x - mMin.x) / (scrMax.x - scrMin.x);
for (x = mMin.x; x < mMax.x; x += step.x)
{
y = fi(x);
// function is defined here and gets in the range
if (1) // òóò áûëî óñëîâèå, ÷òî ôóíêöèÿ ïðàâèëüíî âû÷èñëåíà
{
if ((y > mMin.y) && (y < mMax.y))
{
p = mat2Graf(coord(x, y), scrMin, scrMax, mMin, mMax);
// if it's our first point, only remember its coords
// otherwise, draw a line_d from prev to current
if (firstPoint == 0)
{
line_d(p0.x, p0.y, p.x, p.y);
}
else
firstPoint = 0;
p0 = p;
}
else // too big/small
{
firstPoint = 1;
}
}
else // no value
{
firstPoint = 1;
}
}
}
struct kosBDVK
{
Dword attrib;
Dword name_type;
Dword create_time;
Dword create_date;
Dword access_time;
Dword access_date;
Dword modify_time;
Dword modify_date;
Dword size_low;
Dword size_high;
};
// èòîãîâàÿ âåðñèÿ ÷èòàëêè òåêñòîâûõ ôàéëîâ
int load_points3()
{
kosFileInfo fileInfo;
kosBDVK bdvk;
int filePointer = 0;
Dword count;
int i,j,k;
double d;
Dword filesize, num_number;
double *p2;
if (edit_path[0] == '\0')
return 0;
// get file size
strcpy(fileInfo.fileURL,edit_path);
fileInfo.OffsetLow = 0;
fileInfo.OffsetHigh = 0;
fileInfo.dataCount = 0;
fileInfo.rwMode = 5;
fileInfo.bufferPtr = (Byte *)&bdvk;
Dword rr = kos_FileSystemAccess( &(fileInfo) ); // â CKosFile íåò îïðåäåëåíèÿ ðàçìåðà
sprintf(debuf, "getsize: %U\n", rr);
rtlDebugOutString(debuf);
if (rr != 0)
{
kos_WriteTextToWindow(10,10,0,0x00,(char*)er_file_not_found,strlen(er_file_not_found));
return 0;
}
filesize = bdvk.size_low;
num_number = filesize / 2;
HugeBuf = (char *)allocmem(filesize + 1); // ðàçáèðàåì êàê ñòðîêó, îòñþäà òåðìèíàòîð \0
for (i=0;i<filesize+1;i++)
HugeBuf[i] = 0;
strcpy(fileInfo.fileURL,edit_path);
fileInfo.OffsetLow = 0;
fileInfo.OffsetHigh = 0;
fileInfo.dataCount = filesize;
fileInfo.rwMode = 0;
fileInfo.bufferPtr = (Byte *)HugeBuf;
rr = kos_FileSystemAccess( &(fileInfo) ); // êàêàÿ-òî ïðîáëåìà ñ hands.dll, CKosFile íå ðàáîòàë
sprintf(debuf, "read3: %U\n", rr);
rtlDebugOutString(debuf);
strcpy(full_head, header);
strcpy(full_head+strlen(full_head), " - ");
strcpy(full_head+strlen(full_head), edit_path); // bad code
// à òåïåðü ðàçîáðàòüñÿ â ýòîì
i=0;
k=0;
while (i < filesize)
{
while (isalpha(HugeBuf[i]) && i<filesize) i++;
if (i == filesize) break;
if (k==4 && HugeBuf[i] == '=')
{
//sprintf(debuf,"function: %S",HugeBuf + i);
//rtlDebugOutString(debuf);
// we have a function here
//HugeBuf[0] = ' ';
funct = HugeBuf + i + 1;
strcpy(full_head+strlen(full_head), ". Function y=");
strcpy(full_head+strlen(full_head), funct);
return 1;
}
d = convert(HugeBuf+i, &j);
if (d == ERROR)
{
sprintf(debuf, "Error in input file, byte %U, count %U\n", i, k);
rtlDebugOutString(debuf);
kos_WriteTextToWindow(10, 10, 0, 0x00, (char*)debuf, strlen(debuf));
return 0;
}
if (d == ERROR_END)
{
rtlDebugOutString("EOF :)!\n");
break;
}
i+=j;
switch (k)
{
case 0:
x1=d;
break;
case 1:
x2=d;
break;
case 2:
y1=d;
break;
case 3:
y2=d;
break;
default:
{
if (p2 == NULL)
p2 = (double *)allocmem(num_number * 8);
p2[k-4]=d;
}
}
k++;
}
// format(debuf, 30, "(%f,%f)-(%f,%f)",x1,y1,x2,y2);
// rtlDebugOutString(debuf);
point_count=(k - 4)/2;
//
points = (double *)allocmem(point_count * 2 * 8);
for (i = 0; i < point_count * 2; i++)
points[i] = p2[i];
freemem(p2);
// sprintf(debuf, "count: %U\n", point_count);
// rtlDebugOutString(debuf);
sprintf(debuf, ". Number of points: %U.", point_count);
strcpy(full_head+strlen(full_head), debuf);
freemem(HugeBuf);
HugeBuf = NULL;
return 1;
}
void LaunchTinypad()
{
kosFileInfo fileInfo;
strcpy(fileInfo.fileURL,"/sys/tinypad");
fileInfo.OffsetLow = 0;
fileInfo.OffsetHigh = (Dword)edit_path;
fileInfo.rwMode = 7; // launch
kos_FileSystemAccess(&fileInfo);
}
// âû÷èñëèòü çàäàííóþ ôóíêöèþ èëè êóñî÷íî-ëèíåéíóþ ìåæäó òî÷êàìè
double fu(double x)
{
int i;
double res;
if (funct)
{
set_exp(funct,x);
get_exp(&res); // ïàðñèòü äëÿ êàæäîãî çíà÷åíèÿ õ? äà ÿ ñ óìà ñîøåë.
return res;
}
if (point_count == 0)
{
return 0.0;
}
if (x <= points[0])
return points[1];
if (x >= points[(point_count-1) * 2])
return points[(point_count-1) * 2 + 1];
for (i = 0; i < point_count; i++)
{
if ((x >= points[2 * i]) && (x < points[2 * (i + 1)]))
break;
}
return (x - points[2 * i]) / (points[2 * (i + 1)] - points[2 * i])
* (points[2 * (i + 1) + 1] - points[2 * i + 1]) + points[2 * i + 1];
}
void draw_window(void)
{
char str[80];
int i;
double xx0=0.0, yy0=0.0, xx,yy;
sProcessInfo info;
Dword wi, he;
void *p;
for (i = 0; i < 1024; i++)
info.rawData[i] = 0;
kos_ProcessInfo(&info, 0xFFFFFFFF);
p = info.rawData + 42; // magic
wi = *(Dword *)(p);
he = *(Dword *)((Byte *)p + 4);
if (wi == 0)
wi = WND_W;
if (he == 0)
he = WND_H;
mybox.top = he - 45;
mybox.width = wi - mybox.left - 80;
// start redraw
kos_WindowRedrawStatus(1);
kos_DefineAndDrawWindow(10,40,WND_W,WND_H,
0x33,0xFFFFFF,0,0,(Dword)full_head);
rtlDebugOutString("entering draw_window\n");
if (point_count == 0 && funct == NULL)
{
kos_WriteTextToWindow((wi - 6 * strlen(empty_text))/2,he/2,0,0x000000,(char *)empty_text,strlen(empty_text));
}
else
{
drawFunction(&fu, coord(10, 20), coord(id(wi - 20), id(he - 70)),
coord(x1,y1), coord(x2,y2), 0x00ff0000);
}
kos_WriteTextToWindow(4, mybox.top + 4, 0, 0, (char*)str_filename, strlen(str_filename));
if ((void*)edit_box_draw != NULL)
edit_box_draw((DWORD)&mybox);
kos_DefineButton(wi - 70, mybox.top, 50, 12, 5, 0xc0c0c0);
kos_WriteTextToWindow(wi - 58, mybox.top + 4, 0, 0, (char*)str_editfile, strlen(str_editfile));
// end redraw
kos_WindowRedrawStatus(2);
}
void kos_Main()
{
kos_InitHeap();
full_head = (char*)allocmem(300);
strcpy(full_head, "Graph");
load_edit_box();
if (params[0]) // fuck[0] for debug
{
rtlDebugOutString("launched with params");
rtlDebugOutString((char*)params);
strcpy(edit_path, params);
//rtlDebugOutString((char*)edit_path);
load_points3();
}
rtlDebugOutString("data loaded.\n");
draw_window();
for (;;)
{
edit_box_mouse((dword)&mybox);
switch (kos_WaitForEvent())
{
case 1:
draw_window();
break;
case 2:
// key pressed, read it
Byte keyCode;
kos_GetKey(keyCode);
switch (keyCode)
{
case 0x0D:
if (HugeBuf!=NULL)
{
//sprintf(debuf, "freemem: HugeBuf = %X", HugeBuf);
//rtlDebugOutString(debuf);
freemem((void*)HugeBuf); // ÷òî çà áàã - ïîíÿòü íå ìîãó.
HugeBuf = NULL;
funct = NULL;
}
if (points!=NULL)
{
//sprintf(debuf, "freemem: points = %X", points);
//rtlDebugOutString(debuf);
freemem((void*)points); // è òóò. íó íå îáðàùàþñü ÿ ê ýòîìó óêàçàòåëþ, òîëüêî ïàìÿòü â íåãî
// ïîòîì ñíîâà âûäåëÿþ
points = NULL;
}
point_count = 0;
kos_DrawBar(10,10,200,20,0xFFFFFF); // ôîí äëÿ ñîîáùåíèé îá îøèáêàõ
if (load_points3())
draw_window();
break;
default:
{
__asm
{
mov ah, keyCode
}
edit_box_key((dword)&mybox);
}
}
break;
case 3:
// button pressed; we have only one button, close
Dword button;
kos_GetButtonID(button);
if (button == 1)
kos_ExitApp();
else if (button == 5)
{
LaunchTinypad();
}
}
}
}

View File

@ -0,0 +1,147 @@
# Microsoft Developer Studio Project File - Name="hello" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=hello - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "hello.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "hello.mak" CFG="hello - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "hello - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /Zp1 /W3 /vd0 /O2 /YX /FD /c
# SUBTRACT CPP /X
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "NDEBUG"
# ADD RSC /l 0x419 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 /nologo /base:"0" /entry:"crtStartUp" /subsystem:windows /machine:I386 /nodefaultlib /align:16
# SUBTRACT LINK32 /pdb:none
# Begin Custom Build
InputPath=.\Release\hello.exe
SOURCE="$(InputPath)"
"hello.kex" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
pe2kos Release\hello.exe hello.kex _FIND_ME_
# End Custom Build
# Begin Target
# Name "hello - Win32 Release"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\func.cpp
# End Source File
# Begin Source File
SOURCE=.\hello.cpp
# End Source File
# Begin Source File
SOURCE=.\kolibri.cpp
# End Source File
# Begin Source File
SOURCE=.\KosFile.cpp
# End Source File
# Begin Source File
SOURCE=.\kosSyst.cpp
# End Source File
# Begin Source File
SOURCE=.\math2.cpp
# End Source File
# Begin Source File
SOURCE=.\mcsmemm.cpp
# End Source File
# Begin Source File
SOURCE=.\parser.cpp
# End Source File
# Begin Source File
SOURCE=.\string.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\func.h
# End Source File
# Begin Source File
SOURCE=.\kolibri.h
# End Source File
# Begin Source File
SOURCE=.\KosFile.h
# End Source File
# Begin Source File
SOURCE=.\kosSyst.h
# End Source File
# Begin Source File
SOURCE=.\MCSMEMM.H
# End Source File
# Begin Source File
SOURCE=.\parser.h
# End Source File
# Begin Source File
SOURCE=.\string.h
# End Source File
# Begin Source File
SOURCE=.\use_library.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "hello"=".\hello.dsp" - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@ -0,0 +1 @@

View File

View File

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

View File

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

View File

@ -0,0 +1,46 @@
=== v 0.2 === 6.06.08
формат входных данных(файл graph.cvs)
а) если заданы точки и требуется провести кусочно-линейную функцию
x1 y1 x2 y2 ; границы области построения
x y
x y ; значения
...
б) если задана функция
x1 y1 x2 y2 ; границы области построения
=формула
где числа записываются в формате ###,### или ###.###, например, допустимы следующие записи:
1
1.2
1.
.6
-543.1463
и недопустимы:
1e2
+5
формула - выражение, составленное из чисел, переменной x, операций + - * / и функций: sin, cos, tg ,ctg (остальные в проекте).
примеры:
=sin(x)*x
=x/2
=cos(sin(cos(x)+1)+1)+1
=1/x
в случае ошибки вычисления(не найдена функция, деление на 0) программа не выводит никаких сообщений, а либо вылетает, либо считает результат недопустимой операции нулевым.
== v 0.3 ==== 7.06.08
добавлено много чего из интерфейса.
функции: log, exp, sqrt.
== v 0.4 ===== 9.06.08
улучшен ввод имени файла, обработка ошибок, фиксы утечек памяти.

View File

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

View File

@ -0,0 +1,354 @@
// 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 );
}
Byte *allocmem( Dword reqsize )
{
__asm
{
mov eax, 68
mov ebx, 12
mov ecx, reqsize
int 0x40
}
}
Dword freemem( void *vaddress )
{
__asm
{
mov eax, 68
mov ebx, 13
mov ecx, vaddress
int 0x40
}
}
/*
//
Dword mmMutex = FALSE;
MemBlock *rootfree = NULL;
MemBlock *rootuser = NULL;
bool mmInitialized = false;
Byte *mmHeapTop = NULL;
//
Byte * AllocMemFromSystem( Dword reqSize )
{
Byte *result;
sProcessInfo pInfo;
//
if ( mmInitialized )
{
result = mmHeapTop;
}
else
{
//
kos_ProcessInfo( &pInfo );
//
result = (Byte *)(pInfo.processInfo.used_memory + 1);
//
mmInitialized = true;
}
//
if ( ! kos_ApplicationMemoryResize( ((Dword)result) + reqSize ) )
{
result = NULL;
}
//
mmHeapTop = result + reqSize;
//
return result;
}
//
Byte *allocmem( Dword reqsize )
{
MemBlock *BlockForCheck;
MemBlock *LastKnownGood;
Dword tail;
Byte *address;
//ïîäðîâíÿåì ðàçìåð
if( ( tail = reqsize % SIZE_ALIGN ) != 0 )
{
reqsize += SIZE_ALIGN - tail;
}
LastKnownGood = NULL;
// æä¸ì îñâîáîæäåíèÿ ìüþòåêñà
while ( rtlInterlockedExchange( &mmMutex, TRUE ) )
{
//
kos_Pause( 1 );
}
//èùåì ïîäõîäÿùèé ñâîáîäíûé áëîê
if( rootfree != NULL )
{
for ( BlockForCheck = rootfree; ; BlockForCheck = BlockForCheck->Next )
{
if ( BlockForCheck->Size >= reqsize )
{
//íàøëè
if ( LastKnownGood != NULL )
{
if ( LastKnownGood->Size >= BlockForCheck->Size )
LastKnownGood = BlockForCheck;
}
else
LastKnownGood = BlockForCheck;
if ( LastKnownGood->Size == reqsize )
break;
}
if ( BlockForCheck->Next == NULL )
break;
}
}
if ( LastKnownGood != NULL )
{
//ïðîâåðèì íàéäåííûé áëîê íà âîçìîæíîñòü äåëåíèÿ
tail = LastKnownGood->Size - reqsize;
if ( tail >= ( sizeof(MemBlock) + SIZE_ALIGN ) )
{
//áóäåì ðàçáèâàòü
BlockForCheck = (MemBlock *)( ( (Byte *)LastKnownGood ) + tail );
BlockForCheck->Size = reqsize;
//âñòàâèì çàíÿòûé áëîê â íà÷àëî ñïèñêà çàíàòûõ áëîêîâ
if( rootuser != NULL )
{
BlockForCheck->Next = rootuser;
rootuser->Previous = BlockForCheck;
BlockForCheck->Previous = NULL;
rootuser = BlockForCheck;
}
else
{
rootuser = BlockForCheck;
BlockForCheck->Next = NULL;
BlockForCheck->Previous = NULL;
}
//èçìåíèì ðàçìåð îñòàâøåéñÿ ÷àñòè
LastKnownGood->Size = tail - sizeof(MemBlock);
address = ( (Byte *)BlockForCheck ) + sizeof(MemBlock);
// îòïóñòèì ìüþòåêñ
rtlInterlockedExchange( &mmMutex, FALSE );
return address;
}
else
{
//ïåðåìåñòè áëîê èç î÷åðåäè ñâîáîäíûõ â íà÷àëî î÷åðåäè çàíÿòûõ
//ñíà÷àëà âûêèíåì åãî èç î÷åðåäè ñâîáîäíûõ
if ( LastKnownGood->Previous != NULL )
{
LastKnownGood->Previous->Next = LastKnownGood->Next;
}
else
{
//áëîê ñòîèò â íà÷àëå î÷åðåäè
rootfree = LastKnownGood->Next;
}
if( LastKnownGood->Next != NULL )
{
LastKnownGood->Next->Previous = LastKnownGood->Previous;
}
//òåïåðü âñòàâèì åãî â î÷åðåäü çàíÿòûõ
if( rootuser != NULL )
{
LastKnownGood->Next = rootuser;
rootuser->Previous = LastKnownGood;
LastKnownGood->Previous = NULL;
rootuser = LastKnownGood;
}
else
{
rootuser = LastKnownGood;
LastKnownGood->Next = NULL;
LastKnownGood->Previous = NULL;
}
//
address = ( (Byte *)LastKnownGood ) + sizeof(MemBlock);
// îòïóñòèì ìüþòåêñ
rtlInterlockedExchange( &mmMutex, FALSE );
return address;
}
}
else
{
//íàäî ïîëó÷èòü åù¸ êóñî÷åê ïàìÿòè
LastKnownGood = (MemBlock *)AllocMemFromSystem( reqsize + sizeof(MemBlock) );
//
if( LastKnownGood != NULL )
{
LastKnownGood->Size = reqsize;
//òåïåðü âñòàâèì åãî â î÷åðåäü çàíÿòûõ
if( rootuser != NULL )
{
LastKnownGood->Next = rootuser;
rootuser->Previous = LastKnownGood;
LastKnownGood->Previous = NULL;
rootuser = LastKnownGood;
}
else
{
rootuser = LastKnownGood;
LastKnownGood->Next = NULL;
LastKnownGood->Previous = NULL;
}
address = ( (Byte *)LastKnownGood ) + sizeof(MemBlock);
// îòïóñòèì ìüþòåêñ
rtlInterlockedExchange( &mmMutex, FALSE );
return address;
}
}
// îòïóñòèì ìüþòåêñ
rtlInterlockedExchange( &mmMutex, FALSE );
//
rtlDebugOutString( "allocmem failed." );
kos_ExitApp();
//
return NULL;
}
//
Dword freemem( void *vaddress )
{
Dword result;
Byte *checknext, *address = (Byte *)vaddress;
// æä¸ì îñâîáîæäåíèÿ ìüþòåêñà
while ( rtlInterlockedExchange( &mmMutex, TRUE ) )
{
//
kos_Pause( 1 );
}
MemBlock *released = (MemBlock *)( address - sizeof(MemBlock) );
result = released->Size;
//óáèðàåì áëîê èç ñïèñêà çàíÿòûõ
if ( released->Previous != NULL )
{
released->Previous->Next = released->Next;
}
else
{
rootuser = released->Next;
}
if ( released->Next != NULL )
{
released->Next->Previous = released->Previous;
}
//çàêèíåì òåïåðü ýòîò áëîê â ñïèñîê ñâîáîäíûõ
released->Next = rootfree;
released->Previous = NULL;
rootfree = released;
if ( released->Next != NULL )
{
released->Next->Previous = released;
}
//òåïåðü ïîèùåì ñìåæíûå ñâîáîäíûå áëîêè
checknext = (Byte *)(rootfree) + ( rootfree->Size + sizeof(MemBlock) );
//
for ( released = rootfree->Next; released != NULL; released = released->Next )
{
if ( checknext == (Byte *)released )
{
//ñîáèðàåì áëîêè âìåñòå
//ñíà÷àëà âûêèíåì èç î÷åðåäè ñâîáîäíûõ
released->Previous->Next = released->Next;
if( released->Next != NULL )
{
released->Next->Previous = released->Previous;
}
//òåïåðü óâåëè÷èì ðàçìåð êîðíåâîãî áëîêà
rootfree->Size += released->Size + sizeof(MemBlock);
break;
}
}
//åñëè íàäî, ïîèùåì áëîêè ïåðåä òåêùèì.
checknext = (Byte *)(rootfree);
//
if ( released == NULL )
{
for ( released = rootfree->Next; released != NULL; released = released->Next )
{
if ( checknext == (Byte *)released + ( released->Size + sizeof(MemBlock) ) )
{
//ñîáèðàåì áëîêè âìåñòå
//óâåëè÷èì ðàçìåð áëîêà
released->Size += rootfree->Size + sizeof(MemBlock);
//òåïåðü âûêèíåì èç î÷åðåäè ñâîáîäíûõ
released->Previous->Next = released->Next;
if ( released->Next != NULL )
{
released->Next->Previous = released->Previous;
}
//è çàêèíåì åãî â íà÷àëî î÷åðåäè âìåñòî ïðèñîåäèí¸ííîãî áëîêà èç êîðíÿ ñïèñêà
if ( rootfree->Next != NULL )
{
rootfree->Next->Previous = released;
}
released->Next = rootfree->Next;
released->Previous = NULL;
rootfree = released;
break;
}
}
}
// îòïóñòèì ìüþòåêñ
rtlInterlockedExchange( &mmMutex, FALSE );
return result;
}
*/

View File

@ -0,0 +1,493 @@
#include "func.h"
#include "parser.h"
// token types
#define DELIMITER 1
#define VARIABLE 2
#define NUMBER 3
#define FUNCTION 4
#define FINISHED 10
// error codes
#define ERR_BADFUNCTION -1
#define ERR_BADNUMER -2
#define ERR_GENERAL -3
#define ERR_NOBRACKET -4
#define ERR_BADVARIABLE -5
#define ERR_OVERFLOW -6
double tg(double d)
{
return sin(d) / cos(d);
}
double ctg(double d)
{
return cos(d) / sin(d);
}
double exp(double x)
{
__asm {
fld x
FLDL2E
FMUL
FLD st(0)
FLD1
FXCH
FPREM
F2XM1
fadd
FSCALE
FSTP st(1)
}
}
double log(double x)
{
//return 0.0;
__asm {
FLD1
FLD x
FYL2X
FLDLN2
FMUL
}
}
double sqrt(double x)
{
__asm {
fld x
fsqrt
}
}
double atan(double x)
{
return 0.0; // â ëîì
}
double pow(double x, double y)
{
return 0.0; // â ëîì, ïóñêàé ñ÷èòàþò ÷åðåõ exp è log
}
// represents general mathematical function
typedef double(*matfunc)(double);
// used to link function name to the function
typedef struct
{
char name[10];
matfunc f;
} func;
// the list of functions
const int max_func = 12;
func functions[max_func] =
{
"", NULL,
"sin", &sin,
"cos", &cos,
"exp", &exp,
"sqrt", &sqrt,
"log", &log,
"tg", &tg,
"ctg", &ctg,
"arcsin", &asin,
"arccos", &acos,
"arctg", &atan,
"abs", &fabs
};
// all delimiters
const char *delim="+-*^/%=;(),><"; // not bad words
// structure for most parser functions
char token[80];
int token_type;
char *prog;
double x_value;
int code; // error code
int isdelim(char c)
{
//return strchr(delim, c) != 0;
for (int i = 0; i < 14; i++)
if (c == delim[i])
return 1;
return 0;
}
int isdigit(char c)
{
return (c >= '0' && c <= '9');
}
int isalpha2(char c)
{
return ((c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z'));
}
int iswhite(char c)
{
return (c==' ' || c=='\t');
}
void serror(int code)
{
::code = code;
// longjmp(j, code);
}
void set_exp(char *exp, double x)
{
prog = exp;
x_value = x;
}
int get_token()
{
int tok;
char *temp;
(token_type) = 0;
tok = 0;
temp = (token);
if (*(prog) == '\0')
{
*(token) = 0;
tok = FINISHED;
return ((token_type) = DELIMITER);
}
while (iswhite(*(prog))) ++(prog);
if (isdelim(*(prog)))
{
*temp = *(prog);
(prog)++;
temp++;
*temp = 0;
return ((token_type) = DELIMITER);
}
if (isdigit(*(prog)))
{
while (!isdelim(*(prog)))
*temp++=*(prog)++;
*temp = '\0';
return ((token_type) = NUMBER);
}
if (isalpha2(*(prog)))
{
while (!isdelim(*(prog)))
*temp++=*(prog)++;
(token_type) = VARIABLE;
}
*temp = '\0';
if ((token_type) == VARIABLE)
{
tok = look_up((token));
if (tok)
(token_type) = FUNCTION;
}
return (token_type);
}
int sign(double d)
{
if (d > 0.0)
return 1.0;
if (d < 0.0)
return -1.0;
return 0.0;
}
void putback()
{
char *t;
t = (token);
for (;*t;t++)
(prog)--;
}
int get_exp(double *hold)
{
int res;
code = 0;
// if (res = setjmp(j) != 0)
// return code;
get_token();
if (!*(token))
{
return 0;
}
level2( hold);
putback();
return 0;
}
void level2(double *hold)
{
char op;
double h;
level3( hold);
while ((op=*(token)) == '+' || op == '-')
{
get_token();
level3( &h);
arith(op, hold, &h);
}
}
void level3(double *hold)
{
char op;
double h;
level4( hold);
while ((op=*(token)) == '*' || op == '/' || op == '%')
{
get_token();
level4( &h);
arith( op, hold, &h);
}
}
void level4(double *hold)
{
double h;
level5( hold);
if (*(token) == '^')
{
get_token();
level5( &h);
arith( '^', hold, &h);
}
}
void level5(double *hold)
{
char op;
op = 0;
if (((token_type) == DELIMITER) && *(token) == '+' || *(token) == '-')
{
op = *(token);
get_token();
}
level6( hold);
if (op)
unary(op, hold);
}
void level6(double *hold)
{
if ((*(token) == '(') && ((token_type) == DELIMITER))
{
get_token();
level2( hold);
if (*(token) != ')')
serror( ERR_NOBRACKET);
get_token();
}
else
primitive( hold);
}
void calc_function(double *hold)
{
double d;
int i;
i = look_up(token);
if (i == 0)
serror(ERR_BADFUNCTION); // error
get_token();
if (*(token) != '(')
serror(ERR_NOBRACKET); // error
get_token();
level2(hold);
get_token();
d = functions[i].f(*hold);
*hold = (functions[i].f)(*hold);
// else
// serror( ERR_OVERFLOW);
}
void primitive(double *hold)
{
switch (token_type)
{
case VARIABLE:
*hold = find_var(token);
get_token();
return;
case NUMBER:
//
//*hold = atof((token));
//if (sscanf(token, "%lf", hold) != 1)
*hold = convert(token);
if (*hold == ERROR)
serror( ERR_BADNUMER);
get_token();
return;
case FUNCTION:
calc_function( hold);
return;
default: // error
return;
}
}
void arith(char op, double *r, double *h)
{
double t;
switch(op)
{
case '-':
*r = *r - *h;
break;
case '+':
*r = *r + *h;
break;
case '*':
*r = *r * *h;
break;
case '/':
if (*h == 0)
serror( ERR_OVERFLOW);
else
*r = (*r) / (*h);
break;
case '%':
t = (*r) / (*h);
*r = *r - (t * (*h));
break;
case '^':
*r = pow(*r, *h);
break;
}
}
void unary(char op, double *r)
{
if (op == '-')
*r = -(*r);
}
double find_var(char *s)
{
//return 0; // not imp
//int i;
//for (i = 0; i < kvar; i++)
// if (strcmp(vars[i].name, s) == 0)
// return vars[i].value;
if (s[1] == '\0' && (s[0] == 'x' || s[0] == 'X'))
//if (strcmp(s,"x") == 0 || strcmp(s,"X") == 0)
return x_value;
serror( ERR_BADVARIABLE);
return 0; // to make compiler very happy
//printf("\nPlease enter value for variable \"%s\": ", s);
//scanf("%lf", &vars[kvar].value);
//strcpy(vars[kvar].name, s);
//kvar++;
//return vars[kvar - 1].value;
}
bool strcmp(char *s1, char *s2)
{
int i;
for (i = 0;;i++)
{
if (s1[i] == '\0')
if (s2[i] == '\0')
return 0;
else
return 1;
else
if (s2[i] == '\0')
return 1;
else
{
if (s1[i] != s2[i])
return 1;
}
}
}
int look_up(char *s)
{
int i;
for (i = 0; i < max_func; i++)
if (strcmp(s, functions[i].name) == 0)
return i;
return 0; // search command/function name
}
/*
void delete_white(char *buf)
{
int len = strlen(buf);
char *d = (char *)malloc(len + 1);
char *t = buf;
strcpy(d, buf);
d[len] = '\0';
int i;
for (i = 0; i < len; i++)
if (!iswhite(d[i]))
*t++=d[i];
*t++='\0';
free(d);
}
*/
/*
void main(void)
{
= (parser_struct)malloc(sizeof(parser_struct));
double a;
char buffer[256];
printf("Enter expression: ");
memset(buffer, 0, 256);
gets(buffer);
prog = buffer;
delete_white(buffer);
a = 0;
x_value = 3;
get_exp( &a);
printf("result: %lg\n", a);
getch();
}
*/

View File

@ -0,0 +1,29 @@
void set_exp(char *exp, double x);
// puts the token back to line
void putback(double *hold);
// gets the expression. This function is used externally
int get_exp(double *hold);
// works with +-
void level2(double *hold);
// works with */%
void level3(double *hold);
// works with ^
void level4(double *hold);
// works with ()
void level5(double *hold);
// works with elementary tokens
void level6(double *hold);
// gets value of number, function or variable
void primitive(double *hold);
// performs arithmetical operation
void arith(char op, double *r, double *h);
// performs unary (one-operand) operation
void unary(char op, double *r);
// gets variable value by name
double find_var(char *s);
// stops execution of parser and return error code
void serror(int code);
// checks the function table to see if such a function exists
int look_up(char *s);

View File

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

View File

@ -0,0 +1,111 @@
#include "string.h"
void* memset(void *mem, int c, unsigned size)
{
unsigned i;
for ( i = 0; i < size; i++ )
*((char *)mem+i) = (char) c;
return NULL;
}
void* memcpy(void *dst, const void *src, unsigned size)
{
unsigned i;
for ( i = 0; i < size; i++)
*((char *)dst+i) = *((char *)src+i);
return NULL;
}
void strcat(char strDest[], char strSource[])
{
int i, j;
i = j = 0;
while (strDest[i] != '\0')
i++;
while ((strDest[i++] = strSource[j++]) != '\0')
;
}
int strcmp(const char* string1, const char* string2)
{
while (1)
{
if (*string1<*string2)
return -1;
if (*string1>*string2)
return 1;
if (*string1=='\0')
return 0;
string1++;
string2++;
}
}
void strcpy(char strDest[], const char strSource[])
{
unsigned i;
i = 0;
while ((strDest[i] = strSource[i]) != '\0')
i++;
}
char* strncpy(char *strDest, const char *strSource, unsigned n)
{
unsigned i;
if (! n )
return strDest;
i = 0;
while ((strDest[i] = strSource[i]) != '\0')
if ( (n-1) == i )
break;
else
i++;
return strDest;
}
int strlen(const char* string)
{
int i;
i=0;
while (*string++) i++;
return i;
}
char* strchr(const char* string, int c)
{
while (*string)
{
if (*string==c)
return (char*)string;
string++;
}
return (char*)0;
}

View File

@ -0,0 +1,12 @@
#define NULL ((void*)0)
void* memset(void *mem, int c, unsigned size);
void* memcpy(void *dst, const void *src, unsigned size);
void strcat(char strDest[], char strSource[]);
int strcmp(const char* string1, const char* string2);
//void strcpy(char strDest[], const char strSource[]);
char* strncpy(char *strDest, const char *strSource, unsigned n);
int strlen(const char* string);
char *strchr(const char* string, int c);

View File

@ -0,0 +1,58 @@
typedef Dword dword;
dword am__ = 0x0;
dword bm__ = 0x0;
char aEdit_box_draw[9] = "edit_box";
char aEdit_box_key[13] = "edit_box_key";
char aEdit_box_mouse[15] = "edit_box_mouse";
char aVersion_ed[11] = "version_ed";
char aCheck_box_draw [15] = "check_box_draw";
char aCheck_box_mouse [16] = "check_box_mouse";
char aVersion_ch [11] = "version_ch";
char aOption_box_draw [16] = "option_box_draw";
char aOption_box_mouse[17] = "option_box_mouse";
char aVersion_op [11] = "version_op" ;
//BOX_LIB
typedef dword __stdcall dword_func(dword);
//typedef dword __stdcall dword3_func(dword,dword,dword);
dword_func *edit_box_draw =(dword_func*) &aEdit_box_draw;
dword_func *edit_box_key =(dword_func*) &aEdit_box_key;
dword_func *edit_box_mouse =(dword_func*) &aEdit_box_mouse;
//char lib_path[] = "/sys/lib/box_lib.obj";
char lib_path[] = "/sys/lib/box_lib.obj";
dword lib_path_addr = (dword)lib_path;
dword dummy = 0;
struct edit_box{
dword width, left, top, color, shift_color, focus_border_color, blur_border_color,
text_color, max, text, flags, size, pos, offset, cl_curs_x, cl_curs_y, shift, shift_old;
};
void load_edit_box()
{
kol_struct_import *k = kol_cofflib_load(lib_path);
if (k == NULL)
{
sprintf(debuf, "cannot load library %S", lib_path);
rtlDebugOutString(debuf);
return;
}
edit_box_draw = (dword_func*)kol_cofflib_procload(k, "edit_box");
edit_box_key = (dword_func*)kol_cofflib_procload(k,"edit_box_key");
edit_box_mouse = (dword_func*)kol_cofflib_procload(k,"edit_box_mouse");
kos_SetMaskForEvents(0x27);
if (edit_box_draw == NULL || edit_box_key == NULL || edit_box_mouse == NULL)
rtlDebugOutString("some of functions cannot be loaded!");
}