UI handling out of main loop
This commit is contained in:
parent
2e6c2b826b
commit
7c2753e49a
1 changed files with 52 additions and 5 deletions
57
src/main.c
57
src/main.c
|
@ -1,9 +1,34 @@
|
||||||
|
#include <signal.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <unistd.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include "emulator.h"
|
#include "emulator.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
|
#define SPEED_HZ_UI 64
|
||||||
|
|
||||||
|
void signal_handler( int sig )
|
||||||
|
{
|
||||||
|
switch ( sig ) {
|
||||||
|
/* case SIGINT: /\* Ctrl-C *\/ */
|
||||||
|
/* enter_debugger |= USER_INTERRUPT; */
|
||||||
|
/* break; */
|
||||||
|
case SIGALRM:
|
||||||
|
ui_get_event();
|
||||||
|
ui_update_display();
|
||||||
|
break;
|
||||||
|
case SIGPIPE:
|
||||||
|
ui_stop();
|
||||||
|
exit_emulator();
|
||||||
|
exit( 0 );
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main( int argc, char** argv )
|
int main( int argc, char** argv )
|
||||||
{
|
{
|
||||||
config_t* config = config_init( argc, argv );
|
config_t* config = config_init( argc, argv );
|
||||||
|
@ -14,11 +39,33 @@ int main( int argc, char** argv )
|
||||||
setup_ui( config );
|
setup_ui( config );
|
||||||
ui_start( config );
|
ui_start( config );
|
||||||
|
|
||||||
while ( true ) {
|
sigset_t set;
|
||||||
ui_get_event();
|
struct sigaction sa;
|
||||||
ui_update_display();
|
sigemptyset( &set );
|
||||||
|
sigaddset( &set, SIGALRM );
|
||||||
|
sa.sa_handler = signal_handler;
|
||||||
|
sa.sa_mask = set;
|
||||||
|
#ifdef SA_RESTART
|
||||||
|
sa.sa_flags = SA_RESTART;
|
||||||
|
#endif
|
||||||
|
sigaction( SIGALRM, &sa, ( struct sigaction* )0 );
|
||||||
|
|
||||||
usleep( 1000000 / 64 );
|
/************************************/
|
||||||
|
/* set the real time interval timer */
|
||||||
|
/************************************/
|
||||||
|
/*
|
||||||
|
Every <interval>µs setitimer will trigger a SIGALRM
|
||||||
|
which will getUI events and refresh UI in signal_handler
|
||||||
|
*/
|
||||||
|
struct itimerval it;
|
||||||
|
it.it_interval.tv_sec = 0;
|
||||||
|
it.it_interval.tv_usec = 1000000 / SPEED_HZ_UI;
|
||||||
|
it.it_value.tv_sec = 0;
|
||||||
|
it.it_value.tv_usec = 1000000 / SPEED_HZ_UI;
|
||||||
|
setitimer( ITIMER_REAL, &it, ( struct itimerval* )0 );
|
||||||
|
|
||||||
|
while ( true ) {
|
||||||
|
// fprintf( stderr, "." );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Never reached */
|
/* Never reached */
|
||||||
|
|
Loading…
Reference in a new issue