From ba0e6b3b86d05f9db60c4a53ed7db47961bc3da0 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Wed, 12 Feb 2014 23:05:26 -0500 Subject: [PATCH] Move memory read functions to memory.c Fix warnings given by checkpatch.pl --- src/cli/menu.c | 26 ++--- src/common/cpu8051.c | 124 ++++------------------- src/common/cpu8051.h | 18 ---- src/common/memory.c | 85 ++++++++++++++++ src/common/memory.h | 22 +++++ src/common/opcode2c.pl | 216 ++++++++++++++++++++++------------------- src/common/timers.c | 36 +++---- 7 files changed, 275 insertions(+), 252 deletions(-) diff --git a/src/cli/menu.c b/src/cli/menu.c index 579e950..149552b 100644 --- a/src/cli/menu.c +++ b/src/cli/menu.c @@ -239,14 +239,14 @@ static void console_dump_sfr_registers_compact(void) { int id; - unsigned char PSW = cpu8051_ReadD(_PSW_); + unsigned char PSW = memory_read_direct(_PSW_); int bank_sel = (PSW & 0x18); printf("----------------------------------------------------------------------\n"); printf("| PC | SP | DPTR | ACC | B | PSW: CY AC F0 RS1 RS0 OV - P |\n"); printf("| %.4X | %.2X | %.4X | %.2X | %.2X |", cpu8051.pc, - cpu8051_ReadD(_SP_), memory_sfr_read_dptr(), - cpu8051_ReadD(_ACC_), cpu8051_ReadD(_B_)); + memory_read_direct(_SP_), memory_sfr_read_dptr(), + memory_read_direct(_ACC_), memory_read_direct(_B_)); printf(" %d %d %d %d %d %d %d %d |", (PSW >> 7) & 1, (PSW >> 6) & 1, (PSW >> 5) & 1, (PSW >> 4) & 1, (PSW >> 3) & 1, (PSW >> 2) & 1, (PSW >> 1) & 1, PSW & 1); @@ -254,18 +254,18 @@ console_dump_sfr_registers_compact(void) printf("----------------------------------------------------------------------\n"); printf("| TCON | TMOD | IE | IP | R0 | R1 | R2 | R3 | R4 | R5 | R6 | R7 | |\n"); - printf("| %.2X | %.2X | %.2X | %.2X ", cpu8051_ReadD(_TCON_), - cpu8051_ReadD(_TMOD_), cpu8051_ReadD(_IE_), cpu8051_ReadD(_IP_)); + printf("| %.2X | %.2X | %.2X | %.2X ", memory_read_direct(_TCON_), + memory_read_direct(_TMOD_), memory_read_direct(_IE_), memory_read_direct(_IP_)); printf("| %.2X | %.2X | %.2X | %.2X ", - cpu8051_ReadD(bank_sel + _R0_), - cpu8051_ReadD(bank_sel + _R1_), - cpu8051_ReadD(bank_sel + _R2_), - cpu8051_ReadD(bank_sel + _R3_)); + memory_read_direct(bank_sel + _R0_), + memory_read_direct(bank_sel + _R1_), + memory_read_direct(bank_sel + _R2_), + memory_read_direct(bank_sel + _R3_)); printf("| %.2X | %.2X | %.2X | %.2X ", - cpu8051_ReadD(bank_sel + _R4_), - cpu8051_ReadD(bank_sel + _R5_), - cpu8051_ReadD(bank_sel + _R6_), - cpu8051_ReadD(bank_sel + _R7_)); + memory_read_direct(bank_sel + _R4_), + memory_read_direct(bank_sel + _R5_), + memory_read_direct(bank_sel + _R6_), + memory_read_direct(bank_sel + _R7_)); printf("| |\n"); printf("----------------------------------------------------------------------\n"); diff --git a/src/common/cpu8051.c b/src/common/cpu8051.c index 452ef91..10bc2d2 100644 --- a/src/common/cpu8051.c +++ b/src/common/cpu8051.c @@ -161,95 +161,10 @@ cpu8051_reset(void) memory_sfr_write8(_SP_, 0x07); } -static void -cpu8051_convert_bit_address(uint8_t bit_address, uint8_t *byte_address, - uint8_t *bit_number) -{ - if (bit_address > 0x7F) { - /* SFR 80-FF */ - *byte_address = bit_address & 0xF8; - *bit_number = bit_address & 0x07; - } else { - /* 20-2F */ - *byte_address = (bit_address >> 3) + 0x20; - *bit_number = bit_address & 0x07; - } -} - -/* Write with a direct addressing mode at Address the new Value */ -void -cpu8051_WriteD(unsigned int address, unsigned char value) -{ - memory_write8(INT_MEM_ID, address, value); -} - -/* Write with an indirect addressing mode at Address the new Value */ -void -cpu8051_WriteI(unsigned int address, unsigned char value) -{ - if (address > 0x7F) { - memory_write8(EXT_MEM_ID, address, value); - return; - } - - memory_write8(INT_MEM_ID, address, value); -} - -/* Write with a bit addressing mode at BitAddress the new Value */ -void -cpu8051_WriteB(uint8_t bit_address, uint8_t value) -{ - uint8_t byte_address; - uint8_t bit_number; - unsigned char byte_val, byte_mask; - - cpu8051_convert_bit_address(bit_address, &byte_address, &bit_number); - - byte_mask = ((1 << bit_number) ^ 0xFF); - byte_val = cpu8051_ReadD(byte_address) & byte_mask; - byte_val += value << bit_number; - cpu8051_WriteD(byte_address, byte_val); -} - -/* Read with a direct addressing mode at Address */ -unsigned char -cpu8051_ReadD(unsigned int address) -{ - if (address > 0xFF) - return memory_read8(EXT_MEM_ID, address); - else - return memory_read8(INT_MEM_ID, address); -} - -/* Read with a indirect addressing mode at Address */ -unsigned char -cpu8051_ReadI(unsigned int address) -{ - if (address > 0x7F) - return memory_read8(EXT_MEM_ID, address); - else - return memory_read8(INT_MEM_ID, address); -} - -/* Read with a bit addressing mode at BitAddress */ -unsigned char -cpu8051_ReadB(uint8_t bit_address) -{ - uint8_t byte_address; - uint8_t bit_number; - unsigned char bit_value; - - cpu8051_convert_bit_address(bit_address, &byte_address, &bit_number); - - bit_value = (cpu8051_ReadD(byte_address) >> bit_number); - bit_value &= 1; - return bit_value; -} - static int cpu8051_interrupt_fire(int interrupt_no, int priority) { - if (cpu8051_ReadD(_IP_) & INTERRUPT_MASK(interrupt_no)) + if (memory_read_direct(_IP_) & INTERRUPT_MASK(interrupt_no)) return priority; else return !priority; @@ -258,7 +173,7 @@ cpu8051_interrupt_fire(int interrupt_no, int priority) static int cpu8051_interrupt_enabled(int interrupt_no) { - return (cpu8051_ReadD(_IE_) & INTERRUPT_MASK(interrupt_no)) ? 1 : 0; + return (memory_read_direct(_IE_) & INTERRUPT_MASK(interrupt_no)) ? 1 : 0; } static void @@ -276,7 +191,7 @@ cpu8051_check_interrupts(void) { int i; - if ((cpu8051_ReadD(_IE_) & 0x80) == 0) + if ((memory_read_direct(_IE_) & 0x80) == 0) return; for (i = INTERRUPT_PRIORITY_HIGH; i >= INTERRUPT_PRIORITY_LOW; i--) { @@ -284,32 +199,32 @@ cpu8051_check_interrupts(void) /* Interrupt timer 0 */ if (cpu8051_interrupt_enabled(INTERRUPT_1) && cpu8051_interrupt_fire(INTERRUPT_1, i) && - (cpu8051_ReadD(_TCON_) & 0x20)) { - cpu8051_WriteD(_TCON_, - cpu8051_ReadD(_TCON_) & 0xDF); + (memory_read_direct(_TCON_) & 0x20)) { + memory_write_direct(_TCON_, + memory_read_direct(_TCON_) & 0xDF); cpu8051_process_interrupt(0x0B, i); return; } /* Interrupt timer 1 */ if (cpu8051_interrupt_enabled(INTERRUPT_3) && cpu8051_interrupt_fire(INTERRUPT_3, i) && - (cpu8051_ReadD(_TCON_) & 0x80)) { - cpu8051_WriteD(_TCON_, - cpu8051_ReadD(_TCON_) & 0x7F); + (memory_read_direct(_TCON_) & 0x80)) { + memory_write_direct(_TCON_, + memory_read_direct(_TCON_) & 0x7F); cpu8051_process_interrupt(0x1B, i); return; } /* Serial Interrupts */ if (cpu8051_interrupt_enabled(INTERRUPT_4) && cpu8051_interrupt_fire(INTERRUPT_4, i) && - (cpu8051_ReadD(_SCON_) & 0x03)) { + (memory_read_direct(_SCON_) & 0x03)) { cpu8051_process_interrupt(0x23, i); return; } /* Interrupt timer 2 */ if (cpu8051_interrupt_enabled(INTERRUPT_5) && cpu8051_interrupt_fire(INTERRUPT_5, i) && - (cpu8051_ReadD(_T2CON_) & 0x80)) { + (memory_read_direct(_T2CON_) & 0x80)) { cpu8051_process_interrupt(0x2B, i); return; } @@ -483,7 +398,7 @@ cpu8051_int_mem_bit_info(uint8_t bit_address, char *text) uint8_t bit_number; int len; - cpu8051_convert_bit_address(bit_address, &byte_address, &bit_number); + memory_convert_bit_address(bit_address, &byte_address, &bit_number); len = cpu8051_sfr_mem_info(byte_address, text); sprintf(&text[len], ".%X", bit_address); @@ -493,14 +408,14 @@ cpu8051_int_mem_bit_info(uint8_t bit_address, char *text) int cpu8051_get_instruction_size(unsigned char opcode) { - return InstSizesTbl[opcode]; + return instr_size[opcode]; } /* Display instruction mnemonic. */ int cpu8051_disasm_mnemonic(unsigned char opcode, char *buf) { - return sprintf(buf, "%s", InstTextTbl[InstTypesTbl[opcode]]); + return sprintf(buf, "%s", instr_type_str[instr_type_id[opcode]]); } /* Disasm instruction arguments starting at address into a text string */ @@ -534,8 +449,8 @@ cpu8051_disasm_args(unsigned int address, char *buf) return; } - for (i = 1; i <= InstArgTbl[args_table_offset]; i++) { - switch (InstArgTbl[args_table_offset + i]) { + for (i = 1; i <= instr_arg_type_id[args_table_offset]; i++) { + switch (instr_arg_type_id[args_table_offset + i]) { case ADDR11: { len += sprintf(&buf[len], "%.4XH", ((opcode << 3) & 0xF00) + @@ -601,10 +516,11 @@ cpu8051_disasm_args(unsigned int address, char *buf) default: { len += sprintf( &buf[len], "%s", - ArgsTextTbl[InstArgTbl[args_table_offset + i]]); + instr_arg_type_str[instr_arg_type_id[ + args_table_offset + i]]); } } - if (i < InstArgTbl[args_table_offset]) + if (i < instr_arg_type_id[args_table_offset]) len += sprintf(&buf[len], ","); } } @@ -622,7 +538,7 @@ cpu8051_disasm(unsigned int address, char *text) len += sprintf(text, " %.4X ", address); opcode = memory_read8(PGM_MEM_ID, address); - inst_size = InstSizesTbl[opcode]; + inst_size = instr_size[opcode]; /* Display hex bytes. */ for (i = 0; i < inst_size; i++) diff --git a/src/common/cpu8051.h b/src/common/cpu8051.h index 6dcee47..3348aee 100644 --- a/src/common/cpu8051.h +++ b/src/common/cpu8051.h @@ -74,24 +74,6 @@ cpu8051_run(int instr_count, int (*interface_stop)(void)); void cpu8051_reset(void); -void -cpu8051_WriteD(unsigned int address, unsigned char value); - -void -cpu8051_WriteI(unsigned int address, unsigned char value); - -void -cpu8051_WriteB(uint8_t bit_address, uint8_t value); - -unsigned char -cpu8051_ReadD(unsigned int address); - -unsigned char -cpu8051_ReadI(unsigned int address); - -unsigned char -cpu8051_ReadB(uint8_t bit_address); - int cpu8051_get_instruction_size(unsigned char opcode); diff --git a/src/common/memory.c b/src/common/memory.c index 4b600b4..ec7542a 100644 --- a/src/common/memory.c +++ b/src/common/memory.c @@ -78,6 +78,21 @@ memory_check_address(enum mem_id_t id, unsigned long address, int display_error) } } +void +memory_convert_bit_address(uint8_t bit_address, uint8_t *byte_address, + uint8_t *bit_number) +{ + if (bit_address > 0x7F) { + /* SFR 80-FF */ + *byte_address = bit_address & 0xF8; + *bit_number = bit_address & 0x07; + } else { + /* 20-2F */ + *byte_address = (bit_address >> 3) + 0x20; + *bit_number = bit_address & 0x07; + } +} + u_int8_t * memory_getbuf(enum mem_id_t id, unsigned long address) { @@ -103,6 +118,41 @@ memory_write8(enum mem_id_t id, unsigned long address, u_int8_t value) } } +/* Write with a direct addressing mode at Address the new Value */ +void +memory_write_direct(unsigned int address, unsigned char value) +{ + memory_write8(INT_MEM_ID, address, value); +} + +/* Write with an indirect addressing mode at Address the new Value */ +void +memory_write_indirect(unsigned int address, unsigned char value) +{ + if (address > 0x7F) { + memory_write8(EXT_MEM_ID, address, value); + return; + } + + memory_write8(INT_MEM_ID, address, value); +} + +/* Write with a bit addressing mode at BitAddress the new Value */ +void +memory_write_bit(uint8_t bit_address, uint8_t value) +{ + uint8_t byte_address; + uint8_t bit_number; + unsigned char byte_val, byte_mask; + + memory_convert_bit_address(bit_address, &byte_address, &bit_number); + + byte_mask = ((1 << bit_number) ^ 0xFF); + byte_val = memory_read_direct(byte_address) & byte_mask; + byte_val += value << bit_number; + memory_write_direct(byte_address, byte_val); +} + void memory_sfr_write8(unsigned long address, u_int8_t value) { @@ -130,6 +180,41 @@ memory_read8(enum mem_id_t id, unsigned long address) } } +/* Read with a direct addressing mode at Address */ +unsigned char +memory_read_direct(unsigned int address) +{ + if (address > 0xFF) + return memory_read8(EXT_MEM_ID, address); + else + return memory_read8(INT_MEM_ID, address); +} + +/* Read with a indirect addressing mode at Address */ +unsigned char +memory_read_indirect(unsigned int address) +{ + if (address > 0x7F) + return memory_read8(EXT_MEM_ID, address); + else + return memory_read8(INT_MEM_ID, address); +} + +/* Read with a bit addressing mode at bit_address */ +unsigned char +memory_read_bit(uint8_t bit_address) +{ + uint8_t byte_address; + uint8_t bit_number; + unsigned char bit_value; + + memory_convert_bit_address(bit_address, &byte_address, &bit_number); + + bit_value = (memory_read_direct(byte_address) >> bit_number); + bit_value &= 1; + return bit_value; +} + u_int8_t memory_sfr_read8(unsigned long address) { diff --git a/src/common/memory.h b/src/common/memory.h index 5ba5204..07cf5b3 100644 --- a/src/common/memory.h +++ b/src/common/memory.h @@ -41,6 +41,10 @@ int memory_check_address(enum mem_id_t id, unsigned long address, int display_error); +void +memory_convert_bit_address(uint8_t bit_address, uint8_t *byte_address, + uint8_t *bit_number); + u_int8_t * memory_getbuf(enum mem_id_t id, unsigned long address); @@ -50,6 +54,15 @@ memory_clear(enum mem_id_t id); void memory_write8(enum mem_id_t id, unsigned long address, u_int8_t value); +void +memory_write_direct(unsigned int address, unsigned char value); + +void +memory_write_indirect(unsigned int address, unsigned char value); + +void +memory_write_bit(uint8_t bit_address, uint8_t value); + void memory_sfr_write8(unsigned long address, u_int8_t value); @@ -59,6 +72,15 @@ memory_sfr_write_dptr(u_int16_t value); u_int8_t memory_read8(enum mem_id_t id, unsigned long address); +unsigned char +memory_read_direct(unsigned int address); + +unsigned char +memory_read_indirect(unsigned int address); + +unsigned char +memory_read_bit(uint8_t bit_address); + u_int8_t memory_sfr_read8(unsigned long address); diff --git a/src/common/opcode2c.pl b/src/common/opcode2c.pl index dac4d09..27c9f56 100755 --- a/src/common/opcode2c.pl +++ b/src/common/opcode2c.pl @@ -131,9 +131,12 @@ while($ligne=) { # ------------------------------------------------------------------------------ print DISASM_H "/* Size(in bytes) of each instruction (offset in table is instruction opcode) */\n"; -print DISASM_H "static int InstSizesTbl[] = {"; -for ($i = 0; $i < 256; $i++) { +$nbelement = @nbbytes; + +print DISASM_H "static int instr_size[$nbelement] = {"; + +for ($i = 0; $i < $nbelement; $i++) { if ($i % 16 == 0) { print DISASM_H "\n\t"; } else { @@ -144,16 +147,20 @@ for ($i = 0; $i < 256; $i++) { print DISASM_H "\n"; print DISASM_H "};\n"; print DISASM_H "\n"; + # ------------------------------------------------------------------------------ print DISASM_H "/*\n"; print DISASM_H " * For all 256 opcodes, the value in this table gives the instruction type\n"; print DISASM_H " * ex.: MOV, INC, CLR, CPL,...\n"; print DISASM_H " * To know what is the instruction type, use\n"; -print DISASM_H " * the number as an offset in InstTextTbl[]\n"; +print DISASM_H " * the number as an offset in instr_type_str[]\n"; print DISASM_H " */\n"; -print DISASM_H "static int InstTypesTbl[] = {"; -for ($i = 0; $i < 256; $i++) { +$nbelement = @insttype; + +print DISASM_H "static int instr_type_id[$nbelement] = {"; + +for ($i = 0; $i < $nbelement; $i++) { if ($i % 16 == 0) { print DISASM_H "\n\t"; } else { @@ -164,32 +171,39 @@ for ($i = 0; $i < 256; $i++) { print DISASM_H "\n"; print DISASM_H "};\n"; print DISASM_H "\n"; + # ------------------------------------------------------------------------------ -print DISASM_H "/* List of instructions types referenced by InstTypesTbl[] */\n"; -$nbelement=@insttext; -print DISASM_H "\#define InstTextTblLength $nbelement\n"; -$elementnb=0; -print DISASM_H "static char *InstTextTbl[] = {\n"; +print DISASM_H "/* List of instructions types referenced by instr_type_id[] */\n"; +$nbelement = @insttext; +$elementnb = 0; +print DISASM_H "static char *instr_type_str[$nbelement] = {\n"; + foreach $instruc (@insttext) { print DISASM_H "\t\"$instruc\""; - ($elementnb++ < $nbelement-1) and print DISASM_H ","; + if ($elementnb++ < ($nbelement - 1)) { + print DISASM_H ","; + } print DISASM_H "\n"; } + print DISASM_H "};\n"; print DISASM_H "\n"; + # ------------------------------------------------------------------------------ print DISASM_H "/*\n"; print DISASM_H " * Table describing all arguments types of an instruction\n"; -print DISASM_H " * The table is indexed InstArgTbl[ opcode * 4]\n"; -print DISASM_H " * InstArgTbl[opcode*4 + 1] gives the number of arguments the instruction has\n"; -print DISASM_H " * InstArgTbl[opcode*4 + i] for i=1,2 and 3 give the type of each argument\n"; +print DISASM_H " * The table is indexed instr_arg_type_id[ opcode * 4]\n"; +print DISASM_H " * instr_arg_type_id[opcode*4 + 1] gives number of instruction arguments\n"; +print DISASM_H " * instr_arg_type_id[opcode*4 + i] for i=1,2 and 3 gives type of each argument\n"; print DISASM_H " * for most instructions, the 3rd argument isn't used\n"; -print DISASM_H " * the argument type is referecing to ArgsTextTbl[]\n"; +print DISASM_H " * the argument type is referecing to instr_arg_type_str[]\n"; print DISASM_H " */\n"; -print DISASM_H "\#define InstArgTblLength 256\n"; -print DISASM_H "static int InstArgTbl[] = {"; -for ($i = 0; $i < 1024; $i++) { +$nbelement = @instargs; + +print DISASM_H "static int instr_arg_type_id[$nbelement] = {"; + +for ($i = 0; $i < $nbelement; $i++) { if ($i % 16 == 0) { print DISASM_H "\n\t"; } else { @@ -205,22 +219,26 @@ print DISASM_H "\n"; # ------------------------------------------------------------------------------ print DISASM_H "/*\n"; print DISASM_H " * List all types of arguments available to instructions\n"; -print DISASM_H " * Referenced by InstArgsTbl[]\n"; +print DISASM_H " * Referenced by instr_arg_type_id[]\n"; print DISASM_H " */\n"; + $nbelement = @argstypes; -print DISASM_H "\#define ArgsTextTblLength $nbelement\n"; $elementnb = 0; -print DISASM_H "static char *ArgsTextTbl[] = {\n"; + +print DISASM_H "static char *instr_arg_type_str[$nbelement] = {\n"; + foreach $args (@argstypes) { print DISASM_H "\t\"$args\""; - ($elementnb++ < $nbelement-1) and print DISASM_H ","; + if ($elementnb++ < $nbelement-1) { + print DISASM_H ","; + } print DISASM_H "\n"; } print DISASM_H "};\n"; print DISASM_H "\n"; # ------------------------------------------------------------------------------ -for ($i=0 ; $i< 256; $i++) { +for ($i = 0 ; $i < 256; $i++) { print INST_IMP "/*","*"x76,"\n"; print INST_IMP " * Instruction \"$a_instruction[$i]\" takes $a_cycles[$i] cycle(s) and $a_bytes[$i] byte(s).\n"; print INST_IMP " ","*"x76,"/\n"; @@ -231,11 +249,11 @@ for ($i=0 ; $i< 256; $i++) { if( $i == 0x85 ) { # Cas particulier pour MOV direct,direct -> src et dest sont inverses dans la memoire print INST_IMP " unsigned char srcaddr = memory_read8( PGM_MEM_ID, cpu8051.pc++ );\n"; - print INST_IMP " unsigned char source = cpu8051_ReadD( srcaddr );\n"; + print INST_IMP " unsigned char source = memory_read_direct( srcaddr );\n"; print INST_IMP " unsigned char destaddr = memory_read8( PGM_MEM_ID, cpu8051.pc++ );\n"; - print INST_IMP " unsigned char destination = cpu8051_ReadD( destaddr );\n"; + print INST_IMP " unsigned char destination = memory_read_direct( destaddr );\n"; print INST_IMP " destination = source;\n"; - print INST_IMP " cpu8051_WriteD( destaddr, destination );\n"; + print INST_IMP " memory_write_direct( destaddr, destination );\n"; } else { if ($instargs[$i*4] > 0) { @@ -249,45 +267,45 @@ for ($i=0 ; $i< 256; $i++) { cfw("cpu8051.pc += 2;"); } if ($op_destination == 2) { # A - cfw("unsigned char destination = cpu8051_ReadD( _ACC_ );"); + cfw("unsigned char destination = memory_read_direct( _ACC_ );"); } if ($op_destination == 3) { # direct cfw("unsigned char destaddr = memory_read8( PGM_MEM_ID, cpu8051.pc++ );"); - cfw("unsigned char destination = cpu8051_ReadD( destaddr );"); + cfw("unsigned char destination = memory_read_direct( destaddr );"); } if ($op_destination == 4) { # @R0 - cfw("unsigned char destination = cpu8051_ReadI ( cpu8051_ReadD( BANKPSW + _R0_ ) );"); + cfw("unsigned char destination = memory_read_indirect ( memory_read_direct( BANKPSW + _R0_ ) );"); } if ($op_destination == 5) { # @R1 - cfw("unsigned char destination = cpu8051_ReadI ( cpu8051_ReadD( BANKPSW + _R1_ ) );"); + cfw("unsigned char destination = memory_read_indirect ( memory_read_direct( BANKPSW + _R1_ ) );"); } if ($op_destination == 6) { # R0 - cfw("unsigned char destination = cpu8051_ReadD( BANKPSW + _R0_ );"); + cfw("unsigned char destination = memory_read_direct( BANKPSW + _R0_ );"); } if ($op_destination == 7) { # R1 - cfw("unsigned char destination = cpu8051_ReadD( BANKPSW + _R1_ );"); + cfw("unsigned char destination = memory_read_direct( BANKPSW + _R1_ );"); } if ($op_destination == 8) { # R2 - cfw("unsigned char destination = cpu8051_ReadD( BANKPSW + _R2_ );"); + cfw("unsigned char destination = memory_read_direct( BANKPSW + _R2_ );"); } if ($op_destination == 9) { # R3 - cfw("unsigned char destination = cpu8051_ReadD( BANKPSW + _R3_ );"); + cfw("unsigned char destination = memory_read_direct( BANKPSW + _R3_ );"); } if ($op_destination == 10) { # R4 - cfw("unsigned char destination = cpu8051_ReadD( BANKPSW + _R4_ );"); + cfw("unsigned char destination = memory_read_direct( BANKPSW + _R4_ );"); } if ($op_destination == 11) { # R5 - cfw("unsigned char destination = cpu8051_ReadD( BANKPSW + _R5_ );"); + cfw("unsigned char destination = memory_read_direct( BANKPSW + _R5_ );"); } if ($op_destination == 12) { # R6 - cfw("unsigned char destination = cpu8051_ReadD( BANKPSW + _R6_ );"); + cfw("unsigned char destination = memory_read_direct( BANKPSW + _R6_ );"); } if ($op_destination == 13) { # R7 - cfw("unsigned char destination = cpu8051_ReadD( BANKPSW + _R7_ );"); + cfw("unsigned char destination = memory_read_direct( BANKPSW + _R7_ );"); } if ($op_destination == 14) { # bitaddr cfw("unsigned char destination, dstbitaddr = memory_read8( PGM_MEM_ID, cpu8051.pc++ );"); - cfw("destination = cpu8051_ReadB( dstbitaddr );"); + cfw("destination = memory_read_bit( dstbitaddr );"); } if ($op_destination == 15) { # reladdr cfw("cpu8051.pc++;"); @@ -300,21 +318,21 @@ for ($i=0 ; $i< 256; $i++) { cfw("unsigned char destination = psw_read_cy();"); } if ($op_destination == 18) { # @A+DPTR - cfw("unsigned int destination = cpu8051_ReadD( _ACC_ ) + memory_sfr_read_dptr();"); + cfw("unsigned int destination = memory_read_direct( _ACC_ ) + memory_sfr_read_dptr();"); } if ($op_destination == 20) { # AB - cfw("unsigned char destination = cpu8051_ReadD( _ACC_ );"); - cfw("unsigned char source = cpu8051_ReadD( _B_ );"); + cfw("unsigned char destination = memory_read_direct( _ACC_ );"); + cfw("unsigned char source = memory_read_direct( _B_ );"); } if ($op_destination == 21) { # DPTR cfw("unsigned int destination = memory_sfr_read_dptr();"); } if ($op_destination == 23) { # /bitaddr cfw("unsigned char destination, dstbitaddr = memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );"); - cfw("destination = ( cpu8051_ReadB( dstbitaddr ) ^ 1 );"); + cfw("destination = ( memory_read_bit( dstbitaddr ) ^ 1 );"); } if ($op_destination == 24) { # @DPTR - cfw("unsigned char destination = cpu8051_ReadI(memory_sfr_read_dptr());"); + cfw("unsigned char destination = memory_read_indirect(memory_sfr_read_dptr());"); } } @@ -328,46 +346,46 @@ for ($i=0 ; $i< 256; $i++) { cfw("cpu8051.pc += 2;"); } if ($op_source == 2) { # A - cfw("unsigned char source = cpu8051_ReadD( _ACC_ );"); + cfw("unsigned char source = memory_read_direct( _ACC_ );"); } if ($op_source == 3) { # direct cfw("unsigned char srcaddr = memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );"); - cfw("unsigned char source = cpu8051_ReadD( srcaddr );"); + cfw("unsigned char source = memory_read_direct( srcaddr );"); } if ($op_source == 4) { # @R0 - cfw("unsigned char source = cpu8051_ReadI ( cpu8051_ReadD( BANKPSW + _R0_ ) );"); + cfw("unsigned char source = memory_read_indirect ( memory_read_direct( BANKPSW + _R0_ ) );"); } if ($op_source == 5) { # @R1 - cfw("unsigned char source = cpu8051_ReadI ( cpu8051_ReadD( BANKPSW + _R1_ ) );"); + cfw("unsigned char source = memory_read_indirect ( memory_read_direct( BANKPSW + _R1_ ) );"); } if ($op_source == 6) { # R0 - cfw("unsigned char source = cpu8051_ReadD( BANKPSW + _R0_ );"); + cfw("unsigned char source = memory_read_direct( BANKPSW + _R0_ );"); } if ($op_source == 7) { # R1 - cfw("unsigned char source = cpu8051_ReadD( BANKPSW + _R1_ );"); + cfw("unsigned char source = memory_read_direct( BANKPSW + _R1_ );"); } if ($op_source == 8) { # R2 - cfw("unsigned char source = cpu8051_ReadD( BANKPSW + _R2_ );"); + cfw("unsigned char source = memory_read_direct( BANKPSW + _R2_ );"); } if ($op_source == 9) { # R3 - cfw("unsigned char source = cpu8051_ReadD( BANKPSW + _R3_ );"); + cfw("unsigned char source = memory_read_direct( BANKPSW + _R3_ );"); } if ($op_source == 10) { # R4 - cfw("unsigned char source = cpu8051_ReadD( BANKPSW + _R4_ );"); + cfw("unsigned char source = memory_read_direct( BANKPSW + _R4_ );"); } if ($op_source == 11) { # R5 - cfw("unsigned char source = cpu8051_ReadD( BANKPSW + _R5_ );"); + cfw("unsigned char source = memory_read_direct( BANKPSW + _R5_ );"); } if ($op_source == 12) { # R6 - cfw("unsigned char source = cpu8051_ReadD( BANKPSW + _R6_ );"); + cfw("unsigned char source = memory_read_direct( BANKPSW + _R6_ );"); } if ($op_source == 13) { # R7 - cfw("unsigned char source = cpu8051_ReadD( BANKPSW + _R7_ );"); + cfw("unsigned char source = memory_read_direct( BANKPSW + _R7_ );"); } if ($op_source == 14) { # bitaddr cfw("unsigned char source, srcbitaddr = memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );"); - cfw("source = cpu8051_ReadB( srcbitaddr );"); + cfw("source = memory_read_bit( srcbitaddr );"); } if ($op_source == 15) { # reladdr cfw("(cpu8051.pc)++;"); @@ -380,10 +398,10 @@ for ($i=0 ; $i< 256; $i++) { cfw("unsigned char source = psw_read_cy();"); } if ($op_source == 18) { # @A+DPTR - cfw("unsigned char source = memory_read8( PGM_MEM_ID, cpu8051_ReadD( _ACC_ ) + memory_sfr_read_dptr());"); + cfw("unsigned char source = memory_read8( PGM_MEM_ID, memory_read_direct( _ACC_ ) + memory_sfr_read_dptr());"); } if ($op_source == 19) { # @A+PC - cfw("unsigned char source = memory_read8( PGM_MEM_ID, cpu8051_ReadD( _ACC_ ) + ( ++cpu8051.pc ) );"); + cfw("unsigned char source = memory_read8( PGM_MEM_ID, memory_read_direct( _ACC_ ) + ( ++cpu8051.pc ) );"); } if ($op_source == 21) { # DPTR cfw("unsigned int source = memory_sfr_read_dptr();"); @@ -394,10 +412,10 @@ for ($i=0 ; $i< 256; $i++) { } if ($op_source == 23) { # /bitaddr cfw("unsigned char source, srcbitaddr = memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );"); - cfw("source = ( cpu8051_ReadB( srcbitaddr ) ^ 1 );"); + cfw("source = ( memory_read_bit( srcbitaddr ) ^ 1 );"); } if ($op_source == 24) { # @DPTR - cfw("unsigned char source = cpu8051_ReadI(memory_sfr_read_dptr());"); + cfw("unsigned char source = memory_read_indirect(memory_sfr_read_dptr());"); } } @@ -510,7 +528,7 @@ for ($i=0 ; $i< 256; $i++) { # JZ if ($insttype[$i] == 22) { - cfw("if ( cpu8051_ReadD( _ACC_ ) == 0 ) { cpu8051.pc = destination; }"); + cfw("if ( memory_read_direct( _ACC_ ) == 0 ) { cpu8051.pc = destination; }"); } # XRL @@ -520,7 +538,7 @@ for ($i=0 ; $i< 256; $i++) { # JNZ if ($insttype[$i] == 24) { - cfw("if ( cpu8051_ReadD( _ACC_ ) != 0 ) { cpu8051.pc = destination; }"); + cfw("if ( memory_read_direct( _ACC_ ) != 0 ) { cpu8051.pc = destination; }"); } # JMP @@ -551,8 +569,8 @@ for ($i=0 ; $i< 256; $i++) { # If B is zero, the OV flag will be set indicating a # division-by-zero error cfw("if (source != 0) {"); - cfw(" cpu8051_WriteD(_ACC_, destination/source);"); - cfw(" cpu8051_WriteD( _B_, destination%source);"); + cfw(" memory_write_direct(_ACC_, destination/source);"); + cfw(" memory_write_direct( _B_, destination%source);"); cfw(" psw_clr_ov();"); cfw("} else {"); cfw(" psw_set_ov();"); @@ -578,9 +596,9 @@ for ($i=0 ; $i< 256; $i++) { # A = destination # B = source cfw("psw_clr_cy();"); - cfw("cpu8051_WriteD(_ACC_, destination * source);"); - cfw("cpu8051_WriteD(_B_, (destination * source) / 0x100);"); - cfw("if (cpu8051_ReadD(_B_) > 0)"); + cfw("memory_write_direct(_ACC_, destination * source);"); + cfw("memory_write_direct(_B_, (destination * source) / 0x100);"); + cfw("if (memory_read_direct(_B_) > 0)"); cfw(" psw_set_ov();"); cfw("else"); cfw(" psw_clr_ov();"); @@ -677,44 +695,44 @@ for ($i=0 ; $i< 256; $i++) { cfw("cpu8051.pc = addr16;"); } if ($op_destination == 2) { # A - cfw("cpu8051_WriteD( _ACC_, destination );"); + cfw("memory_write_direct( _ACC_, destination );"); } if ($op_destination == 3) { # direct - cfw("cpu8051_WriteD( destaddr, destination );"); + cfw("memory_write_direct( destaddr, destination );"); } if ($op_destination == 4) { # @R0 - cfw("cpu8051_WriteI( cpu8051_ReadD( BANKPSW + _R0_ ), destination );"); + cfw("memory_write_indirect( memory_read_direct( BANKPSW + _R0_ ), destination );"); } if ($op_destination == 5) { # @R1 - cfw("cpu8051_WriteI( cpu8051_ReadD( BANKPSW + _R1_ ), destination );"); + cfw("memory_write_indirect( memory_read_direct( BANKPSW + _R1_ ), destination );"); } if ($op_destination == 6) { # R0 - cfw("cpu8051_WriteD( BANKPSW + _R0_, destination );"); + cfw("memory_write_direct( BANKPSW + _R0_, destination );"); } if ($op_destination == 7) { # R1 - cfw("cpu8051_WriteD( BANKPSW + _R1_, destination );"); + cfw("memory_write_direct( BANKPSW + _R1_, destination );"); } if ($op_destination == 8) { # R2 - cfw("cpu8051_WriteD( BANKPSW + _R2_, destination );"); + cfw("memory_write_direct( BANKPSW + _R2_, destination );"); } if ($op_destination == 9) { # R3 - cfw("cpu8051_WriteD( BANKPSW + _R3_, destination );"); + cfw("memory_write_direct( BANKPSW + _R3_, destination );"); } if ($op_destination == 10) { # R4 - cfw("cpu8051_WriteD( BANKPSW + _R4_, destination );"); + cfw("memory_write_direct( BANKPSW + _R4_, destination );"); } if ($op_destination == 11) { # R5 - cfw("cpu8051_WriteD( BANKPSW + _R5_, destination );"); + cfw("memory_write_direct( BANKPSW + _R5_, destination );"); } if ($op_destination == 12) { # R6 - cfw("cpu8051_WriteD( BANKPSW + _R6_, destination );"); + cfw("memory_write_direct( BANKPSW + _R6_, destination );"); } if ($op_destination == 13) { # R7 - cfw("cpu8051_WriteD( BANKPSW + _R7_, destination );"); + cfw("memory_write_direct( BANKPSW + _R7_, destination );"); } if ($op_destination == 14) { # bitaddr - cfw("cpu8051_WriteB( dstbitaddr, destination );"); + cfw("memory_write_bit( dstbitaddr, destination );"); } if ($op_destination == 17) { # C cfw("psw_write_cy(destination);"); @@ -723,10 +741,10 @@ for ($i=0 ; $i< 256; $i++) { cfw("memory_sfr_write_dptr(destination);"); } if ($op_destination == 23) { # /bitaddr - cfw("cpu8051_WriteB( dstbitaddr, destination );"); + cfw("memory_write_bit( dstbitaddr, destination );"); } if ($op_destination == 24) { # @DPTR - cfw("cpu8051_WriteI(memory_sfr_read_dptr(), destination);"); + cfw("memory_write_indirect(memory_sfr_read_dptr(), destination);"); } } @@ -740,43 +758,43 @@ for ($i=0 ; $i< 256; $i++) { cfw("cpu8051.pc = addr16;"); } if ($op_source == 2) { # A - cfw("cpu8051_WriteD( _ACC_, source );"); + cfw("memory_write_direct( _ACC_, source );"); } if ($op_source == 3) { # direct - cfw("cpu8051_WriteD( srcaddr, source );"); + cfw("memory_write_direct( srcaddr, source );"); } if ($op_source == 4) { # @R0 - cfw("cpu8051_WriteI( cpu8051_ReadD( BANKPSW + _R0_ ), source );"); + cfw("memory_write_indirect( memory_read_direct( BANKPSW + _R0_ ), source );"); } if ($op_source == 5) { # @R1 - cfw("cpu8051_WriteI( cpu8051_ReadD( BANKPSW + _R1_ ), source );"); + cfw("memory_write_indirect( memory_read_direct( BANKPSW + _R1_ ), source );"); } if ($op_source == 6) { # R0 - cfw("cpu8051_WriteD( BANKPSW + _R0_, source );"); + cfw("memory_write_direct( BANKPSW + _R0_, source );"); } if ($op_source == 7) { # R1 - cfw("cpu8051_WriteD( BANKPSW + _R1_, source );"); + cfw("memory_write_direct( BANKPSW + _R1_, source );"); } if ($op_source == 8) { # R2 - cfw("cpu8051_WriteD( BANKPSW + _R2_, source );"); + cfw("memory_write_direct( BANKPSW + _R2_, source );"); } if ($op_source == 9) { # R3 - cfw("cpu8051_WriteD( BANKPSW + _R3_, source );"); + cfw("memory_write_direct( BANKPSW + _R3_, source );"); } if ($op_source == 10) { # R4 - cfw("cpu8051_WriteD( BANKPSW + _R4_, source );"); + cfw("memory_write_direct( BANKPSW + _R4_, source );"); } if ($op_source == 11) { # R5 - cfw("cpu8051_WriteD( BANKPSW + _R5_, source );"); + cfw("memory_write_direct( BANKPSW + _R5_, source );"); } if ($op_source == 12) { # R6 - cfw("cpu8051_WriteD( BANKPSW + _R6_, source );"); + cfw("memory_write_direct( BANKPSW + _R6_, source );"); } if ($op_source == 13) { # R7 - cfw("cpu8051_WriteD( BANKPSW + _R7_, source );"); + cfw("memory_write_direct( BANKPSW + _R7_, source );"); } if ($op_source == 14) { # bitaddr - cfw("cpu8051_WriteB( srcbitaddr, source );"); + cfw("memory_write_bit( srcbitaddr, source );"); } if ($op_source == 17) { # C cfw("psw_write_cy(source);"); @@ -785,10 +803,10 @@ for ($i=0 ; $i< 256; $i++) { cfw("memory_sfr_write_dptr(source);"); } if ($op_source == 23) { # /bitaddr - cfw("cpu8051_WriteB( srcbitaddr, source );"); + cfw("memory_write_bit( srcbitaddr, source );"); } if ($op_source == 24) { # @DPTR - cfw("cpu8051_WriteI(memory_sfr_read_dptr(), source);"); + cfw("memory_write_indirect(memory_sfr_read_dptr(), source);"); } } } @@ -806,7 +824,7 @@ print INST_DEF " * instructions_8051.h\n"; write_header(INST_DEF); print INST_DEF "#ifndef INSTRUCTIONS_8051_H\n"; print INST_DEF "#define INSTRUCTIONS_8051_H 1\n\n\n"; -print INST_DEF "#define BANKPSW (cpu8051_ReadD(_PSW_) & 0x18)\n\n"; +print INST_DEF "#define BANKPSW (memory_read_direct(_PSW_) & 0x18)\n\n"; print INST_DEF "typedef int (*OPCODE_FP)(void);\n\n\n"; for( $i=0; $i<256; $i++ ) { print INST_DEF "int\n"; diff --git a/src/common/timers.c b/src/common/timers.c index b8afdfa..3e7f3ec 100644 --- a/src/common/timers.c +++ b/src/common/timers.c @@ -54,15 +54,15 @@ timer_increment_check_overflow(uint8_t counter_address, uint8_t tf_mask) { unsigned int tmp; - tmp = cpu8051_ReadD(counter_address); + tmp = memory_read_direct(counter_address); tmp++; tmp &= 0xFF; if (tmp == 0) { /* If overflow set TFx */ - cpu8051_WriteD(_TCON_, cpu8051_ReadD(_TCON_) | tf_mask); + memory_write_direct(_TCON_, memory_read_direct(_TCON_) | tf_mask); } - cpu8051_WriteD(counter_address, tmp); /* Save new value. */ + memory_write_direct(counter_address, tmp); /* Save new value. */ } static void @@ -71,11 +71,11 @@ timer_with_prescaler(uint8_t tl, uint8_t th, uint8_t tf_mask, { unsigned int prescaler; - prescaler = cpu8051_ReadD(tl); + prescaler = memory_read_direct(tl); prescaler++; prescaler &= (1 << prescaler_width) - 1; /* Keep only required bits */ - cpu8051_WriteD(tl, prescaler); + memory_write_direct(tl, prescaler); if (prescaler == 0) timer_increment_check_overflow(th, tf_mask); @@ -98,15 +98,15 @@ process_timer(uint8_t tl, uint8_t th, uint8_t tf_mask, uint8_t TR, uint8_t mode, break; case 2: /* Mode 2, 8-bits counter with Auto-Reload */ - tmp = cpu8051_ReadD(tl); + tmp = memory_read_direct(tl); tmp++; tmp &= 0xFF; if (tmp == 0) { /* If overflow -> reload and set TF0 */ - cpu8051_WriteD(_TCON_, cpu8051_ReadD(_TCON_) | tf_mask); - cpu8051_WriteD(tl, cpu8051_ReadD(th)); + memory_write_direct(_TCON_, memory_read_direct(_TCON_) | tf_mask); + memory_write_direct(tl, memory_read_direct(th)); } else { - cpu8051_WriteD(tl, tmp); + memory_write_direct(tl, tmp); } break; case 3: @@ -123,7 +123,7 @@ process_timer(uint8_t tl, uint8_t th, uint8_t tf_mask, uint8_t TR, uint8_t mode, timer_increment_check_overflow(tl, tf_mask); /* TH0 uses TR1 et TF1. */ - TR = cpu8051_ReadD(_TCON_) & 0x40; + TR = memory_read_direct(_TCON_) & 0x40; if (TR) timer_increment_check_overflow(th, 0x80); @@ -142,20 +142,20 @@ timers_check(void) unsigned int timer_counter; /* Timer 0 */ - tr = cpu8051_ReadD(_TCON_) & 0x10; - mode = cpu8051_ReadD(_TMOD_) & 0x03; - gate = cpu8051_ReadD(_TMOD_) & 0x08; - timer_counter = cpu8051_ReadD(_TMOD_) & 0x04; + tr = memory_read_direct(_TCON_) & 0x10; + mode = memory_read_direct(_TMOD_) & 0x03; + gate = memory_read_direct(_TMOD_) & 0x08; + timer_counter = memory_read_direct(_TMOD_) & 0x04; if ((tr && !gate && !timer_counter) || (mode == 3)) process_timer(_TL0_, _TH0_, 0x20, tr, mode, gate, timer_counter); /* Timer 1 */ - tr = cpu8051_ReadD(_TCON_) & 0x40; - mode = (cpu8051_ReadD(_TMOD_) & 0x30) >> 4 ; - gate = cpu8051_ReadD(_TMOD_) & 0x80; - timer_counter = cpu8051_ReadD(_TMOD_) & 0x40; + tr = memory_read_direct(_TCON_) & 0x40; + mode = (memory_read_direct(_TMOD_) & 0x30) >> 4 ; + gate = memory_read_direct(_TMOD_) & 0x80; + timer_counter = memory_read_direct(_TMOD_) & 0x40; if (tr && !gate && !timer_counter) process_timer(_TL1_, _TH1_, 0x80, tr, mode, gate, -- 2.20.1