3a3947cd |
1 | \r |
2 | #include <stdio.h>\r |
3 | #include <stdlib.h>\r |
4 | #include <stdarg.h>\r |
5 | #include <string.h>\r |
6 | #include <unistd.h>\r |
7 | #include <sys/mman.h>\r |
8 | #include <sys/types.h>\r |
9 | #include <sys/stat.h>\r |
e163b67f |
10 | #include <linux/fb.h>\r |
3a3947cd |
11 | #include <fcntl.h>\r |
12 | #include <errno.h>\r |
13 | \r |
14 | #include "../gp2x/gp2x.h"\r |
e5ab6faf |
15 | #include "../linux/sndout_oss.h"\r |
16b0afd0 |
16 | #include "../common/arm_linux.h"\r |
3a3947cd |
17 | \r |
e163b67f |
18 | static volatile unsigned int *memregs = MAP_FAILED;\r |
3a3947cd |
19 | //static\r |
20 | int memdev = 0;\r |
e5ab6faf |
21 | static int fbdev = -1;\r |
3a3947cd |
22 | \r |
3bb7bd19 |
23 | #define SCREEN_MAP_SIZE (800*480*2)\r |
e163b67f |
24 | static void *screen = MAP_FAILED;\r |
3a3947cd |
25 | void *gp2x_screen;\r |
26 | \r |
3a3947cd |
27 | \r |
28 | /* video stuff */\r |
29 | void gp2x_video_flip(void)\r |
30 | {\r |
3a3947cd |
31 | }\r |
32 | \r |
33 | /* doulblebuffered flip */\r |
34 | void gp2x_video_flip2(void)\r |
35 | {\r |
3a3947cd |
36 | }\r |
37 | \r |
38 | \r |
39 | void gp2x_video_changemode2(int bpp)\r |
40 | {\r |
3a3947cd |
41 | }\r |
42 | \r |
43 | \r |
44 | void gp2x_video_changemode(int bpp)\r |
45 | {\r |
3a3947cd |
46 | }\r |
47 | \r |
48 | \r |
49 | void gp2x_video_setpalette(int *pal, int len)\r |
50 | {\r |
3a3947cd |
51 | }\r |
52 | \r |
53 | \r |
3a3947cd |
54 | void gp2x_video_RGB_setscaling(int ln_offs, int W, int H)\r |
55 | {\r |
3a3947cd |
56 | }\r |
57 | \r |
58 | \r |
59 | void gp2x_video_wait_vsync(void)\r |
60 | {\r |
3a3947cd |
61 | }\r |
62 | \r |
3a3947cd |
63 | void gp2x_video_flush_cache(void)\r |
64 | {\r |
16b0afd0 |
65 | // cache_flush_d_inval_i(gp2x_screen, (char *)gp2x_screen + 320*240*2, 0);\r |
3a3947cd |
66 | }\r |
67 | \r |
3a3947cd |
68 | void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len)\r |
69 | {\r |
3a3947cd |
70 | }\r |
71 | \r |
72 | \r |
73 | void gp2x_memcpy_all_buffers(void *data, int offset, int len)\r |
74 | {\r |
3a3947cd |
75 | }\r |
76 | \r |
77 | \r |
78 | void gp2x_memset_all_buffers(int offset, int byte, int len)\r |
79 | {\r |
e55f0cbb |
80 | memset((char *)gp2x_screen + offset, byte, len);\r |
3a3947cd |
81 | }\r |
82 | \r |
83 | \r |
84 | void gp2x_pd_clone_buffer2(void)\r |
85 | {\r |
16b0afd0 |
86 | memset(gp2x_screen, 0, 800*480*2);\r |
3a3947cd |
87 | }\r |
88 | \r |
e5ab6faf |
89 | // FIXME\r |
90 | #if 0\r |
91 | static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 };\r |
92 | \r |
3a3947cd |
93 | typedef struct ucb1x00_ts_event\r |
94 | {\r |
95 | unsigned short pressure;\r |
96 | unsigned short x;\r |
97 | unsigned short y;\r |
98 | unsigned short pad;\r |
99 | struct timeval stamp;\r |
100 | } UCB1X00_TS_EVENT;\r |
101 | \r |
102 | int gp2x_touchpad_read(int *x, int *y)\r |
103 | {\r |
104 | UCB1X00_TS_EVENT event;\r |
105 | static int zero_seen = 0;\r |
106 | int retval;\r |
107 | \r |
108 | if (touchdev < 0) return -1;\r |
109 | \r |
110 | retval = read(touchdev, &event, sizeof(event));\r |
111 | if (retval <= 0) {\r |
112 | printf("touch read failed %i %i\n", retval, errno);\r |
113 | return -1;\r |
114 | }\r |
115 | // this is to ignore the messed-up 4.1.x driver\r |
116 | if (event.pressure == 0) zero_seen = 1;\r |
117 | \r |
118 | if (x) *x = (event.x * touchcal[0] + touchcal[2]) >> 16;\r |
119 | if (y) *y = (event.y * touchcal[4] + touchcal[5]) >> 16;\r |
120 | // printf("read %i %i %i\n", event.pressure, *x, *y);\r |
121 | \r |
122 | return zero_seen ? event.pressure : 0;\r |
123 | }\r |
e5ab6faf |
124 | #else\r |
125 | int gp2x_touchpad_read(int *x, int *y) { return -1; }\r |
e55f0cbb |
126 | #endif\r |
3a3947cd |
127 | \r |
128 | /* common */\r |
129 | void gp2x_init(void)\r |
130 | {\r |
131 | printf("entering init()\n"); fflush(stdout);\r |
132 | \r |
133 | memdev = open("/dev/mem", O_RDWR);\r |
134 | if (memdev == -1)\r |
135 | {\r |
e5ab6faf |
136 | perror("open(\"/dev/mem\")");\r |
3a3947cd |
137 | exit(1);\r |
138 | }\r |
e163b67f |
139 | /*\r |
e55f0cbb |
140 | memregs = mmap(0, 0x01000000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0x48000000);\r |
141 | if (memregs == MAP_FAILED)\r |
3a3947cd |
142 | {\r |
143 | printf("mmap(memregs) failed with %i\n", errno);\r |
144 | exit(1);\r |
145 | }\r |
e163b67f |
146 | */\r |
a7efb231 |
147 | fbdev = open("/dev/fb0", O_RDWR);\r |
148 | if (fbdev == -1)\r |
149 | {\r |
e5ab6faf |
150 | perror("open(\"/dev/fb0\")");\r |
e163b67f |
151 | exit(1);\r |
152 | }\r |
153 | \r |
e55f0cbb |
154 | screen = mmap(0, SCREEN_MAP_SIZE, PROT_WRITE|PROT_READ, MAP_SHARED, fbdev, 0);\r |
155 | if (screen == MAP_FAILED)\r |
156 | {\r |
e5ab6faf |
157 | perror("mmap(fbptr)");\r |
e55f0cbb |
158 | exit(1);\r |
159 | }\r |
160 | printf("fbptr %p\n", screen);\r |
3bb7bd19 |
161 | gp2x_screen = screen;\r |
3a3947cd |
162 | \r |
3a3947cd |
163 | // snd\r |
e5ab6faf |
164 | sndout_oss_init();\r |
3a3947cd |
165 | \r |
3a3947cd |
166 | printf("exitting init()\n"); fflush(stdout);\r |
167 | }\r |
168 | \r |
3a3947cd |
169 | void gp2x_deinit(void)\r |
170 | {\r |
e163b67f |
171 | if (screen != MAP_FAILED)\r |
172 | munmap(screen, SCREEN_MAP_SIZE);\r |
173 | if (memregs != MAP_FAILED)\r |
174 | munmap((void *)memregs, 0x10000);\r |
3a3947cd |
175 | close(memdev);\r |
e163b67f |
176 | if (fbdev >= 0) close(fbdev);\r |
3a3947cd |
177 | \r |
e5ab6faf |
178 | sndout_oss_exit();\r |
3a3947cd |
179 | \r |
e55f0cbb |
180 | printf("all done");\r |
3a3947cd |
181 | }\r |
182 | \r |
183 | /* lprintf */\r |
184 | void lprintf(const char *fmt, ...)\r |
185 | {\r |
186 | va_list vl;\r |
187 | \r |
188 | va_start(vl, fmt);\r |
189 | vprintf(fmt, vl);\r |
190 | va_end(vl);\r |
191 | }\r |
192 | \r |
193 | \r |
194 | /* fake GP2X */\r |
195 | int crashed_940 = 0;\r |
196 | \r |
3a3947cd |
197 | void set_gamma(int g100, int A_SNs_curve) {}\r |
198 | void set_FCLK(unsigned MHZ) {}\r |
199 | void set_LCD_custom_rate(int rate) {}\r |
200 | void unset_LCD_custom_rate(void) {}\r |
e55f0cbb |
201 | void Pause940(int yes) {}\r |
202 | void Reset940(int yes, int bank) {}\r |
3a3947cd |
203 | \r |