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