override self/exe
[ginge.git] / loader / host_wiz.c
CommitLineData
499bf01c 1/*
2 * GINGE - GINGE Is Not Gp2x Emulator
3 * (C) notaz, 2010-2011
4 *
5 * This work is licensed under the MAME license, see COPYING file for details.
6 */
4d045184 7#include <sys/types.h>
8#include <sys/stat.h>
9#include <fcntl.h>
10#include <unistd.h>
11#include <sys/mman.h>
ad439e71 12#include <linux/input.h>
13
14#include "../common/warm/warm.h"
15
16extern int memdev, probably_caanoo; // leasing from wiz_video
17
18#define BTN_JOY BTN_JOYSTICK
19
8424752c 20static struct in_default_bind wiz_evdev_defbinds[] = {
ad439e71 21 { KEY_UP, IN_BINDTYPE_PLAYER12, GP2X_UP },
22 { KEY_DOWN, IN_BINDTYPE_PLAYER12, GP2X_DOWN },
23 { KEY_LEFT, IN_BINDTYPE_PLAYER12, GP2X_LEFT },
24 { KEY_RIGHT, IN_BINDTYPE_PLAYER12, GP2X_RIGHT },
25 { BTN_JOY + 0, IN_BINDTYPE_PLAYER12, GP2X_A },
26 { BTN_JOY + 1, IN_BINDTYPE_PLAYER12, GP2X_X },
27 { BTN_JOY + 2, IN_BINDTYPE_PLAYER12, GP2X_B },
28 { BTN_JOY + 3, IN_BINDTYPE_PLAYER12, GP2X_Y },
29 { BTN_JOY + 4, IN_BINDTYPE_PLAYER12, GP2X_L },
30 { BTN_JOY + 5, IN_BINDTYPE_PLAYER12, GP2X_R },
31 { BTN_JOY + 8, IN_BINDTYPE_PLAYER12, GP2X_START },
32 { BTN_JOY + 9, IN_BINDTYPE_PLAYER12, GP2X_SELECT },
33 { BTN_JOY + 10, IN_BINDTYPE_PLAYER12, GP2X_PUSH },
34 { BTN_JOY + 6, IN_BINDTYPE_EMU, 0 },
35 { 0, 0, 0 }
36};
37
8424752c 38static const struct in_pdata wiz_evdev_pdata = {
39 .defbinds = wiz_evdev_defbinds,
40};
41
ad439e71 42// todo: rm when generic code works on Wiz
43#if 0
4d045184 44static int gpiodev = -1;
4d045184 45
46int host_init(void)
47{
48 gpiodev = open("/dev/GPIO", O_RDONLY);
49 if (gpiodev < 0)
50 perror(PFX "couldn't open /dev/GPIO");
51
52 return 0;
53}
54
55int host_read_btns(void)
56{
57 int r, value = 0;
58
59 r = read(gpiodev, &value, 4);
60 if (value & 0x02)
61 value |= 0x05;
62 if (value & 0x08)
63 value |= 0x14;
64 if (value & 0x20)
65 value |= 0x50;
66 if (value & 0x80)
67 value |= 0x41;
68
69 return value;
70}
ad439e71 71#endif
4d045184 72
73void *host_mmap_upper(void)
74{
75 void *ret;
76 int r;
77
ad439e71 78 // make sure this never happens on Caanoo
79 if (probably_caanoo) {
80 err("Wiz mmap code called on Caanoo?");
81 return MAP_FAILED;
82 }
83
4d045184 84 // Wiz GP2X
85 // <linux mem> 03460000-03ffffff 00ba0000
86 // 02aa0000-02dfffff 03100000-0345ffff 00360000
87 // <linux mem> 03000000-030fffff 00100000
88 // 03000000-03ffffff 02000000-02ffffff 01000000
89 ret = mmap((void *)0x82000000, 0x1000000, PROT_READ|PROT_WRITE|PROT_EXEC,
90 MAP_SHARED|MAP_FIXED, memdev, 0x3000000);
91 if (ret != (void *)0x82000000)
92 goto fail;
93
94 ret = mmap((void *)0x83000000, 0x100000, PROT_READ|PROT_WRITE|PROT_EXEC,
95 MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
96 if (ret != (void *)0x83000000)
97 goto fail;
98
99 ret = mmap((void *)0x83100000, 0x360000, PROT_READ|PROT_WRITE|PROT_EXEC,
100 MAP_SHARED|MAP_FIXED, memdev, 0x2aa0000);
101 if (ret != (void *)0x83100000)
102 goto fail;
103
104 ret = mmap((void *)0x83460000, 0xba0000, PROT_READ|PROT_WRITE|PROT_EXEC,
105 MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
106 if (ret != (void *)0x83460000)
107 goto fail;
108
109 r = warm_change_cb_range(WCB_B_BIT|WCB_C_BIT, 1, (void *)0x82000000, 0x1000000);
110 r |= warm_change_cb_range(WCB_B_BIT|WCB_C_BIT, 1, (void *)0x83100000, 0x360000);
111 if (r != 0)
112 err("could not make upper mem cacheable.\n");
113
114 return (void *)0x82000000;
115
116fail:
117 err("mmap %p: ", ret);
118 perror(NULL);
119 exit(1);
120}
121
ad439e71 122static void host_actions(int actions[IN_BINDTYPE_COUNT])
123{
124 if (probably_caanoo && (actions[IN_BINDTYPE_EMU] & 1)) {
125 // 'home key as Fn' handling
126 int act = actions[IN_BINDTYPE_PLAYER12];
127 if (act & (1 << GP2X_START)) {
128 act &= ~(1 << GP2X_START);
129 act |= 1 << GP2X_VOL_UP;
130 }
131 if (act & (1 << GP2X_SELECT)) {
132 act &= ~(1 << GP2X_SELECT);
133 act |= 1 << GP2X_VOL_DOWN;
134 }
135 if (act & (1 << GP2X_Y))
136 host_forced_exit();
137 actions[IN_BINDTYPE_PLAYER12] = act;
138 }
139}
499bf01c 140
8424752c 141static void host_init_input(void)
142{
143 in_evdev_init(&wiz_evdev_pdata);
144}
145
499bf01c 146// vim:shiftwidth=2:expandtab