Zilog z80 to Motorola 6809 Transcode – Part 002 – How to handle jump tables

I was going through the data sections of the source code and I found out a lot of small sections where there are jump tables to different routines.  So these will have to be handled separately from regular data that is pointed to and loaded such as player data or graphic data.

For example there is some code that looks like this:

     FDB   $9408     ;0247 94 08    DW 894h   A=0,increment LevelComplete
     FDB   $A306     ;0249 A3 06    DW 6A3h   Increment MainSub2
     FDB   $8E05     ;024B 8E 05    DW 58Eh   Increment MainSub1

So in the example above I need to change the FDB sections and make them pointers to the actual routines that I will have converted to 6809 code.  For example the first entry in the table the Z80 code points to 894h which is really address 0894 and the code at 0894 is:

loc_894:
        LDX     #$4E04          ;0894 21 04 4E       LD      HL,4E04h      
        INC      ,X             ;0897 34             INC     (HL)          
        RTS                     ;0898 C9             RET 

So I need to change the jump table entry from:

     FDB   $9408     ;0247 94 08    DW 894h   A=0,increment LevelComplete

To:

     FDB   loc_894   ;0247 94 08    DW 894h   A=0,increment LevelComplete

At assembly time the correct location will be inserted for the loc_894 value and the table will point to the correct location to jump to (of course I’ll be dealing with the LSB,MSB stuff)

I think to get around any copyright issues with Namco I will have to make the program only work if you have the Pac Man ROMS on the disk and load them at start time into the proper memory location (0000-$4000) similar to how MAME works.  Then I will modify sections of the ROM with the correct jump locations and invert any LSB,MSB bytes that will make the 6809 run faster then doing a byte swap every time we access this data with a 16 bit load.

So the way the 6809 translated source will end up is probably going to be something like this:

-Data Segments with pointers to actual locations of the Data that the main program will need to reference.  These values will use ORG commands so they point to the correct locations in memory.  Some of this data will probably have the LSB,MSB byte reversals applied to the original data locations.

-Another Data section with modified data pointers like I described above, these might be left in the code section in place with the pointers to other routines modified.

-The actual converted code section

These sections will be joined into one big source code file so the pointers will be updated at the time the code is assembled.

Something else I noticed looking through the source code today is that many of the routines that use the Z80 IX and IY registers don’t use the DE and BC registers.  Some do but the vast majority don’t.  So I think I will substitute Y for IY and U for IX in the majority of my translation and hand tweak the sections that use more registers all at the same time.  As with the Space Invaders 8080 translation I used the following 6809 registers in place of the Z80/8080 registers:

X=HL,Y=DE,U=BC and with Pac Man I’ll also use Y=IY and U=IX, of course A and B are good from both CPUs.

See you in the next post…

Glen

 

 

 

 

Advertisements
This entry was posted in CoCo Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s