English Amiga Board


Go Back   English Amiga Board > Main > Retrogaming General Discussion

 
 
Thread Tools
Old 06 September 2019, 19:35   #1
jotd
This cat is no more
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 48
Posts: 3,209
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)

Quote:
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?
jotd is offline  
Old 06 September 2019, 20:18   #2
Minuous
Coder/webmaster/gamer
Minuous's Avatar
 
Join Date: Oct 2001
Location: Canberra/Australia
Posts: 1,987
@jotd:

http://aminet.net/package/misc/emu/amitrs80 is open source and has a Z80 core written in assembler.
Minuous is offline  
Old 06 September 2019, 20:55   #3
Asman
68k

Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 693
@jotd

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)

Code:
; ( 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 )
Code:
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.

Last edited by Asman; 06 September 2019 at 23:03.
Asman is offline  
Old 06 September 2019, 21:25   #4
DanScott
Lemon. / Core Design

DanScott's Avatar
 
Join Date: Mar 2016
Location: Sunny Bournemouth, UK
Posts: 430
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

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 ?
DanScott is online now  
Old 06 September 2019, 21:59   #5
drHirudo
Amiga user
drHirudo's Avatar
 
Join Date: Nov 2008
Location: Sofia / Bulgaria
Posts: 210
Quote:
Originally Posted by jotd View Post
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.
drHirudo is offline  
Old 06 September 2019, 22:07   #6
hitchhikr
Registered User

 
Join Date: Jun 2008
Location: somewhere
Posts: 402
Code:
addq.b	#1,a3
This doesn't exist in 68000, better use addq.w (which is what the original z80 instruction does anyway) .
hitchhikr is offline  
Old 06 September 2019, 22:17   #7
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 3,878
Have you talked to this person? http://www.nickmarentes.com/ProjectArchive/pacman.html
idrougge is offline  
Old 06 September 2019, 22:34   #8
SyX
Registered User

 
Join Date: Sep 2004
Location: Brasil
Age: 45
Posts: 153
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:
Code:
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.
SyX is offline  
Old 06 September 2019, 22:52   #9
Asman
68k

Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 693
Quote:
Originally Posted by hitchhikr View Post
Code:
addq.b	#1,a3
This doesn't exist in 68000, better use addq.w (which is what the original z80 instruction does anyway) .
Indeed. Thanks.
It seems that my z80 knowldege is too limited.

edit: I changed my previous post.

Last edited by Asman; 06 September 2019 at 23:04.
Asman is offline  
Old 06 September 2019, 23:52   #10
jotd
This cat is no more
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 48
Posts: 3,209
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

Code:
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
jotd is offline  
Old 07 September 2019, 03:28   #11
NorthWay
Registered User
 
Join Date: May 2013
Location: Grimstad / Norway
Posts: 608
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?

Last edited by NorthWay; 07 September 2019 at 19:47.
NorthWay is offline  
Old 07 September 2019, 05:42   #12
alpine9000
Registered User

 
Join Date: Mar 2016
Location: Australia
Posts: 726
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

http://www.mpsinc.com/z80.html
alpine9000 is offline  
Old 07 September 2019, 06:44   #13
Hewitson
Registered User
Hewitson's Avatar
 
Join Date: Feb 2007
Location: Melbourne, Australia
Age: 36
Posts: 3,314
Would be better to do Ms. Pac Man. A far better game, in my opinion.
Hewitson is online now  
Old 07 September 2019, 09:31   #14
Steril707
Tigerskunk!

Steril707's Avatar
 
Join Date: Sep 2016
Location: Amiga Island
Posts: 967
Quote:
Originally Posted by Hewitson View Post
Would be better to do Ms. Pac Man. A far better game, in my opinion.
Did your wife tell you to post this?

Steril707 is offline  
Old 07 September 2019, 10:17   #15
jotd
This cat is no more
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 48
Posts: 3,209
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.
jotd is offline  
Old 07 September 2019, 11:02   #16
Hewitson
Registered User
Hewitson's Avatar
 
Join Date: Feb 2007
Location: Melbourne, Australia
Age: 36
Posts: 3,314
Quote:
Originally Posted by Steril707 View Post
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.

Last edited by Hewitson; 07 September 2019 at 11:26.
Hewitson is online now  
Old 07 September 2019, 12:28   #17
jotd
This cat is no more
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 48
Posts: 3,209
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.
jotd is offline  
Old 07 September 2019, 13:39   #18
Dunny
Registered User

Dunny's Avatar
 
Join Date: Aug 2006
Location: Scunthorpe/United Kingdom
Posts: 1,311
https://www.gamasutra.com/view/featu...ier.php?page=3

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.
Dunny is offline  
Old 09 September 2019, 17:28   #19
alexh
Thalion Webshrine
alexh's Avatar
 
Join Date: Jan 2004
Location: Oxford
Posts: 12,222
Quote:
Originally Posted by jotd View Post
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)

https://www.vintageisthenewold.com/a...trs-80-coco-3/

It includes the SW which he used for the conversion

https://nowhereman999.wordpress.com/...-6809-program/

There is a 25 post blog which is quite interesting.
alexh is offline  
Old 10 September 2019, 01:09   #20
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 3,878
Oh, I must have thought there was only one Coco 3 port.
idrougge is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Worst Arcade Conversion Hewitson Nostalgia & memories 57 09 April 2019 12:51
Arcade / Console --> Amiga conversion discussions dlfrsilver Coders. General 587 04 September 2018 17:11
Pacman / Gridrunner crossover game pickaweapon Looking for a game name ? 4 02 July 2012 23:41
Landover's Amiga Arcade Conversion Contest Frog News 1 28 January 2005 23:41
Old Atari ST ? Game...not sure if there was an Amiga conversion.. HCF Looking for a game name ? 14 17 October 2004 17:43

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:09.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Page generated in 0.12660 seconds with 14 queries