PSP port of Meritous RELEASED!

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

PSP port of Meritous RELEASED!

Post by Marach »

Hello
I'm making a PSP port of an SDL game Meritous, it's written in C. I compiled it as C++ code, but PSP always crashes with black screen. Meritous uses SDL, SDL_image and SDL_mixer. I have an Ubuntu version of minpspw - a pre-compiled, native PSP Toolchain, but I wrote programs that have proven all libraries are working fine.
I managed to find the crashing line of code by putting fopen("breakpoint.txt", "w"); into different places of code until I found the place where it does not occur.
Here's the source:

Code: Select all

extern "C"
int main(int, char*[])
{
	int on_title = 1;
	int executable_running = 1;
	SDL_Surface *title, *title_pr, *asceai;
	Uint8 *src_p, *col_p;
	int i;
	int light = 0;
	int x, y;
	int pulse[SCREEN_W * SCREEN_H];
	int precalc_sine[400];
	int tick = 10000000;
	int option = 0;
	int can_continue = 0;
	int maxoptions;
	
	int last_key = 0;
	
	int ticker_tick = 0;

	srand(time(NULL));
	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); // THIS LINE CRASHES MY APP!!!!!
	// BREAKPOINT
	fopen("breakpoint.txt", "w");

	screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, BPP, SDL_SWSURFACE);
	
	asceai = IMG_Load("dat/i/asceai.png");
Please, help me, I don't have any clues how to fix that, I tried everything. HEEEEEEEELP...
Last edited by Marach on Mon Jun 01, 2009 6:41 am, edited 4 times in total.
Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

Putting this:
int pulse[SCREEN_W * SCREEN_H];
on the stack is crazy.

Use malloc() instead, and make sure your heap is set big enough.

Jim
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

Post by Marach »

Oww, if I only know what is that "pulse" used for, I'm sure I could eliminate it. What do I use to change heap size?
Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

Try the search on this forum, it's really useful.
PSP_HEAP_SIZE_KB( size of heap in kb).

Jim
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

Post by Marach »

Ok, I will post if that works. What's the max heap value? Just want to be sure :) .
Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
User avatar
Wally
Posts: 663
Joined: Mon Sep 26, 2005 11:25 am

Post by Wally »

I had a crack at this game, but got nowhere as well..

Make sure you resize the images so they fit the PSP Screen.
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

Post by Marach »

Can I use

Code: Select all

typedef int[SCREEN_W*SCREEN_H] pulse_t;
pulse_t& pulse = new pulse_t;
Will it be compatible with existing code?

EDIT: For now I only want that code to run, I will care about the rest later.
Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

Post by Marach »

OMG IT'S WORKING!!!!!!!

Code: Select all

int* pulse = new int[SCREEN_W*SCREEN_H];
This replacement magically made the game working! Big THX for you guys!
Where's the "Helped" button? xDD

EDIT: One thing, what the hell is that?

Code: Select all

warning: unused variable 'sce_newlib_heap_kb_size'
Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

Post by Marach »

At the moment I'm playing a full Meritous PSP port with working graphics, souns and game saving xDDD I never thought I will make it to that point... Just some fiddling with graphics mode and I will release it :) .
Changing thread name...

EDIT: Expect a release today or tomorrow.
Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

Post by Marach »

I need help.
When I run this port in 640x480 resolution everything looks fine, but when I run it in 480x272 everything looks fine too (images are downsized), but text is all shattered. Text position isn't outside the screen, I'm sure it's not because of hardcoded text or image positions. Here's the code:

Code: Select all

