X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=src%2Fopcode2c.pl;h=a72c8f766319c9888f71a039bb8d93b79c312368;hb=3615ed71ecaa97d539debdf803fa5f3ea21e4a1e;hp=95b9455bbf83b474ec487354f74cb0af34046c1d;hpb=60f3340a9f321271f5ea96df2ccfc248f67bfd2f;p=emu8051.git diff --git a/src/opcode2c.pl b/src/opcode2c.pl index 95b9455..a72c8f7 100755 --- a/src/opcode2c.pl +++ b/src/opcode2c.pl @@ -215,8 +215,6 @@ for ($i=0 ; $i< 256; $i++) { print INST_IMP " ","*"x76,"/\n"; print INST_IMP "int\n"; print INST_IMP "cpu8051_OP_$a_opcodehex[$i](void)\n"; -# TEST hugo new... -# print INST_DEF "int OP_$a_opcodehex[$i]( );\n"; print INST_IMP "{\n"; if( $i == 0x85 ) { @@ -232,7 +230,8 @@ for ($i=0 ; $i< 256; $i++) { if ($instargs[$i*4] > 0) { $op_destination=$instargs[$i*4+1]; if ($op_destination == 0) { # addr11 - print INST_IMP " unsigned int addr11 = ( ( memory_read8( PGM_MEM_ID, cpu8051.pc - 1 ) << 3 ) & 0xF00 ) + memory_read8( PGM_MEM_ID, cpu8051.pc++ );\n"; + print INST_IMP " unsigned int addr11 = ( ( memory_read8( PGM_MEM_ID, cpu8051.pc - 1 ) << 3 ) & 0xF00 ) + memory_read8( PGM_MEM_ID, cpu8051.pc );\n"; + print INST_IMP " cpu8051.pc++;\n"; } if ($op_destination == 1) { # addr16 print INST_IMP "unsigned int addr16 = ( memory_read8( PGM_MEM_ID, cpu8051.pc++ ) << 8 );\n"; @@ -291,7 +290,7 @@ for ($i=0 ; $i< 256; $i++) { print INST_IMP "unsigned char destination = ( cpu8051_ReadD( _PSW_ ) >> 7 );\n"; } if ($op_destination == 18) { # @A+DPTR - print INST_IMP "unsigned int destination = cpu8051_ReadI( cpu8051_ReadD( _ACC_ ) + cpu8051_ReadD( _DPTRLOW_ ) + ( cpu8051_ReadD( _DPTRHIGH_ ) << 8 ) );\n"; + print INST_IMP "unsigned int destination = cpu8051_ReadD( _ACC_ ) + memory_sfr_read_dptr();\n"; } # Mis en commentaire car donnait un warning (destination et source unused variables...) # if ($op_destination == 20) { # AB @@ -299,7 +298,7 @@ for ($i=0 ; $i< 256; $i++) { # print INST_IMP "unsigned char source = cpu8051_ReadD( _B_ );\n"; # } if ($op_destination == 21) { # DPTR - print INST_IMP "unsigned int destination = ( cpu8051_ReadD( _DPTRHIGH_ ) << 8 ) + cpu8051_ReadD( _DPTRLOW_ );\n"; + print INST_IMP "unsigned int destination = memory_sfr_read_dptr();\n"; } if ($op_destination == 22) { # #data16 print INST_IMP "unsigned char destination = ( memory_read8( PGM_MEM_ID, (cpu8051.pc)++ ) << 8 );\n"; @@ -310,7 +309,7 @@ for ($i=0 ; $i< 256; $i++) { print INST_IMP "destination = ( cpu8051_ReadB( dstbitaddr ) ^ 1 );\n"; } if ($op_destination == 24) { # @DPTR - print INST_IMP "unsigned char destination = cpu8051_ReadI( ( cpu8051_ReadD( _DPTRHIGH_ ) << 8 ) + cpu8051_ReadD( _DPTRLOW_) );\n"; + print INST_IMP "unsigned char destination = cpu8051_ReadI(memory_sfr_read_dptr());\n"; } } @@ -376,13 +375,13 @@ for ($i=0 ; $i< 256; $i++) { print INST_IMP "unsigned char source = ( cpu8051_ReadD( _PSW_ ) >> 7 );\n"; } if ($op_source == 18) { # @A+DPTR - print INST_IMP "unsigned char source = memory_read8( PGM_MEM_ID, cpu8051_ReadD( _ACC_ ) + cpu8051_ReadD( _DPTRLOW_ ) + ( cpu8051_ReadD( _DPTRHIGH_ ) << 8 ) );\n"; + print INST_IMP "unsigned char source = memory_read8( PGM_MEM_ID, cpu8051_ReadD( _ACC_ ) + memory_sfr_read_dptr());\n"; } if ($op_source == 19) { # @A+PC print INST_IMP "unsigned char source = memory_read8( PGM_MEM_ID, cpu8051_ReadD( _ACC_ ) + ( ++cpu8051.pc ) );\n"; } if ($op_source == 21) { # DPTR - print INST_IMP "unsigned int source = ( cpu8051_ReadD( _DPTRHIGH_ ) << 8 ) + cpu8051_ReadD( _DPTRLOW_ );\n"; + print INST_IMP "unsigned int source = memory_sfr_read_dptr();\n"; } if ($op_source == 22) { # #data16 print INST_IMP "unsigned char source = ( memory_read8( PGM_MEM_ID, (cpu8051.pc)++ ) << 8 );\n"; @@ -393,7 +392,7 @@ for ($i=0 ; $i< 256; $i++) { print INST_IMP "source = ( cpu8051_ReadB( srcbitaddr ) ^ 1 );\n"; } if ($op_source == 24) { # @DPTR - print INST_IMP "unsigned char source = cpu8051_ReadI( ( cpu8051_ReadD( _DPTRHIGH_ ) << 8 ) + cpu8051_ReadD( _DPTRLOW_) );\n"; + print INST_IMP "unsigned char source = cpu8051_ReadI(memory_sfr_read_dptr());\n"; } } @@ -469,7 +468,7 @@ for ($i=0 ; $i< 256; $i++) { print INST_IMP " cpu8051_WriteD( _PSW_, ( cpu8051_ReadD( _PSW_ ) | 0x80 ) );\n"; print INST_IMP " if ( ( destination & 0x7F ) + ( source & 0x7F ) < 0x80 ) cpu8051_WriteD( _PSW_, ( cpu8051_ReadD( _PSW_ ) | 0x04 ) );\n"; print INST_IMP "} else if ( ( destination & 0x7F ) + ( source & 0x7F ) > 0x7F ) cpu8051_WriteD( _PSW_, ( cpu8051_ReadD( _PSW_ ) | 0x04 ) );\n"; - print INST_IMP "if ( ( destination & 0x0F ) + ( source & 0x0F ) > 0x0F ) cpu8051_WriteD( _PSW_, ( cpu8051_ReadD( _PSW_ ) | 0x04 ) );\n"; + print INST_IMP "if ( ( destination & 0x0F ) + ( source & 0x0F ) > 0x0F ) cpu8051_WriteD( _PSW_, ( cpu8051_ReadD( _PSW_ ) | 0x40 ) );\n"; print INST_IMP "destination += source;\n"; } @@ -484,6 +483,7 @@ for ($i=0 ; $i< 256; $i++) { print INST_IMP "unsigned char SP = cpu8051_ReadD( _SP_ );\n"; print INST_IMP "cpu8051.pc = ( cpu8051_ReadI( SP-- ) << 8 );\n"; print INST_IMP "cpu8051.pc += cpu8051_ReadI( SP-- );\n"; + print INST_IMP "cpu8051_WriteD( _SP_, SP );\n"; } # RLC @@ -512,13 +512,7 @@ for ($i=0 ; $i< 256; $i++) { # ORL if ($insttype[$i] == 19) { - if ($instargs[$i*4+1] == 17) { - # sur des bits - print INST_IMP "cpu8051_WriteD( _PSW_ , ( ( destination | source ) << 7 ) );\n"; - } else { - # sur des bytes - print INST_IMP "destination |= source;\n"; - } + print INST_IMP "destination |= source;\n"; } # JNC @@ -528,13 +522,7 @@ for ($i=0 ; $i< 256; $i++) { # ANL if ($insttype[$i] == 21) { - if ($instargs[$i*4+1] == 17) { - # sur des bits - print INST_IMP "cpu8051_WriteD( _PSW_, ( ( destination & source) << 7 ) );\n"; - } else { - # sur des bytes - print INST_IMP "destination &= source;\n"; - } + print INST_IMP "destination &= source;\n"; } # JZ @@ -612,7 +600,7 @@ for ($i=0 ; $i< 256; $i++) { print INST_IMP "unsigned int reladdr = ((char) memory_read8(PGM_MEM_ID, cpu8051.pc)) + (cpu8051.pc + 1);\n"; print INST_IMP "cpu8051_WriteD( _PSW_, ( cpu8051_ReadD( _PSW_ ) & 0x7F ) );\n"; print INST_IMP "if ( destination < source ) cpu8051_WriteD( _PSW_, ( cpu8051_ReadD( _PSW_ ) | 0x80 ) );\n"; - print INST_IMP "if ( destination != source ) cpu8051.pc = reladdr;\n"; + print INST_IMP "if ( destination != source ) cpu8051.pc = reladdr; else cpu8051.pc++; \n"; } # PUSH @@ -739,14 +727,13 @@ for ($i=0 ; $i< 256; $i++) { print INST_IMP "cpu8051_WriteD( _PSW_, ( ( cpu8051_ReadD( _PSW_ ) & 0x7F) | ( destination << 7 ) ) );\n"; } if ($op_destination == 21) { # DPTR - print INST_IMP "cpu8051_WriteD( _DPTRHIGH_, ( destination >> 8 ) );\n"; - print INST_IMP "cpu8051_WriteD( _DPTRLOW_, ( destination & 0xFF ) );\n"; + print INST_IMP "memory_sfr_write_dptr(destination);\n"; } if ($op_destination == 23) { # /bitaddr print INST_IMP "cpu8051_WriteB( dstbitaddr, destination );\n"; } if ($op_destination == 24) { # @DPTR - print INST_IMP "cpu8051_WriteI( ( cpu8051_ReadD( _DPTRHIGH_ ) << 8 ) + cpu8051_ReadD( _DPTRLOW_ ), destination );\n"; + print INST_IMP "cpu8051_WriteI(memory_sfr_read_dptr(), destination);\n"; } } @@ -802,14 +789,13 @@ for ($i=0 ; $i< 256; $i++) { print INST_IMP "cpu8051_WriteD( _PSW_, ( ( cpu8051_ReadD( _PSW_ ) & 0x7F) | ( source << 7 ) ) );\n"; } if ($op_source == 21) { # DPTR - print INST_IMP "cpu8051_WriteD( _DPTRHIGH_, ( source >> 8 ) );\n"; - print INST_IMP "cpu8051_WriteD( _DPTRLOW_, ( source & 0xFF ) );\n"; + print INST_IMP "memory_sfr_write_dptr(source);\n"; } if ($op_source == 23) { # /bitaddr print INST_IMP "cpu8051_WriteB( srcbitaddr, source );\n"; } if ($op_source == 24) { # @DPTR - print INST_IMP "cpu8051_WriteI( ( cpu8051_ReadD( _DPTRHIGH_ ) << 8 ) + cpu8051_ReadD( _DPTRLOW_ ), source );\n"; + print INST_IMP "cpu8051_WriteI(memory_sfr_read_dptr(), source);\n"; } } }