Loading external assembly code from file and calling it...

C and PASCAL (or any other high-level languages) in here please

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
simonsunnyboy
Moderator
Moderator
Posts: 4866
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Loading external assembly code from file and calling it...

Postby simonsunnyboy » Wed Sep 08, 2010 8:00 pm

I have some code (PC-relative) and ready to use but the interface does not use registers and i can't get to call it properly from AHCC.

Now I want to load this code into a chunk of memory and then call it. What is a proper C way to do this?

Code: Select all

uint8_t codemem[3000];
void *myrout;
...
myrout = (void *)codemem;

/* now soemthing like */

myrout(a,b,c);



Do I need a function pointer? And if so, how do I define it properly?

*EDIT* And ofocurse I need to declare somehow that I have to pass things on the stack - C style. (The original routine is called with ~C:myprout() from GFABASIC)

cheers,
ssb
Simon Sunnyboy/Paradize - http://paradize.atari.org/ - STOT: http://www.npoi.de/stot/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee

Jabber: simonsunnyboy@atari-jabber.org

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2257
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: Loading external assembly code from file and calling it.

Postby lp » Sat Sep 11, 2010 3:12 pm

In Turbo C you would need to declare the routine something like:

Code: Select all

 
void cdecl myrout(a,b,c)


In some implementations its _cdecl, but I am not sure for AHCC.

m0n0
Captain Atari
Captain Atari
Posts: 419
Joined: Mon Oct 05, 2009 3:13 am

Re: Loading external assembly code from file and calling it.

Postby m0n0 » Tue Jan 24, 2012 12:12 am

I think it should be something like:

Code: Select all

typedef void (*my_voidret_func_type)( int, int, int);
typedef int (*my_intret_func_type)( int, int, int);
...

my_voidret_func_type func_ptr = (my_voidret_func_type)&codemem;
my_intret_func_type func_ptr2 = (my_intret_func_type)&codemem[1400];
func_ptr();
int ret = func_ptr2();



and of course you need to add the cdecl somewhere ;)

Henk Robbers
AHCC Developer
AHCC Developer
Posts: 39
Joined: Mon Nov 14, 2011 2:37 pm

Re: Loading external assembly code from file and calling it.

Postby Henk Robbers » Tue Jan 24, 2012 11:47 am

m0n0 wrote:I think it should be something like:

Code: Select all

typedef void (*my_voidret_func_type)( int, int, int);
typedef int (*my_intret_func_type)( int, int, int);
...

my_voidret_func_type func_ptr = (my_voidret_func_type)&codemem;
my_intret_func_type func_ptr2 = (my_intret_func_type)&codemem[1400];
func_ptr();
int ret = func_ptr2();



and of course you need to add the cdecl somewhere ;)


TIP:
In C you can typedef prototypes.
I would have written it like this:

typedef void cdecl VpIII(int, int,int);

VpIII *func = malloc(1400);
/* read your code into func */
func(1,2,3); /* call the code */

.....

Leaving the '*' out of the typedef makes its use more widely possible.
e'g:

VpIII *p; /* declare pointer to function of type VpIII */
VpIII x, y, z, *q; /* prototype functions x, y and z, declare pointer to function q */

User avatar
simonsunnyboy
Moderator
Moderator
Posts: 4866
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: Loading external assembly code from file and calling it.

Postby simonsunnyboy » Thu Jan 26, 2012 4:50 pm

The thread is over a year old - thanks for the unexpected replies :D I'll will investigate and work on this when i find more spare time.

I think I got the idea of having to define proper function pointers here.
Simon Sunnyboy/Paradize - http://paradize.atari.org/ - STOT: http://www.npoi.de/stot/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee

Jabber: simonsunnyboy@atari-jabber.org

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2060
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Loading external assembly code from file and calling it.

Postby charles » Thu Jan 26, 2012 10:34 pm

heres some diversity simon ,
see this thread ,

this is how i did it in pure pascal

i know, not 'c', but

if not one then all .



.draw any similarities?

viewtopic.php?f=70&t=20329


charles
atari is my lifestyle,not a hobby.
HOLD ON ! ! !,
Im printing unreadable characters ...!


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 1 guest