Controller Issues (n00b Question)

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

Moderators: cheriff, TyRaNiD

Post Reply
Energy
Posts: 133
Joined: Sat Mar 26, 2005 4:13 pm
Location: uk/beds/flitwick
Contact:

Controller Issues (n00b Question)

Post by Energy »

Hey
My pong game is slowly getting there -- I've added in Skippy's Controller lib. Yet I haven't managed to get it to work yet. could someone give me a really simple breakdown of how to use it. I can get responses with the Control function however it freezes the game until a button is pressed... Not much fun in pong :/

soz for the n00b question but I'm trying to learn! :)

Thanks
Hippo
Posts: 19
Joined: Sat Jun 25, 2005 10:51 am

Post by Hippo »

It looks to me like skippy911's Control function probably waits for input until doing anything.

Try changing this bit of code in controller.c:

Code: Select all

while(1) {
	key = Read_Key();
	if (key != 0) break;
	pgWaitV();
}
... to something like:

Code: Select all

key = Read_Key();
if (key == 0) return 0;
Looks like you won't pick up all/most input in one frame doing that, though. Try playing around with controller.c until it suits your needs, I guess. (I suggest returning "key" from Control and doing some if-then magic where the input is used... but then again, I might be completely off track.)
User avatar
Agoln
Posts: 326
Joined: Wed Jun 08, 2005 3:14 am
Location: Fort Wayne, IN

Post by Agoln »

Is skippy's controller lib non-blocking? Cause if it's a blocking funcion, it will ALWAYS do that... If it's non-blocking, then it's something where you have to loop always and forever in a "do i have input" "if i do, then do it"
Energy
Posts: 133
Joined: Sat Mar 26, 2005 4:13 pm
Location: uk/beds/flitwick
Contact:

Post by Energy »

ok well Hippo's idea has worked. Not the most responsive, but it does the job for now. :)

Ok this is a serious n00b question - how do I get PgPrint to display a integer value on the screen? Want my score to display! :D lol
*looks very embarrased*
Hippo
Posts: 19
Joined: Sat Jun 25, 2005 10:51 am

Post by Hippo »

Energy wrote:ok well Hippo's idea has worked. Not the most responsive, but it does the job for now. :)

Ok this is a serious n00b question - how do I get PgPrint to display a integer value on the screen? Want my score to display! :D lol
*looks very embarrased*
I use a slightly modified version of the sprintf implementation that Doom(-PSP) uses:

Code: Select all

// sprintf.c
/****************************************************************
Copyright (C) 1997 Lucent Technologies
All Rights Reserved

Permission to use, copy, modify, and distribute this software and
its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of Lucent or any of its entities
not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.

LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
****************************************************************/

/* This is for Sun (and other systems with brain-damaged sprintf that
 * doesn't return the count of characters transmitted).
 * It implements only the relevant subset of sprintf.
 * With ANSI C (and other sensible systems), you can omit Sprintf.o
 * if you add -DSprintf=sprintf to CFLAGS (in the makefile).
 */

#include <stdio.h>
#include <string.h>



#ifdef KR_headers
#ifndef size_t__
#define size_t int
#define size_t__
#endif

#include "varargs.h"

#else

#include "stddef.h"
#include "stdarg.h"
#include "stdlib.h"

#endif
#ifdef __cplusplus
extern "C" &#123;
#endif

 static void
bad
#ifdef KR_headers
&#40;fmt&#41; char *fmt;
#else
&#40;const char *fmt&#41;
#endif
&#123;
	//printf&#40;"bad fmt in Sprintf, starting with "%s"\n", fmt&#41;;
	&#125;

#define put&#40;x&#41; *outbuf++ = x

 int
sprintf
#ifdef KR_headers
	&#40;va_alist&#41;
 va_dcl
#else
	&#40;char *outbuf, const char *fmt, ...&#41;
#endif
&#123;
	char *ob0, *s;
	char buf&#91;32&#93;;
	va_list ap;
	long i, j;

#ifdef KR_headers
	char *outbuf, *fmt;
	va_start&#40;ap&#41;;
	outbuf = va_arg&#40;ap, char*&#41;;
	fmt = va_arg&#40;ap, char*&#41;;
#else
	va_start&#40;ap, fmt&#41;;
