CPCWiki forum

General Category => Games => Topic started by: 40Crisis on 01:16, 04 June 14

Title: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: 40Crisis on 01:16, 04 June 14
When this Pacman emulator was released on the 1st of April 2012,
Many people thought it's was an april fool.

The unbelievable was real !

Some people were complaining that it's was a little bit slow and to address
this problem, they suggest to use the modified rom with hack speed.

Two months after, Syx released the source code which is a fantastic piece of software.

After seeing the Sinclair ZX Spectrum +2A emulator by Simon Owen, I was a little suprised by
the speed difference between the 2 versions.
I had the feeling that the speed could be better on the CPC.

So I began to analyse the code behaviour and timings of the CPC version.
Something that intrigates me was the fact that in game 37% of the
CPU time was wasted in the main loop to wait for the task list to complete.
 
Here's one profile example by address location:

$238d = 17.05 %
$2390 = 6.82 % 
$2391 = 3.41 % 
$2392 = 10.23 %

After numerous checks and measuring timings of what was done in the
interrupt routine ( graphics display, sound rendering, input controls),
I realised that this was done in less than 1/50th of second and the problem was
not in the rendering speed.

It takes me time to understand that the problem was the 300 Hz frequency of interrupts
compared to 50/60Hz frequency of the arcade game. The game rendering timing needed an average
of about three 300 Hz interrupts to be completed.
 
The consequence was that interrupts were often not triggered because interrupts were disable
inside interrupt routine for more than 1/300 s.
This lead to miss some VBL Vblank interrupt.

So I concentrated on the difficult problem: how not to miss VBL Vblank interrupt.
I first tried to tweak interrupt routine but I gave up because it's wasn't the solution.

Finally, I found a very simple solution:
modifing the rom main loop by disabling interrupts,
waiting for vblank, calling original interrupt,disabling interrupts, and then waiting
for task list to complete was much more efficient with little loss in waiting time.

I measured an average of 12.8% CPU time wasted in the waiting part of the main loop.

Now the emulator appears to be much more quicker and smoother.

The only side effect I found is during the display of the main screen were sprites appear for a
brief moment in the middle of the screen, though the modified emulator hasn't been tested much.

In the included archive you will find the pacman. file to put instead of the original one
and the modified source code.

Original source code is at SyX Storage Unit (https://sites.google.com/site/retrocpc/)

Enjoy.
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: SyX on 02:23, 04 June 14
Jejeje, FANTASTIC 40Crisis!!! :D :D :D

I was hacking the code again, because after all the hard work of porting it, we had a bitter aftertaste for the lack of constant speed using the original arcade roms. I was working in two ideas for fixing it, adding a frameskip or fixing the arcade code.

You have made the last and i can only thank you, it's another thing less in the todo list, and one of the things  were burning me more, jejeje, because the state-of-the-art tile and sprite code that i developed for pac-man only were looking at it best in projects of friends (Teodoro, Invasion of the Zombie Monsters V2, 4mhz, ...).

Are you using any special tool for making the profiling or simply counting cycles and making the math?

PS1: I will check if the hack can be used with all the rom hacks too and then i will publish a Pac-Man v1.1 :)

PS2: The fix works in the same pacman hacks than the original (the FAST versions are even funnier now, jejeje).
 
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: 40Crisis on 09:17, 04 June 14
Jejeje, FANTASTIC 40Crisis!!! :D :D :D

I was hacking the code again, because after all the hard work of porting it, we had a bitter aftertaste for the lack of constant speed using the original arcade roms. I was working in two ideas for fixing it, adding a frameskip or fixing the arcade code.

You have made the last and i can only thank you, it's another thing less in the todo list, and one of the things  were burning me more, jejeje, because the state-of-the-art tile and sprite code that i developed for pac-man only were looking at it best in projects of friends (Teodoro, Invasion of the Zombie Monsters V2, 4mhz, ...).

Are you using any special tool for making the profiling or simply counting cycles and making the math?

I modified the arnold emulator to do  statistics on CPU cycles, track I/O locations in memory, track read/write to memory/screen memory,etc.. The problem is that my code is consuming a lot of CPU and need to be optimised.
So the emulator doesn't run at full speed. Another problem is that I'm using the windows version and even without profiling code, directx sound rendering is jerky and comes late.


PS1: I will check if the hack can be used with all the rom hacks too and then i will publish a Pac-Man v1.1 :)

