From: Hugo Villeneuve Date: Mon, 18 Nov 2013 00:48:05 +0000 (-0500) Subject: Add function to read 16-bit address/offset/value from pgm memory X-Git-Tag: v2.0.0~80 X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=ad5ac01289f23e38a1b14a33d4e98a1c5a6655f5;p=emu8051.git Add function to read 16-bit address/offset/value from pgm memory --- diff --git a/src/memory.c b/src/memory.c index ac8bca5..67a9266 100644 --- a/src/memory.c +++ b/src/memory.c @@ -183,6 +183,18 @@ stack_pop16(void) return value; } +/* Read a 16-bit address from PGM memory, starting at offset */ +uint16_t +pgm_read_addr16(uint16_t base) +{ + uint16_t addr; + + addr = memory_read8(PGM_MEM_ID, base) << 8; /* MSB */ + addr |= memory_read8(PGM_MEM_ID, base + 1); /* LSB */ + + return addr; +} + /* Dump memory */ void DumpMem(char *Address, char *Asize, int memory_id) diff --git a/src/memory.h b/src/memory.h index c8761e9..fee41a6 100644 --- a/src/memory.h +++ b/src/memory.h @@ -79,6 +79,9 @@ stack_pop8(void); uint16_t stack_pop16(void); +uint16_t +pgm_read_addr16(uint16_t base); + void DumpMem(char *Address, char *Asize, int memory_id); diff --git a/src/opcode2c.pl b/src/opcode2c.pl index 270112a..035c718 100755 --- a/src/opcode2c.pl +++ b/src/opcode2c.pl @@ -231,8 +231,8 @@ for ($i=0 ; $i< 256; $i++) { cfw("cpu8051.pc++;"); } if ($op_destination == 1) { # addr16 - cfw("unsigned int addr16 = ( memory_read8( PGM_MEM_ID, cpu8051.pc++ ) << 8 );"); - cfw("addr16 += memory_read8( PGM_MEM_ID, cpu8051.pc++ );"); + cfw("uint16_t addr16 = pgm_read_addr16(cpu8051.pc);"); + cfw("cpu8051.pc += 2;"); } if ($op_destination == 2) { # A cfw("unsigned char destination = cpu8051_ReadD( _ACC_ );"); @@ -247,7 +247,6 @@ for ($i=0 ; $i< 256; $i++) { if ($op_destination == 5) { # @R1 cfw("unsigned char destination = cpu8051_ReadI ( cpu8051_ReadD( BANKPSW + _R1_ ) );"); } - if ($op_destination == 6) { # R0 cfw("unsigned char destination = cpu8051_ReadD( BANKPSW + _R0_ );"); } @@ -311,8 +310,8 @@ for ($i=0 ; $i< 256; $i++) { cfw("unsigned int addr11 = ( ( memory_read8( PGM_MEM_ID, cpu8051.pc - 1 ) << 3 ) & 0xF00 ) + memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );"); } if ($op_source == 1) { # addr16 - cfw("unsigned int addr16 = ( memory_read8( PGM_MEM_ID, (cpu8051.pc)++ ) << 8 );"); - cfw("addr16 += memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );"); + cfw("uint16_t addr16 = pgm_read_addr16(cpu8051.pc);"); + cfw("cpu8051.pc += 2;"); } if ($op_source == 2) { # A cfw("unsigned char source = cpu8051_ReadD( _ACC_ );"); @@ -376,8 +375,8 @@ for ($i=0 ; $i< 256; $i++) { cfw("unsigned int source = memory_sfr_read_dptr();"); } if ($op_source == 22) { # #data16 - cfw("unsigned int source = ( memory_read8( PGM_MEM_ID, (cpu8051.pc)++ ) << 8 );"); - cfw("source += memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );"); + cfw("uint16_t source = pgm_read_addr16(cpu8051.pc);"); + cfw("cpu8051.pc += 2;"); } if ($op_source == 23) { # /bitaddr cfw("unsigned char source, srcbitaddr = memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );"); @@ -390,7 +389,6 @@ for ($i=0 ; $i< 256; $i++) { ############################################################################## $modifysrc=0; -# cfw("\n// Inserer le code ici\n\n"; # RR if ($insttype[$i] == 3) {