#endif
	ob0 = outbuf;
	for&#40;;;&#41; &#123;
		for&#40;;;&#41; &#123;
			switch&#40;i = *fmt++&#41; &#123;
				case 0&#58;
					goto done;
				case '%'&#58;
					break;
				default&#58;
					put&#40;i&#41;;
					continue;
				&#125;
			break;
			&#125;
		switch&#40;*fmt++&#41; &#123;
			case 'c'&#58;
				i = va_arg&#40;ap, int&#41;;
				put&#40;i&#41;;
				continue;
			case 'l'&#58;
				if &#40;*fmt != 'd'&#41;
					bad&#40;fmt&#41;;
				fmt++;
				i = va_arg&#40;ap, long&#41;;
				goto have_i;
			case 'd'&#58;
				i = va_arg&#40;ap, int&#41;;
 have_i&#58;
				if &#40;i < 0&#41; &#123;
					put&#40;'-'&#41;;
					i = -i;
					&#125;
				s = buf;
				do &#123;
					j = i / 10;
					*s++ = i - 10*j + '0';
					&#125;
					while&#40;i = j&#41;;
				do &#123;
					i = *--s;
					put&#40;i&#41;;
					&#125;
					while&#40;s > buf&#41;;
				continue;
			case 's'&#58;
				s = va_arg&#40;ap, char*&#41;;
				while&#40;i = *s++&#41;
					&#123; put&#40;i&#41;; &#125;
				continue;
			default&#58;
				bad&#40;fmt&#41;;
			&#125;
		&#125;
 done&#58;
	*outbuf = 0;
	return outbuf - ob0;
	&#125;
#ifdef __cplusplus
	&#125;
#endif
To use it:

Code: Select all

char outputString&#91;12+10+1&#93;; // length of "High Score&#58; " + maximum of a signed integer + null byte
sprintf &#40;&outputString, "High Score&#58; %d", &#40;int&#41;highscore&#41;;
If that doesn't work, try changing the size of outputString. I think that should be just the right size. Additionally, you might want to add an extra parameter to sprintf - the size of the output buffer.
Energy
Posts: 133
Joined: Sat Mar 26, 2005 4:13 pm
Location: uk/beds/flitwick
Contact:

Post by Energy »

Thanks Hippo - I'll give it a try tonight. Pong is a boring game, but at least I'm getting used to the system. Plan to at least make it an interesting version of pong... it's called YAP...
YetAnotherPong
lol
Almost working! :D
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Energy wrote:Ok this is a serious n00b question - how do I get PgPrint to display a integer value on the screen? Want my score to display!
Maybe a sprintf is in the new PSPSDK, but here is some code for a 7 segment display from my Snake game:

Code: Select all

const char digitFont&#91;&#93; = &#123;
	1,1,1,1,
	1,0,0,1,
	1,0,0,1,
	1,0,0,1,
	1,1,1,1,
	
	0,0,0,1,
	0,0,0,1,
	0,0,0,1,
	0,0,0,1,
	0,0,0,1,
	
	1,1,1,1,
	0,0,0,1,
	1,1,1,1,
	1,0,0,0,
	1,1,1,1,
	
	1,1,1,1,
	0,0,0,1,
	1,1,1,1,
	0,0,0,1,
	1,1,1,1,
	
	1,0,0,1,
	1,0,0,1,
	1,1,1,1,
	0,0,0,1,
	0,0,0,1,
	
	1,1,1,1,
	1,0,0,0,
	1,1,1,1,
	0,0,0,1,
	1,1,1,1,
	
	1,1,1,1,
	1,0,0,0,
	1,1,1,1,
	1,0,0,1,
	1,1,1,1,
	
	1,1,1,1,
	0,0,0,1,
	0,0,0,1,
	0,0,0,1,
	0,0,0,1,
	
	1,1,1,1,
	1,0,0,1,
	1,1,1,1,
	1,0,0,1,
	1,1,1,1,

	1,1,1,1,
	1,0,0,1,
	1,1,1,1,
	0,0,0,1,
	1,1,1,1&#125;;

void print7Segment&#40;int x, int y, int digit&#41;
&#123;
	unsigned short* vram = &#40;unsigned short*&#41; pgGetVramAddr&#40;x, y&#41;;
	int xo, yo;
	int i = digit * 5*4;
	for &#40;yo = 0; yo < 5; yo++&#41; &#123;
		for &#40;xo = 0; xo < 4; xo++&#41; &#123;
			if &#40;digitFont&#91;i&#93;&#41; &#123;
				vram&#91;xo + yo * 512&#93; = TEXT_COLOR;
			&#125; else &#123;
				vram&#91;xo + yo * 512&#93; = backgroundData&#91;x + xo + &#40;y + yo&#41; * backgroundWidth&#93;;
			&#125;
			i++;
		&#125;
	&#125;
		
&#125;

