SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 31/08/2015, 03:46 PM   #11
Yashas
Gangsta
 
Join Date: Jun 2012
Location: India
Posts: 867
Reputation: 295
Default Re: #emit Discussion

I just can't see what is wrong in the code below

Code:
stock _INI_LOG(INI:handle, msg[], {Float, _}:...)
{
	printf("ERR MSG %s",msg);

    static arg_count_bytes;
    static str[128],start_adr,end_adr;

    new File:LogFile = fopen(INI_LOG_FILE,io_append);

    #emit LOAD.S.pri  8
	#emit CONST.alt 8 //2 STATIC ARGUMENTS ; 2*4 = 8
	#emit SUB
	#emit STOR.pri arg_count_bytes

    if(arg_count_bytes)
    {
        #emit LCTRL	5
        #emit CONST.alt	msg
        #emit ADD
        #emit STOR.pri	start_adr

        #emit LOAD.alt	arg_count_bytes
        #emit ADD
        #emit STOR.pri	end_adr

        do
        {
            #emit LOAD.I
            #emit PUSH.pri
            #emit LOAD.pri end_adr
            #emit CONST.alt 4
			#emit SUB
			#emit STOR.pri end_adr
        }while(end_adr > start_adr);

        #emit PUSH.S	msg
        #emit PUSH.C 	128
        #emit PUSH.ADR	str

		#emit LOAD.pri arg_count_bytes
		#emit CONST.alt 12
		#emit ADD
		#emit STOR.pri arg_count_bytes
        #emit PUSH.pri

        #emit SYSREQ.C	format

        #emit LOAD.pri arg_count_bytes
		#emit CONST.alt 4
		#emit ADD
		#emit XCHG

        #emit LCTRL	4
        #emit ADD
        #emit SCTRL	4

        if(LogFile)
            fwrite(LogFile,str);
        else
        {
            print("Could not open Log File ("#INI_LOG_FILE")");
            print(str);
		}
	}
	else
	{
        if(LogFile)
        {
            fwrite(LogFile,str);
			fclose(LogFile);
		}
        else
        {
            print("Could not open Log File("#INI_LOG_FILE")");
            print(str);
		}
    }
}
Code:
[08:42:39] ERR MSG [INI]CreateINI:File already exists(%s)
[08:42:39] ERR MSG [INI]Warning:Creating another instance of the same file(%s)
[08:42:39] ERR MSG [INI]ReadString:Key(%s) not found in section ID %d 
[08:42:39] [debug] Run time error 6: "Invalid instruction"
[08:42:39] [debug]  Unknown opcode 0x24000000 at address 0x00000061
[08:42:39] [debug] AMX backtrace:
[08:42:39] [debug] #0 00000061 in public OnFilterScriptInit () at H:\eXtended INI Processor\Server\pawno\include\eINI.inc:254
[08:42:39]   Loaded 1 filterscripts.
It works few times and then suddenly fails
The line 254 is the printf at the very beginning of the function. So did I corrupt the AMX?

Did some random changes to my OnFilterScriptInit which has no relationship with my INI Include but the error seems to change

Code:
[08:50:43] -4081998 ERR MSG [INI]CreateINI:File already exists(%s)
[08:50:43] [debug] Server crashed while executing TestEINI.amx
[08:50:43] [debug] AMX backtrace:
[08:50:43] [debug] #0 native format () [00472b80] from samp-server.exe
[08:50:43] [debug] #1 000001e0 in _INI_LOG (INI:handle=-4081998, msg[][email protected] "[INI]CreateINI:File already ex...", ... <1 argument>) at H:\eXtended INI Processor\Server\pawno\include\eINI.inc:277
[08:50:43] [debug] #2 0000095c in INI:eINI_CreateINI (fname[][email protected] "NewFile.ini") at H:\eXtended INI Processor\Server\pawno\include\eINI.inc:483
[08:50:43] [debug] #3 00011888 in public OnFilterScriptInit () at H:\eXtended INI Processor\Server\filterscripts\TestEINI.pwn:44
[08:50:43] [debug] Native backtrace:
[08:50:43] [debug] #0 00403334 in ?? () from samp-server.exe
[08:50:43] [debug] #1 625658ca in ?? () from plugins\crashdetect.DLL
[08:50:43] [debug] #2 6256774f in ?? () from plugins\crashdetect.DLL
[08:50:43] [debug] #3 62560834 in ?? () from plugins\crashdetect.DLL
[08:50:43] [debug] #4 6256591a in ?? () from plugins\crashdetect.DLL
[08:50:43] [debug] #5 0046a918 in ?? () from samp-server.exe
Code:
#emit ADD
        #emit STOR.pri	end_adr

        do <- LINE 277
        {
            #emit LOAD.I
            #emit PUSH.pri
Yashas is offline   Reply With Quote
Old 10/11/2015, 11:04 PM   #12
Dutheil
Godfather
 
Dutheil's Avatar
 
Join Date: Jul 2014
Location: France
Posts: 5,138
Reputation: 221
Default Re : #emit Discussion

With LOAD.S.pri/alt :
  • I use the value 8, I get the args count in bytes. : *( dat + frm + 8 )
  • I use the value 0, I get an address pointing to the args count in bytes of the last function called. : *( dat + frm )

I would like to know what is the the value 4 when I use it with LOAD.S.pri/alt ? : *( dat + frm + 4 )
__________________
#PrayForFrenchForum
GitHub

Code:
print({1466458484, 543452960, 2037347616, 1952999790, 1797286260, 544694643, 543649646, 1851859053, 1634428192, 1056964608});

Last edited by Dutheil; 10/11/2015 at 11:35 PM.
Dutheil is offline   Reply With Quote
Old 11/11/2015, 01:09 PM   #13
Yashas
Gangsta
 
Join Date: Jun 2012
Location: India
Posts: 867
Reputation: 295
Default Re: #emit Discussion

You will get the return address.

0 stores current frame address
4 stores function return address
8 stores the argument count in terms of total size

I have explained the stack structure after a function call here
forum.sa-mp.com/showthread.php?p=3596399
Yashas is offline   Reply With Quote
Old 18/07/2017, 02:26 PM   #14
Dutheil
Godfather
 
Dutheil's Avatar
 
Join Date: Jul 2014
Location: France
Posts: 5,138
Reputation: 221
Default Re: #emit Discussion

I have 3 questions.

In the PDF "Implementorís Guide", let's take LOAD.pri : pri = PRI = [address]
It is mentioned :
Quote:
An item between square brackets indicates a memory access (relative to the data register, except for jump and call instructions)
So, his code in C is :
PHP Code:
pri = *(data address
1. My first question is : there is any difference between a "data register" and a "data segment" ?

2. My second question is based on the tests I made.
I know when I declare a variable, her value is stored in memory, but we don't have acces to it easily, because I thought that it was only necessary to rely on the semantics.

Example : If I declare a variable named "myVar" with the value 41566421 and I want to get her address in the memory :
PHP Code:
#include "a_samp"

main()
{
    new 
        
myVar 41566421,
        
globalAddress;

    
#emit ADDR.pri myVar
    #emit LOAD.I
    #emit STOR.S.pri globalAddress

    
printf("0x%08x"globalAddress);

It prints me : 0x027A40D5
Edit : Logic, 0x027A40D5 in decimal is 41566421... my bad

But the real address is among these :


If there is a difference in my first question, what data is use in the p-code LOAD.I ?
Otherwise : why it doesn't print me the good address ?

I looked the code in y_amx, and I see a semi-constant "AMX_REAL_DATA" initializes with some manipulations.

3. Is it better to use the p-code STACK twice or once in such cases ? :

PHP Code:
#include "a_samp"

main()
{
    new 
        
string[] = "Dutheil";

    
#emit ADDR.pri string
    #emit PUSH.pri
    #emit PUSH.C 4
    #emit SYSREQ.C print

    #emit ADDR.pri string
    #emit ADD.C 12
    #emit PUSH.pri
    #emit PUSH 4
    #emit SYSREQ.C print

    #emit STACK 16 // fix the stack

or ? :
PHP Code:
#include "a_samp"

main()
{
    new 
        
string[] = "Dutheil";

    
#emit ADDR.pri string
    #emit PUSH.pri
    #emit PUSH.C 4
    #emit SYSREQ.C print

    #emit STACK 8 // fix the stack

    #emit ADDR.pri string
    #emit ADD.C 12
    #emit PUSH.pri
    #emit PUSH 4
    #emit SYSREQ.C print

    #emit STACK 8 // fix the stack

__________________
#PrayForFrenchForum
GitHub

Code:
print({1466458484, 543452960, 2037347616, 1952999790, 1797286260, 544694643, 543649646, 1851859053, 1634428192, 1056964608});

Last edited by Dutheil; 19/07/2017 at 12:36 AM.
Dutheil is offline   Reply With Quote
Old 18/07/2017, 11:47 PM   #15
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 3,759
Reputation: 646
Default Re: #emit Discussion

Quote:
Originally Posted by Dutheil View Post
1. My first question is : there is any difference between a "data register" and a "data segment" ?
Well the data register DAT points to the start of the data section / segment
You can use lctrl and sctrl to load / set the registers

Quote:
Originally Posted by Dutheil View Post
2. My second question is based on the tests I made.
Because you used load.i, addr.pri already returns the address (FRM + offset)
load.i doesn't use the DAT register, it just loads the address, it usually works except if address is between HEA and STK or the unsigned address is over the memory size
PHP Code:
// amx.c
    
case OP_LOAD_I:
        
/* verify address */
        
if (pri>=hea && pri<stk || (ucell)pri>=(ucell)amx->stp)
            
ABORT(amx,AMX_ERR_MEMACCESS);
        
pri=_R(data,pri); // #define _R(base,addr) (* (cell *)((unsigned char*)(base)+(int)(addr)))
        
break; 
No time to look into y_amx but if it says AMX_REAL_DATA it is probably the data section relative to the real memory block of the server

Quote:
Originally Posted by Dutheil View Post
3. Is it better to use the p-code STACK twice or once in such cases ?
Well that doesn't matter at all as long as HEA and STK do no collide
Nero_3D is offline   Reply With Quote
Old 19/07/2017, 12:31 AM   #16
Dutheil
Godfather
 
Dutheil's Avatar
 
Join Date: Jul 2014
Location: France
Posts: 5,138
Reputation: 221
Default Re: #emit Discussion

So, I noticed something :
In LOAD.I, the variable data is used, but in LCTRL 1, this is hdr->dat.
They don't store the same value, that's for sure.
__________________
#PrayForFrenchForum
GitHub

Code:
print({1466458484, 543452960, 2037347616, 1952999790, 1797286260, 544694643, 543649646, 1851859053, 1634428192, 1056964608});
Dutheil is offline   Reply With Quote
Old 19/07/2017, 10:07 PM   #17
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 3,759
Reputation: 646
Default Re: #emit Discussion

Quote:
Originally Posted by Dutheil View Post
So, I noticed something :
In LOAD.I, the variable data is used, but in LCTRL 1, this is hdr->dat.
They don't store the same value, that's for sure.
To correct myself there is a data variable used in load.i (not the DAT register) but it should be equivalent to AMX_REAL_DATA (amx->base (start of amx memory) + hdr->dat (the DAT register))
It shouldn't matter because all opcodes are relative to the data segment
Nero_3D is offline   Reply With Quote
Old 29/12/2017, 02:45 PM   #18
Dutheil
Godfather
 
Dutheil's Avatar
 
Join Date: Jul 2014
Location: France
Posts: 5,138
Reputation: 221
Default Re: #emit Discussion

How can I get the name of any public function into this without index id ?
Example:
PHP Code:
#include "a_samp"

forward CustomPublicFunction();

main()
{
    
CustomPublicFunction();
}

public 
CustomPublicFunction()
{
    
// get here the name of CustomPublicFunction

__________________
#PrayForFrenchForum
GitHub

Code:
print({1466458484, 543452960, 2037347616, 1952999790, 1797286260, 544694643, 543649646, 1851859053, 1634428192, 1056964608});
Dutheil is offline   Reply With Quote
Old 29/12/2017, 03:24 PM   #19
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,535
Reputation: 552
Default Re: #emit Discussion

There's funcidx which returns the index, unless that's what you mean by "without index id"
Misiur is offline   Reply With Quote
Old 29/12/2017, 03:49 PM   #20
Kaperstone
Banned
 
Join Date: May 2011
Location: Russia
Posts: 3,348
Reputation: 824
Default Re: #emit Discussion

Quote:
Originally Posted by Misiur View Post
There's funcidx which returns the index, unless that's what you mean by "without index id"
No, what he meant was to get the name of the callback that the function is in.
Code:
#include "a_samp" 

forward CustomPublicFunction(); 

main() 
{ 
    CustomPublicFunction(); 
} 

public CustomPublicFunction() 
{ 
   print(GetCallbackName()); // will print "CustomPublicFunction"
}
EDIT: http://forum.sa-mp.com/showthread.php?t=353862
Kaperstone is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
when should #emit be used sammp Scripting Help 3 15/11/2014 09:49 AM
@emit Slice Discussion 7 16/04/2013 06:30 PM
Emit Help Snir_sofer Scripting Help 2 25/09/2012 05:54 PM
#emit rVar Scripting Help 3 08/09/2012 06:26 PM
Help with #emit _Petrol_ Scripting Help 0 23/08/2012 03:54 PM


All times are GMT. The time now is 06:50 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.