//******************************************************//
// //
//******************************************************//
program WIN32DLL 'BASIC PLUGIN';
#include 'zirplug/framework.zir';
#include 'smm32.zir';
//////////////////////////////
const strLoaded = 'Basic plugin has loaded!';
function H_strlen(char* str)
{
Eax = nil;
Ebx = str;
while(char[Ebx] != 0)
{
Ebx++;
Eax++;
}
}
function H_strcpy(Dword dst,src)
{
Eax = dst;
Edx = src;
push Eax;
BL = [Edx];
while ( BL != 0)
{
[Eax] = BL;
Eax++; Edx++;
BL = [Edx];
}
[Eax] = 0;
pop Eax;
}
function H_strcat(Dword dst,src)
{
Eax = dst;
Edx = src;
push Eax;
while (byte [Eax] != 0) { Eax++; }
while (byte [Edx] != 0)
{
BL = [Edx];
[Eax] = BL;
Edx++; Eax++;
}
[Eax] = 0;
pop Eax;
}
function H_GetTmpStr(DWord sizeInByte)
{
uses Ebx Ecx;
global int32 StrCnt;
global char* StrFunc[2048];
Eax = StrCnt;
Eax++;
and Eax,2047
StrCnt = Eax;
Ebx = @StrFunc;
lea Ebx,[Ebx+Eax]
Eax=DWord[Ebx];
if( Eax> 0)
{
freemem( Eax);
}
[Ebx]= malloc(sizeInByte);
}
//
// event_Emit()
// return false to allow the assembler to process this keyword internally.
// return true to tell the assembler this keyword has been processed.
//
function event_Dim()
{
uses edi;
Dword Len;
char var[255];
char buf[1024];
repeat {
buf = 0; //make sure buf is initialized otherwise it may be filled with junk
eax = Ziron_ExpectNextToken(zirIdent);
if (eax == -1) {
Ziron_FatalError('Expected Variable Name');
return true;
}
H_strcpy(@var,Ziron_GetStringValue());
//Ziron_ShowMessage(@var);
eax = Ziron_GetNextToken();
case (eax)
{
/********* Dim Var as int32; **************/
state zirAs:
eax = Ziron_ExpectNextToken(zirDATA_TYPE);
if (eax == -1)
{
Ziron_FatalError('Expected data type');
return true;
}
eax = Ziron_GetStringValue();
H_strcat(@buf,eax);
H_strcat(@buf,' ');
H_strcat(@buf,@var);
H_strcat(@buf,';');
H_strcat(@buf,'\r\n');
//Ziron_ShowMessage(@buf);
Len = H_strlen(@buf);
eax = Ziron_Execute(@buf,Len);
if (eax == false)
{
Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
}
break;
/********* dim k%; **************/
state zirModSym:
H_strcat(@buf,'int32 ');
H_strcat(@buf,@var);
H_strcat(@buf,';');
H_strcat(@buf,'\r\n');
//Ziron_ShowMessage(@buf);
Len = H_strlen(@buf);
eax = Ziron_Execute(@buf,Len);
if (eax == false)
{
Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
}
break;
state zirDollarSym:
/********* dim k$; **************/
H_strcat(@buf,'char ');
H_strcat(@buf,@var);
H_strcat(@buf,'[1024];');
H_strcat(@buf,'\r\n');
//Ziron_ShowMessage(@buf);
Len = H_strlen(@buf);
eax = Ziron_Execute(@buf,Len);
if (eax == false)
{
Ziron_FatalError('Dim plugin is not compatible with this version of Ziron');
}
break;
state zirIdent:
eax = Ziron_GetStringValue();
break;
default:
Ziron_FatalError('Expected as Keyword');
return true;
}
eax = Ziron_IsNextLineBreak();
if(eax)
{
break; // check end of line so we end without semicolon
}
eax = Ziron_GetNextToken();
if (eax == zirSEMI_COLON)
{
break;
} elseif (eax != zirCOMMA) {
Ziron_FatalError('Unexpected token type');
}
};
return true;
}
function InitPlugin(pointer pGetF) {
Ziron_LoadAll(pGetF); //use framework utility function to load all
//register our keyword
Ziron_RegisterKeyword('Dim', @event_Dim);
return strLoaded;
}
entry function DLLMain(DWord iDLL; DWord iReason; Pointer iResult) {
if (iReason == DLL_PROCESS_ATTACH) {
return true;
}
return false;
}
exports InitPlugin;
program WIN32CUI 'Basic Syntax test';
#include 'console.zir';
function H_strcpy(Dword dst,src)
{
Eax = dst;
Edx = src;
push Eax;
BL = [Edx];
while ( BL != 0)
{
[Eax] = BL;
Eax++; Edx++;
BL = [Edx];
}
[Eax] = 0;
pop Eax;
}
eax = 1;
print('eax = ', eax:int, '\r\n');
Dim Var as int32 // not well , in basic there is no semicolon at end of file
DIM Name$;
DIM a AS int32, b AS Dword, c AS char;
dim k%;
Var = 1000;
a = -10;
b = 150;
c = ord('A');
k = -2000;
H_strcpy(@Name , 'Emil');
print('Var = ', Var, '\r\n');
print('a = ', a, '\r\n');
print('b = ', b, '\r\n');
print('c = ');
WriteLnEx(@c,1);
print('k = ', k, '\r\n');
WriteLnEx(@Name,4);
wait_key(nil);
ExitProcess(0);