[step_instruction] clean up use of variables

This commit is contained in:
Gwenhael Le Moine 2024-06-11 13:58:00 +02:00
parent 584f93fae8
commit 8454ec1ce5
No known key found for this signature in database
GPG key ID: FDFE3669426707A7

View file

@ -293,7 +293,7 @@ static inline void do_configure( void )
} }
} }
static inline int get_identification( void ) static inline void get_identification( void )
{ {
int i; int i;
static int chip_id[] = { 0, 0, 0, 0, 0x05, 0xf6, 0x07, 0xf8, 0x01, 0xf2, 0, 0 }; static int chip_id[] = { 0, 0, 0, 0, 0x05, 0xf6, 0x07, 0xf8, 0x01, 0xf2, 0, 0 };
@ -308,8 +308,6 @@ static inline int get_identification( void )
saturn.C[ i ] = id & 0x0f; saturn.C[ i ] = id & 0x0f;
id >>= 4; id >>= 4;
} }
return 0;
} }
static inline void do_shutdown( void ) static inline void do_shutdown( void )
@ -554,11 +552,8 @@ void load_addr( word_20* dat, long addr, int n )
void step_instruction( void ) void step_instruction( void )
{ {
int op0, op1, op2, op3, op4, op5, op6; bool illegal_instruction = false;
bool stop = false; int op0, op1, op2, op3, op4, op5;
int t, opX;
unsigned char* REG;
long addr;
op0 = read_nibble( saturn.PC ); op0 = read_nibble( saturn.PC );
switch ( op0 ) { switch ( op0 ) {
@ -701,14 +696,14 @@ void step_instruction( void )
or_register( saturn.C, saturn.C, saturn.D, op2 ); or_register( saturn.C, saturn.C, saturn.D, op2 );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 0xf: /* RTI */ case 0xf: /* RTI */
do_return_interupt(); do_return_interupt();
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 1: case 1:
@ -764,7 +759,7 @@ void step_instruction( void )
copy_register( saturn.R4, saturn.C, W_FIELD ); copy_register( saturn.R4, saturn.C, W_FIELD );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 1: case 1:
@ -817,7 +812,7 @@ void step_instruction( void )
copy_register( saturn.C, saturn.R4, W_FIELD ); copy_register( saturn.C, saturn.R4, W_FIELD );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 2: case 2:
@ -870,7 +865,7 @@ void step_instruction( void )
exchange_register( saturn.C, saturn.R4, W_FIELD ); exchange_register( saturn.C, saturn.R4, W_FIELD );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 3: case 3:
@ -941,47 +936,49 @@ void step_instruction( void )
exchange_reg( saturn.C, &saturn.D1, IN_FIELD ); exchange_reg( saturn.C, &saturn.D1, IN_FIELD );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 4: case 4:
op3 = read_nibble( saturn.PC + 2 ); op3 = read_nibble( saturn.PC + 2 );
opX = op3 < 8 ? 0xf : 6; {
switch ( op3 & 7 ) { int opX = op3 < 8 ? 0xf : 6;
case 0: /* DAT0=A */ switch ( op3 & 7 ) {
saturn.PC += 3; case 0: /* DAT0=A */
store( saturn.D0, saturn.A, opX ); saturn.PC += 3;
break; store( saturn.D0, saturn.A, opX );
case 1: /* DAT1=A */ break;
saturn.PC += 3; case 1: /* DAT1=A */
store( saturn.D1, saturn.A, opX ); saturn.PC += 3;
break; store( saturn.D1, saturn.A, opX );
case 2: /* A=DAT0 */ break;
saturn.PC += 3; case 2: /* A=DAT0 */
recall( saturn.A, saturn.D0, opX ); saturn.PC += 3;
break; recall( saturn.A, saturn.D0, opX );
case 3: /* A=DAT1 */ break;
saturn.PC += 3; case 3: /* A=DAT1 */
recall( saturn.A, saturn.D1, opX ); saturn.PC += 3;
break; recall( saturn.A, saturn.D1, opX );
case 4: /* DAT0=C */ break;
saturn.PC += 3; case 4: /* DAT0=C */
store( saturn.D0, saturn.C, opX ); saturn.PC += 3;
break; store( saturn.D0, saturn.C, opX );
case 5: /* DAT1=C */ break;
saturn.PC += 3; case 5: /* DAT1=C */
store( saturn.D1, saturn.C, opX ); saturn.PC += 3;
break; store( saturn.D1, saturn.C, opX );
case 6: /* C=DAT0 */ break;
saturn.PC += 3; case 6: /* C=DAT0 */
recall( saturn.C, saturn.D0, opX ); saturn.PC += 3;
break; recall( saturn.C, saturn.D0, opX );
case 7: /* C=DAT1 */ break;
saturn.PC += 3; case 7: /* C=DAT1 */
recall( saturn.C, saturn.D1, opX ); saturn.PC += 3;
break; recall( saturn.C, saturn.D1, opX );
default: break;
stop = true; default:
illegal_instruction = true;
}
} }
break; break;
case 5: case 5:
@ -1022,7 +1019,7 @@ void step_instruction( void )
recall_n( saturn.C, saturn.D1, op4 + 1 ); recall_n( saturn.C, saturn.D1, op4 + 1 );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
} else { } else {
switch ( op3 ) { switch ( op3 ) {
@ -1059,7 +1056,7 @@ void step_instruction( void )
recall( saturn.C, saturn.D1, op4 ); recall( saturn.C, saturn.D1, op4 );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
} }
break; break;
@ -1108,7 +1105,7 @@ void step_instruction( void )
saturn.PC += 7; saturn.PC += 7;
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 2: case 2:
@ -1209,7 +1206,7 @@ void step_instruction( void )
break; break;
case 6: /* C=ID */ case 6: /* C=ID */
saturn.PC += 3; saturn.PC += 3;
stop = get_identification(); get_identification();
break; break;
case 7: /* SHUTDN */ case 7: /* SHUTDN */
saturn.PC += 3; saturn.PC += 3;
@ -1260,18 +1257,13 @@ void step_instruction( void )
case 0xa: /* ?CBIT=0 */ case 0xa: /* ?CBIT=0 */
case 0xb: /* ?CBIT=1 */ case 0xb: /* ?CBIT=1 */
op5 = read_nibble( saturn.PC + 4 ); op5 = read_nibble( saturn.PC + 4 );
if ( op4 < 8 ) saturn.CARRY = ( get_register_bit( ( op4 < 8 ) ? saturn.A : saturn.C, op5 ) ==
REG = saturn.A; ( ( op4 == 6 || op4 == 0xa ) ? 0 : 1 ) )
else ? 1
REG = saturn.C; : 0;
if ( op4 == 6 || op4 == 0xa )
t = 0;
else
t = 1;
saturn.CARRY = ( get_register_bit( REG, op5 ) == t ) ? 1 : 0;
if ( saturn.CARRY ) { if ( saturn.CARRY ) {
saturn.PC += 5; saturn.PC += 5;
op6 = read_nibbles( saturn.PC, 2 ); int op6 = read_nibbles( saturn.PC, 2 );
if ( op6 ) { if ( op6 ) {
if ( op6 & 0x80 ) if ( op6 & 0x80 )
op6 |= jumpmasks[ 2 ]; op6 |= jumpmasks[ 2 ];
@ -1282,22 +1274,20 @@ void step_instruction( void )
saturn.PC += 7; saturn.PC += 7;
break; break;
case 0xc: /* PC=(A) */ case 0xc: /* PC=(A) */
addr = dat_to_addr( saturn.A ); saturn.PC = read_nibbles( dat_to_addr( saturn.A ), 5 );
saturn.PC = read_nibbles( addr, 5 );
break; break;
case 0xd: /* BUSCD */ case 0xd: /* BUSCD */
saturn.PC += 4; saturn.PC += 4;
break; break;
case 0xe: /* PC=(C) */ case 0xe: /* PC=(C) */
addr = dat_to_addr( saturn.C ); saturn.PC = read_nibbles( dat_to_addr( saturn.C ), 5 );
saturn.PC = read_nibbles( addr, 5 );
break; break;
case 0xf: /* INTOFF */ case 0xf: /* INTOFF */
saturn.PC += 4; saturn.PC += 4;
do_intoff(); do_intoff();
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 9: /* C+P+1 */ case 9: /* C+P+1 */
@ -1329,12 +1319,14 @@ void step_instruction( void )
case 0xf: /* CPEX n */ case 0xf: /* CPEX n */
op4 = read_nibble( saturn.PC + 3 ); op4 = read_nibble( saturn.PC + 3 );
saturn.PC += 4; saturn.PC += 4;
t = get_register_nibble( saturn.C, op4 ); {
set_register_nibble( saturn.C, op4, saturn.P ); int tmp = get_register_nibble( saturn.C, op4 );
saturn.P = t; set_register_nibble( saturn.C, op4, saturn.P );
saturn.P = tmp;
}
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 1: case 1:
@ -1395,7 +1387,7 @@ void step_instruction( void )
add_register_constant( saturn.D, op3, op5 + 1 ); add_register_constant( saturn.D, op3, op5 + 1 );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
} else { /* MINUS */ } else { /* MINUS */
switch ( op4 & 3 ) { switch ( op4 & 3 ) {
@ -1416,7 +1408,7 @@ void step_instruction( void )
sub_register_constant( saturn.D, op3, op5 + 1 ); sub_register_constant( saturn.D, op3, op5 + 1 );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
} }
break; break;
@ -1441,7 +1433,7 @@ void step_instruction( void )
shift_right_bit_register( saturn.D, op3 ); shift_right_bit_register( saturn.D, op3 );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 0xa: /* R = R FIELD, etc. */ case 0xa: /* R = R FIELD, etc. */
@ -1498,7 +1490,7 @@ void step_instruction( void )
copy_register( saturn.R4, saturn.C, op3 ); copy_register( saturn.R4, saturn.C, op3 );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 1: case 1:
@ -1550,7 +1542,7 @@ void step_instruction( void )
copy_register( saturn.C, saturn.R4, op3 ); copy_register( saturn.C, saturn.R4, op3 );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 2: case 2:
@ -1602,11 +1594,11 @@ void step_instruction( void )
exchange_register( saturn.C, saturn.R4, op3 ); exchange_register( saturn.C, saturn.R4, op3 );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 0xb: case 0xb:
@ -1637,7 +1629,7 @@ void step_instruction( void )
saturn.PC = dat_to_addr( saturn.C ); saturn.PC = dat_to_addr( saturn.C );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 0xc: /* ASRB */ case 0xc: /* ASRB */
@ -1657,7 +1649,7 @@ void step_instruction( void )
shift_right_bit_register( saturn.D, W_FIELD ); shift_right_bit_register( saturn.D, W_FIELD );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 2: case 2:
@ -1781,7 +1773,7 @@ void step_instruction( void )
saturn.CARRY = is_not_zero_register( saturn.D, A_FIELD ); saturn.CARRY = is_not_zero_register( saturn.D, A_FIELD );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
if ( saturn.CARRY ) { if ( saturn.CARRY ) {
saturn.PC += 3; saturn.PC += 3;
@ -1847,7 +1839,7 @@ void step_instruction( void )
saturn.CARRY = is_less_or_equal_register( saturn.D, saturn.C, A_FIELD ); saturn.CARRY = is_less_or_equal_register( saturn.D, saturn.C, A_FIELD );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
if ( saturn.CARRY ) { if ( saturn.CARRY ) {
saturn.PC += 3; saturn.PC += 3;
@ -1884,7 +1876,7 @@ void step_instruction( void )
saturn.PC = op2; saturn.PC = op2;
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 9: case 9:
@ -1941,7 +1933,7 @@ void step_instruction( void )
saturn.CARRY = is_not_zero_register( saturn.D, op1 ); saturn.CARRY = is_not_zero_register( saturn.D, op1 );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
} else { } else {
op1 &= 7; op1 &= 7;
@ -1995,7 +1987,7 @@ void step_instruction( void )
saturn.CARRY = is_less_or_equal_register( saturn.D, saturn.C, op1 ); saturn.CARRY = is_less_or_equal_register( saturn.D, saturn.C, op1 );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
} }
if ( saturn.CARRY ) { if ( saturn.CARRY ) {
@ -2082,7 +2074,7 @@ void step_instruction( void )
dec_register( saturn.D, op1 ); dec_register( saturn.D, op1 );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
} else { } else {
op1 &= 7; op1 &= 7;
@ -2152,7 +2144,7 @@ void step_instruction( void )
exchange_register( saturn.C, saturn.D, op1 ); exchange_register( saturn.C, saturn.D, op1 );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
} }
break; break;
@ -2226,7 +2218,7 @@ void step_instruction( void )
sub_register( saturn.D, saturn.C, saturn.D, op1 ); sub_register( saturn.D, saturn.C, saturn.D, op1 );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
} else { } else {
op1 &= 7; op1 &= 7;
@ -2296,7 +2288,7 @@ void step_instruction( void )
complement_1_register( saturn.D, op1 ); complement_1_register( saturn.D, op1 );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
} }
break; break;
@ -2368,7 +2360,7 @@ void step_instruction( void )
dec_register( saturn.D, A_FIELD ); dec_register( saturn.D, A_FIELD );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 0xd: case 0xd:
@ -2439,7 +2431,7 @@ void step_instruction( void )
exchange_register( saturn.C, saturn.D, A_FIELD ); exchange_register( saturn.C, saturn.D, A_FIELD );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 0xe: case 0xe:
@ -2510,7 +2502,7 @@ void step_instruction( void )
sub_register( saturn.D, saturn.C, saturn.D, A_FIELD ); sub_register( saturn.D, saturn.C, saturn.D, A_FIELD );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
case 0xf: case 0xf:
@ -2581,15 +2573,15 @@ void step_instruction( void )
complement_1_register( saturn.D, A_FIELD ); complement_1_register( saturn.D, A_FIELD );
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
break; break;
default: default:
stop = true; illegal_instruction = true;
} }
instructions++; instructions++;
if ( stop ) if ( illegal_instruction )
enter_debugger |= ILLEGAL_INSTRUCTION; enter_debugger |= ILLEGAL_INSTRUCTION;
} }