Prince of Persia disassembled

All 680x0 related coding posts in this section please.
ppera

Prince of Persia disassembled

Post by ppera »

It may be interesting for some people.
After seeing how game crappily is coded, I decided that instead patching it (to work on TOS 2.06 and higher) do something what never did: disassembling whole executable (some 110KB, but with holes). It was pretty time consuming, but after all, I got 100% good source file - confirmed by reassembling, what produced exactly same executable, and good work, of course.

What fixed so far? : Stupid keyboard reading routine, very TOS version dependant (reason for 4 bombs right after launch).
Now it is OK for TOS 2.06, 4.02 and 4.04 (in fact, it should be completely rewritten).
Most of problems was because author forced MOVE.B to some data register instead MOVE.W before (An,Dn.w). For some reason (probably that TOS 1.0x kept clean upper half of data register words) it worked on TOS 1.0x versions. But on 2.06 failed right at start: did not found game files. Worse was later - game corrupted itself, writing to some wrong addresses. Then some graphic errors were when achieved to start game. All in all, I fixed over 100 locations, and it now works fine under TOS 2.06. On Falcon there are still some freeze (I fixed PSG code for Falcon too, as sound was very knacky).

In attachment is source of original, without modifications. Who wants to play under TOS 2.06 and test on Falcon get corrected version here:

http://www.ppest.org/atari/fromhd.php

Someone to make training options: unlimited time, not to start level at beginning after die, and similar ? :D
You do not have the required permissions to view the files attached to this post.
User avatar
bullis1
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2301
Joined: Tue Dec 12, 2006 2:32 pm
Location: Canada
Contact:

Re: Prince of Persia disassembled

Post by bullis1 »

While this rarely ever happens with source releases/disassemblies, it would be cool if someone were to enhance the game somehow aside from fixes. I always found PoP boring because the scenery never really changed and it didn't have much going one. If someone were to add stuff to the game, like new puzzles, an optional new soundtrack, a variety of scenes, etc. that would be awesome. It's not likely to happen but it's just a thought.
Member of the Atari Legend team
User avatar
Stefan jL
Atari God
Atari God
Posts: 1316
Joined: Thu May 09, 2002 3:21 pm
Location: Sweden
Contact:

Re: Prince of Persia disassembled

Post by Stefan jL »

Maybe someon could enhance it by optimise the code a bit so there is less slowdowns :)
Image
simonsunnyboy
Forum Administrator
Forum Administrator
Posts: 5834
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: Prince of Persia disassembled

Post by simonsunnyboy »

Considering the small amount of moving/animated areas and sprites, it is a big mystery why there are slowdowns at all....Ppera's crack seems to work pretty good sofar (only played up to Level 4)
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
User avatar
bullis1
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2301
Joined: Tue Dec 12, 2006 2:32 pm
Location: Canada
Contact:

Re: Prince of Persia disassembled

Post by bullis1 »

simonsunnyboy wrote:Considering the small amount of moving/animated areas and sprites, it is a big mystery why there are slowdowns at all...
I think it's safe to assume that the culprit is, ahem, less-than-optimal coding. It's been a very long time since I played the ST version. In what cases does it slow down? Is it when there are many traps on screen, or is it because of the Prince's complex animations?
Member of the Atari Legend team
simonsunnyboy
Forum Administrator
Forum Administrator
Posts: 5834
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: Prince of Persia disassembled

Post by simonsunnyboy »

The animations are not complex. It is just a cartoon sequence where the program has to change a single pointer to display another image next time - there is no complex stuff involved.
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
ppera

Re: Prince of Persia disassembled

Post by ppera »

Poor coding is reason, for sure. Even on Falcon it slowdowns sometimes too much (at 16MHz), although on that is unplayable fast in most of time, so need to start it at 8MHz, cache off.
Really should not slowdown at all, considering small part od screen moving.

Making it better would be nice thing, no doubt. Who is experienced here in game programming? Nyh ? :D
User avatar
Stefan jL
Atari God
Atari God
Posts: 1316
Joined: Thu May 09, 2002 3:21 pm
Location: Sweden
Contact:

Re: Prince of Persia disassembled

Post by Stefan jL »

The slowdowns happen when samples are played... for example when a gate closes there is a huge slowdown because of the continues samples being played.
Image
User avatar
bullis1
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2301
Joined: Tue Dec 12, 2006 2:32 pm
Location: Canada
Contact:

Re: Prince of Persia disassembled

Post by bullis1 »