It will depend if the main loop code is at location $238D in all versions


PS2: The fix works in the same pacman hacks than the original (the FAST versions are even funnier now, jejeje).
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: TotO on 09:35, 04 June 14

Great patch Guy!  :-\

As we already said into the past, the next step to improve the speed will be to fix the ROM itself...
But, we don't expect that a few patch should allow a 30% speed-up!!!  :o

It run great now (amazing on a real CPC) as the random frame-drop is now fixed.
That allow it to run always at the speed that we got "sometimes". Thank you!

Now, I have to ask to SyX to swap the score and ghosts texts colours in real time.  :D
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: mr_lou on 18:45, 04 June 14
This is awesome.

I tried it just now on my CPC+. Runs way too fast now of course, because I have to patched ROMs.  :)
Will have to dig up the original ROMs somewhere.
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: redbox on 20:42, 04 June 14
I tried it just now on my CPC+. Runs way too fast now of course, because I have to patched ROMs.  :)

Patched how?
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: mr_lou on 20:52, 04 June 14
Patched how?

I dunno.
The story goes, that the first version of the Pac-Man emulator was a bit too slow, so someone patched the ROM files somehow, making the game run faster, although not with a stable speed. It would slow down at times and run faster at other times.

It seems that now the optimal solution is to run with the original ROM files and this speed patch for the binary instead.
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: SyX on 21:35, 04 June 14
Patched how?
The emulator supports original pacman roms  and bootlegs, one of this bootlegs has a hack that makes pacman goes hyperfast compared with the original arcade.
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: MacDeath on 22:42, 04 June 14
Brilliant !!!
 :o
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: Token on 00:46, 05 June 14
Extremely nice.  8)
Congrats to all of you to make that classic of the classics of arcade to run for real on a CPC.
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: CraigsBar on 00:58, 05 June 14
Pacman emulation on an Amstrad CPC was good before, Now it is amazing. I am hooked all over again.


The extra speed makes this the must have retro game.


I just LOVE it. Great work to all involved. :D


Craig
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: SyX on 05:53, 05 June 14
Thanks everybody for all the nice words. At the end work and life has not let me finish the v1.1 yesterday (today for me yet), but along the day and after everything is tested, it will be available, there is a few extra fixes aside the amazing patch of 40Crisis. For example, the shaking when pacman goes up/down.

I modified the arnold emulator to do  statistics on CPU cycles, track I/O locations in memory, track read/write to memory/screen memory,etc.. The problem is that my code is consuming a lot of CPU and need to be optimised.
So the emulator doesn't run at full speed. Another problem is that I'm using the windows version and even without profiling code, directx sound rendering is jerky and comes late.

I know that arnoldemu has made a lot of improvements since the last release, and i'm sure that when the new version is available, your developing system will improve.

Ah, 40Crisis i have reworked your patch and now the game runs without interrupts at all (only the initialization interrupt, that is executed once). This has let me to save a few more scanlines because i don't need to save/restore any register in the stack in both old interrupt routines, arcade and cpc.

Everything looks more clear now and for example the old cpc interrupt routine is now called cpc_emulation_code. And the only extra optimizations that i can think now is align a few tables to $xxx0 address for change a few 16 bits INCs to 8 bits, but i don't know if i will do or not, because destroy the clarity a little and doesn't save much more cpu time.
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: SyX on 21:08, 05 June 14
As i promised, Pac-Man v1.1 (codename Arcade Edition) is here.

I would like to thank 40Crisis again, because his speed-up hack makes the game totally enjoyable now and because during the process of adding it, let me to add a few extras optimizations and fixes (always great for a hacker mind) and making good the reason because i publish the sources of my projects.

PS: Remember that you need to add the rom files to the DSK.
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: Carnivius on 21:33, 05 June 14

PS: Remember that you need to add the rom files to the DSK.

