Skip to content

Commit 56d1f70

Browse files
store config in a struct
1 parent 91f6bbe commit 56d1f70

File tree

11 files changed

+356
-349
lines changed

11 files changed

+356
-349
lines changed

src/debugger.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4076,24 +4076,24 @@ int debug( void )
40764076
/*
40774077
* do we want to debug ???
40784078
*/
4079-
if ( !useDebugger ) {
4079+
if ( !config.useDebugger ) {
40804080
if ( enter_debugger & ILLEGAL_INSTRUCTION ) {
4081-
if ( verbose )
4081+
if ( config.verbose )
40824082
fprintf( stderr, "reset (illegal instruction at 0x%.5lX)\n", saturn.PC );
40834083
saturn.PC = 0;
40844084
}
40854085
if ( enter_debugger & USER_INTERRUPT )
4086-
if ( verbose )
4086+
if ( config.verbose )
40874087
printf( "usnterrupt (SIGINT) ignored\n" );
40884088

40894089
exit_emulator();
40904090
exit( 1 );
40914091

40924092
if ( enter_debugger & BREAKPOINT_HIT )
4093-
if ( verbose )
4093+
if ( config.verbose )
40944094
printf( "breakpoint hit at 0x%.5lX ignored\n", saturn.PC );
40954095
if ( enter_debugger & TRAP_INSTRUCTION )
4096-
if ( verbose )
4096+
if ( config.verbose )
40974097
printf( "trap instruction at 0x%.5lX ignored\n", saturn.PC );
40984098

40994099
enter_debugger = 0;

src/emu_emulate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ static inline int get_identification( void )
320320

321321
static inline void do_shutdown( void )
322322
{
323-
if ( inhibit_shutdown )
323+
if ( config.inhibit_shutdown )
324324
return;
325325

326326
/***************************/
@@ -2861,7 +2861,7 @@ void emulate( void )
28612861
step_instruction();
28622862

28632863
for ( int i = 0; i < ( int )( sizeof( saturn.keybuf.rows ) / sizeof( saturn.keybuf.rows[ 0 ] ) ); i++ ) {
2864-
if ( saturn.keybuf.rows[ i ] || throttle ) {
2864+
if ( saturn.keybuf.rows[ i ] || config.throttle ) {
28652865
/* Throttling speed if needed */
28662866
gettimeofday( &tv, &tz );
28672867
gettimeofday( &tv2, &tz );

src/emu_init.c

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ int read_8( FILE* fp, word_8* var )
146146
unsigned char tmp;
147147

148148
if ( fread( &tmp, 1, 1, fp ) != 1 ) {
149-
if ( verbose )
149+
if ( config.verbose )
150150
fprintf( stderr, "can\'t read word_8\n" );
151151
return 0;
152152
}
@@ -159,7 +159,7 @@ int read_char( FILE* fp, char* var )
159159
char tmp;
160160

161161
if ( fread( &tmp, 1, 1, fp ) != 1 ) {
162-
if ( verbose )
162+
if ( config.verbose )
163163
fprintf( stderr, "can\'t read char\n" );
164164
return 0;
165165
}
@@ -172,7 +172,7 @@ int read_16( FILE* fp, word_16* var )
172172
unsigned char tmp[ 2 ];
173173

174174
if ( fread( &tmp[ 0 ], 1, 2, fp ) != 2 ) {
175-
if ( verbose )
175+
if ( config.verbose )
176176
fprintf( stderr, "can\'t read word_16\n" );
177177
return 0;
178178
}
@@ -186,7 +186,7 @@ int read_32( FILE* fp, word_32* var )
186186
unsigned char tmp[ 4 ];
187187

188188
if ( fread( &tmp[ 0 ], 1, 4, fp ) != 4 ) {
189-
if ( verbose )
189+
if ( config.verbose )
190190
fprintf( stderr, "can\'t read word_32\n" );
191191
return 0;
192192
}
@@ -202,7 +202,7 @@ int read_u_long( FILE* fp, unsigned long* var )
202202
unsigned char tmp[ 4 ];
203203

204204
if ( fread( &tmp[ 0 ], 1, 4, fp ) != 4 ) {
205-
if ( verbose )
205+
if ( config.verbose )
206206
fprintf( stderr, "can\'t read unsigned long\n" );
207207
return 0;
208208
}
@@ -388,13 +388,13 @@ int read_mem_file( char* name, word_4* mem, int size )
388388
int i, j;
389389

390390
if ( NULL == ( fp = fopen( name, "r" ) ) ) {
391-
if ( verbose )
391+
if ( config.verbose )
392392
fprintf( stderr, "ct open %s\n", name );
393393
return 0;
394394
}
395395

396396
if ( stat( name, &st ) < 0 ) {
397-
if ( verbose )
397+
if ( config.verbose )
398398
fprintf( stderr, "can\'t stat %s\n", name );
399399
return 0;
400400
}
@@ -404,7 +404,7 @@ int read_mem_file( char* name, word_4* mem, int size )
404404
* size is same as memory size, old version file
405405
*/
406406
if ( fread( mem, 1, ( size_t )size, fp ) != ( unsigned long )size ) {
407-
if ( verbose )
407+
if ( config.verbose )
408408
fprintf( stderr, "can\'t read %s\n", name );
409409
fclose( fp );
410410
return 0;
@@ -415,7 +415,7 @@ int read_mem_file( char* name, word_4* mem, int size )
415415
*/
416416

417417
if ( st.st_size != size / 2 ) {
418-
if ( verbose )
418+
if ( config.verbose )
419419
fprintf( stderr, "strange size %s, expected %d, found %ld\n", name, size / 2, st.st_size );
420420
fclose( fp );
421421
return 0;
@@ -424,7 +424,7 @@ int read_mem_file( char* name, word_4* mem, int size )
424424
if ( NULL == ( tmp_mem = ( word_8* )malloc( ( size_t )st.st_size ) ) ) {
425425
for ( i = 0, j = 0; i < size / 2; i++ ) {
426426
if ( 1 != fread( &byte, 1, 1, fp ) ) {
427-
if ( verbose )
427+
if ( config.verbose )
428428
fprintf( stderr, "can\'t read %s\n", name );
429429
fclose( fp );
430430
return 0;
@@ -434,7 +434,7 @@ int read_mem_file( char* name, word_4* mem, int size )
434434
}
435435
} else {
436436
if ( fread( tmp_mem, 1, ( size_t )size / 2, fp ) != ( unsigned long )( size / 2 ) ) {
437-
if ( verbose )
437+
if ( config.verbose )
438438
fprintf( stderr, "can\'t read %s\n", name );
439439
fclose( fp );
440440
free( tmp_mem );
@@ -452,7 +452,7 @@ int read_mem_file( char* name, word_4* mem, int size )
452452

453453
fclose( fp );
454454

455-
if ( verbose )
455+
if ( config.verbose )
456456
printf( "read %s\n", name );
457457

458458
return 1;
@@ -473,7 +473,7 @@ int read_files( void )
473473
if ( !read_rom_file( normalized_rom_path, &saturn.rom, &rom_size ) )
474474
return 0;
475475

476-
if ( verbose )
476+
if ( config.verbose )
477477
printf( "read %s\n", normalized_rom_path );
478478

479479
rom_is_new = false;
@@ -482,7 +482,7 @@ int read_files( void )
482482
/* 2. read saved state from ~/.x48ng/state into fp */
483483
/**************************************************/
484484
if ( NULL == ( fp = fopen( normalized_state_path, "r" ) ) ) {
485-
if ( verbose )
485+
if ( config.verbose )
486486
fprintf( stderr, "can\'t open %s\n", normalized_state_path );
487487
return 0;
488488
}
@@ -506,7 +506,7 @@ int read_files( void )
506506
read_version = 1;
507507
for ( i = 0; i < 4; i++ ) {
508508
if ( !read_char( fp, &saturn.version[ i ] ) ) {
509-
if ( verbose )
509+
if ( config.verbose )
510510
fprintf( stderr, "can\'t read version\n" );
511511
read_version = 0;
512512
}
@@ -525,10 +525,10 @@ int read_files( void )
525525
* try to read latest version file
526526
*/
527527
if ( !read_state_file( fp ) ) {
528-
if ( verbose )
528+
if ( config.verbose )
529529
fprintf( stderr, "can\'t handle %s\n", normalized_state_path );
530530
init_saturn();
531-
} else if ( verbose )
531+
} else if ( config.verbose )
532532
printf( "read %s\n", normalized_state_path );
533533
}
534534
}
@@ -542,7 +542,7 @@ int read_files( void )
542542

543543
saturn.ram = ( word_4* )NULL;
544544
if ( NULL == ( saturn.ram = ( word_4* )malloc( ram_size ) ) ) {
545-
if ( verbose )
545+
if ( config.verbose )
546546
fprintf( stderr, "can\'t malloc RAM[%d]\n", ram_size );
547547
exit( 1 );
548548
}
@@ -551,7 +551,7 @@ int read_files( void )
551551
/* 3. read RAM from ~/.x48ng/ram into saturn.ram */
552552
/*************************************************/
553553
if ( ( fp = fopen( normalized_ram_path, "r" ) ) == NULL ) {
554-
if ( verbose )
554+
if ( config.verbose )
555555
fprintf( stderr, "can\'t open %s\n", normalized_ram_path );
556556
return 0;
557557
}
@@ -575,7 +575,7 @@ int read_files( void )
575575
port1_size = 2 * st.st_size;
576576
if ( ( port1_size == 0x10000 ) || ( port1_size == 0x40000 ) ) {
577577
if ( NULL == ( saturn.port1 = ( word_4* )malloc( port1_size ) ) ) {
578-
if ( verbose )
578+
if ( config.verbose )
579579
fprintf( stderr, "can\'t malloc PORT1[%ld]\n", port1_size );
580580
} else if ( !read_mem_file( normalized_port1_path, saturn.port1, port1_size ) ) {
581581
port1_size = 0;
@@ -608,7 +608,7 @@ int read_files( void )
608608
if ( ( opt_gx && ( ( port2_size % 0x40000 ) == 0 ) ) ||
609609
( !opt_gx && ( ( port2_size == 0x10000 ) || ( port2_size == 0x40000 ) ) ) ) {
610610
if ( NULL == ( saturn.port2 = ( word_4* )malloc( port2_size ) ) ) {
611-
if ( verbose )
611+
if ( config.verbose )
612612
fprintf( stderr, "can\'t malloc PORT2[%ld]\n", port2_size );
613613
} else if ( !read_mem_file( normalized_port2_path, saturn.port2, port2_size ) ) {
614614
port2_size = 0;
@@ -644,7 +644,7 @@ int write_8( FILE* fp, word_8* var )
644644

645645
tmp = *var;
646646
if ( fwrite( &tmp, 1, 1, fp ) != 1 ) {
647-
if ( verbose )
647+
if ( config.verbose )
648648
fprintf( stderr, "can\'t write word_8\n" );
649649
return 0;
650650
}
@@ -657,7 +657,7 @@ int write_char( FILE* fp, char* var )
657657

658658
tmp = *var;
659659
if ( fwrite( &tmp, 1, 1, fp ) != 1 ) {
660-
if ( verbose )
660+
if ( config.verbose )
661661
fprintf( stderr, "can\'t write char\n" );
662662
return 0;
663663
}
@@ -671,7 +671,7 @@ int write_16( FILE* fp, word_16* var )
671671
tmp[ 0 ] = ( *var >> 8 ) & 0xff;
672672
tmp[ 1 ] = *var & 0xff;
673673
if ( fwrite( &tmp[ 0 ], 1, 2, fp ) != 2 ) {
674-
if ( verbose )
674+
if ( config.verbose )
675675
fprintf( stderr, "can\'t write word_16\n" );
676676
return 0;
677677
}
@@ -687,7 +687,7 @@ int write_32( FILE* fp, word_32* var )
687687
tmp[ 2 ] = ( *var >> 8 ) & 0xff;
688688
tmp[ 3 ] = *var & 0xff;
689689
if ( fwrite( &tmp[ 0 ], 1, 4, fp ) != 4 ) {
690-
if ( verbose )
690+
if ( config.verbose )
691691
fprintf( stderr, "can\'t write word_32\n" );
692692
return 0;
693693
}
@@ -703,7 +703,7 @@ int write_u_long( FILE* fp, unsigned long* var )
703703
tmp[ 2 ] = ( *var >> 8 ) & 0xff;
704704
tmp[ 3 ] = *var & 0xff;
705705
if ( fwrite( &tmp[ 0 ], 1, 4, fp ) != 4 ) {
706-
if ( verbose )
706+
if ( config.verbose )
707707
fprintf( stderr, "can\'t write unsigned long\n" );
708708
return 0;
709709
}
@@ -718,7 +718,7 @@ int write_mem_file( char* name, word_4* mem, int size )
718718
int i, j;
719719

720720
if ( NULL == ( fp = fopen( name, "w" ) ) ) {
721-
if ( verbose )
721+
if ( config.verbose )
722722
fprintf( stderr, "can\'t open %s\n", name );
723723
return 0;
724724
}
@@ -728,7 +728,7 @@ int write_mem_file( char* name, word_4* mem, int size )
728728
byte = ( mem[ j++ ] & 0x0f );
729729
byte |= ( mem[ j++ ] << 4 ) & 0xf0;
730730
if ( 1 != fwrite( &byte, 1, 1, fp ) ) {
731-
if ( verbose )
731+
if ( config.verbose )
732732
fprintf( stderr, "can\'t write %s\n", name );
733733
fclose( fp );
734734
return 0;
@@ -741,7 +741,7 @@ int write_mem_file( char* name, word_4* mem, int size )
741741
}
742742

743743
if ( fwrite( tmp_mem, 1, ( size_t )size / 2, fp ) != ( unsigned long )size / 2 ) {
744-
if ( verbose )
744+
if ( config.verbose )
745745
fprintf( stderr, "can\'t write %s\n", name );
746746
fclose( fp );
747747
free( tmp_mem );
@@ -753,7 +753,7 @@ int write_mem_file( char* name, word_4* mem, int size )
753753

754754
fclose( fp );
755755

756-
if ( verbose )
756+
if ( config.verbose )
757757
printf( "wrote %s\n", name );
758758

759759
return 1;
@@ -765,7 +765,7 @@ int write_state_file( char* filename )
765765
FILE* fp;
766766

767767
if ( ( fp = fopen( filename, "w" ) ) == NULL ) {
768-
if ( verbose )
768+
if ( config.verbose )
769769
fprintf( stderr, "can\'t open %s, no saving done\n", filename );
770770
return 0;
771771
}
@@ -865,7 +865,7 @@ int write_state_file( char* filename )
865865

866866
fclose( fp );
867867

868-
if ( verbose )
868+
if ( config.verbose )
869869
printf( "wrote %s\n", filename );
870870

871871
return 1;
@@ -881,21 +881,21 @@ int write_files( void )
881881
if ( errno == ENOENT ) {
882882
make_dir = true;
883883
} else {
884-
if ( verbose )
884+
if ( config.verbose )
885885
fprintf( stderr, "can\'t stat %s, saving to /tmp\n", normalized_config_path );
886886
strcpy( normalized_config_path, "/tmp" );
887887
}
888888
} else {
889889
if ( !S_ISDIR( st.st_mode ) ) {
890-
if ( verbose )
890+
if ( config.verbose )
891891
fprintf( stderr, "%s is no directory, saving to /tmp\n", normalized_config_path );
892892
strcpy( normalized_config_path, "/tmp" );
893893
}
894894
}
895895

896896
if ( make_dir ) {
897897
if ( mkdir( normalized_config_path, 0777 ) == -1 ) {
898-
if ( verbose )
898+
if ( config.verbose )
899899
fprintf( stderr, "can\'t mkdir %s, saving to /tmp\n", normalized_config_path );
900900
strcpy( normalized_config_path, "/tmp" );
901901
}
@@ -914,7 +914,7 @@ int write_files( void )
914914
if ( !write_mem_file( new_rom_path, saturn.rom, rom_size ) )
915915
return 0;
916916

917-
if ( verbose )
917+
if ( config.verbose )
918918
printf( "wrote %s\n", new_rom_path );
919919
}
920920

@@ -941,15 +941,15 @@ int read_rom( const char* fname )
941941
if ( !read_rom_file( fname, &saturn.rom, &rom_size ) )
942942
return 0;
943943

944-
if ( verbose )
944+
if ( config.verbose )
945945
printf( "read %s\n", fname );
946946

947947
dev_memory_init();
948948

949949
ram_size = opt_gx ? RAM_SIZE_GX : RAM_SIZE_SX;
950950

951951
if ( NULL == ( saturn.ram = ( word_4* )malloc( ram_size ) ) ) {
952-
if ( verbose )
952+
if ( config.verbose )
953953
fprintf( stderr, "can\'t malloc RAM\n" );
954954
return 0;
955955
}
@@ -1000,11 +1000,11 @@ void start_emulator( void )
10001000
{
10011001
/* If files are successfully read => return and let's go */
10021002
if ( read_files() ) {
1003-
if ( resetOnStartup )
1003+
if ( config.resetOnStartup )
10041004
saturn.PC = 0x00000;
10051005
} else {
10061006
/* if files were not readable => initialize */
1007-
if ( verbose )
1007+
if ( config.verbose )
10081008
fprintf( stderr, "initialization of %s\n", normalized_config_path );
10091009

10101010
init_saturn();

0 commit comments

Comments
 (0)