2022-03-24 13:41:22 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
2015-07-26 11:16:05 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/time.h>
|
2022-03-24 13:41:22 +01:00
|
|
|
#include <unistd.h>
|
2023-05-04 15:53:39 +02:00
|
|
|
#include <langinfo.h>
|
|
|
|
#include <locale.h>
|
2015-07-26 11:16:05 +02:00
|
|
|
|
2023-09-16 09:18:51 +02:00
|
|
|
#include "runtime_options.h"
|
2023-09-15 17:42:29 +02:00
|
|
|
#include "emulator.h"
|
2023-09-15 09:53:03 +02:00
|
|
|
#include "debugger.h"
|
2023-09-16 15:40:24 +02:00
|
|
|
#include "ui.h" /* init_ui(); */
|
2015-07-26 11:16:05 +02:00
|
|
|
|
2023-04-27 12:15:59 +02:00
|
|
|
void signal_handler( int sig ) {
|
|
|
|
switch ( sig ) {
|
2023-09-15 09:53:03 +02:00
|
|
|
case SIGINT: /* Ctrl-C */
|
|
|
|
enter_debugger |= USER_INTERRUPT;
|
|
|
|
break;
|
2023-04-27 12:15:59 +02:00
|
|
|
case SIGALRM:
|
|
|
|
got_alarm = 1;
|
|
|
|
break;
|
|
|
|
case SIGPIPE:
|
2023-09-13 15:07:31 +02:00
|
|
|
exit_emulator();
|
2023-04-27 12:15:59 +02:00
|
|
|
exit( 0 );
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-07-26 11:16:05 +02:00
|
|
|
}
|
|
|
|
|
2023-04-27 12:15:59 +02:00
|
|
|
int main( int argc, char** argv ) {
|
|
|
|
setlocale( LC_ALL, "C" );
|
|
|
|
|
2023-09-13 12:21:08 +02:00
|
|
|
/**********/
|
|
|
|
/* getopt */
|
|
|
|
/**********/
|
|
|
|
parse_args( argc, argv );
|
|
|
|
|
2023-05-16 16:48:55 +02:00
|
|
|
/*****************************************/
|
2023-09-13 16:49:00 +02:00
|
|
|
/* handlers for SIGALRM, SIGPIPE */
|
2023-05-16 16:48:55 +02:00
|
|
|
/*****************************************/
|
|
|
|
sigset_t set;
|
|
|
|
struct sigaction sa;
|
2023-04-27 12:15:59 +02:00
|
|
|
sigemptyset( &set );
|
|
|
|
sigaddset( &set, SIGALRM );
|
|
|
|
sa.sa_handler = signal_handler;
|
|
|
|
sa.sa_mask = set;
|
2015-07-26 11:16:05 +02:00
|
|
|
#ifdef SA_RESTART
|
2023-04-27 12:15:59 +02:00
|
|
|
sa.sa_flags = SA_RESTART;
|
2015-07-26 11:16:05 +02:00
|
|
|
#endif
|
2023-04-27 12:15:59 +02:00
|
|
|
sigaction( SIGALRM, &sa, ( struct sigaction* )0 );
|
|
|
|
|
2023-09-15 09:24:23 +02:00
|
|
|
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 );
|
|
|
|
|
2023-04-27 12:15:59 +02:00
|
|
|
sigemptyset( &set );
|
|
|
|
sigaddset( &set, SIGPIPE );
|
|
|
|
sa.sa_handler = signal_handler;
|
|
|
|
sa.sa_mask = set;
|
2015-07-26 11:16:05 +02:00
|
|
|
#ifdef SA_RESTART
|
2023-04-27 12:15:59 +02:00
|
|
|
sa.sa_flags = SA_RESTART;
|
2015-07-26 11:16:05 +02:00
|
|
|
#endif
|
2023-04-27 12:15:59 +02:00
|
|
|
sigaction( SIGPIPE, &sa, ( struct sigaction* )0 );
|
|
|
|
|
2023-05-16 16:48:55 +02:00
|
|
|
/************************************/
|
|
|
|
/* set the real time interval timer */
|
|
|
|
/************************************/
|
|
|
|
struct itimerval it;
|
2023-04-30 15:14:17 +02:00
|
|
|
int interval = 20000;
|
2023-04-27 12:15:59 +02:00
|
|
|
it.it_interval.tv_sec = 0;
|
2023-04-30 15:14:17 +02:00
|
|
|
it.it_interval.tv_usec = interval;
|
2023-04-27 12:15:59 +02:00
|
|
|
it.it_value.tv_sec = 0;
|
2023-04-30 15:14:17 +02:00
|
|
|
it.it_value.tv_usec = interval;
|
2023-04-27 12:15:59 +02:00
|
|
|
setitimer( ITIMER_REAL, &it, ( struct itimerval* )0 );
|
|
|
|
|
2023-05-16 16:48:55 +02:00
|
|
|
/**********************************************************/
|
|
|
|
/* Set stdin flags to not include O_NDELAY and O_NONBLOCK */
|
|
|
|
/**********************************************************/
|
|
|
|
long flags;
|
2023-04-27 12:15:59 +02:00
|
|
|
flags = fcntl( STDIN_FILENO, F_GETFL, 0 );
|
|
|
|
flags &= ~O_NDELAY;
|
|
|
|
flags &= ~O_NONBLOCK;
|
|
|
|
fcntl( STDIN_FILENO, F_SETFL, flags );
|
|
|
|
|
2023-09-15 17:42:29 +02:00
|
|
|
/*****************************/
|
|
|
|
/* initialize emulator stuff */
|
|
|
|
/*****************************/
|
2023-09-16 15:40:24 +02:00
|
|
|
init_emulator();
|
|
|
|
init_serial();
|
|
|
|
init_ui();
|
2023-09-13 16:49:00 +02:00
|
|
|
|
2023-05-02 13:42:58 +02:00
|
|
|
/************************/
|
|
|
|
/* Start emulation loop */
|
|
|
|
/************************/
|
2023-04-27 12:15:59 +02:00
|
|
|
do {
|
2023-09-15 09:53:03 +02:00
|
|
|
if ( !exec_flags )
|
|
|
|
emulate();
|
|
|
|
else
|
|
|
|
emulate_debug();
|
|
|
|
|
|
|
|
debug();
|
2023-04-27 12:15:59 +02:00
|
|
|
} while ( 1 );
|
2015-07-26 11:16:05 +02:00
|
|
|
|
2023-04-27 12:15:59 +02:00
|
|
|
return 0;
|
2015-07-26 11:16:05 +02:00
|
|
|
}
|