Stefan jL wrote:The slowdowns happen when samples are played... for example when a gate closes there is a huge slowdown because of the continues samples being played.
I didn't remember that it uses sampled sound. Surely nowadays there are much more efficient replay routines that could be used if someone were so inclined.
Member of the Atari Legend team
User avatar
Mug UK
Administrator
Administrator
Posts: 12306
Joined: Thu Apr 29, 2004 7:16 pm
Location: Stockport (UK)
Contact:

Re: Prince of Persia disassembled

Post by Mug UK »

Patch it so it uses the DMA for STE/TT/Falcon sample replay?
Main site: www.mug-uk.co.uk - digging up bits from my past: Atari ST, ZX Spectrum, Sega 8-bit (game hacks) and NDS (ripping guides). I host a C64 Radio Show for a mate, Max Hall via www.chipsidshow.co.uk

I develop a free Word (for Windows) add-in for Word 2007 upwards. A toolbox that will allow power Word users to fix document errors. You can find it at: mikestoolbox.co.uk
simonsunnyboy
Forum Administrator
Forum Administrator
Posts: 5834
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: Prince of Persia disassembled

Post by simonsunnyboy »

It's probably faster to rewrite the whole game instead of trying to patch an obviously technical inferior code base.
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
User avatar
darklight
Captain Atari
Captain Atari
Posts: 309
Joined: Mon May 08, 2006 7:53 pm
Location: Brisbane
Contact:

Re: Prince of Persia disassembled

Post by darklight »

