1 // vim:shiftwidth=2:expandtab
10 #include <sys/types.h>
13 #include <asm/ucontext.h>
17 #include <sys/resource.h>
18 #include <sys/ioctl.h>
19 #include <linux/soundcard.h>
23 #include "../common/host_fb.h"
24 #include "../common/cmn.h"
25 #include "sys_cacheflush.h"
26 #include "realfuncs.h"
28 #if (DBG & 2) && !(DBG & 4)
43 #define iolog_unh log_io
45 #define iolog_unh(...)
49 #define segvlog printf
54 #if defined(LOG_IO) || defined(LOG_IO_UNK)
55 #include "mmsp2-regs.h"
58 typedef unsigned long long u64;
59 typedef unsigned int u32;
60 typedef unsigned short u16;
61 typedef unsigned char u8;
63 static pthread_mutex_t fb_mutex = PTHREAD_MUTEX_INITIALIZER;
64 static pthread_cond_t fb_cond = PTHREAD_COND_INITIALIZER;
85 #define SRCCTRL_INVIDEO (1 << 8)
86 #define SRCCTRL_SRCENB (1 << 7)
87 #define CTRL_TRANSPARENCYENB (1 << 11)
100 u16 mlc_stl_pallt_d[256*2];
101 u32 mlc_stl_pallt_d32[256];
107 u32 btn_state; // as seen through /dev/GPIO
112 #if defined(LOG_IO) || defined(LOG_IO_UNK)
113 static void log_io(const char *pfx, u32 a, u32 d, int size)
115 const char *fmt, *reg = "";
117 case 8: fmt = "%s %08x %02x %s\n"; d &= 0xff; break;
118 case 32: fmt = "%s %08x %08x %s\n"; break;
119 default: fmt = "%s %08x %04x %s\n"; d &= 0xffff; break;
122 if ((a & ~0xffff) == 0x7f000000)
123 reg = regnames[a & 0xffff];
125 printf(fmt, pfx, a, d, reg);
129 static void memset16(void *dst, u32 pattern, int count)
134 d = (u16 *)((long)dst & ~1);
140 pattern |= pattern << 16;
147 *(u16 *)dl = pattern;
150 static void blt_tr(void *dst, void *src, u32 trc, int w)
152 u16 *d = (u16 *)((long)dst & ~1);
153 u16 *s = (u16 *)((long)src & ~1);
156 for (; w > 0; d++, s++, w--)
161 #define dump_blitter() \
163 u32 *r = &blitter.dstctrl; \
165 for (i = 0; i < 4*4; i++, r++) { \
166 printf("%08x ", *r); \
172 static void *uppermem_lookup(u32 addr, u8 **mem_end)
174 // XXX: maybe support mirroring?
175 if ((addr & 0xfe000000) != 0x02000000)
178 *mem_end = (u8 *)mmsp2.umem + 0x02000000;
179 return (u8 *)mmsp2.umem - 0x02000000 + addr;
182 static void blitter_do(void)
184 u8 *dst, *dste, *src = NULL, *srce = NULL;
185 int w, h, sstrd, dstrd;
189 w = blitter.size & 0x7ff;
190 h = (blitter.size >> 16) & 0x7ff;
191 sstrd = blitter.srcstride;
192 dstrd = blitter.dststride;
194 // XXX: need to confirm this..
195 addr = (blitter.dstaddr & ~3) | ((blitter.dstctrl & 0x1f) >> 3);
197 // use dst bpp.. How does it do blits with different src bpp?
198 bpp = (blitter.dstctrl & 0x20) ? 16 : 8;
201 if (((w == 320 && h == 240) || // blit whole screen
202 (w * h >= 320*240/2)) && // ..or at least half of the area
203 mmsp2.mlc_stl_adr <= addr && addr < mmsp2.mlc_stl_adr + 320*240*2)
206 dst = uppermem_lookup(addr, &dste);
208 // XXX: assume fill if no SRCENB, but it could be pattern blit..
209 if (blitter.srcctrl & SRCCTRL_SRCENB) {
210 if (!(blitter.srcctrl & SRCCTRL_INVIDEO))
213 addr = (blitter.srcaddr & ~3) | ((blitter.srcctrl & 0x1f) >> 3);
214 src = uppermem_lookup(addr, &srce);
218 if (src + sstrd * h > srce) {
219 err("blit %08x->%08x %dx%d did not fit src\n",
220 blitter.srcaddr, blitter.dstaddr, w, h);
221 h = (srce - src) / sstrd;
228 if (dst + dstrd * h > dste) {
229 err("blit %08x->%08x %dx%d did not fit dst\n",
230 blitter.srcaddr, blitter.dstaddr, w, h);
231 h = (dste - dst) / dstrd;
236 if (bpp == 16 && (blitter.ctrl & CTRL_TRANSPARENCYENB)) {
237 u32 trc = blitter.ctrl >> 16;
238 for (; h > 0; h--, dst += dstrd, src += sstrd)
239 blt_tr(dst, src, trc, w);
242 for (; h > 0; h--, dst += dstrd, src += sstrd)
243 memcpy(dst, src, w * bpp / 8);
247 // fill. Assume the pattern is cleared and bg color is used
248 u32 bgc = blitter.patbackcolor & 0xffff;
250 for (; h > 0; h--, dst += dstrd)
251 memset16(dst, bgc, w);
254 for (; h > 0; h--, dst += dstrd)
255 memset(dst, bgc, w); // bgc?
260 pthread_cond_signal(&fb_cond);
264 err("blit %08x->%08x %dx%d translated to %p->%p\n",
265 blitter.srcaddr, blitter.dstaddr, w, h, src, dst);
269 // FIXME: pass real dimensions to blitters
270 static void mlc_flip(void *src, int bpp)
274 // only pass pal to host if it's dirty
275 if (bpp <= 8 && mmsp2.dirty_pal) {
276 host_video_update_pal(mmsp2.mlc_stl_pallt_d32);
280 if (bpp != old_bpp) {
281 host_video_change_bpp(bpp);
287 host_video_blit4(src, 320, 240);
291 host_video_blit8(src, 320, 240);
295 host_video_blit16(src, 320, 240);
304 #define ts_add_nsec(ts, ns) { \
306 if (ts.tv_nsec >= 1000000000) { \
308 ts.tv_nsec -= 1000000000; \
312 static int fb_sync_thread_paused;
314 static void *fb_sync_thread(void *arg)
316 int invalid_fb_addr = 1;
317 int manual_refresh = 0;
321 //ret = pthread_setschedprio(pthread_self(), -1);
322 //log("pthread_setschedprio %d\n", ret);
323 //ret = setpriority(PRIO_PROCESS, 0, -1);
324 //log("setpriority %d\n", ret);
326 ret = clock_gettime(CLOCK_REALTIME, &ts);
328 perror(PFX "clock_gettime");
333 u8 *gp2x_fb, *gp2x_fb_end;
336 ret = pthread_mutex_lock(&fb_mutex);
337 wait_ret = pthread_cond_timedwait(&fb_cond, &fb_mutex, &ts);
338 ret |= pthread_mutex_unlock(&fb_mutex);
341 err("fb_thread: mutex error: %d\n", ret);
345 if (wait_ret != 0 && wait_ret != ETIMEDOUT) {
346 err("fb_thread: cond error: %d\n", wait_ret);
350 if (fb_sync_thread_paused) {
351 ts_add_nsec(ts, 100000000);
355 if (wait_ret != ETIMEDOUT) {
356 clock_gettime(CLOCK_REALTIME, &ts);
357 ts_add_nsec(ts, 50000000);
359 if (manual_refresh == 2)
360 dbg("fb_thread: switch to manual refresh\n");
362 ts_add_nsec(ts, 16666667);
363 if (manual_refresh > 1)
364 dbg("fb_thread: switch to auto refresh\n");
368 mode = (mmsp2.mlc_stl_cntl >> 9) & 3;
369 bpp = mode ? mode * 8 : 4;
371 gp2x_fb = uppermem_lookup(mmsp2.mlc_stl_adr, &gp2x_fb_end);
372 if (gp2x_fb == NULL || gp2x_fb + 320*240 * bpp / 8 > gp2x_fb_end) {
373 if (!invalid_fb_addr) {
374 err("fb_thread: %08x is out of range\n", mmsp2.mlc_stl_adr);
380 mlc_flip(gp2x_fb, bpp);
384 static void fb_thread_pause(void)
386 fb_sync_thread_paused = 1;
387 // wait until it finishes last refresh
388 // that it might be doing now
392 static void fb_thread_resume(void)
394 fb_sync_thread_paused = 0;
397 static u32 xread8(u32 a)
399 iolog("r8 ", a, 0, 8);
400 iolog_unh("r8 ", a, 0, 8);
404 static u32 xread16(u32 a)
406 static u32 fudge, old_a;
409 if ((a & 0xffff0000) == 0x7f000000) {
417 // 0000 P000 VuVd00 0000 YXBA RLSeSt 0R0D 0L0U
418 // | GPIOD |GPIOC[8:15]|GPIOM[0:7]|
421 case 0x1184: // GPIOC
422 d = ~mmsp2.btn_state & 0xff00;
425 case 0x1186: // GPIOD
426 t = ~mmsp2.btn_state;
427 d = (t >> 9) & 0x0080;
428 d |= (t >> 11) & 0x0040;
429 d |= (t >> 7) & 0x0800;
432 case 0x1198: // GPIOM
433 mmsp2.btn_state = host_read_btns();
434 d = ~mmsp2.btn_state & 0xff;
437 case 0x1836: // reserved
440 case 0x2816: // DPC_X_MAX
443 case 0x2818: // DPC_Y_MAX
447 d = mmsp2.mlc_stl_cntl;
451 d = mmsp2.mlc_stl_adrl;
455 d = mmsp2.mlc_stl_adrh;
458 d = mmsp2.mlc_stl_pallt_a;
472 iolog_unh("r16", a, d & 0xffff, 16);
476 iolog("r16", a, d, 16);
480 static u32 xread32(u32 a)
483 if ((a & 0xfff00000) == 0x7f000000) {
489 case 0x0a00: // TCOUNT, 1/7372800s
490 clock_gettime(CLOCK_REALTIME, &ts);
491 t64 = (u64)ts.tv_sec * 1000000000 + ts.tv_nsec;
492 // t * 7372800.0 / 1000000000 * 0x100000000 ~= t * 31665935
498 if ((a & 0xfff00000) == 0x7f100000) {
499 u32 *bl = &blitter.dstctrl;
508 iolog_unh("r32", a, d, 32);
511 iolog("r32", a, d, 32);
515 static void xwrite8(u32 a, u32 d)
517 iolog("w8 ", a, d, 8);
518 iolog_unh("w8 ", a, d, 8);
521 static void xwrite16(u32 a, u32 d)
523 iolog("w16", a, d, 16);
524 if ((a & 0xfff00000) == 0x7f000000) {
528 mmsp2.mlc_stl_cntl = d | 0xaa;
532 // odd addresses don't affect LCD. What about TV?
535 mmsp2.mlc_stl_adrl = d;
538 mmsp2.mlc_stl_adrh = d;
539 if (mmsp2.mlc_stl_adr != mmsp2.old_mlc_stl_adr)
541 pthread_cond_signal(&fb_cond);
542 mmsp2.old_mlc_stl_adr = mmsp2.mlc_stl_adr;
545 mmsp2.mlc_stl_pallt_a = d & 0x1ff;
548 mmsp2.mlc_stl_pallt_d[mmsp2.mlc_stl_pallt_a++] = d;
549 mmsp2.mlc_stl_pallt_a &= 0x1ff;
554 iolog_unh("w16", a, d, 16);
557 static void xwrite32(u32 a, u32 d)
559 iolog("w32", a, d, 32);
561 if ((a & 0xfff00000) == 0x7f100000) {
562 u32 *bl = &blitter.dstctrl;
566 if (a_ == 0x34 && (d & 1))
571 iolog_unh("w32", a, d, 32);
574 #define LINKPAGE_SIZE 0x1000
575 #define LINKPAGE_COUNT 4
576 #define LINKPAGE_ALLOC (LINKPAGE_SIZE * LINKPAGE_COUNT)
585 void (*handler)(struct op_context *op_ctx);
589 struct op_stackframe {
594 static struct op_linkpage *g_linkpage;
595 static u32 *g_code_ptr;
596 static int g_linkpage_count;
598 #define BIT_SET(v, b) (v & (1 << (b)))
600 void emu_handle_op(struct op_context *op_ctx, struct op_stackframe *sframe)
602 u32 *regs = sframe->saved_regs;
604 u32 t, shift, ret, addr;
607 rd = (op & 0x0000f000) >> 12;
608 rn = (op & 0x000f0000) >> 16;
610 if ((op & 0x0f200090) == 0x01000090) { // AM3: LDRH, STRH
611 if (!BIT_SET(op, 5)) // !H
613 if (BIT_SET(op, 6) && !BIT_SET(op, 20)) // S && !L
616 if (BIT_SET(op, 22)) // imm offset
617 t = ((op & 0xf00) >> 4) | (op & 0x0f);
619 t = regs[op & 0x000f];
621 if (!BIT_SET(op, 23))
625 if (BIT_SET(op, 20)) { // Load
627 if (BIT_SET(op, 6)) { // S
629 ret = (signed int)ret >> 16;
634 xwrite16(addr, regs[rd]);
636 else if ((op & 0x0d200000) == 0x05000000) { // AM2: LDR[B], STR[B]
637 if (BIT_SET(op, 25)) { // reg offs
641 t = regs[op & 0x000f];
642 shift = (op & 0x0f80) >> 7;
643 switch ((op & 0x0060) >> 5) {
644 case 0: t = t << shift; break;
645 case 1: t = t >> (shift + 1); break;
646 case 2: t = (signed int)t >> (shift + 1); break;
647 case 3: goto unhandled; // I'm just lazy
653 if (!BIT_SET(op, 23))
657 if (BIT_SET(op, 20)) { // Load
658 if (BIT_SET(op, 22)) // Byte
665 if (BIT_SET(op, 22)) // Byte
666 xwrite8(addr, regs[rd]);
668 xwrite32(addr, regs[rd]);
675 if (addr != addr_check) {
676 fprintf(stderr, "bad calculated addr: %08x vs %08x\n", addr, addr_check);
683 err("unhandled IO op %08x @ %08x\n", op, op_ctx->pc);
686 static u32 make_offset12(u32 *pc, u32 *target)
690 lp_offs = (char *)target - (char *)pc - 2*4;
695 if (lp_offs >= LINKPAGE_SIZE) {
696 err("linkpage too far: %d\n", lp_offs);
700 return (u << 23) | lp_offs;
703 static u32 make_jmp(u32 *pc, u32 *target, int bl)
707 jmp_val = target - pc - 2;
708 if (jmp_val < (int)0xff000000 || jmp_val > 0x00ffffff) {
709 err("jump out of range (%p -> %p)\n", pc, target);
713 return 0xea000000 | (bl << 24) | (jmp_val & 0x00ffffff);
716 static void emit_op(u32 op)
721 static void emit_op_io(u32 op, u32 *target)
723 op |= make_offset12(g_code_ptr, target);
727 static void init_linkpage(void)
729 g_linkpage->handler = emu_call_handle_op;
730 g_code_ptr = g_linkpage->code;
733 static void segv_sigaction(int num, siginfo_t *info, void *ctx)
735 struct ucontext *context = ctx;
736 u32 *regs = (u32 *)&context->uc_mcontext.arm_r0;
737 u32 *pc = (u32 *)regs[15];
738 struct op_context *op_ctx;
741 if (((regs[15] ^ (u32)&segv_sigaction) & 0xff000000) == 0 || // PC is in our segment or
742 (((regs[15] ^ (u32)g_linkpage) & ~(LINKPAGE_ALLOC - 1)) == 0) || // .. in linkpage
743 ((long)info->si_addr & 0xffe00000) != 0x7f000000) // faulting not where expected
745 // real crash - time to die
746 err("segv %d %p @ %08x\n", info->si_code, info->si_addr, regs[15]);
747 for (i = 0; i < 8; i++)
748 dbg(" r%d=%08x r%2d=%08x\n", i, regs[i], i+8, regs[i+8]);
749 signal(num, SIG_DFL);
753 segvlog("segv %d %p @ %08x\n", info->si_code, info->si_addr, regs[15]);
756 op_ctx = (void *)g_code_ptr;
757 op_ctx->pc = (u32)pc;
759 g_code_ptr = &op_ctx->code[0];
761 // emit jump to code ptr
762 *pc = make_jmp(pc, g_code_ptr, 0);
765 emit_op (0xe50d0000 + 0xf00 - 4 * 0); // str r0, [sp, #(-0xf00 + r0_offs)]
766 emit_op (0xe50de000 + 0xf00 - 4 * 14); // str lr, [sp, #(-0xf00 + lr_offs)]
767 emit_op (0xe24f0000 + (g_code_ptr - (u32 *)op_ctx + 2) * 4); // sub r0, pc, #op_ctx
768 emit_op (0xe1a0e00f); // mov lr, pc
769 emit_op_io(0xe51ff000, (u32 *)&g_linkpage->handler); // ldr pc, =handle_op
770 emit_op (0xe51de000 + 0xf00 - 4 * 14); // ldr lr, [sp, #(-0xf00 + lr_offs)]
771 emit_op (make_jmp(g_code_ptr, pc + 1, 0)); // jmp <back>
774 sys_cacheflush(pc, pc + 1);
775 sys_cacheflush(g_linkpage, g_code_ptr);
777 lp_size = (char *)g_code_ptr - (char *)g_linkpage;
778 segvlog("code #%d %d/%d\n", g_linkpage_count, lp_size, LINKPAGE_SIZE);
780 if (lp_size + 13*4 > LINKPAGE_SIZE) {
782 if (g_linkpage_count >= LINKPAGE_COUNT) {
783 err("too many linkpages needed\n");
786 g_linkpage = (void *)((char *)g_linkpage + LINKPAGE_SIZE);
789 //handle_op(regs[15], op, regs, (u32)info->si_addr);
793 void emu_init(void *map_bottom)
795 sigaction_t segv_action = {
796 .sa_sigaction = segv_sigaction,
797 .sa_flags = SA_SIGINFO,
803 g_linkpage = (void *)(((u32)map_bottom - LINKPAGE_ALLOC) & ~0xfff);
804 pret = mmap(g_linkpage, LINKPAGE_ALLOC, PROT_READ|PROT_WRITE,
805 MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
806 if (pret != g_linkpage) {
807 perror(PFX "mmap linkpage");
810 log("linkpages @ %p\n", g_linkpage);
816 err("can't init host\n");
820 ret = host_video_init(NULL, 0);
822 err("can't init host video\n");
827 // we are short on memmory on Wiz, need special handling
828 extern void *host_mmap_upper(void);
829 mmsp2.umem = host_mmap_upper();
831 mmsp2.umem = mmap(NULL, 0x2000000, PROT_READ|PROT_WRITE|PROT_EXEC,
832 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
834 if (mmsp2.umem == MAP_FAILED) {
835 perror(PFX "mmap upper mem");
839 ret = pthread_create(&tid, NULL, fb_sync_thread, NULL);
841 err("failed to create fb_sync_thread: %d\n", ret);
847 mmsp2.mlc_stl_adr = 0x03101000; // fb2 is at 0x03381000
848 mmsp2.mlc_stl_cntl = 0x4ab; // 16bpp, region 1 active
850 sigemptyset(&segv_action.sa_mask);
851 sigaction(SIGSEGV, &segv_action, NULL);
854 int emu_read_gpiodev(void *buf, int count)
857 err("gpiodev read %d?\n", count);
863 mmsp2.btn_state = host_read_btns();
864 memcpy(buf, &mmsp2.btn_state, count);
868 struct dev_fd_t emu_interesting_fds[] = {
869 [IFD_SOUND] = { "/dev/dsp", -1 },
873 static void *emu_mmap_dev(unsigned int length, int prot, int flags, unsigned int offset)
878 if ((offset & ~0xffff) == 0xc0000000) {
879 return mmap((void *)0x7f000000, length, PROT_NONE,
880 MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED|MAP_NORESERVE, -1, 0);
883 if ((offset & ~0xffff) == 0xe0020000) {
884 return mmap((void *)0x7f100000, length, PROT_NONE,
885 MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED|MAP_NORESERVE, -1, 0);
888 if ((offset & 0xfe000000) != 0x02000000) {
889 err("unexpected devmem mmap @ %08x\n", offset);
894 umem = uppermem_lookup(offset, &umem_end);
895 if (umem + length > umem_end)
896 err("warning: uppermem @ %08x overflows by %d bytes\n",
897 offset, umem + length - umem_end);
899 dbg("upper mem @ %08x %d\n", offset, length);
903 void *emu_do_mmap(unsigned int length, int prot, int flags, int fd, unsigned int offset)
905 if (fd == FAKEDEV_MEM)
906 return emu_mmap_dev(length, prot, flags, offset);
908 if (fd == FAKEDEV_FB0)
909 return emu_mmap_dev(length, prot, flags, offset + 0x03101000);
911 if (fd == FAKEDEV_FB1)
912 return emu_mmap_dev(length, prot, flags, offset + 0x03381000);
914 err("bad/ni mmap(?, %d, %x, %x, %d, %08x)\n", length, prot, flags, fd, offset);
919 static int emu_sound_ioctl(int fd, int request, void *argp)
924 dbg("snd ioctl(%d, %08x, %p)", fd, request, argp);
926 dbg_c(" [%d]", *arg);
930 /* People set strange frag settings on GP2X, which even manage
931 * to break audio on pandora (causes writes to fail).
932 * Catch this and set to something that works. */
933 if (request == SNDCTL_DSP_SPEED) {
934 int ret, bsize, frag;
936 // ~4ms. gpSP wants small buffers or else it stutters
937 // because of it's audio thread sync stuff
938 bsize = *arg / 250 * 4;
939 for (frag = 0; bsize; bsize >>= 1, frag++)
942 frag |= 16 << 16; // fragment count
943 ret = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &frag);
945 err("snd ioctl SETFRAGMENT %08x: ", frag);
949 else if (request == SNDCTL_DSP_SETFRAGMENT)
952 return ioctl(fd, request, argp);
955 int emu_do_ioctl(int fd, int request, void *argp)
957 if (fd == emu_interesting_fds[IFD_SOUND].fd)
958 return emu_sound_ioctl(fd, request, argp);
961 /* *********************** */
968 case FBIOGET_FSCREENINFO: {
969 struct fb_fix_screeninfo *fix = argp;
971 memset(fix, 0, sizeof(*fix));
972 strcpy(fix->id, "mmsp2_RGB0");
973 fix->type = FB_TYPE_PACKED_PIXELS;
974 fix->accel = FB_ACCEL_NONE;
975 fix->visual = FB_VISUAL_TRUECOLOR;
976 fix->line_length = 320*2;
977 fix->smem_start = (fd == FAKEDEV_FB0) ? 0x03101000 : 0x03381000;
978 fix->smem_len = 320*240*2;
981 case FBIOGET_VSCREENINFO: {
982 struct fb_var_screeninfo *var = argp;
983 static const struct fb_bitfield fbb_red = { offset: 11, length: 5, };
984 static const struct fb_bitfield fbb_green = { offset: 5, length: 6, };
985 static const struct fb_bitfield fbb_blue = { offset: 0, length: 5, };
987 memset(var, 0, sizeof(*var));
988 var->activate = FB_ACTIVATE_NOW;
990 var->xres_virtual = 320;
992 var->yres_virtual = 240;
995 var->vmode = FB_VMODE_NONINTERLACED;
996 var->bits_per_pixel = 16;
998 var->green = fbb_green;
999 var->blue = fbb_blue;
1002 case FBIOPUT_VSCREENINFO: {
1003 struct fb_var_screeninfo *var = argp;
1004 dbg(" put vscreen: %dx%d@%d\n", var->xres, var->yres, var->bits_per_pixel);
1005 if (var->xres != 320 || var->yres != 240 || var->bits_per_pixel != 16)
1011 /* *********************** */
1013 // fake tty0 to make GPH SDL happy
1014 if (request == 0x4b46) // KDGKBENT
1020 err("bad/ni ioctl(%d, %08x, %p)\n", fd, request, argp);
1025 static const struct {
1029 { "/mnt/tmp/", "/tmp/" },
1032 static const char *wrap_path(const char *path)
1038 // do only path mapping for now
1039 for (i = 0; i < ARRAY_SIZE(path_map); i++) {
1040 len = strlen(path_map[i].from);
1041 if (strncmp(path, path_map[i].from, len) == 0) {
1042 size = strlen(path) + strlen(path_map[i].to) + 1;
1043 buff = malloc(size);
1046 snprintf(buff, size, "%s%s", path_map[i].to, path + len);
1047 dbg("mapped path \"%s\" -> \"%s\"\n", path, buff);
1055 void *emu_do_fopen(const char *path, const char *mode)
1057 const char *w_path = wrap_path(path);
1059 ret = fopen(w_path, mode);
1061 free((void *)w_path);
1066 int emu_do_system(const char *command)
1068 static char tmp_path[512];
1073 if (command == NULL)
1076 // pass through stuff in PATH
1077 p = strchr(command, ' ');
1078 p2 = strchr(command, '/');
1079 if (p2 == NULL || (p != NULL && p2 > p))
1080 return system(command);
1082 make_local_path(tmp_path, sizeof(tmp_path), "ginge_prep");
1083 p = tmp_path + strlen(tmp_path);
1085 p2 = wrap_path(command);
1086 snprintf(p, sizeof(tmp_path) - (p - tmp_path), " --nomenu %s", p2);
1090 dbg("system: \"%s\"\n", tmp_path);
1092 // the app might want the screen too..
1094 ret = system(tmp_path);