How do I do this?   I have the arcade rom (from my MAME roms directory) and I can see what I assume to be the four files mentioned in your pacman's readme file but I don't know how to use Winape to put the roms in the dsk.
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: SyX on 21:38, 05 June 14
How do I do this?   I have the arcade rom (from my MAME roms directory) and I can see what I assume to be the four files mentioned in your pacman's readme file but I don't know how to use Winape to put the roms in the dsk.
Go to menu File -> Drive A -> Edit Disc or Shift + Ctrl + F1, and drag and drop the rom files to the dsk.
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: Carnivius on 21:44, 05 June 14
ok I did that and instead of the pacman picture flashing reds it now fades to black but then nothing. 
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: SyX on 21:59, 05 June 14
ok I did that and instead of the pacman picture flashing reds it now fades to black but then nothing. 
Mark the checkbox that put Add/Remove AMSDOS headers.
Must be only that.
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: Carnivius on 22:06, 05 June 14
Mark the checkbox that put Add/Remove AMSDOS headers.
Must be only that.

That seems to have done it.  Thanks! 
Is all working now.  I loves Pac-Man!  :)
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: 40Crisis on 23:10, 05 June 14
As i promised, Pac-Man v1.1 (codename Arcade Edition) is here.

I would like to thank 40Crisis again, because his speed-up hack makes the game totally enjoyable now and because during the process of adding it, let me to add a few extras optimizations and fixes (always great for a hacker mind) and making good the reason because i publish the sources of my projects.


PS: Remember that you need to add the rom files to the DSK.

Many thanks for this new release

Just a question about something I have seen in the game since version 1.0

the ghost sprites when overlapping other ghost or pacman seem to be unmasked (see screen snasphots)
Black color appears not to transparent. But you hardly notice it.

Is it a bug or feature ? ;)

Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: SyX on 23:29, 05 June 14
Many thanks for this new release
You are guilty of making this release possible :D

Just a question about something I have seen in the game since version 1.0

the ghost sprites when overlapping other ghost or pacman seem to be unmasked (see screen snasphots)
Black color appears not to transparent. But you hardly notice it.

Is it a bug or feature ? ;)
Feature!!! :)

My first implementation printed everything as masked sprites (ghost, pacman and fruits), but the framerate was so low that i changed a lot of things, fruits are printed like tiles, ghosts are non-mask sprites and preshifted and only pacman is the only one masked, because our goal was getting the maximum speed possible.

And as you said is difficult to notice it, because your eyes are mainly centered in pacman... and now is even more difficult to see with the extra and constant speed, jejeje.

Another optimization trick related to those efforts in get enough speed, it's that one of the pre-shifted frames of the ghosts lost one pixel column in the right, but during the game is hard to see too, jejeje.

When you can not get enough cpu speed, then is time of doing illusion tricks, jajaja.
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: 40Crisis on 23:56, 05 June 14
You are guilty of making this release possible :D
It's was a pleasure to bring you a sort of proof of concept.

It's always an interesting challenge to understand
how things work and to improve them.

I learned a lot about pacman internals.

By the way, will you publish the updated source code ?
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: MacDeath on 01:29, 06 June 14
I guess it may also be easy to speed up PacMania as well...
it managed a decent speed when you take the speed up... and it can get rid of those numerous useless rasters and "1bpp mask+1bpp graphics" into real Mode1. :P
 ::)
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: Token on 02:45, 06 June 14
Love the new version so much, so thanks a lot. Smooth, fast, feel like the arcade machine, that's amazing.
 :-* :-* :-* :-* :-* :-*
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: SyX on 05:07, 06 June 14
By the way, will you publish the updated source code ?
You can find them in the downloads section of the SyX Storage Unit (https://sites.google.com/site/retrocpc/home) (i need to update that place or pass everything to github or bitbucket, jejeje).
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: Kris on 16:24, 06 June 14
Just test it on CPC+ and it is simply amazing !!! What a big difference between original and last version !
Congrats to all people involved in this nice improvement :)
 
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: TotO on 14:52, 07 June 14
Here my 2cts... This simple program allow to customize the ghosts names.
After running it, the PACMAN.6J ROM is written. (old=PACMAN.BAK)
Ingame, from the TAB menu, chose: GHOSTS NAMES  ALTERNATE