It would be very very cool if someone could read the source code, then document the level definition files (I'm presuming that data is stored in files?) and also the level graphics files.

With this information, we could develop a level editor and a way of replacing the graphics.

Then, it shouldnt be too hard to make a copy of the POP files, replace level & graphics data with homebrew versions, and hey presto! - multiple new POP games for the ST.
Storm Clouds over the Western Front - my WW1 2D dogfighting game for windows
2D Flight Sims - side scrolling aerial combat games
User avatar
Champions_2002
Atari Super Hero
Atari Super Hero
Posts: 592
Joined: Fri May 31, 2002 8:14 am
Location: Manchester England

Re: Prince of Persia disassembled

Post by Champions_2002 »

Find this website about the prince of persia

http://www.popuw.com
A member of Atarimania ST & 7800 department
ppera

Re: Prince of Persia disassembled

Post by ppera »

Champions_2002 wrote:Find this website about the prince of persia

http://www.popuw.com
For me it is forbidden. I shouldn't do that disassembling... :D

Btw. lot of ideas here. Using DMA sound on STE, Falcon sounds good, but changing audio in so messy code is surely lot of work - must first understanding pretty large part of code.
User avatar
Nyh
Atari God
Atari God
Posts: 1533
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: Prince of Persia disassembled

Post by Nyh »

ppera wrote:Poor coding is reason, for sure. Even on Falcon it slowdowns sometimes too much (at 16MHz), although on that is unplayable fast in most of time, so need to start it at 8MHz, cache off.
Really should not slowdown at all, considering small part od screen moving.

Making it better would be nice thing, no doubt. Who is experienced here in game programming? Nyh ? :D
Well there is poor coding involved indeed! Just out of interest I looked at the sample play routine:

Code: Select all

sample_end:
	move	sr,-(a7)
	ori.w	#$700,sr
	clr.b	$FFFFFA19.w
	bclr	#5,$FFFFFA07.w
	bclr	#5,$FFFFFA13.w
	bclr	#5,$FFFFFA0B.w
	bclr	#5,$FFFFFA0F.w
	move.w	(a7)+,sr
	rts

Sample_play:
	movem.l	d0-d1/a0,-(a7)
	movea.l	l47FE0,a0             ; sample pointer
	cmpa.l	l47FE4,a0             ; sample end
	bcs.s	play_sample           ; play sample
	tst.w	l47FE8                ; repeat?
	bne.s	reset_sample_p        ; yep
	bsr.s	sample_end
	bra.s	Sample_play_end
reset_sample_p:
	movea.l	l47FDC,a0             ; reset sample pointer
play_sample:
	moveq	#0,d0
	move.b	(a0)+,d0
	addi.b	#$80,d0               ; convert signed/unsigned sample (!!!!)
	move.l	a0,l47FE0
	lsl.w	#3,d0
	lea	digi_tab(pc),a0
	adda.w	d0,a0
	move.l	(a0)+,d0
	move.w	(a0)+,d1
	movea.w	#$8800,a0
	movep.l	d0,0(a0)
	movep.w	d1,0(a0)
	bclr	#5,$FFFFFA0F.w
Sample_play_end:
	movem.l	(a7)+,d0-d1/a0
	rte
I am not 100% sure whether this is the main sample play routine because the digi_tab is used at multiple places but there is some room to optimize. First rearrange the memory a bit so important stuff becomes local. Swap the digi_tab so the sign is fixed in the table instead of calculating it during replay, try to use registers a bit more efficient and rearrange some instructions and you get something like this:

Code: Select all

sample_end:
	move	sr,-(a7)
	ori.w	#$700,sr
	clr.b	$FFFFFA19.w
	bclr	#5,$FFFFFA07.w
	bclr	#5,$FFFFFA13.w
	bclr	#5,$FFFFFA0B.w
	bclr	#5,$FFFFFA0F.w
	move.w	(a7)+,sr
	move.l	(a7)+,a0
	rte

Sample_play:
	move.l  a0,-(a7)              ; save a0
	movea.l	sample_ptr(pc),a0     ; sample pointer
	cmpa.l	sample_ptr_end(pc),a0 ; sample end?
	bcs.s	play_sample           ; play sample
	tst.w	sample_repeat(pc)     ; repeat?
	beq.s	sample_end            ; nope
reset_sample_p:
	movea.l	sample_start(pc),a0   ; reset sample pointer
play_sample:
	move.l	d0,-(a7)              ; save d0 and d1
	move.w  d1,-(a7)
	moveq	#0,d0
	move.b	(a0)+,d0
	move.l	a0,sample_ptr         ; save updated sample ptr
	lsl.w	#3,d0
	lea	digi_tab(d0.w,pc),a0
	move.l	(a0)+,d0
	move.w	(a0)+,d1
	lea     $FFFFFA0F.w,a0
	movep.l	d0,-$720F(a0)
	movep.w	d1,-$720F(a0)
	bclr	#5,(a0)
	move.w  (a7)+,d1
	move.l  (a7)+,d0
	move.l  (a7)+,a0
	rte

sample_start:
	DC.B	0,0,0,0
sample_ptr:
	DC.B	0,0,0,0
sample_ptr_end:
	DC.B	0,0,0,0
sample_repeat:
	DC.B	0,0,0,0,0,0

digi_tab:
	DC.B	8,$E,9,$D,$A,$C,0,0
	DC.B	8,$F,9,3,$A,0,0,0
.....
I didn't try to compile it but is should work more or less. If the other routines use nonsigned samples just duplicate the digi_tab for the sake of speed.

Usually you can better rewrite a game then try to patch it to make it faster. But stupid sample play routines are fixable.

Hans Wessels
ppera

Re: Prince of Persia disassembled

Post by ppera »

Nyh wrote: Well there is poor coding involved indeed! Just out of interest I looked at the sample play routine:
...
lea $FFFFFA0F.w,a0
movep.l d0,-$720F(a0)
movep.w d1,-$720F(a0)
...
I will check your changes when get again enough crazy to bother with this creation :D
Btw. for Falcon must not use long write in PSG registers - it will crash machine if no STE bus emul. set. Otherwise will make knocky sound, and here really is such.
I changed it to wordwise write 2x - on some 6 locations in game as author likes to make lot of similar routines...
I think that faster is this:
a0: buffer
a1: 8800.w
move.w (a0)+,(a1) - 3 times
User avatar
Nyh
Atari God
Atari God
Posts: 1533
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: Prince of Persia disassembled

Post by Nyh »

ppera wrote:Btw. for Falcon must not use long write in PSG registers - it will crash machine if no STE bus emul. set. Otherwise will make knocky sound, and here really is such.
I changed it to wordwise write 2x - on some 6 locations in game as author likes to make lot of similar routines...
I think that faster is this:
a0: buffer
a1: 8800.w
move.w (a0)+,(a1) - 3 times
Forgot about the Falcon. You are right. But if you are going to use the move.w you will have to double the size of the digitable. And then I would use move.w (a0)+,8800.w three times. Using 3 times 8800.w costs 12 cycles extra. Saving and restoring a register will cost at least 16 cyles, another 8 for loading the register...

If you are willing to share your fixed source with me I will try to fix some of the speed problems. I haven't got a real STe or Falcon to test so compatibiliry problems are hard for me to fix but with an ST I can fix most speed problems I think.

Hans Wessels
ppera

Re: Prince of Persia disassembled

Post by ppera »

Yes... I was in rush yesterday, and wrote only fast ideas. But maybe even 6x move.b (a0)+,(a1) is faster than moving to data and 3x movep ... However, this is certainly not some speed critical part, as executes not so frequently.
I used as quick fix for Falcon:
swap dn
movep.w dn...
swap dn
movep.w dn..

instead 1x movep.l dn ....

I need to finish fixing of problematic 'move.b' instead 'move.w ' or often needed to put 'and.w #$00FF,dn' ....
Then I post you fixed source. There is a chance that it will work after those fixes good (not freezing) on Falcon, of course with slowdowns...
punkrulesok
Captain Atari
Captain Atari
Posts: 240
Joined: Tue Aug 05, 2003 7:34 pm

Re: Prince of Persia disassembled

Post by punkrulesok »

You should check out the Megadrive version of POP. It's everything that an "upgraded" ST version should be; better GFX, SFX and no slowdowns! Maybe it's worth looking into before anyone tries to patch the ST version?
User avatar
Champions_2002
Atari Super Hero
Atari Super Hero
Posts: 592
Joined: Fri May 31, 2002 8:14 am
Location: Manchester England

Re: Prince of Persia disassembled

Post by Champions_2002 »

just found this fan website for POP

http://www.poplegacy.com/

and another
http://www.princed.org/

this one show you how to make new mods for the game
A member of Atarimania ST & 7800 department
mikro
Hardware Guru
Hardware Guru
Posts: 4723
Joined: Sat Sep 10, 2005 11:11 am
Location: Kosice, Slovakia
Contact:

Re: Prince of Persia disassembled

Post by mikro »

ppera wrote: http://www.ppest.org/atari/fromhd.php

Someone to make training options: unlimited time, not to start level at beginning after die, and similar ? :D
Hi Ppera,

nice work here. Did you decide to challenge Dbug guys? ;-)
ppera

