Controller Issues (n00b Question)
Controller Issues (n00b Question)
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
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
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:
... to something like:
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.)
Try changing this bit of code in controller.c:
Code: Select all
while(1) {
key = Read_Key();
if (key != 0) break;
pgWaitV();
}
Code: Select all
key = Read_Key();
if (key == 0) return 0;
I use a slightly modified version of the sprintf implementation that Doom(-PSP) uses: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*
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" {
#endif
static void
bad
#ifdef KR_headers
(fmt) char *fmt;
#else
(const char *fmt)
#endif
{
//printf("bad fmt in Sprintf, starting with "%s"\n", fmt);
}
#define put(x) *outbuf++ = x
int
sprintf
#ifdef KR_headers
(va_alist)
va_dcl
#else
(char *outbuf, const char *fmt, ...)
#endif
{
char *ob0, *s;
char buf[32];
va_list ap;
long i, j;
#ifdef KR_headers
char *outbuf, *fmt;
va_start(ap);
outbuf = va_arg(ap, char*);
fmt = va_arg(ap, char*);
#else
va_start(ap, fmt);
#endif
ob0 = outbuf;
for(;;) {
for(;;) {
switch(i = *fmt++) {
case 0:
goto done;
case '%':
break;
default:
put(i);
continue;
}
break;
}
switch(*fmt++) {
case 'c':
i = va_arg(ap, int);
put(i);
continue;
case 'l':
if (*fmt != 'd')
bad(fmt);
fmt++;
i = va_arg(ap, long);
goto have_i;
case 'd':
i = va_arg(ap, int);
have_i:
if (i < 0) {
put('-');
i = -i;
}
s = buf;
do {
j = i / 10;
*s++ = i - 10*j + '0';
}
while(i = j);
do {
i = *--s;
put(i);
}
while(s > buf);
continue;
case 's':
s = va_arg(ap, char*);
while(i = *s++)
{ put(i); }
continue;
default:
bad(fmt);
}
}
done:
*outbuf = 0;
return outbuf - ob0;
}
#ifdef __cplusplus
}
#endif
Code: Select all
char outputString[12+10+1]; // length of "High Score: " + maximum of a signed integer + null byte
sprintf (&outputString, "High Score: %d", (int)highscore);
Maybe a sprintf is in the new PSPSDK, but here is some code for a 7 segment display from my Snake game: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!
Code: Select all
const char digitFont[] = {
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};
void print7Segment(int x, int y, int digit)
{
unsigned short* vram = (unsigned short*) pgGetVramAddr(x, y);
int xo, yo;
int i = digit * 5*4;
for (yo = 0; yo < 5; yo++) {
for (xo = 0; xo < 4; xo++) {
if (digitFont[i]) {
vram[xo + yo * 512] = TEXT_COLOR;
} else {
vram[xo + yo * 512] = backgroundData[x + xo + (y + yo) * backgroundWidth];
}
i++;
}
}
}
void printDecimal(int x, int y, int color, int value)
{
int i;
int zero = 1;
int digits[6];
for (i = 5; i >= 0; i--) {
digits[i] = value%10;
value /= 10;
}
i = 0;
while (i < 5 && digits[i] == 0) digits[i++] = -1;
for (i = 0; i < 6; i++) {
if (digits[i] >= 0) {
print7Segment(x, y, digits[i]);
x += 6;
}
}
}
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 :)
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 :)
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).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;
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: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.
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: 2: Is there a simple way to exit out of the program. I've tried, but my PSP hangs. :/ Any ideas?
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 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?
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.
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.