SDLPoP; David's open-source port of PoP

Open-source port of PoP that runs natively on Windows, Linux, etc.
Post Reply
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: David's open-source port of PoP (pre-release)

Post by David »

Did you try one of the solutions on that page?
The simplest would be this: "or you can add the MinGW\bin directory to the system path."

~~~~

Here is the new version.

Changes:
FIXED: Pressing "K" on a skeleton crashes the game.
DONE: The game will play digi sounds (only from DAT files)
Attachments
PORT_PoP_v1.08.zip
(1 MiB) Downloaded 357 times
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: David's open-source port of PoP (pre-release)

Post by Norbert »

Ah, sound effects. :) I played through the game and here's what I noticed:
- For some the pitch is off, for example for the level door opening (very clear) and the prince footsteps (less noticeable).
- I had the feeling that, now and then, not enough sound effects played at the same time. For example, two opening or two closing gates should emit alternating ticks, but if I'm not mistaken they don't in the conversion.
- I think the skeleton that comes alive in level 3 has a sound effect, but I didn't hear this in the conversion. Maybe another sound effect was playing during that animation (see issue above).
- In level 5 I tried trick 35 but instead of teleporting to the left of the gate in the room to the left (8) I got teleported to the room to the right (9).
- During the intro cinematic, when Jaffar opens the palace door the game quits with a "SDL_BuildAudioCVT: " message, shortly after playing (part of?) what appears to be an incorrect sound effect, namely a gate tick.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: David's open-source port of PoP (pre-release)

Post by David »

Norbert wrote: - For some the pitch is off, for example for the level door opening (very clear) and the prince footsteps (less noticeable).
This should be the same thing I mentioned here: viewtopic.php?p=14600#p14600 (that post and the next)
I might add something to mimic the limited selection of sample rates of the Sound Blaster, but that's not the only difference.
Norbert wrote: - I had the feeling that, now and then, not enough sound effects played at the same time. For example, two opening or two closing gates should emit alternating ticks, but if I'm not mistaken they don't in the conversion.
The original PoP can play only one sound effect at the same time.
However, a sound may interrupt another one, if the current sound is marked as interruptible (in sound_interruptible[]) and the new sound has higher priority than the current (smaller number in sound_prio_table[]).
I copied this into the conversion.

Note that if two gates are opening or closing at the same time (triggered by the same button), then they just tick at the same time.
For alternating ticks you need some difference between the gates.
An opening gate ticks in every second frame.
A closing gate ticks in every fourth frame.

I could reproduce the alternating closing sounds in the conversion in the first room of level 10.
First, press the button at the bottom. When the gates begin to close, press the button above the right gate.
Then wait until the right gate starts to close again.

However, SDL has something called "size of the audio buffer" (desired->samples).
I don't know if SDL_PauseAudio(1) waits until the whole buffer is played.
If it does then it may affect the interrupting.

Anyhow, I think it affects the checking of whether a sound ended.
Currently, my code sends an event from digi_callback() if there is no more output data.
This is usually *after* the sound has ended, but the difference is not more than the size of the buffer divided by the output frequency.
Currently it's 512 / 22050 Hz ~ 0.023 s.
Norbert wrote: - I think the skeleton that comes alive in level 3 has a sound effect, but I didn't hear this in the conversion. Maybe another sound effect was playing during that animation (see issue above).
Yes, it has a sound effect, and it is played for me.
Norbert wrote: - In level 5 I tried trick 35 but instead of teleporting to the left of the gate in the room to the left (8) I got teleported to the room to the right (9).
I tried it now, you're right.
I added this to my bugs.txt so I won't forget it.
And I found yet another bug while I tried that:
If you back out from the room where the guard is originally (but the screen is not switched), the kid might fall through the floor at the level door.
Norbert wrote: - During the intro cinematic, when Jaffar opens the palace door the game quits with a "SDL_BuildAudioCVT: " message, shortly after playing (part of?) what appears to be an incorrect sound effect, namely a gate tick.
That also happens to me.
If you listen the original game carefully, the gate tick is there, but it's immediately followed by the other sound.

The error message means that SDL_BuildAudioCVT() did not succeed (its return value is not 1), and it gives an empty error message.
It might be related to the sample rate of that one sound. (14000 Hz)
I added a debug printout to show the return value of SDL_BuildAudioCVT(), and it's 0.

