Subversion Repositories pspware

Rev

Rev 141 | Rev 185 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
128 shine 1
/*
2
 * Lua Player for PSP
3
 * ------------------------------------------------------------------------
4
 * Licensed under the BSD license, see LICENSE for details.
5
 *
6
 * Copyright (c) 2005 Frank Buss <fb@frank-buss.de> (aka Shine)
7
 *
8
 * Credits:
9
 *   many thanks to the authors of the PSPSDK from http://forums.ps2dev.org
10
 *   and to the hints and discussions from #pspdev on freenode.net
11
 *
12
 * $Id: main.c 155 2005-08-14 11:25:51Z shine $
13
 */
14
 
15
#include <pspkernel.h>
16
#include <pspdebug.h>
17
#include <pspdisplay.h>
136 nevyn 18
#include <pspctrl.h>
141 shine 19
#include <pspsdk.h>
128 shine 20
#include <stdlib.h>
21
#include <string.h>
136 nevyn 22
#include <unistd.h>
128 shine 23
 
24
#include "graphics.h"
136 nevyn 25
#include "sound.h"
128 shine 26
#include "luaplayer.h"
27
 
28
/* Define the module info section */
29
PSP_MODULE_INFO("LUAPLAYER", 0x1000, 1, 1);
30
 
31
/* Define the main thread's attribute value (optional) */
32
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
33
 
34
/* Exit callback */
35
int exit_callback(void)
36
{
37
        sceKernelExitGame();
38
 
39
        return 0;
40
}
41
 
42
/* Callback thread */
43
int CallbackThread(SceSize args, void *argp)
44
{
45
        int cbid;
46
 
47
        cbid = sceKernelCreateCallback("Exit Callback", (void *) exit_callback, NULL);
48
        sceKernelRegisterExitCallback(cbid);
49
 
50
        sceKernelSleepThreadCB();
51
 
52
        return 0;
53
}
54
 
55
/* Sets up the callback thread and returns its thread id */
56
int SetupCallbacks(void)
57
{
58
        int thid = 0;
59
 
60
        thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
61
        if(thid >= 0)
62
        {
63
                sceKernelStartThread(thid, 0, 0);
64
        }
65
 
66
        return thid;
67
}
68
 
69
int nullOutput(const char *buff, int size)
70
{
71
        return size;
72
}
73
 
74
int debugOutput(const char *buff, int size)
75
{
76
        static int debugInitialized = 0;
136 nevyn 77
        if(!buff) {
78
                debugInitialized = 0;
79
                return 0;
80
        }
128 shine 81
        if (!debugInitialized) {
82
                disableGraphics();
83
                pspDebugScreenInit();
84
                debugInitialized = 1;
85
        }
86
        return pspDebugScreenPrintData(buff, size);
87
}
88
 
89
__attribute__((constructor)) void stdoutInit()
90
{
91
        pspKernelSetKernelPC();
141 shine 92
        pspSdkInstallNoDeviceCheckPatch();
93
        pspDebugInstallKprintfHandler(NULL);
128 shine 94
 
95
        // ignore startup messages from kernel, but install the tty driver in kernel mode
96
        pspDebugInstallStdoutHandler(nullOutput);
97
}
98
 
99
int main(int argc, char** argv)
100
{
101
        SetupCallbacks();
102
 
136 nevyn 103
        // init modules
128 shine 104
        initGraphics();
136 nevyn 105
        initMikmod();
128 shine 106
 
107
        // install new output handlers  
108
        pspDebugInstallStdoutHandler(debugOutput);
109
        pspDebugInstallStderrHandler(debugOutput);
110
 
111
        // execute Lua script (current directory is where EBOOT.PBP is)
136 nevyn 112
        char path[256];
113
        getcwd(path, 256);
114
        while(1) {
155 shine 115
                clearScreen(0);
116
                flipScreen();
117
                clearScreen(0);
136 nevyn 118
                runScript("script.lua");
119
                SceCtrlData pad; int i;
120
                sceCtrlReadBufferPositive(&pad, 1);
121
                debugOutput("\nPress start to restart\n", 26);
122
                for(i = 0; i < 20; i++) sceDisplayWaitVblankStart();
123
                while(!(pad.Buttons&PSP_CTRL_START)) sceCtrlReadBufferPositive(&pad, 1);
124
                chdir(path);
125
                debugOutput(0,0);
126
                initGraphics();
127
        }
128 shine 128
 
136 nevyn 129
        // Unload modules
130
        unloadMikmod();
128 shine 131
        // wait until user ends the program
132
        sceKernelSleepThread();
133
 
134
        return 0;
135
}