- Top Stats

Top Posters Top Topic Starters Top Topics
Gryzor 2526
TFM 1672
MacDeath 1273
Puresox 1054
arnoldemu 1030
Gryzor 100
Puresox 65
ComSoft612... 63
cpc4eva 55
Xyphoe 53
Converted GX40... - 258952 Views remax 00:14, 05 May 15
R-Type - 95181 Views Keith A Go... 05:08, 25 February 10
Converting a g... - 75952 Views FRAGKI-201... 01:30, 28 March 13
Quick question... - 69269 Views sigh 18:17, 07 December 10
Bubble Bobble ... - 65755 Views Xyphoe 07:54, 05 January 11


Author Topic: SPEED-UP patch FOR Pac-Man emulator for CPC by SyX & TotO  (Read 15360 times)

0 Members and 1 Guest are viewing this topic.

Offline 40Crisis

  • CPC464
  • **
  • Posts: 41
  • Liked: 123
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

Enjoy.

Offline SyX

  • 6128 Plus
  • ******
  • Posts: 1.091
  • Country: br
  • Liked: 1017
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).
 
« Last Edit: 03:19, 04 June 14 by SyX »

Offline 40Crisis

  • CPC464
  • **
  • Posts: 41
  • Liked: 123
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).

Offline TotO

  • 6128 Plus
  • ******
  • Posts: 3.212
  • Country: fr
    • ?area=showdonations;u=4
  • Liked: 2382

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
« Last Edit: 17:17, 04 June 14 by TotO »
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

Offline mr_lou

  • 6128 Plus
  • ******
  • Posts: 2.833
  • Country: dk
    • index.php?action=treasury
    • 8-bit Memoirs - a Blu-ray diskmag-like eBook about the 8-bit era
  • Liked: 1043
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.

Offline redbox

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.751
  • Country: gb
    • redbox
  • Liked: 326
I tried it just now on my CPC+. Runs way too fast now of course, because I have to patched ROMs.  :)

Patched how?

Offline mr_lou

  • 6128 Plus
  • ******
  • Posts: 2.833
  • Country: dk
    • index.php?action=treasury
    • 8-bit Memoirs - a Blu-ray diskmag-like eBook about the 8-bit era
  • Liked: 1043
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.

Offline SyX

  • 6128 Plus
  • ******
  • Posts: 1.091
  • Country: br
  • Liked: 1017
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.

Offline MacDeath

  • Chaotic post writer and mock-up specialist
  • Supporter
  • 6128 Plus
  • *
  • Posts: 4.035
  • Country: fr
  • Liked: 1106
Brilliant !!!
 :o

Offline Token

  • 464 Plus
  • *****
  • Posts: 349
  • Country: fr
  • Liked: 122
Extremely nice.  8)
Congrats to all of you to make that classic of the classics of arcade to run for real on a CPC.

Offline CraigsBar

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.225
  • Country: ie
  • The party ain't over yet
    • index.php?action=treasury
  • Liked: 1146
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

Offline SyX

  • 6128 Plus
  • ******
  • Posts: 1.091
  • Country: br
  • Liked: 1017
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.

Offline SyX

  • 6128 Plus
  • ******
  • Posts: 1.091
  • Country: br
  • Liked: 1017
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.
« Last Edit: 21:12, 05 June 14 by SyX »

Offline Carnivius

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.423
  • Country: gb
  • Mayhem Attack Squad
    • index.php?action=treasury
  • Liked: 1002

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.
Favorite CPC games: SwitchBlade, Stryker in the Crypts of Trogan, Turrican II, UN Squadron, Oh Mummy

Offline SyX

  • 6128 Plus
  • ******
  • Posts: 1.091
  • Country: br
  • Liked: 1017
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.

Offline Carnivius

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.423
  • Country: gb
  • Mayhem Attack Squad
    • index.php?action=treasury
  • Liked: 1002
ok I did that and instead of the pacman picture flashing reds it now fades to black but then nothing. 
Favorite CPC games: SwitchBlade, Stryker in the Crypts of Trogan, Turrican II, UN Squadron, Oh Mummy

Offline SyX

  • 6128 Plus
  • ******
  • Posts: 1.091
  • Country: br
  • Liked: 1017
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.

Offline Carnivius

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.423
  • Country: gb
  • Mayhem Attack Squad
    • index.php?action=treasury
  • Liked: 1002
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!  :)
Favorite CPC games: SwitchBlade, Stryker in the Crypts of Trogan, Turrican II, UN Squadron, Oh Mummy

Offline 40Crisis

  • CPC464
  • **
  • Posts: 41
  • Liked: 123
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 ? ;)


Offline SyX

  • 6128 Plus
  • ******
  • Posts: 1.091
  • Country: br
  • Liked: 1017
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.
« Last Edit: 23:31, 05 June 14 by SyX »

Offline 40Crisis

  • CPC464
  • **
  • Posts: 41
  • Liked: 123
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 ?

Offline MacDeath

  • Chaotic post writer and mock-up specialist
  • Supporter
  • 6128 Plus
  • *
  • Posts: 4.035
  • Country: fr
  • Liked: 1106
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
 ::)

Offline Token

  • 464 Plus
  • *****
  • Posts: 349
  • Country: fr
  • Liked: 122
Love the new version so much, so thanks a lot. Smooth, fast, feel like the arcade machine, that's amazing.
 :-* :-* :-* :-* :-* :-*

Offline SyX

  • 6128 Plus
  • ******
  • Posts: 1.091
  • Country: br
  • Liked: 1017
By the way, will you publish the updated source code ?
You can find them in the downloads section of the SyX Storage Unit (i need to update that place or pass everything to github or bitbucket, jejeje).

Offline Kris

  • 6128 Plus
  • ******
  • Posts: 535
  • Country: fr
  • Team Impact
  • Liked: 194
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 :)