+ invalid_fb_addr = 0;
+ mlc_flip(gp2x_fb, mmsp2.v.bpp, mmsp2.v.stride);
+
+ frame_counter++;
+ if (frame_counter & 0x0f)
+ continue;
+
+check_keys:
+ // this is to check for kill key, in case main thread hung
+ // or something else went wrong.
+ pollux.btn_state = host_read_btns();
+ }
+}
+
+static void fb_thread_pause(void)
+{
+ fb_sync_thread_paused = 1;
+ // wait until it finishes last refresh
+ // that it might be doing now
+ usleep(10000);
+}
+
+static void fb_thread_resume(void)
+{
+ fb_sync_thread_paused = 0;
+}
+
+static u32 xread32_io_cmn(u32 a, u32 *handled)
+{
+ struct timespec ts;
+ u32 d = 0;
+
+ *handled = 1;
+ switch (a) {
+ // Wiz stuff
+ case 0x1980: // TIMER3 TMRCOUNT
+ // assume the timer is set up for microsec time
+ g_clock_gettime_raw(CLOCK_REALTIME, &ts);
+ d = ts.tv_sec * 1000000 + ((u64)(u32)ts.tv_nsec * 4294968 >> 32);
+ break;
+ case 0x402c: // MLCVSTRIDE0
+ case 0x4060: // MLCVSTRIDE1
+ d = pollux.v.stride;
+ break;
+ case 0x4038: // MLCADDRESS0
+ case 0x406c: // MLCADDRESS1
+ d = pollux.mlc_stl_adr;
+ break;
+ // wiz_lib reads:
+ // ???? ???? YXBA DURiLe ???? VdVuMS LR?? ????
+ // | GPIOC[31:16] | GPIOB[31:16] |
+ case 0xa058: // GPIOBPAD
+ d = (pollux.btn_state >> 1) & 0x0100;
+ d |= (pollux.btn_state << 1) & 0x0200;
+ d |= (pollux.btn_state >> 3) & 0x0080;
+ d |= (pollux.btn_state >> 5) & 0x0040;
+ d |= (pollux.btn_state >> 6) & 0x0c00;
+ d <<= 16;
+ d = ~d;
+ break;
+ case 0xa098: // GPIOCPAD
+ pollux.btn_state = host_read_btns();
+ d = (pollux.btn_state >> 8) & 0x00f0;
+ d |= (pollux.btn_state >> 1) & 0x0008;
+ d |= (pollux.btn_state << 2) & 0x0004;
+ d |= (pollux.btn_state >> 5) & 0x0002;
+ d |= (pollux.btn_state >> 2) & 0x0001;
+ d <<= 16;
+ d = ~d;
+ break;
+ default:
+ *handled = 0;
+ break;