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