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\n", sceKernelGetThreadId());
37 cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
38 sceKernelRegisterExitCallback(cbid);
40 sceKernelSleepThreadCB();
49 lprintf("entered psp_init, threadId %i\n", sceKernelGetThreadId());
51 thid = sceKernelCreateThread("update_thread", callback_thread, 0x11, 0xFA0, 0, 0);
54 sceKernelStartThread(thid, 0, 0);
58 sceDisplaySetMode(0, 480, 272);
59 sceDisplaySetFrameBuf(VRAM_FB1, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
61 psp_screen = VRAM_FB0;
66 sceGuStart(GU_DIRECT, guCmdList);
67 sceGuDrawBuffer(GU_PSM_5650, VRAMOFFS_FB0, 512); // point to back fb?
68 sceGuDispBuffer(480, 272, VRAMOFFS_FB1, 512);
69 sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
70 sceGuDepthBuffer(VRAMOFFS_DEPTH, 512);
71 sceGuOffset(2048 - (480 / 2), 2048 - (272 / 2));
72 sceGuViewport(2048, 2048, 480, 272);
73 sceGuDepthRange(0xc350, 0x2710);
74 sceGuScissor(0, 0, 480, 272);
75 sceGuEnable(GU_SCISSOR_TEST);
76 // sceGuAlphaFunc(GU_GREATER, 0, 0xff);
77 // sceGuEnable(GU_ALPHA_TEST);
78 // sceGuDepthFunc(GU_ALWAYS); // GU_GEQUAL);
79 // sceGuEnable(GU_DEPTH_TEST);
81 sceGuDepthMask(0xffff);
82 sceGuDisable(GU_DEPTH_TEST);
84 sceGuFrontFace(GU_CW);
85 // sceGuShadeModel(GU_SMOOTH);
86 // sceGuEnable(GU_CULL_FACE);
87 sceGuEnable(GU_TEXTURE_2D);
88 // sceGuEnable(GU_CLIP_PLANES);
89 sceGuTexMode(GU_PSM_5650, 0, 0, 0);
90 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
91 sceGuTexFilter(GU_NEAREST, GU_NEAREST);
92 // sceGuAmbientColor(0xffffffff);
93 // sceGuEnable(GU_BLEND);
94 // sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
98 sceDisplayWaitVblankStart();
99 sceGuDisplay(GU_TRUE);
103 sceCtrlSetSamplingCycle(0);
104 sceCtrlSetSamplingMode(0);
107 void psp_finish(void)
111 //sceKernelSleepThread();
115 void psp_video_flip(int wait_vsync)
117 if (wait_vsync) sceDisplayWaitVblankStart();
118 sceDisplaySetFrameBuf(psp_screen, 512, PSP_DISPLAY_PIXEL_FORMAT_565,
119 wait_vsync ? PSP_DISPLAY_SETBUF_IMMEDIATE : PSP_DISPLAY_SETBUF_NEXTFRAME);
121 psp_screen = current_screen ? VRAM_FB0 : VRAM_FB1;
124 void *psp_video_get_active_fb(void)
126 return current_screen ? VRAM_FB1 : VRAM_FB0;
129 void psp_video_switch_to_single(void)
131 psp_screen = VRAM_FB0;
132 sceDisplaySetFrameBuf(psp_screen, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
136 void psp_msleep(int ms)
138 sceKernelDelayThread(ms * 1000);
141 unsigned int psp_pad_read(int blocking)
145 sceCtrlReadBufferPositive(&pad, 1);
146 else sceCtrlPeekBufferPositive(&pad, 1);
151 int psp_get_cpu_clock(void)
153 return scePowerGetCpuClockFrequencyInt();
156 int psp_set_cpu_clock(int clock)
158 int ret = scePowerSetClockFrequency(clock, clock, clock/2);
159 if (ret != 0) lprintf("failed to set clock: %i\n", ret);
165 #define LOG_FILE "log.log"
167 void lprintf_f(const char *fmt, ...)
174 logfd = sceIoOpen(LOG_FILE, PSP_O_WRONLY|PSP_O_APPEND, 0777);
180 vsnprintf(buff, sizeof(buff), fmt, vl);
183 sceIoWrite(logfd, buff, strlen(buff));
184 //sceKernelDelayThread(200 * 1000);