Re: Prince of Persia disassembled

Post by ppera »

mikro wrote: Hi Ppera,
nice work here. Did you decide to challenge Dbug guys? ;-)
Not exactly. I do adaptations at mine taste and for old games from my collection, what I played. There is couple exception - as SImulcra, what didn't see earlier, but looks very nice.

This disassembling was in moment of madness. I didn't know how long it will take. It took 2 days, but I think that because of messy code. Some better coded would be done much faster.
Actually, I did at least 5-6 other disassembles, but short loader programs, max 10KB long. It was much faster, in time/length too.

Soon I will start new page, about adaptations - what are common reasons for not running on some TOS, platform, from hard disk, with examples, solutions. Some sources. Will be interactive table with adapted games - visitors may add there new entries, comments.
mikro
Hardware Guru
Hardware Guru
Posts: 4723
Joined: Sat Sep 10, 2005 11:11 am
Location: Kosice, Slovakia
Contact:

Re: Prince of Persia disassembled

Post by mikro »

ppera: cool, go ahead! :)

i just wish you update / make more readable your web, for example there's no way (or i'm blind) to find this page (about hd patched games) from http://ppest.org, some of your sub-pages link to stuff which is again accessible only from there... i'm having constant problems to find any concrete information when i return back to your (great from information point of view) site :)
ppera

Re: Prince of Persia disassembled

Post by ppera »

mikro wrote:ppera: cool, go ahead! :)

i just wish you update / make more readable your web, for example there's no way (or i'm blind) to find this page (about hd patched games) from http://ppest.org, some of your sub-pages link to stuff which is again accessible only from there... i'm having constant problems to find any concrete information when i return back to your (great from information point of view) site :)
There is link to hd patched games only on ImgRun page, and not too visible. I have some scrupules about it - maybe some problems because of still copyrighted titles ?
Yes, there is a need to update it, make better readable and better looking. And even title of page is not really correct.
It is not only hard disk adaptation but TOS version, Falcon adaptation too. Actually, often more time is spent on latest 2 than with adapting for hard disk. And I still discover some new troubles with games - authors were very 'effective' to ensure it not to work under later TOS versions :D

This is still not linked (need to polish, expand):
http://www.ppest.org/atari/playfhd.html
AAmbrosio
Atarian
Atarian
Posts: 2
Joined: Wed Nov 29, 2017 5:26 pm

Re: Prince of Persia disassembled

Post by AAmbrosio »

I´m writing a Prince of Persia for MSX system. I'm having a hard time re-creating the sounds of game.
As MSX use the PSG AY-3-8910 (same as YM-2149 of Atari ST) I think to use the disassembled code for find the sequence of sounds commands.
Unfortunately I don't know the assembler 68000 and I don't find the code.
Someone can help me. Information where are the play sound subroutine and the commands sequences of PSG.
Post Reply

Return to “680x0”