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 void *fb_sync_thread(void *arg)
314 int invalid_fb_addr = 1;
315 int manual_refresh = 0;
319 //ret = pthread_setschedprio(pthread_self(), -1);
320 //log("pthread_setschedprio %d\n", ret);
321 //ret = setpriority(PRIO_PROCESS, 0, -1);
322 //log("setpriority %d\n", ret);
324 ret = clock_gettime(CLOCK_REALTIME, &ts);
326 perror(PFX "clock_gettime");
331 u8 *gp2x_fb, *gp2x_fb_end;
334 ret = pthread_mutex_lock(&fb_mutex);
335 wait_ret = pthread_cond_timedwait(&fb_cond, &fb_mutex, &ts);
336 ret |= pthread_mutex_unlock(&fb_mutex);
339 err("fb_thread: mutex error: %d\n", ret);
343 if (wait_ret != 0 && wait_ret != ETIMEDOUT) {
344 err("fb_thread: cond error: %d\n", wait_ret);
349 if (wait_ret != ETIMEDOUT) {
350 clock_gettime(CLOCK_REALTIME, &ts);
351 ts_add_nsec(ts, 50000000);
353 if (manual_refresh == 2)
354 dbg("fb_thread: switch to manual refresh\n");
356 ts_add_nsec(ts, 16666667);
357 if (manual_refresh > 1)
358 dbg("fb_thread: switch to auto refresh\n");
362 mode = (mmsp2.mlc_stl_cntl >> 9) & 3;
363 bpp = mode ? mode * 8 : 4;
365 gp2x_fb = uppermem_lookup(mmsp2.mlc_stl_adr, &gp2x_fb_end);
366 if (gp2x_fb == NULL || gp2x_fb + 320*240 * bpp / 8 > gp2x_fb_end) {
367 if (!invalid_fb_addr) {
368 err("fb_thread: %08x is out of range\n", mmsp2.mlc_stl_adr);
374 mlc_flip(gp2x_fb, bpp);
378 static u32 xread8(u32 a)
380 iolog("r8 ", a, 0, 8);
381 iolog_unh("r8 ", a, 0, 8);
385 static u32 xread16(u32 a)
387 static u32 fudge, old_a;
390 if ((a & 0xffff0000) == 0x7f000000) {
398 // 0000 P000 VuVd00 0000 YXBA RLSeSt 0R0D 0L0U
399 // | GPIOD |GPIOC[8:15]|GPIOM[0:7]|
402 case 0x1184: // GPIOC
403 d = ~mmsp2.btn_state & 0xff00;
406 case 0x1186: // GPIOD
407 t = ~mmsp2.btn_state;
408 d = (t >> 9) & 0x0080;
409 d |= (t >> 11) & 0x0040;
410 d |= (t >> 7) & 0x0800;
413 case 0x1198: // GPIOM
414 mmsp2.btn_state = host_read_btns();
415 d = ~mmsp2.btn_state & 0xff;
418 case 0x1836: // reserved
421 case 0x2816: // DPC_X_MAX
424 case 0x2818: // DPC_Y_MAX
428 d = mmsp2.mlc_stl_cntl;
432 d = mmsp2.mlc_stl_adrl;
436 d = mmsp2.mlc_stl_adrh;
439 d = mmsp2.mlc_stl_pallt_a;
453 iolog_unh("r16", a, d & 0xffff, 16);
457 iolog("r16", a, d, 16);
461 static u32 xread32(u32 a)
464 if ((a & 0xfff00000) == 0x7f000000) {
470 case 0x0a00: // TCOUNT, 1/7372800s
471 clock_gettime(CLOCK_REALTIME, &ts);
472 t64 = (u64)ts.tv_sec * 1000000000 + ts.tv_nsec;
473 // t * 7372800.0 / 1000000000 * 0x100000000 ~= t * 31665935
479 if ((a & 0xfff00000) == 0x7f100000) {
480 u32 *bl = &blitter.dstctrl;
489 iolog_unh("r32", a, d, 32);
492 iolog("r32", a, d, 32);
496 static void xwrite8(u32 a, u32 d)
498 iolog("w8 ", a, d, 8);
499 iolog_unh("w8 ", a, d, 8);
502 static void xwrite16(u32 a, u32 d)
504 iolog("w16", a, d, 16);
505 if ((a & 0xfff00000) == 0x7f000000) {
509 mmsp2.mlc_stl_cntl = d | 0xaa;
513 // odd addresses don't affect LCD. What about TV?
516 mmsp2.mlc_stl_adrl = d;
519 mmsp2.mlc_stl_adrh = d;
520 if (mmsp2.mlc_stl_adr != mmsp2.old_mlc_stl_adr)
522 pthread_cond_signal(&fb_cond);
523 mmsp2.old_mlc_stl_adr = mmsp2.mlc_stl_adr;
526 mmsp2.mlc_stl_pallt_a = d & 0x1ff;
529 mmsp2.mlc_stl_pallt_d[mmsp2.mlc_stl_pallt_a++] = d;
530 mmsp2.mlc_stl_pallt_a &= 0x1ff;
535 iolog_unh("w16", a, d, 16);
538 static void xwrite32(u32 a, u32 d)
540 iolog("w32", a, d, 32);
542 if ((a & 0xfff00000) == 0x7f100000) {
543 u32 *bl = &blitter.dstctrl;
547 if (a_ == 0x34 && (d & 1))
552 iolog_unh("w32", a, d, 32);
555 #define LINKPAGE_SIZE 0x1000
556 #define LINKPAGE_COUNT 4
557 #define LINKPAGE_ALLOC (LINKPAGE_SIZE * LINKPAGE_COUNT)
566 void (*handler)(struct op_context *op_ctx);
570 struct op_stackframe {
575 static struct op_linkpage *g_linkpage;
576 static u32 *g_code_ptr;
577 static int g_linkpage_count;
579 #define BIT_SET(v, b) (v & (1 << (b)))
581 void emu_handle_op(struct op_context *op_ctx, struct op_stackframe *sframe)
583 u32 *regs = sframe->saved_regs;
585 u32 t, shift, ret, addr;
588 rd = (op & 0x0000f000) >> 12;
589 rn = (op & 0x000f0000) >> 16;
591 if ((op & 0x0f200090) == 0x01000090) { // AM3: LDRH, STRH
592 if (!BIT_SET(op, 5)) // !H
594 if (BIT_SET(op, 6) && !BIT_SET(op, 20)) // S && !L
597 if (BIT_SET(op, 22)) // imm offset
598 t = ((op & 0xf00) >> 4) | (op & 0x0f);
600 t = regs[op & 0x000f];
602 if (!BIT_SET(op, 23))
606 if (BIT_SET(op, 20)) { // Load
608 if (BIT_SET(op, 6)) { // S
610 ret = (signed int)ret >> 16;
615 xwrite16(addr, regs[rd]);
617 else if ((op & 0x0d200000) == 0x05000000) { // AM2: LDR[B], STR[B]
618 if (BIT_SET(op, 25)) { // reg offs
622 t = regs[op & 0x000f];
623 shift = (op & 0x0f80) >> 7;
624 switch ((op & 0x0060) >> 5) {
625 case 0: t = t << shift; break;
626 case 1: t = t >> (shift + 1); break;
627 case 2: t = (signed int)t >> (shift + 1); break;
628 case 3: goto unhandled; // I'm just lazy
634 if (!BIT_SET(op, 23))
638 if (BIT_SET(op, 20)) { // Load
639 if (BIT_SET(op, 22)) // Byte
646 if (BIT_SET(op, 22)) // Byte
647 xwrite8(addr, regs[rd]);
649 xwrite32(addr, regs[rd]);
656 if (addr != addr_check) {
657 fprintf(stderr, "bad calculated addr: %08x vs %08x\n", addr, addr_check);
664 err("unhandled IO op %08x @ %08x\n", op, op_ctx->pc);
667 static u32 make_offset12(u32 *pc, u32 *target)
671 lp_offs = (char *)target - (char *)pc - 2*4;
676 if (lp_offs >= LINKPAGE_SIZE) {
677 err("linkpage too far: %d\n", lp_offs);
681 return (u << 23) | lp_offs;
684 static u32 make_jmp(u32 *pc, u32 *target, int bl)
688 jmp_val = target - pc - 2;
689 if (jmp_val < (int)0xff000000 || jmp_val > 0x00ffffff) {
690 err("jump out of range (%p -> %p)\n", pc, target);
694 return 0xea000000 | (bl << 24) | (jmp_val & 0x00ffffff);
697 static void emit_op(u32 op)
702 static void emit_op_io(u32 op, u32 *target)
704 op |= make_offset12(g_code_ptr, target);
708 static void init_linkpage(void)
710 g_linkpage->handler = emu_call_handle_op;
711 g_code_ptr = g_linkpage->code;
714 static void segv_sigaction(int num, siginfo_t *info, void *ctx)
716 struct ucontext *context = ctx;
717 u32 *regs = (u32 *)&context->uc_mcontext.arm_r0;
718 u32 *pc = (u32 *)regs[15];
719 struct op_context *op_ctx;
722 if (((regs[15] ^ (u32)&segv_sigaction) & 0xff000000) == 0 || // PC is in our segment or
723 (((regs[15] ^ (u32)g_linkpage) & ~(LINKPAGE_ALLOC - 1)) == 0) || // .. in linkpage
724 ((long)info->si_addr & 0xffe00000) != 0x7f000000) // faulting not where expected
726 // real crash - time to die
727 err("segv %d %p @ %08x\n", info->si_code, info->si_addr, regs[15]);
728 for (i = 0; i < 8; i++)
729 dbg(" r%d=%08x r%2d=%08x\n", i, regs[i], i+8, regs[i+8]);
730 signal(num, SIG_DFL);
734 segvlog("segv %d %p @ %08x\n", info->si_code, info->si_addr, regs[15]);
737 op_ctx = (void *)g_code_ptr;
738 op_ctx->pc = (u32)pc;
740 g_code_ptr = &op_ctx->code[0];
742 // emit jump to code ptr
743 *pc = make_jmp(pc, g_code_ptr, 0);
746 emit_op (0xe50d0000 + 0xf00 - 4 * 0); // str r0, [sp, #(-0xf00 + r0_offs)]
747 emit_op (0xe50de000 + 0xf00 - 4 * 14); // str lr, [sp, #(-0xf00 + lr_offs)]
748 emit_op (0xe24f0000 + (g_code_ptr - (u32 *)op_ctx + 2) * 4); // sub r0, pc, #op_ctx
749 emit_op (0xe1a0e00f); // mov lr, pc
750 emit_op_io(0xe51ff000, (u32 *)&g_linkpage->handler); // ldr pc, =handle_op
751 emit_op (0xe51de000 + 0xf00 - 4 * 14); // ldr lr, [sp, #(-0xf00 + lr_offs)]
752 emit_op (make_jmp(g_code_ptr, pc + 1, 0)); // jmp <back>
755 sys_cacheflush(pc, pc + 1);
756 sys_cacheflush(g_linkpage, g_code_ptr);
758 lp_size = (char *)g_code_ptr - (char *)g_linkpage;
759 segvlog("code #%d %d/%d\n", g_linkpage_count, lp_size, LINKPAGE_SIZE);
761 if (lp_size + 13*4 > LINKPAGE_SIZE) {
763 if (g_linkpage_count >= LINKPAGE_COUNT) {
764 err("too many linkpages needed\n");
767 g_linkpage = (void *)((char *)g_linkpage + LINKPAGE_SIZE);
770 //handle_op(regs[15], op, regs, (u32)info->si_addr);
774 void emu_init(void *map_bottom)
776 sigaction_t segv_action = {
777 .sa_sigaction = segv_sigaction,
778 .sa_flags = SA_SIGINFO,
784 g_linkpage = (void *)(((u32)map_bottom - LINKPAGE_ALLOC) & ~0xfff);
785 pret = mmap(g_linkpage, LINKPAGE_ALLOC, PROT_READ|PROT_WRITE,
786 MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
787 if (pret != g_linkpage) {
788 perror(PFX "mmap linkpage");
791 log("linkpages @ %p\n", g_linkpage);
797 err("can't init host\n");
801 ret = host_video_init(NULL, 0);
803 err("can't init host video\n");
808 // we are short on memmory on Wiz, need special handling
809 extern void *host_mmap_upper(void);
810 mmsp2.umem = host_mmap_upper();
812 mmsp2.umem = mmap(NULL, 0x2000000, PROT_READ|PROT_WRITE|PROT_EXEC,
813 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
815 if (mmsp2.umem == MAP_FAILED) {
816 perror(PFX "mmap upper mem");
820 ret = pthread_create(&tid, NULL, fb_sync_thread, NULL);
822 err("failed to create fb_sync_thread: %d\n", ret);
828 mmsp2.mlc_stl_adr = 0x03101000; // fb2 is at 0x03381000
829 mmsp2.mlc_stl_cntl = 0x4ab; // 16bpp, region 1 active
831 sigemptyset(&segv_action.sa_mask);
832 sigaction(SIGSEGV, &segv_action, NULL);
835 int emu_read_gpiodev(void *buf, int count)
838 err("gpiodev read %d?\n", count);
844 mmsp2.btn_state = host_read_btns();
845 memcpy(buf, &mmsp2.btn_state, count);
849 struct dev_fd_t emu_interesting_fds[] = {
850 [IFD_SOUND] = { "/dev/dsp", -1 },
854 static void *emu_mmap_dev(unsigned int length, int prot, int flags, unsigned int offset)
859 if ((offset & ~0xffff) == 0xc0000000) {
860 return mmap((void *)0x7f000000, length, PROT_NONE,
861 MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED|MAP_NORESERVE, -1, 0);
864 if ((offset & ~0xffff) == 0xe0020000) {
865 return mmap((void *)0x7f100000, length, PROT_NONE,
866 MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED|MAP_NORESERVE, -1, 0);
869 if ((offset & 0xfe000000) != 0x02000000) {
870 err("unexpected devmem mmap @ %08x\n", offset);
875 umem = uppermem_lookup(offset, &umem_end);
876 if (umem + length > umem_end)
877 err("warning: uppermem @ %08x overflows by %d bytes\n",
878 offset, umem + length - umem_end);
880 dbg("upper mem @ %08x %d\n", offset, length);
884 void *emu_do_mmap(unsigned int length, int prot, int flags, int fd, unsigned int offset)
886 if (fd == FAKEDEV_MEM)
887 return emu_mmap_dev(length, prot, flags, offset);
889 if (fd == FAKEDEV_FB0)
890 return emu_mmap_dev(length, prot, flags, offset + 0x03101000);
892 if (fd == FAKEDEV_FB1)
893 return emu_mmap_dev(length, prot, flags, offset + 0x03381000);
895 err("bad/ni mmap(?, %d, %x, %x, %d, %08x)\n", length, prot, flags, fd, offset);
900 static int emu_sound_ioctl(int fd, int request, void *argp)
905 dbg("snd ioctl(%d, %08x, %p)", fd, request, argp);
907 dbg_c(" [%d]", *arg);
911 /* People set strange frag settings on GP2X, which even manage
912 * to break audio on pandora (causes writes to fail).
913 * Catch this and set to something that works. */
914 if (request == SNDCTL_DSP_SPEED) {
915 int ret, bsize, frag;
917 // ~4ms. gpSP wants small buffers or else it stutters
918 // because of it's audio thread sync stuff
919 bsize = *arg / 250 * 4;
920 for (frag = 0; bsize; bsize >>= 1, frag++)
923 frag |= 16 << 16; // fragment count
924 ret = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &frag);
926 err("snd ioctl SETFRAGMENT %08x: ", frag);
930 else if (request == SNDCTL_DSP_SETFRAGMENT)
933 return ioctl(fd, request, argp);
936 int emu_do_ioctl(int fd, int request, void *argp)
938 if (fd == emu_interesting_fds[IFD_SOUND].fd)
939 return emu_sound_ioctl(fd, request, argp);
942 /* *********************** */
949 case FBIOGET_FSCREENINFO: {
950 struct fb_fix_screeninfo *fix = argp;
952 memset(fix, 0, sizeof(*fix));
953 strcpy(fix->id, "mmsp2_RGB0");
954 fix->type = FB_TYPE_PACKED_PIXELS;
955 fix->accel = FB_ACCEL_NONE;
956 fix->visual = FB_VISUAL_TRUECOLOR;
957 fix->line_length = 320*2;
958 fix->smem_start = (fd == FAKEDEV_FB0) ? 0x03101000 : 0x03381000;
959 fix->smem_len = 320*240*2;
962 case FBIOGET_VSCREENINFO: {
963 struct fb_var_screeninfo *var = argp;
964 static const struct fb_bitfield fbb_red = { offset: 11, length: 5, };
965 static const struct fb_bitfield fbb_green = { offset: 5, length: 6, };
966 static const struct fb_bitfield fbb_blue = { offset: 0, length: 5, };
968 memset(var, 0, sizeof(*var));
969 var->activate = FB_ACTIVATE_NOW;
971 var->xres_virtual = 320;
973 var->yres_virtual = 240;
976 var->vmode = FB_VMODE_NONINTERLACED;
977 var->bits_per_pixel = 16;
979 var->green = fbb_green;
980 var->blue = fbb_blue;
983 case FBIOPUT_VSCREENINFO: {
984 struct fb_var_screeninfo *var = argp;
985 dbg(" put vscreen: %dx%d@%d\n", var->xres, var->yres, var->bits_per_pixel);
986 if (var->xres != 320 || var->yres != 240 || var->bits_per_pixel != 16)
992 /* *********************** */
994 // fake tty0 to make GPH SDL happy
995 if (request == 0x4b46) // KDGKBENT
1001 err("bad/ni ioctl(%d, %08x, %p)\n", fd, request, argp);
1006 static const struct {
1010 { "/mnt/tmp/", "/tmp/" },
1013 static const char *wrap_path(const char *path)
1019 // do only path mapping for now
1020 for (i = 0; i < ARRAY_SIZE(path_map); i++) {
1021 len = strlen(path_map[i].from);
1022 if (strncmp(path, path_map[i].from, len) == 0) {
1023 size = strlen(path) + strlen(path_map[i].to) + 1;
1024 buff = malloc(size);
1027 snprintf(buff, size, "%s%s", path_map[i].to, path + len);
1028 dbg("mapped path \"%s\" -> \"%s\"\n", path, buff);
1036 void *emu_do_fopen(const char *path, const char *mode)
1038 const char *w_path = wrap_path(path);
1040 ret = fopen(w_path, mode);
1042 free((void *)w_path);
1047 int emu_do_system(const char *command)
1049 static char tmp_path[512];
1053 if (command == NULL)
1056 // pass through stuff in PATH
1057 p = strchr(command, ' ');
1058 p2 = strchr(command, '/');
1059 if (p2 == NULL || (p != NULL && p2 > p))
1060 return system(command);
1062 make_local_path(tmp_path, sizeof(tmp_path), "ginge_prep");
1063 p = tmp_path + strlen(tmp_path);
1065 p2 = wrap_path(command);
1066 snprintf(p, sizeof(tmp_path) - (p - tmp_path), " %s", p2);
1070 dbg("system: \"%s\"\n", tmp_path);
1071 return system(tmp_path);