From 3615ed71ecaa97d539debdf803fa5f3ea21e4a1e Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Sun, 10 Nov 2013 23:16:33 -0500 Subject: [PATCH] Add DPTR read/write functions --- src/emuconsole.c | 2 +- src/memory.c | 15 +++++++++++++++ src/memory.h | 6 ++++++ src/opcode2c.pl | 22 ++++++++++------------ 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/emuconsole.c b/src/emuconsole.c index 3dcdf89..f29bbc5 100644 --- a/src/emuconsole.c +++ b/src/emuconsole.c @@ -156,7 +156,7 @@ console_show_registers(void) " - P |\n"); printf("| %.4X | %.2X | %.4X | %.2X | %.2X |", cpu8051.pc, cpu8051_ReadD(_SP_), - (cpu8051_ReadD(_DPTRHIGH_) << 8) + cpu8051_ReadD(_DPTRLOW_), + memory_sfr_read_dptr(), cpu8051_ReadD(_ACC_), cpu8051_ReadD(_B_)); printf(" %d %d %d %d %d %d %d %d |", (PSW >> 7) & 1, (PSW >> 6) & 1, (PSW >> 5) & 1, (PSW >> 4) & 1, diff --git a/src/memory.c b/src/memory.c index f8753d3..057af56 100644 --- a/src/memory.c +++ b/src/memory.c @@ -24,6 +24,7 @@ #include "common.h" #include "cpu8051.h" +#include "reg8051.h" #include "hexfile.h" #include "memory.h" #include "options.h" @@ -97,6 +98,13 @@ memory_sfr_write8(unsigned long address, u_int8_t value) memory_write8(INT_MEM_ID, address, value); } +void +memory_sfr_write_dptr(u_int16_t value) +{ + memory_write8(INT_MEM_ID, _DPTRHIGH_, value >> 8); + memory_write8(INT_MEM_ID, _DPTRLOW_, (uint8_t) value); +} + u_int8_t memory_read8(enum mem_id_t id, unsigned long address) { @@ -116,6 +124,13 @@ memory_sfr_read8(unsigned long address) return memory_read8(INT_MEM_ID, address); } +u_int16_t +memory_sfr_read_dptr(void) +{ + return (memory_read8(INT_MEM_ID, _DPTRHIGH_) << 8) + + memory_read8(INT_MEM_ID, _DPTRLOW_); +} + /* Dump memory */ void DumpMem(char *Address, char *Asize, int memory_id) diff --git a/src/memory.h b/src/memory.h index 9064813..e8ac7ee 100644 --- a/src/memory.h +++ b/src/memory.h @@ -55,12 +55,18 @@ memory_write8(enum mem_id_t id, unsigned long address, u_int8_t value); void memory_sfr_write8(unsigned long address, u_int8_t value); +void +memory_sfr_write_dptr(u_int16_t value); + u_int8_t memory_read8(enum mem_id_t id, unsigned long address); u_int8_t memory_sfr_read8(unsigned long address); +u_int16_t +memory_sfr_read_dptr(void); + void DumpMem(char *Address, char *Asize, int memory_id); diff --git a/src/opcode2c.pl b/src/opcode2c.pl index dcb6894..a72c8f7 100755 --- a/src/opcode2c.pl +++ b/src/opcode2c.pl @@ -290,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_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 @@ -298,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"; @@ -309,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"; } } @@ -375,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"; @@ -392,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"; } } @@ -727,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"; } } @@ -790,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"; } } } -- 2.20.1