some code cleaning and tiny refactoring
This commit is contained in:
parent
4dc4d8f0b1
commit
560c97cfed
4 changed files with 49 additions and 60 deletions
17
Makefile
17
Makefile
|
@ -41,7 +41,22 @@ dist/dump2rom: src/tools/dump2rom.o
|
||||||
dist/checkrom: src/tools/checkrom.o src/romio.o
|
dist/checkrom: src/tools/checkrom.o src/romio.o
|
||||||
$(CC) $(CFLAGS) $(LIBS) $^ -o $@
|
$(CC) $(CFLAGS) $(LIBS) $^ -o $@
|
||||||
|
|
||||||
dist/x48ng: src/main.o src/hp48emu_actions.o src/x48_debugger.o src/hp48_device.o src/x48_debugger_disasm.o src/hp48_emulate.o src/x48_errors.o src/hp48_init.o src/hp48emu_memory.o src/hp48emu_register.o src/x48_resources.o src/romio.o src/x48_debugger_rpl.o src/hp48_serial.o src/timer.o src/x48.o
|
dist/x48ng: src/main.o \
|
||||||
|
src/hp48emu_actions.o \
|
||||||
|
src/x48_debugger.o \
|
||||||
|
src/hp48_device.o \
|
||||||
|
src/x48_debugger_disasm.o \
|
||||||
|
src/hp48_emulate.o \
|
||||||
|
src/x48_errors.o \
|
||||||
|
src/hp48_init.o \
|
||||||
|
src/hp48emu_memory.o \
|
||||||
|
src/hp48emu_register.o \
|
||||||
|
src/x48_resources.o \
|
||||||
|
src/romio.o \
|
||||||
|
src/x48_debugger_rpl.o \
|
||||||
|
src/hp48_serial.o \
|
||||||
|
src/timer.o \
|
||||||
|
src/x48.o
|
||||||
$(CC) $(CFLAGS) $(LIBS) $^ -o $@
|
$(CC) $(CFLAGS) $(LIBS) $^ -o $@
|
||||||
|
|
||||||
# Cleaning
|
# Cleaning
|
||||||
|
|
|
@ -284,23 +284,28 @@ static inline void draw_nibble( int c, int r, int val ) {
|
||||||
|
|
||||||
#if defined( GUI_IS_X11 )
|
#if defined( GUI_IS_X11 )
|
||||||
x = ( c * 8 ) + 5;
|
x = ( c * 8 ) + 5;
|
||||||
|
#elif defined( GUI_IS_SDL1 )
|
||||||
|
x = ( c * 4 ); // x: start in pixels
|
||||||
|
#endif
|
||||||
if ( r <= display.lines )
|
if ( r <= display.lines )
|
||||||
x -= disp.offset;
|
x -= disp.offset;
|
||||||
|
#if defined( GUI_IS_X11 )
|
||||||
y = ( r * 2 ) + 20;
|
y = ( r * 2 ) + 20;
|
||||||
|
#elif defined( GUI_IS_SDL1 )
|
||||||
|
y = r; // y: start in pixels
|
||||||
|
#endif
|
||||||
val &= 0x0f;
|
val &= 0x0f;
|
||||||
if ( val != lcd_buffer[ r ][ c ] ) {
|
if ( val != lcd_buffer[ r ][ c ] ) {
|
||||||
|
#if defined( GUI_IS_X11 )
|
||||||
XCopyPlane( dpy, nibble_maps[ val ], disp.win, disp.gc, 0, 0, 8, 2, x,
|
XCopyPlane( dpy, nibble_maps[ val ], disp.win, disp.gc, 0, 0, 8, 2, x,
|
||||||
y, 1 );
|
y, 1 );
|
||||||
|
#endif
|
||||||
lcd_buffer[ r ][ c ] = val;
|
lcd_buffer[ r ][ c ] = val;
|
||||||
}
|
}
|
||||||
#elif defined( GUI_IS_SDL1 )
|
|
||||||
if ( val != lcd_buffer[ r ][ c ] )
|
if ( val != lcd_buffer[ r ][ c ] )
|
||||||
lcd_buffer[ r ][ c ] = val;
|
lcd_buffer[ r ][ c ] = val;
|
||||||
|
|
||||||
x = ( c * 4 ); // x: start in pixels
|
#if defined( GUI_IS_SDL1 )
|
||||||
if ( r <= display.lines )
|
|
||||||
x -= disp.offset; // Correct the pixels with display offset
|
|
||||||
y = r; // y: start in pixels
|
|
||||||
SDLDrawNibble( x, y, val );
|
SDLDrawNibble( x, y, val );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -537,7 +542,6 @@ void menu_draw_nibble( word_20 addr, word_4 val ) {
|
||||||
|
|
||||||
void draw_annunc( void ) {
|
void draw_annunc( void ) {
|
||||||
int val;
|
int val;
|
||||||
int i;
|
|
||||||
|
|
||||||
val = display.annunc;
|
val = display.annunc;
|
||||||
|
|
||||||
|
@ -548,7 +552,7 @@ void draw_annunc( void ) {
|
||||||
#if defined( GUI_IS_SDL1 )
|
#if defined( GUI_IS_SDL1 )
|
||||||
char sdl_annuncstate[ 6 ];
|
char sdl_annuncstate[ 6 ];
|
||||||
#endif
|
#endif
|
||||||
for ( i = 0; ann_tbl[ i ].bit; i++ ) {
|
for ( int i = 0; ann_tbl[ i ].bit; i++ ) {
|
||||||
#if defined( GUI_IS_X11 )
|
#if defined( GUI_IS_X11 )
|
||||||
if ( ( ann_tbl[ i ].bit & val ) == ann_tbl[ i ].bit ) {
|
if ( ( ann_tbl[ i ].bit & val ) == ann_tbl[ i ].bit ) {
|
||||||
XCopyPlane( dpy, ann_tbl[ i ].pixmap, disp.win, disp.gc, 0, 0,
|
XCopyPlane( dpy, ann_tbl[ i ].pixmap, disp.win, disp.gc, 0, 0,
|
||||||
|
@ -574,13 +578,10 @@ void draw_annunc( void ) {
|
||||||
|
|
||||||
#if defined( GUI_IS_X11 )
|
#if defined( GUI_IS_X11 )
|
||||||
void init_annunc( void ) {
|
void init_annunc( void ) {
|
||||||
int i;
|
for ( int i = 0; ann_tbl[ i ].bit; i++ )
|
||||||
|
|
||||||
for ( i = 0; ann_tbl[ i ].bit; i++ ) {
|
|
||||||
ann_tbl[ i ].pixmap =
|
ann_tbl[ i ].pixmap =
|
||||||
XCreateBitmapFromData( dpy, disp.win, ( char* )ann_tbl[ i ].bits,
|
XCreateBitmapFromData( dpy, disp.win, ( char* )ann_tbl[ i ].bits,
|
||||||
ann_tbl[ i ].width, ann_tbl[ i ].height );
|
ann_tbl[ i ].width, ann_tbl[ i ].height );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -916,12 +916,11 @@ int write_files( void ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int init_emulator( void ) {
|
int init_emulator( void ) {
|
||||||
if ( !initialize )
|
if ( !initialize && read_files() ) {
|
||||||
if ( read_files() ) {
|
if ( resetOnStartup )
|
||||||
if ( resetOnStartup )
|
saturn.PC = 0x00000;
|
||||||
saturn.PC = 0x00000;
|
return 0;
|
||||||
return 0;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
init_saturn();
|
init_saturn();
|
||||||
|
|
||||||
|
|
56
src/main.c
56
src/main.c
|
@ -38,11 +38,6 @@ void signal_handler( int sig ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc, char** argv ) {
|
int main( int argc, char** argv ) {
|
||||||
sigset_t set;
|
|
||||||
struct sigaction sa;
|
|
||||||
long flags;
|
|
||||||
struct itimerval it;
|
|
||||||
|
|
||||||
setlocale( LC_ALL, "C" );
|
setlocale( LC_ALL, "C" );
|
||||||
|
|
||||||
#if defined( GUI_IS_X11 )
|
#if defined( GUI_IS_X11 )
|
||||||
|
@ -77,27 +72,7 @@ int main( int argc, char** argv ) {
|
||||||
/*
|
/*
|
||||||
* initialize emulator stuff
|
* initialize emulator stuff
|
||||||
*/
|
*/
|
||||||
if ( init_emulator() != 0 ) {
|
init_emulator();
|
||||||
// Some error or information messages
|
|
||||||
const char* errinit_title = "Emulator initialization failed";
|
|
||||||
const char* errinit_text[] = { "",
|
|
||||||
"In order to work the emulator needs",
|
|
||||||
"the following files:",
|
|
||||||
" rom: an HP48 rom dump",
|
|
||||||
" ram: ram file",
|
|
||||||
" hp48: HP state file",
|
|
||||||
"",
|
|
||||||
"These files must be in ~/.x48ng",
|
|
||||||
"",
|
|
||||||
"Install these files and try again.",
|
|
||||||
0 };
|
|
||||||
|
|
||||||
printf( "%s\n", errinit_title );
|
|
||||||
for ( int i = 0; errinit_text[ i ]; i++ )
|
|
||||||
printf( "%s\n", errinit_text[ i ] );
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined( GUI_IS_X11 )
|
#if defined( GUI_IS_X11 )
|
||||||
/*
|
/*
|
||||||
|
@ -118,9 +93,12 @@ int main( int argc, char** argv ) {
|
||||||
|
|
||||||
init_display();
|
init_display();
|
||||||
|
|
||||||
/*
|
|
||||||
* install a handler for SIGALRM
|
/*****************************************/
|
||||||
*/
|
/* handlers for SIGALRM, SIGINT, SIGPIPE */
|
||||||
|
/*****************************************/
|
||||||
|
sigset_t set;
|
||||||
|
struct sigaction sa;
|
||||||
sigemptyset( &set );
|
sigemptyset( &set );
|
||||||
sigaddset( &set, SIGALRM );
|
sigaddset( &set, SIGALRM );
|
||||||
sa.sa_handler = signal_handler;
|
sa.sa_handler = signal_handler;
|
||||||
|
@ -130,9 +108,6 @@ int main( int argc, char** argv ) {
|
||||||
#endif
|
#endif
|
||||||
sigaction( SIGALRM, &sa, ( struct sigaction* )0 );
|
sigaction( SIGALRM, &sa, ( struct sigaction* )0 );
|
||||||
|
|
||||||
/*
|
|
||||||
* install a handler for SIGINT
|
|
||||||
*/
|
|
||||||
sigemptyset( &set );
|
sigemptyset( &set );
|
||||||
sigaddset( &set, SIGINT );
|
sigaddset( &set, SIGINT );
|
||||||
sa.sa_handler = signal_handler;
|
sa.sa_handler = signal_handler;
|
||||||
|
@ -142,9 +117,6 @@ int main( int argc, char** argv ) {
|
||||||
#endif
|
#endif
|
||||||
sigaction( SIGINT, &sa, ( struct sigaction* )0 );
|
sigaction( SIGINT, &sa, ( struct sigaction* )0 );
|
||||||
|
|
||||||
/*
|
|
||||||
* install a handler for SIGPIPE
|
|
||||||
*/
|
|
||||||
sigemptyset( &set );
|
sigemptyset( &set );
|
||||||
sigaddset( &set, SIGPIPE );
|
sigaddset( &set, SIGPIPE );
|
||||||
sa.sa_handler = signal_handler;
|
sa.sa_handler = signal_handler;
|
||||||
|
@ -154,9 +126,10 @@ int main( int argc, char** argv ) {
|
||||||
#endif
|
#endif
|
||||||
sigaction( SIGPIPE, &sa, ( struct sigaction* )0 );
|
sigaction( SIGPIPE, &sa, ( struct sigaction* )0 );
|
||||||
|
|
||||||
/*
|
/************************************/
|
||||||
* set the real time interval timer
|
/* set the real time interval timer */
|
||||||
*/
|
/************************************/
|
||||||
|
struct itimerval it;
|
||||||
int interval = 20000;
|
int interval = 20000;
|
||||||
it.it_interval.tv_sec = 0;
|
it.it_interval.tv_sec = 0;
|
||||||
it.it_interval.tv_usec = interval;
|
it.it_interval.tv_usec = interval;
|
||||||
|
@ -164,9 +137,10 @@ int main( int argc, char** argv ) {
|
||||||
it.it_value.tv_usec = interval;
|
it.it_value.tv_usec = interval;
|
||||||
setitimer( ITIMER_REAL, &it, ( struct itimerval* )0 );
|
setitimer( ITIMER_REAL, &it, ( struct itimerval* )0 );
|
||||||
|
|
||||||
/*
|
/**********************************************************/
|
||||||
* Set stdin flags to not include O_NDELAY and O_NONBLOCK
|
/* Set stdin flags to not include O_NDELAY and O_NONBLOCK */
|
||||||
*/
|
/**********************************************************/
|
||||||
|
long flags;
|
||||||
flags = fcntl( STDIN_FILENO, F_GETFL, 0 );
|
flags = fcntl( STDIN_FILENO, F_GETFL, 0 );
|
||||||
flags &= ~O_NDELAY;
|
flags &= ~O_NDELAY;
|
||||||
flags &= ~O_NONBLOCK;
|
flags &= ~O_NONBLOCK;
|
||||||
|
|
Loading…
Reference in a new issue