The SDL 1.2 doc says "Returns -1 if the filter could not be built or 1 if it could.".
So the documentation does not cover all cases.
However, the SDL 2.0 doc says "Returns 1 if the audio filter is prepared, 0 if no conversion is needed, or a negative error code on failure; call SDL_GetError() for more information.".

So now I modified the code to accept both 0 and 1 as success.
(But "no conversion is needed" sounds strange in this case. The sound is 14000 Hz, the output is 22050 Hz.)

Code: Select all

	SDL_AudioCVT cvt;
	memset(&cvt, 0, sizeof(cvt));
	int result = SDL_BuildAudioCVT(&cvt,
		AUDIO_U8, 1, buffer->digi.sample_rate,
		digi_audiospec->format, digi_audiospec->channels, digi_audiospec->freq
	);
	if (result != 1 && result != 0) {
		sdlperror("SDL_BuildAudioCVT");
		printf("(returned %d)\n", result);
		quit(1);
	}
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: David's open-source port of PoP (pre-release)

Post by David »

(level 5)
David wrote:If you back out from the room where the guard is originally (but the screen is not switched), the kid might fall through the floor at the level door.
First, I found out how to reproduce this reliably:
Repeat this: Press left and esc together, then press esc again.

The "throughfloor_opendoor" bug can be reproduced in the original game in the same way.

I think I found what is causing the bug.

check_on_floor() (in seg006.c) calls get_tile_at_char().
At that point, Char.room = 9, Char.curr_col = 9, Char.curr_row = 2. (Why?)
The tile at that position is a wall.
So the following functions are called: in_wall(), load_fram_det_col(), determine_col(), get_tile_div_mod_m7(), get_tile_div_mod().
get_tile_div_mod() is called with xpos = -14. But it uses xpos as an array index!
Accessing an out-of-range element of an array might return different values in the original game and in the conversion.

Those arrays are used for converting xpos into a tile column, and a position within the tile.
So I replaced array accesses with division and modulo.

This also fixes the original bug you wrote about.

Code: Select all

int __pascal far get_tile_div_mod(int xpos) {
	// xpos might be negative if the kid is far off left.
	// In this case, the array index overflows.
/*	if (xpos < 0 || xpos >= 256) {
		printf("get_tile_div_mod(): xpos = %d\n", xpos);
	}*/
//	obj_xl = tile_mod_tbl[xpos];
//	return tile_div_tbl[xpos];
	int x = xpos - 58;
	int xl = x % 14;
	int xh = x / 14;
	// Integer division rounds towards zero, but we want to round down.
	if (x < 0 && xl != 0) {
		--xh;
	}
	// Modulo returns a negative number if x is negative, but we want 0 <= xl < 14.
	if (xl < 0) {
		xl += 14;
	}
	obj_xl = xl;
	return xh;
}
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: David's open-source port of PoP (pre-release)

Post by Norbert »

David wrote:Yes, I know that the current "name" is a bit long. :)
But I don't know what/which name to choose.
Let's use DOSPoP.
That is David's Open-Source Port of PoP, as you describe the conversion, and as a bonus it includes references to the Disk Operating System (DOS) and Prince of Persia (PoP).
An obvious choice, short, to the point, easy to pronounce, easy to remember, and probably the most logical choice.
A verbatim(!) Google search for 'dospop "prince of persia"' currently returns just three hits, one of which is a post about the abbreviation on this forum.
This should make it easy for anyone to find mentions of the conversion in the future.
Agreed? Anyone who thinks this name/abbreviation is a bad choice?
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: David's open-source port of PoP (pre-release)

Post by Norbert »

Or maybe SDLPoP, or something else with SDL in it, but then you need to make sure to never switch libraries. :)
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: David's open-source port of PoP (pre-release)

Post by David »

DOSPoP: I am still concerned about confusion with the original DOS PoP, especially if they are mentioned together.
SDLPoP: At least there is no confusion here. I don't think I will switch libraries. (Except possibly to SDL2, for the better fullscreen support. -- But that's still SDL.)
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: SDLPoP; David's open-source port of PoP (pre-release)

Post by Norbert »

All right, SDLPoP.
Added it here: http://www.popot.org/get_the_games.php?game=SDLPoP
And here: http://www.princed.org/downloads/
Also added it to this thread's subject.
Near "We are currently converting the game to Windows and Linux: [...]" in the final 25th anniversary text I will add "SDLPoP: " and "PoP.NET: " in front of the URLs.
In future news entries on the Princed home page, Facebook, Twitter, and so on, I'll also use SDLPoP (in addition to a short description of what it entails).
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: SDLPoP; David's open-source port of PoP (pre-release)

