#include #include #include #include #include #include #include #include #include #include #include "options.h" #include "hp48.h" #include "ui.h" /* SDLInit(); SDLCreateHP(); init_display(); */ #include "debugger.h" void signal_handler( int sig ) { switch ( sig ) { case SIGINT: /* Ctrl-C */ enter_debugger |= USER_INTERRUPT; break; case SIGALRM: got_alarm = 1; break; case SIGPIPE: exit_emulator(); exit( 0 ); default: break; } } int main( int argc, char** argv ) { setlocale( LC_ALL, "C" ); /**********/ /* getopt */ /**********/ parse_args( argc, argv ); /*****************************************/ /* handlers for SIGALRM, SIGPIPE */ /*****************************************/ sigset_t set; struct sigaction sa; 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 ); sigemptyset( &set ); sigaddset( &set, SIGINT ); sa.sa_handler = signal_handler; sa.sa_mask = set; #ifdef SA_RESTART sa.sa_flags = SA_RESTART; #endif sigaction( SIGINT, &sa, ( struct sigaction* )0 ); sigemptyset( &set ); sigaddset( &set, SIGPIPE ); sa.sa_handler = signal_handler; sa.sa_mask = set; #ifdef SA_RESTART sa.sa_flags = SA_RESTART; #endif sigaction( SIGPIPE, &sa, ( struct sigaction* )0 ); /************************************/ /* set the real time interval timer */ /************************************/ struct itimerval it; int interval = 20000; it.it_interval.tv_sec = 0; it.it_interval.tv_usec = interval; it.it_value.tv_sec = 0; it.it_value.tv_usec = interval; setitimer( ITIMER_REAL, &it, ( struct itimerval* )0 ); /**********************************************************/ /* Set stdin flags to not include O_NDELAY and O_NONBLOCK */ /**********************************************************/ long flags; flags = fcntl( STDIN_FILENO, F_GETFL, 0 ); flags &= ~O_NDELAY; flags &= ~O_NONBLOCK; fcntl( STDIN_FILENO, F_SETFL, flags ); /* * initialize emulator stuff */ init_emulator(); serial_init(); // SDL Initialization SDLInit(); /* * Create the HP-48 window */ SDLCreateHP(); init_display(); /************************/ /* Start emulation loop */ /************************/ do { if ( !exec_flags ) emulate(); else emulate_debug(); debug(); } while ( 1 ); return 0; }