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
|
|
|
|
2022-03-24 13:41:22 +01:00
|
|
|
#include "hp48.h"
|
2023-05-04 15:53:39 +02:00
|
|
|
#include "x48.h"
|
2023-05-10 15:32:22 +02:00
|
|
|
#include "x48_resources.h"
|
2015-07-26 11:16:05 +02:00
|
|
|
|
2023-05-09 14:41:17 +02:00
|
|
|
#if defined( GUI_IS_X11 )
|
2023-04-27 12:15:59 +02:00
|
|
|
char* progname;
|
2023-05-09 14:41:17 +02:00
|
|
|
#endif
|
2015-07-26 11:16:05 +02:00
|
|
|
|
2022-03-24 13:41:22 +01:00
|
|
|
int saved_argc;
|
2023-04-27 12:15:59 +02:00
|
|
|
char** saved_argv;
|
2015-07-26 11:16:05 +02:00
|
|
|
|
2023-04-27 12:15:59 +02:00
|
|
|
void signal_handler( int sig ) {
|
|
|
|
switch ( sig ) {
|
|
|
|
case SIGALRM:
|
|
|
|
got_alarm = 1;
|
|
|
|
break;
|
|
|
|
case SIGPIPE:
|
|
|
|
exit_x48( 0 );
|
|
|
|
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-05-09 14:41:17 +02:00
|
|
|
#if defined( GUI_IS_X11 )
|
2023-04-27 12:15:59 +02:00
|
|
|
/*
|
|
|
|
* Get the name we are called.
|
|
|
|
*/
|
|
|
|
progname = strrchr( argv[ 0 ], '/' );
|
|
|
|
if ( progname == NULL )
|
|
|
|
progname = argv[ 0 ];
|
|
|
|
else
|
|
|
|
progname++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* save command line options
|
|
|
|
*/
|
|
|
|
save_options( argc, argv );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open up the display
|
|
|
|
*/
|
2023-05-10 14:06:07 +02:00
|
|
|
if ( InitDisplay( argc, argv ) < 0 )
|
2023-04-27 12:15:59 +02:00
|
|
|
exit( 1 );
|
2023-05-10 14:06:07 +02:00
|
|
|
|
2023-05-09 14:48:24 +02:00
|
|
|
#elif defined( GUI_IS_SDL1 )
|
|
|
|
// SDL Initialization
|
|
|
|
SDLInit();
|
|
|
|
|
|
|
|
// Global parameter initialization
|
|
|
|
get_resources();
|
|
|
|
#endif
|
2023-04-27 12:15:59 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize emulator stuff
|
|
|
|
*/
|
2023-05-16 16:48:55 +02:00
|
|
|
init_emulator();
|
2023-05-09 14:48:24 +02:00
|
|
|
|
|
|
|
#if defined( GUI_IS_X11 )
|
2023-04-27 12:15:59 +02:00
|
|
|
/*
|
|
|
|
* Create the HP-48 window
|
|
|
|
*/
|
|
|
|
if ( CreateWindows( saved_argc, saved_argv ) < 0 ) {
|
2023-05-09 14:37:54 +02:00
|
|
|
fprintf( stderr, "can\'t create window\n" );
|
2023-04-27 12:15:59 +02:00
|
|
|
exit( 1 );
|
|
|
|
}
|
2023-05-05 08:59:14 +02:00
|
|
|
|
|
|
|
init_annunc();
|
2023-05-03 10:35:15 +02:00
|
|
|
#elif defined( GUI_IS_SDL1 )
|
2023-04-30 15:14:17 +02:00
|
|
|
// Create the HP-48 window
|
|
|
|
SDLCreateHP();
|
|
|
|
#endif
|
2023-04-27 12:15:59 +02:00
|
|
|
|
2023-05-05 08:59:14 +02:00
|
|
|
serial_init();
|
2023-04-27 12:15:59 +02:00
|
|
|
|
2023-05-05 08:59:14 +02:00
|
|
|
init_display();
|
2023-05-04 16:06:57 +02:00
|
|
|
|
2023-05-16 16:48:55 +02:00
|
|
|
/*****************************************/
|
|
|
|
/* handlers for SIGALRM, SIGINT, 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;
|
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 );
|
|
|
|
|
|
|
|
sigemptyset( &set );
|
|
|
|
sigaddset( &set, SIGINT );
|
|
|
|
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( SIGINT, &sa, ( struct sigaction* )0 );
|
|
|
|
|
|
|
|
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-05-02 13:42:58 +02:00
|
|
|
/************************/
|
|
|
|
/* Start emulation loop */
|
|
|
|
/************************/
|
2023-04-27 12:15:59 +02:00
|
|
|
do {
|
2023-09-07 12:39:01 +02:00
|
|
|
emulate();
|
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
|
|
|
}
|