Subversion Repositories pspware

Rev

Rev 210 | Rev 232 | 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 212 2005-09-10 12:37:23Z 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
 
210 shine 28
/* the boot.lua */
212 shine 29
#include "boot.c"
210 shine 30
 
128 shine 31
/* Define the module info section */
32
PSP_MODULE_INFO("LUAPLAYER", 0x1000, 1, 1);
33
 
34
/* Define the main thread's attribute value (optional) */
35
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
36
 
37
/* Exit callback */
38
int exit_callback(void)
39
{
208 nevyn 40
 
41
// Unload modules
42
        unloadMikmod();
43
 
128 shine 44
        sceKernelExitGame();
45
        return 0;
46
}
47
 
48
/* Callback thread */
49
int CallbackThread(SceSize args, void *argp)
50
{
51
        int cbid;
52
 
53
        cbid = sceKernelCreateCallback("Exit Callback", (void *) exit_callback, NULL);
54
        sceKernelRegisterExitCallback(cbid);
55
 
56
        sceKernelSleepThreadCB();
57
 
58
        return 0;
59
}
60
 
61
/* Sets up the callback thread and returns its thread id */
62
int SetupCallbacks(void)
63
{
64
        int thid = 0;
65
 
66
        thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
67
        if(thid >= 0)
68
        {
69
                sceKernelStartThread(thid, 0, 0);
70
        }
71
 
72
        return thid;
73
}
74
 
75
int nullOutput(const char *buff, int size)
76
{
77
        return size;
78
}
79
 
80
int debugOutput(const char *buff, int size)
81
{
82
        static int debugInitialized = 0;
136 nevyn 83
        if(!buff) {
84
                debugInitialized = 0;
85
                return 0;
86
        }
128 shine 87
        if (!debugInitialized) {
88
                disableGraphics();
89
                pspDebugScreenInit();
90
                debugInitialized = 1;
91
        }
92
        return pspDebugScreenPrintData(buff, size);
93
}
94
 
95
__attribute__((constructor)) void stdoutInit()
96
{
97
        pspKernelSetKernelPC();
141 shine 98
        pspSdkInstallNoDeviceCheckPatch();
99
        pspDebugInstallKprintfHandler(NULL);
128 shine 100
 
101
        // ignore startup messages from kernel, but install the tty driver in kernel mode
102
        pspDebugInstallStdoutHandler(nullOutput);
103
}
104
 
105
int main(int argc, char** argv)
106
{
107
        SetupCallbacks();
108
 
136 nevyn 109
        // init modules
128 shine 110
        initGraphics();
136 nevyn 111
        initMikmod();
128 shine 112
 
113
        // install new output handlers  
114
        pspDebugInstallStdoutHandler(debugOutput);
115
        pspDebugInstallStderrHandler(debugOutput);
116
 
208 nevyn 117
        // execute Lua script (according to boot sequence)
136 nevyn 118
        char path[256];
119
        getcwd(path, 256);
212 shine 120
        char* bootStringWith0 = (char*) malloc(size_bootString + 1);
121
        memcpy(bootStringWith0, bootString, size_bootString);
122
        bootString[size_bootString] = 0;
208 nevyn 123
        while(1) { // reload on error
155 shine 124
                clearScreen(0);
125
                flipScreen();
126
                clearScreen(0);
210 shine 127
 
212 shine 128
                if (runScript(bootStringWith0, true))
208 nevyn 129
                        debugOutput("Error: No script file found.\n", 29);
130
 
131
                debugOutput("\nPress start to restart\n", 26);
136 nevyn 132
                SceCtrlData pad; int i;
133
                sceCtrlReadBufferPositive(&pad, 1);
189 nevyn 134
                for(i = 0; i < 40; i++) sceDisplayWaitVblankStart();
136 nevyn 135
                while(!(pad.Buttons&PSP_CTRL_START)) sceCtrlReadBufferPositive(&pad, 1);
208 nevyn 136
 
137
                chdir(path); // set base path luaplater/
136 nevyn 138
                debugOutput(0,0);
139
                initGraphics();
140
        }
212 shine 141
        free(bootStringWith0);
128 shine 142
 
143
        // wait until user ends the program
144
        sceKernelSleepThread();
145
 
146
        return 0;
147
}