void printDecimal&#40;int x, int y, int color, int value&#41;
&#123;
	int i;
	int zero = 1;
	int digits&#91;6&#93;;
	for &#40;i = 5; i >= 0; i--&#41; &#123;
		digits&#91;i&#93; = value%10;
		value /= 10;
	&#125;
	i = 0;
	while &#40;i < 5 && digits&#91;i&#93; == 0&#41; digits&#91;i++&#93; = -1;
	for &#40;i = 0; i < 6; i++&#41; &#123;
		if &#40;digits&#91;i&#93; >= 0&#41; &#123;
			print7Segment&#40;x, y, digits&#91;i&#93;&#41;;
			x += 6;
		&#125;
	&#125;
&#125;
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

sprintf() is in the new PSPSDK :).
djhuevo
Posts: 47
Joined: Thu Mar 10, 2005 3:50 pm

Post by djhuevo »

sprintf already is loaded within SysclibForKernel

I you work in kernelmode:

for 1.5:
void (*sprintf)(u8 *buffer, const char *str, ...) = (void *)0x8802c4b0;

and for 1.0:
void (*sprintf)(u8 *buffer, const char *str, ...) = (void *)0x880290e0;
sobreviviendo en la tierra de los trolldev
Energy
Posts: 133
Joined: Sat Mar 26, 2005 4:13 pm
Location: uk/beds/flitwick
Contact:

Post by Energy »

Thanks guys for all your help so far... :)
Instead of a new thread I'll ask my questions in here... No rush, but still learning. Thanks

1: According to skippy's last post his controller library supported the home button, yet the version on PSP hacker/updates (whatever they're called) seems to have no mention of this. Have I got an old version? Can someone send me the latest? energy.lp@gmail.com Thanks.

2: Is there a simple way to exit out of the program. I've tried, but my PSP hangs. :/ Any ideas?

3: This one will help me miles: Shine & others use the sceFunctionName. Mainly the one I want to use is in Shines random function. Guessing it maybe used to seed from the time. How can I access these functions?

Oh well thanks for your help so far guys. Apart from that my game seems to be going quite well. The only bit I don't like is the blocky graphics. Seems to be that the bitblt function by NEM makes things look blocky. But graphics aren't a major concern yet.

Just starting to code an oponent to play against. That's why I need the rand function. Otherwise it never misses! lol. Might port it over to the PSPSDK soon :)
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

djhuevo wrote:sprintf already is loaded within SysclibForKernel

I you work in kernelmode:

for 1.5:
void (*sprintf)(u8 *buffer, const char *str, ...) = (void *)0x8802c4b0;

and for 1.0:
void (*sprintf)(u8 *buffer, const char *str, ...) = (void *)0x880290e0;
This is a bad idea, because you have to check for the kernel version to call the right function and it didn't work with newer kernel versions (if there would be some day a procedure to start games in newer kernel versions at all).
Energy wrote:1: According to skippy's last post his controller library supported the home button, yet the version on PSP hacker/updates (whatever they're called) seems to have no mention of this. Have I got an old version? Can someone send me the latest? energy.lp@gmail.com Thanks.
I think you have to test ctrl.buttons for 0x10000 (or another value, don't know exactly; just print it to see which value), nothing special.
Energy wrote: 2: Is there a simple way to exit out of the program. I've tried, but my PSP hangs. :/ Any ideas?
You should do it the PSP way: Let the user decide, when to exit the program, by creating the exit thread and registering the exit callback. See my snake game for an example how to do it.
Energy wrote: 3: This one will help me miles: Shine & others use the sceFunctionName. Mainly the one I want to use is in Shines random function. Guessing it maybe used to seed from the time. How can I access these functions?
Maybe it is already integrated in the new PSPSDK, I didn't try it. Otherwise you could search the function at djhuevo browser API and paste the stubs to the startup.s.
Energy
Posts: 133
Joined: Sat Mar 26, 2005 4:13 pm
Location: uk/beds/flitwick
Contact:

Post by Energy »

Thanks Shine.
will take your snake game apart again. The code has been very useful to me already. Worked on my game a bit over lunch. Feel really stupid on the graphics front... No wonder they looked blocky. I set it to enlarge the graphics twice the size. not too happy with the controls - they work, but seem a bit unresponsive. Apart from a few bugs and the lack of an opponent the game is almost playable.

The guys at work are taking a great interest. Can't wait to show you lot what I've done and see what you think.
squiggle
Posts: 9
Joined: Sun Jun 26, 2005 8:33 pm

Post by squiggle »

Seed = sceKernelLibcTime((void *) 0);
Post Reply