libx48ng/src/main.c

114 lines
2.7 KiB
C
Raw Normal View History

2022-03-24 13:41:22 +01:00
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
2022-03-24 13:41:22 +01:00
#include <unistd.h>
#include <langinfo.h>
#include <locale.h>
2023-09-16 09:18:51 +02:00
#include "runtime_options.h"
#include "emulator.h"
#include "debugger.h"
2023-09-16 15:40:24 +02:00
#include "ui.h" /* init_ui(); */
2023-04-27 12:15:59 +02:00
void signal_handler( int sig ) {
switch ( sig ) {
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;
}
}
2023-04-27 12:15:59 +02:00
int main( int argc, char** argv ) {
setlocale( LC_ALL, "C" );
/**********/
/* getopt */
/**********/
parse_args( argc, argv );
/*****************************************/
2023-09-13 16:49:00 +02:00
/* handlers for SIGALRM, SIGPIPE */
/*****************************************/
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;
#ifdef SA_RESTART
2023-04-27 12:15:59 +02:00
sa.sa_flags = SA_RESTART;
#endif
2023-04-27 12:15:59 +02:00
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 );
2023-04-27 12:15:59 +02:00
sigemptyset( &set );
sigaddset( &set, SIGPIPE );
sa.sa_handler = signal_handler;
sa.sa_mask = set;
#ifdef SA_RESTART
2023-04-27 12:15:59 +02:00
sa.sa_flags = SA_RESTART;
#endif
2023-04-27 12:15:59 +02:00
sigaction( SIGPIPE, &sa, ( struct sigaction* )0 );
/************************************/
/* set the real time interval timer */
/************************************/
struct itimerval it;
int interval = 20000;
2023-04-27 12:15:59 +02:00
it.it_interval.tv_sec = 0;
it.it_interval.tv_usec = interval;
2023-04-27 12:15:59 +02:00
it.it_value.tv_sec = 0;
it.it_value.tv_usec = interval;
2023-04-27 12:15:59 +02:00
setitimer( ITIMER_REAL, &it, ( struct itimerval* )0 );
/**********************************************************/
/* 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 );
/*****************************/
/* 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 {
if ( !exec_flags )
emulate();
else
emulate_debug();
debug();
2023-04-27 12:15:59 +02:00
} while ( 1 );
2023-04-27 12:15:59 +02:00
return 0;
}