// Make buffer for the next seg to put into the loop:\r
DSoundNext=(short *)malloc((PsndLen<<2)+64); if (DSoundNext==NULL) return 1;\r
memset(DSoundNext,0,PsndLen<<2);\r
-// dprintf2("p %p\n", DSoundNext);\r
+// lprintf("p %p\n", DSoundNext);\r
\r
// Create the DirectSound interface:\r
DirectSoundCreate(NULL,&DSound,NULL);\r
\r
// Lock the segment at 'LoopWrite' and copy the next segment in\r
ret = LoopBuffer->Lock(LoopWrite<<((PicoOpt&8) ? 2 : 1),PsndLen<<((PicoOpt&8) ? 2 : 1), &mema,&sizea, &memb,&sizeb, 0);\r
- if (ret) dprintf2("LoopBuffer->Lock() failed: %i\n", ret);\r
+ if (ret) lprintf("LoopBuffer->Lock() failed: %i\n", ret);\r
\r
if (mema) memcpy(mema,DSoundNext,sizea);\r
// if (memb) memcpy(memb,DSoundNext+sizea,sizeb);\r
- if (sizeb != 0) dprintf2("sizeb is not 0! (%i)\n", sizeb);\r
+ if (sizeb != 0) lprintf("sizeb is not 0! (%i)\n", sizeb);\r
\r
ret = LoopBuffer->Unlock(mema,sizea, memb,0);\r
- if (ret) dprintf2("LoopBuffer->Unlock() failed: %i\n", ret);\r
+ if (ret) lprintf("LoopBuffer->Unlock() failed: %i\n", ret);\r
\r
return 0;\r
}\r
#include "version.h"\r
#include <crtdbg.h>\r
#include <commdlg.h>\r
+#include "../../common/readpng.h"\r
\r
char *romname=NULL;\r
HWND FrameWnd=NULL;\r
\r
static HMENU mmain = 0, mdisplay = 0, mpicohw = 0;\r
static int rom_loaded = 0;\r
+static HBITMAP ppad_bmp = 0;\r
+static HBITMAP ppage_bmps[6] = { 0, };\r
+static char rom_name[0x20*3+1];\r
\r
static void UpdateRect()\r
{\r
FrameRectMy = wi.rcClient;\r
}\r
\r
-static void PrepareFroROM()\r
+static int extract_rom_name(char *dest, const unsigned char *src, int len)\r
{\r
- int show = PicoAHW & PAHW_PICO;\r
+ char *p = dest, s_old = 0;\r
+ int i;\r
+\r
+ for (i = len - 1; i >= 0; i--)\r
+ {\r
+ if (src[i^1] != ' ') break;\r
+ }\r
+ len = i + 1;\r
+\r
+ for (i = 0; i < len; i++)\r
+ {\r
+ unsigned char s = src[i^1];\r
+ if (s == 0x20 && s_old == 0x20) continue;\r
+ else if (s >= 0x20 && s < 0x7f && s != '%')\r
+ {\r
+ *p++ = s;\r
+ }\r
+ else\r
+ {\r
+ sprintf(p, "%%%02x", s);\r
+ p += 3;\r
+ }\r
+ s_old = s;\r
+ }\r
+ *p = 0;\r
+\r
+ return p - dest;\r
+}\r
+\r
+\r
+static HBITMAP png2hb(const char *fname, int is_480)\r
+{\r
+ BITMAPINFOHEADER bih;\r
+ HBITMAP bmp;\r
+ void *bmem;\r
+ int ret;\r
+\r
+ bmem = calloc(1, is_480 ? 480*240*3 : 320*240*3);\r
+ if (bmem == NULL) return NULL;\r
+ ret = readpng(bmem, fname, is_480 ? READPNG_480_24 : READPNG_320_24);\r
+ if (ret != 0) {\r
+ free(bmem);\r
+ return NULL;\r
+ }\r
+\r
+ memset(&bih, 0, sizeof(bih));\r
+ bih.biSize = sizeof(bih);\r
+ bih.biWidth = is_480 ? 480 : 320;\r
+ bih.biHeight = -240;\r
+ bih.biPlanes = 1;\r
+ bih.biBitCount = 24;\r
+ bih.biCompression = BI_RGB;\r
+ bmp = CreateDIBitmap(GetDC(FrameWnd), &bih, CBM_INIT, bmem, (BITMAPINFO *)&bih, 0);\r
+ if (bmp == NULL)\r
+ lprintf("CreateDIBitmap failed with %i", GetLastError());\r
+\r
+ free(bmem);\r
+ return bmp;\r
+}\r
+\r
+static void PrepareForROM(unsigned char *rom_data)\r
+{\r
+ int i, ret, show = PicoAHW & PAHW_PICO;\r
EnableMenuItem(mmain, 2, MF_BYPOSITION|(show ? MF_ENABLED : MF_GRAYED));\r
ShowWindow(PicoPadWnd, show ? SW_SHOWNA : SW_HIDE);\r
ShowWindow(PicoSwWnd, show ? SW_SHOWNA : SW_HIDE);\r
CheckMenuItem(mpicohw, 1211, show ? MF_CHECKED : MF_UNCHECKED);\r
PostMessage(FrameWnd, WM_COMMAND, 1220 + PicoPicohw.page, 0);\r
DrawMenuBar(FrameWnd);\r
+ InvalidateRect(PicoSwWnd, NULL, 1);\r
\r
PicoPicohw.pen_pos[0] =\r
PicoPicohw.pen_pos[1] = 0x8000;\r
picohw_pen_pressed = 0;\r
+\r
+ ret = extract_rom_name(rom_name, rom_data + 0x150, 0x20);\r
+ if (ret == 0)\r
+ extract_rom_name(rom_name, rom_data + 0x130, 0x20);\r
+\r
+ if (show)\r
+ {\r
+ char path[MAX_PATH], *p;\r
+ GetModuleFileName(NULL, path, sizeof(path) - 32);\r
+ p = strrchr(path, '\\');\r
+ if (p == NULL) p = path;\r
+ else p++;\r
+ if (ppad_bmp == NULL) {\r
+ strcpy(p, "pico\\pad.png");\r
+ ppad_bmp = png2hb(path, 0);\r
+ }\r
+\r
+ for (i = 0; i < 6; i++) {\r
+ if (ppage_bmps[i] != NULL) DeleteObject(ppage_bmps[i]);\r
+ sprintf(p, "pico\\%s_%i.png", rom_name, i);\r
+ ppage_bmps[i] = png2hb(path, 1);\r
+ }\r
+ }\r
}\r
\r
static void LoadROM(const char *cmdpath)\r
PicoCartUnload();\r
PicoCartInsert(rom_data_new, rom_size);\r
\r
- PrepareFroROM();\r
+ PrepareForROM(rom_data_new);\r
\r
rom_loaded = 1;\r
romname = rompath;\r
for (i = 0; i < 7; i++)\r
CheckMenuItem(mpicohw, 1220 + i, MF_UNCHECKED);\r
CheckMenuItem(mpicohw, 1220 + PicoPicohw.page, MF_CHECKED);\r
+ InvalidateRect(PicoSwWnd, NULL, 1);\r
return 0;\r
case 1300:\r
MessageBox(FrameWnd, "PicoDrive v" VERSION " (c) notaz, 2006-2008\n"\r
\r
static LRESULT CALLBACK PicoSwWndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)\r
{\r
+ PAINTSTRUCT ps;\r
+ HDC hdc, hdc2;\r
+\r
switch (msg)\r
{\r
case WM_CLOSE: return 0;\r
PicoPicohw.pen_pos[1] = 0x2f8 + HIWORD(lparam);\r
SetTimer(FrameWnd, 100, 1000, NULL);\r
break;\r
+ case WM_PAINT:\r
+ hdc = BeginPaint(hwnd, &ps);\r
+ if (ppage_bmps[PicoPicohw.page] == NULL)\r
+ {\r
+ SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT));\r
+ SetTextColor(hdc, RGB(255, 255, 255));\r
+ SetBkColor(hdc, RGB(0, 0, 0));\r
+ TextOut(hdc, 2, 2, "missing PNGs for", 16);\r
+ TextOut(hdc, 2, 18, rom_name, strlen(rom_name));\r
+ }\r
+ else\r
+ {\r
+ hdc2 = CreateCompatibleDC(GetDC(FrameWnd));\r
+ SelectObject(hdc2, ppage_bmps[PicoPicohw.page]);\r
+ BitBlt(hdc, 0, 0, 480, 240, hdc2, 0, 0, SRCCOPY);\r
+ DeleteDC(hdc2);\r
+ }\r
+ EndPaint(hwnd, &ps);\r
+ return 0;\r
}\r
\r
return DefWindowProc(hwnd,msg,wparam,lparam);\r
\r
static LRESULT CALLBACK PicoPadWndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)\r
{\r
+ PAINTSTRUCT ps;\r
+ HDC hdc, hdc2;\r
+\r
switch (msg)\r
{\r
case WM_CLOSE: return 0;\r
PicoPicohw.pen_pos[1] = 0x1fc + HIWORD(lparam);\r
SetTimer(FrameWnd, 100, 1000, NULL);\r
break;\r
+ case WM_PAINT:\r
+ if (ppad_bmp == NULL) break;\r
+ hdc = BeginPaint(hwnd, &ps);\r
+ hdc2 = CreateCompatibleDC(GetDC(FrameWnd));\r
+ SelectObject(hdc2, ppad_bmp);\r
+ BitBlt(hdc, 0, 0, 320, 240, hdc2, 0, 0, SRCCOPY);\r
+ EndPaint(hwnd, &ps);\r
+ DeleteDC(hdc2);\r
+ return 0;\r
}\r
\r
return DefWindowProc(hwnd,msg,wparam,lparam);\r