some code cleaning and tiny refactoring

This commit is contained in:
Gwenhael Le Moine 2023-05-16 16:48:55 +02:00
parent 4dc4d8f0b1
commit 560c97cfed
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
4 changed files with 49 additions and 60 deletions

View file

@ -41,7 +41,22 @@ dist/dump2rom: src/tools/dump2rom.o
dist/checkrom: src/tools/checkrom.o src/romio.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 $@
# Cleaning

View file

@ -284,23 +284,28 @@ static inline void draw_nibble( int c, int r, int val ) {
#if defined( GUI_IS_X11 )
x = ( c * 8 ) + 5;
#elif defined( GUI_IS_SDL1 )
x = ( c * 4 ); // x: start in pixels
#endif
if ( r <= display.lines )
x -= disp.offset;
#if defined( GUI_IS_X11 )
y = ( r * 2 ) + 20;
#elif defined( GUI_IS_SDL1 )
y = r; // y: start in pixels
#endif
val &= 0x0f;
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,
y, 1 );
y, 1 );
#endif
lcd_buffer[ r ][ c ] = val;
}
#elif defined( GUI_IS_SDL1 )
if ( val != lcd_buffer[ r ][ c ] )
lcd_buffer[ r ][ c ] = val;
x = ( c * 4 ); // x: start in pixels
if ( r <= display.lines )
x -= disp.offset; // Correct the pixels with display offset
y = r; // y: start in pixels
#if defined( GUI_IS_SDL1 )
SDLDrawNibble( x, y, val );
#endif
}
@ -537,7 +542,6 @@ void menu_draw_nibble( word_20 addr, word_4 val ) {
void draw_annunc( void ) {
int val;
int i;
val = display.annunc;
@ -548,7 +552,7 @@ void draw_annunc( void ) {
#if defined( GUI_IS_SDL1 )
char sdl_annuncstate[ 6 ];
#endif
for ( i = 0; ann_tbl[ i ].bit; i++ ) {
for ( int i = 0; ann_tbl[ i ].bit; i++ ) {
#if defined( GUI_IS_X11 )
if ( ( ann_tbl[ i ].bit & val ) == ann_tbl[ i ].bit ) {
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 )
void init_annunc( void ) {
int i;
for ( i = 0; ann_tbl[ i ].bit; i++ ) {
for ( int i = 0; ann_tbl[ i ].bit; i++ )
ann_tbl[ i ].pixmap =
XCreateBitmapFromData( dpy, disp.win, ( char* )ann_tbl[ i ].bits,
ann_tbl[ i ].width, ann_tbl[ i ].height );
}
}
#endif

View file

@ -916,12 +916,11 @@ int write_files( void ) {
}
int init_emulator( void ) {
if ( !initialize )
if ( read_files() ) {
if ( resetOnStartup )
saturn.PC = 0x00000;
return 0;
}
if ( !initialize && read_files() ) {
if ( resetOnStartup )
saturn.PC = 0x00000;
return 0;
}
init_saturn();

View file

@ -38,11 +38,6 @@ void signal_handler( int sig ) {
}
int main( int argc, char** argv ) {
sigset_t set;
struct sigaction sa;
long flags;
struct itimerval it;
setlocale( LC_ALL, "C" );
#if defined( GUI_IS_X11 )
@ -77,27 +72,7 @@ int main( int argc, char** argv ) {
/*
* initialize emulator stuff
*/
if ( init_emulator() != 0 ) {
// 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;
}
init_emulator();
#if defined( GUI_IS_X11 )
/*
@ -118,9 +93,12 @@ int main( int argc, char** argv ) {
init_display();
/*
* install a handler for SIGALRM
*/
/*****************************************/
/* handlers for SIGALRM, SIGINT, SIGPIPE */
/*****************************************/
sigset_t set;
struct sigaction sa;
sigemptyset( &set );
sigaddset( &set, SIGALRM );
sa.sa_handler = signal_handler;
@ -130,9 +108,6 @@ int main( int argc, char** argv ) {
#endif
sigaction( SIGALRM, &sa, ( struct sigaction* )0 );
/*
* install a handler for SIGINT
*/
sigemptyset( &set );
sigaddset( &set, SIGINT );
sa.sa_handler = signal_handler;
@ -142,9 +117,6 @@ int main( int argc, char** argv ) {
#endif
sigaction( SIGINT, &sa, ( struct sigaction* )0 );
/*
* install a handler for SIGPIPE
*/
sigemptyset( &set );
sigaddset( &set, SIGPIPE );
sa.sa_handler = signal_handler;
@ -154,9 +126,10 @@ int main( int argc, char** argv ) {
#endif
sigaction( SIGPIPE, &sa, ( struct sigaction* )0 );
/*
* set the real time interval timer
*/
/************************************/
/* set the real time interval timer */
/************************************/
struct itimerval it;
int interval = 20000;
it.it_interval.tv_sec = 0;
it.it_interval.tv_usec = interval;
@ -164,9 +137,10 @@ int main( int argc, char** argv ) {
it.it_value.tv_usec = interval;
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 &= ~O_NDELAY;
flags &= ~O_NONBLOCK;