void supervision_exec(unsigned short *backbuffer, unsigned char bRender) { uint32 supervision_scanline, scan1=0; int i; for (supervision_scanline = 0; supervision_scanline < 160; supervision_scanline++) { m6502_registers.ICount = 512; //Default is 512 timer_exec((m6502_registers.ICount)); #ifdef GP2X if(currentConfig.enable_sound) sound_exec(11025/160); #else sound_exec(22050/160); #endif Run6502(&m6502_registers); #ifdef NDS gpu_render_scanline(supervision_scanline, backbuffer); backbuffer += 160+96; #else gpu_render_scanline_fast(scan1, backbuffer); backbuffer += 160; scan1 += 0x30; #endif } if (Rd6502(0x2026)&0x01) Int6502(supervision_get6502regs(), INT_NMI); }
void gui_loop() { SDL_Event event; GuiWidget *root_widget = gui_root_widget(); if (root_widget == NULL) { printf("ERROR: no found root widget\n"); return; } widget_show(root_widget); root_widget = gui_main_widget(); widget_show(root_widget); while (gui->running) { timer_exec(); if (gui_update() == 0) SDL_Delay(10); if (SDL_PollEvent(&event)) { GuiWidget *cur_widget = (GuiWidget*)stack_peek(gui->win_stack); switch (event.type) { case SDL_VIDEORESIZE: break; case SDL_MOUSEBUTTONDOWN: printf("mouse (%d, %d)\n", event.button.x, event.button.y); break; case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_SPACE) { gui->running = 0; break; } if (cur_widget == NULL) continue; if (event.key.keysym.sym == SDLK_ESCAPE) widget_close(cur_widget); else { widget_process_event(cur_widget, (void *)&event); } break; case SDL_QUIT: gui->running = 0; break; } } } SDL_Quit(); }
/* Timer loop */ static void *timer_loop(timer_queue_t *queue) { struct timespec t_spc; timer_entry_t *timer; m_tmcnt_t c_time; /* Set signal properties */ m_signal_block(SIGINT); m_signal_block(SIGQUIT); m_signal_block(SIGTERM); for(;;) { /* Prevent asynchronous access problems */ TIMERQ_LOCK(queue); /* We need to check "running" flags to know if we must stop */ if (!queue->running) { TIMERQ_UNLOCK(queue); break; } /* Get first event */ timer = queue->list; /* * If we have timers in queue, we setup a timer to wait for first one. * In all cases, thread is woken up when a reschedule occurs. */ if (timer) { t_spc.tv_sec = timer->expire / 1000; t_spc.tv_nsec = (timer->expire % 1000) * 1000000; pthread_cond_timedwait(&queue->schedule,&queue->lock,&t_spc); } else { /* We just wait for reschedule since we don't have any timer */ pthread_cond_wait(&queue->schedule,&queue->lock); } /* We need to check "running" flags to know if we must stop */ if (!queue->running) { TIMERQ_UNLOCK(queue); break; } /* * Now, we need to find why we were woken up. So, we compare current * time with first timer to see if we must execute action associated * with it. */ c_time = m_gettime(); /* Get first event */ timer = queue->list; /* If there is nothing to do for now, wait again */ if ((timer == NULL) || (timer->expire > c_time)) { TIMERQ_UNLOCK(queue); continue; } /* * We have a timer to manage. Remove it from queue and mark it as * running. */ timer_remove_from_queue(queue,timer); timer->flags |= TIMER_RUNNING; /* Execute user function and reschedule timer if required */ if (timer_exec(timer)) timer_schedule_in_queue(queue,timer); TIMERQ_UNLOCK(queue); } return NULL; }