Post by David »

Here is the new version.

Changes:
FIXED: The game quits in the intro, when Jaffar opens the door.
FIXED: When doing the level 5 trick (backing through the gate), the kid appears in the room to the *right* instead of left.
FIXED: Level 5: If you back out from the room where the guard is originally (but the screen is not switched), the kid might fall through the floor at the level door.
Renamed the project to SDLPoP.
DONE: Added version number to the window title.
Attachments
SDLPoP_v1.09.zip
(1 MiB) Downloaded 344 times
salvadorc17
Calif
Calif
Posts: 553
Joined: August 27th, 2011, 2:04 am

Re: SDLPoP; David's open-source port of PoP (pre-release)

Post by salvadorc17 »

Good choice for name "Sdl POP" because this clearly references that is open source, and free liscence???
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: SDLPoP; David's open-source port of PoP (pre-release)

Post by Norbert »

salvadorc17 wrote:Good choice for name "Sdl POP" because this clearly references that is open source, and free liscence???
Not all programs and games created with the SDL library are open-source or free software.
SDL 1.2 is LGPL licensed and SDL 2 uses the zlib License. Both licenses allow use with proprietary software.
An example of a proprietary program that uses it is the Steam client, and an example of a proprietary game is Don't Starve.
salvadorc17
Calif
Calif
Posts: 553
Joined: August 27th, 2011, 2:04 am

Re: SDLPoP; David's open-source port of PoP (pre-release)

Post by salvadorc17 »

Ok, my mistake, but this is really good work anyway for David, then sdl is for cross-platforms???
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: SDLPoP; David's open-source port of PoP (pre-release)

Post by David »

StaticReturn sent me some changes (in a PM) that make it possible to compile the game undex Mac OS X.
(I don't have Mac OS X, so I can't try it.)
Here is the new version.

Changes:
FIXED: Made the game compatible with Mac OS X, based on the suggestions by StaticReturn.
FIXED: Fixed most things that caused compiler warnings. (For example: overflow in implicit constant conversion.)
CHANGE: Now cheats are disabled by default unless the game is compiled in debug mode.
Attachments
SDLPoP_v1.10.zip
(1 MiB) Downloaded 304 times
StaticReturn
Efendi
Efendi
Posts: 13
Joined: September 2nd, 2014, 4:14 am

Re: SDLPoP; David's open-source port of PoP (pre-release)

Post by StaticReturn »

Here's the OS X version of SDLPoP that should run on Mac computers that don't have SDL installed. I only have my laptop for testing, so I make no promises that it will work on your computer.

Also, you should avoid running programs from untrusted sources. I trust me, but you shouldn't until I've earned that trust. So I suggest those who want to play Prince of Persia on a Mac should download the source code and build their own binary.

Have Fun!

-SR

PS: A new Makefile for OSX
Spoiler: show
# Makefile for OSX
#
# If your SDL libraries are not installed under /opt/local/ you will have to replace those paths with your own.
# CFLAGS is the result of -DOSX and the output of the command 'sdl-config --cflags'.

CC = clang
CFLAGS = -DOSX -I/opt/local/include -D_GNU_SOURCE=1 -D_THREAD_SAFE
LDFLAGS = `sdl-config --libs` -lSDL_image
LDSTATIC = `sdl-config --static-libs` /opt/local/lib/libSDL_image.a
OBJ = main.o data.o seg000.o seg001.o seg002.o seg003.o seg004.o seg005.o seg006.o seg007.o seg008.o seg009.o
HFILES = common.h config.h data.h proto.h types.h

# Create a dynamically linked binary.
prince: $(OBJ)
$(CC) -o prince $^ $(LDFLAGS)

# Create a satically linked binary.
static: $(OBJ)
$(CC) -o prince $^ $(LDSTATIC)

%.o: %.c $(HFILES)
$(CC) -c $< $(CFLAGS)

clean:
rm -rf $(OBJ) prince
Attachments
prince.zip
(227.98 KiB) Downloaded 318 times
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: SDLPoP; David's open-source port of PoP (pre-release)

Post by David »

StaticReturn wrote: I trust me, but you shouldn't until I've earned that trust.
Now that's something that we don't hear often.
StaticReturn wrote: PS: A new Makefile for OSX
I think the forum deleted the tabs from that. (But they are there if I look at the source of your post by quoting it.)
Post Reply