Porting 68000 Legacy Assembly to other devices
Guest_Reinier v Vliet_*
Posted 17 February 2006 - 03:00 PM
My first post here so why not start of with a nice Code of the day.
This code of the day is by no means finished, but is a work in progress...
I'd love to hear feedback on this, especially from people with heavy template metaprogramming experience.
Anyway, let's start with explaining first the goal of this code.
I have been programming games for a long time and it all started with the Amiga.
Of course, everyone who was anyone on the Amiga programmed 68000, and C coders were considered Lamers. Yes a lot has changed....
anyhow, I still have a lot of games I'd like to see ported to other platforms, like PocketPC, Windows, Symbian etc. But you guessed, porting 68000 code to C is quite a cumbersome thing to do.
The most common solution is to forget about it completely. But I really like to have all these old games with me on my PocketPC (for sentiment reasons). Another solution is to make an emulator, but this takes quite some time.
Using existing emulators is also an option but making small changes to the program is quite hard/impossible. Also I just don't like the fact to start an emulator first.
So then I came with the next solution:
Why not convert the Asm mnemonics to matching C code?
A bit like this:
// 68000 equivalent:
// moveq #0,d0
// add.l d1,d0
d0 = 0;
d0 += d1;
Still an amazing amount of work actually to convert it like this, and even more work to get it right (making mental notes about the status register and stuff).
Some 7 iterations further I'm at my current implementation. Let me show you a bit of code which actually compiles straight in MSVC 6, but resembles 68000 a lot ;^D
LEA (tabel1, a0) //tabel indexing
MOVEL (#offset, d0)
ADDW (#$7000,d1) // word operations on long registers
BNE (skipover) // Branches
LABEL(skipover) // mid routine labels
JSR (subtract) // sub routines
// simple example subroutine
// advanced subroutine where we push a new return adress on the stack. The rts will then go there instead of returning
ADDL (#4,a7) // Popping one return address of the stack... the next rts will now actually return to the caller of main (e.g. exit the program) rather then returning.
As you can see, stuff like advanced adressing modes is tackled, jumping/branching and subroutines work, labels can be interspersed throughout the code, data definitions work, and stack manipulation (altering return adresses) works.
I'm still not happy though how it's set up. The underlying code actively parses the adressing modes at runtime which would be much better if it could be done at compile time.
This is why I hoped some of you template boys could point me to how the compiler can better actively parse the mnemonics.
the whole poject can be downloaded from my site:
Reinier v Vliet
Posted 18 February 2006 - 04:22 AM
Posted 18 February 2006 - 04:42 PM
Edit: Ahh guess you check some stuff at runtime.. I read your whole post now ;-) But if you improve the adressing mode issue you'd probably get very optimized code.
Posted 18 February 2006 - 05:27 PM
z80: Yes, the parsing of the operands is the thing which bugs me the most. It would be really nice if somehow with fancy template stuff we could get rid of that whole part and the compiler would do that work. Any pointers from anyone would be appreciated :happy:
Posted 04 March 2006 - 02:37 PM
Having to rewrite all the asm using macros/templates seams a bit ..over the top..
Posted 09 March 2006 - 11:08 AM
Posted 23 March 2006 - 08:53 AM
Posted 21 August 2008 - 04:04 PM
I've done something similar for the company I am working for (Javaground), it converts Java bytecode into C++. This allows me to handle differences in the way Java and Brew work. One early program we tested was faster after being converted from Java than another companies manual conversion of the Java code to Brew (there was about 10% code size overhead though, due to reference counting garbage collection to emulate Java).
Posted 09 July 2009 - 03:32 PM
Do not want to make a new topic becouse it the same about i want to ask. So, i just trying to port some assembler routines to the C, and a bit stuck with that. The lines of asm code not so big (400-500), but rewriting everythink by the hands anyway looks hard.
As i can see in this thread someone already to do some automatic convertor from assembler to C for the 68k cpus, so maybe it possible to found somethere ? (the link from 2006 years are not works anymore ). Or maybe any other freeware toolz are present ?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users