I've ported code between Z80 and 6502, but I've no idea of how different is the 9900.
From what I see the 9990 is fully 16bit and quite far from the z80 architecture.
If you go for a "dumb" instruction replacement, I see that you have to:
- emulate in software the stack system of the Z80 (the 9900 does not have it), while the Z80 uses it for subroutines, for saving registers, and sometimes to have fast 16bit access to data areas
- emulate alternative register sets, probably using different workspaces
- emulate the bit manipulation and testing instructions with their huge system of direct and indirect accesses
There are also very uncommon instructions for nibble rotation and BCD math that could result hard to port.
Moreover, the flag system is quite complex: not all instructions affect the flags and you could have that the result of an operation is preserved in the flags for many instructions before being used by a jump instruction.
If you need working code, a dumb instruction replacement could be done using a modern macro assembler. Probably you can replace each instruction by macros accepting the same parameters allowed by the z80 equivalent and customise the body of the macro as a large switch dealing with each case according to the parameter passed. It would need a lot of work, but it is for sure doable.
Anyway, if you need efficient code, you will need to optimize manually the result, unless you are so brave to develop directly a compiler able to do the translation and the peephole optimization.
In this latter case the work would be even bigger... all depends on what you want to do and how many times you will use this "translator"
Edited by artrag, Wed Jun 14, 2017 3:25 PM.