6 #include <pspiofilemgr.h>
7 #include <pspdisplay.h>
13 #include "../common/lprintf.h"
15 PSP_MODULE_INFO("PicoDrive", 0, 1, 34);
17 unsigned int __attribute__((aligned(16))) guCmdList[GU_CMDLIST_SIZE];
19 void *psp_screen = VRAM_FB0;
20 static int current_screen = 0; /* front bufer */
22 #define ANALOG_DEADZONE 80
25 static int exit_callback(int arg1, int arg2, void *common)
32 static int callback_thread(SceSize args, void *argp)
36 lprintf("callback_thread started with id %08x, priority %i\n",
37 sceKernelGetThreadId(), sceKernelGetThreadCurrentPriority());
39 cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
40 sceKernelRegisterExitCallback(cbid);
42 sceKernelSleepThreadCB();
51 lprintf("running in %08x kernel\n", sceKernelDevkitVersion()),
52 lprintf("entered psp_init, threadId %08x, priority %i\n", sceKernelGetThreadId(),
53 sceKernelGetThreadCurrentPriority());
55 thid = sceKernelCreateThread("update_thread", callback_thread, 0x11, 0xFA0, 0, 0);
58 sceKernelStartThread(thid, 0, 0);
62 sceDisplaySetMode(0, 480, 272);
63 sceDisplaySetFrameBuf(VRAM_FB1, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
65 psp_screen = VRAM_FB0;
70 sceGuStart(GU_DIRECT, guCmdList);
71 sceGuDrawBuffer(GU_PSM_5650, (void *)VRAMOFFS_FB0, 512);
72 sceGuDispBuffer(480, 272, (void *)VRAMOFFS_FB1, 512); // don't care
73 sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
74 sceGuDepthBuffer((void *)VRAMOFFS_DEPTH, 512);
75 sceGuOffset(2048 - (480 / 2), 2048 - (272 / 2));
76 sceGuViewport(2048, 2048, 480, 272);
77 sceGuDepthRange(0xc350, 0x2710);
78 sceGuScissor(0, 0, 480, 272);
79 sceGuEnable(GU_SCISSOR_TEST);
81 sceGuDepthMask(0xffff);
82 sceGuDisable(GU_DEPTH_TEST);
84 sceGuFrontFace(GU_CW);
85 sceGuEnable(GU_TEXTURE_2D);
86 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
87 sceGuAmbientColor(0xffffffff);
88 sceGuColor(0xffffffff);
92 sceDisplayWaitVblankStart();
93 sceGuDisplay(GU_TRUE);
97 sceCtrlSetSamplingCycle(0);
98 sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
101 void psp_finish(void)
105 //sceKernelSleepThread();
109 void psp_video_flip(int wait_vsync)
111 if (wait_vsync) sceDisplayWaitVblankStart();
112 sceDisplaySetFrameBuf(psp_screen, 512, PSP_DISPLAY_PIXEL_FORMAT_565,
113 wait_vsync ? PSP_DISPLAY_SETBUF_IMMEDIATE : PSP_DISPLAY_SETBUF_NEXTFRAME);
115 psp_screen = current_screen ? VRAM_FB0 : VRAM_FB1;
118 void *psp_video_get_active_fb(void)
120 return current_screen ? VRAM_FB1 : VRAM_FB0;
123 void psp_video_switch_to_single(void)
125 psp_screen = VRAM_FB0;
126 sceDisplaySetFrameBuf(psp_screen, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
130 void psp_msleep(int ms)
132 sceKernelDelayThread(ms * 1000);
135 unsigned int psp_pad_read(int blocking)
137 unsigned int buttons;
140 sceCtrlReadBufferPositive(&pad, 1);
141 else sceCtrlPeekBufferPositive(&pad, 1);
142 buttons = pad.Buttons;
145 buttons &= ~(BTN_NUB_UP|BTN_NUB_DOWN|BTN_NUB_LEFT|BTN_NUB_RIGHT);
146 if (pad.Lx < 128 - ANALOG_DEADZONE) buttons |= BTN_NUB_LEFT;
147 if (pad.Lx > 128 + ANALOG_DEADZONE) buttons |= BTN_NUB_RIGHT;
148 if (pad.Ly < 128 - ANALOG_DEADZONE) buttons |= BTN_NUB_UP;
149 if (pad.Ly > 128 + ANALOG_DEADZONE) buttons |= BTN_NUB_DOWN;
154 int psp_get_cpu_clock(void)
156 return scePowerGetCpuClockFrequencyInt();
159 int psp_set_cpu_clock(int clock)
161 int ret = scePowerSetClockFrequency(clock, clock, clock/2);
162 if (ret != 0) lprintf("failed to set clock: %i\n", ret);
167 char *psp_get_status_line(void)
169 static char buff[64];
170 int ret, bat_percent, bat_time;
173 ret = sceRtcGetCurrentClockLocalTime(&time);
174 bat_percent = scePowerGetBatteryLifePercent();
175 bat_time = scePowerGetBatteryLifeTime();
176 if (ret < 0 || bat_percent < 0 || bat_time < 0) return NULL;
178 snprintf(buff, sizeof(buff), "%02i:%02i bat: %3i%%", time.hour, time.minutes, bat_percent);
179 if (!scePowerIsPowerOnline())
180 snprintf(buff+strlen(buff), sizeof(buff)-strlen(buff), " (%i:%02i)", bat_time/60, bat_time%60);
185 #define LOG_FILE "log.log"
187 static SceUID logfd = -1;
189 void lprintf_f(const char *fmt, ...)
194 if (logfd == -2) return; // disabled
198 logfd = sceIoOpen(LOG_FILE, PSP_O_WRONLY|PSP_O_APPEND, 0777);
206 vsnprintf(buff, sizeof(buff), fmt, vl);
209 sceIoWrite(logfd, buff, strlen(buff));
211 // make sure it gets flushed