Subversion Repositories pspware

Rev

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