*/
#include <windows.h>
#include <stdio.h>
+#include <dirent.h>
-#include "../common/plat.h"
+#include "../libpicofe/plat.h"
+#include "../libpicofe/posix.h"
#include "../common/emu.h"
-#include "../common/version.h"
-#include <pico/pico.h>
-#include "direct.h"
-#include "dsnd.h"
-#include "main.h"
-
-static unsigned short screen_buff[320 * 240];
-const char *renderer_names[] = { NULL };
-const char *renderer_names32x[] = { NULL };
-
-int plat_parse_arg(int argc, char *argv[], int *x)
-{
- return 1;
-}
-
-void plat_init(void)
-{
- g_screen_ptr = (void *)screen_buff;
-}
+#include <pico/pico_int.h>
int plat_is_dir(const char *path)
{
return GetTickCount() * 1000;
}
-void plat_wait_till_us(unsigned int us)
-{
- int msdiff = (int)(us - plat_get_ticks_us()) / 1000;
- if (msdiff > 6)
- Sleep(msdiff - 6);
- while (plat_get_ticks_us() < us)
- ;
-}
-
void plat_sleep_ms(int ms)
{
Sleep(ms);
return -1;
}
-void pemu_prep_defconfig(void)
-{
- memset(&defaultConfig, 0, sizeof(defaultConfig));
- defaultConfig.s_PicoCDBuffers = 0;
- defaultConfig.Frameskip = 0;
-}
-
-void pemu_validate_config(void)
-{
-}
-
-void pemu_loop_prep(void)
-{
- PicoDrawSetOutFormat(PDF_RGB555, 1);
- PicoDrawSetOutBuf(g_screen_ptr, g_screen_ppitch * 2);
- pemu_sound_start();
-}
-
-void pemu_loop_end(void)
-{
- pemu_sound_stop();
-}
-
-void pemu_forced_frame(int no_scale, int do_emu)
-{
-}
-
-void pemu_finalize_frame(const char *fps, const char *notice_msg)
-{
-}
-
-void plat_video_flip(void)
-{
- DirectScreen(g_screen_ptr);
- DirectPresent();
-}
-
-void plat_video_wait_vsync(void)
-{
-}
-
-void plat_video_toggle_renderer(int change, int is_menu)
-{
- // this will auto-select SMS/32X renderers
- PicoDrawSetOutFormat(PDF_RGB555, 1);
-}
-
-void emu_video_mode_change(int start_line, int line_count, int start_col, int col_count)
-{
- EmuScreenRect.left = start_col;
- EmuScreenRect.right = start_col + col_count;
- EmuScreenRect.top = start_line;
- EmuScreenRect.bottom = start_line + line_count;
-
- PostMessage(FrameWnd, WM_COMMAND, 0x20000 | 2000, 0);
-}
-
-static int sndbuff[2*44100/50/2 + 4];
-
-static void update_sound(int len)
-{
- /* avoid writing audio when lagging behind to prevent audio lag */
- if (PicoIn.skipFrame != 2)
- DSoundUpdate(sndbuff, (currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) ? 0 : 1);
-}
-
-void pemu_sound_start(void)
-{
- int ret;
-
- PicoIn.sndOut = NULL;
- currentConfig.EmuOpt &= ~EOPT_EXT_FRMLIMIT;
-
- // prepare sound stuff
- if (currentConfig.EmuOpt & EOPT_EN_SOUND)
- {
- PsndRerate(0);
-
- ret = DSoundInit(FrameWnd, PicoIn.sndRate, (PicoIn.opt & POPT_EN_STEREO) ? 1 : 0, Pico.snd.len);
- if (ret != 0) {
- lprintf("dsound init failed\n");
- return;
- }
-
- PicoIn.sndOut = (void *)sndbuff;
- PicoIn.writeSound = update_sound;
- currentConfig.EmuOpt |= EOPT_EXT_FRMLIMIT;
- }
-}
-
-void pemu_sound_stop(void)
-{
- DSoundExit();
-}
-
-void pemu_sound_wait(void)
-{
-}
-
int plat_get_root_dir(char *dst, int len)
{
int ml;
return ml;
}
-void plat_status_msg_busy_first(const char *msg)
-{
-}
-
-void plat_status_msg_busy_next(const char *msg)
-{
-}
-
-void plat_status_msg_clear(void)
-{
-}
-
-void plat_video_menu_enter(int is_rom_loaded)
+int plat_get_skin_dir(char *dst, int len)
{
-}
+ int ml;
-void plat_video_menu_begin(void)
-{
+ ml = GetModuleFileName(NULL, dst, len);
+ while (ml > 0 && dst[ml] != '\\')
+ ml--;
+ if (ml != 0)
+ dst[ml++] = '\\';
+ memcpy(dst + ml, "skin\\", sizeof("skin\\"));
+ dst[ml + sizeof("skin\\")] = 0;
+ return ml + sizeof("skin\\") - 1;
}
-void plat_video_menu_end(void)
+int plat_get_data_dir(char *dst, int len)
{
+ return plat_get_root_dir(dst, len);
}
-void plat_update_volume(int has_changed, int is_up)
+void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed)
{
-}
+ void *ptr;
+ unsigned long old;
-const char *plat_get_credits(void)
-{
- return "PicoDrive v" VERSION " minibeta (c) notaz, 2006-2009\n\n"
- "Credits:\n"
- "fDave: base code of PicoDrive\n"
- "Chui: Fame/C\n"
- "NJ: CZ80\n"
- "MAME devs: YM2612, SN76496 and SH2 cores\n"
- "Stéphane Dallongeville: base of Fame/C (C68K), CZ80\n\n"
- "Special thanks (ideas, valuable information and stuff):\n"
- "Charles MacDonald, Eke, Exophase, Haze, Lordus, Nemesis,\n"
- "Pierpaolo Prazzoli, Rokas, Steve Snake, Tasco Deluxe.\n";
+ ptr = VirtualAlloc(NULL, size, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE);
+ if (ptr && need_exec)
+ VirtualProtect(ptr, size, PAGE_EXECUTE_READWRITE, &old);
+ return ptr;
}
-void plat_debug_cat(char *str)
+void plat_munmap(void *ptr, size_t size)
{
+ VirtualFree(ptr, 0, MEM_RELEASE);
}
-// required by pico
-int mp3_get_bitrate(void *f, int size)
+void *plat_mremap(void *ptr, size_t oldsize, size_t newsize)
{
- return 128;
+ void *ret = plat_mmap(0, newsize, 0, 0);
+ if (ret != NULL) {
+ memcpy(ret, ptr, oldsize);
+ plat_munmap(ptr, oldsize);
+ }
+ return ret;
}
-void mp3_start_play(void *f, int pos)
+int plat_mem_set_exec(void *ptr, size_t size)
{
-}
+ unsigned long old;
-void mp3_update(int *buffer, int length, int stereo)
-{
+ return -(VirtualProtect(ptr, size, PAGE_EXECUTE_READWRITE, &old) == 0);
}
// other
printf("%s", buf);
}
-// fake
-int alphasort() { return 0; }
-int scandir() { return 0; }
+// missing from mingw32
+int scandir(const char *dir, struct dirent ***namelist, int (*select)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)) {
+ HANDLE handle;
+ WIN32_FIND_DATA info;
+ char path[MAX_PATH];
+ struct dirent **entries = NULL;
+ size_t count = 0;
+
+ snprintf(path, sizeof(path), "%s\\*", dir);
+ handle = FindFirstFile(path, &info);
+ if (handle == INVALID_HANDLE_VALUE)
+ return -1;
+
+ do {
+ struct dirent *entry = (struct dirent *)malloc(sizeof(struct dirent));
+ if (!entry) {
+ free(entries);
+ FindClose(handle);
+ return -1;
+ }
+
+ strcpy(entry->d_name, info.cFileName);
+ entry->d_type = (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? DT_DIR : DT_REG;
+
+ if (!select || select(entry)) {
+ entries = realloc(entries, (count + 1) * sizeof(struct dirent *));
+ entries[count++] = entry;
+ } else
+ free(entry);
+ } while (FindNextFile(handle, &info));
+ FindClose(handle);
+
+ // Sort entries if a comparison function is provided
+ if (compar) {
+ qsort(entries, count, sizeof(struct dirent *), (int (*)(const void *, const void *))compar);
+ }
+
+ *namelist = entries;
+ return count;
+}
+
+int alphasort(const struct dirent **a, const struct dirent **b) {
+ return strcmp((*a)->d_name, (*b)->d_name);
+}