pandora.c 4.1 KB

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