initial psp code, functional menu
[libpicofe.git] / psp / psp.c
CommitLineData
2951214e 1#include <pspkernel.h>
2#include <pspdisplay.h>
3#include <pspgu.h>
4
5#include "psp.h"
6#include "../common/lprintf.h"
7
8PSP_MODULE_INFO("PicoDrive", 0, 1, 34);
9
10void *psp_screen = PSP_VRAM_BASE0;
11static int current_screen = 0; /* front bufer */
12
13
14/* Exit callback */
15static int exit_callback(int arg1, int arg2, void *common)
16{
17 sceKernelExitGame();
18 return 0;
19}
20
21/* Callback thread */
22static int callback_thread(SceSize args, void *argp)
23{
24 int cbid;
25
26 lprintf("callback_thread started with id %i\n", sceKernelGetThreadId());
27
28 cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
29 sceKernelRegisterExitCallback(cbid);
30
31 sceKernelSleepThreadCB();
32
33 return 0;
34}
35
36void psp_init(void)
37{
38 int thid;
39
40 lprintf("entered psp_init, threadId %i\n", sceKernelGetThreadId());
41
42 thid = sceKernelCreateThread("update_thread", callback_thread, 0x11, 0xFA0, 0, 0);
43 if (thid >= 0)
44 {
45 sceKernelStartThread(thid, 0, 0);
46 }
47
48 /* video */
49 sceDisplaySetMode(0, 480, 272);
50 sceDisplaySetFrameBuf(PSP_VRAM_BASE1, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
51 current_screen = 1;
52 psp_screen = PSP_VRAM_BASE0;
53
54 /* gu */
55 sceGuInit();
56
57 /* input */
58 sceCtrlSetSamplingCycle(0);
59 sceCtrlSetSamplingMode(0);
60}
61
62void psp_finish(void)
63{
64 sceGuTerm();
65
66 //sceKernelSleepThread();
67 sceKernelExitGame();
68}
69
70void psp_video_flip(void)
71{
72 sceDisplaySetFrameBuf(psp_screen, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
73 current_screen ^= 1;
74 psp_screen = current_screen ? PSP_VRAM_BASE1 : PSP_VRAM_BASE0;
75}
76
77void psp_video_switch_to_single(void)
78{
79 psp_screen = PSP_VRAM_BASE0;
80 sceDisplaySetFrameBuf(psp_screen, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
81 current_screen = 0;
82}
83
84void psp_msleep(int ms)
85{
86 sceKernelDelayThread(ms * 1000);
87}
88
89unsigned int psp_pad_read(void)
90{
91 SceCtrlData pad;
92 sceCtrlReadBufferPositive(&pad, 1);
93
94 return pad.Buttons;
95}
96