6 #include <pspiofilemgr.h>
7 #include <pspdisplay.h>
12 #include "../common/lprintf.h"
14 PSP_MODULE_INFO("PicoDrive", 0, 1, 34);
16 void *psp_screen = PSP_VRAM_BASE0;
17 static int current_screen = 0; /* front bufer */
19 static SceUID logfd = -1;
22 static int exit_callback(int arg1, int arg2, void *common)
29 static int callback_thread(SceSize args, void *argp)
33 lprintf("callback_thread started with id %i\n", sceKernelGetThreadId());
35 cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
36 sceKernelRegisterExitCallback(cbid);
38 sceKernelSleepThreadCB();
47 lprintf("entered psp_init, threadId %i\n", sceKernelGetThreadId());
49 thid = sceKernelCreateThread("update_thread", callback_thread, 0x11, 0xFA0, 0, 0);
52 sceKernelStartThread(thid, 0, 0);
56 sceDisplaySetMode(0, 480, 272);
57 sceDisplaySetFrameBuf(PSP_VRAM_BASE1, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
59 psp_screen = PSP_VRAM_BASE0;
65 sceCtrlSetSamplingCycle(0);
66 sceCtrlSetSamplingMode(0);
73 //sceKernelSleepThread();
77 void psp_video_flip(int wait_vsync)
79 if (wait_vsync) sceDisplayWaitVblankStart();
80 sceDisplaySetFrameBuf(psp_screen, 512, PSP_DISPLAY_PIXEL_FORMAT_565,
81 wait_vsync ? PSP_DISPLAY_SETBUF_IMMEDIATE : PSP_DISPLAY_SETBUF_NEXTFRAME);
83 psp_screen = current_screen ? PSP_VRAM_BASE0 : PSP_VRAM_BASE1;
86 void *psp_video_get_active_fb(void)
88 return current_screen ? PSP_VRAM_BASE1 : PSP_VRAM_BASE0;
91 void psp_video_switch_to_single(void)
93 psp_screen = PSP_VRAM_BASE0;
94 sceDisplaySetFrameBuf(psp_screen, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
98 void psp_msleep(int ms)
100 sceKernelDelayThread(ms * 1000);
103 unsigned int psp_pad_read(int blocking)
107 sceCtrlReadBufferPositive(&pad, 1);
108 else sceCtrlPeekBufferPositive(&pad, 1);
113 int psp_get_cpu_clock(void)
115 return scePowerGetCpuClockFrequencyInt();
118 int psp_set_cpu_clock(int clock)
120 int ret = scePowerSetClockFrequency(clock, clock, clock/2);
121 if (ret != 0) lprintf("failed to set clock: %i\n", ret);
127 #define LOG_FILE "log.log"
129 void lprintf_f(const char *fmt, ...)
136 logfd = sceIoOpen(LOG_FILE, PSP_O_WRONLY|PSP_O_APPEND, 0777);
142 vsnprintf(buff, sizeof(buff), fmt, vl);
145 sceIoWrite(logfd, buff, strlen(buff));
146 //sceKernelDelayThread(200 * 1000);