Trap

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
Pascal
Very interested
Posts: 200
Joined: Wed Nov 29, 2006 11:29 am
Location: Belgium
Contact:

Trap

Post by Pascal » Thu Feb 17, 2011 1:45 pm

hello all,

i need to mix a C program with a asm game. From the asm code , i need to call functions of the C program. I was thinking using the Trap opcode.

As i don't need to return to the asm program (no RTE) , i'll do a SP+6 in my trap handler.

Do i need to do something more ? good or bad idea to use trap ?

thanks

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Thu Feb 17, 2011 1:59 pm

Bad idea - just go with the C ABI. The 68000 ABI is save all regs other than d0-d1/a0-a1, and all args go on the stack as longs, regardless of size. Trap, as with all exceptions on the 68000, is slow, taking far longer to dispatch than a simple jsr. If the function never returns, a simple jmp is even faster!

Pascal
Very interested
Posts: 200
Joined: Wed Nov 29, 2006 11:29 am
Location: Belgium
Contact:

Post by Pascal » Thu Feb 17, 2011 2:14 pm

thanks ! silly of me , i'll go for a simple jump ;)

plee
Very interested
Posts: 66
Joined: Wed Nov 29, 2006 11:32 am
Location: Houston, Texas

Re: Trap

Post by plee » Sun Feb 27, 2011 3:46 am

Pascal wrote:hello all,

i need to mix a C program with a asm game. From the asm code , i need to call functions of the C program. I was thinking using the Trap opcode.

As i don't need to return to the asm program (no RTE) , i'll do a SP+6 in my trap handler.

Do i need to do something more ? good or bad idea to use trap ?

thanks
Depending on the compiler you use, you can inter-mix the C code with assembly. GCC's register ops is a bit funky but it can be done.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Re: Trap

Post by Chilly Willy » Sun Feb 27, 2011 4:08 am

plee wrote:Depending on the compiler you use, you can inter-mix the C code with assembly. GCC's register ops is a bit funky but it can be done.
Just put "--register-prefix-optional" in the command line and forget the funk. :wink:

Post Reply