minor code fiddling

This commit is contained in:
Gwenhael Le Moine 2024-04-03 15:51:43 +02:00
parent 11b5b8ea66
commit 7b4e9893e2
No known key found for this signature in database
GPG key ID: FDFE3669426707A7

View file

@ -68,18 +68,14 @@ int get_program_stat( int n ) { return saturn.PSTAT[ n ]; }
void register_to_status( unsigned char* r ) void register_to_status( unsigned char* r )
{ {
int i; for ( int i = 0; i < 12; i++ ) {
for ( i = 0; i < 12; i++ ) {
saturn.PSTAT[ i ] = ( r[ i / 4 ] >> ( i % 4 ) ) & 1; saturn.PSTAT[ i ] = ( r[ i / 4 ] >> ( i % 4 ) ) & 1;
} }
} }
void status_to_register( unsigned char* r ) void status_to_register( unsigned char* r )
{ {
int i; for ( int i = 0; i < 12; i++ ) {
for ( i = 0; i < 12; i++ ) {
if ( saturn.PSTAT[ i ] ) { if ( saturn.PSTAT[ i ] ) {
r[ i / 4 ] |= 1 << ( i % 4 ); r[ i / 4 ] |= 1 << ( i % 4 );
} else { } else {
@ -90,9 +86,9 @@ void status_to_register( unsigned char* r )
void swap_register_status( unsigned char* r ) void swap_register_status( unsigned char* r )
{ {
int i, tmp; int tmp;
for ( i = 0; i < 12; i++ ) { for ( int i = 0; i < 12; i++ ) {
tmp = saturn.PSTAT[ i ]; tmp = saturn.PSTAT[ i ];
saturn.PSTAT[ i ] = ( r[ i / 4 ] >> ( i % 4 ) ) & 1; saturn.PSTAT[ i ] = ( r[ i / 4 ] >> ( i % 4 ) ) & 1;
if ( tmp ) if ( tmp )
@ -161,12 +157,8 @@ void do_interupt( void )
void do_kbd_int( void ) void do_kbd_int( void )
{ {
interrupt_called = 1; do_interupt();
if ( saturn.interruptable ) { if ( !saturn.interruptable )
push_return_addr( saturn.PC );
saturn.PC = 0xf;
saturn.interruptable = 0;
} else
saturn.int_pending = 1; saturn.int_pending = 1;
} }
@ -394,11 +386,10 @@ int is_zero_hardware_stat( int op )
void push_return_addr( long addr ) void push_return_addr( long addr )
{ {
int i;
if ( ++saturn.rstkp >= NR_RSTK ) { if ( ++saturn.rstkp >= NR_RSTK ) {
for ( i = 1; i < NR_RSTK; i++ ) for ( int i = 1; i < NR_RSTK; i++ )
saturn.rstk[ i - 1 ] = saturn.rstk[ i ]; saturn.rstk[ i - 1 ] = saturn.rstk[ i ];
saturn.rstkp--; saturn.rstkp--;
} }
saturn.rstk[ saturn.rstkp ] = addr; saturn.rstk[ saturn.rstkp ] = addr;
@ -408,6 +399,7 @@ long pop_return_addr( void )
{ {
if ( saturn.rstkp < 0 ) if ( saturn.rstkp < 0 )
return 0; return 0;
return saturn.rstk[ saturn.rstkp-- ]; return saturn.rstk[ saturn.rstkp-- ];
} }
@ -431,12 +423,8 @@ void load_addr( word_20* dat, long addr, int n )
void register_to_address( unsigned char* reg, word_20* dat, int s ) void register_to_address( unsigned char* reg, word_20* dat, int s )
{ {
int n; int n = ( s ) ? 4 : 5;
if ( s )
n = 4;
else
n = 5;
for ( int i = 0; i < n; i++ ) { for ( int i = 0; i < n; i++ ) {
*dat &= ~nibble_masks[ i ]; *dat &= ~nibble_masks[ i ];
*dat |= ( reg[ i ] & 0x0f ) << ( i * 4 ); *dat |= ( reg[ i ] & 0x0f ) << ( i * 4 );
@ -451,6 +439,7 @@ long dat_to_addr( unsigned char* dat )
addr <<= 4; addr <<= 4;
addr |= ( dat[ i ] & 0xf ); addr |= ( dat[ i ] & 0xf );
} }
return addr; return addr;
} }
@ -465,11 +454,12 @@ void addr_to_dat( long addr, unsigned char* dat )
void add_address( word_20* dat, int add ) void add_address( word_20* dat, int add )
{ {
*dat += add; *dat += add;
if ( *dat & ( word_20 )0xfff00000 ) {
if ( *dat & ( word_20 )0xfff00000 )
saturn.CARRY = 1; saturn.CARRY = 1;
} else { else
saturn.CARRY = 0; saturn.CARRY = 0;
}
*dat &= 0xfffff; *dat &= 0xfffff;
} }