Code: [Select]
5 'PATCH-MAN ALT NAMES V1.0 / 2014 TotO
10 MEMORY &3FFF:LOAD"PACMAN.6J",&4000
20 DIM col$(3,2),name$(3,2),nick$(3,2)
30 FOR j=0 TO 2:FOR i=0 TO 3:READ col$(i,j),name$(i,j),nick$(i,j):NEXT i,j
40 PRINT:PRINT"PAC-MAN ALTERNATE NAMES":PRINT
50 PRINT"1- Enter your own incredible names"
60 PRINT"2- Use my better names than yours"
70 PRINT"3- Use the MIDWAY alternate names"
80 PRINT"4- Use the NAMCO alternate names":PRINT
90 a$=INKEY$
100 IF a$="1" THEN d=2:GOTO 150
110 IF a$="2" THEN d=2:GOTO 200
120 IF a$="3" THEN d=0:GOTO 200
130 IF a$="4" THEN d=1:GOTO 200
140 GOTO 90
150 'enter your names
160 FOR i=0 TO 3
170 PRINT col$(i,d);:INPUT" ghost name: ",name$(i,d)
180 PRINT col$(i,d);:INPUT" ghost nick: ",nick$(i,d)
190 NEXT i
200 'format strings
210 FOR i=0 TO 3
220 WHILE LEN(name$(i,d))<8 : name$(i,d)=name$(i,d)+"@" : WEND
230 t$=nick$(i,d) : IF LEN(t$)>6 THEN t$=MID$(t$,1,6)
240 t$="&"+t$+"&" : WHILE LEN(t$)<8 : t$=t$+"@" : WEND : nick$(i,d)=t$
250 NEXT i
260 'patch rom
270 FOR i=0 TO 3
280 addr=&4DD6+(i*31)
290 FOR c=0 TO 7
300 POKE addr+c,ASC(MID$(name$(i,d),c+1,1))
310 POKE addr+15+c,ASC(MID$(nick$(i,d),c+1,1))
320 NEXT c,i
330 SAVE"PACMAN.6J",b,&4000,4096
340 PRINT:PRINT"PATCH DONE!":PRINT
350 END
360 ' MIDWAY
370 DATA "RED","AAAAAAAA","BBBBBB"
380 DATA "PURPLE","CCCCCCCC","DDDDDD"
390 DATA "BLUE","EEEEEEEE","FFFFFF"
400 DATA "ORANGE","GGGGGGGG","HHHHHH"
410 ' NAMCO
420 DATA "RED","URCHIN","MACKY"
430 DATA "PURPLE","ROMP","MICKY"
440 DATA "BLUE","STYLIST","MUCKY"
450 DATA "ORANGE","CRYBABY","MOCKY"
460 ' CUSTOM
470 DATA "RED","REDMOND","ASCII"
480 DATA "PURPLE","COLCLASH","SPECCY"
490 DATA "BLUE","COMMODO","BREADY"
500 DATA "ORANGE","POKEY","NOISE"


Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: Gryzor on 13:07, 08 June 14
Finally! I can now put a CPC in my arcade cabinet and no one will know... :D

@TotO (http://www.cpcwiki.eu/forum/index.php?action=profile;u=290) : lol, this is just what Pacman was missing :D
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: CraigsBar on 02:27, 11 April 15
Sorry to Dig up a long dead thread. but I thought yu might like to know...


I just No$Cart-ed my copy of PacMan Emulator 1.1 and it works absolutely perfectly in the c4cpc device.


I won't post the resulting image here (due to the copyrighted arcade rom images), but if anyone was thinking of trying it, I can confirm it works.


Regards
Craig
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: TFM on 03:44, 11 April 15
So... time to use the Plus's hardware sprites ;-)

Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: CraigsBar on 03:45, 11 April 15
So... time to use the Plus's hardware sprites ;-)
now I am sure that would be another speed up. And more colours, but for pacman not really *needed*
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: TotO on 10:05, 11 April 15
Has we spoke with SyX two years ago, the PLUS sprites should be fine for a Ms. Pac-Man version that require more complex things to be properly achieved on CPC.
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: TFM on 19:12, 13 April 15
Well, IMHO programs running in Cart should use Plus features, else put em in a regular ROM (or some ROMs), so everybody can use them.  :)
Title: Re: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO
Post by: CraigsBar on 00:04, 14 April 15
Well, IMHO programs running in Cart should use Plus features, else put em in a regular ROM (or some ROMs), so everybody can use them.  :)
Main reason for putting tape or disc software onto cart as I see it.... Carts are even easier (Flashier) than eproms or xmems and of course, where do you connect an xmem to a gx4000?


OK the current no$cart does not produce gx4000 64k workable carts, but @arnoldemu (http://www.cpcwiki.eu/forum/index.php?action=profile;u=122) is working on that (other than patching each one individually) so soon we could have the vast majority og the CPC archive convertable to the gx4000. and with the c4cpc, this is a good thing, extra features used or not.