English Amiga Board

English Amiga Board (http://eab.abime.net/index.php)
-   Retrogaming General Discussion (http://eab.abime.net/forumdisplay.php?f=17)
-   -   Pacman - the Amiga conversion from the arcade game (http://eab.abime.net/showthread.php?t=98727)

jotd 06 September 2019 19:35

Pacman - the Amiga conversion from the arcade game
Asman asked me to post info on that, since it was discussed on other threads.

So my project was to create a 1:1 port of Pacman which plays the same and all, at 50pfs, on amiga, reusing the work of the zx spectrum program which uses the arcade version.

As someone (mcgeezer) suggested, it should be possible to port the Z80 code to 68000 with a converter.

I found one, and compiled it and all (it was ooold), but there were a LOT of issues with the convert (I think it works well for SMALL programs that don't use low level asm things, like compressors, etc...)

It also has other limitations, the worst one is: it can only run from 0 to $8000 (it uses address registers in signed 16 bit mode)


The FRONTZ80 code and the converted program should reside in the lower 32K or
upper 32K of the MC68000's memory map for proper execution.
So if you convert a big enough program, you hit the limit. And pacman is around $4000 bytes long. With expansion of instructions + adding condition code checking which is different, you easily hit the limit.

So I'm giving that solution up after a few days. So now you know: it's not easy (I can share more details, the convert is far from perfect and a lot of other things are missing (I could have used a small converted example too..., even if MOTOROLA wrote it!)

BUT, what would be almost as efficient would be to run a Z80 emulator designed for 68000 and do the rest exactly the same way. Can someone point me to some Z80 emulator with asm source code?

Minuous 06 September 2019 20:18


http://aminet.net/package/misc/emu/amitrs80 is open source and has a Z80 core written in assembler.

Asman 06 September 2019 20:55


Look here https://github.com/shaunlebron/pacma...isasm/bart.asm

In ancient times I also thought about perfect pacman port. And I thought about converter from Z80 --> mc68000. Of course I did nothing - just disasm some block of code and I stuck with z80 code.

Lets focus on simple z80 routine. (Code taken from bart.asm)


; ( rst 8 - Fill (HL)...(HL+B) with Accumulator )
[0x8] 8      0x77    LD (HL), A                  ;  Load location (HL) with Accumulator
[0x9] 9      0x23    INC HL                      ;  Increment register pair HL
[0xa] 10      0x10    DJNZ N          fc          ;  Decrement B and jump relative 0xfc (-4) if B!=0
[0xc] 12      0xc9    RET                        ;  Return

The converter should convert it in following way (assumption D0 = reg A, D1 - B, A3 - HL )

label08:        move.b        D0,(a3)                ;label08:        0x77        ->        ld        (hl),a
                addq.w        #1,a3                ;                0x23        ->        inc        hl
                dbf        d1,label08        ;                0x10        0xfc        ->        djnz        label08
                rts                        ;                0xc9        ->        ret

Am I right or it just my imagination about perfect world ? :)

Of course its only idea. So first question which comes to my mind is about best usage of 68k registers for z80 register (mapping). How it usually done ?

edit: changed addq.b --> addq.w. Thanks to hitchhikr.

DanScott 06 September 2019 21:25

Well... of course, BC, DE and HL can be used as address registers, but also the 8 bit components B,C,D,E,H,L are also data registers... so you can't really map 1 to 1 to 68k instructions... but I am sure that there is some efficient way of doing it :D

possibly to use memory locations to hold the 8 bit data regs, and pull from memory a 16 bit value into a 68k address register ?

drHirudo 06 September 2019 21:59


Originally Posted by jotd (Post 1344072)
BUT, what would be almost as efficient would be to run a Z80 emulator designed for 68000 and do the rest exactly the same way. Can someone point me to some Z80 emulator with asm source code?

There are many Z80 emulators with source code for 680x0 (Amiga):

Wzonka-Lad http://aminet.net/package/misc/emu/wlz80core - Emulates the slightly different GameBoy's Z80. Very well commented code for each instruction.
AmiMSX - http://aminet.net/misc/emu/AmiMSX_asm.lha Comments in Spanish. The Z80 emulation core is also used for AmiMasterGear, AmiGameBoy
Spectrum http://aminet.net/misc/emu/spectrum-1.7_src.lha and http://aminet.net/misc/emu/spectrum-1.8wip_src.lha - Another Sinclair ZX Spectrum Emulator with source.
CBSpeccy - Russian Sinclair and clones emulator http://aminet.net/misc/emu/CBSpeccy_v027.lha - comments in English.
Speccylator - http://aminet.net/package/misc/emu/Speccylator-src - works on plain 68000 and is fast.

hitchhikr 06 September 2019 22:07


addq.b        #1,a3
This doesn't exist in 68000, better use addq.w (which is what the original z80 instruction does anyway) :D.

idrougge 06 September 2019 22:17

Have you talked to this person? http://www.nickmarentes.com/ProjectArchive/pacman.html

SyX 06 September 2019 22:34

Something like DanScott says, you can put the z80 registers in memory and use an address register for offsets.

Or you can put them in the 68000 registers, something like this:

F/F' -> D3 (Z80 Flag register) | 2 * 8 bits

A/A' -> D4 (Z80 Accumulator) | 2 * 8 bits

BC/BC' -> D5 | 2 * 16 bits

DE/DE' -> D6 | 2 * 16 bits

HL/HL' -> D7 | 2 * 16 bits

IX -> A3 (Index registers are usually used as pointers) 16 bits

IY -> A4 (Index registers are usually used as pointers) 16 bits

PC -> A5 (Z80 PC) 16 bits

SP -> A6 (Z80 Stack) 16 bits

Pacman arcade doesn't use the R or I registers, because that you only need to consider the normal registers and their shadow copy. And you have available the rest of 68000 registers for all the math and logical operations (use rotate and swap for extract z80 registers fast).

The Spectrum emulator from Peter McGavin, than drHirudo posted, it has a nice interface for using. Includes a function that you call and say how many z80 instructions you want to execute... although you will need to modify a few specific instructions (OUT, IN and HALT mainly) because they are specialized to do zx spectrum things.

Although i would not discard the source code conversion yet. In the atari 800 world, that approach has made possible a few zx games conversions with great success (a lot of those conversion look faster in Atari 800 than in the original ZX).

They pass the z80 disassembly source through a c tool that generated the 6502 source that can be assembled later + a few routines that "emulate" the most complex z80 instructions (LDIR, ...) and specific atari code for handling input, graphics, ...

You can get more information about this approach here.

Asman 06 September 2019 22:52


Originally Posted by hitchhikr (Post 1344108)

addq.b        #1,a3
This doesn't exist in 68000, better use addq.w (which is what the original z80 instruction does anyway) :D.

Indeed. Thanks. :)
It seems that my z80 knowldege is too limited. :bash

edit: I changed my previous post.

jotd 06 September 2019 23:52

Really I'm not going to write a Z80 to 68000 converter myself. Too much debugging if something doesn't work. The emulation looks the sanest issue ATM, and probably not so slow.

What would be great would be automatic Z80 to 68000 conversion, with a post-processing that checks if condition flags are needed, and discards them if it isn't, all those asm optimizations that maybe vasm can do

The converter I have does this


Dedicated register usage is as follows:
        D0  - Z80 A register and A' register
        D1  - Z80 flag register and flag' register
        D4  - constant $0F (condition code X bit mask)
        D5  - constant $10 (condition code X bit mask)
        D6  - IX
        D7  - IY
        A1  - pointer to B and BC on stack
        A2  - pointer to C on stack
        A3  - pointer to D and DE on stack
        A4  - pointer to E on stack
        A5  - pointer to L on stack
        A6  - Z80 SP register
        A7  - pointer to H and HL on stack

NorthWay 07 September 2019 03:28

Sounds like what you need is an optimizing assembler. Or perhaps an "assembler compiler" would be closer to the mark. Something that can analyze code flow between entry points and discard dead statements.

Then all you need is to replace Z80 instructions with 68K macros and let the compiler chew on it.

I worked a lot on a 6502 emulator (the original Xformer from the ST), optimizing register and memory layout. Some of the saddest about it was looking at all the code for tracking status bits that you just _had_ to update for every opcode.
Sending static ROM-able code through a converter should cut down the resulting size by a lot if you can drop the un-needed stuff.

Why don't we have assemblers that can spot dead code?

alpine9000 07 September 2019 05:42

It's a shame this seems to be a commercial product, might have been something that coul d have been worth looking at.

z80 -> C -> 68k


Hewitson 07 September 2019 06:44

Would be better to do Ms. Pac Man. A far better game, in my opinion.

Steril707 07 September 2019 09:31


Originally Posted by Hewitson (Post 1344170)
Would be better to do Ms. Pac Man. A far better game, in my opinion.

Did your wife tell you to post this?


jotd 07 September 2019 10:17

z80 -> C that's something that can be done. I've already done 6502 -> C -> 68000/x86/nintendo ds myself for my oric ports and it works.

But I know 6502 and the target very well, and I borrowed stuff from a 6502 emu for tough things like condition codes etc... Not the case with Z80. I may not be the adequate person for this project...

Yesterday I tried to recompile MAME (0.35b12, with amiga parts) with gcc 6. Succeeded building & linking it. Running: lockup right at start software failure ... damn it's never easy.

That gave me the opportunity to look at how it was done, and video refresh (the main culprit of the slowdowns on amiga) seems to use "dirty" areas & asm c2p (that I had to build with vasm -Faout so gcc could understand it). So it's not doing a full screen refresh already. I hoped we could speed this up... maybe the CPU parts with gcc 6. Well, maybe I'll debug it... maybe I'll drop it.

Hewitson 07 September 2019 11:02


Originally Posted by Steril707 (Post 1344180)
Did your wife tell you to post this?


No, I don't have one. It's just a better game.

Edit: The C64 already has a great conversion. I have the original Atarisoft cart.

jotd 07 September 2019 12:28

the most viable option is always to find the functional code (ghosts moves, speeds) and recreate everything from scratch using the same settings & A.I. Of course using the same gfx as well! Not very difficult for a game like Pacman (but still, work).

Already done this with Bagman and it works great. Debugging in MAME helps a lot.

Dunny 07 September 2019 13:39


This documents PacMan in excruciating detail. A friend of mine used it to implement a full PacMan in BASIC and it's a stunningly realistic simulation of the arcade.

The first two pages are just historical information - game mechanics starts at the URL above.

alexh 09 September 2019 17:28


Originally Posted by jotd (Post 1344183)
I've already done 6502 -> C -> 68000

But I know 6502 and the target very well, and I borrowed stuff from a 6502 emu for tough things like condition codes etc...

A guy called Glen Hewlett re-sourced the PacMan Z80 code into to 6809 (which I believe is a variant of the 6502?) in an attempt to faithfully bring PacMan to the CoCo3 (unlike the link above which is a re-creation)


It includes the SW which he used for the conversion


There is a 25 post blog which is quite interesting.

idrougge 10 September 2019 01:09

Oh, I must have thought there was only one Coco 3 port.

All times are GMT +2. The time now is 19:31.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.

Page generated in 0.05740 seconds with 11 queries