Strange problem with a homebrew program

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

Moderators: cheriff, TyRaNiD

Post Reply
Ratfink
Posts: 6
Joined: Tue May 26, 2009 5:15 am
Location: The fourth dimension

Strange problem with a homebrew program

Post by Ratfink »

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: Select all

/* 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 &#40; "PSP Tic-Tac-Toe", 0, 1, 1 &#41;;

#define printf pspDebugScreenPrintf

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
    sceKernelExitGame &#40;&#41;;                            
    return 0;                                        
&#125;                                                    

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41; &#123;
    int cbid;                                 

    cbid = sceKernelCreateCallback &#40;"Exit Callback", exit_callback, NULL&#41;;
    sceKernelRegisterExitCallback &#40;cbid&#41;;                                 

    sceKernelSleepThreadCB &#40;&#41;;

    return 0;
&#125;            

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41; &#123;                                 
    int thid = 0;                                          

    thid = sceKernelCreateThread &#40; "update_thread", CallbackThread, 0x11, 0xFA0, 0, 0 &#41;;
    if &#40; thid >= 0 &#41; &#123;                                                                  
        sceKernelStartThread&#40;thid, 0, 0&#41;;                                               
    &#125;                                                                                   

    return thid;
&#125;               

int main&#40;&#41; &#123;
    pspDebugScreenInit &#40;&#41;;
    SetupCallbacks &#40;&#41;;    

    char squares&#91;3&#93;&#91;3&#93; = &#123;
        &#123;' ', ' ', ' '&#125;,  
        &#123;' ', ' ', ' '&#125;,  
        &#123;' ', ' ', ' '&#125;   
    &#125;;                    
    char player = 'X';    
    int  i = 0;           
    int  cursorX = 1;     
    int  cursorY = 1;     
    SceCtrlData pad;      

    pspDebugScreenSetXY &#40;0, 33&#41;;
    printf &#40;"PSP Tic-Tac-Toe v. 0.1b"&#41;;

    while &#40; 1 &#41; &#123;
        sceCtrlReadBufferPositive &#40;&pad, 1&#41;;

        if &#40; &#40;pad.Buttons & PSP_CTRL_UP&#41; && &#40;cursorY > 0&#41; &#41;
            --cursorY;                                     
        else if &#40; &#40;pad.Buttons & PSP_CTRL_DOWN&#41; && &#40;cursorY < 2&#41; &#41;
            ++cursorY;                                            
        else if &#40; &#40;pad.Buttons & PSP_CTRL_LEFT&#41; && &#40;cursorX > 0&#41; &#41;
            --cursorX;                                            
        else if &#40; &#40;pad.Buttons & PSP_CTRL_RIGHT&#41; && &#40;cursorX < 2&#41; &#41;
            ++cursorX;                                             
        else if &#40; &#40;pad.Buttons & PSP_CTRL_CROSS&#41; &&                
                  &#40;squares&#91;cursorX&#93;&#91;cursorY&#93; == ' '&#41; &#41; &#123;           
            squares&#91;cursorX&#93;&#91;cursorY&#93; = player;                    
            if &#40; player == 'X' &#41;                                   
                player = 'O';                                      
            else if &#40; player == 'O' &#41;                              
                player = 'X';                                      
        &#125;                                                          

        pspDebugScreenSetXY &#40;0, 0&#41;;

        printf &#40;"%c|%c|%c\n", squares&#91;0&#93;&#91;0&#93;, squares&#91;1&#93;&#91;0&#93;, squares&#91;2&#93;&#91;0&#93;&#41;;
        printf &#40;"-+-+-\n"&#41;;                                                
        printf &#40;"%c|%c|%c\n", squares&#91;0&#93;&#91;1&#93;, squares&#91;1&#93;&#91;1&#93;, squares&#91;2&#93;&#91;1&#93;&#41;;
        printf &#40;"-+-+-\n"&#41;;                                                
        printf &#40;"%c|%c|%c\n", squares&#91;0&#93;&#91;2&#93;, squares&#91;1&#93;&#91;2&#93;, squares&#91;2&#93;&#91;2&#93;&#41;;

        pspDebugScreenSetXY &#40;cursorX * 2, cursorY * 2&#41;;
        pspDebugScreenSetBackColor &#40;0xFF0000FF&#41;;       
        printf &#40;"%c", squares&#91;cursorX&#93;&#91;cursorY&#93;&#41;;      
        pspDebugScreenSetBackColor &#40;0xFF000000&#41;;       
        pspDebugScreenSetXY &#40;0, 5&#41;;                    

        if &#40; &#40;&#40;squares&#91;0&#93;&#91;1&#93; == squares&#91;1&#93;&#91;1&#93;&#41; && &#40;squares&#91;1&#93;&#91;1&#93; == squares&#91;2&#93;&#91;1&#93;&#41;&#41; ||
             &#40;&#40;squares&#91;0&#93;&#91;0&#93; == squares&#91;1&#93;&#91;1&#93;&#41; && &#40;squares&#91;1&#93;&#91;1&#93; == squares&#91;2&#93;&#91;2&#93;&#41;&#41; ||
             &#40;&#40;squares&#91;1&#93;&#91;0&#93; == squares&#91;1&#93;&#91;1&#93;&#41; && &#40;squares&#91;1&#93;&#91;1&#93; == squares&#91;1&#93;&#91;2&#93;&#41;&#41; ||
             &#40;&#40;squares&#91;2&#93;&#91;0&#93; == squares&#91;1&#93;&#91;1&#93;&#41; && &#40;squares&#91;1&#93;&#91;1&#93; == squares&#91;0&#93;&#91;2&#93;&#41;&#41; ||
             &#40;&#40;squares&#91;0&#93;&#91;0&#93; == squares&#91;0&#93;&#91;1&#93;&#41; && &#40;squares&#91;0&#93;&#91;1&#93; == squares&#91;0&#93;&#91;2&#93;&#41;&#41; ||
             &#40;&#40;squares&#91;0&#93;&#91;2&#93; == squares&#91;1&#93;&#91;2&#93;&#41; && &#40;squares&#91;1&#93;&#91;2&#93; == squares&#91;2&#93;&#91;2&#93;&#41;&#41; ||
             &#40;&#40;squares&#91;0&#93;&#91;0&#93; == squares&#91;1&#93;&#91;0&#93;&#41; && &#40;squares&#91;1&#93;&#91;0&#93; == squares&#91;2&#93;&#91;0&#93;&#41;&#41; ||
             &#40;&#40;squares&#91;2&#93;&#91;0&#93; == squares&#91;2&#93;&#91;1&#93;&#41; && &#40;squares&#91;2&#93;&#91;1&#93; == squares&#91;2&#93;&#91;2&#93;&#41;&#41; &#41; &#123;
            printf &#40;"%c is the winner!", player&#41;;
            break;
        &#125;

        if &#40; &#40;squares&#91;0&#93;&#91;0&#93; != ' '&#41; &&
             &#40;squares&#91;0&#93;&#91;1&#93; != ' '&#41; &&
             &#40;squares&#91;0&#93;&#91;2&#93; != ' '&#41; &&
             &#40;squares&#91;1&#93;&#91;0&#93; != ' '&#41; &&
             &#40;squares&#91;1&#93;&#91;1&#93; != ' '&#41; &&
             &#40;squares&#91;1&#93;&#91;2&#93; != ' '&#41; &&
             &#40;squares&#91;2&#93;&#91;0&#93; != ' '&#41; &&
             &#40;squares&#91;2&#93;&#91;1&#93; != ' '&#41; &&
             &#40;squares&#91;2&#93;&#91;2&#93; != ' '&#41; &#41; &#123;
            printf &#40;"Tie game!"&#41;;
            break;
        &#125;

        for &#40; i = 0;  i < 5;  ++i &#41;
            sceDisplayWaitVblankStart &#40;&#41;;
    &#125;

    pspDebugScreenClear &#40;&#41;;

    sceKernelSleepThread &#40;&#41;;

    return 0;
&#125;
Makefile:

Code: Select all

GET = psp_tictactoe
OBJS = main.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

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

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/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!
Post Reply