From da17471fcb26f0dbed0aa88f863aec043b9f8851 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Sat, 29 Oct 2011 20:46:22 +0000 Subject: [PATCH] Fix error with SJMP instruction Error reported and fixed by Pierre Ferrari (piferr4ri at gmail.com). --- src/opcode2c.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/opcode2c.pl b/src/opcode2c.pl index 9fcca45..3e3bdc7 100755 --- a/src/opcode2c.pl +++ b/src/opcode2c.pl @@ -282,7 +282,7 @@ for ($i=0 ; $i< 256; $i++) { } if ($op_destination == 15) { # reladdr print INST_IMP "cpu8051.pc++;\n"; - print INST_IMP "unsigned int destination = ( ( memory_read8( PGM_MEM_ID, cpu8051.pc - 1 ) + cpu8051.pc ) & 0xFF ) + ( cpu8051.pc & 0xFF00 );\n"; + print INST_IMP "unsigned int destination = ((char) memory_read8(PGM_MEM_ID, cpu8051.pc - 1)) + cpu8051.pc;\n"; } if ($op_destination == 16) { # #data print INST_IMP "unsigned char destination = memory_read8( PGM_MEM_ID, cpu8051.pc++ );\n"; @@ -367,7 +367,7 @@ for ($i=0 ; $i< 256; $i++) { } if ($op_source == 15) { # reladdr print INST_IMP "(cpu8051.pc)++;\n"; - print INST_IMP "unsigned int source = ( ( memory_read8( PGM_MEM_ID, cpu8051.pc - 1 ) + cpu8051.pc ) & 0xFF ) + ( cpu8051.pc & 0xFF00 );\n"; + print INST_IMP "unsigned int source = ((char) memory_read8(PGM_MEM_ID, cpu8051.pc - 1)) + cpu8051.pc;\n"; } if ($op_source == 16) { # #data print INST_IMP "unsigned char source = memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );\n"; @@ -609,7 +609,7 @@ for ($i=0 ; $i< 256; $i++) { # CJNE if ($insttype[$i] == 34) { - print INST_IMP "unsigned int reladdr = ( ( memory_read8( PGM_MEM_ID, cpu8051.pc ) + ( ( cpu8051.pc + 1 ) & 0x00FF ) ) & 0x00FF ) + ( ( cpu8051.pc + 1 ) & 0xFF00 );\n"; + 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"; -- 2.20.1