6 #include <pspiofilemgr.h>
7 #include <pspdisplay.h>
12 #include "../common/lprintf.h"
14 PSP_MODULE_INFO("PicoDrive", 0, 1, 34);
16 unsigned int __attribute__((aligned(16))) guCmdList[GU_CMDLIST_SIZE];
18 void *psp_screen = VRAM_FB0;
19 static int current_screen = 0; /* front bufer */
21 static SceUID logfd = -1;
24 static int exit_callback(int arg1, int arg2, void *common)
31 static int callback_thread(SceSize args, void *argp)
35 lprintf("callback_thread started with id %i, priority %i\n",
36 sceKernelGetThreadId(), sceKernelGetThreadCurrentPriority());
38 cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
39 sceKernelRegisterExitCallback(cbid);
41 sceKernelSleepThreadCB();
50 lprintf("entered psp_init, threadId %i, priority %i\n", sceKernelGetThreadId(),
51 sceKernelGetThreadCurrentPriority());
53 thid = sceKernelCreateThread("update_thread", callback_thread, 0x11, 0xFA0, 0, 0);
56 sceKernelStartThread(thid, 0, 0);
60 sceDisplaySetMode(0, 480, 272);
61 sceDisplaySetFrameBuf(VRAM_FB1, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
63 psp_screen = VRAM_FB0;
68 sceGuStart(GU_DIRECT, guCmdList);
69 sceGuDrawBuffer(GU_PSM_5650, (void *)VRAMOFFS_FB0, 512);
70 sceGuDispBuffer(480, 272, (void *)VRAMOFFS_FB1, 512); // don't care
71 sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
72 sceGuDepthBuffer((void *)VRAMOFFS_DEPTH, 512);
73 sceGuOffset(2048 - (480 / 2), 2048 - (272 / 2));
74 sceGuViewport(2048, 2048, 480, 272);
75 sceGuDepthRange(0xc350, 0x2710);
76 sceGuScissor(0, 0, 480, 272);
77 sceGuEnable(GU_SCISSOR_TEST);
79 sceGuDepthMask(0xffff);
80 sceGuDisable(GU_DEPTH_TEST);
82 sceGuFrontFace(GU_CW);
83 sceGuEnable(GU_TEXTURE_2D);
84 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
85 sceGuAmbientColor(0xffffffff);
86 sceGuColor(0xffffffff);
90 sceDisplayWaitVblankStart();
91 sceGuDisplay(GU_TRUE);
95 sceCtrlSetSamplingCycle(0);
96 sceCtrlSetSamplingMode(0);
103 //sceKernelSleepThread();
107 void psp_video_flip(int wait_vsync)
109 if (wait_vsync) sceDisplayWaitVblankStart();
110 sceDisplaySetFrameBuf(psp_screen, 512, PSP_DISPLAY_PIXEL_FORMAT_565,
111 wait_vsync ? PSP_DISPLAY_SETBUF_IMMEDIATE : PSP_DISPLAY_SETBUF_NEXTFRAME);
113 psp_screen = current_screen ? VRAM_FB0 : VRAM_FB1;
116 void *psp_video_get_active_fb(void)
118 return current_screen ? VRAM_FB1 : VRAM_FB0;
121 void psp_video_switch_to_single(void)
123 psp_screen = VRAM_FB0;
124 sceDisplaySetFrameBuf(psp_screen, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
128 void psp_msleep(int ms)
130 sceKernelDelayThread(ms * 1000);
133 unsigned int psp_pad_read(int blocking)
137 sceCtrlReadBufferPositive(&pad, 1);
138 else sceCtrlPeekBufferPositive(&pad, 1);
143 int psp_get_cpu_clock(void)
145 return scePowerGetCpuClockFrequencyInt();
148 int psp_set_cpu_clock(int clock)
150 int ret = scePowerSetClockFrequency(clock, clock, clock/2);
151 if (ret != 0) lprintf("failed to set clock: %i\n", ret);
157 #define LOG_FILE "log.log"
159 void lprintf_f(const char *fmt, ...)
166 logfd = sceIoOpen(LOG_FILE, PSP_O_WRONLY|PSP_O_APPEND, 0777);
172 vsnprintf(buff, sizeof(buff), fmt, vl);
175 sceIoWrite(logfd, buff, strlen(buff));
176 //sceKernelDelayThread(200 * 1000);