GP32 X86 To Arm Assembly Code


thegrimreaper

Certified Guru
Joined
Jun 11, 2005
Messages
137
Location
Leeds, North England
Website
Visit site
Hello everybody,

I'm trying to help Franxis continue the great work he's done porting Mame to the GP32. I've been trying to get the vector graphics engine working for the Atari emulator, so that games such as Asteroids, Battle Zone, Lunar Lander and (most desirable of all) Star Wars will be playable on Game Park's little wonder machine.

I've downloaded the original 0.34 version of the msdos source code and I'm trying to port the source code to work with Franxis' 1.2.2 version of the GP32 ARM source code. The problem I'm having is in the file "src\msods\osinline.h" which has an assembly routine written for msdos that now needs to be converted to work with the ARM cpu. I don't know anything about assembly code, but from what I've researched on the web it seems that you need to know what you're doing to make changes to this un-readable language. Anyway, here's the code that is failing to compile...


#define vec_mult _vec_mult
INLINE int _vec_mult(int x, int y)
{
int result;
__asm (
"movl %1 , %0 ; "
"imull %2 ; " /* do the multiply */
"movl %%edx , %%eax ; "
: "=&a" (result) /* the result has to go in eax */
: "mr" (x), /* x and y can be regs or mem */
"mr" (y)
: "%edx", "%cc" /* clobbers edx and flags */
);
return result;
}

And the compilation error I'm getting is...

src/gp32/osinline.h:17: error: unknown register name `%edx' in `asm'


Please help me guys, I'm sure there's lots of people out there that would love to play the original Star Wars etc. on their GP32.
 
I am not sure I understand your question, but the problem is that the code you are trying to compile is written in x86 assembler, using its commands (mov instead of mv and registers (there is no EAX or EDX in the GP32, the registers are r0 - r15).
 
What I'd like is the equivalent code, but written to run correctly (and as efficiently as possible) for the GP32.

From what you've posted, it sounds like you're someone that knows what they're talking about. Would you be able to supply a "ported" version of that x86 code?
 
Remove the x86 function and put this one instead:

static int __inline__ _vec_mult(int x, int y)
{
    int res_hi, res_lo;

    __asm__ __volatile__
    ("smull\t%1,%0,%2,%3"
    : "=r"(res_hi), "=r"(res_lo)
    : "r"(x), "r"(y)
    );

    return res_hi;
}

Sincerely,

LDChen
 
Thanks LDChen, that seems to work.

I was getting a small compilation error, so I changed the function declaration so it now reads...

#define vec_mult _vec_mult
INLINE int _vec_mult(int x, int y)
{
int res_hi, res_lo;

__asm__ __volatile__
("smull\t%1,%0,%2,%3"
: "=r"(res_hi), "=r"(res_lo)
: "r"(x), "r"(y)
);

return res_hi;
}

And that seems to work fine.

Keep your fingers crossed everyone, the Mame version of Star Wars might soon be working.
 
When stuck for asm, just convert to C and then later re-convert to ASM if needed. Remember the great rule of development -- optimize _late_, since sometimes its a total waste of time to do early (and always makes things more complex, which is bad.) ie: You could've converted it to a basic multiple likely to keep coding, and then come back later :) (The mults are used for vector rendering so shouldn't kill performance too much except during the deathstar explosions likely anyway :)

jeff
 
I was going to spit out some C code and then say "convert it to assembler later on as the C may be more reliable to begin with", but someone has already spit out the assembler. Fair point as this bit of assembler was incredible easy to port, but larger chunks should always be ported to C first to just get the code up a running like Jeff says.
 
Back
Top