void draw_char(int cur_x, int cur_y, int c, Uint8 tcol)
{
	int px, py;
	Uint8 *pix;
	
	for &#40;py = 0; py < 8; py++&#41; &#123;
		pix = &#40;Uint8 *&#41;screen->pixels;
		pix += &#40;py+cur_y&#41;*480;
		pix += cur_x;
		
		if &#40;&#40;cur_x >= 0&#41;&&&#40;py+cur_y >= 0&#41;&&&#40;cur_x < 480-8&#41;&&&#40;py+cur_y < 272&#41;&#41; &#123;
			for &#40;px = 0; px < 8; px++&#41; &#123;
				if &#40;font_data&#91;c&#93;&#91;px&#93;&#91;py&#93; == 255&#41; &#123;
					*pix = tcol;
				&#125;
				if &#40;&#40;font_data&#91;c&#93;&#91;px&#93;&#91;py&#93; < 255&#41;&&&#40;font_data&#91;c&#93;&#91;px&#93;&#91;py&#93; > 0&#41;&#41; &#123;
					*pix = &#40;&#40;int&#41;tcol * font_data&#91;c&#93;&#91;px&#93;&#91;py&#93; / 256&#41; + &#40;&#40;int&#41;*pix * &#40;256-font_data&#91;c&#93;&#91;px&#93;&#91;py&#93;&#41; / 256&#41;;
				&#125;
				pix++;
			&#125;
		&#125;
	&#125;
&#125;
As you can see, this code ingerates into a SDL_Surface pixels structure.
"screen" surface is 8-bit.
Does anybody know what's wrong? Anything but text looks fine...
Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

Post by Marach »

FIXED!
What was happening:

What guy did:
pix = (Uint8 *)screen->pixels;
^^ That sets pointer at the beggining of pixel structure
pix += (py+cur_y)*screen->w;
^^ Pointer is moved a certain number of rows down
pix += cur_x;
^^ Pointer is moved to right

What's wrong in it:
This guy thought that a bytes in a row = screen->w * bpp (bytes per pixel).
That's wrong! To fix this, I needed to replace screen->w by screen->pitch, what is a REAL length of a row.

Now, a question:
Do you already want a 640x480 version streched to 16:9 PSP display, or wait for a fully customized 480x272 version? The first one is ready!
Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

If you want to get fancy, add TV support for the Slim - that's 720x480. If you check the threads here, you'll find a version of SDL I made that automatically handles TV as well as scaling the surface to either the LCD or TV at 16:9 or 4:3.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Why not just render natively at all supported resolutions? Its hardly a graphically taxing game.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Torch wrote:Why not just render natively at all supported resolutions? Its hardly a graphically taxing game.
True, if he uses my SDL lib, he just needs to set the resolution to the regular 640x480 and let SDL take care of scaling it to LCD or TV at 4:3 or 16:9. That's how most of my SDL-based game compiles are done... like the current Duke3D and ROTT.
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

Post by Marach »

Sorry, I won't change SDL lib for 2 reasons:
1. I don't know how hard it's to install on my Ubuntu 9.04 with MinPSPW (precompiled toolchain)
2. The 480x272 port is almost finished! Say a big NO to streching xD

What's working:
- sound
- almost all graphics
- saving / loading (see below)
- minimap (see below)
What's not working:
- help browser
- bosses
Known bugs:
- game won't save after ca. 30 minutes of playing
- minimap doesn't scroll near the edges
- some artifacts are drawn outside the screen

Today I will try to fix all bugs, wish me luck :)
If I manage to fix even one bug, see you on PSPUpdates xDDD
Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

Post by Marach »

I've got some problems, so release will be delayed.
After some seconds after entering a boss battle (Meridian) game freezes and PSP resets. I have no idea what is happening.
Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Try increasing the stack size. The fact that the original code had several hundred KB on the stack right smack in main() tells me it treats the stack like candy. Try something like

PSP_MAIN_THREAD_STACK_SIZE_KB(1024);

That'll give you a MB of stack.
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

Post by Marach »

What do you want? It's C code xD .

I'll edit to say if that works.
If it does, expect a release today.

EDIT: S**t happens. Any ideas? :-/
Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

The usual suspects:
memory leak.
memory corruption.
memory exhaustion.
stack overrun.

No silver bullets here, they're all quite tricky to track down.
You should try to get Tyranid's debugger working, or else you're stuck with debugprintf.


Jim
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

Post by Marach »

Nevermind.
I fixed that bug with cooperation with Asceai himself!
Get ready for the release, coming in hours...
Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

Post by Marach »

Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

hurray another game
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

Post by Marach »

Please, look at my last post in this thread: http://forums.qj.net/psp-development-fo ... s-psp.html
Thank you.
Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
Post Reply