Colin
admin
Posts
928
Threads
49
Location
Bulgaria
Post #137
2011-10-26 01:43:18 UTC
This is possible with the blob keyword
blob size_bytes,out
e.g.
blob 1,0x90; //single nop
blob 4,0x90909090; //4 nops
a slightly more complex usage from includes/opcodes.zir
inline op procedure _or(reg1, reg2) {
$expect sizeof $reg1 as sizeof $reg2: 'Operands must be equal size';
$if sizeof $reg1 == 32:
blob 1,0x0B 1,0xC0 + (($reg1*8)+$reg2);
$elseif sizeof $reg1 == 16:
blob 1,0x66 1,0x0B 1,0xC0+(($reg1*8)+$reg2);
$else
blob 1,0x0A 1,0xC0+(($reg1*8)+$reg2);
$end
}
it would be possible to write an Emit macro to implement the keyword :)
Emil_halim
member
Posts
639
Threads
104
Location
Alex, Egypt
Post #138
2011-10-26 18:36:38 UTC
very nice.
does macro system allow incompleted parameters ?
just like printf ic c&c++ ,
inline op mymacro(par1,par2,...)
and if so , is there a way to get those parameters as array
also can we test if any parameter is null ?
also we need a way to know the type of the parameter , is it register ,memory location , abslout value...
all that will be useful.
http://www.freewebs.com/ogremagic/index.htm
Colin
admin
Posts
928
Threads
49
Location
Bulgaria
Post #143
2011-10-26 19:26:52 UTC
i sugest for now you check the includes/console.zir file, this has a reasonable sample with the print macro.
Colin
admin
Posts
928
Threads
49
Location
Bulgaria
Post #203
2011-10-29 20:54:48 UTC
thought i'd post regarding this request - since actually it is useful i have implemented it as written, but better still instead of hardcoded i have used this feature to help me improve the plugin system and written this opcode using the plugin system :)
program WIN32DLL 'EMIT PLUGIN';
#include 'ziron32.zir';
///////////////////
enum ZirToken: DWord {
zirSEMI_COLON, zirCOMMA, zirDATA_TYPE, zirREGISTER, zirNUMBER, zirHEXADECIMAL
}
enum ZirFWID: DWord {
//settings
idCPU_MODE = 10,
//functions
idFATAL_ERROR = 1000,
idSHOW_MESSAGE = 1001,
//special functions
idREGISTER_KEYWORD = 2000,
idEXPECT_NEXT_TOKEN = 5000,
idGET_NEXT_TOKEN = 5001,
idIS_DATA_FLOAT = 5002,
idGET_INTVALUE = 5003,
idGET_DATA_SIZE = 5004,
idEMIT_CODE = 5005
}
///////////////////
const strLoaded = 'Emit plugin has loaded!';
//////////////////////////////
function* Ziron_Get(ZirFWID funcID): DWord; stdcall;
////
procedure* Ziron_FatalError(char* str); stdcall;
procedure* Ziron_ShowMessage(char* str); stdcall;
//
function* Ziron_ExpectNextToken(ZirToken tt): DWord; stdcall;
function* Ziron_GetNextToken(): DWord; stdcall;
function* Ziron_GetIntValue(): Int32; stdcall;
function* Ziron_GetDataSize(DWord id): DWord; stdcall;
function* Ziron_RegisterKeyword(char* name; pointer callback): DWord; stdcall;
procedure* Ziron_EmitCode(char* buffer; DWord len); stdcall;
////
function event_Emit() { //always stdcall; return false to allow the assembler to use the default processor for this keyword
uses edi;
char codeBuf[4];
eax = Ziron_ExpectNextToken(zirDATA_TYPE);
if (eax == -1) {
Ziron_FatalError('Expected data type');
return true;
}
edi = Ziron_GetDataSize(eax);
repeat {
eax = Ziron_GetNextToken();
case (eax) {
state zirHEXADECIMAL:
state zirNUMBER:
codeBuf = Ziron_GetIntValue();
Ziron_EmitCode(@codeBuf, edi);
break;
default:
Ziron_FatalError('Unexpected token type');
return true;
}
eax = Ziron_GetNextToken();
if (eax == zirSEMI_COLON) {
break;
} elseif (eax != zirCOMMA) {
Ziron_FatalError('Unexpected token type');
break;
}
};
return true;
}
function InitPlugin(pointer pGetF) {
Ziron_Get = pGetF;
//get the functions this plugin will require - see plugin_interface.txt
Ziron_FatalError = Ziron_Get(idFATAL_ERROR);
Ziron_ShowMessage = Ziron_Get(idSHOW_MESSAGE);
Ziron_RegisterKeyword = Ziron_Get(idREGISTER_KEYWORD);
Ziron_ExpectNextToken = Ziron_Get(idEXPECT_NEXT_TOKEN);
Ziron_GetNextToken = Ziron_Get(idGET_NEXT_TOKEN);
Ziron_GetIntValue = Ziron_Get(idGET_INTVALUE);
Ziron_GetDataSize = Ziron_Get(idGET_DATA_SIZE);
Ziron_EmitCode = Ziron_Get(idEMIT_CODE);
//register our keyword
Ziron_RegisterKeyword('emit', @event_Emit);
return strLoaded;
}
entry function DLLMain(DWord iDLL; DWord iReason; Pointer iResult) {
if (iReason == DLL_PROCESS_ATTACH) {
return true;
}
return false;
}
exports InitPlugin;
once compiled, put into the plugin directory it allows a new opcode to be used directly in your code:
//lets do a push eax; pop eax
emit byte 0x50, 0x58;
This feature request was the perfect sample plugin to be supplied with Ziron :)
Emil_halim
member
Posts
639
Threads
104
Location
Alex, Egypt
Post #205
2011-10-29 22:46:16 UTC
so nice , when you will release that , want to start playing with it.:yess:
http://www.freewebs.com/ogremagic/index.htm
Colin
admin
Posts
928
Threads
49
Location
Bulgaria
Post #206
2011-10-29 23:05:46 UTC
maybe tomorrow afternoon :)
Emil_halim
member
Posts
639
Threads
104
Location
Alex, Egypt
Post #209
2011-10-29 23:18:22 UTC
well ,
i think it will be better if you add a plugin section in the forum , so that we can collect a post of Plugin source in one place.
http://www.freewebs.com/ogremagic/index.htm