forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Strange problem with a homebrew program

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Ratfink



Joined: 26 May 2009
Posts: 6
Location: The fourth dimension

PostPosted: Thu May 28, 2009 10:35 am    Post subject: Strange problem with a homebrew program Reply with quote

I'm making a simple tic-tac-toe program for the PSP. Whenever I try to run it, it just shows a black screen and does nothing. I can still hit start and it asks if I want to quit the game. I don't know what is wrong, if anyone can figure it out please tell me. Here is the program's source.

main.c:
Code:
/* PSP Tic-Tac-Toe - Tic Tac Toe game for the Sony PSP
 *                                                   
 * It is a simple text-based game of Tic-Tac-Toe.     
 */                                                   

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>   

PSP_MODULE_INFO ( "PSP Tic-Tac-Toe", 0, 1, 1 );

#define printf pspDebugScreenPrintf

/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
    sceKernelExitGame ();                           
    return 0;                                       
}                                                   

/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
    int cbid;                                 

    cbid = sceKernelCreateCallback ("Exit Callback", exit_callback, NULL);
    sceKernelRegisterExitCallback (cbid);                                 

    sceKernelSleepThreadCB ();

    return 0;
}           

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {                                 
    int thid = 0;                                         

    thid = sceKernelCreateThread ( "update_thread", CallbackThread, 0x11, 0xFA0, 0, 0 );
    if ( thid >= 0 ) {                                                                 
        sceKernelStartThread(thid, 0, 0);                                               
    }                                                                                   

    return thid;
}               

int main() {
    pspDebugScreenInit ();
    SetupCallbacks ();   

    char squares[3][3] = {
        {' ', ' ', ' '}, 
        {' ', ' ', ' '}, 
        {' ', ' ', ' '}   
    };                   
    char player = 'X';   
    int  i = 0;           
    int  cursorX = 1;     
    int  cursorY = 1;     
    SceCtrlData pad;     

    pspDebugScreenSetXY (0, 33);
    printf ("PSP Tic-Tac-Toe v. 0.1b");

    while ( 1 ) {
        sceCtrlReadBufferPositive (&pad, 1);

        if ( (pad.Buttons & PSP_CTRL_UP) && (cursorY > 0) )
            --cursorY;                                     
        else if ( (pad.Buttons & PSP_CTRL_DOWN) && (cursorY < 2) )
            ++cursorY;                                           
        else if ( (pad.Buttons & PSP_CTRL_LEFT) && (cursorX > 0) )
            --cursorX;                                           
        else if ( (pad.Buttons & PSP_CTRL_RIGHT) && (cursorX < 2) )
            ++cursorX;                                             
        else if ( (pad.Buttons & PSP_CTRL_CROSS) &&               
                  (squares[cursorX][cursorY] == ' ') ) {           
            squares[cursorX][cursorY] = player;                   
            if ( player == 'X' )                                   
                player = 'O';                                     
            else if ( player == 'O' )                             
                player = 'X';                                     
        }                                                         

        pspDebugScreenSetXY (0, 0);

        printf ("%c|%c|%c\n", squares[0][0], squares[1][0], squares[2][0]);
        printf ("-+-+-\n");                                               
        printf ("%c|%c|%c\n", squares[0][1], squares[1][1], squares[2][1]);
        printf ("-+-+-\n");                                               
        printf ("%c|%c|%c\n", squares[0][2], squares[1][2], squares[2][2]);

        pspDebugScreenSetXY (cursorX * 2, cursorY * 2);
        pspDebugScreenSetBackColor (0xFF0000FF);       
        printf ("%c", squares[cursorX][cursorY]);     
        pspDebugScreenSetBackColor (0xFF000000);       
        pspDebugScreenSetXY (0, 5);                   

        if ( ((squares[0][1] == squares[1][1]) && (squares[1][1] == squares[2][1])) ||
             ((squares[0][0] == squares[1][1]) && (squares[1][1] == squares[2][2])) ||
             ((squares[1][0] == squares[1][1]) && (squares[1][1] == squares[1][2])) ||
             ((squares[2][0] == squares[1][1]) && (squares[1][1] == squares[0][2])) ||
             ((squares[0][0] == squares[0][1]) && (squares[0][1] == squares[0][2])) ||
             ((squares[0][2] == squares[1][2]) && (squares[1][2] == squares[2][2])) ||
             ((squares[0][0] == squares[1][0]) && (squares[1][0] == squares[2][0])) ||
             ((squares[2][0] == squares[2][1]) && (squares[2][1] == squares[2][2])) ) {
            printf ("%c is the winner!", player);
            break;
        }

        if ( (squares[0][0] != ' ') &&
             (squares[0][1] != ' ') &&
             (squares[0][2] != ' ') &&
             (squares[1][0] != ' ') &&
             (squares[1][1] != ' ') &&
             (squares[1][2] != ' ') &&
             (squares[2][0] != ' ') &&
             (squares[2][1] != ' ') &&
             (squares[2][2] != ' ') ) {
            printf ("Tie game!");
            break;
        }

        for ( i = 0;  i < 5;  ++i )
            sceDisplayWaitVblankStart ();
    }

    pspDebugScreenClear ();

    sceKernelSleepThread ();

    return 0;
}


Makefile:
Code:
GET = psp_tictactoe
OBJS = main.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = PSP Tic-Tac-Toe

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak


EDIT: I figured out the problem, and now I'm embarassed that I posted something here about it. It was checking for anything that's three-in-a-row, so a blank square worked too.
_________________
Beware the Ratfink, he can gnaw through your Ethernet cable!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group