5 * This work is licensed under the terms of MAME license.
6 * See COPYING file in the top-level directory.
12 #include "../libpicofe/plat.h"
13 #include "../libpicofe/posix.h"
14 #include "../common/emu.h"
15 #include <pico/pico_int.h>
17 int plat_is_dir(const char *path)
19 return (GetFileAttributes(path) & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0;
22 unsigned int plat_get_ticks_ms(void)
24 return GetTickCount();
27 unsigned int plat_get_ticks_us(void)
29 // XXX: maybe performance counters?
30 return GetTickCount() * 1000;
33 void plat_sleep_ms(int ms)
38 int plat_wait_event(int *fds_hnds, int count, int timeout_ms)
43 int plat_get_root_dir(char *dst, int len)
47 ml = GetModuleFileName(NULL, dst, len);
48 while (ml > 0 && dst[ml] != '\\')
57 int plat_get_skin_dir(char *dst, int len)
61 ml = GetModuleFileName(NULL, dst, len);
62 while (ml > 0 && dst[ml] != '\\')
66 memcpy(dst + ml, "skin\\", sizeof("skin\\"));
67 dst[ml + sizeof("skin\\")] = 0;
68 return ml + sizeof("skin\\") - 1;
71 int plat_get_data_dir(char *dst, int len)
73 return plat_get_root_dir(dst, len);
76 void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed)
81 ptr = VirtualAlloc(NULL, size, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE);
83 VirtualProtect(ptr, size, PAGE_EXECUTE_READWRITE, &old);
87 void plat_munmap(void *ptr, size_t size)
89 VirtualFree(ptr, 0, MEM_RELEASE);
92 void *plat_mremap(void *ptr, size_t oldsize, size_t newsize)
94 void *ret = plat_mmap(0, newsize, 0, 0);
96 memcpy(ret, ptr, oldsize);
97 plat_munmap(ptr, oldsize);
102 int plat_mem_set_exec(void *ptr, size_t size)
106 return -(VirtualProtect(ptr, size, PAGE_EXECUTE_READWRITE, &old) == 0);
110 void lprintf(const char *fmt, ...)
116 vsnprintf(buf, sizeof(buf), fmt, val);
118 OutputDebugString(buf);
122 // missing from mingw32
123 int scandir(const char *dir, struct dirent ***namelist, int (*select)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)) {
125 WIN32_FIND_DATA info;
127 struct dirent **entries = NULL;
130 snprintf(path, sizeof(path), "%s\\*", dir);
131 handle = FindFirstFile(path, &info);
132 if (handle == INVALID_HANDLE_VALUE)
136 struct dirent *entry = (struct dirent *)malloc(sizeof(struct dirent));
143 strcpy(entry->d_name, info.cFileName);
144 entry->d_type = (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? DT_DIR : DT_REG;
146 if (!select || select(entry)) {
147 entries = realloc(entries, (count + 1) * sizeof(struct dirent *));
148 entries[count++] = entry;
151 } while (FindNextFile(handle, &info));
155 // Sort entries if a comparison function is provided
157 qsort(entries, count, sizeof(struct dirent *), (int (*)(const void *, const void *))compar);
164 int alphasort(const struct dirent **a, const struct dirent **b) {
165 return strcmp((*a)->d_name, (*b)->d_name);